#include <bits/stdc++.h>
using namespace std;
const long long q = 239017;
const long long mod = 1e9 + 7;
const long long mod2 = 1e9 + 13;
const long long MAXN = 1e5 + 10;
const long long MAXM = 800;
const long long L = 26;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
pair<long long, long long> p[MAXN * 100];
vector<pair<long long, long long> > h[MAXN];
string v[MAXN];
void prec() {
  p[0] = {1, 1};
  for (long long i = 1; i < MAXN * 100; ++i)
    p[i] = {(p[i - 1].first * q) % mod, (p[i - 1].second * q) % mod2};
}
void calc(long long id) {
  h[id].resize((long long)v[id].size());
  if (!id) h[id].resize(1e6 + 10);
  h[id][0] = {v[id][0], v[id][0]};
  for (long long i = 1; i < (long long)v[id].size(); ++i)
    h[id][i] = {((h[id][i - 1].first * q) % mod + v[id][i]) % mod,
                ((h[id][i - 1].second * q) % mod2 + v[id][i]) % mod2};
}
pair<long long, long long> get(long long l, long long r, long long id) {
  pair<long long, long long> pref;
  if (l) pref = h[id][l - 1];
  return {
      (h[id][r].first - (p[r - l + 1].first * pref.first) % mod + mod) % mod,
      (h[id][r].second - (p[r - l + 1].second * pref.second) % mod2 + mod2) %
          mod2};
}
bool check(long long b, long long sz) {
  long long a = 0;
  long long l1 = (long long)v[a].size() - sz, r1 = (long long)v[a].size() - 1;
  long long l2 = 0, r2 = sz - 1;
  return get(l1, r1, a) == get(l2, r2, b);
}
void $main() {
  prec();
  long long n;
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> v[i];
    calc(i);
  }
  for (long long i = 1; i < n; ++i) {
    long long tl = 1, tr = min((long long)v[0].size(), (long long)v[i].size()),
              meg = 0;
    for (long long mid = tl; mid <= tr; ++mid)
      if (check(i, mid)) meg = mid;
    for (long long j = meg; j < (long long)v[i].size(); ++j) {
      v[0] += v[i][j];
      h[0][(long long)v[0].size() - 1] = {
          ((h[0][(long long)v[0].size() - 2].first * q) % mod + v[i][j]) % mod,
          ((h[0][(long long)v[0].size() - 2].second * q) % mod2 + v[i][j]) %
              mod2};
    }
  }
  cout << v[0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  $main();
  return 0;
}

### Prompt

Create a solution in cpp for the following problem:

Amugae has a sentence consisting of n words. He want to compress this sentence into one word. Amugae doesn't like repetitions, so when he merges two words into one word, he removes the longest prefix of the second word that coincides with a suffix of the first word. For example, he merges "sample" and "please" into "samplease".

Amugae will merge his sentence left to right (i.e. first merge the first two words, then merge the result with the third word and so on). Write a program that prints the compressed word after the merging process ends.

Input

The first line contains an integer n (1 ≤ n ≤ 10^5), the number of the words in Amugae's sentence.

The second line contains n words separated by single space. Each words is non-empty and consists of uppercase and lowercase English letters and digits ('A', 'B', ..., 'Z', 'a', 'b', ..., 'z', '0', '1', ..., '9'). The total length of the words does not exceed 10^6.

Output

In the only line output the compressed word after the merging process ends as described in the problem.

Examples

Input


5
I want to order pizza


Output


Iwantorderpizza

Input


5
sample please ease in out


Output


sampleaseinout

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long q = 239017;
const long long mod = 1e9 + 7;
const long long mod2 = 1e9 + 13;
const long long MAXN = 1e5 + 10;
const long long MAXM = 800;
const long long L = 26;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
pair<long long, long long> p[MAXN * 100];
vector<pair<long long, long long> > h[MAXN];
string v[MAXN];
void prec() {
  p[0] = {1, 1};
  for (long long i = 1; i < MAXN * 100; ++i)
    p[i] = {(p[i - 1].first * q) % mod, (p[i - 1].second * q) % mod2};
}
void calc(long long id) {
  h[id].resize((long long)v[id].size());
  if (!id) h[id].resize(1e6 + 10);
  h[id][0] = {v[id][0], v[id][0]};
  for (long long i = 1; i < (long long)v[id].size(); ++i)
    h[id][i] = {((h[id][i - 1].first * q) % mod + v[id][i]) % mod,
                ((h[id][i - 1].second * q) % mod2 + v[id][i]) % mod2};
}
pair<long long, long long> get(long long l, long long r, long long id) {
  pair<long long, long long> pref;
  if (l) pref = h[id][l - 1];
  return {
      (h[id][r].first - (p[r - l + 1].first * pref.first) % mod + mod) % mod,
      (h[id][r].second - (p[r - l + 1].second * pref.second) % mod2 + mod2) %
          mod2};
}
bool check(long long b, long long sz) {
  long long a = 0;
  long long l1 = (long long)v[a].size() - sz, r1 = (long long)v[a].size() - 1;
  long long l2 = 0, r2 = sz - 1;
  return get(l1, r1, a) == get(l2, r2, b);
}
void $main() {
  prec();
  long long n;
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> v[i];
    calc(i);
  }
  for (long long i = 1; i < n; ++i) {
    long long tl = 1, tr = min((long long)v[0].size(), (long long)v[i].size()),
              meg = 0;
    for (long long mid = tl; mid <= tr; ++mid)
      if (check(i, mid)) meg = mid;
    for (long long j = meg; j < (long long)v[i].size(); ++j) {
      v[0] += v[i][j];
      h[0][(long long)v[0].size() - 1] = {
          ((h[0][(long long)v[0].size() - 2].first * q) % mod + v[i][j]) % mod,
          ((h[0][(long long)v[0].size() - 2].second * q) % mod2 + v[i][j]) %
              mod2};
    }
  }
  cout << v[0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  $main();
  return 0;
}

```