akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int a, b; cin >> a >> b;
    cout << (a+b+1) / 2 << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

		String S = sc.next();
		int Q = sc.nextInt();

		boolean hanten = false;
		List<String> mae = new ArrayList<>();
		List<String> ushiro = new ArrayList<>();
		for (int i=0; i<Q; i++) {
			int T = sc.nextInt();
			if (T == 1) {
				hanten = !hanten;
			}
			else {
				int F = sc.nextInt();
				String C = sc.next();
				if (F == 1 && !hanten || F == 2 && hanten) {
					mae.add(C);
				}
				else {
					ushiro.add(C);
				}
			}
		}

		StringBuilder ans = new StringBuilder();
		if (hanten) {
			for (int i=ushiro.size() - 1; i>=0; i--) {
				ans.append(ushiro.get(i));
			}
			for (int i=S.length() - 1; i>=0; i--) {
				ans.append(S.charAt(i));
			}
			for (int i=0; i<mae.size(); i++) {
				ans.append(mae.get(i));
			}
		}
		else {
			for (int i=mae.size() - 1; i>=0; i--) {
				ans.append(mae.get(i));
			}
			ans.append(S);
			for (int i=0; i<ushiro.size(); i++) {
				ans.append(ushiro.get(i));
			}
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 158436
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;

int n,a[3];
vector<char> ans;

int main(){
    cin>>n>>a[0]>>a[1]>>a[2];
    vector<string> s(n);
    for(int i=0;i<n;i++)cin>>s[i];
    
    for(int i=0;i<n;i++)
    {
    	int x=s[i][0]-'A',y=s[i][1]-'A',z=3-x-y;
	
	if(a[x]==0 && a[y]==0)
	{
		cout<<"No"<<"\n";
		return 0;
	}
    
    	else if(a[x]==1 && a[y]==1 && a[z]==0)
	{
		if(i==n-1)
		{
			a[x]++,a[y]--;
			ans.push_back(s[i][0]);
		}
		else if(s[i+1].find(s[i][0])!=string::npos)
		{
			a[x]++,a[y]--;		
		        ans.push_back(s[i][0]);
		}
		else
		{
			a[x]--,a[y]++;
			ans.push_back(s[i][1]);
		}
	}
	else if(a[x]<=a[y])
	{
		a[x]++,a[y]--;
		ans.push_back(s[i][0]);	
	}
	else if(a[x]>a[y])
	{
		a[x]--,a[y]++;
		ans.push_back(s[i][1]);	
	}
    }
    cout<<"Yes"<<"\n";
    for(int i=0;i<n;i++)
    {
    	cout<<ans[i]<<"\n";
    }
}


Measured memory_bytes: 6744
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define sz(x) ((int) x.size())
#define rd(type, ...) type __VA_ARGS__; sc(__VA_ARGS__)
#define rdv(type, v, n) vector<type> v(n); rep(__ii, 0, n) cin >> v[__ii]
#define rdm(type, v, h, w) vector<vector<type>>(h, vector<type>(w)) v; rep(__ii, 0, h) rep(__jj, 0, w) cin >> v[__ii][__jj]
typedef long long ll;
void solve();
signed main() {ios::sync_with_stdio(false); cin.tie(0);
  cout << fixed; cout.precision(12); solve(); return 0;}
template<typename T> void prv(vector<T> v) {rep(__ii, 0, sz(v)) {if (__ii) cout << ' '; cout << v[__ii];} cout << '\n';} 
template<typename T> void prm(vector<vector<T>> v) {rep(__ii, 0, sz(v)) {rep(__jj, 0, v[__ii].size()) {if (__jj) cout << ' '; cout << v[__ii][__jj];} cout << '\n';}}
template<typename T> void sc(T& x) {cin >> x;}
template<typename Head, typename... Tail> void sc(Head& head, Tail&... tail) {cin >> head; sc(tail...);}
template<typename T> void pr(const T& x) {cout << x << '\n';}
template<typename Head, typename... Tail> void pr(const Head& head, const Tail&... tail) {cout << head << ' '; pr(tail...);}
template<typename... T> void err(const T&... cod) {pr(cod...); exit(0);}

void solve() {
  rd(int, n);
  rdv(int, a, n);
  multiset<int> ms;
  ms.insert(a[0]);
  rep(i, 1, n) {
    auto it = ms.lower_bound(a[i]);
    if (it == ms.begin()) ms.insert(a[i]);
    else {
      it--;
      ms.erase(it);
      ms.insert(a[i]);
    }
  }
  pr(sz(ms));
}

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>

using namespace std;

#define l first
#define r second
#define int long long

int n;
long long b;

signed main()
{
    multiset<int, greater<int> > a;
    int m, kk;
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> kk, a.insert(kk);
    for (int i = 0; i < m; i++) a.insert((*a.begin()) / 2), a.erase(a.begin());
    for (auto c : a) b += c;
    cout << b;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,m = LI()
A = LI()
B = LI()
xyc = [LI() for _ in range(m)]
ans = min(A) + min(B)
for x,y,c in xyc:
    ans = min(ans, A[x-1]+B[y-1]-c)
print(ans)

Measured memory_bytes: 77616
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

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

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

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
int main(){
	string s;
	cin >> s;
	cout << s[0] << s[1] << s[2] << endl;
	return 0;
}

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

long long gcd(long long a,long long b){
  while(a*b!=0){
    if(a>b){
      a=a%b;
    }else{
      b=b%a;
    }
  }
  return a+b;
}

int main(){
  int x;
  cin >> x;
  cout << 360/gcd(360,x) << endl;
}
  

Measured memory_bytes: 3628
import bisect

N=int(input())
ab=[[0,0,0] for _ in range(N)]#x,y,used
cd=[[0,0,0] for _ in range(N)]

for i in range(N):
    ab[i][0],ab[i][1]=map(int,input().split())

for i in range(N):
    cd[i][0],cd[i][1]=map(int,input().split())
    
    
    
ab.sort()
cd.sort()
ans=0

for i in range(N):#各青に対して，
    temp_j=-1
    temp_y=-1
    for j in range(N):
        if ab[j][2]==0:#未使用ならば
            if ab[j][0] < cd[i][0]: #x座標が小さい中で
                if cd[i][1] > ab[j][1] and ab[j][1]>=temp_y:#y座標が最大のものを選ぶ
                    temp_y=ab[j][1]
                    temp_j=j
    if temp_j!=-1:
        ab[temp_j][2]=1
        ans+=1
        
print(ans)
        




Measured memory_bytes: 39280
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int dfs(int a) {


	if (a == 1)return 1;

	int cnt = dfs(a / 2);
	cnt *= 2;
	cnt++;

	//cout << a << " " << cnt << endl;

	return cnt;
}

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

	int H;
	cin >> H;

	int ans = dfs(H);
	cout << ans << endl;
	return 0;
}



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

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pqb             priority_queue<ll>
#define pqs             priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll n,m,a[2002],b[2002];

struct item{
ll wt,val;};
ll solve(vector<item>v,ll n,ll W){
   ll dp[n+1][W+1];
   for(int w=0;w<=W;w++){
    dp[1][w]=0;
   }
   dp[1][v[1].wt]=v[1].val;
   for(int i=2;i<=n;i++){
    for(int w=0;w<=W;w++){
        dp[i][w]=dp[i-1][w];
        if(v[i].wt>w)continue;
        dp[i][w]=max(dp[i][w],v[i].val+dp[i-1][w-v[i].wt]);
    }
   }
   return *max_element(dp[n],dp[n]+W+1);
}

int main()
{
    FIO;
    ll c,d,e,f=0,sum=0,ans,ck,k,p,q,r,t,add=0,w,x,y,z;
    cin>>n>>w;
    vector<item>v(n+1);

    for(int i=1;i<=n;i++){cin>>v[i].wt;cin>>v[i].val;}
    ck=solve(v,n,w);
    cout<<ck<<endl;





    return 0;
}

Measured memory_bytes: 81584
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	ds <- readInts
	print $ sum $ do
		i <- [ 0 .. n - 1 ]
		j <- [ i + 1 .. n - 1 ]
		return $ ( ds !! i ) * ( ds !! j )

Measured memory_bytes: 508
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    A_ = [(a, i+1) for i, a in enumerate(A)]
    A_.sort()
    return ' '.join(map(lambda x: str(x[1]), A_))


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 27128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
//mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9+7, N = 2e5+5;

int a[N], n, m, k;

void solve(int test_case){
	int i, j, x, d;
	cin >> x >> k >> d;
	if(x<0){
		x = -x;
	}
	int t = x/d;
	int ans = 0;
	
	if(t >= k){
		ans =  x-k*d;
	}else if((k-t)%2==0){
		ans =  x-t*d;
	}else {
		ans =  x-t*d-d;
	}cout << abs(ans);
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

string s, t;

int main(){
  cin >> s >> t;
  int cnt = 0;
  rep(i, 3){
    if(s.at(i) == t.at(i)){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>

using namespace std;

const int INF = 1000000000;

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

struct edge { int to, cost; };

int N, M, L;
int A[10000], B[10000], D[10000], E[10000];

vector<edge> G[100]; // E
vector<int> G1[100]; // D

int d[100][101]; // to, restMoney

int getNum(int to, int restMoney) {
  return to * (L + 1) + restMoney;
}

P getP(int num) {
  return P(num / (L + 1), num % (L + 1)); // to, restMoney
}

int dijkstra() {
  for (int i = 0; i < N; i++)
    for (int j = 0; j <= L; j++)
      d[i][j] = INF;
  for (int i = 0; i <= L; i++) d[0][i] = 0;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, L));
  while (!que.empty()) {
    P p = que.top(); que.pop();
    P temp = getP(p.second);
    int v = temp.first;
    int money = temp.second;
    if (p.first > d[v][money]) continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      int length = G1[v][i];
      if (d[e.to][money] > d[v][money] + e.cost) {
        d[e.to][money] = d[v][money] + e.cost;
        que.push(P(d[e.to][money], getNum(e.to, money)));
      }
      if (money >= length && d[e.to][money - length] > d[v][money]) {
        d[e.to][money - length] = d[v][money];
        que.push(P(d[e.to][money - length], getNum(e.to, money - length)));
      }
    }
  }
  int ans = INF;
  for (int i = 0; i <= L; i++) ans = min(ans, d[N - 1][i]);
  return ans;
}


int main(){
  while (1) {
    scanf ("%d%d%d", &N, &M, &L);
    if (N == 0) break;
    for(int i = 0; i < 100; i++) G[i].clear(), G1[i].clear();
    for (int i = 0; i < M; i++) {
      scanf("%d%d%d%d", &A[i], &B[i], &D[i], &E[i]);
      A[i]--; B[i]--;
      edge e1, e2;
      e1.to = B[i], e2.to = A[i], e1.cost = e2.cost = E[i];
      G[A[i]].push_back(e1); G1[A[i]].push_back(D[i]);
      G[B[i]].push_back(e2); G1[B[i]].push_back(D[i]);
    }
    printf("%d\n", dijkstra());
  }
}



Measured memory_bytes: 3240
#include<stdio.h>
int main(){
	int n,k,i,j,m,sp,c=0;
	char map[101][101];
	scanf("%d%d%d",&n,&k,&sp);
	for(i=0;i<n;i++)scanf("%s",map[i]);
	for(i=0;i<n-sp+1;i++){
		for(j=0;j<k;j++){
			if(map[i][j]!='#'){
				for(m=i;m<i+sp;m++){
					if(map[m][j]=='#')break;
					else if(m==i+sp-1)++c;
				}
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<k-sp+1;j++){
			if(map[i][j]!='#'){
				for(m=j;m<j+sp;m++){
					if(map[i][m]=='#')break;
					else if(m==j+sp-1)++c;
				}
			}
		}
	}
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll a[200010];
    cin >> N;
    rep(i,0,N) cin >> a[i];
    map<ll,ll> mp;
    rep(i,0,N) mp[a[i]] = i;
    ll pre[200010] = {}, ne[200010] = {};
    rep(i,0,N){
        pre[i] = i-1;
        ne[i] = i+1;
    }
    ll ans = 0;
    rrep(i,N,1){
        ll pos = mp[i];
        ans += i * (pos - pre[pos]) * (ne[pos] - pos);
        pre[ne[pos]] = pre[pos];
        ne[pre[pos]] = ne[pos];
    }
    print(ans);

}


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

#define int long long
using ll = long long;
const int INF = 1<<29;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var)  std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(int i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(int i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

class UnionFind {
public:
	UnionFind(size_t size) : v(size, -1) {}
	vector<ll> v;

	int root(int x) {
		return (v[x] < 0 ? x : v[x] = root(v[x]));
	}

	bool is_root(int x) {
		return x == root(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 (x != y) {
			if (v[x] > v[y]) swap(x, y);
			v[x] += v[y];
			v[y] = x;
		}
	}

	ll size(int x) {
		return -v[root(x)];
	}
};

signed main() {
	int N,M;
	cin>>N>>M;
	UnionFind tree=UnionFind(N);
	vector<pair<int,int>> a;
	rep(i,M){
		int t1,t2;
		cin>>t1>>t2;
		a.push_back(make_pair(t1-1,t2-1));
	}

	vector<ll> ans;

	ll c=N*(N-1)/2;
	ans.push_back(c);
	rep(i,M-1){
		if(c==0){
			ans.push_back(c);
			continue;
		}
		auto pa=a[M-i-1];
		bool issame=tree.same(pa.first,pa.second);
		if(!issame){
			ll size1=tree.size(pa.first);
			ll size2=tree.size(pa.second);
			tree.unite(pa.first,pa.second);
			ll newsize=tree.size(pa.first);
			c+=size1*(size1-1)/2;
			c+=size2*(size2-1)/2;
			c-=newsize*(newsize-1)/2;
		}

		ans.push_back(c);
	}


	rep(i,M)p(ans[M-i-1]);

	




	return 0;
}



Measured memory_bytes: 5488
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<functional>
#include<vector>
#include<string>
#include<map>
using namespace std;
#define inf 1<<29
struct edge { int to, cost; };
typedef pair<int, int>P;
vector<edge>G[114514];//list graf

int n;
int d[114514];
int da[114514];

void dijk(int s) {
	priority_queue<P,vector<P>,greater<P>>q;
	fill(d, d + 114514, inf);
	d[s] = 0;
	q.push(P(0, s));

	while (q.size()) {
		P p = q.top();
		q.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}

}
int a[114514], b[114514];
int main() {

	cin >> n;
	for (int i = 0; i < n-1; i++) {
		cin >> a[i] >> b[i];
	}

	for (int i = 0; i < n-1; i++) {
		int va=a[i], vb=b[i];
			G[a[i] - 1].push_back({b[i]-1,1});
			G[b[i] - 1].push_back({ a[i] - 1,1 });
	}
	dijk(0);

	int s = n - 1;
	priority_queue<P, vector<P>, greater<P>>q;
	fill(da, da + 114514, inf);
	da[s] = 0;
	q.push(P(0, s));

	while (q.size()) {
		P p = q.top();
		q.pop();
		int v = p.second;
		if (da[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (da[e.to] > da[v] + e.cost) {
				da[e.to] = da[v] + e.cost;
				q.push(P(da[e.to], e.to));
			}
		}
	}
	int fen = 0, snu = 0;
	for (int i = 0; i < n; i++) {
		if (d[i] > da[i])snu++;
		else fen++;
	}

	if (fen > snu)puts("Fennec");
	else puts("Snuke");
}

Measured memory_bytes: 8688
x, y = map(int, input().split())
L = [1, 3, 5, 7, 8, 10, 12]
M = [4, 6, 9, 11]
N = [2]

if (x in L and y in L) or (x in M and y in M) or (x in N and y in N):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
/**
*    author:  yuya1234
*    created: 01.07.2020 09:26:29
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)

#define ALL(v) (s).begin(), (s).end()
#define SORT(s) sort((s).begin(), (s).end())
#define SORTD(s) sort((s).rbegin(), (s).rend())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

    int k, n;
    cin >> k >> n;

    int a[1000001];
    REP(i, n)
        cin >> a[i];

    int diff = 0, ans;
    REP(i, n - 1)
    {
        if (diff < a[i + 1] - a[i])
        {
            diff = a[i + 1] - a[i];
            ans = k - a[i + 1] + a[i];
        }
    }

    if (diff < k - a[n - 1] + a[0])
    {
        ans = a[n - 1] - a[0];
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4412
using System;
using System.Linq;

namespace _3_C
{
    class Program
    {
        static void Main(string[] args)
        {
            bool z = true;
            while (z)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x[0] == 0 && x[1] == 0)
                {
                    z = false;
                }
                else
                {
                    Array.Sort(x);
                    Console.WriteLine(x[0] + " " + x[1]);
                }
            }
        }
    }
}

Measured memory_bytes: 9804
#include<bits/stdc++.h>
#define taskname "test1"
#define int long long
using namespace std;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);   cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    int a, b, c;    cin >> a >> b >> c;
    if ((a * 100 + b * 10 + c) % 4 == 0) cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define INF 0x3f //plus infinite


char s[52][52];
int ans[52][52];
int main(){
  int h,w;
  cin >> h >> w;
  for(int i = 1;i <= h;i++)
    for(int j = 1;j <= w;j++)
      cin >> s[i][j];

  rep(i,h+1)
    rep(j,w+1)
    ans[i][j] = 0;

  for(int i = 1;i <= h;i++){
    for(int j = 1;j <= w;j++){
      if(s[i][j] == '#'){
	++ans[i-1][j-1];
	++ans[i-1][j];
	++ans[i-1][j+1];
	++ans[i][j-1];
	++ans[i][j+1];
	++ans[i+1][j-1];
	++ans[i+1][j];
	++ans[i+1][j+1];
      }
    }
  }

  for(int i = 1;i <= h;i++){
    for(int j = 1;j <= w;j++){
      if(s[i][j] == '.'){
	cout << ans[i][j];
      }else
	cout << "#";
    }
    cout << endl;
  }

}

/*文字列の辞書順について
 *C++の順序では'0'～'9'→'A'～'Z'→'a'～'z'の順に
 *                       なっていることに注意しましょう。
 */

/*行単位での入力
 * getline(cin,文字列変数);
 */


Measured memory_bytes: 256
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

size_t cmp_count;

void merge(vi& A, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  vi L(n1+1), R(n2+1);
  for (int i = 0; i < n1; i++) {
    L[i] = A[left+i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = A[mid+i];
  }
  L[n1] = R[n2] = INF;
  for (int i = 0, j = 0, k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
    cmp_count++;
  }
}

void mergeSort(vi& A, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(int argc, char **argv)
{
  int n;
  scanf("%d", &n);
  vi S(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  mergeSort(S, 0, n);
  const char *sp = "";
  for (int i = 0; i < n; i++) {
    printf("%s%d", sp, S[i]);
    sp = " ";
  }
  putchar('\n');
  printf("%lu\n", cmp_count);
  return 0;
}

Measured memory_bytes: 6828
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long long mod = 1e9+7;
long long power(long long a, long long b, long long m = mod) {
    if(b < 0) {
        return power(power(a, -b), mod-2);
    }
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
const int N = 3e5+9;
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    ll x; cin >> x;
    for(ll a = 0; a*a*a*a <= x; a++) {
        for(ll b = 0; a*a*a*a + b*b*b*b <= x; b++) {
            ll u = a*a*a*a*a, v = b*b*b*b*b;
            if(u-v == x) {
                cout << a << " " << b << endl;
                return 0;
            }
            if(u+v == x) {
                cout << a << " " << -b << endl;
                return 0;
            }
        }
    }



    return 0;
    
}


Measured memory_bytes: 3652
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node *right,*left,*parent;
};

Node *root, *NIL;

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }else{
    if(z->key < y->key){
      y->left = z;
    }else{
      y->right = z;
    }
  }
}


void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node *u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  string com;

  scanf("%d",&n);

  for(i = 0;i<n;i++){
    cin >> com;
    if(com == "insert"){
      scanf("%d",&x);
      insert(x);
    }else if(com == "print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 26724
n=int(input())
mod = 10**9+7
memo=[{} for i in range(n)]
#indexに文字列がそのまま使える
def chk_agc(char):
    l=len(char)
    #print(char)
    result=True
    if l>2:
        last3=char[l-3:l]
        if last3=="AGC" or last3=="ACG" or last3=="GAC":
            result=False
    if l>3:
        if char[l-4]=="A" and char[l-1]=="C":
            if char[l-3]=="G" or char[l-2]=="G":
                result=False
    return result
def count_agc(i,n,last4):
    if i==n:
        return 1
    if last4 in memo[i]:
        return memo[i][last4]
    ret=0
    if i>3:
        last3=last4[1:4]
    else:
        last3=last4
    for char in ["A","G","C","T"]:
        next_last4 = last3+char
        if chk_agc(next_last4):
            ret += count_agc(i+1,n,next_last4)
    if i>2:
        memo[i][last4]=ret
    return ret
print(count_agc(0,n,"")%mod)

Measured memory_bytes: 6444
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int m = saori.saori_hayami();
		int c = saori.saori_hayami();
		int ans = 0;
		int count = 0;
		int[] b = new int[m]; 
		for(int i = 0;i < m;i++){
			b[i] = saori.saori_hayami();
		}
		for(int i = 0;i < n;i++){
			count = 0;
			for(int j =0;j < m;j++){
				count += saori.saori_hayami() * b[j];
			}
			count += c;
			if(count > 0){
				ans++;
			}
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <cstring>
 
using namespace std;
 
int arr[4][13], rank[9], card[5], cnt[13];
string str[5];
 
int getMark(char ch){
    if(ch == 'S'){
	return 0;
    }else if(ch == 'C'){
	return 1;
    }else if(ch == 'H'){
	return 2;
    }
    return 3;
}
 
int getNum(char ch){
    if('2' <= ch && ch <= '9'){
	return (ch-'0')-1;
    }else if(ch == 'A'){
	return 0;
    }else if(ch == 'T'){
	return 9;
    }else if(ch == 'J'){
	return 10;
    }else if(ch == 'Q'){
	return 11;
    }
    return 12;
}
 
int judge(){
    bool same_mark = true;
    char ch = str[0][1];
    for(int i = 1 ; i < 5 ; i++){
	if(ch != str[i][1]){
	    same_mark = false;
	    break;
	}
    }
 
    if(same_mark){
	if(card[0] == 1 && card[1] == 10 && card[2] == 11 &&
	   card[3] == 12 && card[4] == 13){
	    return rank[8];
	}else{
	    bool check = true;
	    for(int i = 1 ; i < 5 ; i++){
		if(card[i] - card[i-1] != 1){
		    check = false;
		    break;
		}
	    }
	    if(check){
		return rank[7];
	    }else{
		return rank[4];
	    }
	}
    }
 
    sort(cnt, cnt+13, greater<int>());
    if(cnt[0] == 4){
	return rank[6];
    }else if(cnt[0] == 3){
	if(cnt[1] == 2){
	    return rank[5];
	}else{
	    return rank[2];
	}
    }else if(cnt[0] == 2){
	if(cnt[1] == 2){
	    return rank[1];
	}else{
	    return rank[0];
	} 
    }else{
	bool check = true;
	for(int i = 1 ; i < 5 ; i++){
	    if(card[i] - card[i-1] != 1){
		check = false;
		break;
	    }
	}
	if(check){
	    return rank[3];
	}
	if(card[0] == 1 && card[1] == 10 && card[2] == 11 &&
	   card[3] == 12 && card[4] == 13){
	    return rank[3];
	}
    }
 
    return 0;
}
 
int main(){
    int N;
    bool space = false;
 
    while(cin >> N){
	if(space){
	    cout << endl;
	}else{
	    space = true;
	}
 
	for(int i = 0 ; i < 4 ; i++){
	    for(int j = 0 ; j < 13 ; j++){
		cin >> arr[i][j];
	    }
	}
	for(int i = 0 ; i < 9 ; i++){
	    cin >> rank[i];
	}
 
	while(N--){
	    int point = 0, m,n;
	    memset(cnt, 0, sizeof(cnt));
	    for(int i = 0 ; i < 5 ; i++){
		cin >> str[i];
		m = getMark(str[i][1]);
		n = getNum(str[i][0]);
		point += arr[m][n];
		card[i] = n+1;
		cnt[n]++;
	    }
	    sort(card, card+5);
	    cout << point*judge() << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
 
using namespace std;
 
string S[3];
int now=0;
int nexts=-1;
int win=-1;
 
int main(){
	std::cin >> S[0];
	std::cin >> S[1];
	std::cin >> S[2];
	while(win==-1){
		if(S[now].length()==0)win=now;
		else{
			if(S[now][0]=='a')nexts=0;
			else if(S[now][0]=='b')nexts=1;
			else if(S[now][0]=='c')nexts=2;
			S[now].erase(S[now].begin());
			now=nexts;
		}
	}
	if(win == 0)printf("A\n");
    if(win == 1)printf("B\n");
	if(win == 2)printf("C\n");
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  bool ok=false;
   for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      if((N-4*i-7*j)==0) ok=true;
    }
  }
  if(ok==false) cout<<"No"<<endl;
  else cout <<"Yes"<<endl;

return 0;
}


Measured memory_bytes: 3596
fun main(args: Array<String>) = println(run {
    val (n,t) = readLine()!!.split(" ").map { it.toInt() }
    val c = (1..n).map { readLine()!!.split(" ").map { it.toInt() } }

    c.filter { it[1]<=t }.map { it[0] }.min()?:"TLE"

})


Measured memory_bytes: 37828
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

int main() {
	LL N, K;
	cin >> N >> K;
	vector<LL> v(100001, 0);
	REP(i, N) {
		LL a, b;
		cin >> a >> b;
		v[a] += b;
	}

	LL sum = 0;
	REP(i, 100001) {
		sum += v[i];
		if (sum >= K) {
			cout << i << endl;
			break;
		}
	}
}

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

int main(){
	while(true)
	{
	long long int m,n;
	cin >> m;
	if(cin.eof()) break;
	cin >> n;
	long long int l1 = m, l2 = n;
	while(l1 != l2)
	{
		if(l1 > l2) l1-=l2;
		else l2-=l1;
	}
	long long int gcd = m*n/l1;
	cout << l1 << " " << gcd << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <set>
#include <queue>
using namespace std;
#define MAXN 50
bool fromA2B(int n, bool g[][MAXN], int a, int b)
{
  g[a][b] = g[b][a] = false;
  bool result;

  bool reached[n];
  for (int i = 0; i < n; i++)
  {
    reached[i] = false;
  }

  queue<int> next;
  next.push(a);
  while (!next.empty())
  {
    auto p = next.front();
    next.pop();
    if (!reached[p])
    {
      reached[p] = true;
      for (int i = 0; i < n; i++)
      {
        if (g[p][i] && !reached[i])
        {
          next.push(i);
          if (i == b)
          {
            g[a][b] = g[b][a] = true;
            return false;
          }
        }
      }
    }
  }

  g[a][b] = g[b][a] = true;
  return true;
}

int main()
{
  int n, m;
  cin >> n >> m;
  bool g[MAXN][MAXN];
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      g[i][j] = false;
    }
  }
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    g[a - 1][b - 1] = g[b - 1][a - 1] = true;
  }
  auto ans = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      if (!g[i][j])
        continue;

      if (fromA2B(n, g, i, j))
      {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(i);
// sort(arr, arr+n, greater<int>());
// const long double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	int n,m;
	cin>>n>>m;
	if(n>m)
	{
		cout<<"safe"<<endl;
	}
	else
	{
		cout<<"unsafe"<<endl;
	}
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int x; cin >> x;
	if (x == 0) {
		cout << 1 << '\n';
	}
	else if (x == 1) {
		cout << 0 << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int no_of_days;
    cin >> no_of_days;
 
    typedef vector <int> v_int;
    v_int swim_happiness(no_of_days + 1);
    v_int bug_happiness(no_of_days + 1);
    v_int homework_happiness(no_of_days + 1);
 
    for(int i = 1; i <= no_of_days; i++)
        cin >> swim_happiness[i] >> bug_happiness[i] >> homework_happiness[i];
 
    const int NO_OF_TYPES = 3;
    vector <v_int> maximum_happiness(no_of_days + 1, v_int(NO_OF_TYPES, 0));
 
    const int SWIM_TODAY = 0, BUG_TODAY = 1, HOMEWORK_TODAY = 2;
    for(int i = 1; i <= no_of_days; i++)
    {
        maximum_happiness[i][SWIM_TODAY] = swim_happiness[i] + max(maximum_happiness[i - 1][BUG_TODAY], maximum_happiness[i - 1][HOMEWORK_TODAY]);
 
        maximum_happiness[i][BUG_TODAY] = bug_happiness[i] + max(maximum_happiness[i - 1][HOMEWORK_TODAY], maximum_happiness[i - 1][SWIM_TODAY]);
 
        maximum_happiness[i][HOMEWORK_TODAY] = homework_happiness[i] + max(maximum_happiness[i - 1][SWIM_TODAY], maximum_happiness[i - 1][BUG_TODAY]);
    }
 
    int overall_happiness = max(maximum_happiness[no_of_days][SWIM_TODAY], max(maximum_happiness[no_of_days][BUG_TODAY], maximum_happiness[no_of_days][HOMEWORK_TODAY]));
 
    cout << overall_happiness;
    return 0;
} 

Measured memory_bytes: 6912
#include<stdio.h>
#define INF 81
int coin[4]={10,50,100,500};
int sum;
int temoti;
int judge(int x1,int x2,int x3,int x4,int change){
    int cnt[4]={0};
    int a=0;
    for(int i=3;i>=0;i--){
        while(coin[i]<=change){
            cnt[i]++;
            a++;
            change-=coin[i];
        }
    }
    if(cnt[0]>0&&x1>0) return 0;
    if(cnt[1]>0&&x2>0) return 0;
    if(cnt[2]>0&&x3>0) return 0;
    if(cnt[3]>0&&x4>0) return 0;
    if(sum<temoti-x1-x2-x3-x4+a) return 0;
    else sum=temoti-x1-x2-x3-x4+a;
    return 1;
}
int main(void){
    int flag=0;
    while(1){
        int price;
        scanf("%d",&price);
        if(price==0) break;
        if(flag) puts("");
        int cnt[4]={0};
        sum=INF;
        int ans[4]={0};
        scanf("%d%d%d%d",&cnt[0],&cnt[1],&cnt[2],&cnt[3]);
        temoti=cnt[0]+cnt[1]+cnt[2]+cnt[3];
        for(int x1=0;x1<=cnt[0];x1++){
            for(int x2=0;x2<=cnt[1];x2++){
                for(int x3=0;x3<=cnt[2];x3++){
                    for(int x4=0;x4<=cnt[3];x4++){
                        int pay=x1*10+x2*50+x3*100+x4*500;
                        if(pay<price) continue;
                        if(judge(x1,x2,x3,x4,pay-price)){
                            ans[0]=x1; ans[1]=x2; ans[2]=x3; ans[3]=x4;
                        }
                    }
                }
            }
        }
        for(int i=0;i<4;i++){
            if(ans[i]){
                printf("%d %d\n",coin[i],ans[i]);
            }
        }
        flag=1;
    }
}



Measured memory_bytes: 2036
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int N;
  std::cin >> N;

  std::vector<int> d(N);
  for (int i = 0; i < N; ++i)
    std::cin >> d[i];

  // Main
  std::sort(d.begin(), d.end());

  // Output
  int p = N / 2;
  int res = d[p] - d[p - 1];
  std::cout << res << std::endl;

  return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    
    if (a > b) {
        cout << "a > b" << endl;
    } else if (a < b) {
        cout << "a < b" << endl;
    } else if (a == b) {
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3096
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    exclude = set()
    prime = set()
    for i in range(2,int(math.sqrt(x))+1):
        if i in exclude:
            continue
        prime.add(i)
        j = i+i
        while j<=math.sqrt(x):
            exclude.add(j)
            j += i
    
    current = x
    while True:
        for rep in prime:
            if current%rep==0:
                break
        else:
            print(current)
            return
        current += 1
    return

if __name__=='__main__':
    x = I()
    solve()

Measured memory_bytes: 9416
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll a, b;
  cin >> a >> b;
  if(a + b < 10) cout << a+b << endl;
  else cout << "error" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        if(a[i]!=i+1)ans++;
    }
    if(ans==2||ans==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

int main(){
    int n;cin>>n;
    vector<long long> nums(n); for(int i=0;i<n;i++){cin>>nums[i];}
    vector<long long> odds;
    for (auto i : nums){
        if (i % 2 == 1){
            odds.push_back(i);
        }
    }
    if (odds.size() % 2 == 1){
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;

}

Measured memory_bytes: 1660