akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;

const long long int MOD = 1000000007;
const int MAX_K = 101010;

long long int fac[MAX_K], finv[MAX_K], inv[MAX_K];

void com_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_K; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long int com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    com_init();
    int n;
    cin >> n;
    vector<int> a(n, -1);
    int num;
    rep(i, n + 1)
    {
        int x;
        cin >> x;
        x--;
        if(a[x] == -1)
        {
            a[x] = i;
        }
        else
        {
            num = a[x] + (n - i);
            break;
        }
    }
    //cout << num << endl;

    rep(i, n + 1)
    {
        int res = com(n + 1, i + 1);
        res = ((MOD + res) - com(num, i)) % MOD;
        cout << res << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 3968
require"matrix";n,m=gets.split.map &:to_i;s=n.times.map{gets.split.map(&:to_i)};p 8.times.map{|b|s.map{|w|Vector[b[2]*2-1,(b&2)-1,b[0]*2-1].dot w}.max(m).inject :+}.max||0

Measured memory_bytes: 2684
k = int(input())
n = 50
x, y = divmod(k, n)
ans = [i+x for i in range(n)]
for i in range(y):
    i %= n
    ans[i] += n
    for j in range(n):
        if i == j:
            continue
        ans[j] -= 1
print(n)
print(*ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) static_cast<int>((a).size())
#define fillchar(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i=int(a); i<=int(b); ++i)
#define irep(i, a, b) for(int i=int(a); i>=int(b); --i)
#define replr(i, a, b) rep(i, a, (b)-1)
#define reprl(i, a, b) irep(i, (b)-1, a)
#define repn(i, n) rep(i, 0, (n)-1)
#define irepn(i, n) irep(i, (n)-1, 0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<string> VS;
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os<<"("<<v.first<<", "<<v.second<<")"; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { os<<"["; repn(i, sz(v)) { if(i) os<<", "; os<<v[i]; } return os<<"]"; }
template<class T> bool setmax(T &_a, T _b) { if(_b>_a) { _a=_b; return true; } return false; }
template<class T> bool setmin(T &_a, T _b) { if(_b<_a) { _a=_b; return true; } return false; }
template<class T> T gcd(T _a, T _b) { return _b==0?_a:gcd(_b,_a%_b); }

int main() {
    int a, b, c, d, e, f, g;
    cin>>a>>b>>c>>d>>e>>f>>g;
    LL ans=0;
    rep(i, 0, 5) if(a>=i && d>=i && e>=i) {
        setmax(ans, b+LL(i*3)+LL(a-i)/2*2+LL(d-i)/2*2+LL(e-i)/2*2);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		if (Y%2 == 1) {
			System.out.println("No");
		} else {
			int tat = 2*X;
			int bi = 4*X;
			if (tat <= Y && Y <= bi) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 35804
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;

    vector<P> p(m);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        p[i] = make_pair(b, a);
    }
    sort(all(p));

    ll ans = 0;
    ll u = 0;
    rep(i, m) {
        ll a = p[i].second;
        ll b = p[i].first;
        if(u <= a) {
            u = b;
            ans++;
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 1792
#include <cstdlib>
#include <iostream>
#include <stack>

using namespace std;

char expr[10000];

int main() {
    stack<long> S;
    cin.getline(expr, 10000);
    char* s = expr;
    for (;;) {
        if (*s == '\0') { break; }
        if ('0' <= *s && *s <= '9') {
            S.push(strtol(s, &s, 10));
            if (*s == ' ') { ++s; }
        } else {
            long b = S.top(); S.pop();
            long a = S.top(); S.pop();
            long r = 0;
            switch (*s) {
                case '+':
                    r = a + b;
                    break;
                case '-':
                    r = a - b;
                    break;
                case '*':
                    r = a * b;
                    break;
            }
            ++s;
            if (*s == ' ') { ++s; }
            S.push(r);
        }
    }
    cout << S.top() << endl;
    return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n, m; cin >> n >> m;
	priority_queue<int, vector<int>> pq;
	while(n--) {
		int a; cin >> a;
		pq.push(a);
	}
	while(pq.size()) {
		int a = pq.top();
		pq.pop();
		if(m>0) {
			pq.push(a/2);
			m--;
		}else{
			long long ans = a;
			while(pq.size()) {
				long long b = pq.top();
				pq.pop();
				ans += b;
			}
			cout << ans << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<lli> vi;
typedef vector<vi> vvi;
#define MAXN 3005
const lli limit= 1000000000000000000ll;
int main(){__
	int n;
	cin >> n;
	lli ans = 1ll;
	vector<lli> num(n);
	for(int i=0; i < n; i++){
		cin >> num[i];
	}
	sort(num.begin(),num.end());
	for(int i =0; i < n; i++){
		lli x;
		x = num[i];
		lli res;
		if(__builtin_smulll_overflow(ans,x,&res)){
			cout << -1 << endl;
			return 0;
		}
		else{
			ans = res;
			if(ans > limit){
				cout<< -1 << endl;
				return 0;
			}
		}
	}
	if(ans > limit){
		cout << -1 << endl;
	}
	else{	
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3956
import numpy as np
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

H = int(input())
n_bin = len(bin(H)[2:])

ans = 2 ** n_bin - 1

print(ans)

Measured memory_bytes: 14620
MAX = 110000
MOD = 1000000007
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD
def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD

N, K = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
r = 0
for i in reversed(range(N)):
  r = (r+As[i]*COM(i, K-1))%1000000007
  r = (r-As[i]*COM(N-i-1, K-1))%1000000007
  #print(r)
print(r)


Measured memory_bytes: 27736
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

int main()
{
    long long X, Y, A , B, C;
    std::cin >> X >> Y >> A >> B >> C;
    std::vector<long long> p(A);
    std::vector<long long> q(B);
    std::vector<long long> r(C);
    for (long long i=0; i<A; ++i)
    {
        std::cin >> p[i];
    }

    for (long long i=0; i<B; ++i)
    {
        std::cin >> q[i];
    }
    for (long long i=0; i<C; ++i)
    {
        std::cin >> r[i];
    }

    auto func = [&](const long long lhs, const long long rhs){ return rhs < lhs; };
    std::sort(p.begin(), p.end(), func);
    std::sort(q.begin(), q.end(), func);
    std::sort(r.begin(), r.end(), func);

    p.resize(X);
    q.resize(Y);
    if (X + Y < C)
        r.resize(X + Y);

    auto total = p;
    for (long long i=0; i<q.size(); ++i)
        total.emplace_back(q[i]);
    for (long long i=0; i<r.size(); ++i)
        total.emplace_back(r[i]);

    std::sort(total.begin(), total.end(), func);
    long long result = 0;
    for (long long i=0; i<X+Y; ++i)
        result += total[i];

    std::cout << result;
}

Measured memory_bytes: 6464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];

  sort(all(d));

  if (n&1) {
    cout << 0 << endl;
  } else {
    cout << d[n/2]-d[n/2-1] << endl;
  }

}


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

int main(void) {
	int n;
	for(;scanf("%d", &n), n != -1;) {
		int i = 0;
		int j;
		static int a[1024];
		while(n != 0) {
			a[i++] = n % 4;
			n /= 4;
		}

		if(i == 0) {
			printf("0\n");
			continue;
		}

		for(j = i - 1; j >= 0; --j) printf("%d", a[j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
arr = [0]*10002

def calc(x,y,z):
  ans = (x**2 + y**2 + z**2 + x*y + y*z + z*x) 
  return ans

for x in range(1,100):
  for y in range(1,100):
    for z in range(1,100):
        arr[min(calc(x,y,z),10001)] += 1
        
for i in range(1,N+1):
  print(arr[i])

Measured memory_bytes: 9424
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/04/04.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC128
//
//

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

#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(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__

void solve(void){
  
  int N, M;
  
  cin >> N >> M;
  
  vector<int> L(M,0);
  vector<int> R(M,0);
    
  int maxL=0;
  int minR=100010;
  
  REP(i,M){
    cin >> L[i] >> R[i];
    chmax(maxL, L[i]);
    chmin(minR, R[i]);
  }
  
 // sort(ALL(L), greater<int>());
 // sort(ALL(R));
  
 // cout << R[0]-L[0]+1 << endl;
  
  int ans=minR-maxL+1;
  
  if(ans<0) ans=0;
  cout << ans << endl;
  
  return;
   
}

#define TESTCASES 1

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}




Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
    int n,i;
    scanf("%d",&n);
    
    int a[n],b[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    for(i=0;i<n;i++){
        b[i]=a[n-1-i];
    }
    
    for(i=0;i<n-1;i++){
        printf("%d ",b[i]);
    }
    printf("%d\n",b[n-1]);
    
    return 0;
}



Measured memory_bytes: 2036
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int a, b;
    while(cin >> a >> b, a||b){
        int max = a + b;
        char ans = 'A';
        range(i,1,5){
            cin >> a >> b;
            if(max < a + b){
                ans = 'A' + i;
                max = a + b;
            }
        }
        cout << ans << ' ' << max << endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>



using ll = long long;
const int M = 1000005;

int a[12][12];

using namespace std;
int main()
{
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> c(n);
	int T = 1001001001;
	int ans=T;
	for (int i= 0;i < n;i++) {
		cin >> c[i];
		for (int j = 0;j < m;j++)
			cin >> a[i][j];
	}//数値入力
	for (int s = 0;s < (1 << n);s++) {
		//買った買ってない判別
		vector<int> sk(m);
		int cost = 0;
		bool ok = true;
		for (int i = 0;i < n;i++) {
			if (s >> i & 1) {
				//買った
				cost +=c[i];//代金
				for (int j = 0;j < m;j++) {
					sk[j] += a[i][j]; //スキル上げ
				}
			}
		}
		for (int j = 0;j < m;j++) {
			if (sk[j] < x) 
				ok = false;
		}
		if (ok)
			ans = min(ans, cost);
	
	}
	if (ans == T) {
		cout << "-1";
	}
	else
		cout << ans;
}


Measured memory_bytes: 3632
#include<stdio.h>
int binarySearch(int n,int A[],int key);
int main(void){
	
	int n,q,S[1000000],T[1000000],i,count=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&T[i]);
	}
	
	for(i=0;i<q;i++){
		if(binarySearch(n,S,T[i])!=0){
			count++;
		}
	}
	
	printf("%d\n",count);
	
	return 0;
}

int binarySearch(int n,int A[],int key){
	
	int left=0,right=n,mid;
	
	while(left<right){
		mid=(left+right)/2;
		if(A[mid]==key){
			return 1;
		}
		else if(key<=A[mid]){
			right=mid;
		}
		else{
			left=mid+1;
		}
	}
	
	return 0;
}


Measured memory_bytes: 2276
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 2002;
int n, A, B, v[N], dp[N][N][2];
int calc(int i, int j, bool t) {
	int z = min(i, j) - 1;
	if (z == -1)
		return abs(v[i] - v[j]);
	int &ret = dp[i][j][t];
	if (ret != -1)
		return ret;
	if (!t)
		ret = max(calc(z, j, false), calc(z, j, true));
	else
		ret = min(calc(i, z, true), calc(i, z, false));
	return ret;
}
int main()
{
	scanf("%d%d%d", &n, &A, &B);
	for (int i = 0; i < n; ++i)
		scanf("%d", v + i);
	reverse(v, v + n);
	v[n] = A;
	v[n + 1] = B;
	memset(dp, -1, sizeof(dp));
	printf("%d\n", calc(n, n + 1, false));
	return 0;
}

Measured memory_bytes: 31616
// AOJ 1014: Computation of Minimum Length of Pipeline
// 2017.11.17 bal4u@uu

#include <stdio.h>
#include <string.h>

int qsize;
typedef struct { int a, b, c; } QUE;
QUE que[10002];

#define PARENT(i) ((i)/2)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

static void min_heapify(int i)
{
	int l, r, min;
	QUE qt;
	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].c < que[i].c) min = l; else min = i;
	if (r < qsize && que[r].c < que[min].c) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

int deq(int *a, int *b, int *c)
{
	if (qsize == 0) return 0;
	*a = que[0].a, *b = que[0].b, *c = que[0].c;
	que[0] = que[--qsize];
	min_heapify(0);
	return 1;
}

void enq(int a, int b, int c)
{
	int i, min;
	QUE qt;
	i = qsize++;
	que[i].a = a, que[i].b = b, que[i].c = c;
	while (i > 0 && que[min = PARENT(i)].c > que[i].c) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

typedef struct { int to[100], c[100]; } T;
T tbl[100];
int len[100];
char visited[100];

int main()
{
	int s, d, c, i, j, k, ans = 0;

	while (scanf("%d%d", &s, &d) && s > 0) {
		memset(visited, 0, sizeof(visited));
		memset(len, 0, sizeof(len));
		qsize = 0;
		ans = 0;
		for (i = 0; i < s; i++) {
			visited[i] = 1;
			for (j = 0; j < d; j++) {
				scanf("%d", &c);
				if (c > 0) enq(i, s+j, c);
			}
		}
		for (i = 0; i < d-1; i++) for (j = i+1; j < d; j++) {
			scanf("%d", &c);
			if (c > 0) {
				int ii = s+i, jj = s+j;
				k = len[ii], tbl[ii].to[k] = jj, tbl[ii].c[k] = c, len[ii]++;
				k = len[jj], tbl[jj].to[k] = ii, tbl[jj].c[k] = c, len[jj]++;
			}
		}

		k = 0; while (k < d) {
			int a, b;
			do deq(&a, &b, &c);
			while (visited[a] && visited[b]);
			k++;
			ans += c;
			if (visited[a]) a = b;
			visited[a] = 1;
			for (i = 0; i < len[a]; i++) {
				if (!visited[tbl[a].to[i]]) enq(a, tbl[a].to[i], tbl[a].c[i]);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

int main() {
  int A,B,C,X,Y;
  cin >> A>>B>>C>>X>>Y;
  if(A+B>2*C){
    if(X>Y){
      cout<<min(max(X,Y)*C*2,Y*C*2+(X-Y)*A)<<endl;
    }
    else{
      cout<<min(max(X,Y)*C*2,X*C*2+(Y-X)*B)<<endl;
    }
  }
  else{
    cout<<min(max(X,Y)*C*2,A*X+B*Y)<<endl;
  }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll h,w,n;
ll x[200010],y[200010];
vector<ll> ys[200010];

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

  cin>>w>>h>>n;
  rep(i,n){
    cin>>x[i]>>y[i];
    x[i]--; y[i]--;
    ys[x[i]].push_back(y[i]);
  }
  rep(j,w)sort(all(ys[j]));

  ll res=w,crt=1;
  rep(j,w-1){
    if(ys[j+1].size()==0){
      crt++; continue;
    }else{
      ll mny=ys[j+1][0];
      if(mny==crt)continue;
      if(mny<crt){
        res=j+1;
        break;
      }
      crt++;
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int MAX_N = 10010;
int res[2001000];
void CountingSort(int A[], int n)
{
    int num[MAX_N] = {};
    for(int i = 0; i < n; i++) num[A[i]]++;
    int pos = 0;
    for(int i = 0; i < MAX_N; i++)
    {
        while(num[i] != 0)
        {
            res[pos] = i;
            pos++;
            num[i]--;
        }
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int A[n + 1];
    for(int i = 0; i < n; i++) cin >> A[i];
    CountingSort(A, n);
    for(int i = 0; i < n; i++)
    {
        if(i) cout << " ";
        cout << res[i];
    }
    cout << endl;
    return 0;
}




Measured memory_bytes: 18876
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] p = new int[n + 1];
		String[] sa = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			p[i] = Integer.parseInt(sa[i]) - 1;
		}
		br.close();
		p[n] = Integer.MAX_VALUE;

		int ans = 0;
		int cnt = 0;
		for (int i = 0; i <= n; i++) {
			if (p[i] == i) {
				cnt++;
			} else {
				ans += (cnt + 1) / 2;
				cnt = 0;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35932
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
long long n, c;
int main(){
	scanf("%lld", &n);
	if(n%2) n = 0;
	for(n/=2;n;c+=n/=5);
	printf("%lld\n", c);
}

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


using namespace std;


const int MOD = 1000 * 1000 * 1000 + 7;


const int N = 10 * 1000 * 1000 + 6000;
const int NREV = 5005;

long long fact[N], revFact[N];

long long expo(long long a, long long n, long long mod) {
    long long ans = 1;

    while (n) {
        if (n & 1LL) ans = (ans * a) % mod;

        n >>= 1;
        a = (a * a) % mod;
    }

    return ans;
}

long long revMod(long long a, long long mod) {
    return expo(a, mod - 2, mod);
}

void pre() {
    fact[0] = revFact[0] = 1;

    for (int i = 1; i < N; i++) {
        fact[i] = (i * fact[i-1]) % MOD;
        
        if (i < NREV) {
            revFact[i] = revMod(fact[i], MOD);
        }
    }
}

long long binom(int n, int m) {
    if (m > n) return 0;

    long long res = (fact[n] * revFact[n-m]) % MOD;
    res = (res * revFact[m]) % MOD;

    return res;
}


int solve(int n, int a) {
    int ans = 0;
    int q = n - a;

    for (int notLoops = 1; notLoops <= a; notLoops++) {
        int ansHere = 0;

        vector <long long> values(a + 1);

        for (int x = 0; x <= a; x++) {
            long long summand = 1;

            summand = (summand * revFact[x]) % MOD;
            summand = (summand * notLoops) % MOD;
            summand = (summand * fact[notLoops + x + q - 1]) % MOD;

            values[x] = summand;
        }

        for (int x = 1; x <= a; x++) {
            values[x] = (values[x] + values[x-1]) % MOD;
        }

        for (int loops = 0; loops < a && loops <= a - notLoops; loops++) {
            int p = loops + notLoops;
            int m = max(a - p - 1, 0);

            long long sum = values[m];

            sum = (sum * binom(p, loops)) % MOD;
            sum = (sum * fact[m]) % MOD;

            if (loops % 2 == 0) {
                ansHere = (ansHere + sum) % MOD;
            } else {
                ansHere = (ansHere + MOD - sum) % MOD;
            }
        }

        ans = (ans + ansHere) % MOD;
    }

    return ans;
}


int main() {
    ios_base::sync_with_stdio(false);
    pre();

    int n, a;
    cin >> n >> a;

    cout << solve(n, a);

    return 0;
}


Measured memory_bytes: 81868
#include <cstdio>

typedef long long int64;

int64 f(int64 b, int64 n) {
	int64 res = 0;
	
	while(n) {
		res += n % b;
		n /= b;
	}
	return res;
}

int main() {
	int64 i, l, r, n, s, b;
	
	scanf("%lld %lld", &n, &s);
	if(n == s){
		printf("%lld\n", n + 1);
		return 0;
	}
	for(l=2; l<=n; l=r+1) {
		r=n/(n/l);
		if(l<=n/l) {
			for(i=l; i<=r; i++) {
				if(f(i, n) == s) {
					printf("%lld\n", i);
					return 0;
				}
			}
		}
		else {
			b = (n + n/l - s) / (n/l);
			if(l <= b and b <= r and f(b, n) == s) {
				printf("%lld\n", b);
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
l = 0
r = 10 ** 9 + 1
while l + 1 < r:
    p = (l + r) // 2
    n = 0
    ok = False
    for v in A:
        n += (v // p - 1)
        if not v % p == 0:
            n += 1
        if n > K:
            break
    else:
        ok = True
    if not ok:
        l = p
    else:
        r = p

print(r)



Measured memory_bytes: 104176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll h,w;cin >> h >>w;
    vector<vector<char>> g(h,vector<char>(w));
    rep(i,h)rep(j,w)cin >> g[i][j];
    set<ll> s;
    rep(i,h){
        bool check=true;
        rep(j,w){
            if(g[i][j]=='#')check=false;
        }
        if(check){
            rep(j,w){
                g[i][j]='x';
            }
            s.ins(i);
        }
    }
    rep(j,w){
        bool check=true;
        rep(i,h){
            if(g[i][j]=='#')check=false;
        }
        if(check){
            rep(i,h){
                g[i][j]='x';
            }
        }
    }
    rep(i,h){
        if(s.count(i))continue;
        rep(j,w){
            if(g[i][j]!='x')cout << g[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
x,k,d = map(int,input().split())
a = 0

if x < 0:
    a = abs(x)//d
    if k < a:
        x += k*d
        k = 0
    else:
        x += a*d
        k -= a
else:
    a = x//d
    if k < a:
        x -= k*d
        k = 0
    else:
        x -= a*d
        k -= a

if k != 0 and k % 2 == 1:
    b = abs(x-d)
    c = abs(x+d)
    x = min(b,c)

print(abs(x))

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

int main() {
  int R, G, B;
  cin >> R >> G >> B;

  if ((100 * R + 10 * G + B) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))

a1s = [0]
for i in range(n):
    a1s.append(a1s[-1] + a1[i])

a2s = [0]
for i in range(n):
    a2s.append(a2s[-1] + a2[i])

candy = []

for i in range(n):
    candy.append(a1s[i+1] + a2s[-1] - a2s[i])

print(max(candy))

Measured memory_bytes: 38384
fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length + 1
    val leftArray = Array(n) { 0L }
    val rightArray = Array(n) { 0L }
    var c = 0L
    (1 until n).forEach {
        c = if (s[it - 1] == '<') c + 1 else 0
        leftArray[it] = c
    }
    c = 0L
    (n - 2 downTo 0).forEach {
        c = if (s[it] == '>') c + 1 else 0
        rightArray[it] = c
    }
    println((0 until n).map { Math.max(leftArray[it], rightArray[it]) }.sum())
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t m,f,r;
  
  while(true){
      cin >> m >> f >> r;
      if(m==-1&&f==-1&&r==-1) break;
      if(m==-1||f==-1) cout << "F" << endl;
      else if(m+f>=80) cout << "A" << endl;
      else if(m+f>=65) cout << "B" << endl;
      else if(m+f>=50) cout << "C" << endl;
      else if(m+f>=30){
          if(r>=50) cout << "C" << endl;
          else cout << "D" << endl;
      }
      else cout << "F" << endl;
  }
 
  return 0;
}


Measured memory_bytes: 3084
//
//AtCoder Beginner Contest 139
//C - Lower
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> h(n);
    REP(i, n) cin >> h[i];

    int ans = 0;
    int cnt = 0;
    REP(i,n-1){
        if (h[i]>=h[i+1]) cnt++;
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
n = int(input())
abc = [map(int,input().split()) for _ in range(n)]
a,b,c = [list(i) for i in zip(*abc)]
dp = [[0]*3 for _ in range(n+1)]
d = [0,1,2] #aが0,bが1,cが,2に対応している
for i in d:#初期値の設定（今回はなくても可）
    dp[0][i] = 0
for i in range(1,n+1):#全体の漸化式
    for j in d:#iを固定したときのjにまつわる漸化式
        if j%3 == 0:
            dp[i][j] = max(dp[i-1][(j+1)%3]+a[i-1],dp[i-1][(j+2)%3]+a[i-1])
        elif j%3 == 1:
            dp[i][j] = max(dp[i-1][(j+1)%3]+b[i-1],dp[i-1][(j+2)%3]+b[i-1])
        else:
            dp[i][j] = max(dp[i-1][(j+1)%3]+c[i-1],dp[i-1][(j+2)%3]+c[i-1])
ans = max(dp[n][0],dp[n][1],dp[n][2])
print(ans)

Measured memory_bytes: 86204
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;

ll n, k, a[N], b[N];
ll ans;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%lld %lld",&n ,&k);
	for(ll i = 1; i <= n; i++)
		scanf("%lld",a + i);
	for(ll i = 1; i < n; i++)
		b[i] = a[i] + a[i + 1];
	for(ll i = 1; i <= n; i++){
		if(b[i] > k){
			ans += b[i] - k;
			b[i + 1] -= min(b[i] - k, a[i + 1]);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

using namespace std;

using ll = long long;

struct Node {
    vector<Node *> children;
    vector<int> cnt;

    Node() : children(26, nullptr), cnt(26) { }
};

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<string> S(N);
    REP(i, N) {
        cin >> S[i];
    }

    Node trie;
    REP(i, N) {
        int L = S[i].size();

        vector<int> first(26, -1);
        REP(j, L) {
            int x = S[i][j] - 'a';
            if (first[x] == -1) {
                first[x] = j;
            }
        }

        Node *p = &trie;
        stack<Node *> s;
        RREP(j, L) {
            int x = S[i][j] - 'a';
            if (p->children[x] == nullptr) {
                p->children[x] = new Node;
            }
            s.push(p);
            p = p->children[x];
        }

        vector<bool> used(26);
        REP(j, L) {
            int x = S[i][j] - 'a';
            used[x] = true;
            Node *parent = s.top();
            s.pop();
            REP(k, 26) {
                parent->cnt[k] += used[k];
            }
            p = parent;
        }
    }

    ll result = 0;
    REP(i, N) {
        int L = S[i].size();
        Node *p = &trie;
        RFOR(j, 1, L) {
            int x = S[i][j] - 'a';
            p = p->children[x];
        }
        int x = S[i][0] - 'a';
        result += p->cnt[x] - 1;
    }
    
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 394872
import sys
sys.setrecursionlimit(10 ** 7)


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    f = list(map(int, input().split()))

    a.sort()
    f.sort(reverse=True)

    l = -1
    r = 10 ** 13

    def test(x):
        cnt = 0
        for ae, fe in zip(a, f):
            cnt += max(0, ae - x // fe)

        return cnt <= k

    while l + 1 < r:
        m = (l + r) // 2
        if test(m):
            r = m
        else:
            l = m

    ans = r
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 119500
#include <iostream>

int main() {
    using namespace std;
    char s[10];
    int cnt = 0;

    for (int i=0; i<6; ++i) {
        cin >> s[i];
        if (s[i] == '1') {
            ++cnt;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 102, K = 100005;

int n, k;
int a[N];

bool dp[K];
int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 0; i <= k; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if (i - a[j] >= 0 && !dp[i - a[j]])
            {
                dp[i] = true;
                break;
            }
        }
    }
    if (dp[k])
        cout << "First" << endl;
    else
        cout << "Second" << endl;
    return 0;
}


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

typedef ostringstream OSS;
typedef istringstream ISS;

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N) for (int i = (init); i < (int)(N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int W, D;
VI WS, DS;

int solve() {
    VI ws(W), ds(D);

    int cnt = 0;
   
    rep(w, W) {
        int n = WS[w];
        ws[w] = n;

        int pos = -1;
        rep(d, D) {
            if (n > DS[d]) continue;

            pos = d;

            if (DS[pos] == n && ds[pos] != DS[pos]) break;
        }
        ds[pos] = max(ds[pos], n);
        cnt += n;
    }

/*    for (auto w : ws) cout << " " << w;
    cout << endl;
    for (auto d : ds) cout << " " << d;
    cout << endl;
*/  
    rep(d, D) {
        if (ds[d] != DS[d]) {
            cnt += DS[d];
            ds[d] = DS[d];
        }
    }

    return cnt;
}

int main(void) {
    while (cin >> W >> D, W) {
        WS = VI(W);
        DS = VI(D);
        for (auto &w : WS) cin >> w;
        for (auto &d : DS) cin >> d;

        cout << solve() << endl;
    }

	return 0;
}

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

int main(){
  ll Q;
  cin >> Q;			
  vector<ll> p;
  vector<ll> dp(100001);
  vector<bool> N(100001, false);

  dp[0] = dp[1] = 0;
  
  for(int i = 2; i <= 100000; i++){
    bool flag = true;
    for(auto x: p){
      if(i % x == 0){
	flag = false;
	break;
      }
      if(x * x > i){
	break;
      }
    }
    if(flag){
      p.push_back(i);
      N[i] = true;
    }
    if(i % 2 != 0 && N[i] && N[(i+1)/2]){
      dp[i] = dp[i-1] + 1;
    }else{
      dp[i] = dp[i-1];
    }
  }

  vector< pair<ll,ll> > q(Q);
  for(int i = 0; i < Q; i++){
    cin >> q[i].first >> q[i].second;
  }

  for(int i = 0; i < Q; i++){
    cout << dp[q[i].second] - dp[q[i].first - 1] << endl;
  }
  
}


Measured memory_bytes: 3200
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
int a[N],n,res;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]),res^=(a[i]&1);
	puts(res?"NO":"YES");
	return 0;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 10000000)

func readLine() []byte {
	buf := make([]byte, 0, 10000000)
	for {
		l, p, err := rdr.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return buf
}

func readInts() (int, int, int, int, int) {
	s1, _ := rdr.ReadString(' ')
	s1 = strings.TrimSpace(s1)
	N, _ := strconv.Atoi(s1)
	s2, _ := rdr.ReadString('\n')
	s2 = strings.TrimRight(s2, "\n")
	K, _ := strconv.Atoi(s2)

	s3, _ := rdr.ReadString(' ')
	s3 = strings.TrimSpace(s3)
	R, _ := strconv.Atoi(s3)

	s4, _ := rdr.ReadString(' ')
	s4 = strings.TrimSpace(s4)
	S, _ := strconv.Atoi(s4)

	s5, _ := rdr.ReadString('\n')
	s5 = strings.TrimRight(s5, "\n")
	P, _ := strconv.Atoi(s5)

	return N, K, R, S, P
}

func score(hand byte, R, S, P int) int {
	switch hand {
	case 'r':
		return P
	case 's':
		return R
	case 'p':
		return S
	}
	return 0
}

func main() {
	var N, K, R, S, P int
	var T []byte

	N, K, R, S, P = readInts()
	T = readLine()

	before := make([]byte, K)
	changed := make([]bool, K)
	ans := 0
	for i := 0; i < K; i++ {
		before[i] = T[i]
		ans += score(T[i], R, S, P)
	}
	for i := K; i < N; i++ {
		if before[i%K] != T[i] {
			ans += score(T[i], R, S, P)
			changed[i%K] = false
		} else {
			if changed[i%K] {
				ans += score(T[i], R, S, P)
				changed[i%K] = false
			} else {
				changed[i%K] = true
			}
		}

		before[i%K] = T[i]
	}

	fmt.Println(ans)
}


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

int main() {
  int a ;
  cin >> a ;
  if( 1000 <= a && 9999 >= a){

  int b = a / 1000;
  int c = ( a % 1000 ) / 100;
  int d = (( a % 1000 ) % 100) / 10;
  int e = (( a % 1000 ) % 100) % 10;
  
   if( !( c == d ) ){
   cout << "No";
   }else if( ( b == c ) || ( d == e ) ){
     cout << "Yes";
   }else{
      cout << "No";
   }
}else{
  cout << "No";
}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    map<int,int>mp;
int main()
{
 long long   int n,k,a,b,mx=0,sum=0,f=0,c=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(mp[a]==0){mp[a]=1;c++;}
        else if(mp[a]==1){c--; mp[a]=0;}
    }
    cout<<c<<endl;

}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	char c; cin >> c;
	c++;
	cout << c << endl;
	return 0;
}

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

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N;
  cin>>N;

  vector<int> P(N),Q(N);

  for(int i=0;i<N;i++) cin>>P.at(i),P.at(i)--;

  for(int i=0;i<N;i++) Q.at(P.at(i))=i;

  for(int i=0;i<N;i++) cout<<Q.at(i)+1<<' ';
  cout<<endl;

}


Measured memory_bytes: 1536
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x,y;
    for(;;){
        cin>>x>>y;
        if(x==0&&y==0){
            break;
        }
        if(x > y){
            swap(x,y);
        }
        cout<<x<<" "<<y<<endl;
    }
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  long int n;
  scanf("%ld",&n);
  
  string s;
  cin>>s;
  set<char > s1;
  long int i,cnt=0;
  for(i=0;i<n-1;++i)
    {
        if(s[i]!=s[i+1])
           cnt++;
    }
    
    printf("%ld",cnt+1);
  
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sidha(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int> 
#define pb push_back
#define st string
#define pairi pair<int,int>
#define m 1000000007 

bool isPrime(int n){
	if(n<=1) return false;
	if(n<=3) return true;
	if(n%2==0 || n%3==0) return false;
	for(int i=5;i*i<=n;i+=6){
		if(n%i==0 || n%(i+2)==0) return false;
	}
	return true;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
	string s;cin>>s;
	if(s[s.size()-1]!='s'){
		s+="s";
	}
	else{
		s+="es";
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
using namespace std;
 
int main() {
	int n,k,r,s,p;
	cin>>n>>k;
	cin>>r>>s>>p;
	string t;
	cin>>t;
	
	ll ans = 0;
	
	string moves = "";
	
	for(int i=0;i<k;i++){
		if(t[i] == 's'){
			ans += r;
			moves += 'r';
		}
		else if(t[i] == 'p'){
			ans += s;
			moves += 's';
		}
		else{
			ans += p;
			moves += 'p';
		}
	}
	
	for(int i=k;i<n;i++){
		
		if(t[i] == 's'){
			if(moves[i-k] == 'r'){
				moves += '#';	
			}
			else{
				ans += r;
				moves+='r';
			}
			
		}
		else if(t[i] == 'p'){
			if(moves[i-k] == 's'){
				moves += '#';
			}
			else{
			ans += s;
			moves += 's';
			}
		}
		else if(t[i] == 'r'){
			if(moves[i-k] == 'p'){
				moves += '#';
			}
			else{
			ans += p;
			moves += 'p';
			}
		}
		
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    for (int i = 0; i < K; i++) ans += p[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
import numpy as np
import sys

read= sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 1000000007
sys.setrecursionlimit(10**7)


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

cnt4,cnt2 = 0,0

for i in a:
    if i%4 == 0:
        cnt4 += 1
    elif i%2 == 0:
        cnt2 += 1

cnt2 = max(1,cnt2)

print("Yes" if 2*cnt4 + cnt2 >= N else "No")

Measured memory_bytes: 23108
n,m=gets.split.map(&:to_i)
lrs=m.times.map{gets.split.map(&:to_i)}
start=lrs[0][0]
finish=lrs[0][1]
m.times do |i|
  start=lrs[i][0] if start<lrs[i][0]
  finish=lrs[i][1] if lrs[i][1]<finish
end
ans=finish-start+1
puts ans<0 ? 0:ans


Measured memory_bytes: 11388
### constant

CS2CN = {
  "Red" => 1, "Yellow" => 2, "Blue" => 3,
  "Magenta" => 4, "Green" => 5, "Cyan" => 6
}

### subroutines

def rot_x!(cb)
  # 1:+y -> 2:+z -> 4:-y -> 3:-z -> 1:+y
  tmp = cb[1]
  cb[1] = cb[3]
  cb[3] = cb[4]
  cb[4] = cb[2]
  cb[2] = tmp
end

def rot_y!(cb)
  # 2:+z -> 0:+x -> 3:-z -> 5:-x -> 2:+z
  tmp = cb[2]
  cb[2] = cb[5]
  cb[5] = cb[3]
  cb[3] = cb[0]
  cb[0] = tmp
end

def rot_z!(cb)
  # 0:+x -> 1:+y -> 5:-x -> 4:-y -> 0:+x
  tmp = cb[0]
  cb[0] = cb[4]
  cb[4] = cb[5]
  cb[5] = cb[1]
  cb[1] = tmp
end

def calc_cbi(cb)
  cbi = 0
  for cn in cb
    cbi = cbi * 10 + cn
  end
  cbi
end

def normalized_cbi(cb)
  cb0 = cb.clone
  #puts "normalizing #{cb0}.."

  while cb0[0] != 1
    (cb0[1] != 1 && cb0[4] != 1) ? rot_y!(cb0) : rot_z!(cb0)
  end

  min_cbi = calc_cbi(cb0)

  3.times.each do
    rot_x!(cb0)
    cbi = calc_cbi(cb0)
    min_cbi = cbi if min_cbi > cbi
  end

  #puts "  #{cb0}->#{min_cbi}"
  min_cbi
end

### main

while true
  n = gets.strip.to_i
  break if n == 0

  cbis = {}
  short = 0

  n.times.each do
    cb = gets.strip.split(' ').map{|s| CS2CN[s]}

    cbi = normalized_cbi(cb)
    #p [cb, cbi]

    if ! cbis[cbi].nil?
      short += 1
    else
      cbis[cbi] = 1
    end
  end

  puts short
end

Measured memory_bytes: 6144
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>	
using namespace std;
typedef long long ll;
#define bay_bay return 0;
#define fori(n) for(int i=0;i<n;++i)
#define for1(n) for(int i=1;i<=n;i+=3)
#define all(v) ((v).begin()), ((v).end())	
#define sz(v) v.size()
#define endl "\n"
constexpr auto EPS = 1e-9;
#define ff fflush(stdout);
const int mod = 1000000007LL;
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
void GOAT()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("output.txt", "w	", stdout);
#else
#endif
}
struct day
{
	ll a, b, c;

};
day days[100009];
int main()
{
	//GOAT();
int n;
cin>>n;
for (int i = 1; i <= n;i++)
		cin >> days[i].a>>days[i].b>>days[i].c;
for (int i = 2; i <= n;i++)
{
	days[i].a += max(days[i - 1].b, days[i - 1].c);
	days[i].b+= max(days[i - 1].a, days[i - 1].c);
	days[i].c += max(days[i - 1].b, days[i - 1].a);

}
cout << max(days[n].a, max(days[n].b, days[n].c));
	
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define st first
#define nd second
#define INF 1000000007LL
using namespace std;

int main(){
#ifndef LOCAL
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
  int n; cin >> n;
  vector<ll> a(n);
  ll x = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    x ^= a[i];
  }
  for(int i = 0; i < n; i++)
    cout << (x ^ a[i]) << ' ';  
}

Measured memory_bytes: 4716
use std::io::prelude::*;
use std::io;

fn main() {
    let mut buffer = String::new();
    let stdin = io::stdin();
    let mut handle = stdin.lock();

    handle.read_line(&mut buffer).unwrap();
    let array = buffer.trim().split_whitespace()
        .map(|s| s.parse::<u32>().unwrap())
        .collect::<Vec<u32>>();
    let gcd = euclidean(&(array[0], array[1]));
    println!("{}", gcd);
}

fn euclidean(v: &(u32, u32)) -> u32 {
    let (l, s) = if v.0 > v.1 {
        (v.0, v.1)
    } else {
        (v.1, v.0)
    };

    if s == 0 {
        return l;
    }

    let rem = l % s;
    euclidean(&(s, rem))
}

Measured memory_bytes: 5056
import java.util.*;
class Main{
  static Scanner s = new Scanner(System.in);
  
  public static void main(String[] args){
    
    int N = s.nextInt();
    int[] X = new int[N];
    for(int i=0;i<N;i++) X[i] = s.nextInt();       
    Arrays.sort(X);
    int temp1 = 0;
    int temp2 = 0;

    for(int i=X[0];i<=X[N-1];i++){
      temp1 = 0;
      for(int j=0;j<N;j++){
        temp1 += Math.pow(X[j]-i,2);
      }
      if(i==X[0]) temp2 =temp1;
      else temp2=Math.min(temp1,temp2);
    }
    System.out.println(temp2);
  }
}

Measured memory_bytes: 21844
a, b, k = map(int, input().split())
List = []
for i in range(k):
    if a + i <= b:
        List.append(a + i)
for i in range(k):
    if b - i >= a:
        List.append(b-i)
List = sorted(set(List))
for i in range(len(List)):
    print(List[i])


Measured memory_bytes: 3060