#include <bits/stdc++.h>
using namespace std;
inline void boostIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
}
int Mod = 1e9 + 7;
int inf = 2e9;
const int Y = 1;
struct Hash {
  string s;
  int n;
  vector<int> H;
  vector<int> P;
  int K;
  int p;
  Hash(string& z) {
    K = 1e9 + 7;
    p = 29;
    s = z;
    n = z.size();
    H.assign(z.size() + 1, 0);
    P.assign(z.size() + 1, 0);
    H[0] = 1;
    P[0] = 1;
    for (int i = 1; i <= n; ++i) {
      H[i] = (1ll * H[i - 1] * p + (s[i - 1] + 1)) % K;
      P[i] = 1ll * P[i - 1] * p % K;
    }
  }
  int Get(int l, int r) {
    int v;
    v = (H[r + 1] - 1ll * H[l] * P[r - l + 1] % K + K);
    if (v >= K) v -= K;
    return v;
  }
  int GetWH(int l, int r, int a) {
    int aa;
    int bb;
    aa = Get(l, a - 1);
    bb = Get(a + 1, r);
    int sizea = ((a - 1) - l + 1);
    int sizeb = (r - (a + 1) + 1);
    int v;
    int g = P[sizeb];
    v = (1ll * aa * g + bb) % K;
    return v;
  }
};
char SYM(string& s, Hash& h, int a, int m) {
  char asym;
  if (m < a)
    asym = s[m];
  else
    asym = s[m + 1];
  return asym;
}
int HSWL(string& s, Hash& h, int a, int m) {
  if (m < a) {
    return h.Get(0, m);
  } else {
    if (a != 0) {
      return h.GetWH(0, m + 1, a);
    } else {
      return h.Get(1, m + 1);
    }
  }
}
char CWL(string& s, Hash& h, int a, string& s2, Hash& h2, int a2) {
  int n = (int)min(s.size(), s2.size()) - 1;
  int l = -1;
  int r = n;
  while (r - l > 1) {
    int m = (r + l) / 2;
    if (HSWL(s, h, a, m) == HSWL(s2, h2, a2, m)) {
      l = m;
    } else {
      r = m;
    }
  }
  int s_size = s.size();
  int s2_size = s2.size();
  if (a < s.size()) s_size--;
  if (a2 < s2.size()) s2_size--;
  if ((r + 1 == s_size || r + 1 == s2_size) &&
      SYM(s, h, a, r) == SYM(s2, h2, a2, r)) {
    return s_size <= s2_size;
  }
  return SYM(s, h, a, r) <= SYM(s2, h2, a2, r);
}
vector<int> Sort(string& s, Hash& h, vector<char>& nxt) {
  int n = s.size() + 1;
  vector<int> A(n);
  int l = 0;
  int r = 0;
  for (int i = n - 2; i >= 0; --i) {
    if (s[i] > nxt[i]) {
      --l;
      A[i] = l;
    } else {
      ++r;
      A[i] = r;
    }
  }
  int Min = inf;
  for (int i = 0; i < n; ++i) {
    Min = min(Min, A[i]);
  }
  for (int i = 0; i < n; ++i) {
    A[i] += (-Min);
  }
  vector<int> Order(n);
  for (int i = 0; i < n; ++i) {
    Order[A[i]] = i;
  }
  return Order;
}
int32_t main() {
  boostIO();
  int n;
  cin >> n;
  vector<string> S(n + 1);
  vector<vector<int>> dp(n + 1);
  vector<vector<char>> nxt(n + 1);
  vector<Hash> H;
  for (int i = 0; i <= n; ++i) {
    if (i != 0)
      cin >> S[i];
    else {
      S[i].push_back('#');
    }
    vector<int> temp(S[i].size() + 1);
    vector<char> temp2(S[i].size());
    dp[i] = temp;
    nxt[i] = temp2;
    H.push_back(Hash(S[i]));
  }
  for (int i = 0; i <= n; ++i) {
    char x1, x2, x3;
    x3 = '#';
    x2 = S[i][S[i].size() - 1];
    nxt[i][S[i].size() - 1] = x3;
    for (int j = (int)S[i].size() - 2; j >= 0; --j) {
      x1 = S[i][j];
      if (x1 == x2) {
        x2 = x3;
      }
      nxt[i][j] = x2;
      x3 = x2;
      x2 = x1;
    }
  }
  vector<vector<int>> ML(n + 1);
  for (int i = 0; i <= n; ++i) {
    ML[i] = Sort(S[i], H[i], nxt[i]);
  }
  int g = 1;
  int sum = 0;
  int prsum = 1;
  for (int i = 1; i <= n; ++i) {
    int p = ML[i - 1].size() - 1;
    int c = ML[i].size() - 1;
    for (c; c >= 0; --c) {
      while (p >= 0 &&
             !CWL(S[i - 1], H[i - 1], ML[i - 1][p], S[i], H[i], ML[i][c])) {
        prsum = (prsum - dp[i - 1][p] + Mod);
        if (prsum >= Mod) prsum -= Mod;
        --p;
      }
      dp[i][c] = (prsum);
      sum = (sum + dp[i][c]);
      if (sum >= Mod) sum -= Mod;
    }
    prsum = sum;
    sum = 0;
  }
  cout << prsum << '\n';
  cerr << '\n' << "RUNTIME: " << 1.0 * clock() / CLOCKS_PER_SEC << " s" << '\n';
  return 0;
  ;
}
