akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int a,b,c; cin>>a>>b>>c;
    if (a==b && b==c && c==a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " = " << (x) << endl;

long long A[1<<20];
long long B[1<<20];
long long f[1<<20];

#define mod 1000000007
#define ll long long

ll inv[1<<20]; // ith index will store (1/i)%mod
ll finv[1<<20]; // ith index will store (1/i!)%mod
ll fact[1<<20]; // ith index will store (i!)%mod

void populate(int n) {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for(int i = 2;i <= n;i++) {
        fact[i] = (i*fact[i-1])%mod;
        inv[i] = mod-((inv[mod%i]*(mod/i))%mod);
        finv[i] = (finv[i-1]*inv[i])%mod;
    }
}

int main() {
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    int n;cin>>n;

	int s = -1, e = -1;
    populate(n+10);
	for(int i = 1;i <= n+1;i++) {
		cin>>A[i];
		if(B[A[i]]) {
			s = B[A[i]];
			e = i;
			break;
		}
		B[A[i]] = i;
	} s--;e--;

    int i = e, j = s;
    ll x = 0, y = 0;
	for(int k = 1;k <= n+1;k++) {
        x = (fact[n+1]*((finv[k]*finv[n+1-k])%mod))%mod;
		y = 0;
		if(k-1 <= n-i+j) {
            y = (fact[n-i+j]*((finv[k-1]*finv[n-i+j+1-k])%mod))%mod;
		}

		cout<<(x-y+mod)%mod<<endl;
	}

    return 0;
}


Measured memory_bytes: 10240
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int nm(int a,int b){
    if(a<b) swap(a,b);
    return (a-1)*(a-2)/2+b-1;
}

bool TS(vector<vector<int>>&v,vector<int>&ts,vector<int>&it){
    int n=v.size();
    vector<int> h(n);
    fr(i,n) for(auto j:v[i]) ++h[j];
    stack<int> st;
    fr(i,n) if(h[i]==0) st.push(i);
    while(!st.empty()){
        int i=st.top();st.pop();
        ts.emplace_back(i);
        for(auto j:v[i]){
            --h[j];
            if(h[j]==0) st.push(j);
        }
    }
    if(ts.size()!=n) return true;
    it.resize(n);
    fr(i,n) it[ts[i]]=i;
    return false;
}

class ELeague {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,m;
        in>>n;
        m=n*(n-1)/2;
        vector<int> h(m);
        vector<vector<int>> a(n+1,vector<int>(n-1));
        vector<vector<int>> v(m);
        Fr(i,n) fr(j,n-1) in>>a[i][j];
        Fr(i,n) fr(j,n-2) v[nm(i,a[i][j])].emplace_back(nm(i,a[i][j+1]));
        vector<int> ts,it;
        if(TS(v,ts,it)){
            out<<-1<<endl;
            return;
        }
        vector<int> dp(m);
        int ans=0;
        fr(i,m){
            ans=max(ans,dp[i]);
            for(auto j:v[ts[i]]){
                dp[it[j]]=max(dp[it[j]],dp[i]+1);
            }
        }
        out<<ans+1<<endl;
    }
};

int main() {
    ELeague solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

int main(){
  int64_t N, M, X;
  cin >> N >> M >> X;
  vector<int64_t> C(N);
  vector<vector<int64_t>> A(N, vector<int64_t>(M));
  for(int64_t i=0; i<N; i++){
    cin >> C.at(i);
    for(int64_t j=0; j<M; j++){
      cin >> A.at(i).at(j);
    }
  }
  int64_t Ans=10000000;
  for(int64_t i=0; i<(int64_t)pow(2, N); i++){
    int64_t Sum=0;
    int64_t subAns=0;
    vector<int64_t> Know(M, 0);
    for(int64_t j=0; j<N; j++){
      if((i/(int64_t)pow(2, j))%2==1){
        for(int64_t k=0; k<M; k++){
          Know.at(k)+=A.at(j).at(k);
        }
        subAns+=C.at(j);
      }
    }
    int64_t p=1;
    for(int64_t j=0; j<M; j++){
      if(Know.at(j)<X){
        p=0;
        break;
      }
    }
    if(p==1){
      Ans=min(Ans, subAns);
    }
  }
  if(Ans==10000000){
    cout << -1 << endl;
  }
  else{
    cout << Ans << endl;
  }
}

Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int k,t;
	k=c-(d-b);
	t=d+(c-a);
	cout<<k<<' '<<t<<' '<<k-(c-a)<<' '<<t-(d-b)<<endl;
}

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

int main() {
    int n; cin >> n;
    int sum = 0;
    int w[100], d[100];
    for (int i = 0; i < n; i++) {
        cin >> w[i]; sum += w[i];
    }
    d[0] = w[0];
    for (int i = 1; i < n; i++) {
        d[i] = d[i-1]+w[i];
    }
    int ans = 1000000000;
    for (int i = 1; i < n; i++) {
        ans = min(ans, abs(2*d[i]-sum));
    }
    cout << ans << endl;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll n,s;cin>>n>>s;
  if(n<s)cout<<-1<<endl;
  else if(n==s)cout<<n+1<<endl;
  else{
    for(i=2;i*i<=n;i++){
      buf=n;
      buf2=0;
      for(;buf!=0;buf/=i){
        buf2+=buf%i;
      }
      if(buf2==s)chmin(res1,i);
    }
    for(i=1;i*i<=n;i++){
      if((n-s)%i==0){
        ll x=1+(n-s)/i;
        buf=n;
        buf2=0;
        for(;buf!=0;buf/=x){
          buf2+=buf%x;
        }
        if(buf2==s)chmin(res1,x);
      }
    }
    if(res1==INF)cout<<-1<<endl;
    else cout<<res1<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char a[6];
    scanf("%s",a);
    int b[26]={0},i,flag=0;
    for (i=0;i<4;i++){
        b[a[i]-65]++;
    }
    for(i=0;i<26;i++){
        if(b[i]==2)
            flag++;
    }
    if(flag==2){
        printf("Yes");
    }
   else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 128
def inpl(): return list(map(int, input().split()))
A, B, M = inpl()
A = inpl()
B = inpl()
res = min(A) + min(B)
for _ in range(M):
    x, y, c = inpl()
    tmp = A[x-1] + B[y-1] - c
    if tmp < res:
        res = tmp
print(res)

Measured memory_bytes: 24812
#include<bits/stdc++.h>
#define maxn 15
#define maxk 1010
using namespace std;

int p[maxn],c[maxn],d,g,n;
int f[maxn][maxk];
int main(){
	scanf("%d%d",&d,&g);
	for(int i=1;i<=d;i++)
		scanf("%d%d",&p[i],&c[i]);
	memset(f,0xcf,sizeof(f));
	f[0][0]=0;
	for(int i=1;i<=d;i++){
		for(int j=0;j<maxk;j++){
			for(int k=0;k<=min(j,p[i]);k++)
				f[i][j]=max(f[i][j],f[i-1][j-k]+k*100*i+(k==p[i]?c[i]:0));
		}
	}
	int ans=0;
	for(int i=1;i<maxk;i++)
		if(f[d][i]>=0&&f[d][i]<g)
			ans=i;
	printf("%d\n",ans+1);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
using namespace std;
int n, a;
int main()
{
	cin>>n>>a;
	if(n>=a)
	{
		cout<<"10"<<endl;
		return 0;
		}	
	else
	{
		cout<<"0"<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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; }

int main() {
    ll N; cin >> N;
    vector<int64_t> p(N), c(N);
    rep(i, N) cin >> p.at(i);
    rep(i, N) c.at(i) = i + 1;

    ll cnt = 0;
    rep(i, N) if (p.at(i) != c.at(i)) cnt++;
    if (cnt <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3616
"use strict";
// import bigInt from 'big-integer'

const Main = input => {
  input = input.trim()
  const a = 'abcdefghijklmnopqrstuvwxyz'
  const i = a.indexOf(input) + 1

  console.log(a[i]);
};

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


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

struct Stat {
	long long a, b, c;
	Stat(){}
	Stat( long long a, long long b, long long c ):a(a),b(b),c(c){}
};
bool operator<( const Stat &r, const Stat &s ) {
	if( r.a != s.a ) return r.a < s.a;
	if( r.b != s.b ) return r.b < s.b;
	return r.c < s.c;
}

long long a, b, c;
set<Stat> st;

int main() {
	int ans;
	cin >> a >> b >> c;
	st.insert(Stat(a,b,c));
	for( ans = 0; !((a&1) || (b&1) || (c&1)); ans++ ) {
		long long aa = (b+c)>>1;
		long long bb = (a+c)>>1;
		long long cc = (a+b)>>1;
		if( st.count(Stat(aa,bb,cc)) ) {
			printf( "-1\n" );
			return 0;
		}
		st.insert(Stat(aa,bb,cc));
		a = aa;
		b = bb;
		c = cc;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
n=int(input())
s=input()

r_cnt=s.count("R")
g_cnt=s.count("G")
b_cnt=s.count("B")

ans=r_cnt*g_cnt*b_cnt

for i in range(n):
    for d in range(n):
        j=i+d
        k=j+d
        if k>=n:
            break
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
            ans-=1

print(ans)   

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
int main(){
    string A,B,C;
    cin>>A>>B>>C;
    char turn='A';
    while(1){
        switch(turn){
            case 'A':
                if(A.size()==0){goto LAST;}
                turn=A[0]+('A'-'a');
                A.erase(A.begin());
                break;
            case 'B':
                if(B.size()==0){goto LAST;}
                turn=B[0]+('A'-'a');
                B.erase(B.begin());
                break;
            case 'C':
                if(C.size()==0){goto LAST;}
                turn=C[0]+('A'-'a');
                C.erase(C.begin());
                break;
        }
    }
LAST:
    cout<<turn<<endl;
}

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

using namespace std;

bool cmp(pair<char, int[3]> p, pair<char, int[3]> q) 
{
    return (p.second[0] > q.second[0]) || (p.second[0] == q.second[0] && p.second[1] < q.second[1]);
}


int main()
{
    int n;

    while (cin >> n) {
        if (!n)
            break;
        
        pair<char, int[3]> team[10];

        for (int i = 0; i < n; i++) {
            char ch;
            
            cin >> team[i].first;
            for (int j = 0; j < n - 1; j++) {
                int ind;
                cin >> ind;
                team[i].second[ind]++;
            }
        }
        
        stable_sort(team, team + n, cmp);

        for (int i = 0; i < n; i++)
            cout << team[i].first << endl;
    }

    return 0;
}

Measured memory_bytes: 1200
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static final long MOD = 1000_000_007;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int last = 0;
        int primes[] = new int[n];
        Arrays.fill(primes, 0);
        for (int i = 1; i <= n; i++) {
            if (isPrime(i)) {
                primes[last] = i;
                last++;
            }
        }

        int counts[] = new int[n];
        Arrays.fill(counts, 0);
        for (int i = 1; i <= n; i++) {
            int ii = i;
            for (int j = 0; j < last; j++) {
                while (ii % primes[j] == 0) {
                    counts[j]++;
                    ii = ii / primes[j];
                }
            }
        }

        long ans = 1;
        for (int i = 0; i < last; i++) {
            ans = modmul(ans, counts[i] + 1, MOD);
        }

        System.out.println(ans);
    }

    static boolean isPrime(long n) {
        if (n == 1) return false;
        if (n == 2) return true;
        for (long i = 2; i < Math.sqrt(n) + 1; i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }

    static long modmul(long a, long b, long mod) {
        return (a * b) % mod;
    }
}

Measured memory_bytes: 23764
n = gets.to_i
a = gets.split.map(&:to_i)

puts a.join(' ')

(1...a.length).each do |i|
  key = a[i]
  j = i - 1
  while j >= 0 && a[j] > key do
    a[j + 1] = a[j]
    j -= 1
  end
  a[j + 1] = key

  puts a.join(' ')
end

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

struct triplet {
  ll x, y, z;
};

ll d(int n, int m, vector<ll> x, vector<ll> y, vector<ll> z) {
  vector<triplet> xyz(n);
  for(int i=0;i<n;i++) {
    xyz[i] = {x[i], y[i], z[i]};
  }
  ll res = 0;
  for(int i=0;i<8;i++) {
    bool x_p = i & 1;
    bool y_p = i & 2;
    bool z_p = i & 4;

    sort(xyz.begin(), xyz.end(), [&](auto const& lhs, auto const& rhs) {
	ll xx_1 = x_p ? lhs.x : -lhs.x;
	ll yy_1 = y_p ? lhs.y : -lhs.y;
	ll zz_1 = z_p ? lhs.z : -lhs.z;

	ll xx_2 = x_p ? rhs.x : -rhs.x;
	ll yy_2 = y_p ? rhs.y : -rhs.y;
	ll zz_2 = z_p ? rhs.z : -rhs.z;
	return xx_1 + yy_1 + zz_1 > xx_2 + yy_2 + zz_2;
	});
    /* 
    for(int j=0;j<n;j++) {
      cout << xyz[j].x << " " << xyz[j].y << " " << xyz[j].z  << " " << (x_p ? xyz[j].x : -xyz[j].x) + (y_p ? xyz[j].y : -xyz[j].y) + (z_p ? xyz[j].z : -xyz[j].z)<< endl;
    }
    */

    ll temp = 0;
    for(int j=0;j<m;j++) {
      temp += ((x_p ? xyz[j].x : -xyz[j].x) + (y_p ? xyz[j].y : -xyz[j].y)+ (z_p ? xyz[j].z : -xyz[j].z));
    }
    //cout << "temp -> " << temp << endl;
    //cout << "========" << endl;
    res = max(res, temp);
  }

  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> x(n);
  vector<ll> y(n);
  vector<ll> z(n);
  for(int i=0;i<n;i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  cout << d(n, m, x, y, z);
}

Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;
  vi a(n),b(n);
  REP(i,n) cin>>a[i];

  ll allx=0;
  for(ll i=0;i<n;i++){
    allx^=a[i];
  }
  //cout<<allx<<endl;

  for(ll i=0;i<n;i++){
    cout<<(allx^a[i])<<" ";
  }
  cout<<endl;

  return 0;
}

Measured memory_bytes: 6368
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A, B;
    REP(i, 0, N) {
        int c;
        cin >> c;
        if (c < 0) {
            A.push_back(-c);
        } else {
            B.push_back(c);
        }
    }
    reverse(begin(A), end(A));
    lli ans = 1LL << 60;
    if (K <= B.size()) {
        ans = B[K - 1];
    }
    if (K <= A.size()) {
        ans = min(ans, (lli)A[K - 1]);
    }
    REP(i, 0, min(K, (int)A.size())) {
        int pos = K - i - 2;
        if (pos >= B.size()) continue;
        int m = min(A[i], B[pos]), M = max(A[i], B[pos]);
        ans = min(ans, 2LL * m + M);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1020
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
maxD = 0
count = [0 for _ in range(N)]
for d in D:
    maxD = max(maxD,d)
    count[d] += 1
answer = 1
for i in range(maxD):
    x = count[i]
    y = count[i+1]
    answer *= pow(x,y,MOD)
    answer %= MOD
if count[0] != 1 or D[0] != 0:
    print(0)
else:
    print(answer)

Measured memory_bytes: 18012
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <utility>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,_all1,_all2,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
const int MOD = 1e9+7;
const int INF = numeric_limits<int>::max();
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; }
template<typename Iterator>void print(const Iterator s, const Iterator t) { if(s==t)return;for(auto it=s;it+1!=t;++it)cout<<*it<<" ";cout<<*(t-1)<<"\n"; }
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}

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

  int A[N-1], B[N-1], c[N];
  bool visited[N];
  fill(all(visited, N), false);

  rep(i, N-1) {
    in(A[i]); in(B[i]);
    --A[i]; --B[i];
  }
  int sum = 0;
  rep(i, N) {
    in(c[i]);
    sum += c[i];
  }
  sort(all(c, N));
  reverse(all(c, N));
  out(sum-c[0]);
  visited[A[0]] = visited[B[0]] = true;

  int ans[N];
  ans[A[0]] = c[0];
  ans[B[0]] = c[1];
  rep(i, 1, N-1) {
    rep(j, N-1) {
      if (visited[A[j]] != visited[B[j]]) {
        if (!visited[A[j]])
          ans[A[j]] = c[i+1];
        else
          ans[B[j]] = c[i+1];
        visited[A[j]] = visited[B[j]] = true;
        break;
      }
    }
  }
  rep(i, N) {
    cout << ans[i];
    if (i + 1 != N)
      cout << " ";
  }
  cout << "\n";

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vi p(n);
	rep(i, 0, n) {
		cin >> p[i];
	}
	vi dp(n + 1, 0);
	rep(i, 0, n) {
		dp[p[i]] = dp[p[i] - 1] + 1;
	}
	int ans = n - *max_element(all(dp));
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
void fun()
{

}
/// check for test case before submitting
void vfun()
{
    ll n;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];
    sort(v.begin(),v.end());
    ll mincs=INT_MAX;
    for(ll k=-100;k<=100;k++)
    {
        ll cst=0;
         fo(i,n)
         {
             cst+=pow(abs(v[i]-k),2);
         }
         mincs=min(mincs,cst);
    }
    cout<<mincs;

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
   // cin>>test;
    while(test--)
    {

        //fun();
        vfun();
//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not



Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int w, h, ans;
char map[20][20];

void ex(int x, int y) {
  if(x < 0 || y < 0 || x >= w || y >= h) return;
  if(map[x][y] == '#') return;

  if(map[x][y] == '@' || map[x][y] == '.') {
    map[x][y] = ':';
    ans ++;
  }
  else {
    return;
  }
  
  ex(x-1, y);
  ex(x+1, y);
  ex(x, y-1);
  ex(x, y+1);
  
  return;
}

int main() {
  while(cin >> w >> h) {
    if(w == 0 && h == 0) break;
    char tmp;
    int s[2];
    for(int j = 0; j < h; j ++) {
      for(int i = 0; i < w; i ++) {
	cin >> tmp;
	map[i][j] = tmp;
	if(tmp == '@') {
	  s[0] = i;
	  s[1] = j;
	}
      }
    }
    
    ans = 0;
    //cout << s[0] << s[1] << endl;
    ex(s[0], s[1]);
    
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
  while(1){
    int n,a=0,b=0,kai=0;
    string asi;
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>asi;
      if(asi[0]=='r'){
        if(asi[1]=='u')a++;
        else a--;
      }
      if(asi[0]=='l'){
        if(asi[1]=='u')b++;
        else b--;
      }
      if(kai%2==0&&a+b==2)kai++;
      if(kai%2==1&&a+b==0)kai++;
    }
    printf("%d\n",kai);
  }
  return 0;
}

Measured memory_bytes: 3148
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

n,k = map(int,input().split())
li = []

for i in range(n):
    a = list(map(int,input().split()))
    li.append(a)

li.sort()

cnt = 0

for i in range(n):
    cnt += li[i][1]

    if cnt >= k:
        print(li[i][0])
        break



Measured memory_bytes: 27872
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;

namespace mp = boost::multiprecision;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;
int N, C;
int H[MAX_N];

/**
* convex hull trick(最小値版 最大値求めたいときはadd(a, b)をadd(-a, -b)にすればいいと思うよ)
*/

template< class T >
struct ConvexHullTrickAddQueryMonotone
{
  deque< pair< T, T > > L;
  int isdec;
 
  ConvexHullTrickAddQueryMonotone() : isdec(-1) {}
 
  inline T getX(const pair< T, T > &a, const T &x)
  {
    return (a.first * x + a.second);
  }
 
  inline bool check(const pair< T, T > &a, const pair< T, T > &b, const pair< T, T > &c)
  {
    return ((b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first));
  }
 
  inline bool empty() { return (L.empty()); }
 
  void add(T a, T b)
  {
    pair< T, T > line(a, b);
 
    if(!L.empty() && L.back().first == a) {
      line.second = min(line.second, L.back().second);
      L.pop_back();
    }
    while(L.size() >= 2 && check(L[L.size() - 2], L.back(), line)) L.pop_back();
    L.emplace_back(line);
 
  }
 
  T getMinimumQuery(T x)
  {
    int low = -1, high = (int) L.size() - 1;
    while(high - low > 1) {
      int mid = (low + high) >> 1;
      if((getX(L[mid], x) >= getX(L[mid + 1], x))) low = mid;
      else high = mid;
    }
    return (getX(L[high], x));
  }
 
  T getMinimumQueryMonotone(T x)
  {
    while(L.size() >= 2 && getX(L[0], x) >= getX(L[1], x)) {
      L.pop_front();
    }
    return (getX(L[0], x));
  }
 
};

int dp[MAX_N];

signed main()
{
  cin >> N >> C;
  REP(n,N) {
    cin >> H[n];
  }

  ConvexHullTrickAddQueryMonotone<int> cht;
  dp[1] = 0; cht.add(-2*H[0], H[0]*H[0]);

  FOR(n,1,N) {
    dp[n+1] = C + H[n]*H[n] + cht.getMinimumQueryMonotone(H[n]);
    cht.add(-2*H[n], H[n]*H[n]+dp[n+1]);
  }

  cout << dp[N] << endl;

  return 0;
}

Measured memory_bytes: 5632
#include<stdio.h>

int N,s[100000];

int binarySearch(int key){
  int left=0;
  int right=N;
  int mid;

  while(left<right){
    mid=(left+right)/2;
    if(key==s[mid])return 1;
    if(key>s[mid])left=mid+1;
    else if(key<s[mid])right=mid;
  }
  return 0;
}

int main(){

  int i,key,N2,c=0;
  scanf("%d",&N);

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

  scanf("%d",&N2);

  for(i=0;i<N2;i++){
    scanf("%d",&key);
    if(binarySearch(key))c++;

  }

  printf("%d\n",c);


  return 0;
}


Measured memory_bytes: 2116
import java.io.File;
import java.io.FileInputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

public class Main {
	
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		long ans = 1;
        long MOD = 1000000007;
        for(int i = 1; i <= N; i++)
          ans = (ans * i) % MOD;
        System.out.println(ans);
	}
}


Measured memory_bytes: 21712
menew=[int(input()) for i in range(5)]
small=0
jo=10

for i in range(5):
    if menew[i]%10<jo and menew[i]%10!=0:
        jo=menew[i]%10
        small=menew[i]
if small!=0:
    menew.remove(small)
    ans=0
    for i in range(4):
        if menew[i]%10==0:
            p=0
        else:
            p=10-menew[i]%10
        ans+=menew[i]+p
    ans+=small
    print(ans)
else:
    print(sum(menew))



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int main()
{
	IOS;
    cout.precision(30);
    ll s; cin >> s;
    ll mod=1000000000;
    ll a=s%mod;
    ll b=s/mod;
    if (a!=0)
    {
        b++;
        a=mod-a;
    }
    cout << 0 << " " << 0 << " " << mod << " " << 1 << " " << a << " " << b ;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <array>
#include <set>
#include <climits>
#include <cassert>
#include <bitset>
#include <numeric>
using namespace std;
#define mod 1000000007



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

#ifdef HELL_JUDGE
    freopen("input","r",stdin);
    freopen("output","w",stdout);
    freopen("error","w",stderr);
#endif 
    int n; cin>>n;
    vector<int>v(n);
    for(auto&itr:v){
        cin>>itr;
    }
    sort(v.begin(),v.end());
    bool ok= true;
    for(int i=1;i<n;++i){
        ok&=(v[i]!=v[i-1]);
    }
    if(ok){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
#define LL long long
struct Edge{
	int next,to;
}edge[maxn*2];
int fi[maxn],n,se,ans=0,que[maxn],s,t,dep[maxn],U,V,dep1[maxn];
inline void add_edge(int u,int v){edge[++se].next=fi[u],edge[se].to=v,fi[u]=se;}
inline void add(int u,int v){add_edge(u,v),add_edge(v,u);}
void bfs(){
	dep[U]=1,que[t++]=U;
	while(s<t){
		int u=que[s++];
		for(int i=fi[u];i;i=edge[i].next){
			int v=edge[i].to;
			if(!dep[v])dep[v]=dep[u]+1,que[t++]=v;
		}
	}
	s=t=1;que[t++]=V,dep1[V]=1;
	while(s<t){
		int u=que[s++];
		if(dep[u]<dep1[u])ans=max(ans,dep1[u]-1); 
		for(int i=fi[u];i;i=edge[i].next){
			int v=edge[i].to;
			if(!dep1[v])dep1[v]=dep1[u]+1,que[t++]=v;
		}
	}
}
int main(){
	int u,v;scanf("%d%d%d",&n,&U,&V);
	for(int i=1;i<n;i++)scanf("%d%d",&u,&v),add(u,v);
	bfs();
	printf("%d",ans-1);
	return 0;
}

Measured memory_bytes: 3328
<?php
  
$n = trim(fgets(STDIN));
$d = explode(' ', trim(fgets(STDIN)));

$c = 0;
for($i=0; $i<$n-1; $i++){
  for($j=$i+1; $j<$n; $j++){
    $c += $d[$i]*$d[$j];
  }
}

echo $c;

?>

Measured memory_bytes: 4728
import math
import collections
from operator import mul
from functools import reduce
import bisect

#n,m=map(int,input().split())

n=int(input())
a=[1]
s=6
while s<=n:
    a.append(s)
    s*=6
s=9
while s<=n:
    a.append(s)
    s*=9
a=sorted(list(set(a)))


dp=[10000000000000]*(n+1)
dp[0]=0

for i in range(n):
    for ai in a:
        if i+ai<=n:
            dp[i+ai]=min(dp[i+ai],dp[i]+1)
       
print(dp[n])            









Measured memory_bytes: 41708
s = gets.chomp
rls = s.scan(/R+L+/)
ans = []
rls.each do |rl|
  r_size = rl.index("L")
  l_size = rl.size - r_size
  r_children = l_size / 2 + (r_size / 2.0).ceil
  l_children = r_size / 2 + (l_size / 2.0).ceil
  (r_size - 1).times { ans << 0 }
  ans << r_children
  ans << l_children
  (l_size - 1).times { ans << 0 }
end
puts ans.join(" ")


Measured memory_bytes: 8112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;cin >> a >> b >> c >> d;
    REP(i,c-a){
      cout << 'R';
    }
    REP(i,d-b){
      cout << 'U';
    }
    REP(i,c-a){
      cout << 'L';
    }
    REP(i,d-b){
      cout << 'D';
    }
    cout << 'D';
    REP(i,c-a+1){
      cout << 'R';
    }
    REP(i,d-b+1){
      cout << 'U';
    }
    cout << "LU";
    REP(i,c-a+1){
      cout << 'L';
    }
    REP(i,d-b+1){
      cout << 'D';
    }
    cout << 'R' << endl;
}

Measured memory_bytes: 3596
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     


def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

comb = [0 for _ in range(2*10**5 + 2)]
comb[0] = 1

for i in range(2*10**5+1):
    comb[i]

def NCMMod(n, a):
    cur = n
    for i in range(2, a+1):
        cur = cur * (n-i+1) // i
    return cur % mod


fac = [-1] * (10**7+1)
finv = [-1] * (10**7+1)
inv = [-1] * (10**7+1)

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

def initNCMMod(limit):
    for i in range(2, limit):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
initNCMMod(2*10**5 + 1)

def main():
    n, a, b = LI()
    comb[1] = n
    n_pow = power_func(2, n, mod)
    for i in range(2, 2*10**5+1):
        comb[i] = comb[i-1] * (n-i+1) * inv[i] % mod
    ans = n_pow - 1
    ans %= mod
    ans = ans - comb[a] - comb[b]
    ans %= mod
    print(ans)

main()



Measured memory_bytes: 286688
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<memory.h>
using namespace std;
typedef long long ll;
const int Max = 4e5 + 5;
const int Mod = 1e9 + 7;
int lst[Max];

int main()
{
	int n;
	cin >> n;
	for (int i = 2;i <= n;i++)
	{
		int a = i;
		for (int j = 2;j <= a;j++)
		{
			while (a % j == 0)
			{
				lst[j]++;
				a /= j;
			}
		}
		if (a != 1) lst[a]++;
	}
	ll res = 1;
	for (int i = 2;i <= n;i++)
	{
		res = (res * (1 + lst[i])) % Mod;
	}
	cout << res;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define MAX_V 100000
using namespace std;
int V,m,w[100001],S[100001];
vector<int> vv[100001];
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];
int C[100001],F[100001],U[100001],ans,UU[100001],UUU[100001];

void DFS(int p,int pr){
  if(S[p]++)return;
  for(int i=0;i<vv[p].size();i++){
    int np=vv[p][i];
    if(pr!=np){
      G[p].push_back(np);
      rG[np].push_back(p);
      DFS(np,p);
    }
  }
}

void dfs(int v){
  used[v]=true;
  for(int i=0;i<G[v].size();i++)if(!used[G[v][i]])dfs(G[v][i]);
  vs.push_back(v);
}

void rdfs(int v,int k){
  used[v]=true;
  cmp[v]=k;
  for(int i=0;i<rG[v].size();i++)if(!used[rG[v][i]])rdfs(rG[v][i],k);
}

int scc(){
  for(int v=0;v<V;v++)if(!used[v])dfs(v);
  memset(used,0,sizeof(used));
  int k=0;
  for(int i=vs.size()-1;i>=0;i--)if(!used[vs[i]])rdfs(vs[i],k++);
  return k;
}

bool DFS1(int p){
  if(U[p]++)return 0;
  bool f=F[cmp[p]]>=2;
  for(int i=0;i<G[p].size();i++)
    f|=DFS1(G[p][i]);
  ans+=w[p]*f;
  return UU[p]=f;
}

int DFS2(int p){
  if(UUU[p]++)return 0;
  int res=0;
  for(int i=0;i<G[p].size();i++)
    res=max(res,DFS2(G[p][i]));  
  return res+(UU[p]?0:w[p]);
}

int main(){
  cin>>V>>m;
  for(int i=0;i<V;i++)cin>>w[i];
  for(int j=0,a,b;j<m;j++){
    cin>>a>>b;a--,b--;
    vv[a].push_back(b),vv[b].push_back(a);
  }
  DFS(0,-1);
  int t=0;
  for(int i=0;i<V;i++)t+=w[i];
  scc();
  for(int i=0;i<V;i++)F[cmp[i]]++;
  DFS1(0);
  cout<<ans+DFS2(0)<<endl;
  return 0;
}

Measured memory_bytes: 28752
N = int(input())
A = list(map(int, input().split()))

s = [0] * (N+1)

for i in range(N):
    s[i+1] = s[i] + A[i]

s.sort()

count = 1
sum = 0
for i in range(N):
    if s[i] == s[i+1]:
        count += 1
    else:
        sum += count * (count - 1) // 2
        count = 1

sum += count * (count - 1) // 2
print(sum)


Measured memory_bytes: 25724
<?php
/*dskhbfjkhs*/
$server = "php://stdin";
$handle = fopen($server, "r");
$n = trim(fgets($handle));
$t = trim(fgets($handle));
$t=explode(' ',$t);
$str='';
for ($i=0;$i<$n;$i++)
{
    $str.=$t[0][$i].$t[1][$i];
}
echo $str."\n";


?>

Measured memory_bytes: 4856
package main

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

// Sorting three number
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	ary := strings.Split(strings.TrimSpace(sc.Text()), " ")
	sort.SliceStable(ary, func(i, j int) bool {
		v1, _ := strconv.Atoi(ary[i])
		v2, _ := strconv.Atoi(ary[j])
		return v1 < v2
	})
	fmt.Println(strings.Join(ary, " "))
}



Measured memory_bytes: 1096
N,M = map(int,input().split())

X = list(map(int,input().split()))

X.sort()

memo = []

for i in range(1,M):
    memo.append(X[i]-X[i-1])

memo.sort()
#print(memo)
ans = 0
for i in range(M-N):
    ans += memo[i]
print(ans)

Measured memory_bytes: 90704
#include<iostream>
#include<vector>
using namespace std;
using ll=long long;

int main(){
    int n;cin>>n;
    vector<ll> a(n+1);
    vector<ll> b(n);
    for(int i=0;i<n+1;++i)cin>>a[i];
    for(int i=0;i<n;++i)cin>>b[i];
    ll ans=0;
    for(int i=0;i<n;++i){
        if(a[i]>=b[i])ans+=b[i];
        else{
            ans+=a[i];
            b[i]-=a[i];
            if(a[i+1]>0){
                if(a[i+1]>=b[i]){
                    ans+=b[i];
                    a[i+1]-=b[i];
                }
                else{
                    ans+=a[i+1];
                    a[i+1]=0;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;

int r,c,k;
ll mat[3002][3002];
ll dp[3002][3002][5];

ll f(int x,int y,int count){
    if(x>r || y>c) return 0;
    if(dp[x][y][count]!=-1) return dp[x][y][count];
    if(count==3){
        return dp[x][y][count] = max(dp[x][y][count],max(f(x+1,y,0),f(x,y+1,count)));
    }
    else if(count<3){
        ll a = max(f(x+1,y,0),f(x,y+1,count));
        ll b = max(f(x+1,y,0)+mat[x][y],f(x,y+1,count+1)+mat[x][y]);
        return dp[x][y][count] = max(dp[x][y][count],max(a,b));
    }
    else if(count==4) return 0;
}

main(){
    cin>>r>>c>>k;
    memset(mat,0,sizeof(mat));
    memset(dp,-1,sizeof(dp));
    int x,y,v;
    while(k--){
        cin>>x>>y>>v;
        mat[x][y] = v;
    }
    ll res = f(1,1,0);
    cout<<res<<"\n";
}

Measured memory_bytes: 426564
#include<stdio.h>

int main(void)
{
   int n, i;
   double x[10];
   char u[10][4];
   double t=0;
 
   scanf("%d",&n);
   
   for(i=0;i<n;i++)
   {
       scanf("%lf %s",&x[i],u[i]);
   
       if(u[i][0]=='B'&&u[i][1]=='T'&&u[i][2]=='C')
       {
            x[i]=x[i]*380000;
       }   
       t+=x[i];
   }
   
   printf("%f\n",t);

   return 0;
}

Measured memory_bytes: 128
#C

n, k, q = map(int, input().split())
seikai=[0]*n
#seikai[i]はプレーヤーi+1の正解数
#print(seikai)
for i in range(q):
    ak = int(input())
    seikai[ak-1] += 1
#print(a)
#print(seikai)
for j in range(n):
    if seikai[j] > q-k:
        print("Yes")
    else:
        print("No")

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

void zero (int x1,int x2,int x3,int x4,int x5)
{
if(x1==0)
  cout<<"1";
  if(x2==0)
  cout<<"2";
 if(x3==0)
  cout<<"3";
  if(x4==0)
  cout<<"4";
  if(x5==0)
  cout<<"5";
   
}

int main()
{
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  zero(a,b,c,d,e);
  return 0;
}

Measured memory_bytes: 3592
import itertools
def myAnswer(N:int,S:list) -> int:
   ans = 0
   dic = {"M":0,"A":0,"R":0,"C":0,"H":0}
   for s in S:
      if(s[0] in dic.keys()):
         dic[s[0]] += 1
   for c in itertools.combinations(dic.values(),3):
      ans += c[0]*c[1]*c[2]
   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   S = [input() for _ in range(N)]
   print(myAnswer(N,S[:]))
if __name__ == '__main__':
   main()

Measured memory_bytes: 10540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(15);
vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	int a,b,t;
	cin >> a >> b >> t;
	cout << b*(t/a) << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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



signed main(void) {
    int n,k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
static bool mp[55][55],mp1[55][55];
bool is_cmp()
{
	for(int i=1;i<=n-m+1;i++)
		for(int j=1;j<=n-m+1;j++)//mp[i][j]
		{
			int flag=1;
			for(int h=1;h<=m;h++)
				for(int k=1;k<=m;k++)
				if(mp[i+h-1][j+k-1]!=mp1[h][k]) flag=0;
			if(flag) return true;
		}
	return false ;
}
int main()
{
	scanf("%d%d",&n,&m);
	getchar();
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			char c;
			scanf("%c",&c);
			if(c=='#') mp[i][j]=1;
		}
		getchar();
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=m;j++)
		{
			char c;
			scanf("%c",&c);
			if(c=='#') mp1[i][j]=1;
		}
		getchar();
	}
	if(is_cmp()) printf("Yes");
	else printf("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }
typedef pair<int,int> P;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};
//UnionFind Uni(N);
//Uni.connect;

struct Edge
{
  int from, to, cost;

  // コストの大小で順序定義
  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
  int n;  // 頂点数
  vector<Edge> es;  // 辺集合

  // クラスカル法で無向最小全域木のコストの和を計算する
  // グラフが非連結のときは最小全域森のコストの和となる
  int kruskal() {
    // コストが小さい順にソート
    sort(es.begin(), es.end());

    UnionFind uf(n);
    int min_cost = 0;

    rep(ei, es.size()) {
      Edge& e = es[ei];
      if (!uf.same(e.from, e.to)) {
        // 辺を追加しても閉路ができないなら、その辺を採用する
        min_cost += e.cost;
        uf.connect(e.from, e.to);
      }
    }

    return min_cost;
  }
};

// 標準入力からグラフを読み込む
Graph input_graph() {
  Graph g;
  int m;
  cin >> g.n >> m;
  rep(i, m) {
    Edge e;
    cin >> e.from >> e.to >> e.cost;
    g.es.push_back(e);
  }
  return g;
}


int main(){
  int n;
  cin >> n;
  // Graph g = input_graph();
  vector<P> xp;
  vector<P> yp;
  rep(i,n){
    int x,y;
    cin >> x >> y;
    xp.push_back(make_pair(x,i));
    yp.push_back(make_pair(y,i));
  }
  sort(xp.begin(),xp.end());
  sort(yp.begin(),yp.end());
	Graph g;
	g.n=n;
	rep(i,n-1){
		Edge e;
		e.from = xp[i].second;
		e.to = xp[i+1].second;
		e.cost = xp[i+1].first - xp[i].first;
		g.es.push_back(e);
	}
	rep(i,n-1){
		Edge e;
		e.from = yp[i].second;
		e.to = yp[i+1].second;
		e.cost = yp[i+1].first - yp[i].first;
		g.es.push_back(e);
	}
  cout << g.kruskal() << endl;
  return 0;
}


Measured memory_bytes: 7144
fun main(args: Array<String>) {
    val (W, H, N) = readLine()!!.split(" ").map(String::toInt)
    val A = Array(N) { readLine()!!.split(" ").map(String::toInt) }

    var x1 = 0
    var x2 = W
    var y1 = 0
    var y2 = H

    A.forEach { n ->
        val (x, y, a) = n
        when (a) {
            1 -> x1 = Math.max(x1, x)
            2 -> x2 = Math.min(x2, x)
            3 -> y1 = Math.max(y1, y)
            else -> y2 = Math.min(y2, y)
        }
    }
    if (x1 > x2) {
        println(0)
        return
    }
    if (y1 > y2) {
        println(0)
        return
    }

    println((W - x1 - (W - x2)) * (H - y1 - (H - y2)))
}



Measured memory_bytes: 36140
l, r = map(int, input().split())

if (r-1) * r < 2019:
    print(l * (l+1))
elif r - l > 2019:
    print(0)
else:
    ans = 2019
    for i in range(l, r):
        for k in range(i+1, r+1):
            a = ((i % 2019) * (k % 2019)) % 2019
            if a < ans:
                ans = a
    print(ans)


Measured memory_bytes: 40684
n = int(raw_input())
C = {'S':range(13), 'H':range(13), 'C':range(13), 'D':range(13)}

for i in range(n):
    suit, num = raw_input().split()
    num = int(num)
    C[suit][num-1] = 14

for i in ['S', 'H', 'C', 'D']:
    for j in range(13):
        if C[i][j] != 14:
            print "%s %d" %(i, j+1)

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int n;
vector<int> color;
vector<vector<pii>> G;

bool dfs(int v, int c, int p) {
    color[v] = c;
    bool flag = true;
    for (int i = 0; i < G[v].size(); ++i) {
        if(G[v][i].first == p) continue;
        pii nv = G[v][i];
        if(nv.second % 2 == 0){
            if(color[nv.first] >= 0 && color[nv.first] != c){
                flag = false;
                break;
            }
            if(dfs(nv.first, c, v)) flag = true;
        }
        else{
            if(dfs(nv.first, (c+1)%2, v)) flag = true;
        }
    }
    if(flag){
        return true;
    }
    else{
        color[v] = -1;
        return false;
    }
}

int main() {
    cin >> n;
    color.assign(n, -1);
    G.assign(n, vector<pii>());
    int u, v, w;
    for (int i = 0; i < n - 1; ++i) {
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back(pii(v, w));
        G[v].push_back(pii(u, w));
    }
    dfs(0, 0, -1);
    for (int i = 0; i < n; ++i) {
        cout << color[i] << endl;
    }
}

Measured memory_bytes: 9728
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
N = inp.shift() * 1
S = 100/4
T = 100/7
cnt = 0
for (i=0; i<=S; i++) {
  for (j=0; j<=T; j++) {
      if (i*4 + j*7 == N) {
          cnt++
          break;
      }
  }
}
console.log(cnt ? 'Yes' : 'No')

Measured memory_bytes: 21064