akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n;
  cin>>n;
  ll h[n+1];
  for(ll i=1;i<=n;i++)
  {
    cin>>h[i];
  }
  ll ans[n+1];
  ans[0] = 0;
  ans[1] = 0;
  ans[2] = abs(h[2]-h[1]);
  for(ll i=3;i<=n;i++)
  {
    ll a1 = ans[i-1]+abs(h[i]-h[i-1]);
    ll a2 = ans[i-2]+abs(h[i]-h[i-2]);
    ans[i] = min(a1,a2);
  }
  cout<<ans[n];
  return 0;
}

Measured memory_bytes: 1792
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
    
n,k=map(int,input().split())

l=[0]*n

for i in range(k):
	a=input()
	li=list(map(int,input().split()))
	for j in li:
		l[j-1]+=1
		
print(l.count(0))


Measured memory_bytes: 67508
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(); it!=c.end(); ++it)

void solveAndOutput(vector<pair<char, int> > list){
	int max = -1;
	char ansShopName = 'F';
	FOR(i, 0, list.size()){
		if (max < list[i].second){
			max = list[i].second;
			ansShopName = list[i].first;
		}
	}
	cout << (char)ansShopName << " " << max << endl;
}

int main(){
	int s1, s2, count = 0;
	char shopName = 'A';
	vector<pair<char, int> > list;
	fastIO;
	// s1&&s2ではWrongAnswerだった.販売個数に0が含まれているのでは...？
	while (cin >> s1 >> s2, s1||s2){
		list.push_back(MP(shopName + count, s1 + s2));
		count++;
		if (count == 5){
			solveAndOutput(list);

			list.clear();
			count = 0;
			shopName = 'A';
		}
	}
	return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);


int g[15][15];
bool flag[1050000];
const int INF = 1001001001;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int main() {
	ll a, b;
	cin >> a >> b;
	ll g = gcd(a, b);
	auto f = factorize(g);
	int ans = f.size() + 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
MOD = 10**9 + 7

FAC = [1]
INV = [1]
for i in range(1,N+1):
  FAC.append((FAC[i-1]*i) % MOD)
  INV.append(pow(FAC[-1],MOD-2,MOD))
def nCr(n,r):
  return FAC[n]*INV[n-r]*INV[r]

if N == 1:
  print(0)
  exit()
ans = 0
for i in range(N):
  if i >= K-1:
    ans += nCr(i,K-1)*A[i]
    ans %= MOD
  if N-i-1 >= K-1:
    ans -= nCr(N-i-1,K-1)*A[i]
    ans %= MOD
print(ans)

Measured memory_bytes: 71336
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

ll dp[111111];
vector<ii> adj[111111];

void dfs(int u, int p)
{
	for(int i=0;i<adj[u].size();i++)
	{
		int v=adj[u][i].fi; int w=adj[u][i].se;
		if(v==p) continue;
		dp[v]=dp[u]+w;
		dfs(v,u);
	}
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int u,v,w; cin>>u>>v>>w;
		u--; v--;
		adj[u].pb(mp(v,w));
		adj[v].pb(mp(u,w));
	}
	int q,rt; cin>>q>>rt; rt--;
	dfs(rt,-1);
	while(q--)
	{
		int u,v; cin>>u>>v; u--; v--;
		cout<<dp[u]+dp[v]<<'\n';
	}
}


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

using namespace std;
int a;
int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);cout.tie(0);
	for(int i=1;i<=5;i++){
		cin>>a;
		if(a!=i){
			cout<<i<<endl;
		}
	}
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n, s = 0;
	cin >> n;
	int tmp = n;
	while (tmp > 0) {
		s += tmp % 10;
		tmp /= 10;
	}
	if (n%s == 0) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
L, R = map(int, input().split())
ans = 20200000000

L_quo = int((L - L % 2019) / 2019)
R_quo = int((R - R % 2019) / 2019)

if L_quo != R_quo:
    print(0)
else:
    L_rem = L % 2019
    R_rem = R % 2019
    for i in range(L_rem, R_rem):
        for j in range(i + 1, R_rem + 1):
            a = (i * j) % 2019
            ans = min(ans, a)
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    int x;
    cin >> x;
    int dis=x/15;
    cout << x*800-dis*200 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(1,0); }
	V<V<pin>> qab(2);
  qab[0].reserve(10000);
  qab[1].reserve(10000);
	for (pin x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2,x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2,(x.second + 1) / 2)); }
	}
	V<vel> c(2, vel(2));
	rep(i, 2) {
		for (pin x : qab[i]) {
			int qc = (2 * x.first + x.second) % 3;
			if ((qc+1)%2) { c[i][0] ^= 1; }
			if (qc) { c[i][1] ^= 1; }
		}
	}
	rep(i, 2) {
		if (!c[1 - i][0]&&!c[1-i][1]) {
			pin ans = solve(qab[i], ex - 1);
			ans.first *= 2; ans.second *= 2; ans.second += i;
			return ans;
		}
	}
	for(pin &v:ab) { v.first++; }
	pin ans = solve(ab, ex); ans.first--;
	return ans;
}
signed main() {
	long long inf = 2e17;
	int n; scanf("%lld", &n);
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; scanf("%lld", &a); scanf("%lld", &b);
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 70);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}

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


int main() {
  int n, result=0;
  cin>>n;
  for (int i=1; i<=n; i++){
      for(int j=1; j<=n; j++){
          for(int k=1; k<=n; k++){
              result++;
          }
          
      }
  }
    cout<<result<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     int a,b,c,d,e,f,g,h,i,j;
     cin>>a;
     int ar[a];
     vector<int>v;
     int k=0;

     for(i=0;i<a;i++)
     {
         cin>>ar[i];
         if(ar[i]%2==0)
         {
             v.push_back(ar[i]);
             k=1;
         }
     }
     if(k==0)
     {
         cout<<"0"<<endl;
     }
     else{
     int  ans=0;
     c=0;

     for(i=0;i<v.size();i++)
     {
         d=0;
         while(v[i]!=0)
         {
             if(v[i]%2==0)
             {
                 v[i]/=2;
                 d++;
             }
             else{break;}
         }
         ans+=d;


     }
     cout<<ans<<endl;
     }
 }


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
 
int main(){
  //入力
  int a,b,c,d,e;
  int k;
  cin >> a >> b >> c >> d >> e;
  cin >> k;
  
  //処理
  string ans;
  int L = e-a;
  if(L<=k) ans = "Yay!";
  else ans = ":(";
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n, Y = map(int,input().split())
x , y , z = '-1' , '-1' , '-1'

def check(num,total):
  for i in range(num+1):
    for j in range(num+1):
      k = num - i - j
      if (k >= 0) and (i + j + k == num) and (10000 * i + 5000 * j + 1000 * k == total):
        x , y , z = str(i) , str(j) , str(k)
        return x + ' ' + y + ' ' + z
res = check(n,Y)
if res is None:
  res = x + ' ' + y + ' ' + z
print(res)

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    int T=1;
    //cin >> T;
    while(T--){
        ll h,w,k;
        string s;
        cin>>h>>w>>k;
        int a[h][w];
        rep(i,h){
            cin>>s;
            rep(j,w) a[i][j]=s[j]-'0';
        }
        vi v,z,tmp;
        ll cut, mn=mod, f,f1;
        rep(i,1<<(h-1)){
            f=1;
            v.pb(0);
            rep(j,h-1){
                if(1&(i>>j)) v.pb(j+1);
            }
            v.pb(h);
            // rep(i,v.size()) cout<<v[i];
            // cout<<el;
            cut=v.size()-2;
            //cout<<cut<<el;
            z.assign(v.size()-1,0);
            tmp.assign(v.size()-1,0);
            rep(j,w){
                f1=0;
                rep_a(g,1,v.size()){
                    tmp[g-1]=0;
                    rep_a(l,v[g-1], v[g]){
                        tmp[g-1]+=a[l][j];
                    }
                    //cout<<tmp<<el;
                    if(tmp[g-1]>k){
                        f=0;
                        break;
                    }
                }
                rep(g,tmp.size()){
                    if(z[g]+tmp[g]>k){
                        f1=1;
                        break;
                    }
                }
                rep(g,tmp.size()){
                    if(f1) z[g]=tmp[g];
                    else z[g]+=tmp[g];
                }
                if(!f) break;
                if(f1) cut++;
            }
            if(f)mn=min(mn,cut);
            v.clear();
            z.clear();

        }
        cout<<mn<<el;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;


int main(){
    int n; cin >> n;
    string s1, s2; cin >> s1 >> s2;
    string ar = "";
    REP(i, n){
        if(s1[i] == s2[i]) ar += 'p';
        else{
            ar += 't'; ++i;
        }
    }
    ll cnt = 1;
    int prv = 0; //1ならp(縦) 2ならt(横)
    REP(i, ar.length()){
         if(!prv){
             if(ar[i] == 'p'){
                 cnt = 3; prv = 1;
             }else{
                 cnt = 6; prv = 2;
             }
         }
         else if(prv == 1){
             if(ar[i] == 'p'){
                cnt = cnt * 2 % MOD; prv = 1;
             }else{
                cnt = cnt * 2 % MOD; prv = 2;
             }
         }else{
             if(ar[i] == 'p'){
                 prv = 1;
             }else{
                 cnt = cnt * 3 % MOD; prv = 2;
             }
         }
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    all_cost = abs(0 - A[0])
    for i in range(N-1):
        all_cost += abs(A[i] - A[i+1])
    all_cost += abs(A[N-1] - 0)
    for i in range(N):
        buf = 0
        if i == 0:
            if (A[0] > 0 and A[0] < A[1]) or (A[0] < 0 and A[0] > A[1]):
                buf = 0
            elif (A[0] > 0 and A[0] > A[1]) or (A[0] < 0 and A[0] < A[1]):
                buf += abs(0 - A[0])
                buf += abs(A[0] - A[1])
                buf -= abs(0 - A[1])
        elif i == N-1:
            if (0 < A[N-1] < A[N-2]) or (0 > A[N-1] > A[N-2]):
                buf = 0
            else:
                buf += abs(0 - A[N-1])
                buf += abs(A[N-2] - A[N-1])
                buf -= abs(0 - A[N-2])
        else:
            if (A[i-1] < A[i] < A[i+1]) or (A[i-1] > A[i] > A[i+1]):
                buf = 0
            else:
                buf += abs(A[i-1] - A[i])
                buf += abs(A[i] - A[i+1])
                buf -= abs(A[i-1] - A[i+1])
        print(all_cost - buf)

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

int main() {
  int N,Ans=0;
  cin>>N;
  vector<int> vec(N);
  rep(i,N){cin>>vec.at(i);}
  sort(vec.begin(),vec.end());
  for (int i = 0; i < N-2; i++){
    for (int j = i+1; j < N-1; j++){
      for (int k = j+1; k < N; k++){if(vec.at(i)+vec.at(j)>vec.at(k)){Ans++;}
                                   }
    }
  }
  cout<<Ans<<endl;
}

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

int main(){
  int N,sum=0;
  cin>>N;
  vector<int> A(N),B(N);
  vector<int> C(N-1);
  for(int i=0; i<N; i++){
    cin>>A.at(i);
  }
  for(int i=0; i<N; i++){
    cin>>B.at(i);
    sum+=B.at(i);
  }
  for(int i=0; i<N-1; i++){
    cin>>C.at(i);
  }
  for(int i=0; i<N-1; i++){
    for(int j=0; j<N-1; j++){
      if(A.at(i)==j+1&&A.at(i+1)==j+2){
        sum+=C.at(j);
      }
    }
  }
  cout<<sum<<endl;
}
  

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define ll long long
#define inf 0x3f3f3f3f

using namespace std;

int a,b,c,d;

int main(){
    scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
    if(a==b||b==c||c==d)puts("Bad");
    else puts("Good");
}


Measured memory_bytes: 256
S = [input() for _ in range(3)]

ia, ib, ic = 1, 0, 0
for i in range(3):
    S[i] = S[i] + 'f'
s = S[0][0]

while True:
    if s == 'a':
        s = S[0][ia]
        ia += 1
        if s == 'f':
            print('A')
            break
    elif s == 'b':
        s = S[1][ib]
        ib += 1
        if s == 'f':
            print('B')
            break
    else:
        s = S[2][ic]
        ic += 1
        if s == 'f':
            print('C')
            break

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

#define pb push_back
#define mp make_pair
#define ld long double
#define ll long long int
#define f(i,g,n) for(int i=g;i<=n;i++)
#define rf(i,g,n) for(int i=n;i>=g;i--)

const int N=1;

bool compare(int a,int b)
{
	return a>b;
}

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


	ld a,b,x,res,vol;
	cin>>a>>b>>x;
	vol = a*a*b;
	if((vol/2) == x)
		cout<<"45.0000000000\n";
	else if((vol/2) < x)
	{
		ld temp = (vol-x)*2;
		temp /= a*a;
		cout<<setprecision(30)<<atan(temp/a)*180/M_PI;
	}
	else
	{
		ld temp = (2*x)/(a*b);
		cout<<setprecision(30)<<atan(b/temp)*180/M_PI;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, a, s, mn=999;
int main() {
	cin>>n;
	for(int i=0; i<n; i++) {
		cin>>a;
		s += a;
		if(a<mn && a%10) mn = a;
	}
	cout<<(s%10 ? s : mn<999 ? s-mn : 0);
	return 0;
}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()
	p := make([]int, n)
	for i := range p {
		p[i] = readInt() - 1
	}

	var ans int
	for i := 0; i < n-1; i++ {
		if p[i] == i {
			p[i], p[i+1] = p[i+1], p[i]
			ans++
		}
	}
	if p[len(p)-1] == len(p)-1 {
		ans++
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 1920
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
inline double sq(double a) { return a*a; }

int bitcount(int b) { int c = 0; while(b) { b &= b-1; c++; } return c; }

int n, x[64], y[64], r[64], c[64], g[64];
bool vis[1<<24];

int solve() {
    memset(vis, 0, sizeof(vis));
    memset(g, 0, sizeof(g));
    rep(i, n) for(int j=i+1; j<n; j++) {
        if(sqrt(sq(x[i]-x[j])+sq(y[i]-y[j]))<r[i]+r[j]) g[i] |= 1<<j;
    }
    int ans = 0;
    queue<int> q;
    q.push(0);
    vis[0] = true;
    while(!q.empty()) {
        int x = q.front();
        q.pop();
        ans = max(ans, bitcount(x));
        int can = ~x;
        rep(i, n) if((x&(1<<i))==0) can &= ~g[i];
        rep(i, n) if(can&(1<<i)) rep(j, i) if(can&(1<<j) && c[i]==c[j]) {
            const int nx = x|(1<<i)|(1<<j);
            if(!vis[nx]) q.push(nx), vis[nx] = true;
        }
    }
    return ans;
}

int main() {
    for(;;) {
        scanf("%d", &n);
        if(n==0) return 0;
        rep(i, n) scanf("%d%d%d%d", x+i, y+i, r+i, c+i);
        printf("%d\n", solve());
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint a, b, c, k;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a >> b >> c >> k;
	
	llint ans = 0;
	while(a >= b){
		b *= 2;
		ans++;
	}
	while(b >= c){
		c *= 2;
		ans++;
	}
	if(ans <= k) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 3684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int[] arr= new int[n];
		for(int i=0;i<n;i++){
			arr[i]=Integer.valueOf(sc.next());
		}
		sc.close();
		
		int count=0;
		boolean f=true;
		while(f){
			f=false;
			for(int i=n-1;i>0;i--){
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			}
			
		}
		System.out.print(arr[0]);
		for(int i=1;i<n;i++){
			System.out.print(" "+arr[i]);
		}
		System.out.println();
		System.out.println(count);
	}

}

Measured memory_bytes: 26224
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main()
{
    int64_t n, m;
    cin >> n >> m;

    vector<int64_t> as(n, 0);
    for (auto& a : as)
    {
        cin >> a;
    }
    as[0] %= m;
    for (int i = 1; i < n; i++)
    {
        as[i] += as[i - 1];
        as[i] %= m;
    }
    map<int64_t, int64_t> counts;
    counts[0]++;
    for (auto& a : as)
    {
        counts[a]++;
    }
    int64_t ans = 0;
    for (auto c : counts)
    {
        ans += c.second * (c.second - 1) / 2;
    }
    cout << ans << endl;
}

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

int main() {
	int n, a;
	vector<int>v;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		v.push_back(a);
	}
	sort(v.rbegin(), v.rend());
	int alice = 0, bob = 0;
	for (int i = 0; i < v.size(); i++) {
		if (i % 2 == 0)alice += v[i];
		else bob += v[i];
	}
	cout << alice - bob << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main{
        public static void main(String args[]){
                try(Scanner sc = new Scanner(System.in)){
                        int a = (new BigInteger(sc.next())).compareTo(new BigInteger(sc.next()));
                        if(a == 0){
                                System.out.println("EQUAL");
                        } else if(a==1){
                                System.out.println("GREATER");
                        } else {
                                System.out.println("LESS");
                        }
                }
        }
}


Measured memory_bytes: 21844
/*
   THE DARK NIGHT RISES
I LOVE YOU 72 AND WILL FOREVER DO SO
Patience, Persistence, Perseverance, Passion, Purpose
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int N = 2e5 + 20 ;
#define F first
#define S second
# define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mk make_pair
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x)       (int)x.size()
const long long int mod=1e9 + 7;
const long double EPS=1e-12;
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )
 
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
bool comp(pair<ll,ll> v1 ,pair<ll,ll> v2 )
{
 
}
bool vis[10] ;
 
int solve()
{
 	ll a, b ,c ;
 	cin >> a >> b ;
	
	vis[a] = true , vis[b] = true ;
	for(int i = 1 ; i < 4 ; i++)
	if(!vis[i]) return cout << i , 0 ;	
}
int main()
{
	fast;
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
 
	return 0;
}
// Patience, Persistence, Perseverance, Passion, Purpose
// I LOVE YOU 72 AND WILL FOREVER DO SO.

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){

	int now = 60 * 60 * 2;
	int hour,minute,second;
	while(cin>>hour){
		now = 60 * 60 * 2;
		cin>>minute;
		cin>>second;
		if(hour==-1 && minute == -1 && second == -1)break;
		now -= (hour * 60 * 60 + minute * 60 + second);
		hour = now / (60*60);
		now %= (60 * 60);
		minute = now / 60,now%=60;
		second = now;
		printf("%02d:%02d:%02d\n",hour,minute,second);
		hour*=3,minute*=3,second*=3;
		while(second>=60){
			minute++;
			second-=60;
		}
		while(minute>=60){
			hour++;
			minute-=60;
		}
		printf("%02d:%02d:%02d\n",hour,minute,second);
	}

}

/*
Sample Input
1 30 0
-1 -1 -1
Output for the Sample Input
00:30:00
01:30:00
*/

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
const int inf=INT_MAX;
#define mod 1e9+7
#define PI acos(-1)
#define INF 0x3f3f3f
#define ll long long
#define pb push_back
#define C(a) cout<<a<<endl;
#define CY cout<<"YES"<<endl;
#define CN cout<<"NO"<<endl;
#define Cy cout<<"Yes"<<endl;
#define Cn cout<<"No"<<endl;
#define ull unsigned long long
#define ffr(a) for(int i=0;i<a;i++)
#define frr(a) for(int i=1-1;i>=0;i--)
#define me(a) memset(a,0,sizeof(a));
#define my(a,b) memcpy(a,b,sizeof(b));
#define cio ios::sync_with_stdio(false);
ll gcd(ll a,ll b){return (a%b==0) ? b : gcd(b,a%b);}
int main()
{
   	int a,b;
   	cin>>a>>b;
   	C(a*b);
    return 0;
}

Measured memory_bytes: 3636
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define rep(i,n) for (int i=0; i < int(n); i++)


// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};
int main() {
    ll n,m;
    cin >> n>>m;
    pair<ll,ll> ab[100010];
    rep(i,m){
        ll ta,tb;
        cin>>ta>>tb;
        ta--;
        tb--;
        ab[i] = {ta,tb};
    }
    vector<ll> result;
    UnionFind uf(n);
    ll ans = n*(n-1)/2;
    rep(i,m){
        int nowi = m-1-i;
        int x = ab[nowi].first;
        int y = ab[nowi].second;
        if( uf.same(x,y) ){
            result.push_back(ans);
        }else{
            result.push_back(ans);
            ans -= uf.size(uf.find(x))*uf.size(uf.find(y));
            uf.unite(x,y);
        }
    }

    rep(i,m){
        int nowi = m-1-i;
        cout<<result[nowi]<<endl;
    }
}

Measured memory_bytes: 4596
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
const int N = 3000;
ll a[N], f[N][N];
int n, x;
int main() {
	ios :: sync_with_stdio(false);
	cin >> n >> x;
	for(int i = 1; i <= n; i ++ ) cin >> a[i], f[i][0] = a[i];
	for(int i = 1; i <= n; i ++ ) {
		for(int j = 1; j <= n; j ++ ) {
			int cur = i - j;
			if(cur <= 0) cur = n + cur;
			f[i][j] = min(f[i][j-1], a[cur]);
		}
	}
	ll ans = 1e15, now = 0;
	for(int i = 0; i < n; i ++ ) {
		now = 0;
		for(int j = 1; j <= n; j ++ ) {
			now += f[j][i];
		}
		ans = min(ans, now + (ll)x*i);
	}
	cout << ans ;
}


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

class B
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var es = new int[n - 1].Select(_ => Read()).ToArray();

		Console.WriteLine(string.Join("\n", Heights(n - 1, 0, es)));
	}

	static long[] Heights(int n, int sv, int[][] es)
	{
		var map = Array.ConvertAll(new int[n + 1], _ => new List<int[]>());
		foreach (var e in es)
		{
			map[e[0]].Add(new[] { e[1], e[2] });
			map[e[1]].Add(new[] { e[0], e[2] });
		}

		var d = Distances(n, sv, map);
		var ev1 = Enumerable.Range(0, n + 1).OrderBy(v => -d[v]).First();
		var d1 = Distances(n, ev1, map);
		var ev2 = Enumerable.Range(0, n + 1).OrderBy(v => -d1[v]).First();
		var d2 = Distances(n, ev2, map);
		return d1.Zip(d2, Math.Max).ToArray();
	}

	static long[] Distances(int n, int sv, List<int[]>[] map)
	{
		var from = new int[n + 1];
		var d = new long[n + 1];
		var q = new Queue<int>();
		from[sv] = -1;
		q.Enqueue(sv);

		while (q.Count > 0)
		{
			var v = q.Dequeue();
			foreach (var e in map[v])
			{
				if (e[0] == from[v]) continue;
				from[e[0]] = v;
				d[e[0]] = d[v] + e[1];
				q.Enqueue(e[0]);
			}
		}
		return d;
	}
}



Measured memory_bytes: 27972
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

tmp_A = [0]*N
for i, x in enumerate(A):
	if i%2 == 0:
		tmp_A[i] = x
	else:
		tmp_A[i] = -x
x = sum(tmp_A)/2

tmp = x
ans = []
for i in range(N):
	print(int(tmp*2), end=" ")
	tmp = A[i]-tmp
print()


Measured memory_bytes: 16196
import sys
N,M = map(int,input().split())
if N >= M:
    print(0)
    sys.exit()
    
lc = list(map(int,input().split()))
lc.sort()
#print(lc)

diff = []
for i in range(M-1):
    diff.append(lc[i+1]-lc[i])
    
#print(diff)
diff.sort()
diff_min = diff[:M-N]
print(sum(diff_min))

Measured memory_bytes: 20628
#include <iostream>
#include <algorithm>

using namespace std;
int main(void) {
    int a[3];
    int K;
    cin >> a[0] >> a[1] >> a[2];
    cin >> K;
    sort(a, a+3);

    for(int i = 0; i < K; i++) {
        a[2] *= 2;
    }

    cout << a[0] + a[1] + a[2];

    return 0;
}

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


int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	if(S.substr(0,N/2) == S.substr(N/2)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}












Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int N;
    vector< int > v;
    double sum;

    cin >> N;
    int temp;
    rep (i, N)
    {
        cin >> temp;
        v.push_back(temp);
    }

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

    sum = (double)(v[0] + v[1]) / (double)2.0;
    for (int i = 2; i < N; ++i)
    {
        sum = (sum + (double)v[i]) / (double)2.0;
    }

    cout << sum << "\n";

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
 
        Scanner sc = new Scanner(System.in);
     
        int A = sc.nextInt(); 
        int B = sc.nextInt(); 
        int K = sc.nextInt();
     
        if(2 * K  <= B - A  ){
          for(int i = 0 ; i < K ; i ++ ){
            System.out.println(A + i);
          }
          for(int i = K - 1 ; i >= 0  ; i -- ){
            System.out.println(B - i);
          }
        } else {
          for(int i = 0 ; i < B - A + 1;i ++ ){
            System.out.println(A + i);
          }
        }
      }
}

Measured memory_bytes: 22996
N = int(input())
S = [None] * N
for i in range(N):
    S[i] = input()
nums = [None] * N
for i, s in enumerate(S):
    tmp = [0] * 26
    for c in s:
        tmp[ord(c)-97] += 1
    nums[i] = ' '.join(map(str, tmp))

ans = 0
checker = dict()

for s in reversed(nums):
    #print(s)
    if s in checker:
        ans += checker[s]
        checker[s] += 1
    else:
        checker[s] = 1
print(ans)

Measured memory_bytes: 92384
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct { int parent, left, right;} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL)
    h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL)
    h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
  if( T[u].parent == NIL ) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left  != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
  
  if(T[u].parent == NIL) {
    printf("root\n");
  } else if(T[u].left == NIL && T[u].right == NIL) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

int main(void) {
  int v, l, r, root = 0;
  scanf("%d",&n);
  for(int i=0;i<n;i++) T[i].parent = NIL;
  for(int i=0;i<n;i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].left  = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }
  
  for(int i=0; i<n; i++)
  if(T[i].parent == NIL) root = i;
  
  setDepth(root,0);
  setHeight(root);
  
  for(int i=0;i<n;i++) print(i);
  
  return 0;
}


Measured memory_bytes: 2048
class SegmentTree():
  def __init__(self, n, oper, e):
    self.n = n
    self.oper = oper
    self.e = e
    self.log = (n - 1).bit_length()
    self.size = 1 << self.log
    self.data = [e] * (2 * self.size)

  def update(self, k):
    self.data[k] = self.oper(self.data[2 * k], self.data[2 * k + 1])

  def build(self, arr):
    #assert len(arr) <= self.n
    for i in range(self.n):
      self.data[self.size + i] = arr[i]
    for i in range(self.size-1,0,-1):
      self.update(i)

  def set(self, p, x):
    #assert 0 <= p < self.n
    p += self.size
    self.data[p] = x
    for i in range(1, self.log + 1):
      self.update(p >> i)

  def get(self, p):
    #assert 0 <= p < self.n
    return self.data[p + self.size]

  def prod(self, l, r):
    #assert 0 <= l <= r <= self.n
    sml = smr = self.e
    l += self.size
    r += self.size
    while l < r:
      if l & 1:
        sml = self.oper(sml, self.data[l])
        l += 1
      if r & 1:
        r -= 1
        smr = self.oper(self.data[r], smr)
      l >>= 1
      r >>= 1
    return self.oper(sml, smr)

  def all_prod(self):
    return self.data[1]


import sys
input = sys.stdin.buffer.readline

N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
maxA = max(A)
st = SegmentTree(maxA+1, max, 0)

for i in range(N):
  mm = st.prod(max(0,A[i]-K),min(maxA,A[i]+K)+1)+1
  st.set(A[i],mm)
ans = st.all_prod()
print(ans)

Measured memory_bytes: 106496
import java.util.*;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
		String b = sc.next();
		int al = a.length();
		int bl = b.length();
		
		for(int i = 0;i<50;i++){
			if(al!=i){
				System.out.print(a.charAt(i));
				}else{
					break;
				}
				if(bl!=i){
				System.out.print(b.charAt(i));
				}else{
					break;
			}
		}
		
	}
}

Measured memory_bytes: 23636
N, K = map(int, input().split())
V = list(map(int, input().split()))

if K <= 2:
    print(max(V[0], V[-1], 0))
    quit()


ans = 0
for a in range(min(N, K)+1):
    for b in range(min(N-a, K-a)+1):
        V_ = sorted(V[:a] + V[-b:]) if b >= 1 else sorted(V[:a])
        tmp = K - (a+b)
        curMinus = 0
        for v in V_:
            if v < 0 and tmp > 0:
                tmp -= 1
                curMinus += -v
        ans = max(ans, sum(V_)+curMinus)

print(ans)

Measured memory_bytes: 3188
#include<stdio.h>
int main(){
  int i,j;
  char a[200];
  long long n,T,st=0,to,sw=0,tall=0,tle=0;
  scanf("%lld %lld",&n,&T);
  scanf("%s",a);
  for(i=0;a[i]!='\0';i++){
    if(a[i]=='n'){
      st=n;
      sw=1;
    }
    if(sw==1){
      if(a[i]=='+'){
	tall+=st;
	st=0;
	sw=0;
      }
      if(a[i]<='9'&&'0'<=a[i]){
	to=1;
	for(j=0;j<a[i]-'0';j++){
	  to*=n;
	  if(to>1000000000){
	    tle++;
	    break;
	  }
	}
	tall+=to;
	to=0;
	sw=0;
	st=0;
      }
    }
  }
  if(st!=0)tall+=st;
  if(tall<=1000000000)  tall*=T;
  else tle++;
  if(tall>1000000000||tle!=0)printf("TLE\n");
  else printf("%lld\n",tall);
  return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
p = read_int()

def solve():
    diff_count = 0
    for i in range(N):
        if p[i] != i + 1:
            diff_count += 1
    if diff_count >= 3:
        return "NO"
    return "YES"

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 3820
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 1e7+7;
const int INF=0x3f3f3f3f;
typedef long long LL;
LL gcd(LL a,LL b){
return b==0?a:gcd(b,a%b);
}

int main(){

LL a,b;
while(scanf("%lld%lld",&a,&b)!=EOF){
    LL g=gcd(a,b);
    LL lcm=a*b/g;
    printf("%lld %lld\n",g,lcm);
}

return 0;
}



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

list = [[] for _ in range(8)]
for i in xyz:
    for j in range(8):
        num = 0
        if j < 4:
            num += i[0]
        else:
            num -= i[0]
        
        if j in [0,1,4,5]:
            num += i[1]
        else:
            num -= i[1]
        
        if j % 2 == 0:
            num += i[2]
        else:
            num -= i[2]
        
        list[j].append(num)

for i in list:
    i.sort(reverse=True)

result = [0] * 8
for i in range(8):
    result[i] = sum(list[i][:m])

print(max(result))

Measured memory_bytes: 3684
#include <cstdio>
#include <vector>
using namespace std;

int solve(){
	int n, t, L;
	scanf("%d%d%*d%d", &n, &t, &L);
	vector<int> ts(n), hs(n);
	for(int i = 0; i < n; ++i){
		scanf("%d%d", &ts[i], &hs[i]);
	}

	int s = 0;
	int k = 0;
	for( ; ; k = (k + 1) % n){
		if(ts[k]){
			++s;
			if(++t > L){ break; }
			--ts[k];
		}
		else if(hs[k]){
			s += 10;
			--hs[k];
		}
		else{ break; }

		if(s >= 9){
			ts[k] += s - 9;
			t -= s - 9;
			s = 0;

			if(t < 0){
				break;
			}
		}
	}
	return k + 1;
}

int main(){
	printf("%d\n", solve());
}

Measured memory_bytes: 1032
import fractions
from functools import reduce
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
 
ip = input().split()
st = int(ip[1])
 
li = []
 
ip2 = input().split()
for i in ip2:
    li.append(abs(int(i) - st))
 
print(gcd_list(li))

Measured memory_bytes: 88300
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let [h,n] = nextIntArray()
    const a = nextIntArray()
    for(let i=0; i<a.length; i++){
        h -= a[i]
    }
    console.log( h<=0 ? "Yes" : "No")

}
Main()


Measured memory_bytes: 37740
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if(A == B && B == C) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
# coding: utf-8
import re
import math
#import numpy as np

mod=int(10**9+7)

#main
a,b=map(int,input().split())
ans=""
min_=min(a,b)
max_=max(a,b)
for i in range(max_):
    ans+=str(min_)
print(ans)

Measured memory_bytes: 38256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    string a; cin>>a;
    ll n=a.size();
    ll ans=n*(n-1)/2;
    vector<ll> cnt(26,0);
   
    for(auto ch : a) cnt[ch-'a']++;
    rep(i,26) ans-=cnt[i]*(cnt[i]-1)/2;
    cout<<ans+1<<endl;
}

Measured memory_bytes: 640
h,w=map(int, input().split())
a=[""]*h
for i in range(h):
  a[i]=input()
row=[False]*h
column=[False]*w
for i in range(h):
  for j in range(w):
    if a[i][j]=="#":
      row[i]=True
      column[j]=True
for i in range(h):
  if row[i]:
    for j in range(w):
      if column[j]:
        print(a[i][j], end = "")
    print()

Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

Int cnt;
Int N;

vector<Int> f(vector<Int> ans) {
    vector<Int> v(N,0);
        rep(i,N) {
            int start, end;
            if (i >= ans[i]) start = i-ans[i];
            else start = 0;
            if (i+ans[i] <= N-1) end = i+ans[i];
            else end = N-1;
            v[start]++;
            if (end < N-1) v[end + 1]--;
        }
    vector<Int> w(N);
    w[0] = v[0];
    if (ans[0] != N && w[0] == N) cnt++;
    rep1(i,N-1) {
        w[i] = w[i-1] + v[i];
        if (ans[i] != N && w[i] == N) cnt++;
    }
    return w;
}

int main(){
    Int K;
    cin >> N >> K;
    if (K > 50) K = 50;
    vector<Int> A(N), ans(N);
    cnt = 0;
    rep(i,N) {
        cin >> A[i];
        ans[i] = A[i];
        if (A[i] == N) cnt++;
    }

    rep(i,K) {
        ans = f(ans);
        if (cnt == N) break;
    }

    if(N > 1) rep(i,N-1) cout << ans[i] << " ";
    cout << ans[N-1] << endl;




}

Measured memory_bytes: 11168
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 21 22:04:00 2020

@author: NEC-PCuser
"""

N = int(input())

a = list(map(int, input().split()))

sum_a = 0

for i in a:
    sum_a ^= i

ans_list = []
for i in a:
    ans_list.append(str(sum_a ^ i))

print(' '.join(ans_list))

Measured memory_bytes: 35020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<ll> v(N+1);
  vector<ll> w(N);
  rep(i,N+1)cin >> v[i];
  rep(i,N) cin >> w[i];
  ll count  = 0;
  rep(i,N){
    if(v[i]+v[i+1] <= w[i]){
      count += v[i]+v[i+1];
      v[i] = v[i+1] = 0;
    }else{
      if(v[i]<=w[i]){
        w[i] -= v[i];
        count += v[i];
        count += w[i];
        v[i+1] -= w[i];
      }else{
        count += w[i];
        v[i] -= w[i];
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#define N 100

int main(){
  int M[N][N];
  int i, j, n, u, k, v;

  scanf("%d",&n);

  for(i = 0; i < n; i++) for(j = 0; j < n; j++) M[i][j] = 0;

  for(i = 0; i < n; i++){
    scanf("%d%d",&u, &k);
    u--;
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(j) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
        #define pb push_back
        #define mp make_pair
        #define ii pair<int,int>
        #define modulo 1000000007
        #define modulus 10000000000000003
        #define INF 100000000000000000
        #define int long long int
        using namespace std;
		vector<int> values,weights;
		vector<vector<int>> depe;
        int dp(int n,int w){
			if(depe[n][w]!=-1) return depe[n][w];
			int res;
			if(n==1){
				if(w<weights[0]) return 0;
				else return values[0];
				}
			if(w>weights[n-1]) res=max(dp(n-1,w-weights[n-1])+values[n-1],dp(n-1,w));
			else res=dp(n-1,w);
			depe[n][w]=res;
			return res;
			}
        int32_t main(){
			ios_base::sync_with_stdio(0);
			cin.tie(NULL);
			int N,W,val,weight;
			cin >> N >> W;
			depe.resize(N+1,vector<int>(W+1,-1));
			for(int i=0;i<N;i++){
				cin >> weight >> val;
				weights.pb(weight);
				values.pb(val);
				}
			cout << dp(N,W);
		}


Measured memory_bytes: 80256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll mod = static_cast<ll>(1e9) + 7;

static ll nums[] = {
    1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};

int main()
{
    ll k;
    cin >> k;
    --k;

    cout << nums[k] << endl;

    return 0;
}


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

bool check(int,int);

int main(){
	int a,b;
	cin >> a >> b;
	if(check(a,b))cout << '0';
	else cout << a-2*b;
	return 0;
}

bool check(int x,int y){
	return x <= 2*y;
}


Measured memory_bytes: 256