akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cassert>
#include<cctype>
using namespace std;

string s;
int cur=0;

char readchar()
{
    assert(cur<s.size());
    char ret=s[cur];
    cur+=1;
    return ret;
}

char peek()
{
    assert(cur<s.size());
    return s[cur];
}

int digit()
{
    assert(isdigit(peek()));
    int n = readchar() - '0';
    return n;
}

int number()
{
    int n=digit();
    while (cur < s.size() && isdigit(peek()))
       n=n*10+digit();
    return n;
}

int expression();

int factor()
{
    if(peek()!='(')  
      return number();
    cur+=1;
    int n=expression();
    assert(peek()==')');
    cur+=1;
    return n;
}

int term()
{
    int a=factor();
    while((cur<s.size()) && (peek()=='*'||peek()=='/'))
    {
        char op=readchar();
        int b=factor();
        if(op =='*')  a *=b;
        else a /=b;
    }
    return a;
}

int expression()
{
    int a=term();
    while(cur<s.size()&&(peek()=='+'||peek()=='-'))
    {
        char op=readchar();
        int b=term();
        if(op=='+')  a +=b;
        else  a -=b;
    }
    return a;
}

int parse()
{
    return expression();
}

int main()
{
    int n,a;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> s;
        cur=0;
        a=parse();
        cout << a << endl;
    }
}


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

//input
ll n,k;
vector<ll>p,c;

ll solve(ll x){
    ll wa = 0;
    ll now = x;
    ll cnt = 0;
    bool fi = true;
    while(fi||now!=x){
        ll nx = p[now];
        wa += c[nx];
        now = nx;
        cnt++;
        fi=false;
    }
    if(wa<=0){
        ll M = c[p[now]];
        ll wa = 0;
        rep(i,cnt){
            ll nx = p[now];
            wa += c[nx];
            now = nx;
            chmax(M,wa);
        }
        return M;
    }
    ll res = 0;
    res += wa*(k/cnt-1);
    ll nokori = k-(k/cnt-1)*cnt;
    ll M = 0;
    wa = 0;
    rep(i,nokori){
        ll nx = p[now];
        wa += c[nx];
        now = nx;
        chmax(M,wa);
    }
    res += M;
    return res;

}



int main(){
    cin >> n >> k;
    p.resize(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    c.resize(n);
    rep(i,n)cin>>c[i];
    ll ans = -INF;
    rep(i,n){
        chmax(ans,solve(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
int main(){
	int k;
	int n;
	int p[1000];
	int max;
	int maxi;
	int tail;
	int swap;
	int i;
	int j;
	int sum;
	
	scanf("%d%d", &n, &k);
	for(i = 0; i < n; i++){
		scanf("%d", &p[i]);
	}
	
	tail = n-1;
	for( ; tail > 0; tail--){
		max = 0;
		for(j = 0; j < tail+1; j++){
			if(max < p[j]){
				max = p[j];
				maxi = j;
			}
		}
		swap = p[tail];
		p[tail] = p[maxi];
		p[maxi] = swap;
	}
	
	
	sum = 0;
	for(i = 0; i < k; i++){
		sum += p[i];
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 1732
params_s = input()
params_a = params_s.split(' ')

params = [int(x) for x in params_a]

W = params[0]
H = params[1]
x = params[2]
y = params[3]
r = params[4]

ll_x = r
ul_x = W - r
ll_y = r
ul_y = H - r

if (ll_x <= x & x <= ul_x) & (ll_y <= y & y <= ul_y):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define rep(n) for(int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n; cin >> n;
    vector<int> x(n); repeat(i, n) cin >> x[i];
    sort(x.begin(), x.end());
    int sum = accumulate(x.begin(), x.end(), 0);
    
    if (sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }
    
    repeat(i, n) {
        if (x[i] % 10 == 0) continue;
        cout << sum - x[i] << endl;
        return 0;
    }
    
    cout << 0 << endl;
    return 0;
}


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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  if (a + b == c || b + c == a || c + a == b) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
fun main() {
  val N = readInt()
  println(if (N >= 30) "Yes" else "No")
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


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

void bubbleSort(vector<string> &A)
{
    int N = A.size();
    bool flag = true;
    while (flag)
    {
        flag = false;
        for (int j = N - 1; j > 0; j--)
        {
            if (A.at(j)[1] < A.at(j - 1)[1])
            {
                swap(A.at(j), A.at(j - 1));
                flag = true;
            }
        }
    }
}

void selectionSort(vector<string> &A)
{
    int N = A.size();
    int i, j, minj;
    for (i = 0; i < N; i++)
    {
        minj = i;
        for (j = i; j < N; j++)
        {
            if (A.at(j)[1] < A.at(minj)[1])
            {
                minj = j;
            }
        }
        if (i != minj)
        {
            swap(A.at(i), A.at(minj));
        }
    }
}

void print_result(vector<string> C)
{
    for (int i = 0; i < C.size() - 1; i++)
    {
        cout << C.at(i) << " ";
    }
    cout << C.back() << endl;
}

int main()
{
    int N, i;
    cin >> N;
    vector<string> C_for_bubble(N);
    vector<string> C_for_selection(N);
    for (i = 0; i < N; i++)
    {
        cin >> C_for_bubble[i];
    }
    C_for_selection = C_for_bubble;
    bubbleSort(C_for_bubble);
    print_result(C_for_bubble);
    cout << "Stable" << endl;
    selectionSort(C_for_selection);
    print_result(C_for_selection);
    if (C_for_bubble == C_for_selection)
    {
        cout << "Stable" << endl;
    }
    else
    {
        cout << "Not stable" << endl;
    }
}


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

int n, m, k;
void solve(){
	int i, j;
}

int main(){
	int a, b, c;
	int ans = 0;
	cin >> a >> b >> c >> k;
	if(k > a){
		k-=a;
		ans = a;
		k-=b;
		if(k>0){
			ans -= k;
		}
		cout << ans;
	}else {
		cout << k;
	}
	return 0;
}

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

const long long MX = 1e18;

int main() {
    long long mp=1;
    long long N; cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    for (int i = 0; i < N; i++) {
        if (MX / mp < A[i]) {
            cout << -1 << endl;
            return 0;
        }
        mp *= A[i];
    }
    cout << mp << endl;
    return 0;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  double a,b,h,m;
  cin>>a>>b>>h>>m;
  double pi = acos(-1);
  double th = (h * 60 + m) / 720. * 2 * pi;
  double tm = (h * 60 + m) / 60. * 2 * pi;
  double xh = a * cos(th);
  double yh = a * sin(th);
  double xm = b * cos(tm);
  double ym = b * sin(tm);
  auto dx = xh - xm;
  auto dy = yh - ym;
  cout<<fixed<<setprecision(12)<<sqrt(dx*dx + dy*dy)<<endl;
  return 0;
}


Measured memory_bytes: 4116
X,N = map(int,input().split())
P = list(map(int,input().split()))
for i in range(N):
    if not (X-i in P):
        print(X-i)
        exit()
    elif not (X+i in P):
        print(X+i)
        exit()
if N == 0:
    print(X)
else:
    print(0)

Measured memory_bytes: 61584
#include <cstdio>
#include <cstring>
using namespace std;

const int sz = 1000010;

char s[sz];
int mp[sz];

int main(){
	fgets(s, sz, stdin);
	int n = strlen(s) - 1;
	
	mp[0] = -1;
	int t = -1;
	for(int i = 0; i < n; ++i){
		while(t >= 0 && s[t] != s[i]){
			t = mp[t];
		}
		mp[i + 1] = ++t;
	}
	
	t = n;
	while(t * 2 > n){
		int p = n - t;
		if(p * 3 > n){
			printf("Love %.*s!\n", p, s);
			return 0;
		}
		t = mp[t];
	}
	puts("mitomerarenaiWA");
}

Measured memory_bytes: 5860
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int s;
    cin >> s;
    int h = s / 3600;
    int ss = s - h * 3600;
    int m = ss / 60; 
    int sss = ss - m * 60;
    cout << h << ":" << m << ":" << sss << endl;
    return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>

int is_prime(int x){
  int i;
  for(i=2;i*i<=x;i++)
    {
      if(x%i==0)return 0;
    }
  return 1;
}

int main(void){
  int i,n,ans;
  while(scanf("%d",&n) && n)
    {
      ans = 0;
      for(i=n+1;i<=2*n;i++)
	{
	  if(is_prime(i))ans++;
	}
      printf("%d\n",ans);
    }
  return 0;
}

Measured memory_bytes: 760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//Micro Futures scalping to get my tendies
vector<int> adj[200200];
int dp[200200];
int arr[200200]; int h[200200];
int sum = 0;
int dfs(int root){ 
	int sum = 0;
	for(auto xx : adj[root]){
		sum += dfs(xx);
	}
	return sum+arr[root-1];
}
int main(){
	ll x; cin>>x;
	if(x >= 30) cout<<"Yes"<<"\n";
	else cout<<"No\n";
}

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

int main() {
    string s;
    cin >> s;
    set<char> set_c;

    char x = s.at(0);
    int i = 0;

    for (int i = 0; i < s.size(); i++) {
            set_c.insert(s.at(i));
    }
    string ans = "yes";
    if (set_c.size() != s.size())
        ans = "no";
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*xy = map(int,read().split())

wa = []
sa = []
for x,y in zip(xy[::2],xy[1::2]):
    wa.append(x+y)
    sa.append(x-y)

v = max(wa)-min(wa)
w = max(sa)-min(sa)

print(max(v,w))


Measured memory_bytes: 54628
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
vector<pair<int,pair<int,int> > > g[110];
int ijk[110][110];
int v[110][110];
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		for(int i=0;i<110;i++)g[i].clear();
		for(int i=0;i<b;i++){
			int p,q,r,s;
			scanf("%d%d%d%d",&p,&q,&r,&s);
			p--;q--;
			g[p].push_back(make_pair(q,make_pair(r,s)));
			g[q].push_back(make_pair(p,make_pair(r,s)));
		}
		for(int i=0;i<110;i++){
			for(int j=0;j<110;j++){
				v[i][j]=0;
				ijk[i][j]=999999999;
			}
		}
		ijk[0][c]=0;
		priority_queue<pair<int,pair<int,int> > >Q;
		Q.push(make_pair(0,make_pair(0,c)));
		while(Q.size()){
			int cost=-Q.top().first;
			int at=Q.top().second.first;
			int has=Q.top().second.second;
			Q.pop();
			if(v[at][has])continue;
			v[at][has]=1;
			for(int i=0;i<g[at].size();i++){
				if(has>=g[at][i].second.first){
					if(!v[g[at][i].first][has-g[at][i].second.first]&&ijk[g[at][i].first][has-g[at][i].second.first]>cost){
						ijk[g[at][i].first][has-g[at][i].second.first]=cost;
						Q.push(make_pair(-cost,make_pair(g[at][i].first,has-g[at][i].second.first)));
					}
				}
				if(!v[g[at][i].first][has]&&ijk[g[at][i].first][has]>cost+g[at][i].second.second){
					ijk[g[at][i].first][has]=cost+g[at][i].second.second;
					Q.push(make_pair(-ijk[g[at][i].first][has],make_pair(g[at][i].first,has)));
				}
			}
		}
		int ret=999999999;
		for(int i=0;i<=c;i++){
			ret=min(ret,ijk[a-1][i]);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1632
#!/usr/bin/env python3
import sys
import numpy as np

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    sum_all = sum(A) % MOD
    ans = 0
    for i in range(N-1):
        ans = (ans + (A[i] * (sum_all-A[i]))) % MOD
        sum_all -= A[i]
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 51400
package main

import (
	"fmt"
)

var n, k int

func main() {
	fmt.Scan(&n, &k)

	n = n % k
	if n > k/2 {
		n = k - n
	}

	for n%k != n {
		n = n % k
		if n > k/2 {
			n = k - n
		}
	}
	fmt.Println(n)
}

func abs(n int) int {
	if n > 0 {
		return n
	}
	return -n
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


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

int main(){
  string S;
  cin >> S;
  vector<bool> see(26);
  for(int i=0; i<S.size(); i++){
    see.at(S.at(i)-97)=true;
  }
  string ans="None";
  for(int i=0; i<26; i++) if(see.at(i)==false){
    ans=i+97;
    break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int 
#define ar array
#define pb push_back
#define fi(a,b) for(int i=a;i<(b);i++)
#define fj(a,b) for(int j=a;j<(b);j++)
#define fk(a,b) for(int k=a;k<(b);k++)
#define lb lower_bound
#define ub upper_bound
//hash base 177013

const int mxn=1003;
int n,m;
vector<string> mat;
bool vis[mxn][mxn];
vector<pair<int,pair<int,int>>> adj[mxn][mxn];
int d[mxn][mxn];

bool valid(int x,int y)
{
	if(x>=0&&x<n&&y>=0&&y<m&&mat[x][y]=='.') return true;
	return false;
}
void dij(pair<int,int> node)
{
	priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>>> q;
	memset(d,0x3f,sizeof(d));
	d[node.first][node.second]=0;
	q.push({0,{node.first,node.second}});
	while(q.size())
	{
		auto u=q.top();
		q.pop();
		for(auto i:adj[u.second.first][u.second.second])
		{
			if(d[i.second.first][i.second.second]>d[u.second.first][u.second.second]+i.first)
			{
				d[i.second.first][i.second.second]=d[u.second.first][u.second.second]+i.first;
				q.push({d[i.second.first][i.second.second],{i.second.first,i.second.second}});
			}
		}
	}
}


int main()
{
	FAST;
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	//ll testcase;
	//cin>>testcase;
	//while(testcase--)
	{
		cin>>n>>m;
		int startx,starty,endx,endy;
		cin>>startx>>starty>>endx>>endy;
		--startx,--starty,--endx,--endy;
		mat=vector<string> (n);
		fi(0,n)
		{
			cin>>mat[i];
		}
		fi(0,n)
		{
			fj(0,m)
			{
				if(mat[i][j]=='#') continue;
				if(valid(i-1,j))
				{
					adj[i][j].pb({0,{i-1,j}});
				}
				if(valid(i+1,j))
				{
					adj[i][j].pb({0,{i+1,j}});
				}
				if(valid(i,j+1))
				{
					adj[i][j].pb({0,{i,j+1}});
				}
				if(valid(i,j-1))
				{
					adj[i][j].pb({0,{i,j-1}});
				}
				for(int k=-2;k<=2;k++)
				{
					for(int x=-2;x<=2;x++)
					{
						if(k==0&&x==0) continue;
						if(valid(i+k,j+x))
						{
							adj[i][j].pb({1,{i+k,j+x}});
						}
					}
				}
			}
		}
		dij({startx,starty});
		if(d[endx][endy]>100000000)
		{
			cout<<-1;
			return 0;
		}
		cout<<d[endx][endy];
		
		
	}
}


Measured memory_bytes: 150928
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(18);
}
signed main(){
  init_io();
  ll x,y,z;
  cin >> x >> y >> z;
  swap(x,y);
  swap(x,z);
  cout << x<<" "<<y<<" "<<z<<endl;
}


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

#define maxn 200010

using namespace std;

int v[maxn];
bool used[maxn];

int main() {
    ios_base::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    if (x == 1 || x == 2*n-1) {
        cout << "No";
        return 0;
    }
    cout << "Yes\n";
    v[n] = x;
    used[x] = true;
    v[n-1] = x-1;
    used[x-1] = true;
    v[n+1] = x+1;
    used[x+1] = true;
    if (x != n) {
        if (x != 2*n-2) {
            v[n-2] = x+2;
            used[x+2] = true;
        } else {
            v[n+2] = x-2;
            used[x-2] = true;
        }
    }
    int j = 1;
    for (int i = 1; i <= 2*n-1; ++i) {
        if (v[i])
            continue;
        while (used[j])
            ++j;
        used[j] = true;
        v[i] = j;
    }
    
    for (int i = 1; i <= 2*n-1; ++i) {
        cout << v[i] << "\n";
    }
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

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

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> b(n+1);
    for(int i = 1; i <= n-1; ++i){
        cin >> b[i];
    }
    b[0] = b[1];
    b[n] = b[n-1];
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        ans += min(b[i-1], b[i]);
    }
    cout << ans << "\n";
    return 0;
}

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

int main(){
        string S;
        cin >> S;
        int ans = 0;
        if(S == "SUN") ans = 7;
        if(S == "MON") ans = 6;
        if(S == "TUE") ans = 5;
        if(S == "WED") ans = 4;
        if(S == "THU") ans = 3;
        if(S == "FRI") ans = 2;
        if(S == "SAT") ans = 1;
        cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
q = int(input())

A = [0] * 100001
for i in a:
  A[i] += 1

ans  = 0
for i in range(len(A)):
  ans += i * A[i]  

for n in range(q):
  b,c = list(map(int, input().split()))
  ans += (c * A[b]) - (b * A[b])
  A[c] += A[b]
  A[b] = 0
  print(ans)



Measured memory_bytes: 20884
#include <stdio.h>
int main(){
  int N, i, j, k ;
  int num[100];
  while(1){ 
    int ch = 0;   
    scanf("%d",&N);
    if (N == 0)break;
    for( i = 0 ; i < N ; i++)
      scanf("%d",&num[i]);
    for(i = 0 ; i < N ; i++){
      for(j = N - 1 ; j >= i+1 ; j--){
    if(num[j] < num[j-1]){
      ch++;
      k = num[j];
      num[j] = num[j-1];
      num[j-1] = k;
    }
      }
    }
    printf("%d\n",ch);
  }
     
    return 0;
  }
   

Measured memory_bytes: 600
s_d = [i for i in input()]
t = input()
flg = True

for i in range(len(s_d)-1, -1, -1):
    if len(s_d) - i >= len(t) and s_d[i] == '?' or s_d[i] == t[0]:
        j, n = i+1, 1
        while j <= len(s_d) - 1 and n <= len(t) - 1:
            if s_d[j] == '?' or s_d[j] == t[n]:
                j += 1
                n += 1
            else:
                break

        if n >= len(t):
            s_d[i:i+len(t)] = t
            break
else:
    print("UNRESTORABLE")
    flg = False

if flg:
    for i in range(len(s_d)):
        if s_d[i] == '?':
            s_d[i] = 'a'

    print("".join(s_d))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}




int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	ll a, b;
	cin >> a >> b;
	cout << a * b << endl;


	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int n,dp[3][100005],a[100005],b[100005],c[100005];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
	dp[0][0]=a[0];
	dp[1][0]=b[0];
	dp[2][0]=c[0];
	for(int i=1;i<n;i++){
		dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
		dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
		dp[2][i]=max(dp[0][i-1],dp[1][i-1])+c[i];
	}
	cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
}


Measured memory_bytes: 2560
class SegmentTree():
	def __init__(self,n):
		self.dat = [0 for _ in range(n*2-1)]
		#index n???????????????????????¢?????????:
		#???????????? : (n-1)//2
		#???????????? : (2n+1) , (2n+2)
		self.n = n

	def update (self,node_index,value):
		""" index?????????value????????´?????? """
		index = node_index + (self.n-1) #node_index????????????dot???index?????????
		self.dat[index] += value

		#?????°????????????????????????????????´????????????
		while index > 0 :
			index = (index - 1) // 2				 #???????????????????????£???
			self.dat[index] = self.dat[index*2+1] + self.dat[index*2+2] #??????????????????????????????

	def querry (self,left,right,nowNode,nowLeft,nowRight):
		"""[left,right):??¢?´¢??????,noeNode:?????¨????????????,[nowLeft,nowRight):?????¨?????????????????????"""

		# ??????????????¶??£????????????
		if nowRight < left or nowLeft > right:
			return 0

		# ?????¨?????¢?´¢???????????¨????????????????????????????????????
		if left <= nowLeft and nowRight <= right:
			return self.dat[nowNode]

		# ???????????????????????????????????¨???????????????
		else:
			value_left = self.querry(left,right,2*nowNode+1,nowLeft,(nowLeft+nowRight)//2)
			value_right = self.querry(left,right,2*nowNode+2,(nowLeft+nowRight)//2+1,nowRight)
			return (value_left + value_right)

	def DEBUG_dat(self):
		print(self.dat)


if __name__ == "__main__":
	n ,q  = map(int,input().split(" "))
	result = []

	for i in range(1,20):
		if 2 ** i >= n:
			min_pow2 = 2 **  i
			break

	tree = SegmentTree(min_pow2)

	for i in range(q):
		com,x,y = map(int,input().split(" "))
		if com == 0:
			tree.update(x-1,y)
		else:
			result.append(tree.querry(x-1,y-1,0,0,min_pow2-1))

	for ans in result:
		print(ans)

Measured memory_bytes: 13140
#include <iostream>
using namespace std;
int main(void){
    int N, M, C, B[20], A[20][20], cnt = 0, tmp;
    cin >> N >> M >> C;
    for (int i = 0; i < M; i++) cin >> B[i];
    for (int i = 0; i < N; i++) {
        tmp = C;
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
            tmp += A[i][j] * B[j];
        }
        if (tmp > 0) cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main()
{
  int N, M; cin >> N >> M;
  const int MAX_NUM = 1000007;
  int broken_floor[MAX_NUM];
  long long int dp[MAX_NUM];
  for (int i=1; i<=M; i++) {
    int a; cin >> a;
    broken_floor[a] = 1;
  }
  
  dp[0] = 1;
  dp[1] = 1;
  for (int i=2; i<=N; i++) {
    if (broken_floor[i]) {
      //cout << dp[i] << endl;
      continue;
    }
    if (! broken_floor[i-1]) {
      dp[i] += dp[i-1];
      dp[i] %= MOD;
    }
    if (! broken_floor[i-2]) {
      dp[i] += dp[i-2];
      dp[i] %= MOD;
    }
  }
  cout << dp[N] << endl;
  
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

int main()
{
	int a, b, d, r;
	double f;

	cin >> a >> b;

	d = a / b;
	r = a % b;

	f = double(a) / b;

	cout << d << " " << r << " " << fixed << setprecision(20) 
		 << f << endl;

    return 0;
}


Measured memory_bytes: 3260
//Author - Sanket Mundra
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define IIITA ios::sync_with_stdio(0)
#define sanket cin.tie(0)
#define mundra cout.tie(0)
ll M = 1000000007;

int main()
{
	IIITA; sanket; mundra;
	ll t,i,j,n,m,l,k,r,sum,ans,mx,mn,x,y,z;
	cin>>i>>j;
	cout<<6-i-j<<endl;
	return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
if a == 5 and b == 5 and c == 7:
    print("YES")
elif a == 5 and b == 7 and c == 5:
    print("YES")
elif a == 7 and b == 5 and c == 5:
    print("YES")
else:
    print("NO")
   

Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

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

	int ans = 0;
	for (int i = 0;i < 10;i++) {
		for (int j = 0;j < 10;j++) {
			for (int k = 0;k < 10;k++) {
				int flag_i = 0, flag_j = 0;
				for (int l = 0;l < s.length();l++) {
					if (flag_j == 1) {
						if (s[l] - 48 == k) {
							ans++;
							break;
						}
					}
					else {
						if (flag_i == 1) {
							if (s[l] - 48 == j) flag_j = 1;
						}
						else {
							if (s[l] - 48 == i) flag_i = 1;
						}
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> ans;
    for (int i = 1; i <= 100; ++i) {
        if ((A % i == 0) && (B % i == 0)) ans.push_back(i);
    }
    sort(ans.begin(), ans.end(), greater<>());
    cout << ans[K - 1] << endl;
}

Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

def bfs(start):
    d = [-1]*n
    d[start] = 0
    q = collections.deque([start])
    while q:
        p = q.popleft()
        next_v = edge[p]
        for v in next_v:
            if d[v] == -1:
                q.append(v)
                d[v] = d[p] + 1
    return d

if __name__ == "__main__":
    n = int(input())
    edge = []
    for i in range(n):
        u,k,*v_li = map(int,input().split())
        u-=1
        for j in range(len(v_li)):
            v_li[j] -= 1
        edge.append(v_li)
    ans = bfs(0)
    for i in range(n):
        print(i+1,ans[i])



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

vector<int> ar[(int)1e5+10];
int dp[(int)1e5+10];

// return longest path from node

int dfs(int node, int par = -1) {
    if(dp[node] != 0) return dp[node];
    int res = 0;
    for(int ch: ar[node]) {
        if(ch != par) {
            int cur = dfs(ch, node);
            res = max(res, cur+1);
        }
    }
    return dp[node] = res;
}

int main() {
    int v, e; cin >> v >> e;
    for(int i=0; i<e; ++i) {
        int a, b; cin >> a >> b;
        ar[a].push_back(b);
    }

    int ans = 0;
    for(int i=1; i<=v; ++i) {
        ans = max(ans, dfs(i));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 8832
N, M = map(int, input().split())
e=[[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    e[a].append(b)
    e[b].append(a)

from collections import deque
def dws(st):
  ret = 0
  q = deque([])   # キュー
  q.append(st)
  while len(q) > 0:
    p = q.popleft()
    if len(p)==N:
      ret += 1
    else:
      for a in e[p[-1]]:
        if not a in p:
          q.append(p+[a])    # キュー追加
  return ret
print(dws([1]))

Measured memory_bytes: 4084
// @samaranand
//
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define int64 long long
#define VI vector < int >
#define VII vector < vector < int > >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define pii pair < int , int >
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define sz(v) v.size()
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
//const long long biGinf = 9e+18;
const char nwl = '\n';

int visit[100005];


int fun(VI &v, int n, int m = 0) {
	if (m + 1 == n - 1) {
		visit[m + 1] = abs(v[m] - v[m + 1]);
		return abs(v[m] - v[m + 1]);
	} else if (m + 2 == n - 1) {
		visit[m + 2] = abs(v[m] - v[m + 2]);
		return abs(v[m] - v[m + 2]);
	}
	else  {
		int a;
		if (visit[m + 1] != -1)
			a = visit[m + 1] + abs(v[m + 1] - v[m]);
		else {
			visit[m + 1] = fun(v, n, m + 1);
			a = visit[m + 1] + abs(v[m + 1] - v[m]);
		}
		int b;
		if (m + 2 <= n - 1) {
			if (visit[m + 2] != -1)
				b = visit[m + 2] + abs(v[m + 2] - v[m]);
			else {
				visit[m + 2] = fun(v, n, m + 2);
				b = visit[m + 2] + abs(v[m + 2] - v[m]);
			}

		}
		else
			b = inf;
		//cout << "a " << a << " b " << b << nwl;
		return min(a, b);
	}
}


int main() {

	//ur code
	for (int i = 0; i < 100005; i++)
		visit[i] = -1;
	int n;
	cin >> n;
	VI v(n);
	inpv(v);
	cout << fun(v, n);
	//cout << "\ntest done";
	return 0;
}

Measured memory_bytes: 7296
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n>999)cout<<"ABD"<<endl;
	else cout<<"ABC"<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
const int p=1000000007;
using namespace std;
struct node{
	int a,b;
};
int n,k,dp[102][64000],sum[102][64000];
vector<node>num;
int main(){
	scanf("%d%d",&n,&k);
	int x=1;num.push_back((node)<%0,0%>);
	while(x<=n){
		int t=n/x,y=n/t;
		num.push_back((node)<%x,y%>);
		x=y+1;
	}
	int v=num.size();
	for(int i=1;i<v;i++){
		dp[1][i]=num[i].b-num[i].a+1;
		sum[1][i]=(sum[1][i-1]+dp[1][i])%p;
	}
	for(int i=2;i<=k;i++){
		for(int j=1;j<v;j++){
			dp[i][j]=1ll*sum[i-1][v-j]*(num[j].b-num[j].a+1)%p;
			sum[i][j]=(sum[i][j-1]+dp[i][j])%p;
//			printf("sum=%d\n",dp[i][j]);
		}
	}
	printf("%d\n",sum[k][v-1]);
	return 0;
}

Measured memory_bytes: 51320
fn main() {
    let s: String = read();
    let n: usize = read();
    let mut rev = false;
    let mut v: Vec<Vec<char>> = vec![vec![]; 2]; // index: 0 のときは front, index: 1のときは back
    for _ in 0..n {
        let op: usize = read();
        match op {
            1 => rev = !rev,
            2 => {
                let f: usize = read();
                let c = read::<String>().chars().next().unwrap();
                match f {
                    // reverse 状態のときは、 front end も行動を反転する
                    1 => v[if rev { 1 } else { 0 }].push(c),
                    2 => v[if rev { 0 } else { 1 }].push(c),
                    _ => unreachable!(),
                }
            }
            _ => unreachable!(),
        }
    }
    let c: String = if rev { s.chars().rev().collect() } else { s };
    let f: String = v[if rev { 1 } else { 0 }].iter().cloned().rev().collect();
    let b: String = v[if rev { 0 } else { 1 }].iter().cloned().collect();
    println!("{}{}{}", f, c, b);
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let token: String = cin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 6652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const ll mod = 1e9+7;

main(){
    int x;cin>>x;
    if(x) cout<<"0";
    else cout<<"1";
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <list>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (int i = 0; i<vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

int SumDigitValues(int x)
{
	int sum = 0;
	while (x)
	{
		sum += x % 10;
		x = x / 10;
	}

	return sum;
}

int Factorial(int n)
{
	if (n < 0) return 0;
	if (n == 0) return 1;
	return n * Factorial(n - 1);
}

int factorial(int n)
{
	if (n > 1)
	{
		return n * factorial(n - 1);
	}
	else
	{
		return 1;
	}
}

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

	int cnt = 0;
	for (int num = 1; num <= n; num++)
	{
		if (num % 2 != 0) cnt++;
	}

	cout << ((float)cnt / n) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  while(1) {
    int m, f, r, mf;
    string result;
    cin >> m >> f >> r;
    mf = m + f;
    if (m == -1 && f == -1 && r == -1) break;
    if ((m == -1 || f == -1) || (mf < 30)) {
      result = "F";
    } else if ((50 <= mf && mf < 65) || (30 <= mf && mf < 50 && r >= 50)) {
      result = "C";
    } else if (30 <= mf && mf < 50) {
      result = "D";
    } else if (65 <= mf && mf < 80) {
      result = "B";
    } else if (80 <= mf) {
      result = "A";
    }
    cout << result << endl;
  }
}


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

#define se second
#define fi first
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;

int cnt[1000];

int main(){
    int n;
    scanf("%d", &n);
    while (n--){
        int temp;
        scanf("%d", &temp);
        cnt[temp] = 1;
    }

    int ans = 0;
    for (int i = 0; i <= 100; i++)
        ans += cnt[i];

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
fun main(args:Array<String>):Unit {
    val (d, n) = readLine()!!.trim().split(' ').map(String::toInt)
    println(
            if (n == 100) digit(d) * 101
            else digit(d) * n
    )
}
fun digit(d:Int):Int {
    return when(d){
        0 -> 1
        else -> digit(d - 1) * 100
    }
}

Measured memory_bytes: 38192
def GCD(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    else:
        return GCD(b, a % b)


def LCM(a, b):
    return a * b // GCD(a, b)

n, m = [int(i) for i in input().split()]
s = input()
t = input()

l = LCM(n, m) # = 45
k = l//GCD(n, m) # = 15
flag = True
for i in range(l//k):
    if s[k*i//(l//n)] != t[k*i//(l//m)]:
        flag = False

if flag:
    print(l)
else:
    print(-1)

Measured memory_bytes: 3316
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll
const long double pi = 3.14159265358979323846;

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,b; cin >> a >> b;
    ll c,d; cin >> c >> d;
    ll ans = -INF;
    chmax(ans, a * c);
    chmax(ans, a * d);
    chmax(ans, b * c);
    chmax(ans, b * d);

    cout << ans << "\n";
}

Measured memory_bytes: 3652
s = input()
c = 0
if s[0] == 'A':
    for i in range(2,len(s)-1):
        if s[i] == 'C':
            c += 1
    if c != 1:
        print("WA")
        exit(0)
    else:
        for i in s:
            if i != 'A' and i != 'C':
                if not i.islower():
                    print("WA")
                    exit(0)
    print("AC")
else:
    print("WA")
    exit(0)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define PB push_back
using namespace std;
typedef vector<int> VI;

int n, k;
VI books[11];

int dp[11][2010];

int main()
{
  scanf("%d%d", &n, &k);
  for(int i = 0; i < n; i++){
    int c, g;
    scanf("%d%d", &c, &g);
    books[g].PB(c);
  }

  for(int i = 1; i <= 10; i++)
    sort(books[i].begin(), books[i].end(), greater<int>());

  for(int i = 1; i <= 10; i++)
    for(int j = 1; j < books[i].size(); j++)
      books[i][j] += books[i][j - 1] + 2 * j;

  for(int i = 1; i <= 10; i++)
    for(int j = 0; j <= k; j++)
      for(int j2 = 0; j2 <= books[i].size() && j - j2 >= 0; j2++)
	dp[i][j] = max(dp[i][j], dp[i - 1][j - j2] + (j2 ? books[i][j2 - 1] : 0));
  
  printf("%d\n", dp[10][k]);
  return 0;
}

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

int s,t,V,E;
bool flag[10100]={false};
vector<int> A[10100];
list<int> ans;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

void dfs(int u){
    flag[u]=true;
    for(int i=0;i<A[u].size();++i){
        int v=A[u][i];
        if(flag[v]==false){
            dfs(v);
        }
    }
    ans.push_front(u);
}

void tp_srt(){
    for(int i=0;i<V;++i){
        if(flag[i]==false) dfs(i);
    }
}

int main(){
    cin>>V>>E;
    Fill(flag,false);
    for(int i=0;i<E;++i){
        cin>>s>>t;
        A[s].push_back(t);
    }

    tp_srt();

    for(list<int>::iterator i=ans.begin();i!=ans.end();++i){
        cout<<*i<<"\n";
    }
}


Measured memory_bytes: 4096
#include <algorithm>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using ll = long long;
using namespace std;
static ll imin = std::numeric_limits<ll>::min() / 2;
static ll imax = std::numeric_limits<ll>::max() / 2;
#define rep(i, n) for (ll i = 0; (i) < (n); ++(i))
#define rep1(i, n) for (ll i = 1; (i) < (n); ++(i))
#define rev_rep(i, n) for (ll i = (n)-1; (i) >= 0; --(i))
#define range(a, i, b) for (ll i = (a); (i) < (b); ++(i))

#ifdef LOCAL
#define dump(x) cout << #x << ":" << x << "\n";
#endif
#ifndef LOCAL
#define dump(x)
#endif

#define all(v) v.begin(), v.end()
#define readl(N) \
  ll N;          \
  cin >> N
#define readlv(N, vec) \
  vector<ll> vec(N);   \
  rep(i, N) { cin >> vec[i]; }
#define greater_than [](ll l, ll r) { return l > r; }
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, std::map<T1, T2>& mp);
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& pair);
template <class T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& vec);
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& pair) {
  os << '(' << pair.first << ',' << pair.second << ')';
  return os;
}

template <class T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& vec) {
  std::size_t n = vec.size();
  if (n == 0) {
    return os;
  }
  os << " ";
  for (ll i = 0; i < n - 1; ++i) {
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, std::map<T1, T2>& mp) {
  std::size_t n = mp.size();
  if (n == 0) {
    return os;
  }
  os << " ";
  for (auto&& x : mp) {
    os << x << " ";
  }
  os << std::endl;
  return os;
}

template <class T>
std::ostream& operator<<(std::ostream& os, std::set<T>& mp) {
  std::size_t n = mp.size();
  if (n == 0) {
    return os;
  }
  os << " ";
  for (auto&& x : mp) {
    os << x << " ";
  }
  os << std::endl;
  return os;
}

template <class T>
inline bool chmin(T& a, T const b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T const b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll fact(ll n) {
  ll res = 1;
  while (n > 0) {
    res *= n;
    n--;
  }
  return res;
}

ll pow(ll i, ll n) {
  ll res = 1;
  while (n >= 0) {
    res *= i;
    n--;
  }
  return res;
}

ll gcd(ll l, ll r) {
  if (l < r) {
    return gcd(r, l);
  }
  if (r == 0) {
    return l;
  }
  return gcd(r, l % r);
}

template <class T>
vector<T> accum_sum(vector<T> a) {
  vector<T> b(a.size() + 1);
  b[0] = a[0];
  rep(i, a.size()) { b[i + 1] = b[i] + a[i]; }
  return b;
}
constexpr ll mod = 1e9 + 7;
int main(int argc, char const* argv[]) {
  readl(N);
  ll prev = 0;
  ll res = 0;
  rep(i, N) {
    ll x;
    cin >> x;
    dump(x);
    dump(prev);
    dump(x - prev);
    if (x - prev > 0) {
      res += x - prev;
    }
    prev = x;
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
 int N = 0;
  
  if (scanf("%d", &N) < 1) {
    return 1;
  }
  if (N < 1 || 100 < N) {
    return 2;
  }
  
  int i;
  int total = 0;
  for (i = 1; i <= N; i++) {
    total += i;
  }
  
  printf("%d", total);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, i = 1;
    cin >> N;
    if(N == 1) {
        cout << 1 << endl;
    } else {
        while(N > i * (i + 1) / 2)
            i++;
        cout << i << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#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 vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	ll n;cin>>n;
	if(n==0) {cout<<0<<endl;return 0;}
	string ans;
	ll b=1;
	while(n!=0){
		if((n/b)%2!=0) {ans+='1';n-=b;}
		else ans+='0';
		b*=-2;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
    S.append(input())
print('AC x ' + str(S.count('AC')))
print('WA x ' + str(S.count('WA')))
print('TLE x ' + str(S.count('TLE')))
print('RE x ' + str(S.count('RE')))

Measured memory_bytes: 16280
from bisect import bisect_left, bisect_right

N = int(input())
Ls = list(map(int, input().split()))

Ls.sort()
#print(Ls)

ans = 0
for i in range(N):
    for j in range(i+1, N):
        k = bisect_left(Ls, Ls[i]+Ls[j])
        ans += k-j-1
print(ans)


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

namespace AtCoderCore {
	public class Program {
		private const int MOD = 1000000007;

		static void Main (string[] args) {
			long[] ab = Console.ReadLine ().Split (' ').Select (x => long.Parse (x)).ToArray ();
			long a = ab[0];
			long b = ab[1];
			
			long pre = 0;
			bool isPre = false;
			if(a % 2 == 1){
				pre = a;
				isPre = true;
				a += 1;
			}

			long post = 0;
			bool isPost = false;
			if(b % 2 == 0){
				post = b;
				isPost = true;
				b -= 1;
			}

			long count = Math.Max(0, (b - a + 1) / 2);
			long c = count % 2 == 0 ? 0 : 1;
			long ans = c;
			if(isPre){
				ans ^= pre;
			}

			if(isPost){
				ans ^= post;
			}

			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 13268
#include <iostream>
using namespace std;
int main() {
	int a[3];
	int tmp;

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

	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 3; j++) {
			if (a[i] > a[j]) {
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	cout << a[0] << " " << a[1] << " " << a[2] << "\n";

	return 0;
}

Measured memory_bytes: 1164
import           Data.List (sort)
  
main :: IO ()
main = do
    [n, x] <- map read . words <$> getLine
    as <- map read . words <$> getLine
    print $ solve n x as

solve :: Int -> Int -> [Int] -> Int
solve n x as
    | sum as == x = n
    | sum as < x = n - 1
    | otherwise = length $ takeWhile (<= x) $ scanl1 (+) $ sort as

Measured memory_bytes: 1020
package main

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

func main() {
	N := ReadInt()
	adjL := make([][]int, N)
	for i := 0; i < N-1; i++ {
		a, b := ReadInt()-1, ReadInt()-1
		adjL[a] = append(adjL[a], b)
		adjL[b] = append(adjL[b], a)
	}
	c := ReadInts(N)
	sort.Sort(sort.Reverse(sort.IntSlice(c)))
	sum := 0
	for _, score := range c[1:] {
		sum += score
	}
	ans := make([]int, N)
	order := 0
	seen := make([]bool, N)
	var dfs func(v int)
	dfs = func(v int) {
		if seen[v] {
			return
		}
		seen[v] = true
		ans[v] = c[order]
		order++
		for _, u := range adjL[v] {
			dfs(u)
		}
	}
	dfs(0)

	fmt.Println(sum)
	for _, a := range ans {
		fmt.Printf("%d ", a)
	}
	fmt.Println()
}

func dfs(adjL [][]int, c []int, seen []bool, v int, order int, ans []int) {
	if seen[v] {
		return
	}
	seen[v] = true
	ans[v] = c[order]

}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 4664