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

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back

int n;
int asked = 0;

int ask(int u) {
	printf("%d\n", u);
	asked++;
	
	assert(asked <= 20);
	
	fflush(stdout);
	
	string x; cin >> x;
	
	if (x[0] == 'V') {
		return 0;
	} else if (x[0] == 'M') {
		return 1;	
	} else return -1;
}

int basic;

int main() {
	cin >> n;
	basic = ask(0);
	
	if (basic == 0) return 0;

	int low = 0, high = n;
	
	while (true) {
		int mid = (low + high) >> 1;
		int col = ask(mid);
		
		if (col == 0) return 0;
		
		int exp = (mid % 2 == 1 ? -basic : basic);
		
		if (exp == col) {
			low = mid + 1;	
		} else {
			high = mid - 1;	
		}
	}
}

Measured memory_bytes: 3824
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <iomanip>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <set>
#include <map>
#include <queue>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    ll n;
    string s;
    vector<int> r;
    vector<int> g;
    vector<int> b;
    cin >> n >> s;
    ll num = 0;
    for (ll i = 0; i < n;i++)
    {
        if(s[i]=='R')
            r.push_back(i+1);
        if(s[i]=='G')
            g.push_back(i+1);
        if(s[i]=='B')
            b.push_back(i+1);
    }
    for(auto i:r)
        for(auto j:g)
            for(auto k:b)
            {
                if(2*k==j+i) continue;
                if(2*i==k+j) continue;
                if(2*j==i+k) continue;
                num++;
            }
    cout << num;
    return 0;
}


Measured memory_bytes: 3200
import java.io.*;

public class Main{
  public static void main(String[] args) {
    try {
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      String a, b, c;
      String d, e, f;

      a = reader.readLine();
      d = a.substring(0, 1);
      b = reader.readLine();
      e = b.substring(1, 2);
      c = reader.readLine();
      f = c.substring(2);

      System.out.println(d + e + f);
      
    }
    catch (Exception e) {
      
    }
  }
}

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

int main(){
int n;
  cin>>n;//>>x >> y>> z;
  
/*vector<int> a(n);
  rep(i,n) cin>>a.at(i);*/
    int x,y;
  x=0;
  y=0;
    
for(int i =9;i>0;i--){
if(n%i==0){
  x=i;
  y=n/i;
  break;
}
} 
  
  x<10 && y<10 ?
    cout<<"Yes"
    : cout<<"No";
}

Measured memory_bytes: 256
n,x = map(int,input().split())
ans = 0
if 2*x == n:
    ans = 3*x
else:
    ans += n
    a = x
    b = n - x
    while True:
        ans += (a//b)*2*b
        c = b
        b = a%b
        a = c
        if b == 0:
            ans -= a
            break
    
print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 1E5 + 10;

struct E{
	int x,y; E(){}
	E(int x,int y): x(x),y(y){}
}edgs[maxn];

int n,m,Black,White,Ans,A,B,tp,f[maxn],fa[maxn],L[maxn],stk[maxn];
bool flag;

vector <int> v[maxn];

int getint()
{
	char ch = getchar(); int ret = 0;
	while (ch < '0' || '9' < ch) ch = getchar();
	while ('0' <= ch && ch <= '9')
		ret = ret * 10 + ch - '0',ch = getchar();
	return ret;
}

void Color(int x,int from)
{
	int now = f[x];
	if (now == 1) ++Black; else ++White;
	for (int i = 0; i < v[x].size(); i++)
	{
		int to = v[x][i];
		if (to == from) continue;
		if (L[to])
		{
			if (L[to] > L[x]) continue;
			flag = (L[x] - L[to] & 1) ? 0 : 1;
			A = to; B = x; continue;
		}
		f[to] = -now; L[to] = L[x] + 1;
		Color(to,x); fa[to] = x; f[x] += f[to];
	}
}

void Add(int x,int delta)
{
	for (int i = x; i; i = fa[i])
		f[i] += delta;
}

void Calc_Ans()
{
	for (int i = 1; i <= m; i++)
	{
		if (edgs[i].x == A && edgs[i].y == B) continue;
		if (edgs[i].x == B && edgs[i].y == A) continue;
		Ans += abs(f[L[edgs[i].x] > L[edgs[i].y] ? edgs[i].x : edgs[i].y]);
	}
	printf("%d\n",Ans);
}

void Check1()
{
	if (Black != White) {puts("-1"); return;}
	Calc_Ans();
}

void Check2()
{
	if (Black != White)
	{
		if (abs(Black - White) % 2 != 0) {puts("-1"); return;}
		int delta = (Black - White) / -2;
		Ans = abs(delta); Add(A,delta); Add(B,delta);
	}
	Calc_Ans();
}

void Check3()
{
	if (Black != White) {puts("-1"); return;}
	for (int i = B; i != A; i = fa[i]) stk[++tp] = f[i];
	sort(stk + 1,stk + tp + 1);
	int tmp = stk[(tp + 1) / 2]; Add(A,tmp); Add(B,-tmp);
	Ans = abs(tmp); Calc_Ans();
}

void Solve()
{
	n = getint(); m = getint();
	for (int i = 1; i <= m; i++)
	{
		int x = getint(),y = getint();
		edgs[i] = E(x,y); v[x].push_back(y); v[y].push_back(x);
	}
	f[1] = L[1] = 1; Color(1,0);
	if (m == n - 1) Check1();
	else if (flag) Check2(); else Check3();
}

void Clear()
{
	Ans = flag = Black = White = tp = 0;
	for (int i = 1; i <= n; i++) v[i].clear(),L[i] = 0;
}

int main()
{
	Solve();
	//int T = getint();
	//while (T--) Solve(),Clear();
	return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
        #define int long long
        #define endl '\n'
        using namespace std;
        signed main(){
        iostream::sync_with_stdio(0),cin.tie(0);
        int a,b,c,d,z=1000000;
        cin>>a>>b>>c>>d;
        while(z--){
        if(a<=0){
        cout<<"No";
        exit(0);
        }
        else if(c<=0){
        cout<<"Yes";
        exit(0);
        }
        if(z%2)
        c-=b;
        else
        a-=d;
        }
        }


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


int main(){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    int x[100], y[100];
    for(int i=0;i<N;i++)
        cin >> x[i];
    for(int i=0;i<M;i++)
        cin >> y[i];
    //降順ソート
    sort(x, x + N, greater<int>());
    //昇順ソート
    sort(y, y + M);
    if(x[0] < y[0]){
        for(int i=x[0] + 1;i<=y[0];i++){
            if(X<i && i<=Y){
                cout << "No War" << endl;
                return 0;
            }
        }
        cout << "War" << endl;
    }else{
        cout << "War" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    char num_chars[256]={};
    for (char c; scanf("%c", &c)!=EOF;)
        if ((c|0x20)>='a' && (c|0x20)<='z')
            ++num_chars[c|0x20];

    for (char c='a'; c<='z'; ++c)
        printf("%c : %d\n", c, num_chars[c+0]);

    return 0;
}

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

int H, W;
int arr[205][205];
int dist[15][15];

void findTheShortest(){
	for (int k = 0; k < 10; k++)
		for (int i = 0 ; i < 10; i++)
			for (int j = 0 ; j < 10; j++) 
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> H >> W;
	for (int i = 0 ; i < 10; i++)
		for (int j = 0 ; j < 10; j++)
			cin >> dist[i][j];
	findTheShortest();
	int ans = 0;
	for (int i = 0 ; i < H; i++) 
		for (int j = 0 ; j < W; j++) {
			int tmp;
			cin >> tmp;
			if (tmp != -1) ans += dist[tmp][1];
		}
	cout << ans << '\n';
	return 0;
}

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

const ll mod=1e9+7;
ll h[1000000]{0};
ll dp[1000000]{0};
ll n,k;
ll solve(ll i){
    if(i==n) return 0;
    if(i>n) return INT_MAX;
    if(dp[i]!=-1) return dp[i];
    ll ans=INT_MAX;
    for(ll j=i+1;j<=i+k && j<=n ;j++){
        ans=min(ans,solve(j)+abs(h[i]-h[j]));
    }
    return dp[i]=ans;
}

int main() {

    memset(dp,-1,sizeof(dp));
    cin>>n;
    cin>>k;
    for(ll i=0;i<n;i++){
        cin>>h[i+1];
    }
    cout<<solve(1)<<endl;

}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    vector<vector<int>> list(301);
    int res = 0;
    for(int i = 0; i<list.size();i++) {
        int h,w;
        cin >> h >> w;
        if (h == 0 && w == 0) {
            res = i;
            break;
        }
        list[i] = {h,w};
    }

    for(int i = 0; i<res; i++) {
        for(int k = 0; k < list[i][0]; k++) {
            for(int j = 0; j < list[i][1]; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3116
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::*;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
    n: usize,
    }

    let mut vec =vec![0; 4];

    for _ in 0..n {
      input!{
        s: String,
      }
      if s == "AC" {
        vec[0] += 1;
      }

      if s == "WA" {
        vec[1] += 1;
      }

      if s == "TLE" {
        vec[2] += 1;
      }

      if s == "RE" {
        vec[3] += 1;
      }
    }

     println!("AC x {}", vec[0]);
     println!("WA x {}", vec[1]);
     println!("TLE x {}", vec[2]);
     println!("RE x {}", vec[3]);
}


Measured memory_bytes: 2580
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef float f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
const int mod=998244353;
//const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

int a[200005],b[200005];
int n;
bool check(int i) {
	if(b[i]>b[(i+n-2)%n+1]&&b[i]>b[i%n+1]&&b[i]!=a[i])
		return 1;
	return 0;
}
void solve() {
	cin>>n;
	fr(i,1,n)
		cin>>a[i];
	fr(i,1,n)
		cin>>b[i];
	set<int> lar;
	for(int i=1; i<=n; i++) {
		if(check(i))
			lar.insert(i);
	}
	int ans=0;
	while(lar.size()) {
		int te=*lar.begin();
		lar.erase(lar.begin());
		int lol=min((b[te]-a[te])/(b[te%n+1]+b[(te+n-2)%n+1]),b[te]/(b[te%n+1]+b[(te+n-2)%n+1]));
		ans+=lol;
		b[te]-=lol*(b[te%n+1]+b[(te+n-2)%n+1]);
		if(check(te%n+1)) {
			lar.insert(te%n+1);
		}
		if(check((te+n-2)%n+1)) {
			lar.insert(((te+n-2)%n+1));
		}
	}
	fr(i,1,n) {
		if(a[i]!=b[i]) {
			cout<<-1<<endl;
			return;
		}
	}
	cout<<ans<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod = 998244353;
const int N = 1e5 + 5;

int main()
{
	ios::sync_with_stdio(false);
	cout.tie(NULL);
	string s;
	cin >> s;
	if(s[s.length()-1] == 's')
		cout << s << "es" << endl;
	else
		cout << s << "s" << endl; 
	return 0;  
} 

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int maxValue = 1e5 + 5;

int dfs(int i , vector<int>g[] , int *maxNodes , int dist){
    if(g[i].size() == 0){
        maxNodes[i] = 1;
    }
    if(maxNodes[i] != 0) return maxNodes[i];
    for(int j : g[i]){
        maxNodes[i] = max(maxNodes[i] , dfs(j , g , maxNodes , dist) + 1);
    }
    return maxNodes[i];
}

int main(){
	int n , m;
	cin>>n>>m;
	vector<int>g[n + 1];
	for(int i = 0; i < m; i++){
	    int u , v;
	    cin>>u>>v;
	    g[u].push_back(v);
	}
	int maxNodes[n + 1];
	for(int i = 0; i <= n; i++){
	    maxNodes[i] = 0;
	}
	for(int i = 1; i <= n; i++){
	    if(maxNodes[i] == 0){
	        dfs(i , g , maxNodes , 0);
	    }
	}
	int ans = 0;
	for(int i = 0; i <= n; i++){
	    ans = max(ans , maxNodes[i]);
	}
	ans -= 1;
	cout<<ans;
}

Measured memory_bytes: 12028
#include <bits/stdc++.h>
#define mid (tl+tr)/2
#define mod 1000000007
#define fain(arr) for(int i=0;i<n;i++)cin>>arr[i];
#define all(x) x.begin(),x.end()
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bugv(n1) if(DEBUG)cout<<#n1<<" is "<<n1<<'\n';
#define buga(A) cout<<#A<<" is :"<<endl ; for(auto x:A)cout<<x<<" "; cout<<endl;
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ll long long 
#define pii pair<int,int>
#define pll pair<long long ,long long >
#define pi acos(-1)
#define sz(x) ((int)x.size())
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define DEBUG true
using namespace std;

int main() {
  // FILE;
  SPEED;
  
  int n;
  cin>>n;
  ll w;
  cin>>w;

  ll wa[n];
  ll va[n];

  rep(i,0,n){
    cin>>wa[i];
    cin>>va[i];
  } 

  ll dp[n+1][100001];

  for(int i=0;i<=100000;i++){
    if(va[n-1]==i){
      dp[n-1][i]=wa[n-1];
    }
    else{
      dp[n-1][i]=LLONG_MAX;
    }
  }

  for(int i=n-2;i>=0;i--){

    for(int j=0;j<=100000;j++){

      ll o1 = dp[i+1][j];
      ll o2 = LLONG_MAX;
      ll o3 = LLONG_MAX;
      if(j-va[i]>=0){
        if(dp[i+1][j-va[i]]!=LLONG_MAX)
        o2=dp[i+1][j-va[i]]+wa[i];
      }
      if(j==va[i]){
        o3=wa[i];
      }
      dp[i][j]=min({o1,o2,o3});
    }

  }

  // for(int i=150;i>=0;i--){
  //   for(int j=0;j<n;j++){
  //     cout<<dp[j][i]<<" ";
  //   }
  //   cout<<endl;
  // }

  // for(int i=0;i<n;i++){
  //   for(int j=0;j<=30;j++){
  //     cout<<dp[i][j]<<" ";
  //   }
  //   cout<<endl;
  // }


  for(int i=100000;i>=0;i--){

    if(dp[0][i]<=w){
      cout<<i<<endl;
      break;
    }
  }

  

}

Measured memory_bytes: 78464
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val (d,x) = readLine()!!.split(" ").map{it.toInt()}
    var ans = x
    repeat(n){
        val a = readLine()!!.toInt()
        for(i in 1 .. d step(a)){
            ans++
        }
    }
    println(ans)
}

Measured memory_bytes: 37864
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    sx,sy,ex,ey = i_map()

    fp = "U"*(ey-sy)
    fr = "R"*(ex-sx)
    fd = "D"*(ey-sy)
    fl = "L"*(ex-sx)
    f = fp+fr+fd+fl

    fl = "L"
    sp = "U"*(ey-sy+1)
    fr = "R"*(ex-sx+1)
    fd = "D"
    sr = "R"
    sd = "D"*(ey-sy+1)
    sl = "L"*(ex-sx+1)
    p = "U"
    s = fl+sp+fr+fd+sr+sd+sl+p

    print(f+s)











if __name__=="__main__":
    main()


Measured memory_bytes: 9412
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;



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

	//input
	cin >> n;



	//calc
	string ans = "No";

	for (int a = 1; a <= 9; a++){
		for (int b = 1; b <= 9; b++){
			if (n == a * b){
				ans = "Yes";
				break;
			}
		}
	}

	//ans
	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
mod = 10**9 + 7

ans = 1
import string
A = [chr(i) for i in range(ord('a'), ord('z')+1)]
B = {}
for i in range(len(A)):
    B[A[i]] = i
C = [1] * 26

for i in range(n):
    C[B[s[i]]] += 1

for i in range(len(C)):
    ans = (ans * C[i]) % mod

print(ans-1)

# for i in range(n):
#     for j in range(26):
#         if j != B[s[i]]:
#             C[j] = ans * 2
#     ans += (ans - C[B[s[i]]])
#     print(C[:5],ans)

# print(ans-1)

Measured memory_bytes: 39408
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,m,ans;
int main(){
    cin >> n >> m;
    
    for(int i=1; i<=n; i++){
        for(int j=10; j<=m; j++){
            if(j % 10 >= 2 && j/10 >= 2 && (j%10) * (j / 10) == i){
                ans++;
            }
        }
    }
    cout << ans;
    
    
    
    return 0;
}


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

const int maxn = 1e5 + 5;

int n,cur;
long long m;
int h[maxn], child[maxn][2], bad[maxn];
char s[maxn];

int get(int x,int y) {
    if(child[x][y]==-1) {
        cur++;
        h[cur] = h[x]+1;
        child[x][y] = cur;
    }
    return child[x][y];
}

long long G(long long x) {
    long long ans = 1;
    while(x%2==0) x/=2, ans*=2;
    return ans;
}

int main() {
    int i,x,t,len;
    long long ans = 0;

    cur = 0;
    h[cur] = 0;
    memset(child,-1,sizeof(child));

    scanf("%d%lld",&n,&m);
    for(t=0;t<n;t++) {
        scanf(" %s",s);
        len = strlen(s);
        for(i=0,x=0;i<len;i++) x = get(x,s[i]-'0');
    }

    for(i=0;i<=cur;i++) {
        if((child[i][0]==-1 && child[i][1]!=-1) || (child[i][0]!=-1 && child[i][1]==-1)) {
            ans ^= G(m-h[i]);
        }
    }

    if(ans==0) printf("Bob");
    else printf("Alice");
}


Measured memory_bytes: 1536
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <string.h> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

struct Info
{
	string card;
	int point = {};
};

int main(){
    //std::ifstream in("resource/input.txt");
    //std::cin.rdbuf(in.rdbuf());
	Info taro, hanako;
	int n;
	cin >> n;
	REP(i,n)
	{
		cin >> taro.card >> hanako.card;

		if(taro.card > hanako.card)
		{
			taro.point += 3;
		}
		else if(taro.card < hanako.card)
		{
			hanako.point += 3;
		}
		else
		{
			taro.point += 1;
			hanako.point += 1;
		}
	}
	
	cout << taro.point << " " << hanako.point << endl;
	
	return 0;
}




Measured memory_bytes: 3180
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}


//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;

int main(){
  int h,w,k;cin>>h>>w>>k;
  vs c(h);rep(i,h)cin>>c[i];
  int ans=0;
  for (int tmp = 0; tmp < (1 <<h ); tmp++) {
  bitset<6> s(tmp);
  
     for(int tnp = 0; tnp < (1 << w); tnp++) {
       bitset<6> t(tnp);
       int cnt =0;
       for(int i=0; i<h;i++){
         for(int j=0; j<w; j++){
           if(!s.test(i) && !t.test(j)){
             if(c[i][j]=='#')cnt++;
           }
           
         }
       }
       if(cnt==k)ans++;       
      }
  }
  cout<<ans<<endl;
}







Measured memory_bytes: 3672
from heapq import*
i=input
for s in[0]*int(i()):
 n,*x=int(i()),[],[]
 for _ in'_'*n:k,l,r=t=[*map(int,i().split())];x[l>r]+=[[n-k,r,l],t][l>r],
 for x in x:
  h=[]
  for k,l,r in sorted(x):heappush(h,l-r);s+=l-(k<len(h)and heappop(h))
 print(s)

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

int main() {
    string S;
    cin >> S;
  int counter =0;
  if(S[0]=='o'){
    counter +=1;
  }
  if(S[1]=='o'){
    counter +=1;
  }
  if(S[2]=='o'){
    counter +=1;
  }
  cout<< 700 + 100*counter <<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl; 
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v)            for (auto i : v)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
#define pb(x)                 push_back(x)
#define bp(x)                 __builtin_popcount(x)
#define mp(x, y)              make_pair((x), (y))
#define fi                    first
#define se                    second
#define setp(x)               setprecision(x)
#define mset(m, v)            memset(m, v, sizeof(m))
#define sz(x)                 (int)(x.size())
static const int INF        = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD        = 1000000007;
static const double PI      = 3.14159265358979;

//#define int                   long long

typedef vector<double>        vd;
typedef vector<string>        vs;
typedef vector<bool>          vb;
typedef vector<int>           vi;
typedef pair<int, int>        pii;
typedef vector<pii>           vpii;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int _x; cin >> _x; return _x; }
      
vi aa, bb;
signed main() { 
        int a, b;
        while (cin >> a >> b) {
                aa.pb(a);
                bb.pb(b);
        }
        int ap = 0;
        int bp = 0;
        while (true) {
                vi g[110];
                while (aa[ap] != 0 && bb[bp] != 0) {
                        int a, b;
                        a = aa[ap];
                        b = bb[bp];
                        ap ++;
                        bp ++;
                        a --;
                        b --;
                        g[a].pb(b);
                        g[b].pb(a);
                }
                ap ++;
                bp ++;
                bool f = true;
                rep(i, 110) if (i != 0 && i != 1 && sz(g[i]) & 1) f = false;
                puts((sz(g[0]) & 1) && (sz(g[1]) & 1) && f ? "OK" : "NG"); 
                if (ap == sz(aa)) return 0;
                else continue;
        }
}               

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

A.sort()
B.sort()
C.sort()

def is_ok(arg, target, abc):
    if abc[arg] >= target:
        return True
    else:
        return False

def is_ok2(arg, target, abc):
    if abc[arg] > target:
        return True
    else:
        return False


def bict(left, right, target, abc, jug):

    while(right - left > 1):
        mid = (right + left)//2

        if jug(mid, target, abc):
            right = mid
        else:
            left = mid

    return right

cnt = 0
for b in B:
    a_min_index = bict(-1, N, b, A, is_ok)
    c_min_index = bict(-1, N, b, C, is_ok2)
    temp = (a_min_index - 1 + 1) * (N - c_min_index)
    cnt += temp

print(cnt)


Measured memory_bytes: 23328
#include<iostream>
#include<cstdio>
#include<math.h>
#define NGS 100000

using namespace std;

bool isPrime(int);

int main(){
  int N,Arrange[2][NGS],i,j,k,l,count=0;
 
  /* 
  for(i=0;i<NGS;i++){
    Arrange[0][i]=0;
    Arrange[1][i]=0;
  }
  */
  
  while( scanf("%d",&N)!=EOF){
    count=0;
    k=1;
    l=N;
    
    for(i=0;i<N;i++){
      Arrange[0][i]=k;
      k++;
      Arrange[1][i]=l;
      l--;
    }
      
    /*  for(i=0;i<N;i++){
      cout << Arrange[0][i];
    }
    cout << endl;
    
    for(i=0;i<N;i++){
      cout << Arrange[1][i];
    }    
    cout << endl;
    */

    for(i=0;i<N;i++){     
      if(isPrime(Arrange[0][i]) == true)
	{
	  if(isPrime(Arrange[1][i]) == true)count++;
	}
    }
    
    cout << count << endl;
    
    
    
  }
}


bool isPrime(int x){
  int i;

  // cout << x << endl;
  if(x<2)return false;
  else if(x == 2)return true;
  if(x%2 == 0)return false;
  int limit = (int)sqrt((double)x) +1;
  for(i=3;i<=limit;i+=2){
    if(x%i==0)return false;
  }
  return true;
}

Measured memory_bytes: 968
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> x(n);
    REP(i, n) cin >> x[i];

    ll ans = LINF;
    REP1(i, 100) {
        ll sum = 0;
        REP(j, n) {
            sum += (x[j] - i) * (x[j] - i);
        }
        chmin(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline

N=int(input())

xylist,yxlist=[],[]
par_dic={}
for i in range(N):
  x,y=map(int,input().split())
  xylist.append((x,y))
  yxlist.append((y,x))
  par_dic[(x,y)]=(x,y)
xylist.sort()
yxlist.sort()
#print(xylist)

elist=[]
for i in range(1,N):
  x1,y1=xylist[i-1]
  x2,y2=xylist[i]
  elist.append((min(abs(x2-x1),abs(y1-y2)),(x1,y1),(x2,y2)))
  y1,x1=yxlist[i-1]
  y2,x2=yxlist[i]
  elist.append((min(abs(x2-x1),abs(y1-y2)),(x1,y1),(x2,y2)))
#print(hq)
elist.sort(reverse=True)

def get_par(x):
  if x == par_dic[x]:
    return x
  else:
    par_dic[x] = get_par(par_dic[x])
    return par_dic[x]
def merge(x,y):
  par_x = get_par(x)
  par_y = get_par(y)
  if par_x != par_y:
    par_dic[par_y] = par_x
def is_same(x,y):
  return get_par(x) == get_par(y)

answer=0
while elist:
  d,p1,p2=elist.pop()
  #print(d,p1,p2)
  if not is_same(p1,p2):
    merge(p1,p2)
    answer+=d
  
print(answer)

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

#include <boost/multiprecision/cpp_dec_float.hpp>

namespace mp = boost::multiprecision;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	mp::cpp_dec_float_100 a,b,c;
	cin >>a >>b >>c;
	
	mp::cpp_dec_float_100 sa = mp::sqrt(a);
	mp::cpp_dec_float_100 sb = mp::sqrt(b);
	mp::cpp_dec_float_100 sc = mp::sqrt(c);
	
	sa += sb;
	if(sa < sc) puts("Yes");
	else puts("No");
	return 0;
}
	

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<queue>
#define null NULL
using namespace std;

struct Node
{
    int dl,dr,s;
    Node *pl,*pr;
};
int n,q;

void build(Node *&p,int l,int r)
{
    p=(Node *)malloc(sizeof(Node));
    p->dl=l,p->dr=r,p->s=0;
    p->pl=null,p->pr=null;
    int mid=(l+r)/2;
    if(r>l)
    {
        build(p->pl,l,mid);
        build(p->pr,mid+1,r);
    }
}
int query(Node *&p,int l,int r)
{
    if(p->dl==l &&p->dr==r)
        return p->s;
    int mid=(p->dl+p->dr)/2;
    if(r<=mid)
        return query(p->pl,l,r);
    else if(l>mid)
        return query(p->pr,l,r);
    else
        return query(p->pl,l,mid)+query(p->pr,mid+1,r);
}
void update(Node *&p,int x,int data)
{
    p->s+=data;
    if(p->dl==p->dr)//找到最后一个叶子节点
        return;
    int mid=(p->dl+p->dr)/2;
    if(x<=mid)
        update(p->pl,x,data);
    else
        update(p->pr,x,data);
}
int main()
{
    int i,type,tx,ty;
    Node *tree=null;
    scanf("%d%d",&n,&q);
    build(tree,0,n-1);
    for(i=0;i<q;i++)
    {
        scanf("%d%d%d",&type,&tx,&ty);
        tx--;
        if(type==0)
        {
            update(tree,tx,ty);
        }else
        {
            ty--;
            int ans=query(tree,tx,ty);
            printf("%d\n",ans);
        }
    }
    return 0;
}



Measured memory_bytes: 12584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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 ll MAX_V = 300;
// d[u][v]は辺（u, v)のコスト
vector<vector<ll> > d(MAX_V, vector<ll>(MAX_V, INF));
// 頂点数
ll V;

int perm[8];
ll MIN = INF;

void permutation(int n) {
    do {
        ll res = 0;
        // permに対する操作
        rep(i, n-1){
            res += d[perm[i]][perm[i+1]];
        }
        chmin(MIN, res);
    } while (next_permutation(perm, perm + n));
    return;
    
}

void warshall_floyd() {
    rep(k, V){
        rep(i, V){
            rep(j, V){
                chmin(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

// ---------------------------------------------------
// O(|V|^3) すべての２頂点間の最短路を求める(ワーシャル・フロイド法)
// ---------------------------------------------------

int main(){
    ll E, a, b, cost, R;
    cin >> V >> E >> R;
    rep(i, R){
        cin >> a;
        a--;
        perm[i] = a;
    }
    sort(perm, perm+R);

    // 対角線は0に設定(それ以外はINF)
    rep(i, V){
        d[i][i] = 0;
    }
    rep(i, E){
        cin >> a >> b >> cost;
        a--; b--; //0-index
        d[a][b] = cost;
        d[b][a] = cost;
    }
    // 実行
    warshall_floyd();

    permutation(R);
    cout << MIN << endl;
}

Measured memory_bytes: 4348
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int a,b;
    while(cin>>s)
    {
        a=0;
     int    f=1;
        int  c,d,e;
        b=s.size()-1;
        for(c=0,d=b;c<=b;c++,d--)
        {
            if(s[c]!=s[d])
            {
                f=0;
            }

        }
        if(f==1)
        {
            int p,q;
            p=(s.size()-1)/2.;
            p--;
            f=1;
            for(c=0,d=p;c<=p;c++,d--)
            {
                if(s[c]!=s[d])f=0;
            }
            if(f==1)
            {

                 int p,q;
            p=(s.size()+3)/2.;
            p--;
            f=1;
            for(c=p,d=s.size()-1;c<s.size();c++,d--)
            {
                if(s[c]!=s[d])f=0;
            }
            if(f==1)
            {
                cout<<"Yes"<<endl;
            }
            else
            {
                cout<<"No"<<endl;
            }



            }
            else cout<<"No"<<endl;





        }
        else cout<<"No"<<endl;


    }











    return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	int n,max_r;
	char buf[1001];

	int** table = new int*[1001];
	for(int i = 0; i < 1001; i++)table[i] = new int[1001];
	for(int i = 0; i < 1001; i++){
		table[0][i] = 0;
		table[i][0] = 0;
	}

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		max_r = 0;

		for(int i=0; i < n; i++){
			scanf("%s",buf);
			for(int k= 0;buf[k]!= 0; k++){
				if(buf[k] == '.'){
					table[i+1][k+1] = min(table[i][k],min(table[i][k+1],table[i+1][k]))+1;
					max_r = max(max_r,table[i+1][k+1]);
				}else{
					table[i+1][k+1] = 0;
				}
			}
		}

		printf("%d\n",max_r);
	}

    return 0;
}

Measured memory_bytes: 6608
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

int main() {
	IOS();
	ll r, g, b, n;
	cin >> r >> g >> b >> n;
	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			ll sum = i * r + j * g;
			if (n - sum >= 0 && (n - sum) % b == 0) ans++;
		}
	}
	dump(ans);
	return 0;
}

Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
N = ri()
print(N // 3)

Measured memory_bytes: 63084
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int LINF=1e18;
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}

signed main(){
  int n;cin>>n;
  int ans=-LINF,m=LINF;
  while(n--){
    int a;cin>>a;
    chmax(ans,a-m);
    chmin(m,a);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  pair<int,int> a[200000];
  int ans[200000];
  int mx=0,mxcnt=1,nxt=0;
  rep(i,n){
    int num;
    cin>>num;
    a[i]=make_pair(num,i);
  }
  sort(a,a+n);
  rep(i,n){
    if(i!=n-1){
      ans[a[i].scd]=a[n-1].fst;
    }else{
      ans[a[i].scd]=a[n-2].fst;
    }
  }
  rep(i,n){
    cout<<ans[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 6272
#if defined(__GNUC__)
#include <bits/stdc++.h>
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {if(b == 0){return 1;} int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {if(b == 0){return 1;} int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)

itn main() {
	std::ios::sync_with_stdio(false);

	itn h, w, n;

	cin >> h >> w >> n;

	itn up = max(h, w);

	itn res = n / up;

	if (n % up) {
		++res;
	}

	cout << res;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


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

    if(n==1){
        int c;
        cin >> c;
        cout << '0' << endl;
        return 0;
    }

    vector<int> v[n];

    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    int c[n];
    rep(i,n){
        cin >> c[i];
    }
    sort(c,c+n);

    queue<int> que;
    int d[n] = {};
    int count = n-1;
    d[0] = c[count];
    count--;
    que.push(0);

    while(!que.empty()){
        int x = que.front();
        que.pop();
        rep(i,v[x].size()){
            if(d[v[x][i]]==0){
                d[v[x][i]] = c[count];
                count--;
                que.push(v[x][i]);
            }
        }
    }

    ll ans = 0;
    rep(i,n-1){
        ans += c[i];
    }
    cout << ans << endl;
    rep(i,n){
        cout << d[i] << ' ';
    }
    cout << endl;

    return 0;
}
 
 


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    int cnt=0;
    for(int i=0; i<N; i++){
        if(i+1==a[a[i]-1]) cnt++;
    }
    cout << cnt/2;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=Integer.parseInt(in.next()),A[]=new int[n];
		for(int i=0;i<n;i++)A[i]=Integer.parseInt(in.next());
		
		int q=Integer.parseInt(in.next());
		for(int i=0;i<q;i++) {
			int b=Integer.parseInt(in.next()),e=Integer.parseInt(in.next());
			reverse(A,b,e);
		}
		for(int i=0;i<n-1;i++)System.out.print(A[i]+" ");
		System.out.println(A[n-1]);
	}
	
	static void reverse(int A[],int b,int e) {
		for(int i=0;i<(e-b)/2;i++) {
			int tt=A[e-1-i];
			A[e-1-i]=A[b+i];
			A[b+i]=tt;
		}
	}

}


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

const ll INF = 1LL << 60;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    ll place1;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] == 1) place1 = i+1;
    }
    //最小値は1＝＞1を全体に広げていく
    ll count = (N+K-3)/(K-1);
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1024
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

x, y, z = MAP()
print(z, x, y)

Measured memory_bytes: 61804
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		char[] s = sc.next().toCharArray();
		for (int i = 0; i < s.length; i++) {
			if (s[i] == 'A') {
				sb.append('T');
			} else if (s[i] == 'T') {
				sb.append('A');
			} else if (s[i] == 'C') {
				sb.append('G');
			} else if (s[i] == 'G') {
				sb.append('C');
			}
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }

main()
{
    ll a,b,c,d; cin>>a>>b>>c>>d;
    ll x,y;

    a--;
    x=a-a/c-a/d+a/lcm(c,d);
    y=b-b/c-b/d+b/lcm(c,d);
    cout<<y-x<<endl;
}

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

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

	set<int> st;
	while(q--){
		int query,y;cin>>query>>y;
		if(query==0){
			// insert
			st.insert(y);
			cout<<st.size()<<endl;
		}else{
			cout<<(st.find(y)!=st.end()?1:0)<<endl;
		}
	}
  return 0;
}



Measured memory_bytes: 12428
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=3e3+50;
const ll mod=1e9+7;
using namespace std;
int n,t,i,j,f[nmax][2*nmax],rs;
pair<int,int>a[nmax];
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>t;
	t--;
	for(i=1;i<=n;i++)cin>>a[i].fr>>a[i].sc;
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++)
	{
		for(j=0;j<=t+a[i].fr;j++)
		{
			f[i][j]=f[i-1][j];
			if(a[i].fr<=j)
			{
				f[i][j]=max(f[i][j],f[i-1][j-a[i].fr]+a[i].sc);
			}
			rs=max(rs,f[i][j]);
		}
	}
	cout<<rs<<endl;
	return 0;
}


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

int main() {

    ll x, y, a, b, c; cin >> x >> y >> a >> b >> c;
    vector<ll> p_(a), q_(b);
    for (ll i = 0; i < a; i++) {
        cin >> p_[i];
    }
    for (ll i = 0; i < b; i++) {
        cin >> q_[i];
    }
    vector<pair<ll, string>> pa;
    sort(p_.rbegin(), p_.rend());
    for (ll i = 0; i < x; i++) {
        pa.push_back({ p_[i], "red" });
    }
    sort(q_.rbegin(), q_.rend());
    for (ll i = 0; i < y; i++) {
        pa.push_back({ q_[i], "green" });
    }
    for (ll i = 0; i < c; i++) {
        ll r; cin >> r;
        pa.push_back({ r,"non" });
    }
    sort(pa.rbegin(), pa.rend());
    ll ans = 0;
    for (ll i = 0; i < x + y; i++) {        
        if (pa[i].second == "non" && 0 < c) {
            ans += pa[i].first;
            c--;
        }
        else if (pa[i].second == "non" && 0 == c) continue;
        else {
            ans += pa[i].first;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> drink(N);
    int A, B;
    for (int i = 0; i < N; i++) {
        cin >> A >> B;
        drink[i] = make_pair(A, B);
    }

    sort(drink.begin(), drink.end());
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        int tmp = min(drink[i].second, M);
        ans += (long long)drink[i].first * tmp;
        M -= tmp;
        if (M == 0) break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024