malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   struct Event {     long long x, t, i;     Event() {}     Event(long long x, long long t, long long i) : x(x), t(t), i(i) {}   };   bool cmpEvents(const Event &a, const Event &b) {     return tie(a.x, a.t, a.i) < tie(b.x, b.t, b.i);   }   const long long MAX_N = 2e5 + 5;   long long n;   long long cnt[MAX_N];   pair<bool, bool> cover[MAX_N];   void solve() {     cin >> n;     vector<Event> sc;     for (long long i = 1; i <= n; ++i) {       cnt[i] = 0;       cover[i] = make_pair(false, false);       long long l, r;       cin >> l >> r;       l *= 2, r *= 2;       sc.emplace_back(l, -1, i);       sc.emplace_back(r, 1, i);     }     sort(sc.begin(), sc.end(), cmpEvents);     for (long long i = 1; i < 2 * n; ++i) {       sc.emplace_back((sc[i - 1].x + sc[i].x) / 2, 0, 0);     }     sort(sc.begin(), sc.end(), cmpEvents);     set<long long> alive;     long long start_ans = 2;     for (long long i = 0; i < (long long)sc.size();) {       long long j = i;       while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == -1) {         alive.emplace(sc[j].i);         ++j;       }       while (i < j) {         cover[sc[i].i].first = (long long)alive.size() > 1;         ++i;       }       while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == 0) {         if ((long long)alive.size() == 1) {           cnt[*alive.begin()]++;         }         ++j;       }       if (alive.empty()) {         start_ans++;       }       i = j;       while (j < (long long)sc.size() && sc[i].x == sc[j].x && sc[j].t == 1) {         cover[sc[j].i].second = (long long)alive.size() > 1;         ++j;       }       while (i < j) {         alive.erase(sc[i].i);         ++i;       }     }     long long ans = 0;     for (long long i = 1; i <= n; ++i) {       ans = max(ans, start_ans + cnt[i] - !cover[i].first - !cover[i].second - 1);     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long T;     cin >> T;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, in[100010], sum1, sum2;   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       in[x]++;       in[y]++;     }     for (int i = 1; i <= n + 1; i++)       if (in[i] == 1)         sum1++;       else if (in[i] == 2)         sum2++;     if (sum1 == 2 && sum2 == n - 2) {       cout <<  bus topology ;       return 0;     }     sum1 = sum2 = 0;     for (int i = 1; i <= n; i++)       if (in[i] == 2) sum1++;     if (sum1 == n) {       cout <<  ring topology ;       return 0;     }     sum1 = sum2 = 0;     for (int i = 1; i <= n + 1; i++)       if (in[i] == 1)         sum1++;       else if (in[i] == n - 1)         sum2++;     if (sum1 == n - 1 && sum2 == 1) {       cout <<  star topology ;       return 0;     }     cout <<  unknown topology ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long n, m, k, t;     cin >> n >> m >> k >> t;     pair<int, int> mp[k + 1];     long long x, y, a, b;     for (int i = 0; i < k; i++) {       cin >> mp[i].first >> mp[i].second;     }     sort(mp, mp + k);     for (int i = 0; i < t; i++) {       cin >> x >> y;       long long idx = m * (x - 1) + y;       bool f = true;       for (int i = 0; i < k; i++) {         if (mp[i].first > x || (mp[i].first == x && mp[i].second > y)) {           idx -= (i + 1);           break;         }         if (mp[i].first == x && mp[i].second == y) {           f = false;           cout <<  Waste  << endl;           break;         }         if (i == k - 1) idx = idx - k - 1;       }       if (idx % 3 == 0 && f)         cout <<  Carrots  << endl;       else if (idx % 3 == 1 && f)         cout <<  Kiwis  << endl;       else if (idx % 3 == 2 && f)         cout <<  Grapes  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10;   const int INF = int(1e9);   int main() {     int n;     char str1[maxn], str2[maxn];     while (~scanf( %d , &n)) {       scanf( %s %s , str1, str2);       int h, m;       h = (str1[0] -  0 ) * 10 + str1[1] -  0 ;       m = (str2[0] -  0 ) * 10 + str2[1] -  0 ;       int ans = 0;       while (h % 10 != 7 && m % 10 != 7) {         if (m - n < 0) {           m = m - n + 60;           if (h == 0)             h = 23;           else             h--;         } else           m = m - n;         ans++;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 9e18;   const int inf = 2147483647;   long long qpow(long long a, long long b, long long mod) {     long long r = 1;     for (; b; b >>= 1) {       if (b & 1) r = (r * a) % mod;       a = (a * a) % mod;     }     return r;   }   const int N = 1e5 + 5;   void work() {     int t;     scanf( %d , &t);     while (t--) {       int r, g, b, w;       scanf( %d%d , &r, &g);       scanf( %d%d , &b, &w);       int sum = 0;       if (r % 2) sum++;       if (g % 2) sum++;       if (b % 2) sum++;       if (sum == 0)         puts( YES );       else if (sum == 1) {         puts(w % 2 == 0 ?  YES  :  NO );       } else if (sum == 2) {         if (r && g && b)           puts(w % 2 ?  YES  :  NO );         else           puts( NO );       } else {         puts( YES );       }     }   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[1000], b, c, d;     cin >> b >> c >> d;     a[0] = b;     a[1] = c;     for (int i = 2; i <= d; i++) {       a[i] = a[i - 1] + a[i - 2];     }     cout << a[d];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n], i, j, k1 = 0, k2 = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1)         k1++;       else         k2++;     }     int k3 = 0, k4 = 0;     for (i = 0; i < n; i++) {       if (a[i] == 1)         k3++;       else         k4++;       if (k3 >= k1 || k4 >= k2) {         j = i;         break;       }     }     cout << j + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   struct Node {     long long x, y;   } Edge[300005];   long long pre[300005];   bool cmp(Node a, Node b) { return a.y > b.y; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &Edge[i].x, &Edge[i].y);     }     sort(Edge + 1, Edge + n + 1, cmp);     priority_queue<int, vector<int>, greater<int>> q;     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (q.size() < m) {         q.push(Edge[i].x);         pre[i] = pre[i - 1] + Edge[i].x;         ans = max(ans, Edge[i].y * pre[i]);       } else {         if (Edge[i].x <= q.top()) {           pre[i] = pre[i - 1];         } else {           pre[i] = pre[i - 1] - q.top() + Edge[i].x;           q.pop();           q.push(Edge[i].x);           ans = max(ans, Edge[i].y * pre[i]);         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char x, y, t;   struct node {     char c;     int p;   } ans[4];   inline bool cmp(const node &a, const node &b) { return a.p < b.p; }   int main() {     for (register int i = 1; i <= 3; i++) {       ans[i].c =  A  + i - 1;       cin >> x >> t >> y;       if (t ==  > ) swap(x, y);       ans[x -  A  + 1].p++;       ans[y -  A  + 1].p += 2;     }     sort(ans + 1, ans + 4, cmp);     if (ans[1].p == ans[2].p || ans[2].p == ans[3].p) {       cout <<  Impossible ;       return 0;     }     cout << ans[1].c << ans[2].c << ans[3].c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 1e6 + 5;   long long ans[MX];   long long upd[MX];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, w;     cin >> n >> w;     vector<int> a[n];     int mx[n];     for (int i = 0; i < n; i++) {       int l;       cin >> l;       a[i] = vector<int>(l);       mx[i] = -1000000000;       for (int j = 0; j < l; j++) {         cin >> a[i][j];         mx[i] = max(mx[i], a[i][j]);       }     }     memset(ans, 0, sizeof(ans));     for (int i = 0; i < n; i++) {       if (w >= 2 * a[i].size() + 1) {         int currmx = 0;         for (int j = 0; j < a[i].size(); j++) {           currmx = max(currmx, a[i][j]);           ans[j + 1] += currmx;         }         currmx = 0;         for (int j = a[i].size() - 1; j >= 0; j--) {           currmx = max(currmx, a[i][j]);           ans[w - ((a[i].size() - 1) - j)] += currmx;         }         upd[a[i].size()] -= max(mx[i], 0);         upd[w - a[i].size()] += max(mx[i], 0);       } else {         deque<int> q;         int idx = 0;         bool zero = false;         for (int j = 1; j <= w; j++) {           if (idx < a[i].size()) {             while (!q.empty() && a[i][q.back()] <= a[i][idx]) {               q.pop_back();             }             q.push_back(idx++);           }           zero = (a[i].size() <= (j - 1)) || (a[i].size() <= (w - j));           if (zero)             ans[j] += max(a[i][q.front()], 0);           else             ans[j] += a[i][q.front()];           if (((a[i].size() - q.front()) + j) >= w + 1) {             q.pop_front();           }         }       }     }     for (int i = w; i >= 1; i--) {       upd[i] += upd[i + 1];     }     for (int i = 1; i <= w; i++) cout << ans[i] + upd[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     string a;     string b;     cin >> a >> b;     int order = 0;     while (a[order] ==  0 ) {       order++;     }     a.erase(0, order);     order = 0;     while (b[order] ==  0 ) {       order++;     }     b.erase(0, order);     if (a.size() > b.size()) {       cout <<  > ;     } else if (a.size() < b.size()) {       cout <<  < ;     } else {       for (int i = 0; i < a.size(); i++) {         if (a[i] > b[i]) {           cout <<  > ;           return 0;         } else if (a[i] < b[i]) {           cout <<  < ;           return 0;         }       }       cout <<  = ;     }   }
#include <bits/stdc++.h>   using i8 = std::int8_t;   using i16 = std::int16_t;   using i32 = std::int32_t;   using i64 = std::int64_t;   using u8 = std::uint8_t;   using u16 = std::uint16_t;   using u32 = std::uint32_t;   using u64 = std::uint64_t;   auto SolveTest() -> void {     int n;     std::cin >> n;     std::vector<int> a(n);     for (auto &elem : a) {       std::cin >> elem;     }     std::set<int> numbers(std::begin(a), std::end(a));     for (auto it = std::begin(numbers); std::next(it) != std::end(numbers);          ++it) {       if (std::abs(*it - *std::next(it)) > 1) {         std::cout <<  NO n ;         return;       }     }     std::cout <<  YES n ;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.tie(nullptr);     i32 test_count;     std::cin >> test_count;     for (i32 t = 0; t < test_count; ++t) {       SolveTest();     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   unordered_map<int, int> mask, f;   int SG(int s) {     if (f.count(s)) return f[s];     bool t[30] = {0};     for (int i = 0; s >> i; i++) {       t[SG(s >> (i + 1) | (s & ((1 << i) - 1)))] = 1;     }     for (int i = 0; i < 30; i++)       if (!t[i]) return f[s] = i;     return 30;   }   int main() {     scanf( %d , &n);     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       for (int d = 2; d * d <= x; d++)         if (x % d == 0) {           int c = 0;           while (x % d == 0) x /= d, c++;           mask[d] |= 1 << (c - 1);         }       if (x > 1) mask[x] |= 1;     }     int ans = 0;     for (auto s : mask) ans ^= SG(s.second);     puts(ans ?  Mojtaba  :  Arpa );     return 0;   }
//Author: AnandRaj uux   #include <bits/stdc++.h>   using namespace std;      typedef long long ll;   typedef long double ld;   typedef pair<int,int> pii;   typedef vector<int> vi;   typedef vector<vi> vvi;   typedef vector<pii> vpii;   typedef pair<ll,ll> pll;   typedef vector<ll> vl;   typedef vector<vl> vvl;   typedef vector<pll> vpll;       #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);   #define test() int t;cin>>t;while(t--)   #define all(v) v.begin(),v.end()   #define prinp(p) cout<<p.first<<   <<p.second<<endl   #define prinv(V) for(auto v:V) cout<<v<<   ;cout<<endl   #define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]   #define what(x) cerr<<#x<<  =  <<x<<endl   #define KStest() int t,t1;cin>>t;t1=t;while(t--)   #define KScout cout<< Case # <<t1-t<< :     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 1e9+7,MAX = 1e6+5;   const ll INF = 1e18+5;      vvi A;   bool can = true;   vi TS;   vi vis,inStack;   void dfs(int x, int parent)    {       vis[x] = true;       inStack[x] = true;       for(auto v:A[x])        {           if (vis[v] && inStack[v])            {               can = false;               return;           }           if(!vis[v])            {               dfs(v, x);           }       }       inStack[x] = false;       TS.push_back(x);   }      int main()   {    int n,m,k;    cin>>n>>m>>k;    A.resize(n+1);    vector<string> P(n+1);    map<string,int> Sp;    take(P,1,n);    for(int i=1;i<=n;i++) Sp[P[i]] = i;        vis.resize(n+1);    inStack.resize(n+1);       vector<int> MT(m+1);    vector<string> S(m+1);       for(int i=1;i<=m;i++)    {     cin>>S[i]>>MT[i];     set<string> X;     X.insert(  );     for(int j=0;j<k;j++)     {      set<string> XX;      for(auto x:X)      {       XX.insert(x+ _ );       XX.insert(x+S[i][j]);      }      X = XX;     }     if(X.count(P[MT[i]])==0) {can = false;break;}     for(auto x:X)     {      if(Sp.find(x)==Sp.end() || Sp[x]==MT[i]) continue;      else      {       A[MT[i]].push_back(Sp[x]);      }     }    }    // for(int i=1;i<=n;i++)    // {    //  prinv(A[i]);    // }    for(int i=1;i<=n;i++)    {     if(!vis[i]) dfs(i,-1);    }    if(can)    {     cout<< YES <<endl;     reverse(all(TS));     prinv(TS);    }    else cout<< NO <<endl;         }
#include <bits/stdc++.h>   using namespace std;   const int N = 405;   int n, kk;   vector<pair<int, int>> v[N][N], e[N];   int dp[N][N], sz[N], f[N];   void dfs1(int pos, int fa) {     sz[pos] = 1;     for (auto &i : e[pos])       if (i.first != fa) {         dfs1(i.first, pos);         sz[pos] += sz[i.first];         f[i.first] = i.second;       }   }   void dfs2(int pos, int fa) {     if (pos == 1)       dp[pos][sz[pos]] = 0;     else       dp[pos][sz[pos]] = 1;     dp[pos][0] = 0;     for (auto &i : e[pos]) {       if (i.first == fa) continue;       dfs2(i.first, pos);       for (int j = sz[pos] - 1; j > 0; --j) {         int tk = -1;         for (int k = 0; k <= sz[i.first] && k <= j; k++)           if (dp[pos][j] > dp[i.first][k] + dp[pos][j - k]) {             dp[pos][j] = dp[i.first][k] + dp[pos][j - k], tk = k;             v[pos][j] = v[pos][j - tk], v[pos][j].push_back({i.first, tk});           }         if (tk != -1)           v[pos][j] = v[pos][j - tk], v[pos][j].push_back({i.first, tk});       }     }   }   void print_ans(int pos, int cnt) {     if (sz[pos] == cnt) {       cout << f[pos] <<    ;       return;     }     for (auto &i : v[pos][cnt]) print_ans(i.first, i.second);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> kk;     cin.tie(0);     for (int i = 1; i < n; i++) {       int t1, t2;       cin >> t1 >> t2;       e[t1].push_back({t2, i});       e[t2].push_back({t1, i});     }     memset(dp, 63, sizeof(dp));     dfs1(1, 0);     dfs2(1, 0);     int ans = dp[1][n - kk], pos = 1;     for (int i = 2; i <= n; i++)       if (sz[i] >= kk && ans > dp[i][sz[i] - kk] + 1)         ans = dp[i][sz[i] - kk] + 1, pos = i;     cout << ans << endl;     if (pos != 1) cout << f[pos] << endl;     print_ans(pos, sz[pos] - kk);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int c3[100010], c2[1010];   int graph[110][110];   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     memset(graph, 0, sizeof graph);     for (int i = (3), _b = (100); i <= _b; ++i) {       c3[i] = (i * (i - 1) * (i - 2)) / 6;     }     for (int i = (2), _b = (100); i <= _b; ++i) {       c2[i] = (i * (i - 1)) / 2;     }     int k, esco;     cin >> k;     for (int i = (100), _b = (3); i >= _b; --i) {       if (k >= c3[i]) {         k -= c3[i];         esco = i;         break;       }     }     for (int i = 0; i < (int)(esco); ++i) {       for (int j = 0; j < (int)(esco); ++j) {         if (i != j) graph[i][j] = graph[j][i] = 1;       }     }     int fixo = esco;     while (k > 0) {       int cont = 0;       for (int i = (fixo), _b = (2); i >= _b; --i) {         cont = i;         if (k >= c2[i]) break;       }       for (int i = 0; i < (int)(cont); ++i) graph[i][esco] = graph[esco][i] = 1;       k -= c2[cont];       esco++;     }     cout << esco << endl;     for (int i = 0; i < (int)(esco); ++i) {       for (int j = 0; j < (int)(esco); ++j) {         cout << graph[i][j] <<   ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed;     cout << setprecision(10);     int row, column;     char temp;     cin >> row >> column;     for (int i = 0; i < int(row - 1); ++i) {       for (int j = 0; j < int(column); ++j) {         cin >> temp;       }     }     string s;     cin >> s;     int s1 = 0;     for (int i = 0; i < int(column); ++i) {       if (s[i] ==  B ) {         s1++;         while (s[i] ==  B ) i++;       }     }     cout << s1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   int test[maxn];   int main() {     int n, num(0), x;     cin >> n;     char ch;     int l = 2e5;     int r = l + 1;     int mi, ma;     for (int i = 0; i < n; i++) {       cin >> ch >> x;       if (ch ==  L ) {         test[x] = l;         num++;         l--;         mi = test[x];       } else if (ch ==  R ) {         test[x] = r;         num++;         r++;         ma = test[x];       } else if (ch ==  ? ) {         int temp = test[x];         int ans = min(temp - mi, r - 1 - temp);         cout << ans << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 2;   int len, ans = 0, maxdis[N];   vector<int> adj[N], cur;   void dfs(int x, int p) {     if (adj[x].size() == 1) {       maxdis[x] = 0;       return;     }     int i, idxmin1;     for (i = 0; i < adj[x].size(); i++) {       if (adj[x][i] != p) {         dfs(adj[x][i], x);       }     }     cur.clear();     for (i = 0; i < adj[x].size(); i++) {       if (adj[x][i] != p) {         cur.push_back(maxdis[adj[x][i]] + 1);       }     }     sort(cur.begin(), cur.end());     for (i = 0; i < cur.size() - 1; i++) {       if (cur[i] + cur[i + 1] > len) {         break;       }     }     ans += cur.size() - 1 - i;     maxdis[x] = cur[i];   }   int main() {     ios::sync_with_stdio(0);     int n, i, j, k, l = 0;     cin >> n >> len;     for (i = 1; i < n; i++) {       cin >> j >> k;       adj[j].push_back(k);       adj[k].push_back(j);     }     for (i = 1; i <= n; i++) {       if (adj[i].size() > 1) {         l = i;         break;       }     }     dfs(l, l);     cout << ans + 1;   }
#include <bits/stdc++.h>      using namespace std;      struct node {       int u , v , w;       node(){}       node(int u,int v,int w):       u(u) , v(v) , w(w){};       bool operator < (const node &o) const {           return w < o.w;       }   };      struct dsu {       int par[200010];       void init() {           for (int i = 1 ; i <= 200000 ; ++i) par[i] = i;       }       int fin(int u) {           if (u != par[u]) par[u] = fin(par[u]);           return par[u];       }       bool join(int u , int v) {           u = fin(u);           v = fin(v);           if (u == v) return false;           if (par[u] > par[v]) swap(u , v);           par[u] = v;           return true;       }   } a , b;      set < int > vertex;   vector < int > g[200010];   vector < node > edge;   long long rest;      void DFS(int u) {       vertex.erase(u);       sort(g[u].begin(),g[u].end());       int v = 0;       while (1) {           auto it = vertex.lower_bound(v);           if (it == vertex.end()) return;           v = *it;           if (!binary_search(g[u].begin(),g[u].end(),v)) {               a.join(u , v);               DFS(v);               rest--;           }           v++;       }   }      int main() {       ios::sync_with_stdio(0);       cin.tie(0);cout.tie(0);       long long n , m;       int x = 0;       cin >> n >> m;       rest = n * (n - 1) / 2 - m;       for (int i = 1 ; i <= m ; ++i) {           int u , v , w;           cin >> u >> v >> w;           x ^= w;           g[u].push_back(v);           g[v].push_back(u);           edge.emplace_back(u , v , w);       }       a.init();b.init();       for (int i = 1 ; i <= n ; ++i)           vertex.insert(i);       for (int i = 1 ; i <= n ; ++i)           if (vertex.count(i)) DFS(i);       if (rest > 0) x = 0;       int res = 0;       sort(edge.begin(),edge.end());       for (auto p : edge) {           int u = p.u , v = p.v , w = p.w;           if (a.join(u , v)) {               res += w;               b.join(u , v);           } else if (b.join(u , v)) x = min(x , w);       }       cout << res + x;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int a[N];   vector<int> v;   int main() {     int n, s;     scanf( %d%d , &n, &s);     int ans = 0;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (a[s] != 0) ans++;     for (int i = 1; i <= n; i++)       if (i == s)         continue;       else         v.push_back(a[i]);     v.push_back(0);     sort(v.begin(), v.end());     int cnt = 0;     int idx = 0;     while (v[idx] == 0 && idx < n) cnt++, idx++;     ans += cnt;     cnt--;     ans--;     int last = n - 1;     for (int i = idx; i <= last; i++) {       if (i == 0) continue;       if (v[i] == v[i - 1]) continue;       if (v[i - 1] == v[i] - 1) continue;       int diff = v[i] - v[i - 1] - 1;       if (diff <= cnt) {         cnt -= diff;         continue;       }       diff -= cnt;       cnt = 0;       while (diff--) {         if (last >= i) {           last--;           ans++;           continue;         }         if (last <= i) break;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long m = 1e9 + 7;   long long c[4010][4010];   long long dp[4010];   int main() {     c[0][1] = 0;     for (int i = 0; i <= 4000; i++) c[i][0] = 1;     for (int i = 1; i <= 4000; i++) {       for (int j = 1; j < i + 2; j++)         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % m;     }     dp[0] = 1;     for (int i = 1; i <= 4000; i++) {       dp[i] = 0;       for (int j = 0; j < i; j++) {         dp[i] = (dp[i] + dp[i - j - 1] * c[i - 1][j]) % m;       }     }     int n;     cin >> n;     long long ans = 0;     for (int i = 0; i < n; i++) ans = (ans + dp[i] * c[n][i]) % m;     cout << ans;     return 0;   }