Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pp pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 /*int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }*/
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int a){
	par= vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0)
      return a;
    else
      return par[a]=find(par[a]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int gcm(int a,int b){
    if(b==0)
        return a;
    return gcm(b,a%b);
}
int lcm(int a,int b){
    return a/gcm(a,b)*b;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
/*struct dfs(){

}*/
signed main(){
	string a,c;
	cin>>a;
	int b=1000000,d,e;
	for(char i='a';i<'z';i++){
		a=c;
		d=1;
		e=0;
		for(int j=0;j<a.sz;j++){
			Sort(a);
		    if(a[0]==a[a.sz-1]){
		    	b=min(b,e);
		    	break;
		    }
		    if(a[j]==i){
		    	a[j-1]=i;
		    	d=0;
		    }
		    if(j==a.sz-1){
		    	if(d)
		    		break;
		    	else{
		    		d=0;
		    		e++;
		    		a.pp;
		    	}
		    }
		}
	}
	cout<<e<<endl;
}
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pp pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 /*int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }*/
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int a){
	par= vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0)
      return a;
    else
      return par[a]=find(par[a]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int gcm(int a,int b){
    if(b==0)
        return a;
    return gcm(b,a%b);
}
int lcm(int a,int b){
    return a/gcm(a,b)*b;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
/*struct dfs(){

}*/
signed main(){
	string a,c;
	cin>>a;
	int b=1000000,d,e;
	for(char i='a';i<'z';i++){
		a=c;
		d=1;
		e=0;
		for(int j=0;j<a.sz;j++){
			Sort(a);
		    if(a[0]==a[a.sz-1])a{
		    	b=min(b,e);
		    	break;
		    }
		    if(a[j]==i){
		    	a[j-1]=i;
		    	d=0;
		    }
		    if(j==a.sz-1){
		    	if(d)
		    		break;
		    	else{
		    		d=0;
		    		e++;
		    		a.pp;
		    	}
		    }
		}
	}
	cout<<e<<endl;
}

Compiler output:
a.cc:13:9: warning: "fi" redefined
   13 | #define fi first
      |         ^~
a.cc:7:9: note: this is the location of the previous definition
    7 | #define fi first#include<bits/stdc++.h>
      |         ^~
a.cc:241:7: error: redefinition of 'template<class T> void cou(std::vector<std::vector<_Tp> >)'
  241 |  void cou(vector<vector<T>> a){
      |       ^~~
a.cc:31:7: note: 'template<class T> void cou(std::vector<std::vector<_Tp> >)' previously declared here
   31 |  void cou(vector<vector<T>> a){
      |       ^~~
a.cc:268:6: error: redefinition of 'long long int wari(long long int, long long int)'
  268 |  int wari(int a,int b) {
      |      ^~~~
a.cc:58:6: note: 'long long int wari(long long int, long long int)' previously defined here
   58 |  int wari(int a,int b) {
      |      ^~~~
a.cc:274:6: error: redefinition of 'long long int keta(long long int)'
  274 |  int keta(int a){
      |      ^~~~
a.cc:64:6: note: 'long long int keta(long long int)' previously defined here
   64 |  int keta(int a){
      |      ^~~~
a.cc:280:6: error: redefinition of 'long long int souwa(long long int)'
  280 |  int souwa(int a){
      |      ^~~~~
a.cc:70:6: note: 'long long int souwa(long long int)' previously defined here
   70 |  int souwa(int a){
      |      ^~~~~
a.cc:319:7: error: redefinition of 'bool prime(long long int)'
  319 |  bool prime(int a){
      |       ^~~~~
a.cc:109:7: note: 'bool prime(long long int)' previously defined here
  109 |  bool prime(int a){
      |       ^~~~~
a.cc:334:8: error: redefinition of 'struct Union'
  334 | struct Union{
      |        ^~~~~
a.cc:124:8: note: previous definition of 'struct Union'
  124 | struct Union{
      |        ^~~~~
a.cc:362:5: error: redefinition of 'long long int ketas(long long int)'
  362 | int ketas(int a){
      |     ^~~~~
a.cc:152:5: note: 'long long int ketas(long long int)' previously defined here
  152 | int ketas(int a){
      |     ^~~~~
a.cc:370:5: error: redefinition of 'long long int gcm(long long int, long long int)'
  370 | int gcm(int a,int b){
      |     ^~~
a.cc:160:5: note: 'long long int gcm(long long int, long long int)' previously defined here
  160 | int gcm(int a,int b){
      |     ^~~
a.cc:375:5: error: redefinition of 'long long int lcm(long long int, long long int)'
  375 | int lcm(int a,int b){
      |     ^~~
a.cc:165:5: note: 'long long int lcm(long long int, long long int)' previously defined here
  165 | int lcm(int a,int b){
      |     ^~~
a.cc:403:8: error: redefinition of 'int main()'
  403 | signed main(){
      |        ^~~~
a.cc:193:8: note: 'int main()' previously defined here
  193 | signed main(){
      |        ^~~~
a.cc: In function 'int main()':
a.cc:413:41: error: expected ';' before '{' token
  413 |                     if(a[0]==a[a.sz-1])a{
      |                                         ^
      |                                         ;