akhauriyash/Code-Regression huggingface dataset:
def main
    n,k,s = gets.chomp.split(" ").map(&:to_i)
    a = []
    k.times do
        a.push s
    end
    (n-k).times do
        t = s + 1
        t = 1 if s == 10**9
        a.push t
    end
    puts a.join(" ")
end

main


Measured memory_bytes: 4732
# https://atcoder.jp/contests/abc131/tasks/abc131_d
# 最適なのは締切が速い順から取り掛かること
import sys
from operator import itemgetter
read = sys.stdin.readline


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


N = read_a_int()
AB = read_tuple(N)
AB.sort(key=itemgetter(1))
jikoku = 0
for a, b in AB:
    jikoku += a
    if jikoku > b:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 31948
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)

const string YES = "YES";
const string NO = "NO";

void solve(long long X){
    if(X == 3 || X == 5 || X == 7)
        cout << YES << endl;
    else
    {
        cout << NO << endl;
    }
    
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
import itertools
N,M=map(int,input().split())
edges=[]
for i in range(M):
    edges.append(list(map(int,input().split())))

res=0
for i in itertools.permutations(range(2,N+1),N-1):
    path=[1]+list(i)
    check=[sorted(path[i:i+2]) in edges for i in range(len(path)-1)]
    if not False in check:
        res+=1
print(res)

Measured memory_bytes: 74848
/*input
10 1000000000000000000
0 0 1 1 0 0 0 1 1 0
0 0 0 0 0 1 1 1 0 0
0 1 0 0 0 1 0 1 0 1
1 1 1 0 1 1 0 1 1 0
0 1 1 1 0 1 0 1 1 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 0 0 1 0 1
1 0 0 0 1 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
1 0 1 1 1 0 1 1 1 0
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ld,ld>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=1e6+1;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
    ll x=a-b;
    while(x<0) x+=MOD;
    while(x>MOD) x-=MOD;
    return x;
}
ll mult(ll a,ll b){
    return a*b%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a);
        if(res>1e10) return 1e11;
        a=(a*a);
        b>>=1;
    }
    return res;
}
const ll maxn=55;
const ll maxlg=__lg(maxn)+2;
int n;
struct M{
    vector<vector<int>> v;
    M(){
        v.resize(n,vector<int>(n));
    }
    M operator* (const M &b) const{
        M c;
        REP(i,n){
            REP(j,n){
                REP(k,n){
                    c.v[i][j]+=mult(v[i][k],b.v[k][j]);
                    c.v[i][j]%=MOD;
                }
            }
        }
        return c;
    }
};
int main(){
    ll k;
    cin>>n>>k;
    vector<vector<int>> can(n,vector<int>(n));
    REP(i,n) REP(j,n) cin>>can[i][j];
    M x,ans;
    x.v=can;
    REP(i,n) ans.v[i][i]=1;
    while(k){
        if(k%2==1) ans=ans*x;
        x=x*x;
        k/=2;
    } 
    ll ans2=0;
    REP(i,n) REP(j,n) ans2+=ans.v[i][j],ans2%=MOD;
    cout<<ans2;
}

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


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

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]--;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        if(i==a[a[i]]) ans++;
    }
    ans/=2;
    cout<<ans<<endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define pr pair<int, int>
#define graph vector< vector<int> >
#define vs vector<string>
#define mn -
#define pls +
#define mod %
#define E =
#define EE ==
#define pls +
#define le <=
#define ge <=
//int mx=9999999;
/**  '' "\n" x ^ **/
void YES()
{
    cout<<"YES\n";
}

void NO()
{
    cout<<"NO\n";
}
void yes()
{
    cout<<"Yes\n";
}

void no()
{
    cout<<"No\n";
}
int main() {
    /**  '' "\n" x ^ **/
    /** printf("\n") */
    ios::sync_with_stdio(false);
    cin.tie(0);
    string str;
    cin>>str;
    if(str[2]==str[3]&&str[4]==str[5])
        yes();
    else no();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000000000


int main(){
  char buf[1024];
  long N;
  long *a=(long *)malloc(sizeof(long)*5);

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%ld", &N);
  rep(i,5){
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf, "%ld", &a[i]);
  }

  long min=INF;
  rep(i,5){
    if(a[i]<min){
      min=a[i];
    }
  }

  long ans=0;
  if(N<=min){
    ans=5;
  }
  else{
    if(N%min==0){
      ans+=N/min;
    }
    else{
      ans+=N/min+1;
    }
    ans+=4;
  }

  printf("%ld\n", ans);

  return 0;

}


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

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

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);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int a = in.nextInt();
			int b = in.nextInt();
			if(a > b) {
				out.println(a - 1);
			} else {
				out.println(a);
			}
		}
	}
	
	static class InputReader {
		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());
		}

	}
}


Measured memory_bytes: 23252
N, W = map(int, input().split())
wv = [[0 for i in range(2)] for j in range(N)]
dp = [[0 for i in range(N+1)] for j in range(W+1)]

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

for i in range(N):
  for w in range(1,W+1):
    if w < wv[i][0]:
      dp[w][i+1] = dp[w][i]
    else:
      dp[w][i+1] = max(dp[w-wv[i][0]][i]+wv[i][1], dp[w][i])

print(dp[-1][-1])


Measured memory_bytes: 169164
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define Q 44
#define i16 short
#define Min(xxx,yyy) xxx=min(xxx+0,yyy)
i16 sm[Q][Q],f[Q][Q][Q][Q];
char aa[Q];
inline i16 G(int x1,int y1,int x2,int y2)
{--x1,--y1;return sm[x2][y2]+sm[x1][y1]-sm[x1][y2]-sm[x2][y1];}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int sx=-1,sy=-1;
	for(int i=1;i<=n;i++){
		scanf("%s",aa+1);
		for(int j=1;j<=m;j++){
			sm[i][j]=sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+(aa[j]=='#');
			if(aa[j]>='A'&&aa[j]<='Z')sx=i,sy=j;
		}
	}
	if(min(sx,sy)<0)cerr<<"Err!!\n";
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			for(int k=1;k<=n;k++)
				for(int l=1;l<=m;l++)
					f[i][j][k][l]=10000;
	f[1][1][n][m]=0;
	i16 ans=10000;
	for(int x1=1;x1<=sx;x1++)
	for(int y1=1;y1<=sy;y1++)
	for(int x2=n;x2>=sx;--x2)
	for(int y2=m;y2>=sy;--y2){
		i16 val=f[x1][y1][x2][y2];
		Min(ans,val+min(min(G(x1,y1,sx,sy),G(sx,sy,x2,y2)),min(G(x1,sy,sx,y2),G(sx,y1,x2,sy))));
		for(int px=x1;px<=x2;px++)
			for(int py=y1;py<=y2;py++){
				if(px>=sx&&py<=sy)Min(f[x1][py][px][y2],val+G(x1,y1,px,py-1)+G(px+1,py,x2,y2));
				if(px>=sx&&py>=sy)Min(f[x1][y1][px][py],val+G(x1,py+1,px,y2)+G(px+1,y1,x2,py));
				if(px<=sx&&py<=sy)Min(f[px][py][x2][y2],val+G(x1,py,px-1,y2)+G(px,y1,x2,py-1));
				if(px<=sx&&py>=sy)Min(f[px][y1][x2][py],val+G(x1,y1,px-1,py)+G(px,py+1,x2,y2));
			}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n[3];cin>>n[0]>>n[1]>>n[2];
  sort(n,n+3);
  cout<<n[2]-n[1]+(n[1]-n[0])/2+(n[1]-n[0])%2*2<<endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	public static class Walk implements Comparable<Walk>{
		int pos;
		int prev_pos;
		int speed;
		double time;
		
		public Walk(int pos, int prev_pos, int speed, double time) {
			super();
			this.pos = pos;
			this.prev_pos = prev_pos;
			this.speed = speed;
			this.time = time;
		}

		@Override
		public int compareTo(Walk o) {
			return Double.compare(this.time, o.time);
		}
	}
	
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);

		while (true) {
			final int n = sc.nextInt();
			final int m = sc.nextInt();
			
			if(n == 0 && m == 0){
				break;
			}
			
			final int s = sc.nextInt() - 1;
			final int g = sc.nextInt() - 1;
			
			int[][] dist  = new int[n][n];
			int[][] limit = new int[n][n];
			
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					dist[i][j] = -1;
					limit[i][j] = -1;
				}
			}
			
			for(int i = 0; i < m; i++){
				final int x = sc.nextInt() - 1;
				final int y = sc.nextInt() - 1;
				final int d = sc.nextInt();
				final int c = sc.nextInt();
				
				dist[x][y]  = dist[y][x]  = d;
				limit[x][y] = limit[y][x] = c;
			}
			
			boolean[][][] is_visited = new boolean[n][n][30 + 1];
			
			PriorityQueue<Walk> queue = new PriorityQueue<Walk>();
			queue.add(new Walk(s, -1, 1, 0));
			
			boolean flag = false;
			while(!queue.isEmpty()){
				Walk walk = queue.poll();
				
				//System.out.println(walk.pos + " " + walk.prev_pos + " " + walk.time + " " + walk.speed);
				
				if(walk.prev_pos != -1 && is_visited[walk.pos][walk.prev_pos][walk.speed]){
					continue;
				}else if(walk.prev_pos != -1){
					is_visited[walk.pos][walk.prev_pos][walk.speed] = true;
				}
				
				if(walk.pos == g && walk.speed == 1){
					System.out.printf("%f\n", walk.time);
					flag = true;
					break;
				}
				
				for(int to = 0; to < n; to++){
					if(dist[walk.pos][to] < 0){
						continue;
					}else if(to == walk.prev_pos){
						continue;
					}
					
					if(walk.prev_pos == -1){
						if(limit[walk.pos][to] >= 1 && !is_visited[to][walk.pos][1]){
							queue.add(new Walk(to, walk.pos, 1, walk.time + dist[walk.pos][to]));
						}
					}else{
						for(int speed = -1; speed <= 1; speed++){
							final int next_speed = walk.speed + speed;
						
							if(next_speed <= 0){
								continue;
							}else if(limit[walk.pos][to] < next_speed){
								break;
							}else if(is_visited[to][walk.pos][next_speed]){
								continue;
							}
						
							queue.add(new Walk(to, walk.pos, next_speed, walk.time + (double)(dist[walk.pos][to]) / next_speed));
						}
					}
				}
			}
			
			if(!flag){
				System.out.println("unreachable");
			}
		}
	}

}

Measured memory_bytes: 72404
mod=1000000007
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]

xc=0
for i in range(1,n):
    a=x[i]-x[i-1]
    if i<=((n)//2):
        l=i
    else:
        l=n-i
    xc+=a*(l*n-(l*l))
    xc=xc%mod

yc=0
for i in range(1,m):
    a=y[i]-y[i-1]
    if i<=((m)//2):
        l=i
    else:
        l=m-i
    yc+=a*(l*m-(l*l))
    yc=yc%mod
print((xc*yc)%mod)


Measured memory_bytes: 18624
#include <stdio.h>

int main(void)
{
	int i;
	int j;
	
	for (i = 1; i <= 9; i++){
		for ( j = 1; j <= 9; j++){
			printf("%dx%d=%d\n", i, j, i * j);
		}
	}
	
	return 0;
}

Measured memory_bytes: 520
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String work;
		for(int i=0; i<h; i++){
			work = sc.next();
			System.out.println(work);
			System.out.println(work);
		}
		return;
	}
}

Measured memory_bytes: 10836
//by Top1
#include <bits/stdc++.h>
     
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
 
const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 6e5 + 111;
     
using namespace std;

int q, n, m, dp[2000][2000];
char a[2000][2000];

void solve(){    
	cin >> n >> m;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];

	dp[1][1] = 1;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (a[i][j] == '.')
				dp[i][j] += (dp[i - 1][j] + dp[i][j - 1]) % mod;

	cout << dp[n][m];
		
}

main(){
    boost;
	    
	q = 1;

	while (q--){
		solve();
	}
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    string s[2003];
    for(int i = 0; i < h; i++){
        cin >> s[i];
        s[i] = s[i] + '#';
    }
    s[h] = "";
    vector<int> rl[2002], ud[2002];
    for(int j = 0; j <= w; j++) s[h] += '#';
    for(int i = 0; i < h; i++){
        rl[i].push_back(-1);
        int now = 0;
        for(int j = 0; j <= w; j++){
            if(s[i][j] == '#') rl[i].push_back(now);
            now++;
        }
    }
    for(int j = 0; j < w; j++){
        ud[j].push_back(-1);
        int now = 0;
        for(int i = 0; i <= h; i++){
            if(s[i][j] == '#') ud[j].push_back(now);
            now++;
        }
    }
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] != '#'){
                int y = lower_bound(rl[i].begin(), rl[i].end(), j) - rl[i].begin();
                y = rl[i][y] - rl[i][y - 1] - 1;
                int t = lower_bound(ud[j].begin(), ud[j].end(), i) - ud[j].begin();
                t = ud[j][t] - ud[j][t - 1] - 1;
                ans = max(ans, y + t - 1);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 36480
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""
import numpy as np


N = int(input())
print(2 * np.pi * N)



# def main():

# if __name__ == '__main__':
#     main()


Measured memory_bytes: 26976
from math import gcd
n, m = map(int, input().split()); s = input(); t = input()
g = gcd(n, m); a = 0
for i in range(g):
    if s[len(s)//g*i] != t[len(t)//g*i]: a = 1; break
print(n*m//g) if a == 0 else print(-1)

Measured memory_bytes: 9244
using System;

namespace _0533
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] W = new int[10];
            int[] K = new int[10];
            for (int i = 0; i < 10; i++)
            {
                W[i] = int.Parse(Console.ReadLine());
            }
            for (int i = 0; i < 10; i++)
            {
                K[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(W);
            int Wgoukei = (W[9] + W[8] + W[7]);
            Array.Sort(K);
            int Kgoukei = (K[9] + K[8] + K[7]);
            Console.WriteLine(Wgoukei + " " + Kgoukei);
        }
    }
}

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
const int maxn=100010;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int dp[maxn][3],happiness[maxn][3],n;
int main()
{
    n=read();
    for(int i=1;i<=n;i++)
        happiness[i][0]=read(),
        happiness[i][1]=read(),
        happiness[i][2]=read();

    dp[1][0]=happiness[1][0],
    dp[1][1]=happiness[1][1],
    dp[1][2]=happiness[1][2];
    
    for(int i=2;i<=n;i++)
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+happiness[i][0],
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+happiness[i][1],
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+happiness[i][2];

    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
    return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;
    for (int i=0; i<=100; i++){
        for (int j=0; j<=100; j++){
            if (i+j==x && 2*i+4*j==y){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

int main(){
	int H,W,A,B;
	cin >> H >> W >> A >> B;
	
	for(int a = 0 ; a <= H ; a ++){
		for(int b = 0 ; b <= W ; b ++){
			if(a*A+(H-a)*(W-A) == b*B+(W-b)*(H-B)){
				//cout << a << " " << b << endl;
				vector<int> X,Y;
				if(H >= W){
					for(int j = 0 ; j < A ; j ++){
						for(int i = 0 ; i < H ; i ++)X.push_back(i);
					}
					for(int j = A ; j < W-A ; j ++){
						for(int i = 0 ; i < H-a ; i ++)X.push_back(i);
					}
				}
				else {
					for(int i = 0 ; i < a ; i ++){
						for(int j = 0 ; j < A ; j ++)X.push_back(i);
					}
					for(int i = a ; i < H ; i ++){
						for(int j = 0 ; j < W-A ; j ++)X.push_back(i);
					}
				}
				if(W > H){
					for(int j = 0 ; j < B ; j ++){
						for(int i = 0 ; i < W ; i ++)Y.push_back(i);
					}
					for(int j = B ; j < H-B ; j ++){
						for(int i = 0 ; i < W-b ; i ++)Y.push_back(i);
					}
				}
				else {
					for(int i = 0 ; i < b ; i ++){
						for(int j = 0 ; j < B ; j ++)Y.push_back(i);
					}
					for(int i = b ; i < W ; i ++){
						for(int j = 0 ; j < H-B ; j ++)Y.push_back(i);
					}
				}
				static string ret[1002];
				ret[0] = "";
				for(int i = 0 ; i < W ; i ++)ret[0] += "0";
				for(int i = 1 ; i < H ; i ++)ret[i] = ret[i-1];
				for(int i = 0 ; i < a*A+(H-a)*(W-A) ; i ++){
					//cout << X[i] << " " << Y[i] << endl;
					ret[X[i]][Y[i]] = '1';
				}
				for(int i = 0 ; i < H ; i ++){
					cout << ret[i] << endl;
				}
				return 0;
			}
		}
	}
	puts("No");
}

Measured memory_bytes: 11884
N = int(input())
S = []
for i in range(N):
  tmp = list(input().split(" "))
  tmp[1] = int(tmp[1])
  tmp+=[i+1]
  S.append(tmp)

S.sort(key=lambda x:(x[0],-x[1]))
for ans in S:
  print(ans[2])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp> 
using namespace boost::multiprecision; 
using namespace std;
int main(){
	int n;
  cin >> n;
  long long arr[n];
  for(int i=0;i<n;i++) cin >> arr[i];
  cpp_int pro = 1;
  sort(arr,arr+n);
  bool zer = 0, ans=0;
  for(int i = 0;i < n;i++){
  	if(arr[i]==0){
    	zer=1;
    	break;}
    else{	
    	pro*=arr[i];
    	if(pro > 1000000000000000000){
    		ans=1;
      break;}
    }
  }
  if(zer)
    cout << 0;
  else if(ans)
    cout << -1;
  else
    cout << pro;
  return 0;
}

Measured memory_bytes: 4472
# include <iostream>
# include <string>
# include <vector>
using namespace std;
int main()
{
	long long p,q,m,l,a,j,w,n;
	string s;
	cin>>s;
	cin>>w;
	s=s+s[0];
	n=s.size();
	p=0;
	m=0;
	l=0;
	a=0;
	j=0;
	vector<int>x;
	if(n==2)
	{
		cout<<w/2;
		return 0;
	}
	for(int i=0; i<n-1; i++)
	{
		if(s[i]==s[i+1])
		{
			p=p+1;
			q=1;
			if(i==n-2 && x.size()!=0)
			{
				a=p;
				if(a%2==0 || x[0]%2==0)
				{
					m=m+a/2*w;
				}
				else
				{
					m=m+(a/2+1)*w-1;
				}
			}
			if(i==n-2 && x.size()==0)
			{
				a=p;
				if(a%2==0)
				{
					m=m+a/2*w;
				}
				else
				{
					if(w%2==0)
					{
						m=m+a/2*w/2;
						m=m+(a/2+1)*w/2;
					}
					else
					{
						m=m+a/2*(w/2+1);
						m=m+(a/2+1)*(w/2);
					}
				}
			}
		}
		else
		{
			if(q==1)
			{
				m=m+(p+1)/2*w;
				x.push_back(p+1);
				p=0;
				q=0;
			}
		}
	}
	cout<<m;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, K;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;

	int ans = 0;
	while (0 < N) {
		N /= K;
		ans++;
	}
	cout << ans << endl;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,m;
cin>>n>>m;
long long a[n];
for(long long i=0;i<n;i++){
  cin>>a[i];
}
long long sum=0;
for(long long i=0;i<n;i++){
  sum+=a[i];
}
sort(a,a+n);
reverse(a,a+n);
long long ans=0;
long long sum2;
 if(sum%(4*m)==0){
   sum2=sum/(4*m);
 }
 else {
   sum2=sum/(4*m)+1;
 }
if(a[m-1]>=sum2){
  cout<<"Yes"<<endl;
}
else{
  cout<<"No"<<endl;
}
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
int f(int x) {
	string s = to_string(x);
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		ans += s[i] - '0';
	}
	return ans;
}
int main() {
	int n;
	cin >> n;
	if (n%f(n) == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main() {
  int n,ans = 0,m = 1e5,p,av = 0;
  cin >> n;
  vector<int>a(n);
  rep(i,n){
    cin >> a[i];
    av += a[i];
  }
  rep(i,n){
    if(m > abs(av-n*a[i])){
      p = i;
      m = abs(av-n*a[i]);
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 256
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;
vector < int > adj[maxn];
int ans;

int dfs(int v=1){
    int mx = 0;
    vector < int > vec;
    for(int u : adj[v])
        vec.pb(dfs(u));
    sort(vec.begin() , vec.end());
    reverse(vec.begin() , vec.end());
    for(int i = 0 ; i < vec.size() ; i ++) mx = max(mx ,vec[i]+ i + 1);
    return(mx);
}

int32_t main(){
    migmig
    cin >> n;
    for(int i = 2 ; i <= n;  i ++){
        int u;
        cin >> u;
        adj[u].pb(i);
    }
    cout << dfs();
    return(0);
}

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

int main(){
  int N,h,m,s;
  cin >> N;
  h=N/3600;N-=3600*h;
  m=N/60;N-=60*m;
  s=N;
  cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  bool col[w]={}, row[h]={};
  string a[h];
  for(int i=0;i<h;i++)
    cin >> a[i];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j] == '#'){
        row[i] = true;
        col[j] = true;
      }
    }
  }
  for(int i=0;i<h;i++){
    if(!row[i]) continue;
    for(int j=0;j<w;j++){
      if(col[j]){
        cout << a[i][j];
      }
    }
    cout << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	int map[10][10]={};
	int x,y,s,nx,ny;
	int dx1[]={-1,0,0,0,1};
	int dy1[]={0,-1,0,1,0};
	int dx2[]={-1,-1,-1,0,0,0,1,1,1};
	int dy2[]={-1,0,1,-1,0,1,-1,0,1};
	int dx3[]={-2,-1,-1,-1,0,0,0,0,0,1,1,1,2};
	int dy3[]={0,-1,0,1,-2,-1,0,1,2,-1,0,1,0};
	char c;
	while(cin>>x>>c>>y>>c>>s){
		if(cin.eof())break;
		if(s==1){
			for(int i=0;i<5;i++){
				nx=x+dx1[i];
				ny=y+dy1[i];
				if(0<=nx&&nx<10&&0<=ny&&ny<10)map[nx][ny]++;
			}
		}else if(s==2){
			for(int i=0;i<9;i++){
				nx=x+dx2[i];
				ny=y+dy2[i];
				if(0<=nx&&nx<10&&0<=ny&&ny<10)map[nx][ny]++;
			}
		}else{
			for(int i=0;i<13;i++){
				nx=x+dx3[i];
				ny=y+dy3[i];
				if(0<=nx&&nx<10&&0<=ny&&ny<10)map[nx][ny]++;
			}
		}
	}
	int res=0,m=0;
	for(int i=0;i<10;i++)for(int j=0;j<10;j++)if(!map[i][j])res++;else if(map[i][j]>m)m=map[i][j];
	printf("%d\n%d\n",res,m);
    return 0;
}

Measured memory_bytes: 1144
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

int w,h,n;
struct node{
    int x,y,z;
}p[105];
int mp[105][105];
int main(){
    mes(mp,0);
    cin>>w>>h>>n;
    int cnt=w*h;
    rep(i,1,n){
        cin>>p[i].x>>p[i].y>>p[i].z;
        switch(p[i].z){
            case 1:{
                rep(j,1,p[i].x){
                    rep(k,1,h){
                        if(mp[j][k]==0){
                            //printf("mp=%d %d\n",j,k);
                            cnt--;
                            mp[j][k]=1;
                        }
                    }
                }
                break;
            }
            case 2:{
                rep(j,p[i].x+1,w){
                    rep(k,1,h){
                        if(mp[j][k]==0){
                            cnt--;
                            mp[j][k]=1;
                        }
                    }
                }
                break;
            }
            case 3:{
                rep(j,1,w){
                    rep(k,1,p[i].y){
                        if(mp[j][k]==0){
                            cnt--;
                            mp[j][k]=1;
                        }
                    }
                }
                break;
            }
            case 4:{
                rep(j,1,w){
                    rep(k,p[i].y+1,h){
                        if(mp[j][k]==0){
                            //printf("mp=%d %d\n",j,k);
                            cnt--;
                            mp[j][k]=1;
                        }
                    }
                }
                break;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c=0,d;
    while(1){
        cin>>a>>b;
        d=a+b;
        if(d==0){
            break;
        }
        for(int h=a;h>=1;h--){
            for(int i=h-1;i>=1;i--){
                for(int o=i-1;o>=1;o--){
                    if(h+i+o==b){
                        c++;
                    }
                }
            }
        }
        cout<<c<<endl;
        c=0;
    }
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(void){
    // Your code here!
 ll a,b,c,d,l;
 cin >> a >> b >> c >> d;
 l=(c*d)/__gcd(c,d);
 cout << b-a+1-(b/c)+((a-1)/c)-(b/d)+((a-1)/d)+(b/l)-((a-1)/l);
 return 0;
}

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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;
typedef pair<int, int> pii;

int main(){
  int n;
  while(cin >> n and n){
    vector<pii> trees;
    int w, h;
    cin >> w >> h;
    int sum[w][h];
    memset(sum, 0, sizeof(sum));
    int x, y;
    REP(i, n) {
      cin >> x >> y;
      sum[--x][--y] = 1;
    }
    int s, t;
    cin >> s >> t;
    REP(i, w) REP(j, h) {
      if(j == 0) continue;
      sum[i][j] += sum[i][j-1];
    }
    int res = 0;
    REP(i, w-s+1) REP(j, h-t+1){
      int tmp = 0;
      REP(k, s) tmp += sum[i+k][j+t-1] - (j==0 ? 0 : sum[i+k][j-1]);
      res = max(tmp, res);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3124
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;

}

vector<ll> a;
vector<vector<ll>> dp(401, vector<ll>(401, 0));

ll solve(ll l, ll r) {
	if (l == r) {
		return 0;
	}

	if (dp[l][r] > 0) {
		return dp[l][r];
	}

	ll res = INF;

	FOR(i, l, r) {
		res = min(res, solve(l, i) + solve(i + 1, r) + a[r + 1] - a[l]);
	}
	dp[l][r] = res;

	return res;
}

signed main() {
	ll n, x;

	cin >> n;

	a.push_back(0);

	REP(i, n) {
		cin >> x;
		a.push_back(x);
	}

	FOR(i, 1, n + 1) {
		a[i] += a[i - 1];
	}

	cout << solve(0, n - 1) << endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <iomanip>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdlib>

using namespace std;

#define PB push_back
#define MP make_pair
#define L first
#define R second

typedef pair<int, int> pie;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    int ans = 0;
    cin >> n;
    while (n--) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10;
int a[N];
ll ans;
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int t1=0,t2=0;int temp=a[n],cnt=0;
    for(int i=n;i>=1;i--){
        if(t1!=0&&t2!=0)break;
        if(a[i]==temp){
            cnt++;
        }
        else{
            if(cnt>=4){
                if(t1==0)
                t1=t2=temp;
                else t2=temp;
            }else if(cnt>=2){
                if(t1==0)t1=temp;
                else t2=temp;
            }
            temp=a[i];cnt=1;
        }
    }
    if(cnt>=4){
        if(t1==0)
        t1=t2=temp;
        else t2=temp;
    }else if(cnt>=2){
        if(t1==0)t1=temp;
        else t2=temp;
    }
    ans=1ll*t1*t2;
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<cstdio>
#include<ctime>
#include<iostream>
using namespace std;
const int md=924844033;
long long dp[2010];
int a[2010];
bool vis[2010];
int f[2010][2010][2];
long long fac[2010];
int n,k;
int main(){
//	freopen("c.in","r",stdin);
//	freopen("c.out","w",stdout);
	scanf("%d%d",&n,&k);
	fac[0]=1;
	for(int i=1;i<=2000;i++)
		fac[i]=fac[i-1]*i%md;
	int p,cnt1,cnt2;
	f[1][0][0]=1;
	f[1][1][1]=1;
	for(int i=2;i<=2000;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(j>0)
				f[i][j][1]=f[i-1][j-1][0]%md;
			f[i][j][0]=(f[i-1][j][1]+f[i-1][j][0])%md;
		}
	}
	dp[0]=1;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			cnt1=cnt2=0;
			p=i;
			vis[p]=1;
			if(i-k>0) cnt1++;
			while(p+2*k<=n){
				cnt1++,cnt2++;
				p=p+k*2;
				vis[p]=1;
			}
			if(p+k<=n) cnt2++;
			cnt1=cnt1+cnt2;
			for(int j=0;j<=cnt1;j++)
				a[j]=(f[cnt1][j][1]+f[cnt1][j][0])%md;
			for(int j=n;j>=0;j--)
				for(int s=1;s<=cnt1&&s<=j;s++)
					dp[j]=(dp[j]+dp[j-s]*a[s])%md;
		}
	}
	long long ans=0;
	for(int i=0;i<=n;i++)
		ans=(ans+fac[n-i]*dp[i]%md*((i&1)?-1:1)+md)%md;
	printf("%lld\n",ans);
	return 0;
}


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

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

using ll = long long;


int main(){
  int N,X; cin >> N >> X;
  vector<int> L(N);
  rep(i,N) cin >> L[i];
  int D = 0;
  int cnt = 1;
  rep(i,N){
    D += L[i];
    if(D > X) break;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
use proconio::input;

#[derive(Clone)]
struct ProbRecord {
    got_ac: bool,
    num_was: i32,
}

fn main() {
    input!{
        n: i32,
        m: i32,
    }

    let mut records = vec![ProbRecord{ got_ac: false, num_was: 0 }; n as usize];
    let mut num_ac = 0;
    let mut num_penalties = 0;

    for _ in 0..m {
        input! {
            p: i32,
            s: String,
        }
        if s == "AC" {
            if !records[(p - 1) as usize].got_ac {
                records[(p - 1) as usize].got_ac = true;
                num_ac += 1;
                num_penalties += records[(p - 1) as usize].num_was;
            }
        } else if s == "WA" {
            records[(p - 1) as usize].num_was += 1;
        } else {
            panic!("Unexpected string");
        }
    }

    println!("{} {}", num_ac, num_penalties);
}


Measured memory_bytes: 3508
def g;gets.split.map &:to_i;end
while(n,m=g)[0]>0
e=[c=(0..m).map{|i|([0]+[1e4]*m).rotate -i},c.map{|i|i.dup}]
n.times{a,b,*c=g;i=-1;e.map{|h|h[a][b]=h[b][a]=c[i+=1]}}
r=1..m
r.each{|k|r.each{|i|(i+1..m).each{|j|e.map{|h|h[i][j]>(z=h[i][k]+h[k][j])&&h[i][j]=h[j][i]=z}}}}
g[0].times{*d,c=g;a,b=d.sort;p e[c][a][b]}
end

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

int n;

signed main(){
  
  cin>>n;

  int num = 1;
  int ans = 0;
  
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if( a == num ){
      ans++;
      num++;
    }
  }

  ans = n - ans;

  if( ans == n ) cout<<-1<<endl;
  else cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;cin>>s;
    string a="dream",b="dreamer",c="erase",d="eraser";
    bool flag;
    while(true){
        flag=1;
        if(s.size()>=7){
            if(s.substr(s.size()-7)==b){
                s=s.substr(0,s.size()-7);
                flag=0;
            }
        }
        if(s.size()>=6){
            if(s.substr(s.size()-6)==d){
                s=s.substr(0,s.size()-6);
                flag=0;
            }
        }
        if(s.size()>=5){
            if(s.substr(s.size()-5)==a or s.substr(s.size()-5)==c){
                s=s.substr(0,s.size()-5);
                flag=0;
            }
        }
        if(flag)break;
    }
    if(!s.size())cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 512
{-# LANGUAGE CPP #-}
module Main where

import qualified Data.Vector.Unboxed as V 
import qualified Data.Map.Strict as M
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.Char
import qualified Data.List as L

dump :: (Show a) => a -> IO()
#if __GLASGOW_HASKELL__ >= 800
dump x = print x
#else
dump _ = pure ()
#endif

-- "101010" -> [1,0,1,0,1,0]
readToList :: String -> [Int]
readToList [] = []
readToList (x:xs) = read [x] : readToList xs

 
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

-- "10 10 10" -> [10, 10, 10]
getlist :: IO [Int]
getlist = (fmap (read . BS.unpack) . BS.words) <$> BS.getLine

-- "10 10 10" -> [10, 10, 10]
getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readmat :: Int -> IO [[Int]]
readmat rows = replicateM rows getlist

newtype UF a = UF (M.Map a a) deriving (Show) -- Map node parent

makeuf :: Int -> UF Int
makeuf n = let m = M.fromList $ zip [0..n] [0..n]
                in UF m

union :: (Eq a, Ord a) => a -> a -> UF a -> UF a
union l r uf@(UF m) = let lp = find l uf
                          rp = find r uf
                      in if lp == rp
                         then uf
                         else if size l uf < size r uf
                              then UF $ M.update (const $ Just rp) lp m
                              else UF $ M.update (const $ Just lp) rp m

find :: (Eq a, Ord a) => a -> UF a -> a
find x uf@(UF m) = let px = m M.! x
                in if px == x
                   then px
                   else find px uf -- TODO 貼り直し

size :: (Eq a, Ord a) => a -> UF a -> Int
size x (UF m) = M.size $ M.filter (\par -> par==x) m

genbit :: Int -> [[Int]]
genbit 0 = []
genbit 1 = [[0],[1]]
genbit len = do
  x <- [0,1]
  map (x:) $ genbit (len-1)

base :: Int
base = 10 ^ 9 + 7

forn :: (Num a, Enum a, Monad m) => a -> (a -> m b) -> m [b]
forn x = forM [0..(x-1)]

count :: (Eq a) => a -> [a] -> Int
count y = length . filter (== y)

main :: IO()
main = do
  a <- getlist
  b <- getlist
  print $ head $ [1..3] L.\\ (concat [a, b])


Measured memory_bytes: 508
#include<stdio.h>
int main(){
	int a,b,c,num=0,a1,b1,c1,f=1;
	scanf("%d%d%d",&a,&b,&c);
	while(a%2==0 && b%2==0 && c%2==0){
		a1=a/2;
		b1=b/2;
		c1=c/2;
		a=b1+c1;
		b=a1+c1;
		c=a1+b1;
		num++;
		if(a==b && b==c){
			f=0;
			printf("-1\n");
			break;
		}
	}
	if(f==1)printf("%d\n",num);
} 

Measured memory_bytes: 128
x,y = map(int,input().split())
if x == y:
    ans = 0
elif 0 <= x < y:
    ans = y - x
elif 0 <= y < x:
    if y == 0:
        ans = 1 + x 
    else:
        ans = 1 - y + x + 1
elif x < y <= 0:
    ans = y - x
elif y < x <= 0:
    if x == 0:
        ans = - y + 1
    else:
        ans = 1 - y + x + 1
elif x < y:
    if abs(x) <= abs(y):
        ans = 1 + y + x
    elif abs(x) > abs(y):
        ans = - y - x + 1
elif y < x:
    if abs(x) <= abs(y):
        ans = - y - x + 1
    elif abs(x) > abs(y):
        ans = 1 + y + x
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <ctype.h>
  
int main()
{
    int i;
  
    int sum = 0;
    char W[11], T[1001];
  
    scanf("%s", W);
    for( i = 0; W[i]; ++i ) W[i] = tolower(W[i]);
    while( 1 ){
        scanf("%s", T);
        if( strcmp("END_OF_TEXT", T) == 0 ) break;
        for( i = 0; T[i]; ++i ) T[i] = tolower(T[i]);
        if( strcmp(W, T) == 0 ) ++sum;
    }
  
    printf("%d\n", sum);
  
  }

Measured memory_bytes: 2680
//GridRepainting2.cpp (C)
#include <iostream>
#include <string>
using namespace std;

int main(){
  int H, W,x,y;
  int dx[] = {1,0,-1,0};
  int dy[] = {0,1,0,-1};
  string S[60];
  bool flag = false;
  bool Ans;
  cin >> H >> W;
  for(int i = 0; i < H; i++) cin >> S[i];
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(S[i][j] == '#'){
        for(int k = 0; k < 4; k++){
          x = i + dx[k];
          y = j + dy[k];
          if(x>=0&&x<H&&y>=0&&y<W&&S[x][y]=='#') flag = true;
        }
        if(!flag){
          Ans = false;
          break;
        }
        flag = false;
        Ans = true;
      }
    }
    if(!Ans) break;
  }
  if(Ans) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 256
N,M,Q=map(int,input().split())
L,R=0,0
A=[[0]*(N+1) for i in range(N+1)]
for i in range(M):
  L,R=map(int,input().split())
  A[L][R]+=1
B=[[0]*(N+1) for i in range(N+1)]
for i in range(N):
  for j in range(N):
    B[i+1][j+1]=B[i+1][j]+B[i][j+1]-B[i][j]+A[i+1][j+1]
for i in range(Q):
  L,R=map(int,input().split())
  print(B[N][R]-B[L-1][R])

Measured memory_bytes: 79256
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
using namespace std;

ll N,a,b,c,d,e;
string S;
int main()
{
    cin >> S;
    if(S == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define r second
#define l first
#define f first
#define s second
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 3e3 + 10;

int N;
vector<int> V;

ll DPf[MAX][MAX][2];
ll DPs[MAX][MAX][2];

pii solve(int l, int r, bool p){
	if(DPf[l][r][p] != -1) return {DPf[l][r][p],DPs[l][r][p]};

	pii ans;

	if(l == r){
		if(p) return {V[l],0};
		else return {0,V[l]};
	}

	if(p){
		if(V[l] + solve(l+1,r,!p).f > V[r] + solve(l,r-1,!p).f){
			ans.l = V[l] + solve(l+1,r,!p).f;
			ans.r = solve(l+1,r,!p).s;
		}
		else{
			ans.l = V[r] + solve(l,r-1,!p).f;
			ans.r = solve(l,r-1,!p).s;
		}
	}
	else{
		if(V[l] + solve(l+1,r,!p).s > V[r] + solve(l,r-1,!p).s){
			ans.r = V[l] + solve(l+1,r,!p).s;
			ans.l = solve(l+1,r,!p).f;
		}
		else{
			ans.r = V[r] + solve(l,r-1,!p).s;
			ans.l = solve(l,r-1,!p).f;
		}
	}

	DPf[l][r][p] = ans.f;
	DPs[l][r][p] = ans.s;

	return ans;
}

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

	cin >> N;

	memset(DPf, -1, sizeof DPf);
	memset(DPs, -1, sizeof DPs);
	V.resize(N);

	for(auto &x : V) cin >> x;

	pii ans = solve(0,N-1,1);

	cout << ans.l - ans.r << endl;

	return 0;
}


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


int main(){
   int a,b;cin>>a>>b;
   if(a+b==3)cout<<3<<endl;
   else if(a+b==4)cout<<2<<endl;
   else cout<<1<<endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    Vec a(n);
    rep(i,n)cin>>a[i];

    ll ans=0;

    ll j = 0;
    ll x = 0;
    rep(i,n){
        while (((x+ a[j]) == (x^a[j])) && j < n){
            x += a[j];
            j++;
        }
        ans += j-i+1;
        if(j<i){
            j++;
        }else{
            x -= a[i];
        }
    }


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


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int power(int n)
{
    int num=1;
    for(int i=0;i<n;i++)num*=10;
    return num;
}
int serch(int sum,int n)
{
    if(sum>21)return 0;
    else if(n==0)return sum;
    else return max(serch(sum+11,n-1),serch(sum+1,n-1));
}
int main()
{
    string str;
    while(getline(cin,str)){
        if(str[0]=='0')break;
        int card[1000]={},co=0,point=0;
        for(int i=0;;i++){
            if(str[i]==' '||str[i]=='\0'){
                for(int j=point;j<i;j++)card[co]+=(str[j]-'0')*power(i-1-j);
                co++;point=i+1;
            }
            if(str[i]=='\0')break;
        }
        int cou=0,sum=0;
        for(int i=0;i<co;i++){
            if(card[i]==1)cou++;
            else if(card[i]<10)sum+=card[i];
            else sum+=10;
        }
        cout<<serch(sum,cou)<<endl;
    }
}

Measured memory_bytes: 1180