akhauriyash/Code-Regression huggingface dataset:
import sys
import queue

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

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

#+++++

def ggg(n,a,b,c,d):
	init = n
	open = queue.PriorityQueue()
	close = set()
	open.put((0, n))
	min_v = n*d
	while not open.empty():
		cost, pos = open.get()
		if pos in close:
			continue
		if cost > min_v:
			continue
		
		min_v = min(min_v, cost+pos*d)
		for c, add in zip([a,b,c],[2,3,5]):
			k = pos % add
			nc = cost + k*d + c
			np = pos // add
			if nc <= min_v and np not in close:
				open.put((nc, np))
				#pa((nc,np))
			nnc = cost + (add-k) *d + c
			nnp = (pos + add) // add
			if nnc <= min_v and nnp not in close:
				open.put((nnc, nnp))
				#pa((nnc,nnp))
		close.add(pos)
	return min_v
		
		



def main():
	t = int(input())
	for i in range(t):
		n, a, b , c, d = tin()
		r = ggg(n,a,b,c,d)
		print(r)
	#s = input()
	
	
#+++++
isTest=False

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

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

Measured memory_bytes: 90388
def dfs(depth, swich):
    if depth == N:
        global ans
        flg = True
        for i in range(M):
            cnt = 0
            for j in range(s[i][0]):
                if S[s[i][j+1]-1] == 1:
                    cnt += 1
            if cnt % 2 != p[i]:
                flg = False
        if flg:
            ans += 1
    else:
        S[depth] = swich
        dfs(depth+1, on)
        dfs(depth+1, off)

N, M = map(int, input().split())
s = []
for i in range(M):
    s.append(list(map(int, input().split())))
p = list(map(int, input().split()))
ans = 0
S = [None for i in range(N)]
on = 1
off = 0
dfs(0, on)
dfs(0, off)
print(ans//2)


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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x) for (auto&& v : (x))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))

int main() {
  string s, t;
  cin >> s >> t;
  ll sl = s.size(), tl = t.size();
  ll res = LLONG_MAX;
  rep(i, sl - tl + 1) {
    ll c = 0;
    rep(j, tl) if (s[j + i] != t[j])++ c;
    updatemin(res, c);
  }
  cout << res << endl;
}


Measured memory_bytes: 3632
import sys
from heapq import heappush, heappop
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    jobs = {}
    for _ in range(N):
        A, B = map(int, input().split())
        if A > M:
            continue
        if A in jobs.keys():
            jobs[A] += [-B]
        else:
            jobs[A] = [-B]

    profit = 0
    days = jobs.keys()
    potential_jobs = []
    
    # M-1日後から今日まで遡る
    for elappsed_day in range(1, M+1):
        if elappsed_day in days:
            for job in jobs[elappsed_day]:
                heappush(potential_jobs, job)
        if len(potential_jobs) > 0:
            profit += heappop(potential_jobs)
            
    print(-profit)

if __name__ == "__main__":
    main()


Measured memory_bytes: 26020
#include <stdio.h>

int main(){

    int H;
    int A;

    scanf("%d %d", &H, &A);

    if(H % A == 0){
        printf("%d\n", H / A);
}
    else{
        printf("%d\n", (H / A) + 1);
    }

    return 0;

}

Measured memory_bytes: 1712
import time
import random
import bisect
def test(li):
    m=0
    for i in range(D):
        m+=s[i][li[i]-1]
        last[li[i]-1]=i+1
        for j in range(26):
            m-=c[j]*(i+1-last[j])
    return m

def query(p,q,d):
    d+=1
    b=bisect.bisect_left(play[p],d)
    np=play[p][b+1] if b+1<len(play[p]) else 366
    bp=play[p][b-1]
    minus=((0+np-d)*(np-d+1)//2)-((d-bp+np-bp)*(np-d)//2)
    b=bisect.bisect_left(play[q],d)
    np=play[q][b+1] if b+1<len(play[q]) else 366
    bp=play[q][b-1]
    plus=((d-bp+np-bp)*(np-d)//2)-((0+np-d)*(np-d+1)//2)
    if plus-minus>0:
        if d in play[p]:
            play[p].remove(d)
        play[q].append(d)
        play[q].sort()
        return True
    else:
        return False

start=time.time()
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
last=[0]*26
t=[random.randrange(26) for i in range(D)]
play=[[0] for i in range(26)]
for i in range(D):
    play[t[i]-1].append(i+1)
for i in range(26):
    play[i].append(366)
    
res=test(t)
while(True):
    if time.time()-start>=1.70:
        break
    for i in range(D):
        if time.time()-start>=1.70:
            break
        q=random.randrange(26)
        p=t[i]
        query(p,q,i)
for i in range(D):
  print(t[i]+1)

Measured memory_bytes: 92644
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const ll maxn=1e18+1;
// #define M 1005
// int A[M];
inline void rd(ll &l){
	l=0;int f=0;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){l=l*10+ch-'0';ch=getchar();}
	if(f)l=-l;
}
int main(){
	ll n,m,ans;
	rd(n);rd(m);
	n%=m;
	printf("%lld\n",min(n,m-n));
	return 0;
}

Measured memory_bytes: 128
from collections import Counter
size_a = int(input())
a = Counter(int(x) for x in input().split())
keys = list(a.keys())
keys.sort()
pair_cnt = 0
while size_a >= 2:
    x = keys[-1]
    if a[x] == 0:
        keys.pop()
        continue
    a[x] -= 1
    size_a -= 1
    if a[x] == 0:
        keys.pop()
    b = 2 ** x.bit_length() - x
    if a[b] > 0:
        a[b] -= 1
        size_a -= 1
        if a[b] == 0:
            del a[b]
        pair_cnt += 1
print(pair_cnt)

Measured memory_bytes: 110292
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
const long long md=1e9+7;
long long n,a[101010],qian[101010],hou[101010],ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	long long bf=1;
	qian[1]=1;
	for(int i=2;i<n;i++)
	{
		bf=bf*(i-1);
		bf%=md;
		qian[i]=(qian[i-1]*i+bf)%md;
	}
	hou[n-1]=1;
	for(int i=n-2;i>=0;i--)
	{
		hou[i]=hou[i+1]*(i+1)%md;
	}
	for(int i=1;i<n;i++)
	{
		ans+=(a[i]-a[i-1])*qian[i]%md*hou[i]%md;
		ans%=md;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
a,b = list(map(int,input().split()))
if( a > b ):
    a,b = b,a
if a > 0 and b > 0:
    print("Positive")
elif a <= 0 and b >= 0:
    print("Zero")
else:
    if (abs(a) - abs(b)) % 2 == 0:
        print("Negative")
    else:
        print("Positive")

Measured memory_bytes: 3060
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  //ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

  ll p = (a1 - b1) * t1;
  ll q = (a2 - b2) * t2;
  if(p > 0) {
    p *= -1;
    q *= -1;
  }
  if (p + q == 0) {
    puts("infinity");
    return 0;
  }
  if(p + q < 0){
    puts("0");
    return 0;
  }
  ll s = (-p) / (p + q);
  ll t = (-p) % (p + q);
  ll ans = 2 * s + 1;
  if (t == 0) ans--;

  cout << ans << endl;

  return 0;
}


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

int main() {
	int W, H, x, y;
	cin >> W >> H >> x >> y;
	cout << W * 0.5 * H << " ";
	if (x == W * 0.5 && y == H * 0.5) {
		cout << 1;
	}
	else cout << 0;
	
}

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

struct edge {
    int to;
    int cost;
};

int V, E, r;


vector<vector<edge>> G;

vector<int> dist;

int main()
{
    cin >> V >> E >> r;

    G.resize(V);
    dist.assign(V, 0);

    for (int i = 0; i < V; i++) {
        dist[i] = (i == r ? 0 : INF);
    }

    for (int i = 0; i < E; i++) {
        int s, t, d;
        cin >> s >> t >> d;

        G[s].push_back(edge{t, d});
        //        G[t].push_back(edge{s, d});
    }

    priority_queue<int> pq;
    pq.push(r);

    while (!pq.empty()) {
        int t = pq.top();
        pq.pop();

        for (auto i : G[t]) {
            int to = i.to;
            int cost = i.cost;

            if (dist[to] > dist[t] + cost) {
                dist[to] = dist[t] + cost;
                pq.push(to);
            }
        }
    }

    for (int i = 0; i < V; i++){
        if(dist[i] == INF){
            cout << "INF" << endl;
        }else{
            cout << dist[i] << endl;
        }
    }
}


Measured memory_bytes: 16016
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cout << #x " = " << (x) << '\n';
#define P(x) cout << #x << '\n';    
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;

int get(vector<int> a)
{
	int res = 0;
	int po = 1;
	for(int i = 0; i < a.size(); ++ i)
	{
		res += po * a[i];
		po *= 2;
	}
	return res;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	
	int n;
	cin >> n;
	vector<int> a(n);
	vector<pii> test[n];
	for(int i = 0; i < n; ++ i)
	{
		cin >> a[i];
		for(int j = 0; j < a[i]; ++ j)
		{
			int x, y;
			cin >> x >> y;
			-- x;
			test[i].push_back({x, y});
		}
	}
	int tot = 1 << n;
	int mx = 0; 
	for(int i = 0; i < tot; ++ i)
	{
		vector<int> hon(n, 0);
		bool ok = true;
		for(int j = 0; j < n; ++ j)
			if(i & (1 << j))
				hon[j] = 1;
		for(int j = 0; j < n; ++ j)
		{
			if(i & (1 << j))
			{
				for(int k = 0; k < test[j].size(); ++ k)
				{
					// cout << test[j][k].first << " " << test[j][k].second << '\n';
					int per = test[j][k].first;
					int val = test[j][k].second;
					if(hon[per] != val)
						ok = false;
				}
			}
			// else
			// {
				// for(int k = 0; k < (int)test[j].size(); ++ k)
				// {
					// hon[test[j][k].first] = !test[j][k].second;
				// }
			// }
		}
		// debug(i);
		// debug(get(hon));
		// for(int i = 0; i < n; ++ i)
			// cout << hon[i] << " ";
		// cout << '\n';
		// int cnt = 0;
		// for(int i = 0; i < n; ++ i)
			// if(hon[i] == 1)
				// ++ cnt;
		// bool ok = true;
		// for(int j = 0; j < n; ++ j)
		// {
			// if(i & (1 << j))
				// if(hon[j] == 0)
				// {
					// debug(j);
					// debug(hon[j]);
					// P(first);
					// ok = false;
				// }
			// else
				// if(hon[j] == 1)
				// {
					// debug(j);
					// debug(hon[j]);
					// P(sec);
					// ok = false;
				// }
		// }
		// if(!ok) cnt = 0;
		// debug(cnt);
		
		// int could = get(hon);
		// if(i == could)
			// mx = max(mx, (int)__builtin_popcountll(could));
		if(ok)
			mx = max(mx, (int)__builtin_popcountll(i));
		
	}
	cout << mx << '\n';
	
	return 0;
}






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

using namespace std;
using ll = long long;

#define MOD 1000000007
template<int mod>
struct ModInt{
   int x;
   ModInt():x(0){}
   ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
   ModInt &operator+=(const ModInt &p){
	   if((x+=p.x)>=mod)x-=mod;
	   return *this;
   }
   ModInt &operator-=(const ModInt &p){
	   if((x+=mod-p.x)>=mod)x-=mod;
	   return *this;
   }
   ModInt &operator*=(const ModInt &p){
	   x=(int)(1LL*x*p.x%mod);
	   return *this;
   }
   ModInt &operator/=(const ModInt &p){
	   *this*=p.inverse();
	   return *this;
   }
   ModInt &operator^=(long long p){
	   ModInt res = 1;
	   for (; p; p >>= 1) {
		   if (p & 1) res *= *this;
		   *this *= *this;
	   }
	   return *this = res;
   }
   ModInt operator-()const{return ModInt(-x);}
   ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
   ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
   ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
   ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
   ModInt operator^(long long p)const{return ModInt(*this)^=p;}
   bool operator==(const ModInt &p)const{return x==p.x;}
   bool operator!=(const ModInt &p)const{return x!=p.x;}
   explicit operator int() const { return x; }
   ModInt operator=(const int p) {x = p; return ModInt(*this);}
   ModInt inverse()const{
	   int a=x,b=mod,u=1,v=0,t;
	   while(b>0){
		   t=a/b;
		   a-=t*b;
		   std::swap(a,b);
		   u-=t*v;
		   std::swap(u,v);
	   }
	   return ModInt(u);
   }
   friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
	   return os<<p.x;
   }
   friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
	   long long x;
	   is>>x;
	   a=ModInt<mod>(x);
	   return (is);
   }
};
typedef ModInt<MOD> mint;

int main()
{
	ll n; cin >> n;
	mint ans = (mint(10)^n) - (mint)2 * (mint(9)^n) + (mint(8)^n);
	cout << ans << endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		String[] ss = s.split("");
		for(int i=0; i<ss.length; i++){
			System.out.print(ss[i]);
			i++;
		}

		scan.close();
	}
}


Measured memory_bytes: 37764
#include <iostream>
using namespace std;
int cnt[10005];
int main(int argc, char** argv) {
	int n;
	cin >> n;
	int ans=0;
	for(int i=n;i>=1;i--)
	{
		cnt[i]=(n/i)*(n/i)*(n/i);
		for(int j=i+i;j<=n;j+=i)
			cnt[i]-=cnt[j];
		ans+=cnt[i]*i;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3192
from collections import deque
aa = list(map(str, input()))
S = deque()
for a in aa:
	S.append(a)
Q = int(input())
ope = []

for _ in range(Q):
	a = list(map(str, input().split()))
	if len(a) == 1:
		ope.append(a)
	else:
		ope.append(a)
	
# 先頭か末尾かを判定していけばよい
std = True # 順列か否か

for i in range(Q):
	if ope[i][0] == "1":
		std = not std
	else:
		if ope[i][1] == "1": # 先頭に付加
			if std: S.appendleft(ope[i][2])
			else: S.append(ope[i][2])
		else: # 末尾に不可
			if std: S.append(ope[i][2])
			else: S.appendleft(ope[i][2])
		
if std:		
	for s in S:
		print(s, end = "")
else:
	for s in reversed(S):
		print(s, end = "")

Measured memory_bytes: 123964
/// ITNOG :)))
/// SAliB
#include <bits/stdc++.h>

using namespace std;

#define pb                      push_back
#define pp                      pop_back
#define mp                      make_pair
#define fi                      first
#define sec                     second
#define xmax(x,y)               ((x) = max((x),(y)))
#define xmin(x,y)               ((x) = min((x),(y)))
#define all(x)                  (x).begin(),(x).end()
#define mem(x , y)              memset(x , y , sizeof(x))
#define _                       ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define debug1(a)               cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n';
#define debug2(a , b)           cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n' << #b << " ---> " << b << '\n';
#define debug3(a , b , c)       cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n' << #b << " ---> " << b << '\n' << #c << " ---> " << c << '\n';
#define debug4(a , b , c , d)   cout << string(40 , '*') << '\n' << #a << " ---> " << a << '\n' << #b << " ---> " << b << '\n' << #c << " ---> " << c << '\n' << #d << " ---> " << d << '\n';
#define connect(a , b , c)      a[b].pb(c) , a[c].pb(b)
//
typedef long long int ll            ;
typedef unsigned long long int ull  ;
typedef unsigned int uint           ;
typedef long double ld              ;
typedef string str                  ;
typedef pair < int , int > pii      ;
typedef pair < pii , int > ppi      ;
typedef pair < int , pii > pip      ;
typedef pair < ll , ll> pll         ;
typedef pair < ll , pll> plp        ;
typedef pair < pll , ll> ppl        ;
typedef vector < ll > vl            ;
typedef vector < ld > vld           ;
typedef vector < int > vi           ;
typedef vector < str > vs           ;
//
inline int   iin()  { int x   ; scanf("%d" , &x)   ;  return x; }
inline ll    lin()  { ll  x   ; scanf("%lld" , &x) ;  return x; }
inline ll    Lin()  { ll  x   ; scanf("%I64d" , &x);  return x; }
//
inline int   iout(int  x)  { printf("%d" , x)   ;  }
inline ll    lout(ll   x)  { printf("%lld" , x) ;  }
inline ll    Lout(ll   x)  { printf("%I64d" , x);  }
//
const int maxn4 = 1e4 + 85 , maxn5 = 1e5 + 69 , maxn6 = 1e6 + 85 , maxn7 = 1e7 + 69 , maxn8 = 1e8 + 85 , maxn9 = 1e9 + 69 , modi1 = 1e7 + 7 , modi2 = 1e9 + 7;
const ll mod1 = 1e7 + 7 , mod2 = 1e9 + 7;
int mn = INT_MAX , mx = INT_MIN;
//
int h[maxn5];
int main()
{_
    int n; cin >> n;
	int a[n];
	for(int i = 0 ; i < n ; i++)
	    cin >> a[i];
	int t1 = n , t3 = n , t2 = n , t4=n , t5 , t6;
	for(int i = 1 ; i < n ; i += 2)
		h[a[i]]++;
	for(int i = 0 ; i < maxn5 ; i++)
	{
		xmin(t1 , (n / 2) - h[i]);
		if(t3 > t1)
		{
			swap(t3 , t1);
			t5 = i;
		}
	}
	mem(h , 0);
	for(int i = 0 ; i < n ; i += 2)
		h[a[i]]++;
	for(int i = 0 ; i < maxn5 ; i++)
	{
		xmin(t2 , (n / 2) - h[i]);
		if(t4 > t2)
		{
			swap(t4 , t2);
			t6 = i;
		}
	}
	if (t5 != t6) 
	    printf("%d" , t3 + t4);
	else
		printf("%d",min(t1 + t4 , t3 + t2));
	return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    long long d,t,s;
    cin>>d>>t>>s;

    if(d>t*s){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    return 0;

}
/*


*/


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define fi first
#define se second
#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)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin>>n;
  vl X(n);
  rep(i,n)cin>>X[i];
  vl Y = X;
  sort(rng(Y));
  ll r = Y[(n/2)];
  ll l = Y[(n/2)-1];

  rep(i,n){
    if(X[i] >l)cout<<l<<endl;
    else cout<<r<<endl;
  }
  return 0;
}

Measured memory_bytes: 5376
#include <stdio.h>

int n,A[2000];

int main(){
  int i,j,q,m;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&m);

    if(hantei(0,m))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int hantei(int a,int m){

  if(m==0)return 1;
  if(a>=n)return 0;

  int c = hantei(a+1,m) || hantei(a+1,m-A[a]);

  return c;
}

  



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

char key;
int cnt;

char t[10][10]={
  { ' ' , ' ' , ' ' , ' ' , ' '},
  {'\'' , ',' , '.' , '!' , '?'},
  { 'a' , 'b' , 'c' , 'A' , 'B' , 'C'},
  { 'd' , 'e' , 'f' , 'D' , 'E' , 'F'},
  { 'g' , 'h' , 'i' , 'G' , 'H' , 'I'},
  { 'j' , 'k' , 'l' , 'J' , 'K' , 'L'},
  { 'm' , 'n' , 'o' , 'M' , 'N' , 'O'},
  { 'p' , 'q' , 'r' , 's' , 'P' , 'Q' , 'R' , 'S'},
  { 't' , 'u' , 'v' , 'T' , 'U' , 'V'},
  { 'w' , 'x' , 'y' , 'z' , 'W' , 'X' , 'Y' , 'Z'}
};

int u[10]={1,5,6,6,6,6,6,8,6,8};


int main(){
  while(cin>>str){
    key=str[0];
    cnt=0;

    for(int i=1;i<(int)str.size();i++){
      if(key==str[i]){
	cnt++;
      }else{
	if(key!='0'){
	  cout<<t[key-'0'][cnt%u[key-'0']];
	}else{
	  for(int j=0;j<cnt;j++)cout<<' ';
	}
	key=str[i];
	cnt=0;
      }
    }
    
    cout<<t[key-'0'][cnt%5]<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 1176
import collections
n=int(input())
d=list(map(int,input().split()))

c=collections.Counter(d)
ans=1
ans=c[0]

if ans==1 and d[0]==0:
    for i in range(1,len(c)):
        ans*=(c[i-1]**c[i])%998244353
    print(ans%998244353)
else:
    print(0)

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

int main()
{
    int N;
    cin >> N;
    vector<vector<int> > A(N, vector<int>(N));
    for (int i=0; i<N*N; i++) cin >> A[i/N][i%N];

    vector<vector<bool> > need(N, vector<bool>(N, true));
    for (int i=0; i<N; i++)
    {
        for (int j=i+1; j<N; j++)
        {
            for (int k=0; k<N; k++)
            {
                if (k==i || k==j) continue;
                if (A[i][k] + A[k][j] < A[i][j])
                {
                    cout << -1 << endl; return 0;
                }
                else if (A[i][k] + A[k][j] == A[i][j])
                {
                    need[i][j] = false;
                }
            }
        }
    }
    long long ans = 0;
    for (int i=0; i<N; i++)
    {
        for (int j=i+1; j<N; j++)
        {
            if (need[i][j]) ans += A[i][j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	ll q, h, s, d, n; cin >> q >> h >> s >> d >> n;
	ll two[4];
	two[0] = 8 * q;
	two[1] = 4 * h;
	two[2] = 2 * s;
	two[3] = 1 * d;
	sort(two, two + 4);

	ll one[4];
	one[0] = 4 * q;
	one[1] = 2 * h;
	one[2] = 1 * s;
	sort(one, one + 3);

	if (n & 1) {
		cout << one[0] + two[0] * (n / 2) << endl;
	}
	else {
		cout << two[0] * (n / 2) << endl;
	}

	return 0;
}

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

int main() {
  string s; ll k; int n;
  cin >> s >> k;
  --k;
  n = s.size();
  
  char ans;
  rep(i,n) {
    ans = s[i];
    if(s[i]!='1') break;
    if(--k<0) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, const char * argv[]) {
    int h, w;
    char s[50][50];
    bool allwhite = true;
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] != '#')
                continue;
            allwhite = false;
            if(i > 0){ //上見る
                if(s[i - 1][j] == '#')
                    continue;
            }
            if(i < (h - 1)){//した見る
                if(s[i + 1][j] == '#')
                    continue;
            }
            if(j > 0){//左見る
                if(s[i][j - 1] == '#')
                    continue;
            }
            if(j < (w - 1)){
                if(s[i][j + 1] == '#')
                    continue;
            }
            if(allwhite){
                cout << "Yes";
                return 0;
            }
            cout <<"No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}



Measured memory_bytes: 256
l=[1,9,30,76,141,267,400,624,885,1249,1590,2208,2689,3411,4248,5248,6081,7485,8530,10248,11889,13687,15228,17988,20053,22569,25242,28588,31053,35463,38284,42540,46581,50893,55362,61824,65857,71247,76884,84388,89349,97881,103342,111528,120141,128047,134580,146316,154177,164817,174438,185836,194157,207927,218812,233268,245277,257857,268182,288216,299257,313635,330204,347836,362973,383709,397042,416448,434025,456967,471948,499740,515581,536073,559758,583960,604833,633651,652216,683712,709065,734233,754734,793188,818917,846603,874512,909496,933081,977145,1006126,1041504,1073385,1106467,1138536,1187112,1215145,1255101,1295142,1342852,1373253,1422195,1453816,1502376,1553361,1595437,1629570,1691292,1726717,1782111,1827492,1887772,1925853,1986837,2033674,2089776,2145333,2197483,2246640,2332104,2379085,2434833,2490534,2554600,2609625,2693919,2742052,2813988,2875245,2952085,3003306,3096024,3157249,3224511,3306240,3388576,3444609,3533637,3591322,3693924,3767085,3842623,3912324,4027884,4102093,4181949,4270422,4361548,4427853,4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692]
print(l[int(input())-1])


Measured memory_bytes: 9348
from math import log2
from collections import deque
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    LogN = int( log2(N))+1 # log of edge number
    E = [ list( map( int, input().split()))[1:] for i in range(N)]
    parent = [[-1]*(LogN) for _ in range(N)]
    start = 0
    deq = deque([0])
    depth = [-1]*N
    depth[start] = 0
    while deq: #calculate depth and calculate the parent of each vertex by 2**0 = 1
        v = deq.popleft()
        nextdepth = depth[v] + 1
        for w in E[v]:
            if depth[w] == -1:
                depth[w] = nextdepth
                parent[w][0] = v
                deq.append(w)

    for k in range(LogN-1):
        for v in range(N):
            if (parent[v][k] < 0):
                parent[v][k+1] = -1
            else:
                parent[v][k+1] = parent[ parent[v][k]][k]

    Q = int( input())
    for _ in range(Q):
        u, v = map( int, input().split())
        if depth[u] > depth[v]:
            u, v = v, u
        for k in range(LogN):
            if( (depth[v] - depth[u]) >> k & 1):
                v = parent[v][k]
        if u == v:
            print(u)
            continue
        for k in range(LogN-1, -1, -1):
            if parent[u][k] != parent[v][k]:
                u = parent[u][k]
                v = parent[v][k]
        print(parent[u][0])

if __name__ == '__main__':
    main()



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

int main() {
	int  n, m;
  	cin >> n >> m;
  	vector<pair<int, int>> p(m);
  	for(int i = 0; i < m; i++) cin >> p.at(i).first >> p.at(i).second;
  	
  	for(int x = 0; x < 1000; x++){
      int keta = 1;
      int nx = x/10;
      vector<int> d(1, x%10);
        while(nx){
        keta++;
        d.push_back(nx%10);
        nx /= 10;
      }
      if (keta != n) continue;
      bool ok = true;
      reverse(d.begin(), d.end());
      for(int i = 0; i < m; i++){
        if(d.at(p.at(i).first-1) != p.at(i).second) ok = false;
      }
      if(ok){
        cout << x << endl;
        return 0;
      }
    }
  cout << -1 << endl;
}

Measured memory_bytes: 256
def main():
	N, W = map(int, input().split())
	WV = [list(map(int, input().split())) for _ in range(N)]

	dp = [0] * (W + 1)
	for w, v in WV:
		for sumw in range(W, w - 1, -1):
			t = dp[sumw - w] + v
			if dp[sumw] < t:
				dp[sumw] = t
		#for x in dp:
		#	print("{:4d}".format(x), end="")
		#print()
	return max(dp)

print(main())


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

using namespace std;

int main() {

    int b,cnt=0,cnt1=0; cin>>b;

    string s; cin>>s;

    for(int i=0;i<s.length();i++){
        if(s[i] == 'R') cnt++;
        else if(s[i] == 'B') cnt1++;
     }

     if(cnt > cnt1) cout<<"Yes"<<endl;
     else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
N, M = map(int, input().split())
states = []
for i in range(N):
    state = list(map(int, input().split()))
    states.append(state[:])
checkpoints = []
for i in range(M):
    check = list(map(int, input().split()))
    checkpoints.append(check[:])

for s in states:
    a, b = s
    top = 10**9
    for i, c in enumerate(checkpoints):
        ca, cb = c
        distance = abs(a-ca) + abs(b - cb)
        if top > distance:
            top = distance
            ans = i+1
    print(ans)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>
#include <map>
#include <time.h>
using namespace std;

int main(){
	string S;
	bool b = true;
	const string ch = "keyence";

	cin >> S;

	int l = 0, r = 0, p;
	p = S.find(ch);
	if (p != string::npos){
		if (p != 0 || p != S.size() - ch.size())
			b = false;
	}
	else{
		for (int i = 0; i < ch.size(); ++i){
			if (S[i] == ch[i])
				++l;
		}
		for (int i = 0; i < ch.size(); ++i){
			if (S[S.size() - 1 - i] == ch[ch.size() - 1 - i])
				++r;
		}

		if (l + r < ch.size())
			b = false;
	}

	if (b)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=n-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    int l,r;
    cin>>l>>r;

    int tmp=r-l;
    l%=2019;
    r=l+tmp;

    int ans=2019;

    if(r<2019){
        repa(i,l,r)repa(j,i+1,r+1)cmin(ans,(i*j)%2019);
        cout<<ans<<"\n";
        return 0;
    }else cout<<0<<"\n";

    return 0;

}

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

int main () {

  int l, count = 0;
  string a, b, c;
  cin >> l >> a >> b >> c;

  for (int i = 0; i < l; i++) {
    if (a[i] == b[i] && a[i] == c[i] && b[i] == c[i]) {
      continue;
    }

    if (b.find(a[i], i) != i) {
      if (c.find(a[i], i) == i) {
        b[i] = a[i];
        count++;
        continue;
      }

      if (b.find(c[i], i) == i) {
        a[i] = b[i];
        count++;
        continue;
      } else {
      b[i] = a[i];
      c[i] = a[i];
      count+=2;
      continue;
      }
    } 
      c[i] = a[i];
      count++;

  }
  cout << count << endl;

  return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0) cout << "Zero" << endl;
    else if (a > 0 && b > 0 || a < 0 && b < 0 && abs(b - a - 1) % 2 == 0) cout << "Positive" << endl;
    else cout << "Negative" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S 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 lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  int ans=0;
  if(a>=k){
    cout<<k<<endl;
    return 0;
  }
  k-=a;
  ans+=a;
  if(b>=k){
    cout<<ans<<endl;
    return 0;
  }
  k-=b;
  cout<<ans-k<<endl;
  

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector <int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a.at(i);
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int A = 0;
  int B = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) A += a.at(i);
    else B += a.at(i);
  }
  
  cout << A - B << endl;
}


Measured memory_bytes: 256
a,b=map(int,input().split())
x=[1,3,5,7,8,10,12]
y=[4,6,9,11]
if a==2 and b==2:
  print("Yes")
elif a in y and b in y:
  print("Yes")
elif a in x and b in x:
  print("Yes")
else:
  print("No")

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

using namespace std;

double check_right_triangle(int a,int b,int c){
    return (pow(a,2) + pow(b,2) - pow(c,2))/(2 * a * b);
}

int main(void){
    int n,a,b,c;
    cin >> n;
    for(int i=0;i < n;i ++){
        cin >> a >> b >> c;
        if((check_right_triangle(a,b,c) *
            check_right_triangle(a,c,b) *
            check_right_triangle(b,c,a)) == 0){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}


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

int vector_finder(vector<int> vec, int number) {
    auto itr = find(vec.begin(), vec.end(), number);
    size_t index = distance( vec.begin(), itr );
    if (index != vec.size()) {
        return 1;
    }
    else {
        return 0;
    }
}

int main(){
    int N, cnt=0;
    string S;
    cin >> N >> S;
    for(int i = 0; i < 1000; i++){
        string V = to_string(i);
        if (i < 10) V = "00" + V;
        else if (i < 100) V = "0" + V;
        vector<int> ind(3, N+100);
        int k = 0;
        for(int j = 0; j < N; j++){
            if(S[j] == V[k] && !vector_finder(ind, j)){
                ind[k] = j;
                k++;
            }
            if(k == 3) break;
        }
        if (!vector_finder(ind, N+100)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mypair;
ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b!= 0){
		d = extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x = 1;
		y = 0;
	}

	return d;
}
void swap(ll &a,ll &b){
	ll tmp = a;
	a = b;
	b = tmp;
	return ;
}
ll gcd(ll x,ll y){
	if(y!=0){
		return gcd(y,x%y);
	}else{
		return x;
	}
}
int main(){
 ll a,b,d;
 while(1){
	cin>>a>>b>>d;
	if(a==0)break;
	ll x,y;
	bool flag = false;
	ll c =extgcd(a,b,x,y);
	if(x<y){
	swap(x,y);
	swap(a,b);
	flag = true;
	}
	
	ll tx = b/gcd(a,b),ty = -a/gcd(a,b);
	//cout<<ty<<endl;
	x*=d/c;
	y*=d/c;
	//cout<<x<<' '<<y<<endl;
	ll t= x/tx;
	ll ansx =abs(x),ansy =abs(y);
	ll x1 =x,x2 =x,y1=y,y2=y;
	for(int i=0;i<=50000;i++){
	x1+=tx;
	y1+=ty;
	x2-=tx;
	y2-=ty;
	if(ansx+ansy>abs(x1)+abs(y1)||(ansx+ansy==abs(x1)+abs(y1)&&a*ansx+b*ansy>a*abs(x1)+b*abs(y1))){
		ansx =abs(x1);
		ansy =abs(y1);
	}
	
	if(ansx+ansy>abs(x2)+abs(y2)||(ansx+ansy==abs(x2)+abs(y2)&&a*ansx+b*ansy>a*abs(x2)+b*abs(y2))){
		ansx =abs(x2);
		ansy =abs(y2);
	}

	}



	//cout<<x<<y<<endl;
	if(flag){
	cout<<ansy<<' '<<ansx<<endl;
	}else{
	cout<<ansx<<' '<<ansy<<endl;
	}

	

 }

	return 0;

}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;
constexpr int MOD = 1e9+7;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yay!" : ":(")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, a, b, c, d, e, k);
    CoutYn(e-a <= k);
}

Measured memory_bytes: 764
#include <cstdio>
#include <queue>
using namespace std;
struct t
{
	int x,y;
}a[100001],b;
struct cmp
{
	bool operator()(const struct t &a,const struct t &b)
	{
		return a.x>b.x;
	}
};
int main()
{
	long long int n,i,j,k,l;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++)
		scanf("%d%d",&a[i].x,&a[i].y);
	priority_queue <t,vector<t>,cmp> q(a,a+n);
	while(k!=0&&!q.empty())
	{
		b=q.top();
		q.pop();
		if(k-b.y>0)	{k-=b.y;	l=b.x;}
		else if(k-b.y==0)	{k=0;	l=b.x;}
		else if(k-b.y<0&&k!=0)	{k=0;	l=b.x;}
	}
	printf("%lld\n",l);
	return 0;
}

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

typedef long long ll;
typedef std::pair<ll, ll> P;
typedef std::tuple<ll, ll, ll> t3;
constexpr ll INF = 1e15;
constexpr ll mod = 1e9+7;

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

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


class Divisor {
private:
	vector<ll> F;
public:
	Divisor(ll N) {
		for (ll i = 1; i * i <= N; i++) {
			if (N % i == 0) {
				F.push_back(i);
				if (i * i != N) F.push_back(N / i);
			}
		}
		sort(begin(F), end(F));
	}
	int size() { return F.size(); }
	ll operator[](int k) { return F[k]; }
	const vector<ll>& factors() { return F; }
};

int main() {
	ll k;
	cin >> k;
	vector<vector<ll>> dp(k, vector<ll>(10, 0));
	rep(i, 10) {
		dp[k - 1][i] = 1;
	}
	for (int i = k - 2; i >= 0; i--) {
		rep(j, 10) {
			for (int a : {-1, 0, 1}) {
				ll id = a + j;
				if (id < 0 || id > 9) continue;
				dp[i][j] += dp[i + 1][id];
				chmin(dp[i][j], INF);
			}
		}
	}
	vector<int> ans;
	int front = -1;
	ll prev = 0;
	int digit = 1;
	for (; digit <= k; digit++) {
		for (int j = 1; j < 10; j++) {
			ll next = dp[k - digit][j];
			if (prev + next >= k) {
				ans.push_back(j);
				front = j;
				break;
			}
			prev += next;
		}
		if (front >= 0) break;
	}
	for (int i = k - digit + 1; i < k; i++) {
		for (int a : {-1, 0, 1}) {
			ll j = a + front;
			if (j < 0 || j > 9) continue;
			ll next = dp[i][j];
			if (prev + next >= k) {
				ans.push_back(j);
				front = j;
				break;
			}
			prev += next;
		}
	}
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 14856
#include<bits/stdc++.h>
#include<unordered_map>
#include<algorithm>
/*
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*    ▀▀       ▀▀▀▀▀▀    ▀     ▀▀▀▀▀▀      ▀    ▀
*   ▀  ▀      ▀         ▀     ▀            ▀  ▀
*  ▀    ▀     ▀ ▀ ▀     ▀     ▀ ▀ ▀         ▀
* ▀ ▀▀▀▀ ▀    ▀         ▀     ▀             ▀
*▀        ▀   ▀         ▀     ▀             ▀
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*/
using namespace std;
void afify()
{
	ios::sync_with_stdio(0);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
//===============================================
#define ll long long
#define ld double
#define mk make_pair
#define loop(i,intial,n)  for(int i=(intial);i<n;i++)
#define loopn(j,n) for(int j=int(n);j>=0;j--)
#define loopm(name)  for(auto it : name)
#define loopm2(name)  for(auto it2 : name)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(v) v.begin(),v.end()
#define PI (ld)(3.14159265358979323846)
//===============================================
#define SF(a) scanf("%d",&a)
#define SF2(a,b) scanf("%d %d",&a,&b)
#define SFLL(a) scanf("%lld",&a)
#define SFLL2(a,b) scanf("%lld %lld",&a,&b)
#define PF(a) printf("%d\n",a)
#define PFLL(a) printf("%lld\n",a)
//===============================================
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <vi> vvi;
typedef vector <vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;
typedef stringstream ss;
const double EPS = 1e-4;
const ll oo = (ll) 10e9 + 7;
const ll N = 1e5 + 18;
const ll mod = 1000003;
//int dx[] = { 0, 1, 0, -1 };
//int dy[] = { 1, 0, -1, 0 }; // 4 Direction*/
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction*/
//freopen("largest.in", "r", stdin);
//freopen("output.txt", "w", stdout);
//ifstream ifs("input.txt");
//ofstream ofs("output.txt");

int main()
{
	afify();
	int n;
	cin >> n;
	ll res = 0, mx = -5, ind = 0;
	loop(i, 2, n + 1) {
		res = 0;
		int m = i;
		while (m%2==0)
		{
			res++;
			m /= 2;
		}
		if (res > mx) {
			mx = res, ind = i;
		}
	}
	cout << max(ind,(ll)1) << endl;

	return 0;
}

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

#define ll long long
#define vi vector<int>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>

using namespace std;

int main() {
	int n,x;
	cin>>n>>x;
	
	if(n-2*x<0)
		cout<<0<<endl;
	else
		cout<<n-2*x<<endl;
}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int start = max(A, C);
    int end = min(B, D);
    int time = end - start;

    if (time >= 0) {
        cout << time << endl;
    } else {
        cout << "0" << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(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; }


int main(){
    int n; cin >> n;
    vector<ll> A(n); rep(i, n) cin >> A[i];

    ll res = 0;
    rep(i, n){
      ll num = A[i]/2*2;
      res += num/2;
      A[i] -= num;
      if(A[i] == 1 && i<n-1){
          if(A[i+1] > 0){
              A[i] = 0;
              A[i+1]--;
              res++;
          }
      }  
    }

    cout << res << ln;
}


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		if(S[0] == S[1] && S[1] == S[2]){
			Console.WriteLine("Yes"); return;
		}
		if(S[3] == S[1] && S[1] == S[2]){
			Console.WriteLine("Yes"); return;
		}
		Console.WriteLine("No"); return;
	}
	String S;
	public Sol(){
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
  int N,K;
  int a[60];
  int total = 0;
  cin >> N >> K;
  for(int i=0;i<N;++i) cin >> a[i];
  sort(a,a+N,greater<int>()); //大きい順
  for(int i=0;i<K;++i){
    total += a[i];
  }
  cout << total << endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <tuple>
#include <set>
#include <algorithm>

int main(){
  int N;
  std::cin >> N;
  std::vector<int> p_arr(N), pos_arr(N);
  for(int i = 0; i < N; i++){
    int p;
    std::cin >> p;
    p--;
    p_arr[i] = p;
    pos_arr[i] = i;
  }
  std::sort(pos_arr.begin(), pos_arr.end(), [&](int l, int r){return p_arr[l] > p_arr[r];});

  std::set<int> pos_set;
  long long ans = 0;
  for(auto&& pos: pos_arr){
    if(pos_set.size() == 0){
      pos_set.insert(pos);
      continue;
    }
    long long l,r,l2,r2;
    std::set<int>::iterator it = pos_set.upper_bound(pos);
    if(it == pos_set.end()){
      r = 0;
      r2 = N-pos;
    }else if(std::next(it) == pos_set.end()){
      r = N-*(it);
      r2 = *it-pos;
    }else{
      r = *(std::next(it)) - *(it);
      r2 = *it-pos;
    }
    if(it == pos_set.begin()){
      l = 0;
      l2 = pos+1;
    }else if(std::prev(it) == pos_set.begin()){
      l = *(std::prev(it))+1;
      l2 = pos-*(std::prev(it));
    }else{
      l = *(std::prev(it)) - *(std::prev(std::prev(it))); 
      l2 = pos-*(std::prev(it));
    }
    pos_set.insert(pos);
    ans += (p_arr[pos]+1)*(l*r2+r*l2);
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 5760
from fractions import gcd
_, *Q = map(int, open(0).read().split())
for a, b, c, d in zip(*[iter(Q)] * 4):
	if a < b or d < b:
		print("No")
		continue
	if c >= b:
		print("Yes")
		continue
	a %= b
	g = gcd(b, d)
	# b - g + a - g * (a // g) < b
	if b - g + a - g * (a // g) > c:
		print("No")
	else:
		print("Yes")

Measured memory_bytes: 5432