malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long n1 = n - (k - 1);       if (n1 > 0 && n1 % 2 == 1) {         cout <<  YES n ;         for (long long i = 0; i < k - 1; i++) cout <<  1  ;         cout << n1 <<   n ;         continue;       }       long long n2 = n - 2 * (k - 1);       if (n2 > 0 && n2 % 2 == 0) {         cout <<  YES n ;         for (long long i = 0; i < k - 1; i++) cout <<  2  ;         cout << n2 <<   n ;         continue;       }       cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int main() {     int n, K;     cin >> n >> K;     if (K == 1 || n <= 3) {       puts( -1 );     } else if (K >= n) {       puts( -1 );     } else if (n == 4) {       if (K == 3) {         puts( 3 n1 2 n2 3 n3 4 );       } else {         puts( -1 );       }     } else {       if (K == 3) {         vector<pair<int, int> > E;         E.push_back({1, 2});         E.push_back({2, 3});         E.push_back({3, 4});         for (int i = 2; i <= 3; ++i) {           for (int j = 5; j <= n; ++j) {             E.push_back({i, j});           }         }         printf( %d n , E.size());         for (auto it : E) {           printf( %d %d n , it.first, it.second);         }       } else if (K == 2) {         printf( %d n , n - 1);         for (int i = 1; i < n; ++i) {           printf( %d %d n , i, i + 1);         }       } else {         puts( -1 );       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int N;   char s[105];   int dp[105][2605];   void pre() {     dp[0][0] = 1;     for (int i = 1; i <= 100; i++)       for (int j = 0; j <= 25 * i; j++)         for (int c = 0; c < 26; c++)           if (j - c >= 0) (dp[i][j] += dp[i - 1][j - c]) %= mod;   }   void solve_test() {     scanf( %s n , s + 1);     N = strlen(s + 1);     int cst = 0;     for (int i = 1; i <= N; i++) cst += s[i] -  a ;     int ans = (dp[N][cst] - 1 + mod) % mod;     printf( %d n , ans);   }   int main() {     pre();     int T;     scanf( %d n , &T);     for (int t = 1; t <= T; t++) solve_test();     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   long long step(long long a, long long n) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return step(a * a, n / 2);     else       return a * step(a, n - 1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<int> A, d;     A.resize(n + 1);     d.resize(n + 1);     for (int i = 1; i <= n; i++) cin >> A[i];     vector<int> tmp(n + 1, 10e6);     for (int i = n; i >= 1; i--) {       d[i] = tmp[A[i]];       tmp[A[i]] = i;     }     set<pair<int, int>> cur;     set<int> used;     int ans = 0, last = 0;     for (int i = 0; i <= n; i++) tmp[i] = 0;     for (int i = 1; i <= n && used.size() < k; i++) {       if (used.find(A[i]) == used.end()) {         ans++;         used.insert(A[i]);         cur.insert(make_pair(-d[i], A[i]));         tmp[A[i]] = -d[i];       } else {         cur.erase(cur.find(make_pair(tmp[A[i]], A[i])));         cur.insert(make_pair(-d[i], A[i]));         tmp[A[i]] = -d[i];       }       last = i;     }     for (int i = last + 1; i <= n; i++) {       if (used.find(A[i]) != used.end()) {         cur.erase(cur.find(make_pair(tmp[A[i]], A[i])));         cur.insert(make_pair(-d[i], A[i]));         tmp[A[i]] = -d[i];       } else {         pair<int, int> t = *cur.begin();         cur.erase(cur.begin());         used.erase(t.second);         used.insert(A[i]);         cur.insert(make_pair(-d[i], A[i]));         tmp[A[i]] = -d[i];         ans++;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[200005];   int mv;   int main() {     scanf( %d , &n);     mv = n / 2;     if (n % 2 == 0) mv--;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     sort(a + 1, a + n + 1);     int ret = 2000000000;     for (int i = 0; i <= mv; i++) {       ret = min(ret, a[n - (mv - i)] - a[i + 1]);     }     printf( %d n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, b, mod;   int a[505];   int dp[505][505];   int main() {     scanf( %d%d%d%d , &n, &m, &b, &mod);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     dp[0][0] = 1;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         for (int k = a[i]; k <= b; ++k) {           dp[j][k] += dp[j - 1][k - a[i]];           if (dp[j][k] >= mod) dp[j][k] -= mod;         }       }     }     int ans = 0;     for (int i = 0; i <= b; ++i) {       ans += dp[m][i];       if (ans >= mod) ans -= mod;     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100050, maxm = 5050;   int n, m, K, p, h[maxn], a[maxn];   long long hh[maxn], ans;   long long tim[maxn];   int cnt[maxm];   bool judg(long long x) {     int i, j;     long long tis = 0;     for (i = 0; i < m; i++) cnt[i] = 0;     for (i = 0; i < n; i++) tis += tim[i] = max(0LL, (hh[i] - x - 1 + p) / p);     if (tis > K * m) return 0;     for (i = 0; i < n; i++) {       int now = 0, h0 = h[i];       for (j = 0; j < tim[i]; j++) {         long long t = h0 + 1LL * (m - now) * a[i] - 1LL * (tim[i] - j - 1) * p -                       x,                   tn;         if (h0 < t)           tn = now + (t - h0 - 1) / a[i] + 1;         else           tn = now;         if (tn >= m) return 0;         h0 = max(0LL, h0 + (tn - now) * a[i] - p);         cnt[now = tn]++;       }     }     for (i = m - 1; i >= 0; i--) {       cnt[i] += cnt[i + 1];       if (cnt[i] > (m - i) * K) return 0;     }     return 1;   }   int main() {     int i, j;     long long l = 0, r = 0, mid;     scanf( %d%d%d%d , &n, &m, &K, &p);     for (i = 0; i < n; i++)       scanf( %d%d , &h[i], &a[i]), r = max(r, hh[i] = h[i] + 1LL * a[i] * m);     while (l < r) {       mid = (l + r) >> 1;       if (judg(mid))         r = mid;       else         l = mid + 1;     }     ans = l;     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   int n, num[100], cnt[N];   long long a[N];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       long long temp = a[i];       while (temp && temp % 2 == 0) {         cnt[i]++;         temp /= 2;       }       num[cnt[i]]++;     }     int id = 0;     for (int i = 1; i <= 63; i++)       if (num[i] > num[id]) id = i;     cout << n - num[id] << endl;     for (int i = 1; i <= n; i++)       if (cnt[i] != id) cout << a[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000000 + 2;   const long long MOD = 1e9 + 7;   int N, p[MAXN];   long long s[MAXN], c[MAXN], f[MAXN], Ans;   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   int main() {     cin >> N;     for (int i = 1; i <= N; i++) scanf( %lld , s + i);     for (int i = 2; i <= N; i++) scanf( %d , p + i);     for (int i = N; i; i--) s[p[i]] += s[i];     for (int i = N; i; i--) {       s[i] = s[1] / gcd(s[1], s[i]);       if (s[i] <= N) c[s[i]]++;     }     for (int i = N; i; i--)       for (int j = 2 * i; j <= N; j += i) c[j] = (c[j] + c[i]) % MOD;     f[1] = 1;     for (int i = 1; i <= N; i++)       if (c[i] >= i)         for (int j = 2 * i; j <= N; j += i) f[j] = (f[j] + f[i]) % MOD;     for (int i = 1; i <= N; i++)       if (c[i] >= i) Ans = (Ans + f[i]) % MOD;     cout << Ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       a.push_back(x);     }     sort(a.begin(), a.end());     int l = 0;     int r = n - 1;     for (int i = 0; i < n; i++) {       if (i % 2) {         cout << a[r--] <<    ;       } else {         cout << a[l++] <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long qpow(long long a, long long n) {     long long res = 1;     while (n) {       if (n % 2) {         res = (res * a) % 100000007;         n--;       } else {         n = n / 2;         a = (a * a) % 100000007;       }     }     return res;   }   void solve() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, q;     cin >> n >> q;     vector<long long> arr(n + 1);     for (long long i = 1; i <= n; i++) cin >> arr[i];     vector<long long> H(n + 1);     for (long long i = 0; i < q; i++) {       long long l, r;       cin >> l >> r;       H[l]++;       if (r + 1 <= n) H[r + 1]--;     }     for (long long i = 1; i <= n; i++) H[i] += H[i - 1];     sort(H.begin() + 1, H.end());     sort(arr.begin() + 1, arr.end());     long long sum = 0;     for (long long i = 1; i <= n; i++) sum += H[i] * arr[i];     cout << sum <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string A[15];   long long nr[100];   int N, K;   long long mn = 1000000000;   int main() {     scanf( %d %d n , &N, &K);     for (int i = 1; i <= N; i++) cin >> A[i];     vector<int> v;     for (int i = 1; i <= K; i++) v.push_back(i);     do {       for (int i = 1; i <= N; i++) {         nr[i] = 0;         for (int j = 0; j < K; j++) nr[i] = nr[i] * 10 + (A[i][v[j] - 1] -  0 );       }       sort(nr + 1, nr + N + 1);       mn = min(mn, nr[N] - nr[1]);     } while (next_permutation(v.begin(), v.end()));     cout << mn;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, f = 0, s = 0;     char pass[3], x[2];     cin >> pass[0] >> pass[1];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x[0] >> x[1];       if (x[0] == pass[0] && x[1] == pass[1]) {         cout <<  YES ;         return 0;       }       if (x[1] == pass[0]) {         f = 1;       }       if (x[0] == pass[1]) {         s = 1;       }     }     if (s && f) {       cout <<  YES ;       return 0;     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, x, y, n;       cin >> a >> b >> x >> y >> n;       long long p = a - x, q = b - y;       long long pp = min(p, n), qq = min(q, n);       long long aa = a - pp, bb = b - qq;       long long tt = a + b - n;       if (p + q <= n)         cout << x * y << endl;       else {         if (aa < bb)           cout << aa * (tt - aa) << endl;         else           cout << bb * (tt - bb) << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 110;   int n;   char s[N][30];   char ss[30];   int p;   int len[N];   int in[30];   int nxt[30];   int bf[30][30], ind[30];   void go(int i) {     ss[p++] = char(i +  a );     if (nxt[i] >= 0) go(nxt[i]);   }   int main() {     scanf( %d , &n);     memset(nxt, -1, sizeof(nxt));     for (int i = 0; i < n; ++i) {       scanf( %s , s[i]);       len[i] = strlen(s[i]);     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < len[i]; ++j) {         in[s[i][j] -  a ] = 1;         for (int k = j + 1; k < len[i]; ++k) {           bf[s[i][j] -  a ][s[i][k] -  a ] = 1;         }       }       for (int j = 0; j < len[i] - 1; ++j) {         nxt[s[i][j] -  a ] = s[i][j + 1] -  a ;       }     }     for (int i = 0; i < 26; ++i) {       for (int j = 0; j < 26; ++j) {         if (bf[j][i]) {           ++ind[i];         }       }     }     for (int i = 0; i < 26; ++i) {       if (!ind[i] && in[i]) {         go(i);       }     }     puts(ss);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string st[30] = { zero ,     one ,      two ,        three ,     four ,                     five ,     six ,      seven ,      eight ,     nine ,                     ten ,      eleven ,   twelve ,     thirteen ,  fourteen ,                     fifteen ,  sixteen ,  seventeen ,  eighteen ,  nineteen ,                     twenty ,   thirty ,   forty ,      fifty ,     sixty ,                     seventy ,  eighty ,   ninety };   int main() {     int n;     while (cin >> n) {       if (n <= 20)         cout << st[n];       else if (n % 10 == 0)         cout << st[20 + n / 10 - 2];       else if (n < 30)         cout << st[20] +  -  + st[n % 10];       else if (n < 40)         cout << st[21] +  -  + st[n % 10];       else if (n < 50)         cout << st[22] +  -  + st[n % 10];       else if (n < 60)         cout << st[23] +  -  + st[n % 10];       else         cout << st[20 + n / 10 - 2] +  -  + st[n % 10];       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int dpmax[200005][20];   long long int dpmin[200005][20];   long long int a[200005], b[200005];   int n;   void ST() {     for (int i = 1; i <= n; i++) {       dpmax[i][0] = a[i];       dpmin[i][0] = b[i];     }     for (int j = 1; (1 << j) <= n; j++) {       for (int i = 1; i + (1 << j) - 1 <= n; i++) {         dpmax[i][j] = dpmax[i][j - 1] > dpmax[i + (1 << (j - 1))][j - 1]                           ? dpmax[i][j - 1]                           : dpmax[i + (1 << (j - 1))][j - 1];         dpmin[i][j] = dpmin[i][j - 1] < dpmin[i + (1 << (j - 1))][j - 1]                           ? dpmin[i][j - 1]                           : dpmin[i + (1 << (j - 1))][j - 1];       }     }   }   long long int RMQmax(int l, int r) {     int k = 0;     while ((1 << (k + 1)) <= r - l + 1) k++;     return dpmax[l][k] > dpmax[r - (1 << k) + 1][k] ? dpmax[l][k]                                                     : dpmax[r - (1 << k) + 1][k];   }   long long int RMQmin(int l, int r) {     int k = 0;     while ((1 << (k + 1)) <= r - l + 1) k++;     return dpmin[l][k] < dpmin[r - (1 << k) + 1][k] ? dpmin[l][k]                                                     : dpmin[r - (1 << k) + 1][k];   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     ST();     long long int ans = 0;     for (int i = 1; i <= n; i++) {       int l = i, r = n, mid, flag = 0;       long long int x, y;       long long int last = 0, first = 0;       while (l <= r) {         mid = (l + r) / 2;         x = RMQmax(i, mid);         y = RMQmin(i, mid);         if (x == y) {           flag = 1;           last = mid;         }         if (x > y) r = mid - 1;         if (x < y || x == y) l = mid + 1;       }       if (flag) {         l = i;         r = n;         while (l <= r) {           mid = (l + r) / 2;           x = RMQmax(i, mid);           y = RMQmin(i, mid);           if (x < y) {             l = mid + 1;           } else {             r = mid - 1;             first = mid;           }         }         ans += (last - first + 1);       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1e6 + 20;   const int maxm = 1e5 + 10;   const long long int mod = 998244353;   const long long int INF = 1e18 + 100;   const int inf = 0x3f3f3f3f;   const double pi = acos(-1.0);   const double eps = 1e-8;   using namespace std;   int a[50][50];   int num[200], c[200];   int main() {     int _;     for (scanf( %d , &_); _; _--) {       memset(num, 0, sizeof num);       memset(c, 0, sizeof c);       memset(a, 0, sizeof a);       int n, m;       scanf( %d %d , &n, &m);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);       if (n == 2 && m == 2) {         if (a[0][0] != a[1][1])           puts( 1 );         else           puts( 0 );       } else {         n--;         m--;         for (int i = 0; i <= n; i++) {           for (int j = 0; j <= m; j++) {             c[i + j]++;             num[i + j] += a[i][j];           }         }         int ans = 0;         if ((n + m) % 2 == 1) {           for (int i = 0; i < (n + m) / 2; i++) {             ans += min(num[i] + num[n + m - i],                        (c[i] + c[n + m - i]) - (num[i] + num[n + m - i]));           }           int i = (n + m) / 2;           ans += min(num[i] + num[n + m - i],                      (c[i] + c[n + m - i]) - (num[i] + num[n + m - i]));         } else {           for (int i = 0; i < (n + m) / 2; i++) {             ans += min(num[i] + num[n + m - i],                        (c[i] + c[n + m - i]) - (num[i] + num[n + m - i]));           }         }         printf( %d n , ans);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   const int MOD = 998244353;   int main() {     int n;     while (cin >> n) {       int p;       long long x = 0, y = 0;       for (int i = 1; i <= n; i++) {         cin >> p;         x += p / 2;         y += p / 2;         if (p % 2) {           if (i % 2)             x++;           else             y++;         }       }       printf( %I64d n , min(x, y));     }   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int i;     char n[100010], m;     stack<char> s;     scanf( %s , n);     for (i = 0; n[i] != 0; i++) {       if (s.empty()) {         s.push(n[i]);       } else {         m = s.top();         if (m == n[i])           s.pop();         else           s.push(n[i]);       }     }     if (s.empty())       printf( Yes n );     else       printf( No n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, pair<int, int> > > E(m);     {       int cnt = 0;       for (int i = 0; i < m; i++) {         cin >> E[i].first >> E[i].second.first;         E[i].second.second = i;         if (E[i].second.first == 1) cnt++;         E[i].second.first = 1 - E[i].second.first;       }       if (cnt != n - 1) {         cout << -1 << endl;         return 0;       }     }     sort(E.begin(), E.end());     vector<pair<int, int> > res(m);     queue<pair<int, int> > que;     int latest = 1;     for (int i = 0; i < m; i++) {       if (E[i].second.first == 0) {         res[E[i].second.second] = make_pair(latest, latest + 1);         for (int u = 1; u < latest && que.size() < m; u++)           que.push(make_pair(u, latest + 1));         latest++;       } else {         if (que.empty()) {           cout << -1 << endl;           return 0;         } else {           auto v = que.front();           que.pop();           res[E[i].second.second] = v;         }       }     }     for (int i = 0; i < m; i++)       cout << res[i].first <<     << res[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   const int M = 1e9 + 100;   long long a[N];   int main() {     int n, m;     long long x, y;     while (~scanf( %d %d , &n, &m)) {       x = -M;       y = M;       for (int i = 0; i < n; i++) {         scanf( %lld , &a[i]);         x = max(a[i], x);         y = min(a[i], y);       }       if (m == 1)         printf( %lld n , y);       else if (m >= 3)         printf( %lld n , x);       else         printf( %lld n , max(a[0], a[n - 1]));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       vector<int> deg(n);       vector<vector<int>> adj(n);       for (int i = 0, u, v; i < m; ++i) {         cin >> u >> v;         --u, --v;         adj[u].push_back(v);         adj[v].push_back(u);         ++deg[u], ++deg[v];       }       deque<int> q;       for (int i = 0; i < n; ++i) {         sort(adj[i].begin(), adj[i].end());         if (deg[i] == k - 1) q.push_back(i);         if (deg[i] < k - 1) q.push_front(i);       }       vector<int> ans;       vector<bool> mp(n);       while (!q.empty()) {         int u = q.front();         q.pop_front();         if (deg[u] == -1) continue;         if (deg[u] == k - 1) {           vector<int> &c = ans;           for (auto v : adj[u])             if (deg[v] != -1) {               c.push_back(v);               mp[v] = true;             }           c.insert(upper_bound(c.begin(), c.end(), u), u);           mp[u] = true;           bool ok = true;           for (auto &i : c) {             if (adj[i].size() <= 3 * c.size()) {               int cnt = 0;               for (auto j : adj[i]) cnt += mp[j];               if (cnt != k - 1) {                 ok = false;                 break;               }             } else {               for (size_t j = &i - &c[0]; ++j < c.size();) {                 auto it = lower_bound(adj[i].begin(), adj[i].end(), c[j]);                 if (it == adj[i].end() || *it != c[j]) {                   ok = false;                   break;                 }               }             }           }           if (ok) break;           for (auto i : c) mp[i] = false;           c.clear();         }         deg[u] = -1;         for (auto v : adj[u])           if (deg[v] != -1) {             if (deg[v] == k - 1) q.push_front(v);             if (deg[v] == k) q.push_back(v);             --deg[v];           }       }       if (ans.empty()) {         for (int i = 0; i < n; ++i)           if (deg[i] != -1) ans.push_back(i);         if (!ans.empty()) {           cout <<  1   << ans.size() <<   n ;           for (auto &i : ans) cout << i + 1 <<    n [&i == &ans.back()];         } else           cout <<  -1 n ;       } else {         cout <<  2 n ;         for (auto &i : ans) cout << i + 1 <<    n [&i == &ans.back()];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mas[1001][1001];   char chars[1000][1001];   int n, m;   int st = 0;   vector<int> woi;   int p = 0;   void dfs(int x, int y) {     st++;     mas[x][y] = p;     if (x != 0) {       if (mas[x - 1][y] == 0 && chars[x - 1][y] ==  . ) {         dfs(x - 1, y);       }     }     if (y != 0) {       if (mas[x][y - 1] == 0 && chars[x][y - 1] ==  . ) {         dfs(x, y - 1);       }     }     if (x + 1 != n) {       if (mas[x + 1][y] == 0 && chars[x + 1][y] ==  . ) {         dfs(x + 1, y);       }     }     if (y + 1 != m + 1) {       if (mas[x][y + 1] == 0 && chars[x][y + 1] ==  . ) {         dfs(x, y + 1);       }     }   }   void startdfs(int x, int y) {     st = 0;     p++;     dfs(x, y);     woi.push_back(st);   }   int calculate(int x, int y) {     int ans = 1;     set<int> f;     if (x != 0) {       f.emplace(mas[x - 1][y]);     }     if (y != 0) {       f.emplace(mas[x][y - 1]);     }     if (x != n) {       f.emplace(mas[x + 1][y]);     }     if (y != m + 1) {       f.emplace(mas[x][y + 1]);     }     for (auto w : f) {       ans += woi[w];     }     return ans;   }   int main() {     char ch;     woi.push_back(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m + 1; j++) {         scanf( %c , &ch);         chars[i][j] = ch;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m + 1; j++) {         if (chars[i][j] ==  .  && mas[i][j] == 0) {           startdfs(i, j);         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m + 1; j++) {         if (chars[i][j] ==  * ) {           int c = calculate(i, j) % 10;           chars[i][j] = c +  0 ;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 1; j < m + 1; j++) {         printf( %c , chars[i][j]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, A[100000], count0 = 0, max = 0;     scanf( %i , &n);     for (int i = 0; i < n; i++) {       scanf( %i , A + i);       if (A[i] < 0) A[i] = -A[i] - 1;       if (!A[i]) count0++;       if (A[i] > max) max = A[i];     }     if (count0 == n) {       for (int i = 1; i < n; i++) printf( -1  );       return 0 * printf(n & 1 ?  0  :  -1 );     }     for (int i = 0; i < n; i++) {       if (A[i]) {         if (A[i] == max) {           if (n & 1)             printf( %i  , max);           else             printf( %i  , -A[i] - 1);           max = 0;         } else           printf( %i  , -A[i] - 1);       } else         printf( -1  );     }   }