akhauriyash/Code-Regression huggingface dataset:
N = int(input())
L = [list(map(int, input().split())) for i in range(N-1)]
ans = []

for i in range(N-1):
    time = L[i][1]
    for j in range(i, N-1):
        c, s, f = L[j]
        if time < s:
            time = s
        elif time % f == 0:
            pass
        else:
            time += f - time % f
        time += c
    ans.append(time)

ans.append(0)
print(*ans, sep="\n")

Measured memory_bytes: 41072
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

ok = 0
min_price = 12 * 10 ** 5
for i in range(2 ** n):
    skills = [0] * m
    price = 0
    for j in range(n):
        if i >> j & 1:
            price += ca[j][0]
            for k in range(m):
                skills[k] += ca[j][k + 1]
    if all([j >= x for j in skills]):
        min_price = min(price, min_price)
        ok = 1
if ok:
    print(min_price)
else:
    print(-1)


Measured memory_bytes: 74540
import java.util.*;
class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int num=sc.nextInt();
		List<Integer> Value = new ArrayList<Integer>();	//Listの宣言	
		for(int i=0;i<num;i++)
		{
			Value.add(sc.nextInt());//Listに追加
		}		
			Collections.sort(Value);//昇順に並べ替え
			Collections.reverse(Value);//逆順に並べ替え
			int total = Value.get(0)/2;
		for(int i=1;i<num;i++)
		{
			total = total + Value.get(i);
		}
		System.out.println(total);
	}		
}


Measured memory_bytes: 21844
N = int(input())
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
if sum(A)-sum(B) < 0:
    print(-1)
    exit()
C = []
ans = 0
count = 0
for i in range(N):
    if A[i]-B[i] < 0:
        ans += 1
        count += A[i]-B[i]
    elif A[i]-B[i] > 0:
        C.append(A[i]-B[i])
    else:
        continue
if count == 0:
    print(0)
    exit()
C.sort()
C.reverse()
for i in range(len(C)):
    count += C[i]
    ans += 1
    if count >= 0:
        print(ans)
        exit()
print(ans)


Measured memory_bytes: 18932
N = int(input())
A = sorted(list(map(int,input().split())))
t = 0
for e in A:
    if e < 0:
        t += 1
B = sorted([abs(e) for e in A])

if t%2 == 1:
    print(sum(B)-B[0]*2)
else:
    print(sum(B))

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

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

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

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

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

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

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



	
int main() {
	ll n;
	cin >> n;
	ll a[MAX];

	repn(i, n) cin >> a[i];

	sort(a + 1, a + n + 1);

	ll ans = 0;
	ll v = INF;

	repn(i, n - 1) {
		if (abs(a[n] - a[i] * 2) < v) { v = abs(a[n] - a[i] * 2); ans = i; }
	}

	cout << a[n] << " " << a[ans];

	system("PAUSE");
}

Measured memory_bytes: 3200
N = int(input())
A = list(map(int,input().split()))

counts = {}
for a in A:
    for i in [a-1, a, a+1]:
        if not i in counts:
            counts[i] = 0
        counts[i] += 1


counts = sorted(counts.items(), key=lambda x:x[1], reverse=True)

print(counts[0][1])

Measured memory_bytes: 23896
#include<stdio.h>
#define PI 100
int main()
{
    int i,j,t,k;
    int n;
    int a[PI];
    while(scanf("%d",&n)==1)
     {
         k=0;
         for(i=0;i<n;i++)
          scanf("%d",&a[i]);
        for(i=0;i<n-1;i++)
        {
           for(j=1;j<n-i;j++)
            {
                if(a[j]<a[j-1])
                {
                   t=a[j];
                   a[j]=a[j-1];
                   a[j-1]=t;
                    k++;
                }
            }
        }
        for(i=0;i<n-1;i++)
         {
            printf("%d ",a[i]);
         }
         printf("%d\n",a[n-1]);
        printf("%d\n",k);
     }
     return 0;
}



Measured memory_bytes: 2044
/*
    Author - Param Kothari
    Ah shit, here we go again
*/
 
/* Ordered Set Implementaton:

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll res = 0, suma = a + b;
    res = (n / (a + b)) * a;
    n = n % suma;
    res = res + min(n, a);
    cout << res << "\n";
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
t = []
for i in range(10):
	if str(i) not in S:
		t.append(i)
cnt = 0
flg1 = [0] * 10
ind1 = 0
for i in t:
	flg1[i] = 1
while True:
	if flg1[int(S[ind1])] == 1:
		ind1 += 1
	else:
		flg2 = [0] * 10
		for i in t:
			flg2[i] = 1
		ind2 = ind1 + 1
		while True:
			if flg2[int(S[ind2])] == 1:
				ind2 += 1
			else:
				flg3 = [0] * 10
				for i in t:
					flg3[i] = 1
				ind3 = ind2 + 1
				while True:
					if flg3[int(S[ind3])] == 1:
						ind3 += 1
					else:
						flg3[int(S[ind3])] = 1
						cnt += 1
						ind3 += 1

					if flg3.count(0) == 0:
						break
					if ind3 == N:
						break
				flg2[int(S[ind2])] = 1
				ind2 += 1
			if flg2.count(0) == 0:
				break
			if ind2 == N-1:
				break
		flg1[int(S[ind1])] = 1
		ind1 += 1
	if flg1.count(0) == 0:
		break
	if ind1 == N-2:
		break

print(cnt)


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

#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
#define loo 10000000000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

vi gr[100100];
map<ii, int> w;
int visi[100100], ans[100100];

void dfs(int at, int color){
    visi[at] = 1;
    ans[at] = color;

    for(int l : gr[at]){
        if(!visi[l]){
            if(w[{at, l}]%2) dfs(l, 3-color);
            else dfs(l, color);
        }
    }
}   

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; ++i){
        int x, y, z; cin >> x >> y >> z;
        gr[x].pb(y);
        gr[y].pb(x);
        w[{x, y}] = z;
        w[{y, x}] = z;
    }
    int res = 0;
    for (int i = 1; i <= n; ++i){
        if(!visi[i]) {
            res++;
            dfs(i, 1);
        }
    }

    cout << res << endl; 
    return 0;
}

Measured memory_bytes: 29952
import numpy as np

N,M,C = map(int,input().split())
B = np.array(list(map(int,input().split()))+[C])

A_list = np.zeros((N,M+1))
for i in range(N):
  A_list[i,:] = np.array(list(map(int,input().split()))+[1])

cnt=0
for i in range(N):
#  print(A_list[i,:]*B)
  if sum(A_list[i,:]*B)>0:
    cnt+=1
print(int(cnt))

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

int main(){
	/*input*/
	int n;	cin >> n;
	int* a = new int[n];
	int* b = new int[n]; 
	int* ans = new int[n]; 
	for(int i = 0; i < n; i++){
		cin >> a[i];
		b[i] = a[i];
		ans[i] = 0;
	}
	/*calculation*/
	sort(b, b+n);
	for(int i = 0; i < n; i++){
		(a[i] == b[n - 1])?ans[i] = b[n - 2]:ans[i] = b[n - 1];
	}

	/*output*/
	for(int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}
	delete[] a;
	delete[] b;
	delete[] ans;
}


Measured memory_bytes: 3968
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if (a > b) {
        if (b - w * t >= a - v * t) {
            cout << "YES" << endl;
            return 0;
        }
        else {
            cout << "NO" << endl;
            return 0;
        }
    }
    else {
        if (b + w * t <= a + v * t) {
            cout << "YES" << endl;
            return 0;
        }
        else {
            cout << "NO" << endl;
            return 0;
        }
    }

    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

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

long long gcd(long long a,long long b){
	while(1){
		if(a<b) swap(a,b);
		if(!b) break;
		a %= b;
	}
	return a;
}

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

#define ll long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll k; cin >> k;
    ll ans = 0;
    rep(i,1,k+1){
        rep(j,1,k+1){
            rep(l,1,k+1){
                ans += gcd(gcd(i,j),l);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
n,m,x=map(int,input().split())
A=[[0]*(m+1) for i in range(n)]
for i in range(n):
  A[i]=list(map(int,input().split()))
ans=10**10
for i in range(2**n):
  s=format(i,"20b")
  S=[]
  for j in range(n):
    if s[-1-j]=="1":
      S.append(j)
  X=[0]*m
  c=0
  for j in range(len(S)):
    c+=A[S[j]][0]
    for k in range(m):
      X[k]+=A[S[j]][k+1]
  f=0
  for j in range(m):
    if X[j]<x:
      f=1
  if f==0:
    if c<ans:
      ans=c
if ans==10**10:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 68496
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 100005;
int f[MAXN], n;
vector<int> gra[MAXN];

void dfs(int u, int fa) {
	for (int v : gra[u]) if (v != fa) {
		dfs(v, u);
		f[u] ^= f[v];
	}
	if (u > 1) ++f[u];
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int u, v; scanf("%d%d", &u, &v);
		gra[u].push_back(v), gra[v].push_back(u);
	}
	dfs(1, 0);
	puts(f[1] ? "Alice" : "Bob");
	return 0;
}

Measured memory_bytes: 12288
x,k,d = map(int,input().split())
y = abs(x)//d
if y >= k:
        ans = abs(abs(x)-d*k)

else:
        if (k-y)% 2 == 0:
                ans = abs(abs(x)-d*y)
        else:
                ans = min(abs(abs(x)-d*y+d),abs(abs(x)-d*y-d))
print(ans)

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

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

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;

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

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

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

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

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

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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

int main() {
	
	ll W, H;
	cin >> W >> H;

	vector<pair<ll, ll>> p(W+H);

	rep(i, W) {
		cin >> p[i].first;
		p[i].second = 0;
	}
	rep(i, H) {
		cin >> p[W + i].first;
		p[W+i].second = 1;
	}

	sort(p.begin(), p.end());

	vector<ll> rui(2, 0);

	ll ans = 0;

	rep(i, W + H) {
		if (p[i].second == 0) {
			ans += (H + 1 - rui[1])*p[i].first;
			rui[0]++;
		}
		else {
			ans += (W + 1 - rui[0])*p[i].first;
			rui[1]++;
		}
	}

	cout << ans<<endl;

	system("PAUSE");
}


Measured memory_bytes: 3576
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

N=int(input())
mod=10**9+7
num=pow(4,N,mod)

S={}
for i in range(1,N+1):
    S[i]={}

S[1]={"A":1,"G":1,"C":1,"T":1}
C=["A","G","C","T"]
for i in range(1,N):
    for s in S[i]:
        for c in C:
            st=s+c
            if len(st)>=5:
                st="".join(list(st)[1:])

            if len(st)==3:
                if st in ["AGC","GAC","ACG"]:
                    continue
            elif len(st)==4:
                if "AGC" in st or "GAC" in st or "ACG" in st:
                    continue
                if st[0]+st[1]+st[3]=="AGC":
                    continue
                if st[0]+st[2]+st[3]=="AGC":
                    continue
            if not st in S[i+1]:
                S[i+1][st]=S[i][s]
            else:
                S[i+1][st]+=S[i][s]
                S[i+1][st]%=mod

#print(S)
print(sum([S[N][i] for i in S[N]])%mod)


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

using namespace std;

int main() {
    string s;
    cin >> s;
    bool ok = 1;
    for (int i = 0; i < s.size(); i++) {
        if (i & 1) {
            if (s[i] != 'i') {
                ok = 0;
            }
        } else {
            if (s[i] != 'h') {
                ok = 0;
            }
        }
    }
    if (s.size() & 1) ok = 0;
    puts(ok ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MAX=510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

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


//n!
ll fact_mod(ll n) {
    ll ret=1; 
    for(ll i=2;i<=n;i++) ret=ret*(i%mod)%mod;
    return ret;
}
 
// 繰り返し二乗法 
ll pow_mod(ll x, ll n){
    if(n==0) return 1;
    ll ret=pow_mod((x*x) % mod, n/2);
    if(n&1) ret=(ret*x)%mod;
    return ret;
}
 
//nCr O(r) nがでかくても安心
ll combination_mod(ll n, ll r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    ll a=1;
    //a=n!/(n-r)!=n~n-r+1までの総積->O(r)
    for(ll i=0;i<r;i++) a=a*((n-i)%mod)%mod;
    //b=inv(r!)
    ll b=pow_mod(fact_mod(r), mod-2);
    return (a%mod)*(b%mod)%mod;
}
 
ll inv_mod(ll n){
    // フェルマーの小定理
    return pow_mod(n,mod-2);
}



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    COMinit();

    ll n,k;cin>>n>>k;
    if(k>=n-1){
        cout<<combination_mod(n+n-1,n)<<endl;
        return 0;
    }

    ll ans=1;
    for(ll i=1;i<=k;i++){
        // cout<<ans<<endl;
        ans+=COM(n,i)*COM(i+n-i-1,i)%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

int main(){
	int n;
	scanf("%d", &n);
	vi a(n), b(n);
	FOR(i,0,n){
		scanf("%d", &a[i]);
		scanf("%d", &b[i]);
	}
	if(n%2){
		sort(all(a));
		sort(all(b));
		ll mini = a[n/2];
		ll maxi = b[n/2];
		printf("%lld\n", maxi-mini+1);
	} else {
		sort(all(a));
		sort(all(b));
		ll mini = a[n/2 -1] + a[n/2];
		ll maxi = b[n/2 -1] + b[n/2];
		printf("%lld\n", maxi-mini+1);
	}
	return 0;
}



Measured memory_bytes: 4864
#include <stdio.h>

int main()
{
 int a, d, e=0, f=0, b[a], c[a];
 
 scanf("%d",&a);
 for(d=0;d<a;d++){
  scanf("%d",&b[d]);
 }
 for(d=0;d<a;d++){
  scanf("%d",&c[d]);
 }
 
for(d=0;d<a;d++){
    if(b[d]>c[d]){
        e = e + b[d];
        f = f + c[d];
    }
}
printf("%d",(e-f));

return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let ab = (read::<i32>(), read::<i32>());

    if ab.0 * ab.1 % 2 == 1 {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
S = input()
if(S[0]==S[1] and S[2]==S[3]) or (S[0]==S[2] and S[1]==S[3]) or (S[0]==S[3] and S[1]==S[2]):
    if(S[0]==S[1]==S[2]==S[3]):
        print("No")
    else:
        print("Yes")
else:
    print("No")

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

int main( int argc , char *argv[] )
{
  char buf[20];
  int n;
  int i;
  int ans = 0;
  
  int inner = 0;
  int lastA = 0;
  int firstB = 0;
  int AXB = 0;
  
  scanf( "%d\n" , &n );
  
  for( i = 0 ; i < n ; i++ ) {
    int l,j;
    
    scanf( "%s\n" , buf );
    l = strlen( buf );

    if( buf[0] == 'B' && buf[l-1] == 'A' ) {
      AXB++;
    } else if( buf[0] == 'B' ) {
      firstB++;
    } else if( buf[l-1] == 'A' ) {
      lastA++;
    }
    
    for( j = 0 ; j < l-1 ; j++ ) {
      if( buf[j] == 'A' && buf[j+1] =='B' ) {
        inner++;
      }
    }
  }

  ans = inner;
  
  if( AXB > 0 ) {
    ans += AXB - 1;

    if( lastA > 0 ) {
	    lastA--;
	    ans++;
    }
    if( firstB > 0 ) {
	    firstB--;
	    ans++;
    }
  }

  if( lastA > firstB ) {
	  ans += firstB;
  } else {
	  ans += lastA;
  }
  
  printf( "%d\n" , ans );
  
  return 0;
}


Measured memory_bytes: 128
S = input()

i = 0
ans = 0
l = r = 0
while i < len(S) and S[i] == '>':
    l += 1
    i += 1
ans += l*(l+1)//2

while i < len(S):
    l = r = 0
    while i < len(S) and S[i] == '<':
        l += 1
        i += 1
    while i < len(S) and S[i] == '>':
        r += 1
        i += 1
    mx,mn = max(l,r),min(l,r)
    ans += mx*(mx+1)//2
    ans += mn*(mn-1)//2
print(ans)


Measured memory_bytes: 4212
import java.util.Scanner;

public class Main {

	public static void main(String[] args)  {

		Scanner scaner = new Scanner( System.in );

		int first = Integer.parseInt( scaner.next() );
		int second= Integer.parseInt( scaner.next() );
		int third = Integer.parseInt( scaner.next() );

		String resultMessage = "No";

		if (  first < second && second < third ) {
			resultMessage = "Yes";
		}

		System.out.println( resultMessage );


		scaner.close();
	}

}

Measured memory_bytes: 26008
def main():
    import sys
    input = sys.stdin.readline
    from collections import deque

    N,M = map(int,input().split())
    dp = [-1]*N
    ad = [deque() for _ in range(N)]
    num = [0]*N
    for _ in range(M):
        x,y = map(int,input().split())
        x -= 1; y -= 1
        ad[x].append(y)
        num[y] += 1

    L = []
    S = deque()

    for v in range(N):
        if num[v] == 0:
            S.append(v)
            dp[v] = 0

    while S:
        v = S.popleft()
        L.append(v)
        for _ in range(len(ad[v])):
            nv = ad[v].popleft()
            num[nv] -= 1
            if num[nv] == 0:
                S.append(nv)
                dp[nv] = dp[v] + 1

    ans = max(dp)
    print(ans)

main()

Measured memory_bytes: 75056
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int a;
   string s;
   cin >> a >> s;

   if(a>=3200) cout << s << endl;
   else cout << "red" << endl;



   return 0;
}

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

// https://www.slideshare.net/hcpc_hokudai/binary-indexed-tree
// Binary Indexed Tree (BIT)
// 1-indexed
template<typename T>
struct BIT{
private:
    vector<T> array;
    const int n;

public:
    // 初期化
    BIT(int _n) : array(_n + 1, 0), n(_n) {}

    // [1, i]までの累積和を求める
    T sum(int i) {
        T s = 0;
        while(i > 0){
            s += array[i];
            i -= i & -i;
        }
        return s;
    }

    // [i, j]の要素の総和
    T sum(int i, int j) {
        T ret_i = sum(i-1);
        T ret_j = sum(j);
        return ret_j - ret_i;
    }

    // i番目に要素xを追加
    void add(int i, T x){
        while(i <= n) {
            array[i] += x;
            i += i & -i;
        }
    }
};


int main() {
    int n, q, com, x, y;
    cin >> n >> q;
    BIT<int> bit(n);
    for(int i = 0; i < q; ++i) {
        cin >> com >> x >> y;
        if(com == 0) {
            bit.add(x,y);
        }
        else {
            cout << bit.sum(x,y) << endl;
        }
    }

    return 0;
}


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

int main()
{
  std::string S;
  std::cin >> S;
  int ans = 0;
  for (int i = 0; i < S.size(); i++)
  {
    if (S[i] == '+') ans++;
    else ans--;
  }
  std::cout << ans << std::endl;
}


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

int main() {
    int m;
    cin >> m;
    long long ans = 0, sum = 0;
    for (int i = 0; i < m; i++) {
        long long d, c; cin >> d >> c;
        ans += c;
        sum += (d*c);
    }

    ans = ans + ((sum-1)/9) - 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int a, b, c;
  while (cin >> a >> b >> c) {
    int res = a * b / 2;
    cout << res << endl;
  }
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  for(int i = 0; i < N; i++){
    cin >> p[i];
  }

  sort(p.begin(),p.end());
  int sum = 0;
  for(int i = 0; i < N-1; i++){
    sum += p[i];
  }
  cout << sum + p[N-1] / 2 << endl;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <tuple>
#include <set>
#include <map>

#define FOR0(var, max) for (ul (var) = 0; (var) < (max); ++(var))
#define FORi(var, min, max) for (ul (var) = (min); (var) < (max); ++(var))
#define FORi_INV(var, min, max) for (ul (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

const static ul NMAX = 100000;
const static ul SEGNMAX = (1 << 17);
const static ul AiMAX = 1000000000;

static ul N;
static ul Ai[NMAX];

template <class T>
T gcd(T a, T b) {
  while (b) {
    T t = a % b;
    a = b;
    b = t;
  }
  return a;
}

static ul segtree[SEGNMAX * 2 - 1];

void segtree_init(void) {
  FOR0(i, SEGNMAX * 2 - 1) {
    segtree[i] = 0;
  }
}

ui segtree_parent(ui i) {
  if (i == 0) {
    return 0;
  }
  return (i - 1) / 2;
}

ui segtree_child1(ui i) {
  return i * 2 + 1;
}

ui segtree_child2(ui i) {
  return i * 2 + 2;
}

bool segtree_is_leaf(ui i) {
  return (SEGNMAX - 1 <= i);
}

void segtree_propagate_from_leaf(ui i) {
  ui cur = SEGNMAX - 1 + i;
  while (cur != 0) {
    cur = segtree_parent(cur);
    auto x1 = segtree[segtree_child1(cur)];
    auto x2 = segtree[segtree_child2(cur)];
    segtree[cur] = gcd(x1, x2);
  }
}

void segtree_update(ui i, ul x) {
  segtree[SEGNMAX - 1 + i] = x;
  segtree_propagate_from_leaf(i);
}

ul segtree_query_impl(ui a, ui b, ui k, ui l, ui r) {
  if (r <= a || b <= l) {
    return 0;
  } else if (a <= l && r <= b) {
    return segtree[k];
  } else {
    auto ta = segtree_query_impl(a, b, segtree_child1(k), l, (l + r) / 2);
    auto tb = segtree_query_impl(a, b, segtree_child2(k), (l + r) / 2, r);
    // cout << "l, r, ta, tb = " << l << ", " << r << ", " << ta << ", " << tb << endl;
    return gcd(ta, tb);
  }
}

// [a, b)
ul segtree_query(ui a, ui b) {
  return segtree_query_impl(a, b, 0, 0, SEGNMAX);
}

void solve(void) {
  segtree_init();
  FOR0(i, N) {
    segtree_update(i, Ai[i]);
  }
  ul res = 0;
  FOR0(i, N) {
    ul t = 0;
    if (0 != i) {
      t = segtree_query(0, i);
    }
    if (i + 1 != N) {
      t = gcd(t, segtree_query(i + 1, N));
    }
    // cout << t << endl;
    // cout << segtree_query(0, i) << ", " << segtree_query(i + 1, N) << endl;
    if (res < t) {
      res = t;
    }
  }
  cout << res << endl;
}

int main(void) {
  cin >> N;
  FOR0(i, N) {
    cin >> Ai[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;

int main()
{
	
	while(1)
	{
		int aSum(0),bSum(0);
		int n;

		cin >> n;
		
		if(n == 0)
			break;

		for(int i = 0;i < n;i++)
		{
			int a,b;
			cin >> a >> b;
		
			if(a > b){
				aSum += a + b;
			}else if(a < b){
				bSum += a + b;
			}else{
				aSum += a;
				bSum += b;
			}
		}
		cout << aSum << " " << bSum << endl;
	}
	return 0;
}

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

string ans[51];
int main(){
    int N;string S;cin>>N>>S;
    if(N%2)cout<<"No"<<endl;
    else{
        int flag=0;
        rep(i,N/2){
            if(S[i]!=S[N/2+i]){
                flag++;
                break;
            }
        }
        if(flag)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e7+5;
const int mod=1e9+7;
ll n,m,s,a[105],ans;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        s+=a[i];
    }
    for(int i=1;i<=n;i++) if(a[i]*4*m>=s) ans++;
    if(ans>=m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b){
    if (a < b){
        a = b;
        return 1;
    }
    return 0;
}
template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return 1;
    }
    return 0;
}

const long long INF = 1LL << 60;

int N;
long long h[100010];
long long dp[100010];

int main(){
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < N; ++i){
        cin >> h[i];
    }

    for (int i = 0; i < 100010; ++i) {
        dp[i] = INF;
    }

    dp[0] = 0;

    for (int i = 0; i < N; ++i){
        for (int j = 1; j <= K; ++j){ // これだけ飛べるよ
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    
    }


    cout << dp[N - 1] << endl;

}








Measured memory_bytes: 1792
#!/usr/bin/env python3
from collections import deque

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    S = deque(input())
    Q = int(input())
    direction = 1

    for _ in range(Q):
        query = input().split()
        t = int(query[0])

        if t == 1:
            direction = direction *  -1

        elif t == 2:
            f = int(query[1])
            c = query[2]
            if f == 1:
                # add to front
                if direction == 1:
                   S.appendleft(c)
                # add to back
                if direction == -1:
                   S.append(c)
            elif f == 2:
                # add to back
                if direction == 1:
                   S.append(c)
                # add to front
                if direction == -1:
                   S.appendleft(c)
    S = list(S)
    if direction == -1:
        S = S[::-1]

    print(''.join(S))
    pass

if __name__ == '__main__':
    main()

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int a, b, c; cin >> a >> b >> c;
    cout << min({a+b, b+c, c+a}) << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7760
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a, b;
    cin >> a >> b;
    int s, t, r;
    s = t = r = 0;
    for(int i = 0; i < n; i++)
    {
        int p; cin >> p;
        if(p <= a) s++;
        else if(p <= b) t++;
        else if(p > b) r++;
    }
    cout << min({s, t, r}) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
using namespace std;
int main()
{
    int k;
    int ans = 0;
    vector<int> a(5);
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
    for (int i = 0; i < 5; i++)
    {
        for (int j = i + 1; j < 5; j++)
        {
            if (a[j] - a[i] > k)
            {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;

    return 0;
}

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

int main(){

    string s;
    cin >> s;

    int n1, n2;

    n1 = atoi(s.substr(0,2).c_str());
    n2 = atoi(s.substr(2,2).c_str());

    if(n1 > 12 || n1 == 0){
        if(n2 > 12 || n2 == 0){
            cout << "NA" << endl;
        }
        else{
            cout << "YYMM" << endl;
        }
    }
    else{
        if(n2 > 12 || n2 == 0){
            cout << "MMYY" << endl;
        }
        else{
            cout << "AMBIGUOUS" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

#include<bits/stdc++.h>
using namespace std;

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vll;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vll,less<ll>>;
using pqchoto=priority_queue<ll,vll,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"YES"<<nn
#define    no             cout<<"NO"<<nn
#define    nn             "\n" ///endl
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)

template < typename T > string toString ( T Number ) { stringstream ss ; ss << Number ; return ss.str() ; }
template < typename T > ll toll ( T str ) { stringstream ss ; ss << str ; ll num ; ss >> num ; return num ; }
ll power(ll n , ll k) { if(k == 0) return 1 ; if(k&1) return n*sqr(power(n,k/2)) ; else return sqr(power(n,k/2)); }

const   int  N   =   2e5+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;
const   int dx[] =   {+1,+2,+2,+1,-1,-2,-2,-1};
const   int dy[] =   {-2,-1,+1,+2,+2,+1,-1,-2};

int main() {ikarus_101

    ll n,m,i,j,k,x;

    string s;
    cin>>n>>s;
    x=0;
    ll mx = 0;
    rep(i,n)
    {
        if(s[i] == 'I') x++;
        else x--;
        mx = max(mx,x);
    }
    cout << mx << endl;






















    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int n;
    cin>>n;
    vector<ll> h(n);
    rep(i,n)cin>>h[i];
    int ans=0;
    int cnt=0;
    rep(i,n-1){
        if(h[i]>=h[i+1]){
            ++cnt;
            ans=max(cnt,ans);
        }else{
            cnt=0;
        }
    }
    cout<<ans<<endl;
}





Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

struct UF{
	vector<int> par, rank;

	UF(int n){
		for(int i = 0; i < n; i++){
			par.emplace_back(i);
		}
		rank.assign(n, 0);
	}

	int root(int x){
		return par[x] == x ? x : par[x] = root(par[x]);
	}

	bool same(int x, int y){
		return root(x) == root(y);
	}

	void unite(int x, int y){
		x = root(x);
		y = root(y);
		if(rank[x] < rank[y]) par[x] = y;
		else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}
};

int64_t dist(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b){
	return min(abs(a.first - b.first), abs(a.second - b.second));
}

int main(){
	int n;
	cin >> n;
	pair<pair<int64_t, int64_t>, int> p[n];
	for(int i = 0; i < n; i++){
		cin >> p[i].first.first >> p[i].first.second;
		p[i].second = i;
	}
	pair<pair<int64_t, int64_t>, int> q[n];
	for(int i = 0; i < n; i++){
		q[i].first = {p[i].first.second, p[i].first.first};
		q[i].second = i;
	}
	sort(p, p + n);
	sort(q, q + n);
	priority_queue<pair<int64_t, pair<int, int>>, vector<pair<int64_t, pair<int, int>>>, greater<pair<int64_t, pair<int, int>>>> pq;	//cost, from, to
	for(int i = 0; i < n - 1; i++){
		pq.push(make_pair(dist(p[i].first, p[i + 1].first), make_pair(p[i].second, p[i + 1].second)));
		pq.push(make_pair(dist(q[i].first, q[i + 1].first), make_pair(q[i].second, q[i + 1].second)));
	}
	UF uf(n);
	int64_t ans = 0;
	while(!pq.empty()){
		auto puni = pq.top();
		pq.pop();
		int64_t d = puni.first;
		pair<int, int> ft = puni.second;
		if(!uf.same(ft.first, ft.second)){
			uf.unite(ft.first, ft.second);
			ans += d;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 10992
#include <iostream>
#include <string>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    string s, t;
    cin >> s >> t;
    int n = (int) s.size(), m = (int) t.size();

    set<string> st;
    for (int i = 0; i < n - m + 1; ++i) {
        string temp = s.substr(i, m);

        bool match = true;
        for (int j = 0; j < m; ++j) {
            if (temp[j] == '?') continue;
            else if (temp[j] != t[j]) match = false;
        }
        if (match) {
            string add = s;
            for (int k = i; k - i < m; ++k) add[k] = t[k - i];
            for (int l = 0; l < n; ++l) {
                if (add[l] == '?') add[l] = 'a';
            }
            st.insert(add);
        }
    }

    if (st.empty()) cout << "UNRESTORABLE" << endl;
    else cout << *st.begin() << endl;
}

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

int main(){
int a,b,c;
cin>>a>>b>>c;
if(c-b>a)
cout<<"dangerous"<<endl;
else{
	if(c-b>0)
	cout<<"safe"<<endl;
	else
	cout<<"delicious"<<endl;
}

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define re register
#define IL inline
using namespace std;
const int maxn=1e5+10;
template<typename T> void read(T &x){
	T f=1;x=0;
	char s=getchar();
	while(s<'0' || s>'9'){if(s=='-') f=-1;s=getchar();}
	while(s>='0' && s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();}
	x*=f;
}
ll n,m;
vector<int> t[maxn];
ll f[maxn];
ll ans[maxn];
bool book[maxn];
void dfs(int st){
	f[st]=1;
	book[st]=1;
	for(re int i=0;i<t[st].size();i++){
		if(!book[t[st][i]]){
			book[t[st][i]]=1;
		//	fa[t[st][i]]=st;
			dfs(t[st][i]);
			f[st]=(f[st]%m*(f[t[st][i]]+1)%m)%m;
		}
	}
	return;
}
void huangen(int st){
	//cout<<1<<endl;
	int len=t[st].size();
	int pre[len+5],suf[len+5];
	pre[0]=suf[len+1]=1;
	for(re int i=1;i<=len;i++){
		pre[i]=(pre[i-1]%m*(f[t[st][i-1]]+1)%m)%m;	
		suf[len-i+1]=(suf[len-i+2]%m*(f[t[st][len-i]]+1)%m)%m;
	}
	for(re int i=0;i<t[st].size();i++){
		if(ans[t[st][i]]!=-1) continue;
		int tmp1=f[st],tmp2=f[t[st][i]];
		f[st]=(pre[i]%m*suf[i+2]%m)%m;
		f[t[st][i]]=(f[t[st][i]]%m*(f[st]+1)%m)%m;
		ans[t[st][i]]=f[t[st][i]];
		huangen(t[st][i]);
		f[st]=tmp1;f[t[st][i]]=tmp2;
	}
	return;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	read(n);read(m);
	for(re int i=1;i<n;i++){
		int x,y;
		read(x);read(y);
		t[x].push_back(y);
		t[y].push_back(x);
	}
	dfs(1);
	memset(ans,-1,sizeof ans);
	ans[1]=f[1];
	huangen(1);
	for(re int i=1;i<=n;i++) cout<<ans[i]%m<<endl;
	return 0;
}


Measured memory_bytes: 20992
N = int(input())
c = list(input())


l1 = list()
for i in range(N):
    if c[i] == 'R':
        l1.append(i)
        


num = 0

def swap(i, j):
    a = c[i]
    c[i] = c[j]
    c[j] = a
    return

if len(l1) >= 1:
    for i in range(N):
        if i > l1[-1]:
            break
        if c[i] == 'W':
             swap(i, l1.pop(-1))
             num += 1
        if len(l1) == 0:
            break
print(num)


Measured memory_bytes: 18476
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
 
// from: https://www.youtube.com/watch%20?reload=9&v=TdR816rqc3s&feature=youtu.be
// Union(くっつける)　Find(どのグループか判別する)する木
struct UnionFind{
    vector<int> d;  // 負なら根、グループのサイズを示す。　負じゃないなら子、親のIDを示す。
    UnionFind(int n): d(n, -1){}    // コンストラクタ。nは要素数。最初は全てが根

    int find(int x){    // どのグループか判別する
        if (d[x]<0)   return x;   // 根なら頂点番号を返す（グループ番号とする）。
        return d[x] = find(d[x]);  // 子なら親のグループ番号を参照する（そして自分の親を根にする。）
    }
    bool unite(int x, int y){   // 二つの要素をくっつける
        x = find(x); y = find(y);   //  根同士をくっつける
        if(x == y) return false;    // 同じグループ内なら連結済み
        if(-d[x] < -d[y]) swap(x, y); // デカい方にくっつけたいので、yの方がデカいならswap
        // cout << "x: " << x << "y: " << y << endl;
        d[x] += d[y];   // グループのサイズ
        d[y] = x;   // xにyをくっつける。xが親
        return true;
    }
    bool same(int x, int y){ return find(x)==find(y);}   // 同じグループかどうか
    int size(int x){ return -d[find(x)];}
};


int main(){
    // vector<int> friend;
    int N, M, K; cin >> N >> M >> K;
    UnionFind uf(N);
    vector<vector<int>> tomo(N);
    vector<vector<int>> block(N);

    rep(i, M){  // friend
        int a, b; cin >> a >> b; a--; b--;
        uf.unite(a, b);
        // cout << "a: " << a << "b: " << b << endl;
        tomo.at(a).push_back(b);
        tomo.at(b).push_back(a);
    }
    rep(i, K){  // block
        int c, d; cin >> c >> d; c--; d--;
        block.at(c).push_back(d);
        block.at(d).push_back(c);
    }

    // 連結数(グループサイズ)- (友達数, 同ブロック内での、ブロック数) -1(自分)
    rep(i, N){
        // cout << "(int)tomo[i].size(): " <<  (int)tomo[i].size() <<" (int)block[i].size()" << (int)block[i].size() << endl;
        int size = uf.size(i) - (int)tomo[i].size() -1;
        
        // (int)block[i].size()
        for(int j: block[i]){
            if(uf.same(i, j)) size--;
        }

        cout << size << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 12672
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    long long n,k;
    cin>>n>>k;
    n%=k;
    long long ans=n;
    
    while(abs(n-k)<ans){
        ans=abs(n-k);
        n=ans;
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [0]*n
b = [0]*n
for i in range(n):
  a[i], b[i] = map(int, input().split())

a.sort()
b.sort()

if n%2:
  k1 = a[n//2]
  k2 = b[n//2]
else:
  k1 = a[n//2-1]+a[n//2]
  k2 = b[n//2-1]+b[n//2]

ans = k2-k1+1
print(ans)

Measured memory_bytes: 25500
#include <bits/stdc++.h>
using namespace std;
int main(){
 int n;
 char s[100],t[100],ans[200];
  cin >> n;
  for(int i=0;i<n;i++){
      cin >>s[i];
  }
  for(int i=0;i<n;i++){
      cin >>t[i];
  }
  for(int i=0;i<2*n;i++){
  if(i%2==0){
  ans[i]=s[i/2];
  }
  else if(i%2==1){
    ans[i]=t[(i-1)/2];
    }
  }
  for(int i=0;i<2*n;i++){
      cout <<ans[i];
  }
}


Measured memory_bytes: 256