#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin>>N; vector>A; for(int i=0;i>S; bool ok=true; for(int j=0;jS[j+1])ok=false; } if(ok)A.push_back({S[0]-'a',S.back()-'a',S.size()}); } sort(A.begin(),A.end()); vectordp(27); for(auto i:A){ dp[i[1]]=max(dp[i[1]],dp[i[0]]+i[2]); for(int j=0;j<26;j++){ dp[j+1]=max(dp[j+1],dp[j]); } } cout<