akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int score = 0, out = 0;
        int bases[3] = {};
        while (true) {
            char event[8];
            cin >> event;
            if (strcmp(event, "OUT") == 0) {
                out++;
                if (out == 3) {
                    break;
                }
            } else if (strcmp(event, "HIT") == 0) {
                score += bases[2];
                bases[2] = bases[1];
                bases[1] = bases[0];
                bases[0] = 1;
            } else if (strcmp(event, "HOMERUN") == 0) {
                score += bases[0] + bases[1] + bases[2] + 1;
                bases[0] = bases[1] = bases[2] = 0;
            }
        }
        cout << score << endl;
    }
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
int main()
{
	int i,n,m,t,b,ac,k;
	char s[100];
	char a[100];
	scanf("%s",&s);
	n=0;
	m=0;
	for(i=0;i<strlen(s);i++)
	{
		if(s[i]=='C')
		n++;
		if(s[i]=='F')
		m++;
	}
	ac=0;
	t=0;
	b=0;
	for(i=0;i<strlen(s);i++)
	{
		if(s[i]=='C')
		{
		
		t=i;
		for(k=i+1;k<strlen(s);k++)
		{
		if(s[k]=='F')
		b=k;
	}
		if(t<b)
		break;
	}
}
	if(t<b)
	printf("Yes");
	else
	printf("No");
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;

ll solve(void);
ll gcd(ll x, ll y);

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

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

ll solve(void)
{
	ll m, n;
	cin >> n >> m;
	vector<ll> a(n);

	ll sum = 0;
	for (auto& ai :a) 
	{
		cin >> ai;
		sum += ai;
	}

	ll cnt = 0;
	for (auto& ai : a)
	{
		if ( 4 * ai  * m >= sum )
			cnt ++;
	}

	cout << (cnt >= m ? "Yes" : "No" ) << endl;
	
	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define p(x) cout << x << '\n'
#define pn() cout << '\n'
#define ps(x) cout << x << ' '

#define DBG = 1

using ll = long long;


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

    int n;
    cin >> n;

    vector<int> h(n);
    for (auto &x: h) {
        cin >> x;
    }

    vector<int> dp(n, 1e9 + 7);
    dp[0] = 0;

    for (int i = 0; i < n; i++) {
        for (auto &j: {i + 1, i + 2}) {
            if (j < n) {
                auto cost = abs(h[i] - h[j]);
                dp[j] = min(dp[j], dp[i] + cost);
            }
        }
    }

    p(dp[n - 1]);

    return 0;
}

Measured memory_bytes: 1024
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
main=print.solve.V.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve=V.foldl1'(+%).(V.zipWith(*%)=<<V.scanl'(+%)0).V.tail
a+%b=(a+b)`mod`m
a*%b=(a*b)`mod`m
m=10^9+7

Measured memory_bytes: 12588
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin>>N;
	vector<LL> A(N+2);
	for(int i=1;i<=N;++i){
		cin>>A[i];
	}
	A[0] = 0;
	A[N+1] = 0;
	LL sum = 0;
	for(int i=1;i<N+2;++i){
		sum += abs(A[i]-A[i-1]);
	}
	LL res;
	for(int i=1;i<=N;++i){
		res = sum;
		res -= abs(A[i]-A[i-1])+abs(A[i+1]-A[i]);
		res += abs(A[i+1]-A[i-1]);
		cout << res << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 2048
function main(input) {
  const args = input.split(' ');
  const a = parseInt(args[0], 10);
  const b = parseInt(args[1], 10);
  const c = parseInt(args[2], 10)

  if(a<c && b<c){
    console.log(a*b/2)
  }else if(a<b){
    console.log(a*c/2)
  }else{
    console.log(b*c/2)
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
a,b,c = map(int, input().split())
i = int(str(a)+str(b))+c
i2= int(str(b)+str(a))+c
j = int(str(b)+str(c))+a
j2= int(str(c)+str(b))+a
k = int(str(c)+str(a))+b
k2= int(str(a)+str(c))+b
n = max(i,i2,j,j2,k,k2)
print(n)


Measured memory_bytes: 3064
n, m = gets.split.map(&:to_i)
ss   = m.times.map{ gets.split.map(&:to_i) }
ps   = gets.split.map(&:to_i)

# 全てのスイッチの状態を出してみる
# 2^N の計算量になるが, N=10なので計算できる範囲.
# 1=on, 0=off
sws = [[1], [0]]
(n-1).times do | i |
  new_sws = []
  sws.each do | sw |
    new_sws << [sw, 1].flatten
    new_sws << [sw, 0].flatten
  end
  sws = new_sws
end

# SWの状態が条件に一致しているか確認する
ans = 0
sws.each do | sw |
  is_good = true
  0.upto(m-1) do | i |
    sum = 0
    #p "kohan = #{ss[i].slice(1, ss[i].size)}"
    #p "   sw = #{sw}"
    ss[i].slice(1, ss[i].size).each{|j| sum += sw[j-1]}
    if ps[i] != sum%2
      is_good = false
      break
    end
  end
  ans += 1 if is_good
end
p ans

Measured memory_bytes: 2556
while true
    n = gets.to_i
    break if n == 0
    tiles = [[0, 0]]
    left = right = top = bottom = 0
    (n - 1).times{
        a, b = gets.chomp.split.map(&:to_i)
        x, y = tiles[a]
        case b
        when 0
            x -= 1
            left = x if left > x
        when 1
            y -= 1
            bottom = y if bottom > y
        when 2
            x += 1
            right = x if right < x
        when 3
            y += 1
            top = y if top < y
        end
        tiles << [x, y]
    }
    puts "#{right - left + 1} #{top - bottom + 1}"
end


Measured memory_bytes: 6852
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n, ans = 999999999;
	scanf("%lld", &n);
	long long l = sqrt(n);
	for (long long i = l; i >= 1; i--) {
		if (n % i == 0) {
			long long a, b;
			long long j = n / i;
			if (i >= 1000000000) a = 10; 
			else if (i >= 100000000) a = 9; 
			else if (i >= 10000000) a = 8;
			else if (i >= 1000000) a = 7;
			else if (i >= 100000) a = 6; 
			else if (i >= 10000) a = 5;
			else if (i >= 1000) a = 4;
			else if (i >= 100) a = 3;
			else if (i >= 10) a = 2;
			else if (i >= 1) a = 1;
			if (j >= 1000000000) b = 10; 
			else if (j >= 100000000) b = 9; 
			else if (j >= 10000000) b = 8;
			else if (j >= 1000000) b = 7;
			else if (j >= 100000) b = 6; 
			else if (j >= 10000) b = 5;
			else if (j >= 1000) b = 4;
			else if (j >= 100) b = 3;
			else if (j >= 10) b = 2;
			else if (j >= 1) b = 1;
			long long m = max(a, b);
			ans = min(ans, m);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N;
	
	cin >> N;
	
	ll A[N+1], B[N];
	
	for(int i=0; i<N+1; i++)
		cin >> A[i];
	
	for(int i=0; i<N; i++)
		cin >> B[i];
	
	ll ans = 0;
	for(int i=0; i<N; i++){
		if(A[i] >= B[i]){
			ans += B[i];
			A[i] -= B[i];
			B[i] = 0;
		}else{
			ans += A[i];
			B[i] -= A[i];
			A[i] = 0;
		}
		
		if(A[i+1] >= B[i]){
			ans += B[i];
			A[i+1] -= B[i];
			B[i] = 0;
		}else{
			ans += A[i+1];
			B[i] -= A[i+1];
			A[i+1] = 0;
		}
	}
	
	cout << ans;
	
	return 0;
}

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

int main()
{
	unsigned long long a,b;
	string s;
	cin>>a>>s;
	b=(s[0]-'0')*100+(s[2]-'0')*10+(s[3]-'0');
	cout<<a*b/100;
	return 0;
}

Measured memory_bytes: 3608
/*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
struct point{
    double x,y;
    point operator - (point rhs){return (point){x-rhs.x,y-rhs.y};}
    point operator + (point rhs){return (point){x+rhs.x,y+rhs.y};}
}p[5];
double Cross(point a,point b){return a.x*b.y-a.y*b.x;}
bool judge(){
	if(Cross(p[3]-p[1],p[2]-p[1])<0)swap(p[3],p[2]);
	if(Cross(p[2]-p[1],p[4]-p[1])>0)return 0;
	if(Cross(p[3]-p[2],p[4]-p[2])>0)return 0;
	if(Cross(p[1]-p[3],p[4]-p[3])>0)return 0;
	return 1;
}
int main(){
	int i,j;
	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",
		&p[1].x,&p[1].y,&p[2].x,&p[2].y,&p[3].x,&p[3].y,&p[4].x,&p[4].y)!=EOF){
		if(judge())printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 3212
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        //int t=Integer.parseInt(br.readLine());
        String str[]=br.readLine().split(" ");
        int a=Integer.parseInt(str[0]);
        int b=Integer.parseInt(str[1]);
        int c=Integer.parseInt(str[2]);
        int k=Integer.parseInt(br.readLine());
        while(k>0&&b<=a)
        {
            b*=2;
            k--;
        }
        while(k>0&&c<=b)
        {
            c*=2;
            k--;
        }
        if(a<b&&b<c)
        pw.println("Yes");
        else
        pw.println("No");
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 32828
#include<bits/stdc++.h>
using namespace std;
int A,B,C;
int sum_7,sum_5;
int main(){
	scanf("%d%d%d",&A,&B,&C);
	if(A==5) sum_5++;
	if(B==5) sum_5++;
	if(C==5) sum_5++;
	if(A==7) sum_7++;
	if(B==7) sum_7++;
	if(C==7) sum_7++;
	if(sum_5==2&&sum_7==1) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 3664
#include <cstdio>

const int N_BALL = 10;

int balls[N_BALL];

bool solve(int l_top, int r_top, int n) {
  if (n == N_BALL) return true;

  int l_top_ = balls[n];
  if (l_top > l_top_) return false;
  if (solve(l_top_, r_top, n+1)) return true;

  int r_top_ = balls[n];
  if (r_top > r_top_) return false;
  if (solve(l_top, r_top_, n+1)) return true;

  return false;
}

int main() {
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    for (int bi = 0; bi < N_BALL; bi++) scanf("%d", &balls[bi]);

    if (solve(-1, -1, 0)) printf("YES\n");
    else printf("NO\n");
  }

  return 0;
}

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

int main(){
  double N;
  cin >> N;
  int cnt=0;
  for(int i=1;i<=N;i++){
    if(i%2==1)cnt++;
  }
  cout << 1.0*cnt/N << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
char s[50],a[9]={1,6,8,6,8,8},i,j,p,n,q;main(){for(;scanf("%d\n",&n),n;printf("%d\n",i)){for(i=0;i<n;s[i++]=strlen(gets(s+i)));for(i=j=0;j<7;)for(p=i++,j=q=1;q>0;)for(q=a[j++];q>1;q-=s[p++]);}}

Measured memory_bytes: 1200
#include <cstdio>
#include <algorithm>
using namespace std;
int f[105][11];
int p[105][11];
int state[105];
int n;
int ans=0x80000000;
void dfs(int step, int c){
	int i, j, k;
	if(step>10){
		if(!c)
			return;
		j=0;
		for(i=1; i<=n; i++)
			j+=p[i][state[i]];
		ans=max(ans, j);
		return;
	}
	dfs(step+1, c);
	for(i=1; i<=n; i++)
		state[i]+=f[i][step];
	dfs(step+1, c+1);
	for(i=1; i<=n; i++)
		state[i]-=f[i][step];
}
int main(){
	int i, j;
	
	scanf("%d", &n);
	for(i=1; i<=n; i++)
		for(j=1; j<=10; j++)
			scanf("%d", &f[i][j]);
	for(i=1; i<=n; i++)
		for(j=0; j<=10; j++)
			scanf("%d", &p[i][j]);
			
	dfs(1, 0);
	printf("%d", ans);
	return 0;
} 

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;

//public class Problem0005_GCDandLCM {
public class Main {
	public static void main(String[] args) {
		try {
		//	Problem0005_GCDandLCM test = new Problem0005_GCDandLCM();
			Main test = new Main();
			
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			
			String line;
			while((line = reader.readLine()) != null) {
				try {
					String[] textArray = line.split(" ");
					int[] numbers = new int[2];
					for(int i = 0; i < 2; i++) {
						numbers[i] = Integer.parseInt(textArray[i]);
					}
					test.showAnswer(numbers[0], numbers[1]);
				} catch(NumberFormatException e) {
					break;
				}
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	void showAnswer(int x, int y) {
		int oddX = x;
		int oddY = y;
		int gcd = 1;	//Ååöñ
		
		while(oddX % 2 == 0 && oddY % 2 == 0) {
		//	System.out.println("denominator:" + 2 + "\tgcd:" + gcd + "\toddX:" + oddX + "\toddY:" + oddY);
			oddX = oddX / 2;
			oddY = oddY / 2;
			gcd = gcd * 2;
		}
		while(oddX % 3 == 0 && oddY % 3 == 0) {
		//	System.out.println("denominator:" + 3 + "\tgcd:" + gcd + "\toddX:" + oddX + "\toddY:" + oddY);
			oddX = oddX / 3;
			oddY = oddY / 3;
			gcd = gcd * 3;
		}
		
		int min = getMin(x, y);
		int denominator = 5;	//ªêi±êÅë¤Æ·é)
		for(int i = 0; denominator < Math.sqrt(min); i++) {
		//	System.out.println("denominator:" + denominator + "\tgcd:" + gcd + "\toddX:" + oddX + "\toddY:" + oddY);
			while(oddX % denominator == 0 && oddY % denominator == 0) {
				oddX = oddX / denominator;
				oddY = oddY / denominator;
				gcd = gcd * denominator;
			}
			if(i % 2 == 1) {	//2Æ3Ì{ðòÎ·
				denominator = denominator + 4;
			} else {
				denominator = denominator + 2;
			}
		}
		
		int lcm = gcd * oddX * oddY;
		System.out.println(gcd + " " + lcm);
	}
	int getMin(int x, int y) {
		int min;
		if(x > y) {	//y¬
			min = y;
		} else {	//x¬
			min = x;
		}
		return min;
	}
}

Measured memory_bytes: 9700
import math

def solv():
    a, b = map(int, input().split())
    x = (a + b)/2
    if (math.floor(x * 10) % 10 >= 5):
        print(math.floor(x)+1)
    else:
        print(math.floor(x))

if __name__ == '__main__':
    solv()

Measured memory_bytes: 3060
function Main(input) {
  // 数字
  var A = parseInt(input[0], 10);
  var B = parseInt(input[1], 10);
  var C = parseInt(input[2], 10);
  // 文字
  // var A = input[0];

  if (A < B) {
    if (A < C && C < B) {
      console.log('Yes');
    } else {
      console.log('No');
    }
  } else {
    if (B < C && C < A) {
      console.log('Yes');
    } else {
      console.log('No');
    }
  }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 7372
A, B, M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
x = []
y = []
c = []
setmin = 1001001001001
for _ in range(M):
    xi, yi, ci = map(int, input().split())
    x.append(xi)
    y.append(yi)
    c.append(ci)
    discountprice = a[xi-1] + b[yi-1] - ci
    if discountprice < setmin:
        setmin = discountprice
print(min(min(a)+min(b), setmin))

Measured memory_bytes: 85100
//
//  main.cpp
//  contest
//
//  Created by TmpGuest on 2020/4/18.
//  Copyright © 2020 TmpGuest. All rights reserved.
//

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
int main() {
ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    map<string, int> m;
    string s;
    cin>>n;
    while(n--) {
        cin>>s;
        m[s]++;
    }

    cout<<m.size();
    
    return 0;
}


Measured memory_bytes: 19244
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a / gcd(a , b) * b;
}
 
int main() {
    ios::sync_with_stdio(false);
    int n;
    ll a , b = 1;
    cin >> n;
    for (int i = 0 ; i < n ; i++) {
        cin >> a;
        b = lcm(a , b);
    }
    cout << b;
}

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

using namespace std;
vector<int> ans;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0) break;
		
		string word[40];
		for(int i = 0;i < n;i++){
			cin >> word[i];
		}
		
		int tanku[] = {5,7,5,7,7};
		int ini = 0;
		for(int i = 0;i < n;i++){
			if(ini != 0) break;
			int kun = 0;
			int kulen = 0;
			for(int j = i;j < n;j++){
				kulen += word[j].size();
				if(kulen == tanku[kun]){
					kun++;
					kulen = 0;
					if(kun >= 5){
						ini = i+1;
						break;
					}
				}else if(kulen > tanku[kun]){
					break;
				}
			}
		}
		ans.push_back(ini);
	}
	
	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
	
	return 0;
}


Measured memory_bytes: 3196
N = int(input())

s = {'a'}

def solve(n):
    global s
    if n == N:
        return
    new_s = set()
    for v in s:
        xc = chr(ord(max(v))+1)
        for vc in v:
            new_s.add(v + vc)
            new_s.add(v + xc)
    s = new_s
    solve(n+1)

solve(1)
ans = sorted(s)
print(*ans, sep='\n')

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

#define STRING(str) #str
#define ll long long

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}

int main() {
	string s;
	cin >> s;
	int n = s.size();
	if (s[n-1] == 's') {
		s += "es";
	} else {
		s += 's';
	}
	cout << s << endl;
}

Measured memory_bytes: 3628
def main():
    a, b = map(int, input().split())
    x = gcd(a, b)
    ans = prime_factorize(x)
    print(len(set(ans)) + 1)


def gcd(a, b):
    while b != 0:
        tmp = a % b
        a = b
        b = tmp
    return a


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main()
{
	int  N, A,T,Ans,x,calc;

	vector<int> H;
	vector<int> Sum;
	vector<int> Ditect;
	cin >> N;
	cin >> T >> A;

	for (int i = 0; i <= N - 1; i++)
	{
		cin >> x;
		H.push_back(x);
		calc = abs(1000*T -  6 * x - 1000*A);
		Sum.push_back(calc);
		Ditect.push_back(calc);
	}

	sort(Sum.begin(), Sum.end());

	for (int n = 0; n <= N - 1; n++)
	{
		if(Sum[0]==Ditect[n])
		{
			Ans = n + 1;
		}
	}

	cout << Ans << endl;


	return 0;
}

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

int main(){

	ll N;

	cin >> N;

	ll a[N+1] = {} , dpf[N+1][N+1] = {} , dps[N+1][N+1] = {};
	// dpf[i][j] := [i,j]の区間でゲームを行った際の先攻の人の得点
	// dps[i][j] := [i,j]の区間でゲームを行った際の後攻の人の得点


	for(int i=1 ; i<=N ; i++ ){
		cin >> a[i];
		dpf[i][i] = a[i];
	}

	for(int i=1 ; i<=N ; i++ ){ // i := 幅 -> 幅が小さい区間から決まっていくから
		for(int j=1 ; j+i<=N ; j++ ){ // [j,j+i]の計算

			dpf[j][i+j] = max( dps[j+1][i+j]+a[j] , dps[j][i+j-1]+a[i+j] );
			// 区間[j,i+j]で先攻の人の得点は 
			//( a[j]+区間[j+1,i+j]で後攻の人の得点 )　または　( a[j+i]+区間[j,i+j-1]で後攻の人の得点 )


			dps[j][i+j] = min( dpf[j+1][i+j] , dpf[j][i+j-1] );
			// 区間[j,i+j]で後攻の人の得点は 
			// 先攻の人がa[j]を取った場合 -> 区間[j+1,i+j]の先攻の人の得点
			// 先攻の人がa[i+j]を取った場合 -> 区間[j,i+j-1]の先攻の人の得点
			
		}
	}

	cout << dpf[1][N] - dps[1][N] << endl;

}

Measured memory_bytes: 140928
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for v, c in zip(V, C):
    if v-c > 0:
        ans += v-c
print(ans)


Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var H = G;
		var N = H[1] - H[0];
		var x = N * (N + 1) / 2;
		Console.WriteLine(x - H[1]);
	}
}


Measured memory_bytes: 11348
#include<bits/stdc++.h>
const int mo=1e9+7,N=1005;
int n,K,i,j,k,a,f[25][N],C[N][N];
int main(){
	for(i=**C=1;i<N;++i)for(j=*C[i]=1;j<=i;++j)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
	scanf("%d%d",&n,&K);f[0][n]=1;
	for(i=1;i<=K;++i){
		scanf("%d",&a);
		for(j=0;j<=a;++j)for(k=n;k>=j;--k)f[i][k-j]=(f[i][k-j]+1ll*f[i-1][k]*C[k][j]%mo*C[n-j][a-j])%mo;
	}
	printf("%d\n",f[K][0]);
	return 0;
}

Measured memory_bytes: 4224
H,W=map(int,input().split())
S=[input()for _ in range(H)]

from collections import deque
maze=[[10**4]*W for _ in range(H)]
maze[0][0]=1*(S[0][0]=='#')
que=deque([[0,0]])
while que:
    y,x=que.popleft()
    for i,j in [(1,0),(0,1)]:
        nexty,nextx=y+i,x+j
        if nexty>=H or nextx>=W:
            continue
        else:
            if S[y][x]=='.':
                if S[nexty][nextx]=='.':
                    if maze[nexty][nextx]>maze[y][x]:
                        maze[nexty][nextx]=maze[y][x]
                        que.append([nexty,nextx])
                else:
                    if maze[nexty][nextx]>maze[y][x]+1:
                        maze[nexty][nextx]=maze[y][x]+1
                        que.append([nexty,nextx])
            elif S[y][x]=='#':
                if maze[nexty][nextx]>maze[y][x]:
                    maze[nexty][nextx]=maze[y][x]
                    que.append([nexty,nextx])

print(maze[H-1][W-1])

Measured memory_bytes: 9516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }

int main(){
    string S;
    cin >> S;
    ll res = 700;
    REP(i, 3) if (S[i]=='o') res += 100;
    cout << res << "\n";
}


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

using namespace std;

int main()
{
    long long N, K;
    cin >> N;
    cin >> K;
    long long count = 1;
    while(1){
        if (N < K)
            break;
        N /= K;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;

int main(){
	int n,r;
	while(cin >> n >> r,n){
		int ds[n];
		for(int i = 0;i < n;i++) ds[i] = n - i;
		int p,c;
		for(int i = 0;i < r;i++){
			cin >> p >> c;
			int sds[n];
			p--;
			for(int t = p;t < p + c;t++) sds[t-p] = ds[t];
			for(int t = 0;t < p;t++) sds[t+c] = ds[t];
			for(int t = 0;t < p + c;t++) ds[t] = sds[t];
		}
		cout << ds[0] << endl;
	}
}

Measured memory_bytes: 1160
S = input()
K = int(input())

import collections
S_count = collections.Counter(S)

ans_list = set()

for key in S_count:
    for idx, s in enumerate(S):
        if s == key:
            short_S = S[idx:min(idx+5, len(S))]
            append_s = ""
            for s in short_S:
                append_s += s
                ans_list.add(append_s)
    if len(ans_list) >= 5:
        break
# print(ans_list)
ans_list = sorted(list(ans_list))
print(ans_list[K-1])

Measured memory_bytes: 39664
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin>>x>>y;
  int flag=0;
  for(int i=0;i<=x;i++){
    if(i*4+(x-i)*2==y){
       cout<<"Yes";
      flag=1;
      break;
    }
  }
    if(flag==0)
       cout<<"No";
  }
    

Measured memory_bytes: 3660
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}



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

    string s;
    cin>>s;
    if(n%2!=0){
        cout<<"No"<<endl;
    }
    else{
        string s1,s2;
        for(int i=0;i<n/2;i++){
            s1+=s[i];
        }
        for(int i=n/2;i<n;i++){
            s2+=s[i];
        }
        if(s1==s2){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    return 0;
    }


Measured memory_bytes: 256
h, w = map(int, input().split())
s = [input() for _ in range(h)]

ans = [[0] * w for _ in range(h)]

dr = [-1, -1, -1, 0, 1, 1, 1, 0]
dc = [-1, 0, 1, 1, 1, 0, -1, -1]

for i in range(h):
    for j in range(w):
        cnt = 0
        for k in range(8):
            nr = i + dr[k]
            nc = j + dc[k]
            if 0 <= nr < h and 0 <= nc < w:
               if s[nr][nc] == '#':
                   cnt += 1
        if s[i][j] == '#':
            ans[i][j] = '#'
        else:
            ans[i][j] = str(cnt)

for i in range(h):
    print(''.join(ans[i]))

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

using namespace std;
int main(void){

    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int result = 0;
    for(int i=0; i<=a; i++) {
        for(int j=0; j<=b; j++) {
            for(int k=0; k<=c; k++) {
                if(i*500+j*100+k*50 == x) {
                    result++;
                }
            }
        }
    }
    
    cout << result << endl;

    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for(int i = 0;i < n; i++)
using namespace std;
const int MAX = 10000000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    COMinit();
    ll n, k,m,a; cin >> n >> k;
    if ((n + k) % 3 != 0) cout << 0 << endl;
    else {
        m = n - (n + k) / 3; a = k - (n + k) / 3;
        cout << COM(m + a, a) << endl;
    }
}

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

int main()
{
    /* ------- 宣言と入力 ------- */

    int a, b;

    cin >> a >> b;

    /* ------- 計算 ------- */

    for (int i = 0; i < max(a, b); i++)
    {
        cout << min(a, b);
    }

    cout << endl;

    return 0;
}


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

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

	int N = 0;
	cin >> N;
	int a[210];
	int an = 1000;
	for (int i = 0; i < N; i++) {
		int c = 0;
		cin >> a[i];
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			c++;
		}
		an = min(c, an);
	}
	cout << an;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
sum_a = [0]
for i in range(n):
  sum_a.append(sum_a[-1] + a[i])
del sum_a[0]
del sum_a[-1]
total = sum(a)
for i in range(n - 1):
  sum_a[i] = abs(total / 2 - sum_a[i])
print(int(min(sum_a) * 2))

Measured memory_bytes: 86992
#include<iostream>
#include<cctype>

using namespace std;
int main()
{
	string s;
	int a,b;
	cin>>a>>b;
	cin>>s;
	if(s.size()!=a+b+1)
	{
		cout<<"No";
		return 0;
	}
	for(int i=0;i<s.size();i++){
		if(i!=a)
		{
		if(!isdigit(s[i])){
			cout<<"No";
			return 0;
		}
		}
		else{
			if(s[i]!='-'){
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include<tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	int n; cin >> n;
	int data[100][100];
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j) cin >> data[i][j];
	ll sum = 0;
	for (int i = 0; i < n; ++i)
		for (int j = i + 1; j < n; ++j) sum += min(data[i][j], data[j][i]);
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3136
Imports System

Module Program
    Sub Main(args As String())

        Dim N As Integer = Integer.Parse(Console.ReadLine())
        Dim tmp() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()



        Dim ans As Integer = 0
        For i As Integer = 0 To N - 3
            For j As Integer = i + 1 To N - 2
                Dim min As Integer = tmp(i)
                Dim max As Integer = tmp(i)
                If tmp(i) <> tmp(j) Then
                    If tmp(i) < tmp(j) Then
                        max = tmp(j)
                    Else
                        min = tmp(j)
                    End If
                    For k As Integer = j + 1 To N - 1
                        If tmp(i) <> tmp(k) AndAlso tmp(j) <> tmp(k) Then
                            If min < tmp(k) Then
                                If tmp(k) < max Then
                                    If min + tmp(k) > max Then
                                        ans += 1
                                    End If
                                Else
                                    If min + max > tmp(k) Then
                                        ans += 1
                                    End If
                                End If
                            Else
                                If tmp(k) + min > max Then
                                    ans += 1
                                End If
                            End If
                        End If
                    Next
                End If
            Next
        Next

        Console.WriteLine(ans)

    End Sub
End Module


Measured memory_bytes: 28416
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;
typedef long long ll;

const ll INF = 1e18;
using LP = pair<ll, int>;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

int main(void) {
  int H, W, K;
  cin >> H >> W >> K;
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x1--;
  y1--;
  x2--;
  y2--;
  vector<string> grid(H);
  rep(i, H) cin >> grid[i];

  auto toId = [&](int x, int y, int v) { return (x * W + y) * 4 + v; };
  auto modCeilK = [&](int d) { return (d - 1 + K) / K * K; };
  vector<ll> dist(4 * H * W, INF);
  priority_queue<LP, vector<LP>, greater<LP>> que;
  auto push = [&](int x, int y, int v, ll d) {
    int id = toId(x, y, v);
    if (dist[id] <= d) return;
    dist[id] = d;
    que.emplace(d, id);
  };
  rep(i, 4) push(x1, y1, i, 0);
  while (!que.empty()) {
    ll d = que.top().first;
    int id = que.top().second;
    que.pop();
    if (dist[id] != d) continue;
    int x = id / W / 4;
    int y = id / 4 % W;
    int v = id % 4;
    rep(nv, 4) push(x, y, nv, modCeilK(d));
    int nx = x + dx[v], ny = y + dy[v];
    if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
    if (grid[nx][ny] == '@') continue;
    push(nx, ny, v, d + 1);
  }
  ll ans = INF;
  rep(i, 4) ans = min(ans, dist[toId(x2, y2, i)]);
  if (ans == INF) {
    cout << -1 << endl;
  } else {
    ans = modCeilK(ans) / K;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 44092
#include<bits/stdc++.h>
using namespace std;
int a[101];
int main(){
	int a1,a2,b1,b2;
	cin>>a1>>a2>>b1>>b2;
	if(a1+a2>b1+b2)cout<<"Left";
	else if(a1+a2<b1+b2)cout<<"Right";
	else cout<<"Balanced";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {

    ll N;
    cin >> N;
    vector<ll> A(N), B(N), C(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll tmp = 0;
    vector<ll> cumlA(N), cumlB(N);
    REP(i, N){
        while(tmp < N && A[tmp] < B[i])tmp++;
        cumlA[i] = tmp;
    }
    tmp = 0;
    ll hoge = 0;
    REP(i, N){
        while(tmp < N && B[tmp] < C[i]){
            hoge += cumlA[tmp];
            tmp++;
        }
        cumlB[i] = hoge;
    }
    ll ans = 0;
    REP(i, N) ans += cumlB[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#define DEBUG 0
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
#define pb push_back
#define all(v) v.begin(), v.end()
#define for1(i, n) for (ll i = 0; i < (n); i++)
#define for2(i, m, n) for (ll i = (m); i < (n); i++)
#define for3(i, m, n, d) for (ll i = (m); i < (n); i += (d))
#define INF (1LL << 60)
#if DEBUG
#define dump(v1) dump_1(#v1, v1)
#define dump2(v1, v2) dump_2(#v1, v1, #v2, v2)
#define dump3(v1, v2, v3) dump_3(#v1, v1, #v2, v2, #v3, v3)
#else
#define dump(v1)
#define dump2(v1, v2)
#define dump3(v1, v2, v3)
#endif
#if DEBUG
template <typename T> void dump_1(const string &n1, const T &v1) {
    cerr << n1 << ": " << v1 << endl;
}
template <typename T1, typename T2>
void dump_2(const string &n1, const T1 &v1, const string &n2, const T2 &v2) {
    cerr << n1 << ": " << v1 << "  " << n2 << ": " << v2 << endl;
}
template <typename T1, typename T2, typename T3>
void dump_3(const string &n1, const T1 &v1, const string &n2, const T2 &v2,
            const string &n3, const T3 &v3) {
    cerr << n1 << ": " << v1 << "  " << n2 << ": " << v2 << "  " << n3 << ": "
         << v3 << endl;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &v) {
    os << "(" << v.first << ", " << v.second << ")";
    return os;
}
template <typename T1, typename T2, typename T3>
ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &v) {
    os << "(" << get<0>(v) << ", " << get<1>(v) << ", " << get<2>(v) << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << *it;
    }
    os << "]";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
    os << "{";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << *it;
    }
    os << "}";
    return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &v) {
    os << "{";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << it->first << ":" << it->second;
    }
    os << "}";
    return os;
}
#endif // DEBUG
void Yes(void) { cout << "Yes" << endl; }
void No(void) { cout << "No" << endl; }
void YES(void) { cout << "YES" << endl; }
void NO(void) { cout << "NO" << endl; }
template <typename T> void print(const T &v) { cout << v << endl; }
//---------------------------------------------------------
void solve() {
    ll A, B, C;
    cin >> A >> B >> C;
    print(max(0LL, C - (A - B)));
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll n,ll K)
{
    KAKA
    vl h(n);
    pragi(0,n)
    {
        cin>>h[i];
    }
    vector<ll> dp(n);
    //tie(dp[n-1],dp[n-2]) = MT(0,llabs(h[n-1] - h[n-2]));
    dp[n-1] = 0;
   if(n >= (K+1)){ pragk(n-2,n-K)
    {
        vl v;
        pragi(1,n-k)
        {
            v.eb(llabs(h[k] - h[k+i]) + dp[k+i]);
        }
        dp[k] = *min_element(v.begin(),v.end());
    }
    pragk(n-K-1,0)
    {
      //dp[k] = min((llabs(h[k] - h[k+1]) + dp[k+1]),(llabs(h[k] - h[k+2]) + dp[k+2]));
      vl vec;
      pragi(1,K+1)
      {
       vec.eb(llabs(h[k] - h[k + i]) + dp[k+i]);
      }
      dp[k] = *min_element(vec.begin(),vec.end());
    }}
    else
    {
        pragk(n-2,0)
    {
        vl v;
        pragi(1,n-k)
        {
            v.eb(llabs(h[k] - h[k+i]) + dp[k+i]);
        }
        dp[k] = *min_element(v.begin(),v.end());
    } }
    
    cout<<dp[0]<<"\n";
}
int main()
{
    KAKA
    ll n,K;
    cin>>n>>K;
    Compute(n,K);

}

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n), b(n);
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> b[i];
    }

    ll cnt = 0;
    PQ<P> pq;
    rep(i, n) {
        if(a[i] != b[i]) pq.emplace(b[i], i);
    }

    auto num = [&](int i) {
        if(i < 0) return n-1;
        if(i > n-1) return 0;
        return i;
    };
    bool out = false;
    while(!pq.empty()) {
        int now;
        tie(ignore, now) = pq.top();
        pq.pop();
        int h = b[num(now+1)] + b[num(now-1)];
        int x = b[now] % h;
        if(x < a[now] and (a[now]-x)%h == 0) {
            x = a[now];
        }
        if(h > b[now] or x < a[now]) {
            out = true;
            break;
        }
        cnt += (b[now]-x)/h;
        b[now] = x;
        if(x != a[now]) pq.emplace(x, now);
    }
    if(out) {
        cout << -1 << endl;
    } else {
        cout << cnt << endl;
    }
}

Measured memory_bytes: 6888
class segtree:
    ## define what you want to do ,(min, max)
    sta = -1
    func = max

    def __init__(self,n):
        self.n = n
        self.tree = [self.sta]*(2*n)

    def build(self, list):
        for i,x in enumerate(list,self.n):
            self.tree[i] = x

        for i in range(self.n-1,0,-1):
            self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1])

    def set(self,i,x):
        i += self.n
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1])

    ## take the value of [l,r) 
    def get(self,l,r):
        l += self.n
        r += self.n
        res = self.sta

        while l < r:
            if l & 1:
                res = self.func(self.tree[l],res)
                l += 1
            if r & 1:
                res = self.func(self.tree[r-1],res)
            l >>= 1
            r >>= 1
        return res

    def max_right(self, l, x):
        """[l,r) が ok であるような最大の r を返す"""
        N = self.n
    
        def is_ok(v):
            return v < x
    
        def get_max(a,b):
            if a is None:
                return b
            if b is None:
                return a
            return max(a,b)
        v = None
        i, node_l, node_w = l + N, l, 1
        while True:
            if not (i & 1):
                i >>= 1
                node_w <<= 1
                continue
            if node_l + node_w > N:
                break
            v1 = get_max(v, self.tree[i])
            if is_ok(v1):
                v, i = v1, (i + 1) >> 1
                node_l, node_w = node_l + node_w, node_w << 1
            else:
                break
        # 奇数セルに居て、とりきれないことが分かっている。偶数をとっていく
        i, node_w = i << 1, node_w >> 1
        while node_w:
            if node_l + node_w > N:
                i, node_w = i << 1, node_w >> 1
                continue
            v1 = get_max(v, self.tree[i])
            if is_ok(v1):
                v, i = v1, (i + 1) << 1
                node_l, node_w = node_l + node_w, node_w >> 1
            else:
                i, node_w = i << 1, node_w >> 1
        i >>= 1
        return i - N


n,q = map(int,input().split())
a = list(map(int,input().split()))

seg = segtree(n)
seg.build(a)
for _ in range(q):
    t,x,v = map(int,input().split())
    if t == 1:
        seg.set(x-1,v)
    elif t == 2:
        print(seg.get(x-1,v))
    else:
        print(seg.max_right(x-1,v)+1)

Measured memory_bytes: 98480
n = int(input())
t = list(map(int, input().split(' ')))
m = int(input())
drinks = [list(map(int, input().split(' '))) for _ in range(m)]

for drink in drinks:
    total = 0
    for i in range(n):
        if i+1 != drink[0]:
            total += t[i]
        else:
            total += drink[1]
    print(total)
        


Measured memory_bytes: 3192
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, y;
    cin>>n>>y;
    y/=1000;
    rep(i,n+1)rep(j,n+1){
        int k=n-i-j;
        if(k<0)continue;
        if(10*i + 5*j + k == y){
            cout<<i<<" "<<j<<" "<<k<<endl;
            return 0;
        }
    }
    cout <<"-1 -1 -1"<<endl;
    return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 998244353;

int main() {

    ll n;
    string s = "";
    cin >> n;
    n--;

    do {
        s.push_back(n % 26 + 'a');
        n /= 26;
        --n;
    } while (n != -1);

    for (auto itr = s.rbegin(); itr != s.rend(); ++itr) {
        cout << *itr;
    }
    cout << endl;

}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int a,b,q;
ll s[125252], t[125252], x[125252];

int main(){
  scanf("%d%d%d",&a,&b,&q);
  s[0] = -1ll<<50;
  t[0] = -1ll<<50;
  REP(i,a)scanf("%lld",s+i+1);
  REP(i,b)scanf("%lld",t+i+1);
  s[a+1] = 1ll<<50;
  t[b+1] = 1ll<<50;
  a += 2;
  b += 2;
  REP(i,q)scanf("%lld",x+i);
  REP(i,q){
    ll p = x[i];
    int sid = lower_bound(s,s+a,p) - s;
    int tid = lower_bound(t,t+b,p) - t;
    ll ans = 1ll<<60;
    CHMIN(ans, abs(p-s[sid])+abs(s[sid]-t[tid]));
    CHMIN(ans, abs(p-t[tid])+abs(t[tid]-s[sid]));
    sid--;
    CHMIN(ans, abs(p-s[sid])+abs(s[sid]-t[tid]));
    CHMIN(ans, abs(p-t[tid])+abs(t[tid]-s[sid]));
    tid--;
    CHMIN(ans, abs(p-s[sid])+abs(s[sid]-t[tid]));
    CHMIN(ans, abs(p-t[tid])+abs(t[tid]-s[sid]));
    sid++;
    CHMIN(ans, abs(p-s[sid])+abs(s[sid]-t[tid]));
    CHMIN(ans, abs(p-t[tid])+abs(t[tid]-s[sid]));
    printf("%lld\n",ans);
  }
  return 0;
}


Measured memory_bytes: 3712