akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint n, k;
vector<P> G[100005];
llint ans[100005];

void dfs(int v, int p, int c)
{
	int id = 0;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i].first == p) continue;
		ans[G[v][i].second] = (c+1+id)%k;
		dfs(G[v][i].first, v, (c+1+id)%k);
		id++;
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint u, v;
	for(int i = 1; i <= n-1; i++){
		cin >> u >> v;
		G[u].push_back(P(v, i));
		G[v].push_back(P(u, i));
	}
	for(int i = 1; i <= n; i++) k = max(k, (llint)G[i].size());
	dfs(1, 0, -1);
	
	cout << k << endl;
	for(int i = 1; i <= n-1; i++) cout << ans[i]+1 << endl;
	
	return 0;
}

Measured memory_bytes: 10752
x,n = map(int, input().split())
l = list(map(int, input().split()))
l_dis = [num - x for num in l]

def s_func(x):
    if x < 0:
        return abs(x) - 0.5
    else:
        return abs(x)
    
l_dis = sorted(l_dis, key=s_func)
if len(l_dis)==0:
    print(x)
elif l_dis[0] != 0:
    print(x)
else:
    i = 1
    j = 1
    b = -1
    while True:
        if i > len(l_dis)-1 or l_dis[i] != j*b:
            print(x + j*b)
            break
        i += 1
        b *= -1
        if i > len(l_dis)-1 or l_dis[i] != j*b:
            print(x + j*b)
            break
        i += 1
        b *= -1
        j += 1

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

int main(){
	int d;
	
	cin>>d;
	
	if(d==25)cout<<"Christmas";
	if(d==24)cout<<"Christmas Eve";
	if(d==23)cout<<"Christmas Eve Eve";
	if(d==22)cout<<"Christmas Eve Eve Eve";
	
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define Rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
typedef long long ll;

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

    int n;
    cin >> n;
    int a[n], b[n];
    rep (i, n) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a, a + n, greater<int>());
    rep (i, n) {
        if (a[0] == b[i]) cout << a[1] << endl;
        else cout << a[0] << endl;
    }
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int d;
    cin >> d;
    
    vector<int> c(26);
    vector<vector<int>> s(d, vector<int>(26, 0));
    vector<int> l(26);
    vector<int> ans(d);
    for(int ic=0;ic<26;ic++) {
        cin >> c.at(ic);
    }
    for(int id=0;id<d;id++) {
        for(int iw=0;iw<26;iw++) {
            cin >> s.at(id).at(iw);
        }
    }

    llint tmax, ttmp, q;
    vector<int> ltmp(26);
    for(int id=0;id<d;id++) {
        q = 0;
        tmax = 0;
        for(int iw=0;iw<26;iw++) {
            ttmp = s.at(id).at(iw);
            for(int iw=0;iw<26;iw++) {
                ltmp.at(iw) = l.at(iw);
            }
            ltmp.at(iw) = id + 1;
            for(int il=0;il<26;il++) {
                ttmp -= c.at(il)*(id + 1 - l.at(il));
            }
            if(ttmp>tmax) {
                q = iw;
                tmax = ttmp;
            }
        }
        l.at(q) = id + 1;
        ans.at(id) = q + 1;
    }
    for(int id=0;id<d;id++)  {
        cout << ans.at(id);
        if(id!=d-1) cout << endl;
    }
    return 0;
}


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

int main() {
  int N, A;
  cin >> N >> A;
  cout << N*N-A << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] x = new int[N];
    int[] y = new int[N];
    for (int i = 0; i < N; i++) {
      x[i] = scanner.nextInt();
      y[i] = scanner.nextInt();
    }

    int[] order = new int[N];
    for (int i = 0; i < N; i++) order[i] = i;

    double sum = 0;
    do {
      sum += distance(N, x, y, order);
    } while (next(order));
    for (int i = 1; i <= N; i++) {
      sum /= i;
    }
    System.out.println(sum);
  }

  private static double distance(int N, int[] x, int[] y, int[] order) {
    double sum = 0;
    int lastx = x[order[0]];
    int lasty = y[order[0]];
    for (int i = 1; i < N; i++) {
      sum += Math.sqrt((x[order[i]] - lastx) * (x[order[i]] - lastx) + (y[order[i]] - lasty) * (y[order[i]] - lasty));
    }
    return sum;
  }

  public static boolean next(int[] p) {
    final int n = p.length;

    int i = n - 1;
    while (i > 0 && p[i - 1] >= p[i]) i--;
    if (i <= 0) return false;

    int j = n - 1;
    while (j >= i && p[j] <= p[i - 1]) j--;

    swap(p, i - 1, j);

    j = n - 1;
    while (i < j) swap(p, i++, j--);

    return true;
  }

  private static void swap(int[] a, int i, int j) {
    int tmp = a[j];
    a[j] = a[i];
    a[i] = tmp;
  }
}


Measured memory_bytes: 22100
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

LL dfs(int x,int y,vector<vector<LL>> &dp,vector<LL> &sif){
	if(x>y) return 0ll;
	return max(sif[y+1]-sif[x]-dfs(x+1,y,dp,sif),sif[y+1]-sif[x]-dfs(x,y-1,dp,sif));
}
void solve(){
	int n;
	cin>>n;
	vector<int> nums(n);
	for(int i=0;i<n;i++) cin>>nums[i];
	vector<LL> sif(n+1,0);
	for(int i=0;i<n;i++){
		sif[i+1]=sif[i]+nums[i];
	}
	vector<vector<LL>> dp(n,vector<LL>(n,0ll));
	for(int i=0;i<n;i++){
		dp[i][i] = nums[i];
	}
	for(int len=2;len<=n;len++){
		for(int i=0;i<(n-len+1);i++){
			int j = i+len-1;
			dp[i][j] = max(sif[j+1]-sif[i]-dp[i+1][j],sif[j+1]-sif[i]-dp[i][j-1]);
		}
	}
	cout<<2ll * dp[0][n-1]-sif[n]<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 70784
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n, m;
  cin >> n >> m;
  
  vector<vector<int>> s(m, vector<int>());
  rep(i, m) {
    int k;
    cin >> k;
    rep(j, k) {
      int l;
      cin >> l;
      s[i].push_back(l-1);
    }
  }
  
  
  
  vector<int> p(m);
  rep(i, m) {
    cin >> p[i];
  }
  
  int ans = 0;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    
    bitset<10> b(tmp);//全スイッチオンオフして確かめる
    bool flag = true;
    
    rep(i, m) {//スイッチがtmpのとき
      bitset<10> c;//i番の電球がどのスイッチと繋がってるか
      
      rep(j, s[i].size()) {
        c[s[i][j]] = 1;//s[i][]に入っているスイッチとつながっている
      }
      
      
      bitset<10> d = b & c;
      
      
      int cnt = d.count();//i番の電球と繋がっているスイッチでonになっているスイッチの数
      
      if (cnt % 2 == p[i]) {
        continue;//i番の電球は点灯したからi+1番を見る
      } else {
        flag = false;//i番がつかなかったからこのtmpはダメ、tmp+1を考える
        break;
      }
      
    
    }
    
    if (flag) ans++;
    
  }
  
  cout << ans << endl;

}




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

const int MOD = 1e9+7;

void precalc();
int putere(int x, int p);
int comb(int n, int k);
int combR(int n, int k)
{
    return comb(n+k-1,n-1);
}

int f[400005], inv[400005];
int n;

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

    int k;

    cin >> n >> k;
    //formula este: nr[i] = C(n,i) * Cr(n-i,i)
    //adica: alegem i camere in care raman 0
    //si apoi alegem unde punem cele i persoane
    //Cr(n,k) = C(n+k-1,n-1)

    precalc();
    int ans = 0;
    k = min(k,n-1);
    for (int i=0;i<=k;i++)
    {
        int aux = (1ll*comb(n,i)*combR(n-i,i)) % MOD;
        ans = (ans+aux)%MOD;
    }
    cout << ans << '\n';
    return 0;
}

int putere(int x, int p)
{
    int aux = 1;

    while (p)
    {
        if (p%2)
            aux = (1ll*aux*x)%MOD;
        x = (1ll*x*x)%MOD;
        p /= 2;
    }
    return aux;
}

int comb(int n, int k)
{
    int ans = f[n];

    ans = (1ll*ans*inv[k])%MOD;
    ans = (1ll*ans*inv[n-k])%MOD;
    return ans;
}

void precalc()
{
    f[0] = 1;
    inv[0]= putere(f[0],MOD-2);
    for (int i=1;i<=2*n;i++)
    {
        f[i] = (1ll*f[i-1]*i)%MOD;
        inv[i] = putere(f[i],MOD-2);
    }
}

Measured memory_bytes: 3328
//
// Created by yamunaku on 2019/07/14.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    cin >> n;
    vi a(n);
    bool b=false;
    rep(i,n){
        cin >> a[i];
        if(a[i]!=0) b=true;
    }
    sort(all(a));
    if(n%3){
        if(b) CNO;
        else CYES;
    }else{
        int x=a[0],y=a[n/3],z=a[n/3*2];
        if((x^y^z)!=0){
            CNO;
        }else{
            rep(i,n/3){
                if(a[i]!=a[0]){
                    CNO;
                    return 0;
                }
            }
            rep(i,n/3){
                if(a[i+n/3]!=a[n/3]){
                    CNO;
                    return 0;
                }
            }
            rep(i,n/3){
                if(a[i+n/3*2]!=a[n/3*2]){
                    CNO;
                    return 0;
                }
            }
            CYES;
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;


int main(void){
    int n;
    scanf("%d", &n);
    
    vector<int> v1;
    vector<int> v2;
    int num;
    for(int i = 0; i < n; i++){
        scanf("%d", &num);
        v1.push_back(num);
        v2.push_back(num);
    }
    sort(v2.begin(), v2.end());

    for(int i = 0; i < n; i++){
        if(v1[i] < v2[n / 2]){
            printf("%d\n", v2[n / 2]);
        }else{
            printf("%d\n", v2[n / 2 - 1]);
        }
    }

    return 0;
}


Measured memory_bytes: 3948
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

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

	int n, t;
	cin >> n >> t;
	int costMin = 10000;
	for (int i = 0; i < n; i++) {
		int cost, time;
		cin >> cost >> time;
		if (time <= t) {
			costMin = min(cost, costMin);
		}
	}
	if (costMin < 10000) {
		cout << costMin << "\n";
	}
	else {
		cout << "TLE\n";
	}

	return 0;
}

Measured memory_bytes: 384
a,b,c = (int(x) for x in input().split())

l = [a,b,c]

for i in range(2):
    if(l[0] > l[i+1]):
        l[0],l[i+1] = l[i+1],l[0]

if(l[1] > l[2]):
    l[1],l[2] = l[2],l[1]

print(l[0],l[1],l[2])


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
int main() {
  int n; cin >> n;
  long long int a[50];
  rep(i,n) cin >> a[i];
  // sort(a,a+n,greater<int>());
  long long int ans = 0;
  bool f = true;
  while (f) {
    f = false;
    rep(i,n) {
      if (a[i] >= n) {
        f = true;
        long long int pluscnt = a[i] / n;
        a[i] = a[i] % n;
        
        ans += pluscnt;
        rep(j,n) {
          if (i==j) continue;
          a[j] += pluscnt;
        }
        
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){ 
  string s,t;
  cin >> s>>t;
  int cnt=0;
  rep(i,3){
    if(s[i]==t[i]){
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]

for a, b in ab:
    manh = 10**9
    num = 0
    for c, d in cd:
        if abs(a - c) + abs(b - d) < manh:
            manh = abs(a - c) + abs(b - d)
            num = cd.index([c, d]) + 1
    print(num)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
	char ch;
	int cnt[26] = {0};
	int i,len;

	while(scanf("%c", &ch) != EOF){
		if(ch >= 'a' && ch <= 'z'){
			cnt[ch - 'a']++;
		}else if(ch >= 'A' && ch <= 'Z'){
			cnt[ch - 'A']++;
		}
	}

	len = sizeof(cnt) / sizeof(cnt[0]);
	
	for(i = 0;i < len;i++){
		printf("%c : %d\n", 'a' + i, cnt[i]);
	}
	return 0;
}

Measured memory_bytes: 540
#include <stdio.h>
#include <stdlib.h>
int main(void){
    char a[1001],c[101],f[1001],m[1001];
    int b,d,e,i,j;
    scanf("%s",&a);
    scanf("%d",&b);
    for(i=0;i<b;i++){
        scanf("%s %d %d",&c,&d,&e);
        
        if(strcmp(&c,"print")==0){
            for(j=d;j<=e;j++) printf("%c",a[j]);
            printf("\n");
        }
        
        if(strcmp(&c,"reverse")==0){
            for(j=d;j<=e;j++) m[j] = a[j];
            for(j=d;j<=e;j++) a[j] = m[d+e-j];
        }
        
        if(strcmp(&c,"replace")==0){
            scanf("%s",&f);
            for(j=d;j<=e;j++) a[j] = f[j-d];
        }
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++)
        cin >> H[i];

    int res = 0, cnt = 0;
    for (int i = 1; i < N; i++) {
        if (H[i] <= H[i - 1]) {
            cnt++;
        } else {
            res = max(res, cnt);
            cnt = 0;
        }
    }
    res = max(res, cnt);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 764
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int n = sc.nextInt();
        int cx[] = {0, w};
        int cy[] = {0, h};
        for(int i = 0; i < n; i++){
        	int x = sc.nextInt();
            int y = sc.nextInt();
            int a = sc.nextInt();
            if(a == 1 && cx[0] < x){
            	cx[0] = x;
            }else if(a == 2 && cx[1] > x){
            	cx[1] = x;
            }else if(a == 3 && cy[0] < y){
            	cy[0] = y;
            }else if(a == 4 && cy[1] > y){
            	cy[1] = y;
            }
            if(cx[0] >= cx[1] || cy[0] >= cy[1]){
            	System.out.println(0);
                return;
            }
        }
        int yoko = cx[1] - cx[0];
        int tate = cy[1] - cy[0];
        System.out.println(yoko * tate);
	}
}

Measured memory_bytes: 36456
N, M = map(int, input().split())
Lmax = 1
Rmin = N

for i in range(M):
  L, R = map(int, input().split())
  Lmax = max(Lmax, L)
  Rmin = min(Rmin, R)
  if Rmin < Lmax:
    print(0)
    exit()
print(Rmin-Lmax+1)

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

int main() {
  int n;
  cin >> n;
  
  if(n%10==2 ||n%10==4 ||n%10==5 ||n%10==7 ||n%10==9){
    cout << "hon" << endl;
  }
  else if(n%10==0 ||n%10==1 ||n%10==6 ||n%10==8){
     cout << "pon" << endl;
  }
  else{
     cout << "bon" << endl;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll mod = 1e9+7;

int main(){
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  rep(i,n-1) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }

  vector<vector<ll>> dp(n, vector<ll>(2,0));
  vector<int> visited(n,0);

  auto dfs = [&](auto& f, int p, int u)-> void{

    if (visited[u]) return ;

    dp[u][0] = 1; 
    dp[u][1] = 1;

    for (auto v : g[u]) {
      if (v == p) continue;
      f(f, u, v);
      (dp[u][0] *= (dp[v][0] + dp[v][1] % mod)) %= mod;
      (dp[u][1] *= dp[v][0]) %= mod;
    }
    visited[u] = 1; 
  };
  dfs(dfs,-1,0);

  cout << (dp[0][0] + dp[0][1]) % mod << endl;
  return 0;
} 

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

#define ll long long

int main() {
    std::ios::sync_with_stdio(false);
    using namespace std;
    int n;
    cin >> n;
    vector< vector<int> > A(n, vector<int>(n - 1));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n - 1; j++) {
            cin >> A[i][j];
            A[i][j]--;
        }
   auto matches = [&A](int i, int i_turn,
                     int j, int j_turn) -> bool {
       return A[i][i_turn] == j &&
              A[j][j_turn] == i;
   };

   vector< vector<char> > C(n, vector<char>(n, false));
   auto getField = [&C, &A](int x, int y) {
       auto mminmax = minmax({x, y});
       int mmin = mminmax.first, mmax = mminmax.second;
       bool tmp = C[mmin][mmax];
       C[mmin][mmax] = true;
       return tmp;
   };
   queue< pair<int, int> > Q;
   for(int i = 0; i < n; i++)
       if(matches(i, 0, A[i][0], 0)) {
           if(!getField(i, A[i][0])) {
               Q.push({i, A[i][0]});
           }
       }
   Q.push({-1, -1});

   vector<int> B(n, 0);

   int m = 0, result = 0;
   while(Q.size() > 1) {
       int i = Q.front().first,
           j = Q.front().second;
       Q.pop();
       if(i == -1 && j == -1) {
            result += 1;
            Q.push({-1, -1});
            continue;
       }
       m += 1;
       for(int x : {i, j}) {
           B[x] += 1;
           if(B[x] == n - 1) continue;
           int other = A[x][B[x]];
           if(matches(x, B[x], other, B[other]) && !getField(x, other)) {
               Q.push({x, other}); 
           }
       }
   }

   if(m != (n * (n - 1) / 2)) {
       cout << "-1\n";
   } else {
       cout << result + 1 << "\n";
   }
   return 0;
}


Measured memory_bytes: 5248
#include <map>
int main() {
  int N, a, x{}, n{3}, b{1};
  scanf("%d",&N);
  std::map<int, int> m;
  if (N % 3) while (scanf("%d",&a)+1) b &= !a;
  else {
    N /= 3;
    while (scanf("%d",&a)+1) if (!(++m[a] % N)) --n, x ^= a;
    b = !n && !x;
  }
  printf("%s\n", b?"Yes":"No");
}


Measured memory_bytes: 6764
import java.util.Scanner;

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(a + b/2);
	}

}

Measured memory_bytes: 21844
import sys

s = list(input())
n = len(s)
t = []
ind = [-1]
for i in range(n):
    if s[i] != "x":
        t.append(s[i])
        ind.append(i)
ind.append(n)
# print(t)
ng = 0
lt = len(t)
for i in range(lt):
    if t[i] != t[lt-1-i]:
        ng = 1
        break
if ng == 1:
    print(-1)
    sys.exit()

ind1 = [ind[i+1]-ind[i] for i in range(len(ind)-1)]
ans = 0
for i in range(len(ind1) // 2):
    ans += abs(ind1[i] - ind1[len(ind1) - 1 - i])
print(ans)

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll dp[100010][13];
int main()
{
    string S;
    cin >> S;
    
    int N;
    N = S.length();

    // 初期化
    Fill(dp,0);
    dp[0][0] = 1;

    int temp;
    for(int i=0; i<N; i++){
        if(S[i] == '?'){
            for(int j=0; j<=9; j++){
                for(int k=0; k<=12; k++){
                    dp[i+1][(k*10+j)%13]+=dp[i][k]%MOD;
                }
            }
        }
        else{
            for(int k=0; k<=12; k++){
                dp[i+1][(k*10+(S[i]-'0'))%13]+=dp[i][k]%MOD;
            }
        }
    }
    cout << dp[N][5] % MOD << endl;
    return 0;
}

Measured memory_bytes: 10624
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
using namespace std;

#define MAXN 100010

struct edge
{
    int to,next;
}edg[MAXN];
int head[MAXN];
bool vis[10];
int cnt,ans;
void add(int u,int v)
{
    edg[cnt].to=v;
    edg[cnt].next=head[u];
    head[u]=cnt++;
}
int n,m;
void dfs(int u,int num)
{
    if(num==n)
    {
        ans++;
        return ;
    }
    vis[u]=1;
    for(int i=head[u];i!=-1;i=edg[i].next)
    {
        int v=edg[i].to;
        if(!vis[v])
        {
            dfs(v,num+1);
            vis[v]=0;
        }
    }
}
int main()
{
    cnt=0;
    ans=0;
    scanf("%d%d",&n,&m);
    memset(head,-1,sizeof(head));
    for(int i=0;i<m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        add(u,v);
        add(v,u);
    }
    dfs(1,1);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;

/**
 * FizzBuzz
 */
public class Main {

	static final long MAX = 100000000000000000L;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		long s = parseLong(br.readLine());

		long left, right, mid, len;
		left = 1;
		right = MAX + 1;
		mid = 0;
		len = 0;

		while (left < right) {
			mid = left + (right - left) / 2;
			len = len(mid);
			if (len - fizzbuzz(mid).length() < s && s <= len) {
				break;
			} else if (len - fizzbuzz(mid).length() <= s) {
				left = mid + 1;
			} else {
				right = mid;
			}
		}

		StringBuilder ans = new StringBuilder();

		long _mid = mid;
		long _s = len + 1;

		outer:
		while (true) {
			String tmp = fizzbuzz(_mid);
			for (int i = tmp.length() - 1; i >= 0; i--) {
				ans.append(tmp.charAt(i));
				_s--;
				if (_s == s) break outer;
			}
			_mid--;
		}
		ans = ans.reverse();

		for (long i = mid + 1; ans.length() < 20; i++) {
			ans.append(fizzbuzz(i));
		}

		System.out.println(ans.toString().substring(0, 20));
	}

	static long len(long m) {

		if (m == 0) return 0;

		int n = String.valueOf(m).length();
		long _m = ((long) Math.pow(10, n - 1)) - 1;

		long q3 = m / 3 - _m / 3;
		long q5 = m / 5 - _m / 5;
		long q15 = m / 15 - _m / 15;
		long q35 = q3 + q5 - q15 * 2;

		return (m - _m - q35 - q15) * n + q35 * 4 + q15 * 8 + len(_m);
	}

	static String fizzbuzz(long m) {
		if (m == 0) {
			return "";
		} else if (m % 15 == 0) {
			return "FizzBuzz";
		} else if (m % 3 == 0) {
			return "Fizz";
		} else if (m % 5 == 0) {
			return "Buzz";
		} else {
			return String.valueOf(m);
		}
	}
}

Measured memory_bytes: 24488
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//　敵の数
		int n = sc.nextInt();
		// 必殺技の回数
		int k = sc.nextInt();
        //攻撃回数
        long t = 0;
      
      	// 必殺技で除去できる物は除外
     	if(k>=n){
          System.out.println(t);
        }
      
      	else{
          //敵の体力
		  long a[] = new long[n];
      	
  		  for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
          }
      
      	  Arrays.sort(a);
      	
          for(int i=0;i<n-k;i++){
            t = t+a[i];
          }
		  System.out.println(t);
        }
	}
}


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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}

#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

void err(vector<string>::iterator it) {}

template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;

	int lb = 0, rb = n;

	while (rb - lb > 1) {
		int mb = (rb + lb) >> 1;
		int tot = n, cur = mb;
		while (tot > 0 && cur > 0) {
			if (tot >= cur) tot -= cur, cur = tmin(cur - 1, tot);
			else cur--;
		}
		if (tot == 0) rb = mb;
		else lb = mb;
	}
	vector<int> ans;
	int tot = n, cur = rb;
	while (tot > 0 && cur > 0) {
		if (tot >= cur) {
			ans.push_back(cur);
			tot -= cur, cur = tmin(cur - 1, tot);
		}
		else cur--;
	}
	sort(ALL(ans));
	for (int v : ans) printf("%d\n", v);

	return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		long x = sc.nextLong();
		long y = sc.nextLong();
		long res = x;
		int cnt = 0;
		while (res <= y) {
			cnt++;
			res *= 2;
		}
		out.println(cnt);
		
		out.close();
	} 

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}


Measured memory_bytes: 23252
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := NewScanner()
	S := strings.Split(sc.NextLine(), "/")

	if v, _ := strconv.Atoi(S[1]); v < 5 {
		fmt.Println("Heisei")
	} else {
		fmt.Println("TBD")
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int bingo[3][3];
    bool open[3][3];

    rep(i, 3)rep(j, 3){
        cin >> bingo[i][j];
        open[i][j] = false;
    }

    int N;
    cin >> N;
    rep(i, N) {
        int b; cin >> b;
        rep(j, 3)rep(k, 3){
            if(bingo[j][k] == b) open[j][k] = true;
        }
    }

    bool ok = false;
    rep(i, 3){
        bool c = true, d = true, e = true, f = true;
        rep(j, 3) {
            c &= open[i][j];
            d &= open[j][i];
            e &= open[j][j];
            f &= open[2 - j][j];
        }
        ok |= (c | d | e | f);
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
n = gets.to_i
as = gets.split.map &:to_i

plus = nil
minus = nil

minus = as[0]

is_minus = true

i = 1

wallet = 1000

as.each_with_index{ |a, i|
	if i == 0 then
		next
	end
	
	if is_minus then
		if minus >= a then
			minus = a
		else
			is_minus = false
			plus = a
		end
	else
		if plus <= a then
			plus = a
		else
			kabu = wallet / minus
			wallet = (wallet - kabu * minus) + kabu * plus
			
			is_minus = true
			minus = a
		end
	end
}

if is_minus == false and minus < as[-1] then
	plus = as[-1]
	kabu = wallet / minus
	wallet = (wallet - kabu * minus) + kabu * plus
end

puts wallet



Measured memory_bytes: 14300
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 998244353
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll> > vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

bool prime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

ll addmod(ll a,ll b)
{
    if(a+b<mod)return a+b;
    else return a+b-mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll modinv(ll a)
{
    return modexp(a,mod-2,mod);
}

bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    return a.fi>b.fi;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll n,k; cin>>n>>k;
ll sum = 0;
vi arr(n);
rep(i,0,n)cin>>arr[i],sum+=arr[i];
sort(all(arr),greater<ll>());


ll x = sum/(4*k);
if(sum%(4*k))x++;
ll cnt = 0;
rep(i,0,n)
{
    if(arr[i]>=x)cnt++;
}
if(cnt>=k)cout<<"Yes\n";
else cout<<"No\n";
return 0;
}
/*
6
1 2 3 4 5 -6
*/


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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int L = A + B;
    int R = C + D;
    if(L > R) cout << "Left" << endl;
    else if(L == R) cout << "Balanced" << endl;
    else cout << "Right" << endl;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i=0; i<4; i++) {
        string ani;
        if (i == 0) ani = "SS";
        else if (i == 1) ani = "WW";
        else if (i == 2) ani = "SW";
        else ani = "WS";
        for (int j=1; j<n-1; j++) {
            char pre = *(ani.end() - 2);
            if (s.at(j) == 'o') {
                if (ani.back() == 'S') {
                    ani.push_back(pre);
                } else {
                    if (pre == 'S') ani.push_back('W');
                    else ani.push_back('S');
                }
            } else {
                if (ani.back() == 'S') {
                    if (pre == 'S') ani.push_back('W');
                    else ani.push_back('S');
                } else {
                    ani.push_back(pre);
                }
            }
        }
        bool ok = true;
        if (ani.front() == 'S') {
            if (s.front() == 'o' && ani.at(1) != ani.back()) ok = false;
            if (s.front() == 'x' && ani.at(1) == ani.back()) ok = false;
        } else {
            if (s.front() == 'o' && ani.at(1) == ani.back()) ok = false;
            if (s.front() == 'x' && ani.at(1) != ani.back()) ok = false;
        }
        if (ani.back() == 'S') {
            if (s.back() == 'o' && *(ani.end()-2) != ani.front()) ok = false;
            if (s.back() == 'x' && *(ani.end()-2) == ani.front()) ok = false;
        } else {
            if (s.back() == 'o' && *(ani.end()-2) == ani.front()) ok = false;
            if (s.back() == 'x' && *(ani.end()-2) != ani.front()) ok = false;
        }

        if (ok) {
            cout << ani << "\n";
            return;
        }
    }
    cout << -1 << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 748
#include <iostream>
using namespace std;
int main(void){
    int a, b;
    cin >> a >> b;
    if(a > b) {
        cout << "a > b" << endl;
    }
    else if(a < b) {
        cout << "a < b" << endl;
    }
    else {
        cout << "a == b" << endl;
    }
}



Measured memory_bytes: 3108
from collections import deque
H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1; Cw -= 1; Dh -= 1; Dw -= 1;
S = []

for _ in range(H):
    S.append(input())

dq = deque()
dq.append((Cw, Ch))

dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

visited = [[-1 for _ in range(W)] for _ in range(H)]
visited[Ch][Cw] = 0
while dq:
    x, y = dq.popleft()

    #コスト無しで行けるエリアを列挙
    for dx_, dy_ in zip(dx, dy):
        if (not 0 <= x+dx_ < W) or (not 0 <= y+dy_ < H):
            continue
        if S[y+dy_][x+dx_] == "#":
            continue
        #まだ訪れていない or 実はノーコストで到達可能な点だった
        if visited[y+dy_][x+dx_] == -1 or visited[y+dy_][x+dx_] > visited[y][x]:
            visited[y+dy_][x+dx_] = visited[y][x]
            dq.appendleft((x+dx_, y+dy_))

    for i in range(-2, 3):
        for j in range(-2, 3):
            if (not 0 <= x+i < W) or (not 0 <= y+j < H):
                continue
            if S[y+j][x+i] == '#':
                continue

            if visited[y+j][x+i] == -1:
                visited[y+j][x+i] = visited[y][x] + 1
                dq.append((x+i, y+j))

ans = visited[Dh][Dw]
print(ans)


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

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No")
	{
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

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

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;

int main()
{
	string s;
	cin >> s;
	if (s.size() == 2) {
		if (s[0] == s[1]) {
			cout << 1 << " " << 2 << endl;
		}
		else {
			cout << -1 << " " << -1 << endl;
		}
		return 0;
	}
	for (int i = 0; i < s.size() - 2; i++) {
		if (s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2]) {
			cout << i+1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
}



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

int main() {
    // 2以上差がある場合は必ず隣り合ってしまうので0になる
    // 1差がある場合は、先頭に来るのが猿か犬か多い方に必ず決まる。
    // なので、犬の並べ方の組み合わせ N! * 猿の並べ方の組み合わせ M!になる
    // 同数の場合は その組み合わせに加えてどちらが先頭に来るかが考えに加わるので 2 * N! * M! になる
    int N, M;
    cin >> N >> M;
    int sa = abs(N - M);
    if (sa >= 2) {
        cout << 0 << endl;
        return 0;
    }

    bool dousuu = M == N;
    int64_t ans = 1;
    while (N > 0) {
        ans = ans * N % int(pow(10, 9.0) + 7);
        N = N - 1;
    }

    while (M > 0) {
        ans = ans * M % int(pow(10, 9.0) + 7);
        M = M - 1;
    }

    if (dousuu) {
        ans = ans * 2 % int(pow(10, 9.0) + 7);
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

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

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;



template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  u64 &value() noexcept { return a; }
  u64 &value() const noexcept { return a; }
  modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  modint pow(u64 exp){
    modint res=1,rhs=*this;
    while (exp) {
      if (exp % 2) {
        res *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return res;
  }

  friend ostream& operator<<(ostream& os,modint& rhs){
    os << rhs.value();
    return os;
  }

  friend istream& operator>>(istream &is,modint &rhs){
      is>>rhs.value();
      rhs.value()%=Modulus;
      return is;
  }

};

using mint=modint<(int)1e9+7>;
struct factorial{
  vector<mint>fact,inv;
  factorial(int n){
    fact.assign(n,0);
    inv.assign(n,0);
    fact[0]=1;
    for(int i=0;i<n-1;i++){
      fact[i+1]=fact[i]*(i+1);
    }
    inv[n-1]=(mint)1/fact[n-1];
    for(int i=n-1;i>=1;i--){
      inv[i-1]=inv[i]*i;
    }
  }
  mint comb(int a,int b){
    if(b>a||b<0)return 0;
    return fact[a]*inv[b]*inv[a-b];
  }

};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  if(k>=n){
    k=n-1;
  }
  factorial f(1e6);
  mint res=0;
  rep(i,k+1){
    res+=f.comb(n-1,i)*f.comb(n,i);
  }
  cout<<res<<endl;





  return 0;

}


Measured memory_bytes: 15872
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

int main(){
  ll N;
  cin>>N;
  
  bool sign=false;
  if(N<0) {sign=true;N=N*(-2);}
  if(N==0) {cout<<0<<endl;return  0;}
  bitset <100> bit = N;
  




  vector <int> base(0);

  for(int i=0;i<100;i++){
    base.push_back(bit[i]);
    //cout<<bit[i];
  }
//  cout<<endl;

//cout<<"#########"<<endl;


// -2based
  for(int i=0;i<=99;i++){
    if(i%2==1){
      if(base[i]==1){
        base[i+1]++;
       
      
      }
     
    }
     //cout<<base[i];//<<endl;

  }
  //cout<<endl;

 //cout<<"#########"<<endl;



  while(true){
    bool flag=true;
    vector <int> save=base;


    for(ll i=0;i<base.size();i++){
      if(base[i]==2 and base[i+1]==1 ){
        base[i]=0;
        base[i+1]=0;
      }
    }
/*
     for(int i=0;i<base.size();i++){
      if(base[i] == save[i]) continue;
      else flag=false;
      if(base[i]>=4) cout<<"異常"<<endl;
    } */
    

    for(ll i=0;i<=base.size()-1;i++){
      if(base[i]==2){
        base[i+1]++;
        base[i+2]++;
        base[i]=0;
        break;
      }
    }

     /*for(int i=0;i<base.size();i++){
      if(base[i] == save[i]) continue;
      else flag=false;
      if(base[i]>=4) cout<<"異常"<<endl;
    }*/



     for(ll i=0;i<base.size();i++){
      if(base[i]== 2*base[i+1] ){
        base[i]=0;
        base[i+1]=0;
      }

      
    }

    //cout<<1<<endl;
    for(int i=0;i<base.size();i++){
      if(base[i] == save[i]) continue;
      else flag=false;
      //if(base[i]>=4) cout<<"異常"<<endl;
    }

  //for(int i=0;i<base.size();i++){
    //cout<<base[i];
 // }
 // cout<<endl;
    if(flag) break;
    
  }

  //cout<<1234<<endl;

  if(sign){
    base.erase(base.begin());
    bool flag=false;
    for(int i=base.size()-1;i>=0;i--){
      if(flag){
        cout<<base[i];
        
      } else {
        if(base[i]==1){
          flag=true;
          cout<<base[i];
        }
      }
      
    }
    
  } else {
    
    //base.erase(base.begin());
    bool flag=false;
    for(int i=base.size()-1;i>=0;i--){
      if(flag){
        cout<<base[i];
        
      } else {
        if(base[i]==1){
          flag=true;
          cout<<base[i];
        }
      }
      
    }
    
  }
  cout<<endl;
  
  
  
  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
R, B = 2.times.map { N.times.map{ gets.split.map(&:to_i) } }
G = Array.new(N) { [] }
M = Array.new(2 * N, -1)
USED = Array.new(2 * N, false)

R.each_index do |i|
  B.each_index do |j|
    r = R[i]
    b = B[j]
    G[i] << N + j if r[0] < b[0] && r[1] < b[1]
  end
end

def matching(u)
  USED[u] = true
  G[u].find do |v|
    w = M[v]
    if w < 0 || (!USED[w] && matching(w))
      M[u] = v
      M[v] = u
    end
  end
end

flow = 0
loop do
  USED.fill(false)
  f = N.times.count{|u| M[u] < 0 && matching(u) }
  if f.zero?
    break
  else
    flow += f
  end
end
puts flow




Measured memory_bytes: 3964
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
using namespace std;

typedef long long ll;
int app[55][26];
int ans[26];
int main() {
  int n; cin >> n;
  string s[55];
  string a = "";
  for ( int i = 0; i < 26; i++ ) ans[i] = 100;
  
  for ( int i = 0; i < n; i++ ) {
    cin >> s[i];
  }

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < s[i].length(); j++ ) {
      app[i][s[i][j]-'a']++;
    }
  }

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < 26; j++ ) {
      ans[j] = min(ans[j],app[i][j]);
    }
  }
  /*
  for ( int i = 0; i < 26; i++ ) {
    cout << ans[i] << " ";
  }
  cout << endl;
  */
  for ( int i = 0; i < 26; i++ ) {
    if ( ans[i] > 0 ) {
      for ( int j = 0; j < ans[i]; j++ ) {
	//cout << "======" << i+'a' << endl;
	a += i+'a';
      }
    }
  }

  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

int main()
{
    int is_possible = true;

    typedef vector <int> v_int;
    vector <v_int> matrix (4, v_int(4, 0));

    for(int i = 1; i <= 3; i++)
        for(int j = 1; j <= 3; j++)
            scanf("%d", &matrix[i][j]);

    vector <int> row_sum(4, 0);
    for(int i = 1; i <= 3; i++)
        for(int j = 1; j <= 3; j++)
            row_sum[i] += matrix[i][j];

    sort(all(row_sum));
    vector <int> A(4);

    vector <int> column_sum(4, 0);
    for(int i = 1; i <= 3; i++)
        for(int j = 1; j <= 3; j++)
            column_sum[j] += matrix[i][j];

    sort(all(column_sum));
    vector <int> B(4);

    if( !((row_sum[1] - row_sum[2])%3 == 0 && (row_sum[2] - row_sum[3])%3 == 0 && (row_sum[1] - row_sum[3])%3 == 0) )
    {
        is_possible = false; //printf("R");
    }

    if( !((column_sum[1] - column_sum[2])%3 == 0 && (column_sum[2] - column_sum[3])%3 == 0 && (column_sum[1] - column_sum[3])%3 == 0) )
    {
        is_possible = false; //printf("C");
    }

    if( matrix[1][1]  + matrix[3][3] != matrix[3][1] + matrix[1][3])
    {
        is_possible = false;
    }




    printf(is_possible ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256