9
lfpgbnlzyn
c
s
w
r
m
q
y
yinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy
 6
u
p
m
z
v
vv
 4
qe
nd
iqryhukieskfvaeettersinksrmazelxtgvartuz
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 6
nf
ysvchtjkfgsbyfzxjaykey
advqnf
wl
pi
ppppfvvmaebvhkoagppppp
 3
j
k
kkailgwqnxtdsttkkkkkkk
 4
o
yhnx
e
ennn
 10
j
dyfu
udzj
wwow
xtnw
f
c
q
o
gggg
 6
w
g
c
j
y
f
 4
r
o
w
wwwwwwwwww
 2
zxwp
ppppctfisvflhtjggg
 5
m
g
u
t
tttt
 2
n
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 3
lt
en
eeeeeeeeee
 4
vr
hp
l
llbn

7 5 541 10 10 4 4 1 21 5 9 93 21 3
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <random>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
 
using namespace std;
using namespace __gnu_pbds;
 	// find_by_order()  // order_of_key
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define fc(i,a,b) for(ll i =a ;i<=b ;i++)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inff (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
#define SPEED ios_base::sync_with_stdio(false) ;cin.tie(NULL) ;cout.tie(NULL) ;
#define fp(i,a,n) for(ll i=n-1; i>a ;i--)
#define deb(x) cout << #x << " ---> " << x << endl;
#define X first
#define Y second
#define pia 3.1415926536
#define mod 1000000007
#define mod2 998244353
#define vvi vector<vi>
#define ml map<ll,ll>
#define mll map<pll,ll>
#define vvl vector<vl>
#define letsh(a,b) a<<b
#define rigsh(a,b) a>>b 
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()) ;
	  
		ll lcm(ll a, ll b){
               return a / __gcd(a, b) * b;
       }
	   bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 	   

          ll power(ll a,ll n)
	   {
        ll ans=1;
        while(n)
		{
        if(n&1) ans=(ans*a)%mod;
        a=(a*a)%mod ;
        n=n>>1;
   		 }
   		 return ans;
      }
      ll power2(ll a,ll n)
      {
      	ll ans =1 ;
      	while(n)
      	{
      		if(n&1) ans =(ans*a)%mod2 ;
      		a = (a*a)%mod2 ;
      		n =n>>1 ;
		  }
		  return ans ;
	  }
	  void p1(ll x,ll y)
	  {
	  	cout<<x<<" "<<y<<" "<<endl ;
	  }
      #define N 5000
	  vvl dir({{1, 0}, {-1, 0}, {0, 1}, {0, -1}});
	  int main() 
	  	{
	  		SPEED
	        int n; cin>>n ;
	       vector<string> p(n) ;
	       f(i,0,n) cin>>p[i] ;
	       int dp[26] ={0} ,dp1[26] ={0} ;
	       f(i,0,n)
		   {
		   	int m =p[i].size() ;
		   	 
		   	 f(j,0,m) dp1[p[i][j]-'a']++ ;
		   	 int tem =p[i][0]-'a' ;int tem1 =p[i][m-1]-'a' ;
			 if(dp1[p[i][0]-'a'] ==m )
			 {
			 	dp[p[i][0]-'a'] = ((dp[tem]+1)*m +dp[tem]) ;
 			  }
			 else
			 {	
			 	int cnt =0 ,cnt1=0 ;
			 	f(k,0,m) if((p[i][k]-'a') == tem) cnt++ ;
					 else break ;
					 fd(k,m-1,0)  if((p[i][k]-'a') == tem1) cnt1++ ;
					 else break ;
				if(i !=0){
				 if(tem ==tem1) 
			 	{
			 	 dp[tem] = max(dp1[tem] ,cnt+cnt1+min(1,dp[tem])) ; 	 
				}
				else
				{
				dp[tem] = max(dp1[tem] ,cnt+min(1,dp[tem])) ;
				dp[tem1] =max(dp1[tem1] ,cnt1+ min(1,dp[tem1])) ;
				}
			  }
		     }
	        dp1[tem] =dp1[tem1] =0 ;
			  f(j,0,26) if(j != tem && j !=tem1 )dp[j] = max(min(1,dp[j]),dp1[j]) ,dp1[j] =0 ; 
		   }
		   int ans =0 ;
		   f(i,0,26) ans = max(ans,dp[i]) ;
		   cout<<ans<<endl ;
		}