Language: C

#include<stdio.h>
#include<stdlib.h>

#define max(a,b) ((a)>(b)?(a):(b))

int n,k;
int rank[5010];
int rank2[5010];
int tmp[5010];

int compare_int(const void *a,const void *b){
	int i=*(int*)a,j=*(int*)b;
	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(char *s,int *sa,int m){
	n=m;
	int i;
	for(i=0;i<=n;i++){
		sa[i]=i;
		rank[i]=(i<n?(s[i]-'a'):-1);
	}
	for(k=1;k<=n;k*=2){
		qsort(sa,n,sizeof(int),compare_int);
		tmp[sa[0]]=0;
		for(i=1;i<=n;i++){
			tmp[sa[i]]=tmp[sa[i-1]]+(compare_int(sa[i-1],sa[i])>0?1:0);
		}
		for(i=0;i<=n;i++)rank[i]=tmp[i];
	}
}

void construct_lcp(char *s,int *sa,int lcp,int m){
	int i;
	for(i=0;i<=m;i++)rank2[sa[i]]=i;
	int h=0;
	lcp[0]=0;
	for(i=0;i<n;i++){
		int j=sa[rank2[i]-1];

		if(h>0)h--;
		for(;j+h<n&&i+h<n;h++){
			if(s[j+h]!=s[i+h])break;
		}
		lcp[rank2[i]-1]=h;
	}
}

int main(){
	int i;
	char s[5500];
	int sa[5010];
	int lcp[5010];
	int ans=0;
	scanf("%d%s",&n,s);
	construct_sa(s,sa,n);
	construct_lcp(s,sa,lcp);
	for(i=0;i<n;i++)ans=max(ans,lcp[i]);
	printf("%d\n",ans);
	return 0;
}

Compiler output:
main.c: In function 'compare_int':
main.c:17:17: error: 'ri' undeclared (first use in this function); did you mean 'i'?
   17 |         }return ri-rj;
      |                 ^~
      |                 i
main.c:17:17: note: each undeclared identifier is reported only once for each function it appears in
main.c:17:20: error: 'rj' undeclared (first use in this function); did you mean 'j'?
   17 |         }return ri-rj;
      |                    ^~
      |                    j
main.c: In function 'construct_sa':
main.c:31:64: error: passing argument 1 of 'compare_int' makes pointer from integer without a cast [-Wint-conversion]
   31 |                         tmp[sa[i]]=tmp[sa[i-1]]+(compare_int(sa[i-1],sa[i])>0?1:0);
      |                                                              ~~^~~~~
      |                                                                |
      |                                                                int
main.c:11:29: note: expected 'const void *' but argument is of type 'int'
   11 | int compare_int(const void *a,const void *b){
      |                 ~~~~~~~~~~~~^
main.c:31:72: error: passing argument 2 of 'compare_int' makes pointer from integer without a cast [-Wint-conversion]
   31 |                         tmp[sa[i]]=tmp[sa[i-1]]+(compare_int(sa[i-1],sa[i])>0?1:0);
      |                                                                      ~~^~~
      |                                                                        |
      |                                                                        int
main.c:11:43: note: expected 'const void *' but argument is of type 'int'
   11 | int compare_int(const void *a,const void *b){
      |                               ~~~~~~~~~~~~^
main.c: In function 'construct_lcp':
main.c:41:12: error: subscripted value is neither array nor pointer nor vector
   41 |         lcp[0]=0;
      |            ^
main.c:49:20: error: subscripted value is neither array nor pointer nor vector
   49 |                 lcp[rank2[i]-1]=h;
      |                    ^
main.c: In function 'main':
main.c:61:28: error: passing argument 3 of 'construct_lcp' makes integer from pointer without a cast [-Wint-conversion]
   61 |         construct_lcp(s,sa,lcp);
      |                            ^~~
      |                            |
      |                            int *
main.c:37:40: note: expected 'int' but argument is of type 'int *'
   37 | void construct_lcp(char *s,int *sa,int lcp,int m){
      |                                    ~~~~^~~
main.c:61:9: error: too few arguments to function 'construct_lcp'
   61 |         construct_lcp(s,sa,lcp);
      |         ^~~~~~~~~~~~~
main.c:37:6: note: declared here
   37 | void construct_lcp(char *s,int *sa,int lcp,int m){
      |      ^~~~~~~~~~~~~