malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   inline char getThirdColor(char a, char b) {     char ret;     if (a ==  B  && b ==  G  || a ==  G  && b ==  B )       ret =  R ;     else if (a ==  B  && b ==  R  || a ==  R  && b ==  B )       ret =  G ;     else if (a ==  R  && b ==  G  || a ==  G  && b ==  R )       ret =  B ;     return ret;   }   std::unordered_map<std::string, bool> ump;   inline bool solve(std::string s, char c) {     if (s.size() == 1) {       return s[0] == c;     }     if (ump.find(s) != ump.end()) return ump[s];     bool ret = false;     for (int i = 0; i < s.size(); ++i) {       for (int j = i + 1; j < s.size(); ++j) {         if (s[i] == s[j]) {           std::string next_pass{s[i]};           for (int k = 0; k < s.size(); ++k) {             if (k != i && k != j) next_pass += s[k];           }           ret = solve(next_pass, c);         } else {           char thirdColor = getThirdColor(s[i], s[j]);           std::string next_pass{thirdColor};           for (int k = 0; k < s.size(); ++k) {             if (k != i && k != j) next_pass += s[k];           }           ret = solve(next_pass, c);         }         if (ret) break;       }       if (ret) break;     }     return ump[s] = ret;   }   int main() {     int n;     std::cin >> n;     std::string s;     std::cin >> s;     std::string modified;     modified.reserve(n);     std::unordered_map<char, int> cnt;     for (int i = 0; i < s.size(); ++i) {       if (modified.empty()) {         modified += s[i];         ++cnt[s[i]];       } else if (modified.back() == s[i] && cnt[s[i]] == 1) {         modified += s[i];         ++cnt[s[i]];       } else if (modified.back() != s[i]) {         modified += s[i];         ++cnt[s[i]];       }     }     std::vector<char> possible{ B ,  G ,  R };     for (int i = 0; i < possible.size(); ++i) {       ump.clear();       if (solve(modified, possible[i])) {         std::cout << possible[i];       }     }     std::cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, n, k;     cin >> t;     while (t--) {       long long ats = 0;       cin >> n >> k;       while (n) {         ats += n % k;         n -= n % k;         while (n % k == 0 && n) n /= k, ats++;       }       cout << ats <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000001;   int n, m, x;   pair<int, int> a[maxn];   int st[maxn], q[maxn], cnt, ans[maxn], tail, top;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].first);     }     int x;     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       a[n + i].first = m - 1 - x;       a[n + i].second = 1;     }     sort(a + 1, a + 1 + 2 * n);     top = 0;     tail = 0;     for (int i = 1; i <= 2 * n; i++) {       if (a[i].second == 0)         st[++top] = a[i].first;       else {         if (top == 0)           q[++tail] = a[i].first;         else           ans[++cnt] = (m - 1 - a[i].first + st[top--]) % m;       }     }     for (int i = 1; i <= tail; i++)       ans[++cnt] = (st[i] + m - 1 - q[tail - i + 1]) % m;     sort(ans + 1, ans + 1 + n);     reverse(ans + 1, ans + 1 + n);     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     cout << endl;     fclose(stdin);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 15;   int n, a[MAXN], b[MAXN], inf = 1e9 + 19, pos, st[MAXN], en[MAXN], LIS,                            cnt[MAXN];   void fil() {     b[0] = -inf;     for (int i = 1; i < MAXN; i++) b[i] = inf;   }   int bs(int x) {     int s = 0, e = 1e5 + 10;     while (s + 1 < e) {       int mid = (s + e) / 2;       if (b[mid] < x)         s = mid;       else         e = mid;     }     if (b[s] >= x) {       b[s] = x;       return s;     } else {       b[e] = x;       return e;     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     fil();     for (int i = 0; i < n; i++) {       pos = bs(a[i]);       st[i] = pos;     }     for (int i = 0; i <= n; i++)       if (b[i] != inf) LIS = i;     fil();     for (int i = n - 1; i >= 0; i--) {       pos = bs(-a[i]);       en[i] = pos;     }     for (int i = 0; i < n; i++)       if (st[i] + en[i] - 1 == LIS) cnt[st[i]]++;     for (int i = 0; i < n; i++) {       if (st[i] + en[i] - 1 != LIS)         cout << 1;       else if (cnt[st[i]] == 1)         cout << 3;       else         cout << 2;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<char> s(n);     long long ans = 0;     for (int i = 0; i < n; ++i) {       cin >> s[i];       if (i > 0 and s[i] ==  .  and s[i - 1] ==  . ) ++ans;     }     for (int i = 0; i < m; ++i) {       int pos;       cin >> pos;       --pos;       char c;       cin >> c;       if (c ==  .  and s[pos] !=  . ) {         if (pos > 0 and s[pos - 1] ==  . ) ++ans;         if (pos < n and s[pos + 1] ==  . ) ++ans;       } else if (c !=  .  and s[pos] ==  . ) {         if (pos > 0 and s[pos - 1] ==  . ) --ans;         if (pos < n and s[pos + 1] ==  . ) --ans;       }       s[pos] = c;       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   char ans[1005][1005];   int x[1005][1005], y[1005][1005];   int n;   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   bool isvalid(int i, int j) {     if (i < 0 || j < 0 || i >= n || j >= n) return 0;     return 1;   }   void color(int i, int j) {     if (i < 0 || j < 0 || i >= n || j >= n || ans[i][j] ==  Z  || x[i][j] != -1 ||         y[i][j] != -1)       return;     ans[i][j] =  Z ;     for (int k = 0; k < 4; k++) color(i + dx[k], j + dy[k]);   }   void DFS(int i, int j, char ch, int ka, int kh) {     if (i < 0 || j < 0 || i >= n || j >= n || x[i][j] == -1 || ans[i][j] !=  K )       return;     ans[i][j] = ch;     if (isvalid(i + 1, j) && x[i + 1][j] == ka && y[i + 1][j] == kh) {       DFS(i + 1, j,  U , ka, kh);     }     if (isvalid(i - 1, j) && x[i - 1][j] == ka && y[i - 1][j] == kh) {       DFS(i - 1, j,  D , ka, kh);     }     if (isvalid(i, j + 1) && x[i][j + 1] == ka && y[i][j + 1] == kh) {       DFS(i, j + 1,  L , ka, kh);     }     if (isvalid(i, j - 1) && x[i][j - 1] == ka && y[i][j - 1] == kh) {       DFS(i, j - 1,  R , ka, kh);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> x[i][j] >> y[i][j];         ans[i][j] =  K ;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (x[i][j] == -1 && y[i][j] == -1)           color(i, j);         else if (x[i][j] == i + 1 && y[i][j] == j + 1)           DFS(i, j,  X , i + 1, j + 1);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (ans[i][j] ==  Z ) {           if (isvalid(i + 1, j) && x[i + 1][j] == -1) {             ans[i][j] =  D ;             ans[i + 1][j] =  U ;           } else if (isvalid(i - 1, j) && x[i - 1][j] == -1) {             ans[i][j] =  U ;             ans[i - 1][j] =  D ;           } else if (isvalid(i, j + 1) && x[i][j + 1] == -1) {             ans[i][j] =  R ;             ans[i][j + 1] =  L ;           } else if (isvalid(i, j - 1) && x[i][j - 1] == -1) {             ans[i][j] =  L ;             ans[i][j - 1] =  R ;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (ans[i][j] ==  K  || ans[i][j] ==  Z ) {           cout <<  INVALID ;           return 0;         }       }     }     cout <<  VALID n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cout << ans[i][j];       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   using pq = priority_queue<T>;   template <class T>   using pqg = priority_queue<T, vector<T>, greater<T>>;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char* x) { cerr <<     << x <<    ; }   void __print(const string& x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V>& x) {     cerr <<  { ;     __print(x.first);     cerr <<  ,  ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T& x) {     int first = 0;     cerr <<  { ;     for (auto& i : x) cerr << (first++ ?  ,   :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   const int MOD = 1000000007;   const char nl =   n ;   const int MX = 100001;   void solve() {     int N;     cin >> N;     int A[N];     for (int i = 0; i < (N); i++) cin >> A[i];     int sum = 0;     for (int i = 0; i < (N); i++) sum += A[i];     if (sum % 2) {       cout <<  NO  << nl;       return;     }     int cnt = 0;     vector<int> ops;     for (int i = 0; i < (N); i++) {       cnt += A[i];       if (A[i] == 0) {         if (cnt % 2) {           ops.push_back(i - 1);           int X = 0;           for (int j = 0; j < (3); j++) X ^= A[i - 1 + j];           for (int j = 0; j < (3); j++) A[i - 1 + j] = X;         }         if (A[i] == 0) {           cnt = 0;         } else           cnt++;       }     }     sum = 0;     for (int i = 0; i < (N); i++) sum += A[i];     if (sum == N) {       cout <<  NO  << nl;       return;     }     int fz = 0;     for (int i = (N)-1; i >= 0; i--)       if (A[i] == 0) fz = i;     while (fz > 0) {       ops.push_back(fz - 2);       A[fz - 2] = 0;       A[fz - 1] = 0;       A[fz] = 0;       fz -= 2;     }     for (int i = 0; i < (N - 1); i++) {       if (A[i] == 0 && A[i + 1] == 1) {         ops.push_back(i);         A[i] = 0;         A[i + 1] = 0;         A[i + 2] = 0;       }     }     cout <<  YES  << nl;     cout << (int)(ops).size() << nl;     for (auto& a : ops) {       cout << a + 1 <<    ;     }     cout << nl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T = 1;     cin >> T;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n - 1; i += 2) {         cout << a[i + 1] <<     << -1 * a[i] <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_L = 20;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 7;   int p = 100000007;   template <typename T>   void scan(T &x) {     x = 0;     bool neg = 0;     register T c = getchar();     if (c ==  - ) neg = 1, c = getchar();     while ((c < 48) || (c > 57)) c = getchar();     for (; c < 48 || c > 57; c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15);     if (neg) x *= -1;   }   template <typename T>   void print(T n) {     bool neg = 0;     if (n < 0) n *= -1, neg = 1;     char snum[65];     long long int i = 0;     do {       snum[i++] = n % 10 +  0 ;       n /= 10;     } while (n);     --i;     if (neg) putchar( - );     while (i >= 0) putchar(snum[i--]);     putchar(  n );   }   bool semiprime(long long int num) {     int cnt = 0;     for (int i = 2; cnt < 2 && i * i <= num; ++i)       while (num % i == 0) num /= i, ++cnt;     if (num > 1) ++cnt;     return cnt == 2;   }   bool prime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   vector<pair<long long int, long long int>> g[100001];   long long int dfs(long long int nod, long long int y) {     long long int ret = 0;     for (auto x : g[nod]) {       if (x.first != y) {         ret = max(ret, x.second + dfs(x.first, nod));       }     }     return ret;   }   void overpower() {     long long int n, x, y, z;     long long int tot = 0;     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> x >> y >> z;       g[x].push_back(make_pair(y, z));       g[y].push_back(make_pair(x, z));       tot += 2 * z;     }     cout << tot - dfs(1, 0);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int t;     t = 1;     long long int i;     for (long long int i = i = 0; i < t; i++) {       overpower();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, Ord[100000 + 5];   long long ans, Set[100000 + 5][5];   inline int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }   int main() {     scanf( %d%d , &n, &k);     printf( %d n , (n * 6 - 1) * k);     for (int i = 0; i < n; i++)       printf( %d %d %d %d n , (1 + i * 6) * k, (2 + i * 6) * k, (3 + i * 6) * k,              (5 + i * 6) * k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int max(long long int a, long long int b) {     if (a > b)       return a;     else       return b;   }   long long int min(long long int a, long long int b) {     if (a < b)       return a;     else       return b;   }   const int dx[4] = {-1, 1, 0, 0};   const int dy[4] = {0, 0, -1, 1};   int XX[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int YY[] = {-1, 0, 1, -1, 1, -1, 0, 1};   vector<pair<long long int, long long int> > edges;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int n, m, i, j, k, l, r, ind, c, d, x;     cin >> n >> k;     j = k + 1;     long long int z = n / k;     long long int count = 0, ans = 2 * z;     j = 2;     vector<long long int> vec, vec2;     for (i = 1; i <= k; i++) {       count = 0;       while (count < z && j <= n) {         if (count == 0)           edges.push_back(make_pair(1, j));         else           edges.push_back(make_pair(j - 1, j));         j++;         count++;       }       vec2.push_back(count);       vec.push_back(j - 1);     }     if (j == n + 1) {       sort(vec2.begin(), vec2.end());       long long int sum = vec2[vec2.size() - 1];       if (vec2.size() >= 2) sum += vec2[vec2.size() - 2];       cout << sum <<   n ;       for (i = 0; i < edges.size(); i++) {         cout << edges[i].first <<     << edges[i].second <<   n ;       }       return 0;     }     long long int flag = 0;     for (i = 0; i < vec.size(); i++) {       if (j == n + 1) break;       edges.push_back(make_pair(vec[i], j));       j++;       flag++;     }     if (flag == 1)       ans++;     else if (flag > 1)       ans += 2;     cout << ans <<   n ;     for (i = 0; i < edges.size(); i++) {       cout << edges[i].first <<     << edges[i].second <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   char arr[1000007];   void sieve() {     arr[0] = 1;     arr[1] = 1;     for (int i = 4; i <= 1000007; i += 2) arr[i] = 1;     for (int i = 3; i * i <= 1000007; i += 2) {       if (arr[i] == 0) {         for (int j = i; i * j <= 1000007; j++) {           arr[i * j] = 1;         }       }     }   }   int main() {     sieve();     int n;     cin >> n;     int p = n + 1;     if (n < 3) {       if (n == 1) {         cout <<  1  << endl;         cout <<  1  << endl;         return 0;       } else {         cout <<  1  << endl;         cout <<  1 1  << endl;         return 0;       }     }     cout <<  2  << endl;     for (int i = 2; i <= p; i++) {       if (arr[i] == 0)         cout <<  1  ;       else         cout <<  2  ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, vector<int> > m;   int main() {     int n, k, query;     scanf( %d %d , &n, &k);     for (int i = 0; i < (int)(k); i++) {       scanf( %d , &query);       m[query - 1].push_back(i);     }     int ans = 0;     std::vector<int>::iterator low;     for (int i = 0; i < (int)(n); i++) {       if (m[i].size() == 0) {         ans += 3;         if (i == 0 || i == n - 1) ans--;       } else {         if (i - 1 >= 0) {           low = lower_bound(m[i - 1].begin(), m[i - 1].end(), m[i][0]);           if (low == m[i - 1].end() || m[i - 1].size() == 0) {             ans++;           }         }         if (i + 1 < n) {           low = lower_bound(m[i + 1].begin(), m[i + 1].end(), m[i][0]);           if (low == m[i + 1].end() || m[i + 1].size() == 0) ans++;         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 1e6 + 1;   int n, m;   string s[3];   int dp[mx][8];   bool isok(int i, int j) {     int cnt = 0;     for (int k = 0; k < 2; k++) cnt += ((i >> k) & 1) + ((j >> k) & 1);     if (cnt % 2 == 0) return false;     if (n == 2) return true;     cnt = 0;     for (int k = 1; k < 3; k++) cnt += ((i >> k) & 1) + ((j >> k) & 1);     return cnt & 1;   }   int solve(int idx, int msk) {     if (idx == m) return 0;     int &ans = dp[idx][msk];     if (~ans) return ans;     ans = 1e9;     for (int i = 0; i < (1 << n); i++)       if (idx == 0 || isok(msk, i)) {         int cur = 0;         for (int j = 0; j < n; j++) cur += ((i >> j) & 1) != (s[j][idx] -  0 );         ans = min(ans, cur + solve(idx + 1, i));       }     return ans;   }   int main() {     cin.tie(nullptr);     ios_base::sync_with_stdio(0);     cin >> n >> m;     if (n == 1) return cout <<  0 , 0;     if (n >= 4) return cout <<  -1 , 0;     for (int i = 0; i < n; i++) cin >> s[i];     int ans = 1e9;     memset(dp, -1, sizeof dp);     for (int i = 0; i < (1 << n); i++) ans = min(ans, solve(0, i));     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long N, M;   long long Arb[800002], Value[100002], Lazy[800002], Colour[800002];   void Build(long long K, long long L, long long R) {     long long Mid = (L + R) / 2;     if (L == R) {       Colour[K] = L;       return;     }     Build(2 * K, L, Mid);     Build(2 * K + 1, Mid + 1, R);   }   void Read() { cin >> N >> M; }   void Relax(long long K, long long L, long long R) {     if (Lazy[K] == 0) return;     Colour[2 * K] = Colour[2 * K + 1] = Colour[K];     Arb[2 * K] += Lazy[K] * ((L + R) / 2 - L + 1);     Arb[2 * K + 1] += Lazy[K] * (R - (L + R) / 2);     if (L != R) {       Lazy[2 * K] += Lazy[K];       Lazy[2 * K + 1] += Lazy[K];     }     Lazy[K] = 0;   }   void Update(long long K, long long L, long long R, long long Poz1,               long long Poz2, long long Val) {     long long Mid = (L + R) / 2;     Relax(K, L, R);     if (L > Poz2 || R < Poz1 || K > 4 * N) return;     if (Poz1 <= L && R <= Poz2) {       if (Colour[K] > 0) {         Arb[K] += abs(Colour[K] - Val) * (R - L + 1);         Lazy[K] += abs(Colour[K] - Val);         Colour[K] = Val;       } else {         Update(K * 2, L, Mid, Poz1, Poz2, Val);         Update(K * 2 + 1, Mid + 1, R, Poz1, Poz2, Val);         Arb[K] = Arb[2 * K] + Arb[2 * K + 1];         Colour[K] = Val;       }       return;     }     Update(2 * K + 1, Mid + 1, R, Poz1, Poz2, Val);     Update(2 * K, L, Mid, Poz1, Poz2, Val);     Arb[K] = Arb[2 * K] + Arb[2 * K + 1];     Colour[K] = Colour[K * 2] == Colour[K * 2 + 1] ? Colour[K * 2] : 0;   }   long long Qwery(long long K, long long L, long long R, long long Poz1,                   long long Poz2) {     Relax(K, L, R);     long long Mid = (L + R) / 2;     if (L > Poz2 || R < Poz1) return 0;     if (Poz1 <= L && R <= Poz2) return Arb[K];     return Qwery(2 * K, L, Mid, Poz1, Poz2) +            Qwery(2 * K + 1, Mid + 1, R, Poz1, Poz2);   }   void Browse() {     long long i;     for (i = 1; i <= M; i++) {       long long type, a, b, c;       cin >> type >> a >> b;       if (type == 1) {         cin >> c;         Update(1, 1, N, a, b, c);       }       if (type == 2) cout << Qwery(1, 1, N, a, b) <<   n ;     }   }   int main() {     Read();     Build(1, 1, N);     Browse();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   int q, n, a[N], pos[N], dp[N], pre[N];   long long ans = 0;   int main() {     scanf( %d , &q);     while (q--) {       ans = 0;       scanf( %d , &n);       for (int i = 1; i <= n; i++) pre[i] = -1;       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         dp[i] = 0;         pos[i] = N;         if (pre[a[i]] == -1) {           pre[a[i]] = i;         }       }       dp[N - 1] = 0;       for (int i = 0; i < n; i++) {         if (a[i + 1] == a[i])           pos[i + 1] = i;         else {           if (a[i + 1] == a[pos[i] - 1]) {             pos[i + 1] = pos[i] - 1;             continue;           }           int tmp = i;           while (a[i + 1] != a[pos[tmp] - 1]) {             tmp = pos[tmp] - 1;             if (a[i + 1] == a[pos[tmp] - 1]) {               pos[i + 1] = pos[tmp] - 1;               break;             }             if (tmp == N - 1 || tmp < pre[a[i + 1]]) {               pos[i + 1] = N;               break;             }           }         }       }       for (int i = 0; i < n; i++) {         if (pos[i] != N) dp[i] = 1;       }       for (int i = 0; i < n; i++) {         dp[i] += dp[pos[i] - 1];         ans += dp[i];       }       printf( %lld n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e17;   const int MAXM = 1e5 + 5;   const int MAXN = 1e6 + 4;   long long fact[MAXM];   long long nChoosek(long long n, long long k) {     if (k > n) return 0;     if (k * 2 > n) k = n - k;     if (k == 0) return 1;     long long result = n;     for (long long i = 2; i <= k; ++i) {       result *= (n - i + 1);       result /= i;     }     return result;   }   int main() {     long long n;     cin >> n;     long long Ans = 0;     for (long long i = 5; i <= 7; i++) {       Ans += nChoosek(n, i);     }     cout << Ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   int val[501000], deg[501000];   vector<int> adj[501000];   int main() {     int n, m, u, v;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);       deg[u]++, deg[v]++;     }     set<pair<int, int> > st;     for (int i = 1; i <= n; i++) {       if (adj[i].size() > 1) st.insert(pair<int, int>(adj[i].size(), i));     }     while (!st.empty()) {       pair<int, int> a = *st.begin();       if (a.first < 2) break;       st.erase(a);       val[a.second] ^= 1;       u = a.second;       deg[u] = 0;       for (int i = 0; i < adj[u].size(); i++) {         int v = adj[u][i];         if (val[v] == val[u]) {           if (deg[v] > 1) st.erase(pair<int, int>(deg[v], v));           deg[v]++;           if (deg[v] > 1) st.insert(pair<int, int>(deg[v], v));           deg[u]++;         } else {           if (deg[v] > 1) st.erase(pair<int, int>(deg[v], v));           deg[v]--;           if (deg[v] > 1) st.insert(pair<int, int>(deg[v], v));         }       }     }     for (int i = 1; i <= n; i++) printf( %d , val[i]);     return 0;   }