akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define PI 3.1415926535897932384626
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,a,b) for(i=a;i<b;i++)
#define ll long long
#define pb push_back
#define popb pop_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define ini(a) memset(a,-1,sizeof(a))
#define M (ll)(1e9+7)

#define chk(a) cout << endl << #a << " : " << a << endl
#define chk2(a,b) cout << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cout << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cout << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl


using namespace std;

typedef pair<int, int>	pi;
typedef pair<int,pi>    pii;
typedef pair<ll, ll>	pl;
typedef pair<ll,pl>     pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pi>		vpi;
typedef vector<pii>     vpii;
typedef vector<pl>		vpl;
typedef vector<pll>     vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;


void add_self_modulo(ll &a,ll b){
	a+=b;
	if(a>=M){
		a-=M;
	}
}

void sub_self_modulo(ll &a,ll b){
	a-=b;
	if(a<0LL){
		a+=M;
	}
}


void solve(){
	
	ll n,k,K,i,j,aj;
	cin>>n>>K;
	//cout<<n<<" "<<K<<endl;
	ll a[n];
	fo(i,n){cin>>a[i];}
	vector<ll> dp(K+1,0);
	dp[0]=1LL;

	//dp[i]=no of ways to distribute i candies among j children
	
	fo(i,n){
		vector<ll> fake(K+2,0LL);
		//for(ll used_candies=K;used_candies>=0LL;used_candies--){
		for(ll used_candies=0;used_candies<=K;used_candies++){
			ll limit=min(a[i],K-used_candies);
			ll L=used_candies+1;
			ll R=used_candies+limit;
			if(L>R)continue;
			add_self_modulo(fake[L],dp[used_candies]);
			sub_self_modulo(fake[R+1],dp[used_candies]);
		}
		ll prefix_sum=0LL;
		for(j=0;j<=K;j++){
			add_self_modulo(prefix_sum,fake[j]);
			add_self_modulo(dp[j],prefix_sum);
		}
	}
	//cout<<"hey\n";
	cout<<dp[K]<<endl;
	//cout<<"hi\n";




}



int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   string s;
   cin >> s;
   int n = s.length();
   if(n & 1){
      cout << "No\n";
      return 0;
   }
   f(i,0,n){
      if(i&1){
         if(s[i]!='i'){
            cout << "No\n";
            return 0;
         }
      }else{
         if(s[i]!='h'){
            cout << "No\n";
            return 0;
         }
      }
   }
   cout << "Yes";
   return 0;
}

Measured memory_bytes: 256
<?php
$input = preg_split('/ /', trim(fgets(STDIN)));

$d= $input[0];
$a = $input[1];
$b = $input[2];
if ($b <= $a) {
    echo "delicious";
} else if ($b <= $a + $d) {
    echo "safe";
} else if ($b > $a + $d) {
    echo "dangerous";
}
?>

Measured memory_bytes: 3828
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N;
//deque<ll> a;
vector<ll> a;
ll m[3000][3000][2];

void init()
{
}

ll rec(int l, int r, int turn)
{
    //cout << l << " " << r << " " << turn << endl;
    if(l > r) return 0;
    if(m[l][r][turn] != -1) return m[l][r][turn];
    ll ret = 0;
    if(turn == 0){
        ret = max(rec(l+1, r, 1) + a[l], rec(l, r-1, 1) + a[r]);
    }else{
        ret = min(rec(l+1, r, 0) - a[l], rec(l, r-1, 0) - a[r]);
    }
    //cout << l << " " << r << " " << turn << " " << ret << endl;
    return m[l][r][turn] = ret;
}

void solve()
{
    REP(i, N) REP(j, N) REP(k, 2) m[i][j][k] = -1;
    cout << rec(0, N-1, 0) << endl;
#if 0
    ll ret = 0;
    deque<ll> ra(a);
    reverse(ALL(ra));
    int turn = 0;
    while(a.size() != 0){
        auto ita = a.begin(), itra = ra.begin();
        bool update = false;
        while(ita != a.end() && itra < ra.end()){
            if(*ita > *itra){
                ret += (turn == 0 ? a.front() : -a.front());
                a.pop_front();
                ra.pop_back();
                update = true;
                break;
            }else if(*ita < *itra){
                ret += (turn == 0 ? a.back() : -a.back());
                a.pop_back();
                ra.pop_front();
                update = true;
                break;
            }
            ita++;
            itra++;
        }
        if(!update){
            ret += (turn == 0 ? a.front() : -a.front());
                a.pop_front();
                ra.pop_back();
        }
        turn = (turn + 1) % 2;
    }
    cout << ret << endl;
#endif
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N){
        ll v;
        cin >> v;
        a.pb(v);
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 141056
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <set>

using namespace std;
using ll = long long;

template<typename T> void print(T t) { cout << t << endl; }
ll MOD = 1000000007;

int main() {
	int N, cR=0, ans=0;
	string cs;
	cin >> N >> cs;
	for(char& c : cs){
		if (c == 'R') cR++;
	}
	for (int i = 0; i < cR; i++) {
		if (cs[i] == 'W') ans++;
	}
	print(ans);
}

Measured memory_bytes: 3712
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap, VecDeque};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;
#[allow(dead_code)]
const MODLL: i64 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn solve(s: &Vec<char>, l: usize, r: usize, k: usize, mut dp: &mut Vec<Vec<Vec<i32>>>) -> i32 {
    if l > r {
        return 0
    }
    if dp[l][r][k] != -1 {
        return dp[l][r][k]
    }
    if l == r {
        dp[l][r][k] = 1;
        return 1
    }

    dp[l][r][k] = 0;
    if s[l] == s[r] {
        dp[l][r][k] = solve(&s, l + 1, r - 1, k, &mut dp) + 2;
    }
    if k + 1 < dp[0][0].len() {
        dp[l][r][k] = max(dp[l][r][k], solve(&s, l + 1, r - 1, k + 1, &mut dp) + 2);
    }
    dp[l][r][k] = max(dp[l][r][k], solve(&s, l + 1, r, k, &mut dp));
    dp[l][r][k] = max(dp[l][r][k], solve(&s, l, r - 1, k, &mut dp));

    dp[l][r][k]
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let (s, k): (String, usize) = (sc.read(), sc.read());
    let s: Vec<char> = s.chars().collect();
    let mut dp: Vec<Vec<Vec<i32>>> = vec![vec![vec![-1; k + 1]; s.len()]; s.len()];

    println!("{}", solve(&s, 0, s.len() - 1, 0, &mut dp));
}

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

ll a[200500], b[200500],N;

int main(){
    cin >> N;
    FOR(i, 1, N+1)cin >> a[i];
    ll crash=0;
    int n = 1;
    for(int i=1;i<=N;i++)
    {
        bool flag=false;
        for(int j=n;j<=N;j++)
        {
            if(a[j]!=i){crash++;if(crash>N-1){cout << -1 << endl;return 0;}}
            else {n=j+1;b[i]++;break;}
        }
        if(crash>N-1){cout << -1 << endl;return 0;}
        if(b[i]==0)
        {
            break;
        }
    }
    cout << crash << endl;
    return 0;
}

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

int main() {
    int H , W ;
    cin >> H >> W ;
	string S = "";
    char temp;
    for(int i = 0 ; i < H * W ; i++){
    	cin >> temp;
        S += temp;
    }
    for(int i = 0; i < H * W; i++){
    	if(S.at(i) == '#'){
        	cout << "#";
        }
        else{
        	int count = 0;
            int x = i % W;
            int y = i / W;
            if((x > 0 && y > 0) && S.at((x - 1)+ (y - 1) * W) == '#'){
            	count++;
            }
            if((y > 0) && S.at(x + (y - 1) * W) == '#'){
            	count++;
            }
            if((x + 1 < W && y > 0) && S.at((x + 1) + (y - 1) * W) == '#'){
            	count++;
            }
            if(x > 0 && S.at((x - 1)+ y * W) == '#'){
            	count++;
            }
            if(x + 1 < W && S.at((x + 1)+ y * W) == '#'){
            	count++;
            }
            if((x > 0 && y + 1 < H) && S.at(x - 1 + (y + 1) * W) == '#'){
            	count++;
            }
            if((y + 1 < H) && S.at(x + (y + 1) * W) == '#'){
            	count++;
            }
            if((x + 1 < W && y + 1 < H) && S.at(x + 1 + (y + 1) * W) == '#'){
            	count++;
            }
            cout << count;
        }
        if((i + 1) % W == 0){
        	cout << endl;
        }
    }
}


Measured memory_bytes: 3620
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from numba import njit

def main():
    N = int(input())
    @njit
    def solve(N):
        for h in range(1, 3501):
            for n in range(1, 3501):
                shisu = h * N * n
                bosu = n * (h * 4 - N) - h * N
                if bosu >= 1:
                    if not (shisu / bosu) % 1:
                        return h, n , int((h * N * n) / (n * (h * 4 - N) - h * N))
    r = solve(N)
    print(*r , sep=' ')

if __name__ == '__main__':
    main()


Measured memory_bytes: 109688
import math
a,b,C = input().split( )
a1 = float(a)
b1 = float(b)
C1 = float(C)
print(a1*b1*math.sin(math.radians(C1))/2)
c1 = math.sqrt(a1**2+b1**2-2*a1*b1*math.cos(math.radians(C1)))
print(a1+b1+c1)
print(b1*math.sin(math.radians(C1)))


Measured memory_bytes: 5688
n = input()
a_list = list(map(int, input().split()))
ruisekiwa = [0] * (len(a_list) + 1) 
for i in range(len(a_list)):
    ruisekiwa[i + 1] = ruisekiwa[i] + a_list[i]
sum_ = 0
mod = 10 ** 9 + 7
for i in range(len(a_list)):
    sum_ += ((a_list[i] % mod) * ((ruisekiwa[-1] % mod) - (ruisekiwa[i + 1] % mod))) % mod
print(sum_ % mod)

Measured memory_bytes: 31612
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main(int argc, char* argv[])
{
  int count =1;
  while(1)
  {
    int t; 
    cin >>t;
    if(t==0)
    {
      cout << count;
      break;
    }
    ++count;
  }
  return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cctype>
#include <queue>
#define ll long long 
#define ri register int 
using namespace std;
template <class T>inline void read(T &x){
    x=0;int ne=0;char c;
    while(!isdigit(c=getchar()))ne=c=='-';
    x=c-48;
    while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
    x=ne?-x:x;return ;
}
const int maxn=100005;
int N,m;
int a[maxn];
ll ans=0;
struct Op{
	int v,cnt;
	bool operator<(const Op&x)const {
		return v>x.v;
	}
}opt[maxn];
struct Heap{
	int n,heap[maxn];
	inline void up(int fa){
		while(fa>1){
			if(heap[fa]<heap[fa>>1]){
				swap(heap[fa],heap[fa>>1]);
				fa=fa>>1;
			}
			else break;
		}
	}
	inline void push(int v){
		heap[++n]=v;
		up(n);
	}
	inline void down(int fa){
		int s=fa<<1;
		while(s<=n){
			if(s<n&&heap[s]>heap[s+1])s++;
			if(heap[s]<heap[fa]){
				swap(heap[s],heap[fa]);
				fa=s;s=fa<<1;
			}
			else break;
		}
	}
	inline void pop(){
		heap[1]=heap[n--];
		down(1);
	}
	inline int top(){
		return heap[1];
	}
}q;
int main(){
	int b,c;
	read(N),read(m);
	for(ri i=1;i<=N;i++){
		read(a[i]);
		q.push(a[i]);
		ans+=a[i];
	}
	for(ri i=1;i<=m;i++){
		read(opt[i].cnt),read(opt[i].v);
	}
	sort(opt+1,opt+1+m);
	//printf("%d\n",opt[1].v);
	for(ri k=1;k<=m;k++){
		b=opt[k].cnt,c=opt[k].v;
		bool flag=0;
		for(ri i=1;i<=b&&!flag;i++){
			if(q.top()>=c){flag=1;}
			else{
				ans-=q.top();
				q.pop();
				q.push(c);
				ans+=c;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i < b; i++)
using ll = long long;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<ll> t(n);
    REP(i, 0, n) cin >> t[i];
    sort(t.begin(), t.end());
    ll ans = t[0];
    REP(i, 1, n) {
        ans = ans / __gcd(ans, t[i]) * t[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
		int ban;
		int su;
		int kin;
		int s=6000,a=4000,b=3000,c=2000;
		Scanner sc = new Scanner(System.in);
		
		for(int i=0;i<4;i++){
			ban = sc.nextInt();
		    su = sc.nextInt();
			switch(ban){
				case 1:
				kin = s*su;
				System.out.println(kin);
				break;
				case 2:
				kin = a*su;
				System.out.println(kin);
				break;
				case 3:
				kin = b*su;
				System.out.println(kin);
				break;
				case 4:
				kin = c*su;
				System.out.println(kin);
				break;
			}
		}
	}
}

Measured memory_bytes: 17316
def F(P):
	r=0
	for i in range(P):
		r+=26**i
	return r

def f(c):
	for p in range(15,-1,-1):
		for coef in range(26,0,-1):
			if c- coef*(26**p) >= F(p):
				return coef, p
		

n=int(input())

c=n
t=[]
while c:
	x,p =f(c)
	# ~ print((x,p))
	t+=[x]
	c-=(x*(26**p))
# ~ print(t)
a=""
for j in t:
	a+=chr(j+97-1)
print(a)


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

vector<int> c[110];
int sum[110];
int idx[110];

int main(){
    int n, d;
    while(cin >> n >> d, n){
        int MAX = 0, MIN = 1e9;
        rep(i, 0, n){
            c[i].clear();
            sum[i] = 0;
            idx[i] = 0;
        }
        rep(i, 0, n){
            int m;
            cin >> m;
            c[i].resize(m);
            rep(j, 0, m){
                cin >> c[i][j];
                sum[i] += c[i][j];
            }
            reverse(c[i].begin(), c[i].end());
            MAX = max(MAX, sum[i]);
            MIN = min(MIN, sum[i]);
        }
        bool ans = true;
        while(1){
            bool f = false;
            rep(i, 0, n){
                if(idx[i] == c[i].size()) continue;
                int tmp = sum[i] - c[i][idx[i]];
                sum[i] = tmp;
                MAX = 0, MIN = 1e9;
                rep(j, 0, n){
                    MAX = max(MAX, sum[j]);
                    MIN = min(MIN, sum[j]);
                }
                if(MAX - MIN > d){
                    sum[i] += c[i][idx[i]];
                    continue;
                }
                // cout << i << ' ' << sum[i] << ' ' << c[i][idx[i]] << endl;
                f = true;
                idx[i]++;
                sum[i] = tmp;
                break;
            }
            
            if(!f){
                rep(i, 0, n) if(sum[i] != 0) ans = false;
                break;
            }
        }
        if(ans) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 3192
use proconio::{fastout, input};
const MOD: u128 = 1_000_000_000 + 7;
#[allow(unused_mut)]
#[fastout]
fn main() {
    input! {
        n: u128,
        a: [u128; n]
    }
    let a: Vec<u128> = a;
    let mut sum: u128 = a.iter().sum();
    let mut res: u128 = a
        .iter()
        .map(|&i| {
            sum = sum - i;
            sum * i % MOD
        })
        .sum();
    res = res % MOD;
    println!("{}", res);
}


Measured memory_bytes: 7132
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;
const string TASK = "Factors of Factorial";

const int Mod = (int)1e9 + 7;
const int maxn = 1e6 + 1;
int n,cnt[maxn],res;
vector <int> f[maxn];

void Enter()
{
	cin >> n;
}

void Init()
{
	for (int i=2;i<=n;++i) {
		if (f[i].size() == 0)
			for (long long j=i;;) {
				for (long long k=1;k*j<=n;++k)
					f[j*k].push_back(i);
				if (j <= n / i)
					j *= i;
				else
					break;
			}
		for (int d : f[i])
			++cnt[d];
	}
}

void Solve()
{
	res = 1;
    for (int i=1;i<=n;++i)
		res = 1ll * res * (cnt[i] + 1) % Mod;
	cout << res;
}

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

	//freopen((TASK+".INP").c_str(),"r",stdin);
	//freopen((TASK+".OUT").c_str(),"w",stdout);

	Enter();
	Init();
	Solve();
}


Measured memory_bytes: 24832
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    ll N;
    cin >> N;
    ll A[N*3];
    for(int i=0;i<N*3;i++){
        cin >> A[i];
    }
    sort(A,A+N*3);
    reverse(A,A+N*3);
    ll ans=0,count=0;
    for(int i=0;i<N*3;i++){
        if(i%2==1){
            ans = ans + A[i];
            count++;
            if(count==N)break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
import bisect
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1,N):
    A[i]+=A[i-1]

index = bisect.bisect(A,K)
for i in range(M):
    K-=B[i]
    if K>=0:
        a=bisect.bisect(A,K)
        if a+i+1>=index:
            index=a+i+1
print(index)

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

int main() {
  int n;
  cin>>n;
  n=n%10;
  if (n==2||n==4||n==5||n==7||n==9) cout<<"hon"<<endl;
  else if(n==0||n==1||n==6||n==8) cout<<"pon"<<endl;
  else cout<<"bon"<<endl;
  return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, x;
vector <ll> a;
int main() {
	cin >> n >> x;
	a = vector<ll> (n);
	for(ll &i : a) cin >> i;
	ll res = 0;
	for(ll i = 0; i < n - 1; i++){
		if(a[i] + a[i + 1] > x){
			ll dif = (a[i] + a[i + 1]) - x;
			res += dif;
			a[i + 1] -= dif;
			if(a[i + 1] < 0){
				dif = abs(a[i + 1]);
				a[i + 1] = 0;
				a[i] -= dif;
			}
		}
	}
	cout << res << "\n";
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int x; cin >> x;
	vector<Int> p;
	for(Int i=2; i<=2*x; ++i){
		bool f = true;
		for(auto j:p){
			if(i % j == 0){
				f = false;
				break;
			}
			if(j*j > i){
				break;
			}
		}
		if(f) p.push_back(i);
	}
	for(auto i:p){
		if(i >= x){
			cout << i << "\n";
			return 0;
		}
	}
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef pair <double,double> dd;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define inf=1000000000
ll ipow(ll base, ll exp)
{
    ll result = 1;
    for (;;)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        if (!exp)
            break;
        base *= base;
    }

    return result;
}
ll p(ll d){
    ull s=1;
    ll cnt{0};
    while(d>s)s=ipow(2,cnt);
    return s-d;

}
vector<pair<ll,ll>> AJ;
vector<vector<ll>> knap;
ll W;
ll ma(ll a,ll b){
if(a>b)return a;
return b;
}
void nap(int in){
    if(knap[in][0]>=0)return ;
    nap(in-1);
    for(int i=0;i<=W;i++)
        if(AJ[in].first>i)
            knap[in][i]=knap[in-1][i];
        else
            knap[in][i]=ma(knap[in-1][i],(knap[in-1][i-AJ[in].first]+AJ[in].second));
}
int main(){
    ll n;
    cin>>n>>W;
    for(int i=0;i<n;i++){
        ll w,v;
        cin>>w>>v;
        AJ.push_back({w,v});
    }
    //for(int i=0;i<n;i++)cout<<AJ[i].first<<" "<<AJ[i].second<<endl;
    for(int i=0;i<n;i++)
        knap.push_back(vector<ll> (W+1,-1));

    for(int i=0;i<=W;i++)
        if(i>=AJ[0].first)
            knap[0][i]=AJ[0].second;
        else
            knap[0][i]=0;
    nap(n-1);
//    for(int i=0;i<n;i++){
//        for(int j=0;j<=W;j++)cout<<knap[i][j]<<" ";
//        cout<<endl;
//    }
    cout<<knap[n-1][W];

return 0;
}


Measured memory_bytes: 78592
//前置き
#pragma region

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

typedef  long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

#pragma endregion

//関数定義
#pragma region 
//偶数 ->　true :: 奇数　-> false
bool EVEN(ll a){
    return a%2-1;
}

//最大公約数
ll gcd(ll a, ll b) {  
    if (!b)  
        return a;  
    return gcd(b, a%b);  
}  

//最小公倍数
ll lcm(ll a, ll b) {  
    return a*b/gcd(a,b);  
} 

#pragma endregion

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(a*b, c) << endl;
}




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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
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;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t n;
  cin >> n;
  int64_t a[n] = {};
  int64_t value = 0;
  for(int64_t i=0;i<n;i++){
    cin >> a[i];
    value = value^a[i];
  }
  for(int64_t i=0;i<n;i++){
    cout << (value^a[i]);
    if(i==n-1) cout << endl;
    else cout << " ";
  }
  return 0;
}

Measured memory_bytes: 5120
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define arep(i, v) for (auto i : v)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
// #include <atcoder/all>
// using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline void dump(T& v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
template <class T, class U>
inline void dump(map<T, U>& v) {
    irep(i, v) { cout << i->first << " " << i->second << '\n'; }
}
inline string getline() {
    string s;
    getline(cin, s);
    return s;
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
struct io {
    io() {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;

/* --------------------   ここまでテンプレ   -------------------- */




int main() {
    
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=-LLINF;
    chmax(ans,b*d);
    chmax(ans,a*c);
    chmax(ans,b*c);
    chmax(ans,a*d);
    fin(ans);
}



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

int main()
{
  int nAnum, nBnum, nCnum;
  cin >> nAnum >> nBnum >> nCnum;

  bool nReslt = false;
  for (int n = 1; n <= nBnum; n++)
    if ((nAnum * n - nCnum) % nBnum == 0)
    {
      nReslt = true;
      break;
    }

  if (nReslt)  cout << "YES" << endl;
  else         cout << "NO"  << endl;

  return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    T, A = map(int, input().split())
    H = list(map(int, input().split()))

    nearest = float('inf')
    nearest_num = 0
    for i in range(N):
        temp = T - H[i] * 0.006
        diff = abs(A-temp)
        if nearest > diff:
            nearest = diff
            nearest_num = i + 1
    
    print(nearest_num)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#define ll long long

using namespace std;


int main(void){
   ll n, m;
   cin >> n >> m;
   vector<pair<ll, ll>> check;
   for(ll i = 0; i <= 1000; i++){
      check.emplace_back(i, 0);
      //cout << check[i].first << " " << check[i].second << endl;
   }
   if(m > 0){
      for(ll i = 0; i < m; i++){
         ll s, c;
         cin >> s >> c;
         for(ll i = 0; i < 1000; i++){
            string str = to_string(i);
            string cc = to_string(c);
            if(str[s-1] != cc[0] || str.length()!=n)
               check[i].second = 1;
         }
      }
      for(ll i = 0; i < 1000; i++){
         //cout << i << " " << check[i].second << endl;
         if(check[i].second==0){
            cout << i << endl;
            break;
         }
         if(i == 999)
            cout << -1 << endl;
      }
   }
   else if(m == 0){
      if(n==1)
         cout << 0 << endl;
      if(n==2)
         cout << 10 << endl;
      if(n==3)
         cout << 100 << endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int dir(char[], char[]);
int main(void){
    int n,a,t=0,h=0;
    char T[108],H[108];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s %s",T,H);
        a=dir(T,H);
        if(a==0){
            t+=3;
        }else if(a==1){
            h+=3;
        }else{
            t++;
            h++;
        }
    }
    printf("%d %d\n",t,h);
    return 0;
}
int dir(char x[],char y[]){
    int c=0;
    while(x[c]!='\0' || y[c]!='\0'){
        if(x[c]<y[c]){
            return 1;
        }else if(x[c]>y[c]){
            return 0;
        }else{
            c++;
            continue;
        }
        c++;
    }
    return 2;
}


Measured memory_bytes: 2148
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); ++i)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define INF ((1 << 30) - 1)
 
int main(){
    istream_iterator<int> itr(cin);
    int n = *itr, m = *(++itr);
    vector<int> a(m), b(m), c(m);
    rep(i, m){
        a[i] = *(++itr) - 1;
        b[i] = *(++itr) - 1;
        c[i] = *(++itr);
    }
 
    vector< vector<int> > p(n);
    rep(i, n){
        p[i] = vector<int>(n, INF);
    }
    rep(i, n){
        p[i][i] = 0;
    }
    rep(i, m){
        p[a[i]][b[i]] = c[i];
        p[b[i]][a[i]] = c[i];
    }
    rep(i, n)
        rep(j, n)
            rep(k, n)
                p[j][k] = min(p[j][k], p[j][i] + p[i][k]);
 
    int sum = 0;
    rep(i, m){
        bool used = false;
        rep(j, n){
            if(p[j][a[i]] + c[i] == p[j][b[i]] || p[j][b[i]] + c[i] == p[j][a[i]]){
                used = true;
                break;
            }
        }
        if(!used){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var N int
  fmt.Scan(&N)
  
  val := false
  for i := 1; i < 10; i++ {
    if N % i == 0 && N / i < 10 {
      val = true
    }
  }
  if val {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e+9+7;
//Digts Parade
int main(){
    string s;cin>>s;
    long long dp[s.size()+2][13];
    for(int i=0;i<=s.size();i++){
        for(int j=0;j<13;j++){
            dp[i][j]=0;
        }
    }
    
    for(int i=0;i<s.size();i++){
        char r=s[i];
        //dp[i][j]=k <=> i文字目までの数値を割ったときの余りがjである個数
        if(r=='?'){//?には0~9の数字を入れることができる
            if(i==0){
                for(int j=0;j<=9;j++){
                    dp[i+1][j]=1;
                }
                continue;
            }
            
            for(int k=0;k<=9;k++){
                for(int j=0;j<13;j++){
                    int ren=j*10+k;
                    ren%=13;
                    dp[i+1][ren]+=dp[i][j];
                    dp[i+1][ren]%=mod;
                }
            }
            continue;
        }
        
        int now=(int)(r-'0');
        if(i==0){
            dp[i+1][now]=1;
            continue;
        }
        for(int j=0;j<13;j++){
            int ren=j*10+now;
            ren%=13;
            dp[i+1][ren]=dp[i][j];
            dp[i+1][ren]%=mod;
        }
        
    }
    cout<<dp[s.size()][5]<<endl;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n;
	cin >> n;
	vi a(n);
	REP(i, n) cin >> a[i];
	int ans = INF;
	for (int i = -100; i <= 100; i++)
	{
		int sum = 0;
		for (auto j : a) sum += (j - i) * (j - i);
		chmin(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    from operator import itemgetter
    from bisect import bisect_right
    input = sys.stdin.readline

    N, D, A = map(int, input().split())
    info = []
    for _ in range(N):
        x, h = map(int, input().split())
        info.append((x, h))
    info.sort(key=itemgetter(0))

    imos = [0] * N
    X = [info[i][0] for i in range(N)]
    H = [info[i][1] for i in range(N)]
    ans = 0
    i = 0
    dam = 0
    while True:
        dam += imos[i] * A
        assert dam >= 0
        bomb = (max(H[i] - dam, 0) - 1) // A + 1
        ans += bomb
        #print(i, ans, imos)
        if H[i] > dam:
            j = bisect_right(X, X[i] + 2*D)
        else:
            j = 0
        if j == i:
            i += 1
        else:
            if i == N-1:
                break
            imos[i+1] += bomb
            if j != N:
                imos[j] -= bomb
            i += 1
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
    int64_t n, w;
    cin>>n>>w;
    int64_t weight[n+1], values[n+1];
    for(int64_t i=1;i<n+1;i++){
        cin>>weight[i]>>values[i];
    }
    weight[0] = 0;
    values[0] = 0;
    int64_t dp[n+1][w+1];
    for(int64_t i=0;i<n+1;i++){
        for(int64_t j=0;j<w+1;j++){
            dp[i][j] = 0;
        }
    }
    for(int64_t i = 1;i<n+1;i++){
        for(int64_t j = 1;j<w+1;j++){
            int64_t a = 0;
            int64_t b = 0;
            if(j-weight[i]>=0){
                a = dp[i-1][j-weight[i]] + values[i];
                b = dp[i-1][j];
                dp[i][j] = max(a, b);
            }
            else{
                int64_t temp = 0;
                dp[i][j] = max(temp, dp[i-1][j]);
            }
        }
    }
    
    // for(int64_t i=0;i<n+1;i++){
    //     for(int64_t j=0;j<w+1;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    cout<<dp[n][w];
    // your code goes here
	return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
#define input(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,h,w,t,p,q,ans=0;
vl v;
 
ll solve(){
    a=0;
    rep(i,n){
        if(v[i]==i+1)a++;
    }
    if(a==n-2||a==n){
        cout<<"YES"<<endl;
        return 0;
    }
    cout<<"NO"<<endl;
    return 0;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    input(v,n);
    
    solve();
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i){
    int h, w;
    cin >> h >> w;
    vector<string> V(h);
    for(int i = 0; i < h; ++i){
      cin >> V[i];
    }
    vector<int> T(26,h), L(26,w), R(26,-1), B(26,-1);
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
        char c = V[i][j];
        if(c != '.'){
          T[c-'A'] = min(i,T[c-'A']);
          L[c-'A'] = min(j,L[c-'A']);
          B[c-'A'] = max(i,B[c-'A']);
          R[c-'A'] = max(j,R[c-'A']);
        }
      }
    }
    vector<int> C;
    for(int i = 0; i < 26; ++i){
      if(B[i] >= 0) C.push_back(i);
    }
    string ans = "SAFE";
    vector< vector<bool> > G(26,vector<bool>(26,false));
    for(int i = 0; i < C.size(); ++i){
      for(int j = T[C[i]]; j <= B[C[i]]; ++j){
        for(int k = L[C[i]]; k <= R[C[i]]; ++k){
          if(V[j][k] == '.'){
            ans = "SUSPICIOUS";
          }else if(V[j][k] != 'A'+C[i]){
            G[C[i]][V[j][k]-'A'] = true;
          }
        }
      }
    }
    if(ans == "SUSPICIOUS"){
      cout << ans << endl;
      continue;
    }
    ans = "SUSPICIOUS";
    do{
      map<int,int> M;
      for(int i = 0; i < C.size(); ++i) M[C[i]] = i;
      bool f = true;
      for(int i = 0; i < 26; ++i){
        if(!f) break;
        for(int j = 0; j < 26; ++j){
          if(G[i][j] && M[i] > M[j]){
            f = false;
            break;
          }
        }
      }
      if(f){
        ans = "SAFE";
      }
    }while(next_permutation(C.begin(),C.end()));
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {

    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    string s;
    cin>>s;
    
  

    bool cc = true;
    for(ll i=a;i<c;i++){
        if(s[i]=='#'&&s[i+1]=='#'){
            cc=false;
            break;
        }
    }

    for(ll i=b;i<d;i++){
        if(s[i]=='#'&&s[i+1]=='#'){
            cc=false;
            break;
        }
    }

    if(!cc){
        cout<<"No"<<endl;
        return 0;
    }

    if(c<d){
        cout<<"Yes"<<endl;
        return 0;
    }else{
        s = '#'+ s + '#';
//        bool f = false;
//            for (ll i = b; i < d; i++) {
//                if(i+1<n&&s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
//                   cout<<"Yes"<<endl;
//                   return 0;
//                }
//            }
//
//
//            cout<<"No"<<endl;
        for(int i=b;i<=d;i++) if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.'){
                puts("Yes");
                return 0;
            }
        puts("No");
        return 0;


    }

    return 0;
}


Measured memory_bytes: 772
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N; cin >> N;
	int M = -INF;
	int m = INF;
	rep(i, N) {
		int A; cin >> A;
		M = max(M, A);
		m = min(m, A);
	}
	cout << M - m << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;

int main(){
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  string s[N];
  for(int i = 0; i < N; i++){
    s[i] = S.substr(i, 1);
  }
  bool flag = false;
  int rui[N];
  int cnt = 0;
  F(i, N){
    string tmp = s[i];
    if(tmp == "A"){
      flag = true;
    }
    else if(tmp == "C" && flag){
      flag = false;
      cnt++;
    }
    else{
      flag = false;
    }
    rui[i] = cnt;
  }
  F(i, Q){
    int s1 = 0;
    int s2 = 0;
    cin >> s1 >> s2;
    int rcnt = rui[s2-1] - rui[s1-1];
    cout << rcnt << endl;
  }
  return 0;
}


Measured memory_bytes: 6784
N= int(input())
W= list(map(int,input().split()))
X=0

i=1
for i in range (N-1):
    A=sum(W[0:i+1])-sum(W[i+1:N])
    if A>=0:
        B=sum(W[i:N])-sum(W[0:i])
        if A<B:
            X=A
        else:
            X=B
        break
    else:

        i=i+1

print(X)


Measured memory_bytes: 3060
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        if(a >= k){
          System.out.println(k);
        }else if(k-a-b < 0){
          System.out.println(a);
        }else{
          System.out.println(a-(k-a-b));
        }
    }
}


Measured memory_bytes: 35888
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a;
  getline(std::cin,a);
  bool f1=a.size()%2==1;
  bool f2=a[0]==a[a.size()-1];
  if(f1^f2)cout<<"First";
  else cout<<"Second";
  return 0;
}

Measured memory_bytes: 3768
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int d;
    cin >> d;
    vector<int> c(26);
    for(int i=0; i<26; i++) cin >> c[i];
    vector<vector<int>> G(d,vector<int> (26));
    for(int i=0; i<d; i++){
        for(int j=0; j<26; j++){
            cin >> G[i][j];
        }
    }
    vector<int> t(d);
    int sum = 0;
    vector<int> l(26,0);
    vector<int> n(26,0);
    for(int i=0; i<d; i++){
        int mx = -inf;
        int id = -1;
        for(int j=0; j<26; j++){
            if(chmax(mx,G[i][j]-(c[j]*l[j]))){
                id = j;
            }
        }        
        l[id] = i+1;
        n[id] += G[i][id];
    }
    for(int i=0; i<26; i++) sum += n[i];
    for(int k=0; k<100000; k++){
        vector<P> pre(100);
        for(int i=0; i<100; i++){
            int a = rand() % d;
            int b = rand() % 26;
            pre[i].first = a;
            pre[i].second = t[a];
            t[a] = b;
        }
        vector<ll> now(26,0);
        vector<int> last(26,0);
        for(int i=0; i<d; i++){
            last[t[i]] = i+1;
            now[t[i]] += G[i][t[i]];
            for(int j=0; j<26; j++){
                now[t[i]] -= c[j] * (i+1 - last[j]);
            }
        }
        int s = 0;
        for(int j=0; j<26; j++){
            s += now[j];
        }
        if(s > sum){
            sum = s;
        }else{
            for(int i=0; i<100; i++){
                t[pre[i].first] = pre[i].second;
            }
        }
    }
    for(int i=0; i<d; i++){
        cout << t[i]+1 << "\n";
    }
    return 0;
}


Measured memory_bytes: 3712
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


class Node:
    def __init__(self,value,index):
        self.value = value
        self.index = index

    def items(self):
        return [self.value,self.index]

# 0-indexed SegmentTree
class SegmentTree:
    def __init__(self,N,aa):
        self.N0 = 2**(N-1).bit_length()
        self.nodes = [Node(-1,i+1-self.N0) for i in range(2*self.N0-1)]
        for i in reversed(range(2*self.N0-1)):
            ind = i+1-self.N0
            if ind >= N:
                self.nodes[i].value = -1
            elif N > ind >= 0:
                self.nodes[i].value = aa[ind]
            else:
                self.nodes[i] = self.process(self.nodes[i*2+1],self.nodes[i*2+2])

    def update(self,i,x): #iの値をxに更新
        i += self.N0 - 1
        self.nodes[i].value = x
        while i > 0:
            i = (i-1)//2
            self.nodes[i] = self.process(self.nodes[i*2+1],self.nodes[i*2+2])

    def query(self,L,R): #[L,R)の値
        retnode = Node(-1,-1)
        L += self.N0
        R += self.N0
        while L < R:
            if R&1 :
                R -= 1
                retnode = self.process(retnode,self.nodes[R-1])
            if L&1 :
                retnode = self.process(retnode,self.nodes[L-1])
                L += 1
            L >>= 1; R >>= 1
        return retnode

    def process(self,node_x,node_y): #x,yが子の時，親に返る値
        if node_x.value > node_y.value:
            return node_x
        else:
            return node_y


N = inp()
SS = inpl()
SS.sort()

ST = SegmentTree(2**N,SS)

now = [SS[-1]]

Rinds = [0]*(2**N)
itr = 0
for i,S in enumerate(SS):
    while True:
        if S <= SS[itr]:
            Rinds[i] = itr
            break
        else:
            itr += 1


now = [Node(SS[2**N-1],2**N-1)]

for t in range(1,N+1):
    next = []
    for n in now:
        R = Rinds[n.index]
        tmpnode = ST.query(0,R)
        if tmpnode.value < 0:
            print('No')
            exit()
        next.append(tmpnode)
        ST.update(tmpnode.index,-1)

    now = now + next


print('Yes')


Measured memory_bytes: 133052
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
L = 0
for i, a in enumerate(A):
  if L + a <= S/2:
    L += a
  else:
    R = S - L
    diff = R - L
    if 2*a - diff < diff:
      L += a
      R -= a
    break
    
R = S - L
print(abs(R - L))

Measured memory_bytes: 26220