// 最悪計算量は確実にTLEするレベルだが // 実際は問題ない(と思いたい) #include #include using namespace std; #define inRange(x,a,b) (a <= x && x <= b) int main(){ int n; cin >> n; if(n > 26){ cout << "Impossible" << endl; return 0; } auto enc = [](string &s)->int{ int ret = 0; for(int i = s.length()-1; i >= 0; i--){ ret *= 52; if(inRange(s[i],'a','z')){ ret += s[i]-'a'; }else{ ret += 26 + s[i]-'A'; } } if(s.length() == 2) ret += 52; return ret; }; auto f = [](int i, string &s)->pair{ if(i == 0) return {s.substr(0,1), s.substr(1,2)}; else return {s.substr(0,2), s.substr(2,1)}; }; vector v(n); for(int i = 0; i < n; i++) cin >> v[i]; bool used[3000] = {}; for(int i = 0; i < 1< p = f((i>>j)&1, v[j]); int a = enc(p.first), b = enc(p.second); if(used[a] || used[b]){ while(--j >= 0){ p = f((i>>j)&1, v[j]); int a = enc(p.first), b = enc(p.second); used[a] = used[b] = false; } ng = true; break; }else{ used[a] = used[b] = true; } } if(ng) continue; // ok! for(int j = 0; j < n; j++){ pair p = f((i>>j)&1, v[j]); cout << p.first << " " << p.second << endl; } return 0; } cout << "Impossible" << endl; return 0; }