akhauriyash/Code-Regression huggingface dataset:
N,C = map(int, input().split())
x = [0] * N
v = [0] * N
for i in range(N):
    x[i], v[i] = map(int, input().split())

x_cum_L = [0] * (N+1)
v_cum_L = [0] * (N+1)
x_cum_R = [0] * (N+1)
v_cum_R = [0] * (N+1)
for i in range(1, N+1):
    x_cum_L[i] = x[i-1]
    v_cum_L[i] = v_cum_L[i-1] + v[i-1]
    x_cum_R[i] = C - x[-i]
    v_cum_R[i] = v_cum_R[i-1] + v[-i]

reward_L = [0] * (N+1)
reward_R = [0] * (N+1)
for i in range(N+1):
    reward_L[i] = v_cum_L[i] - x_cum_L[i]
    reward_R[i] = v_cum_R[i] - x_cum_R[i]

reward_max_L = [0] * (N+1)
reward_max_R = [0] * (N+1)
for i in range(1, N+1):
    reward_max_L[i] = max(reward_max_L[i-1], reward_L[i])
    reward_max_R[i] = max(reward_max_R[i-1], reward_R[i])

ans = 0
for i in range(N+1):
    ans_L = reward_L[i] - x_cum_L[i] + reward_max_R[N - i]
    ans_R = reward_R[i] - x_cum_R[i] + reward_max_L[N - i]
    ans = max(ans, ans_L, ans_R)

print(ans)


Measured memory_bytes: 54872
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	uint64_t a, b, x;

	scanf("%"PRIu64" %"PRIu64" %"PRIu64, &a, &b, &x);

	printf("%"PRIu64"\n", (b/x + 1) - ((a + x - 1)/x));

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n+1),sum(n+1,0),sum2(n+1,0);
    FOR(i,1,n+1) cin>>a[i];
    ll ans=0,ans2=0;
    FOR(i,1,n+1){
      sum[i]=sum[i-1]+a[i];
      if(i%2==1 && sum[i]<=0){
        ans+=1-sum[i-1]-a[i];
        sum[i]=1;
      }
      if(i%2==0 && sum[i]>=0){
        ans+=1+sum[i-1]+a[i];
        sum[i]=-1;
      }
    }
    FOR(i,1,n+1){
      sum2[i]=sum2[i-1]+a[i];
      if(i%2==0 && sum2[i]<=0){
        ans2+=1-sum2[i-1]-a[i];
        sum2[i]=1;
      }
      if(i%2==1 && sum2[i]>=0){
        ans2+=1+sum2[i-1]+a[i];
        sum2[i]=-1;
      }
    }
    /*
    FOR(i,1,n+1){
      cout<<sum[i]<<' '<<sum2[i]<<'\n';
    }
    cout<<' '<<ans<<' '<<ans2<<'\n';
    */
    cout<<min(ans,ans2)<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    ll n, m; cin >> n >> m;
    ll h[n];
    rep(i, n){
        cin >> h[i];
    }
    vector<ll> g[n];
    rep(i, m){
        ll a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    ll ans = 0;
    rep(i, n){
        bool is_good = true;

        for(auto j : g[i]){
            if(h[i] <= h[j]){
                is_good = false;
                break;
            }
        }

        if(is_good){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10276
S=input()
A1=int(S[0:2])
A2=int(S[2:4])

if 12>=A2>=1:
    if 12>=A1>=1:
        print("AMBIGUOUS")
    else:
        print("YYMM")
else:
    if 12>=A1>=1:
        print("MMYY")
    else:
        print("NA")

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		ArrayList<Integer> prime = new ArrayList<Integer>();
		prime.add(2);
		prime.add(3);
		prime.add(5);
		prime.add(7);

		boolean sieve2[] = new boolean[100];
		Arrays.fill(sieve2, true);
		int j = 0;
		for(int i=0; i<prime.size(); i++){
			j = prime.get(i)-1;
			while(j<100){
				sieve2[j] = false;
				j += prime.get(i);
			}
		}
		sieve2[0] = false;

		for(int i=0; i<100; i++){
			if(sieve2[i]){prime.add(i+1);}
		}

		boolean sieve3[] = new boolean[10000];
		Arrays.fill(sieve3, true);
		for(int i=0; i<prime.size(); i++){
			j = prime.get(i)-1;
			while(j<10000){
				sieve3[j] = false;
				j += prime.get(i);
			}
		}
		sieve3[0] = false;
		for(int i=0; i<10000; i++){
			if(sieve3[i]){prime.add(i+1);}
		}


		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int search = 0;
		int answer = n;
		j = 0;
		for(int i=0; i<n; i++){
			search = Integer.parseInt(std.next());

			while(search >= prime.get(j)*prime.get(j)){
				if(search%prime.get(j) == 0){
					answer--;
					break;
				}else{
					j++;
					if(j>=prime.size()){break;}
				}
			}
			j = 0;
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 41080
#include<iostream>
#include<stdio.h>

using namespace std;

int main(void)
{
  char s1[15],s2[15],s3[15];
  cin>>s1>>s2>>s3;
  
  printf("%c%c%c",s1[0]-32,s2[0]-32,s3[0]-32);
  cout<<endl;
  return 0;
}



Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,k;
    cin>>a>>b>>c;
    cout<<(a+b)*c/2<<"\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        String S = sc.next();

        System.out.println(solve(N, S));
    }

    private static int solve(int N, String S) {
        int min = Integer.MAX_VALUE;

        int[] left = new int[N+2];
        int[] right = new int[N+2];
        for (int i=2; i<=N; i++) {
            right[i] = right[i-1] + (S.charAt(i-2) == 'W' ? 1 : 0);
        }
        // System.err.println(Arrays.toString(right));
        for (int i=N-1; i>=1; i--) {
            left[i] = left[i+1] + (S.charAt(i) == 'E' ? 1 : 0);
        }
        // System.err.println(Arrays.toString(left));

        for (int i=1; i<=N; i++) {
            if (min > right[i] + left[i]) {
                // System.err.println("update! i=" + i + ", right=" + right[i] + ", left=" + left[i]);
            }
            min = Math.min(min, right[i] + left[i]);
        }


        return min;
    }
}

Measured memory_bytes: 32540
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: Vec<i32> = (0..n).map(|_| input()).collect();

    let mut v = vec![];
    for i in 0..n {
        let p = v.upper_bound_by(|v| a[i].cmp(v));
        if p == v.len() {
            v.push(a[i]);
        } else {
            v[p] = a[i];
        }
    }

    println!("{}", v.len());
}

trait BinarySearch<T: Ord> {
    fn lower_bound_by<F: FnMut(&T) -> std::cmp::Ordering>(&self, f: F) -> usize;
    fn upper_bound_by<F: FnMut(&T) -> std::cmp::Ordering>(&self, f: F) -> usize;

    fn lower_bound(&self, x: &T) -> usize {
        self.lower_bound_by(|e| e.cmp(x))
    }

    fn lower_bound_by_key<U: Ord, F: FnMut(&T) -> U>(&self, x: &U, mut f: F) -> usize {
        self.lower_bound_by(|e| f(e).cmp(x))
    }

    fn upper_bound(&self, x: &T) -> usize {
        self.upper_bound_by(|e| e.cmp(x))
    }

    fn upper_bound_by_key<U: Ord, F: FnMut(&T) -> U>(&self, x: &U, mut f: F) -> usize {
        self.upper_bound_by(|e| f(e).cmp(x))
    }
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound_by<F: FnMut(&T) -> std::cmp::Ordering>(&self, mut f: F) -> usize {
        let mut l = -1 as i64;
        let mut r = self.len() as i64;
        while r - l > 1 {
            let m = ((l + r) / 2) as usize;
            if f(&self[m]) == std::cmp::Ordering::Less {
                l = m as i64;
            } else {
                r = m as i64;
            }
        }
        r as usize
    }

    fn upper_bound_by<F: FnMut(&T) -> std::cmp::Ordering>(&self, mut f: F) -> usize {
        let mut l = -1 as i64;
        let mut r = self.len() as i64;
        while r - l > 1 {
            let m = ((l + r) / 2) as usize;
            if f(&self[m]) == std::cmp::Ordering::Greater {
                r = m as i64;
            } else {
                l = m as i64;
            }
        }
        r as usize
    }
}


Measured memory_bytes: 4476
s = input()
l = [s[:-i] for i in range(1,len(s)-1)]

for i in range(len(l)):
    half = len(l[i])//2
    if len(l[i]) % 2 == 0:
        if l[i][:half] == l[i][half:]:
            print(len(l[i]))
            exit()


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

using namespace std;

bool isPrime(int n)
{
	for(int i = 2; i < n; i++)
		if((n%i)==0)
			return false;
	return true;	
}

int main()
{
	int n = 0;
	
	
	while(true)
	{
		cin>>n;

		if(n == 0)
			break;

		vector <int> myArray;
		int c = 0;

		for (int i = 2; i < n; i++)
			if(isPrime(i) == true)
				myArray.push_back(i);

		for(int j = 0; j < myArray.size(); j++)
			for(int k = j; k < myArray.size(); k++)
				if((myArray[j] + myArray[k]) == n)
					c++;

		cout<<c<<endl;
	}
	
	return 0;
}

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

int main(){
 int A,B,K; cin >> A >> B >> K;
  for(int i =min(A,B);i >=1;--i){
    if(A % i ==0 && B % i == 0){
      --K;
      if(K == 0){
        cout << i << endl;
        return 0;
      }
    }
  }
  assert(false);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int main() {
	ll A, B, C, X, Y;
	scanf("%lld %lld %lld", &A, &B, &C);
	scanf("%lld %lld", &X, &Y);

	ll v = A*X + B*Y;
	for (ll i = 0; i <= 100050; i++) {
		ll x = max(0ll, X - i);
		ll y = max(0ll, Y - i);
		v = min(v, A*x + B*y + 2*C*i);
	}
	return !printf("%lld\n", v);
}

Measured memory_bytes: 256
// Remember...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e5+10, inf=2e9;

int n,k;

vector< pair<int, pll> >vec;
vector<pll> vec2, vec3;

ll ans;

void handle();

ll solve(vector<pll> &v){
    ll ans=0, sm=0;
    for(auto p:v){
	ans+= p.F * p.S;
	sm+= p.S;
    }
    if(sz(v)<k) return ans;
    
    for(int i=0;i<k-1;i++){
	sm-= v[i].S;
    }
    for(int i=0;i<sz(v)-k+1;i++){
	ans+= v[i].F * sm;
	sm-= v[i+k-1].S;
    }
    return ans;
}
void add(int x){
    while(vec.back().F < x) handle();
    vec.PB({x,{1,1}});
}
void handle(){
    int x=vec.back().F;
    vec2.clear();
    while(vec.back().F == x){
	vec2.PB(vec.back().S);
	vec.pop_back();
    }
    reverse(vec2.begin(),vec2.end());
    ans+= solve(vec2);
    
    if(sz(vec2)<k){ add(inf); return; }
    vec3.resize( sz(vec2)/k );

    for(int i=k;i<=sz(vec2);i+=k){
	ll sm=0;
	for(int j=i;j<=min(sz(vec2),i+k-1);j++)
	    sm+= vec2[j-1].S;
	vec3[(i/k)-1].S= sm;
    }    
    reverse(vec2.begin(),vec2.end());
    reverse(vec3.begin(),vec3.end());
    for(int i=k;i<=sz(vec2);i+=k){
	ll sm=0;
	for(int j=i;j<=min(sz(vec2),i+k-1);j++)
	    sm+= vec2[j-1].F;
	vec3[(i/k)-1].F= sm;
    }
    reverse(vec3.begin(),vec3.end());

    ans-= solve(vec3);

    for(auto p:vec3){
	vec.PB({x+1,p});
    }
}

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

    cin>>n>>k;
    vec.PB({inf,{1,1}});   
    while(n--){
	int x; cin>>x;
	add(x);
    }
    add(inf);    
    return cout<<ans<<endl,0;
}
// Deathly mistakes:
//  * Read the problem carefully.
//  * Check maxn.
//  * Overflows.


// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


Measured memory_bytes: 12780
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0009
{
    public class Program

    {
        /// <summary>
        ///素数判定
        /// </summary>
        public static bool IsPrime(long number)
        {
            long boundary = (long)Math.Floor(Math.Sqrt(number));

            if (number == 1) return false;
            if (number == 2) return true;

            for (long i = 2 ; i <= boundary ; ++i)
            {
                if (number % i == 0) return false;
            }
            return true;
        }

        public static void Main(string[] args)
        {
            int[] primeCount = new int[1000000];
            primeCount[1] = 0;
            primeCount[2] = 1;

            for (int i = 3 ; i < primeCount.Length  ; i++)
            {
                if (IsPrime(i)) primeCount[i] = primeCount[i - 1] + 1;
                else primeCount[i] = primeCount[i - 1];
            }

            while (true)
            {
                string line = ReadSt();
                if (line == null) break;
                Console.WriteLine(primeCount[int.Parse(line)]);
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 19272
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int n;
double x[101],y[101],z[101],r[101];
struct data{
	double dist;
	int f,t;
	data(){}
	data(double d,int ff,int tt){
		dist=d;
		f=ff;
		t=tt;
	}
};

bool comp(const data &d1,const data &d2){
	return d1.dist<d2.dist;
}

int par[101],rank[101];
void init(int x){
	for(int i=0;i<x;i++){
		par[i]=i;
		rank[i]=0;
	}
}

int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);
}

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)return;
	if(rank[x]<rank[y]){
		par[x]=y;
	}else{
		if(rank[x]==rank[y])rank[x]++;
		par[y]=x;
	}
}

bool same(int x,int y){
	return find(x)==find(y);
}

vector<data> d;

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		d.clear();
		init(n);
		for(int i=0;i<n;i++){
			scanf("%lf %lf %lf %lf",&x[i],&y[i],&z[i],&r[i]);
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				double dist=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2)+pow(z[i]-z[j],2));
				if(dist<=r[i]+r[j])unite(i,j);
				else if(dist<fabs(r[i]-r[j]))unite(i,j);
				else d.push_back(data(dist-r[i]-r[j],i,j));
			}
		}
		sort(d.begin(),d.end(),comp);
		double res=0.0;
		for(int i=0;i<d.size();i++){
			if(!same(d[i].f,d[i].t)){
				unite(d[i].f,d[i].t);
				res+=d[i].dist;
			}
		}
		printf("%.3f\n",res);
	}
	return 0;
}

Measured memory_bytes: 1268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtheleteProgramming3
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = ab[0];
            int b = ab[1];
            if ((a + b) % 3 == 0||a%3==0||b%3==0)
            {
                Console.WriteLine("Possible");
            }else
            {
                Console.WriteLine("Impossible");
            }
        }
    }
}


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

int main() {

    int N, K;
    cin >> N >> K;
    vector<int> heights(N);
    for (int i = 0; i < N; i++)
        cin >> heights[i];


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

    int ans = 1e9 + 10;
    for (int i = 0; i < N - K + 1; i++)
    {
        ans = min(ans, heights[i + K - 1] - heights[i]);
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define all(x) begin(x), end(x)
#define range(x) begin(x), begin(x)
#define what(x) cout << #x << ": " << x << '\n'
#define print(x) for (auto &el: x) cout << el << ' '; cout << '\n'
using namespace std;
 
template<typename S, typename T>
ostream& operator <<(ostream &os, pair<S, T> &m) { 
    os << '[' << m.first << " " << m.second << ']'; 
    return os; 
}

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

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

    vector<int> res;
    for (int i = 0; i < n; ++i) {
        res.push_back(v[i]);
        if (i < n - 1) res.push_back(v[i]);
    }

    reverse(begin(res), end(res));

    ll ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        ans += res[i];
    }

    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 6064
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#include<cassert>
#include<queue>
#include<map>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 101
#define inf (1<<29)
using namespace std;
int a[MAX];
int A[10001];
int n;
double b,r,v,e,f;
double mincost[MAX][10001];
 
struct P
{
  int last;
  double x,cost,now;
  P(double now=-1,double x=-1,double cost=-1,int last=-1):now(now),x(x),cost(cost),last(last){}
  bool operator < (const P &a)const
  {
    return cost >= a.cost;
  }
};
 
double getCost(double x)
{
  if(x >= r)return 1.0/(v - e * (x - r));
            return 1.0/(v - f * (r - x));    
}
 
void dijkstra()
{
  double ans = inf;
  rep(i,n)rep(j,10001)mincost[i][j] = inf;
  mincost[0][0] = 0;
 
  priority_queue<P> Q;
  Q.push(P(0,0,0,0));
 
  while(!Q.empty())
    {
      P p = Q.top(); Q.pop();
      if(p.now >= a[n-1])
    {
      ans = min(ans,p.cost);
      continue;
    }    
 
      if(ans <= p.cost)continue;
 
      assert(0 <= p.cost);
      double ncost = p.cost + getCost(p.x);
      assert(0 <= ncost);
 
      if(mincost[p.last][(int)p.now+1] > ncost)
    {
      mincost[p.last][(int)p.now+1] = ncost;
      Q.push(P(p.now+1,p.x+1,ncost,p.last));
    }
 
      if(A[(int)p.now+1] != -1)
    {
      double change_cost = (A[(int)p.now+1]==n?0:b);
      ncost += change_cost;
      Q.push(P(p.now+1,0,ncost,A[(int)p.now+1]));
    }
 
    }
 
  cout << setiosflags(ios::fixed) << setprecision(4) << ans << endl;
}
 
int main()
{
  while(cin >> n,n)
    {
      rep(i,10001)A[i] = -1;
      rep(i,n)
    {
      cin >> a[i];     
      A[a[i]] = i+1; 
    }
      cin >> b >> r >> v >> e >> f;
    
 
      dijkstra();
 
    }
  return 0;
}

Measured memory_bytes: 9536
import array
n,w=map(int,input().split())
weight=[]
value=[]
for _ in range(n):
    tempw,tempv=map(int,input().split())
    weight.append(tempw)
    value.append(tempv)
t=[[0 for i in range(n+1)] for j in range(w+1)]
for i in range(1,w+1):
    for j in range(1,n+1):
        if(weight[j-1]<=i):
            t[i][j]=max(value[j-1]+t[i-weight[j-1]][j-1],t[i][j-1])
        else:
            t[i][j]=t[i][j-1]
print(t[-1][-1])


Measured memory_bytes: 165916
h, w = list(map(int, input().split()))

c = []

for i in range(h):
    c.append(input())

for i in range(h*2):
    if i == 0:
        print(c[0])
    elif i == 1:
        print(c[0])
    elif i%2 == 0:
        print(c[i//2])
    else:
        print(c[(i-1)//2])

Measured memory_bytes: 3060
n = int(input())

cnt1 = 0
cnt2 = 0
cnt4 = 0

for d in map(int,input().split()):
    if d%4==0:
        cnt4+=1
        continue
    if d%2==0:
        cnt2+=1
        continue
    cnt1+=1
res = True
if cnt2>0:
    res = (cnt1<=cnt4)
else:
    res = (cnt1<=(cnt4+1))

if res:
    print("Yes")
else:
    print("No") 


Measured memory_bytes: 11480
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

void solve(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    ll sum  = 0;
    rep(i, n) sum += a[i];
    if(sum%10) ANS(sum);
    ll f = inf;
    rep(i, n)
    {
        if(a[i]%10 != 0) f = min(f, a[i]);
    }
    if(f == inf) ANS(0);
    ANS(sum-f);
}

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



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using Weight = int;
using Flow = int;
struct Edge {
	int s, d; Weight w; Flow c;
	Edge() {};
	Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
	addArc(g, a, b, w);
	addArc(g, b, a, w);
}

struct UnionFind {
	vector<int> parent;
	int size;
	UnionFind(int n) :parent(n, -1), size(n) {}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y)return false;
		if (sizeOf(x) < sizeOf(y))swap(x, y);
		parent[x] += parent[y]; parent[y] = x; size--;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
	int sizeOf(int x) { return -parent[root(x)]; }
};

pair<Weight, Edges> kruskal(const Graph &g) {
	int n = g.size();
	UnionFind uf(n);
	Edges es;
	for (int i = 0; i < n; i++)
		for (auto &e : g[i])
			es.emplace_back(e);
	sort(es.begin(), es.end());
	Weight total = 0;
	Edges mst;
	for (auto &e : es)
		if (!uf.same(e.s, e.d)) {
			uf.unite(e.s, e.d);
			mst.push_back(e);
			total += e.w;
		}
	return make_pair(total, mst);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	using T = pair<int, int>;
	vector<T> a, b;
	rep(i, 0, N) {
		int x, y; cin >> x >> y;
		a.emplace_back(x, i);
		b.emplace_back(y, i);
	}
	sort(all(a));
	sort(all(b));
	Graph g(N);
	rep(i, 0, N - 1) {
		addEdge(g, a[i].second, a[i + 1].second, a[i + 1].first - a[i].first);
		addEdge(g, b[i].second, b[i + 1].second, b[i + 1].first - b[i].first);
	}
	cout << kruskal(g).first << endl;
	return 0;
}

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

using ll=long long;
const ll z=0;

int main() {
  int H,W,K;
  int ans=1020;
  cin >> H >> W >> K;
  vector<string> s(H);
  for(int i=0;i<H;i++){
    cin >> s[i];
  }
  for(int div=0;div<(1<<H-1);div++){
    int group=0;
    vector<int> id(H);
    for(int i=0;i<H;i++){
      id[i]=group;
      if(div>>i&1){
        group++;
      }
    }
      group++;
      vector<vector<int>> c(group,vector<int>(W,0));
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          c[id[i]][j] +=(s[i][j]-'0');
        }
      }
      int cnt=group-1;
      vector<int> now(group,0);
      auto add = [&](int j){
        for(int i=0;i<group;i++){
          now[i] +=c[i][j];
        }
        for(int i=0;i<group;i++){
          if(now[i]>K){
            return false;
          }
        }
        return true;
      };
      for(int j=0;j<W;j++){
        if(!add(j)){
          cnt++;
          now=vector<int> (group,0);
          if(!add(j)){
            cnt=1020;
            break;
          }
        }
      }
      ans=min(ans,cnt);
    }
  cout << ans << endl;
}

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

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

int main() {
    int N;
    string S;

    cin >> N;
    cin >> S;

    if (S.size() % 2) {
        cout << "No" << endl;
        return 0;
    }
    
    bool flg = true;
    for (int i = 0; i < (N / 2); i++) {
        if (S.at(i) != S.at((N / 2) + i)) {
            flg = false;
            break;
        }
    }

    cout << (flg ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n, y = map(int, input().split())
for m10000 in range(n + 1):
  for m5000 in range(n + 1 - m10000):
    m1000 = n - m10000 - m5000
    if m10000 * 10000 + m5000 * 5000 + m1000 * 1000 == y:
      print(m10000, m5000, m1000)
      exit(0)
print('-1 -1 -1')

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



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

	int n, a;
	int min=9999999, pos=0;
    cin>>n>>a;
    int arr[a];
    int ans;
	for(int i=0; i<a; i++){
		cin>>arr[i];
	}
	sort(arr, arr+a);
	if(a == 0){
		cout<<n;
	}else{
		
	
		for(int i=arr[0]-1; i<=arr[a-1]+1; i++){
			if(i == arr[pos]){
	
				pos ++;
				continue;
			}
			int temp = abs(n-i);
			if(temp < min) {
				min = temp;
				ans = i;
			}
			
			
		}
		cout<<ans;
	}
		
	

		
	
		
  return 0;
}

Measured memory_bytes: 3644
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    S = input()

    ans = 0
    for i in range(N):
        X = S[:i+1]
        Y = S[i+1:]
        syurui = 0
        onaji = {}
        for x in X:
            if (x in Y) and (not x in onaji):
                onaji[x] = True
                syurui += 1
        ans = max(ans, syurui)
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	ll ans = 0;
	FOR(b, 1, N+1) {
		ans += max(0LL,(N / b) * (b - K));
		ans += max(0LL,(N % b) - K + 1);
		if (K == 0)ans--;
	}
	cout << ans << endl;
	PAU;
	return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt1 = 0, cnt2 = 0;
  for (auto& c : s) {
    if (c == '.') {
      cnt2++;
    }
  }
  int ans = 2 * n;
  for (auto& c : s) {
    ans = min(ans, cnt1 + cnt2);
    if (c == '#') {
      cnt1++;
    } else {
      cnt2--;
    }
  }
  ans = min(ans, cnt1 + cnt2);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 720
// 2020Mcontest1.cpp : 定义控制台应用程序的入口点。

#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;


int main()
{
	string s1, s2;
	cin >> s1 >> s2;
	cout << s2.append(s1) << endl;
    return 0;
}



Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let x: i64 = sc.cin();
    let n: usize = sc.cin();
    let ps: std::collections::HashSet<i64> = sc.vec(n).iter().cloned().collect();
    let mut ans = 0;
    for z in -200..200 {
        if (x - z).abs() < (ans - x).abs() && !ps.contains(&z) {
            ans = z;
        }
    }
    put!(ans);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


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

int main(){
  string s;
  cin>>s;
  int k=1;
  if(s.size()==1) {cout<<"No"; return 0;}
  for(int i=0;k<=s.size();i+=2){
    if(s[i]!='h' || s[k]!='i'){ cout<<"No"; return 0;}
    k+=2;
  }
  cout<<"Yes";
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	char x;
	std::cin >> x;
	print((char)(x+1));
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll,pair<ll,ll> > pp;
pp mm[100001];
ll d[100001];

int main(){
    ll n,h;
    ll ans=0;
    cin>>n>>h;
    ll di,hi,ch=h;
    for(int i=0;i<n-1;++i){
        cin>>di>>hi;
        mm[i].first=ch+hi<=h||ch<0 ? hi:h-ch;mm[i].second.first=i;mm[i].second.second=ch;
        d[i]=di;
        ch -= di;
    }
    int l=0;
    for(int i=0;i<n;++i){
        ch=mm[i].second.second;
        if(ch<=0){
            pp t=*max_element(mm+l,mm+i);
            hi=t.first;
            int ch2=t.second.second;
            i=t.second.first;l=i;
            int dv;
            if(-ch/hi+1>(h-ch2)/hi-1){
                dv=(h-ch2)/hi;
                ans+=dv;
                ch=ch2+hi*dv;
            } 
            else{
                dv=-ch/hi+1;
                ans+=dv;
                ch=min(h,ch2+hi*dv); 
            }             
        }
        hi=mm[i].first;
        mm[i].first=ch+hi>h ? h-ch:hi;
        mm[i].second.second=ch; 
        mm[i+1].second.second= ch-d[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6224
x, y = gets.split(" ").map(&:to_i)
a = Array.new(x){gets.split(" ").map(&:to_i)}
b = Array.new(y){gets.to_i}

x.times do |i|
  element = 0
  y.times do |j|
    element += a[i][j] * b[j]
  end
  puts element
end

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

int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(void){
    long long int n, ans, wari;
    vector<long long int> traffic(5);
    cin >> n;
    for(long long int i = 0LL; i < 5LL; i++) cin >> traffic[i];
    sort(traffic.begin(), traffic.end());
    if(n % traffic[0] == 0) wari = n / traffic[0] - 1LL;
    else wari = n / traffic[0];
    ans = 5LL + wari;
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n)cin >> a[i];
    
    map<ll, ll> cnt;
    ll ans = 0;
    ll sum[n];
    sum[0] = a[0];
    cnt[sum[0]] = 0;
    if(sum[0] == 0)ans++;
    for(ll i = 1; i < n; ++i){
        sum[i] = sum[i-1] + a[i];
        if(sum[i] == 0)ans++;
        if(cnt.find(sum[i]) != cnt.end()){
            cnt[sum[i]]++;
            ans += cnt[sum[i]];
        }
        else{
            cnt[sum[i]] = 0;
        }
    }
    cout << ans << endl;

    // all_map(itr,cnt)cout << itr->first << " : " << itr->second << endl;
}

Measured memory_bytes: 15872
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    now_a_i=a[i]
    now_b_i=b[i]
    if now_a_i>=now_b_i:
        a[i]=now_a_i-now_b_i
        b[i]=0
        ans+=now_b_i
    else:
        a[i]=0
        b[i]=now_b_i-now_a_i
        ans+=now_a_i
        now_a_i_1=a[i+1]
        now_b_i=b[i]
        if now_a_i_1>=now_b_i:
            a[i+1]=now_a_i_1-now_b_i
            b[i]=0
            ans+=now_b_i
        else:
            a[i+1]=0
            b[i]=now_b_i-now_a_i_1
            ans+=now_a_i_1
print(ans)

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int D;
  cin>>D;
  vector<int> c(26+1);
  for(int i(1);i<27;i++){
    cin>>c[i];
  }
  vector<vector<int>> s(D+1,vector<int>(26+1));
  for(int i(1);i<=D;i++){
    for(int j(1);j<=26;j++){
      cin>>s[i][j];
    }
  }
  vector<int> t(D+1);
  int nowp(0);
  vector<int> l(D,0);
  for(int i(1);i<=D;i++){
    int maxj(0),maxp(-1e9);
    for(int j(1);j<=26;j++){
      //i日目がj番目の場合
      int tmp(nowp);
      tmp += s[i][j];
      for(int k(1);k<=26;k++){ //ここ一度和を計算しておけば、何回も引くものを計算しなくても良い
        if(k == j) continue;
        tmp -= c[k]*(i - l[j]);
      }
      if(maxp < tmp) {
        maxj = j;
        maxp = tmp;
      }
    }
    t[i] = maxj;
    // 貪欲的にmaxj番目と決める
    nowp += s[i][maxj];
    l[maxj] = i;
    for(int j(1);j<=26;j++){
      nowp -= c[j]*(i - l[j]);
    }
  }

  for(int i(1);i<=D;i++){
    cout << t[i] << endl;
  }
  return 0;
}



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

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

max_edge = 0

for i in range(h):
    if c[i][0] == 0:
        dp[i][0] = 1
        max_edge = 1
for i in range(w):
    if c[0][i] == 0:
        dp[0][i] = 1
        max_edge = 1
        
        
for i in range(1,h):
    for j in range(1,w):
        if c[i][j] == 1:
            dp[i][j] = 0
        else:
            dp[i][j] = min(dp[i][j-1],dp[i-1][j],dp[i-1][j-1]) + 1
            max_edge = max(max_edge,dp[i][j])

print(max_edge**2)


Measured memory_bytes: 55188
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool comp (const string& s, const string& t) {
  if(s.size() != t.size()) return s.size() < t.size();
  return s < t;
}
string smin(const string& s, const string& t){
  if(comp(s, t)) return s;
  else return t;
}

int main(){
  int N;
  while(cin>>N && N){
    vector<string> v_(N);
    REP(i, N) cin>>v_[i];
    vector<bool> need(N, true);
    REP(i, N)REP(j, N) if(v_[i] != v_[j] && v_[i].find(v_[j]) != string::npos) need[j] = false;
    REP(i, N)REP(j, N) if(i != j && v_[i] == v_[j]) need[max(i, j)] = false;
    vector<string> v;
    REP(i, N) if(need[i]) v.push_back(v_[i]);
    N = v.size();
    string dp[1<<10][10];
    REP(i, 1<<N)REP(j, N)dp[i][j] = string(200, '~');
    REP(i, N){
      dp[1<<i][i] = v[i];
    }
    for(int S = 0; S < 1<<N; S++){
      for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
          if(((S >> i) & 1) && !((S >> j) & 1)){
            dp[S | (1<<j)][j] = smin(dp[S | (1<<j)][j], dp[S][i] + v[j]);
            for(int k = 1; k < min(dp[S][i].size(), v[j].size()); k++){
              if(dp[S][i].substr(dp[S][i].size() - k, k) == v[j].substr(0, k)){
                dp[S | (1<<j)][j] = smin(dp[S | (1<<j)][j], dp[S][i] + v[j].substr(k));
              }
            }
          }
        }
      }
    }
    string ans = string(200, '~');
    REP(i, N) ans = smin(ans, dp[(1<<N) - 1][i]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;
int n, l, r, pr[N], s[N];
int main() {
	int i, j;
	for(i=2; i<N; i++) if(!pr[i])
		for(j=i*2; j<N; j+=i) pr[j]=1;
	for(i=3; i<N; i+=2) {
		s[i] = s[i-2];
		if(!pr[i] && !pr[(i+1)/2]) s[i]++;
	}
	scanf("%d", &n);
	while(n--) {
		scanf("%d%d", &l, &r);
		printf("%d\n", s[r] - s[max(l-2, 1)]);
	}
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace  std;
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

  
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define re(n) for (int i = 0; i < n; ++i)
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define eb emplace_back

//OutPut
#define ps(x) cout << x << endl;
#define ps_end(x) {ps(x); return;}


const int md = 1e9 + 7; //998244353 ;
const int dir[4][2] = {{-1,0}, {1, 0}, {0, -1}, {0, 1}};
template<class T> bool ckmin(T& a, const T& b) { 
  return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { 
  return a < b ? a = b, 1 : 0; }
ll pw(auto x, auto y) {  ll s = 1; while(y) { if (y & 1) s = s * x % md; x= 1LL * x * x % md; y /= 2; } return s;}

const int maxn = 1e6 + 10;

int n, m, nq, nk;
string str;

void task() {
  ll n, x ,m;
  cin >> n >> x >> m;
  vi use(m);
  use[x] = 1;
  vector<ll> sum(m + 1);
  sum[1] = x;
  for (int i = 2; i <= n; ++i) {
   x = x * x % m;
   sum[i] = sum[i - 1] + x; 
   if (use[x]) {
    int len = i - use[x];
    ll cycle_sum = sum[i] - sum[use[x]]; 
    ll remain = n - use[x];
    cout <<  sum[use[x]] + cycle_sum * (remain  / len) + sum[remain % len + use[x]] - sum[use[x]] << endl;   
    return; 
   }
   use[x] = i;

  }
  cout << sum[n] << endl;
  //Read the stuff at the bottom
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout<<fixed<<setprecision(20);
  int T = 1;
 // cin >> T;
  for (int ti = 1; ti <= T; ++ti) {
    task();
  }
  return 0;
}

/* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
  * write down
*/


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	int N;
	int d[105];
	int sum = 0;

	cin >> N;
	rep(i, N)
		cin >> d[i];

	rep(i, N - 1)
	{
		for (int j = i + 1; j < N; j++)
			sum += d[i] * d[j];
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll util(ll R){
	ll rem[]={R,1,R+1,0};
	return rem[R%4];
}
int main(){
	ll A,B;
	cin>>A>>B;
	if(A>0){
		ll res=util(B)^util(A-1);
		cout<<res<<endl;
	}else{
		cout<<util(B)<<endl;
	}
}

Measured memory_bytes: 256