akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define M 1000000
long long H,W,A[10],q;
int p[M];
struct{int a,b,n,q;}d[900001];

void f(int a,int b){
	int h,t,i;
	if(1<a&&a<H&&1<b&&b<W){
		if(i=p[h=(a/M+a+b/M+b)%M]){
			for(;;){
				if(d[i].a==a&&d[i].b==b){
					break;
				}else if(d[i].q){
					i=d[i].q;
				}else{
					d[i=d[i].q=++q].a=a;
					d[i].b=b;
					break;
				}
			}
		}else{
			d[i=p[h]=++q].a=a;
			d[i].b=b;
		}
		--A[t=d[i].n++];
		++A[t+1];
	}
}
int main(){
	int a,b,i,j;
	scanf("%lld%lld%d",&H,&W,&i);
	A[0]=(H-2)*(W-2);
	for(;~scanf("%d%d",&a,&b);)
		for(i=-1;i<=1;++i)
			for(j=-1;j<=1;++j)
				f(a+i,b+j);
	for(i=0;i<=9;++i)printf("%lld\n",A[i]);
	return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c; cin >> a >> b >> c;
  int x; cin >> x;
  x /= 50;
  int ans = 0;
  rep(A, 0, a+1) {
    rep(B, 0, b+1) {
      rep(C, 0, c+1) {
        if (A * 10 + B * 2 + C == x) ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
bool dp[8005][32005];
bool func(vector<ll> &v,ll p){
    memset(dp,0,sizeof(dp));
    dp[0][16000]=1;
    for(ll i=0,n=v.size();i<n;i++){
        for(ll j=0;j<=32000;j++){
            if(dp[i][j]==false)continue;
            dp[i+1][j+v[i]]=dp[i+1][j-v[i]]=1;
        }
    }
    return dp[v.size()][16000+p];
}
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    string s;cin>>s;
    ll x,y;cin>>x>>y;
    vector<ll> vx,vy;
    for(ll i=0,n=s.size(),cnt=0,flg=0;i<=n;i++){
        if(i!=n && s[i]=='F')cnt++;
        else{
            if(flg==0)vx.push_back(cnt);
            else vy.push_back(cnt);
            cnt=0,flg^=1;
        }
    }
    x-=vx[0];
    vx.erase(vx.begin());
    if(func(vx,x) && func(vy,y))cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 250624
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
typedef pair<int,int> P;

int dp[1005][10005];

struct magic{
    int d,c;
};

// int main(){
//     int h,n;
//     cin >> h >> n;
//     // vector<vector<int>> dp(n,vector<int>(h+1,INF));
//     vector<magic> ms(n);
//     rep(i,n){
//         int a, b; cin >> a >> b;
//         // ms[i].d = a;ms[i].c = b;
//         magic p; p.d = a;p.c = b;
//         ms[i] = p;
//     }
    
//     rep(i,n+1)dp[i][0]=0;
//     rep(i,h+1)dp[0][i]=INF;
//     rep(i,n){
//         rrep(j,h){
//             if(j-ms[i].d <0){
//                 dp[i+1][j] = min(dp[i][j],dp[i+1][0]+ms[i].c);
//             }
//             else dp[i+1][j] = min(dp[i][j],dp[i+1][j-ms[i].d]+ms[i].c);
//         }
//     }
//     // rep(i,n+1){
//     //     rep(j,h+1){
//     //         cout<<dp[i][j] << " ";
//     //     }
//     //     cout << endl;
//     // }

//     cout << dp[n][h] << endl;
//     return 0;
// }




int main(){
    int h,n;
    cin >> h >> n;
    // vector<vector<int>> dp(n,vector<int>(h+1,INF));
    vector<magic> ms(n);
    rep(i,n){
        int a, b; cin >> a >> b;
        // ms[i].d = a;ms[i].c = b;
        magic p; p.d = a;p.c = b;
        ms[i] = p;
    }
    int dp[10005];
    
    rep(i,h+1)dp[i]=INF;
    dp[0] = 0;
    rep(j,h+1){
        rep(i,n){
            if(j-ms[i].d>=0)dp[j] = min(dp[j-ms[i].d]+ms[i].c, dp[j]);
            else dp[j] = min(dp[0]+ms[i].c,dp[j]);
        }
    }
    cout << dp[h]<<endl;
    
    // rep(i,n+1){
    //     rep(j,h+1){
    //         cout<<dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    // cout << dp[n][h] << endl;
    return 0;
}


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

ll Gcd(ll m, ll n){
  ll temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

ll Lcm(ll m, ll n){
  return m * n / Gcd(m,n);
}

ll A,B,C,D;
int main(void){
  cin>>A>>B>>C>>D;
  ll CD = Lcm(C,D);
  ll BC = B/C;
  ll BD = B/D;
  ll BCD = B/CD;
  ll AC = (A-1)/C;
  ll AD = (A-1)/D;
  ll ACD = (A-1)/CD;
  ll cnt = B-A-((BC+BD-BCD)-(AC+AD-ACD))+1;
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long ans;
const int N = 100 + 10;
int n, m, q, a[N], b[N], c[N], d[N], A[N];
void dfs(int dps, int lst) {
    if (dps > n) {
        long long tans = 0;
        for (int i = 1; i <= q; i++) {
            if (A[b[i]] - A[a[i]] == c[i]) {
                tans += d[i];
            }
        }
        ans = max(ans, tans);
    }
    else {
        for (int i = lst; i <= m; i++) {
            A[dps] = i;
            dfs(dps + 1, i);
        }
    }
}

int main() {
    scanf("%d %d %d", &n, &m, &q);
    for (int i = 1; i <= q; i++) {
        scanf("%d %d %d %d", a + i, b + i, c + i, d + i);
    }
    dfs(1, 1);
    printf("%lld\n", ans);
    return 0;
}

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

using namespace std;
#pragma GCC optimize("O3")

typedef long long ll;
typedef long double ld;
const int maxN = 1e5 + 10;
int x[maxN], y[maxN];
int n, m;
vector < int > by[maxN];
int fenw[maxN];
const int mod = (int)1e9 + 7;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
void upd(int v, int by) {
    v += 1;
    while (v < maxN) {
        fenw[v] = sum(fenw[v], by);
        v = (v | (v - 1)) + 1;
    }
}
int get(int r) {
    r += 1;
    int ans = 0;
    while (r > 0) {
        ans = sum(ans, fenw[r]);
        r &= (r - 1);
    }
    return ans;
}
int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> x[i];
    for (int i = 1; i <= m; i++) cin >> y[i];
    vector < pair < int, int > > rects;
    vector < int > idX, idY;
    for (int i = 1; i <= n; i++) {
        if (x[i] < y[1] || x[i] > y[m]) continue;
        int p = lower_bound(y + 1, y + m + 1, x[i]) - y;
        assert(y[p] > x[i]);
        idX.emplace_back(y[p] - x[i]);
        assert(x[i] > y[p - 1]);
        idY.emplace_back(x[i] - y[p - 1]);
        rects.emplace_back(y[p] - x[i], x[i] - y[p - 1]);
    }
    if (rects.empty()) {
        cout << 1;
        return 0;
    }
    sort(rects.begin(), rects.end());
    rects.erase(unique(rects.begin(), rects.end()), rects.end());
    sort(idX.begin(), idX.end());
    idX.erase(unique(idX.begin(), idX.end()), idX.end());
    sort(idY.begin(), idY.end());
    idY.erase(unique(idY.begin(), idY.end()), idY.end());
    for (auto& it : rects) {
        it.first = lower_bound(idX.begin(), idX.end(), it.first) - idX.begin() + 1;
        it.second = lower_bound(idY.begin(), idY.end(), it.second) - idY.begin() + 1;
        by[it.first].emplace_back(it.second);
    }
    upd(0, 1);
    for (int i = 0; i < maxN; i++) {
        if (by[i].empty()) continue;
        vector < int > pp(by[i].size());
        for (int r = 0; r < by[i].size(); r++) {
            pp[r] = get(by[i][r] - 1);
        }
        for (int r = 0; r < by[i].size(); r++) {
            upd(by[i][r], pp[r]);
        }
    }
    int ans = get(maxN - 2);
    cout << ans;
    return 0;
}


Measured memory_bytes: 8040
from heapq import heappush, heappop
from collections import deque
import itertools
from itertools import permutations
import sys
import bisect
sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
YNeos='YNeos'
mo=10**9+7
imp='IMPOSSIBLE'


s=input()
t=list(s)[::-1]
ans=0
dp=[0]*13
dp[0]=1
for d in range(len(t)):
    
    if t[d]=='?':
        tm=[0]*13
        for x in range(10):
            r=int(x)*pow(10,d,13)
            for i in range(13):
                tm[(i+r)%13]+=dp[i]
        dp=[j%mo for j in tm]
    else:
        tm=[0]*13
        r=int(t[d])*pow(10,d,13)
        for i in range(13):
            tm[(i+r)%13]=dp[i]
        dp=[j for j in tm]
    #print(dp)

print(dp[5]%mo)


Measured memory_bytes: 50288
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		string S;
		cin >> S;
		int x = 15 - S.size();
		int y = count( S.begin(), S.end(), 'o' );
		cout << (x+y >= 8 ? "YES" : "NO") << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define in(a) ((a)>=0?(a):0)
using namespace std;
typedef long long LL;
const int MAX_N=105;
const int MAX_K=100005;
const int Mod=1e9+7;
LL dp[MAX_N][MAX_K];
int n,k;
int a[MAX_N];
LL calc(int l,int r,LL sum[])
{
	return l>0?(sum[r]-sum[l-1]):sum[r];
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=0;i<=k;i++)dp[0][i]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=k;j++)
		{
		/*	for(int j_=in(j-a[i]);j_<=j;j_++)
			{
				dp[i][j]+=dp[i-1][j_];
				dp[i][j]%=Mod;
			}*/
			dp[i][j]+=calc(in(j-a[i]),j,dp[i-1]);
			dp[i][j]%=Mod;
		}
		for(int j=1;j<=k;j++)
		{
			dp[i][j]+=dp[i][j-1];
		}
	}
	cout<<dp[n][k]-dp[n][k-1]<<endl;
	return 0;
}


Measured memory_bytes: 80128
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	long int x = 0;
	long int y = 0;
	long int X = 0;
	long int ans =1000000000000000;
	for(int i=0;i<n;i++){
		X = X + a[i];
	}
	for(int i=0;i<n-1;i++){
		x = x + a[i];
		if(abs(2*x-X)<ans){
			ans = abs(2*x-X);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
N,K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * N
for i in range(min(N,K)):
    dp[i] = abs(h[i]-h[0])

for i in range(K,N):
    dp[i] = dp[i-1] + abs(h[i]-h[i-1])
    for j in range(2,K+1):
        dp[i] = min(dp[i-j] + abs(h[i]-h[i-j]),dp[i])

answer = dp[-1]
print(answer)

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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<Edge>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
void dfs(string S,int N,vector<string> &v){
  if(S.size() == N) return;
  if(S.size() == N-1){
  v.push_back(S+'A');
  v.push_back(S+'B');
  v.push_back(S+'C');
  v.push_back(S+'x');
  }
  dfs(S+'A',N,v);
  dfs(S+'B',N,v);
  dfs(S+'C',N,v);
  dfs(S+'x',N,v);
}


int main(){
 ll X,Y,A,B,C;
 cin >> X >> Y >> A >> B >> C;
 vector<ll> p(A),q(B),r(C);
 rep(i,A){
   cin >> p[i];
 }
 rep(i,B){
   cin >> q[i];
 }
 rep(i,C){
   cin >> r[i];
 }
 vector<pair<ll,char>> v;
 rep(i,A){
   v.push_back(make_pair(p[i],'R'));
 }
 rep(i,B){
   v.push_back(make_pair(q[i],'G'));
 }
 rep(i,C){
   v.push_back(make_pair(r[i],'M'));
 }
 sort(v.begin(),v.end());
 reverse(v.begin(),v.end());
 
 ll ans = 0;
 ll cx = 0;//取ったRの個数
 ll cy = 0;//取ったGの個数
 ll c = 0;//取った個数
 rep(i,v.size()){
   if(v[i].second == 'R' && cx < X){
     cx++;
     c++;
     ans += v[i].first;
   }
   if(v[i].second == 'G' && cy < Y){
     cy++;
     c++;
     ans += v[i].first;
   }
   if(v[i].second == 'M'){
     c++;
     ans += v[i].first;
   }
   if(c == X+Y) break;
 }
  cout << ans << endl;
 }

Measured memory_bytes: 12908
import java.util.Scanner;


public class Main {

    static void solve() {
        Scanner scan = new Scanner(System.in);

        int r = scan.nextInt();
        int g = scan.nextInt();
        int b = scan.nextInt();
        int k = scan.nextInt();

        while(k>0) {
            if(r<g && g<b) {
                System.out.println("Yes");
                return;
            }
            if(r>=g) {
                g*=2;
            } else if(b<=g) {
                b*=2;
            }
            k--;
        }

        if(r<g && g<b) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");

//        for (int i = 0; i < n; i++) {
//
//        }

//        int t = scan.nextInt();
//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
//            int[] arr1 = new int[n];
//            for (int j = 0; j < n; j++) {
//                arr1[j] = scan.nextInt();
//            }
////            scase(n, arr1);
//        }


//        long t = scan.nextLong();

//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
////            scase(n);
//        }
    }


    static void solveCase(int t, int x, String s) {

    }

    static void scase(int[] arr1, int[] arr2) {
    }


    public static void main(String[] args) {

        solve();

    }


//
//    class Counter extends HashMap<Integer, Integer> {
//        public int get(int k) {
//            return containsKey(k) ? super.get(k) : 0;
//        }
//
//        public void add(int k, int v) {
//            put(k, get(k) + v);
//        }
//    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}

Measured memory_bytes: 27068
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF (long long)1000000007
#define MOD (long long)998244353
using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++)cin >> a[i];
    if(a[0]!=0){
        cout<<0<<endl;
        return 0;
    }
    int max_a=0;
    vector<int> count(n);
    for(int i=0; i<n; i++){
        count[a[i]]++;
        max_a=max(max_a,a[i]);
    }
    if(count[0]!=1){
        cout<<0<<endl;
        return 0;
    }
    long long result=1;
    for(int i=1; i<=max_a; i++){
        if(count[i]==0){
            cout<<0<<endl;
            return 0;
        }
        for(int j=0; j<count[i]; j++){
            result=(result*count[i-1])%MOD;
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() { 
  string s;cin >> s;
  int ans;
  rep(i,3){
    if(s[i]=='1')ans++;
  }
  cout << ans << endl;
}


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

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

#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> inline bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

template <typename T> T read(T& x) {
    T f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 4000;

int n;
vector<int> G[N + 5];
int fa[N + 5], a[N + 5];
int r[N + 5], b[N + 5], d[N + 5];

bool chk() {
    for(int i = 0; i < n; ++i) if(a[i] != i) return false;
    return true;
}

vector<int> ans;
void move(int u) {
    ans.pb(u);
    int t = a[0];
    for(int i = u; i >= 0; i = fa[i]) std::swap(a[i], t);
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);

    fa[0] = -1;
    for(int i = 1; i < n; ++i) read(fa[i]), G[fa[i]].pb(i), d[i] = d[fa[i]] + 1;
    for(int i = 0; i < n; ++i) read(a[i]);

    int cnt = 0;
    while(cnt < n) {
        vector<int> trash;
        for(int i = n - 1; i >= 0; --i) if(!b[i]) {
            trash.pb(i);
            int c = -1, sz = 0;
            for(auto v : G[i]) if(!b[v]) ++ sz, c = v;

            if(!sz) r[i] = i;
            else if(sz == 1 && r[c] != -1) r[i] = r[c];
            else r[i] = -1;
        }

        std::sort(trash.begin(), trash.end(), [&](const int& p, const int& q) {
            return mp(r[p], d[p]) > mp(r[q], d[q]);
        });

        for(int i = 0; i < (int) trash.size(); ) {
            if(r[a[0]] != -1) {
                int x = r[a[0]];
                for(; b[x] && a[x] > a[0]; x = fa[x]);
                move(x);
                ++ cnt;
                for(; b[x]; x = fa[x]); 
                b[x] = true;
            } else {
                move(trash[i++]);
            }
            for(; i < (int) trash.size() && b[trash[i]]; ++i);
        }
    }

    assert(chk());
    printf("%lu\n", ans.size());
    for(auto v : ans) printf("%d\n", v);

    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll INF = 1LL << 62;
#define atcoder(int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define sc(x) cin >> x
#define pr(x) cout << x << endl

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int main(){

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b < c + d)pr("Right");
	else if (a + b == c + d)pr("Balanced");
	else pr("Left");

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String s = sc.next();


    if(s.equals("Sunny")){
      System.out.println("Cloudy");
    }else if(s.equals("Cloudy")){
      System.out.println("Rainy");
    }else if(s.equals("Rainy")){
      System.out.println("Sunny");
    }
    
  }

}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;


void solve() {
	int n, m; cin >> n >> m;
	bool red[100000];
	int ball[100000];
	rep(i, n) { red[i] = false; ball[i] = 1; }
	red[0] = true;
	rep(i, m) {
		int x, y; cin >> x >> y; x--; y--;
		ball[x]--; ball[y]++;
		if (ball[x] == 0) {
			red[y] = red[y] || red[x];
			red[x] = false;
		}
		else {
			red[y] = red[y] || red[x];
		}
	}
	int ans = 0;
	rep(i, n) { if(red[i]) ans++; }
	cout << ans << endl;
}

int main() {

	solve();

	return 0;
}


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

const int mod = 998244353;

int main() {
  int n, s; cin >> n >> s;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  vector<vector<ll>> dp(n+1, vector<ll>(s+1));
  dp.at(0).at(0) = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i+1][j] += 2*dp[i][j];
      dp[i+1][j] %= mod;
      if (j+a.at(i) <= s) {
        dp[i+1][j+a.at(i)] += dp[i][j];
        dp[i+1][j+a.at(i)] %= mod;
      }
    }
  }
  cout << dp[n][s] << '\n';
  return 0;
}


Measured memory_bytes: 73656
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m){
		if(n==0 && m==0) break;
		vector<int> taro;
		vector<int> hanako;
		int sumt=0,sumh=0;
		for(int i=0;i<n;i++){
			int card1;
			cin>>card1;
			sumt+=card1;
			taro.push_back(card1);
		}
		for(int i=0;i<m;i++){
			int card2;
			cin>>card2;
			sumh+=card2;
			hanako.push_back(card2);
		}
		sort(taro.begin(),taro.end());
		sort(hanako.begin(),hanako.end());
		int a=-1,b=-1;
		for(int i=0;i<taro.size();i++){
			for(int j=0;j<hanako.size();j++){
				if(sumt-sumh==(taro[i]-hanako[j])*2){
					a=taro[i];
					b=hanako[j];
					goto k;
				}
			}
		}
		k:
		if(a==-1 && b==-1){
			cout<<"-1"<<endl;
		}else{
			cout<<a<<" "<<b<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

ll gcd(ll a,ll b){return b ? gcd(b,a%b) :a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}






ll di[]={1,0,-1,0};
ll dj[]={0,-1,0,1};

struct UnionFind {
    vector<int>d;
    UnionFind(int n=0):d(n,-1){}
    int find(int x){
        if((d[x])<0)return x;
        return d[x]=find(d[x]);
    }
    bool unite(int x,int y){
        x =find(x);y=find(y);
        if(x==y)return false;
        if(d[x]>d[y])swap(x,y);
        d[x]+=d[y];
        d[y]=x;
        return true;
    }
    bool same(int x,int y){return find(x)==find(y);};
    int size(int x){return -d[find(x)];};
};




// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint f(int n) {
    if(n==0)return 1;
    mint x=f(2/n);
    x*=x;
    if(n%2==1)x*=2;
    return x;
}

mint choose(int n,int a){
    mint x =1,y=1;
    rep(i,a){
      x*=n-i;
      y*=a+i;
    }
    return x/y;
}

vector<ll>to[1000000];
const ll inf=10000000007;





ll m=1000000007;

int main()
{ 
  ll n;
  cin>>n;
  vector<ll>a(n);
  vector<ll>b;
  rep(i,n)cin>>a[i];
  b=a;
  Rep(i,n)a[i]=a[i]+a[i-1];
  ll ans=0;
  rep(i,n-1){
    ll c=b[i]%m;
    ll d=(a[n-1]-a[i])%m;
    ans+=c*d%m;
    ans%=m;
  }
  cout<<ans<<endl;
}
 
 




Measured memory_bytes: 29944
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>
#include <cstdint>
using namespace std;

int main() {
    constexpr size_t W = 0, V = 1;

    uint32_t n, w;
    cin >> n >> w;
    vector<array<uint32_t, 2>> items(n);
    for (auto &e : items) cin >> e[W] >> e[V];

    vector<vector<uint64_t>> dp(n + 1, vector<uint64_t>(w + 1));
    fill(dp[0].begin(), dp[0].end(), 0);

    for (uint32_t i = 0; i < n; ++i) {
        for (uint32_t j = 0; j <= w; ++j) {
            if (items[i][W] <= j) {
                dp[i + 1][j] = max(dp[i][j - items[i][W]] + items[i][V], dp[i][j]);
            }
            else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    cout << dp[n][w] << endl;
}



Measured memory_bytes: 83116
x, k, d = map(int, input().split())

r = x%d
l = r-d

lc = abs(x-l)//d
rc = abs(x-r)//d

ans = min(abs(x-d*k), abs(x+d*k))
if(k>=lc):
    if((k-lc)%2): ans = min(ans, min(abs(l+d), abs(l-d)))
    else: ans = min(ans, abs(l))
if(k>=rc):
    if((k-rc)%2): ans = min(ans, min(abs(r+d), abs(r-d)))
    else: ans = min(ans, abs(r))
print(ans)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=998244353;
const int INF=1e9;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


         
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll n,m;
  cin >> n >> m;
  ll ans=0;
  ll l=0,r=1e12;
  while(abs(l-r)>1){
    ll mid=(r+l)/2;
    
    ll x=n,y=m;
    if(mid>n){
      y-=(mid-x)*2;
    }
    if(y>=mid*2)l=mid;
    else r=mid;
  }
  cout << l << endl;
  return 0;     
}


Measured memory_bytes: 3580
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

#include <bits/stdc++.h>
using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \
            c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define memo(dp, val) memset(dp, val, sizeof(dp))
#define NINJA                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define all(a) a.begin(), a.end()
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define dloop(i, n) for (int i = n - 1; i >= 0; i--)
#define iii tuple<int, int, int>
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int, int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main() {
  NINJA;

  string s;
  cin >> s;

  int n = sz(s);

  if (s[n - 1] == 's') {
    cout << s << "es" << endl;
  } else {
    cout << s << "s" << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define vec vector<ll>
#define ms multiset<ll>
#define f(i,x,n) for(int i=x;i<n;i++)
#define int long long
#define mod 998244353
#define endl "\n"
void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
int32_t main()
{
	fastio();
	int a,b;
	cin>>a>>b;
	int aa=(a+b)/2;
	if(a==b)
		cout<<0;
	else 
	{
		if(abs(a-aa)==abs(b-aa))
			cout<<aa;
		else
			cout<<"IMPOSSIBLE";
	}
}

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

int main() {
  cout << setprecision(15);
  int k, s;
  cin >> k >> s;

  int ans = 0;
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j <= k; ++j) {
      int z = s - i - j;
      if (0 <= z && z <= k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int N;
    string ans;
    cin >> N;
    int judge = N % 100 % 10;
    if (judge == 3){
        ans = "bon";
    }else if (judge == 0 || judge == 1 || judge == 6 || judge == 8){
        ans = "pon";
    }else {
        ans = "hon";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
  int i;
  int count = 0;
  string str;
  cin >> str;
  for(i=0; i<str.size(); i++){
    if (str[i] == '1'){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,a,b;

int main(){
	cin>>n>>a>>b;
	if(abs(a-b)%2==0) cout<<"Alice"<<endl;
	else cout<<"Borys"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//



     signed main(){
  int d;
  clock_t st=clock();
  cin>>d;
    clock_t ed=clock();

  int c[26];
  for(int i=0;i<26;i++)cin>>c[i];
  int t[d],s[d][26],x[26]={};
    vector<int>v[26];
    for(int i=0;i<26;i++)v[i].push_back(-1);

  for(int i=0;i<d;i++)for(int j=0;j<26;j++)cin>>s[i][j];
   // cerr<<'i';
  for(int i=0;i<d;i++){
      for(int j=0;j<26;j++)x[j]+=c[j];
      int k=0;
      for(int j=1;j<26;j++)if(x[k]+s[i][k]<x[j]+s[i][j])k=j;
      t[i]=k;
      x[k]=0;
      v[k].push_back(i);
  }
  for(int i=0;i<26;i++)v[i].push_back(d);
//for(int i=0;i<d;i++)cout<<t[i]+1<<endl;
  // cerr<<double(clock()-st)/CLOCKS_PER_SEC<<endl;

while(double(clock()-st)/CLOCKS_PER_SEC<1.95){
  if(rand()%1000000000){
    int p=rand()%d;
    auto q=find(v[t[p]].begin(),v[t[p]].end(),p);
    q++;
  // int m=(p+(*q))/2;
   int m=p+rand()%((*q)-p);
//cerr<<m<<' '<<p<<endl;
   if(m==p)continue;
   auto r1=find(v[t[m]].begin(),v[t[m]].end(),m);
   auto r0=r1-1,r2=r1+1;
   if((m-p)*((*q)-m)*c[t[p]]+s[m][t[p]]>(m-(*r0))*((*r2)-m)*c[t[m]]+s[m][t[m]]){
 
    v[t[p]].insert(q,m);
    v[t[m]].erase(r1);
    t[m]=t[p];
   }
  }else{
    int p=rand()%(d-1);
    if(t[p]==t[p+1]){continue;}
    auto q1=find(v[t[p]].begin(),v[t[p]].end(),p);
    auto q0=q1-1,q2=q1+1;
      auto r1=find(v[t[p+1]].begin(),v[t[p+1]].end(),p+1);
    auto r0=q1-1,r2=q1+1;
    if((p-(*q0))*((*q2)-p)*c[t[p]]+s[p][t[p]]+(p+1-(*r0))*((*r2)-p-1)*c[t[p+1]]+s[p+1][t[p+1]]-(p+1-(*q0))*((*q2)-p-1)*c[t[p]]+s[p+1][t[p]]+(p-(*r0))*((*r2)-p)*c[t[p+1]]+s[p][t[p+1]]<0){
      (*q1)=p+1;
      (*r1)=p;
      swap(t[p],t[p+1]);
    }
   
  }




}
     for(int i=0;i<d;i++)cout<<t[i]+1<<endl;


     }


 


 






    





      

        


Measured memory_bytes: 3764
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; ll k; cin >> n >> k;
  vector<ll> a(n); REP(i, n) cin >> a[i];
  sort(ALL(a));
  ll lb = -LINF, ub = LINF;
  while (ub - lb > 1) {
    ll mid = (lb + ub) >> 1;
    ll cnt = 0;
    REP(i, n) {
      if (a[i] < 0) {
        int l = i, r = n;
        while (r - l > 1) {
          int m = (l + r) >> 1;
          (a[i] * a[m] >= mid ? l : r) = m;
        }
        cnt += n - r;
      } else {
        int l = i, r = n;
        while (r - l > 1) {
          int m = (l + r) >> 1;
          (a[i] * a[m] >= mid ? r : l) = m;
        }
        cnt += l - i;
      }
    }
    // if (mid == -6) cout << cnt << '\n';
    // cout << mid << ' ' << cnt << '\n';
    (cnt < k ? lb : ub) = mid;
  }
  cout << lb << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    long double ans = 0;
    int n;
    cin >> n;
    vector<pair<int, int>> v;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        if(a|b){
            v.emplace_back(a, b);
        }
    }
    n = v.size();
    sort(v.begin(),v.end(), [](auto a, auto b){
        return atan2(a.first, a.second) < atan2(b.first, b.second);
    });
    for (int i = 0; i < n; ++i) {
        v.emplace_back(v[i]);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int l = i, r = j + (i > j ? n : 0);
            int y = 0, x = 0;
            for (int k = l; k <= r; ++k) {
                y += v[k].first; x += v[k].second;
            }
            ans = max(ans, hypot<long double>(y, x));
        }
    }
    printf("%.15Lf\n", ans);
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    string s;
    cin>>s;

    int c=0,c1=0;
    for(int i=0; i<3; i++)
    {
        if(s[i]=='A')
            c++;
        else
            c1++;
    }

    if(c>0 && c1>0)
        cout<<"Yes\n";
    else
    cout<<"No\n";




    return 0;
}


Measured memory_bytes: 256
from math import gcd

N = int(input())
A = list(map(int, input().split()))

g_all = A[0]
for a in A[1:]:
    g_all = gcd(g_all, a)

if g_all > 1:
    print('not coprime')
    quit()

def sieve(n):
    if n <= 1:
        return []
    elif n == 2:
        return [2]
    len_list = (n + 1) // 2
    len_sqrt = int(len_list**0.5) + 1
    flags = [True] * len_list
    flags[0] = False
    for i in range(len_sqrt):
        if flags[i]:
            w = i*2 + 1
            start = (w ** 2) // 2
            for j in range(start, len_list, w):
                flags[j] = False
    return [2] + [i*2+1 for i in range(len_list) if flags[i]]



appeared = [False] * (10**6 + 1)
primes = sieve(10**3)
for a in A:
    if a == 1:
        continue
    for p in primes:
        if a % p == 0:
            if appeared[p]:
                print('setwise coprime')
                quit()
            appeared[p] = True
            while a % p == 0:
                a //= p
    
    if a != 1:
        if appeared[a]:
            print('setwise coprime')
            quit()
        
        appeared[a] = True

print('pairwise coprime')

Measured memory_bytes: 205392
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

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

  int n;
  while (cin >> n, n) {
    int m[111], k;
    vector<vector<int>> p(n, vector<int>(111));
    rep(i, n) {
      cin >> m[i];
      rep(j, m[i]) { cin >> p[i][j]; }
    }
    cin >> k;
    vector<int> l(k);
    rep(i, k) cin >> l[i];

    int ans = -2;
    rep(i, n) {
      bool ok = true;
      vector<bool> used(m[i], true);
      rep(f, k) {
        bool flag = false;
        rep(j, m[i]) {
          if (l[f] == p[i][j] && used[j]) {
            flag = true;
            used[j] = false;
          }
        }
        ok &= flag;
      }
      if (ok) {
        if (ans == -2)
          ans = i + 1;
        else
          ans = -1;
      }
    }
    if (ans == -2) ans = -1;
    cout << ans << "\n";
  }

  return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>


#define BUF_SIZE 2000000
typedef unsigned char uchar;

int comp(const void* a, const void* b) {
  return *(int*)b - *(int*)a;
}

#define BUCKET_SIZE 200001

int main(void) {
  int num, kind;
  char line[BUF_SIZE];
  FILE* fp = stdin;
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  sscanf(line, "%d %d", &num, &kind);

  int i;
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  char *tmpbuf = line;
  long sz = sysconf(_SC_PAGESIZE);
  long pagesize = sizeof(int)*(num+1)+(sz-1)/sz;
  // void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
  int* hist = mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  // int hist[BUCKET_SIZE] = {0};
  for(i = 0; i < num; i++) {
    char* tmp = strtok(tmpbuf, " ");
    int n = strtol(tmp, NULL, 10);
    hist[n]++;
    tmpbuf = NULL;
  }
  qsort(hist, num+1, sizeof(int), comp); //descending order

  int sum = 0;
  for(i = kind; i < num+1 && hist[i] != 0; i++) {
    sum += hist[i];
  }
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);

//探索する方向を確認
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};


int main(){
  int H, W;
  cin >> H >> W;
  //端っこだけ，for文を分けると難しい？
  vector<string> s(H);
  REP(h,H) cin >> s[h];

  REP(h,H) REP(w,W){
    int cnt = 0;
    if(s[h][w] == '.'){
      REP(dir,8){
        int nh = h +dx[dir];
        int nw = w +dy[dir];
        //範囲外はスキップ
        if(nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
        if(s[nh][nw] == '#') ++cnt;
      }
      s[h][w] = cnt + '0';
    }
  }

  REP(h,H){
    cout << s[h] << endl;
  }

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int X,A,B;
	cin>>X>>A>>B;
	ce((X-A)%B)

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  uint64_t N;
  cin >> N;

  if (N == 1LL) {
    cout << 1;
  }
  else {    
    uint64_t a = 1;
    uint64_t b = 2;  
    uint64_t c;
    for (uint64_t i = 0; i < N - 1; i++) {
      c = a + b;
      b = a;
      a = c;
    }
    cout << c;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main implements Runnable {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int[][][] undirectedGraph(int n, int[] v1, int[] v2, int[] cost) {
		int[] cnt = new int[n];
		for (int i : v1) cnt[i]++;
		for (int i : v2) cnt[i]++;

		int[][][] g = new int[n][][];
		for (int i=0; i<n; i++) g[i] = new int[cnt[i]][2];
		for (int i=0; i<v1.length; i++) {
			int s = v1[i];
			int t = v2[i];

			g[s][--cnt[s]][0] = t;
			g[s][cnt[s]][1] = cost[i];

			g[t][--cnt[t]][0] = s;
			g[t][cnt[t]][1] = cost[i];
		}

		return g;
	}

	static ArrayList<Integer> articularionPoint(int[][][] g) {
		int n = g.length;
		int[] low = new int[n];
		int[] ord = new int[n];
		Arrays.fill(ord, -1);
		ArrayList<Integer> res = new ArrayList<>();

		for (int cur=0; cur<n; cur++) {
			if (ord[cur] == -1) {
				dfsAP(g, cur, low, ord, new int[]{0}, res);
			}
		}

		res = new ArrayList<>(new HashSet<>(res));
		Collections.sort(res);

		return res;
	}

	static void dfsAP(int[][][] g, int cur, int[] low, int[] ord, int[] p, ArrayList<Integer> res) {
		low[cur] = ord[cur] = p[0]++;
		for (int[] to : g[cur]) {
			int next = to[0];
			if (ord[next] == -1) {
				dfsAP(g, next, low, ord, p, res);
				low[cur] = Math.min(low[cur], low[next]);
				if ((ord[cur] == 0 && ord[next] != 1) || (ord[cur] != 0 && low[next] >= ord[cur])) {
					res.add(cur);
				}
			} else {
				low[cur] = Math.min(low[cur], ord[next]);
			}
		}
	}

	public void run() {
		int v = in.nextInt();
		int e = in.nextInt();
		int[] s = new int[e];
		int[] t = new int[e];
		int[] c = new int[e];
		for (int i=0; i<e; i++) {
			s[i] = in.nextInt();
			t[i] = in.nextInt();
			c[i] = 0;
		}

		int[][][] g = undirectedGraph(v, s, t, c);
		ArrayList<Integer> ans = articularionPoint(g);
		for (int i=0; i<ans.size(); i++) {
			out.println(ans.get(i));
		}

		out.flush();
		in.close();
		out.close();
	}

	public static void main(String[] args) {
		new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 68920