akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];

    map<int, int> mp;

    rep(i, n) {
        mp[a[i]-1]++;
        mp[a[i]]++;
        mp[a[i]+1]++;
    }

    int mx = 0;
    for (auto&& p : mp) {
        mx = max(mx, p.second);
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>

int main(){
  int A,B;
  scanf("%d%d",&A,&B);
  if(A < 6) printf("0\n");
  if(A >= 6 && A < 13) printf("%d\n",B / 2);
  if(A >= 13) printf("%d\n",B);
  return 0;
}

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

const int MAX_N = 305;

char board[2 * MAX_N][2 * MAX_N];
int32_t cnt[2 * MAX_N][2 * MAX_N];

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

	int32_t n;
	cin >> n;

	for(int32_t i = 1; i <= n; i++) {
		for(int32_t j = 1; j <= n; j++) {
			cin >> board[i][j];
			board[i + n][j] = board[i][j];
			board[i][j + n] = board[i][j];
			board[i + n][j + n] = board[i][j];
		}
	}

	for(int32_t i = 1; i <= 2 * n; i++) {
		for(int32_t j = 1; j <= 2 * n; j++) {
			for(int32_t p = 0; ; p++) {
				if(p >= n || i + p > 2 * n || j + p > 2 * n) {
					cnt[i][j] = p;
					break;
				}
				
				if(board[i + p][j] != board[i][j + p]) {
					cnt[i][j] = p;
					break;
				}
			}
		}
	}
	
	int32_t ans = 0;
	for(int32_t i = 1; i <= n; i++) {
		for(int32_t j = 1; j <= n; j++) {
			bool isOk = true;
			for(int32_t p = 0; p < n; p++) {
				if(cnt[i + p][j + p] < n - p) {
					isOk = false;
					break;
				}
			}

			if(isOk) {
				ans++;
			}
		}
	}

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



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

int main(void){
  int r, c;
  cin >> r >> c;
  int a[r][c], b[r+1][c+1];
  for (int x=0; x<=r; x++) {
    for (int y=0; y<=c; y++) {
      b[x][y] = 0;
    }
  }
  //入力&処理開始
  for (int d=0; d<r; d++) {
    for (int e=0; e<c; e++) {
      cin >> a[d][e]; // 入力
      b[d][e] = a[d][e]; // 表bにコピー
      b[r][e]+= a[d][e]; // 最右枠に追加
      b[d][c]+= a[d][e]; // 最下段の処理
      b[r][c]+= a[d][e]; // 右下枠に追加
    }
  }
  //入力&処理終了
  // cout << endl; // デバッグ用に空行を出力
  //出力開始
  for (int f=0; f<=r; f++) {
    for (int g=0; g<=c; g++) {
      cout << b[f][g];
      if (g!=c) {
        cout << ' ';
      }
    }
    cout << endl;
  }
  //出力終了
}



Measured memory_bytes: 3132
#include <iostream>

using namespace std;

//Compiler version g++ 6.3.0

int main()

{

	int money;	int s, a, ans;

	

	cin>>money;

	

	if(money>=500)

	{

		if(money/500==0)

		{

			ans= money/500 * 1000;

		}

		else if (money/500!=0){

			

			s=(money/500) * 1000;

			

			a= ((money%500)/5 )* 5;

			

			ans = s+a;

		}

	}

	else if (money<500)

	{

		ans = ((money%500)/5 )* 5;

	}

	

	cout<<ans;

    

}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(!n){
			break;
		}
		vector<int> score;
		int in;
		for(int i=0;i<n;i++){
			cin>>in;
			score.push_back(in);
		}
		sort(score.begin(),score.end());
		int sum=0;
		for(int i=1;i<score.size()-1;i++){
			sum+=score[i];
		}
		int avr=sum/(n-2);
		cout<<avr<<endl;
	}
	return 0;
}


Measured memory_bytes: 3160
#include<iostream>
using namespace std;
int main(){
	string s;
	cin>>s;
	int length=s.length();
	int max=length/2;
	int ans=0;
	for(int i=length-1;i>=0;i--){
		int ii=0;
		if((i%2)==0){
			ii=i/2;
		}else{
			continue;
		}
		char*temp=new char[i];
		int j=0;
		for(j=0;j<ii;j++){
			temp[j]=s[j];
		}
		bool check=true;
		for(int k=0;k<ii;k++){
			if(s[j+k]!=temp[k]){
				check=false;
				break;
			}
		}
		if(check){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define MOD 1000000007

using namespace std;
int main() {
    long long a, b, x;
    cin >> a >> b >> x;
    long long diminish = a - b;
    if (x < a) {
        cout << x%MOD << endl;
        return 0;
    }
    long long trade = (x-a) / diminish + 1;
    trade %= MOD;
    b %= MOD;
    x %= MOD;
    cout << (x + ((trade * b) % MOD)) % MOD << endl;
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin>>n;
	int a[n]; rep(i,n) cin>>a[i];
	int lm[n]={},rm[n]={};
	lm[0] = a[0];
	rm[n-1] = a[n-1];
	for(int i=1;i<n;i++) lm[i] = max(lm[i-1],a[i]);
	for(int i=1;i<n;i++) rm[n-1-i] = max(rm[n-i],a[n-1-i]);
	// rep(i,n) cout<<lm[i]<<" ";
	// rep(i,n) cout<<rm[i]<<" ";
	rep(i,n){
		int lmax=(i-1>=0?lm[i-1]:0);
		int rmax=(i+1<n?rm[i+1]:0);
		cout<<max(lmax,rmax)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el cout << "\n"
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);
ll n , m ,k;
ll nbr;
 vector<ll> mp[501501];
bool visited[501501];
vector <ll> dist; /// distance dans un arbre
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second > b.second);
}

void dfs(ll s)
{
    visited[s]=true; nbr++;
    dist[s]++;
    for (int i=0;i<mp[s].size();i++)
    {
        if (visited[mp[s][i]]==false)
        {
            dist[mp[s][i]]=dist[s];
            dfs(mp[s][i]);
        }
    }
}

bool valid(ll x,ll y)
	{
	    return ( x<n && y<m);
	}

int main()
{
	IOS;
    ll n;
    cin >> n;
    ll k;
    cin >> k;
    vector<ll> H;
    vector <ll> dp(n+1,0);
   // cout << dp[0];
    //cout << endl;
    for(int i=0;i<n;i++)
    {
        ll h;
        cin >> h;
        H.push_back(h);
    }
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(H[1]-H[0]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=dp[i-1]+abs(H[i-1]-H[i-2]);
        for(int j=2;j<=k;j++)
            {   if(i-1-j>=0)
                    dp[i]=min(dp[i],dp[i-j]+abs(H[i-1]-H[i-1-j]));}

    }
    /*for(int i=0;i<=n;i++)
        cout << dp[i] << " ";*/
    cout << dp[n];



    return 0;
}


Measured memory_bytes: 13944
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
ans=[0 for i in range(n)]
u=0
for i in range(n):
    if i%2==0:
        u+=lis[i]
    else:
        u-=lis[i]
u=u//2
ans[0]=u
#print(u)
for i in range(n-1):
    ans[i+1]=-ans[i]+lis[i]
for i in range(n):
    ans[i]*=2
print(*ans)
        

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


ll solve(ll n, vector<ll> heights) {
	vector<ll> dp(n, 0);
	dp[0] = 0;
	dp[1] = abs(heights[1] - heights[0]);
	for (int i = 2; i < n; ++i) {
		dp[i] = min(dp[i - 1] + abs(heights[i] - heights[i - 1]), dp[i - 2] + abs(heights[i] - heights[i - 2]));
	}
	return dp[n - 1];
}
int main() {


	ll n;
	cin >> n;
	vector<ll> heights(n, 0);
	for (int i = 0; i < n; ++i) {cin >> heights[i];}
	cout << solve(n, heights);
}


Measured memory_bytes: 5576
s = list(input())

ans = 0
for i in range(2**(len(s)-1)):
  p = ['']*len(s)
  f = ''
  for j in range(len(s)-1):
    if (i>>j & 1):
      p[j] = '+'
      
  for i in range(len(s)):
    f += s[i] + p[i]
  ans += eval(f)
  
print(ans)

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

bool check(ll X, ll K, vector<ll> &a, vector<ll> &f) {
    ll need = 0;
    rep(i, a.size()) {
        ll ok = X / f[i];
        if (ok < a[i]) need += a[i] - ok;
    }
    return need <= K;
}


int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N);
    vector<ll> f(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> f[i];

    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());

    ll ok = 1e13, ng = -1;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if (check(mid, K, a, f)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 3328
import collections
N = int(input())
a = sorted(list(map(int,input().split())))
c = collections.Counter(a)
cnt = 0
for i in c.most_common():
   # print(i)
    if i[0]<i[1]:
      cnt=cnt+i[1]-i[0]
    if i[0]>i[1]:
      cnt=cnt+i[1]
print(cnt)   

Measured memory_bytes: 21608
#include<bits/stdc++.h>
using namespace std;
const long long INF=1000000000;
typedef long long ll;
int main(){
   char s[3];
   int count = 0;
   for (int i = 0; i < 3;i++){
      cin>>s[i];
      if(s[i]=='1')
         count++;
   }
   cout << count << endl;
   return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 1_000_000_007

def permanent(A):
    # O(N2^N) algorithm
    N = A.shape[0]

    # 残す列の集合 -> 行の和の積
    products = np.ones(1 << N, np.int64)
    for r in range(N):
        # r行目の計算をする
        row_sum = np.zeros(1 << N, np.int64)
        for n in range(N):
            row_sum[1 << n:1 << n + 1] = row_sum[:1 << n] + A[r, n]
        products *= row_sum
        products %= MOD

    # 符号をかけて集計する
    sgn = np.ones(1 << N, np.int64)
    for n in range(N):
        sgn[1 << n:1 << n + 1] = -sgn[:1 << n]

    products = products * sgn[::-1]

    perm = products.sum() % MOD
    return perm

N = int(readline())
A = np.array(read().split(), np.int64).reshape(N, N)

print(permanent(A))

Measured memory_bytes: 92216
Scanf.scanf "%d %d" (fun a b ->
    let calc k =
        let rec loop i acc =
            if i = 42 then acc else
                let l = 1 lsl i in
                let m = l + l in
                let c = k mod m in
                if c < l       then loop (i + 1) acc else
                if c mod 2 = 1 then loop (i + 1) acc
                               else loop (i + 1) (acc lor l)
        in
        let q = k mod 4 in
        let acc = if q = 1 || q = 2 then 1 else 0 in
        loop 1 acc 
    in
    Printf.printf "%d\n" @@ if a = 0 then calc b else calc b lxor calc (a - 1);
)

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fori(i,s,n) for(ll i=s;i<=n;i++)
#define ford(j,s,n) for(int i=n;i>=s;i--)
#define pb push_back
#define TEST int t; cin>>t; for(int T=1;T<=t;T++)
const int MAX = 1000001; 
struct Query 
{ 
    int l, r, idx; 
}; 
  
// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
  
// updating the bit array 
void update(int idx, int val, vector<int> &bit, int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
int query(int idx, vector<int> &bit, int n)
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(vector<int> arr, int n,vector<Query> queries, int q) 
{ 
    // initialising bit array 
    vector<int> bit(n+1,0); 
    //memset(bit, 0, sizeof(bit)); 
  
    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    vector<int> last_visit(MAX,-1); 
    
  
    // answer for each query 
    vector <int> ans(q,0); 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    {   if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
  
        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
  
        // If i is equal to r of any query  store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit, n)- 
                     query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
  
    // print answer for each query 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    vector<Query> q(m);
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<m;i++){
        cin>>q[i].l>>q[i].r;
        q[i].idx=i;
        q[i].l--;
        q[i].r--;
    }
    sort(q.begin(), q.end(), cmp); 
    answeringQueries(a, n, q, m); 
    return 0;
}


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

int main() {

	vector<int> prim(1000000+1);
	fill(prim.begin(),prim.end(),1);
	prim[0]=0;
	prim[1]=0;
	for(int i=2;i<prim.size();i++){
		if( prim[i]!=0 ){
			int x=i+i;
			while(x<prim.size()){
				prim[x]=0;
				x+=i;
			}
		}
	}

	while(true)
	{
		int N,X;
		cin >> N >> X;
		if(N==0 && X==0)break;
		
		vector<int> food;
		for(int i=0;i<N;i++){
			int m;
			cin >> m;
			food.push_back(m);
		}
		
		vector<int> num(X+1);
		fill(num.begin(),num.end(),0);
		for(int i=0;i<N;i++){
			if( food[i]<=X ){
				num[ food[i] ]=1;
			}
		}
		for(int i=0;i<=X;i++){
			if( num[i]!=0){
				for(int j=0;j<N;j++){
					if( i+food[j]<=X){
						num[i+food[j]]=1;
					}
				}
			}
		}
		int ans=-1;
		for(int x=X;x>=0;x--){
			if( prim[x]==1 && num[x]!=0){
				ans = x;
				break;
			}			
		}
		if(ans>0){
			cout << ans << endl;
		}else{
			cout << "NA" << endl;
		}
	}
	


	return 0;
}

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

#define int long long
#define ll long long
#define pb push_back

main(){
    int k, n;
    cin >> k >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    int maxi = 0;
    for(int i = 0; i < n - 1; i++){
        maxi = max(maxi, a[i + 1] - a[i]);
    }
    maxi = max(maxi, a[0] + (k - a[n - 1]));
    cout << k - maxi;
}


Measured memory_bytes: 1920
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定
#include <list> //前後に数値を入れれる配列



#define REP(i,m,n) for(int i = (int) (m);i < (int) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
ll chg_DegRad(int deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(int rad) {
	return rad * 180.0 / PI;
}

//提出コード↓

ll a, b;


int main() {
	cin >> a >> b;
	if (a <= 8 && b <= 8) cout << "Yay!" << endl;
	else cout << ":(" << endl;





	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	if(c=='-')f=-1,c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d r()
ll n,ans;
double dd;
double dis(double x1,double y1,double x2,double y2){
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
	n=d;
	cin>>dd;
	f(i,1,n){
		double x,y;
		cin>>x>>y;
		if(dis(x,y,0,0)<=dd)ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3848
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
#define MOD (1000000007)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll DP[401][401];
ll a[400];
ll sa[401];
ll solve(int i, int j){
    if (DP[i][j] != -1){
        return DP[i][j];
    }
    if (j-i == 1){
        return 0;
    }else{
        DP[i][j] = solve(i,i+1) + solve(i+1,j);
        REPS(k, j-i-1) {
            chmin(DP[i][j], solve(i,i+k) + solve(i+k,j));
        }
        DP[i][j] += sa[j] - sa[i];

        return DP[i][j];
    }
}

int main() {
    int N;
    cin >> N;
    sa[0] = 0;
    REP(i, N) {
        cin >> a[i];
        sa[i+1] = sa[i] + a[i];
    }
    REP(i, N+1) {
        REP(j, N+1) {
            DP[i][j] = -1;
        }
    }
    cout << solve(0, N);
    
}

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

int main() 
{
    int i;
    int n =0;
    int arr[10000];
    for(i=1;i<10001;i++)
    {
    cin>>arr[i];
    n++;
    if(arr[i] == 0)
		{
			goto Exit;
		}
    }
      Exit:;
        for(int j=1; j<n;j++)
        {
            cout<<"Case "<<j<<":"<<" "<<arr[j]<<endl;
        }
}


Measured memory_bytes: 3140
#組み合わせ個数
def choose(n, r, mod)
  return 0 if not (0 <= r and r <= n)
  return 1 if r == 0 or r == n
  fact(n, mod) * inverse(fact(r, mod) * fact(n-r, mod) % mod, mod) % mod
end
#階乗(MODあり)
@fact = [1]
def fact(n, mod)
  if n > @fact.size then
    f = @fact[-1]
    (@fact.size+1..n).each{|i|
      f = (f * i) % mod
      @fact << f
    }
  end
  @fact[n-1]
end
#逆元(MODあり)
def inverse(x, mod)
  pow(x, mod-2, mod)
end
#べき乗(MODあり)(繰り返し２乗法)
def pow(x, n, mod)
  ans = 1
  while n > 0
    ans = ans * x % mod if n.odd?
    x = x * x % mod
    n >>= 1
  end
  ans
end

E = Hash.new{|h, k| h[k] = []}
MOD = 10 ** 9 + 7
N, K = gets.chomp.split(" ").map(&:to_i)
(N - 1).times{
  a, b = gets.chomp.split(" ").map(&:to_i)
  E[a] << b
  E[b] << a
}

q = []
done = Array.new(N + 1, false)
q.push([1, 0])
M = Hash.new{|h, k| h[k] = 0}
until(q.empty?) do
  a, d = q.pop
  done[a] = true
  m = 0
  E[a].each{|b|
    if !done[b] then
      q.push([b, d + 1])
      m += 1
    end
  }
  M[m] += 1 if d > 0
end

ans = choose(K, 1, MOD)
m = E[1].size
ans = (ans * choose(K - 1, m, MOD)) * fact(m, MOD) % MOD if m > 0
M.each{|k, v|
  next if k == 0
  ans = (ans * pow((choose(K - 2, k, MOD) * fact(k, MOD)) % MOD, v, MOD)) % MOD
}

puts ans


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

using namespace std;
using ll = long long;

ll x, y;
ll ans = 2e15;

void dfs(ll cur , ll depth, ll tim) {

    if(cur == y)ans = min(ans, tim);
    if(depth == 10)return;

    dfs(-cur, depth + 1, tim + 1);
    if(cur < y) {
        dfs(y, depth + 1, tim + (y - cur));
    }

    if(cur < -y) {
        dfs(-y, depth + 1, tim + (-y - cur));
    }
}

int main()
{
    cin >> x >> y;
    dfs(x, 0, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int X = sc.nextInt();
    	List<Integer> glad = new ArrayList<>();
    	for (int i = 0; i < N; i++) {
			glad.add(sc.nextInt());
		}
    	Collections.sort(glad);
    	int count = 0;
    	for (Integer i : glad) {
    		if (i <= X) {
    			X -= i;
    			count++;
    		} else if (X < i) {
    			X = 0;
    			break;
    		}
    	}
    	if (X != 0) {
    		count--;
    	}
    	System.out.println(count);
    }
}

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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;
#define fastio ios_base::sync_with_stdio(false); \
		cin.tie(0);							     \
		cout.tie(0);
#define sz(arr) (ll)arr.size()

using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const double PI = 4.0 * atan(1.0);

ll powmod(ll a, ll b, const ll MOD) { ll res = 1; a %= MOD; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % MOD; a = a * a % MOD; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
/*ll f[200001];
ll kCn(ll k, ll n) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }*/


int main() {
	//#ifndef ONLINE_JUDGE
	//	(void)freopen("input.txt", "r", stdin);
	//	(void)freopen("output.txt", "w", stdout);
	//#endif // !ONLINE_JUDGE
	fastio;
	int r;
	cin >> r;
	cout << 2 * PI * r;
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

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

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    ll A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A);
    rep(i, A) { 
        cin >> s[i];
    }
    s.push_back(-1000000000000);
    s.push_back(1000000000000);
    vector<ll> t(B);
    rep(i, B) { 
        cin >> t[i];
    }
    t.push_back(-1000000000000);
    t.push_back(1000000000000);
    sort(all(s));
    sort(all(t));
    rep(i, Q) {
        ll x;
        cin >> x;
        auto sleft_iter = lower_bound(all(s), x);
        sleft_iter--;
        ll sleft = s[distance(s.begin(), sleft_iter)];
        ll sright = *upper_bound(all(s), x);

        auto tleft_iter = lower_bound(all(t), x);
        tleft_iter--;
        ll tleft = t[distance(t.begin(), tleft_iter)];
        ll tright = *upper_bound(all(t), x);

        vector<ll> tmp;
        tmp.push_back(abs(sright-x) + abs(sright-tright));
        tmp.push_back(abs(tright-x) + abs(tright-sright));
        tmp.push_back(abs(sright-x) + abs(sright-tleft));
        tmp.push_back(abs(tright-x) + abs(tright-sleft));
        tmp.push_back(abs(sleft-x) + abs(sleft-tleft));
        tmp.push_back(abs(tleft-x) + abs(tleft-sleft));
        tmp.push_back(abs(sleft-x) + abs(sleft-tright));
        tmp.push_back(abs(tleft-x) + abs(tleft-sright));
        sort(all(tmp));
        print(tmp[0]);
    }
    return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
using namespace std;
using ll=long long;
using R=double;

int find2(ll a){
	int count = 0;
	while(a%2!=1){
		a = a/2;
		count++;
	}
	return count;
}

int main(){
	int N,K;
	cin >> N >> K;
	int A[N+3]={0};
	for(int i = 0; i < N; i++){
		int x;
		cin >> x;
		A[x]++;
	}

	sort(A, A+N+3, greater<int>());

	int result = 0;
	for(int i = K; i < N; i++){
		//printf("%d\n",A[i]);
		result += A[i];
	}

	cout << result << endl;
	return 0;

}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i,e,n) for(int i=e; i<n; i++)

using namespace std;

int main()
{
    int W , H , N;
    cin >> W >> H >> N;

    vector<vector<bool>> b(H,vector<bool>(W));

    for(int i=0; i<N; i++){
        int x,y,a;
        cin >> x >> y >> a;

        if(a == 1){
            rep(h,0,H){
                rep(w,0,x){
                    b.at(h).at(w) = true;
                }
            }
        }
        if(a == 2){
            rep(h,0,H){
                rep(w,x,W){
                    b.at(h).at(w) = true;
                }
            }  
        }
        if(a == 3){
            rep(h,0,y){
                rep(w,0,W){
                    b.at(h).at(w) = true;
                }
            }
        }
        if(a == 4){
            rep(h,y,H){
                rep(w,0,W){
                    b.at(h).at(w) = true;
                }
            }
        }    
    }

    int cnt=0;
    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
            if(b.at(h).at(w) == false)
            cnt++;
        }
    }

    cout << cnt << endl;
}

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

const ll mod = 1e9 + 7;

ll fpow(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = ret * a %mod; a = a * a % mod; b >>= 1; } return ret; }

int main() {
	ll n, k; cin >> n >> k;
	ll gcd[k+1] = {};
	for (int i = 1; i <= k; i++)
		gcd[i] = fpow(k / i, n);
	for (int i = k / 2; i >= 1; i--)
		for (int j = i + i; j <= k; j += i)
			gcd[i] -= gcd[j];
	for (int i = 1; i <= k; i++)
		gcd[i] = i * gcd[i] % mod;
	cout << accumulate(gcd + 1, gcd + 1 + k, 0LL) % mod;
}

Measured memory_bytes: 4408
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
ll a[100];
ll n;
pair<ll, ll> dp[100][2];
int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    cin >> n;

    FOR(i,1,n) cin >> a[i];

    dp[0][0] = {1000, 0};
    dp[0][1] = {1000, 0};

    FOR(i,1,n){
        dp[i][0] = dp[i-1][0].first > dp[i-1][1].first + dp[i-1][1].second * a[i] ? dp[i-1][0]: make_pair(dp[i-1][1].first + dp[i-1][1].second * a[i], 0LL);
        dp[i][1] = dp[i-1][1].second > dp[i-1][0].first / a[i]? dp[i-1][1] : make_pair(dp[i][0].first - (dp[i-1][0].first/a[i]) *a[i], dp[i-1][0].first/a[i]);
    }

    cout << dp[n][0].first << endl;

    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <ctype.h>
#include <string.h>
 
int
main (
  int   argc,
  char *argv[ ]
  )
{
  int res = 0;
  char w[ 16 ], *p;
 
  scanf ( "%s", w );
  for ( p = w; *p != '\0'; ++p )
  {
    *p = tolower ( *p );
  }
 
  for ( ; ; )
  {
    char t[ 1024 ], *p;
 
    scanf ( " %s", t );
    if ( !strcmp ( t, "END_OF_TEXT" ) ) break ;
 
    for ( p = t; *p != '\0'; ++p )
    {
      *p = tolower ( *p );
    }
    res += !( strcmp ( t, w ) );
  }
 
  printf ( "%d\n", res );
 
  return ( 0 );
}

Measured memory_bytes: 552
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


move = None
tx = None
ty = None


@mt
def slv(S, x, y):
    tx = x
    ty = y
    move = list(map(lambda x: len(x), S.split('T')))
    xm = [move[0]]
    for i in range(2, len(move), 2):
        xm_ = []
        for x in xm:
            xm_.append(x + move[i])
            xm_.append(x - move[i])
        xm = set(xm_)

    ym = [0]
    for i in range(1, len(move), 2):
        ym_ = []
        for y in ym:
            ym_.append(y + move[i])
            ym_.append(y - move[i])
        ym = set(ym_)

    return 'Yes' if tx in xm and ty in ym else 'No'


def main():
    S = read_str().strip()
    x, y = read_int_n()
    print(slv(S, x, y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6596
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <stdbool.h>

void reverse(char str[], int length)
{
    int start = 0;
    int end = length -1;
    while (start < end)
    {
        int temp;
        temp=*(str+start);
        *(str+start)=*(str+end);
        *(str+end)=temp;

        start++;
        end--;
    }
}

char* inttochar(int num, char* str, int base)
{
    int i = 0;
    bool p = false;

    if (num == 0)
    {
        str[i++] = '0';
        str[i] = '\0';
        return str;
    }

    if (num < 0 && base == 10)
    {
        p = true;
        num = -num;
    }

    while (num != 0)
    {
        int rem = num % base;
        str[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0';
        num = num/base;
    }

    if (p){
        str[i++] = '-';
    }

    str[i] = '\0';

    reverse(str, i);

    return str;
}
int main(){
    int a,b,l;
    char c[100];
    scanf("%d%d",&a,&b);

    inttochar(a,c,b);

    l=strlen(c);

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

return 0;
}


Measured memory_bytes: 128
N = int(input())
W = list(map(int, input().split()))

S1 = 0
S2 = 0
Z = 10000
for i in range(N):
    for j in range(i+1):
        S1 = S1+W[j]
    for k in range(i+1, N):
        S2 = S2+W[k]
    if(Z > abs(S1-S2)):
        Z = int(abs(S1-S2))
    S1 = 0
    S2 = 0

print(Z)

Measured memory_bytes: 3060
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
  
#define int long long int 
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

double EPS = 1e-9; 
int INF = 1000000005; 
long long INFF = 1000000000000000005LL;
const int mod = 1e9 + 7; 

//#define CI cpp_int
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define RESET(a, b) memset(a, b, sizeof(a)) 
#define deb(...) cerr << "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define size(v) (int)v.size() 
#define endl "\n"
#define SINT int32_t
#define UMO unordered_map
#define USO unordered_set
#define UB(v, n) upper_bound(ALL(v), n)
#define LB(v, n) lower_bound(ALL(v), n)
#define to_bin(b, n) bitset<b>(n) // Provide binary representation of a Number
#define setBits(n) popcount(n) // count Set Bits in a Number
#define MX *max_element
#define MN *min_element
#define TC int t; cin >> t; while (t--) 
int popcount(uint32_t n) {

    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + ((n >> 4) & 0xF0F0F0F)) * 0x1010101) >> 24;
}

void Panda() {
    char b;
    cin >> b;
    if(b == 'C' || b == 'G') {
        b == 'C'? cout << 'G' << endl : cout << 'C' << endl;
    } else {
        b == 'T'? cout << 'A' << endl : cout << 'T' << endl;
    }
}
  
int32_t main() {
 
    FAST;

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

    return 0; 
} 

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

typedef long long ll;

int main() {
    ll N, K;
    ll ans = 10000000000000001;
    cin >> N >> K;
    vector<ll>x(N);
    for (ll i = 0; i < N; i++) {
        cin >> x[i];
    }

    for (ll l = 0; l < N-K+1; l++) {
        ll r = l+K-1;
        ll cost1, cost2;
        cost1 = abs(x[l]) + abs(x[r]-x[l]);
        cost2 = abs(x[r]) + abs(x[r]-x[l]);
        ans = min({ans, cost1, cost2});
    }

    cout << ans << endl;
}


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

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

  long long p1 = 1, p2 = 1, ans;
  if (abs(N - M) <= 1) {
    const int MOD = 1000000007;
    for (int i = N; i > 0; i--) p1 = (p1 % MOD * i % MOD) % MOD;
    for (int i = M; i > 0; i--) p2 = (p2 % MOD * i % MOD) % MOD;
    ans = (p1 % MOD * p2 % MOD) % MOD;

    if (abs(N - M) == 0) ans = (ans % MOD * 2 % MOD) % MOD;
  } else ans = 0;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  ll result = 0;
  REP(i, 1, N+1) {
    if (i % 3 == 0 || i % 5 == 0) continue;
    result += i;
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 3652
object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input:String):String={
    f(input.split("\n")(1).split(" ").map(_.toInt).toList,0).toString()
  }

  def f(list:List[Int],count:Int):Int={
    if(list.forall(_%2==0)){
      f(list.map(_/2),count+1)
    }else{
      count
    }
  }

  val tests=List("""3
8 12 40""" -> """2""",
    """4
5 6 8 10""" -> """0""",
"""6
382253568 723152896 37802240 379425024 404894720 471526144"""->"""8""");

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}.zipWithIndex.map{case ((input,outputExpect),i)=>{
      val output=solve(input).trim();
      s"test${i+1}:"+(if(output==outputExpect){
        "Passed"
      }else{
        s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
      })
    }}.mkString("\n");
  }
}

Measured memory_bytes: 25424
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;
int main(int argc, char const *argv[]) {
  int N;
  cin >> N;

  vector<long long> X(N);
  vector<long long> sortedX(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    sortedX[i] = X[i];
  }
  sort(sortedX.begin(), sortedX.end());

  map<int, long long> mp;
  for (int i = 1; i <= N; i++) {
    if (i <= N / 2) {
      mp[sortedX[i - 1]] = sortedX[N / 2 + 1 - 1];
    } else {
      mp[sortedX[i - 1]] = sortedX[N / 2 - 1];
    }
  }

  for (int i = 0; i < N; i++) {
    cout << mp[X[i]] << "\n";
  }

  return 0;
}


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

int main(){
    int64_t H,W;
    cin >> H >> W;
    int64_t ans;
    if (H == 1 || W == 1){
        cout << 1 << endl;
    }
    else if (H % 2 == 0 || W % 2 == 0){
        cout << H * W / 2 << endl;
    }
    else {
        cout << (H * W + 1) / 2 << endl;
    }
}

Measured memory_bytes: 256
using System;

namespace atCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            long min = long.Parse(input[0]);
            long max = long.Parse(input[1]);
            long div1 = int.Parse(input[2]);
            long div2 = int.Parse(input[3]);

            long count = max - min + 1;
            long num_div1 = GetMultiples(min, max, div1);
            long num_div2 = GetMultiples(min, max, div2);
            long num_dup = GetMultiples(min, max, GetLeastCommonMultiple(div1,div2));

            long result = count - num_div1 - num_div2 + num_dup;
            Console.WriteLine(result);
        }

        //min-max間のdivの倍数の数
        static long GetMultiples(long min,long max, long div)
        {
            long minmultiple = min + (min % div == 0 ? 0 : (div - min % div));
            long maxmultiple = max - max % div;
            return (maxmultiple - minmultiple) / div + 1;
        }

        //最小公倍数
        static long GetLeastCommonMultiple(long a, long b)
        {
            long x = a * b;
            if (a < b)
            {
                long tmp = a;
                a = b;
                b = tmp;
            }

            /* ユークリッドの互除法 */
            long r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return x/b;
        }
    }
}


Measured memory_bytes: 11092
#include <cstdio>
#define p 1000000007

inline int add(int x, int y) { return (x += y) >= p ? x - p : x; }
inline int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }
inline int mul(int x, int y) { return (long long)x * y % p; }
inline int power(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = mul(ans, x); x = mul(x, x); } return ans; }
inline int inv(int x) { return power(x, p - 2); }

inline int fac(int n) { int ans = 1; for (int i = 1; i <= n; ++i) ans = mul(ans, i); return ans; }
inline int C(int n, int k) { int ans = 1; for (int i = n - k + 1; i <= n; ++i) ans = mul(ans, i); return mul(ans, inv(fac(k))); }

int n, a, b;

int main() {
    scanf("%d%d%d", &n, &a, &b);
    printf("%d\n", sub(power(2, n), add(add(C(n, a), C(n, b)), 1)));
    return 0;
}


Measured memory_bytes: 128
s=list(input())
ans = 0
if s[0]== "S":
  if s[1]=="S":
    if s[2]=="S":
      ans=0
    else:
      ans=1
  else:
    if s[2]=="S":
      ans = 1
    else:
      ans = 2
else:
  if s[1]=="S":
    ans=1
  else:
    if s[2]=="S":
      ans=2
    else:
      ans=3
print(ans)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
using namespace std;
vector<int> vis;
vector<int> siz;
vector<vector<int>> ed;
int dfs(int u){
    if(vis[u]==2){
        return siz[u];
    }
    if(ed[u].size()==0){
        vis[u]=2;
        return siz[u]=0;
    }
    vis[u]=1;
    int maxi=0;
    for(auto x:ed[u]){
       maxi=max(maxi,dfs(x));
    }
    vis[u]=2;
    maxi++;
    return siz[u]=maxi;
}
int main(){
    int n,m;
    cin>>n>>m;
    vis.assign(n,0);
    siz.assign(n,0);
    ed.assign(n,vector<int>(0));
    for(int i=0;i<m;i++){
        int c,d;
        cin>>c>>d;
        c--;d--;
        ed[c].push_back(d);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(vis[i]==0){
            int l =dfs(i);
            ans=max(l,ans);
        }
    }
   // for(int i=1;i<=n;i++)cout<<siz[i]<<endl;
    cout<<ans<<endl;
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
long long k,dp[33][22],d[33][22];
int main()
{
	cin>>k;
	for(int i=1;i<10;i++)
	{
		dp[1][i]=1;
	}
	for(int i=1;i<=20;i++)
	{
		for(int j=0;j<=9;j++)
		{
			if(j!=0)
			{
				dp[i+1][j-1]+=dp[i][j];
			}
			dp[i+1][j]+=dp[i][j];
			if(j!=9)
			{
				dp[i+1][j+1]+=dp[i][j];
			}
		}
	}
	for(int i=0;i<10;i++)
	{
		d[1][i]=1;
	}
	for(int i=1;i<=20;i++)
	{
		for(int j=0;j<=9;j++)
		{
			if(j!=0)
			{
				d[i+1][j-1]+=d[i][j];
			}
			d[i+1][j]+=d[i][j];
			if(j!=9)
			{
				d[i+1][j+1]+=d[i][j];
			}
		}
	}
	for(int i=1;;i++)
	{
		long long nw=0;
		for(int j=0;j<=9;j++)
		{
			nw+=dp[i][j];
		}
		if(k>nw)
		{
			k-=nw;
			continue;
		}
        if(k==nw)
        {
        	for(int j=1;j<=i;j++)
        	{
        		cout<<9;
			}
			cout<<endl;
			return 0;
		}
		int lt=-1;
		for(int j=1;j<=i;j++)
		{
			long long cnt=0;
			bool ok=true;
//			cout<<endl<<k<<endl;
			if(k==0)
			{
				cout<<0;
				continue;
			}
			if(j==1)
			{
				for(int kk=1;kk<=9;kk++)
				{
					cnt+=d[i-j+1][kk];
					if(cnt>=k)
					{
						ok=false;
						cout<<kk;
						lt=kk;
						k-=cnt-d[i-j+1][kk];
						break;
					}
				}
				if(ok==true)
				{
					k-=cnt-d[i-j+1][9];
					cout<<9;
					lt=9;
				}
			}
			else
			{
				if(lt!=0)
				{
					cnt+=d[i-j+1][lt-1];
				}
				if(cnt>=k)
				{
					cout<<lt-1;
					k-=cnt-d[i-j+1][lt-1];
					lt--;
					continue;
				}
				cnt+=d[i-j+1][lt];
				if(cnt>=k)
				{
					cout<<lt;
					k-=cnt-d[i-j+1][lt];
					continue;
				}
				cnt+=d[i-j+1][lt+1];
				cout<<lt+1;
				k-=cnt-d[i-j+1][lt+1];
				lt++;
			}
		}
		cout<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8

n = int(input())
a,b = map(int,input().split())
p = list(map(int,input().split()))

p.sort()

cnt = [0,0,0]

for i in range(0,n):
    if(p[i] <= a):
        cnt[0]+=1
    elif(a < p[i] <= b):
        cnt[1]+=1
    else:
        cnt[2]+=1

#print(cnt)
print(min(cnt))

Measured memory_bytes: 3064
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  int A, B;
  int K;

  sc.scan(A, B, K);

  int cnt = 0;
  double[1000000] num = new double[1000000];


  foreach_reverse (i; 1 .. 101) {
    if (A % i == 0 && B % i == 0) {
      num[cnt] = i;
      cnt++;
    }
  }

  writeln(num[K - 1]);
}


Measured memory_bytes: 17916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5,inf=1e18;
ll l[N],r[N],c[N],dp[N];
vector<ll> ent[N],ext[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m;cin>>n>>m;
    for(ll i=1;i<=m;i++){
        cin>>l[i]>>r[i]>>c[i];
        ent[r[i]].push_back(i);
        ext[l[i]].push_back(i);
    }
    for(ll i=1;i<n;i++)dp[i]=inf;
    multiset< pair<ll,ll> > st;
    for(ll i=n;i>=1;i--){
        if(!st.empty())dp[i]=min(dp[i] , st.begin()->first);
        for(auto &id:ent[i])st.insert({dp[r[id]]+c[id],id});
        for(auto &id:ext[i])st.erase({dp[r[id]]+c[id],id});
    }
    if(dp[1]>=inf)cout<<"-1";
    else cout<<dp[1];
}

Measured memory_bytes: 16000
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k;
	multiset<int> s;
	multiset<int>::iterator it;
	cin >> n;
	vector<int> a(n), ans(n);
	for (i = 0; i < n; i++) {
		cin >> a[i];
		s.insert(a[i]);
	}
	for (i = 0; i < n; i++) {
		it = s.find(a[i]);
		s.erase(it);

		ans[i] = *s.rbegin();

		s.insert(a[i]);
	}

	for (i = 0; i < n; i++) cout << ans[i] << "\n";

	return 0;
}



Measured memory_bytes: 12544
n,m=map(int,input().split())
a=[]
b=[]
c=[]
d=[]

for i in range(n):
    li=list(map(int,input().split()))
    a.append(li[0])
    b.append(li[1])
for i in range(m):
    li=list(map(int,input().split()))
    c.append(li[0])
    d.append(li[1])

def man(x1,y1,x2,y2):
    return(abs(x1-x2)+abs(y1-y2))

for i in range(n):
    distance=10**9
    for j in range(m):
        if distance!=min(distance,man(a[i],b[i],c[j],d[j])):
            point=j+1
            distance=min(distance,man(a[i],b[i],c[j],d[j]))

    print(point)



Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
 
int main(){
    char word[11];
    char text[100];
    int count = 0;
    scanf("%s", word);
    
    while(1){
        scanf("%s", text);
        
        if(strcmp(text, "END_OF_TEXT") == 0){
          break;
        }
        
        for(int i=0; text[i]!='\0'; i++){
            text[i] = tolower(text[i]);
        }
        
        if(strcmp(word, text) == 0){
            count++;
        }
    }
    printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 2096