akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VLL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// name.order_of_key (val): returns the no. of values strictly less than val
// *name.find_by_order (k): returns the kth largest element iterator.(0-based)

#define INF32 INT_MAX
#define INF64 LLONG_MAX
#define fir first
#define sec second
#define pr_nl cout<<'\n' 
#define nl '\n' 
#define pb push_back
#define MP make_pair
#define lcm(a,b) ((a*b)/gcd(a,b))
#define SET(a,b) memset(a,b,sizeof(a))
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define fast_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

clock_t strt, ed;
double cpu_time_used;
const ld pi=acos(-1);
long long int MOD = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */


long long int fact(int n);
ll power(ll a,ll b);
const int N=(int)2e5+5;
long long int a[N],n,k,dp[N];
int main()
{
	fast_IO;strt = clock();	
//	cout<<fixed<<setprecision(10)<<nl;
    //cerr<<fixed<<setprecision(10)<<nl;
    cin>>n>>k;
    fr(i,1,n) cin>>a[i];
    dp[0]=dp[1]=0;
    dp[2]=abs(a[1]-a[2]);
    for(int i=3;i<=n;i++){
        long long mn=INF32;
        for(int j=1;j<=k;j++){
                if(i-j<1) continue;
              //  trace(i,j,dp[i-j]);
                mn=min(mn,dp[i-j]+abs(a[i]-a[i-j]));
        }
        dp[i]=mn;
    }
    cout<<dp[n]<<nl;
	

	ed = clock();cpu_time_used = ((double) (ed - strt)) / CLOCKS_PER_SEC;trace(cpu_time_used);
	return 0;
}
long long int fact(int n)
{
	return((n==0||n==1)?1:(n*fact(n-1)));
}
ll power(ll a,ll b)
{
	ll r=1;
	while(b){
		if(b & 01) r=(r*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return r;
}


Measured memory_bytes: 1792
n,l = map(int,input().split())
a = [0]+list(map(int,input().split()))
ll = None
for i in range(1,n):
    if a[i]+a[i+1] >= l:
        ll = i
        break

if not ll:
    print('Impossible')
else:
    print('Possible')
    for i in range(1,ll):
        print(i)
    for i in range(n-1,ll,-1):
        print(i)
    print(ll)

Measured memory_bytes: 14060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
	int ans = 0;
	char add;
	string s;
	cin >> s;
	add = s[0];
	for (int i = 1; i < s.size(); i++)
		if (add != s[i]) {
			add = s[i];
			ans++;
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}


#define N 	100*1000+5
void solve(){	
	int n, m;
	cin>>n>>m;
	priority_queue<int>q;
	vii v;
	rep(i,0,n){
		int a, b;
		cin>>a>>b;
		v.pb(mp(a, b));
	}
	sort(all(v));
	ll st = 1, i = 0, ans = 0;
	while(st <= m){
		while(i < n && v[i].x <= st){
			q.push(v[i].y);
			i++;
		}
		if(sz(q)){
			ans += q.top();
			q.pop();
		}
		st++;
	}
	cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
xけせばいい
xxaxxがあったか。そうか。
xadxxxaxxx
xxxaxxdxxaxxx
xaaxxa
もともとペアだったら2個ひけばいいか
だめだったか
*/
int main(){
  string s; cin>>s;
  ll ans=0;
  for(int i=0,j=s.size()-1; i<=j; i++){
    if(i>=j) break;
    while(s[i]!=s[j]){
      if(s[i]=='x'){
        i++;
        ans++;
      }
      else if(s[j]=='x'){
        j--;
        ans++;
      }
      else{
        cout<<-1<<endl;
        return 0;
      }
    }
    j--;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val S = input.next()
    var countA = 0
    var countB = 0
    
    for (c in S) {
      if (c == 'A') {
        ++countA
      }
      
      if (c == 'B') {
        ++countB
      }
    }
    
    if (countA == 3 || countB == 3) {
      println("No")
    } else {
      println("Yes")
    }
  }
}

Measured memory_bytes: 36272
X = int(input())

C = 0
D = 0

if X >= 0 and X <= 10 ** 9:
    while True:
        if X >= 500:
            C = X // 500
            X = X - (500 * C)
        elif X >= 5:
            D = X // 5
            X = X - (5 * D)
        else:
            break

total = (1000 * C) + (5 * D)

print(total)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

int N,x[20];
set<vector<int> > ans;
set<vector<int> >::iterator it;

int vmax(int *d)
{
	int mx;
	for(mx=400; mx>0; mx--) 
	{
		if(d[mx]) break;
	}
	return mx;
}

void dfs(int j, int *d)
{
	if(j==N)
	{
		int tx[20];
		memcpy(tx,x,sizeof(tx));
		sort(tx,tx+N);

		vector<int> v;
		for(int i=0; i<N-1; i++)
		{
			v.push_back(tx[i+1]-tx[i]);
		}
		ans.insert(v);
		return;
	}

	int td[401];
	int L=vmax(d);
	for(int r=0; r<2; r++)
	{
		bool ok=true;
		memcpy(td,d,sizeof(td));

		x[j]=(r==0)?L:(x[1]-L);
		for(int i=0; i<j; i++)
		{
			int dd = abs(x[j]-x[i]);
			
			if(td[dd]==0)
			{
				ok=false;
				break;
			}
			td[dd]--;			
		}
		if(ok)
		{
			dfs(j+1,td);
		}
	}
}

int main()
{
	bool first=true;
	while(cin >> N, N)
	{
		int d[401]={0};
		for(int i=0; i<N*(N-1)/2; i++)
		{
			int t;
			cin >> t;
			d[t]++;
		}

		ans.clear();

		int L=vmax(d);
		x[0]=0; x[1]=L; d[L]--;
		dfs(2,d);

		for(it=ans.begin(); it!=ans.end(); it++)
		{
			for(int i=0; i<N-1; i++)
			{
				cout << (*it)[i] << (i==N-2?"\n":" ");
			}
		}		
		cout << "-----\n";
	}
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001LL;
constexpr double EPS = 1e-10;
using number = long long;


int main() {
    int n, z, w; cin >> n >> z >> w;
    vi a(n);
    rep(i, n) cin >> a[i];
    if (n == 1) cout << abs(a[0] - w) << endl;
    else cout << max(abs(a[n - 2] - a[n - 1]), abs(a[n - 1] - w)) << endl;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())
Y = Y // 1000

flag = 0
x = 0
while x <= N:
    y = 0
    while x + y <= N:
        if 9 * x + 4 * y == Y - N:
            print(x, y, Y - 10 * x - 5 * y)
            flag = 1
            break
        else:
            y += 1
    if flag == 1:
        break
    else:
         x += 1
if flag == 0:
    print('-1 -1 -1')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
int a[100005];
int b[100005];
int c[100005];
int dp[100005][3];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[1][0] = a[0];
    dp[1][1] = b[0];
    dp[1][2] = c[0];

    for(int i=2;i<=n;i++)
    {
        dp[i][0] = max(a[i-1]+dp[i-1][1],a[i-1]+dp[i-1][2]);
        dp[i][1] = max(b[i-1]+dp[i-1][0],b[i-1]+dp[i-1][2]);
        dp[i][2] = max(c[i-1]+dp[i-1][1],c[i-1]+dp[i-1][0]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e6 + 5;
const int MOD = 998244353;

int n;
int a[N], f[N], dp[N];

int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

int modinv(int k)
{
	return pow(k, MOD - 2, MOD);
}

int32_t main()
{
	IOS;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		f[a[i]]++;
	}
	for(int i = N - 1; i >= 1; i--)
	{
		int sum = 0, cnt = 0, sum2 = 0;
		for(int j = i; j < N; j += i)
		{
			cnt += f[j];
			sum += (f[j] * j) % MOD;
			sum2 += ((j * j) % MOD *  f[j]) % MOD;
			sum %= MOD;
			sum2 %= MOD;
			if(j > i)
				dp[i] = (dp[i] - dp[j] + MOD) % MOD;
		}
		if(cnt > 0)
		{
			int cur = (sum * sum) % MOD;
			cur -= sum2;
			cur %= MOD;
			cur += MOD;
			cur %= MOD;
			cur *= modinv(2);
			cur %= MOD;
			dp[i] += cur;
			dp[i] %= MOD;
		}
	}
	int ans = 0;
	for(int i = 1; i < N; i++)
	{
		ans += dp[i] * modinv(i);
		ans %= MOD;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 18688
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define loop(i,n)for(i=0;i<n;i++)
#define INF 1000000000
using ll = long long int;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;





int main(){
    IOS;
    //freopen("inputfile.txt","r",stdin);
  int n,m;cin>>n>>m;
  int ar[4];
 memset(ar,-1,sizeof(ar));
  bool flag = true;
  while(m--)
  {
      int i,v;cin>>i>>v;
      if(ar[i]==-1 || ar[i]==v)ar[i] = v;
      else flag = false;
  }
  if(ar[1]==0 && n>1)flag = false;
  else if(ar[1]==-1 && n>1)ar[1] = 1;
  if(flag==false)cout<<"-1"<<endl;
  else
  {
      for(int i=1;i<n+1;i++)
      {
          if(ar[i]==-1)cout<<"0";
          else cout<<ar[i];
      }
      cout<<endl;
  }
    return 0;
}


Measured memory_bytes: 3632
x,y,z = map(int,input().split())

ans = 0

s = []

while True:
    if x%2 == 0 and y%2 == 0 and z%2 == 0:
        ans += 1
        if [x,y,z] in s:
            print(-1)
            break
        else:
            s.append([x,y,z])
    else:
        print(ans)
        break
    
    x,y,z = y//2+z//2,x//2+z//2,x//2+y//2

Measured memory_bytes: 9196
N = int(input())
A = [int(input()) for i in range(N)]

# 入力された数列を降順でソート
sortA = sorted(A, reverse=True)

if sortA[0] == sortA[1]:
    # 最大値が2個発生するならば、そのときはすべての行で最大値が表示される
    for i in range(N):
        print(sortA[0])
else:
    # 最大値が1個しかない場合、最大値の存在する位置では最大から2番めの値が表示されるが、それ以外では最大値が表示される
    maxP = A.index(sortA[0])
    for i in range(maxP):
        print(sortA[0])
    print(sortA[1])
    for i in range(maxP+1, N):
        print(sortA[0])

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

int main()
{
  int i;
  long long int ans;
  long long int N;
  double D;
  scanf("%lld %lf",&N,&D);
  long long int zahyo[N+1][2];
  double space;
  
  ans = 0;
  for(i=0;i<N;i++){
    scanf("%lld %lld",&zahyo[i][0],&zahyo[i][1]);
    space = sqrt((zahyo[i][0]*zahyo[i][0] + zahyo[i][1]*zahyo[i][1]));
    //printf("%f\n",space);
    if( space <= D ){
      ans++;
    }
  }
  
  printf("%lld\n",ans);
  
  return 0; 
}

Measured memory_bytes: 5264
#include<bits/stdc++.h>
using namespace std;
long long Price[3][2];
vector<int> V;
long long Ans;
void dfs(int pos,long long Left,long long Sum)
{
	if((int)(V.size())==0)
	{
		Ans=Sum;
		return ;
	}
	int Realpos=V[pos];
	long long mx=Left/Price[Realpos][0];
	if(pos==(int)(V.size())-1)
	{
		Ans=max(Ans,Sum+mx*(Price[Realpos][1]-Price[Realpos][0]));
		return ;
	}
	for(int i=0;i<=mx;i++)
		dfs(pos+1,Left-i*Price[Realpos][0],Sum-i*Price[Realpos][0]+i*Price[Realpos][1]);
	return ;
}
int main()
{
	long long N;
	cin>>N;
	for(int j=0;j<2;j++)
		for(int i=0;i<3;i++)
			cin>>Price[i][j];
	for(int i=0;i<3;i++)
		if(Price[i][0]<Price[i][1])
			V.push_back(i);
	dfs(0,N,N);
	for(int i=0;i<3;i++)
		swap(Price[i][0],Price[i][1]);
	V.clear();
	N=Ans;
	for(int i=0;i<3;i++)
		if(Price[i][0]<Price[i][1])
			V.push_back(i);
	dfs(0,N,N);
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 123456789
//0x3f3f3f3f
#define INFL 10000000000000000
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<int,pii> pdii;
long long int MOD = 1000000007;


int main(void){
	ll a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c){
		if(a%2==1)cout<<0<<endl;
		else cout<<-1<<endl;
	}else{
		int ans=0;
		while(1){
			if(a%2==1||b%2==1||c%2==1)break;
			ll ta,tb,tc;
			ta=(b+c)/2;
			tb=(a+c)/2;
			tc=(a+b)/2;
			a=ta;
			b=tb;
			c=tc;
			ans++;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
// #include <vector>

bool isIn(int value, int min, int max) {
    return (min <= value && value <= max);
}
int main(int argc, char* argv[]){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    // 左が0からWの間
    if (!isIn(x-r, 0, W)){
        printf("No\n");
        return 0;
    }
    // 右が0からWの間
    if (!isIn(x+r, 0, W)){
        printf("No\n");
        return 0;
    }
    // 上が0からHの間
    if (!isIn(y-r, 0, H)){
        printf("No\n");
        return 0;
    }
    // 下が0からHの間
    // 右が0からWの間
    if (!isIn(y+r, 0, H)){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
}


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

bool ok(string s, int a, int b) {
  for (int i=0; i<a; i++) {
    if (s[i] < '0' || s[i] > '9') {
      return false;
    }
  }
  if (s[a] != '-') {
    return false;
  }
  for (int i=a+1; i<a+b+1; i++) {
    if (s[i] < '0' || s[i] > '9') {
      return false;
    }
  }
  return true;
}
int main() {
  int a, b;
  cin>>a>>b;
  string s;
  cin>>s;
  if (ok(s, a, b)) {
    cout<<"Yes"<<endl;
  } else {
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=k;i<(ll)(n);i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
const ll inf=1001001001001001;
const int mod=998244353;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}

int main(){
    ll n,m;cin>>n>>m;
    vi v(n);
    rep(i,n)cin>>v[i];
    vector<vector<P>> g(n);
    vector<P> hen(m);
    vi ans(m,1000000000);
    vi c(n);
    rep(i,m){
        ll a,b;cin>>a>>b;a--;b--;
        hen[i].fi=a;hen[i].se=b;
        g[a].eb(b,i);
        g[b].eb(a,i);
        if(v[a]!=v[b]||(c[a]&&c[b]))continue;
        ans[i]=v[a];
        if(c[a])c[b]=3-c[a];
        else if(c[b])c[a]=3-c[b];
        else{
            c[a]=1;c[b]=2;
        }
    }
    vector<P> s(n);
    rep(i,n)s[i].fi=v[i];
    rep(i,n)s[i].se=i;
    sort(all(s));
    rep(i,n){
        if(c[s[i].se])continue;
        for(auto ne:g[s[i].se]){
            if(v[ne.fi]>s[i].fi)continue;
            c[s[i].se]=3-c[ne.fi];
            ans[ne.se]=s[i].fi;
            break;
        }
        if(!c[s[i].se]){
            out(-1);
            return 0;
        }
    }
    rep(i,n){
        if(c[i]==1)cout<<'B';
        else cout<<'W';
    }
    cout<<endl;
    rep(i,m)cout<<ans[i]<<endl;
}


Measured memory_bytes: 22144
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr first
#define sc second
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=3e5+10;
int main()
{
    FASTINOUT;
    int x,a,b;
    cin>>x>>a>>b;
    int A=abs(a-x);
    int B=abs(b-x);
    if (A<=B)
    cout<<"A";
    else
        cout<<"B";
    return 0;
}


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

int main(){
  int n,money=100000;
  cin>>n;
  for( int i=0;i<n;i++ ){
    money=(money/100)*105;
    if(money-money/1000*1000){
      money-=(money-money/1000*1000);
      money+=1000;
    }
  }
  cout<<money<<endl;
  return 0;
}

Measured memory_bytes: 1160
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String S = sc.next();
    	int B = 0;
    	int W = 0;
    	for (int i = 0; i < S.length(); i++) {
    		if (i%2 == 0) {
    			if (S.charAt(i) == '0') {
    				W++;
    			} else {
    				B++;
    			}
    		} else {
    			if (S.charAt(i) == '0') {
    				B++;
    			} else {
    				W++;
    			}
    		}
    	}
    	System.out.println(Math.min(B, W));
    }
}

Measured memory_bytes: 23960
n, y = map(int, input().split())
flag = 0
for i in range(y//10000 + 1):
    total = y - 10000*i
    for j in range((y - 10000*i)//5000 + 1):
        total = y - 10000*i - 5000*j - 1000*(n-i-j)
        if total == 0:
            print(i, j, n-i-j)
            flag = 1
            break
    if flag == 1:
        break
if flag == 0:
    print(-1,-1,-1)

Measured memory_bytes: 3064
#include <iostream>
#include <cassert>
#include <fstream>
#include <sstream>
#include <math.h>
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <time.h>
#include <stdio.h>
#include <deque>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define POW(n) ((n)*(n))
#define ALL(a) (a).begin(),(a).end()
#define cerr if(false) cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

int N,M;
vi list;

struct UnionFind {
	vi root;
	vi sizes;

	UnionFind(int max) : root(max), sizes(max, 1) {
		REP(i, max) {
			root[i] = i;
		}
	}

	int find(int x) {
		if (x == root[x]) return x;

		return root[x] = find(root[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);

		if (x == y)return;

		if (sizes[x] < sizes[y]) swap(x, y);
		if (y == 0) {
			swap(x, y);
		}

		root[y] = x;
		sizes[x] += sizes[y];

		sizes[y] = -1;
	}

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

	int size(int x) {
		return sizes[find(x)];
	}

	void remove(int x) {

		//REP(i,root.size()) {
		//	if (i == 0)continue;
		//	if (root[i] == x)root[i] = 0;
		//}
		root[x] = x;
		sizes[0]--;
	}

};

void solve() {

}

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

	list.resize(N+1,1);

	UnionFind uf(N+1);
	uf.unite(0, 1);

	REP(i,M) {
		int s1, s2;
		cin >> s1 >> s2;

		list[s1]--; list[s2]++;


		//可能性あり
		if (uf.same(s1,0)) {
			uf.unite(s1, s2);
			if (list[s1] == 0)uf.remove(s1);
		}
		
	}

	//cout << (uf.size(0)-1) << endl;
	ll ans = -1;
	for (int v:uf.root) {
		if (v == 0)ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1408
def max_(s, q, j):
  for i in range(1, q):
    if s[0][j] < s[i][j]:
      return False
  return True

D = int(input())
N = 26
c = [int(i) for i in input().split()]
last = [0 for i in range(N)]
s = list()
q = 7
for i in range(q):
  s.append([int(j) for j in input().split()])
  
for i in range(D-q):
  d_score = -1
  ans = -1
  ans_d = -1
  for j in range(N):
    last_day = (i + 1 - last[j])
    arg = s[0][j] + c[j]*last_day
    if d_score < arg and max_(s, q, j):
      d_score = arg
      ans = j+1
    if d_score < arg:
      ans_d = j+1
  if ans == -1:
    ans = ans_d
  print(ans)
  del s[0]
  s.append([int(j) for j in input().split()])
  last[ans-1] = i+1
for i in range(q):
  d_score = -1
  ans = -1
  for j in range(N):
    last_day = i + 1 - last[j]
    arg = s[i][j] + c[j]*last_day
    if d_score < arg:
      d_score = arg
      ans = j+1
  print(ans)
  last[ans-1] = i+1

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

using namespace std;
const int N = 3000;

double p[1 + N];
double dp[1 + N][1 + N];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> p[i];
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
        dp[i][0] = (1 - p[i]) * dp[i - 1][0];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= i; j++)
            dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
    double ans = 0;
    for (int i = (n + 1) / 2; i <= n; i++)
        ans += dp[n][i];
    cout << fixed << setprecision (10) << ans << "\n";
    return 0;
}


Measured memory_bytes: 68992
# cording :utf-8
num_int = int(input())
# print(num_int)

num_list = list(map(int, input().split()))
# print(num_list)

num_max = max(num_list)
# print(num_max)
num_min = min(num_list)
# print(num_min)

num_abs = (num_max - num_min)
print(num_abs)


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

int main(){
    int n, m;
    cin >> n >> m;
    string S;
    cin >> S;

    vector<int> ans;
    int i = n;
    while (i > 0){
        int j = max(0, i - m);
        for (; j < i; j++){
            if (S[j] == '0'){
                break;
            }
        }
        if (i == j){
            puts("-1");
            return 0;
        }

        ans.push_back(i - j);
        i = j;
    }

    copy(ans.rbegin(), ans.rend(), ostream_iterator<int>(cout, " "));
    cout << endl;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

ll f(ll A, ll B) {
	assert(A > 0);
	if(A == B) return 1;
	ll t = A ^ B;
	int k = 63 - __builtin_clzll(t);
	ll mask = (1ll << k) - 1;
	debug("%lld - %lld (%lld)\n", A, B, mask);
	A &= mask;
	B &= mask;
	ll ans = (A == 0 ? mask + 1 : f(A, mask));
	int ta = -1;
	if(A > 0) ta = 63 - __builtin_clzll(A);
	int tb = -1;
	if(B > 0) tb = 63 - __builtin_clzll(B);
	if(tb >= ta) ans += 1ll << k;
	else {
		ans += ((1ll << (k - ta - 1)) - 1) * (1ll << (ta + 1));
		ans += 1ll << (tb + 1);
		ans += (1ll << (ta + 1)) - A;
	}
	return ans;
}

int main() {
	ll A, B;
	cin >> A >> B;
	cout << f(A, B) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(x) (x).begin(),(x).end()

int main () {
  string a, b;
  int num;

  cin >> a >> b;

  istringstream ss = istringstream(a+b);
  ss >> num;

  REP(i, 316) {
    if((i*i) == num) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 384
n = int(input())
c = list(input())

count = 0
i = 0
j = 1

while n>i+j:
    if c[i] == 'W' and c[-j] == 'R':
        count += 1
        i += 1
        j += 1
    elif c[i] == 'R':
        i += 1
    elif c[-j] == "W":
        j += 1

        
print(count)

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

int main()
{
	char b;
	cin >> b;

	if (b == 'A') {
		cout << "T" << endl;
	}
	else if (b == 'T') {
		cout << "A" << endl;
	}
	else if (b == 'G') {
		cout << "C" << endl;
	}
	else if (b == 'C') {
		cout << "G" << endl;

	}


}





Measured memory_bytes: 3536
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e5+5;
int Num[N],n;
inline int Read(){
    char ch;
    int f=1;
    while((ch=getchar())<'0'||ch>'9')
        if(ch=='-') f=-1;
    int x=ch^48;
    while((ch=getchar())>='0'&&ch<='9')
        x=(x<<3)+(x<<1)+(ch^48);
    return x*f;
}
inline void Query(){
    sort(Num+1,Num+n+1);
    for(register int i=1;i<n;i++)
        if(Num[i]==Num[i+1]){
            puts("NO");
            return ;
        }
    puts("YES");
    return ;
}
int main(){
    scanf("%d",&n);
    for(register int i=1;i<=n;i++)
        Num[i]=Read();
    Query();
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P = pair<ll,ll>;

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
    ll N,M;
    cin >> N >>M;
    vector<P> AB(M);
    for(int i=0;i<M;i++){
        ll A,B;
        cin >> A >>B;
        --A;--B;
        AB[i].first = A;
        AB[i].second = B;
    }
    ll addHappy[M] ={};
    UnionFind uf = UnionFind(N);
    for(int i=M-1;i>=0;--i){
        if(uf.same(AB[i].first,AB[i].second)){
            continue;
        }
        addHappy[i] = ll(uf.size(AB[i].first)) * ll(uf.size(AB[i].second));
        uf.unite(AB[i].first,AB[i].second);
    }
    ll temp =0;
    for(int i=0;i<M;i++){
        temp += addHappy[i];
        cout << temp << endl;
    }


    return 0;
}

Measured memory_bytes: 5884
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL n,k,q;
    cin >> n >> k >> q;
    VI a(q);
    REP(i,0,q) cin >> a[i];
    VI c(n);
    REP(i,0,q) ++c[a[i]-1];
    REP(i,0,n) {
        if (c[i] > q - k) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

const ll inf = 1LL << 60;
class SegmentTree {
    vector<ll> data;
    int N;
public:
    SegmentTree(int n) {
        N = 1;
        while (N < n) N *= 2;
        data.resize(2 * N - 1, inf);
    }
    void update(int pos, ll val) {
        pos += N - 1;
        data[pos] = val;
        while (pos > 0) {
            pos = (pos - 1) / 2;
            data[pos] = min(data[2 * pos + 1], data[2 * pos + 2]);
        }
    }
    ll query(int l, int r) {
        return query(l, r, 0, N, 0);
    }
    ll query(int l, int r, int a, int b, int x) {
        if (b <= l || r <= a) {
            return inf;
        }
        if (l <= a && b <= r) {
            return data[x];
        }
        int mid = (a + b) / 2;
        return min(query(l, r, a, mid, 2 * x + 1), query(l, r, mid, b, 2 * x + 2));
    }
};

template<typename T>
void chmin(T &a, T b) {
    a = min(a, b);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int r, c, q;
    while (cin >> r >> c >> q, r + c + q) {
        bool swapflag = false;
        int rr = r, cc = c;
        if (r > c) {
            swapflag = true;
            swap(r, c);
        }
        vector<SegmentTree> vec(r, SegmentTree(c));
        {
            auto grid = make_v(r, c, 0LL);
            REP(i, 0, rr) {
                REP(j, 0, cc) {
                    if (swapflag) {
                        cin >> grid[j][i];
                    } else {
                        cin >> grid[i][j];
                    }
                }
            }
            REP(i, 0, r) {
                REP(j, 0, c) {
                    vec[i].update(j, grid[i][j]);
                }
            }
        }
        REP(i, 0, q) {
            int r1, c1, r2, c2;
            cin >> r1 >> c1 >> r2 >> c2;
            if (swapflag) {
                swap(r1, c1);
                swap(r2, c2);
            }
            ll ans = inf;
            REP (j, r1, r2 + 1) {
                chmin(ans, vec[j].query(c1, c2 + 1));
            }
            cout << ans << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 36708
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int calc(int a, int b, char op){
	if(op=='+') return a+b;
	if(op=='-') return a-b;
	if(op=='*') return a*b;
}


signed main() {
	while (1) {
		int sum = 0;
		vi d(4);
		rep(i, 0, 4) {
			cin >> d[i];
			sum += d[i];
		}
		if (sum == 0) break;
		bool f = false;
		char op[4] = { "+-*" };
		sort(all(d));
		do {
			rep(i, 0, 3) {
				rep(j, 0, 3) {
					rep(k, 0, 3) {
						int t1 = calc(d[0], d[1], op[i]);
						int t2 = calc(d[2], d[3], op[k]);
						int t3 = calc(t1, d[2], op[j]);
						if (calc(t1, t2, op[j]) == 10) {
							printf("((%d %c %d) %c (%d %c %d))\n", d[0], op[i], d[1], op[j], d[2], op[k], d[3]);
							k = 3; j = 3; i = 3; f = true;
						}
						else if (calc(t3, d[3], op[k]) == 10) {
							printf("(((%d %c %d) %c %d) %c %d)\n", d[0], op[i], d[1], op[j], d[2], op[k], d[3]);
							k = 3; j = 3; i = 3; f = true;
						}
					}
				}
			}
			if (f) break;
		} while (next_permutation(all(d)));
		if (f == false) cout << 0 << endl;
	}
}

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

signed main(){

  int q;
  cin>>q;
  deque<int> deq;
  while(q--){
    int com;cin>>com;
    if(com==0){
      int d,x;cin>>d>>x;
      if(d==0)deq.push_front(x);
      else deq.push_back(x);
    }
    else if(com==1){
      int p;cin>>p;
      cout<<deq[p]<<endl;
    }
    else if(com==2){
      int d;cin>>d;
      if(d==0)deq.pop_front();
      else deq.pop_back();
    }
  }

}


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

int w, h;
int map[52][52];


int find_island(int *x, int *y)
{
    for (*y = 1; *y <= h; (*y)++){
        for (*x = 1; *x <= w; (*x)++){
            if (map[*y][*x] == 0){
                return (1);
            }
        }
    }
    
    return (0);
}


void paint_island(int x, int y, int no)
{
    int flag;

    map[y][x] = no;

	do {
		flag = 0;
		for (y = 1; y <= h; y++){
			for (x = 1; x <= w; x++){
				if (map[y][x] == no){
					if (map[y - 1][x] == 0){
						map[y - 1][x] = no;
						flag = 1;
					}
					if (map[y + 1][x] == 0){
						map[y + 1][x] = no;
						flag = 1;
					}
					if (map[y][x - 1] == 0){
						map[y][x - 1] = no;
						flag = 1;
					}
					if (map[y][x + 1] == 0){
						map[y][x + 1] = no;
						flag = 1;
					}
					if (map[y - 1][x - 1] == 0){
						map[y - 1][x - 1] = no;
						flag = 1;
					}
					if (map[y + 1][x - 1] == 0){
						map[y + 1][x - 1] = no;
						flag = 1;
					}
					if (map[y - 1][x + 1] == 0){
						map[y - 1][x + 1] = no;
						flag = 1;
					}
					if (map[y + 1][x + 1] == 0){
						map[y + 1][x + 1] = no;
						flag = 1;
					}
				}
			}
		}
	} while (flag == 1);
}


int main(void)
{
    int x, y;
    int a;
    int island_no;
    
    while (1){
        scanf("%d%d", &w, &h);
        if (w == 0 && h == 0){
            break;
        }
        
        memset(map, 0, sizeof(map));
        for (y = 1; y <= h; y++){
            for (x = 1; x <= w; x++){
                scanf("%d", &a);
                if (a == 0){
                    map[y][x] = -1;
                }
                else {
                    map[y][x] = 0;
                }
            }
        }
        
        island_no = 0;
        while (find_island(&x, &y) == 1){
            island_no++;
            paint_island(x, y, island_no);
        }
        
        printf("%d\n", island_no);
    }
    return (0);
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    if(a <= 5)
    {
        cout << "0";
    }
    else if(a <= 12)
    {
        cout << b / 2;
    }
    else
    {
        cout << b;
    }
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/perl
use POSIX qw(floor);

my ($n,$k) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @a = map { $_ - 1 } split(/\s+/,<STDIN>);

my @vi = ();
$#vi = $n - 1;

if( $a[0]==0 ){
  print "1\n"; exit(0);
}

my $x = 0;
my $ci = -1;

for(my $i=0;$i<=$n;$i++){
  if( ('x' . $vi[$x]) ne 'x' ){
    $ci = $i;
    last;
  }
  $vi[$x] = $i;
  $x = $a[$x];
}

my  $xx = $vi[$x];
my  $yy = $ci - $vi[$x];

#print "$n $k $xx $yy \n";

if( $k > $xx + $yy ){
  my $d1 = ( $k - $xx ) % $yy;
  my $d2 = ( $k - $xx - $d1 ) / $yy;
  $k -= $d2 * $yy;
}

#print "$n $k $xx $yy \n";


$x = 0;
for(my $i=0;$i<$k;$i++){
  $x = $a[$x];
}

$x++;
print "$x\n";






Measured memory_bytes: 40608
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int ue,migi,mae;
int main(){
	int N;
	string str;
	int strsn[10000];
	int tokitasu,tmp;
	while(1){
	cin>>N;
	if(N==0)  break;
	for(int i=0;i<N;i++){
		cin>>str;
		if(str=="North")strsn[i]=0;
		else if(str=="East")strsn[i]=1;
		else if(str=="South")strsn[i]=2;
		else if(str=="West")strsn[i]=3;
		else if(str=="Right")strsn[i]=4;
		else strsn[i]=5;
	}
	tokitasu=1;
	ue=1;migi=3;mae=2;
	for(int i=0;i<N;i++){
		switch(strsn[i]){
		case 0:
			tmp=ue;
			ue=mae;
			mae=(7-tmp);
			break;
		case 1:
			tmp=ue;
			ue=(7-migi);
			migi=tmp;
			break;
		case 3:
			tmp=ue;
			ue=migi;
			migi=(7-tmp);
			break;
		case 2:
			tmp=ue;
			ue=(7-mae);
			mae=tmp;
			break;
		case 4:
			tmp=mae;
			mae=migi;
			migi=(7-tmp);
			break;
		case 5:
			tmp=mae;
			mae=(7-migi);
			migi=tmp;
			break;
		}
		tokitasu+=ue;
	}
	cout<<tokitasu<<endl;
	}
	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
int A[110];

int main(int argc, char *argv[])
{
    int a, b, k;
    std::cin >> a >> b >> k;
    int count = 0;
    for(int i = 1; i <= std::min(a,b); i++){
        if(!(a%i) && !(b%i)){
            A[count] = i;
            count++;
        }
    }
    std::cout << A[count-k] << std::endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func reverseCopy(r, s []byte) {
	n := len(s)
	for i := 0; i < n; i++ {
		r[i] = s[n-i-1]
	}
}

func main() {
	var s string
	var q int
	fmt.Scan(&s, &q)

	rev := false
	head := []byte{}
	tail := []byte{}
	body := []byte(s)

	for ; q > 0; q-- {
		var t int
		fmt.Scan(&t)
		if t == 1 {
			head, tail = tail, head
			rev = !rev
		} else {
			var f int
			fmt.Scan(&f, &s)

			if f == 1 {
				head = append(head, s[0])
			} else {
				tail = append(tail, s[0])
			}
		}
	}

	// fmt.Println(string(head), string(body), string(tail))
	res := make([]byte, len(head))
	reverseCopy(res, head)
	if rev {
		tmp := make([]byte, len(body))
		reverseCopy(tmp, body)
		res = append(res, tmp...)
	} else {
		res = append(res, body...)
	}
	res = append(res, tail...)
	fmt.Println(string(res))
}


Measured memory_bytes: 5760
#include <stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	int i,j,ans;
	for(i=0;i<10;i++){
		j=i+1;
		if(1000*i<n && n<=1000*j){
			ans=1000*j-n;
			break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1732
fun main(args: Array<String>) = IO().exec {
    val n = int()
    val a = LongArray(n){long()}
    a.sort()
    a.reverse()
    val cum = Cum(a)
    var cnt = 1
    for (i in 1 until n) if (cum[i until n] * 2 >= a[i-1]) cnt++ else break
    println(cnt)
}

class Cum(val a: LongArray) {
    val s = LongArray(a.size + 1)
    init {
        for (i in a.indices) {
            s[i+1] = s[i] + a[i]
        }
    }
    operator fun get(range: IntRange): Long = s[range.last+1] - s[range.first]
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

Measured memory_bytes: 41932
#include <iostream>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int a, b; cin >> a >> b; cout << max(0, a - 2 * b);
}

Measured memory_bytes: 896
#二部グラフ化できるか
#最大深さ

from collections import deque

n = int(input())
s = []

for i in range(n):
    sij = input()
    s.append(sij)
    
d = [-1]*n

Q = deque()

d[0] = 0

Q.append(0)

while Q:
    v = Q.popleft()
    for i in range(n):
        if int(s[v][i]):
            if d[i]<0:
                d[i] = d[v] + 1
                Q.append(i)
            elif (d[i]-d[v])%2==0:
                print(-1)
                exit()

mxd = max(d)
mxd_id = d.index(mxd)

"""   
d2 = [-1]*n

d2[mxd_id] = 0

Q.append(mxd_id)

while Q:
    v = Q.popleft()
    for i in range(n):
        if int(s[v][i]):
            if d2[i]<0:
                d2[i] = d2[v] + 1
                Q.append(i)
"""

#最長距離の求め方をフロイドワーシャルに変更
dd = [[10**5 for i in range(n)] for j in range(n)]
for i in range(n):
    dd[i][i] = 0
    for j in range(n):
        if int(s[i][j]):
            dd[i][j] = 1
for k in range(n):
    for i in range(n):
        for j in range(n):
            dd[i][j] = min(dd[i][j], dd[i][k] + dd[k][j])
            

ans = 0

for i in range(n):
    for j in range(n):
        ans = max(ans, dd[i][j])

print(ans+1)



                
        

Measured memory_bytes: 43244
import java.util.Scanner;                                                                        
class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(true){
            int a = 0;
            int n = in.nextInt();
            int x = in.nextInt();
        if(n == 0 && x == 0){
            break;
        }
        for(int i = 1; i <= n-2; i++){
            for(int j = i+1; j <= n-1; j++){
                for(int k = j+1; k <= n; k++){
                    if(i+j+k == x){
                        a++;
                    }
                }
            }
        }
                System.out.println(a);
        }
   }
}

Measured memory_bytes: 26312
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	public void solve() {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] ansArr = new int[n];
		Arrays.fill(ansArr, -1);
		
		int m = sc.nextInt();
		for(int i = 0 ; i < m; i++) {
			int s = sc.nextInt();
			int c = sc.nextInt();
			
			if(ansArr.length > 1 && s == 1 && c == 0) {
				System.out.println(-1);
				sc.close();
				return;
			}
			if(ansArr[s-1] >= 0 && ansArr[s-1] != c) {
				System.out.println(-1);
				sc.close();
				return;
			}
			ansArr[s-1] = c;
		}
		
		for(int i = 0; i < n ; i++) {
			if(ansArr[i] < 0) {
				if(i == 0 && ansArr.length > 1) {
					System.out.print(1);
				}else {
					System.out.print(0);
				}
			}else {
				System.out.print(ansArr[i]);
			}
		}
		
		System.out.print("\n");
		
		sc.close();
	}
}


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

int top, S[1000];

void push(int x) {
    S[++top] = x;
}

int pop() {
    top--;
    return S[top+1];
}

int main() {
    int a, b;
    top = 0;
    char s[100];
    while ( scanf("%s", s) != EOF) {
        if(s[0] == '+') {
            a = pop();
            b = pop();
            push(a + b);
        } else if(s[0] == '-'){
            b = pop();
            a = pop();
            push(a - b);
        } else if (s[0] == '*') {
            a = pop();
            b = pop();
            push(a * b);
        }else {
            push(atoi(s));
        }
    }
    
    printf("%d\n", pop());
    
    return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n, result;
    double t, a, tmp = 10000000.0, hoge;
    cin >> n >> t >> a;
    for(int i = 0; i < n; ++i) {
        cin >> hoge;
        hoge = abs(t - hoge * 0.006 - a);
        if(hoge < tmp) {
            tmp = hoge;
            result = i + 1;
        }
    }
    cout << result << endl;
    return 0;
}


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

int main() {
  int x; cin >> x;
  const int lim = 100003;
  vector<int> p(lim);
  for (int i=2; i<=lim; i++) {
    for (int j=i; j<=lim; j+=i) {
      p[j]++;
    }
  }

  rep(i,lim+1) {
    if (p[i] == 1 && i >= x) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3800