akhauriyash/Code-Regression huggingface dataset:
/*  -*- coding: utf-8 -*-
 *
 * b.cc: D: いろはちゃんとマス目 / Iroha and a Grid
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 100000;
const int MAX_W = 100000;
const int MAX_N = MAX_H + MAX_W;

typedef long long ll;
const ll MOD = 1000000007;

/* typedef */

/* global variables */

ll fs[MAX_N], ifs[MAX_N];

/* subroutines */

ll powmod(ll a, int n) {  // a^n % MOD
  ll pm = 1;
  while (n > 0) {
    if (n & 1) pm = (pm * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return pm;
}

inline ll invfs(int n) {
  return (ifs[n] > 0) ? ifs[n] : (ifs[n] = powmod(fs[n], MOD - 2));
}

inline ll nck(int n, int k) {  // nCk % MOD
  return (fs[n] * invfs(n - k) % MOD) * invfs(k) % MOD;
}

/* main */

int main() {
  int h, w, a0, b0;
  cin >> h >> w >> a0 >> b0;

  int n = h + w - 2;
  int a1 = h - a0, b1 = w - b0;

  fs[0] = 1;
  for (int i = 1; i <= n; i++) fs[i] = fs[i - 1] * i % MOD;

  ll sum = 0;
  for (int y = 0; y < a1; y++) {
    sum += nck(b0 - 1 + y, y) * nck(b1 - 1 + h - 1 - y, b1 - 1) % MOD;
    sum %= MOD;
  }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  int N;
  cin >> N;

  vector<int> A(N);
  for(int i=0; i<N;i++){
    cin >> A[i];
  }

  int i1=0;
  int cnt = 0;
  for(int j=0; j<N;j++){
    if(A[j] == i1+1){
      i1++;
    }
    else{
      cnt++;
    }
  }

  if(i1==0){
    cout << -1 << endl;
    return 0;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265359
int main(){
    int A,B; cin>>A>>B;
    if(A>=13){
        cout<<B;
    }
    else if(A<6){
        cout<<0;
    }
    else{
        cout<<B/2;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll cur1 = max(a * c, b * d);
    ll cur2 = max(a * d, b * c);
    cout << max(cur1, cur2) << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3612
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Sorting a Segment
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_E2 = 1 << 19; // = 524288
const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;

template <typename T, const int MAX_E2>
struct SegTreeMinMax {
  int n, e2;
  T mins[MAX_E2], maxs[MAX_E2];
  SegTreeMinMax() {}

  void init(int _n) {
    n = _n;
    for (e2 = 1; e2 < n; e2 <<= 1);
    fill(mins, mins + MAX_E2, INF);
    fill(maxs, maxs + MAX_E2, -INF);
  }

  T &get_min(int i) { return mins[e2 - 1 + i]; }
  T &get_max(int i) { return maxs[e2 - 1 + i]; }
  T &get(int i) { return get_min(i); }
  void set(int i, T v) { get_min(i) = get_max(i) = v; }

  void set_all() {
    for (int j = e2 - 2; j >= 0; j--) {
      int j0 = j * 2 + 1, j1 = j0 + 1;
      mins[j] = min<T>(mins[j0], mins[j1]);
      maxs[j] = max<T>(maxs[j0], maxs[j1]);
    }
  }

  pair<T,T> get_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return pair<T,T>(INF, -INF);
    if (r0 <= i0 && i1 <= r1) return pair<T,T>(mins[k], maxs[k]);

    int im = (i0 + i1) / 2;
    pair<T,T> v0 = get_range(r0, r1, k * 2 + 1, i0, im);
    pair<T,T> v1 = get_range(r0, r1, k * 2 + 2, im, i1);
    return pair<T,T>(min<T>(v0.first, v1.first), max<T>(v0.second, v1.second));
  }
  pair<T,T> get_range(int r0, int r1) { return get_range(r0, r1, 0, 0, e2); }
  T min_range(int r0, int r1) { return get_range(r0, r1).first; }
  T max_range(int r0, int r1) { return get_range(r0, r1).second; }
};

/* global variables */

bool ncs[MAX_N];
SegTreeMinMax<int,MAX_E2> st;

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  st.init(n);

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    st.set(i, ai);
  }
  st.set_all();

  int ncn = 0;
  for (int i = 0; i < n;) {
    int j = i + 1;
    while (j < n && st.get(j - 1) < st.get(j)) j++;
    while (i + k <= j) ncs[i++] = true, ncn++;
    i = j;
  }
  
  int dn = 0;
  for (int i = 0, j = k; j < n; i++, j++)
    if (! ncs[i] && ! ncs[i + 1]) {
      pii v = st.get_range(i, j + 1);
      int &minv = v.first, &maxv = v.second;
      if (st.get_min(i) == minv && st.get_max(j) == maxv) dn++;
    }

  //printf("ncn=%d, dn=%d\n", ncn, dn);
  int cnt = (n - k + 1) - ((ncn > 1) ? ncn - 1 : 0) - dn;
  printf("%d\n", cnt);
  return 0;
}

/*
  in3.txt:
  10 4
  2 0 1 3 7 5 4 6 8 9

  0: 0123754689
  1: 2013754689
  2: 2013574689
  3: 2013457689
  4: 2013456789
  5: 2013745689
  6: 2013754689
 */


Measured memory_bytes: 4480
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

// const ll MOD = (ll)1e9+7;
const ll MAX = (ll)6e3+10;

int main(void) {
   ll H,W,K;
   cin>>H>>W>>K;
   vector<vector<ll>> A;
   A.resize(H);
   rep(i,0,H) A[i].resize(W);
   rep(i,0,H) rep(j,0,W) {
      char s;
      cin>>s;
      if (s=='#') A[i][j] = 1;
   }
   // rep(i,0,H) rep(j,0,W) {
      // cout<<A[i][j]<<endl;
   // }
   vector<ll> B(H,0);
   vector<ll> Bs(H,0);
   rep(i,0,H) rep(j,0,W) B[i] += A[i][j];
   // rep(i,0,H) cout<<B[i]<<endl;
   Bs[0] = B[0];
   rep(i,1,H) Bs[i] += Bs[i-1]+B[i];

   vector<vector<ll>> Ans;
   Ans.resize(H);
   rep(i,0,H) Ans[i].resize(W);
   rep(i,0,H) rep(j,0,W) Ans[i][j] = 0;
   ll now = 1;
   rep(i,0,H) {
      if (B[i]==0) continue;
      rep(j,0,W) {
         Ans[i][j] = now;
         if (A[i][j]==1 && now != Bs[i]) now++;
      }
      now++;
   }
   ll first = H;
   rep(i,0,H) {
      if (B[i]!=0) chmin(first,(ll)i);
   }
   for (int i = first; i>0;i--) {
      rep(j,0,W) {
         Ans[i-1][j] = Ans[i][j];
      }
   }
   rep(i,1,H) {
      if (Ans[i][0]!=0) continue;
      rep(j,0,W) Ans[i][j] = Ans[i-1][j];
   }
   rep(i,0,H) {
      rep(j,0,W) cout<<Ans[i][j]<<" ";
      cout<<endl;
   }


   return 0;
}



Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define  fo(i,n) for(ll i=0;i<n;i++)
#define rfo(i,n) for(ll i=n;i>=0;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
ll mod(ll a)
{
	return a%(1000000007);
}
void solve()
{
	ll n;
	cin>>n;
	vector<ll> A(n);
	fo(i,n)
	{
		cin>>A[i];
	}
	vector<ll> ss(n);
	ss[n-1] = A[n-1];
	for(ll i=n-2;i>=0;i--)
	{
		ss[i] =ss[i+1]+ A[i];
		ss[i] = mod(ss[i]);
	}
	ll ans =0;
	for(ll i = 1;i<n;i++)
	{
		ans = mod(ans)+ mod(A[i-1]*ss[i]);
		ans = mod(ans);
	}
	cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 6304
#include<bits/stdc++.h>
using namespace std;

int rec(int number, int sum, int count){
  if(sum == 0) return(1);
  if(sum - number * number < 0 || count >= 4) return(0);
  return rec( number + 1, sum, count) + rec( number, sum - number * number, count + 1);
}

int main(){
  int n;
  while(cin >> n, n){
    cout << rec( 1, n, 0) << endl;
  }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  rep(i,tx-sx) cout << "R";
  rep(i,ty-sy) cout << "U";
  rep(i,tx-sx) cout << "L";
  rep(i,ty-sy+1) cout << "D";
  rep(i,tx-sx+1) cout << "R";
  rep(i,ty-sy+1) cout << "U";
  cout << "LU";
  rep(i,tx-sx+1) cout << "L";
  rep(i,ty-sy+1) cout << "D";
  cout << "R";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
 
using namespace std;

 
const int INF = (int) 1e9;

struct point {
	int x;
    int y;
	point() : x(0), y(0) {}
};
 
struct fenwick_tree {
	int n;
	unordered_map<int, int> F;
 
    fenwick_tree() : n(INF) {
        F.rehash((int) 2.1e5);
    }
	void upd(int i, int x) {
		for (; i < n; i |= i + 1)
			F[i] = max(F[i], x);
	} 
	int get(int i) {
		int res = 0;
		for (; i >= 0; i &= i + 1, --i)
			res = max(res, F[i]);
		return res;
	}
};
 
 
bool cmp(point a, point b) {
    return make_pair(a.x, a.y) < make_pair(b.x, b.y); 
}
 
 
int main() {
#ifdef NICK
	freopen("input.txt", "r", stdin);
#else

#endif
    point start, finish;
    int n;
    cin >> start.x >> start.y;
    cin >> finish.x >> finish.y;
    cin >> n;
    point p[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y;
    }
    if (start.x > finish.x)
        swap(start, finish);
    if (start.y > finish.y) {
        finish.y = 2 * start.y - finish.y;
        for (int i = 0; i < n; i++) {
            p[i].y = 2 * start.y - p[i].y;
        }
    }
    vector<point> a;
    for (int i = 0; i < n; i++) {
        if (start.x <= p[i].x && p[i].x <= finish.x && start.y <= p[i].y && p[i].y <= finish.y)
            a.emplace_back(p[i]);
    }
    fenwick_tree dp;
    sort(a.begin(), a.end(), cmp);
    for (int i = 0; i < (int)a.size(); ++i)
        dp.upd(a[i].y, dp.get(a[i].y) + 1);
    int cur = dp.get(INF);
    long double ans = 0;
    if (cur != min(finish.y - start.y, finish.x - start.x) + 1)
        ans = 100.0 * (finish.y + finish.x - start.y - start.x) - 20.0 * cur + 5 * M_PI * cur;
    else
        ans = 100.0 * (finish.y + finish.x - start.x - start.y) - 20.0 * cur + 5 * M_PI * (cur - 1) + 10 * M_PI;
    cout << fixed << setprecision(13) << ans << "\n";
	return 0;
}


Measured memory_bytes: 68384
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % 13;
    } else {
        return modpow(m, n - 1) * m % 13;
    }
}
long long power(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = pow(m, n / 2);
        return t * t;
    } else {
        return pow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k) {
    ll denomi = 1;
    for (int i = n; i > n - k; i--) {
        denomi *= i;
        denomi %= mod;
    }
    ll numera = 1;
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}
int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    REP(i, n) { cin >> v[i]; }
    ll ans = 0;
    REP(i, n + 1) {
        REP(j, n + 1) {
            vector<ll> neg;
            ll cur = 0;
            if (i + j <= min(k, n)) {
                REP(l, i) {
                    if (v[l] < 0) {
                        neg.push_back(v[l]);
                    }
                    cur += v[l];
                }
                REP(l, j) {
                    if (v[n - 1 - l] < 0) {
                        neg.push_back(v[n - 1 - l]);
                    }
                    cur += v[n - 1 - l];
                }
                sort(neg.begin(), neg.end());
                REP(l, min(k - i - j, (ll)neg.size())) { cur -= neg[l]; }
                ans = max(ans, cur);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define mp make_pair
typedef long long ll;
using namespace std;

const ll INF = 1e9;
ll R,C,sx,sy,gx,gy,cnt;
char F[1000][1000];
ll d[1000][1000];
typedef pair<ll,ll> P;
queue<P> que;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};


int main(void){
    cin >> R >> C;

    rep(i,R)rep(j,C){
        cin >> F[i][j];
        if(F[i][j] == '.')cnt++;
    }

    sx = 0;sy=0;
    gx = R-1;gy=C-1;
    rep(i,R)rep(j,C)d[i][j] = INF;
    d[sx][sy] = 0; 
    que.push(mp(sx,sy));
    while(!que.empty()){
        P pos = que.front();que.pop();
        ll x = pos.first,y = pos.second;
        if(x == gx && y == gy)break;
        rep(i,4){
            ll nx = x + dx[i],ny = y + dy[i];
            if(0<=nx && nx <R && 0<=ny && ny<C && d[nx][ny] == INF && F[nx][ny] !='#'){
                que.push(mp(nx,ny));
                d[nx][ny] = d[x][y]+1;
            }
        }
    }
    if(d[gx][gy] == INF) cout << -1 << endl;
    else cout << cnt - d[gx][gy] - 1 << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Solution {
 private:
  int c(int n) {
    if (n < 2) return 0;
    return n * (n - 1) / 2;
  }

 public:
  string judgeStatusSummary(const vector<string>& s) {
    int n_AC = 0, n_WA = 0, n_TLE = 0, n_RE = 0;

    for (auto& str : s) {
      if (str == "AC")
        ++n_AC;
      else if (str == "WA")
        ++n_WA;
      else if (str == "TLE")
        ++n_TLE;
      else if (str == "RE")
        ++n_RE;
    }

    string ans;
    ans += "AC x " + to_string(n_AC) + "\n";
    ans += "WA x " + to_string(n_WA) + "\n";
    ans += "TLE x " + to_string(n_TLE) + "\n";
    ans += "RE x " + to_string(n_RE);
    return ans;
  }
};

int main() {
  int n;
  cin >> n;

  vector<string> s(n);
  for (int i = 0; i < n; ++i) cin >> s[i];

  Solution sol;
  const string ans = sol.judgeStatusSummary(s);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;

vector<string>s;

int decide(int x, int y, char s){
    if(s=='-')
        return x-y;
    return x+y;
}

void calculate(){
    string sign = "+++";

    for(int i=1; i<=4; i++){
        do{
            s.push_back(sign);
        }while(next_permutation(sign.begin(), sign.end()));

        for(int j=2, k=0;k<i; k++,j--)
            sign[j] = '-';
    }
}

int main(){
    calculate();
    string num;

    while(cin>>num){
        string ans;
        for(int i=0; i<s.size(); i++){
            int sum = num[0]-'0';

            for(int j=0; j<3; j++){
                sum = decide(sum, num[j+1]-'0', s[i][j]);
            }

            if(sum == 7)
                ans = s[i];
        }

        for(int i=0; i<3; i++)
            printf("%c%c",num[i],ans[i]);
        printf("%c=7\n",num[3]);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

const int MAX = 10000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
    long long x, y; 
    cin >> x >> y;
    long long I=y*2/3-x/3;
    long long J=x*2/3-y/3;
    if((x+y)%3!=0) cout << 0 << endl;
    else if(I<0||J<0) cout<<0<<endl;
    else{
        cout << COM(I+J,I) << endl;
    
    }
}

Measured memory_bytes: 234624
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> a(m);
    rep(i,m) cin >> a.at(i);
    int cost1=0;
    for(int i=x;i<=n;i++){
        rep(j,m){
            if(a.at(j)==i)cost1++;
        }
    }
    int cost2=0;
    for(int i=x;i>=0;i--){
        rep(j,m){
            if(a.at(j)==i)cost2++;
        }
    }
    cout << min(cost1,cost2) << endl;
}

Measured memory_bytes: 256
// AOJ 2039: Space Coconut Crab II
// 2017.11.6 bal4u@uu

#include <stdio.h>
#define TM 0
#if TM
#include <time.h>
#endif

#define MAX  30000
char tbl[MAX+1] = {1,1,0,0};		// zero: if prime
int p[3250] = {						// p[39] = 173 = sqrt(MAX), max sz = 3245
 2,   3,  5,  7, 11, 13, 17, 19, 23, 29, 
 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 
 73, 79, 83, 89, 97,101,103,107,109,113, 
127,131,137,139,149,151,157,163,167,173 }; int sz;

void mkprime()
{
	int i, j, k;
	for (i = 0; i <= 39; i++) {
		k = p[i];
		for (j = k<<1; j < MAX; j += k) tbl[j] = 1;
	}
	for (sz = 39, i = 173; i <= MAX; i += 2) if (!tbl[i]) p[sz++] = i;
}

int bsch(int x)
{
	int m, l = 0, r = sz;

    while (l < r) {
        m = (l + r) >> 1;
		if (p[m] == x) return m;
        if (p[m] < x) l = m + 1; else r = m;
    }
	return l-1;
}

int main()
{
	int t, i, j, k, m, ans;
#if TM
	clock_t start, end;
	start = clock();
#endif
	mkprime();
	while (scanf("%d", &t) && t > 0) {
		if (!(t & 1)) {
			k = (t>>1)-1;
			if (k > 2 && !(k & 1)) putchar('0');
			else                   putchar('1' - tbl[k]);
			putchar('\n');
		} else {
			ans = 0;
			for (i = 0; ; i++) {
				m = bsch((t-p[i]) >> 1);
				if (m < i) break;
				for (j = i; j <= m; j++) {
					k = p[i] + p[j];
					if (t-k < p[j]) break;
					if (k < t && (k<<1) > t && !tbl[t-k]) ans++;
				}
			}
			printf("%d\n", ans);
		}
	}
#if TM
	end = clock();
	printf("time %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 1740
use io::*;
use std::collections::BinaryHeap;
use std::cmp;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let w: usize = sc.next();
    let bs: Vec<Vec<usize>> = sc.next_mat(2, n);
    let mut hs: Vec<BinaryHeap<usize>> = vec![BinaryHeap::new();4];
    let w0 = bs[0][0];
    for b in bs {
        hs[b[0]-w0].push(b[1]);
    }
    let mut its: Vec<Vec<usize>> = hs.iter().map(|h| h.clone().into_sorted_vec()).collect();
    for i in 0..4 {
        its[i].push(0);
        its[i].reverse();
        its[i] = its[i].iter().scan(0, |ac,&x| {*ac += x; Some(*ac)}).collect();
    }
    let mut ans = 0;
    for i in 0..cmp::min(w / w0 + 1, its[0].len()) {
        let wi = w - i * w0;
        for j in 0..cmp::min(wi / (w0+1) + 1, its[1].len()) {
            let wj = wi - j * (w0+1);
            for k in 0..cmp::min(wj / (w0+2) + 1, its[2].len()) {
                let wk = wj - k * (w0+2);
                let l = cmp::min(wk / (w0+3), its[3].len()-1);
                ans = cmp::max(ans,its[0][i]+its[1][j]+its[2][k]+its[3][l]);
            }
        }
    }
    println!("{}",ans);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 4352
// D - Lucky PIN
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; string S; cin>>N>>S;
	int ans = 0;
	for(int i=0; i<1000; i++){
		char c1 = i/100 +'0', c2 = (i%100)/10 +'0', c3 = i%10 +'0';
		int ix;
		for(ix=0; ix<N && S[ix]!=c1; ix++); if(ix==N) continue;
		for(++ix; ix<N && S[ix]!=c2; ix++); if(ix==N) continue;
		for(++ix; ix<N && S[ix]!=c3; ix++); if(ix==N) continue;
		ans++;
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> weight(N);
  vector<int> value(N);
  for (int i = 0; i < N; i++) {
    cin >> weight.at(i) >> value.at(i);
  }
  vector<vector<int>> dp(N + 1, vector<int> (N * 1000 + 1));
  for (int i = 0; i < N + 1; i++) {
    for (int j = 0; j < N * 1000 + 1; j++) {
      dp.at(i).at(j) = 1000000010;
    }
  }
  dp.at(0).at(0) = 0;
  for (int i = 1; i < N + 1; i++) {
    for (int j = 0; j < N * 1000 + 1; j++) {
      if (j - value.at(i - 1) >= 0) {
        dp.at(i).at(j) = min(dp.at(i - 1).at(j),
                         dp.at(i - 1).at(j - value.at(i - 1)) + weight.at(i - 1));
      }
      else dp.at(i).at(j) = min(dp.at(i - 1).at(j), dp.at(i).at(j));
    }
  }
  int result = 0;
  for (int i = 0; i < N * 1000 + 1; i++) {
    if(dp.at(N).at(i) <= W) {
      result = i;
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 43348
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll; //long longをllとして簡略
 
int main(){
  int ans=0;
  int n;
  cin >> n;
  int a[n];

  rep(i,n){
    cin >> a[i];
  }

  rep(i,n){
    if(i+1==a[a[i]-1]){
      ans++;
      a[i]=0;
    }
  }

  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 640
def main():

    n = int(input())
    a = list(map(int,input().split()))


    m = 10**9 + 7
    ans = 0
    s = []
    total = sum(a)
    s.append(total-a[0])
    for i in range(1,n):
        s.append(s[i-1] - a[i])
    for i in range(n):
        tmp = s[i] % m
        ans += tmp * a[i]
    # ans //= 2
    print(ans%m)

if __name__=='__main__':
    main()


Measured memory_bytes: 31276
#include<iostream>
#include<stdio.h>
#include<set>
using namespace std;
int main()
{
     set<int>s;
     int t,n;
     cin>>t;
     while(t--)
     {
         cin>>n;
         if(s.count(n))
         s.erase(n);
         else
         s.insert(n);
     }
         int sum=s.size();
         printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int B[] = new int[N];
		int max =0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			if (A[i]>B[i]) {
				max +=A[i]-B[i];
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int a,b,c;
    cin>>a>>b>>c;
    if((a+b+c)<=21){
        cout<<"win"<<endl;
    }
    else{
        cout<<"bust"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int main() {
  int n;
  int f = 0;
  cin >> n;
  string h;
  vector<string> s;
  for (int i = 0; i < n; i++) {
    cin >> h;
    s.push_back(h);
  }
  sort(s.begin(), s.end());
  for (int j = 0; j < n - 1; j++) {
    if (s[j] != s[j + 1]) f++;
  }
  cout << f + 1;
  return 0;
}

Measured memory_bytes: 11656
#include<bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define verify(x) if(x >= MOD) x -= MOD;

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void print_case(int tn) {cout<<"Case #"<<tn<<": ";}

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;
/*----------------------------------------------------------------------*/

ll mk;

bool cnt(int target, vi& arr) {
    int n = arr.size(); 
    ll res = 0;
    FOR(i, 0, n) {
        int lo = 0, hi = n - 1, r = -1;
        while(lo <= hi) {
            int mid = (lo + hi) >> 1;
            if(arr[i] + arr[mid] >= target) {
                r = max(r, mid);
                lo = mid + 1;
            } else hi = mid - 1;
        }

        if(r >= 0) {
            res += (r + 1);
        }
    }
    return (res >= mk);
}

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n;cin>>n>>mk;
    vi arr(n);
    FOR(i, 0, n) cin>>arr[i];
    sort(all(arr), greater<int>());
    int lo = arr[n - 1] + arr[n - 1], hi = arr[0] + arr[0];
    int m = 0;
    while(lo <= hi) {
        int mid = (lo + hi) >> 1;
        if(cnt(mid, arr)) {
            m = max(mid, m);
            lo = mid + 1;
        } else hi = mid - 1;
    }
    // deb(m);
    ll res = 0; ll counter = 0;
    vll cumsum(n, 0);
    FOR(i, 0, n) {
        cumsum[i] = ((i) ? cumsum[i - 1] : 0) + 1LL * arr[i];
    }
    FOR(l, 0, n) {
        int lo = 0, hi = n - 1, r = -1;
        while(lo <= hi) {
            int mid = (lo + hi) >> 1;
            if(arr[l] + arr[mid] >= (m + 1)) {
                r = max(r, mid);
                lo = mid + 1;
            } else hi = mid - 1;
        }

        if(r >= 0) {
            counter += (r + 1);
            res += 1LL * cumsum[r] + (r + 1) * 1LL * arr[l];
        }
    }
    // deb(counter);
    assert(counter <= mk);
    res += (mk - counter) * 1LL * m;
    cout << res;
    return 0;
}

Measured memory_bytes: 4520
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>

using namespace std;
#define REP(m,n) for(int i=m;i<n;++i)
#define REPj(m,n) for(int j=m;j<n;++j)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair

int main() {
	string s;
	cin >> s;
	s.erase(s.begin() + s.size() - 8, s.begin() + s.size());
	cout << s << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,m;
    double a[11],max=0,k=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lf",&a[i]);
    }
    for(i=0;i<n;i++)
    if(max<a[i]) max=a[i],m=i;
    max=max/2;
    for(i=0;i<n;i++)
        k+=a[i];
    printf("%.0lf",k-max);
    return 0;
}


Measured memory_bytes: 128
N = gets.to_i
M = 2**N - 1
全証言 = N.times.map{|i|
	gets.to_i.times.inject(1<<i){|b,|
		x, y = gets.split.map(&:to_i)
		next b | ((1-y)<<(N+x-1)) | (y<<(x-1))
	}
}
F = lambda{|b|
	c = 全証言.map.with_index{|証言,i| b[i]==1 ? 証言 : 0 }.inject(b, :|)
	next c if (b^c)&M == 0
	next F[c]
}
全証言.map!(&F)
p N.downto(0).find{|i|
	全証言.combination(i).any?{|c|
		c = c.inject(0, :|)
		next (c>>N)&c&M == 0
	}
}


Measured memory_bytes: 3836
#include<stdio.h>
int main(void){
  int a=0,b=0,s=0,syu=0;
  scanf("%d",&a);
  scanf("%d",&b);
  s=a*b;
  syu=2*a+2*b;
  printf("%d %d\n",s,syu);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;

void bubbleSort(vector<tuple<string, int>>& C, int N) {
  for (int i = 0; i < N - 1; i++) {
    for (int j = N - 1; j > i; j--) {
      if (get<1>(C.at(j)) < get<1>(C.at(j - 1))) {
        swap(C.at(j), C.at(j - 1));
      }
    }
  }
}

void selectionSort(vector<tuple<string, int>>& C, int N) {
  for (int i = 0; i < N - 1; i++) {
    int minJ = i;
    for (int j = i + 1; j < N; j++)
      if (get<1>(C.at(j)) < get<1>(C.at(minJ))) minJ = j;
    swap(C.at(i), C.at(minJ));
  }
}

bool isStable(vector<tuple<string, int>> original,
              vector<tuple<string, int>> sorted, int N) {
  for (int i = 1; i < 10; i++) {
    vector<char> types;
    for (auto o : original) {
      if (get<1>(o) == i) types.push_back(get<0>(o).at(0));
    }
    int j = 0;
    for (auto s : sorted) {
      if (get<1>(s) == i) {
        char type = get<0>(s).at(0);
        if (type != types.at(j)) return false;
        j++;
      }
    }
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int>> C(N);
  for (int i = 0; i < N; i++) {
    string card;
    cin >> card;
    C.at(i) = make_tuple(card.at(0), atoi(&card.at(1)));
  }

  vector<tuple<string, int>> bubbleSorted(N);
  copy(C.begin(), C.end(), bubbleSorted.begin());
  vector<tuple<string, int>> selectionSorted(N);
  copy(C.begin(), C.end(), selectionSorted.begin());

  bubbleSort(bubbleSorted, N);
  selectionSort(selectionSorted, N);

  cout << get<0>(bubbleSorted.at(0)) << get<1>(bubbleSorted.at(0));
  for (int i = 1; i < N; i++)
    cout << ' ' << get<0>(bubbleSorted.at(i)) << get<1>(bubbleSorted.at(i));
  cout << endl;
  if (isStable(C, bubbleSorted, N))
    cout << "Stable" << endl;
  else
    cout << "Not stable" << endl;

  cout << get<0>(selectionSorted.at(0)) << get<1>(selectionSorted.at(0));
  for (int i = 1; i < N; i++)
    cout << ' ' << get<0>(selectionSorted.at(i))
         << get<1>(selectionSorted.at(i));
  cout << endl;
  if (isStable(C, selectionSorted, N))
    cout << "Stable" << endl;
  else
    cout << "Not stable" << endl;
}



Measured memory_bytes: 3236
N = int(input())
edge = [{} for _ in range(N+1)]
dist = [-1]*(N+1)
for _ in range(N-1):
    a,b,c = map(int,input().split())
    edge[a][b] = c
    edge[b][a] = c
Q,K = map(int,input().split())
dist[K] = 0
dfs_stack = [K]
while dfs_stack:
    s = dfs_stack.pop()
    for t,t_dist in edge[s].items():
        if dist[t] == -1:
            dist[t] = dist[s] + t_dist
            dfs_stack.append(t)
for _ in range(Q):
    x,y = map(int,input().split())
    print(dist[x]+dist[y])

Measured memory_bytes: 99684
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define ms(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+5;
int t, a, b;

int main()
{
	cin >> t >> a >> b;
	cout << min(t*a, b) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define ii pair <ll, ll>
#define iii pair <ll, ii>
#define ll long long
#define X first
#define Y second

const int N = 2E5 + 10;

int n, Root[N], Ranked[N];
ii a[N], x[N], y[N];

void Input()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i].X >> a[i].Y;
}

int Find_Root(int u)
{
    if (u == Root[u]) return u;
    return Root[u] = Find_Root(Root[u]);
}

bool Union(int u, int v)
{
    u = Find_Root(u);
    v = Find_Root(v);
    if (u == v) return false;

    if (Ranked[u] > Ranked[v]) swap(u, v);
    Root[u] = v;
    Ranked[v] += Ranked[u];

    return true;
}

void Solve()
{
    ll res = 0;
    priority_queue <iii, vector <iii>, greater <iii> > PQ;
    for (int i = 1; i <= n; i++) x[i] = {a[i].X, i};
    for (int i = 1; i <= n; i++) y[i] = {a[i].Y, i};
    sort(x + 1, x + 1 + n);
    sort(y + 1, y + 1 + n);

    for (int i = 1; i < n; i++) {
        PQ.push({x[i + 1].X - x[i].X, {x[i].Y, x[i + 1].Y}});
        PQ.push({y[i + 1].X - y[i].X, {y[i].Y, y[i + 1].Y}});
    }
    for (int i = 1; i <= n; i++) Root[i] = i, Ranked[i] = 1;

    int k = n - 1;
    while (k && PQ.size()) {
        ll Distance = PQ.top().X;
        int u = PQ.top().Y.X;
        int v = PQ.top().Y.Y;
        PQ.pop();
        if (Union(u, v)) {
            k--;
            res += Distance;
        }
    }

    cout << res;
}

#define task "test"
int main()
{
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int testcase = 1;
    /// cin >> testcase;
    while (testcase--) {
        Input();
        Solve();
    }
}




Measured memory_bytes: 16492
#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e20;
const int INF = 1e9;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll w, h, x, y;
  cin >> w >> h >> x >> y;
  bool flag = false;
  double ans = (w * h) / 2.0;
  if(w / 2.0 == x && h / 2.0 == y) flag = true;
  flag ? cout << ans << ' ' << 1 << endl : cout << ans  << ' '<< 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=987654323;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<lldo>&ar,lldo in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<lldo>&ar,lldo in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint a,b,c,x,y;cin>>a>>b>>c>>x>>y;
	llint ans=big;
	mineq(a,c+c);
	mineq(b,c+c);
	if(x>y){ans=(x-y)*a+y*min(a+b,c+c);}
	else{ans=(y-x)*b+x*min(a+b,c+c);}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main(){
	
	int n, ans = 0;
	
	cin >> n;
	
	for (int i = 0; i < n; i++){
		long long a;
		
		cin >> a;
		
		if (a % 2 == 0){
			while (a % 2 == 0){
				a-= a /2;
				ans++;
			} 	
		} else {
			continue;
		}
	}
	
	cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int H,W;
char fld[50][50];
int A[50][50];
bool mark[50][50];
void solve(){
    cin>>H>>W;
    rep(i,H)rep(j,W)cin>>fld[i][j];
    vector<char>vec;
    rep(i,H)rep(j,W)if(isalpha(fld[i][j]))vec.pb(fld[i][j]);
    sort(all(vec));vec.erase(unique(all(vec)),vec.end());
    rep(i,H)rep(j,W){
        if(isalpha(fld[i][j]))A[i][j]=lower_bound(all(vec),fld[i][j])-vec.begin();
        else A[i][j]=vec.size();
    }

    int max_x[10],max_y[10],min_x[10],min_y[10];
    rep(i,vec.size()){
        max_x[i]=max_y[i]=-1001001001;
        min_x[i]=min_y[i]=1001001001;
    }

    rep(i,H)rep(j,W){
        chmax(max_x[A[i][j]],j);
        chmax(max_y[A[i][j]],i);
        chmin(min_x[A[i][j]],j);
        chmin(min_y[A[i][j]],i);
    }

    vint p(vec.size());
    rep(i,vec.size())p[i]=i;
    do{
        memset(mark,0,sizeof(mark));
        bool ok=true;
        for(int c:p){
            reps(i,min_y[c],max_y[c]+1){
                reps(j,min_x[c],max_x[c]+1){
                    if(!mark[i][j]&&A[i][j]!=c)ok=false;
                    mark[i][j]=true;
                }
            }
        }
        if(ok){
            cout<<"SAFE"<<endl;
            return;
        }
    }while(next_permutation(all(p)));
    cout<<"SUSPICIOUS"<<endl;
}

signed main(){
    int T;
    cin>>T;
    while(T--)solve();
}

Measured memory_bytes: 3152
#include <cstdio>
#include <vector>
using namespace std;
const int maxn = 100005;
vector<int> nt[maxn];
int n, sg[maxn];

void dfs(int x, int fa)
{
	for (auto v:nt[x])		if (v!=fa) dfs(v,x), sg[x]^=(sg[v]+1);
}

int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n-1; i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		nt[x].push_back(y);
		nt[y].push_back(x);
	}
	dfs(1,0);
	if (sg[1]) puts("Alice");else puts("Bob");
}

Measured memory_bytes: 12288
n=int(input())
def just(n,sho):
    for i in range(sho+1):
        m=4*i
        while m!=n:
            m+=7
            if m>n:
                break
            if m==n:
                return print("Yes")
    return print("No")

if n%4==0 or n%7==0 or n%11==0:
    print("Yes")
else:
    just(n, n//4)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long int n, a, b;
    cin >> n >> a >> b;
    long long int k = a + b;
    long long int ans = 0;
    long long int cnt1 = n / k, cnt2 = n % k;
    ans += a * cnt1 + min(a, cnt2);

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, a;
bool d[10] = {0};

bool check(int x) {
    while (x) {
        if (d[x%10]) return 0;
        x /= 10;
    }
    return 1;
}

int main() {
    cin >> a >> n;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        d[x] = 1;
    }
    while (!check(a)) a++;
    cout << a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;

//const int MOD=998244353;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
	int n;
	cin>>n;
	
	vector<vector<int>> tree(n+1);
	
	for(int i=0; i<n-1; i++){
	    int x,y;
	    cin>>x>>y;
	    tree[x].push_back(y);
	    tree[y].push_back(x);
	}
	
	vector<int> d1(n+1,-1), d2(n+1,-1);
	int r=1, dr=0;
	
	queue<int> q;
	q.push(1);
	
	d1[1]=0;
	while(q.size()){
	    int cur=q.front();
	    q.pop();
	    for(int i:tree[cur]){
	        if(d1[i]==-1){
	            q.push(i);
	            d1[i]=d1[cur]+1;
	            if(d1[i]>dr){
	                dr=d1[i];
	                r=i;
	            }
	        }
	    }
	}
	
	int diam=0;
	q.push(r);
	d2[r]=0;
	while(q.size()){
	    int cur=q.front();
	    q.pop();
	    for(int i:tree[cur]){
	        if(d2[i]==-1){
	            q.push(i);
	            d2[i]=d2[cur]+1;
	            diam=max(diam,d2[i]);
	        }
	    }
	}
	
	diam++;
	
	cout<<(diam%3==2?"Second":"First");
	
    return 0;
}

Measured memory_bytes: 14452
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;


int main() {
ll N;
cin>>N;
pair<ll,ll> ba[N];
rep(i,N){
    ll A,B;
    cin>>A>>B;
    ba[i]=make_pair(B,A);
}
sort(ba,ba+N);
ll now=0;
rep(i,N){
    if(ba[i].first-ba[i].second<now){
        cout<<"No"<<endl;
        return 0;
    }
    else{
        now+=ba[i].second;
    }
}
cout<<"Yes"<<endl;



  return 0;
}

Measured memory_bytes: 6740
from fractions import gcd
#from math import gcd
N,M = map(int,input().split())
A = list(map(int,input().split()))
lcm = A[0]
lis = [[0] for _ in range(30)]
tmp = 0
while A[0]%2 == 0:
    A[0]//= 2
    tmp += 1
lis[tmp] = 1

for i in range(1,N):
    tmp = 0
    Ai = A[i]
    while Ai%2 == 0:
        Ai//= 2
        tmp += 1
    lis[tmp] = 1
    lcm = (lcm*A[i]) // gcd(lcm,A[i])
    if lcm > 2*M:
        print(0)
        exit()
jud = False
if lis.count(1) > 1:
    print(0)
    exit()


M -= lcm//2
ans = (M//lcm)+1
print(ans)


Measured memory_bytes: 16320
#include<bits/stdc++.h>

using namespace std;
mt19937_64 rng(58);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    long long n;
    long long ans = 0;
    cin >> n;
    for (long long i = 1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3628
//In the name of Allah
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; 
typedef pair<int,int> pii; 

const int maxN = 1000 * 100 + 10; 
ll a[maxN]; 
const ll inf = 1e18; 
ll dp[maxN]; 
set<pair<ll,int>> curr1, curr2; 

int main() { 
	ios::sync_with_stdio(false); cin.tie(0); 
	a[0] = 0; 
	int n,e,T; cin >> n >> e >> T;
	for( int i = 0 ; i < n ; i++ ) cin >> a[i+1]; 

	curr1.insert( { inf , -1 } ) ; 
	curr2.insert( { inf , -1 } ) ; 
	fill( dp , dp + n + 1 , inf ) ; 
	dp[0] = 0; 
	int last = 0; 
	curr1.insert( { 0ll , 0 } ); 
	for( int i = 1 ; i <= n ; i++ ) { 
		while( last < i && 2ll * (a[i] - a[last+1]) >= T ) { 
			curr1.erase( { 0ll + dp[last] ,  last } ) ; 
			curr2.insert( { 0ll + dp[last] - 2ll * a[last+1] , last } ); 
			last++; 
		}
		dp[i] = min( 0ll + curr1.begin()->first + T , 
				0ll + curr2.begin()->first + 2ll * a[i] ); 
		curr1.insert( { dp[i]  , i } ); 
	}
	cout << dp[n] + e << endl;
}



Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  rep(i, N) cin >> h[i];
  
  for(int i=1; i<N; i++){
    if(h[i] < h[i-1]){
      cout << "No" << endl;
      return 0;
    }else{
      if(h[i] >= h[i-1]+1) h[i]--;
    }
  }
  cout << "Yes" << endl;

}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int x, y, z, k;
	cin >> x >> y >> z >> k;

	long long a[1001],b[1001],c[1001];
	vector<long long> ab, abc;
	int i;
	for(i=0;i<x;i++) cin >> a[i];
	// printf("%d\n", a[x-1]);
	for(i=0;i<y;i++) cin >> b[i];
	// printf("%d\n", b[y-1]);
	for(i=0;i<z;i++) cin >> c[i];
	// printf("%d\n", c[z-1]);
	// cout << "a:" << a[x-1] << " b:" << b[y-1] << " c:" << c[z-1] << endl;

	for(i=0;i<x;i++){
		for(int j=0;j<y;j++){
			ab.push_back(a[i]+b[j]);
		}
	}
	sort(ab.begin(), ab.end(), greater<long long>());
	for(i=0;i<min(k, x*y);i++){
		for(int j=0;j<z;j++){
			abc.push_back(ab[i]+c[j]);
		}
	}
	sort(abc.begin(), abc.end(), greater<long long>());

	for(i=0;i<k;i++){
		cout << abc[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 43364
def main():
    N, L = map(int, input().split())
    tastes = []
    num = []
    perfectPie = 0
    for i in range(N):
        perfectPie += i + L
        tastes.append(i + L)
        num.append(abs(i + L))
    num.sort()
    if num[0] in tastes:
        print(perfectPie - num[0])
    else:
        print(perfectPie + num[0])
main()  

Measured memory_bytes: 9208
package main

import (
	"fmt"
)

var N, M, Q int
var a, b, c, d []int
var max int

func main() {
	fmt.Scan(&N, &M, &Q)
	a = make([]int, Q)
	b = make([]int, Q)
	c = make([]int, Q)
	d = make([]int, Q)
	for i := range a {
		fmt.Scan(&a[i], &b[i], &c[i], &d[i])
		a[i]--
		b[i]--
	}
	for i := 0; i < M; i++ {
		A := make([]int, 1)
		A[0] = i
		dfs(A)
	}

	fmt.Println(max)
}


func dfs(A []int) {
	if len(A) == N {
		score := 0
		for i := range a {
			if (A[b[i]] - A[a[i]]) == c[i] {
				score += d[i]
			}
		}
		if score > max {
			max = score
		}
	} else {
		n := len(A) -1
		k := A[n]
		for v := k; v<M; v++ {
			B := A
			dfs(append(B, v))
		}
	}
}


Measured memory_bytes: 5952
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;

int main() {
	int N = 0;//シマの数
	int M = 0;//定期便の数
	int g = 0;
	int g2 = 0;
	

	cin >> N >> M;
	bool go1[200000] = {false};
	bool goN[200000] = {false};
	
	for (int i = 1; i <= M; i++) {

		cin >> g >> g2;
		if (g == 1 && g2 != 1) {
		
			go1[g2] = true;
			

		}
		else if (g2 == N && g != 1) {
	
			goN[g] = true;
		

		}
		

	}
	for (int j = 2;j<=N;j++) {
		if (goN[j]==true && go1[j]==true) {
			cout << "POSSIBLE" << endl;
			break;
		}
		else if (j==N) {
			cout << "IMPOSSIBLE" << endl;
		
		}

	}



	return 0;
}


Measured memory_bytes: 764