akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define all(n) (n).begin(),(n).end()
#define fi first
#define se second

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

const int MOD = 1e9+7;

int main() {

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

	int n,k;
	cin >> n >> k;
	int a[200000],ans=0;
	for (int i = 0; i < n; i++) cin >> a[i];
	ll lo=0,hi=1e9;
	while(lo<=hi) {
		int mid = (lo+hi)/2;
		int cuts = 0;
		if (mid==0) {
			cout << 1 << "\n";
			return 0;
		}
		for (int i = 0; i < n; i++) {
			cuts+=(a[i]-1)/mid;
			if (cuts>k) break;
		}
		if (cuts<=k) ans=mid,hi=mid-1;
		else lo=mid+1;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  	int output = 700;
	string s;
  	cin >> s;
  	int counter = 0;
  	if(s[0]=='o') ++counter;
  	if(s[1]=='o') ++counter;
  	if(s[2]=='o') ++counter;
  	cout << output + counter*100  << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
 
const long long mod = 1e9 + 7 ;
 
vector <pair<int,int> > g[312345];
long long a[312345];

int n,k;
map<long long, long long> mp;

int main ( ) {

	cin >> n>>k;
	long long ans = 0;
	mp[0]=1;
	for(int i =1 ; i <= n; i++) {
		int x;
		cin >> x;
		x %= k;		
		a[i] = a[i - 1] +x;
		a[i]%=k;
		//cout<<(i-a[i])<<endl;
		if(i>=k)mp[((i-k-a[i-k])%k+k)%k]--;
		ans+=mp[((-a[i]+i)%k+k)%k];
		mp[((-a[i]+i)%k+k)%k]++;
	}	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 22016
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc,char** argv){
  int n,m,X,Y;
  cin >> n >> m >> X >> Y;
  int x[n],y[m];
  for(int i = 0; i < n ;i++){
    cin >> x[i];
  }
  for(int i = 0; i < m ; i++){
    cin >> y[i];
  }
  sort(x,x+n);
  sort(y,y+m);
  int x_ = ( x[n-1] > X ) ? x[n-1] : X;
  int y_ = ( y[0] < Y ) ? y[0] : Y;
  if(x_ < y_){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABlackjack solver = new ABlackjack();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABlackjack {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            out.println(a + b + c >= 22 ? "bust" : "win");
        }

    }

    static class FastReader {
        public BufferedReader br;
        public StringTokenizer st;
        String context = null;

        public FastReader(InputStream in) {
            this(new InputStreamReader(in));
        }

        public FastReader(InputStreamReader input) {
            br = new BufferedReader(input);
        }

        public String next() {
            if (context != null) {
                System.err.print("[" + context + "] Wait for input ...");
            }
            while (st == null || !st.hasMoreElements()) {
                try {
                    String s = br.readLine();
                    if (s == null)
                        return null;
                    st = new StringTokenizer(s);
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new RuntimeException("Could not read");
                }
            }
            String res = st.nextToken();
            if (context != null) {
                System.err.println("[" + context + "] ... received : " + res);
            }
            return res;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 25044
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <complex>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

using namespace std;
typedef long long int ll;

int main() {
	int ans = 0;
	ll n = 0;
	cin >> n;
	vector<ll> a((ll)n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	vector < ll > b((ll)n);
	for (int i = 0; i < n; ++i) cin >> b[i];

	vector<ll> p;
	ll m = 0;
	for (int i = 0; i < n; ++i)
	{
		ll sa = a[i] - b[i];
		if (sa < 0)
		{
			++ans;
			m += sa;
		}
		else
		{
			p.emplace_back(sa);
		}
	}

	sort(p.begin(), p.end());
	reverse(p.begin(), p.end());

	int i = 0;
	while (1)
	{
		if (m < 0)
		{
			m += p[i];
			++ans;
			++i;
			if (i > p.size() && m < 0)
			{
				cout << -1 << endl;
				return 0;
			}
		}
		else
		{
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

string s;
string t = "CODEFESTIVAL2016";

int main() {
	cin >> s;
	
	int ans = 0;
	for (int i = 0; i < s.length(); i++) if (s[i] != t[i]) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  string s;
  cin>>s;
  cout << s[0] << s[1] << s[2] << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int k,s,ans;
int main()
{
    cin>>k>>s;
    for(int x=0;x<=k;x++)
    {
        for(int y=0;y<=k;y++)
        {
            if(s-x-y>=0&&s-x-y<=k) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

int gcd(int a, int b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最小公倍数

int main(){
  int K;
  cin>>K;
  int ans(0);
  for(int a(1);a<=K;a++){
    for(int b(1);b<=K;b++){
      for(int c(1);c<=K;c++){
        ans += gcd(gcd(a,b),c);
      } 
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3624
import Debug.Trace
import Control.Monad
import Data.List
import Control.Applicative

main = do
  [a,b] <- map read . words <$> getLine :: IO [Int]
  putStrLn $ show $ func a b

func :: Int -> Int -> Int
func x y
  |mod y x == 0 = x + y
  |otherwise = y - x

Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include<unordered_map>
#include <set>
#include<unordered_set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <math.h>

#define lli long long int
#define ld long double
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

void pre() {
    return ;
}


void solve()
{
    lli n, k;
    cin>>n>>k;
    lli ans = 0;
    while(n) {
        n /= k;
        ans ++;
    }
    cout<<ans;
    cout<<'\n';
    return ;
}

/*
*/

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

//    pre();

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}
/*
*/


Measured memory_bytes: 256
#include<stdio.h>
int main(){

  char A[10],B[10],C[10];
  int i,j;

  scanf("%s %s %s",A,B,C);

  for(i = 0; A[i] != '\0'; i++);

  for(j = 0; B[j] != '\0'; j++);

  if(A[i-1] == B[0] && B[j-1] == C[0]){
    printf("YES\n");
  }else{
    printf("NO\n");
  }

  return 0;
}

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

using namespace std;

int main() {
	int a, b, total;
	cin >> a >> b;
	
	if (a < 6) total = 0;
	else if (a < 13) total = b / 2;
	else total = b;
	
	cout << total;
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var S1 = ReadString();
            var S2 = ReadString();
            Out(S1 == new string(S2.Reverse().ToArray()) ? "YES" : "NO");
        }

        //最小公倍数
        static int LCM(int num1, int num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        static long LCM(long num1, long num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        //最大公約数
        static int GCD(int num1, int num2)
        {
            int a = Math.Max(num1, num2);
            int b = Math.Min(num1, num2);
            int mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static long GCD(long num1, long num2)
        {
            long a = Math.Max(num1, num2);
            long b = Math.Min(num1, num2);
            long mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static string ReadString()
        {
            return Console.ReadLine();
        }

        static void Out(object o)
        {
            Console.WriteLine(o);
        }
    }

    static class EnumerableExtension
    {
        public delegate void Function<in T>(T val);

        public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
        {
            foreach (var x in enumerable)
            {
                function(x);
            }
        }
    }

    class PriorityQueue<T>
    {
    }

    class UnionFind
    {
        private readonly int[] _array;

        public UnionFind(int N)
        {
            _array = new int[N];
            for (int i = 0; i < N; i++)
            {
                _array[i] = i;
            }
        }

        public int GetRootNode(int n)
        {
            if (_array[n] == n) return n;
            return _array[n] = GetRootNode(_array[n]);
        }

        public void UnionGroup(int a, int b)
        {
            var rootA = GetRootNode(a);
            var rootB = GetRootNode(b);
            if (rootA == rootB) return;
            _array[rootA] = rootB;
        }

        public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);

        public bool IsRoot(int n) => _array[n] == n;
    }
}

Measured memory_bytes: 13268
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (n)-1; i > -1; i--)
#define reps(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define sper(i, s, n) for (int i = (s); i >= (int)(n); i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve()
{
    string s;
    cin >> s;
    bool ok = false;
    rep(i, s.size())
    {
        reps(j, i, s.size())
        {
            string t = s.substr(0, i) + s.substr(j);
            if (t == "keyence")
            {
                ok = true;
            }
            // cout << t << endl;
        }
    }
    if (ok)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3564
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    if a[i]%4==0:
        a[i]=4
    elif a[i]%2==0:
        a[i]=2
    else:
        a[i]=0
from collections import Counter
C = Counter(a)
if C[4]>=C[0]+C[2]%2-1:
    print('Yes')
else:
    print('No')

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

using namespace std;
vector<int> o;
int yy[1001][101];
int main()
{
int w,h;
cin>>w>>h;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
    int x;
    cin>>x;
o.push_back(x);


}
int s=0,p=0;

for(int i=0;i<w;i++)
{
    if(!s)
  for(int j=0;j<h;j++)
    {
        yy[i][j]=p+1;
        o[p]--;
        if(!o[p])
        p++;
    }
    else
    {
         for(int j=h-1;j>=0;j--)
    {
        yy[i][j]=p+1;
        o[p]--;
        if(!o[p])
        p++;
    }

    }


    s=1-s;




}
for(int i=0;i<w;i++){
  for(int j=0;j<h;j++)
cout<<yy[i][j]<<" ";


cout<<"\n";
}









    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	double h,w;cin>>w>>h;
	double x,y;cin>>x>>y;
	int chk=0;
	if(x==w/2&&y==h/2) chk=1;

	cout<<fixed<<setprecision(15)<<h*w/2.0<<" "<<chk<<"\n";
}

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

int main() {
  string S;
  cin >> S;
  
  int Aaru = 0;
  for( int i = 0; i < S.size(); i++ ){
    if( S.at(i) == 'A' ){
      Aaru = i;
      break;
    }
  }
  
  int Zaru = 0;
  for( int i = S.size()-1; i >= 0; i-- ){
    if( S.at(i) == 'Z' ){
      Zaru = i;
      break;
    }
  }
  cout << Zaru - Aaru + 1 << endl;
      
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
using namespace std;
#define INF (1<<27)
int dp[100][100];
int main() {
	int n,k;
	while(scanf("%d %d",&n,&k),n|k) {
		fill((int*)dp,(int*)(dp+100),INF);
		for(int i=0;i<k;i++) {
			int a,b,c;
			scanf("%d",&a);
			if(a==0) {
				scanf("%d %d",&a,&b);
				if(dp[a-1][b-1]>=INF) {
					printf("-1\n");
				}else {
					printf("%d\n",dp[a-1][b-1]);
				}
			}else {
				scanf("%d %d %d",&a,&b,&c);
				if(dp[a-1][b-1]>c) {
					dp[a-1][b-1]=dp[b-1][a-1]=c;
					for(int k=0;k<n;k++) {
						for(int i=0;i<n;i++) {
							for(int j=0;j<n;j++) {
								dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
							}
						}
					}
				}
			}
		}
	}
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


map<int, int> mp;

signed main(){
    int s, m = 1;
    cin >> s;
    mp[s]++;
    while(true){
        m++;
        if(s % 2 == 0){
            s /= 2;
            if(mp[s] > 0) break;
            mp[s]++;
        }else{
            s = 3 * s + 1;
            if(mp[s] > 0) break;
            mp[s]++;
        }
    }
    PRINT(m);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a>=13)
  {cout<<b;}
  else if(a<13&&a>5){
    cout<<b/2;
  }
  else {cout<<0;}
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const ll INF = 10000000000;
const ll MOD = 1000000007;
const ll MAX = 55;


int main() {
    int N,X,Y;
    cin >> N >> X >> Y;
    
    int d = Y-X;
    vector<ll> ans(N, 0);
    for(int a = 1; a < N; a++){
        for(int b = a + 1; b < N+1; b++){
            if( a <= X && Y <= b){
                ans.at(b-a-d+1)++;
            }
            else if( X <= a && b <= Y){
                ans.at( min(b-a, a-b+d+1) )++;
            }
            else if( X <= a && Y <= b){
                ans.at( b-Y + min(Y-a, a-X+1) )++;
            }
            else{
                ans.at( X-a + min(b-X, Y-b+1) )++;
            }
        }
    }
    
    for(int i = 1; i < N; i++){
        printf("%lld\n", ans.at(i));
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>

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

using namespace std;

int main(){
	int h=0;
	char s[100][1001];
	for(int i=0;;i++){
		fgets(s[i],1001,stdin);
		s[i][strlen(s[i])-1]='\0';
		if(strcmp(s[i],"END_OF_TEXT")==0){ h=i; break; }
	}

	int cx=0,cy=0;
	char buf[1001]="";
	while(1){
		char cmd; scanf(" %c",&cmd);
		if(cmd=='-') break;

		if     (cmd=='a') cx=0;
		else if(cmd=='e') cx=strlen(s[cy]);
		else if(cmd=='p') cx=0, cy=max(cy-1,0);
		else if(cmd=='n') cx=0, cy=min(cy+1,h-1);
		else if(cmd=='f'){
			if(s[cy][cx]) cx++;
			else if(cy<h-1) cy++, cx=0;
		}
		else if(cmd=='b'){
			if(cx>0) cx--;
			else if(cy>0) cy--, cx=strlen(s[cy]);
		}
		else if(cmd=='d'){
			if(s[cy][cx]){
				for(int j=cx+1;s[cy][j-1];j++) s[cy][j-1]=s[cy][j];
			}
			else if(cy<h-1){
				strcpy(s[cy]+cx,s[cy+1]);
				for(int i=cy+1;i<h-1;i++) strcpy(s[i],s[i+1]);
				h--;
			}
		}
		else if(cmd=='k'){
			if(!s[cy][cx]){
				if(cy<h-1){
					strcpy(s[cy]+cx,s[cy+1]);
					for(int i=cy+1;i<h-1;i++) strcpy(s[i],s[i+1]);
					h--;
					buf[0]='\n'; buf[1]='\0';
				}
			}
			else{
				strcpy(buf,s[cy]+cx);
				s[cy][cx]='\0';
			}
		}
		else{ // cmd=='y'
			if(buf[0]){
				if(buf[0]=='\n'){
					for(int i=h-1;i>cy;i--) strcpy(s[i+1],s[i]);
					strcpy(s[cy+1],s[cy]+cx);
					s[cy][cx]='\0';
					cy++;
					cx=0;
					h++;
				}
				else{
					int m=strlen(buf);
					for(int j=strlen(s[cy]);j>=cx;j--) s[cy][j+m]=s[cy][j];
					rep(j,m) s[cy][j+cx]=buf[j];
					cx+=m;
				}
			}
		}
	}

	rep(i,h) puts(s[i]);

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <atcoder/dsu>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
//#define inf 2000000000
#define inf 8000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;
using namespace atcoder;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
const int maxn=200005;
//i_am_noob
int n,q,x,u,v;
dsu d(maxn);

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> q;
    while(q--){
        cin >> x >> u >> v;
        if(!x) d.merge(u,v);
        else print1(d.same(u,v));
    }
    return 0;
}


Measured memory_bytes: 3796
#include <iostream>

using namespace std;

void output(int a[],int n){
  for(int i=0;i<n;i++){
    if(i) cout << " " << a[i];
    else cout << a[i];
  }
  cout << endl;
}

int main(){
  int n; cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  output(a,n);
  for(int i=1;i<n;i++){
    int v=a[i];
    int j=i-1;
    while(j>=0 && a[j]>v){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
    output(a,n);
  }
}

Measured memory_bytes: 3016
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

struct cake {
    i64 x, y, z;
};

class abc100d {
private:
    void update(const vector<cake> &v, int M, i64 &res) {
        i64 x = 0, y = 0, z = 0;
        for (int i = 0; i < M; ++i) {
            x += v[i].x; y += v[i].y; z += v[i].z;
        }
        res = max(res, abs(x) + abs(y) + abs(z));
    }
public:
    void solve(istream& in, ostream& out) {
        int N, M;
        in >> N >> M;
        vector<cake> v(N);
        for (int i = 0; i < N; ++i) {
            in >> v[i].x >> v[i].y >> v[i].z;
        }
        i64 res = 0;
        sort(begin(v), end(v), [](const cake &lhs, const cake &rhs) {
            return lhs.x + lhs.y + lhs.z < rhs.x + rhs.y + rhs.z;
        });
        update(v, M, res);
        sort(begin(v), end(v), [](const cake &lhs, const cake &rhs) {
            return lhs.x + lhs.y - lhs.z < rhs.x + rhs.y - rhs.z;
        });
        update(v, M, res);
        sort(begin(v), end(v), [](const cake &lhs, const cake &rhs) {
            return lhs.x - lhs.y + lhs.z < rhs.x - rhs.y + rhs.z;
        });
        update(v, M, res);
        sort(begin(v), end(v), [](const cake &lhs, const cake &rhs) {
            return lhs.x - lhs.y - lhs.z < rhs.x - rhs.y - rhs.z;
        });
        update(v, M, res);
        sort(begin(v), end(v), [](const cake &lhs, const cake &rhs) {
            return -lhs.x + lhs.y + lhs.z < -rhs.x + rhs.y + rhs.z;
        });
        update(v, M, res);
        sort(begin(v), end(v), [](const cake &lhs, const cake &rhs) {
            return -lhs.x + lhs.y - lhs.z < -rhs.x + rhs.y - rhs.z;
        });
        update(v, M, res);
        sort(begin(v), end(v), [](const cake &lhs, const cake &rhs) {
            return -lhs.x - lhs.y + lhs.z < -rhs.x - rhs.y + rhs.z;
        });
        update(v, M, res);
        sort(begin(v), end(v), [](const cake &lhs, const cake &rhs) {
            return -lhs.x - lhs.y - lhs.z < -rhs.x - rhs.y - rhs.z;
        });
        update(v, M, res);
        out << res << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	abc100d solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import sys
import queue
input = sys.stdin.readline

N, Q = map(int, input().split())
tree = [[] for _ in range(N+1)]
value = [0] * (N+1)
visit = [False] * (N+1)

# make_tree
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

# make_value
for _ in range(Q):
    p, x = map(int, input().split())
    value[p] += x

# all_value_sum
q = queue.Queue()
q.put(1)
visit[1] = True
while not q.empty():
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            value[next] += value[now]
            q.put(next)
            visit[next] = True

# output_value
s = " ".join(map(str, value[1:]))
print(s)

Measured memory_bytes: 128728
#include<iostream>
 #include<algorithm>
 using namespace std;
 int main()
{
     int k, n;
     cin >> k >> n;
     int* a = new int[n];
     int* b = new int[n];
     for (int i = 0;i < n;i++)
     {
         cin >> a[i];
     }
     sort(a, a + n);
     for (int i = 0;i < n-1;i++)
     {
         b[i] = a[i + 1] - a[i];
     }
     b[n - 1] = k - a[n - 1] + a[0];
     sort(b, b + n);
     printf("%d", k - b[n - 1]);
      return 0;
     }

Measured memory_bytes: 1920
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=300005;
int n;
struct node
{
	int a,pos;
}a[MAXN];
bool cmp(node a,node b)
{
	return a.a<b.a;
}
int main()
{
	//freopen("sort.in","r",stdin);
	//freopen("sort.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].a);
		a[i].pos=i;
	}
	sort(a+1,a+n+1,cmp);
	int jl=0;
	for(int i=1;i<=n;i++)
		if((a[i].pos&1)!=(i&1))
			jl++;
	printf("%d\n",jl/2);
	fclose(stdin);
	fclose(stdout);
}

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

int main(){
	int n;
	deque<int> ans;

	while(cin>>n){
		for(int i=512;i>0;i/=2){
			if(n-i>=0){
				n-=i;
				ans.push_front(i);
				if(n==0) break;
			}
		}
		for(int i=0;i<ans.size();i++){
			if(i>0) cout<<" ";
			cout<<ans[i];
		}
		cout<<endl;
		ans.clear();
	}

	return 0;
}


			

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
using namespace std;
 
using ll = long long;
 
int main() {
    int N;
    cin >> N;
 
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
 
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += A[i] / 2;
        A[i] %= 2;
        if (i + 1 < N && A[i] > 0 && A[i + 1] > 0) {
            ans++;
            A[i + 1]--;
        }
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int h = s / (60*60);
        s -= h*60*60;
        int m = s/60;
        s -= m*60;
        System.out.printf("%d:%d:%d\n", h, m, s);
        sc.close();
    }
}


Measured memory_bytes: 26308
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
  int N,K;
  cin>>N>>K;
  int cnt[N]={ };
  for(int i=0;i<N;i++){
    int a=i+1;
    while(a<K){
      a*=2;
      cnt[i]++;
    }
  }
  long double sum=0;
  for(int i=0;i<N;i++){
    sum+=pow(0.5L,cnt[i])/N;
  }
  cout<<setprecision(13)<<sum;
  
     
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b,aa[1000],cnt=0;
string s;
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>aa[i];
		if(aa[i]!=i+1){
			cnt++;
		}
	}
	if(cnt<=2){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
}

Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ull, ull> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

bool n, s, e, w;


int main(){

    ios_base::sync_with_stdio(0);

    string str;
    cin>>str;

    for(auto ch : str)
    	if(ch == 'N')	n = true;
    	else if(ch == 'S')	s = true;
    	else if(ch == 'E')	e = true;
    	else	w = true;

    if(s+n==1 || e+w==1)	cout<<"No";
    else	cout<<"Yes";
    return 0;
}






Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};



int main() {
    int N, M;
    cin >> N >> M;
    int G[8][8] = {{0}};
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a][b] = G[b][a] = 1;
    }

    vector<int> p;
    for (int i = 0; i < N; i++) {
        p.push_back(i);
    }

    int ans = 0;
    do {
        if (p[0] != 0) continue;
        bool flag = true;
        for (int i = 0; i < N - 1; i++) {
            if (!G[p[i]][p[i + 1]]) {
                flag = false;
            }
        }
        if (flag) ans++;
    } while(next_permutation(p.begin(), p.end()));
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin>>n;
	int val[n];
	int coin[n];

	for(int i=0;i<n;i++)cin>>val[i];

	for(int i=0;i<n;i++)cin>>coin[i];

	int diff=-1e9;
	
	int value;
	vector<int> result;
	int temp;
	
	for(int i=0;i<n-1;i++)
	{	
		value=val[i];
		diff = val[i]-coin[i];
		for(int j=i+1;j<n;j++)
		{
			temp=diff+val[j]-coin[j];
			diff=max(diff,temp);
		}
		result.push_back(diff);
	}
	result.push_back(0);
	sort(result.begin(),result.end());
	cout<<result[result.size()-1]<<'\n';
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int A=S.at(0)-'0';
  int B=S.at(1)-'0';
  int C=S.at(2)-'0';
  int D=S.at(3)-'0';
  if(A-B-C-D==7){
    cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
  }
  else if(A-B-C+D==7){
    cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
  }
  else if(A-B+C-D==7){
    cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
  }
  else if(A-B+C+D==7){
    cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
  }
  else if(A+B-C-D==7){
    cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
  }
  else if(A+B-C+D==7){
    cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
  }
  else if(A+B+C-D==7){
    cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
  }
  else{
    cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
  }
}
  

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

int main()
{
 long long i,x,f=0,s=0;
  for(i=0;i<3;i++)
  {
    cin>>x;
    
    if(x==5)
      ++f;
    else if(x==7)
      ++s;
  }
  if(f==2&&s==1)
    cout<<"YES\n";
  else
    cout<<"NO\n";
  
  return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

X = list(input())
length = len(X)

cur = 0
cnt = 0
for i in range(length):
    cur = max(cur, i+1)
    x = X[i]
    if x=='S':
        while cur<length:
            v = X[cur]
            if v=='T':
                cnt += 2
                cur += 1
                break
            cur += 1
print(length-cnt)
    

Measured memory_bytes: 82228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int ll

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORED(i, s, n) for (int i = (s); i >= (int)(n); i--)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
// gcd : O(logN)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return
#define srting string

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

#define uniq(v) (v).erase(unique(ALL((v))), (v).end());

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

// 間に何個入っても同じ
// 間の重複を無視して、外から1つずつ取っていけばよい
signed main() {
    make(string, S);

    uniq(S);
    int ans = S.size() - 1;
    cout << ans << endl;
}


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

#define Bye return 0
#define ll long long
const ll MAX = 1e2;

void solve(){
    string a, b, c; cin>>a>>b>>c;
    int size_a = a.size(), size_b = b.size();
    cout<<(a[size_a-1] == b[0] && b[size_b-1] == c[0] ?  "YES" : "NO")<<endl; 
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


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

vector<bool> seen;
vector<ll> mark;
void dfs(const Graph &G, ll v) {

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        seen[v] = true;
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        mark[next_v] = v;
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m),b(m);
    REP(i,m){
        cin >> a[i] >> b[i];
    }
    Graph G(n+1);
    G[0] = {0};
    for (int i = 0; i < m; ++i) {
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }

    ll count = 0;
    seen.assign(n+1, false);
    mark.assign(n+1,0);
    mark[1] = 0;


    vector<int> dist(n+1, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[1] = 0;
    que.push(1); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            mark[nv] = v;
            que.push(nv);
        }
    }


    // for(int v = 1; v < n+1; ++v){
    //     if (seen[v]) continue;
    //     dfs(G, v);
    //     ++count;
    // }
    if(count > -1){
        cout << "Yes" << endl;
        FOR(i, 2, n+1){
            cout << mark[i] << endl;
        }
    } else {
        cout << "No" << endl;
    }


}


Measured memory_bytes: 13960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;

int main() {
    map<int, int> mp;
    int flag = 0;
    int n;
    cin >> n;
    for(int i = 0, x; i < n; i++) {
        cin >> x;
        mp[x]++;
        if(mp[x] > 1) {
            flag = 1;
        }
    }
    cout << (!flag ? "YES": "NO");
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a[100010]={},ans=0;

    cin >> n;
    REP(i,n){
        cin >> a[i+1];
    }

    REPN(i,1,n){
        if(a[a[i]]==i) ans++;
    }

    cout<< ans/2 << endl;

    return 0;
}


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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 100 * 1000 + 17;

int n, a[MAXN], nx, ny, x = 1, y;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1, a + n + 1, greater<int>());
	int ind = 1;
	for (int i = 2; i <= n + 1; i++, nx++, ny++)
		if (a[i] <= nx + 1) {
			ind = i;
			break;
		}
	for (int i = ind; i <= n; i++)
		if (a[i] > nx)
			x++;
	y = a[ind - 1] - ny;
	cerr << "# " << ind << ' ' << x << ' ' << y << endl;
	if (x % 2 && y % 2)
		cout << "Second" << endl;
	else
		cout << "First" << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

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

    int l = 0, r = 50000;
    while (r - l > 1) {
        int m = (l+r)/2;
        if (floor(m * 1.08) <= n) l = m;
        else r = m;
    }

    if (floor(l * 1.08) != n) {
        cout << ":(" << endl;
    } else {
        cout << l << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

difer = [v - c for v, c in zip(V, C)]

ans = 0
for i in range(len(difer)):
    if difer[i] >= 0:
        ans += difer[i]

print(ans)


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

using namespace std;

int main()
{
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    long long n, m;
    cin >> n >> m;
    m /= 2;
    long long l = 0;
    long long r = m + 1;
    while (l < r - 1){
        long long m1 = (l + r) / 2;
        if (2 * m1 <= n + m && m1 <= m){
            l = m1;
        }
        else{
            r = m1;
        }
    }
    cout << l;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>


//深さ優先探索：O(ノード数)で木に纏わる処理をできる
void dfs(int now, int par, std::vector<std::vector<int>>& ki, std::vector<int>& count) {
    for (auto chi : ki[now]) if (chi != par) {
        //繋がったノードを取り出す
        //繋がったノードが親なら無視
        //子なら値を分配
        count[chi] += count[now];
        dfs(chi, now, ki, count);
    }
}

int main() {
    //std::ifstream in("in01.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    int n, q;
    std::cin >> n >> q;
    
    //つながりのあるノードを保存する
    //0が存在しているので、無を指定するには-1などにする
    std::vector<std::vector<int>> ki;
    std::vector<int> count;
    ki.resize(n+1);
    count.resize(n+1);
    
    for (int i = 1; i < n; i++) {
        int a, b;
        std::cin >> a >> b;
        ki[a].push_back(b);
        ki[b].push_back(a);
    }
    
    for (int i = 0; i < q; i++) {
        int p, x;
        std::cin >> p >> x;
        count[p] += x;
    }
    
    dfs(1, -1, ki, count);
    
    for (int i = 1; i <= n; i++) {
        std::cout << count[i] << " ";
    }
    std::cout << std::endl;
    
    return 0;
}


Measured memory_bytes: 29696
#include <iostream>

using namespace std;

int main()
{
    int h,w;
    cin>>h>>w;
    int n;
    int value=1;
    cin>>n;
    int maps[h][w];
    int data[n];
    for (int i=0;i<n;i++){
        cin>>data[i];
    }
    int r=0,c=0;
        for (int j=0;j<n;j++){
            while (data[j]>0){
                if (c==w){
                    r++;
               c=w-1;
               value=-1;
                }
                else if (c==-1){
                    r++;
                    c=0;
                    value=1;
                }
                maps[r][c]=j+1;
                c+=value;
                data[j]--;
            }
        }
        for (int i=0;i<h;i++){
            for (int j=0;j<w;j++){
                cout<<maps[i][j];
                cout <<" ";
            }
            cout <<endl;
        }
    return 0;
}


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

using namespace std;
int a,k,b;
int main(){
cin>>k>>a>>b;
if(b-a+1>=k)
cout<<"OK";
else if(k==1)
cout<<"OK";
else if((b-a+a%k)>=k)
cout<<"OK";
else if(a%k==0)
cout<<"OK";
else
cout<<"NG";
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
  //define llint = long long int; 
  long long int n,m;
  cin>>n>>m;
  long long int a[n];
  long long int b[m],c[m];
  vector<tuple<long long int,long long int>> x;
  for(long long int i=0;i<n;i++){
    cin>>a[i];
    x.push_back(make_tuple(a[i],1));
  }
  for(long long int i=0;i<m;i++){
    cin>>b[i]>>c[i];
    x.push_back(make_tuple(c[i],b[i]));
  }

  sort(x.begin(),x.end());
  vector<tuple<long long int,long long int>> y;
  y.push_back(x[0]);
//  cout<<"x: "<<x.size()<<endl;
  long long int yi = 0;
  for(long long int i=1;i<x.size();i++){
      long long int h0 =(long long int) get<0>(x[i-1]);
      long long int h1 =(long long int) get<0>(x[i]);
      long long int h2 =(long long int) get<1>(y[yi]);
      long long int h3 =(long long int) get<1>(x[i]);
    if(h0==h1){
 //     cout<<i<<endl;
      y[yi] = make_tuple((long long int)h1,(long long int )h2+h3); 
    }else{
      y.push_back(x[i]);
      yi += 1;
    }
  }

  long long int sum = 0;
  long long int piv = 0;
  sort(y.rbegin(),y.rend());
  for(long int i=0;i<y.size();i++){
    long long int h0 =(long long int ) get<0>(y[i]);
    long long int h1 =(long long int) get<1>(y[i]);

    if(piv+h1 > n){
      sum += h0*(n-piv);
//      cout<< h0<<"*"<<(n-piv)<<endl;
      break;
    } else {
      sum += h0*h1;
      piv += h1;
//      cout<< h0<<"*"<<h1<<"+";
    }
  }

  
  //  debug
/*  cout<<"x"<<endl;
  for(int i=0;i<x.size();i++){
    cout<<(long long int )get<0>(x[i])<<","<<get<1>(x[i])<<endl;
  }
  cout<<"__y__"<<endl;
  for(int i=0;i<y.size();i++){
    cout<<get<0>(y[i])<<","<<get<1>(y[i])<<endl;
  }
  cout<<"__"<<endl;
*/  cout<<sum;
}


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

using namespace std;

#define ll long long

//iostream::sync_with_stdio(false);

const int maxn = 1e5 + 5;

int main()
{
    char a;
    cin >> a;
    if(a >= 65 && a <= 90)
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }
	return 0;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define tr(container, it) \
for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++)
#define all(c) c.begin(), c.end()
#define sum(v) accumulate(all(v),0LL)
#define rep(i,s,n) for (int i=s; i<n; i++)
#define lli long long int
#define MOD 1000000007
#define pii pair <int,int> 
#define pll pair <lli, lli>
#define endl '\n'
#define debugv(c) for(auto hnvx : c) cout << hnvx <<" "; cout << endl;
#define debug(c) cout<<#c<<" := "<<c<<endl;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n][3];
    rep(i,0,n) rep(j,0,3)
    {
        cin>>a[i][j];
    }
    int ans[n][3];
    rep(i,0,3) ans[0][i]=a[0][i];
    rep(i,1,n) rep(j,0,3)
    {
        ans[i][j]=0;
        rep(k,0,3) if(j!=k)
        ans[i][j]=max(ans[i][j],a[i][j]+ans[i-1][k]);
    }
    cout<<max(ans[n-1][0],max(ans[n-1][1],ans[n-1][2]));
}


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

#define TIMES(cnt,s,e) for(int cnt=s; cnt<e; ++cnt)


int main(void){
	char s[17];
	char c[] = "CODEFESTIVAL2016";
	int ans=0;

	scanf("%s",s);
	TIMES(i,0,16) {
		ans += s[i]==c[i] ? 0:1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import itertools
n,m = map(int,input().split())
e = [[False]*n for _ in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  e[a-1][b-1] = True
  e[b-1][a-1] = True

ans = 0
l = [i for i in range(1,n)]
for p in itertools.permutations(l):
  p = [0] + list(p)
  reach = 1
  for i in range(n-1):
    if not e[p[i]][p[i+1]]:
      reach = 0
      break
  ans += reach

print(ans)

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

int main(void)
{
    long long int a,b,c,i,j,k,n;

    cin >> a>>b;

    if(a>=13) cout << b;
    else if(a<=12 && a>=6) cout <<  b/2;
    else cout << 0;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int n, i, a, b, c, d;
    a=b=c=d=0;
    scanf("%d", &n);
    char s[10];
    for(i=0; i<n; i++)
    {
        scanf("%s", s);
        if(strcmp(s,"AC")==0) a++;
        if(strcmp(s,"WA")==0) b++;
        if(strcmp(s,"TLE")==0) c++;
        if(strcmp(s,"RE")==0) d++;
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", a, b, c, d);
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    ll a, b; cin >> a >> b;
    ll c = 0;
    if(a % 2 == 0 && b % 2 == 0){
        c = (b - a) / 2;
        if(c % 2 == 0){
            cout << (0 ^ b) << endl;
        }else{
            cout << (1 ^ b) << endl;
        }
    }else if(a % 2 == 0){
        c = (b - a + 1) / 2;
        if(c % 2 == 0){
            cout << 0 << endl;
        }else{
            cout << 1 << endl;
        }
    }else if(b % 2 == 0){
        c = (b - (a + 1)) / 2;
        if(c % 2 == 0){
            cout << (a ^ 0 ^ b) << endl;
        }else{
            cout << (a ^ 1 ^ b) << endl;
        }
    }else{
        c = (b - a) / 2;
        if(c % 2 == 0){
            cout << (a ^ 0) << endl;
        }else{
            cout << (a ^ 1) << endl;
        }
    }
}


Measured memory_bytes: 256
# coding: utf-8
A, B, C, K = map(int, input().split())

if A == B:
    print(0)
    exit()
if abs(A - B) > 10**18:
    print('Unfair')
elif K % 2 == 1:
    print(B - A)
else:
    print(A - B)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

int main()
{
    int H, N;
    std::cin >> H >> N;
    bool result = false;
    for (auto i=0; i<N; ++i)
    {
        int A;
        std::cin >> A;
        H -= A;
        if (H <= 0)
        {
            result = true;
            break;
        }
    }

    if (result)  
        std::cout << "Yes";
    else
        std::cout << "No";
}


Measured memory_bytes: 256