akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
#define debug(x) cout << #x << " = " << (x) << endl;
const ll MOD = 1000000007;

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
    cout << "[";
    for(auto &i: v) cout << i << ", ";
    cout << "]" << endl;
    return os;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, pair<K, V> p) {
    os << "{" << p.first << ", " << p.second << "} ";
    return os;
}

int main() {
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0); 
    
    int k; cin >> k;
    int gcd = 0;
    for(int i = 1; i <= k; ++i) {
        for(int j = 1; j <= k; ++j) for(int l = 1; l <= k; ++l)
            gcd += __gcd(i, __gcd(j, l));
    }
    cout << gcd << endl;
}

Measured memory_bytes: 3648
try:
    num = []
    while True:
        #標準入力
        i = int(input())
        #0だった場合１番後ろを出力し削除、それ以外はリストに追加
        if i == 0:
            print(num[-1])
            num.pop(-1)
        else:num.append(i)
#EOFErrorをひろい、ループを抜ける
except EOFError:
    pass


Measured memory_bytes: 5592
n = int(raw_input())
for loop in xrange(n):
    a = []
    while len(a) < 9:
        a += map(lambda i:int(i,16),raw_input().split())
    key = 0
    for i in xrange(32):
        s = sum(a[j]^key for j in xrange(8))
        if s&(1 << (i+1)-1) != (a[-1]^key)&(1 << (i+1)-1): key |= (1 << i)
    print "%x"%key

Measured memory_bytes: 4224
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
int p[3100];
int ans[3100];
int cur[3100];
int main(){
	init_C(3100);
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
	}
	for(int i=0;i<a;i++){
		if(!p[i])continue;
		for(int j=0;j<=a;j++)cur[j]=0;
		cur[a]=1;
		cur[1]=a-1;
		for(int j=a;j>0;j--){
			int ks=cur[j];
			ans[j-1]=(ans[j-1]+ks)%a;
			cur[j]-=ks;
			cur[j-1]=(cur[j-1]+i*ks)%a;
		}
	}
	for(int i=0;i<a;i++){
		if(i)printf(" ");
		printf("%d",(a-ans[i])%a);
	}printf("\n");
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m;
    cin >> n >> m;
    cout << (m+n-3)/(n-1) << endl;
}

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

int main() {
    int A = 0, B = 0;
    int N;
    cin >> N ;
    int a[N];
    for(int i = 0; i < N ; i++) {
        cin >> a[i];
    }
    
    // insertion sort
    for(int i = 0; i < N -1 ; i++) {
        int tmp_max = a[i];
        int tmp_idx = i;

        for(int j = i+1; j < N ; j++) {
            if(tmp_max < a[j]) {
                tmp_max = a[j];
                tmp_idx = j;    
            }
        }
        // a[i] と a[tmp_idx]の入れ替え
        int work = a[i]; a[i] = tmp_max; a[tmp_idx] = work;
    }
    /*
    for(int i = 0; i < N ; i++) {
        cout << a[i] << ", ";
    }
    cout << "\n";
    */
    for(int i = 0; i < N ; i++) {
        if(i % 2 == 0) {
            A += a[i];
        }
        else {
            B += a[i];
        }
    }
    cout << A - B << endl;

    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

	ll a,b;
	cin>>a>>b;

	if(a==b)
	{
		for(int i=0;i<b;i++)
			cout<<a;
		cout<<endl;
	}
	else{
		if(a>b) swap(a,b);
		for(int i=0;i<b;i++)
			cout<<a;
		cout<<endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n+1);
    rep1(i,n) cin >> a[i];
    ll mx = min(k,(ll)log(n)+1);
    rep1(ki,k){
        vector<ll> b(n+2);
        rep1(i,n){
            ll l = max(i-a[i], (ll)1);
            ll r = min(i+a[i]+1,n+1);
            b[l]++;
            b[r]--;
        }
        rep0(i,n-1) b[i+1] += b[i];
        b.pop_back();
        if(a == b)break;
        a = b;
    }
    rep1(i,n) cout << a[i] << endl;

}
/*
5 1
1 0 0 1 0

5 2
1 0 0 1 0
*/

Measured memory_bytes: 5940
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int n,a[100001];
ll m,tot,all,sum[100001];
inline bool check(int x) {
	ll sum=0;
	for(res i=1;i<=n;++i) sum+=n-(lower_bound(a+1,a+1+n,x-a[i])-a)+1;
	return sum>m;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(res i=1;i<=n;++i) cin>>a[i];
	sort(a+1,a+1+n);
	for(res i=1;i<=n;++i) sum[i]=sum[i-1]+a[i];
	int l=0,r=2*a[n],ans=0;
	while(l<=r) {
		int mid=l+r>>1;
		if(check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	for(res i=1;i<=n;++i) {
		int now;
		all+=n-(now=lower_bound(a+1,a+1+n,ans-a[i])-a)+1;
		tot+=sum[n]-sum[now-1]+(ll)a[i]*(n-now+1);
	}
	print(tot-(ll)ans*(all-m),'\n');
	cout<<flush;	
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 1536
/**
 * Created by hiramekun at 18:48 on 2020-04-04.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vl p(a), q(b), r(c);
    cin >> p >> q >> r;
    sort(all(p)), reverse(all(p));
    sort(all(q)), reverse(all(q));
    sort(all(r)), reverse(all(r));
    vl px, qy;
    rep(i, x) px.eb(p[i]);
    rep(i, y) qy.eb(q[i]);

    vl pqr = px;
    rep(i, y) pqr.eb(qy[i]);
    rep(i, c) pqr.eb(r[i]);
    sort(all(pqr)), reverse(all(pqr));
    ll ans = 0;
    rep(i, x + y) ans += pqr[i];
    
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 6964
import Data.Char
import Control.Monad
import Control.Monad.ST
import Data.Array.ST

modifyArray :: (Ix i) => STUArray s i Int -> i -> (Int->Int) -> ST s ()
modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = readLn >>= print.f

f::Int->Int
f n = runST $ do
    dp <- newArray ( ((0,False),(False,False,False)), ((k,True),(True,True,True)) ) 0
        :: ST s (STUArray s ((Int,Bool),(Bool,Bool,Bool)) Int)
    writeArray dp ((0,False),(False,False,False)) 1
    forM_ [(i,f,d, x,s3,s5,s7) | (i,d)<-zip [0..] s, [f,s3,s5,s7]<-replicateM 4 [False,True]
        , x <- dropWhile ((&& (s3||s5||s7)).(==0)) $ takeWhile ((||f).(<=d)) [0,3,5,7]] $
        \(i,f,d,x,s3,s5,s7) -> do
            let nf = f || x<d
            let n3 = s3 || x==3
            let n5 = s5 || x==5
            let n7 = s7 || x==7
            modifyArray dp ((i+1,nf),(n3,n5,n7)) =<< (+) <$> readArray dp ((i,f),(s3,s5,s7))
    (+) <$> readArray dp ((k,False),(True,True,True)) <*> readArray dp ((k,True),(True,True,True))
    where
        s = map digitToInt $ show n
        k = length s

Measured memory_bytes: 508
/* ********************************
Author        :caoyu01
Created Time  :2016/9/5 14:17:33
File Name     :c.cpp
***********************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define cle(x) memset(x,0,sizeof(x))
#define rep(i,x) for(int i=0;i<x;i++)
const int N=1000+10;
const double eps=1e-10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
char a[N][N];
int h,w;
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	while(cin>>h>>w){
		rep(i,h)cin>>a[i];
		rep(i,h){
			rep(j,w){
				if(i==0||(i!=h-1&&(j%2==0||(j%2==1&&a[i][j]=='#'))))cout<<'#';
				else cout<<".";
			}
			cout<<endl;
		}
		cout<<endl;
		rep(i,h){rep(j,w){
			if(i==h-1||(i!=0&&(j%2==1||(j%2==0&&a[i][j]=='#'))))cout<<'#';
			else cout<<".";
		}
		cout<<endl;
		}
	}
    return 0;
}


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

int main() {
  int n; cin >> n;
  int d1, d2, d3, d4;
  d1 = n / 1000;
  d2 = (n % 1000) / 100;
  d3 = (n % 100) / 10;
  d4 = n % 10;
  
  char op1, op2, op3;
  if (d1 + d2 + d3 + d4 == 7) {
    op1 = '+';
    op2 = '+';
    op3 = '+';
  }
  else if (d1 + d2 + d3 - d4 == 7) {
    op1 = '+';
    op2 = '+';
    op3 = '-';
  }
  else if (d1 + d2 - d3 + d4 == 7) {
    op1 = '+';
    op2 = '-';
    op3 = '+';
  }
  else if (d1 + d2 - d3 - d4 == 7) {
    op1 = '+';
    op2 = '-';
    op3 = '-';
  }
  else if (d1 - d2 + d3 + d4 == 7) {
    op1 = '-';
    op2 = '+';
    op3 = '+';
  }
  else if (d1 - d2 - d3 + d4 == 7) {
    op1 = '-';
    op2 = '-';
    op3 = '+';
  }
  else if (d1 - d2 + d3 - d4 == 7) {
    op1 = '-';
    op2 = '+';
    op3 = '-';
  }
  else if (d1 - d2 - d3 - d4 == 7) {
    op1 = '-';
    op2 = '-';
    op3 = '-';
  }
  
  cout << d1 << op1 << d2 << op2 << d3 << op3 << d4 << "=7" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int extgcd(int a, int b, int& x, int& y);

int main(void){
    int a, b; cin >> a >> b;
    
    int x, y;
    extgcd(a, b, x, y);

    cout << x << " " << y << endl;

	return 0;
}

int extgcd(int a, int b, int& x, int& y){
    int d = a;

    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    else{
        x = 1; y = 0;
    }

    return d;
}

Measured memory_bytes: 1164
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i = 1, x;
        while (true) {
            x = scanner.nextInt();
            if (x == 0)
                break;
            System.out.println("Case "+ i++ +": " + x);
        }
        scanner.close();
    }
}


Measured memory_bytes: 41420
/*
* @author:  codancer
* @createTime:  time
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
ll a[200004];
int main(){
	ll k,n;
	cin>>k>>n;
	rep(i,1,n) cin>>a[i];
	sort(a+1,a+n+1);
	vector<ll> dis;
	ll minn=k-(a[n]-a[1]);
	rep(i,2,n){
		minn=max(minn,a[i]-a[i-1]);
	}
	cout<<k-minn<<endl;
	return 0;
}

Measured memory_bytes: 1792
<?php
fscanf(STDIN, "%d %d", $n, $m);
$array = explode(' ',trim(fgets(STDIN)));
rsort($array);

$sum = array_sum($array);
$kizyun = $sum /4 /$m;
$can_flg = true;
for($i=0;$i<$m;$i++) {
  if($kizyun > $array[$i]) {
    $can_flg = false;
    break;
  }
}

echo ($can_flg) ? 'Yes': 'No';

Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007

int main(){
  int N;
  cin >> N;
  vector<int> x(N);
  rep(i,N){
    cin >> x[i];
  }

  vector<int> v;
  ll mn = 1;
  ll ret = 1;
  rep(i,x.size()){
    if(mn <= x[i]){
      v.push_back(mn);
      mn += 2;
    }else{
      ret *= (v.size()+1LL);
      ret %= MOD;
    }
  }

  for(ll i=1; i<=v.size(); i++){
    ret *= i;
    ret %= MOD;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 1276
import math

def nth_prime(N):
    primes = [2]
    n = 1
    while(len(primes) < N):
        n += 2
        m = int(math.sqrt(n))
        for p in primes:
            if p > m:
                primes.append(n)
                break
            if n % p == 0:
                break
    return primes[-1]

def main():
    N = int(input())
    i = 1
    a = []
    while len(a) < N:
        p = nth_prime(i)
        if p % 5 == 1:
            a.append(nth_prime(i))
        i += 1
    s = ' '.join(str(i) for i in a)
    print(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long int
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
#define output(x) for (auto a:x) cout<<a<<" ";cout<<endl;
#define output2(x) for (auto a:x) cout<<a.fi<<" "<<a.se<<endl;
#define PI 3.14159265
#define rall(x) x.rbegin(),x.rend()
#define all(x) x.begin(),x.end()
#define sz(x) (int) x.size()
// DEBUG TEMPLATE
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
  *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  
// DEBUG TEMPLATE ENDS

#define MOD 1000000007
int power(int x,int y,int mod = MOD) 
{ 
  int ret = 1;
  x = x % mod;
  while (y){
    if(y&1) ret = (ret*x)%mod;
    y = y>>1;
    x = (x*x)%mod;
    } 
    return ret%mod; 
}

void solve()
{ 
  int x,k,d;
  cin>>x>>k>>d;
  x = abs(x);
  int req = x/d;
  if (req >= k){
    debug() << imie("this");
    cout<<x-k*d<<endl;
    return;
  }
  int x1 = x-req*d , x2 = x - (req+1)*d;
  if ( (k-req)%2 == 0){
    cout<<abs(x1)<<endl;
  } else cout<<abs(x2)<<endl;
}


/*
  
*/
signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--)
  solve();
}
// Check MOD values plox :(


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 998244353
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
struct SEG{
	ll seg[1<<18];
	SEG(void){
		for(int i=0;i<1<<18;i++)seg[i]=INF;
	}
	void up(int a,ll x){
		a+=(1<<17)-1;
		seg[a]=min(seg[a],x);
		while(a>0){
			a=(a-1)/2;
			seg[a]=min(seg[a*2+1],seg[a*2+2]);	
		}
	}
	ll que(int a,int b,int l,int r,int k){
		if(b<l||r<a)return INF;
		if(a<=l&&r<=b)return seg[k];
		return min(que(a,b,l,(l+r-1)/2,k*2+1),que(a,b,(l+r+1)/2,r,k*2+2));
	}
};
ll n,dp[100005],m;
vector<P>r[100005];
SEG seg;
int main(void){
	cin>>n>>m;
	for(int i=0;i<n;i++)dp[i]=INF;
	for(int i=0;i<m;i++){
		ll l,y,c;
		cin>>l>>y>>c;
		r[--y].PB(P(--l,c));
	}
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<r[i].size();j++){
			ll l=r[i][j].F,c=r[i][j].S;
			dp[i]=min(dp[i],seg.que(l,i-1,0,(1<<17)-1,0)+c);
		}
		seg.up(i,dp[i]);
	}
	if(dp[n-1]==INF)dp[n-1]=-1;
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> A(N);
	ll ans = pow(3, N);
	ll odd = 1;
	rep(i,N){
		cin>>A[i];
		if(A[i]&1)continue;
		odd *= 2;
	}
	cout << ans - odd << endl;
}

Measured memory_bytes: 256
def my_input():
    inp = int(raw_input())
    result = []
    while inp != 0:
        result.append(inp)
        inp = int(raw_input())
    return result

def calc1(v):
    return min([calc2(v ** 3 - x ** 3) for x in range(1,v)])

def calc2(v):
    return v - int(v ** (1.0/3)) ** 3

def main():
    for x in [calc1(i) for i in my_input()]:
        print x

main()

Measured memory_bytes: 4372
#include <iostream>
using namespace std;
int main(void){
    int W,H,N;
    cin>>W>>H>>N;
    int x[N],y[N],a[N];
    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i]>>a[i];
    }

    int xmax=0,xmin=W,ymax=0,ymin=H;
    for(int i=0;i<N;i++){
        if(a[i]==1&&xmax<=x[i]) xmax=x[i];
        if(a[i]==2&&xmin>=x[i]) xmin=x[i];
        if(a[i]==3&&ymax<=y[i]) ymax=y[i];
        if(a[i]==4&&ymin>=y[i]) ymin=y[i];
    }
    if(xmax<=xmin&&ymax<=ymin) cout<<(xmin-xmax)*(ymin-ymax);
    else cout<<0;
    return 0;
    
}

Measured memory_bytes: 256
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
#define clr0(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,-1,sizeof(a))
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
main()
{
    timesave;
    int n,m,tot,flag=0;
    cin>>n>>m;
    for(int i=0;i<=n;i++)
    {
        tot=(i*2)+(n-i)*4;
        if(tot==m)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}




Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
//#define s second
#define MOD 1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
#define INF (long long)102000000000000
#define NAX (int)1e2+2
typedef long long ll;
typedef unsigned long long ull;
class solution{
public:
	void solve(){
		int n,mo;
		cin>>n>>mo;
		//vector<pair<int,string>> v(n);
		int temp;
		string s;
		unordered_map<int,bool> m;
		for(int i=1;i<=n;i++){
			m.insert({i,false});
		}
		int ans=0,r=0;
		map<int,int> wa;
		for(int i =0;i<mo;i++){
			cin>>temp;
			if(m[temp] == false){
				cin>>s;
				if(s == "AC"){
					ans++;
					m[temp] = true;
					r += wa[temp];
					//ans++;
				}
					else{
						wa[temp]++;
					}
				}
				else{
					cin>>s;
				}
			}
		cout<<ans<<" "<<r;
	}
};
	  
int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();

 return 0;
}


Measured memory_bytes: 8996
#include<bits/stdc++.h>
using namespace std;int main(){int n,a[100002];long t=0;scanf("%d",&n);for(int i=1;i<= n;i++)scanf("%d",&a[i]),t+=abs(a[i]-a[i-1]);t+=abs(a[n]);for(int i=1;i<=n;i++)printf("%ld\n",t-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]));}

Measured memory_bytes: 1664
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

s = gc
list = []
ans = true
s.each do |ss|
if list.include? ss
  ans = false
  break
end
list << ss
end

puts ans ? "yes" : "no"

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

constexpr int mod = 998244353;
class mint {
 public:
  long long x;
  constexpr mint(long long x = 0) : x((x % mod + mod) % mod) {}
  constexpr mint operator-() const { return mint(-x); }
  constexpr mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr mint& operator-=(const mint& a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr mint& operator*=(const mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint operator+(const mint& a) const {
    mint res(*this);
    return res += a;
  }
  constexpr mint operator-(const mint& a) const {
    mint res(*this);
    return res -= a;
  }
  constexpr mint operator*(const mint& a) const {
    mint res(*this);
    return res *= a;
  }
  constexpr mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  constexpr mint inv() const { return pow(mod - 2); }
  constexpr mint& operator/=(const mint& a) { return (*this) *= a.inv(); }
  constexpr mint operator/(const mint& a) const {
    mint res(*this);
    return res /= a;
  }
};

istream& operator>>(istream& is, const mint& m) {
  is >> m.x;
  return is;
}

ostream& operator<<(ostream& os, const mint& m) {
  os << m.x;
  return os;
}

mint choose(long long n, long long a) {
  mint x, y;
  x.x = 1;
  y.x = 1;
  for (long long i = (0); i < (a); ++i) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

int main() {
  int n;
  cin >> n;
  map<int, ll> data;
  int head_value;
  int max_value = 0;
  REP(i, n) {
    int x;
    cin >> x;
    if (i == 0) {
      head_value = x;
    }
    max_value = max(max_value, x);
    data[x] += 1;
  }

  if (head_value != 0 || data[0] != 1) {
    cout << 0 << endl;
  } else {
    mint ans;
    ans.x = 1;
    FOR(i, 2, max_value + 1) {
      mint tmp;
      tmp.x = data[i - 1];
      tmp = tmp.pow(data[i]);
      ans = ans * tmp;
    }
    cout << ans << endl;
    return 0;
  }
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

vector<vector<ll>> V;

void topo(ll x,vector<bool>& vis,stack<ll>& S){
    vis[x] = true;
    for(ll k=0;k<V[x].size();k++){
        if(vis[V[x][k]] == false){
            topo(V[x][k],vis,S);
        }
    }
    S.push(x);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin>>n>>m;
    V.resize(n+1);
    while(m--){
        ll x,y;
        cin>>x>>y;
        V[x].push_back(y);
    }
    vector<bool> vis(n+1,false);
    stack<ll> S;
    for(ll i=1;i<=n;i++){
        if(vis[i] == false){
            topo(i,vis,S);
        }
    }
    vector<ll> dp(n+1,0);
    while(!S.empty()){
        ll x = S.top();
        S.pop();
        for(ll k=0;k<V[x].size();k++){
            dp[V[x][k]] = max(dp[V[x][k]],dp[x] + 1);
        }
    }
    ll max1 = 0;
    for(ll i=1;i<=n;i++){
        max1 = max(max1,dp[i]);
    }
    cout<<max1<<endl;
}

Measured memory_bytes: 10112
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288

int main(){
    int n,k;
    cin>>n>>k;
    vector<int>p(n);
    rep(i,n)cin>>p[i];
    vector<int>a(n-k+1);
    rep(i,k)a[0]+=p[i];
    for(int i=1;i<n-k+1;i++){
        a[i]=a[i-1]-p[i-1]+p[i+k-1];
    }
    double max=0;
    rep(i,a.size()){
        
        if(a[i]>max)max=a[i];
    }
    
    max=(max+k)/2;
    printf("%.10f\n",max);
    return 0;
}

Measured memory_bytes: 1792
if __name__ == '__main__':
    N, M = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*M]
    ab = sorted(ab, key=lambda x: x[1])
    cnt = 0
    ans = 0
    for a, b in ab:
        if ans < a:
            ans = b - 1
            cnt += 1
    print(cnt)


Measured memory_bytes: 29716
#include<bits/stdc++.h>
using namespace std;
vector<int> l[200005];
int visited[200005];
map<int,int> mp;
int main()
{
   int n;
   cin>>n;
   int a[n][3];

   for(int i=0;i<n;i++)
   {
      cin>>a[i][0]>>a[i][1]>>a[i][2];
   }
   int dp[n][3];
   memset(dp,0,sizeof(dp));
   // dp[0][0]=max(a[0][1],a[0][2]);
   // dp[0][1]=max(a[0][0],a[0][2]);
   // dp[0][2]=max(a[0][1],a[0][0]);

   dp[0][0]=a[0][0];
   dp[0][1]=a[0][1];
   dp[0][2]=a[0][2];

   for(int i=1;i<n;i++)
   {
      // dp[i][0]=dp[i-1][0]+max(a[i][1],a[i][2]);
      // dp[i][1]=dp[i-1][1]+max(a[i][0],a[i][2]);
      // dp[i][2]=dp[i-1][2]+max(a[i][1],a[i][0]);
      dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
      dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
      dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
   }
//    cout<<"\n";

//   for(int i=0;i<n;i++)
//   {
//      cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<"\n";
//   }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

}


Measured memory_bytes: 7296
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
 
#ifdef LOCAL
#define show(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif
 
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}
 
template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}
 
struct P {
    ll x, y;
    char ty;
};
ostream& operator<<(ostream& os, const P& p) {
    return os << p.ty << "(" << p.x << ", " << p.y << ")";
}
 
V<ll> v;
ll dfs(int l, int r, ll a, ll b) {
    if (l > r) return 0;
    ll ans = (ll) 1e18;
    for (int k = l; k <= r; k++) {
        ans = min(ans, (a + b) * v[k] + dfs(l, k - 1, a, a + b) + dfs(k + 1, r, a + b, b));
    }
    return ans;
}
 
 
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
 
    int n;
    cin >> n;
    v = V<ll>(n);
    for (int i = 0; i < n; i++) cin >> v[i];
 
    cout << v[0] + v[n - 1] + dfs(1, n - 2, 1, 1) << endl;
    // set<V<int>> st;
    // st.insert({1, 1});
 
    // for (int ph = 3; ph <= 18; ph++) {
    //     set<V<int>> nst;
    //     for (auto v: st) {
    //         int n = int(v.size());
    //         for (int i = 1; i <= n - 1; i++) {
    //             auto w = v;
    //             w.insert(w.begin() + i, {v[i - 1] + v[i]});
    //             nst.insert(w);
    //         }
    //     }
    //     st = nst;
    //     cout << "PH " << ph << " : " << st.size() << endl;
    // }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int main(){
    int n;
    scanf("%d", &n);
    lld a[n];
    rep(i, 0, n){
        scanf("%lld", &a[i]);
    }
    lld ans = 0;
    int l = 0, r = 0;
    lld sum = 0, xor = 0;
    while(l < n){
        while(r < n && (sum + a[r]) == (xor ^ a[r])){
            sum += a[r];
            xor ^= a[r];
            r++;
        }
        ans += r - l;
        if(l == r){
            r++;
        }else{
            sum -= a[l];
            xor ^= a[l];
        }
        l++;
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 100000

using namespace std;

const ll mod = 1000000007;
vi g[maxn+5];
vi fii[maxn+5];
ll d[maxn+5][2], tot[maxn+5];

void dfsi (int nod, int t) {
  for (int nn: g[nod])
    if (nn != t) fii[nod].pb(nn), dfsi(nn, nod);
}

void dfs (int nod) {
  for (int nn: fii[nod]) dfs(nn);
  d[nod][0] = d[nod][1] = 1;
  if (sz(fii[nod]) > 0) {
    for (int nn: fii[nod]) d[nod][0] = (d[nod][0] * tot[nn]) % mod;
    for (int nn: fii[nod]) d[nod][1] = (d[nod][1] * d[nn][0]) % mod;
  }
  tot[nod] = (d[nod][0] + d[nod][1]) % mod;
}

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n; cin >> n;
  int i, j, z, a, b;
  for (i = 0; i < n-1; i++) {
    cin >> a >> b; a--; b--;
    g[a].pb(b); g[b].pb(a);
  }
  dfsi(0, -1);
  dfs (0);
  cout << tot[0];
  return 0;
}


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


int main() {
  string s; cin >> s;

  if(s[0] == s[1] && s[1] == s[2] && s[2] =='R') cout << 3 << endl;
  else if((s[0] == s[1] && s[1] == 'R') || (s[1]==s[2] && s[2] =='R')) cout << 2 << endl;
  else if(s[0] == 'R' || s[1] == 'R' || s[2] =='R' ) cout << 1 << endl;
          else cout << 0 << endl;
  
}


Measured memory_bytes: 3620
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N;
    cin >> N;
    V<ll> A(N + 1), B(N);
    for(auto &&ele : A) cin >> ele;
    for(auto &&ele : B) cin >> ele;

    ll ans = 0;
    for(ll i = 0; i < N; i++) {
        ll &b = B[i];
        ll ei = min(b, A[i]);
        ans += ei;
        A[i] -= ei;
        b -= ei;
        ll eii = min(b, A[i + 1]);
        ans += eii;
        A[i + 1] -= eii;
        b -= eii;
    }

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


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

  int sum = L * N + N * (N-1) / 2;

  if(L >= 0) sum -= L;
  else if(abs(L) >= N) sum -= (L + N -1);

  cout << sum << endl;

  return 0;
}



Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    if 0 in A: print(0)
    else:
        ans = 1
        for i, a in enumerate(A):
            ans *= a
            if ans > 10 ** 18:
                print(-1)
                break
        else:
            print(ans)
        

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 21780
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner reader= new Scanner(System.in);
        int num=reader.nextInt();
        int[] A= new int[100001];
        for(int i=0; i<num; i++){
            int x= reader.nextInt();
            if (x==0){
                A[0]++;
                A[1]++;
            }
            else
            {if(x==9999){
                A[9999]++;
                A[9998]++;
            }
            else{
                A[x]++;
                A[x+1]++;
                A[x-1]++;
            }}}
            int max=A[0];
            for (int j=1; j<100001; j++){
                if (A[j]>max)
                    max=A[j];
            }
            System.out.println(max);
        }

    }


Measured memory_bytes: 50224
import fractions
 
n = int(input())
a = list(map(int, input().split()))
 
l = 1
for i in range(n):
	l = l // fractions.gcd(l, a[i])*a[i]
 
ans = 0
for i in range(n):
	ans += l//a[i]
print(ans%(10**9+7))

Measured memory_bytes: 6072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include<queue>
#include<math.h>
#include <iomanip>
#define rep(i,n) for (int i=0; i<(n);++i)
using namespace std;
using ll=long long;
using P =pair<double, double>;
const ll INF = 1LL << 60;
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 double PI = 3.14159265358979323846;

int main() {
	P a, b;

	double A, B, h, m;
	cin >> A >> B >> h >> m;

	long double omegaA ;
	long double omegaB ;
	omegaA = 0.5 * (h * 60 + m) * PI / 180;
	omegaB = 6 * m * PI / 180;

	a.first = A * sin(omegaA);
	a.second =  A * cos(omegaA);
	b.first = B * sin(omegaB);
	b.second = B* cos(omegaB);

	double dis = sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
	cout <<fixed<<setprecision(15)<< dis << endl;

	return 0;
}

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

using namespace std;

// 貪欲法

// N: お店の数
// M: 求める本数
long N, M;

using P = pair<long, long>;
vector<P> vec;

void solve();

int main() {
  cin >> N >> M;
  vec.resize(N);

  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    vec[i] = make_pair(a, b);
  }

  solve();
}

void solve() {
  sort(vec.begin(), vec.end());

  long long m = M;
  long long price = 0;
  for (auto p : vec) {
    if (m - p.second > 0) {
      price += p.first * p.second;
      m = m - p.second;
    } else {
      price += p.first * m;
      m = 0;
      break;
    }
  }
  cout << price << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define each(i, n) for(auto&& i: n)
#define pr(n) cout << fixed << setprecision(n)

int main() {
  int A, B, a = 0;
  cin >> A >> B;
  B--;
  while(B > 0) {
    B -= A - 1;
    a++;
  }
  cout << a << endl;
}

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

using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long


int main(){
  int N;
  cin >> N;
  LINT A[N];
  REP(i, N) cin >> A[i];

  sort(A, A+N, greater<LINT>());

  LINT ansl = 0;
  LINT anss = 0;
  int count = 0;


  REP(i, N-1){
    if(A[i] == A[i+1] && count == 1) {
      anss = A[i];
      break;
    }

    if(A[i] == A[i+1] && count == 0) {
      ansl = A[i];
      ++count;
      ++i;
    }
  }

  cout << ansl * anss ;

  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    String subs = s.substring(2,s.length()-1);
    boolean flg = true;
    int countC = 0;
    if(!s.substring(0,1).equals("A"))
      flg = false;
    for(int i=0; i<subs.length(); i++) {
      if(subs.charAt(i)=='C')
        countC++;
    }
    if(countC!=1)
      flg = false;
    for(int i=1; i<s.length(); i++) {
      if(!s.substring(i,i+1).equals("C") && Character.isUpperCase(s.charAt(i)))
         flg = false;
    }
    System.out.println(flg==false?"WA":"AC");
  }
}

Measured memory_bytes: 32600
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<double> b(n-1);
    for(int i=0; i<n-1; i++){
        cin>>b.at(i);
    }
    
    int ans=0;
    for(int i=0; i<n; i++){
        if(i==0){
            ans+=b.at(i);
        }else if(i==n-1){
            ans+=b.at(i-1);
        }else{
            ans+=min(b.at(i-1), b.at(i));
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
class Integer
  def bijective_s(base=nil, offset=nil)
    offset ||= 'a'.ord #97
    base ||= 26
    value = self
    result = []
    while value > 0
      value -= 1
      result << (value%base+offset).chr
      value /= base
    end
    result.reverse.join
  end
end

number = gets.to_i
puts number.bijective_s

Measured memory_bytes: 14148
#include <iostream>
using namespace std;
int main(void)
{
	int a,b,c,d,e,k;
	int flag=0;
	cin>>a>>b>>c>>d>>e>>k;
	if(b-a>k)
	flag=1;
	if(c-a>k)
	flag=1;
	if(d-a>k)
	flag=1;
	if(e-a>k)
	flag=1;
	
	if(c-b>k)
	flag=1;
	if(d-b>k)
	flag=1;
	if(e-b>k)
	flag=1;
	
	if(d-c>k)
	flag=1;
	if(e-c>k)
	flag=1;
	
	if(e-d>k)
	flag=1;
	
	if(flag==0)
	cout<<"Yay!"<<endl;
	else
	cout<<":("<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
ll m=1000000007;
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p)%m;
p=(p*p)%m;
k>>=1;
}
return a;
}
using namespace std;
int main()
{
ll n;
cin>>n;
cout<<n*n*n;
return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
#define ex(x) return cout << x << endl, 0
int n, a[MAXN], b[MAXN];
int ans = 0;
ll sum;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i = 0; i < n;i ++) cin >> a[i], sum += a[i];
	for(int i = 0; i < n;i ++) cin >> b[i], sum -= b[i];
	if( sum < 0) ex(-1);
	sum = 0;
	vector< int > vec;
	vec.clear();
	for(int i = 0; i < n; i++){
		if( b[i] > a[i]) sum += b[i] - a[i], ans ++;
		else if(a[i] > b[i]) vec.push_back(a[i] - b[i]);
	}
	sort(vec.begin(), vec.end());
	while( sum > 0 ){
		sum -= vec.back();
		vec.pop_back();
		ans ++;
	}
	ex(ans);
    return 0;
}



Measured memory_bytes: 4492
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	vector<vector<bool> > dp(N + 1);
	for (int i = 1; i <= N; ++i) {
		dp[i].resize(N - i + 1, false);
		if (i == 1) continue;
		for (int j = 0; j <= N - i; ++j) {
			for (int k = 1; k < i; ++k) {
				if (dp[k][j] && dp[i - k][j + k]) {
					dp[i][j] = true;
				}
			}
			if (A[j] != A[j + i - 1]) continue;
			vector<bool> dp2(i + 1);
			dp2[0] = true;
			for (int k = 1; k <= i; ++k) {
				if (dp2[k - 1] && A[j + k - 1] == A[j]) dp2[k] = true;
				for (int l = 0; l < k; ++l) {
					if (dp2[l] && dp[k - l][j + l]) dp2[k] = true;
				}
			}
			if (dp2[i]) dp[i][j] = true;
		}
	}
	cout << (dp[N][0] ? "yes" : "no") << endl;
	return 0;
}


Measured memory_bytes: 3124
from collections import deque
import itertools

N=int(input())
b=[-1]+list(map(int,input().split()))
ans=deque([])
for i in range(N):
    i=len(b)-1
    while i>0:
        if b[i]==i:
            ans.appendleft(str(i))
            b=list(itertools.chain(b[:i],b[i+1:]))
            break
        i-=1
    else:
        break
if len(b)==1:
    print("\n".join(ans))
else:
    print(-1)

Measured memory_bytes: 3316