malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   inline int dist(int a, int b, int d) {     assert(a % d && b % d);     if (a >= 0)       a /= d;     else       a = a / d - 1;     if (b >= 0)       b /= d;     else       b = b / d - 1;     return abs(a - b);   }   int main() {     int a, b, x1, y1, x2, y2;     scanf( %d%d%d%d%d%d , &a, &b, &x1, &y1, &x2, &y2);     printf( %d n ,            ((dist(x1 + y1, x2 + y2, 2 * a)) > (dist(x1 - y1, x2 - y2, 2 * b))                 ? (dist(x1 + y1, x2 + y2, 2 * a))                 : (dist(x1 - y1, x2 - y2, 2 * b))));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pll = pair<ll, ll>;   using dd = long double;   namespace {   static bool constexpr dbg = 0;   ll constexpr N = -1;   ll n, a, b, c;   void init() { cin >> n >> a >> b >> c; }   void solve() {     if (n == 1)       cout << 0;     else if (n == 2)       cout << min(a, b);     else       cout << (min(a, b) + (n - 2) * min({a, b, c}));   }   }  // namespace   int main() {     if (!dbg) {       std::ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     }     cout << fixed << setprecision(20);     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long P[200020];   long long n, m;   long long Mod = 998244353;   long long Power(long long a, long long b) {     if (b < 1) return 1;     long long Tmp = Power(a, b / 2);     Tmp = Tmp * Tmp % Mod;     if (b & 1) Tmp = Tmp * a % Mod;     return Tmp;   }   long long inv(long long a) { return Power(a, Mod - 2); }   long long C(long long a, long long b) {     if (b < 0 || a < 0 || a - b < 0) return 0;     return P[a] * inv(P[a - b] * P[b] % Mod) % Mod;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> n >> m;     P[0] = 1;     for (int i = 1; i < 200020; i++) P[i] = i * P[i - 1] % Mod;     long long Ans = C(m, n - 1) * (n - 2) % Mod * Power(2, n - 3) % Mod;     cout << Ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100100], id[100100], t, Ans, ans[100100], n, i, vis[100100], j, k;   int flag;   vector<int> vec[100100];   bool cmp(int u, int v) { return a[u] < a[v]; }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       id[i] = i;     }     sort(id + 1, id + 1 + n, cmp);     vec[1].push_back(1);     if (n > 1) vec[1].push_back(n);     vis[1] = vis[n] = vis[0] = vis[n + 1] = 1;     ;     j = 1;     while (a[id[j]] == 1) {       if (vis[id[j]] == 0) {         vec[1].push_back(id[j]);         vis[id[j]] = 1;       }       j++;     }     for (i = 2; i <= n; i++) {       flag = 0;       while (a[id[j]] == i) {         if (vis[id[j]] == 0) {           vec[i].push_back(id[j]);           vis[id[j]] = 1;           flag = 1;         }         j++;       }       for (k = 0; k < vec[i - 1].size(); k++) {         t = vec[i - 1][k];         if (vis[t - 1] == 0) {           vis[t - 1] = 1;           vec[i].push_back(t - 1);           flag = 1;         }         if (vis[t + 1] == 0) {           vis[t + 1] = 1;           vec[i].push_back(t + 1);           flag = 1;         }       }       if (!flag) break;     }     printf( %d n , i - 1);   }
#include <bits/stdc++.h>   using namespace std;   int dp[5005][5005];   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> s;     memset(dp, -1, sizeof dp);     int ans = 0;     for (int i = 0; i < s.size(); i++) {       int can_rev = 0;       int cur = 0;       for (int j = i; j < s.size(); j++) {         if (cur == 0) ans++;         if (s[j] ==  ( ) {           cur++;         } else if (s[j] ==  ) ) {           cur--;           if (cur < 0) {             if (can_rev == 0) break;             can_rev--;             cur += 2;           }         } else {           if (cur > 0) {             cur--;             can_rev++;           } else {             cur++;           }         }       }       if (cur == 0) ans++;       ans--;     }     cout << ans <<   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 int t, i;     cin >> t;     while (t--) {       long long int n, x, tt = 0;       vector<pair<long long int, long long int>> v, v1;       multimap<long long int, long long int> m, u;       multiset<long long int> s;       cin >> n;       for (long long int i = 0; i < n; i++) {         cin >> x;         v.push_back({x, i});         m.insert({x, i});       }       long long int c = 0, a, b, min = INT_MAX, j, k;       if (n < 2) {         cout <<  -1  <<   n ;         continue;       } else {         sort((v).begin(), (v).end());         for (long long int j = 0; j < v.size() - 1; j++) {           if (v[j].first != v[j + 1].first)             continue;           else {             tt = 1;             for (long long int k = j + 1; k < v.size(); k++) {               if (v[j].first == v[k].first)                 c = v[k].second - v[j].second;               else                 break;               if (c == 1) {                 min = c;                 break;               } else if (c < min)                 min = c;             }           }         }         if (tt == 0)           cout <<  -1  <<   n ;         else           cout << min + 1 <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 10;   const long long inf = 1e15;   const int mod = 1e6;   void faster() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   const long long N = 3e5 + 10;   int n, m;   string s;   pair<long long, long long> p[N];   long long prefix[N];   int main() {     faster();     int n;     cin >> n;     prefix[0] = 1;     for (int i = 0; i < n; i++) {       cin >> p[i].first >> p[i].second;     }     sort(p, p + n);     long long mini = p[0].first;     long long maxi = prefix[0];     for (int i = 1; i < n; i++) {       if (p[i].first - p[i].second >= mini) {         auto q = lower_bound(p, p + i, make_pair(p[i].first - p[i].second, 0ll));         q--;         int ind = q - p;         prefix[i] = prefix[ind] + 1;       } else         prefix[i] = 1;       maxi = max(maxi, prefix[i]);     }     cout << n - maxi << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     long long n;     cin >> n;     long long nmax = 9999999999;     while ((nmax / 2) >= n) nmax /= 10;     int inc = nmax + 1;     long long ans = 0;     if (nmax == 0) {       ans = (n * (n - 1)) / 2;       cout << ans << endl;       return 0;     }     while (n >= (nmax / 2)) {       cerr <<  ans             <<   is   << ans << endl;       ;       if (n >= nmax)         ans += (nmax / 2);       else         ans += n - (nmax / 2);       nmax += inc;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   char a[99];   char b[99];   int n;   int c, d;   int get(char p, char q, char r, char s) {     if (p == r) return 0;     if (p ==  ( ) {       if (r ==  [ ) return -1;       return 1;     } else if (p ==  [ ) {       if (r ==  ( ) return 1;       return -1;     } else {       if (r ==  ( ) return -1;       return 1;     }   }   int main() {     int i, j;     scanf( %s %s , a, b);     n = strlen(a);     for (i = 0; i < n; i += 2) {       j = get(a[i], a[i + 1], b[i], b[i + 1]);       if (j == 1)         c++;       else if (j == -1)         c--;     }     if (c == 0)       printf( TIE n );     else if (c > 0)       printf( TEAM 1 WINS n );     else       printf( TEAM 2 WINS n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int x = 0;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string statement;       cin >> statement;       if (statement.find( + ) != std::string::npos) {         x += 1;       } else {         x -= 1;       }     }     cout << x << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, h, i, j, t, m, l, r, q;     long long p = 0, k, w, z, x, y, d;     string s =   , st =   , s1 =   , s2 =   ;     q = 1;     for (l = 0; l < q; l++) {       int x1, y1, x2, y2;       std::cin >> x1 >> y1 >> x2 >> y2 >> x >> y;       p = x2 - x1;       h = y2 - y1;       z = 0;       if (p % x == 0 && h % y == 0) {         if (p / x == h / y)           z = 1;         else {           p = p / x;           h = h / y;           d = abs(p - h);           if (d % 2 == 0) z = 1;         }       }       if (z == 0)         std::cout <<  NO  << std::endl;       else         std::cout <<  YES  << std::endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[101][2];   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     ;     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     if (v[0] == 1) dp[0][0] = 0, dp[0][1] = 1;     if (v[0] == 2) dp[0][0] = 1, dp[0][1] = 0;     if (v[0] == 3) dp[0][0] = 1, dp[0][1] = 1;     for (int i = 1; i < n; i++) {       if (v[i] == 0) {         dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);         dp[i][1] = dp[i][0];       }       if (v[i] == 1) {         dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);         dp[i][1] = dp[i - 1][0] + 1;       }       if (v[i] == 2) {         dp[i][0] = dp[i - 1][1] + 1;         dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]);       }       if (v[i] == 3) {         dp[i][0] = dp[i - 1][1] + 1;         dp[i][1] = dp[i - 1][0] + 1;       }     }     cout << n - max(dp[n - 1][0], dp[n - 1][1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1E9;   const long long LINF = (long long)1E18;   int INP, AM;   char BUF[(1 << 10) + 1], *inp = BUF;   template <typename T>   T gcd(T a, T b) {     return (b == 0) ? abs(a) : gcd(b, a % b);   }   template <typename T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   const char DEBUG_PARAM[] =  __LOCAL_TESTING ;   const char IN[] =  input.txt ;   const char OUT[] =  output.txt ;   int ntest = 0, test;   inline void init();   inline void run();   inline void stop() { ntest = test - 1; }   int main(int argc, char* argv[]) {     if (argc > 1 && strcmp(argv[1], DEBUG_PARAM) == 0) {       freopen(IN,  r , stdin);     }     init();     if (ntest == 0) {       puts( ntest = ? );       return 0;     }     for (test = 1; test <= ntest; test++) {       run();     }     return 0;   }   const int dx[] = {-1, 0, 0, 1};   const int dy[] = {0, -1, 1, 0};   const long double EPS = 1E-9;   const long long MODULO = 1000000007LL;   inline void init() { ntest = 1; }   const int maxn = 100000 + 5;   pair<int, int> p[maxn];   int n;   vector<int> X, Y;   int sumX, sumY;   void solve() {     int limit = ceil((double)n / 2);     for (int i = (n); i >= (1); i--) {       if (((int)(X).size()) == limit) {         Y.push_back(p[i].second);         sumY += p[i].first;       } else if (((int)(Y).size()) == limit) {         X.push_back(p[i].second);         sumX += p[i].first;       } else {         if (sumX < sumY) {           X.push_back(p[i].second);           sumX += p[i].first;         } else {           Y.push_back(p[i].second);           sumY += p[i].first;         }       }     }     cout << ((int)(X).size()) << endl;     for (int i = 0; i < (((int)(X).size())); i++) {       cout << X[i];       if (i != ((int)(X).size()) - 1) cout <<    ;     }     cout << endl;     cout << ((int)(Y).size()) << endl;     for (int i = 0; i < (((int)(Y).size())); i++) {       cout << Y[i];       if (i != ((int)(Y).size()) - 1) cout <<    ;     }   }   inline void run() {     cin >> n;     for (int i = (1); i <= (n); i++) {       cin >> p[i].first;       p[i].second = i;     }     sort(p + 1, p + 1 + n);     solve();   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   template <typename... Args>   void writeln(Args... args) {     ((cout << args <<    ), ...);     cout << endl;   }   template <typename... Args>   void _db(Args... args) {     ((cerr << args <<   ;;  ), ...);     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<pair<ll, ll>> v(n);     for (int i = 0; i < n; ++i) {       cin >> v[i].first >> v[i].second;     }     sort(v.begin(), v.end(), [](const pair<ll, ll>& f, const pair<ll, ll>& s) {       return abs(f.first) + abs(f.second) < abs(s.first) + abs(s.second);     });     int count = n * 2;     for (auto [x, y] : v) {       if (x != 0) {         count += 2;       }       if (y != 0) {         count += 2;       }     }     cout << count << endl;     for (auto [x, y] : v) {       if (x != 0) {         char dir = x > 0 ?  R  :  L ;         cout << 1 <<     << abs(x) <<     << dir <<   n ;       }       if (y != 0) {         char dir = y > 0 ?  U  :  D ;         cout << 1 <<     << abs(y) <<     << dir <<   n ;       }       cout << 2 <<   n ;       if (x != 0) {         char dir = x > 0 ?  L  :  R ;         cout << 1 <<     << abs(x) <<     << dir <<   n ;       }       if (y != 0) {         char dir = y > 0 ?  D  :  U ;         cout << 1 <<     << abs(y) <<     << dir <<   n ;       }       cout << 3 <<   n ;     }     flush(cout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6 + 5;   const long long MAXM = 4e7 + 5;   const int MOD = 998244353;   long long n, m, p;   struct node1 {     long long x, c;   } a[MAXN], b[MAXN];   struct node2 {     long long x, y, z;   } c[MAXN];   struct node {     long long l, r, val, mark;   } t[MAXN << 2];   void build(long long rt, long long l, long long r) {     t[rt].l = l, t[rt].r = r;     t[rt].mark = 0;     if (l == r) {       t[rt].val = -b[l].c;       return;     }     long long mid = (t[rt].l + t[rt].r) >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     t[rt].val = max(t[rt << 1].val, t[rt << 1 | 1].val);   }   void spread(long long rt) {     t[rt << 1].val += t[rt].mark;     t[rt << 1 | 1].val += t[rt].mark;     t[rt << 1].mark += t[rt].mark;     t[rt << 1 | 1].mark += t[rt].mark;     t[rt].mark = 0;   }   void update(long long rt, long long l, long long r, long long val) {     if (l > r) return;     if (t[rt].l >= l && t[rt].r <= r) {       t[rt].val += val;       t[rt].mark += val;       return;     }     spread(rt);     long long mid = (t[rt].l + t[rt].r) >> 1;     if (l <= mid) update(rt << 1, l, r, val);     if (r > mid) update(rt << 1 | 1, l, r, val);     t[rt].val = max(t[rt << 1].val, t[rt << 1 | 1].val);   }   bool cmp(node1 a, node1 b) { return a.x < b.x; }   bool cmp1(node2 a, node2 b) { return a.x < b.x; }   long long q[MAXN];   int main() {     while (~scanf( %I64d%I64d%I64d , &n, &m, &p)) {       for (long long i = 1; i <= n; i++) scanf( %I64d%I64d , &a[i].x, &a[i].c);       for (long long i = 1; i <= m; i++) scanf( %I64d%I64d , &b[i].x, &b[i].c);       sort(a + 1, a + n + 1, cmp);       sort(b + 1, b + m + 1, cmp);       for (long long i = 1; i <= m; i++) q[i] = b[i].x;       build(1, 1, m);       for (long long i = 1; i <= p; i++) {         scanf( %I64d%I64d%I64d , &c[i].x, &c[i].y, &c[i].z);       }       sort(c + 1, c + p + 1, cmp1);       long long pos = 1;       long long ans = -1ll << 62;       for (long long i = 1; i <= n; i++) {         while (pos <= p && c[pos].x < a[i].x) {           long long pp = upper_bound(q + 1, q + m + 1, c[pos].y) - q;           update(1, pp, m, c[pos].z);           pos++;         }         ans = max(ans, (long long)t[1].val - a[i].c);       }       printf( %I64d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c, x, y;     string s;     cin >> r >> c >> x >> y;     cin >> s;     vector<int> visited(r * c + 1, 0);     cout <<  1  ;     int t, n = s.size();     visited[c * (x - 1) + y] = 1;     for (int i = 0; i < n - 1; i++) {       if (s[i] ==  U  && (x - 1 >= 1 && x - 1 <= r)) {         x -= 1;         t = c * (x - 1) + y;         if (visited[t])           cout <<  0  ;         else {           visited[t] = 1;           cout <<  1  ;         }       } else if (s[i] ==  U )         cout <<  0  ;       else if (s[i] ==  D  && (x + 1 >= 1 && x + 1 <= r)) {         x += 1;         t = c * (x - 1) + y;         if (visited[t])           cout <<  0  ;         else {           visited[t] = 1;           cout <<  1  ;         }       } else if (s[i] ==  D )         cout <<  0  ;       else if (s[i] ==  L  && (y - 1 >= 1 && y - 1 <= c)) {         y -= 1;         t = c * (x - 1) + y;         if (visited[t])           cout <<  0  ;         else {           visited[t] = 1;           cout <<  1  ;         }       } else if (s[i] ==  L )         cout <<  0  ;       else if (s[i] ==  R  && (y + 1 >= 1 && y + 1 <= c)) {         y += 1;         t = c * (x - 1) + y;         if (visited[t])           cout <<  0  ;         else {           visited[t] = 1;           cout <<  1  ;         }       } else         cout <<  0  ;     }     t = 0;     for (int i = 1; i <= r * c; i++) {       if (visited[i] == 1) t++;     }     cout << r * c - t;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x, xxxxx = 0;   string s, word;   long long indx = 0, lmt;   string v[100009], out =   ;   bool f_int = false;   bool ok() {     if (indx > lmt) return xxxxx = 1, false;     bool o1, o2;     o1 = o2 = false;     if (v[indx] ==  int  and indx != 1) {       out +=  int ;       f_int = true;       return true;     }     ++indx;     out +=  pair< ;     o1 = ok();     ++indx;     out +=  , ;     o2 = ok();     if (!o2) xxxxx = 1, out +=  XXX ;     out +=  > ;     return true;   }   int main() {     cin >> x;     getchar();     getline(cin, s);     stringstream ss(s);     while (ss >> word) {       v[++indx] = word;     }     if (indx == 1) {       if (v[1] ==  int )         cout <<  int ;       else         cout <<  Error occurred ;       return 0;     }     lmt = indx;     indx = 1;     ok();     if (xxxxx || !f_int || indx != lmt)       cout <<  Error occurred ;     else       cout << out;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 5000;   const int MAXN = 200, MAXE = 2 * MAXN;   int src, snk, nNode, nEdge;   int Q[MAXN], fin[MAXN], pro[MAXN], dist[MAXN];   int flow[MAXE], cap[MAXE], Next[MAXE], to[MAXE];   inline void init(int _src, int _snk, int _n) {     src = _src, snk = _snk, nNode = _n, nEdge = 0;     memset(fin, -1, sizeof(fin));   }   inline void add(int u, int v, int c) {     to[nEdge] = v, cap[nEdge] = c, flow[nEdge] = 0, Next[nEdge] = fin[u],     fin[u] = nEdge++;     to[nEdge] = u, cap[nEdge] = 0, flow[nEdge] = 0, Next[nEdge] = fin[v],     fin[v] = nEdge++;   }   bool bfs() {     int st, en;     memset(dist, -1, sizeof(dist));     dist[src] = st = en = 0;     Q[en++] = src;     while (st < en) {       int u = Q[st++];       for (int i = fin[u]; i >= 0; i = Next[i]) {         int v = to[i];         if (flow[i] < cap[i] && dist[v] == -1) {           dist[v] = dist[u] + 1;           Q[en++] = v;         }       }     }     return (dist[snk] != -1);   }   int dfs(int u, int fl) {     if (u == snk) return fl;     for (int &e = pro[u]; e >= 0; e = Next[e]) {       int v = to[e];       if (flow[e] < cap[e] && dist[v] == dist[u] + 1) {         int df = dfs(v, min(cap[e] - flow[e], fl));         if (df > 0) {           flow[e] += df;           flow[e ^ 1] -= df;           return df;         }       }     }     return 0;   }   long long dinitz() {     long long ret = 0;     while (bfs()) {       for (int i = 0; i <= nNode; i++) pro[i] = fin[i];       while (true) {         int df = dfs(src, inf);         if (df)           ret += (long long)df;         else           break;       }     }     return ret;   }   int arr[MAXN], x[MAXN], y[MAXN];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     for (int i = 1; i <= m; i++) {       scanf( %d %d , &x[i], &y[i]);       if (x[i] % 2 == 0) swap(x[i], y[i]);     }     set<int> prime;     for (int i = 1; i <= n; i++) {       int nw = arr[i];       for (int p = 2; p * p <= nw; p++) {         int cnt = 0;         while (nw % p == 0) {           ++cnt, nw /= p;         }         if (cnt) prime.insert(p);       }       if (nw > 1) prime.insert(nw);     }     long long tot = 0;     for (set<int>::iterator it = prime.begin(); it != prime.end(); it++) {       int p = *it;       int s = 0, t = n + 1;       init(s, t, n + 2);       for (int i = 1; i <= n; i++) {         int nw = arr[i], cnt = 0;         while (nw % p == 0) ++cnt, nw /= p;         if (cnt) {           if (i % 2 == 1)             add(s, i, cnt);           else             add(i, t, cnt);         }       }       for (int i = 1; i <= m; i++) {         add(x[i], y[i], inf);       }       tot += dinitz();     }     printf( %lld n , tot);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:36777216 )   const int Nmax = 100100;   const int Drection[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};   int h, q;   long long minV[55], maxV[55];   long long leftDown(long long L, int hg) {     if (hg == h) return L;     return leftDown(L << 1ll, hg + 1);   }   long long rightDown(long long R, int hg) {     if (hg == h) return R;     return rightDown((R << 1ll) + 1, hg + 1);   }   inline void end(long long x) {     if (x == 0)       cout <<  Data not sufficient!  << endl;     else if (x == -1)       cout <<  Game cheated!  << endl;     else       cout << x << endl;     exit(0);   }   inline void add(long long x) {     static long long extra = -1;     if (x <= 0) end(extra);     if (extra != -1) end(0);     extra = x;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> h >> q;     minV[1] = maxV[1] = 1;     for (int i = 2; i <= h; i++) {       minV[i] = minV[i - 1] * 2ll;       maxV[i] = maxV[i - 1] * 2ll + 1;     }     vector<pair<long long, long long> > list;     for (int i = 1; i <= q; i++) {       long long lv, L, R, ans;       cin >> lv >> L >> R >> ans;       if (ans == 1) {         if (minV[lv] <= L - 1)           list.push_back(make_pair(leftDown(minV[lv], lv), rightDown(L - 1, lv)));         if (R + 1 <= maxV[lv])           list.push_back(make_pair(leftDown(R + 1, lv), rightDown(maxV[lv], lv)));       } else         list.push_back(make_pair(leftDown(L, lv), rightDown(R, lv)));     }     sort(list.begin(), list.end());     long long L = leftDown(1, 1);     long long R = rightDown(1, 1);     for (int i = 0; i < list.size(); i++) {       if (list[i].first > L) {         add(L++);         i--;         continue;       }       L = max(L, list[i].second + 1);     }     while (L <= R) add(L++);     add(-10);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const int mod = 1e9 + 7;   int n, m;   int c[N][N], fac[N], f[N][N][2][2], dp[N], g[N];   void Init() {     scanf( %d%d , &n, &m);     c[0][0] = 1;     for (int i = 1; i <= n; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++) {         c[i][j] = c[i - 1][j] + c[i - 1][j - 1];         if (c[i][j] >= mod) c[i][j] -= mod;       }     }     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % mod;   }   inline void Add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   int main() {     Init();     f[1][0][1][0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= i; j++) {         for (int a = 0; a < 2; a++) {           for (int b = 0; b < 2; b++) {             int t = f[i][j][a][b];             Add(f[i + 1][j][b][0], t);             Add(f[i + 1][j + 1][b][1], t);             if (a == 0) Add(f[i + 1][j + 1][b][0], t);           }         }       }     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j < 2; j++) {         Add(dp[i], f[n + 1][i][j][0]);       }     }     for (int i = n; i >= 0; i--) {       g[i] = 1LL * dp[i] * fac[n - i] % mod;       for (int j = i + 1; j <= n; j++) {         g[i] -= 1LL * c[j][i] * g[j] % mod;         if (g[i] < 0) g[i] += mod;       }     }     printf( %d n , g[m]);     return 0;   }