akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

int main() {
  int i, j;
  int taro = 0, hana = 0;
  int turn, win;
  char card_taro[100], card_hana[100];

  scanf("%d", &turn);

  for (i = 0; i < turn; i++) {
    scanf("%s", card_taro);
    scanf("%s", card_hana);

    for (j = 0; j < 100; j++) {
      if (card_taro[j] =='\0' && card_hana[j] == '\0')
        break;
      if (card_taro[j] > card_hana[j]) {
        win = 1;
        break;
      }
      else if (card_taro[j] < card_hana[j]) {
        win = 2;
        break;
      }
      else
        win = 0;
    }

    if (win == 1)
      taro = taro + 3;
    else if (win == 2)
      hana = hana + 3;
    else {
      taro++;
      hana++;
    }

  }
    printf("%d %d\n", taro, hana);

    return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
int main(void)
{
	int n;
	scanf("%d", &n);
	if(n==1)
	printf("Hello World");
	else
	{
		int a, b;
		scanf("%d%d", &a, &b);
		printf("%d", a+b);
	}
	return 0;
}

Measured memory_bytes: 128
import re
n=int(input())
A=[]
for i in range(n):
    word=["."]*n
    for j in range(int(input())):
        x,y=map(int,input().split())
        word[x-1]=str(y)
    A.append(word)

ans=0
for i in range(2**n):
    num=format(i, "b").zfill(n)
    flag,cnt=1,0
    for j,k in enumerate(num):
        search=re.search(r"".join(A[j]),num)
        if search!=None and k=="1":
            cnt +=1
        elif (search==None and k=="1") or (search!=None and k=="0"):
            flag=0
            break
    if flag:ans=max(ans,cnt)
print(ans)

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


//defines...
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define in insert
#define pi 2*acos(0.0)1
#define srt(s) sort(s.begin(),s.end())
#define rsrt(s) sort(s.rbegin(),s.rend())
#define all(x) x.begin(),x.end()

const ll mod=1e9+7;
const ll MX=2e5+5;

//code goes from here...



int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);
#endif

    boost
    //---------------------------------
    string s ;
    cin >> s;
    ll ans=0;
    ll cnt=0;
    for(int i=0;i<s.size();i++)
    {
        
        if(s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C')
        {
            cnt++;
            ans=max(ans,cnt);
        }
        else cnt=0;
    }
    cout << ans << endl;
    
    //---------------------------------
    
    return 0;
}


Measured memory_bytes: 3580
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 22:56:10 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

N = int(input())
#X, Y = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(N-1)]

fact = [1, 1] # 元テーブル
fact_inv = [1, 1] # 逆元テーブル
tmp_inv = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N+1):
    fact.append((fact[-1] * i) % mod)
    tmp_inv.append((-tmp_inv[mod % i] * (mod//i)) % mod)
    fact_inv.append((fact_inv[-1] * tmp_inv[-1]) % mod)
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return fact[n] * fact_inv[r] * fact_inv[n-r] % mod
#逆元作成
def inv(a,mod):
    return pow(a,mod-2,mod)

graph = [[] for _ in range(N+1)]
for a, b in ab:
    graph[a].append(b)
    graph[b].append(a)
    
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if parent[x] == y:
            continue
        parent[y] = x
        stack.append(y)

size_d = [0] * (N + 1)
dp_d = [1] * (N + 1)
for v in order[::-1]:
    dp_d[v] *= fact[size_d[v]]
    dp_d[v] %= mod
    p = parent[v]
    s = size_d[v] + 1
    size_d[p] += s
    dp_d[p] *= fact_inv[s] * dp_d[v]
    dp_d[p] %= mod

size_u = [N - x - 1 for x in size_d]
dp_u = [1] * (N + 1)
for v in order[1:]:
    p = parent[v]
    x = dp_d[p] * inv(dp_d[v],mod)
    x *= fact_inv[size_d[p]] * fact[size_d[v] + 1]
    x *= fact[size_u[v] - 1] * fact_inv[size_u[p]]
    x *= dp_u[p]
    dp_u[v] = x % mod

for xd, xu, sd, su in zip(dp_d[1:], dp_u[1:], size_d[1:], size_u[1:]):
    x = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % mod
    print(x)



Measured memory_bytes: 128656
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;

#define MOD 998244353

int main(){
    ll n,ans=1;
    cin >> n;
    ll x[n];
    for (ll i=0;i<n;i++){
        cin >> x[i];
    }
    if (x[0]!=0){
        cout << 0 << endl;
        return 0;
    }
    sort(x,x+n);
    if (x[1]==0){
        cout << 0 << endl;
        return 0;
    }
    ll z=0;
    ll count=0;
    ll count2=1;
    for (ll i=0;i<=x[n-1];i++){
        for (ll j=z;j<n;j++){
            if (x[j]==i){
                count++;
            }else{
                z=j;
                break;
            }
        }
        if (count==0){
            cout << 0 << endl;
            return 0;
        }
        for (ll j=0;j<count;j++){
            ans=(ans*count2)%MOD;
        }
        count2=count;
        count=0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n,m;
    cin >> n >> m;
    cout <<  ((n-m)*100 + m*1900)*pow(2,m) << endl;
    return 0;
}

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

int main() {
  long x;
  std::cin >> x;
  std::bitset<32> bs(x);
  std::cout << bs << std::endl
            << (~bs) << std::endl
            << (bs << 1) << std::endl
            << (bs >> 1) << std::endl;
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD (1'000'000'007)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(a-x)>abs(b-x))pr('B');
    else pr('A');
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

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

	for (int i = 1; i <= 3; ++i) {
		if (i != A && i != B) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
int32_t main()
{


	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int l, r;
	cin >> l >> r;
	if (l * r < 2019)
		cout << l*(l + 1);
	else if ((l - 1) / 2019 != (r / 2019))
	{
		cout << 0;
	}
	else
	{
		int min = LONG_MAX;
		for (int i = l; i < r; i++)
		{
			for (int j = i + 1; j <= r; j++)
			{
				if (((i * j) % 2019) < min)
				{
					min = ((i * j) % 2019);
				}
			}
		}
		cout << min;
	}
}

Measured memory_bytes: 256
n = int(input())
a = []
num = []
prem = 0
m = 0
j = 0
for i in range(n):
    a.append(int(input()))
for i in range(n):
    if a[i] > m:
        prem = m
        m = a[i]
        num = []
        num.append(i)
    elif a[i] == m:
        num.append(i)
    elif a[i] > prem:
        prem = a[i]
for i in range(n):
    if len(num) > 1:
        print(m)
    elif j < len(num) and i == num[j]:
        print(prem)
        j += 1
    else:
        print(m)


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

int find(int u,int o,int* a,int x){
	
    if(o<=u+1){
      return 0;
    }

    int k = (u+o)/2;
    if(a[k] == x){return 1;}
    else if(a[k] <x){
        return find(k,o,a,x);
    }
    else {
        return find(u,k,a,x);
    }


}

int main(){
    int r[4000],g[4000],b[4000];
    int rlen = 0;
    int glen = 0;
    int blen = 0;
    int N;
    cin >> N;
    for(int i=1;i<=N;i++){
        char c;
        cin >> c;
        if(c=='R'){
            r[rlen]=i;
            rlen +=1;}
        else if(c=='G'){
            g[glen]=i;
            glen+=1;
        }
        else{
            b[blen] = i;
            blen +=1;
        }

    }
    if(rlen ==0 || glen == 0 || blen == 0){cout << 0 << endl;}
    else{
        long long int sum=0;
        for(int i=0;i<rlen;i++){
            for(int j=0;j<glen;j++){
                if( (r[i]+g[j])%2==0){
                    int x=(r[i]+g[j])/2;
                    if(find(-1,blen,&(b[0]),x)==1){sum+=1;}

                }

            }
        }
        for(int i=0;i<rlen;i++){
            for(int j=0;j<blen;j++){
                if( (r[i]+b[j])%2==0){
                    int x=(r[i]+b[j])/2;
                    if(find(-1,glen,&(g[0]),x)==1){sum+=1;}
                    
                }

            }
        }
        for(int i=0;i<blen;i++){
            for(int j=0;j<glen;j++){
                if( (b[i]+g[j])%2==0){
                    int x=(b[i]+g[j])/2;
                    if(find(-1,rlen,&(r[0]),x)==1){sum+=1;}
                    
                }

            }
        }
        cout << (long long int)rlen*glen*blen - sum << endl;
    }


    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
#define faster       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long ll;
typedef long double ld;


int main(){

f(i,0,5){
  ll a; cin>>a;
  if(a==0){
    cout << i+1 << endl;
    break;
  }
}
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a,b,c;
	int a1=700;
	scanf("%c%c%c",&a,&b,&c);
	if(a=='o')
	{
		a1+=100;
	}
	if(b=='o')
	{
		a1+=100;
	}
	if(c=='o')
	{
		a1+=100;
	}
	printf("%d",a1);
	return 0;
 } 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include<set>


#define rep(i,p,q) for(ll i = p;i < q;++i)
#define ll long long

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

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

ll npk(ll n, ll k) {
	ll ret = 1;
	if (n < k || n < 0)return 0;
	rep(i, 0, k) {
		ret *= (n - i);
		ret %= MOD;
	}
	if (ret < 0) ret = 0;
	return ret;
}

const long long MAX_N = 1 << 17;
long long dat[2 * MAX_N - 1];

class SegmentTree {
private:
	//node数
	long long n;

	//[a,b)の最大値を求める
	long long query(long long a, long long b, long long k, long long l, long long r) {
		if (r <= a || b <= l)return 0;

		if (a <= l && r <= b) return dat[k];
		else {
			long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return std::max(vl, vr);
		}
	}
public:
	SegmentTree(long long n_) {
		n = 1;
		while (n < n_) n *= 2;

		for (long long i = 0; i < 2 * n - 1; i++)dat[i] = 0;
	}

	//k番目の値をaにする
	void update(long long k, long long a) {
		k += n - 1; //葉
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = std::max(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}

	//[a,b)の最大値を求める
	long long search(long long a, long long b) {
		return query(a, b, 0, 0, n);
	}
};

//136D 別解
int main(void) {
	ll n, m;
	cin >> n >> m;
	vector<vector<ll>> albeit = vector<vector<ll>>(100001,vector<ll>());
	rep(i, 0, n) {
		ll a, b;
		cin >> a >> b;
		albeit[a].push_back(b);
	}
	priority_queue<ll, vector<ll>> pq = priority_queue<ll, vector<ll>>();
	ll ans = 0;
	rep(i, 1, m + 1) {
		if (albeit[i].size() > 0) {
			for (const auto& money : albeit[i]) {
				pq.push(money);
			}
		}
		
		if (pq.size() > 0) {
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 5632
function Main(s) {
  var ans = [];
  for(var i = 0; i < s.length; i++){
    if(s[i] === "B") ans.pop();
    else ans.push(s[i]);
  }
	console.log(ans.join(""));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7496
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,ans;
vector<int> v;
int x(){
	int num=0;
	for (int i=v.size()-1;i>=0;i--) num=num*10+v[i];
	return num;
}
int main(){
	cin>>n;
	for (int i=1;i<=7;i++)
		for (int j=1;j<=7;j++)
			for (int k=1;k<=7;k++)
				if (i+j+k<=9){
					v.clear();
					for (int l=0;l<i;l++) v.push_back(3);
					for (int l=0;l<j;l++) v.push_back(5);
					for (int l=0;l<k;l++) v.push_back(7);
					do{
						if (x()<=n) ans++;
					}while (next_permutation(v.begin(),v.end()));
				}
	cout<<ans<<endl;
	return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

//Heron's formula
double area(double a, double b, double c) {
	double s = (a + b + c) / 2;
	return sqrt(s*(s - a)*(s - b)*(s - c));
}

signed main() {
	cout << fixed << setprecision(8);
	for (double a, l, x; cin >> a >> l >> x&&l;) 
		cout << area(a, l, l) + area(l, (l + x) / 2, (l + x) / 2) * 2 << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, a[maxn];
ll ans;

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

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		if (a[i])
		{
			if (i < n - 1 && ((a[i] & 1) && a[i + 1]))
			{
				a[i]--;
				a[i + 1]--;
				ans++;
			}
			ans += a[i] / 2;
		}
	cout << ans << endl;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int n;
    cin>>n;
    cout<<(n-1)/2<<endl;
}


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

vector<int> get_divisors(int n) {
  vector<int> divisor;
  for(int i=1;i*i<=n;i++) {
    if(n%i == 0) {
      divisor.push_back(i);
      if(i*i!=n) {
        divisor.push_back(n/i);
      }
    }
  }
  sort(divisor.begin(), divisor.end());
  return divisor;
}
int main() {
  int n, k;
  cin>>n>>k;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  sort(a, a + n);
  long long sum_a = 0;
  for (int i=0; i<n; i++) sum_a += a[i];
  vector<int> divisors = get_divisors(sum_a);
  reverse(divisors.begin(), divisors.end());

  for (auto d: divisors) {
    if (d > a[n-1] + k) {
      continue;
    }
    int cnt = 0;
    vector<int> rs;
    for (int i=0; i<n; i++) {
      int m = a[i] % d;
      if (m == 0) {
        continue;
      }
      rs.push_back(m);
    }
    sort(rs.begin(), rs.end());

    int n_rs = rs.size();
    long long m_acc[n_rs+1];
    long long p_acc[n_rs+1];
    m_acc[0] = 0;
    p_acc[0] = 0;
    for (int i=1; i<=n_rs; i++) {
      m_acc[i] = m_acc[i-1] + rs[i-1];
      p_acc[i] = p_acc[i-1] + d - rs[i-1];
    }
    for (int i=0; i<=n_rs; i++) {
      if (max(m_acc[i], p_acc[n_rs] - p_acc[i]) <= k) {
        if ((m_acc[i] - p_acc[n_rs] + p_acc[i]) % d == 0) {
          cout<<d<<endl;
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 384
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 n: usize = read();
    let mut ans: usize = 1;
    if n == 0 {
        println!("1");
        return;
    }
    while ans <= n {
        ans *= 2;
    }
    println!("{}", ans / 2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    vector<ll> x(5, 0);
    rep1(i, 5) cin >> x[i];
    rep1(i, 5) {
        if (x[i]==0){
            cout << i+1 << endl;
        }
    }
}

Measured memory_bytes: 3620
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s=sc.next();
		int c=1;
		for(int i=0;i<n-1;i++) {
			if(s.charAt(i)!=s.charAt(i+1)) {
				c++;
			}
		}
		System.out.println(c);

	}

}


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

int main() {

	string s;
	cin >> s;
	int l = 0, mx = 0;

	for (char c : s) {
		if (c == 'T') l++;
		else l--;
		mx = max(mx, l);
	}

	cout << 2 * mx << endl;

}

Measured memory_bytes: 640
package main

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

func main() {
	N := ReadInt()
	for i := 1; i < 10; i++ {
		for j := 1; j < 10; j++ {
			if i*j == N {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
	return
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }

func ReadInt() int {
	v, e := strconv.Atoi(Read())
	if e != nil {
		panic(e.Error())
	}
	return v
}


Measured memory_bytes: 1772
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.1415;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

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

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;

	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

ll getGcd(ll a, ll b) {
	if (a < b) {
		ll temp = b;
		b = a;
		a = temp;
	}

	ll r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

/*int getNum(ll target) {

	int bottom = 0;
	int top = 151;
	while (1 < top - bottom) {
		int middle = (top + bottom) / 2;
		if (target < line[middle])top = middle;
		else bottom = middle;
	}
	return bottom;
}*/

int main() {

	string N; cin >> N;
	int last = N.size()-1;
	int lastLetter = N[last];
	string ans = "hon";
	if (lastLetter == '3') {
		ans = "bon";
	}
	else if (lastLetter == '0' || lastLetter == '1' || lastLetter == '6' || lastLetter == '8') {
		ans = "pon";
	}
	cout << ans << endl;
}




Measured memory_bytes: 5444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repr(i, n) for(int i = n; i>=0; i--)
#define all(x) (x).begin(), (x).end()
#define INF 100100100
typedef long long ll;
typedef pair<int, int> p;

int main(void)
{
	char in;
	int a, b, c, d;
	scanf(" %c", &in);
	a = in - 48;
	scanf(" %c", &in);
	b = in - 48;
	scanf(" %c", &in);
	c = in - 48;
	scanf(" %c", &in);
	d = in - 48;
	if (a + b + c + d == 7) printf ("%d+%d+%d+%d=7\n", a, b, c, d);
	else if (a + b + c - d == 7) printf ("%d+%d+%d-%d=7\n", a, b, c, d);
	else if (a + b - c + d == 7) printf ("%d+%d-%d+%d=7\n", a, b, c, d);
	else if (a + b - c - d == 7) printf ("%d+%d-%d-%d=7\n", a, b, c, d);
	else if (a - b + c + d == 7) printf ("%d-%d+%d+%d=7\n", a, b, c, d);
	else if (a - b + c - d == 7) printf ("%d-%d+%d-%d=7\n", a, b, c, d);
	else if (a - b - c + d == 7) printf ("%d-%d-%d+%d=7\n", a, b, c, d);
	else printf ("%d-%d-%d-%d=7\n", a, b, c, d);
	return 0;
}


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

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> road(n,0);
  for (int i; i<m*2; i++){
    int tmp;
    cin >>tmp;
    road.at(tmp-1)++;
  }
  for (int c:road){
    cout << c <<endl;
  }
}

Measured memory_bytes: 256
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=int(1e4);
const int cst[10]={0,2,5,5,4,5,6,3,7,6};
int num[10];
string dp[15],Num[10];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++) scanf("%d",&num[i]),Num[i]+='0'+num[i];
	for(int i=2;i<=n;i++){
		for(int j=0;j<m;j++){
			int c=cst[num[j]];
			if(i<c) continue;
			if(dp[(i-c+15)%15]=="" && i-c!=0) continue;
			string str=dp[(i-c+15)%15]+Num[j];
			if(dp[i%15].length()<str.length()) dp[i%15]=str;
			else if(dp[i%15].length()==str.length() && dp[i%15]<str) dp[i%15]=str;
		}
//		cout<<i<<" "<<dp[i%15]<<endl;
	}
	cout<<dp[n%15]<<endl;
	return 0;
}

Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var D int
	fmt.Scanln(&D)

	msgs := []string{
		"Christmas Eve Eve Eve",
		"Christmas Eve Eve",
		"Christmas Eve",
		"Christmas",
	}

	fmt.Println(msgs[D-22])
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include<utility>
using namespace std;
using ll = long long;
int dx[8] = { 1,1,1,1,-1,-1,-1,-1 }, dy[8] = { 1,-1,1,-1,1,-1,1,-1 }, dz[8] = { 1, 1, -1, -1, 1, 1, -1, -1 };

int main() {
	ll n, m, x, y, z,score[8][1000],ans=0;
	fill(score[0], score[8], -1 * 10000000000);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> x >> y >> z;
		for (int j = 0; j < 8; j++) {
			score[j][i] = x * dx[j] + y * dy[j] + z * dz[j];
		}
	}
	for (int i = 0; i < 8; i++) {
		sort(score[i], score[i] + n);
		ll asd = 0;
		for (int j = 0; j < m; j++) {
			asd += score[i][n - 1 - j];
		}
		ans = max(ans, asd);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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

int main() {
	int n;
	cin >> n;
	map<int, int> mp;
	rep(i, n) {
		int a;
		cin >> a;
		mp[a]++;
	}

	int cnt = 0;
	for (auto x : mp) {
		if (x.first == x.second) continue;
		else if (x.first < x.second) cnt += (x.second - x.first);
		else cnt += x.second;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n;
	while(cin>>n,n){
		vector<int> v(n);
		rep(i,n) cin>>v[i];
		sort(v.begin(),v.end());
		int sum=0;
		rep(i,n-2){
			sum+=v[i+1];
		}
		sum/=n-2;
		cout<<sum<<endl;
	}
	return 0;

}

Measured memory_bytes: 1216
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
lis = Is()
slis = sorted(lis)
c = 0
for i in range(n):
    if lis[i] != slis[i]:
        c += 1
if c == 2 or c == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 4584
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct State {
  vector<int> S[3];
  int step;
  int parent_from;
  int parent_to;

  bool empty(size_t i) const { return S[i].size() == 0; }
  void push(size_t i, int v) { S[i].push_back(v); }
  void pop(size_t i) { S[i].pop_back(); }
  int top(size_t i) const { return S[i].back(); }
};

inline bool IsMovable(int from, int to, const State& p) {
  if (to < 0 || to >= 3) return false;
  if (p.empty(from)) return false;
  if (to == p.parent_from && from == p.parent_to) return false;
  return p.empty(to) || p.top(from) >= p.top(to);
}

inline bool Done(int n, const State& p) {
  return p.S[0].size() == n || p.S[2].size() == n;
}

int BFS(const State& start, int n) {
  queue<State> q;
  q.push(start);

  int step = 0;
  while (!q.empty()) {
    const auto p = q.front();
    q.pop();

    if (Done(n, p)) {
      step = p.step;
      break;
    }
    for (int from = 0; from < 3; ++from) {
      for (int d : {-1, 1}) {
        const int to = from + d;
        if (IsMovable(from, to, p)) {
          State new_state = p;
          new_state.step = p.step + 1;
          new_state.parent_from = from;
          new_state.parent_to = to;
          new_state.push(to, p.top(from));
          new_state.pop(from);
          q.push(new_state);
        }
      }
    }
  }
  return step;
}

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

  int n, m;
  for (;;) {
    cin >> n >> m;
    if (n == 0 && m == 0) break;

    // State goal;
    State start;
    start.step = 0;
    for (int i = 0; i < 3; ++i) {
      int t;
      cin >> t;
      int k;
      for (int j = 0; j < t; ++j) {
        cin >> k;
        start.S[i].push_back(k);
      }
    }
    const auto step = BFS(start, n);
    const auto ans = step <= m ? step : -1;
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;
const double PI=3.14159265358979323846;

int main (){
    string S;
    cin >> S;

    if (S.size()<26) {

        rep(i,0,26) {
            char ans = 'a'+i;
            bool tmp=true;
            rep(j,0,S.size()) {
                if (S[j]==ans) {
                    tmp = false;
                }
            }
            if (tmp){
                cout << S << ans << endl;
                break;
            }
        }
    }
    else if (S == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
    }

    else {
        string T = S;
        next_permutation(S.begin(),S.end());
        rep(i,0,S.size()) {
            if (T[i]==S[i]){
                continue;
            }
            else {
                rep(j,0,i+1) {
                    cout << S[j];
                }
                cout << endl;
                break;
            }
        }
    }

}



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

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define iter_e(i, x) for (int i = pos[x]; i; i = g[i].frt)

const int NR = 1e5 + 10;

struct Edge { int y, frt, w; } g[NR << 1];
int pos[NR], gsz, root, sz[NR], ta[NR], n;

void AE(int x, int y, int z) { g[++gsz] = (Edge) { y, pos[x], z }, pos[x] = gsz; }

#define v g[i].y

void dfs(int x, int fa) {
	sz[x] = 1; 
	iter_e(i, x) if (v != fa) {
		dfs(v, x), sz[x] += sz[v];
		ta[x] = max(ta[x], sz[v]);
	}
	ta[x] = max(ta[x], n - sz[x]);
	if (ta[x] < ta[root]) root = x;
}

long long ans;

void dfs2(int x, int fa) {
	sz[x] = 1;
	iter_e(i, x) if (v != fa) {
		dfs2(v, x), sz[x] += sz[v];
		ans += 2ll * g[i].w * sz[v];
	}
}

int main() {
	scanf("%d", &n); ta[0] = n + 2;
	iter(i, n - 1) {
		int x, y, w;
		scanf("%d%d%d", &x, &y, &w);
		AE(x, y, w); AE(y, x, w);
	}
	dfs(1, 0);
	dfs2(root, 0);
	if (ta[root] == (n + 1) / 2) {
		iter_e(i, root) if (sz[v] == n / 2) ans -= g[i].w;
	} else {
		int mind = 1e9;
		iter_e(i, root) if (g[i].w < mind) mind = g[i].w;
		ans -= mind;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 7680
#include"bits/stdc++.h"
//#include<boost/multi_array.hpp>
//#include<boost/optional.hpp>
//#include<boost/range/irange.hpp>
//#include<boost/range/algorithm.hpp>
//#include<boost/range/adaptors.hpp>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

void Main() {
	int n, x, t;
	cin >> n >> x >> t;
	if (n % x == 0) {
		cout << (n / x)*t << endl;
	} else {
		cout << ((n / x)+1)*t << endl;
	}
}

int main() {
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3660
#include <cstdio>
#include <iterator>
#include <queue>
const int INFT = 1e9+7;
const int MAXN = 55;
const int MAXK = 105;
int dp[MAXN][MAXN][MAXK];
int V[MAXN];
int K, N;

int dfs(int l, int r, int m) {
    if (dp[l][r][m] != -INFT) {
        return dp[l][r][m];
    }
    int sum = 0;
    std::priority_queue<int> heap;
    for (int i = 1; i <= N; ++i) if ((i <= l) || (r <= i)) {
        sum += V[i];
        if (V[i] < 0) heap.push(-V[i]);
    }
    if (!m) {
        return dp[l][r][m] = sum;
    }
    // Operations C and D.
    for (int k = 0; (k < m) && !heap.empty(); ++k) {
        sum += heap.top();
        heap.pop();
    }
    // Operations A and B.
    if (l < r) {
        sum = std::max(dfs(l+1, r, m-1), sum);
        sum = std::max(dfs(l, r-1, m-1), sum);
    }
    return dp[l][r][m] = sum;
}

int main() {
    scanf(" %d%d", &N, &K);
    for (int i = 1; i <= N; ++i) {
        scanf("%d", &V[i]);
    }
    for (int i = 0; i <= N + 1; ++i) {
        for (int j = 0; j <= N + 1; ++j) {
            for (int k = 0; k <= K; ++k) {
                dp[i][j][k] = -INFT;
            }
        }
    }
    printf("%d\n", dfs(0, N+1, K));
    return 0;
}
// Case: 3 3 3 -1 3 = 6
// Handle indices: dp[-1][N+1]

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define PII pair<int,int>
#define MP make_pair
#define fir first
#define sec second
#define PB push_back
#define db long double
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
char str[20];
int main() {
	scanf("%s",str+1);
	int len=strlen(str+1);
	int ans=15-len;
	for(int i=1;i<=len;++i) ans+=str[i]=='o';
	if(ans>=8) printf("YES");
	else printf("NO");
	return 0;
} 

Measured memory_bytes: 256
n = int(input())
S = []
H = []
C = []
D = []

for _ in range(n):
    raw = input().split(" ")
    if str(raw[0]) == "S":
        S.append(int(raw[1]))
    elif str(raw[0]) == "H":
        H.append(int(raw[1]))
    elif str(raw[0]) == "C":
        C.append(int(raw[1]))
    elif str(raw[0]) == "D":
        D.append(int(raw[1]))

M = [S, H, C, D]
M_name = ["S", "H", "C", "D"]

for m, m_name in zip(M, M_name):
    for i in range(1,14):
        if i not in m:
            print ("%s %d"%(m_name, i))    

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a == 1) a = 14;
    if(b == 1) b = 14;

    if(a >  b) cout << "Alice" << endl;
    if(a == b) cout << "Draw" << endl;
    if(a <  b) cout << "Bob" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long LL; 

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	LL ans = 1;
	while(n > 0){
		ans *= n;
		n--;
	}
	
	cout << ans << endl;
		
	return 0;
}

Measured memory_bytes: 1184
{-# LANGUAGE CPP #-}

module Main where

import qualified Data.Vector.Unboxed as V
import qualified Data.Map.Strict as M
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.Char
import qualified Data.List as L

dump :: (Show a) => a -> IO ()

#if __GLASGOW_HASKELL__ >= 800
dump x = print x
#else
dump _ = pure ()
#endif

-- "101010" -> [1,0,1,0,1,0]
readToList :: String -> [ Int ]
readToList [] = []
readToList (x : xs) = read [ x ] : readToList xs

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

-- "10 10 10" -> [10, 10, 10]
getList :: IO [ Int ]
getList = (fmap (read . BS.unpack) . BS.words) <$> BS.getLine

-- "10 10 10" -> [10, 10, 10]
getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readmat :: Int -> IO [ [ Int ] ]
readmat rows = replicateM rows getList

newtype UF a = UF (M.Map a a)
    deriving ( Show ) -- Map node parent

makeuf :: Int -> UF Int
makeuf n = let m = M.fromList $ zip [ 0 .. n ] [ 0 .. n ] in UF m

unionUF :: ( Eq a, Ord a ) => a -> a -> UF a -> UF a
unionUF l r uf @ (UF m) = let lp = findUF l uf
                              rp = findUF r uf in if lp == rp then uf
    else if size l uf < size r uf then UF $ M.update (const $ Just rp) lp m
        else UF $ M.update (const $ Just lp) rp m

findUF :: ( Eq a, Ord a ) => a -> UF a -> a
findUF x uf @ (UF m) = let px = m M.! x in if px == x then px else findUF px uf -- TODO 貼り直し

size :: ( Eq a, Ord a ) => a -> UF a -> Int
size x (UF m) = M.size $ M.filter (\par -> par == x) m

genbit :: Int -> [ [ Int ] ]
genbit 0 = []
genbit 1 = [ [ 0 ], [ 1 ] ]
genbit len = do
    x <- [ 0, 1 ]
    map (x :) $ genbit (len - 1)

base :: Int
base = 10 ^ 9 + 7

forn :: ( Num a, Enum a, Monad m ) => a -> (a -> m b) -> m [ b ]
forn x = forM [ 0 .. (x - 1) ]

count :: (Eq a) => a -> [ a ] -> Int
count y = length . filter (== y)

main :: IO ()
main = do
    [ d, n ] <- getList
    if n /= 100 then print $ 100 ^ d * n else print $ 100 ^ d * (n + 1)




Measured memory_bytes: 508
def main():
    n, k = map(int, input().split())
    res = 0
    t=0
    for i in range(1, n + 1):
        count = 0
        j = i
        while (j < k):
            j *= 2
            count += 1
        if i == 1:
            t = count
            res += 1
        else:
            res += 2 ** (t - count)
    res = res/((2**t) *n)
    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  cout << (abs(x - a) <= abs(x - b) ? 'A' : 'B') << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int n[]=new int[3],i,j,t;
		for(i=0;i<3;i++) n[i]=stdIn.nextInt();
		for(i=0;i<2;i++) {
			for(j=2;j>i;j--) {
				if(n[j-1]>n[j]) {
					t=n[j-1];
					n[j-1]=n[j];
					n[j]=t;
				}
			}
		}
		System.out.print(n[0]+n[1]);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
using namespace std;
int n, i, x, y, j, ok;
int c[100005];
vector<int> v[100005];
void dfs(int nod, int t){
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i];
        if(vecin != t){
            dfs(vecin, nod);
            if(c[vecin] == 0){
                if(c[nod] == 1){
                    ok = 0;
                }
                c[nod] = 1;
            }
        }
    }
}
int main(){
    cin>> n;
    for(i = 1; i < n; i++){
        cin>> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    ok = 1;
    dfs(1, 0);
    if(c[1] == 0){
        ok = 0;
    }
    if(ok == 0){
        cout<<"First";
    }
    else{
        cout<<"Second";
    }
}


Measured memory_bytes: 6272
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define all(c) (c).begin(),(c).end()

using namespace std;

int main(void){

  int n;
  while(cin >> n,n){
    vector<int>a(n);
    for(int i=0;i<n;i++)cin >> a[i];
    sort(all(a));
    int ans = 1<<29;
    for(int i=0;i+1<n;i++)
      ans = min(ans,a[i+1]-a[i]);
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-7

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

ll cross(P base, P x1, P x2) {
  return (x1.first - base.first)*(x2.second - base.second) - (x1.second - base.second)*(x2.first - base.first);
}

double dist(P x1, P x2) {
  return sqrt((double)(pow2(x2.first-x1.first) + pow2(x2.second-x1.second)));
}

double poww2(P x1, P x2) {
  return ((pow2(x2.first-x1.first) + pow2(x2.second-x1.second)));
}

vector<P> convex_hull(vector<P> ps) {
  int n = ps.size();
  int k = 0;
  sort(ALL(ps));
  vector<P> qs(n * 2);
  rep(i, n) {
    while(k > 1 && (cross(qs[k-2], qs[k-1], ps[i]) <= 0)) k--;
    qs[k++] = ps[i];
  }
  int t = k;
  repr(i, n-1) {
    while(k > t && (cross(qs[k-2], qs[k-1], ps[i]) <= 0)) k--;
    qs[k++] = ps[i];
  }
  qs.resize(k-1);
  return qs;
}

int main() {
  int n;
  cin >> n;
  vector<P> A;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    A.push_back(P(x, y));
  }

  auto manh = [&](P& p1, P& p2){
      return abs(p1.first - p2.first) + abs(p1.second - p2.second);
  };
  vector<P> Ac = convex_hull(A);
  ll ans = 0;
  rep(i, Ac.size()){
      for (int j = 0; j < i; j++){
          ans = max(ans, manh(Ac[i], Ac[j]));
      }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15900
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

res = 0
for i in range(n):
    res += b[a[i]-1]
    if i >= 1:
        if a[i] == a[i-1]+1:
            res += c[a[i-1]-1]
print(res)

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

using namespace std;

using ll = long long;

ll binExp(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) {
            res *= a;
        }
        a *= a;
        b >>= 1;
    }
    return res;
}

int main() {
    ll n, k;
    cin >> n  >> k;
    if (n == 1) {
        cout << k;
    } else {
        cout << k * binExp(k - 1, n - 1);
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramC
    {
        static List<int> _list;

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var list = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToList();
            _list = new List<int>(list);
            _list.Sort();
            var mean1 = _list[n / 2 - 1];
            var mean2 = _list[n / 2];

            for (var i = 0; i < n; i++)
            {
                var a = list[i];
                var index = BinarySearch3(a);
                var b = index < n / 2 ? mean2 : mean1;
                Console.WriteLine(b);
            }
        }

        static int BinarySearch3(int key)
        {
            int ng = -1;
            int ok = _list.Count;

            while (Math.Abs(ok - ng) > 1)
            {
                int mid = (ok + ng) / 2;

                if (isOk(mid, key))
                {
                    ok = mid;
                }
                else
                {
                    ng = mid;
                }
            }

            return ok;
        }

        // indexが条件を満たすかどうか
        static bool isOk(int index, int key)
        {
            return _list[index] >= key;
        }
    }
}


Measured memory_bytes: 51724
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<algorithm>
#include<cstdlib>
#include<string>
using namespace std;

string just(int n){
	stringstream buf;
	buf<<n;
	while(buf.str().size()<3){
		string t = buf.str();
		buf.str("");
		buf<<" "<<t;
	}
	return buf.str();
}

int main(){
	int n=0,m;
	while(scanf("%d",&m)==1,m){
		int mat[m][m];
		for(int x=0;x<m;x++){
			for(int y=0;y<m;++y)mat[x][y] = 0;
		}
		int j = 1;
		mat[0][0] = j;
		int x=0,y=0;
		while(j!=m*m){
			if(j!= m*m && y+1<m && mat[x][y+1]==0){
				++y;
				++j;
				mat[x][y] = j;
			}
	
			while(j!=m*m && x+1<m && y-1>=0 && mat[x+1][y-1]==0){
				++x;--y;++j;
				mat[x][y]=j;
			}
	
			if(j!=m*m && x+1<m && mat[x+1][y]==0){
				++x;++j;
				mat[x][y]=j;
			}
		
			while(j!=m*m && x-1>=0 && y+1<m && mat[x-1][y+1]==0){
				--x;++y;++j;
				mat[x][y]=j;
			}
		}
		cout<<"Case "<<++n<<":"<<endl;
		for(int x=0;x<m;++x){
			for(int y=0;y<m;++y){
				cout<<just(mat[x][y]);
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1244