akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main(){

    int N, Q;
    scanf("%d %d", &N, &Q);

    int i, j, cnt=0, flag, l, r, acnum[N], accnt[N];
    int *ans = (int*)calloc(Q+1, sizeof(int));
    char S[N+1];

    scanf("%s", S);

    for (i=0; i<N; i++){
        if (S[i] == 'A'){
            flag = 1;
        }
        if (S[i] == 'C' && flag == 1){
            acnum[cnt] = i-1;
            cnt++;
        }
        if (S[i] != 'A'){
            flag = 0;
        }
    }

    cnt = 0;
    for (i=0; i<N; i++){
        accnt[i] = cnt;
        if (i == acnum[cnt]){
            cnt++;
        }
    }

    for(i=0; i<Q; i++){
        scanf("%d %d", &l, &r);
        printf("%d\n",accnt[r-1]-accnt[l-1]);
    }

    return 0;
}

Measured memory_bytes: 1408
lines = $stdin.read
array = lines.split("\n")
N = array[0].to_i
S = array[1].split("")
ans = 0

(0..999).each do |n|
  nnn = sprintf "%03d\n", n
  idx1 = S.index(nnn[0])
  idx2 = S[idx1+1, S.length].index(nnn[1]) unless idx1.nil?
  idx3 = S[idx1+idx2+2, S.length].index(nnn[2]) unless idx2.nil?

  if not idx1.nil? and not idx2.nil? and not idx3.nil?
    #p nnn
    ans += 1
  end
end

puts ans

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

std::vector<int> MPAlgorithm(const std::string& str)
{
	std::vector<int> ret(str.size() + 1);
	ret[0] = -1;
	for (int i{}; i < (int)str.size(); i++)
	{
		int prev{ret[i]};
		while (prev >= 0 && str[prev] != str[i]) prev = ret[prev];
		ret[i + 1] = prev + 1;
	}
	return std::move(ret);
}

int main()
{
	int H, W;
	scanf("%d%d", &H, &W);
	std::vector<std::string> field(H);
	for (auto& e: field) std::cin >> e;
	int R, C;
	scanf("%d%d", &R, &C);
	std::vector<std::string> pattern(R);
	for (auto& e: pattern) std::cin >> e;
	using vi = std::vector<int>;
	using vvi = std::vector<vi>;
	vvi mp(R);
	for (int i{}; i < R; i++)
		mp[i] = MPAlgorithm(pattern[i]);
	for (int row{}; row + R <= H; row++)
	{
		std::bitset<1000> bs{};
		for (int i{}; i + C <= W; i++)
			bs[i] = true;
		for (int p_r{}; p_r < R; p_r++)
		{
			for (int i{}, length{}; i < W; i++)
			{
				while (length >= 0 && field[row + p_r][i] != pattern[p_r][length]) length = mp[p_r][length];
				length++;
				if (length < C)
				{
					if (i - C + 1 >= 0)
						bs[i - C + 1] = false;
					continue;
				}
				length = mp[p_r][length];
			}
		}
		for (int col{}; col < W; col++)
			if (bs[col])
				printf("%d %d\n", row, col);
	}

	return 0;
}


Measured memory_bytes: 8916
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

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

int64_t get_int(void) {
  int64_t num;
  scanf("%lld", &num);
  return num;
}

#define NUM_2_MAX 1000000

int main(void) {
    int64_t num = get_int();
    static char primen[NUM_2_MAX+1];
    memset(primen, 0x01, NUM_2_MAX+1);

    int i, j;
    for(i = 2; i <= NUM_2_MAX; i++) {
        if(!primen[i]) break;
        int ulimit = NUM_2_MAX/i;
        for(j = 2; j <= ulimit; j++) {
            primen[i*j] = 0;
        }
    }
    for(i = 2; i <= 1000; i++) {
        int n = i;
        if(!primen[n]) break;
        while(n<=NUM_2_MAX) {
            primen[n] = 1;
            n *= i;
        }
    }

    int ans = 0;
    int divisor = 2;
    while(num >= divisor) {
        // num is prime
        if(divisor > NUM_2_MAX) {
            ans++;
            break;
        }
        if(!primen[divisor]) { divisor++; continue; }
        if(num%divisor) { divisor++; continue; }
        num /= divisor;
        divisor++;
        ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2708
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin>>H>>W;
  int ja=0;
  int ja2=0;
  vector<vector<char>> data(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>data.at(i).at(j);
    }
  }
  vector<int> row(H, 0);
  vector<int> col(W, 0);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (data.at(i).at(j)=='#') {
        row.at(i) = 1;
        col.at(j) = 1;
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
	  if (row.at(i)==1) {
      for (int j = 0; j < W; j++) {
        if (col.at(j)==1) {
          cout << data.at(i).at(j);
        }
      }
      cout << endl;
    }
  }  
}


Measured memory_bytes: 3656
H, W, K=map(int,input().split())
F = [input() for _ in range(H)]
ans = 0 
for i in range(2**H):
  for j in range(2**W):
    cnt = 0
    for ii in range(H):
      for jj in range(W):
        if (i>>ii)%2==0 or (j>>jj)%2==0 or F[ii][jj]==".":
          continue
        cnt+=1
    if cnt==K:
      ans+=1
print(ans)

Measured memory_bytes: 9080
#include<stdio.h>

int main()
{
	int input;
	int stack[100];
	int sp=0;
	int outtrain[110];
	int i;

	for(i=0;i<10;i++){stack[i]=0;}
	for(i=0;i<11;i++){outtrain[i]=0;}
	i=0;
	while(scanf("%d",&input)!=EOF)
	{
		if(input==0)
		{	
			outtrain[i]=stack[sp];
			stack[sp]=0;
			i++;
			if(sp>0){sp--;}
		}
		else
		{
			if(stack[0]!=0){sp++;}
			stack[sp]=input;
		}
	}
	i=0;
	while(outtrain[i]!=0)
	{
		printf("%d\n",outtrain[i]);
		i++;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int dp[200000];

int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < 200000; ++i)
    dp[i] = INF;

  dp[0] = 0;

  for (int i = 0; i <= n; ++i)
  {
    dp[i + 1] = min(dp[i + 1], dp[i] + 1);
    for (int j = 6; j <= 100000; j *= 6)
    {
      dp[i + j] = min(dp[i + j], dp[i] + 1);
    }
    for (int j = 9; j <= 100000; j *= 9)
    {
      dp[i + j] = min(dp[i + j], dp[i] + 1);
    }
  }

  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
 char s[10];
    cin >> s;
    int ans = 0;
    for(int i = 0;i <strlen(s);i++) {
        int k = 0;
        if (s[i] == 'R') {
            for(int j = i;s[j] == 'R';j++) {
                k++;
            }
            if(ans < k) ans = k;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
N = int(input())
n = list(map(int, input().split()))

count = 0
for i in range(1, N - 1):
    if n[i - 1] < n[i] <= n[i + 1] or n[i - 1] >= n[i] > n[i + 1]:
        count += 1

print(count)

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

int a;
int b;
int c;

int main(){
	cin >> a;
	cin >> b;
	cin >> c;
	if ( a<b && b<c ) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 304;

int n, m, k, i, j, l, d, start, is, tab[N][N], bat[N][N], isRow[N], last[N];
char t[N];

int main() {
scanf("%d %d %d", &n, &m, &k);
for (i=0;i<n;i++) {
	scanf("%s", t);
	for (j=0;j<m;j++) if (t[j] == '#') {
		isRow[i] = 1;
		tab[i][j] = 1;
		last[i] = j;
	}
}
is = 0;
d = 0;
for (i=0;i<n;i++) {
	if (!isRow[i]) {
		if (is) for (j=0;j<m;j++) bat[i][j] = bat[i - 1][j];
		continue;
	}
	d++;
	if (!is) {
		start = 0; 
		is = 1;
	} else start = i;
	for (j=0;j<m;j++) {
		for (l=start;l<=i;l++) bat[l][j] = d;
		if (tab[i][j] && j != last[i]) d++;
	}
}
for (i=0;i<n;i++) {
	for (j=0;j<m;j++) printf("%d ", bat[i][j]);
	printf("\n");
}
return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        String ans = "";
        while (true) {
            long c = n % 26;
            if (c == 0) {
                c = 26;
            }
            ans = String.valueOf((char)(0x60 + c)) + ans;
            if (n <= 26) {
                break;
            }
            n--;
            n /= 26;
        }
        System.out.println(ans);
    }
}


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

int main(){
    int N, C, D[35][35], c[510][510];
    cin >> N >> C;
    rep1(i,C) rep1(j,C) cin >> D[i][j];
    rep1(i,N) rep1(j,N) cin >> c[i][j];

    map<int,int> colors0, colors1, colors2;
    rep1(i,N) rep1(j,N){
        if((i+j)%3 == 0) colors0[c[i][j]]++;
        if((i+j)%3 == 1) colors1[c[i][j]]++;
        if((i+j)%3 == 2) colors2[c[i][j]]++;
    }

    Int ans = 1e16;
    rep1(c1,C)rep1(c2, C) rep1(c3,C){
        if(c1 == c2 || c2 == c3 || c3 == c1) continue;

        Int cur = 0;
        for(pair<int,int> x: colors0)
            cur += x.second * D[x.first][c1];
        
        for(pair<int,int> x: colors1)
            cur += x.second * D[x.first][c2];
        
        for(pair<int,int> x: colors2)
            cur += x.second * D[x.first][c3];

        ans = min(ans, cur);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1280
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
// input macro
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        a: [i32; 3],
        l: [i32; n],
    }
    let sum = (0..1 << n)
        .map(|bit| {
            (0..n)
                .map(|i| if bit >> i & 1 != 0 { l[i] } else { 0 })
                .sum::<i32>()
        })
        .collect::<Vec<_>>();
    let mut ans: i32 = 1e9 as i32;
    for bit1 in 1..(1 << n) {
        for bit2 in 1..(1 << n) {
            if bit1 & bit2 != 0 {
                continue;
            }
            for bit3 in 1..(1 << n) {
                if bit1 & bit3 != 0 || bit2 & bit3 != 0 {
                    continue;
                }
                let mut s = 0;
                for i in 0..n {
                    if bit1 >> i & 1 != 0 || bit2 >> i & 1 != 0 || bit3 >> i & 1 != 0 {
                        s += 1;
                    }
                }
                s = (s - 3) * 10;
                let sub =
                    (a[0] - sum[bit1]).abs() + (a[1] - sum[bit2]).abs() + (a[2] - sum[bit3]).abs();
                ans = min(ans, sub + (s as i32));
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<cstring>
#include<map>
#include<sstream>
 
using namespace std;

int N;
int ans[4] = {0,0,0,0};

int main(){
  
  cin>>N;
  
  string S[N];
  
  for(int i = 0; i < N;i++) cin>>S[i];
  
  for(int i = 0; i < N; i++){
    if("AC" == S[i]){
      ans[0]++;
    } else if("WA" == S[i]){
      ans[1]++;
    } else if("TLE" == S[i]){
      ans[2]++;
    } else { 
      ans[3]++;
    }
  }
  
  cout<<"AC x "<<ans[0]<<endl;
  cout<<"WA x "<<ans[1]<<endl;
  cout<<"TLE x "<<ans[2]<<endl;
  cout<<"RE x "<<ans[3]<<endl;
}


Measured memory_bytes: 6720
N =int(input())

edge = [[] for i in range(N)]
adj = [[] for i in range(N)]

for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append((b, i))
    adj[b].append((a, i))

K = 0
for i in range(N):
    K = max(K, len(adj[i]))
print(K)

from collections import deque
color = [-1] * (N - 1)
qu = deque([0])
done = [False] * N
done[0] = True
vc = [-1] * N
while(len(qu) > 0):
    v = qu.popleft()
    for nv, e in adj[v]:
        if not done[nv]:
            vc[v] = (vc[v] + 1) % K
            color[e] = vc[v]
            qu.append(nv)
            vc[nv] = vc[v]
            done[nv] = True

for i in range(N - 1):
    print(color[i] + 1)

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll h; cin >> h;

    ll t = 1;

    ll ans = 0;

    while (t <= h) {
        ans += t;
        t *= 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
typedef tuple<double,ll,ll>T;
#define PI 3.14159265358979
#define MOD (ll)1000000007
ll gcd(ll x, ll y)
{
   if (x%y == 0)
   {
       return(y);
   }
   else
   {
       return(gcd(y, x%y));
   }
}

ll lcm(ll x, ll y)
{
   return x / gcd(x, y) * y;
}

ll mod_pow(ll x, ll n, const ll p) {
  ll ret = 1ll;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

int main(){
  ll N;
  cin>>N;
  map<P,P> score;
  ll ABo=0ll;
  ll Ao=0ll;
  ll Bo=0ll;
  ll ans=0ll;
  rep(i,N){
  	ll a,b;
    int flag=0;
  	cin>>a>>b;
    if(a==0&&b==0){ABo++;continue;}
    if(a==0){Ao++;continue;}
    if(b==0){Bo++;continue;}
    if(a>0ll&&b<0ll){flag=1;}
    if(a<0ll&&b>0ll){flag=1;}
    if(a<0ll){a=-a;}if(b<0ll){b=-b;}
    ll g=gcd(a,b);
    a/=g;
    b/=g;
    
    if(flag==0){
      score[P(a,b)].second++;
    }
    if(flag==1){
      score[P(b,a)].first++;
    }
  }
  ans=1ll;
  ans=mod_pow(2ll,Ao,(ll)1000000007)+mod_pow(2ll,Bo,(ll)1000000007)-1ll;
  ans%=MOD;
  for(auto k:score){
    auto p=k.second.first;
    auto q=k.second.second;
    p=mod_pow(2ll,p,(ll)1000000007);
    q=mod_pow(2ll,q,(ll)1000000007);
    ans=ans*((p+q-1ll)%MOD);
    ans%=MOD;
  }
  ans+=ABo;
  ans--;
  ans+=MOD;
  ans%=MOD;
  cout<<ans;
}

Measured memory_bytes: 19220
s = input()

conList = []
for i in range(16):
    flag = str(bin(i))[2:].zfill(4)
    a = ''
    if( flag[0] == '1'):
        a = a+'A'
    a = a+'KIH'
    if( flag[1] == '1'):
        a = a+'A'   
    a = a+'B'
    if( flag[2] == '1'):
        a = a+'A'  
    a = a+'R'
    if( flag[3] == '1'):
        a = a+'A' 
    conList.append(a) 
if( s in conList):
    print('YES')
else:
    print('NO')

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int n, m; cin >> n >> m;
  vl s(n), t(m); ina(s,n); ina(t,m);
  vvl dp(n+1, vl(m+1,0));
  rep(i,n+1) dp[i][0] = 1;
  rep(j,m+1) dp[0][j] = 1;
  REP(i,1,n+1) {
    REP(j,1,m+1) {
      dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1];
      if (s[i-1] == t[j-1]) {
        dp[i][j] += dp[i-1][j-1];
      }
      dp[i][j] = (dp[i][j] + MOD) % MOD;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}


Measured memory_bytes: 31616
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
    int m;  //?????£??????????????°
    int h;  //?????£?????????????????????
    int len;    //??????
    int i;  //??°??????????????°
    int j;  //??°?????????
    char ch[400];   //??????????????????
    char tmp1[400]; //???????????????
    char tmp2[400]; //???????????????
    char *pch;
    char *ptmp1;
    char *ptmp2;
    
    for(i = 0; i < 400; i++)
    {
        ch[i] = 0;
        tmp1[i] = 0;
        tmp2[i] = 0;
    }
    
    
    while(1)
    {
        scanf("%s", ch);
        len = strlen(ch);
        if(strstr(ch, "-"))
        {
            break;
        }
        
        scanf("%d", &m);
        pch = ch;
        ptmp1 = tmp1;
        ptmp2 = tmp2;
        for(i = 0; i < m; i++)
        {
            scanf("%d", &h);
            strncpy(ptmp1, pch, h);
            strncpy(ptmp2, (pch + h), len - h);
            
            //printf("tmp1 %s\n", tmp1);
            //printf("tmp2 %s\n", tmp2);
            
            strcpy(ch, strcat(tmp2, tmp1));
            //printf("ch %s\n", ch);
            
            for(j = 0; j < 400; j++)
            {
                tmp1[j] = 0;
                tmp2[j] = 0;
            }
        }
        printf("%s\n", ch);
    }
    return 0;
}

Measured memory_bytes: 604
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	vector<int>a;
	vector<int>b;
	int x,y;
	char c;
	while( cin>>x>>c>>y){
		a.push_back(x);
		b.push_back(y);
	}
	int sum=0,cnt=0;
	for(int i=0;i<a.size();i++){
		sum+=a[i]*b[i];
		cnt+=b[i];
	}
	printf("%d\n%d\n",sum,(int)(cnt/(double)a.size()+0.5));
	return 0;
}

Measured memory_bytes: 1192
from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)  

Measured memory_bytes: 141572
#include<stdio.h>
#include<string.h>
int main(){
    char s[2000];
    int n, i, j, key = 0;
    scanf("%d ", &n);
    while( n-- ) {
        fgets(s, sizeof(s), stdin);
        for ( i = 0; i < strlen(s); i++ ) {
            if ( s[i] == 'H' ) {
                if ( s[i+1] == 'o' && s[i+2] == 's' && s[i+3] == 'h' && s[i+4] == 'i' && s[i+5] == 'n' && s[i+6] == 'o') {
                    s[i+6] = 'a';
                }
            }
        }
        printf("%s", s);
        key++;
    }    
    return 0;
}

Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    ll sum = 0;
    rep(i,n){
        cin>>a[i];
        sum += a[i];
    }
    ll lsum = 0;
    ll ans = 1LL<<60;
    for(int i=0; i<n-1; i++){
        lsum += a[i];
        ll rsum = sum - lsum;
        ans = min(ans, abs(lsum-rsum));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

vector<ll> graph[300010];
ll dist[300010];
ll vertice,edge,thrice;
ll source,destination;
#define N 100000
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    memset(dist,-1,sizeof(dist));
    cin>>vertice>>edge;
    ll vert1,vert2;
    while(edge--)
    {
        cin>>vert1>>vert2;
        graph[vert1].push_back(vert2+N);
        graph[vert1+N].push_back(vert2+N+N);
        graph[vert1+N+N].push_back(vert2);
    }
    cin>>source>>destination;
    queue<ll> q1;
    q1.push(source);
    dist[source]=0LL;
    ll front,size,store;
    while(!q1.empty())
    {
        front=q1.front();
        q1.pop();
        size=graph[front].size();
        for(ll i=0;i<size;i++)
        {
            store=graph[front][i];
            if(dist[store]==-1)
            {
                q1.push(store);
                dist[store]=dist[front]+1;
            }
        }
    }
    if(dist[destination]!=-1)
    {
        dist[destination]/=3;
    }
    cout<<dist[destination];
    return 0;
}

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

using namespace std;

int main() {
    unsigned int n, k;
    cin >> n >> k;

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

    sort(vt.begin(), vt.end(), greater<>());
    cout << accumulate(vt.begin(), vt.begin() + k, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
   int r,g,b; cin >> r >> g >> b;
   int num = 100*r + 10*g + b;
   if(num % 4 == 0) cout << "YES" << endl;
   else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define max 41
int n,in[max],pre[max],t[max];
int j,k;
void noderest(int l,int r){
  if(l>=r)return;
  int i =pre[j++];
  //cout<<"in:"<<in[i]<<endl;
  noderest(l,in[i]);
  noderest(in[i]+1,r);
  t[k++]=i;
}
int main(){
  int i,root;
  cin>>n;
  for(i=0;i<n;i++)cin>>pre[i];
  for(i=0;i<n;i++){
    cin>>root;
    in[root]=i;
  }
  root=in[i];
  noderest(0,n);
  for(i=0;i<k-1;i++){
    cout<<t[i]<<" ";
  }
  cout<<t[i]<<endl;
  return 0;
}



Measured memory_bytes: 3128
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

struct Node {
  int number;
  int parent = -1;
  int depth;
  string type;
  std::vector<int> children;
};

std::vector<Node> nodes;

void check_parent() {
  for (Node node : nodes) {
    for (int child : node.children) {
      nodes[child].parent = node.number;
    }
  }
}

void check_depth() {
  for (Node node : nodes) {
    int parent = node.parent;
    int depth = 0;
    while (parent != -1) {
      parent = nodes[parent].parent;
      depth++;
    }
    nodes[node.number].depth = depth;
  }
}

void check_type() {
  for (Node node : nodes) {
    if (node.parent == -1) {
      nodes[node.number].type = "root";
    } else if (node.children.empty()) {
      nodes[node.number].type = "leaf";
    } else {
      nodes[node.number].type = "internal node";
    }
  }
}

void sort_node() {
  sort(nodes.begin(), nodes.end(),
       [](const Node &x, const Node &y) { return x.number < y.number; });
}

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

  rep(i, n) {
    Node node;
    cin >> node.number;

    int d;
    cin >> d;
    rep(j, d) {
      int child;
      cin >> child;
      node.children.push_back(child);
    }
    nodes.push_back(node);
  }

  // process
  sort_node();
  check_parent();
  check_depth();
  check_type();

  // output
  for (Node node : nodes) {
    std::cout << "node " << node.number << ": parent = " << node.parent
              << ", depth = " << node.depth << ", " << node.type << ", ";
    std::cout << "[";
    for (int i = 0; i < node.children.size(); i++) {
      if (i)
        std::cout << ", ";
      std::cout << node.children[i];
    }
    std::cout << "]" << '\n';
  }

  return 0;
}



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

int main(){
  int K;
  cin >> K;
  vector<int> A(32);
  A={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << A.at(K-1) << endl;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Scanner;

/**
 * Aizu 0033
 */
public class Main {
	private Scanner in = new Scanner(System.in);
	private int numOfBall = 10;
	
	private Main() {
		int n = in.nextInt();
		
		for(int i=0; i<n; i++) {
			ArrayDeque<Integer> dataset = new ArrayDeque<Integer>();	
			int[] tmpData = new int[numOfBall];
			for(int j=0;j<numOfBall;j++) {
				tmpData[j] = in.nextInt();
			}
			for(int j=numOfBall-1;j>0;j--) {
				dataset.push(tmpData[j]);
			}
			int[] cylinders = new int[2]; //筒(の最後の要素)
			System.out.println(solve(dataset, cylinders));
		}
		
	}
	
	private String solve(ArrayDeque<Integer> dataset, int[] cylinders) {
		if(dataset.isEmpty())
			return "YES";
		
		int head = dataset.pop();
		if(head > cylinders[0]) {
			cylinders[0] = head;
		} else if(head > cylinders[1]) {
			cylinders[1] = head;
		} else {
			return "NO";
		}
		return solve(dataset, cylinders);
	}

	public static void main(String[] args) {
		new Main();
	}

}

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

int main ()
{
    int n, d, x, a;
    cin >> n >> d >> x;
    int ans = x;
    for (int i = 0; i < n; ++i)
    {
        cin >> a;
        if (d % a == 0)
        {
            ans += d / a;
        }
        else
        {
            ans += d / a + 1;
        }
    }
    cout << ans;
}

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

int BinarySearch(int x,int S[],int N);

int main(){
  int a[100000];
  int b[50000];
  int count=0;
  int a_n=0,b_n=0;
  cin >> a_n;
  for(int i=0;i<a_n;i++){
    cin>>a[i];
  }
  cin >> b_n;
  for(int i=0;i<b_n;i++){
    cin>>b[i];
  }
  for(int i=0;i<b_n;i++){
    if(BinarySearch(b[i],a,a_n)!=-1){
      count++;
    }
  }
  cout << count << endl;
}

int BinarySearch(int x,int S[],int N){
  int B=0;
  int T=N-1;
  while(B<=T){
    int mid=(B+T)/2;
    if(S[mid]==x)
      return mid;
    else if(S[mid]<x)
      B=mid+1;
    else
      T=mid-1;
  }
  return -1;
}



Measured memory_bytes: 3652
///                ..:: In The Name Of God ::..
#include<bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define error(x) cerr << #x << " = " << (x) << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    string s;cin >> s;
    cout << count(all(s),'2') << endl;
    
    
    return 0;
}


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

int N,M;
int A[100001];

int main(){
	scanf("%d%d",&N,&M);
	int sm = 0;
	for(int i = 0; i < M; i++){
		scanf("%d",&A[i]);
		sm += A[i];
	}
	int ans = N >= sm ? N-sm : -1;
	printf("%d\n",ans);


	return 0;
}


Measured memory_bytes: 3836
#include<stdio.h>
#define M 500000
 
int n;
 
int parent(int i){
    return i/2;
}
int left(int i){
    return 2*i;
}
int right(int i){
    return 2*i+1;
}
 
void maxHeapify(int A[], int i){
    int largest;
    int l,r;
    int tmp;
    l = left(i);
    r = right(i);
     
    if(l<=n && A[l] > A[i])largest=l;
    else largest=i;
     
    if(r<=n && A[r]>A[largest])largest=r;
     
    if(largest != i){
        tmp=A[i];
        A[i]=A[largest];
        A[largest]=tmp;
        maxHeapify(A,largest);
    }
     
}
 
void buildMaxHeap(int A[]){
    int i;
    for(i=n/2;i>=1;i--){
        maxHeapify(A, i);
    }
}
 
 
int main(void){
    int i;
 
    int heap[M];
    scanf("%d",&n);
    for(i=1;i<n+1;i++){
        scanf("%d",&heap[i]);
    }
     
    buildMaxHeap(heap);
 
     
    for(i=1;i<n+1;i++){
        printf(" %d",heap[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 2548
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int sum = 0;
    for(int i=1; i<=n; i++) {
      sum += i;
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 32672
#include<iostream>
#include<string>
using namespace std;
void result(int,int);

int numX[3001][3001];
int numY[3001][3001];
int len[3001][3001],maxL=0,maxX=0,count=0;
char Len[3001][3001];

int main(){
	string s,t;

	cin>>s>>t;
	for(int i=1;i<=s.length();i++){
		for(int j=1;j<=t.length();j++){
			len[i][j]=max(len[i-1][j],len[i][j-1]);
			if(s[i-1]==t[j-1]){
				len[i][j]=len[i-1][j-1]+1;
				numX[i][j]=j-1;
				numY[i][j]=i-1;
				Len[i][j]=s[i-1];
			}else{
				len[i][j]=max(len[i][j-1],len[i-1][j]);
				if(len[i][j-1]>=len[i-1][j]){
					numX[i][j]=j-1;
					numY[i][j]=i;
				}else{
					numX[i][j]=j;
					numY[i][j]=i-1;
				}
			}
			if(maxL<=len[i][j])maxX=j;
			maxL=max(maxL,len[i][j]);
		}
	}
	result(maxX,s.length());
	return 0;
}

void result(int x,int y){
	if(numY[y][x]>=1&&numX[y][x]>=1)result(numX[y][x],numY[y][x]);
	if(Len[y][x]!='\0')cout<<Len[y][x];
}

Measured memory_bytes: 114816
S = input()
mod = 10 ** 9 + 7
A, AB, ABC, ALL = 0, 0, 0, 1

for s in S:
    if s == 'A':
        A += ALL
        A %= mod

    if s == 'B':
        AB += A
        AB %= mod

    if s == 'C':
        ABC += AB
        ABC %= mod

    if s == '?':
        ABC = (3 * ABC + AB) % mod
        AB = (3 * AB + A) % mod
        A = (3 * A + ALL) % mod
        ALL *= 3
        ALL %= mod

print(ABC)


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

using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int a[n];
		for(int i=0;i<n;i++)cin>>a[i];
		sort(a,a+n);
		for(int i=2;i<n-1;i++)a[1]+=a[i];
		cout<<a[1]/(n-2)<<endl;
	}	

}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a.at(i).first;
    cin >> a.at(i).second;
  }

  sort(a.begin(), a.end());
  long long ans = 0;
  int num = 0;
  int flag = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < a.at(i).second; j++) {
      ans += a.at(i).first;
      num++;
      if (num == m) {
        flag = 1;
        break;
      }
    }
    if (flag) break;
  }
  cout << ans;
}


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

int main(){
	int A[3];
	int sum=0;
	for(int i=0;i<3;i++){
		cin >> A[i];
		sum += A[i];
	} 
	sort(A,A+3);

	int S=3*A[2]-sum;
	int ans =0;
	if(S%2==0){
		ans =S/2;
	}
	else ans = (S+3)/2;

	cout << ans << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    double r;
    cin >> r;
  cout << fixed << setprecision(10);
    cout << 2 * 3.14 * r << endl;
    return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define ll128 __uint128_t
#define ld long double
#define pll pair <ll, ll>

#define vll vector <ll>
#define vld vector<ld>
#define vpll vector<pll>

#define vvll vector <vll>

#define rep(i, a, b) for(ll i = a; i < b; i++)
#define per(i, a, b) for(ll i = (ll)a - 1; i >= b; --i)

#define endl "\n"
#define pb push_back
#define pf push_front

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define sorta(v) sort(all(v))
#define sortd(v) sort(rall(v))

#define debug if (1)
#define log(val) debug {cout << "\n" << #val << ": " << val << "\n";}

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file(name) freopen(name".in", "r", stdin); freopen(name".out", "w", stdout);
#define FILE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

#define mod (ll)(1e9 + 7)
#define inf (mod * mod)

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

ostream & operator << (ostream & out, vll & a) {
    for(auto i : a) out << i << " ";
    return out;
}

istream & operator >> (istream & in, vll & a) {
    for(auto &i : a) in >> i;
    return in;
}

struct Sq {
    ll cost, len;
    ll x, y;
};

struct pt {
    ll x, y;
};

struct Rect {
    pt a, b;

    Rect(ll x1, ll y1, ll x2, ll y2) {
        a.x = x1;
        a.y = y1;
        b.x = x2;
        b.y = y2;
    }
};

ll intersection(Rect a, Rect b) {
    ll l = max(min(a.a.x, a.b.x), min(b.a.x, b.b.x));
    ll r = min(max(a.a.x, a.b.x), max(b.a.x, b.b.x));

    ll d = max(min(a.a.y, a.b.y), min(b.a.y, b.b.y));
    ll u = min(max(a.a.y, a.b.y), max(b.a.y, b.b.y));

    if (l >= r || d >= u) {
        return 0;
    }

    return 1;
}

int main() {
    ll n;
    cin >> n;
    vll a(n);
    cin >> a;
    ll ans = 0;
    rep(i, 0, n) {
        if (i + 1 < n) {
            if (a[i] >= a[i + 1]) {
                ans += a[i] / 2;
                a[i] %= 2;
            }
            if (a[i + 1] < a[i]) {
                continue;
            }
            a[i + 1] -= a[i];
            ans += a[i];
            a[i] = 0;
        }
        ans += a[i] / 2;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3944
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if X == 500*i + 100*j + 50*k:
                count += 1

print(count)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
    using namespace std;
	
    int main(){
    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
		int k,n;
		cin>>k>>n;
		int arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		int ans=0;
		for(int i=0;i<n-1;i++){
			ans=max(ans,arr[i+1]-arr[i]);
		}
		ans=max(k-arr[n-1]+arr[0],ans);
		cout<<k-ans<<"\n";
		return 0;
    }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A,B,C,D,E;
int dp[NMAX] = {};

string S;
vec v;

bool ans = {};

void solve(){
  // main algorithm
  ans = N % 10 == 9 || N / 10 == 9;
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  if(ans) {
    cout << "Yes\n";
  }
  else {
    cout << "No\n";
  }
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  cin >> N;
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	long long int n,m;
 
	cin >> n >> m;
 
	long long int res = 1;
 
	for(long long int i=1;i<=sqrt(m);i++)
	{
		if(m%i==0)
		{
			if(i>=n)
			{
				res = max(res,m/i);
			}
			if(m/i>=n)
			{
				res = max(res,i);
			}
		}
	}
 
	cout << res << '\n';
 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    long long sum = 0;
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
        sum += A.at(i);
    }
    if(sum % 2 == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N,M,V,P;
  cin>>N>>M>>V>>P;
  vector<ll> v(N);
  for(ll i = 0; i < N; i++) cin>>v[i];
  sort(v.begin(),v.end());
  ll r = N,l=-1;
  while(r-l>1){
    bool ok = false;
    ll mid = (r+l)/2;
    if(v[mid]>=v[N-P]) ok = true;
    else if(mid+P>=V&&v[mid]+M>=v[N-P]) ok=true;
    else{
      ll rest = (V-(P+mid))*M;
      ll n = 0LL;
      for(ll i = mid+1;i<=N-P;i++) n+=(v[mid]+M-v[i]);
      if(n>=rest) ok=true;
    }
    if(v[mid]+M<v[N-P]) ok=false;
    if(ok) r=mid;
    if(!ok) l=mid;
  }
  cout<<N-r<<endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>
#include <sstream>
#include <bitset>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

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

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	while(n > 0) {
		n /= k;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3152
def f(a):
  if a%2 == 0:
    return a//2
  else:
    return 3*a+1

s = int(input())
a = [s]
i=2
 
while(True):
  a.append(f(a[i-2]))
  if a[i-1] in a[:i-1]:
    print(i)
    break
  i=i+1


Measured memory_bytes: 3060
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int c[10];

int main(void){
	         
	          int r,g,b;
	          cin >> r >> g >> b;
	          cout << ((100*r+10*g+b)%4==0 ? "YES":"NO") << endl;

	          return 0;
}


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

if n % 2 == 1:
    for i in range(1, m+1):
        print(i, n-i)
else:
    for i in range(1, m+1):
        if (n - i - i) > (n // 2):
            print(i, n-i)
        else:
            print(i+1, n-i)


Measured memory_bytes: 9220
N = int(input())
C = 0
D = 0
E = 0
F = 0
S = ''

for i in range(N):
    S = input()
    if S == 'AC':
        C += 1
    elif S == 'WA':
        D += 1
    elif S == 'TLE':
        E += 1
    elif S == 'RE':
        F += 1
print('AC x '+ str(C), 'WA x ' + str(D),  'TLE x ' + str(E),  'RE x ' + str(F), sep='\n')


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

int main(){
  int N,D;
  cin >> N >> D;
  
  vector<vector<int>> X(N,vector<int>(D));
  
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin >> X.at(i).at(j);
    }
  }
  
  int d=0;
  int ans=0;
  
  for(int k=0;k<N-1;k++){
    for(int l=k+1;l<N;l++){
      for(int m=0;m<D;m++){
        d +=(X.at(l).at(m)-X.at(k).at(m))*(X.at(l).at(m)-X.at(k).at(m));
      }
      for(int n=1;n<=d;n++){
        if(d==n*n){
          ans++;
        }
      }
      d=0;
    }
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
// const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int n, k;
  cin >> n >> k;
  vt<i64> h(n);
  rep(i, 0, n) cin >> h[i];

  sort(rall(h));
  int i = 0;
  for(; i < n && k > 0; ++i, --k) {
    h[i] = 0;
  }
  i64 ans = 0;
  for(; i < n; ++i) ans += h[i];
  cout << ans << endl;
}

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

using namespace std;
using i64 = std::int_fast64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  i64 N, D, A;
  cin >> N >> D >> A;
  vector<i64> X(N), H(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> H[i];
  }

  vector<int> idx(N);
  for (int i = 0; i < N; i++) {
    idx[i] = i;
  }
  sort(idx.begin(), idx.end(), [&](int a, int b) { return X[a] < X[b]; });
  vector<i64> _X(N), _H(N);
  for (int i = 0; i < N; i++) {
    _X[i] = X[idx[i]], _H[i] = H[idx[i]];
  }
  X = _X, H = _H;

  i64 damage = 0, res = 0;
  queue<pair<i64, i64>> que;
  for (int i = 0; i < N; i++) {
    while (!que.empty() && que.front().first < X[i]) {
      damage -= que.front().second;
      que.pop();
    }

    if (H[i] <= damage) continue;

    int cnt = (H[i] - damage + A - 1) / A;
    damage += cnt * A;
    res += cnt;
    que.push(make_pair(X[i] + 2 * D, A * cnt));
  }

  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 8960