malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char s[2004], temp[2004], e[2004], c, cnt;   int n;   int q[27];   void f(int x) {     cnt++;     if (cnt != n * 3)       printf( %d  , x);     else       printf( %d n , x);     int i;     for (i = n - x + 1; i <= n; i++) temp[n - i + 1] = s[i];     for (i = 1; i < n - x + 1; i++) temp[i + x] = s[i];     for (i = 1; i <= n; i++) s[i] = temp[i];   }   int main() {     int t, i, j, k, x, l1, l2, flag, o;     scanf( %d , &t);     scanf( %s , s + 1);     scanf( %s , e + 1);     l1 = strlen(s + 1);     l2 = strlen(e + 1);     if (l1 != l2) {       printf( -1 n );       return 0;     }     memset(q, 0, sizeof(q));     for (i = 1; i <= l1; i++) {       q[s[i] -  a ]++;       q[e[i] -  a ]--;     }     flag = 1;     for (i = 0; i < 26; i++) {       if (q[i]) flag = 0;     }     if (flag == 0) {       printf( -1 n );       return 0;     }     n = l1;     printf( %d n , n * 3);     cnt = 0;     for (o = 0; o < n; o++) {       f(n);       c = e[n - o];       for (i = n - o; i >= 0; i--) {         if (s[i] == c) break;       }       f(n - i);       f(1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const int inf = 99999999;   int n;   char c[20];   int r[20];   int b[20];   int dp[1 << 16][123];   int main() {     int n;     cin >> n;     int maxi = 0;     int ans1 = 0;     int ans2 = 0;     for (int i = 0; i < n; i++) {       cin >> c[i] >> r[i] >> b[i];       maxi += i;       ans1 += r[i];       ans2 += b[i];     }     memset(dp, -1, sizeof(dp));     dp[0][0] = 0;     for (int i = 1; i < 1 << n; i++) {       for (int j = 0; j < n; j++) {         if (i >> j & 1) {           int R = 0;           int B = 0;           for (int k = 0; k < n; k++) {             if (k != j && i >> k & 1) {               R += c[k] ==  R ;               B += c[k] ==  B ;             }           }           R = min(R, r[j]);           B = min(B, b[j]);           for (int k = 0; k <= maxi; k++) {             if (dp[i ^ (1 << j)][k] != -1) {               dp[i][k + R] = max(dp[i][k + R], dp[i ^ (1 << j)][k] + B);             }           }         }       }     }     int ans = max(ans1, ans2);     for (int i = 0; i <= maxi; i++) {       if (dp[(1 << n) - 1][i] != -1) {         ans = min(ans, max(ans2 - dp[(1 << n) - 1][i], ans1 - i));       }     }     cout << ans + n;     return 0;   }
#include <bits/stdc++.h>   void output1(int n) {     for (int i = 0; i < n; ++i) {       printf( 10 );     }     printf(  n );   }   void output2(int m) {     --m;     for (int i = 0; i < m; ++i) {       printf( 01 );     }     printf( 0 n );   }   void output3(int n, int m) {     if (n == m + 1) {       --n;       for (int i = 0; i < n; ++i) {         printf( 10 );       }       printf( 1 n );       return;     }     int tmp = n - m - 1;     int up = m + 1;     up--;     for (int i = 0; i < up; ++i) {       printf( 1 );       if (tmp) {         printf( 1 );         --tmp;       }       printf( 0 );     }     printf( 1 );     if (tmp) {       printf( 1 );     }     printf(  n );   }   int main() {     int n, m;     while (scanf( %d%d , &m, &n) != EOF) {       if (m == n) {         output1(n);       } else if (m == n + 1) {         output2(m);       } else if (n > m && n <= 2 * m + 2) {         output3(n, m);       } else {         printf( -1 n );       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   const char nl =   n ;   using namespace std;   using ll = long long;   using vi = vector<int>;   using vl = vector<ll>;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using str = string;   str to_string(char c) { return str(1, c); }   str to_string(bool b) { return b ?  true  :  false ; }   str to_string(const char* second) { return (str)second; }   str to_string(str second) { return second; }   template <class A>   str to_string(complex<A> c) {     stringstream ss;     ss << c;     return ss.str();   }   str to_string(vector<bool> v) {     str res =  { ;     for (int i = 0; i < (int)v.size(); i++) res += char( 0  + v[i]);     res +=  } ;     return res;   }   template <size_t SZ>   str to_string(bitset<SZ> b) {     str res =   ;     for (int i = 0; i < b.size(); i++) res += char( 0  + b[i]);     return res;   }   template <class A, class B>   str to_string(pair<A, B> p);   template <class T>   str to_string(T v) {     bool fst = 1;     str res =  { ;     for (const auto& x : v) {       if (!fst) res +=  ,  ;       fst = 0;       res += to_string(x);     }     res +=  } ;     return res;   }   template <class A, class B>   str to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << to_string(h);     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   string c;   int n;   int dp[26][26];   signed main() {     cin.tie(nullptr);     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < 26; i++) {       for (int j = 0; j < 26; j++) {         dp[i][j] = -1e9;       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       cin >> c;       int m = c.length();       int a = c[0] -  a ;       int b = c[m - 1] -  a ;       for (int j = 0; j < 26; j++) {         dp[j][b] = max(dp[j][b], dp[j][a] + m);       }       dp[a][b] = max(dp[a][b], m);     }     for (int i = 0; i < 26; i++) {       ans = max(ans, dp[i][i]);     }     cout << ans << nl;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5100;   const long long M = 15;   const long long mod = 1e9 + 7;   const long long MOD = 998244353;   const long long P = 1336;   const long double eps = 0.000000001;   const long long inf = 1e9;   mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());   long long w[N], b[N], a[N], dp[N], u[N];   vector<long long> nom[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     srand(time(0));     long long n, k, V;     cin >> n >> k >> V;     long long sum = 0;     if (V == 0) {       cout <<  YES  <<   n ;       cout << inf <<   1 2 ;       return 0;     }     for (long long i = 0; i < n; i++) {       cin >> w[i];       sum += w[i];       b[i] = w[i] % k;       a[i] = w[i] - b[i];       if (a[i] > V) a[i] = V / k * k;     }     if (sum < V) {       cout <<  NO ;       return 0;     }     dp[0] = 1;     for (long long i = 0; i < n; i++) {       for (long long j = k; j >= 0; j--) {         if (dp[j] != 1) continue;         long long per = (j + b[i]) % k;         if (per == 0) per = k;         if (dp[per]) continue;         dp[per] = 2;         for (auto to : nom[j]) {           nom[per].push_back(to);         }         nom[per].push_back(i);       }       for (long long j = k; j >= 0; j--) {         if (dp[j] == 2) dp[j] = 1;       }     }     for (long long i = 0; i < n; i++) {       long long need = (V - a[i]) % k;       if (need == 0) need = k;       if (!dp[need] && need != k) continue;       long long no = -1;       vector<pair<long long, pair<long long, long long> > > g;       for (long long j = 0; j < n; j++) {         u[j] = 0;       }       for (auto to : nom[need]) {         u[to] = 1;       }       if (u[i] == 0 && need != k) continue;       long long s = 0;       for (auto to : nom[need]) {         u[to] = 1;         if (to == i) {           s += w[i];           continue;         }         g.push_back({inf, {to, i}});         s += w[to];       }       long long e = -1;       for (long long j = 0; j < n; j++) {         if (u[j]) continue;         e = j;       }       if (s < V) {         need = (V - s) / k;         for (long long j = 0; j < n; j++) {           if (u[j] || j == e) continue;           long long c = w[j] / k;           if (w[j] % k) c++;           if (c) g.push_back({c, {j, e}});           w[e] += w[j];         }         long long c = w[e] / k;         if (c < need) continue;         g.push_back({need, {e, i}});       }       if (s > V) {         need = (s - V) / k;         if (i)           g.push_back({need, {i, 0}});         else           g.push_back({need, {i, 1}});       }       cout <<  YES  <<   n ;       for (auto to : g) {         cout << to.first <<     << to.second.first + 1 <<                  << to.second.second + 1 <<   n ;       }       return 0;     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 500000 + 24;   int a[MAX];   int main() {     int n, m, ans, tmp, u, v, fc;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     m = a[0];     ans = 0;     for (int i = 0; i < n; i++) {       while (i < n && a[i] == m) {         i++;       }       tmp = 0;       u = i;       if (m == 0) {         while (i + 1 < n && a[i] == 1 && a[i + 1] == 0) {           tmp++;           i += 2;         }       } else {         while (i + 1 < n && a[i] == 0 && a[i + 1] == 1) {           tmp++;           i += 2;         }       }       v = i;       ans = max(ans, tmp);       int j = u;       for (; j < v - tmp; j++) {         a[j] = m;       }       fc = (i < n) ? a[i] : a[n - 1];       for (; j < v; j++) {         a[j] = fc;       }       m = a[i];       i--;     }     printf( %d n , ans);     for (int i = 0; i < n - 1; i++) {       printf( %d  , a[i]);     }     printf( %d n , a[n - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int n, a[maxn], cnt[maxn], mx = 0, last[maxn * 2], ans = 0;   void solve1(int x) {     for (int i = 1; i <= n; i++) last[n - i] = last[n + i] = -1;     last[n] = 0;     int cur = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == x)         cur++;       else if (a[i] == mx)         cur--;       if (last[n + cur] == -1)         last[n + cur] = i;       else         ans = max(ans, i - last[n + cur]);     }   }   void solve2(int x) {     for (int i = 1; i <= n; i++) cnt[i] = 0;     int l = 1, equal = 0;     cnt[a[l]]++;     if (cnt[a[l]] == x) equal++;     for (int i = 2; i <= n; i++) {       cnt[a[i]]++;       if (cnt[a[i]] == x)         equal++;       else if (cnt[a[i]] > x) {         while (cnt[a[i]] > x) {           cnt[a[l]]--;           if (cnt[a[l]] == x - 1) equal--;           l++;         }       }       if (equal >= 2) ans = max(ans, i - l + 1);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       cnt[a[i]]++;       mx = cnt[mx] < cnt[a[i]] ? a[i] : mx;     }     int limt = sqrt(n);     for (int i = 1; i <= n; i++)       if (cnt[i] >= limt && i != mx) solve1(i);     for (int i = 1; i < limt; i++) solve2(i);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[6];     for (int i = 0; i < 6; i++) {       cin >> arr[i];     }     sort(arr, arr + 6);     int tracker[10];     for (int i = 0; i < 10; i++) {       tracker[i] = 0;     }     for (int i = 0; i < 6; i++) {       tracker[arr[i]]++;     }     int legs = -1;     for (int i = 0; i < 10; i++) {       if (tracker[i] >= 4) {         legs = i;         break;       }     }     if (legs != -1) {       int head1 = -1, head2;       int taken[6];       int takenCounter = 0;       for (int i = 0; i < 6; i++) {         taken[i] = 0;       }       for (int i = 0; i < 6; i++) {         if (arr[i] == legs) {           taken[i] = 1;           takenCounter++;         }         if (takenCounter == 4) {           break;         }       }       for (int i = 0; i < 6; i++) {         if (taken[i] == 0) {           if (head1 == -1) {             head1 = arr[i];           } else {             head2 = arr[i];           }         }       }       if (head1 != head2) {         cout <<  Bear ;       } else {         cout <<  Elephant ;       }     } else {       cout <<  Alien ;     }   }
#include <bits/stdc++.h>   using namespace std;   string s;   int n, a, b, ans, nr1, nr0, minD;   int main() {     cin >> n >> a >> b;     cin >> s;     a--;     b--;     minD = (int)1e8;     nr1 = (int)1e8;     nr0 = (int)1e8;     for (int i = 0; i < s.size(); i++) {       if (s[i] == s[a]) {         nr1 = i;         if (abs(nr1 - nr0) < minD) minD = abs(nr1 - nr0);       }       if (s[i] == s[b]) {         nr0 = i;         if (abs(nr0 - nr1) < minD) minD = abs(nr0 - nr1);       }     }     cout << minD;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void minn(T& a, T b) {     if (a > b) a = b;   }   template <class T>   void maxx(T& a, T b) {     if (a < b) a = b;   }   void debug() { return; }   template <class H, class... T>   void debug(H a, T... b) {     cerr << a;     debug(b...);   }   void is() { return; }   template <class H, class... T>   void is(H& a, T&... b) {     cin >> a;     is(b...);   }   void os() { return; }   template <class H, class... T>   void os(H a, T... b) {     cout << a;     os(b...);   }   const int mod = 1e9 + 7;   const int N = 2e5 + 5;   int n, q;   int nx[N], pr[N], nx100[N];   void sw(int x, int y) {     swap(nx[x], nx[y]);     pr[nx[x]] = x;     pr[nx[y]] = y;     int k = x;     for (int i = 1; i <= 100; i++) k = pr[k];     for (int i = 1; i <= 105; i++) {       nx100[k] = x;       x = nx[x];       k = nx[k];     }     k = y;     for (int i = 1; i <= 100; i++) k = pr[k];     for (int i = 1; i <= 105; i++) {       nx100[k] = y;       y = nx[y];       k = nx[k];     }   }   void solve() {     is(n, q);     for (int i = 1; i <= n; i++) {       is(nx[i]);       pr[nx[i]] = i;     }     for (int i = 1; i <= n; i++) {       int k = i;       for (int j = 1; j <= 100; j++) {         k = nx[k];       }       nx100[i] = k;     }     while (q--) {       int t, x, y;       is(t, x, y);       if (t == 2) {         int k = x;         while (y >= 100) {           y -= 100;           k = nx100[k];         }         while (y--) k = nx[k];         os(k,   n );       } else {         sw(x, y);       }     }   }   signed main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int T = 1;     while (T--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int mod = 1e9 + 7;   int n, m, a[N], t[N], r[N], second[N];   pair<int, int> T[2][N * 4];   pair<int, int> get_max(int l, int r, int v = 1, int tl = 1, int tr = n) {     if (tl > r || tr < l) return make_pair(-mod, 0);     if (l <= tl && tr <= r) return T[0][v];     int tm = (tl + tr) / 2;     return max(get_max(l, r, v * 2, tl, tm),                get_max(l, r, v * 2 + 1, tm + 1, tr));   }   pair<int, int> get_min(int l, int r, int v = 1, int tl = 1, int tr = n) {     if (tl > r || tr < l) return make_pair(mod, 0);     if (l <= tl && tr <= r) return T[1][v];     int tm = (tl + tr) / 2;     return min(get_min(l, r, v * 2, tl, tm),                get_min(l, r, v * 2 + 1, tm + 1, tr));   }   void upd(int p, int v = 1, int tl = 1, int tr = n) {     if (tl == tr) {       T[0][v] = T[1][v] = make_pair(a[p], p);       return;     }     int tm = (tl + tr) / 2;     if (p <= tm)       upd(p, v * 2, tl, tm);     else       upd(p, v * 2 + 1, tm + 1, tr);     T[0][v] = max(T[0][v * 2], T[0][v * 2 + 1]);     T[1][v] = min(T[1][v * 2], T[1][v * 2 + 1]);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];       upd(i);     }     for (int i = 1; i <= m; i++) cin >> t[i] >> r[i];     for (int i = m; i; i--) second[i] = max(second[i + 1], r[i]);     for (int i = 1; i <= m; i++) {       if (r[i] > second[i + 1]) {         if (t[i] == 1) {           for (int j = r[i]; j > second[i + 1]; j--) {             pair<int, int> x = get_max(1, j);             swap(a[x.second], a[j]);             upd(x.second);             upd(j);           }         } else {           for (int j = r[i]; j > second[i + 1]; j--) {             pair<int, int> x = get_min(1, j);             swap(a[x.second], a[j]);             upd(x.second);             upd(j);           }         }       }     }     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e6 + 3;   const int INFI = 1e9 * 2;   const long long LINFI = 1e17;   const double pi = acos(-1.0);   const int N = 111;   const int M = 222222;   const int move[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1};   int a[N][N];   int main() {     int n, m;     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) scanf( %d , &a[i][j]);       if (n == 1)         printf( %d n , 0);       else {         for (int i = 0; i < n; i++) {           m = 0;           for (int j = 0; j < n; j++)             if (i != j) m |= a[i][j];           printf( %d  , m);         }         printf(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const long long inff = 0x3f3f3f3f3f3f3f3f;   const int N = 5e2 + 8;   int n, kk, a[N], dp[2][N][N];   int main() {     cin.tie(0);     cout.tie(0);     cin >> n >> kk;     int qw = 0;     dp[qw ^ 1][0][0] = 1;     for (int i(1); i <= (n); ++i) {       scanf( %d , &a[i]);       for (int j(0); j <= (kk); ++j)         for (int k(0); k <= (kk); ++k) dp[qw][j][k] = dp[qw ^ 1][j][k];       for (int j(kk); j >= (a[i]); --j)         for (int k(kk); k >= (0); --k)           dp[qw][j][k] = max(dp[qw][j][k], dp[qw ^ 1][j - a[i]][k]);       for (int j(kk); j >= (a[i]); --j)         for (int k(kk); k >= (0); --k)           dp[qw][k][j] = max(dp[qw][k][j], dp[qw ^ 1][k][j - a[i]]);       qw ^= 1;     }     qw ^= 1;     int num = 0;     for (int i(0); i <= (kk); ++i)       if (dp[qw][i][kk - i]) num++;     cout << num << endl;     for (int i(0); i <= (kk); ++i)       if (dp[qw][i][kk - i]) printf( %d  , i);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s1, s2, s3;   int win(string s1, string s2) {     if (s1 ==  rock ) {       if (s2 ==  rock ) return 0;       if (s2 ==  scissors ) return 1;       if (s2 ==  paper ) return 2;     }     if (s1 ==  paper ) {       if (s2 ==  rock ) return 1;       if (s2 ==  scissors ) return 2;       if (s2 ==  paper ) return 0;     }     if (s1 ==  scissors ) {       if (s2 ==  rock ) return 2;       if (s2 ==  scissors ) return 0;       if (s2 ==  paper ) return 1;     }   }   int main() {     cin >> s1 >> s2 >> s3;     if (win(s1, s2) == 1 && win(s1, s3) == 1) {       cout <<  F ;       return 0;     }     if (win(s2, s1) == 1 && win(s2, s3) == 1) {       cout <<  M ;       return 0;     }     if (win(s3, s1) == 1 && win(s3, s2) == 1) {       cout <<  S ;       return 0;     }     cout <<  ? ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[101];     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     int i = 1;     while (a[i] == a[i - 1] && i < n) i++;     if (i == n)       printf( NO n );     else       printf( %d n , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace placeholders;   template <class T>   void mini(T &l, T r) {     l = min(l, r);   }   template <class T>   void maxi(T &l, T r) {     l = max(l, r);   }   template <class TH>   void _dbg(const char *sdbg, TH h) {     cerr << sdbg <<  =  << h <<   n ;   }   template <class TH, class... TA>   void _dbg(const char *sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, a...);   }   template <class T>   ostream &operator<<(ostream &os, vector<T> v) {     os <<  [ ;     for (auto vv : v) os << vv <<  , ;     return os <<  ] ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   using llint = long long;   const int B = 1e9 + 7;   int a[40][40];   llint mem[40], cnt[40];   void add(llint &a, llint b) {     a = (a + b) % B;     if (a < 0) a += B;   }   void init() {     mem[0] = 1;     cnt[0] = 1;     for (int i = 1; i < 40; ++i) {       int c = 1 << (i - 1);       cnt[i] = cnt[i - 1] * 4 % B;       add(mem[i], mem[i - 1] * 4 % B + 1ll * c * c % B * c % B * 2 % B);     }   }   llint calc(llint a, llint b) {     a %= B, b %= B;     return ((a + b) * (b - a + 1) / 2) % B;   }   pair<llint, llint> get(int x, int y, int k, int d) {     llint ret = 0;     int sz = 1 << d;     if (x < y) swap(x, y);     if (x <= 0 || y <= 0 || k <= 0) return make_pair(0, 0);     if (x >= sz) {       llint a = min(k, sz);       llint b = min(y, sz);       ret = calc(1, a) * b % B;       ;       return make_pair(b * calc(1, a) % B, b * a % B);     }     if (d == 0) return make_pair(1 <= k, 1 <= k);     int t = 1 << (d - 1);     auto t1 = get(x, y, k, d - 1);     auto t2 = get(x - t, y, k - t, d - 1);     auto t3 = get(y, y - t, k - t, d - 1);     auto t4 = get(x - t, y - t, k, d - 1);     ;     add(ret, t1.first);     add(ret, t2.first + t2.second * t % B);     add(ret, t3.first + t3.second * t % B);     add(ret, t4.first);     llint c = 0;     add(c, t1.second);     add(c, t2.second);     add(c, t3.second);     add(c, t4.second);     ;     return make_pair(ret, c);   }   llint go(int x1, int y1, int x2, int y2, int k) {     llint ret = 0;     add(ret, get(x2, y2, k, 30).first);     add(ret, -get(x1 - 1, y2, k, 30).first);     add(ret, -get(x2, y1 - 1, k, 30).first);     add(ret, get(x1 - 1, y1 - 1, k, 30).first);     return ret;   }   void run() {     init();     ;     int q;     scanf( %d , &q);     for (int i = 1; i <= q; ++i) {       int x1, y1, x2, y2, k;       scanf( %d%d%d%d%d , &x1, &y1, &x2, &y2, &k);       printf( %lld n , go(x1, y1, x2, y2, k));     }   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long up = 2e5 + 5;   pair<int, int> pt[2005];   inline bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     if (a.first == b.first) return a.second < b.second;     return a.first < b.first;   }   long long fac[up], inv[up], facinv[up], facinv2[up];   long long pow_mod(long long a, long long k) {     long long res = 1;     while (k) {       if (k & 1) res = (res * a) % mod;       a = (a * a) % mod;       k >>= 1;     }     return res;   }   void init() {     fac[0] = fac[1] = 1;     for (long long i = 2; i < up; ++i) fac[i] = fac[i - 1] * i % mod;     inv[1] = 1, facinv[0] = facinv[1] = 1;     facinv2[0] = facinv2[1] = 1;     for (long long i = 2; i < up; ++i) {       long long t = mod / i, k = mod % i;       inv[i] = i * t * t % mod * inv[k] % mod * inv[k] % mod;       facinv[i] = facinv[i - 1] * inv[i] % mod;     }   }   long long C(long long n, long long m) {     return fac[n] * facinv[n - m] % mod * facinv[m] % mod;   }   long long ans[2005];   int main() {     init();     int h, w, k;     cin >> h >> w >> k;     for (long long i = 0; i < k; ++i) cin >> pt[i].first >> pt[i].second;     pt[k].first = h, pt[k].second = w;     ++k;     sort(pt, pt + k, cmp);     for (long long i = 0; i < k; ++i) {       ans[i] = C(pt[i].first + pt[i].second - 2, pt[i].first - 1);       for (long long j = 0; j < i; ++j) {         ans[i] -= ans[j] *                   C(pt[i].first - pt[j].first + pt[i].second - pt[j].second,                     pt[i].first - pt[j].first) %                   mod;         ans[i] = (ans[i] + mod) % mod;       }     }     cout << ans[k - 1] << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int big = ((long long int)1 << 30);   const long long int mod = 1000000007;   int main(void) {     int n, m, ans = 0, i, q, w, gen = 0;     vector<int> kaz;     vector<bool> uma;     scanf( %d %d , &n, &m);     m--;     kaz.resize(n);     uma.resize(n + 1);     for (i = 0; i < n; i++) {       scanf( %d , &q);       if (i == m && q != 0) {         ans++;         q = 0;       }       if (i != m && q == 0) {         q = n;       }       kaz[i] = q;       uma[q] = 1;     }     sort(kaz.begin(), kaz.end());     while (-1) {       for (; gen <= n; gen++) {         if (uma[gen] == 0) {           break;         }       }       if (kaz.back() <= gen) {         break;       }       ans++;       kaz.pop_back();       uma[gen] = 1;     }     printf( %d n , ans);     return 0;   }