akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001;
const int NMAX=8;

vector<string> s(105);

vector<int> ans;

int main()
{
int h,w;
cin>>h>>w;
rep(i,h)cin>>s[i];
int dp[105][105];
//if (s[0][0]=='#')dp[0][0]=1;
//else if (s[0][0]=='.')dp[0][0]=0;
char now='.';
int cnt_h=0;
int cnt_w=0;
for(int i=0;i<h;i++){
	if (now=='.' and s[i][0]=='#') cnt_h++;
	dp[i][0]=cnt_h;
	now=s[i][0];
//	cout<<cnt_h<<'h'<<endl;
}
now='.';
for(int i=0;i<w;i++){
	if (now=='.' and s[0][i]=='#') cnt_w++;
	//cout<<cnt_w<<'w'<<endl;
	dp[0][i]=cnt_w;
	now=s[0][i];
}
//rep(i,h)rep(j,w)cout<<dp[i][j]<<endl;

for(int i=1;i<h;i++){
	for(int j=1;j<w;j++){
		int temp1,temp2;
		temp1=dp[i-1][j];
		temp2=dp[i][j-1];
		if (s[i][j]=='#'  and s[i-1][j]=='.')temp1++;
		if (s[i][j]=='#'  and s[i][j-1]=='.')temp2++;
		dp[i][j]=min(temp1,temp2);
	//	cout<<dp[i][j]<<endl;
	//	cout<<i<<'i'<<j<<'j'<<endl;

	}

}

cout<<dp[h-1][w-1];


}


Measured memory_bytes: 256
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitsf(n) __builtin_popcount(n)
ll power(ll x, ll y); 

const ll MOD = 1000000007;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    string s;
    cin >> s;
    vector<int> v;
    rep(i, 0, s.size()) if(s[i] == 'B') v.pb(i);
    int n = v.size(), r = s.size() - 1;
    ll res = 0;

    rrep(i, n-1, 0) res += (ll)(r - (n - 1 - i) - v[i]);

    cout << res;
}
 
ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}


Measured memory_bytes: 1532
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

const ll MOD=1e9+7;

int N,K,L;
int par[2][200100], sz[2][200100];

inline int find(int ix, int n) { return par[ix][n]==n ? n : par[ix][n]=find(ix,par[ix][n]); }

inline void join(int ix, int a, int b) {
  a=find(ix,a), b=find(ix,b);
  if (a==b) return;
  if (sz[ix][a] > sz[ix][b]) swap(a,b);
  sz[ix][b] += sz[ix][a];
  par[ix][a] = b;
}

map<pii,int> mp;

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

  cin>>N>>K>>L;

  for(int i=1;i<=N;i++) par[0][i]=par[1][i]=i, sz[0][i]=sz[1][i]=1;

  int a,b;
  while (K --> 0) cin>>a>>b, join(0,a,b);
  while (L --> 0) cin>>a>>b, join(1,a,b);

  for (int i=1;i<=N;i++) mp[{find(0,i), find(1,i)}]++;


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

  return 0;


}


Measured memory_bytes: 15104
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

map<long long, long long> prime_factors(long long n) {
  map<long long, long long> res;
  if (n == 1) {
    res[n] = 1;
    return res;
  }
  for (long long i = 2, _n = n; i * i <= _n + 1; ++i) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

int main() {
  long long N, P;
  cin >> N >> P;
  map<long long, long long> pf = prime_factors(P);

  long long res = 1;

  for (map<long long, long long>::iterator it = pf.begin(), end = pf.end();
       it != end; ++it) {
    long long cnt = it->second / N;
    while (cnt) {
      res *= it->first;
      --cnt;
    }
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
from math import ceil

N, A, B = map(int, input().split())
H = []
for _ in range(N):
    H.append(int(input()))
    
left = 0
right = max(H)//B + 1

while right - left > 1:
    mid = (right + left) // 2
    c = sum([ceil((h-B*mid)/(A-B)) for h in H if h > B*mid])
    
    if c > mid:
        left = mid
    else:
        right = mid
print(right)

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 10000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int w, d;
int h1[15], h2[15];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        int w, d;
        int h1[15] = {}, h2[15] = {};
        cin >> w >> d;
        if (w == 0 && d == 0) break;
        rep(i, w) cin >> h1[i];
        rep(i, d) cin >> h2[i];
        int ans = 0;
        rep(i, w) {
            ans += h1[i];
            rep(j, d) {
                if (h1[i] == h2[j]) {
                    h2[j] = -1;
                    break;
                }
            }
        }
        rep(j, d) if (h2[j] != -1) ans += h2[j];
        cout << ans << endl;
    }
}

Measured memory_bytes: 3140
#include <iostream>
#include <cmath>

using namespace std;
long long N,A,B,C,D,E;
int main() {
    cin >> N >> A >> B >> C >> D >> E;
    cout<<(N - 1) / min(A,min(B,min(C,min(D,E)))) + 5;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2000000000)
input=lambda : sys.stdin.readline().rstrip('\n')

n,q=map(int,input().split())
s=input()
dic=[[0 for i in range(q)] for i in range(26)]
for i in range(q):
    t,d=input().split()
    c=ord(t)-ord('A')
    if d=='L':
        dic[c][i]=-1
    if d=='R':
        dic[c][i]=1

l,r=-1,n
while l+1<r:
    mid=(l+r)//2
    d=mid
    f=False
    for i in range(q+1):
        if d==-1:
            f=True
            break
        if d==n or i==q:
            f=False
            break
        c=ord(s[d])-ord('A')
        if dic[c][i]!=0:
            d+=dic[c][i]
    if f:
        l=mid
    else:
        r=mid
tmp1=l
l,r=-1,n
while l+1<r:
    mid=(l+r)//2
    d=mid
    f=False
    for i in range(q+1):
        if d==n:
            f=True
            break
        if d==-1 or i==q:
            f=False
            break
        c=ord(s[d])-ord('A')
        if dic[c][i]!=0:
            d+=dic[c][i]
    if f:
        r=mid
    else:
        l=mid
print(max(r-tmp1-1,0))

Measured memory_bytes: 135292
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
int n,k,q;
int res = 1e9;
vector<int> a;

void solve(int x){
    vector<int> s;
    priority_queue<int,vector<int>,greater<int>> qu;
    rep(i,n+1){
        if(a[i] < x){
            while(!qu.empty()){
                if(qu.size() >= k){
                    s.push_back(qu.top());
                }
                qu.pop();
            }
        }else{
            qu.push(a[i]);
        }
    }
    if(s.size() < q) return;
    sort(s.begin(), s.end());
    res = min(res, s[q-1]-x);
}

int main(void){
    cin>>n>>k>>q;
    a.resize(n);
    rep(i,n) cin>>a[i];
    a.push_back(0);
    rep(i,n) solve(a[i]);
    cout<<res<<endl;
    return 0;
}


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

using namespace std;

int main()
{
    char s[10];
    while(~scanf("%s",s))
    {
      	int _a=0,_b=0; 
		for(int i=0;s[i];i++){
          if(s[i]=='A') _a++;
          else if (s[i]=='B') _b++;
        }
        printf(_a&&_b?"Yes\n":"No\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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

int main(){
  int n;
  cin >> n;
  int b=0;
  int c=0;
  rep(i,0,n){
    int a;
    cin >> a;
    if(b<=a)c++;
    b = max(a,b);
  }
  cout << c << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vpii = vector<pii>;
#define forn(i,n) for (int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second

void cxxio() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}

ll solve(const vpii& ps) {
    int n=ps.size();
    vpii L(n), R(n);
    forn(i, n) {
        L[i]=pii(ps[i].ff, i);
        R[i]=pii(ps[i].ss, i);
    }
    sort(all(L));
    sort(all(R));
    reverse(all(L));
    vi used(n);
    ll ans=0, pos=0;
    auto move=[&](pii p) {
        if (pos<p.ff) {
            ans+=llabs(p.ff-pos);
            pos=p.ff;
        }
        if (pos>p.ss) {
            ans+=llabs(p.ss-pos);
            pos=p.ss;
        }
    };
    for (int i=0, j=0;;) {
        for (; i<n && used[L[i].ss]; i++);
        if (i==n) break;
        move(ps[L[i].ss]);
        used[L[i].ss]=1;
        for (; j<n && used[R[j].ss]; j++);
        if (j==n) break;
        move(ps[R[j].ss]);
        used[R[j].ss]=1;
    }
    return ans+llabs(pos);
}

int main() {
    cxxio();
    int n;
    cin>>n;
    vpii ps(n);
    forn(i, n) cin>>ps[i].ff>>ps[i].ss;
    ll ans=solve(ps);
    forn(i, n) ps[i]=pii(-ps[i].ss, -ps[i].ff);
    ans=max(ans, solve(ps));
    cout<<ans<<'\n';
}


Measured memory_bytes: 3032
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    int N, K, tmp, min = -1;
    cin >> N >> K;
    vector<int> heights;
    for (int i=0; i<N; i++){
        cin >> tmp;
        heights.push_back(tmp);
    }
    sort(heights.begin(), heights.end());
    for (int i=0; i<N - K + 1; i++){
        min = heights[i+K - 1] - heights[i] < min || min < 0 ? heights[i+K - 1] - heights[i] : min;
    }
    
    cout << min << endl;
    

}

Measured memory_bytes: 892
#pragma warning(disable:4996)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector> 
#include<algorithm>
using namespace std;
const long long maxn = 0x3f3f3f3f;
long long dp[5000],cost[1005],num[1005],val[1005];
vector<int> key[1005];
int main() 
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		scanf("%d%d", &cost[i], &num[i]);
		for (int j = 0; j < num[i]; j++)
		{
			int l;
			scanf("%d", &l);
			key[i].push_back(l);
		}
	}
	for (int i = 1; i <= m; i++)
	{
		int len = key[i].size();
		for (int j = 0; j < len; j++)
		{
			val[i] += 1 << (key[i][j]-1);
		}
	}
	memset(dp,maxn , sizeof(dp));
	for (int i = 1; i <= m; i++)
	{
		dp[val[i]] = min(dp[val[i]], cost[i]);
	}
	for (int j = 1; j <= m; j++)
	{
		for (int i = 0; i < (1 << n); i++)
		{
			dp[i|val[j]] = min(dp[i|val[j]], dp[i] + cost[j]);		
		}
	}
	if (dp[(1 << n) - 1]<maxn)
	{
		printf("%lld\n",dp[(1 << n) - 1]);
	}
	else
	{
		printf("-1\n");
	}
	//system("pause");
	return 0;
}





Measured memory_bytes: 384
package main

import (
	"fmt"
)

func min(a ...int) int {
	m := a[0]
	for i, v := range a {
		if i == 0 {
			continue
		}
		if m > v {
			m = v
		}
	}
	return m
}

func main() {
	// Code for C - Walk on Multiplication Table
	var N int
	fmt.Scanf("%d", &N)

	var minNum int = 1000000000000000
	for i := 1; i*i <= N; i++ {
		if N%i != 0 {
			continue
		} else {
			j := N / i
			minNum = min(minNum, (i-1)+(j-1))
		}
	}

	fmt.Println(minNum)
}


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

int main(){
  int n, d, x;
  cin >> n >> d >> x;
  int ret = x;
  for(int i=0; i<n; i++){
    int ai;
    cin >> ai;
    ret += ((d-1)/ai + 1);
  }
  cout << ret;
  return 0;
}
  
    

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# B
# 
# input
s = input()
# calc
if s[0:7] == 'keyence' or s[-7:] == 'keyence':
  print('YES')
elif s[0:1]+s[-6:] == 'keyence':
  print('YES')
elif s[0:2]+s[-5:] == 'keyence':
  print('YES')
elif s[0:3]+s[-4:] == 'keyence':
  print('YES')  
elif s[0:4]+s[-3:] == 'keyence':
  print('YES')
elif s[0:5]+s[-2:] == 'keyence':
  print('YES')  
elif s[0:6]+s[-1:] == 'keyence':
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        Integer K = Integer.parseInt(st.nextToken());
        Integer S = Integer.parseInt(st.nextToken());
        long ans=0;
        for (int i=0; i<=K; i++) {

            for (int j=0; j<=K; j++) {
                if(i+j>S)
                    continue;
                if(S-i-j<=K)
                    ans++;
            }
        }
        System.out.println(ans);
        
    }

}


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

int main(){
    int n,a,b,c;
    cin>>n>>a>>b>>c;
    vector<string> v(n+1);
    vector<string> ans;
    int flag=0;
    for(int i=0;i<n;i++) cin>>v[i];
    v.push_back("0");
    for(int i=0;i<n;i++){
        if(v[i]=="AB"){
            if(a==1 && b==1 && c==0 && v[i+1]=="BC"){
                ans.push_back("B");
                b++;
                a--;
            }
            else if((a==1 && b==1 && c==0 && v[i+1]=="AC")){
                ans.push_back("A");
                a++;
                b--;
            }
            else{
                if(max(a,b)==a){
                    ans.push_back("B");
                    a--;b++;
                }
                else{
                    ans.push_back("A");
                    a++;b--;
                }
            }
            if(a<0 || b<0 ||c<0){
                flag=1;break;
            }
        }
        else if(v[i]=="BC"){
            if(b==1 && c==1 && a==0 && v[i+1]=="AC"){
                ans.push_back("C");
                c++;
                b--;
            }
            else if((b==1 && c==1 && a==0 && v[i+1]=="AB")){
                ans.push_back("B");
                b++;
                c--;
            }
            else{
                if(max(b,c)==b){
                    ans.push_back("C");
                    b--;c++;
                }
                else{
                    ans.push_back("B");
                    b++;c--;
                }
            }
            if(a<0 || b<0 ||c<0){
                flag=1;break;
            }
        }
        else{
            if(a==1 && c==1 && b==0 && v[i+1]=="AB"){
                ans.push_back("A");
                a++;
                c--;
            }
            else if((a==1 && c==1 && c==0 && v[i+1]=="BC")){
                ans.push_back("C");
                a--;
                c++;
            }
            else{
                if(max(a,c)==a){
                    ans.push_back("C");
                    a--;c++;
                }
                else{
                    ans.push_back("A");
                    a++;c--;
                }
            }
            if(a<0 || b<0 ||c<0){
                flag=1;break;
            }
        }
    }
    if(flag) cout<<"No";
    else{
        cout<<"Yes"<<endl;
        for(auto x:ans) cout<<x<<endl;
    }
}

Measured memory_bytes: 13664
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int a,b,cnt=0;
    string s;
    cin>>a>>b>>s;
    rep(i,a+b+1){
        if(s[i]=='-') cnt++;
    }
    if(cnt==1&&s[a]=='-') cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, 0, h) rep(j, 0, w) cin >> a[i][j];

  vector<tuple<int, int, int, int>> v;
  rep(i, 0, h) rep(j, 0, w) {
    if (a[i][j] & 1) {
      if (j < w - 1) {
        a[i][j + 1]++;
        a[i][j]--;
        v.emplace_back(i + 1, j + 1, i + 1, j + 2);

      } else {
        if (i < h - 1) {
          a[i + 1][j]++;
          a[i][j]--;
          v.emplace_back(i + 1, j + 1, i + 2, j + 1);
        }
      }
    }
  }

  cout << v.size() << endl;
  for (auto vv : v) {
    cout << get<0>(vv) << " " << get<1>(vv) << " " << get<2>(vv) << " "
         << get<3>(vv) << endl;
  }
}


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

typedef long long int ll;
typedef long long unsigned int ull;
typedef long double ld;
typedef vector<int> vr;
typedef pair<int, int> pr;
#define pb push_back
#define ff first
#define ss second
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433
#define endl "\n"
//cout << fixed << setprecision(2);


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >> s;
    int len = s.size();
    if(s[len-1] == 's'){
        cout << s+"es" << endl;
    }
    else{
        cout << s+'s' << endl;
    }

    return 0;
}



Measured memory_bytes: 3664
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> s;
  int ans = 0;

  bool is_allten = true;

  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    s.push_back(tmp);
    ans += tmp;
    if (tmp % 10 != 0) {
      is_allten = false;
    }
  }

  sort(s.begin(), s.end());

  if (ans % 10 != 0) {
    cout << ans << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (s[i] % 10 != 0) {
      ans -= s[i];
      break;
    }
  }

  if (is_allten) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
s = input()
mod = 10**9 + 7
total = 0

n = len(s)
cnt_left_one = [0] * (n + 1)
for i in range(1, n + 1):
    if s[i - 1] == '1':
        cnt_left_one[i] = cnt_left_one[i - 1] + 1
    else:
        cnt_left_one[i] = cnt_left_one[i - 1]

# 全部そのまま
total += pow(2, cnt_left_one[n], mod)

for k in range(0, n):
    if s[k] == '0':
        continue
    total += pow(2, cnt_left_one[k], mod) * pow(3, n - 1 - k, mod)

print(total % mod)


Measured memory_bytes: 41836
#include<iostream>
using namespace std;
int main()
{
  int k;
  cin>>k;
  int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<a[k-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

ll dp[(1<<21)];
ll a[21][21];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	dp[0]=1;
	for(ll mask=0;mask<( (1LL<<n)-1);mask++)
	{
		ll a1=__builtin_popcount(mask);
		for(ll i=0;i<n;i++)
		{
			if(a[a1][i] && !((mask>>i)&1LL))
			{
				dp[(mask|(1LL<<i))]+=dp[mask];
				dp[(mask|(1LL<<i))]%=mod;
			}
		}
	}
	cout<< dp[( (1LL<<n)-1 )];
    return 0;
}


//252908XL

Measured memory_bytes: 16640
b = list(map(int, input().split()))
x1=b[0]
y1=b[1]
x2=b[2]
y2=b[3]
xkyori=abs(x1-x2)
ykyori=abs(y1-y2)
if x1>=x2:
    if y1>=y2:
        print(x2+ykyori,y2-xkyori,x1+ykyori,y1-xkyori)
    else:
        print(x2-ykyori,y2-xkyori,x1-ykyori,y1-xkyori)
else:
    if y1>=y2:
        print(x2 + ykyori, y2 + xkyori, x1 + ykyori, y1 + xkyori)
    else:
        print(x2-ykyori,y2+xkyori,x1-ykyori,y1+xkyori)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static List<string> perms = new List<string>();

        static void Main(string[] args)
        {
            var strs = Console.ReadLine().Split();
            var N = int.Parse(strs[0]);
            var M = int.Parse(strs[1]);
            var X = int.Parse(strs[2]);
            var Y = int.Parse(strs[3]);

            var x = new int[N];
            var y = new int[M];

            strs = Console.ReadLine().Split();
            for (int i = 0; i < N; i++) x[i] = int.Parse(strs[i]);

            strs = Console.ReadLine().Split();
            for (int i = 0; i < M; i++) y[i] = int.Parse(strs[i]);

            if (Math.Max(X, x.Max()) < Math.Min(Y, y.Min()))
                Console.WriteLine("No War");
            else
                Console.WriteLine("War");
        }
    }
}


Measured memory_bytes: 13268
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) { if(b==0) return a; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { return a/GCD(a,b)*b; }

class ACalc {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int a;in>>a;out<<a+a*a+a*a*a<<endl;

	}
};


int main() {
	ACalc solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3196
import sys

N = int(input())
T, A = map(int, input().split())
H = list(map(int, sys.stdin.readline().rsplit()))

mini = 10 ** 9
index = -1
for i, h in enumerate(H):
    temp = T - h * 0.006
    if mini > abs(temp - A):
        mini = abs(temp - A)
        index = i + 1
print(index)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}

const ll INF = 1e18;
const ll MAXD = 100000;
void mainsolve(){

	ll n;
	cin >> n;
	vector<ll> units;
	units.push_back(1);
	ll tmp = 1;
	rep(i,6){
		tmp *= 6;
		units.push_back(tmp);
	}
	tmp = 1;
	rep(i,6){
		tmp *= 9;
		units.push_back(tmp);
	}

	vector<ll> dp(MAXD+1, INF);
	for(ll x : units){
		if(x <= MAXD) dp[x] = 1;
	}

	// TODO init
	for(ll i = 1; i <= MAXD; i++){
		for(ll x : units){
			if(i-x >= 1 && x <= MAXD) dp[i] = min(dp[i], dp[i-x] + dp[x]);
		}
	}
	
	cout << dp[n] << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

mod = 998244353


NN = 10**4 # 使うデータによって変える

inv = [0]
for i in range(1, NN):
    inv.append(pow(i, mod-2, mod))

def main():
    A, B, C, D = map(int, input().split())
    dp = [[0]*(D+1) for _ in range(C+1)]
    dp2 = [[0]*(D+1) for _ in range(C+1)]


    for w in range(B-1, D+1):
        dp[A][w] = 0
        dp2[A][w] = pow(A, (D-B), mod)


    for c in range(A+1, C+1):
        if D - B - 1 >= 0:
            t = pow(c*inv[c-1] % mod, D-B-1, mod)
        kakeru = (c-1)*inv[c] % mod
        dp[c][B] = pow(B,c-A,mod) * pow(c, D-B, mod) % mod
        dp2[c][B] = dp[c][B]
        for d in range(B+1, D+1):
            dp[c][d] = (dp2[c-1][d-1] + dp[c-1][d]*d % mod ) * t % mod
            t = t * kakeru % mod
            dp2[c][d] = (dp2[c][d-1] + dp[c][d]) % mod

    print(dp2[C][D])


if __name__ == "__main__":
    main()

Measured memory_bytes: 205952
// B - Echo
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; string S; cin>>N>>S;
	if(N&1){ puts("No"); return 0; }
	rpz(i, N/2) if(S[i] != S[N/2 + i]){ puts("No"); return 0; }
	puts("Yes");
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dist(int x, int y){
  return x * x + y * y;
}

int main(){
  int T;
  cin >> T;
  while(T--){
    int N, X, Y;
    cin >> N >> X >> Y;
    int NX, NY;
    cin >> NX >> NY;
    vector<int> BX(N), BY(N);
    REP(i, N) cin >> BX[i] >> BY[i];
    vector< vector<int> > G(N);
    REP(i, N)FOR(j, i + 1, N){
      if(dist(BX[i] - BX[j], BY[i] - BY[j]) <= 50 * 50){
        G[i].push_back(j);
        G[j].push_back(i);
      }
    }
    int ans = 0;
    vector<int> cnt(N);
    queue<int> que[2];
    int T = Y / X + 1;
    REP(i, N) if(dist(BX[i] - NX, BY[i] - NY) <= 10 * 10){
      que[0].push(i);
      cnt[i] = T + 1;
    }
    while(!que[ans & 1].empty()){
      REP(i, N) if(cnt[i] > 0) cnt[i] --;
      //printf("%d:\n", ans);
      while(!que[ans & 1].empty()){
        int u = que[ans & 1].front(); que[ans & 1].pop();
        //printf("%d : %d %d\n", u, BX[u], BY[u]);
        REP(i, G[u].size()){
          int v = G[u][i];
          if(cnt[v] == 0){
            que[(ans + 1) & 1].push(v);
            cnt[v] = T + 1;
          }
        }
      }
      ans ++;
      if(ans >= 100000) break;
    }
    if(ans >= 100000) cout << "You're always welcome!" << endl;
    else cout << ans * X << endl;
  }

  return 0;
}

Measured memory_bytes: 5228
#include <iostream>
#include <string>

using namespace std;

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

int main(){
    int h, n, a[100000];
    cin >> h >> n;
    rep(i, n) cin >> a[i];
    string com = "No";
    rep(i, n) {
        h -= a[i];
        if(h <= 0){
            com = "Yes";
            break;
        }
    }
    cout << com;
    return 0;
}


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

int main(){
    double o=0,e=0,a,b,c,d,n,m,k,l,ans=0,max=0;
    string s,t,u;
    double x;
    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>x>>u;
        if (u=="JPY") {
            ans+=x;
        }
        else ans+=x*380000;
    }
    
    
    cout<<ans<<endl;
    
}


Measured memory_bytes: 888
#include<stdio.h>
#include<algorithm>
#define maxn 200005
#define inf 0x3f3f3f3f
using namespace std;
typedef long int ll;
bool prime[60000];
int ans[60000], p;
int main()
{
    for (int i = 2; i < 60000; ++i){
        if (!prime[i]) for (int j = 2; j * i < 60000; ++j) prime[j * i] = 1;
    }
    int n;
    scanf("%d", &n);
    for (int i = 2; i <= 55555; ++i) if (!prime[i] && i % 5 == 1) ans[++p] = i;
    for (int i = 1; i < n; ++i) printf("%d ", ans[i]);
    printf("%d\n", ans[n]);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  ll n;
  cin >> n;
  vl v(5);
  ll x = LINF;
  rep(i,5){
    cin >> v[i];
    x = min(x,v[i]);
  }
  if(x>=n){
    cout << 5 << endl;
    return 0;
  }
  else{
    if(x!=1){
      cout << 5+n/x << endl;
      return 0;
    }
    else{
      cout << 4+n/x << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5010;
 
ll dp[MAX_N][MAX_N];  // dp[i][j] : s[i]とs[j](i < j)から始まる共通部分文字列の長さの最大値
 
int main() {
    ll n;
    string s;
    cin >> n >> s;
 
    for(ll i = n-2; i >= 0; i--) {
        for(ll j = n-1; j >= i+1; j--) {
            if(s[i] == s[j]) {
                dp[i][j] = dp[i+1][j+1] + 1;
            }
        }
    }
 
    ll ans = 0;
    exrep(i, 0, n-2) {
        exrep(j, i+1, n-1) {
            ll u = min(j-i, dp[i][j]);
            chmax(ans, u);
        }
    }
 
    out(ans);
    re0;
}

Measured memory_bytes: 194944
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
char s[N];
int ret[N];

bool solve(int n, char s[]) {
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
      ret[0] = i;
      ret[1] = j;
      for (int i = 2; i < n + 2; ++i) {
        if (ret[i - 1]) {
          ret[i] = (s[i - 1] == 'o' ? 1 - ret[i - 2] : ret[i - 2]);
        } else {
          ret[i] = (s[i - 1] == 'o' ? ret[i - 2] : 1 - ret[i - 2]);
        }
      }
      if (ret[0] == ret[n] && ret[1] == ret[n + 1]) return true;
    }
  }
  return false;
}

int main() {
  int n;
  scanf("%d%s", &n, s);
  s[n] = s[0];
  if (!solve(n, s)) {
    puts("-1");
  } else {
    for (int i = 0; i < n; ++i) {
      putchar(ret[i] ? 'W' : 'S');
    }
    puts("");
  }
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

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


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
    
		// 出力
		System.out.println(Math.max(Math.max(a + b, a - b), a * b));
	}
}


Measured memory_bytes: 21844
import java.util.*;
 
class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
 
		String s =sc.next();
		
		if(s.equals("A"))System.out.println("T");
		else 	if(s.equals("T"))System.out.println("A");
		else 	if(s.equals("C"))System.out.println("G");
		else 	if(s.equals("G"))System.out.println("C");
		

	}
	
}

Measured memory_bytes: 23636
#include <iostream>
#include <cstdio>
#include <complex>
#include <cassert>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <sstream>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define mp(a,b) make_pair(a,b)
#define SZ(a) ((int)(a).size())
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
#define pb(a) push_back(a)
#define F first
#define S second
typedef pair<int,int> PI;
typedef complex<double> pt;

int n;
int x[100],y[100],r[100];



vector<pt> cross(int c1,int c2){
  int dx=x[c1]-x[c2];
  int dy=y[c1]-y[c2];
  int rr=r[c1]+r[c2];
  if(dx*dx+dy*dy> rr*rr) return vector<pt>();

  /*
     /|\
    /_|_\
    x1

    r1*r1 -x1*x1 = r2*r2-(rr-x1)*(rr-x1) = r2*r2-rr*rr+2*rr*x1-x1*x1
    r1*r1 = r2*r2-rr*rr+2*rr*x1
    2*rr*x1=r1*r1-r2*r2+rr*rr
    x1 = (r1*r1-r2*r2+rr*rr)/2/rr
  */
  int r1 = r[c1];
  int r2 = r[c2];
  double rrr = sqrt(dx*dx+dy*dy);
  double x1 = (r1*r1-r2*r2+rrr*rrr)/2./rrr;
  //cout << x1 << endl;
  double dd=sqrt(dx*dx+dy*dy);
  double mx = -dx/dd*x1 + x[c1];
  double my = -dy/dd*x1 + y[c1];
  
  double diax = -dy;
  double diay = dx;
  
  double y1 = sqrt(r1*r1-x1*x1);
  vector<pt> ret;
  ret.pb(pt(mx+diax/dd*y1,my+diay/dd*y1));
  ret.pb(pt(mx-diax/dd*y1,my-diay/dd*y1));
  
  return ret;
}


#define ALL(a) (a).begin(),(a).end()

bool can(pt a, pt b){
  vector<pair<double,double> > check;
  if(abs(b-a) < 1e-5) return true;
  
  rep(i,n){
    pt c(x[i],y[i]);
    pt ac = c-a;
    pt v=(b-a);
    double acv = ac.real()*v.real()+ac.imag()*v.imag();
    double cc=norm(ac)-r[i]*r[i];
    double aa=norm(v);
    double bb=-2.*acv;
    if(bb*bb-4.*aa*cc < 1e-4) continue;
    double p1 = (-bb-sqrt(bb*bb-4.*aa*cc))/2./aa;
    double p2 = (-bb+sqrt(bb*bb-4.*aa*cc))/2./aa;
    if(p1 > 1 - 1e-5) continue;
    if(p2 < 1e-5) continue;
    //cout << " " << p1 << " " << p2 << endl;
    p1=max(0.,p1);
    p2=min(1.,p2);
    check.pb(mp(p1,p2));
  }
  sort(ALL(check));
  
  double cur = 0;
  FOR(it,check){
    if(it->F > cur + 1e-8) return false;
    cur = max(it->S,cur);
  }
  
  return cur > 1-1e-8;
}
  
void solve(){
  rep(i,n) cin >> x[i] >> y[i] >> r[i];
  vector<pt> plist;
  plist.pb(pt(x[0],y[0]));
  plist.pb(pt(x[n-1],y[n-1]));
  
  rep(i,n-1){
    vector<pt> t=cross(i,i+1);
    rep(j,SZ(t)){
      plist.pb(t[j]);
      //cout << t[j].real() << " " << t[j].imag() << endl;
    }
  }

  //can(pt(0,0),pt(5,4));
  
  //exit(0);
  
  priority_queue<pair<double,int> > q;
  
  q.push(mp(0,0));
  vector<bool> vis(100000);
  while(!q.empty()){
    double cc = -q.top().F;
    int cv = q.top().S;
    q.pop();
    if(vis[cv]) continue;
    //cout << " " << plist[cv].real() << " " << plist[cv].imag() << " " << cc << endl;
    vis[cv] = 1;
    if(cv == 1){
      printf("%.8f\n",cc);
      return;
    }
    
    rep(j,SZ(plist)){
      if(!vis[j] && can(plist[cv],plist[j]))
        q.push(mp(-cc-abs(plist[cv]-plist[j]),j));
    }
  }

  cout << -1 << endl;
}

int main(){
  while(cin >> n && n) solve();
}

Measured memory_bytes: 1284
from itertools import accumulate
import bisect
n = int(input())
als = list(map(int, input().split()))

ac = list(accumulate(als))

asum = sum(als)

trg = asum/2
idx = bisect.bisect_left(ac, asum/2)
if ac[idx] == trg:
    ans = 0
else:
    ans = min(trg - ac[idx-1], ac[idx] - trg)/0.5
print(int(ans))


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

ll digit(ll a)
{
    ll ans = 0;

    while (a)
    {
        ans++;
        a /= 10;
    }
    return (ans);
}

int main()
{
    ll n;
    cin >> n;

    ll ans = 1001001001;
    for (ll a = 1; a * a <= n; a++)
    {
        ll b;
        if (n % a != 0)
            continue;
        b = n / a;
        ans = min(ans, max(digit(a), digit(b)));
    }

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


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
using namespace std;
vector<int> g[100003];
long long int m=1000000007;
long long int k;

struct E{
	long long int p,c1,c2,perm;
};

long long int f2(long long int a,long long int b){
	if(a<=b){
		return (b-a)%m;
	}else{
		return 0;
	}
}

E f(int p1,E e1){
	//cout<<"(e1 "<<p1<<" "<<e1.perm<<" "<<e1.c1<<" "<<e1.c2<<")";
	E e2;
	e2.p=p1;
	e2.c2=e1.c1;
	e2.perm=1;
	E e5,e3;
	e5.p=p1;
	e5.c1=0;
	e5.c2=0;
	e5.perm=1;
	e3.p=p1;
	e3.c1=1;
	e3.c2=e1.c1;
	e2.c1=p1==1?0:1;
	e3.perm=1;
	for(int i=0;i<g[p1].size();i++){
		if(g[p1][i]==e1.p)continue;
		//cout<<"(e2 "<<p1<<" "<<e2.perm<<" "<<e2.c1<<" "<<e2.c2<<")";
		E e4=f(g[p1][i],e3);
		e5.c1++;
		e5.c2+=e4.c1;
		e3.c2++;
		e1.perm=(e1.perm*e4.perm)%m;
	}
	//cout<<"(e2 "<<p1<<" "<<e2.perm<<" "<<e2.c1<<" "<<e2.c2<<")";
	//cout<<"(e5 "<<p1<<" "<<e5.perm<<" "<<e5.c1<<" "<<e5.c2<<")\n";
	e1.perm=(e1.perm*f2(e1.c1+e1.c2,k))%m;
	e1.c2=e5.c1;
	e1.c1=1;
	return e1;
}

int main() {
	// your code goes here
	int n;
	cin>>n>>k;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	E e1;
	e1.p=1;
	e1.c1=0;
	e1.c2=0;
	e1.perm=1;
	cout<<f(1,e1).perm<<"\n";
	return 0;
}

Measured memory_bytes: 19840
#include <cstdio>
#include <algorithm>

using namespace std;

int p[100];

int main() {
    int n, a, b, x = 0, y = 0, z = 0, i;
    
    scanf("%d %d %d", &n, &a, &b);
    
    for (i = 0; i < n; i++) scanf("%d", &p[i]);
    
    for (i = 0; i < n; i++) {
        if (p[i] <= a) {
            x++;
        } else if (p[i] <= b) {
            y++;
        } else {
            z++;
        }
    }
    
    printf("%d\n", min(x, min(y, z)));
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }



int main(){
  char a,b;
  cin >> a >> b;
  if(a == 'H' and b=='H' or a == 'D' and b == 'D')cout << 'H' << endl;
  else cout << 'D' << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * B - Crane and Turtle
 * 庭に何匹かの動物がいます。
 * これらはそれぞれ、2 本の足を持つ鶴か 4 本の足を持つ亀のいずれかです。
 * 高橋くんは、「庭の動物の総数は X 匹で、それらの足の総数は Y 本である」と発言しています。
 * この発言が正しいような鶴と亀の数の組合せが存在するか判定してください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        int x = sc.nextInt();
        int y = sc.nextInt();
        System.out.println( ( x * 4 < y || x * 2 > y ||  y % 2 == 1 ) ? "No" : "Yes" );

        sc.close();
    }
}


Measured memory_bytes: 35636
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

LL f(LL x) {
	LL ans = 0;
	inc(i, 40) {
		LL y = 1LL << i;
		LL z = 1LL << (i + 1);
		
		LL c = fl(x, z) * y + max(0LL, x % z - y);
		if(c % 2 == 1) { ans |= y; }
	}
	
	return ans;
}

int main() {
	LL a, b;
	cin >> a >> b;
	
	cout << (f(a) ^ f(b + 1)) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, bool isFront) {
	if (first_itr < 0 || first_itr > str.size()) {
		return str;
	}
	else {
		if (isFront) {
			std::string tmp;
			for (size_t i = 0; i < first_itr; i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
		else {
			std::string tmp;
			for (size_t i = first_itr; i < str.size(); i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
	}
}


bool dfs(int depth, str s) {
	/*if (depth == n) {
		ans.push_back(s);
		return false;
	}
	for (int i = 0; i < n; i++) {
		if (dfs(depth + 1, s + dic.at(i))) {
			return true;
		}
	}*/
	return false;
}



int main() {
	int n, m; cin >> n >> m;
	if (n == m)cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;
}

Measured memory_bytes: 256
from collections import deque

n = int(input())
a = []
firstB = deque()
lastA = deque()
both = deque()
used = set()
for i in range(n):
    s = input().strip()
    a.append(s)
    if s[0] == 'B' and s[-1] == 'A':
        both.append(i)
        used.add(i)
    elif s[0] == 'B':
        firstB.append(i)
        used.add(i)
    elif s[-1] == 'A':
        lastA.append(i)
        used.add(i)

ret = ''
while both:
    ret += a[both.pop()]
if ret and lastA:
    ret = a[lastA.pop()] + ret
if ret and firstB:
    ret += a[firstB.pop()]
while lastA and firstB:
    ret += a[lastA.pop()] + a[firstB.pop()]
while lastA:
    ret += a[lastA.pop()]
while firstB:
    ret += a[firstB.pop()]
for i in range(n):
    if i not in used:
        ret += a[i]
print(ret.count('AB'))

Measured memory_bytes: 136836