Roman and Denis are on the trip to the programming competition. Since the trip was long, they soon got bored, and hence decided to came up with something. Roman invented a pizza's recipe, while Denis invented a string multiplication. According to Denis, the result of multiplication (product) of strings s of length m and t is a string t + s_1 + t + s_2 + … + t + s_m + t, where s_i denotes the i-th symbol of the string s, and "+" denotes string concatenation. For example, the product of strings "abc" and "de" is a string "deadebdecde", while the product of the strings "ab" and "z" is a string "zazbz". Note, that unlike the numbers multiplication, the product of strings s and t is not necessarily equal to product of t and s.

Roman was jealous of Denis, since he invented such a cool operation, and hence decided to invent something string-related too. Since Roman is beauty-lover, he decided to define the beauty of the string as the length of the longest substring, consisting of only one letter. For example, the beauty of the string "xayyaaabca" is equal to 3, since there is a substring "aaa", while the beauty of the string "qwerqwer" is equal to 1, since all neighboring symbols in it are different.

In order to entertain Roman, Denis wrote down n strings p_1, p_2, p_3, …, p_n on the paper and asked him to calculate the beauty of the string ( … (((p_1 ⋅ p_2) ⋅ p_3) ⋅ … ) ⋅ p_n, where s ⋅ t denotes a multiplication of strings s and t. Roman hasn't fully realized how Denis's multiplication works, so he asked you for a help. Denis knows, that Roman is very impressionable, he guarantees, that the beauty of the resulting string is at most 10^9.

Input

The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of strings, wroted by Denis.

Next n lines contain non-empty strings p_1, p_2, …, p_n, consisting of lowercase english letters.

It's guaranteed, that the total length of the strings p_i is at most 100 000, and that's the beauty of the resulting product is at most 10^9.

Output

Print exactly one integer — the beauty of the product of the strings.

Examples

Input


3
a
b
a


Output


3


Input


2
bnn
a


Output


1

Note

In the first example, the product of strings is equal to "abaaaba".

In the second example, the product of strings is equal to "abanana".
#include <bits/stdc++.h>
using namespace std;
long long M = 100000007;
long long size[100005];
bool complete[100005][30];
long long longest[100005][30];
long long rigth[100005][30];
long long left[100005][30];
long long Wrigth[100005][30];
long long Wleft[100005][30];
long long Wlongest[100005][30];
long long Wsize[100005];
bool Wcomplete[100005][30];
int main() {
  int n;
  cin >> n;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    Wsize[i] = s.size();
    if (i == 0) {
      size[i] = s.size();
    } else {
      size[i] = size[i - 1] + (size[i - 1] + 1LL) * s.size();
    }
    for (int j = 0; j < 28; j++) {
      long long count = 0;
      while (count < s.size() && s[count] - 'a' == j) {
        count++;
      }
      if (count == s.size()) {
        Wcomplete[i][j] = true;
      }
      Wleft[i][j] = count;
      count = 0;
      while (count < s.size() && s[s.size() - 1 - count] - 'a' == j) {
        count++;
      }
      Wrigth[i][j] = count;
      count = 0;
      long long lon = 0;
      for (int k = 0; k < s.size(); k++) {
        if (s[k] - 'a' == j) {
          count++;
          lon = max(lon, count);
        } else {
          count = 0;
        }
      }
      Wlongest[i][j] = lon;
    }
  }
  long long result = 0;
  for (int j = 0; j < 28; j++) {
    complete[0][j] = Wcomplete[0][j];
    longest[0][j] = Wlongest[0][j];
    for (int i = 1; i < n; i++) {
      if (complete[i - 1][j] && Wcomplete[i][j]) {
        longest[i][j] = size[i];
        complete[i][j] = true;
      } else if (Wcomplete[i][j]) {
        longest[i][j] =
            longest[i - 1][j] + (longest[i - 1][j] + 1LL) * Wsize[i];
      } else {
        if (longest[i - 1][j] > 0) {
          longest[i][j] = max(1LL + Wleft[i][j] + Wrigth[i][j], Wlongest[i][j]);
        } else {
          longest[i][j] = Wlongest[i][j];
        }
      }
    }
    result = max(result, longest[n - 1][j]);
  }
  cout << result << '\n';
  return 0;
}
