#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 0
#else
#include "../template/debug.cpp"
#endif
using namespace std;
using ll = int_fast64_t;
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define pq priority_queue
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORE(i,a,b) for(int i = (a); i <= (b); ++i)
#define ROF(i,a,b) for(int i = (a); i >= (b); --i)
#define trav(a,x) for(auto& a: x)
#define ****(x) trav(i,x) cin >> i
#define sz(x) (int)x.size()
template<class T> using minpq = pq<T, vector<T>, greater<T>>;
template<class T> bool ckmin(T& a, const T& b){return b<a?a=b,1:0;}
template<class T> bool ckmax(T& a, const T& b){return a<b?a=b,1:0;}
template<int D, typename T>struct vt : public vector<vt<D - 1, T>> { template<typename... Args>
vt(int n = 0, Args... args) : vector<vt<D - 1, T>>(n, vt<D - 1, T>(args...)) {}};
template<typename T> struct vt<1, T> : public vector<T> {
vt(int n = 0, const T& val = T()) : vector<T>(n, val) {}};
vector<char> ans;
struct trie {
trie* children[26] = {};
int last = 69, mxd = -1;
bool isleaf = false;
};
void trie_add(trie* root, string s) {
trie* cur = root;
FOR(i,0,sz(s)){
int c = s[i] - 'a';
if (cur->children[c] == NULL)
cur->children[c] = new trie;
if(ckmax(cur -> mxd, sz(s) - i - 1)){
cur -> last = c;
}
cur = cur->children[c];
}
cur->isleaf = true;
}
void dfs(trie* root){
if(root -> isleaf) ans.pb('P');
FOR(i,0,26) if(root -> children[i] != NULL && i != root -> last) {
ans.pb(char(i + 'a'));
dfs(root -> children[i]);
}
if(root -> last != 69) {
ans.pb(char(root -> last + 'a'));
dfs(root -> children[root -> last]);
}
ans.pb('-');
}
void uwu(){
int n; cin >> n;
vector<string> str(n);
trav(i, str) cin >> i;
trie t;
trav(i, str) trie_add(&t, i);
dfs(&t);
while(ans.back() == '-') ans.pop_back();
cout << sz(ans) << "\n";
trav(i, ans) cout << i << "\n";
}
signed main(){
cin.tie(0) -> sync_with_stdio(0);
int t = 1;
// cin>>t;
while(t--){
uwu();
}
}
Compilation message
printer.cpp:19:9: error: macro names must be identifiers
19 | #define ****(x) trav(i,x) cin >> i
| ^