akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; cin >> s;
	if(s.size() < 26){
		for(char i = 'a'; i <= 'z'; i++){
			if(count(s.begin(), s.end(), i) == 0){
				s.push_back(i);
				break;
			}
		}
	} else {
	string t;
	while(!s.empty()){
		bool found = false;
		for(auto & c : t) if(c > s.back()){
			s.back() = c;
			found = true;
			break;
		}
		if(found) break;
		t.push_back(s.back()); s.pop_back();
	}
	}
	if(s.empty()) cout << -1 << endl;
	else cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,k;
    cin>>a>>b>>k;
    int index=0;
    for(int i=a*b;i>=1;i--){
        if(a%i==0 && b%i==0){
            index++;
            if(index==k){
                cout << i<<endl;
                return 0;
            }
        }
    }
    return 0;
}


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

using namespace std;

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

  vector<int> h(N); for(int i=0;i<N;i++) cin>>h[i];
  vector<unsigned long long> dp(N+K,1LL<<60);
  dp[0]=0;
  for(int i=0;i<(N-1);i++){
    for(int j=1;j<=K;j++){
      dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
    }
  }

  cout<<dp[N-1]<<endl;

  return 0;
}




Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    deque<char> ss, tt;
    for(char c : s) ss.push_back(c);
    for(char c : t) tt.push_back(c);
    bool ans = false;
    for(int i = 0; i < tt.size(); i++) {
        ans |= ss == tt;
        tt.push_back(tt.front());
        tt.pop_front();
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void display(vector<int>, int);

int main()
{
    lol result{0};
    lol n; cin >> n;
    //int k; cin >> k;
    
    vector<int> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    display(a, n);
    vector<int> b(n);
    b = a;
    FOR(i, 1, n - 1)
    {
        int k = a[i];
        int j = i - 1;
        while(j >= 0 && b[j] > k)
        {
            b[j + 1] = b[j];
            j--;
        }
        b[j + 1] = k;
        display(b, n);
    }
    

    //cout << result << endl;
    return 0;
}

void display(vector<int> c, int n)
{
    cout << c[0];
    FOR(i, 1, n - 1)
    {
        cout << " " << c[i];
    }
    cout << endl;
}


Measured memory_bytes: 3148
# include"stdio.h"
int main(){
    int k,s,cou=0,x;
    scanf("%d %d",&k,&s);
    for(int i=0;i<k+1;i++)
        for(int j=0;j<k+1;j++){
               x=s-i-j;
                if(x>=0&&x<=k)  cou++;
        }
    printf("%d\n",cou);
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace dwango_5_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nk = ReadLine().Split().Select(int.Parse).ToArray();
            int n = nk[0];
            int k = nk[1];
            long[] input = ReadLine().Split().Select(long.Parse).ToArray();

            var list = new List<long>();
            for (int i = 0; i < n; i++){
                long sub = 0;
                for (int j = i; j < n; j++){
                    sub += input[j];
                    list.Add(sub);
                }
            }

            long ans = 0;
            for (int i = 40; i >= 0; i--){
                var check = new List<long>();
				foreach (var item in list){
					if ((item & 1L << i) > 0){
                        check.Add(item);
                    }
				}
				if (check.Count >= k){
					ans += 1L << i;
                    list = check;
				}
			}
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 27488
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  enum Janken : int64_t { kRock, kSChoki, kPar };
  int64_t N, K, R, S, P;
  cin >> N >> K >> R >> S >> P;
  string T;
  cin >> T;
  const int64_t L = static_cast<int64_t>(T.length());
  int64_t result = 0;
  for (int64_t i = 0; i < K; ++i) {
    vector<vector<int64_t>> dp;
    for (int64_t j = 0; i + j * K < L; ++j) {
      dp.push_back(vector<int64_t>(3, 0));
      const int64_t index = i + j * K;
      Janken enemy;
      if (T.c_str()[index] == 'r') {
        enemy = kRock;
      } else if (T.c_str()[index] == 's') {
        enemy = kSChoki;
      } else {
        enemy = kPar;
      }
      if (j == 0) {
        dp[j][kRock] = (enemy == kSChoki) ? R : 0;
        dp[j][kSChoki] = (enemy == kPar) ? S : 0;
        dp[j][kPar] = (enemy == kRock) ? P : 0;
      } else {
        dp[j][kRock] = max(dp[j - 1][kSChoki], dp[j - 1][kPar]) + ((enemy == kSChoki) ? R : 0);
        dp[j][kSChoki] = max(dp[j - 1][kRock], dp[j - 1][kPar]) + ((enemy == kPar) ? S : 0);
        dp[j][kPar] = max(dp[j - 1][kRock], dp[j - 1][kSChoki]) + ((enemy == kRock) ? P : 0);
      }
    }
    const int64_t len = static_cast<int64_t>(dp.size());
    result += max(dp[len - 1][kRock], max(dp[len - 1][kSChoki], dp[len - 1][kPar]));
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 6276
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};
const int NMAX=200010;
mint fact[NMAX],infac[NMAX];
void Make_Fact(){
  fact[0]=fact[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    fact[i]=fact[i-1]*(mint)i;
  }
}
void Make_InvFact(){
  infac[0]=infac[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    infac[i]=infac[i-1]/(mint)i;	
  }
}
mint Comb(int n,int k){
  if(n<0||k<0||n-k<0) return 0;
  return fact[n]*infac[k]*infac[n-k];
}

int main()
{
  Make_Fact();
  Make_InvFact();
  
  int h,w,a,b;
  cin >> h >> w >> a >> b;

  mint res;
  rep(i,h-a){
    res += Comb((i+b-1),i)*Comb((h-i-1+w-b-1),h-i-1);
  }
  cout << res.x << "\n";
  return 0;
}


Measured memory_bytes: 3328
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=5;
        int num[]=new int[5];
        for(int i=0;i<n;i++)num[i]=sc.nextInt();
        int count=10000;
        int num2[]=new int[5];
        for(int i=0;i<n;i++){num2[i]=num[i];while(num2[i]%10!=0)num2[i]++;}
        for(int i=0;i<n;i++){
            int c=0;
            for(int j=0;j<n;j++){
                if(i==j)c+=num[j];
                else c+=num2[j];
            }
            count=Math.min(c,count);
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def main():
    #N, K = map(int, input().split())
    S = input().strip()

    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            print("Bad")
            return
    print("Good")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MAX_V=114514LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};


int main(){
  ll q,h,s,d;
  cin>>q>>h>>s>>d;
  ll n;cin>>n;
  h=min(h,2*q);
  s=min(s,2*h);
  d=min(d,2*s);
  cout<<n/2*d+n%2*s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
//#define F first
//#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
 
 
int main(void){
    string s;
    ll k;
    cin>>s>>k;
    int cnt=0;
    int c=0,cnt1=0;

    string S="0"+s+s;
    c=0;
    cnt=0;
    FOR(i,1,S.size()){
        if(S[i]==S[i-1]){
            c++;
            if(c%2!=0&&i-1<s.size()){
                cnt++;
                //cout<<i-1<<endl;
            }
            else if(c%2!=0)cnt1++;
        }
        else{
            c=0;
        }
    }
    
    if(c==S.size()-2){
        printf("%lld \n",s.size()*k/2);
        return 0;
    }
    //cout<<cnt<<" "<<cnt1<<endl;
    printf("%lld \n",cnt+cnt1*(k-1));


    

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int main() {
	int k;
	cin >> k;
	ll sum(0);
	rep(i, k) {
		rep(j, k) {
			rep(o, k) {
				int q = gcd(i + 1, j + 1);
				int n = gcd(q, o + 1);
				sum += n;
			}
		}
	}
	
	cout << sum;
	return 0;
}

Measured memory_bytes: 3632
n,k = map(int, input().split())
h = [i for i in map(int, input().split())]

DP = [0]
for i in range(n-1):
    act = float("inf")
    for j in range(k):
        if i < j: continue
        act = min(abs(h[i+1]-h[i-j])+DP[-1-j], act)
    DP += [act]
    

print(DP[-1])

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

int main() {
    int H, N, A, B;
    vector<int> V;
    vector<int> weight;
    vector<int> value;
    cin >> H >> N;

    V.reserve(H + 1);
    weight.reserve(N);
    value.reserve(N);
    for (auto i = 0;i < N;i ++) {
        cin >> A >> B;
        weight[i] = B;
        value[i] = A;
    }

    V[0] = 0;
    for (auto i = 1;i <= H;i ++) {
        int w = weight[0];
        if (i > value[0]) {
            w = weight[0] + V[i - value[0]];
        }
        V[i] = w;
        for (int k = 1;k < N;k ++) {
            int w = weight[k];
            if (i > value[k]) {
                w = weight[k] + V[i - value[k]];
            }
            V[i] = min(w, V[i]);
        }
    }
    cout << V[H] << endl;

    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;

typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>Order_Set;

Order_Set X;

const int mxn = 2e5+100;
const int Mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false);

    int n, k;
    cin>>n>>k;
    long long Ans = 0;
    for(int i=0 ; i<k ; i++){
        int x;
        cin>>x;
        Ans+=x;
    }
    (Ans >= n) ? cout<<"Yes"<<endl : cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main(void)
{
	int N;
	string S, T;
	cin >> N;
	cin >> S >> T;
	for (int i = 0; i < N; i++) {
		cout << S[i] << T[i];
	}
	putchar('\n');

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2550;
using ll = long long;
using pll = pair<ll, ll>;
void amin(ll &a, ll b){
	a = min(a, b);
}
ll f[2][maxn][maxn];
int main(){
	vector<pll> e;
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		ll a, b; cin >> a >> b;
		e.push_back({a, b});
	}
	sort(e.begin(), e.end(), [](pll a, pll b){
		return a.first + a.second > b.first + b.second;
	});
	int m = n / 2;
	const ll inf = 1ll<<60;
	for(int i = 0; i < 2; i++) 
		for(int j = 0; j <= m; j++) 
			for(int k = 0; k <= m; k++) 
				f[i][j][k] = inf;
	f[0][0][0] = 0;
	for(int i = 0; i < n; i++){
		ll a, b; tie(a, b) = e[i];
		ll l = a + b;
		int ati = min(i, m);
		for(int x = 0; x < 2; x++){
			for(int y = 0; y + x <= ati; y++){
				int z = i - y - x;
				amin(f[x][y+1][z], f[x][y][z] + b + y * l);
				amin(f[x][y][z+1], f[x][y][z] + a + z * l);
				if(!x){
					amin(f[1][y][z], f[x][y][z] + m * l);
				}
			}
		}
	}
	cout << f[n&1][m][m] << endl;
	return 0;
}


Measured memory_bytes: 101120
#include<stdio.h>
#include<string.h>

int main(void){
    char s[4];
    scanf("%s",s);
    if(strcmp(s,"AAA") == 0 || strcmp(s,"BBB") == 0){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
#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;
    string s;
    cin >> n >> s;
    s += s[0];
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            vector<bool> v(n+2);
            v[0] = i, v[1] = j;
            for (int k = 1; k <= n; ++k) {
                v[k+1] = (v[k-1] != v[k]);
                if(s[k] == 'x') v[k+1] = !v[k+1];
            }
            if(v[0] == v[n] && v[1] == v[n+1]){
                for (int k = 0; k < n; ++k) {
                    printf("%c", (v[k] ? 'W' : 'S'));
                }
                printf("\n");
                return 0;
            }
        }
    }
    cout << -1 << "\n";
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int x[3];
    x[0] = a;
    x[1] = b;
    x[2] = c;
    sort(x,x+3);
    int ans=0;
    for (int i = 0; x[1] != x[2]; i++)
    {
        ans++;
        x[1]++;
        x[0]++;
    }
    for (int i = 0; x[0] < x[1];i++){
        x[0] += 2;
        ans++;
    }
    if(x[0]!=x[1]){
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
 
#define M 2000000
#define L 14
 
char H[M][L]; /* Hash Table */
 
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
 
/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
 
int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }
 
int find(char str[]){
    long long key,i,h;
    key = getKey(str);
    for(i=0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}
 
int insert(char str[]){
 
    long long key, i, h;
    key = getKey(str);
    for(int i=0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0) {
            strcpy(H[h],str);
            return 0;
        }
    }
    return 0;
}
 
int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
     
    scanf("%d", &n);
     
    for ( i = 0; i < n; i++ ){
        scanf("%s %s", com, str);
         
        if ( com[0] == 'i' ){
            insert(str);
        } else {
            if (find(str)){
            printf("yes\n");
            } else {
            printf("no\n");
            }
        }
    }
 
    return 0;
}
 

Measured memory_bytes: 28380
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>

using namespace std;

int conv(string s){
	if(s.size() == 0) return 0;
	if(s.size() > 1 && s[0] == '0') return -1;
	int res = 0;
	for(int i=0;i<s.size();i++){
		res *= 10;
		res += s[i] - '0';
	}
	return res;
}

int main(){
	string s;
	cin >> s;
	int ans = 0;
	for(int i=0;i<s.size();i++){
		int a = conv(s.substr(0, i));
		int b = conv(s.substr(i));
		if(a == -1 || b == -1) continue;
		if(b >= a && a % 2 == b % 2) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

struct edge{int u,v;double cost;};

int par[100000],rank[100000],V,E;
edge es[100000];

void init(int n){for(int i=0;i<n;i++){par[i]=i;rank[i]=0;}}
int find(int x){if(par[x]==x)return x;else return find(par[x]);}
void unite(int x,int y){x=find(x);y=find(y);if(x==y)return;if(rank[x]<rank[y])par[x]=y;else{par[y]=x;if(rank[x]==rank[y])rank[x]++;}}
bool same(int x,int y){return find(x)==find(y);}

bool comp(const edge e1,const edge e2){return e1.cost<e2.cost;}

double kruskal(){
	sort(es,es+E,comp);
	init(V);
	double res=0;
	rep(i,E){
		edge e=es[i];
		if(!same(e.u,e.v)){
			unite(e.u,e.v);
			res+=e.cost;
		}
	}
	return res;
}

double x[100],y[100],z[100],r[100];

int main(){
	while(cin>>V&&V){
		E=V*(V-1)/2;
		rep(i,V)cin>>x[i]>>y[i]>>z[i]>>r[i];
		int cur=0;
		rep(i,V)rep(j,V)if(i<j){es[cur].u=i;es[cur].v=j;es[cur++].cost=max(0.0,sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i])+(z[j]-z[i])*(z[j]-z[i]))-r[i]-r[j]);}
		printf("%.3f\n",kruskal());
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll e=a*c;
    ll f=a*d;
    ll g=b*c;
    ll h=b*d;
    cout << max({e,f,g,h}) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};

int main(){
    int N; cin >> N;
    vector<int> a(N);
    int ans = 0;
    for (int i = 0; i < N; i++){
        cin >> a[i];
        ans += a[i]-1;
    }
    cout << ans << endl;
}

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

int main(){
	int n;
    cin >> n;
    int a[n+1], b[n];
    long long res = 0;
    for (int i = 0; i < n+1;  i++){
    	cin >> a[i];
    }
    for (int j = 0; j < n; j++){
    	cin >> b[j];
    }
    for (int k = 0; k < n; k++){
    	if (b[k] >= a[k]){
        	res += a[k];
            int tmp = b[k] - a[k];
            res += min(tmp, a[k+1]);
            a[k+1] = max(0, a[k+1]-tmp);
        }else{
        	res += b[k];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
    
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1000*1000*1000;
const ll LINF = (ll)1e18;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};

vector<vector<int>> mp(501, vector<int>(501,0));

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H, W;
    cin >> H >> W;
    vector<vector<int>> mp(H, vector<int>(W,0));
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N){
        cin >> a[i];
    }
    int idx = 0;
    REP(i, H){
        if(i % 2 == 0){
            for(int j = 0; j < W; j++){
                mp[i][j] = idx+1;
                a[idx]--;
                if(a[idx] <= 0){
                    idx++;
                }
            }
        }else{
            for(int j = W - 1; j >= 0; j--){
                mp[i][j] = idx+1;
                a[idx]--;
                if(a[idx] <= 0){
                    idx++;
                }
            }
        }
    }
    REP(i, H){
        REP(j, W){
            cout << mp[i][j];
            if(j != W-1){
                cout << " ";
            }
        }
        cout << endl;
    }
    return 0;
}


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

int main() {
  string s;cin>>s;
  int ans=s.size(),n=s.size();
  rep(i,2){
    int cnt=0;
    rep(j,n){
      if(j%2==0&&s[j]!=(char)(i+'0'))cnt++;
      if(j%2==1&&s[j]==(char)(i+'0'))cnt++;
         }
         ans=min(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3756
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      aa: [[usize; m]; n],
    }

    use std::collections::HashSet;
    use std::collections::HashMap;
    let mut removed = HashSet::new();

    let mut map = HashMap::new();
    for i in 0..n {
        let v = aa[i][0];
        let e = map.entry(v).or_insert(vec![]);
        e.push((i,0usize));
    }


    let mut ans = n;
    while removed.len() < m {
        let mut temp: Vec<_> = map.iter().map(|v| (v.1.len(), *v.0)).collect();
        temp.sort();
        temp.reverse();

        ans = min(ans, temp[0].0);
        let to_remove = temp[0].1;
        removed.insert(to_remove);

        let xys = map.remove(&to_remove).unwrap();
        for (x, y) in xys {
            for y in y+1..m {
                let v = aa[x][y];
                if removed.contains(&v) {
                    continue;
                }
                let e = map.entry(v).or_insert(vec![]);
                e.push((x,y));
                break;
            }
        }
    }
    puts!("{}\n", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define MAX 50
#define MIX 450
#define inf 1<<29
#define linf 1e16
#define eps (1e-8)
#define mod 1000000007
#define pi acos(-1)
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;

typedef pair<string,int> psi;
typedef pair<int,string> pis;

vector<pis> e[MAX];
int n,m,s,g;

bool comp(string a,string b){
  int size=min(a.size(),b.size());
  FOR(i,0,size){
    if(a[i]<b[i])return true;
    if(b[i]<a[i])return false;
  }
  if(a.size()<b.size())return true;
  return false;
}

class compare{
  public:
    bool operator() (psi b,psi a){
      int size=min(a.f.size(),b.f.size());
      FOR(i,0,size){
        if(a.f[i]<b.f[i])return true;
        if(b.f[i]<a.f[i])return false;
     }
      if(a.f.size()<b.f.size())return true;
      return false;
    }
};

string solve(){
  priority_queue<psi,vector<psi>,compare > pq;
  string d[MAX][MIX];
  FOR(i,0,MAX)fill(d[i],d[i]+MIX,"~");
  d[s][0]="";
  pq.push(mp("",s));
  while(pq.size()){
    psi u = pq.top();
    pq.pop();
    if(comp(d[u.s][u.f.size()],u.f))continue;
    if(u.s==g && u.f.size()<240){
      FOR(i,0,200)
        if(comp(d[g][240+i],u.f))
          return "NO";
      return u.f;
    }
    FOR(i,0,e[u.s].size()){
      int next=e[u.s][i].f;
      string cost=u.f+e[u.s][i].s;
      int size = cost.size();
      if(MIX<=size)continue;
      if(comp(cost,d[next][size])){
        d[next][size]=cost;
        pq.push(mp(cost,next));
      }
    }
  }
  return "NO";
}

int main()
{
  while(1){
    cin>>n>>m>>s>>g;
    if(n+m+s+g==0)break;
    FOR(i,0,MAX)e[i].clear();
    FOR(i,0,m){
      int x,y;
      string S;
      cin>>x>>y>>S;
      e[x].pb(mp(y,S));
    }
    cout<<solve()<<endl;
  }
  return 0;
}




Measured memory_bytes: 14904
n,x = map(int,input().split())
l = []
s = 0
for i in range(n):
    l.append(int(input()))
    s += l[i]
    
for j in range(0,100000):
    if (x-s) == 0:
        print(n)
        break
    elif ((x-s)/(min(l)*(j+1))) < 1:
        print(n+j)
        break

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin>> s;
  
  REP(i,s.length()){
    if(s[i]=='?'){
      s[i] = 'D';
    }
  }

  cout << s << endl;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll MAXN = 

ll a,b,c,d;

ll calc(ll n) {
    return b / n - (a-1) / n;
}
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> a >> b >> c >> d;
    cout << b - a + 1 - calc(c) - calc(d) + calc(c*d/__gcd(c,d)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n;
int main()
{
	cin>>n;
	for(int i=1;1;i++)
	{
		if(i*(i+1)/2>=n)
		{
			rep2(j,1,i+1)
			{
				if(i*(i+1)/2-n!=j)cout<<j<<endl;
			}
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

struct score
{
	int team,pro,wrong[11];
	ll _time;
	
	score(int n){team = n;pro = 0;_time = 0;REP(i,11)wrong[i] = 0;}
	
	bool operator<(const score& right) const
	{
		return pro != right.pro ? pro > right.pro :
		_time != right._time ? _time < right._time : team > right.team ;
	}
};


int main()
{
	int m,t,p,r;
	
	while(cin>>m>>t>>p>>r,m|t|p|r)
	{
		vector<score> v;
		REP(i,t)
		{
			score tmp(i);
			v.PB(tmp);
		}
		
		
		REP(i,r)
		{
			int mm,tt,pp,jj;
			cin>>mm>>tt>>pp>>jj;
			if(!jj)
			{
				v[tt-1].pro++;
				v[tt-1]._time+=mm+20*v[tt-1].wrong[pp];
			}
			else
			{
				v[tt-1].wrong[pp]++;
			}
		}
		
		sort(ALL(v));
//		REP(i,t)
//		{
//			cout << v[i].team << ' ' << v[i].pro << ' ' << v[i]._time << endl;
//		}
		
		cout << v[0].team+1 ;
		for(int i = 1;i < t;i++)
		{
			if(v[i].pro == v[i-1].pro && v[i]._time == v[i-1]._time)
			{
				cout << '=' << v[i].team+1;
			}
			else
			{
				cout << ',' << v[i].team+1;
			}
		}
		cout << endl;
	}
		
	return 0;
}

Measured memory_bytes: 3048
M, D = map (int, input().split())
takahashireki_counter = 0
for m in range(1, M+1):
    for d in range(1, D+1):
        if d<10 : continue
        d10 = d//10
        d1 = d%10
        if d1 >= 2 and d10 >= 2 and d1*d10 == m:
            takahashireki_counter += 1
print(takahashireki_counter)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
        int n, m; cin >> n >> m;
        vector<bool> ok(n, false);
        vector<int>  c(n, 0);

        REP(i, m) {
                int p;
                string s;
                cin >> p >> s;
                --p;
                if (s == "AC") {
                        if (!ok[p]) {
                                ok[p] = true;
                        }
                } else {
                        if (!ok[p]) {
                                c[p]++;
                        }
                }
        }

        int ac = 0, wa = 0;

        REP(i, n) {
                if (ok[i]) {
                        ac++;
                        wa += c[i];
                }
        }

        cout << ac << " " << wa << endl;

        return 0;
}


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


  int h[1000000]; 
  int c[1000000];

  int abs(int n,int m){
      if(n>=m) return n-m;
      else return m-n;
  }

  int rec(int n){
      
       if(n==0){
          return c[0]=0;
      }

       if(n == 1){
          return c[1]= abs(h[0],h[1]); 
      }

      else if(c[n] != -1) return c[n];

      else{
          return c[n] = min(rec(n-1)+abs(h[n-1],h[n]) , rec(n-2)+abs(h[n-2],h[n])) ;

      }


  }

  int main(){
      int n;
      cin >> n;
      
     for(int i=0;i<n;i++) {
          cin >> h[i];
          c[i] = -1;
      }
      

      cout << rec(n-1) << endl;
  }


Measured memory_bytes: 7040
main :: IO ()
main = do
  mapM_ putStrLn ans'

format :: Int -> Int -> String
format i j = show i ++ "x" ++ show j ++ "=" ++ show (i * j)

ans' = foldr (\i b -> f i ++ b) [] [1..9]
f i = map (format i) [1..9]

Measured memory_bytes: 3496
import itertools
N=int(input())
ListP = tuple(map(int, input().split()))
ListQ = tuple(map(int, input().split()))
s_l = set(ListP)
Per = list(itertools.permutations(s_l))
Per.sort()
mid1 = 0
mid2 = 0
for i in range(len(Per)):
  if Per[i] == ListP:
    mid1 = i+1
  if Per[i] == ListQ:
    mid2 = i+1
res = abs(mid1 -mid2)
print(res)

Measured memory_bytes: 13984
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/
	
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	ll ma = 0;
	rep(i, n) {
		cin >> a[i];
		chmax(ma, a[i]);
	}

	ll g = a[0];
	for (int i = 1; i < n; i++) {
		g = gcd(g, a[i]);
	}

	bool f = false;
	while (ma >= 0) {
		if (ma == k) {
			f = true;
			break;
		}
		ma -= g;
	}
	if (f) {
		out("POSSIBLE");
	}
	else {
		out("IMPOSSIBLE");
	}

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(ll i = 0;i < (n); ++i)
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    if(a == b){
        cout << '0' << endl;
        return 0;
    }
    if((b-a)%2 == 0){
        cout << (b-a)/2 << endl;
        return 0;
    }else{
        ll ans = min(a-1,n-b);
        ans += (b-a)/2+1;
        cout << ans << endl;
        return 0;
    }
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#define INF 100000000
using namespace std;
int N,A,B,C,l[10];
int dfs(int cur,int a,int b,int c);
int main(void)
{
  cin >> N >> A >> B >> C;
  for(int i=0;i<N;i++) {
    cin >> l[i];
  }
  cout << dfs(0,0,0,0) << "\n";
  return 0;
}
int dfs(int cur,int a,int b,int c)
{
  if(cur==N) {
    if(a>0&&b>0&&c>0) {
      return abs(a-A)+abs(b-B)+abs(c-C)-30;
    } else {
      return INF;
    }
  }
  int r0=dfs(cur+1,a,b,c);
  int r1=dfs(cur+1,a+l[cur],b,c)+10;
  int r2=dfs(cur+1,a,b+l[cur],c)+10;
  int r3=dfs(cur+1,a,b,c+l[cur])+10;
  return min(r0,min(r1,min(r2,r3)));
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
a = list(map(int, input().split()))
nmax = [None]*(n+1)
nmax[-1] = 0
for i in range(n-1, -1, -1):
    nmax[i] = nmax[i+1] + a[i+1]
    
k = 1
ans = 0
for i,(num, M) in enumerate(zip(a, nmax)):
    if k<num:
        ans = -1
        break
    k -= num
    k = min(M, k)
    ans += (k+num)
    k *= 2
print(ans)

Measured memory_bytes: 83700
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.begin(), a.end())
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin>>n>>m;
    cout<<(m==n?"Yes\n":"No\n");
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main() {
    ll n, m; cin >> n >> m;
    ll res = 0;
    ll s = min(n, m/2);
    res += s;
    m -= s*2;
    res += m/4;
    cout << res << ln;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int n,m,q;
int ans[503][503];
int main(){
	cin>>n>>m>>q;
	for (int i=0;i<m;i++){
		int l,r;
		cin>>l>>r;
		ans[1][r]++,ans[l+1][r]--; 
	}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			ans[i][j]+=ans[i-1][j]+ans[i][j-1]-ans[i-1][j-1];
	for (int i=0;i<q;i++){
		int p,s;
		cin>>p>>s;
		cout<<ans[p][s]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
  ll n;cin >>n;
  ll out =0;
  ll prev =0;
  for (ll i=0;i<n;++i){
    ll a;cin>>a;
    if(a<=prev){
      out +=prev-a;
    } else {
      prev = a;
    }
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 3632
/* ex 9_2
   Sagzar1993 */

#include <stdio.h>
#include <stdlib.h>

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    int cnt = 0; //除去可能なキューブの数
    char cube; //キューブの色を表す文字
    //最初のノードの指す先
    node *cubeFirst = NULL;
    
    //１文字ずつ入力してスタックを操作
    while(1){
        scanf("%c", &cube);
        //文字列の最後に来たら終了
        if(cube == '\n'){
            break;
        }
        if(cubeFirst == NULL){
            push(&cubeFirst, cube); //スタックが空ならそのまま追加
        }else if((cubeFirst->elem == '0' && cube == '1') || (cubeFirst->elem == '1' && cube == '0')){
            pop(&cubeFirst); //入力されたcubeをスタックの先頭と比較し、０と１の組ならば除去可能
            cnt += 2; //取り出したスタックの先頭および入力の２文字が除去可能なので、cntを＋２
        }else{
            push(&cubeFirst, cube); //０同士、１同士ならば除去不可なのでそのままスタックに追加
        }
    }
    
    printf("%d\n", cnt); //除去可能なキューブ数cntを出力
    return 0;
}

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

#define MAX_N 1000000

using namespace std;

int cnt;

void print(int A[], int n) {
	for (int i = 0; i < n; i ++) {
		cout << A[i] << endl;
	}
}

void insertion_sort(int A[], int n, int g) {
	for (int i = g; i < n; i ++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && v < A[j]) {
			A[j + g] = A[j];
			j -= g;
			cnt ++;
		}
		A[j + g] = v;
	}
}

void shell_sort(int A[], int n) {
	cnt = 0;
	vector<int> G;
	int h = 1;
	while (h <= n) {
		G.push_back(h);
		h = 3 * h + 1;
	}

	cout << G.size() << endl;

	for (int i = G.size() - 1; i >= 0; i -- ) {
		cout << G[i] << " ";
		insertion_sort(A, n, G[i]);
	}
	cout << endl;
	cout << cnt << endl;

}

int main() {
	int n, A[MAX_N];

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

	shell_sort(A, n);
	
	print(A, n);

	return 0;
}


Measured memory_bytes: 7028
LastStation = 9

def solve start, dest
  result = Array.new
  result << current = start
  up = (! (start <= 5 && dest < start)) ? true : false

  while current != dest
    if up
      current += 1
    else
      current -= 1
    end

    if current >  LastStation
      current = 5
      up = false
    end
    if current < 0
      current = 1
      up = true
    end
    
    result << current
  end

  result
end

$stdin.gets.to_i.times do
  start, dest = $stdin.gets.chomp.split(" ").map(&:to_i)
  result = solve(start, dest)
  first = true
  result.each do |s|
    printf " " unless first
    printf "%d", s
    first = false
  end
  printf "\n"
end

Measured memory_bytes: 6112
#include<bits/stdc++.h>
using namespace std;
int main(){
  int r,c,p[10][10000],ans;
  while(cin>>r>>c,r){
    ans=0;    
    for(int i=0;i<r;i++)
      for(int j=0;j<c;j++)
	cin>>p[i][j];
    
    for(int i=0;i<(1<<r);i++){
      int t=0;
      for(int l=0;l<c;l++){
	int a=0;
	for(int j=0,k=1;j<r;j++,k*=2){
	  if(i/k%2)a+=!p[j][l];
	  else a+=p[j][l];
	}
	t+=max(a,r-a);
      }
      ans=max(ans,t);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1548
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	public static void main(String[] __){
		int n=getInt();
		String a=s.next(),b=s.next();
		for(int i=0;i<n;i++) {
			String r=a.substring(i,n);
			if(b.startsWith(r)) {
				System.out.println((a+b.replaceFirst(r,"")).length());
				return;
			}
		}
		System.out.println((a+b).length());
	}
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int dp[101][4][2];

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

  dp[0][0][1]=1;
  
  rep(i, n)rep(j, K+1)rep(k, 2)rep(a, 10){
    int x = s[i]-'0';
    int ni = i+1;
    int nj = j;
    int nk=k;
    // もし着目中の数値が0でなければ0でない数値のカウントを増やす。
    if(a)nj++;
    // 0の個数が4以上だと題意から除外可能なので除外する。
    if(nj>3)continue;
    // 今の所n丁度で着目中の数値と着目中の桁が一致してたら今の所n丁度継続、そうでなければn未満確定。着目数値の方が着目桁よりもデカければn超過確定なので飛ばす。
    if(k){
      if(a>x)continue;
      if(a<x)nk=0;
    }
    // k==0ならn未満確定なので何もしない、そのままnk==0で遷移する
    dp[ni][nj][nk] += dp[i][j][k];
  }
  cout<<dp[n][K][0]+dp[n][K][1]<<endl;

  return 0;

  rep(i, n+1)rep(j, K){
    rep(k, 2)cout<<dp[i][j][k]<<' ';
    cout<<endl;
  }

  return 0;
}



Measured memory_bytes: 3584