Algorithm


A. You're Given a String...
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).

Input

The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.

Output

Output one number — length of the longest substring that can be met in the string at least twice.

Examples
input
Copy
abcd
output
Copy
0
input
Copy
ababa
output
Copy
3
input
Copy
zzz
output
Copy
2



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <iostream>
#include <algorithm>
#include <string>
#include <map>

typedef long long ll;

using namespace std;

map<string, int> mp;

int main() {
	string s, tmp;
	cin >> s;

	for(int i = 0; i < (int)s.length(); ++i)
		for(int j = 0; j <= (int)s.length() - i; ++j) {
			tmp = s.substr(i, j);
			if(tmp != "")
				mp[tmp]++;
		}

	map<string, int>::iterator it;
	int res = 0;
	for(it = mp.begin(); it != mp.end(); it++)
		if(it->second >= 2)
			res = max(res, (int)it->first.length());

	cout << res << endl;

	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
abcd
Advertisements

Demonstration


Codeforcess Solution A. You're Given a String... C,C++, Java, Js and Python ,A. You're Given a String,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+