#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
T power(T b, U n) {
  assert(n >= 0);
  T ans = 1;
  for (; n > 0; n /= 2, b *= b)
    if (n & 1) ans *= b;
  return ans;
}
long long power(long long b, long long n, long long mod) {
  assert(n >= 0);
  long long ans = 1;
  for (; n > 0; n /= 2, b = (b * b) % mod)
    if (n & 1) ans = (ans * b) % mod;
  return ans;
}
template <long long mod>
struct Modular {
  long long val;
  Modular() {}
  Modular(long long _val) { val = _val; }
  Modular normalize(const long long x) {
    val = x % mod;
    if (val < 0) val += mod;
    return val;
  }
  bool operator==(const Modular &a) { return val == a.val; }
  bool operator!=(const Modular &a) { return val != a.val; }
  Modular operator=(long long x) { return normalize(x); }
  Modular operator=(const Modular &x) {
    val = x.val;
    return *this;
  }
  Modular operator+=(const Modular &a) { return normalize(val + a.val); }
  Modular operator-=(const Modular &a) { return normalize(val - a.val); }
  Modular operator*=(const Modular &a) { return normalize(val * a.val); }
  Modular operator/=(const Modular &b) {
    return normalize(val * inverse(b).val);
  }
  friend Modular operator^(Modular b, long long n) { return power(b, n); }
  friend Modular inverse(Modular b) { return b ^ (mod - 2); }
  friend Modular operator+(Modular a, const Modular &b) { return a += b; }
  friend Modular operator-(Modular a, const Modular &b) { return a -= b; }
  friend Modular operator*(Modular a, const Modular &b) { return a *= b; }
  friend Modular operator/(Modular a, const Modular &b) { return a /= b; }
  friend Modular operator+(Modular a, long long b) { return a += b; }
  friend Modular operator-(Modular a, long long b) { return a -= b; }
  friend Modular operator*(Modular a, long long b) { return a *= b; }
  friend Modular operator/(Modular a, long long b) { return a /= b; }
  friend Modular operator+(long long b, Modular a) { return a += b; };
  friend Modular operator-(long long b, const Modular &a) {
    Modular c(b);
    return c -= a;
  }
  friend Modular operator*(long long b, Modular a) { return a *= b; };
  friend Modular operator/(long long b, const Modular &a) {
    Modular c(b);
    return c /= a;
  }
  friend istream &operator>>(istream &in, Modular &a) {
    long long x;
    in >> x;
    a.normalize(x);
    return in;
  }
  friend ostream &operator<<(ostream &out, const Modular &a) {
    return out << a.val;
  }
};
const int mx = 1e6 + 5;
const long long mod1 = 998244353;
const long long mod2 = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  vector<string> vec(n);
  for (string &x : vec) cin >> x;
  vector<Modular<mod1> > pwr1(mx + 1, 1);
  for (int i = 1; i <= mx; i++) pwr1[i] = pwr1[i - 1] * 31;
  vector<Modular<mod2> > pwr2(mx + 1, 1);
  for (int i = 1; i <= mx; i++) pwr2[i] = pwr2[i - 1] * 29;
  vector<Modular<mod1> > pref1(1, 0);
  vector<Modular<mod2> > pref2(1, 0);
  string ans = vec[0];
  int sz = ans.size();
  int p = mx;
  for (int i = 0; i < sz; i++, p--) {
    pref1.push_back(pref1.back() + pwr1[p] * ans[i]);
    pref2.push_back(pref2.back() + pwr2[p] * ans[i]);
  }
  for (string x : vec) {
    Modular<mod1> curr1 = 0;
    Modular<mod2> curr2 = 0;
    int maxi = -1;
    int limit = min(sz, int(x.size()));
    for (int i = 0, j = mx; i < limit; i++, j--) {
      curr1 += pwr1[j] * x[i];
      curr2 += pwr2[j] * x[i];
      Modular<mod1> temp1 = pref1[sz] - pref1[sz - i - 1];
      temp1 *= pwr1[sz - i - 1];
      Modular<mod2> temp2 = pref2[sz] - pref2[sz - i - 1];
      temp2 *= pwr2[sz - i - 1];
      if (temp1 == curr1 && temp2 == curr2) maxi = i;
    }
    string now = x.substr(maxi + 1);
    ans += now;
    for (int i = 0; i < now.size(); i++, p--) {
      pref1.push_back(pref1.back() + pwr1[p] * now[i]);
      pref2.push_back(pref2.back() + pwr2[p] * now[i]);
      sz++;
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int testcase = 1;
  for (int i = 1; i <= testcase; i++) {
    solve();
  }
  return 0;
}

### Prompt

Please create a solution in CPP to 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;
template <typename T, typename U>
T power(T b, U n) {
  assert(n >= 0);
  T ans = 1;
  for (; n > 0; n /= 2, b *= b)
    if (n & 1) ans *= b;
  return ans;
}
long long power(long long b, long long n, long long mod) {
  assert(n >= 0);
  long long ans = 1;
  for (; n > 0; n /= 2, b = (b * b) % mod)
    if (n & 1) ans = (ans * b) % mod;
  return ans;
}
template <long long mod>
struct Modular {
  long long val;
  Modular() {}
  Modular(long long _val) { val = _val; }
  Modular normalize(const long long x) {
    val = x % mod;
    if (val < 0) val += mod;
    return val;
  }
  bool operator==(const Modular &a) { return val == a.val; }
  bool operator!=(const Modular &a) { return val != a.val; }
  Modular operator=(long long x) { return normalize(x); }
  Modular operator=(const Modular &x) {
    val = x.val;
    return *this;
  }
  Modular operator+=(const Modular &a) { return normalize(val + a.val); }
  Modular operator-=(const Modular &a) { return normalize(val - a.val); }
  Modular operator*=(const Modular &a) { return normalize(val * a.val); }
  Modular operator/=(const Modular &b) {
    return normalize(val * inverse(b).val);
  }
  friend Modular operator^(Modular b, long long n) { return power(b, n); }
  friend Modular inverse(Modular b) { return b ^ (mod - 2); }
  friend Modular operator+(Modular a, const Modular &b) { return a += b; }
  friend Modular operator-(Modular a, const Modular &b) { return a -= b; }
  friend Modular operator*(Modular a, const Modular &b) { return a *= b; }
  friend Modular operator/(Modular a, const Modular &b) { return a /= b; }
  friend Modular operator+(Modular a, long long b) { return a += b; }
  friend Modular operator-(Modular a, long long b) { return a -= b; }
  friend Modular operator*(Modular a, long long b) { return a *= b; }
  friend Modular operator/(Modular a, long long b) { return a /= b; }
  friend Modular operator+(long long b, Modular a) { return a += b; };
  friend Modular operator-(long long b, const Modular &a) {
    Modular c(b);
    return c -= a;
  }
  friend Modular operator*(long long b, Modular a) { return a *= b; };
  friend Modular operator/(long long b, const Modular &a) {
    Modular c(b);
    return c /= a;
  }
  friend istream &operator>>(istream &in, Modular &a) {
    long long x;
    in >> x;
    a.normalize(x);
    return in;
  }
  friend ostream &operator<<(ostream &out, const Modular &a) {
    return out << a.val;
  }
};
const int mx = 1e6 + 5;
const long long mod1 = 998244353;
const long long mod2 = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  vector<string> vec(n);
  for (string &x : vec) cin >> x;
  vector<Modular<mod1> > pwr1(mx + 1, 1);
  for (int i = 1; i <= mx; i++) pwr1[i] = pwr1[i - 1] * 31;
  vector<Modular<mod2> > pwr2(mx + 1, 1);
  for (int i = 1; i <= mx; i++) pwr2[i] = pwr2[i - 1] * 29;
  vector<Modular<mod1> > pref1(1, 0);
  vector<Modular<mod2> > pref2(1, 0);
  string ans = vec[0];
  int sz = ans.size();
  int p = mx;
  for (int i = 0; i < sz; i++, p--) {
    pref1.push_back(pref1.back() + pwr1[p] * ans[i]);
    pref2.push_back(pref2.back() + pwr2[p] * ans[i]);
  }
  for (string x : vec) {
    Modular<mod1> curr1 = 0;
    Modular<mod2> curr2 = 0;
    int maxi = -1;
    int limit = min(sz, int(x.size()));
    for (int i = 0, j = mx; i < limit; i++, j--) {
      curr1 += pwr1[j] * x[i];
      curr2 += pwr2[j] * x[i];
      Modular<mod1> temp1 = pref1[sz] - pref1[sz - i - 1];
      temp1 *= pwr1[sz - i - 1];
      Modular<mod2> temp2 = pref2[sz] - pref2[sz - i - 1];
      temp2 *= pwr2[sz - i - 1];
      if (temp1 == curr1 && temp2 == curr2) maxi = i;
    }
    string now = x.substr(maxi + 1);
    ans += now;
    for (int i = 0; i < now.size(); i++, p--) {
      pref1.push_back(pref1.back() + pwr1[p] * now[i]);
      pref2.push_back(pref2.back() + pwr2[p] * now[i]);
      sz++;
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int testcase = 1;
  for (int i = 1; i <= testcase; i++) {
    solve();
  }
  return 0;
}

```