malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 5e4 + 5, P = 1e9 + 7;   struct Trie {     int ch[2], siz, mn, mx;   } t[N * 32];   int n, a[N], cntnode = 1, s[N][33], rt[N], ans;   long long kth, m;   void Insert(int x) {     int now = 1;     t[now].siz++;     for (int i = 31; ~i; --i) {       int& nxt = t[now].ch[a[x] >> i & 1];       if (!nxt) nxt = ++cntnode, t[nxt].mn = x;       now = nxt;       ++t[now].siz;       t[now].mx = x;     }   }   int calc(int v, int l, int r) {     if (!l) return 0;     int res = 0;     for (int i = 31; ~i; --i) {       int p = v >> i & 1;       if (!p)         (res += (1LL << i) * (s[r][i] - s[l - 1][i]) % P) %= P;       else         (res += (1LL << i) * (r - l + 1 - s[r][i] + s[l - 1][i]) % P) %= P;     }     return res;   }   int main() {     scanf( %d%lld , &n, &m);     m *= 2;     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; ++i) {       Insert(i);       for (int j = 31; ~j; --j) s[i][j] = s[i - 1][j] + (a[i] >> j & 1);     }     for (int i = 1; i <= n; ++i) rt[i] = 1;     for (int i = 31; ~i; --i) {       long long tot = 0;       int z;       for (int j = 1; j <= n; ++j) {         int p = (a[j] >> i & 1) ^ 1;         tot += t[t[rt[j]].ch[p]].siz;       }       if (tot >= m)         z = 1, kth |= 1LL << i;       else         z = 0, m -= tot;       for (int j = 1; j <= n; ++j) rt[j] = t[rt[j]].ch[(a[j] >> i & 1) ^ z];     }     for (int i = 1; i <= n; ++i) {       int now = 1;       for (int j = 31; ~j; --j) {         int p = (a[i] ^ kth) >> j & 1;         if (!(kth >> j & 1) && t[now].ch[p ^ 1])           (ans += calc(a[i], t[t[now].ch[p ^ 1]].mn, t[t[now].ch[p ^ 1]].mx)) %=               P;         now = t[now].ch[p];       }     }     printf( %lld , 1LL * (kth * m % P + ans) % P * (P + 1 >> 1) % P);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   vector<pair<int, int> > g[maxn];   set<pair<int, int> > s;   int c[maxn], dis[maxn];   void dijekstra(int u) {     dis[u] = 0;     s.insert(make_pair(u, dis[u]));     while (s.size()) {       pair<int, int> a = *s.begin();       s.erase(a);       for (int i = 0; i < g[a.first].size(); i++) {         if (a.second + g[a.first][i].second < dis[g[a.first][i].first]) {           s.erase(make_pair(g[a.first][i].first, dis[g[a.first][i].first]));           dis[g[a.first][i].first] = a.second + g[a.first][i].second;           s.insert(make_pair(g[a.first][i].first, dis[g[a.first][i].first]));         }       }     }     s.clear();   }   int main() {     ios_base::sync_with_stdio(false);     memset(dis, 63, sizeof(dis));     int n, x, y;     cin >> n;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 0; i < n - 1; i++) {       cin >> x >> y;       if (c[x] == c[y]) {         g[x].push_back(make_pair(y, 0));         g[y].push_back(make_pair(x, 0));       } else {         g[x].push_back(make_pair(y, 1));         g[y].push_back(make_pair(x, 1));       }     }     dijekstra(1);     int mx = -1, j;     for (int i = 1; i <= n; i++)       if (dis[i] > mx) mx = dis[i], j = i;     memset(dis, 63, sizeof(dis));     dijekstra(j);     mx = -1;     for (int i = 1; i <= n; i++)       if (dis[i] > mx) mx = dis[i], j = i;     cout << (dis[j] + 1) / 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[100003][3], ara[100003], mod = 1000000007, n, m;   long long solve(long long idx, long long sta) {     if (idx == n) {       if (sta == 0 || sta == 2)         return 1;       else {         return 0;       }     } else if (dp[idx][sta] != -1)       return dp[idx][sta];     else {       long long p = 0, q = 0, r = 0, t, x, y, z;       if (sta == 0) {         p = solve(idx + 1, 0);         x = 1;         z = idx + 1;         if (ara[idx] == 1) {           x = 2;           z = idx + m;         }         q = solve(z, x);       } else if (sta == 1) {         x = 1;         z = idx + 1;         if (ara[idx] == 1) {           x = 2;           z = idx + m;         }         q = solve(z, x);       } else {         p = solve(idx, 0);         q = solve(idx + 1, sta);       }       t = (p + q) % mod;       dp[idx][sta] = t;       return dp[idx][sta];     }   }   int main() {     long long i, k, ans = 1, sc = 1;     string str, ttr, ntr;     cin >> str;     cin >> ttr;     n = str.size();     m = ttr.size();     if (n >= m) {       for (i = 0; i <= n - m; i++) {         if (str[i] == ttr[0]) {           ntr = str.substr(i, m);           if (ntr == ttr) {             ara[i] = 1;           }         }         dp[i][0] = -1;         dp[i][1] = -1;         dp[i][2] = -1;       }     }     if (n >= m) {       for (i = n - m; i <= n; i++) {         dp[i][0] = -1;         dp[i][1] = -1;         dp[i][2] = -1;       }       ans = solve(0, 0);     }     if (ans >= sc)       k = ans - sc;     else {       k = (mod - sc) + ans;     }     printf( %lld n , k);     return 0;   }
#include <bits/stdc++.h>   void read(int& x) {     x = 0;     char c;     do {       c = getchar();     } while (c <  0  || c >  9 );     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }   }   using namespace std;   int n, m, f[1000 + 5][1000 + 5], ans, sum[1000 + 5];   int s[100000 + 5][3], as[100000 + 5];   vector<int> v[100000 + 5];   void place(int x, int y) {     f[x][y] = !f[x][y];     ans++;     sum[x]++;   }   void remove(int x, int y) {     f[x][y] = !f[x][y];     ans--;     sum[x]--;   }   void invert(int x) {     f[x][0] = !f[x][0];     ans -= sum[x];     sum[x] = m - sum[x];     ans += sum[x];   }   void dfs(int k) {     int o = 0, t, x, y, i;     t = s[k][0];     x = s[k][1];     y = s[k][2];     if (t == 1)       if (f[x][y] ^ f[x][0] ^ 1)         place(x, y);       else         o = 1;     if (t == 2)       if (f[x][y] ^ f[x][0])         remove(x, y);       else         o = 1;     if (t == 3) invert(x);     as[k] = ans;     for (i = 0; i < v[k].size(); i++) dfs(v[k][i]);     if (o) return;     if (t == 1) remove(x, y);     if (t == 2) place(x, y);     if (t == 3) invert(x);   }   int main() {     int q, x, y, i;     read(n);     read(m);     read(q);     for (i = 1; i <= q; i++) {       read(s[i][0]);       read(s[i][1]);       if (s[i][0] < 3) read(s[i][2]);       if (s[i][0] < 4)         v[i - 1].push_back(i);       else         v[s[i][1]].push_back(i);     }     dfs(0);     for (i = 1; i <= q; i++) printf( %d n , as[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int64_t n;     cin >> n;     multiset<int64_t> S;     if (n & 1) {       n--;       cout << n / 2 << endl;       while (n) {         S.insert(2);         n = n - 2;       }       auto itr = S.end();       itr--;       S.erase(itr);       S.insert(3);     } else {       cout << n / 2 << endl;       while (n) {         S.insert(2);         n = n - 2;       }     }     for (auto itr = S.begin(); itr != S.end(); itr++) {       cout << (*itr) <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     while (cin >> n) {       string s;       getline(cin, s);       getline(cin, s);       stringstream ss(s);       string token;       string res =   ;       vector<int> numelements;       bool error = 0;       if (s ==  int ) {         cout <<  int  << endl;         continue;       }       while (ss >> token) {         int cur = numelements.size() - 1;         if (cur >= 0 && numelements[cur] == 1) res +=  , ;         if (token ==  pair ) {           if (cur >= 0) {             numelements[cur]++;             if (numelements[cur] >= 3) {               error = 1;               break;             }           }           res +=  pair< ;           numelements.push_back(0);         } else if (token ==  int ) {           if (cur < 0) {             error = 1;             break;           }           numelements[cur]++;           res +=  int ;           if (numelements[cur] >= 3) {             error = 1;             break;           }           while (numelements.size() > 0 &&                  numelements[numelements.size() - 1] == 2) {             numelements.erase(numelements.end() - 1);             res +=  > ;           }         }       }       if (numelements.size() > 0) error = 1;       if (error)         cout <<  Error occurred  << endl;       else         cout << res << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, k, l, m, n, x, y, z;     cin >> n >> x >> y;     string s;     cin >> s;     for (i = 0; i < n; i++) {       if (s[i] ==  0 ) break;     }     if (i == n) return cout << 0 << endl, 0;     for (j = s.size() - 1; j >= 0; j--)       if (s[j] ==  0 ) break;     s = s.substr(i, j - i + 1);     long long int cnt = 0;     for (i = 1; i < s.size(); i++) {       if (s[i] ==  0  && s[i - 1] ==  1 ) cnt++;     }     cnt++;     cout << (cnt - 1) * min(x, y) + y << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int N = 2e5 + 5;   int gcd(int a, int b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   bool compare(long long i, long long j) { return i > j; }   long long power(long long x, long long y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return (power(x, y / 2) % mod * power(x, y / 2) % mod) % mod;     else       return (x % mod * power(x, y / 2) % mod * power(x, y / 2) % mod) % mod;   }   class sortByVal {    public:     bool operator()(const pair<long long, pair<long long, long long>> &a,                     const pair<long long, pair<long long, long long>> &b) {       if (a.first != b.first) {         return a.first < b.first;       }       return a.second.first > b.second.first;     }   };   bool prime[100005];   void SieveOfEratosthenes(long long n) {     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long a, b, n, m;       cin >> a >> b >> n >> m;       if (n + m > a + b) {         cout <<  NO  << endl;         ;       } else {         if (m > min(a, b)) {           cout <<  NO  << endl;           ;         } else           cout <<  YES  << endl;         ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   ifstream fin( A.in );   ofstream fout( A.out );   long long r, h;   int main() {     cin >> r >> h;     if (h % r == 0) {       cout << (h / r) * 2 + 1;       return 0;     }     double d = double(h) / double(r);     int z = h / r;     double dd = z + 0.5;     if (d >= dd) {       if ((r / 2) * (r / 2) + ((d - dd) * r + r / 2) * ((d - dd) * r + r / 2) >=           r * r)         cout << 2 * z + 3;       else         cout << 2 * z + 2;     } else {       cout << 2 * z + 1;     }   }
#include <bits/stdc++.h>   const int maxn = 1e2 + 10;   const int dis[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};   using namespace std;   long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }   long long qpow(long long p, long long q) {     long long f = 1;     while (q) {       if (q & 1) f = f * p % 1000000007;       p = p * p % 1000000007;       q >>= 1;     }     return f;   }   int n, m, k, t, q, co[maxn][maxn], c[maxn];   long long dp[maxn][maxn][maxn];   int main() {     int i, j;     for (i = 0; i <= 100; i++)       for (j = 0; j <= 100; j++)         for (k = 0; k <= 100; k++) dp[i][j][k] = 1e18;     scanf( %d%d%d , &n, &m, &q);     for (i = 1; i <= n; i++) scanf( %d , &c[i]);     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) scanf( %d , &co[i][j]);     i = 1;     if (i == 1) {       if (c[i])         dp[1][c[i]][1] = 0;       else {         for (j = 1; j <= m; j++) dp[1][j][1] = co[1][j];       }     }     for (i = 2; i <= n; i++) {       if (c[i]) {         for (j = 1; j <= m; j++)           for (k = 1; k <= 100; k++) {             if (j == c[i])               dp[i][j][k] = min(dp[i - 1][j][k], dp[i][j][k]);             else               dp[i][c[i]][k] = min(dp[i - 1][j][k - 1], dp[i][c[i]][k]);           }       } else {         for (j = 1; j <= m; j++)           for (k = 1; k <= 100; k++)             for (t = 1; t <= m; t++) {               dp[i][j][k] =                   min(dp[i][j][k], t == j ? dp[i - 1][t][k] + co[i][j]                                           : dp[i - 1][t][k - 1] + co[i][j]);             }       }     }     long long mi = 1e18;     for (i = 1; i <= m; i++) mi = min(dp[n][i][q], mi);     printf( %lld n , mi == 1e18 ? -1 : mi);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void CP() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     return;   }   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     int a[n + 1];     a[1] = 1;     for (int i = 2; i <= n; i++) {       a[i] = a[i - 1] + i;     }     for (int i = 1; i <= n; i++) {       cerr << a[i] <<    ;     }     cerr << endl;     if (m == 1) {       m -= 1;     } else {       if (m > a[n]) {         m %= a[n];         cerr << m << endl;       }       int i;       for (i = n - 1; i > 1; i--) {         if (m >= a[i]) {           m %= a[i];           break;         }       }       if (i == 1 && m != 0) {         m -= 1;       }     }     cout << m << endl;     return 0;   }
#include<bits/stdc++.h>   #define fast  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)   #define arin(x,n) for(int i=0;i<n;i++)cin>>x[i]   #define debug(x,n) for(int i=0;i<n;i++)cout<<x[i]<<      #define pb push_back   #define all(c) begin(c), end(c)   #define isAll(c) (int)(c).size()   typedef long long int ll;       using namespace std;      int solve(vector <pair<int, int>> &arr)   {       int num = isAll(arr);       vector <int> lc(num);        vector <int> rc(num);          for (int i = 0; i < num; i++)           lc[i] = arr[i].first, rc[i] = arr[i].second;          sort(all(lc)), sort(all(rc));          int result = 1e9 + 7;       for (auto [l, r] : arr)       {           int result_l = distance(begin(rc), lower_bound(all(rc), l)),               result_r = distance(upper_bound(all(lc), r), end(lc));                 result = min(result, result_l + result_r);       }       return result;   }       int main()   {    fast;    ll T=1;    cin>>T;    while(T--)    {     int num;     cin >> num;        vector <pair<int, int>> arr(num);     for(auto &[x, y] : arr)       cin >> x >> y;             cout << solve(arr) << endl;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, a, b;       string s =   , s1;       cin >> n >> a >> b;       for (int i = 0; i < b; i++) s += ( a  + i);       for (int i = b; i < a; i++) s +=  a ;       s1 = s;       int x = n / a, y = n % a;       x--;       while (x--) {         s += s1;       }       for (int i = 0; i < y; i++) s += s1[i];       cout << s << endl;     }   }
#include <bits/stdc++.h>   inline long long read() {     long long x = 0;     char ch = getchar(), w = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * w;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   inline void writeln(long long x) {     write(x);     puts(  );   }   using namespace std;   const int N = 5e5 + 656666;   long long n, m, c, c0;   struct TT {     long long t, a, b;   } a[N];   bool cmp(TT x, TT y) { return x.t < y.t; }   map<long long, long long> q;   long long cal() {     q.clear();     long long ans = 0;     q[0] = c0;     long long now = c0, cap = c;     for (int i = 1; i <= n; ++i) {       long long rest = a[i].t - a[i - 1].t;       long long val = 0;       now -= rest;       while (!q.empty() && rest) {         val = min(rest, q.begin()->second);         rest -= val;         q.begin()->second -= val;         ans += val * q.begin()->first;         if (!q.begin()->second) q.erase(q.begin());       }       if (rest) return -1;       long long ned = min(cap - now, a[i].a);       now += ned;       while (!q.empty() && a[i].b < q.rbegin()->first && ned < a[i].a) {         val = min(q.rbegin()->second, a[i].a - ned);         q.rbegin()->second -= val;         ned += val;         if (!q.rbegin()->second) q.erase(--q.end());       }       q[a[i].b] += ned;     }     return ans;   }   int main() {     int T = read();     while (T--) {       n = read(), m = read(), c = read(), c0 = read();       for (int i = 1; i <= n; ++i) {         a[i].t = read();         a[i].a = read();         a[i].b = read();       }       a[++n] = (TT){m, 0, 0};       sort(a + 1, a + 1 + n, cmp);       writeln(cal());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void task() {     int s, t, q, r = 1;     long long tm, cs;     cin >> t >> s >> q;     cs = s;     while (cs < t) {       tm = cs;       cs = (q - 1) * tm + cs;       if (cs < t) r++;     }     cout << r;   }   int main() {     ios_base::sync_with_stdio(false);     task();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cerr <<   n ; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << setw(2) << *it <<   =   << setw(2) << a <<    ;     err(++it, args...);   }   void solve() {     int n;     cin >> n;     int a[n], status[n], res[n];     memset(res, 0, sizeof res);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> status[i];     for (int i = 0; i < n; i++)       if (status[i]) res[i] = a[i];     vector<int> v;     for (int i = 0; i < n; i++) {       if (status[i] == 0) v.push_back(a[i]);     }     sort(v.rbegin(), v.rend());     int idx = 0;     for (int i = 0; i < n; i++)       if (status[i] == 0) res[i] = v[idx++];     for (int i = 0; i < n; i++) cout << res[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int test;     cin >> test;     while (test--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[1000000];   vector<pair<int, int> > ans;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= k; i++) {       int high = 1, low = 1;       for (int j = 2; j <= n; j++) {         if (a[j] > a[high]) high = j;         if (a[j] < a[low]) low = j;       }       if (high != low) {         ans.push_back(make_pair(high, low));         a[high]--;         a[low]++;       }     }     int high = 1, low = 1;     for (int j = 2; j <= n; j++) {       if (a[j] > a[high]) high = j;       if (a[j] < a[low]) low = j;     }     int s = ans.size();     cout << a[high] - a[low] <<     << s << endl;     ;     for (int i = 0; i <= s - 1; i++)       cout << ans[i].first <<     << ans[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MN = 44, MS = (1 << 21) + 2;   int n, K;   long long adj[MN];   int dp[MS], clique;   bool is[MS];   int main() {     ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> K;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) {         bool t;         cin >> t;         adj[i] |= (1ll << j) * t;       }     if (n == 1) return cout <<  0 n , 0;     int b = n / 2;     for (int msk = 1; msk < (1 << b); ++msk) {       int v = __builtin_ctz(msk);       dp[msk] = dp[msk ^ (1 << v)];       dp[msk] = max(dp[msk], dp[(msk ^ (1 << v)) & adj[v]] + 1);       clique = max(clique, dp[msk]);     }     is[0] = true;     for (int msk = 1; msk < (1 << (n - b)); ++msk) {       int v = __builtin_ctz(msk);       is[msk] = is[msk ^ (1 << v)];       v += b;       for (int i = b; i < n; ++i)         if (i != v) {           if ((msk & (1 << (i - b))) && !(adj[v] & (1ll << i))) is[msk] = false;         }       if (is[msk]) {         long long M = (1 << b) - 1;         for (int i = b; i < n; ++i)           if (msk & 1 << (i - b)) M &= adj[i];         clique = max(clique, dp[M] + __builtin_popcount(msk));       }     }     cout << setprecision(12) << fixed          << 1ll * clique * (clique - 1) * ((long double)K / clique) *                 ((long double)K / clique) / 2          <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, int> > v;   int n;   long long A[100005];   long long B[100005];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int a, b;       scanf( %d %d , &a, &b);       A[i] = (long long)a;       B[i] = (long long)b;       v.push_back(make_pair((long long)(b - a), i));     }     sort(v.begin(), v.end());     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long a = A[v[i - 1].second];       long long b = B[v[i - 1].second];       ans += a * ((long long)(i - 1)) + b * ((long long)(n - i));     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, string> mapa;   int main() {     mapa[0] =  zero ;     mapa[1] =  one ;     mapa[2] =  two ;     mapa[3] =  three ;     mapa[4] =  four ;     mapa[5] =  five ;     mapa[6] =  six ;     mapa[7] =  seven ;     mapa[8] =  eight ;     mapa[9] =  nine ;     mapa[10] =  ten ;     mapa[11] =  eleven ;     mapa[12] =  twelve ;     mapa[13] =  thirteen ;     mapa[14] =  fourteen ;     mapa[15] =  fifteen ;     mapa[16] =  sixteen ;     mapa[17] =  seventeen ;     mapa[18] =  eighteen ;     mapa[19] =  nineteen ;     mapa[20] =  twenty ;     mapa[30] =  thirty ;     mapa[40] =  forty ;     mapa[50] =  fifty ;     mapa[60] =  sixty ;     mapa[70] =  seventy ;     mapa[80] =  eighty ;     mapa[90] =  ninety ;     int num;     cin >> num;     if (num <= 19) {       cout << mapa[num] << endl;     } else if (num % 10 == 0) {       cout << mapa[num] << endl;     } else {       int aux = (num / 10) * 10;       int rest = num % 10;       cout << mapa[aux] <<  -  << mapa[rest] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, a = 0;     cin >> x >> y;     for (int i = 1; i <= x; i++) {       if (i % 2 == 0) {         if (a == 0) {           for (int k = 0; k < y - 1; k++) {             cout <<  . ;           }           cout <<  #  << endl;           a++;         } else {           a = 0;           cout <<  # ;           for (int k = 0; k < y - 1; k++) {             if (k == y - 2) {               cout <<  .  << endl;             } else {               cout <<  . ;             }           }         }       } else {         for (int j = 0; j < y; j++) {           if (j == y - 1) {             cout <<  #  << endl;           } else {             cout <<  # ;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }   int main() {     int A, B, i;     long long int sum = 0;     int a[100001] = {0};     cin >> A;     cin >> B;     for (i = 0; i < A; i++) {       cin >> a[i];     }     qsort(a, A, sizeof(int), cmpfunc);     for (i = 1; i < A; i++) {       if ((a[i] - a[0]) % B == 0)         sum = sum + (a[i] - a[0]) / B;       else {         sum = -1;         break;       }     }     cout << sum;     return 0;   }