akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
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;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}
const int INF=1e6;
const ll int MOD=998244353;

main(){
    vec v={in(),in(),in()};
    sort(all(v));
    cout<<(v==vec{5,5,7} ? "YES" : "NO");
}

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

namespace ForAtcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            BigInteger[] inputArray = Console.ReadLine().Split(' ').Select(i => BigInteger.Parse(i)).ToArray();
            BigInteger result = inputArray[0];
            for (var j = 0; j < n; j++)
            {
                if (inputArray[j] == 0)
                {
                    result = 0;
                    goto END;
                }
            }
            for (var i = 1; i < n; i++)
            {
                result = result * inputArray[i];
                if (result > (BigInteger)Math.Pow(10, 18))
                {
                    result = -1;
                    break;
                }
            }
            END:;
            Console.WriteLine(result);
        }
    }
}

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

int main(){
  int e;
  stack<int> S;
  while(cin >> e){
    if(e > 0){
      S.push(e);
      continue;
    }
    cout << S.top() << endl;
    S.pop(); 
  }

  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll MOD = ll(1e9) + 7;

int main()
{
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    for (ll i = K; i <= N+1; i++) {
        ll ci = (i*(N-i+1) + 1) % MOD;
        ans = (ans + ci) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 1e3 + 5;
const int M = 1e4 + 5;

int h, n;
int a[N], b[N];
int dp[N][M];

int f(int idx, int hp) {
    if(hp <= 0) return 0;
    if(idx > n) return INF;
    int &sol = dp[idx][hp];
    if(sol != -1) return sol;
    return sol = min(f(idx + 1, hp), f(idx, hp - a[idx]) + b[idx]);
}

void solve() {
    cin >> h >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i <= n + 3; i++) {
        for(int j = 0; j <= h + 3; j++) {
            dp[i][j] = -1;
        }
    }
    cout << f(1, h) << "\n";
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 42936
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    string s,t;
    cin >> s;
    cin >> t;
    int q;
    cin >> q;
    int a[q],b[q],c[q],d[q];
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
        c[i]--;
        d[i]--;
    }
    int n = s.size();
    int sums[n + 1] = {};
    rep(i,n){
        sums[i + 1] = s[i] == 'A' ? 1 : 2;
    }
    rep(i,n){
        sums[i + 1] += sums[i];
    }
    int m = t.size();
    int sumt[m + 1] = {};
    rep(i,m){
        sumt[i + 1] = t[i] == 'A' ? 1 : 2;
    }
    rep(i,m){
        sumt[i + 1] += sumt[i];
    }
    rep(i,q){
        if((sums[b[i] + 1] - sums[a[i]]) % 3 == (sumt[d[i] + 1] - sumt[c[i]]) % 3){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#木の根を求める
def find(x,par):
    if par[x] == x:
        return x
    else:
        return find(par[x],par)

#xとyの属する集合の併合
def unite(x,y,par,rank):
    x = find(x,par)
    y = find(y,par)
    
    if x != y:
        #xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x]==rank[y]:
                rank[x] += 1

#xとyが同じ集合に属するかの判定
def same(x,y,par):
    return find(x,par) == find(y,par)
    
n, m = map(int, input().split())
a, b = [], []
ans = 0
for i in range(m):
    ta, tb = map(int,input().split())
    a.append(ta-1)
    b.append(tb-1)
    
for i in range(m):
    par = []
    rank = []
    diff = set()
    for j in range(n): # 初期化
        par.append(j)
        rank.append(0)
    for j in range(m):
        if j == i:
            continue
        else:
            unite(a[j],b[j],par,rank)
    for j in range(n):
        diff.add(find(j,par))
    if len(diff) == 1:
        continue
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, n;
    cin >> h >> w >> n;
    map<pair<int, int>, int> black_cnt;
    REP(i, n) {
        int hh, ww;
        cin >> hh >> ww;
        hh--;
        ww--;
        FOR(dh, -1, 1)FOR(dw, -1, 1) {
            if(hh + dh <= 0 or hh + dh >= h - 1 
                or ww + dw <= 0 or ww + dw >= w - 1) continue;
            black_cnt[make_pair(hh + dh, ww + dw)]++;
        }
    }


    VL ans(10, 0);
    int comp_cnt = 0;
    for(auto& p : black_cnt) {
        ans[p.second]++;
        comp_cnt++;
    }
    ans[0] = (h - 2) * (w - 2) - comp_cnt;
    REP(i, 10) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 56576
import java.util.*;
class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
      
		int k = sc.nextInt();
		long l = 7;
      	int ans = -1;
      
      	for(int i=1;i<=k;i++){
        	if(l%k == 0){
              ans = i;
              break;
            }
          l = (l * 10 + 7) % k;
        }
      	System.out.println(ans);
		}
	}

Measured memory_bytes: 35736
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;


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

    bool flag = false;
    for (int i = 1; i <= 9; i++) {
        if (n % i == 0 and n / i < 10) {
            flag = true;
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;
#define ll long long
const ll MOD=1e9+7;
int main()
{
    ll ans=0;
    ll n,k;
    cin>>n>>k;
    for (ll i=k;i<=n+1;i++)
    {
        ans+=((n*(n+1)/2-(n-i)*(n-i+1)/2)-(i-1)*i/2+1);
        ans%=MOD;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    while (true) {
        int h,w;cin>>h>>w;
        if (!h&&!w) break;
    
        rep(i,h) {
            char c='.';
            rep(j,w) {
                if ((i==0 || i==h-1) || (j==0 || j==w-1)) c='#';
                else c='.';
                cout<<c;
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


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

using namespace std;

int main() {
  int a, b, x;
  cin >> a >> b >> x;
  if (a <= x && (a + b) > x) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  string s;
  cin >> s;
  bool ok=true;
  rep(i,3)if(s[i]==s[i+1])ok=false;
  if(ok)cout<<"Good" << endl;
  else cout << "Bad" << endl;
  return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    int price = 700;
    for (int i = 0; i < 3; ++i)
        if (s[i] == 'o') price += 100;
    cout << price;
    return 0;
}


Measured memory_bytes: 256
N,Q=map(int,input().split())
S=input()
a=[0]*N
for i in range(N-1):
  a[i+1]=a[i]+(1 if S[i:i+2]=="AC" else 0)
for i in range(Q):
  l,r=map(int,input().split())
  print(a[r-1]-a[l-1])


Measured memory_bytes: 9284
"use strict";
const main = arg => {
  let info = arg.split("\n");
  let max = 0;
  let tmp = 0;
  for(let t of info[1]){
    if(t == "I"){
      tmp += 1;
    } else {
      tmp -= 1;
    }
    if(max < tmp){
    	max = tmp;
    }
  }
  
  console.log(max);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int l[10];
int main(void){
	int n, s=0;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> l[i];
		s += l[i];
	}
	sort(l, l+n);
	s -= l[n-1];
	if(l[n-1]<s) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;

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

	if (A <= X && X <= A + B)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

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


int main(){
    vector<int> A(3);
    cin >> A[0] >> A[1] >> A[2];
    
    sort(A.begin(),A.end());
    
    int ans=0;
    if(((A[2]-A[0])%2==0&&(A[2]-A[1])%2==0) || ((A[2]-A[0])%2==1&&(A[2]-A[1])%2==1)){
        ans += A[2]-A[1];
        ans += ((A[2]-A[0])-(A[2]-A[1]))/2;
    }
    else {
        ans++;
        A[1]++;
        A[2]++;
        ans += A[2]-A[1];
        ans += ((A[2]-A[0])-(A[2]-A[1]))/2;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
require 'pp'

C=Array.new(3){Array.new(3)}
C[0]=gets.chomp.split(' ').map{|n| n.to_i}
C[1]=gets.chomp.split(' ').map{|n| n.to_i}
C[2]=gets.chomp.split(' ').map{|n| n.to_i}

# 1
flg = true
i = 1
1.upto(2){|i|
	flg = flg && C[0][0] - C[i][0] == C[0][1] - C[i][1] &&
		  C[0][0] - C[i][0] == C[0][2] - C[i][2]
}
1.upto(2){|j|
	flg = flg && C[0][0] - C[0][j] == C[1][0] - C[1][j] &&
		  C[0][0] - C[0][j] == C[2][0] - C[2][j]
}

if(flg)
	puts "Yes"
else
	puts "No"
end


Measured memory_bytes: 2044
/*
     ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् |
     उर्वारुकमिव बन्धनान्मृत्योर्मुक्षीय माऽमृतात् ||
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
     int x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;
int a[N], vis[N], n, m, k;
vi g[N], e, f;

void work()
{
     reverse(all(f));
     // print(e);
     // print(f);
     for (auto x : e)
     {
          k--;
          if (k == 0)
          {
               cout << x;
               exit(0);
          }
     }
     if (k % sz(f) == 0)
          cout << f.back();
     else
     {
          k %= sz(f);
          cout << f[k - 1];
     }
     exit(0);
}

void dfs(int i)
{
     e.pb(i);
     vis[i]++;
     for (auto x : g[i])
     {
          if (!vis[x])
               dfs(x);
          else
          {
               while (e.back() != x)
               {
                    f.pb(e.back());
                    e.pop_back();
               }
               f.pb(e.back());
               e.pop_back();
               work();
          }
     }
}

void solve()
{
     cin >> n >> k;
     k++;
     for (int i = 1; i <= n; i++)
     {
          cin >> a[i];
          g[i].pb(a[i]);
     }

     dfs(1);

}

int32_t main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

     cout << setprecision(9) << fixed;
     clock_t z = clock();
     solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

     return 0;
}

Measured memory_bytes: 33372
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	int a[n];
	REP(i, n) cin >> a[i];
	bool flag = 1;
	ll ans = 0;
	while (flag){
		flag = 0;
		REP(i, n){
			if (a[i] > 0){
				flag = 1;
				int j;
				for (j = i; j < n; j++){
					if (a[j] == 0) break;
					else a[j]--;
				}
				i = j;
				ans++;
			}
		}

	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
//#include <vector>
#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 10000100
//#define NIL -1

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

    LL num=0;
    for(LL i=0; i<s.size()-1; i++){
        if(s[i]!=s[i+1]){
            num++;
        }
    }

    cout << num << endl;

    return 0;
}


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

int main(){
    ll d,t,s;
    cin>>d>>t>>s;
    cout<<(t*s>=d?"Yes":"No")<<endl;
    return 0;
}

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

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

    int m, n;
    m = a.size();
    n = b.size();

    if(a[m-1] == b[0] && b[n-1] == c[0])
        cout<<"YES";
    else
        cout<<"NO";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define ULL unsigned long long
using namespace std;

int main() {
    //std::cout << "Hello, World!" << std::endl;

    ULL a, b, x, cnt = 0;
    scanf("%lld %lld %lld", &a, &b, &x);
    if (a == 0)
        cnt = b/x + 1;
    else
        cnt = b/x - (a-1)/x;

    printf("%lld\n", cnt);

     return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M1 = sc.nextInt();
        int D1 = sc.nextInt();
        int M2 = sc.nextInt();
        int D2 = sc.nextInt();
        if (M1!=M2) System.out.println(1);
        else System.out.println(0);
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int a = 1;
        for(int i = 1 ; i < n ; i++ ){
            if(s.charAt(i - 1) != s.charAt(i)){
                a++;
            }
        }
        System.out.println(a);
        sc.close();
    }
}

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

using namespace std;

int main(){
    int d;
    scanf("%d", &d);
    switch(d){
    case 25:
        puts("Christmas");
        break;
    case 24:
        puts("Christmas Eve");
        break;
    case 23:
        puts("Christmas Eve Eve");
        break;
    case 22:
        puts("Christmas Eve Eve Eve");
        break;
    default:
        break;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    String N = sc.next();
    String ff = N.substring(2,4);
    String ee = N.substring(4,6);
    if(ff.substring(0,1).equals(ff.substring(1,2)) && ee.substring(0,1).equals(ee.substring(1,2))){
           System.out.println("Yes");
       } else {
           System.out.println("No");
       }
    }
  }


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

typedef long long int ll;

ll f(ll x){
	if(x%4==0)return x;
	if(x%4==1)return 1;
	if(x%4==2)return x+1;
	return 0;
}

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

	if(a==0) cout<<f(b);
	
	else {ll x = f(a-1)^f(b);cout<<x;}
}

Measured memory_bytes: 256
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

N = k()
edge = [[] for _ in range(N+1)]

for _ in range(N-1):
    a,b,c = I()
    edge[a].append((b,c))
    edge[b].append((a,c))

Q,K = I()

dist = [None]*(N+1)

def dfs(x,d):
    dist[x] = d
    for y,dd in edge[x]:
        if dist[y] is not None:
            continue
        dfs(y,d+dd)

dfs(K,0)
for _ in range(Q):
    x,y = I()
    print(dist[x]+dist[y])

Measured memory_bytes: 137392
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int ans=0,mini=0;
    int a;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a>=mini){
            ans++;
            mini=a;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// AtCoder_A
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();

		// 出力
		if(a >= 3200) {
			System.out.println(s);
		} else {
			System.out.println("red");

		}
	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


Measured memory_bytes: 35680
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <tuple>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int x, y, a, b, c;
    vector<pair<ll, char>> apples;
    cin >> x >> y >> a >> b >> c;
    for (int i = 0; i < a; i++) {
        ll h;
        cin >> h;
        apples.push_back({h, 'r'});
    }
    for (int i = 0; i < b; i++) {
        ll h;
        cin >> h;
        apples.push_back({h, 'g'});
    }
    for (int i = 0; i < c; i++) {
        ll h;
        cin >> h;
        apples.push_back({h, ' '});
    }
    sort(apples.begin(), apples.end());
    reverse(apples.begin(), apples.end());
    ll ans = 0;
    int r_count = 0, g_count = 0, c_count = 0;
    for (auto apple : apples) {
        char color = apple.second;
        ll happy = apple.first;

        if (color == 'r' && r_count == x) continue;
        if (color == 'g' && g_count == y) continue;

        ans += happy;
        if (color == 'r') r_count++;
        else if (color == 'g') g_count++;
        else c_count++;

        if (r_count + c_count + g_count == x + y) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 10476
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    ll x,y;
    int ans = 1;
    cin >> x >> y;
    while(x*2 <= y){
        ans ++;
        x *= 2;
    }

    cout << ans;


    return 0;
}











Measured memory_bytes: 3536
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

type stick struct{ a, c int }
type sticks []stick

func (s sticks) Len() int           { return len(s) }
func (s sticks) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sticks) Less(i, j int) bool { return s[i].a > s[j].a }

func main() {
	n := readInt()
	m := make(map[int]int, n)
	for i := 0; i < n; i++ {
		a := readInt()
		m[a]++
	}

	sts := sticks(make([]stick, 0, len(m)))
	for a, c := range m {
		sts = append(sts, stick{a, c})
	}
	sort.Sort(sts)
	t := 0
	for _, st := range sts {
		if t == 0 {
			if st.c >= 4 {
				fmt.Println(st.a * st.a)
				return
			} else if st.c >= 2 {
				t = st.a
			}
		} else {
			if st.c >= 2 {
				fmt.Println(t * st.a)
				return
			}
		}
	}
	fmt.Println(0)
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main()
{
  int N,K;
  cin >> N >> K;
  vll A(N);
  cin >> A;
  
  ll ans = LLONG_MAX;
  REP(i,1<<N){
    if(counter(i) < K)continue;
    vint v;
    REP(j,N)if(i & (1<<j))v.pb(j);
    ll cost=0;
    ll pre = -1LL;
    REP(j,v.size()){
      ll ma=pre;
      for(int k=(j?v[j-1]:0); k<v[j];k++)chmax(ma,A[k]);
      cost += max(0LL,ma-A[v[j]]+1);
      pre=max(ma+1,A[v[j]]);
    }
    chmin(ans,cost);
  }
  cout << ans << endl;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;

    int tp = ceil((n * 1.0)/ min({a, b, c, d, e}));
    cout << tp + 4 << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

int main(){
    ll A,B,C,K;
    cin>>A>>B>>C>>K;
    if(K<A) cout<<K<<endl;
    else if(K<=A+B) cout<<A<<endl;
    else cout<<A-(K-A-B)<<endl;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

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

int main()
{
    int n,m;
    string s;
    cin>>n>>m>>s;
    vector<int> ans;
    int now=n;
    while (now>0)
    {
        bool ok=false;
        for (int deme = min(now,m); deme > 0; deme--)
        {
            if(s[now-deme]=='0')
            {
                now-=deme;
                ans.push_back(deme);
                ok=true;
                break;
            }
        }
        if(ok==false)
        {
            cout<<-1<<endl;
            return 0;
        }
    }
    for (int i = ans.size() - 1; i >= 0; i--)
    {
        cout<<ans[i];
        if(i==0) cout<<endl;
        else cout<<" ";
    }
    
    
    return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ins insert
#define sz(x) (long long)x.size()
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
const ld pi = 3.141592653;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

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

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int T = 1;
        //cin>>T;
        while(T--)
        {
                ll n, i, ans=0;
                cin>>n;
                vector<ll> a(n);
                for(i=0; i<n; i++) cin>>a[i];
                if(n==1) {}
                else{
                        for(i=1; i<n; i++){
                                if(a[i] < a[i-1]){
                                        ans = ans + abs(a[i] - a[i-1]);
                                        a[i] = a[i-1];
                                }
                        }
                }
                cout<<ans;
        }
        return 0;
}

Measured memory_bytes: 4748
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
q = int(input())
s = sum(a)
d = defaultdict(int)
for x in a:
    d[x] += 1
for i in range(q):
    b,c = map(int,input().split())
    s += (c-b) * d[b]
    d[c] += d[b]
    d[b] = 0
    print(s)

Measured memory_bytes: 24256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


std::vector<int> sieve(int n) {
  std::vector<int> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (int i = 2; i*i < n; ++i) {
    if (res[i] < i) continue;
    for (int j = i*i; j < n; j += i)
      if (res[j] == j) res[j] = i;
  }
  return res;
}

std::vector<int> factor(int n, const std::vector<int>& min_factor) {
  // min_factor は sieve() で得られたものとする
  std::vector<int> res;
  while (n > 1) {
    res.push_back(min_factor[n]);
    n /= min_factor[n];
    // 割った後の値についても素因数を知っているので順次求まる
  }
  return res;
}

int main(){
    ll n;cin >> n;
    vl v(n);rep(i,n)cin >> v[i];
    vector<int> minfac=sieve(1000010);
    set<ll> st;
    bool ok=true;
    rep(i,n){
        vector<int> p=factor(v[i],minfac);
        //for(auto z:p)cout << z <<" ";cout <<endl;
        for(auto z:p)if(st.count(z))ok=false;
        for(auto z:p)st.ins(z);
    }
    if(ok)cout << "pairwise coprime" <<endl;
    else{
        ll ret=v[0];
        rep(i,n)ret=__gcd(ret,v[i]);
        if(ret==1)cout << "setwise coprime" <<endl;
        else cout << "not coprime" <<endl;
    }
} 

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k, ans = 1;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    ans += min(ans, k);
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
  long long n1; cin >> n1;
  for (long long h = 1; h < 3500; ++h)
  for (long long n = 1; n < 3500; ++n)
    if (4 * n * h - n1 * (n + h) != 0 && n1 * n * h >= (4 * n * h - n1 * (n + h)) && n1 * n * h / (4 * n * h - n1 * (n + h)) > 0)
  if (n1 * n * h % (4 * n * h - n1 * (n + h)) == 0)
  {
    cout << h << " " << n << " " << n1 * n * h / (4 * n * h - n1 * (n + h)) << endl;
    return 0;
  }


  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long M = 1_000_000_007;
    int N = scanner.nextInt();
    int K = scanner.nextInt();
    long res = 0;
    long[] count = new long[K + 1];
    for (int k = K; k >= 1; k--) {
      int n = K / k;
      count[k] = modpow(n, N, M);
      for (int i = 2; i * k <= K; i++) {
        count[k] -= count[i * k];
        if (count[k] < 0) count[k] += M;
      }
      res += count[k] * k % M;
      res %= M;
    }
    System.out.println(res);
  }

  private static long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
      if (n % 2 == 1) res = (res * a) % mod;
      a = (a * a) % mod;
      n >>= 1;
    }
    return res % mod;
  }
}


Measured memory_bytes: 28108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=105;
const int M=100050;
int a[N];
bool dp[M];
int main()
{
int n,k;
scanf("%i %i",&n,&k);
for(int i=1;i<=n;i++)
scanf("%i",&a[i]);
for(int j=1;j<=k;j++)
for(int i=1;i<=n;i++)
if(j>=a[i] && dp[j-a[i]]==0)
dp[j]=1;
printf("%s",dp[k]?"First":"Second");
return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int A[3]; rep(i,3)cin >> A[i];
  sort(A, A+3);
  if(A[0] == A[1]  && A[1]== 5 && A[2] == 7) 
    cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int i,x,t,p;
  cin>>x;
  i=0;
  t=100;
  while(t<x)
  {
      p=(t*1)/100;
      t=t+p;
      i++;
  }
  cout<<i;
}


Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int n,a[200010];
    long long ans = 0;
    scanf("%d",&n);
    for (int i = 1; i <= n; i++) {
        scanf("%d",&a[i]);
    }
    int j = 1;
    long long suma = 0,sumb = 0;
    for (int i = 1; i <= n; i++) {
        while (j <= n && (suma + a[j]) == (sumb ^ a[j])) {
            suma += a[j];
            sumb ^= a[j];
            j++;
        }
        ans += j - i;
        suma -= a[i];
        sumb ^= a[i];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4528
N=int(input())
A=list(map(int,input().split()))
B=map(int,input().split())
C=list(map(int,input().split()))
l=[]

for i in range(len(A)-1):
    if A[i]+1==A[i+1]:
        l.append(C[A[i]-1])

total=sum(B)+sum(l)
print(total)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int get_win_score (char c, int r, int s, int p) {
    if ( c == 'r' )
        return p;
    if ( c == 's' )
        return r;
    if ( c == 'p' )
        return s;
    return 0;
}

int main (void) {
    int n, k;
    int r, s, p;
    int i, j;

    scanf("%d%d%d%d%d", &n, &k, &r, &s, &p);

    long long tmp, ans=0;
    char t[n+1], pre;

    scanf("%s", &t[1]);

    for ( i=1; i<=k; i++ ) {
        tmp = get_win_score(t[i], r, s, p);
        pre = t[i];
        for ( j=i+k; j<=n; j+=k ) {
            if ( t[j] == pre )
                pre = '0';  /* dummy */
            else {
                tmp += get_win_score(t[j], r, s, p);
                pre = t[j];
            }
        }
        ans += tmp;
    }

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


Measured memory_bytes: 256
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
		
const double eps = 1e-9;																							   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////

///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////

void functionK(LL n, LL k){
	int digit = (int)(floor(log(n) / log(k)) + 1);
	cout << digit << endl;
}

/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  LL n, k;
  cin >> n >> k;
  
  functionK(n, k);
  
  

	
	return 0;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

const ll MOD = 1000000007;
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll COMinv(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return finv[n] * (fac[k] * fac[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}

using Graph = vector<vector<int>>;
ll N, K;
ll ans;

void dfs(const Graph& graph, int v, int p) {
	//行きがけ処理
	ll csize = graph[v].size() - 1;
	if (p == -1){
		csize++;
		if (K-1 < csize){
			ans = 0;
		} else {
			ll tmp = (fac[K-1] * finv[K - 1 - csize]) % MOD;
			ans = (ans * tmp) % MOD;
		}
	} else if (csize == 0){
	} else {
		if (K-2 < csize){
			ans = 0;
		} else {
			ll tmp = (fac[K-2] * finv[K - 2 - csize]) % MOD;
			ans = (ans * tmp) % MOD;
		}
	}
	for (auto nv : graph[v]){
		if (nv == p) continue;
		dfs(graph, nv, v);
	}
}

int main() {
	cin >> N >> K;

	Graph graph(N);
	for (int ii = 0; ii < N-1; ++ii){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	COMinit();

	int root = 0;
	ans = K;
	dfs(graph, /*v=*/root, /*p=*/-1);
	
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 21120
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

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

int main()
{

   string s; cin>>s;

   int q; scanf("%d" , &q);
    bool rev = false;
   for(int i = 0 ; i<q ; i++)
   {
    int t; scanf("%d", &t);
    if(t==1)rev = !rev;
    else
    {
        int f; scanf("%d", &f);
        char ch; cin>>ch;

        if(f==1)
        {
            if(!rev)
            {
                s.insert(0,1,ch);
            }
            else
            {
                s.push_back(ch);
            }

        }
        else if(f==2)
        {
            if(!rev)
            {
              s.push_back(ch);
            }
            else
            {
               s.insert(0,1,ch);
            }
        }
    }
}

    if(rev)
    {
        for(int i = s.length()-1 ; i>=0 ; i--)
            cout<<s[i];
        printf("\n");
    }
    else
    {
        printf("%s\n",s.c_str());
    }

    return 0;
}


Measured memory_bytes: 1028
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug (fprintf(stderr,"orzyrt\n"),fflush(stderr))
	#define debug(__a...) (fprintf(stderr,__a),fflush(stderr))
	#define setfile(__a) ('orzyrt')
	#define Compile(__a) system("g++ "__a".cpp -lm -o "__a)
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
	#define setfile(__a) freopen(__a".in","r",stdin);freopen(__a".out","w",stdout)
	#define Compile(__a) ('orzyrt')
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(b<a)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

namespace Night{
	const int mod = 998244353;
	int n;
	int a[111111];
	LL ans=1;
	int main(){
		read(n);
		for(R int i=0;i<n;++i)read(a[i]);
		sort(a,a+n);
		for(R int i=0;i<n;++i){
			(ans*=__gcd(a[i],i))%=mod;
		}
		cout<<ans;
		return 0;
	}
}
int main(){
	return Night::main();
}


Measured memory_bytes: 640
// [AT1979 BBQ Easy] https://www.luogu.org/problem/AT1979
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

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

    n *= 2;

    int a[n+3];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    sort(a, a+n);

    int ans = 0;
    for (int i = 0; i < n; i+=2)
    {
        ans += a[i];
    }

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

Measured memory_bytes: 256
import sys
import numpy as np
input = sys.stdin.readline
N, M , X, Y = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]
xmax = max(x)
ymin = min(y)
Z = [int(x) for x in range(X + 1, Y + 1)]
for z in Z:
    if xmax < z and ymin >= z:
        print("No War")
        sys.exit()
print("War")


Measured memory_bytes: 12436
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll MOD=1e9+7 ;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string s;
    cin >> s;
    bool flag = true;

    rep(i, s.length())
    {
        if (i&1)
        {
            if (s[i]=='R')
            {
                flag = false;
                break;
            }
        }
        else
        {
            if (s[i] == 'L')
            {
                flag = false;
                break;
            }
        }
        
    }
    if (flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256