akhauriyash/Code-Regression huggingface dataset:
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main(void){
    ll x;
    cin >> x;
    ll a;
    ll b;
    while( ((500*(a+1))) <= x){
        a++;
    }
    while( (500*a)+(5*(b+1))<=x){
        b++;
    }
    cout << a*1000 + b*5 << endl;

    return 0;
}

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

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

	vector<long long> A(N);
	for(int i=0;i<N;i++){
		cin >> A.at(i);
	}

	if(find(A.begin(), A.end(), 0) != A.end()){
		cout << 0 << endl;
		return 0;
	}

	long long ans=1;

	for(int i=0;i<N;i++){
		if(A[i] > 1000000000000000000 / ans){
			cout << -1 << endl;
			return 0;
		}else{
			ans *= A.at(i);
		}
	}
	if(ans > 1000000000000000000){
		cout << -1 << endl;
		return 0;
	}else{
		cout << ans << endl;
	}


}


Measured memory_bytes: 4040
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
using namespace std;

const long long N = 2e3 + 5, MOD = 1e9 + 7;

long long dp[N][N], pre[N][N];

void test() {
    int n;
    cin >> n;
    long long ans = 0;
    dp[0][0] = 1;
    for (int i = 0; i <= n; ++i) {
        pre[0][i] = 1;
    }
    for (int len = 1; len <= n; ++len) {
        for (int sum = 3; sum <= n; ++sum) {
            dp[len][sum] = pre[len - 1][sum - 3];
            pre[len][sum] = (pre[len][sum - 1] + dp[len][sum]) % MOD;
        }
        ans += dp[len][n];
    }
    cout << ans % MOD << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; ++i) {
        test();
    }
    return 0;
}


Measured memory_bytes: 66148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		var A = GetLongs(N);
		Array.Sort(A);
		Array.Reverse(A);

		long ans = A[0];
		for(long i = 1; i < N - 1; i++)
			ans += A[(i + 1) / 2];

		WriteLine(ans);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 48128
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
const int N = 100002;
const int oo = INT_MAX;
int d,t,s;

int main(){
    scanf("%d%d%d",&d,&t,&s);
    double time=d*1.0/s;
    if(time<=t)
        puts("Yes");
    else
        puts("No");
    
}




Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		String str = sc.next();

		if(str.toLowerCase().equals(str)){
			System.out.println("a");
		}
		else {
			System.out.println("A");
		}
	}

}


Measured memory_bytes: 26904
using System;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NL = Console.ReadLine().Split(' ');
            int N = int.Parse(NL[0]);
            int L = int.Parse(NL[1]);

            int i = 1;
            int Mini = 10000;
            for(;i <= N ;i ++ )
            {
                if(Mini*Mini >= (L + i -1)* (L + i - 1))
                {
                    Mini = L + i - 1;
                }
            }
            Console.WriteLine(L * N + N*(N+1)/2 - N - Mini) ;

        }

    }
}


Measured memory_bytes: 11092
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
dis = []
for i in range(1,len(a)):
    dis.append(abs(a[i]-a[i-1]))
s = sum(dis)
for i in range(1,len(a)-1):
    print(s+abs(a[i-1]-a[i+1])-(dis[i]+dis[i-1]))

Measured memory_bytes: 14048
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, const char * argv[])
{
    double a=0.0;
    double b=0.0;
    double c=0.0;
    double d=0.0;
    double e=0.0;
    double f=0.0;
    double x=0.0;
    double y=0.0;
    int end=0;
    
    while(scanf("%d",&end)!=EOF){
        a=end;
        scanf("%lf",&b);
        scanf("%lf",&c);
        scanf("%lf",&d);
        scanf("%lf",&e);
        scanf("%lf",&f);
        
        y = (d*c-a*f)/(d*b-a*e);
        x = (c-b*y)/a;
        
        printf("%.3lf",x);
        printf(" ");
        printf("%.3lf\n",y);
        
    }
    
}

Measured memory_bytes: 1248
N = gets.to_i
count = 0
flg = false
N.times do |i|
  d1, d2 = gets.chomp.split.map(&:to_i)
  if d1 == d2
    count += 1
    flg = true if count == 3
  else
    count = 0
  end
end

print flg ? 'Yes' : 'No'

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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	string S[3];
	rep(i,3) cin >> S[i];
	rep(i,3) reverse(S[i].begin(),S[i].end());
	char w;
	int t=0;
	while(1){
		if(S[t].empty()){
			w='A'+t;
			break;
		}
		char c=S[t].back();
		S[t].pop_back();
		t=c-'a';
	}
	cout << w << endl;

	return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>

int main(){
  int i, j, n, max, min, res;
  int a[200000];

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &a[i]);
  }

  min = a[0];
  res = a[1] - min;
  if(res < 0) min = a[1];
  
  for(i=2; i<n; i++){
    if(a[i]- min > res) res = a[i]- min;
    else if(min > a[i])  min = a[i];
  }

  printf("%d\n", res);
}



Measured memory_bytes: 2580
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=1e5+5; 
vector <pair<int, int> > adj[maxn];
bool vis[maxn];
int x[maxn];

void dfs(int now,int dist)
{
	vis[now] = true;
	x[now] = dist;
 
	for (int i = 0; i < adj[now].size(); i++)
	{
		int next = adj[now][i].first;
		int d = adj[now][i].second;
		if (vis[next] == false)
		{
			dfs(next, dist + d);
		}
	}
}
 
int main()
{
	int n, m;
	int l, r, d;
	bool ok = true;
 
	cin.tie(0);
 
	while(cin >> n >> m)
	{
		ok=true;
	for (int i = 0; i < m; i++)
	{
		cin >> l >> r >> d;
		adj[l].push_back(make_pair(r, d)); //关联点 
		adj[r].push_back(make_pair(l, -d));
	}
 
	memset(x, 0, sizeof(x));
	memset(vis, 0, sizeof(vis));
 
	for (int i = 1; i <= n; i++)
	{
		if (vis[i]==false)
		{
			dfs(i, 0);
		}
	}

	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j < adj[i].size(); j++)
		{
			int v = adj[i][j].first;
			if (adj[i][j].second != x[v]-x[i])
			{
				ok = false;
				break;
			}
		}
		if (ok == false)
		{
			cout << "No" << '\n';
			break;
		}
 
	}
 
	if (ok == true)
	{
		cout << "Yes" << '\n';
	}
	}
	return 0;
}

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

int main()
{
    int N,K;
    cin >> N >> K;
    int r,s,p;
    string T;
    cin >> r >> s >> p;
    
    cin >> T;
    ll point=0;
    char H[N];
    rep(i,N){
        H[i]='n';
    }
    
    rep(i,K){
        if(T[i]=='r'){
            H[i]='p';
            point+=p;
        }else if(T[i]=='s'){
            H[i]='r';
            point+=r;
        }else{
            H[i]='s';
            point+=s;
        }
    }
    for(int i=K;i<N;++i){
        if(T[i]=='r'&&H[i-K]!='p'){
            H[i]='p';
            point+=p;
        }else if(T[i]=='s'&&H[i-K]!='r'){
            H[i]='r';
            point+=r;
        }else if(T[i]=='p'&&H[i-K]!='s'){
            H[i]='s';
            point+=s;
        }
    }
    cout << point << endl;
}

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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define  endl 			"\n"
#define  FOR(i, a, n)   for (ll i = a; i < n; i++)
#define  ROF(i, a, n)   for (ll i = a; i >= n; i--)
#define  all(x)         (x).begin(), (x).end()
#define  mset(x, val)   memset(x,val,sizeof(x))
#define  dline          cout<<"///REACHED///\n";

typedef long long ll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  4e+5+7;



// 1 100




int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,k;
	cin>>n;
	vector<ll> arr(n);
	ll ans;
	ll ctr=0;
	FOR(i,0,n){
		cin>>arr[i];
		while(arr[i]%2==0){
			ctr++;
			arr[i]/=2;
		}
	}
	cout<<ctr<<endl;

	return 0;
}


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

long long dp[100005];

long long stairs(long long a) {
  long long num = 1;
  for(int i = 2;i <= a;i++){
    num *= i;
    num %= 1000000007;
  }
  return num;
}

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

  if(N == M) {
    cout << stairs(N) * stairs(N) * 2 % 1000000007<< endl;
  }else if(N + 1 == M || N == M + 1) {
    cout << stairs(M) * stairs(N) % 1000000007 << endl;
  }else {
    cout << 0 << endl;
  }

}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int i,a,b;
  char n[16];
  for(i=0;i<9;i++){
    scanf("%s %d %d",n,&a,&b);
    printf("%s %d %d\n",n,a+b,200*a+300*b);
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,lli,N+2,0);
  rep(i,1,N+1)cin >> P[i];
  Vec(Q,lli,N+1,0);
  rep(i,0,N+1)Q[i]=abs(P[i]-P[i+1]);
  rep(i,0,N+1)sum+=Q[i];
  rep(i,1,N+1)Out(sum-Q[i-1]-Q[i]+abs(P[i-1]-P[i+1]));
}

Measured memory_bytes: 2816
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  char color = s[0];
  for(int i=1; i<=n; i++){
    if(color != s[i]){
      ans++;
      color = s[i];
    }
  }
  cout << ans << endl;
  return 0;
}


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

class Main {
    public static void main(String[] args) throws IOException {
        Scan sc = new Scan();
        int n = sc.scanInt();
        int k = sc.scanInt();
        int[] arr = new int[n];
        for(int i =0; i < n; ++i)
            arr[i] = sc.scanInt();
        Arrays.sort(arr);
        long res = 0;
        for(int i = 0; i < n-k; ++i){
            res += arr[i];
        }
        System.out.println(res);
    }
}

class Scan
{
    private byte[] buf=new byte[1024];
    private int index;
    private InputStream in;
    private int total;
    public Scan()
    {
        in=System.in;
    }
    public int scan()throws IOException
    {
        if(total<0)
        throw new InputMismatchException();
        if(index>=total)
        {
            index=0;
            total=in.read(buf);
            if(total<=0)
            return -1;
        }
        return buf[index++];
    }
    public int scanInt()throws IOException
    {
        int integer=0;
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        int neg=1;
        if(n=='-')
        {
            neg=-1;
            n=scan();
        }
        while(!isWhiteSpace(n))
        {
            if(n>='0'&&n<='9')
            {
                integer*=10;
                integer+=n-'0';
                n=scan();
            }
            else throw new InputMismatchException();
        }
        return neg*integer;
    }
    public double scanDouble()throws IOException
    {
        double doub=0;
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        int neg=1;
        if(n=='-')
        {
            neg=-1;
            n=scan();
        }
        while(!isWhiteSpace(n)&&n!='.')
        {
            if(n>='0'&&n<='9')
            {
                doub*=10;
                doub+=n-'0';
                n=scan();
            }
            else throw new InputMismatchException();
        }
        if(n=='.')
        {
            n=scan();
            double temp=1;
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    temp/=10;
                    doub+=(n-'0')*temp;
                    n=scan();
                }
                else throw new InputMismatchException();
            }
        }
        return doub*neg;
    }
    public String scanString()throws IOException
    {
        StringBuilder sb=new StringBuilder();
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        while(!isWhiteSpace(n))
        {
            sb.append((char)n);
            n=scan();
        }
        return sb.toString();
    }
    private boolean isWhiteSpace(int n)
    {
        if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
        return true;
        return false;
    }
}

Measured memory_bytes: 25512
N = int(input())
p_dict = {2:1, 3:1}
for num in range(4,N+1):
  is_prime = True
  for prime, cnt in p_dict.items():
    if num%prime == 0:
      p_dict[prime] = cnt + 1
      idx = 2
      while num%(prime**idx) == 0:
        idx += 1
        p_dict[prime] += 1
      is_prime = False
  if is_prime:
    p_dict[num] = 1

def num(n):
  return len(list(filter(lambda x:x >= n-1, p_dict.values())))

ans = num(75) + num(25) * (num(3)-1) + num(15) * (num(5)-1) + (num(5) * (num(5)-1) * (num(3)-2))//2
print(ans)


  

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

const int N = 202;
int g[N][N];
int dfs(int w, int b){
    if(g[w][b]>=0) return g[w][b];

    vector<bool> ap(N);
    if(w>0) ap[dfs(w-1,b)] = true;
    for(int i=1; i<=min(w,b); ++i) ap[dfs(w,b-i)] = true;
    if(b>0) ap[dfs(w+1,b-1)] = true;

    int ret = N;
    rep(i,N)if(!ap[i]){
        ret = i;
        break;
    }
    return g[w][b] = ret;
}

int main(){
    memset(g,-1,sizeof(g));
    int n;
    cin >>n;
    int a = 0;
    rep(i,n){
        int w,b;
        cin >>w >>b;
        a ^= dfs(w,b);
    }
    cout << !a << endl;
    return 0;
}



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

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		//?????°???????????????
		int people = sc.nextInt();
		int max = 0;

		int[] wakasagi = new int[people+1];
		Arrays.fill(wakasagi, 0);

		for(int $ = 1; $ <= people; $++) {
			wakasagi[sc.nextInt()] = sc.nextInt();
			max = Math.max(max, wakasagi[$]);
		}

        for(int i = 1;i <= people; i++) {
            if(wakasagi[i] == max) {
                System.out.println(i + " " + max);
                break;
            }
        }
	}

}

Measured memory_bytes: 26384
N, Y = map(int, input().split())

def otoshidama():
    for i in range(N+1):
        for j in range(N+1-i):
            if 10000*i + 5000*j + 1000*(N-i-j) == Y:
                print(i, j, N-i-j)
                return
    print(-1, -1, -1)

otoshidama()

Measured memory_bytes: 3060
n = gets.chomp.to_i

a = gets.chomp.split(" ").map{|i|i = i.to_i}
b = gets.chomp.split(" ").map{|i|i = i.to_i}
c = gets.chomp.split(" ").map{|i|i = i.to_i}
#pp n
#pp a
sum = 0
(n-1).times{|i|
  sum += b[a[i]-1]
  if a[i] == a[i+1]-1 then
    sum += c[a[i]-1]
  end 
  #puts "now i=#{i}, sum=#{sum}"
}
sum += b[a[n-1]-1]
puts sum

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

int main(){
  int n,x; cin>>n>>x;
  int min_m=2*10e5;
  int sum_m=0;
  for (int i=0; i<n; i++){
    int m; cin>>m;
    sum_m+=m;
    min_m=min(min_m,m);
  }
  x-=sum_m;
  cout<<n+x/min_m<<endl;
}

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

int main(void)
{
	int w, h, n;

	std::cin >> w >> h >> n;

	int x, y;
	x = y = 0;
	for (int i = 0; i < n; i++) {
		int xi, yi, a;
		std::cin >> xi >> yi >> a;

		switch (a) {
		case 1:
			x = std::max(x, xi);
			break;
		case 2:
			w = std::min(w, xi);
			break;
		case 3:
			y = std::max(y, yi);
			break;
		case 4:
			h = std::min(h, yi);
			break;
		default:
			return 1;
		}
	}

	int area;
	if ((x >= w) ||
		(y >= h)) {
		area = 0;
	}
	else {
		area = (w - x) * (h - y);
	}
	std::cout << area;

	return 0;
}

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

typedef vector<int> vec;
typedef vector<vec> mat;

struct edge { int from, to, cap, cost, rev; };

int N, M, C, S, T;
const int INF  = 1 << 28;

int main() {
    while (cin >> N >> M >> C >> S >> T, N + M + C + S + T) {
        S--, T--;

        vector<mat> ccost(C, mat(N, vec(N, INF)));
        for (int c = 0; c < C; c++)
            for (int i = 0; i < N; i++) ccost[c][i][i] = 0;

        for (int i = 0; i < M; i++) {
            int x, y, d, c; cin >> x >> y >> d >> c;
            x--, y--, c--;
            ccost[c][x][y] = ccost[c][y][x] = min(ccost[c][y][x], d);
        }

        for (auto &c : ccost)
            for (int i = 0; i < N; i++)
                for (int j = 0; j < N; j++)
                    for (int k = 0; k < N; k++)
                        c[j][k] = min(c[j][k], c[j][i] + c[i][k]);

        mat lvec(C), rvec(C);
        for (int i = 0; i < C; i++) {
            int n; cin >> n;
            lvec[i].resize(n-1);
            rvec[i].resize(n);
        }

        mat dcost(C, vec(100000));
        for (int i = 0; i < C; i++) {
            for (auto &j : lvec[i]) cin >> j;
            for (auto &j : rvec[i]) cin >> j;

            for (int j = 0, k = 0; j < 100000; j++) {
                if (k == lvec[i].size()) dcost[i][j+1] = dcost[i][j] + rvec[i][k];
                else {
                    dcost[i][j+1] = dcost[i][j] + rvec[i][k];
                    if (j + 1 == lvec[i][k]) k++;
                }
            }
        }

        mat G(N, vec(N, INF));
        for (int c = 0; c < C; c++) {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    if (ccost[c][i][j] != INF)
                        G[i][j] = min(G[i][j], dcost[c][ccost[c][i][j]]);
                }
            }
        }

        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                for (int k = 0; k < N; k++) G[j][k] = min(G[j][k], G[j][i] + G[i][k]);

        cout << (G[S][T] == INF ? -1 : G[S][T]) << endl;
    }

    return 0;
}

Measured memory_bytes: 12100
#include <iostream>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	if(a<b){cout << "a < b" << endl;}
	if(a>b){cout << "a > b" << endl;}
	if(a==b){cout << "a == b" << endl;}
	return 0;
}



Measured memory_bytes: 3088
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> n >> s;
	ans = n;
	for(i=1;i<n;i++) {
		if (s[i-1]==s[i]) ans--;
	}
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int isOk(string s, int N){
    int ok = 1;
    char c = s[0];
    rep(i,0,N) if(s[i]!=c) ok=0;
    return ok;
}
int main(){
  string s; cin>>s;
  map<char, int> ma;
  int N = s.size();
  int ans = inf;
  for(char c='a' ; c<='z' ; c++){
    int cnt = 0;
    string t = s;
    int n = N;
    while(!isOk(t, n)){
        rep(i,0,n-1){
            if(t[i]==c){
                t[i] = c;
            }else if(t[i+1]==c){
                t[i] = c;
            }else{
                t[i] = t[i+1];
            }
        }
        n--;
        cnt++;
    }
    chmin(ans, cnt);
  }
  cout<<ans<<endl;
  return 0;
}   

Measured memory_bytes: 3612
n = int(input())
s = input()
a = [int(i) for i in s.split()]

maxv = -1

for i in range(n):
    for j in range(n-1):
        if i == j:
            continue
        if abs(a[i]-a[j]) > maxv:
            maxv = abs(a[i]-a[j])


print(maxv)

Measured memory_bytes: 3060
use proconio::input;

fn main() {
    input!(n: usize, a: [usize; n]);

    const AMAX: usize = 1_000_000;

    let mut div = vec![0; AMAX + 1];
    let mut pri = Vec::new();

    for i in 2..=AMAX {
        if div[i] == 0 {
            div[i] = i;
            pri.push(i);
        }
        let mut j = 0;
        while j < pri.len() && pri[j] <= div[i] && i * pri[j] <= AMAX {
            div[i * pri[j]] = pri[j];
            j += 1;
        }
    }

    let mut cnt = vec![0; AMAX + 1];
    for &a in &a {
        cnt[a] += 1;
    }
    for i in (2..=AMAX).rev() {
        if div[i] == i {
            continue;
        }
        let j = i / div[i];
        cnt[j] += cnt[i];
        if div[j] != div[i] {
            cnt[div[i]] += cnt[i];
        }
    }

    let pairwise = pri.iter().all(|&i| cnt[i] <= 1);
    let setwise = pri.iter().all(|&i| cnt[i] < n);

    println!(
        "{}",
        if pairwise {
            "pairwise coprime"
        } else if setwise {
            "setwise coprime"
        } else {
            "not coprime"
        }
    );
}


Measured memory_bytes: 32640
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <set>
using namespace std;

set<int> v;
int N;

inline bool is_valid(long long val) {
  bool three = false, five = false, seven = false;
  while(val) {
    int dig = val % 10;
    if(dig == 3) three = true;
    if(dig == 5) five = true;
    if(dig == 7) seven = true;
    val /= 10;
  }
  return three && five && seven;
}

void generate(long long have) {
  if(have > N) return;
  if(is_valid(have)) {
    v.insert(have);
  }
  generate(have * 10LL + 3);
  generate(have * 10LL + 7);
  generate(have * 10LL + 5);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  generate(0);

  int ans = 0;
  for(int val: v) {
    if(val <= N) ++ans;
  }
  cout << ans << endl;
}


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

int main(){
	
/*
	for(int i=0; i<7; i++){
		int a,b;
		cin >> a >> b;
		cout << a - b <<endl;
		*/

	/*
	for(int i=0; i<4; i++){
		int T, K;
		cin >> T >> K;
		if(T == 1){
			cout << K*6000 << endl;
		}
		else if(T == 2){
			cout << K*4000 << endl;
		}
		else if(T == 3){
			cout << K*3000 << endl;
		}
		else{
			cout << K*2000 << endl;
		}

	}
	*/
	
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int x, y, b, p;
		cin >> x >> y >> b >> p;

		if(b >= 5 && p >= 2){
			cout << (x*b + y*p)*4/5 << endl;
		}

		else{
			cout << min(x*b + y*p,(x * max(b,5) + y * max(p,2))*4/5 ) << endl;
		}
	}

	return 0;

}



Measured memory_bytes: 3116
#include <iostream>
#include <stack>

using namespace std;

int main()
{
	stack<int> st;

	int n;
	while (cin >> n)
	{
		if (n == 0)
		{
			cout << st.top() << endl;
			st.pop();
			continue;
		}

		st.push(n);
	}

	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
typedef long long ll;
int H,W;
const int H_MAX=2002;
const int W_MAX=2002;
vector<vector<char>> S(H_MAX,vector<char>(W_MAX,'#'));
vector<vector<int>> L(H_MAX,vector<int>(W_MAX,0));
vector<vector<int>> R(H_MAX,vector<int>(W_MAX,0));
vector<vector<int>> U(H_MAX,vector<int>(W_MAX,0));
vector<vector<int>> D(H_MAX,vector<int>(W_MAX,0));

int main(){
    cin >> H >> W;
    
    rep(i,H){
        rep(j,W){
            cin >> S[i+1][j+1];
        }
    }

    //横の長さ調べる
    rep2(i,1,H+1){
        rep2(j,1,W+1){
            if(S[i][j]=='.'){
                L[i][j]=L[i][j-1]+1;
                U[i][j]=U[i-1][j]+1;
            }
            if(S[H+1-i][W+1-j]=='.'){
                D[H+1-i][W+1-j]=D[H+1-i+1][W+1-j]+1;
                R[H+1-i][W+1-j]=R[H+1-i][W+1-j+1]+1; 
            }
        }
    }

    int ans=0;
    rep2(i,1,H+1){
        rep2(j,1,W+1){
            ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 69120
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var cpon = N / 15;
            Console.WriteLine(N * 800 - 200 * cpon);
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

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

using namespace std;

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;
const int N =100;
int n, x;
int d[N+1];

int main() {
  fscanf(stdin, "%d%d ", &n, &x);
  d[0] = 0;
  REP(i,n) {
    int l;
    fscanf(stdin, "%d ", &l);
    d[i+1] = d[i] + l;
  }
  int res = 0;
  REP(i,n+1) if (d[i] <= x) res++;
  fprintf(stdout, "%d\n", res);
  return 0;
}


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

vector<ii> edges;
vector<ii> adj[111111];
ll s[111111];
ll ans[111111];
ll sub[111111];
ll contr[111111];

void dfs(int u,int p)
{
	sub[u]=1;
	for(int i=0;i<adj[u].size();i++)
	{
		int v=adj[u][i].fi; int e=adj[u][i].se;
		if(v==p) continue;
		dfs(v,u);
		sub[u]+=sub[v];
	}
}

int n; 

void dfs2(int u,int p)
{
	for(int i=0;i<adj[u].size();i++)
	{
		int v=adj[u][i].fi; int e=adj[u][i].se;
		if(v==p) continue;
		//cerr<<"VISIT : "<<v<<' '<<e<<'\n';
		contr[e] = sub[v];
		if((n-2*sub[v])!=0)
		{
			ans[e] = (s[u] - s[v])/(sub[v] - (n - sub[v]));
		}
		dfs2(v,u);
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	bool sub1=1; bool sub2=1;
	for(int i=0;i<n-1;i++)
	{
		int u,v; cin>>u>>v; u--; v--;
		edges.pb(mp(u,v));
		adj[u].pb(mp(v,i)); adj[v].pb(mp(u,i));
		if(u!=0||v!=i+1)
		{
			sub2=0;
		}
		if(u!=i||v!=i+1)
		{
			sub1=0;
		}
	}
	for(int i=0;i<n;i++) cin>>s[i];
	
	dfs(0,-1);
	dfs2(0,-1);
	
	ll sum=s[0];
	for(int i=0;i<n-1;i++)
	{
		sum-=contr[i]*ans[i];
	}
	for(int i=0;i<n-1;i++)
	{
		if(ans[i]==0)
		{
			ans[i]=sum/contr[i];
		}
	}
	
	for(int i=0;i<n-1;i++)
	{
		cout<<ans[i]<<'\n';
	}
}	


Measured memory_bytes: 20848
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<int, ll> PIL;
const ll mod = 1e9 + 7;

const int N = 100100;
vector<PIL> edges[N];

bool vis[N];
bool contra;
ll pot[N];

void dfs(int v, ll p) {
  if (vis[v]) {
    if (pot[v] != p) {
      contra = true;
    }
    return;
  }
  vis[v] = true;
  pot[v] = p;
  REP(i, 0, edges[v].size()) {
    PIL wc = edges[v][i];
    int w = wc.first;
    ll c = wc.second;
    dfs(w, p + c);
  }
}


int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  REP(i, 0, m) {
    int l, r, d;
    cin >> l >> r >> d;
    edges[l].push_back(PIL(r, d));
    edges[r].push_back(PIL(l, -d));
  }
  REP(i, 0, n) {
    if (not vis[i]) {
      dfs(i, 0);
    }
  }
  cout << (contra ? "No" : "Yes") << endl;
}


Measured memory_bytes: 16640
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N, A, B = getNM()
H = getArray(N)

def judge(time, main, sub, hp):
    diff = main - sub
    cnt = 0
    for i in range(len(hp)):
        left = hp[i] - time * sub
        if left > 0:
            cnt += (left + diff - 1) // diff

    return cnt

ok = 10 ** 12 + 1
ng = -1

while ok - ng > 1:
    mid = (ok + ng) // 2
    opt = judge(mid, A, B, H)

    # mid:仮のの回数
    # opt:midを定めた時必要な爆発の回数
    # 仮の回数が必要な回数より多ければokを緩和
    if mid >= opt:
        ok = mid
    else:
        ng = mid
print(ok)

Measured memory_bytes: 88572
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>

#ifdef GONGKUNPENG
#include <cassert>

#define _GG 1
#else
#define _GG 0
#endif

#define uint unsigned
#define vector std::vector
#define max(a, b) std::max(a, b)
#define min(a, b) std::min(a, b)
#define swap(a, b) std::swap(a, b)
#define sort(...) std::sort(__VA_ARGS__)
#define ms(a, v) memset(a, v, sizeof(a))
#define ufor(i, n) for (int i = 1; i < n; ++i)
#define sfor(i, n) for (int i = 1; i <= n; ++i)
#define tfor(i, n) for (int i = 0; i < n; ++i)

#if __cplusplus >= 201103L
using ll = long long;
using ull = unsigned long long;
#else
typedef long long ll;
typedef unsigned long long ull;
#endif

const ll INF = 0x3f3f3f3f;
const uint MAXN =
#ifdef GONGKUNPENG
    15
#else
    2005
#endif
    ;

int dis[MAXN][MAXN];
int buf[MAXN];

int main() {
  int n, x, y, e;
  scanf("%d%d%d", &n, &x, &y);
  sfor(i, n) sfor(j, n) dis[i][j] = abs(i - j);
  dis[x][y] = dis[y][x] = 1;
  sfor(i, n) sfor(j, n) {
    e = min(dis[i][x] + dis[x][j], dis[i][y] + dis[y][j]);
    e = min(dis[i][j], e);
    dis[i][j] = dis[j][i] = e;
  }

  sfor(i, n) sfor(j, n) {
    if (j == i) break;
    ++buf[dis[i][j]];
  }

  buf[1] = n;
  for (int i = 1; i < n; ++i) printf("%d\n", buf[i]);
  return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mii map<int,int>
#define io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main() {
	io
	ll n;
	cin>>n;
  	cout<<n*(n-1)/2;
	return 0;
}

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

typedef unsigned long long ll;

const int maxn= 1e5+5;
ll a[maxn];
ll n,ans;
ll b[maxn];
ll c[maxn];

int main(){

    cin>>n;
    n++;

    for(int i=1;i<=n;i++) cin>>a[i];
    ans=0;
    b[1]=1;
    c[n]=a[n];
    for(int i=2;i<=n;i++){
        b[i] = (b[i-1]-a[i-1])<<1;
    }
    for(int i=n-1;i>=1;i--) c[i] = c[i+1]+a[i];
    for(int i=1;i<=n;i++) ans+=min(b[i],c[i]);
    int flag=0;
    for(int i=1;i<=n;i++){
        if(a[i]>b[i]){
            flag=1;
            break;
        }
    }
    if(flag) cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5960
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
MAX_DIGIT = 50

############
############
############

Q = i_inpl()
l, r = [], []

max_r = -INF
for _ in range(Q):
    li, ri = l_inpl()
    l.append(li)
    r.append(ri)
    max_r = max(max_r, ri)

MAX_X = 100030
prime_table = [True] * MAX_X
prime_table[0] = prime_table[1] = False

for (i, is_prime) in enumerate(prime_table):
    if is_prime:
        for n in range(i*i, MAX_X, i):
            prime_table[n] = False

# 1は2017に似てない数字
cumsums = [0]
for odd in range(3, max_r+3, 2):
    tmp = 0
    if prime_table[odd] and prime_table[(odd+1)//2]:
        tmp += 1
    cumsums.append(cumsums[-1] + tmp)

for li, ri in zip(l, r):
    if li > 1:
        li = li//2 - 1
    else:
        li = 0
    ri = ri//2
    print(cumsums[ri]-cumsums[li])


Measured memory_bytes: 14692
using System;

class Program
{
  static void Main(string[] args)
  {
    string[] str = Console.ReadLine().Split(' ');
    int n = int.Parse(str[0]);

    string[] s = new string[n];
    for (int i=0; i<n; i++) {
      s[i] = Console.ReadLine();
    }

    Array.Sort(s);
    string ret = "";
    for (int i=0; i<n; i++) {
      ret += s[i];
    }
    Console.WriteLine(ret);
  }
}


Measured memory_bytes: 13408
import sys

from collections import deque
# q = deque(); q.append(x); q.appendleft(x); q.pop() -> x; q.popleft() -> x
from collections import defaultdict
# d = defaultdict(lambda: []); d[key] -> []
import heapq
# hq = []; heapq.heappush(hq, x); heapq.heappop(hq) -> x; heapq.heappushpop(hq, x) -> x
import bisect
# bisect.bisect_left([1,2,3,4], 1) -> 0; bisect.bisect_left([1,2,3,4], 1.5) -> 1; bisect.bisect_right([4,3,2,1], 1.5)

#import numpy as np
#from scipy.misc import comb

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    T, A = i2nn()
    H = i2nn()
    d = 1e+6
    n = -1
    for i, h in enumerate(H):
        a = T - h * 0.006
        d2 = abs(A - a)
        if d > d2:
            d = d2
            n = i+1
    print(n)

main()


Measured memory_bytes: 38384
#include <iostream>
#define swap(type, x, y) do { type t = x; x = y; y = t; } while (0)
using namespace std;

void show(int A[], int N)
{
    for (int i = 0; i < N; i++) {
        if (i == N - 1)
            cout << A[i] << endl;
        else
            cout << A[i] << ' ';
    }
}

int selectionSort(int A[], int N)
{
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int min = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[min])
                min = j;
        }
        if (min != i) {
            swap(int, A[i], A[min]);
            cnt++;
        }
    }
    return cnt;
}

int main()
{
    int n, *arr, cnt;

    cin >> n;
    arr = new int[n];
    for (int i = 0; i < n; i++)
        cin >> arr[i];

    cnt = selectionSort(arr, n);

    show(arr, n);
    cout << cnt << endl;

    delete[] arr;
}


Measured memory_bytes: 3112
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//

int32_t main()
{
    io;
    long double a, b, n;
    cin>>a>>b>>n;
    long double x = min(b-1, n);
    cout<<1LL*floor(a*x/b);
    return 0;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  int ans = 1;
  for (int i = 2; i <= 100; i *= 2) {
    if (i <= n) ans = i;
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long mod = 1000000007;
long long N, K, A[1 << 18];
vector<long long> L1, L2;

long long getans(int p1, int p2) {
	long long ret = 1;
	for (int i = 0; i < p1; i++) {
		ret *= L1[i];
		ret = (ret + mod * mod) % mod;
	}
	for (int i = 0; i < p2; i++) {
		ret *= -L2[i];
		ret = (ret + mod * mod) % mod;
	}
	return ret;
}

int main() {
	// 入力
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		if (A[i] >= 0) L1.push_back(A[i]);
		else L2.push_back(-A[i]);
	}

	// 場合分け
	if (N == K) {
		cout << getans(L1.size(), L2.size()) << endl;
		return 0;
	}

	// ソート
	sort(L1.begin(), L1.end()); reverse(L1.begin(), L1.end());
	sort(L2.begin(), L2.end()); reverse(L2.begin(), L2.end());

	// 計算
	int c1 = 0, c2 = 0;
	for (int i = 0; i < K; i++) {
		if (L1.size() == c1) { c2++; }
		else if (L2.size() == c2) { c1++; }
		else if (L1[c1] < L2[c2]) { c2++; }
		else { c1++; }
	}

	// 場合分け
	if (c2 % 2 == 1 && L1.size() == 0) {
		long long ans = 1;
		for (int i = L2.size() - K; i < L2.size(); i++) {
			ans *= -L2[i];
			ans = (ans + mod * mod) % mod;
		}
		cout << ans << endl;
		return 0;
	}

	// その他
	if (c2 % 2 == 1) {
		if (L1.size() == c1 || c2 == 0) { c1--; c2++; }
		else if (L2.size() == c2 || c1 == 0) { c1++; c2--; }
		else {
			long long va = L1[c1 - 1], vb = L1[c1];
			long long vc = L2[c2 - 1], vd = L2[c2];
			if (vd * vc < vb * va) { c1++; c2--; }
			else { c1--; c2++; }
		}
	}
	cout << getans(c1, c2) << endl;
	return 0;
}

Measured memory_bytes: 6592