akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{

int num[11]={};
int x,t,T=0;
double S1=0,S2=0,V1,V2,W;
bool f1=false,f2=false;
while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%lf,%lf",&num[0],&num[1],&num[2],&num[3],&num[4],&num[5],&num[6],&num[7],&num[8],&num[9],&V1,&V2)!=EOF){
/*
for(int i=1;i<10;i++)
{scanf("%d",&x);num[i]=x;}
cin>>V1>>V2;
*/W=0;S1=0;S2=0;
for(int i=0;i<10;i++)
S1+=num[i];
for(int i=0;i<10;i++)
S2=V1+V2;
t=0;T=0;
W=S1*V1/S2;
//cout<<S1<<" "<<S2<<" "<<W<<" ";
do{

T+=num[t];
if(T==W)f1=true;
t++;
}while(T<W);
if(f1==false)printf("%d\n",t);
else if(f1==true)printf("%d\n",t);
}
return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
char c;
int main(){
	cin>>c;
	c=((c-'a')+1)+'a';
	cout<<c;
	re 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

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

	return 0;
}


Measured memory_bytes: 3072
#!/usr/local/bin/python3
# coding: utf-8

ha = input()
kita = ha.split(" ")
a = int(kita[0])
b = int(kita[1].replace(".",""))
m = a*b
m = str(m)

c = kita[1].split(".")
try:
    co = len(c[1])
except:
    co = 0
if int(kita[0]) * float(kita[1]) < 1:
    print("0")
elif co > 0:
    print(m[:-1*co])
else:
    print(m)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n,k,ans=0;cin>>n>>k;
    
    rep(i,n){
        ll h;cin>>h;
        if(h>=k) ans++;
    }

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

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

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	
	cout << string(tx - sx, 'R') + string(ty - sy, 'U');
	cout << string(tx - sx, 'L') + string(ty - sy, 'D');
	
	cout << 'D' + string(tx - sx + 1, 'R') + string(ty - sy + 1, 'U') + 'L';
	cout << 'U' + string(tx - sx + 1, 'L') + string(ty - sy + 1, 'D') + 'R';
	
	cout << endl;
	return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;






ll solve(ll cap, vector<vector<ll>> a) {
    vector<ll> dp(cap+1, 0);
    iota(dp.begin(), dp.end(), 0);

    for (int i=1; i<=cap; i++) {
	for (auto item: a) {
	    ll weight = item[0];
	    ll reward = item[1];
	    if (i-weight>=0) {
		dp[i] = max(dp[i], reward+dp[i-weight]);
	    }
	}
    }

    return *max_element(dp.begin(), dp.end());
}


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


    ll n;
    ll ga,sa,ba;
    ll gb,sb,bb;

    cin>>n;
    cin>>ga>>sa>>ba;
    cin>>gb>>sb>>bb;

    n = solve(n, {{ga,gb},{sa,sb},{ba,bb}});
    n = solve(n, {{gb,ga},{sb,sa},{bb,ba}});
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 198428
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	int n;
	cin >> n;
	V a(n);
	int MAX = 0;
	int pla = -1;
	rep(i, n) {
		cin >> a[i];
		if (MAX < a[i]) pla = i;
		chmax(MAX, a[i]);
	}
	int base = MAX / 2;
	int near = Inf;
	int ans = -1;
	rep(i, n) {
		int tmp = abs(base - a[i]);
		if (i == pla) continue;
		if (tmp < near) {
			near = tmp;
			ans = a[i];
		}
	}
	cout << MAX << " " << ans << endl;
	return 0;
}

Measured memory_bytes: 640
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
#include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)   (x).begin(),(x).end()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define mp       make_pair
#define eb       emplace_back

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i*i <= n; i++) {
		ans = max(ans, i*i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())

ab = [list(map(int,input().split())) for i in range(n)]

a = [i[0] for i in ab]
b = [i[1] for i in ab]

temp = 0
for i in reversed(range(n)):
    a[i] += temp
    
    if a[i] % b[i] == 0:
        continue
    
    else:
        temp += (b[i] - (a[i]%b[i]))
    
print(temp)

Measured memory_bytes: 33048
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vint a = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
    int K;
    cin >> K;
    cout << a[K -1] << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from heapq import heappop as hpp, heappush as hp

readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

geta = 10**6        
Q = [-(B[i]*geta+i) for i in range(N)] + [0]
Q.sort()

ans = 0
cnt = 0
inf = 10**9+7
while cnt < N:
    b, idx = divmod(-hpp(Q), geta)
    a = A[idx]
    if b < a:
        ans = -1
        break
    bside = B[(idx+1)%N] + B[(idx-1)%N]
    kb = 1+(b-bside)//bside
    ka = (b-a)//bside
    k = min(ka, kb)
    B[idx] -= k*bside
    ans += k
    if B[idx] == a:
        cnt += 1
    elif k == 0:
        ans = -1
        break
    else:
        hp(Q, -(B[idx]*geta+idx))
print(ans)

Measured memory_bytes: 115448
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll H, W;
ll N;

int main() {
	scanf("%lld %lld %lld", &H, &W, &N);
	ll temp = max(H, W);
	ll ans = ceil(N / (temp * 1.0));
	printf("%lld\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e) int i; for(int i=s;i<=e;i++)
#define repd(i,s,e) int i; for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())

const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
 


signed main()
{
 
    fast;
    read(n);
    readarr(a,n);
    int nxt =1,k=0;
    loop(i,n){
    	if(a[i]==nxt) {
    		k++;
    		nxt++;
    	}
    }
    if(k==0) cout<<-1<<endl;
    else
    cout<<n-k<<endl;
    return 0;
}

/* Pooja Yadav */

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

  #define int         long long
  #define pb          push_back
  #define pf          emplace_front
  #define all(a)      (a).begin(),(a).end()
  #define rall(a)     (a).rbegin(),(a).rend()
  #define pii 		pair<int,int>
  #define psi 		pair<string,int>
  #define vi 			vector<int>
  #define vpii  		vector<pii>
  #define vvi 		vector<vi>
  #define sz(x)	    (int)(x).size()
  #define x           first
  #define y           second
  #define endl        '\n'
  #define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  #define MOD         1000000007
  #define hell        998244353
  #define prec(n) 	fixed<<setprecision(n)
  #define ini(a, i) 	memset(a, i, sizeof(a))
  #define output(x)   cout << (x ? "YES" : "NO")<<endl;
  using namespace std;

  #define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
  #define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
  #define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
  void err(istream_iterator<string> it) {}
  template<typename T, typename... Args>
  void err(istream_iterator<string> it, T a, Args... args) {
      cout << "[" << *it << ": " << a << "]\t";
      err(++it, args...);
  }

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


  // Code from Here -------------------------------------------------------------------------------

  signed main() {
      tezz

      // #ifndef ONLINE_JUDGE
      // 	freopen("input.txt", "r", stdin);
      // 	freopen("output.txt", "w", stdout);
      // #endif

      int n;
      cin >> n;
      int a[n];
      int sum = 1;
      for(int i=0; i<n; i++){
          cin >> a[i];		
      }
      int pre[n+1];
      pre[n-1] = a[n-1];
      int ans = 0;
      pre[n]=0;
      for(int i=n-1; i>=0; i--){
          pre[i] = (pre[i+1] + a[i])%MOD;
      }
      for(int i=0; i<n; i++){
          ans = (ans + (pre[i+1] * a[i])%MOD)%MOD;
      }
      cout << ans << endl;

      return 0;
  }

Measured memory_bytes: 6680
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


N = int(input())

if N == 1:
    print(0)
    exit()

fact = factorization(N)
ans = 0
for _, y in fact:
    for i in range(y):
        y -= i+1
        ans += 1
        if y < i+2:
            break

print(ans)


Measured memory_bytes: 9480
#include <iostream>
#include <math.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  long long D;
  cin>>D;
  long long X[N]={};
  long long Y[N]={};
  int i;
  int count=0;
  for (i=0;i<=N-1;i++){
  cin>>X[i]>>Y[i];
  }
  for(i=0;i<=N-1;i++){
  if(X[i]*X[i]+Y[i]*Y[i]<=D*D){
  count++;
  }
   // cout<<X[i]*X[i]+Y[i]*Y[i]<<endl;
  }
  cout<<count;
}

Measured memory_bytes: 6752
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

typedef string::const_iterator State;
int number(State&);
int factor(State&);
int term(State&);
int expression(State&);

// ??°??????????????????????????????????????°????????????
int number(State &begin) {
    int ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}

// ??¬??§?????°???????????????????????????????????????????????????
int factor(State &begin) {
    if (*begin == '(') {
        begin++; // '('????£???°??????
        int ret = expression(begin);
        begin++; // ')'????£???°??????
    } else {
        return number(begin);
    }
}

// ?????????????????????????????????????????????????????????????????????
int term(State &begin) {
    int ret = factor(begin);

    for (;;) {
        if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        } else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        } else {
            break;
        }
    }

    return ret;
}

// ?????????????????????????????????????????????????????????????????????
int expression(State &begin) {
    int ret = term(begin);

    for (;;) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);
        } else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        } else {
            break;
        }
    }

    return ret;
}

int expression2(State &begin){
    int ret = term(begin);

    for (;;) {
        if (*begin == '+') {
            begin++;
            ret += number(begin);
        } else if (*begin == '-') {
            begin++;
            ret -= number(begin);
        } else if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        } else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        } else {
            break;
        }
    }

    return ret;

}


int main(){
    int n;
    string s;
    getline(cin, s);
    cin >> n;
    cin.ignore();

    State begin = s.begin();
    State begin2 = s.begin();
    int correct = expression(begin);
    int mistake = expression2(begin2);
    if(n == correct && n == mistake){
        cout << 'U' << endl;
    }else if(n == correct){
        cout << 'M' << endl;
    }else if(n == mistake){
        cout << 'L' << endl;
    }else{
        cout << 'I' << endl;
    }
    return 0;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define stop exit(0)
#define pb push_back
#define skip continue
//scanf("%lld",&a);
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    vector<long long>u,v;
    pair<long long, long long>n;
    set<string>y;
    long long a,b,c,d=0,e=0,i,f=0,g=0,j,k=0,l=0,r=0,z,m,h,p;
    string t,s,x,q;
    double w;
    cin>>a>>b;
    b*=b;
    while(a--){
        cin>>c>>d;
        if(c*c+d*d<=b){
            e++;
        }
    }
    cout<<e;
}

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

string s, t;


int main() {
	cin>>s>>t;
	int n = s.size(), m = t.size();
	int dp[n+1][m+1];
	
	for(int i=0; i<=n; i++) dp[i][0] = 0;
	for(int j=0; j<=m; j++) dp[0][j] = 0;
	
	for(int i=1;i<=n;i++) {
		for(int j=1; j<=m; j++) {
			if(s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1]+1;
			else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	
//	for(int i=0;i<=n;i++) {
//		for(int j=0; j<=m; j++) {
//			cout<<dp[i][j]<<" ";
//		}
//		cout<<"\n";
//	}
	string res = "";
	int i = n, j = m;
	while(i>0 && j>0) {
//		if(dp[i][j]==0) break;
		if(s[i-1] == t[j-1]) {
			i--; j--;
			res+=s[i];
			
		}
		else if(dp[i-1][j] > dp[i][j-1]) {
			i--;
		}
		else {
			j--;
		}
	}
	reverse(res.begin(), res.end());
	cout<<res;
		
	
//	cout<<dp[n][m];	
	
	return 0;
	
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    reverse(a.begin(), a.end());
    vector<int> lis{a[0]};
    for (int i = 1; i < n; i++) {
        auto itr = upper_bound(lis.begin(), lis.end(), a[i]);
        if (itr == lis.end())
            lis.push_back(a[i]);
        else
            *itr = a[i];
    }
    cout << lis.size() << endl;
}

Measured memory_bytes: 1276
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ld = long double;
using ll = long long;

constexpr int mod = 998244353;
constexpr int odw2 = (mod + 1) / 2;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
int Pot(int a, int b) { int res = 1; while (b) { if (b % 2 == 1) MnozDo(res, a); a = Mnoz(a, a); b /= 2; } return res; }
int Odw(int a) { return Pot(a, mod - 2); }
void PodzielDo(int& a, int b) { MnozDo(a, Odw(b)); }
int Podziel(int a, int b) { return Mnoz(a, Odw(b)); }
int Moduluj(ll x) { x %= mod; if (x < 0) x += mod; return x; }

template <typename T> T Maxi(T& a, T b) { return a = max(a, b); }
template <typename T> T Mini(T& a, T b) { return a = min(a, b); }

constexpr int nax = 300 * 1000 + 105;

int sil[nax];
int odwsil[nax];

int C(int n, int k) {
  if (!(0 <= k and k <= n)) return 0;
  return Mnoz(sil[n], Mnoz(odwsil[n - k], odwsil[k]));
}

int main() {
  sil[0] = 1;
  for (int i = 1; i < nax; i++) sil[i] = Mnoz(sil[i - 1], i);
  odwsil[nax - 1] = Odw(sil[nax - 1]);
  for (int i = nax - 2; i >= 0; i--) odwsil[i] = Mnoz(odwsil[i + 1], i + 1);

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  int wynik = 0;
  for (int i = 0; i <= n; i++) {
    ll zost = k - i * a;
    if (zost >= 0 and zost % b == 0) {
      zost /= b;
      if (0 <= zost and zost <= n) {
        DodajDo(wynik, Mnoz(C(n, i), C(n, zost)));
      }
    }
  }
  cout << wynik << endl;
  return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL A, B, C, D, E, F;
std::set<LL>wL, sL;
long double per;
LL ans, sub;

int main()
{
	in >> A >> B >> C >> D >> E >> F;

	rep(i, F / (100 * A) + 1)
	{
		rep(j, F / (100 * B) + 1)
		{
			auto res = 100 * (i*A + j*B);
			wL.insert(res);
		}
	}
	rep(i, F / C + 1)
	{
		rep(j, F / D + 1)
		{
			auto res = i*C + j*D;
			sL.insert(res);
		}
	}
	for (auto i : wL)
	{
		for (auto j : sL)
		{
			auto sum = i + j;
			if ((0 < sum && sum <= F) && (i * E / 100 >= j))
			{
				long double res = (long double)100 * (long double)j / (long double)sum;
				if (res >= per)
				{
					ans = sum;
					sub = j;
					per = res;
				}
			}
		}
	}
	
	out << ans << " " << sub << std::endl;
	return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.buffer.readline

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18

def divisors(n) -> list:
    res = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n // i)
    return res


N, K = map(int, input().split())
MOD = 10 ** 9 + 7

cnt = defaultdict(int)
for k in range(1, K + 1):
    for d in divisors(k):
        cnt[d] += 1
#print(cnt)

tmp = defaultdict(int)
for k in range(K, 0, -1):
    tmp[k] = pow(cnt[k], N, MOD)
    for i in range(2, K // k + 1):
        tmp[k] -= tmp[i * k]
#print(tmp)

ans = 0
for k in range(1, K + 1):
    ans = (ans + k * tmp[k]) % MOD
print(ans)

Measured memory_bytes: 100720
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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()
{
    string s;
    cin >> s;

    stack<char> stck;
    int len_ = s.size();
    for (int i=0; i<len_; i++) {
        char c = s[i];
        if (c == '0') {
            stck.push('0');
        } else if (c == '1') {
            stck.push('1');
        } else {
            if (!stck.empty()) {
                stck.pop();
            }
        }
    }

    vector<char>vec;
    while (!stck.empty()) {
        vec.emplace_back(stck.top());
        stck.pop();
    }

    reverse(vec.begin(), vec.end());
    for (int i=0; i<vec.size(); i++) {
        cout << vec[i];
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 3612
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#include <string>
using namespace std;

//宣言
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//数値
#define MOD 1000000007
#define INF (1<<20)
const double EPS = 1e-10;
const double PI = acos(-1.0);

//操作
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define REPB(i,n) for(int i=n;i>=0;--i)
#define SORT(A) sort(A,A+sizeof(A)/sizeof(A[0]))
#define VSORT(A) sort(A.begin(),A.end())
#define EXIST(s,e) (s.find(e)!=s.end())
#define PB push_back
#define MP make_pair
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);

//DEBUG
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

ll gcd(ll a,ll b) {
	if (a < b) swap(a, b);
	while (b > 0) {
		ll r = a%b;
		a = b;
		b = r;
	}
	return a;
}

int main() {
	ll n, x; cin >> n >> x;
	cout << 3 * (n - gcd(n, x)) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
typedef long long ll;
const int maxn = 1e5;
const double eps = 1e-9;
int main(void)
{
	ll a, b, c;
	scanf("%lld %lld %lld", &a, &b, &c);
	ll x, y;
	x = 4 * a * b;
	y = (c - a - b) * (c - a - b);
	if (c - a - b < 0)
		printf("No\n");
	else {
		if (x < y)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.lang.Math.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HashMap<Integer,Integer> mem = new HashMap<>();
        int k = in.nextInt();
        int s = in.nextInt();
        int x = Math.min(s,k);
        int total=0 ;
        for(int i =0;i<=x;i++){
            for(int j=0;j<=x;j++){
                int sum = i+j;
                if(sum<=s && sum+x>=s)
                    total++;
            }
        }
        System.out.print(total);
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct UnionFind
{
    vector<ll> par;
    vector<ll> rank;
    vector<ll> sz;
    UnionFind(ll n) : par(n), rank(n), sz(n)
    {
        for(ll i = 0; i < n; i++)
        {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }
    ll root(ll x)
    {
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }
    void unite(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y])
        {
            par[x] = y;
            sz[y] += sz[x];
        }
        else
        {
            par[y] = x;
            sz[x] += sz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    bool same(ll x, ll y)
    {
        return root(x) == root(y);
    }
    ll size(ll x)
    {
        x = root(x);
        return sz[x];
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind tree(n);
    for(int i = 0; i < m; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        if(!tree.same(x, y))
        {
            tree.unite(x, y);
        }
    }
    set<int> s;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int cand = tree.root(i);
        if(s.count(cand) == 0)
        {
            ans++;
            s.insert(cand);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7296
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N;
const int MAX_N = 10000;
ll a[MAX_N - 1], b[MAX_N - 1], c[MAX_N];

bool used[MAX_N];
vll G[MAX_N];

priority_queue<ll, vll, greater<ll> > pq;

ll ans[MAX_N];

void dfs(int v) {
  used[v] = true;
  REP(i, G[v].size()) {
    if(!used[G[v][i]]) dfs(G[v][i]);
  }
  ans[v] = pq.top();
  pq.pop();
}



int main(){
  cin >> N;
  REP(i, N - 1) cin >> a[i] >> b[i];
  REP(i, N) cin >> c[i];
  REP(i, N - 1) {
    G[a[i] - 1].pb(b[i] - 1);
    G[b[i] - 1].pb(a[i] - 1);
  }
  REP(i, N) {
    used[i] = false;
    pq.push(c[i]);
  }
  dfs(0);

  sort(c, c + N);
  ll s = 0;
  REP(i, N - 1) {
    s += c[i];
  }
  cout << s << endl;

  REP(i, N) {
    cout << ans[i];
    if(i != N -1) cout << " ";
    else cout << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	char str1[3];
	char str2[3];
	
	scanf("%s", str1);
	scanf("%s", str2);
	
	if (str1[0] == str2[2] && str1[2] == str2[0] && str1[1] == str2[1]){
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
	return (0);
}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main() {
    int n;
    string s;
    vector<int> a(n);
    vector<int> cnt(3);
    cin >> n >> s;
    rep(i,n) a[i] = s[i]%3;
    rep(i,n) cnt[a[i]]++;
    ll ans = 1;
    rep(i,3) ans *= cnt[i];
    rep(j,n)rep(i,j){
        int k = 2*j-i;
        if(k < n){
            if(a[j] == a[i])continue;
            if(a[i] == a[k])continue;
            if(a[k] == a[j])continue;
        ans--;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 100000

using namespace std;

int p[maxn+5];
string s[maxn+5];
bool ac[maxn+5];

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n, m; cin >> n >> m;
  int i, j, z, a1 = 0, a2 = 0;
  for (i = 0; i < m; i++) {
    cin >> p[i] >> s[i];
    if (s[i] == "AC" && ac[p[i]] == 0) ac[p[i]] = 1, a1++;
  }
  for (i = 0; i < m; i++) {
    if (s[i] == "AC") ac[p[i]] = 0;
    if (s[i] == "WA" && ac[p[i]] == 1) a2++;
  }
  cout << a1 << ' ' << a2;
  return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int uint;
typedef long double ld;
//#define ll __int128
#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<pii> vpi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = atan2(1, 0) * 2;

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T>
ostream & operator << (ostream &out, vector<T> &a) {
    out << "{";
    for (auto x : a) out << x << " ";
    return out << "}";
}

void smain();

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


#ifdef ART_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef ART_HOME
    cout << "\n\n\n";
    cout << "TOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC << endl;
#endif
}


vi a, b, c;


bool comp(int i, int j)
{
    return a[i] - b[i] < a[j] - b[j];
}


void smain() {
    int n;
    cin >> n;

    int dif = 0;

    a.resize(n), b.resize(n), c.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    int ans = 0;

    for (int i = 0; i < n; ++i)
    {
        cin >> b[i];
        dif += min(0LL, a[i] - b[i]);
        c[i] = i;

        if (a[i] < b[i])
            ans++;
    }

    if (dif >= 0)
    {
        cout << 0 << '\n';
        return;
    }

    stable_sort(RALL(c), comp);
    int cur = 1;

    for (int i : c)
    {
        dif += a[i] - b[i];
        if (dif >= 0)
        {
            cout << cur + ans << '\n';
            return;
        }

        cur++;
    }

    cout << "-1\n";
}

Measured memory_bytes: 2944
n = int(input())
a,b = [],[]
ans = 0
for i in range(n):
    A,B = map(int,input().split())
    a.append(A)
    b.append(B)
def solve(x,y):
    z = -(-x//y)
    return y*z-x
for i in range(n-1,-1,-1):
    a[i] += ans
    ans += solve(a[i],b[i])


print(ans)

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

ll d[11][11];
int main() {
	int n;
	while (cin >> n, n) {
		memset(d, 0x3f, sizeof(d));
		int Max = 1;
		rep(i, n) {
			int a, b, c; scanf("%d%d%d", &a, &b, &c);
			d[a][b] = c; d[b][a] = c;
			Max = max(Max, max(a, b) + 1);
		}
		rep(k, Max)rep(i, Max)rep(j,Max)
			d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		int index;
		ll Min = LLONG_MAX;
		rep(i, Max) {
			ll cnt = 0;
			rep(j, Max) {
				if (i == j)continue;
				cnt += d[i][j];
			}
			if (cnt < Min) {
				Min = cnt;
				index = i;
			}
		}
		cout << index << ' ' << Min << endl;
	}
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;int64_t p[1<<20],g,N,i,c,b,n[1<<20],d[1<<20];main(){for(cin>>N;i<N;)cin>>c>>b,c+=1e9,p[i++]=(c<<32)+c+b;for(sort(p,p+N);c=i--;g=d[i]=(g+d[n[i]=c]+1)%998244353)for(;c<N&p[c]<p[i]<<32;c=n[c]);cout<<*d+1;}

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

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ff first
#define ss second

using namespace std;

const double pi = acos(-1);
const int N = 1e6 + 6, mod = 998244353, M = 1e7 + 7;
const ll MAX = 5e18;

char x;

int main()
{
    cin >> x;
    if(x > 'Z')
        cout << 'a';
    else
        cout << 'A';

    return 0;
}


Measured memory_bytes: 3580
S = input()
A = [0]*(len(S)+1)

for i in range(len(S)):
    if S[i] == "<":
        A[i+1] = A[i]+1

for i in range(len(S)-1, -1, -1):
    if S[i] == ">":
        A[i] = max(A[i], A[i+1]+1)

print(sum(A))

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

using pii = pair<int,int>;
using ll = long long;
using ull = unsigned long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ull MOD = 1000000007;

class Solver {
  public:
    bool solve() {
        ull N, K; cin >> N >> K;
        vector<ull> A(N); cin >> A;

        vector<ull> cnt(2010);
        rep(i, N) cnt[A[i]]++;
        rep(i, 2001) cnt[i + 1] += cnt[i];

        ull ans = 0;
        rep(i, N) repeat(j, i + 1, N) {
            if(A[i] > A[j]) ans = (ans + K) % MOD;
        }
        ull a = (K * (K - 1) / 2) % MOD;
        rep(i, N) {
            ans = ans + (cnt[A[i] - 1] * a) % MOD;
            ans %= MOD;
        }
        cout << ans % MOD << endl;

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

/**
 * Created by Ayushi on 18/08/2019.
 */

public class Main {
    public static void main(String[] args) throws IOException {
        double tot = 0;
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        double[] a = new double[n];
        temp = r.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            a[i] = Double.parseDouble(temp[i]);
            tot += 1/a[i];
        }
        r.close();
        double ans = 1/tot;
        System.out.println(ans);
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n): fact(n+1), ifact(n+1){
    assert(n < mod);
    fact[0] = 1;
    for (int i=1; i<=n; ++i)fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i=n; i>=1; --i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n-k];
  }
}comb(100005);

mint f(int n, int k){
  if(n<0) return 0;
  mint res = comb(n, k);
  res *= comb.fact[k];
  return res;
}
int k;
mint ans;
vector<int> to[100005];
void dfs(int v, int p=-1){
  for(int u: to[v]){
    if(u==p) continue;
    dfs(u, v);
  }
  int nk = (p==-1) ? k: k-2;
  int c = (p==-1) ? to[v].size() + 1: to[v].size() - 1;
  ans *= f(nk, c);
}
int main() {
  int n;
  cin >> n >> k;
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans = 1;
  dfs(0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

int main(){
    int n;
    cin >> n;
    for(int i = n; i < 1000; i++){
        if(i%111==0){
            cout << i << endl;
            break;
        }
    }


    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 REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
#define PER(i,n) for(int i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

void dfs(int v, const vector<vP> &g, vl &x, vb &seen) {
  seen[v] = true;
  for(P nv : g[v]) {
    if(seen[nv.fi]) continue;
    x[nv.fi] = x[v] + nv.se;
    dfs(nv.fi, g, x, seen);
  }
}

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

  int n, m;
  cin >> n >> m;
  vector<vP> g(n);
  rep(i,m) {
    int l, r, d;
    cin >> l >> r >> d;
    l--; r--;
    g[l].emplace_back(r,d);
    g[r].emplace_back(l,-d);
  }
  vl x(n,inf);
  vb seen(n);
  x[0] = 0;
  rep(i,n) {
    if(seen[i]) continue;
    dfs(i,g,x,seen);
  }
  rep(i,n) {
    for(P nv : g[i]) {
      if(x[i]+nv.se != x[nv.fi]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 14208
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
count = 0
for i in range(n):
    sum = 0
    a = list(map(int, input().split()))
    for bi, ai in zip(b, a):
        sum += bi * ai
    sum += c
    if(sum > 0):
        count += 1
print(count)

Measured memory_bytes: 3060
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    rep(i, M) {
        cin >> a.at(i);
        cin >> b.at(i);
    }

    rep(i, N) {
        int count = 0;
        rep(j, M) {
            if (a.at(j) == (i + 1) || b.at(j) == (i + 1)) {
                count++;
            }
        }
        cout << count << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int k , x ,n ,s ;
    cin >> k>>x ;
    n=x-k+1;
    s=2*k-1;
    for (int i=0;i<s;i++){
         cout << n<<" ";
         n++;
         }
    return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> l(n), r(n);
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    l[i] = x - y;
    r[i] = x + y;
  }
  vector<int> idx(n);
  iota(begin(idx), end(idx), 0);
  sort(begin(idx), end(idx), [&](int i, int j) {
    return r[i] < r[j];
  });
  int mr = -0x3f3f3f3f, res = 0;
  for (int i : idx) {
    if (mr <= l[i]) {
      mr = r[i];
      ++res;
    }
  }
  cout << res << '\n';
}


Measured memory_bytes: 1408
A,B,C,D = map(int,list(input()))
def main(A,B,C,D):
    for i in range(2):
        ans1 =0
        if i == 0:
            ans1 = A + B
            s1 ='+'
        else:
            ans1 = A - B
            s1 ='-'
        for j in range(2):
            ans2 = 0
            if j == 0:
                ans2 = ans1 + C
                s2 ='+'
            else:
                ans2 = ans1 - C
                s2 ='-'
            for k in range(2):
                ans3 = 0
                if k == 0:
                    ans3 = ans2 + D
                    s3 ='+'
                else:
                    ans3 = ans2 - D
                    s3 ='-'
                if ans3 == 7:
                    print(str(A)+s1+str(B)+s2+str(C)+s3+str(D)+"=7")
                    return
main(A,B,C,D)   

Measured memory_bytes: 3064
N = int(input())
C = [int(input()) for _ in range(N)]

p = [0 for _ in range((2 * 10**5) + 1)]
dp = [0 for _ in range(N)]
p[C[-1]] = -1
dp[-1] = 1
for i in range(2, N + 1):
    if p[C[-i]] == 0 or p[C[-i]] == -i + 1:
        dp[-i] = dp[-i + 1]
    else:
        dp[-i] = (dp[-i + 1] + dp[p[C[-i]]]) % (10**9 + 7)
    p[C[-i]] = -i

ans = dp[0]
print(ans)


Measured memory_bytes: 20524
#include <bits/stdc++.h>
using namespace std;
int ans = 1e9;
int H,W;
int mp[52][52];
int nx,ny;
void func(int y,int x){
	//cout << y << ' ' <<x<<endl;
	if(mp[y][x] == 1){
		mp[y][x] = 2;
		func(y,x);
	}
	if(mp[y+1][x] == 1){
		mp[y+1][x] = 2;
		func(y+1,x);
	}
	if(mp[y][x+1] == 1){
		mp[y][x+1] = 2;
		func(y,x+1);
	}
	if(mp[y+1][x+1] == 1){
		mp[y+1][x+1] = 2;
		func(y+1,x+1);
	}
	if(mp[y-1][x] == 1){
		mp[y-1][x] = 2;
		func(y-1,x);
	}
	if(mp[y][x-1] == 1){
		mp[y][x-1] = 2;
		func(y,x-1);
	}
	if(mp[y-1][x-1] == 1){
		mp[y-1][x-1] = 2;
		func(y-1,x-1);
	}
	if(mp[y+1][x-1] == 1){
		mp[y+1][x-1] = 2;
		func(y+1,x-1);
	}
	if(mp[y-1][x+1] == 1){
		mp[y-1][x+1] = 2;
		func(y-1,x+1);
	}
}
void findL(){
	nx = -1;ny = -1;
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			if(mp[i][j] == 1){
				nx = j,ny = i;
				//cout <<nx<<ny<<endl;
				i = H; j = W;
			}
		}
	}
}
int main(){
	cin >> H>>W;
	while(W!=0||H!=0){
		for(int i = 0; i < 52;i++){
			for(int j = 0; j < 52; j++){
				mp[i][j] = 0;
			}
		}
		for(int i = 1; i <= H; i++){
			for(int j = 1; j <= W; j++){
				cin >> mp[i][j];
			}
		}
		int c = 0;
		findL();
		while(nx != -1 && ny != -1){
			func(ny,nx);
			c++;
			findL();
		}
		cout << c << endl;
		cin >> W >> H;
	}
	return 0;
}


Measured memory_bytes: 3216
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n == 0 || n == 1)return dp[n] = 1;
  if(dp[n] != -1)return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}

int main(){
  int n,i;
  for(i = 0 ; i < 50 ; i++){
    dp[i] = -1;
  }
  scanf("%d",&n);
  printf("%d\n",fib(n));
  return 0;
}



Measured memory_bytes: 2052