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

using namespace std;

#define endl '\n'

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

const int N = 1e6;

int n;
char s[N];

pii t[N];

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

	cin >> s;
	int sz = strlen(s);
	vector<pii> pairs;

	for( int i = 0; s[i]; i++){
		if(s[i] != 'x'){
			t[n++] = {s[i], i};
		}
	}

	if(n == 0){
		cout << "0" << endl;
		exit(0);
	}

	int lo = 0, hi = n - 1;
	while(lo < hi){
		if(t[lo].first != t[hi].first){
			cout << "-1" << endl;
			exit(0);
		}
		lo++, hi--;
	}

	lo = 0, hi = n - 1;

//	cerr << sz << endl;
//	cerr <<  t[n-1].second << endl;
	int beg = t[0].second;
	int en = sz - t[n-1].second - 1;

	ll ans = abs(en-beg);
//	cerr << beg << " " << en << endl;
	while(lo < hi){
		int cnt = hi - lo - 1;
		ll a = t[lo + 1].second - t[lo].second - 1;
		ll b = t[hi].second - t[hi - 1].second - 1;
		ans += abs(a - b);
		lo++, hi--;
	}
	cout << ans << endl;





	return 0;
}



Measured memory_bytes: 3072
#include <stdio.h>
#include <iostream>
 
using namespace std;
 
int main() {
 
    int a,b,c;
    int counter1 = 0;
    int counter2 = 0;
    char d;
    while (cin >> a >> d >> b >> d >> c) {
        if (c * c == a * a + b * b) {
            counter1++;
        } else if (c < a + b && a == b){
            counter2++;
        }
    }
 
    cout << counter1 << endl << counter2 << endl;
 
    return 0;
}


Measured memory_bytes: 1160
N = int(input())
prime = [2]
for i in range(3, 100):
    flag = 0
    for j in prime:
        if i % j == 0:
            flag = 1
    if flag == 0:
        prime.append(i)

factorization = [0 for i in range(101)]

for i in range(1, N+1):
    for j in prime:
        while i % j == 0:
            i = i // j
            factorization[j] += 1

ans = 0
factorization.sort(reverse = True)
for i in range(N):
    if factorization[i] >= 74:
        ans += 1
    else:
        break
for i in range(N):
    if factorization[i] >= 24:
        for j in range(N):
            if i != j:
                if factorization[j] >= 2:
                    ans += 1
                else:
                    break
    else:
        break

for i in range(N):
    if factorization[i] >= 14:
        for j in range(N):
            if j != i:
                if factorization[j] >= 4:
                    ans += 1
                else:
                    break
    else:
        break

for i in range(N):
    if factorization[i] >= 4:
        for j in range(i+1, N):
            if factorization[j] >= 4:
                for k in range(N):
                    if k != i and k != j:
                        if factorization[k] >= 2:
                            ans += 1
                        else:
                            break
            else:
                break
    else:
        break
print(ans)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int d;
	float a, b, c, e;
	cin>>a;
	cin>>b;
	c=(a+b)/2;
	d= c;
	e= d-c;
	if(c>d){
		if(e >= -0.5 && e < 1){
			cout<<d+1<<endl;
		}
	}
	else{
		cout<<c<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define maxn 4097152
using namespace std;
int N,k;
int ha[maxn][21],res[maxn][21],dc[maxn];
int Gstat(int s1,int s2,int l1,int l2)
{
	assert((((1<<l1)+s1)<<l2)+s2<maxn);
	return (((1<<l1)+s1)<<l2)+s2;
}
char buf[21][maxn];
int ans,alen;
void Pre()
{
	int inv,tinv,ginv;
	for(int i=0;i<=N;i++) scanf("%s",buf[i]);
	alen=1e9;
	for(int i=N;i>=0;i--)
	{
		//printf("%d\n",i);
		for(int j=0;j<=i;j++)
		{
			for(int fr=0;fr<(1<<j);fr++)
			{
				for(int tl=0;tl<(1<<(i-j));tl++)
				{
					//assert(inc<maxn*60);
					int stat=Gstat(fr,tl,j,i-j);
					if(j==0) ha[stat][j]=(buf[i][tl]=='1');
					
					if(tl!=0) ha[Gstat(fr<<1|1,tl^(1<<dc[tl]-1),j+1,dc[tl]-1)][j+1]+=ha[stat][j];
					
					if(tl!=(1<<(i-j))-1)
					{
						inv=(tl^((1<<(i-j))-1));
						tinv=(inv^(1<<dc[inv]-1));
						ginv=(tinv^((1<<(dc[inv]-1))-1));
						ha[Gstat(fr<<1,ginv,j+1,dc[inv]-1)][j+1]+=ha[stat][j];
					}
					res[fr][j]+=ha[stat][j];
				}
			}
		}
	}
	for(int i=N;i>=0;i--)
		for(int j=0;j<(1<<i);j++)
			if(res[j][i]>=k)
			{
				for(int t=i-1;t>=0;t--) printf("%d",j>>t&1);
				return;
			}
}
int main()
{
	scanf("%d%d",&N,&k);
	for(int i=1;i<maxn;i++) dc[i]=dc[i>>1]+1;
	dc[0]=1;
	Pre();
	return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c, x;
  while (cin >> a >> b >> c >> x) {
    int cnt = 0;
    for (int i = 0; i <= a; ++i) {
      for (int j = 0; j <= b; ++j) {
        for (int k = 0; k <= c; ++k) {
          cnt += (x == (500 * i + 100 * j + 50 * k));
        }
      }
    }
    cout << cnt << endl;
  }
  
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

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

    while (1) {
        s.pop_back();
        s.pop_back();

        bool even = true;

        rep(i, s.length() / 2 - 1) {
            if (s[i] != s[i + s.length() / 2]) {
                even = false;
                break;
            }
        }
        if (even) {
            cout << s.length() << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k;
long long cnt=1;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		if(i==1){
			cnt*=k;
		}else{
			cnt*=k-1;
		}
	}
	cout << cnt;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int m = 0, f = 0, r = 0;
	while(1){
		scanf("%d %d %d", &m, &f, &r);
		if(m == -1 && f == -1 && r == -1){
			break;
		}
		if(m == -1 || f == -1){
			printf("F\n");
		}else if(m+f >= 80){
			printf("A\n");
		}else if(m+f >= 65){
			printf("B\n");
		}else if(m+f >= 50){
			printf("C\n");
		}else if(m+f >= 30){
			if(r >= 50){
				printf("C\n");
			}else{
				printf("D\n");
			}
		}else{
			printf("F\n");
		}
	}
}
		


Measured memory_bytes: 2064
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  ll now=1;
  rep(i,0,n){
    if(a[i]==0){
      cout<<0<<endl;
      return 0;
    }
  }
  rep(i,0,n){
    if(LLONG_MAX/a[i]<=now)judge=false;
    else now*=a[i];
  }
  if(judge&&now<=INF)cout<<now<<endl;
  else cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 3972
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod
  
X, Y = map(int,input().split())

mm = (2*Y - X) / 3
nn = (2*X - Y) / 3

ans = 0

if mm.is_integer() and nn.is_integer():
    mm = int(mm)
    nn = int(nn)
    if mm >=0 and nn>=0:
        ans =comb(mm+nn, nn, 10**9+7)
      
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
  int r, D, x2k;
  scanf("%d %d %d", &r, &D, &x2k);

  for(int i = 1; i <= 10; i++) {
    x2k = (r * x2k - D);
    printf("%d\n", x2k);
  }
  return 0;
}


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

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  for (int i = 0; i < n; i++)
  {
    cin >> s[i] >> t[i];
  }
  string x;
  cin >> x;
  bool ok = false;
  int rez = 0;
  for (int i = 0; i < n; i++)
  {
    if (ok)
    {
      rez += t[i];
    }
    if (s[i] == x)
    {
      ok = true;
    }
  }
  cout << rez << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, m;

P a[N];

int32_t main(){_

   cin>>n>>m;

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

   sort(a, a+n);

   int ans = 0, rem = m;

   for (int i = 0; i < n; ++i)
   {
      ans += min(rem, a[i].S) * a[i].F;
      rem -= min(rem, a[i].S);
   }

   cout<<ans;
   #warning make sure N size is correct!
   return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    int N, M;
    cin >> N >> M;
    vi H(N);
    for (int i = 0; i < N; i++)
        cin >> H[i];

    vector<bool> good(N, true);
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        --a; --b;
        if (H[a] >= H[b]) good[b] = false;
        if (H[a] <= H[b]) good[a] = false;
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (good[i]) ++ans;
    }
    
    cout << ans << endl;
}

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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;


int get(vector<pair<int, int> >  &vec, pii &p)
{
	int res = 0;
	for (auto &i : vec)
	{
		res = max(res, abs(p.ff - i.ff) + abs(p.ss - i.ss));
	}
	return res;
}
void solve()
{
	int n;
	cin >> n;
	vector<pii> vec(n);
	int minx = inf, miny = inf;
	vector<int> x(n), y(n);
	map<int, int> mp1, mp2;
	lop(i, 0, n) cin >> x[i] >> y[i], mp1[ x[i] + y[i] ]++, mp2[ x[i] -  y[i] ]++;
	int ans = 0;

	lop(i, 0, n)
	{
		int sum = x[i] + y[i], dif = x[i] - y[i];
		mp1[sum]--;
		if ( mp1[sum] == 0 ) mp1.erase(sum);
		int mnsum = mp1.begin()->ff;
		mp1[sum]++;

		mp2[dif]--;
		if ( mp2[dif] == 0 ) mp2.erase(dif);
		int mndifs = mp2.begin()->ff;
		mp2[dif]++;


		ans = max({ans, sum - mnsum, dif - mndifs});


	}
	cout << ans << endl;



}

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

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





















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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int A, B, C; cin >> A >> B >> C;
	int M = max({A, B, C});
	
	if((3*M)%2 ==  (A+B+C)%2){
		cout << (3*M - (A+B+C))/2 << endl;
	}else{
		cout << (3*(M+1) - (A+B+C))/2 << endl;
	}



	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
#define ll long long
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << a * b << ' ' << 2 * (a + b) << endl;
	return 0;
}


Measured memory_bytes: 3136
import java.util.*;
class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			Node[] node = new Node[n];
			for(int i = 0; i < n; i++) {
				node[i] = new Node(i);
			}
			Edge[] edge = new Edge[n-1];
			int[][] time = new int[n][n];
			for(int i = 0; i < n; i++) {
				Arrays.fill(time[i], 2 << 27);
			}
			
			
			
			for(int i = 0; i < n-1; i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				int t = sc.nextInt();
				
				time[a-1][b-1] = t;
				time[b-1][a-1] = t;
				edge[i] = new Edge(a,b,t);
				node[a-1].edge.add(t);
				node[b-1].edge.add(t);		
				node[a-1].x++;
				node[b-1].x++;
			}
			
			int sum = 0;
			int max = 0;
			
			for(int i = 0; i < n; i++) {
				time[i][i] = 0;
			}
			
			boolean[] isp = new boolean[n];
			for(int k = 0; k < n; k++) {
				for(int i = 0; i < n; i++) {
					for(int j = 0; j < n; j++) {
						time[i][j] = Math.min(time[i][j], time[i][k] + time[k][j]);
					}
				}
			}
			

			for(int i = 0; i < n-1; i++) {
				if(node[edge[i].f-1].x >= 2 && node[edge[i].t-1].x >= 2) {
					sum += edge[i].c;
				}
				if(node[edge[i].f-1].x >= 2 && node[edge[i].t-1].x == 1) {
					isp[edge[i].f-1] = true;
				}
				if(node[edge[i].t-1].x >= 2 && node[edge[i].f-1].x == 1) {
					isp[edge[i].t-1] = true;
				}
			}
			
			sum *= 2;
			
			for(int i = 0; i < n; i++) {
				if(isp[i]) {
					max = Math.max(time[0][i], max);
				}
			}
			
			if(node[0].x == 1) {
				sum += node[0].edge.get(0)*2;
			}
			//System.out.println(sum);
			
			sum -= max;
			
			System.out.println(sum);
		
		}
	}
	
	static class Node {
		int id;
		int x;
		ArrayList<Integer> edge = new ArrayList<Integer>();
		Node(int id) {
			this.id = id;
		}
	}
	
	static class Edge {
		int f;
		int t;
		int c;
		Edge(int f, int t, int c) {
			this.f = f;
			this.t = t;
			this.c = c;
		}
	}
	
	
}

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

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


double d2(vector<double> &a, vector<double> &b) {
  return (a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]);
}

int main() {
  int N;
  cin >> N;
  double x,y,ep=0.000001,ok=2000,ng=0,now=1000;
  vector<vector<double>> c(N);
  rep(i,N) {
    cin >> x >> y;
    c[i] = {x,y};
  }

  

  bool flag;
  while (ok-ng>ep) {
    flag = false;
    rep(i,N-1)rep2(j,i+1,N) {
      vector<vector<double>> tmp;
      if (d2(c[i],c[j]) >4*now*now) continue;
      else if (d2(c[i],c[j]) == 4*now*now) tmp.push_back({(c[i][0]+c[j][0])/2, (c[i][1]+c[j][1])/2});
      else {
        vector<double> H,p1,p2, p = {c[j][0]-c[i][0], c[j][1]-c[i][1]};
        
        long double td = p[0]*p[0]+p[1]*p[1];
        rep(div,2) p[div] *= sqrt(((4*now*now - (td))/ (td)))/2;
        p1 = {-p[1], p[0]};p2 = {p[1], -p[0]};
        H = {(c[i][0]+c[j][0])/2, (c[i][1]+c[j][1])/2};
        tmp.push_back({H[0]+p1[0], H[1]+p1[1]});
        tmp.push_back({H[0]+p2[0], H[1]+p2[1]});
        // cout << H[0]+p1[0] << ' ' << H[1]+p1[1] << endl;
      }
      // cout << tmp.size() << endl;

      for (auto t:tmp) {
        // printf("%.8lf %.8lf\n",t[0],t[1]);
        bool out = false;
        rep(al,N) {
          if (i==al || j==al) continue;
          if (d2(t,c[al]) > now*now) {
            // printf("{%.3lf,%.3lf} {%.3lf,%.3lf}  ",t[0],t[1],c[al][0],c[al][1]);
            // printf("%.3lf %.3lf\n",d2(t,c[al]),now*now);
            
            out=true;
            break;
          }
        }
        if (out) continue;
        flag = true;
        break;
      }
    }
    // return 0;
    // rep(i,N) {//円の中心
    //   bool out = false;
    //   rep(j,N) {
    //     if ( d2(c[i],c[j]) > now*now) {
    //       out = true;
    //       break;
    //     }
    //   }
    //   if (out) continue;
    //   flag = true;
    //   break;
    // }

    if (flag) ok = now;
    else ng = now;
    now = (ok+ng)/2;
  }
  printf("%.8lf\n", now);
} 


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    for(int i = 1; i < n + 1; i++){
        if(i % 3 == 0){
            cout << " " << i;
        }
        else if(i % 10 == 3){
            cout << " " << i;
        }
        else{
            int x = i;
            while(x != 0){
                x /= 10;
                if(x % 10 == 3){
                    cout << " " << i;
                    break;
                }
            }
        }
    }
    cout << "" << endl;
}


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

int getMaxCmb(int a, int b) {
    int m = std::max(a + b, a - b);
    int n = a * b;
    return std::max(m, n);
}

int main() {
    int a, b;
    std::cin >> a >> b;
    std::cout << getMaxCmb(a, b) << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long l,r,i,val,j;
    cin>>l>>r;
//     long long minn=(l*r);
//     for(i=l;i<r;i++){
//         for(j=l+1;j<=r;j++){
//             val=(i*j)%2019;
//             if(val<minn){
//                 minn=val;
//             }
            
//         }
//     }
//     cout<<minn;
//     return 0;
// }

 long long result = ((l%2019)*((l+1)%2019))%2019;

for(i=l;i<=r-1;i++){
  if(result == 0){
    break;
  }
  for(j=i+1;j<=r;j++){
    if(result == 0){
      break;
    }
    if(result > ((i%2019)*(j%2019))%2019){
      result = ((i%2019)*(j%2019))%2019;
    }
  }
}
cout<<result;
return 0;
}
 

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

int main(){
  int N;
  cin >>N;
  
  int a, b, c, d;
  a = N/1000;
  b = N/100 - 10*a;
  c = N/10 -10*b - 100*a ;
  d = N%10;
  
  if (a==b && b==c){
    cout << "Yes" << endl;
  } 
  else if (b==c && c==d){
    cout << "Yes"<< endl;
  }
  else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    int data[100001]={};
    int n,a;
    long answer=0;
    long temp;
    scanf("%d",&n);
    for(int loop=0;loop<n;loop++){
        scanf("%d",&a);
        if(a<=100000){
            data[a]++;
        }else{
            answer++;
        }
    }
    for(long loop=1;loop<=100000;loop++){
        temp=data[loop]-loop;
        if(temp>0){
            answer+=temp;
        }else if(temp<0){
            answer+=data[loop];
        }
    }
    printf("%ld\n",answer);
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

#include <ctype.h>

int main(void) {
	char c;
	
	do {
		scanf("%c", &c);
		if (isupper(c)) {
			c = c - 'A' + 'a';
		} else if (islower(c)) {
			c = c - 'a' + 'A';
		}
		printf("%c", c);
	} while (c != '\n');
	
	return 0;
}

Measured memory_bytes: 2548
n=int(input())
xy=[list(map(int,input().split())) for _ in [0]*n]
dist=0
for i in range(n):
    for j in range(i+1,n):
        dist+=((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5
print(dist/(((n*(n-1))//2))*(n-1))

Measured memory_bytes: 3188
// 9/19 リアルタイム参加
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
    ll N, X, M;
    cin >> N >> X >> M;

    vector<ll> ans;
    ans.push_back(0);

    ll final_ans = 0;
    bool has_cycle = false;

    map<ll, ll> mp;  // firstの値のあまりがsecond回目に登場。

    ll now = X;
    ans.push_back(now % M);
    mp[now % M] = 1;

    for (ll index = 2; index <= N; index++) {
        now = (now * now) % M;
        if (mp[now] != 0) {
            ll prev = mp[now];
            ll cycle_sum = ans[index - 1] - ans[prev - 1];  // 1サイクルの和
            // ll cycle_num = now - prev;
            ll cycle_num = index - prev;

            // printf("prev, cycle_sum, cycle_num = %d, %d, %d\n", prev, cycle_sum, cycle_num);

            ll rest_num = N - index + 1;  // index自身も含む。
            // cout << "here?2" << endl;
            ll rest_sum = (rest_num / cycle_num) * cycle_sum;
            // cout << "here?3" << endl;
            ll rest_of_rest = rest_num % cycle_num;
            // cout << rest_of_rest << endl;
            for (ll i = 0; i < rest_of_rest; i++) {
                rest_sum += now;
                now = (now * now) % M;
            }

            // cout << "here?" << endl;

            final_ans = ans[index - 1] + rest_sum;
            has_cycle = true;
            break;
        } else {
            mp[now] = index;
            ans.push_back(ans.back() + now);
            // printf("now, index, ans = %d, %d, %d\n", now, index, ans.back());
        }
    }

    if (has_cycle) {
        cout << final_ans << endl;
    } else {
        cout << ans[N] << endl;
    }
}


Measured memory_bytes: 6764
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str;

int main(void){
	cin >> str;
	int res=0;
	int now=0;
	for(int i=0;i<str.size();i++){
		int mok=str[i]-'A';
		if(now==mok)res++;
		else{
			while(mok!=now){
				now=(now+1)%26;
				if(now==0)res++;
			}
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 3280
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< int > A(N), B(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	vector< vector< int > > dp(1 << N, vector< int >(51, LINF));
	dp[0][0] = 0;
	rep(b, 1 << N) {
		bitset< 20 > bit(b);
		vector< int > C;
		int p = 0;
		rep(i, N) if (!bit[i]) {
			C.push_back(i);
		}
		else ++p;
		rep(j, 51) {
			if (dp[b][j] == LINF)
				continue;
			rep(k, C.size()) {
				int now = p + k;
				int l;
				if ((C[k] - p) % 2 == 0) {
					l = A[C[k]];
				} else {
					l = B[C[k]];
				}
				int next = b | (1 << C[k]);
				if (l >= j)
					chmin(dp[next][l], dp[b][j] + k);
			}
		}
	}
	int ans = LINF;
	rep(j, 51) chmin(ans, dp[(1 << N) - 1][j]);
	if (ans == LINF)
		ans = -1;
	cout << ans << endl;
	return 0;
}

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

int main() {
int n,a[100000],c=0;
unordered_map<int,int> b{};
cin>>n;
for(int i=0;i<n;i++){
    cin>>a[i];
    b[a[i]]=i%2;
}
sort(a,a+n);
for(int i=0;i<n;i++){
    if(b[a[i]]!=i%2)c++;
}
cout<<c/2<<endl;
	return 0;
}

Measured memory_bytes: 4900
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
#define mk make_pair
using namespace std; const int N=400010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,m;
int f[N],tot;
inline int Find(int x) { return f[x]^x?f[x]=Find(f[x]):x; }
signed main()
{
	n=read(), m=read();
	for(ri int i=1;i<=n;i++) f[i]=i;
	for(ri int i=1;i<=m;i++)
	{
		int u,v;
		u=read(), v=read();
		int x=Find(u), y=Find(v);
		if(x==y) continue;
		f[x]=y, tot++;
	}

	printf("%lld\n",n-tot-1);
    return 0;
}

Measured memory_bytes: 4476
require 'pp'

n = gets.to_i
a_n = gets.split.map(&:to_i)
memo = {}
a_n.each do |a|
    memo[a] ||= 0
    memo[a] += 1
end

memo2 = {}
sum = 0
memo.each do |k, v|
    memo2[k] ||= []
    memo2[k][0] = (v * (v-1) / 2)
    memo2[k][1] = (v-1) * (v-2) / 2
    sum += memo2[k][0]
end

a_n.each do |a|
    puts sum - memo2[a][0] + memo2[a][1]
end


Measured memory_bytes: 47112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    ll n; cin>>n;
    vector<ll> t(n);
    rep(i,n) cin>>t[i];
    ll res=0;
    rep(i,n) res+=t[i];
    ll m; cin>>m;
    rep(i,m){
        ll p,x; cin>>p>>x;
        cout<<res-t[p-1]+x<<endl;
    }
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std ; 
#define ll long long
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
#define MOD 1000000007
#define test int tcase ; cin>>tcase ; while(tcase--)
int main(){
    int n ; 
    cin>>n ; 
    map<string,int> a ; 
    for(int i = 0 ; i<n ; i++){
        string s ; 
        cin>>s ; 
        a[s]++ ; 
    }
    int count = 0;
    for(auto it = a.begin() ; it!=a.end(); it++){
        count++ ; 
    }
    cout<<count ; 
}

Measured memory_bytes: 19260
def examA():
    N, A, B = LI()
    ans = min(A*N,B)
    print(ans)
    return

def examB():
    N, D = LI()
    X = [LI() for _ in range(N)]
    ans = 0
    for i,j in itertools.combinations(X,2):
        cur = 0
        for k in range(D):
            cur += (i[k]-j[k])**2
        cur **=0.5
        if cur==int(cur):
            ans +=1
    print(ans)
    return

def examC():
    L, R = LI()
    cur = []; ans = 10**9
    for i in range(L,min(2019+L,R)+1):
        if i%2019==0:
            ans = 0
            break
        else:
            cur.append(i%2019)
    if ans==0:
        print(ans)
        return
    N = len(cur)
    for i,j in itertools.combinations(cur,2):
        ans = min(ans,(i*j)%2019)
    print(ans)
    return

def examD():
    N = I()
    A = LI()
    dis = [0]*N
    for i in range(N):
        cur = A[i-N+1]-A[i-N]
        dis[i] = cur*2
#    print(dis)
    ans = [0]*N
    for i in range(2,2*N,2):
        ans[i-N] = ans[i-N-2] + dis[i-N-2]
#    print(ans)
    ad = (sum(A) - sum(ans))//N
    for i in range(N):
        ans[i] += ad
    print(" ".join(map(str,ans)))
    return

def bfs(n,e,fordfs,K):
    #点の数、スタートの点、有向グラフ
    W = K
    que = deque()
    que.append(e)
    len = [10**9]*n
    len[e] = 0
    while que:
        now = que.popleft()
        nowlen = len[now]
        cur = K-min(2,nowlen+1)
        for ne in fordfs[now]:
            if len[ne] == 10**9:
                W *=cur; W %=mod
                cur -=1
                len[ne] = nowlen+1
                que.append(ne)
    return W
def examE():
    N, K = LI()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        a,b = LI()
        V[a-1].append(b-1)
        V[b-1].append(a-1)
    ans = bfs(N,0,V,K)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examE()


Measured memory_bytes: 61744
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
constexpr long MOD = 1e9 + 7;
using namespace std;
using VI = vector<int>;

int main() {
    int x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    
    double a = hypot(x1 - x2, y1 - y2);
    double b = hypot(x2 - x3, y2 - y3);
    double c = hypot(x3 - x1, y3 - y1);
    
    double A = acos((b * b + c * c - a * a) / 2 / b / c);
    double B = acos((c * c + a * a - b * b) / 2 / c / a);
    double C = acos((a * a + b * b - c * c) / 2 / a / b);
    
    assert(0 < A < acos(-1) && 0 < B < acos(-1) && 0 < C < acos(-1));
    double tA = 1 / tan(A / 2);
    double tB = 1 / tan(B / 2);
    double tC = 1 / tan(C / 2);
    
    double ans = 0;
    ans = max(ans, a / (tB + tC + 2));
    ans = max(ans, b / (tC + tA + 2));
    ans = max(ans, c / (tA + tB + 2));
    printf("%.10f\n", ans);
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>

#include <queue>
#include <cstdio>

#include <list>

#define PI (3.14159265358979323846)
#define INF (1e+9)
#define DIV_NUM (1000000007)

using namespace std;


bool seen[501][501];

int N,K;
char field[501][501];
int  dist[501][501];

typedef pair<int, int> P;
queue<P> que;


//typedef vector<vector<int>> v;
vector<double> A;
vector<double> A2;


int main(){
  
  
    // input data
 
    cin >> K >> N;

    int ai = 0;
    int tmp = 1;
    int c01 = 0;
    int c02 = 0;
    int c03 = 0;

    for (int i = 0; i < N; i++) {
        cin >> ai;
        A.push_back(ai);
        
//        std::cout << A.front() << "  " << A.back() << "  " << ai[i] << "\n";

    }
       
       
    std::sort(A.begin(), A.end());//昇順ソート

    for (int i = 0; i < (N-1); i++) {
        c01 = A[i+1]-A[i];
        A2.push_back(c01);
    }
        c01 = K - A.back();
        c02 = A.front() - 0;
        c03 = c01 + c02;

        A2.push_back(c03);


    std::sort(A2.begin(), A2.end(), std::greater<int>());//降順ソート


    int G=0;

    for (int i = 0; i <(A2.size()-1) ; i++) {
        G = G + A2[i+1];
    }


    
    std::cout << G ;

        return 0;

}


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

using namespace std;

int main(){
	long long a,b,c;
	
	cin>>a>>b>>c;
	
	if(a>=b && b>=c) cout<<c<<" "<<b<<" "<<a<<endl;
		else if(a>=c && c>=b) cout<<b<<" "<<c<<" "<<a<<endl;
			else if(b>=a && a>=c) cout<<c<<" "<<a<<" "<<b<<endl;
			  else if(b>=c && c>=a) cout<<a<<" "<<c<<" "<<b<<endl;
			    else if(c>=a && a>=b) cout<<b<<" "<<a<<" "<<c<<endl;
			      else cout<<a<<" "<<b<<" "<<c<<endl;
			      
	return 0;
}


Measured memory_bytes: 3088
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 1E+05;

int N;

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

    cin >> N;

    int odd = 0;
    int four = 0;

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a & 1) {
            odd++;
        } else if (a % 4 == 0) {
            four++;
        }
    }

    string ans;
    if (odd + four == N) {
        if (odd <= four + 1) {
            ans = "Yes";
        } else {
            ans = "No";
        }
    } else {
        if (odd <= four) {
            ans = "Yes";
        } else {
            ans = "No";
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3612
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()
}

fn solve(n: i32, k: i32) -> i32 {
    if n % k == 0 { 0 } else { 1 }
}

fn main() {
    let nk = read_vec::<i32>();

    println!("{}", solve(nk[0], nk[1]));
}


Measured memory_bytes: 4352
#[allow(dead_code)]
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()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();

    let a = read_vec::<u32>();
    let b = read_vec::<u32>();
    let c = read_vec::<u32>();

    let mut ans = 0;
    for i in 0..n {
        let bi = a[i] as usize - 1;
        ans += b[bi];

        if i > 0 && a[i-1] + 1 == a[i] {
            ans += c[bi-1];
        }
    }
    println!("{}", ans);
}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
 int a,b,c;
 cin>>a>>b>>c;
 cout<<(c/a)*b<<endl;
 return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <utility>
using namespace std;

int main() {
	int N;
	cin >> N;
	int s;
	int m=1000;
	int ans=0;
	for(int i=0; i<N; i++){
		cin >> s;
		ans+=s;
		if(s%10 != 0){
			m=min(m,s);
		}
	}
	
	if(ans%10 == 0){
		if(m==1000){cout<<0<<endl;}
		else{
			cout<<ans-m<<endl;
		}
	}else{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int deg[200009]={0};

int main()
{
    long long n,k,i,r,sum,s;
    scanf("%lld%lld",&n,&k);
    for(i=1;i<=n-1;i++){
        long long v1,v2;
        scanf("%lld%lld",&v1,&v2);
        deg[v1]++;
        deg[v2]++;

    }

    sum=k;
    for(s=k-1,i=1;i<=deg[1];i++,s--)
        sum=sum*s%mod;
    for(i=2;i<=n;i++){

        for(int j=1,s=k-2;j<deg[i];j++,s--)
            sum=sum*s%mod;
    }
    if(sum<=0)
        sum=0;
    printf("%lld\n",sum);

    return 0;
}


Measured memory_bytes: 4144
<?php
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

class out {
    public static function println($str = "") {
        echo ($str) . PHP_EOL;
    }
}

$sc = new Scanner();
$n = $sc->nextInt();

$circle = 3;
$circle2 = $n * $n * intval(3);
$res = $circle2/$circle;

out::println($res);
?>

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

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

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

  int max = 1;
  for(int i = 2; i <= X; ++i) {
    int n = i * i;
    while(n <= X) {
      chmax(max, n);
      n *= i;
    }
  }
  cout << max << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    ll n;cin>>n;
    vel A(n);
    rep(i,n){
        cin>>A[i];
    }
    ll ans=0;
    rep(i,n){
        if(i==0){
            continue;
        }else {
            if(A[i-1]>A[i]){
                ans+=A[i-1]-A[i];
                A[i]=A[i-1];
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	ll n,i,j,k;
	cin>>n>>k;
	ll a[n+2],dp[n+2];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(i=2;i<n;i++)
	{
		ll mini=1e18;
		for(j=i-1;j>=max(0ll,i-k);j--)
			mini=min(mini,dp[j]+abs(a[i]-a[j]));
		dp[i]=mini;
	}
	cout<<dp[n-1]<<nl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
signed main()
{
    int n, ans = 0;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i] -= i;
        a[i]--;
    }
    sort(a.begin(), a.end());
    int median = a[(n - 1) / 2];
    for (int i = 0; i < n; i++)
    {
        ans += abs(a[i] - median);
    }
    cout << ans << endl;
    return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
int ans=0;
for(int i=0; i<S.size(); i++){
    if(S.at(i)==T.at(i))continue;
    else{
        ans++;
        break;
}
}
if(ans==1)cout<< NO <<endl;
else cout<< YES <<endl;
}

int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	int a,b,ans=0;
	cin >> a >> b;

	for(int i=0;i<2;i++){
		if(a>=b){
			ans+=a;
			a -= 1;
		}
		else {
			ans+=b;
			b -= 1;
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(ll i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int n;
string m = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int findidx(char c) {
	rep(i, m.size())if(c == m[i]) return i;
}

void solve(void) {
	int k[110];
	string s;
	rep(i, n) cin >> k[i];
	cin >> s;
	string ans;
	rep(i, s.size()) {
		int idx = findidx(s[i]);
		idx = ((idx + 52) - k[i % n]) % 52;
		ans += m[idx];
	}
	cout << ans << endl;
}

int main(void) {
	// cout << m.size() << endl;
	while(1) {
		cin >> n;
		if(n == 0) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 3172
n = int(input())
a = []
ans = []
m = 0
sec = 0
c = 0
for i in range(n):
    num = int(input())
    a.append(num)
    m = max(num, m)

for i in range(n):
    if a[i] < m:
        sec = max(a[i], sec)

c = a.count(m)

if c == 1:
    for i in range(n):
        if a[i]==m:
            ans.append(sec)
        else:
            ans.append(m)
else:
    for i in range(n):
        if a[i]==m:
            if c>0:
                ans.append(m)
                c -= 1
            else:
                ans.append(sec)
        else:
            ans.append(m)

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 14100
#include<iostream>
#include<algorithm>
#define N 1000000
#define M 200

using namespace std;

int dp[M], dp1[N], dp2[N];

void init(){
  dp[0]=0; dp1[0]=0; dp2[0]=0;
  for(int i=1; i<M; ++i) dp[i]=i*(i+1)*(i+2)/6;
  for(int i=1; i<N; ++i){
    dp1[i]=N; dp2[i]=N;
    for(int j=1; j<N; ++j){
      if(i-dp[j] < 0) break;
      dp1[i] = min(dp1[i], dp1[i-dp[j]]+1);
      if(dp[j]%2) dp2[i] = min(dp2[i], dp2[i-dp[j]]+1);
    }
  }
}

int main(){
  init();
  int n;
  while(1){
    cin >> n;
    if(!n) break;
    cout << dp1[n] << " " << dp2[n] << endl;
  }
  return 0;
}

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

int main(){
    long long K,A,B;
    cin >> K >> A >> B;
    
    long long i;
    bool qq=0;
    for(i=K; i<=1000; i=i+K){
        if(A<=i && i <=B){
            qq = 1;
        }
    }
    if(qq){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 3688