akhauriyash/Code-Regression huggingface dataset:
using System;

class quiz
{
    public int solve(int N, int[] a)
    {
        int ave = 0, ans = 0;

        for (int i = 0; i < N; i++)
        {
            ave += a[i];
        }

        if((double)ave/N < (double)((int)ave/N) + 0.5)
        {
            ave = ave / N;
        }
        else
        {
            ave = ave / N + 1;
        }

        for (int i = 0; i < N; i++)
        {
            ans += (a[i] - ave) * (a[i] - ave);
        }

        return ans;
    }

    public int[] ParseIntBySpace(string str)
    {
        int[] array = new int[str.Length];
        int lastloc = 0, spaceloc = -1;

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == ' ')
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc - 1));
                spaceloc = i;
            }
            else if (i == str.Length - 1)
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc));
            }
        }

        Array.Resize(ref array, lastloc);

        return array;
    }
}

class Example
{
    static void Main()
    {
        quiz ex = new quiz();

        //while (true)
        Console.WriteLine(ex.solve(int.Parse(Console.ReadLine()),ex.ParseIntBySpace(Console.ReadLine())));
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll A,B,C,X;
    cin >>A>>B>>C>>X;
    ll ans=0;
    rep(i,A+1){
        rep(j,B+1){
            ll m=500*i+100*j;
            if(X-m<0){
                continue;
            }
            if((X-m)%50==0 && (X-m)/50<=C){
                ans++;
            }
        }
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3572
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();
       	int add=a+b;
      	int sub=a-b;
      	int mul=a*b;
      
      if(add>=sub){
        if(add>=mul){
          // 出力
		System.out.println(add);
        }else{
           System.out.println(mul);
        }
      }
      else{
             if(sub>=mul){
          // 出力
		System.out.println(sub);
        }else{
           System.out.println(mul);
             }
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int) i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}

const int N=1e5+10;
ll a[N<<4];
int sum[11];
main(){
    ios
    int h,w,n;scanf("%d%d%d",&h,&w,&n);
    h-=2,w-=2;
    int x;int y;
    int cnt=0;
    ll m=(ll)h*w;
    rep(iii,n){
        scanf("%d%d",&x,&y);
        rep(i,3)if( x-i>=1 && x-i<=h){
            rep(j,3)if(y-j>=1 && y-j<=w){
            a[cnt++]=((ll)(x-i)<<32)+(y-j);
            }
        }
    }
    sort(a,a+cnt);
    ll t=1;
    rep(i,cnt){
        if(a[i]==a[i+1])t++;
        else sum[t]++,t=1,m--;
    }
    cout<<m<<" ";
    rep2(i,1,9)cout<<sum[i]<<" ";
}



Measured memory_bytes: 8448
N = int(input())
a_list = [int(i) for i in input().split(' ')]
b_list = [int(i) for i in input().split(' ')]
c_list = [int(i) for i in input().split(' ')]

manzoku = 0
last_order = -1
for order in a_list:
    manzoku += b_list[order - 1]
    if order == last_order + 1:
        manzoku += c_list[last_order - 1]
    last_order = order

print(manzoku)


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

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

  int x, n;
  cin >> x >> n;

  set<int> s;
  for (int i = 0; i < n; ++i) {
    int p;
    cin >> p;

    s.emplace(p);
  }

  int ans = 0;

  for (int i = -1; i <= 101; ++i) {
    if (s.count(i)) continue;

    if (abs(ans - x) > abs(i - x)) ans = i;
  }

  cout << ans << '\n';

  return (0);
}


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

int N;
vector<int> G[100010];
int dep[100010];
int sub[100010];

int DFS(int v,int p,int d)
{
    int res = 1;
    dep[v] = d;
    for(int i = 0; i < G[v].size(); i++)
    {
        int w = G[v][i];
        if(w == p)continue;
        res += DFS(w,v,d + 1);
    }
    sub[v] = res;
    return res;
}

vector<int> con(int v)
{
    vector<int> res;
    int now = v,bef = 0;
    while(now)
    {
        int nex = 0;
        int cnt = 0;
        for(int i = 0; i < G[now].size(); i++)
        {
            int w = G[now][i];
            if(w == bef)continue;
            if(sub[w] > 1)nex = w;
            else cnt++;
        }
        res.push_back(cnt);
        bef = now;
        now = nex;
    }
    return res;
}

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N - 1; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int L,R;

    memset(dep,-1,sizeof(dep));
    memset(sub,-1,sizeof(sub));
    DFS(1,0,0);
    int MAX = 0,id;
    for(int i = 0; i <= N; i++)if(MAX < dep[i])
    {
        MAX = dep[i];
        id = i;
    }
    L = id;
    memset(dep,-1,sizeof(dep));
    memset(sub,-1,sizeof(sub));
    DFS(L,0,0);
    MAX = 0;
    for(int i = 1; i <= N; i++)if(MAX < dep[i])
    {
        MAX = dep[i];
        id = i;
    }
    R = id;

    int now = L,bef = 0;
    while(now)
    {
        int nex = 0;
        for(int j = 0; j < G[now].size(); j++)
        {
            int w = G[now][j];
            if(w == bef)continue;
            if(sub[w] > 1)
            {
                if(nex)
                {
                    printf("-1\n");
                    return 0;
                }
                nex = w;
            }
        }
        bef = now;
        now = nex;
    }

    DFS(L,0,0);
    vector<int> vL = con(L);
    DFS(R,0,0);
    vector<int> vR = con(R);

    int st = L;
    for(int i = 0; i < vL.size(); i++)
    {
        if(vL[i] < vR[i])
        {
            st = L;
            break;
        }
        if(vL[i] > vR[i])
        {
            st = R;
            break;
        }
    }
    vector<int> V,ans;
    if(st == L)V = vL;
    else V = vR;

    int top = 1;
    for(int i = 0; i < V.size(); i++)
    {
        if(V[i] == 0)ans.push_back(top++);
        else
        {
            for(int j = 0; j < V[i]; j++)
            {
                ans.push_back(top + j + 1);
            }
            ans.push_back(top++);
            top += V[i];
        }
    }

    swap(ans[N - 1],ans[N - 2]);

    for(int i = 0; i < N; i++)
    {
        printf("%d",ans[i]);
        if(i != N - 1)printf(" ");
    }printf("\n");
    return 0;
}


Measured memory_bytes: 16504
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define deba(a) cout << #a << " " << a << endl;
int main()
{
	fast;
#ifndef ONLINE_JUDGE
	freopen("/home/kushagra/Desktop/Kushagra/input.txt", "r", stdin);
	freopen("/home/kushagra/Desktop/Kushagra/output.txt", "w", stdout);
#endif
	string s;
	cin >> s;
	ll x = 0;
	rep(i, 0, s.size())
	{
		x += (s[i] - '0');
	}
	// deba(x);
	if (x % 9 == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 3704
n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
 cnt[i] +=1
 sum+=i
  
q=int(input())
ans=0
 
for j in range(q):
 x,y=map(int,input().split())
 sum+=(y-x)*cnt[x]
 cnt[y]+=cnt[x]
 cnt[x]=0
 print(sum)

Measured memory_bytes: 21084
#include <stdio.h>
#include <iostream>
// #include <math.h>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int N;
  cin >> N;
  print(N*800 - 200*(N/15));

}


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

import static java.lang.System.in;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt(), K=sc.nextInt(), Q=sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        HashSet<Integer> vis = new HashSet<>();
        PriorityQueue<Integer> small = new PriorityQueue<>(), big = new PriorityQueue<>();
        int ans = Integer.MAX_VALUE;
        for(int i=0;i<n;i++){
            if(!vis.add(a[i])) continue;
            big.clear();
            int left=0;
            while(left<n){
                if(a[left]<a[i]) {
                    left++;
                    continue;
                }
                small.clear();
                while(left<n&&a[left]>=a[i]){
                    small.add(a[left++]);
                }
                while(small.size()>=K) big.add(small.poll());
            }
            if(big.size()<Q) continue;
            for(int j=1;j<Q;j++) big.poll();
            ans = Math.min(ans,big.peek()-a[i]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 49276
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;
int MX=1e2;
const int NX = 1e7;
int main(){
    int a,b,c;cin>>a>>b>>c;
    int dp[MX][MX][MX];
    fol(i,MX)fol(j,MX) fol(k,MX) dp[i][j][k]=NX;
    dp[a][b][c]=0;int buf;
    MX -=2;
    for(int i=a;i<MX;i++) for(int j=b;j<MX;j++) for(int k=c;k<MX;k++) {
        buf = dp[i][j][k];
        dp[i+1][j+1][k]=min(dp[i+1][j+1][k],buf+1);
        dp[i+1][j][k+1]=min(dp[i+1][j][k+1],buf+1);
        dp[i][j+1][k+1]=min(dp[i][j+1][k+1],buf+1);
        dp[i+2][j][k]=min(dp[i+2][j][k],buf+1);
        dp[i][j+2][k]=min(dp[i][j+2][k],buf+1);
        dp[i][j][k+2]=min(dp[i][j][k+2],buf+1);
    }
    int ans = NX;
    fol(i,MX){
        ans = min(ans,dp[i][i][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4224
#include<iostream>
using namespace std;
 
int main(){
	 
  	double a, b;
  	
  	while(cin >> a >> b) {
 	
  	if(a <35.50 && b < 71.00)
	cout <<"AAA\n";
	
	else if(a < 37.50 && b < 77.00)
	cout <<"AA\n";
	
    else if(a < 40.00 && b < 83.00)
	cout <<"A\n";
	
    else if(a < 43.00 && b < 89.00)
	cout <<"B\n";
	
    else if(a < 50.00 && b < 105.00)
	cout <<"C\n";
	
    else if(a < 55.00 && b < 116.00)
	cout <<"D\n";
	
    else if(a < 70.00 && b < 148.00)
	cout <<"E\n";
	
    else 
	cout << "NA\n";
  }
  	return 0;
}


Measured memory_bytes: 3084
#include<stdio.h>
int main(viud) {
    int a, b, n, i, j, x, y, key[100][100];
    scanf("%d %d", &a, &b);
    while (1) {
        for ( i = 1; i <= a; i++ ) {
            for ( j = 1; j <= b; j++ ) key[j][i] = 1;
        }
        scanf("%d", &n);
        for ( i = 1; i <= n; i++ ) {
            scanf("%d %d", &x, &y);
            key[y][x] = 0;
           /* printf("key[%d][%d]:%d\n", y, x, key[y][x]);*/
        }
        key[0][1] = 1;
        for ( i = 1; i <= b; i++ ) {
            for ( j = 1; j <= a; j++ ) {
                if ( key[i][j] != 0 ) {
                    key[i][j] = key[i][j - 1] + key[i - 1][j];
                    /*printf(" key[%d][%d]:%d key[%d][%d]:%d\n", i, j-1, key[i][j-1], i-1, j, key[i-1][j]);*/
                }
                /*printf("key[%d][%d]:%d\n", i, j, key[i][j]);*/
            }
        }
        printf("%d\n", key[b][a]);
        scanf("%d %d", &a, &b);     
        if ( a == 0 && b == 0)break;   
    }
    return 0;
}

Measured memory_bytes: 1816
//Moh_K_Imar .......
//24/08/2020  ... 5,38 .
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ld a,b;
    cin>>a>>b;
    cout<<ceil(a/b)<<endl;

    return 0;
}



Measured memory_bytes: 3756
import java.util.*;
 
 
public class Main {
	public static void main (String[] args){
		Scanner sc =  new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long Q = N/(A+B);
		long ex = N%(A+B);
		long R = 0;
		if(A > 0) {
			if(ex < A) {
				R = A * Q + ex;
			}
			else if(ex >= A) {
				R = (Q+1) * A;
			}
		}
		System.out.println(R);
	}
}

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

using namespace std;

int main() {
	char x[5];
	char y[5];
	scanf("%s%s", x, y);
	if (x[0] == y[0]) printf("=\n");
	else printf("%c\n", (x[0] < y[0]) ? '<' : '>');
	return 0;
}

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

class Console {
    static Console instance;
    final BufferedReader reader;

    public static Console getInstance() {
        if (instance == null) {
            instance = new Console();
        }
        return instance;
    }
    
    public Console() {
        reader = new BufferedReader(new InputStreamReader(System.in));
    }

    public int readInt() throws IOException {
        return Integer.parseInt(reader.readLine());
    }

    public int[] readLineNumbers(int n) throws IOException {
        String[] numStrings = reader.readLine().split(" ");
        int[] result = new int[n];
        for (int i = 0;i < n;i++) {
            result[i] = Integer.parseInt(numStrings[i]);
        }
        return result;
    }
    
    public void output(int n) {
        System.out.println(n);
    }
}

public class Main {
    public static void main(String[] args) throws Exception {
        int n = Console.getInstance().readInt();
        int[] S = Console.getInstance().readLineNumbers(n);
        int q = Console.getInstance().readInt();
        int[] T = Console.getInstance().readLineNumbers(q);
        
        int count = 0;
        for (int i = 0;i < q;i++) {
            int t = T[i];
            int min = 0;
            int max = n - 1;

            while (min <= max) {
                int index = (min + max) / 2;
                if (S[index] == t) {
                    count++;
                    break;
                } else if (min == max) {
                    // not found
                    break;
                } else if (S[index] > t) {
                    max = index - 1;
                } else if (S[index] < t) {
                    min = index + 1;
                }
            }
        }

        Console.getInstance().output(count);
    }
}

Measured memory_bytes: 48208
def e_cell_distance(N, M, K, MOD=10**9 + 7):
    class Combination(object):
        """
        組み合わせ
        参考: https://harigami.net/contents?id=5f169f85-5707-4137-87a5-f0068749d9bb
        """
        __slots__ = ["mod", "factorial", "inverse"]

        def __init__(self, max_n: int = 10**6, mod: int = 10**9 + 7):
            fac, inv = [1], []
            fac_append, inv_append = fac.append, inv.append

            for i in range(1, max_n + 1):
                fac_append(fac[-1] * i % mod)

            inv_append(pow(fac[-1], mod - 2, mod))

            for i in range(max_n, 0, -1):
                inv_append(inv[-1] * i % mod)

            self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]

        def combination(self, n, r):
            if r == n or r == 0:
                return 1
            if r > n:
                return 0
            return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod

    comb = Combination(N * M).combination(N * M - 2, K - 2)
    t1 = sum([d * (M - d) * (N**2) for d in range(1, M)])
    t2 = sum([d * (N - d) * (M**2) for d in range(1, N)])
    t = (t1 + t2) % MOD
    return (comb * t) % MOD

N, M, K = [int(i) for i in input().split()]
print(e_cell_distance(N, M, K))

Measured memory_bytes: 20524
package main

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

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,1000)}
  n := input.NextInt()
  l := make([]*Edge,n-1)
  for i:=0;i<n-1;i++ {
    a,b := input.NextInts()
    l[i] = &Edge{[]int{a-1,b-1},[]int{0,0},0}
  }
  s := input.NextIntArray()
  t := NewGraph(n)
  for i:=0;i<n-1;i++ {
    t.AddEdge(l[i].x[0],l[i])
    t.AddEdge(l[i].x[1],l[i])
  }
  used := make([]bool,n)
  var dfs func(int) int
  dfs = func(v int) int {
    used[v] = true
    ret := 1
    for _,e := range t[v] {
      i := 0
      if e.x[0] == v { i = 1 }
      if used[e.x[i]] { continue }
      e.y[i] = dfs(e.x[i])
      e.y[1-i] = n-e.y[i]
      ret += e.y[i]
    }
    return ret
  }
  dfs(0)
  nd := -1
  for i:=0;i<n-1;i++ {
    if l[i].y[0] == l[i].y[1] { nd = i;continue }
    l[i].cost = (s[l[i].x[1]]-s[l[i].x[0]])/int64(l[i].y[0]-l[i].y[1])
  }
  var dfs2 func(int) int64
  dfs2 = func(v int) int64 {
    used[v] = true
    ret := int64(0)
    for _,e := range t[v] {
      i := 0
      if e.x[0] == v { i = 1 }
      if used[e.x[i]] { continue }
      ret += dfs2(e.x[i])
      ret += e.cost*int64(e.y[i])
    }
    return ret
  }
  if nd != -1 {
    for i:=0;i<n;i++ { used[i] = false }
    l[nd].cost = (s[l[nd].x[0]]-dfs2(l[nd].x[0]))/int64(l[nd].y[0])
  }
  for i:=0;i<n-1;i++ { fmt.Println(l[i].cost) }
}

type Edge struct { x,y []int;cost int64 }
type Graph [][]*Edge
func NewGraph(n int) Graph { return make([][]*Edge,n) }
func(g Graph) AddEdge(from int,e *Edge) { g[from] = append(g[from],e) }

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int {
  n,_ := strconv.Atoi(i.NextLine())
  return n
}
func(i *Input) NextInts() (int,int) {
  s := strings.Fields(i.NextLine())
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}
func(i *Input) NextIntArray() []int64 {
  s := strings.Fields(i.NextLine())
  a := make([]int64,len(s))
  for i:=0;i<len(s);i++ { a[i],_ = strconv.ParseInt(s[i],10,64) }
  return a
}

Measured memory_bytes: 77056
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X) for(long int I=X;I>=0;I--)
#define INF 1000000007
using namespace std;

int p[3][3];

int main(){
  p[0][1]=3;
  p[0][2]=6;
  p[1][1]=2;
  p[1][2]=2;
  p[2][1]=1;
  p[2][2]=3;
  int N;
  string s,S2;
  long int ans = 1;
  cin >> N >> s >> S2;
  vector<int> v(1,0);
  FOR(i,0,N){
    if(s[i] == s[i+1]){
      v.push_back(2);
      i++;
    }
    else{
      v.push_back(1);
    }
  }
  FOR(i,0,v.size()-1){
    ans *= p[v[i]][v[i+1]];
    ans %= INF;
  }
  cout << ans << endl;
}

//0→2 6
//0→1 3
//2→1 1
//2→2 3
//1→1 2
//1→2 2


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

vector<int> prime;
bool is_prime[100100 + 1];

int sieve(int n) {//n以下の素数の数を返す
	int p = 0;
	for (int i = 0; i <= n; i++)is_prime[i] = 1;
	is_prime[0] = is_prime[1] = 0;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime.push_back(i);
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = 0;
		}
	}
	return p;
}

int n;
int sum[100100];

int main() {
	sieve(100100);
	rep(i, 100100)sum[i] = (is_prime[i] && is_prime[(i + 1) / 2]);
	rep(i, 100100 - 1)sum[i + 1] += sum[i];
	cin >> n;
	rep(i, n) {
		int l, r;
		cin >> l >> r;
		cout << sum[r] - sum[l - 1] << endl;
	}
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

ll memo[210000];
bool ok[210000];
ll dfs(ll n) {
    if(ok[n]) return memo[n];
    if(n == 0) {
        memo[n] = 0;
        ok[n] = true;
        return memo[n];
    }
    if(n == 1) {
        memo[n] = 1;
        ok[n] = true;
        return memo[n];
    }

    ll next = n % __builtin_popcountll(n);
    memo[n] = dfs(next) + 1;
    ok[n] = true;
    return memo[n];
}

ll beki(ll a, ll b, ll m){
    a %= m;
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2, m);
    ans = ans * ans % m;
    if(b % 2 == 1){
        ans = ans * a % m;
    }
    return ans;
}

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

    ll N;
    string X;
    cin >> N >> X;

    ll p = 0;
    for(auto c : X) if(c == '1') p++;
    ll p1 = max(p-1, 0ll), p2 = p+1;
    ll tot1 = 0, tot2 = 0;
    rep(i, N) {
        if(X[i] == '1') {
            if(p1 > 0) tot1 += beki(2, N-1-i, p1);
            tot2 += beki(2, N-1-i, p2);
        }
    }

    vll ans(N);
    rep(i, N) {
        if(X[i] == '0') {
            ll tmp = tot2 + beki(2, N-1-i, p2);
            tmp %= p2;
            ans[i] = dfs(tmp) + 1;
        }
        else {
            if(p1 == 0) {
                ans[i] = 0;
                continue;
            }
            ll tmp = tot1 - beki(2, N-1-i, p1);
            if(tmp < 0) tmp += p1;
            tmp %= p1;
            ans[i] = dfs(tmp) + 1;
        }
    }
    rep(i, N) cout << ans[i] << endl;
}


Measured memory_bytes: 5876
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	k := getNextInt(scanner)

	cuteyYosupot := make([]int, 0)
	rn := 0
	for i := 1; i <= n/i; i++ {
		rn = i
		if i < n/i {
			cuteyYosupot = append(cuteyYosupot, n/i)
		}
	}
	cc := len(cuteyYosupot)
	cuteyYosupot = append(cuteyYosupot, n/(cc+1))

	for i := 0; i < cc; i++ {
		cuteyYosupot[i] -= cuteyYosupot[i+1]
	}
	cuteyYosupot = cuteyYosupot[0:cc]
	dp := makeInts(k, rn+cc+1)
	for i := 1; i <= rn; i++ {
		dp[0][i] = dp[0][i-1] + 1
	}
	for i := 0; i < cc; i++ {
		dp[0][rn+i+1] = dp[0][rn+i] + int64(cuteyYosupot[cc-1-i])
	}

	mod := int64(1e9 + 7)
	for d := 1; d < k; d++ {
		for i := 1; i <= rn; i++ {
			dp[d][i] = dp[d][i-1] + dp[d-1][rn+cc+1-i]
			dp[d][i] %= mod
		}
		for i := 0; i < cc; i++ {
			dp[d][rn+i+1] = (dp[d][rn+i] + dp[d-1][cc-i]*int64(cuteyYosupot[cc-1-i])) % mod
		}
	}

	fmt.Fprintln(writer, dp[k-1][rn+cc])

	writer.Flush()
}

func makeInts(h, w int) [][]int64 {
	index := make([][]int64, h, h)
	data := make([]int64, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}


Measured memory_bytes: 53120
#E
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))

R = 0
G = 0
B = 0
ans = -1
count = 1
for i,a in enumerate(A):
    if i == 0:
        if a != 0:
            ans = 0
            break
        else:
            R = 1
            count*=3
    else:
        if R == a and G == a and B == a:
            count*=3
            R+=1
        elif R == a and G == a:
            count*=2
            R+=1
        elif R == a and B == a:
            count*=2
            R+=1
        elif G == a and B == a:
            count*=2
            G+=1
        elif R == a:
            R+=1
        elif G == a:
            G+=1
        elif B == a:
            B+=1
        else:
            ans = 0
            break
        
            
if ans == 0:
    print(ans)
else:
    ans = count
    print(ans%mod)
        
        

    


Measured memory_bytes: 52996
N, M = map(int, input().split())
MOD = 10**9 + 7
exist = [1 for _ in range(N+2)]
for _ in range(M):
    exist[int(input())] = 0
dp = [0 for _ in range(N+2)]
dp[0] = 1
for i in range(N):
    dp[i+1] = (dp[i+1] + dp[i] * exist[i+1]) % MOD
    dp[i+2] = (dp[i+2] + dp[i] * exist[i+2]) % MOD
print(dp[N])

Measured memory_bytes: 7832
#include<iostream>
using namespace std;
int main(){
	int cantidades[1000000] = {0};
	int a,b;
	cin>>a;
	for(int i = 0; i<a-1; i++){
		cin>>b;
		cantidades[(b-1)]++;
	}
	for(int i = 0; i<a;i++){
		cout<<cantidades[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 7540
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n\r\t', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)

    orは!忘れに注意(末尾再帰なら直前)
*/



main :-
    get_number(N),
    get_chars(S),
    append(X,X,S) -> writeln("Yes") ; writeln("No").

    % statistics(inferences, IC), writeln(IC).


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

namespace ProblemC
{
    class Program
    {
        static void Main(string[] args)
        {
            var buff = GetLongList();
            long N = buff[0];
            long M = buff[1];
            long K = buff[2];

            var A = GetLongList();
            var B = GetLongList();
            long max = 0;
            var sumA = new long[N + 1];
            var sumB = new long[M + 1];
            long temp = 0;
            sumA[0] = 0;
            sumB[0] = 0;
            for(int i = 0; i < N; i++)
            {
                temp += A[i];
                sumA[i + 1] = temp;
            }
            temp = 0;
            for(int i = 0; i < M; i++)
            {
                temp += B[i];
                sumB[i + 1] += temp;
            }

            int index = (int)M;
            for(int i = 0; i <= N; i++)
            {
                for(int j = index; j >= 0; j--)
                {
                    if(sumA[i] + sumB[j] <= K)
                    {
                        max = max < i + j ? i + j : max;
                        index = j;
                        break;
                    }
                }
            }
            Console.WriteLine(max);
        }

        public static int GetInt() => int.Parse(Console.ReadLine());
        public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray();
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static List<long> GetLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();

    }
}


Measured memory_bytes: 72972
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue

#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n, m;
int l, r;

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

    cin >> n >> m;
    l = 1;
    r = n;
    F0R(_, m){
        int cl, cr;
        cin >> cl >> cr;
        l = max(l, cl);
        r = min(r, cr);
    }
    if(r < l) cout << 0;
    else cout << r-l+1;
    cout << "\n";

    return 0;
}


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


def solve(K: int, A: int, B: int):
    for n in range(A, B+1):
        if n % K ==0:
            print('OK')
            return

    print('NG')

    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
	int N;
	cin >> N;

	vector<int> A(N);
	for (int a = 0; a < N; a++) {
		cin >> A[a];
	}
	sort(A.begin(), A.end());
	int alice = 0;
	int bob = 0;
	for (int a = 0; a < N;a++) {
		if (a%2==0) {
			alice += A[a];
		}
		else {
			bob += A[a];
		}
	}
	cout<< abs(alice-bob)<<endl;


}

Measured memory_bytes: 256
#include <iostream> 
#include <iomanip> 
#include <vector> 
#include <algorithm> 
#include <numeric> 
#include <functional> 
#include <cmath> 
#include <queue> 
#include <stack> 

#define Ford(i,a,b) for (int i=(a);i<(b);i++) 
#define For(i,n) Ford(i,0,n) 
typedef long long ll; 

using namespace std;

int main(){
  int N;
  double Money=0.0;
  cin>>N;
  double x[N];
  string u[N];
  for(int i=0;i<N;i++){
    cin>>x[i]>>u[i];
    if(u[i]=="JPY"){
      Money+=x[i];
    }
    else{
      Money+=x[i]*(380000.0);
    }
  }
  cout<<fixed<<setprecision(11)<<Money<<endl;
  return 0;
}






Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
int c=0;
void merge(int*A,int l,int m,int r){
	int *L,*R,n1,n2,i,j,k;
	n1=m-l;
	n2=r-m;
	L=(int*)malloc(sizeof(int)*(n1+1));
	R=(int*)malloc(sizeof(int)*(n2+1));
	for(i=0;i<n1;i++)L[i]=A[l+i];
	for(i=0;i<n2;i++)R[i]=A[m+i];
	L[n1]=R[n2]=INT_MAX;
	i=j=0;
	for(k=l;k<r;k++){
		if(L[i]<=R[j]){
			A[k]=L[i];
			i++;
		}else{
			A[k]=R[j];
			j++;
		}
		c++;
	}
	free(L);free(R);
}
void merge_sort(int*A,int l, int r){
	int m;
	if(l+1<r){
		m=(l+r)/2;
		merge_sort(A,l,m);
		merge_sort(A,m,r);
		merge(A,l,m,r);
	}
}
int main(){
	int i,n,*A;
	scanf("%d",&n);
	A=(int*)malloc(sizeof(int)*(n));
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	merge_sort(A,0,n);
	for(i=0;i<n;i++)printf("%d%c",A[i],i==n-1?'\n':' ');
	printf("%d\n",c);
	return 0;
}

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

int main(){
    int n,T,ans=1005;cin>>n>>T;vector<int> c(n),t(n);
    for(int i=0;i<n;i++){
        cin>>c.at(i)>>t.at(i);
        if(t.at(i)<=T){
            ans=min(ans,c.at(i));
        }
    }
    if(ans==1005) cout<<"TLE"<<endl;
    else cout<<ans<<endl;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n, a, b;cin >> n >> a >> b;
    vector<LL> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    double mmax = 0;
    for(int i=0;i<a;i++){
        mmax += v[i];
    }
    mmax /= a;
    printf("%.8f\n", mmax);

    LL comb[51][51];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(j > i){
                comb[i][j] = 0LL;
            }else if(j == 0 || j == i){
                comb[i][j] = 1LL;
            }else{
                comb[i][j] = comb[i-1][j-1]+comb[i-1][j];
            }
        }
    }
    int l = 0;
    for(l=0;l<n;l++){
        if(v[0] != v[l]) break;
    }
    if(a<=l){
        LL ans = 0;
        for(int i=a;i<=min(b, l);i++){
            ans += comb[l][i];
        }
        printf("%lld\n", ans);
    }else{
        int x = 0;
        int y = 0;
        for(int i=0;i<n;i++){
            if(v[i] == v[a-1]){
                x++;
                if(i<a) y++;
            }
        }
        printf("%lld\n", comb[x][y]);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repr(i, m, n) for (int (i)(m - 1); (i)>=(n); --(i))
#define repv(i, v) for (unsigned (i)(0); (i)<(v.size()); ++(i))
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define sortgi(v) sort(all(v), greater<int>())
#define sortgd(v) sort(all(v), greater<double>())
#define sortgll(v) sort(all(v), greater<ll>())
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using ll = long long;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vpii = vector<pii>;
using pqi = priority_queue<int>;
using pqd = priority_queue<double>;
using pqll = priority_queue<ll>;
using pqvi = priority_queue<vi>;
using pqvll = priority_queue<vll>;

vll prime(ll n) {
	vll p;
	map<ll, ll> mp;
	ll i = 2;
	while (n != 1) {
		while (n % i == 0) {
			n /= i;
			++mp[i];
		}
		++i;
	}
	for (auto j = mp.begin(); j != mp.end(); ++j) {
		p.push_back(j->second);
	}
	return p;
}

// モジュラ逆数 //
ll mod_inv(ll a, ll m) {
    ll b(m), u(1), v(0);
    while (b) {
        ll t(a / b);
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    if (u < 0) {
        u += m;
    }
    return u;
}

ll nCm(ll n, ll m, ll mod) {
	ll a = 1;
	m = min(n-m, m);
	rep(i, 0, m) {
		a *= n - i;
		a %= mod;
	}
	rep(i, 1, m + 1) {
		a *= mod_inv(i, mod);
		a %= mod;
	}
	return a;
}

int main() {
	ll N, M;
	cin >> N >> M;
	vll p = prime(M);
	ll a = 1;
	ll mod = 1e9 + 7;
	repv(i, p) {
		// cout << p[i] << endl;
		a *= nCm(p[i] + N - 1, N - 1, mod);
		a %= mod;
	}
	cout << a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//节点从0到n-1
#define maxn 100006
struct node { double x, y; };
int n;//有多少个点
int tot;//凸包上的点
node p[maxn];//所有点数组从0开始
node P[maxn];//凸包上的点
const double pi = acos(-1.0);
//三点差积	 
double X(node A, node B, node C) { return (B.x - A.x)*(C.y - A.y) - (C.x - A.x)*(B.y - A.y); }
//两点距离
double len(node A, node B) { return sqrt((A.x - B.x)*(A.x - B.x) + (A.y - B.y)*(A.y - B.y)); }
//角度小的在前面,相同的话距离小的在前面
bool cmp(node A, node B) {
	double pp = X(p[0], A, B);
	if (pp > 0)return true;
	if (pp < 0)return false;
	if (pp == 0)return len(p[0], A) < len(p[0], B);
}
const double eps = 1e-9;
//三点点积	 
double dian(node A, node B, node C) { return (B.x - A.x)*(C.x - A.x) + (C.y - A.y)*(B.y - A.y); }
//建立凸包存到P里//以下是n>=3的情况,n=1,2要特判
void build() {
	//找左下角的点
	for (int i = 0; i < n; i++) {
		if (p[i].y < p[0].y) swap(p[i], p[0]);
		if (p[i].y == p[0].y&&p[i].x < p[0].x) swap(p[i], p[0]);
	}
	sort(p + 1, p + n, cmp);
	P[0] = p[0];
	P[1] = p[1];
	tot = 1;//初始两个点
	for (int i = 2; i < n; i++) {
		//如果需要边上的点 
		while (tot > 0 && X(P[tot - 1], P[tot], p[i]) < 0)tot--;
//		while (tot > 0 && X(P[tot - 1], P[tot], p[i]) <= 0)tot--;//P[tot]在左边 舍弃
		tot++;
		P[tot] = p[i];
	}
	// 如果需要边上点 要这块 
	node endd = P[tot];
	for (int i = n - 1; i >= 0; i--) {
		if (abs(X(P[0], endd, p[i])) <= eps) {
			if (dian(p[i], P[0], endd) < 0) {
				tot++;
				P[tot] = p[i];
			}
		}
		else break;
	}
	// 到这上面是需要注释掉的 
	tot++;
}
int main(){
//	freopen("a.txt","r",stdin);
	scanf("%d",&n);
	for(int i=0;i<n;i++)cin>>p[i].x>>p[i].y;
	build();
	printf("%d\n",tot);
	for(int i=0;i<tot;i++){
		cout<<P[i].x<<' '<<P[i].y<<endl;
	}
	return 0;
}


Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
    cin>>n;
    for(int i=0; i<=n/4; i++) {
        for(int j=0; j<=n/7; j++) {
            if(i*4+j*7==n) {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#! /usr/bin/python3
import copy
H, W, K = map(int, input().strip().split())

grid = []

def count_black(g):
	#print(g)
	res = 0
	for i in g:
		for c in i:
			if c == '#':
				res += 1
	return res


for r in range(H):
	grid.append([x for x in input().strip()])

ans = 0

for i in range(2 ** H):
	for j in range(2 ** W):
		newgrid = copy.deepcopy(grid)

		for k in range(H):
			if ((i & (2 ** k)) > 0):
				newgrid[k] = ['-' for x in range(W)]
		for k in range(W):
			if ((j & (2 ** k)) > 0):
				for ii in range(H):
					newgrid[ii][k] = '-'

		if (count_black(newgrid) == K):
			ans += 1
print(ans)

Measured memory_bytes: 9276
def solve():
    N = int(input())
    Ass = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(N)]

    day = 0
    numMatch = 0
    ps = set(range(N))
    isReadys = [0] * N
    iAs = [-1] * N
    while True:
        day += 1
        p2s = set()
        for p in ps:
            iAs[p] += 1
            if iAs[p] == N-1: continue
            q = Ass[p][iAs[p]]
            if isReadys[q] and Ass[q][iAs[q]] == p:
                isReadys[q] = 0
                p2s.add(p)
                p2s.add(q)
                numMatch += 1
            else:
                isReadys[p] = 1
        if numMatch >= N*(N-1)//2:
            print(day)
            break
        if not p2s:
            print(-1)
            break
        ps = p2s

solve()


Measured memory_bytes: 34548
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/
#define INF 10000000010

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

	int N, K;
	
	cin >> N >> K;

	ll dp[N];
	dp[0] = 0;

	rep(i, N)
	{
		dp[i+1] = INF;
	}

	ll h[N];
	
	rep(i, N)
	{
		cin >> h[i];

		for(int k=1; k <= K; k++)
		{
			if (i - k >= 0)
			{
				dp[i] = min(dp[i], dp[i-k] + abs(h[i]-h[i-k]));
			}
			else
			{
				break;
			}
		}
	}

	cout << dp[N-1]<<endl;

	
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	map<pair<int, int>, int> freq;
	int ans = 0;
	
	for(int i = 1; i <= n; i++) {
		int first, last = -1;
		int x = i;
		while(x) {
			if(last == -1) last = x % 10;
			first = x % 10;
			x /= 10;
		}
		
		freq[make_pair(first, last)]++;
	}
	
	for(int i = 1; i <= n; i++) {
		int first, last = -1;
		int x = i;
		while(x) {
			if(last == -1) last = x % 10;
			first = x % 10;
			x /= 10;
		}
		ans += freq[make_pair(last, first)];
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int a = sc.nextInt();
        int ab = 30;

        if (a >= ab) {
            System.out.println("Yes");
        } else if (a < ab) {
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 35752
N = int(input())
D = {}
for i in range(1, N+1):
  a = i
  dig = 1
  p = 2
  while a != 1:
    j = 0
    while a % p == 0:
      j += 1
      a //= p
      dig *= p
    if j != 0:
      if p in D:
        D[p] += j
      else:
        D[p] = j
    p += 1
    if p > int(i**(1/2)) and dig != i:
      if i//dig in D:
        D[i//dig] += 1
      else:
        D[i//dig] = 1
      break
A = [D[i] for i in D]
A.sort()
L = len(A)
i2, i4, i14, i24, i74 = 0, 0, 0, 0, 0
p2, p4, p14, p24, p74 = 0, 0, 0, 0, 0
j = 0
while j < L:
  if A[j] >= 2 and p2 == 0:
    i2 = j
    p2 = 1
  if A[j] >= 4 and p4 == 0:
    i4 = j
    p4 = 1
  if A[j] >= 14 and p14 == 0:
    i14 = j
    p14 = 1
  if A[j] >= 24 and p24 == 0:
    i24 = j
    p24 = 1
  if A[j] >= 74 and p74 == 0:
    i74 = j
    p74 = 1
  j += 1
S = (L - i74) * p74
S += (L - i2 - 1) * (L - i24) * p2 * p24
S += (L - i4 - 1) * (L - i14) * p4 * p14
S += ((L - i2 - 2) * (L - i4) * (L - i4 - 1) * p2 * p4) // 2
print(S)

Measured memory_bytes: 3188
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    if (n % 2 == 0)
        --n;
    int diff = n / 2;
    vector <pii> ans;
    for (int i = 0, j = diff; i < j; ++i, --j)
        ans.eb(i, j);
    for (int i = diff + 1, j = 2 * diff; i < j; ++i, --j)
        ans.eb(i, j);
    forn (i, 0, m)
        cout << ans[i].fs + 1 << " " << ans[i].sc + 1 << "\n";
    return 0;
}

Measured memory_bytes: 4252