#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

template<typename flow_t>
struct Dinic {
    struct Edge {
        int to; flow_t cap; int rev; bool isrev;
        Edge(int t, flow_t c, int r, bool b) : to(t), cap(c), rev(r), isrev(b) { }
    };
    const flow_t INF;
    vector<vector<Edge>> g;
    vector<int> min_cost, iter;
    Dinic(int n) : INF(numeric_limits<flow_t>::max()), g(n) { }
    void add_edge(int from, int to, flow_t cap) {
        g[from].emplace_back(Edge(to, cap, g[to].size(), false));
        g[to].emplace_back(Edge(from, 0, g[from].size() - 1, true));
    }
    bool bfs(int s, int t) {
        min_cost.assign(g.size(), -1); min_cost[s] = 0;
        queue<int> que; que.emplace(s);
        while (!que.empty() && min_cost[t] == -1) {
            int v = que.front(); que.pop();
            for (auto &e: g[v]) if (e.cap > 0 && min_cost[e.to] == -1) {
                min_cost[e.to] = min_cost[v] + 1;
                que.emplace(e.to);
            }
        }
        return min_cost[t] != -1;
    }
    flow_t dfs(int v, int t, flow_t flow) {
        if (v == t) return flow;
        for (int &i = iter[v]; i < (int)g[v].size(); i++) {
            Edge &e = g[v][i];
            if (e.cap > 0 && min_cost[v] < min_cost[e.to]) {
                flow_t d = dfs(e.to, t, min(flow, e.cap));
                if (d > 0) {
                    e.cap -= d, g[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    flow_t max_flow(int s, int t) {
        flow_t flow = 0;
        while (bfs(s, t)) {
            iter.assign(g.size(), 0);
            flow_t f = 0;
            while ((f = dfs(s, t, INF)) > 0) flow += f;
        }
        return flow;
    }
    friend ostream& operator<<(ostream& os, Dinic& mf) {
        for (int i = 0; i < (int)mf.g.size(); i++) {
            for (auto &e: mf.g[i]) if (!e.isrev) {
                auto &rev_e = mf.g[e.to][e.rev];
                os << i << " -> " << e.to << " (flow: ";
                os << rev_e.cap << " / " << e.cap + rev_e.cap << ")" << endl;
            }
        }
        return os;
    }
};

int main() {
    int n; cin >> n;
    vector<string> ss(n);
    for (auto &si: ss) cin >> si;
    string ans;
    for (int c = 0; c < 26; c++) {
        Dinic<int> mf(26 + 2);
        int s = 26, t = s + 1;
        int deg_out = 0, deg_in = 0;
        for (auto &si: ss) {
            int u = si.front() - 'a', v = si.back() - 'a';
            if (u == c) u = s, deg_out++;
            if (v == c) v = t, deg_in++;
            mf.add_edge(u, v, 1);
        }
        if (deg_in && mf.max_flow(s, t) == deg_out) ans += 'a' + c;
    }
    for (char c: ans) cout << c << endl;
    return 0;
}


### Prompt

Create a solution in Cpp for the following problem:

Problem

Here is a list of strings. Let's take a break and play with shiritori. Shiritori is performed according to the following rules.

1. First of all, select one of your favorite strings from the list and exclude that string from the list.
2. Next, select one character string from the list in which the last character of the previously selected character string is the first character.
3. Exclude the selected string from the list.



After this, steps 2 and 3 will be repeated alternately.

Now, let's assume that this shiritori is continued until there are no more strings to select from the list in 2. At this time, I want to list all the characters that can be the "last character" of the last selected character string.

Constraints

The input satisfies the following conditions.

* $ 1 \ le N \ lt 10 ^ 4 $
* $ 1 \ le | s_i | \ lt 100 $
* $ s_i \ neq s_j (i \ neq j) $
* The string contains only lowercase letters

Input


$ N $
$ s_1 $
$ s_2 $
$ s_3 $
::
$ s_N $


The number of strings $ N $ is given on the first line.
The following $ N $ line is given a list of strings.

Output

Output the characters that can be the "last character" of the last selected character string in ascending order from a to z in lexicographical order.

Examples

Input

5
you
ate
my
hum
toast


Output

e
t
u


Input

7
she
sells
sea
shells
by
the
seashore


Output

a
e
y

### Response

```cpp
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

template<typename flow_t>
struct Dinic {
    struct Edge {
        int to; flow_t cap; int rev; bool isrev;
        Edge(int t, flow_t c, int r, bool b) : to(t), cap(c), rev(r), isrev(b) { }
    };
    const flow_t INF;
    vector<vector<Edge>> g;
    vector<int> min_cost, iter;
    Dinic(int n) : INF(numeric_limits<flow_t>::max()), g(n) { }
    void add_edge(int from, int to, flow_t cap) {
        g[from].emplace_back(Edge(to, cap, g[to].size(), false));
        g[to].emplace_back(Edge(from, 0, g[from].size() - 1, true));
    }
    bool bfs(int s, int t) {
        min_cost.assign(g.size(), -1); min_cost[s] = 0;
        queue<int> que; que.emplace(s);
        while (!que.empty() && min_cost[t] == -1) {
            int v = que.front(); que.pop();
            for (auto &e: g[v]) if (e.cap > 0 && min_cost[e.to] == -1) {
                min_cost[e.to] = min_cost[v] + 1;
                que.emplace(e.to);
            }
        }
        return min_cost[t] != -1;
    }
    flow_t dfs(int v, int t, flow_t flow) {
        if (v == t) return flow;
        for (int &i = iter[v]; i < (int)g[v].size(); i++) {
            Edge &e = g[v][i];
            if (e.cap > 0 && min_cost[v] < min_cost[e.to]) {
                flow_t d = dfs(e.to, t, min(flow, e.cap));
                if (d > 0) {
                    e.cap -= d, g[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    flow_t max_flow(int s, int t) {
        flow_t flow = 0;
        while (bfs(s, t)) {
            iter.assign(g.size(), 0);
            flow_t f = 0;
            while ((f = dfs(s, t, INF)) > 0) flow += f;
        }
        return flow;
    }
    friend ostream& operator<<(ostream& os, Dinic& mf) {
        for (int i = 0; i < (int)mf.g.size(); i++) {
            for (auto &e: mf.g[i]) if (!e.isrev) {
                auto &rev_e = mf.g[e.to][e.rev];
                os << i << " -> " << e.to << " (flow: ";
                os << rev_e.cap << " / " << e.cap + rev_e.cap << ")" << endl;
            }
        }
        return os;
    }
};

int main() {
    int n; cin >> n;
    vector<string> ss(n);
    for (auto &si: ss) cin >> si;
    string ans;
    for (int c = 0; c < 26; c++) {
        Dinic<int> mf(26 + 2);
        int s = 26, t = s + 1;
        int deg_out = 0, deg_in = 0;
        for (auto &si: ss) {
            int u = si.front() - 'a', v = si.back() - 'a';
            if (u == c) u = s, deg_out++;
            if (v == c) v = t, deg_in++;
            mf.add_edge(u, v, 1);
        }
        if (deg_in && mf.max_flow(s, t) == deg_out) ans += 'a' + c;
    }
    for (char c: ans) cout << c << endl;
    return 0;
}


```