Language: C++

#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int n,k;
int rank[200001];
int tmp[200001];
int lcp[200001];
int sa[200001];

bool compare_sa(int i,int j){
	if(rank[i]!=rank[j])return rank[i]<rank[j];
	else{
		int ri=(i+k<=n?rank[i+k]:-1);
		int rj=(j+k<=n?rank[j+k]:-1);
		return ri<rj;
	}
}

void construct_sa(string s){
	for(int i=0;i<=n;i++){
		sa[i]=i;
		rank[i]=i<n?s[i]:-1;
	}
	for(k=1;k<=n;k*=2){
		sort(sa,sa+n+1,compare_sa);
		tmp[sa[0]]=0;
		for(int i=1;i<=n;i++){
			tmp[sa[i]]=tmp[sa[i-1]]+(compare_sa(sa[i-1],sa[i])?1:0);
		}
		for(int i=0;i<=n;i++){
			rank[i]=tmp[i];
		}
	}
}

void construct_lcp(string s){
	for(int i=0;i<=n;i++){
		rank[sa[i]]=i;
	}
	int h=0;
	lcp[0]=0;
	for(int i=0;i<n;i++){
		int j=sa[rank[i]-1];
		if(h>0)h--;
		for(;j+h<n && i+h<n;h++){
			if(s[j+h]!=s[i+h])break;
		}
		lcp[rank[i]-1]=h;
	}
}

int func(string s){
	construct_sa(s);
	construct_lcp(s);
	int res=0;
	for(int i=0;i<=n;i++){
		res=max(res,lcp[i]);
	}
	return res;
}

string t;

int main(void){
	cin >> t;
	n=t.size();
	printf("%d\n",n-func(t));
	return 0;
}

Compiler output:
a.cc: In function 'bool compare_sa(int, int)':
a.cc:26:12: error: reference to 'rank' is ambiguous
   26 |         if(rank[i]!=rank[j])return rank[i]<rank[j];
      |            ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/vector:62,
                 from a.cc:3:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:26:21: error: reference to 'rank' is ambiguous
   26 |         if(rank[i]!=rank[j])return rank[i]<rank[j];
      |                     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:26:36: error: reference to 'rank' is ambiguous
   26 |         if(rank[i]!=rank[j])return rank[i]<rank[j];
      |                                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:26:44: error: reference to 'rank' is ambiguous
   26 |         if(rank[i]!=rank[j])return rank[i]<rank[j];
      |                                            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:28:32: error: reference to 'rank' is ambiguous
   28 |                 int ri=(i+k<=n?rank[i+k]:-1);
      |                                ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:29:32: error: reference to 'rank' is ambiguous
   29 |                 int rj=(j+k<=n?rank[j+k]:-1);
      |                                ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc: In function 'void construct_sa(std::string)':
a.cc:37:17: error: reference to 'rank' is ambiguous
   37 |                 rank[i]=i<n?s[i]:-1;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:46:25: error: reference to 'rank' is ambiguous
   46 |                         rank[i]=tmp[i];
      |                         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc: In function 'void construct_lcp(std::string)':
a.cc:53:17: error: reference to 'rank' is ambiguous
   53 |                 rank[sa[i]]=i;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:58:26: error: reference to 'rank' is ambiguous
   58 |                 int j=sa[rank[i]-1];
      |                          ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~
a.cc:63:21: error: reference to 'rank' is ambiguous
   63 |                 lcp[rank[i]-1]=h;
      |                     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:20:5: note:                 'int rank [200001]'
   20 | int rank[200001];
      |     ^~~~