akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
ll modinv(ll a, ll m) {
	assert(m > 0);
	if (m == 1) return 0;
	a %= m;
	if (a < 0) a += m;
	assert(a != 0);
	if (a == 1) return 1;
	return m - modinv(m, a) * m / a;
}

template <int MOD_> struct modnum {
private:
	int v;
public:
	static const int MOD = MOD_;

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int () const { return v; }
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum operator ~ () const {
		modnum res;
		res.v = modinv(v, MOD);
		return res;
	}

	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= (~o);
	}

	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

using num = modnum<998244353>;

vector<num> fact;
vector<num> ifact;

void init(){
	fact = {1};
	for(int i = 1; i < 1100000; i++) fact.push_back(i * fact[i-1]);
	for(num x : fact) ifact.push_back(1 / x);	
}

num ncr(int n, int k){
	if(k < 0 || k > n) return 0;
	return fact[n] * ifact[k] * ifact[n-k];
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	init();

	int n, k;
	cin >> n >> k;

	num ans = 0;
	for(int r = 0; r <= k; r++){
		int b = k - r;
		if(r < b || r < n) continue;
		num cur = 0;
		if(r == b){
			cur += ncr(2*r-1, r);
			cur -= ncr(2*r-1, n-2);
		} else {
			cur += ncr(r+b, r);
			cur -= ncr(r+b, -r+n-1+b);
		}
		ans += cur;
	}
	cout << (int)ans << '\n';
}

Measured memory_bytes: 20712
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

const int N=1005;
const int MOD=1e9+7;

int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n,m;
  cin>>n>>m;
  vector<int> v;
  vector<int> v1;
  if(n>m)
  {
  	int t=n;
  	while(t--)
  	{
  	
  		v.push_back(m);
  	}
  }
 for(int i=0;i<v.size();i++)
 {
 	cout<<v[i];
 }


 if(n<=m)
  {
  	int t=m;
  	while(t--)
  	{
  	
  		v1.push_back(n);
  	}
  }
 for(int i=0;i<v1.size();i++)
 {
 	cout<<v1[i];
 }
  
  






  
}



Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	A := sc.nextIntSlice(N)
	ans := int(1e+9)
	for i := -100; i <= 100; i++ {
		sum := 0
		for _, a := range A {
			sum += pow(abs(i-a), 2)
		}
		if sum < ans {
			ans = sum
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    double N, M, d;
    cin >> N >> M >> d;
    if(d == 0) {
        cout << (1 / N) * (M - 1) << endl;
        return 0;
    }
    cout << fixed << setprecision(10) << (2 * (N - d)) / (N * N) * (M - 1)
         << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int R;
  cin >> R;
  cout << setprecision(16) << 2*M_PI*R << endl;
  return 0;
}

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

int main() {
	long long w, h, x, y;
	cin>>w>>h>> x>>y;
	cout<<setprecision(12)<<w*h/2.0<<" ";
	cout<<(2*x == w && 2*y == h);
	    
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
	int n;
	scanf("%d",&n);
	int k;
	for(int i=1;i<n;i++){
		if(n<=i*(i+1)/2){
			k=i;
			break;
		}
	}
	for(int i=k;i>=1;i--){
		if(n>=i){
			printf("%d\n",i);
			n=n-i;
		}
	}
	if(n==1)printf("1\n");
	if(n==2)printf("2\n");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  int a, b, d, r;
  double f;
  
  scanf("%d %d", &a, &b);
  
  d = a / b;
  r = a % b;
  f = (double) a / (double) b;
  
  printf("%d %d %lf",d, r, f);
  return 0;
}


Measured memory_bytes: 2100
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        int G = sc.nextInt();
        int B = sc.nextInt();
        int n = sc.nextInt();
        int count = 0;
        for (int i = 0; R * i <= n; i++) {
            for (int j = 0; R * i + G * j <= n; j++) {
                int val = R * i + G * j;
                int diff = n - val;
                if (diff % B == 0) count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23252
#pragma region Template
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RNG(i, a, b) for(int i = a; i < b; i++)
#define RBF(i, v) for(auto& i : v)
#define ALL(x) x.begin(), x.end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;
template<typename T> using VP = vector<pair<T, T>>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX >> 2;
const int INF = INT_MAX >> 1;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }
#pragma endregion

signed main()
{
	LL n;
	cin >> n;
	V<LL> a(n+1), lim(n);
	RBF(ai, a) cin >> ai;

	if (n == 0) {
		if (a[0] == 1) {
			col(1);
		}
		else col(-1);
		return 0;
	}

	LL v = 1, i = 0, ans = a[n];
	while (i < n) {
		LL u = v - a[i];
		
		if (u <= 0) {		
			col(-1);
			return 0;
		}
		lim[i] = v;
		if (v < INF64) v = 2 * u;
		else v = INF64;
		i++;
	}
	i = n-1;
	v = a[n];
	while (i >= 0) {
		if (v > 2 * (lim[i] - a[i])) {
			col(-1);
			return 0;
		}
		v = min(v, lim[i] - a[i]) + a[i];
		ans += v;
		i--;
	}

	col(ans);
	return 0;
}


Measured memory_bytes: 4732
using System;
 
namespace HelloWorld
{
    class Program
    {
        static string[] letters = { "the", "this", "that" };
        const int COUNT = 'z' - 'a' + 1;

        static void Main()
        {
            string line;
            string result = "";
            while ((line = Console.ReadLine()) != null)
            {
                for (int i = 0; i < COUNT; i++)
                {
                    bool isAccepted = false;
                    result = Shift(line, i);
                    foreach (var let in letters)
                    {
                        if (result.Contains(let))
                        {
                            isAccepted = true;
                            break;
                        }
                    }
                    if (isAccepted)
                    {
                        break;
                    }
                }
                Console.WriteLine(result);
            }
        }

        static string Shift(string line, int i)
        {
            string result = "";
            foreach (var letter in line)
            {
                result += IsLetter(letter) ? (char)((letter - 'a' + i) % COUNT + 'a') : letter;
            }
            return result;
        }

        static bool IsLetter(char chara)
        {
            return 'a' <= chara && 'z' >= chara;
        }
    }
}


Measured memory_bytes: 17868
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int dp[SIZE][2];
char s[SIZE];
int main(){
    int n; R(n);
    RS(s+1);
    FOR(i,1,n){
        dp[i][0]=dp[i-1][0]+(s[i]=='.');
    }
    for(int i=n;i>0;i--){
        dp[i][1]=dp[i+1][1]+(s[i]=='#');
    }
    int an=0;
    FOR(i,0,n)an=max(an,dp[i][0]+dp[i+1][1]);
    W(n-an);
    return 0;
}


Measured memory_bytes: 3584
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,x[105]={},ans=inf,cnt=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> x[i];
  }
  for(int i=1; i<=100; i++) {
    cnt=0;
    for(int j=0; j<n; j++) {
      cnt+=(x[j]-i)*(x[j]-i);
    }
    ans=min(ans,cnt);
  }
  cout << ans << endl;
}

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

int main()
{
  int N,K;
  cin>>N>>K;
  
  vector<int> p;
  
  for(int i = 0;i < N;i++)
  {
    int tmp;
   cin>>tmp;
    p.push_back(tmp);
  }
  
  sort(p.begin(),p.end());
  
  int res = 0;
  
  for(int i = 0;i < K;i++)
  {
    res += p[i];
  }
  
  cout<<res;
  
  return 0;

}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
signed main() {
    int A;cin>>A;
    string S;cin>>S;
    int B=0;
    B+=(S[0]-'0')*100;
    B+=(S[2]-'0')*10;
    B+=(S[3]-'0');
    cout<<A*B/100<<endl;
    
}


Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int x;
int zeinuki(int n){
for(int i = n;i >= 0;i--){
	if((i * (100 + x))/100 == n)return i;
	}
	return 0;
}

int main() {
	int y,s,ax,ay,ymax;
	while(1){
		ymax = 0;
		cin >> x >> y >> s;
		if(x == 0)break;
		for(int i = 1;i <= s/2;i++){
			//cout << i << " " << s - i << endl;
			ax = zeinuki(i);
			ay = zeinuki(s-i);
			//cout << ax << " " << ay <<endl;
			ax = ax * (100 + y)/100;
			ay = ay * (100 + y)/100;
			ymax = max(ymax,(ax + ay));
			//cout << ax << " " << ay <<  " " << ymax << endl;
		}
		cout << ymax << endl;
	}
	
	return 0;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long ans{0}, n{0}, m{0}, nm{0};
    for(unsigned long i = 0; i < N; ++i){
        string s;
        cin >> s;
        bool p = 0;
        for(const auto c : s){
            if(p && c == 'B')++ans;
            p = (c == 'A');
        }
        if(s[0] == 'B')++n;
        if(s.back() == 'A')++m;
        if(s[0] == 'B' && s.back() == 'A')++nm;
    }
    if(n == nm && m == nm)--n;
    cout << min(n, m) + ans << endl;
    return 0;
}

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

vector<vector<int>> graph;
int val[10000];
int arr[10000];

void dfs(int u, int p, int &ans, int &j)
{
    for (int v : graph[u])
        if (v != p)
            dfs(v, u, ans, j);;
    
    if (u)
        ans += val[j];
    arr[u] = val[j];
    ++j;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    graph.resize(n);
    for (int i = 1; i != n; ++i)
    {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    for (int i = 0; i != n; ++i)
        cin >> val[i];
    sort(val, val + n);
    
    int ans = 0;
    int j = 0;
    dfs(0, -1, ans, j);
    
    cout << ans << '\n';
    for (int i = 0; i != n; ++i)
        cout << arr[i] << ' ';
    
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	constexpr Int MOD = 1e9 + 7;
	int N;
	cin >> N;
	vector<Int> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }

	vector<Int> d(N, 0);
	for (int i = 0; i < N; ++i) {
		d[i] = a[i];
		if (i > 0) { (d[i] += d[i - 1]) %= MOD; }
	}

	Int ans = 0;
	for (int i = N - 1; i > 0; --i) {
		(ans += a[i] * d[i - 1] % MOD) %= MOD;
	}
	cout << ans % MOD << "\n";

	return 0;
}


Measured memory_bytes: 6424
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <utility>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long int ll;
#define MOD 1000000007
#define MAX 1000000000000000000
#define ln "\n"
#define pb push_back
#define pll pair<ll,ll>
#define f first
#define s second
#define TEST ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main() 
{
	fast_io;
	ll m1,m2,d1,d2;
	//string s;
	//TEST
	//{
	    cin>>m1>>d1;
	    cin>>m2>>d2;
	    if((m1==4 || m1==6 || m1==9 || m1==11) && (d1==30))
	    cout<<1<<endl;
	    else
	    if((m1==1 || m1==3 || m1==5 || m1==7 || m1==8 || m1==10 || m1==12) && (d1==31))
	    cout<<1<<endl;
	    else
	    if(m1==2 && d1==28)
	    cout<<1<<endl;
	    else
	    cout<<0<<endl;
	//}
	return 0;
}

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

int main() {
  int N;
  cin >> N ;
  
  for( int i = 0; i < N; i++){
    string x;
    cin >> x;
    if(x == "Y"){
        cout << "Four" << endl;	
        break;
 	   }
    else if (i == N-1){
      cout << "Three" << endl;
    	}
	}
}

Measured memory_bytes: 3656
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut s = vec![];
    let mut t = vec![];
    for i in 0..n {
        let v = read_vec::<String>();
        s.push(v[0].clone());
        t.push(i64::from_str_radix(&v[1], 10).unwrap());
    }
    let x = read::<String>();
    let mut ans = 0;
    let mut found = false;
    for (title, tt) in s.into_iter().zip(t) {
        if found {
            ans += tt;
        }
        if title == x {
            found = true;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
n = int(input())
a = list(map(int,input().split()))
ans = 1
lim = int(1e+18)
if a.count(0):
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if lim < ans:
        print(-1)
        exit()
print(ans)


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

int main() {
  string S;
  cin >> S;
  if (S == "Sunny")
  {
    cout << "Cloudy" << endl;
  }
  else if (S == "Cloudy")
  {
    cout << "Rainy" << endl;
  }
  else
  {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 3552
n=int(input())
s = [0] * (n+1)

print(0,flush=True)
a = input()
if a=='Vacant':
    exit()
s[0]=a
s[n]=a

l = 0
r = n
while True:
    m = (r+l)//2
    print(m,flush=True)
    a = input()
    if a=='Vacant':
        exit()
    s[m]=a
    if s[l]==s[r]:
        if s[l]==s[m]:
            if (m-l)%2==1:
                r = m
            else:
                l = m
        else:
            if (m-l)%2==1:
                l = m
            else:
                r = m
    else:
        if s[l]==s[m]:
            if (m-l)%2==1:
                r = m
            else:
                l = m
        else:
            if (m-l)%2==1:
                l = m
            else:
                r = m


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

// マクロ //
#define rep(i,N) for(int i = 0; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //

vb seen;
vvi graph;
vi H;
int high = 0;
int max_at = -1;

void search(int n) {
    seen[n] = true;
    if (chmax(high, H[n])) {
        max_at = n;
    }

    for (auto x : graph[n]) {
        if (seen[x]) continue;
        search(x);
    }
}

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    int N, M;
    cin >> N >> M;
    vi A(M), B(M);
    H.assign(N, 0);
    rep(i, N) cin >> H[i];
    rep(i, M) cin >> A[i] >> B[i];

    graph.resize(N);
    seen.assign(N, false);
    rep(i, M) {
        graph[A[i] - 1].push_back(B[i] - 1);
        graph[B[i] - 1].push_back(A[i] - 1);
    }

    int ans = 0;
    
    rep(i, N) {
        bool flag = false;
        for (auto x : graph[i]) {
            if (H[i] <= H[x]) flag = true;
        }
        if (flag) continue;
        ans++;
    }
    cou(ans);
}

Measured memory_bytes: 9544
a, b, c, x, y=[int(i) for i in input().split()]

price = 0

if x - y > 0:
    diff = x - y
    n_same = y
    rest_pr = a
else:
    diff = y - x
    n_same = x
    rest_pr = b


if a + b < c * 2:
    price += (a+b) * n_same
else:
    price += c * n_same * 2

if rest_pr < c * 2:
    price += rest_pr * diff
else:
    price += c * diff * 2

print(price)

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

int calc(int x){
    int ret = 0;
    while(x % 100 == 0){
        x /= 100;
        ret++;
    }
    return ret;
}

int main(){
    int D, N;
    cin >> D >> N;

    int num = 0, cnt = 0;
    while(cnt < N){
        num++;
        if(calc(num) == D) cnt++;
    }
    cout << num << endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    a, b, c = map(int, raw_input().split())
    if a < b:
        if b < c:
            print a, b, c
        elif a < c:
            print a, c, b
        else:
            print c, a, b
    else:
        if a < c:
            print b, a, c
        elif b < c:
            print b, c, a
        else:
            print c, b, a

Measured memory_bytes: 4204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	ll N;
	cin >> N;
	ll A[100000];
	rep(i, N) cin >> A[i];
	
	ll sum = 0;
	rep(i, N) sum += A[i];

	int OK = 1;
	if (sum % (N * (N + 1) / 2)) OK = 0;
	else {
		ll k = sum / (N * (N + 1) / 2);
		rep(i, N) {
			A[i] -= k * (i + 1);
		}
		ll kazu = 0;
		rep(i, N - 1) {
			if ((A[i] - A[i + 1]) % N || A[i] < A[i + 1]) OK = 0;
			else {
				kazu += (A[i] - A[i + 1]) / N;
			}
		}
		if ((A[0] - A[N - 1]) % N) OK = 0;
		else {
			if (kazu > k) OK = 0;
		}
	}

	if (OK) co("YES");
	else co("NO");


	Would you please return 0;
}

Measured memory_bytes: 1024
h, w = map(int, input().split())

a = []
for i in range(h):
    A = list(map(int, input().split()))
    a.append(A)

ans_n = 0
ans_xy = []

for i in range(h):
    for j in range(w):
        if a[i][j] % 2 == 1:
            if j < w-1:
                a[i][j] = 0
                a[i][j+1] += 1
                ans_n += 1
                ans_xy.append([i + 1, j + 1, i + 1, j + 2])

for i in range(h):
    if a[i][w-1] % 2 == 1:
        if i < h - 1:
            a[i][w-1] = 0
            a[i+1][w-1] += 1
            ans_n += 1
            ans_xy.append([i + 1, w, i + 2, w])

print(ans_n)
for k in range(ans_n):
    print(*ans_xy[k])

Measured memory_bytes: 30256
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod
def iparse():
    return list(map(int, input().split()))

if __name__ == "__main__":
    s = [list(input()) for i in range(3)]
    for e in s:
        e.reverse()
    
    turn = 0
    while True:
        if len(s[turn]) == 0:
            break
        tmp = s[turn].pop()
        if tmp == 'a':
            turn = 0
        elif tmp == 'b':
            turn = 1
        else:
            turn = 2

    if turn == 0:
        print("A")
    elif turn == 1:
        print("B")
    else:
        print("C")
        
    


Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(abs(a-b)>max(abs(a-c),abs(c-b)))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> vs(N);
  for(int i=0; i<N; i++){ cin >> vs.at(i); }
  vector<int> cs(N);
  for(int i=0; i<N; i++){ cin >> cs.at(i); }

  int res=0;
  for(int i=0; i<N; i++){
    int margin = vs.at(i) - cs.at(i);
    if( margin>0 ){ res+=margin; }
  }
  
  cout << res << endl;

}

Measured memory_bytes: 256
import numpy as np
A=list(list(map(int, input().split())) for _ in range(3))
N=int(input())
B=list(int(input()) for _ in range(N))
a=np.array(A)
c=a.flatten()
C=c.tolist()

for c in range(len(C)):
    for b in range(len(B)):
        if C[c]==B[b]:
            C[c]=0

if (sum(C[:3])==0) | (sum(C[3:6])==0) | (sum(C[6:9])==0):
    print("Yes")
elif (C[0]+C[3]+C[6]==0) | (C[1]+C[4]+C[7]==0) | (C[2]+C[5]+C[8]==0):
    print("Yes")
elif (C[0]+C[4]+C[8]==0) | (C[2]+C[4]+C[6]==0): 
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14244
from collections import defaultdict

N,Q=map(int,input().split())
l=[ tuple( map(int,input().split()) ) for i in range(N-1) ]
p=[ tuple( map(int,input().split()) ) for i in range(Q) ]
d=defaultdict(list)
for vert,childs in l:
    d[vert].append(childs)


d_2=defaultdict(int)
for i in range(1,N+1):
    d_2[i]=0

for p,x in p:
    d_2[p]+=x

for n in d_2.keys():
    for m in d[n]:
        d_2[m]+=d_2[n]

ans=d_2.values()
print(*ans)

Measured memory_bytes: 150292
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let b = v[1];
	println!("{}", (a-1)*(b-1));
}

Measured memory_bytes: 4352
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll A,B;
	cin >> A>>B;
	
	// 解法
	if (B%A==0) printf("%lld\n", A+B);
	else printf("%lld\n", B-A);
}


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

using namespace std;

int main(){

  string s;
  cin >> s;
  int n = s.size();
  long long res = 0;
  int suff = 0;
  int pot = 1;
  int mod = 2019;
  unordered_map<int, int> cnt_suff;
  cnt_suff[suff]++;
  for(int i = n - 1 ; i >= 0; i--){
    int digit = s[i] - '0';
    suff = (suff + digit * pot) % mod;
    pot = (pot * 10) % mod;
    res += cnt_suff[suff];
    cnt_suff[suff]++;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long h, w, a, b;

  	cin >> h >> w >> a >> b;
  	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if((j<a&&i<b)||(a<=j&&b<=i&&j<w-1)){
				cout <<1;
			}else if((a<=j&&i<b&&j<w-1) || (j<a&&b<=i)){
				cout <<0;
			}else if((j==w-1)&&i<b){
				cout<<0<<endl;
			}else if((j==w-1)&&b<=i){
				cout<<1<<endl;
			}
		}
	}
}


Measured memory_bytes: 1280
N, M = gets.split.map(&:to_i)

s = []

# p s

M.times do |i|
  
  p, y = gets.split.map(&:to_i)
  s.push([p, y, i+1, nil])
  
end

ns = s.sort_by do |b|
  [b[0], b[1], b[2], b[3]]
end

t = 1
ns[0][3] = 1
1.upto(M-1) do |i|
  
  t = 0 if ns[i][0] != ns[i-1][0]
  t += 1
  ns[i][3] = t
end

ns = ns.sort_by do |b|
  b[2]
end

# p ns 

ns.each do |k|
  
  puts k[0].to_s.rjust(6,?0) + k[3].to_s.rjust(6,?0)

end

  
  
  


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

using namespace std;

int main()
{
	string a_str, b_str;
	cin >> a_str;
	cin >> b_str;

	int a, b;
	a = stoi(a_str);
	b = stoi(b_str);

	cout << a * b << " " << 2 * (a + b) << endl;

	return 0;
}


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

using namespace std;

int main()
{
    string s;
    while (cin >> s) {
        char c[3][3];
        for (int i = 0; i < 9; i++) {
            c[i/3][i%3] = s[i];
        }

        auto check = [&](char m) -> bool {
            for (int i = 0; i < 3; i++) {
                if (c[i][0] == m && c[i][1] == m && c[i][2] == m) {
                    return true;
                }
                if (c[0][i] == m && c[1][i] == m && c[2][i] == m) {
                    return true;
                }
            }
            if (c[0][0] == m && c[1][1] == m && c[2][2] == m) {
                return true;
            }
            if (c[0][2] == m && c[1][1] == m && c[2][0] == m) {
                return true;
            }
            return false;
        };

        if (check('o')) {
            cout << 'o' << endl;
        } else if (check('x')) {
            cout << 'x' << endl;
        } else {
            cout << 'd' << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3040
#include <stdio.h>
int main(){

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

  r=x%y;

  while(r!=0){

    x=y;
    y=r;
    r=x%y;

  }

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

  return 0;

}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define Jai_Hind_Dosto ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define carry_is_Live ll bakchodi; cin>>bakchodi; while(bakchodi--)
typedef  int ll;
#define pahli_fursat 0
#define mithai_ki_dukan 200
int main() {
    Jai_Hind_Dosto;
    //carry_is_Live
    {
       ll n;
       cin>>n;
       ll x=n%10;
       if(x==3){
           cout<<"bon\n";
       }
       else if(x<2 || x==6 || x==8){
           cout<<"pon\n";
       }
       else{
           cout<<"hon\n";
       }
       
    }
	return pahli_fursat;
}


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

int main() {
  while(true) {
    int a, b;
    cin >> a >> b;
    if(a != 0 || b != 0) {
      if(a < b)
        cout << a << " " << b << endl;
      else
        cout << b << " " << a << endl;
    } else {
      break;
    }
  }
}



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

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    vector<int> v(N);

    int sum = 0;
    for(auto& e : v)
    {
        cin >> e;
        sum += e;
    }
    double ave = (double)sum / N;

    double d_min = 0.0;
    map<double, int> m;
    //for(auto& e : v)
    for(int i = 0; i < N; ++i)
    {
        double d = abs((double)v[i] - ave);
        m.insert(make_pair(d, i));
    }

    cout << m.begin()->second << endl;

    return 0;
}

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

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;
int n;
string s;
int main(){
    cin>>n>>s;
    int ans=0;
    rep(i,0,n-2){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            ans++;
        }
    }
    puts(ans);
}

Measured memory_bytes: 256
H,W=map(int,input().split())
grid=[]
for _ in range(10):
    grid.append(list(map(int,input().split())))

Wall=[]
for _ in range(H):
    Wall.append(list(map(int,input().split())))


d=[0]*10
for start in range(10):

    #距離格納配列
    distance=grid[start]

    #確定済み配列
    visited=[0] * 10
    visited[start] = 1
    size = 1

    while size<10:
        min_distance = 10**9
        for i in range(10):
            if visited[i]==0 and distance[i] <min_distance:
                min_distance = distance[i]
                v = i

        visited[v] = 1
        size+=1

        for x in range(10):
            if distance[x] > distance[v] + grid[v][x]:
                distance[x] = distance[v] + grid[v][x]

    d[start]=distance[1]

ans=0
for i in range(H):
    for j in range(W):
        if Wall[i][j]==-1:
            continue
        else:
            ans+=d[Wall[i][j]]

print(ans)


Measured memory_bytes: 9468
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int64 MOD = 1000000007;

template<typename T> void fastin(T &num) {
  bool negative = false;
  T c;
  num = 0;
  c = getchar_unlocked();
  if (c == '-') {
    negative = true;
    c = getchar_unlocked();
  }
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
  if (negative) num *= -1;
}

template<typename T> void fastout(T &n) {
  T N = n, rev, count = 0;
  rev = N;
  if (N == 0) {
    putchar_unlocked('0');
    putchar_unlocked('\n');
    return;
  }
  while ((rev % 10) == 0) { 
    ++count; rev /= 10;
  }
  rev = 0;
  while (N != 0) { 
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) { 
    putchar_unlocked(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar_unlocked('0');
  putchar_unlocked('\n');
}

int n; int64 k;
vector<int> graph[101010];

int64 ans;

void dfs(int v, int p) {
  int64 can = k - 1;
  if (p != -1) --can;
  for (auto next : graph[v]) {
    if (next == p) continue;
    (ans *= can) %= MOD;
    --can;
    dfs(next, v);
  }
}

int main(){
  //ios_base::sync_with_stdio(false);
  //cin.tie(nullptr);
  fastin(n); fastin(k);
  //cin >> n >> k;
  rep(i, n - 1) {
    int x, y; fastin(x); fastin(y); 
    --x; --y;
    graph[x].emplace_back(y);
    graph[y].emplace_back(x);
  }
  ans = k;
  dfs(0, -1);

  fastout(ans);

  return 0;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const unsigned int M = 1000000007;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    char a,b;
    while(cin>>a>>b){
        if(a==b)cout<<"H"<<endl;
        else cout<<"D"<<endl;
    }
}


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

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<bool> skipRow(n, true), skipColumn(m, true);
    vector<string> vs(n);
    for(int i = 0; i < n; i++){
        cin >> vs[i];
        for(int j = 0; j < m; j++){
            if(vs[i][j] == '#'){
                skipRow[i] = skipColumn[j] = false;
            }
        }
    }
    for(int i = 0; i < n; i++){
        if(skipRow[i]) continue;
        for(int j = 0; j < m; j++){
            if(skipColumn[j]) continue;
            cout << vs[i][j];
        }
        cout << "\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 6010;
int n;char s[N];

bool kind[N];
string f[N];
int cnt,pos[N];
int bel[N];

int main()
{
	cin >> n;
	scanf("%s",s);
	for(int _s=0,i=0;i<2*n;i++){
		_s+=(s[i]=='b')?1:-1;
		if(!_s){
			pos[++cnt]=i;
			kind[cnt] = s[i]=='a'?0:1;
		}
	}
	pos[0]=-1;
	bool v=1;
	for(int i=cnt;i;i--){
		if(!kind[i]){
			v=0;
			int s1=0,s2=0;
			for(int j=pos[i-1]+1;j<=pos[i];j++){
				if(s[j]=='b')bel[j]=++s1;
				else bel[j]=++s2;
			}
			f[i]=f[i+1];
			for(int j=1;j<=s1;j++){
				string c;
				for(int k=pos[i-1]+1;k<=pos[i];k++){
					if(bel[k]>=j)c+=s[k];
				}
				f[i]=max(f[i], c+f[i+1]);
			}
		}
		else if(v){
			int s1=0,s2=0;
			for(int j=pos[i-1]+1;j<=pos[i];j++){
				if(s[j]=='a')bel[j]=++s1;else bel[j]=++s2;
			}
			int r = pos[i-1]+1;
			for(;;){
				while(r<=pos[i]&&s[r]=='b')++r;
				if(r>pos[i])break;
				f[i]+="ab";
				int t=bel[r];
				r++;
				while(bel[r]!=t)r++;
				r++;
			}
			f[i]+=f[i+1];
		}else f[i]=f[i+1];
	}
	cout << f[1] << endl;
	return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

int main() {
input:
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }

    set<ll> m;
    rep(i, n) { m.insert(a[i]); }

    ll size = m.size();

    if (n == size) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

calculate:
    return 0;
}



Measured memory_bytes: 11136
import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

minA = A[0]
Query = []
for _ in range(m):
    b,c = map(int,input().split())
    if c > minA:
        Query.append([b,c])
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
index = 0
for b,c in Query:
    if index >= n:
        break
    #print("----")
    cnt = 0
    Flag = True
    while Flag:
        #print(A,b,c,index)
        if A[index] < c:
            A[index] = c
            cnt += 1
            index += 1
            if (cnt >= b) or (index >= n):
                Flag = False
        else:
            Flag = False
    '''
    #A.sort()
    if A[0] >= c:
        break
    else:
        index = min(bisect.bisect_left(A,c),b)
        if index > len(A):
            ans += c * len(A)
            break
        else:
            ans += c * index
            A = A[index:]
    print(A)
    '''
print(sum(A))

Measured memory_bytes: 36576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

ull top(ull val) { return 1llu << (63llu - __builtin_clzll(val)); }

void binary_basis_insert(vector<ull>& w, ull a) {
	for (auto v : w) if (top(v) & a) a ^= v;
	if (!a) return;
	ull t = top(a);
	for (auto& v : w) if (t & v) v ^= a;
	w.push_back(a);
}

vector<ull> binary_basis(vector<ull>& w) {
	vector<ull> res;
	for (auto v : w) binary_basis_insert(res, v);
	return res;
}

int main()
{
	int N;
	cin >> N;
	vector<ull> A(N);
	ull X = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		X ^= A[i];
	}
	for (ull b = 0; b < 60; b++) if (X & (1LL << b)) {
		for (int i = 0; i < N; i++) if (A[i] & (1LL << b)) {
			A[i] -= 1LL << b;
		}
	}
	auto v = binary_basis(A);
	ull a = 0;
	for (auto val : v) {
		if ((a ^ val) > a) a ^= val;
	}
	cout << X + (a * 2) << endl;
	return 0;
}


Measured memory_bytes: 1152
from heapq import heapify, heappop, heappush

nm = list(map(int, input().split()))
n, m = nm[0], nm[1]
d = {}
ab_list = list()
for i in range(n):
    ab = list(map(int, input().split()))
    rem_day, reward = ab[0], ab[1]
    if rem_day in d:
        d[rem_day].append(-reward)
    else:
        d[rem_day] = [-reward]


result = 0

candidates = list()

for rem in range(1, m + 1):
    added_candidates = d.get(rem)
    if added_candidates is not None:
        for ac in added_candidates:
            heappush(candidates, ac)

    if len(candidates) > 0:
        top = heappop(candidates)
        result += -top

print(result)


Measured memory_bytes: 26532
while 1:
    n=int(input())
    if n==0: break
    a=b=0
    while n:
        c,d=map(int,input().split())
        if c<d:b+=c+d
        elif c>d:a+=c+d
        else:
             a+=c
             b+=c
        n-=1
    print(a,b)

Measured memory_bytes: 7596
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))
    b =list(map(int, input().split()))
    c = list(map(int, input().split()))

    ans = b[a[0]-1]
    pre = a[0] - 1
    for i in range(1, N):
        ans += b[a[i] - 1]
        if pre + 1 == a[i] - 1:
            ans += c[pre]
        pre = a[i] - 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064