Language: C++

#pragma CLANG optimize("Ofast")

#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

int N;
string S;
//int A[100] = {};
vector<int> v[26];
int cnt;
int ans = 0;
//int c = 0;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> N >> S;

	REP(i, 26) v[i].reserve(5010);
	//らんだむに先頭とする二文字を選べばn^2で2500万？だめ
	REP(i, N) {
		//先頭おなじの記録
		//A[S[i] - 'a']++;
		v[S[i] - 'a'].emplace_back(i);
		//0~26がa~zに対応
	}
	REP(i, 26) {
		cnt = 0;
		REP(j, v[i].size()) {
			for (int k = j + 1; k < v[i].size(); k++) {
				if (v[i][k] - v[i] <= ans) continue;
				REP(l, v[i][k] - v[i][j]) {
//					c++;
//					if (c > 50000000 * 12 + 30000000) {
//						cout << max(cnt, ans) << endl;
//						return 0;
//					}
					if (v[i][k] + l < N && S[v[i][k] + l] == S[v[i][j] + l]) {
						cnt++;
					}
					else {
						break;
					}
				}
				ans = max(cnt, ans);
				cnt = 0;
			}
		}
	}
	cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:45: error: no match for 'operator-' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>')
   61 |                                 if (v[i][k] - v[i] <= ans) continue;
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/deque:62,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:61:50: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   61 |                                 if (v[i][k] - v[i] <= ans) continue;
      |                                                  ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:61:50: note:   mismatched types 'const std::move_iterator<_IteratorL>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   61 |                                 if (v[i][k] - v[i] <= ans) continue;
      |                                                  ^