akhauriyash/Code-Regression huggingface dataset:
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>'50000000'},'ruby',$0);def f(i)a=H[i].map{|e|-f(e)}.sort;(1..a.size).map{|i|i-a[i-1]}.max||0end;H=Hash.new{|h,k|h[k]=[]};2.upto(gets.to_i){|i|H[gets.to_i]<<i};p f 1

Measured memory_bytes: 224592
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    String[] li = S.split("");
    int count = 0;
    
    for(int i=0;i<N-1;i++){
      if(li[i].equals(li[i+1])){
        count++;
      }
    }
    
    System.out.println(N-count);
  }
}

Measured memory_bytes: 33980
## coding: UTF-8
from decimal import *
s = input().split()
t = [int(p) for p in s]

#print(t)
a = t[0]
b = t[1]
c = t[2]

if(c-a-b<0):
    print("No")
elif( 2 * a * b < a * a + b * b + c * c - 2 * a * c - 2 * b * c):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 5076
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){

            int w = Integer.parseInt(sc.next());
            int h = Integer.parseInt(sc.next());
            int n = Integer.parseInt(sc.next());

            int smallXMax = 0;
            int largeXMin = w;
            int smallYMax = 0;
            int largeYMin = h;

            for(int i = 0; i < n; i++){
                int x = Integer.parseInt(sc.next());
                int y = Integer.parseInt(sc.next());
                int a = Integer.parseInt(sc.next());

                if(a == 1 && smallXMax < x) smallXMax = x;
                if(a == 2 && largeXMin > x) largeXMin = x;
                if(a == 3 && smallYMax < y) smallYMax = y;
                if(a == 4 && largeYMin > y) largeYMin = y;

            }

            int ans = (largeXMin - smallXMax)*(largeYMin - smallYMax);
            if((largeXMin - smallXMax) < 0 || (largeYMin - smallYMax) < 0) System.out.println(0);
            else System.out.println(ans);

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 23892
x = int(input())

for a in range(10**3):
  for b in range(10**3):
    frag = False
    if a ** 5 - b ** 5 == x:
      print(a,b)
      frag = True
      break
    elif (-a) ** 5 - b ** 5 == x:
      print(-a,b)
      frag = True
      break
      
    elif a ** 5 - (-b) ** 5 == x:
      print(a,-b)
      frag = True
      break
      
    elif (-a) ** 5 - (-b) ** 5 == x:
      print(-a,-b)
      frag = True
      break
  if frag == True:
      break
    

Measured memory_bytes: 9208
def c(n):
    b = 2
    f = set()
    while b * b <= n:
        while n % b == 0:
            n //= b
            f |= {b}
        b += 1
    if n > 1:
        f |= {n}
    return f
a, b = map(int, input().split())
print(len(c(a) & c(b)) + 1)

Measured memory_bytes: 3060
n,a,b = gets.chomp.split(" ").map(&:to_i)
v = gets.chomp.split(" ").map(&:to_i).sort.reverse
ave = v[0..a-1].inject(:+).to_f/a
puts sprintf("%f",ave)
f = v[a-1]
c = v[0..a-1].count(f)
d = v.count(f)
e = 1
count = 0
if c == a
  e = [b-a,d-c].min+1
end
e.times do |i|
  temp = 1
  (c+i).times do |j|
    temp *= d-j
  end
  (c+i).times do |j|
    temp /= j+1
  end
  count += temp
end
puts count

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

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    String readStr;
    while ((readStr = reader.readLine()) != null) {
      long l = Integer.parseInt(readStr.split(" ")[0]);
      long r = Integer.parseInt(readStr.split(" ")[1]);
      
      System.out.println(gcd(l, r) + " " + lcm(l, r));
    }

  }

  public static long gcd(long m, long n) {
    return n == 0 ? m : gcd(n,m%n);
  }

  public static long lcm(long m, long n) {
    return m*n/gcd(m, n);
  }
  
}

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

int main() {

	int m, f, sum, r;
	char rank;

	cin >> m >> f >> r;
	while ((m & f & r) != -1) {
		if (m < 0 || f < 0) {
			rank = 'F';
		} else {
			sum = m + f;
			if (sum < 30) {
				rank = 'F';
			} else if (sum < 50) {
				rank = 'D';
				if (r > 49)
					rank = 'C';
			} else if (sum < 65) {
				rank = 'C';
			} else if (sum < 80) {
				rank = 'B';
			} else {
				rank = 'A';
			}
		}
		cout << rank << endl;
		cin >> m >> f >> r;
	}

	return 0;
}

Measured memory_bytes: 1152
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long K = sc.nextLong();
    long ans =0;
    N = N%K;
    ans =N;
    for(int i=0;i<100;i++){
      N=Math.abs(N-K);
      if(N<ans){
        ans=N;
      }
    }
    System.out.println(ans);

  }
  

  
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll n,m;sc(n);sc(m);
 if(n<m)puts("0");
 else puts("10");
return 0;}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
using namespace std;
void solve(long long N, std::vector<long long> A){
    set<long long> colors;
    int ns=0;
    for(auto a:A){
        if(a/400 <8)colors.insert(a/400);
        else ns++;
    }
    int nf=colors.size();
    cout << max(1, nf) << " " << nf+ns << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {


	int a, b;
	cin >> a >> b;

	int n = b - a - 1;

	int ans = n * (n + 1) / 2;
	ans -= a;

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
N,M,X,Y = map(int,input().split())

x = list(map(int,input().split()))
y = list(map(int,input().split()))
x_max = max(x)
y_min = min(y)


flg = True
if x_max < y_min:
  if X < Y - 1:
    if X < y_min:
      if x_max < Y: 
        print("No War")
        flg = False

if flg:
  print("War")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int n;  cin >> n; 
    vector<int>a(n);
    vector<int>b(n);
    vector<int>c(n-1);
    rep(i, n)	cin >> a[i];
    rep(i, n)	cin >> b[i];
    rep(i, n-1)	cin >> c[i];
    //solve
    int ans = 0;
    rep(i, n){
	ans += b[i];
	if(i<n-1){
	    if(a[i]+1==a[i+1]){
		ans += c[a[i]-1];
	    }
	}
    }
    cout << ans << endl;	
    return 0;
}


Measured memory_bytes: 256
// finish date: 2018/12/15

#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)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    string S;
    cin >> S;
    ll ans = 0;
    vi cntW(S.length(), 0);
    if (S[S.length() - 1] == 'W') cntW[S.length() - 1] = 1;
    for (int i = S.length() - 2; i >= 0; i--) {
        cntW[i] = cntW[i + 1];
        if (S[i] == 'W') cntW[i]++;
    }
    rep(i,S.length()){
        if(S[i]=='B') ans += cntW[i];
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 1412
#include <algorithm>
#include <array>
#include <assert.h>
#include <chrono>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;

typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
mt19937 rnd(228 + 1488 + 239 + 24111997 % 322 + std::hash<std::string>()("Tsypkokokokoko is gay"));
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
  cout.flush();
  cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}


#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((ll)(x).size())
#define popcnt(x) (__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template <typename T>
void update_max(T& x, T y) { x = max(x, y); }
template <typename T>
void update_min(T& x, T y) { x = min(x, y); }
template <typename T>
T min(T x, T y, T z) { return min(x, min(y, z)); }
template <typename T>
T max(T x, T y, T z) { return max(x, max(y, z)); }

ll get_bit(ll m, ll i) {
  return (m >> i) & 1;
}

void set_bit(ll& m, ll i) {
  m |= (1LL << i);
}

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }


ll kek(ll x) {
  ll ans = 1;
  while (x /= 2) { ++ans; }
  return ans;
}


int main() {
  cout << fixed << setprecision(20);
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  ll h;
  cin >> h;
  cout << ((1LL << kek(h)) - 1);

  print_time();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>ty[3];
main()
{
	int t,p;
    scanf("%d",&t);
    for(int i = 0;i < t;i++)
    {
        scanf("%d",&p);
        if(p%4==0)
        {
            ty[0].push_back(p);
        }
        else if(p%2!=0)
        ty[1].push_back(p);
        else
        ty[2].push_back(p);
    }
    if(ty[1].size()==0)
    {
        printf("Yes");
        return 0;
    }
    if(ty[0].size()>=ty[1].size()-1)
    {
        if(ty[0].size()>ty[1].size()-1)
        printf("Yes");
        else
        {
            if(ty[2].size()!=0)
            printf("No");
            else
            printf("Yes");
        }
    }
    else
    printf("No");
}
/*
2 4 2 5 5
*/


Measured memory_bytes: 1012
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	int n, m;
	cin >> n >> m;

	vector< int> in(m);
	for (int &e : in) cin >> e;

	int s = accumulate(begin(in), end(in), 0);

	cout << max(-1, n - s) << endl;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define printd(x) printf("%.12f\n", ans);
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main(void) {
    map<int, int> mp;
    int n;
    cin >> n;
    rep (i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }

    for (auto x: mp) {
        if (x.second == 2) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

    char c = Math.abs(a - x) < Math.abs(b - x) ? 'A' : 'B';
    System.out.println(c);

  }
}

Measured memory_bytes: 35608
#include <stdio.h>
#include <string.h>
int main(void){
    char s[100000+5];
    scanf("%s", s);
    int n=strlen(s);
    
    int i=0, ans[100000]={0};
    
    while(i<n){
        int r=0, l=0;
        while(s[i]=='R'){
            i++;
            r++;
        }
        int p=i;
        while(s[i]=='L'){
            i++;
            l++;
        }
        ans[p-1]=(r+1)/2+l/2;
        ans[p]=r/2+(l+1)/2;
    }
    for(int i=0; i<n; i++){
        printf("%d", ans[i]);
        if(i<n-1)printf(" ");
    }
    return 0;
}


Measured memory_bytes: 2192
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<cfloat>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(scanf("%d",&n),n){
    char buff[n][n+1];
    REP(i,n) scanf("%s",buff[i]);

    int ans = 0;

    REP(i,n){
      int cnt = 0;
      REP(j,n){
	if(buff[i][j] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

    REP(j,n){
      int cnt = 0;
      REP(i,n){
	if(buff[i][j] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

    REP(i,n){
      int cnt = 0;
      REP(j,n-i){
	if(buff[i+j][j] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

    REP(i,n){
      int cnt = 0;
      REP(j,n-i){
	if(buff[j][i+j] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

    REP(i,n){
      int cnt = 0;
      REP(j,i+1){
	if(buff[j][i-j] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

    REP(i,n){
      int cnt = 0;
      REP(j,i+1){
	if(buff[n-j-1][n-(i-j)-1] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

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

Measured memory_bytes: 0
/*
23280701537353
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
//#define   Y            imag()
//#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
//#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
//#define    dp(a,b)          (((conj(a))*(b)).real())
//#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
//#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     PT                    complex<double>
#define outfile freopen("out.out", "w", stdout);
#define infile  freopen("in.in", "r", stdin);
#define PI acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void FS(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

int main()
{
    int a,b;
    cin>>a>>b;
    if(abs(a-b)%2==0)
        cout<<min(a,b)+abs(a-b)/2<<endl;
    else
        cout<<"IMPOSSIBLE"<<endl;
}






























Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

char c;
string s;
int ans,size,a,n;

int get_int(){

  size = s.size();
  a = 1;
  n = 0;
  for( int i = size - 1 ; i >= 0 ; i-- ){
    n += ( s[i] - '0' ) * a;
    a *= 10;
  }
  return n;
}

int main(void){

  s = "";
  ans = 0;

  while( scanf("%c",&c) != EOF ){
    if( '0' <= c && c <= '9' ){
      s += c;
    }
    else {
      ans += get_int();
      s = "";
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1200
c = [0 for i in range(3)]
for i in range(3):
    c[i] = list(map(int,input().split()))

sum_yoko = [0 for i in range(3)]
for i in range(3):
    sum_yoko[i] = sum(c[i])
    
sum_tate = [0 for i in range(3)]
for i in range(3):
    sum_tate[i] = c[0][i]+c[1][i]+c[2][i]
    
b1mb2 = (sum_yoko[0]-sum_yoko[1])/3
b2mb3 = (sum_yoko[1]-sum_yoko[2])/3
b3mb1 = (sum_yoko[2]-sum_yoko[0])/3
a1ma2 = (sum_tate[0]-sum_tate[1])/3
a2ma3 = (sum_tate[1]-sum_tate[2])/3
a3ma1 = (sum_tate[2]-sum_tate[0])/3

chk =[b1mb2,b2mb3,b3mb1,a1ma2,a2ma3,a3ma1]

flg = 0
for i in chk:
    if (i*10)%10 != 0:
        flg = 1

if flg == 1:
    print("No")
else:
    print("Yes")

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

struct Card{char suit, value;};

void Buble(Card A[], int N){
  for(int i=0;i<N;++i){
    for(int j=N-1;j>i;--j){
      if(A[j].value < A[j-1].value) swap(A[j], A[j-1]);
    }
  }
}

void Selection(Card A[], int N){
  for(int i=0;i<N;++i){
    int minj=i;
    for(int j=i;j<N;++j){
      if(A[j].value<A[minj].value) minj=j;
    }
    swap(A[i], A[minj]);
  }
}

void Print(Card A[], int N){
  for(int i=0;i<N;++i){
    if(i!=N-1) cout << A[i].suit << A[i].value << " ";
    else cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(Card C1[], Card C2[], int N){
  for(int i=0;i<N;++i){
    if(C1[i].suit!=C2[i].suit) return false;
  }
  return true;
}

int main() {
    Card C1[36], C2[36]; int N; cin >> N;
    for(int i=0;i<N;++i){
      cin >> C1[i].suit >> C1[i].value;
      C2[i]=C1[i];
    }
    Buble(C1, N);
    Selection(C2, N);
    Print(C1, N);
    cout << "Stable" << endl;
    Print(C2, N);
    cout << (isStable(C1, C2, N)?"Stable":"Not stable") << endl;
    return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>

int dp[45];

int fib(int n){

  if(n==0){
    return 1;
  } else if(n==1){
    return 1;
  } else if(n>=2){
    if(dp[n]!=0)return dp[n];
    dp[n] = fib(n-1)+fib(n-2);
    return dp[n];
  }
}

int main(){
  int n;
  int i;
  for(i=0;i<45;i++)dp[i]=0;
  scanf("%d",&n);
  n=fib(n);
  printf("%d\n",n);
  
  return 0;
}

Measured memory_bytes: 596
var x = require('fs').readFileSync('/dev/stdin', 'utf8');
var n = x.split(" ");
var a = parseInt(n[0]);
var b = parseInt(n[1]);
if (a < b){
    console.log("a < b");
}
else if (a > b){
    console.log("a > b");
}
else if (a == b){
    console.log("a == b")
}


Measured memory_bytes: 15096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());

int main() {
  string S;
  cin >> S;
  if (S == "ABC")
    cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
}

Measured memory_bytes: 3624
#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>;
const int inf{int(1e9)};
int main(void){
  int N, M;
  cin >> N >> M;
  // vector <int> s(M);
  // vector <int> c(M);
  vector <P> p(M);
  rep(i,M) cin >> p[i].first >> p[i].second;
  rep(x,1000){
    bool ok = true;  //フラグ
    vector <int> d(1, x%10);  //各桁を格納
    int nx = x / 10;
    while (nx){
      d.push_back(nx%10);
      nx /= 10;
    }
    reverse(d.begin(), d.end());
    if (d.size() != N) continue;
    rep(i,M){
      if (d[p[i].first - 1] != p[i].second) ok = false;
    }
    if (ok){
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


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

int main(void){
  string s;
  cin >> s;
  string res("No");
  for(int i=0;i!=3;i++){
    if(s[i]=='7'){
      res="Yes";
    }
  }
  cout << res << endl;
  return 0;
}


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

int N, X;
vector<int> bounce;

int main(){
	int b;
	scanf("%d %d", &N, &X);
	for (int i = 0; i < N; ++i) {
		scanf("%d", &b);
		bounce.push_back(b);
	}
	int coor = 0, times = 1;
	for (auto it = bounce.begin(); it < bounce.end(); ++it) {
		if (coor + *it <= X) {
			coor += *it;
			times++;
		}
		else break;
	}
	printf("%d\n", times);
}


Measured memory_bytes: 256
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]


def main():
    n, m, q = na()
    lrs = [na() for _ in range(m)]
    pqs = [na() for _ in range(q)]

    table = [[0] * (n+1) for _ in range(n+1)]

    # 
    for l, r in lrs:
        table[l][r] += 1

    # 行方向の累積和
    for i in range(1, n+1):
        for j in range(1, n+1):
            table[i][j] += table[i][j-1]

    # 列方向の累積和
    for j in range(1, n+1):
        for i in range(1, n+1):
            table[i][j] += table[i-1][j]
            
    for p, q in pqs:
        v = table[q][q] - table[q][p-1] - table[p-1][q] + table[p-1][p-1]
        print(v)
    

main()

Measured memory_bytes: 99932
from sys import stdin
import heapq
def main():

    input = stdin.readline

    N = int(input())
    S = input()[:-1]

    R_num = S.count("R")
    G_num = S.count("G")
    B_num = S.count("B")

    ans_sum = R_num*G_num*B_num

    for i in range(N):
        for j in range(1,((N-i-1)//2)+1):
            if (S[i] != S[i+j]) & (S[i+j] != S[i+j*2]) & (S[i] != S[i+j*2]):
                ans_sum -= 1

    print(ans_sum)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 9268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll MOD2=1e9+9;
const ll N=2e5+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll n,a;
ld ans;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);	
	cin>>n;
	while(n--){
		cin>>a;
		ans+=1.0/a;
	}
	cout<<fixed<<setp(12)<<1.0/ans<<"\n";
	return 0;
}




Measured memory_bytes: 256
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = []
for i in range(N):
    heapq.heappush(B,-A[i])

for i in range(M):
    x = -heapq.heappop(B)
    if x == 0:
      break
    x = x//2
    heapq.heappush(B,-x)

print(-sum(B))

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

int main() {
  int n, m;
  cin >> n >> m;
  
  cout << (n - 1) * (m - 1) << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <cassert>
using namespace std;
bool ProximaPalabra(string palabra,char let)
{
		map<char, int> letras;
		for (int i = 0;i <= ('z' - 'a');i++) {
			letras['a' + i] = i;
		}
		
		int palabraarray[26];

		for(int i=0; i<26;i++)
		{
			palabraarray[i] = -1;
		}
		
	
		for(int i=0;i<(int)palabra.length();i++)
		{
			palabraarray[letras[palabra[i]]]=0;
		}
		if(let!=-1){
			for(int i=0;i<let - 'a' + 1;i++)
			{
				palabraarray[i]=0;
			}
		}
		int letrafaltante=-1;
	
		for(int i=0;i<26;i++)
		{
			if(palabraarray[i]==-1)
			{
				letrafaltante=i;
				break;
			}
		}

		if (letrafaltante == -1) return false;
		cout<<palabra+ (char)('a' + letrafaltante)<<endl;	
		return true;
	
}
int main() 
{
	//~ freopen("input.in", "r", stdin);
	string palabra;
	cin>>palabra;

	

	if(palabra.length()!=26)
	{
		ProximaPalabra(palabra,-1);
	}
	else
	{
		string palabraNueva="";
		int i=0;
		while(palabra[i]>palabra[i+1]&& i<25)
		{
			palabraNueva+=palabra[i];
			i++;
		}

		if(palabraNueva.size()==25 && palabraNueva[24]=='b')
		{
			cout<< -1 <<endl;
		
		}else
		{
			//~ vector<int> j;
			//~ for(int i=0;i<((int)(palabra.size()) - 1);i++)
			//~ {
				//~ if(palabra[i]>palabra[i+1])
				//~ {
					//~ j.push_back(i);
				//~ }
			//~ }
			
			for (int j = (int)(palabra.size()) - 1;j >= 0;j--) {
				if (ProximaPalabra(palabra.substr(0, j),palabra[j])) break;
			}
			
		}
		
	}
	
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
// 16:08-
const string P1="Fennec",P2="Snuke";
const int MAX_N=1e5+1;
int N;
VI E[MAX_N];
int C[MAX_N];

VI P;
void dfs(int u, int pre, VI &cur) {
  cur.push_back(u);
  if(u==N) {
    P=cur;
    return;
  }
  FORR(v,E[u]) if(v!=pre) {
    dfs(v,u,cur);
  }
  cur.pop_back();
}
void dfs2(int u, int c) {
  FORR(v,E[u]) if(C[v]==0) {
    dump2(v,c);
    C[v]=c;
    dfs2(v,c);
  }
}

void solve() {
  VI p={};
  dfs(1,-1,p);
  dumpAR(P);
  assert(SZ(P));
  ZERO(C);
  int l=0,r=SZ(P)-1;
  VI Q1,Q2;
  while(l<r) {
    Q1.push_back(P[l]),Q2.push_back(P[r]);
    C[P[l++]]=1,C[P[r--]]=2;
  }
  dump2(C[P.front()],C[P.back()]);
  dumpAR(Q1);
  dumpAR(Q2);
  FORR(u,Q1) dfs2(u,1);
  FORR(u,Q2) dfs2(u,2);
  
  int cnt[3]={};
  REPE(i,N) cnt[C[i]]++;
  dump2(cnt[1],cnt[2]);
  string res=cnt[1]>cnt[2]?P1:P2;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  REPE(i,N) E[i].clear();

  cin>>N;
  REP(i,N-1) {
    int u,v;
    cin>>u>>v;
    E[u].push_back(v),E[v].push_back(u);
  }
  solve();
  return 0;
}


Measured memory_bytes: 13944
#include <iostream>
#define int long long
using namespace std;
int X, Y, S;
int tax(int x, int p){
    return p*(100+x)/100;
}
int solve(int x, int y, int s){
    int max = 0;
    for(int i=1; i<s; i++){
        for(int j=1; j<s; j++){
            if(tax(x, i) + tax(x, j) == s){
                int t = tax(y, i) + tax(y,j);
                max = (max > t)? max: t;
            }
        }
    }
    return max;
}

signed main(){
    while(cin >> X >> Y >> S && X > 0){
        cout << solve(X, Y, S) << endl;
    }
}


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

int main(void) {
  int K, A, B;
  cin >> K >> A >> B;
  string s;
  
  s = "NG";
  
  for(int i=A; i<=B; i++){
    if(i % K == 0){
      s = "OK";
      break;
    }
  }
  
  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int A, B; cin >> A >> B;
	cout << (A >= 13?B:(A <= 5?B-B:B/2)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std;

int main(){

	int n;
	cin>>n;

	vector<int> p(n);
	for(int i=0;i<n;i++) cin>>p[i];

	int res=0;
	for(int i=0;i<n-1;i++){
		if(p[i]==i+1) swap(p[i],p[i+1]),res++;
	}
	if(p[n-1]==n) res++;

	cout<<res<<endl;

	return 0;
}


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

using namespace std;

int main()
{
    int n;  cin >> n;
    vector<int> t(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    int m;  cin >> m;
    vector<int> p(m);
    vector<int> x(m);
    for (int i = 0; i < m; ++i) {
        cin >> p[i] >> x[i];
    }

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        ans = ans + t[i];
    }

    for (int i = 0; i < m; ++i) {
        cout << (ans - t[p[i] - 1]) + x[i] << endl;
    }
}

Measured memory_bytes: 256
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
	string s;
	cin >> s;
	const int n = s.size();
	map<int, int> hash;
	const int p = 2019;
	hash[0]++;
	int ans = 0;
	int pwr = 1;
	int suffix = 0;
	for (int i = n - 1; ~i; i--) {
	   // cout << (s[i] - '0') * pwr << " ";
		suffix = (suffix + (s[i] - '0') * pwr) %p;
		ans += hash[suffix];
// 		cout << ans;
		hash[suffix]++;
// 		cout << pwr << " ";
		pwr = pwr * 10 % p;
	}
	cout << ans << endl;
}
int32_t main() {
	BOLT;
	solve();
}

Measured memory_bytes: 3768
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int h, n, i = 0;
	cin >> h >> n;
	vector<pair<int, int>>vec(n);
	rep(i, n) {
		cin >> vec[i].first >> vec[i].second;
	}
	vector<int>DP(100000000,0);//魔力をiとしDP[i]をダメージとする
	DP[0] = 0;
	while(1) {
		i++;
		rep(j, n) {
			if (i - vec[j].second >= 0) {
				DP[i] =max(DP[i],DP[i - vec[j].second] + vec[j].first);
				if (DP[i] >= h) {
					cout << i << endl;
					return 0;
				}
			}
		}
	}
}




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

int main() {
    string s;
    string ans = "Yes";
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(i%2 == 0){
            if(s.at(i) == 'L')ans = "No";
        }else{
            if(s.at(i) == 'R')ans = "No";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys 
input = sys.stdin.readline
import itertools

def Washall_Floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d

n, m, r = map(int, input().split())
R = list(map(int, input().split()))
f_inf = float('inf')
dist = [[f_inf]*n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    dist[a][b] = c
    dist[b][a] = c

Washall_Floyd(dist)
S = [i for i in itertools.permutations(R, r)]
cnt = f_inf
for s in S:
  tmp = 0
  for i in range(len(s)-1):
    tmp += dist[s[i]-1][s[i+1]-1]
  cnt = min(cnt, tmp)
print(cnt)


Measured memory_bytes: 62300
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    //final List<Integer> list2 = new ArrayList<>();
    //final List<Long> list3 = new ArrayList<>();

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int sum = 0;
    int sum2 = 1001001001;

    if(a + b >= 2*c){
        if(x>=y){
                sum += y*2*c;
                sum += (x-y)*a;
        }else{
                sum += x*2*c;
                sum += (y-x)*b;
        }
    }else{
        sum += a*x + b*y; 
    }

    if(a + b >= 2*c){
        if(x>=y){
            sum2 = x*2*c;
        }else{
            sum2 = y*2*c;
        }
    }

    System.out.println(Math.min(sum,sum2));

    

    




    







}
}

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

using namespace std;

template <typename T>
inline T read()
{
	T x = 0;
	char ch = getchar();
	bool f = 0;
	while(ch < '0' || ch > '9')
	{
		f = (ch == '-');
		ch = getchar();
	}
	while(ch <= '9' && ch >= '0')
	{
		x = ((x + (x << 2)) << 1) + (ch - '0');
		ch = getchar();
	}
	return  f? -x : x;
}

template <typename T>
void put(T x)
{
	if(x < 0)
	{
		x = -x;
		putchar('-');
	}
	if(x < 10) {
		putchar(x + 48);
		return;
	}
	put(x / 10);
	putchar(x % 10 + 48);
	return ;
}

#define reg register
#define rd read <int>
#define pt(i) put <int> (i), putchar(' ')

typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned long long ull;
typedef unsigned int ui;

const int Maxn = 2e5 + 111;

ll n, sum;

int main()
{
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
#endif
	cin >> n;
	sum = (n + 1) * n / 2;
	for(int i = 1; i <= n; ++i)
	{
		if(i % 3 == 0 || i % 5 == 0) sum -= i;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3632
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a%2!=b%2) cout<<"IMPOSSIBLE"<<endl;
	else cout<<(a+b)/2<<endl;
}*/
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int f[55];
	cin>>n;
	int num=0;
	for(int i=1;i<=n;i++)
	{
		cin>>f[i];
		if(f[i]!=i) num++;
	}
	if(num<=2) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int f[100010];
	int a[100010];
	for(int i=1;i<=n+1;i++) cin>>f[i];
	for(int i=1;i<=n;i++) cin>>a[i];
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=f[i]) ans+=(long long)f[i],a[i]-=f[i],f[i]=0;
		else ans+=(long long)a[i],f[i]-=a[i],a[i]=0;
		if(a[i]>=f[i+1]) ans+=(long long)f[i+1],a[i]-=f[i+1],f[i+1]=0;
		else ans+=(long long)a[i],f[i+1]-=a[i],a[i]=0;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

int n;

void gen(string cur, VI& cnt) {
  if ((int)cur.size() == n) {
    cout<<cur<<"\n";
    return;
  }
  for (int i = 0; i < 26; ++i) {
    ++cnt[i];
    cur += (char)(i+'a');
    gen(cur, cnt);
    cur.pop_back();
    --cnt[i];
    if (cnt[i] == 0)
      break;
  }
}

int main() {
  init_ios();
  cin >> n;
  VI cnt(26);
  string s = "";
  gen(s, cnt);
}

Measured memory_bytes: 1536
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main (void)
{
    int n,i,k=0;
    scanf("%d",&n);
    char s[n][11];
    for(i=0;i<n;i++){
        scanf("%s",s[i]);
    }
  
    qsort(s,n,11,strcmp); 
    for(i=0;i<n-1;i++){
        if(strcmp(s[i],s[i+1])!=0)
            k++;
    } 
    printf("%d",k+1);
  return 0;
}

Measured memory_bytes: 5740
N, K = gets.chomp.split.map(&:to_i)
h = gets.chomp.split.map(&:to_i)

dp = Array.new(N, Float::INFINITY)

dp[0] = 0

for i in 0..N-2
  for j in 1..[N-i-1, K].min
    c = dp[i] + (h[i+j] - h[i]).abs
    dp[i+j] = c if c < dp[i+j]
  end
end

puts dp.last

Measured memory_bytes: 12036
#define DEBUG 0

/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 5/19/2019, 9:14:18 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
typedef tuple<ll, int> edge;
vector<edge> V[100010];
int visited[100010];

void dfs(int v, int from, ll d)
{
  if (visited[v] >= 0)
  {
    return;
  }
  if (from == -1)
  {
    visited[v] = 0;
  }
  else
  {
    if (d % 2 == 0)
    {
      visited[v] = visited[from];
    }
    else
    {
      visited[v] = 1 - visited[from];
    }
  }
  for (auto x : V[v])
  {
    ll dist = get<0>(x);
    int w = get<1>(x);
    dfs(w, v, dist);
  }
}

int main()
{
  cin >> N;
  for (auto i = 0; i < N - 1; i++)
  {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    u--;
    v--;
    V[u].push_back(edge(w, v));
    V[v].push_back(edge(w, u));
  }
  fill(visited, visited + 100010, -1);
  dfs(0, -1, 0);
  for (auto i = 0; i < N; i++)
  {
    cout << visited[i] << endl;
  }
}

Measured memory_bytes: 9088
#include<iostream>
using namespace std;
int main()
{
  long long a,b;
  cin>>a>>b;
  for(int i=1; i<=b; i++)
  {
    if((a*i)%b==0)
    {
      cout<<a*i<<endl;
      break;
    }
  }
  return 0;
}
  


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

signed main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A[i];
  sort(A.begin(), A.end(), greater<int>());

  int sum =0;
  for(int i=0; i<N; i++) sum+=A[i];

  int l = sum / (4*M);
  for(int i=0; i<M; i++) {
    if(A[i]*4*M < sum) { puts("No"); return 0;}
  }
  puts("Yes");
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef int64_t ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst) : src(src), dst(dst), weight(1) {}
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int main(){
  int N, M;
  cin >> N >> M;
  Graph g(N);
  vector<vector<int>> dist(N, vector<int> (N, INF));
  REP(i, N) dist[i][i] = 0;
  REP(i, M) {
    int a, b, c;
    cin >> a >> b >> c; --a; --b;
    dist[a][b] = dist[b][a] = c;
    g[a].push_back(Edge(a, b, c));
    g[b].push_back(Edge(b, a, c));
  }
  REP(k, N) REP(i, N) REP(j, N) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

  int ret = 0;
  REP(i, N) for(Edge e : g[i]) {
    if(dist[e.src][e.dst] < e.weight) ++ret;
  }
  ret /= 2;

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
int n;
int a[nax];
long long ans = 1000;
long long cur = 1000;
long long stk = 0;

int main () {
    scanf("%d", &n);
    for (int i = 1 ; i <= n ; ++ i) {
        scanf("%d", a + i);
    }

    for (int i = 1 ; i < n ; ++ i) {
        if (a[i] < a[i + 1]) {
            stk += cur / a[i];
            cur %= a[i];
        }

        if (a[i] >= a[i + 1]) {
            cur += stk * a[i];
            stk = 0;
        }

        ans = max(ans, cur);
    }

    cur += stk * a[n];
    ans = max(ans, cur);
    printf("%lld\n", ans);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
long double coins[3005];
int n;
long double dp[3005][3005][3];

int main(){
   
    cin >> n;
    for(int i=1;i<=n;i++) cin >> coins[i];
    
    
    for(int i=n;i>=0;i--){
        for(int j=n;j>=0;j--){
            for(int k=1;k>=0;k--){
                if(i==n){
                    if(j<=(n/2)) dp[i][j][k]=0;
                    else if(k==1) dp[i][j][k]=coins[i];
                    else dp[i][j][k]=1-coins[i];
                }
                
                else{
                    long double t1,t2;
                    if(i==0){
                        t1=dp[i+1][j][0];
                        t2=dp[i+1][j+1][1];
                    }
                    else if(k==1){
                        t1=dp[i+1][j][0]*coins[i];
                        t2=dp[i+1][j+1][1]*coins[i];
                    }
                    else{
                        t1=dp[i+1][j][0]*(1-coins[i]);
                        t2=dp[i+1][j+1][1]*(1-coins[i]);
                    }
                    dp[i][j][k]=t1+t2;
                }
            }
        }
    }
    printf("%0.12Lf\n",dp[0][0][0]);
}

Measured memory_bytes: 426324
#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;

const int N=100000,mod=1000000007;
int n,m;
int f[N+5],a[N+5];

int main(void){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	scanf("%d",&a[i]),
	f[a[i]]=-1;
	f[0]=1;
	for(int i=1;i<=n;i++){
		if(f[i]==-1)continue;
		int s=0;
		if(f[i-1]!=-1)s+=f[i-1];
		if(f[i-2]!=-1)s+=f[i-2];
		f[i]=s%mod;
	} 
	printf("%d\n",f[n]);
}


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

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


#define FOR(i, s, e) for (int (i) = (s); (i) < (e); (i)++)

int main() {
    int D, G; cin >> D >> G;
    int p[11], c[11];
    FOR(i, 0, D) cin >> p[i] >> c[i]; 


    int mini = 1 << 30;

    FOR(bit, 0, (1<<D)) {
        int sum = 0, num = 0;
        FOR(i, 0, D) {
            if (bit & (1<<i)) {
                sum += (i + 1) * 100 * p[i];
                sum += c[i];
                num += p[i];
            }
        }

        if (sum >= G) {
            chmin(mini, num);
        }
        else {
            FOR(i, 0, D) {
                if(!(bit & (1<<i))) {
                    FOR(j, 1, p[i]) {
                        sum += (i + 1) * 100 * j;
                        num += j;
                        if (sum >= G) {
                        chmin(mini, num);
                        sum -= (i + 1) * 100 * j;
                        num -= j;
                        break;
                        }
                        sum -= (i + 1) * 100 * j;
                        num -= j;
                    }
                }
            }
        }
    }

    printf("%d\n", mini);
}



Measured memory_bytes: 256