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

int main() {
  int n, k, o = 0, c = 0;
  cin >> n >> k;
  vector<int> a(n), num(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
    num.at(a.at(i) - 1)++;
  }
  sort(num.begin(), num.end());
  sort(a.begin(), a.end());
  int r = unique(a.begin(), a.end()) - a.begin() - k;
  if(r > 0) {
    for(int i = 0; i < n; i++) {
      if(num.at(i)) {
        o += num.at(i);
        c++;
        if(c == r)
          break;
      }
    }
  }
  cout << o << endl;
}

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

const ll M = 1000000007;

vector<ll> fac(2000005);
vector<ll> ifac(2000005);
//べき乗高速化
ll mpow(ll x, ll n){
	ll ans = 1;
	while(n != 0){
		if (n&1) ans = ans * x % M;
		x = x*x % M;
		n  = n >> 1;
	}
	return ans;
}

//aCbを計算
ll comb(ll a, ll b){
	if (a == 0 && b == 0) return 1;
	if (a < b || a < 0){
		return 0;
	}
	ll temp = ifac[a-b] * ifac[b] % M;
	return temp * fac[a] % M;
}

int main(){
	ll X,Y;
	cin >> X >> Y;
	fac[0] = 1;
	ifac[0] = 1;
	for(ll i = 0; i<= 2000000; i++){
		fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
		ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
	
	if((X+Y)%3!=0){
		cout << 0 << endl;
	}else{
		//何回移動するか
		ll temp = (X+Y)/3;
		if(X-temp<0){
			cout << 0 << endl;
		}else{
			cout << comb(temp,X-temp) << endl;
		}
	}
    return 0;
}



Measured memory_bytes: 31488
#include <stdio.h>

int main(void) {
	int x,y;

	while(1){
		scanf("%d %d", &x, &y);
		
		if(x==0 && y==0) break;
		if(x>y){int tmp=x; x=y; y=tmp;}
		
		printf("%d %d\n", x, y);
		
	}
		
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;

//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const LL INF=LONG_MAX;
const double EPS=0.00001;
const long double PI = acos(-1.0);

const int MAX_N=2e5+2;

int main(){
    LL N,M,K;
    cin>>N>>M>>K;
    if(K==0||K==N*M){
        cout<<"Yes"<<endl;
        return 0;
    }
    for(LL i=0;i<=N;i++)for(LL j=0;j<=M;j++){
        LL tmp=i*M+j*(N-i);
        tmp-=i*j;
        if(tmp==K){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


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

#if DEBUG && !ONLINE_JUDGE
    #include "/home/tushar_garg/Desktop/cpp/debug.h"
#else
    #define dbg(x...)
#endif

typedef     long long                            ll; 
typedef     pair<ll, ll>                         pl; 
typedef     vector<ll>                           vl;
typedef     vector<char>                         vc;
typedef     vector<bool>                         vb; 
typedef     vector<vl>                           vvl; 
typedef     vector<pl>                           vll; 
typedef     map<ll, ll>                          dict; 
typedef     map<ll, ll, greater <ll> >           sdict; 
typedef     map<char, ll>                        mcl;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pl>                   pqii;
typedef     priority_queue<ll, vl, greater<ll>>  pqmini;

#define rep(i, a, n) for (auto i=a-(a>n); i!=n-(a>n); i+=1-2*(a>n))
#define trav(i, a) for(auto &i:a)
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back
#define eb emplace_bac
#define flash ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define QuickSilver cin.exceptions(cin.failbit),setprecision(12),cout.precision(12)
#define get(a) rep(i,0,sz(a))cin>>a[i];
#define sz(a) (ll)(a.size())
#define all(a) a.begin(), a.end()
#define mod 1000000007

int main(){
	flash; QuickSilver;
	int a, b; cin>>a>>b;
  if(a==b) cout<<"Yes\n";
  else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define VALMAX 100
int getMax(int hist[], int maxArr[]){
	int i;
	int max;
	int counter = 0;
	for(i = 0; i < VALMAX; i++){
		if(hist[i] > max){max = hist[i];}
	}
	for(i = 0; i < VALMAX; i++){
		if(hist[i] == max){
			maxArr[counter] = i;
			counter++;
		}
	}
	return counter;
}
int main(void){
	int i,n;
	int hist[VALMAX];
	int maxArr[VALMAX];
	int maxNum;
	for(i = 0; i < VALMAX; i++){
		hist[i] = 0;
	}
	while(1){
		if(scanf("%d",&n) == EOF){break;}
		hist[n]++;
	}
	maxNum = getMax(hist,maxArr);
	for(i = 0; i < maxNum; i++){
		printf("%d\n",maxArr[i]);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>

using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    for (long i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3924
N, M = map(int,input().split())
def read(List,N):
  for _ in range(N):
    x, y = input().split()
    x,y = int(x),int(y)
    List.append((x,y))
  return List
students = []
points = []
students = read(students,N)
points = read(points,M)

def distance(A,B):
  distance = abs(A[0] - B[0]) + abs(A[1] - B[1])
  return distance

Answer_list = []
for i in range(N):
  answer = -1
  tempdistance = 10**17
  #tempdistance = 100
  for j in range(M):
    candidate = distance(students[i],points[j])
    if candidate < tempdistance:
      answer = j
      tempdistance = candidate
  Answer_list.append(answer)
for item in Answer_list:
  print(item+1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<double> VD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1 << 17;
int n;
int a[N];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);
	
	cin >> n;
	FOR(i, 0, n)
		cin >> a[i];
	
	sort(a, a + n);
	if (n % 3)
	{
		if (a[n - 1] == 0)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
		return 0;
	}
	
	bool ok = 1;
	n /= 3;
	FOR(j, 0, 3)
		FOR(i, 0, n)
			ok &= a[j * n + i] == a[j * n];
	
	if (ok && ((a[0] ^ a[n] ^ a[2 * n]) == 0))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


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

int main() 
{

  int N,M;
  cin>>N>>M;
  
  vector<int> AC(N,0);
  vector<int> WA(N,0);
  int penalty=0;
  int correct=0;
  for(int i=0;i<M;i++){
    int Pi;
    string Si;
    cin>>Pi>>Si;
    
    if(Si=="AC"&&AC.at(Pi-1)==0){
	  AC.at(Pi-1)=1;
      correct++;
      penalty+=WA.at(Pi-1);
    }
    else if(Si=="WA"&&AC.at(Pi-1)==0)
      WA.at(Pi-1)++;
  }
  
  cout<<correct<<" "<<penalty<<endl;
  
    return 0;
}

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

int main(){
  int N; cin >> N;
  vector<int> H(N+1);
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  H[N]=H[N-1]+1;
  int ans=0;
  int count=0;
  for(int i=1;i<=N;i++){
    if(H[i]<=H[i-1]){
      count++;
    }
    else{
      ans=max(ans,count);
      count=0;
    }
  }
  cout << ans << endl;
}

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

int main(){
	int num;
	scanf("%d",&num);
	int resp=0;

	while(num){
		resp = resp +num%10;
		num = num/10;
	}
	if(resp==1){
		printf("10\n");
	}else{
		printf("%d\n",resp);
	}
	

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var s string
	fmt.Scanf("%s", &s)

	list := strings.Split(s, "")
	fmt.Println(countPair(list))
}

func countPair(list []string) int {
	var rc, wc int
	for _, v := range list {
		if v == "W" {
			wc++
		}
		if v == "R" {
			rc++
		}
	}

	var ret int
	var l_rc, r_wc int
	r_wc = 0
	l_rc = rc
	ret = max(rc, wc)
	//fmt.Println(ret)
	for _, v := range list {
		tmp := max(r_wc, l_rc)
		if ret > tmp {
			ret = tmp
		}
		if v == "W" {
			r_wc++
		}
		if v == "R" {
			l_rc--
		}
	}
	tmp := max(r_wc, l_rc)
	if ret > tmp {
		ret = tmp
	}
	return ret
}

func max(a int, b int) int {
	return int(math.Max(float64(a), float64(b)))
}


Measured memory_bytes: 6560
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;

ll a[6];

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll ans;
    FOR(i,5){
        sfl(a[i]);
        if(a[i]==0){
            ans = i;
        }
    }
    pfl(ans);
    return 0;
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define Cin(x) cin >> x
#define Cin2(x,y) cin >> x >> y
#define Cin3(x,y,z) cin >> x >> y >> z
#define Cin4(w,x,y,z) cin >> w >> x >> y >> z
#define Cout(x) cout << x << "\n"
#define Cout2(x,y) cout << x << y << "\n"
#define Cout3(x,y,z) cout << x << y << z << "\n"
#define Cout4(w,x,y,z) cout << w << x << y << z << "\n"
#define Kaigyou cout << "\n"
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define Size(n) (n).size()
#define All(v) (v).begin(), (v).end()
#define Pb(i) push_back(i)

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

    ll a,b,c,x,y,ans;
    cin >> a >> b >> c >> x >> y;
    if(a+b <= 2*c) ans = a*x+b*y;
    else{
        ans = 2 * c * min(x,y);
        if(x > y) ans += min(a*abs(x-y), c*2*abs(x-y));
        else ans += min(b*abs(x-y), c*2*abs(x-y));
    }
    Cout(ans);
    return 0;
}

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

ll t1,t2,a1,a2,b1,b2;

int main(){
  ll ans=0;
  cin >> t1>>t2>>a1>>a2>>b1>>b2;
  


  if ((t1*a1+t2*a2)==(t1*b1+t2*b2)){
    cout<<"infinity"<<endl;
    return 0; 
  }

  if (a1==b1){
      cout<<"infinity"<<endl;
      return 0; 
  }

  if (t1*a1>t1*b1){
    if (t2*a2>=t2*b2){
        cout<<"0"<<endl;
        return 0; 
    }
    
    if ((t1*a1+t2*a2)>(t1*b1+t2*b2)){
        cout<<"0"<<endl;
        return 0; 
    }
  }

  if (t1*a1<t1*b1){
    if (t2*a2<=t2*b2){
        cout<<"0"<<endl;
        return 0; 
    }
    if ((t1*a1+t2*a2)<(t1*b1+t2*b2)){
        cout<<"0"<<endl;
        return 0; 
    }
  }




  ll A,B;
  A=abs((a1-b1)*t1);
  B=abs((a2-b2)*t2);
  if (A<B){
    ll tmp=B;
    B=A;
    A=tmp;
  }

  ll C=B/(A-B);
  ans=C*2LL;
  if ((B%(A-B))!=0LL){
    ans++;
  }




  cout<<ans<<endl;
  return 0;
}







Measured memory_bytes: 256
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,a,b;
  cin >> n >> a >> b;

  cout << (n*a<b ? n*a : b) << endl;
  return 0;
}


Measured memory_bytes: 256
'use strict'
const lines = require('fs').readFileSync(0, 'utf8').split('\n')
const firstLine = lines[0].split(' ').map(Number)
const N = firstLine[0]
const W = firstLine[1]
var dp = new Array(N + 1);
for(var i = 0; i < N + 1; i++){
  dp[i] = new Array(W + 1).fill(0);
}

for (let i=0;i < N;i++) {
  const tmp = lines[i+1].split(' ').map(Number)
  const value = tmp[1];
  const weight = tmp[0];
  for (let w=0; w<=W; w++) {
    if (w - weight >= 0) {
      dp[i+1][w] = Math.max(dp[i+1][w], dp[i][w-weight] + value)
    }
    dp[i+1][w] = Math.max(dp[i+1][w], dp[i][w])
  }
}
console.log(dp[N][W])

Measured memory_bytes: 188544
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,w;
  cin>>n>>w;
  int a[n],b[n];
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  int dp[n+1][w+1];
  memset(dp,0,sizeof dp);
  for(int i=0;i<n;i++){
    for(int j=0;j<=w;j++){
      if(j<b[i]) dp[i+1][j]=dp[i][j];
      else dp[i+1][j]=max(dp[i][j],dp[i][j-b[i]]+a[i]);
    }
  }
  cout<<dp[n][w]<<endl;
}


Measured memory_bytes: 7012
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstring>
#include<climits>
#include<queue>
using namespace std;
#define MAXN 100000
int A,ans;
int main()
{
    scanf("%d",&A);
    int ans=A;
    for(int i=0;i<=A;i++)
    {
        int cont=0;
        int t=i;
        while(t>0)cont+=t%6,t/=6;
        t=A-i;
        while(t>0)cont+=t%9,t/=9;
        ans=min(ans,cont);
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
bool sqr(int x)
{
	int lo=1, hi = 1000, mid;
	while(lo<=hi){
		mid = (lo+hi)/2;
		if((mid*mid)==x) return true;
		else if((mid*mid)>x) hi = mid - 1;
		else lo = mid + 1;
	}
	return false;
}
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string a, b;
	cin >> a >> b;
	//string A = to_string(a);
	//string B = to_string(b);
	//cout << A << " " << B << endl;
	string c = a + b;
	//cout << c << endl;
	int x = stoi(c);
	//cout << x << endl;
	if(sqr(x)) cout << "Yes\n";
	else cout << "No\n";
	
	return 0;
}


Measured memory_bytes: 3660
n, k = gets.split.map(&:to_i)
d = gets.chomp.split

nums = %w(0 1 2 3 4 5 6 7 8 9) - d
c = n.to_s.size

ans = 10 ** 7

2.times do |i|
  nums.repeated_permutation(c + i) do |x|
    a = x.join.to_i
    if a >= n
      ans = [ans, a].min
    end
  end
end
puts ans


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,mina,minb,maxa,maxb;
int main(){
	cin>>n>>m>>x>>y;
	mina=1000;
	minb=1000;
	maxa=-1000;
	maxb=-1000;
	for(int i=0,a;i<n;i++)
		cin>>a,maxb=max(maxb,a),minb=min(minb,a);
	for(int i=0,a;i<m;i++)
		cin>>a,maxa=max(maxa,a),mina=min(mina,a);
	if(mina<=maxb || (mina<=x && maxb<=x) || (mina>y && maxb>=y))	
		cout<<"War";
	else
		cout<<"No War";
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vector<int> X(N);
	for (auto& x : X) cin >> x;

	int ans = int(1e9);
	for (int p = 1; p <= 100; p++) {
		int cnd = 0;
		for (auto x : X) {
			cnd += (x-p) * (x-p);
		}
		ans = min(ans, cnd);
	}
	cout << ans << '\n';

	return 0;
}


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

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

using lint = long long;
constexpr lint INF = 1LL << 50;

void solve() {
    int n, m;
    std::cin >> n >> m;

    Edges<lint> edges(m);
    Graph<lint> graph(n);
    for (auto& e : edges) {
        std::cin >> e.src >> e.dst >> e.cost;
        --e.src, --e.dst;

        graph[e.src].emplace_back(e.src, e.dst, e.cost);
        graph[e.dst].emplace_back(e.dst, e.src, e.cost);
    }

    // BFSで割り当てをする関数
    std::vector<lint> vs(n);
    std::vector<int> cs(n);
    auto paint = [&](lint w) {
        std::fill(cs.begin(), cs.end(), -1);
        vs[0] = w;
        cs[0] = 0;

        std::queue<int> que;
        que.push(0);

        while (!que.empty()) {
            int v = que.front();
            que.pop();

            for (auto e : graph[v]) {
                int u = e.dst;
                if (cs[u] != -1) continue;

                cs[u] = 1 - cs[v];
                vs[u] = e.cost - vs[v];
                que.push(u);
            }
        }
    };

    paint(0);
    bool bip = true, ok = true;
    for (auto e : edges) {
        if (cs[e.src] == cs[e.dst]) bip = false;
        if (vs[e.src] + vs[e.dst] != e.cost) ok = false;
    }

    if (bip) {
        // 各色の最小値を求める
        lint lmin = INF, rmin = INF;
        for (int v = 0; v < n; ++v) {
            if (cs[v] == 0) {
                lmin = std::min(lmin, vs[v]);
            } else {
                rmin = std::min(rmin, vs[v]);
            }
        }

        std::cout << (ok ? std::max(lmin + rmin - 1, 0LL) : 0) << std::endl;
    } else {
        // c(0)の候補を探す
        lint w = 0;
        for (auto e : edges) {
            if (cs[e.src] == cs[e.dst]) {
                w = std::abs(vs[e.src] + vs[e.dst] - e.cost);
                break;
            }
        }

        // 再度割り当てて判定
        paint(w / 2);
        ok = true;
        for (int v = 0; v < n; ++v) {
            if (vs[v] <= 0) ok = false;
        }
        for (auto e : edges) {
            if (vs[e.src] + vs[e.dst] != e.cost) ok = false;
        }

        std::cout << ok << std::endl;
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 10880
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int n,m,k,q;
vector<int> matsuri,dist;
vector<pint> v[101010];
void bfs(){
    priority_queue<pint,vector<pint>,greater<pint>> que;
    dist.resize(n,inf);
    for(auto e:matsuri){
        dist[e]=0;
        que.push({0,e});
    }
    while(que.size()){
        int d=que.top().first,x=que.top().second;
        que.pop();
        if(dist[x]<d)continue;
        for(auto to:v[x]){
            if(dist[to.second]>dist[x]+to.first){
                dist[to.second]=dist[x]+to.first;
                que.push({dist[to.second],to.second});
            }
        }
    }
}
struct ppUF{
   vector<int> par,ti;
   vector<vector<pint>> his;
   ppUF(int n):ti(n,inf+1),par(n,-1),his(n){
       for(auto &vs:his)vs.emplace_back(-1,-1);
   }
   int find(int t,int x){
       if(ti[x]>t)return x;
       return find(t,par[x]);
   }

   bool unite(int t,int x,int y){
       x=find(t,x);y=find(t,y);
       if(x==y)return false;
       if(par[x]>par[y])swap(x,y);
       par[x]+=par[y];
       his[x].emplace_back(t,par[x]);
       par[y]=x;
       ti[y]=t;
       return true;
   }

   bool same(int t,int x,int y){
       return find(t,x)==find(t,y);
   }
   int time(int x,int y){
       if(!same(inf,x,y))return -1;
       int ok=inf,ng=-1,mid=0;
       while(ok-ng>1){
           mid=(ok+ng)/2;
           if(same(mid,x,y))ok=mid;
           else ng=mid;
       }
       return ok;
   }

   int size(int t,int x){
       x = find(t,x);
       return -prev(lower_bound(his[x].begin(),his[x].end(),pint(t,0)))->second;
   }
};



int main(){
    cin>>n>>m>>k>>q;
    vector<pint> edge;
    rep(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        --x;--y;
        v[x].push_back({z,y});
        v[y].push_back({z,x});
        edge.push_back({x,y});
    }
    rep(i,k){
        int x;cin>>x;
        matsuri.push_back(x-1);
    }
    bfs();
    ppUF uf(n);
    for(auto& e:edge)if(dist[e.first]>dist[e.second])swap(e.first,e.second);
    sort(edge.begin(),edge.end(),[&](pint x,pint y){return dist[x.first]>dist[y.first];});
    vector<int> ans;
    rep(i,m){
        uf.unite(i, edge[i].first, edge[i].second);
        ans.push_back(dist[edge[i].first]);
    }
    rep(i,q){
        int x,y;
        cin>>x>>y;
        --x;--y;
        int ok=m,ng=-1,mid=0;
       while(ok-ng>1){
           mid=(ok+ng)/2;
           if(uf.same(mid,x,y))ok=mid;
           else ng=mid;
       }
       cout<<ans[ok]<<endl;
    }
    return 0;
}



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

int main(){
  long unsigned int K;
  cin >> K;
  string S;
  cin >> S;
  /*
  int U = S.length();
  cout << U << endl;
  */
  
  if(K>=S.length()){
    cout << S << endl;
  }else{
    for(int i=0;i<K;i++){
      cout << S.at(i);
    }
    cout << "...";
  }
  
  cout << endl;
  
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
int main()
{ 
    int n;
    cin>>n;
    long long int ans;
    long long int d[n];
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    if(d[0]!=0){
        cout<<0<<endl;
        return 0;
    }
    sort(d,d+n);
    int l[n];//根からn(n-1まで)の距離の頂点の個数
    int k=0;//到達している距離
    for(int i=0;i<n;i++){
        l[i]=0;
    }
    if(n==1){
        if(d[0]==0){
            cout<<1<<endl;
        }
        else{
            cout<<0<<endl;
        }
        return 0;
    }

    //実行
    if(d[0]!=0||d[1]!=1){
        cout<<0<<endl;
        return 0;
    }
    k=1;
    l[0]=1;
    l[1]=1;
    ans=1;
    for(int i=2;i<n;i++){
        if(d[i]==k+1){
            k++;
        }
        if(d[i]>k){
            cout<<0<<endl;
            return 0;
        }
        l[d[i]]++;
        ans=ans*l[d[i]-1];
        if(ans>998244352){
            ans=ans%998244353;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, k;
vector<i64> l;
int main() {
  cin >> n >> k;
  read_n(l, n);
  sort(begin(l), end(l));
  i64 ans = 0;
  while (k--) {
    ans += l.back();
    l.pop_back();
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define pii pair < int, int >
typedef vector<int> vi;
typedef   long long ll;
const int mod =1e9+7;




void solve(){
	int a;
	cin>>a;
	cout<<a*a*3;
}

int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

const int MX = 100005;

int main()
{
    int n;
    cin >> n;
    vector<ll> cnt(MX);
    rep(i,n){
        int a;
        cin >> a;
        cnt[a]++;
    }
    ll tot = 0;
    rep(i,MX) tot += i*cnt[i];

    int q;
    cin >> q;
    rep(i,q){
        int b, c;
        cin >> b >> c;
        tot += (c-b)*cnt[b];
        cnt[c] += cnt[b]; cnt[b]=0;
        cout << tot << endl;
    }
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	if (n < 2) {
		cout << 1 << endl;
	} else {
		int f[n+1];
		f[0] = f[1] = 1;
		for(int i=2;i<=n;i++){
			f[i]=f[i-1]+f[i-2];
		}
		cout << f[n] << endl;
	}
	return 0;
}



Measured memory_bytes: 3124
/*     !ya khoda!     */
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define ld long double

#define pp push
#define po pop()
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
#define I insert
#define E erase

#define F first
#define S second

#define mkp make_pair
#define pll pair<ll,ll>
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define all(a) a.begin(),a.end()

#define coutghat(x)      cout<<tolower(x);
#define coutashar(x,d)   cout<<fixed<<setprecision(x)<<(ld)d
#define IOS ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)
//#define poow(a,b,M)   b?(poow((a*a)%M,b/2)%M * (b&1?a))%M:1 ;
/*==========================================================================*/
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll poow(ll x,ll n,ll Mod=1e9+7) { return (n==0?1:poow(x*x%Mod,n/2)*(n&1?x:1)%Mod); }
//#pragma optimize O3
// 107,109, 211,223, 307, 401,409, 503,509, 601,607, 701,709, 809, 907, 1009
/*==========================================================================*/
const int N=1e5+100 , M=1e6+10  , SQ=550 , LG=21 , base=2;
const int mod=1e9+7 , MOD=1e9+9;
const ll  INF=1e9   , inf=1e18 , super_inf=~0ull/4;
ll t , a,b,c,d , g;
/*==========================================================================*/
int main()
{
	IOS;
	cin>>t;
	while(t--)
    {
        cin>>a>>b>>c>>d;
        if(a<b || d<b)
        {
            cout<<"No\n";
            continue;
        }

        g=__gcd(b,d);
        if(   ((a%b)+g*((b-(a%b))/g)==b ? (a%b)+g*((b-(a%b))/g)-g : (a%b)+g*((b-(a%b))/g))>c   )   cout<<"No\n";
        else                                                                                       cout<<"Yes\n";
    }
    return 0;
}


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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

int main(){
    int n; cin >> n;
    ll a = 0;
    for(int i = 1; i <= n; i++){
        if(!(i % 3 == 0 || i % 5 == 0)){
            a += i;
        }
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>

class disjoint_set {
private:
    std::vector<size_t> parents;
    std::vector<size_t> ranks;
    std::vector<size_t> component_sizes;
public:
    const size_t n_vertices;
    size_t n_components;

    disjoint_set(size_t n_vertices) : n_vertices(n_vertices), parents(n_vertices), ranks(n_vertices, 0), n_components(n_vertices), component_sizes(n_vertices, 1) {
        for (size_t i = 0; i < n_vertices; ++i) {
            parents[i] = i;
        }
    }

    size_t root(size_t x) {
        if (parents[x] == x) {
            return x;
        } else {
            return parents[x] = root(parents[x]);
        }
    }

    void merge(size_t x, size_t y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (ranks[x] < ranks[y]) {
            parents[x] = y;
            component_sizes[y] += component_sizes[x];
        } else {
            parents[y] = x;
            component_sizes[x] += component_sizes[y];
            if (ranks[x] == ranks[y]) {
                ++ranks[x];
            }
        }
        --n_components;
    }

    bool is_same(size_t x, size_t y) {
        return root(x) == root(y);
    }

    size_t component_size(size_t x) {
        return component_sizes[root(x)];
    }
};

int main() {

    using namespace std;

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, q;
    cin >> n >> q;
    disjoint_set ds(n);
    for (int i = 0; i < q; ++i) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            ds.merge(x, y);
        } else { // if (com == 1) {
            cout << ds.is_same(x, y) << '\n';
        }
    }
    cout << flush;

    return 0;
}


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

#define F first
#define S second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define in(x) insert(x)
#define forr(i, a, b) for(int i = a;i <= b;i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define did_you_calis_enough ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define int long long

using namespace std;

const int INF =  4294967295;
const int  N = 2e6 + 667;
const int mod = 1e9 + 7;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double PI = acos(-1.0);


main() {
	did_you_calis_enough
	char n;cin >> n;
	cout << (((int)(n) > (int)('Z')) ? 'a' : 'A');
}

//Coded by LoliThief

Measured memory_bytes: 3648
#include <stdio.h>
int main(void){
    int n,m,t,i,j;
    scanf("%d %d\n",&n,&m);
    int a[n][m],b[m],ans[n];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i=0;i<m;i++){
        scanf("%d",&b[i]);
    }
    for(i=0;i<n;i++){
        t=0;
        for(j=0;j<m;j++){
            t+=(a[i][j]*b[j]);
        }
        ans[i]=t;
    }
    for(i=0;i<n;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 2144
#include <stdio.h>

int bitcount(unsigned int n) {
	n=((n & 0xAAAAAAAA)>>1)+(n & 0x55555555);
	n=((n & 0xCCCCCCCC)>>2)+(n & 0x33333333);
	n=((n & 0xF0F0F0F0)>>4)+(n & 0x0F0F0F0F);
	n=((n & 0xFF00FF00)>>8)+(n & 0x00FF00FF);
	n=((n & 0xFFFF0000)>>16)+(n & 0x0000FFFF);
	return n;
}

long long gcd(long long a,long long b) {
	return b==0?a:gcd(b,a%b);
}

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

int main(void) {
	long long n;
	int m;
	while(scanf("%lld%d",&n,&m)==2 && (n!=0 || m!=0)) {
		long long p[20];
		long long sum=n*(n+1)/2;
		long long num=n;
		int imax=1<<m;
		int i;
		for(i=0;i<m;i++)scanf("%lld",&p[i]);
		for(i=1;i<imax;i++) {
			int bit=bitcount(i);
			long long muri=1;
			int k;
			for(k=0;k<m;k++) {
				if(i&(1<<k)) {
					muri=lcm(muri,p[k]);
					if(muri>n)break;
				}
			}
			if(bit%2==0) {
				num+=n/muri;
				sum+=(muri+(muri+muri*(n/muri-1)))*(n/muri)/2;
			} else {
				num-=n/muri;
				sum-=(muri+(muri+muri*(n/muri-1)))*(n/muri)/2;
			}
		}
		printf("%.15f\n",num==0?0:(double)sum/num);
	}
	return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <vector>

using namespace std;


int main(int argc, char *argv[]) {
	int N, A;
	cin >> N >> A;
	vector<int> x(N+1);

	for (int i = 1; i <= N; i++) cin >> x[i];

	long dp[51][51][2501] = {};

	for (int j = 0; j <= N; j++)
		dp[j][0][0] = 1;

	for (int s = 0; s <= N * 50; s++) {
		for (int k = 1; k <= N; k++) {
			for (int j = 1; j <= N; j++) {
				if (x[j] > s)
					dp[j][k][s] = dp[j-1][k][s];
				else
					dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j]];
			}
		}
	}

	long ans = 0;
	for (int k = 1; k <= N; k++)
		ans += dp[N][k][k * A];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 51072
class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        else:
            if self.size(x) < self.size(y):
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        x = self.find(x)
        return -self.parent[x]

    def is_root(self, x):
        return self.parent[x] < 0


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

friends = [[] for _ in range(n)]
blocks = [[] for _ in range(n)]
UF = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    friends[a].append(b)
    friends[b].append(a)
    UF.unite(a, b)

for j in range(k):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    blocks[a].append(b)
    blocks[b].append(a)

for i in range(n):
    num = UF.size(i) - 1
    for j in blocks[i]:
        if UF.same(i, j):
            num -= 1
    num -= len(friends[i])
    print(num, end=' ')


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

const int N = 100;
int dp[N+1][N+1][2];

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

    int k,x;
    cin>>k>>x;

    if(k*500>=x) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((c>=a)&&(c<=b))
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
    return 0;
}


Measured memory_bytes: 256
void main()
{
    long[] tmp = readln.split.to!(long[]);
    long a = tmp[0], b = tmp[1];

    if (a == 0 || b == 0)
    {
        if (a < b) writeln(abs(b.abs-a.abs));
        else writeln(abs(b.abs-a.abs) + 1);
    }
    else if (a / a.abs == b / b.abs)
    {
        if (a <= b) writeln(b - a);
        else writeln(a - b + 2);
    }
    else
    {
        writeln(abs(b.abs-a.abs) + 1);
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

const string YES = "Yes";
const string NO = "No";

void solve(long long K, long long X){
  string ans;
  (500*K>=X)?ans=YES:ans=NO;
  cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
      cout << fixed << setprecision(6);
    long long K;
    scanf("%lld",&K);
    long long X;
    scanf("%lld",&X);
    solve(K, X);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	map<string, int> mp;
	rep(i,N){
		string S;
		cin >> S;
		mp[S]++;
	}
	cout << "AC x " << mp["AC"] << endl;
	cout << "WA x " << mp["WA"] << endl;
	cout << "TLE x " << mp["TLE"] << endl;
	cout << "RE x " << mp["RE"] << endl;
}

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

public class Main{
	static int[][] pollock = new int[2][1000000];

	static void Conjecture(){
		int n = 1;
		Arrays.fill(pollock[0], 1000000);
		Arrays.fill(pollock[1], 1000000);

		while(n*(n+1)*(n+2)<1000000*6){
			pollock[0][n*(n+1)*(n+2)/6] = 1;
			if((n*(n+1)*(n+2)/6)%2==1){
				pollock[1][n*(n+1)*(n+2)/6] = 1;
			}
			n++;
		}

		n = 1;
		for(int i=2; i<1000000; i++){
			if(pollock[0][i]==1) n++;

			for(int j=1; j<=n; j++){
				pollock[0][i] = Math.min(pollock[0][i], pollock[0][i-j*(j+1)*(j+2)/6]+1);
				if((j*(j+1)*(j+2)/6)%2==1){
					pollock[1][i] = Math.min(pollock[1][i], pollock[1][i-j*(j+1)*(j+2)/6]+1);
				}
			}
		}
	}

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

		while(true){
			int num = sc.nextInt();
			if(num==0) break;
			System.out.println(pollock[0][num] + " " + pollock[1][num]);
		}
	}
}

Measured memory_bytes: 34724
#include <cmath>

#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cout.precision(16);
  cout << fixed;

  int n;
  cin >> n;

  vector<int> a(n + 1);
  for (auto&& i : a)
    cin >> i;

  vector<int> b(n);
  for (auto&& i : b)
    cin >> i;

  long long ans = 0;

  for (int i = 0; i < n; ++i) {
    int cur = min(a[i], b[i]);

    a[i] -= cur;
    b[i] -= cur;
    ans += cur;

    cur = min(a[i + 1], b[i]);

    a[i + 1] -= cur;
    b[i] -= cur;
    ans += cur;
  }

  cout << ans;
}


Measured memory_bytes: 1024
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class MainApp
{

	static public void Main()
	{
      		int N = Oneint();
            int[] A = Arrayint();
            int[] ans = new int[N];
            for(int i = 0; i < N - 1; i++)
            {
                ans[A[i]-1]++;
            }
            for(int i = 0; i < N; i++)
            {
                Console.WriteLine(ans[i]);
            }

	}


	private static string[] Arraystring()
	{
		return Console.ReadLine().Split(' ');
	}

	private static string Onestring()
	{
		return Console.ReadLine();
	}

	private static int Oneint()
	{
		return int.Parse(Console.ReadLine());
	}

	private static int[] Arrayint()
	{
		return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
	}
}


Measured memory_bytes: 43676
#=
A:
- Julia version: 0.5.2
- Author: abap
- Date: 2019-12-29
=#
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
A,B = parseMap(split(readline()))

x = [A+B,A-B,A*B]

println(maximum(x))


Measured memory_bytes: 109116
import sys
import math

import heapq

def input():
    return sys.stdin.readline().rstrip()


def tc():
    N = int(input())



def main():
    N = int(input())

    dp = [0]*(N+1)
    rt = int(N **0.5) +2
    for i in range(1,rt):
        for j in range(1,rt):
            for k in range(1,rt):
                case =int( i**2 + j **2 + k **2 + i*j + i*k + j*k )
                if case <=N:
                    dp[case] +=1


    for l in range(1,N+1):
        print(dp[l])










if __name__ == "__main__":
    main()


Measured memory_bytes: 9464
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

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

  int h, w, n;
  cin >> h >> w >> n;
  stack<pii> st;
  int a[n + 5];
  reps(i, n){
    cin >> a[i];
    st.push(mp(a[i], i));
  }
  int ans[h + 5][w + 5];
  rep(i, h){
    int na, su;
    //    cout << st.top().fi<< " ";
    if(i % 2 == 0){
      for(int j = 0;j < w;j ++){
	tie(na, su) = st.top();
	st.pop();
	na --;
	ans[i][j] = su;
	if(na != 0){
	  st.push(mp(na, su));
	}
      }
    } else {
      for(int j = w - 1;j >= 0;j --){
	tie(na, su) = st.top();
	st.pop();
	na --;
	ans[i][j] = su;
	if(na != 0){
	  st.push(mp(na, su));
	}
      }
    }
  }
  rep(i, h){
    rep(j, w - 1){
      cout << ans[i][j] << " ";
    }
    cout << ans[i][w - 1] << '\n';
  }
  return 0;
}


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

bool check_split(int &k, int &mid, vector<int> ws) {
  auto cars = 0;
  auto weights = 0;
  for (auto &item : ws) {
    if (weights + item > mid) {
      cars++;
      weights = 0;
    }
    weights += item;
  }
  return cars < k;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> ws;
  int wi;
  rep(i, n) {
    cin >> wi;
    ws.push_back(wi);
  }
  auto left = *max_element(ws.begin(), ws.end());
  auto right = accumulate(ws.begin(), ws.end(), 0);
  auto mid = 0;
  while (right - left > 1) {
    mid = (left + right) / 2;
    if(check_split(k, mid, ws))
      right = mid;
    else
      left = mid;
      
  }
  if (check_split(k, left, ws))
    cout << left <<endl;
  else
    cout << right << endl;
}




Measured memory_bytes: 3796
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    string S; cin >> S;

    if (S[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }

    if (S[1] <= 'Z' || S[S.length() - 1] <= 'Z') {
        cout << "WA" << endl;
        return 0;
    }

    sort(S.begin(), S.end());

    if (S[1] != 'C') {
        cout << "WA" << endl;
        return 0;
    }

    if (S[2] <= 'Z') {
        cout << "WA" << endl;
        return 0;
    }

    cout << "AC" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int w[2];
int h[2];
int x[2];
int y[2];
int t[2][500][500];
int m[2][500][500];
bool used[2][500][500];
vector<int> ad[2];
priority_queue<P,vector<P>,greater<P> > que;
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
void bfs(int a){
	int i;
	m[a][y[a]][x[a]]=1;
	que.push(P(1,y[a]*w[a]+x[a]));
	while(!que.empty()){
		P p=que.top();que.pop();
		int xp=p.second%w[a];
		int yp=p.second/w[a];
		if(p.first>m[a][yp][xp])continue;
		used[a][yp][xp]=true;
		for(i=0;i<4;i++){
			if(xp+dx[i]>=0&&xp+dx[i]<w[a]&&yp+dy[i]>=0&&yp+dy[i]<h[a]){
				if(!used[a][yp+dy[i]][xp+dx[i]]&&m[a][yp+dy[i]][xp+dx[i]]>max(p.first,t[a][yp+dy[i]][xp+dx[i]])){
					m[a][yp+dy[i]][xp+dx[i]]=max(p.first,t[a][yp+dy[i]][xp+dx[i]]);
					que.push(P(m[a][yp+dy[i]][xp+dx[i]],(yp+dy[i])*w[a]+(xp+dx[i])));
				}
			}
		}
	}
}
int main(){
	int r;
	int i,j,k;
	while(1){
	scanf("%d",&r);
	if(r==0)return 0;
	for(i=0;i<2;i++){
		scanf("%d %d %d %d",&w[i],&h[i],&x[i],&y[i]);
		x[i]--;y[i]--;
		for(j=0;j<h[i];j++)for(k=0;k<w[i];k++)scanf("%d",&t[i][j][k]);
	}
	for(i=0;i<2;i++){
		for(j=0;j<h[i];j++)for(k=0;k<w[i];k++){
			m[i][j][k]=200000000;
			used[i][j][k]=false;
		}
		bfs(i);
	}
	for(i=0;i<2;i++){
		ad[i].clear();
		ad[i].push_back(0);
		for(j=0;j<h[i];j++){
			for(k=0;k<w[i];k++){
				ad[i].push_back(m[i][j][k]);
			}
		}
		sort(ad[i].begin(),ad[i].end());
	}
	int ans=200000000;
	i=max(0,r-ad[1].size()+1);
	while(1){
		if(i>=ad[0].size()||r-i>=ad[1].size())break;
		ans=min(ans,ad[0][i]+ad[1][r-i]);
		i++;
	}
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 8272
from collections import Counter
from operator import itemgetter

N,K = list(map(int,input().split()))
A = list(Counter(map(int,input().split())).items())
A = sorted(A,key=itemgetter(1),reverse = True)

ans = 0
B = A[K:]
for i in range(len(B)):
    ans += B[i][1]
print(ans)

Measured memory_bytes: 41500
#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;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	
	if (a + b == c || a + c == b || c + b == a) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256