akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
#define MOD 1000000007

int cnt[100010] = {0};

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

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

    if (N % 2 == 0) {
        for (int i = 1; i <= N - 1; i += 2) {
            if (cnt[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
        }
    } else {
        for (int i = 2; i <= N - 1; i += 2) {
            if (cnt[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
        }
        if (cnt[0] != 1) {
            cout << 0 << endl;
            return 0;
        }
    }
    unsigned long long ans = 1;
    for (int i = 0; i < N / 2; i++) {
        ans = (ans * 2) % MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define N 400005
using namespace std;
struct edge{
	int k,next;
}e[40000005];
int n,m,d1,d2,a[1005],b[1000005],id[605][605],col[N],s[1005],top,home[N],cnt=-1,w[1005];
bool ok[1000005];
bool vis[N];
void add(int x,int y){
	cnt++;
	e[cnt].k=y;
	e[cnt].next=home[x];
	home[x]=cnt;
}
void insert(int x,int y){
	add(x,y);add(y,x);
}
void dfs(int k){
	for(int i=home[k];~i;i=e[i].next) if(!col[e[i].k]) col[e[i].k]=3^col[k],dfs(e[i].k);
}
void solve(int d){
	memset(col,0,sizeof(col));
	memset(home,-1,sizeof(home));
	cnt=-1;
	top=0;
	for(int i=0;i<n+n&&i*i<=d;i++) if(ok[d-i*i]) s[++top]=i,w[top]=b[d-i*i];
	for(int i=0;i<n+n;i++){
		for(int p=0;p<n+n;p++){
			int x=id[i][p];
			for(int j=1;j<=top;j++){
				int S=w[j];
				if(p>=s[j]){
					if(i>=S) insert(x,id[i-S][p-s[j]]);
					if(i+S<n+n) insert(x,id[i+S][p-s[j]]);
				}
				if(p+s[j]<n+n){
					if(i>=S) insert(x,id[i-S][p+s[j]]);
					if(i+S<n+n) insert(x,id[i+S][p+s[j]]);
				}
			}
		}
	}
	for(int i=0;i<m;i++) if(vis[i]&&!col[i]) col[i]=1,dfs(i);
	for(int i=0;i<m;i++) if(vis[i]&&col[i]==2) vis[i]=0;
}
int main(){
	scanf("%d%d%d",&n,&d1,&d2);
	m=(n+n)*(n+n);
	for(int i=0;i<=1000;i++) a[i]=i*i,ok[a[i]]=1,b[a[i]]=i;
	for(int i=0;i<n+n;i++)
		for(int p=0;p<n+n;p++) id[i][p]=i*(n+n)+p;
	for(int i=0;i<m;i++) vis[i]=1;
	solve(d1);
	solve(d2);
	int sum=0;
	for(int i=0;i<n+n;i++)
		for(int p=0;p<n+n;p++)
			if(vis[id[i][p]]&&col[id[i][p]]==1){
				if(sum==n*n) break;
				sum++;
				printf("%d %d\n",i,p);
			}
	return 0;
}

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

count = 0
flag = True
while flag:
    for i in range(N-1):
        if h[i] != 0 and h[i+1] == 0:
            count += 1
        if h[i] > 0:
            h[i] -= 1
    if h[N-1] > 0:
        h[N-1] -= 1
        count += 1
        
    count_0 = 0
    for i in range(N):
        if h[i] == 0:
            count_0 += 1
    if count_0 == N:
        flag = False

print(count)

Measured memory_bytes: 3064
#include<stdio.h>
main(){
  int n,i,a,b;
  while(1){
  scanf("%d",&n);
  if(n==0)break;
  for(b=0,i=0;i<n/4;i++){
    scanf("%d",&a);
    b+=a;
  }
  printf("%d\n",b);
  }
  return 0;
}

Measured memory_bytes: 600
A, B, C = map(int, input().split())
flag = False
if A == 7:
	if B == C and (B == 5 or C == 5):
		flag = True

elif B == 7:
	if A == C and (A == 5 or C == 5):
		flag = True

elif C == 7:
	if A == B and (A == 5 or B == 5):
		flag = True		

print("YES") if flag == True else print("NO")

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);
  int con = 1;
  int num = 0;
  for (int i = 0; i < N; i++) {
    if (vec.at(num) == 2) {
      cout << con << endl;
      return 0;
    }
    num = vec.at(num) - 1;
    con++;
  }
  cout << -1 << endl;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	int n=sz(s), cnd1=0, cnd2=0;
	rep(i, n){
		if((i%2 && s[i]=='1') || (i%2==0 && s[i]=='0')) cnd1++;
		if((i%2 && s[i]=='0') || (i%2==0 && s[i]=='1')) cnd2++;
	}
	cout <<min(cnd1, cnd2) <<"\n";
	return 0;
}


Measured memory_bytes: 512
N,K,Q=map(int,input().split())
score = [0]*N
#print(score)
for i in range(Q):
  score[int(input())-1]+=1
#print(score)
for i in range(N):
  if K-Q+score[i]>0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 4680
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

string s;

int main()
{

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

    cin >> s;
    if( s=="SUN" ) cout << 7;
    if( s=="MON" ) cout << 6;
    if( s=="TUE" ) cout << 5;
    if( s=="WED" ) cout << 4;
    if( s=="THU" ) cout << 3;
    if( s=="FRI" ) cout << 2;
    if( s=="SAT" ) cout << 1;

    return 0;
}


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

int main(){
    ll h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    cout<<60*(h2-h1)+(m2-m1)-k<<endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

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

        final Set<Integer> set = IntStream.rangeClosed(1, 3)
                .boxed()
                .collect(Collectors.toSet());

        set.remove(a);
        set.remove(b);

        for (final int value : set) {
            System.out.println(value);
        }
    }
}


Measured memory_bytes: 28628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] b = new int[n-1];
		for(int i = 0; i < n-1; i++) {
			b[i] = sc.nextInt();
		}
		int sum = b[0];
		for(int i = 0; i < n-2; i++) {
			sum += Math.min(b[i], b[i+1]);
		}
		sum += b[n-2];
		System.out.println(sum);
		sc.close();

	}

}

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

int main() {
  int N, x;
  cin >> N;
  for (int i = 0; i < N; i++){
    int l, r;
    x == 0;
    cin >> l >> r;
    x += r - l + 1;
    }
  cout << x << endl;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<long long> h(n);
    vector<long long> che(n);
    rep(i, n)
    {
        cin >> h.at(i);
        che.at(i) = 0;
    }

    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        che.at(a) = max(h.at(b), che.at(a));
        che.at(b) = max(h.at(a), che.at(b));
    }
    int ans = 0;
    rep(i, n)
    {
        if (h.at(i) > che.at(i))
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4844
while True:
    
    H,W = map(int,input().split())
    
    if H==0 and W==0:
        break
    
    for i in range(H):
        for j in range(W):
            if (i+j)%2 ==1:
                print(".",end='')
            else:
                print("#",end='')
        print()
    print()


Measured memory_bytes: 7004
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979
 
void mul_mod(ll& a, ll b){
    a *= b;
    a %= MOD;
}
 
void add_mod(ll& a, ll b){
    b += MOD;
    a += b;
    a %= MOD;
}

int n,m,memo[4444][4444];
bool done[4444][4444];
char s[4444],t[4444];

int dp(int i, int j){
    if(done[i][j]){
        return memo[i][j];
    }
    done[i][j] = true;
    if(i == n || j == m){
        memo[i][j] = 0;
    }else if(s[i] != t[j]){
        memo[i][j] = 0;
    }else{
        memo[i][j] = dp(i+1,j+1) + 1;
    }
    return memo[i][j];
}

int main(void){
    int i,j,ans;
    while(scanf(" %s ",s)!=EOF){
        fill(done[0],done[4444],false);
        ans = 0;
        scanf(" %s ",t);
        n = strlen(s); m = strlen(t);
        for(i=0; i<n; ++i){
            for(j=0; j<m; ++j){
                if(!done[i][j]){
                    ans = max(ans,dp(i,j));
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  bool flag[4] = {false};
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'N') {
      flag[0] = true;
    }
    else if (s[i] == 'S') {
      flag[1] = true;
    }
    else if (s[i] == 'W') {
      flag[2] = true;
    }
    else {
      flag[3] = true;
    }
  }
  if ((flag[0] == flag[1]) && (flag[2] == flag[3])) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#D問題
N, M=map(int, input().split())
V = input().split()
V_i = [int(i) for i in V]

ans = 0
for i in range(M+1):
    for j in range(M+1-i):
        if i+j >N:
            break;
        num = 0
        dump_num = []
        for k in range(i):
            num += V_i[k]
            dump_num.append(V_i[k])
        for k in range(N-1,N-j-1,-1):
            num+=V_i[k]
            dump_num.append(V_i[k])
        dump_num.sort()
        for k in range(M-i-j):
            if k >= len(dump_num):
                break;
            if dump_num[k] >= 0:
                break;
            num -= dump_num[k]
        
        if num >= ans:
            ans = num
print(ans)
            

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

Measured memory_bytes: 600
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll X, Y, Z, ans=0;
    in3(X, Y, Z);
    while(1){
        if(ans*Y+(ans+1)*Z > X){
            put(--ans);
            return 0;
        }
        ans++;
    }
}


Measured memory_bytes: 128
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N, K;
    cin >> N >> K;
    deque<ll> D;
    rep(i, N) {
        ll v;
        cin >> v;
        D.push_back(v);
    }

    ll ans = 0;

    for (int a = 0; a <= N; a++) {
        for (int b = 0; b <= N; b++) {
            if (a + b <= N && a + b <= K) {
                ll cnt = 0;
                vector<ll> v;
                rep(i, a) {
                    cnt += D[i];
                    v.push_back(D[i]);
                }

                rep(j, b) {
                    cnt += D[N - 1 - j];
                    v.push_back(D[N - 1 - j]);
                }

                sort(all(v));

                // 捨てる操作は最大でK-a-b回できる。-のやつは捨てられるだけ捨てよう
                rep(k, K - a - b) {
                    if (k >= v.size())
                        continue;
                    if (v[k] < 0)
                        cnt -= v[k];
                }

                ans = max(ans, cnt);
            }
        }
    }

    cout << ans << endl;
}

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

using namespace std;

int main() {
	string a, b;
	cin >> a >> b;
	if (a.length() > b.length()) {
		cout << "GREATER" << endl;
		return 0;

	}
	else if (a.length() < b.length()) {
		cout << "LESS" << endl;
		return 0;

	}
	else if (a==b) {
		cout << "EQUAL" << endl;
		return 0;
	}
	else {
		for (int i = 0; i < a.length(); i++) {
			if ((int)a[i] > (int)b[i]) {
				cout << "GREATER" << endl;
		return 0;

			}
			if ((int)a[i] < (int)b[i]) {
				cout << "LESS" << endl;
				return 0;

			}
		}
	}

}

Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

H, W, A, B = list(map(int, sys.stdin.readline().split()))


# dp = np.ones(W, dtype=int)
# for h in range(1, H - A):
#     dp = dp.cumsum() % MOD
# for h in range(H - A, H):
#     dp[B:] = dp[B:].cumsum() % MOD
# print(dp[-1])


def get_factorials(max, mod=None):
    """
    階乗 0!, 1!, 2!, ..., max!
    :param int max:
    :param int mod:
    :return:
    """
    ret = [1]
    n = 1
    if mod:
        for i in range(1, max + 1):
            n *= i
            n %= mod
            ret.append(n)
    else:
        for i in range(1, max + 1):
            n *= i
            ret.append(n)
    return ret

def mod_inv(a, mod):
    """
    a の逆元
    :param int a:
    :param int mod:
    :return:
    """
    return pow(a, mod - 2, mod)


factorials = get_factorials(H + W, MOD)


def ncr(n, r, mod=None):
    """
    scipy.misc.comb または scipy.special.comb と同じ
    組み合わせの数 nCr
    :param int n:
    :param int r:
    :param int mod: 3 以上の素数であること
    :rtype: int
    """
    if n < r:
        return 0

    return factorials[n] * mod_inv(factorials[r], mod) * mod_inv(factorials[n - r], mod) % mod


ans = 0
for i in range(W - B):
    ans += ncr((H - A - 1) + (W - i - 1), W - i - 1, MOD) * ncr((A - 1) + i, i, MOD)
    ans %= MOD
print(ans)


Measured memory_bytes: 52464
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <map>

using namespace std;


int main(){

	long long N,M;
	cin>>N>>M;
	long long H[N];
	int highest[N];
	for(int i=0;i<N;i++){
		highest[i]=1;
	}
	long long A[M],B[M];
	long long AA[M],BB[M];
	for(int i=0;i<N;i++){
		cin>>H[i];
	}
	for(int i=0;i<M;i++){
		cin>>AA[i]>>BB[i];
		A[i]=AA[i]-1;
		B[i]=BB[i]-1;
	}

	for(int i=0;i<M;i++){
		if(H[A[i]]>H[B[i]]){
			highest[B[i]]=0;
		}else if(H[A[i]]<H[B[i]]){highest[A[i]]=0;
		}else{
			highest[A[i]]=0;
			highest[B[i]]=0;
		}
	}
	long long ryo=0;
	for(int i=0;i<N;i++){
		ryo=ryo+highest[i];
	}

	cout<<ryo<<endl;


}


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

int h,w,r,c;

enum DIR { L, U, R, D };
int di[] = { 0, -1, 0, 1 };
int dj[] = { -1, 0, 1, 0 };
int open[510][510][4];
int win[510][510];

bool inner(int i, int j){
    return i >= 0 && j >= 0 && i < h && j < w;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(cin >> h >> w >> r >> c && h){
        --r; --c;
        memset(win, 0, sizeof win);
        memset(open, 0, sizeof open);
        rep(i,h*2+1){
            if(i%2 == 0){
                rep(j,w){
                    int x;
                    cin >> x;
                    open[i/2][j][U] = !x;
                    if(i/2) open[i/2-1][j][D] = !x;
                }
            } else {
                rep(j,w+1){
                    int x;
                    cin >> x;
                    open[i/2][j][L] = !x;
                    if(j) open[i/2][j-1][R] = !x;
                }
            }
        }
        queue<pair<int,int>> q;
        rep(i,h)rep(j,w) if(i == 0 || j == 0 || i == h-1 || j == w-1) q.emplace(i,j);
        while(q.size()){
            int ci,cj;
            tie(ci,cj) = q.front();
            q.pop();
            int cnt[2] = {};
            if(win[ci][cj]) continue;
            rep(d,4){
                int ni = ci + di[d];
                int nj = cj + dj[d];
                if(!inner(ni,nj) || win[ni][nj]) ++cnt[open[ci][cj][d]];
            }
            if(cnt[0] && cnt[1]){
                win[ci][cj] = true;
                rep(d,4){
                    int ni = ci + di[d];
                    int nj = cj + dj[d];
                    if(inner(ni,nj) && !win[ni][nj]) q.emplace(ni,nj);
                }
            }
        }
        bool ok = win[r][c];
        rep(d,4){
            int ni = r + di[d];
            int nj = c + dj[d];
            if(open[r][c][d] && (!inner(ni,nj) || win[ni][nj])) ok = true;
        }
        cout << (ok ? "Yes" : "No") << '\n';
    }
}

Measured memory_bytes: 8248
def S(x1,y1,x2,y2,x3,y3):
    return ((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2.0
import sys
for dataset in sys.stdin:
    xa,ya,xb,yb,xc,yc,xd,yd=map(float,dataset.split(","))
    ABC=S(xa,ya,xb,yb,xc,yc)
    BCD=S(xb,yb,xc,yc,xd,yd)
    CDA=S(xc,yc,xd,yd,xa,ya)
    DAB=S(xd,yd,xa,ya,xb,yb)
    if ABC>0 and BCD>0 and CDA>0 and DAB>0:
        print "YES"
    elif ABC<0 and BCD<0 and CDA<0 and DAB<0:
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 4256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846


using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

const LL MOD = 998244353;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(a + b, min(b + c, c + a)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int n,k;
int a[100001];

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		scanf("%d",&k);
		int l=0,r=n-1,cnt=0;
		while(1){
			cnt++;
			int m=(l+r)/2;
			if(m<0)break;
			//printf("%d %d %d %d %d %d\n",l,m,r,a[l],a[m],a[r]);
			if(a[m]==k || r-l<=0)break;
			if(a[m]<k)l=m+1;
			if(a[m]>k)r=m-1;
			if(r-l<0)break;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1032
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    string a,b;
    cin >> a >> b;
    int num = stoi(a+b);
    bool ok = false;
    for (int i = 1; i*i <= 100100; i++){
        if (i*i == num){
            ok = true;
        }
    }
    if (ok){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int dyy[]={0,-1,0,1};
int dxx[]={-1,0,1,0};

#define int ll

int n,k;
int x[100010],y[100010];
vector <int> v(100010);
vector <int> p(100010);
signed main(){
    cin>>n>>k;
    rep(i,0,n)cin>>v[i];
    int ans=1e9;
    rep(i,0,n-k+1){
        int j=i+k-1;
        if(v[i]<0&&v[j]>0)ans=min(ans,abs(v[i])+abs(v[j])+min(abs(v[i]),abs(v[j])));
    else ans=min(ans,max(abs(v[i]),abs(v[j])));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
map<int,ll> cnt;
int n;
ll k;
int main(){
    cin >> n >> k;
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        cnt[a] += b;
    }
    for(auto it = cnt.begin(); it != cnt.end(); ++it){
        k -= it->second;
        if(k <= 0){
            cout << it->first << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 4224
X = int(input())

n_500 = 0
n_5 = 0

while True:
    if X // 500 != 0:
        n_500 += 1
        X -= 500
    else:
        break

while True:
    if X // 5 != 0:
        n_5 += 1
        X -= 5
    else:
        break

print(1000*n_500 + 5*n_5)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    string T;
    cin >> T;
    ll Dcount=0, PDcount=0;
    for(size_t i=0;i<T.size(); i++)
    {
        if(T[i]=='?')
        {
            T[i] = 'D';
        }
    }
    cout << T << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

int main(){
	int n;
	while(scanf(" %d", &n) != EOF){
		int p=n%39;
		
		printf("3C");
		if(p==0) printf("39\n");
		else if(p < 10) printf("0%d\n", p);
		else printf("%d\n", p);
	}

	return 0;
} 

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

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

#define rrep(i,n) for(int i =n; i >=0; --i)

#define rep_(i,m,n) for(int i =m; i <n; ++i)

#define INF 2e9

#define ll long long

const ll MOD = 1000000007;

const  long double PI=(acos(-1));

const  long double EPS=0.0000000001;

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

    sort(a.begin(),a.end());

    bool flag = true;
    rep(i,n-1){
        if(a[i] == a[i+1])flag = false;
    }

    if(flag)cout << "YES" << endl;
    else cout << "NO" << endl;



    return 0;
}

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

using namespace std;
using ll = long long;

ll dp[1005][1005];
const ll MOD_VAL= 1e9+7;
string maps[1005];

int h, w;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>h>>w;
    dp[1][1] = 1;
    for(int i=0;i<h;i++){
        cin>>maps[i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i==0 && j==0) continue;
            if(maps[i][j]=='#') continue;
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j])%MOD_VAL;
        }
    }
    cout<<dp[h][w];

    return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline void mod_add(long long &x, long long y) {
	x += y;
	if(x >= mod) x -= mod;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	string s;
	cin >> s;
	int n = s.size();
	vector<vector<long long>> dp(n + 1, vector<long long>(4));
	string t = "ABC?";
	dp[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 4; j++) {
			if(s[i] == t[j]) {
				if(j != 3) {
					for(int k = 0; k < 4; k++) {
						mod_add(dp[i + 1][k], dp[i][k]);
					}
					mod_add(dp[i + 1][j + 1], dp[i][j]);
				}
				else {
					for(int k = 0; k < 4; k++) {
						mod_add(dp[i + 1][k], dp[i][k] * 3 % mod);
					}
					for(int k = 0; k < 3; k++) {
						mod_add(dp[i + 1][k + 1], dp[i][k]);
					}
				}
			}
		}
	}
	cout << dp[n][3] << endl;
	return 0;	
}


Measured memory_bytes: 7376
#include <bits/stdc++.h>
#include <time.h>  
#define f first
#define s second
#define rep(i, l, r) for (long long i = (l); i < (r); i++)
#define repb(i, r, l) for (long long i = (r); i > (l); i--)
#define pb push_back
 
using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef deque <long long> dq;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull; 
const int MAX_CHAR=256;
 
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 
const ll mod = 1e9 + 7;
 
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
} 
 
ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

bool sortinrev(const pair<ll,string> &a,  
               const pair<ll,string> &b) 
{ 
       return (a.first > b.first); 
}
 
vl countFreq(ll arr[], ll n) 
{ 
    unordered_map<ll, ll> mp; 
    vector <ll> v;
    
    for (ll i = 0; i < n; i++) 
        mp[arr[i]]++; 
   
    for (auto x : mp) 
        v.pb(x.second);
    
    return v;
}
 
bool sortbysec(const pair<ll, ll>& a, 
               const pair<ll, ll>& b) 
{ 
    return (a.second < b.second); 
} 

ll binarySearch(ll arr[], ll l, ll r, ll x) 
{ 
    while (l <= r) 
    { 
        ll m = l + (r - l) / 2; 
        if (arr[m] == x) 
            return m; 
        if (arr[m] < x) 
            l = m + 1; 
        else
            r = m - 1; 
    }
    return -1; 
}

const ll MAXSIEVE=(1e3);
ll spf[MAXSIEVE];
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXSIEVE; i++) 
        spf[i] = i; 

    for (ll i=4; i<MAXSIEVE; i+=2) 
        spf[i] = 2; 
  
    for (ll i=3; i*i<MAXSIEVE; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXSIEVE; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}

int main()
{
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    
    while(t--)
    {
        ll k;
        cin >> k;
        
        ll sum=0;
        rep(i,1,k+1)
            rep(j,1,k+1)
                rep(l,1,k+1)
                    sum+=gcd(i,gcd(j,l));
        
        cout << sum << endl;
    }
}


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

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

            for(int i=1;i<n; i++)
            {
                int tmp = int.Parse(Console.ReadLine());

                if (i == 1) res = tmp - min;
                else
                    res = (res >= (tmp - min) ? res : tmp - min);
                min = min < tmp ? min : tmp;
            }

            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 9084
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define ll long long
#define assign_max(into, compared) (into = max((into), (compared))) 

using namespace std;

int main(void){
    int N,M;
    cin >> N >> M;
    vector<bool> is_broken (N, false);
    for(int i = 0;i < M;i++){
        int job;
        cin >> job;
        is_broken[job] = true;
    }
    vector<ll> dp (N+1, 0);
    dp[0] = 1;
    for(int i = 0;i < N;i++){
        if(i+1 <= N && !is_broken[i+1]) dp[i+1] = (dp[i+1] + dp[i]) % 1000000007;
        if(i+2 <= N && !is_broken[i+2]) dp[i+2] = (dp[i+2] + dp[i]) % 1000000007;
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int dp[61][2][2][2] = {};
long long L, R;

int main() {
    cin >> L >> R;

    dp[60][0][0][0] = 1;
    for(int i=59; i>=0; --i) {
        int l = L >> i & 1;
        int r = R >> i & 1;
        for(int j=0; j<2; ++j) {
            for(int k=0; k<2; ++k) {
                for(int s=0; s<2; ++s) {
                    int prev = dp[i + 1][j][k][s];
                    for(int x=0; x<2; ++x) {
                        for(int y=0; y<2; ++y) {
                            if(x && !y) continue;
                            int nj = j, nk = k, ns = s;
                            
                            if(!j && l && !x) continue;
                            if(!l && x) nj = 1;

                            if(!k && !r && y) continue;
                            if(r && !y) nk = 1;

                            if(!s && x!=y) continue;
                            if(x && y) ns = 1;

                            dp[i][nj][nk][ns] = (dp[i][nj][nk][ns] + prev) % MOD; 
                        }
                    }
                }
            }
        }
    }

    int res = 0;
    for(int j=0; j<2; ++j) {
        for(int k=0; k<2; ++k) {
            for(int s=0; s<2; ++s) {
                res = (res + dp[0][j][k][s]) % MOD;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 384
n = int(input())
mochi = []
for i in range(n) :
	m = int(input())
	mochi.append(m)
mochi.sort(reverse=True)
count = 1
old = mochi[0]
for new in mochi[1:] :
	if old == new :
		continue
	elif old > new :
		old = new
		count += 1
	else :
		break
print(count)

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

 struct node{

  struct node *right,*left,*parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int);
void inorder(Node);
void preorder(Node);
Node find(Node,int);


int main(){
  int n,k,i;
  char str[20];
  Node get;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",str);
    if(str[0]=='f') {
      scanf("%d",&k);
      get = find(root,k);
      if(get != NIL) printf("yes\n");
      else printf("no\n");
    }else if(strcmp(str,"insert")==0){
      scanf("%d",&k);
      insert(k);
    }else if(strcmp(str,"print")==0 ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
}


  }

  return 0;
  }


void insert(int k){
  Node y,x,z;

  y= NIL; //x's parent
  x=root;
  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;
    
  }
  z->parent = y;
  if(y==NIL){
    root=z;

  }else{
    if(z->key < y->key){
      y->left =z;
    }else{
      y->right =z;
    }

  }


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


}

Node find(Node x,int k){

  while(x != NIL&&k !=x->key){
    if(k < x->key) x = x->left;
    else x = x->right;

  }


  return x;
}



Measured memory_bytes: 20452
#include <iostream>
#include <climits>
#include <cstring>
#include <queue>

using namespace std;

bool field[100][100];
int w, h, dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1},
	dp[100][100];

void solve()
{
	queue<int> qux, quy;
	
	for( int j = 0; j < 2*h-1; j++)
		for( int i = 0; i < 2*w-1; i++)
			dp[j][i] = INT_MAX;
	
	dp[0][0] = 1;
	qux.push(0);
	quy.push(0);
	
	while( !qux.empty() && !quy.empty() )
	{

		int x = qux.front();
		int y = quy.front();

		qux.pop();
		quy.pop();
		
		for(int i = 0; i < 4; i++)
		{
			int nx = x + dx[i];
			int ny = y + dy[i];

			if( nx >= 0 && nx < 2*w-1 && ny >= 0 && ny < 2*h-1 && field[ny][nx] != 1 )
			{
				nx += dx[i];
				ny += dy[i];

				if( dp[ny][nx] > dp[y][x] + 1 )
				{
					dp[ny][nx] = dp[y][x] + 1;
					qux.push(nx);
					quy.push(ny);
				}
			}
		}

	}

	return;
}

int main()
{
	while( cin >> w >> h, w||h)
	{
		memset(field, 0, sizeof(field));

		for(int j = 0; j < 2*h-1; j++)
		{
			if( j % 2 == 0 )
			{
				for(int i = 0; i < w-1; i++)
				{
					cin >> field[j][2*i+1];
				}
			}
			else
			{
				for(int i = 0; i < w; i++)
				{
					cin >> field[j][2*i];
				}
			}

		}

/*
//field表示用

		for( int j = 0; j < 2*h-1; j++)
		{
			for( int i = 0; i < 2*w-1; i++)
			{
				cout << field[j][i];
			}
			
			cout << endl;
		}
*/

		solve();

		if( dp[2*h-2][2*w-2] == INT_MAX )
			cout << '0' << endl;
		else
			cout << dp[2*h-2][2*w-2] << endl;
	}

	return 0;
}

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

typedef int64_t i64;

constexpr i64 llinf=4611686018427387903LL;

template <class T_>
class wdjset{
public:
    i64 n;
    i64 *par;
    i64 gr;
    T_ *w;
    void make(i64 N){
        n=gr=N;
        par=new i64[n]{};
        w=new T_[n]{};
        for(i64 i=0;i<n;i++) par[i]=1;
    }
    inline i64 find(i64 X){
        if(par[X]>0) return X;
        else{
            i64 r=find(-par[X]);
            w[X]+=w[-par[X]];
            return -(par[X]=-r);
        }
    }
    i64 unite(i64 X,i64 Y,T_ W){
        i64 px=find(X),py=find(Y);
        if(px==py) return 0;
        W+=w[X];
        W-=w[Y];
        if(par[px]<par[py]){
            i64 t=px;
            px=py;
            py=t;
            W=-W;
        }
        par[px]+=par[py];
        par[py]=-px;
        w[py]=W;
        gr--;
        return 1;
    }
    i64 same(i64 X,i64 Y){
        return (find(X)==find(Y));
    }
    T_ diff(i64 X,i64 Y){
        if(!same(X,Y)) return (T_)llinf;
        return w[Y]-w[X];
    }
    i64 size(i64 x){
        return par[find(x)];
    }
    void refr(void){
        delete[] par;
    }
};

int main(void){
    i64 n,q;
    scanf("%lli%lli",&n,&q);
    wdjset<i64> s;
    s.make(n);
    for(i64 i=0;i<q;i++){
        i64 t;
        scanf("%lli",&t);
        if(t==0){
            i64 x,y,z;
            scanf("%lli%lli%lli",&x,&y,&z);
            s.unite(x,y,z);
        }
        else{
            i64 x,y;
            scanf("%lli%lli",&x,&y);
            i64 d=s.diff(x,y);
            if(d==llinf) printf("?\n");
            else printf("%lli\n",d);
        }
    }
    return 0;
}



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

using namespace std;
const int N=105;
int A[N],n,x,y,z,mx,mn;
long long sum=0;
int main(){
    scanf("%d",&n);
    n--;
    for(int i=0;i<n;++i){
        scanf("%d",A+i);
    }
    sum+=A[0];
    for(int i=1;i<n;++i){
        sum+=min(A[i-1],A[i]);
    }
    sum+=A[n-1];
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 256
n, k = map(int,input().split())

p = list(map(int,input().split()))

a = 0

for i in range(k):
    a += p[i]

ans = a

for i in range(n-k):
    a -= p[i]
    a += p[i+k]
    if a > ans:
        ans = a

ans = (ans+k)/2

print(ans)


Measured memory_bytes: 25060
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cassert>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n, a, b; cin >> n >> a >> b;
  vector<int> p(n);
  rep(i, n) {
    int pos; cin >> pos;
    pos--;
    p[pos] = i;
  }

  int k = 2*n+1;
  vector<ll> dp(k);

  rep(i, n) {
    int now = p[i]*2+1;
    //debug(i); debugln(now);
    ll mi = LLONG_MAX;
    rep(j, k) {
      chmin(mi, dp[j]);
      if (now < j) {
        dp[j] = mi+a;
      } else if (now > j) {
        dp[j] = mi+b;
      } else {
        dp[j] = mi;
      }
      //debug(i); debug(j); debugln(dp[j]);
    }
  }

  ll ans = LLONG_MAX;
  rep(i, k) {
    chmin(ans, dp[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int k ,t;
  cin >> k >> t;
  vector<pair<int,int>>vec;
  rep(i,t){
    int a; cin>>a;
    vec.push_back(make_pair(a,i+1));
  }
  sort(vec.begin(),vec.end(),greater<pair<int,int>>());
  
  int M=vec[0].first;
  int sum=0;
  rep(i,t-1){
    sum+=vec[i+1].first;
  }
  cout<<max(M-1-sum,0)<<endl;
  
}


Measured memory_bytes: 256
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

l.sort(key=lambda x:x[1])

t = 0

for i in range(n):
    t += l[i][0]
    if t > l[i][1]:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 53728
a = int(input())
x = []
for i in range(a):
    x.append(input())
print("AC x " + str(x.count("AC")))
print("WA x " + str(x.count("WA")))
print("TLE x " + str(x.count("TLE")))
print("RE x " + str(x.count("RE")))

Measured memory_bytes: 16288
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    string S;
    int K;
    cin >> S >> K;

    map<char, int> CtoI;
    char moji = 'b';
    CtoI['a'] = 0;
    for(int i = 25; moji <= 'z'; moji++, i--)   CtoI[moji] = i;
    

    int size = S.size();
    for(int i = 0; i < size; i++){
        if(i == size-1) S[i] = 'a' + (S[i] - 'a' + K)%26;
        else{
            if(CtoI[S[i]] <= K){
                K -= CtoI[S[i]];
                S[i] = 'a';
            }
        }
    }

    cout << S << "\n";
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int N;
  ci(N);
  ve<int> d(N);
  rep(i, N){
    ci(d.at(i));
  }
  sort all(d);
  int c = 0;
  rep(i, N - 1){
    if(d.at(i) < d.at(i + 1)){
      c++;
    }
  }
  co(c + 1);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
int main() {
	double w, h, x, y;

	cin >> w >> h >> x >> y;

	double area = (double)((w * h) / 2);

	cout << fixed << setprecision(12) << area << " ";

	if (x * 2 == w && y * 2 == h) {
		cout << 1;
	}
	else {
		cout << 0;
	}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

int main(){
	double x,h;
	while(~scanf("%lf",&x)){
		scanf("%lf",&h);

		if(x==h && x==0) break;

		double a = x / 2.0;
		double b = sqrt(a*a + h*h);

		printf("%0.7f\n",x*b*2.0+x*x);
	}
}

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

int main(){
  int N;
  cin >> N;
  string ans = "";
  while(N != 0){
	if(N % 2 != 0){
      N--;
      ans = "1" + ans;
    }
    else {
      ans = "0" + ans;
    }
    N /= -2;
  }
  
  if(ans == ""){
    ans = "0";
  }
  cout <<ans << endl;
}

Measured memory_bytes: 256
while True:
    n,x = list(map(int, input().split()))
    if n == x == 0:
        break

    num_set = []
    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                if i < j < k and i+j+k ==x:
                    li = [i,j,k]
                    if not li in num_set:
                        num_set.append(li)
    print(len(num_set))

Measured memory_bytes: 7684
#include<vector>
#include<queue>
#include<functional>
#include<algorithm>
#include<set>
#include<iostream>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> t3;

const int MX = 2005;
const int MM = 1000000007;

int main()
{
	int N, a, b = 0;
	ll ans = 0;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		scanf("%d", &a);
		ans += (a+b)/2;
		if( a ) b = (a+b) % 2;
		else b = 0;
	}
	printf("%lld\n", ans);
}


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

using namespace std;


int main() {
	string str;
	cin >> str;

	int length;
	ostringstream strlen;
	length = str.size() - 2;
	strlen << length;

	str.replace(1, length, strlen.str());
	cout << str << endl;

	return 0;
}

Measured memory_bytes: 256
k=int(input())
s=str(input())
long =len(s)
i =0
ans = str()
if k>long:
    print(s)
else:
    for i in range(long):
        if i<k:
           ans = str(ans+s[i])
        else:
           ans = str(ans+"...")
           break
print(ans)

Measured memory_bytes: 9172
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



int main() {
    unsigned int a, b;
    cin >> a >> b;
    cout << ((b % a)? b - a : a + b) << endl;
}

Measured memory_bytes: 384
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ini_1 = []
end_n = []
for i in range(m):
    if ab[i][0] == 1:
        ini_1.append(ab[i][1])
    elif ab[i][1] == n:
        end_n.append(ab[i][0])
if set(ini_1) & set(end_n):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 54528
n,m = (int(i) for i in input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
difx,dify,num,num2,mod = [],[],0,0,10**9+7
for i in range(1,n): difx.append(x[i]-x[i-1])
for i in range(1,m): dify.append(y[i]-y[i-1])
for i in range(n-1): num = (num+(i+1)*(n-i-1)*difx[i])%mod
for i in range(m-1): num2 = (num2+(i+1)*(m-i-1)*dify[i])%mod
print(num*num2%mod)

Measured memory_bytes: 19580
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=9;i++)
	{
		if(n%i==0&&n/i>=1&&n/i<=9)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		while(true){
			int h = stdIn.nextInt();
			int w = stdIn.nextInt();
			if(h==0&&w==0){
				return;
			}
			char[][] map = new char[h][w];
			boolean[][] visited = new boolean[h][w];
			for(int i=0;i<h;i++){
				map[i] = stdIn.next().toCharArray();
			}			
			int x = 0, y = 0;
			while(true){
				if(visited[x][y]){
					System.out.println("LOOP");
					break;
				}
				visited[x][y] = true;
				if(map[x][y]=='>'){
					y++;
				}
				else if(map[x][y]=='<'){
					y--;
				}
				else if(map[x][y]=='v'){
					x++;
				}
				else if(map[x][y]=='^'){
					x--;
				}
				else if(map[x][y]=='.'){
					System.out.println(y+" "+x);
					break;
				}
			}
		}
	}
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    string s;
    cin >> s;

    int ans = 0;
    for(int in=0;in<s.size();in++) {
        if(s.at(in)=='+') ans++;
        else ans--;
    }

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


Measured memory_bytes: 256