akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    int a = sc.nextInt();
    int b = sc.nextInt();
    String u = sc.next();

    if (u.equals(s)) {
      System.out.println((a-1)+" "+b);
    } else {
      System.out.println(a+" "+(b-1));
    }
  }

}


Measured memory_bytes: 23124
#include <stdio.h>

int main() {
	int H = 0;
	int W = 0;
	while (1) {
		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0) { break; }
		for (int a = 0; a < H; a++) {
			for (int b = 0; b < W; b++) {
				if (a == 0 || a == H - 1 || b == 0 || b == W - 1) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1744
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////




int main() {

	ll N;
	cin >> N;
	vector<ll> x(N + 1,0);

	repn(i, N) cin >> x[i];

	ll L;
	cin >> L;

	vector<ll> tr(N + 1);

	repn(i, N) {
		auto itr = upper_bound(x.begin(), x.end(), x[i] + L);
		tr[i] = distance(x.begin(), itr) - 1;
		//cout << tr[i] << endl;
	}

	vector<vector<ll>> dp(N + 1, vector<ll>(30));

	repn(i, N)dp[i][0] = tr[i];

	repn(j, 29)repn(i,N) {
		dp[i][j] = dp[dp[i][j - 1]][j - 1];
		//cout << i << j << dp[i][j]<<endl;
	}

	ll Q;
	cin >> Q;
	repn(i, Q) {
		ll a, b;
		cin >> a >> b;

		if (a > b) { swap(a, b); }

		ll ans = 0;

		for (ll j = 29; j >= 0; j--) {
			if (dp[a][j] < b) {
				//cout << dp[a][j] << endl;
				ans += 1 << j;
				a = dp[a][j];
			}
		}

		cout << ans + 1<<endl;
	}

	system("PAUSE");

}





Measured memory_bytes: 31744
M,D = map(int,input().split())

m  = 0
d10 = 2
d1 = 2

cnt = 0
while True:
    m = d10 * d1 
    d = d10 * 10 + d1
    if m <= M and d <= D:
        cnt += 1

    d1 += 1
    if d1 == 10:
        d1 = 2
        d10 += 1
        if d10 == 10:
            break
print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <functional>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


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


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}


int main() {
    vector<ll> x(5, 0);
    for(int i = 0; i < 5; i++) {
        cin >> x[i];
        if(x[i]==0) {

         cout << i+1 << endl;
         return 0;
        }
    }


    return 0;    
}



Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template<class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl;exit(0);}else return;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	string S; cin >> S;
	int n = S.size();
	int ans = n;
	REP(i, n - 1) if (S[i] != S[i + 1]) ans=min(ans, max(i + 1, n - (i + 1)));
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 512
n = int(input())
dp = [1000000] * 100010
dp[0] = 0
for i in range(n):
    a = 1
    while i + a <= 100000:
        dp[i + a] = min(dp[i + a], dp[i] + 1)
        a *= 6
    b = 1
    while i + b <= 100000:
        dp[i + b] = min(dp[i + b], dp[i] + 1)
        b *= 9
print(dp[n])


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll  ara[1000000];


int  main()
{
    ll  n;
    cin>>n;
    ll  k;
    cin>>k;
    ll x;
    for(ll  i=0;i<n;i++) ara[i]=0;
    ll q;
    cin>>q;
    for(ll  i=0;i<q;i++)
    {
        cin >>x;
        ara[x]++;
    }

    for(ll i=1;i<=n;i++)
    {
        ara[i]=k-abs((q-ara[i]));
    }
    for(ll  i=1;i<=n;i++)
    {
        if(ara[i]<=0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;;
    }
    return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=2e6+5;
unordered_map<int,int> head[maxn];
struct EDGE{
	int v,nex,c;
}edge[maxn];
int ecnt;
inline void add_edge(int u,int v,int c){
	edge[++ecnt]={v,head[u][c],c};head[u][c]=ecnt;
	edge[++ecnt]={u,head[v][c],c};head[v][c]=ecnt;
}
int main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,m;cin>>n>>m;
	bool vis[maxn],vvis[maxn];
	vector<vector<int>> nex(maxn);
	int vcnt=n;
	for(int i=1;i<=m;i++) {
		int u,v,c;cin>>u>>v>>c;
		add_edge(u,v,c);
	}
	std::function<void(int,int)> dfs= [&] (int u,int col) {
		nex[u].push_back(vcnt);
		nex[vcnt].push_back(u);
		vvis[u]=1;
		for(int i=head[u][col];i;i=edge[i].nex) if(!vis[i]){
			vis[i]=1;
			int v=edge[i].v;if(vvis[v]) continue;
			dfs(v,col);
		}
	};
	for(int i=1;i<=ecnt;i++) {
		if(!vis[i]) {
			++vcnt;
			dfs(edge[i].v,edge[i].c);
			for(auto x:nex[vcnt]) vvis[x]=0;
			// vis[i]=1;
		}
	}

	vector<int> dis(maxn);queue<int> Q;Q.push(1);dis[1]=1;
	while(!Q.empty()) {
		int u=Q.front();Q.pop();
		for(auto v:nex[u]) {
			if(dis[v]) continue;
			dis[v]=dis[u]+1;
			Q.push(v);
		}
	}
	cout<<(dis[n]?(dis[n]-1)/2:-1)<<endl;
    return 0;
}

Measured memory_bytes: 200584
#include <stdio.h>

int main(){

    int a,b,c;
    int cp;

    scanf("%d %d %d",&a,&b,&c);
    if(b > c){
        cp = b;
        b = c;
        c = cp;
    }
    if(a > b){
        cp = a;
        a = b;
        b = cp;
    }
    if(b > c){
        cp = b;
        b = c;
        c = cp;
    }

    printf("%d %d %d\n",a,b,c);
}


Measured memory_bytes: 2068
n = int(input()) - 1
c, s, f = [0] * n, [0] * n, [0] * n
for i in range(n):
    c[i], s[i], f[i] = map(int, input().split())
for i in range(n):
    t = s[i] + c[i]
    for j in range(i + 1, n):
        if t <= s[j]:
            t = s[j]
        else:
            if t % f[j]:
                t += f[j] - (t % f[j])
        t += c[j]
    print(t)
print(0)


Measured memory_bytes: 3064
function Main(input){
  input = input.split(" ");
  var result = parseInt(input[0], 10) * parseInt(input[1], 10);
   var answer = result % 2;
   
   if(answer === 1){
     console.log("Odd");
   }else{
      console.log("Even");
   }
   
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21448
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		boolean isYYMM = false;
		boolean isMMYY = false;

		int fh =  Integer.parseInt(s.substring(0, 2));
		int lh =  Integer.parseInt(s.substring(2));

		if (0 < lh && lh <= 12) {
			isYYMM = true;
		}

		if (0 < fh && fh <= 12) {
			isMMYY = true;
		}

		String ans = isYYMM ? isMMYY ? "AMBIGUOUS" : "YYMM"
				: isMMYY ? "MMYY" : "NA" ;
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 21716
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n <= m then  List.range n `To m else []
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'
let itoa n = Char.chr (n + Char.code '0')

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let a = scan "%c" id

let () =
  if Char.is_uppercase a then Printf.printf "A\n"
  else Printf.printf "a\n"


Measured memory_bytes: 5360
#include<stdio.h>

int main() {
int a,b,i;
char s[2000];
scanf("%d %d",&a,&b);
scanf("%s",s);

for(i=0;i<a+b;i++) {
if(i == a && s[i] != '-') {printf("No\n"); return 0;}
if(i != a && s[i] == '-'  ) {printf("No\n"); return 0;}
}
printf("Yes\n");
}

Measured memory_bytes: 128
import math

n, m = map(int, input().split())
a = list(map(int, input().split()))
b = {}
for i in range(n):
    count = 0
    temp = a[i]
    while temp % 2 == 0:
        count += 1
        temp //= 2
    b.setdefault(count, 0)
    b[count] += 1
if len(b.keys()) >= 2:
    ans = 0
else:
    temp = 1
    for i in range(n):
        temp = temp * a[i] // math.gcd(temp, a[i])
    temp2 = temp // 2
    ans = m // temp2 - m // temp
print(ans)

Measured memory_bytes: 20328
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000

int main() {
    vector<int> x(4);
    vector<int> y(4);
    for (int i = 0; i < 2; i++) {
        cin >> x.at(i) >> y.at(i);
    }
    int cx, cy, dx, dy;
    dx = (-1)*(y.at(1)-y.at(0))+x.at(0);
    dy = (x.at(1)-x.at(0))+y.at(0);
    cx = (y.at(0)-dy)*(-1)+dx;
    cy = (x.at(0)-dx)+dy;
    cout << cx << " " << cy << " " << dx << " " << dy << endl;
}

Measured memory_bytes: 256
//2018.09.18 解説見た後。

#include <iostream>
using namespace std;

int main() {

    string s;
    cin >> s;

    int size = s.size();
    int current=0;
    string test="";
    bool ans;

    while(1){
        test = "";

        if(size-current==0){ans=true; break;}
        else if(size-current<3){ ans = false; break;}
        else if(size-current==3){
            test = test+s[current]+s[current+1]+s[current+2];
            if(test=="ase"){ ans=true; break;}
            else{ans=false; break;}
        }
        else if(size-current==4){
            test = test+s[current]+s[current+1]+s[current+2]+s[current+3];
            if(test=="aser"){ans=true;break;}
            else{ans = false; break;}
        }
        else if(size-current==5){
            test = test+ s[current]+s[current+1]+s[current+2]+s[current+3]+s[current+4];
            if(test=="dream" || test=="erase"){ ans=true; break; }
            else{ ans = false; break; }
        }
        else if(size-current==6){
            test = test+ s[current]+s[current+1]+s[current+2]+s[current+3]+s[current+4]+s[current+5];
            if(test == "eraser"){ ans=true; break;}
            else{ans=false; break;}
        }
        else if(size-current==7){
            test = test+ s[current]+s[current+1]+s[current+2]+s[current+3]+s[current+4]+s[current+5]+s[current+6];
            if(test == "dreamer"){ ans=true; break;}
            else{ans=false; break;}
        }
        else{
            test = test+ s[current]+s[current+1]+s[current+2]+s[current+3]+s[current+4]+s[current+5]+s[current+6];
            if(test == "dreamer"){current+=7;continue; }
            else{
                test="";
                test = test+ s[current]+s[current+1]+s[current+2]+s[current+3]+s[current+4]+s[current+5];
                if(test == "eraser"){ current+=6; continue;}
                else{
                    test="";
                    test = test+ s[current]+s[current+1]+s[current+2]+s[current+3]+s[current+4];
                    if(test=="dream" || test=="erase"){ current+=5; continue;}
                    else{
                        test ="";
                        test = test+s[current]+s[current+1]+s[current+2]+s[current+3];
                        if(test=="aser"){current+=4;continue;}
                        else{
                            test="";
                            test = test+ s[current]+s[current+1]+s[current+2];
                            if(test=="ase"){
                                current+=3;
                                continue;
                            }
                        }
                    }
                }
            }
        }
        ans = false;
        break;
    }

    if(ans==true)cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define re register
int f[23][(1<<22)+1];
char ss[(1<<22)+1];
int main()
{
	re int n,k;
	scanf("%d%d",&n,&k);n++;
	for(re int i=1;i<=n;i++)
	{
		scanf("%s",ss);
		for(re int j=0;j<(1<<i-1);j++)f[i][j|(1<<i-1)]=ss[j]-'0';
	}
	for(re int i=n-1;i>=0;i--)
	{
		for(re int j=0;j<(1<<i);j++)
		{
			for(re int i1=i+1;i1<=n;i1++)
			{
				re int x1=j|(1<<i1-1),x0=j+(1<<i1-1)-(1<<i);
				for(re int j1=0;j1<(1<<n-i1);j1++)
				{
					f[i][j|(j1<<i+1)]+=f[i1][x0|(j1<<i1)];
					f[i][j|(j1<<i+1)|(1<<i)]+=f[i1][x1|(j1<<i1)];
					//printf("*k*%d %d %d %d\n",i,j,j|(j1<<i+1),f[i][j|(j1<<i+1)]);
					//printf("*l*%d %d %d %d\n",i,j,j|(j1<<i+1)|(1<<i),f[i][j|(j1<<i+1)|(1<<i)]);
				}
			}if(j&(1<<i-1))for(re int i1=i+1;i1<=n;i1++)f[i][j]+=f[i1][j|(1<<i1-1)];//printf("**%d %d %d\n",i,j,f[i][j]);
		}
	}
	re int ans=1;
	for(re int i=1;i<=n;i++)
	{
		re int num=-1;
		for(re int j=1<<i-1;j<(1<<i);j++)if(num==-1&&f[0][j]>=k)num=j;
		if(num!=-1)ans=num;
	}
	re int jj=0;
	for(;(1<<jj)<=ans;jj++);jj-=2;
	for(;jj>=0;jj--)printf("%d",(ans&(1<<jj))>>jj);
}

Measured memory_bytes: 222592
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<stack>
#include<sstream>
#include<string>
#include<cassert>
#include<ctime>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
int kase = 0;
//int n, m;

ll n, a, b, c, d;

int main()
{
	scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
	for(int i= 0  ; i <= n; i++)
		if (n * c - c - i * (c + d) <= b - a && b - a <= n * d - d - i * (c + d))
		{
			printf("YES\n");
			return 0;
		}
	printf("NO\n");
}

Measured memory_bytes: 256
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

// const ll MOD = (ll)1e9+7;
const ll MAX = (ll)6e3+10;

int main(void) {
   ll N,M;
   cin>>N;
   ll ans = 0;
   rep(i,0,N) {
      ll a;
      cin>>a;
      ans += a-1;
   }
   cout<<ans<<endl;

   return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
const int maxn=100010;
const int inf=1e9;
int n,k,val[maxn],first[maxn],nxt[maxn<<1],to[maxn<<1],e;
void AddEdge(int u,int v) {
	to[++e]=v;nxt[e]=first[u];first[u]=e;
	to[++e]=u;nxt[e]=first[v];first[v]=e;
}
int mn[maxn][2],mx[maxn][2];
int f[maxn],siz[maxn],vis[maxn],size,root;
void getroot(int x,int fa) {
	int maxs=0;siz[x]=1;
	for(int i=first[x];i;i=nxt[i]) if(to[i]!=fa&&!vis[to[i]]) {
		getroot(to[i],x);siz[x]+=siz[to[i]];
		maxs=max(maxs,siz[to[i]]);
	}
	f[x]=max(maxs,size-siz[x]);
	if(f[root]>f[x]) root=x;
}
int Mx[2],Mn[2];
// Max (v - d)  Min (v + d)
void dfs(int x,int dep,int fa) {
	mn[x][Mn[0]+dep&1]=min(mn[x][Mn[0]+dep&1],Mn[0]+dep);
	mn[x][Mn[1]+dep&1]=min(mn[x][Mn[1]+dep&1],Mn[1]+dep);
	mx[x][Mx[0]-dep&1]=max(mx[x][Mx[0]-dep&1],Mx[0]-dep);
	mx[x][Mx[1]-dep&1]=max(mx[x][Mx[1]-dep&1],Mx[1]-dep);
	for(int i=first[x];i;i=nxt[i]) if(to[i]!=fa&&!vis[to[i]]) dfs(to[i],dep+1,x);
}
void dfs2(int x,int dep,int fa) {
	if(val[x]>=0) {
		Mn[val[x]+dep&1]=min(Mn[val[x]+dep&1],val[x]+dep);
		Mx[val[x]-dep&1]=max(Mx[val[x]-dep&1],val[x]-dep);
	}
	for(int i=first[x];i;i=nxt[i]) if(to[i]!=fa&&!vis[to[i]]) dfs2(to[i],dep+1,x);
}
void solve(int x) {
	vis[x]=1;
	Mx[0]=Mx[1]=-inf;Mn[0]=Mn[1]=inf; 
	dfs2(x,0,0);dfs(x,0,0); 
	for(int i=first[x];i;i=nxt[i]) if(!vis[to[i]]) {
		f[0]=size=siz[to[i]];getroot(to[i],root=0);
		solve(root);
	}
}
void color(int x,int fa) {
	for(int i=first[x];i;i=nxt[i]) if(to[i]!=fa) {
		if(val[x]-1>=mx[to[i]][0]&&val[x]-1<=mn[to[i]][0]) val[to[i]]=val[x]-1;
		else val[to[i]]=val[x]+1;
		color(to[i],x);
	}
}
int main() {
	n=read();
	rep(i,2,n) AddEdge(read(),read());
	memset(val,-1,sizeof(val));
	k=read();
	rep(i,1,k) {
		int x=read();
		val[x]=read();
	}
	rep(i,1,n) mn[i][0]=mn[i][1]=inf,mx[i][0]=mx[i][1]=-inf;
	f[0]=size=n;getroot(1,root=0);
	solve(root);
	int ok=1;
	rep(i,1,n) {
		int c=0;
		if(mn[i][0]!=inf&&mx[i][0]!=-inf) {
			c++;
			if(mx[i][0]>mn[i][0]) ok=0;
		}
		if(mn[i][1]!=inf&&mx[i][1]!=-inf) {
			swap(mn[i][0],mn[i][1]);swap(mx[i][0],mx[i][1]);
			c++;
			if(mx[i][0]>mn[i][0]) ok=0;
		}
		if(c!=1) {ok=0;break;}
	}
	if(ok) {
		puts("Yes");
		rep(i,1,n) if(val[i]>=0) {
			color(i,0);
			break;
		}
		rep(i,1,n) printf("%d\n",val[i]);
	}
	else puts("No");
	return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

ll a[101010];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	ll l;
	cin>>l;
	int f=0;
	for (int i=0;i<n;i++){
		cin>>a[i];
		if (i>0&&a[i]+a[i-1]>=l){
			f=i;
		}
	}
	if (!f){
		cout<<"Impossible"<<endl;
		return 0;
	}
	cout<<"Possible"<<endl;
	for (int i=1;i<f;i++){
		cout<<i<<"\n";
	}
	for (int i=n-1;i>f;i--){
		cout<<i<<"\n";
	}
	cout<<f<<"\n";
}

Measured memory_bytes: 1664
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
ll dp[4000][6500];
int main(){
int n,t;
cin>>n>>t;
vector<P> v(n);
for(int i=0;i<n;i++){
    cin>>v[i].fi>>v[i].se;
}
sort(all(v));
for(int i=0;i<n;i++){
    for(int j=0;j<t;j++){
          chmax(dp[i+1][j+v[i].fi],dp[i][j]+v[i].se);
          chmax(dp[i+1][j],dp[i][j]);
    }
}
ll ans=0;
for(int i=0;i<6500;i++)for(int j=0;j<=n;j++)chmax(ans,dp[j][i]);
cout<<ans<<endl;
}



Measured memory_bytes: 152960
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Node
{
    int key;
    struct Node *prev,*next;
};
typedef struct Node Node;

Node *Nil;

void init()
{
    Nil = (Node *)malloc(sizeof(Node));
    Nil->next = Nil;
    Nil->prev = Nil;
}
void insert(int key)
{
    Node *x =(Node*)malloc(sizeof(Node));
    x->key = key;
    //Insert Behind Head
    x->next = Nil->next;
    x->next->prev = x;
    Nil->next = x;
    x->prev = Nil;
}
Node *listSearch(int key)
{
    Node *cur = Nil->next;
    while(cur->key!=key && cur != Nil)
    {
        cur = cur->next;
    }
    return cur;
}
void deleteNode(Node *t)
{
    if(t == Nil)return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}
void deleteFirst()
{
    deleteNode(Nil->next);
}
void deleteLast()
{
    deleteNode(Nil->prev);
}
void deleteKey(int key)
{
    deleteNode(listSearch(key));
}
void printList()
{
    Node *cur = Nil->next;
    int isf = 0;
    while(1)
    {
        if(cur == Nil)break;
        if(isf++ > 0)printf(" ");
        printf("%d",cur->key);
        cur = cur->next;
    }
    printf("\n");
}
int main()
{
    int key,n,i;
    int size = 0;
    char com[20];
    int  np = 0,nd = 0;
    scanf("%d",&n);
    init();
    for(i = 0; i < n; i++)
    {
        scanf("%s%d",com,&key);
        if(com[0]=='i'){insert(key);np++;size++;}
        else if(com[0]=='d')
        {
            if(strlen(com)>6)
            {
                if(com[6] == 'F')deleteFirst();
                else if(com[6]=='L')deleteLast();

            }
            else
            {
                deleteKey(key);
                nd++;
            }
            size--;
        }
    }
    printList();

    return 0;
}



Measured memory_bytes: 33056
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
int main(void) {
	int n;cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	cout << a[n / 2] - a[n / 2 - 1] << endl;
}

Measured memory_bytes: 640
//競技中わからなかった
//最初大きいものを最大限使う方針を立てたができない
//貪欲法では　3^n　かかる気がする
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdlib> //abs() これは整数のみ

using namespace std;

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

const int max_v = 300;
const int INF = 1000000;



int main() {
	int n, ans=0, y ,a,b,c,money;
	int man, gosen, sen;
	cin >> n;
	cin >> y;

	for(a=0; n >= a; a++){
		for (b = 0; n >= a+b; b++){
			c = n-a-b;
			money = 10000 * a + 5000 * b + 1000 * c;
			if(money == y) {
				cout << a <<' ' << b << ' ' << c << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

void read( std::string s[], int n )
{
	for( int i = 0; i < n; i++ ) {
		std::cin >> s[ i ];
	}
	return;
}

int main()
{
	int n, m;

	std::cin >> n;
	std::string s[ 100 ];
	read( s, n );

	std::cin >> m;
	std::string t[ 100 ];
	read( t, m );

	int maxcnt = 0;
	for( int i = 0; i < n; i++ ) {
		std::string b = s[ i ];
		int cnt = 0;
		for( int j = 0; j < n; j++ ) {
			if( b == s[ j ] ) {
				cnt += 1;
			}
		}
		for( int k = 0; k < m; k++ ) {
			if( b == t[ k ] ) {
				cnt -= 1;
			}
		}
		maxcnt = std::max( maxcnt, cnt );
	}

	std::cout << maxcnt << std::endl;
	return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

vector<bool> eratosthenes(int n) {
	vector<bool> is_prime(n+1,true);
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i*i<=n;i++) {
		if(is_prime[i]) {
			for(int j=2*i;j<=n;j+=i) {
				is_prime[j]=false;
			}
		}
	}
	return is_prime;
}

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

	int n,ans=0;
	cin>>n;
	auto is_prime=eratosthenes((int)1e8);
	REP(i,n) {
		int tmp;cin>>tmp;
		if(is_prime[tmp]) ans++;
	}
	cout<<ans<<endl;

	return 0;
}



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

typedef long long ll;

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

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a - 1) * (b - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np
n=int(input())
ta=list(map(int,input().split()))
t=ta[0]
a=ta[1]
h=list(map(int,input().split()))
temp=[0 for i in range(n)]
for i in range(n):
    temp[i] = abs((t-0.006*h[i])-a)
ans = np.argmin(temp) + 1
print(ans)


Measured memory_bytes: 22416
def IsBingo(arr_9):
    BINGO=['x','x','x']
    C1=arr_9[0::3]
    C2=arr_9[1::3]
    C3=arr_9[2::3]
    X1=[arr_9[0],arr_9[4],arr_9[8]]
    X2=[arr_9[2],arr_9[4],arr_9[6]]
    if (arr_9[:3]==BINGO or arr_9[3:6]==BINGO or arr_9[6:]==BINGO
     or C1==BINGO or C2==BINGO or C3==BINGO or X1==BINGO or X2==BINGO):
        return 'BINGO'


A1=list(input().split())
A2=list(input().split())
A3=list(input().split())
A=A1+A2+A3
N=int(input())
for _ in range(N):
    n=input()
    if A.count(n)==1:
        A[A.index(n)]="x"
# A1=A[:3]
# A2=A[3:6]
# A3=A[6:]
# print(A1,A2,A3)

if IsBingo(A)=='BINGO':
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int a, b, c;
    scan(a, b, c);
    writeln(a <= c && c <= b ? "Yes" : "No");
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=100010;
int main()
{
  string s,y="",m="",d="";
  cin>>s;
  for(int i=0;i<4;i++) y+=s[i];
  // cout<<s[5]+s[6]<<endl;
  m={s[5],s[6]};
  d={s[8],s[9]};
  // cout<<y<<" "<<m<<" "<<d<<endl;
  int a=stoi(y);
  int b=stoi(m);
  int c=stoi(d);
  // cout<<a<<" "<<b<<" "<<c<<endl;
  if(a<2019) cout<<"Heisei\n";
  else if(a==2019)
  {
    if(b<4) cout<<"Heisei\n";
    else if(b==4)
    {
      if(c<=30) cout<<"Heisei\n";
      else cout<<"TBD\n";
    }
    else cout<<"TBD\n";
  }
  else cout<<"TBD\n";
  return 0;
}


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

const int MX = 200005, MOD = 1E9 + 7;

int m, n, k;
long long ans = 0, fct[MX], ivf[MX], inv[MX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> m >> n >> k;
    fct[0] = ivf[0] = 1;
    fct[1] = ivf[1] = inv[1] = 1;
    for (int i = 2; i <= m * n; i++)
    {
        fct[i] = fct[i - 1] * i % MOD;
        inv[i] = MOD - MOD / i * inv[MOD % i] % MOD;
        ivf[i] = ivf[i - 1] * inv[i] % MOD;
    }
    for (int i = 1; i <= m; i++)
    {
        int cur = i - (m + 1 - i);
        (ans += 1LL * n * n % MOD * i % MOD * cur) %= MOD;
    }
    for (int i = 1; i <= n; i++)
    {
        int cur = i - (n + 1 - i);
        (ans += 1LL * m * m % MOD * i % MOD * cur) %= MOD;
    }
    (ans += MOD) %= MOD;
    cout << ans * fct[m * n - 2] % MOD * ivf[k - 2] % MOD * ivf[m * n - k] % MOD;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    ll t, a, rest = 1, resa = 1;

    //find p s.t.pt >= rest, pa >= resa
    REP(i, n){
        cin >> t >> a;
        ll p = max((rest - 1) / t + 1, (resa - 1) / a + 1);
        rest = p * t;
        resa = p * a;
    }
    cout << rest + resa << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a = 0;
  int x,y,z;
  cin >> a;
  
  x = a / 100;
  x = x % 2;
  y = a / 10;
  y = y % 2;
  z = a % 2;
   
  cout << x + y + z << endl;
  
  return 0;
}

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

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string s, t; cin >> s >> t;
  
  int n = s.size();
  
  bool good = true;
  for (int i = 0; i < n; ++i) {
    good = good && (s[i] == t[i]);
  }
  
  if(good) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }


  
  return 0;
}




Measured memory_bytes: 3652
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>
#include <complex>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-6;
const double PI  = acos(-1.0);


typedef complex<double> CP;
int N;
CP point[310];

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

  while(true){
	cin >> N; if(N == 0) break;
	REP(i,N){
	  double x,y; cin >> x >> y;
	  point[i] = CP(x, y);
	}

	int ans = 1;
	for(int i1=0;i1<N;++i1){
	  for(int i2=i1+1;i2<N;++i2){
		double d = norm(point[i1] - point[i2]);
		if(sqrt(d) > 2.00){
		  continue;
		}
		CP m = (point[i1] + point[i2]) / 2.0;
		CP n = point[i2] - point[i1];
		n /= abs(n);
		n = CP(-imag(n), real(n));

		CP c = m + n * sqrt(1 - d / 4.0);
		int res = 2;
		for(int i=0;i<N;++i){
		  if(i==i1 || i==i2) continue;
		  if(abs(c-point[i]) <= 1.0)
			++res;
		}
		ans = max(ans, res);

		c = m - n * sqrt(1 - d / 4.0);
		res = 2;
		for(int i=0;i<N;++i){
		  if(i==i1 || i==i2) continue;
		  if(abs(c-point[i]) <= 1.0)
			++res;
		}
		ans = max(ans, res);
		
	  }
	}
	
	cout << ans << endl;
  }

  return 0;
}

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

#define ll long long

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}

int main() {

	ll N, ans = 0;
	vector<ll> A, B, C;

	cin >> N;
	for (int i = 0; i < N; i++) {

		ll tmp;
		cin >> tmp;
		A.push_back(tmp);

	}
	for (int i = 0; i < N; i++) {

		ll tmp;
		cin >> tmp;
		B.push_back(tmp);

	}
	for (int i = 0; i < N; i++) {

		ll tmp;
		cin >> tmp;
		C.push_back(tmp);

	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	int a = 0, c = 0;

	for (int i = 0; i < N; i++) {

		if (a < N) {
			while (A[a] < B[i]) {

				a++;
				if (a == N)break;

			}
		}
		if (c < N) {
			while (C[c] <= B[i]) {

				c++;
				if (c == N)break;

			}
		}
		ans += a*(N - c);

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 998244353
//#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,k;
int main(){
	scanf("%lld%lld",&n,&k);
	if((k+k+n+n-1)*n>(k+n+n+k+n+n+n-1)*n/2){
		puts("-1");
		return 0;
	}
	
	ll l1=(n-1)/2;
	ll l2=n-1;
	ll r1=n-1;
	ll r2=n/2-1;
	
	rep(i,0,n){
		if(i%2==0){
			printf("%lld %lld %lld\n",k+l1--,k+n+r1--,k+n+n+n-1-i);
		}else{
			printf("%lld %lld %lld\n",k+l2--,k+n+r2--,k+n+n+n-1-i);
		}
	}
}

Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <climits>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int D, G; cin>>D>>G;
  vector<int> p(D), c(D);
  vector<bool> perf(D);
  REP(i,D) cin>>p[i]>>c[i];
  int ans = INT_MAX;
  REP(mask, 1<<D) {
    int cnt = 0;
    int	score =	0;
    REP(i, D) {
      perf[i] = ((1<<i)&mask) != 0;
      if(perf[i]) {
	cnt += p[i];
	score += c[i] + (i+1)*100*p[i];
      } 
    }
    if(score >=	G) {
      ans = min(ans, cnt);
      //      cout << "J:" << mask << " " << cnt << " " << ans << endl;         
    } else {
      for(int i = D-1; i >= 0; i--) {
	if(perf[i]) continue;
	int point = (i+1)*100;
	int rem = G-score;
        if((p[i]-1)*point >= rem) {
          int k = rem/point;
          if(rem%point>0) k++;
          cnt += k;
          ans = min(ans,cnt);
          //      cout << "K:" << mask << " " << cnt << " " << ans << endl;     
          break;
        } else {
          score += (p[i]-1)*point;
          cnt += (p[i]-1);
        }
      }
    }

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



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

int main() {
	int N, M;
	string S;
	bool open = false;
	cin >> N;
	map<string, bool> mp;
	for (int i = 0; i < N; i++) {
		cin >> S;
		mp[S] = true;
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
		cin >> S;
		if (!mp[S]) {
			cout << "Unknown " << S << endl;
		}
		else {
			if (open) cout << "Closed by " << S << endl;
			else cout << "Opened by " << S << endl;
			open = !open;
		}
	}
}


Measured memory_bytes: 3256
#include<stdio.h>
int dp[50001];
int main(void){
	int i,j;
	int n,m;
	scanf("%d %d",&n,&m);
	for(j=0;j<=n;j++){
		if(j==0){
			dp[j]=0;
		}
		else {
			dp[j]=100000;
		}
	}
	int a;
	for(i=0;i<m;i++){
		scanf("%d",&a);
		for(j=0;j<n;j++){
			if(dp[j]>=0 && j+a<=n && dp[j+a]>dp[j]+1 ){
				dp[j+a]=dp[j]+1;
			}
		}
		/*for(j=0;j<=n;j++){
			printf("%d ",dp[j]);
		}
		printf("\n");*/
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1220
# coding: utf-8
# Here your code !
def searchEmployeeSales(employeeId):
    for data in employeeSalesList:
        if data[0] == employeeId:
            return data
    
    newData = [employeeId, 0]
    employeeSalesList.append(newData)
    return newData

def printEmployeeOfDataset():
    answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
    if answerList:
        print("\n".join(map(str, answerList)))
        return
    print("NA")

dataCount = int(input())
while dataCount > 0:
    employeeSalesList = []
    for _ in range(dataCount):
        employeeId, price, volume = list(map(int, input().split(" ")))
        employeeSales = searchEmployeeSales(employeeId)
        employeeSales[1] += price * volume
    printEmployeeOfDataset()
    dataCount = int(input())

Measured memory_bytes: 7792
#include <stdio.h>
#include <string.h>
int main(void)
{
    int n,k,i;
    char s[11];
    scanf("%d%s%d", &n,s,&k);
    for(i=0; i<n; i++)
    {
        if(strncmp(&s[k-1], &s[i], 1)==0) printf("%c", s[i]);
        else printf("*");
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
  char c[200];
  int m,h,i,j,k,num=0,temp;
  while(1){
    scanf("%s",&c);
     if(c[0]=='-')break;
    for(num=0; num<300; num++)if(c[num]=='\0')break;
    scanf("%d",&m);
    for(i=0; i<m; i++){
      scanf("%d",&h);
      for(j=0; j<h; j++){
    temp=c[0];
    for(k=0; k<num; k++){
          c[k]=c[k+1];
    }
        c[num-1]=temp;
      }
    }
    printf("%s\n",&c);
  }
  return 0;
}


Measured memory_bytes: 2044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.nextLine();
		sc.close();
		if(n.charAt(n.length()-1)=='2'||
				n.charAt(n.length()-1)=='4'||
				n.charAt(n.length()-1)=='5'||
				n.charAt(n.length()-1)=='7'||
				n.charAt(n.length()-1)=='9') {
			System.out.println("hon");
		} else if(n.charAt(n.length()-1)=='0'||
				n.charAt(n.length()-1)=='1'||
				n.charAt(n.length()-1)=='6'||
				n.charAt(n.length()-1)=='8') {
			System.out.println("pon");
		} else {
			System.out.println("bon");
		}
		
	}

}


Measured memory_bytes: 35720
/*
ID: thanhvq1
LANG: C++14
PROB: namenum
*/

#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;
//#define int long long
#define double long double
#define vec vector
#define vi vector<int>
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define unset unordered_set
#define ii pair<int, int>
#define vii vector<ii>
#define F first
#define S second
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first, l.second+r.second};
} 
typedef void (*callback_function)(void); // type for conciseness
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

void FILEIO() {  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout); }
//void FILEIO() {  freopen("namenum.in", "r", stdin);  freopen("namenum.out", "w", stdout); }
void input() {   }

int n, m;
vi L, R;

void solve() {
	cin >> n >> m;
	L.resize(m); R.resize(m);
	FOR(i, 0, m) cin >> L[i] >> R[i];
	sort(L.begin(), L.end()); sort(R.begin(), R.end());
	if(L.back() <= R.front()) cout << R.front() - L.back() + 1;
	else cout << 0 << endl;
}

//#undef int
signed main() {
//#define int long long
  ios_base::sync_with_stdio(false); cin.tie();
//  FILEIO();
//auto beginProgram = chrono::steady_clock::now();

//  while (1)
//  {
		input();
		solve();
//  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


Measured memory_bytes: 1024
import sys
import queue

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	h, w = tin()
	#s = input()
	ol = queue.Queue()
	m=[input() for _ in range(h)]
	b = [[-1]*w for _ in range(h)]
	b[0][0]=1
	ol.put(0)
	while not ol.empty():
		p = ol.get()
		x, y = p//1000, p%1000
		for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
			if x+dx<0 or x+dx>=h or y + dy <0 or y+dy >= w:
				continue
			if m[x+dx][y+dy]=='#':
				continue
			if b[x+dx][y+dy]>=0:
				continue
			b[x+dx][y+dy]=b[x][y]+1
			ol.put((x+dx)*1000+(y+dy))
	#print(b)
	if b[-1][-1]==-1:
		return -1
	return sum([s.count('.') for s in m])- b[-1][-1]
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 43368
#include<stdio.h>
int n,i,a[101]={0},s=0;
int main()
{
     scanf("%d",&n);
     for(i=1;i<=n;i=i+1)
       scanf("%d",&a[i]);
     for(i=2;i<=n;i=i+1)
     {
         if(a[i]==a[i-1])
         {
            s=s+1;
            a[i]=0;
         }
     }
     printf("%d",s);
     return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main()
{
	ll a,b;
	cin>>a>>b;
	if(a>b)cout<<min(a%b,abs(b-(a%b)))<<endl;
	else if(a==b)cout<<0<<endl;
	else cout<<min(a,abs(b-a))<<endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
list = []
for i in 0...n do
  list.push([i+1, a[i]])
end
list.sort! do |e, f|
  e[1] <=> f[1]
end
for i in 0...n do
  print list[i][0]
  print (i == n-1) ? "\n" : " "
end


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int A,B,C,X; cin >> A >> B >> C >> X;
    int ans=0;
    REP(i,A+1)REP(j,B+1)REP(k,C+1){
        if(500*i+100*j+50*k == X) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
let n = read_int ();;
let g = Array.init 200000 (fun _ -> []);;
let visited = Array.make 200000 false;;

for i = 0 to n - 1 do
  let x, y = Scanf.scanf " %d %d" (fun x y -> x - 1, y - 1 + 100000) in
  g.(x) <- y :: g.(x);
  g.(y) <- x :: g.(y);
done

let rec dfs u cl cr = 
  if not visited.(u) then (
    if u < 100000 then
      cl := !cl + 1
    else
      cr := !cr + 1;
    visited.(u) <- true;
    List.iter (fun v -> dfs v cl cr) g.(u);
  );;


let ans = ref (-n);;
for i = 0 to 199999 do
  let cl = ref 0 and cr = ref 0 in
  dfs i cl cr;
  ans := !ans + !cl * !cr;
done;;

Printf.printf "%d\n" !ans;;


Measured memory_bytes: 15488