akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
    }
    // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
    // 12%13 + 11%12 + 10%11 + 9%10 + 8%9 + 7%8 + 6%7 + 5%6 + 4%5 + 3%4 + 2%3 + 1%2 + 13%1
    println!("{}", (n - 1 + 1) * (n - 1) / 2);
}


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

int main(){
  int P,Q,R;
  cin >> P >> Q >> R;
  
  vector<int> V(3);
  
  V.at(0) = P;
  V.at(1) = Q;
  V.at(2) = R;
  
  sort(V.begin(),V.end());
  
  cout << P + Q + R - V.at(2) << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << (a+b)*c/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    for(ll i = 1; i <= 9; ++i){
        for(ll j = i; j <= 9; ++j){
            if(i * j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


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

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    int ans1 = a.back();

    int tmp = 0;
    int ans2 =0;
    rep(i,a.size()-1) {
        if (min(ans1-a[i],a[i]-0)>tmp) {
            tmp = min(ans1-a[i],a[i]-0);
            ans2 = a[i];
        }
    }
    cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 640
import collections

n = int(input())
a_list = [int(num) for num in input().split(" ")]
c_dict = collections.Counter(a_list)

total_comb = 0
for i in c_dict:
    i_count = c_dict[i]
    total_comb += int(i_count*(i_count-1)/2)
for k in range(n):
    except_num = a_list[k]
    print(total_comb - (c_dict[except_num]-1))


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

using namespace std;

template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec){
    os << "[";
    for(int i=0;i<vec.size();i++){
        os << (i==0?"":" ") << vec[i];
    }
    os <<  "]";
    return os;
}


int main(){
    string a;
    cin >> a;
    long long n = a.size();
    vector<long long> chcnt(26, 0);

    for(int i=0;i<n;i++){
        chcnt[a[i]-'a']++;
    }
    long long ans = n * (n - 1) / 2;
    for(int i=0;i<26;i++){
        long long t = chcnt[i] * (chcnt[i]-1) / 2;
        ans -= t;
    }
    cout << ans+1 << endl;
    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin >> s >> t;
  int32 n = s.size();
  REP(i,n){
    bool flg = true;
    REP(j,n){
      if(s[j] != t[(i+j)%n]){
        flg = false;
        break;
      }
    }
    if(flg){
      Yes(true);
      return 0;
    }
  }
  Yes(false);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
double na,nb;
string s;
int pre[100010],num[100010],f[100010],x[100010],ans[100010];
int n,m,k;
int findd(int x)
{
    if(pre[x]!=x)pre[x]=findd(pre[x]);
    return pre[x];
}
void sum(int a,int b)
{
    a=findd(a);b=findd(b);
    if(a!=b)
    {
        pre[a]=b;
    }
}
int main()
{
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)pre[i]=i;
    for(int i=0;i<m;i++)
    {
        int a,b;cin>>a>>b;
        f[a]++;f[b]++;
        sum(a,b);
    }
    for(int i=1;i<=n;i++)
        x[findd(i)]++;
    for(int i=1;i<=n;i++)
        ans[i]=x[pre[i]]-f[i]-1;
    for(int i=0;i<k;i++)
    {
        int a,b;cin>>a>>b;
        if(pre[a]==pre[b])
        {
            ans[a]--;ans[b]--;
        }
    }
    for(int i=1;i<=n;i++)cout<<ans[i]<<' ';
    return 0;
}


Measured memory_bytes: 2688
#include <iostream>

using namespace std;

using ll = long long;

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

typedef pair<int, int> P;

const int MOD = (int) 1e9 + 7;

template<class T>
bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}

template<class T>
bool chmin(T &a, const T &b) {
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a, b;
	cin >> a >> b;
	
	if (abs(a - b) > 16 - (a + b)) {
		cout << ":(" << endl;
	} else {
		cout << "Yay!" << endl;
	}
	
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  sort(a.rbegin(),  a.rend());
  int alice, b;
  alice = 0;
  b = 0;
  REP(i, n){
    if (i % 2 == 0) alice += a[i];
    else b += a[i];
  }
  cout << alice - b << endl;
  return 0;
}



Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main(void){
   int a,b;
   cin>>a;
   b=a%7;
   if(b==2){cout<<"sat"<<endl;}
   if(b==3){cout<<"sun"<<endl;}
   if(b==4){cout<<"mon"<<endl;}
   if(b==5){cout<<"tue"<<endl;}
   if(b==6){cout<<"wed"<<endl;}
   if(b==0){cout<<"thu"<<endl;}
   if(b==1){cout<<"fri"<<endl;}
}


Measured memory_bytes: 3100
<?php   

list($n, $m) = explode(' ',(fgets(STDIN)));  
$a = explode(' ', trim(fgets(STDIN)));  
rsort($a);  
$count = 0;  
$sum = 0;  
//総得票  
foreach ($a as $value) {  
// code...  
$sum += $value;  
}  

for ($i=0; $i<$m ; $i++) {  
// code...  
if ($a[$i] >= $sum/ (4*$m)) {  
// code...  
$count ++;  

}  
}  
if($count >= $m){  
echo 'Yes';  
}else{  
echo 'No';  
}  

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

typedef long long ll;
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define FORD(i, a, b) for (ll i = a; i >= b; i--)

int a, b;
void ReadInput(){
    cin>>a>>b;
}

void SOL(){
	if(a>b || a==b)
    {
        FOR(i, 1, a)
            cout<<b;
        return;
    }
    if(a<b)
    {
      	FOR(i, 1, b)
            cout<<a;
        return;
    }	
}
int main() 
{
   ReadInput();
   SOL();
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		ArrayDeque<Integer> cars = new ArrayDeque<Integer>();
		while (scanner.hasNext()) {
			int number = scanner.nextInt();
			if (number == 0) System.out.println(cars.pollLast());
			else cars.addLast(number);
		}
	}
}

Measured memory_bytes: 26084
n=int(input())
x=input()
cntm=0
cntp=0
fn=0
xi=[0]*n
ans=[0]*n
for i in range(n):
    if x[i]=="1":
        fn+=1
for i in reversed(range(n)):
    if x[i]=="1":
        cntp+=pow(2,n-i-1,fn+1)
        cntp%=fn+1
        if fn>1:
            cntm+=pow(2,n-i-1,fn-1)
            cntm%=fn-1
for i in reversed(range(n)):
    if x[i]=="1":
        if fn>1:
            xi[i]=(cntm-pow(2,n-i-1,fn-1))%(fn-1)
            ans[i]+=1
    else:
        xi[i]=(cntp+pow(2,n-i-1,fn+1))%(fn+1)
        ans[i]+=1
#print(xi)
for i in range(n):
    num=xi[i]
    while num>0:
        cnt=0
        for j in range(31):
            if (num>>j)&1:
                cnt+=1
        num%=cnt
        ans[i]+=1
    print(ans[i])

Measured memory_bytes: 81620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
void print(ll x){
	char y=x%10+'0';
	if(x>=10)print(x/10);
	putchar(y);
}
ll n,x,ans,a[100005]; 
int main(){
	n=read();
	for(int i=0;i<=n;i++)
		a[i]=read();
	for(int i=0;i<n;i++){
		x=read();
		if(a[i]<=x){
			ans+=a[i],x-=a[i];
			if(a[i+1]>=x)ans+=x,a[i+1]-=x;
			else ans+=a[i+1],a[i+1]=0;
		}
		else ans+=x;
	}
	print(ans);
	return 0;
}

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

array = input()
array = array.split()
for i in range(len(array)):
    array[i] = float(array[i])

W,H,x,y,r = array[0],array[1],array[2],array[3],array[4]

if x-r >= 0 and y+r <= H and x+r <= W and y-r >= 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 7504
import copy
h, w, k = map(int, input().split())

c = list()
judge = list()
for a in range(h):
    c.append(list(input()))
    judge.append([False]*w)

red = '*'

exist = False

ans = list()

for i in range(2 ** h):
    tmp = copy.deepcopy(c)
    for j in range(h):
        if (i >> j) & 1:
            tmp[j] = [red]*w
    ans.append(tmp)

result = list()

length = len(ans)
for now in range(length):
    for i in range(2**w):
        tmp = copy.deepcopy(ans[now])
        for j in range(w):
            if (i >> j) & 1:
                tmp_length = len(tmp)
                for z in range(tmp_length):
                    tmp[z][j] = red
        result.append(tmp)

result_length = len(result)

num = 0

for a in range(result_length):
    red_count = 0
    for b in range(h):
        red_count += result[a][b].count('#')
    if k == red_count:
        num += 1

print(num)


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int n;
string str;
int isEdge[222222];
int cou[3];
int pointer[222222];
int ans[222222];
bool used[222222];

int main(){

	REP(i,222222)pointer[i] = i;

	cin >> n;n *= 2;

	cin >> str;
	str = '1' + str + '1';

	REP(i,n){
		int tmp = 0;
		isEdge[i] = ((str[i] == '1') + (str[i+1] == '1'));
		cou[isEdge[i]]++;
	}

	if(cou[2] % 2){
		cout << "No" << endl;
		return 0;
	}

	int nowNum = 1;

	if(cou[2] % 4 == 2){
		vector<vector<int>> paths;
		vector<int> path;
		int pla = 0;
		REP(i,n){
			if(isEdge[n-1-i] == 1){
				pla = n-1-i;
				break;
			}
		}
		for(int i = 0;i < n;i++){
			int place = (i + pla) % (n);
			if(isEdge[place] == 0){

			}
			else if(isEdge[place] == 1){
				path.PB(place);
				if(path.size() > 1){
					if(path.size() > 2){
						paths.PB(path);
					}
					path.clear();
				}
			}
			else{
				path.PB(place);
			}
		}
		if(paths.size() <= 1){
			cout << "No" << endl;
			return 0;
		}

		ans[paths[0][1]] = 1;
		ans[paths[1][1]] = 1;
		nowNum++;
		isEdge[paths[0][1]] = -1;
		isEdge[paths[1][1]] = -1;
		swap(pointer[paths[0][0]],pointer[paths[1][0]]);
	}

	vector<int> seica;
	REP(i,n){
		if(isEdge[i] == 1)seica.PB(i);
		if(seica.size() == 2){
			ans[pointer[seica[0]]] = nowNum;
			ans[pointer[seica[1]]] = nowNum;
			nowNum++;
			seica.clear();
		}
	}

	REP(i,n){
		if(isEdge[pointer[i]] == 2)seica.PB(i);
		if(seica.size() == 4){
			ans[seica[0]] = nowNum;
			ans[seica[1]] = nowNum + 1;
			ans[seica[2]] = nowNum;
			ans[seica[3]] = nowNum + 1;
			nowNum+=2;
			seica.clear();
		}
	}

	REP(i,n){
		if(isEdge[i] == 0)seica.PB(i);
		if(seica.size() == 2){
			ans[seica[0]] = nowNum;
			ans[seica[1]] = nowNum;
			nowNum++;
			seica.clear();
		}
	}

	cout << "Yes" << endl;
	REP(i,n)cout << ans[i] << ' ';cout << endl;

	return 0;
}


Measured memory_bytes: 4856
N =int(input())
# スペース区切りの整数の入力
SP=[]
for i in range(N):
    nakami=input().split()
    SP.append([nakami[0],nakami[1],i])

SP.sort(key=lambda x:(x[0],-int(x[1])))

for x in SP:
    print(x[2]+1)



Measured memory_bytes: 3060
#include <stdio.h>


typedef struct complex{
    int re;
    int im;
}complex;

complex mul_comp(complex vec1, complex vec2){
    complex new_vec;
    new_vec.re = vec1.re * vec2.re - vec1.im * vec2.im;
    new_vec.im = vec1.re * vec2.im + vec2.re * vec1.im;
    return new_vec;
}

complex sub_comp(complex vec1, complex vec2){
    complex new_vec;
    new_vec.re = vec2.re - vec1.re;
    new_vec.im = vec2.im - vec1.im;
    return new_vec;
}

int main(void){
    int vec1_re, vec1_im, vec2_re, vec2_im;
    complex vec1, vec2, vec3, vec4, routin = {0, 1};
    scanf("%d %d %d %d", &vec1_re, &vec1_im, &vec2_re, &vec2_im);
    vec1.re = vec1_re;
    vec1.im = vec1_im;
    vec2.re = vec2_re;
    vec2.im = vec2_im;
    vec4 = mul_comp(sub_comp(vec1, vec2), routin);
    vec4.re = vec4.re + vec1.re;
    vec4.im = vec4.im + vec1.im;
    vec3 = mul_comp(sub_comp(vec4, vec1), routin);
    vec3.re = vec3.re + vec4.re;
    vec3.im = vec3.im + vec4.im;
    printf("%d %d %d %d\n", vec3.re, vec3.im, vec4.re, vec4.im);
    return 0;
}

Measured memory_bytes: 1660
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] p=new int[44];
		long[] a1=new long[n];
		for(int i = 0; i<n; i++){
			long a= sc.nextLong();
			a1[i]=a;
			int count=0;
			while(a>0){
				if((a & 1)==1){
					p[count]++;
				}
				a>>=1;
				count++;
			}
		}
		long[] pow=new long[44];
		pow[0]=1;
		for(int i = 1; i<44; i++){
			pow[i]=pow[i-1]*2;
		}
		long ans=0;
		for(int i = 43; i>=0; i--){
			if(p[i]*2<=n){
				if(ans+pow[i]<=k){
					ans+=pow[i];
				}
			}
		}
		long an=0;
		for(int i = 0; i<n; i++){
			an+=ans^a1[i];
		}
		System.out.println(an);
	}
}


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

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

    int T[N+1], X[N+1], Y[N+1];
    T[0] = 0;
    X[0] = 0;
    Y[0] = 0;

    for (int i=1; i<=N; i++) {
        cin >> T[i] >> X[i] >> Y[i];
    }

    string ans = "Yes";
    int dist, dt;
    for (int i=1; i<=N; i++) {
        dist = abs(X[i] - X[i-1]) + abs(Y[i] - Y[i-1]);
        dt = T[i] - T[i-1];
        if (dist > dt) ans = "No";
        if (dist < dt && dist%2 != dt%2) ans = "No";
    }

    cout << ans << endl; 

    return 0;
}



Measured memory_bytes: 1408
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
		ll N=0;

		cin >> N;

		cout << N*(N+1)/2;

		return 0;
    }

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

typedef long long ll;

int main(void)
{
    //freopen("input.txt", "r", stdin);

    ll n;
    cin>>n;


        n=n%10;

    if(n == 2 || n==4 || n==5 || n==7 || n==9)
        cout<<"hon\n";
    else if(n == 0 || n == 1 || n == 6 || n == 8)
        cout<<"pon\n";
    else if(n == 3)
        cout<<"bon\n";

    return 0;
}


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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

const int INF=1001001001;
int dp[2][9][9][2];
string S;
void solve(){
    rep(i,S.size())S[i]--;
    fill_n(***dp,2*9*9*2,INF);
    rep(i,9)rep(j,9)rep(k,2){
        if(i%3<=j%3)dp[0][i][j][k]=0;
    }

    rep(t,S.size()){
        int h=S[t]-'0';
        rep(i,9)rep(j,9)rep(k,2){
            if(i%3<=h%3){
                chmin(dp[(t+1)&1][i][h][1],dp[t&1][i][j][k]+(k==1));
            }
            if(h%3<=j%3){
                chmin(dp[(t+1)&1][h][j][0],dp[t&1][i][j][k]+(k==0));
            }
            dp[t&1][i][j][k]=INF;
        }
    }
    int ans=INF;
    rep(i,9)rep(j,9)rep(k,2)chmin(ans,dp[S.size()&1][i][j][k]);
    cout<<ans<<endl;
}

signed main(){
    while(cin>>S,S!="#")solve();
    return 0;
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
#define FOR(i,j,k)  for(int i=(j);i<=(k);i++)
using namespace std;
int f[3][101],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&f[i][j]);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			f[i][j]+=max(f[i-1][j],f[i][j-1]);
	printf("%d\n",f[2][n]);
	return 0;
}


Measured memory_bytes: 256
S = str(input())
ls = len(S)
odd_list = []
result = ""

while ls > 0:
    ls -= 1
    if ls % 2 == 0:
        odd_list.append(ls)
odd_list = sorted(odd_list)
# print(odd_list)

for i in odd_list:
    result = result + S[i]
print(result)

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

int main(){
int n,W;
cin>>n>>W;
  int wt[n],v[n];
  for(int i=0;i<n;i++)cin>>wt[i]>>v[i];
  
  ll k[n+1][W+1];
  
  for(int i=0;i<=n;i++)
    for(int w=0;w<=W;w++){
      if(w==0 || i==0)k[i][w]=0;
      else if(wt[i-1]<=w)k[i][w]=max(k[i-1][w],k[i-1][w-wt[i-1]]+v[i-1]);
      else k[i][w]=k[i-1][w];
    }
  cout<<k[n][W]<<endl;
  return 0;
}

Measured memory_bytes: 79104
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println( N*A <= B? N*A: B );
        
      }
     


}



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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
int num[NMAX];
int main(int argc, char const *argv[])
{
	int n;
	ll ans = 0;
	scanf("%d",&n);
	for(register int i = 1;i <= n;i++)
	{
		int val;
		scanf("%d",&val);
		ans += 1ll*val;
		num[val]++;
	}
	scanf("%d",&n);
	while(n--)
	{
		int b,c;
		scanf("%d%d",&b,&c);
		num[c] += num[b];
		ans += 1ll*num[b]*(c - b);
		num[b] = 0;
		printf("%lld\n",ans );
	}
	return 0;
}

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

using namespace std;

int main(){
        int h, w, d, a, q, l, r;
        int px[90001], py[90001];
        int dp[90001];
        cin>>h>>w>>d;
        for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                        cin>>a;
                        px[a]=i, py[a]=j;
                }
        }
        for(int i=0;i<90001;i++){
                dp[i]=0;
        }
        for(int i=d+1;i<=h*w;i++){
                dp[i]=dp[i-d]+abs(px[i]-px[i-d])+abs(py[i]-py[i-d]);
        }
        cin>>q;
        for(int i=0;i<q;i++){
                cin>>l>>r;
                cout<<dp[r]-dp[l]<<endl;
        }
        return 0;
}


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

char s[5];
int h,w,d;

int main(){
    int i,j,x,y;
	s[0]='R',s[1]='Y',s[2]='G',s[3]='B';
    scanf("%d%d%d",&h,&w,&d);
    for(i=0;i<h;++i){
    	for(j=0;j<w;++j){
    		x=((w+i+j)/d)&1;
    		y=((w+i-j)/d)&1;
    		printf("%c",s[x*2+y]);
    	}
    	puts("");
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb; 
typedef long long ll;  
typedef double db;                         
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = (1 << 16) + 48, mod = 1e9 + 7, maxn = 102;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;



int n, a[30][30], cost[N], dp[N];


void precalc () {
	forn (mask, 0, (1 << n) - 1) {
		vi v;
		forn (i, 0, n - 1)
			if (mask & (1 << i))
				v.pb(i);
		
		forn (i, 0, sz(v) - 1)
			forn (j, i + 1, sz(v) - 1)
				cost[mask] += a[v[i]][v[j]];
	}		
}



main () {
	cin >> n;
	forn (i, 0, n - 1)
		forn (j, 0, n - 1)
			cin >> a[i][j];

	
	precalc();
	dp[0] = 0;
	forn (mask, 1, (1 << n) - 1) {
		dp[mask] = cost[mask];
		for (int nMask = mask; nMask; nMask = ((nMask - 1) & mask))  
			dp[mask] = max(dp[mask], dp[nMask] + dp[nMask ^ mask]);    
		
	}


	cout << dp[(1 << n) - 1] << endl;
} 

Measured memory_bytes: 1280
// CppPractice.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main()
{
	int a, b;
	int ans = 0;
	int tmp = 0;
	cin >> a >> b;
	tmp = 1;
	while (tmp < b) {
		tmp -= 1;
		tmp += a;
		ans += 1;
	}

	cout << ans << endl;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
@s=Array.new(1000010)
@a=Array.new(1000010,0)
@e97=1000000007
n,m=gets.split.map(&:to_i)
for i in 1..m do
    p = gets.to_i
    @a[p] = 1
end

@s[0] = 1

for i in 1..n do
    if @a[i]==1
        @s[i] = 0
    else
        s1 = @s[i - 1]
        s2 = i >= 2 ? @s[i - 2] : 0
        @s[i] = (s1 + s2) % @e97
    end
end


p @s[n]


Measured memory_bytes: 17660
n = int(input())
l = [int(i) for i in input().split()]

ct = 0
m = 0
for i in range(1,n):
    if l[i] <= l[i-1]:
        ct += 1
    else:
        m = max(m,ct)
        ct = 0

print(max(m,ct))
    

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

using namespace std;
using Graph = vector<vector<int>>;
int main(){

long long x,ans=0;
cin >> x;

while(x>=500){
    ans += (x/500)*1000;
    x = x-(x/500)*500;
    
}
while(x>=5){
    ans += (x/5)*5;
    x = x-(x/5)*5;
    
}
cout << ans;
return 0;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
	int p,q,r;
	cin>>p>>q>>r;
	if(p>q)swap(p,q);
	if(p>r)swap(p,r);
	if(q>r)swap(q,r);
	cout<<p+q; 
	return 0;
}

Measured memory_bytes: 256
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>*/
#include <bits/stdc++.h>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

template<int SZ>
class SegMin {
	public:
		pii seg[2*SZ];

		SegMin() {
			memset(seg,0,sizeof seg);	
		}
		
		void upd(int p, pii value) {  // set value at position p
			for (seg[p += SZ] = value; p > 1; p >>= 1) seg[p>>1] = min(seg[p],seg[p^1]);
		}
		
		void build() {
			for (int i = SZ-1; i > 0; --i) seg[i] = min(seg[2*i],seg[2*i+1]);	
		}
		
		pii query(int l, int r) {  // minimum on interval [l, r)
			pii res = {MOD,MOD};
			for (l += SZ, r += SZ; l < r; l >>= 1, r >>= 1) {
				if (l&1) res = min(res,seg[l++]);
				if (r&1) res = min(res,seg[--r]);
			}
			return res;
		}
};

int N;
vi p;
SegMin<1<<17> e,o;
set<pair<pii,pii>> bes;

void init() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> N; p.resize(N);
	F0R(i,N) cin >> p[i];
	for (int i = 0; i < N; i += 2) e.upd(i/2,{p[i],i}); // OK
	for (int i = 1; i < N; i += 2) o.upd(i/2,{p[i],i});
}

void ins(int x, int y) {
    if (x > y) return;
    if (x % 2 == 0) bes.insert({e.query(x/2,y/2+1),{x,y}});  // OK
    else bes.insert({o.query(x/2,y/2),{x,y}});
}

void solve() {
    pair<pii,pii> z = *bes.begin(); bes.erase(bes.begin());
    pii b1 = z.s, b2;
    b2.f = z.f.s; // index of min
    if (z.s.f % 2 == 0) b2.s = o.query(z.f.s/2,z.s.s/2+1).s; // check
    else b2.s = e.query(z.f.s/2+1,z.s.s/2+1).s;
    
    cout << p[b2.f] << " " << p[b2.s] << " ";
    ins(b1.f,b2.f-1);
    ins(b2.f+1,b2.s-1);
    ins(b2.s+1,b1.s);
}

int main() {
    init();
	ins(0,N-1);
	while (bes.size()) solve();
}

Measured memory_bytes: 8960
def main():
    N = int(input())
    P = [int(x) for x in input().split()]
    count = 1
    num = P[0]
    for i in range(1, N):
        if num >= P[i]:
            count += 1
            num = P[i]
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 25768
import sys
from collections import defaultdict

n,k = map(int, input().split())
di = defaultdict(int)
for i in range(n):
    a, b = map(int, input().split())
    di[a] += b

cnt = 0
for x in sorted(di.keys()):
    cnt += di[x]
    if cnt >= k:
        print(x)
        sys.exit()


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

class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> parent;
    UnionFind(int N){
        parent = vector<int>(N,-1);
    }
    int root(int A){
        if(parent[A] < 0) return A;
        return parent[A]=root(parent[A]);
    }
    int size(int A){
        return -parent[root(A)];
    }
    bool unite(int A, int B) {
        A = root(A);
        B = root(B);
        if(A == B) return false; 
        if(size(A) < size(B)) swap(A,B);
        parent[A] += parent[B];
        parent[B] = A;
        return true;
    }
    bool same(int A, int B){
        return root(A)==root(B);
    } 
};

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    int n,m,q;
    cin>>n>>m>>q;
    array<int,3> a[m];
    UnionFind uni(n+5);
    for(int i=0;i<m;i++){
        int d,l,r;
        cin>>d>>l>>r;
        a[i] = {d,l,r};
    }
    sort(a,a+m);
    int now = 0;
    bool ans[q]={};
    array<int,4> b[q]={};
    for(int i=0;i<q;i++){
        int d,s,t;
        cin>>d>>s>>t;
        b[i] = {d,s,t,i};
    }
    sort(b,b+q);
    for(int i=0;i<q;i++){
        while(now < m && a[now][0] < b[i][0]){
            int l=a[now][1], r=a[now][2];
            int low=l-1, up=r+1;
            while(up-low>1){
                int mid = (up+low)/2;
                if(uni.same(mid,l)){
                   low = mid; 
                }
                else up = mid;
            }
            l = up;
            low = l-1,up=r+1;
            while(up-low>1){
                int mid = (up+low)/2;
                if(uni.same(r,mid)){
                    up=mid;
                }
                else low=mid;
            }
            r=low;
            //cerr << l << " " <<r << endl;
            for(int k=l;k<=min(r+1,a[now][2]);k++){
                uni.unite(a[now][1],k);
            }
            now++;
        }
        if(b[i][1] >= b[i][2]) ans[b[i][3]] = 1;
        if(uni.same(b[i][1],b[i][2])) ans[b[i][3]] = 1;
    }
    for(int i=0;i<q;i++){
        if(ans[i]){
            cout << "Yes\n";
        }
        else cout << "No\n";
    }
}


Measured memory_bytes: 5976
#include <stdio.h>

int main(void)
{
	int n,a,min=1000000,max=-1000000,i;
	long s=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		s+=a;
		min>a?min=a:0;
		max<a?max=a:0;
	}
	printf("%d %d %ld\n",min,max,s);
	return 0;
}


Measured memory_bytes: 2108
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().solver();
	}

	void solver() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		int Q = sc.nextInt();
		long[] P = new long[N];
		Arrays.fill(P, K - Q);
		for (int i = 0; i < Q; ++i) {
			int A = sc.nextInt();
			--A;
			P[A]++;
		}
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < N; ++i) {
			if (P[i] <= 0)
				pw.println("No");
			else
				pw.println("Yes");
		}
		pw.close();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 50312
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
  ll l[100010], r[100010];
  for(int i=0; i<n; i++) cin>>l[i]>>r[i];
  priority_queue<ll> quel;
  priority_queue<ll, vector<ll>, greater<ll>> quer;
  quel.push(l[0]);
  quer.push(l[0]);
  ll dl=0, dr=0, s=0;
  for(int i=1; i<n; i++){
    dl-=r[i]-l[i];
    dr+=r[i-1]-l[i-1];
    if(quel.top()+dl>l[i]){
      quel.push(l[i]-dl);
      quel.push(l[i]-dl);
      s+=(quel.top()+dl-l[i]);
      quer.push(quel.top()+dl-dr);
      quel.pop();
    }else if(quer.top()+dr<l[i]){
      quer.push(l[i]-dr);
      quer.push(l[i]-dr);
      s+=(l[i]-quer.top()-dr);
      quel.push(quer.top()+dr-dl);
      quer.pop();
    }else{
      quel.push(l[i]-dl);
      quer.push(l[i]-dr);
    }
  }
  cout<<s<<endl;
    return 0;
}


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

int main() {
	int w, h, n;
	cin >> w >> h >> n;

	int x, y, a;

	int s = 0;
	int t = 0;
	
	for (int i = 0; i < n; i++) {
		cin >> x >> y >> a;
		if (a == 1) {
			s = max(s, x);
		}
		else if (a == 2) {
			w = min(w, x);
		}
		else if (a == 3) {
			t = max(t, y);
		}
		else if (a == 4) {
			h = min(h, y);
		}

	}
	int S = (w - s) * (h - t);
	if (w < s || h < t) cout << 0 << endl;
	else cout << S << endl;

	return 0;
}

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

using namespace std;

#pragma GCC optimize("O3")
static const auto __ = [] {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  return nullptr;
}();

int solve(int N) {
  int V[N];
  for (int& v : V) {
    cin >> v;
  }
  int C[N];
  for (int& c : C) {
    cin >> c;
  }
  int ans {0};
  for (int bit {0}; bit < (1 << N); ++bit) {
    int X {0};
    int Y {0};
    for (int i {0}; i < N; ++i) {
      if (bit & (1 << i)) {
        X += V[i];
        Y += C[i];
      }
    }
    ans = max(ans, X - Y);
  }
  return ans;
}

int main(int argc, char* argv[]) {
  int N;
  cin >> N;
  cout << solve(N) << '\n';
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.List;

public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    String input = sc.nextLine();
		String result = input.equals("ABC") ? "ARC" : "ABC";
	    System.out.println(result);
	}
}


Measured memory_bytes: 35640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  cin >> a;
  vector<int> b(n);
  cin >> b;

  ll sum = 0;
  for (int i = n; i >= 0; --i) {
    int tmp = min(b[i], a[i]);
    b[i] -= tmp;
    a[i] -= tmp;
    sum += tmp;
    if (i - 1 < 0) continue;
    tmp = min(b[i - 1], a[i]);
    b[i - 1] -= tmp;
    a[i] -= tmp;
    sum += tmp;
  }
  // cout << a << endl << b << endl;
  cout << sum << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);


int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  map<string, int> mp;

  REP(i,n){
    string x;
    cin >> x;
    sort(ALL(x));
    s[i] = x;
  }

  REP(i,n){
    ++mp[s[i]];
  }

  ll ans = 0;
  for(auto& p : mp){
    int s = p.second;
    ans += (ll)s*(s-1)/2;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 14056
class comb():
  F = [1, 1]
  Fi = [1, 1]
  I = [0, 1]
  def __init__(self, num, mod):
    self.MOD = mod
    for i in range(2, num + 1):
      self.F.append((self.F[-1] * i) % mod)
      self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
      self.Fi.append(self.Fi[-1] * self.I[i] % mod)
  def com(self, n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD

S = int(input())
MOD = 10 ** 9 + 7

ans = 0
com = comb(5000, MOD)
for i in range(1, 2000):
  n = S - i * 3
  if n < 0: break
  ans = (ans + com.com(i + n - 1, n)) % MOD

print(ans)

Measured memory_bytes: 9760
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int n;
    int m;
    int l;
 
   cin >> n >> m >> l;
  
   int ans = n/(m+l);
   int amari = n%(m+l);
  
//   cout << n << endl;
  // cout << m << endl;
  // cout << l << endl;
  // cout << ans << endl;
  // cout << amari << endl;
  
   if(amari>=l){
     
      cout << ans << endl;
     
   }else{
     
     cout << ans-1 << endl;
   }
  
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
if n % 4 == 0:
  print("Yes")
elif n % 7 == 0:
  print("Yes")
else:
  for i in range((n // 4) + 1):
    for j in range((n // 7)+1):
      if n == 4*i + 7*j:
        print("Yes")
        exit()
  print("No")

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cassert>
#include <iostream>
using std::cin; using std::cout; using std::endl;
#include <algorithm>
using std::sort; using std::min; using std::max;
#include <vector>
using std::vector;
#include <set>
using std::set;
#include <queue>
using std::queue; using std::priority_queue;
#include <utility>
using std::pair;
typedef pair<int, int> pii;
typedef long long LL;
typedef long double LD;
#define pass printf("%s : Line.%d\n", __FUNCTION__, __LINE__);
const int maxN = 100000 + 233;
const int maxM = 100000 + 233;
const int INF = 0x3f3f3f3f;
int n, m;

struct Edge {
	int from, to, dist;
	Edge() {}
	Edge(int f, int t, int d) : from(f), to(t), dist(d) {}
};
vector<Edge> edges;
vector<int> G[maxN];

int d[maxN];
bool inq[maxN];
void SPFA() {
	queue<int> Q;
	for(int i = 1; i <= n; ++i) inq[i] = true, d[i] = n;
	for(int i = 1; i <= n; ++i) Q.push(i);
	while(!Q.empty()) {
		int u = Q.front(); Q.pop(); inq[u] = false;
		for(int i = 0; i < (int)G[u].size(); ++i) {
			Edge &e = edges[G[u][i]];
			if(d[e.to] > d[u] + e.dist) {
				d[e.to] = d[u] + e.dist;
				if(!inq[e.to]) Q.push(e.to), inq[e.to] = true;
			}
		}
	}
}

void addedge(int u, int v, int w) {
	edges.push_back(Edge(u, v, w));
	G[u].push_back(edges.size() - 1);
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		int a = min(x, y), b = max(x, y);
		addedge(b, a, -1);
	}
	for(int i = 1; i < n; ++i) {
		int a = i, b = i + 1;
		addedge(a, b, 1);
		addedge(b, a, 0);
	}
	memset(d, INF, sizeof(d));
//	d[1] = 0;
	SPFA();
	printf("%d\n", d[n] - d[1]);
	return 0;
}

Measured memory_bytes: 13744
n, k, q = list(map(int, input().split()))
a = [int(input()) for _ in range(q)]
l = [0] * n
s = k - q
for i in a:
    l[i - 1] += 1
if s <= 0:
    for i in range(n):
        if s + l[i] > 0:
            print('Yes')
        else:
            print('No')
else:
    for _ in range(n):
        print('Yes')

Measured memory_bytes: 8632
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int N, M;
	cin >> N >> M;
	vector<int> S(M), C(M);
	for (int i = 0; i < M; ++i) {
		cin >> S[i] >> C[i];
		if (N < S[i]) {
			cout << -1 << endl;
			return;
		}
		if (N>1 && S[i]==1 && C[i]==0) {
			cout << -1 << endl;
			return;
		}
	}
	vector<int> start = {0,0,10,100,1000};
	for (int i = start[N]; i < start[N + 1]; ++i) {
		vector<int> B(N);
		int ter = i;
		for (int k = 0; k < N; ++k) {
			B[k] = ter % 10;
			ter /= 10;
		}
		reverse(B.begin(), B.end());
		bool flag = true;
		for (int k = 0; k < M; ++k) {
			if (B[S[k]-1] != C[k]) {
				flag = false;
				break;
			}
		}
		if (flag == true) {
			cout << i << endl;
			return;
		}
	}
	cout << -1 << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
S = input()
S += "T"
gx, gy = map(int, input().split())
firstT = S.find("T")
X = {firstT}
Y = {0}
h = True
f = 0
for s in S[firstT:]:
    if s == "T":
        if h:
            newX = set([])
            for x in X:
                newX.add(x + f)
                newX.add(x - f)
            X = newX
        else:
            newY = set([])
            for y in Y:
                newY.add(y + f)
                newY.add(y - f)
            Y = newY
        h = not h
        f = 0
    else:
        f += 1
if gx in X and gy in Y:
    print("Yes")
else:
    print("No")


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Pair[] P = new Pair[N];
		for(int i=0;i<N;i++){
			P[i] = new Pair(i, A[i] + B[i]);
		}
		Array.Sort(P, (p, q) => p.V.CompareTo(q.V));
		Array.Reverse(P);
		long ans = 0;
		for(int i=0;i<N;i++){
			if(i % 2 == 0) ans += A[P[i].Idx];
			if(i % 2 == 1) ans -= B[P[i].Idx];
		}
		Console.WriteLine(ans);
	}
	
	class Pair{
		public int Idx;
		public long V;
		public Pair(int idx, long v){
			V = v; Idx = idx;
		}
	}
	
	int N;
	long[] A,B;
	public Sol(){
		N = ri();
		A = new long[N];
		B = new long[N];
		for(int i=0;i<N;i++){
			var d = rla();
			A[i] = d[0];
			B[i] = d[1];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 21308
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

const int mo=int(1e9+7),Z=2001;
int n,a[200010],b[200010],f[4010][4010],fac[8010],ifac[8010],ans;

int C(int n,int m){return 1LL*fac[n]*ifac[m]%mo*ifac[n-m]%mo;}

int qpow(int a,int b)
{
	int x=a;  a=1;
	while (b)
		{
			if (b&1)  a=1LL*a*x%mo;
			x=1LL*x*x%mo,b>>=1;
		}
	return a;
}

void work()
{
	scanf("%d",&n),fac[0]=1;
	for (int i=1; i<=8000; i++)  fac[i]=1LL*fac[i-1]*i%mo;
	ifac[8000]=qpow(fac[8000],mo-2);
	for (int i=8000; i; i--)  ifac[i-1]=1LL*ifac[i]*i%mo;
	for (int i=1; i<=n; i++)
		{
			scanf("%d %d",&a[i],&b[i]);
			f[Z-a[i]][Z-b[i]]++;
			ans=(ans+mo-C(2*(a[i]+b[i]),2*a[i]))%mo;
		}
	for (int i=1; i<2*Z; i++)
		for (int j=1; j<2*Z; j++)
			f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%mo;
	for (int i=1; i<=n; i++)  (ans+=f[Z+a[i]][Z+b[i]])%=mo;
	printf("%d",int(1LL*ans*qpow(2,mo-2)%mo));
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 64640