akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n){
    cin >> s.at(i);
  }
  map<string,int> mp;
  rep(i,n){
    sort(ALL(s.at(i)));
    mp[s.at(i)]++;
  }
  ll ans = 0;
  for(auto p : mp){
    ll a = p.second;
    ans+=a*(a-1)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 18176
import math

class Point:
    def __init__(self, x = 0.0, y = 0.0):
        self.x = x
        self.y = y

    def __str__(self):
        return f"{self.x:.8f} {self.y:.8f}"


def koch(d, l, r):
    if d == 0:
        return

    s = Point()
    t = Point()
    u = Point()
    s.x = (2*l.x + 1*r.x) / (1 + 2)
    s.y = (2*l.y + 1*r.y) / (1 + 2)
    t.x = (1*l.x + 2*r.x) / (2 + 1)
    t.y = (1*l.y + 2*r.y) / (2 + 1)
    u.x = (t.x - s.x) * math.cos(math.radians(60)) - (t.y - s.y) * math.sin(math.radians(60)) + s.x
    u.y = (t.x - s.x) * math.sin(math.radians(60)) + (t.y - s.y) * math.cos(math.radians(60)) + s.y

    koch(d - 1, l, s)
    print(s)
    koch(d - 1, s, u)
    print(u)
    koch(d - 1, u, t)
    print(t)
    koch(d - 1, t, r)

n = int(input())
l, r = Point(), Point(100.0, 0.0)
print(l)
koch(n, l, r)
print(r)


Measured memory_bytes: 5784
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define rep(i, n) for (int i = 0; i < (n); ++i)

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

    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    vector<bool> dp(A[N-1]+1, true);
    int itr = 0;
    for (int i = 0; i < N; ++i) {
        if (!dp[A[i]]) continue;
        for (int j = 2; j*A[i] <= A[N-1]; ++j) {
            dp[j*A[i]] = false;
        }
    }

    int ans = 0;
    rep(i, N) {
        if (i < N-1 && A[i] == A[i+1]) {
            dp[A[i]] = false;
        }
        if (dp[A[i]]) ans++;
    }

    // rep(i, A[N-1]+1) {
    //     if (dp[i]) cout << i << " " << 1 << endl;
    //     else cout << i << " " << 0 << endl;
    // }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3952
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P; 
const int N = 100005;
//////////////////////////////

int n;
string p;
Int dp[3300][3300];
Int dp_sum[3300][3300];

int main()
{
	cin >> n;
	cin >> p;
	dp[0][0] = 1;

	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= i - 1; j++) {
			dp_sum[i - 1][j] = dp[i - 1][j];
			if (j - 1 >= 0) dp_sum[i - 1][j] += dp_sum[i - 1][j - 1];
			dp_sum[i - 1][j] %= MOD;
		}
		for (int j = 0; j <= i; j++) {
			if (p[i - 1] == '<') {
				if (j - 1 >= 0) dp[i][j] = dp_sum[i - 1][j - 1];
			}
			else {
				dp[i][j] = dp_sum[i - 1][i - 1];
				if (j - 1 >= 0) dp[i][j] -= dp_sum[i - 1][j - 1];
				dp[i][j] %= MOD;
			}
		}
	}

	Int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += dp[n - 1][i];
		ans %= MOD;
	}
	if (ans < 0) ans += MOD;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 97468
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const int MAX=1e5+1;
const ll INF=1e9;

int main()
{
    int n,q;
    string s;
    cin>>n>>q;
    cin>>s;
    int dp[n+1]={0};
    int ans[q]={0};
    rep(i,n-1)
    {
        dp[i+1]=dp[i] + (s.substr(i,2)=="AC");
    }
    rep(i,q)
    {
        int l,r;
        cin>>l>>r;
        ans[i]=dp[r-1]-dp[l-1];
    }
    rep(i,q)
    {
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
bitset<4000010> f;
int n,x,s;
int main(){
	f[0]=1;
	cin>>n;
	FOR(i,1,n){
		getint(x);
		s+=x;
		f|=(f<<x);
	}
	FOR(i,(s+1)/2,s)
		if (f[i]) return cout<<i<<endl,0;
		
	FOR(i,0,4) cout<<f[i]<<' ';
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	string s;
	cin >> s;
	
	ll pow_2[10];
	ll pow_10[10];
	pow_2[0] = 1;
	pow_10[0] = 1;
	rep(i,9){
		pow_2[i+1] = pow_2[i]*2;
		pow_10[i+1] = pow_10[i]*10;
	}
	
	ll ret = 0;
	ll n = s.size();
	rep(i,n){
		rep(j,n-i-1){
			ret += pow_2[n-2-j]*pow_10[j]*(ll)(s[i]-'0');
		}
		ret += pow_2[i]*pow_10[n-i-1]*(ll)(s[i]-'0');
	}
	cout << ret << endl;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<25);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

struct vtx{
	int x,y,f,r;
};

string s[111];
int h,w;

queue<vtx> que;

bool check(int i, int j){
	return (0<=i && i<h && 0<=j && j<w && s[i][j]!='#');
}

bool dist[111][111][6][6];

int main(void){
	int i,j;
	vtx u,v;
	cin >> h >> w;
	for(i=0; i<h; ++i){
		cin >> s[i];
		for(j=0; j<w; ++j){
			if(s[i][j]!='#'){
				s[i][j] -= '1';
			}
		}
	}
	dist[0][0][1][2] = true;
	v.x = 0; v.y = 0; v.f = 1; v.r = 2;
	que.push(v);
	while(!que.empty()){
		u = que.front();
		que.pop();
		i = u.x; j = u.y;
		if(i==(h-1)&&j==(w-1)){
			cout << "YES" << endl;
			return 0;
		}
		if(check(i-1,j)){
			if((!dist[i-1][j][s[i][j]][u.r]) && s[i-1][j]==(5-u.f)){
				dist[i-1][j][s[i][j]][u.r] = true;
				v.x = i-1; v.y = j; v.f = s[i][j]; v.r = u.r;
				que.push(v);
			}
		}
		if(check(i+1,j)){
			if((!dist[i+1][j][5-s[i][j]][u.r]) && s[i+1][j]==u.f){
				dist[i+1][j][5-s[i][j]][u.r] = true;
				v.x = i+1; v.y = j; v.f = 5-s[i][j]; v.r = u.r;
				que.push(v);
			}
		}
		if(check(i,j-1)){
			if((!dist[i][j-1][u.f][s[i][j]]) && s[i][j-1]==5-u.r){
				dist[i][j-1][u.f][s[i][j]] = true;
				v.x = i; v.y = j-1; v.f = u.f; v.r = s[i][j];
				que.push(v);
			}
		}
		if(check(i,j+1)){
			if((!dist[i][j+1][u.f][5-s[i][j]]) && s[i][j+1]==u.r){
				dist[i][j+1][u.f][5-s[i][j]] = true;
				v.x = i; v.y = j+1; v.f = u.f; v.r = 5-s[i][j];
				que.push(v);
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}



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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String[] inputs = input.readLine().split(" ");

        int A = Integer.parseInt(inputs[0]);
        int B = Integer.parseInt(inputs[1]);

        if (A == 1) {
            if (B==1) {
                System.out.println("Draw");
            } else {
                System.out.println("Alice");
            }
        } else if (B == 1) {
            System.out.println("Bob");
        } else {
            if (A==B) {
                System.out.println("Draw");
            } else if (A < B) {
                System.out.println("Bob");
            } else {
                System.out.println("Alice");
            }
        }
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int a,b,c,s,g;
int main()
{
	cin>>a>>b>>c>>s;
	if(s>=a)
	{
		s-=a;
		g+=a;
	}
	else 
	{
		cout<<s;
		return 0;
	}
	if(s>=b)s-=b;
	else
	{
		cout<<g;
		return 0;
	}
	g-=s;
	cout<<g;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.1415926535

ll dp[105][100005],pre[105][100005];

int main() 
{
    FAST;
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int j=0;j<=a[0];j++)
    {
        dp[0][j]=1;
        pre[0][j]=j+1;
    }
    for(int j=a[0]+1;j<100005;j++)
    {
        dp[0][j]=0;
        pre[0][j]=a[0]+1;
    }
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<100005;j++)
        {
            ll x=j-a[i];
            if(x<=0)
                dp[i][j]=pre[i-1][j];
            else
                dp[i][j]=(pre[i-1][j]-pre[i-1][x-1]+A)%A;
        }
        pre[i][0]=dp[i][0];
        for(int j=1;j<100005;j++)
            pre[i][j]=(pre[i][j-1]+dp[i][j])%A;
    }
    cout<<dp[n-1][k];
    return 0;
}

Measured memory_bytes: 160000
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/28 15:24:46 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	int	n, m;
	cin >> n >> m;
	vector<int>	V(n, 1);
	bitset<100005>	bs;
	bs.set(0);
	rep(i, m)
	{
		int	a, b;
		cin >> a >> b;
		a--;
		b--;
		if (bs.test(a))
		{
			bs.set(b);
			if (V.at(a) == 1)
				bs.reset(a);
		}
		V.at(a)--;
		V.at(b)++;
	}
	cout << bs.count() << endl;
}
// END

int		main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


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

#define F first
#define S second
#define pb push_back
#define ld  double
#define ll long long
#define int long long


using namespace std;

const int MAXN = 101 * 1001;


int32_t main()
{
   ios::sync_with_stdio(0);cin.tie(0);
   int i,o,t,j,l,s,z;
   cin >> i >> o >> t >> j >> l >> s >> z ;
   int ans = 0 ;
   for(int k = max(0ll,min({i,j,l})-3) ;k <= min({i,j,l}) ; k ++ ){
   ans = max(ans,o+k*3+((i-k)/2)*2+((j-k)/2)*2+((l-k)/2)*2);

   }
   cout<<ans;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  k = min(k, 60);
  vector<int> ans(n);
  for (int t = 0; t < k; ++t) {
    vector<int> tmp(n);
    for (int i = 0; i < n; ++i) {
      tmp[max(0, i - a[i])]++;
      if (i + a[i] + 1 < n) {
        tmp[i + a[i] + 1]--;
      }
    }
    for (int i = 1; i < n; ++i) {
      tmp[i] += tmp[i - 1];
    }
    a = tmp;
    ans = tmp;
  }
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << (i == n - 1 ? '\n' : ' ');
  }
  return 0;
}

Measured memory_bytes: 5612
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

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










Measured memory_bytes: 256
import heapq
N = int(input())
A = list(map(int, input().split()))
F = []
L = []
for i in range(N):
    F.append(A[i])
for i in range(2*N, 3*N):
    L.append(A[i]*(-1))
heapq.heapify(F)
heapq.heapify(L)
f_sum = sum(F)
f_list = [f_sum]
l_sum = sum(L)
l_list = [l_sum]
for i in range(N, 2*N):
    f = heapq.heappushpop(F, A[i])
    f_sum = f_sum - f + A[i]
    f_list.append(f_sum)
    l = heapq.heappushpop(L, A[-i-1]*(-1))
    l_sum = l_sum - l + A[-i-1]*(-1)
    l_list.append(l_sum)

ans = (-1) * 10 ** 15
for k in range(N+1):
    ans = max(ans, f_list[k]+l_list[-k-1])
print(ans)


Measured memory_bytes: 38292
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <bitset>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ansn() printf("%d\n",ans)
#define lansn() printf("%lld\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp(aa,bb) make_pair(aa,bb)
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007 ;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
const ll infl = 100000000000000000;//1e17
const int maxn=  3e6+20;
const int maxm = 3e2+20;
//muv[i]=(p-(p/i))*muv[p%i]%p;
int in(int &ret)
{
    char c;
    int sgn ;
    if(c=getchar(),c==EOF)return -1;
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    sgn = (c=='-')?-1:1;
    ret = (c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0');
    ret *=sgn;
    return 1;
}

int check(ll x)
{
    int res = 0;
    while(x)
    {
        res += x%10;
        x/=10;
    }
    return res;
}
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL


    ll n;
    sld(n);
    ll base = 1;
    ll now = 0;
    int cnt = 1;
    int ans = 0;
    while(1)
    {
        if( n>= cnt*base + now)ans = max(ans,check(cnt*base+now));
        else break;
        if(++cnt==10)
        {
            now += 9*base;
            cnt = 1;
            base *=10;
        }
    }
    ansn();
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();
    let mut tmp: Vec<i64> = vec![];
    tmp.push(a);
    tmp.push(b);
    tmp.push(c);
    tmp.sort();
    tmp.push(a);
    let maxv = tmp[2];
    let mid = tmp[1];
    let minv = tmp[0];

    let mut ans = 0;

    ans += maxv - mid;
    ans += (mid - minv) / 2 + ((mid - minv) % 2) * 2;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0, 0,-1,1,-1, 1,-1};
int dy[]={0,1,-1, 0,1,-1,-1, 1};

 

int main(){
    int n,m;cin >> n >> m;
    vector<bool> f(n,false);
    vector<int> a(n,0);
    int ans = 0;
    for (int i = 0; i < m; i++) {
        int p;cin >> p;
        p--;
        string s;cin >> s;
        if(s=="WA"){
            if(f[p]) continue;
            a[p]++;
        }
        else{
            if(f[p]) continue;
            f[p]=true;
            ans += a[p];
        }
    }
    int t = 0;
    for (int i = 0; i < n; i++) {
        if(f[i]) t++;
    }
    cout << t << " " << ans << endl;
    return 0;
}



Measured memory_bytes: 640
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;
template<typename T>
class UnionFind {
public:
    UnionFind(size_t  size) : data_(size, -1) {}

    bool unite(T x, T y) {
        x = root(x);
        y = root(y);

        if (x != y) {
            if (data_[y] < data_[x]) {
                std::swap(x, y);
            }
            data_[x] += data_[y];
            data_[y] = x;
        }
        return x != y;
    }

    bool isSameGroup(T x, T y) {
        return root(x) == root(y);
    }

    T root(T x) {
        return data_[x] < 0 ? x : data_[x] = root(data_[x]);
    }

    // --
    size_t size(T x) {
        return -data_[root(x)];
    }

private:
    std::vector<T> data_;
};

int main()
{
    int64_t N, K, L;
    std::cin >> N >> K >> L;

    UnionFind<int64_t> road(N);
    UnionFind<int64_t> train(N);

    for (decltype(K) i = 0; i < K; ++i) {
        int64_t p, q;
        std::cin >> p >> q;
        p--; q--;
        road.unite(p, q);
    }

    for (decltype(L) i = 0; i < L; ++i) {
        int64_t r, s;
        std::cin >> r >> s;
        r--; s--;
        train.unite(r, s);
    }

    std::map<int64_t, std::map<int64_t, int64_t>> m;

    for (int64_t i = 0; i < N; ++i) {
        m[road.root(i)][train.root(i)] ++;
    }

    for (int64_t i = 0; i < N; ++i) {
        std::cout << m[road.root(i)][train.root(i)] << " ";
    }
    std::cout << std::endl;
    return 0;
}


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

int main()
{
    int a, b;
    
    cin >> a >> b;
    
    if(a > b) { cout << a - 1 << endl; }
    else { cout << a << endl; }
    
    return 0;
}


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

typedef complex<double>P;
typedef pair<P, P> L;

int n,ans,dp[1<<16];
bool dp1[1<<16];
vector<P>v;
double EPS=1e-15,x,y;

double cross(P a, P b){return (conj(a)*b).imag();}

bool isparallel(L a,L b){
  return cross(a.first-a.second,b.first-b.second) == 0.0 ;
}

void make(int a,int b){

  memset(dp1,0,sizeof(dp1));

  vector<int>g;

  g.push_back((1<<a)+(1<<b));

  for(int i=0;i<n;i++)if(i!=a&&i!=b){
    for(int j=i+1;j<n;j++)if(j!=a&&j!=b){
      if(isparallel(L(v[a],v[b]),L(v[i],v[j]))){
        g.push_back((1<<i)+(1<<j));
      }
    }
  }

  dp1[0]=1;
  int c=0;

  for(int i=0;i<g.size();i++){
    for(int j=0;j<(1<<n);j++)if(dp1[j]){
      if((g[i]&j)==0)dp1[g[i]|j]=1;
    }
  }

  for(int i=0;i<(1<<n);i++)
    if(dp1[i]){
      int t=__builtin_popcount(i);
      t/=2;
      dp[i]=(t-1)*t/2;
    }
}
main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    v.push_back(P(x,y));
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      make(i,j);
    }
  }
  for(int i=0;i<(1<<n);i++){
    for(int j=0;j<(1<<n);j++){
      if((i&j)==0){
        dp[i|j]=max(dp[i|j],dp[i]+dp[j]);
        ans=max(ans,dp[i|j]);
      }
    }
  }
  cout<<ans<<endl;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

    // if((N==1) && (M==1)){
    //     cout << 0 << endl;
    //     return 0;
    // }
    cout << N*(N-1)/2 + M*(M-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int h,w,k;
    cin >> h >> w >> k;
    int ans[h][w] = {};
    bool yes[h] = {};
    int cnt = 1;
    int st[h];
    int gl[h];
    char s[h][w];
    REP(i,h){
        st[i] = cnt;
        REP(j,w){
            cin >> s[i][j];
            if(s[i][j] == '#'){
                yes[i] = true;
                cnt++;
            }
        }
        gl[i] = cnt - 1;
    }
    REP(i,h){
        if(yes[i]){
            cnt = st[i];
            REP(j,w){
                ans[i][j] = cnt;
                if(s[i][j] == '#' && cnt != gl[i]){
                    cnt++;
                }
            }
        }
    }
    int n = 0;
    while(!yes[n]) n++;
    REP(i,n){
        REP(j,w){
            ans[i][j] = ans[n][j];
        }
    }
    for(int i = n; i < h; i++){
        if(!yes[i]){
            REP(j,w){
                ans[i][j] = ans[i - 1][j];
            }
        }
    }
    REP(i,h){
        REP(j,w){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
  
 int main(void){
 
      int i,N;
 
      scanf("%d",&N);
 
      int K[N];
      int P[N];
      for(i=0; i<N; i++){
          scanf("%d %d",&K[i],&P[i]);
          }
 
 
      for(i=0; i<N; i++){
          if(K[i]%P[i]==0)
          printf("%d\n",P[i]);
          else
          printf("%d\n",K[i]%P[i]);
          }
      return 0;
  }

Measured memory_bytes: 596
N, Ma, Mb = map(int, input().split())
items = []
for i in range(N):
    a, b, c = map(int, input().split())
    items.append((a, b, c))

dp = [[[10**8 for cb in range(420)] for ca in range(420)]
      for i in range(N + 1)]
dp[0][0][0] = 0

for i in range(N):
    for ca in range(400):
        for cb in range(400):
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+items[i][0]][cb+items[i][1]] = \
                min(dp[i+1][ca+items[i][0]][cb+items[i][1]],
                    dp[i][ca][cb]+items[i][2])


ans = 10**8
for ca in range(1, 401):
    if ca*Mb % Ma == 0 and ca*Mb//Ma <= 400:
        ans = min(ans, dp[N][ca][ca*Mb//Ma])
if ans == 10**8:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 137844
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 1e9+7;
const int maxn = 1e5+10;
int n, d;
int a[maxn];
map<int, int> po;
LL C1[maxn], C2[maxn]; //C1--n C2--n-d-1
///
LL quick_pow (LL a, LL p, LL m) { //a^p mod m
    LL ret = 1;
    while (p) {
        if (p % 2 == 1) ret = ret * a % m;
        a = a * a % m;
        p /= 2;
    }
    return ret;
}
///
void gen_C (LL * C, int n) {
    C[0] = 1;
    for (int i = 1; i <= n; i++) {
        C[i] = C[i-1] * (n-i+1) % mod;
        C[i] = C[i] * quick_pow (i, mod-2, mod) % mod;
    }
}
int main () {
    scanf ("%d", &n);
    for (int i = 1; i <= n+1; i++) {
        scanf("%d", &a[i]);
        if (po[a[i]]) d = i-po[a[i]];
        else po[a[i]] = i;
    }
    gen_C (C1, n+1);
    gen_C (C2, n-d);
    for (int k = 1; k <= n+1; k++) {
        printf ("%I64d\n", (C1[k]-C2[k-1]+mod)%mod);
    }
}


Measured memory_bytes: 13184
from heapq import heappush, heappop
K = int(input())
INF = float("inf")
d = [INF] * K
G = [[] for i in range(K)]
for i in range(K):
    G[i].append(((i + 1) % K, 1))
    G[i].append(((10 * i) % K, 0))

d[1] = 0
que = [(1, 0)]
while que:
    v, cost = heappop(que)
    if d[v] < cost:
        continue

    for w, c in G[v]:
        if d[w] > d[v] + c:
            d[w] = d[v] + c
            heappush(que, (w, d[w]))

print(d[0] + 1)


Measured memory_bytes: 112560
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())
#define pb push_back
#define mp make_pair
#define MODP(A,B) A=(A+B)%mod
typedef pair<ll,ll> P;
typedef pair<double,double> Pd;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};


int main(){
    ll M,N; cin>>N>>M;
    vec d(N); rep(i,N) cin>>d.at(i);
    ll SUM=0;
    rep(i,N) SUM+=d.at(i);
    sort(ALL(d));
    reverse(ALL(d));
    ll K=(SUM-1)/(4*M);
    if(K<d.at(M-1)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
s = [INT() for _ in range(N)]

ans = sum(s)
if ans%10:
	print(ans)
	sys.exit()
for x in sorted(s):
	if (ans - x) % 10:
		print(ans-x)
		break
else:
	print(0)


Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,m,n) for(ll i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back












int main(){

    ll n;
    cin>>n;

    vector<pair<ll,ll>> data(n);

    rep(i,n){
        ll x,y;
        cin>>x>>y;
        data.at(i)=make_pair(x,y);
    }

    vector<ll> sum(n);

    rep(i,n){
        sum.at(i)=data.at(i).first+data.at(i).second;
    }

    vector<ll> sub(n);

    rep(i,n){
        sub.at(i)=data.at(i).first-data.at(i).second;
    }

    sort(ALL(sum));
    sort(ALL(sub));

    ll answer=max((sum.at(n-1)-sum.at(0)),(sub.at(n-1)-sub.at(0)));

    cout<<answer<<endl;


















}

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

int main(void){
  ll S;
  int s;
  cin >> S;
  int min = 1000;
  while(S / 100 != 0){
    s = S%1000;
    if(min > abs(s - 753)) min = abs(s - 753);
    S/=10;
  }
  cout << min << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
f = sys.stdin


while True:
    n = int(f.readline())
    if n ==0:
        break
    m, star, d = [int(f.readline()) for _ in range(3)]
    lines = [f.readline().strip() for _ in range(d)]
    lots = [None for j in range(d + 1)]
    lots[0] = [i + 1 for i in range(n)]
    for i, line in enumerate(lines):
        lots[i + 1] = lots[i][:]
        for j, c in enumerate(line):
            if c == '1':
                lots[i + 1][j], lots[i + 1][j + 1] = lots[i + 1][j + 1], lots[i + 1][j]
    star = lots[-1][star - 1]
    if m == star:
        print(0)
        continue
    for i, lot in enumerate(lots):
        index_min = min(lot.index(m), lot.index(star))
        index_max = max(lot.index(m), lot.index(star))
        if i and index_max - index_min == 1:
            line = lines[i - 1]
            if (index_min == 0 or line[index_min - 1] == '0') and  line[index_min] == '0' and (index_max == n - 1 or  line[index_max] == '0' ):
                print(i, min(lot.index(m), lot.index(star)) + 1)
                break
        if i == len(lots) - 1:
            print(1)

Measured memory_bytes: 6772
row = input().split()
s = list(row[0])
Flag = 0
count = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'A':
        Flag = 1
    if s[i] == 'Z' and Flag == 1:
        ans = count

    if Flag == 1:
        count += 1

print(ans+1)

Measured memory_bytes: 4840
/* 
/*-----------------------------------------------*/
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long int ll;
typedef vector<ll> vll;
/*-----------------------------------------------*/
// #define DBGMODE
#ifdef DBGMODE
	#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
	#define debug(...)
#endif
/*-----------------------------------------------*/
int N, Q, S[100010], l, r, ans;
char str[100010];
/*-----------------------------------------------*/
int main() {
	#ifdef DBGMODE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	memset(S, 0, sizeof S);
	scanf("%d%d", &N, &Q);
	scanf("%s", str);
	for (int i = 0; i < N - 1; i++) 
		if (str[i] == 'A' && str[i + 1] == 'C')
			S[i]++;
	for (int i = 1; i < N; i++) S[i] += S[i - 1];
	while (Q--) {
		scanf("%d%d", &l, &r);
		l--; r--;
		ans = 0;
		if (r > 0) ans += S[r - 1];
		if (l > 0) ans -= S[l - 1];
		printf("%d\n", ans);
	}

}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k;
  cin>>n>>k;
  
  set<int> st;
  for(int i=0;i<k;i++){
    int d;
    cin>>d;
    for(int j=0;j<d;j++){
      int a;
      cin>>a;
      st.insert(a);
    }
  }
  cout<<n-st.size();
}

Measured memory_bytes: 3604
import sys
import itertools

input = sys.stdin.readline

def main():
    a = b = 0
    n = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))
    d = [1,2,3,4,5,6,7,8,9]

    prm = list(itertools.permutations(d[:n], n))

    a = prm.index(p) + 1
    b = prm.index(q) + 1

    print(abs(a-b))

if __name__ == '__main__':
    main()

Measured memory_bytes: 8052
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define in(x) scanf("%d",&x)
#define inn(x,y) scanf("%d%d",&x,&y)
#define innn(x,y,z) scanf("%d%d%d",&x,&y,&z)

using namespace std;
const int N=2e6+5;
const int mod=1e9+7;

ll h;
int main(){
    cin>>h;
    ll x=  log2(h)+1;
    cout<<(1LL<<x)-1;
    return 0;
}

Measured memory_bytes: 512
fun ans (a: Array<Int>): String {
  val count = a.count{it >= 1}
  if (a[8] == 0) {
    return "${count} ${count}"
  } else if (count != 1) {
    return "${count-1} ${count-1+a[8]}"
  } else {
    return "${1} ${count-1+a[8]}"
  }
}

fun main (args: Array<String>) {
  val N = readLine()!!.toInt()
  var a = readLine()!!.split(" ")
  var lis = Array(9, {0})
  var idx = 0
  for (i in 0..2800 step 400){
    lis[idx] = a.filter{i <= it.toInt()}.filter{it.toInt() < i + 400}.size
    idx++
  }
  lis[8] = a.filter{3200 <= it.toInt()}.size
  println(ans(lis))
}


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

ll vis[200][sz];
ll kp[200][sz];
ll vl[200];
ll wt[200];


ll knapsack(ll n, ll w)
{
   if(n==0 || w==0)return 0;
   if(wt[n-1]>w)return knapsack(n-1,w);

   if(vis[n][w]==1)return kp[n][w];

    vis[n][w]=1;
    return kp[n][w]=max(vl[n-1]+knapsack(n-1,w-wt[n-1]),knapsack(n-1,w));

}

int main()
{
    ll n,w,i,k;
    memset(vis,0,sizeof(vis));
    cin>>n>>w;
    for(i=0; i<n; i++)
    {
        cin>>wt[i]>>vl[i];
    }

    k=knapsack(n,w);

    cout<<k<<endl;
    return 0;

}


Measured memory_bytes: 237184
N = int(input())
dp = [0]*N
for i in range(N):
  dp[int(input())-1] = i
ans = 0
cc = 0
for i in range(N-1):
  if dp[i] < dp[i+1]:
    cc += 1
  else:
    ans = max(cc, ans)
    cc = 0
ans = max(cc, ans)
print(N-ans-1)

Measured memory_bytes: 10932
#include <bits/stdc++.h>
using namespace std;
	
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
	
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
	
class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
	
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}
	
bool solve() {
	int n; cin >> n;
	int A[n+1]; REP (i,n+1) cin >> A[i];
	int B[n]; REP (i,n) cin >> B[i];
	int ans = 0;
	REP (i,n) {
		if (B[i] <= A[i]) {
			ans+=B[i];
		} else {
			ans+=A[i];
			B[i] -= A[i];
			if (A[i+1] < B[i]) {
				ans+=A[i+1];
				A[i+1] = 0;
			} else {
				A[i+1] -= B[i];
				ans += B[i];
			}
		}
	}
	cout << ans << endl;
}
	
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

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

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

int main_() {
	string S;
	cin >> S;

	regex re(",");
	string ans = regex_replace(S, re, " ");

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


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

int main(){
    int W, H, N;
    cin >> W >> H >> N;
    int l=0, r=W, u=H, d=0;
    for (int i = 0; i < N; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) l = max(l, x);
        if (a == 2) r = min(r, x);
        if (a == 3) d = max(d, y);
        if (a == 4) u = min(u, y);
    }
    cout << max(0, (r-l))*max(0, (u-d)) << endl;
    return 0;
}

Measured memory_bytes: 256
import math
A,B,H,M = map(int, input().split())
X = H*30+M*0.5
Y = M*6
if  -180 < X - Y < 0:
  z = Y - X
elif X - Y <= -180:
  z = 360 -(Y - X)
elif 180 > X - Y >= 0:
  z = X - Y
elif X - Y >= 180:
  z = 360-(X - Y)
ans = A*A+B*B-2*A*B*math.cos(math.radians(z))
ANS = math.sqrt(ans)

print(ANS)

Measured memory_bytes: 9388
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#include<map>
#include<set>
#define LL long long
#define fr first
#define sc second
#define SX E[x].size( )
#define SY E[y].size( )
using namespace std;
typedef pair<int,int> pr;
inline pr mp(int x,int y) {return x<y?make_pair(x,y):make_pair(y,x);}
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int N=100005;
int n,m,f[N];
map<pr,int>H;set<int>E[N];queue<pr>q;
inline int find(int x) {return f[x]==x?x:f[x]=find(f[x]);}
int main( )
{
  int i,x,y,k;pr o;
  n=read( );m=2*n-2;
  for(i=1;i<=m;i++)
    {
      x=read( );y=read( );
      E[x].insert(y);E[y].insert(x);
      if((++H[o=mp(x,y)])==2) q.push(o);
    }
  for(i=1;i<=n;i++) f[i]=i;
  set<int>::iterator it,ed;
  while(!q.empty( ))
    {
      o=q.front( );q.pop( );
      x=find(o.fr);y=find(o.sc);
      if(x==y) continue;n--;
      if(SX>SY) swap(x,y);
      for(it=E[x].begin( ),ed=E[x].end( );it!=ed;it++)
	{
	  k=find(*it);
	  if(k==y) continue;
	  else E[y].insert(k);
	  --H[mp(k,x)];
	  if((++H[o=mp(k,y)])==2) q.push(o);
	}
      f[x]=y;
    }
  puts(n==1?"YES":"NO");
  return 0;
}


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

// @@ !! LIM(UnionFind)
// --> UnionFind
// ---- inserted library file UnionFind.cc

class UnionFind {
protected:
  int size;
  vector<int> _leader;
  vector<int> _rank;
  vector<int> _gsize;
  unordered_map<int, vector<int>> _groups;
  
public:
  UnionFind(int s);
  int leader(int i);
  int merge(int i, int j);
  int groupSize(int i);
  const unordered_map<int, vector<int>>& groups();
  const vector<int>& group(int i);
};

UnionFind::UnionFind(int s) {
  size = s;
  _leader = vector<int>(size);
  for (int i = 0; i < size; i++) { _leader.at(i) = i; }
  _rank = vector<int>(size, 1);
  _gsize = vector<int>(size, 1);
}

int UnionFind::leader(int i) {
  int cur = i;
  int nxt = _leader.at(cur);
  vector<int> seen;
  while (cur != nxt) {
    seen.push_back(cur);
    cur = nxt;
    nxt = _leader.at(cur);
  }
  for (auto j : seen) _leader.at(j) = cur;
  return cur;
}

int UnionFind::merge(int i0, int j0) {
  if (!_groups.empty()) {
    cerr << "merge() cannot be called after group() or groups()." << endl;
    exit(1);
  }
  int li = leader(i0);
  int lj = leader(j0);
  if (li == lj) return li;
  int ri = _rank.at(li);
  int rj = _rank.at(lj);
  int rep = li;
  int other = lj;
  if      (ri <  rj) swap(rep, other);
  else if (ri == rj) _rank.at(rep)++;
  _leader.at(other) = rep;
  _gsize.at(rep) += _gsize.at(other);
  return rep;
}

int UnionFind::groupSize(int i) {
  return _gsize.at(leader(i));
}

const unordered_map<int, vector<int>>& UnionFind::groups() {
  if (_groups.empty()) {
    for (int i = 0; i < size; i++) _groups[leader(i)].push_back(i);
  }
  return _groups;  
}

const vector<int>& UnionFind::group(int i) { return groups().at(leader(i)); }



// ---- end UnionFind.cc
// @@ !! LIM  -- end mark --

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, M; cin >> N >> M;
  if (M == N - 1) {
    cout << "0\n";
    return 0;
  }
  if (N > 2 * M + 2) {
    cout << "Impossible\n";
    return 0;
  }

  vector<ll> cost(N);
  for (ll i = 0; i < N; i++) cin >> cost.at(i);
  UnionFind uf(N);
  for (ll i = 0; i < M; i++) {
    ll x, y; cin >> x >> y;
    uf.merge(x, y);
  }
  vector<ll> rest;
  ll sum = 0;
  for (ll i = 0; i < N; i++) {
    if (uf.leader(i) == i) {
      vector<ll> v;
      for (ll x : uf.group(i)) v.push_back(cost.at(x));
      sort(v.begin(), v.end());
      sum += v.at(0);
      for (ll j = 1; j < (ll)v.size(); j++) rest.push_back(v.at(j));
    }
  }
  sort(rest.begin(), rest.end());
  for (ll i = 0; i < N - M - 2; i++) sum += rest.at(i);
  cout << sum << endl;

  return 0;
}



Measured memory_bytes: 10604
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.ES", "r", stdin );
	string str = "";
	map<string, int> words; words.clear();
	int max_len = 0;
	int max_freq = 0;
	while (getline (cin, str ) ){

		int n = str.length();
		rep (i, n ){
			if (isalpha (str[i] ) )
				str[i] = tolower(str[i] );
		} // end rep

		string s = "";
		stringstream ss (str );
		while (ss >> s ){
			max_len = max (max_len, (int)s.length() );
			words[s]++;
			max_freq = max (max_freq, words[s] );
		} // end while
	} // end while
	map<string,int>::iterator it = words.begin();
	string res_f = "", res_l = "";
	for (; it != words.end(); it++ ){
		string w = (*it).first;
		int cnt = (*it).second;
		if (cnt == max_freq ){
			res_f = w;
		} // end if
		if (w.length() == max_len ){
			res_l = w;
		} // end if
	} // end for
	cout << res_f << ' ' << res_l << endl;

	return 0;
}

Measured memory_bytes: 1208
def main():

    N, X = map(int, input().split())
    L = list(map(int, input().split()))
    D = [0] * (N + 1)
    D[0] = 0
    cnt = 0
    for i in range(N):
        D[i + 1] = D[i] + L[i]
    for i in range(N + 1):
        if D[i] <= X:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  
  string s;
  cin >>s;
  int a=0,z =0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
      a =i;
      break;
    }
  }
  for(int i=s.size()-1 ; i >=0 ; i--){
    if(s[i]=='Z'){
      z =i;
      break;
    }
  }
  cout << z-a+1<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);
using namespace std;
ll n,o=1,ans;
int main()
{
    cin>>n;
    n--;
    for(ll i=1;i*i<=n;i++)
    {
        if(n%i)continue;
        ans++;
        if(n/i!=i)ans++;
    }
    n++;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i)continue;
        ll x=n;
        while(x%i==0)x/=i;
        if(x%i==1){ans++;}
        i=n/i;
        if(i==n/i)continue;
        x=n;
        while(x%i==0)x/=i;
        if(x%i==1){ans++;}
        i=n/i;
    }
    cout<<ans;
}



Measured memory_bytes: 256