akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint arr[100000], N, M;

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

int main() {
	cin >> N >> M;
	lint curr_lcm = 1;
	lint minv = INF;
	REP(i, N) {
		cin >> arr[i];
		chmin(minv, arr[i]);
	}
	lint com_cnt = 0;
	{
		lint curr = minv;
		while (curr > 1 && curr % 2 == 0) {
			com_cnt++;
			curr /= 2;
		}
	}
	REP(i, N) {
		lint curr = arr[i], cnt = 0;
		while (curr > 1 && curr %2 == 0) {
			cnt++;
			curr /= 2;
		}
		if (com_cnt != cnt) {
			cout << 0 << endl;
			return 0;
		}
		curr_lcm = curr_lcm * arr[i] / gcd(curr_lcm, arr[i]);
		if (curr_lcm / 2 > M) {
			cout << 0 << endl;
			return 0;
		}
	}
	cout << 1 + (M - curr_lcm / 2) / curr_lcm << endl;
}


Measured memory_bytes: 4336
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#define MAX 200000

struct neta_t {
	int t, d;
};


/* おいしさの降順→ネタの昇順 */
int cmp(const void* a, const void* b) {
	const struct neta_t* x = (const struct neta_t*)a, *y = (const struct neta_t*)b;
	if (x->d > y->d) return -1;
	if (x->d < y->d) return 1;
	if (x->t < y->t) return -1;
	return x->t > y->t;
}

int N, K;
struct neta_t neta[MAX];
char tabeta_neta[MAX] = {0};
struct neta_t kisyutu_neta[MAX];
int kncount = 0;

void read_data(void) {
	int i;
	if (scanf("%d%d", &N, &K) != 2) exit(1);
	for (i = 0; i < N; i++) {
		if (scanf("%d%d", &neta[i].t, &neta[i].d) != 2) exit(1);
	}
}

int main(void) {
	int i;
	int64_t ans = 0;
	int64_t cans = 0;
	int64_t score = 0;
	int64_t syurui = 0;
	read_data();
	qsort(neta, N, sizeof(*neta), cmp);
	/* とりあえずおいしい順に食べる */
	for (i = 0; i < K; i++) {
		score += neta[i].d;
		if (tabeta_neta[neta[i].t]) {
			kisyutu_neta[kncount++] = neta[i];
		} else {
			syurui++;
		}
		tabeta_neta[neta[i].t] = 1;
	}
	ans = score + syurui * syurui;
	/* 種類数を稼いでみる */
	for (i = K; i < N; i++) {
		if (kncount > 0 && !tabeta_neta[neta[i].t]) {
			score -= kisyutu_neta[--kncount].d;
			score += neta[i].d;
			syurui++;
			tabeta_neta[neta[i].t] = 1;
			cans = score + syurui * syurui;
			if (cans > ans) ans = cans;
		}
	}
	printf("%"PRId64"\n", ans);
	return 0;
}


Measured memory_bytes: 1788
#include <stdio.h>
        #include <string.h>
         
        int main() {
         
        	char c[101];
        	char num,chl;
         
        	scanf("%s", &c);
         
        	num = strlen(c);
         
        	chl = c[(num - 1)];
         
        	printf("%c%d%c",c[0],(num-2),chl);
         
        	return 0;
         
        }

Measured memory_bytes: 128
/*
	i need all of her, what if she doesn't even want any of me
*/
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Os")
 
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define mp make_pair
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=3e5+10, maxm=1e7+10, lg=16, mod=998244353, inf=1e18;

ll n,cr,cg,cb;
string s;

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n>>s;
	ll ans=1; for(int i=1;i<=n;i++) ans*=i, ans%=mod;
	for(int i=0;i<3*n;i++){
		vector<ll> v={cr,cg,cb};
		sort(all(v),greater<ll>());
		ll x;
		if(s[i]=='R') x=cr++;
		if(s[i]=='G') x=cg++;
		if(s[i]=='B') x=cb++;
		if(v[0]==x);
		else if(v[1]==x) ans*=v[1]-v[0], ans%=mod;
		else ans*=v[2]-v[1], ans%=mod;
	}
	cout<<ans;
	
	return 0;
}






Measured memory_bytes: 720
#include <stdio.h>
 
#define INT_MIN (1)
#define INT_MAX (1000000000)
#define SUCCESS (0)
#define FAILURE (-1)
 
int gcd(int x, int y);
void swap(int *x, int *y);
int judge_constraint(int test_num, int min, int max);
 
int main(void){
    int x;
    int y;
     
    scanf("%d%d", &x, &y);
     
    if(judge_constraint(x, INT_MIN, INT_MAX) == FAILURE)
    {
        return FAILURE;
    }
     
    if(judge_constraint(y, INT_MIN, INT_MAX) == FAILURE)
    {
        return FAILURE;
    }
     
    printf("%d\n", gcd(x,y));
     
    return SUCCESS;
}
 
int gcd(int x, int y)
{
    int r;
     
    if(x < y)
    {
        swap(&x, &y);
    }
     
    while(y > 0)
    {
        r = x % y;
        x = y;
        y = r;
    }
     
    return x;
}
 
 
void swap(int *x, int *y)
{
    int tmp = *x;
    *x = *y;
    *y = tmp;
     
    return;
}
 
int judge_constraint(int test_num, int min, int max)
{
    if(test_num < min || test_num > max)
    {
        return FAILURE;
    }
     
    return SUCCESS;
}

Measured memory_bytes: 1856
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}


const int n_max = 100005;
int n;

struct edge{
    int to,cost;
};

vector<edge> E[n_max];
int dist[n_max];
int par[n_max];


void dijkstra(int v){
    reversed_priority_queue< pair<int,int> > Q;
    Q.push( mp(0,v) );
    REP(i,n) dist[i] = INF;
    REP(i,n) par[i] = -1;
    dist[v] = 0;
    bool used[n];
    REP(i,n) used[i] = false;
    while(Q.size()){
        int now = Q.top().se;
        Q.pop();
        if(used[now]) continue;
        used[now] = true;
        itrfor(itr,E[now]){
            if(dist[itr->to] > dist[now] + itr->cost  ){
                Q.push( mp(itr->cost + dist[now], itr->to) );
                par[itr->to] = now;
                dist[itr->to] = itr->cost + dist[now];
            } 
        }
    }

}


signed main(){
    int m,s;
    cin >> n >> m >> s;
    REP(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        E[a].push_back( edge{b,c} );
    }
    dijkstra(s);
    REP(i,n){
        if(dist[i] != INF){
            cout << dist[i] << endl;
        }
        else{
            cout << "INF" << endl;
        }
    }   
}


Measured memory_bytes: 20292
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, C[202020];
i64 dp[202020];
int last[202020];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%d", C + i);
		--C[i];
	}
	for (int i = 0; i < 202020; ++i) last[i] = -1;
	dp[0] = 1;
	for (int i = 0; i < N; ++i) {
		dp[i + 1] = dp[i];
		if (last[C[i]] != -1 && last[C[i]] != i - 1) {
			ADD(dp[i + 1], dp[last[C[i]] + 1]);
		}
		last[C[i]] = i;
	}
	printf("%lld\n", dp[N]);
	return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int a;
  cin >> a;
  string s;
  cin >> s;
  cout << (a>=3200 ? s : "red") << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a


def prime_factor(n):
    a=[]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            a.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        a.append(n)
    return set(a)




n=int(input())
L=list(map(int,input().split()))
val = L[0]

for i in range(1,n):
    val = gcd(L[i],val)

if val!=1:
    print('not coprime')
    sys.exit()

d={}
for i in range(n):
    factor=prime_factor(L[i])
    for j in factor:
        if j not in d:
            d[j]=1
        else:
            print('setwise coprime')
            sys.exit()
print('pairwise coprime')




Measured memory_bytes: 174292
words = ['dream', 'dreamer' ,'erase' ,'eraser']
t = ''
s = input()

s = s[::-1]
words = [word[::-1] for word in words]

start=0
for i in range(1, len(s)+1):
  if s[start:i] in words:
    t+=s[start:i]
    start=i
    
if s==t:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main() {
    int f,t,x;
    set<int>s;
    cin>>t;
    while(t--) {
        cin>>f>>x;
        if(f==0) {
            s.insert(x);
            cout<<s.size()<<endl;
        }
        else if(f==1) {
            cout<<s.count(x)<<endl;
        }
    }
    return 0;
}





Measured memory_bytes: 12372
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

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

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

    sort(ALL(a));
    cout << a[N - 1] - a[0] << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 100005;
const int mod = 998244353;

lint dp[2][2][32];
int arr[MAXN][5];

int getbit(int x, int y){ return (x >> y) & 1; }

bool compat(int pos, int msk){
	for(int i=0; i<5; i++){
		if(arr[pos][i] == -1) continue;
		if(getbit(msk, i) != arr[pos][i]) return 0;
	}
	return 1;
}

lint solve(int n){
	for(int i=0; i<32; i++){
		for(int j=0; j<32; j++){
			bool valid = compat(0, i) && compat(1, j);
			if((getbit(i, 2) + getbit(i, 3) + getbit(j, 1) + getbit(j, 2)) % 2 == 1) valid = 0;
			if(valid) dp[1][i >> 4][j]++;
		}
	}
	for(int i=1; i<n-1; i++){
		memset(dp[(i+1)%2], 0, sizeof(dp[0]));
		for(int j=0; j<2; j++){
			for(int k=0; k<32; k++){
				dp[i%2][j][k] %= mod;
				if(!dp[i%2][j][k]) continue;
				int idx1 = getbit(k, 4);
				for(int idx2 = 0; idx2 < 32; idx2++){
					if(compat(i + 1, idx2) && (j + getbit(idx2, 0) + getbit(k, 2)) % 2 == 0 && 
						(getbit(k, 2) + getbit(k, 3) + getbit(idx2, 1) + getbit(idx2, 2)) % 2 == 0){
						dp[(i+1)%2][idx1][idx2] += dp[i%2][j][k];
					}
				}
			}
		}
	}
	lint ret = 0;
	for(int i=0; i<2; i++){
		for(int j=0; j<32; j++){
			ret += dp[(n-1)%2][i][j];
		}
	}
	return ret % mod;
}

lint ipow(lint x, lint p){
	lint ret = 1, piv = x;
	while(p){
		if(p & 1) ret = ret * piv % mod;
		piv = piv * piv % mod;
		p >>= 1;
	}
	return ret;
}

int main(){
	int n, m;
	map<pi, int> mp;
	scanf("%d %d",&n,&m);
	memset(arr, -1, sizeof(arr));
	arr[0][0] = arr[0][1] = arr[1][0] = 0;
	arr[n-1][3] = arr[n-1][4] = arr[n-2][4] = 0;
	for(int i=0; i<m; i++){
		int x, y, z;
		scanf("%d %d %d",&x,&y,&z);
		x--; y--;
		if(abs(x - y) <= 2){
			arr[x][y-x+2] = z;
		}
		else{
			if(x > y) swap(x, y);
			if(mp.find(pi(x, y)) != mp.end()){
				if(mp[pi(x, y)] != z){
					puts("0");
					return 0;
				}
			}
			else mp[pi(x, y)] = z;
		}
	}
	lint free = 0;
	for(int i=1; i<=n; i++){
		free += max(0, n - 2 - i);
	}
	free -= mp.size();
	cout << solve(n) * ipow(2, free) % mod << endl;
}


Measured memory_bytes: 5376
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto nodes = new BiNode[](n);

  auto prN = readln.split.to!(int[]); prN[] -= 1;
  auto inN = readln.split.to!(int[]); inN[] -= 1;

  auto root = createNodes(nodes, prN, inN);
  auto poN = postorderWalk(nodes, nodes[root]); poN[] += 1;

  writeln(poN.to!(string[]).join(" "));
}

int createNodes(ref BiNode[] nodes, ref int[] prN, ref int[] inN)
{
  if (inN.empty) return -1;

  auto cr = prN.front;
  prN.popFront;

  auto sp = inN.findSplit([cr]);
  auto l = createNodes(nodes, prN, sp[0]);
  auto r = createNodes(nodes, prN, sp[2]);

  nodes[cr] = new BiNode(cr, l, r);
  return cr;
}

int[] postorderWalk(BiNode[] nodes, BiNode node)
{
  int[] r;
  if (node.l != -1) r ~= postorderWalk(nodes, nodes[node.l]);
  if (node.r != -1) r ~= postorderWalk(nodes, nodes[node.r]);
  r ~= [node.id];
  return r;
}

class BiNode
{
  int id;
  int parent;
  int l, r;

  this(int id, int l, int r)
  {
    this.id = id;
    this.parent = -1;
    this.l = l;
    this.r = r;
  }

  bool isRoot()
  {
    return parent == -1;
  }
}

Measured memory_bytes: 2524
N=int(input())
x=[0]*N
y=[0]*N
for i in range(N):
  x[i], y[i] = map(int, input().split())

import numpy as np

d=[0]*N*(N-1)
k=0
for i in range(N):
  for j in range(N):
    if i!=j:
      a=np.array([x[i], y[i]])
      b=np.array([x[j], y[j]])
      u=b-a
      d[k]=np.linalg.norm(u)
      k+=1

ans=sum(d)/N
print(ans)



Measured memory_bytes: 12504
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define min(a, b) a < b ? a : b
#define max(a, b) a > b ? a : b

int main(void)
{
	long long i;
	long long N;
	long long min = 0, push = 0;
	scanf("%lld", &N);

	long long a[N], b[N];

	for (i = 0; i < N; i++) {
		scanf("%lld %lld", &a[i], &b[i]);
	}
	
	for (i = N - 1; i >= 0; i--) {
		//printf("%lld %lld\n", a[i], b[i]);
		if (a[i] == 0 || b[i] == 1) {
			continue;
		} else {
			a[i] += min;
			if (a[i] <= b[i]) {
				push = b[i] - a[i];
				min += push;
			} else if((a[i] % b[i])) {
				push = b[i] - (a[i] % b[i]);
				min += push;
			}
		}
	}
	printf("%lld\n", min);

	return (0);
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

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

    vector<long long int> H;

    for (int i = 0; i <N; i++){
        long long int tmp;
        cin >> tmp;
        H.push_back(tmp);
    }

    sort(H.begin(),H.end(),greater<long long int>());

    long long int n_attack=0;

    for (int i = K; i <N; i++){
        n_attack+=H[i];
    }

    cout << n_attack;
    

    return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
using namespace std;
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)

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

    int N, A, B;
    cin >> N >> A >> B;

    ll ans1, ans2;
    ans1 = min(A, B);
    ans2 = max(0, (A + B - N));
    
    cout << ans1 << " " << ans2 << "\n";
}

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

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
const int MAX_N=1e5*2;
int bit[MAX_N+10], n;
ll a[100000];
int sum(int i){
    int s=0;
    while(i>0){
        s+=bit[i];
        i-=i&-i;
    }
    return s;
}

void add(int i, int x){
    while(i<=MAX_N+10){
        bit[i]+=x;
        i+=i&-i;
    }
}
bool C(ll x){
    int s[n+1];
    s[0]=1e5+1;
    ll res=0;
    rep(i,0,n){
        if(a[i]<=x){
            s[i+1]=s[i]+1;
        }
        else s[i+1]=s[i]-1;
    }
    rep(i,0,n+1){
        res+=sum(s[i]-1);
        add(s[i],1);
    }
    if(res<ll(n)*(n+1)/4+1) return false;
    else return true;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    rep(i,0,n) cin>>a[i];
    ll ng=0, ok=1e9;
    while(ok-ng>1){
        ll mid=(ng+ok)/2;
        if(C(mid)) ok=mid;
        else ng=mid;
        memset(bit, 0, sizeof(bit));
    }
    cout <<ok<<"\n";
}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

ostream& operator<<(ostream& os,const tuple<int,int,int>& t){
	return os<<'('<<get<0>(t)<<','<<get<1>(t)<<','<<get<2>(t)<<')';
}

int main()
{
	for(int n;cin>>n && n;){
		vi ts(n),cs(n);
		rep(i,n) cin>>ts[i]>>cs[i];
		
		queue<tuple<int,int,int>> q[2]; // (index,lap,time)
		rep(i,n) q[1].emplace(i,0,0);
		
		int res=-1;
		for(;;){
			if(q[0].empty() && q[1].empty()) break;
			int cur=0,next=1;
			if(q[1].size() && (q[0].empty() || get<2>(q[1].front())<get<2>(q[0].front())))
				cur=1,next=0;
			
			int t=get<2>(q[cur].front());
			vector<tuple<int,int,int>> buf;
			while(q[cur].size() && t>=get<2>(q[cur].front())){
				int i,lap,time; tie(i,lap,time)=q[cur].front(); q[cur].pop();
				if(cur==1) lap++;
				if(lap>cs[i]){
					res=t;
					continue;
				}
				buf.emplace_back(i,lap,t+ts[i]);
			}
			
			sort(all(buf),[](tuple<int,int,int> a,tuple<int,int,int> b){return get<2>(a)<get<2>(b);});
			for(auto t:buf) q[next].emplace(t);
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1220
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int n,k;
      cin >> n >> k;
      ll h[n];
      rep(i,n)cin >> h[i];
      ll ans=inf;
      sort(h,h+n);
      for(int i=0;i+k-1<=n-1;i++){
        ll x=h[i+k-1]-h[i];
        ans=min(ans,x);
      }
      cout << ans << endl;
      return 0;}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main(void){
	int n;
	string s;
	cin>>n;
	cin>>s;
	int ans = 0;
	rep(i,n-1){
		bool aru[26];
		rep(j,26){
			aru[j] = false;
		}
		rep(j,i+1){
			aru[s[j]-'a'] = true;
		}
		int memo=0;
		for(int j=i+1; j<n;j++){
			if(aru[s[j]-'a']){
				memo++;
				aru[s[j] - 'a'] = false;
			}
		}
		ans=max(ans,memo);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 892
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<algorithm>
#include<iostream>
using namespace std;

int N;
//+ 0 even odd even 0
long long x,dp[5]={};
int main(){
  cin>>N;
  while(N--){
    cin>>x;
    dp[4]=min({dp[0],dp[1],dp[2],dp[3],dp[4]})+x;
    dp[3]=min({dp[0],dp[1],dp[2],dp[3]})+(!x)*2+(x&1);
    dp[2]=min({dp[0],dp[1],dp[2]})+(~x&1);
    dp[1]=min(dp[0],dp[1])+(!x)*2+(x&1);
    dp[0]=dp[0]+x;
  }
  cout<<(*min_element(dp,dp+5))<<endl;
}

Measured memory_bytes: 256
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	map<string,int> mp;
	int sum = 0;
	rep(i,n){
		string s;
		cin >> s;
		sort(all(s));
		++mp[s];
		sum += mp[s]-1;
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 11264
#include <stdio.h>
#include <math.h>
#define rep(i,l,n) for(i=l;i<n;i++)

int main(void){
	int sum,i,s[1001];
	double m,a2n,a2,a,n;
	
	while(1){
		scanf("%lf",&n);
		if(n==0) break;
		sum=0;
		a2n=0;
		rep(i,0,n){
			scanf("%d",&s[i]);
			sum+=s[i];
		}
		m=sum/n;
		rep(i,0,n){
			a2n+=pow(s[i]-m,2);
		}
		a2=a2n/n;
		a=pow(a2,0.5);
		printf("%10.10lf\n",a);
	}
	return 0;
}


Measured memory_bytes: 2928
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;
long ggd(long a, long b) {//最小公倍数，最大公約数
	if(a<b)swap(a,b);
	if (b == 0) {
		return a;			
	}
	return ggd(b, a % b);
}
long lcm(long number1,long number2){
	return number1/ggd(number1,number2)*number2;	
}


int main(){
    ll a,b,c,d;
    std::cin >> a>>b>>c>>d;
    ll aa,bb,cc;
    aa=(b/c)-ceil(dou(a)/c)+1;
    bb=(b/d)-ceil(dou(a)/d)+1;
    c=lcm(d,c);
    cc=(b/c)-ceil(dou(a)/c)+1;
   // std::cout << aa<<' '<<bb<<' '<<cc << std::endl;
    std::cout << b-a+1-aa-bb+cc << std::endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
typedef pair<int,int> pii;
#define mp make_pair
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
int h,w,n;
int main()
{
	h=gi();w=gi();n=gi();
	if(h<w)swap(h,w);
	printf("%d\n",(n+h-1)/h);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
typedef pair<ll,ll> cp2;
typedef pair<ll,cp2> cp3;
#define fi first
#define se second
#define sec se.fi
#define thr se.se
const ll mod = 1000000007;
//              123456789

int s[105];

int main(){
	int n, p;
	
	cin >> n;
	
	REP(i,n){
		cin >> p;
		
		s[p]++;
	}
	
	int max = 0;
	
	for (int i = 100; i > 0; i--){
		s[i-1] += s[i];
		
		if (s[i] >= i){
			max = i;
			break;
		}
	}
	
	cout << max << endl;
	
	return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
char H[200005],T[200005];

int main()
{
	string S;
	cin >> S;
	int Q;
	cin >> Q;
	bool rev = false;
	string temp = S;
	int cntH = 0, cntT = 0;
	rep(i,Q)
	{
		int t;
		cin >> t;
		if (t == 1)
		{
			if (rev) rev = false;
			else rev = true;
		}
		else
		{
			int f;
			char c;
			cin >> f >> c;
			if (!rev)
			{
				if (f == 1)
				{
					H[cntH] = c;
					cntH++;
				}
				else
				{
					T[cntT] = c;
					cntT++;
				}
			}
			else
			{
				if (f == 1)
				{
					T[cntT] = c;
					cntT++;
				}
				else
				{
					H[cntH] = c;
					cntH++;
				}
			}
		}
	}
	if (rev)
	{
		rep(i,cntT)
		{
			cout << T[cntT-1-i];
		}
		reverse(S.begin(), S.end());
		cout << S;
		rep(i,cntH)
		{
			cout << H[i];
		}
	}
	else
	{
		rep(i,cntH)
		{
			cout << H[cntH-1-i];
		}
		cout << S;
		rep(i,cntT)
		{
			cout << T[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int a, b;
    cin >> a >> b;
    if(a<=b){
        rep(i, b){
            cout << a;
        }
    }else{
        rep(i, a){
            cout << b;
        }
    }
    cout << endl;
    return 0;
}

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

string s[55];
int h,w;

int f(int y,int x){
  int res = 0;
  rep(a,3){
    rep(b,3){
      if(y+a-1<0||h<=y+a-1||x+b-1<0||w<=x+b-1) continue;
      if(s[y+a-1][x+b-1] == '#') res++;
    }
  }
  return res;
}


int main(){
  cin >> h >> w;
  rep(y,h){
    cin >> s[y];
  }
  rep(y,h){
    rep(x,w){
      if(s[y][x] == '#') cout << '#';
      else cout << f(y,x);
    }
    cout << endl;
  }
  return 0;
}


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

int main()
{
    int N, M, C;
    cin >> N >> M >> C;

    int B[M];
    for (int i = 0; i < M; ++i)
        cin >> B[i];

    int A[N][M];
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < M; ++j)
            cin >> A[i][j];

    int judge, ans = 0;
    for (int i = 0; i < N; ++i)
    {
        judge = C;
        for (int j = 0; j < M; ++j)
            judge += A[i][j] * B[j];
        if (judge > 0)
            ++ans;
    }
    cout << ans << endl;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    vector<string> b(m);
    for(int i = 0;i < n;i++)cin >> a.at(i);
    for(int i = 0;i < m;i++)cin >> b.at(i);
    for(int ay = 0;ay < n;ay++){
        for(int ax = 0;ax < n;ax++){
            if(n - m + 1 <= ay || n - m + 1 <= ax)break;
            bool judge = true;
            for(int by = 0;by < m;by++){
                for(int bx = 0;bx < m;bx++){
                    if(a.at(ay + by).at(ax + bx) != b.at(by).at(bx))judge = false;
                }
            }
            if(judge){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
# include <stdio.h>
# include <stdlib.h>
long long int max (long long int a,long long int b){
	if (a<b) return b;
	else return a;
}
int abs(int n){
	if(n<=0) return (-1*n);
	else return n;
}
int main(){
	int i,n,k,a,capa,*weight,j;
	long long int *val,b;
	scanf ("%d %d",&n,&capa);
	weight=(int*)malloc(n*sizeof(int));
	val=(long long int*)malloc(n*sizeof(long long int));
	for(i=0;i<n;i++){
		scanf ("%d %lld",&weight[i],&val[i]);
	}
	long long int *ans;
	ans=(long long int*)malloc((capa+1)*sizeof(long long int));
	for(i=0;i<capa+1;i++) ans[i]=-1;
	ans[0]=0;
	long long int res=0;
	for(i=0;i<n;i++){
		for(j=capa;j>=weight[i];j--){
			ans[j]=max(ans[j],ans[j-weight[i]]+val[i]);
			if (ans[j]>res) res=ans[j];
		}
	}
	printf ("%lld\n",res);
	return 0;
}

Measured memory_bytes: 2508
S = str(input())
T = str(input())
ans = 1001
for i in range(len(S)-len(T)+1):
    S_t = S[i:i+len(T)]
    count = 0
    for j in range(len(T)):
        if S_t[j]!=T[j]:
            count +=1
    ans = min(count,ans)
print(ans)

Measured memory_bytes: 9112
import java.util.Scanner
val sc = Scanner(System.`in`)

fun main(args: Array<String>) {
    val a = sc.nextInt()
    val b = sc.nextInt()
    var k = sc.nextInt()

    for(i in 100 downTo 1){
        if(a%i==0&&b%i==0) k--
        if(k==0) {
            println(i)
            return
        }
    }
}

Measured memory_bytes: 31276
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>

#define MAX_N (100000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  char S[MAX_N + 1];
  scanf("%s", S);
  const int N = strlen(S);

  // solve
  int cnts[3] = {};
  for (int i = 0; i < N; i++) {
    cnts[S[i] - 'a']++;
  }
  if (abs(cnts[0] - cnts[1]) <= 1 && abs(cnts[1] - cnts[2]) <= 1 &&
      abs(cnts[2] - cnts[0]) <= 1) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}


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

#define ll     long long
#define fr     first
#define sec    second
#define rep(i,n)  for(i=0;i<n;i++)
#define vi     vector <int>
#define vc     vector <char>
#define vl     vector <ll>
#define vb     vector <bool>
#define pb     push_back
#define M      1000000007
#define ios    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open   freopen("input.txt","r",stdin);
#define close  freopen("output.txt","w",stdout);
#define M_PI   3.14159265358979323846
#define pp     pair<int,int>
#define nn 100003
#define MM 1000000000
#define MN 1000000000000000000
int main()
{
    ios;
    string s;
    cin>>s;
    if(s.compare("ABC")==0)
        cout<<"ARC";
    else
        cout<<"ABC";
    
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll,ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll T=1;
//	cin >> T;
	ll t=0;
	while(t++<T){
    ll N;
    cin >> N;
    string s;
    cin >> s;
    string t;
    ll nw=0,nr=0;
    fo(i,N) {
        if(s[i]=='W')nw++;
        else nr++;
    }
    fo(i,nr) t+='R';
    fo(i,nw) t+='W';
    nw=0;
    fo(i,N) if(s[i]!=t[i]) nw++;
    cout << nw/2 << endl;
	}
return 0;
}


Measured memory_bytes: 3856
N,K=map(int, input().split())
A=list(map(int, input().split()))

ans = float('inf')

for i in range(0,N-K+1):
    ans = min(ans,abs(A[i])+abs(A[i]-A[i+K-1]),abs(A[i+K-1])+abs(A[i]-A[i+K-1]))

print(ans)


Measured memory_bytes: 14224
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,A,B,C,D = Is()
s = S()
if "##" in s[A-1:C] or "##" in s[B-1:D]:
    print("No")
elif C < D:
    print("Yes")
elif C > D:
    if "..." in s[B-2:D+1]:
        print("Yes")
    else:
        print("No")


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

int N, K;

double solve(void) {
	int point;
	double val;
	double ret = 0.0;
	for (int i = 1; i <= N; ++i) {
		point = i;
		val = 1.0;
		while (point < K) {
			point *= 2;
			val *= 0.5;
		}
		ret += (1.0 / N) * val;
	}
	return ret;
}

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

	double ans = solve();

	cout << fixed << setprecision(11) << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
num_odd = 0
num_mul2 = 0
num_mul4 = 0
for a in A:
    if a % 4 == 0:
        num_mul4 += 1
    elif a % 2 == 0:
        num_mul2 += 1
    elif a % 2 == 1:
        num_odd += 1

ans = False
if num_mul2 == 0:
    if num_mul4 + 1>= num_odd:
        ans = True
else:
    if num_mul4 >= num_odd:
        ans = True
print('Yes' if ans else 'No')


Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>

using namespace std;



int main(){
    int a,b;
    cin >> a >> b;
    if (a>=13) cout << b << endl;
    else if( a>=6) cout << b/2 << endl;
    else cout << 0 << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,cnt1=0,cnt2=0;
  int hash[3]={0};
  cin>>a>>b>>c;
  hash[a-5]++;
  hash[b-5]++;
  hash[c-5]++;
  if((hash[0]==2)&&(hash[2]==1))
  {
    cout<<"YES";
  }
  else
  {
    cout<<"NO";
  }
  
  return 0;
}
  

Measured memory_bytes: 256
#B
n = int(input())
cnt_ac = 0
cnt_wa = 0
cnt_tle = 0
cnt_re = 0
for _ in range(n):
    s = input()
    if s == 'AC':
        cnt_ac += 1
    elif s == 'TLE':
        cnt_tle += 1
    elif s == 'WA':
        cnt_wa += 1
    else:
        cnt_re += 1

print('AC x {}'.format(cnt_ac))
print('WA x {}'.format(cnt_wa))
print('TLE x {}'.format(cnt_tle))
print('RE x {}'.format(cnt_re))

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<long long>
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define mp make_pair
#define endl '\n'
#define _ << ' '
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(min(a, d), min(b, c))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e18+1;
const ll N = 2e5;

int n, a[50], mx=0, p=0, ind;
vector<int> neg, pos;
vector< pair<int, int> > ans;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("B.txt", "r", stdin);
    #endif
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        if(a[i] < 0)
        {
            neg.pb(i+1);
            if(abs(a[i])>mx)
            {
                mx = abs(a[i]);
                p = 1; ind = i+1;
            }
        }
        else if(a[i] > 0)
        {
            pos.pb(i+1);
            if(a[i]>mx)
            {
                mx = a[i];
                p = 0; ind = i+1;
            }
        }
    }
    if(p)
    {
        for(auto i : pos)
        {
            ans.pb({ind, i});
        }
        for(int i=n-2; i>=0; i--)
        {
            ans.pb({i+2, i+1});
        }
    }
    else
    {
        for(auto i : neg)
        {
            ans.pb({ind, i});
        }
        for(int i=0; i<n-1; i++)
        {
            ans.pb({i+1, i+2});
        }
    }
    cout << sz(ans) << endl;
    for(auto p : ans) cout << p.F _ << p.S << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,c,p,i,a,b,d,e;
	a=0;
	scanf("%d %d",&n,&c);
		for(i=0;i<c;i++){
			scanf("%d",&p);
			a=a+p;
		}
	e=n+1;
	b=a/e;
	if(a%e!=0){
		b=b+1;
	}
	printf("%d\n",b);
	return 0;
}
		


Measured memory_bytes: 2112
while(True):
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    else:
        cnt = 0
        for i in range(1, n+1):
            for k in range(i+1, n+1):
                for l in range(k+1, n+1):
                    if i + k + l == x:
                        cnt += 1
        print(cnt)


Measured memory_bytes: 5596
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			string str = Console.ReadLine();

			if (n % 2 == 0)
			{
				if (str.Substring(0, n / 2).Equals(str.Substring(n / 2)))
				{
					Console.WriteLine("Yes");
					return;
				}
			}

			Console.WriteLine("No");
		}
	}

}


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

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

int main()
{
    char inp[10];
    scanf("%s", inp);

    sort(inp, inp + 4);
    if ((inp[0] == inp[1]) && (inp[2] == inp[3]) && (inp[0] != inp[2]))
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,C,D[2][5001],i,j,*A,*B;
main(){
    A=D[0],B=D[1];
    cin>>N;
    fill_n(*D,1e4+2,1e9);A[1]=B[0]=0;
    for(;i<N-1&&cin>>C;i++)for(j=N/2;~j;j--)A[j+1]=min(A[j],B[j]+C),B[j]=min(A[j]+C,B[j]);
    cout<<min(A[N/2],B[N/2])<<endl;
}

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

bool isPrime(int x) {
	int s = int(sqrt(double(x)));
	//cout << " " << s << endl;
	if (x == 2) return true;
	if (x % 2 == 0 || x <2)return false;
	for (int i = 2; i <= s+1; i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int main() {
	int n, x, cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		if (isPrime(x))cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int D, N;
	cin >> D >> N;
	if(N < 100)	cout << N;
	else cout << N+1;
	REP(i, 0, D) cout << "00";

}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int po(int m, int n) {
  int res = 1;
  for(int i=0;i<n;++i) {
    res *= m;
  }
  return res;
}

ll sum(int cb, int m, int n, int k, vector<int> dice) {
  ll res = 0;
  if(k == n) {
    for(int i=0;i<n;++i) {
      res += dice[i];
    }
    res = max(1ll, res - cb);    
  } else {
    dice.push_back(0);
    int last = SZ(dice)-1;
    for(int i=1;i<=m;++i) {
      dice[last] = i;
      res += sum(cb, m, n, k+1, dice);
    }
  }
  return res;
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  while(1) {
    int n, m, k; cin >> n >> m >> k;
    if(n == 0 && m == 0 && k == 0) break;
    vi dice;
    cout << sum(k, m, n, 0, dice) / (double)po(m, n) << endl;
  }
}



Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    Point[] lefts = new Point[N];
    Point[] rights = new Point[N];
    boolean[] visited = new boolean[N];

    for (int i = 0; i < N; i++) {
      int left = scanner.nextInt();
      int right = scanner.nextInt();
      lefts[i] = new Point(i, left);
      rights[i] = new Point(i, right);
    }
    Arrays.sort(lefts, (o1, o2) -> o2.pos - o1.pos);
    Arrays.sort(rights, Comparator.comparingInt(o -> o.pos));

    long leftd = 0;
    int c = 0;
    int l = 0;
    int r = 0;
    while (l < N && r < N) {
      while (l < N && (visited[lefts[l].id] || lefts[l].pos <= c)) l++;
      if (l < N) {
        leftd += lefts[l].pos - c;
        c = lefts[l].pos;
        visited[lefts[l].id] = true;
      }
      while (r < N && (visited[rights[r].id] || rights[r].pos >= c)) r++;
      if (r < N) {
        leftd += c - rights[r].pos;
        c = rights[r].pos;
        visited[rights[r].id] = true;
      }
    }
    leftd += Math.abs(c);

    long rightd = 0;
    for (int i = 0; i < N; i++) visited[i] = false;
    c = 0;
    l = 0;
    r = 0;
    while (l < N && r < N) {
      while (r < N && (visited[rights[r].id] || rights[r].pos >= c)) r++;
      if (r < N) {
        rightd += c - rights[r].pos;
        c = rights[r].pos;
        visited[rights[r].id] = true;
      }
      while (l < N && (visited[lefts[l].id] || lefts[l].pos <= c)) l++;
      if (l < N) {
        rightd += lefts[l].pos - c;
        c = lefts[l].pos;
        visited[lefts[l].id] = true;
      }
    }
    rightd += Math.abs(c);

    System.out.println(Math.max(leftd, rightd));
  }

  static class Point {
    final int id;
    final int pos;

    Point(int id, int pos) {
      this.id = id;
      this.pos = pos;
    }
  }
}


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

#define lint long long
#define P pair<int, int>

int main() {
    lint N, A, B;
    cin >> N >> A >> B;

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

    sort(v.begin(), v.end(), greater<lint>());

    double sum = 0;

    for(int i = 0; i < A; ++i){
        sum += (double)v[i] / A;
    }
    cout << setprecision(100) << sum << endl;

    lint num = v[A - 1];
    
    sort(v.begin(), v.end());

    lint n = upper_bound(v.begin(), v.end(), num) - lower_bound(v.begin(), v.end(), num);

    int cnt = v.end() - upper_bound(v.begin(), v.end(),num);

    lint ku, kl;
    if(num != v[N - 1]){
        ku = min(num, A - cnt); 
        kl = A - cnt;
    } else {
        ku = min(B, n);
        kl = A;
    }
    // cout << kl << " " << ku << endl;
    lint ans = 0;

    for(int k = kl; k <= ku; ++k){
        lint tmp = 1;
        for(int i = 1; i <= k; ++i){
            tmp *= (n - i + 1);
            tmp /= i;
        }
        // cout << tmp << endl;
        ans += tmp;
    }

    cout << ans << endl;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < 3; i++) {
		if (s.at(i) == t.at(i)) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
ans = ""
while (N != 0):
    if N % 2 == 0:
        ans = "0" + ans
    else:
        ans = "1" + ans
        N -= 1
    N //= -2
if ans == "":
    ans = "0"
print(ans)


Measured memory_bytes: 2940