akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    bool g[n][n] = {};
    rep(i, 0, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        g[a[i]][b[i]] = true;
        g[b[i]][a[i]] = true;
    }

    int path[n];
    rep(i, 0, n) path[i] = i;
    int ans = 0;
    do {
        if (path[0] != 0) continue;
        bool flag = true;
        rep(i, 0, n - 1) if (!g[path[i]][path[i + 1]]) flag = false;
        if (flag) ans++;
    } while (next_permutation(path, path + n));

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


Measured memory_bytes: 256
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main() {
  int N, K, calc, cnt;
  cin >> N >> K;
  double ans;
  ans = 0;
  for (int i = 1; i <= N; i++) {
    calc = i;
    cnt = 0;
    while (calc < K) {
      calc = calc * 2;
      cnt++;
    }
    if (cnt == 0) {
      ans = ans + (1 / (double)N);
    } else {
      ans = ans + ((1 / (double)N) * (1 / pow(2, cnt)));
    }
  }
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}


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

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

    int K, X;
    cin >> K >> X;
    K--;
    for (int i = X - K; i <= X + K; i++)
    {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
// finish date: 2018/03/25

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int Q;
    cin >> Q;
    rep(i, Q) {
        ll A, B;
        cin >> A >> B;
        ll score = A * B;
        int sq = (int) sqrt(score);
        if (sq == sqrt(score)) sq--;
        int ans = sq * 2;
        if (A != B) ans--;
        if ((ll) sq * (sq + 1) >= score) ans--;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
a.sort()
A_score = 0
B_score = 0
counter = 0
while len(a)>0:
  if counter % 2 == 0:
    A_score += a.pop()
  else:
    B_score += a.pop()
  counter += 1

print(A_score - B_score)

Measured memory_bytes: 3060
MyString=Union{String,SubString{String},Char}
MyStringArray=Union{Array{String,1},Array{SubString{String},1},Array{Char,1}}
parseInt(x::MyString) = parse(Int, x)
parseInt(x::Real) = trunc(Int, x)
parseBigInt(x::MyString) = parse(BigInt, x)
parseBigInt(x::Real) = trunc(BigInt, x)
parseFloat(x::MyString) = parse(Float64, x)
parseFloat(x::Real) = trunc(Float64, x)
parseBigFloat(x::MyString) = parse(BigFloat, x)
parseBigFloat(x::Real) = trunc(BigFloat, x)
parseMap(x::MyStringArray) = map(parseInt, x)
parseMapBig(x::MyStringArray) = map(parseBigInt, x)

function main()
    a=sort(parseMap(split(readline())))
    if a[1]==5 && a[2]==5 && a[3]==7
        println("YES")
    else
        println("NO")
    end
end
main()

Measured memory_bytes: 114356
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N,K;
  cin >> N >> K;
  vector<int> A(K);
  REP(i, K) cin >> A[i];
  
  FOR(i,N,100000){
    int flag=0;
    REP(j,K){
      int x = i;
      while(x>0){
        if(x%10==A[j]){
          flag=1;
          break;
        }
        x/=10;
      }
    }
    if(flag==0){
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
using System;

public class Rectangle
{
    //????????¢?????¢????????¨?????????????±???????
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int a;
        int b;
        string[] square;
        /*---??£?¨???¨---*/

        /*???????????????????????§????????????*/
        square = Console.ReadLine().Split(' ');
        a = int.Parse(square[0]);
        b = int.Parse(square[1]);

        /*????????¢?????¢????????¨?????????????????§??????*/
        Console.WriteLine("{0} {1}",a*b ,2*a + 2*b);
    }
}

Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;

// いもす法を使ったDP(本番終了後の実装)
int main() {
  int N,K; cin>>N>>K;
  vector<pair<int,int> > s;
  for(int i=0; i<K; i++){
      int li,ri; cin>>li>>ri;
      pair<int,int> si(li,ri);
      s.emplace_back(si);
  }
  int slen=s.size();

  vector<int> routnum(N,0);
  vector<int> routnumdif(N-1,0); // -> routnum[i+1]-routnum[i]
  routnum[0]=1;
  routnumdif[0]=-1;
  for(int i=0; i<N-1; i++){
      for(int j=0; j<K; j++){
          int lj=s[j].first; int rj=s[j].second;
          if(i+lj-1<N-1){
              routnumdif[i+lj-1]+=routnum[i];
              routnumdif[i+lj-1]%=mod;
          }
          if(i+rj<N-1){
              routnumdif[i+rj]-=routnum[i];
              routnumdif[i+rj]+=mod;
              routnumdif[i+rj]%=mod;
          }
      }
      routnum[i+1]=routnum[i]+routnumdif[i];
      routnum[i+1]%=mod;
  }

  cout<<routnum[N-1]<<endl;
}

Measured memory_bytes: 4848
N,K = map(int, raw_input().split())
dic = {}
for _ in xrange(N):
  p = raw_input()
  if p[0] in dic:
    dic[p[0]] += 1
  else:
    dic[p[0]] = 1

counter = 0
while True:
  tmp = sorted(dic.items(), key=lambda x:x[1], reverse=True)
  if len(dic) < K: break
  for i in xrange(K):
    dic[tmp[i][0]] -= 1
    if dic[tmp[i][0]] == 0:
      del dic[tmp[i][0]]
  counter += 1

print counter

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 90000000000000000;
int PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

ll z = 0;

int main(){
  ll N;cin >> N;
  vector<ll> A(N),B(N),C(N);
  for(int i = 0;i < N;i++)cin >> A[i];
  for(int i = 0;i < N;i++)cin >> B[i];
  for(int i = 0;i < N;i++)cin >> C[i];
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  /*for(int i = 0;i < N;i++)cout << A[i] <<' ';
  cout << endl;
  for(int i = 0;i < N;i++)cout << B[i] <<' ';
  cout << endl;
  for(int i = 0;i < N;i++)cout << C[i] <<' ';
  cout << endl;*/
  
  ll ans = 0;
  for(int i = 0;i < N;i++){
    ll L = 0,R = 0;
    int l = -1,r = N;
    while(r-l>1){
      int mid = (r+l)/2;
      if(A[mid] >= B[i]){
        r = mid;
      }else{
        l = mid;
      }
    }
    if(0 <= r - 1&& r - 1 < N){
      if(A[r-1] < B[i]){
        L = r;
      }
    }
    l = -1;
    r = N;
    while(r-l>1){
      int mid = (r+l)/2;
      if(C[mid] > B[i]){
        r = mid;
      }else{
        l = mid;
      }
    }
    if(0 <= r && r < N){
      if(C[r] > B[i]){
        R = N-r;
      }
    }
    ans += R * L;
    //cout << L <<' '<< R << endl;
  }
  cout << ans << endl;
}



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

int main() {
	int n, x[3];
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> x[0] >> x[1] >> x[2];
		sort(x, x + 3);
		for(int j = 0; j < 3; j++) {
			x[j] *= x[j];
		}
		if(x[2] == x[0] + x[1]) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1168
#include <stdio.h>
#include <math.h>

int main(void){
    // Your code here!
    
int h,w;
int k;
char c[6][6];
int ans=0;

    scanf("%d %d %d",&h,&w,&k);
    //printf("%d %d %d",h,w,k);
    
    for(int i=0;i<h;i++){
        scanf("%s",&c[i][0]);
    }

int hkaisuu=1;
int wkaisuu=1;

for(int i=0;i<h;i++){
    hkaisuu*=2;
}
for(int i=0;i<w;i++){
    wkaisuu*=2;
}


//printf("\n%d %d\n",hkaisuu,wkaisuu);


int know=0;

for(int i=0;i<hkaisuu;i++){
    for(int j=0;j<wkaisuu;j++){
        know=0;
        
for(int hnow=0;hnow<h;hnow++){
    for(int wnow=0;wnow<w;wnow++){
        if(c[hnow][wnow]=='#'&&(i&(1<<hnow))==0 &&(j&(1<<wnow))==0){know++;}
    
}
}
//printf("%d %d\n",know,k);
if(know==k){ans++;}
}
}
 
 

   printf("%d",ans);
}

Measured memory_bytes: 1732
//
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define speed ios::sync_with_stdio(false)
using namespace std;

string gs(char x){
    string s(1,x);
    return s;
}


int main()
{
	speed;
	
	ll n;
	cin>>n;
	ll arr[n];
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		arr[i]-=(i+1);
	}

	sort(arr,arr+n);
	ll ind;
	ll b;
	if(n%2)
	{
		ind=(n+1)/2;
		ind--;
		b=arr[ind];
	}
	else
	{
		ind=n/2;
		b=(arr[ind]+arr[ind-1])/2;
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		ans+=abs(arr[i]-b);
	}
	cout<<ans;

	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

#define N 25
#define NIL -1

struct Node{
  int p,l,r;
};

struct Node T[N];
int n,D[N],H[N];

void setDepth(int,int);
int setHeight(int);
int getSibling(int);
void print(int);

int main(void){
  int v,l,r,root=0;
  int i,j;

  scanf(" %d",&n);
  for(i = 0; i < n; i++)T[i].p = NIL;

  for(i = 0; i < n; i++){
    scanf(" %d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }

  for(i = 0; i < n; i++){
    if(T[i].p == NIL) root = i;
  }

  setDepth(root,0);
  setHeight(root);

  for(i = 0; i < n; i++){
    print(i);
  }
  
  return 0;
}

void setDepth(int u, int d){
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].l,d+1);
  setDepth(T[u].r,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].l != NIL){
    h1 = setHeight(T[u].l)+ 1;
  }
  if(T[u].r != NIL){
    h2 = setHeight(T[u].r)+ 1;
  }
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].p == NIL)return NIL;
  if(T[T[u].p].l != u && T[T[u].p].l != NIL){
    return T[T[u].p].l;
  }
  if(T[T[u].p].r != u && T[T[u].p].l != NIL){
    return T[T[u].p].r;
  }
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].l != NIL)deg++;
  if(T[u].r != NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].p == NIL){
    printf("root\n");
  }
  else if(T[u].l == NIL && T[u].r == NIL){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}



Measured memory_bytes: 2072
using System;
using System.Linq;

namespace ABC124C
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().ToArray();

            int time0 = 0;
            int time1 = 0;

            int len = line.Length;

            for(var i = 0; i < len; i++)
            {
                if(i % 2 == 0)
                {
                    if(line[i] == '1')
                    {
                        time0++;
                    }
                }
                else
                {
                    if(line[i] == '0')
                    {
                        time0++;
                    }
                }
            }
            
            for(var i = 0; i < len; i++)
            {
                if(i % 2 == 0)
                {
                    if(line[i] == '0')
                    {
                        time1++;
                    }
                }
                else
                {
                    if(line[i] == '1')
                    {
                        time1++;
                    }
                }
            }

            if(time0 > time1)
            {
                Console.WriteLine(time1);
            }
            else
            {
                Console.WriteLine(time0);
            }
        }
    }
}


Measured memory_bytes: 13280
N = int(input())
lst = []
for i in range(1,N+1):
  S,P = input().split()
  #一つのリストとしてlstに追加する、番号もつけて
  lst.append([S,-1*int(P),i])

lst = sorted(lst,key=lambda x:(x[0],x[1]))
for i in lst:
  print(i[2])

Measured memory_bytes: 3060
#include<stdio.h>

#define N_MAX 100000

int main(void){

    int N,i,ans=0,AbleToDown = 0;
    long int H[N_MAX];

    scanf("%d",&N);
    for(i = 0;i < N;i++){
        scanf("%ld",&H[i]);
    }

    for(i = 0;i< N - 1;i++){
        if(H[i] >= H[i + 1]){
            AbleToDown++;
        }else{
            if(ans < AbleToDown){
                ans = AbleToDown;
            }
          AbleToDown = 0;
        }
    }

    if(ans < AbleToDown){
        ans = AbleToDown;
    }

    printf("%d",ans);
    return 0;
}



Measured memory_bytes: 896
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;

int main(){
  long long int n,cnt=0,ccnt=0;
  cin>>n;
  bool ok=false;
  long long int num[n];
  for(int i=0;i<n;i++){
    cin>>num[i];
    if(num[i]%2==0 and num[i]%4!=0)
    ccnt++;
    if(num[i]%4==0)
    cnt++;
  }
  cnt+=ccnt/2;
  if(cnt+1>=(n-cnt))
  ok=true;
  if(ok)
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;
}


Measured memory_bytes: 1024
#include <queue>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

#if __has_include("debugger.cpp")
  #include "debugger.cpp"
#else
void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) > 0) cout << " ";
  print(std::forward<Tail>(tail)...);
}
# endif

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  ll input(n, x, y);
  vector<vector<ll>> graph(n);
  REP(i, n - 1) {
    graph[i].push_back(i + 1);
    graph[i + 1].push_back(i);
  }
  graph[x - 1].push_back(y - 1);
  graph[y - 1].push_back(x - 1);

  struct Args {
    ll to, cost;
  };
  vector<vector<ll>> visited(n, vector<ll>(n, -1));
  auto comp = [](Args &v1, Args &v2){
    return v1.cost > v2.cost;
  };
  REP(i, n) {
    priority_queue<Args, vector<Args>, decltype(comp)> que{comp};
    // queue<Args> que;
    que.push({i, 0});
    while(!que.empty()) {
      // Args args = que.front();
      Args args = que.top();
      que.pop();
      if (visited[i][args.to] != -1) continue;

      visited[i][args.to] = args.cost;
      for(auto v: graph[args.to]) {
        que.push({v, args.cost + 1});
      }
    }
  }

  // print(visited);
  map<ll, ll> cnt;
  for(auto v: visited) {
    for(auto value: v) {
      cnt[value]++;
    }
  }

  REP(i, n - 1) {
    print(cnt[i + 1] / 2);
  }
}


Measured memory_bytes: 35152
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if (a==b)
	{
		cout<<c;
	}
	else
	{
		if (a==c)
		{
			cout<<b;
		}
		else if (b==c)
		{
			cout<<a;
		}
	}
	cout<<"\n";
	return 0;
}

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


int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    for(int i = 0; i < N; ++i) cin >> v[i];

    sort(v.begin(), v.end());

    double ans = v[0]/pow(2, N-1);
    for(int i = 1; i < N; ++i){
        ans += v[i]/pow(2, N-i);
    }
    cout<< ans << endl;

    return 0;
}

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

int main(){
    double n;
    cin >> n;
    // 切り上げ
    int ans = ceil(n/1.08);
    // 切り捨て
    if(floor(ans*1.08) == n) cout << ans << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
typedef long long ll;
const double PI = acos(-1);
using namespace std;

int main(void){
    int N,A,B;cin>>N>>A>>B;
    cout<<min(A,B)<<" "<<max(0,A+B-N)<<endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <map>
//#define LOCAL
using namespace std;
typedef long long ll;
map<string,ll>m;

int main() {
#ifdef LOCAL
ifstream fin("1.txt");
streambuf*p;
p=cin.rdbuf(fin.rdbuf());
#endif // LOCAL
ll q;
cin>>q;
for(ll i=0;i<q;i++){
    ll a;
    string key;
    cin>>a>>key;
    if(0==a){
        ll x;
        cin>>x;
        m[key]=x;
    }else if(1==a){
        if(m.count(key)) cout<<m[key]<<endl;
        else cout<<'0'<<endl;
    }else if(2==a){
        m.erase(key);
    }else if(3==a){
        string r;
        cin>>r;
        map<string, ll>::iterator i1, i2;
        i1=m.lower_bound(key);
        i2=m.upper_bound(r);
        for(;i1!=i2;i1++){
            cout<<i1->first<<' '<<i1->second<<endl;
        }
    }
}

#ifdef LOCAL
fin.close();
#endif // LOCAL
}



Measured memory_bytes: 27796
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

func main() {
	n := readi()

	p := primeFactors(n)
	agg := make(map[int]int)
	for i := 0; i < len(p); i++ {
		agg[p[i]]++
	}

	ans := 0
	for _, a := range agg {
		i := 0
		sum := 0
		for {
			sum = sum + i
			if sum > a {
				i = i - 1
				break
			}
			i++
		}
		ans += i
	}
	fmt.Println(ans)
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

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

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

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func primeFactors(n int) []int {
	factors := make([]int, 0)
	i := 2
	for i*i <= n {
		r := n % i
		if r != 0 {
			i++
		} else if r == 0 {
			n /= i
			factors = append(factors, i)
		}
	}
	if n > 1 {
		factors = append(factors, n)
	}
	return factors
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

// func searchInts(a []int, k int) int {
// 	return binarySearch(len(a), func(i int) bool {
// 		return a[i] >= k
// 	})
// }

func binarySearch(n int, f func(int) bool) int {
	i, j := 0, n
	for i < j {
		h := int(uint(i+j) >> 1)
		if !f(h) {
			i = h + 1
		} else {
			j = h
		}
	}
	return i
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


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

using namespace std;

const int N =  1e5 + 5;
pair < int , int > a[N];
int main()
{
    int n , m;
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i].first >> a[i].second;
    }
    sort(a , a+n);

    long long ans = 0;
    int j = 0;
    priority_queue < int > q;
    for(int i = 1 ; i <= m ; i++)
    {
        while(j < n && a[j].first <= i) q.push(a[j].second) , j++;

        if(q.empty()) continue;
        ans += q.top(); q.pop();
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1660
fun main(args: Array<String>) {
  val (N, M) = readInts()
  val A = readInts()
  val map = mutableMapOf<Long, Long>()

  map[0] = 1

  var cnt = 0L
  var sum = 0L
  A.forEach {
    sum += it
    sum %= M
    val n = map[sum]
    if (n == null) {
      map[sum] = 1
    } else {
      cnt += n
      map[sum] = n + 1
    }
  }

  println(cnt)
}

fun gcd(a: Int, b: Int): Int = if (a < b) gcd(b, a) else if (b == 0) a else gcd(b, a % b)
fun gcd(a: Long, b: Long): Long = if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = (a * b) / gcd(a, b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }


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

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

 vector<int> vec(N);
 for(int i=0; i<N; i++) cin >> vec.at(i);

 sort(vec.begin(), vec.end());

 int ans=1;

 for(int i=0; i<N; i++){
     if(i!=0 && vec.at(i)!=vec.at(i-1)) ans++;
 }

 cout <<ans<<endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; cin>>a>>b;
    if (b<a){
        cout<<a-1<<endl;
    }else{
        cout<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=True)
x = []
y = []
for i in range(len(a)):
    if i%2==0:
        x.append(a[i])
    else:
        y.append(a[i])
print(sum(x)-sum(y))


Measured memory_bytes: 3060
<?php
$k = array();
$w = array();
$sumk = 0;
$sumw = 0;
for ($i = 0; $i < 20; $i++) {
    if($i<10){
        $w[] = str_replace(array("\r", "\n"), '', fgets(STDIN));
        
    }else{
        $k[] = str_replace(array("\r", "\n"), '', fgets(STDIN));
    }
}
sort($w);
sort($k);
for($i=0,$j=9;$i<3;$i++,$j--){
    $sumk += $k[$j];
    $sumw += $w[$j];
}
echo $sumw.' '.$sumk.PHP_EOL;
?>


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

    inline int D(){
        int t ;
        scanf( "%d" , &t ) ;
        return t ;
    }
    inline ll LLD(){
        ll t ;
        scanf( "%lld" , &t ) ;
        return t ;
    }
   // const int INF = 0x3f3f3f3f;
//###################################################################
const int maxw=100000,N=105;
int n,W,w[N],v[N];
ll dp[N][maxw];
int main(){
    n=D(),W=D();
    for(int i=0;i<n;i++){
        w[i]=D();
        v[i]=D();
    }
    for(int i=0;i<=W;i++)
        if(i>=w[0])dp[0][i]=v[0];

    for(int i=1;i<n;i++){
        for(int j=0;j<=W;j++){
            if(j<w[i]) dp[i][j]=dp[i-1][j];
            else{
                dp[i][j]=max(dp[i-1][j],1ll*v[i]+dp[i-1][j-w[i]]);
            }
        }
    }
    printf("%lld",dp[n-1][W]);
}

Measured memory_bytes: 80128
#include<iostream>
#include<string>

int main() {
	int n;
	std::cin >> n;
	double a[100];
	double kakeru = 1;
	double sum = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
		kakeru *= a[i];
	}
	for (int i = 0; i < n; i++) {
		sum += kakeru / a[i];
	}
	std::cout << kakeru / sum << std::endl;
}


Measured memory_bytes: 256
fn getline() -> String {
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn main() {
    let s = getline();
    let vec: Vec<_> = s.trim().split(' ').map(|s| s.parse().unwrap()).collect();
    let a: i32 = vec[0];
    let b: i32 = vec[1];
    let c: i32 = vec[2];

    let ans = if a <= c && c <= b { "Yes" } else { "No" };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

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

int main(){
  ll A,B;cin>>A>>B;
  ll C=gcd(A,B);
  int cnt=1;
  for(ll i=2;i*i<=C;i++)if(C%i==0){
    while(C%i==0){
      C/=i;
    }
    cnt++;
    if(C==1) break;
  }
  if(C!=1) cnt++;
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main ()
{
	int n, cek = 0;
	cin >> n;
	if (n < 13){
		cout << n << endl;
		return 0;
	}
	for (int i=1; i<n; i++){
		if (i+floor(i*8/100) == n){
			cout << i << endl;
			cek = 1;
		}
	}
	if (cek == 0){
		cout << ":(" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <numeric>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define ALL(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main(){
	int n, d; cin >> n >> d;
	vector<vector <double> > X;
	rep(i,n){
		vector<double> Y;
		rep(j,d){
			double x; cin >> x;
			Y.push_back(x);
		}
		X.push_back(Y);
	}

	int ans = 0;
	reps(i,n-1){
		rep(j,i){
			double sum = 0;
			rep(k,d){
				sum += pow((X[i][k] - X[j][k]), 2.0);
			}
			if(ceil(pow(sum, 0.50)) == floor(pow(sum, 0.50))) ans++;
		}
	}

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


Measured memory_bytes: 512
k = int(input())
#n = int(input())

def S(x):
	return sum(list(map(int, list(str(x)))))

def T(x):
	return x / S(x)

n = 1
snuke = [1]
x = 1

while n < k:
	x += 1
	cand = x
	T_min = T(x)
	for d in range(len(str(x))-1):
		if T((x // (10**(d+1)) + 1) * (10**(d+1)) - 1) < T_min:
			T_min = T((x // (10**(d+1)) + 1) * (10**(d+1)) - 1)
			cand = (x // (10**(d+1)) + 1) * (10**(d+1)) - 1
	x = cand
	snuke.append(x)
	n += 1

print(*snuke, sep="\n")

Measured memory_bytes: 3188
n = int(input())
happymat = []
for _ in range(n):
    happymat.append(list(map(int, input().split())))

# dp[j] stores the max happiness doing activity j on the current
dp = [0]*3

for i in range(n):
    prev = dp.copy()
    for j in range(3):
        dp[j] = happymat[i][j] + max(prev[(j+1)%3], prev[(j+2)%3])

print(max(dp))

Measured memory_bytes: 32296
S = input()

while True:
    if S == "hi":
        flag = True
        break
    elif len(S) < 2:
        flag = False
        break
    elif S[-2:] == "hi":
        S = S[:-2]
    else:
        flag = False
        break

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
 
#define N 1000
 
int main(){
 
  int i, j, c;
  int flag = 0;
  char T[N], P[N];
 
  scanf("%s", T);
  scanf("%s", P);
 
  for(i=0; i<strlen(T); i++){
    flag = 0;
    for(j=0, c=i; j<strlen(P); j++, c++){
      if(T[c] != P[j]){
        flag = 1;
      }
    }
    if(flag == 0) printf("%d\n", i);
  }
  return 0;
}


Measured memory_bytes: 2112
#include <algorithm>
#include <deque>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  char c;
  int q, n, t, f, flag = 0;
  deque<char> d;
  cin >> s >> q;
  for (int i = 0; i < s.length(); i++) {
    d.push_back(s[i]);
  }
  for (int i = 0; i < q; i++) {
    cin >> t;
    if (t == 1) {
      flag ^= 1;
    } else {
      cin >> f >> c;
      if ((flag + f) % 2) {
        d.push_front(c);
      } else {
        d.push_back(c);
      }
    }
  }
  if (flag) {
    for (int i = d.size() - 1; i >= 0; i--) {
      cout << d[i];
    }
  } else {
    n = d.size();
    for (int i = 0; i < n; i++) {
      cout << d[i];
    }
  }
  cout << endl;
}

Measured memory_bytes: 960
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;

int N,M;
Graph G;
vector<int> dist;
queue<int> que;

void input(){
  cin >> N >> M;
  G.resize(N+1);
  dist.resize(N+1,-1);
  int a,b;
  for(int i=0;i<M;i++){
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
}

void solve(){
  int v;
  que.push(1);
  dist[1]=0;
  while(!que.empty()){
    v=que.front();    
    que.pop();
    for(auto nv:G[v]){
      if(dist[nv]!=-1){
	continue;
      }
      que.push(nv);
      dist[nv]=v;
    }
  }
}  

int main(){
  input();
  solve();
  for(int i=2;i<N+1;i++){
    if(dist[i]==-1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  for(int i=2;i<N+1;i++){
    cout << dist[i] << endl;
  }
  return 0;
}



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


int main(){
    string s;
    cin>>s;
    string b;
    string d;
    int h;
    int a=s.length();
    for(int i=0;i<a;i++){
      if(s[i]=='C'){
          b="C";
          h=i;
          //cout<<s[i]<<endl;
          break;
      }
    }
    for(int i=h;i<a;i++){
        if(s[i]=='F'){
            d="F";
            //cout<<s[i]<<endl;
            break;
        }
      }
    if(b+d=="CF"){
        cout<<"Yes"<<endl;
    
    }
    else{
        cout<<"No"<<endl;
    
    }
    return 0;
}




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

int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    double ans = w * h / 2.0;
    int isMultiple;
    if(w / 2 == x && h / 2 == y) isMultiple = 1;
    else isMultiple = 0;

    cout << setprecision(20) << ans << ' ' << isMultiple << endl;

    return 0;
}

Measured memory_bytes: 384
#import re
import sys
#input = sys.stdin.readline
#import heapq
#import bisect
#from collections import deque
#import math

def main():
    n = int(input())
    A = list(map(int,input().split()))
    A.sort()
    for i in range(n-1):
        if A[i] == A[i+1]:
            print("NO")
            return
    
    print("YES")



    
if __name__ == '__main__':
    main()


Measured memory_bytes: 26808
def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))

    ev = [(num + 1) / 2 for num in p]

    cumsum = []
    c = 0
    for num in ev:
        c += num
        cumsum.append(c)
    cumsum.append(0)  # let cumsum[-1] be 0
    
    ans = 0
    for i in range(n):
        if i + k - 1 > n - 1:
            break
        nominee = cumsum[i+k-1] - cumsum[i-1]
        if nominee > ans:
            ans = nominee

    print(ans)

main()


Measured memory_bytes: 82312
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
/*
ll GCD(ll A,ll B){
  return (B==0)?(A):(GCD(B,A%B));
}
ll LCM(ll A,ll B){
  return A/GCD(A,B)*B;
}
*/
int main(){
	ll N,M;
	ll X[1000],Y[1000],Z[1000];
	cin>>N>>M;
	FOR(i,0,N){
		cin>>X[i]>>Y[i]>>Z[i];
	}
	ll ma=0;
	FOR(i,0,8){
		vector<ll> V;
		FOR(j,0,N){
			ll a=0;
			if((i>>0)&1){
				a+=X[j];
			}else{
				a-=X[j];
			}
			if((i>>1)&1){
				a+=Y[j];
			}else{
				a-=Y[j];
			}
			if((i>>2)&1){
				a+=Z[j];
			}else{
				a-=Z[j];
			}
			V.PB(a);
		}
		sort(V.rbegin(),V.rend());
		ll s=0;
		FOR(j,0,M){
			s+=V[j];
		}
		ma=max(ma,s);
	}
	cout<<ma<<endl;
	return 0;
}

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

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

	int a[200001] = {0};
	int c[200001] = {0};

	for (int i = 2;i <= N;i++)
	{
		cin >> a[i];
		c[a[i]]++;

	}

	for (int i = 1;i <= N;i++)
	{
		cout << c[i] << endl;
	}
}

Measured memory_bytes: 5136
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int n,m,f[1<<15][16],g[1<<15][16],w[16][16],q[1<<15],v[1<<15],lowbit[1<<15],ans=2e9;
inline void R(int&x,int y){y<x?x=y:0;}
int main()
{
    n=read();m=read();
    for(int i=1;i<=m;++i)
    {
        int a=read(),b=read(),c=read();
        w[a][b]=w[b][a]=c;
    }
    memset(f,63,sizeof(f));f[1][1]=0;
    for(int i=1;i<1<<n;++i)
    {
        int lb=1;
        for(;!(i&(1<<lb-1));++lb);
        for(int j=1;j<=n;++j)
            g[i][j]=g[i^(1<<lb-1)][j]+w[lb][j];
        lowbit[i]=lb;
    }
    for(int i=1;i<1<<n;++i) if(i&1)
        for(int j=1;j<=n;++j) if(i&(1<<j-1))
        {
            for(int k=1;k<=n;++k)
                if(!(i&(1<<k-1))&&w[k][j])
                    R(f[i|(1<<k-1)][k],f[i][j]+g[i^(1<<j-1)][k]);
            int r=(1<<n)-1-i,top=0;
            for(int s=r;s&=r;--s) q[++top]=s;
            for(int k=top;k;--k)
            {
                v[q[k]]=v[q[k]^(1<<lowbit[q[k]]-1)]+g[i^(1<<j-1)][lowbit[q[k]]];
                R(f[i|q[k]][j],f[i][j]+v[q[k]]);
            }
        }
    printf("%d\n",f[(1<<n)-1][n]);
    return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
using namespace std;
using ll = long long;
int depth[1000];


int solve()
{
    int n, m;
    cin >> n >> m;
    if (n == m and n == 0)
        return 0;

    vector<int> graph[n];
    rep(i, 0, m)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    rep(i, 0, n)
        depth[i] = -1;
    depth[0] = 0;

    queue<int> que;
    que.push(0);
    depth[0] = 0;

    int cnt_e, cnt_o;
    cnt_e = cnt_o = 0;
    while (que.size() > 0)
    {
        int now = que.front();
        que.pop();
        // cout << "aaaaaa : " << now << ' ' << depth[now] << endl;

        if (depth[now] % 2 == 0 and cnt_e >= 0)
            cnt_e++;
        if (depth[now] % 2 == 1 and cnt_o >= 0)
            cnt_o++;

        for (auto next: graph[now])
        {
            if (depth[next] == -1)
            {
                depth[next] = depth[now] + 1;
                que.push(next);
            }
            else if (depth[next] == depth[now])
            {
                cout << 0 << endl;
                return 1;
            }
        }
    }

    vector<int> ans;
    if (cnt_o > 1 and cnt_o % 2 == 0)
        ans.push_back(cnt_o / 2);
    if (cnt_e > 1 and cnt_e % 2 == 0)
        ans.push_back(cnt_e / 2);
    sort(ans.begin(), ans.end());

    if (ans.size() == 2 and ans[0] == ans[1])
        ans = {ans[0]};

    cout << ans.size() << endl;
    for (auto a: ans)
        cout << a << endl;
    return 1;
}

int main()
{
    while(solve()){}
    return 0;
}


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

int main() {

    int a;
    int b;
    int c;
    int d;
    
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;

    if ( a * b < c * d) {
        cout << c * d << endl;
    }
    else {
        cout << a * b << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
py = [list(map(int, input().split())) + [i] for i in range(m)]
py.sort(key=lambda x: [x[0], x[1]])
ans = []
P = [0] * (n + 1)
for p, y, i in py:
    P[p] += 1
    tmp = str(p).zfill(6) + str(P[p]).zfill(6)
    ans.append([i,tmp])
ans.sort()
for i,a in ans:
    print(a)

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

if n == 0:
    print(0)

else:

    lim = int((n**0.5))

    ans = 0
    for i in range(1,lim+1):
        if n%i == 0 and i*i != n and i*(i+1) != n:
            ans += (n//i)-1

    print(ans)


Measured memory_bytes: 40428
#include<stdio.h>
#include<stdlib.h>
int int_comp(const void*a,const void*b){return *(int*)a-*(int*)b;}
int main(){
    int n;
    int x[100];
    int su[100];

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    for(int i=0;i<101;i++)su[i]=0;
    for(int i=0;i<101;i++){
        for(int j=0;j<n;j++){
            su[i]+=(x[j]-i)*(x[j]-i);
        }
    }
    qsort(su,101,sizeof(int),int_comp);
    printf("%d\n",su[0]);
    return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }

const int MAX_N = 100000;
int n;
int a[MAX_N+1];
int b[MAX_N+1];

int main()
{
  cin >> n;
  forn(i,n+1) cin >> a[i];
  forn(i,n) cin >> b[i];

  ll res = 0;
  int c = min(b[0],a[0]);
  a[0] -= c;
  b[0] -= c;
  res += c;
  forn1(i,n) {
    c = min(b[i-1],a[i]);
    b[i-1] -= c;
    a[i] -= c;
    res += c;
    c = min(b[i],a[i]);
    a[i] -= c;
    b[i] -= c;
    res += c;
  }

  cout << res << endl;

  return 0;
}


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

int N, M;
int A[1 << 19];
int C[1 << 19];

bool solve(int border) {
	for (int i = 0; i <= 4 * N; i++) C[i] = 0;
	for (int i = 0; i < 2 * N; i++) {
		int pos1 = lower_bound(A, A + 4 * N, M - A[i]) - A;
		int pos2 = lower_bound(A, A + 4 * N, (M + border + 1) - A[i]) - A;
		if (pos2 <= 2 * N) {
			C[i + pos1] += 1;
			C[i + pos2] -= 1;
		}
		else {
			C[i + pos1] += 1;
			C[i + 2 * N] -= 1;
			C[i + 0] += 1;
			C[i + (pos2 - 2 * N)] -= 1;
		}
	}
	for (int i = 1; i <= 4 * N; i++) C[i] += C[i - 1];

	for (int i = 0; i <= 2 * N; i += 2) {
		int r1 = 0; if (i != 0) r1 = C[i - 1];
		int r2 = 0; if (i != 2 * N) r2 = C[2 * N + i - 1];
		if (r1 == i && r2 == (2 * N - i)) return true;
	}
	return false;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < 2 * N; i++) cin >> A[i];
	sort(A, A + 2 * N);
	for (int i = 0; i < 2 * N; i++) A[i + 2 * N] = A[i] + M;
	
	int cl = 0, cr = M, cm, minx = (1 << 30);
	for (int i = 0; i < 30; i++) {
		cm = (cl + cr) / 2;
		if (solve(cm) == true) { cr = cm; minx = min(minx, cm); }
		else { cl = cm; }
	}

	cout << minx << endl;
	return 0;
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

int n, m, q;
ll l, d[305][305], d2[305][305];
ll ans[90000];
void solve() {
    cin >> n >> m >> l;

    rep(i, n) {
        rep(j, n) d[i][j] = d2[i][j] = inf;
        d[i][i] = d2[i][i] = 0;
    }

    rep(i, m) {
        int a, b; ll c;
        cin >> a >> b >> c; --a, --b;
        mins(d[a][b], c); mins(d[b][a], c);
    }

    rep(k, n) rep(i, n) rep(j, n)
        mins(d[i][j], d[i][k] + d[k][j]);

    rep(i, n) rep(j, n) if (i != j && d[i][j] <= l) mins(d2[i][j], 1LL);

    rep(k, n) rep(i, n) rep(j, n)
        mins(d2[i][j], d2[i][k] + d2[k][j]);

    cin >> q;
    rep(i, q) {
        int s, t; cin >> s >> t; --s, --t;
        if (d2[s][t] != inf)ans[i] = d2[s][t] - 1;
        else ans[i] = -1;
    }

    rep(i, q) cout << ans[i] << endn;
}

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


Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>

#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#define all(c) c.begin(),c.end()
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define MAX_V 1001
#define MAX_E 401
#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-7

typedef long long ll;
inline int toInt(std::string s) { int v; std::istringstream sin(s); sin >> v; return v; }
template<class T> inline std::string toString(T x) { std::ostringstream sout; sout << x; return sout.str(); }
using namespace std;

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
#define X real()
#define Y imag()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template< typename T >
struct edge {
	int src, to;
	T cost;

	edge(int to, T cost) : src(-1), to(to), cost(cost) {}

	edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

	edge &operator=(const int &x) {
		to = x;
		return *this;
	}

	operator int() const { return to; }
};
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

int main()
{
	ll n;
	string s;
	cin >> n >> s;
	ll res = n + 1;

	vector<ll> E_n(n);
	vector<ll> W_n(n);
	rep(i, s.size())
	{
		if (i != 0)
		{
			E_n[i] = E_n[i - 1];
		}
		if (s[i] == 'E')
		{
			E_n[i] += 1;
		}
		if (i != 0)
		{
			W_n[i] = W_n[i - 1];
		}
		if (s[i] == 'W')
		{
			W_n[i] += 1;
		}
	}

	rep(i, s.size())
	{
		if (s[i] == 'E')
		{
			if (i == 0)
			{
				res = min(res, (E_n[n - 1] - E_n[i]));
				continue;
			}
			res = min(res,W_n[i - 1] + (E_n[n - 1] - E_n[i]));
		}
		else {
			if (i == 0)
			{
				res = min(res, (E_n[n - 1] - E_n[i]));
				continue;
			}
			res = min(res, W_n[i - 1] + (E_n[n - 1] - E_n[i]));
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 5380
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =3e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
int main()
{
	int x;
	scanf("%d",&x);
	if(x>=30) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <climits>
#include <utility>

using namespace std;

int dfs( vector< vector<int> > &board, const int &h, const int &w, int y, int x )
{
	if ( !( 0 <= y && y < h && 0 <= x && x < w ) || 
		board[y][x] == 0 )
	{
		return 0;
	}

	board[y][x] = 0;

	for ( int i = -1; i <= 1; i++ )
	{
		for ( int j = -1; j <= 1; j++ )
		{
			dfs( board, h, w, y + i, x + j );
		}
	}
	return 1;
}

int main()
{
	while ( true )
	{
		int w, h;
		cin >> w >> h;

		if ( !( w | h ) )
		{
			break;
		}

		vector< vector<int> > board( h, vector<int>( w ) );

		for ( int i = 0; i < h; i++ )
		{
			for ( int j = 0; j < w; j++ )
			{
				cin >> board[i][j];
			}
		}

		int res = 0;

		for ( int i = 0; i < h; i++ )
		{
			for ( int j = 0; j < w; j++ )
			{
				res += dfs( board, h, w, i, j );
			}
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1412
#include<stdio.h>
#include<string.h>
typedef long long LL;
LL a[20];
LL my_pow(LL ds,LL cf)
{
	LL sum=1;
	for(int i=0;i<cf;i++)
		sum*=ds;
	return sum;
}
LL dfs(int now,int size)
{
	if(now==size-1)
	{
		if(a[size-1]%2==1)
			return 2;
		else
			return 1;
	}
	else
	{
		if(a[now]%2==0)
			return my_pow(3,size-1-now)+2*dfs(now+1,size);
		else
			return 2*my_pow(3,size-1-now)+dfs(now+1,size);
	}
}
int main()
{
	int N;
	scanf("%d",&N);
	LL sum=0;
	for(int i=0;i<N;i++)
		scanf("%d",&a[i]);
	sum=dfs(0,N);
	printf("%lld\n",sum);
	return 0;
 } 

Measured memory_bytes: 128
s = input()
a, b = int(s[:2]), int(s[2:])

if 0<a<13 and 0<b<13:
    ans = 'AMBIGUOUS'
elif 0<a<13 and (b>12 or b==0):
    ans = 'MMYY'
elif (a>12 or a==0) and 0<b<13:
    ans = 'YYMM'
else:
    ans = 'NA'

print(ans)

Measured memory_bytes: 3064