akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct Node
{
	int key;
	Node *p, *l, *r;
} *root = NULL;

void insert(Node *z){
	Node *x, *y;
	y = NULL;
	x = root;
	while(x!=NULL){
		y = x;
		if(z->key < x->key) x = x->l;
		else x = x->r;
	}
	z->p = y;
	if(y==NULL) root = z;
	else if(z->key < y->key) y->l = z;
	else y->r = z;
}
void preP(Node *x){
	if(x==NULL) return;
	printf(" %d",x->key);
	preP(x->l);
	preP(x->r);
}
void inP(Node *x){
	if(x==NULL) return;
	inP(x->l);
	printf(" %d",x->key);
	inP(x->r);
}
Node* find(int k){
	Node *x = root;
	while(x!=NULL && k!=x->key)
		if(k < x->key) x = x->l;
		else x = x->r;
	return x;
}
Node *next(Node *x){
	Node *y = x->r;
	while(y->l) y = y->l;
	return y;
}
void del(Node *x){
	Node *par = x->p;
	Node *son = (x->l)?(x->l):(x->r);
	if(par==NULL) root = son;
	else if(x->l==NULL || x->r==NULL){
		if(par->l == x) par->l = son;
		else par->r = son;
		if(son) son->p = par;
	}
	else{
		son = next(x);
		x->key = son->key;
		del(son);
	}
}
int main()  
{
	char cmd[10];
	int n,t; cin>>n;
	while(n--){
		scanf("%s",cmd);
		if(cmd[0]=='i'){
			Node *z = new Node;
			scanf("%d",&(z->key));
			z->l = z->r = NULL;
			insert(z);
		}
		else if(cmd[0]=='p'){
			inP(root);
			putchar('\n');
			preP(root);
			putchar('\n');
		}
		else if(cmd[0]=='f'){
			scanf("%d",&t);
			puts(find(t)?"yes":"no");
		}
		else{
			scanf("%d",&t);
			del(find(t));
		}
	}
	return 0;
}




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

int main(){
	string spell;
	getline(cin, spell);
    int i = spell.length();
  	if (spell[i-1] == 's'){
    	cout<<spell<<'e'<<'s'<<endl;}
  	else{
  		cout<<spell<<'s'<<endl;}
  	
    return 0;
}

Measured memory_bytes: 3624
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    a=0;
    b=0;
    c=0;
    d=0;
    rep(i,n){
        cin>>str;
        if(str=="AC") a++;
        if(str=="WA") b++;
        if(str=="TLE") c++;
        if(str=="RE") d++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;

    return 0;
}


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

#define Debug(x) x
typedef int regular_int;
#define int ll
typedef long long ll;

int x[300000], B[300000];

regular_int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(12) << fixed;

	int N;
	cin >> N;

	priority_queue<pair<int, int > > q;
	for(int i = 0; i < N; ++i) {
		cin >> x[i];
	}
	for(int i = 0; i < N; ++i) {
		cin >> B[i];
		if(B[i] < x[i]) {
			cout <<  - 1 << endl;
			return 0;
		}
		if(B[i] > x[i])
			q.push(make_pair(B[i], i));
	}
	int cnt = 0;

	while(!q.empty()) {
		int i = q.top().second;
		q.pop();
		int d = B[(i + 1) % N] + B[(i + N - 1) % N];
		int k = (B[i] - x[i]) / d;
		B[i] -= k * d;
        cnt += k;
		if(!k || B[i] < x[i]) {
			cout <<  - 1 << endl;
			return 0;
		}
		if(B[i] > x[i])
			q.push(make_pair(B[i], i));
	}

	cout << cnt << endl;
	return 0;
}


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

using ll = long long;

#define MAXN 3000
ll pizza[MAXN];
ll memo[MAXN][MAXN];




ll mangia(ll a, ll b, ll somma) {
    if (a==b) return pizza[a];
    if (memo[a][b]==-1) memo[a][b]=max(somma-mangia(a+1, b, somma-pizza[a]), somma-mangia(a, b-1, somma-pizza[b]));
    return memo[a][b];
}

ll sum=0;

ll contentezza (ll N, ll V[]) {
    for (ll i=0; i<N; i++) {
        pizza[i] = V[i];
        sum+=V[i];
    }
    memset(memo,-1,sizeof(memo));
    return mangia(0, N-1, sum);
}

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

    ll X = contentezza(N,a);
    ll Y = sum - X;
    ll ans = X-Y;

  	cout << ans << endl;
}


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

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			int[] p = new int[n];
			for(int i = 0;i < n;i++){
				p[i] = scan.nextInt();
			}
			Arrays.sort(p);
			long wait = 0;
			for(int i = 0;i < n-1;i++){
				for(int j = 0;j <= i;j++){
					wait += p[j];
				}
			}
			System.out.println(wait);
		}
	}
}

Measured memory_bytes: 44968
#include<stdio.h>

int compare(const void *a,const void *b){
  return *(int*)a-*(int*)b;
}


int main(){
	
	int N,d[110],i,ans=1;
	
	scanf("%d",&N);
	
	for(i=0;i<N;i++){
		scanf("%d",&d[i]);
	}
	
	qsort(d,N,sizeof(int),compare);
	
	for(i=0;i<N-1;i++){
		if(d[i+1]>d[i]){
			ans++;
		}
		
	}
	
	printf("\n\n%d\n\n",ans);
	
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;
using Int = int_fast64_t;
using Float = long double;

Int gcd(Int a, Int b) {
  while (b > 0) {
    Int c = a;
    a = b;
    b = c % b;
  }
  return a;
}

int main() {
  Int N; cin >> N;
  vector<Int> A(N + 1);
  for (Int i = 1; i <= N; i++) cin >> A[i];
  const Int sqrtN = 316;
  Int K = (N + sqrtN - 1) / sqrtN;

  vector<Int> bucket(K + 1);
  for (Int j = 1; j <= K; j++) for (Int i = 1; i <= min(sqrtN, N); i++)
    bucket[j] = gcd(bucket[j], A[(j - 1) * sqrtN + i]);
  
  auto query = [&] (Int L, Int R) {
    Int result = 0;
    if (!(L <= R)) return result;
    for (Int j = 1; j <= K; j++) {
      Int a = (j - 1) * sqrtN + 1;
      Int b = j * sqrtN;
      if (L <= a && b <= R)
        result = gcd(result, bucket[j]);
      else {
        for (Int i = max(a, L); i <= min(b, R); i++)
          result = gcd(result, A[i]);
      }
    }
    return result;
  };

  Int res = 0;
  for (Int i = 1; i <= N; i++)
    res = max(res, gcd(query(1, i - 1), query(i + 1, N)));
  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1024
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

bool palin(string x){
	for(int i = 0, j = sz(x)-1; i < j; ++i, --j)
		if(x[i] != x[j]) return false;
	return true;
}

int main(){

	fastio;
	string x;
	cin >> x;
	int n = sz(x);
	if(palin(x) && palin(x.substr(0,(n-1)/2)) && palin(x.substr((n+3)/2-1,1000)) ){
		cout << "Yes" << endl;
	}else cout << "No" << endl;

	return 0;
}


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

int main(){
	int N, M, sum = 0;
  	cin >> N >> M;
  	int a;
  	for(int i =0; i < M; i++){
      cin >> a;
      sum += a;
    } 
  	if(N - sum >= 0)cout << N - sum << endl;
  	else cout << -1 << endl;
  
  return 0;
  	
}


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

///--->>> CONTAINERS <<<---///
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vector< ll > >;
using vpi = vector<pair<ll,ll> >;
using pi = pair<ll,ll>;
using st = set<ll>;
using stk = stack<ll>;
using kiwi = queue<ll>;
using pkiwi = priority_queue<ll>;
using mp = map<ll,ll>;
using ump = unordered_map<ll,ll>;

///--->>> MACROS<<<---///
const ll mx = 1e5+123;
#define MOD 1000000007
#define REP(i,n) for (ll i=1;i<=n;++i)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

///--->>>OPTIMIZE<<<---///
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

///--->>> DEBUGGER<<<---///
#define dbg(args...) do {cerr<<#args<<" : "; diraf(args); } while(0)
void diraf ()  {        cerr << endl;}
template < typename T, typename ... hello>void diraf( T arg, const hello &... rest) {cerr<<arg<< ' ';diraf(rest...);}

int main(){
    fastio;
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    ///cout<<fixed<<setprecision(20);
    ll d, t, s, v; cin>>d>>t>>s;
    v = s * t;
    if(v>=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    int x = a+b*5+c*10+d*50+e*100+f*500;
    cout<<(x>=1000)<<endl;
    return 0;
}

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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define dup(x,y) (((x)+(y)-1)/(y))
#define vecadd emplace_back

typedef long long ll;

int main(){
  int n,m;
  cin>>n>>m;
  priority_queue<int> que;
  rep(i,n){
    int a;
    cin>>a;
    que.push(a);
  }
  
  rep(i,m){
    int num=que.top();
    que.pop();
    num/=2;
    que.push(num);
  }
  
  ll ans=0;
  rep(i,n){
    ans+=que.top();
    que.pop();
  }
  
  cout<<ans;
  
  return 0;
}


Measured memory_bytes: 892
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) cout << (x) << endl;
#define ENDL cout << endl;
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

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;}
struct Init_On{
    Init_On(){
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(16);
    }
};

signed main(){
    Init_On s;
    int n , m , x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<int> comp(m);
    vector<vector<int>> a(12,vector<int>(12));
    int ans = INF;
    rep(i , n){
        cin >> c[i];
        rep(j ,m){
            cin >> a[i][j];
        }
    }
    rep(st , 1<<n){
        int cost = 0;
        comp.clear();
        comp.resize(m);
        rep(i ,n){
            if(st>>i&1) {
                rep(j , m){
                    comp[j] += a[i][j];
                }
                cost += c[i];
            }
        }
        bool f = true;
        rep( i , m){
            if(comp[i] < x) { f = false; break; }
        }
        if(f) ans = min( ans , cost);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3660
import sys
import itertools
input = sys.stdin.readline


n=int(input())
a=list(map(int, input().split()))
b=itertools.accumulate(a)
b=[0]+list(b)
dp=[[0]*(n) for i in range(n)]

x=float('inf')
for i in range(n-1,-1,-1):
    for j in range(i+1,n):
        if j>=i+2:
            for k in range(i,j):
                x=min(dp[i][k]+dp[k+1][j],x)
            dp[i][j]=x+(b[j+1]-b[i])
            x=float('inf')
        else:
            dp[i][j]=b[j+1]-b[i]
print(dp[0][-1])



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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int h, w;
char x[12][12];
char y[12][12];
bool use[12];
bool saw[12];
int key = -1;

bool check() {
    memset(saw,0,sizeof(saw));
    if (key != -1) saw[key] = true;
    rep(i,w) {
        if (saw[i]) continue;
        for (int j = i+1; j < w; j++) {
            if (saw[j]) continue;
            bool ok = true;
            rep(k,h) {
                if (y[k][i] != y[h-1-k][j]) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                saw[i] = true;
                saw[j] = true;
                break;
            }
        }
        if (!saw[i]) return false;
    }
    return true;
}

bool dfs(int v, int pos) {
    while (v != h && use[v]) v++;
    if (v == h) {
        return check();
    }
    use[v] = true;
    rep(i,w) y[pos][i] = x[v][i];
    for (int i = v+1; i < h; i++) {
        if (use[i]) continue;
        rep(j,w) y[h-1-pos][j] = x[i][j];
        use[i] = true;
        if (dfs(v+1, pos+1)) return true;
        use[i] = false;
    }
    use[v] = false;
    return false;
}

int main() {
    cin >> h >> w;
    rep(i,h) rep(j,w) cin >> x[i][j];
    if (h%2 == 1) {
        if (w%2 == 1) {
            rep(i,h) {
                rep(j,w) {
                    key = j;
                    memset(use, 0, sizeof(use));
                    use[i] = true;
                    if (dfs(0, 0)) {
                        puts("YES");
                        return 0;
                    }
                }
            }
        } else {
            rep(i,h) {
                memset(use, 0, sizeof(use));
                use[i] = true;
                if (dfs(0, 0)) {
                    puts("YES");
                    return 0;
                }
            }
        }
    } else {
        if (w%2 == 1) {
            rep(i,w) {
                memset(use, 0, sizeof(use));
                key = i;
                if (dfs(0, 0)) {
                    puts("YES");
                    return 0;
                }
            }
        } else {
            memset(use, 0, sizeof(use));
            if (dfs(0, 0)) {
                puts("YES");
                return 0;
            }
        }
    }
    puts("NO");
}
































Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int p[1000000];
void gray(int s,int n,int g) {
	if(n==0) return;
	for(int i=0;i<(1<<(n-1));i++) {
		p[s+i]^=(g<<(n-1));
		p[s+i+(1<<(n-1))]^=((g^1)<<(n-1));
	}
	gray(s,n-1,0);
	gray(s+(1<<(n-1)),n-1,1);
}
void solve(int s,int n,int a,int b) {
	if((__builtin_popcount(b))==1) { //Bazni slucaj
		gray(s,n,0);
		int t1=(1<<(n-1));
		int t2=b;
		for(int i=0;i<(1<<n);i++) {
			if(((p[i+s]&t1)^(p[i+s]&t2)) && ((((p[i+s]&t1)^(p[i+s]&t2)))^(t1^t2))) p[i+s]^=(t1^t2);
		}
		for(int i=0;i<(1<<n);i++) p[i+s]^=a;
		return;
	}
	int t1=(1<<(n-1));
	int t2=t1;
	while((b&t2)==0) t2>>=1;
	gray(s,n-1,0);
	solve(s+t1,n-1,t1^(t1>>1),(b^t2^(t1>>1)));
	for(int i=0;i<(1<<n);i++) {
		if(((p[i+s]&t1)^(p[i+s]&t2)) && ((((p[i+s]&t1)^(p[i+s]&t2)))^(t1^t2))) p[i+s]^=(t1^t2);
	}
	for(int i=0;i<(1<<n);i++) p[i+s]^=a;
}
int main()
{
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	if(((__builtin_popcount((a^b)))&1)==0) {
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	solve(0,n,a,b^a);
	for(int i=0;i<(1<<n);i++) printf("%d ",p[i]);
	return 0;
}

Measured memory_bytes: 1536
var lines =[];

var readline = require("readline");
var rl = readline.createInterface({
  input:  process.stdin,
  output: process.stdout
});

rl.on('line',function(x){
  lines.push(x);
});

rl.on('close',function(){
 var t = Number(lines[0].split(" ")[0]);
 var x = Number(lines[0].split(" ")[1]);

 console.log(t/x);
});

Measured memory_bytes: 7628
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
if(a*b%2==0){
System.out.println("No");
        }else{
             System.out.println("Yes");}
scan.close();
}
}

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



int main() {
  vector<int> a(3);
  rep(i,3){
      cin >> a[i];
  }
  sort(a.begin(),a.end());
  if((a[0] == a[1] && a[1] != a[2]) ||
  (a[0] != a[1] && a[1] == a[2])) cout << "Yes" << endl;
  else cout << "No" << endl; 
  
}

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

int checkOdd(int x){
    return x % 2;
}

int main(){
    int n, tmp, f;
    cin >> n;
    REP(i, n){
        cin >> tmp;
        if(i == 0) f = checkOdd(tmp);
        else f ^= checkOdd(tmp);
    }
    if(f == 0) cout << "YES" << endl; 
    else cout << "NO" << endl;

    return 0;
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N; cin >> N;
	ll maxn = 1001;
	vector<bool> is_prime(maxn, true);
	vector<ll> v(maxn, 0);
	is_prime[0] = is_prime[1] = false;
	rep(i, maxn) {
		if (!is_prime[i]) continue;
		ll j = 2 * i;
		while (j < maxn) {
			is_prime[j] = false;
			j += i;
		}
	}


	rep(i, N + 1) {
		ll n = i;
		ll k = 0;
		while (n > 1) {
			while (not is_prime[k]) k++;
			while (n % k == 0) {
				v[k]++;
				n /= k;
			}
			k++;
		}
	}
	ll ans = 1;
	sort(all(v));
	reverse(all(v));
	for (auto a : v) {
		if (a == 0) break;
		ans = ans * (a+1) % MOD;
	}
	cout << ans << endl;
}

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

int votes[26];

int main()
{
	while (true) {
		int n;
		std::cin >> n;

		if (n == 0) return 0;

		std::memset(votes, 0, sizeof(votes));

		bool fixed = false;
		int max_votes = 0;
		int maxc = 0;

		for (int i = 1; i <= n; i++) {
			char c;
			std::cin >> c;
			if (fixed) continue;

			int cn = c - 'A';
			votes[cn]++;

			if (votes[cn] > max_votes) {
				max_votes = votes[cn];
				maxc = cn;
			}

			fixed = true;
			for (int j = 0; j < 26; j++) {
				if (j == maxc) continue;
				if (votes[j] + (n - i) >= max_votes) {
					fixed = false;
					break;
				}
			}

			if (fixed) {
				std::cout << (char)(maxc + 'A') << " " << i << std::endl;
			}
		}

		if (!fixed)
			std::cout << "TIE" << std::endl;
	}
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pi acos(-1)

using namespace std;

int main() {
    nl // 

    int x; cin >> x;
    cout << (x >= 30 ? "Yes":"No");

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    double ans = double(w * h) / 2;
    int a = (x * 2 == w && y * 2 == h ? 1 : 0);
    printf("%.20f %d\n", ans, a);
}


Measured memory_bytes: 3736
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	int a, b;
	cin >> a >> b;

	println(max(a - 2 * b, 0));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e12;
const int MOD = 1e9 + 7;

#define MAX_N 100
#define MAX_V 1000

ll dp[MAX_N + 1][MAX_N * MAX_V + 1];

signed main(){
	int N;
	ll W;
	cin >> N >> W;
	int w[N],v[N];
	REP(i,N){
		cin >> w[i] >> v[i];
	}
	for(int i = 0; i <= MAX_N; i++){
		for(int j = 0; j <= MAX_N * MAX_V; j++){
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= MAX_N * MAX_V; j++){
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			if(j - v[i] >= 0){
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
			}
			
		}
	}
	ll ans = 0;
	for(ll i = 0; i <= MAX_V * MAX_N; i++){
		if(dp[N][i] <= W){
			ans = max(ans, i);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 79104
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
using namespace std;

int main() {
	int a,b,c,d,e,f;
	int n,m,h;
	int M1,M2,M3,M4,M5,M6;
	cin>>a>>b>>c>>d>>e>>f;
	M1=a,M2=b,M3=c,M4=d,M5=e,M6=f;
	cin>>n;

	for (int i=0;i<n;i++){
		cin>>m>>h;
		if(m==M1){
			if(h==M2)cout<<M3;
			if(h==M3)cout<<M5;
			if(h==M4)cout<<M2;
			if(h==M5)cout<<M4;
		}
		if(m==M2){
			if(h==M6)cout<<M3;
			if(h==M3)cout<<M1;
			if(h==M1)cout<<M4;
			if(h==M4)cout<<M6;
		}
		if(m==M3){
			if(h==M6)cout<<M5;
			if(h==M5)cout<<M1;
			if(h==M1)cout<<M2;
			if(h==M2)cout<<M6;
		}
		if(m==M4){
			if(h==M1)cout<<M5;
			if(h==M5)cout<<M6;
			if(h==M6)cout<<M2;
			if(h==M2)cout<<M1;
		}
		if(m==M5){
			if(h==M3)cout<<M6;
			if(h==M6)cout<<M4;
			if(h==M4)cout<<M1;
			if(h==M1)cout<<M3;
		}
		if(m==M6){
			if(h==M2)cout<<M4;
			if(h==M4)cout<<M5;
			if(h==M5)cout<<M3;
			if(h==M3)cout<<M2;
		}
		cout<<endl;
	}


	return 0;
}

Measured memory_bytes: 3100
#include <iostream>

int main() {
	int a,b;
	std::cin >> a >> b;

	if (a < b) {
		std::cout << "a < b" << std::endl;
	}
	else if (a > b) {
		std::cout << "a > b" << std::endl;
	}
	else {
		std::cout << "a == b" << std::endl;
	}
}


Measured memory_bytes: 3104
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define PII pair<LL,LL>
#define sqr(x) (x)*(x)
#define FOR(i,a,b) for (LL i=(a);i<=(b);++i)
#define ROF(i,b,a) for (LL i=(b);i>=(a);--i)
typedef long long LL;
inline LL read(){
	LL x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}

const LL MAXN=300005,INF=10000000000000000LL;
LL n,m,a[MAXN],b[MAXN];
int main(){
	n=read(); m=0;
	FOR(i,1,n) a[i]=read();
	while (1){
		sort(a+1,a+1+n);
		FOR(i,1,n) b[i]=a[i]/n;
		//FOR(i,1,n) cout<<a[i]<<' '<<b[i]<<endl;
		LL k=n;
		while (k>1&&b[k-1]==b[k]) k--;
		//cout<<k<<endl;
		if (k==1) {
			m+=n*(a[n]-n+1);
			break;
		}
		LL x=(a[k]-a[k-1])/(n+1),y=n-k+1;
		if (x==0) x++;
		m+=x*y;
		FOR(i,1,k-1) a[i]+=x*y;
		FOR(i,k,n) a[i]-=(n-y+1)*x;
	}
	cout<<m<<endl;
	
	return 0;
}

/*
*/


Measured memory_bytes: 2304
n = gets.to_i
as = []
n.times do
  as << gets.split.map(&:to_i)
end

cx = nil
cy = nil
h = nil

(0..100).each do |x|
  (0..100).each do |y|
    a = as.find{|a| a[2] != 0}
    h = a[2] + (a[0] - x).abs + (a[1] - y).abs
    flg = as.all? do |a|
      a[2] == [h - (a[0] - x).abs - (a[1] - y).abs, 0].max
    end
    if flg
      puts "#{x} #{y} #{h}"
      exit
    end
  end
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int b[100010];
int main(){
	int n;
	while(~scanf("%d",&n)){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i=0;i<n;i++) cin>>a[i];
		for(int i=0;i<n;i++){
			b[a[i]-1]++;
			b[a[i]+1]++;
			b[a[i]]++;
		}
		int max=0,h=0;
		for(int i=0;i<=100001;i++){
			if(b[i]>max){
				max=b[i];
				h=i;
			}
		}
		cout<<max<<endl;
	} 
	return 0;
} 

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

long long B, N, a, b;

long long grundy(long long A, long long K){
    long long x, k;
    while(A >= K){
        x = A / K;
        k = A % K;
        k %= x + 1;
        if(k == 0)return x;
        A = (K - 1) * x + k - 1;
    }
    return 0;
}

int main(){
    scanf("%lld", &N);
    for(int i = 0; i < N; ++i){
        scanf("%lld%lld", &a, &b);
        B ^= grundy(a, b);
    }
    puts(B ? "Takahashi" : "Aoki");
    return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  int lmax=0,rmin=100000;
  for(int i=0;i<M;i++){
    int l,r;
    cin >> l >> r;
    lmax=max(l,lmax);rmin=min(r,rmin);
  }
  cout << max(0,rmin-(lmax-1)) << endl;
  return 0;
}

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

int main(void) {

    int N; cin >> N;
    string S; cin >> S;

    int cnt = 0;
    for (int i = N-1; i >= 0; i--) {
        if (S[i] == ')') {
            cnt++;
        } else {
            if (cnt > 0) {
                cnt--;
            } else {
                S += ')';
            }
        }
    }
    cout << string(cnt, '(') + S << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static int func(int n) {
		int res=0;
		if(n%2==0) {
			res=n/2;
		}
		else if(n%2==1) {
			res=3*n+1;
		}
		return res;
	}

	public static void main(String[] args) {
		int ans=0;
		int []a=new int[1000000];
		Scanner sc=new Scanner(System.in);
		int s=sc.nextInt();
		a[0]=s;
		for(int i=1;i<a.length;i++) {
			a[i]=func(a[i-1]);
			for(int j=0;j<i;j++) {
				if(a[i]==a[j]) {
					ans=i+1;
					break;
				}
			}
			if(ans!=0)break;
		}
		System.out.println(ans);
	}


}


Measured memory_bytes: 25044
//NAME-ADITYYA OJHA
                                               /*
                                                      GURU(MENTOR)-AARADHYA
                                               */
/*
 *     Heart beats fast
 *         Colors and promises
 *             How to be brave
 *                 How can I love when I am afraid to fall...
                                             (courtesy-amnesiac_dusk)
 */

#include <bits/stdc++.h>
#define ll long long int
#define forin for(int i=0;i<n;i++)
#define pb push_back
#define vx vector<ll> x
#define vy  vector<ll> y
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  f   first
#define  s   second
#define mod 1000000007
using namespace std;

/*
check for corner cases(for n==1)
 check for int overflow
 run on some sample cases before submitting
*/

/*FERMAT THEOREM

       pow(x,m-1)%m=1 (x and m are co-prime)
*/
/*MODULAR INVERSE

        pow(x,-1)=pow(x,m-2) (x and m are co-prime)
*/

/*
ll  mode(ll x,ll n,ll mod)
{
    if(n==0)return 1%mod;

    ll u=mode(x,n/2,mod);
    u=(u*u)%mod;
    if(n & 1)u=(u*x)%mod;
}
*/




const ll INF=1e11+ 5;
int main()
{
   fast;
    ll n;
    cin>>n;

     string s[n];
     ll cnt=0,cnt1=0,cnt2=0,cnt3=0;
     for(int i=0;i<n;i++)
     {
         cin>>s[i];
         if(s[i]=="AC")cnt++;
         else if(s[i]=="WA")cnt1++;
         else if(s[i]=="TLE")cnt2++;
         else
            cnt3++;
     }
     cout<<"AC"<<" "<<"x"<<" "<<cnt<<endl;
     cout<<"WA"<<" "<<"x"<<" "<<cnt1<<endl;
     cout<<"TLE"<<" "<<"x"<<" "<<cnt2<<endl;
     cout<<"RE"<<" "<<"x"<<" "<<cnt3<<endl;


}


































Measured memory_bytes: 6784
'use strict';
const main = val => {
  const a = parseInt(val[0].split(' ')[0], 10);
  const b = parseInt(val[0].split(' ')[1], 10);
  let ans = Math.ceil((b-1)/(a-1));
  console.log(ans);
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    int N, K, C;
    string S;
    cin >> N >> K >> C >> S;
    
    vector<int> L(K, N), R(K, 0);   

    int k = 0;
    rep(i, S.size()) {
        if(S[i] == 'x') continue;
        
        L[k++] = i;
        i += C; 

        if(k == K) break;
    }
    for(int i = S.size() - 1; i >= 0; i--){
        if(S[i] == 'x') continue;

        R[--k] = i;
        i -= C;

        if(k == 0) break; 
    }
    
    for(int k = 0; k < K; k++){
        if(L[k] == R[k]) Cout(L[k]+1);
    }

}


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

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

    vector<long long int> a(N), b(N), c(M), d(M);
    for( int i = 0; i < N; ++i )
        cin >> a[i] >> b[i];
    for( int i = 0; i < M; ++i )
        cin >> c[i] >> d[i];

    vector<long long int> ans(N, 0), dis(M);
    for( int i = 0; i < N; ++i ){
        for( int j = 0; j < M; ++j ) // 各チェックポイントとの距離
            dis[j] = abs(a[i]-c[j]) + abs(b[i]-d[j]);
        for( int j = 1; j < M; ++j ) // 距離が最小のチェックポイント
            if( dis[j] < dis[ans[i]] ) ans[i] = j;
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <list>
#define ll long long
using namespace std;
int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    list<ll> b;
    for(int i=0;i<n;i++){        
        cin>>a[i];        
    }
    for(int i=0;i<n;i++){
        if(0==i%2){
            b.push_back(a[i]);
        }else{
            b.push_front(a[i]);
        }
    }
    if(1==n%2) reverse(b.begin(),b.end());

    for(auto iter=b.begin();iter!=b.end();iter++){
        cout<<*iter<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 9984
import java.util.*;
public class Main {
	
	public static long gcd(long a, long b) {
		if(b == 0)
			return a;
		else
			return gcd(b, a % b);
	}
	
	public static long lcm(long a, long b) {
		return a * (b / gcd(a, b));
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long ans = sc.nextLong();
		for(int i = 1; i < N; i++)
			ans = lcm(ans, sc.nextLong());
		System.out.println(ans);
	}

}

Measured memory_bytes: 22612
def main():
  N,K=map(int,input().split())
  h=list(map(int,input().split()))
  DP=[0]*N
  for i in range(1,N):
    min_k=float('inf')
    min_k=min([DP[j]+abs(h[i]-h[j]) for j in range(max(i-K,0),i)])
    DP[i]=min_k
    pass
  print(DP[-1])

if __name__ == '__main__':
  main()



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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){

  int a[4];
  rep(i,4)cin >> a[i];
  if(a[0]+a[1] > a[2]+a[3])cout << "Left" << endl;
  else if(a[0]+a[1] == a[2]+a[3])cout << "Balanced" << endl;
  else cout << "Right" << endl;




  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i,a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}

int main()
{
    int k;
    string s;
    cin >> k >> s;
    if(s.size()>k){
        REP(i,k){
            cout << s[i];
        }
        cout << "..." << endl;
    }
    else{
        cout << s << endl;
    }
}

Measured memory_bytes: 3624
def yes!; puts'Yes'; exit end
def no!; puts'No'; exit end

(N,),A,B = $<.map{|ln| ln.split.map(&:to_i) }

I = (0...N).sort_by{|i| B[i] }
LB = A.map{|a|
	I.bsearch_index{|i| a<=B[i] }||N
}
LB.sort.then{|lbs|
	no! unless lbs.each_with_index.all?{|lb,i| lb<=i }
	yes! if lbs.each_cons(2).any?(&:uniq!)
}

i,v,V = 0,0,[nil]*N
until V[i]
	V[i] = v+=1
	i = I[LB[i]]
end

v<N ? yes! : no!


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

int main() {
  int64_t H ,W;
  cin >> H >> W;
  
  int64_t C = H * W;
  
  if(H == 1 || W == 1){
    cout << "1" << endl;
  }
  
  
  else if(C % 2 == 0){
    cout << C / 2 << endl;
  }
  
  else{
    cout << C / 2 + 1 << endl;
  }
  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m, a;
    while(cin >> n >> m >> a, n|m|a){
        vector<int> perm(n);
        for (int i = 0; i < n; ++i) {
            perm[i] = i+1;
        }
        vector<array<int, 3>> v(m);
        for (int i = 0; i < m; ++i) {
            int h, p, q;
            scanf("%d %d %d", &h, &p, &q);
            v[i] = {h, p-1, q-1};
        }
        sort(v.begin(), v.end());
        for (int i = 0; i < m; ++i) {
            swap(perm[v[i][1]], perm[v[i][2]]);
        }
        cout << perm[a-1] << "\n";
    }
    return 0;
}



Measured memory_bytes: 3224
import sys
input = sys.stdin.readline

def fib2(n):
    n0,n1 = 1,1
    ans = 1
    for i in range(2,n+1):
        n0,n1 = n1,ans
        ans = n0 + n1
    return ans

if __name__ == "__main__":
    n = int(input())
    print(fib2(n))



Measured memory_bytes: 5604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_133
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            long[] lr = ReadLongs();
            long l = lr[0];
            long r = lr[1];
            if (r-l >= 2019)
            {
                WriteLine(0);
            }
            else
            {
                bool[] ok = new bool[2019];
                long ll = l % 2019;
                long rr = r % 2019;
                if (ll < rr)
                {
                    for (long i = ll; i <= rr; i++) ok[i] = true;
                }
                else
                {
                    for (long i = ll; i < 2019; i++) ok[i] = true;
                    for (long i = 0; i <=rr; i++) ok[i] = true;
                }

                long res = 2018;
                for (long i = 0; i < 2019; i++)
                {
                    if (!ok[i]) continue;
                    for (long j = i + 1; j < 2019; j++)
                    {
                        if (!ok[j]) continue;

                        res = Min(res, (i * j) % 2019);
                    }
                }

                WriteLine(res);
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
#include <stdio.h>

int main(int argc, char *argv){
	
	int sec;
	int min;
	int hour;
	
	scanf("%d", &sec);
	
	min = sec / 60;
	hour = min / 60;
	
	sec %= 60;
	min %= 60;
	
	printf("%d", hour);
	printf(":%d", min);
	printf(":%d\n", sec);
	
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main(){
    ll n,m;cin>>n>>m;
    ll l[m],r[m];
    for(ll i=0;i<m;i++){
        cin>>l[i]>>r[i];
    }
    ll la,ra;
    la=1;
    ra=n;
    for(ll i=0;i<m;i++){
        la=max(la,l[i]);
        ra=min(ra,r[i]);
        if(ra<la){
            i=m;
            la=0;
            ra=-1;
        }
    }
    cout<<ra-la+1<<endl;
    return 0;
}



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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);
const int  MAX=2000;
int dp[10007][300],n,capacity,value[MAX],wt[MAX];

int solve(int w , int n) {
    if(dp[w][n] != -1 ) {
        return dp[w][n];
    }
    if(w < 0 || n<0) {
        return dp[w][n]=0;
    }
    if(wt[n] > w ) {
        return dp[w][n] = solve(w,n-1);
    } else {
        return dp[w][n] = max(solve(w-wt[n],n-1)+value[n],solve(w,n-1));
    }
    return dp[w][n];
}

int main()
{
	ios_base::sync_with_stdio(false);
    for(int i=0;i<10007;i++) {
        for(int j=0;j<300;j++) {
            dp[i][j]=-1;
        }
    }
    cin>>n>>capacity;
    for(int i=1;i<=n;i++) {
        cin>>value[i]>>wt[i];
    }
    cout<<solve(capacity,n)<<"\n";
    

	return 0;

}

Measured memory_bytes: 12936
LI = lambda: list(map(int, input().split()))
n = int(input())
a = LI()

maxnodes = [1]
sumnodes = 0

if n == 0:
    if a[0] == 1:
        print(1)
    else:
        print(-1)
else:
    for d in range(1, n+1):
        tmp = (maxnodes[-1]-a[d-1])*2
        if tmp < 0:
            print(-1)
            break
        else:
            maxnodes.append(tmp)
    else:
        if maxnodes[d] < a[d]:
            print(-1)
        else:
            maxnodes[d] = a[d]
            sumnodes += a[d]
            for d in range(n-1, -1, -1):
                maxnodes[d] = min(maxnodes[d+1]+a[d], maxnodes[d])
                sumnodes += maxnodes[d]
            print(sumnodes)

Measured memory_bytes: 678912
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		boolean[] S = new boolean[13];
		boolean[] H = new boolean[13];
		boolean[] C = new boolean[13];
		boolean[] D = new boolean[13];
        for(int i=0;i<N;i++){
            String[] a = br.readLine().split(" ");
        	switch(a[0].charAt(0)){
        	case 'S':
        		S[Integer.parseInt(a[1])-1]=true;
        		break;
        	case 'H':
        		H[Integer.parseInt(a[1])-1]=true;
        		break;
        	case 'C':
        		C[Integer.parseInt(a[1])-1]=true;
        		break;
        	case 'D':
        		D[Integer.parseInt(a[1])-1]=true;
        		break;
        	}
        }
        for(int i=0;i<13;i++) if(!S[i]) System.out.println("S "+(i+1));
        for(int i=0;i<13;i++) if(!H[i]) System.out.println("H "+(i+1));
        for(int i=0;i<13;i++) if(!C[i]) System.out.println("C "+(i+1));
        for(int i=0;i<13;i++) if(!D[i]) System.out.println("D "+(i+1));
	}
}

Measured memory_bytes: 16932
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(ll i = s; i < n; i++)
const ll maxn = 505;
ll ans[maxn][maxn];
ll integer[10005];
vector<ll> p;
ll n;
ll dx[] = {0,0,1,-1};
ll dy[] = {1,-1,0,0};

void generatingprimes(){
	rep(i,2,10005){
		while(integer[i])i++;
		p.push_back(i);
		for(ll j = 2*i; j < 10000; j+=i){
			integer[j] = 1;
		}
	}
	// for(auto prime:p)cout<<prime<<" ";
	return;
}

inline ll entry(ll a, ll b){
	return p[(a+b)/2]*p[(a-b)/2+749];
}

inline ll lcm(ll a, ll b){
	return a*(b/__gcd(a,b));
}

int main(){
	cin>>n;
	generatingprimes();
	// cout<<p[1000]<<endl;
	rep(i,0,n){
		if(i%2==1)for(ll j = 1; j < n; j+=2){
			ans[i][j] = entry(i,j);
		}else for(ll j = 0; j < n; j+=2){
			ans[i][j] = entry(i,j);
		}
	}
	rep(i,0,n){
		if(i%2==0) for(ll j = 1; j<n; j+=2){
			ll tmp = 1;
			rep(k,0,4){
				ll nx = i+dx[k];ll ny =j+dy[k];
				if(nx>=n||nx<0||ny>=n||ny<0)continue;
				tmp = lcm(tmp,ans[nx][ny]);
			}
			ans[i][j] = tmp+1;
		}else for(ll j = 0; j < n; j+=2){
			ll tmp = 1;
			rep(k,0,4){
				ll nx = i+dx[k];ll ny =j+dy[k];
				if(nx>=n||nx<0||ny>=n||ny<0)continue;
				tmp = lcm(tmp,ans[nx][ny]);
			}
			ans[i][j] = tmp+1;
		}
	}
	if(n==2)ans[0][1] = (ans[1][0]-1)*2+1;
	rep(i,0,n){
		rep(j,0,n){
			cout<<ans[i][j]<<" ";
		}
		cout<<endl;
	} 
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n;
    while(cin >>n,n){
        auto f = [&](int y, int x){
            return y*n+x;
        };

        const int V = n*n;
        vector<vector<int>> G(V);
        rep(i,n)rep(j,n){
            int x,y;
            cin >>x >>y;

            int u = f(i,j), v = f(y,x);
            G[u].pb(v);
            G[v].pb(u);
        }

        int ans = 0;
        vector<bool> vis(V);
        rep(i,V)if(!vis[i]){
            vis[i] = true;
            ++ans;
            queue<int> que({i});
            while(!que.empty()){
                int v = que.front();
                que.pop();
                for(int e:G[v])if(!vis[e]){
                    vis[e] = true;
                    que.push(e);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3324
import java.util.Scanner;

public class Main {
    
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        
        String[] numbers = scanner.nextLine().split(" ");
        int a = Integer.parseInt(numbers[0]);
        int b = Integer.parseInt(numbers[1]);
        
        System.out.println(String.format("%d %d %.6f", a/b, a%b, (double)a/(double)b));
    }
}


Measured memory_bytes: 26324
n = int(input())
s = input()

count_black = 0
count_white = 0
a = n + 1
cnt_white = [0] * a
cnt_black = [0] * a
result = []

for i in range(n):
    if s[i] == ".":
        count_white += 1

cnt_white[0] = count_white

for i in range(n):
    if s[i] == "#":
        count_black += 1
    else:
        count_white -= 1
    cnt_white[i+1] = count_white
    cnt_black[i+1] = count_black

for i in range(n+1):
    result.append(cnt_black[i] + cnt_white[i])

ans = min(result)

print(ans)


Measured memory_bytes: 20904
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n, k;
    string s;
    cin >> n >> s >> k;
    char c = s[k-1];
    for(int i=0;i<n;++i){
        if(s[i]!=c) s[i] = '*';
    }
    cout << s << endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s0 = [list(input()) for _ in range(h)]
s = [["0"]*(w+2)]+[["0"]+s0[i]+["0"] for i in range(h)]+[["0"]*(w+2)]
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == ".":
            s[i][j] = "{0}".format([s[i-1][j-1], s[i-1][j], s[i-1][j+1],
                                s[i][j-1], s[i][j+1], s[i+1][j-1],
                                s[i+1][j], s[i+1][j+1]].count("#"))
for i in range(1, h+1):
    print(''.join(s[i][1:w+1]))


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll Pow(ll A, ll N){
  if (N == 0) return 1;
  if (N % 2 == 0) return Pow(A * A % MOD, N / 2);
  return Pow(A * A % MOD, N / 2) * A % MOD;
}

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

  ll ans = Pow(10, N);
  ans -= 2 * Pow(9, N); ans %= MOD;
  ans += Pow(8, N); ans %= MOD;
  if (ans < 0) ans += MOD;
  cout << ans << endl;

  return 0;
}


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

int main() {
	int n;
	cin>>n;
	int an=0;
	for(int i=1;i<=n;i++){
		int o=0,v=i;
		while(v){
			o^=1;
			v/=10;
		}
		an+=o;
	}
	cout<<an;
	return 0;
}

Measured memory_bytes: 256
#n=int(input())
n,k=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

first = al[0]
for i in range(k, n):
    last = al[i]
    if first < last :
        print('Yes')
    else:
        print('No')
    first = al[i-k+1]




Measured memory_bytes: 31616
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 2e5 + 7;
const int maxm = 1e6 + 7;
const int ALP = 26;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;

long long poww(long long a,long long b)
{
	long long res=1,base=a;
	while(b)
	{
		if(b&1)
			res=(res*base)%mod;
		base=(base*base)%mod;
		b>>=1;
	}
	return res;
}

long long inv(long long x)
{
	return poww(x,mod-2);
}

int n;
vector<int> G[maxn];
long long ans[maxn];
int siz[maxn];

void dfs(int cur,int fa)
{
	siz[cur]=1;
	for(int x:G[cur])
	{
		if(x==fa)
			continue;
		dfs(x,cur);
		siz[cur]+=siz[x];
	}
}

vector<long long>tmp;

void calc(int cur,int fa)
{
	tmp.clear();
	for(int x:G[cur])
	{
		if(x==fa)
			continue;
		tmp.push_back(inv(poww(2,siz[x])));
	}
	if(fa!=0)
		tmp.push_back(inv(poww(2,n-siz[cur])));
	ans[cur]=1;
	long long res=1;
	for(long long x:tmp)
		res=(res*x)%mod;
	ans[cur]=(ans[cur]-res+mod)%mod;
	long long sum=1;
	for(long long x:tmp)
		sum=(sum*x)%mod;
	res=0;
	for(long long x:tmp)
		res=(res+sum*inv(x)%mod*(1-x+mod)%mod)%mod;
	ans[cur]=(ans[cur]-res+mod)%mod;
	ans[cur]=(ans[cur]*inv(2))%mod;
	for(int x:G[cur])
	{
		if(x==fa)
			continue;
		calc(x,cur);
	}
}
int main()
{
	//freopen("1.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1,0);
	calc(1,0);
	long long res=0;
	for(int i=1;i<=n;i++)
		res=(res+ans[i])%mod;
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 31360