akhauriyash/Code-Regression huggingface dataset:
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

ll dp[200010][5];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int l;
    cin >> l;
    vi a(l);
    cin >> a;
    rep(i, 200010) rep(j, 5) dp[i][j] = linf;
    dp[0][0] = 0;
    rep(i, l + 1) rep(j, 5) {
            if (j + 1 < 5) chmin(dp[i][j + 1], dp[i][j]);
            if (i == l) continue;
            int now;
            if (j == 0 or j == 4) now = a[i];
            else if (j == 1 or j == 3) {
                if (a[i] & 1) now = 1;
                else now = (a[i] == 0 ? 2 : 0);
            } else now = 1 - (a[i] & 1);
            chmin(dp[i + 1][j], dp[i][j] + now);
        }
    cout << dp[l][4] << endl;
}


Measured memory_bytes: 11904
import math
import fractions
import sys
import itertools
import numpy as np
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))

r=input1()
print(r**2)

Measured memory_bytes: 15360
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
typedef long long ll;
typedef long double ld;
#define rep(i,a)  for(ll i=0; i< a; i++)
#define pb push_back
#define vl vector<ll>
#define trace(x)  cerr << #x << ": " << x << endl;
void __print(ll x) {cerr << x;}
void __print(ld x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const ll N=1e9+7;

int main()
{
	fast;
	ll n;cin>>n;
	vector<ll> v(n);vector<ll> pref(n);
	for(ll i=0;i<n;i++)
	{
		cin>>v[i];
		pref[i]=v[i];
		if(i)pref[i]+=pref[i-1];
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		ll z=pref[n-1]-pref[i];z%=N;
		z*=v[i];
		z%=N;ans+=z;ans%=N;
	}
	cout<<ans;


}

Measured memory_bytes: 6360
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
	int n, i;
	string s;
	set<string> ss;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		cin >> s;
		ss.insert(s);
	}

	printf("%d\n", ss.size());

	return 0;
}

Measured memory_bytes: 19416
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)
	if strings.HasPrefix(t, s) && len(s)+1 == len(t) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1756
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<bool>> e(n, vector<bool>(n, false));
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		e[a][b] = true;
		e[b][a] = true;
	}

	vector<int> v(n);
	rep(i, n) v[i] = i;

	int ans = 0;
	do {
		if (v[0] != 0) break;
		bool flag = true;
		rep(i, n - 1) {
			if (!e[v[i]][v[i + 1]]) flag = false;
		}
		if (flag) ans++;
	} while (next_permutation(v.begin(), v.end()));
	cout << ans << endl;
}

Measured memory_bytes: 256
N, *A = map(int, open(0).read().split())

C = {}
for a in A:
    if a in C.keys():
        C[a] += 1
    else:
        C[a] = 1
B = list(C.items())
B.sort(key=lambda x: x[0])

ans = 0
for i in range(len(B)):
    count = B[i][1]
    if i+1 < len(B) and B[i+1][0] == B[i][0]+1:
        count += B[i+1][1]
        if i+2 < len(B) and B[i+2][0] == B[i][0]+2:
            count += B[i+2][1]
    ans = max(ans, count)
print(ans)

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

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

	int res = 1e9;
	for (int i = 1; i <= N/2; i++){
		int a = i;
		int b = N - a;
		int sa = 0, sb = 0;
		while (a != 0){
			sa += a%10;
			a /= 10;
		}
		while (b != 0){
			sb += b%10;
			b /= 10;
		}

		res = min(res, sa + sb);
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		if (N == 1) {
			System.out.println(1);
			return;
		}
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		int mp = Integer.signum(A[0] - A[1]);
		int count = 1;
		for (int i = 1; i < A.length; i++) {
			int sig = Integer.signum(A[i - 1] - A[i]);
			if (mp * sig < 0) {
				count++;
				mp = 0;
			} else if (mp == 0) {
				mp = sig;
			}
		}
		System.out.println(count);
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 52208
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n,h; cin>>n>>h;
	vector<int> a(n),b(n);
	int maxa=0;
	for(int i=0;i<n;i++) {
		cin>>a[i]>>b[i];
		maxa=max(maxa,a[i]);
	}
	sort(b.begin(),b.end(),greater<int>());
	int i=0;
	int ans=0;
	while(b[i]>maxa){
		h-=b[i];
		ans++;
		i++;
		if(h<=0){
			cout << ans << endl;
			return 0;
		}
	}
	ans+=h/maxa+(h%maxa>0?1:0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
def iread():
    return int(input())


def sread():
    return input()


def aread(t="int"):
    if t == "int":
        ret = [int(i) for i in input().split()]
    elif t == "str":
        ret = list(input())
    return ret


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


def main():
    k, x = scan()
    r = range(x - k + 1, x + k, 1)
    for i in r:
        print('{} '.format(i), end="")
    print("")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
float ans;
int main() {
    int n; cin >> n;
    for(int i = 0; i < n; i++) {
        float a; cin >> a;
        ans += (1/a);
    }
    printf("%.5f", (1/ans));
    return 0;
}


Measured memory_bytes: 256
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

void start() {
	#ifndef ONLINE_JUDGE 
		freopen("in", "r", stdin); 
		freopen("out", "w", stdout); 
	#endif
}

int n, m;
string s;

int32_t main() {
    IOS;
    start();

    cin >> n >> m >> s;
    set<pair<int,int>> st;
    st.insert({0,0});

    int dp[n+2][2];
    dp[0][0] = 0;
    dp[0][1] = 0;

    for(int i = 1 ; i <= n ; i++) {
        if(s[i] == '1') {
            if(i >= m) {
                st.erase({dp[i - m][0], i - m});
            }
            continue;
        }
        if(!st.size()) {
            return cout << -1, 0;
        }
        auto it  = st.begin();
        dp[i][0] = (*it).first + 1;
        dp[i][1] = (*it).second;
        st.insert({dp[i][0],i});
        if(i>=m) {
            st.erase({dp[i - m][0], i - m});
        }
    }
    int pos = n;
    vector<int> v;
    while(pos != 0) {
        v.push_back(pos - dp[pos][1]);
        pos = dp[pos][1];
    }
    reverse(v.begin(), v.end());
    for(auto i: v)
        cout << i << " ";
}   

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

int main(){
	string str;
	cin>>str;
	if(str[0]==str[1]){
	  if(str[2]==str[3]&&str[0]!=str[2]){
	  	cout<<"Yes"<<endl;
	  	return 0;
	  }else{
		cout<<"No"<<endl;
	}
	}else if(str[0]==str[2]){
	  if(str[1]==str[3]&&str[0]!=str[1]){
	  	cout<<"Yes"<<endl;
	  	return 0;
	  }else{
		cout<<"No"<<endl;
	}
	}else if(str[0]==str[3]){
	  if(str[1]==str[2]&&str[0]!=str[1]){
	  	cout<<"Yes"<<endl;
	  	return 0;
	  }else{
		cout<<"No"<<endl;
	}
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main()
{
	int dp[10001];
	
	int m;
	while (scanf("%d", &m), m){
		dp[0] = 1;
		for (int i = 1; i <= 1000; i++){
			dp[i] = 0;
		}
		
		for (int i = 0; i < m; i++){
			int number, num;
			scanf("%d %d", &number, &num);
			
			for (int j = 1000; j >= 0; j--){
				if (dp[j]){
					for (int k = 1; k <= num; k++){
						dp[j + k * number] += dp[j];
					}
				}
				
			}
		}
		
		int g;
		scanf("%d", &g);
		for (int i = 0; i < g; i++){
			int n;
			scanf("%d", &n);
			
			printf("%d\n", dp[n]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1040
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = int.Parse(_[0]);
            var m = int.Parse(_[1]);

            var cn = n * (n - 1) / 2;
            var cm = m * (m - 1) / 2;
            Console.WriteLine(cn + cm);
        }
    }
}


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  
  if(s[2] == s[3] && s[4] == s[5])
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
  return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int Sum(const string&s){
  int n = (int)s.size();
  int sum = 0;
  for(int i = 0; i < n; ++i)sum += s[i] - '0';
  return sum;
}

int main(){
  int a,b; cin >> a >> b;
  cout << (a+b)%24 << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
	string s;
	cin >> s;
	int k;
	cin >> k;
	int n = s.size();
	vector<vll> dp(n + 1, vll(k + 1, vl(2)));
	dp[0][0][1] = 1;
	rep (keta, n) {
		int nketa = keta + 1;
		rep (j, k + 1) {
			rep (giri, 2) {
				if (dp[keta][j][giri] == 0) continue;
				rep (add, 10) {
					int ngiri = 0;
					if (giri and (s[keta] - '0') < add) continue;
					if (giri and (s[keta] - '0') == add) ngiri = 1;
					int nj = j;
					if (add != 0) nj++;
					if (nj > k) continue;
					dp[nketa][nj][ngiri] += dp[keta][j][giri];
				}
			}
		}
	}
	ll ans = dp[n][k][0] + dp[n][k][1];
	cout << dp[n][k][0] + dp[n][k][1] << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import Counter


def solve(N: int, A: "List[int]"):
    countA = Counter(A)
    A.sort()
    l = [True for _ in range(A[-1] + 1)]
    for i in range(N):
        j = 2
        while A[i] * j <= A[-1]:
            l[A[i] * j] = False
            j += 1
    cnt = 0
    for a in A:
        cnt += (l[a] and countA[a] == 1)
    print(cnt)




# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Measured memory_bytes: 184976
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a)&-(a))
#define clean(a,b) memset(a,b,sizeof(a))
const int mod = 1e9 + 7;
// const int inf=0x3f3f3f3f;
const int maxn = 2e5+9;

inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}

int _;

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
int main()
{
    ll a,b,b_;
    char k;
    scanf("%lld%lld%c%lld",&a,&b,&k,&b_);
    ll b__=b*100+b_;
    ll c=a*b__/100;
    printf("%lld\n",c);
    return 0;
}


Measured memory_bytes: 3748
n,k=map(int,input().split())

i=0

while k**i<=n:
  i+=1

result=""
while i>=0:
  result=result+str(n//k**i)
  n=n-(n//k**i)*k**i
  i=i-1

  
  
print(len(str(int(result))))
  

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N){
  int cnt = 0;
  REP1(i, N+1) {
    int cnt2 = 0;
    REP1(j, i+1) {
      cnt2 += i % j == 0;
    }
    if(cnt2 == 8 && i % 2 == 1) {
      cnt++;
    }
  }
  
  cout << cnt << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int solve(int n,string s)
{
	int m=s.size();
	vvl dp(n+1,vl(n+1));
	dp[0][0]=1;
	rep(i,n){
		rep(j,n){
			(dp[i+1][j+1]+=dp[i][j])%=MOD;
			if(j==0)
				(dp[i+1][j]+=dp[i][j])%=MOD;
			else
				(dp[i+1][j-1]+=dp[i][j]*2)%=MOD;
		}
	}
	return dp[n][m];
}

int main()
{
	for(int n;cin>>n && n;){
		string s; cin>>s;
		cout<<solve(n,s)<<endl;
	}
}


Measured memory_bytes: 195840
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int mm[100005];
int cnt[100005];

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

// #ifndef ONLINE_JUDGE
//     if(fopen("INPUT.txt","r"))
//     {
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//     }
// #endif  

    int n,m;
    cin>>n>>m;
    int x,y;
    for(int i=1;i<=n;i++)
        cnt[i]=1;
    mm[1]=1;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        cnt[x]--;
        cnt[y]++;
        if(mm[x])
        {
            mm[y]=1;
        }
        if(cnt[x]==0)
            mm[x]=0;
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        ans+=mm[i];

    cout<<ans;
} 
    
 


Measured memory_bytes: 5160
MOD = 10**9 + 7
def nCr(n, r, MOD):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
            result %= MOD

    return result
n, a, b = map(int,input().split())
ans = pow(2,n,MOD)-1-nCr(n,a,MOD)-nCr(n,b,MOD)
while ans < 0:
    ans += MOD
print(ans)


Measured memory_bytes: 107168
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define MOD 1000000007
#define REP(i,n) for(i=1;i<=n;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define vl vector<LL>
#define itr ::iterator it
#define lb lower_bound
#define ub upper_bound
#define LL long long
#define ULL unsigned long long
LL n,i,j,ans = 0;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s ;
    cin>>s ;
    if(s=="zyxwvutsrqponmlkjihgfedcba")
    {
        cout<<-1;
        return 0 ;
    }
    set<char> sett(all(s)) ;
    string temp = s ;
    for(char i='a';i<='z';i++)
    { if(sett.count(i)==0)
      {  temp.pb(i) ;
         cout<<temp ;
         return 0 ;
      }
    }
    string n,ans = "zyxwvutsrqponmlkjihgfedcba",temp1  ;
    for(int i=0;s[i];i++)
    {  if(s[i]=='z')
       {  temp1.pb(s[i]) ;
          n.pb(s[i]) ;
          continue ;
       }
       set<char> sett(all(n));
       for(char j=1+s[i];j<='z';j++)
       {   if(sett.count(j)==0)
           {   n.pb(j) ;
               ans = min(ans,n) ;

               break ;
           }
       }
       //if(n>s and n<ans and sett.size()==n.length())  ans = n ;
       temp1.pb(s[i]) ;
       //cout<<i<<" "<<ans<<endl;
       n = temp1 ;
    }
    cout<<ans ;

}
/*zyxwvutsrabcdefghiqponmlkj*/
/*mihuysacjrndqgbtzlpvxwfoek*/


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;


#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}

int main(){
  	string s;
    cin >> s;
    if(s=="ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC"<<endl;
    }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl;
  return 0;
}


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

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

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int x;
  cin >> x;
  cout << (x<1200 ? "ABC" : "ARC") <<endl;
}


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

int main()
{
    string S;
    cin >> S;
    int ans = 0;
    rep(i, 4)
    {
        if (S[i] == '+')
            ans++;
        else
            ans--;
    }
    cout << ans << endl;
}

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

using namespace std;

const int nax=1e6+6;
int val[nax];
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int& x:a)cin>>x,val[x]++;
  int gcd=a[0];
  for(int x:a)gcd=__gcd(gcd,x);
  if(gcd!=1){
    cout<<"not coprime";
    return 0;
  }
  for(int i=2;i<nax;i++){
    int tmp=0;
    for(int j=i;j<=nax;j+=i){
      tmp+=val[j];
      if(tmp>1)cout<<"setwise coprime",exit(0);
    }
  }
  cout<<"pairwise coprime";

}


Measured memory_bytes: 11372
#include<bits/stdc++.h>
#define N 510
using namespace std;
char s[N][N];
int main(){
	int h,w;
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++){
		scanf("%s",s[i]);
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i==0||i!=h-1&&(j&1||s[i][j]=='#')) putchar('#');
			else putchar('.');
		}
		putchar('\n');
	}
	puts("");
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i==h-1||i!=0&&(j%2==0||s[i][j]=='#')) putchar('#');
			else putchar('.');
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG //(compiler options)
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define sz(x) ((int)(x).size())
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
using namespace std;
using ll = long long; using ull = unsigned ll; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> T mind(T &x, const T &y) {if (y < x) {T d = y-x; x = y; return d;} else return 0;} //RETURNS A NON-POSITIVE VALUE
template<typename T> T maxd(T &x, const T &y) {if (y > x) {T d = y-x; x = y; return d;} else return 0;}
template<typename C> int uniq(C &a) {a.erase(unique(all(a)), end(a)); return sz(a);}
template<typename C, typename F> int uniq(C &a, F cmp) {a.erase(unique(all(a), cmp), end(a)); return sz(a);}
const int mod = 1e9+7, infi = 1e9; const ll infl = 1e18; const ld infd = INFINITY;

#define x(a) real(a)
#define y(a) imag(a)
using G = ll; using point = complex<G>;
istream& operator>>(istream &is, point &p){G x, y; is >> x >> y; p = {x, y}; return is;}
ostream& operator<<(ostream &os, const point &p){os << p.x() << ' ' << p.y(); return os;}
G dot(const point &a, const point &b) {return (conj(a)*b).x();}
G crs(const point &a, const point &b) {return (conj(a)*b).y();}
G ori(const point &a, const point &b, const point &c) {return crs(b-a, c-b);};
bool cmpyx(const point &a, const point &b) {return a.y()<b.y() || (a.y()==b.y()&&a.x()<b.x());};

int main()
{
    #ifndef LOCAL
    //ifstream cin("hull.in"); ofstream cout("hull.out");
    #endif // LOCAL
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << setprecision(15);
    char s[] = "- +";
    char ac, bc, cc, dc; cin >> ac >> bc >> cc >> dc;
    int a = ac-'0', b = bc-'0', c = cc-'0', d = dc-'0';
    for(int x1 = -1; x1 <= 1; x1 += 2) for(int x2 = -1; x2 <= 1; x2 += 2) for(int x3 = -1; x3 <= 1; x3 += 2) {
        if (a + x1*b + x2*c + x3*d == 7) {
            cout << a << s[x1+1] << b << s[x2+1] << c << s[x3+1] << d << "=7";
            return 0;
        }
    }
}



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

  int N;
  int A[100];
  int i, j, key, temp1, temp2;

  scanf("%d",&N);
 
  for(i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  
  for(i=0; i<N-1; i++){
      printf("%d ", A[i]);
  }
  printf("%d", A[N-1]);
    printf("\n");
  
  for(j=1; j<=N-1; j++){
    key = A[j];
    i=j-1;
    while(i>=0 && A[i]>key){
      temp1=A[i]; temp2=A[i+1];
      A[i+1]=temp1; A[i]=temp2;
      i=i-1;
      
    }
    for(i=0; i<N-1; i++){
      printf("%d ", A[i]);
    }
    printf("%d", A[N-1]);
    printf("\n");

    
    A[i+1]=key;
  }
  
  return 0;
}



Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
int main()
{
    ll n; cin>>n;
    deque<ll>q;
    for(ll i=1;i<=n;i++)
    {
        ll ch; cin>>ch;
        if(i%2)
           q.pb(ch);
        else
           q.pf(ch);
    }
    if(n%2==0)
    {
        while(!q.empty())
        {
            cout<<q.front()<<" ";
            q.pop_front();
        }
    }
    else
    {
        while(!q.empty())
        {
            cout<<q.back()<<" ";
            q.pop_back();
        }
    }
    cout<<endl;
}

Measured memory_bytes: 3840
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		int sum = 0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 1; i <= N; i++) {
			sum += i;
			list.add(i);
			if(sum >= N) {
				break;
			}
		}
		for(int i : list) {
			if(i != sum - N) {
				System.out.println(i);
			}
		}
	}
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<int> t = a;
	sort(t.begin(), t.end());
	int c = t[n / 2];
	int d = t[n / 2 - 1];
	rep(i, n) {
		if (a[i] < c) cout << c << endl;
		else cout << d << endl;
	}
	return 0;
}


Measured memory_bytes: 4808
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N = int(input())
X = list(map(int, input().split()))

x = X[:]
x.sort()
m1 = x[N//2 - 1]
m2 = x[N//2]

for a in X:
    if a <= m1:
        print(m2)
    else:
        print(m1)

Measured memory_bytes: 25476
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.{NumericRange, Queue}
import scala.collection.mutable
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val W, H, T = sc.nextInt
    val P = sc.nextInt
    val A = Array.fill(W)(Array.fill(H)(0))
    for (i <- Range(0, P)) {
      A(sc.nextInt)(sc.nextInt) += 1
      sc.nextInt
    }
    for (i <- Range(0, H)) (for (j <- Range(0, W)) (A(j)(i) *= sc.nextInt))
    println(A.map(x => x.sum).sum)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}


Measured memory_bytes: 50280
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  if ((N + 1) / 2 >= K) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 101
#define INF 100100

static const int WHITE = 0; //not visited
static const int GRAY = 1; //visited
static const int BLACK = 2;

int n, M[MAX][MAX];
int color[MAX];
int dist_from_start[MAX];
int parent_node[MAX];

void dijkstra(int start) {
  //initialize
  for (int i = 1; i <= n; i++) {
    color[i] = WHITE;
    dist_from_start[i] = INF;
    parent_node[i] = -1;
  }

  dist_from_start[start] = 0;
  color[start] = GRAY;

  while (true) {
    int mincost = INF;
    int now = -1;

    //初回はmincost = 0になる(始点)
    for (int i = 1; i <= n; i++) {
      if (color[i] != BLACK && dist_from_start[i] < mincost) {
        mincost = dist_from_start[i];
        now = i;
      }
    }

    if (now == -1) break;

    color[now] = BLACK;

    for (int v = 1; v <= n; v++) {
      if (color[v] != BLACK && M[now][v] != INF) {
        if (dist_from_start[now] + M[now][v] < dist_from_start[v]) {
          dist_from_start[v] = dist_from_start[now] + M[now][v];
          parent_node[v] = now;
          color[v] = GRAY;
        }
      }
    }
  }

  for (int i = 1; i <= n; i++) cout << i-1 << " " << (dist_from_start[i] == INF ? -1 : dist_from_start[i]) << endl;
}

int main() {
  cin >> n;

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      M[i][j] = INF;
    }
  }

  int u, k;
  for (int i = 1; i <= n; i++) {
    cin >> u >> k;
    for (int j = 1; j <= k; j++) {
      int v, t;
      cin >> v >> t;
      M[u+1][v+1] = t;
    }
  }

  dijkstra(1);

  return 0;
}



Measured memory_bytes: 3128
#include<stdio.h>
#include<string.h>
#define N 1001

int main(){
  int i,j,n;
  int num[N];
  char number[N];
  
  for(n=0;n<N;n++){
    num[n]=0;
  }
  n=0;
  
  while(1){
    scanf("%s",number);
    if(number[0]=='0'&&number[1]=='\0')break;
    for(i=0;i<strlen(number);i++){
      num[n]+=number[i]-'0';
    }
    n++;
  }
 
  for(j=0;j<n;j++){
    printf("%d\n",num[j]);
  }
  
  return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

int main()
{
  int n, x;
  while(cin >> n >> x){
    int cur = 0;
    int ans = 1;
    for(int i = 0 ; i < n ; i++){
      int L;
      cin >> L;
      cur += L;
      ans += cur <= x;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int div2(int n){
	int ans = 0;
	int m = n;
	while(m%2 == 0){
		ans++;
		m /= 2;
	}
	return ans;
}

int main(){
	int N;
	cin >> N;
	int A[N];
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	int sum = 0;
	for(int i = 0; i < N; i++){
		sum += div2(A[i]);
	}
	cout << sum << "\n";
}


Measured memory_bytes: 256
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin >> t;
	map<string, int>m;
	while (t--)
	{
		string x;
		cin >> x;
		m[x]++;
	}
	cout << "AC x " << m["AC"] << endl << "WA x " << m["WA"] << endl << "TLE x " << m["TLE"] << endl << "RE x " << m["RE"] << endl;
	return 0;
}






Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=17,M=(1ll<<N)+10,mod=1e9+7;
ll a[N][N],n,dp[M],val[M];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=0;i<n;i++)for(ll j=0;j<n;j++)cin>>a[i][j];
    for(ll mask=0;mask<(1ll<<n);mask++){
        for(ll i=0;i<n;i++){
            for(ll j=i+1;j<n;j++){
                if((mask>>i)&1 and (mask>>j)&1)val[mask]+=a[i][j];
            }
        }
    }

    for(ll mask=0;mask<(1ll<<n);mask++){
        for(ll cur=mask;cur>=0;cur=mask&(cur-1)){
            ll othr_grp = mask^cur;
            dp[mask] = max(dp[mask] , dp[cur]+val[othr_grp]);
            if(cur==0)break;
        }
    }

    cout<<dp[(1ll<<n)-1];
}

Measured memory_bytes: 1280
#include <stdint.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long N, long long K, std::vector<long long> p) {
  sort(ALL(p));
  ll ans = 0;
  REP(i, K) {
    ans += p[i];
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> p(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &p[i]);
  }
  solve(N, K, std::move(p));
  return 0;
}


Measured memory_bytes: 3704
#include<cstdio>

using namespace std;

int a[11];

bool dfs(int k, int B, int C)
{
    if(k==10) return true;
    if(a[k]>B)
        if(dfs(k+1, a[k], C)) return true;
    if(a[k]>C)
        if(dfs(k+1, B, a[k])) return true;
    return false;
}


int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        for(int i=0; i<10; i++)
            scanf("%d", &a[i]);
        if(dfs(0, 0, 0)) printf("YES\n");
        else  printf("NO\n");

    }

    return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
vector <int> order(vector <vector<int>> &graph){
    int sz = graph.size();
    vector <int> ord(sz);
    queue <int> q;
    q.push(0);
    vector <bool>  done(sz) ;
    done[0] = true;
    while(!q.empty()){
        int now = q.front(); q.pop();
        int cnt = 0;
        for(int i=0;i<graph[now].size();i++){
            if(done[graph[now][i]]) continue;
            cnt++;
            q.push(graph[now][i]);
            done[graph[now][i]] = true;
        }
        ord[now] = cnt;
    }
    return ord;
}
void check_order(vector <int> &ord){
    int x = ord.size();
    for(int i=0;i<x;i++){
        cout<<ord[i]<<endl;
    }
}
int main(void){
    int n, k; cin>>n>>k;
    vector <vector<int>> graph(n ,vector <int>( ));
    //cout<<n-1<<endl;
    for(int i=0;i<n-1;i++){
        int a,b; cin>>a>>b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    //それぞれの頂点の次数について調べていくよ!
    vector <int> ord = order(graph);
    long long ans = k;
    int cone0 = ord[0];
    for(int i=0;i<cone0;i++){
        ans*= k-1-i;
        ans %= MOD;
    }
    for(int i=1;i<n;i++){
        int cone = ord[i];
        for(int j=0;j<cone;j++){
        ans*= k-2-j;
        ans %= MOD;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6904
#include<bits/stdc++.h>
 using namespace std;
 int main(){
     int i,c=0,a;
     double ans;
     cin>>a;
     for(i=1;i<=a;i++){
        if(i%2!=0){
            c++;
        }
     }
     ans=(double)c/a;
     cout<<fixed<<setprecision(10)<<ans<<endl;
     return 0;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
  
int main()
{
  string S;
  cin >> S;

  int a = S.at(0)-'0';
  int b = S.at(1)-'0';
  int c = S.at(2)-'0';
  int d = S.at(3)-'0';

  if(a+b+c+d==7){
    cout << a << "+" << b << "+" << c << "+" << d << "=" << 7 << endl;
  }else if(a-b+c+d==7){
    cout << a << "-" << b << "+" << c << "+" << d << "=" << 7 << endl;
  }else if(a+b-c+d==7){
    cout << a << "+" << b << "-" << c << "+" << d << "=" << 7 << endl;
  }else if(a+b+c-d==7){
    cout << a << "+" << b << "+" << c << "-" << d << "=" << 7 << endl;
  }else if(a-b-c+d==7){
    cout << a << "-" << b << "-" << c << "+" << d << "=" << 7 << endl;
  }else if(a-b+c-d==7){
    cout << a << "-" << b << "+" << c << "-" << d << "=" << 7 << endl;
  }else if(a+b-c-d==7){
    cout << a << "+" << b << "-" << c << "-" << d << "=" << 7 << endl;
  }else if(a-b-c-d==7){
    cout << a << "-" << b << "-" << c << "-" << d << "=" << 7 << endl;
  }
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	int N;
	cin >> N;
	LL ret = 0;
	for (int i : range(N)) {
		LL a;
		cin >> a;
		while (a % 2 == 0) {
			ret++;
			a /= 2;
		}
	}
	cout << ret << endl;


	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main {
	static int x;
	static int ans;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.next());
		int m = Integer.parseInt(in.next());
		char[][] original = new char[n][m];
		for(int i = 0; i < n; i++) {
			original[i] = in.next().toCharArray();
		}
		int ans = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(original[i][j] == '.') {
					ans = Math.max(ans, solve(i, j, original, n, m));
				}
			}
		}
		System.out.println(ans);
	}
	public static int solve(int ii, int jj, char[][] original, int x, int y) {
		int[][] visited = new int[x][y];
		int[][] dp = new int[x][y];
		for(int i = 0; i < x; i++)
			for(int j = 0; j < y; j++)
				dp[i][j] = 1000000;
		dp[ii][jj] = 0;
		int max = 0;
		while(true) {
			int min = 1000000;
			int xx = -1;
			int yy = -1;
			for(int i = 0; i < x; i++) {
				for(int j = 0; j < y; j++) {
					if((dp[i][j] != 1000000) && (visited[i][j] == 0)) {
						if(dp[i][j] < min) {
							min = dp[i][j];
							xx = i;
							yy = j;
							max = Math.max(max, dp[i][j]);
						}
					}
				}
			}
			if(xx == -1) break;
			else {
				visited[xx][yy] = 1;
				if(xx - 1 >= 0) {
					if(original[xx - 1][yy] == '.') {
						dp[xx - 1][yy] = Math.min(dp[xx - 1][yy], dp[xx][yy] + 1);
					}
				}
				if(xx + 1 < x) {
					if(original[xx + 1][yy] == '.') {
						dp[xx + 1][yy] = Math.min(dp[xx + 1][yy], dp[xx][yy] + 1);
					}
				}
				if(yy - 1 >= 0) {
					if(original[xx][yy - 1] == '.') {
						dp[xx][yy - 1] = Math.min(dp[xx][yy - 1], dp[xx][yy] + 1);
					}
				}
				if(yy + 1 < y) {
					if(original[xx][yy + 1] == '.') {
						dp[xx][yy + 1] = Math.min(dp[xx][yy + 1], dp[xx][yy] + 1);
					}
				}
			}
		}
		return max;
	}
}

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

int main()
{
  while(true)
  {
    int n,x;
    cin>>n>>x;
    if(n+x==0) return 0;
    int ans=0;
    for (int i = 1; i <= n; ++i)
    {
      for (int j = 1; j <= n; ++j)
      {
        if(i==j) continue;
        for (int k = 1; k <= n; ++k)
        {
          if(i==k || j==k ) continue;
          if(i+j+k==x) ans++;
        }
      }
    }
    cout<<ans/6<<endl;
  }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
// #include <bits/stdtr1c++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;


/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/

/// Typedef
typedef long long           ll;
typedef unsigned long       ul;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef vector<vi>          vvi;
typedef vector<ll>          vll;
typedef pair<int,int>       pii;
typedef pair<ll,ll>         pll;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       scanf("%lld %lld %lld", &x, &y, &z)
template <class T> inline T bigMod(T p,T e,T M){ ll ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T) ret;}
template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T> inline string int2String(T a){ostringstream str; str<<a; return str.str();}
template <class T> inline T string2int(string a){stringstream str(a); T b; str>>b; return b;}


#define MAX                 200005
#define MOD                 1000000007
#define base                1000000007
#define eps                 1e-9
#define INF                 1llu<<61    // 2,305,843,009,213,693,952
#define inf                 1<<29       // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932
// #define INF              0x3f3f3f3f3f3f3f3f
// #define inf              0x3f3f3f3f

int ara[MAX],br[MAX];
int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n;si(n);
    FOR(i,0,n)si(ara[i]);
    br[n-1]=ara[n-1];
    ROF(i,n-2,0){
        br[i] = br[i+1] + ara[i];
    }
    int res = INT_MAX,sum=0;
    FOR(i,0,n){
        sum+=ara[i];
        res = min(res,abs(sum-br[i+1]));
    }
    cout<<res<<endl;

    #ifdef VAMP
       printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif

    return 0;
}

Measured memory_bytes: 256