akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

signed main() {
	int s;
	cin>>s;
	int x=ceil(sqrt(s));
	cout<<0<<' '<<0<<' '<<x<<' '<<1<<' '<<x*x-s<<' '<<x<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
int n,mod;
LL ans;
const int N=3010;
LL C[N][N],S[N][N];
LL ksm(LL a,LL b,LL mod)
{
	LL res=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)res=res*a%mod;
	return res;
}
void YYCH()
{
	C[0][0]=S[0][0]=1;
	for(int i=1;i<=n+1;++i)
	{
		C[i][0]=1;
		for(int j=1;j<=i;++j)
		{
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
			S[i][j]=(S[i-1][j-1]+S[i-1][j]*j)%mod;
		}
	}
}
int main()
{
	cin>>n>>mod;YYCH();
	for(int i=0;i<=n;++i)
	{
		LL _2=ksm(2,n-i,mod),mul=(LL)(i&1?mod-1:1)*C[n][i]%mod*ksm(2,ksm(2,n-i,mod-1),mod)%mod,res=0,_2j=1;
		for(int j=0;j<=i;++j)
		{
			(res+=S[i+1][j+1]*_2j)%=mod;
			_2j=_2j*_2%mod;
		}
		(ans+=res*mul)%=mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 139904
def insertionSort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v

    return cnt


def shellSort(A, n):
    cnt = 0
    m = 1
    gs = [1]
    gn = 1
    while (3*gn+1) <= n:
        gn = 3*gn + 1
        gs.append(gn)
        m += 1
    gs = gs[::-1]
    print(m)
    for g in gs:
        if g == 1:
            print(g)
        else:
            print('{} '.format(g), end='')
        cnt = insertionSort(A, n, g, cnt)
    print(cnt)

n = int(input())
A = [int(input()) for _ in range(n)]
shellSort(A, n)
[print(a) for a in A]


Measured memory_bytes: 53200
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
#define LL long long
#define MOD 1000000007
#define rep(i, s, x) for(int i=s; i<x; i++)

int a, b, c, d, n, m, A[10000] = {}, ans = 0;
string s;

int main() {
	cin >> n >> s;
	rep(i, 0, n - 1) {
		int tmp = 0;
		bool l[30], r[30];
		rep(j, 0, 26)l[j] = r[j] = false;
		rep(j, 0, n) {
			if (i >= j) {
				l[s[j] - 'a'] = true;
			}
			else r[s[j] - 'a'] = true;
		}
		rep(j, 0, 26)if (l[j] && r[j])tmp++;
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

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

    int n, k;
    cin >> n >> k;

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

    vector<int> dp(n + 2, INT_MAX);

    dp[0] = 0;
    REP(i, n) REP(j, k + 1)
        chmin(dp[i + j], dp[i] + abs(h[i] - h[i +j]));

    cout << dp[n - 1] << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include<functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stack>

#define LL long long
#define pii pair<int,int>
#define pLL pair<LL,LL>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<LL>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<LL>
#define vecpii vector<pii>
#define vecpLL vector<pLL>
#define vecbL vector<bool>
#define endl "\n"
#define REP(e,v) for(auto e:v)
#define rep(i, a, n) for(LL i = a; i < n;i++)

using namespace std;

int inp(){
	int x;
	scanf("%d",&x);
	return x;
}
LL linp(){
	LL x;
	scanf("%lld",&x);
	return x;
}

void outp(int i){
	printf("%d",i);
}

void loutp(LL i){
	printf("%lld",i);
}

LL mod(LL i){
	return i % 1000000007;
}


int gcd(int i,int j){
	if(j != 0)
		return gcd(j, i % j);
	else
		return i;

}

int tNoEP(){
	LL N,M;

	cin >> N >> M;

	loutp((N*(N-1))/2+(M*(M-1)/2));

	return 0;
}

bool isKaibun(string s){

	/*
	for(LL i = 0,j = s.length()-1; i != j;i++,j--){

		if(s[i] != s[j]) {
			return false;
		}

	}
	*/
	string rs = s;
	reverse(s.begin(), s.end());

	if(rs == s)
		return true;
	else
		return false;
}

int SP(){

	string s;

	cin >> s;

	LL N = s.length();

	if(isKaibun(s) &&
			isKaibun(s.substr(0, (N-1)/2  )) &&
				isKaibun(s.substr((N+3)/2 -1 , N)))
		printf("Yes");
	else
		printf("No");

	return 0;

}

signed main() {

	//tNoEP();
	SP();
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (true) {
			int m = Integer.parseInt(in.next());
			int f = Integer.parseInt(in.next());
			int r = Integer.parseInt(in.next());
			if (m == -1 && f == -1 && r == -1) {
				break;
			}
			int total = m + f;
			String grade;
			if (m == -1 || f == -1) {
				grade = "F";
			} else if (total >= 80) {
				grade = "A";
			} else if (total >= 65) {
				grade = "B";
			} else if (total >= 50) {
				grade = "C";
			} else if (total >= 30) {
				if (r >= 50) {
					grade = "C";
				} else {
					grade = "D";
				}
			} else {
				grade = "F";
			}
			System.out.println(grade);
		}
		in.close();
	}
}	


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

struct node{
	struct node *right;
	struct node *left;
	struct node *parent;
	int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

/*
	節点 x を根とする部分木の中で最小のキーを持つ節点を返す
*/
Node treeMinimum (Node x ){
	while (x->left != NIL ){
		x = x->left;
	} // end while
	
	return x;
}

Node treeSearch (Node u, int k ){
	if (u == NIL || u->key == k ) return u;
	else
	if (u->key < k ){
		return treeSearch (u->right, k );
	}else{
		return treeSearch (u->left, k );
	} // end if 
}

/*
	2分探索木の節点 x に次節点がある場合はの次節点を返す
	ただし、木の中で x が最大のキーを持つ場合は NIL を返す
*/
Node treeSuccessor (Node x ){
	Node y = NIL;
	if (x->right != NIL ){
		return treeMinimum (x->right );
	} // end if
	y = x->parent;
	while (y != NIL && x == y->right ){
		x = y;
		y = y->parent;
	} // end while

	return y;
}

void treeDelete (Node z ){
	Node y;	// node to be deleted
	Node x;	// child of y

	/* 削除する節点 y を決定する */
	if (z->left == NIL || z->right == NIL ){
		y = z;				/* z が子を最大1つ持つ場合は入力節点の z */
	}else{
		y = treeSuccessor (z );	/* z が子を2つ持つ場合は z の次節点 */
	} // end if

	/* x を y の NIL ではない子または y が子を持たない場合は NIL に設定 */
	if (y->left != NIL )
		x = y->left;
	else
		x = y->right;
	
	/* y の親と x のポインタを変更し y を削除する */
	/* x が NIL または y が根のときの境界条件を処理 */
	if (x != NIL )
		x->parent = y->parent;	/* z が子を1つ持つ場合 */
	
	if (y->parent == NIL ){
		root = x;
	}else{
		if (y == (y->parent)->left){
			(y->parent)->left = x;
		}else{
			(y->parent)->right = x;
		} // end if
	} // end if

	/* z の次節点が削除されたときに y の内容を z  に移動する */
	if (y != z ){
		z->key = y->key;
	} // end if

	free(y);
}

void insert (int k ){
	Node y = NIL;
	Node x = root;
	Node z;

	z = malloc (sizeof (struct node ) );
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL ){
		y = x;
		if (z->key < x->key ){
			x = x->left;
		}else{
			x = x->right;
		} // end if
	} // end while

	z->parent = y;
	if (y == NIL ){
		root = z;	// 木 T が空だった場合
	}else{
		if (z->key < y->key ){
			y->left = z;
		}else{
			y->right = z;
		} // end if
	} // end if
}

void inorder (Node u ){
	if (u == NIL ) return;
	inorder (u->left );
	printf (" %d", u->key );
	inorder (u->right );
}

void preorder (Node u ){
	if (u == NIL ) return;
	printf (" %d", u->key );
	preorder (u->left );
	preorder (u->right );
}

int main()
{
	int n, i, x;
	char com[20];

	root = NIL;
	scanf ("%d", &n );
	for (i = 0; i < n; i++ ){
		scanf ("%s", com );
		if (com[0] == 'i' ){	// case insert 
			scanf ("%d", &x );
			insert (x );
		}else
		if (com[0] == 'p' ){ // case print
			inorder (root );
			printf ("\n" );
			preorder (root );
			printf ("\n" );
		}else
		if (com[0] == 'f' ){	// case find
			scanf ("%d", &x );
			Node t = treeSearch (root, x );
			if ( t != NIL ) printf ("yes\n" );
			else printf ("no\n" );
		}else
		if (com[0] == 'd' ){	// case delete
			scanf ("%d", &x );
			treeDelete (treeSearch (root, x ) );
		} // end if
	} // end for

	return 0;
}

Measured memory_bytes: 19364
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long N,A_sum,B_sum,m,ans;
int main(){
    cin>>N;
    vector<long long>A(N),B(N),C(N),ok;
    for(int i=0;i<N;i++){cin>>A[i];A_sum+=A[i];}
    for(int i=0;i<N;i++){cin>>B[i];B_sum+=B[i];}
    if(A_sum<B_sum){cout<<-1<<endl;return 0;}
    for(int i=0;i<N;i++)C[i]=A[i]-B[i];
    for(int i=0;i<N;i++){
        if(C[i]>=0)ok.emplace_back(C[i]);
        else m+=C[i],ans++;
    }
    if(m>=0){cout<<0<<endl;return 0;}
    sort(ok.begin(),ok.end(),greater<long long>());
    for(auto x:ok){
        m+=x;
        ans++;
        if(m>=0){cout<<ans<<endl;return 0;}
    }
    return 0;
}

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

typedef long long ll;

int main() {
    int K, x = 1, c = 0;
    cin >> K;
    for (int i = 1; i <= 10; i++) { // i桁
        for (int j = 1; j <= 9; j++) { // 先頭j
            rep(k, x) {
                int l = k, a = j;
                bool f = true;
                int y = x / 3;
                rep(m, i - 1) {
                    if ((l / y) % 3 == 0) {
                        a--;
                        if (a < 0) f = false;
                    }
                    if ((l / y) % 3 == 2) {
                        a++;
                        if (a > 9) f = false;
                    }
                    y /= 3;
                }
                if (f) c++;
                if (c == K) {
                    //cout << "i=" << i << " j=" << j << " k=" << k << "\n";
                    cout << j;
                    a = j;
                    l = k;
                    y = x / 3;
                    rep(m, i - 1) {
                        if ((l / y) % 3 == 0) {
                            a--;
                        }
                        if ((l / y) % 3 == 2) {
                            a++;
                        }
                        cout << a;
                        y /= 3;
                    }
                    cout << "\n";
                    return 0;
                }
            }
        }
        x *= 3;
    }
}

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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if ((x - r >= 0) && (x + r <= W) && (y - r >= 0) && (y + r <= H)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }   
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define     ll          long long int
#define     REP(i,x,n)    for(ll i=x;i<n;i++)
#define     SZ(v)       (ll)v.size()
#define     endl        "\n"
#define     ff          first
#define     ss          second
#define     PQ_MIN      priority_queue <ll, vector<ll>, greater<ll> >
#define     PQ          priority_queue <int>
#define     pbds        tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define     setbit(x)   __builtin_popcount(x)
#define     prec(n)     fixed<<setprecision(n)
#define     pb(n)       push_back(n)
#define     clr(n)      memset(n,0,sizeof(n))
#define     reset(n)    memset(n,-1,sizeof(n))
#define     ii          pair<ll,ll>
#define     vll         vector<ll>

using namespace std;
using namespace __gnu_pbds;
bool comp(pair<ll,ll> a,pair<ll,ll> b) {       }
const ll INF=1e16;
const ll MOD=5;
const ll nxm=1e6+5;
vector<ll> allprime;
bool isprime[nxm];
void sieve()
{
    memset(isprime,1,sizeof(isprime));
    for(ll i=2;i<nxm;i++)
    {
        if(isprime[i])
        for(ll j=i*i;j<nxm;j+=i)
        {
            isprime[j]=0;
        }
    }
    for(ll i=2;i<nxm;i++)
        if(isprime[i])
        allprime.push_back(i);
}
void print(vector<vector<ll> >&v)
{
    ll n=v.size();
    ll m=v[0].size();
    cout<<"\n";
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
            cout<<v[i][j]<<" ";
        cout<<"\n";
    }
}
void print(vector<ll>&v)
{
    ll n=v.size();
    cout<<"\n";
    for(ll i=0;i<n;i++)
    {
            cout<<v[i]<<" ";
    }
        cout<<"\n";

}
void print(set<ll>&s)
{

cout<<endl;

set<ll>::iterator it;
for(it=s.begin();it!=s.end();it++)
    cout<<*it<<" ";
cout<<endl;
}

ll power(ll a,ll p)
{
    ll res=1;
    while(p>0)
    {
        if(p&1){
            res=(res*a)%MOD;
            p--;
        }
            a=(a*a)%MOD;
            p/=2;
    }

    return res%MOD;


}
ll __lcm(ll a,ll b)
{
    return ((a*b)/__gcd(a,b));
}
ll fact(ll a)
{
    ll res=1;
    for(ll i=1;i<=a;i++)
        res*=i;
    return res;
}
ll sqroot[nxm];
ll perfect_square()
{
    memset(sqroot,-1,sizeof(sqroot));
    for(ll i=1;i*i<=nxm;i++)
    {
        sqroot[(i*i)]=i;
    }
}
bool is_prime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
        return false;
    return true;
}
void solve(){
ll n;cin>>n;
ll res=0;
REP(i,1,n+1)
{
    ll c;cin>>c;
    if(i&1 && c&1)
        res++;
}
cout<<res<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
//	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b&&a<c){
		if(b<c){
			printf("%d %d %d\n",a,b,c);
		}
		else{
			printf("%d %d %d\n",a,c,b);
		}
	}
	else if(b<a&&b<c){
		if(a<c){
			printf("%d %d %d\n",b,a,c);
		}
		else{
			printf("%d %d %d\n",b,c,a);
		}
	}
	else{
		if(a<b){
			printf("%d %d %d\n",c,a,b);
		}
		else{
			printf("%d %d %d\n",c,b,a);
		}
	}
	return 0;
}

Measured memory_bytes: 2760
#include <algorithm>
    #include <cstdio>
    #include <iostream>
    #include <cfloat>
    #include <climits>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <queue>
    #include <sstream>
    #include <stack>
    #include <time.h>
    #include <vector>
    #include <complex>
    #include <map>
    #include <set>
    #include <iomanip>
    #include <math.h>
    #include <stdlib.h>
    #include <list>
    #include <utility>
    #include <memory>
    #include <cstring>
    #include <fstream>
    #include <numeric>
    #include <assert.h>
    #include <bits/stdc++.h>
    using namespace std;
    int n,k,h[100004];
    int main(){
    	cin>>n>>k;
    	for (int i=1;i<=n;i++)
    		cin>>h[i];
    	int rp=1e9;
    	sort (h+1,h+n+1);
    	for(int i=k;i<=n;i++){
    		if (h[i]-h[i-k+1]<rp)
    			rp=h[i]-h[i-k+1];
    	}
    	cout<<rp; 
    	return 0;
    }

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
//#define int long long
int32_t main()
{
   int n; cin >> n;
   bool ok = 0;
   vi v(n);	fr(_,n){
   	int x,y; cin>> x>> y;
   	v[_] = (x==y);
   }
   rep(i,1,n-2) ok |= (v[i] == 1 and v[i-1] == 1 and v[i+1]==1);
   cout<< (ok ? "Yes\n":"No\n");
}

Measured memory_bytes: 3620
#include<stdio.h>
int main() {
	long long int n, s[5000] = {},m,min=10000000,count=0;
	scanf("%lld%lld", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &s[i]);
		m -= s[i];
		if (s[i] < min) {
			min = s[i];
		}
	}
	printf("%lld", n + m / min);
}

Measured memory_bytes: 256
#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)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
    int N, ans = 0;
    cin >> N;
    vint P(N);
    rep(i, N)
    {
        cin >> P[i];
    }
    int Min = 200001;
    rep(i, N)
    {
        if (P[i] <= Min)
        {
            ans++;
        }
        Min = min(Min, P[i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe
import Data.Ord

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

calc (xs : xss) m t
  | m <= num = t + price * m
  | otherwise = calc xss (m - num) (t + price * num)
  where
    price = head xs
    num = last xs

main = do
  [n, m] <- getIntList
  xss <- getIntNList n
  let xss' = sortBy (comparing head) xss
  print $ calc xss' m 0


Measured memory_bytes: 65148
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<double,int> P;

int n;
double a[100001];
double b[100001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf",&a[i]);
		b[i]=a[i];
	}
	sort(b,b+n);
	for(int i=0;i<n;i++){
		int w=lower_bound(b,b+n,a[i])-b;
		int l=upper_bound(b,b+n,a[i])-b;
		printf("%d\n",w*3+(l-w-1)*1);
	}
	return 0;
}

Measured memory_bytes: 4656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m,ans=0;
	cin>>n>>m;
	vl a(n),ap(n),v(n),x(m),y(m);
	rep(i,n){
		cin>>a[i],a[i]--;
		v[max(0ll,a[i]-ap[a[i]])]++;
		ap[a[i]]++;
	}
	rep(i,n){
		if(v[i]==0)ans++;
	}
	rep(i,m){
		cin>>x[i]>>y[i];
		x[i]--;y[i]--;
		ap[a[x[i]]]--;
		v[max(0ll,a[x[i]]-ap[a[x[i]]])]--;
		if(v[max(0ll,a[x[i]]-ap[a[x[i]]])]==0)ans++;
		
		a[x[i]]=y[i];
		if(v[max(0ll,y[i]-ap[y[i]])]==0)ans--;
		v[max(0ll,y[i]-ap[y[i]])]++;
		ap[y[i]]++;
		cout<<ans<<"\n";
	}
}

 


Measured memory_bytes: 9344
#include<bits/stdc++.h>
#define GO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
const int N = 3e4 + 5;
const int M = 1e6 + 5;
const int Mod = 1e9 + 7;

ll GCD(ll a, ll b) {
	while (a) b %= a, swap(a, b);
	return b;
}


int main()
{
	GO;
	int k;
	cin >> k;
	ll ans = 0;
	for (int i = 1; i <= k; i++)
		for (int j = 1; j <= k; j++)
			for (int kk = 1; kk <= k; kk++)
				ans += GCD(i, GCD(j, kk));
	cout << ans << endl;
	return 0;
}

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

mulAll = 1
for i in range(N):
    mulAll *= A[i]

num = 0
for i in range(N):
    mulAll //= A[i]
    num += mulAll
    mulAll *= A[i]

ans = mulAll / num

print(ans)


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

int main(){
  int N;
  int count =0;
  cin >> N;
  for(int i=0; i<N; i++){
    int x;
    int temp=0;
    cin >>x;
    
    if(x%2 ==1){
      count =0;
      	break;
    }
    
    while(x%2 == 0){
      temp+=1;
        x/=2;
    }
    if(count ==0)
      count =temp;
    else
      count = min(count,temp);
  }
  cout << count << endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
L = []
brank = "." * W
for _ in range(H):
  S = input()
  if S == brank:
    continue
  L.append(list(map(str, S)))

if L:
  L1 = list(zip(*L))
  brank = tuple(["." for _ in range(len(L1[0]))])
  ans = []

  for l in L1:
    if l == brank:
      continue
    ans.append(l)


  for a in zip(*ans):
    print("".join(a))

Measured memory_bytes: 9176
N = int(input())
P = list(map(int,input().split(" ")))
c=0
for i in range(1,len(P)-1):
    #print(P[i-1],P[i],P[i+1])
    if P[i-1]<P[i]<P[i+1] or P[i-1]>P[i]>P[i+1]:
        c+=1
print(c)

Measured memory_bytes: 2940
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    int ans;
    if (n % x == 0)ans = n / x * t;
    else { ans = (n / x + 1) * t; }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3188
// atcoder/abc155/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
template<typename P, typename Q> inline pair<Q, P> reverse(pair<P, Q> p) { return make_pair(p.second, p.first); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    int mx = 0;
    map<string, int> m;
    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      ++m[s];
      setmax(mx, m[s]);
    }
    vector<string> v;
    each (i, m) {
      if (i.second == mx) v.push_back(i.first);
    }
    sort(v.begin(), v.end());
    each (i, v) cout << i << endl;
  }

  return 0;
}


Measured memory_bytes: 25584
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        x: u32,
    }

    let ans = match solve(x) {
        Some(num) => num,
        None => 0,
    };

    println!("{}", ans);

}

fn solve(num : u32) -> Option<u32> {
    for n in num..100004 { 
        if is_prime(n) {
            return Some(n); 
        }
    }
    None
}

fn is_prime(num : u32) -> bool {
    let mut i = 2;
    while i*i <= num {
        //println!("{}", num / i);
        if num % i == 0 {
            return false;
        }
        i = i + 1;
    }
    true
}

#[test]
fn test_is_primte() {
    assert_eq!(is_prime(20), false);
}

Measured memory_bytes: 4352
#include<iostream>
using ull = unsigned long long; 

ull gcd(const ull a,const ull b){
	return (b==0) ? a : gcd(b,a%b);
}

ull lcm(const ull a,ull b){
	ull h = gcd(a,b);
	return h ? (a*(b/h)):0;
}


int main(){

	unsigned long long A ,B;
	unsigned long C,D;
	std::cin >> A >> B >> C >> D;
  	
	ull AdevC = (A - 1) / C; 
	ull AdevD = (A - 1) / D;
	ull AdevCD = (A -1) / lcm(C,D);
	ull BdevC = B / C;
	ull BdevD = B / D;
	ull BdevCD = B / lcm(C,D);

	auto total = B-A+1 - ((BdevC + BdevD - BdevCD)-(AdevC + AdevD - AdevCD));

	std::cout << total;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<ctime>
#include<cstring>
#include<cstdio>
#define IOS ios::sync_with_stdio(false); cin.tie(0); 
using namespace std;
typedef pair<int,int> PII;
const int N=110;
const int INF=0x3f3f3f3f;
char s[N];
int main(){
	IOS;
	//clock_t starttime,endtime;	
	//starttime=clock();
	string ans="Yes";
	cin>>s+1;
	int n=strlen(s+1);
	for(int i=1;i<=n/2;i++){
		if(s[i]!=s[n-i+1]){
			ans="No";
		}
	}
	for(int i=1;i<=(n-1)/4;i++){
		if(s[i]!=s[(n-1)/2-i+1]){
			ans="No";
		}
	}
	for(int i=(n+3)/2,j=0;i<=n;i++,j++){
		if(s[i]!=s[n-j]){
			ans="No";
		}
	}
	cout<<ans<<endl;
	//endtime=clock();
	//cout<<(double)(endtime - starttime) / CLOCKS_PER_SEC<<"s"<<endl;
	return 0;
}

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


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

    int total = 0;
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        while (a % 2 == 0) {
            a /= 2;
            total++;
        }
    }
    std::cout << total << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int turu = 2;
  int tart = 4;
  int x, y;
  int judge = 0;
  scanf("%d%d", &x, &y);
  for(int i = 1; i <= x; i++) {
    if(turu * i + tart * (x-i) == y) {
      judge = 1;
    } else if(tart * i + turu * (x-i) == y) {
      judge = 1;
    }
  }
  if(judge == 1) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 1692
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
    int n;
    cin >> n;
    vector<ll> l(n);
    rep(i,n)cin >> l.at(i);
    sort(l.begin(),l.end());
    ll ans=0;
    rep(i,n-2){
      for(int j=i+1;j<n-1;j++){
        for(int k=j+1;k<n;k++){
            if(l.at(i)+l.at(j)>l.at(k) && l.at(i)!=l.at(j) && l.at(i)!=l.at(k) && l.at(j)!=l.at(k))ans++;
        }
      }
    }
    cout << ans << endl;
}



    
   


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n = 0, sum = 0; string s; 
	for(int h = 0; h < 5; h++){
	    cin >> s;
	    for (int h = 0; h < s.size() - 2; h++) {
	    	if (s[h] == 'J'&&s[h + 1] == 'O'&&s[h + 2] == 'I') {
    			n++;
    		}
	    	if (s[h] == 'I'&&s[h + 1] == 'O'&&s[h + 2] == 'I') {
		    	sum++;
	    	}
	    }
    	cout << n << endl;
    	cout << sum << endl;
    	n = 0; sum = 0;
	}
	cin >> n;
}



Measured memory_bytes: 3168
#!/usr/bin/perl

use strict;
use warnings;

my ($n, $k);
{
    my $in = <STDIN>;
    ($n, $k) = split(" ", $in);
}
my ($r, $s, $p);
{
    my $in = <STDIN>;
    ($r, $s, $p) = split(" ", $in);
}
my $t = <STDIN>;

my $h = sub {
    my $num = shift;
    if ("r" eq $num) {
        return "p";
    } elsif ("s" eq $num) {
        return "r";
    } elsif ("p" eq $num) {
        return "s";
    }
};
my $score = sub {
    my $num = shift;
    if ("p" eq $num) {
        return $p;
    } elsif ("r" eq $num) {
        return $r;
    } elsif ("s" eq $num) {
        return $s;
    }
};

my @c;
for (my $i=0; $i<$n; $i++) {
        $c[$i] = $h->(substr($t, $i, 1));
}
for (my $i=0; $i<$n-$k; $i++) {
    if ($c[$i] eq $c[$i+$k]) {
        $c[$i+$k] = "x";
    }
}
my $sum;
for (my $i=0; $i<$n; $i++) {
    $sum += $score->($c[$i]);
}
print "$sum\n";

Measured memory_bytes: 8704
S = gets.chomp

divides = ['dream', 'dreamer', 'erase', 'eraser']
bfs = [0]
can = false
while !bfs.empty?
  t = bfs.pop
  if t == S.size
    can = true
    break
  end
  divides.each do |d|
    bfs << t + d.size if S.slice(t, d.size) == d
  end
end
puts can ? 'YES' : 'NO'

Measured memory_bytes: 2044
#!/usr/bin/env python3
def main():
    w = int(input())
    n = int(input())
    nums = list(range(1, w + 1))
    for _ in range(n):
        a, b = map(int, input().split(','))
        nums[a - 1], nums[b - 1] = nums[b - 1], nums[a - 1]
    for i in nums:
        print(i)
if __name__ == '__main__':
    main()

Measured memory_bytes: 7668
#include <iostream>

using namespace std;

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

    int count = 0;
    for (int i = 0; i < N; ++i) {
        int t;
        cin >> t;

        while (t % 2 == 0) {
            ++count;
            t /= 2;
        }
    }

    cout << count << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }
  map<int, int> m;
  rep(i, N) {
    m[i - A[i]]++;
  }

  int ans = 0;
  rep(i, N - 1) {
    int num = A[i] + i;
    ans += m[num];
    m[i - A[i]]--;
  }
  cout << ans << endl;
}

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

int main(){
    int n,d,cnt = 0;
    cin>>n>>d;
    vector<vector<int>> A(n,vector<int>(d));
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>A[i][j];
        }
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            int ans=0;
            for(int k=0;k<d;k++){
                int hako = abs(A[i][k]-A[j][k]);
                ans+=hako*hako;
            }
            for(int h=0;h<=ans;h++){
                if(ans==h*h){
                    cnt++;
                    break;
                }
            }
        }
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <random>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using std::cin;
using std::cerr;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
using std::stack;
using std::string;
using std::unordered_set;
using std::vector;
using std::lower_bound;
using std::upper_bound;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  cout << (n + 1) / 2;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int k,a,b;
int main(){
    cin>>k>>a>>b;
    if(a%k==0)k=a;
    else k=a/k*k+k;
    if(a<=k&&k<=b)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
    int h,w;
    cin>>h>>w;

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

    vector<bool>hh(h,false);
    vector<bool>ww(w,false);

    for(int i=0;i<h;i++){
        for (int j=0;j<w;j++) {
            if(a[i].at(j)=='#'){
                hh[i]=true;
                ww[j]=true;
            }
        }
    }

    for(int i=0;i<h;i++){
        if(hh[i]){
            for (int j=0;j<w;j++) {
                if(ww[j]){
                    cout<<a[i].at(j);
                }
            }
            cout<<endl;
        }
    }

}


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

int main() {
  ll n;
  cin >> n;
  bool ans = false;
  ll doubles = 0;
  for(ll i=0; i<n; i++) {
    ll a,b;
    cin >> a >> b;
    if(a==b) {
      doubles++;
      if(doubles>=3) {
        ans = true;
      }
    } else {
      doubles = 0;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3132
def f(a):
	q=a[:n];s=sum(q);heapify(q)
	for e in a[n:2*n+1]:yield s;s+=e-heappushpop(q,e)
from heapq import*;n,*a=map(int,open(0).read().split());print(max(map(sum,zip(f(a),list(f([-e for e in a[::-1]]))[::-1]))))

Measured memory_bytes: 36308
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using Graph = vector<vector<ll>>;

int main(){
  int x,a,b;cin>>x>>a>>b;
  if(a >= b)
  {
    cout << "delicious" << endl;
  }
  else if (a + x >= b)
  {
    cout << "safe" << endl;
  }
  else
  {
    cout << "dangerous" << endl;
  }
  
  
}

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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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

  vector<int> q(102);
  rep(i, 102) { q[i] = i; }

  rep(i, n) {
    int p;
    cin >> p;
    q.erase(remove(q.begin(), q.end(), p), q.end());
  }

  int ans = 1001001001;
  for (auto u : q) {
    if (abs(ans - x) > abs(u - x)) ans = u;
  }

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


Measured memory_bytes: 3632
# エラトステネスの篩いによる素数列の生成
def eratosthenes(n)
  return [] unless n.is_a?(Integer) && n >= 2
  list = Array.new(n - 1).map.with_index {|i, k| k + 2}
  result = [1]
  while list.size >= 1 && list.last >= result.last**2
    p = list.shift
    result << p
    #list.delete_if {|v| v % p == 0 }
    #下の2行は上記一行に置換可能だが、上記では1/12の性能しか出ない。
    list.each.with_index(0) {|i, k| list[k] = nil if i % p == 0}
    list.compact!
  end
  result.shift
  result = result + list
  result.sort_by! {|v| v}
end

def bsearch2(ary, key, l, h)
  return "a" if ary == [] 
  return "b" if l > h
  return "c" if l < 0 || h >= ary.size
  
  mid = ((h + l) / 2 + 1).truncate
  
  return mid if ary[mid] == key
  return l if l == h
  if key < ary[mid]
    bsearch2(ary, key, l, mid - 1)
  else
    bsearch2(ary, key, mid, h)
  end
end

list = eratosthenes(999999)
h = list.size

while line = gets
  n = line.chomp.to_i
  if n <= 1
    puts 0
    next
  end
  puts bsearch2(list, n, 0, h - 1) + 1
end

Measured memory_bytes: 25472
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9
struct Puzzle{
    int f[N2];
    int space;
    string path;
    bool operator < ( const Puzzle &p ) const {
        for ( int i = 0; i < N2; i++ ) {
            if ( f[i] == p.f[i] ) continue;
            return f[i] > p.f[i];
        }
        return false;
    }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p) {
    for ( int i = 0; i < N2; i++ )
    if ( p.f[i] != (i + 1) ) return false;
    return true;
}

string bfs(Puzzle s) {
    queue<Puzzle> Q;
    map<Puzzle, bool> V;
    Puzzle u, v;
    s.path = "";
    Q.push(s);
    V[s] = true;

    while(!Q.empty()){
        u = Q.front(); Q.pop();
        if (isTarget(u) ) return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for ( int r =0; r < 4; r++ ) {
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if ( tx < 0 || ty < 0 || tx >=N || ty >= N ) continue;
            v = u;
            swap(v.f[u.space], v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if ( !V[v] ) {
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    return "unsolvable";
}

int main(){
    Puzzle in;
    for ( int i = 0; i < N2; i++ ){
        cin >> in.f[i];
        if ( in.f[i] == 0 ){
            in.f[i] = N2;
            in.space = i;
        }
    }
    string ans = bfs(in);
    cout << ans.size() << endl;
    return 0;
}












Measured memory_bytes: 30612
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <map>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    string S;
    cin >> S;
    if (S == "keyence") {
        cout << "YES" << "\n";
    } else if (S.substr(0, 7) == "keyence" || S.substr(S.length()-7, 7) == "keyence") {
        cout << "YES" << "\n";
    } else {
        string key = "keyence";
        for (unsigned long i = 1; i <= 6; ++i) {
            if (S.substr(0, i) == key.substr(0, i) &&
                S.substr(S.length()-7+i, 7-i) == key.substr(i, 7-i)) {
                cout << "YES" << "\n";
                return 0;
            }
        }
        cout << "NO" << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if ((A - B) % 2 != 0) {
    cout << "IMPOSSIBLE" << endl;
  }
  else {
    cout << (A + B) / 2 << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <set>

using namespace std;

set<int> s;
set<int>::iterator it;

int n;
int m;
int counter1 = 0;
int x;
int i;
int j;

int main(){
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&x);
		s.insert(x);
	}
	scanf("%d",&m);	
	for(i=0;i<m;i++){
		scanf("%d",&x);
		if(*s.lower_bound(x)==x) counter1++;
	}
	printf("%d\n",counter1);
	return 0;
}


Measured memory_bytes: 7388
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define Pl pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
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;}
ll INF = 1e+18;
int iINF = 1e9;


int main()
{
  string S; cin >> S;
  reverse(S.begin(), S.end());
  int sz = S.size(); --sz;
  vector<string> cand = {"maerd", "remaerd", "resare", "esare"};
  
  for(int i = 0; i < sz;){
    bool flag = false;
    for(auto comp : cand){
      if(S.substr(i, comp.size()) == comp){ flag = true, i += comp.size(); break;}
    }
    if(!flag){ cout << "NO" << endl; return 0;}
  }

  cout << "YES" << endl;
}

Measured memory_bytes: 3760
#include<stdio.h>
int main()
{
    int a,b,i,j,k;
    scanf("%d",&a);
    int x[a][6];
    for(i=0;i<a;i++){
        for(j=0;j<6;j++){
            scanf("%d",&x[i][j]);
        }
    }
 
    for(i=0;i<a-1;i++){
        for(j=i+1;j<a;j++){
            for(k=0;k<122;k++){
                if(x[i][0]==x[j][0]&&x[i][5]==x[j][5]){
                    if(x[i][1]==x[j][1]&&x[i][4]==x[j][4]){
                        if(x[i][2]==x[j][2]&&x[i][3]==x[j][3]){
                            puts("No");
                            return 0;
                        }
                    }
                    else{
                        b=x[j][1];x[j][1]=x[j][2];x[j][2]=x[j][4];
                        x[j][4]=x[j][3];x[j][3]=b;
                    }
                }
                if(k%2){
                    b=x[j][1];x[j][1]=x[j][0];x[j][0]=x[j][4];
                    x[j][4]=x[j][5];x[j][5]=b;
                }
                else{
                    b=x[j][5];x[j][5]=x[j][2];x[j][2]=x[j][0];
                    x[j][0]=x[j][3];x[j][3]=b;
                }
            }
        }
    }
    puts("Yes");
    return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"

int main(){
  int N,x;
  cin>>N>>x;
  priority_queue<int,vector<int>,greater<int>> Q;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    Q.push(a);
  }
  int ans = 0;
  while(!Q.empty()){
    int a = Q.top();
    if(x >= a){
      Q.pop();
      ans++;
      x -= a;
    }
    else
      break;
  }
  if(Q.empty() && x > 0)
    ans--;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 0
num = 0
bt = 0
bi = 0
for i in range(n):
    t += a[i]
    if t > k:
        t -= a[i]
        break
    else:
        num += 1

for j in range(m):
    t += b[j]
    if t > k:
        t -= b[j]
        break
    else:
        bt += b[j]
        bi += 1

inum = num
num += bi
cnum = num

for i in range(inum):
    t -= a[inum - i - 1]
    cnum -= 1
    while bi < m:
        t += b[bi]
        if t > k:
            t -= b[bi]
            break
        else:
            bi += 1
            cnum += 1
    if num < cnum:
        num = cnum
print(num)

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    int odd = 0;
    int even = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i]%2==0) even ++;
        else odd ++;
    }
    cout << (odd%2==0 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 640