akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll INF = 1e16;

ll n, mod;
vvl G;
vl dp1;  // dp1[v] : 頂点vを根とする下方向の部分木の塗り方の場合の数
vl dp2;  // dp2[v] : 頂点vを根とする上方向の部分木の塗り方の場合の数
vl ans;  // ans[v] : 頂点vを黒で塗るときの場合の数

void dfs1(ll v, ll p = -1) {
    // 行きの処理はこのへんに書く
    ll x = 1;
    for(ll to : G[v]) {
        if(to == p) {
            continue;
        }
        dfs1(to, v);
        // 帰りの処理はこのへんに書く
        x = x * dp1[to] % mod;
    }
    dp1[v] = x + 1;
}

void dfs2(ll v, ll p = -1) {
    // 行きの処理はこのへんに書く
    if(p == -1) {
        dp2[v] = 1;
    }
    vl ruiL(G[v].size(), 1);
    rep(i, (ll)G[v].size()) {
        ll to = G[v][i];
        if(i-1 >= 0) {
            ruiL[i] = ruiL[i-1];
        }
        if(to == p) {
            continue;
        }
        ruiL[i] = dp1[to] * ruiL[i] % mod;
    }
    vl ruiR(G[v].size(), 1);
    for(ll i = G[v].size()-1; i >= 0; i--) {
        ll to = G[v][i];
        if(i+1 < (ll)G[v].size()) {
            ruiR[i] = ruiR[i+1];
        }
        if(to == p) {
            continue;
        }
        ruiR[i] = dp1[to] * ruiR[i] % mod;
    }
    rep(i, (ll)G[v].size()) {
        ll to = G[v][i];
        if(to == p) {
            continue;
        }
        ll x = 1;
        if(i-1 >= 0) {
            x = x * ruiL[i-1] % mod;
        }
        if(i+1 < (ll)G[v].size()) {
            x = x * ruiR[i+1] % mod;
        }
        dp2[to] = (x * dp2[v] + 1) % mod;
        dfs2(to, v);
    }
}

void dfs3(ll v, ll p = -1) {
    // 行きの処理はこのへんに書く
    ans[v] = dp2[v];
    for(ll to : G[v]) {
        if(to == p) {
            continue;
        }
        ans[v] = ans[v] * dp1[to] % mod;
        dfs3(to, v);
        // 帰りの処理はこのへんに書く
    }
}

int main() {
    
    cin >> n >> mod;    
    
    G.resize(n);
    rep(i, n-1) {
        ll x, y;
        cin >> x >> y;
        x--;  y--;
        G[x].pb(y);
        G[y].pb(x);
    }

    dp1.resize(n);
    dp2.resize(n);
    ans.resize(n);
    dfs1(0);
    dfs2(0);
    dfs3(0);

    rep(v, n) {
        out(ans[v]);
    }

    re0;
}

Measured memory_bytes: 21296
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;

int main(){
  int n,q;
  int x[100010];
  for(int r=0;r<100010;r++){
    x[r]=0;
  }
  cin>>n>>q;
  string s;
  cin>>s;
  pair<int,int> len[q];
  for(int i=0;i<q;i++){
    cin>>len[i].first>>len[i].second;
  }
  for(int i=1;i<=s.size();i++){
    if(s[i-1]=='A' and s[i]=='C')
    x[i]=1+x[i-1];
    else
    x[i]+=x[i-1];
  }
  for(int i=0;i<q;i++){
    cout<<x[len[i].second-1]-x[len[i].first-1]<<endl;
  }
}


Measured memory_bytes: 2176
#include <stdio.h>
int BubbleSort(int *a,int b);

int main(int argc, const char * argv[]) {
    int a[100],n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    printf("%d\n",BubbleSort(&a,n));
}

int BubbleSort(int *a,int n){
    int i,tmp,count=0 ;
    int flag = 1;
    
    while(flag){
        flag=0;
        for(i=n-1;i>=1;i--){
            if(a[i]<a[i-1]){
                count++;
                tmp=a[i];
                a[i]=a[i-1];
                a[i-1]=tmp;
                flag=1;
            }
        }
    }
    for(i=0;i<n-1;i++){
        printf("%d ",a[i]);
    }
    printf("%d\n",a[i]);
    return count;
}


Measured memory_bytes: 2136
#include<iostream>
#include<cstdio>
using namespace std;
int n,a,b;
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	if(b-a==0)
	{
		puts("Alice");
		return 0;
	}
	if((b-a)%2==1)
		puts("Borys");
	else
		puts("Alice");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <limits>
using namespace std;
using ull = unsigned long long int;

ull f(ull a, ull b)
{
    auto g = [](ull x) {
        int cnt;
        for (cnt = 0; x != 0; cnt++)
        {
            x = x / 10;
        }
        return cnt;
    };
    return max(g(a), g(b));
}

int main()
{
    ull N;
    cin >> N;
    vector<std::pair<ull, ull>> p;

    for (ull i = 1; i * i <= N; i++)
    {
        if (N % i == 0)
        {
            if (i > N / i)
                break;
            p.emplace_back(i, N / i);
        }
    }

    ull m = 11;
    for (const auto &i : p)
    {
        m = min(m, f(i.first, i.second));
    }

    cout << m << endl;
}

Measured memory_bytes: 3604
// すべての操作は独立していて、順番は関係ない
// また、おなじ操作を二回以上行う必要はなく、それらは0回/1回の操作と等しい
// よって、0<=i<=N, 0<=j<=Mの全ての(i,j)に対して、
// i行をフリップ、j列をフリップさせたときの黒マスの数を調べ、それがKに等しくなるかどうか調べる
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int N, M, K;
int black(int i, int j) {
    return (N-i)*j + i*(M-j);
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;
 
int main()
{
  char a,b;
  cin >> a>>b;
  if(a == b) cout << "H" << endl;
  else cout << "D" << endl;
  return 0;
}


Measured memory_bytes: 3544
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
bool bfs(vector<vi>& edges){
    int N=edges.size();
    queue<int> q;
    q.push(0);
    REP(i,2){
        queue<int> tmp;
        while(!q.empty()){
            int u = q.front(); q.pop();
            for(auto v:edges[u]){
                tmp.push(v);
                if (v==N-1) return true;
            }
        }
        q = tmp;
    }
    return false;
    
}
//fixed<<setprecision(10)<<ans<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vector<vi> edges(N);
    REP(i,M){
        int a,b;
        cin >> a >> b;
        a--;b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    
    bool ok = bfs(edges);
    if(ok) cout <<"POSSIBLE\n";
    else cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 12784
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <cstdio>
using Int = long long;
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
int main()
{
    int A, B; cin >> A >> B;
    cout << (A + B) % 24 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		if(N%3!=0) {
			for(int i=0; i<N; i++) {
				int a = in.nextInt();
				if(a != 0) {
					System.out.println("No");
					return;
				}
			}
			System.out.println("Yes");
			
		}else {
			int[] list = new int[3];
			int[] count = new int[3];
			list[0] = list[1] = list[2] = -1;
			for(int i=0; i<N; i++) {
				int a = in.nextInt();
				for(int j=0; j<3; j++) {
					if(list[j] == -1) {
						list[j] = a;
						count[j] ++;
						break;
					}else if(list[j] == a) {
						count[j] ++;
						break;
					}
					if(j==2) {
						System.out.println("No");
						return;
					}
				}
			}
			if(list[1] == -1 && list[0] == 0 ||
				list[2] == -1 && (list[0] == 0 && count[0] == N/3 || list[1] == 0 && count[1] == N/3) ||
				count[0]==count[1] && count[1]==count[2] && (list[0]^list[1]) == list[2]
			) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}

	public static void main(String[] args) {
		new Main().solve();
	}
}

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

typedef long long int ll;
typedef pair<ll, ll> P;

ll A, B, C, X;

int main(){
    cin >> A >> B >> C >> X;

    ll ans = 0;
    for(int i=0;i<=A;i++){
        for(int j=0;j<=B;j++){
            for(int k=0;k<=C;k++){
                if(X == 500*i + 100*j + 50*k)   ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int n,m,x,k;
    int a[105];
    scanf("%d%d%d",&n,&m,&x);
    memset(a,0,sizeof(a));
    for (int i=1;i<=m;i++) { scanf("%d",&k); a[k]=1; }
    a[n]=0;
    int sum=0,sun=0;
    for (int i=x;i<=n;i++) sum+=a[i];
    for (int i=x;i>=0;i--) sun+=a[i];
    printf("%d\n",min(sum,sun));
    return 0;
}


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

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

// ***************************************


int main(void) {

	int N;
	cin >> N;

	vector<int> X(N);
	for (auto& x : X) {
		cin >> x;
	}

	ll min_cost = 1e+10;
	FOR(i, 1, 101) {
		ll cost = 0;
		for (auto& x : X) {
			cost += pow(x - i, 2);
		}
		chmin(min_cost, cost);
	}

	cout << min_cost << endl;

	
	return 0;
}

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

int main(void)
{
  string a;
  cin >> a;
  int b = atoi(a.substr(0, 4).c_str());
  int c = atoi(a.substr(5, 2).c_str());
  if (c < 5)
    cout << "Heisei";
  else
    cout << "TBD";
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace C___Forbidden_List2
{
    public class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine();
            var b = Console.ReadLine();
            Console.WriteLine(DoMain(a, b));
        }

        public static int DoMain(string a, string b)
        {
            var c = a.Split(" ").Select(x => int.Parse(x)).ToList();
            var x = c[0];
            var n = c[1];
            if (n == 0)
            {
                return x;
            }

            var p = b.Split(" ").Select(x => int.Parse(x)).ToList();

            if (!p.Contains(x))
            {
                return x;
            }

            int i = 1;
            int count = 1;
            while (true)
            {
                if (count % 2 == 1)
                {
                    if(!p.Contains(x - i)) return x - i;
                }
                else
                {
                    if (!p.Contains(x + i)) return x + i;
                    i++;
                }
                count++;
            }
        }
    }
}


Measured memory_bytes: 28284
n,m=map(int,input().split())
pair=[]
uf = [-1]*(n+1)

def root(x):
        if uf[x]<0: 
                return x
        else: 
                uf[x]=root(uf[x])
                return uf[x]

def issame(x,y):
        return root(x)==root(y)

def unite(x,y):
        x=root(x)
        y=root(y)
        if x==y:
                return False
        if uf[x]>uf[y]:
                x,y=y,x
        uf[x]+=uf[y]
        uf[y]=x
        return True

def size(x):
        return -uf[root(x)]


ans=[n*(n-1)//2]

for _ in range(m):
        a,b=map(int,input().split())
        pair.append((a,b))

for i,p in enumerate(reversed(pair)):
        if not issame(p[0],p[1]):               
                ans.append(ans[i]-size(p[0])*size(p[1]))
                unite(p[0],p[1])    
        else:
                ans.append(ans[i])

ans.reverse()
for i in range(m):
        print(ans[i+1])
                

Measured memory_bytes: 22592
# -*- coding: utf-8 -*-

from heapq import heappush, heappop

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

# A日後、報酬B
# 日付ごとに報酬をリスト化
workList = {}
for i in range(n):
    a, b = map(int, input().split())
    if a not in workList:
        workList[a] = [b]
    else:
        workList[a].append(b)

hq = []
sum = 0
for i in range(1, m + 1):
    # 日付が短い順にheapに追加
    # 最大値を取り出すため正負は逆に
    if i in workList:
        for w in workList[i]:
            heappush(hq, -w)

    # 最大値を取り出し、正負を戻して加算
    if len(hq) > 0:
        val = heappop(hq)
        sum += -val

print(sum)


Measured memory_bytes: 26072
#include<iostream>
using namespace std;
int checkSorted(int n, int arr[])
{
  int first=0,second=0;
  int count=0;
  for(int i=1;i<n;i++)
  {
    if(arr[i]<arr[i-1])
    {
      count++;
      if(first==0)
        first=i;
      else
        second=i;
    }
  }
  if(count>2)
    return false;
  if(count==0)
    return true;
  if(count==2)
    swap(arr[first-1],arr[second]);
  else if(count==1)
    swap(arr[first-1],arr[first]);
  for(int i=1;i<n;i++)
    if(arr[i]<arr[i-1])
      return false;
  return true;
}
int main() 
{ 
    int n; 
  	cin>>n;
  	int arr[n];
    for(int i=0;i<n;i++)
    {
      cin>>arr[i];
    }
    if(checkSorted(n,arr))
      cout<<"YES";
  	else
      cout<<"NO";
    return 0; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int main()
{
	IO_OP;
	
	string s;
	cin >> s;
	for(int i=0;i<3;i++)
		if(s[i] == s[i+1]) {
			cout << "Bad" << endl;
			return 0;
		}
	cout << "Good" << endl;
}



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

int main(){
    int N, L;
    cin >> N >> L;
    int res = 0;
    int diff = INT_MAX;
    int m = 0;

    for(int i=0;i<N;i++){
        int f = L + i;
        if(abs(f) < diff){
            m = f;
            diff = abs(f);
        }
        res += f;
    }
    res -= m;

    cout << res  << endl;

    return 0;
}

Measured memory_bytes: 888
#include <stdio.h>

int calc_digit(int);

int main(){
	int a,b;

	while(1){
		if(scanf("%d %d" ,&a,&b) == EOF){
			break;
		}
		printf("%d\n",calc_digit(a+b));
	}

	return 0;
}

int calc_digit(int num){
	int digit=0;

	while(1){
		num /= 10;
		digit++;
		if(num == 0){
			break;
		}
	}

	return digit;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
using ll = long long;
using namespace std;

void solve() {
   string s;
   cin >> s;
   int diff = INT_MAX;
   for(int i = 0; i + 2 < s.length(); i++) {
      diff = min(diff, abs(753 - stoi(s.substr(i, 3))));
   }
   cout << diff << endl;
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define MOD 1000000007
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,M;
int S,T;
int U[200100],V[200100],D[200100];
ll d[100100];
ll fS[100100],fT[100100];
vector<P> g[100100];
priority_queue<P,vector<P>,greater<P> > q;
bool used[100100];
int main(){
	scanf("%d %d",&N,&M);
	scanf("%d %d",&S,&T);
	S--;T--;
	for(int i=0;i<M;i++){
		scanf("%d %d %d",&U[i],&V[i],&D[i]);
		U[i]--;V[i]--;
		g[U[i]].pb(P(V[i],D[i]));
		g[V[i]].pb(P(U[i],D[i]));
	}
	for(int i=0;i<N;i++){
		d[i]=LLINF;
	}
	d[S]=0ll;
	q.push(P(0ll,S));
	while(!q.empty()){
		P a = q.top();
		q.pop();
		int v = a.sec;
		if(d[v]<a.fi)continue;
		for(int i=0;i<g[v].size();i++){
			int to = g[v][i].fi;
			ll cost = g[v][i].sec;
			if(d[to]>d[v]+cost){
				d[to]=d[v]+cost;
				q.push(P(d[to],to));
			}
		}
	}
	/*for(int i=0;i<N;i++){
		cout << d[i] << ' ';
	}
	cout << endl;*/
	fS[S]=1ll;
	for(int i=0;i<N;i++)q.push(P(d[i],i));
	while(!q.empty()){
		P a = q.top();
		q.pop();
		int v = a.sec;
		for(int i=0;i<g[v].size();i++){
			int to = g[v][i].fi;
			ll cost = g[v][i].sec;
			if(d[to]==d[v]+cost){
				fS[to]=(fS[to]+fS[v])%MOD;
			}
		}
	}
	fT[T]=1ll;
	for(int i=0;i<N;i++)q.push(P(-d[i],i));
	while(!q.empty()){
		P a = q.top();
		q.pop();
		int v = a.sec;
		for(int i=0;i<g[v].size();i++){
			int to = g[v][i].fi;
			ll cost = g[v][i].sec;
			if(d[to]==d[v]-cost){
				fT[to]=(fT[to]+fT[v])%MOD;
			}
		}
	}
	/*for(int i=0;i<N;i++){
		cout << fS[i] << ' ';
	}
	cout << endl;
	for(int i=0;i<N;i++){
		cout << fT[i] << ' ';
	}
	cout << endl;*/
	ll ans = (fS[T]*fS[T])%MOD;
	for(int i=0;i<N;i++){
		if(d[i]*2ll!=d[T])continue;
		ll t1 = (fS[i]*fS[i])%MOD;
		ll t2 = (fT[i]*fT[i])%MOD;
		ans = (ans+MOD-(t1*t2)%MOD)%MOD;
	}
	for(int i=0;i<M;i++){
		int u = U[i],v = V[i],c = D[i];
		if(d[u]>d[v])swap(u,v);
		if(d[u]+c!=d[v])continue;
		if(2ll*d[u]<d[T]&&2ll*d[v]>d[T]){
			ll t1 = (fS[u]*fS[u])%MOD;
			ll t2 = (fT[v]*fT[v])%MOD;
			ans = (ans+MOD-(t1*t2)%MOD)%MOD;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

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

int main() {
    int n; cin >> n;
    ll a[n+1]; rep(i,n+1) cin >> a[i];
    ll b[n]; rep(i,n) cin >> b[i];
    ll ans = 0;
    ll j = 0;
    rep(i,n) {
        // bi->ai
        j = min(a[i],b[i]);
        ans += j;
        a[i] -= j;
        b[i] -= j;
        // bi->ai+1
        j = min(a[i+1],b[i]);
        ans += j;
        a[i+1] -= j;
        b[i] -= j;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5168
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

  long long N;
  cin >> N;

  long long ans = N;
  for(long long i = 1; i <= sqrt(N); ++i) {
    if(N % i == 0) {
      ans = (i - 1) + ((N / i) - 1);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    string zo = string(a, '0') + string(w-a, '1');
    string oz = string(a, '1') + string(w-a, '0');
    rep(i, h) cout << (i<b ? zo : oz) << endl;
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int m = in.nextInt();
			int[][] path = new int[n+1][n+1];
			for (int i = 0; i < m; i++) {
				int a = in.nextInt();
				int b = in.nextInt();
				path[a][b]++;
				path[b][a]++;
			}
			for (int i = 1; i <= n; i++) {
				int count = 0;
				for (int j = 1; j <= n; j++) {
					count += path[i][j];
				}
				out.println(count);
			}
		}

	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}

	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}
}


Measured memory_bytes: 21460
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int dp[ten5];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,small=0;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0,now=0;
    //vector <int> v;
    //float f,g,h;
    //char now,pre;
    //string a;
    cin>>n;
    dp[0]=0;
    for(i=1;i<=n;i++)
    {
        dp[i]=dp[i-1]+1;
        for(j=1;j<=i;j*=6) dp[i]=min(dp[i],dp[i-j]+1);
        for(j=1;j<=i;j*=9) dp[i]=min(dp[i],dp[i-j]+1);
    }
    cout<<dp[n];
    return 0;
}





Measured memory_bytes: 640
class UnionFind:
    # 初期化
    def __init__(self, n):
        # 根なら-size, 子なら親の頂点
        self.par = [-1] * n
        # 木の高さ
        self.rank = [0] * n

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

    # 併合
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 異なる集合に属する場合のみ併合
        if x != y:
            # 高い方をxとする。
            if self.rank[x] < self.rank[y]:
                x,y = y,x
            # 同じ高さの時は高さ+1
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            # yの親をxとし、xのサイズにyのサイズを加える
            self.par[x] += self.par[y]
            self.par[y] = x

    # 同集合判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 集合の大きさ
    def size(self, x):
        return -self.par[self.find(x)]

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

# 必要
c = sorted(a)
d = sorted(b)
for i in range(n):
    if c[i]>d[i]:
        print('No')
        exit()

for i in range(n-1):
    if c[i+1]<=d[i]:
        print('Yes')
        exit()

for i in range(n-1):
    if c[i]==c[i+1]:
        print('Yes')
        exit()
    if d[i]==d[i+1]:
        print('Yes')
        exit()

# 理想と現実の対応
e = {}
f = {}
for i in range(n):
    e[c[i]]=d[i]
    f[a[i]]=b[i]

# 理想と現実の対応の逆
ee = {v: k for k, v in e.items()}
ff = {v: k for k, v in f.items()}

for x in a:
    if e[x]==f[x]:
        print('Yes')
        exit()

z = [0]*n
u = UnionFind(n)

g = {}
for i in range(n):
    g[a[i]]=i

for i in range(n):
    if z[i]==1:
        continue
    x = a[i]
    y = f[x]
    j = i
    while z[j]==0:
        z[j]=1
        x = ee[y]
        y = f[x]
        jj = g[x]
        u.unite(j,jj)
        j=jj

for i in range(n):
    if u.same(0,i)==False:
        print('Yes')
        exit()


print('No')

Measured memory_bytes: 120516
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main()
    {
        string[] inputSplit = ReadLine().Split(' ');

        int A = int.Parse(inputSplit[0]);
        int B = int.Parse(inputSplit[1]);
        int C = int.Parse(inputSplit[2]);
        int D = int.Parse(inputSplit[3]);
        int downTimeBothSwitch = 0;
        int upTimeBothSwitch = 0;
        int result = 0;

        if (B - C <= 0 || D - A <= 0) WriteLine("0");
        else
        {
            if (A < C) downTimeBothSwitch = C;
            else downTimeBothSwitch = A;
            if (B <= D) upTimeBothSwitch = B;
            else upTimeBothSwitch = D;
            WriteLine(upTimeBothSwitch - downTimeBothSwitch);
        }
    }
}

Measured memory_bytes: 11092
x, y = map(int, input().split())
if (2*x-y)%3 != 0 or (2*y-x)%3 != 0:
    print(0)
    exit()

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


a = (2*x-y)//3
b = (2*y-x)//3
n = a+b
r = a
res = cmb(n,r,mod)
print(res)


Measured memory_bytes: 124544
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    s = [True if s == "o" else False for s in list(str(input().rstrip('\n')))]
    ls = [[0] * n for _ in range(4)]
    ls[0][0] = False
    ls[0][1] = False
    ls[1][0] = False
    ls[1][1] = True
    ls[2][0] = True
    ls[2][1] = False
    ls[3][0] = True
    ls[3][1] = True
    for i in range(1, n-1):
        ls[0][i+1] = (s[i] == ls[0][i]) == ls[0][i-1]
        ls[1][i+1] = (s[i] == ls[1][i]) == ls[1][i-1]
        ls[2][i+1] = (s[i] == ls[2][i]) == ls[2][i-1]
        ls[3][i+1] = (s[i] == ls[3][i]) == ls[3][i-1]
    for i in range(4):
        if (s[-1] == ls[i][-1] and ls[i][0] == ls[i][-2]) or (s[-1] != ls[i][-1] and ls[i][0] != ls[i][-2]):
            if (s[0] == ls[i][0] and ls[i][1] == ls[i][-1]) or (s[0] != ls[i][0] and ls[i][1] != ls[i][-1]):
                print("".join(["S" if ls[i][j] else "W" for j in range(n)]))
                exit()
    print(-1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 66572
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-3;

typedef pair<int, int> P;

int main()
{
	int n, m;
	while (cin >> n, n) {
		vector<int> X(n + 1), Y(n + 1);
		for (int i = 0, b; i < n; i++) {
			cin >> b;
			cin >> X[b] >> Y[b];

		}

		vector< vector< pair<double, int> > > bld(n + 1);
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (i != j && (X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]) <= 2500) {
					bld[i].push_back(P(sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j])), j));
					bld[j].push_back(P(sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j])), i));
				}
			}
		}
		cin >> m;
		for (int i = 0, s, g; i < m; i++) {
			cin >> s >> g;
			vector<bool> dec(n + 1, false);
			vector<double> ans(n + 1);
			priority_queue< pair<double, int> > pq;
			pq.push(pair<double, int>(0.0, -s));
			while (!pq.empty()) {
				const int num = -pq.top().second;
				ans[num] = -pq.top().first;
				dec[num] = true;
				for (auto da : bld[num]) {
					if(!dec[da.second])
						pq.push(pair<double, int>(-ans[num] - da.first, -da.second));
				}
				while (!pq.empty() && dec[-pq.top().second]) pq.pop();
			}
			if (dec[g]) {
				int tmp = g;
				vector<int> a;
				a.reserve(n);
				while (tmp != s) {
					for (auto da : bld[tmp]) {
						if (ans[da.second] <= ans[tmp] - da.first + eps && ans[da.second] >= ans[tmp] - da.first - eps) {
							a.push_back(tmp);
							tmp = da.second;
							break;
						}
					}
				}
				cout << s;
				for (int j = a.size() - 1; j >= 0; j--)
					cout << " " << a[j];
				cout << endl;
			}
			else
				cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3060
s = list(input())
ans = 100
n = len(s)
q = list(set(s))
for _ in q:
    x = _
    m = n - 1
    t = list(s)
    r = ['0'] * m
    while len(set(t)) > 1:
        for i in range(m):
            if t[i] == x or t[i+1] == x:
                r[i] = x
            else:
                r[i] = t[i]
        m -= 1
        t = list(r)
        r = ['0'] * m
    ans = min(ans,n-len(t))
print(ans)

Measured memory_bytes: 9004
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
signed main() {
	int h, a, b;
	cin >> h >> a >> b;
	int ans = 0;
	for (int i = a; i <= b; i++) 
		if (!(h%i))ans++;
	cout << ans << endl;
}


Measured memory_bytes: 3104
import sys
inputs = sys.stdin.readlines()
from fractions import gcd
from operator import mul
from functools import reduce
lcm = lambda x, y: x*y // gcd(x, y)

n, m = map(int, inputs[0].split())
A = list(map(int, inputs[1].split()))
g = reduce(gcd, A)
if all((a // g) % 2 for a in A):
    print(round((m+1) / reduce(lcm, A)))
else:
    print(0)

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

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

    int n, h, w;
    cin >> n >> h >> w;

    cout << (n-h+1) * (n-w+1) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Fouradjacent solver = new Fouradjacent();
        solver.solve(1, in, out);
        out.close();
    }

    static class Fouradjacent {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int is_two = 0;
            int is_four = 0;
            int is_one = 1;
            for (int i = 0; i < n; i++) {
                long a = in.nextLong();
                if (a % 4 == 0) {
                    is_four++;
                } else if (a % 2 == 0) {
                    is_two++;
                } else {
                    is_one++;
                }
            }
            if (n % 2 == 0) {
                int zan = n - (is_four * 2);
                if (zan <= 0) {
                    out.print("Yes");
                    return;
                }
                if (zan <= is_two) {
                    out.print("Yes");
                    return;
                }
            } else {
                int zan = (n - 1) - (is_four * 2);
                if (zan <= 0) {
                    out.print("Yes");
                    return;
                }
                zan++;
                if (zan <= is_two) {
                    out.print("Yes");
                    return;
                }
            }
            out.print("No");
        }

    }
}



Measured memory_bytes: 59488
class Map(dict):
    def __missing__(self, key):
        default_value = 0
        self[key] = default_value
        return default_value


def main():
    int(input())

    d = Map()
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        d[i + height] += 1
        ans += d[i - height]

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 67312
import Control.Applicative
import Data.List
import Control.Monad
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    [a, b] <- map strToInt . words <$> getLine

    -- 出力
    let x =  if odd (a + b) then (a + b + 1) `div` 2 else (a + b) `div` 2
    putStrLn $ show x


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

using namespace std;

int main(){

    int A, B, C, X;

    int count = 0;
    int sum;

    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;

    for(int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                sum = 500 * i + 100 * j + 50 * k;
                if(sum == X) count++;

            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
n=int(input())
s=input()
a=[1 if i=='(' else -1 for i in s]
e=[0]
for i in range(n):
    e.append(e[i]+a[i])
s=-min(e)*'('+s
s+=(s.count('(')-s.count(')'))*')'
print(s)
#print(e)

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/abc094_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, M, X;
  cin >> N >> M >> X;
  
  vector<int> c(N, 0);
  rep(i, M) {
    int a;
    cin >> a;
    c[a] = 1;
  }

  ll a = 0;
  rep(i, X) { a += c[i]; }
  ll b = 0;
  repi(i, X, N) { b += c[i]; }

  cout << min(a, b) << endl;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApplication6
{
    class Program0824
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();

            int n = int.Parse(a);


            int[] s = new int[13];
            int[] h = new int[13];
            int[] c = new int[13];
            int[] d = new int[13];

            for (int i = 0; i < n; i++)
            {
                string[] ss = Console.ReadLine().Split(' ');
                string mark = ss[0];
                int rank = int.Parse(ss[1]);

                if (mark == "S")
                {
                    s[rank - 1] = 1;

                }
                if (mark == "H")
                {
                    h[rank - 1] = 1;

                }

                if (mark == "C")
                {
                    c[rank - 1] = 1;

                }
                if (mark == "D")
                {
                    d[rank - 1] = 1;

                }

            }
            for (int one = 0; one < 13; one++)
            {
                if (s[one] != 1)
                {
                    Console.WriteLine("S " + (one + 1));
                }

            }
            for (int two = 0; two < 13; two++)
            {
                if (h[two] != 1)
                {
                    Console.WriteLine("H " + (two + 1));
                }
            }
            for (int three = 0; three < 13; three++)
            {
                if (c[three] != 1)
                {
                    Console.WriteLine("C " + (three + 1));
                }
            }
            for (int four = 0; four < 13; four++)
            {
                if (d[four] != 1)
                {
                    Console.WriteLine("D " + (four + 1));
                }
            }


        }
    }
}

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

string print(string str, int a, int b){
  return str.substr(a, b-a+1);
}

string reverse(string str, int a, int b){
  string sub;
  for (int i = 0; i < b-a+1; i++) {
    sub[i] = str[b-i];
  }
  for (int i = 0; i < b-a+1; i++) {
    str[a+i] = sub[i];
  }
  return str;
}

string replace(string str, int a, int b, string p){
  return str.replace(a, b-a+1, p);
}

int main() {
  int q;
  string str;

  cin >> str;
  cin >> q;

  for (int i = 0; i < q; i++) {
    int a, b;
    string command, p;
    cin >> command;
    if (command == "print"){
      cin >> a >> b;
      cout << print(str, a, b) << endl;
    }
    else if (command == "reverse"){
      cin >> a >> b;
      str = reverse(str, a, b);
    }
    else if (command == "replace"){
      cin >> a >> b >> p;
      str = replace(str, a ,b ,p);
    }
  }
  return 0;
}

Measured memory_bytes: 3224
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
int N,K;
bool f[11];
int main()
{
	while(scanf("%d%d",&N,&K)!=EOF)
	{
		memset(f,1,sizeof(f));
		int xx;
		for(int i=1;i<=K;i++)
		{
			scanf("%d",&xx);
			f[xx]=0;
		}
		int i=N;
		while(1)
		{
			int now=i;
			bool ff=0;
			while(now>0)
			{
				if(!f[now%10])
				{
					ff=1;
					break;
				}
				now/=10;
			}
			if(!ff) break;
			i++;
		}
		printf("%d\n",i);
	}
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	int q = read.to!int;
	
	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i);
	
	foreach(i; 0 .. n - 1){
		int a = read.to!int - 1;
		int b = read.to!int - 1;
		nodes[a].nodes ~= nodes[b];
		nodes[b].nodes ~= nodes[a];
	}
	
	nodes[0].treefy(null);
	
	foreach(t; 0 .. q){
		int p = read.to!int - 1;
		long x = read.to!long;
		nodes[p].value += x;
	}
	
	nodes[0].calc;
	
	nodes.map!(x => x.value.to!string).join(" ").writeln;
}

class Node{
	int id;
	long value;
	Node[] nodes;
	Node[] kids;
	Node parent;
	bool isTreefied;
	this(int id){
		this.id = id;
	}
	void treefy(Node par){
		this.isTreefied = 1;
		if(par) this.parent = par;
		foreach(nd; this.nodes){
			if(nd.isTreefied) continue;
			else{
				this.kids ~= nd;
				nd.treefy(this);
			}
		}
	}
	void calc(){
		foreach(kid; this.kids){
			kid.value += this.value;
			kid.calc;
		}
	}
}


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

typedef long long ll;
const int INF = 1e9;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int rEat, gEat, red, green, white;
	cin>>rEat>>gEat>>red>>green>>white;
	vector<int> rA(red);
	vector<int> gA(green);
	vector<int> wA(white);
	for (int i = 0; i < red; i++) {
		cin>>rA[i];
	}
	for (int i = 0; i < green; i++) {
		cin>>gA[i];
	}
	for (int i = 0; i < white; i++) {
		cin>>wA[i];
	}
	sort(rA.begin(), rA.end(), greater<int>());
	sort(gA.begin(), gA.end(), greater<int>());
	sort(wA.begin(), wA.end(), greater<int>());
	if (rEat < red){
		rA.erase(rA.begin() + rEat, rA.end());
	}
	if (gEat < green){
		gA.erase(gA.begin() + gEat, gA.end());
	}
	// cout<<rA.size()<<' '<<gA.size()<<'\n';
	wA.resize(white + rEat + gEat);
	copy(rA.begin(), rA.end(), wA.begin() + white);
	copy(gA.begin(), gA.end(), wA.begin() + white + rEat);
	sort(wA.begin(), wA.end(), greater<int>());
	ll ans = 0;
	for (int i = 0; i < rEat+gEat; i++) {
		ans+=wA[i];
		// cout<<wA[i]<<'\n';
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int x,y,z; cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}



Measured memory_bytes: 256
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005

int main()
{
    fastread;
    int l, r, d;
    cin>>l>>r>>d;
    int ans = r/d - ((l - 1)/d);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<set>
#include<map>
#include<queue>
#define mp make_pair
#define pi pair<int,int>
using namespace std;
inline 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;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
set<int>::iterator it;
queue<pi>q;
set<int>p[100010];
map<pi,int>ap;
int fa[100010];
inline int findfa(int x)
{
	if(fa[x]!=x)fa[x]=findfa(fa[x]);
	return fa[x];
}
inline pi make(int x,int y){if(x>y)swap(x,y);return mp(x,y);}
inline void ins(int x,int y)
{
	p[x].insert(y);p[y].insert(x);
	pi uf=make(x,y);ap[uf]++;
	if(ap[uf]==2)q.push(uf);
}
inline void del(int x,int y){ap.erase(mp(x,y)),p[y].erase(x);}
int main()
{
    //freopen("a.in","r",stdin);
	//freopen("a.in","w",stdout);
	int n=read();
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<2*n-1;i++)
	{
		int x=read(),y=read();
		ins(x,y);
	}n--;
	bool bk=true;
	while(n--)
	{
		int x,y;
		while(1)
		{
			if(q.empty()){bk=false;break;}
			pi uf=q.front();q.pop();
			x=findfa(uf.first),y=findfa(uf.second);
			if(x!=y)break;
		}
		if(bk==false)break;
		if(p[x].size()>p[y].size())swap(x,y);
		fa[x]=y;del(x,y);
		for(it=p[x].begin();it!=p[x].end();it++)
		{
			int pl=findfa(*it);
			if(pl==y)continue;
			del(x,pl),ins(pl,y);
		}
	}
	if(bk==false)puts("NO");
	else puts("YES");
    return 0;
}

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

int main() {
  int x, y; cin>>x>>y;
  int ans=2e9+1;
  for (int i=-1; i<=1; i+=2) {
    for (int j=-1; j<=1; j+=2) {
      int X=x*i, Y=y*j;
      if (X>Y) continue;
      ans=min(ans, Y-X+(i==-1)+(j==-1));
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int H,W;
  cin >> H >> W;
  int a[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }
  vector<pair<P,P>> ans;
  for (int i = 0; i < H - 1; i++) {
    for (int j = 0; j < W; j++) {
      if (a[i][j] % 2 == 1) {
        ans.push_back(make_pair(make_pair(i,j),make_pair(i+1,j)));
        a[i][j] -= 1;
        a[i+1][j] += 1;
      }
    }
  }
  for (int i = 0; i < W - 1; i++) {
    if (a[H-1][i] % 2 == 1) {
      ans.push_back(make_pair(make_pair(H-1,i),make_pair(H-1,i+1)));
      a[H-1][i] -= 1;
      a[H-1][i+1] += 1;
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first.first + 1 << " " << ans[i].first.second + 1 << " " << ans[i].second.first + 1 << " " << ans[i].second.second + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 5104
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
  string a;
  while(getline(cin,a)){
    if(a[0]=='.')break;
    stack<char> b;
    int c=0;
    for(int i=0;i<a.size();i++){
      if(a[i]=='['||a[i]=='(')b.push(a[i]);
      if(a[i]==']'||a[i]==')'){
        if(b.empty())c++;
        else if((b.top()=='['&&a[i]==']')||(b.top()=='('&&a[i]==')'))b.pop();
        else c++;
      }
    }
    if(c==0&&b.empty())cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

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

int main() {
  int32_t n, k;
  std::cin >> n >> k;

  std::vector<int32_t> p(n);
  for (int32_t i = 0; i < n; ++i) {
    std::cin >> p.at(i);
  }

  std::sort(p.begin(), p.end());

  int32_t sum = 0;
  for (int32_t i = 0; i < k; ++i) {
    sum += p.at(i);
  }

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


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
int n, e, par[maxn], cnt[maxn];
void make_set()
{
    for(int i=1; i<=n; i++) par[i]=i;
}
int find_rep(int u)
{
    if(par[u]==u) return u;
    return par[u] = find_rep(par[u]);
}
void make_union(int u, int v)
{
    u = find_rep(u);
    v = find_rep(v);
    if(u!=v) par[v]=u;
}
int main()
{
    cin>>n>>e;
    make_set();
    for(int i=1; i<=e; i++){
        int u, v;
        cin>>u>>v;
        make_union(u, v);
    }
    int ans=0;
    for(int i=1; i<=n; i++){
        int id = find_rep(i);
        cnt[id]++;
        ans = max(ans, cnt[id]);
    }
    cout<<ans;
}

Measured memory_bytes: 5068
#include <iostream>
using namespace std;
bool makeTriangle(int l1, int l2, int l3) {
    bool result;
    if (l1 == l2 || l2 == l3 || l3 == l1) {
        return false;
    }
    if (l1+l2>l3 && l2+l3>l1 && l3+l1>l2) {
        return true;
    } else {
        return false;
    }
}
int main() {
    int n;
    cin >> n;
    int l[n];
    for (int i=0; i<n; i++) {
        cin >> l[i];
    }
    int cnt = 0;
    for (int i=0; i<n-2; i++) {
        for (int j=i+1; j<n-1; j++) {
            for (int k=j+1; k<n; k++) {
                if (makeTriangle(l[i], l[j], l[k])) cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632