akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def ans(self):
        print(len(set(self.par))-1)

n,m=map(int,input().split())
uf=UnionFind(n)

for i in range(m):
    a,u,v=map(int,input().split())
    if a==0:
        uf.union(u,v)
    else:
        if uf.same_check(u,v):
            print(1)
        else:
            print(0)


Measured memory_bytes: 17968
s = list(input())
T = list(input())

def rplc(s, i, T):
  s = s[:i] + T + s[i+len(T):]
  return ''.join(s).replace('?', 'a')

ans = 'UNRESTORABLE'
for i in range(len(s)-len(T)+1):
  flg = True
  for j in range(len(T)):
    if s[i+j] == '?':
      continue
    if s[i+j] != T[j]:
      flg = False
      break
  if flg:
    ans = rplc(s, i , T) 

print(ans)



Measured memory_bytes: 3064
#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(){
  ll x,k,d;
  cin >> x >> k >> d;
  x = abs(x);
  ll ans;
  if(x/d > k){
    ans = x - d*k;
  }
  else{
    ll e = x/d;
    k -= e;
    x -= e*d;
    if(k%2 == 1){
      x = abs(x-d);
    }
    ans = x;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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;
}
///////////////////////////////////////////////

int main(){
	int N,M;
	SCD2(N,M);
	vector<int> A,B;
	REP(i,N){
		int a; SCD(a);
		A.PB(a);
	}

	REP(i,M){
		int b; SCD(b);
		B.PB(b);
	}

	ll ans = 1;
	sort(ALL(A));
	sort(ALL(B));

	REP(i,N-1){
		if (A[i] == A[i+1]){
			PRINTD(0);
			return 0;
		}
	}

	REP(i,M-1){
		if (B[i] == B[i+1]){
			PRINTD(0);
			return 0;
		}
	}

	FORqr(x,1,M*N){
		ll ax = A.end() - lower_bound(ALL(A),x);
		ll bx = B.end() - lower_bound(ALL(B),x);
		bool justa = binary_search(ALL(A),x);
		bool justb = binary_search(ALL(B),x);

		if (justa && justb){

		}else if(justa){
			ans = (ans * bx) % MOD;
		}else if(justb){
			ans = (ans * ax) % MOD;
		}else{
			ans = (ans * (((ax * bx)%MOD) - ((M*N-x) % MOD)) ) %MOD;
		}
		if (ans < 0) ans += MOD;
		//cout << "loop = " << x << ", " << ans << "\n";
	}

	PRINTLLD(ans);
}

Measured memory_bytes: 256
n=int(input());t,x,y=[],[],[]
for _ in range(n):
  a,b,c=map(int,input().split())
  t.append(a);x.append(b),y.append(c)
for i in range(n):
  r1,r2=[[t[0],x[0]+y[0]],[t[i]-t[i-1],abs(x[i]-x[i-1])+abs(y[i]-y[i-1])]][i!=0]
  if not (r1>=r2 and r1%2==r2%2): print('No');break
else:
  print('Yes')

Measured memory_bytes: 17472
#include <bits/stdc++.h>
#define INF 114514810
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)

using namespace std;

int n, a, b, c, d, t = 0, sum = INF, ans, nodes = 0, p, q, r, w;
int x[102][102], y[102][102];

int main(){
	while (true){
		cin >> n >> nodes;
		if (n == 0 && nodes == 0) break;
		REP(i, 101)
			REP(j, 101){
			x[i][j] = (i == j ? 0 : INF);
			y[i][j] = (i == j ? 0 : INF);
		}
		REP(i, n){
			cin >> a >> b >> c >> d;
			x[a-1][b-1] = x[b-1][a-1] = c;
			y[a-1][b-1] = y[b-1][a-1] = d;
		}
		REP(k, nodes)
			REP(i, nodes)
			REP(j, nodes){
			x[i][j] = min(x[i][j], x[i][k] + x[k][j]);
			y[i][j] = min(y[i][j], y[i][k] + y[k][j]);
		}
		cin >> w;
		REP(k, w){
			cin >> p >> q >> r;
			if (r) cout << y[p-1][q-1] << endl;
			else cout << x[p-1][q-1] << endl;
		}
	}
}

Measured memory_bytes: 1240
#include <iostream>

int main () {
    int a, b, c, x, ans = 0;
    std::cin >> a >> b >> c >> x;
    for(int i = 0; i <= a; ++ i){
        for(int j = 0; j <= b; ++j){
            for(int k = 0; k <= c; ++k){
                if(i*500 + j*100 + 50*k == x) ++ans;
            }
        }
    }
    std::cout << ans << std::endl;

}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(INF)
#define INF 1e17
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b; cin>>a>>b;
	if(a%2!=b%2) cout<<"IMPOSSIBLE\n";
	else cout<<(a+b)/2<<"\n";
	return 0;
}




















Measured memory_bytes: 256
a = input()
print("NYoe s"[(a[0] == a[1] and a[1] == a[2]) or (a[1] == a[2] and a[2] ==
                                                   a[3]) or (a[0] == a[1] and a[1] == a[2] and a[2] == a[3])::2])


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int N=3e5+5;
const int M=1e5+5;
const int T=1e7+5;
int n,m,st[M],en[M];
pair<int,int> p[N];

struct Chairman_Tree
{
	int seg_tot,rt[N];
	struct node
	{
		int lsn,rsn,cnt;
	};
	node seg[T];
	
	void update(int &rt,int las,int l,int r,int pos)
	{
		seg[rt=++seg_tot]=seg[las];
		++seg[rt].cnt;
		if(l==r) return;
		int mid=(l+r)>>1;
		if(pos<=mid) update(seg[rt].lsn,seg[las].lsn,l,mid,pos);
		else update(seg[rt].rsn,seg[las].rsn,mid+1,r,pos);
	}
	
	int query(int rt,int las,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R) return seg[rt].cnt-seg[las].cnt;
		int mid=(l+r)>>1;int ret=0;
		if(L<=mid) ret+=query(seg[rt].lsn,seg[las].lsn,l,mid,L,R);
		if(R>mid) ret+=query(seg[rt].rsn,seg[las].rsn,mid+1,r,L,R);
		return ret;
	}
};
Chairman_Tree SS;

void init()
{
	int i,now=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
		scanf("%d%d",&p[i].first,&p[i].second);
	sort(p+1,p+n+1);
	
	for(i=1;i<=m;++i)
	{
		st[i]=now+1;
		while(p[now+1].first==i) ++now;
		en[i]=now;
	}
	
	for(i=1;i<=n;++i)
		SS.update(SS.rt[i],SS.rt[i-1],1,m,p[i].second);
}

int calc(int x,int y,int l,int r)
{
	return SS.query(SS.rt[en[y]],SS.rt[st[x]-1],1,m,l,r);
}

void work()
{
	int i,j,ans=0;
	for(i=1;i<=m;++i)
	{
		ans=0;
		for(j=i;j<=m;j+=i)
			ans+=calc(j-i+1,j,j,m);
		printf("%d\n",ans);
	}
}

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

Measured memory_bytes: 69120
H,W = map(int,input().split())
grid = []
for i in range(H):
    row = list(input())
    grid.append(row)
while True:
    r_change = False
    for q in range(len(grid)):
        if "#" not in grid[q]:
            del grid[q]
            r_change = True
            break
    if not r_change:
        break
while True:
    c_change = False
    for k in range(len(grid[0])):
        if "#" not in [row[k] for row in grid]:
            grid = [[row[p] for p in range(len(row)) if p != k] for row in grid]
            c_change = True
            break
    if not c_change:
        break
for row in grid:
    print("".join(row))

Measured memory_bytes: 3188
import java.util.*;
import java.lang.*;


public class Main {
	static int n;
	static int m;
	static int[] a;
	static int[] b;
	static boolean[] visited;
	static int count = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		a = new int[m];
		b = new int[m];
		visited = new boolean[n + 1];
		for (int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		search(1);
		System.out.println(count);
	}
	static void search(int number) {
		visited[number] = true;
		if (comp()) {
			count++;
			visited[number] = false;
			return;
		}
		for (int i = 0; i < m; i++) {
			if (a[i] == number && !visited[b[i]]) {
				search(b[i]);
			}
		}
		for (int i = 0; i < m; i++) {
			if (b[i] == number && !visited[a[i]]) {
				search(a[i]);
			}
		}
		visited[number] = false;
		return;
	}
	static boolean comp() {
		boolean bre = false;
		for (int i = 1; i <= n; i++) {
			if (!visited[i]) {
				bre = true;
				break;
			}
		}
		if (!bre) {
			return true;
		} else {
			return false;
		}
	}
}

Measured memory_bytes: 23764
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, T, *A = map(int, read().split())

    B = [0] * N
    B[0] = INF
    for i in range(N - 1):
        if B[i] > A[i]:
            B[i + 1] = A[i]
        else:
            B[i + 1] = B[i]

    p = 0
    C = [0] * N
    for i in range(N):
        C[i] = A[i] - B[i]
        if p < C[i]:
            p = C[i]

    ans = C.count(p)

    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int off = 1; off < n; ++off) {
    int len = 0;
    for (int i = 0; i < n-off; ++i) { 
      ans = max(ans, len);
      if (len == off) { 
        len = 0;
      }
      else if (s[i] == s[i+off]) ++len;
      else len = 0;
    }
    ans = max(ans, len);
  }
  cout << ans << endl;
}



Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;
const int maxn = 100100;

int main()
{
    int r,d,x;
    cin>>r>>d>>x;
    for (int i=1;i<=10 ;i++ )
    {
        x=r*x-d;
        cout<<x<<endl;
    }

	//system("pause");
	return 0;
}


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

using namespace std;

#define int long long

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (a > b)
    {
        cout << "safe" << endl;
    }
    else
    {
        cout << "unsafe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+10;
typedef long long ll;
const ll Inf=1e18;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,a[N],x,mn[N],pos[N];
ll ans=0;
int main() {
    cin>>n>>x;
    for(int i=1;i<=n;i++) a[i]=gi(),mn[i]=a[i],pos[i]=i,ans+=a[i];
    for(int j=1;j<=n;j++) {
        ll tmp=0;
        for(int i=1;i<=n;i++) {
            pos[i]--;if(pos[i]==0) pos[i]=n;
            mn[i]=min(mn[i],a[pos[i]]); tmp+=mn[i];
        }
        ans=min(ans,tmp+1ll*j*x);
    }
    printf("%lld\n",ans);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
count = 0

for i in range(0, n):
    minj = i
    for j in range(i, n):
        if a[j] < a[minj]:
            minj = j
    if i != minj:
        a[i], a[minj] = a[minj], a[i]
        count += 1
    
print(" ".join([str(num) for num in a]))
print(count)



Measured memory_bytes: 5608
#include<stdio.h>
int main(){
    int a,b,c,k;
    scanf("%d %d %d",&a,&b,&c);
    scanf("%d",&k);
    for(int i=1;i<=k;i++){
        if(c>=b){
            if(c>b){
                if(b>=a){
                    if(b>a){
                        printf("Yes\n");
                        return 0;
                    }else{
                        b=b*2;
                        continue;
                    }
                }else{
                    b=b*2;
                    continue;
                }
            }if(b>=a){
                if(b>a){
                    printf("Yes\n");
                    return 0;
                }else{
                    b=b*2;
                    continue;
                }
            }else{
                b=b*2;
                continue;
            }
        }else{
            c=c*2;
            continue;
        }
    }
    if((b>a)&&(c>b)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
 
//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int k;
	cin >> k;
	int l,r;
	cin >> l >> r;
	for (int i = l ; i <= r ; i++)
	{
		if (i % k == 0)
		{
			cout << "OK\n";
			return 0;
		}
	}
	cout << "NG\n";
	return 0;
}

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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n, m;
    cin >> n >> m;
    vector<Int> a(n);
    for (Int i = 0; i < (Int)n; i++) {
        cin >> a[i];
    }
    vector<Int> b(m);
    for (Int i = 0; i < (Int)n; i++) {
        b[a[i] % m]++;
    }
    Int res = b[0] / 2;
    b[0] -= res * 2;
    if (m % 2 == 0) {
        res += b[m / 2] / 2;
        b[m / 2] -= (b[m / 2] / 2) * 2;
    }
    for (Int i = 1; i < (Int)(m + 1) / 2; i++) {
        Int sub = min(b[i], b[m - i]);
        b[i] -= sub;
        b[m - i] -= sub;
        res += sub;
    }
    map<Int, Int> mp;
    for (Int i = 0; i < (Int)n; i++) {
        mp[a[i]]++;
    }
    for (auto i : mp) {
        if (i.se >= 2 and b[i.fi % m] >= 2) {
            Int sub = min(i.se / 2, b[i.fi % m] / 2);
            res += sub;
            b[i.fi % m] -= sub * 2;
        }
    }
    print(res);
    return 0;
}

Measured memory_bytes: 8064
n, d = map(int, input().split())
lst = []
for _ in range(n):
  x = list(map(int, input().split()))
  lst.append(x)
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    dist = 0
    for k in range(d):
      dist += (lst[i][k] - lst[j][k])**2
    j = 1
    while j**2 <= dist:
      if j**2 == dist:
        ans += 1
        break
      j += 1
print(ans)

Measured memory_bytes: 8952
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(a%3==0||b%3==0||(a+b)%3==0){
      	System.out.println("Possible");
      }else{
      	System.out.println("Impossible");
      }
    }
}

Measured memory_bytes: 21844
import copy, collections

n = int(input())
a = list(map(int, input().split()))
size = max(a)
a.sort()
a = collections.deque(a)
a2 = copy.copy(a)
b = [0] * (size + 1)
while a:
    test = a.popleft()
    count = 1
    if not a:
        pass
    else:
        while a[0] == test:
            a.popleft()
            count += 1
            if not a:
                break
    for i in range(size // test):
        b[test * (i + 1)] += count
ans = 0
for i in range(n):
    if b[a2[i]] == 1:
        ans += 1
print(ans)

Measured memory_bytes: 34280
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

#define lp for(ll i=0;i<n;i++)
#define MN 200000
ll n, k, a[MN], f[MN];

bool ps(ll t) {
	ll s = 0;
	lp if (a[i] * f[i] > t)s += a[i] - t / f[i];
	return s <= k;
}

int main() {	
	cin>>n>>k;
	lp cin >> a[i];
	lp cin >> f[i];
	sort(a,a+n);
	sort(f,f+n,greater<>());
	ll r = 0, l = 10000000000000000;
	while (r != l) {
		ll m=(r+l)/2;
		if (ps(m))l=m;
		else r=m+1;
	}
	cout << r << endl;
}

Measured memory_bytes: 3328
def f_saiki(n)
  i = n
  while i > 0 do
    saiki(n, i, [])
    i -= 1
  end
end

def saiki(n, i, a)
  if n == i
    a << i
    puts a.join(" ")
  else
    j = n - i
    while j > 0 do
      if j > i
        j -= 1
        next
      end
      saiki(n - i, j, a + [i])
      j -= 1
    end
  end
end

while (n = gets.to_i) != 0 do
  f_saiki(n)
end

Measured memory_bytes: 6116
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i, h) cin >> a.at(i);
  vector<bool> bh(h, false), bw(w, false);
  rep(i, h)rep(j, w){
    if(a.at(i).at(j) == '#'){
      bh.at(i) = true;
      bw.at(j) = true;
    }
  }
  rep(i, h){
    if(bh.at(i) == false) continue;
    rep(j, w){
      if(bw.at(j) == false) continue;
      cout << a.at(i).at(j);
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
    int P;
    int Q;
    int R;
    
    int largest;
    cin>> P>>Q>>R;
    largest=0;
    if (P>=Q && P>=R)
        largest=P;
    else if (R>=P && R>=Q)
        largest=R;
    else
        largest=Q;
    
    int sum;
    sum=P+Q+R-largest;
    
    cout << sum << endl;
    return 0;
}


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

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int N;
  cin >> N;
  vector<int> a(N+1);
  vector<int> b(N);
  rep(i, N+1){
    cin >> a[i];
  }
  rep(i, N){
    cin >> b[i];
  }

  ll ans = 0;

  rep(i, N){
    // 近くの敵をまず倒す
    int t = min(a[i], b[i]);
    ans += t;
    b[i] -= t;
    // 残りの力で倒す
    if(i < N){
      t = min(a[i+1], b[i]);
      ans += t;
      a[i+1] -= t;
    }
        
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n;
int main() {
    scanf("%d",&n);
    int ans = 0;
    for(int x=1;x<=n;x+=2) {
        int now = 1;
        int t = x;
        for(int i=2;i<=t;i++) {
            int cnt = 0;
            while(t%i==0) cnt++, t/=i;
            now *= (cnt+1);
        }
        if(now==8) ans++;
    }
    printf("%d",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N; cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) cin >> v[i];	

	ll xsum = 0;
	for (int i = 0; i < N; i++) xsum ^= v[i];
	for (int i = 0; i < N; i++) cout << (xsum ^ v[i]) << '\n';
	return 0;
}

Measured memory_bytes: 3800
n,k = map(int,input().split())
a = list(map(int,input().split()))
checked = [0]
next_num = a[0]-1
check = [0]*n
i = 0
while True:
    if i == 0:
        i += 1
    elif check[next_num] == 1:
        loop = checked[checked.index(next_num):]
        break
    checked.append(next_num)
    check[next_num] = 1
    next_num = a[next_num]-1
dif = len(checked) - len(loop)
if k <= dif:
    print(checked[k]+1)
else:
    k = k-dif
    print(loop[k%len(loop)]+1)

Measured memory_bytes: 32148
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int q,l,r,a[100005]={};
  bool f[100005]={};
  cin >> q;
  for(int i=2; i<=100000; i++) {
    if(!f[i]) {
      for(int j=i*2; j<=100000; j+=i) {
        f[j]=true;
      }
    }
  }
  for(int i=3; i<=100000; i+=2) {
    if(!f[i]&&!f[(i+1)/2]) {
      a[i]++;
    }
  }
  for(int i=3; i<=100000; i++) {
    a[i]+=a[i-1];
  }
  while(q--) {
    cin >> l >> r;
    cout << a[r]-a[l-1] << endl;
  }
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

#define rep(i, l, r) for (int i = l; i <= r; i ++)
#define dwn(i, r, l) for (int i = r; i >= l; i --)
#define repG(u, i) for (int i = hd[u]; i; i = e[i].nxt)
#define ev e[i].v
#define ec e[i].c
#define sqr(x) (x)*(x)
#define rlxX(x, y) x = max(x, y)
#define rlxN(x, y) x = min(x, y)
#define clr(a, b) memset(a, b, sizeof(a))
#define gc getchar()

typedef long long LL;
typedef double db;
const int N = 4e2 + 5, mod = 1e9 + 7;

int rd() {
	char ch = gc; int ret = 0;
	while (ch < '0' || ch > '9') ch = gc;
	while (ch >= '0' && ch <= '9') ret = ret*10 + ch-'0', ch = gc;
	return ret;
}

int n, c, a[N], b[N], p[N][N], s[N][N], f[N][N];

int main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	n = rd(), c = rd();
	rep(i, 1, n) a[i] = rd();
	rep(i, 1, n) b[i] = rd();
	rep(i, 1, N-1) p[i][0] = 1, s[i][0] = i;
	rep(i, 1, N-1) rep(j, 1, c) p[i][j] = 1ll*p[i][j-1]*i%mod, s[i][j] = (s[i-1][j]+p[i][j])%mod;

	f[0][0] = 1;
	rep(i, 1, n) rep(j, 0, c) {
		rep(k, 0, j) f[i][j] = (f[i][j]+1ll*f[i-1][j-k]*(mod+s[b[i]][k]-s[a[i]-1][k])%mod)%mod;
	}
	printf("%d\n", f[n][c]);

	return 0;
}
/*

*/



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


int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> vec(n);
    REP(i, n) cin >> vec[i];

    if (n <= k) {
        cout << 0 << endl;
        return 0;
    }
    sort(ALL(vec));
    cout << accumulate(vec.begin(), vec.begin()+(n - k), (long long)0) << endl;

    return 0;
}

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

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

    bool flag = false;
    int ans_i = 0, ans_j = 0, ans_k = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            int k = n - i - j;
            if (k >= 0 && k <= n) {
                int total = 10000 * i + 5000 * j + 1000 * k;
                if (total == y) {
                    flag = true;
                    ans_i = i;
                    ans_j = j;
                    ans_k = k;
                }
            }
        }
    }
    if (flag)
        cout << ans_i << " " << ans_j << " " << ans_k << endl;
    else
        cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main(void){
  int N;
  double T, A;
  cin >> N >> T >> A;
  int H[N];
  int i;
  //入力
  for(i=0; i<N; i++)
    cin >> H[i];

  double sub_min = 10000;
  int num_min;
  double tem, tem_abs;
  for(i=0; i<N; i++){
    //気温計算
    tem = T - H[i]*0.006;
    //cout << i+1 << " : tem : " << tem << endl;
    //絶対値計算
    tem_abs = fabs(tem - A);
    //cout << i+1 << " : abs : " << tem_abs << endl;
    //差の最小値の更新
    if(sub_min > tem_abs){
      sub_min = tem_abs;
      num_min = i+1;
    }
  }

  cout << num_min << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll x, y, z; cin >> x >> y >> z;
    x -= z;
    cout << x/(y+z) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> a(n); rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	int gcd = a[0]; reps(i, 1, n) gcd = __gcd(gcd, a[i]);
	printf("%d\n", gcd);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


vector<int> dijkstra(int i, int n, vector<vector<pair<int, int>>> graph) {
  vector<int> d(n, INF);
  d[i] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
  q.push(make_pair(0, i));
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : graph[v]) {
      if (d[x.first] > d[v] + x.second) {
        d[x.first] = d[v] + x.second;
        q.push(pair<int, int>(d[x.first], x.first));
      }
    }
  }
  return d;
}

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

  vector<vector<pair<int, int>>> graph(N);
  REP(i, N-1){
    int u, v, d;
    cin >> u >> v >> d;
    u--; v--;
    graph[u].emplace_back(v, d);
    graph[v].emplace_back(u, d);
  }

  auto dist = dijkstra(0, N, graph);
  
  REP(i, N){
    if(dist[i]%2) cout << 0 << "\n";
    else cout << 1 << "\n";
  }

  return 0;
}


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

bool check(int n,vector<int>&a){
    while(n){
        int m = n%10;
        if(a[m])
            return false;
        n/=10;
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);

    int n,k,x;
    cin >> n >> k;
    vector<int>a(10,0);
    for(int i=0;i<k;i++){
        cin >> x;
        a[x]++;
    }
    while(1){
        if(check(n,a)){
            cout << n << endl;
            break;
        }
        n++;
    }

    return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

x1, y1, x2, y2 = MAP()
a = complex(x1, y1)
b = complex(x2, y2)
rot = complex(cos(pi / 2), sin(pi / 2))
c = b + (b - a) * rot
d = a + (b - a) * rot
print(int(round(c.real, 0)), int(round(c.imag, 0)), int(round(d.real, 0)), int(round(d.imag, 0)))


Measured memory_bytes: 5976
/*
  Id: ak260901
  Task: a
  Lang: C++
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define foru(i, l, r) for(register int i = l; i <= r; i++)
#define ford(i, r, l) for(register int i = r; i >= l; i--)

int read() {
  int res = 0; char c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)) res = res * 10 + c - '0', c = getchar();
  return res;
}

const int maxn = 101;

int n, m, L[maxn], cnt = 1;

int main() {
  n = read(); m = read();
  for(int i = 1; i <= n; i++)
    L[i] = read();
  for(int i = 1; i <= n; i++) {
    L[i] += L[i - 1];
    if(L[i] > m) {printf("%d\n", cnt); return 0;}
    cnt++;
  } printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 256
// G++ MACro.cpp -std=c++14
#include <boost/multiprecision/cpp_int.hpp>
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define SANKOU(n,a,b) cout << ((n) ? (a) : (b) ) << endl;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)// for macro
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);// warshall-floyd

#define CIN(x) int x;cin>>x;
#define CIN2(x,y) int x,y;cin>>x>>y;
#define CIN3(x,y,z) int x,y,z;cin>>x>>y>>z;
#define SCIN(x) string x;cin>>x;
#define SCIN2(x,y) string x,y;cin>>x>>y;
#define COUT(x) cout<<(x)<<endl;
#define SCOUT(x) cout<<(x)<<" ";
#define ENDL cout<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i];
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())


#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair
int main(){
    CIN(n);
    V a(n);VECCIN(a);
    ll count=0;
    REP(i,n){
        count+=a[i]/2;
        a[i]%=2;
        if(a[i]&&a[i+1]){a[i+1]--;count++;}
    }
    COUT(count);

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main (int argc, char** argv)
{
    int a, b;
    char s[3];

    scanf("%d %d", &a, &b);
    memset(s, '\0', sizeof(s));

    if (a > b) {
        sprintf(s, "%s", ">");
    }
    else if (a < b) {
        sprintf(s, "%s", "<");
    }
    else {
        sprintf(s, "%s", "==");
    }

    printf("a %s b\n", s);
    return 0;
}

Measured memory_bytes: 592
N,K=map(int,input().split())
p=list(map(int,input().split()))
ans=(sum(p[0:K])+K)/2
temp=ans
for i in range(1,N-K+1):
    temp-=(p[i-1]+1)/2
    temp+=(p[i+K-1]+1)/2
    if temp>ans:
        ans=temp
print(ans)

Measured memory_bytes: 24804
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  int a,b;cin>>a>>b;
  b--;
  string s;cin>>s;
  s[b]=tolower(s[b]);
  cout<<s<<endl;
}


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

using namespace std;
int main()
{
 
   int a,b;
   scanf("%d%d",&a,&b);
   int i;
   int flag=1;
   for(i=1;;++i)
     {
         if((int)(i*0.08)==a && (int)(i*0.1)==b) 
             {   flag=1;
                 break;
             }
             
         if((int)(i*0.08)>a && (int)(i*0.1)>b) 
             {   flag=0;
                  break;
             }
             
     }
     
     if(flag==1)
         printf("%d",i);
         
     else
       printf("-1");

}

Measured memory_bytes: 256
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans = 0
for i in range(n):
  if i==0:
    if a[0]>x:
      ans += a[0]-x
      a[0]=x
  else:
    if a[i-1]+a[i]>x:
      ans += a[i-1]+a[i]-x
      a[i]=x-a[i-1]
print(ans)

Measured memory_bytes: 14592
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

S = s()

res = ''
for c in S:
    if c == '0':
        res += '0'
    elif c == '1':
        res += '1'
    elif len(res) > 0:
        res = res[:-1]

print(res)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {



        long N = cin.Nextint;
        var A = cin.Scanlong;
        long ans = 0;
        while (true)
        {
            long tmp = 0;
            for (int i = 0; i < N; i++)
            {
                tmp += A[i] / N;
            }
            if (tmp == 0) break;
            ans += tmp;
            for (int i = 0; i < N; i++)
            {
                A[i] = A[i] % N + (tmp - A[i] / N);
            }
        }
        WriteLine(ans);


        /*for (int i = 0; i < N; i++)
        {
            M[A[i] % N]++;
            cnt += A[i] / N;
        }

        for (int i = 0; i < N; i++)
        {
            cnt += 
        }*/

        /*Array.Sort(A);
        Array.Reverse(A);

        //最大で，
        long K = (A[0] - (N - 1)) * N;
        WriteLine(K + " " + K / N);

        long D = K / N;


        long cnt = 0;

        for (int i = 0; i < N; i++)
        {
            if (A[0] == A[i]) continue;

            long t = (A[0] - A[i]) / N + 1;
            long d = (A[i] + D) / N - (A[i] + D) / N;
            WriteLine(t - d);

            K -= Math.Min(t - d, D);
        }

        WriteLine(K);

        for (int i = 0; i < N; i++)
        {
            cnt += A[i] / N;

        }*/

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 11216
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    const int max = 1e9;
    for(int i = 0;i <= max;i++){
        if(abs(a-i) == abs(b-i)){
            cout << i << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    int n;
    cin >> n;

    int odd = 0;

    rep(i, n){
        int a;
        cin >> a;
        if(a%2) ++odd;
    }

    if(odd%2) puts("NO");
    else puts("YES");

    return 0;
}

Measured memory_bytes: 256
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
// set<int>st{ 3,1,4,1,5,9,2,6,5,3,5 };
//     for (auto itr = st.begin(); itr != st.end(); ++itr) {
//         cout << *itr;
//     }
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
  int n;
  cin>>n;
  vector<int>vec(n);
  int d=0;
  int sum=0;
  rep(i,n){
    cin>>vec.at(i);
    if(i==0){
      sum+=1;
      d=vec.at(0);
    }else{
      if(vec.at(i)<=d){
       sum+=1;
       d=vec.at(i);
      }
    }
  }
  cout<<sum<<endl;
  }

Measured memory_bytes: 4060
/// Zhupengfei 2018
/// Hereby declare: this program is in public domain.

/// Solution for problem: SoundHound D

#include <bits/stdc++.h>

#ifdef LOCAL
#pragma GCC poison printf // To avoid fastio problems
#pragma GCC poison scanf
#endif

using namespace std;

struct rec{
	int u;
	int a, b;
};

vector<rec> sons[100001]={};
long long maximal[100001]={};
long long dists[100001]={};
long long distt[100001]={};

bool v[100001]={};
int n, m, s, t;

typedef pair<int,int> P; 

pair<long long, int> ans[100001]={};

void dijkstras(int s)
{
    priority_queue<P,vector<P>,greater<P> > que;
    dists[s] = 0;
    que.push(P(0,s));
    while(!que.empty())
    {
        P p = que.top(); que.pop();
        int v = p.second;
        if (dists[v] < p.first) continue;
        for(int i = 0; i < sons[v].size(); i++)
        {
            auto e = sons[v][i];
            if (dists[e.u] > dists[v] + e.a)
            {
                dists[e.u] = dists[v] + e.a;
                que.push(P(dists[e.u],e.u));
            }
        }
    }
}

void dijkstrat(int s)
{
    priority_queue<P,vector<P>,greater<P> > que;
    distt[s] = 0;
    que.push(P(0,s));
    while(!que.empty())
    {
        P p = que.top(); que.pop();
        int v = p.second;
        if (distt[v] < p.first) continue;
        for(int i = 0; i < sons[v].size(); i++)
        {
            auto e = sons[v][i];
            if (distt[e.u] > distt[v] + e.b)
            {
                distt[e.u] = distt[v] + e.b;
                que.push(P(distt[e.u],e.u));
            }
        }
    }
}

bool operator<(pair<long long, int> a, pair<long long, int> b){
	return a.first==b.first?a.second>b.second:a.first>b.first;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int u, v, a, b;
	cin>>n>>m>>s>>t;
	for(int i=1;i<=m;i++){
		cin>>u>>v>>a>>b;
		sons[u].push_back({v, a, b});
		sons[v].push_back({u, a, b});
	}
	for(int i=1;i<=n;i++) dists[i]=distt[i]=1e18;
	dijkstras(s);
	dijkstrat(t);
	for(int i=1;i<=n;i++){
		ans[i]=make_pair((long long)(1e15)-dists[i]-distt[i], i);
	}
	sort(ans+1, ans+n+1);
	int year=0;
	for(int i=n;i>=1;i--) {
		while(year<ans[i].second) {
			year++;
			cout<<ans[i].first<<endl;
		}
	}
	
	return 0;
}



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


int main(){
    int N;
    cin >> N;
    int T[N];
    int A[N];
    for(int i=0; i<N; i++){
        cin >> T[i] >> A[i];
    }

    long long currentT=T[0], currentA=A[0];
    for(int i=1; i<N; i++){
        long long nextT=T[i], nextA=A[i];
        /*if(nextT < currentT || nextA < currentA){
            long long scale = max( ceil((double)currentT/nextT) ,
                                   ceil((double)currentA/nextA) );
            nextT *= scale;
            nextA *= scale;
        }*/
        if(nextT < currentT || nextA < currentA){
            long long scale = max(currentT/nextT,currentA/nextA);

            nextT = T[i]*scale;
            nextA = A[i]*scale;
            if(nextT < currentT || nextA < currentA){
                scale++;
                nextT = T[i]*scale;
                nextA = A[i]*scale;
            }
        }


        currentT = nextT;
        currentA = nextA;
    }
    cout << (currentT + currentA) << '\n';

}





Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M; cin >> N >> M;
  vector<int> cnt(N+1, 0);
  REP(i, M){
    int a, b; cin >> a >> b;
    cnt[a]++;
    cnt[b]++;
  }
  bool flag = true;
  REP(i, N){
    if(cnt[i]%2 == 1) flag = false;
  }
  if(flag){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3704
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  REP(i,a,b) for(int i=a;i<b;i++)
typedef long long int lld;
typedef vector<lld> vl;
typedef vector<int> vi;
typedef vector<string> vs;



//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());

int main() {

	long n,k;
	cin>>n;
	vl x;
	rep(i,5){
		cin>>k;
		x.push_back(k);
	}
	long min=*min_element(x.begin(),x.end());
	long ans;
	if(n%min==0)
		ans=n/min+4;
	else
		ans=n/min+5;

	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
n = int(raw_input())

xx = 1
yy = 1
for i in xrange(n):
  [x, y] = [int(e) for e in raw_input().strip().split()]
  #print "===%d, %d===" % (x, y)
  if i == 0:
    xx = x
    yy = y
  else:
    #print "===(%d, %d)  (%d, %d)===" % (x, y, xx, yy)
    if x >= xx and y >= yy:
	  xx = x
	  yy = y
    else:
	  multi_x = -1
	  multi_y = -1
	  if x < xx:
	    multi_x = xx / x
	    if xx % x != 0: multi_x += 1
	  if y < yy:
	    multi_y = yy / y
	    if yy % y != 0: multi_y += 1
	  multi = max(multi_x, multi_y)
	  xx = x * multi
	  yy = y * multi
	  #print "===" + str(multi)
print xx + yy

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

int main(){
    int N;cin >> N;
    vector<long long> L(N);
    int count=0;
    for(int i=0;i<N;i++) cin >> L.at(i);
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int k=j+1;k<N;k++){
                if((L.at(i)!=L.at(j))&&(L.at(j)!=L.at(k))&&(L.at(k)!=L.at(i))){
                    long long M=max(L.at(i),max(L.at(j),L.at(k)));
                    if(!(M>=(L.at(i)+L.at(j)+L.at(k)-M))) count++;            
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int answer[5];
int in[5];
int main(){
	for(int i = 0;i<=4;i++){
		cin >> in[i];
	}
	for(int i = 0;i<=4;i++){
		for (int j =i+1; j<=4;j++){
			if(in[i] <= in[j]){
				int t = in[i];
				in[i] = in[j];
				in[j] = t;
			}
		}
	}
	for(int i = 0;i<=3;i++)
		cout << in[i] << " " ;
		
	cout << in[4]<< endl;
	return 0;
}

Measured memory_bytes: 0
ll = set()

def search(s):
    ll.add(int(s))
    if len(s) == 10:
        return
    
    if int(s[-1]) == 0:
        search(s+"1")
    elif int(s[-1]) == 9:
        search(s+"8")
    else:
        search(s+str(int(s[-1])+1))
        search(s+str(int(s[-1])-1))
    search(s+s[-1])
    
for i in range(1, 10):
    search(str(i))

ll = list(sorted(ll))

print(ll[int(input())-1])

Measured memory_bytes: 67000