akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int r,g;cin>>r>>g;
    cout<<2*g-r<<endl;
}


Measured memory_bytes: 256
N, Q = [int(i) for i in input().split()]
S = input()
lr = []
for i in range(Q):
    l, r = input().split(" ")
    lr.append((int(l)-1, int(r)-1))
    
# i番目を含む右部分文字列中に"AC"が何回現れるか
c = [0 for _ in range(N)]
for i in range(N-1)[::-1]:
    if S[i] == "A" and S[i+1] == "C":
        c[i] = c[i+1] + 1
    else:
        c[i] = c[i+1]
        
for i in range(Q):
    l, r = lr[i]
    a = c[l] - c[r]
    print(a)

Measured memory_bytes: 19812
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
vector<int> ki[220000],even,odd,one,two,zero;

void dfs(int now,int last = -1,int dist = 0){
	if(dist%2)odd.push_back(now);
	else even.push_back(now);
	for(int next :ki[now]){
		if(next == last)continue;
		dfs(next,now,dist+1);
	}
}
int main()
{
	int n;
	cin >> n;
	vector<int> ans(n,0);
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		a--;b--;
		ki[a].push_back(b);
		ki[b].push_back(a);
	}
	dfs(0);
	int es = even.size();
	int os = odd.size();
	
	rep(i,n){
		if((i+1)%3 == 0)zero.push_back(i+1);
		else if((i+1)%3 == 1)one.push_back(i+1);
		else two.push_back(i+1);
	}
	
	
	if(es <= n/3){
		rep(i,es){
			ans[even[i]] = zero.back();
			zero.pop_back();

		}
		rep(i,os){
			if(two.size() > 0){
			    ans[odd[i]] = two.back();
				two.pop_back();
			}
			else if(one.size()> 0){
				ans[odd[i]] = one.back();
				one.pop_back();
			}
			else{
				ans[odd[i]] = zero.back();
				zero.pop_back();
			}
		}
		rep(i,n)cout << ans[i] << endl;

	
	}



	else if(os <= n/3){
		rep(i,os){
			ans[odd[i]] = zero.back();
			zero.pop_back();

		}
		rep(i,es){
			if(two.size() > 0){
			    ans[even[i]] = two.back();
				two.pop_back();
			}
			else if(one.size()> 0){
				ans[even[i]] = one.back();
				one.pop_back();
			}
			else{
				ans[even[i]] = zero.back();
				zero.pop_back();
			}
		}
		rep(i,n)cout << ans[i] << endl;
	
		

	}
	else{
		rep(i,os){
			if(one.size() > 0){
				ans[odd[i]] = one.back();
				one.pop_back();
			}
			else {
				ans[odd[i]] = zero.back();
				zero.pop_back();
			}
		}
		rep(i,es){
			if(two.size() > 0){
				ans[even[i]] = two.back();
				
				two.pop_back();
			}
			else {
				ans[even[i]] = zero.back();
				zero.pop_back();
			}
		}
		rep(i,n)cout << ans[i] << endl;


	}

	return 0;
}

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

//------------------------- DEBUGGING -----------------------------------------------------------------------
#ifdef DEBUG
#define debug( args... ) { vector<string> _v = split( #args, ','); err( _v.begin(), args); cerr << '\n'; }
vector<string> split( const string& s, char c) {
    vector<string> v;
    stringstream ss( s);
    string x;
    while ( getline( ss, x, c))
        v.emplace_back( x);
    return move( v);
}
void err( vector<string>::iterator it) { }
template<typename T, typename... Args>
void err( vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr( ( *it)[0] == ' ', it -> length()) << " = " << a << '\t';
    err( ++it, args...);
}
#else
#define debug(...)
#endif
//------------------------ MACROS ----------------------------------------------------------------------------

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define bck(i,j,k) for(i = j; i > (k); i--)
#define all(x) x.begin(), x.end()
#define el '\n'

typedef long long int ll;
typedef long double DO;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
//---------------------------  TEMPLATE ENDS, MAKE CHANGES FROM HERE ----------------------------------------

const int mod = 1e9+7;
const ll inf = 2e18;
const DO eps = 1e-9;
const int NN = 1e5 + 2;

vvi adj;
int ar[NN];

void solve(){
    int i = 0, j = 0, k = 0, n = 0, m = 0;
    cin>>i;
    if(i == 1){
        cout<<"Hello World"<<el;
    }
    else{
        
        cin>>j>>k;
    cout<<(j+k)<<el;
    }
}

int main(){
#ifndef DEBUG
    ios::sync_with_stdio(false); cin.tie(0); 
#endif
    int T = 1, tc;
    for(tc = 1; tc <= T; tc++){
        solve();
    }
    return 0;
}



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

class B
{
	static void Main()
	{
		var l = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var n = int.Parse(Console.ReadLine());
		Console.WriteLine(new string(Console.ReadLine().Select(c => l[(c - 'A' + n) % 26]).ToArray()));
	}
}


Measured memory_bytes: 13396
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector <int> vi;
typedef vector <string> vs;

string right(string &text, int n){
	int length = text.size();
	string tmp;
	tmp = text.substr(length-n, n);
	text = text.substr(0, length-n);
	return tmp;
}

long str2lng(string text){
	stringstream ss;
	ss<<text;
	long tmp;
	ss>>tmp;
	return tmp;
}

string lng2str(long n){
	stringstream ss;
	ss<<n;
	string text;
	ss>>text;
	return text;
}

string lng2str8(long n){
	stringstream ss;
	ss<<setw(10)<<setfill ('0')<<n;
	string text;
	ss>>text;
	return text;
}

vi longstr2num(string text){
	vi buf;
	while (!text.empty()){
		if (text.size()>=8)
			buf.push_back(str2lng(right(text, 8)));
		else{
			buf.push_back(str2lng(text));
			text="";
		}
	}
	return buf;
}

int main(void){
	int n;
	cin>>n;
	for (int i=0; i<n; i++){
		string s1, s2;
		cin>>s1>>s2;
		vi tmp, tmp1 = longstr2num(s1), tmp2 = longstr2num(s2);
		int size1 = tmp1.size(), size2 = tmp2.size(), size=max(size1, size2);
		long s, c = 0;
		for (int j=0; j<size; j++){
			s = c;
			if (j<size1) s += tmp1[j];
			if (j<size2) s += tmp2[j];
			
			tmp.push_back(s%100000000);
			c = s / 100000000;
		}
		if (c != 0)	tmp.push_back(c);

		stringstream buf;
		for (int j=tmp.size()-1; j>=0; j--)
			if (j != tmp.size()-1)
				buf<<setfill('0')<<setw(8)<<tmp[j];
			else
				buf<<tmp[j];
		string str;
		buf>>str;
		if (str.size()>80) cout<<"overflow"<<endl;
		else cout<<str<<endl;
	}
	return 0;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<40)
#define mod 1000000007
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

int main(){
	ll n;cin>>n;
	vector<ll> h(n+1);
	rep(i,n) cin>>h[i];
	h[n]=INF;//sentinel

	ll dp[100100]={0};//i番目のマスまでで移動してくるときの最大移動回数
	
	ll ans=0;
	rep(i,n){
		if(h[i+1]<=h[i]){
			dp[i+1]=dp[i]+1;//右の方が小さいとき(もしくは同じ)
		}else{
			ans=max(ans,dp[i]);
			dp[i+1]=0;
		}
	}

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

Measured memory_bytes: 1792
nlist = input().split()
#nlist = [int(i) for i in a]
calc = []
c = int(0)

ans = int(0)

for i in nlist:
	#print(calc)
	if i == '+':
		for j in range(len(calc)-1,len(calc)-3,-1):
			ans += calc.pop(j)
		calc.append(int(ans))

	elif i == '-':
		ans -= calc.pop(len(calc)-1)
		ans += calc.pop(len(calc)-1)
		calc.append(int(ans))
	elif i == '*':
		ans = calc.pop(len(calc)-2) * calc.pop(len(calc)-1)
		calc.append(int(ans))

	else:
		calc.append(int(i))

	ans = 0
print(calc[0])




Measured memory_bytes: 5600
#include <cstdio>
#include <queue>
using namespace std;

bool getBit(){
	char c;
	for(;;){
		c=getchar();
		if(c=='0')return 0;
		if(c=='1')return 1;
	}
}
int modex(int b, int e, int m){
	int h = 1;
	while(e){
		if(e&1)
			h=(long long)h*b % m;
		b=(long long)b*b % m;
		e>>=1;
	}
	return h;
}
int main(){
	int n;
	scanf("%d", &n);
	vector <int> answerKey(1048576);
	answerKey[0]=0;
	for(int i = 1;i < 1048576;i ++){
		answerKey[i]=1+answerKey[i%__builtin_popcount(i)];
	}
	if(n<=20){
		int x=0;
		for(int i = 0;i < n;i ++)
			x=x*2+getBit();
		for(int i = n;i --;)
			printf("%d\n", answerKey[x^(1<<i)]);
		return 0;
	}
	vector <bool> x(n);
	int bits=0;
	for(int i = n;i --;){
		x[i]=getBit();
		bits+=x[i];
	}
	int aa=0;
	if(bits>=2){
		for(int i = n;i --;){
			aa=(aa*2+x[i])%(bits-1);
		}
	}
	int bb=0;
	for(int i = n;i --;){
		bb=(bb*2+x[i])%(bits+1);
	}
	vector <int> ps(n+1);
	ps[0]=0;
	for(int i = 0;i < n;i ++)
		ps[i+1]=ps[i]+x[n-1-i];
	for(int i = n;i --;){
		if(i>=20){
			if(x[i]){
				if(ps[n-20]-1==0){
					int X=0;
					for(int i = 20;i --;){
						X=X*2+x[i];
					}
					printf("%d\n", answerKey[X]);
				}else{
					printf("%d\n", 1+answerKey[(aa+(bits-1)-modex(2, i, bits-1))%(bits-1)]);
				}
			}else{
				printf("%d\n", 1+answerKey[(bb+modex(2, i, bits+1))%(bits+1)]);
			}
		}else{
			if(x[i]){
				if(ps[n-20]==0){
					int X=0;
					for(int i = 20;i --;){
						X=X*2+x[i];
					}
					X-=1<<i;
					printf("%d\n", answerKey[X]);
				}else{
					printf("%d\n", 1+answerKey[(aa+(bits-1)-modex(2, i, bits-1))%(bits-1)]);
				}
			}else{
				if(ps[n-20]==0){
					int X=0;
					for(int i = 20;i --;){
						X=X*2+x[i];
					}
					X+=1<<i;
					printf("%d\n", answerKey[X]);
				}else{
					printf("%d\n", 1+answerKey[(bb+modex(2, i, bits+1))%(bits+1)]);
				}
			}
		}
	}
}

Measured memory_bytes: 7836
#include <iostream>
using namespace std;
int main(){
  int x,y,r;
  cin >> x >> y;
  if (x<y){
    int z = x;
    x = y;
    y = z;
  }
  while (y > 0){
    r = x%y;
    x = y;
    y = r;
  }
  cout << x << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; i++)
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
#define MOD (int)(1e9+7)
using namespace std;
typedef pair<int, int> P;
struct edge {
    int to, cost;
};

class dijkstra {
private:
    int V;
    int d[100002];
    priority_queue<P, vector<P>, greater<>> que;

public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

    int find(int e) {
        return d[e];
    }
};

int gcd(int a, int b) {
    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}

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

bool prime(int a) {
    if (a == 1)
        return false;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0)
            return false;
    }
    return true;
}

class Union_Find {
private:
    vector<int> t, s;

public:
    Union_Find(int max_length) {
        rep(i, max_length + 1) {
            t.push_back(i);
            s.push_back(1);
        }
    }

    void Union(int x, int y) {
        if (same(x, y))
            return;
        int tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        } else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        } else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        } else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }

    int Find(int n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }

    bool same(int x, int y) {
        return Find(x) == Find(y);
    }

    int get_Size(int a) {
        return s[a];
    }
};

vector<int> primeFactorization(int n) {
    vector<int> re;
    int cnt = 2;
    while (n != 1) {
        if (n % cnt != 0) {
            cnt++;
            continue;
        }
        n /= cnt;
        re.push_back(cnt);
    }
    return re;
}
signed main() {
    int r;
    cin>>r;
    cout<<r*r*3<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

vector<int> v;
vector<vector<int>> t;
int n;

void dfs(int z, int from_val, int from_no) {
  v[z] += from_val;
  rep(i, 0, t[z].size()) {
    if (from_no == t[z][i])
      continue;
    dfs(t[z][i], v[z], z);
  }
}

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

  int q;
  cin >> n >> q;
  t.resize(n);
  rep(i, 0, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    t[a].push_back(b);
    t[b].push_back(a);
  }

  v.resize(n);
  rep(i, 0, q) {
    int p, x;
    cin >> p >> x;
    p--;
    v[p] += x;
  }

  dfs(0, 0, 0);

  rep(i, 0, n) {
    if (i > 0)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
}


Measured memory_bytes: 23552
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
const int N=25;
int n,m,tot,id[N][N],dis[N*N][N*N];
char s[N][N];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(s[i][j]!='#')
            id[i][j]=++tot;
    memset(dis,inf,sizeof(dis));
    for(int i=1;i<=tot;i++) dis[i][i]=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        if(s[i][j]!='#')
    {
        for(int k=0;k<4;k++)
        {
            int x=i+dx[k];
            int y=j+dy[k];
            if(x<1||x>n||y<1||y>m||s[x][y]=='#') continue;
            dis[id[x][y]][id[i][j]]=dis[id[i][j]][id[x][y]]=1;
        }
    }
    for(int k=1;k<=tot;k++)
        for(int i=1;i<=tot;i++)
        for(int j=1;j<=tot;j++)
        dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
    int ans=0;
    for(int i=1;i<=tot;i++)
        for(int j=1;j<=tot;j++)
        if(dis[i][j]!=inf)
        ans=max(ans,dis[i][j]);
    printf("%d\n",ans);
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int d[N];
  REP(i,N)cin>>d[i];
  sort(d,d+N);
  cout<<d[N/2]-d[N/2-1]<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define N 200
int n, x[N], y[N], h[N];

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) scanf("%d%d%d", &x[i], &y[i], &h[i]);
    int p = 1; while (h[p] == 0) p++;
    for(int i = 0; i <= 100; i++)
        for(int j = 0; j <= 100; j++) {
            bool pan = true; int nowh = h[p] + abs(i - x[p]) + abs(j - y[p]);
            for(int k = 1; k <= n; k++)
                if (max(nowh - abs(i - x[k]) - abs(j - y[k]), 0) != h[k]) {
                    pan = false; break;
                }
            if (pan) return cout << i << " " << j << " " << nowh << endl, 0;
        }
}

Measured memory_bytes: 256
#include<stdio.h>

void calc(int, int);

int main(){
  int x,y;

  scanf("%d %d",&x,&y);

  calc(x,y);

 
  
  return 0;
}

void calc(int x, int y){
  int z;

  if(y > x){
    z=x;
    x=y;
    y=z;
  }
  
  while(1){
      z = x%y;
      x = y;
      y = z;
      if(z == 0)break;
    }
    printf("%d\n",x);
}



Measured memory_bytes: 2140
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 3e2 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a^b^c) << endl;
	return 0;
}


Measured memory_bytes: 256
import heapq

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
pq = p[:x]+q[:y]
heapq.heapify(pq)

for e in r :
    heapq.heappushpop(pq, e)

print(sum(pq))


Measured memory_bytes: 23456
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
    R int res=1;
    for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
    return res;
}
const int N=1e6+5;
int fac[N],ifac[N],n,k,res;
inline int C(R int n,R int m){return m<0||m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
inline int calc(R int n,R int m,R int k){return dec(C(n+m,n),C(n+m,n+1-k));}
void init(int n=1e6){
    fac[0]=ifac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
    ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
}
int main(){
//  freopen("testdata.in","r",stdin);
    scanf("%d%d",&n,&k);
    if(k<n)return puts("0"),0;
    init();
    for(R int a=max((k+1)>>1,n),b;a<=k;++a){
        b=k-a;
        R int t=min(a-(n-1),b);
        if(a-(n-1)==t)--t;
        upd(res,calc(a,b-(a==b),-t));
    }
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 8064
n, m = map(int, input().split())
X = tuple(map(int, input().split()))
X = sorted(X)
dx = []
for px, bx in zip(X[:m], X[1:]):
    dx.append(bx-px)
if n >= m:
    print(0)
else:
    dx = sorted(dx, reverse=True)
    print(sum(dx[n-1:]))


Measured memory_bytes: 95816
import collections
N = int(input())
S = [input() for _ in range(N)]
c = collections.Counter(S)
d = c.most_common()
cnt = 0
for i in range(len(c)-1):
    if d[i][1] == d[i+1][1]:
        cnt += 1
    else:
        break
e = []
for j in range(cnt+1):
    e.append(d[j][0])
e.sort()
for k in range(len(e)):
    print(e[k])

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


int main()
{
    ll a, b;
    cin >> a >> b;
    ll ans = a - 2 * b;
    if(ans < 0) ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 256
// 2015/03/05 Tazoe

#include <iostream>
using namespace std;

int main()
{
	for(int i=0; i<4; i++){
		int t, n;
		cin >> t >> n;

		switch(t){
		case 1:
			cout << 6000*n << endl;
			break;
		case 2:
			cout << 4000*n << endl;
			break;
		case 3:
			cout << 3000*n << endl;
			break;
		default:
			cout << 2000*n << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const int sz=2e5+100;
int main()
{
    Khela
    int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    int t,cs;
    while(cin>>n)
    {
        vector<ll> test;
        ll ara[n];
        for(i=0;i<n;i++)
        {
            cin>>ara[i];
            test.pb(ara[i]);
        }

        sort(test.begin(),test.end());
        ll ct=0;
        for(i=0;i<n;i++)
        {
            for(j=i+1;j<n;j++)
            {
                ll p=test[i]+test[j];
                ll x=upper_bound(test.begin()+j,test.end(),test[j])-lower_bound(test.begin()+j,test.end(),test[j]);
                x=max(0ll,x-1);
                x+=lower_bound(test.begin(),test.end(),p)-upper_bound(test.begin(),test.end(),test[j]);
                ct+=max(0ll,x);
            }
        }

        cout<<ct<<endl;
    }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    if (k == 0) {
        ans = n * n;
        cout << ans << endl;
        return 0;
    }

    for (ll b = 1; b <= n; b++) {
        ans += max(0LL, (b - k)) * (n / b) + max(0LL, (n % b) - k + 1);
    }

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


Measured memory_bytes: 256
/*
 ============================================================================
 Name        : AtCoder_A.c
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

int main(void) {
	char c[3];
	int i=0;
	int N = 700;
	scanf("%s", c);

	for(i=0; i<3; i++){
		if(c[i] == 'o'){
			N = N+100;
		}
	}
	printf("%d", N);
	return EXIT_SUCCESS;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
while True:
    m,f,r = [int(i) for i in input().split(' ')]
    if m == -1 and f == -1 and r == -1:
        break
    else:
        if m == -1 or f == -1 or m + f < 30:
            print("F")
        elif m + f >= 80:
            print("A")
        elif m + f >= 65 and m + f <80:
            print("B")
        elif m + f >= 50 and m + f < 65:
            print("C")
        elif m + f >= 30 and m + f < 50:
            if r>=50:
                print("C")
            else:
                print("D")

Measured memory_bytes: 7704
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    string str;
    cin >> str;
    string str_rev(str);
    int cnt = 0;
    reverse(str_rev.begin(), str_rev.end());
    for(int i=0; i<str.size(); i++){
        if(str[i] != str_rev[i]) cnt++;
    }

    cout << (cnt/2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <boost/range/irange.hpp>
#include <deque>
#include <limits>

using namespace std;
using namespace boost;

int main() {
    using uint = unsigned int;
    uint N, M;
    cin >> N >> M;
    vector<uint> Ls(M, 0);
    vector<uint> Rs(M, 0);
    vector<int> Ds(M, 0);
    for (auto i: irange((uint) 0, M)) {
        uint l;
        uint r;
        int d;
        cin >> l >> r >> d;
        Ls.at(i) = l - 1;
        Rs.at(i) = r - 1;
        Ds.at(i) = d;
    }
    vector<vector<pair<uint, int>>> adjacency_list(N);
    for (auto i: irange((uint) 0, M)) {
        adjacency_list.at(Ls.at(i)).emplace_back(make_pair(Rs.at(i), Ds.at(i)));
        adjacency_list.at(Rs.at(i)).emplace_back(make_pair(Ls.at(i), -Ds.at(i)));
    }
    vector<bool> weight_calculated(N, false);
    deque<uint> to_be_visited{};
    vector<int> weights(N, std::numeric_limits<int>::max());

    for (uint pointer{0};pointer < N; pointer++) {
        if (!weight_calculated.at(pointer)) {
            weights.at(pointer) = 0;
            weight_calculated.at(pointer) = true;
            to_be_visited.emplace_back(pointer);
            while (!to_be_visited.empty()) {
                uint now{to_be_visited.front()};
                to_be_visited.pop_front();
                for (pair<uint, int> next_data:adjacency_list.at(now)) {
                    uint node_index{next_data.first};
                    int weight{next_data.second};
                    if (!weight_calculated.at(node_index)) {
                        to_be_visited.emplace_back(node_index);
                        weights.at(node_index) = weights.at(now) + weight;
                        weight_calculated.at(node_index) = true;
                    }
                }
            }
        }
    }
    for (auto i: irange((uint) 0, M)) {
        if (weights.at(Rs.at(i)) - weights.at(Ls.at(i)) != Ds.at(i)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 11776
#include <bits/stdc++.h>
using namespace std;
typedef long long l;
l a=0;
l r[10]={1,11,112,1124,11248,112496,1124992,11249984,112499968,1124999936};
string s;
int main(){
    cin>>s;
    for(int i=0;i<s.size();++i) a+=r[s.size()-i-1]*(1<<i)*(s[i]-'0');
    cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main(): 
    N = int(input())
    A = [0] + list(map(int, input().split()))
    
    ans = [0] * (N+1)
    c = 0
    for i in range(N, 0, -1):
        t = sum(ans[i::i])
            
        if A[i] != (t%2): 
            ans[i] = 1
            c += 1
            
    print(c)
    for idx, n in enumerate(ans): 
        if n: print(idx, '', end='')

if __name__ == '__main__':
    main()

Measured memory_bytes: 8360
#include <stdio.h>
#include <math.h>
int main(void){
    int n,i,j;
    float x[4], y[4];
    double ab, cd;
    
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        for(j=0; j<4; j++)
            scanf("%f%f", &x[j], &y[j]);
        ab = (y[1]-y[0]) / (x[1]-x[0]);
        cd = (y[3]-y[2]) / (x[3]-x[2]);
        if(ab == cd) printf("YES\n");	//傾きが等しければ平行
        else printf("NO\n");
    }
    return 0;
}


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

main(){
  int N;
  cin >> N;
  int n_list[N],x_list[N],y_list[N];
  string plan = "Yes";
  
  n_list[0] = 0;
  x_list[0] = 0;
  y_list[0] = 0;
 
  for(int i=0; i < N+1; i++){
    cin >> n_list[i+1] >> x_list[i+1] >> y_list[i+1] ;
  }
  
  for(int i=0; i < N; i++){
   if( abs(x_list[i+1]-x_list[i])+abs(y_list[i+1]-y_list[i]) <= n_list[i+1]-n_list[i] ){
     if( (n_list[i+1]-n_list[i]-abs(x_list[i+1]-x_list[i])-abs(y_list[i+1]-y_list[i]))%2 == 1){
     plan = "No";
     break;      
     }
   }
   else{
     plan = "No";
     break;
   }
   }

  cout << plan <<endl;
    
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main(void){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int left  = A+B; //左の皿の上のおもりの合計
  int right = C+D; //右の皿の上のおもりの合計

  if(left < right) //右の方が重い
    cout << "Right" << endl;
  else if(left > right) //左の方が重い
    cout << "Left" << endl;
  else //それ以外 (左と右が等しい)
    cout << "Balanced" << endl;
  
  return 0;
}


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

int main(){
  int N, Q;
  string s;
  cin >> N >> Q >> s;
  int ans[N];
  ans[0] = 0;

  for(int i=0; i<N-1; i++){
    if(s[i]=='A' && s[i+1]=='C'){
      ans[i+1] = ans[i]+1;
    } else {
      ans[i+1] = ans[i];
    }
  }

  int l, r;
  for (int i=0; i<Q; i++){
    cin >> l >> r;
    printf("%d\n", ans[r-1]-ans[l-1]);
  }
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp> 
using namespace std;

vector<string> inputVS(void);

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

    if (S[2] == S[3] && S[4] == S[5]){
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int h,w;
cin>>h>>w;
vector<vector<int>> a(h,vector<int>(w));
for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>a[i][j];
ll cnt=0;
int i=0;
vector<P> move;
queue<P> q;
while(1){
  if(i==h)break;
  if(i%2==0){
       for(int j=0;j<w;j++){
         if(q.empty()&&a[i][j]==0)continue;
         if(a[i][j]%2==1&&!q.empty()){
           while(!q.empty()){
             P p=q.front();
                move.push_back(p);
                q.pop();
            }
            move.emplace_back(i,j);
            move.emplace_back(-1,-1);
         }
         else if(!q.empty()||a[i][j]%2==1){q.push(P(i,j));
        }
       }
  }
  else{
     for(int j=w-1;j>=0;j--){
        if(q.empty()&&a[i][j]==0)continue;
         if(a[i][j]%2==1&&!q.empty()){
           while(!q.empty()){
             P p=q.front();
                move.push_back(p);
                q.pop();
            }
              move.emplace_back(i,j);
              move.emplace_back(-1,-1);
           }
         else if(!q.empty()||a[i][j]%2==1)q.push(P(i,j));
         
       }
  }
  i++;
}
if(move.size()==0){
  cout<<0<<endl;
  return 0;
}
for(int t=0;t<move.size()-1;t++){
  if(move[t].fi==-1||move[t+1].fi==-1)continue;
  cnt++;
 // cout<<move[t].fi<<" "<<move[t].se<<" "<<move[t+1].fi<<" "<<move[t+1].se<<endl;
}
cout<<cnt<<endl;
for(int t=0;t<move.size()-1;t++){
  if(move[t].fi==-1||move[t+1].fi==-1)continue;
cout<<move[t].fi+1<<" "<<move[t].se+1<<" "<<move[t+1].fi+1<<" "<<move[t+1].se+1<<endl;
}
}

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

int main() {
	int n;
	cin >> n;
	int ans = 0, tmp = 0;
	char s;
	while (cin >> s) {
		if (s == 'I') tmp++;
		else tmp--;
		ans = max(tmp, ans);
	}
	cout << ans << endl;
}

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

char p[1100][1100];

int main(){

	int C=0;//布の枚数
	int N=0;//横＆縦の行数
	
	int D=0;
	int Y=0;//r
	int X=0;//c
	int henkou=0;
	int kioku=0; //対象かどうかを見るときに一時的に格納する変数
	int out=0;//対象になっていないことを記憶
	int aout=0;//内容変更によって対称かを記憶する
	int error=0;//対象になってない組の個数
	
	int G[100];//変更するX座標
	int H[100];//変更するY座標
	
	int i=0;
	int j=0;
	int d=0;
	int in=0;
	int A=0;
	int x=0;
	int y=0;
                
    cin>>C;
	cin>>N;	
	for(i=0;i<N;i++){
		cin>>p[i];
	}	
	/*
	for(y=0;y<N;y++){
	    for(x=0;x<N;x++){
	        cout<<p[y][x];
	    }
	    cout<<endl;
	}
	*/
	
	/////////一週目の処理/////////////////
	for(Y=0;Y<N/2;Y++){
		for(X=0;X<N/2;X++){
			out=0;
			kioku=p[Y][X];
				if(p[Y][N-1-X]!=kioku){
					out=1;
				}//左右対称かを見る
				
				if(p[N-1-Y][X]!=kioku){
					out=1;
				}//上下が対称か見る
				
				if(p[N-1-Y][N-1-X]!=kioku){
					out=1;
				}//斜めに対称か見る
						
			if(out==1){
				error=error+1;
			}
		}
	}
	
	//cout<<error<<endl;
	
	//-----------------------------------------------------------
	if(error==0){
		A=A+1;    //一枚目対称象だった
	}

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

	//////二週目以降（ループ）変更点のみを計算//////
	
	for(i=0;i<C-1;i++){
//		cout<<"/////////////////"<<endl; 
			
		///変更///
		cin>>D;     
		for(j=0;j<D;j++){
			cin>>H[j]>>G[j];
		                                  
	    	out=0;
	    	aout=0;
			///////////要変更/////////////////////
		    kioku=p[H[j]-1][G[j]-1];                          
			if(kioku!=p[H[j]-1][N-G[j]] || kioku!=p[N-H[j]][G[j]-1] || kioku!=p[N-H[j]][N-G[j]]){//--------------------
                //左右反転座標              //上下反転座標              //上下左右反転座標
				out=1;//完全対称になっていない
			}
			/*if(kioku==p[H[j]-1][N-G[j]] && kioku==p[N-H[j]][G[j]-1] && kioku==p[G[j]-1][H[j]-1]){
				out=0;
			}
			*/
			/////////////////////////////////////////
			
			//内容の変更//
			if(p[H[j]-1][G[j]-1]=='0'){
				p[H[j]-1][G[j]-1]='1';
				//cout<<"ok";
				//cout<<p[H[j]-1][G[j]-1]<<endl;
			}else{
				p[H[j]-1][G[j]-1]='0';
			    //cout<<"ok";
			    //cout<<p[H[j]-1][G[j]-1]<<endl;
			}
			
			
//				cout<<p[0];
			
////////////////////////
			
			///////
			
			///要変更///////////////////////////////////
			kioku=p[H[j]-1][G[j]-1];			
			if(kioku!=p[H[j]-1][N-G[j]] || kioku!=p[N-H[j]][G[j]-1] || kioku!=p[N-H[j]][N-G[j]]){//--------------------
                                      //左右反転座標              //上下反転座標                                            //上下左右反転座標
				aout=1;//完全対称になっていない
				//cout<<"非対称"<<endl;
			}/*
			if(kioku==p[H[j]-1][N-G[j]] && kioku==p[N-H[j]][G[j]-1] && kioku==p[N-H[j]][N-G[j]]){
				aout=0;
			}*/
			
			/////////////////////////////////////////////
			
			if(out==0 && aout==1){//対称が崩れたとき
				error=error+1;
		//		cout<<"崩れた"<<endl;
			}
			if(out==1 && aout==0){//対称になったとき
				error=error-1;
		//		cout<<"対称になった"<<endl;
			}
			/*
			for(d=0;d<N;d++){
			    cout<<p[d]<<endl;
			}
			cout<<endl;
			*/
		}
		
		//out<<error<<endl;
		
		if(error==0){
			A=A+1;
		}
		//cout<<A<<endl;		
		//////
		//cout<<"-----------------"<<endl;

    }

cout<<A<<endl;




                 
}


Measured memory_bytes: 4180
package main

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

func solution(n int, a []int) int {
        sort.Ints(a)
        amax := a[n-1]

        memo := make([]int, amax+1)
        for i := 0; i < n; i++ {
                for j := 1; a[i]*j <= amax; j++ {
                        if j == 1 && memo[a[i]] == 1 {
                                memo[a[i]]++
                                break
                        }
                        memo[a[i]*j]++
                }
        }
        c := 0
        for i := range a {
                if memo[a[i]] == 1 {
                        c++
                }
        }
        return c
}

func main() {
        r := bufio.NewReader(os.Stdin)
        var n int
        fmt.Fscan(r, &n)
        a := make([]int, n)
        for i := range a {
                fmt.Fscan(r, &a[i])
        }
        fmt.Println(solution(n, a))
}

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

using namespace std;
typedef long long LL;
typedef pair <LL, int> P;
const int Maxn = 2e5 + 5;
const LL inf = 0x3f3f3f3f3f3f3f3f;
LL a[Maxn], f[Maxn];
int n;
LL k;
P vec[Maxn];
bool check(LL x){
    LL cnt = 0;
    priority_queue <P> pq;
    for (int i = 1; i <= n; i++){
        pq.push(P(f[i] * a[n + 1 - i], f[i]));
    }
    while (!pq.empty()){
        P tmp = pq.top();
        pq.pop();
        if (tmp.first <= x) return true;
        cnt += (tmp.first - x - 1) / tmp.second + 1;
        if (cnt > k) return false;
    }
    return true;
}
int main(){
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &f[i]);
    sort(a + 1, a + n + 1);
    sort(f + 1, f + n + 1);
    LL l = 0, r = inf;
    while(l < r){
        LL m = (l + r) >> 1;
        if (check(m))
            r = m;
        else
            l = m + 1;
    }
    cout << l << endl;
}



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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

struct mint {
  ll x;
  mint(ll x=0): x(((x%mod)+mod)%mod) {}
  mint operator-() const {return mint(-x);}
  mint& operator-=(const mint a) {
    if((x-=a.x) < 0) x+=mod;
    return *this;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint& operator+=(const mint a) {
    if((x+=a.x) > mod) x-=mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint& operator*=(const mint a) {
    x*=a.x;
    x%=mod;
    return *this;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll ex) const {
    if(!ex) return 1;
    if(ex&1) return *this * pow(ex-1);
    mint base = pow(ex/2);
    return base*base;
  }
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    *this*=a.inv();
    return *this;
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(ll x): fact(x+1),ifact(x+1) {
    fact[0] = 1;
    ifact[0] = 1;
    REP(i,x) {
      fact[i+1] = fact[i]*(i+1);
      ifact[i+1] = fact[i+1].inv();
    }
  }
  mint C(ll n, ll r) {
    return fact[n]*ifact[n-r]*ifact[r];
  }
};

int main(int argc, char const* argv[])
{
  int r1,c1,r2,c2;
  cin>>r1>>c1>>r2>>c2;
  r1--; c1--;
  combination comb(r2+c2+2);
  mint ans = comb.C(r2+c2+2,c2+1)-1 - (comb.C(r1+c2+2,c2+1)-1) - (comb.C(r2+c1+2,c1+1)-1) + comb.C(r1+c1+2,c1+1)-1;
  // printf("comb.C(%d,%d): %lld\n", r2+c2+2,c2+1,comb.C(r2+c2+2,c2+1));
  // printf("comb.C(%d,%d): %lld\n", r1+c2+2,c2+1,comb.C(r1+c2+2,c2+1));
  // printf("comb.C(%d,%d): %lld\n", r2+c1+2,c1+1,comb.C(r2+c1+2,c1+1));
  // printf("comb.C(%d,%d): %lld\n", r1+c1+2,c1+1,comb.C(r1+c1+2,c1+1));

  printf("%lld\n", ans.x);

  return 0;
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
const int inf = 2e9+7;

long long w[101], v[101];
long long f[110][100100];

int main()
{
    int N, V, i, j;

    cin>>N>>V;

    for(i=0;i<N;i++)
        cin>>w[i]>>v[i];
    fill(f[0],f[0]+100001,inf);
    f[0][0] = 0;
    for(i=0;i<N;i++)
    {
        for(j=0;j<=100000;j++)
            if(j >= v[i])
                f[i+1][j] = min(f[i][j-v[i]] + w[i], f[i][j]);
            else
                f[i+1][j] = f[i][j];
    }
    int res=0;
    for(int i=0;i<=100000;i++)
        if(f[N][i]<=V)
            res = i;

    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353,INF=1e18;



int main() {
    int N;
    cin>>N;
    vector<set<int>> to(N);
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        --a;--b;
        to[a].insert(b);
        to[b].insert(a);
    }
    vector<int> C(N);
    rep(i,N){
        cin>>C.at(i);
    }
    sort(C.begin(),C.end());
    vector<int> ans(N);
    ll point=0;
    rep(i,N-1){
        int sma;
        rep(j,N){
            if(to[j].size()==1){
                sma=j;
                break;
            }
        }
        ans.at(sma)=C.at(i);
        to[*begin(to[sma])].erase(sma);
        to[sma].erase(*begin(to[sma]));
    }
    rep(i,N){
        if(ans.at(i)==0)ans.at(i)=C.at(N-1);
    }
    rep(i,N-1){
        point+=C.at(i);
    }
    cout<<point<<endl;
    rep(i,N-1){
        cout<<ans.at(i)<<" ";
    }
    cout<<ans.at(N-1)<<endl;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main {

	
	public static void main(String[] args) {
		FastScanner in=new FastScanner();
		PrintWriter out=new PrintWriter(System.out);
	//	int t=in.nextInt();
	//	while(t-->0)
		solve(in,out);
		out.close();
	}
    static long gcd(long a,long b){
        if(b==0) return a;
        else return gcd(b,a%b);
    }
    static void solve(FastScanner in,PrintWriter out){
      int n=in.nextInt();
      int a[]=new int[n]; a=in.readArray(n);
     Stack<Integer> st=new Stack<>();
     for(int i=n;i>0;i--) st.push(i);
      for(int i=0;i<n;i++){
          if(st.peek()==a[i]) st.pop();
      }
      if(st.size()!=n) {
          out.println(st.size());
      }
      else out.println(-1);
    }    
	


	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 56380
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using it=std::int64_t;
const it INF=1<<30;

int main(){
    it N,Q;
    std::string S;
    std::vector<std::set<it>> alp;
    alp.assign(26,std::set<it>({INF}));
    std::vector<it> res(0);

    cin>>N>>S>>Q;
    for(it i=0;i<N;i++){
        alp[S[i]-'a'].insert(i);
    }
    for(it i=0;i<Q;i++){
        it cmd;
        cin>>cmd;
        if(cmd==1){
            it i_q; char c_q;
            cin>>i_q>>c_q; i_q--;
            char c_p=S[i_q];
            S[i_q]=c_q;
            alp[c_p-'a'].erase(i_q);
            alp[c_q-'a'].insert(i_q);
        }
        else{
            it l_q,r_q,count;
            cin>>l_q>>r_q; l_q--;
            count=0;
            for(int j=0;j<26;j++){
                if(alp[j].empty()) continue;
                it l_i=*alp[j].lower_bound(l_q);
                it r_i=*alp[j].lower_bound(r_q);
                if(l_i<r_i) count++;
            }
            res.push_back(count);
        }
    }
    for(it i=0;i<res.size();i++){
        cout<<res[i]<<endl;
    }
}

Measured memory_bytes: 24708
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

vector<int> parent;
vector<int64_t> nodes;
int getParent(int x) {
  int y = x;
  while (y != parent[y]) {
    y = parent[y];
  }
  parent[x] = y;
  return y;
}

bool isSame(int x, int y) {
  x = getParent(x);
  y = getParent(y);
  return (x == y);
}

bool unite(int x, int y) {
  x = getParent(x);
  y = getParent(y);
  if (x == y) return false;
  if (nodes[x] < nodes[y]) swap(x, y);
  parent[y] = x;
  nodes[x] += nodes[y];
  return true;
}

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, M;
  cin >> N >> M;
  vector<int> A(M);
  vector<int> B(M);
  rep(i, M) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }

  parent.resize(N);
  nodes.resize(N, 1);
  rep(i, N) parent[i] = i;

  vector<int64_t> answer(M);
  answer[M - 1] = N * (N - 1) / 2;
  for (int i = M - 1; i > 0; --i) {
    if (isSame(A[i], B[i])) {
      answer[i - 1] = answer[i];
    } else {
      int a = getParent(A[i]);
      int b = getParent(B[i]);
      int64_t diff = nodes[a] * nodes[b];
      answer[i - 1] = answer[i] - diff;
      unite(A[i], B[i]);
    }
  }

  rep(i, M) { cout << answer[i] << endl; }
  return 0;
}


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

int main(){
  int n; // 柿の木の数
  
  while(cin>>n&&n!=0){
    int w,h;
    cin >> w >> h;
    int field[100][100];

    for(int i=0;i<100;i++){
      for(int j=0;j<100;j++){
        if(i<w&&j<h)
          field[i][j] = 0;
        else
          field[i][j] = -1;
      }
    }

    for(int i=0;i<n;i++){
      int x,y;
      cin >> x >> y;
      field[x-1][y-1] = 1;
    }

    int s,t;
    cin >> s >> t;
    int max=0;

    for(int i=0;i<=w-s;i++){
      for(int j=0;j<=h-t;j++){
        int count=0;
        for(int k=0;k<s;k++){
          for(int l=0;l<t;l++){
            if(field[i+k][j+l]==1) count++;
          }
        }
        if(max<count) max=count;
      }
    }
    cout << max << endl;
  }

  return 0;
}

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

int main()
{
	int K;
  cin >> K;
  int x = 7 % K;
  for(int i = 1; i <= K; ++i){
  	if(x == 0){
    cout << i << endl;
      return 0;
    }
    x = (x * 10 + 7) % K;
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <numeric>
#include <unordered_map>

int main() {
    long n;
    std::cin >> n;

    std::unordered_map<long, long> a;

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

    long q;
    std::cin >> q;

    long b, c;
    {
        std::cin >> b >> c;

        const long count = a[b];
        a.erase(b);
        a[c] += count;
    }
    auto previous = std::accumulate(
                            std::begin(a),
                            std::end(a),
                            std::make_pair(0l, 0l),
                            [](std::pair<long, long> f, std::pair<long, long> s) {
                                return std::make_pair(1l, (f.second * f.first) + (s.second * s.first));
                            })
                            .second;
    std::cout << previous << std::endl;

    for (long i = 1; i < q; ++i) {
        std::cin >> b >> c;

        const long count = a[b];
        a.erase(b);
        a[c] += count;

        previous -= (b * count);
        previous += (c * count);
        std::cout << previous << std::endl;
    }
}

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

int main(){
	int N, t = 0;
	cin >> N;
	vector<int> A(N), ans(N, 0);
	for(int i=0; i<N; i++){
		cin >> A[i];
		if(A[i] > i){
			cout << -1 << endl;
			return 0;
		}
		if(t <= i - A[i]){
			t = i - A[i];
			ans[i - A[i]] = A[i];
		}else{
			cout << -1 << endl;
			return 0;
		}
	}
	long long ANS = 0;
	for(int i=0; i<N; i++){
		ANS += ans[i];
	}
	cout << ANS << endl;
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
lst = []
klst = []
for i in range(N):
    k, v = input().split()
    lst.append((i+1, k, int(v)))
    klst.append(k)
klst = list(set(klst))
klst.sort()
# print(lst)
# print(klst)

ans = [[] for i in range(len(klst))]
#ans2 = [[0], [1], [2]]
#print(ans)
counter = 0
for name in klst:
    #for i in range(len(lst)):
    for res in lst:
        a, b, c = res
        if b == name:
            ans[counter].append((c, a))
    ans[counter].sort()
    #print(ans)
    counter += 1
#print(ans)

for answer in ans:
    for (a, b) in reversed(answer):
        print(b)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main(){
  int n ;
  cin>> n ;
  if(n%2==1){
    int m=(n-1)*(n-1)/2 ;
    cout<< m<<endl ;
  rep2(i,1,n-1){
    rep2(j,i+1,n){
      if(i+j!=n)
      cout <<i<<" " <<j<< endl ;
    }
  }
  }
   else{
     int m=(n-2)*(n)/2;
    cout <<m<<endl ;
    rep2(i,1,n-1){
    rep2(j,i+1,n){
    if(i+j!=n+1)
     cout <<i<<" "<<j<<endl ;
    }
        }
    }
    return 0;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;


int main() {
	int x; cin >> x;
	int ans = 1;
	REP(i, 2, x) {
		int a = i * i;
		while (a <= x) {
			ans = max(ans, a);
			a *= i;
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256