malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     fast();     long long int t;     t = 1;     while (t--) {       int n;       cin >> n;       long long arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       sort(arr, arr + n, greater<int>());       int a = ceil((float)n / 2);       int b = n - a;       int answer = 0;       int curr = a;       vector<long long> arr2;       vector<long long> arr3;       for (int i = 1; i < a; i++) {         for (int j = curr; j < n; j++) {           if (arr[j] < arr[i]) {             curr = j + 1;             answer++;             arr2.push_back(arr[j]);             break;           } else             arr3.push_back(arr[j]);         }       }       cout << answer << endl;       for (int i = 0; i < arr3.size(); i++) arr2.push_back(arr3[i]);       if (arr2.size() != b) {         for (int i = 0; i < (b - arr2.size()); i++)           arr2.push_back(arr[n - 1 - i]);       }       for (int i = 0; i < n; i++) {         if (i % 2)           cout << arr2[i / 2] <<    ;         else           cout << arr[i / 2] <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int cnt(vector<vector<pair<int, int>>>& graph, int cur, int parent, int val) {     int ans = 1;     for (auto p : graph[cur]) {       if (p.first == parent) continue;       if (p.second == val) ans += cnt(graph, p.first, cur, val);     }     return ans;   }   void fill(vector<vector<pair<int, int>>>& graph,             vector<pair<bool, bool>>& visited, vector<pair<int, int>>& cnt_vec,             int cur, int parent, int val, int num) {     if (val == 0) {       visited[cur].first = true;       cnt_vec[cur].first = num;     } else {       visited[cur].second = true;       cnt_vec[cur].second = num;     }     for (auto p : graph[cur]) {       if (p.first == parent) continue;       if (p.second == val) fill(graph, visited, cnt_vec, p.first, cur, val, num);     }   }   int process(vector<vector<pair<int, int>>>& graph,               vector<pair<bool, bool>>& visited, vector<pair<int, int>>& cnt_vec,               int start, int val) {     int n = graph.size(), ans;     ans = cnt(graph, start, -1, val);     fill(graph, visited, cnt_vec, start, -1, val, ans);     return ans;   }   int main() {     int n, i, a, b, val, tmp;     long long ans = 0;     cin >> n;     vector<vector<pair<int, int>>> graph(n + 1);     for (i = 0; i < n - 1; ++i) {       cin >> a >> b >> val;       graph[a].push_back({b, val});       graph[b].push_back({a, val});     }     vector<pair<int, int>> cnt_vec(n + 1, {0, 0});     vector<pair<bool, bool>> visited(n + 1, {false, false});     vector<int> components;     for (i = 1; i <= n; ++i) {       if (!visited[i].first) {         tmp = process(graph, visited, cnt_vec, i, 0);         if (tmp > 1) components.push_back(tmp);       }       if (!visited[i].second) {         tmp = process(graph, visited, cnt_vec, i, 1);         if (tmp > 1) components.push_back(tmp);       }     }     for (auto num : components) ans += 1LL * num * (num - 1);     for (i = 1; i <= n; ++i)       ans += 1LL * (cnt_vec[i].first - 1) * (cnt_vec[i].second - 1);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   void pr_init() {}   void solve() {     string str[2];     cin >> str[0] >> str[1];     long long ss = (long long)str[0].size();     long long dp[2][ss + 1];     for (long long i = 0; i < 2; i++) {       for (long long j = 0; j < ss; j++) {         if (str[i][j] ==  X )           dp[i][j] = 0;         else           dp[i][j] = 1;       }     }     dp[0][ss] = dp[1][ss] = 0;     long long ways = 0;     for (long long j = 0; j < ss; j++) {       if (dp[0][j] == 1 && dp[1][j] == 1) {         if (dp[0][j + 1] == 1)           ways++, dp[0][j + 1] = 0;         else if (dp[1][j + 1] == 1)           ways++, dp[1][j + 1] = 0;         continue;       } else if (dp[0][j] == 1) {         if (dp[0][j + 1] == 1 && dp[1][j + 1] == 1)           ways++, dp[0][j + 1] = 0, dp[1][j + 1] = 0;         continue;       } else if (dp[1][j] == 1) {         if (dp[0][j + 1] == 1 && dp[1][j + 1] == 1)           ways++, dp[0][j + 1] = 0, dp[1][j + 1] = 0;         continue;       }     }     cout << ways << endl;   }   int32_t main() {     pr_init();     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   template <class t>   inline t read(t &x) {     char c = getchar();     bool f = 0;     x = 0;     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     if (f) x = -x;     return x;   }   template <class t, class... A>   inline void read(t &x, A &...a) {     read(x);     read(a...);   }   template <class t>   inline void write(t x) {     if (x < 0)       putchar( - ), write(-x);     else {       if (x > 9) write(x / 10);       putchar( 0  + x % 10);     }   }   const int N = 55;   int n, a[N], cnt;   signed main() {     read(n);     for (int i = 1; i <= n; i++) read(a[i]);     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) cnt += a[i] == a[1];     if (cnt > n / 2)       puts( Bob );     else       puts( Alice );   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5, Lim = 18;   int tr[maxn * 19][2], nowxor, cnt = 1, siz[maxn * 19], n, m;   template <typename T>   inline void read(T &x) {     char c;     int f = 1;     while (!isdigit(c = getchar())) (c ==  - ) && (f = -1);     x = c ^ 48;     while (isdigit(c = getchar())) x = x * 10 + (c ^ 48);     x *= f;   }   void insert(int x, int u = 1, int now = Lim) {     if (now == -1) return siz[u] = 1, void();     int s = x >> now & 1;     if (!tr[u][s]) tr[u][s] = ++cnt;     insert(x, tr[u][s], now - 1);     siz[u] = siz[tr[u][0]] + siz[tr[u][1]];   }   inline int query(int x = nowxor) {     int u = 1, res = 0;     for (int i = Lim; i >= 0; --i) {       int s = x >> i & 1;       if (siz[tr[u][s]] == ((1 << i)))         u = tr[u][s ^ 1], res |= (1 << i);       else         u = tr[u][s];       if (!u) return res;     }     return res;   }   int main() {     int x;     read(n);     read(m);     for (int i = 1; i <= n; ++i) read(x), insert(x);     while (m--) {       read(x);       nowxor ^= x;       printf( %d n , query());     }     return 0;     int yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;   }
#include <bits/stdc++.h>   long long vx[200010], vy[200010];   std::map<long long, long long> mp, gg;   int main() {     int n;     long long a, b;     scanf( %d%lld%lld , &n, &a, &b);     long long ans = 0;     for (int k = 1; k <= n; k++) {       long long t;       scanf( %lld%lld%lld , &t, &vx[k], &vy[k]);       long long c = a * vx[k] - vy[k];       long long d = (long long)2000000000 * vx[k] + vy[k];       ans -= gg[d];       gg[d]++;       ans += mp[c];       mp[c]++;     }     printf( %lld n , 2 * ans);   }
#include <bits/stdc++.h>   using namespace std;   const int mmmm = 1111;   int n;   char s[mmmm];   int a[mmmm], f[mmmm];   void qwe() {     a[0] = 1989;     f[0] = 1;     for (int i = 1; i <= 9; i++) {       f[i] = f[i - 1] * 10;       a[i] = a[i - 1] + f[i];     }   }   int main() {     qwe();     while (scanf( %d , &n) != EOF) {       for (int i = 1; i <= n; i++) {         scanf( %s , s);         int l = strlen(s) - 4;         int c = 0;         for (int i = 4; i < l + 4; i++) {           c = c * 10 + s[i] -  0 ;         }         int asd = a[l - 1];         int zxc = a[l];         int t1 = asd / f[l] * f[l] + c;         int t2 = zxc / f[l] * f[l] + c;         if (t1 >= asd && t1 < zxc) {           printf( %d n , t1);         } else {           printf( %d n , t2);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000000 + 7;   const int N = 10000001;   long long dp[N];   int main() {     dp[1] = 0;     dp[2] = 3;     for (int i = 3; i < N; i++) dp[i] = (dp[i - 2] * 3 + dp[i - 1] * 2) % mod;     int n;     while (scanf( %d , &n) != EOF) printf( %lld n , dp[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e7;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     int n, ans = INT_MAX, count = 0;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];       count += (v[i] == 1);     }     if (count > 0) {       cout << n - count << endl;     } else {       vector<vector<int>> dp(n, vector<int>(n));       for (int i = 0; i < n; i++) dp[i][i] = v[i];       for (int i = 0; i < n; i++)         for (int j = i + 1; j < n; j++) dp[i][j] = gcd(v[j], dp[i][j - 1]);       for (int i = 0; i < n; i++)         for (int j = i; j < n; j++)           if (dp[i][j] == 1) ans = min(ans, j - i);       if (ans == INT_MAX)         cout << -1 << endl;       else         cout << ans + n - 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   pair<int, int> p[10][10];   int nom[4];   bool cmp(int a, int b) {     if (p[a][0] != p[b][0])       return (p[a][0] < p[b][0]);     else       return (p[a][1] < p[b][1]);   }   int main() {     for (int i = (0); i < (4); i++) {       for (int j = (0); j < (2); j++) {         scanf( %d%d , &p[i][j].first, &p[i][j].second);       }       if (p[i][0].first == p[i][1].first) {         if (p[i][0].second > p[i][1].second) swap(p[i][0], p[i][1]);       } else {         if (p[i][0].first > p[i][1].first) swap(p[i][0], p[i][1]);       }     }     for (int i = (0); i < (4); i++) nom[i] = i;     sort(nom, nom + 4, &cmp);     if (p[nom[1]][0].second == p[nom[1]][1].second &&         p[nom[1]][0].first != p[nom[1]][1].first) {       if (p[nom[0]][0].first == p[nom[0]][1].first &&           p[nom[0]][0].second != p[nom[0]][1].second) {         if (p[nom[2]][0].second == p[nom[2]][1].second &&             p[nom[2]][0].first != p[nom[2]][1].first) {           if (p[nom[3]][0].first == p[nom[3]][1].first &&               p[nom[3]][0].second != p[nom[3]][1].second) {             if (p[nom[0]][0] == p[nom[1]][0] && p[nom[0]][1] == p[nom[2]][0] &&                 p[nom[2]][1] == p[nom[3]][1] && p[nom[3]][0] == p[nom[1]][1]) {               printf( YES n );               return 0;             }           }         }       }     }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[200000];   int cost[200001];   int sub() {     int n, p, k;     cin >> n >> p >> k;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     sort(A, A + n);     for (int i = 0; i < n; i++) {       if (i < k - 1) {         cost[i + 1] = cost[i] + A[i];       } else {         cost[i + 1] = cost[i - k + 1] + A[i];       }     }     int ans = 0;     for (int i = 0; i <= n; i++) {       if (cost[i] <= p) {         ans = i;       }     }     cout << ans << endl;     return 0;   }   int main() {     int t;     cin >> t;     while (t--) {       sub();     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const long long INF = 1e18 + 1LL;   const double Pi = acos(-1.0);   const int N = 5e5 + 10, M = 1e3 + 20, mod = 1e9 + 7, inf = 2e9;   vector<int> G[N];   long long dp[N][10], fs[N][10];   long long ans = 0;   int n, k, a, b;   void dfs(int u, int f) {     dp[u][0] = 1;     for (int i = 0; i < G[u].size(); ++i) {       int to = G[u][i];       if (to == f) continue;       dfs(to, u);       for (int j = 0; j <= k; ++j) {         for (int h = 0; h <= k; ++h) {           if (!dp[u][j] || !dp[to][h]) continue;           long long tmp = j + h + 1;           if (tmp % k)             tmp = tmp / k + 1;           else             tmp = tmp / k;           ans += tmp * dp[to][h] * dp[u][j] + fs[u][j] * dp[to][h] +                  fs[to][h] * dp[u][j];         }       }       for (int j = 1; j <= k; ++j)         dp[u][j] += dp[to][j - 1], fs[u][j] += fs[to][j - 1];       dp[u][1] += dp[to][k];       fs[u][1] += fs[to][k] + dp[to][k];     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &a, &b);       G[a].push_back(b);       G[b].push_back(a);     }     dfs(1, 0);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     reverse(s.begin(), s.end());     reverse(t.begin(), t.end());     int i = 0;     while (i < s.length() && i < t.length() && s[i] == t[i]) {       i++;     }     cout << s.length() + t.length() - 2 * i;   }
#include <bits/stdc++.h>   int main() {     int n, s;     scanf( %d%d , &n, &s);     s *= 100;     int max = 0;     bool tr = false;     for (int i = 1; i <= n; i++) {       int d, c;       scanf( %d%d , &d, &c);       int money = d * 100 + c;       if (money <= s) {         tr = true;         int sweet = (s - money) % 100;         if (max < sweet) max = sweet;       }     }     if (tr == false)       printf( -1 n );     else       printf( %d n , max);   }
#include <bits/stdc++.h>   using namespace std;   int n, k, m;   int times[45];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k >> m;     for (int i = 0; i < k; i++) cin >> times[i];     int s = 0;     for (int i = 0; i < k; i++) s += times[i];     sort(begin(times), begin(times) + k);     int currBest = 0;     for (int numSolves = 0; numSolves < n + 1; numSolves++) {       if (s * numSolves > m) break;       int score = 0;       score += numSolves * (k + 1);       int timeLeft = m - s * numSolves;       int numUnsolved = n - numSolves;       int i = 0;       while (timeLeft >= times[i] && i < k) {         score += min(timeLeft / times[i], numUnsolved);         timeLeft -= times[i] * min(timeLeft / times[i], numUnsolved);         i++;       }       currBest = max(score, currBest);     }     cout << currBest <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename V>   void bugp(const pair<T, V> &x) {     cerr <<  {  << x.first <<  ,   << x.second <<  }  << endl;   }   template <typename T, typename U, typename V>   void bugpp(const pair<T, pair<U, V> > &x) {     cerr <<  {  << x.first <<  , {  << x.second.first <<  ,   << x.second.second          <<  }}  << endl;   }   template <typename T>   bool maximize(T &x, const T &y) {     if (x < y) {       x = y;       return 1;     }     return 0;   }   template <typename T>   bool minimize(T &x, const T &y) {     if (x > y) {       x = y;       return 1;     }     return 0;   }   const int N = 100001;   int n, arr[N], dp[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     int total_sum = 0;     map<int, int> cnt;     for (int i = 1, _n = (n); i <= _n; ++i) {       cin >> arr[i];       total_sum += arr[i];       if (!(total_sum & 1)) dp[i] = cnt[total_sum - total_sum / 2];       ++cnt[total_sum];     }     long long ans = 0;     int sum = 0;     for (int i = (n), _b = (3); i >= _b; --i) {       sum += arr[i];       if (3 * sum == total_sum) ans += dp[i - 1];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const long long OO = 0x3f3f3f3f3f3f3f3fLL;   const int maxn = 200000;   int d, V, n;   pair<int, int> a[maxn + 5];   long long dp[maxn + 5];   int Min[maxn + 5];   int main() {     memset(Min, -1, sizeof Min);     scanf( %d%d%d , &d, &V, &n);     for (int i = (0), _end_ = (n); i < _end_; ++i)       scanf( %d%d , &a[i].first, &a[i].second);     a[n++] = make_pair(0, 0);     a[n++] = make_pair(d, 0);     sort(a, a + n);     for (int i = (0), _end_ = (n - 1); i < _end_; ++i)       if (a[i].first + V < a[i + 1].first) {         printf( -1 n );         return 0;       }     long long ans = 0;     int lst = 0, cur = 0;     for (int i = (1), _end_ = (n); i < _end_; ++i) {       cur = a[i - 1].first;       while (a[lst].first + V < a[i].first) {         ans += (long long)(a[lst].first + V - cur) * a[lst].second;         cur = a[lst].first + V;         int best = -1;         for (int j = lst + 1; j <= n; j += j & -j)           if (best == -1 || (Min[j] != -1 && a[Min[j]].second < a[best].second))             best = Min[j];         lst = best;       }       ans += (long long)(a[i].first - cur) * a[lst].second;       cur = a[i].first;       if (a[i].second < a[lst].second) lst = i;       for (int j = i; j > 0; j -= j & -j)         if (Min[j] == -1 || a[Min[j]].second > a[i].second) Min[j] = i;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, x, y, ans = 0, t;   bool p1[1010], p2[1010];   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) p1[i] = p2[i] = 1;     p1[1] = p2[1] = p1[n] = p2[n] = 0;     for (i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       p1[x] = p2[y] = 0;     }     ans = 2 * (n - 2);     for (i = 2; i < n; i++) {       if (p1[i] == 0) ans--;       if (p2[i] == 0) ans--;     }     if (n % 2) {       t = n / 2 + 1;       if (p1[t] == 0) ans++;       if (p2[t] == 0) ans++;       ans -= 2;       if (p1[t] || p2[t]) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace fastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline long long read() {     bool sign = 0;     char ch = nc();     long long x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return 0;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (sign) x = -x;     return x;   }   };  // namespace fastIO   using namespace fastIO;   vector<long long> e[2000010];   long long dep[2000010], fa[2000010], son[2000010], top[2000010], id[2000010],       now = 0, f[2000010];   void dfs1(long long x, long long pre) {     dep[x] = 1;     for (auto i : e[x]) {       if (i == pre) continue;       dfs1(i, x);       fa[i] = x;       if (dep[i] > dep[son[x]]) son[x] = i;       dep[x] = max(dep[x], dep[i] + 1);     }   }   void dfs2(long long x, long long tp) {     id[x] = ++now;     top[x] = tp;     if (son[x]) dfs2(son[x], son[x]);     for (auto i : e[x]) {       if (i == son[x] || i == fa[x]) continue;       dfs2(i, tp);     }   }   long long maxx[1000010], maxi[1000010];   void merge(long long p, long long x, long long y) {     for (long long i = 1; i <= dep[y]; i++) {       f[id[x] + i - 1] += f[id[y] + i - 1];       if (f[id[x] + i - 1] > maxx[p] ||           (f[id[x] + i - 1] == maxx[p] && i < maxi[p]))         maxx[p] = f[id[x] + i - 1], maxi[p] = i;     }   }   void dfs3(long long x, long long pre) {     if (son[x]) dfs3(son[x], x);     if (son[x])       maxx[x] = maxx[son[x]], maxi[x] = maxi[son[x]] + 1;     else       maxx[x] = 1, maxi[x] = 0;     for (auto i : e[x]) {       if (i == fa[x] || i == son[x]) continue;       dfs3(i, x);       merge(x, son[x], i);     }     f[id[x]] = 1;     if (maxx[x] == 1) maxi[x] = 0;   }   signed main() {     long long n = read();     for (long long i = 1; i < n; i++) {       long long x = read(), y = read();       e[x].push_back(y);       e[y].push_back(x);     }     dfs1(1, 1);     dfs2(1, 1);     dfs3(1, 1);     for (long long i = 1; i <= n; i++) cout << maxi[i] <<   n ;     return 0;   }
#include <iostream>   #include <string.h>   #include <bits/stdc++.h>   using namespace std;   int main() {       int t;       cin >> t;       while(t--) {           int x;           cin >> x;           bool isPossible = false;           for (int i = 0; i < 11; i++) {               if (111*i <= x && (x - 111*i)%11 == 0) {                   isPossible = true;               }           }           if(isPossible) cout <<  YES  << endl;           else cout <<  NO  << endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   int a[maxn], ra[maxn];   int main() {     int n, m, k;     while (~scanf( %d%d%d , &n, &m, &k)) {       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         ra[a[i]] = i;       }       int t;       long long cnt = 0;       for (int i = 0; i < m; i++) {         scanf( %d , &t);         int j = ra[t];         if ((j + 1) % k == 0)           cnt += (j + 1) / k;         else           cnt += ((j + 1) / k + 1);         if (j != 0) {           swap(a[j], a[j - 1]);           swap(ra[t], ra[a[j]]);         }       }       cout << cnt << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   unsigned long long n, k, x;   unsigned long long a[300000];   unsigned long long dpL[300000];   unsigned long long dpR[300000];   int main() {     int i, j;     cin >> n >> k >> x;     unsigned long long s = 0, MAX = 0;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n - 1; i++) {       dpL[i + 1] = dpL[i] | a[i];     }     for (i = n - 1; i > 0; i--) {       dpR[i - 1] = dpR[i] | a[i];     }     unsigned long long ans1 = a[0], ans2 = a[n - 1];     for (i = 0; i < k; i++) {       ans1 = ans1 * x;       ans2 = ans2 * x;     }     unsigned long long ans = max(ans1 | dpR[0], ans2 | dpL[n - 1]);     for (i = 1; i < n - 1; i++) {       unsigned long long ANS = a[i];       for (j = 0; j < k; j++) {         ANS *= x;       }       ans = max(ans, ANS | dpL[i] | dpR[i]);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int64_t n, m;     cin >> n >> m;     pair<char, int64_t> a[n][m];     for (int64_t i = 0; i < n; ++i) {       for (int64_t j = 0; j < m; ++j) {         cin >> a[i][j].first;         a[i][j].second = 0;       }     }     for (int64_t i = 0; i < n; ++i) {       for (int64_t j = 0; j < m; ++j) {         int64_t c = 0;         for (int64_t k = 0; k < n; ++k) c += a[k][j].first == a[i][j].first;         if (c > 1) a[i][j].second = 1;         c = 0;         for (int64_t k = 0; k < m; ++k) c += a[i][j].first == a[i][k].first;         if (c > 1) a[i][j].second = 1;       }     }     for (int64_t i = 0; i < n; ++i) {       for (int64_t j = 0; j < m; ++j) {         if (a[i][j].second == 0) cout << a[i][j].first;       }     }   }