akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;

using ll = long long;
const int N = 1e5+5;

int main()
{
    ios_base::sync_with_stdio(0);

    int n,mx = 0;
    cin >> n;
    map<string,int> mp;
    for(int i = 0; i < n; ++i) {
        string s; cin >> s;
        mp[s]++;
        mx = max(mx, mp[s]);
    }
    vector<pair<int,string>> a;
    for(auto itr : mp) {
        a.push_back({itr.second, itr.first});
    }
    sort(a.rbegin(), a.rend());

    vector<string> ans;
    for(auto itr : a) {
        if(itr.first == mx) ans.push_back(itr.second);
        else break;
    }
    sort(ans.begin(), ans.end());
    for(auto itr : ans)
        cout << itr << "\n";
    return 0;
}


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

int main(){
  deque<int> deq;
  string str;
  int a,b;

  while(cin >> str){
    if(str == "+"){
      a = deq.front(); deq.pop_front();
      b = deq.front(); deq.pop_front();
      deq.push_front(a+b);
    }else if(str == "-"){
      b = deq.front(); deq.pop_front();
      a = deq.front(); deq.pop_front();
      deq.push_front(a-b);
    }else if(str == "*"){
      a = deq.front(); deq.pop_front();
      b = deq.front(); deq.pop_front();
      deq.push_front(a*b);
    }else if(str == "/"){
      b = deq.front(); deq.pop_front();
      a = deq.front(); deq.pop_front();
      deq.push_front(a/b);
    }else{
      deq.push_front(stoi(str));
    }
  }
  cout << deq.front() << endl;
}


Measured memory_bytes: 3196
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;
using P = pair<int, int>;


ull E = 1000000007;

int main() {
    string w;
    cin >> w;
    map<char, int> m;
    for (char c : w) {
        ++m[c];
    }
    for (const auto& i : m) {
        if (i.second % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

#define min(a,b) ((a<b) ? a : b)

int cost[10][10];

void calcPath(int n)
{
    int s,i,j,k,d;

    for (s = 0 ; s < 45 ; s++) {
        for (i = 0 ; i <= n ; i++) {
            for (j = 0 ; j <= n ; j++) {
                d = cost[i][j];
                for (k = 0 ; k <= n ; k++) {
                    if ( (cost[i][k] < 0) || (cost[k][j] < 0) ) continue;
                    d = (d >= 0) ? min(d,cost[i][k]+cost[k][j]) : cost[i][k]+cost[k][j];
                }
                cost[i][j] = d;
            }
        }
    }
}

// ----------------------------------------------------------------
int main(void)
{
    int i,j,len, minpath,n, townA, townB, t, townLast, bestTownNo;

    while(cin >> n) {
        if (n <= 0) break;
        // Initialize variables
        memset(cost,-1,sizeof(cost));
        townLast = -1;
        // read & set data
        for (i = 0 ; i < n ; i++) {
            cin >> townA;
            cin >> townB;
            cin >> t;  // time A->B
            cost[townA][townA] = 0;
            cost[townB][townB] = 0;
            cost[townA][townB] = t;
            cost[townB][townA] = t;
            if (townA > townLast) townLast = townA;
            if (townB > townLast) townLast = townB;
        }
        // calculate minimum path
        calcPath(townLast);
        // find best solution
        bestTownNo = -1;
        minpath = -1;
        for (i = 0 ; i <= townLast ; i++) {
            len = 0;
            for (j = 0 ; j <= townLast ; j++) {
                if(cost[i][j] > 0) len += cost[i][j];
            }
            if ((minpath < 0) || (len < minpath)) {
                minpath = len;
                bestTownNo = i;
            }
        }
        cout << bestTownNo << " " << minpath << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
	string s;
	cin >> s;
	cout << (s == "ABC" ? "ARC" : "ABC") << endl;
}


Measured memory_bytes: 3628
N,K = [int(x) for x in input().split()]
arr=[]
for i in range(N):
    arr.append([int(x) for x in input().split()])
    
arr.sort(key=lambda tup: tup[0])

for i in range(N):
    K=K-arr[i][1]
    if K<=0:
        print(arr[i][0])
        break


Measured memory_bytes: 22872
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
int fg(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
signed main(){
 double a,b,c,d;
  cin>>a>>b>>c>>d;
 double e=c*60+d;
 double h=M_PI/30*d;
  double g=M_PI/360*e;
  double f=fabs(h-g);
  if(f>M_PI){
   double ab=sqrt(a*a+b*b-2*a*b*cos(2*M_PI-f));
    cout<<setprecision(14)<<ab;      }
   else {
   double ac=sqrt(a*a+b*b-2*a*b*cos(f));
     cout<<setprecision(14)<<ac;
              }
}
    

Measured memory_bytes: 4052
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s1 = sc.next().toCharArray();
        char[] s2 = sc.next().toCharArray();
        List<Integer> list = new ArrayList<>();
       list.add(1);
       for (int i = 0 ; i < n - 1 ; i++ ) {
           if (s1[i] == s1[i + 1]) {
               list.set(list.size() - 1, 2);
           } else {
               list.add(1);
           }
        }

       long ans = list.get(0) == 1 ? 3 : 6;
       for (int i = 0 ; i < list.size() - 1 ; i++) {
           if (list.get(i) == 1 && list.get(i + 1) == 1) {
               ans *= 2;
           } else if (list.get(i) == 1 && list.get(i + 1) == 2) {
               ans *= 2;
           } else if (list.get(i) == 2 && list.get(i + 1) == 1) {
           } else {
               ans *= 3;
           }
       }
       System.out.println(ans % 1000000007);
    }

}

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

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 0, cnt = 1;
    while (b > cnt)
    {
        cnt--;
        cnt += a;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using Lint=long long;
template<int mod> class ModInt
{
 private:
    Lint val;
 public:
    Lint value(){ return val; }
    ModInt(Lint x=0){ val=x%mod; }
    ModInt pow(int n){
        ModInt res(1),x(val);
        while(n>0){ if(n&1) res*=x; x*=x; n>>=1; }
        return res;
    }
    ModInt inv(){ return pow(mod-2); }
    ModInt& operator+=(ModInt rhs){ val+=rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator-=(ModInt rhs){ val+=mod-rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator*=(ModInt rhs){ val=val*rhs.val%mod; return *this; }
    ModInt& operator/=(ModInt rhs){ *this*=rhs.inv(); return *this; }
    ModInt operator+(ModInt rhs){ return ModInt(val)+=rhs; }
    ModInt operator-(ModInt rhs){ return ModInt(val)-=rhs; }
    ModInt operator*(ModInt rhs){ return ModInt(val)*=rhs; }
    ModInt operator/(ModInt rhs){ return ModInt(val)/=rhs; }
};
using mint=ModInt<1000000007>;

template<typename T> class BiCoef
{
 public:
    vector<T> fact,ifact,inv;
    BiCoef(int N):fact(N+1),ifact(N+1),inv(N+1){
        fact[0]=ifact[N]=inv[0]=1;
        for(int i=1;i<=N;i++) fact[i]=fact[i-1]*i;
        ifact[N]/=fact[N];
        for(int i=N-1;i>=0;i--) ifact[i]=ifact[i+1]*(i+1);
        for(int i=1;i<=N;i++) inv[i]=ifact[i]*fact[i-1];
    }
    T comb(int n,int k){
        if(n<0 or k<0 or n<k) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

const int mod=1e9+7;

int main()
{
   int N,K; cin>>N>>K;
   vector<int> a(N);
   for(int i=0;i<N;i++) cin>>a[i];
   sort(a.begin(),a.end());

   BiCoef<mint> bc(N);
   mint ans=0;
   for(int i=0;i<N;i++){
      int less=i,more=N-(i+1);
      mint k=bc.comb(less,K-1)-bc.comb(more,K-1);
      ans+=k*mint(a[i]+mod);
   }
   cout<<ans.value()<<endl;
   return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct edge {
    int to;
    int cost;
};

int n;
vector<vector<edge>> graph;

ll prim() {
    vector<bool> used(n);
    rep(i,n) used[i]=false;
    
    priority_queue<pair<int,int> ,vector<pair<int,int>>, greater<pair<int,int>>> que;
    que.push(make_pair(0,0));
    
    ll ret=0;
    
    while(!que.empty()){
        pair<int,int> p=que.top(); que.pop();
        int cost=p.first;
        int v=p.second;
        
        if(used[v]) continue;
        used[v]=true;
        ret+=(ll)cost;
        
        for(edge e:graph[v]){
            que.emplace(e.cost,e.to);
        }
    }
    
    return ret;
    
}

int main() {
    cin>>n;
    vector<pair<int,int>> xs(n),ys(n);
    rep(i,n) {
        int x,y;
        cin>>x>>y;
        xs[i]=make_pair(x,i);
        ys[i]=make_pair(y,i);
    }
    sort(all(xs));
    sort(all(ys));
    
    graph.resize(n);
    rep(i,n-1) {
        edge e={xs[i+1].second,xs[i+1].first-xs[i].first};
        graph[xs[i].second].push_back(e);
        e={xs[i].second,xs[i+1].first-xs[i].first};
        graph[xs[i+1].second].push_back(e);
        
        e={ys[i+1].second,ys[i+1].first-ys[i].first};
        graph[ys[i].second].push_back(e);
        e={ys[i].second,ys[i+1].first-ys[i].first};
        graph[ys[i+1].second].push_back(e);
    }
    
    cout<<prim()<<endl;
    
}


Measured memory_bytes: 11636
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Aug 25 02:43:06 2019
//
package main

import "fmt"

const (
	left  = true
	right = false
	mod   = 1e9 + 7
)

func main() {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)

	if s[0] == 'W' || s[len(s)-1] == 'W' {
		fmt.Println(0)
		return
	}

	pos := make([]bool, 2*n)
	for i := range s {
		if i == 0 {
			pos[i] = left
			continue
		}

		if s[i] == s[i-1] {
			pos[i] = !pos[i-1]
		} else {
			pos[i] = pos[i-1]
		}
	}

	lefts, rights := 0, 0
	ans := 1
	for i := range pos {
		if pos[i] == left {
			lefts++
			continue
		}

		ans *= lefts - rights
		ans %= mod
		rights++
	}

	if lefts != rights || pos[len(pos)-1] != right {
		fmt.Println(0)
		return
	}

	for i := 1; i <= n; i++ {
		ans *= i
		ans %= mod
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2176
#include <stdio.h>          // printf(), scanf()
#include <math.h>           // sqrt()
#include <stdbool.h>

#define MAX_V 100

const int INF = 1000000000;
int V;
double cost[MAX_V][MAX_V];
double d[MAX_V];
int prev[MAX_V];

void
dijkstra(int s)
{
	bool used[MAX_V];

	for (int i = 0; i < V; ++i)
	{
		d[i] = INF;
		used[i] = false;
		prev[i] = -1;
	}

	d[s] = 0.0;
	while (true)
	{
		int v = -1;
		for (int u = 0; u < V; ++u)
		{
			if (!used[u] && (v == -1 || d[u] < d[v]))
				v = u;
		}

		if (v == -1)
			break;

		used[v] = true;
		for (int u = 0; u < V; ++u)
		{
			if (d[v] + cost[v][u] < d[u])
			{
				d[u] = d[v] + cost[v][u];
				prev[u] = v;
			}
		}
	}
}

void
solve(int s, int g)
{
	int path[MAX_V];

	dijkstra(s);
	if (d[g] == INF)
		printf("NA\n");
	else
	{
		int ix = 0;
		for (; g != -1; g = prev[g])
			path[ix++] = g;

		for (int i = ix - 1; i >= 0; --i)
			printf("%d%c", path[i] + 1, (i != 0) ? ' ' : '\n');
	}
}

int
main(int argc, char **argv)
{
	int x[MAX_V], y[MAX_V];

	while (true)
	{
		scanf("%d", &V);
		if (V == 0)
			break;

		for (int i = 0; i < V; ++i)
		{
			x[i] = INF;
			y[i] = INF;
		}

		for (int i = 0; i < V; ++i)
		{
			int b;
			int tx, ty;
			scanf("%d%d%d", &b, &tx, &ty);
			b--;
			x[b] = tx, y[b] = ty;
		}

		for (int i = 0; i < V; ++i)
		{
			for (int j = 0; j < V; ++j)
				cost[i][j] = (i == j) ? 0 : INF;
		}

		for (int i = 0; i < V; ++i)
		{
			for (int j = 0; j < V; ++j)
			{
				if (i != j && x[i] != INF && y[i] != INF)
				{
					int rx = x[i] - x[j], ry = y[i] - y[j];
					double r = sqrt(rx * rx + ry * ry);
					if (r <= 50.0)
					{
						cost[i][j] = r;
						cost[j][i] = r;
					}
				}
			}
		}

		int m;
		scanf("%d", &m);
		for (int i = 0; i < m; ++i)
		{
			int s, g;
			scanf("%d%d", &s, &g);
			s--, g--;
			solve(s, g);
		}
	}

	return 0;
}


Measured memory_bytes: 1756
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <queue>
#include <set>
using namespace std;

int main(){
    string S;
    string tmp;
    std::cin >> S;
    
    bool ans = false;
    if((S[0] == S[1])&&(S[2] == S[3])&&(S[0] != S[2])) ans = true;
    if(S[0] != S[1]){
        if((S[1] == S[2])&&(S[0] == S[3])) ans = true;
        if((S[1] == S[3])&&(S[0] == S[2])) ans = true;
    }
    if(ans){
        std::cout << "Yes" << "\n";
    }else{
        std::cout << "No" << "\n";
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
   
        int n = scan.nextInt();
        int m = scan.nextInt();
        int [][]A;
        A = new int[n][m];
        int []b;
        b = new int[m];
        int []c;
        c = new int[n];
        int i,j;
   
        for(i = 0; i < n; i++){
            for(j = 0; j < m; j++){
            A[i][j] = scan.nextInt();
            }
        }
   
        for(j = 0; j < m ; j++){
        b[j] = scan.nextInt();
        }
   
        for(i = 0; i < n; i++){
            for(j = 0; j < m; j++){
            c[i] += A[i][j]*b[j];
            }
            System.out.println(c[i]);
        }
    }
}

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

int G[100][100];
int d[100];

void init_d(int n){
    rep(i,n){
        d[i]=-1;
    }
}
void input_graph(int n){
    int u,k,v;
    rep(i,n){
        scanf("%d %d",&u,&k);
        u--;
        rep(j,k){
            scanf("%d",&v);
            v--;
            G[u][v] = 1;
        }
    }
}
void bfs(int s,int n){    
    queue<int> que;
    que.push(s);
    while(que.size()>0){
        int u = que.front();
        que.pop();
        rep(i,n){
            if(G[u][i]==1 && d[i] == -1){
                d[i]=d[u]+1;
                que.push(i);
            }
        }
    }
}
void print_graph(int n){
    rep(i,n){
            printf("%d %d\n",i+1,d[i]);
    }
}

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int n;
    cin >> n;
    init_d(n);
    input_graph(n);
    d[0]=0;
    bfs(0,n);
    print_graph(n);
}


Measured memory_bytes: 3268
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int K, X;
	
	cin>>K>>X;
	
	if(500 * K >= X) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int J[1011][1011],O[1011][1011],I[1011][1011];
int a[100001],b[100001],c[100001],d[100001];
char joi[1001][1001];
int main(void)
{
	int M,N,K,i,j,sumJ,sumO,sumI;
	scanf("%d%d%d",&M,&N,&K);
	for(i=1;i<=M;i++){
		for(j=1;j<=N;j++){
			scanf(" %c",&joi[i][j]);
		}
	}
	for(i=1;i<=M;i++){
		for(j=1;j<=N;j++){
			J[i][j]=0;
			O[i][j]=0;
			I[i][j]=0;
		}
	}
	for(i=1;i<=M;i++){
		for(j=1;j<=N;j++){
			if(joi[i][j]=='J'){
				J[i][j]++;
			}
			if(joi[i][j]=='O'){
				O[i][j]++;
			}
			if(joi[i][j]=='I'){
				I[i][j]++;
			}
			J[i][j+1]+=J[i][j];
			O[i][j+1]+=O[i][j];
			I[i][j+1]+=I[i][j];
		}
	}
	for(i=1;i<=N;i++){
		for(j=1;j<M;j++){
			J[j+1][i]+=J[j][i];
			O[j+1][i]+=O[j][i];
			I[j+1][i]+=I[j][i];
		}
	}
	for(i=1;i<=K;i++){
		scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
	}
	for(i=1;i<=K;i++){
		sumJ=0;
			sumJ+=J[c[i]][d[i]];
			sumJ-=J[a[i]-1][d[i]];
			sumJ-=J[c[i]][b[i]-1];
			sumJ+=J[a[i]-1][b[i]-1];
		sumO=0;
			sumO+=O[c[i]][d[i]];
			sumO-=O[a[i]-1][d[i]];
			sumO-=O[c[i]][b[i]-1];
			sumO+=O[a[i]-1][b[i]-1];
		sumI=0;
			sumI+=I[c[i]][d[i]];
			sumI-=I[a[i]-1][d[i]];
			sumI-=I[c[i]][b[i]-1];
			sumI+=I[a[i]-1][b[i]-1];
		printf("%d %d %d\n",sumJ,sumO,sumI);
	}
	return 0;
}

Measured memory_bytes: 16832
#include<iostream>
using namespace std;
int main(){
  long long n,i,l,r,p,b4p,w,b4w;
char s[11];
  cin>>n;
l=0;
r=n;
cout<<"0"<<endl;
cin>>s;
if(s[0]=='V')
return 0;
if(s[0]=='M')
b4w=0;
else
b4w=1;
b4p=0;
while(1){
p=(l+r)/2;
cout<<p<<endl;
cin>>s;
if(s[0]=='V')
return 0;
if(s[0]=='M')
w=0;
else
w=1;
if(abs(p-b4p+w-b4w)%2==0){
if(p>b4p)
l=p;
else
r=p;
}
else{
if(p>b4p)
r=p;
else
l=p;
}
b4p=p;
b4w=w;
}
}


Measured memory_bytes: 852
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
int n,m,dist[N],pre[N];
vi v[N];
queue<int>q;
signed main()
{
	Very_fast;
	cin>>n>>m;
	rep(i,m)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	pre[0]=-1;
	q.push(0);
	while(!q.empty())
	{
		int now=q.front();q.pop();
		for(int i=0;i<v[now].size();i++)
		{
			int to=v[now][i];
			if(!pre[to])
			{
				pre[to]=now+1;
				q.push(to);
			}
		}
	}
	bool flag=true;
	rep(i,n-1)
	{
		if(!pre[i+1])
			flag=false;
	}
	if(!flag)
		cout<<"No\n";
	else{
		cout<<"Yes\n";
		rep(i,n-1)cout<<pre[i+1]<<"\n";
	}
	return 0;
}

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


int main(){
    int n,m;
    cin >> n >> m;
    vector<bool> flg(n,false);
    vector<int> penalty(n);
    int ans = 0;
    rep(i,m){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s=="AC" && flg[p]==false) {
            flg[p]=true;
            ans++;
        }
        else if(s=="WA" && flg[p]==false) penalty[p]++;
    }
    int ans_pnl = 0;
    rep(i,n){
        if(flg[i]==true) ans_pnl+=penalty[i];
    }
    cout << ans << " " << ans_pnl << endl;
    return 0;
}

Measured memory_bytes: 3724
use std::io::*;

fn main() {
    let a = read();
    let b = read();
    let h = read();

    println!("{}", (a + b) * h / 2);
}

fn read() -> usize {
    let s = stdin();
    let b = s.bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    b.parse::<usize>().ok().unwrap()
}

//fn read_vec() -> Vec<char> {
//    let mut s = String::new();
//    stdin().read_line(&mut s).expect("poi");
//    s.chars().collect()
//}


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


Measured memory_bytes: 3152
import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
    int i =1;
    while(kbd.hasNext()){
        int x = kbd.nextInt();
        if(x!=0){
        System.out.println("Case "+i+": "+x);
        i++;
        }
    }
    }
}

Measured memory_bytes: 33056
#include <cstdio>
#include <algorithm>
using namespace std;

int arr[300000];

int main() {
	int n;
	scanf("%d", &n);
	for(int i=0; i<3*n; i++) 
		scanf("%d", &arr[i]);

	sort(arr, arr+3*n);
	int cnt=0;
	long long ans=0;
	for(int i=3*n-2; cnt!=n; i-=2, cnt++)
		ans+=arr[i];	

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


Measured memory_bytes: 1280
#include <iostream>

using namespace std;

int main(void) {
	int num, k, all, i, j;
	cin >> num >> k;
	all = (num - 1) * (num - 2) / 2;
	if (k > all) {
		printf("-1\n");
		return 0;
	}
	printf("%d\n", num - 1 + all - k);
	for (i = 2; i <= num; i++)
		printf("1 %d\n", i);
	for (i = 2; i < num; i++) {
		if (all == k)
			break;
		for (j = i + 1; j <= num; j++) {
			printf("%d %d\n", i, j);
			all--;
			if (all == k)
				break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  int cards[4][13];
  rep(i, 4){
    rep(j, 13){
      cards[i][j] = 0;
    }
  }

  rep(i, n){
    string s;
    int num;
    cin >> s >> num;
    num -= 1;
    if(s == "S"){
      cards[0][num] = 1;
    }else if(s == "H"){
      cards[1][num] = 1;
    }else if(s == "C"){
      cards[2][num] = 1;
    }else if(s == "D"){
      cards[3][num] = 1;
    }   
  }
  
  rep(i, 4){
    rep(j, 13){
      if(cards[i][j] == 0){
      	if(i == 0) cout << "S ";
        else if(i == 1) cout << "H ";
        else if(i == 2) cout << "C ";
        else if(i == 3) cout << "D ";
        cout << j+1 << endl;
      }   
    }
  }
  return 0;
}



Measured memory_bytes: 3232
#include<iostream>

using namespace std;

struct Peoplesum{
	int rooms[30];		
};

int main() {
	
	Peoplesum A[4];
	int n;
	
	while( cin >> n) {
		
		int b, r, f, v;
		
		for(int i=0;i<4;i++) {
			
			for(int j=0;j<30;j++)
			
			A[i].rooms[j] = 0;
			
		}
		
		for(int i=0;i<n;i++){
			
			cin >> b >> r
				>> f >> v;
			
			A[b-1].rooms[(r-1)*10+f-1] += v;
			
		}
		
		for(int i=0;i<4;i++) {
			
			for(int j=0;j<30;j++) {
				
				cout <<" " << A[i].rooms[j];
				
				if( (j + 1 ) % 10 ==0 )
				cout << "\n";

			}
			for(int k=0;k<20;k++){
			if( i == 3)
			continue;
			else
			cout <<"#";
		}
			if( i != 3)
			cout << "\n";
		}
		
	}
	
	return 0;
}


Measured memory_bytes: 3088
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		ll n,d;
		ll ans = 0;
		scanf("%lld %lld",&n , &d);
		while (n--)
		{
			ll a,b;
			scanf("%lld%lld",&a,&b);
			if (sqrt(a*a + b*b) <= d)
			ans++;
	//		cerr << imie(ans) << endl;
		}
		printf("%lld",ans);
		
 
return 0;
}  

/*
               
 

*/


Measured memory_bytes: 3800
# -*- coding: utf-8 -*-
import sys, re

N = input()
S = input()
sentence = ''
left, right = 0, 0
for s in S:
    sentence += s
    if s == '(':
        left += 1
    else:
        right += 1
    if left - right < 0:
        sentence = '(' + sentence
        left += 1
if left - right > 0:
    sentence = sentence + ')' * (left - right)
print(sentence)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p[19];
int D;
ll floor(ll x,ll y){
    return x/y-((x^y)<0&&x%y);
}
int main(){
    scanf("%d",&D);
    p[0]=1;
    for(int i=1;i<=18;i++)p[i]=p[i-1]*10;
    ll ans=0;
    function<void(int,int,ll,ll)> dfs=[&](int p1,int p2,ll diff,ll coeff){
        if(p1>=p2){
            if(p1==p2)coeff*=10;
            if(diff==0)ans+=coeff;
            return;
        }
        ll x=p[p2]-p[p1];
        {
            ll i=floor(diff,x);
            ll nd=diff-i*x,nc=coeff;
            if(abs(nd)<x&&abs(i)<=9){
                nc*=10-abs(i);
                if(p1==0)nc--;
                dfs(p1+1,p2-1,nd,nc);
            }
        }
        {
            ll i=floor(diff,x)+1;
            ll nd=diff-i*x,nc=coeff;
            if(abs(nd)<x&&abs(i)<=9){
                nc*=10-abs(i);
                if(p1==0)nc--;
                dfs(p1+1,p2-1,nd,nc);
            }
        }
    };
    for(int i=1;i<=18;i++)dfs(0,i-1,D,1);
    printf("%lld\n",ans);
    return 0;
}

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

long N;
long A[200001];
long C[200001];

int main(){
    cin>>N;
    for(long i=1;i<=N;i++){
        cin>>A[i];
        C[A[i]]++;
    }

    //for(long i=1;i<=N;i++){
    //    cout<<C[i]<<endl;
    //}

    long sum=0;
    for(long i=1;i<=N;i++){
        if(C[i]>=2){
            sum+=C[i]*(C[i]-1)/2;
        }
    }
    //cout<<sum<<endl;

    long ans;
    for(long i=1;i<=N;i++){
        if(C[A[i]]>=2){
            ans=sum-(C[A[i]]-1);
        }else{
            ans=sum;
        }
        cout<<ans<<endl;
    }
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  string s;
  cin >> s;
  int ans = 0;
  if (s.find("RRR") == 0) {
    ans = 3;
  } else if (s.find("RR") == 0 || s.find("RR") == 1) {
    ans = 2;
  } else if (s.find("R") <= 2) {
    ans = 1;
  } else {
    ans = 0;
  }
  cout << ans << endl;
}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

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

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

int main() {
    string s;
    cin >> s;
    if (s.find('7') != string::npos)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3588
import fractions
N,K=map(int,raw_input().split())
A=map(int,raw_input().split())

for i in range(N):
	if i==0:
		pass
	elif i==1:
		g=fractions.gcd( A[0] , A[1] )
	else:
		g=fractions.gcd( g , A[i] )

if K==max(A):
	print "POSSIBLE"
elif K<max(A):
	if K%g==0:
		print "POSSIBLE"
	else:
		print "IMPOSSIBLE"
else:
	print "IMPOSSIBLE"		



Measured memory_bytes: 45592
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,q,com,b,e;
    std::deque<int> deq;
    priority_queue<int,std::vector<int>,std::greater<int>> que1;
    priority_queue<int> que2;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        deq.emplace_back(a);
    }
    cin >> q;
    for (int j=0;j<q;j++) {
        cin >> com >> b >> e;
        if ( com==0 ) {
            for (int k=b;k<e;k++) {
                que1.push(deq[k]);
            }
            cout << que1.top() << endl;
            for (int l=b;l<e;l++) {
                que1.pop();
            }
        } else if ( com==1 ) {
            for (int m=b;m<e;m++) {
                que2.push(deq[m]);
            }
            cout << que2.top() << endl;
            for (int n=b;n<e;n++) {
                que2.pop();
            }
        }
    }
}



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


struct Node{
	int a;
	int b;
};

int n;
Node f[100003];
bool cmp(Node a, Node b){
	if(a.b < b.b) return true;
	return false;
}

int main(){	
	cin >> n;
	for(int i = 1; i <=n; i++){
		cin >> f[i].b;
		f[i].a = i;
	}
	sort(f+1, f+1+n, cmp);
	for(int i = 1; i <= n; i++) cout << f[i].a << ' ';
	return 0;
}

Measured memory_bytes: 1536
using System;

class program
{
    static void Main(string[] args)
    {
        /*
         * 方針：
         * (ai,bi)を(index,value)とみて、クエリが来るたびにsum[index]+=value;とする。
         * 全部読み取ったらindex=0からforLoopでK-sum[index]を計算、K<=0となったらその時のindexが答え。
         */
        string[] inputs = Console.ReadLine().Split();
        long N = long.Parse(inputs[0]);
        long K = long.Parse(inputs[1]);

        long[] sum = new long[100001];

        for(int i = 0; i < N; i++)
        {
            inputs = Console.ReadLine().Split();
            long index = long.Parse(inputs[0]);
            long value = long.Parse(inputs[1]);
            sum[index] += value;
        }
        for(int i=1;i< 100001; i++)
        {
            K -= sum[i];
            if (K <= 0)
            {
                Console.WriteLine(i);
                break;
            }
        }

    }
}

Measured memory_bytes: 17336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}

int main(){
    string s,t; cin>>s>>t;
    ll a,b; cin>>a>>b;
    string u; cin>>u;
    if(u==s)cout<<a-1<<' '<<b<<endl;
    else cout<<a<<' '<<b-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dim 100001
long long a,b,x,z;
int main()
{
    cin>>a>>b>>x;
    if(a>x)cout<<"NO"<<endl;
    else if(a+b<=x)cout<<"NO"<<endl;
    else if(a==x || (a+b-1)>=x)cout<<"YES"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long long ll;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 2000000009
#define MOD 1000000007
int main(){//16 16 32 24 24 16 20 20 24 10 10 20
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll a,b,c;cin>>a>>b>>c;
  if((c%2)||(b%2)||(a%2)){cout<<0<<endl; return 0;}
  if((a==b)&&(b==c)){cout<<-1<<endl;return 0;}
  ll p,q,r;p=a+b;q=b+c;r=a+c;ll ans=0;
  while((p%2==0)&&(q%2==0)&&(r%2==0)){
  p/=2;q/=2;r/=2;ans++;
  }
  cout<<ans<<endl;return 0;
  //caricurate
  //output
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int hani[14][14] = { 0 }, x, y, size;
	int white = 0, max_num = 0;
	char tmp;

	while ( cin >> x >> tmp >> y >> tmp >> size )
	{
		x = x + 2;
		y = y + 2;
		if ( size == 1 )
		{
			hani[x][y] = hani[x][y] + 1;
			hani[x-1][y] = hani[x-1][y] + 1;
			hani[x+1][y] = hani[x+1][y] + 1;
			hani[x][y-1] = hani[x][y-1] + 1;
			hani[x][y+1] = hani[x][y+1] + 1;
		}
		else if ( size == 2 )
		{
			hani[x][y] = hani[x][y] + 1;
			hani[x-1][y] = hani[x-1][y] + 1;
			hani[x+1][y] = hani[x+1][y] + 1;
			hani[x][y-1] = hani[x][y-1] + 1;
			hani[x][y+1] = hani[x][y+1] + 1;
			
			hani[x-1][y-1] = hani[x-1][y-1] + 1;
			hani[x+1][y-1] = hani[x+1][y-1] + 1;
			hani[x-1][y+1] = hani[x-1][y+1] + 1;
			hani[x+1][y+1] = hani[x+1][y+1] + 1;
		}
		else if ( size == 3 )
		{
			hani[x][y] = hani[x][y] + 1;
			hani[x-1][y] = hani[x-1][y] + 1;
			hani[x+1][y] = hani[x+1][y] + 1;
			hani[x][y-1] = hani[x][y-1] + 1;
			hani[x][y+1] = hani[x][y+1] + 1;
			
			hani[x-1][y-1] = hani[x-1][y-1] + 1;
			hani[x+1][y-1] = hani[x+1][y-1] + 1;
			hani[x-1][y+1] = hani[x-1][y+1] + 1;
			hani[x+1][y+1] = hani[x+1][y+1] + 1;

			hani[x-2][y] = hani[x-2][y] + 1;
			hani[x][y-2] = hani[x][y-2] + 1;
			hani[x+2][y] = hani[x+2][y] + 1;
			hani[x][y+2] = hani[x][y+2] + 1;
		}
	}

	for ( int i = 2 ; i < 12 ; i = i + 1 )
	{
		for ( int j = 2 ; j < 12 ; j = j + 1 )
		{
			if ( hani[i][j] == 0 )
			{
				white = white + 1;
			}
			max_num = max( max_num, hani[i][j] );
		}
	}

	cout << white << endl;
	cout << max_num << endl;

	return 0;
}

Measured memory_bytes: 2996
import java.util.Arrays;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N, K;
		int[] Type;// 実際の数字が何個あるか

		String number = sc.nextLine();
		String[] numbers = number.split(" ");
		N = Integer.parseInt(numbers[0]);
		Type = new int[N];
		K = Integer.parseInt(numbers[1]);

		number = sc.nextLine();
		numbers = number.split(" ");

		for (int i = 0; i < numbers.length; i++) {
			Type[Integer.parseInt(numbers[i]) - 1]++;
		}

		//ソートを使用
		Arrays.sort(Type);

//		for(int i = 0; i < Type.length; i++) {
//			System.out.print(Type[i] + " ");
//		}

		int sum = 0;
		for(int i = Type.length-1; Type.length - 1 - K < i; i--) {
			sum = sum + Type[i];
		}

		System.out.println(N - sum);
	}

}


Measured memory_bytes: 61056
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int MAX = max(a+b, max(b+c, c+a));
	int d[3][3] = {0};
	d[0][0] = a;
	d[0][1] = b;
	d[1][1] = c;
	int x = 3*c;
	d[0][2] = x-a-b;
	d[2][1] = x-b-c;
	d[2][2] = x-a-c;
	d[1][2] = x-d[0][2]-d[2][2];
	d[2][0] = x-d[2][1]-d[2][2];
	d[1][0] = x-d[0][0]-d[2][0];
	for (int i = 0; i < 3; i++) {
		cout << d[i][0];
		for (int j = 1; j < 3; j++) {
			cout << ' ' << d[i][j];
		}
		cout << endl;
	}
	return 0;
}

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

signed main() {
    vector<char> vowel = {'a', 'e', 'i', 'o', 'u'};
    char in;
    cin >> in;
    for (auto &vo : vowel) {
        if (in == vo) {
            cout << "vowel\n";
            return 0;
        }
    }
    cout << "consonant\n";
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#include <vector>
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define LONG_LONG_MAX 9223372036854775807LL
#define pblank putchar(' ')
#define ll LL
#define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> P;
int n, m, k;
const int maxn = 1e5 + 10;
template <class T>
inline T read()
{
    int f = 1;
    T ret = 0;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        ret = (ret << 1) + (ret << 3) + ch - '0';
        ch = getchar();
    }
    ret *= f;
    return ret;
}
template <class T>
inline void write(T n)
{
    if (n < 0)
    {
        putchar('-');
        n = -n;
    }
    if (n >= 10)
    {
        write(n / 10);
    }
    putchar(n % 10 + '0');
}
template <class T>
inline void writeln(const T &n)
{
    write(n);
    puts("");
}
unordered_map<ll, int> mp;
void init()
{
    for (int i = 1; i <= 9; i++)
        for (int j = 1; j <= 9; j++)
            mp[i * j] = 1;
}
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    init();
    n = read<int>();
    if (mp.count(n))
        puts("Yes");
    else
        puts("No");
    return 0;
}

Measured memory_bytes: 256
// Try AtCoder
// author: Loenardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let a = get!();
    let b = get!();
    if a < 10 && b < 10 {
        println!("{}", a * b);
    } else {
        println!("-1");
    }
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 112345;
vector<int> g[MAX_N];

struct LCA {

  int log2(int b) {return 31 - __builtin_clz(b);}

  int parent[20][MAX_N]; // [k][i] := i からちょうど 2^k 回親方向へ進んだ頂点番号。無いなら -1
  int depth[MAX_N];
  int N;

  LCA(){}

  void build(int N, int root) {
    CLR(parent, -1);
    this->N = N;
    int K = log2(N) + 1;
    dfs(root, -1, 0);
    for (int k = 0; k < K; k++) {
      for (int i = 0; i < N; i++) {
        parent[k+1][i] = parent[k][i] >= 0 ? parent[k][parent[k][i]] : -1;
      }
    }
  }
  void dfs(int u, int p, int d) {
    parent[0][u] = p;
    depth[u] = d;
    for (int v : g[u]) if (v != p) {
      dfs(v, u, d+1);
    }
  }
  int get(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    int K = log2(N) + 1;
    for (int k = 0; k < K; k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
        v = parent[k][v];
      }
    }
    if (u == v) return u;
    for (int k = K-1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};

LCA lca;

int main2() {

  REP(i, MAX_N) g[i].clear();

  int N = nextInt();
  REP(i, N) {
    int K = nextInt();
    REP(_, K) {
      int j = nextInt();
      g[i].push_back(j);
      g[j].push_back(i);
    }
  }
  lca.build(N, 0);
  int Q = nextInt();
  REP(_, Q) {
    int u = nextInt();
    int v = nextInt();
    int ans = lca.get(u, v);
    printf("%d\n", ans);
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}




Measured memory_bytes: 21160
#include<stdio.h>

int main()
{
	int a[4],b[4],c,d,hit,blow;
	
	while(scanf("%d %d %d %d\n%d %d %d %d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3]) !=EOF){
		hit=0,blow=0;
		for(c=0;c<=3;c++){
			if(a[c]==b[c]){
				hit+=1;
			}else{
				for(d=0;d<=3;d++){
					if(a[c]==b[d] && c!=d)blow+=1;
				}
			}
		}
		printf("%d %d\n",hit,blow);
	}
	return 0;
}

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

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.bigin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vi>
#define vvi64 vector<vi64>

using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    vi64 l(n);
    Srep(n) cin >> l[i];
    Vsort(l);
    Srep(n-2){
        Lrep(j,i+1,n-1){
            Lrep(k,j+1,n){
                if((l[i]!=l[j]) && (l[i]!=l[k]) && (l[j]!=l[k]))
                if(l[i] + l[j] > l[k]) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<math.h>

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

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

int main(){
	int D,G,ans=123456789;
	scanf("%d%d",&D,&G);
	int p[D],c[D];
	for(int i=0;i<D;i++)scanf("%d%d",&p[i],&c[i]);
	
	for(int k=0;k<pow(2,D);k++){
		int bit=k;
		int score=0;
		int solved=0;
		int max_not_comp=-1;
		for(int i=0;i<D;i++){
			if(bit%2==1){
				score+=(i+1)*100*p[i]+c[i];
				solved+=p[i];
			}else max_not_comp=max(max_not_comp,i);
			bit/=2;
		}
		if(score<G){
			int req=G-score;
			if(req>(max_not_comp+1)*100*(p[max_not_comp]-1))continue;
			solved+=(req+(max_not_comp+1)*100-1)/((max_not_comp+1)*100);
		}
		ans=min(ans,solved);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  // M は 10**5 くらい
  // K は 10**9 くらい
  long M, K;
  cin >> M >> K;
  if (M == 0) {
    if (K == 0) cout << "0 0" << endl;
    else cout << -1 << endl;
    return 0;
  }
  if (M == 1) {
    if (K == 0) cout << "0 0 1 1" << endl;
    else cout << -1 << endl;
    return 0;
  }
  long arraySize = 2 << M;
  long numberLimit = 1 << M;
  if (numberLimit <= K) {
    cout << -1 << endl;
    return 0;
  }
  vector<long> result(arraySize);
  result[0] = K;
  result[arraySize/2] = K;
  long count = 0;
  for (long i = 0; i < numberLimit; i++) {
    if (i == K) continue;
    result[1 + count] = i;
    result[arraySize - 1 - count] = i;
    count++;
  }
  bool space = false;
  rep (i, arraySize) {
    if (space) cout << " " << result[i];
    else {
      cout << result[i];
      space = true;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1000001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
using namespace std;
ll n, t, m, c1, c2, c, x, y, z,sum, mn = 999999999, avg, pos, dif,k, mx, xi, yi;
const int MXN=2e5;
const ll mod=1e9+7;
ll pre[MXN];
bool prime[MXN];

bool PE ( ll x )
{
    for ( ll i = 2; i * i <= x; i+=1+(i&1))
    if ( x % i == 0 )
    return false;
    return true;
}
ll dist[MXN];
void sieve()
{
    memset(prime , 1 , sizeof prime);

    for ( ll i = 2; i * i <= MXN; i+=1+(i&1))
    if (prime[i])
    {
          for (ll j = i * i; j < MXN; j +=i)
         prime[j] = false;
    }
}

bool PR ( string s )
{
    int n = s.length();
    for ( ll i = 0; i < n / 2; i++ )
    if ( s[i] != s[n - i - 1] )
    return false;
    return true;
}

string s , o;
ll a[MXN];


bool is(string fs , string nd ) 
{ 
    int j = 0;
    int fn = fs.length();
     int nn = nd.length();

   for (int i=0; i<fn && j<nn; i++) 
      if (fs[i] == nd[j])
         j++; 
  
 
   return j==nn; 
}

bool ok (ll mid )
{
    
}

int main (void){
    
     SpeeD;
string s;
cin >> s;
if (s[s.length() -  1 ] == 's')
s+="es";
else s+='s';
cout << s;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  int n;
  cin>>n;
  llong ans = 0;
  REP(i,n){
    llong x;
    cin>>x;
    while(true){
      if(x%2==0){
        ans++;
        x /= 2;
      }else{
        break;
      }
    }
  }

  cout<<ans<<endl;


  return 0;
}

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

using namespace std;
#define ll long long
int main(){ 
    
    {
        ll n;
        ll m;
        ll x;
        cin >> n >> m >> x;
        
        vector<ll> a(n);
        for(ll a_i = 0; a_i <n; a_i++){
           cin >> a[a_i];
        }
        
        vector<ll> b(m);
        for(ll b_i =0; b_i <m; b_i++){
           cin >> b[b_i];
        }
        
        ll sum=0,count=0,temp=0,i=0,j=0;        
        
        while(i<n && sum+a[i]<=x){    //considering only first stack and calculating count
            sum+=a[i];
            i++;
        }
        count=i;        
       
        while(j<m && i>=0){          //now adding one element of second stack at a time and subtracting the top element of first stack and calculating the count   
            sum+=b[j];             
            j++;
            while(sum>x && i>0){
                i--;
                sum-=a[i];
            }
            if(sum<=x && i+j>count)
                count=i+j;
        }
        cout<<count<<endl;
    } 
    return 0;
}

Measured memory_bytes: 6424
mod=10**9+7
r=[[(j-k)*9%13 for j in range(10)] for k in range(13)]
dp=[1]+[0]*12
for c in input():
  dp = [sum(dp[j] for j in k)%mod for k in r] if c>'9' else [dp[(int(c)-k)*9%13] for k in range(13)]
print(dp[5])

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

const int mod=998244353;

int n,s;
int a[3005];
int dp[3005],ans;

int main(){

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

    cin>>n>>s;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        for(int j=s-a[i];j>0;j--){
            dp[j+a[i]]=(dp[j+a[i]]+dp[j])%mod;
        }
        dp[a[i]]=(dp[a[i]]+i)%mod;
        ans=(ans+dp[s])%mod;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
cnt = 0
if a == b == c and  a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    cnt = -1
else:
    while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
        a, b, c = b // 2 + c // 2, a // 2 + c // 2, a // 2 + b // 2
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<stdio.h>

int a[100001] = {};

int main(void){

  int p;
  int n;
  int k;


  p = 0;
  scanf("%d %d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);

    if(k <= a[i]){
       p++;
    }
  }

  printf("%d\n",p);

  return 0;

}


Measured memory_bytes: 512
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var lines = [];
reader.on('line', (line)=> {
          lines.push(line);
          });

reader.on('close', () =>{
  var line = lines[0];
  var elems =line.split(' ');
  var A = elems[1];
  var B = elems[2];
  var D = B-A-1;
  var E = D%2;
  if (E == 1){
    console.log('Alice');
  }
  else if (E == 0){
    console.log('Borys');
  }
});

Measured memory_bytes: 7500