akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define INF 2000000000
typedef struct {
  char m;
  int n;
} Card;
int c=0;
Card L[50000],R[50000];
void swap(Card *a,Card *b){
  Card tmp;
  tmp=*a;
  *a=*b;
  *b=tmp;
}
void merge(Card *A,int left,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1].n=INF;
  R[n2].n=INF;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i].n<=R[j].n){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
    c++;
  }
}

void mergeSort(Card *A,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2 ;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
} 


int partition(Card *A,int p,int r){
  int i,j;
  Card x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].n<=x.n){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}

void quicksort(Card *A,int p,int r){
  int q;
  if(p<r){
    q=partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }
}
  
int main(){
  int i,n,flag=0;
  Card A[100000],B[100000];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf(" %c%d",&A[i].m,&A[i].n);
    B[i]=A[i];
  }
  quicksort(A,1,n);
  mergeSort(B,1,n+1);
  for(i=1;i<=n;i++){
    if(A[i].m!=B[i].m) flag=1;
  }
  if(flag==1) printf("Not stable\n");
  else printf("Stable\n");
  for(i=1;i<=n;i++) printf("%c %d\n",A[i].m,A[i].n);
  return 0;
}



Measured memory_bytes: 4080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
inline int Add(int x,int y){
    return (x+=y)>=mod?x-mod:x;
}
inline int Sub(int x,int y){
    return (x-=y)>=0?x:x+mod;
}
inline int Mul(int x,int y){
    return 1ll*x*y%mod;
}
int n,x,y,z;
int dp[1<<16],newdp[1<<16];
bool ok[1<<17];
bool check(int n){
    vector<int> v;
    int c=0;
    while(n){
        c++;
        if(n&1){
            v.push_back(c);
            c=0;
        }
        n>>=1;
    }
    int o=z;
    int sum=0;
    for(int i=0;i<v.size();i++){
        sum+=v[i];
        if(sum==o){
            if(o==z)o+=y;
            else if(o==y+z)o+=x;
            else o=-1;
        }
    }
    if(o==-1)return false;
    return true;
}
int main(){
    scanf("%d%d%d%d",&n,&x,&y,&z);
    int m=x+y+z-1;
    for(int i=0;i<(1<<m+1);i++)ok[i]=check(i);
    //for(int i=0;i<(1<<m);i++)cout<<i<<' '<<ok[i]<<endl;
    dp[0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<(1<<m);j++)newdp[j]=0;
        for(int j=0;j<(1<<m);j++){
            if(dp[j]==0)continue;
            for(int k=1;k<=10;k++){
                int x=(j<<k|(1<<(k-1)))%(1<<m+1);
                if(ok[x]){
                    x=x%(1<<m);
                    newdp[x]=Add(newdp[x],dp[j]);
                }
            }
        }
        for(int j=0;j<(1<<m);j++)dp[j]=newdp[j];
    }
    int ans=1;
    for(int i=1;i<=n;i++)ans=Mul(ans,10);
    for(int i=0;i<(1<<m);i++)ans=Sub(ans,dp[i]);
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 896
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
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 chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int P;
int cnt[10000];
char S[200000];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	char c;
	int N = 0;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';
	while ((c = getchar_unlocked()) >= '0') P = P * 10 + c - '0';
	if (P == 2) {
		ll kotae = 0;
		rep(i, N) {
			if ((getchar_unlocked() - '0') % 2 == 0) kotae += i + 1;
		}
		printf("%lld", kotae);
		return 0;
	}
	if (P == 5) {
		ll kotae = 0;
		rep(i, N) {
			if ((getchar_unlocked() - '0') % 5 == 0) kotae += i + 1;
		}
		printf("%lld", kotae);
		return 0;
	}

	cnt[0] = 1;
	ll kotae = 0;
	const int p = P;
	int ima = 1;
	int mae = 0;
	fread(S, 1, N, stdin);
	char *s = S + N;

	int shou = N / 5;
	int amari = N % 5;
	rep(i, shou) {
		int a = ((*--s - '0') * ima + mae) % p;
		kotae += cnt[a]++;
		mae = a;
		ima *= 10;
		a = ((*--s - '0') * ima + mae) % p;
		kotae += cnt[a]++;
		mae = a;
		ima *= 10;
		a = ((*--s - '0') * ima + mae) % p;
		kotae += cnt[a]++;
		mae = a;
		ima *= 10;
		a = ((*--s - '0') * ima + mae) % p;
		kotae += cnt[a]++;
		mae = a;
		ima *= 10;
		a = ((*--s - '0') * ima + mae) % p;
		kotae += cnt[a]++;
		mae = a;
		ima = ima * 10 % p;
	}
	rep(i, amari) {
		int a = ((*--s - '0') * ima + mae) % p;
		kotae += cnt[a]++;
		mae = a;
		ima *= 10;
	}

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 384
import sys

input = sys.stdin.buffer.readline
n = int(input())
ans = [0] * (n + 1)


def calc(a, b, c):
    return a * a + b * b + c * c + a * b + b * c + c * a


for i in range(1, int(n ** (1 / 2)) + 2):
    for j in range(i, int(n ** (1 / 2)) + 2):
        for k in range(j, int(n ** (1 / 2)) + 2):
            # print(i, j, k)
            temp = calc(i, j, k)
            if temp == 10:
                print(i, j, k)
            if temp > n:
                continue
            if i == j and j == k:
                ans[temp] += 1
            elif i == j:
                ans[temp] += 3
            elif j == k:
                ans[temp] += 3
            elif k == i:
                ans[temp] += 3
            else:
                ans[temp] += 6

print(*ans[1:], sep="\n")



Measured memory_bytes: 74616
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647

bool check(string x) {
  bool ret = true;
  int n = x.size();
  int d = n / 2;
  rep(i,d) {
    if(x[i] == x[n-i-1]) continue;
    else ret = false;
  }
  return ret;
}

int main() {
  kyun;
  string s;
  cin >> s;
  int size = s.size();
  string a = s.substr(0,size/2);
  string b = s.substr((size+1)/2,size/2);
  string ans = "Yes";
  if(check(s) == false) ans = "No";
  if(check(a) == false) ans = "No";
  if(check(b) == false) ans = "No";
  cout << ans;
  hinata;
}


Measured memory_bytes: 256
N=int(input())
H=list(map(int,input().split()))
lst=[]
cnt=0
for i in range(1,N):
    if H[i-1]>=H[i]:
        cnt+=1
        lst.append(cnt)
    else:
        cnt=0
if lst==[]:
    print(0)
else:
    print(max(lst))

Measured memory_bytes: 14224
#include<iostream>
#include<cassert>
#include<vector>
#include<cmath>
#include<cstdio>
#include<algorithm>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)

using namespace std;

struct P
{
  int to,cost;
  P(int to=inf,int cost=inf):to(to),cost(cost){}
};

//
template<typename T>
bool visit(const T& G,int v,vector<int>& order,vector<int>& color)
{
  color[v] = 1;
  for(__typeof((G[v]).begin()) e = G[v].begin();e != G[v].end();e++)
    {
      if(color[e->to] == 2)continue;//このvisit以外のvisitで訪れた
      if(color[e->to] == 1)return false;//このvisitで訪れた
      if(!visit(G,e->to,order,color))return false;
    }
  order.push_back(v);
  color[v] = 2;
  return true;
}

template<typename T>
bool topologicalSort(const T& G,vector<int>& order)
{
  int SizeG = G.size();
  vector<int> color(SizeG); 
  for(int u=0;u<SizeG;u++)
    if(!color[u] && !visit(G,u,order,color))
      return false;
  reverse(order.begin(),order.end());
  return true;
}
//

int n,m,a,b;

int main()
{
  cin >> n >> m;
  assert(n >= 2);
  vector<vector<P> > G(n,vector<P>());
  rep(_,m)
    {
      scanf("%d %d",&a,&b);
      a--,b--;
      G[a].push_back(P(b,1));
    }
  vector<int> order;
  topologicalSort(G,order);
  rep(i,order.size())cout << order[i]+1 << endl;
  int color[n],cnt[n];

  rep(i,n)color[i] = 0,cnt[i] = 0;
  rep(i,n)rep(j,G[order[i]].size())
    color[G[order[i]][j].to] = max(color[G[order[i]][j].to],color[order[i]]+1);

  rep(i,n)cnt[color[i]]++;

  bool check = false;
  rep(i,n)if(cnt[i] >= 2)check = true;

    cout << check << endl;

  return 0;
}

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

int main() {
	int n;
	cin>>n;
	if(n%10==3){
	    cout<<"bon";
	}
	else if(n%10==0 || n%10==1 || n%10==6 || n%10==8){
	    cout<<"pon";
	}
	else{
	    cout<<"hon";
	}
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n';

int main(){
    ios_base::sync_with_stdio(0); cin.tie(nullptr);
    char c; cin>>c;
    cout<<((isupper(c))?'A':'a')<<endl;
    return 0;
}

Measured memory_bytes: 3556
s = list(input())
n = len(s)
ans = [0] * n

r = 0
l = 0
s.append("R")

for i in range(n):
    if s[i] == "R":
        r += 1
        
        if s[i+1] == "L":
            if r % 2 == 1:
                ans[i] += r//2 + 1
                ans[i+1] += r//2
                
            else:
                ans [i] += r//2
                ans[i+1] += r//2
                
            r = 0
        
    else:
        l += 1
        
        if s[i+1] == "R":
            if l % 2 == 1:
                ans[i-l] += l//2
                ans[i-l+1] += l//2 + 1
                
            else:
                ans[i-l] += l//2
                ans[i-l+1] += l//2
                
            l = 0
            
print(*ans)

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

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

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

static const ll INF = 1e15;

static const ll mod = 1e9 + 7;

int main() {
	ll n,k;
    cin >> n >> k;
    vector<ll> prev(n);
    rep(i, n) cin >> prev[i];
    vector<ll> current(n);
    rep(_, k) {
        vector<ll> sums(n + 1, 0);
        const auto& source = prev;
        for (int i = 0; i < n; i++) {
            auto t = source[i];
            auto front = max(0LL, i - t);
            auto back = min(n, i + t + 1);
            sums[front]++;
            sums[back]--;
        }
        //cout << "back array" << endl;
        //rep(i, n + 1) {
        //    cout << sums[i] << ",";
        //}
        //cout << endl;
        ll s = 0;
        //cout << "current" << endl;
        rep(i, n) {
            s += sums[i];
            //cout << s << ",";
            current[i] = s;
        }
        bool finish = true;
        rep(i, n) {
            if (current[i] != n) {
                finish = false;
                break;
            }
        }
        swap(prev, current);
        if (finish) break;
    }
    rep(i, n) {
        cout << prev[i] << " ";
    }
    cout << endl;
	return 0;
}
	

Measured memory_bytes: 7964
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

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

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long gcd(long long a, long long b) {
  if(a % b == 0) return b;
  else return gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  if(n%2==0)cout<<n/2<<endl;
  else cout<<n/2+1<<endl;
}


Measured memory_bytes: 256
//==========================================
// ABC130b
//
// 2019/08/21
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  int n, x;
  cin >> n >> x;
  int l, d, cnt;
  d=0;
  cnt=1;

  for(int i=0; i<n; i++)
  {
    cin >> l;
    d = d + l;
    if(d<=x) cnt++;
  }
  cout << cnt << endl;  

  return 0;
}

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

#define rep(i,N) for(int i=0; i<(N); i++)
#define pb push_back

typedef long long ll;
typedef pair<int,int> P;
const ll mod=1e9+7;

char S[100005];
ll dp[100005][15];

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){ 

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

cin>>S;

int ns=0;
for(int i=0; S[i]!='\0'; ++i) ns++;

if(S[0]=='?'){
	rep(i,10){
	dp[ns-1][i]=1;
	}
}else{
	int x=ctoi(S[0]);
	dp[ns-1][x]=1;
}

for(int i=ns-2; i>=0; i--){
	ll in=ns-1-i;
	if(S[in]=='?'){
		rep(k,10){
			rep(j,13){
				ll n=(k+10*j)%13;
				dp[i][n]=(dp[i][n]+dp[i+1][j])%mod;
			}
		}
	}else{
		rep(k,10){
			if(ctoi(S[in])==k){ 
			rep(j,13){
				ll n=(k+10*j)%13; 
				dp[i][n]=(dp[i][n]+dp[i+1][j])%mod;
			}
			}
		}
	}
}

cout<<dp[0][5]<<endl;

}


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

vector<int> G[5010];
vector<int> rG[5010];

bool From1[2510];
bool toN[2510];


void dfs(int v) {
    if (From1[v]) return;
    From1[v] = true;
    for (auto to: G[v]) dfs(to);
}

void rdfs(int v) {
    if (toN[v]) return;
    toN[v] = true;
    for (auto to: rG[v]) rdfs(to);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, P;
    cin >> N >> M >> P;
    int a[5010], b[5010], c[5010];
    rep(i, M) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        c[i] = -c[i] + P;
        G[a[i]].push_back(b[i]);
        rG[b[i]].push_back(a[i]);
    }
    dfs(0);
    rdfs(N - 1);
    int ok[5010];
    int d[5010];
    rep(i, 5010) d[i] = INF;
    d[0] = 0;
    rep(i, N) ok[i] = From1[i] & toN[i];
    // // rep(i, N) cout << ok[i] << " ";
    // cout << endl;
    int step = 0;
    bool update = true;
    while(update) {
        update = false;
        rep(i, M) {
            if (!ok[a[i]] || !ok[b[i]]) continue;
            if (d[a[i]] + c[i] < d[b[i]]) {
                update = true;
                d[b[i]] = d[a[i]] + c[i];
            }
        }
        step++;
        if (step > N) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << max(0, -d[N - 1]) << endl;
    return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std ;
typedef long long ll ;
# define rep (i , n ) for ( int i =0; i < n ; i++)

int main()
{
	cin.tie(NULL);
	string S;
	cin >> S;

	int len = S.size();
	int min = 1000;

	int arr[len];
	for (int i = 0; i < len; i++)
	{
		arr[i] = S[i] - 48;
	}


	for (int j = 0; j < len - 2; j++)
	{
		int tmp = arr[j] * 100 + arr[j+1] * 10 + arr[j+2];
		int tmp_min = abs(tmp - 753);

		if (tmp_min < min)
		{
			min = tmp_min;
		}
	}
	cout << min << endl;
	return 0;
}

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

const int N = (1e5) + 5;
const ll OO = LLONG_MAX;
vector<int> maxSelection_ind;
ll interval_l[N], interval_r[N];
int interval_ind[N];
int n;

bool compInd_r(int i, int j) {
  return interval_r[i] < interval_r[j];
}

int activitySelection(int interval_ind[], int n) {
  sort(interval_ind, interval_ind + n, compInd_r);
  maxSelection_ind.clear();
  ll last_r = -OO;
  for (int i = 0; i < n; ++i) {
    int ind = interval_ind[i];
    if (last_r <= interval_l[ind]) {
      maxSelection_ind.emplace_back(ind);
      last_r = interval_r[ind];
    }
  }
  return maxSelection_ind.size();
}

int main() { // claudio van
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x, l; cin >> x >> l;
    interval_l[i] = x - l;
    interval_r[i] = x + l;
    interval_ind[i] = i;
  }
  cout << activitySelection(interval_ind, n) << "\n";
  return 0;
}

Measured memory_bytes: 2812
n=int(input())
i = 1
while True:
    x = i
    if x % 3 == 0 :
        print("",i,end="")
        if i+1 <= n :
            i+=1
            continue
        break
    while True:
        if x % 10 == 3 :
            print("",i,end="") 
            break
        x //=10
        if  x!=0 :
            continue
        break
    
    if  i+1 <= n :
        i+=1
        continue
    break
print("")


Measured memory_bytes: 6164
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#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 repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define o_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
#define trav(it, v) for(auto &it : v)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 	return r;
}


void solve()
{
	int x;
	cin >> x;
	rep(i, 1e5){
		if(i * (i + 1) / 2 >= x){
			cout << i;
			return;
		}
	}

}
int main()
{
    Red;
    // freopen("black.in", "r", stdin);
	// freopen("black.out", "w", stdout);
    int T = 1;
    // cin >> T;
    for(int i = 1; i <= T; ++i) {
    	// cout << "Case #" << i << ": ";
    	solve();
  	}
  	return 0;

}


Measured memory_bytes: 3664
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define Maxn 100000
#define ll long long
char s[Maxn+5],t[Maxn+5];
vector<int> id[30];
int n,m;
int num;
int main(){
	scanf("%s",s+1);
	scanf("%s",t+1);
	while(s[++n]!='\0');
	n--;
	while(t[++m]!='\0');
	m--;
	for(int i=1;i<=n;i++){
		id[s[i]-'a'].push_back(i);
	}
	for(int i=1;i<=m;i++){
		if(id[t[i]-'a'].empty()){
			puts("-1");
			return 0;
		}
	}
	int last=0;
	int x;
	for(int i=1;i<=m;i++){
		if(last>=id[t[i]-'a'].back()){
			num++;
			last=id[t[i]-'a'].front();
			continue;
		}
		x=upper_bound(id[t[i]-'a'].begin(),id[t[i]-'a'].end(),last)-id[t[i]-'a'].begin();
		last=id[t[i]-'a'][x];
	}
	cout<<1ll*num*n+last<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main()
{
		string a,b,s;
		cin>>a>>b;
	int s1[2];
	string c=a+b; 
stringstream ss;  
ss<<c;  
int i;  
ss>>i;  

	if(sqrt(i)==int(sqrt(i))) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
  
using namespace std;
  
int main(void){

	int W,H;
	int x,y;
	bool f;
	char stage[101][101];

	while(1){
		cin>>H>>W;
		if(H==0&&W==0) break;
		getchar();
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				stage[i][j]=getchar();
			}
			getchar();
		}
		x=0,y=0;
		f=true;
		while(f){
			switch(stage[y][x]){
				case '>':
					stage[y][x]='-';
					x+=1;
					break;
				case '<':
					stage[y][x]='-';
					x-=1;
					break;
				case '^':
					stage[y][x]='-';
					y-=1;
					break;
				case 'v':
					stage[y][x]='-';
					y+=1;
					break;
				case '.':
					cout<<x<<" "<<y<<endl;
					f=false;
					break;
				case '-':
					cout<<"LOOP"<<endl;
					f=false;
					break;
				default:
					cout<<"error"<<endl;
					return -1;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1172
N = int(input())
p = list(map(int, input().split()))

p_sort = sorted(p)
x = 0

for i in range(N):
    if p[i] == p_sort[i]:
        continue
    else:
        x += 1

if x == 2 or x ==0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

int ans;

void solve(void){
	string s;
	cin >> s;
	if(s.size() == 1){
		if(s.back() == 's'){
			s += "es";
		}
		else{
			s += "s";
		}
		cout << s << endl;
		return;
	}
	if(s[s.size()-1] == 's'){
		s += "es";
	}
	else{
		s += "s";
	}
	 cout << s << endl; 
}

signed main() {
int t = 1;
// cin >> t;    
	while(t--)
    solve();

    return 0;
}


Measured memory_bytes: 3640
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(M)]
ab.sort(key=lambda x:x[1])
ans=1
x=ab[0][1]
for a,b in ab[1:]:
    if a+1>x:
        x=b
        ans+=1
print(ans)


Measured memory_bytes: 65368
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
int bitcount(int n) {
  int cnt = 0;
  while (n > 0) {
    if ((n & 1) == 1) {
      cnt++;
    }
    n >>= 1;
  }
  return cnt;
}

int main() {
  int N, M;
  cin >> N >> M;
  VEC<int> K(M);
  VEC<VEC<int>> S(M);
  REP(i, 0, M) {
    cin >> K[i];
    S[i] = VEC<int>(K[i]);
    REP(j, 0, K[i]) {
      cin >> S[i][j];
      S[i][j]--;
    }
  }
  VEC<int> P(M);
  REP(i, 0, M) cin >> P[i];
  VEC<int> pattern(M, 0);
  REP(i, 0, M) {
    REP(j, 0, K[i]) { pattern[i] += (1 << S[i][j]); }
  }

  int count =0;
  REP(bit, 0, 1 << N) {
    int all = 1;
    REP(i, 0, M) {
      int on = bit & pattern[i];
      if (bitcount(on) % 2 != P[i]) {
        all = 0;
        break;
      }
    }
    if(all)count++;
  }
  cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    n -= 1
    now = ['a']
    for _ in range(n):
        next = []
        for S in now:
            d = ord(max(S)) - ord('a')
            for i in range(d+2):
                next.append(S + chr(i + ord('a')))
        now = next

    now.sort()
    for S in now:
        print(S)
resolve()

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

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

  vector<int> a(m);
  //vectorに全入力値を代入する
  rep(i,m) cin >> a[i];

  //勉強にかかる日数を算出する
  int sum = 0;
  rep(i,m) sum += a[i];

  int ans = 0;
  if (n - sum < 0) ans = -1;
  else ans = n - sum;

  cout << ans << endl;

}


Measured memory_bytes: 3636
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, m: usize, x: i64,
    }
    let mut prices = Vec::new();
    let mut aij = Vec::new();
    for _ in 0..n {
        input! {c: i64, aa: [i64; m],}
        prices.push(c);
        aij.push(aa);
    }

    let mut ans = std::i64::MAX;
    for bits in 0..1<<n {
        let mut rikaido = vec![0i64; m];
        let mut amount = 0i64;
        for i in 0..n {
            let mask = 1<<i;
            if bits & mask != 0 {
                amount += prices[i];
                for algo in 0..m {
                    rikaido[algo] += aij[i][algo];
                }
            }
        }
        if rikaido.into_iter().all(|r| r >= x) {
            ans = min(ans, amount);
        }
    }
    if ans == std::i64::MAX {
        println!("-1")
    } else {
        println!("{}", ans);
    }

}



Measured memory_bytes: 2180
#include <stdio.h>
int main (void)
{
	int a,b,c;
	
	scanf("%d %d %d\n",&a,&b,&c);
	
	if(a<=b && b<=c)
	{
		printf("%d %d %d\n",a,b,c);
	}
	else if(a<=c && c<=b)
	{
		printf("%d %d %d\n",a,c,b);
	}
	else if(b<=a && a<=c)
	{
		printf("%d %d %d\n",b,a,c);
	}
	else if(c<=a && a<=b)
	{
		printf("%d %d %d\n",c,a,b);
	}
	else if(c<=b && b<=a)
	{
		printf("%d %d %d\n",c,b,a);
	}
	else if(b<=c && c<=a)
	{
		printf("%d %d %d\n",b,c,a);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <bitset>

using ll = long long int;
using ul = unsigned long long int;

namespace lamlib
{
	// Absolute
	template<class T>
	inline T abs(const T &a){ return (a>0) ? a : -a; }
	// GCD: a > b
	ul gcd(ul a,ul b) { return (!b) ? a : gcd(b,a%b); }
}

int main(int argc,char *argv[])
{
	ll k,n;
	std::cin >> k >> n;

	std::vector<ll> a(n,0);
	for(ll i = 0;i < n;++i) { std::cin >> a[i]; }
	
	ll max = (a[0]+k)-a[n-1];
	for(ll i = 0;i < n-1;++i)
	{
		ll d = (a[i+1]-a[i]);
		if(d > max){ max = d; }
	}

	std::cout << k-max << std::endl;

	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
	    // 引数で標準入力System.inを指定する
	    Scanner scanner = new Scanner(System.in);
		try {

		    // 1行目を取得(a)
			String[] line1Array = scanner.nextLine().split(" ");
			int num = Integer.parseInt(line1Array[0]);

			for (int i = 1; i < num + 1; i++) {
				int answer = searcher(i);
				System.out.printf("%d", answer);
				System.out.println("");
			}

		} finally {
		    // Scannerクラスのインスタンスをクローズ
		    scanner.close();
		}
		long end = System.currentTimeMillis();
		// System.out.println((end - start) );
	}

	public static int searcher (int target) {
		int answer = 0;

		boolean isNotOveredX =true;
		int x = 0;

		boolean isNotOveredY =true;
		int y = 0;

		boolean isNotOveredZ =true;
		int z = 0;

		while (isNotOveredX) {
			x++;
			y=0;
			z=0;

			// 打ち切る
			if (x >= target) { break; }

			long sum = (x * x);

			if ( sum >= target) {break;}

			while (isNotOveredY) {
				y++;
				z=0;

				// 打ち切る
				if (y >= target) { break; }

				//sum = (x * x) + (y * y) + (x * y) ;
				sum = (x * x) + (y * (y + x));

				// 打ち切る
				if ( sum >= target) { break;}

				while (isNotOveredZ) {

					z++;
					//long sum =  (x * x) + (y * y) + (z * z) + (x * y) + (y * z)  + (z * x) ;

					// 打ち切る
					if (z >= target) { break; }

					long beforeSum = sum;
					// sum = sum + (z * z)  + (y * z)  + (z * x) ;
					sum = sum + (z * z)  + (z * (y +x)) ;
					//sum =  (x * x) + (y * y) + (z * z) + (x * y) + (y * z)  + (z * x) ;

					if (sum > target)  { break; }

					if (sum == target) {
						answer++;
						break;
					}
					sum = beforeSum;
				}
			}
		}
		return answer;
	}

}


Measured memory_bytes: 59792
export class Main {
  static main(input): string {
    const tmp: string[] = input.split("\n");
    const t: number = tmp[0].split(" ").map(int => parseInt(int))[0];
    return `${3 * t * t}`;
  }
}
 console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

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

int main() {
	int N;
	cin >> N;
	bool flag = false;
	string x;
	for (int i=0; i<N; i++){
		cin >> x;
		if (x=="Y") flag = true;
	}
	if (flag) puts("Four");
	else puts("Three");
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;

int main() {
   int n;cin >>n;
   vector<int>a(n);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
    }
    sort(all(a));
    bool flg=true;
    if(a.back()==0){
        puts("Yes");
        return 0;
    }
    if(a.size()%3!=0){
        flg=false;
    }
    int m=a.size()/3;
    if(a[0]!=a[m-1])flg=false;
    if(a[m]!=a[2*m-1])flg=false;
    if(a[2*m]!=a[3*m-1])flg=false;
    if((a[0]^a[m])!=a[2*m])flg=false;
    if(flg)puts("Yes");
    else puts("No");
}


Measured memory_bytes: 3724
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int> >in(n,vector<int>(m));
  vector<vector<int> >out(n+1,vector<int>(m+1));
  rep(i,n+1)rep(j,m+1)out[i][j]=1e9;
  out[0][1]=0;
  rep(i,n)rep(j,m){
    char d;cin>>d;in[i][j]=d-'0';
  }
  rep(i,n)rep(j,m)out[i+1][j+1]=in[i][j]+min(out[i][j+1],out[i+1][j]);
  cout<<out[n][m]<<endl; 

}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
int main()
{
         string s;
         cin>>s;
         int c=0;
         if(s[2]!=s[3])c=1;
         if(s[4]!=s[5])c=1;
         if(c==0)cout<<"Yes"<<endl;
         else cout<<"No"<<endl;
         return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n, ans; ans = 0;
    scanf("%lld", &n);
    ll a[n] = {};
    ll memo[n+1] = {};
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        memo[a[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        ans += (memo[i]*(memo[i]-1))/2;
    }
    for (int i = 0; i < n; i++) {
        printf("%lld\n", ans-(memo[a[i]]-1));
    }
}

Measured memory_bytes: 6948
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    long long  a[N],c=0,b=0;
    for(int i=0;i<N;i++){
        cin >> a[i];
        c+=a[i];
    }
    
    long long ans=1000000000000000;
    for(int i=0;i<N-1;i++){
        c=c-a[i];
        b=b+a[i];
        ans = min(abs(c-b),ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
N,M,K = map(int,input().split())

MOD = 998244353
l = [0]*N
l[0] = 1
for i in range(1,N):
  l[i] = l[i-1]*(M-1)
  l[i] = l[i]%MOD

fact = [0]*N
fact[0] = 1
for i in range(1,N):
  fact[i] = fact[i-1]*i%MOD
  
fact_inv = [0]*N
for i in range(N):
  fact_inv[i] = pow(fact[i], MOD-2, MOD)
ans = 0
for i in range(K+1):
  ans += M*l[N-1-i]%MOD * fact[N-1] * fact_inv[i] %MOD * fact_inv[N-1-i] %MOD
  ans %= MOD
  
print(ans%MOD)

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
    int N,K; cin >> N >> K;
    cout << N - K + 1 << endl; 
    return 0;
}


Measured memory_bytes: 256
line=input().split()
n=int(line[0])
k=int(line[1])

points=[]
hojds=[]
bredds=[]
for i in range(n):
    line=input().split()
    x=int(line[0])
    y=int(line[1])
    points.append([x,y])
    bredds.append(x)
    hojds.append(y)
hojds.sort()
bredds.sort()
points.sort(key=lambda x:x[0])

area=10**18*4
for h1 in hojds:
    for h2 in hojds:
        if h1>=h2:
            continue
        for b1 in bredds:
            num=0
            for p in points:
                if p[0]>=b1 and p[1]>=h1 and p[1]<=h2:
                    num+=1
                    if num==k:
                        b2=p[0]
                        newarea=(b2-b1)*(h2-h1)
                        area=min(area,newarea)
                        break
            
print(area)


Measured memory_bytes: 3188
import Data.List
import Control.Monad

main = do
  [h,w] <- map read . words <$> getLine
  n <- readLn
  as <- map read . words <$> getLine
  putStrLn $ unlines $ map (unwords . map show) (coloring h w n as)

coloring h w n as = zipWith ($) (cycle [id,reverse]) sns
  where
    sns = splitOn w ns
    ns = concat $ zipWith (\x a -> replicate a x) [1..n] as

splitOn :: Int -> [a] -> [[a]]
splitOn n = unfoldr (\xs -> guard ((not.null) xs) >> return (splitAt n xs))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    string s;

	cin >> s;

	bool c = false;
	bool f = false;

	int i, len = s.size();

	rep(i, len) {
		if (s[i] == 'C') c = true;
		if (c && s[i] == 'F') f = true;
	}

	if (c && f) Out("Yes");
	else Out("No");
	
	return 0;
}


Measured memory_bytes: 256
/*In the name of Allah*/
#include <bits/stdc++.h>
using namespace std;
#define inf 1000000111
#define MAX 200111
#define mod 1000000007
#define ll long long
int n,k;
vector<int> g[MAX];
bool see[MAX];
ll ans = 1;
inline void solve(){
	queue<int> q;
	q.push(1);
	ans *= k;
	int cap;
	while(q.size()){
		int u = q.front();
		q.pop();
		see[u] = 1;
		if(u == 1)cap = k - 1;
		else cap = k - 2;
		for(auto v : g[u]){
			if(!see[v]){
				ans *= cap;
				ans %= mod;
				cap--;
				q.push(v);
			}
		}
	}
	cout<<ans;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int x,y;
	cin>>n>>k;
	for(int i = 1; i < n ; i++){
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	solve();
	return 0;
}


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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n, m;
    cin >> n >> m;

    ll tmp = pow(2, m);
    ll ans = 1900 * tmp * m;
    ans += tmp * (n-m) * 100;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main()
{ string s1,s2;
cin>>s1>>s2;
int sum=0;
int t=s1.length();
for(int x=0; x<t; x++)
{
    if(s1[x]==s2[x])
    sum++;
}
  if(sum==t)
  cout<<"Yes";
  else
  cout<<"No";
}

Measured memory_bytes: 3620
n = input()
a = sorted(map(int, raw_input().split()))
a_i = a[-1]
a_j = a[0]
best = -1
for j in range(n-1):
    cur = min(a_i - a[j], a[j])
    if best < cur:
        a_j = a[j]
        best = cur
print "%d %d" % (a_i, a_j)

Measured memory_bytes: 11308
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>

    using namespace std;
    using Graph = vector<vector<int>>;

    #define INF 10000000
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

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

    
    int main(){
      long x,y;
      cin>>x>>y;
      y /=x;
      long cnt=0;
      while(y>0){
        cnt++;
        y/=2;
      }
      cout <<cnt<<endl;
      }
    

    

     

Measured memory_bytes: 256
function main(input) {
    var arr = input.split(/\r?\n/g)[0].split(" ");
    const A = arr[0], B = arr[1], C = arr[2];
    var flg = false;
    if (A == B && B != C) flg = true;
    if (B == C && C != A) flg = true;
    if (C == A && A != B) flg = true;
    console.log(flg ? "Yes" : "No")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;


int main() {
  ll n,m;
  cin >> n >> m;
  ll ans = max(n-m,0LL);

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

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int num,train,taxi,trainsum;

    scanf("%d %d %d",&num,&train,&taxi);

    trainsum=train*num;

    if(trainsum<taxi){
        printf("%d\n",trainsum);
    }else{
        printf("%d\n",taxi);
    }

    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N = sc.nextInt();
        // スペース区切りの整数の入力
        int [] A = new int [N];
        for(int i=0; i<N; i++){
        	A[i] = sc.nextInt();
        }
        
        long [] L = new long [N];
        for(int i=1; i<N; i++){
        	if(A[i]<A[i-1]){
            	L[i]=A[i-1]-A[i];
                A[i]=A[i-1];
            } else{
            	L[i]=0;
            }
        }
      	
      	long S;
   		S=0;
      	for(int i=1; i<N; i++){
        	S=S+L[i];
        }     	
        // 出力
        System.out.println(S);
    }
}


Measured memory_bytes: 59988
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

int N, A, B;

int main() {
    cin >> N >> A >> B;
    vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(401, vector<int>(401, 1e9)));
    dp[0][0][0] = 0;
    int ans = 1e9;
    for (int k = 1; k <= N; k++) {
        int a, b, c;
        cin >> a >> b >> c;
        for (int i = 0; i <= 400; i++) {
            for (int j = 0; j <= 400; j++) {
                if (i < a || j < b) {
                    dp[k][i][j] = dp[k - 1][i][j];
                    continue;
                }
                dp[k][i][j] = min(dp[k - 1][i][j], dp[k - 1][i - a][j - b] + c);
                if (i * B == j * A) ans = min(dp[k][i][j], ans);
            }
        }
    }
    cout << (ans < 1e9? ans: -1) << endl;
}

Measured memory_bytes: 27264
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

class dice{
  int* me;
public:
  dice(){}
  dice(int me_[6]){
    me = me_;
  }
  int getMe(int i){
    return *(me+i);
  }
  void East(){
    swap(me[0], me[3]);
    swap(me[3], me[5]);
    swap(me[5], me[2]);
  }
  void West(){
    swap(me[0], me[2]);
    swap(me[2], me[5]);
    swap(me[5], me[3]);
  }
  void North(){
    swap(me[0], me[1]);
    swap(me[1], me[5]);
    swap(me[5], me[4]);
  }
  void South(){
    swap(me[0], me[4]);
    swap(me[4], me[5]);
    swap(me[5], me[1]);
  }
  void Rotate(){
    swap(me[1], me[2]);
    swap(me[2], me[4]);
    swap(me[4], me[3]);
  }
};

bool same(dice d1, dice d2){
  REP(i,6)
    if(d1.getMe(i)!=d2.getMe(i))
      return false;
  return true;
}
bool sameDice(dice d, dice e){
  REP(i,4){
    if(same(d,e)){
      return true;
    }
    d.Rotate();
  }
  d.North();
  REP(i,4){
    if(same(d,e)){
      return true;
    }
    d.Rotate();
  }
  d.West();
  REP(i,4){
    if(same(d,e)){
      return true;
    }
    d.Rotate();
  }
  d.West();
  REP(i,4){
    if(same(d,e)){
      return true;
    }
    d.Rotate();
  }
  d.West();
  REP(i,4){
    if(same(d,e)){
      return true;
    }
    d.Rotate();
  }
  d.North();
  REP(i,4){
    if(same(d,e)){
      return true;
    }
    d.Rotate();
  }
  return false;
}

int me[6*100];
dice d[100];

int main(){ _;
  int n;cin>>n;
  REP(i,n*6) cin>>me[i];
  REP(i,n) d[i]=dice(me+i*6);
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(sameDice(d[i],d[j])){
	cout<<"No"<<endl;
	return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define nl cout<<'\n';
#define int long long
#define ff first
#define ss second
#define _lmax 1e14
#define pb push_back
void print(int a)                  {              cout<<a<<'\t'<<'\n';}
void print(int a,int b)                {          cout<<a<<'\t'<<b<<'\t'<<'\n';}
void print(int a,int b,int  c)             {      cout<<a<<'\t'<<b<<'\t'<<c<<'\n';}
void print(int a,int  b,int  c,int  d)         {   cout<<a<<'\t'<<b<<'\t'<<c<<'\t'<<d<<'\n';}
void print(int a,int  b,int  c,int  d,int  e)      { cout<<a<<'\t'<<b<<'\t'<<c<<'\t'<<d<<'\t'<<e<<'\n';}
void print(vector<int> &a)  {for(auto i:a)  cout<<i<<" ";   nl;}
void print(string s){cout<<s;nl;}

void MAIN()
{
    int n;  cin>>n;
    vector<int> a(n) , dp(n);
    for(auto &i:a)  cin>>i;

    dp[0] = 0;
    dp[1] = abs(a[0] - a[1]);

    for(int i=2 ; i<n ; i++)
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]) ,
                    dp[i-2] + abs(a[i] - a[i-2]));
    print(dp[n-1]);


}
int32_t main()
{
//      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
//     int t;  cin>>t; while(t--)
//     ios_base::sync_with_stdio(0) , cin.tie(0);  int t; cin>>t; while(t--)
    MAIN();
    return 0;
}
/*

9 2
6 19 3 4 4 2 6 7 8
2 5 11 18 30 43 62 83 121






*/


















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

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


Measured memory_bytes: 256
#include<stdio.h>
#define bit(n,m)(((n)>>(m))&1)

long long a[310];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%lld",a+i);
	long long xx=0;
	for(int i=2;i<n;i++)xx^=a[i];
	long long ss=a[0]+a[1];
	//ss=X+Y=(X^Y)+((X&Y)*2)
	//xx=X^Y
	
	long long aa=(ss-xx)/2;
	if( ss<xx || ss%2!=xx%2 || (aa&xx) || aa>a[0] ){
		puts("-1");
		return 0;
	}
	
	for(int i=60;i>=0;i--)if(bit(xx,i)){
		if((aa^(1LL<<i))<=a[0])aa^=1LL<<i;
	}
	
	printf("%lld\n",aa==0?-1:a[0]-aa);

}

Measured memory_bytes: 1708