akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#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(){
    string s, ans;
    while(cin >> s){
        int i = 0;
        char a;
        ans = "";
        while(i < s.size()){
            if(s.size() % 2 || s[i] > '6' || s[i + 1] > '5' || s[i] < '1' || s[i + 1] < '1'){
                ans = "NA";
                break;
            }
            if(s[i] == '6'){
                if(s[i + 1] == '1')
                    a = 'z';
                else if(s[i + 1] == '2')
                    a = '.';
                else if(s[i + 1] == '3')
                    a = '?';
                else if(s[i + 1] == '4')
                    a = '!';
                else if(s[i + 1] == '5')
                    a = ' ';
            }else{
                a = 'a' + (s[i + 1] - '1') + 5 * (s[i] - '1');
            }
            ans+= a;
            i+= 2;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1188
type dice = { one : int; two : int; three : int; four : int; five : int; six : int}

type direction = N | S | W | E

let move {one=a;two=b;three=c;four=d;five=e;six=f} = function
    N -> {one=b;two=f;three=c;four=d;five=a;six=e}
  | S -> {one=e;two=a;three=c;four=d;five=f;six=b}
  | W -> {one=c;two=b;three=f;four=a;five=e;six=d}
  | E -> {one=d;two=b;three=a;four=f;five=e;six=c}

let rec turn_right d = function
  | 0 -> d
  | i -> let {one=a;two=b;three=c;four=d;five=e;six=f} = d in
    turn_right {one=a;two=c;three=e;four=b;five=d;six=f} (i-1)

let () =
  let read_dice () =  Scanf.scanf "%d %d %d %d %d %d\n"
      (fun a b c d e f -> {one=a;two=b;three=c;four=d;five=e;six=f}) in
  let d1,d2 = read_dice (), read_dice () in
  let all_pattern = List.map (fun l -> List.fold_left
                                 (fun dice direc -> move dice direc) d2 l) [[];[S];[W];[N];[E];[S;S]]
                    |> List.fold_left (fun acc d -> List.map
                                          (fun t -> turn_right d t)
                                          [0;1;2;3] |> (@) acc) [] in
  all_pattern
  |> List.filter (fun x -> x=d1)
  |> (function [] ->  "No"
             | _ -> "Yes")
  |> print_endline

Measured memory_bytes: 2212
S = input()
triple = []
gap    = 1000
for x in range(len(S)-2):
    triple.append(int(S[x] + S[x+1] + S[x+2]))
for x in triple:
    if x >= 753:
        if x - 753 <= gap:
            gap = x - 753
    else :
        if 753 - x <= gap:
            gap = 753 - x
print(gap)

Measured memory_bytes: 3060
n = int(input())
ans = []
# 1-200までの全奇数の約数を求める
for i in range(1, 200, 2):
    cnt = 0
    for j in range(1, i + 1):
        if i % j == 0:
            cnt += 1

        # 約数の数が0個の奇数を配列にいれる。
        if cnt == 8:
            ans.append(i)

# N以下の配列の数を求める。
ans2 = []
for k in ans:
    if k <= n:
        ans2.append(k)

print(len(ans2))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;
const int mod = 1000000007;

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  deque<int> dq;
  REP(i, n){
    auto p = lower_bound(ALL(dq), a[i]);
    if(p == dq.begin()){
      dq.push_front(a[i]);
    }else{
      *(p-1) = a[i];
    }
  }
  cout << dq.size() << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <unordered_map>

#define MIN(a,b) (a)>(b)?(b):(a)

using namespace std;

using P=pair<int, int>;

int main() {
	int N, M;
	cin >> N >> M;
	vector<P> V;
	for (int i = 0, a, b; i < N; i++) {
		cin >> a >> b;
		if (a <= M) {
			V.emplace_back(a, b);
		}
	}

	sort(V.begin(), V.end(), [](const P & a, const P & b) {
		if (a.first == b.first)return a.second > b.second;
		return a.first < b.first;
	});

	int i = 1;
	int ans = 0;
	int j = 0;
	priority_queue<int> Q;
	while (i <= M) {
		for (; j < V.size(); j++) {
			if (V[j].first >i) {
				break;
			}
			Q.push(V[j].second);
		}
		if (!Q.empty()) {
			ans += Q.top(); Q.pop();
		}
		i++;
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 1908
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	long long n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	long long ret=0;
	ret+=n/(a+b)*a;
	ret+=min(n%(a+b),a);
	printf("%lld\n",ret);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,a[200050],c[200050],ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=n;i>=1;i--)
	{
		int res=0;
		for(int j=i+i;j<=n;j+=i)res^=c[j];
		if(res^a[i])c[i]=1;
	}
	for(int i=1;i<=n;i++)if(c[i])ans++;
	printf("%d\n",ans);
	for(int i=1;i<=n;i++)if(c[i])printf("%d ",i);
}

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

using namespace std;

#define pb push_back
#define fi first
#define se second
typedef pair<int, int> ii;
typedef pair<long long, int> li;
typedef pair<long long, pair<int, int> > lii;

const int N = 2e5 + 5;
const long long inf = 1e18 + 123;
int n, a[N], d;
long long ans;
vector<ii> vec;
vector<lii> edge;

struct Bit1 {
    vector<li> node;
    Bit1 (int sz = 0) {
        node.assign(sz + 5, li(inf, 0) );
    }
    void update (int pos, li val) {
        for (; pos < (int)node.size(); pos += pos & -pos) node[pos] = min(node[pos], val);
    }
    li get (int pos) {
        li ret = li(inf, 0);
        for (; pos > 0; pos -= pos & -pos) ret = min(ret, node[pos]);
        return ret;
    }
};

struct Bit2 {
    vector<li> node;
    Bit2 (int sz = 0) {
        node.assign(sz + 5, li(inf, 0) );
    }
    void update (int pos, li val) {
        pos = (int)node.size() - pos;
        for (; pos < (int)node.size(); pos += pos & -pos) node[pos] = min(node[pos], val);
    }
    li get (int pos) {
        pos = (int)node.size() - pos;
        li ret = li(inf, 0);
        for (; pos > 0; pos -= pos & -pos) ret = min(ret, node[pos]);
        return ret;
    }
};

struct Dsu {
    vector<int> pSet, szSet;
    Dsu (int _n = 0) {
        pSet.assign(_n + 5, 0); for (int i = 0; i < (int)pSet.size(); ++i) pSet[i] = i;
        szSet.assign(_n + 5, 1);
    }
    int findSet (int i) { return i == pSet[i] ? i : pSet[i] = findSet(pSet[i]); }
    bool unionSet (int i, int j) {
        i = findSet(i);
        j = findSet(j);
        if (i == j) return false;
        if (szSet[i] > szSet[j]) swap(i, j);
        szSet[j] += szSet[i];
        pSet[i] = j;
        return true;
    }
};

long long cost (int i, int j) { return 1LL * abs(i - j) * d + a[i] + a[j]; }

int main () {
    scanf("%d %d", &n, &d);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
        vec.pb(ii(a[i], i) );
    }
    sort(vec.begin(), vec.end() );

    Bit1 bit1(n);
    Bit2 bit2(n);

    for (auto _ : vec) {
        int i = _.se;
        li tmp1 = bit1.get(i), tmp2 = bit2.get(i);
        if (tmp1.se) edge.pb(lii(cost(tmp1.se, i), ii(tmp1.se, i) ) );
        if (tmp2.se) edge.pb(lii(cost(tmp2.se, i), ii(tmp2.se, i) ) );
        bit1.update(i, li(a[i] - 1LL * i * d, i) );
        bit2.update(i, li(a[i] + 1LL * i * d, i) );
    }
    sort(edge.begin(), edge.end() );

    Dsu dsu(n);

    for (auto _ : edge) {
        if (dsu.unionSet(_.se.fi, _.se.se) ) ans += _.fi;
    }

    cout << ans;

    return 0;
}


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

int main()
{
	int k;
	string s;
	cin>>k>>s;
	
	if(k>=s.size())
		cout<<s<<endl;
	else
	{
		for(int i=0;i<k;i++)
			cout<<s[i];
		cout<<"..."<<endl;
	}
		
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<time.h>
#include<stdlib.h>

using namespace std;

int main(){
    int N; int K; int Q;
    cin >> N; cin >> K; cin >> Q;
    int* getpoints = (int*)malloc(sizeof(int)*N);
    for(int i = 0; i < N; i++) getpoints[i] = 0;
    for(int i = 0; i < Q; i++){
        int crr = 0;
        cin >> crr;
        getpoints[crr - 1] += 1;
    }
    for(int i = 0; i < N; i++){
        if((getpoints[i] + K - Q) > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))

n, a, b = MI()
s = input()
ok = 0
rank = 0
for si in s:
    if si == 'a':
        if ok < a+b:
            print("Yes")
            ok += 1
        else:
            print("No")
    elif si == 'b':
        rank += 1
        if ok < a+b and rank <= b:
            print("Yes")
            ok += 1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
const int inf=1e9;
int main() {
  
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
    	int h,w,k;cin>>h>>w>>k;
    	int ans=INT_MAX;
    	int y=(1<<(h-1));
    	string a[h];
    	rep(i,h)cin>>a[i];
    	for(int i=0;i<y;i++){
    		int t=__builtin_popcount(i);
    		int temp=t;
    		int dp[t+1][w];
    		int f=1;
    		for(int j=0;j<w;j++){
    			int s=0;
    			int u=0;
    			for(int l=0;l<h;l++){
    				if(a[l][j]=='1'){
    					s++;
    				}
    				int val=(1<<l)&(i);
    				if(val||(l==(h-1))){
    					dp[u][j]=s;
    					// cout<<s<<endl;
    					s=0;
    					if(dp[u][j]>k){
    						f=0;break;
    					}
    					u++;
    				}
    			}
    		}
    		if(!f)continue;
    		int flag[t+1]={0};
    		for(int j=0;j<w;j++){
    			int u=1;
    			rep(l,t+1){
    				flag[l]+=dp[l][j];
    				if(flag[l]>k){
    					temp++;u=0;
    					break;
    				}
    			}
    			if(!u){
    				rep(l,t+1)flag[l]=dp[l][j];
    			}
    		}
    		if(f){
    			ans=min(ans,temp);
    		}
    		
    	}
    	cout<<ans;
    }   
    return 0;   
}   	

Measured memory_bytes: 256
n = int(input())
m = {}
for _ in range(n):
    x, y, d = input().split()
    x, y = int(x) * 2, int(y) * 2
    if d not in m:
        m[d] = [1000000000, -1000000000, 1000000000, -1000000000]
    m[d][0] = min(m[d][0], x)
    m[d][1] = max(m[d][1], x)
    m[d][2] = min(m[d][2], y)
    m[d][3] = max(m[d][3], y)

dx = {'L': -1, 'R': 1, 'U': 0, 'D': 0}
dy = {'L': 0, 'R': 0, 'U': 1, 'D': -1}

px = []
py = []
for d in 'LRUD':
    if d in m:
        px.append((m[d][0], dx[d]))
        px.append((m[d][1], dx[d]))
        py.append((m[d][2], dy[d]))
        py.append((m[d][3], dy[d]))

times = [0]
def append(pa, pb):
    (a, da) = pa
    (b, db) = pb
    if db != da:
        t = (a - b) // (db - da)
        if t >= 0:
            times.append(t)

for i in range(len(px)):
    for j in range(i + 1, len(px)):
        append(px[i], px[j])

for i in range(len(py)):
    for j in range(i + 1, len(py)):
        append(py[i], py[j])

ret = 1000000000000000000
for t in times:
    bb = [1000000000, -1000000000, 1000000000, -1000000000]
    for d in 'LRUD':
        if d in m:
            bb[0] = min(bb[0], m[d][0] + dx[d] * t)
            bb[1] = max(bb[1], m[d][1] + dx[d] * t)
            bb[2] = min(bb[2], m[d][2] + dy[d] * t)
            bb[3] = max(bb[3], m[d][3] + dy[d] * t)
    ret = min(ret, (bb[1] - bb[0]) * (bb[3] - bb[2]))

print(ret / 4.0)

Measured memory_bytes: 46168
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef pair<char,int>P;

int main(){
	
	string s;
	cin>>s;
	
	s+="E";
	vector<P>V;
	
	int cnt=1;
	char lst=s[0];
	for(int i=1;i<s.size();i++){
		if(s[i]==lst){
			cnt++;
		}
		else{
			V.push_back(P(lst,cnt));
			cnt=1;
			lst=s[i];
		}
	}
	
	int ans=0;
	/*
	for(int i=0;i<V.size();i++){
		cout<<V[i].first<<" "<<V[i].second<<endl;
	}
	*/
	
	for(int i=0;i<((int)(V.size()))-2;i++){
		if(V[i].first=='J'&&V[i+1].first=='O'&&V[i+2].first=='I'){
			if(V[i].second>=V[i+1].second && V[i+2].second>=V[i+1].second){
				ans=max(ans,V[i+1].second);
			}
		}
	}
	cout<<ans<<endl;
	
	
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	for(int i = 0; i < n; i++) cin >> p.at(i);

	int cnt = 0;
	for(int i = 0; i < n; i++) {
		if(i != p.at(i) - 1) cnt++;
	}

	if(cnt <= 2) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;
int f[200][200];
int v[200][200];
int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		int xs,ys,xg,yg;
		scanf("%d%d%d%d",&xs,&ys,&xg,&yg);
		xs--;ys--;xg--;yg--;
		int n;
		scanf("%d",&n);
		for(int i=0;i<200;i++)
			for(int j=0;j<200;j++)
				f[i][j]=v[i][j]=0;
		for(int i=0;i<n;i++){
			int p,q,r,s;scanf("%d%d%d%d",&p,&q,&r,&s);
			r--;s--;
			if(q==0){
				for(int j=0;j<4;j++)
					for(int k=0;k<2;k++)
						f[r+j][s+k]=p;
			}else{
				for(int j=0;j<2;j++)
					for(int k=0;k<4;k++)
						f[r+j][s+k]=p;
			}
		}
		if(f[xs][ys]!=f[xg][yg]||!f[xs][ys]){
			printf("NG\n");
			continue;
		}
		queue<pair<int,int> >Q;
		v[xs][ys]=1;
		Q.push(make_pair(xs,ys));
		while(Q.size()){
			int row=Q.front().first;
			int col=Q.front().second;
			Q.pop();
			for(int i=0;i<4;i++){
				if(0<=row+dx[i]&&row+dx[i]<a&&0<=col+dy[i]&&col+dy[i]<b&&!v[row+dx[i]][col+dy[i]]&&f[row+dx[i]][col+dy[i]]==f[row][col]){
					v[row+dx[i]][col+dy[i]]=1;
					Q.push(make_pair(row+dx[i],col+dy[i]));
				}
			}
		}
		if(v[xg][yg])printf("OK\n");
		else printf("NG\n");
	}
}

Measured memory_bytes: 1328
// educational dp - frog 1
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pr cout<<
#define in cin>>
#define tc(t) ll t;cin>>t;while(t--)
#define fr(i,n) for(ll i=0;i<n;i++)
#define mod 1e9+7
#define nl pr "\n"
#define rt return
//ll a[10000];


int main()
{
    ll n;
    in n;
    ll a[n];
    fr(i,n) in a[i];
    ll dp[n];
    fr(i,n) dp[i]=mod;
    dp[0]=0;
    for(ll i=0;i<n;i++)
    {
        if(i+1<n)
            dp[i+1]=min(dp[i]+abs(a[i]-a[i+1]),dp[i+1]);
        if(i+2<n)
            dp[i+2]=min(dp[i]+abs(a[i]-a[i+2]),dp[i+2]);
    }
    //fr(i,n) pr dp[i];
    pr dp[n-1];
	rt 0;
}

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

#define PB push_back
#define MP make_pair
#define fi first
#define se second

typedef long long LL;

const double EPS=1e-9;
const double PI=acos(-1.0);
const int MAXN=100005;
const LL MOD=1000000007;
const int dx[8]={-1, 0, 1, -1, 1, -1, 0, 1}, dy[8]={-1, -1, -1, 0, 0, 1, 1, 1};

void base(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main(){
	string s;
	cin>>s;
	for(int i=0; i<s.length(); i++){
		if(i==3) cout<<8;
		else cout<<s[i];
	}
	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  ll x,y;
  cin >> x >> y;
  ll ans = INF;
  {
    if (x<=y) ans =min(ans,y-x);
  }
  {
    ll nx=-x; 
    if (nx<=y) ans=min(ans,y-nx+1);
  }
  {
    ll ny=-y;
    if(x<=ny) ans=min(ans,ny-x+1);
  }{
    ll nx=-x,ny=-y;
    if(nx<=ny) ans=min(ans,ny-nx+2);
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    long long n, w, i, j;
    cin >> n >> w;
    long long wts[n][2];

    for(i = 0; i < n; ++i)
        cin >> wts[i][0] >> wts[i][1];

    long long dp[n][w + 1];

    for(i = 0; i <= w; ++i)
        dp[0][i] = (wts[0][0] <= i) ? wts[0][1] : 0;
    for(i = 0; i < n; ++i)
        dp[i][0] = 0;

    for(i = 1; i < n; ++i) {
        for(j = 1; j <= w; ++j) {
            dp[i][j] = (wts[i][0] <= j) ? max(dp[i - 1][j], wts[i][1] + dp[i - 1][j - wts[i][0]]) : dp[i - 1][j];
        }
    }
    cout << dp[n - 1][w] << "\n";
    return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
struct modint {
    ll x;
    modint(ll x = 0) : x((x % MOD + MOD) % MOD) {
    }
    ll value() const {
        return x;
    }
    modint operator-() const {
        return modint(-x);
    }
    modint& operator+=(const modint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    modint& operator-=(const modint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    modint& operator*=(const modint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    modint operator+(const modint a) const {
        modint res(*this);
        return res += a;
    }
    modint operator-(const modint a) const {
        modint res(*this);
        return res -= a;
    }
    modint operator*(const modint a) const {
        modint res(*this);
        return res *= a;
    }
    modint pow(ll t) const {
        if (t == 0) return 1;
        modint a = pow(t >> 1);
        a *= a;
        if (t % 2 == 1) a *= *this;
        return a;
    }
    modint inv() const {
        return pow(MOD - 2);
    }
    modint& operator/=(const modint a) {
        return (*this) *= a.inv();
    }
    modint operator/(const modint a) const {
        modint res(*this);
        return res /= a;
    }
};
struct combination {
    vector<modint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) {
            fact[i] = fact[i - 1] * i;
        }
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; i--) {
            ifact[i - 1] = ifact[i] * i;
        }
    }
    modint operator()(int n, int k) {
        if (n < k || k < 0) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
    modint h(int n, int k) {
        n += k - 1;
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} comb(2002002);
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    modint ans = 1;
    int pre = INF;
    for (int i = 1; i < n; i++) {
        ans *= min({i, (a[i - 1] + 1) / 2, pre}) + 1;
        pre = min({i, (a[i - 1] + 1) / 2, pre}) + 1;
    }
    cout << ans.value() << endl;
}


Measured memory_bytes: 31872
def f(n,e,a):
    d[n].extend([a,e,"root" if a<0 else "internal node" if len(d[n][1]) else "leaf"])
    for i in d[n][1]:f(i,e+1,n)
n=input()
c=[0]*n
d=sorted([map(int,raw_input().split()) for _ in range(n)])
for i in d:
    i[1:]=[i[2:]]
    for j in i[1]:c[j]=1
f(c.index(0),0,-1)
for i in d:print "node {0}: parent = {2}, depth = {3}, {4}, {1}".format(*i)

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

int main(void){
  string s;
  cin >> s;
  
  int count = 0;
  for(int i = 0; i < 6; i ++)
    if(s.at(i) == '1') count ++;

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int Sum(int x) {
  int s = 0;
  while (x) {
    s += x % 10;
    x /= 10;
  }
  return s;
}

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

  int N;
  cin >> N;
  int ans = N;
  for (int i = 1; i < N; ++i) {
    ans = min(ans, Sum(i) + Sum(N - i));
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int p[n];
    rep(i,n) cin >> p[i];
    int a = 0;
    rep(i,n){
        if(p[i] != i+1) a++;
    }
    if(a <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include <vector>
using namespace std;
long long Read() {
    long long x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9') {
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
int main() {
    int n,x,y;
    n=Read(),x=Read(),y=Read();
    n-=x;
    n%=y;
    cout<<n<<endl;
    return 0;
}

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


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

const int INF = 1000000000;

int main()
{
	int a,b;

	scanf("%d %d", &a,&b);

	if (a == b)
	{
		printf("Draw\n");
	}else if (a == 1)
	{
		printf("Alice\n");
	}else if (b == 1)
	{
		printf("Bob\n");
	}else if (a > b)
	{
		printf("Alice\n");
	}else
	{
		printf("Bob\n");
	}

	return 0;
}
	

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
        c: usize,
    }

    let mut l = max(max(a,b),c);
    let mut s = min(min(a,b),c);
    let mut m = 0;
    if (a>=b && a<=c) || (a>=c && a<=b) {
        m = a;
    } else if (b>=a && b<=c) || (b>=c && b<=a) {
        m = b;
    } else if (c>=a && c<=b) || (c>=b && c<=a){
        m = c;
    }

    let mut cnt = 0;
    while m>=s+2 {
        s += 2;
        cnt += 1;
    }

    if m==s {
        cnt += l-m;
    } else {
        cnt += l-m+2;
    }

    println!("{}", cnt);

}


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

int main() {
    string s, t;
    cin >> s >> t;
    string r = s;

    string ans = "No";
    do {
        rotate(rbegin(r), rbegin(r) + 1, rend(r));
        if (r == t) ans = "Yes";
    } while (r != s);

    cout << ans << endl;
}


Measured memory_bytes: 256
/***************************************** START OF TEMPLATE *********************************************/
#include<bits/stdc++.h>

using namespace std;

#define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  f              first
#define  s              second
#define  pb             push_back
#define  INPa(a,n)      foo(i,1,n) cin>>a[i];
#define  deb2d(a,n,m)   foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}
#define  deb1d(a,n)     foo(i,1,n)cout<<a[i]<<" ";newl;
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<" ";newl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" ";newl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" ";newl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d;newl;
#define  ll             long long
#define  ld             long double
#define  pll            pair<ll,ll>
#define  vll            vector<ll>
#define  vpll           vector<pll>

const ll   MOD   =  998244353;
const ll   INF   =  LLONG_MAX;
const int  INFi  =  INT_MAX;
const ll   N     =  2e+5 + 8;

vll adj[N]; ll vis[N];
ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

ll test_cases = 1; randomINIT;

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ll n, m, k, f[N], res = 0;


/***************************************** FUNCTION IMPLEMENTATIONS **************************************/
ll fast_pow(ll x, ll y, ll MOD = MOD) {
	ll res = 1;
	while (y) {
		if (y & 1)res = (res * x) % MOD;
		y >>= 1; x = (x * x) % MOD;
	}
	return res;
}

ll mod_inverse(ll x, ll MOD = MOD) {
	return fast_pow(x, MOD - 2, MOD);
}

ll nCr(ll n, ll r) {
	return f[n] * mod_inverse(f[n - r]) % MOD * mod_inverse(f[r]) % MOD;
}
/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN(ll tc) {
	cin >> n >> m >> k;
	foo(p, n - k, n) res = (res + nCr(n - 1, p - 1) * m % MOD * fast_pow(m - 1, p - 1)) % MOD;
	cout << res;
}

int main() {
	SPEED;
	f[0] = 1;
	foo(i, 1, N - 1)f[i] = f[i - 1] * i % MOD;
	//cin>>test_cases;
	foo(i, 1, test_cases) {
		MAIN(i);
	}
}

Measured memory_bytes: 9884
#include <stdio.h>
#include <math.h>

int main() {
		int inNum;
		int result;
		
		scanf("%d", &inNum);
		if (inNum < 1 || inNum > 100) {
			printf("error\n");
			return 0;
		}
		
		result = pow(inNum, 3.0);
		printf("%d\n", result);
}


Measured memory_bytes: 2100
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
constexpr ll TEN(ll n){return n==0?1:10ll*TEN(n-1);}

constexpr ll inf = TEN(9)+5;
constexpr ll linf = 3*TEN(18);

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

    vector<int> imos(N + 1);

    rep(i, M) {
        int l, r; cin >> l >> r;
        --l, --r;
        imos[l]++, imos[r + 1]--;
    }

    rep(i, N) imos[i + 1] += imos[i];

    int ans = 0;
    rep(i, N) if (imos[i] == M) ans++;

    cout << ans << endl;
}


Measured memory_bytes: 3740
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        // num of switch
        int n = sc.nextInt();
        // num of light bulb
        int m = sc.nextInt();

        // switches each light bulb is connected to
        int[][] s = new int[m][];

        // when light bulb is on
        boolean[] p = new boolean[m];

        for (int i=0; i < m; i++) {
            int k = sc.nextInt();
            s[i] = new int[k];
            for (int j=0; j < k; j++) {
                s[i][j] = sc.nextInt();
            }
        }

        for (int i=0; i < m; i++)
            p[i] = itob(sc.nextInt());

        AtomicInteger ans = new AtomicInteger(0);

        dfs(0, n, ans, new boolean[n], s, p);

        System.out.println(ans);
    }

    private static boolean itob(int i) {
        return i == 1;
    }

    private static void dfs(int depth, int maxDepth, AtomicInteger ans, boolean[] sw, int[][] s, boolean[] p) {
        if (depth == maxDepth) {
            if (check(sw, s, p))
                ans.getAndIncrement();
        } else {
            sw[depth] = true;
            dfs(depth+1, maxDepth, ans, sw, s, p);

            sw[depth] = false;
            dfs(depth+1, maxDepth, ans, sw, s, p);
        }
    }

    private static boolean check(boolean[] sw, int[][] s, boolean[] p) {
        for (int i=0; i < p.length; i++) {
            boolean bulb = false;

            for (int as : s[i]) {
                if (sw[as-1])
                    bulb = !bulb;
            }
            if (bulb != p[i]) {
                return false;
            }
        }
        return true;
    }

}


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

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

typedef long long LL;

int main(){
  int n;
  cin >> n;
  vector<LL> a(n);
  int ki=0;
  LL total=0;
  int pos;
  bool one=false;
  for(int i=0;i<n;i++){
    cin >> a[i];
    total+=a[i]-1;
    if(a[i]%2){
      pos=i;
      ki++;
    }
    if(a[i]==1) one=true;
  }
  if(n==1){
    cout << "Second" << endl;
    return 0;
  }
  LL kaisu=1;
  int gcd,x,y;
  while(1){
    if(one){
      cout << (((kaisu+total)%2)?"Second":"First") << endl;
      return 0;
    }
    if(total%2){
      cout << (kaisu%2?"First":"Second") << endl;
      return 0;
    }
    if(ki>1){
      cout << (kaisu%2?"Second":"First") << endl;
      return 0;
    }
    kaisu++;
    a[pos]--;
    gcd=a[0];
    for(int i=1;i<n;i++){
      x=gcd;
      y=a[i]%gcd;
      if(y==0) continue;
      while(x%y){
        gcd=x;
        x=y;
        y=gcd%y;
      }
      gcd=y;
    }
    ki=0;
    total=0;
    for(int i=0;i<n;i++){
      a[i]/=gcd;
      total+=a[i]-1;
      if(a[i]%2){
        ki++;
        pos=i;
      }
      if(a[i]==1) one=true;
    }
    // for(int i=0;i<n;i++) cout << a[i] << " ";
    // cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#define MAX 26
#define NIL -1
using namespace std;

struct Node {
	int parent, left, right;
};

void printPreOrder(Node node[], int parent);
void printInOrder(Node node[], int left);
void printPostOrder(Node node[], int left);

int main() {
	Node node[MAX];
	int i, j, n, id, root, left;
	cin >> n;
	for (i = 0; i < n; i++) {
		node[i].parent = NIL;
		node[i].left = NIL;
		node[i].right = NIL;
	}

	for (i = 0; i < n; i++) {
		cin >> id;
		cin >> node[id].left >> node[id].right;
		node[node[id].left].parent = id;
		node[node[id].right].parent = id;
	}

	root = 0;
	while (node[root].parent != NIL) {
		root = node[root].parent;
	}

	cout << "Preorder\n";
	printPreOrder(node, root);
	cout << "\nInorder\n";
	printInOrder(node, root);
	cout << "\nPostorder\n";
	printPostOrder(node, root);
	cout << endl;

	return 0;
}

void printPreOrder(Node node[], int parent) {
	cout << " " << parent;
	if (node[parent].left != NIL)printPreOrder(node, node[parent].left);
	if (node[parent].right != NIL)printPreOrder(node, node[parent].right);
}

void printInOrder(Node node[], int parent) {
	if (node[parent].left != NIL)printInOrder(node, node[parent].left);
	cout << " " << parent;
	if (node[parent].right != NIL)printInOrder(node, node[parent].right);
}

void printPostOrder(Node node[], int parent) {
	if (node[parent].left != NIL)printPostOrder(node, node[parent].left);
	if (node[parent].right != NIL)printPostOrder(node, node[parent].right);
	cout << " " << parent;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define ld long double
#define vi vector<int>
#define si set<int>
#define vc vector<char>
#define vll vector<ll>
#define vd vector<double>
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define pii pair<int,int>
#define pi 3.14159265358979323846264338327950
using namespace std ;
// #define debug

const int MOD = 1E9 + 7 ;
const int N = 1E5 ;

vi cnt(N + 5, 0) ;
int main() {
    #ifdef debug
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif // debug
    optimize

    int n ; cin >> n ; ll sum = 0 ;
    vll a(n) ; lp(i, 0, n-1) { cin >> a[i] ; sum += a[i] ; ++cnt[a[i]] ; }
    int q ; cin >> q ;
    lp(qq, 1, q) {
        ll ai , bi ; cin >> ai >> bi ;

        sum = sum + (bi - ai) * cnt[ai] ;
        cnt[bi] += cnt[ai] ;
        cnt[ai] = 0 ;
        cout << sum << endl ;
    }
}


Measured memory_bytes: 4500
#include <cstdio>
#include <algorithm>
typedef long long ll;

int n,k,c[200005];
ll Ns,Ans;
struct Rec{ll s;int p;inline bool operator<(const Rec &o)const{return s!=o.s?s<o.s:p<o.p;}}a[200005];

void Modify(int x){for(++x;x<=n+1;x+=x&-x)++c[x];}
int Query(int x,int s=0){for(++x;x;x^=x&-x)s+=c[x];return s;}

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1,x;i<=n;++i)scanf("%d",&x),a[i]=(Rec){Ns+=x-k,i};
    std::sort(a,a+n+1);
    for(int i=0;i<=n;++i)Ans+=Query(a[i].p),Modify(a[i].p);
    return printf("%lld\n",Ans),0;
}

Measured memory_bytes: 4096
x, n = map(int, input().split())
if n == 0:
    print(x)
    quit()

ps = list(map(int, input().split()))
if not x in ps:
    print(x)
    quit()

m_diff = 0
b_diff = 0

m = x
while m in ps:
    m_diff += 1
    m -= 1

b = x
while b in ps:
    b_diff += 1
    b += 1

if (m_diff > b_diff):
    print(b)
else:
    print(m)


Measured memory_bytes: 9196
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<int> b(a),c(a);
  map<int,int> f;
  rep(i,a)
    cin>>b[i];
  sort(all(b));
  int d=1;
  c[0]=b[0];
  f[b[0]]++;
  rep(i,a-1){
  if(b[i]!=b[i+1]){
  c[d]=b[i+1];
    d+=1;
  }
    f[b[i+1]]++;
  }
  int g=0;
  rep(i,a){
  if(c[i]<=f[c[i]])
    g+=f[c[i]]-c[i];
    else
      g+=f[c[i]];
  }
 out(g);
}

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

int main() {
  string n;
  cin >> n;
  int s = 0;
  rep(i, n.size()) s += n[i] - '0';
  if (s % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3720
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=1,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi A(n);
  VIN(A)
  SORT(A);
  REP(i,n){
  	if(A[i]%4==0) z++;
    else if(A[i]%2==0) y++;
    if(y==2){
      y = 0;
      z++;
    }
  }
  Yes(z >= n/2);
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

typedef long long i64;

const int MOD = 1000000007;

class Matrix {
public:
  i64 num[5][5];
  int n, m;
  Matrix(int _n = 0, int _m = 0) {
    n = _n, m = _m;
    memset(num, 0, sizeof num);
  }
  inline friend Matrix operator * (const Matrix &a, const Matrix &b) {
    Matrix c = Matrix(a.n, b.m);
    for (int i = 0; i < a.n; ++i)
      for (int j = 0; j < b.m; ++j)
	for (int k = 0; k < a.m; ++k)
	  c.num[i][j] = (c.num[i][j] + a.num[i][k] * b.num[k][j]) % MOD;
    return c;
  }
} res, T1, T2, T;

Matrix fpm(Matrix x, int y) {
  Matrix res = Matrix(x.n, x.n);
  for (int i = 0; i < x.n; ++i) res.num[i][i] = 1;
  while (y) {
    if (y & 1) res = res * x;
    x = x * x;
    y >>= 1;
  }
  return res;
}

int N, M, X[100005];

int main() {
  scanf("%d%d", &N, &M);
  
  res = Matrix(1, 3), res.num[0][0] = 1;
  T1 = Matrix(3, 3), T2 = Matrix(3, 3);

  T1.num[0][0] = T1.num[1][1] = T1.num[2][2] = 1;
  T1.num[0][1] = 2, T1.num[1][2] = 1, T1.num[0][2] = 1;
  T1.num[1][0] = 1, T1.num[2][0] = 1, T1.num[0][0] += 1;
  T2 = T1, T2.num[1][0] = T2.num[2][0] = 0, T2.num[0][0] -= 1;
  
  for (int i = 1; i <= M; ++i) {
    scanf("%d", &X[i]);
    res = res * fpm(T1, X[i] - X[i - 1] - 1) * T2;
  }

  res = res * fpm(T1, N - X[M]);

  printf("%lld\n", res.num[0][2]);
  
  return 0;
}

Measured memory_bytes: 512
import java.util.*

fun main(args: Array<String>) {
    val k = Integer.parseInt(readNext())
    val s = readNext()
    val list = s.split(" ")
    var doubleList = ArrayList<Double>()
    for(i in 0..(k - 1)) {
        doubleList.add(1.0 / list.get(i).toDouble())
    }
    val sum = doubleList.sum()
    val result = 1 / sum
    println(result)
//    println(result)
}


    fun readNext(): String {
        return readLine()!!
    }


Measured memory_bytes: 37988
#include<stdio.h>

int selectionsort(int A[], int N){
    int minj, t, sw = 0;
    for(int i = 0; i < N; i++){
        minj = i;
        for(int j = i; j < N; j++){
            if( A[j] < A[minj]){
                minj = j;
            }
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if(i != minj) sw++;
    }
    return sw;
}

int main(){
    int A[100], N, sw;
    
    scanf("%d", &N);
    for(int i = 0; i < N; i++) scanf("%d", &A[i]);
    
    sw = selectionsort(A, N);
    
    for(int i = 0; i < N; i++){
        if(i) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);
    
    return 0;
}


Measured memory_bytes: 2040
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll   long long
#define ld long double
#define endl '\n'
#define INF 10000000000000000
#define pll pair<ll,ll>
#define ff first
#define ss second

using namespace std;
const ll N = 1000005;
const ll MOD = 10e8+7;
bool dp[N];
ll a[105];
int main()
{
 //freopen("input.txt","r",stdin);
 //  freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    for(ll i =1;i<=n;i++) {
        cin>>a[i];
    }
    for(ll i =1;i<=k;i++) {
        for(ll j=1;j<=n;j++) {
            if(a[j]<=i && !dp[i-a[j]])
                dp[i]=1;
        }
    }
    if(dp[k]) cout<<"First"; else cout<<"Second";

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long int dp[3010][3010];
main(){
int n;
cin>>n;
long long int a[n];
for(int i=0;i<n;i++)cin>>a[i];

for(int L=n-1;L>=0;L--)for(int R=L;R<n;R++){
	if(L==R)dp[L][R]=a[L];
	else dp[L][R]=max(a[L]-dp[L+1][R],a[R]-dp[L][R-1]);
}

cout<<dp[0][n-1];


}




Measured memory_bytes: 70016
IMPOSSIBLE = -9999999

s = gets.chomp
length = s.length

if length == 1
  puts(1)
  exit
end

dp = Array.new(2) { Array.new(length, 0) }

dp[0][0] = 1
dp[1][0] = IMPOSSIBLE
dp[0][1] = (s[0] == s[1]) ? IMPOSSIBLE : 2
dp[1][1] = 1

(2..(length-1)).each do |i|
  dp[0][i] = dp[1][i-1] + 1
  dp[0][i] = dp[0][i-1] + 1 if (s[i-1] != s[i]) && (dp[0][i] < dp[0][i-1] + 1)
  dp[1][i] = dp[0][i-2] + 1
  dp[1][i] = dp[1][i-2] + 1 if (s[i-3, 2] != s[i-1, 2]) && (dp[1][i] < dp[1][i-2] + 1)
end

puts([dp[0][length-1], dp[1][length-1]].max)

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

int main(){
  string s,p;
  getline(cin,s);
  getline(cin,p);
  s = s + s;
  if(s.find(p)!=string::npos){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

int N;
double p[3000];
double dp[3000][3000];

int main(){
  cin >> N;
  for(int i=0;i<N;i++) cin >> p[i];
  for(int i=0;i<=N;i++) for(int j=0;j<=N;j++) dp[i][j]=0;
  dp[0][0]=1-p[0];
  dp[0][1]=p[0];

  for(int i=0;i<N-1;i++){
    for(int j=0;j<=N;j++){
      dp[i+1][j]+=dp[i][j]*(1-p[i+1]);
      dp[i+1][j+1]+=dp[i][j]*p[i+1];
    }
  }

  double res=0;
  for(int i=(N+1)/2;i<=N;i++) res+=dp[N-1][i];
  cout << setprecision(10) << res << endl;
  return 0;
}


Measured memory_bytes: 70528
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N=100010;
int maxY[N];
int main(){
    int w,h,n;
    cin>>w>>h>>n;
    for(int i=0;i<n;i++){
	int x,y;
	scanf("%d%d",&x,&y);
	maxY[x]=max(maxY[x],y);
    }
    int ans=w-1,M=0;
    for(int x=w-2;x>=0;x--){
	M=max(M,maxY[x+1]);
	ans=min(ans,x+M);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3608
def main(input = STDIN)
  n = input.gets.to_i
  score = Array.new(n, 0)
  m = input.gets.to_i
  a = input.gets.split(" ").map(&:to_i)
  a.each do |i|
    b = input.gets.split(" ").map(&:to_i)
    score[i - 1] += n
    b.each_with_index do |j, idx|
      if i == j
        score[idx] += 1
        score[i - 1] -= 1
      end
    end
  end
  puts score
end
main

Measured memory_bytes: 6104