akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

/*std::mt19937 mt{ std::random_device{}() };

std::uniform_int_distribution<int> dist(1, 6);
dist(mt);

while(1){
	val;
	cout << val << endl;
	sol1 = solver1();
	sol2 = solver2();
	if(sol1==sol2){
	cout << "OK" << endl;
	}else{
	cout << "NG" << endl;
	cout << sol1 << endl;
	cout << sol2 << endl;
	break;
	}
}
*/

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  int n;
  cin >> n;
  ll ans=0;
  ll M=0;
  rep(i, n){
	  ll a;
	  cin >> a;
	  if(a > M){
		  M = a;
	  }else{
		  ans += M-a;
	  }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;



int main() {
	speed;
	cout << fixed << setprecision(6);
	/*start*/

	int a, b;
	cin >>a >>b;
	a += b;
	if (a % 2 == 0) {
		c(a / 2);
	}
	else {
		c(a / 2 + 1);
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
	int a,b,ans;
  	scanf("%d %d",&a,&b);
    if(a>b){
    	ans = 2*a - 1;
    }else if(a<b){
    	ans = 2*b - 1;
    }else{
    	ans = a+b;
    }
  	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define fi first 
#define se second
const long long MOD = 1000000007;
const long long inf = 1ll << 61;
const double eps = 0.000000000001;
typedef long long ll;
struct edge { int to; int cost; int color; };
int s[100006], t[100006], r[100006];

signed main() {
	int a, b, q; cin >> a >> b >> q;
	rep(i, a)cin >> s[i+1];
	rep(i, b)cin >> t[i+1];
	s[0] = t[0] = -inf;
	s[a + 1] = inf; t[b + 1] = inf;
	rep(i, q) {
		cin >> r[i];
		int S[3], T[3];
		S[0] = *(upper_bound(s, s + a + 2, r[i]) - 1);
		S[1] = *lower_bound(s, s + a + 2, r[i]);
		T[0] = *(upper_bound(t, t + b + 2, r[i]) - 1);
		T[1] = *lower_bound(t, t + b + 2, r[i]);
		int ans = inf;
		rep(j, 2) {
			rep(k, 2) {
				ans = min(ans, abs(S[j] - T[k]) + min(abs(r[i] - S[j]), abs(r[i] - T[k])));
			}
		}

		cout << ans<< endl;
	}
}


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

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n;
		int id;
		int s;
		while(true){
			n = scan.nextInt();
			if(n == 0)break;
			
			T[] t = new T[n];
			
			for(int i = 0; i < n; i++){
				id = scan.nextInt();
				s = 0;
				for(int j = 0; j < 4; j++){
					s += scan.nextInt()*60+scan.nextInt();
				}
				t[i] = new T(id, s);
			}
			Arrays.sort(t);
			System.out.println(t[0].id + "\n" + t[1].id + "\n" + t[n-2].id);
		}
	}
	static class T implements Comparable<T>{
		int id, t;
		public T(int id, int t) {
			this.id = id;
			this.t = t;
		}
		public int compareTo(T o) {
			return t - o.t;
		}
	}
}

Measured memory_bytes: 68520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 1000000000000000

int main(){
	ll n, m, x; cin >> n >> m >> x;
	vector<vector<ll>> vall(n,vector<ll>(m+1));
	REP(i,n) REP(j,m+1) cin >> vall[i][j];
	ll ans = INF;
	REP(i,(1ll<<n)){
		vector<ll> judl(m+1);
		REP(j,n) if ((i>>j)&1ll) REP(k,m+1) judl[k] += vall[j][k];
		bool jud = true;
		FOR(l,1,m) if (judl[l]<x) jud=false;
		if (jud) ans=min(ans,judl[0]);
	}
	if (ans==INF) cout << -1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 3620
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
#print(N,A,B,C)

satisfy = sum(B)
con=[]

for i in range(N-1):
  if A[i] + 1 == A[i+1]:
    con.append(A[i]-1)

#print(con)

for i in con:
  satisfy += C[i]
  #print(i, C[i])

print(satisfy)




Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	ll N; cin >> N;
	ll base = (ll)sqrt(N);
	while (N%base != 0) {
		base--;
	}
	cout << base + (N / base) - 2 << endl;




	return 0;
}


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

int main() {
	long long int N;
  	cin>>N;
  	long long int mod=0;
    long long int q=26;
  	string s;
  	while(N>0){
     	mod=N%q;
      	if(mod==0){
         	s+=(char)(122);
          	N-=26;
        }else{
      		s+=(char)(mod+96);
        }
      	N/=q;
      	
      
    }
  
  	reverse(s.begin(),s.end());
      
  	
  	
  	
  	cout<<s<<endl;
}

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

typedef long long ll;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    rep(i, H) cin >> S[i];
    int ans = 1e9;
    rep(i, 1 << (H - 1)) {
        int count = 0;
        rep(j, H - 1) {
            count += ((i >> j) & 1);
        }
        vector<vector<int>> v(W);
        rep(j, W) v[j].push_back(S[0][j] - '0');
        rep(j, H - 1) {
            rep(k, W) {
                if ((i >> j) & 1) v[k].push_back(S[j + 1][k] - '0');
                else v[k].back() += S[j + 1][k] - '0';
            }
        }
        /*
        cout << "i=" << i << "\n";
        rep(j, v[0].size()) {
            rep(k, W) {
                cout << v[k][j] << " ";
            }
            cout << "\n";
        }
        */
        vector<int> a(v[0].size(), 0);
        int n = v[0].size();
        rep(j, W) {
            bool f = false;
            rep(k, n) {
                a[k] += v[j][k];
                if (a[k] > K) f = true;
            }
            if (f) {
                count++;
                //cout << "count++\n";
                rep(k, n) {
                    a[k] = v[j][k];
                }
            }
            f = false;
            rep(k, n) {
                if (a[k] > K) f = true;
            }
            if (f) {
                count = 1e9;
                break;
            }
            /*
            cout << "j=" << j << "\n";
            rep(k, n) cout << a[k] << " ";
            cout << "\n";
            */
        }
        //if (count < ans) cout << "ans=" << count << "\n";
        ans = min(ans, count);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.math.*;

public class Main
{

    public static void process()throws IOException
    {
        Long a=nl();
        Double x=nd();
        Long b=(long)(100l*x);

        a*=b;
        pn(a/100l);
    }


    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new FastReader();

        long s = System.currentTimeMillis();
        int t=1;
        //t=ni();
        while(t-->0)
            process();

        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }
    
    
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static int ni()throws IOException{return Integer.parseInt(sc.next());}
    static long nl()throws IOException{return Long.parseLong(sc.next());}
    static double nd()throws IOException{return Double.parseDouble(sc.next());}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    
    static long mod=(long)1e9+7l;

    static<T> void r_sort(T arr[],int n){
        Random r = new Random(); 
        for (int i = n-1; i > 0; i--){ 
            int j = r.nextInt(i+1); 
                  
            T temp = arr[i]; 
            arr[i] = arr[j]; 
            arr[j] = temp; 
        } 
        Arrays.sort(arr); 
    }
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}


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

int main(){
    string s;
    cin>>s;
    int size;
    size=s.size();
    int m=1000;
    for(int i=0;i<size-2;i++){
        int k=stoi(s.substr(i,3));
        if(abs(k-753)<m){
            m=abs(k-753);
        }
    }
    cout<<m;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
int main(){
  int a,b,c[3];
  cin>>a>>b;
  c[0]=a+b;
  c[1]=a-b;
  c[2]=a*b;
  sort(c,c+3);
  cout<<c[2]<<endl;
  return(0);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:16777216")
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <unordered_map>

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 2e5 + 7;
const int inf = 2e9 + 7;
const ll infl = 1e18 + 7;
const long double eps = 1e-9;
const ll mod = 998244353;

int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif // _DEBUG

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string s, t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
	vector<vector<pair<int, int>>> p(n + 1, vector<pair<int, int>>(m + 1, { -1, -1 }));
	for (int i = 0; i <= n; i++) {
		dp[i][0] = 0;
	}
	for (int i = 0; i <= m; i++) {
		dp[0][i] = 0;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i - 1] == t[j - 1]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
				p[i][j] = { i - 1, j - 1 };
			}
			else {
				if (dp[i - 1][j] > dp[i][j - 1]) {
					dp[i][j] = dp[i - 1][j];
					p[i][j] = { i - 1, j };
				}
				else {
					dp[i][j] = dp[i][j - 1];
					p[i][j] = { i, j - 1 };
				}
			}
		}
	}
	string ans;
	int x = n, y = m;
	while (1) {
		int nx = p[x][y].ff, ny = p[x][y].ss;
		if (nx == -1) break;
		if (x - nx + y - ny == 1) {
			x = nx, y = ny;
		}
		else {
			ans.push_back(s[nx]);
			x = nx, y = ny;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
	return 0;
}

Measured memory_bytes: 105984
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-26 23:24:58 +0900
# LastModified: 2020-09-26 23:33:37 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    L = input()
    if int(L[0]) + int(L[1]) + int(L[2]) + int(L[3]) == 7:
        print("{}+{}+{}+{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) + int(L[1]) + int(L[2]) - int(L[3]) == 7:
        print("{}+{}+{}-{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) + int(L[1]) - int(L[2]) + int(L[3]) == 7:
        print("{}+{}-{}+{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) - int(L[1]) + int(L[2]) + int(L[3]) == 7:
        print("{}-{}+{}+{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) + int(L[1]) - int(L[2]) - int(L[3]) == 7:
        print("{}+{}-{}-{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) - int(L[1]) + int(L[2]) - int(L[3]) == 7:
        print("{}-{}+{}-{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) - int(L[1]) - int(L[2]) + int(L[3]) == 7:
        print("{}-{}-{}+{}=7".format(L[0], L[1], L[2], L[3]))

    elif int(L[0]) - int(L[1]) - int(L[2]) - int(L[3]) == 7:
        print("{}-{}-{}-{}=7".format(L[0], L[1], L[2], L[3]))




if __name__ == "__main__":
    main()


Measured memory_bytes: 9336
n,m=map(int,input().split())
L=[]
M=[]
for i in range(m):
  l,m=map(int,input().split())
  L.append(l)
  M.append(m)
  
a=max(L)
b=min(M)
if a<=b:
  print(b-a+1)
else:
  print(0)


Measured memory_bytes: 10996
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define f(i,a,b) for(int i=a; i<b; i++)
#define pb push_back
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
using namespace std;

int main()
{
    IOS
    double l;
    cin>>l;
    double x = (l*l*l)/27;
    printf("%0.7f", (l/3)*(l/3)*(l/3));
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    num = ''
    num += str(i // 100)
    num += str((i // 10) % 10)
    num += str(i % 10)
    j = 0
    for n in range(N):
        if S[n] == num[j]:
            j += 1
        if j == 3:
            break
    if j == 3:
        cnt += 1
print(cnt)



Measured memory_bytes: 41852
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
	int n,k,wildcard,temp;
	vector<int> a;
	while(scanf("%d %d",&n,&k)){
		if(n==0&&k==0)
		break;
		for(int i=0;i<k;i++){
			scanf("%d",&temp);
			a.push_back(temp);
		}
		sort(a.begin(),a.end());
		wildcard=(a[0]==0 ? 1:0);
		if(wildcard==1)
		a.erase(a.begin()+0);
		int i=0,cnt=1,max=0,cnt1temp;
		while(i<k){
			if(a[i+1]==a[i]+1){
				cnt++;
			}
			else{
				if(wildcard==0){
					cnt>max ? max=cnt:0;
					cnt=1;
				}
				else if(wildcard==2){
					cnt+=1+cnt1temp;
					cnt>max ? max=cnt:0;
					cnt=1;
					wildcard=1;
				}
				else{
					if(a[i+1]!=a[i]+2){
						cnt++;
						cnt>max ? max=cnt:0;
						cnt=1;
					}
					else{
						cnt1temp=cnt;
						cnt=1;
						wildcard=2;
					}
				}
			}
			i++;
		}
		printf("%d\n",max);
	}
}

Measured memory_bytes: 3508
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    int last_a = 0;
    int first_b = 0;
    int both = 0;
    int res = 0;
    rep(i, N) {
        string s;
        cin >> s;
        bool judge1 = 0, judge2 = 0;
        if (s[0] == 'B')
            judge1 = 1;
        if (s[s.size() - 1] == 'A')
            judge2 = 1;
        if (judge1 && judge2)
            both++;
        if (judge1 && !judge2)
            first_b++;
        if (!judge1 && judge2)
            last_a++;
        char prev = '#';
        rep(j, s.size()) {
            if (prev == 'A' && s[j] == 'B')
                res++;
            prev = s[j];
        }
    }

    if (both >= 1) {
        res += (both - 1);
        if (first_b >= 1 && last_a >= 1) {
            first_b--, last_a--;
            res += 2;
            res += min(first_b, last_a);
        } else if (first_b == 0 && last_a != 0) {
            res += 1;
        } else if (first_b != 0 && last_a == 0) {
            res += 1;
        }
    } else {
        res += min(first_b, last_a);
    }

    cout << res << endl;
}

Measured memory_bytes: 256
from operator import itemgetter

N = int(input())
A = list(map(int,input().split()))
B =[]
for i,c in enumerate(A):
    B.append([i+1,c])

B = sorted(B, key=itemgetter(1))

ans =[]
for i in range(N):
    ans.append(B[i][0])

C =map(str,ans)
C =' '.join(C)
print(C)

Measured memory_bytes: 28092
N,K = map(int,input().split())
r = [0]*N
for i in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    for j in range(d):
        r[A[j]-1] += 1

ans = 0
for i in range(N):
    if r[i] == 0:
        ans += 1
print(ans)

Measured memory_bytes: 9224
n=int(input())
ta=[list(map(int, input().split())) for _ in range(n)]
a,b=1,1
import math
for i in range(n):
    x,y=ta[i]
    t=max(-(-a//x),-(-b//y))
    a,b=t*x,t*y
print(a+b)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[200000];
constexpr ll MOD=1e9+7;
int main() {
    int n, k;
    cin >> n >> k;
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    // - 全部選ぶ場合はそのまま計算するだけ
    if (n==k){
        ll prod = 1;
        for (int i=0;i<n;++i){
            prod = (prod * (a[i]%MOD+MOD)%MOD)%MOD;
        }
        cout << prod;
        return 0;
    }
    sort(a, a+n);
    // - 最大値が負
    //   - 負の数しかいない and 奇数個選ぶ
    if (a[n-1]<0 && k%2==1){
        ll prod = 1;
        for (int i=1;i<=k;++i){
            prod = (prod * (a[n-i]%MOD+MOD)%MOD)%MOD;
        }
        cout << prod;
        return 0;
    }
    // - 最大値が0以上
    //   - 負の数しかいない and 偶数個選ぶ
    if (a[n-1]<0 && k%2==0){
        ll prod = 1;
        for (int i=0;i<k;++i){
            prod = (prod * (a[i]%MOD+MOD)%MOD)%MOD;
        }
        cout << prod;
        return 0;
    }
    //   - 0以上がいる場合
    //     - 負の数が奇数個なら絶対値最小のものを残せばよい
    //     - 負の数が偶数個なら全部使えばよい
    int l=0, r=n-1;
    ll prod=1;
    while(k>0){
        if(k==1){
            prod = (prod * (a[r]%MOD+MOD)%MOD)%MOD;
            r-=1;
            k=0;
        }else{
            ll prod_1 = a[l]*a[l+1], prod_2 = a[r]*a[r-1];
            if(prod_1 < prod_2){
                prod = (prod * (prod_2%MOD))%MOD;
                r-=2;
            }else{
                prod=(prod*(prod_1%MOD))%MOD;
                l+=2;
            }
            k-=2;
        }
    }
    cout << prod;
    return 0;
}

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

int main() {
  int A, B, C; cin >> A >> B >> C;
  if (A + B >= C) cout << "Yes" << endl;
  else            cout << "No" << endl;
}


Measured memory_bytes: 3668
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
    int n;
    int k;
    int sum;
    int a[100];
    while(scanf("%d",&n)!=EOF)
    {
        sum=0;
        scanf("%d",&k);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]<=abs(k-a[i]))
                sum=sum+a[i];
            else
                sum=sum+abs(k-a[i]);
        }

        cout<<2*sum<<endl;

    }
}




Measured memory_bytes: 256
import sys

def main():
    N, M = map(int, input().split())
    As = list(map(int, input().split()))
    sys.stderr.write(str(As))
    sys.stderr.write('\n')


    s = sum(As)
    cnt = len([a for a in As if a >= 1.0 * s / (4*M)])
    sys.stderr.write(str(s))
    sys.stderr.write('\n')
    sys.stderr.write(str(cnt))
    sys.stderr.write('\n')


    if cnt >= M:
        print("Yes")
    else:
        print("No")

    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
using namespace std; 
  
typedef long long LL; 
typedef pair<int, int> pii; 
typedef pair<LL, LL> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<string> vs;
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<LL> vl; 
typedef vector<vl> vvl; 
  
double EPS = 1e-9; 
int INF = 100005; 
long long int mod=1000000007;
long long TES=1000007;
long long INFF = 1000000000000000005LL; 
double PI = acos(-1); 
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 }; 
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 }; 
  
#ifdef TESTING 
#define DEBUG fprintf(stderr, "====TESTING====\n") 
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl 
#define debug(...) fprintf(stderr, __VA_ARGS__) 
#else 
#define DEBUG 
#define VALUE(x) 
#define debug(...) 
#endif 
  
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) 
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) 
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) 
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) 
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) 
#define FOREACH(a, b) for (auto&(a) : (b)) 
#define rep(i, n) FOR(i, 0, n) 
#define repn(i, n) FORN(i, 1, n) 
#define MAX(a, b) a = max(a, b) 
#define MIN(a, b) a = min(a, b) 
#define SQR(x) ((LL)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define TC(t) while (t--)

void solve()
{
   
   int x,y;
   cin>>x>>y;
   if(y&1)
   {
       cout<<"No\n";
       return;
   }
  /* else
   if(y/4==x-1 && y%4==2)
   {
        cout<<"Yes\n";
        return;
   }
   else
    if(y/4==x && y%4==2)
   {
        cout<<"No\n";
        return;
   }*/
   else
   if(y>4*x|| (y/4==x && y%4!=0) || 2*x>y)
   {
       cout<<"No\n";
       return;
   }
   cout<<"Yes\n";
   return;
   
}
int main()
{
    IOS();
   /* int test;
    cin>>test;
    TC(test)*/
    solve();
    return 0;
}





Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> a(n);
	vector<pair<int,int>> p(m);

	rep(i,0,n) cin >> a[i];
	rep(j,0,m){
		int x,y;
		cin >> x >> y;
		p[j] = make_pair(y,x);
	}

	p.push_back( make_pair(0 , n ) );

	rvsort(a);
	vsort(p);
	reverse(p.begin() , p.end() );
	queue<int> q1 , q2;

	rep(i,0,n) q1.push(a[i]);

	int idx = 0;
	rep(i,0,n) {
		q2.push( p[idx].first );
		p[idx].second--;
		if( p[idx].second <= 0  ) idx++;
	}

	ll ans = 0;
	rep(i,0,n){
		int p1,p2;
		p1 = q1.front();
		p2 = q2.front();

		if( p1 > p2 ){
			q1.pop();
			ans += p1;

			/*
			if(q1.empty()){
				for( int j = 0 ; j < n - i ; j++ ){
					ans += q2.front();
					q2.pop();
				}
				break;
			}
			*/

		}
		else{
			q2.pop();
			ans += p2;

			/*
			if(q2.empty()){
				for( int j = 0 ; j < n - i ; j++ ){
					ans += q1.front();
					q1.pop();
				}
				break;
			}
			*/

		}

	}


	cout << ans << endl;

	ret 0;
}

Measured memory_bytes: 2288
#include <stdio.h>
#define LL long long
int p[50],m[50],tot;//p[]记录质数,m[]记录幂次
int main(){
	LL n;
	int i,j,ans=0;
	scanf("%lld",&n);
	for(i=2;(LL)i*i<=n;i++)//注意此处不能写成for(i=2;i*i<=n;i++)
		if(n%i==0){
			p[++tot]=i;
			while(n%i==0)n/=i,m[tot]++;
		}
	if(n>1)p[++tot]=n,m[tot]=1;
	for(i=1;i<=tot;i++){
		j=1;
		while(1){
			if(m[i]>=j)ans++,m[i]-=j;
			else break;
			j++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1704
import sys

N, M = [int(s) for s in input().split()]
sys.setrecursionlimit(10**5)
dp = [-1] * (N+1)
neighbors = [[] for _ in range(N+1)]

for _ in range(M):
    x, y = [int(s) for s in input().split()]
    neighbors[x].append(y)

def LP(v):
    if dp[v] != -1:
        return dp[v]
    else:
        res = 0
        lp = [-1]
        for nv in neighbors[v]:
            lp.append(LP(nv))
        res = max(res, max(lp) + 1)
        dp[v] = res
        return res

ans = 0
for v in range(1,N+1):
    ans = max(ans, LP(v))

print(ans)



Measured memory_bytes: 164428
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 














int main()
{
    int l;
    cin>>l;
    long double len=(double)l/3.0;
    long double res=(double)len*len*len;
    cout<<fixed<<setprecision(10)<<res;
}
























 
 
 
 
 

















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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

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;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}

        
//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int N,M,Q;
vi a,b,c,d;
int ans=0;
void dfs(vi A){
  if(A.size()==N){
    int now=0;
    rep(i,Q){
      if(A[b[i]]-A[a[i]] ==c[i]){
        now +=d[i];
      }
    }
    ans = max(ans,now);
    return;
  }
  int prev=(A.empty() ?  0:A.back());
  for(int i=prev; i<M; i++ ){
    A.pb(i);
    dfs(A);
    A.pop_back(); 
  }
    
}
int main(){
  cin>>N>>M>>Q;
  vi w(Q),x(Q),y(Q),z(Q);
  rep(i,Q){
    cin>>w[i]>>x[i]>>y[i]>>z[i];
    w[i]--;x[i]--;
  }
  a=w;b=x;c=y;d=z;
  vi B={};
  dfs(B);
  cout<<ans<<endl;
  
}






Measured memory_bytes: 3716
use proconio::input;
use proconio::marker::{Bytes, Chars, Isize1, Usize1};

fn main() {
    input! {
        mut cs: Chars
    }

    let len = cs.len();

    let ans = if cs[len-1] == 's' { 
        cs.push('e');
        cs.push('s');
        cs
    } else {
        cs.push('s');
        cs
    };

    println!("{}",ans.iter().collect::<String>())
}

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

int main() {
	int H, W, M;
	cin >> H >> W >> M;
	vector<int> h(M), w(M);
	// vector<vector<int>> h_vec(H, vector<int>()), w_vec(W, vector<int>());
	// vector<pair<int, vector<int>>> h_vec(H, pair<int, vector<int>>()), w_vec(W, pair<int, vector<int>>());
	vector<pair<int, pair<int, vector<int>>>> h_vec(H, pair<int, pair<int, vector<int>>>()), w_vec(W, pair<int, pair<int, vector<int>>>());
	for (int i=0;i<H;i++) {
		h_vec[i].first = 0;
		h_vec[i].second.first = i;
	}
	for (int i=0;i<W;i++) {
		w_vec[i].first = 0;
		w_vec[i].second.first = i;
	}
	for (int i=0;i<M;i++) {
		cin >> h[i];
		cin >> w[i];
		h[i]--;
		w[i]--;
		h_vec[h[i]].first++;
		h_vec[h[i]].second.second.push_back(w[i]);
		w_vec[w[i]].first++;
		w_vec[w[i]].second.second.push_back(h[i]);
	}

	sort(h_vec.begin(), h_vec.end());
	sort(w_vec.begin(), w_vec.end());

	int h_vec_max = h_vec[H-1].first;
	int h_index = H-1;

	int h_cnt = 0;
	vector<int> w_cnt(W, 0);

	while (h_vec[h_index].first == h_vec_max) {
		h_cnt++;
		for (int w_val : h_vec[h_index].second.second) {
			w_cnt[w_val]++;
		}

		h_index--;
		if (h_index < 0) break;
	}

	set<int> w_can_use;
	for (int i=0;i<W;i++) {
		if (w_cnt[i] != h_cnt) w_can_use.insert(i);
	}
	// cout << "w_cnt" << endl;
	// for (auto kkk : w_cnt) {
	// 	cout << kkk << " ";
	// }
	// cout << endl;
	// cout << "###" << endl;

	// cout << "w_can_use" << endl;
	// for (auto kkk : w_can_use) {
	// 	cout << kkk << " ";
	// }
	// cout << endl;
	// cout << "###" << endl;


	int w_vec_max = w_vec[W-1].first;
	int w_index = W-1;

	int ans = h_vec_max+w_vec_max-1;
	while (w_vec[w_index].first == w_vec_max) {
		int w_iii = w_vec[w_index].second.first;
		// cout << "W_iii " << w_iii << endl;
		if (w_can_use.count(w_iii)) {
			ans++;
			break;
		}

		w_index--;
		if (w_index < 0) break;
	}

	cout << ans << endl;
}

Measured memory_bytes: 62900
import java.util.*;

public class Main{
	
	//1420 start
	
	HashSet<String> appear;
	char [][] data;
	String ans;
	int h,w;
	int [] vx = {0,1,0,-1,1,1,-1,-1};
	int [] vy = {1,0,-1,0,1,-1,-1,1};
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			h = sc.nextInt();
			w = sc.nextInt();
			if((h|w) == 0) break;
			
			data = new char[h][w];
			for(int i = 0; i < h; i++){
				String s = sc.next();
				data[i] = s.toCharArray();
			}
			ans = "";
			appear = new HashSet<String>();
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					
					solve(i, j);
				}
			}
			System.out.println(ans.equals("") ? 0 : ans);
		}
	}

	private void solve(int y, int x) {
		
		for(int i = 0; i < 8; i++){
			StringBuilder sb = new StringBuilder();
			sb.append(data[y][x]);
			int xx = x, yy = y;
			while(true){
				xx = (xx + vx[i] + w) % w;
				yy = (yy + vy[i] + h) % h;
				if(xx == x && yy == y){
					break;
				}
				sb.append(data[yy][xx]);
				
				if(appear.contains(sb.toString())){
					
					String now = sb.toString();
					//System.out.println("now = " + now);
					if(now.length() > ans.length()){
						ans = now;
					}
					else if(now.length() == ans.length() && now.compareTo(ans) < 0){
						ans = now;
					}
				}
				else{
					appear.add(sb.toString());
				}
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 77000
#include <stdio.h>

int main() {
	int answer = 0;
	int N = 0;
	scanf("%d", &N);

	int A[N];
	int A_even[N];
	for(int i = 0; i < N; i++) {
		A_even[i] = 0;
	}
	int j = 0;
	for(int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		if((A[i] % 2) == 0) {
			if(((A[i] % 3) == 0) || ((A[i] % 5) == 0)) {
			} else {
				printf("DENIED\n");
				return 0;
			}
		}
	}
	printf("APPROVED\n");
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  vector<int> nv;
  for (int x : v) {
    nv.push_back(x - 1);
    nv.push_back(x);
    nv.push_back(x + 1);
  }
  sort(nv.begin(), nv.end());
  int count = 1, maxv = -1;
  for (int i = 0; i < nv.size(); i++) {
    if (nv[i] == nv[i + 1]) {
      count++;
    } else {
      maxv = max(maxv, count);
      count = 1;
    }
  }
  cout << maxv << endl;
}


Measured memory_bytes: 2804
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int r, g;
  cin >> r >> g;

  cout << g * 2 - r << endl;


  
  return 0;
}

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

int main()
{
    int t;
    int n, k;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        cin >> n >> k;
        int a[100000], b[99999];
        for (int j = 0; j < n; j++) {
            cin >> a[j];
        }
        sort(a, a + n);
        int sum = 0;
        for (int j = 0; j < n - 1; j++) {
            b[j] = a[j + 1] - a[j];
            sum += b[j];
        }
        sort(b, b + n - 1);
        reverse(b,b+n-1);
        if (n > k) {
            for (int s = 0; s < k - 1; s++) {
                sum -= b[s];
            }
        }
        else{
            sum = 0;
        }
        cout << sum << endl;
    }
        return 0;

}

Measured memory_bytes: 1956
#include <bits/stdc++.h>
using namespace std;
long long dp[101][123456];
int main(void){
	int N,W;
	cin >> N >> W;
	long long w[N],v[N];
	for(int i=0;i<N;i++){
		cin >> w[i] >> v[i];
	}
	//vの最大値を求める。
	
	//dp[i][j]i-1番目までを選んで総重量がj以下のときの価値の最大値
	for(int i=0;i<N;i++){
		for(int j=0;j<=W;j++){
			if(j-w[i]>=0){
				dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
			}
			dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
		}
	}
	cout << dp[N][W] << endl;
}

Measured memory_bytes: 96128
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    string s;
    int a,b,c;
    fi>>a>>b>>c;
    swap(b,c);
    fi>>s;
    s = '#' + s;
    int cnt = b + c;
    for (int i = 1;i <= a;++i)
    {
        if (cnt > 0 && (s[i] == 'a' || (s[i] == 'b' && b > 0)))
            --cnt,fo << "Yes\n",b -= s[i] == 'b';
        else
            fo << "No\n";
    }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

Measured memory_bytes: 892
#n = int(input())
#a, b = map(int,input().split())
#l = list(map(int,input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
s = list(input())
t = list(input())


def sameNum(s, t):
    res = 0
    for i in range(len(s)):
        if s[i] == t[i]:
            res += 1
    return res


ns = len(s)
nt = len(t)
mn = nt
for i in range(ns-nt+1):
    samenum = sameNum(s[i:i+nt], t)
    mn = min(mn, nt-samenum)
print(mn)


Measured memory_bytes: 9144
h, w=map(int, input().split())
ans=['']*(h+2)
ans[0]='#'*(w+2)
ans[h+1]='#'*(w+2)
for i in range(1, h+1):
  ans[i]='#'+input()+'#'
for i in range(h+2):
  print(ans[i])

Measured memory_bytes: 3060
n,m=[int(x) for x in input().split()]
kens=[[] for x in range(n)]
shis=["" for x in range(m)]
for i in range(m):
    pi,yi=[int(x)-1 for x in input().split()]
    kens[pi].append((i,yi))
    shis[i]=("0"*10+str(pi+1))[-6:]
for ken in kens:
    ken=sorted(ken,key=lambda x :x[1])
    for i in range(len(ken)):
        shis[ken[i][0]]+=("0"*6+str(i+1))[-6:]
for shi in shis:
    print(shi)

Measured memory_bytes: 80416
#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 ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 
ll a[500];
map<ll,ll>c;
int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> x >> n;

	for(i=1;i<=n;i++)
	{
		cin >> a[i];
		c[a[i]]=1;
	}

	ll mn=2000,ans;
	for(i=-200;i<=200;i++)
	{
		if(c.find(i)==c.end())
		{
			if(abs(x-i)<mn)
			{
				mn=abs(x-i);
				ans=i;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3616
// Last Change: 04/18/2019 22:24:38.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

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

  vector<pair<ll, ll>> shop(N);
  ll A, B;
  for (ll i = 0; i < N; ++i) {
    cin >> A >> B;
    shop[i] = make_pair(A, B);
  }

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

  ll ans = 0, bottle = 0, index = 0;
  while (bottle < M) {
    ll tmp = min(shop[index].second, M - bottle);
    bottle += tmp;
    ans += tmp * shop[index].first;
    ++index;
  }

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
  string s,t,k,l;
  cin >> s;
  int ss=s.size();
  vector <int> v;
  for(int i=1;i<ss;i++){
     t=s.substr(0,ss-i);
     int ts=t.size();
     if(ts%2==1) continue;
     k=t.substr(0,ts/2);
     l=t.substr(ts/2);
     if(k==l) v.push_back(ts);
  }
  sort(v.begin(),v.end());
  int vs=v.size();
  cout <<v[vs-1]<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
public class Main{
	static ArrayList<Integer>[] edge;
	static long[][] dp;
	static int m;
	static ArrayList<Long>[] fcum;
	static ArrayList<Long>[] bcum;
	static long[] ans;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		m=sc.nextInt();
		//0が白、１が黒
		dp=new long[n][2];
		edge=new ArrayList[n];
		fcum=new ArrayList[n];
		bcum=new ArrayList[n];
		for(int i=0; i<n; i++){
			dp[i][0]=dp[i][1]=1;
			bcum[i]=new ArrayList<>();
			edge[i]=new ArrayList<>();
			fcum[i]=new ArrayList<>();
		}
		for(int i=1; i<n; i++){
			int x=sc.nextInt()-1;
			int y=sc.nextInt()-1;
			edge[x].add(y);
			edge[y].add(x);
		}
		dfs1(0,0);
		ans=new long[n];
		ans[0]=dp[0][1];
		dfs2(0,0,1);
		PrintWriter pw=new PrintWriter(System.out);
		for(int i=0; i<n; i++){
			pw.println(ans[i]);
		}
		pw.flush();
	}
	static void dfs2(int now,int from,long mu){
		int index=1;
		for(int i:edge[now]){
			if(i!=from){
				long tmu=(1+mu*((fcum[now].get(index-1)*bcum[now].get(fcum[now].size()-1-index))%m))%m;
				ans[i]=dp[i][1]*tmu%m;
				index++;
				dfs2(i,now,tmu);
			}
		}
	}
	static void dfs1(int now,int from){
		fcum[now].add(1L);
		bcum[now].add(1L);
		for(int i:edge[now]){
			if(i!=from){
				dfs1(i,now);
				dp[now][0]=dp[now][0]*dp[i][0]%m;
				dp[now][1]=dp[now][1]*(dp[i][0]+dp[i][1])%m;
			}
		}
		long cum=1;
		for(int i=0; i<edge[now].size(); i++){
			if(edge[now].get(i)!=from){
				cum=cum*(dp[edge[now].get(i)][1]+1)%m;
				fcum[now].add(cum);
			}
		}
		cum=1;
		for(int i=edge[now].size()-1; i>=0; i--){
			if(edge[now].get(i)!=from){
				cum=cum*(dp[edge[now].get(i)][1]+1)%m;
				bcum[now].add(cum);
			}
		}
	}
}


Measured memory_bytes: 144100
#include <stdio.h>

int main(void) {
	char S[5];
	scanf("%s",S);
	if(S[0]==S[1]&&S[2]==S[3]&&S[0]!=S[2]){
		printf("Yes");
	}else if(S[0]==S[2]&&S[1]==S[3]&&S[0]!=S[1]){
		printf("Yes");
	}else if(S[0]==S[3]&&S[1]==S[2]&&S[0]!=S[1]){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
  int N;
  ll K;
  while (cin >> N >> K) {
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    vector<int> cnt(70, 0);
    for (int b = 0; b < 70; b++) {
      for (ll a : A) cnt[b] += (a >> b) & 1;
    }
    ll resK = 0;
    for (ll a : A) resK += a ^ K;
    ll res = resK;
    ll bottom = 0;
    for (int b = 0; b < 70; b++) {
      if ((K >> b) & 1) {
        ll mask = (1ll << b) - 1;
        ll X = (K & (~mask)) ^ (1ll << b);
        ll sum = bottom;
        for (ll a : A) sum += (a ^ X) & (~mask);
        res = max(res, sum);
      }
      bottom += (1ll << b) * max(N - cnt[b], cnt[b]);
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

C = Counter(A).most_common()
p = 0
for k,v in C:
    if v==1 and k==0 and N%2==1:
        continue
    elif v==2:
        p += 1
        continue
    else:
        p = 0
        break
if N==1:
    print(1)
else:
    print(p if p==0 else (2**p)%(10**9+7))

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

int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int M=max({a,b,c});
    int ans=a+b+c-M;
    for(int i=1;i<=k;i++)M*=2;
    ans+=M;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import math


def main():
    N = int(input())
    xy_list = [list(map(int, input().split())) for i in range(N)]

    sum = 0

    for i, xy1 in enumerate(xy_list):
        for j, xy2 in enumerate(xy_list):
            if i == j:
                continue

            x1 = xy1[0]
            x2 = xy2[0]
            y1 = xy1[1]
            y2 = xy2[1]

            sum += math.sqrt((x1-x2)**2 + (y1-y2)**2)

    print(sum/N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,cnt,a,bit[(1LL<<20)],ans;
vector<ll>v,v2,v1;
ll sum(ll i){
    ll s=0;
    while(i>0){
        s+=bit[i];
        i-=i&-i;
    }
    return s;
}
void add(ll i,ll x){
    while(i<=n+1){
        bit[i]+=x;
        i+=i&-i;
    }
    return ;
}
int main(void){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        v.push_back(cnt);
        v2.push_back(cnt);
        cin>>a;
        cnt+=a;
        cnt-=k;
    }
    v.push_back(cnt);
    v2.push_back(cnt);
    sort(v2.begin(),v2.end());
    for(int i=0;i<=n;i++){
        ll L=lower_bound(v2.begin(),v2.end(),v[i])-v2.begin();
        v1.push_back(L+1);
    }
    for(ll x:v1){
        ans+=sum(x);
        add(x,1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6628