malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, q, a[N], s1[N], t1, s2[N], t2;   vector<int> ans1[N], ans2[N];   bool tag[N];   inline void down(int &x, const int y) { x > y ? x = y : 0; }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     set<int> cand;     int mp[2] = {n, n};     for (int i = n; i; --i) {       if (i < n && a[i] != a[i + 1]) {         bool t = a[i] > a[i + 1];         if (mp[t ^ 1] < n) ans1[i] = {i, mp[t ^ 1], mp[t ^ 1] + 1};         mp[t] = i;       }       while (t1 && a[s1[t1]] > a[i]) {         if (tag[s1[t1]]) cand.emplace(s1[t1]);         tag[s1[t1--]] = true;       }       while (t2 && a[s2[t2]] < a[i]) {         if (tag[s2[t2]]) cand.emplace(s2[t2]);         tag[s2[t2--]] = true;       }       int _t1 = t1, _t2 = t2, l, r;       for (l = 1, r = t1, t1 = 0; l <= r;) {         int mid = l + r >> 1;         if (a[s1[mid]] != a[i])           t1 = mid, l = mid + 1;         else           r = mid - 1;       }       for (l = 1, r = t2, t2 = 0; l <= r;) {         int mid = l + r >> 1;         if (a[s2[mid]] != a[i])           t2 = mid, l = mid + 1;         else           r = mid - 1;       }       if (t1 && t2) {         int pos = max(s1[t1], s2[t2]);         auto nxt = cand.upper_bound(pos);         if (nxt != cand.end()) {           int p1, p2, l, r, rr = *nxt;           for (l = 1, r = t1; l <= r;) {             int mid = l + r >> 1;             if (s1[mid] < rr)               p1 = s1[mid], r = mid - 1;             else               l = mid + 1;           }           for (l = 1, r = t2; l <= r;) {             int mid = l + r >> 1;             if (s2[mid] < rr)               p2 = s2[mid], r = mid - 1;             else               l = mid + 1;           }           if (p1 > p2) swap(p1, p2);           ans2[i] = {i, p1, p2, rr};         }       }       s1[t1 = _t1 + 1] = i, s2[t2 = _t2 + 1] = i;     }     for (int i = n; i; --i) {       if (!ans1[i + 1].empty() &&           (ans1[i].empty() || ans1[i + 1].back() < ans1[i].back()))         ans1[i] = ans1[i + 1];       if (!ans2[i + 1].empty() &&           (ans2[i].empty() || ans2[i + 1].back() < ans2[i].back()))         ans2[i] = ans2[i + 1];     }     for (int t = 0, l, r; t < q; ++t) {       scanf( %d%d , &l, &r);       if (!ans2[l].empty() && ans2[l].back() <= r) {         puts( 4 );         for (auto x : ans2[l]) printf( %d  , x);         puts(  );       } else if (!ans1[l].empty() && ans1[l].back() <= r) {         puts( 3 );         for (auto x : ans1[l]) printf( %d  , x);         puts(  );       } else         puts( 0 ), puts(  );     }     return 0;   }
#include <bits/stdc++.h>   int mod, n, a, b, good;   std::set<std::pair<int, int> > set;   std::pair<int, int> make_pair(int i, int j) {     return {std::min(i, j), std::max(i, j)};   }   int main() {     scanf( %d%d , &mod, &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &a, &b);       set.insert(make_pair(a - 1, b - 1));     }     for (int k = 1; k < mod && !good; k++) {       if (mod % k == 0) {         good = true;         for (auto p = set.begin(); good && p != set.end(); p++)           if (!set.count(make_pair((p->first + k) % mod, (p->second + k) % mod)))             good = false;       }     }     printf( %s n , good ?  yes  :  no );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, y, z, d[200 + 5], nows[200 + 5], fr[200 + 5], en[200 + 5],       A[200 + 5], S, T, fa[200 + 5], now, Bh, Ch, B[200 + 5], C[200 + 5], H, un,       wn, ToT;   struct yyy {     int to, w, z;   } tmp;   struct ljb {     int head, h[200 + 5];     yyy f[1000 + 5 << 2];     inline void add(int x, int y, int z) {       f[head] = (yyy){y, z, h[x]};       h[x] = head++;     }   } s, G;   queue<int> Q;   struct ques {     int x, y, z;   } F[200 + 5];   inline bool cmp(ques x, ques y) { return x.z > y.z; }   inline void Get(int x, int y, int z) {     s.add(x, y, z);     s.add(y, x, z);   }   inline int bfs() {     while (!Q.empty()) Q.pop();     memset(d, 0x3f, sizeof(d));     d[S] = 0;     Q.push(S);     nows[S] = s.h[S];     while (!Q.empty()) {       now = Q.front();       Q.pop();       for (int i = s.h[now]; ~i; i = tmp.z) {         tmp = s.f[i];         if (!tmp.w || d[tmp.to] < 1e9) continue;         d[tmp.to] = d[now] + 1;         Q.push(tmp.to);         nows[tmp.to] = s.h[tmp.to];         if (tmp.to == T) return 1;       }     }     return 0;   }   inline int dfs(int x, int sum) {     if (x == T) return sum;     int i, k, pus = 0;     yyy tmp;     for (i = nows[x]; ~i; i = tmp.z) {       tmp = s.f[i];       nows[x] = i;       if (!tmp.w || d[tmp.to] != d[x] + 1) continue;       k = dfs(tmp.to, ((sum) < (tmp.w) ? (sum) : (tmp.w)));       if (!k) d[tmp.to] = 1e9;       pus += k;       sum -= k;       s.f[i].w -= k;       s.f[i ^ 1].w += k;       if (!sum) break;     }     return pus;   }   inline void build(int l, int r) {     if (l == r) return;     int Ans = 0, i;     S = A[l];     T = A[r];     s = G;     while (bfs()) Ans += dfs(S, 1e9);     F[++H] = (ques){S, T, Ans};     ToT += Ans;     Bh = Ch = 0;     for (i = l; i <= r; i++) (d[A[i]] < 1e9 ? B[++Bh] : C[++Ch]) = A[i];     for (i = l; i <= l + Bh - 1; i++) A[i] = B[i - l + 1];     for (i = l + Bh; i <= r; i++) A[i] = C[i - l - Bh + 1];     Ans = Bh;     build(l, l + Ans - 1);     build(l + Ans, r);   }   inline int Getfa(int x) { return x == fa[x] ? x : fa[x] = Getfa(fa[x]); }   int main() {     register int i;     scanf( %d%d , &n, &m);     memset(s.h, -1, sizeof(s.h));     for (i = 1; i <= m; i++) scanf( %d%d%d , &x, &y, &z), Get(x, y, z);     for (i = 1; i <= n; i++) A[i] = i;     G = s;     build(1, n);     sort(F + 1, F + n, cmp);     for (i = 1; i <= n; i++) fa[i] = en[i] = fr[i] = i;     for (i = 1; i < n; i++)       un = Getfa(F[i].x), wn = Getfa(F[i].y), en[un] = fr[wn], fr[wn] = fr[un],       fa[un] = wn;     now = fr[Getfa(1)];     printf( %d n , ToT);     while (en[now] ^ now) printf( %d  , now), now = en[now];     printf( %d n , now);   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     int ans = 1;     for (int i = 2; i <= n; ++i) {       ans = 1LL * ans * i % M;     }     int two = 1;     for (int i = 1; i < n; ++i) {       two = (two + two) % M;     }     cout << (ans - two + M) % M <<   n ;   }
#include <bits/stdc++.h>   typedef int iarrN[100003][35];   struct IO {     template <typename T>     inline IO operator>>(T &n) {       n = 0;       char c = getchar();       while (c <  0  || c >  9 ) c = getchar();       while (c >=  0  && c <=  9 )         n = (n << 3) + (n << 1) + (c ^ 48), c = getchar();       return *this;     }   } cin;   constexpr int MX = 33, inf = 0x3f3f3f3f;   int N, son[100003][35], mnw[100003][35];   long long K, sw[100003][35];   void init() {     cin >> N >> K;     for (int i = 1; i <= N; ++i) cin >> son[i][0], ++son[i][0];     for (int i = 1; i <= N; ++i) cin >> mnw[i][0], sw[i][0] = mnw[i][0];     for (int j = 1; j <= MX; ++j)       for (int i = 1; i <= N; ++i) {         son[i][j] = son[son[i][j - 1]][j - 1];         sw[i][j] = sw[i][j - 1] + sw[son[i][j - 1]][j - 1];         mnw[i][j] = std::min(mnw[i][j - 1], mnw[son[i][j - 1]][j - 1]);       }   }   inline void query(int u) {     int ansmn = inf;     long long k = K, anss = 0;     for (int i = MX; i >= 0; --i)       if (k >= (1ll << i)) {         k -= 1ll << i;         anss += sw[u][i];         ansmn = std::min(ansmn, mnw[u][i]);         u = son[u][i];       }     printf( %I64d %d n , anss, ansmn);   }   int main() {     init();     for (int i = 1; i <= N; ++i) query(i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     long long f = 1;     long long x = 0;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return x * f;   };   const int maxn = 1e4 + 5;   int res[maxn];   int main() {     int n = read(), d = read(), l = read();     int up, dw;     up = (n / 2 + (n & 1)) * l - (n / 2);     dw = (n / 2 + (n & 1)) - (n / 2) * l;     if (d < dw || d > up) {       printf( -1 );       return 0;     }     for (int i = 1, now = up; i <= n; ++i) {       if (now == d) {         printf( %d  , i & 1 ? l : 1);         continue;       }       int del = min(now - d, l - 1);       if (i & 1) {         printf( %d  , l - del);         now -= del;       } else {         printf( %d  , 1 + del);         now -= del;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   FILE *in;   FILE *out;   const int MAX = 131072;   const int TREE = 262144;   int n;   int a[MAX];   int tree[TREE];   void update(int idx, int val) {     idx += (TREE >> 1);     while (idx) {       tree[idx] = max(tree[idx], val);       idx >>= 1;     }   }   int query(int idx) {     idx += (TREE >> 1);     int ret = tree[idx];     bool flag = !(idx & 1);     idx >>= 1;     while (idx) {       if (flag) ret = max(ret, tree[(idx << 1) + 1]);       flag = !(idx & 1);       idx >>= 1;     }     return ret;   }   int lis() {     int ans = 0;     for (int i = n - 1; i >= 0; i--) {       int cur = query(a[i] + 1) + 1;       ans = max(ans, cur);       update(a[i], cur);     }     return ans;   }   int main(void) {     in = stdin;     out = stdout;     fscanf(in,  %d , &n);     for (int i = 0; i < n; i++) fscanf(in,  %d , &a[i]);     fprintf(out,  %d n , lis());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};   int n, m, gx, gy, len, vis[15][15], ucs;   inline bool out(int x, int y) { return x < 0 || x >= n || y < 0 || y >= m; }   char s[15][15 + 1];   struct P {     int x[9], y[9], step, h;     P() { step = 0; }     void cal_h() { h = step + abs(gx - x[0]) + abs(gy - y[0]); }     int get_hsh() {       int hsh = 0;       for (int i = 0; i < len; i++) hsh = hsh * 131 + x[i] + 1;       for (int i = 0; i < len; i++) hsh = hsh * 131 + y[i] + 1;       return hsh;     }     bool operator<(const P &p) const { return h > p.h; }   };   int vc[15][15];   bool chk(int x, int y) {     vc[x][y] = 1;     if (s[x][y] ==  @ ) return 1;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i], ny = y + dy[i];       if (out(nx, ny) || vc[nx][ny] || s[nx][ny] ==  # ) continue;       if (chk(nx, ny)) return 1;     }     return 0;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (s[i][j] ==  @ ) gx = i, gy = j;     P p, np;     for (int i = 1; i <= 9; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < m; k++)           if (s[j][k] ==  0  + i) {             p.x[len] = j;             p.y[len] = k;             len++;           }     if (!chk(p.x[0], p.y[0])) return puts( -1 ), 0;     set<int> vs;     priority_queue<P> q;     p.cal_h();     q.push(p);     vs.insert(p.get_hsh());     while (!q.empty()) {       p = q.top();       q.pop();       ucs++;       for (int i = 0; i < len - 1; i++) vis[p.x[i]][p.y[i]] = ucs;       for (int i = 0; i < 4; i++) {         int hx = p.x[0] + dx[i], hy = p.y[0] + dy[i];         if (out(hx, hy)) continue;         if (vis[hx][hy] == ucs) continue;         if (s[hx][hy] ==  # ) continue;         if (s[hx][hy] ==  @ ) return printf( %d n , p.step + 1), 0;         np.x[0] = hx;         np.y[0] = hy;         np.step = p.step + 1;         memcpy(np.x + 1, p.x, (len - 1) * sizeof(int));         memcpy(np.y + 1, p.y, (len - 1) * sizeof(int));         if (vs.count(np.get_hsh())) continue;         vs.insert(np.get_hsh());         np.cal_h();         q.push(np);       }     }     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int customCeil(int k, int s) {     if (k % s == 0) return k / s;     return k / s + 1;   }   int main() {     long long int n;     cin >> n;     long long int arr[n];     for (int i = (0); i < (n); ++i) {       cin >> arr[i];     }     long long int m;     cin >> m;     long long int c[m];     for (int i = (0); i < (n); ++i) {       cin >> c[i];     }     long long int sum = 0;     sort(arr, arr + n);     for (int i = (0); i < (n); ++i) {       sum += arr[i];     }     for (int i = (0); i < (m); ++i) {       cout << sum - arr[n - c[i]] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       double a, b;       cin >> a >> b;       cout << fixed << setprecision(15);       if (b == 0) {         cout << 1 << endl;       } else if (a == 0) {         cout << 0.5 << endl;       } else if (a > b * 4) {         cout << 1 - b / a << endl;       } else {         double remain = b - a / 4;         cout << 1 - (b + remain) / (4 * b) << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int64_t MOD = 998244353;   const int64_t N = 2e5 + 5;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int64_t mpow(int64_t x, int64_t y) {     if (y == 0) return 1;     int64_t temp = mpow(x, y / 2);     temp *= temp;     temp %= MOD;     if (y & 1) return (x * temp) % MOD;     return temp;   }   int64_t inverse(int64_t x) { return mpow(x, MOD - 2); }   int64_t fact[N], ifact[N];   int64_t nCr(int64_t n, int64_t r) {     int64_t ans = fact[n];     ans *= ifact[r];     ans %= MOD;     ans *= ifact[n - r];     ans %= MOD;     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     fact[0] = 1;     ifact[0] = 1;     for (int64_t i = 1; i < N; i++) {       fact[i] = fact[i - 1] * i;       fact[i] %= MOD;       ifact[i] = inverse(fact[i]);     }     int64_t n, k;     cin >> n >> k;     int64_t arr[n];     for (int64_t i = 0; i < n; i++) {       cin >> arr[i];     }     int64_t equal = 0;     for (int64_t i = 0; i < n; i++) {       if (arr[i] == arr[(i + 1) % n]) equal++;     }     int64_t ans = mpow(k, equal);     int64_t ans2 = 0;     for (int64_t i = 0; i <= n - equal - 1; i++) {       int64_t lol = mpow(k - 2, i);       if ((n - equal - i) % 2 == 1) {         lol *= mpow(2, n - equal - i - 1);         lol %= MOD;       } else {         int64_t rem = mpow(2, n - equal - i);         rem -= nCr(n - equal - i, (n - equal - i + 1) / 2);         rem = rem + 10 * MOD;         rem %= MOD;         rem *= inverse(2);         rem %= MOD;         lol *= rem;         lol %= MOD;       }       lol *= nCr(n - equal, i);       lol %= MOD;       ans2 += lol;       ans2 %= MOD;     }     ans *= ans2;     ans %= MOD;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout <<  ?   << 1 <<     << 3 << endl;     int ac;     cin >> ac;     cout <<  ?   << 1 <<     << 2 << endl;     int ab;     cin >> ab;     cout <<  ?   << 2 <<     << 3 << endl;     int bc;     cin >> bc;     int amc = ab - bc;     int a2 = ac + amc;     int a = a2 / 2;     int b = ab - a;     int c = bc - b;     vector<int> res = {a, b, c};     for (int i = 0; i < n - 3; i++) {       cout <<  ?   << 1 <<     << i + 4 << endl;       int tmp;       cin >> tmp;       res.push_back(tmp - a);     }     cout <<  !  ;     for (int val : res) cout << val <<    ;     cout << endl;   }
#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define srt(s) sort(s.begin(),s.end())   int main()   {       ll t;       cin>>t;       while(t--)       {           ll n;           cin>>n;           string s;           cin>>s;           ll x=0;           ll p=0,p1=0;           ll mark=0;           stack<char>st,st1;           for(int i=0; i<n; i++)           {               if(s[i]== M )               {                   x++;               }           }           if(3*x!=n)           {               mark=1;           }           for(int i=0; i<n; i++)           {               if(s[i]== T )               {                   st.push(s[i]);               }               else               {                   if(st.size()>0)                   {                       st.pop();                   }                   else                   {                       mark=1;                       break;                   }               }           }           for(int i=n-1; i>=0; i--)           {               if(s[i]== T )               {                   st1.push(s[i]);               }               else               {                   if(st1.size()>0)                   {                       st1.pop();                   }                   else                   {                       mark=1;                       break;                   }               }           }           if(mark==0)           {               cout<< YES <<endl;           }           else           {               cout<< NO <<endl;           }       }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int f, x;     cin >> f;     x = f + 1;     if (f == 0) {       f = 0;     } else if (x % 2 == 0) {       f = x / 2;     } else {       f++;     }     cout << f << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       long long a, b, ans;       cin >> a >> b;       long long x;       x = min(a, b);       ans = max(max(a, b), 2 * x);       cout << ans * ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int modpow(long long int a, long long int n, long long int temp) {     long long int res = 1;     while (n > 0) {       res = (res * res) % temp;       if (n & 1) res = (res * a) % temp;       n /= 2;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (a == 0)       return (b);     else       return (gcd(b % a, a));   }   void f(int a[][1001], int x, int y) {     if (a[x][y] >= 4) {       int t = a[x][y] / 4;       a[x][y + 1] += t;       a[x + 1][y] += t;       a[x - 1][y] += t;       a[x][y - 1] += t;       a[x][y] = a[x][y] % 4;       f(a, x + 1, y);       f(a, x - 1, y);       f(a, x, y + 1);       f(a, x, y - 1);     }   }   int main() {     int a[1001][1001] = {0};     int n, q, x, y;     cin >> n >> q;     a[500][500] = n;     f(a, 500, 500);     while (q--) {       cin >> x >> y;       x += 500;       y += 500;       if (x > 1000 || y > 1000 || x < 0 || y < 0)         cout << 0 << endl;       else         cout << a[x][y] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int pi = 10000000;   vector<long long int> prime(pi), pri;   void seive() {     long long int i, j, k, l;     for (i = 4; i <= pi; i += 2) prime[i] = 1;     pri.push_back(2);     for (i = 3; i <= pi; i += 2) {       if (prime[i] == 0) pri.push_back(i);       for (j = i * i; j <= pi; j += i) {         if (prime[j] == 0) prime[j] = 1;       }     }     cout << pri.size() << endl;   }   int main() {     long long int n, i = 0, l = -2, k = INT_MAX, j, a = 0, f = 1, c = 0, b = 0,                      x = 100000000007, d = 0, y, m, zero = 0, one = 10,                      z = 1000000007;     string s =  qwertyuiopasdfghjkl;zxcvbnm,./ , mar =   , s2;     char ch[26] = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i ,                     j ,  k ,  l ,  m ,  n ,  o ,  p ,  q ,  r ,                     s ,  t ,  u ,  v ,  w ,  x ,  y ,  z },          bo, an;     vector<long long int> vc, vct, vctt;     vector<pair<long long int, long long int>> pa;     map<char, char> mp;     double num, nr, radi;     stack<char> bra, bra2;     cin >> n >> m >> s;     for (i = 0; i < m; i++) {       cin >> bo >> an;       for (j = 0; j < 26; j++) {         if (ch[j] == bo)           ch[j] = an;         else if (ch[j] == an)           ch[j] = bo;       }     }     for (i = 0; i < n; i++) {       mar += ch[s[i] -  a ];     }     cout << mar << endl;   }
#include <bits/stdc++.h>   using namespace std;   string s[70010];   map<pair<int, int>, int> m;   pair<int, int> ans[70010];   int main() {     int k = 64, p = 5;     int n, i, j, l;     cin >> n;     for (i = 1; i <= n; i++) cin >> s[i];     for (i = 1; i <= n; i++)       for (j = 0; j < 9; j++) {         int x = 0;         for (l = j; l < 9; l++) {           x = x * 10 + s[i][l] -  0 ;           if (m.find(pair<int, int>(x, l - j + 1)) != m.end() &&               m[pair<int, int>(x, l - j + 1)] != i)             m[pair<int, int>(x, l - j + 1)] = -1;           else             m[pair<int, int>(x, l - j + 1)] = i;         }       }     for (auto it = m.begin(); it != m.end(); it++) {       if (it->second == -1) continue;       if (ans[it->second].second == 0 ||           ans[it->second].second > it->first.second)         ans[it->second] = pair<int, int>(it->first.first, it->first.second);     }     for (i = 1; i <= n; i++) {       char s[10];       sprintf(s,  %%0%dd n , ans[i].second);       printf(s, ans[i].first);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 10;   int f[MAX_N], g[MAX_N], h[MAX_N], pos[MAX_N];   vector<int> adj[MAX_N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int m = 0;     for (int i = 1; i <= n; i++) {       cin >> f[i];       if (adj[f[i]].empty()) {         m++;         h[m] = f[i];         pos[f[i]] = m;       }       adj[f[i]].push_back(i);     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < adj[i].size(); j++) {         if (g[adj[i][j]] != 0) {           cout <<  -1 n ;           return 0;         }         g[adj[i][j]] = pos[i];       }     }     for (int i = 1; i <= n; i++) {       if (!g[i]) {         cout <<  -1 n ;         return 0;       }     }     for (int i = 1; i <= m; i++) {       if (g[h[i]] != i) {         cout <<  -1 n ;         return 0;       }     }     cout << m <<   n ;     for (int i = 1; i <= n; i++) {       cout << g[i];       if (i < n) cout <<    ;     }     cout <<   n ;     for (int i = 1; i <= m; i++) {       cout << h[i];       if (i < m) cout <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, xa, ya, xb, yb;   int main() {     scanf( %d%d%d%d%d%d , &a, &b, &xa, &ya, &xb, &yb);     a <<= 1, b <<= 1;     int x1 = (xa + ya), y1 = (xa - ya), x2 = (xb + yb), y2 = (xb - yb);     int sector_1_x = (x1 / a) - (x1 < 0), sector_1_y = (y1 / b) - (y1 < 0);     int sector_2_x = (x2 / a) - (x2 < 0), sector_2_y = (y2 / b) - (y2 < 0);     printf( %d n ,            max(abs(sector_1_x - sector_2_x), abs(sector_1_y - sector_2_y)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long M, n;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long ttttt = 1;     while (ttttt--) {       cin >> M >> n;       long long a[n], ans[n];       cin >> a[0];       long long ok = -1;       if (a[0] <= M * -1) ok = 1;       for (long long i = 1; i < n; i++) {         cin >> a[i], a[i] += a[i - 1];         if (a[i] <= M * -1 && ok == -1) ok = i + 1;       }       if (ok != -1) {         cout << ok;         cout <<   n ;         return 0;       }       if (a[n - 1] >= 0) {         cout << -1;         cout <<   n ;         return 0;       }       for (long long i = 0; i < n; i++) {         long long x = M + a[i];         x = ceil(x / (a[n - 1] * -1.0));         ans[i] = x * n + i + 1;       }       for (long long i = 0; i < n; i++) ans[0] = min(ans[0], ans[i]);       cout << ans[0];       cout <<   n ;       return 0;     }     return 0;   }