#include<bits/stdc++.h>
using namespace std;
int main(){
int N, D, risF=1;
cin >> N >> D;
vector<string> word(N);
vector<int> R(N, 0);
for(int i=0; i<N; i++){
cin >> word[i];
}
for(int i=0;i<N;i++){
if(R[i]==0){
int ris=1;
for(int j=i+1;j<N; j++){
if(R[j]==0){
char cost;
if(word[i][0]-word[j][0]<0)
cost=word[i][0]-word[j][0]+26;
else
cost=word[i][0]-word[j][0];
int t=0;
for(int z=1;z<D;z++){
char cost2;
if(word[i][z]-word[j][z]<0)
cost2=word[i][z]-word[j][z]+26;
else
cost2=word[i][z]-word[j][z];
if(cost!=cost2){
t=1;
break;
}
}
if(t==0){
ris++;
R[j]=1;
}
}
}
if(risF<ris)
risF=ris;
}
}
cout << risF << endl;
}
Non so come ottimizzare, idee?