malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int n, p[N];   void solve(int n) {     if ((n & 1) && (n - 1) % 4) {       puts( -1 );       return;     }     if (!(n & 1) && n % 4) {       puts( -1 );       return;     }     if (n & 1) p[(n + 1) >> 1] = (n + 1) >> 1;     for (int i = (1); i < ((n >> 1) + 1); ++i)       if (!p[i]) {         p[i] = i + 1;         p[i + 1] = n + 1 - i;         p[n + 1 - i] = n - i;         p[n - i] = i;       }     for (int i = (1); i < (n + 1); ++i) printf( %d%c , p[i],    n [i == n]);   }   int main() {     scanf( %d , &n);     solve(n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long INF = (long)1e09;   int n, m, k, p = 0, id, inv, minv, ans, d = -2;   int main() {     scanf( %d , &n);     if (n == 3) {       cout << 5;       return 0;     }     if (n == 1) {       cout << 1;       return 0;     }     for (m = 3; (m * m + 1) / 2 < n; m += 2)       ;     printf( %d , m);   }
#include <bits/stdc++.h>   using namespace std;   int n, p;   long long u, v, w, res;   map<long long, long long> a;   void cal(long long u, long long v, long long w) {     res = 0;     while (u != v) {       if (u < v) swap(u, v);       a[u] += w;       if (w == 0) res += a[u];       u >>= 1;     }   }   int main() {     cin >> n;     while (n-- > 0) {       cin >> p;       if (p == 1) {         cin >> u >> v >> w;         cal(u, v, w);       } else {         cin >> u >> v;         cal(u, v, 0);         cout << res << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long tc = 1;     cin >> tc;     while (tc--) {       long long n;       cin >> n;       set<long long> st;       for (long long i = 0; i < n; i++) {         long long a;         cin >> a;         st.insert(a);       }       if (st.size() > 1)         cout <<  1 n ;       else         cout << n <<   n ;     }   }
#include <bits/stdc++.h>   struct info {     int p, c;   };   bool vis[5010];   int check[10010], level = 1, I[5010], pair[10010], result[5010];   info input[5010];   std::vector<int> graph[10010];   bool dfs(int index) {     check[index] = level;     for (int i = 0; i < graph[index].size(); i++) {       int next = graph[index][i];       if (pair[next] == -1) {         pair[next] = index;         return true;       } else if (check[pair[next]] != level && dfs(pair[next])) {         pair[next] = index;         return true;       }     }     return false;   }   int main(void) {     int n, m, d;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &input[i].p);     for (int i = 1; i <= n; i++) scanf( %d , &input[i].c);     scanf( %d , &d);     for (int i = 1; i <= d; i++) {       scanf( %d , I + i);       vis[I[i]] = true;     }     for (int i = 1; i <= n; i++) {       if (vis[i] == false && input[i].p < m) {         graph[input[i].p].push_back(input[i].c + m - 1);       }     }     memset(pair, -1, sizeof(pair));     int r = 0;     while (r < m && dfs(r)) {       level++;       r++;     }     for (int i = d; i >= 1; i--) {       result[i] = r;       if (input[I[i]].p < m)         graph[input[I[i]].p].push_back(input[I[i]].c + m - 1);       level++;       while (r < m && dfs(r)) {         level++;         r++;       }     }     for (int i = 1; i <= d; i++) printf( %d n , result[i]);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const int maxn5 = 5e5 + 10;   const int maxnt = 1.2e6 + 10;   const int maxn3 = 1e3 + 10;   const long long mod = 1e9 + 7;   const long long inf = 2e18;   int st, cmp[maxn5], nxt[maxn5], pre[maxn5];   vector<int> adj[maxn5], ver[maxn5];   bool mark[maxn5];   void join(int a, int b) {     if (ver[a].size() > ver[b].size()) swap(a, b);     for (auto u : ver[a]) {       cmp[u] = b;       ver[b].push_back(u);     }     if (a == st) {       st = nxt[a];       pre[nxt[a]] = -1;     } else {       if (nxt[a] != -1) pre[nxt[a]] = pre[a];       nxt[pre[a]] = nxt[a];     }     ver[a].clear();     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       cmp[i] = i;       ver[i].push_back(i);       pre[i] = i == 1 ? -1 : i - 1;       nxt[i] = i == n ? -1 : i + 1;     }     st = 1;     for (int i = 1; i <= n; i++) {       int ind = st;       for (auto u : adj[i]) mark[u] = true;       while (ind != -1) {         if (ind == cmp[i]) {           ind = nxt[ind];           continue;         }         bool done = false;         for (auto u : ver[ind])           if (!mark[u]) {             int c = ind;             ind = nxt[ind];             done = true;             join(c, cmp[i]);             break;           }         if (!done) ind = nxt[ind];       }       for (auto u : adj[i]) mark[u] = false;     }     int cnt = 0, ind = st;     while (ind != -1) {       cnt++;       ind = nxt[ind];     }     cout << cnt <<   n ;     while (st != -1) {       cout << ver[st].size() <<    ;       for (auto u : ver[st]) cout << u <<    ;       cout <<   n ;       st = nxt[st];     }     return 0;   }
#include <bits/stdc++.h>   int x[2002], y[2002];   using namespace std;   int main() {     int n;     cin >> n;     set<int> S;     for (int i = 1; i <= n; ++i) {       cin >> x[i];       S.insert(x[i]);     }     for (int i = 1; i <= n; ++i) {       cin >> y[i];       S.insert(y[i]);     }     int val = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (S.find(x[i] ^ y[j]) != S.end()) val++;       }     }     if (val & 1)       cout <<  Koyomi n ;     else       cout <<  Karen n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e4;   long long a[maxn];   int v[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     for (long long i = 1; i < maxn; i++) {       a[i] = i * (i - 1) / 2;     }     int T;     cin >> T;     while (T--) {       long long n;       cin >> n;       int tn = 0;       for (int i = maxn - 1; i && n; i--) {         while (n >= a[i]) {           n -= a[i];           v[++tn] = i;         }       }       v[tn + 1] = 0;       for (int i = 1; i <= tn; i++) {         cout << 1;         for (int j = 0; j < v[i] - v[i + 1]; j++) cout << 3;       }       cout << 7 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using lint = long long;   int n, x, y;   bool ask_1y(const vector<int>& a) {     if (a.empty()) {       return false;     }     cout <<  ?   << a.size();     for (int i : a) {       cout <<     << i + 1;     }     cout << endl;     int r;     cin >> r;     return r == y || r == (x ^ y);   }   bool same[11];   void solve(istream& cin, ostream& cout) {     cin >> n >> x >> y;     int hb = -1;     for (int i = 0; i < 10; i++) {       vector<int> a;       for (int j = (0); j < int(n); ++j) {         if ((((j) >> (i)) & 1)) {           a.push_back(j);         }       }       if (ask_1y(a)) {         hb = i;       } else {         same[i] = true;       }     }     int a = 0;     int b = 0;     for (int i = 0; i < 10; i++) {       if (i == hb) {         b |= (1 << (hb));         continue;       }       vector<int> v;       for (int j = (0); j < int(n); ++j) {         if (!(((j) >> (i)) & 1) && !(((j) >> (hb)) & 1)) {           v.push_back(j);         }       }       if (ask_1y(v)) {         if (!same[i]) {           b |= (1 << (i));         }       } else {         a |= (1 << (i));         if (same[i]) {           b |= (1 << (i));         }       }     }     cout <<  !   << a + 1 <<     << b + 1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve(cin, cout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 7 + 5;   int n, a[maxn];   char str[maxn];   int main() {     cin >> n;     int ans = 0;     while (n--) {       cin >> str;       for (int i = 0; i < 7; i++) {         a[i] += str[i] -  0 ;         ans = max(ans, a[i]);       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int sum = 0;     sort(a, a + n);     for (int i = 0; i < n; i++) {       sum = sum + (a[n - 1] - a[i]);     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   int low, up, x, n;   int vec[16];   int recurse(int i, int a, int b, int s, int cnt) {     if (i == n) {       if (cnt >= 2 && low <= s && s <= up && a - b >= x) {         return 1;       }       return 0;     }     return recurse(i + 1, max(a, vec[i]), min(b, vec[i]), s + vec[i], cnt + 1) +            recurse(i + 1, a, b, s, cnt);   }   int main() {     scanf( %d , &n);     scanf( %d , &low);     scanf( %d , &up);     scanf( %d , &x);     for (int i = 0; i <= n - 1; ++i) scanf( %d , &vec[i]);     printf( %d n , recurse(0, INT_MIN, INT_MAX, 0, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class TH>   void _dbg(const char *sdbg, TH h) {     cerr << sdbg <<  =  << h << endl;   }   template <class TH, class... TA>   void _dbg(const char *sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, a...);   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class Iterable,             class = typename enable_if<!is_same<string, Iterable>::value>::type>   auto operator<<(ostream &os, Iterable v) -> decltype(os << *begin(v)) {     os <<  [ ;     for (auto vv : v) os << vv <<  ,  ;     return os <<  ] ;   }   const int inf = 0x3f3f3f3f;   const long long infll = 0x3f3f3f3f3f3f3f3fll;   template <class T>   int sign(T x) {     return (x > 0) - (x < 0);   }   template <class T>   T abs(const T &x) {     return (x < T(0)) ? -x : x;   }   vector<int> graph[112345];   int c[112345][4];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int n, a, b;     cin >> n;     for (int k = 1; k <= 3; k++)       for (int i = 1; i <= n; i++) cin >> c[i][k];     for (int i = 0; i + 1 < n; i++) {       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     int start;     for (int i = 1; i <= n; i++) {       if (graph[i].size() > 2) {         cout << -1 << endl;         return 0;       }       if (graph[i].size() == 1) start = i;     }     vector<int> pi = {1, 2, 3};     long long ans = infll;     vector<int> best_color;     vector<int> color(n + 1);     do {       long long tmp = 0;       int cur = start;       int prev = start;       for (int i = 0; i < n; i++) {         color[cur] = pi[i % 3];         tmp += c[cur][pi[i % 3]];         for (int j = 0; j < graph[cur].size(); j++)           if (graph[cur][j] != prev) {             prev = cur;             cur = graph[cur][j];             break;           }       }       if (tmp < ans) {         ans = min(ans, tmp);         best_color = color;       }     } while (next_permutation(pi.begin(), pi.end()));     cout << ans << endl;     for (int i = 1; i <= n; i++) cout << best_color[i] <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n < 6)       cout << -1 << endl;     else {       for (int i = 2; i <= 4; i++) cout << 1 <<     << i << endl;       for (int i = 5; i <= n; i++) {         cout << 2 <<     << i << endl;       }     }     for (int i = 1; i < n; i++) {       cout << i <<     << i + 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<vector<int>> adj;   vector<vector<int>> vis;   int dfs1(int a, int b) {     if (a == n - 1 and b == m - 1) return 1;     vis[a][b] = 1;     if (a + 1 < n and adj[a + 1][b] and !vis[a + 1][b])       if (dfs1(a + 1, b)) return 1;     if (b + 1 < m and adj[a][b + 1] and !vis[a][b + 1])       if (dfs1(a, b + 1)) return 1;     vis[a][b] = 2;     return 0;   }   int dfs2(int a, int b) {     if (a == n - 1 and b == m - 1) return 1;     vis[a][b] = 1;     if (a + 1 < n and adj[a + 1][b] and vis[a + 1][b] != 1)       if (dfs2(a + 1, b)) return 1;     if (b + 1 < m and adj[a][b + 1] and vis[a][b + 1] != 1)       if (dfs2(a, b + 1)) return 1;     return 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     adj = vector<vector<int>>(n, vector<int>(m));     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       for (int j = 0; j < m; ++j) {         if (s[j] ==  . )           adj[i][j] = 1;         else           adj[i][j] = 0;       }     }     int a = 0;     vis = vector<vector<int>>(n, vector<int>(m, 0));     a += dfs1(0, 0);     a += dfs2(0, 0);     cout << a <<   n ;   }
#include <bits/stdc++.h>   long long cmpfunc(const void* a, const void* b) {     return (*(long long*)a - *(long long*)b);   }   int main(void) {     long long int test, i, j, n, count, flag = 0, o1 = 0, o2 = 0, b1, x, m, l,                                         max, sum2, min, f, r, o, sum1, sum = 0, y,                                         count1 = 0, a[1000000];     scanf( %lld , &n);     count = 0;     f = 0;     for (i = 0; i < n; i++) {       scanf( %lld , &x);       if (a[x] == 0 && x != 0) {         count++;         a[x]++;       }     }     printf( %lld n , count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a % b == 0) return b;     return gcd(b, a % b);   }   int v[11];   int main() {     int a, k = 0;     scanf( %d , &a);     for (int i = 2; i < a; i++) {       int t = a;       int pos = 0;       while (t) {         int mod = t % i;         k += mod;         t = (t - mod) / i;         if (!t) break;       }     }     int vbcd = gcd(k, a - 2);     printf( %d/%d , k / vbcd, (a - 2) / vbcd);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x[100009], y[100009], sx, sy;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x[i] >> y[i];       sx += x[i];       sy += y[i];     }     if (sx % 2 == 0 && sy % 2 == 0) {       cout << 0;       return 0;     }     for (int i = 1; i <= n; i++) {       if ((sx - x[i] + y[i]) % 2 == 0 && (sy - y[i] + x[i]) % 2 == 0) {         cout << 1;         return 0;       }     }     cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   long long int min(long long int a, long long int b) {     if (a < b) {       return a;     } else {       return b;     }   }   long long int max(long long int a, long long int b) {     if (a > b) {       return a;     } else {       return b;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       string str;       cin >> str;       if (n == 1) {         cout << 1 <<   n ;         continue;       }       if (n == 2) {         if (str[0] == str[1]) {           cout << 1 <<   n ;           continue;         }       }       vector<long long int> seg;       long long int curr_length = 1;       for (long long int i = 0; i < str.size() - 1; i++) {         if (str[i] == str[i + 1]) {           curr_length++;         } else {           seg.push_back(curr_length);           curr_length = 1;         }       }       seg.push_back(curr_length);       long long int segtillnow = 0;       long long int ans = 0;       for (long long int i = 0; i < seg.size(); i++) {         segtillnow++;         if (seg[i] == 1) {           continue;         } else if (seg[i] > 1) {           long long int operations = min(seg[i] - 1, segtillnow);           ans += operations;           segtillnow -= operations;         }       }       ans += ((segtillnow + 1) / 2);       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string cad1;     string cad2;     cin >> cad1 >> cad2;     if (cad1 == cad2) {       cout <<  YES ;     } else {       if (cad1.size() != cad2.size()) {         cout <<  NO ;       } else {         int ceros = 0;         int unos = 0;         for (int i = 0; i < cad2.size(); ++i) {           if (cad2[i] ==  0 ) ceros++;           if (cad1[i] ==  1 ) unos++;         }         if (ceros == cad2.size())           cout <<  NO ;         else {           if (unos > 0)             cout <<  YES ;           else             cout <<  NO ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[100000];   int n, m, x, y, i, sol, v[501][501];   int main() {     cin >> n >> m >> x >> y;     cin >> s;     cout << 1 <<    ;     int l = strlen(s);     for (i = 0; i < l - 1; i++) {       v[x][y] = 1;       if (s[i] ==  R  && y < m) y++;       if (s[i] ==  L  && y > 1) y--;       if (s[i] ==  U  && x > 1) x--;       if (s[i] ==  D  && x < n) x++;       if (v[x][y] == 1)         cout << 0 <<    ;       else {         cout << 1 <<    ;         sol++;       }     }     cout << n * m - sol - 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, cnt;   char phone[128];   int main() {     scanf( %d , &n);     scanf( %s , phone);     cnt = 0;     for (int i = 0; i < n; i++) {       if (cnt == 2 and n - i >= 2) {         printf( - );         cnt = 0;       }       printf( %c , phone[i]);       cnt++;     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<string> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     set<string> s;     for (int i = n - 1; i >= 0; i--) {       if (s.find(a[i]) == s.end()) {         cout << a[i] <<   n ;       }       s.insert(a[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long double EPS = 1e-10;   const int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};   const int MAX_N = 400;   int ans[181];   void init() {     fill(ans, ans + 181, -1);     for (int i = 3; i <= MAX_N; ++i) {       double min_deg = 180.0 / i;       for (int deg = 1; deg <= 180; ++deg) {         if (ans[deg] != -1) continue;         if (deg - floor(deg / min_deg + EPS) * min_deg < EPS &&             deg <= min_deg * double(i - 2))           ans[deg] = i;       }     }   }   int main() {     init();     int t, deg;     cin >> t;     while (t--) {       cin >> deg;       cout << ans[deg] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long ans;   void solve(long long a, long long b, long long c, long long l) {     for (long long i = 0; i <= l; i++) {       long long x = min(a - b - c + i, l - i);       if (x >= 0) ans -= (x + 1) * (x + 2) / 2LL;     }   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     long long a, b, c, l;     cin >> a >> b >> c >> l;     ans = (l + 1) * (l + 2) * (l + 3) / 6LL;     solve(a, b, c, l);     solve(b, a, c, l);     solve(c, a, b, l);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T m, T n) {     while (n) {       T t = m % n;       m = n;       n = t;     };     return m;   }   template <typename T>   T exgcd(T a, T b, T& sa, T& ta) {     T q, r, sb = 0, tb = 1, sc, tc;     sa = 1, ta = 0;     if (b) do         q = a / b, r = a - q * b, a = b, b = r, sc = sa - q * sb, sa = sb,         sb = sc, tc = ta - q * tb, ta = tb, tb = tc;       while (b);     return a;   }   template <typename T>   T mul_inv(T a, T b) {     T t1 = a, t2 = b, t3;     T v1 = 1, v2 = 0, v3;     T x;     while (t2 != 1)       x = t1 / t2, t3 = t1 - x * t2, v3 = v1 - x * v2, t1 = t2, t2 = t3, v1 = v2,       v2 = v3;     return (v2 + b) % b;   }   template <typename T>   T powmod(T a, T b, T MOD) {     if (b < 0) return 0;     T rv = 1;     while (b) (b % 2) && (rv = (rv * a) % MOD), a = a * a % MOD, b /= 2;     return rv;   }   const int maxn = 2e5 + 7;   int n;   int L;   int a[maxn];   int b[maxn];   vector<int> to_remove[maxn];   vector<int> to_add[maxn];   int dist_tbl[maxn];   bool explored[maxn];   int dis(int x, int y) { return min(abs(x - y), L - abs(x - y)); }   int calc(int k) {     int& r = dist_tbl[k];     if (r >= 0) return r;     r = 0;     for (int i = 0; i < n; i++) r = max(r, dis(a[i], b[(i + k) % n]));     return r;   }   int main(int argc, char* argv[]) {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     cin >> n >> L;     {       clock_t time_start = clock();       clock_t time_end = time_start + CLOCKS_PER_SEC * 0.8;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       sort(a, a + n);       sort(b, b + n);       memset(dist_tbl, -1, sizeof(dist_tbl));       memset(explored, 0, sizeof(explored));       map<int, set<int> > values;       for (int i = 0, ij = max(1, n / 64); i < n; i += ij) {         values[calc(i)].insert(i);       }       int explore_values[] = {-4, -2, -1, 1, 2, 4, 0};       while (clock() < time_end && values.size() < n) {         vector<int> toExplore;         int nmin = 64;         for (auto it : values) {           if (it.second.empty()) --nmin;           for (int k : it.second) {             if (--nmin < 0) break;             if (!explored[k]) {               toExplore.push_back(k);               explored[k] = true;             }           }           if (nmin < 0) break;         }         if (toExplore.size() == 0) break;         int new_explore = 0;         for (int k : toExplore) {           values[calc(k)].erase(k);           for (int ei = 0; explore_values[ei]; ei++) {             int k2 = (k + n + explore_values[ei]) % n;             k2 = (k2 + n) % n;             if (dist_tbl[k2] < 0) {               new_explore++;               values[calc(k2)].insert(k2);             }           }         }         if (!new_explore) break;       }       cout << values.begin()->first << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fr() {     freopen( test_input.txt ,  r , stdin);     freopen( a.out ,  w , stdout);   }   const int N = 5e5 + 5;   const int MAX = 5e6 + 123;   const int INF = 2e9;   const int mod = 1e9 + 7;   const double pi = 3.1415926536;   double eps = 1e-10;   bool used1[N], used2[N];   void solve() {     int n;     string s1, s2;     map<int, int> cnt1, cnt2;     map<int, pair<int, int> > ans;     cin >> s1 >> s2;     cin >> n;     for (int i = 1; i <= n; i++) {       int t, m;       char p, c;       cin >> t >> p >> m >> c;       if (p ==  h ) {         if (c ==  y )           cnt1[m]++;         else           cnt1[m] += 2;         if (cnt1[m] >= 2 and !used1[m]) {           ans[t] = make_pair(0, m);           used1[m] = 1;         }       } else {         if (c ==  y )           cnt2[m]++;         else           cnt2[m] += 2;         if (cnt2[m] >= 2 and !used2[m]) {           ans[t] = make_pair(1, m);           used2[m] = 1;         }       }     }     for (int i = 1; i <= 90; i++) {       if (ans[i] != make_pair(0, 0)) {         if (ans[i].first == 0)           cout << s1 <<    ;         else           cout << s2 <<    ;         cout << ans[i].second <<     << i << endl;       }     }   }   int t;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     t = 1;     while (t--) {       solve();     }     return 0;   }