akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    n=int(input())
    ans=0
    for _ in range(n-1):
        u,v=map(int,input().split())
        # print(u,v)
        if u>v:
            u,v=v,u
        ans+=u*(n-v+1)
    ans=-ans
    for i in range(1,n+1):
        ans+=(n-i+1)*i
    print(ans)

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 76800
n, a = map(int, input().split())
x = list(map(int, input().split()))


def ave_comb(v_max, ave):
    dp = [[[0 for c in range(n*v_max+1)] for b in range(n+1)] for a in range(n+1)]

    for i in range(n+1):
        dp[i][0][0] = 1

    for i in range(1, n+1):
        for j in range(1, i+1):
            for k in range(1, n*v_max+1):
                if k - x[i-1] >= 0:
                    dp[i][j][k] = dp[i-1][j-1][k-x[i-1]] + dp[i-1][j][k]
                else:
                    dp[i][j][k] = dp[i-1][j][k]

    ans = 0
    for t in range(1, n+1):
        ans += dp[n][t][ave*t]

    return ans


def main():
    x_max = max(max(x), a)

    print(ave_comb(x_max, a))


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back


vec modcomb(ll n, ll k, ll m)
{
    vec c(k+1, 0), inv(k+1, 0);
    inv[1] = 1;
    c[0] = 1; c[1] = n;
    REP(i,2,k+1) {
        inv[i] = m - inv[m%i] * (m / i) % m;
        c[i] = (((c[i-1] * (n - i + 1)) % m) * inv[i]) % m;
    }
    return c;
}

int main()
{
    ll X, Y;
    cin >> X >> Y;
    
    ll A = Y * 2 - X, B = X * 2 - Y;
    if(A >= 0 && B >= 0 && A % 3 == 0 && B % 3 == 0) {
        A /= 3; B /= 3;
        vec C = modcomb(A + B, MIN(A,B), MOD);
        PR(C[MIN(A,B)]);
    }
    else PR(0);

    return 0;
}

/*



*/

Measured memory_bytes: 8420
def myAnswer(N:int,A:list) -> str:
   counter4 = 0
   counter2 = 0
   for a in A:
      if(a % 4 == 0):
         counter4 += 1
      elif(a % 2 == 0):
         counter2 += 1
   if(counter4 >= N//2):
      return "Yes"
   elif(counter4 >= (N-(counter2//2)*2)//2):
      return "Yes"
   else:
      return "No"


def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

ll gcd(ll a,ll b){
  ll r = a%b;
  while(r!=0){
    a = b;
    b = r;
    r = a%b;
  }

  return b;
}

int main(){
  ll n; cin >> n;
  vector<ll> t(n);
  rep(i,n){
    cin >> t.at(i);
  }

 sort(all(t));

 rep(i,n-1){
   if(t.at(i)>t.at(i+1)) swap(t.at(i),t.at(i+1));
   if(t.at(i+1)%t.at(i)==0) continue;
   else t.at(i+1)=t.at(i+1)/gcd(t.at(i+1),t.at(i))*t.at(i);
 }

 cout << t.at(n-1) << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(){
  int n = 0;
  int value[20] ={0};
  int cost[20] ={0};
  int is_buy[20] ={0};
  int ans=0;

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

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

  for(int i=0; i<n;i++){
    if(value[i] > cost[i]){
      is_buy[i]= 1;
    }
  }

  for(int i=0; i<n;i++){
    if(is_buy[i]){
      ans += (value[i]-cost[i]);
    }
    //  printf("%d ",ans);                                                                                                                                                           
  }
  printf("%d",ans);


  return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int n;
int cnt[maxn], Max;
void no() { puts("Impossible"); exit(0);}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		int v;
		scanf("%d", &v);
		++cnt[v];
		Max = max(Max, v);
	}
	if(Max % 2 == 0)
	{
		int h = Max / 2;
		for(int i = 1; i < h; ++i) if(cnt[i]) no();
		if(cnt[h] != 1) no();
		for(int i = h + 1; i <= Max; ++i) if(cnt[i] < 2) no();
	}
	else
	{
		int h = (Max + 1) / 2;
		for(int i = 1; i < h; ++i) if(cnt[i]) no();
		if(cnt[h] != 2) no();
		for(int i = h + 1; i <= Max; ++i) if(cnt[i] < 2) no();
	}
	puts("Possible");
	return 0;
}
		
	

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second


int main(int argc, char const *argv[])
{
    ll n,k;
    cin >> n >> k;
    int dp[61][n];
    REP(i,n)
    {
        cin >> dp[0][i];
        dp[0][i]--;
    }
    
    REP(i,60) REP(j,n)
    {
        dp[i+1][j] = dp[i][dp[i][j]];
    }

    int v = 0;
    REPD(i,60)
    {
        ll l = 1ll<<i;
        if (l <= k)
        {
            v = dp[i][v];
            k -= l;
        }
    }
    cout << v + 1 << endl;
    return 0;
}


Measured memory_bytes: 51216
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int n,m;
	cin>>n>>m;

	cout<<lcm(n,m)<<endl;

}

Measured memory_bytes: 3604
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

struct Edge {
    int to, cost;
};
using Graph = vector< vector<Edge> >;

int dist[100010];

// dist[i] := 頂点 i から最も遠い葉との距離
void dfs(Graph &G, int cur, int par=-1) {
    for(auto e : G[cur]) {
        if(e.to == par) continue;
        dfs(G, e.to, cur);
        dist[cur] = max(dist[cur], dist[e.to] + e.cost);
    }
}

int solve(Graph &G, int root, int d_par, int par=-1) {
    vector< pair<int, int> > children;
    children.push_back(make_pair(0, -1));

    for(auto e : G[root]) {
        if(e.to == par) children.push_back(make_pair(d_par + e.cost, e.to));
        else children.push_back(make_pair(dist[e.to] + e.cost, e.to));
    }
    sort(children.begin(), children.end(), greater< pair<int, int> >());

    int max_cost = children[0].first + children[1].first;
    for(auto e : G[root]) {
        if(e.to == par) continue;
        int nxt_d_par = children[children[0].second == e.to].first;
        max_cost = max(max_cost, solve(G, e.to, nxt_d_par, root));
    }
    return max_cost;
}

int main() {
    int N; scanf("%d", &N);

    Graph G(N);
    for(int i=0; i<N-1; i++) {
        int s, t, w; scanf("%d%d%d", &s, &t, &w);
        G[s].push_back(Edge{t, w});
        G[t].push_back(Edge{s, w});
    }
    dfs(G, 0);
    printf("%d\n", solve(G, 0, 0));
}


Measured memory_bytes: 25492
s = input();
check = [0]*26;
base = ord("A");
count2 = 0;
for i in range(4) :
	check[ord(s[i])-base] += 1;
for i in range(26) :
	if check[i] == 2 :
		count2 += 1;
if count2 == 2 :
	print('Yes');
else :
	print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class Graph
{
public:
  int solve();
};

int Graph::solve()
{
  int n;
  cin >> n;
  
  vector<vector<int>> adj( n + 1, vector<int>( n + 1, 0 ) );
  
  for ( auto i = 0; i < n; ++i )
    {
      int u;
      int k;
      int v;
      cin >> u;
      cin >> k;
      for ( auto j = 0; j < k; ++j )
        {
          cin >> v;
          adj[u][v] = 1;
        }
    }

  for ( auto i = 1; i <= n; ++i )
    {
      for ( auto j = 1; j <= n; ++j )
        {
          if ( j > 1 ) cout << " ";
          cout << adj[i][j];
        }
      cout << endl;
    }
  
  return 0;
}

int main()
{
  Graph g;

  g.solve();

  return 0;
}

Measured memory_bytes: 1256
n=int(input())
list=[int(i) for i in input().split()] 

def search_odd(n):
    if n % 2 == 1:
        return True
    else:
        return False

count=0
isOdd=False
while True:
    for i in range(0,n):
        isOdd = search_odd(list[i])
        if isOdd:
            break
        list[i] = list[i]/2
    if isOdd:
        break
    count+=1
print (count)

Measured memory_bytes: 3064
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF=100000000000000LL;

int main() {
	int x,y,z;
	cin>>x>>y>>z;
	int ans=0;
	ans=x/(z+y);
	if(x%(y+z)<z)ans--;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
N,K=list(map(int,input().split()))
X=list(map(int,input().split()))

P_list=[0]
N_list=[0]
zero_num=0

for x in X:
    if x < 0:
        N_list.append(-x)
    elif x == 0:
        zero_num=1
    else:
        P_list.append(x)
        
K=K-zero_num

P_list.sort()
N_list.sort()
P_list,N_list

move=[]
for i in range(K+1):
    j=K-i
#     print(i,j)
    if i >= len(P_list) or j >= len(N_list):
        continue
    move_=min(2*P_list[i]+N_list[j],P_list[i]+2*N_list[j])
#     print(move_)
    move.append(move_)
    
if len(move)==0:
    move.append(0)
    
print(min(move))

Measured memory_bytes: 91872
#include <iostream>
using namespace std;
int main(void){
 int x,y;
 cin>>x>>y;

 if(x<y){
     cout<<y-x<<endl;
 } 
 if(x>y){
     cout<<x-y<<endl;
 }
 if(x==y){
     cout<<"0"<<endl;
 }
}



Measured memory_bytes: 3116
N = int(input())
lst = list(map(int, input().split()))

flag = True
count = 0
while flag:
    for i in range(N):
        if lst[i]%2 == 0:
            lst[i] = lst[i]/2
        else:
            flag = False
            
    count += 1
print(count-1)       

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

int main(void) {
  int debt = 100000;
  int interest = 5;
  int money = debt;
  int n;

  scanf("%d", &n);
  while (n--) {
    money += money * interest / 100;
    money = ceil(money / 1000.0) * 1000;
  }

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

  return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u,int k){
	while(u != NIL && k != u->key){
		if(k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		}else{
			x = x->right;
		}
	}
	z->parent = y;
	if(y == NIL){
		root = z;
	}else{
		if(z->key < y->key){
			y->left = z;
		}else{
			y->right = z;
		}
	}
}

void inorder(Node *u){
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u){
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main(){
	int n,i,x;
	string com;
	
	scanf("%d",&n);
	
	for(i = 0;i < n;i++){
		cin >> com;
		if(com[0] == 'f'){
			scanf("%d",&x);
			Node *t = find(root,x);
			if(t != NIL) printf("yes\n");
			else printf("no\n");
		}else if(com == "insert"){
			scanf("%d",&x);
			insert(x);
		}else if(com == "print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 21924
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main {
	PrintWriter out;
    StringTokenizer st;
    BufferedReader br;
 	
 	class Pair implements Comparable<Pair>
	{
	    int f;
	    int s;
 
	    Pair(int t, int r) {
	       f = t;
	       s = r;
	    }
	    public int compareTo(Pair p)
	    {
	    	if(this.f!=p.f)
	    		return this.f-p.f;
 
	    	return this.s-p.s;
	    }
 	}
 // 	class Sort implements Comparator<String> 
	// { 
	//     public int compare(String a, String b) 
	//     { 
	//     	return (a+b).compareTo(b+a);
	//     } 
	// }
 
	String ns() {
        while (st == null || !st.hasMoreElements()) {
 
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
 
    String nextLine() throws Exception {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            throw new Exception(e.toString());
        }
        return str;
    }
 
    int nextInt() {
        return Integer.parseInt(ns());
    }
 
    long nextLong() {
        return Long.parseLong(ns());
    }
 
    double nextDouble() {
        return Double.parseDouble(ns());
    }
	
	int upperBound(long a[],long key)
	{
		int l=0,r=a.length-1;
		int i=-1;
 
		while(l<=r)
		{
			int mid=(l+r)/2;
 
			if(a[mid]<key)
				l=mid+1;
 
			else{
				i=mid;	
				r=mid-1;
			}
			
		}
		return i;
	}
	int lowerBound(Pair[] a , long key)
	{
		int l = 0, r = a.length- 1;
		int i = -1;
 	
		while(l<=r)
		{
			int mid=(l+r)/2;
 
			if(a[mid].f<key)
			{
				i=mid;
				l=mid+1;	
			}
 
			else
				r=mid-1;
			
		}
		return i;
	}
 
	long power(long x,long y)
	{
	    long ans=1;
	    
	    while(y!=0)
	    {
	        if(y%2==1) ans=(ans*x)%mod;
	        x=(x*x)%mod;
	        y/=2;
	    }
	    return ans%mod;
	}
	
 
	int mod= 1000000007;
	long gcd(long x ,long y)
	{
		if(y==0)
			return x;
		return gcd(y,x%y);
	}
 
	// ArrayList<Integer> a[];
	// TreeMap<Integer, Long> map;
	// int vis[];
	// long d[];
	// void dfs(int ver, int m)
	// {
	// 	map.put(ver, d[m % 3]);
	// 	for(int v : a[ver])
	// 	{
	// 		if(vis[v] == 0){
	// 			vis[v] = vis[ver] + 1;
	// 			dfs(v, m + 1);
	// 		}
	// 	}
	// }
 
 	int countSetBits(long n) 
    { 
        int count = 0; 
        while (n > 0) { 
            n &= (n - 1); 
            count++; 
        } 
        return count; 
    }

	void solve() throws IOException{
		int n = nextInt();
		char c[] = ns().toCharArray();
		int r = 0, w = 0;
		for(int i = 0; i < n; i++)
		{
			if(c[i] == 'R')
				r++;
			else
				w++;
		}
		int m = r;
		for(int i = 0; i < m ;i++)
		{
			if(c[i] == 'R')
				r--;
		}
		out.println(r);
	}
	
    void run() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
		solve();
		out.flush();
 
		out.close();
	}
 
	public static void main(String args[]) throws IOException {
		new Main().run();
	}
}



Measured memory_bytes: 36636
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
int gcd(int x,int y){
	if(x>y) swap(x,y);
	while(x>0){
		y%=x;
		swap(x,y);
	}
	return y;
}
int main(){
	while(true){
		string s;
		cin>>s;
		if(s[0]=='#') break;
		reverse(s.begin(),s.end());
		int now=0,ans=0,p=1;
		if(s[0]=='h') now+=5,ans=0;
		else now+=4,ans=1;
		while(now!=s.size()){
			p*=2;
			if(s[now]=='h'){
				now+=5;
				ans*=2;
				ans--;
			}else{
				now+=4;
				ans*=2;
				ans++;
			}
		}
		ans*=90;
		int g=gcd(ans,p);
		ans/=g,p/=g;
		if(p==1) cout<<ans<<endl;
		else cout<<ans<<"/"<<p<<endl;
	}
}

Measured memory_bytes: 1192
open System

let [| N; M |] = stdin.ReadLine().Split(' ') |> Array.map int
let (cnt : int[]) = Array.zeroCreate N
for i in {0..(M - 1)} do
  let [| a; b |] = stdin.ReadLine().Split(' ') |> Array.map int
  cnt.[a - 1] <- cnt.[a - 1] + 1
  cnt.[b - 1] <- cnt.[b - 1] + 1

cnt
|> Array.iter (printfn "%d")

Measured memory_bytes: 14160
/*
 * AC	78 ms	14208 KB
 */
#include <cstdio>
#include <iostream>
#include <vector>
 
using namespace std;
 
#define INF 1e9
 
int N, K;
vector<int> edge[100005]; // edge[i] connect from i to edge[i][j].
int v[100005];   // v[i] is written in vertex i
int par[100005]; // vertex i's parent is par[i]
int lb[100005], ub[100005];  // Range [lb[i], ub[i]] is allowed at vertex i, v[i] must be in [lb[i], ub[i]]
 
int root;
 
void dfs(int vertex) {
    for (int i = 0; i < edge[vertex].size(); ++i) {
        int nextVertex = edge[vertex][i];
        if (nextVertex != par[vertex]) {
            par[nextVertex] = vertex;
            dfs(nextVertex);
        } else {
            // skip this
        }
    }
 
    for (int i = 0; i < edge[vertex].size(); ++i) {
        int nextVertex = edge[vertex][i];
        lb[vertex] = max(lb[vertex], lb[nextVertex] - 1);
        ub[vertex] = min(ub[vertex], ub[nextVertex] + 1);
    }
}
 
// Decide the example of v[i]
void dfs2(int vertex) {
    for (int i = 0; i < edge[vertex].size(); ++i) {
        int nextVertex = edge[vertex][i];
        if (nextVertex != par[vertex]) {
            par[nextVertex] = vertex;
            int tmp;
            tmp = v[vertex] + 1;
            if (lb[nextVertex] <= tmp && tmp <= ub[nextVertex]) {
                v[nextVertex] = tmp;
            } else {
                tmp = v[vertex] - 1;
                if (lb[nextVertex] <= tmp && tmp <= ub[nextVertex]) {
                    v[nextVertex] = tmp;
                } else {
                    // Error, impossible
                    lb[root] = INF;
                    ub[root] = -INF;
                    return;
                }
            }
            dfs2(nextVertex);
        } else {
            // skip this
        }
    }
}
 
int main(){
    //freopen("e3.in", "r", stdin);
    scanf("%d", &N);
    int a, b;
    for (int i = 0; i < N-1; ++i) {
        scanf("%d %d", &a, &b);
        edge[a].push_back(b);
        edge[b].push_back(a);
 
    }
    // init
    for (int i = 1; i <= N; ++i) {
        v[i] = INF;
        lb[i] = -INF;
        ub[i] = INF;
    }
 
    scanf("%d", &K);
    for (int i = 0; i < K; ++i) {
        int vertex, p;
        scanf("%d %d", &vertex, &p);
        v[vertex] = p;
        lb[vertex] = ub[vertex] = p;
        root = vertex;
    }
    par[root] = root;
    dfs(root);
    dfs2(root);
 
    if (lb[root] == v[root] && ub[root] == v[root]) {
        // possible
        printf("Yes\n");
        for (int i = 1; i <=N; ++i) {
            printf("%d\n", v[i]);
        }
    } else {
        printf("No\n");
    }
 
 
 
    return 0;
}

Measured memory_bytes: 14208
from collections import defaultdict
from bisect import bisect

def solve(K,A):
    N = len(A)
    indices = defaultdict(list)
    for i,a in enumerate(A):
        indices[a].append(i)

    memo = [False]*N
    memo[0] = True
    trace = [0]
    cnt = [0]
    while True:
        i = trace[-1]
        c = cnt[-1]
        l = indices[A[i]]
        j = (l[bisect(l,i)%len(l)]+1)%N
        if j == 0 and i+1==N:
            c += 2
        elif j <= i+1:
            c += 1
        trace.append(j)
        cnt.append(c)
        if memo[j]:
            break
        else:
            memo[j] = True

    i = trace.index(trace[-1])

    period = cnt[-1] - cnt[i]
    if K > cnt[i]:
        K = (K-cnt[i])%period + cnt[i]
    if K == 0:
        return tuple()
    head = trace[bisect(cnt, K-1)-1]
    # print(cnt)
    # print(trace)
    # print(period)
    # print(K)
    # print(head)
    ans = []
    cur = head
    while cur < N:
        l = indices[A[cur]]
        j = bisect(l, cur)
        if j == len(l):
            ans.append(cur)
            cur += 1
        else:
            cur = l[j]+1
    return tuple(A[i] for i in ans)

def naive(K,A):
    s = {}
    l = []
    for k in range(K):
        for a in A:
            try:
                i = l.index(a)
                l = l[:i]
            except ValueError:
                l.append(a)
    return tuple(l)

# from random import randrange

# for n in range(100):
#     K = randrange(1,4)
#     A = [randrange(10) for _ in range(10)]
#     s1 = solve(K,A)
#     s2 = naive(K,A)
#     if s1 != s2:
#         print(n)
#         print(K)
#         print(A)
#         print(s1)
#         print(s2)
#         exit()
# solve(2,[1,1,1])

N,K = map(int,input().split())
A = list(map(int,input().split()))
print(*solve(K,A))

Measured memory_bytes: 79204
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(){
    int w, h;
    string s[1000];
    set<string> st;
    char c;
    cin >> w >> h;
    for(int i = 0; i<h; st.insert(s[i++]))
    for(int j = 0; j<w; j++) cin >>c, s[i]+=c;
    sort(s, s+h);
    bool ans = 1;
    int cnt = 0;
    for(int i = 0; i<w; i++){
        if(s[0][i] == '1') cnt++;
        if(s[h / 2 - 1][i] == s[(h + 1) / 2][i]) ans = 0;
    }
    if( (cnt != w / 2 && cnt != (w + 1) / 2) || st.size() != 2 ) ans = 0;
    cout << (ans ? "yes" : "no")  << endl;
    return 0;
}


Measured memory_bytes: 3972
'use strict';
(function(stdin) {
  var lines  = stdin.toString();
  var re = /[A-Za-z]+\n([1-9][0-9]*\n)+/g;
  var result = (function(data) {
    return data
      .map(function(v) {
        return v.slice(- v[1])
          .map(Number)
          .reduce(function(str,num) {
            return str.slice(num) + str.slice(0,num);
          },v[0]);
      }).join('\n');
  }(lines.match(re).map(function(v){return v.trim().split('\n');})
  ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}


int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = a * (n/(a+b));
    n %= a+b;
    ans += min(n,a);
    cout << ans << endl;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
	char name[100];
	int t;
}P;

P Q[LEN];

int head,tail,n;

void enqueue(P x){
	Q[tail]=x;
	tail=(tail+1)%LEN;
}

P dequeue(){
	P x =Q[head];
	head =(head +1)%LEN;
	return x;
}

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

int main(){
	int elaps = 0,c;
	int i,q;
	P u;
	scanf("%d %d",&n, &q);
	
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	
	head=1;
	tail=n+1;
	
	while(head != tail){
		u=dequeue();
		c=min(q,u.t);
		u.t -= c;
		elaps += c;
		if(u.t>0){
			enqueue(u);
		}else{
			printf("%s %d\n",u.name,elaps);
		}
	}
	
	return 0;
	
}


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

#define MAXN 1000001

int size[MAXN],cnt;
vector<int> edge[MAXN];

void addedge(int u,int v)
{
	edge[u].push_back(v);
}

void dfs1(int now,int father)
{
	size[now]=1;
	for(int i=0;i<edge[now].size();++i)
	{
		if(edge[now][i]==father)continue;
		dfs1(edge[now][i],now);
		if(size[edge[now][i]]==2)size[edge[now][i]]=-1;
		else size[now]+=size[edge[now][i]];
	}
}

void dfs2(int now,int father)
{
	++cnt;
	int num=0;
	for(int i=0;i<edge[now].size();++i)
	{
		if(edge[now][i]==father)continue;
		if(size[edge[now][i]]==1){++num;}
		if(size[edge[now][i]]!=-1)dfs2(edge[now][i],now);
	}
	if(num>=2){puts("First");exit(0);}
}

int main()
{
	int n;
	scanf("%d",&n);	
	for(int i=1;i<n;++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	dfs1(1,0);
	dfs2(1,0);
	if(cnt==1)puts("First");else puts("Second");
}

Measured memory_bytes: 28032
#!/usr/bin/env python3

MOD = int(1e9)+7

def extgcd(a, b):
    if b == 0:
        return [1, 0, a]
    x, y, g = extgcd(b, a%b)
    return [y, x - a//b * y, g]


def mod_inverse(a, m):
    x, y, _ = extgcd(a, m)
    return (m+x%m) % m


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

maxf = 2*n + 10
f = [1 for _ in range(maxf)]
invf = [1 for _ in range(maxf)]

for i in range(1, maxf):
    f[i] = (i * f[i - 1]) % MOD
 
invf[maxf-1] = pow(f[maxf - 1], MOD-2, MOD)
for i in range(maxf-1, 0, -1):
    invf[i-1] = (i*invf[i]) % MOD
 
def comb(a, b):
    if b > a:
        return 0
    return (((f[a]*invf[b]) % MOD) * invf[a-b]) % MOD

a = [ int(x) for x in input().split() ]
a.sort(reverse=True)

ans = 0

for i, v in enumerate(a):
    ans += v*comb(n-i-1, k-1)
    ans %= MOD
    ans -= v*comb(i, k-1)
    ans %= MOD
    
print(ans)



Measured memory_bytes: 30228
s = list(str(input()))
q = int(input())
flag = 1
from collections import deque
s = deque(s)
for i in range(q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        flag = 1-flag
    else:
        t, f, c = query
        if f == '1':
            if flag:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if flag:
                s.append(c)
            else:
                s.appendleft(c)

s = list(s)
if not flag:
    s.reverse()
print(''.join(s))


Measured memory_bytes: 101192
def solve():
  N, W = map(int, input().split())
  dp = [[float('inf')]*(10**5+1) for _ in range(N+1)]
  for i in range(N+1):
    dp[i][0] = 0
  for i in range(N):
    w,v = map(int, input().split())
    for j in range(10**5+1):
      dp[i+1][j] = min(dp[i][j],dp[i+1][j])
      if j+v<=10**5:
        dp[i+1][j+v] = min(dp[i][j+v],dp[i][j]+w)
  for i in range(10**5,-1,-1):
    if dp[-1][i]<=W:
      ans = i
      break
  return ans
print(solve())

Measured memory_bytes: 247992
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

bool furui[10010];
vector<int> prime;
vector<int> twin;

void mkprime() {
	for(int i = 0; i < 10010; i++) furui[i] = true;
	furui[0] = furui[1] = false;
	for(int i = 0; i < 10010; i++) {
		if(furui[i]) {
			prime.push_back(i);
			for(int j = i * 2; j < 10010; j += i) {
				furui[j] = false;
			}
		}
	}
	for(int i = 0; i < prime.size() - 1; i++) {
		if(prime[i + 1] - prime[i] == 2)
			twin.push_back(prime[i + 1]);
	}
	sort(twin.begin(), twin.end());
}

int main() {
	int n;
	mkprime();
	while(cin >> n, n) {
		vector<int>::iterator iter;
		iter = upper_bound(twin.begin(), twin.end(), n);
		cout << *(iter-1) - 2 << " " << *(iter-1) << endl;
	}
}

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

using namespace std;

int main()
{
    string n;
    cin >> n;
    
    if(n[0] > n[1]) {
        for(int i = 0; i < 3; i++) {
            cout << n[0];
        }
    }
    else if(n[0] == n[1]) {
        if(n[0] >= n[2]) {
            for(int i = 0; i < 3; i++) {
                cout << n[0];
            }
        }
        else {
            for(int i = 0; i < 3; i++) {
                cout << char(n[0] + 1);
            }
        }
    }
    else {
        for(int i = 0; i < 3; i++) {
            cout << char(n[0] + 1);
        }
    }
    
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
*A, = map(int, input().split())
for _ in range(min(K, 50)):
    counter = [0] * (N+2)
    for i, a in enumerate(A, 1):
        counter[max(0, i - a)] += 1
        counter[min(N + 1, i + a + 1)] += -1
    for i in range(1, len(counter) - 1):
        counter[i] += counter[i-1]
    A = counter[1:N+1]
print(*A)


Measured memory_bytes: 170764
def ext_euler(a, b):
    # return (x, y, gcd(a, b)) s.t. ax + by = gcd(a, b)
    assert a > b
    if b == 0:
        return 1, 0, a
    y, x, v = ext_euler(b, a % b)
    y -= (a // b) * x
    return x, y, v


def mod_inv(a, mod):
    if a > mod:
        x, _, _ = ext_euler(a, mod)
    else:
        _, x, _ = ext_euler(mod, a)
    return x % mod


def mod_comb(n, k, mod):
    if k > n // 2:
        return mod_comb(n, n - k, mod)
    c = 1
    for i in range(k):
        c *= (n - i)
        c *= mod_inv(k - i, mod)
        c %= mod
    return c


def main():
    MOD = 10**9 + 7
    X, Y = list(map(int, input().split(' ')))
    if (2 * X - Y) % 3 != 0 or (- X + 2 * Y) % 3 != 0:
        print(0)
        exit(0)
    a = (2 * X - Y) // 3
    b = (- X + 2 * Y) // 3
    if a < 0 or b < 0:
        print(0)
        exit(0)
    print(mod_comb(a + b, b, MOD))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

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

ll n, m, x[1000], y[1000], z[1000], xa[1000], ya[1000], za[1000];

ll sol(ll a, ll b, ll c)
{
    REP(i, n)
    {
        xa[i] = ((x[i] * a) + (y[i] * b) + (z[i] * c));
    }

    sort(xa, xa + n);
    //sort(ya, ya + n);
    //sort(za, za + n);

    ll o = 0, p = 0, q = 0;
    REP(i, m)
    {
        o += xa[n - i - 1];
        //p += ya[n - i - 1];
        //q += za[n - i - 1];

        //cout << xa[n - i - 1] << endl;
    }

    o = abs(o);
    return o; //+ p + q;
}

int main()
{
    cin >> n >> m;
    REP(i, n)
    cin >> x[i] >> y[i] >> z[i];

    ll ans = 0;
    vector<ll> t;
    t.push_back(sol(1, 1, 1));
    t.push_back(sol(1, -1, 1));
    t.push_back(sol(1, 1, -1));
    t.push_back(sol(1, -1, -1));
    t.push_back(sol(-1, 1, 1));
    t.push_back(sol(-1, -1, 1));
    t.push_back(sol(-1, 1, -1));
    t.push_back(sol(-1, -1, -1));

    SORT(t);

    cout << t[7] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){int n;
		 	cin>>n;
		 	float a[n];
		 	for(int i=0;i<n;i++){
		 					cin>>a[i];
			 }
			 int temp;
				for(int i=1;i<n;i++){
								for(int j=0;j<n-i;j++){
													if(a[j]>a[j+1]){
														           temp=a[j+1];
														           a[j+1]=a[j];
														           a[j]=temp;
													}
								}
			}
			float sum=a[0];
			for(int i=1;i<=n-1;i++){
				               sum=(sum+a[i])/2;
			}
			cout<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int A[N];
    int B[N] = {};
    int ans = 1;
    rep(i, N) cin >> A[i];
    int tmp = 0;
    rep(i, N-1) {
        if(A[i+1] - A[i] < 0) {
            B[tmp++] = -1;
        } else if (A[i+1] - A[i] > 0) {
            B[tmp++] = 1;
        }
    }
    rep(i, N-1) {
        if (B[i] == B[i+1]) continue;
        if (B[i] != B[i+1]) {
            if(B[i+1] == 0 || B[i] == 0) break;
            ans++;
            i++;
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner


object Main extends App  {
  val sc = new Scanner(System.in)

  val n = sc.nextInt

  val primeList = (1 to n).filter(isPrime)

  val primeDecompositionList = (2 to n).map{ k =>
    val eachList =
      k match {
        case 1 => List(1)
        case x =>loop(x)
      }
    loop2(eachList,List.empty[(Int,Int)])
  }

  val res = primeDecompositionList.flatten.groupBy(_._1).values.foldLeft(1L){ (prod, list) =>
    prod * ( list.map(_._2).sum + 1) % 1000000007
  }

  println(res)

  def isPrime(num: Int) :Boolean={
    num match{
      case 1 => false
      case 2 => true
      case x => (2 to Math.sqrt(x).floor.toInt).forall(x % _ != 0)
    }
  }

  def loop(num: Int): List[Int] ={
    num match{
      case 1 => List(1)
      case x if primeList.contains(x) => List(x)
      case x => {
        val z = primeList.find(x % _ == 0).get
        z +: loop(x / z)
      }
    }
  }

  def loop2(list: List[Int], ll: List[(Int,Int)]): List[(Int,Int)]={
    if(list.isEmpty) ll
    else {
      val (t, f) = list.partition(_ == list.head)
      loop2(f, ll :+ (t.head, t.size) )
    }
  }
}


Measured memory_bytes: 28188
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (100000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, T, as[MAX_N];
  scanf("%d %d", &N, &T);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // optimal move
  // max_rests[i] : max{as[i], ..., as[N - 1]}
  // incomes[i] : income per apple if we bought apples at i
  int max_rests[MAX_N], incomes[MAX_N], max_income = 0;
  max_rests[N - 1] = as[N - 1];
  for (int i = N - 2; i >= 0; i--) {
    max_rests[i] = max(max_rests[i + 1], as[i]);
  }
  for (int i = 0; i < N; i++) {
    incomes[i] = max_rests[i] - as[i];
    max_income = max(max_income, incomes[i]);
  }

  // solve
  // answer is the number of cities where apples can be bought to achieve
  // the maximum income
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += incomes[i] == max_income;
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 1280
H,W=map(int, input().split())
S=[input() for i in range(H)]

Ts=""
for i in range(W+2):
    Ts+="#"

Ps=""
P=[]
for i in range(H):
    Ps+="#"
    Ps+=S[i]
    Ps+="#"
    P.append(Ps)
    Ps=""

print(Ts)
for i in range(H):
    print(P[i])
print(Ts)


Measured memory_bytes: 3060
package main

import (
	"fmt"
	"math"
)

func solve(n int, d int, xs [][]float64) int {
	var r int
	for i := 0; i < n-1; i++ {
		for j := i+1; j < n; j++ {
			var p float64
			for k := 0; k < d; k++ {
				a := math.Abs(xs[i][k] - xs[j][k])
				p += math.Pow(a, 2)
			}
			s := math.Sqrt(p)
			si := int(s)
			if s-float64(si) == 0 {
				r++
			}

		}
	}
	return r
}

func main() {
	var n, d int
	fmt.Scan(&n)
	fmt.Scan(&d)

	var xs [][]float64
	for i := 0; i < n; i++ {
		var x []float64
		for j := 0; j < d; j++ {
			var item float64
			fmt.Scan(&item)
			x = append(x, item)
		}
		xs = append(xs, x)
	}

	fmt.Println(solve(n, d, xs))
}

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

using namespace std;

int n,m;
map<int,int> num;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for (int i=1;i<=m;i++) {
        int x,y;
        cin>>x>>y;
        num[x]++; num[y]++;
    }
    for (auto inf : num)
        if (inf.second % 2) {
            cout<<"NO"<<endl;
            return 0;
        }
    cout<<"YES";
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<cstdio>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
ll mod = 1e9 + 7;
long N;
long sum = 1;
long a[1001] = {};
int main() {
	cin >> N;
	for (int i = 2; i <= N; ++i) {
		int k = i;
		for (int j = 2; k > 1;) {
			if (k%j == 0) {
				a[j]++;
				k /= j;
			}
			else {
				j++;
			}
		}
	}
	for (int i = 2; i <= N; ++i) {
		sum *= (a[i] + 1);
		sum %= mod;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>


int main(){
  int i,j,k;
  int H,W;
  scanf("%d %d",&H,&W);
  char S[H+2][W+2];
  for(i=0;i<H+2;i++){
    for(j=0;j<W+2;j++)
      S[i][j] = '.';
  }
  for(i=1;i<=H;i++){
    scanf("%s",S[i]);
  }
  
  for(i=1;i<=H;i++){
    for(j=1;j<=W;j++){
      if(S[i][j]=='#'){
        if(!(S[i+1][j] == '#' || S[i-1][j] == '#' || S[i][j+1] == '#' || S[i][j-1] == '#')){
          puts("No");
          return 0;
        }
      }
    }
  }
  puts("Yes");
  return 0;
}




Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
long long a[110000];
map<long long,bool>app;
int cnt;
long long go(string s,int le,int ri){
	  int i,j,k;
	  long long res=0;
	  for(i=le;i<=ri;i++)
	     res=res*100+(s[i]-'a'+1);
	  for(i=ri-le+2;i<=5;i++)	 
	     res*=100;
	  return res;
}
int main()
{     int n,m,i,j,k;
      string s;
      cin>>s;
      n=s.length();
      cin>>k;
      for(i=0;i<n;i++)
         for(j=i;j<=min(i+k,n-1);j++){
            long long res=go(s,i,j);
            if(!app[res]){
            	a[++cnt]=res;
            	app[res]=1;
            }
         }
      sort(a+1,a+cnt+1);
      char c[110];
      cnt=0;
      while(a[k]){
      	if(a[k]%100)c[++cnt]=(a[k]%100-1)+'a';
      	a[k]/=100;
      }
      for(i=cnt;i>0;i--)
         cout<<c[i];
	  return 0;
}


Measured memory_bytes: 1664
#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;

void solve() {
  long N, K;
  cin >> N >> K;
  long ans = 0;
  ans++;
  N -= K;
  ans += (N / (K-1));
  if (N % (K-1)) ans++;
  cout << ans << endl;
}

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


Measured memory_bytes: 256
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String a = scan.next();
        String b = scan.next();
        String a_b = a + b;
        
        String cnt;
        
        int num = Integer.parseInt( a_b );
        
        int num_root = (int)Math.sqrt((double)num);
        
        //System.out.println(num_root);
        
        if( num_root * num_root == num )
          cnt = "Yes";
        else
          cnt = "No";
        
        System.out.println(cnt);
	  }
}

Measured memory_bytes: 21844
from collections import deque
n,m=map(int,input().split())
edg=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    edg[a].append(b)
    edg[b].append(a)
visited=[False for i in range(n)]
visited[0]=True
parent=[None for i in range(n)]
q=deque([0])
while len(q)>0:
    now=q.popleft()
    for i in edg[now]:
        if not visited[i]:
            q.append(i)
            visited[i]=True
            parent[i]=now
print("Yes")
for i in parent[1:]:
    print(i+1)


Measured memory_bytes: 101244
#include <iostream>
#include <vector>
#include <utility>
#include <tuple>

using namespace std;
using ll = long long;
#define int ll

const int INF = 1LL << 60;

const int MAX_N = 1000;

vector<int> table[MAX_N];
vector<int> rev_table[MAX_N];

bool reachable[MAX_N];
bool reachable2[MAX_N];
bool valid[MAX_N];

void dfs(int node) {
    if (reachable[node]) return;
    reachable[node] = true;
    for (int next : table[node]) dfs(next);
}

void dfs2(int node) {
    if (reachable2[node]) return;
    reachable2[node] = true;
    for (int next : rev_table[node]) dfs2(next);
}

signed main() {
    int N, M;
    cin >> N >> M;

    vector<tuple<int, int, int>> edges(M);

    for (int j = 0; j < M; j++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edges[j] = make_tuple(a, b, -c);

        table[a].push_back(b);
        rev_table[b].push_back(a);
    }

    dfs(0);
    dfs2(N-1);
    for (int i = 0; i < N; i++) valid[i] = reachable[i] & reachable2[i];

    vector<int> d(N, INF);
    d[0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            int a, b, c;
            tie(a, b, c) = edges[j];

            if (!valid[a] || !valid[b]) continue;

            if (d[b] > d[a] + c) {
                d[b] = d[a] + c;
                if (i == N - 1) {
                    cout << "inf" << endl;
                    return 0;
                }
            }
        }
    }

    cout << -d[N-1] << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int b[]=new int[a*2];
	for(int i=0;i<a*2;i++) {
		b[i]=scan.nextInt();
	}
	Arrays.sort(b);
	int count=0;
	for(int i=0;i<a*2;i+=2) {
		count+=b[i];
	}
	System.out.println(count);
	scan.close();
	}
}

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

int main() {
char  c;
cin >> c;

if ((c == 'a') || (c == 'i' ) || (c == 'u') || (c == 'e') || (c == 'o'))
cout <<  "vowel" << endl;

else
cout << "consonant" << endl;

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;

using namespace std;
//
// Created by karayuu on 2019-3-28.
//

/**
 * 与えられた文字列を全て小文字にします.
 * tolower(char)のstring版
 * @param s 小文字にしたい文字列.
 * @return sを小文字にした文字列.
 */
string toStrLower(const string s) {
    string str = s;
    transform(s.begin(), s.end(), str.begin(), ::tolower);
    return str;
}

int main() {
    string w;
    cin >> w;
    w = toStrLower(w);

    int count = 0;
    while (true) {
        string t;
        cin >> t;

        if (t == "END_OF_TEXT") break;
        t = toStrLower(t);
        if (t == w) {
            count++;
        }
    }

    P(count);
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
using namespace std;

int cnt;
string s;
stack<int> st;	

int main(){
	cin>>cnt;
	cnt = 0;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]==')'){
			if(st.size()) st.pop();
			else cnt++;
		}
		else st.push(1);
	}
	while(!st.empty()) s.push_back(')'), st.pop();
	for(int i=0;i<cnt;i++) s.insert(s.begin(), '(');
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n, k, c;
    string s;
    cin >> n >> k >> c;
    cin >> s;

    int earliest[k] = {};
    int latest[k] = {};

    int tmp = 0;
    for(int i=0;i<n;++i)
    {
        if(s[i] == 'o')
        {
            earliest[tmp] = i;
            tmp++;
            i += c;
            if(tmp == k) break;
        }
    }

    tmp = k-1;
    for(int i=n-1;i>=0;--i)
    {
        if(s[i] == 'o')
        {
            latest[tmp] = i;
            tmp--;
            i -= c;
            if(tmp == -1) break;
        }
    }
    
    for(int i=0;i<k;++i)
    {
        if(earliest[i] == latest[i]) cout << earliest[i] + 1 << endl;
    }
}

Measured memory_bytes: 3348
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[4];
    for(int i = 0; i < 4; i++) {
      a[i] = n % 10;
      n /= 10;
    }
    String ans = "No";
    int c = 0;
    for(int i = 0; i < 2; i++) {
      if(a[i] != a[i + 1]) c = 1;
    }
    int d = 0;
    for(int i = 1; i < 3; i++) {
      if(a[i] != a[i + 1]) d = 1;
    }
    if((c == 0) || (d == 0)) ans = "Yes";
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;
 
 
int main()
{
	IOS;
	cin>>x>>y;
	cout<<6-x-y<<ln;
}

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

int main() {
 string s;cin>>s;
 int n = s.size();
 int mn=1000;
 rep(i,n-2){
   int t = stoi(s.substr(i,3));
   mn = min(mn,abs(t-753));
  }
  cout<<mn;
}

Measured memory_bytes: 256