akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T>inline int bs(int g,int k,T c){while(abs(k-g)>1){int m=(g+k)/2;(c(m)?k:g)=m;}return k;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    int n;
    cin >> n;
    vector<int> p(n);
    cin >> p;

    int mn = n+1;
    int cnt = 0;
    for(int i = 0; i < n; ++i){
        if(p[i] < mn){
            ++cnt;
            mn = p[i];
        }
    }
    cout << cnt << '\n';

    
    
    return 0;
}


Measured memory_bytes: 1024
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    ll n, k, s;
    cin >> n >> k >> s;
    for(int i = 0; i < k; i++) {
        cout << (s) << " ";
    }
    if( s == 1e9 ) s -= 2;
    for(int i = k; i < n; i++) {
        cout << (s + 1) << " ";
    }
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int A[3], cnt = 0, len;
    len = sizeof(A)/sizeof(int);
    vector<int> v;
    for(int i = 0; i < 3; i++){
        cin >> A[i];
    }
    while(!(A[0] == A[1] && A[0] == A[2])){
        sort(A, A+len);
        if(A[1] - A[0] >= 2){
            A[0] += 2;
        } else {
            A[0] += 1;
            A[1] += 1;
        }
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[100],count=0,mem=0;
  for(int i=0;i<n;i++){
    while(1){
      
      cin>>a[i];
      if(a[i]==1){
	count++;
	if(mem<count) mem=count;
	break;
      }
      count=0;
      break;
    }
  }
    cout<<mem+1<<endl;
  return 0;
}



Measured memory_bytes: 3120
#include<iostream>
using namespace std;
 
int main()
{
    int N, W;
    cin >> N >> W;
  
    int v[N],w[N];
     
    for(int i=0; i<N; i++){
        cin >> v[i] >> w[i];
    }
  
    int dp[N+1][W+1];
 
    for(int j=0; j<=W; j++)
        dp[N][j] = 0;
  
    for(int i=N-1; i>=0; i--){
        for(int j=0; j<=W; j++){
            if(j<w[i])
                dp[i][j] = dp[i+1][j];
            else{
                if(dp[i+1][j]>dp[i+1][j-w[i]]+v[i])
                    dp[i][j] = dp[i+1][j];
                else   
                    dp[i][j]=dp[i+1][j-w[i]]+v[i];         
             }
        }
   } 
    cout << dp[0][W] << endl;
  
    return 0;
}

Measured memory_bytes: 7020
N, M, C= map(int, input().split())
B = list(map(int, input().split()))
count = 0
for i in range(N):
    s = 0
    A = list(map(int, input().split()))
    for j in range(M):
        s += A[j] * B[j]
    s += C
    if s > 0:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string hoge;
    cin >> hoge;
    for (int i = 0; i < hoge.size(); i++) {
        if (i % 2 == 1 
            && (hoge[i] != 'L' && hoge[i] != 'U' && hoge[i] != 'D')) {
            cout << "No" << endl;
            return 0;
        } else if (i % 2 == 0
            && (hoge[i] != 'R' && hoge[i] != 'U' && hoge[i] != 'D')) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long x,long long y){
    while(x && y){
        x%=y;
        if(x==0)break;
        y%=x;
    }
    return x+y;
}
int main(){
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;
    long long lcm=c*d/gcd(c,d);
    cout<<b-b/c-b/d+b/lcm-a+a/c+a/d-a/lcm<<endl;
    return 0;
}


Measured memory_bytes: 3592
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::*;
use proconio::{input, fastout, marker::*};

// O(√n)
fn prime_factorization(mut n: usize) -> collections::HashMap<usize,usize> {
    let mut p = collections::HashMap::new();
    let mut i = 2;

    while i*i <= n {
        while n%i == 0 {
            n /= i;
            *p.entry(i).or_insert(1) += 1;
        }
        i += 1;
    }
    if n > 1 {*p.entry(n).or_insert(1) += 1;}
    p
}

#[fastout]
fn main() {
  input!{
    n:usize,
    a:[usize;n]
  }
  let mut set:collections::HashSet<usize> = collections::HashSet::new();
  let mut pairwise_flag:bool = true;
  for i in 0..n {
      let x:collections::HashMap<usize,usize> = prime_factorization(a[i]);
      for (k,_v) in x.iter() {
          if set.contains(k) {
            pairwise_flag = false;
          }
          set.insert(*k);
      }
  }
  println!("{} coprime",
           if pairwise_flag {
               "pairwise"
           }else{
            let mut x = a[0];
            for i in 0..n {
                x = num_integer::gcd(a[i],x);
            }
            if x == 1{
                "setwise"
            }else{
                "not"
            }
           });
}


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

A = []
for _ in range(n):
    A.append(int(input()))

dp = [0 for _ in range(n)]
dp[0] = A[0]
len = 1

def CeilIndex(A, l, r, key):
    while r-l > 1:
        m = (l+r) // 2
        if A[m] >= key:
            r = m
        else:
            l = m
    return r

for i in range(1, n):
    #print(A[i], dp)
    if A[i] < dp[0]:
        dp[0] = A[i]
    elif A[i] > dp[len-1]:
        dp[len] = A[i]
        len += 1
    else:
        dp[CeilIndex(dp, -1, len-1, A[i])] = A[i]
print(len)




Measured memory_bytes: 10348
#include <bits/stdc++.h>
using namespace std;
 
int main() {string S;
           cin>>S;
            int sum=0;
           for(int i=0;i<3;i++)
           {
             if(S.at(i)=='1'){sum ++;}
             else{sum+=0;}
           }
          cout<<sum<<endl; }


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

#define endl '\n'

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;

#define ff first
#define ss second

#define x first
#define y second

const int N = 200;

pii dir[2] = {
  {1, 0},
  {0, 1}
};

bool a[N][N];
int dp[N][N];

int dfs(pii u, int n, int m) {
  if (u.x == m-1 and u.y == n-1) return a[u.y][u.x];
  if (~dp[u.y][u.x]) return dp[u.y][u.x];
  dp[u.y][u.x] = INT_MAX;
  for (int i = 0; i < 2; i++) {
    pii v = {u.x + dir[i].x, u.y + dir[i].y};
    if (v.x < m and v.y < n) {
      dp[u.y][u.x] = min(dp[u.y][u.x], dfs(v, n, m) + (a[u.y][u.x] and !a[v.y][v.x]));
    }
  }
  return dp[u.y][u.x];
}

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

  string s;

  int h, w;
  cin >> h >> w;
  cin.ignore();

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c; cin >> c;
      a[i][j] = (c == '#');
    }
    cin.ignore();
  }

  memset(dp, -1, sizeof dp);

  int ans = dfs({0, 0}, h, w);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
/*https://abc105.contest.atcoder.jp/
018.8.11
*/

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
using namespace std;

int main()
{
 	ios::sync_with_stdio(false);
	int N;
	int i,j,k;
	while(cin>>N)
	{
		j=0;
		for(i=0;i<N;i++)
		{
			if(N-4*i<0)
			{
				break;
			}
			if((N-4*i)%7==0)
			{
				cout<<"Yes"<<endl;
				j=1;
				break;
			}
		}
		if(j==0)
		{
			cout<<"No"<<endl;
		}
	}
	
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();
	vector<int> a(n),b(n);
	for(int &i:a)i=in();for(int &i:b)i=in();
	reverse(all(b));
	int c=-1;
	for(int i=0;i<n;i++)
	if(a[i]==b[i]){c=a[i];break;}
	int l=0,r=-1;
	for(int i=0;i<n;i++)
	{
		if(b[i]==c and a[i]==c){l=i;break;}
	}
	for(int i=n-1;i>=0;i--)
	if(b[i]==c and a[i]==c){r=i;break;}
	
	for(int i=0;i<n;i++)
	{
		if(a[i]!=c and b[i]!=c and l<=r)
		{swap(b[i],b[l]);l++;}
	}
	if(l<=r){puts("No");return 0;}
	puts("Yes");
	for(int i:b)cout<<i<<" ";
	
	
}


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

using namespace std;

int main(){
  string S;
  cin>>S;
  vector<int> stack_int,first_number,second_number;
  vector<char> stack_char;
  for(int i=0;i<S.length();i++){
    if(S[i]=='_'){
      continue;
    }else if(S[i]=='\\'){
      stack_int.push_back(i);
      stack_char.push_back(S[i]);
    }else if(S[i]=='/'&&stack_int.empty()==false){
      first_number.push_back(stack_int[stack_int.size()-1]);
      stack_int.pop_back();
      stack_char.pop_back();
      second_number.push_back(i);
    }else{
      continue;
    }
  }
  int All_area=0;
  vector<int> Area;
  if(first_number.empty()==false){
    int First=first_number[first_number.size()-1],
        Second=second_number[first_number.size()-1];
    for(int i=first_number.size()-1;i>=0;i--){
      if(First<first_number[i]&&Second>second_number[i]){
        Area[Area.size()-1]+=second_number[i]-first_number[i];
      }else{
        First=first_number[i];
        Second=second_number[i];
        Area.push_back(Second-First);
      }
      All_area+=second_number[i]-first_number[i];
    }
  }

  cout<<All_area<<endl;
  if(Area.empty()==false){
    cout<<Area.size();
    for(int i=Area.size()-1;i>=0;i--){
      cout<<" "<<Area[i];
      if(i==0)cout<<endl;
    }
  }else{
    cout<<0<<endl;
  }
}



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

using namespace std;
using ll = long long;

const int mod = 998244353;
int add(int a, int b) {
	return a + b < mod ? a + b : a + b - mod;
}

const int N = 200005;

int st[2*N];
int n, k;

int query(int l, int r) {
	int ans = 0;
	for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
		if(l & 1) ans = add(ans, st[l++]);
		if(r & 1) ans = add(ans, st[--r]);
	}
	return ans;
}
void upd(int p, int val) {
	p += n;
	st[p] = add(st[p], val);
	while(p >>= 1) st[p] = add(st[2 * p], st[2 * p + 1]);
}

int L[20], R[20];
int dp[N];
int main() {

	scanf("%d %d", &n, &k);

	for(int i = 0; i < k; i++) scanf("%d %d", L + i, R + i);

	dp[n - 1] = 1;
	upd(n - 1, dp[n - 1]);
	for(int i = n - 2; i >= 0; i--) {
		for(int j = 0; j < k; j++) {
			if(i + L[j] > n - 1) continue;
			dp[i] = add(dp[i], query(i + L[j], min(n - 1, i + R[j])));
		}
		upd(i, dp[i]);
	}

	printf("%d\n", dp[0]);
}


Measured memory_bytes: 6156
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    REP(i, 1, 114514)
    {
        ans = 0;
        REP(j, 1, i+1)
        {
            if (i % j == 0)
            {
                ans++;
            }
        }
        if (ans == n)
        {
            cout << i << endl;
            return 0;
        }
    }

}



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

ll MOD = 1000000007;

ll modpow(ll x, ll y, ll n) {
    ll res = 1;
    x%=n;
    while (y>0) {
        if (y%2==1) {
            res*=x; res%=n;
        }
        y/=2;
        x*=x; x%=n;
    }
    return res;
}

int main() {
    vector<ll> facts(100002), invs(100002);
    facts[0] = 1;
    invs[0] = 1;
    for (ll i=1; i<=100001; i++) {
        facts[i] = facts[i-1]*i%MOD;
        invs[i] = modpow(facts[i],MOD-2,MOD);
    }
    ll n, x;
    cin >> n;
    vector<ll> nums;
    for (ll i=0; i<=n; i++) {
        cin >> x;
        nums.push_back(x);
    }
    ll cnt = 0;
    vector<ll> counts(100002, 0);
    for (auto i : nums) counts[i]++;
    ll mark;
    for (ll i=0; i<=n; i++) if (counts[i]==2) mark = i;
    for (ll i=0; i<=n; i++) {
        if (nums[i]==mark) break;
        cnt++;
    }
    for (ll i=n; i>=0; i--) {
        if (nums[i]==mark) break;
        cnt++;
    }
    ll res;
    for (ll i=1; i<=n+1; i++) {
        res = 0;
        ll mult = facts[n+1] * invs[i] % MOD;
        mult = mult*invs[n+1-i]%MOD;
        res+=mult; res%=MOD;
        if (cnt>=i-1) {
            mult = facts[cnt] * invs[i-1] % MOD;
            mult = mult*invs[cnt-i+1]%MOD;
            res-=mult; if (res<0) res+=MOD;
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 6392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
struct segtree{
	#define s (1<<19)
	int seg[s];
	void init(){
		fill(seg,seg+s,-INF);
	}
	void update(int k,int a){
		k+=s/2-1; seg[k]=max(seg[k],a);
		while(k>0){
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
	int query(int a,int b,int k,int l,int r){
		if(r<a || b<l || b<a) return -INF;
		if(a<=l && r<=b) return seg[k];
		else{
			int vl=query(a,b,k*2+1,l,(l+r)/2);
			int vr=query(a,b,k*2+2,(l+r)/2+1,r);
			return max(vl,vr);
		}
	}
}seg1,seg2;
int n,q,b[200005],f[200005];
P p[200005];
int main(){
	scanf("%d",&n);
	repn(i,n){
		scanf("%d",&b[i]);
		f[i] = f[i-1]+(b[i]==1?1:-1);
	}
	scanf("%d",&q);
	repn(i,q){
		int L,R; scanf("%d%d",&L,&R);
		p[i] = mp(L,R);
	}
	sort(p+1,p+q+1);
	seg1.init(); seg2.init();
	int ret = 0;
	seg1.update(0,0); seg2.update(0,0);
	repn(i,q){
		int L = p[i].fi,R = p[i].sc;
		//[1,...,L-1]
		int x = seg1.query(0,L-1,0,0,(1<<18)-1);
		int dp = -INF;
		x += f[R]-f[L-1];
		dp = max(dp,x);
		x = seg2.query(L,R-1,0,0,(1<<18)-1);
		x += f[R];
		dp = max(dp,x);
		assert(dp>=-1e8);
	//	cout<<dp<<endl;
		seg1.update(R,dp);
	//	cout<<R<<dp<<endl;
		seg2.update(R,dp-f[R]);
	}
	ret = max(ret,seg1.query(0,(1<<18)-1,0,0,(1<<18)-1));
	ret *= -1;
	//cout<<ret<<endl;
	for(int i=1;i<=n;i++){
		ret += b[i];
	}
	cout<<ret<<endl;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
using st = size_t;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using ull = unsigned long long;
#define inf 0x40000000
#define all(v) v.begin(), v.end()
#define alld(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
template <typename T> using mptr = T*;
using mp = pair<int, int>;
auto des = [](auto a, auto b) { return a > b; };

#include <bits/stdc++.h>
using namespace std;

int main() {
	vector<vector<int>>a(3,vector<int>(3));
	rep(i,3)rep(j,3)cin>>a.at(i).at(j);
	int n,t;
	cin>>n;
	vector<vector<bool>>b(3,vector<bool>(3,false));
	rep(i,n){
		cin>>t;
		rep(j,3){
			rep(k,3){
				if(t==a.at(j).at(k))
					b.at(j).at(k)=true;
			}
		}
	}
	int c;
	bool yes=false;
	rep(i,3){
		c=0;
		rep(j,3){
			if(b.at(i).at(j)==true)
				++c;
		}
		if(c==3)yes=true;
	}
	rep(j,3){
		c=0;
		rep(i,3){
			if(b.at(i).at(j)==true)
				++c;
		}
		if(c==3)yes=true;
	}
	if(b.at(0).at(0)&&b.at(1).at(1)&&b.at(2).at(2))yes=true;
	if(b.at(0).at(2)&&b.at(1).at(1)&&b.at(2).at(0))yes=true;
	if(yes)cout<<"Yes\n"s;
	else cout<<"No\n"s;
}

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

using namespace std;

int main() {
    int n, m;

    cin >> n >> m;
    map<int, string> mp;
    int z;
    string s;
    int countin=0;
    int ca = 0;
    int arr[100000];
    for(int i = 0; i < 100000; i++) {
        arr[i] = 0;
    }


    for(int i = 0; i < m; i++) {
        cin >> z;
        cin >> s;
        mp[z] = s;
        if(mp[z]=="AC" && arr[z] != -1){
            countin += arr[z];
            arr[z] = -1;
            ca++;
        }else if (arr[z] != -1){
            arr[z]++;
        }
    }
    cout << ca << " " << countin << endl;

    /*if(m == 0) {
        cout << 0 << " " << 0 << endl;
    }else{
        cin >> z;
        cin >> s;
        mp.insert(pair<int,string>(z, s));
        if(mp[z] == "AC") {
            ca++;

        }else {
            countin++;
        }
        for(int i = 1; i < m; i++) {
            cin >> z;
            cin >> s;
            if(mp[z]=="AC"){
                b = true;
            }else{
                mp[z] = s;
            }


            if(mp[z]=="AC" && !b) {
                ca++;

            }else if (!b){
                arr[z]++;
                countin ++;
            }
            b = false;
        }
        cout << ca << " " << countin << endl;
    }*/


    return 0;
}

Measured memory_bytes: 11768
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n;
  cin >> n;
  vint A(n+1);
  vint B(n);
  rep(i,0,n+1) cin >> A[i];
  rep(i,0,n) cin >> B[i];
  int ans = 0;
  rep(i,0,n){
    if(B[i] < A[i]){
      ans += B[i];
    }
    else{
      if(A[i+1] > B[i] - A[i]){
        A[i+1] -= B[i] - A[i];
        ans += B[i];
      }
      else{
        ans += A[i] + A[i+1];
        A[i+1] = 0;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
int main()
{    
    string t = "";
    string s;
    cin >> s;
    for(int i = 0;i < (int)s.size();i++)
    {
        if(s[i] == '0')
            t += "0";
        
        if(s[i] == '1')
            t += "1";

        if(s[i] == 'B' && t.size() != 0)
            t.pop_back();
    }
    cout << t << '\n';
}   



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        System.out.println(calc(a));
    }

    public static int calc(int a){
        return a + a*a + a*a*a;
    }
}


Measured memory_bytes: 35780
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
const int maxn = 62, mlg = 18, rt = 1<<10, mod = 1e9 + 7;
struct dsu {
	vi p, r;
	vector<vi> col;
	dsu(int n) {
		p.resize(n+1);
		iota(all(p), 0);
		r.resize(n+1,1);
		col.resize(n+1);
	}
	int par(int v) {
		return v^p[v] ? p[v] = par(p[v]) : v;
	}
	void unite(int i, int j) {
		i = par(i), j = par(j);
		if(i == j) return;
		if(r[i] < r[j]) swap(i, j);
		p[j] = i, r[i] += r[j];
		for(auto x : col[j]) col[i].push_back(x);
	}
};
int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, k, l;
	cin >> n >> k >> l;
	dsu a(n), b(n);
	int f, t;
	while(k--) {
		cin >> f >> t;
		a.unite(f, t);
	}
	for(int i = 1; i <= n; i++) b.col[i].pb(a.par(i));
	while(l--) {
		cin >> f >> t;
		b.unite(f, t);
	}
	vector<map<int, int>> ans(n+1);
	for(int i = 1; i <= n; i++) if(i == b.par(i)) {
		for(auto j : b.col[i]) ans[j][i]++;
	}
	for(int i = 1; i <= n; i++) {
		f = a.par(i), t = b.par(i);
		cout << ans[f][t] << ' ';
	}
} 


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

using namespace std;

struct expand_type {
    template <typename... T>
    expand_type (T&&...) {}
};
template <typename... ArgTypes>
void print (ArgTypes... args) {
    expand_type {0, (cerr << args << ", ", 0)...};
    cerr << "\b\b \n";
}
#define printv(x) cerr << "["; for(auto i : (x)) cerr << i << ", "; cerr << "\b\b]\n";

typedef unsigned long long ull;
typedef long double ld;


void solve () {
    string n;
    cin >> n;
    int d = n.back() - '0';
    if (d == 3) {
        cout << "bon" << endl;
    } else if (d == 0 || d == 1 || d == 6 || d == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
}

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


Measured memory_bytes: 3604
use proconio::*;

fn run() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let m = *a.iter().max().unwrap();
    let mut f = (0..=m).collect::<Vec<_>>();
    for i in (2..).take_while(|p| p * p <= m) {
        if f[i] == i {
            for j in i..=(m / i) {
                f[j * i] = i;
            }
        }
    }
    let mut cnt = vec![0; m + 1];
    for mut a in a {
        while a > 1 {
            let p = f[a];
            cnt[p] += 1;
            while a % p == 0 {
                a /= p;
            }
        }
    }
    let ans = if cnt.iter().all(|c| *c <= 1) {
        "pairwise coprime"
    } else if cnt.iter().all(|c| *c < n) {
        "setwise coprime"
    } else {
        "not coprime"
    };
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 31936
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> point(n,0);
    int a;
    for(int i = 0;i < q;i++) {
        cin >> a;
        point.at(a - 1)++;
    }
    for(int i = 0;i < n;i++) {
        if(k - (q - point.at(i)) > 0) {
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
    }
}


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

typedef long long LL;

const int maxn=2e5+5;
const LL mo=998244353;

struct ST{
	int col,num;
	ST() {col=num=0;}
};

int n;
char s[3*maxn];
LL fac[maxn];

int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	
	fac[0]=1;
	fo(i,1,n) fac[i]=fac[i-1]*i%mo;
	
	LL ans=1, cnt=0, left=0;
	ST neg,zero;
	fo(i,1,3*n) if (zero.num>0 && neg.num>0 && s[i]!=zero.col && s[i]!=neg.col)
	{
		(ans*=cnt)%=mo;
		cnt--;
		zero.num--;
		neg.num--;
	} else if (neg.num==zero.num)
	{
		if (s[i]==zero.col) zero.col=neg.col;
		neg.col=s[i];
		neg.num++;
		left=1;
	} else
	{
		if (neg.col!=s[i])
		{
			zero.col=s[i];
			zero.num++;
			cnt++;
			(ans*=left)%=mo;
			left--;
		} else
		{
			neg.num++;
			left++;
		}
	}
	
	(ans*=fac[n])%=mo;
	
	printf("%lld\n",ans);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
typedef long long LL;
const int MaxN = 2e5;
using namespace std;

LL a[MaxN + 5],b[MaxN + 5];
int main(){
	int n;
	cin>>n;
	for(int i=1; i<=n; ++i){
		cin>>a[i];
		b[i] = a[i];
	}
	int mid = n/2;
	sort(a+1,a+n+1);
	for(int i=1; i<=n; ++i){
			if(b[i] <= a[mid])cout<<a[mid+1]<<endl;
			else cout<<a[mid]<<endl;
	}

	return 0;
}

Measured memory_bytes: 5376
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string X;
	scan(X);
	int N=X.size();
	int snum=0;
	rep(i,N){
		if(X[i]=='S') snum++;
		else if(snum>0) snum--;
	}
	prin(snum*2);
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main{

	static int count = 0;

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int n  = sc.nextInt();
		int[] A = new int[n];

		for(int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}

		int p = partition (A, 0, n-1);

		StringBuilder sb = new StringBuilder();
        int outLen = A.length;

        if(p != 0){
            sb.append(A[0]);
        }
        else{
            sb.append("[" + A[0] + "]");
        }
        for(int i = 1; i < outLen ; i++){
            if(i == p){
                sb.append(" ["+ A[i] + "]");

            }
            else{
                sb.append(" "+ A[i]);

            }
        }
        System.out.println(sb);
	}

	static int	 partition (int[] A, int p, int r) {
		int x = A[r];
		int i = p - 1;

		for(int j = p; j < r; j++) {
			if(A[j] <= x) {
				i = i + 1;
				swap(A, i, j);
			}
		}

		swap(A, i+1, r);
		return i + 1;
	}

	private static void swap(int[] a, int index1, int index2) {
		int temp = a[index1];
		a[index1] = a[index2];
		a[index2] = temp;
	}


}


Measured memory_bytes: 68124
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    using ll = long long;
    using P = pair<int,int>;
    
    int main() {
   
     ll n;
     cin >> n;
     ll count = 0;
     
     for(int i = 1; i <= n; i++){
     	if(i%5==0 || i%3==0) continue;
     	else count+=i;
     }
      cout << count << '\n';
     
     return 0;
    }

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;

signed main(){
    int N,M;cin>>N>>M;
    int dp[(1<<N)];
    REP(i,(1<<N))dp[i]=INF;
    dp[0]=0;
    REP(i,M){
        int a,b;cin>>a>>b;
      	int now=0;
        REP(j,b){
            int c;cin>>c;c--;
            now+=(1<<c);
        }
        for(int k=0;k<(1<<N);k++) chmin(dp[(k|now)],dp[k]+a);
    }
    int ans=dp[(1<<N)-1];
    cout<<(ans!=INF?ans:-1)<<endl;
}

Measured memory_bytes: 256
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
a = inl()
if n<-4 and k==2:
    3/0
mx = sum(a)
lacc = [0]*(n+1)
racc = [0]*(n+1)
for i in range(n):
    lacc[i+1] = lacc[i]+max(a[i],0)
for i in range(n-1,-1,-1):
    racc[i] = racc[i+1]+max(a[i],0)
sk = sum(a[:k])
for i in range(n-k+1):
    mx = max(mx,lacc[i]+max(sk,0)+racc[i+k])
    if i<n-k:
        sk += a[i+k]-a[i]
print(mx)


Measured memory_bytes: 86972
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define S 10001
#define M 1000000007
#define nl cout<<"\n";
#define error  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x) cerr << #x << " is " << x << endl;
#define test lli t;  cin>>t; while(t--)
int main()
{
    lli i,j,n,k;
    cin>>n>>k;
    lli a[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    lli dp[n+1];
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(i=3;i<=n;i++)
    {
         for(j=1;j<=k&&i-j>=1;j++)
         {
            if(j==1)
            {
                dp[i]=dp[i-1]+abs(a[i]-a[i-j]);
            } 
            else
            {
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            }
         }
        
    }
    cout<<dp[n];
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

int main(void) {
  string S;
  ll K;
  cin >> S >> K;

  vector<string> sub;
  REP(i, 0, S.size()) REP(j, i, min(i + 5, (ll) S.size())) {
    sub.push_back(S.substr(i, j + 1 - i));
    sort(sub.begin(), sub.end());
    sub.erase(unique(sub.begin(), sub.end()), sub.end());
    if(sub.size() > 5) sub.resize(5);
  }

  cout << sub[K - 1] << endl;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = input()
    tmp = 0
    for i in N:
        tmp += int(i)
    if tmp%9==0:
        print('Yes')
    else:
        print('No')




if __name__ == '__main__':
    main()


Measured memory_bytes: 9228
#include <cstdint>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

int32_t check(std::vector<uint32_t> &a_list)
{
    uint32_t pos = 1;
    uint32_t count = 1;
    while(a_list.at(pos) != 0)
    {
        uint32_t &a = a_list.at(pos);
        if (a == 2) return count;
        pos = a;
        a = 0;
        count++;
    }
    return -1;
}

int main(void)
{
    uint32_t n;

    std::cin >> n;

    std::vector<uint32_t> a_list(n+1);
    for (uint32_t i = 1; i < a_list.size(); ++i) {
        std::cin >> a_list.at(i);
    }

    std::cout << check(a_list) << std::endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
int n;
void solve(int k, string s, int last) {
    if(k == n) {
        cout << s << endl;
        return;
    }

    for(int i=0; i<=min(last+1, k); i++) {
        solve(k+1, s+(char)('a'+i), max(last, i));
    }
}

// void solve(string s, string cand) {
//     if((int) s.length() == n) {
//         cout << s << '\n';
//         return;
//     }
//     for(char c:cand) solve(s+c, cand);
// }

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

    solve(1, "a", 0);
    // string cand="";
    // for(int i=0; i<n; i++) {
    //     cand += (char)('a'+i);
    //     solve(cand, cand);
    // }

    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(ll i=(ll)b;i<(ll)e;++i)
#define forr(i,b,e)		  for(ll i=(ll)b;i<(ll)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (ll)x.size()
ll faster_in(){ll r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const ll INF = 1234567890;

const ll tam = 2e5 + 10;
const ll mod = 998244353;

ll modPow(ll b, ll e) {
    ll res = 1;
    while (e > 0) {
        if (e&1) res = (res * b) % mod;
        b = (b * b) % mod;
        e >>= 1;
    }
    return res;
}

ll purosUnos[tam];

ll T[4*tam], lazy[4*tam];
#define index ll L = 2*nodo+1, R = L+1, mid =(b+e)>>1;

void push(ll b, ll e, ll nodo) {
    index;
    if (lazy[nodo] == 0) return;
    if (b != e) {
        ll izq = mid - b + 1;
        ll der = e - mid;
        T[L] = (purosUnos[izq] * lazy[nodo]) % mod;
        T[R] = (purosUnos[der] * lazy[nodo]) % mod;
        lazy[L] = lazy[R] = lazy[nodo];
    }
    lazy[nodo] = 0;
}

void update(ll b, ll e, ll nodo, ll i, ll j, ll val) {
    index;
    if (j < b || e < i) return;
    if (i <= b && e <= j) {
        T[nodo] = (purosUnos[e-b+1] * val) % mod;
        lazy[nodo] = val;
        return;
    }
    push(b, e, nodo);
    update(b, mid, L, i, j, val);
    update(mid+1, e, R, i, j, val);
    T[nodo] = ((T[L] * modPow(10, e-mid)) % mod) + T[R];
    T[nodo] %= mod;
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    purosUnos[0] = 0;
    fore(i, 1, tam) {
        purosUnos[i] = purosUnos[i-1] + modPow(10, i-1);
        purosUnos[i] %= mod;
    }
    ll n, q;
    cin >> n >> q;
    update(0, n-1, 0, 0, n-1, 1);
    fore(i, 0, q) {
        ll l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        update(0, n-1, 0, l, r, d);
        cout << T[0] << '\n';
    }
    return 0;
}
// Dinosaurs are cool!

Measured memory_bytes: 13380
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>
#include <set>

using namespace std;

class cAllocateBaggage
{
	int mn, mk;

	vector<int> vw, vallocatedWeight;
public:
	cAllocateBaggage(int n, int k, vector<int> &v) 
		: mn(n), mk(k), vw(v)
	{
	}

	void alloc2();
};

void cAllocateBaggage::alloc2()
{
	int left = 0;
	int right = 100000 * 10000;

	int p = 0;
	int t_index;
	bool isFound;
	int p_found = 0;

	while (left <= right)
	{
		t_index = 0;
		isFound = false;
		p = left + (right - left) / 2;
		vallocatedWeight.clear();
		vallocatedWeight.resize(mk);

		for (int i = 0; i < vw.size(); ++i)
		{
			if (vallocatedWeight[t_index] + vw[i] > p && mk == t_index + 1)
			{
				break;
			}
			else if (vallocatedWeight[t_index] + vw[i] > p)
			{
				++t_index;
				--i;
			}
			else
			{
				vallocatedWeight[t_index] += vw[i];
				if ((i == (vw.size() - 1)) && t_index <= mk)
				{
					isFound = true;
				}
			}
		}
		if (isFound)
		{
			right = p - 1;
			p_found = p;
		}
		else
		{
			left = p + 1;
		}
	}
	if (!isFound)
		p = p_found;
	cout << p << endl;
}

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

	int n, k;
	cin >> n >> k;
	cin.ignore();

	vector<int> vw;

	int w;
	for (int i = 0; i < n; ++i)
	{
		cin >> w;
		vw.push_back(w);
	}

	cAllocateBaggage cab(n, k, vw);
	cab.alloc2();

	return 0;
}

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

typedef struct Node{
  int k;
  struct Node *right;
  struct Node *left;
  struct Node *parent;
}T;

T *root, *NIL;

void Insert(int);
void Inorder(T *);
void Preorder(T *);
T * Find(T *, int);
void Delete(T *);
T * Minimum(T *);
T * Successor(T *);

int main(){
  int i,n,value,findnum;
  char com[10];

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%s",com);

    if(strcmp(com,"insert") == 0){
      scanf("%d",&value);
      Insert(value);
    }
    else if(strcmp(com,"print") == 0){
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
    else if(strcmp(com,"find") == 0){
      scanf("%d",&value);
      struct Node *F = Find(root,value);
      if(F != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(com,"delete") == 0){
      scanf("%d",&value);
      Delete(Find(root,value));
    }
  }

    return 0;
}

void Insert(int n){
T *p = root;
T *q = NIL;
T *r;

r = (T *)malloc(sizeof(struct Node));
r -> k = n;
r -> left = NIL;
r -> right = NIL;

while(p != NIL){
   q = p;
   if(r->k < p->k){
     p = p -> left;
   }
   else{
     p = p -> right;
   }
}

r -> parent = q;
  if(q == NIL){
    root = r;
  }
  else{
    if(r->k < q->k){
      q -> left = r;
    }
    else{
      q -> right = r;
    }
  }
}

void Inorder(T *x){
  if(x == NIL) return;
  Inorder(x -> left);
  printf(" %d",x -> k);
  Inorder(x -> right);
}

void Preorder(T *x){
  if(x == NIL) return;
  printf(" %d",x -> k);
  Preorder(x -> left);
  Preorder(x -> right);
}

T * Find(T *x, int n){
  while(x != NIL && n != x -> k){
    if(n < x -> k ) x = x -> left;
    else x = x -> right;
  }
  return x;
}

void Delete(T *x){
  struct Node *y;
  struct Node *z;

  if(x -> left == NIL || x -> right == NIL) y = x;
  else y = Successor(x);

  if(y -> left != NIL) z = y -> left;
  else z = y -> right;

  if(z != NIL) z -> parent = y -> parent;

  if(y -> parent == NIL){
    root = y;
  }
  else {
    if(y == y -> parent -> left) y -> parent -> left = z;
    else y -> parent -> right = z;
  }

  if(y != x) x -> k = y -> k;

  free(y);
}

T * Minimum(T *x){
  while(x -> left != NIL) x = x -> left;
  return x;
}

T * Successor(T *x){
  struct Node *y;

  if(x -> right != NIL) return Minimum(x -> right);

  y = x -> parent;
  while(y != NIL && x == y -> right){
    x = y;
    y = y -> parent;
  }
  return y;
}



Measured memory_bytes: 20540
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = []
ord = [-1 for i in range(n+1)]
v = 1
c = 1
l = 0
while ord[v] == -1:
    ord[v] = len(s)
    s.append(v)
    v = a[v-1]
c = len(s) - ord[v]
l = ord[v]
if k < l:
    print(s[k])
else:
    k -= l
    k %= c
    print(s[l+k])

Measured memory_bytes: 107040
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <cassert>

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

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


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int a, b, sum = 0;
	cin >> a >> b;
	for (int i = 0; i < b - a; i++)
		sum += i;
	cout << sum - a << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

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

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (abs(c - a) <= d || (abs(b - a) <=d && abs(c - b) <= d)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main(){
  int a[4][4];
  bool app[4][4];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>a[i][j];
    }
  }
  int n,b[10];
  cin>>n;
  for(int k=0;k<n;k++){
    cin>>b[k];
  }
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      app[i][j]=false;
      for(int k=0;k<n;k++){
        if(a[i][j]==b[k]){
          app[i][j]=true;
        }
      }
    }
  }
  bool at=false;
  for(int i=0;i<3;i++){
    if(app[i][0]&&app[i][1]&&app[i][2]){
      at=true;
    }
    else if(app[0][i]&&app[1][i]&&app[2][i]){
      at=true;
    }
  }
  if(app[0][0]&&app[1][1]&&app[2][2]){
    at=true;
  }
  else if(app[0][2]&&app[1][1]&&app[2][0]){
    at=true;
  }
  if(at){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}
  
  


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

using namespace std;

#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

const int INF = 1e9 + 5;
const int MAXN = 3e6 + 123;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool cmp(const string& a, const string& b) {
	return (a + b) < (b + a);
}

vector<int> Reversed(const vector<int>& s){
   vector<int> d = s;
   reverse(all(d));
   return d;
}

void solve(){
    int a,b,c;
    cin >> a >> b >> c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    cout << s.size();

}

int main(){
    //freopen("lepus.in","r",stdin);
   // freopen("lepus.out","w",stdout);
    //faster();
    int n=1;
    //cin>>n;
    while(n--){
        solve();
        //cout << endl;
    }
    //fclose(stdout);
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]

B = sorted(A, reverse=True)


MAX1 = B[0]
MAX2 = B[1]


if MAX1 == MAX2:
    for a in range(N):
        print(MAX1)
else:
    for a in A:
        if a != MAX1:
            print(MAX1)
        else:
            print(MAX2)


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

using namespace std;

int main(){
    int n , m;
    cin >> n >> m;
    vector<int> a(m,0);
    for(int i=0;i<n;i++){
        int k ;
        cin >> k;
        for(int j=0;j<k;j++){
            int l;
            cin >> l;
            a[l-1] ++;
        }
    }
    int ans = 0;
    for(int i=0;i<m;i++){
        if(a[i] == n){
            ans ++;
        }
    }
    cout << ans;
    
}

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int x, pp; cin >> x >> pp;
  double p = pp / 100.0;
  double ans;
  if(x % 2) {
    ans = 1 + (1 / p) * (x / 2) + (1 / p) * (1 - p);
  } else {
    ans = (1 / p) * (x / 2);
  }
  cout << fixed << setprecision(7) << ans << endl;
}


Measured memory_bytes: 256
INF = 10**10
n, ma, mb = [int(item) for item in input().split()]
abc = [[int(item) for item in input().split()] for _ in range(n)]

memo = [[INF] * 401 for _ in range(401)]
memo[0][0] = 0 
for a, b, c in abc:
    for i in range(400,-1,-1):
        for j in range(400,-1,-1):
            if memo[i][j] != INF:
                memo[i+a][j+b] = min(memo[i+a][j+b], memo[i][j] + c)
ans = INF
for i in range(1,min(400//ma, 400//mb)):
    ans = min(ans, memo[ma*i][mb*i])
if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 4852
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	D := 0
	for i := 0; i < M; i++ {
		var H int
		fmt.Scan(&H)
		D += H
	}
	if D <= N {
		fmt.Println(N - D)
	} else {
		fmt.Println(-1)
	}
}


Measured memory_bytes: 2472
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();

    long[] a = nal(n);
    long sum = Arrays.stream(a).sum();
    long x = sum / 2;
    long left = 0;
    long right = sum;

    long ret = Long.MAX_VALUE;
    for (int i = 0; i <= n; i++) {
      ret = Math.min(ret, Math.abs(left - right));
      if (i < n) {
        left += a[i];
        right -= a[i];
      }
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 55128