akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

vector<int> calc(vector<int> a) {
  map<int,int> m;
  for(int i = 0; i < a.size(); ++i) {
    m[a[i]] += 1;
  }
  for(int i = 0; i < a.size(); ++i) {
    a[i] = m[a[i]];
  }
  return a;
}

int n;
vector<int> a;

int main() {
  while(cin >> n && n) {
    a.resize(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    int res = 0;
    while(1) {
      vector<int> b = calc(a);
      if(a == b) break;
      a = b;
      ++res;
    }
    cout << res << endl;
    for(int i = 0; i < n; ++i) {
      if(i) cout << " ";
      cout << a[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm. fill_n(&an[0][0],n*m,0); typedef long long ll;*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}

void solve(){
	int n;
	cin >> n;
	int a[n];
	FO(i,0,n)cin >> a[i];
	int tm = 0,fm = 0;
	FO(i,0,n){
		if(a[i]%2 == 0){
			if(a[i]%4 == 0)fm++;
			else tm++;
		}
	}
	n -= tm;
	if(tm > 0){
		if(2*fm >= n)cout << "Yes" << endl;
		else cout << "No" << endl;
	}else{
		if(2*fm+1 >= n)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

int32_t main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int t; t = 1;
	// cin >> t;
	FE(i,1,t)
		solve();
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        long a, b, c, d;
        cin >> a >> b >> c >> d;
        if (a < b || d < b) {
            cout << "No";
        } else if (c >= b) {
            cout << "Yes";
        } else {
            long bb = b;
            long dd = d;
            while (dd > 0) {
                long tt = bb % dd;
                bb = dd;
                dd = tt;
            }
            long g = bb;
            long k = (a - b + 1 + g - 1) / g;
//            cout << g << " " << k << " " << (a - k * g) << "\n";
            if (a - k * g > c) {
                cout << "No";
            } else {
                cout << "Yes";
            }
        }
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
while True:
  n = int(input())
  if n == 0:
    break
  tlst = []
  qlst = []
  for _ in range(n):
    m, a, b = map(int, input().split())
    qlst.append((m, a, b))
    tlst.append(a)
    tlst.append(b)
    tlst.append(b - 1)
  tlst = sorted(list(set(tlst)))
  tlst.sort()
  tdic = {}
  for i, t in enumerate(tlst):
    tdic[t] = i
  lent = len(tlst)
  mp = [0] * lent
  for m, a, b in qlst:
    a, b = tdic[a], tdic[b]
    mp[a] += m
    mp[b] -= m
  
  acc = 0
  for i in range(lent):
    acc += mp[i]
    if acc > 150:
      print("NG")
      break
  else:
    print("OK")



Measured memory_bytes: 5628
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>

using namespace std;

typedef long long ll;

ll MOD = 2019;

int main(void){
    ll l, r;
    cin >> l >> r;
    if(r - l - 1 >= 2019){
        cout << 0 << endl;
        return 0;
    }
    ll ans = MOD;
    for(ll i = l;i <= r - 1; i++){
        for(ll j = i + 1;j <= r; j++){
            ans = min(ans, (i * j) % MOD);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    lint n, k;
    cin >> n >> k;

    vector<lint> as(n);
    for(lint i=0; i<n; i++)  cin >> as[i];

    vector<lint> sum{0};
    for(auto e : as)  sum.push_back(sum.back() + e);

    vector<lint> feat(n+1);
    for(lint i=0; i<=n; i++)  feat[i] = (sum[i] - i) % k;

    map<lint, lint> mp;
    lint ans = 0;
    for(lint l=0, r=0; r<=n; r++) {
        if(r - l == k)  mp[feat[l++]]--;
        ans += mp[feat[r]];
        mp[feat[r]]++;
    }

    cout << ans << endl;
}

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

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

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

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


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

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

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

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

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
int main(){
	long double a, b, c, d, t;
	cin >> a >> b >> c >> d >> t;
	YES(b-d>0&&abs(a-c)/(b-d)<=t)
	return 0;
}

Measured memory_bytes: 3724
#include <stdio.h>

int main(void)
{
	int c1,c5,c10,c50,c100,c500,a,b;
	scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
	a=c1+(c5*5)+(c10*10)+(c50*50)+(c100*100)+(c500*500);
	if(a>=1000){
		b=1;
	}else{
		b=0;
	}
	printf("%d\n",b);
	return 0;
}


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

using namespace std;

int N, mod = 1e9 + 7, a[60];

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int substract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}

int pow (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

/*void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i);
inv[lim] = pow (fac[lim], mod - 2);for (int i=lim - 1; i>=1; i--)inv[i] = mul (inv[i + 1], i + 1);}
int comb (int N, int K){int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;}*/

int brut = 0;
void back (int pos)
{
    if (pos == N + 1)
    {
        for (int i=N + 1; i<=2 * N; i++)
            a[i] = a[N];
        bool ok = 1;
        for (int i=1; i<=N; i++)
            for (int j=i + 1; j<=i + a[i]; j++)
                if (a[j] != a[i + 1])
                    ok = 0;
        if (ok)
        {
            brut ++;
/*            for (int i=1; i<=N; i++)
                printf ("%d ", a[i]);
            printf ("\n");*/
        }
        return ;
    }
    for (int i=1; i<=N; i++)
        a[pos] = i, back (pos + 1);
}

int ans = 0, dp[1000009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
/*back (1);
printf ("%d\n", brut);*/
dp[0] = 1, dp[1] = dp[2] = 0, dp[3] = 1, dp[4] = 2;
for (int i=5; i<=N; i++)
    dp[i] = add (add (dp[i - 1], dp[i - 1]), substract (dp[i - 3], dp[i - 2]));
/*for (int i=0; i<N; i++)
    for (int j=2; i + j + 1 <= N; j++)
        dp[i + j + 1] = add (dp[i + j + 1], mul (dp[i], j - 1));*/
/*for (int i=0; i<=N; i++)
    printf ("%d\n", dp[i]);
return 0;*/
for (int i=1; i<=N; i++)
    dp[i] = add (dp[i], dp[i - 1]);
ans = 1;///full de 1
for (int i=0; i<N; i++)
{
    ans = add (ans, mul (dp[i], N - 1));
    if (i < N - 1)
        ans = add (ans, mul (dp[i], mul (N - 1, N - 1)));
}
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 4096
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,a,k=0,d=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a);
		if(a%4==0)
		{
			k++;
		}
		if(a%2==0&&a%4!=0)
		{
			d++;
		}
	}
	if(d!=0)
	{
		if(k>=n-k-d)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else if(d==0)
	{
		if(n-k-1<=k)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
} 

Measured memory_bytes: 256
from collections import deque


def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set() for _ in range(3 * N)]
    for a, b in LIST:
        a, b = 3 * (a - 1), 3 * (b - 1)
        NEAR[a].add(b + 1)
        NEAR[a + 1].add(b + 2)
        NEAR[a + 2].add(b)
    return NEAR


def bfs(S, T, N):  # 幅優先探索  # キュー
    S, T = 3 * (S - 1), 3 * (T - 1)
    dist = [-3] * (3 * N)  # 前処理
    dist[S] = 0
    que, flag = deque([S]), set([S])

    while que:
        q = que.popleft()
        for i in near[q]:  # 移動先の候補
            if i in flag:  # 処理済みか否か
                continue
            dist[i] = dist[q] + 1
            que.append(i), flag.add(i)
    return dist[T] // 3


n, m = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(m)]
s, t = map(int, input().split())

# 解説AC
near = nearlist(n, uv)
ans = bfs(s, t, n)
print(ans)


Measured memory_bytes: 217256
#include <iostream>
#include <string.h>

using namespace std;

int main(){
 int W,a,b;
 scanf("%d %d %d",&W,&a,&b);

 if(a-W <= b && b <= a+W){
   cout << 0 << endl;
 }

 if(a+W < b){
   cout << b-a-W << endl;
 }
 if(a-W > b){
   cout << a-b-W << endl;
 }
 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  priority_queue<pll,vector<pll>,greater<pll>> q;
  for(ll i=0;i<n;i++) {
    ll a,b;
    cin >> a >> b;
    q.push({b,a});
  }
  ll cur=0;
  while(q.size()) {
    ll ti=q.top().first;
    ll co=q.top().second;
    q.pop();
    if(cur+co>ti) {
      cout << "No" << endl;
      return 0;
    }
    cur+=co;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 6512
#include <iostream>
#include <cstdio>
#define rep (i, n) for (int i = 1; i <= n; i++)
#define int long long

using namespace std;

signed main() {
	int x;
	cin >> x;
	
	long double s = 100;
	int cnt = 0;
	int t = s;
	while (t < x) {
		cnt++;
		s = 1.01 * t;
		t = (int)s;
	}
	
	cout << cnt << '\n';
	
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<" ---------------------------------------------- "<<endl
#define LL long long
#define uint unsigned int 
#define ULL unsigned long long
#define LDB long double
#define DB double
#define pii pair<int,int>
#define pli pair<LL,int>
#define mp make_pair
#define pb push_back
using namespace std;
inline LL read(){
	LL nm=0; bool fh=true; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) fh^=(cw=='-');
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return fh?nm:-nm;
}
#define mod 1000000007
namespace  CALC{
	inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
	inline int mns(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
	inline int mul(LL x,LL y){return x*y%mod;}
	inline void upd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
	inline void dec(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
	inline int qpow(int x,int sq){int res=1;for(;sq;sq>>=1,x=mul(x,x))if(sq&1)res=mul(res,x);return res;}
}using namespace CALC;
#define M 3200000
int n,m,pre[M],mx,suf[M],t[M],ans;
char ch[M];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%s",ch+1),n=strlen(ch+1),suf[n+1]=n+n+1,mx=0;
	for(int i=1;i<=n;i++) mx=max(mx,pre[i]=pre[i-1]+((ch[i]=='1')?1:-1));
	for(int i=n;i>0;i--) suf[i]=min(suf[i+1],mx-pre[i]);
	int dn=0;
	for(int i=1,now=0,pr=0;i<=n;i++){
		if(ch[i]!='?') t[i]=((ch[i]-'0')<<1)-1;
		else if(now+2<=suf[i]) now+=2,t[i]=1;
		else t[i]=-1;
		pr+=t[i],dn=min(dn,pr);
	} ans=mx-dn;
	mx++,dn=0;
	for(int i=n;i>0;i--) suf[i]=min(suf[i+1],mx-pre[i]);
	for(int i=1,now=0,pr=0;i<=n;i++){
		if(ch[i]!='?') t[i]=((ch[i]-'0')<<1)-1;
		else if(now+2<=suf[i]) now+=2,t[i]=1;
		else t[i]=-1;
		pr+=t[i],dn=min(dn,pr);
	} ans=min(ans,mx-dn);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 16504
import Data.List
import Data.Maybe

table = ['A'..'Z']

solve :: Int -> String -> String
solve _ [] = []
solve n (s:ss) = res : solve n ss
  where res = table !! ((fromJust (s `elemIndex` table) + n) `mod` 26)

main :: IO ()
main = do
  n <- readLn
  s <- getLine
  putStrLn $ solve n s


Measured memory_bytes: 1532
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int tmp1 = a;
	a = b;
	b = tmp1;
	int tmp2 = a;
	a = c;
	c = tmp2;
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 888
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long e = sc.nextLong();

        long[] list = {a, b, c, d, e};
        Arrays.sort(list);

        long count = n / list[0] + 4;
        if (n % list[0] != 0) {
            count++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n,l,i,t=0;
  cin>>n>>l;
  t=n*(l-1);
  t+=(n*(n+1))/2;
  if(l>=0)
  t-=(l);
  else 
  {int k,r;
  r=l-1;
  if ((-1*r) <= n) k=0;
  else k=r+n;
  t-=k;
      
  }
  cout<<t;
  return 0;
   
  
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout << a[0] << ' ' << a[1] << ' ' << a[2] << endl;
    
    return 0;
}

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

using namespace std;

int main() {
	string S;
	cin >> S;
	int cnt = 0;
	for(int i = 1; i < S.size(); i++) {
		if(S[i] != S[i-1]) cnt++;
	}
	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 512
#include<cstdio>
inline int in();
typedef long long ll;
inline void wr(ll);
const int N=(int)2e5+5;
ll a[N],tong[N],sum[N];
int main(int argc,char**argv){
	register int n=in();
	for(register int i=1;i<=n;++i)
		a[i]=in();
	for(register int i=1;i<=n;++i)
		++tong[a[i]];
	for(register int i=1;i<=n;++i)
		sum[0]+=tong[i]*(tong[i]-1)/2;
	for(register int i=1;i<=n;++i)
		sum[i]=sum[0]-tong[i]*(tong[i]-1)/2;
	for(register int k=1;k<=n;++k){
		--tong[a[k]];
		wr(sum[a[k]]+tong[a[k]]*(tong[a[k]]-1)/2),putchar('\n');
		++tong[a[k]];
	}
}
inline int in(){
	register char c=getchar();
	register int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())
		if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	return x*f;
}
inline void wr(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)wr(x/10);
	putchar(x%10+'0');
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    int first = 0, last = (N - 1);
    vector<string> mem(N);
    string str1, str2;
    if (mem[first] == "")
    {
        cout << first << endl;
        cin >> str1;
        if (str1 == "Vacant")
            return 0;
        mem[first] = str1;
    }

    if (mem[last] == "")
    {
        cout << last << endl;
        cin >> str2;
        if (str2 == "Vacant")
            return 0;
        mem[last] = str2;
    }
    for (size_t i = 0; i < 18; i++)
    {
        int mid = (first + last) / 2;
        string str;
        if(mem[mid]=="")
        {
            cout<<mid<<endl;
            cin>>str;
            if(str == "Vacant")
            return 0 ;
            mem[mid]=str;
        }

        if (abs(first - mid) % 2 == 0)
        {
            if (mem[first] == mem[mid])
                first = mid;
            else
                last = mid;
        }
        else if (abs(first - mid) % 2 != 0)
        {
            if (mem[first] == mem[mid])
                last = mid;
            else
                first = mid;
        }
    }

    return 0;
}

Measured memory_bytes: 6348
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

int main(void) {
  ll n;
  cin >> n;
  arrll(a,n);
  ll ans;
  rep(i,n){
    if(a[i]==0){
      prt(0);
      return 0;
    } else {
      ans=a[0];
    }
  }

  rep(i,n-1){
    if(a[i+1]>1000000000000000000/ans){
      prt(-1);
      return 0;
    }
    ans*=a[i+1];
  }

  prt(ans);
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
 
// Shortcut
 
#define int long long
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)
 
// I/O & Debug
 
#define PrintV(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << ' ';
#define PrintVl(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << endl;
#define PrintA(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << ' ';
#define PrintAl(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/
 
// Functions
 
//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a));
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());
 
// Data Structure
 
#define pque priority_queue
#define mts multiset
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;
 
const int N = 1e3 + 5, M = 2e3 + 5, mod = 1e9 + 7, inf = 1e9 + 7;
 
int n, k, ans;
int a[N], pow2[45];
vi x, y;
bool ck;
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    pow2[0] = 1;
    For(i, 1, 45){
        pow2[i] = pow2[i - 1] * 2;
    }
    cin >> n >> k;
    ForE(i, 1, n){
        cin >> a[i];
    }
    ForE(i, 1, n){
        int ans = 0;
        ForE(j, i, n){
            ans += a[j];
            x.pb(ans);
        }
    }
    FordE(i, 44, 0){
        y.clear();
        For(j, 0, x.size()){
            if (x[j] & pow2[i]){
                y.pb(x[j]);
            }
        }
        if (y.size() < k){
            continue;
        }
        ans += pow2[i];
        x.clear();
        x = y;
    }
    cout << ans;
}
 
/*
==================================+
INPUT:                            |
------------------------------    |
 
------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |
 
------------------------------    |
==================================+
*/

Measured memory_bytes: 6384
#include<stdio.h>
int main(){
  long n,m,ans=0;
  scanf("%ld%ld",&n,&m);
  if(m<=n){
    ans=m/2;
  }
  else if(m>n && m/2<=n){
    ans=m/2;
  }
  else{
    ans=n+(m-2*n)/4;
  }
  printf("%ld\n",ans);
  return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] a = new int[n];
		int[] b = new int[n];
		for( int i=0 ; i<n ; i++ ) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		
		long ans = 0;
		
		for( int i=n-1 ; i>=0 ; i--) {
			long c = (a[i] + ans) % b[i];
			if(c>0)
				ans += b[i] - c;
		}
		
		System.out.println(ans);
		
	}
}


Measured memory_bytes: 60356
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int n, m, ans = 0;
    vector<string> a, b;
    string s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        a.push_back(s);
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> s;
        b.push_back(s);
    }
    for (int i = 0; i < n; i++) {
        int p = 0;
        for (int j = i; j < n; j++) {
            if (a[i] == a[j]) p++;
        }
        for (int j = 0; j < m; j++) {
            if (a[i] == b[j]) p--;
        }
        ans = max(p, ans);
    }
    cout << ans << endl;
}







Measured memory_bytes: 256
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    
    if m == -1 or f == -1:
        print ("F")
    elif m + f >= 80:
        print ("A")
    elif m + f >= 65:
        print ("B")
    elif m + f >= 50:
        print ("C")
    elif m + f >= 30:
        if r >= 50:
            print ("C")
        else:
            print ("D")
    else:
        print ("F")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
template <typename T>
struct UnionFind {
   vector<T> par; 
 
   UnionFind(T N) : par(N) { 
        for(T i = 0; i < N; i++) par[i] = i;
   }
 
   int root(T x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
   }
 
   void unite(T x, T y) { 
       T rx = root(x); 
       T ry = root(y); 
       if (rx == ry) return; 
       par[rx] = ry; 
   }
 
   bool same(T x, T y) { 
       T rx = root(x);
       T ry = root(y);
       return rx == ry;
   }
};
 

bool is_product_overflow(long double a, long double b) {

	long double prod = a * b;
	
	return (prod / b != a);
}


int main(){

    long double a,b,c;
    cin >> a >> b >> c;
    long double d=c-a-b;


    if(a+2*sqrt(a*b)+b<c){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
 
}

Measured memory_bytes: 256
s = int(input())
mod = 10**9 + 7

dp = [0]*(s+1)
dp[0] = 1

for i in range(1,s+1):
    if i >= 3:
        dp[i] = dp[i-3] + dp[i-1]
        dp[i] %= mod

print(dp[s])

Measured memory_bytes: 63432
count = 0
c = [10, 50, 100, 500]
while true do
  price = gets.to_i
  break if price.zero?
  puts if !count.zero?
  b = gets.split.map(&:to_i)
  total = (b.zip(c)).map{|x, y| x * y}.reduce(:+)
  change = total - price
  f = []
  c.reverse.each{|x|
    f.unshift change / x
    change %= x
  }
  4.times{|i| puts "#{c[i]} #{(b[i] - f[i])}" if b[i] - f[i] > 0 }
  count += 1
end

Measured memory_bytes: 8888
k = ["R","U","D"]
g = ["L","U","D"]
S = list(input())
ans = "Yes"

for n,s in enumerate(S):
    if(n % 2 == 0):
        if((s in k) == False):
            ans = "No"
            break
    else:
        if((s in g) == False):
            ans = "No"
            break
print(ans)


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

int main(){
    int L,R;
    cin >> L >> R;
    
    if (R-L>=2018) {
        cout <<0 << endl;
    } else if(R-L<2018){
        int l = L%2019, r=R%2019;
        int tmp=2019*2019;
        if (r<l) {
            for (int i=l; i<=2018; i++) {
                for (int j=0; j<=r; ++j) {
                    tmp = min(tmp, (i*j)%2019);
                }
            }
            cout << tmp << endl;
        } else {
            for (int i=l; i<=r; i++) {
                for (int j=i+1; j<=r; ++j) {
                    tmp = min(tmp, (i*j)%2019);
                }
            }
            cout << tmp <<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll N, n = -1;
    cin >> N;
    if (N == 1) {
        vector<int> arr = {1};
        cout << "Yes" << endl << "2" << endl;
        for(int i = 0; i < 2; i++) {
            cout << arr.size() << " ";
            for(int val: arr)
                cout << val << " ";
            cout << endl;
        }
        return 0;
    }
    // 1, 3, 6, 10, 15....
    ll acc = 1;
    for(ll i = 2; ; i++) {
        acc += i;
        if (acc > N) {
            break;
        } else if (acc == N) {
            n = i;
        }
    }
    if (n == -1) {
        cout << "No" << endl;
    } else {
        vector<vector<int>> arr = {{1, 2}, {2, 3}, {1, 3}};
        int cur = arr.back().back()+1;
        for(int i = 3; i <= n; i++) {
            for(int j = 0; j < i; j++) {
                arr[j].push_back(cur+j);
            }
            vector<int> nxt(i, 0);
            for(int j = 0; j < i; j++)
                nxt[j] = (cur+j);
            arr.push_back(nxt);
            cur = nxt.back()+1;
        }
        cout << "Yes" << endl << arr.size() << endl;
        for(int i = 0; i < arr.size(); i++) {
            cout << arr[i].size() << " ";
            for(int val: arr[i])
                cout << val << " ";
            cout << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 2688
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
#define sq(x) ((x) * (x))

const int mxn = 501;
int n;
int a[sq(mxn)];
pi p[mxn];

void die(){
	cout << "No" << endl;
	exit(0);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	
	memset(a, -1, sizeof(a));
	for(int i = 0; i < n; i++){
		cin >> p[i].f;
		a[--p[i].f] = p[i].s = i;
	}
	
	sort(p, p + n);
	
	int x = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < p[i].s; j++){
			while(~a[x]) x++;
			a[x] = p[i].s;
		} 
		if(x > p[i].f) die();
	}
	
	for(int i = 0; i < n; i++){
		while(~a[x]) x++;
		if(x < p[i].f) die();
		for(int j = 0; j < n - p[i].s - 1; j++){
			while(~a[x]) x++;
			a[x] = p[i].s;
		}
	}
	
	cout << "Yes" << endl;
	cout << a[0] + 1;
	for(int i = 1; i < sq(n); i++) cout << " " << a[i] + 1;
	cout << endl;

	return 0;
}

Measured memory_bytes: 4624
while true
  n = gets.to_i
  break if n==0

  a = Array.new(n){gets.to_i}
  
  max = a.max

  if n>1
    for k in 2..n
      ksum = a[0..k-1].inject(:+)
      max = ksum if ksum>max
      for l in 0..n-k-1
        ksum += a[k+l]-a[l]
        max = ksum if ksum>max
      end
    end
  end
  
  puts max
end

Measured memory_bytes: 8760
/* Akshat Sharma @akshat98 */
#include <iostream>
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp   make_pair
#define pb   push_back
#define F    first
#define S    second
#define ll   long long
#define MOD  1000000007
#define MAX  1000000001
#define vi 	 vector<int>
#define vl   vector<ll>
#define vpi  vector<pair<int,int> >
#define vpl  vector<pair<ll,ll> >
#define rep(i,a,b) for(i=a;i<b;i++)
#define reqp(i,a,b) for(i=a;i<=b;i++)
#define ren for(i=0;i<n;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;
vi vec[100005];
bool vis[100005]={0};

void dfs(int ind){
	for(auto it:vec[ind]){
		if(!vis[it]){
			vis[it]=1;
			dfs(it);
		}
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	//freopen("input_file.txt", "r", stdin);
	//freopen("output_file.txt", "w", stdout);
	#endif
	int i,j,k,l,n,test_case,m,r;
	test_case=1;
	//cin>>test_case;
	while(test_case--){
		cin>>n>>m;
		
		// memset(vis,0,sizeof vis);
		vi x(m),y(m),z(m);
		rep(i,0,m){
			cin>>x[i]>>y[i]>>z[i];
			x[i]--;
			y[i]--;
			vec[x[i]].pb(y[i]);
			vec[y[i]].pb(x[i]);
		}
		int cnt=0;
		rep(i,0,n){
			if(vis[i]==0){
				cnt++;
				dfs(i);
			}
		}
		cout<<cnt;



	}
	
	return 0;
}

Measured memory_bytes: 10112
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	int a,b;
	cin >> a >> b;
	cout << (a+b)%24;
}

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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(long.Parse).ToList();
            a.Sort();

            long ans = 0;
            for(int i = 0; i < n - 1; i++)
            {
                ans += a[n - (i + 3) / 2];
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 47708
#!/usr/bin/env python3
import sys
import numpy as np


def solve(S: int, W: int):
    if W>=S:
        print('unsafe')
    else:
        print('safe')
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(S, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27128
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int k; cin >> k;
	char t = s.at(0);
	bool flag2 = false;
	rep(i, s.size()) {
		if (t != s.at(i))flag2 = true;
	}
	if (!flag2 && s.size() % 2 != 0) {
		int a = s.size();
		int b = (a / 2+1) * (k / 2) + (a/2)*(k - k/2);
		cout << b << endl;
		return 0;
	}
	int cnt = 0;
	int cnt2 = 0;
	rep(i, s.size() -1) {
		if (s.at(i) == s.at(i + 1)) {
			cnt++; i++;
		}
	}
	string tmp = s + s;
	rep(i, tmp.size() - 1) {
		if (tmp.at(i) == tmp.at(i + 1)) {
			cnt2++; i++;
		}
	}
	int ans = cnt2 - cnt;
	ans = cnt + ans * (k - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
string s, t;
vector < int > count_bal(string& s) {
    vector < int > f(s.size() + 1);
    for (int i = 0; i < s.size(); i++) {
        f[i + 1] = f[i];
        if (s[i] == 'A') f[i + 1]++;
        else f[i + 1]--;
    }
    return f;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    string s, t;
    cin >> s >> t;
    auto fs = count_bal(s);
    auto ft = count_bal(t);
    int q;
    cin >> q;
    while (q--) {
        int a1, b1, c1, d1;
        cin >> a1 >> b1 >> c1 >> d1;
        int r = (fs[b1] - fs[a1 - 1]) % 3;
        int u = (ft[d1] - ft[c1 - 1]) % 3;
        if (r < 0) r += 3;
        if (u < 0) u += 3;
        if (u == r) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 1744
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args)throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try{
      String[] S = br.readLine().split(" ");
      int X = Integer.parseInt(S[0]);
      int Y = Integer.parseInt(S[1]);
      int Z = X+Y;
      int A = Integer.parseInt(S[2]);
      int B = Integer.parseInt(S[3]);
      int C = Integer.parseInt(S[4]);
      
      int[] red = new int[A];
      int[] green = new int[B];
      
      S = br.readLine().split(" ");
      for(int i = 0; i < A; i++){
          red[i] = Integer.parseInt(S[i]);
      }
      
      S = br.readLine().split(" ");
      for(int i = 0; i < B; i++){
          green[i] = Integer.parseInt(S[i]);
      }
      
      ArrayList<Integer> list = new ArrayList<>();
      S = br.readLine().split(" ");
      for(int i = 0; i < C; i++){
          list.add(Integer.parseInt(S[i]));
      }
      
      Arrays.sort(red);
      Arrays.sort(green);
      
      for(int i = 0; i < X; i++){
          list.add(red[A-i-1]);
      }
      for(int i = 0; i < Y; i++){
          list.add(green[B-i-1]);
      }
      Collections.sort(list);
      
      long ans = 0;
      for(int i = 0; i < Z; i++){
        ans += list.get(C+Z-i-1);
      }
      System.out.println(ans);
    }catch(Exception e){
    }
  }
}


Measured memory_bytes: 68712
n,m = map(int,input().split())
balls = [1]*n #i番目の箱に入っているボールの数
red = [1] +[0]*(n-1) #i番目の箱に赤いボールが入っている可能性があるか否か
for i in range(m):
    x,y = map(int,input().split())
    x -= 1
    y -= 1 #0-indexedに直す
    if red[x] :red[y] = 1
    balls[x] -= 1
    balls[y] += 1
    if balls[x] == 0:
        red[x] = 0
print(sum(red))

Measured memory_bytes: 47092
import Data.List

main = interact $ show' . solve . read' . lines
  where
    solve = addCol . addRow
    addCol xs = map appendSum xs
    addRow = transpose . addCol . transpose
    appendSum row = row ++ [sum row]
    show' = unlines . map (unwords . map show)
    read' = map (map read . words) . tail :: [String] -> [[Int]]



Measured memory_bytes: 7536
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int INF = 100000000;

int main(){
	//freopen("test.txt", "r", stdin);
	while(1){
		int n, m;
		cin >> n >> m;
		if(!n && !m) break;
		vector<int> h(n);
		vector<int> hc;
		rep(i, n){
			cin >> h[i];
		}
		for(int i = 0; i < n; i++){
			int hsum = 0;
			for(int j = i; j < n; j++){
				hsum += h[j];
				hc.push_back(hsum);
			}
		}
		vector<int> w(m);
		vector<int> wc;
		rep(i, m){
			cin >> w[i];
		}
		for(int i = 0; i < m; i++){
			int wsum = 0;
			for(int j = i; j < m; j++){
				wsum += w[j];
				wc.push_back(wsum);
			}
		}

		sort(all(hc));
		sort(all(wc));

		int cnt = 0;
		rep(i, hc.size()){
			cnt += (upper_bound(all(wc), hc[i]) - lower_bound(all(wc), hc[i]));
		}

		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 23904
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] v = new int[n];
    int[] e = new int[100001];
    int[] o = new int[100001];
    for (int i = 0; i < n; i++) {
      v[i] = sc.nextInt();
      if (i % 2 == 0) {
        e[v[i]]++;
      } else {
        o[v[i]]++;
      }
    }
    int e1 = 0;
    int e2 = 0;
    int o1 = 0;
    int o2 = 0;
    for (int i = 1; i <= 100000; i++) {
      if (e[i] > e[e1]) {
        e1 = i;
      }
      if (o[i] > o[o1]) {
        o1 = i;
      }
    }
    for (int i = 1; i <= 100000; i++) {
      if (e[e1] >= e[i] && e[i] > e[e2] && e1 != i) {
        e2 = i;
      }
      if (o[o1] >= o[i] && o[i] > o[o2] && o1 != i) {
        o2 = i;
      }
    }
    if (e1 != o1) {
      int ans = 0;
      for (int i = 0; i < n; i++) {
        if (i % 2 == 0 && v[i] != e1) {
          ans++;
        }
        if (i % 2 == 1 && v[i] != o1) {
          ans++;
        }
      }
      System.out.println(ans);
    } else {
      int ans1 = 0;
      for (int i = 0; i < n; i++) {
        if (i % 2 == 0 && v[i] != e1) {
          ans1++;
        }
        if (i % 2 == 1 && v[i] != o2) {
          ans1++;
        }
      }
      int ans2 = 0;
      for (int i = 0; i < n; i++) {
        if (i % 2 == 0 && v[i] != e2) {
          ans2++;
        }
        if (i % 2 == 1 && v[i] != o1) {
          ans2++;
        }
      }
      System.out.println(Math.min(ans1, ans2));
    }
  }
}

Measured memory_bytes: 61512
#include <iostream>
#include <string>
#include <algorithm>
  
using namespace std;
  
int main()
{
    int n, k;
    cin >> n >> k;
    int h [n];
    long long int total = 0;
    
    for (int i = 0; i < n; i++){
        int z;
        cin >> z;
        h[i] = z;
    }
    
    sort(h, h+n);
    
    for (int i = 0 ; i < n-k; i++){
        total += h[i];
    }
    
    string s = to_string(total);
    
    cout << s << endl;
} 


Measured memory_bytes: 1024
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

n=int(input())
d={}
res=[[0,0] for _ in range(n)]
for i in range(n):
    a=float(input())
    b=round(a*pow(10,9))
    x=0
    y=0
    f=True
    while f:
        f=False
        if b%2==0:
            x+=1
            b=b//2
            f=True
        if b%5==0:
            y+=1
            b=b//5
            f=True
    if x*100+y not in d:
        d[x*100+y]=1
    else:
        d[x*100+y]+=1
    res[i]=[x,y]
ans=0
for i in range(n):
    x,y=res[i]
    for j in d:
        xc=j//100
        yc=j%100
        if xc+x>=18 and yc+y>=18:
            if xc==x and yc==y:
              ans+=d[j]-1
            else:
              ans+=d[j]
print(ans//2)


Measured memory_bytes: 115244
n = gets.to_i
points = []
n.times do
  points << gets.chomp.split.map(&:to_i)
end

time = 0
pos_x = 0
pos_y = 0
dic = true
n.times do |i|
  dt = points[i][0] - time
  dist = (points[i][1] - pos_x) + (points[i][2] - pos_y)

  if dist > dt
    dic = false
    break
  elsif dist % 2 != dt % 2
    dic = false
    break
  end

  time = points[i][0]
  pos_x = points[i][1]
  pos_y = points[i][2]
end

puts dic ? "Yes" : "No"

Measured memory_bytes: 9468
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	string s;
	int k;
	cin >> k >> s;
	int n = s.size();
	if (n <= k)
		cout << s;
	else {
		for (int i = 0; i < k; i++)
			cout << s[i];
		cout << "...";
	}
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 3656