akhauriyash/Code-Regression huggingface dataset:
n = int(input())

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

d = {}
s = 0
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
    
    s += i

q = int(input())

for i in range(0, q):

    b, c = map(int, input().split())

    if b in d:
        s = s - (d[b] * b) + (d[b] * c)
        if c in d:
            d[c] += d[b]
        else:
            d[c] = d[b]
        d[b] = 0
    
        print(s)
    else:
        print(s)
        




Measured memory_bytes: 20800
n=int(input())
l=[0]*n
A=[]
for i in  range(0,n):
    l[i]=int(input())
    A.append([[0,0] for i in range(l[i])])
    for j in range(l[i]):
        A[i][j][0],A[i][j][1]=map(int,input().split())
count=0
for i in range(0,2**n):
    count1=0
    for j in range(n):
        if (i>>(n-j-1))&1:
            count1=count1+1
        for m in range(l[j]):
            if  (i>>(n-j-1))&1:
                if A[j][m][1]!=(i>>(n-A[j][m][0]))&1:
                    break
        else:
            continue
        break
    else:
        if count1>count:
            count=count1
print(count)


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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LONG_LONG_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;


int main() {
    string s;
    cin >> s;
    int n = s.length();
    vector<int> a(n+1);
    rep(i,n+1) {
        if(s[i] == '<') {
            a.at(i+1) = max(a.at(i+1), a.at(i)+1);
        }
    }
    for(int i = n; i >= 0; i--) {
        if(s[i-1] == '>') {
            a.at(i-1) = max(a.at(i-1), a.at(i)+1);
        }
    }
    ll ans = 0;
    rep(i,n+1) {
        ans += a.at(i);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2820
from itertools import accumulate
from collections import Counter
n, *A = map(int, open(0).read().split())
s = 0
for k, v in Counter(accumulate(A)).items():
    if k == 0:
        s += (v+1)*v // 2
    else:
        s += v*(v-1) // 2
print(s)

Measured memory_bytes: 42748
// https://img.atcoder.jp/abc061/editorial.pdf

#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

struct edge{
private:
public:
    edge(){}
    edge(uint u_in, uint v_in, uint c_in): u(u_in), v(v_in), cost(c_in) {}
    ~edge(){}
    int u; // from
    int v; // to
    int cost;
};

void negCost_ow(vector<edge>& vEdge){
    for(uint i=0; i<vEdge.size(); ++i){
        vEdge[i].cost = -1 * vEdge[i].cost;
    }
}
void neg_ow(vector<int64>& vRhs){
    for(uint i=0; i<vRhs.size(); ++i){
        vRhs[i] = -1 * vRhs[i];
    }
}

void bellmanFord(vector<bool>& vCycle, vector<int64>& vCost, const uint V, const uint E, const vector<edge>& vEdge, const uint begin){
    vCycle.resize(V); for(uint i=0; i<V; ++i){ vCycle[i]=false; }
    vCost.resize(V); for(uint i=0; i<V; ++i){ vCost[i]=INT64_MAX; } vCost[begin]=0ll;
    uint V_m1 = V-1;
    
    for(uint vi=0;; ++vi){
        bool isUpdate = false;
        for(uint ei=0; ei<E; ++ei){
            const struct edge& e = vEdge[ei];
            
            if(vCost[e.u]==INT64_MAX){ continue; }
            if(vCost[e.v] <= vCost[e.u] + e.cost){ continue; }
            vCost[e.v] = vCost[e.u] + e.cost;
            isUpdate = true;
            
            if(vi!=V_m1){ continue; }
            vCycle[e.u] = true;
            vCycle[e.v] = true;
        }
        if(!isUpdate){ return; }
        if(vi==V_m1){ return; }
    }
    return;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint V, E; cin >> V >> E;
    vector<edge> vEdge(E);
    for(uint i=0; i<E; ++i){
        uint a, b, c; cin >> a >> b >> c; --a; --b;
        vEdge[i].u    = a;
        vEdge[i].v    = b;
        vEdge[i].cost = c;
    }
    negCost_ow(vEdge);
    
    vector<bool> vCycle; vector<int64> vCost;
    bellmanFord(vCycle, vCost, V, E, vEdge, 0);
    if(vCycle[V-1]){ cout << "inf" << endl; return 0; }
    neg_ow(vCost);
    
    cout << vCost[V-1] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(0);
	int n;
	cin >> n; 
    vector<int> a(n+1,0), x(n+1,0);
    for(int i=1; i<=n; ++i){
        cin >> a[i];
        x[1] += a[i];
    }
    for(int i=2; i<n; i+=2){
        x[1] -= 2*(a[i]);
    }
    cout << x[1] << " ";
    for(int i=2; i<=n; ++i){
        x[i]=2*a[i-1]-x[i-1];
        cout << x[i] << " ";
    }
	cout << endl;
}

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

typedef long long ll;

int main(){
    ll N,K; cin >> N >> K;
    ll a[N+1]; for(int i=1;i<=N;i++) cin >> a[i];

    bool used[N+1]={};
    bool used2[N+1]={};
    vector<int> ans;

    ll tmp=1;
    ll size=0;
    for(int i=0;i<2*N;i++){
        if(used2[tmp]) break;
        if(used[tmp]){
            size++;
            used2[tmp]=true;
            tmp=a[tmp];
        }else{
            ans.push_back(tmp);
            used[tmp]=true;
            tmp=a[tmp];
        }
    }
    /*
    cout << size << endl;
    for(int i=0;i<ans.size();i++){
        cout << ans[i] << " ";
    }
    cout << endl;
    */
    ll n=ans.size()-size;
    if(K<ans.size()){
        cout << ans[K] << endl;
    }else{
        ll ind=(K-n)%size;
        cout << ans[n+ind] << endl;
    }
    
}

Measured memory_bytes: 6180
#include<bits/stdc++.h>
using namespace std;
#define nn 500008
vector<int> v[nn];
struct jack{
	int si,di,co,when;
	jack(int a=0,int b=0,int c=0,int d=0){
		si=a,di=b,co=c;when=d;
	}
};
bool operator<(jack a,jack b){
	if(a.di!=b.di) return a.di<b.di;
	return a.when<b.when;
}
int color[nn],when[nn];

int n,m,q;
int si[nn],di[nn],co[nn];

signed main(){
	scanf("%d%d",&n,&m);
	while(m--){
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].push_back(y),v[y].push_back(x);
	}
	
	scanf("%d",&q);
	priority_queue<jack> pq;
	for(int i=1;i<=q;i++) scanf("%d%d%d",&si[i],&di[i],&co[i]),pq.push(jack(si[i],di[i],co[i],i));
	while(pq.size()){
		jack x=pq.top();pq.pop();
		if(when[x.si]<x.when){
			when[x.si]=x.when;
			color[x.si]=x.co;
		}
		else continue;

		for(int i=0;i<v[x.si].size();i++)if(x.di){
			int y=v[x.si][i];
			if(when[y]<x.when)
				pq.push(jack(y,x.di-1,x.co,x.when));
		}
	}
	
	for(int i=1;i<=n;i++) printf("%d\n",color[i]);
	
	return 0;
}

Measured memory_bytes: 32876
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e5+100, mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int res=0,last=0;
	
	for(int i=n-2;i>=0;i--){
		if( a[i]>=a[i+1] ){
			++last;
		}else{
			last=0;
		}
		res=max(res,last);
	}
	cout<<res;
}


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

int main(int argc, char const *argv[]) {
  int a, b;
  int tmp, ans;
  cin >> a >> b;

  if (a > b)
    tmp = 2 * a - 1;
  else
    tmp = 2 * b - 1;

  if (tmp > (a + b))
    ans = tmp;
  else
    ans = a + b;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <unordered_map>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

UINT gcd(UINT a, UINT b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

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

const UINT mod = 1000000007;
const double pi = 3.141592653589793238462;
const INT intmax = 9223372036854775807;

UINT _PowMod(UINT x, UINT y, UINT _mod)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % _mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = _PowMod(x, y / 2, _mod);
		return tmp * tmp % _mod;
	}
	else
	{
		auto tmp = _PowMod(x, y / 2, _mod);
		return (tmp * tmp % _mod) * x % _mod;
	}
}


UINT PowMod(UINT x, UINT y)
{
	return _PowMod(x, y, mod);
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

INT nCrMod(INT start, INT n, INT r)
{
	if (n < r)
	{
		return 0;
	}
	INT a = start;
	for (size_t i = n; i >= n - r + 1; i--)
	{
		a *= i;
		a %= mod;
	}
	for (size_t i = 1; i <= r; i++)
	{
		a *= getModInv(i);
		a %= mod;
	}
	return a;
}

INT nHrMod(INT start, INT n, INT r)
{
	return nCrMod(start, n + r - 1, r);
}

INT _nCrMod(INT start, INT n, INT r)
{
	if (n <= 0)
	{
		return 0;
	}
	return nCrMod(start, n, r);
}

struct uf
{
	vector<INT> p;

	uf(INT n) : p(n)
	{
		for (size_t i = 0; i < n; i++)
		{
			p[i] = i;
		}
	}

	INT rt(INT n)
	{
		return p[n] == n ? n : p[n] = rt(p[n]);
	}

	void un(INT n, INT m)
	{
		p[rt(n)] = p[rt(m)];
	}

	bool eq(INT n, INT m)
	{
		return rt(n) == rt(m);
	}
};

bool lineCol(INT a1x, INT a1y, INT a2x, INT a2y, INT b1x, INT b1y, INT b2x, INT b2y)
{
	auto ta = (b1x - b2x) * (a1y - b1y) + (b1y - b2y) * (b1x - a1x);
	auto tb = (b1x - b2x) * (a2y - b1y) + (b1y - b2y) * (b1x - a2x);
	auto tc = (a1x - a2x) * (b1y - a1y) + (a1y - a2y) * (a1x - b1x);
	auto td = (a1x - a2x) * (b2y - a1y) + (a1y - a2y) * (a1x - b2x);

	return tc * td < 0 && ta * tb < 0;
}

INT powInt(INT a, INT b)
{
	if (b == 0)
	{
		return 1;
	}
	if (b == 1)
	{
		return a;
	}
	INT tmp = powInt(a, b / 2);
	return (b % 2 == 1 ? a * tmp * tmp : tmp * tmp);
}

INT _sMod(string n, INT mod)
{
	INT k = (n[0] - '0') % mod;
	for (size_t i = 1; i < n.length(); i++)
	{
		k *= 10;
		k += (n[i] - '0');
		k %= mod;
	}
	return k;
}

#define forin(v, n)				\
for (size_t i = 0; i < n; i++)	\
{								\
	cin >> v[i];				\
}

#define vec(t, name, n)			vector<t> name(n)
#define vec_(t, name, n, init)	vector<t> name(n, init)

#define vec2(t, name, n, m)			vector<vector<t>> name(n, vector<t>(m))
#define vec2_(t, name, n, m, init)	vector<vector<t>> name(n, vector<t>(m, init))

struct xy
{
	INT x, y;
	xy() :x(0), y(0) {}
	xy(INT _x, INT _y) : x(_x), y(_y) {}
};

int main()
{
	INT n, k;
	cin >> n >> k;
	cout << k * powInt(k - 1, n - 1) << endl;
	return 0;
}


Measured memory_bytes: 256
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d, e, H, W, L;
long long A[200005] = {};
char B[500][500] = {};
long long C[205][205] = {};
long long D[200005] = {};
long long E[200005] = {};
bool f, ff;
string S[2];
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


bool fs[2005][2005] = {};

int main() {


	cin >> B[0][0]>>B[0][1]>>B[0][2];
	cin >> B[1][0] >> B[1][1] >> B[1][2];
	
	

	if (B[0][0] == B[1][2] && B[0][1] == B[1][1] && B[0][2] == B[1][0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;

}


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

using namespace std;

int main(void)
{
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    for(int i = 0; i < N; ++i){
        cin >> H[i];
    }

    vector<int> good(N, 1);
    for (int i = 0; i < M; ++i){
      	int A, B;
        cin >> A >> B;
        if(H[A-1]>H[B-1]){
            good[B-1] = 0;
        }
        else if (H[A-1]<H[B-1]){
            good[A-1] = 0;
        }
      	else{
          good[A-1] = 0;
          good[B-1] = 0;
        }
    }
    cout << count(good.begin(), good.end(), 1) << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N;
  cin >> N;
 
  // ここにプログラムを追記
  rep(i, N) {
    string s;
    cin >> s;
    
    if (s == "Y") {
      cout << "Four" << endl;
      break;
    } else {
      if (i == N - 1) {
        cout << "Three" << endl;
      }
      continue;
    }
  }
}

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

int main(){
    int N;
    int d[110];
    cin>>N;
    for(int i=0;i<N;++i)cin>>d[i];
    sort(d,d+N,greater<int>());
    int counter=1;
    if(N==1){
        
    }
    else{
        for(int i=1;i<N;++i){
            if(d[i]!=d[i-1])counter+=1;
        }
        
    };
    cout<< counter <<endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#define inf 0x3f3f3f3f
#define esp 1e-7
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int n;
long long num[300000];
long long sumall,x,y;

long long xy(long long a){return a>0? a:-a;}

int main(){
	n=read();
	sumall=x=y=0;
	for (int i=1;i<=n;i++){
		num[i]=read();
		sumall+=num[i];
	}
	long long minn=100000000000000000ll;
	x=num[1];
	minn=min(abs(x-(sumall-x)),minn);
	for (int i=2;i<n;i++){
		x+=num[i];
		minn=min(abs(x-(sumall-x)),minn);
	}
	cout<<minn<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	LOOP(N){
		string S=in<string>();
		vector<string> TA;
		stack<int> IP;
		stack<string> SIP;

		int M=S.size();
		string buf;
		S.insert(0,"(");
		S.insert(M,")");
		REP(i,M+1){
			char ch=S[i];
			if(ch!='+' && ch!='-' && ch!='*' && ch!='/' && ch!='(' && ch!=')'){
				buf.push_back(ch);
			}
			else if(ch!='('){
				if(!buf.empty()) TA.push_back(buf);
				buf.clear();
				if(ch=='+' || ch=='-'){
					while(!SIP.empty()){
						if(SIP.top()=="("){
							break;
						}
						TA.push_back(SIP.top());
						SIP.pop();
					}
					SIP.push(string(1,ch));
				}
				else if(ch=='*' || ch=='/'){
					if(!SIP.empty() && (SIP.top()=="*" || SIP.top()=="/")){
						TA.push_back(SIP.top());
						SIP.pop();
					}
					SIP.push(string(1,ch));
				}
				else if(ch==')'){
					while(!SIP.empty()){
						if(SIP.top()=="("){
							SIP.pop();
							break;
						}
						TA.push_back(SIP.top());
						SIP.pop();
					}
				}
			}
			else if(ch=='('){
				SIP.push("(");
			}
		}
		if(!buf.empty()) TA.push_back(buf);
		while(!SIP.empty()){
			TA.push_back(SIP.top());
			SIP.pop();
		}
		for(auto& x:TA){
			if(x!="+" && x!="-" && x!="*" && x!="/"){
				int V;
				sscanf(x.c_str(),"%d",&V);
				IP.push(V);
			}
			else if(x=="+"){
				int V=IP.top();IP.pop();
				int U=IP.top();IP.pop();
				IP.push(V+U);
			}
			else if(x=="*"){
				int V=IP.top();IP.pop();
				int U=IP.top();IP.pop();
				IP.push(V*U);
			}
			else if(x=="-"){
				int V=IP.top();IP.pop();
				int U=IP.top();IP.pop();
				IP.push(U-V);
			}
			else if(x=="/"){
				int V=IP.top();IP.pop();
				int U=IP.top();IP.pop();
				IP.push(U/V);
			}
		}
		out(IP.top());
	}
	return 0;
}



Measured memory_bytes: 3208
#include <cstdio>
#include <algorithm>
using namespace std;
#define fup(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
inline int read()
{
    int X=0,w=1; char ch=0;
    while(ch<'0' || ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0' && ch<='9') X=(X<<3)+(X<<1)+ch-'0',ch=getchar();
    return X*w;
}
struct dl{ int v; double t; }d[500005];
int n,l,v,t,h = 1,len; double x,y;
inline void insert(int t,int v)
{
	d[++len].v = v; d[len].t = t;
	while(len>h&&d[len].t<=d[len-1].t)
	{ 
		d[len-1].t = (d[len].t*d[len].v+d[len-1].t*d[len-1].v)/(d[len].v+d[len-1].v);
		d[len-1].v = d[len].v+d[len-1].v; len--;
	}
}
int main()
{
	//freopen("E:\\inout\\cs.in","r",stdin);
	n = read(); l = read();
	fup(i,1,n)
	{
		t = read(); v = read();
		y = y+(double)v*t; x = x+v;
		while(h<=len&&x>l)
		{
			if(x-l>=d[h].v)
			{
				x -= d[h].v;
				y -= 1LL*d[h].v*d[h].t;
			}else
			{
				d[h].v -= x-l;
				y -= (double)(x-l)*d[h].t;
				x = l; break;
			} h++;
		}
		insert(t,v); printf("%.7lf\n",y/x);
	}
	return 0;
}


Measured memory_bytes: 16768
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,ans=100000001,cost;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(int j=1;j<=100;j++){
        cost=0;
        for(int i=0;i<n;i++){
            cost+=(a[i]-j)*(a[i]-j);
        }
        ans=min(ans,cost);
    }
    cout<<ans;
}

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



int main() {
  int n;
  cin >> n;
  int a, tmp = 0;
  rep(i,n){
    cin >> a;
    if(a == tmp+1){
      tmp++;
    }
  }
  int ans = -1;
  if(tmp != 0) ans = n - tmp;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define US unordered_set
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef vector<vvi> vvvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
const ll MOD = 1000000007;

pii extendedEuclid(ll a,ll b){
  bool swapped=false;
  if(a<b) {swap(a,b);swapped=true;}
  pii x={1,0},y={0,1};
  while(1){
    ll xv=a*x.first+b*x.second;
    ll yv=a*y.first+b*y.second;
    if(yv==0) {if(swapped) return {x.second,x.first}; else return x;}
    ll d=xv/yv;
    swap(x,y);
    y.first-=d*x.first;
    y.second-=d*x.second;
  }
}

ll inverse(ll a,ll mod) {
  return (mod+extendedEuclid(a,mod).first%mod)%mod;
}

ll power(ll a, ll b, ll mod) {
  ll tmp=a;
  ll tmpp=1;
  ll ret=1;
  while(1){
    if(b%(tmpp*2)){
      ret=ret*tmp%mod;
      b-=tmpp;
    }
    if(b==0) break;
    tmp=tmp*tmp%mod;
    tmpp*=2;
  }
  return ret;
}

int main() {
  ll N,A,B,C,D; cin>>N>>A>>B>>C>>D;
  vi v(N+1);
  vi vv(N+1);
  {v[0]=1; FOR(i,1,N+1) v[i]=v[i-1]*i%MOD;}
  REP(i,N+1) vv[i]=inverse(v[i],MOD);
  vvi dp(B+1,vi(N+1));
  dp[A-1][0]=1;
  FOR(i,A,B+1) REP(j,N+1) {
    dp[i][j]+=dp[i-1][j];
    FOR(k,C,D+1) {
      if(k*i>j) break;
      ll tmp=1;
      tmp=tmp*dp[i-1][j-k*i]*v[N-j+k*i]%MOD;
      tmp=tmp*vv[N-j]%MOD;
      tmp=tmp*power(vv[i],k,MOD)%MOD;
      tmp=tmp*vv[k]%MOD;
      dp[i][j]+=tmp;
    }
    dp[i][j]%=MOD;
  }
  cout<<dp[B][N]<<endl;
}


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

int main() {
ll x,n,s1=0,s2=0,s=0,i;
cin>>n;
int a[n],b[n];

for(i=0;i<n;i++){cin>>a[i];}
for(i=0;i<n;i++){cin>>b[i];s2+=b[i];}
for(i=0;i<n;i++)
{ s1+=a[i];
    s=max(s,s1+s2);
    s2-=b[i];
}cout<<s;
}

Measured memory_bytes: 3596
/**
 *    author:  FromDihPout
 *    created: 2020-08-11
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    map<int,int> freq;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        freq[x]++;
    }
    
    int ans = 0;
    for (auto i : freq) {
        if (i.first != i.second) {
            ans += i.second >= i.first ? i.second - i.first : i.second;
        }
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

void solve()
{
	int n;
	cin >> n;
	int n2 = n * 2;
	vector<int> Vec;
	for(int i = 0; i < n2; ++i)
	{
		Vec.push_back(i + 1);
	}
	int m;
	cin >> m;
	for(int i = 0; i < m; ++i)
	{
		int k;
		cin >> k;
		if(k == 0)
		{
			vector<int> VecBuf = Vec;
			Vec.clear();
			for(int i = 0; i < n; ++i)
			{
				Vec.push_back(VecBuf[i]);
				Vec.push_back(VecBuf[n + i]);
			}
		}
		else
		{
			vector<int> VecBuf = Vec;
			Vec.clear();
			for(int i = k; i < n2; ++i)
			{
				Vec.push_back(VecBuf[i]);
			}
			for(int i = 0; i < k; ++i)
			{
				Vec.push_back(VecBuf[i]);
			}
		}
	}
	for(int i = 0; i < n2; ++i)
	{
		cout << Vec[i] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

bool pri(long long n) {
	if (n < 2)
		return 0;
	for (int i = 2; i * i <= n; ++i)
		if (n % i == 0)
			return 0;
	return true;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long x;
	cin >> x;
	for (int i = x; ; ++i)
		if (pri(i)) {
			cout << i << '\n';
			return 0;
		}
  return 0;
}



Measured memory_bytes: 256
r,c=map(int,input().split())
mod=10**9+7
dp=[[0]*(c+1) for i in range(r+1)]
a=[]
for i in range(r):
    a.append(input())
dp[0][1]=1
for i in range(1,r+1):
    for j in range(1,c+1):
        if(a[i-1][j-1]=='.'):
            dp[i][j]=dp[i-1][j]+dp[i][j-1]
            #print((str(dp[i-1][j])+str(dp[i][j-1])),end=" ")
    #print()
#for i in dp:
#    print(i)
print(dp[r][c]%mod)


Measured memory_bytes: 157416
N, M = map(int,input().split())
G = [[] for _ in range(N)]
for i in range(M):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  G[a].append(b)
  G[b].append(a)

visited = [True]*N
visited_all = [False]*N
cnt = [0]

def dfs(visited, pos):
  visited[pos] = False
  if visited == visited_all:
    cnt[0] += 1
  else:
    for p in G[pos]:
      if visited[p] == False:
        continue
      dfs(visited, p)
      visited[p] = True

dfs(visited, 0) 
print(cnt[0]) 

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

void solve() {
    int N; cin >> N;
    vector<vector<int>> G(N);
    vector<int> deg(N);
    vector<P> pairs;
    int mx = 0;
    for(int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        pairs.emplace_back(--a, --b);
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        mx = max(mx, ++deg[a]);
        mx = max(mx, ++deg[b]);
    }
    map<P, int> ma;
    auto dfs = [&](auto &&dfs, int cur, int pre, int col) -> void {
        for(auto &to : G[cur]) {
            if(to == pre) continue;
            if(++col > mx) col = 1;
            ma[{cur, to}] = col;
            ma[{to, cur}] = col;
            dfs(dfs, to, cur, col);
        }
    };
    dfs(dfs, 0, -1, 0);
    cout << mx << '\n';
    for(auto &p : pairs) {
        cout << ma[p] << '\n';
    }
}

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


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

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  
  multiset<int> hset;
  for(int i = 0; i < N; i++){
    int H;
    cin >> H;
    hset.emplace(H);
  }
  
  long long sum = 0;
  int count = 0;
  for(auto &elem : hset){
    if(count >= N-K){
      break; 
    }
    sum += elem;
    ++count;
  }
  
  cout << sum;
  return 0;
}

Measured memory_bytes: 9600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9) + 7;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
      	String s = sc.next();
      	// 對每個字母計數
      	int[] charCnt = new int[26];
      	// 每個字母最遠到哪裡，例如finalLoc[0] = 15,代表a最後一次出現的位置
      	int[] finalLoc = new int[26];
      	int len = s.length();
      	
      	for (int i = 1; i < len; i++) {
      		if (s.charAt(i) == s.charAt(i - 1)) {
      			System.out.println((i) + " " + (i + 1));
  				System.exit(0);
      		}
      	}
      	
      	for (int i = 2; i < len; i++) {
      		if (s.charAt(i) == s.charAt(i - 2)) {
      			System.out.println((i - 1) + " " + (i + 1));
  				System.exit(0);
      		}
      	}
      	
      	System.out.println("-1 -1");
	}
	
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;

int main() {
	int n, a, b;
	cin >> n;

	if(n == 2){
		cin >> a >> b;
		cout << a + b << endl;
	}else{
		cout << "Hello World" << endl;
	}



    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define print(x) cout<<#x<<"="<<x<<'\n'
#define print2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define print3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define fr(i,a,n) for(int i=a;i<=(n);++i)
#define rf(i,a,n) for(int i=a;i>=(n);--i)
#define mp make_pair
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<long double>
#define vvi vector<vector<long double>>
#define vpii vector<pii>
using namespace std;

vi graph[101];
int level[101];
bool vis[101];

int main(){
	int t=1;
	// cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		// long double temp=((long double)(1))/((long double)(3));
		// cout<<setprecision(16);
		// cout<<temp;
		vi a(n);
		vector<bool> dp(k+1,false);
		rep(i,n){
			cin>>a[i];
			dp[a[i]]=true;
		}
		fr(i,0,k){
			bool temp=true;
			rep(j,n){
				if(i-a[j]>=0){
					temp=temp&dp[i-a[j]];
				}
			}
			dp[i]=!temp;
		}
		if(dp[k])
			cout<<"First\n";
		else
			cout<<"Second\n";
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,a,n) for(ll i=a;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin>>n;
  ll a[n],num[n+1];
  rep(i,0,n+1)num[i]=0;
  rep(i,0,n){
    cin>>a[i];
    num[a[i]]++;
  }
  ll sum=0;
  rep(i,1,n+1){
    if(num[i]>=2){
      rep(j,1,num[i])sum+=j;
    }
  }
  rep(i,0,n){
    if(a[i])cout<<sum-num[a[i]]+1<<endl;
  }
  return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int main() {
	string S;
	cin >> S;
	int N = S.length();

	ll ans = 0;
	for (int bit = 0 ; bit < (1 << (N - 1)) ; bit++) {

    	ll sum = 0;
    	ll num = S[0] - '0';
    	for (int i = 0 ; i < N - 1 ; i++) {
			if ((bit >> i) & 1) {
        		sum += num;
        		num = 0;
			}
      		num = num * 10 + S[i+1] - '0';
    	}
    	sum += num;
		
    	ans += sum;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll MOD = 998244353;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    ll ans = 1e18;
    ll tmp = 0;
    for(int i = 0; i < n; i++)
    {
        tmp += a[i];
        ans = min(ans, abs(sum - 2*tmp));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
int main()
{
  int n, d[101], c[101];
  int i, ans = 0;

  std::cin >> n;
  for (i = 0; i < n; i++)
  {
    std::cin >> d[i];
  }

  for (i = 0; i <= 100; i++)
  {
    c[i] = 0;
  }

  for (i = 0; i < n; i++)
  {
    c[d[i]]++;
  }

  for (i = 0; i <= 100; i++)
  {
    if (c[i] > 0)
    {
      ans++;
    }
  }

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

Measured memory_bytes: 764
n,pp = gets.split.map(&:to_i)

h = [0,0]
gets.split.each{|e| h[e.to_i % 2] += 1}

if h[1] == 0
    puts pp == 0 ? 2 ** n : 0
else
    puts 2 ** (n - 1)
end

Measured memory_bytes: 1788
A, B, C, X, Y = map(int, input().split())


min_cost = 0

if X - Y > 0:
    temp_cost = 2 * C * Y
    temp_cost += A * (X - Y)    

    temp_cost2 = 2 * C * X

    if temp_cost > temp_cost2:
        min_cost = temp_cost2
    else:
        min_cost = temp_cost

else:
    temp_cost = 2 * C * X
    temp_cost += B * (Y - X)

    temp_cost2 = 2 * C * Y

    if temp_cost > temp_cost2:
        min_cost = temp_cost2
    else:
        min_cost = temp_cost


temp_cost3 = A * X + B *Y

if temp_cost3 < min_cost:
    min_cost = temp_cost3

print(min_cost)



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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VC vector<char>
using namespace std;

int main() {
	int n;
	cin >> n;
	int res = 1;
	VC v(n);
	REP(i, n) {
		cin >> v[i];
	}
	sort(ALL(v));
	REP(i, n-1) {
		if (v[i] != v[i + 1]) {
			res++;
		}
	}
	if (res == 3) {
		cout << "Three" << endl;
	}
	else {
		cout << "Four" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N,Ma,Mb=list(map(int,input().split()))

mix=set([(0,0)])
ans=10**9
cost={(0,0):0}
for i in range(N):
    a,b,c=list(map(int,input().split()))
    tmp=mix.copy()
    tmp2=cost.copy()
    for x in tmp:
        d=x[0]+a
        e=x[1]+b
        f=min(tmp2.get((d,e),10**9),tmp2[x]+c)
        cost[(d,e)]=f
        mix.add((d, e))
        if d*Mb==e*Ma and f<ans:
            ans=f
"""
print(cost)
print(mix)
"""
if ans==10**9:
    ans=-1
print(ans)

Measured memory_bytes: 14232
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	string S, T;

	cin >> S >> T;

	cout << T + S << endl;

	return 0;
}


Measured memory_bytes: 384
n,k=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]

# ==================================================-
# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math
import sys
sys.setrecursionlimit(10**9)
def binary_research(start,end,function):
    if start==end:
        return start
    middle=math.ceil((start+end)/2)
    if function(middle):
        start=middle
    else:
        end=middle-1
    return binary_research(start, end, function)
positive=[]
negative=[]
zero=False


for i in x:
    if i<0:
        negative.append(abs(i))
    elif i>0:
        positive.append(i)
    else:
        zero=True
positive.sort()
negative.sort()


def function(time):
    if time==-1:
        return True
    ans_list=[]
    ans=0
    if zero:
        ans+=1
    for i in positive:
        if i<=time:
            ans_list.append(i)
            ans+=1
        else:
            break
    negative_list=[]
    for i in negative:
        if i<=time:
            negative_list.append(i)
        else:
            break
    negative_list=negative_list[::-1]
    newans=ans
    while negative_list:
        newans,ans_list,negative_list=function2(ans_list,negative_list,newans,time)
        ans=max(ans,newans)
        if ans_list==[]:
            break
        else:
            ans_list.pop()
            newans-=1
    if ans>=k:
        return False
    return True



def function2(ans_list,negative_list,ans,time):
    if ans_list==[]:
        max_num=0
    else:
        max_num=ans_list[-1]
    remain_time=time-max_num*2
    while negative_list:
        i=negative_list.pop()
        if max_num==0:
            if i<=remain_time:
                ans+=1
        elif max_num+i+min(i,max_num)<=time:
            ans+=1
        else:
            negative_list.append(i)
            break
    return ans,ans_list,negative_list


print(binary_research(-1,3*10**8+1,function)+1)

Measured memory_bytes: 20092
// Alchemist
// Resistors in Parallel
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>

using namespace std;
int N;

struct data
{
    int reward;
    int days;

public:
    data(int a, int b)
    {
        reward = b;
        days = a;
    }
    bool operator<(data b)
    {
        return this->days < b.days;
    }
};

int main()
{
    //int A[50];
    //int B[50];
    vector<data> vec;

    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        vec.push_back(data(a, b));
    }
    std::sort(vec.begin(), vec.end(), [](data a, data b) { return a.days < b.days; });

    std::priority_queue<int> q;

    int score = 0;

    int i = 0;
    for (int j = 1; j <= M; j++)
    {
        for (; i < N && vec[i].days <= j; i++)
        {
            q.push(vec[i].reward);
        }
        if (!q.empty())
        {
            score += q.top();
            q.pop();
        }
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 1908
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int x, a, b; cin >> x >> a >> b;

    if (abs(x - a) < abs(x - b)) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  ll X,Y;
  cin>>X>>Y;
  if(abs(X-Y)<=1) cout<<"Brown"<<endl;
  else cout<<"Alice"<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
struct Edge {
	int src;
	int dst;
	int rev;
	int cap;
};
typedef vector<vector<Edge>> Graph;
void add_edge(Graph &g, int s, int t, int c) {
	g[s].push_back(Edge{ s,t,int(g[t].size()),c });
	g[t].push_back(Edge{ t,s,int(g[s].size())-1,0 });
}
struct Compare {
public:
	bool operator()(const pair<int, int>&l, const pair<int, int>&r) {
		return l.first < r.first;
	}
};
const int AMAX = INT_MAX / 2;
int maximumflow(Graph& g,int start,int goal) {
	int ans = 0;
	while (true) {
		int flow = 0;
		priority_queue<pair<int, int>>que;
		que.emplace(AMAX, 0);
		vector<int>memo(g.size(), 0),rev(g.size(),-1);
		memo[start] = AMAX;
		while (!que.empty()) {
			auto atop(que.top());

			que.pop();
			const int now(atop.second);
			const int f(atop.first);
			if (now == goal) {
				flow = f;
				break;
			}
			for (auto e : g[now]) {
				const int nextcost(min(f, e.cap));
				if (memo[e.dst] < min(f, nextcost)) {
					memo[e.dst] = min(f, nextcost);
					rev[e.dst] = e.rev;
					que.emplace(nextcost, e.dst);
				}
			}
		}
		if (flow == 0)return ans;
		ans += flow;
		int now(goal);
		while (now != start) {
			g[now][rev[now]].cap += flow;
			int next(g[now][rev[now]].dst);
			g[next][g[now][rev[now]].rev].cap -= flow;
			now = next;
		}
		int ss; ss = 0;
		ss += 1;
		ans += ss;
		ans -= ss;
	}
}

int main() {
	int V, E; cin >> V >> E;
	Graph g(V);
	for (int i = 0; i < E; ++i) {
		int s, t, c; cin >> s >> t >> c;
		add_edge(g,s, t, c);
	}
	int ans = maximumflow(g, 0, V - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3212
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[210001],i,j,k,n,m,ans,lim;
int main(){
	scanf("%d%d%d",&n,&m,&lim);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for (i=j=1,ans=0;i<=n;i++){
		if (a[i]-a[j]>lim||i-j+1>m){
			ans++;j=i;
		}
	}
	ans++;
	printf("%d\n",ans);
	return 0;
}

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

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

    vector<int> p, q;
    rep(i, 0, n)
    {
        int num;
        cin >> num;
        p.push_back(num);
        q.push_back(num);
    }

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

    int cnt = 0;
    rep(i, 0, n) cnt += int(p[i] != q[i]);

    if (cnt < 3)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){

int X,t;
  cin>>X>>t;
  cout<<(t>X ? 0 : X-t);
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////



int main() {
	
	ll N, M, X, Y;
	cin >> N >> M >> X >> Y;

	ll x[MAX], y[MAX];

	repn(i, N) cin >> x[i];
	repn(i, M) cin >> y[i];

	ll Z = X;
	repn(i, N) Z = max(Z, x[i]);

	ll W = Y;
	repn(i, M) W = min(W, y[i]);

	if (Z < W) { cout << "No War"; }
	else { cout << "War"; }

	system("PAUSE");
}

Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
const int mx=223456;
#define ll long long
#define p push_back
#define ff first
#define ss second
ll n ,s[mx],cnt=200000,sum;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            s[i+1]=cnt;
            cnt++;
            sum++;
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int i, j, n, v, sw = 0, minj, a[100];
	scanf("%d", &n);
	for (i = 0; i < n; i++)scanf("%d", &a[i]);
	for (i = 0; i < n; i++) {
		minj = i;
		for (j = i; j < n; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		v = a[i];
		a[i] = a[minj];
		a[minj] = v;
		if (minj != i)sw++;
	}
	for (i = 0; i < n; i++) {
		printf("%d", a[i]);
		if (i != n - 1)printf(" ");
	}
	printf("\n%d\n", sw);
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  string t;
  cin >> t;
  int n=s.size();
  bool ans=true;
  for(int i=0;i<n;++i) {
    if(t[i]!=s[i]) ans=false;
  }
  puts(ans?"Yes":"No");
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  char a,b;
  cin >> a >> b;
  int c=a-'0',d=b-'0';
  string s,t;
  rep(i,d){
    s.push_back(a);
  }
  rep(i,c) t.push_back(b);
  cout << min(s,t) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define IOS std::ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
const int N = 1e6+20;
const ll Mod = 1e5;
const int INF = 0x3f3f3f3f;
int main(){
  int flag1 = 0;
  int flag2 = 0;
  string s;
  cin>>s;
  if(s[0] <= '1'){
    if(s[0] ==  '1'){
      if(s[1] > '2'){
        flag1 = 1;
      }
    }else{
      if(s[1] == '0'){
        flag1 = 1;
      }
    }
  }else{
    flag1 = 1;
  }
  if(s[2] <= '1'){
    if(s[2] ==  '1'){
      if(s[3] > '2'){
        flag2 = 1;
      }
    }else{
      if(s[3] == '0')
      flag2 = 1;
    }
  }else flag2 = 1;
  if(flag2 && flag1){
    cout<<"NA"<<endl;
  }else if(flag2){
    cout<<"MMYY"<<endl;
  }else if(flag1){
    cout<<"YYMM"<<endl;
  }else{
    cout<<"AMBIGUOUS"<<endl;
  }
	return 0;
}


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

int main() {
    int rooms[4][3][10] = {};
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        rooms[b - 1][f - 1][r - 1] += v;
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                cout << ' ' << rooms[i][j][k];
            }
            cout << endl;
        }
        if (i != 3) cout << "####################" << endl;
    }
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int N;
	cin >> N;
	vector<LL> A(N+2);
	vector<int> pos(N + 1, 0);
	A[0] = INF; A[N + 1] = INF;
	for (int i = 1; i <=N; ++i) {
		cin >> A[i];
		pos[A[i]] = i;
	}
	set<int> L, R;
	L.insert(-pos[N]);
	R.insert(pos[N]);

	LL ans = 0;
	set<int>::iterator itr;
	for (int i = N - 1; i >= 1; --i) {
		LL ter = pos[i];
		int Lpos2,Lpos1,Rpos1, Rpos2;
		itr = R.upper_bound(ter);
		if (itr != R.end() ){
			Rpos1 = *itr;
			itr = R.upper_bound(Rpos1);
			if (itr != R.end()) {
				Rpos2 = *itr;
			}
			else {
				Rpos2 = N + 1;
			}

			itr = L.upper_bound(-ter);
			if (itr != L.end()) {
				Lpos1 = -(*itr);
			}
			else {
				Lpos1 = 0;
			}
			LL res = (LL)(ter - Lpos1) * (Rpos2 - Rpos1);
			ans += res*i;
		}
		
		itr = L.upper_bound(-ter);
		if(itr != L.end()){
			Lpos1 = -(*itr);
			itr = L.upper_bound(-Lpos1);
			if (itr != L.end()) {
				Lpos2 = -(*itr);
			}
			else {
				Lpos2 = 0;
			}

			itr = R.upper_bound(ter);
			if (itr != R.end()) {
				Rpos1 = (*itr);
			}
			else {
				Rpos1 = N + 1;
			}
			LL res = (LL)(Lpos1 - Lpos2) * (Rpos1 - ter);
			ans += res*i;
		}
		R.insert(ter);
		L.insert(-ter);
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int a,b;
    string s;
    cin >> a >> b >> s;
    int flag = 0;
    for(int i = 0; i < s.size(); i++){
        if(i == a){
            if(s[i] != '-') flag = 1; 
        }else if(!('0' <= s[i] && s[i] <= '9')) flag = 1;
    }
    cout << (flag ? "No" : "Yes") << endl;

    return 0;
}

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

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

print (ans)

Measured memory_bytes: 18476