akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static int N;
    static int[] B;

    static void Main(string[] args)
    {
        var s = new Scanner();
        N = s.ReadInt();
        B = s.ReadIntArray(N - 1);

        Solve();
    }

    static void Solve()
    {
        ulong ans = 0;
        int[] A = new int[N];
        A[0] = B[0];
        A[N - 1] = B[N - 2];

        for (int i = N - 2; i >= 1; i--)
        {
            A[i] = Math.Min(B[i], B[i - 1]);
        }

        foreach (var a in A)
        {
            ans += Convert.ToUInt64(a);
        }
        Console.WriteLine(ans);
    }
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }

    public string ReadStr()
    {
        return this.Next();
    }

    public char ReadChar()
    {
        return this.Next()[0];
    }

    public int ReadInt()
    {
        return int.Parse(this.Next());
    }

    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }

    public long ReadLong()
    {
        return long.Parse(this.Next());
    }

    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }

    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }

    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }

    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}



Measured memory_bytes: 11220
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // input
        Scanner sc = new Scanner(System.in);
        int[] list = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        System.out.println(list[sc.nextInt() - 1]);
    }
}

Measured memory_bytes: 21588
def GCD(a: int, b: int) -> int:
    return a if b == 0 else GCD(b, a % b)


def LCM(a: int, b: int) -> int:
    return a * b // GCD(a, b)


a, b = map(int, input().split())
ans = LCM(a, b)
print(ans)


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <cstdio>
const long long MAXN=0x7fffffffffffff;
using namespace std;
int a_min(long long a,long long b){
	return a>b?b:a;
}
int main(){
	int n,a[400000];
		scanf("%d",&n);
	long long sum=0LL; 
	for(int i=1;i<=n;i++){ 
		scanf("%d",&a[i]);
		sum+=a[i]; 
	} 
	long long snu=0LL; 
 	long long rac; 
	long long ans=MAXN;
	for(int i=1;i<n;i++){ 
  		snu+=a[i]; 
  		rac= sum-snu;
   		ans = min(ans,abs(rac-snu)); 
   } 
	printf("%lld",ans); 
	return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        List<Integer> list = new ArrayList<>();
        int n=sc.nextInt();
        int j=n;
        while(j-->0){
            list.add(sc.nextInt());
        }
        for(int i=n-1;i>0;i--) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println(list.get(0));
    }
}


Measured memory_bytes: 26140
from itertools import permutations

n,m,rnum = map(int,input().split())
inf = 10**18
shortest = [[inf for i in range(n)] for j in range(n)]
r = list(map(int,input().split()))
for i in range(len(r)):
    r[i]-= 1

for i in range(m):
    a,b,c = map(int,input().split())
    shortest[a-1][b-1] = c
    shortest[b-1][a-1] = c

for i in range(len(shortest)):
    for j in range(len(shortest)):
        for k in range(len(shortest)):
            shortest[j][k] = min(shortest[j][k],shortest[j][i]+shortest[i][k])

ans = inf
# print(shortest)
for p in permutations(r):
    temp = 0
    for i in range(rnum-1):
        temp+=shortest[p[i]][p[i+1]]
    if ans > temp:
        ans = temp
print(ans)

Measured memory_bytes: 46424
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  
if ((c == 'a' ) || (c == 'i' ) || (c == 'u' ) || (c == 'e' ) || (c == 'o' )) cout << "vowel" << endl;
  else cout << "consonant" <<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <cctype>
using namespace std;

unsigned char vis[1 << 24];
char c[16][20];
bool wall[256];
int gen;

inline bool check(int u, int v){
	for(int i = 0; i < 24; i += 8){
		int p1 = v >> i & 255;
		if(p1){
			int j = i == 16 ? 0 : i + 8;
			if(wall[p1]){ return false; }
			int p2 = v >> j & 255;
			if(p1 == p2){ return false; }
			if(
				p1 == (u >> j & 255) &&
				p2 == (u >> i & 255)
			){
				return false;
			}
		}
	}
	return true;
}

int solve(int start, int goal){
	const int dif[5] = {0, -1, 1, -16, 16};

	++gen;
	queue<int> q;
	q.push(start);
	q.push(-1);
	int tm = 1;
	vis[start] = gen;
	while(1){
		int u = q.front();
		q.pop();
		if(u < 0){
			q.push(-1);
			++tm;
		}
		else{
			for(int i1 = u & 255 ? 4 : 0; i1 >= 0; --i1)
			for(int i2 = u >> 8 & 255 ? 4 : 0; i2 >= 0; --i2)
			for(int i3 = u >> 16 ? 4 : 0; i3 >= 0; --i3){
				int v = u + dif[i1] + (dif[i2] << 8) + (dif[i3] << 16);
				if(vis[v] == gen){ continue; }
				if(check(u, v)){
					if(v == goal){ return tm; }
					vis[v] = gen;
					q.push(v);
				}
			}
		}
	}
}

int main(){
	int w, h;
	while(scanf("%d%d%*d ", &w, &h), w){
		for(int i = 0; i < h; ++i){
			fgets(c[i], 20, stdin);
		}

		int goal = 0;
		int start = 0;
		for(int i = 0; i < h; ++i){
			for(int j = 0; j < w; ++j){
				if(c[i][j] == '#'){
					wall[i << 4 | j] = true;
				}
				else{
					wall[i << 4 | j] = false;
					if(isupper(c[i][j])){
						goal |= (i << 4 | j) << (c[i][j] - 'A') * 8;
					}
					else if(islower(c[i][j])){
						start |= (i << 4 | j) << (c[i][j] - 'a') * 8;
					}
				}
			}
		}

		printf("%d\n", solve(start, goal));

		if(gen == 255){
			memset(vis, 0, sizeof vis);
			gen = 0;
		}
	}
}

Measured memory_bytes: 17144
#include <iostream>

using namespace std;

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

    int N, A;
    cin >> N >> A;

    if ((N % 500) <= A)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


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

char S[1000][1000];
char *ans[1000];

int main (void) {
	int N, L;
	char *tmp;
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
		ans[i] = S[i];
	}

	for (int i = 0; i < N; i++) {
	for (int i = 1; i < N; i++) {
		if (strcmp(ans[i-1], ans[i]) > 0) {
			tmp = ans[i-1];
			ans[i-1] = ans[i];
			ans[i] = tmp;
		}
	}
	}
	for (int i = 0; i < N; i++) cout << ans[i];
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 384
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
ABs = [inpl() for i in range(N)]
ABs = reversed(ABs)

SUM = 0
for a,b in ABs:
	tmp = (a+SUM)%b
	if tmp == 0:
		continue
	else:
		SUM += b-tmp

print(SUM)


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

int main() {
  ll n; cin >> n;
  vector<tuple<string, ll, ll>> t;
  
  rep(i,n){
    string s; ll p;
    cin >> s >> p;
    t.push_back(make_tuple(s, -p, i+1));
  }
  
  sort(t.begin(),t.end());
  
  rep(i, n)
    cout << get<2>(t[i]) << endl;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
long long int euclidean_gcd(long long int a, long long int b) {
    if(a < b) return euclidean_gcd(b, a);
    long long int r;
    while ((r=a%b)) {
    a = b;
    b = r;
    }
    return b;
}
long long int lcm(long long int a, long long int b) {
    long long int tmp = euclidean_gcd(a, b);
    long long int ans = a / tmp * b;
    return ans;
}
int main() {
    int N;
    cin >> N;
    vector<long long int> T(N);
    for(int i = 0; i < N; i++) {
        cin >> T[i];
    }
    long long int ans = 1LL;
    for(int i = 0; i < N; i++) {
        ans = lcm(ans, T[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
	return (b==0) ? a:gcd(b,a%b);
}

int main(){
   int n;
   cin >>n;
   auto a = vector<int>();
   for (int i = 0; i < n; i++)
   {
       /* code */
       int temp;
       cin >> temp;
       a.push_back(temp);
   }
   auto res=*max_element(a.begin(),a.end());
   for(int i = 0;i<a.size();i++){
		res = gcd(res,a[i]);   		
   }
   cout << res;

}

Measured memory_bytes: 892
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    int i;
    if(a<=b){
        for(i=0;i<b;i++){
            printf("%d",a);
        }
        putchar('\n');
    }else{
        for(i=0;i<a;i++){
            printf("%d",b);
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
  
  
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b){
        for(int i=0;i<a;i++){
            cout<<b;
        }
    }
    else{
        for(int i=0;i<b;i++){
            cout<<a;
        }
    }
    cout<<"\n";
    return 0;
}



Measured memory_bytes: 256
#coding:utf-8

N,A,B,C = map(int,input().split())

solve = []
p = A+B+C
s = str(input())

for i in range(N):

    if p == 0:
        print('No')
        break

    if i != N-1:
        nex = str(input())
    elif i == N-1:
        nex = s

    if p == 2 and nex != s:
        if A == 1 and B == 1 and C == 0 and s == 'AB':
            if nex == 'BC':
                B += 1
                A -= 1
                solve.append('B')
            elif nex == 'AC':
                A += 1
                B -= 1
                solve.append('A')
            s = nex
            continue
        elif A == 0 and B == 1 and C == 1 and s == 'BC':
            if nex == 'AB':
                B += 1
                C -= 1
                solve.append('B')
            elif nex == 'AC':
                C += 1
                B -= 1
                solve.append('C')
            s = nex
            continue
        elif A == 1 and B == 0 and C == 1 and s == 'AC':
            if nex == 'BC':
                C += 1
                A -= 1
                solve.append('C')
            elif nex == 'AB':
                A += 1
                C -= 1
                solve.append('A')
            s = nex
            continue
    
    if s == 'AB':
        if A == 0 and B == 0:
            print('No')
            break
        if A >= B:
            A -= 1
            B += 1
            solve.append('B')
        else:
            A += 1
            B -= 1
            solve.append('A')
    elif s == 'BC':
        if B == 0 and C == 0:
            print('No')
            break
        if B >= C:
            B -= 1
            C += 1
            solve.append('C')
        else:
            B += 1
            C -= 1
            solve.append('B')
    elif s == 'AC':
        if C == 0 and A == 0:
            print('No')
            break
        if C >= A:
            C -= 1
            A += 1
            solve.append('A')
        else:
            C += 1
            A -= 1
            solve.append('C')

    s = nex
            
    if i == N-1:
        print('Yes')
        for t in solve:
            print(t)

Measured memory_bytes: 9940
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [N] = input[0].map(Number);
  const checkpoints = input.slice(N + 1, -1).map((line) => line.map(Number));

  const answer: number[] = [];

  for (let i = 1; i <= N; i++) {
    const [a, b] = input[i].map(Number);

    let minDistance = Number.MAX_SAFE_INTEGER;
    let candidate = 0;

    checkpoints.forEach(([c, d], j) => {
      const distance = Math.abs(c - a) + Math.abs(d - b);

      if (distance < minDistance) {
        minDistance = distance;
        candidate = j + 1;
      }
    });

    answer.push(candidate);
  }

  return answer.join("\n");
};

console.log(main(read()));


Measured memory_bytes: 33312
#include<bits/stdc++.h>
using namespace std;
const int M=1e3+60;
int a[M][M];
int main(){
	long long n;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<n;j++){
			scanf("%d",&a[i][j]);
		}
		a[i][0]=1;
	}
	long long num=n*(n-1)/2;
	int flag=0;
	long long ans=0;
	long long i=0;
	while(1){
		int flag2=0;
		int used[M]={0};
		for(int j=1;j<=n;j++){
			long long k=a[j][0];
			if(k!=n&&!used[j]){
				long long t1=a[j][k];
				long long k2=a[t1][0];
				long long t2=a[t1][k2];
				if(!used[t1]&&k2!=n&&t2==j){
					a[t1][0]++;
					a[j][0]++;
					used[t1]=1;
					used[j]=1;
					flag2=1;
					i++;
				}
			}
		}
		ans++;
		if(!flag2){
			flag=1;
			break;
		}
		if(i==num){
			break;
		}
	}
	if(!flag){
		printf("%d\n",ans);
	}else{
		printf("-1\n");
	}
	return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int a[4];

int main(){
	for(int i=0;i<4;i++) scanf("%1d",&a[i]);
	if(a[0]==a[1]||a[1]==a[2]||a[2]==a[3]) cout<<"Bad";
	else cout<<"Good";
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <functional>
#include <map>
#include <math.h>
#include <list>

using namespace std;
#define ll long long int


int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

	queue<ll> q;
	q.push(1);
	q.push(2);
	q.push(3);
	q.push(4);
	q.push(5);
	q.push(6);
	q.push(7);
	q.push(8);
	q.push(9);
	int k; cin >> k;
	ll i = 0;


	while (k--) {
		i = q.front();
		q.pop();
		if (i % 10 != 0) q.push(i * 10 + (i % 10) - 1);
		q.push(i * 10 + (i % 10));
		if(i% 10 != 9) q.push(i * 10 + (i % 10) + 1);
	}

	cout << i << endl;

	return 0;
}

Measured memory_bytes: 4764
using System;

class Myon{
    static void Main(string[] args){
        string[] input = Console.ReadLine().Split(' ');

        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        int C = int.Parse(input[2]);

        if(A == B && B == C)Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 13140
/*
Original problem: 
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

namespace SOLVE {
    void main() {
        string a, b;
        cin >> a >> b;
        // dp[i][j] is the maximum length substring considering the first i/j letters
        vector < VI > dp(a.length() + 1, VI(b.length() + 1));
        REP(i, 1, a.size() + 1) {
            REP(j, 1, b.size() + 1) {
                // if same: dp[i][j] = d[i-1][j-1] + 1
                // else: = max(dp[i-1][j], dp[i][j-1])
                if (a[i - 1] == b[j - 1]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }

        // to find the word, do a 2-pointer approach and print backwards
        stack < char > ans;
        int ptra = a.size(), ptrb = b.size();
        while (dp[ptra][ptrb] != 0) {
            // case 1: move left
            if (dp[ptra][ptrb] == dp[ptra - 1][ptrb]) {
                ptra--;
            } else if (dp[ptra][ptrb] == dp[ptra][ptrb - 1]) {
                ptrb--;
            } else {
                ans.push(a[ptra - 1]);
                ptra--, ptrb--;
            }
        }

        while (ans.size()) {
            cout << ans.top();
            ans.pop();
        }


    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

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

int main() {
	int n;
	int x;
	cin >> n;
	for (int i = 1; i <= n; i++){
		x = i;
		if (x % 3 == 0) {
			cout << " " << i;
		}
		else {
			for (;;) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
				if (x < 1)break;
			}
		}
	}
	cout << endl;
}


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

class Rolling_Hash{
private:
  int n;
  static constexpr ll base1=1007,base2=2009;
  static constexpr ll mod1=(1e9+7),mod2=(1e9+9);
  vector<ll> hash1,hash2,mpow1,mpow2;
public:
  Rolling_Hash(const string& s){
    n=s.size();
    hash1.resize(n+1,0);
    hash2.resize(n+1,0);
    mpow1.resize(n+1,1);
    mpow2.resize(n+1,1);
    for(ll i=0;i<n;++i){
      hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
      hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
      mpow1[i+1] = (mpow1[i]*base1)%mod1;
      mpow2[i+1] = (mpow2[i]*base2)%mod2;
    }
  }
  auto get(ll l,ll r){
    ll lefval = hash1[r]-hash1[l]*mpow1[r-l]%mod1;
    ll rigval = hash2[r]-hash2[l]*mpow2[r-l]%mod2;
    if(lefval<0)lefval+=mod1;
    if(rigval<0)rigval+=mod2;
    return make_pair(lefval,rigval);
  }
  auto get_LCP(int a,int b){
    int len = min( n-a+1,n-b+1 );
    int low=0,high=len;
    while( high-low>1 ){
      int mid=(high+low)/2;
      if(get(a,a+mid)!=get(b,b+mid))high=mid;
      else low=mid;
    }
    return low;
  }
};

main(){

  int n;
  string s;
  cin>>n>>s;

  Rolling_Hash rh(s);
  int ans=0;
  rep(i,n){
    for(int j=i+1;j<n;++j){
      int lcp=rh.get_LCP(i,j);
      ans=max(ans,min(lcp,j-i));
    }
  }
  cout<<(ans)<<endl;

}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N;
int A[200001];
int S[200001];

int Get(int l, int r)
{
	return S[r] - S[l];
}

int Ans(int s0, int s1, int s2, int s3)
{
	return MAX(s0, MAX(s1, MAX(s2, s3))) - MIN(s0, MIN(s1, MIN(s2, s3)));
}

int GetAnsFromCut(int c0, int c1, int c2)
{
	int s0 = Get(0, c0);
	int s1 = Get(c0, c1);
	int s2 = Get(c1, c2);
	int s3 = Get(c2, N);
	return Ans(s0, s1, s2, s3);
}

signed main()
{
	cin >> N;
	REP(i, N)
	{
		cin >> A[i];
	}

	S[0] = 0;
	for (int i = 1; i < N + 1; i++)
	{
		S[i] = S[i - 1] + A[i - 1];
	}

	int c0 = 1;
	int c1 = 2;
	int c2 = 3;

	int min = GetAnsFromCut(c0, c1, c2);
	for (int i = c2 + 1; i < N; i++)
	{
		int next_ans = GetAnsFromCut(c0, c1, c2);
		if (next_ans < min)
		{
			min = next_ans;
		}
		else
		{
			break;
		}
	}

	for (int i = 2; i < N - 1; i++)
	{
		int c1 = i;
		if (c1 == c2) c2++;
		int ans = GetAnsFromCut(c0, c1, c2);
		while (true)
		{
			bool is_update = false;

			if (c0 + 1 < c1)
			{
				int next_c0 = c0 + 1;
				int next_ans = GetAnsFromCut(next_c0, c1, c2);
				if (next_ans < ans)
				{
					c0 = next_c0;
					ans = next_ans;
					is_update = true;
				}
			}

			if (c2 + 1 < N)
			{
				int next_c2 = c2 + 1;
				int next_ans = GetAnsFromCut(c0, c1, next_c2);
				if (next_ans < ans)
				{
					c2 = next_c2;
					ans = next_ans;
					is_update = true;
				}
			}

			if (!is_update)
			{
				break;
			}
		}
		min = MIN(min, ans);
	}

	cout << min << endl;
}







Measured memory_bytes: 3328
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int l = scan.nextInt();
		
		int[][] a = new int[n][m];
		int[][] b = new int[m][l];
		long[][] c = new long[n][l];
		
		// a in
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				a[i][j] = scan.nextInt();
			}
		}
		
		// b in
		for(int i = 0; i < m; i++) {
			for(int j = 0; j < l; j++) {
				b[i][j] = scan.nextInt();
			}
		}
		
		// c cal
		long temp = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < l; j++) {
				for(int k = 0; k < m; k++) {
					temp += a[i][k] * b[k][j];
				}
				c[i][j] = temp;
				temp = 0;
			}
		}
		
		// syso
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < l; j++) {
				if(j == 0) System.out.print(c[i][j]);
				else System.out.print(" " + c[i][j]);
			}
			System.out.println();
		}
		
	}

}



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

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

#define BR "\n"
#define SP " "

int main() {
  int W, H, N;
  cin >> W >> H >> N;

  vector<vector<ll>> cells(W, vector<ll>(H, 0));

  rep0(i, N) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) rep(h, 0, H) rep(w, 0, x) cells[w][h] = 1;
    if (a == 2) rep(h, 0, H) rep(w, x, W) cells[w][h] = 1;
    if (a == 3) rep(w, 0, W) rep(h, 0, y) cells[w][h] = 1;
    if (a == 4) rep(w, 0, W) rep(h, y, H) cells[w][h] = 1;
  }

  ll ans = W * H;
  rep0(w, W) {
    rep0(h, H) {
      if (cells[w][h]) ans--;
    }
  }

  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ll  long long
#define mod 1000000007
#define ve vector
#define pi pair<int,int>
#define pb push_back
#define F first
#define S second
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int inf=1e9+5;
vector<ll>A,B;


ll power(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b/=2;
	}
	return res;
}

void path(ll a,int state)
{
 for(ll i=2;i*i<=a;i++)
 {
  if(a%i==0)
  {
    if(state==0)A.push_back(a/i);
     else B.push_back(a/i);
      path(a/i,state);
      return ;
  }
 }
}

void solve()
{ 
  ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll steps=x/d;
    if(k>steps)
    {
        x-=(steps*d);
        k-=steps;
        if(k&1)cout<<abs(x-d)<<endl;
        else cout<<x<<endl;
    }
    else   
    {
        x-=(k*d);
        cout<<x<<endl;
    }
}

signed main()
{
//#ifndef ONLINE_JUDGE
    //  freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
//#endif
    FAST;
   
    
     int t=1;
    //cin>>t;
     while(t--)
    	solve();
    return 0;
}



Measured memory_bytes: 3652
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll x,n;
  cin>>x>>n;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  ll ans = -1;
  ll mn = 10000000;
  rep(i,0,102){
    ll flag = 0;
    rep(j,0,v.sz){
      if(i==v[j])flag = 1;
    }
    if(flag==1)continue;
    ll d = abs(x-i);
    if(d<mn){
      mn = d;
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) (i%(ll)(1e9 + 7))


int main(){
	string a,b,c;
	cin >> a >> b>> c;
	cout << (char)((int)a[0]+('A'-'a')) <<(char)((int)b[0]+('A'-'a')) << (char)((int)c[0]+('A'-'a')) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#input
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

#output
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

s = p[:X] + q[:Y] + r

s.sort(reverse = True)
answer = sum(s[:X+Y])    

print(answer)

Measured memory_bytes: 22720
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)

	var rooms [4][3][10]int

	var tou int
	var kai int
	var room int
	var num int

	for i := 0; i < n; i++ {
		fmt.Scan(&tou)
		fmt.Scan(&kai)
		fmt.Scan(&room)
		fmt.Scan(&num)

		rooms[tou-1][kai-1][room-1] = rooms[tou-1][kai-1][room-1] + num
	}

	for i := 0; i < 4; i++ {
		if i != 0 {
			fmt.Println(strings.Repeat("#", 20))
		}
		for j := 0; j < 3; j++ {
			for m := 0; m < 10; m++ {
				fmt.Print(" ")
				fmt.Print(rooms[i][j][m])
				// if m == 9 {
				// 	if i == 3 && j == 2 {
				// 		break
				// 	}
				// 	fmt.Println()
				// }
			}
			fmt.Println()
		}
	}
}



Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	string S;
	cin >> S;
	int count = 0,t;
	int N = S.size();
	for(t = 0; t < N; t++) {
		if (S[t] == 'x')
			count++;
	}
	if (count >= 8)
		cout << "NO";
	else
		cout << "YES";
	return 0;
}


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

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    std::vector<int> input(2*n);
    for(int i = 0; i < input.size(); ++i){
        scanf("%d", &input[i]);
    }
    std::sort(input.begin(), input.end());
    int ans = 0;
    for(int i = 0; i < input.size(); i += 2){
        ans += input[i];
    }
    printf("%d\n", ans);
    return 0;
}

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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;

int main(){
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    priority_queue<P> que;
    for(int i=0;i<a;i++) cin >> p[i];
    for(int i=0;i<b;i++) cin >> q[i];
    for(int i=0;i<c;i++) cin >> r[i];
    for(int i=0;i<a;i++) que.push(P(p[i],0));
    for(int i=0;i<b;i++) que.push(P(q[i],1));
    for(int i=0;i<c;i++) que.push(P(r[i],2));
    int z = 0;
    ll ans = 0;
    while(x+y-z>0){
        auto t = que.top();
        que.pop();
        int id = t.second;
        if(id == 0 && x > 0){
            ans += t.first;
            x--;
        }
        if(id == 1 && y > 0){
            ans += t.first;
            y--;
        }
        if(id == 2){
            ans += t.first;
            z++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12908
#include <cstdio>
#include <cstring>

typedef long long LL;

LL n, k;
LL a[200050], b[200050];
LL C[200050];

void trans(LL * A, LL * B){
	for (int i = 1; i <= n; i++){
		C[i] = A[B[i]];
	}
	for (int i = 1; i <= n; i++){
		A[i] = C[i];
	}
}

int main(){
	scanf("%lld %lld", &n, &k);
	for (int i = 1; i <= n; i++){
		scanf("%lld", a + i);
		b[i] = i;
	}
	while (k != 0){
		if (k & 1) trans(b, a);
		k >>= 1;
		trans(a, a);
	}
	printf("%lld\n", b[1]);
	return 0;
}


Measured memory_bytes: 6424
import itertools
N = int(input())
S = [input() for _ in range(N)]
march = ['M', 'A', 'R', 'C', 'H']
cnt = [0]*5
for s in S:
    if s[0] == 'M':
        cnt[0] += 1
    elif s[0] == 'A':
        cnt[1] += 1
    elif s[0] == 'R':
        cnt[2] += 1
    elif s[0] == 'C':
        cnt[3] += 1
    elif s[0] == 'H':
        cnt[4] += 1
ans = 0
for comb in itertools.combinations(cnt, 3):
    ans += comb[0]*comb[1]*comb[2]
print(ans)


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main(void){
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i,n) cin >> p[i];

	int ans = 0;
	
	rep(i,n-1){
		if(p[i]==i+1 and p[i+1]==i+2){
			swap(p[i],p[i+1]),ans++;
		}
	}

	rep(i,n) if(p[i]==i+1) ans++;
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

/*bool operator<(const data &d)const{
	return hoge;
}*/

int N,M;


int solve(){
	vector<int>g[M];
	vector<int>point(M);
	vector<int>maxPoint(N,0);
	vector<int>minPoint(N,0);
	rep(i,0,M){
		cin>>point[i];
		int t;
		cin>>t;
		rep(j,0,t){
			int tt;
			cin>>tt;
			tt--;
			g[i].push_back(tt);
			maxPoint[tt] += point[i];
			if(t==1)minPoint[tt] += point[i];
		}
	}
	int ret = 0;
	rep(i,0,N){
		rep(j,0,N){
			if(i==j)continue;
			chmax(ret,maxPoint[i]-minPoint[j]+1);
		}
	}
	return ret;
}
 
signed main(){
	IOS();
	vector<int>ans;
	while(cin>>N>>M,N||M){
		int t = solve();
		ans.push_back(t);
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}


Measured memory_bytes: 4152
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
using namespace std;
using ll = int64_t;

auto main () -> int
{
  ll sum = 0;
  rep (i, 3)
  {
    ll a;
    cin >> a;
    sum += a;
  }
  auto ans = sum >= 22;
  cout << (ans ? "bust" : "win") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define RNG(i,from,to) for(ll i=(from); i<(ll)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;

int main(int argc, char const *argv[])
{
  ll N, res = 0; cin >> N;
  RNG(i, 1, N+1) RNG(j, 1, N/i + 1) res += i*j;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
using namespace std;
    
int main(void){
    int n,m;
    cin>>n;
    // cin>>m;
    int a[n];
    int sum =0;
    for(int i=0;i<n;i++){
        a[i] = 0;
    }


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

Measured memory_bytes: 4416
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W;
    cin >> H >> W;
    ll c[11][11] = {};
    rep(i,0,10){
        rep(j,0,10){
            cin >> c[i][j];
        }
    }
    ll A[210][210] = {};
    rep(i,0,H){
        rep(j,0,W){
            cin >> A[i][j];
        }
    }
    rep(k,0,10){
        rep(i,0,10){
            rep(j,0,10){
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    ll ans = 0;
    rep(i,0,H){
        rep(j,0,W){
            if(A[i][j] >= 0){
                ans += c[A[i][j]][1];
            }
        }
    }
    print(ans);


}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  double sum = 0;
  deque<pair<double, double>> Q;
  for (int i = 0; i < n; ++i) {
    double T, V;
    scanf("%lf%lf", &T, &V);
    if (i > 0) {
      double rem = V;
      while (rem > 0) {
        if (Q.front().first > rem)  {
          Q.front().first -= rem;
          sum -= rem * Q.front().second;
          break;
        } else {
          rem -= Q.front().first;
          sum -= Q.front().first * Q.front().second;
          Q.pop_front();
        }
      }
    }
    // trace(i);
    // for (auto& it : Q) {
    //   trace(it.first, it.second);
    // }
    while (Q.size() && Q.back().second > T) {
      double V2 = Q.back().first, T2 = Q.back().second;
      Q.pop_back();
      sum -= V2 * T2;
      T = (V2 * T2 + V * T) / (V2 + V);
      V += V2;
    }
    Q.push_back({V, T});
    sum += V * T;
    printf("%.10f\n", sum / m);
  }
  return 0;
}


Measured memory_bytes: 18832
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int temp,i;
    for(i = 1;i <= n;++i){
        cin >> temp;
        a.at(i-1) = temp-i;
    }
    sort(a.begin(),a.end());
    long long ans = 0;
    for(i = 0;i < n;++i){
        ans += abs(a.at(i)-a.at(n/2));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    string s, t;
    cin >> s >> t;
    string tt = "";
    for(int i=0; i<s.length(); i++){
        tt += t[i];
    }
    if(s == tt) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
    
using namespace std;
    
#define endl "\n"
#define ll unsigned long long
//#define int long long int
#define vi vector <int >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define vii vector < pii >
#define vll vector <ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define double long double
#define a first
#define b second

const int N = 10010;
int n, h;
vii arr(1005);
int dp[N];


int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);	
    
    cin >> h >> n;
    forn(i, n)
        cin >> arr[i].a >> arr[i].b;

    dp[0] = 0;
    rep(i, 1, h + 1){
        dp[i] = INT_MAX;
        forn(x, n){
            dp[i] = min(dp[i],dp[max(i - arr[x].a,0)] + arr[x].b);
        }
    }
    cout << dp[h] << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string o,e;int i;cin >> o >> e;
  for(i=0;i<o.size()+e.size();i++){
    if(i%2==0) cout << o[i/2];
    else cout << e[i/2];
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> a(n+1);
    vector<int> b(n);
    for (int i = 0; i < n+1; i++)
    {
        int input; cin >> input;
        a[i] = input;
    }
    for (int i = 0; i < n; i++)
    {
        int input; cin >> input;
        b[i] = input;
    }

    long int ans = 0;

    for (int i = 0; i < n; i++)
    {
        int left = min(a[i], b[i]);
        a[i] -= left;
        b[i] -= left;
        ans += left;

        int right = min(a[i+1], b[i]);
        a[i+1] -= right;
        b[i] -= right;
        ans += right;
    }
    
    cout << ans << endl;

}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;;
int main(){
string s,t;
cin >> s>>t;
int a[26]={},b[26]={};
for(int i=0;i<s.size();i++){
int c=s[i]-'a';
a[c]++;
}
for(int i=0;i<t.size();i++){
int c=t[i]-'a';
b[c]++;
}
int max=0,min=0,min1=0;
for(int i=0;i<26;i++){
if(a[i]!=0&&min==0){
min=i;
}
if(b[i]!=0){
max=i;
}
}
if(min < max){
cout <<"Yes";
}
else if(max < min){
cout <<"No";
}
else{
if(a[min]<b[max]){
cout <<"Yes";
}
else{
cout <<"No";
}
}
return 0;
}

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int dp[41][401][401];

int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;
    rep(i, n+1){
        rep(j, 401){
            rep(k, 401){
                dp[i][j][k] = IINF;
            }
        }
    }
    vector<int> a(n), b(n), c(n);
    rep(i, n){
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[0][0][0] = 0;
    REP(i, 1, n+1){
        rep(j, 401){
            rep(k, 401){
                dp[i][j][k] = dp[i-1][j][k];
                if(j >= a[i-1] && k >= b[i-1]){
                    dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-a[i-1]][k-b[i-1]] + c[i-1]);
                }
            }
        }
    }
    int l = ma, m = mb;
    int ans = IINF;
    while(l <= 400 && m <= 400){
        ans = min(ans, dp[n][l][m]);
        l += ma;
        m += mb;
    }
    if(ans < IINF){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 25984
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
#define inv(v)         \
    for (auto &it : v) \
        cin >> it;
#define MOD 1000000007

void solve()
{
    vi a(5);
    inv(a);

    for(int i=0;i<5;i++){
		if(a[i] == 0){
			cout << i+1 << endl;
		}
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3616
from itertools import accumulate
import bisect

N=int(input())
A=[int(x) for x in input().split()]
S=list(accumulate(A))

def solve(x):
  cnt=S[x]
  L=bisect.bisect_left(S,cnt/2)
  R=bisect.bisect_left(S,(cnt+S[N-1])/2)
  L2=L-1
  R2=R-1
  res=10**10
  if R < N:
    ans=[S[L],cnt-S[L],S[R]-cnt,S[N-1]-S[R]]
    ans2=[S[L2],cnt-S[L2],S[R]-cnt,S[N-1]-S[R]]
    res=min(res,max(ans)-min(ans),max(ans2)-min(ans2))
  if R2 < N:
    ans3=[S[L],cnt-S[L],S[R2]-cnt,S[N-1]-S[R2]]
    ans4=[S[L2],cnt-S[L2],S[R2]-cnt,S[N-1]-S[R2]]
    res=min(res,max(ans3)-min(ans3),max(ans4)-min(ans4))
  return res

res=10**10
for i in range(N):
  a=solve(i)
  res=min(res,a)
print(res)

Measured memory_bytes: 24180
from bisect import *

S = input()
T = input()

ds = {}
for i,s in enumerate(S) :
    if s not in ds :
        ds[s] = [i]
    else :
        ds[s].append(i)
L = []
ind = -1
flg = 0
cnt = 0
for t in T :
    if t not in ds :
        ans = -1
        flg = 1
        break
if flg == 0 :
    for t in T :
        if ind >= ds[t][-1] :
            ind = ds[t][0]
            L.append(ind)
            cnt += 1
        else :
            ind = ds[t][bisect_right(ds[t], ind)]
            L.append(ind)
    ans = cnt * len(S) + L[-1] + 1
"""
    cnt = 0
    val = L[0]
    for i in range(1,len(L)) :
        if val >= L[i] :
            val = L[i]
            cnt += 1
"""
    
print(ans)

Measured memory_bytes: 50652
#include <stdio.h>

int isprime(int num){
	int i;
	if(num != 2 && num % 2 == 0){
		return 0;
	}

	for(i = 3;i*i <= num;i += 2){
		if(num % i == 0){
			return 0;
		}
	}

	return 1;
}

int main(){
	int n,a,b;

	while(scanf("%d",&n) != EOF){
		a = n-1;
		b = n+1;
		while(1){
			if(isprime(a)){
				break;
			}
			a--;
		}
		while(1){
			if(isprime(b)){
				break;
			}
			b++;
		}
		printf("%d %d\n",a,b);
	}

	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		String S = sc.next();
		int[] w = new int[n+1];
		int[] e = new int[n+1];
		for(int i = 0;i < n;i++){
			if(S.charAt(i) == 'E'){
				e[i+1] = e[i]+1;
			}else{
				e[i+1] = e[i];
			}
		}
		for(int i = 0;i < n;i++){
			if(S.charAt(i) == 'W'){
				w[i+1] = w[i]+1;
			}else{
				w[i+1] = w[i];
			}
		}
		long ans = Long.MAX_VALUE;
		for(int i = 1;i <= n;i++){
			int sum = w[i-1] + (e[n] - e[i]);
			if(sum <= ans){
				ans = sum;
			}
		}
		System.out.println(ans);
	}

}



class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 32940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100;
const ll mod = 1000000007;
int main(){
int n;
cin>>n;
n++;
int m=1;
int ans=0,cnt=0;
while(m*10<=n){
    cnt++;
    if(cnt%2==1)ans+=m*10-m;
    m*=10;
}
if(cnt%2==0)ans+=n-m;
cout<<ans<<endl;
}



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

using namespace std;

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

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            ans += vt[i];
        } else {
            ans -= vt[i];
        }
    }

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

Measured memory_bytes: 256
#include <stdio.h>

int main () {

  char vet[25];

  scanf(" %s", vet);

  vet[5]=' ';  // se você botar duas aspas significa que vc está dando uma string como argumento para uma casa só
  vet[13]= ' ';    // uma string nao consegue ficar dentro de uma casa só

  for (int k=0; k<19; k++) {
      printf("%c", vet[k]);
  }
  printf("\n");


 return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main(){
  int x,a[101],count=1;
  char str[100];
 
  while(scanf("%s",str) != EOF){
    if(str[0]=='+'){
      a[count-2] += a[count-1];  
      count--;
    }

    else if(str[0]=='-'){
      a[count-2]-=a[count-1];
      count--;
    }

    else if( str[0] == '*' ){
      a[count-2] *= a[count-1]; 
      count--;
    }

    else{
      x=atoi(str);
      a[count]=x;
      count++;
    }
  }
  printf("%d\n",a[count-1]);
  return 0;
}

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

int main() {
  int K, S, count{0};
  cin >> K >> S;
  for (int i = 0; i <= K; ++i) {
    for (int j = 0; j <= K; ++j) {
      if (i + j <= S && S - i - j <= K) {
        ++count;
      }
    }
  }
  cout << count << '\n';
  return 0;
}


Measured memory_bytes: 256