akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=998244353, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;                       // to be set
    vector<Abel> dat;
   
    // [1, n]
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }
    
    // a is 1-indexed
    inline void add(int a, Abel x) {a++;
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    // [1, a], a is 1-indexed
    inline Abel sum(int a) {a++;
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }
    
    // [a, b), a and b are 1-indexed
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
};
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll mul(ll a,ll b,ll c,ll d){
	a*=b;
	c*=d;
	c%=mod;
	a%=mod;
	return (a*c)%mod;
}
ll solve(ll a,ll b,ll c,ll d){
	ll ret = 0;
	vector<ll> num = {a,b,c,d};
	vector<ll> o(4),ox(4);
	for(int i=0;i<4;i++){
		ox[i] = modpow(2LL,num[i]);
		o[i] = ox[i] - 1;
	}
	ret += mul(ox[0],o[1],o[2],ox[3]);
	//cout << ret << endl;
	ret += mul(o[0],ox[1],ox[2],o[3]);
	//cout << ret << endl;
	ret -= mul(o[0],o[1],o[2],o[3]);
	//cout << ret << endl;
	ret += mul(ox[0],ox[1],ox[2],ox[3]);
	//cout << ret << endl;
	return (ret%mod+mod)%mod;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int,int> > v(n);
    for(int i=0;i<n;i++) cin >> v[i].first >> v[i].second;
    {
    	map<int,int> mp;
    	for(int i=0;i<n;i++) mp[v[i].first] = 0;
    	int idx = 0;
    	for(auto& x:mp) x.second = idx++;
    	for(int i=0;i<n;i++) v[i].first = mp[v[i].first];
    }
    {
    	map<int,int> mp;
    	for(int i=0;i<n;i++) mp[v[i].second] = 0;
    	int idx = 0;
    	for(auto& x:mp) x.second = idx++;
        for(int i=0;i<n;i++) v[i].second = mp[v[i].second];
    }
    sort(be(v));
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    vector<ll> d(n);
    for(int _ = 0; _ < 2;_++){
    	{
    		BIT<ll> bit(n+1);
    		for(int i=0;i<n;i++){
    			a[i] = bit.sum(v[i].second);
    			b[i] = i - a[i];
    			bit.add(v[i].second,1LL);
    		}
    	}
    	reverse(be(v));
    	swap(a,c);
    	swap(b,d);
    	reverse(be(a));
    	reverse(be(b));
    	reverse(be(c));
    	reverse(be(d));
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
    	(ans += solve(a[i],b[i],c[i],d[i]))%=mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11264
A, B = map(int, input().split())
 
res1 = A + B
res2 = A - B
res3 = A * B
 
if res1 > res2:
  if (res1 > res3):
    print (res1)
  else:
  	print (res3)
else:
  if (res2 > res3):
    print (res2)
  else:
    print (res3)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;
#define out(i) cout<<(i)<<endl

int main() {
  double N,s;
  cin>>N;
  s=6.28318530717958623200*N;
  cout<<fixed<<setprecision(5);
  cout<<s<<endl;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  unordered_set<int> set;
  rep1 (i, 9) {
    rep1 (j, 9) {
      set.insert(i * j);
    }
  }
  cout << (set.find(n) != set.end() ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
const getUnique = (arr) =>
  arr.filter((value, index, self) => self.indexOf(value) === index);

function Main (input) {
  const strArr = input.split(/\s/g)[1].split('');
  const strLength = strArr.length;
  var counter = 0;

  const results = new Array(strLength).fill('').map((value, index) => {
    if (index === 0) return 0;

    const right = [...strArr]
    const left = right.splice(index);
    const uniqueRight = getUnique(right);
    const uniqueLeft = getUnique(left);
    
    const result = uniqueRight.filter((value) => uniqueLeft.indexOf(value) !== -1);
    return result ? result.length : 0
  });
  console.log('%s', Math.max(...results));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 8580
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;

immutable limitList = 100000;



void main() {
    int input;
    bool[] listNumbers = new bool[](limitList);
    int[] listPrimeNumbers; //List of prime numbers.

    listNumbers.fill(true);
    listNumbers[0..1] = false;
    foreach (i; 2..limitList.to!double.sqrt.to!int) {
        if (listNumbers[i]) {
            for (int j = i*2; j < limitList; j += i) listNumbers[j] = false;
        }
    }

    while ((input = readln.chomp.to!int) != 0) {
        uint count = 0;

        foreach (i; 2..(input/2)+1) {
            if(listNumbers[i] && listNumbers[input-i]) count++;
        }

        writeln(count);
    }
}

Measured memory_bytes: 1252
import java.util.*;

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

    long cnt = 0;

    HashMap<String, Integer> a = new HashMap<>(n);

    for(int i=0 ; i<n ; i++){
      String str = sc.next();
      char[] aa = str.toCharArray();
      Arrays.sort(aa);
      String newStr = new String(aa);
      if(a.containsKey(newStr)){
          cnt+=a.get(newStr);
          a.put(newStr, a.get(newStr)+1);
      }else{
          a.put(newStr, 1);
      }
    }
    System.out.println(cnt);
  }
}

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

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

  double ans;
  if(n==1) ans = 1.0;
  else if(n%2==0) ans=0.5;
  else ans = (n/2 + 1)/(double)n;

  printf("%.10lf",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod=1e9+7;

vector<vector<int>> to(10);

int main(){
    int n,m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<int> num;
    for(int i = 0; i < n; i++){
        num.push_back(i);
    }
    int sam = 1;
    for(int i = 1; i < n; i++){
        sam *= i;
    }
    int cnt = 0;

    for(int i = 0; i < sam; i++){
        for(int i = 0; i < n-1; i++){
            bool flag = false;

            for(int j = 0; j < to[num[i]].size(); j++){
                if(i != 0 && to[num[i]][j] == num[i-1]) continue;
                if(to[num[i]][j] == num[i+1]) flag = true;
            }
            if(!flag) break;
            if(i == n-2) cnt++;
        }
        next_permutation(num.begin()+1,num.end());
    }

    cout << cnt << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#pragma region DEBUG
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
vector <lli> below(MAX);
vector <lli> ans(MAX);
lli n;
void DFS(lli s, vector <bool> &visited, vector<vector<lli> >&adj){
    visited[s] = true;
    ans[s] = INT_MIN;
    for(auto i : adj[s]){
        if(!visited[i]){
            DFS(i,visited,adj);
            lli q = below[i]+1;
            ans[s] = max(ans[s], q);
            below[s] += below[i]+1;
        }
    }
    ans[s] = max(ans[s], n-1ll-below[s]);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout)
    lli t;
    //cin>>t;
    t = 1;
    while(t--){
       // lli n;
        cin>>n;
       cout<<(1-n)<<endl;
        
    }
}

Measured memory_bytes: 10968
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int debug = 0;
bool ans = false;

bool kaibun(string s1){
    string s2;
    s2 = s1;
    reverse(s2.begin(), s2.end());
    if(s1==s2)
        return true;
    else
        return false;
}

int main(){
    string S1,S2,S3;

    int n;
    cin >> S1;
    n = S1.size();
    S2 = S1.substr(0, (n - 1) / 2);
    S3 = S1.substr((n + 3) / 2-1, n-1);

    if (debug)
    {
        cout << "S2=" << S2 << endl;
        cout << "S3=" << S3 << endl;
    }

    if(kaibun(S1)&&kaibun(S2)&&kaibun(S3))
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define lint long long

struct event{
    int t, f, c;
};

vector<event> E;
int rec[30];
bool used[30];

bool comp(const event& x, const event& y){
    if(x.t != y.t) return x.t < y.t;
    if(x.f != y.f) return x.f < y.f;
    return x.c < y.c;
}

int find_available(int ch){
    rep(i, 30){
        if(rec[i] == ch + 100) return i;
    }
    rep(i, 30){
        if(rec[i] == -1) return i;
    }
    return -1;
}

int find_recording(int ch){
    rep(i, 30){
        if(rec[i] == ch) return i;
    }
    return -1;
}

int main(){
    int n, c; cin >> n >> c;
    memset(rec, -1, sizeof(rec));

    rep(i, n){
        int s, t, ch; cin >> s >> t >> ch; ch--;
        E.push_back(event{s, 1, ch});
        E.push_back(event{t, 0, ch});
        E.push_back(event{t+1, -1, ch});
    }
    sort(all(E), comp);

    rep(i, (int)E.size()){
        event e = E[i];
        if(e.f == 1){
            int fa = find_available(e.c);
            rec[fa] = e.c;
            used[fa] = true;
        }
        else if(e.f == 0){
            int fr = find_recording(e.c);
            rec[fr] = e.c + 100;
        }
        else{
            int fr = find_recording(e.c + 100);
            if(fr >= 0) rec[fr] = -1;
        }
    }

    int res = 0;
    rep(i, c){
        if(used[i]) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 8560
/*
    アリナ・グレイはかわいい
*/

#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i = 0;i < n;i++)cin >> a[i] >> b[i];
    
    reverse(a,a+n);
    reverse(b,b+n);
    
    long long int ans = 0;
    for(int i = 0;i < n;i++){
        if((a[i]+ans) % b[i] > 0)ans += (b[i] - ((a[i]+ans) % b[i]));
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 1024
s = list(str(input()))
t = list(str(input()))

X = [[] for _ in range(26)]
for i, c in enumerate(s):
    j = ord(c)-ord('a')
    X[j].append(i)

ans = 0
import bisect
cur = -1
for c in t:
    j = ord(c)-ord('a')
    if len(X[j]) == 0:
        print(-1)
        exit()
    k = bisect.bisect_right(X[j], cur)
    if k != len(X[j]):
        cur = X[j][k]
    else:
        cur = X[j][0]
        ans += len(s)
ans += cur+1
print(ans)


Measured memory_bytes: 87644
#include<iostream>
using namespace std;
const int maxn=100005;
const int inf=0x3f3f3f3f;
long long n,k,dp[maxn][5],a[maxn],b[maxn],c[maxn];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	dp[1][1]=a[1];
	dp[1][2]=b[1];
	dp[1][3]=c[1];
	for(int i=2;i<=n;i++)
	{
		dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i];
		dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i];
		dp[i][3]=max(dp[i-1][1],dp[i-1][2])+c[i];
	}
	cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<endl;
	return 0;
}

Measured memory_bytes: 9840
#include<bits/stdc++.h>
#define ll      long long
#define pb	    push_back
#define F	    first
#define S	    second
#define B	    begin()
#define E	    end()
#define pii     pair < ll , ll >
#define FASTIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std ;
int jamil ;
int main()
{
    FASTIO
    string s ;
    cin >> s ;
    int a = s[0] - '0' , b = s[1] - '0' , c = s[2] - '0' , d = s[3] - '0' ;
    if( a - b - c  - d == 7 ) cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7";
    else if ( a - b - c + d  == 7 ) cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";
    else if( a - b + c - d == 7 )  cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";
    else if ( a - b + c + d == 7 ) cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";
    else if ( a + b - c - d == 7 ) cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";
    else if ( a + b - c + d == 7 ) cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
    else if ( a + b + c -  d == 7 ) cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";
    else if ( a + b + c + d == 7 ) cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";

	return 0 ;
}


Measured memory_bytes: 3644
n=int(input())
p=list(map(int,input().split()))
min_val=10**18
ans=0
for i in range(n):
  if i==0:
    min_val=p[i]
    ans+=1
    continue
  if min_val>=p[i]:
    min_val=p[i]
    ans+=1
print(ans)




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

int main() {
    int h, a;
    cin >> h >> a;
    int i = 0;
    int j = 0;
    while(i < h){
        h = h - a;
        j++;
        if(i >= h){
            cout << j;
        }
    }

    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <string.h>
int main (){
    char s[6];
    int cnt,i;
    scanf("%s",s);
    for(i=0; i<strlen(s); i++){
        if(s[i]=='1'){
                cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
/* Date: 01/04/2020
 * Author: @codingoo
 * Problem Name: Algae
 * Platform: AtCoder
 */
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    int r, D, x;
    cin >> r >> D >> x;
    rep(i, 0, 10) {
        x = (x * r) - D;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int visited[100001];
vector <int> p[100001];
int num=0;
void dfs(int curr,int prev){
	if(visited[curr]==2){
		return;
	}
	if(visited[curr]==1){
		num++;
		return;
	}
	visited[curr]=1;
	for(int i=0;i<p[curr].size();i++){
		if(p[curr][i]!=prev){
			dfs(p[curr][i],curr);
		}
	}
	visited[curr]=2;
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int s,e;
		cin>>s>>e;
		p[s].push_back(e);
		p[e].push_back(s);
	}
	for(int i=1;i<=n;i++){
		if(visited[i]!=2){
			dfs(i,0);
		}
	}
	cout<<max((n-1)-(m-num),0)<<endl;
}

Measured memory_bytes: 10784
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<queue>
#define null NULL
using namespace std;
/** 区间表示：[p->dl,p->dr]
 *  从0开始计数，[0,n-1]
 *  线段树RSQ
 *
 */

struct Node
{
    long long dl,dr,s,delta;
    Node *pl,*pr;
};
int n,q;

void build(Node *&p,int l,int r)
{
    p=(Node *)malloc(sizeof(Node));
    p->dl=l,p->dr=r,p->s=0,p->delta=0;
    p->pl=null,p->pr=null;
    int mid=(l+r)/2;
    if(r>l)
    {
        build(p->pl,l,mid);
        build(p->pr,mid+1,r);
    }
}

void preorder(Node *p)
{
    if(p!=null)
    {
        printf("%d %d %d %d\n",p->dl,p->dr,p->s,p->delta);
        preorder(p->pl);
        preorder(p->pr);
    }
}
///在其他节点更新和查询的过程中都要向下延迟修改
void pushdown(Node *&p,int delta)
{
    p->pl->s += p->delta*(p->pl->dr - p->pl->dl+1);
    p->pr->s += p->delta*(p->pr->dr - p->pr->dl+1);
    p->pl->delta += p->delta;
    p->pr->delta += p->delta;
    p->delta=0;
}
///当前区间的更新只更新到某些节点，下边节点的更新需要下次延迟修改
void update(Node *&p,int l,int r,int data)
{
    ///[l,r]必然位于[p->dl,p->dr]子区间
    ///当前节点的所有数据都是正确的！！
    ///延迟修改-lazy-tag技术
    ///此处下行的是之前的数据
    if(p->delta!=0 && p->dr>p->dl)
        pushdown(p,p->delta);

    p->s+=data*(r-l+1);
    if(p->dl==l &&p->dr==r)
    {
        p->delta=data;
        return ;
    }
    int mid=(p->dl+p->dr)/2;
    if(r<=mid)
        update(p->pl,l,r,data);
    else if(l>mid)
        update(p->pr,l,r,data);
    else
        update(p->pl,l,mid,data),update(p->pr,mid+1,r,data);
}
///当前节点的所有数据都是正确的！！
///即使不正确，在进入到这个之前也被pushdown过了,，所以一定是正确的
long long query(Node *&p,int l,int r)
{
    ///一个查询区间最终必然被分成若干个小的区间和，最后一个定会完全和区间贴合
    if(p->delta!=0 && p->dr>p->dl)
        pushdown(p,p->delta);

    if(p->dl==l &&p->dr==r)
        return p->s;
    int mid=(p->dl+p->dr)/2;
    ///判断查询区间与当前区间的位置关系
    //全部位于左侧
    if(r<=mid)
        return query(p->pl,l,r);
    //全部位于右侧
    else if(l>mid)
        return query(p->pr,l,r);
    //两个都有
    else
        return query(p->pl,l,mid)+query(p->pr,mid+1,r);
}

int main()
{
    int i,type,tx,ty,x;
    Node *tree=null;
    scanf("%d%d",&n,&q);
    build(tree,0,n-1);
    for(i=0;i<q;i++)
    {
        scanf("%d",&type);
        if(type==0)
        {
            scanf("%d%d%d",&tx,&ty,&x);
            tx--,ty--;
            update(tree,tx,ty,x);
        }else
        {
            scanf("%d",&tx);
            tx--,ty--;
            long long ans=query(tree,tx,tx);
            printf("%lld\n",ans);
        }
    }
    return 0;
}



Measured memory_bytes: 15700
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] array = new int[N];
    
    for(int i=0; i<N; i++){
      array[i] = sc.nextInt();
    }
    
    int M =sc.nextInt();
    for(int j=0; j<M; j++){
      int P = sc.nextInt();
      int X = sc.nextInt();
      int sum =0;
      int[] array2 = new int[N];
      for(int k=0; k<N; k++){
        if(k == (P - 1) ){  
          array2[k] = X;
        }else{
          array2[k] = array[k];
        }
      }
      for(int num : array2){
        sum += num;
      }
      System.out.println(sum);
    }
    
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N,A,B;cin>>N>>A>>B;
  P(min(N*A,B));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define print(x) for(auto& i:x) cout<<i<<" "; cout<<'\n';
#define scan(x) for(auto& i:x) cin>>i;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define pii pair<int, int>
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<" "<<b<<endl
#define d3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define d4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define d5(a,b,c,d,e) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl
ll mod=1e9+7;

void solve(){
	ll n; cin>>n;
	vector<ll> a(n); scan(a);
	ll mx=a[0], ans=0;
	for(int i=1;i<n;i++){
		if(a[i]<mx) ans+=mx-a[i];
		mx=max(mx,a[i]);
	}
	cout<<ans<<endl;
}


int main() {
	//freopen("test.txt", "r", stdin);
	FAST; int T=1;
	//cin>>T;
	while(T--) solve();
	return 0;
}

Measured memory_bytes: 4404
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <functional>


#include <math.h>


using namespace std;


class Solution {
public:
    void solve(int num, std::istream& in, std::ostream& out) {
		int a, b, c, k; in >> a >> b >> c >> k;
		int sum = 0;
		if (k > 0) {
			sum += min(a, k);
			k -= a;
		}
		if (k > 0) {
			k -= b;
		}
		if (k > 0) {
			sum -= k;
		}
		out << sum;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
	//int T; in >> T;
	//for(int i = 0;i < T;i++)
		//solution.solve(i+1, in, out);
	solution.solve(0, in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 3188
//300
fun ac097(args: Array<String>) {
    val str = args[0]
    val K = args[1].toInt()
    val set = mutableSetOf<String>()
    (1..Math.min(K, str.length)).forEach { len ->
        (0..str.length - len).forEach { start ->
            set.add(str.substring(start, start + len))
        }
    }
    val sortedSet = set.sorted()
    println(sortedSet[K - 1])
}

fun main(args: Array<String>) {
    ac097(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 40964
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main(void){
    int startX,startY,destinationX,destinationY;
    int i,j;
    scanf("%d %d %d %d",&startX,&startY,&destinationX,&destinationY);
            for(i=0;i<destinationY-startY;i++){
                printf("U");
            }
            for(i=0;i<destinationX-startX;i++){
                printf("R");
            }
            for(i=0;i<destinationY-startY;i++){
                printf("D");
            }
            for(i=0;i<destinationX-startX;i++){
                printf("L");
            }
            printf("L");
            for(i=0;i<destinationY-startY+1;i++){
                printf("U");
            }
            for(i=0;i<destinationX-startX+1;i++){
                printf("R");
            }
            printf("D");
            printf("R");
            for(i=0;i<destinationY-startY+1;i++){
                printf("D");
            }
            for(i=0;i<destinationX-startX+1;i++){
                printf("L");
            }
            printf("U");
    return 0;

}

Measured memory_bytes: 128
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
cost=[2,2,5,5,4,5,6,3,7,6]

dp=[0 for i in range(n+1)]

for i in range(1,n+1):
    p=0
    for j in a:
        if i-cost[j]>=0 and (dp[i-cost[j]]!=0 or i-cost[j]==0):
            p=max(p,int(dp[i-cost[j]]*10+j))
    dp[i]=p

print(dp[n])

Measured memory_bytes: 14516
import copy
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
 if i==0:
  cnt+=abs(a[i])
 else:
  cnt+=abs(a[i]-a[i-1])
cnt+=abs(a[n-1])
#print(cnt,0)
for i in range(n):
 if i==0:
  if a[i]>=0 and a[i+1]>=0 and a[i+1]<=a[i] or a[i]<=0 and a[i+1]<=0 and a[i]<=a[i+1]:#ok
   print(cnt-2*(abs(a[i])-abs(a[i+1])))
  elif a[i]>=0 and a[i+1]>=0 and a[i+1]>=a[i] or a[i]<=0 and a[i+1]<=0 and a[i]>=a[i+1]:#ok
   print(cnt)
  else:
   print(cnt-2*abs(a[i]))
 elif i<=n-2: #ok
  if a[i-1]>=a[i] and a[i]>=a[i+1] or a[i-1]<=a[i] and a[i]<=a[i+1]:
   print(cnt)
  elif a[i]>=a[i-1]>=a[i+1] or a[i+1]>=a[i-1]>=a[i]:
   print(cnt-2*abs(a[i]-a[i-1]))
  elif a[i]>=a[i+1]>=a[i-1] or a[i-1]>=a[i+1]>=a[i]:
   print(cnt-2*(abs(a[i]-a[i+1])))
 else:
  if a[i]>=0 and a[i-1]>=0 and a[i-1]<a[i] or a[i]<=0 and a[i-1]<=0 and a[i]<=a[i-1]:#ok
   print(cnt-2*(abs(a[i])-abs(a[i-1])))
  elif a[i]>=0 and a[i-1]>=0 and a[i-1]>a[i] or a[i]<=0 and a[i-1]<=0 and a[i]>=a[i-1]:#ok
   print(cnt)
  else:
   print(cnt-2*abs(a[i]))

Measured memory_bytes: 66208
#include <iostream>
using namespace std;
int main(){
  int a , b , c ,ans;
  cin>>a>>b; 
  if(a==1&&b==3) cout<<2<<endl;
    else if(a==3&&b==1) cout<<2<<endl;
    else if(a==1&&b==2) cout<<3<<endl;
    else if(a==2&&b==1) cout<<3<<endl;
  else cout<<1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long LL;

int main(){
  int A,B,C,D,E,F;
  cin>>A>>B>>C>>D>>E>>F;
  
  int sum=100*A;
  int sug=0;
  
  for(int i=0;i<30/A+1;i++){
	if(100*A*i>F){
	  break;
	}
	for(int j=0;j<30/B+1;j++){
	  if(100*A*i+100*B*j>F){
	  break;
	  }
	  for(int k=0;k<3000/C+1;k++){
		if(100*A*i+100*B*j+C*k>F){
		  break;
		}
		for(int l=0;l<3000/D+1;l++){
		  if(100*A*i+100*B*j+C*k+D*l>F){
			break;
		  }
		  if((A*i+B*j)*E<C*k+D*l){
			break;
		  }

		  if((100*A*i+100*B*j+C*k+D*l)!=0){
			if((double)sug/(double)sum
			   <(double)(C*k+D*l)/(double)(100*A*i+100*B*j+C*k+D*l)){

			  sug=C*k+D*l;
			  sum=100*A*i+100*B*j+C*k+D*l;
			}
		  }
		}
	  }
	}
  }

  cout << sum << " " << sug << endl;

}


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

using namespace std;

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

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define dbg(x)
#endif

#define X first
#define Y second
int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    int H, W, N; cin >> H >> W >> N;
    vector<pii> pts(N);
    map<pii, int> mmap;
    for (int i = 0; i < N; i++){
        int x, y; cin >> x >> y; x--; y--;
        pts[i] = {x, y};
        mmap[pts[i]] = 1;
    }
    vector<ll> res(10, 0);
    for (int i = 0; i < N; i++){
        for (int k = 0; k < 9; k++){
            pii p = {pts[i].X + dx[k], pts[i].Y + dy[k]};
            bool valid = true;
            int cnt = 0;
            for (int kk = 0; kk < 9; kk++){
                int i2 = p.X + dx[kk], j2 = p.Y + dy[kk];
                if (i2 < 0 || i2 >= H || j2 < 0 || j2 >= W) {
                    valid = false;
                    break;
                }
                if (mmap.count({i2, j2})) cnt += 1;
            }
            if (valid){
                assert(cnt >= 1);
                res[cnt] += 1;
            }
        }
    }
    ll sum = 0;
    for (int i = 9; i >= 1; i--){
        assert(res[i] % i == 0);
        res[i] /= i;
        sum += res[i];
    }
    res[0] = (ll)(H - 3 + 1) * (W - 3 + 1) - sum;
    for (int i = 0; i < 10; i++) cout << res[i] << endl;
    return 0;
}


Measured memory_bytes: 7424
a = list(map(int,input().split()))
A = a[0]
B = a[1]
c = True
for x in range(10001):
    a = x * 0.08
    b = x * 0.1
    if A == int(a) and B == int(b):
        print(x)
        c = False
        break
if c:
    print(-1)

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

int compare_int(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int main(){
    int n; 
    cin >> n;
    int *a = new int[n];
    a[0] = -1;
    for (int i = 1; i < n;i++)
    {
        cin >> a[i];
    }
    int *b = new int[n];
    for (int i = 0; i < n;i++)
    {
        b[i] = 0;
    }
    for (int i = 1; i < n; i++)
    {
        b[a[i] - 1]++;
    }
    for (int i = 0; i < n;i++)
    {
        cout << b[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int n,k;
    string s;
    cin>>n>>s>>k;
    rep(i,n){
        if(s[i]!=s[k-1])s[i]='*';
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s; cin >> s;
  if(s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes";
  }else{
    cout << "No";
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  int k;
  char s[100];
  int len,i;
  scanf("%d %s",&k,s);
  len=strlen(s);
  if(len<=k){
    printf("%s\n",s);
  }else{
    for(i=0;i<k;i++){
      printf("%c",s[i]);
    }
    printf("...\n");
  }
  return 0;
}
  

Measured memory_bytes: 1644
#include <bits/stdc++.h>
#define pb push_back
#define tam 220000
#define offset 100000
#define se second
#define fi first
#define forr(i,p,n) for(ll i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<int,int> ii;
using namespace std;
vector<string> resp;
int main()
{
    resp.pb("dream");
    resp.pb("dreamer");
    resp.pb("erase");
    resp.pb("eraser");
    string txt;
    cin>>txt;
    int N,M;
    M=txt.size();
    string otrotxt;
    while(M>0)
    {
        
        bool cond=0;

        forr(i,0,resp.size())
        {
            N=resp[i].size();
            if (M-N<0)continue;
            otrotxt=txt.substr(M-N,N);
            //cout<<otrotxt<<" "<<resp[i]<<endl;
            if (otrotxt==resp[i])
                {
                    M-=N;
                    cond=1;
                    break;
                }
        }
        if (cond==0)break;

    }
    if (M==0)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}

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

using ll = long long;
using ull = unsigned long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define bzero(p, n) memset(p, 0, n)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}

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

    ll N, W;
    cin >> N >> W;

    vector<ll> w(N), v(N);
    ll v_sum = 0;
    rep(i, N) {
        cin >> w[i] >> v[i];
        v_sum += v[i];
    }

    vector<vector<ll>> dp(N+1, vector<ll>(v_sum+1, LLONG_MAX));
    dp[0][0] = 0;

    rep(i, N) {
        rep(j, v_sum + 1) {
            if (dp[i][j] == LLONG_MAX) continue;
            chmin(dp[i + 1][j], dp[i][j]);
            if (j + v[i] <= v_sum)
                chmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
        }
    }

    ll ans = 0;
    rep(i, v_sum+1) {
        if (dp[N][i] <= W)
            ans = i;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    // 吐き出し法(row reduction)、xorのtotalのbitが1の部分はそのまま
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll xtotal = 0;
    rep(i, N) xtotal ^= A[i];
    rep(i, N) A[i] &= ~xtotal;
    ll ans = 0;
    // 吐き出し法
    int r = 0;
    for (int i = 60; i >= 0; i--) {
        int j = r;
        for (; j < N; j++) {
            if ((A[j]>>i)&1) {
                swap(A[j], A[r]);
                break;
            }
        }
        if (j == N) continue;
        for (int k = 0; k < N; k++) {
            if (k == r) continue;
            if ((A[k]>>i)&1) A[k] ^= A[r];
        }
        r++;
    }
    rep(i, N) ans ^= A[i];
    ans *= 2;
    ans += xtotal;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3988
#include<iostream>
#include<set>

std::multiset<long long> s;

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

	long long n,m,a;

	std::cin>>n;
	for(int i = 0; i < n; i++) {
		std::cin>>a;
		s.insert(a);
	}

	std::cin>>m;
	for(int i = 0; i < m; i++) {
		std::cin>>a;
		auto it = s.find(a);
		if(it == s.end()) {
			std::cout<<"NO\n";
			return 0;
		}
		s.erase(it);
	}
	std::cout << "YES\n";
	return 0;
}


Measured memory_bytes: 9600
#import<atcoder/all>
using namespace std;int o(int a,int b){return a<b?b:a;}int e(){return 0;}int K,A;atcoder::segtree<int,o,e>P(3<<17);main(){for(cin>>K>>K;cin>>A;)P.set(A,P.prod(o(0,A-K),min(3<<17,A+K+1))+1);cout<<P.all_prod();}

Measured memory_bytes: 8504
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define  int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    string s;
    cin>>s;
    int mx[10],mn[10];
    for(int i=0;i<10;i++)
    {
        mx[i]=-1;
        mn[i]=n;
    }
    for(int i=0;i<n;i++)
    {
        mx[s[i]-'0']=i;
        mn[s[i]-'0']=min(mn[s[i]-'0'],i);
    }
    int cnt=0;
    for(int i=0;i<10;i++)
    {
        for(int j=0;j<10;j++)
        {
            for(int k=0;k<10;k++)
            {
                for(int l=mn[i]+1;l<mx[k];l++)
                    if(l>=0&&l<n&&(s[l]-'0')==j)
                    {
                        cnt++;
                        //cout<<i<<" "<<j<<" "<<k<<endl;
                        break;
                    }
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <float.h>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <list>
#include <stack>
#include <queue>
#include <sstream>

#define For(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  For(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
int h, w, d;
vector<vector<int>> v(500, vector<int>(500));


int main() {
	string str;
	cin >> str;
	cout << str.substr(0,str.length() - 8) << endl;

}



Measured memory_bytes: 1280
///////////////////// author : TrEbLeCleF /////////////////////
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define For(i, a) for (int i=0; i<(a); i++)
#define FORR(i,a,b) for (int i = (b)-1; i >= a; i--)
#define Forr(i,a) for (int i = (a)-1; i >= 0; i--)
/////////////////////////// ..... ///////////////////////////
#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args){
cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }
/////////////////////////// ..... ///////////////////////////
#define int ll
#define pb(x) push_back(x)
#define print(v,s,e) for(int i = s; i < e; i++)cout << v[i]<<" ";cout<<"\n";
#define INF 1e17
#define PI 3.14159265358979323846 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
/////////////////////////// GLOBAL ///////////////////////////


/////////////////////////// GLOBAL ///////////////////////////
void solve(){
	int n;cin >> n;
	int a[n+1];
	For(i,n)cin >> a[i];
	int ans = 1000;
	For(i,n-1){
		if(a[i]<a[i+1]){
			int stocks = ans/a[i];
			ans %= a[i];	
			ans += a[i+1]*stocks;
		}
	}
	cout << ans <<"\n";
}

int32_t main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		freopen("TC", "r", stdin);
		//freopen("output.txt","w",stdout);
	#endif 
    ios_base:: sync_with_stdio(false); 
   	cin.tie(0); 
	int t=1;
	//cin >> t;
	for(int tt=1;tt<=t;tt++){
		//cout << "Case #"<<tt<<": ";
		solve();
	}
	#ifndef ONLINE_JUDGE
    	cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
    #endif
}

Measured memory_bytes: 3644
#include<cstdio>
static const int kMaxVertices = 100;
static const int kInfinity = 3000;
static int Adjacency_matrix[kMaxVertices][kMaxVertices];

void Prim(int n){
	bool has_not_been_discovered[kMaxVertices];
	int lowest_cost_edge[kMaxVertices];
	int parent[kMaxVertices];
	for (int i = 0; i < n; ++i)	{
		has_not_been_discovered[i] = true;
		lowest_cost_edge[i] = kInfinity;
	}
	lowest_cost_edge[0] = 0;
	parent[0] = -1;

	while(true) {
		int mincost = kInfinity;
		int vertex_to_add;
		for (int i = 0; i < n; ++i)	{
			if(has_not_been_discovered[i] && lowest_cost_edge[i] < mincost){
				mincost = lowest_cost_edge[i];
				vertex_to_add = i;
			}
		}

		if(mincost == kInfinity)
			break;

		has_not_been_discovered[vertex_to_add] = false;
		int vertex_added = vertex_to_add;

		for (int i = 0; i < n; ++i)	{
			if(has_not_been_discovered[i] && Adjacency_matrix[vertex_added][i] < lowest_cost_edge[i]) {
				lowest_cost_edge[i] = Adjacency_matrix[vertex_added][i];
				parent[i] = vertex_added;
			}
		}
	}
	int total_cost = 0;
	for (int i = 0; i < n; ++i)
		total_cost += lowest_cost_edge[i];
	printf("%d\n", total_cost);
}

int main() {
	int number_of_vertices;
	scanf("%d", &number_of_vertices);
	for (int vertex_from = 0; vertex_from < number_of_vertices; ++vertex_from) {
		for (int vertex_to = 0; vertex_to < number_of_vertices; ++vertex_to)	{
			int tmp;
			scanf("%d", &tmp);
			Adjacency_matrix[vertex_from][vertex_to] = (tmp < 0) ? kInfinity : tmp;
		}
	}
	Prim(number_of_vertices);
	return 0;
}

Measured memory_bytes: 2756
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{
  ll n,k,s;
  cin >> n >> k >> s;

  rep(i,n)
  {
    if(i < k)
    {
      if(i == 0)
      {
        cout << s;
      }
      else
      {
        cout << " " << s;      
      }
    }
    else
    {
      if(s == 1000000000)
      {
        cout << " " << 1;
      }
      else
      {
        cout << " " << 1000000000;      
      }
    }
  }
  cout << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline int ubnd(T&v,ET(T) x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T) x){return lower_bound(begin(v),end(v),x)-begin(v);}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline void inpt(T&v,int n,function<ET(T)()>f=In<ET(T)>){for(v.reserve(n);n--;v.emplace_back(f()));}
TT inline void show(T&v,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),cout<<x;cout<<e;}
#undef TT
#undef ET

inline void fast_io(){ios::sync_with_stdio(0); cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline string instr(){string x;cin>>x;return x;}
inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a, ll p){return pow_mod(a,p-2,p);}

const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000;
const int SieveSize = 1000001;

bool sieve[SieveSize] = {true, true};
int main()
{
  for (int i = 2; i * i < SieveSize; i++){
    if (sieve[i]) continue;
    for (int j = i * i; j < SieveSize; j += i) sieve[j] = true;
  }
  int a, d, n;
  while (cin >> a >> d >> n, a || d || n){
    int cnt = 0;
    while (cnt != n){
      if (!sieve[a]) cnt++;
      a += d;
    }
    cout << a - d << "\n";
  }
  return (0);
}

// priority_queue queue deque front top push pop map set stringstream max_element min_element insert count find get tie make_tuple

Measured memory_bytes: 2132
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(n):
    if A[i] >= B[i]:
        ans += B[i]
    else:
        ans = ans + A[i] + min(A[i + 1], B[i] - A[i])
        A[i + 1] = max(A[i + 1] - (B[i] - A[i]), 0)
print(ans)


Measured memory_bytes: 24144
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

int read() {
    int v=0;
    char c;
    for(c=getchar(); c<48; c=getchar());
    for(; c>47; c=getchar())v=(v<<3)+(v<<1)+(c^48);
    return v;
}

int a[3003][3003];

int main()
{   ios;
    int i,j,k,l,n;
    cin>>n;
    rep(i,1,n)
    {
        rep(j,1,n-1)
            cin>>a[i][j];
    }
    k=0;j=0;
    int vis[3003]={0},p[3003];
    rep(i,0,3002)p[i]=1;
    while(k<((n*(n-1))>>1))
    {
        l=0;
        j++;
        rep(i,1,n)vis[i]=0;
        rep(i,1,n)
        {  
            int to=a[i][p[i]]; 
            //cout<<i<<" "<<to<<":"<<a[to][p[to]]<<en;
            if(p[i]==n || vis[i]==1 || vis[to]==1)continue;
            if(a[to][p[to]]==i)
            {   l++;
                vis[to]=1;
                vis[i]=1;
                p[to]++;
                p[i]++;
                k++;
            }
        }
        if(l==0)
        {
            cout<<-1;
            return 0;
        }
    }   
    cout<<j;
    return 0;
}


Measured memory_bytes: 11904