akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAXN=200+10,inf=0x3f3f3f3f;
int G[MAXN][MAXN],R[10],ans=inf,n,m,r;
inline void read(int &x)
{
	int data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=(data<<3)+(data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
inline void init()
{
	for(register int i=1;i<=n;++i)
		for(register int j=1;j<=n;++j)G[i][j]=inf;
}
inline void Floyd()
{
	for(register int k=1;k<=n;++k)
		for(register int i=1;i<=n;++i)
			for(register int j=1;j<=n;++j)G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
}
int main()
{
	read(n);read(m);read(r);
	init();
	for(register int i=1;i<=r;++i)read(R[i]);
	for(register int i=1;i<=m;++i)
	{
		int u,v,k;
		read(u);read(v);read(k);
		G[u][v]=G[v][u]=k;
	}
	Floyd();
	sort(R+1,R+r+1);
	do{
		int res=0;
		for(register int i=1;i<r;++i)res+=G[R[i]][R[i+1]];
		ans=min(ans,res);
	}while(next_permutation(R+1,R+r+1));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>

using namespace std;
int player[100005];

int main(){
  int i, x, np, k, nq;
  cin>>np>>k>>nq;
  for(i = 0;i< nq; i++){
    cin>>x;
    player[x]++;
  }
  for(i = 1;i<= np ;i++){
    if((k+player[i]-nq)>0)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
}

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

string x;
int sum = 0;

int main(){
  while(1){
    cin >> x;
    if(x == "0") break;

    for(int i = 0; i < x.size(); i++){
      sum += x[i] - '0';
    }
    cout << sum << endl;
    sum = 0;
  }
}

Measured memory_bytes: 3180
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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 dyominov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ANewYear solver = new ANewYear();
        solver.solve(1, in, out);
        out.close();
    }

    static class ANewYear {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            out.print(24 - in.nextInt() + 24);
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        public void close() {
        }

    }
}



Measured memory_bytes: 21204
A, B, C, D = list(map(int, input().split()))

if A < C:
    if B - C > 0:
        print(min(B - C, B - A, D - C))
    else:
        print("0")
elif C < A:
    if D - A > 0:
        print(min(D - A, B - A, D - C))
    else:
        print("0")
else:
    print(min(B - A, D - C))


Measured memory_bytes: 3060
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Strings with the Same Length
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

char s[MAX_N + 4], t[MAX_N + 4];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d%s%s", &n, s, t);

  for (int i = 0; i < n; i++)
    putchar(s[i]), putchar(t[i]);
  putchar('\n');
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int p[] = new int[N];
		int val = 0;
		for(int i = 0;i < N;i++) {
			p[i]  = sc.nextInt();
			
		}
		Arrays.sort(p);	
		p[N-1] = p[N-1] / 2;
		for(int i = 0;i < N;i++) {
			val = val + p[i];
		}
		System.out.println(val);
		sc.close();
	}
}

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

void fact(int n,vector<int> &x){
  while (n%2==0){
    n/=2;
    x.at(2)++;
  }
  for (int i=3; i<=sqrt(n); i=i+2){
    while (n%i==0){
      n/=i;
      x.at(i)++;
    }
  }
  if (n>2){
    x.at(n)++;
  }
  return;
}

int main(){
  int N;
  cin>>N;
  int count=0;
  
  for (int i=1; i<=N; i=i+2){
    vector<int> x(N+1,1);
    fact(i,x);
    int total=1;
    for (int j=0; j<N+1; j++){
      total*=x.at(j);
    }
    if (total==8){
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3628
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

n=int(input())
xs=[]
ys=[]
for _ in range(n):
    x,y=map(int,input().split())
    tx,ty=x+y,x-y
    xs.append(tx)
    ys.append(ty)
xs=sorted(xs)
ys=sorted(ys)
ans=max(abs(xs[-1]-xs[0]),abs(ys[-1]-ys[0]))
print(ans)

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

int main() {
    int n;
    cin>>n;
    if((1<=n&&n<=10)||n==12||n==14||n==15||n==16||n==18||n==20||n==21||n==24||n==25||n==27||n==28||n==30||n==32||n==35||n==36||n==40||n==42||n==45||n==48||n==49||n==54||n==56||n==63||n==64||n==72||n==81){
        cout<<"Yes";
    }
    else cout<<"No";
	return 0;
}

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

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


Measured memory_bytes: 256
N = input()
l = (len(N) + 1) // 2
isodd = len(N) % 2
cnt = 0
for ii in range(1, l + 1):
    k = ii * 2 - 1
    if ii == l and isodd:
        cnt += int(N) - 10 ** (k - 1) + 1
    else:
        cnt += 10 ** k - 10 ** (k - 1)

print (cnt)


Measured memory_bytes: 2940
using System;

namespace ABC098_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);
            Console.WriteLine(Math.Max(Math.Max(a + b, a - b), a * b));
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

int main(void)
{
    
    int i_inputA;
    int i_inputB;
    int i_inputC;

    scanf("%d%d%d", &i_inputA, &i_inputB, &i_inputC);

    if ((i_inputA == i_inputB && i_inputB == i_inputC) || (i_inputA != i_inputB && i_inputB != i_inputC && i_inputA != i_inputC))
    {
        printf("No");
    }
    else
    {
        printf("Yes");
    }

}

Measured memory_bytes: 128
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
#define N 1010
int MOD = 1000000007;
int fac[N+1];
int inv[N+1];
ll bitpow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x % MOD;
        x = x * x %MOD;
        n = n >> 1;
    }
    return ans;
}
ll COM(ll n,ll k){
    return fac[n]*inv[k]%MOD*inv[n-k]%MOD;
}
int dp[1010][1010] = {0};
signed main(){
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    fac[0] = 1;
    inv[0] = 1;
    for(int i = 1;i <= N;i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = bitpow(fac[i],MOD-2)%MOD;
    }
    dp[a-1][0] = 1;
    for(int i = a;i <= b;i++){
        for(int j = 0;j <= n;j++){
            dp[i][j] = dp[i-1][j];
            for(int k = c;k <= d;k++){
                if(j-i*k < 0 || i*k > n)break;
                dp[i][j] += dp[i-1][j-i*k] * fac[n-(j-i*k)] %MOD * inv[n-(j-i*k) - i*k] %MOD * inv[k]%MOD * bitpow(inv[i],k)%MOD;
                dp[i][j] %= MOD;
                // if(i == 3){
                //     //cerr << "j : dp[i-1][j-i*k] : fac[n-(j-i*k)] : inv[n-i*k] : inv[k] : bitpow(inv[i],k)" << endl;
                //     //cerr << j << " " << dp[i-1][j-i*k] <<  " : " << fac[n-(j-i*k)]<<  " : "<< inv[n-i*k] <<  " : "<<  inv[k] <<  " : "<<  bitpow(inv[i],k);
                //     //cerr << endl;
                //  }
            }
        }
    }
    cout << dp[b][n] << endl;




    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_d
// rm -r -f test;oj dl http://arc067.contest.atcoder.jp/tasks/arc067_c

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std; 
int main(){
	long long K;
	cin>>K;
	queue<long long> q;
	for(int i=1;i<=9;i++)
	{
		q.push(i);
	}
	while(!q.empty())
	{
		long long x=q.front();
		q.pop();
		K--;
		if (K==0)
		{
			cout<<x<<endl;
			break;
		}
		for(int y=(x%10)-1;y<=(x%10)+1;y++) {
			if (y<0 || y>=10) 
			{
				continue;
			}
			q.push(x*10+(long long)y);
		}
	}
	return 0;
}

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

void solve(int N, int M, int K, vector<int> A, vector<int> B)
{
    int ia = 0, ib = 0;
    int t = 0;
    while (ia < N)
    {
        if (t + A.at(ia) > K)
            break;
        t += A.at(ia);
        ia++;
    }
    while (ib < M)
    {
        if (t + B.at(ib) > K)
            break;
        t += B.at(ib);
        ib++;
    }
    int res = ia + ib;

    while (ia > 0)
    {
        ia--;
        t -= A.at(ia);
        while (ib < M)
        {
            if (t + B.at(ib) > K)
                break;
            t += B.at(ib);
            ib++;
        }
        res = max(res, ia + ib);
    }
    cout << res << endl;
}

int main()
{
    int N;
    cin >> N;
    int M;
    cin >> M;
    int K;
    cin >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    vector<int> B(M);
    for (int i = 0; i < M; i++)
    {
        cin >> B.at(i);
    }
    solve(N, M, K, move(A), move(B));
    return 0;
}


Measured memory_bytes: 4772
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n, h, w;
    cin >> n >> h >>w;
    vector<ll> a(n);
    vector<ll> b(n);
    REP(i,n) cin >> a[i] >> b[i];
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] >= h && b[i] >= w) {
            ans++;
        }
    }
    cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n-1];
    rep(i,n){
        cin >> a[i];
    }
    int ans = 0;
    rep(i,n){
        cin >> b[i];
        ans += b[i];
    }
    rep(i,n-1){
        cin >> c[i];
    }
    rep(i,n-1){
        if (a[i]+1==a[i+1]) {
            ans += c[a[i]-1];
        }
    }
    cout << ans << endl;


    
}

Measured memory_bytes: 256
import numpy as np

N, D = map(int, input().split())
point_i_lst = []
for i in range(N):
    point_i_lst.append(list(map(int, input().split())))

count = 0
for i in range(N):
    for j in range(i+1, N):
        tmp = 0
        for k in range(D):
            tmp += (point_i_lst[i][k] - point_i_lst[j][k])**2
        
        tmp = np.sqrt(tmp)
        if tmp - int(tmp) == 0:
            count += 1

print(count)

Measured memory_bytes: 12424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int ans = 0;
	string s;
	cin >> s;
	rep(i, (s.size()-1)/2) {
		if (s.substr(0, i + 1) == s.substr(i + 1, i + 1))ans = i + 1;
	}
	cout << ans*2 << endl;
}

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

int main(){
    int a,b,c,d,e;
    int time=0;
    cin >> a >> b >> c >> d >> e;
    if(a<0){
        time = (0-a)*c+d+b*e;
    }else{
        time = (b-a)*e;
    }
    cout << time << endl;
}


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

struct edge { int u,v,cost; };

struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n, -1) { }
  int root(int x) {
    if (par[x]<0) return x;
    else return par[x]=root(par[x]);
  }
  bool issame(int x, int y) {
    return root(x) == root(y);
  }
  void merge(int x, int y) {
    x=root(x); y=root(y);
    if (x==y) return ;
    if (-par[x]<-par[y]) swap(x, y);
    par[x]+=par[y];
    par[y]=x;
  }
};

const int MAX_E=200000;

int n,V,E;
edge es[MAX_E+1];

bool comp(const edge& e1, const edge& e2) {
  return e1.cost<e2.cost;
}

int kruskal() {
  sort(es, es+E, comp);
  UnionFind uf(V);
  int res=0;
  for (int i=0; i<E; i++) {
    edge e=es[i];
    if (!uf.issame(e.u, e.v)) {
      uf.merge(e.u, e.v);
      res+=e.cost;
    }
  }
  return res;
}

int main() {
  cin>>n;
  V=n;
  E=2*n-2;
  vector<pair<pair<int,int>, int>> A(n);
  rep(i, n) {
    cin>>A[i].first.first>>A[i].first.second;
    A[i].second=i;
  }
  sort(A.begin(), A.end());
  rep(i, n-1) {
    int x1=A[i].first.first, y1=A[i].first.second;
    int x2=A[i+1].first.first, y2=A[i+1].first.second;
    int cost=min(abs(x1-x2), abs(y1-y2));
    es[i]={A[i].second, A[i+1].second, cost};
  }
  rep(i, n) swap(A[i].first.first, A[i].first.second);
  sort(A.begin(), A.end());
  rep(i, n-1) {
    int x1=A[i].first.first, y1=A[i].first.second;
    int x2=A[i+1].first.first, y2=A[i+1].first.second;
    int cost=min(abs(x1-x2), abs(y1-y2));
    es[i+n-1]={A[i].second, A[i+1].second, cost};
  }
  int res=kruskal();
  cout<<res<<endl;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  int count = 0;
  string str;
  cin >> A >> B;
  for (int i = A; i <= B; i++) {
    str = to_string(i);
    if (str[0] == str[4] and str[1] == str[3]) count += 1;
  }
  cout << count << endl;
}	

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

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            long H = long.Parse(Console.ReadLine());

            if (H == 1)
            {
                Console.WriteLine(1);
            }
            else if (H % 2 == 0)
            {
                Console.WriteLine(popo(bebe(H)));
            }
            else
            {
                Console.WriteLine(popo(bebe(H)));
            }
        }
        public static long bebe(long H)
        {
            var n = 0;
            while (H > 1)
            {
                H /= 2;
                n++;
            }
            return n - 1;
        }
        public static long popo(long H)
        {
            long n = 3;
            for (int i = 0; i < H; i++)
            {
                n = 2 * n + 1;
            }
            return n;
        }
    }
}


Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	static long N = 1000000007;

	static long exponentiation(long base, long exp) {
		long t = 1L;
		while (exp > 0) {
			if (exp % 2 != 0)
				t = (t * base) % N;

			base = (base * base) % N;
			exp /= 2;
		}
		return t % N;
	}

	public static void main(String args[]) throws Exception {
		MyScanner sc = new MyScanner();
		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		boolean flag = false;
		for (int i = a; i <= b; i++) {
			if (i % k == 0) {
				flag = true;
				break;
			}
		}
		System.out.println((flag == true) ? "OK" : "NG");
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

Measured memory_bytes: 32588
H, W, K = map(int, input().split())

c = [list(input()) for i in range(H)]

tate = 2 ** H
yoko = 2 ** W

ans = 0
for i in range(1, tate+1):
    for j in range(1, yoko+1):
        kuro = 0
        for x in range(H):
            for y in range(W):
                if i >> x & 1 and j >> y & 1 and c[x][y] == '#':
                    kuro += 1
        if kuro == K:
            ans += 1

print(ans)


Measured memory_bytes: 68504
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    if(n%2==0){
        cout << (double) (n/2)/n;
    }
    else{
        cout << (double) (n/2+1)/n;
    }

    return 0;
}

Measured memory_bytes: 3768
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

bool dfs(int depth,vi ball,stack<int> B,stack<int> C){
	if (depth == 10){
		return true;
	}
	bool ret,retB,retC;
	int A = ball[depth];
	
	if (B.top() < A){
		B.push(A);
		retB = dfs(depth + 1,ball,B,C);
		B.pop();
	}else{
		retB = false;
	}
	if (C.top() < A){
		C.push(A);
		retC = dfs(depth + 1,ball,B,C);
		C.pop();
	}else{
		retC = false;
	}

	if (retB or retC){
		ret = true;
	}else{
		ret = false;
	}

	return ret;

}

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

	for (int i = 0; i < n; i++){
		vi ball(10);
		stack<int> B,C;
		B.push(-1);
		C.push(-1);
		int num;
		for (int j = 0; j < 10; j++){
			cin >> ball[j];
		}

		if (dfs(0,ball,B,C)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3160
#include<stdio.h>
//#include<algorithm>
//#include<vector>
#include<map>
using namespace std;

const long long MAXN=1000000000;

int main(){
	map<long long,int> mp;
	int num,n;
	long long x;
	//for(long long i=1;i<=MAXN;i++) mp[x]=0;
	while(scanf("%d",&n)==1){
		num=0;
		for(int i=0;i<n;i++){
			scanf("%lld",&x);
			if(mp[x]==0){
				num++;
				mp[x]=1;
			}
			else if(mp[x]==1){
				num--;
				mp[x]=0;
			}
		}
		printf("%d\n",num);
	}
	return 0;
}

Measured memory_bytes: 6528
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, C, D):

    B -= A
    A = 0
    M = N - 1
    for i in range(N):
        u = i * D - (M-i) * C
        l = i * C - (M-i) * D
        if l <= B <= u:
            return 'YES'

    return 'NO'


def main():
    N, A, B, C, D = read_int_n()
    print(slv(N, A, B, C, D))


if __name__ == '__main__':
    main()


Measured memory_bytes: 60140
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	char a[101];
	gets(a);
	int str=strlen(a);
	for (register int i=0; i<str; i++)
	{
		if (a[i]=='C')
		{
			for (register int o=i+1; o<str; o++)
			{
				if (a[o]=='F')
				{
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
    return 0;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var n int 
  fmt.Scan(&n)
  tot := 0.0
  for i := 0; i < n; i++ {
    var x float64
    var u string
    fmt.Scan(&x, &u)
    if u == "BTC" {
      x *= 3.8e+5
    }
    tot += x
  }
  fmt.Println(tot)
}

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

int main() {
  
  int n;
  cin >> n;
  int m;
  cin >> m;
  
  vector<int> vec(m, 0);
  
  for (int i=0; i<n; i++) {
    int k;
    cin >> k;
    for (int j=0; j<k; j++) {
      int kk;
      cin >> kk;
      vec.at(kk-1)++;
    }
  }
  
  int s=0;
  for (int i=0; i<m; i++) {
    if (vec.at(i)==n) s++;
  }
  
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll n;
    cin >> n;
    map<ll, ll> a;
    ll total = 0;
    REP(i, n){
        ll ai;
        cin >> ai;
        a[ai]++;
        total += ai;
    }

    ll q;
    cin >> q;
    REP(i, q){
        ll bi, ci;
        cin >> bi >> ci;
        if(a.count(bi) == 0){
            cout << total << endl;
        }else{
            total -= a[bi] * bi;
            total += a[bi] * ci;
            cout << total << endl;
            a[ci] += a[bi];
            a.erase(bi);
        }
    }
    return 0;
}


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

int main(void)
{
    int m,d;
    cin >> m >> d;
    int i;
    int j;
    int out=0;
    for(i=1;i<=m;i++)
    {
        for(j=22;j<=d;j++)
        {
            if(j%10==1)
            {
                continue;
            }
            if((j/10)*(j%10)==i)
            {
                out++;
            }
        }
    }

    cout << out << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define p(x) cout << (x) << endl
#define FOR(i,r,n) for(ll i=(ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n); i>=r; i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) REP(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pb push_back

const int inf = (int)1e9;
const ll INF = (ll)1e18;

// vectorの中身をcout << vs;で表示
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
    o << "{";
    for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
    o << "}";
    return o;
}

ll gcd (ll a, ll b) {
	while (b > 0) {
		ll t = a % b;
		a = b, b = t;
	}
	return a;
}

ll lcm (ll a, ll b) {
	return (a / gcd (a, b)) * b;
}

bool is_prime (ll n) {
		if (n < 2) return false;
		else if (n == 2) return true;
		else if (n % 2) return false;
		
		double sqrtn = sqrt(n);
		for (ll i = 0; i < sqrtn; i += 2) {
			if (n % i == 0) return false; 
		}
		return true;
}

ll n, k, cnt=0, ans=0;
string s,t;

// ==================== template ============================

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

	ll a, b; cin >> a >> b;
	if (a <= 8 && b <= 8) ans = 1;
	cout << (ans ? "Yay!" : ":(") << endl;

}



Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {

  int N, D,A;

  scanf("%d %d\n",&N,&D );

  if(N%(2*D+1)==0){
    printf("%d\n",N/(2*D+1));
  }else{
    printf("%d\n",N/(2*D+1)+1 );
  }
    
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using edge = tuple<int, int, int>;


struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1){}
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x != y){
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
    }
    int root(int x) {return data[x] < 0 ? x : data[x] = root(data[x]);}
    int size(int x) {return -data[root(x)];}
};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V, E;
    cin >> V >> E;
    if (V == 1){
        cout << 0 << endl;
        return 0;
    }
    UnionFind uf(V);
    vector<edge> edges;
    while (E--){
        int s, t, w;
        cin >> s >> t >> w;
        edges.emplace_back(w, s, t);
    }
    sort(begin(edges), end(edges));
    int total_weight = 0;
    int pos = 0;
    int u, v, w;
    tie(w, u, v) = edges[pos];
    for (int i = 1; i < V; ++i){
        while (uf.root(u) == uf.root(v)){
            ++pos;
            w = get<0>(edges[pos]);
            u = get<1>(edges[pos]);
            v = get<2>(edges[pos]);
        }
        uf.unite(u, v);
        total_weight += w;
    }
    cout << total_weight << endl;
    return 0;
}

Measured memory_bytes: 4592
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    int ans = (n + 2 * d) / (2 * d + 1);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cstdlib>
using namespace std;

int main () {
	int n,i,c,b=0;
	cin >> n;
	int a[n];
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	int flag =1;
	while(flag){
		flag = 0;
		for(i=n-1;i>=1;i--){
			if(a[i]<a[i-1]){
				b++;
				c=a[i];
				a[i]=a[i-1];
				a[i-1]=c;
				flag=1;
			}
		}
	}
	for(i=0;i<n;i++){
		if(i!=n-1) cout << a[i] << " ";
		else cout << a[i] << endl;
	} 
	cout << b << endl;
}

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

int main() {
  ll X; cin >> X;
  ll start = 100;
  ll cnt = 0;
  while (start < X) {
    start = floor(start*1.01);
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
int a[3];

int main(){
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  if(a[0] + a[1] == a[2]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//Longest Common Subsequence  
using namespace std;
string a , b; 
vector <char> v ;  
int lcs[3010][3010]={},ans=0; 
int main() {
	cin >> a >> b ; 
	a=' '+a;
	b=' '+b;
	for (int i=1 ;i<a.size();i++)
		for (int j=1 ; j<b.size();j++)
		{
			if(a[i]==b[j])
			{
			
				lcs[i][j]=lcs[i-1][j-1]+1;
			}
			else
				lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]); 
		}
		
	int i=a.size()-1 ;
	int j=b.size()-1 ;
	while (lcs[i][j])
	{
		if(a[i]==b[j])
			{
				v.push_back(a[i]); 
				i--;j--; 
			}
			else
				if(lcs[i][j]==lcs[i-1][j])
				i--;
				else
				j--; 
		
	}
	
	if(v.size()==0)
	cout<<' ';
	else
	for(int i=v.size()-1 ;i>=0;i--)
	cout <<v[i]; 
	
	return 0;
}

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

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    ll n; cin >> n;
    ll t, a, x, y;
    x = 1; y = 1;
    rep(i,0,n) {
        cin >> t >> a;
        ll n = (x - 1) / t + 1;
        ll m = (y - 1) / a + 1;
        ll k = max(n, m);
        x = t * k; y = a * k;
    }
    cout << x + y << endl;
    return 0;
}

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

int main(){
  string S, T;
  cin >> S >> T;
  T.pop_back();
  if(T == S) cout << "Yes" << endl;
  else cout << "No" << endl;
    

}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

bool prime_table[100000001];

bool is_prime(int n){
  for(int i = 2; i * i <= n; i++){
    if(n%i==0) return false;
  }
  return n != 1;
}

int main() {
  int n, tmp;
  cin >> n;
  int count = 0;
  for (int i = 0; i < n; i++) {
      cin >> tmp;
      if(is_prime(tmp)) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
class Stackcats {
	std::stack<T> stack_1, stack_2;
	
	private:
	void rolling() {
		if(!stack_2.empty()) return;
		while(!stack_1.empty()) {
			stack_2.push(stack_1.top());
			stack_1.pop();
		}
	}
	public:
	Stackcats() {
		stack_1 = std::stack<T>();
		stack_2 = std::stack<T>();
	}
	void push(T x) {
		stack_1.push(x);
	}
	T front() {
		if(empty()) return T{};
		if(!stack_2.empty()) {
			return stack_2.top();
		}
		rolling();
		return stack_2.top();
	}
	void pop() {
		if(empty()) return;
		if(!stack_2.empty()) {
			stack_2.pop();
			return;
		}
		rolling();
		stack_2.pop();
	}
	void clear() {
		stack_1.clear();
		stack_2.clear();
	}
	bool empty() {
		return !(stack_1.size() + stack_2.size());
	}
	size_t size() {
		return stack_1.size() + stack_2.size();
	}
};

int main() {
	int n, q; scanf("%d%d", &n, &q);
	Stackcats<std::pair<std::string, int>> qu;
	while(n--) {
		std::string s; int t; cin >> s >> t;
		
		qu.push({s, t});
	}
	int now = 0;
	while(!qu.empty()) {
		auto p = qu.front(); qu.pop();
		
		if(p.second <= q) {
			printf("%s %d\n", p.first.c_str(), now + p.second);
			now += p.second;
			continue;
		} else {
			qu.push({p.first, p.second - q});
			now += q;
		}
	}
	return 0;
}



Measured memory_bytes: 5988
d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
T = [i % 26 for i in range(d)]
score = 0

for t in range(10**5):
    p = t % d
    q = t % 26
    memo = T[p]
    T[p] = q
    L = [-1 for j in range(26)]
    X = [0 for j in range(26)]
    tmp = 0
    for i in range(d):
        tmp += S[i][T[i]]
        X[T[i]] += (d - i) * (i - L[T[i]])
        L[T[i]] = i
    for j in range(26):
        tmp -= C[j] * (dd - X[j])
    if tmp > score:
        score = tmp
    else:
        T[p] = memo

for t in T:
    print(t + 1)


Measured memory_bytes: 74492
#include <stdio.h>
#define INF 10000
#define BLACK 1
#define WHITE 0
#define NIL -1
#define N 2000

int a[N][N];
int n;

int prim()
{
  int i, u, v, count=0, mincost,pi[N],d[N],color[N];
  for( i=0 ; i<n ; i++ ){
    d[i] = N;
    pi[i]=NIL;
    color[i]=WHITE;
  }
  while(1){
    mincost = INF;
    for( i=0 ; i<n ; i++ ){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost = d[i];
	u=i;
      }
    }
    if(mincost==INF)
      break;

    color[u] = BLACK;
    for( v=0 ; v<n ; v++ ){
      if(color[v]!=BLACK && d[v]>a[u][v] && a[u][v]!=-1){
	pi[v] = u;
	d[v] = a[u][v];
      }
    }
  }
  for( i=0 ; i<n ; i++ )
    count+=a[i][pi[i]];

  return count;
}

int main()
{
  int i, j;
  scanf("%d",&n);
  for( i=0 ; i<n ; i++ ){
    for( j=0 ; j<n ; j++ ){
      scanf("%d",&a[i][j]);
    }
  }

  printf("%d\n",prim());

  return 0;
}



Measured memory_bytes: 2212
program prob4
    implicit none
    integer::N, i, j, ans, p
    integer, allocatable::A(:)
    read(*,*) N
    allocate(A(N))
    read(*,*) A

    ans = 1
    p = 0
    do i = 2, N
        if(p == 0) then
            if(A(i) > A(i-1)) then
                p = 1
            else if(A(i) < A(i-1)) then
                p = -1
            end if
        else
            if(p == 1) then
                if(A(i) < A(i-1)) then
                    p = 0
                    ans = ans + 1
                end if
            else
                if(A(i) > A(i-1)) then
                    p = 0
                    ans = ans + 1
                end if
            end if
        end if
    end do

    write(*,*) ans
    stop
end program


Measured memory_bytes: 3372
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void print_vec(vector<int>& a){
		int n=a.size();

	for(int i=0;i<a.size();i++)
		cout << a[i] << (i<n-1 ? " ":"\n");
}

void print_vec(vector<bool>& a){
		int n=a.size();

	for(int i=0;i<a.size();i++)
		if(a[i])
			cout << i << (i<n-1 ? " ":"\n");
}

void print_vec(vector<long long>& a){
	int n=a.size();
	for(int i=0;i<a.size();i++)
		cout << a[i] << (i<n-1 ? " ":"\n");
	cout << "\n";
}

void solve(){
	int n;
	cin >> n;
	for(int i=int(floor(n/105));i<=int(ceil(n/100));i++){
		if(n-100*i >= 0 && n-100*i <= 5*i){
			cout << "1\n";
			return;
		}
	}
	cout<<"0\n";
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	
	solve();
	
	return 0;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
	int n, q;
	cin >> n >> q;
	for (int unko = 0; unko < q; unko++) {
		int v, w;
		cin >> v >> w;
		if (n == 1) {
			cout << min(v, w) << endl;
			continue;
		}
		while (v != w) {
			if (v > w) {
				v = (v + n - 2) / n;
			}
			else {
				w = (w + n - 2) / n;
			}
		}
		cout << v << endl;
	}
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	vector<string> s(n);
	for(int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	
	vector<int> cnt(26, 100);
	for(int i = 0; i < n; ++i) {
		vector<int> tmp(26, 0);
		
		for(int j = 0; j < (int)s[i].size(); ++j) {
			tmp[s[i][j] - 'a']++;
		}
		
		for(int j = 0; j < 26; ++j) {
			cnt[j] = min(cnt[j], tmp[j]);
		}
	}
	
	string ans = "";
	for(int i = 0; i < 26; ++i) {
		for(int j = 0; j < cnt[i]; ++j) {
			ans += (char)(i + 'a');
		}
	}
	
	if( ans == "" ) {
		cout << " " << endl;
	} else {
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3608
n = gets.to_i
s = []
n.times do
  s << gets.chomp!
end

m = gets.to_i
t = []
m.times do
  t << gets.chomp!
end

h = Hash.new(0)
h2 = Hash.new(0)

s.each do |i|
  h[i] += 1
end

t.each do |i|
  h2[i] += 1
end

h3 = Hash.new(0)
a = h.keys & h2.keys
a.each do |i|
  h3[i] = h[i] - h2[i]
end

h4 = Hash.new(0)
b = (h.keys | h2.keys) - (h.keys & h2.keys)
b.each do |i|
  h4[i] = h[i] + h2[i]
end

h4.each do |k,v|
  h4.delete(k) if h2.include?(k)
end

ans = h.values.max if h3.size == 0
h3.each do |k,v|
  if v <= 0
    ans = h4.size != 0 ? h4.values.max : 0
  else
    ans = h3.values.max
  end
end

p ans


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

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

int main(){
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    //入力された回数分(a_i)だけ、iを追加する
    queue<int> q;
    for(int i = 1; i <= N; i++){
        int a;
        cin >> a;
        rep(j, a) q.push(i);
    }

    //色を塗るマス目の2次元配列
    vector<vector<int>> grid(H, vector<int>(W, 0));
    rep(i, H){
        if(i % 2 == 0){
            rep(j, W){
                grid[i][j] = q.front();
                q.pop();
            }
        }else{
            for(int j = W-1; j >= 0; j--){
                grid[i][j] = q.front();
                q.pop();
            }
        }
    }

    if(!q.empty()) cout << "q is not empty!!" << endl;
    cout << endl;
    rep(i, H){
        rep(j, W) cout << grid[i][j] << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3692
s = list(input())
K = int(input())

n = len(s)
for i in range(n - 1):
    tmp = (26 - ord(s[i]) + ord('a')) % 26 #aにするために必要な回数
    if tmp <= K:
        K -= tmp
        s[i] = 'a'

K %= 26 #最後の一回で調整する
tmp = ord(s[n - 1]) + K
if tmp >= 123:
    tmp -= 26
s[n - 1] = chr(tmp)

print (*s, sep = '')
    

Measured memory_bytes: 6964
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n, d, x;
	cin >> n >> d >> x;
	vector<int> a(n);
	int ans = x;
	rep(i, 0, n) {
		cin >> a[i];
		ans++;
		for (int j = 1;j*a[i]+1 <= d;j++) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read();
    let q = read();
    let mut adj: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let a = read::<usize>() - 1;
        let b = read::<usize>() - 1;
        adj[a].push(b);
        adj[b].push(a);
    }
    let mut xsum = vec![0; n];
    for _ in 0..q {
        let p = read::<usize>() - 1;
        let x: i64 = read();
        xsum[p] += x;
    }

    let mut ans = vec![0; n];

    fn rec(v: usize, p: usize, xpar: i64, adj: &Vec<Vec<usize>>, xsum: &Vec<i64>, ans: &mut Vec<i64>) {
        let x = xpar + xsum[v];
        ans[v] = x;
        for &c in adj[v].iter() {
            if c == p {
                continue;
            }
            rec(c, v, x, adj, xsum, ans);
        }
    }

    rec(0, !0, 0, &adj, &xsum, &mut ans);

    for a in ans.iter() {
        print!("{} ", a);
    }
    println!();
}


Measured memory_bytes: 38396
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		Integer[] c = new Integer[a];
		int d = 0;
		for (int i = 0; i < a; i++) {
			c[i] = sc.nextInt();
		}
		
		Arrays.sort(c, Comparator.reverseOrder());
		
		
		for (int i = 0; i < b; i++) {
			d += c[i];
		}
		
		System.out.println(d);
	}
}

Measured memory_bytes: 21972
N = gets.to_i
a = gets.split.map(&:to_i).sort.reverse.group_by(&:itself).reject {|k,v| v.size <= 1 }
f = false
t = 0
a.each do |k,v|
  if !f && v.size >= 4
    p k*k
    exit
  elsif t.zero?
    f = true
    t = k
  else
    p t*k
    exit
  end
end
p 0


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

int main(){
  ll n,x,t,ans=0; cin>>n>>x;
vector<ll>v(n);
  rep(i,n){ 
    cin>>t;
  v.at(i)=abs(x-t);
          }
  sort(v.begin(),v.end());
  for(ll i=v.at(0); i>=1;i--){
  bool flag=true;
    rep(k,n){
  if(v.at(k)%i!=0){flag=false; break;}
  }
    if(flag){cout<<i<<endl; break;}
  }
 
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

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

    //map<string, int> msc;
    map<string,int> sums;
    int total = 0;
    for (int i = 0; i < N; i++) {
        string name;
        int time;
        cin >> name >> time;
        //msc[name] = time;
        total += time;
        sums[name] = total;
    }

    string X;
    cin >> X;
    cout << total - sums[X] << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
    list<char> l1, l2;
    string S;
    int Q;
    cin >> S >> Q;

    bool forward = true;
    char c;
    int t, f;

    rep(i, Q) {
        cin >> t;
        if (t == 1) {
            forward = !forward;
            continue;
        }
        cin >> f >> c;
        if (f == 1) {
            if (forward)
                l1.push_front(c);
            else
                l2.push_back(c);
        } else {
            if (forward)
                l2.push_back(c);
            else
                l1.push_front(c);
        }
    }

    if (!forward) {
        for(auto itr = l2.rbegin(); itr != l2.rend(); ++itr) {
            cout << *itr;
        }
        for(auto itr = S.rbegin(); itr != S.rend(); ++itr) {
            cout << *itr;
        }
        for(auto itr = l1.rbegin(); itr != l1.rend(); ++itr) {
            cout << *itr;
        }
    } else {
        for(auto itr = l1.begin(); itr != l1.end(); ++itr) {
            cout << *itr;
        }
        cout << S;
        for(auto itr = l2.begin(); itr != l2.end(); ++itr) {
            cout << *itr;
        }
    }
    return 0;
}


Measured memory_bytes: 6912
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i, n){
        cin >> a[i];
        a[i]--;
    }
    vector<int> when(n, -1);
    int nowpos = 0;
    int cnt = 0;
    when[0] = 0;
    vector<int> history(n);
    history.push_back(0);
    while(1){
        cnt++;
        nowpos = a[nowpos];
        history.push_back(nowpos);
        if(cnt == k){
            cout << nowpos+1 << endl;
            return 0;
        }
        if(when[nowpos] != -1)  
            break;
        when[nowpos] = cnt;
    }

    int period = cnt - when[nowpos];
    int from = when[nowpos];
    k -= from;
    k = (k + period) % period;

    REP(i, k)
        nowpos = a[nowpos];
    cout << nowpos+1 << endl;
    return 0;
}

Measured memory_bytes: 5996