akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

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

    k = min(k, 100);
    while (k--) {
        vector<int> b(n + 1);
        for (int i = 0; i < n; i++) {
            b[max(0, i - a[i])]++;
            b[min(n, i + a[i] + 1)]--;
        }
        for (int i = 0; i < n; i++) b[i + 1] += b[i];
        for (int i = 0; i < n; i++) a[i] = b[i];
    }
    for (int i = 0; i < n; i++) {
        cout << a[i] << " \n"[i == n - 1];
    }
    return 0;
}


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

constexpr long long INF = ((long long)1<<31)-1;

class SegTree{
public:
	int N;
	vector<long long> Dat;
	SegTree(int n){
		if((n & (n - 1)) == 0) N = n;
		else{
			N = 1;
			while(n > 0){
				N <<= 1;
				n >>= 1;
			}
		}
		Dat.resize(2 * N - 1, INF);
	}

	void update(int i, int x){ // a[i] <- x
		i += N - 1;
		Dat[i] = x;
		while(i > 0){
			i = (i - 1) / 2;
			Dat[i] = min(Dat[i * 2 + 1], Dat[i * 2 + 2]);
		}
	}

	long long find(int a, int b, int k, int l, int r){ // return min of [a, b) in node k
		if(r < a || b <= l) return INF;
		if(a <= l && r < b) return Dat[k];
		long long vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
		long long vr = find(a, b, k * 2 + 2, 1 + (l + r) / 2, r);
		return min(vl, vr);
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	SegTree st(n);
	while(q--){
		int t, x, y;
		cin >> t >> x >> y;
		if(t == 0) st.update(x, y);
		else cout << st.find(x, y+1, 0, 0, st.N-1) << "\n";
	}
}


Measured memory_bytes: 4888
from collections import deque
H, W = map(int,input().split())
sl = []
for _ in range(H):
    sl.append(list(input()))



for i in range(H):
    for j in range(W):
        if sl[i][j] == '#':
            continue

        cnt = 0
        directions = [[1, 0], [0, 1], [-1, 0], [0, -1], [1, 1], [-1, -1], [1, -1], [-1, 1]]
        for d in directions:
            y,x = i+d[0],j+d[1]
            if i+d[0] >= H:
                continue
            if i+d[0] < 0:
                continue
            if j+d[1] >= W:
                continue
            if j + d[1] < 0:
                continue
            if sl[y][x] == '#':
               cnt += 1
        sl[i][j] = str(cnt)

for v in sl:
    print(''.join(v))



Measured memory_bytes: 9516
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VL T(N),A(N);
    VL conf(N,-1);
    REP(i,N){
        cin >> T[i];

        if(i == 0){
            conf[i] = T[i];
            //if(conf[i] > A[i]){
            //    cout << 0 << endl;
            //    return 0;
            //}
            continue;
        }
        if(T[i-1] != T[i]){
            conf[i] = T[i];
            //if(conf[i] > A[i]){
            //    cout << 0 << endl;
            //    return 0;
            //}

        }
    }

    REP(i,N) cin >> A[i];

    REP(i,N){
        dump(i)
        dump(conf[i])
        if(i == N-1){
            if(conf[i] == -1){
                conf[i] = A[i];
            }
            else{
                if(conf[i] != A[i]){
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
        else{
            if(A[i] != A[i+1]){
                if(conf[i] == -1) conf[i] = A[i];
                else{
                    if(conf[i] != A[i]){
                        cout << 0 << endl;
                        return 0;
                    }
                }
            }
        }
    }
    //cout << printVector(conf) << endl;
    REP(i,N){
        if(conf[i] == 1) continue;

        if(min(T[i],A[i]) < conf[i]){
            cout << 0 << endl;
            return 0;
        }
    }

    LL ans = 1;
    REP(i,N){
        if(conf[i] != -1) continue;

        ans = (ans * min(T[i],A[i])) % MOD;
    }
    cout << ans << endl;
}

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

int main() {
  int n,a[4][13]={};
  cin>>n;
  int i=0;
  while(i<n){
    char suit;
    int rank;
    cin>>suit>>rank;
    i++;
    switch(suit){
      case 'S':
        a[0][rank-1]=1;
        break;
      case 'H':
        a[1][rank-1]=1;
        break;
      case 'C':
        a[2][rank-1]=1;
        break;
      case 'D':
        a[3][rank-1]=1;
        break;
    }
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<13;j++){
      if(a[i][j]!=1){
        if(i==0){
          cout<<'S'<<" ";
        }else if(i==1){
          cout<<'H'<<" ";
        }else if(i==2){
          cout<<'C'<<" ";
        }else if(i==3){
          cout<<'D'<<" ";
        }
      cout<<j+1<<endl;
      }
    }
  }
}


Measured memory_bytes: 3084
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

string s[105];
signed main(void)
{
	int h, w;
	cin >> h >> w;
	REP(i, h) cin >> s[i];

	REP(i, w+2) cout << '#'; cout << endl;
	REP(i, h) cout << "#" << s[i] << "#" << endl;
	REP(i, w+2) cout << "#"; cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fp(i,l,r) for(register int (i)=(l);(i)<=(r);++(i))
#define fd(i,l,r) for(register int (i)=(l);(i)>=(r);--(i))
#define fe(i,u) for(register int (i)=front[(u)];(i);(i)=e[(i)].next)
#define mem(a) memset((a),0,sizeof (a))
//#define int long long
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return x*f;
}
void wr(int x){
    if(x<0)x=-x,putchar('-');
    if(x>=10)wr(x/10);
    putchar('0'+x%10);
}
const int MAXN=1e5+10;
int cnt,n,m,q,front[MAXN],d[MAXN],vt[MAXN],c[MAXN],mx[MAXN],col[MAXN],tcnt;
struct tEdge{
    int v,next;
}e[MAXN<<1];
inline void adde(int u,int v){
    e[++tcnt]=(tEdge){v,front[u]};front[u]=tcnt;
}
void dfs(int u,int d,int c){
    //printf("%d %d %d\n",u,d,c);
    ++cnt;
    mx[u]=d;if(!col[u])col[u]=c;if(!d)return;
    fe(i,u){
        int v=e[i].v;if(d-1<=mx[v])continue;
        dfs(v,d-1,c);
    }
}
main(){
    n=read();m=read();
    fp(i,1,m){
        int a=read(),b=read();
        adde(a,b);adde(b,a);
    }
    q=read();
    fp(i,1,q)
        vt[i]=read(),d[i]=read(),c[i]=read();
    memset(mx,-1,sizeof mx);
    fd(i,q,1){
        if(d[i]<=mx[vt[i]])continue;
        dfs(vt[i],d[i],c[i]);
    }
    fp(i,1,n)
        wr(col[i]),putchar('\n');
    return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N, M, K;
vector<pii> reds;
vector<pii> blues;
//=============================
void input()
{
    cin >> N;
    reds.resize(N);
    blues.resize(N);
    rep(i, N)
    {
        cin >> reds[i].first >> reds[i].second;
    }
    rep(i, N)
    {
        cin >> blues[i].first >> blues[i].second;
    }
}
//=============================
void func() {}
//=============================
void solve()
{
    sort(blues.begin(), blues.end());
    sort(reds.begin(), reds.end(), [](const pii &a, const pii &b) {
        return a.second > b.second;
    });

    set<int> rr;
    int ans = 0;
    for (auto b : blues)
    {
        for (auto r : reds)
        {
            if (rr.find(r.second) == rr.end() && b.first > r.first && b.second > r.second)
            {
                ans++;
                rr.insert(r.second);
                break;
            }
        }
    }
    cout << ans << endl;
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

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


int main(void) {
  ll N;
  cin >> N;
  ll a[MAX];
  ll i;
  ll dp[MAX][2]={};
  
  for(i=0; i<N; i++) cin >> a[i];
  
  for(i=0; i<N; i++) {
    dp[i+1][0]=gcd(dp[i][0], a[i]);
    dp[i+1][1]=max(dp[i][0], gcd(dp[i][1], a[i]));
  }
  
  ll ans=max(dp[N][0], dp[N][1]);
  
  ll t=0;
  for(i=1; i<N; i++) {
    t=gcd(t, a[i]);
  }
  
  chmax(ans, t);
  pt(ans);
}






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

int main(void)
{
    int n; cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    sort(s.begin(), s.end());
    int ans = 1;
    for (int i = 1; i < n; i++)
    {
        if (s[i-1] == s[i]) continue;
        else ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9548
#整数の入力
A = int(input())
#スペース区切りの整数の入力リスト
S_list = list(map(int, input().split()))

A_list = []
for i in range(A):
  A_list.append(i+1)
  S_list[i] = int(S_list[i])
    

counter = 0
for i in range(A):
  if(A_list[i] != S_list[i]):
    counter = counter + 1

if((counter == 0)or(counter == 2)):
  print("YES")
else:
  print("NO")

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

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < 3;i++)
    {
        if(n%10==7)
        {
            cout << "Yes" << endl;
            break;
        }else
        {
            n /= 10;
            if(i==2)
            {
                cout << "No";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3640
n = int(input())
b = [int(i) for i in input().split()]
s = []

while len(b) > 0:
    m = -1
    for i in range(len(b)):
        if b[i] == i + 1:
            m = i
    if m == -1:
        break
    else:
        s.append(b.pop(m))

if m == -1:
    print(-1)
else:
    print(*reversed(s), sep='\n')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main(){
    int n;
    Int k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    vector<int> s;
    vector<int> ord(n+1,-1);
    int c = 1,l=0;
    {
        int v = 1;
        while(ord[v]==-1){
            ord[v] = s.size();
            s.push_back(v);
            v = a[v-1];
        }
        c = s.size()-ord[v];
        l = ord[v];
    }
    if(k<l) cout << s[k] << endl;
    else{
        k-=l;
        k%=c;
        cout << s[l+k] << endl;
    }
}

Measured memory_bytes: 5876
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#include<unordered_set>

using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,p) scanf("%d %d %d %d",&n,&m,&o,&p)
#define SINT5(n,m,o,p,q) scanf("%d %d %d %d %d",&n,&m,&o,&p,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 0x2aaaaaaa; // 715,827,882
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };

#define fs  first
#define sc  second


int main() {
	int n;
	bool f = true;
	int mi = 1000000009;

	ll sum = 0;
	SINT(n);
	rep(i, n) {
		int a, b;
		SINT2(a, b);
		if (a != b) {
			f = false;
		}
		if (a > b) {
			mi = min(mi, b);
		}
		sum += b;
	}
	if (f) {
		PLLN(0);
	} else {
		PLLN(sum - mi);
	}

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    using Double = long double;

    var(Double, L);
    const auto x = L / 3;
    cout << fixed << setprecision(12);
    print(x * x * x);

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,x,i,j,max=0;
    scanf("%i",&n);
    int a[n],b[n];
    for(i=0;i<n;i++)scanf("%i",&a[i]);
    for(i=0;i<n;i++)scanf("%i",&b[i]);
    for(j=0;j<n;j++)
    {
        x=0;
        for(i=0;i<n;i++)
        {
            if(i<=j)x=x+a[i];
            if(i>=j)x=x+b[i];
        }
        if(x>max)max=x;
    }
    printf("%i",max);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main() {
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> b.at(i);
  }

  for (int i = 1; i < N; i++) {
    a.at(i) = a.at(i) + a.at(i - 1);
    b.at(N - i - 1) = b.at(N - i - 1) + b.at(N - i);
  }

  int res = 0;
  for (int i = 0; i < N; i++) {
    int c = a.at(i) + b.at(i);
    if (c > res) {
      res = c;
    }
  }

  cout << res << endl;
}

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

typedef long long ll;

int main() {
    ll N, a, count = 0;
    cin >> N;
    priority_queue<ll> pq;
    rep(i, N) {
        cin >> a;
        pq.push(a);
    }
    while (true) {
        a = pq.top();
        pq.pop();
        if (a <= N - 1 - count) {
            cout << count << endl;
            break;
        }
        ll d = (a + 1 + count) / (N + 1);
        a -= d * (N + 1);
        count += d;
        pq.push(a);
    }
}

Measured memory_bytes: 256
import java.math.*;
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int placeCount = sc.nextInt();
			int t = sc.nextInt();
			int target = sc.nextInt();

			int[] places = new int[placeCount];
			int i = 0;
			while (i < placeCount) {
				places[i] = sc.nextInt();
				i++;
			}

			BigDecimal abs = null;
			int j = 1;
			int result = 0;
			for (int p : places) {
				BigDecimal val = getValue(t, p);

				BigDecimal wk = val.subtract(BigDecimal.valueOf(target));
				if (abs == null || abs.compareTo(wk.abs()) >= 0) {
					abs = wk.abs();
					result = j;
				}
				j++;
			}
			System.out.println(result);
		}
	}

	public static BigDecimal getValue(int t, int x) {
		return BigDecimal.valueOf(t)
			.subtract(BigDecimal.valueOf(x).multiply(BigDecimal.valueOf(0.006)));
	}
}


Measured memory_bytes: 29648
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n,m,q;
    cin>>n>>m>>q;
    vi a(q),b(q),c(q),d(q);
    vpii cmp;
    rep(i,0,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;b[i]--;
    }
    vi res(n+m-1,1);
    rep(i,0,n)res[i]=0;
    ll max=0;
    do{
        vi A(n);
        int cntone=1;
        int id=0;
        rep(i,0,n+m-1){
            if(res[i])cntone++;
            else A[id++]=cntone;
        }
        ll v=0;
        rep(i,0,q){
            if(A[b[i]]-A[a[i]]==c[i])v+=d[i];
        }
        chmax(max,v);
    }while(next_permutation(res.begin(),res.end()));
    cout<<max<<endl;
    return 0;
}




Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int dp[100000];
const int INF = 2000000000;

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    dp[i] = INF;
  }
  rep(i, n) {
    int temp;
    cin >> temp;
    int ind = lower_bound(dp, dp+n, temp) - dp;
    dp[ind] = temp;
  }
  int ans = lower_bound(dp, dp+n, INF) - dp;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3472
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 500000000
#define IOS ios_base::sync_with_stdio(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
bool check(int n,int p){return (1<<p)&n;}
const int N=100010;
int ara[N];
ll m=998244353;
ll power(ll a,ll b)     ///calculate a^b%m
{
    ll res=1;
    ll y=a;
    while(b>0)
    {
        if(b%2==1)
            res=(res*y)%m;
        y=(y*y)%m;
        b/=2;
//        cout<<"res = "<<res<<endl;
    }
    return res;
}
int aa[N];
int main()
{
    IOS;
    int n;cin>>n;
    for(int i=0;i<n;i++)
    {
        int a;cin>>a;
        aa[i]=a;
        ara[a]++;
    }
    ll res=1;
    if(ara[0]!=1||aa[0]!=0){
        cout<<0<<endl;
        return 0;
    }
    for(int i=1;i<n;i++)
    {
        res=(power(ara[i-1],ara[i])*res)%m;
    }
    cout<<res<<endl;
}








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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll res = min(k, a); k -= min(k, a);
  k -= min(k, b);
  res -= min(k, c);
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 3652
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


w,h,n=l()
r=[i for i in range(w+1)]
c=[i for i in range(h+1)]
for i in range(n):
    # print(r,c)
    a,b,x=l()
    if(x==1):
        r=r[br(r,a-1):]
    elif(x==2):
        r=r[:bl(r,a+1)]
    elif(x==3):
        c=c[br(c,b-1):]
    else:
        c=c[:bl(c,b+1)]
# print(r,c)
if(len(r)==0 or len(c)==0):
    print(0)
    exit()
print((max(r)-min(r))*(max(c)-min(c)))


Measured memory_bytes: 5120
a, b = map(int, input().split())
if b < 0:
    if (b-a+1) % 2 == 0:
        ans = 'Positive'
    elif (b-a+1) % 2 == 1:
        ans = 'Negative'

elif a > 0:
    ans = 'Positive'
else:
    ans = 'Zero'

print(ans)

Measured memory_bytes: 3060
s = gets.to_s.chomp.bytes
q = gets.to_s.to_i

lr = [[], []]
state = 0

$<.each do |query|
  
  query.chomp!
  # p query
  if query == "1"
    state = 1 - state
    # s.reverse!
  else
    if query[0,3] == "2 1"
      lr[state] << query[-1].ord
    else
      lr[1-state] << query[-1].ord
    end
  end
end

if state == 1
  puts (lr[state].reverse + s.reverse + lr[1-state] ).pack("U*")
else
  puts (lr[state].reverse + s + lr[1-state] ).pack("U*")
end

Measured memory_bytes: 10588
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int i=0;i<n;i++) cin>>h[i];
  sort(h,h+n);
  int ans=1000000010;
  for(int i=0;i<=n-k;i++){
    ans=min(ans,h[i+k-1]-h[i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <atcoder/segtree>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

ll op(ll a, ll b) {
    return max(a, b);
}

ll e() {
    return -1LL;
}

ll M;

bool f(ll x) {
    return x < M;
}

int main() {
    int N, Q;
    scanf("%d %d", &N, &Q);
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    atcoder::segtree<ll, op, e> sgt(A);

    for (int q = 0; q < Q; q++) {
        int T;
        scanf("%d", &T);
        if (T == 1) {
            int X;
            ll V;
            scanf("%d %lld", &X, &V);
            sgt.set(X-1, V);
        }
        if (T == 2) {
            int L, R;
            scanf("%d %d", &L, &R);
            printf("%lld\n", sgt.prod(L-1, R));
        }
        if (T == 3) {
            int X;
            scanf("%d %lld", &X, &M);
            printf("%d\n", sgt.max_right<f>(X-1)+1);
        }
    }
}

Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true){

		 int h = sc.nextInt();
         int w = sc.nextInt();
         if(h == 0 && w == 0) break;


		for ( int i = 0; i < h; i++ ){
		    for ( int j = 0; j < w; j++ ){
		        System.out.print("#");
		    }
		    System.out.println("");
		}
		System.out.println("");

		}

		}







	}





Measured memory_bytes: 34216
import java.io.*;
import java.util.*;
public class Main {
    private static MyScanner scanner;
 
    public static void main (String[] args){
        Main instance = new Main();
        scanner = instance.new MyScanner();
        instance.solve();
    }
 
    private void solve() {
        try {
            String s = scanner.next();
            System.out.println(s.replaceAll(",", " "));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
 
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String line = br.readLine();
            while (line.equals("")) {
                line = br.readLine();
            }
            s = line.split(reg, 0);
            i = 0;
            return s[i++];
        }
 
        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }
 
        public double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
 
        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 25044
s = list(input())
ans = 0
for i in range(1,len(s)):
    if s[i-1] == '1' and s[i] == '1':
        s[i] = '0'
        ans += 1
    elif s[i-1] == '0' and s[i] == '0':
        s[i] = '1'
        ans += 1
print(ans)

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

int main(void)
{ 

	ll i,n,W,sum=0;
	cin>>n>>W;
	vector <ll> value(n,0),weight(n,0);
	for(i=0;i<n;i++)
	{cin>>weight[i]>>value[i];
		sum+=value[i];
	}
	ll INF=1e18 + 5;
	vector <ll> dp(sum+1,INF);
	ll va;
	dp[0]=0;
	for(i=0;i<n;i++)
	{
		for(va=sum-value[i];va>=0;va--)
		{
			dp[va+value[i]]=min(dp[va+value[i]],dp[va]+weight[i]);
		}	
		
	}	
	ll ans=0;
	for(i=0;i<=sum;i++)
	{
		if(dp[i]<=W)
		{
			ans=max(ans,i);
		}
	}
	cout<<ans;
	
}

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

int main(){
	string a,b; cin>>a>>b;
	int as=a.size();
	int bs=b.size();
	if(a==b) {cout<<"EQUAL"<<endl; return 0;}
	if(as>bs) cout<<"GREATER"<<endl;
	else if(as<bs) cout<<"LESS"<<endl;
	else{
		rep(i,as){
			if(a[i]>b[i]) {cout<<"GREATER"<<endl; return 0;}
			else if(a[i]<b[i]) {cout<<"LESS"<<endl; return 0;}
		}
	}
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(0);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";


using namespace std;

ll n;



ll poww(ll a,ll b)
{
  ll res=1;
  for(ll i=1;i<=b;i++)res*=a;
  return res;
}

ll res=1;

int main(){
FLASH;
cin>>n;
ll kol=1;
ll sum=0;
for(ll i=1;i<=13;i++)
{
  res*=26LL;
  sum+=res;
  if(sum<n)kol=i+1;
  else break;	
}

sum-=res;
n-=sum;
string ans="";
for(ll i=1;i<=kol;i++)
{
  ll sim=1;
  for(ll j=1;j<=26;j++)
  {
	ll z=(j-1)*poww(26LL,kol-i)+1;
	if(z<=n)sim=j;  
  }

  n-=(sim-1)*poww(26LL,kol-i);
  ans+=('a'+sim-1);	
}

cout<<ans<<endl;


return 0;
} 


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

using namespace std;

const int MAXN = 1e5 + 5;
int tab[MAXN];
int dp[MAXN];

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

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> tab[i];
    }

    dp[0] = 0;
    dp[1] = abs(tab[1] - tab[0]);

    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i - 1] + abs(tab[i] - tab[i - 1]), dp[i - 2] + abs(tab[i] - tab[i - 2]));
    }

    cout << dp[n - 1] << "\n";
}


Measured memory_bytes: 1024
#include <stdio.h>

int main (){
   int n,l;scanf("%d %d",&n,&l);
   char s[101][101];for(int i = 0;i < n;i++){
      scanf("%s",s[i]);
   }
   //文字列はsに入れてください。また、文字数はsizeまでです。
   char x[101];
   for (int i=0; i<n; ++i) {
      for (int j=i+1; j<n; ++j) {
         if (strcmp(s[i],s[j])>0) {
            strcpy(x,s[i]);
            strcpy(s[i],s[j]);
            strcpy(s[j],x);
         }else {
            continue;
         }
      }
   }
   for(int i = 0;i < n;i++)
      printf("%s",s[i]);
}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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



int main(){
  ll n,x; cin >> n >> x; vector<string> arraystr(n);
  
  rep(i,n) cin >> arraystr[i];
  
  sort(all(arraystr));
  
  rep(i,n){
    cout << arraystr[i];
  }
  
  cout << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
     static int getTheNumberOfCoin(int C[],int n,int m){
         int T[] = new int[n + 1];
         for(int i = 1;i < n + 1;i++){
             T[i] = T[i - 1] + C[0];
         }
         for(int i = 0;i < m;i++){
             for(int j = C[i];j < n + 1;j++){
                 if(T[j] < T[j - C[i]] + 1){
                     T[j] = T[j];
                 }else{
                     T[j] = T[j - C[i]] + 1;
                 }
             }
         }
         return T[n];
     }
     public static void main(String[] args) {
         Scanner in = new Scanner(System.in);
         int n = in.nextInt();
         int m = in.nextInt();
         int C[] = new int [m]; 
         for(int i = 0;i < m;i++){
             C[i] = in.nextInt();
         }
         int min = getTheNumberOfCoin(C,n,m);
         System.out.println(min);
     }
}

Measured memory_bytes: 26976
#include<stdio.h>

int main(){
    int N,ans=0;

    scanf("%d", &N);
    char S[100000];
    scanf("%s",S);
    for (int i = 0; i < N-1; i++){
        if (S[i] != S[i+1]){
            ans++;
        }
    }
    
    printf("%d\n",ans+1);
    return 0;
}

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

int main() {

    int k,s;

    cin >> k >> s;

    int count = 0;

    for(int i = min(k,s); i >= 0; i--){
        for(int j = min(k,s-i); j >= 0; j--){
            if(s - i - j > k) break;
            count++;
        }
    }
    //
    //(s+2 C 2)

    // count = (s+2) * (s+1) / 2;

    cout << count << endl;

    return 0;
}

// int nCr(int n, int r){
//     int ans = 1;
//
//     for(int i = 0; i<r; i++){
//         ans *= (n-i);
//     }
//
//     for(int i = 0; i<r; i++){
//         ans /= (r-i);
//     }
//
//     return ans;
// }



Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n: usize = read();
    let a: Vec<usize> = (0..n).map(|_| read()).collect();

    let mut count = 0;
    for i in 0..n {
        if a[i] != i + 1 {
            count += 1;
        }
    }
    if count <= 2 {
        println!("YES");
    } else {
        println!("NO");
    }
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;

map<long long, int> mymap;

long long cnt, sum;
int n, a[200005];

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    mymap[0] = 1;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
        if(mymap.count(sum))
            cnt += mymap[sum];
        mymap[sum]++;
    }
    cout << cnt << "\n";
}


Measured memory_bytes: 13568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		sc.close();
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<n;i++) {
			sb.append(s[i]);
			sb.append(t[i]);
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;


const ll modo=1e9+7;
const ll inf=2e14;
const ll ms=(2e5) +5;

int main()
{
    idfc;
    int fl=1;
    int i;
    int n;
    cin>>n;
    int p;
    for(i=0;i<n;i++)
    {
        cin>>p;
        if(p%2)continue;
        if(p%3&&p%5)fl=0;
    }
    if(fl)cout<<"APPROVED";
    else cout<<"DENIED";
    return 0;
}

Measured memory_bytes: 256
//#include <fstream>

#include <iostream>
#include <algorithm>

using namespace std;

const int NMAX = 100005;
int n, cost[NMAX], dp[NMAX];

int main()
{
	//ifstream cin("test.in");
	//ofstream cout("test.out");
	cin >> n;
	for (int i = 1;i <= n;++i)
		cin >> cost[i];
	dp[1] = 0;
	dp[2] = abs(cost[2] - cost[1]);
	for (int i = 3;i <= n;++i)
		dp[i] = min(dp[i - 1] + abs(cost[i] - cost[i - 1]), dp[i - 2] + abs(cost[i] - cost[i - 2]));
	cout << dp[n] << "\n";
	return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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



void solve() {
	int N; cin >> N;
    vector<ll> a(N+1);
    vector<ll> b(N);
    rep(i, N+1) cin >> a[i];
    rep(i, N) cin >> b[i];

    ll res=0;
    rep(i, N){
        if(a[i] < b[i]){
            res += a[i];
            b[i] -= a[i];
            if(b[i] < a[i+1]){
                res += b[i];
                a[i+1] -= b[i];
            }else{
                res += a[i+1];
                a[i+1] = 0;
            }
        }else{
            res += b[i];
        }
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

const long long MOD = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> is_a_has(n * m + 1), is_b_has(n * m + 1);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (is_a_has.at(a)) {
            cout << 0 << endl;
            return 0;
        }

        is_a_has.at(a) = true;
    }
    for (int i = 0; i < m; i++) {
        int b;
        cin >> b;
        if (is_b_has.at(b)) {
            cout << 0 << endl;
            return 0;
        }

        is_b_has.at(b) = true;
    }

    long long ans = 1;
    long long cnt_a = 0, cnt_b = 0;
    for (int i = n * m; i >= 1; i--) {
        if (!is_a_has.at(i) && !is_b_has.at(i)) {
            ans *= max(0ll, (cnt_a * cnt_b - (n * m - i))) % MOD;
            ans %= MOD;
        }
        else if (is_a_has.at(i) ^ is_b_has.at(i)) {
            if (is_a_has.at(i)) ans *= cnt_b;
            else ans *= cnt_a;
            ans %= MOD;
        }

        cnt_a += is_a_has.at(i);
        cnt_b += is_b_has.at(i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
n, k = input().split(' ')
r,s,p = input().split(' ')
t = input()
n,k,r,s,p = int(n),int(k),int(r),int(s),int(p)

subS = ""
for i in range(len(t)):
    if (t[i] == 'r'): subS += 'p'
    elif (t[i] == 'p'): subS += 's'
    else: subS += 'r'

sums = 0
already = [True]
# print(subS)
# print(r)
# print(len(t))
for i in range(len(t)):
    if (i == 0):
        if(subS[i]== 'r'): sums += r
        elif(subS[i] == 'p'): sums += p
        else: sums += s
        continue   
    if (t[i] != t[i - k]):
        sums += (subS[i] == 'r')*r + (subS[i] == 'p')*p + (subS[i] == 's')*s
        already.append(True)
    else:
          if(i >= k and already[i - k]): already.append(False)
          else:
                already.append(True)
                sums += (subS[i] == 'r')*r + (subS[i] == 'p')*p + (subS[i] == 's')*s
print(sums)   

Measured memory_bytes: 4372
#include <set>
#include <cstdio>
#include <vector>
 
using namespace std;
bool able;
int main()
{
    int i,a[5];
    for(i = 1;i <= 4;i++)
    {
    	scanf("%1d",&a[i]);
    	if(a[i] == a[i - 1]&&i != 1) able = 1;
	}
	if(able) printf("Bad");
	else printf("Good");
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;


/*
どこかK個が連続して白あるいは黒で塗られているような塗り方はすべて達成できる(それ以外は無理)。
左端からa[i-1]までのすべての項の和と、正の項の和をそれぞれメモっていけば早い。
*/

int N, K;
long long a[100000];
long long sum[100000];
long long pos_sum[100000];
long long ans;

int main() {
	ans = 0;


	scanf("%d %d", &N, &K);
	for (int i=0; i < N; i++) {
		scanf("%lld", &a[i]);
	}
	sum[0] = 0;
	pos_sum[0] = 0;
	for (int i=1; i < N+1; i++) {
		sum[i] = sum[i-1] + a[i-1];
		if (a[i - 1] > 0) { pos_sum[i] = pos_sum[i - 1] + a[i - 1]; }
		else { pos_sum[i] = pos_sum[i - 1]; }
	}

	for (int i = 0; i < N - K + 1; i++) {
		/*iからi+K-1までを白あるいは黒で塗る。0からi-1までの正の和、iからi+K-1までのすべての和あるいは0、
		i+KからN-1までの正の和*/
		if (ans < pos_sum[i] + pos_sum[N] - pos_sum[i + K]) {
			ans = pos_sum[i] + pos_sum[N] - pos_sum[i + K];
		}
		if (ans < pos_sum[i] + pos_sum[N] - pos_sum[i + K] + sum[i + K] - sum[i]) {
			ans = pos_sum[i] + pos_sum[N] - pos_sum[i + K] + sum[i + K] - sum[i];
		}
	}

	printf("%lld", ans);
}

Measured memory_bytes: 2560
n, k = map(int,input().split())
a = list(map(int, input().split()))
# print(a)
ans = 10**15
for i in range(2**n):
    
    maxheight = a[0]
    money = 0
    see = 1
    for j in range(1,n):
        if see >= k:
            break 
        if a[j]>maxheight:
            see += 1
            maxheight = a[j]
        elif a[j]<=maxheight and (i>>j)&1 ==1:
            # print(i,j)
            money += maxheight-a[j]+1
            
            maxheight += 1
            see +=1
    # print(bin(i), money, maxheight,see)
    if see >= k and money <= ans:
        ans = money
print(ans)




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

int modd=1e9+7;
long long P(int x)
{
	long long t=1;
	while(x>0)
	{
		t*=x;x--;
		t%=modd;
	}
	return t;
}

int main()
{
	long long n,m;
	cin>>n>>m;
	int d=n-m;
//	cout<<d<<endl;
	long long ans;
	if(d>=2||d<=-2) ans=0;
	else {
		if(d==1||d==-1) 
		{
			ans=P(n)*P(m)%modd;
		}
		else {
			if(d==0)
			ans=(P(n)*P(m)%modd)*2%modd;
		}
	} 
	ans%=modd;
	cout<<ans;
//	cout<<endl<<P(1000);
	
	return 0;
}

Measured memory_bytes: 256