akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let (A, B): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let mut ans = 0;
    let mut k = 1;
    for i in 0..B {
        if k >= B {
            break;
        }
        k += A - 1;
        ans += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>

int cmp_rw(int r, int w){
  if(r>=w){
    return r;
  }else{
    return w;
  }
}

int main(){
  int n,i,w=0,r=0,min;
  scanf("%d",&n);

  char c[n+1];
  scanf("%s",c);

  for(i=0;i<n;i++){
    if(c[i]=='R'){
      r++;
    }
  }

  min = cmp_rw(r,w);

  for(i=0;i<n;i++){
    if(c[i]=='W'){
      w++;
    }else if(c[i]=='R'){
      r--;
    }
    if(cmp_rw(r,w)<min){
      min = cmp_rw(r,w);
    }
  }

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

  return 0;
}

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

using namespace std;

int main() {
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < s.size() / 2; i++)
		if (s[i] != s[s.size() - 1 - i])
			cnt++;
	cout << cnt << endl;
	return 0;
}

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

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

ll MOD = 1000000007;

struct seg{
	int siz;
	int s[1<<21];
	void init(){
		siz = 1<<20;
		for(int i = 0 ; i < 2*siz-1 ; i ++){
			s[i] = 0;
		}
	}
	void add(int a,int b,int x,int k,int l,int r){
		if(b <= l || r <= a)return;
		if(a <= l && r <= b){
			s[k] += x;
			return;
		}
		add(a,b,x,2*k+1,l,(l+r)/2);
		add(a,b,x,2*k+2,(l+r)/2,r);
	}
	int query(int a,int k,int l,int r){
		if(a+1 <= l || r <= a)return 0;
		if(l == a && r == a+1){
			int ret = s[k];
			s[k] = 0;
			return ret;
		}
		if(s[k] != 0){
			add(l,r,s[k],2*k+1,l,(l+r)/2);
			add(l,r,s[k],2*k+2,(l+r)/2,r);
			s[k] = 0;
		}
		return query(a,2*k+1,l,(l+r)/2)+query(a,2*k+2,(l+r)/2,r);
	}
}seg;

ll f(ll n){
	if(n == 0)return 1;
	ll ret = f(n-1);
	ret *= 2;
	if(ret >= MOD)ret -= MOD;
	return ret;
}

int main(){
	static int n;
	static int a[500010];
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("%d",&a[i]);
	}
	
	static ll dp[1<<20][2];
	for(int i = 0 ; i < (1<<20) ; i ++){
		dp[i][0] = 1;
		dp[i][1] = 0;
	}
	ll sum = 0;
	int cnt = 0;
	seg.init();
	for(int i = 0 ; i < n ; i ++){
		sum ^= a[i];
		if(sum == 0){
			seg.add(0,1<<20,1,0,0,seg.siz);
			cnt ++;
		}
		else {
			int t = seg.query(sum,0,0,seg.siz);
			dp[sum][0] += dp[sum][1]*t;
			dp[sum][0] %= MOD;
			dp[sum][1] += dp[sum][0];
			if(dp[sum][1] >= MOD)dp[sum][1] -= MOD;
		}
		//cout << sum << " ";
	}
	//cout << endl;
	if(sum == 0){
		ll ret = 0;
		for(int i = 1 ; i < (1<<20) ; i ++){
			//int t = seg.query(i,0,0,seg.siz);
			//ret += dp[i][1]*t;
			//if(i <= 15)cout << i << ":" << dp[i][1] << " " << t << endl;
			ret += dp[i][1];
		}
		//cout << cnt << " " << ret << endl;
		//cout << f(8) << endl;
		ret += f(cnt-1);
		cout << ret%MOD << endl;
	}
	else {
		cout << dp[sum][0] << endl;
	}
}


Measured memory_bytes: 34560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a; //　n = 合計　a = １円の枚数
  cin >> n >> a;
  if( n % 500 <= a ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
X, N = map(int, input().split())
p = list(map(int, input().split()))
l = [0] * 102
k = 999

for i in range(0, 101):
  for j in range(N):
    if p[j] == i:
      l[i] = 1
    j = j+1
  i = i+1
for i in range(-1, 101):
  i = i+1
  if l[i] == 1:
    continue
  k = min(k, abs(X-i))

if l[X-k] == 1:
    print(X+k)
else:
    print(X-k)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*/
#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
    vector <string> v;
    stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x);
    return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
    cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
    err(++it, args...);
}
 
int ini(){int x; scanf("%d",&x);return x;}
long long inl(){ long long x;scanf("%lld",&x); return x;}
double ind(){double x; scanf("%lf",&x);return x;}
#define Iin ini();
#define Lin inl();
#define Din ind();

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;

int a[N];

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int t=1,te=0;

    while(t--){
        int res=0;
        string s;

        cin>>s;

        for(int i=0,j=(int)s.size()-1;i<j;i++,j--){
            if(s[i]!=s[j])res++;
        }

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


        //printf("Case %d: ",++te);
    }
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<deque>
#include<map>
#include<utility>
using namespace std;
int main(void){
    int n;cin >> n;
    deque<deque<int>> a(n);
    deque<pair<int,int>> w(n);
    map<int,int> m;
    for(int i = 0; i < n - 1; i++){
        int x,y;cin >> x >> y;x--;y--;
        a[x].push_back(y);
        w[i] = make_pair(x,y);
        }
    deque<int> k;
    k.push_back(0);
    map<pair<int,int>,int> z;
    int ma = 0;
    while(!k.empty()){
        int p = k.front();
        int t = 0;
        for(int i = 0; i < int(a[p].size()); i++){
            t++;
            k.push_back(a[p][i]);
            if(p > 0 && t == m[p]) t++;
            pair<int,int> f = make_pair(p,a[p][i]);
            z.insert(make_pair(f,t));
            m.insert(make_pair(a[p][i],t));
            }
        ma = max(ma, t);    
        k.pop_front();    
        }
    cout << ma << "\n";    
    for(int i = 0; i < n - 1; i++) cout << z[w[i]] << "\n";    
    }

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

#define ll long long
#define pb push_back

vector<int>g[100003];
vector<int>v(100003);
queue<int>q;

int main()
{
    ll n,k;
    cin>>n>>k;
    ll c=0;
    for(int i=0;i<n;i++)
    {
        ll p,q;
        cin>>p>>q;
        if(sqrt(p*p+q*q)<=k)
        {
            c++;
            //cout<<sqrt(p*p+q*q)<<endl;
        }
        
    }
    cout<<c<<endl;
}











Measured memory_bytes: 6068
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;


int main(void) {
	int n;
	cin >> n;
	vector<string> u(n);
	vector<double> x(n);
	REP(i, n) cin >> x[i] >> u[i];
	double sum = 0;
	REP(i, n) {
		if (u[i] == "BTC") {
			x[i] = 380000.0*x[i];
		}
		sum += x[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import permutations
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
ans = 0
li = list(permutations(range(N)))
l = len(list(permutations(range(N))))
for i in li:
    for j in range(N-1):
        x1, x2 = xy[i[j]][0], xy[i[j+1]][0]
        y1, y2 = xy[i[j]][1], xy[i[j+1]][1]
        ans += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
print(ans/l)

Measured memory_bytes: 18792
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, K;
    cin >> A >> B;

    if ((A + B) % 2 == 0)
    {
        cout << (A + B) / 2 << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;

int main(){
  int a,b;
  string s;
  cin >> a >> b >> s;
  
  bool flag=true;
  
  if(s.length() != a+b+1) flag = false;
  
  rep(i,a){
    if(!isdigit(s[i])) flag = false;
  }
  if(s[a]!='-') flag=false;
  rep2(i,a+1,a+b+1){
    if(!isdigit(s[i])) flag = false;
  }
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
k,n = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
abs_arr = []
(n-1).times do |i|
  abs_arr << (arr[i+1] - arr[i]).abs
end
abs_arr << k - arr[-1] + arr[0]

abs_arr.sort!
puts abs_arr[0..-2].inject(&:+)

Measured memory_bytes: 19200
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
	cout << max(60 * (h2 - h1) + m2 - m1 - k, 0);

	return 0;
}

Measured memory_bytes: 3600
import java.util.*;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        long[] H = new long[N+1];
        for(int i = 1; i <= N; i++) {
            H[i] = Long.parseLong(sc.next());
        }
        
        int[] isgood = new int[N+1]; //goodなら0 badなら1
        
        for(int i = 0; i < M; i++) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            if(H[a] < H[b]) {
                isgood[a] = 1;
            }else if(H[a] == H[b]) {
                isgood[a] = 1;
                isgood[b] = 1;
            }else {
                isgood[b] = 1;
            }
        }
        
        int count = 0;
        for(int i = 1; i <= N; i++) {
            if(isgood[i] == 0) {
                count++;
            }
        }
        System.out.println(count);
        
        
        
    }
}

Measured memory_bytes: 60572
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long q,h,s,d;
    cin >> q >> h >> s >> d;
    long long n;
    cin >> n;
    vector <long long> perDouble(4);
    perDouble[0] = q*4*2;
    perDouble[1] = h*2*2;
    perDouble[2] = s*1*2;
    perDouble[3] = d;
    long long price = perDouble[0];
    int bestPriceIndex = 0;
    for(int i = 1; i < 4; i++){
        if(price > perDouble[i]){
            price = perDouble[i];
            bestPriceIndex = i;
        } 
    }
    long long ans = 0;
    switch (bestPriceIndex)
    {
    case /* constant-expression */0:
        /* code */
        ans = n*q*4;
        break;
    case /* constant-expression */1:
        /* code */
        ans = n*h*2;
        break;
    case /* constant-expression */2:
        /* code */
        ans = n*s;
        break;
    case /* constant-expression */3:
        /* code */
        if(n%2==0){
            ans = n*d/2;
        }else{
            long long price = perDouble[0];
            int bestPriceIndex = 0;
            for(int i = 1; i < 3; i++){
                if(price > perDouble[i]){
                    price = perDouble[i];
                    bestPriceIndex = i;
                } 
            }
            if(n==1){
                switch (bestPriceIndex)
                {
                case /* constant-expression */0:
                    /* code */
                    ans = q*4;
                    break;
                case /* constant-expression */1:
                    /* code */
                    ans = h*2;
                    break;
                case /* constant-expression */2:
                    /* code */
                    ans = s;
                    break;
                default:
                    break;
                }
            }else{
                ans = (n-1)/2*d;
                switch (bestPriceIndex)
                {
                case /* constant-expression */0:
                    /* code */
                    ans += q*4;
                    break;
                case /* constant-expression */1:
                    /* code */
                    ans += h*2;
                    break;
                case /* constant-expression */2:
                    /* code */
                    ans += s;
                    break;
                default:
                    break;
                }
            }

        }
        break;
    default:
        break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
N = int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]

count = 0

for i in range(N):
  if x[i] == y[i]:
    count += 1
    if count == 3:
      print("Yes")
      exit()
    
  else:
    count = 0
    
  
print("No")


Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"

    
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    ll n;
    ll k;
    cin>>n>>k;
    ll a[n];
    rep(i,n)cin>>a[i];
    ll sum=0;
    sort(a,a+n);
    rep(i,k)sum+=a[i];
    cout<<sum;

}




Measured memory_bytes: 3660
max_n=10**6
mod=10**9+7

frac=[1]
for i in range(1,max_n+1):
  frac.append((frac[-1]*i)%mod)

inv=[1,1]
inv_frac=[1,1]
for i in range(2,max_n):
  inv.append((mod-inv[mod%i]*(mod//i))%mod)
  inv_frac.append((inv_frac[-1]*inv[-1])%mod)
  
def perm(m,n):
  if m<n:
    return 0
  if m==1:
    return 1
  return (frac[m]*inv_frac[m-n])%mod

def comb(m,n):
  if m<n:
    return 0
  if m==1:
    return 1
  return (frac[m]*inv_frac[n]*inv_frac[m-n])%mod  

n,k=map(int,input().split())
s=0
for i in range(0,min(n,k+1)):
  s=(s+comb(n,i)*comb(n-1,i))%mod
print(s)
  

Measured memory_bytes: 166260
# -*- coding: utf-8 -*-
import logging
import time


class Solver:
    def __init__(self):
        self.a = 0
        self.b = 0

    # 入力
    def input_value(self):
        # self.n = int(input())
        # self.A, self.B = map(int, input().split())
        # self.A = list(map(int, input().split()))
        # self.a, self.b, self.c = map(int, [input() for i in range(4)])
        # self.t = [None] * self.n
        self.a, self.b = map(int, input().split())

    @staticmethod
    def run(a, b):
        return a * b - a - b + 1

    @staticmethod
    def test():
        start_time = time.time()

        assert Solver.run(2) == 2, 'Error.'

        elapsed_time = time.time() - start_time
        logging.debug('elapsed_time: {0}'.format(elapsed_time) + '[sec]')


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)

    solver = Solver()
    # Solver.test()

    solver.input_value()
    ans = solver.run(solver.a, solver.b)
    print(str(ans))


Measured memory_bytes: 4712
from functools import lru_cache


@lru_cache(maxsize=None)
def solve(x, y):
    if (x**2 + y**2) <= d**2:
        return 1
    else:
        return 0


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

ans = 0
for _ in range(n):
    x, y = map(int, input().split())
    ans += solve(x, y)

print(ans)

Measured memory_bytes: 47044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll k;
  cin >> k;
  vll a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[k - 1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int main(){int a,b;cin>>a>>b;char c[a][b];int d[a+2][b+2];for(int i=0;i<a;i++){for(int j=0;j<b;j++){cin>>c[i][j];if(c[i][j]=='.') d[i][j]=0;if(c[i][j]=='#') d[i][j]=1;}}for(int i=0;i<a;i++){for(int j=0;j<b;j++){if(d[i][j]==1&&(i==0||d[i-1][j]==0)&&(i==a-1||d[i+1][j]==0)&&(j==0||d[i][j-1]==0)&&(j==b-1||d[i][j+1]==0)){cout<<"No";return 0;}}}cout<<"Yes";return 0;}

Measured memory_bytes: 256
while True:
  n, x = map(int, input().split())
 
  if n == 0 and x == 0:
    break
 
  ans = 0
 
  for i in range(1,n+1):
    for j in range(i+1,n+1):
      k = x-(i+j)
      if k >= 1 and k <= n and k > j:
        ans += 1
 
  print(ans)


Measured memory_bytes: 5596
fun main(args: Array<String>){
    val (n,k) = readLine()!!.split(" ").map(String::toInt)
    val max = (n-1)*(n-2)/2

    if(max < k){
        println(-1)
        return
    }

    val redu = if(k < max) max-k else 0
    var count = 0
    println(n-1+redu)

    for(i in 1..n){
        for(j in i+1..n){
            println("$i $j")
            count++
            if(count == n-1+redu){
                return
            }
        }
    }
}

Measured memory_bytes: 36620
#include <cstdio>

int main(void)
{
    long long n,a,b,c;

    scanf("%lld",&n);

    for(c = 1;c * c <= n;++c)
        if((n % c) == 0)
            a = n / c;

    b = 0;
    while(a)
        ++b,a /= 10;
    printf("%lld\n",b);
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a*b>=c*d){
        printf("%d\n",a*b);
    }
    else{
        printf("%d\n",c*d);
    }
    return 0;
}

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

int howm(ll a,ll int level,int k)
{
    if (a%(1<<level)==0&&(a/(1<<level))%k==0)
        {
            return (a/(1<<level))/k-1;
        }
    else 
        return ((1.0*a)/(1<<level))/k;
}
bool check(int len,vector<ll int>&arr,int k)
{
    ll int tot=0;
    for (int c=arr.size()-1;c>=0;c--)
        {
            ll a=1;
            ll tot_temp=0;
            ll min_ans=1000000001;
            for (int level=0;true;level++)
                {
                    min_ans=min(min_ans,(1<<level)-1LL+(1<<level)*howm(arr[c],level,len));
                    if ((1.00*arr[c])/a<=len)
                        {tot_temp+=(1<<level)-1;break;}

                    a*=2;
                }
                tot+=min(tot_temp,min_ans);
        }
        return tot<=k;
}
void solve()
{
  int n,k;
  cin >> n >> k;
  vector<ll int>arr(n);
  for (int c=0;c<n;c++)
    cin >> arr[c];
    sort(arr.begin(),arr.end());
  int i=1,j=1000000000;
  while(j-i>1)
    {
        int mid=(i+j)/2;
        if (check(mid,arr,k))
            j=mid;
        else i=mid;
    }
    if (check(i,arr,k))
        cout << i << endl;
    else cout << j << endl;
}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);     
    int t;
    //cin >> t;
    t=1;
    for (int tt=0;tt<t;tt++)
        {
            solve();
        }    
        return 0;
}

Measured memory_bytes: 4784
#include <stdio.h>

int main() {

    int N;
    int i;
    int a_count;
    int b_count;
    int c_count;

    scanf("%d", &N);

a_count = 0;

    while(N / 100 > 0) {
        N -= 100;
        a_count++;
        //printf("N = %d\n", N);
    }

    b_count = 0;

    while(N / 10 > 0) {
        N -= 10;
        b_count++;
        //printf("N = %d\n", N);
        }

        c_count = 0;

    while(N > 0) {
        N--;
        c_count++;
        //printf("N = %d\n", N);
    }
       //printf("%d %d %d\n",a_count, b_count, c_count);
    if(a_count == 7 || b_count == 7 || c_count == 7) {
        printf("Yes\n");
    }
        else {
            printf("No\n");
        }
            
        return 0;
    }

Measured memory_bytes: 1648
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	in(ll, N, D, X);
	ll t;
	loop(i, N) {
		cin >> t;
		X += D / t + !!(D%t);
	}
	out(X);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int PMAX = 20000000;
int main(){
  int N,M,X,i,j,k;
  cin >> N >> M >> X;
  vector<int> c(N);
  vector<int> s(M);
  vector<vector<int>> A(N,vector<int>(M));
  for(i=0;i<N;i++){
    cin >> c[i];
    for(j=0;j<M;j++)
      cin >> A[i][j];
  }
  int N2 = 1;
  N2 <<= N;
  int scm = PMAX;
  for(i=0;i<N2;i++){
    int sc = 0;
    for(k=0;k<M;k++)
      s[k] = 0;
    for(j=0;j<N;j++){
      if (i & (1 << j)){
        sc += c[j];
        for(k=0;k<M;k++)
          s[k] += A[j][k];
      }
    }
    bool xf = true;
    for(k=0;k<M;k++)
      if (s[k] < X){
        xf = false;
        break;
      }
    if (xf)
      scm = min(scm,sc);
  }
  if (scm != PMAX)
	  cout << scm << "\n";
  else
	  cout << "-1\n";
    

  return 0;
}

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

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

int main(){
  int n,x,X;
  cin>>n>>x;
  vector<long> k(n);
  for(int i=0;i<n;i++){
    cin>>X;
    if (X-x<0){
      k[i] = -(X-x);
    }else{
      k[i] = X-x;
    }
  }
  long f=k[0];
  for(int i=0;i<n-1;i++){
    f = __gcd(f,k[i+1]);
  }
  cout<<f<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)
#define INF 1<<9

int main()
{
	int n;
	cin >> n;
	vector<int> a;
	vector<int> front, back;
	REP(i, 0, n) {
		int aa;
		cin >> aa;
		a.push_back(aa);
	}

	bool left = true;
	RREP(i, 0, a.size()) {
		if (left) {
			front.push_back(a[i]);
			left = false;
		}
		else {
			back.push_back(a[i]);
			left = true;
		}
	}

	REP(i, 0, front.size()) cout << front[i] << endl;
	RREP(i, 0, back.size()) cout << back[i] << endl;
	
	return 0;
}

Measured memory_bytes: 4212
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std;
long long  a[100010],c[100010];
int main(){
	int n;
	long long sum=1;
	long long b=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(a[i]==a[i+1])sum++;
		else{
			if(sum<a[i])b+=sum;
			else if(sum>a[i])b+=sum-a[i];
			sum=1;
	}
	}
	printf("%lld\n",b);
}

		


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

#define N 110
int n, a[N], x;


int main() {
	while (scanf("%d%d", &n, &x) != EOF) {
		for (int i = 1; i <= n; ++i) {
			scanf("%d", a + i);
		}
		int res = 1;
		int y = 0;
		for (int i = 1; i <= n; ++i) {
			y += a[i];
			if (y <= x) {
				++res;
			}
		}
		printf("%d\n", res);
	}
	return 0;
}


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

using namespace std;

int main(){
    int x,y,z,ans = 0;
    cin >> x >> y >> z;

    x -= z;

    while(x >= y+z){
        ans++;
        x -= (y+z);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F(a,b,c,d) for (register int a=b;a<=c;a+=d)
#define FD(a,b,c,d) for (register int a=b;a>=c;a-=d)
using namespace std;
int main(){
	int n;
	cin>>n;
	if (n<1000)  cout<<"ABC"<<endl;
	else cout<<"ABD"<<endl;
	return 0;
}



Measured memory_bytes: 256
a,b= map(int, input().split())
if(b==0):
    print(a)
else:
    L=list(map(int,input().split(" ")))
    if(a not in L):
       print(a)
    else:
       i=int(1)
       while(True):
          if((a-i) not in L):
             print(a-i)
             break
          elif((a+i) not in L):
             print(a+i)
             break
          i+=1



Measured memory_bytes: 9156
#include <iostream>
#include <string.h>

using namespace std;
char str[101];
int main(){
	cin >> str;
	int len = strlen(str);
	bool jud1 = false, jud2 = false;
	for(int i=0; i<len; i++){
		if(str[i] == 'C') jud1 = true;
		if(str[i] == 'F' && jud1 == true) jud2 = true;
	}
	if(jud2 == true) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;


int main(){
 

 long double a,b,x; cin >> a >> b >> x;

 double th,ta,pi;pi = acos(-1);
 if (x > a*a*b/2)
 {
    ta = (a*a*b-x)*2/(a*a*a);
    th = atan(ta);
   
 }
 else
 {
    ta = a*b*b/(2*x);
    th = atan(ta);
 }
 th = th * 180/pi;

 printf("%.10lf\n",th);
 

return 0;
}


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

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

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

# A~Z -- START --
l=['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']
# A~Z --- END ---

def main():
  n=I()
  s=S()

  ans=''
  for x in s:
    t=l.index(x)
    ans+=l[(t+n)%26]
  return ans

# main()
print(main())


Measured memory_bytes: 6480
#include<stdio.h>
int main()
{
    int N;
    float m;
    scanf("%d",&N);
    if(N%2==0)
    {
        m=0.5;
        printf("%.10f\n",m);
    }

    else
    {
        m=((N+1)/2)/(float)N;
        printf("%.10f",m);
    }
    return 0;
}

Measured memory_bytes: 128
local n = io.read("*n")
local c = 0LL + io.read("*n")
local x, v = {}, {}
for i = 1, n do
  x[i] = 0LL + io.read("*n")
  v[i] = 0LL + io.read("*n")
end

local score_forward = {v[1] - x[1]}
do
  local cur = score_forward[1]
  for i = 2, n do
    cur = cur + v[i] - (x[i] - x[i - 1])
    if score_forward[i - 1] < cur then
      score_forward[i] = cur
    else
      score_forward[i] = score_forward[i - 1]
    end
  end
end

local score_backward = {}
do
  for i = 1, n do score_backward[i] = 0LL end
  score_backward[n] = v[n] - (c - x[n])
  local cur = score_backward[n]
  for i = n - 1, 1, -1 do
    cur = cur + v[i] - (x[i + 1] - x[i])
    if score_backward[i + 1] < cur then
      score_backward[i] = cur
    else
      score_backward[i] = score_backward[i + 1]
    end
  end
end

local ret = 0LL
for i = 1, n do
  local scorecand = score_forward[i]
  if ret < scorecand then
    ret = scorecand
  end
  if i < n then
    scorecand = scorecand - x[i] + score_backward[i + 1]
    if ret < scorecand then
      ret = scorecand
    end
  end
end
for i = n, 1, -1 do
  local scorecand = score_backward[i]
  if ret < scorecand then
    ret = scorecand
  end
  if 1 < i then
    scorecand = scorecand - (c - x[i]) + score_forward[i - 1]
    if ret < scorecand then
      ret = scorecand
    end
  end
end
local str = tostring(ret):gsub("LL", "")
print(str)


Measured memory_bytes: 17516
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scan_init()
	n := scanInt()
	// 10^13
	// 26ずつ動いている
	// waruN := n/26
	// fmt.Println(waruN)
	// 1 ~ 26 (i
	// (i+1) -> (i+1)*26
	//桁数調べるsiraberu
	keta := 0
	niroku := 0
	hazimariniroku := 1
	for {
		niroku += 1 // 最初に1をタス
		niroku = niroku* 26
		if n > niroku {
			keta ++
			hazimariniroku = niroku + 1
			continue
		}
		break
	}
	keta ++ //1桁目が0となっているので
	// 桁がわかれば
	// 27進数なのはわかるので、
	// ziyouhou := hazimariniroku //始まりnirokuはその桁の最初のなので前の桁の最後を取得したいので+1
	outputstring := []string{}
	value := n - hazimariniroku
	for i:= 1; i<=keta; i++ {
		take := value % 26
		// fmt.Println("value", value)
		outputstring = append(outputstring,toAlpher(take))
		value /= 26
	}
	output := ""
	for i:= len(outputstring)-1; i>= 0; i-- {
		output = output + outputstring[i]
	}
	fmt.Println(output)
}
var sc = bufio.NewScanner(os.Stdin)
func toAlpher (a int) string{
	switch a {
	case 0:
		return "a"
		break
	case 1:
		return  "b"
		break
	case 2:
		return  "c"
		break
	case 3:
		return "d"
		break
	case 4:
		return "e"
		break
	case 5:
		return "f"
		break
	case 6:
		return "g"
		break
	case 7:
		return "h"
		break
	case 8:
		return  "i"
		break
	case 9:
		return  "j"
		break
	case 10:
		return  "k"
		break
	case 11:
		return  "l"
		break
	case 12:
		return  "m"
		break
	case 13:
		return  "n"
		break
	case 14:
		return "o"
		break
	case 15:
		return "p"
		break
	case 16:
		return "q"
		break
	case 17:
		return "r"
		break
	case 18:
		return "s"
		break
	case 19:
		return "t"
		break
	case 20:
		return "u"
		break
	case 21:
		return "v"
		break
	case 22:
		return "w"
		break
	case 23:
		return "x"
		break
	case 24:
		return "y"
		break
	case 25:
		return "z"
		break
	}
	return "a"
}
func scan_init () {
	sc.Split(bufio.ScanWords)
}
func scanInt () int{
	sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
//func scan () string{
//  sc.Scan()
//	return sc.Text()
//}

Measured memory_bytes: 1776
n = int(input())
A = []
for i in range(n):
    A.append(input())

#0の時正しい
ans = 0
#長さが違うと同じものがある
if(len(A) != len(set(A))):
    ans+=1

for i in range(1, len(A)):
    if(i<len(A)):
        if(A[i-1][-1] == A[i][0]):
            continue
        else:
            ans+=1
if(ans==0):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;
   
signed main(){
    
    int n,q;
    cin >> n >> q;
    vector<int> a(n);
    rep(i,n)cin >> a[i];

    int s[100010] = {0};
    for(int i = 1;i < n;i++){
        s[i] = s[i-1] + a[n-i];
    }
    int s_m[100010] = {0};
    for(int i = 1;2*i-1 < n;i++){
        if(n%2 == 0){
            s_m[i] = s_m[i-1] + a[2*i-1];
        }else{
            s_m[i] = s_m[i-1] + a[2*i-2]; 
        }
    }
    
    vector<int> k;
    for(int i = 1;i <= n - n/2 - 1;i++){
        int r = a[n-1-i];
        int l = a[n-1-2*i];
        k.pb((r+l)/2);
    }
    SORT(k);

    rep(i,q){
        int x;
        cin >> x;
        int num = k.end() - lower_bound(k.begin(),k.end(),x) + 1;
        int ans = s[num] + s_m[n-n/2-num];
        cout << ans << endl;
    }

    return 0;   
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://aising2019.contest.atcoder.jp/tasks/aising2019_d

Measured memory_bytes: 4600
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

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

int main(int argc, char const *argv[]) {
    string s; cin>>s;
    int x = s.back()-'0';
    if (x == 3) {
        cout << "bon" << '\n';
    }
    else if (x == 0 || x == 1 || x == 6 || x == 8) {
        cout << "pon" << '\n';
    }
    else {
        cout << "hon" << '\n';
    }
    return 0;
}

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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int N = (int) 1e9;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int x, y, z;
	cin >> x >> y >> z;
	int ans = (x - z) / (y + z);
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>

inline void sayyes(void) { std::printf("YES\n"); std::exit(EXIT_SUCCESS); }
inline void sayno(void) { std::printf("NO\n"); std::exit(EXIT_SUCCESS); }

int main(int argc, char* argv[]) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  /* */
  int a[3];
  std::cin >> a[0] >> a[1] >> a[2];
  std::sort(a, a + 3);
  if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
    sayyes();
  } else {
    sayno();
  }
  /* */

  return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int m,n;
cin>>n>>m;
int A[105]={0};
int num=0;
int sum=0;
for(int i=1;i<=n;i++){
  cin>>A[i];
  sum+=A[i];
}

for(int i=1;i<=n;i++){
  if(4*m*A[i]>=sum)num++;
}
if(num>=m)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

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

using namespace std;

#define loop(i,n) for(i=0;i<n;i++)
typedef long long ll;
ll const m =1000000007;
 
ll power(ll a,int n,int m)
{ 
    
    if(n==0)
        return 1;
    else if(n==1)
        return a%m;
    else
    {
        ll res=power(a,n/2,m);
        if(n%2==0)
            return ((res)*(res))%m;
    
    else
        return ((res)*(res)*(a))%m;
    }
}

int main()
{
 ll n,i,j=0,k,count=0,temp=0,temp0=0,temp1=0;
  cin>>n;
  ll arr[n];
  
for(i=0;i<n;i++) cin>>arr[i];

sort(arr,arr+n);

while(arr[n-1]>0)
{
  temp0=0,temp1=0;
for(i=0;i<n;i++)
{
  if(arr[i]%2==0)temp0++;
  else temp1++;

  arr[i]/=2;
}
    temp=(ll)(power(2,j,m))*temp0;
    temp=(temp%m)*(temp1);
    count=(count+temp)%m;
    j++;
}

cout<<count<<"\n";


return 0;
}
     


    

    


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

int main() {
    int n;
    cin >> n;
    int nt = 0,nx = 0,ny = 0;
    rep(i,n) {
        int t,x,y;
        cin >> t >> x >> y;
        int mx = x-nx;
        int my = y-ny;
        if(abs(mx)+abs(my) > (t-nt)) {
            cout << "No" << endl;
            return 0;
        }
        if((t-nt-(abs(mx)+abs(my)))%2 != 0) {
        cout << "No" << endl;
        return 0;
        }
    }
    cout << "Yes" << endl;
}

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

using namespace std;

int n, x;
deque <int> dq;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> x;
        if (i & 1)
            dq.push_front(x);
        else
            dq.push_back(x);
    }
    if (n & 1)
        for (auto u: dq)
            cout << u << ' ';
    else
        while (dq.size()){
            cout << dq.back() << ' ';
            dq.pop_back();
        }
}


Measured memory_bytes: 3072
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

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

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

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

	map<ll, map<ll,ll>> dic;
	rep(i, 1, N) {
		ll u, v, w;
		cin >> u >> v >> w;
		dic[u][v] = w;
		dic[v][u] = w;
	}

	vector<bool> ans(N + 1);
	vector<bool> flg(N + 1,true);
	stack<ll> st({ 1 });
	flg[1] = false;
	ans[1] = true;
	while (!st.empty()) {
		ll cur = st.top();
		st.pop();
		for (auto x : dic[cur]) {
			if (flg[x.first]) {
				if (x.second & 1) {
					ans[x.first] = !ans[cur];
				}
				else {
					ans[x.first] = ans[cur];
				}
				st.push(x.first);
				flg[x.first] = false;
			}
		}
	}

	repeq(i, 1, N) {
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 25504
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll n,m;cin>>n>>m;
    ll c[m];
    REP(i,m)cin>>c[i];
    ll dp[n+1];REPS(i,n)dp[i]=INF;dp[0]=0;
    REPS(j,n){
        REP(i,m){
            if(c[i]<=j)dp[j]=min(dp[j],dp[j-c[i]]+1);
            dp[j]=min(dp[j],dp[j-1]+1);
        }
    }
    cout<<dp[n]<<"\n";
}



Measured memory_bytes: 3464
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
int MOD=1000000007;
int dp[1000005][4];
//0=nothing
//1=only 0
//2=only 9
//3=both
main(){
	int n;
	dp[2][0]=8*8;
	dp[2][1]=17;
	dp[2][2]=17;
	dp[2][3]=1+1;
	FE(i,3,1000000){
		dp[i][0]=dp[i-1][0]*8;
		dp[i][1]=dp[i-1][1]*9+dp[i-1][0];
		dp[i][2]=dp[i-1][2]*9+dp[i-1][0];
		dp[i][3]=dp[i-1][1]+dp[i-1][2]+dp[i-1][3]*10;
		F(j,0,4) dp[i][j]%=MOD;
	}
	while(~getI(n)){
		if(n<2){
			puts("0");
			continue;
		}
		printf("%lld\n",dp[n][3]);
	}
}


Measured memory_bytes: 35072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

int main() {
    long long n;
    cin >> n;
    string ans = "";
    while (n > 0) {
        // nを26で割ったあまりを求める
        int res = n % 26;
        // あまりが0なら26に変える(zに相当)
        if (res == 0) {
            res = 26;
        }
        // 余りは文字を付け足す
        ans += (char)('a' + res - 1);
        // 余りを引いて26で割る(小数点切り捨て)
        n = (n - res) / 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


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

import sys


def main():
    mod = 1000000007                # 10^9+7
    def input():  return sys.stdin.readline().rstrip()
    def mi():     return map(int, input().split())
    def lmi():    return list(map(int, input().split()))
    def debug(x): print(x, file=sys.stderr)


    def check_positive(k, pos, neg):
        if k % 2 == 0:
            return (len(neg) // 2) * 2 + len(pos) >= k
        else:
            if pos:
                k -= len(pos) if len(pos) % 2 == 1 else len(pos) - 1
                return (len(neg) // 2) * 2 >= k
            return False

    def solve(n, k, L):
        pos = []
        zero_cnt = 0
        neg = []
        for elm in L:
            if elm < 0:
                neg.append(elm)
            elif elm > 0:
                pos.append(elm)
            else:
                zero_cnt += 1
        
        if check_positive(k, pos, neg):
            # 答えは正にできる。できるだけ大きい正の値を作ろう
            abs_neg = []
            tmp = sorted([abs(elm) for elm in neg], reverse=True)
            i = 0
            while i + 1 < len(tmp):
                abs_neg.append(tmp[i] * tmp[i+1])
                i += 2
            abs_neg.reverse()
            neg = abs_neg    # 昇順
            pos.sort()    # 昇順
            mul = 1
            cnt = 0
            # print(pos)
            # print(neg)
            while cnt < k:
                if pos and neg:
                    if (k - cnt) % 2 == 1:
                        mul = (mul * pos.pop()) % mod
                        cnt += 1
                    elif len(pos) >= 2 and pos[-1] * pos[-2] >= neg[-1]:
                        mul = (mul * pos.pop() * pos.pop()) % mod                            
                        cnt += 2
                    else:
                        mul = (mul * neg.pop()) % mod
                        cnt += 2                    
                elif pos:
                    mul = (mul * pos.pop()) % mod
                    cnt += 1
                elif neg:
                    assert cnt <= k - 2 and (k - cnt) % 2 == 0
                    mul = (mul * neg.pop()) % mod
                    cnt += 2
                else:
                    raise RuntimeError
            return mul

        elif zero_cnt != 0:
            # 答えは 0 にできる。0 が最善や
            return 0

        else:
            # 答えは負にしかならぬ。できるだけ 0 に近い負の値を作ろう
            tmp = [abs(elm) for elm in L]
            tmp.sort()
            mul = 1
            # print(tmp)
            for i in range(k):
                mul = (mul * tmp[i]) % mod
            return mod - mul
    
    
    n, k = mi()
    L = lmi()

    print(solve(n, k, L))




if __name__ == "__main__":
    main()


Measured memory_bytes: 126228
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b+c)cout<<"Yes"<<endl;
  else if(b==c+a)cout<<"Yes"<<endl;
  else if(c==a+b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256