malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, +1, -1};   int dy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   int biton(int N, int pos) { return N = N | (1 << pos); }   int bitoff(int N, int pos) { return N = N & ~(1 << pos); }   bool check(int N, int pos) { return (bool)(N & (1 << pos)); }   int n, ar[1234567], k;   pair<int, int> p[323456];   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &p[i].first);       p[i].second = i + 1;       ar[i + 1] = p[i].first;     }     sort(p, p + n, greater<pair<int, int>>());     int start = k + 1;     long long int ans = 0;     map<int, int> block, ok;     for (int i = 0; i < n; i++) {       while (block[start] != 0) start++;       if (start < p[i].second) {         ok[p[i].second] = p[i].second;         block[p[i].second] = p[i].second;       } else {         ok[p[i].second] = start;         block[start] = start;         start++;       }     }     long long int sum = 0;     for (int i = 1; i <= n; i++) {       sum += 1LL * (ok[i] - i) * ar[i];     }     printf( %lli n , sum);     for (int i = 1; i <= n; i++) printf( %i  , ok[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     int d, n;     cin >> d >> n;     vector<int> days(n);     for (int i = 0; i < n; i++) cin >> days[i];     int count = 0;     for (int i = 1; i < n; i++) count += d - days[i - 1];     cout << count <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int f(long long int a) {     long long int i, r = 0;     for (i = 1; i <= a; i++) {       r += i * (9 * (pow(10, i - 1)));     }     return r;   }   int main() {     long long int i, n, a;     cin >> n;     for (i = 1; n % (long long int)(pow(10, i)) != n; i++)       ;     a = f(i - 1);     n = n - (pow(10, i - 1));     a = a + ((n + 1) * (i));     cout << a;   }
#include <bits/stdc++.h>   using namespace std;   int a[200010];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     int mn = a[n];     for (int i = 1; i <= n / 2; i++) mn = min(mn, a[i + n / 2] - a[i]);     printf( %d n , mn);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     scanf( %d%d n , &n, &x);     if (n == 5) printf( >...v nv.<.. n..^.. n>.... n..^.< n1 1 n );     if (n == 3) printf( >vv n^<. n^.< n1 3 n );     if (n == 100) {       for (int i = 0; i < 50; i++) {         puts(              v<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<<<<<<<<<<<<<<<               <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< );         puts(              >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.               >.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>^ );       }       printf( 1 1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e2 + 1;   int n, m, q, ans[MAX][MAX], t[MAX][MAX][2];   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> q;     for (int i = 1; i < n + 1; i++)       for (int j = 1; j < m + 1; j++) {         t[i][j][0] = i;         t[i][j][1] = j;       }     while (q--) {       int ty;       cin >> ty;       if (ty == 1) {         int x;         cin >> x;         int x1 = t[x][1][0], y1 = t[x][1][1];         for (int i = 1; i < m; i++) {           t[x][i][0] = t[x][i + 1][0];           t[x][i][1] = t[x][i + 1][1];         }         t[x][m][0] = x1;         t[x][m][1] = y1;       } else if (ty == 2) {         int x;         cin >> x;         int x1 = t[1][x][0], y1 = t[1][x][1];         for (int i = 1; i < n; i++) {           t[i][x][0] = t[i + 1][x][0];           t[i][x][1] = t[i + 1][x][1];         }         t[n][x][0] = x1;         t[n][x][1] = y1;       } else {         int x, y, z;         cin >> x >> y >> z;         ans[t[x][y][0]][t[x][y][1]] = z;       }     }     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j < m + 1; j++) cout << ans[i][j] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int l[300005], r[300005];   int main() {     int n;     scanf( %d , &n);     int lm = -1, rm = 0x3f3f3f3f;     int ansl = 0, ansr = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &l[i], &r[i]);       if (l[i] > lm) {         ansl = i;         lm = l[i];       }       if (r[i] < rm) {         ansr = i;         rm = r[i];       }     }     int lmm = 0x3f3f3f3f, rmm = -1;     for (int i = 1; i <= n; i++) {       if (l[i] == lm && lmm > r[i]) {         lmm = r[i];         ansl = i;       }       if (r[i] == rm && rmm < l[i]) {         rmm = l[i];         ansr = i;       }     }     if (ansl == ansr) {       int lll = -1, rrr = 0x3f3f3f3f;       for (int i = 1; i <= n; i++) {         if (i == ansl) continue;         lll = max(lll, l[i]);         rrr = min(rrr, r[i]);       }       if (rrr <= lll) {         printf( 0 n );       } else         printf( %d n , rrr - lll);     } else {       int ll1 = -1, rr1 = 0x3f3f3f3f;       for (int i = 1; i <= n; i++) {         if (i == ansl) continue;         ll1 = max(ll1, l[i]);         rr1 = min(rr1, r[i]);       }       int ll2 = -1, rr2 = 0x3f3f3f3f;       for (int i = 1; i <= n; i++) {         if (i == ansr) continue;         ll2 = max(ll2, l[i]);         rr2 = min(rr2, r[i]);       }       if (ll2 >= rr2 && ll1 >= rr1)         printf( 0 n );       else {         int ans = max(rr2 - ll2, rr1 - ll1);         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct camel {     int x, y;   };   int main() {     int n;     bool r = false;     cin >> n;     camel arr[n];     for (int i = 0; i < n; i++) cin >> arr[i].x >> arr[i].y;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++)         if (arr[i].x + arr[i].y == arr[j].x)           if (arr[j].x + arr[j].y == arr[i].x) r = true;     }     if (r)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using lld = long double;   using vi = vector<int>;   using vll = vector<long long>;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int x[n];     for (int &u : x) {       cin >> u;     }     sort(x, x + n);     if ((x[n - 1] - x[0] == 0) || (x[n - 1] - x[0] == 1)) {       cout << n << endl;       for (int &u : x) {         cout << u <<    ;       }     } else {       int a = count(x, x + n, x[0]);       int b = count(x, x + n, x[0] + 1);       int c = count(x, x + n, x[0] + 2);       if (2 * min(a, c) > 2 * (b / 2)) {         cout << n - (2 * min(a, c)) << endl;         if (a <= c) {           b += 2 * a;           c -= a;           a = 0;         } else {           b += 2 * c;           a -= c;           c = 0;         }       } else {         cout << n - (2 * (b / 2)) << endl;         if (b % 2 == 0) {           a += b / 2;           c += b / 2;           b = 0;         } else {           a += b / 2;           c += b / 2;           b = 1;         }       }       while (a--) {         cout << x[0] <<    ;       }       while (b--) {         cout << x[0] + 1 <<    ;       }       while (c--) {         cout << x[0] + 2 <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 200005;   int prime[1100000], primesize;   bool isprime[11000000];   long long f[N], invf[N];   long long inv[N];   void getlist(int listsize) {     memset(isprime, 1, sizeof(isprime));     isprime[1] = false;     for (int i = 2; i <= listsize; i++) {       if (isprime[i]) prime[++primesize] = i;       for (int j = 1; j <= primesize && i * prime[j] <= listsize; j++) {         isprime[i * prime[j]] = false;         if (i % prime[j] == 0) break;       }     }   }   void extend_gcd(long long a, long long b, long long& d, long long& x,                   long long& y) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       extend_gcd(b, a % b, d, y, x);       y -= x * (a / b);     }   }   void ni(int n) {     inv[0] = inv[1] = 1;     for (int i = 2; i <= n; i++) {       inv[i] = (mod - (mod / i)) * inv[mod % i] % mod;     }   }   long long fpow(long long a, long long k) {     long long res = 1;     while (k) {       if (k & 1) res = (res * a) % mod;       k >>= 1;       a = a * a % mod;     }     return res;   }   void init(int n) {     f[0] = 1;     for (int i = 1; i <= n; ++i) {       f[i] = f[i - 1] * i % mod;     }     invf[n] = fpow(f[n], mod - 2);     for (int i = n - 1; i >= 0; --i) {       invf[i] = invf[i + 1] * (i + 1) % mod;     }   }   long long C(int n, int k) {     if (k < 0 || k > n) return 0;     return f[n] * invf[k] % mod * invf[n - k] % mod;   }   long long pos[27][200005];   long long num[27];   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       pos[s[i] -  a ][0]++;       pos[s[i] -  a ][pos[s[i] -  a ][0]] = i + 1;     }     long long m;     cin >> m;     for (int i = 1; i <= m; i++) {       memset(num, 0, sizeof(num));       string x;       cin >> x;       long long res = 0;       for (auto j : x) {         num[j -  a ]++;         res = max(res, pos[j -  a ][num[j -  a ]]);       }       cout << res << endl;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, n, ch = 0;     string s, g;     cin >> n >> k >> s;     for (int i = 1; i <= n && ch == 0; i++) {       string t = s.substr(0, i);       string temp =   0 ;       int count;       (n % i == 0) ? count = n / i : count = (n / i) + 1;       for (int j = 0; j < count; j++) temp += t;       if (temp.find(s) == 0) {         g = t;         ch++;       }     }     string l =   0 ;     for (int i = 0; i < k - 1; i++) l += g;     l += s;     cout << l << endl;   }
#include <bits/stdc++.h>   using namespace std;   int a, b[1000002], c = 0, d, e, f, g, h, i, j;   int main() {     cin >> a;     for (i = 1; i <= a; i++) {       cin >> d;       b[d]++;       if (b[d] > c) {         c = b[d];         e = d;       }     }     cout << e;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     char a[n][m];     bool vis[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         vis[i][j] = false;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (i > 0 && i < n - 1 && j > 0 && j < m - 1) {           bool flag = true;           for (int k = -1; k <= 1; k++) {             for (int l = -1; l <= 1; l++) {               if (k == 0 && l == 0) continue;               if (a[i + k][j + l] ==  . ) {                 flag = false;               }             }           }           if (flag == true) {             for (int k = -1; k <= 1; k++) {               for (int l = -1; l <= 1; l++) {                 if (k == 0 && l == 0) continue;                 vis[i + k][j + l] = true;               }             }           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  #  && vis[i][j] == false) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;   }
#include <bits/stdc++.h>   typedef long long int ll;   typedef unsigned long long int ull;   #define N 1010100   #define inf 1e9      #define loop(x, n, r) for(int i = x; i < n; i += r)      #define pb push_back   #define pp pair<int, int>      using namespace std;      int main(){       ios::sync_with_stdio(0); cin.tie(0);       int T = 1;       cin >> T;       while(T--){           int n;           cin >> n;           string b;           cin >> b;           cout <<  1 ;           char prev = b[0] ==  0  ?  1  :  2 ;           loop(1, n, 1){               if(prev ==  2 ){                   if(b[i] ==  1 )                       cout <<  0 ;                   else                       cout <<  1 ;                   prev =  1 ;               }               else if(prev ==  1 ){                   if(b[i] ==  1 ){                       cout <<  1 ;                       prev =  2 ;                   }                   else{                       cout <<  0 ;                       prev =  0 ;                   }               }               else{                   if(b[i] ==  1 ){                       cout <<  1 ;                       prev =  2 ;                   }                   else{                       cout <<  1 ;                       prev =  1 ;                   }               }           }           cout <<   n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 111111;   const int INF = 1000000000, mod = 1000000007;   const long long LLINF = 1000000000000000000ll;   long long n, k, d1, d2;   bool try_solve(long long d1, long long d2) {     if (n % 3) return 0;     if ((k - d1 + d2) % 3) return 0;     long long x2 = (k - d1 + d2) / 3;     if (x2 >= 0 && x2 <= k) {       long long x1 = d1 + x2;       long long x3 = x2 - d2;       if (x1 >= 0 && x1 <= k && x3 >= 0 && x3 <= k && x1 <= n / 3 &&           x2 <= n / 3 && x3 <= n / 3) {         return 1;       }     }     return 0;   }   int main() {     int t;     scanf( %d , &t);     while (t-- > 0) {       scanf( %I64d %I64d %I64d %I64d , &n, &k, &d1, &d2);       bool can = 0;       for (int i = -1; i <= 1; ++i) {         for (int j = -1; j <= 1; ++j) {           if (i == 0 || j == 0) continue;           can |= try_solve(d1 * i, d2 * j);         }       }       puts(can ?  yes  :  no );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 1e9;   const int N = 1e6 + 6;   long long powmod(long long a, long long b, long long mod) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;     }     return res;   }   long long gcd(long long a, long long b) {     while (b > 0) {       long long t = a % b;       a = b, b = t;     }     return a;   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   long long is_prime(long long n) {     if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0)) return 0;     for (long long i = 5, t = 2; i * i <= n; i += t, t = 6 - t)       if (n % i == 0) return 0;     return 1;   }   int main() {     string g;     vector<string> s;     long long ans = 0;     for (long long i = 0; i < 2; i++) cin >> g, s.push_back(g);     for (long long i = 0; i < s[0].length(); i++) {       if (i == 0) {         if (s[0][i] ==  0  && s[1][i] ==  0  && s[1][i + 1] ==  0 ) {           ans++;           s[0][i] =  x ;           s[1][i] =  x ;           s[1][i + 1] =  x ;         } else if (s[0][i] ==  0  && s[1][i] ==  0  && s[0][i + 1] ==  0 ) {           ans++;           s[0][i] =  x ;           s[1][i] =  x ;           s[0][i + 1] =  x ;         }       } else {         if (s[0][i] ==  0  && s[1][i] ==  0  && s[1][i - 1] ==  0 ) {           ans++;           s[0][i] =  x ;           s[1][i] =  x ;           s[1][i - 1] =  x ;         } else if (s[0][i] ==  0  && s[1][i] ==  0  && s[0][i - 1] ==  0 ) {           ans++;           s[0][i] =  x ;           s[1][i] =  x ;           s[0][i - 1] =  x ;         } else if (s[0][i] ==  0  && s[1][i] ==  0  && s[1][i + 1] ==  0 ) {           ans++;           s[0][i] =  x ;           s[1][i] =  x ;           s[1][i + 1] =  x ;         } else if (s[0][i] ==  0  && s[1][i] ==  0  && s[0][i + 1] ==  0 ) {           ans++;           s[0][i] =  x ;           s[1][i] =  x ;           s[0][i + 1] =  x ;         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int countBits(long long mask) {     int res = 0;     while (mask) mask &= (mask - 1), ++res;     return res;   }   string toString(long long n) {     stringstream ss;     ss << n;     return ss.str();   }   long long toNumber(string s) {     stringstream ss;     long long n;     ss << s;     ss >> n;     return n;   }   bool palindrome[2001][2001];   int Start[2001], End[2001], cumEnd[2001];   int main() {     string str;     while (cin >> str) {       memset(Start, 0, sizeof Start);       memset(End, 0, sizeof End);       memset(palindrome, 0, sizeof palindrome);       for (int i = (int)(0), _m = (int)(str.size()); i < _m; ++i) {         palindrome[i][i] = true;         if (i && str[i] == str[i - 1]) palindrome[i - 1][i] = true;       }       for (int len = (int)(3), _m = (int)(str.size()); len < _m; ++len)         for (int i = (int)(0), _m = (int)(str.size()); i < _m; ++i)           if (len + i - 1 >= str.size())             break;           else             palindrome[i][i + len - 1] =                 (str[i] == str[i + len - 1]) && palindrome[i + 1][i + len - 2];       for (int i = (int)(0), _m = (int)(str.size()); i < _m; ++i) {         for (int j = (int)(i), _m = (int)(str.size()); j < _m; ++j)           Start[i] += palindrome[i][j];         for (int j = (int)(0), _m = (int)(i + 1); j < _m; ++j)           End[i] += palindrome[j][i];         cumEnd[i] = End[i] + (!i ? 0 : cumEnd[i - 1]);       }       long long res = 0;       for (int i = (int)(1), _m = (int)(str.size()); i < _m; ++i)         res += (long long)Start[i] * cumEnd[i - 1];       cout << res << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, cnt_t = 0;   vector<pair<int, int>> ls_[2];   vector<int> upb, downb;   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first) {       return a.first < b.first;     }     return a.second < b.second;   }   long long proc(vector<pair<int, int>> &ls) {     long long sum = 0;     int sz = ls.size();     if (sz == 0) return 0;     sort(ls.begin(), ls.end(), cmp);     int ex_up = 0, ex_down = 0;     int bup = -200001;     int bdown = -bup;     int i, rup, rdown;     for (i = 0; i < sz; i++) {       if (ls[i].second > bup || ls[i].second == bup && ls[i].first > rup) {         bup = ls[i].second, rup = ls[i].first;       }       if (ls[i].second < bdown || ls[i].second == bdown && ls[i].first > rdown) {         bdown = ls[i].second, rdown = ls[i].first;       }     }     int j, k;     int bd;     bd = ls[0].second;     int bsz = (ls.back().first - ls[0].first) / 2;     upb.clear();     upb.resize(bsz);     downb.clear();     downb.resize(bsz);     for (i = 0, k = ls[0].first; k < rup; k += 2) {       for (j = i; ls[j].first == k; j++)         ;       if (j > i) {         if (ls[j - 1].second > bd) bd = ls[j - 1].second;         i = j;       }       upb[(k - ls[0].first) / 2] = bd;     }     bd = ls[0].second;     for (i = 0, k = ls[0].first; k < rdown; k += 2) {       for (j = i; ls[j].first == k; j++)         ;       if (j > i) {         if (ls[i].second < bd) bd = ls[i].second;         i = j;       }       downb[(k - ls[0].first) / 2] = bd;     }     bd = ls.back().second;     for (i = sz - 1, k = ls.back().first; k > rup; k -= 2) {       for (j = i; ls[j].first == k; j--)         ;       if (j < i) {         if (ls[i].second > bd) bd = ls[i].second;         i = j;       }       upb[bsz - 1 - (ls.back().first - k) / 2] = bd;     }     bd = ls.back().second;     for (i = sz - 1, k = ls.back().first; k > rdown; k -= 2) {       for (j = i; ls[j].first == k; j--)         ;       if (j < i) {         if (ls[j + 1].second < bd) bd = ls[j + 1].second;         i = j;       }       downb[bsz - 1 - (ls.back().first - k) / 2] = bd;     }     for (i = 0; i < bsz; i++) {       if (upb[i] >= downb[i]) {         sum += (upb[i] - downb[i]) / 2;       }     }     return sum;   }   int main() {     int n, i, u, v;     scanf( %d , &n);     ls_[0].clear();     ls_[1].clear();     for (i = 0; i < n; i++) {       scanf( %d%d , &u, &v);       ls_[((u + v) % 2 + 2) % 2].push_back(make_pair(u - v, u + v));     }     long long ans = proc(ls_[0]) + proc(ls_[1]);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, n, m, k;     int i, j, a[55];     bool f = 0;     cin >> n >> m >> k;     for (i = 0; i < n; i++) cin >> a[i];     sort(a + 0, a + n);     if (k >= m) {       cout << 0 << endl;       f = 1;     } else       for (i = n - 1, x = 0; i >= 0 && k > 0; i--) {         if (i < (n - 1))           x += (a[i] - 1);         else           x += a[i];         if ((x + k - 1) >= m) {           cout << (n - i) << endl;           f = 1;           break;         }       }     if (f == 0) cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int ch = getchar(), f = 0;     int x = 0;     while (ch <  0  || ch >  9 ) {       f |= ch ==  - ;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f ? -x : x;   }   struct eric {     int to, next, v;   } edge[10005 << 4];   int head[10005], size = 1;   int n, m;   int dis[10005], out[10005 << 4], vis[10005], used[10005], num[10005];   inline void add(int x, int y, int z) {     edge[++size].to = y;     edge[size].v = z;     edge[size].next = head[x];     head[x] = size;   }   queue<int> que;   int ined[10005];   void dfs1(int pos) {     vis[pos] = 1;     for (int i = head[pos]; i; i = edge[i].next) {       int v = edge[i].to;       if (edge[i].v < 0 || vis[v]) continue;       dfs1(v);     }   }   void dfs2(int pos) {     used[pos] = 1;     for (int i = head[pos]; i; i = edge[i].next) {       int v = edge[i].to;       if (edge[i].v > 0 || used[v]) continue;       dfs2(v);     }   }   inline bool ok(int x, int y) { return used[x] && used[y] && vis[x] && vis[y]; }   inline void SPFA(int s) {     for (int i = 1; i <= n; i++) dis[i] = -1000000007 / 10;     dis[s] = 0;     que.push(s);     ined[s] = 1;     while (!que.empty()) {       int u = que.front();       que.pop();       ined[u] = 0;       for (int i = head[u]; i; i = edge[i].next) {         int v = edge[i].to;         if (dis[v] < dis[u] + edge[i].v && ok(u, v)) {           dis[v] = dis[u] + edge[i].v;           if (!ined[v]) ined[v] = 1, que.push(v), num[v]++;         }       }       if (num[u] >= n) {         puts( No );         exit(0);       }     }   }   int main() {     n = read(), m = read();     for (int i = 1, x, y; i <= m; i++)       x = read(), y = read(), add(x, y, 1), add(y, x, -2);     dfs1(1);     dfs2(n);     SPFA(1);     for (int u = 1; u <= n; u++) {       for (int i = head[u]; i; i = edge[i].next) {         int v = edge[i].to;         if (!ok(u, v)) {           out[i >> 1] = 1;           continue;         }         out[i >> 1] = abs(dis[v] - dis[u]);         if (out[i >> 1] > 2) {           puts( No );           return 0;         }       }     }     puts( Yes );     for (int i = 1; i <= m; i++) printf( %d n , out[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long a, b, c, d;     cin >> a >> b >> c >> d;     if (a + b == c + d || a + c == b + d || a + d == b + c || a + b + c == d ||         a + c + d == b || b + c + d == a || a + b + d == c) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }   }