akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<queue>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
ll dx[4] = {1,0,0,-1};
ll dy[4] = {0,1,-1,0};

#define ARRAY_MAX 1005

int main(){

    ll n,m;
    cin >> n;
    map<ll,ll> a;
    ll tmp;
    REP(i,n){
        cin >> tmp;
        a[tmp]++;
    }
    cin >> m;
    vector<ll> b(m);
    REP(i,m){
        cin >> b[i];
    }

    bool ans = true;
    REP(i,m){

        if(a.find(b[i]) != a.end()){
            //問題がある
            if(a[b[i]] > 0){
                //まだ使っていない問題がある
                a[b[i]]--;
            }else{
                ans = false;
                break;
            }
        }else{
            ans = false;
            break;
        }
    }
    if(ans){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }



    return 0;
}

Measured memory_bytes: 16384
#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 ordered_set tree<pair<int,int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define standardVar ll n,m,i,j,k,num,num1,num2,flag=0
#define nn <<"\n"
#define __ <<" "<<
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define ittr(x,v) for(auto x=v.begin();x!=v.end();x++)
#define itr(x,n) for(x=0;x<n;x++)
#define itrab(x,a,b) for(x=a;x<b;x++)
#define itpr(v) ittr(x,v)cout<<*x<<" "; cout nn
#define itppr(v) ittr(x,v)cout<<(*x).ff<<" "<<(*x).ss<<"  "; cout nn
#define pi 3.14159265359
#define dTor(x) ((x)*pi)/180.0

typedef long long int ll;       //TYPEDEFS
typedef long double ld;
typedef vector<ll> vl;
typedef map<ll,ll> ml;
typedef set<ll> sl;
typedef string str;
typedef pair<ll, ll> pl;
typedef vector< pl > vpl;
typedef map<pl,ll> mpl;
typedef set< pl > spl;
typedef vector<str> vst;
typedef vector<vl> vvl;

const ll M=1000000007;          //COMMON MODULO
const ll N=998244353;

ll power(ll x, ll y, ll p){     //MODULAR EXPONENTIATION
    ll res=1;
    x=x%p;
    if(x==0)
        return 0;
    while(y>0){
        if(y&1)
            res=(res*x)%p;
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}
ll inv(ll x, ll m){             //FERMAT INVERSE
    return power(x,m-2,m);
}
struct comp{                    //COMPARISON ON PAIRS
    template<typename T>        
    bool operator()(const T &a, const T &b){
        if (a.ff==b.ff)
            return (a.ss<b.ss);
        else
            return (a.ff<b.ff);
    }
};
bool mod(const pair<ll,ll> &a, const pair<ll,ll> &b){   //COMPARATOR FOR PAIRS (SORTING)
    if(a.ff!=b.ff)
        return (a.ff<b.ff);
    else
        return (a.ss<b.ss);
}
void sieve(vl &prime){          //SIEVE OF ERATOSTHENES
    ll maxN=1e6;
    vector<bool> pr(maxN+1,1);
    for(int i=2;i*i<=maxN;i++)
        if(pr[i]==1)
            for(int j=i*i;j<=maxN;j+=i)
                pr[j]=0;
    for(ll i=2;i<=maxN;i++)
        if(pr[i]==1)
            prime.pb(i);
}
bool isValid(ll i, ll j, ll n, ll m){   //CHECKS FOR OVERFLOW
    if(i>=0&&i<n&&j>=0&&j<m){
        return true;
    }
    return false;
}

//MAIN FUNCTION STARTS HERE

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    standardVar;
    cin>>n>>m>>k;
    vst v;
    itr(i,n){
        str s;
        cin>>s;
        v.pb(s);
    }
    ll ans=0;
    for(ll mask=0;mask<(1<<(n+m));mask++){
        ll c=0;
        itr(i,n){
            itr(j,m){
                if(v[i][j]=='.')
                    continue;
                if(mask&((1<<i)|(1<<(n+j))))
                    continue;
                c++;
            }
        }
        //cout<<c<<" ";
        if(c==k){
            ans++;
        }
    }
    cout<<ans nn;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n = 3;
    vector<int> vc;
    while(n--){
        int x;
        cin >> x;
        vc.push_back(x);
    }
    sort(vc.begin(), vc.end());
    
    for(int i = 0; i < vc.size() - 1; i++){
        cout << vc[i] << " ";
    }
    cout << vc[vc.size() - 1] << "\n";
}



Measured memory_bytes: 3208
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    int a[n];
    int b[n];
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    int sa[n];
    int sb[n];
    sa[0]=a[0];
    sb[0]=b[0];
    for(int i=1;i<n;i++){
        sa[i]=sa[i-1]+a[i];
        sb[i]=sb[i-1]+b[i];
    }
    int ans=sa[0]+sb[n-1];
    for(int i=1;i<n;i++){
        int z=sa[i]+sb[n-1]-sb[i-1];
        if(ans<z){
            ans=z;
        }
    }
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>

using namespace std;

int m, n, N, ans;
char mat[1000][1000];
int d[1000][1000], sx[10], sy[10];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

int bfs(int sx, int sy, int tx, int ty) {
    memset(d, -1, sizeof(d));
    d[sx][sy] = 0;
    queue<pair<int, int>> q;
    q.push(make_pair(sx, sy));
    int x, y, xx, yy;
    while (!q.empty()) {
        pair<int, int> cur = q.front(); q.pop();
        x = cur.first;
        y = cur.second;
        for (int i = 0; i < 4; i++) {
            xx = x + dx[i];
            yy = y + dy[i];
            if (xx >= 0 && xx < m && yy >= 0 && yy < n && mat[xx][yy] != 'X' && d[xx][yy] == -1) {
                d[xx][yy] = d[x][y] + 1;
                if (xx == tx && yy == ty) {
                    return d[xx][yy];
                }
                q.push(make_pair(xx, yy));
            }
        }
    }
    return 0;
}

void solve() {
    ans = 0;
    for (int i = 0; i < m; i++) {
        cin >> mat[i];
        for (int j = 0; j < n; j++) {
            if (mat[i][j] == 'S') {
                sx[0] = i;
                sy[0] = j;
            } else if (mat[i][j] >= '1' && mat[i][j] <= '9') {
                int t = mat[i][j] - '0';
                sx[t] = i;
                sy[t] = j;
            }
        }
    }
    for (int i = 1; i <= N; i++) {
        ans += bfs(sx[i-1], sy[i-1], sx[i], sy[i]);
    }
}

int main(int argc, const char * argv[]) {
    cin >> m >> n >> N;
    solve();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7892
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s;cin>>s;
	int n = s.size();

	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		a[i] = s[i] - '0';
	}

	vector<ll> dp1(n + 1,0LL);//i桁目まででLより小さいことが確定したa,b
	vector<ll> dp2(n + 1,0LL);//i桁目まででLと一致しているa,b
	dp2[0] = 1;
	for(int i = 1; i < n + 1; i++) {
		if (a[i - 1] == 1){
			dp1[i] = (dp2[i - 1] + dp1[i - 1] * 3) % mod;
			dp2[i] = (dp2[i - 1] * 2) % mod;
		}
		else{
			dp1[i] = (dp1[i - 1] * 3) % mod;
			dp2[i] = dp2[i - 1];
		}
	}
	cout << (dp1[n] + dp2[n]) % mod << endl;
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int X;
	cin >> X;

	auto result = 1;
	if (X > 1)
	{
		for (auto i = 2; i <= 31; ++i)
		{
			auto temp = i * i;
			while (temp <= X)
			{
				result = max(result, temp);
				temp *= i;
			}
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
using namespace std;

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

	double Y;
	Y = pow(2, K);

		if (A >= B && A >= C) {
			cout << (A * Y) + B + C  << endl;
		}
		else if (B >= A && B >= C) {
			cout << (B * Y) + A + C << endl;
		}
		else if (C >= A && C >= B) {
			cout << (C * Y) + A + B << endl;
		}
	//cout << Y << endl;
}



Measured memory_bytes: 256
//https://atcoder.jp/contests/abc138/tasks/abc138_b
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    double ans=0;
    vector<int>a(n);
    rep(i,n) cin>>a.at(i);
    
    rep(i,n){
        ans += 1.0/a.at(i);
    }
    
    ans = 1.0/ans;

    cout << fixed << setprecision(6) << ans << endl;
}

Measured memory_bytes: 256
program poll
    implicit none
    integer(4):: n,i,count
    character(10),allocatable:: s(:)

    read*, n   
    allocate(s(n))
    do i=1,n
        read*,s(i)
    end do

    call smerge_sort(s, 1,n)

    count = serch_max_remain_word(s)
    count = serch_max_remain_word(s, (count))
    

contains
function serch_max_remain_word(s, count_print) result(max_count)
    integer(4):: max_count
    integer(4),intent(in), optional:: count_print
    character(10),allocatable:: s(:)
    integer(4):: i
    count=1
    max_count=0

    do i=2,size(s(:))
        if (s(i) == s(i-1)) then
            count=count+1
        else
            max_count=max(max_count,count)
            if (present(count_print)) then
                if (count == count_print) print*,s(i-1)
            end if
            count=1
        end if
    end do
    max_count=max(max_count,count)
    if (present(count_print)) then
        if (count == count_print) print*,s(i-1)
    end if
end function

recursive subroutine smerge_sort(s, fst,lst)
    integer(4):: fst,lst,mid
    character(10):: s(:), tmp

    if (lst-fst < 2) then
        if (s(lst) < s(fst)) then
            tmp = s(fst)
            s(fst) = s(lst)
            s(lst) = tmp
        end if
        return
    end if

    mid = (fst+lst)/2
    call smerge_sort(s,fst,mid)
    call smerge_sort(s,mid+1,lst)
    call smerge(s,fst,mid,lst)

end subroutine

subroutine smerge(s,fst,mid,lst)
    integer(4):: fst,mid,lst
    integer(4):: li,ri,ti
    character(10):: s(:)
    character(10),allocatable:: tmp(:)

    allocate(tmp(lst-fst+1))
    li=fst
    ri=mid+1
    ti=1

    do while(li <= mid .and. ri <= lst)
        if (s(li) <= s(ri)) then
            tmp(ti) = s(li)
            li=li+1
        else
            tmp(ti) = s(ri)
            ri=ri+1
        end if
        ti=ti+1
    end do

    if (ri > lst) then
        tmp(ti:) = s(li:mid)
    else
        tmp(ti:) = s(ri:lst)
    end if

    s(fst:lst) = tmp(:)
    deallocate(tmp)
end subroutine
end program



Measured memory_bytes: 5540
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
int main(){
    int a,b;
    cin>>a>>b;
    int ans=1,cnt=0;
    while(true){
        if (ans>=b)
        {
            /* code */
            cout<<cnt<<endl;
            break;
        }
        ans--;
        ans+=a;
        cnt++;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	int a, b, c;

	cin >> a >> b >> c;

	if (b - a == c - b) cout << "YES" << endl;
	else cout << "NO" << endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    ll N,K;
    cin>>N>>K;
    vll A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(ALL(A));
    reverse(ALL(A));
    ll ansR=1000000001;
    ll ansL=0;
    while(ansL<ansR-1){
        ll cut=0;
        ll L=(ansL+ansR)/2-1;
        //cout<<ansL<<","<<ansR<<","<<L<<endl;
        for(int i=0;i<N;i++){
            //L=3なら 1~3:0回 4~6:1回
            if(L<A[i]){
                cut+=(ll)ceil((double)A[i]/(double)L)-1;
                if(cut>K)break;
            }
        }
        if(cut<=K){
            ansR=L+1;
        }else{
            ansL=L+1;
        }
    }
    cout<<ansL<<endl;
}


Measured memory_bytes: 4700
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        }
        int res = 1;
        int diff = 0;
        for (int i = 1; i < n; i++) {
            if(ar[i]-ar[i-1]==0){
                //nop
            }else{
                if(diff == 0){
                    diff = ar[i]-ar[i-1];
                }else{
                    if((long)(diff)*(long)(ar[i]-ar[i-1])<0){
                        diff = 0;
                        res++;
                    }
                }
            }
        }
        System.out.println(Math.max(1,res));


        sc.close();
    }
}

class io {
    public static void br() {
        System.out.println("");
    }

    public static void yesno(boolean f) {
        System.out.println(f ? "yes" : "no");
    }

    public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    }

    public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    }

}

class Algo {
    public static int nibutan(int target, int[] ar) {
        // ar[i] >= target なる最小のiを探す
        int res;
        int high = ar.length;
        int low = 0;
        while (high > low) {
            res = (high + low) / 2;
            if (ar[res] < target) {
                // ↑↓ここを変える
                low = res + 1;
            } else {
                // ↓ここを変える
                high = res;
            }
        }
        return low;
    }

    public static boolean isOdd(int n) {
        return n % 2 == 1;
    }

    public static boolean isEven(int n) {
        return n % 2 == 0;
    }


}



Measured memory_bytes: 50356
#!/usr/bin/env python3
import sys
from itertools import chain

# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np


def solve(N: int):
    az = "abcdefghijklmnopqrstuvwxyz"
    N -= 1
    answer = ""
    while True:
        answer = az[N % 26] + answer
        N = N // 26
        if N == 0:
            break
        N = N - 1
    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N = map(int, line.split())
    N = int(next(tokens))  # type: int
    answer = solve(N)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9156
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
    int ans = 0;
    int bc = min(b,c);
    ans += 2 * bc;
    b -= bc;
    c -= bc;
    int ac = min(a,c);
    ans += ac;
    a -= ac;
    c -= ac;
    ans += b;
    if (c) ans += 1;
	cout << ans << endl;
}


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

const int MAXN = 310;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

char s[310];
int dp[MAXN][MAXN][MAXN], K, n, ans;

inline void chkmax(int &cur, int val) {
	if(val > cur) cur = val;
}

int main() {

	scanf("%s", s+1);
	K = read();
	n = strlen(s+1);
	if(n == 1) {
		printf("1\n");
		return 0;
	}
	int i, j, k, d;
	//dp[1][n][0] = s[1] == s[n] ? 2 : 0;
	//dp[1][n][1] = 2;
	dp[0][n+1][0] = 0;
	for(d = n+1; d > 1; d--) 
		for(i = 0; i+d <= n+1; i++) {
			j = i+d;
			for(k = 0; k <= K; k++) {
				chkmax(dp[i][j-1][k], dp[i][j][k]);
				chkmax(dp[i+1][j][k], dp[i][j][k]);
				if(i + 1 != j-1) {
					chkmax(dp[i+1][j-1][k], dp[i][j][k]+(s[i+1] == s[j-1] ? 2 : 0));
					chkmax(dp[i+1][j-1][k+1], dp[i][j][k]+2);
				}
				else chkmax(dp[i+1][j-1][k], dp[i][j][k]+1);
				chkmax(ans, dp[i][j][k]);
			}
		}
	for(i = 1; i < n; i++) 
		for(k = 0; k <= K; k++) 
			chkmax(ans, dp[i][i+1][k]);
	for(i = 1; i <= n; i++)
		for(k = 0; k <= K; k++)
			chkmax(ans, dp[i][i][k]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 114560
#%%
n = int(input())
a = [[] for i in range(n)]
for i in range(n):
    tmp = [int(input()), i]
    a[i] = tmp

b = sorted(a)
#print(b)

c = []
ans = 0
for i in range(n):
    c.append(b[i][1])
    ans += (i - c[i])%2
ans //= 2

print(ans)



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

int main(){
  char s[3];
  bool abc[3];
  for(int i=0;i<3;i++) abc[i] = false;
  cin >> s;
  for(int i=0;i<3;i++){
    abc[s[i]-'a'] = true;
  }
  if(abc[0] && abc[1] && abc[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import math

N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]

rtot = 0
temp = 1

for i in range(N):
    # temp *= i + 1
    for j in range(N):
        if i == j:
            continue
        rtot += math.sqrt( (xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2 )

# res = rtot / temp
ans = rtot / N

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
//////////////////////////////////

vector<pair<char, int>> RunLengthEncoding(string data) {
    int n = data.size();
    vector<pair<char, int>> ret;
    char c = data[0];
    int num = 1;
    for(int i=1; i<n; i++) {
        if(data[i] == c) {
            num++;
        }else{
            ret.push_back({c, num});
            c = data[i];
            num = 1;
        }
    }
    ret.push_back({c, num});
    // for(int i=0; i<ret.size(); i++) {
    //     cerr << ret[i].first << " " << ret[i].second << endl;
    // }
    return ret;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    // RRRLLLRRLLRL
    auto r = RunLengthEncoding(s);
    int pos = 0;
    vector<int> a(n, 0);
    for(int i=0; i<r.size(); i+=2) {
        int tmp = r[i].second + r[i+1].second;
        if(tmp%2 == 0) {
            a[pos+r[i].second-1] = tmp/2;
            a[pos+r[i].second] = tmp/2;
        }else{
            if(r[i].second % 2 == 1){
                a[pos+r[i].second-1] = tmp - tmp/2;
                a[pos+r[i].second] = tmp/2;
            }else{
                a[pos+r[i].second-1] = tmp/2;
                a[pos+r[i].second] = tmp - tmp/2;
            }
        }
        pos += tmp;
    }

    for(int i=0; i<n; i++) {
        cout << a[i] << " ";
    }
    cout << endl;

    return 0;
}




// EOF


Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

int main(void){
    
    ll H,W,K;
    vector<string> A;
    string a;
    
    ll sy,sx;
    cin >> H >> W >> K;
    REP(i,H){
        cin >> a;
        A.push_back(a);
        REP(j,W){
            if(a[j]=='S'){
                sy=i;sx=j;
            }
        }
    }
    
    ll D[810][810];
    REP(i,810){
        REP(j,810){
            D[i][j]=INF;
        }
    }
    D[sy][sx]=0;
    
    ll dx[4]={1,0,-1,0};
    ll dy[4]={0,1,0,-1};
    
    queue<pair<pair<ll,ll>,ll>> Q;
    Q.push({{sy,sx},0});
    
    while(!Q.empty()){
        ll y=Q.front().first.first;
        ll x=Q.front().first.second;
        ll c=Q.front().second;
        Q.pop();
        if(c>=K)continue;
        
        REP(k,4){
            ll ny=y+dy[k];
            ll nx=x+dx[k];
            
            if(!(0<=nx&&nx<W))continue;
            if(!(0<=ny&&ny<H))continue;
            if(D[ny][nx]!=INF)continue;
            if(A[ny][nx]=='#')continue;
            
            D[ny][nx]=c+1;
            Q.push({{ny,nx},c+1});
        }
        
    }
    
    /*
    REP(i,H){
        REP(j,W){
            cout << (D[i][j]==INF?9:D[i][j]) << " ";
        }cout << endl;
    }
    */
    
    ll Ans=INF;
    REP(i,H){
        REP(j,W){
            if(D[i][j]==INF)continue;
            ll u = min({i,H-1-i,j,W-1-j});
            u = (u+K-1)/K;
            Ans = min(Ans,u);
            
            //cout << i MM j MM u << endl;
        }
    }
    cout << Ans+1 << endl;
    
    return 0;
}



Measured memory_bytes: 9464
def resolve():
    S = list(input())
    S.reverse()
    substr = ''
    p = ['dream', 'dreamer', 'erase', 'eraser']
    for i in S:
        substr = i + substr
        if substr in p:
            substr = ''
    ans = 'YES' if substr == '' else 'NO'
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 4044
#include <stdio.h>
int main (){
long long int x,a,b;
scanf("%lld %lld %lld",&x,&a,&b);
if ((b-a)<=0){
printf("delicious");
}else if((b-a)<=x){
printf("safe");
}else{
printf("dangerous");
}
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

struct Combination {
    vector<lint> fac, finv, inv;
    Combination(lint maxN) : fac(maxN + 100), finv(maxN + 100), inv(maxN + 100) {
        maxN += 100; // for safety
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1]            = 1;
        for (lint i = 2; i <= maxN; ++i) {
            fac[i]  = fac[i - 1] * i % mod;
            inv[i]  = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    lint operator()(lint n, lint k) {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint h, w, a, b;
    cin >> h >> w >> a >> b;
    Combination nCk(200000);
    mint ret = 0;
    for (int i = b; i < w; ++i) {
        ret += nCk(h - 1 - a + i, i) * nCk(a - 1 + w - 1 - i, a - 1);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define vsort(v) sort((v).begin(),(v).end())
#define vrsort(v) sort((v).rbegin(),(v).rend())
#define vreverse(v) reverse((v).begin(),(v).end())
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define INF 1998021900
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll n;cin>>n;vll h(n);ain(i,n,h);
  //caricurate
  ll mx=-3;ll i=0;
  if(n==1){cout<<0<<endl;return 0;}
  
  while(i<n-1){
    ll j=0;
    while(h[i]>=h[i+1]){j++;i++;if((i+1)==n){break;}}
    if(j>mx){mx=j;}
    i++;
  }
  //output
  cout<<mx<<endl;
}

Measured memory_bytes: 1152
#include <stdio.h>

int main(void)
{
	int n;
	int a[3];
	int i, j;
	int min, flag;
	
	scanf("%d", &n);

	min = 1000000000;
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if (min > a[i]){
			min = a[i];
		}
	}
	
	for (i = 1; i <= min; i++){
		flag = 0;
		for (j = 0; j < n; j++){
			if ((a[j] % i) == 0){
				flag++;
			}
			if (flag == n){
				printf("%d\n", i);
			}
		}
	}
	
	return (0);
}

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

typedef long long int ll;
typedef long long unsigned int ull;
typedef long double ld;
typedef vector<int> vr;
typedef pair<int, int> pr;
#define pb push_back
#define ff first
#define ss second
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433
//cout << fixed << setprecision(2);


int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k, n;
    cin >> n >> k;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int sum = 0;
    for(int i = 0; i < k; i++){
        sum += v[i];
    }
    cout << sum << endl;
    return 0;
}


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

int main()
{
    int a[5];
    for(int &i:a)
    {
        cin >> i;
    }
    for(int i=0; i< 5 ;i++)
    {
        if(a[i] == 0)
        {
            cout << i+1;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3628
// B.

#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	sort(p.rbegin(), p.rend());
	int ans = accumulate(p.begin(), p.end(), 0LL) - p[0] / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string ans[10][10]={
	{
		"0",
		"0 1",
		"0 1 2",
		"0 1 2 3",
		"0 1 2 3 4",
		"0 1 2 3 4 5",
		"0 1 2 3 4 5 6",
		"0 1 2 3 4 5 6 7",
		"0 1 2 3 4 5 6 7 8",
		"0 1 2 3 4 5 6 7 8 9"
	},
	{
		"1 0",
		"1",
		"1 2",
		"1 2 3",
		"1 2 3 4",
		"1 2 3 4 5",
		"1 2 3 4 5 6",
		"1 2 3 4 5 6 7",
		"1 2 3 4 5 6 7 8",
		"1 2 3 4 5 6 7 8 9"
	},
	{
		"2 1 0",
		"2 1",
		"2",
		"2 3",
		"2 3 4",
		"2 3 4 5",
		"2 3 4 5 6",
		"2 3 4 5 6 7",
		"2 3 4 5 6 7 8",
		"2 3 4 5 6 7 8 9"
	},
	{
		"3 2 1 0",
		"3 2 1",
		"3 2",
		"3",
		"3 4",
		"3 4 5",
		"3 4 5 6",
		"3 4 5 6 7",
		"3 4 5 6 7 8",
		"3 4 5 6 7 8 9"
	},
	{
		"4 3 2 1 0",
		"4 3 2 1",
		"4 3 2",
		"4 3",
		"4",
		"4 5",
		"4 5 6",
		"4 5 6 7",
		"4 5 6 7 8",
		"4 5 6 7 8 9"
	},
	{
		"5 4 3 2 1 0",
		"5 4 3 2 1",
		"5 4 3 2",
		"5 4 3",
		"5 4",
		"5",
		"5 6",
		"5 6 7",
		"5 6 7 8",
		"5 6 7 8 9"
	},
	{
		"6 7 8 9 5 4 3 2 1 0",
		"6 7 8 9 5 4 3 2 1",
		"6 7 8 9 5 4 3 2",
		"6 7 8 9 5 4 3",
		"6 7 8 9 5 4",
		"6 7 8 9 5",
		"6",
		"6 7",
		"6 7 8",
		"6 7 8 9"
	},
	{
		"7 8 9 5 4 3 2 1 0",
		"7 8 9 5 4 3 2 1",
		"7 8 9 5 4 3 2",
		"7 8 9 5 4 3",
		"7 8 9 5 4",
		"7 8 9 5",
		"7 8 9 5 4 3 2 1 0 1 2 3 4 5 6",
		"7",
		"7 8",
		"7 8 9"
	},
	{
		"8 9 5 4 3 2 1 0",
		"8 9 5 4 3 2 1",
		"8 9 5 4 3 2",
		"8 9 5 4 3",
		"8 9 5 4",
		"8 9 5",
		"8 9 5 4 3 2 1 0 1 2 3 4 5 6",
		"8 9 5 4 3 2 1 0 1 2 3 4 5 6 7",
		"8",
		"8 9"
	},
	{
		"9 5 4 3 2 1 0",
		"9 5 4 3 2 1",
		"9 5 4 3 2",
		"9 5 4 3",
		"9 5 4",
		"9 5",
		"9 5 4 3 2 1 0 1 2 3 4 5 6",
		"9 5 4 3 2 1 0 1 2 3 4 5 6 7",
		"9 5 4 3 2 1 0 1 2 3 4 5 6 7 8",
		"9"
	}
};
	int n,a,b;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		cout<<ans[a][b]<<endl;
	}
	return 0;
}

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

void fnTrace(const vector<int> &a_cnrviSort)
{
  for (int i = 0; i < a_cnrviSort.size(); i++)
  {
    if (i) cout << " ";
    cout << a_cnrviSort[i];
  }
  cout << endl;
}

void fnInsertionSort(vector<int> &a_rviSort)
{
  for (int ixSorting = 1; ixSorting < a_rviSort.size(); ixSorting++)
  {
    int iTarget = a_rviSort[ixSorting];
    int ixSorted = ixSorting - 1;

    while (ixSorted >= 0               &&
           iTarget  < a_rviSort[ixSorted])
    {
      a_rviSort[ixSorted + 1] = a_rviSort[ixSorted];
      ixSorted--;
    }
    a_rviSort[ixSorted + 1] = iTarget;
    fnTrace(a_rviSort);
  }
}

int main()
{
  vector<int> viSort;
  int iMaxSize;
  
  cin >> iMaxSize;
  for (int i = 0; i < iMaxSize; i++)
  {
    int iNum;
    cin >> iNum;
    viSort.push_back(iNum);
  }

  fnTrace(viSort);
  fnInsertionSort(viSort);

  return 0;
}

Measured memory_bytes: 1216
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << "{";
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i] << ",}"[i == vec.size() - 1];
  }
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << "{" << p.first << " " << p.second << "}";
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

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

  int h, w, a, b; cin >> h >> w >> a >> b;

  char ans[h][w];

  rep(i, h) {
    rep(j, w) {
      ans[i][j] = '1';
    }
  }

  for (int i = 0; i < b; ++i) {
    for (int j = 0; j < a; ++j) {
      ans[i][j] = '0';
    }
  }

  for (int i = b; i < h; ++i) {
    for (int j = a; j < w; ++j) {
      ans[i][j] = '0';
    }
  }

  rep(i, h) {
    rep(j, w) {
      cout << ans[i][j];
    }
    cout << '\n';
  }


  return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b ,c ,d;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b ){
        d = b;
        b = a;
        a = d;
    }
    if(b>c){
        d= c;
        c =b;
        b =d;
    }
if(a>b){
    d= b;
    b = a;
    a = d;
}
    printf("%d %d %d\n",a, b,c);
    return 0;
}



Measured memory_bytes: 2732
#include <cstdio>

int a[5];
int b[4];
int main(){
    for(int i=0;i<3;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        a[x]++;
        a[y]++;
    }
    int flag = 0;
    for(int i=1;i<=4;i++){
        b[a[i]]++;
    }
    printf("%s\n", b[1] == 2 && b[2] == 2 ? "YES" : "NO");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c[100001],d[100001];
	cin>>a>>b;
	for (int i=0;i<a;i++)
		d[i]=1;
	for (int i=0;i<a;i++)
		cin>>c[i];
	int cnt=a;
	for (int i=0;i<b;i++)
	{
		int e,f;
		cin>>e>>f;
		if (d[e-1]==1&&c[e-1]<=c[f-1])
		{
			cnt--;
			d[e-1]=0;
		}
		if (d[f-1]==1&&c[f-1]<=c[e-1])
		{
			cnt--;
			d[f-1]=0;
		}
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 4348
#include <iostream>
#include <vector>

int main(int argc, char const* argv[])
{
    int n;
    std::cin >> n;
    std::vector<int> vec = std::vector<int>();
    vec.reserve(n);
    int count_one = 0;
    for (int i = 0; i < n; i++) {
        int x;
        std::cin >> x;
        vec.push_back(x);
        if (x == 1) count_one++;
    }
    if(count_one == 0) {
        std::cout << "-1" << std::endl;
        return 0;
    }
    int count = 0;
    int left = 1;
    for (auto iter = std::begin(vec); iter != std::end(vec); iter++) {
        if (*iter == left) {
            left++;
        } else {
            count++;
        }
        if (count > n) {
            std::cout << "-1" << std::endl;
            return 0;
        }
    }
    std::cout << count << std::endl;
    return 0;
}


Measured memory_bytes: 1024
n = gets.chomp.to_i

one = 9-1+1
thr = 999-100+1
fiv = 99999 - 10000 + 1
result = 0
case n.to_s.length
when 6 then
  result = one + thr + fiv
when 5
  result = one + thr + fiv - (99999 - n)
when 4 then
  result = one + thr
when 3
  result = one + thr - (999 - n)
when 2 then
  result = one
when 1 then
  result = one - (9 - n)
end
puts result

Measured memory_bytes: 3836
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;
typedef long long ll;

int n, X;
ll pre;

inline void cmax(ll &x, ll y) {
    if (x < y) x = y;
}

struct Node { ll b, l, r;} x[N];

inline bool cmp(Node a, Node b) {
    return a.b * a.l + (X - a.b) * a.r > b.b * b.l + (X - b.b) * b.r;
}

inline bool check(ll now) {
    ll k = now / X, t = now % X;
    if (k > n) return true;
    ll res = pre;
    for (int i = 1; i <= k; ++i)
        res += x[i].b * x[i].l + (X - x[i].b) * x[i].r;
    ll tmp = 0;
    for (int i = 1; i <= k; ++i) {
        cmax(tmp, min(t, x[i].b) * x[i].l + max(0LL, t - x[i].b) * x[i].r - (x[i].b * x[i].l + (X - x[i].b) * x[i].r) + (x[k + 1].b * x[k + 1].l + (X - x[k + 1].b) * x[k + 1].r));
    }
    for (int i = k + 1; i <= n; ++i)
        cmax(tmp, min(t, x[i].b) * x[i].l + max(0LL, t - x[i].b) * x[i].r);
    res += tmp;
    return res >= 0;
}

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n >> X;
    for (int i = 1; i <= n; ++i)
        scanf("%lld%lld%lld", &x[i].b, &x[i].l, &x[i].r), pre -= x[i].b * x[i].l;
    sort(x + 1, x + n + 1, cmp);
    ll l = 0, r = 1e10;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (!check(mid)) l = mid + 1;
        else r = mid;
    }
    printf("%lld\n", l);
    return 0;
}


Measured memory_bytes: 4352
n, k = map(int, input().split(' '))
a = [int(i) for i in input().split(' ')]

dp = [float('inf')] * n
dp[0] = 0
for i in range(1, n):
    for x in range(1, min(i, k) + 1):
        z = abs(a[i - x] - a[i]) + dp[i - x]
        if dp[i] > z:
            dp[i] = z
print(dp[-1])

Measured memory_bytes: 54624
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_
void debug_out() {cerr << endl;}
template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl;
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    string s; cin >> s;
    if (s.back() == 's') s += "es";
    else s += "s";
    cout << s << '\n';
    return 0;
}

Measured memory_bytes: 3624
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

at = [0]
for i in range(len(A)):
    at.append(A[i])
    if i > 0:
        at[-1] += at[i]

bt = [0]
for i in range(len(B)):
    bt.append(B[i])
    if i > 0:
        bt[-1] += bt[i]


n = 0
time = 0


for i, a in enumerate(at):
    if a > K:
        break
    l = 0
    r = len(bt)-1
    while r - l > 1:
        m = (l+r)//2
        if bt[m] < K-a:
            l = m
        else:
            r = m
    if bt[r] <= K -a:
        b = bt[r]
    else:
        r -= 1
        b = bt[r]
    if i + r >= n:
        n = i + r

print(n)


Measured memory_bytes: 48456
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int ds=0,res=0;
  string S;
  cin >> S;
  REP(i,S.size()){
    res += S[i]-'0';
  }
  REP(i,S.size()){
    ds = 0;
    if(S[i] != '0'){
      for(int j=0;j<S.size();j++){
        if(j == i){
          ds += S[j] - '0' - 1;
     
        }else if(j > i){
          ds += 9;
     
        }else{
          ds += S[j] - '0';
     
        }
      }
     
      res = max(ds,res);
    }
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


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

int main()
{
    string x;
    cin >>x;
  	if(x.length()<=2){
    	cout<<0<<endl; 
      	return 0;
    }
    int matubi = stoi(x.substr(x.length()-2,2));
    int sonota = stoi(x.substr(0,x.length()-2));
    if(sonota*5>=matubi){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;   
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
d1d2 = [map(int, input().split()) for _ in range(n)]
d1, d2 = [list(i) for i in zip(*d1d2)]
h = 'No'
for i in range(n):
    if i > 1:
        if d1[i] == d2[i]:
            if d1[i-1] == d2[i-1]:
                if d1[i-2] == d2[i-2]:
                    h = 'Yes'
                    break
print(h)

Measured memory_bytes: 9176
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a,T b){a=max(a,b);}
template<typename T> inline void minimize(T &a,T b){a=min(a,b);}
template<typename T> inline bool middle(T a,T b,T c){return b<=a && a<=c;}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
inline void outputVI(VI x){REP(i,SI(x)){cout << three(i," ","") << x[i];}OUT("");}
const int SIZE1=1e6+1000;
const int SIZE2=5010;
const int SIZE3=400;
const int SIZE=SIZE1;
const LL p=7+1e9;
const LL INF=1LL<<60;
const long double EPS=1e-7;
string s;
ut N,M,K,X,L,Y;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE],nums[SIZE],maps[SIZE2][SIZE2],answer=zero;
 
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////////////////////////////////////////////////////////////////////////////////////
void init(){
 	
}
LL solve(){
	cin >> N >> Y;
	Y/=1000;
	int miner=INF;
	REP(i,N+1)
		REP(j,N+1){
			if(i*9+j*4+N==Y and N-i-j>=0){
				cout << i <<" " << j <<" "<< N-i-j << endl;
				return 0;
			}
		}
	cout << -1 << " " << -1 << " " << -1 << endl; 
	return 0;
}
signed main(){
	solve();
	return 0;
}

Measured memory_bytes: 24448
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=100005;
int n,L,T,x,w,a[N],id;

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

int main()
{
	n=getint(),L=getint(),T=getint();
	rep(i,1,n)
	{
		x=getint(),w=getint()==2?-1:1;
		int dis=x+w*T;
		if(dis>0) id=(id+dis/L)%n;
		if(dis<0) id=(id+(dis+1)/L-1)%n;
		a[i]=(dis%L+L)%L;
	}
	sort(a+1,a+1+n),id=(id+n)%n;
	rep(i,id+1,n) printf("%d\n",a[i]);
	rep(i,1,id) printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 1536
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
sum=0
k=int(input())
for i in range(1,k+1):
	for j in range(i,k+1):
		for l in range(j,k+1):
			if i==j and j==l:
				sum+=gcd(i,j,l)
			elif i==j or j==l or i==l:
				sum+=(gcd(i,j,l))*3
			else:
				sum+=(gcd(i,j,l))*6
print(sum)

Measured memory_bytes: 9632
#include <stdio.h>
int main() {
  int n,k;
  char s[n];
  scanf("%d%s%d",&n,s,&k);
k=k-1;
  for(int i=0;i<n;i++){
    if(s[i]==s[k]){
    printf("%c",s[i]);
    }else{
    printf("*");
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int main()
{
	std::ios::sync_with_stdio(false);
	int N, Ma, Mb;
	scanf("%d %d %d", &N, &Ma, &Mb);
	std::vector<int>a(N), b(N), c(N);
	rep(i, N) scanf("%d %d %d", &a[i], &b[i], &c[i]);
	std::vector<std::vector<std::vector<int>>> memo(41, std::vector<std::vector<int>>(412, std::vector<int>(412, -1)));

	std::function<int(int,int,int)> dp([&](int n, int aa, int bb)->int {
		if (aa > 0 && bb > 0 && aa*Mb / Ma == bb && bb*Ma / Mb == aa) return 0;
		if (n == N) return 114514;
		if (memo[n][aa][bb] != -1) return memo[n][aa][bb];
		int res1 = dp(n + 1, aa + a[n], bb + b[n]) + c[n];
		int res2 = dp(n + 1, aa, bb);
		return memo[n][aa][bb] = std::min(res1, res2);
	});

	printf("%d\n", dp(0, 0, 0) >= 114514 ? -1 : dp(0, 0, 0));
	return 0;
}

Measured memory_bytes: 28800
import math
target = int(input())
if 0 < target % 11 < 6:
    print(math.floor(target / 11 * 2) + 1)
elif target % 11 == 6:
    print(math.floor(target / 11 * 2))
else:
    print(math.ceil(target / 11 * 2))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
int d(lli k){
	if(k<10)return 1;
	return d(k/10)+1;
}

int main(){
	lli s;
	cin>>s;
	int n=d(s);
  if(n==1){cout<<s;return 0;}
  if(s==9999999999){cout<<12656242944;return 0;}
	lli ans=0;
	rep(x,pow(2,n-1)){
		lli pat=s;
		rep(i,n-1){
			if((x>>i)&1==1){
				ans+=pat/pow(10,n-1-i);
				pat=pat%(lli)pow(10,n-1-i);
			}
		}
      ans+=pat;
	}
	cout<<ans;
}

Measured memory_bytes: 256