akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int x;
    in(x);
    yn(x>=30);
}

Measured memory_bytes: 3664
a,b,c,x,y=[int(i) for i in input().split()]

sum_list=[]


max_c=max(x,y)

#ABセットをi組頼む
for i in range(max_c+1):
    
    #Cのみ
    if i>=x and i>=y:
        sum=2*c*i
        
    #CとA
    elif i<x and i>=y:
        sum=2*c*i+a*(x-i)
    
    #CとB   
    elif i>=x and i<y:
        sum=2*c*i+b*(y-i)
    
    #CとAとB
    else:
        sum=2*c*i+a*(x-i)+b*(y-i)
        
    sum_list.append(sum)
    
    
print(min(sum_list))

Measured memory_bytes: 12868
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N;
    int c = N;
    int s = 0;
    while (c)
    {
        s += c % 10;
        c /= 10;
    }
    if(N % s == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import bisect 
from itertools import accumulate

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
ans = 0

xOK = A[0]*2
xNG = A[-1]*2 + 1
nx = 0
while xOK+1 < xNG:
    x = (xOK + xNG)//2
    nx = 0
    for a in A:
        nx += N-(bisect.bisect_left(A,x-a))
        if nx >= M:
            xOK = x
            break
    else:
        xNG = x

S=[0]+list(accumulate(A))

ans = 0
nnx = 0        
for a in A:
    nx = bisect.bisect_right(A,xOK-a)
    ans += a*(N-nx) + (S[N]-S[nx])
    nnx += (N-nx)
ans += xOK*(M-nnx)
        
    
print(ans)

Measured memory_bytes: 14368
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n;
P p[214514];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> p[i].first; p[i].second = i;
	}
	sort(p, p + n);
	set<int>st;
	st.insert(-1); st.insert(n);
	int ans = 0;
	rep(i, n) {
		auto itlo = st.lower_bound(p[i].second);
		auto itlo_ = itlo; itlo--;
		int le = *itlo, ri = *itlo_;
		ans += p[i].first * (p[i].second - le) * (ri - p[i].second);
		st.insert(p[i].second);
	}
	cout << ans << endl;
}


Measured memory_bytes: 13312
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<(a*b>c*d?a*b:c*d)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i, n) rep (i, n)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
template<typename T,typename U> ostream& operator<< (ostream& out, const pair<T,U>& val){return out << "(" << val.F << ", " << val.S << ")";}
template<class T> ostream& operator<< (ostream& out, const vector<T>& val){out << "{";rep(i,SZ(val)) out << (i?", ":"") << val[i];return out << "}";}
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

int p,q;
string P[1000],Q[100];

bool ok(int r,int c,int s){
  int ro,rc,co,cc,so,sc;
  ro=rc=co=cc=so=sc=0;
  rep(i,p){
    int le=r*(ro-rc)+c*(co-cc)+s*(so-sc);
    string pe(le,'.');
    if(P[i].substr(0,SZ(pe))!=pe) return false;
    if(P[i][le]=='.') return false;
    ro += count(ALL(P[i]),'(');
    rc += count(ALL(P[i]),')');
    co += count(ALL(P[i]),'{');
    cc += count(ALL(P[i]),'}');
    so += count(ALL(P[i]),'[');
    sc += count(ALL(P[i]),']');
  }
  return true;
}

void solve(){
  rep(i, p) cin >> P[i];
  rep(i, q) cin >> Q[i];

  set<pair<int,PI > > rcs;
  for(int r=1;r<=20;++r)
    for(int c=1;c<=20;++c)
      for(int s=1;s<=20;++s)
        if(ok(r,c,s)){
          //cout << r << ' ' << c << ' ' << s << endl;
          rcs.insert(mp(r,mp(c,s)));
        }
  set<int> ans[q];
  FOR(it,rcs){
    int r=it->F;
    int c=it->S.F;
    int s=it->S.S;
    int ro,rc,co,cc,so,sc;
    ro=rc=co=cc=so=sc=0;
    rep(i,q){
      ans[i].insert(r*(ro-rc)+c*(co-cc)+s*(so-sc));
      ro += count(ALL(Q[i]),'(');
      rc += count(ALL(Q[i]),')');
      co += count(ALL(Q[i]),'{');
      cc += count(ALL(Q[i]),'}');
      so += count(ALL(Q[i]),'[');
      sc += count(ALL(Q[i]),']');
    }
  }
  
  rep(i,q){
    if(i) cout << ' ';
    if(ans[i].size()==1) cout << *ans[i].begin();
    else cout << -1;
  }
  cout << endl;
}

int main(int argc, char *argv[])
{
  while(cin >> p >> q && p && q) solve();
  return 0;
}

Measured memory_bytes: 1744
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

const int WHITE=0, GRAY=1, BLACK=2;

struct DFS {
    int n;
    vector<vector<int>> g;
    vector<int> discover;
    vector<int> finish;
    vector<int> state;
    int time = 1;
    
    DFS(int n):n(n) {
        g.assign(n, vector<int>());
        discover.assign(n, -1);
        finish.assign(n, -1);
        state.assign(n, WHITE);
    }
    
    void addEdge(int u, int v) {
        g[u].push_back(v);
    }
    
    void solve() {
        for (int i = 0; i < n; i++) {
            if (state[i] == WHITE) {
                dfs(i);
            }
        }
    }
    
    void dfs(int u) {
        state[u] = GRAY;
        discover[u] = time++;
        for (int v : g[u]) {
            if (state[v] == WHITE) {
                dfs(v);
            } 
        }
        finish[u] = time++;
        state[u] = BLACK;
    }
    
    void print() {
        for (int i = 0; i < n; i++) {
            cout << i << ":";
            for (int v : g[i]) {
                cout << v << " ";
            }
            cout << endl;
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    DFS dfs(n);
    for (int i = 0; i < n; i++) {
       int u, k;
       cin >> u >> k;
       u--;
       for (int j = 0; j < k; j++) {
           int v;
           cin >> v;
           v--;
           dfs.addEdge(u, v);
       }
    }
    
    //dfs.print();
    
    dfs.solve();
    
    for (int i = 0; i < n; i++) {
        cout << (i + 1) <<  " " << dfs.discover[i] << " " << dfs.finish[i] << endl; 
    }
    
    return 0;
}

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

int N, Y;

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

    int ans = 0;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            int k = N - i - j;
            if( 0 <= k && i * 10000 + j * 5000 + k * 1000 == Y ){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

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

void solve() 
{
    ll n;cin>>n;
    vector<ll> arr(100005,0);
    ll sum = 0;
    for(ll i = 0;i<n;i++){
        ll temp;cin>>temp;
        ++arr[temp];
        sum+=temp;
    }
    ll q;cin>>q;
    for(ll i = 0;i<q;i++)
    {
        ll a,b;cin>>a>>b;
        ll x = arr[a];
        sum -= (x * a);
        sum += (x * b);
        arr[a] = 0;
        arr[b] += x;
        cout << sum << endl;
    }
} 

//driver
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll test = 1;
    // cin>>test;
    for(ll i = 0;i<test;i++)
    {
        solve();
    }
}    

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> a(N);
  
  for ( int i = 0; i < N; i++ ) {
    cin >> a.at(i);
  }
  
  int next = 0;
  int count = 0;
  for ( int i = 0; i < N; i++ ) {
    count++;
    
    if ( a.at(next) == 2 ) {
      next = a.at(next) - 1;
      break;
    }
    next = a.at(next) - 1;
  }
  
  if ( next == 1 ) {
    cout << count << endl;
  }
  else {
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 640
import sys
S = input()
A = S[0]
B = S[1]
C = S[2]
D = S[3]
if int(A) + int(B) + int(C) + int(D) == 7:
    print(A + '+' + B + '+' + C + '+' + D + '=7')
    sys.exit()
if int(A) - int(B) + int(C) + int(D) == 7:
    print(A + '-' + B + '+' + C + '+' + D + '=7')
    sys.exit()
if int(A) + int(B) - int(C) + int(D) == 7:
    print(A + '+' + B + '-' + C + '+' + D + '=7')
    sys.exit()
if int(A) - int(B) - int(C) + int(D) == 7:
    print(A + '-' + B + '-' + C + '+' + D + '=7')
    sys.exit()
if int(A) + int(B) + int(C) - int(D) == 7:
    print(A + '+' + B + '+' + C + '-' + D + '=7')
    sys.exit()
if int(A) - int(B) + int(C) - int(D) == 7:
    print(A + '-' + B + '+' + C + '-' + D + '=7')
    sys.exit()
if int(A) + int(B) - int(C) - int(D) == 7:
    print(A + '+' + B + '-' + C + '-' + D + '=7')
    sys.exit()
if int(A) - int(B) - int(C) - int(D) == 7:
    print(A + '-' + B + '-' + C + '-' + D + '=7')
    sys.exit()

Measured memory_bytes: 38256
def gcd(a,b)
  if b == 0  
    return a
  end  
  gcd(b, a % b)
end  

n,x = gets.split.map(&:to_i)
xs  = gets.split.map{|e| e.to_i - x}
d = gcd(xs[0], gcd(xs[1]||xs[0] ,xs[2]||xs[0])).abs

d = xs[0]
xs.each do |e|
    d = gcd(d,e)
end
puts d.abs


Measured memory_bytes: 8452
#include <stdio.h>

char a[105][105];

int main(){

	int H,W;

	scanf("%d %d",&H,&W);

	int i,j;

	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
		scanf(" %c",&a[i][j]);
		}
	}

	for(i=0;i<H+2;i++){
		for(j=0;j<W+2;j++){
			if(i==0 || i==H+1 || j==0 || j==W+1){printf("#");}
			else{printf("%c",a[i-1][j-1]);}
		}
		printf("\n");
	}


	return 0;
}

Measured memory_bytes: 128
fn main() {
    let (a, b, c): (usize, usize, usize) = (read(), read(), read());

    if a == b {
        if a != c && b != c {
            println!("Yes");
            return;
        }
    } else {
        if a == c || b == c {
            println!("Yes");
            return;
        }
    }
    println!("No");
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let token: String = cin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int X; scanf("%d", &X);
  int sum = 0, ans = 0, d = 1;
  while (sum < X) {
    sum += d++;
    ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    ll H,W,N,A,B;
    cin >> H >> W >> N;
    map<pair<ll,ll>, ll> count;
    
    REP(i,0,N){
        cin >> A >> B;
        A--;B--;
        REP(y,0,3){
            REP(x,0,3){
                if((A-y)<0 || (A-y+2)>=H || (B-x+2)>=W || (B-x)<0) continue;
                count[make_pair(A-y, B-x)]++;
            }
        }
    }

    map<int,int> ansmap;
    for(auto itr=count.begin(); itr!=count.end(); itr++){
        ansmap[itr->second]++;
    }

    ll zero=(H-2)*(W-2);
    for(auto itr=ansmap.begin(); itr!=ansmap.end(); itr++){
        zero -= itr->second;
    }
    P(zero);
    REP(i,1,10){
        P(ansmap[i]);
    }
}

Measured memory_bytes: 56448
/* 2018-01-07-17.30.16 */

#include<bits/stdc++.h>
#define ll long long int
#define N 100010
using namespace std;

int main()
{
    int n,y;
    scanf("%d %d",&n,&y);
    y/=1000;
    int temp1=5*n-y,temp2=y-n;
    if(y<n)
    {
        printf("-1 -1 -1\n");
        return 0;
    }
    int i=0;
    while(temp2>=9*i)
    {
        if((temp1+5*i)%4==0 && (temp2-9*i)%4==0 && temp1+5*i>=0)
        {
            printf("%d %d %d\n",i,(temp2-9*i)/4,(temp1+5*i)/4);
            return 0;
        }
        i++;
    }
    printf("-1 -1 -1\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>

using namespace std;

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

int main()
{
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vector<int> ans(N, 0);
  for (int i = 1; i <= X - Y + N; i++)
  {
    ans[i] += X - Y + N - i + 1;
  }
  if ((Y - X + 1) % 2 == 0)
  {
    for (int i = 1; i <= (Y - X + 1) / 2 - 1; i++)
    {
      ans[i] += Y - X + 1;
    }
    ans[(Y - X + 1) / 2] += (Y - X + 1) / 2;
  }
  else
  {
    for (int i = 1; i <= (Y - X) / 2; i++)
    {
      ans[i] += Y - X + 1;
    }
  }
  for (int i = X + 1; i <= Y - 1; i++)
  {
    for (int j = 1; j <= X; j++)
    {
      ans[min(i - X, Y - i + 1) + j]++;
    }
  }
  for (int i = X + 1; i <= Y - 1; i++)
  {
    for (int j = 1; j <= N - Y - 1; j++)
    {
      ans[min(Y - i, i - X + 1) + j]++;
    }
  }

  ans[1]--;

  // int sum__ = 0;
  // for (int i = 1; i < N; i++)
  // {
  //   sum__ += ans[i];
  // }
  // cout << sum__ << endl;

  for (int i = 1; i < N; i++)
  {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])
negative_count = np.sum(A<0)

abs_A = list(map(abs, A))
if(negative_count%2==0):
    print(int(np.sum(abs_A)))
else:
    print(int(np.sum(abs_A) - (min(abs_A)*2)))


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

#define ll long long

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll x,n;
    cin>>x>>n;
  
    if(x<n)
      cout<<0<<endl;
    else
      cout<<10<<endl;
    
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int X = sc.nextInt();
      int A = sc.nextInt();
      if(X<A){
        System.out.println(0);
      }else{
        System.out.println(10);
      }
    }
}

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

public class Main {

    public static void main(String[] args) throws IOException {
        init();

        int n = nextInt();
        long m = nextLong();
        int v = nextInt(), p = nextInt();

        ArrayList<Long> problemScores = new ArrayList<>();
        for (int i = 0; i < n; i++) problemScores.add(nextLong());

        problemScores.sort(Comparator.reverseOrder());
        Map<Long, Integer> firstPosition = new HashMap<>();
//        System.out.println(problemScores);
        for (int i = n - 1; i >= 0; i--) {
            firstPosition.put(problemScores.get(i), i);
        }
        long toBeat = problemScores.get(p - 1);
        long can = 0;
        int leverage = p - 1;
        long totalLeverage = 0L;
        int leverageContributors = 0;
        long prevScore = -1;
        for (Long score : problemScores) {
            if (score >= toBeat) can++;
            else {
                long canIncrease = p - 1 + n - firstPosition.get(score);
                long remainder = m * Math.max(0, v - canIncrease);
                totalLeverage -= (prevScore - score)*leverageContributors;
                while (leverage < firstPosition.get(score)) {
                    totalLeverage += (score + m - problemScores.get(leverage));
                    leverage++;
                    leverageContributors++;
                }
//                System.out.println(score + " " + totalLeverage + " " + remainder);
                if (totalLeverage >= remainder && score + m >= toBeat) can++;
            }
            prevScore = score;
        }

        System.out.println(can);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}

Measured memory_bytes: 47812
#include<bits/stdc++.h>
using namespace std;
vector<int> values, costs;
int n, aux, mx, res;
void bt(int m, int val) {
	if(m == n) {
		mx = max(mx, val);
		return;
	}
	int tmp = values[m] - costs[m];
	if(tmp > 0)	bt(m + 1, val + tmp);
	bt(m + 1,  val);
	return;
}
int main() {
	cin>>n;
	for(int i = 0; i < n; i++) {
		cin>>aux;
		values.push_back(aux);
	}
	for(int i = 0; i < n; i++) {
		cin>>aux;
		costs.push_back(aux);
	}
	bt(0, 0);
	cout<<mx<<endl;
	return 0;
}

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

using namespace std;

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

    int l , r;
    cin >> l >> r;

    r = min(r , l + 2019);

    int mn = 1e9;
    for (int i = l ;i < r ;i++)
        for (int j = i + 1 ;j <= r ;j++)
            mn = min(1ll * mn , (i * 1ll * j) % 2019);

    cout << mn;
}

Measured memory_bytes: 256
#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 A1,A2,A3;
  cin >> A1 >> A2 >> A3;
  if ((A1+A2+A3) <= 21 ) {
    cout << "win" << endl;
  } else {
    cout << "bust" << endl;
  }
    return 0;


}

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

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

    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>> a[i];
    }
    
    sort(a.begin(), a.end(), greater<int>());
    //reverse(a.begin(), a.end());

    int alice=0, bob=0;
    for(int i=0; i<n; i++){
        if(i%2==0){
            alice+=a[i];
        }else{
            bob+=a[i];
        }
    }
    cout<< alice - bob << endl;
    return 0;
}

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((abs(b - a) <= d && abs(c - b) <= d)|| abs(c - a) <= d)
        cout << "Yes" << endl;
        else
            cout << "No" << endl;
}

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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

struct UnionFind {
  vi par; //par[i] : iの親番号（例）par[3] = 2 : 3の親は2

  UnionFind(int N) : par(N) { //最初は全てが根として初期化
    rep(i,N) par[i] = i;
  }

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

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

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


int main(){

  int n,m;
  cin >> n >> m;

  vi v(n);

  rep(i,n)cin >> v[i];

  UnionFind tree(n);

  rep(i,m){
    int x,y;
    cin >> x >> y;
    tree.unite(x-1,y-1);
  }

  int cnt = 0;
  rep(i,n){
    if(tree.same(i,v[i] -1))cnt++;
  }

  pr(cnt);


  return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  string t;
  cin >> t;
  REP(i, SZ(t)) {
	if (t[i] == '?') {
		t[i] = 'D';
	  }
  }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 3712
n = gets.to_i
s = gets.chomp.chars
h0 = {}
h1 = {}
h2 = {}
n.times do |i|
  h1.keys.each do |k2|
    if h2.key?(k2 + s[i]) == false
      h2[k2 + s[i]] = 1
    end
  end
  h0.keys.each do |k1|
    if h1.key?(k1 + s[i]) == false
      h1[k1 + s[i]] = 1
    end
  end
  if h0.key?(s[i]) == false
    h0[s[i]] = 1
  end
end
puts h2.keys.size

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

int main(){
    int count=0, n,m;
    cin >> n;
    vector<int> s(n);
    for(int i=0;i<n;i++) cin >> s[i];
    cin >> m;
    vector<int> t(m);
    for(int i=0; i<m; i++) cin >> t[i];
    
    
    sort(s.begin(), s.end());
    for(int i=0;i<t.size(); i++){
        if(binary_search(s.begin(), s.end(), t[i])){
            count++;
        }
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3140
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[3000];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  ll n,h;
  cin >> n >> h;
  vi a(n), b(n);
  ll maxNum = 0;
  ll ans = n;
  ll hit = 0;
  rep(i, n){
    cin >> a[i] >> b[i];
    maxNum = (maxNum < a[i]) ? a[i] : maxNum;
  }
  rep(i, n){
    if(b[i] < maxNum){
      ans--;
      continue;
    }
    hit += b[i];
  }
  if(hit >= h){
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    ans = 0;
    hit = 0;
    rep(i, n){
      hit += b[i];
      ans++;
      if(hit >= h) break;
    }
    cout << ans << endl;
  }else{
    ll nokori = h - hit;
    ans += ll(nokori / maxNum);
    ans += ((double)nokori/maxNum - ll(nokori/maxNum) == 0) ? 0 : 1;
    cout << ans << endl;
  }
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

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

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	rep(i, n) cin >> v[i];
	sort(rall(v));
	ll ans = 0;
	for (int i = k; i < n; i++) {
		ans += v[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,q = inm()
s = ins()
t = []
d = []
for i in range(q):
    tt,dd = input().split()
    t.append(tt)
    d.append(dd)
ltop = 0
for i in range(q-1,-1,-1):
    if t[i]==s[ltop] and d[i]=='L':
        ltop += 1
        if ltop==n:
            break
    elif ltop>0 and t[i]==s[ltop-1] and d[i]=='R':
        ltop -= 1
rtop = n-1
for i in range(q-1,-1,-1):
    if t[i]==s[rtop] and d[i]=='R':
        rtop -= 1
        if rtop == -1:
            break
    elif rtop<n-1 and t[i]==s[rtop+1] and d[i]=='L':
        rtop += 1
print(n-min(n,ltop+n-1-rtop))


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
char s[200005];

int main() {
    scanf("%s", s);
    n = strlen(s);
    int state = 0;
    LL ans = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == 'A') {
            if (state % 2 == 1) {
                state = 0;
            } else {
                ans += state / 2;
            }
        } else if (s[i] == 'B') {
            if (state % 2 == 1) {
                ++state;
            } else {
                state = 0;
            }
        } else {
            if (state % 2 == 0) {
                ++state;
            } else {
                state = 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    int n;
    int a[100];
    cin >> n;

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

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

    return 0;
}

Measured memory_bytes: 3068
#include <cstdio>

template<int N, typename T, T M>
struct factorial_mod
{
	T mod[N + 1];
	T inv_mod[N + 1];

	constexpr factorial_mod() : mod(), inv_mod()
	{
		mod[0] = 1;
		for (int i = 0; i < N; ++i)
		{
			mod[i + 1] = (mod[i] * (i + 1)) % M;
		}
		inv_mod[N] = power(mod[N], M - 2);
		for (int i = N - 1; i >= 0; --i)
		{
			inv_mod[i] = (inv_mod[i + 1] * (i + 1)) % M;
		}
	}

	constexpr T power(T a, T b) const
	{
		T r = 1;
		while (b > 0)
		{
			if ((b & 1) != 0) r = (r * a) % M;
			a = (a * a) % M;
			b >>= 1;
		}
		return r;
	}

	constexpr T comb(T n, T r) const
	{
		if (r < 0 || r > n || n < 0) return 0;
		return (((mod[n] * inv_mod[r]) % M) * inv_mod[n - r]) % M;
	}
};

constexpr factorial_mod<1000000, long long, 1000000007> fmod;

int main()
{
  long long x, y;
  scanf("%lld%lld", &x, &y);
  if ((x + y) % 3 != 0)
  {
    puts("0");
    return 0;
  }
  long long n = (x + y) / 3;
  x -= n;
  y -= n;
  if (x < 0 || y < 0)
  {
    puts("0");
    return 0;
  }
  printf("%lld\n", fmod.comb(n, x));
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	if(n<=9){
		for(int i=0; ++i<=n; printf("%d\n",i));
		return 0;
	}
	for(int i=0; ++i<=9; printf("%d\n",i));
	n-=8;
	long long bas=1;
	for(int i=1; n&&i<=10; ++i){
		for(int j=9; ++j<(i-1)*10&&--n; printf("%d%lld\n",j,bas-1));
		bas*=10;
		if(!n)
			break;
		for(int j=max(i-2,0); ++j<10&&--n; printf("%d%lld\n",j,bas-1));
	}
	for(int i=11; n&&i<=13; ++i,bas*=10)
		for(int j=9; ++j<100&&--n; printf("%d%lld\n",j,bas-1));
	bas/=10;
	for(int i=13; n; ++i){
		for(int j=99; ++j<(i-2)*10&&--n; printf("%d%lld\n",j,bas-1));
		bas*=10;
		if(!n)
			break;
		for(int j=max(i-3,0); ++j<100&&--n; printf("%d%lld\n",j,bas-1));
	}
	return 0;
}

Measured memory_bytes: 1732
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <queue>
#define PII pair<int, int>
#define T3I tuple<int, int, int>
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

const int MAX_N = 101;
vector<string> G;
int dp[MAX_N][MAX_N][2];

int solve(int i, int j, int c)
{
    int &res = dp[i][j][c];
    if(res != -1) return res;
    if(i == 0 && j == 0) {
        if(c == 0 && G[0][0] == '.') return res = 0;
        else if(c == 1 && G[0][0] == '#') return res = 0;
        else return res = 1;
    }
    int vu = INF, vl = INF;
    if(c == 0 && G[i][j] == '.') {
        if(i > 0) {
            vu = min(vu, solve(i-1, j, 0));
            vu = min(vu, solve(i-1, j, 1)+1);
        }
        if(j > 0) {
            vl = min(vl, solve(i, j-1, 0));
            vl = min(vl, solve(i, j-1, 1)+1);
        }
    }else if(c == 1 && G[i][j] == '#') {
        if(i > 0) {
            vu = min(vu, solve(i-1, j, 0)+1);
            vu = min(vu, solve(i-1, j, 1));
        }
        if(j > 0) {
            vl = min(vl, solve(i, j-1, 0)+1);
            vl = min(vl, solve(i, j-1, 1));
        }
    }else if(c == 0 && G[i][j] == '#') {
        if(i > 0) {
            vu = min(vu, solve(i-1, j, 0)+(G[i-1][j] == '#'? 0 : 1));
            vu = min(vu, solve(i-1, j, 1)+(G[i-1][j] == '.'? 1 : 2));
        }
        if(j > 0) {
            vl = min(vl, solve(i, j-1, 0)+(G[i][j-1] == '#'? 0 : 1));
            vl = min(vl, solve(i, j-1, 1)+(G[i][j-1] == '.'? 1 : 2));
        }
    }else {
        if(i > 0) {
            vu = min(vu, solve(i-1, j, 0)+(G[i-1][j] == '#'? 1 : 2));
            vu = min(vu, solve(i-1, j, 1)+(G[i-1][j] == '.'? 0 : 1));
        }
        if(j > 0) {
            vl = min(vl, solve(i, j-1, 0)+(G[i][j-1] == '#'? 1 : 2));
            vl = min(vl, solve(i, j-1, 1)+(G[i][j-1] == '.'? 0 : 1));
        }
    }
    //if(i == 0 && j == 1) cout << vu << " " << vl << endl;
    return res = min(vu, vl);
}

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

    memset(dp, -1, sizeof dp);
    int n, m;
    cin >> n >> m;
    G.resize(n);
    for(int i = 0; i < n; ++i) {
        cin >> G[i];
    }
    cout << min(solve(n-1, m-1, 0), solve(n-1, m-1, 1)+1) << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N,K;
  cin >> N >> K;
  
  vector<int>ball(N,0);
  
  for(int i=0;i<N;i++){
    cin >> ball[i];
  }
  
  int ans = 0;
  
  for(int i=0;i<N;i++){
    if(ball[i] >= K - ball[i])
      ans += (K - ball[i]) * 2;
    else
      ans += ball[i] * 2;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
INF = 10 ** 20
A, B, Q = gets.chomp.split(" ").map(&:to_i)

S_ARRAY = []
S_ARRAY << -INF
A.times do
  S_ARRAY << gets.to_i
end
S_ARRAY << INF

T_ARRAY = []
T_ARRAY << -INF
B.times do
  T_ARRAY << gets.to_i
end
T_ARRAY << INF

X_ARRAY = []
Q.times do
  X_ARRAY << gets.to_i
end

X_ARRAY.each do |x|
  east_s_index = S_ARRAY.bsearch_index {|pos| pos >= x}
  nearest_ss = [S_ARRAY[east_s_index - 1], S_ARRAY[east_s_index]]

  east_t_index = T_ARRAY.bsearch_index {|pos| pos >= x}
  nearest_ts = [T_ARRAY[east_t_index - 1], T_ARRAY[east_t_index]]

  distances = []

  nearest_ss.each do |s|
    nearest_ts.each do |t|
      distances << (x - s).abs + (s - t).abs
      distances << (x - t).abs + (t - s).abs
    end
  end

  puts distances.min
end

Measured memory_bytes: 5684
/* 
 * Project: AtCoder Beginners Contest 136 C - Build Stairs
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/09/09
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
#include <vector>
using namespace std;

uint32_t n;
vector<int64_t> h;

void solve() {

    bool is_ok = true;
    for (int i=n-2;i>=0;i--) {
        if (h[i] > h[i+1]) {
            if (h[i] - h[i+1] >= 2) {
                is_ok = false;
                break;
            }
            h[i]--;
        }
    }
    if (is_ok)
        printf("Yes\n");
    else
        printf("No\n");

}

int main() {

    scanf("%d", &n);
    h.resize(n);
    for (int i=0;i<n;i++) {
        scanf("%lld", &h[i]);
    }

    solve();
}

Measured memory_bytes: 3636
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
3
1 2 3
---+/
/+---test
4
1 3 1 1
---+/
/+---test
8
27 23 76 2 3 5 62 52
---+/

void main(string[] args) {
  const N = readln.chomp.to!long;
  const W = readln.split.map!(to!long).array;

  const all = W.sum;
  long cur;
  foreach (i, w; W) {
    cur += w;
    if (cur > all - cur) {
      min(abs(2*cur - all), abs(2*(cur-w) - all)).writeln;
      return;
    }
  }
}


Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	int N,V,P;
	long M;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		N = nextInt();
		M = nextLong();
		V = nextInt();
		P = nextInt();

		long []A = nextLongArray(N);
		Arrays.sort(A);
		long []maxup = A.clone();
		long []Rup = A.clone();
		long up = M*1;
		for(int i=0;i<N;i++) {
			maxup[i] += up;
		}
		for(int i=N-1;i>N-P;i--) {
			Rup[i] += up;
		}

		int low = 0,hi = N-1;
		for(int i=0;i<N;i++) {
			if(maxup[i]>=Rup[N-P]) {
				low = i;
				break;
			}
		}

		int index = (low + hi) / 2;
		int tr = N-P;
		long order_p = Math.max(0,V-P);
		while(low < hi) {
			if(order_p <= index) {
				hi = index;
			}else {
				long _order_p = (order_p-index)*M; //右側に送るポイント
				int _i = index+1;
				while(_order_p > 0 && _i < tr+1) {
					long t = Math.max(maxup[index]-A[_i],0);
					if(t == 0)break;
					_order_p -= t;
					_i++;
				}
				if(_order_p <= 0) {
					hi = index;
				}else {
					low = index+1;
				}
			}
			index = (low + hi) / 2;
		}
		long cnt = N-index;

		out.println(cnt);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}

	long lcm(long m, long n) {
	        return m * n / gcd(m, n);
	}
}

Measured memory_bytes: 48956
// clang-format off
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
#define DEB(variable) cout << #variable << '=' << variable << endl

#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

// clang-format on
int main(){

    llint k;
    cin>>k;
    llint result = 0;
    FOR(i,1,k+1){
        FOR(j,1,k+1){
            FOR(l,1,k+1){
            result+=gcd(i,gcd(j,l));    
           }
        }    
    }
    cout<<result<<endl;

    return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int N;
    ll H;
    cin >> N >> H;
    vector<ll> a(N);
    vector<ll> b(N);
    ll inpa, inpb;
    ll amax = 0;
    REP(i,N){
        cin >> inpa >> inpb;
        a[i] = inpa;
        b[i] = inpb;
        amax = max(amax, inpa);
    }

    int ans = 0;
    sort(b.begin(), b.end(), greater<ll>());
    REP(i,N){
        if(amax < b[i]){
            H -= b[i];
            ans++;  
        }
        if(H <= 0)
            break;
    }
    if(H > 0){
        ans += H / amax;
        if(H % amax != 0) ans++;
    }  
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int[][][] houses = new int[4][3][10];	
	int n = scan.nextInt();
	for (int cnt = 0; cnt < n; cnt++) {
	    int b = scan.nextInt() - 1;
	    int f = scan.nextInt() - 1;
	    int r = scan.nextInt() - 1;
	    int v = scan.nextInt();
	    houses[b][f][r] += v;
	}
	for (int b = 0; b < 4; b++) {
	    for (int f = 0; f < 3; f++) {
		for (int r = 0; r < 10; r++) {
		    System.out.print(" " + houses[b][f][r]);
		}
		System.out.println();
	    }
	    if (b != 3) {
		for (int i = 0; i < 20; i++) {
		    System.out.print("#");
		}
		System.out.println();
	    }
	}
    }
}

Measured memory_bytes: 29224
// Problem : B - Magic 2
// Contest : AtCoder - M-SOLUTIONS Programming Contest 2020
// URL : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
#define 	ll		    long long
#define 	rep(i,a,n)  for(int i=a;i<n;i++)
#define 	MOD 		1000000007
#define 	vp 			vector<pair<int,int> >
#define 	ff 			first
#define 	ss 			second
#define 	pb 			push_back
#define 	all(x) 		(x.begin(),x.end())
#define 	dg(x)		cerr<<"--- x = "<<x<<"\n"
#define 	endl		"\n"
#define int long long

using namespace std;
const int N = 1e5;
ll ar[N];

void solve(){
	int r,g,b,k; cin  >> r >> g >> b >> k;
	int c=0;
	bool flag=true;
	while(g <= r){
		
	
		g*=2;
		c++;
		if(c > k){
			flag=false;
			break;
		}
	}
	while(b <= g){
		
	
		b*=2;
		c++;
		if(c > k){
			flag=false;
			break;
		}
	}
	if(flag)
		cout << "Yes";
	else
		cout << "No";
	
}

int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
}


Measured memory_bytes: 3600
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};

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

        long r=sc.nextLong();
        long d=sc.nextLong();
        long x=sc.nextLong();
        long ans=0;
        for (int i = 0; i < 10; i++) {
        	x=x*r-d;
            out.println(x);	
		}

//        out.println(ans);
        out.flush();
    }
    



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}


//class P implements Comparable<P>{
//    long a,b; 
//    int id;
//    P(long a, long b,int id) {
//        this.a=a;
//        this.b=b;
//        this.id=id;
//    }
//    public int compareTo(P p){
//    	if(a*b-p.a*p.b>0) return 1;
//    	if(-a*b+p.a*p.b>0) return -1;    	
//        return 0;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long[] nextLongArray(int size) throws IOException{
    	long r[] = new long[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextLong(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 21076