akhauriyash/Code-Regression huggingface dataset:
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*; 
import java.util.*;
import java.util.regex.*;

/*
			  br = new BufferedReader(new FileReader("input.txt"));
			  pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
			  br = new BufferedReader(new InputStreamReader(System.in));
			  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		//int qq = 1;
		int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++) {
			ArrayList<Integer> l = new ArrayList<>();
			for(int i = 2; i <= 30000; i++) {
				if(i%2!=0 && i%3!=0 && i%5!=0) continue;
				l.add(i);
			}
			int n = readInt();
			while(true) {
				long gcd = 0;
				Collections.shuffle(l);
				long ans = 0;
				for(int i = 0; i < n; i++) {
					ans += l.get(i);
					gcd = gcd(gcd, l.get(i));
				}
				if(gcd == 1 && ans%30==0) break;
			}
			for(int i = 0; i < n; i++) {
				pw.print(l.get(i));
				if(i == n-1) pw.println();
				else pw.print(" ");
			}
		}
		exitImmediately();
	}

	public static long gcd(long a, long b) {
		if(a==0)return b;
		if(b==0)return a;
		return gcd(b, a%b);
	}
	
	private static void exitImmediately() {
		pw.close();
		System.exit(0);
	}

	private static long readLong() throws IOException {
		return Long.parseLong(readToken());
	}

	private static double readDouble() throws IOException {
		return Double.parseDouble(readToken());
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(readToken());
	}

	private static String readLine() throws IOException  {
		String s = br.readLine();
		if(s == null) {
			exitImmediately();
		}
		st = null;
		return s;
	}

	private static String readToken() throws IOException  {
		while(st == null || !st.hasMoreTokens())  {
			st = new StringTokenizer(readLine().trim());
		}
		return st.nextToken();
	}
}

Measured memory_bytes: 25548
#include <iostream>
#include<algorithm>
#include <vector>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define max(x,y) (((x)>(y)) ? x:y)
#define min(x,y) (((x)<(y)) ? x:y)
#define FOR(a) for(int i=0;i<a;i++)
#define ender {return 0;}
#define tosasuretu(a) (a*(a+1)/2)
inline ll kaizyo(ll);
ll gcd(ll, ll);
ll combination(ll, ll);
int main() {
	int n;
	float a[100];
	cin >> n;
	float sum = 0;
	FOR(n) {
		cin >> a[i];
		sum += a[i];
	}
	sum /= n;
	float Min = 1000;
	int MinNum;
	FOR(n) {
		a[i] = a[i] - sum;
		if (Min > abs(a[i])) {
			MinNum = i;
			Min = abs(a[i]);
		}
	}
	cout << MinNum;

	return 0;
}


inline ll kaizyo(ll x) {
	long ans = 1;
	for (int z = 0; z < x; z++) {
		ans *= (x - z);
	}
	return ans;
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

Measured memory_bytes: 384
N,X = gets.chomp.split(" ").map(&:to_i)
arr = gets.chomp.split(" ").map(&:to_i)

bound = 0
cnt = 0
arr.unshift 0
arr.each do |l|
    bound +=l
    if bound <= X
        cnt +=1
    else
        break
    end
    
end

puts cnt

Measured memory_bytes: 1916
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		char ans='A';
		for(; sc.hasNext();){
			String s=sc.nextLine();
			if(s.charAt(0)==ans)
				ans=s.charAt(2);
			else if(s.charAt(2)==ans)
				ans=s.charAt(0);
		}
		println(""+ans);
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

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

int main() {
 int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  ll ans=0;
  for(int i=0;i<k;i++){
    ans=ans+a.at(i);
  }
  cout << ans << endl;
}



Measured memory_bytes: 3628
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=[LI() for _ in range(n)]

  l=sorted(l,key=lambda x:x[2],reverse=True)

  ans=[]
  for Cx in range(101):
    for Cy in range(101):
      H=l[0][2]+abs(l[0][0]-Cx)+abs(l[0][1]-Cy)
      f=True
      for x,y,h in l[1:]:
        if h!=max(H-abs(x-Cx)-abs(y-Cy),0):
          f=False
          break
      if f:
        ans.append(str(Cx)+' '+str(Cy)+' '+str(H))
  if len(ans)==1:
    return ans[0]

# main()
print(main())


Measured memory_bytes: 6484
import itertools
n,m,q = map(int,input().split())
a = [];b = []; c = []; d = []
for i in range(q):
    u,x,y,z = map(int,input().split())
    a.append(u)
    b.append(x)
    c.append(y)
    d.append(z)

ans = 0
for A in itertools.combinations_with_replacement(range(1,m+1),n):
    score = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            score += d[i]
    ans = max(score,ans)
print(ans)



Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int INF=-2000000000;
int main() {
  int n;
  cin >> n;
  vector<P> x(n);
  for(int i=0; i<n; i++){
    int xx,l;
    cin >> xx >> l;
    x[i]=P(xx+l,xx-l);
  }
  sort(x.begin(),x.end());
  int end=x[0].first;
  ll cnt=1;
  for(int i=1; i<n; i++){
    if(end<=x[i].second){
      end=x[i].first;
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  const int m = getInt();
  vector<vector<int> > v(n);
  vector<int> in(n);
  vector<int> ans(n);

  REP(i,m){
    const int a = getInt() - 1;
    const int b = getInt() - 1;
    v[a].push_back(b);
    in[b]++;
  }

  queue<int> q;
  REP(i,n) if(in[i] == 0) q.push(i);

  while(q.size()){
    const int pos = q.front(); q.pop();

    for(const int next : v[pos]){
      ans[next] = max(ans[next], ans[pos] + 1);
      if(--in[next] == 0) q.push(next);
    }
  }

  printf("%d\n", *max_element(ans.begin(), ans.end()));

  return 0;
}

Measured memory_bytes: 6528
n = int(input())
H = list(map(int, input().split()))

# シミュレーションで求められる
# 目標地点からさかのぼる

ans = 0
for _ in range(max(H)):
    flg = False
    for i in range(n):
        if H[i] > 0:
            H[i] -= 1
            if not flg:
                ans += 1
                flg = True
        elif H[i] == 0:
            flg = False

print(ans)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define p(S) cout<<(S)<<endl
using namespace std;

vector<string> ans;
string str;
bool used[26];

void dfs(string s){
	unsigned int num=s.size();
	if(num == str.size()){
		ans.push_back(s);
		return;
	}
	if(str[num]=='a'|| used[str[num]-'a']){
		dfs(s+str[num]);
	}
	if(str[num]!='z' && !used[str[num]-'a'+1]){
		used[str[num]-'a'+1]=true;
		dfs(s+(char)(str[num]+1));
		used[str[num]-'a'+1]=false;
	}
	return;
}
int main(){
	while(cin>>str){
                if(str=="#") break;
		ans.clear();
		REP(i,0,26) used[i]=false;
		dfs("");
		p(ans.size());
		REP(i,0,min<int>(ans.size(),5)){
			p(ans[i]);
		}
		REP(i,max<int>(ans.size()-5,5),ans.size()){
			p(ans[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 4312
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();
        int[][] a = new int[H][W];
        for (int i=0;i<H;i++) {
            for (int j=0;j<W;j++) {
                a[i][j] = Integer.parseInt(sc.next());
            }
        }
        ArrayList<Integer> y_b = new ArrayList<Integer>();
        ArrayList<Integer> x_b = new ArrayList<Integer>();
        ArrayList<Integer> y_a = new ArrayList<Integer>();
        ArrayList<Integer> x_a = new ArrayList<Integer>();
        int cnt = 0;
        for (int i=0;i<H;i++) {
            for (int j=0;j<W;j++) {
                if (i==H-1 && j==W-1) {
                    continue;
                }
                if (a[i][j]%2==1 && j==W-1) {
                    y_b.add(i);
                    x_b.add(j);
                    y_a.add(i+1);
                    a[i+1][j]++;
                    x_a.add(j);
                    cnt++;
                } else if (a[i][j]%2==1) {
                    y_b.add(i);
                    x_b.add(j);
                    y_a.add(i);
                    x_a.add(j+1);
                    a[i][j+1]++;
                    cnt++;
                }
            }
        }
        System.out.println(cnt);
        for (int i=0;i<cnt;i++) {
            System.out.println((y_b.get(i)+1) + " " + (x_b.get(i)+1) + " " + (y_a.get(i)+1) + " " + (x_a.get(i)+1));
        }
        // System.out.println(Arrays.deepToString(a));
    }
}

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

using namespace std;

//#define int long long

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

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)

#define rep(i,n) for_(i,0,n)
#define rrep(i,n) rfor_(i,0,n)

#define pb push_back
//#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

int if_bomb(char c) {
    if (c == '#') {
        return 1;
    } else {
        return 0;
    }
}

int main(int argc, char const* argv[])
{
    vector<vector<char>> field;
    int h, w;

    cin >> h >> w;

    for (int i = 0; i < h; i++) {
        vector<char> buf;
        for (int j = 0; j < w; j++) {
            char c;
            cin >> c;;
            buf.push_back(c);
        }
        field.push_back(buf);
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (field[i][j] == '#') {
                cout << '#';
            } else {
                int result = 0;
                for (int k = -1; k <= 1; k++) {
                    for (int l = -1; l <= 1; l++) {
                        if ((k == 0 && l == 0) || k + i < 0 || l + j < 0 || k + i >= h || l + j >= w) continue;
                        else result += if_bomb(field[i + k][j + l]);
                    }
                }
                cout << result;
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
 
    long ans = 0;
 
    //i について全探索する
    for (int i = 0; i < N; i++)
    {
        //A[i+1] ... A[N] の値を更新する
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
}

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

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


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int N,M,C;  cin>>N>>M>>C;
    int B[M],A[N][M];
    int count=0;;
    
    for(int i=0;i<M;i++)    cin>>B[i];
    
    for(int i=0;i<N;i++){
        int sum=0;
        for(int j=0;j<M;j++){
            cin>>A[i][j];
            sum+=A[i][j]*B[j];
        }
        if(sum+C>0) count++;
    }
    
    cout<<count<<endl;
}


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

int main()
{
    int n, tp = 0, hp = 0;
    cin >> n;
    for (int a = 0; a < n; a++)
    {
        string t, h;
        cin >> t;
        cin >> h;
        if (t < h)hp += 3;
        else if (t>h)tp += 3;
        else tp += 1, hp += 1;
    }
    cout << tp << " " << hp << endl;
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

ll modpow(ll a,ll b,ll m){
	ll res = 1 ;
	while(b>0){
		if(b&1) res = res*a%m ;
		b >>= 1 ;
		a = a*a%m ;
	}
	return res ;
}

int main(){
	ll n ; cin >> n ;
	string s ; cin >> s ;
	ll a=0,b=0 ;
	ll cnt = 0 ;
	for(int i=0;i<n;i++)  cnt += (s.at(i)=='1') ;
	if(cnt==0){
		for(int i=0;i<n;i++) cout << 1 << endl ;
		return 0 ;
	}
	if(cnt==1){
		for(int i=0;i<n;i++){
			if(s.at(i)=='1') cout << 0 << endl ;
			else if(i==n-1) cout << 2 << endl ;
			else cout << 1 << endl ;
		}
		return 0 ;
	}
	for(int i=0;i<n;i++){
		if(s.at(i)=='1'){
			a += modpow(2,n-i-1,cnt+1) ;
			b += modpow(2,n-i-1,cnt-1) ;
		}
	}
	for(int i=0;i<n;i++){
		ll tmp,ans=1,sub=0 ;
		if(s.at(i)=='1'){
			tmp = (b-modpow(2,n-i-1,cnt-1)+cnt-1)%(cnt-1) ;
			while(tmp){
				ans++ ;
				sub = 0 ;
				for(int j=0;j<64;j++) sub += (tmp>>j&1) ;
				tmp = tmp%sub ;
			}
		}else{
			tmp = (a+modpow(2,n-i-1,cnt+1))%(cnt+1) ;
			while(tmp){
				ans++ ;
				sub = 0 ;
				for(int j=0;j<64;j++) sub += (tmp>>j&1) ;
				tmp = tmp%sub ;
			}
		}
		cout << ans << endl ;
	}
}

Measured memory_bytes: 3756
using System;
using System.Collections.Generic;
class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int a = 0, b = 0, ab = 0;
            bool allBXA = true;
            for (int i=0; i<n; i++)
            {
                string s = Console.ReadLine();
                if (s[0] == 'B')
                {
                    b++;
                    if (s[s.Length - 1] != 'A') allBXA = false;
                }
                if (s[s.Length - 1] == 'A')
                {
                    a++;
                    if (s[0] != 'B') allBXA = false;
                }
                for (int j=0; j < s.Length - 1; j++)
                {
                    if (s[j] == 'A' && s[j+1] == 'B') ab++;
                }
            }
            if (a == 0 && b == 0) allBXA = false;
            ab += Math.Min(a, b);
            if (allBXA) ab--;
            Console.WriteLine(ab);
            
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;

ll maxs (ll x, ll y){
  if (x > y) return x;
  else return y;
}

ll mins (ll x, ll y){
  if (x > y) return y;
  else return x;
}

int main(){
  ll H, W;
  cin >> H >> W;
  if (H % 3 && W % 3){
    ll ans = INF;
    for (ll h = 1; h < H; h++) {
      ll s1 = h * W;
      ll w = W/2;
      ll s2 = (H - h) * w;
      ll s3 = (H-h)*(W-w);
      ll s_max = maxs(s1, maxs(s2, s3));
      ll s_min = mins(s1, mins(s2, s3));
      ll sa = abs(s_max - s_min);
      ans = mins(ans, sa);
    }
    for (ll h = 1; h < H; h++) {
      ll s1 = h * W;
      ll s2, s3;
      if ((H-h) % 2 == 0) {  
        s2 = ((H - h) / 2) * W;
        s3 = s2;
      } else {
        s2 = ((H - h) / 2) * W;
        s3 = ((H - h) / 2 + 1) * W;
      }
      ll s_max = maxs(s1, maxs(s2, s3));
      ll s_min = mins(s1, mins(s2, s3));
      ll sa = abs(s_max - s_min);
      ans = mins(ans, sa);
    }
    swap(H, W);
    for (ll h = 1; h < H; h++) {
      ll s1 = h * W;
      ll w = W/2;
      ll s2 = (H - h) * w;
      ll s3 = (H-h)*(W-w);
      ll s_max = maxs(s1, maxs(s2, s3));
      ll s_min = mins(s1, mins(s2, s3));
      ll sa = abs(s_max - s_min);
      ans = mins(ans, sa);
    }
    for (ll h = 1; h < H; h++) {
      ll s1 = h * W;
      ll s2, s3;
      if ((H-h) % 2 == 0) {  
        s2 = ((H - h) / 2) * W;
        s3 = s2;
      } else {
        s2 = ((H - h) / 2) * W;
        s3 = ((H - h) / 2 + 1) * W;
      }
      ll s_max = maxs(s1, maxs(s2, s3));
      ll s_min = mins(s1, mins(s2, s3));
      ll sa = abs(s_max - s_min);
      ans = mins(ans, sa);
    }  
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int prime(int num);
int data[1000000];

int main(void){

	int n,i,count;
	count=0;
	for(i=2;i<1000000;i++){
		count=count+prime(i);
		data[i]=count;
	}
	while(scanf("%d",&n)!=EOF){
		printf("%d\n",data[n]);
	}
	return 0;
}

int prime(int num){
	int i;
	if(num==2){return 1;}
	for(i=2;i<(int)sqrt(num)+1;i++){
		if(num % i==0){return 0;}
	}
	return 1;
}

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



int main() {
  int n;
  int dp[31];
  dp[1] = 1;
  dp[2] = 2;
  dp[3] = 4;
  for ( int i = 4; i <= 30; i++ ) dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
 
  while ( cin >> n, n ) {
    cout << dp[n]/10/365 + 1 << endl;
  }


  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pi 3.141592653
#define pb push_back
#define pp pop_back
#define mp make_pair
#define in insert
#define ff first
#define ss second
#define mod 1000000007
#define rep(i,n) for(int i = 0 ; i<n ; i++)
#define repr(i,n) for(int i = n-1 ; i>=0 ; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define SORT(v) sort(v.begin(),v.end())
void solve();
ll gc(ll a,ll b)
{
    if(b==0) return a;
    return gc(b,a%b);
}
signed main()
{
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}
void solve() 
{
    double h,a;
    cin>>h>>a;
    cout<<ceil(h/a)<<endl;
}

Measured memory_bytes: 256
//12252024832524
#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; 

typedef long long LL;
const int MAXN = 100005;
int n,tot;
int a[3];
int s[3][2],cz[MAXN];
char ans[MAXN];
string opt[3] = {"AB","AC","BC"};

LL Read()
{
	LL x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
void Put1(LL x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
void Put(LL x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x);
	if(c >= 0) putchar(c);
}
template <typename T>T Max(T x,T y){return x > y ? x : y;}
template <typename T>T Min(T x,T y){return x < y ? x : y;}
template <typename T>T Abs(T x){return x < 0 ? -x : x;}

void pre()
{
	s[0][0] = 0;
	s[0][1] = 1;
	s[1][0] = 0;
	s[1][1] = 2;
	s[2][0] = 1;
	s[2][1] = 2;
}
int whi()
{
	string x;
	cin >> x;
	for(int j = 0;j < 3;++ j) if(x == opt[j]) return j;
}
void solve(int x,int y)
{
	if(a[x] > a[y]) a[x]--,a[y]++,printf("%c\n",y+'A');
	else a[x]++,a[y]--,printf("%c\n",x+'A');
}
int num()
{
	int ret = 0;
	for(int i = 0;i < 3;++ i) if(a[i])ret++;
	return ret;
}
void ed(int x)
{
	for(int i = x;i <= n;++ i) solve(s[cz[i]][0],s[cz[i]][1]);
}
void ed2(int x)
{
	for(int i = x;i <= n;++ i)
	{
		int A = s[cz[i]][0],B = s[cz[i]][1];
		if(a[A] > 1 || a[B] > 1 || a[A] != a[B]) solve(A,B);
		else
		{
			bool stp[3] = {};
			if(i == n) solve(A,B);
			else
			{
				stp[s[cz[i+1]][0]] = 1;
				stp[s[cz[i+1]][1]] = 1;
				if(stp[A]) a[A]++,a[B]--,printf("%c\n",A+'A');
				else a[A]--,a[B]++,printf("%c\n",B+'A');
			}
		}
		if(num() == 3) 
		{
			ed(i+1);
			return;
		}
	}
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	pre();
	n = Read();
	for(int i = 0;i < 3;++ i)
		a[i] = Read();
	for(int i = 1;i <= n;++ i) cz[i] = whi();
	if(num() == 3)
	{
		printf("Yes\n");
		ed(1);
	}
	else if(num() == 2)
	{
		printf("Yes\n");
		ed2(1);
	}
	else if(num() == 1)
	{
		for(int i = 1;i <= n;++ i)
		{
			int A = s[cz[i]][0],B = s[cz[i]][1];
			if(a[B]) 
			{
				a[A]++;
				a[B]--;
				ans[i] = A + 'A';
			}
			else if(a[A])
			{
				a[A]--;
				a[B]++;
				ans[i] = B + 'A';
			}
			else 
			{
				printf("No\n");
				return 0;
			}
			if(num() == 2)
			{
				printf("Yes\n");
				for(int j = 1;j <= i;++ j) printf("%c\n",ans[i]);
				ed2(i+1);
				return 0;
			}
		}
		printf("Yes\n");
		for(int i = 1;i <= n;++ i) printf("%c\n",ans[i]);
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 3672
n = int(input())
vs = []
for _ in range(n):
    vs.append(tuple(map(int, input().split())))

dp = [[0 for _ in range(3)] for _ in range(n)]
dp[0] = [vs[0][0], vs[0][1], vs[0][2]]

for i in range(1, n):
    dp[i][0] = vs[i][0] + max(dp[i-1][1], dp[i-1][2])
    dp[i][1] = vs[i][1] + max(dp[i-1][2], dp[i-1][0])
    dp[i][2] = vs[i][2] + max(dp[i-1][0], dp[i-1][1])

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

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

int main()
{
    int n, m;
    string s, t, u;

    while( cin >> n )
    {
        s = "I";
        u = "";
        if( !n )
            break;

        for( int i = 0; i < n; i++ )
            s += "OI";

        cin >> m;

        cin >> t;
        
        int cnt = 0, i = 0;
        while( i < m )
        {
            u = t.substr( i, s.size() );
            if( s == u )
                cnt++;
            i++;
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll n,r;
  cin >> n >> r;

  cout << r + 100*max((10-n),0LL) << endl;
  
  return 0;


}


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

int main() {
	string s;
	cin >> s;
	for (int i = 0;i < s.size();++i) {
		if (s[i] == ',') {
			s[i] = ' ';
		}
	}
	cout << s << endl;
	return 0;
}

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

int N(char c) {
  if(c=='A') return 11;
  if(isalpha(c)) return 10;
  return c-'0';
}

int main() {
  int T;
  cin >> T;
  while(T--) {
    vector<int> v;
    int sum=0;
    char x;
    cin >> x;
    v.push_back(N(x));
    sum+=N(x);
    int a[9];
    for(int i=0;i<9;i++) {
      char x;
      cin >> x;
      a[i]=N(x);
    }
    if(sum+a[0]==21) {
      cout << "blackjack" << endl;
      continue;
    }
    for(int i=0;i<9;i++) {
      int x=a[i];
      v.push_back(x);
      sum+=x;
      while(sum>21) {
        bool f=0;
        for(int j=0;j<v.size();j++) {
          if(v[j]==11) {
            v[j]=1;
            sum-=10;
            f=1;
            break;
          }
        }
        if(!f) break;
      }
      if(sum>17) break;
      bool f=0;
      for(int j=0;j<v.size();j++) {
        if(v[j]==11) f=1;
      }
      if(sum==17&&!f)break; 
    }
    if(sum>21) cout << "bust" << endl;
    else cout << sum << endl;
  }
  return 0;
}


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

int main(){
	int n;
	cin>>n;
	vector<vector<int>> a(n,vector<int>(3));
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	int memo[n+1][3];
	for(int j=0;j<3;j++)
		memo[0][j] = 0;
	for(int i=1;i<n+1;i++){
		for(int j=0;j<3;j++){
			int q1=INT_MIN, q2=INT_MIN, q3=INT_MIN;
			 if(j!=0)
				q1 = a[i-1][0]+memo[i-1][0];
			if(j!=1)
				q2 = a[i-1][1]+memo[i-1][1];
			if(j!=2)
				q3 = a[i-1][2]+memo[i-1][2];
			memo[i][j] = max(q1,max(q2,q3));
		}
	}
	cout<<max(memo[n][0],max(memo[n][1],memo[n][2]));
}

Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void)
{
    int n, m;
    cin >> n >> m;
    string ans = "No";
    if (n == m)
        ans = "Yes";
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cctype>

int main() {
	char ch;

	while (1) {
		scanf("%c", &ch);
		if (isalpha(ch)) {
			if (islower(ch))printf("%c", toupper(ch));
			else printf("%c", tolower(ch));
		}
		else printf("%c", ch);

		if (ch == '\n')break;
	}
	return 0;
}

Measured memory_bytes: 2676
#include <iostream>
/*
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <unordered_map>
*/
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

//const ll nmax=100001;
//const ll inf=1000000000+7;
const ll hmax=500;
const ll wmax=500;
ll a[hmax+1][wmax+1],xy[hmax*wmax+1][4];


int main(){
    ll H,W;
    cin>>H>>W;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin>>a[i][j];
        }
    }
    ll N=0;
    for(int i=1;i<=H;i++){
        if(i%2==1){
            for(int j=1;j<W;j++){
                if(a[i][j]%2==1){
                    xy[N][0]=i;xy[N][1]=j;xy[N][2]=i;xy[N][3]=j+1;
                    N++;
                    a[i][j]--;
                    a[i][j+1]++;
                }
            }
            if(a[i][W]%2==1&&i!=H){
                xy[N][0]=i;xy[N][1]=W;xy[N][2]=i+1;xy[N][3]=W;
                N++;
                a[i][W]--;
                a[i+1][W]++;
            }
        }
        else if(i%2==0){
            for(int j=W;1<j;j--){
                if(a[i][j]%2==1){
                    xy[N][0]=i;xy[N][1]=j;xy[N][2]=i;xy[N][3]=j-1;
                    N++;
                    a[i][j]--;
                    a[i][j-1]++;
                }
            }
            if(a[i][1]%2==1&&i!=H){
                xy[N][0]=i;xy[N][1]=1;xy[N][2]=i+1;xy[N][3]=1;
                N++;
                a[i][1]--;
                a[i+1][1]++;
            }
        }
    }
    cout<<N<<endl;
    for(int i=0;i<N;i++){
        cout<<xy[i][0]<<" "<<xy[i][1]<<" "<<xy[i][2]<<" "<<xy[i][3]<<endl;
    }


    return 0;
}


Measured memory_bytes: 9856
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
    ll N, x, m1, m2;
    cin >> N;

    vector<ll> X, Y;

    for (int i = 0; i < N; i++) {
        cin >> x;
        X.push_back(x);
    }

    Y = X;
    sort(X.begin(), X.end());
    m1 = X[N/2-1];
    m2 = X[N/2];

    for (int i = 0; i < N; i++) {
        if (Y[i] <= m1) {
            cout << m2 << endl;
        } else {
            cout << m1 << endl;
        }
    }
}


Measured memory_bytes: 5872
#include <iostream>
using namespace std;
int main(){
	string s[8];
	for(int i=0;i<8;++i)getline(cin,s[i]);
	cout<<"90\n";
	for(int j=0;j<8;++j){
		for(int i=7;i>=0;--i)cout<<s[i][j];
		cout<<"\n";
	}
	cout<<"180\n";
	for(int j=7;j>=0;--j){
		for(int i=7;i>=0;--i)cout<<s[j][i];
		cout<<"\n";
	}
	cout<<"270\n";
	for(int j=7;j>=0;--j){
		for(int i=0;i<8;++i)cout<<s[i][j];
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 0
import math

def distance(x,y):
    return math.sqrt(x*x+y*y)


n,d = map(int,input().split())
c=0

d_distance = distance(0,d)


for i in range(n):
    x,y = map(int,input().split())
    n_distance = distance(x,y)
    if(n_distance <= d_distance):
        c += 1


print(c)





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

int main(){
  string s;
  cin>>s;
  if(s[1]=='B')cout<<"ARC"<<endl;
  else cout<<"ABC"<<endl;
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    while(true) {
        cin >> n;
        if(n==0)break;
        vector<pair<int,int>> v(n);
        v[0]={0,0};
        int miny=0,maxx=0,may=0,minx=0;
       for(int i=1;i<n;i++){
            int a,b;
            cin>>a>>b;
            int x=v[a].first;
            int y=v[a].second;

            if(b==0){
                v[i].first=x+1;
                v[i].second=y;
            }else if(b==3){
                v[i].first=x;
                v[i].second=y-1;
            }else if(b==2){
                v[i].first=x-1;
                v[i].second=y;
            }else{
                v[i].first=x;
                v[i].second=y+1;
            }

            //cout<<v[i].first<<" "<<v[i].second<<endl;
            if(v[i].first>maxx){
                maxx=v[i].first;
            }else if(v[i].first<minx){
                minx=v[i].first;
            }

            if(v[i].second>may){
                may=v[i].second;
            }else if(v[i].second<miny){
                miny=v[i].second;
            }

        }
       // cout<<minx<<endl;

        cout<<(maxx-minx+1)<<" "<<(may-miny+1)<<endl;

    }




    return 0;
}



Measured memory_bytes: 3096
from collections import deque

H, W = map(int, input().split())
C_h, C_w = map(int, input().split())
D_h, D_w = map(int, input().split())
W_ = W + 4
H_ = H + 4
S = ["#" * W_] * 2 + ["##" + input() + "##" for _ in range(H)] + ["#" * W_] * 2

INF = float('inf')
costs = [[INF] * W_ for _ in range(H_)]
costs[C_h + 1][C_w + 1] = 0
d0 = deque()
d0.append((C_h + 1, C_w + 1, 0))
d1 = deque()
while d0:
    h, w, c = d0.popleft()
    d1.append((h, w, c))
    for i, j in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
        hh = h + i
        ww = w + j
        if S[hh][ww] == '.' and c < costs[hh][ww]:
            costs[hh][ww] = c
            d0.appendleft((hh, ww, c))
    if len(d0) == 0:
        while d1:
            h, w, c = d1.popleft()
            for i in range(5):
                for j in range(5):
                    hh = h + i - 2
                    ww = w + j - 2
                    if S[hh][ww] == '.' and c + 1 < costs[hh][ww]:
                        costs[hh][ww] = c + 1
                        d0.append((hh, ww, c + 1))

if costs[D_h + 1][D_w + 1] != INF:
    ans = costs[D_h + 1][D_w + 1]
else:
    ans = -1
print(ans)


Measured memory_bytes: 106356
import java.util.*;
import java.io.*;
class Main{
	public static void main(String[]args){
		Scanner in=new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out, true);
		String str[] = in.nextLine().split(" ");
		int h = Integer.parseInt(str[0]);
		int w = Integer.parseInt(str[1]);
		int k = Integer.parseInt(str[2]);

		String s[]=new String[6];
		for(int i=0;i<h;i++)
			s[i]=in.nextLine();
		
		int ans = 0;
		for(int a=0;a<(1<<h);a++){
			for(int b=0;b<(1<<w);b++){
				int cnt = 0;
				for(int i=0;i<h;i++){
					for(int j=0;j<w;j++){
						if(nth_bit(a, i) && nth_bit(b, j) && (s[i].charAt(j) == '#'))
							cnt++;
					}
				}
				if(cnt == k)
					ans++;
			}
		}
		out.println(ans);
	}

	public static boolean nth_bit(int num, int n){
		if(((num >> n) & 1) == 1)
			return true;
		return false;
	}
}
// ABC -173


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



int main(){
  int D,E;

  while(true){
    cin >> D >> E;
    if(D + E == 0) break;

    int dis[10000]={};
    for(int h=0;h<=D/2;h++){
      dis[h]=h*h+(D-h)*(D-h);
    }
    
    double ans=-1;
    
    for(int h=0;h<=D/2;h++){
      if(dis[h]==E*E){ans=pow(dis[h],1.0/2); break;}
      if(dis[h+1]<E*E && E*E<dis[h] && h<=D/2-1){
	if(abs(pow(dis[h+1],1.0/2)-E)>abs(pow(dis[h],1.0/2)-E)){ans=pow(dis[h],1.0/2);}
	else{ans=pow(dis[h+1],1.0/2);}
	break;
	  }
    }

    if(dis[0]<E*E){ans=D;}

    if(dis[D/2]>E*E){ans=pow(dis[D/2],1.0/2);}

    cout<<abs(ans-E)<<endl;

  }
  return 0;
}



Measured memory_bytes: 3432
#include <bits/stdc++.h>
#define mp  make_pair
#define ls  (n<<1)
#define rs  (ls|1)
using namespace std;

typedef pair <int,int>  PII;
const int N=100010;
struct edge{int s,t,n;}e[20*N];
int n,m,tot,x[N],y[N],t[N],id[N],h[N],D[N],L[N],c[N],S[N],inS[N],top;
PII a[N];

void addedge(int s,int t){e[++tot]=(edge){s,t,h[s]},h[s]=tot;}

void build(int n,int l,int r)
{
	t[n]=++m;
	if (l==r)  {id[l]=t[n];  return;}
	int mid=(l+r)>>1;
	build(ls,l,mid),build(rs,mid+1,r);
}

void link(int n,int l,int r)
{
	if (l==r)  return;
	int mid=(l+r)>>1;
	addedge(t[n],t[ls]),addedge(t[n],t[rs]);
	link(ls,l,mid),link(rs,mid+1,r);
}

void link(int n,int l,int r,int L,int R,int x)
{
	if ((L<=l)&&(r<=R))  addedge(x,t[n]);
	else
		{
			int mid=(l+r)>>1;
			if (L<=mid)  link(ls,l,mid,L,R,x);
			if (mid<R)  link(rs,mid+1,r,L,R,x);
		}
}

void tarjan(int x)
{
	D[x]=L[x]=++tot,S[++top]=x,inS[x]=1;
	for (int i=h[x],y; y=e[i].t,i; i=e[i].n)
		if (!D[y])  tarjan(y),L[x]=min(L[x],L[y]);
		else  if (inS[y])  L[x]=min(L[x],D[y]);
	if (D[x]==L[x])
		{
			c[x]=++c[0],inS[x]=0;
			for (int y=S[top--]; y!=x; c[y]=c[0],inS[y]=0,y=S[top--]);
		}
}

bool check(int d)
{
	for (int i=1; i<=m; i++)  h[i]=D[i]=L[i]=0;
	d--,tot=0,link(1,1,2*n);
	for (int i=1,l,r,p,q; i<=n; i++)
		{
			addedge(id[p=lower_bound(a+1,a+2*n+1,mp(x[i],i))-a],i+n);
			addedge(id[q=lower_bound(a+1,a+2*n+1,mp(y[i],i+n))-a],i);
			l=lower_bound(a+1,a+2*n+1,mp(x[i]-d,0))-a;
			r=lower_bound(a+1,a+2*n+1,mp(x[i]+d,2*n+1))-a-1;
			if (l<p)  link(1,1,2*n,l,p-1,i);
			if (p<r)  link(1,1,2*n,p+1,r,i);
			l=lower_bound(a+1,a+2*n+1,mp(y[i]-d,0))-a;
			r=lower_bound(a+1,a+2*n+1,mp(y[i]+d,2*n+1))-a-1;
			if (l<q)  link(1,1,2*n,l,q-1,i+n);
			if (q<r)  link(1,1,2*n,q+1,r,i+n);
		}
	tot=0;
	for (int i=1; i<=m; i++)  if (!D[i])  tarjan(i);
	for (int i=1; i<=n; i++)  if (c[i]==c[i+n])  return 0;
	return 1;
}

void work()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		scanf("%d %d",&x[i],&y[i]),a[i]=mp(x[i],i),a[i+n]=mp(y[i],i+n);
	sort(a+1,a+2*n+1);
	m=2*n,build(1,1,2*n);
	int l=0,r=a[2*n].first-a[1].first+1,mid;
	for (; r-l>1; (check(mid=(l+r)>>1)?l:r)=mid);
	printf("%d",l);
}

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


Measured memory_bytes: 15488
aord = ord("a")
s = list(raw_input())
k = int(input())
i = 0

while k > 0 and i < len(s):
	if k >= ord('z') - ord(s[i]) + 1:
		if s[i] != "a":
			k -= ord('z') - ord(s[i]) + 1
			s[i] = "a"

	i += 1
k = k%26
s[len(s)-1] = chr(ord(s[len(s)-1]) + k)
print ''.join(s)

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

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

    string s;
    cin >> s;

    vector<string> A = 
    {
        "AKIHABARA",
        "KIHABARA",
        "AKIHBARA",
        "AKIHABRA",
        "AKIHABAR",
        "KIHBARA",
        "AKIHBRA",
        "AKIHABR",
        "KIHABAR",
        "KIHABRA",
        "AKIHBAR",
        "KIHBRA",
        "AKIHBR",
        "KIHABR",
        "KIHBAR",
        "KIHBR"
    };
    
    REP(i, A.size()){
        if(A[i] == s){
            cout << "YES" << endl; 
            return 0;
        }
    }

    cout << "NO" << endl;
    return 0;

}


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

int main(){
  ll n, m;
  cin >> n >> m;
  
  if(n == m){
    cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}


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

int main()
{
	int r, g, b;
	cin >> r >> g >> b;

	int num = 100 * r + 10 * g + b;

	if (num % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}






Measured memory_bytes: 3628
#include<cstdio>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    a=a*b;
    c=c*d;
    if(a>c)
        printf("%d",a);
    else
        printf("%d",c);
    return 0;
}


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

signed main() {
	int x;
	cin >> x;
	x %= 1000;
	if (x == 0) cout << 0 << endl;
	else cout << 1000 - x << endl;
}

Measured memory_bytes: 3516
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
typedef pair<int, int> P;
int d[55];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> d[i];
	int sum = 0;
	rep(i, n) {
		for (int j = i + 1; j < n; j++)sum += d[i] * d[j];
	}
	cout << sum << endl;
}


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

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;

int X, K, Q, lst = 0, dir = -1;
vi todo;
int a,b,c;

void process(int ti) {
    while (ti) {
        if (ti < abs(todo[todo.size()-1])) {
            int sgn = todo[todo.size()-1] > 0 ? 1 : -1;
            todo[todo.size()-1] -= sgn*ti;
            c += sgn*ti;
            ti = 0;
        } else {
            c += todo[todo.size()-1];
            ti -= abs(todo[todo.size()-1]);
            todo.erase(todo.end()-1);
        }
        if (a+c < 0) {
            if (b+c > 0) a = -c;
            else a = b = c = 0;
        } else if (b+c > X) {
            if (a+c < X) b = X-c;
            else a = b = 0, c = X;
        }
    }
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> X >> K; 
	F0R(i,K) {
	    int r; cin >> r;
	    todo.pb((r-lst)*dir);
	    dir *= -1; lst = r;
	}
	todo.pb(dir*MOD);
	reverse(todo.begin(),todo.end());
	
	a = 0, b = X, c = 0;
	cin >> Q; lst = 0;
	F0R(i,Q) {
	    int t, z; cin >> t >> z;
	    process(t-lst);
	    if (z <= a) cout << a+c << "\n";
	    else if (z <= b) cout << z+c << "\n";
	    else cout << b+c << "\n";
	    lst = t;
	}
}

// read!
// ll vs. int!

Measured memory_bytes: 1784
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N;
    cin >> N;
    ll h[N];
    rep(i, N) cin >> h[i];
    bool is_can = true;
    for(int i = N-1; i > 0; i--){
        if(h[i] - h[i-1] < 0){
            if(h[i] - h[i-1] == -1){
                h[i-1]--;
            }else{
                is_can = false;
                break;
            }
        }
    }
    if(is_can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

// 最大公約数を求める
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}



int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll K;
	cin>>K;
    
    ll ans = 0;
    ll tmp_gcd;
    rep(a,K){
        rep(b,K-a){
            rep(c,K-a-b){
                tmp_gcd = gcd(a+1,a+b+1);
                tmp_gcd = gcd(tmp_gcd,a+b+c+1);
                if(b==0){
                    if(c==0){
                        ans += tmp_gcd;
                    }else{
                        ans += tmp_gcd*3;
                    }
                }else{
                    if(c==0){
                        ans += tmp_gcd*3;
                    }else{
                        ans += tmp_gcd*6;
                    }
                }

            }
        }
    }

    cout<<ans<<"\n";


	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cmath>

using namespace std;

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

int R[16][16][16][300];

int main() {
  rep (a, 16) rep (c, 16) rep (s, 16) {
    R[a][c][s][0] = s;
    rep (i, 256) {
      R[a][c][s][i + 1] = (a * R[a][c][s][i] + c) % 256;
    }
  }
  int n, I[300];
  while (true) {
    cin >> n;
    if (n == 0) break;
    rep (i, n) cin >> I[i];
    int alpha[300] = {}, ra, rc, rs;
    double hh = 0;
    rep (s, 16) rep (a, 16) rep (c, 16) {
      int alpha[300] = {};
      rep (i, n) alpha[(I[i] + R[a][c][s][i + 1]) % 256]++;
      double h = 0;
      rep (i, 300) if (alpha[i] > 0) h -= alpha[i] * log(alpha[i]);
      if (hh > h + 1e-9) {
	hh = h;
	ra = a;
	rc = c;
	rs = s;
      }
    }
    cout << rs << " " << ra << " " << rc << endl;
  }
  return 0;
}

Measured memory_bytes: 6004
import math

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

least_trans = min(A, B, C, D, E)
if least_trans < N:
    ans = math.ceil(N / least_trans) + 4
else:
    ans = 5

print(ans)


Measured memory_bytes: 3060
N,M=map(int,input().split())

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

c=0
ans=0
for i in range(N):
    c=c+A[i]

d=c/(4*M)

for j in range(N):
    if A[j]>=d:
        ans=ans+1
    else:
        pass

if ans>=M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string s,t;
  cin >> s >> t;
  cout << t+s << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);

    if( a==5 && b==5 && c==7){
        printf("YES\n");
    }
    else if(a==7 && b==5 && c==5){
        printf("YES\n");
    }
    else if(a==5 && b==7 && c==5){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }

    return 0;
}

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

const int INF = 1 << 28;

void WarshallFloyd(vector<vector<int>> &D) {
    REP(k, 0, D.size()) {
        REP(i, 0, D.size()) {
            REP(j, 0, D.size()) {
                D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
            }
        }
    }
}

int factorial(int n) {
    int f = 1;
    REP(i, 1, n + 1)
    f *= i;
    return f;
}

int main() {
    int N, M, R; cin >> N >> M >> R;
    
    vector<int> r(R);
    REP(i, 0, R) {
        cin >> r[i];
        r[i]--;
    }

    vector<vector<int>> D(N, vector<int>(N, INF));
    REP(i, 0, M) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        D[a][b] = c;
        D[b][a] = c;
    }
    REP(i, 0, N) D[i][i] = 0;
    WarshallFloyd(D);
    sort(r.begin(), r.end());
    int f = factorial(R), ans = INF;
    REP(i, 0, f) {
        int tmp = 0;
        REP(j, 0, R - 1) {
            tmp += D[r[j]][r[j + 1]];
        }
        ans = min(ans, tmp);
        next_permutation(r.begin(), r.end());
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;

int n;
int a[2 * MaxN + 5];
int main()
{
	while(scanf("%d", &n) != EOF)
	{
		for(int i = 1; i <= n; i++)
			scanf("%d", &a[i]);
		if(n & 1)
		{
			for(int i = n; i >= 1; i -= 2)
				printf("%d ", a[i]);
			for(int i = 2; i <= n; i += 2)
				printf("%d ", a[i]);
			printf("\n");
		}
		else 
		{
			for(int i = n; i >= 1; i -= 2)
				printf("%d ", a[i]);
			for(int i = 1; i <= n; i += 2)
				printf("%d ", a[i]);
			printf("\n");
		}
		memset(a, 0, sizeof(a));
	}
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b,c,d;
    cin >>a>>b>>c>>d;
    
    cout << min({a,b})+ min({c,d}) << 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++)
using ll = long long;

char change(ll x){
    if(x==0) return 'z';
    if(x==1) return 'a';
    if(x==2) return 'b';
    if(x==3) return 'c';
    if(x==4) return 'd';
    if(x==5) return 'e';
    if(x==6) return 'f';
    if(x==7) return 'g';
    if(x==8) return 'h';
    if(x==9) return 'i';
    if(x==10) return 'j';
    if(x==11) return 'k';
    if(x==12) return 'l';
    if(x==13) return 'm';
    if(x==14) return 'n';
    if(x==15) return 'o';
    if(x==16) return 'p';
    if(x==17) return 'q';
    if(x==18) return 'r';
    if(x==19) return 's';
    if(x==20) return 't';
    if(x==21) return 'u';
    if(x==22) return 'v';
    if(x==23) return 'w';
    if(x==24) return 'x';
    if(x==25) return 'y';
    if(x==26) return 'z';
}

int main(){
    ll n;
    cin >> n;
    ll k=1;
    ll x1=1;
    ll x2=26;
    bool flag=false;
    while(1){
        if(x1<=n && n<=x2){
            flag=true;
        }
        if(flag) break;
        k++;
        x1*=26; x2=26*x1+x2;
    }
    vector<ll> a(k);
    for(int i=0;i<k;i++){
        a[i]=n%26;
        if(a[i]==0) n -= 26;
        n /= 26;
    }
    for(int i=k-1;i>=0;i--){
        char s=change(a[i]);
        cout << s;
    }
    cout << endl;
}

Measured memory_bytes: 3596
a = sorted(input())
b = sorted(input(), reverse=True)

i = 0
ans = False

while i < len(a) and i < len(b):
  if a[i] != b[i] :
    if a[i] > b[i]:
      ans = False
    else:
      ans = True
    break
  i += 1
else:
  if len(a) < len(b):
    ans = True
  
if ans:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064