akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define INF 100100100100100

int main(){

    long long n; cin >> n;
    vector<long long> r(n);
    vector<long long> c(n);
    for(long long i = 0; i < n; i++){
        cin >> r[i] >> c[i];
    }

    vector<vector<long long> > dp(n + 1, vector<long long> (n + 1, INF));
    for(int i = 0; i < n; i++) dp[i][i + 1] = 0;
    
    for(int k = 2; k <= n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 1; j < k; j++){
                if(i + k <= n){
                    chmin(dp[i][i + k], dp[i][i + j] + dp[i + j][i + k] + r[i] * c[i + j - 1] * c[i + k - 1]);
                }
            }
        }
    }

    cout << dp[0][n] << endl;
    
    return 0;
}


Measured memory_bytes: 3200
use superslice::Ext;
fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        mut a: [i64;n],
    }
    a.sort();
    let mut b=vec![0;n+1];
    for i in (0..n).rev() {
        b[i]=a[i]+b[i+1];
    }
    let mut l=0;
    let mut r=a[n-1]*2+1;
    let mut s=0;
    while l+1<r {
        let x=(l+r)/2;
        let mut c=0;
        let mut t=0;
        for &v in &a {
            let k=a.lower_bound(&(x-v));
            c+=n-k;
            t+=v*(n-k)as i64+b[k];
        }
        if c<m {
            r=x;
        }
        else {
            l=x;
            s=t-x*(c-m)as i64;
        }
    }
    println!("{}",s);
}

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

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

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  string s ;
  cin >> s ;
  s.at(5) = ' ' ;
  s.at(13) = ' ' ;
  
  cout << s <<endl ;
  
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int sum=0;
    int x=0;
    for(int i=0;i<N;i++)
    {
        cin>>x;
        sum+=x;
    }
    if(sum>=H)
    {
        cout<<"Yes";
    }
    else{cout<<"No";}
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define sort(a) sort(a.begin(), a.end())
#define loop(n) for(ll i = 0; i<n; i++)
using namespace std;

int first(ll n){
    int digits = log10(n);
    n = n/pow(10, digits);
    return n;
}

int main(){
    int n, f, l; cin>>n;
    //pair<int, int> p;
    map<pair<int, int>, ll> m;
    for(ll i = 1; i<=n; i++){
        l = i%10;
        f = first(i);
        m[{f,l}]++;
    }

    ll ans = 0;
    for(int i = 0; i<10; i++){
        for(int j = 0; j<10; j++) ans += m[{i,j}]*m[{j,i}];
    }

    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

signed main(){
	int A,V,B,W,T;
	cin>>A>>V>>B>>W>>T;
	if(B<A)swap(A,B);
	int rea=A+V*T,reb=B+W*T;
	if(rea>=reb)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){

	int e;
	int y_max,z_max;
	int j,k;
	int answer;
	int x,y,z;
	while(1){
		

		answer = 10000000;

		scanf("%d",&e);
		if(e == 0){
			break;
		}

		y_max = 1000;
		z_max = 100;

		for(j=0; j<=y_max; j++){
			for(k=0; k<=z_max; k++){

				y = j;
				z = k;

				x = e - y*y - z*z*z;
				//
				if(x >= 0){
					//if(e == x + y*y + z*z*z){
						if(answer > x + y + z){
							answer = x + y + z;
						}
					//}
				}
			}
		}
		printf("%d\n",answer);
	}


}

Measured memory_bytes: 1028
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
v = LI()
v.sort()
ans = v.pop(0)

for i in v:
  ans = (ans+i)/2
print(ans)


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void solve(){
	ll n,x,m,res=0;
	cin>>n>>x>>m;
	vector<ll> v(1,x);
	set<ll> s;
	s.insert(x);
	while(1){
		x=(x*x)%m;
		if(s.find(x)!=s.end())
			break;
		v.push_back(x);
		s.insert(x);
	}
	for(ll i=0;i<min(n,sz(v));i++)
		res+=v[i];
	if(n>sz(v)){
		res=0;
		for(ll i=0;i<sz(v);i++){
			if(x==v[i]){
				n-=i;
				ll sum=0;
				for(ll j=i;j<sz(v);j++)
					sum+=v[j];
				res+=(n/(sz(v)-i))*sum;
				n%=(sz(v)-i);
				for(ll j=i;j<n+i;j++)
					res+=v[j];
				break;
			}
			res+=v[i];
		}
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}


Measured memory_bytes: 5972
n = int(input())
s = input()
ans = 0
for i in range(10):
    for  j in range(10):
        for k in range(10):
            i_index = s.find(str(i))
            if i_index > - 1:
                j_index = s.find(str(j), i_index + 1)
                if j_index > -1:
                    k_index = s.find(str(k), j_index + 1)
                    if k_index > -1:
                        ans += 1
print(ans)

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

tuple<int, int> input_int2() {
	int a, b;
	cin >> a >> b;	
	return forward_as_tuple(a, b);
}

tuple<int, int, int> input_int3() {
	int a, b, c;
	cin >> a >> b >> c;	
	return forward_as_tuple(a, b, c);
}

vector<int> input_int_array(int n,vector<int> vec) {
	for (int i=0,tmp=0; i<n && cin >> tmp; i++) vec[i]=tmp;
	return vec;
}

vector<vector<int>> input_int_matrix(int n, int m, vector<vector<int>> matrix) {
	int tmp;
	for(int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			cin >> tmp;
			matrix[i][j] = tmp;
		}
	}
	return matrix;
}

const int MAX_N = 20;
const int MAX_M = 20;

int A, B;

void input() {
	tie(A, B) = input_int2();
}

void print_matrix(int N, int M, vector<vector<int>> matrix) {
	for(int i=0; i<N; i++){
		for(int j=0; j<M; j++) {
			cout << matrix[i][j] << " ";
		}
		cout << endl;
	}	
}

int solve() {
	return B%A==0 ? A+B : B-A;
}

int main() {
	input();
	cout << solve() << endl;
}


Measured memory_bytes: 632
using System;
using System.Collections.Generic;

public class Program
{
    private static int PlusNum;
    private static long Res;
    private static string Exp;
    public static void Main()
    {
        Exp = Console.ReadLine();
        PlusNum = Exp.Length;
        Res = long.Parse(Exp);
        Solve();
    }

    public static void Solve()
    {
        for (int i = 1; i < PlusNum; i++)
        {
            List<int> plusPoses = new List<int>();
            plusPoses.Add(i);
            Sum(plusPoses);
        }
        Console.WriteLine(Res);
    }

    public static void Sum(List<int> plusPoses_)
    {
        Res += Calc(plusPoses_);
        for (int i = plusPoses_[plusPoses_.Count - 1] + 1; i < PlusNum; i++)
        {
            List<int> plusPoses = new List<int>(plusPoses_);
            plusPoses.Add(i);
            Sum(plusPoses);
        }
    }

    public static long Calc(List<int> plusPoses)
    {
        long res = 0;
        int left = 0;
        for (int i = 0; i < plusPoses.Count; i++)
        {
            int right = plusPoses[i];
            res += long.Parse(Exp.Substring(left, right - left));
            left = right;
        }
        res += long.Parse(Exp.Substring(left, PlusNum - left));
        return res;
    }
}


Measured memory_bytes: 2904
N = int(input().strip())
h = [[0] * (N+1) for i in range(3)]
for i in range(1, N+1):
    a, b, c = map(int, input().split(" "))
    h[0][i] = max(h[1][i-1], h[2][i-1]) + a
    h[1][i] = max(h[0][i-1], h[2][i-1]) + b
    h[2][i] = max(h[0][i-1], h[1][i-1]) + c

print(max(h[0][N], h[1][N], h[2][N]))

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

const int maxn = 3005;
int n, t;
pair<int,int> a[maxn];
int dp[maxn][maxn];

int f(int i, int j) {
    if (j >= t) return 0;
    if (i >= n) return 0;
    if (dp[i][j] >= 0) return dp[i][j];
    dp[i][j] = f(i+1,j);
    dp[i][j] = max(dp[i][j],a[i].second+f(i+1,j+a[i].first));
    //printf("[%d][%d]: %d\n",i,j,dp[i][j]);
    return dp[i][j];
}

int main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    memset(dp,-1,sizeof dp);
    cin >> n >> t;
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a,a+n,[](auto a, auto b) {
            return a.first < b.first;
            });
    int ans = f(0,0);    
    cout << ans << '\n';
}



Measured memory_bytes: 35712
import itertools
N,A,B,C=map(int,input().split())
l=list()
for i in range(N):
    l.append(int(input()))


def solve(x,ans,m):
    global N,A,B,C,l

    c=[10000,-1]
    for i in  range(0,len(l)):
        if(abs(l[i]-x)<=10 and abs(l[i]-x)<=c[0]):
            c[0]=abs(l[i]-x)
            c[1]=i
    
    if(c[1]!=-1):
        tmp=l[c[1]]
        l.pop(c[1])

        return(ans+abs(tmp-x))
    else:
        minst=1000000
        minset=[]
        for i in range(1,len(l)-m+1):
                for j in itertools.combinations(l,i):
                        if(abs(sum(j)-x)+(len(j)-1)*10<minst):
                                minst=abs(sum(j)-x)+(len(j)-1)*10
                                minset=[]
                                for z in j:
                                        minset.append(z)
        for i in minset:
                l.remove(i)
        return(abs(sum(minset)-x)+(len(minset)-1)*10)




totalAns=1000000000
import copy
L=copy.deepcopy(l)

ans=0
ans+=solve(A,0,2)
ans+=solve(B,0,1)
ans+=solve(C,0,0)
if(ans<totalAns):
    totalAns=ans

l=copy.deepcopy(L)
ans=0
ans+=solve(A,0,2)
ans+=solve(C,0,1)
ans+=solve(B,0,0)
if(ans<totalAns):
    totalAns=ans

l=copy.deepcopy(L)
ans=0
ans+=solve(B,0,2)
ans+=solve(A,0,1)
ans+=solve(C,0,0)
if(ans<totalAns):
    totalAns=ans

l=copy.deepcopy(L)
ans=0
ans+=solve(B,0,2)
ans+=solve(C,0,1)
ans+=solve(A,0,0)
if(ans<totalAns):
    totalAns=ans

l=copy.deepcopy(L)
ans=0
ans+=solve(C,0,2)
ans+=solve(A,0,1)
ans+=solve(B,0,0)
if(ans<totalAns):
    totalAns=ans

l=copy.deepcopy(L)
ans=0
ans+=solve(C,0,2)
ans+=solve(B,0,1)
ans+=solve(A,0,0)
if(ans<totalAns):
    totalAns=ans

print(totalAns)

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

using namespace std;

const int N = (int) 2e5 + 7;

int n, m;
bool used[N];
vector<int> graph[N];
int component_size = 0;

void dfs(int v) {
    used[v] = true;
    component_size++;
    for (int u : graph[v]) {
        if (!used[u]) {
            dfs(u);
        }
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (!used[i]) {
            component_size = 0;
            dfs(i);
            ans = max(ans, component_size);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 20976
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<long long> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  sort(L.begin(),L.end());
  int cnt = 0;
  // for(int i=0;i<N;i++)  cout << L.at(i) << endl;

  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=j+1;k<N;k++){
        if(L.at(i)!=L.at(j)&&L.at(j)!=L.at(k)&&L.at(k)!=L.at(i)){
          if(L.at(i)+L.at(j)>L.at(k) && L.at(j)+L.at(k)>L.at(i) && L.at(k)+L.at(i)>L.at(j)){
            cnt ++;
            // cout << L.at(i) << " "  << L.at(j)<< "  "<< L.at(k) << endl;
            // cout << i << " "  << j << "  "<< k << endl;
          }
        }
      }
    }
  }

  cout << cnt << endl;

}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int h[105];
int main(void){
    int n,h,h2,ans=1;cin>>n>>h;
    for(int i=1;i<n;i++){
        cin>>h2;
        if(h2>=h)ans++;
        h=max(h,h2);
    }
    cout<<ans<<endl;
    
    return 0;
}


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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    ll n;
    cin>>n;
    float fo = ((n/2) + ( (n&1) ? 1: 0));

    cout<<float(fo/n);






}
// Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3788
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

int lis(vector<int> &v) {
	vector<int> ans(v.size(), INF);
	for (int i = 0; i < v.size();i++) {
		(*lower_bound(ans.begin(), ans.end(), v[i])) = v[i];
	}
	return lower_bound(ans.begin(), ans.end(), INF) - ans.begin();
}

int main() {
	LL x1, x2, y1, y2;
	int n;
	cin >> x1 >> y1 >> x2 >> y2;
	cin >> n;
	if (x1 > x2) {
		swap(x1, x2);
		swap(y1, y2);
	}
	vector<pair<int, int>> xy;
	int x, y;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		xy.emplace_back(x, y);
	}
	int sign = (y1 - y2) > 0 ? -1 : 1;
	vector<pair<int, int>> in;
	for(int i=0;i<n;i++){
		if (min(x1, x2) <= xy[i].first&&xy[i].first <= max(x1, x2) && min(y1, y2) <= xy[i].second&&xy[i].second <= max(y1, y2)) {
			in.emplace_back(xy[i]);
		}
	}
	sort(in.begin(), in.end());
	vector<int> temp;
	for (int i = 0; i < in.size();i++) {
		temp.push_back(sign*in[i].second);
	}
	int m = lis(temp);
	double ans = 100 * (abs(x1 - x2) + abs(y1 - y2));
	if (m - 1 == abs(x1 - x2) || m - 1 == abs(y1 - y2)) {
		ans += (10 * PI - 20) - (20 - 5 * PI) * (m - 1);
	}
	else {
		ans -= (20 - 5 * PI) * m;
	}
	cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 5232
def 解():
    iN,iM = [int(_) for _ in input().split()]
    iD = 10**9+7

    if abs(iN - iM) <= 1:
        if iN < iM:
            iN,iM = iM,iN
        iFacM = 1
        for i in range(1,iM+1):
            iFacM *= i
            iFacM %=iD
        if iN == iM:
            print( iFacM * iFacM % iD * 2 % iD )
        else:
            iFacN = iFacM
            for i in range(iM+1,iN+1):
                iFacN *= i
                iFacN %=iD
            print( iFacM * iFacN % iD  )
    else:
        print(0)
解()


Measured memory_bytes: 3320
def solve():
    N = int(raw_input())
    V = [int(_) for _ in raw_input().split()]
    C = [int(_) for _ in raw_input().split()]
    get = [V[i] - C[i] for i in range(N)]
    sum = 0
    for i in range(N):
        if get[i] > 0:
            sum += get[i]
    print str(sum)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

//繰り返し二乗法
ll EX(ll x,ll n){
    if(n == 0) return 1;
    else if(n%2 == 1) return EX(x,n-1)*x%mod;
    else return EX(x*x%mod,n/2)%mod;
}

struct primes{

    vector<bool> flag;
    void flag_prime(ll max){
        if(max +1 > flag.size()) flag.resize(max+1,true);
        flag[0] = false;
        flag[1] = false;
        for(int i = 2; i*i < max+1; i++){
            if(flag[i]){
                for(int j = 2; i*j < max+1; j++) flag[i*j] = false;
            }
        }
    }

    vector<int> num;
    void num_prime(int max){
        for(int i = 0; i < max+1; i++){
            if(flag[i]) num.push_back(i);
        }
    }

};

int main(){
    ll n,k;
    cin >> n >> k;
    map<ll,ll> mp;
    primes prime;
    prime.flag_prime(k+1);
    prime.num_prime(k+1);
    for(int i = 1; i <= k; i++){
        mp[i] = EX(k/i,n);
    }
    ll ans = 0;
    for(auto p:prime.num){
        for(int i = p; i <= k; i += p){
            mp[i/p] -= mp[i];
        }
    }
    for(int i = 1; i <= k; i++){
        ans += mp[i]*i;
        ans %= mod;
    }
    cout << (ans+mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 9848
N = int(input())
S = input()
ans = S[1:].count('E')  # n=0のとき
a = ans
for i in range(1,N):
    if S[i] == 'E':
        a -= 1
    if S[i-1] == 'W':
        a += 1
    #print(a)
    ans = min(ans,a)
print(ans)

#  W E E W W
#  * 1 1 0 0  2
#  1 * 1 0 0  2
#  1 0 * 0 0  1
#  1 0 0 * 0  1
#  1 0 0 1 *  2


Measured memory_bytes: 42564
x = input()
n = len(x)

arr1_dif = 0
arr2_dif = 0
for i in range(n):
  if i%2 == 0:
    if x[i] == '0':
      arr1_dif += 1
    else:
      arr2_dif += 1
  else:
    if x[i] == '0':
      arr2_dif += 1
    else:
      arr1_dif += 1

print(arr1_dif if arr1_dif<arr2_dif else arr2_dif)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
	int n;
	cin>>n;
	vi v(n);
	int cnt = 0;
	for(int i = 0; i < n; i++){
		cin>>v[i];
		if(v[i]%2!=0&&v[i]%2==(i+1)%2)cnt++;
	}	
	cout<<cnt;
}
signed main(){
	speed;
	int t=1;
	//cin>>t;
	while(t--)solve();
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  int a,b;cin>>a>>b;
  string ab,ba;
  rep(i,b)ab+=a+'0';
  rep(i,a)ba+=b+'0';
  string ans=ab;
  if(ab>ba)ans=ba;
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
import re
while True:
    s = input()
    if s == '#':
        exit()
    s = re.sub(r'[q|w|e|r|t|a|s|d|f|g|z|x|c|v|b]+', 'q', s)
    s = re.sub(r'[y|u|i|o|p|h|j|k|l|n|m]+', 'p', s)
    print(s.count('qp') + s.count('pq'))

Measured memory_bytes: 6728
#include <bits/stdc++.h>
// #define DEBUG

using namespace std;

const int N = 3e2+7;
const long long INF = 1e18;

int n, k;
int h[N];
long long res = INF;
// dp[i][j] keep i'th , del j's before i
long long dp[N][N];

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> h[i];

    for (int i = 0; i <= n+1; ++i)
        for (int j = 0; j <= n+1; ++j)
            dp[i][j] = INF;
    dp[0][0] = 0;

    for (int i = 1; i <= n+1; ++i) {
        for (int j = 0; j < i && j <= k; ++j) {
            for (int k = 0; k <= j && i-k-1 >= 0; ++k) {
                dp[i][j] = min(dp[i][j], dp[i-k-1][j-k]+max(0, h[i]-h[i-k-1]));
            }
#ifdef DEBUG
            printf("dp[%d][%d]=%lld\n", i, j, dp[i][j]);
#endif
            if (i == n+1) res = min(res, dp[i][j]);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <list>
#include <vector>
using namespace std;
int main()
{
    int n, q, query, t, x,s;
    cin >> n >> q;
    vector<list<int>> lis(n);
    while (q--) {
        cin >> query;
        if (query == 0) {
            cin >> t >> x;
            lis[t].push_back(x);
        }
        else if (query == 1) {
            cin >> t;
            if (lis[t].empty()) {
                cout << endl;
                continue;
            }
            list<int>::iterator it,en=lis[t].end();
            en--;
            for (it = lis[t].begin(); it != lis[t].end(); it++) {
                if (it != en)
                    cout << *it << " ";
                else cout << *it << endl;
            }
        }
        else if (query == 2) {
            cin >> s >> t;
            list<int>::iterator itt=lis[t].end();
            lis[t].splice(itt, lis[s]);
            lis[s].clear();
        }
    }
}


Measured memory_bytes: 18720
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    counter = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    counter += 1
    print(counter)


Measured memory_bytes: 5596
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int in[100005];

int main() {
  int n,m;
  S2(n,m);
  while(m--) {
    int u,v;
    S2(u,v);
    in[u]++;
    in[v]++;
  }
  rep(i,1,n+1) if(in[i] & 1) {
    printf("NO\n");
    return 0;
  }
  printf("YES\n");
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(ll i=0; i<n; i++)
using namespace std;
typedef long long ll;

const ll INF = ll(1e18)+1;

int main(){
    int x; cin >>x;
    if(x<600) cout << 8<<endl;
    else if(x<800) cout << 7 << endl;
    else if(x<1000) cout << 6 << endl;
    else if(x<1200) cout << 5 << endl;
    else if(x<1400) cout << 4 << endl;
    else if(x<1600) cout << 3 << endl;
    else if(x<1800) cout << 2 << endl;
    else cout << 1 << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int beg = 1, end = 1e5;
    ll mid;
    while(end - beg > 1){
        mid = (beg+end)/2;
        if(SQ(mid) > n){
            end = mid;
        }
        else
        {
            beg = mid;
        }
    }    
    cout << SQ(beg) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define END "END_OF_TEXT"

void
strtolower(char *);

int
main(void)
{
    char word[11];
    char text[12];
    int count = 0;

    scanf("%10s", word);
    while (scanf("%11s", text) && strcmp(text, END)) {
        strtolower(text);
        if (!strcmp(text, word))
            count++;
    }
    
    printf("%d\n", count);

    return 0;
}

void
strtolower(char *str)
{
    for ( ; *str; str++)
        *str = tolower(*str);
}


Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    if (a < 10 && b < 10) {
        cout << a * b << "\n";
    } else {
        cout << -1 << "\n";
    }
}

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

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var list = Console.ReadLine().Split(' ');
        var ass = new int[n];
        for (int i = 0; i < ass.Length; ++i)
            ass[i] = int.Parse(list[i]);

        Array.Sort(ass);

        int index = 1;
        for (; index < ass.Length - 1; ++index)
        {
            if (ass[index] >= 0)
                break;
        }

        var total = 0;
        for (int i = 0; i < index; ++i)
            total -= ass[i];
        for (int i = index; i < ass.Length; ++i)
            total += ass[i];

        Console.WriteLine(total);

        for (int i = index; i < ass.Length - 1; ++i)
        {
            Console.WriteLine($"{ass[0]} {ass[i]}");
            ass[0] -= ass[i];
        }

        var tail = ass[ass.Length - 1];
        for (int i = 0; i < index; ++i)
        {
            Console.WriteLine($"{tail} {ass[i]}");
            tail -= ass[i];
        }
    }

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


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

#define print(x) for(auto it : x) cout<< it << ' '; cout << '\n';
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                ll a = v[i], b = v[j], c = v[k];
                if (a != b && b != c && c != a) {
                    if (a + b > c && b + c > a && c + a > b)
                    ans++;
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3652
import sys
n=int(input())
a=list(map(int,input().split()))
for i in range(min(n+1,40)):
  if a[i]>2**i:
    print(-1)
    sys.exit()
if a[0]!=0 and n!=0:
  print(-1)
  sys.exit()
A=[0]
for i in range(n+1):
  A.append(A[-1]+a[i])
s=sum(a)
ans=1
x=1
for i in range(1,n+1):
  S=s-A[i]
  if x*2<S:
    ans+=x*2
    x*=2
    x-=a[i]
    if x<=0:
      print(-1)
      sys.exit()
  else:
    x=S
    ans+=x
print(ans)

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

class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        String[] input = br.readLine().split(" ");

        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(input[i]);
        }

        int pivot = partition(arr, 0, n-1);

        StringBuilder sb = new StringBuilder();
        
        for(int i = 0; i < n; i++){
            if(i == pivot){
                sb.append("[").append(arr[i]).append("] ");
            }else{
                sb.append(arr[i]).append(" ");
            }
        }

        System.out.println(sb.toString().trim());
    }

    static int partition(int[] A, int p, int r){
        int x = A[r];
        int i = p-1;

        for(int j = p; j < r; j++){
            if(A[j] <= x){
                i++;
                swap(A, i, j);
            }
        }
        
        swap(A, i+1, r);

        return i+1;
    }

    static void swap(int[] A , int x, int y){
        int tmp = A[x];
        A[x] = A[y];
        A[y] = tmp;
    }

}


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

typedef long long ll;
const int MAX_N = 100030;    // Change as necessary
const ll  MODD = 1000000009; //

int A[MAX_N];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n,c,k; cin >> n >> c >> k;
  for(int i=0;i<n;i++) cin >> A[i];
  sort(A,A+n);

  int ans = 0;
  for(int i=0,j=0;i<n;i=j){
    for(j=i;j<n && j-i < c && A[i]+k >= A[j];j++);
  	ans++;
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define sl1(a)  scanf("%lld",&a)
#define sl2(a,b)  scanf("%lld %lld",&a,&b)
#define sl3(a,b,c)  scanf("%lld %lld %lld",&a,&b,&c)
#define PI 3.1415926535897932

int main(){
    int mod=1000000007;
    int n,m,ans;
    for(;;) {
        int n,t;
        double v,p=0;
        sc1(n);
        if (n==0) break;
        vector<int> a(n);
        for(auto&e:a) sc1(e);
        t=accumulate(a.begin(),a.end(),0);
        v=1.0*t/n;
        rep(i,n) p+=pow((a[i]-v),2);
        printf("%.15lf\n",sqrt(p/n));

    }
    return 0;
}



Measured memory_bytes: 3232
import java.util.Scanner;

public class Main {
	static int MOD = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int NINV = modInv(n, MOD);

		long combi = 1;
		long ans = 1;
		for ( int i = 0 ; i < Math.min(n - 1, k) ; i++ ) {
			combi = (combi * (n - i)) % MOD;
			combi = (combi * (modInv(i + 1, MOD))) % MOD;

			long h = (combi * (n - i - 1)) % MOD;
			h = (h * NINV) % MOD;

			long p = (combi * h) % MOD;
			ans = (ans + p) % MOD;
		}

		System.out.println(ans);
	}

	static int power(int base, int exp, int mod) {
		long res = 1;
		int first = base % mod;
		int cnt = exp == 0 ? 0 : firstBitPos(exp) + 1;
		while ( cnt >= 0 ) {
			res = (res * res) % mod;
			if ( ((exp >> cnt) & 1) != 0 ) {
				res = (res * first) % mod;
			}
			cnt--;
		}
		return (int) res;
	}

	// 最大公約数と、ax + by = gcdを満たすx,yを計算する
	static int[] xgcd(int a, int b) {
		int x0 = 1;
		int y0 = 0;
		int x1 = 0;
		int y1 = 1;
		while ( b != 0 ) {
			int q = a / b;
			int tmp = b;
			b = a % b;
			a = tmp;

			tmp = x1;
			x1 = x0 - q * x1;
			x0 = tmp;

			tmp = y1;
			y1 = y0 - q * y1;
			y0 = tmp;
		}
		return new int[] {a, x0, y0};
	}

	// 逆元
	static int modInv(int a, int mod) {
		int[] xgcd = xgcd(a, mod);
		return (xgcd[1] + mod) % mod;
	}

	static int firstBitPos(int num) {
		int x = num | (num >> 1);
		x |= x >> 2;
		x |= x >> 4;
		x |= x >> 8;
		x |= x >> 16;
		return countBits(x);
	}

	static int countBits(int num) {
		int cnt = (num & 0x55555555) + (num >> 1 & 0x55555555);
		cnt = (cnt & 0x33333333) + (cnt >> 2 & 0x33333333);
		cnt = (cnt & 0x0f0f0f0f) + (cnt >> 4 & 0x0f0f0f0f);
		cnt = (cnt & 0x00ff00ff) + (cnt >> 8 & 0x00ff00ff);
		return (cnt & 0x0000ffff) + (cnt >> 16 & 0x0000ffff);
	}
}


Measured memory_bytes: 24020
menber = []
while (arg = gets.split(",").map(&:to_i)) != [0, 0]
  menber << arg
end
menber.sort_by!{|item|-item[1]}
rank = Array.new(menber.length)
temp = [0, 31]
menber.each{|item|
  if item[1] != temp[1]
    temp[1] = item[1]
    temp[0] += 1
  end
  rank[item[0] - 1] = temp[0]
}
while n = gets
  puts rank[n.to_i - 1]
end

Measured memory_bytes: 6104
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,m,t;
int have[303],dat[303];
int need[303][303];
int now[303][303];
int a[200005],b[200005];
inline bool ok(int step){
	memset(now,0,sizeof now);
	memcpy(have,dat,sizeof have);
	for(int i=1;i<=step;i++){
		now[a[i]][b[i]]++;
		have[b[i]]--;
	}
	for(int i=1;i<=n;i++){
		int mul=inf;
		for(int j=1;j<=m;j++)if(need[i][j])mul=min(mul,now[i][j]/need[i][j]);
		for(int j=1;j<=m;j++)have[j]+=mul*need[i][j],now[i][j]-=mul*need[i][j];
	}
	while(1){
		bool change=false;
		for(int i=1;i<=n;i++){
			if(*max_element(now[i],now[i+1])==0)continue;
			bool ok=true;
			for(int j=1;j<=m;j++)if(need[i][j]-now[i][j]>have[j])ok=false;
			if(ok){
				for(int j=1;j<=m;j++)have[j]+=now[i][j],now[i][j]=0;
				change=true;
			}
		}
		if(!change)break;
	}
	if(*max_element(now[1],now[n+1])>0)return false;
	return true;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m>>t;
	for(int i=1;i<=m;i++)cin>>dat[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>need[i][j];
		}
	}
	for(int i=1;i<=t;i++)cin>>a[i]>>b[i];
	int l=0,r=t+1;
	while(r-l>1){
		int mid=l+r>>1;
		if(ok(mid))l=mid;
		else r=mid;
	}
	cout<<(r==t+1?-1:r)<<endl;
	return 0;
}


Measured memory_bytes: 5416
#include<stdio.h>

 int cnt;
 
 void insertionSort(int A[],int n,int g);
 void shellSort(int A[],int n);

 int n;
 int A[1000000];

 int main(){
            int i;
            scanf("%d",&n);
            for(i=0;i<n;i++)scanf("%d",A+i);
            shellSort(A,n);
            printf("%d\n",cnt);
            for(i=0;i<n;i++)printf("%d\n",A[i]);
            return 0;
            }

 void insertionSort(int A[],int n,int g){
            int tmp;
            int i,j;
            for(i=g;i<n;i++){
                             tmp=A[i];
                             j=i-g;
                             while(j>=0&&A[j]>tmp){
                                                   A[j+g]=A[j];
                                                   j-=g;
                                                   ++cnt;
                                                   } 
                             A[j+g]=tmp;
                             }
             }

void shellSort(int A[], int n) {
  int m = 0;
  int G[100];
  int i;
  G[0] = 1;
  for(m = 1; 3*G[m-1]+1 <= n; ++m) G[m] = 3*G[m-1]+1;
  printf("%d\n", m);
  cnt = 0;
  for(i = m-1; i >= 0; --i) {
    printf("%d%c", G[i], " \n"[i==0]);
    insertionSort(A, n, G[i]);
  }
}


Measured memory_bytes: 5616
/*  -*- coding: utf-8 -*-
 *
 * 3013.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int t;
  scanf("%d", &t);

  printf("%d %d\n", t / 30, (t % 30) * 2);
  return 0;
}



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

typedef long long ll;

int main() {
    int n, m, d;
    cin >> n >> m >> d;
    if (d == 0) {
        cout << setprecision(12) << 1.0 * (n - d) / n / n * (m - 1) << endl;
    } else {
        cout << setprecision(12) << 2.0 * (n - d) / n / n * (m - 1) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    cin>>n;
    vector<string>m;
    vector<string>a;
    vector<string>r;
    vector<string>c;
    vector<string>h;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(s.at(0)=='M'){
            m.push_back(s);
        }
        if(s.at(0)=='A'){
            a.push_back(s);
        }
        if(s.at(0)=='R'){
            r.push_back(s);
        }
        if(s.at(0)=='C'){
            c.push_back(s);
        }
        if(s.at(0)=='H'){
            h.push_back(s);
        }
    }

    ll ans=0;
    vector<ll>aa(5);
    aa.at(0)=m.size();
    aa.at(1)=a.size();
    aa.at(2)=r.size();
    aa.at(3)=c.size();
    aa.at(4)=h.size();
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                ans+=aa.at(i)*aa.at(j)*aa.at(k);
            }
        }
    }
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 5748
n,m,x,y = map(int,input().split())
xl = list(map(int, input().split()))
yl = list(map(int, input().split()))
xl.sort()
yl.sort()
if xl[n-1] < yl[0] and x < yl[0] and xl[n-1] < y:
    print("No War")
else:
    print("War")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)

typedef pair<int,int> P;
typedef long long ll;

const int INF = 1001001001;
const int mod = 1000000007;
const double PI=acos(-1);

#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) { 
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}

ll nCr(ll n, ll r, ll mod){
    ll x = 1, y = 1;
    
    lrep(i, r) {
        x *= n-i;
        x %= mod;
 
        y *= r-i;
        y %= mod;
    }
 
    ll rtn = (x * modinv(y, mod)) % mod;
 
    return rtn;
}

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

    map<ll,ll> F;

    while(M%2==0) {
        if (!F.count(2)) {
            F[2]=1;
        }
        else {
            F[2]++;
        }
        M/=2;
    }
    for(int i=3; i<=M; i++)  {
        while(M%i==0) {
            if (!F.count(i)) {
                F[i]=1;
            }
            else {
                F[i]++;
            }
            M/=i;
        }
    }
    ll ans = 1;

    for (auto p:F) {
        ans *= nCr(p.second+N-1,N-1,mod);
        ans %= mod;
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int a[5]={};
    rep(i,3){
        int k,q;
        cin >> k >> q;
        a[k]++;
        a[q]++;
    }
    int cnt = 0;
    rep(i,5){
        if(a[i]%2!=0)cnt++;
    }
    if(cnt>2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 888
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M=list(map(int,input().split()))
uf=UnionFind(N+1)
p=list(map(int,input().split()))
for i in range(M):
    x,y=list(map(int,input().split()))
    uf.union(x,y)
count=0
for i in range(1,N+1):
    if (uf.same(p[i-1],i)):count+=1
print(count)

Measured memory_bytes: 14708
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

int n;
string s,t;

int main() {
  cin >> s;
  string k="keyence";
  int n=s.size(); bool ok=false;
  rep(i,8){
    t=s.substr(0,i); 
    if(i!=7) t+=s.substr(n-(7-i));
    if(t==k) ok=true;
  }
  cout << (ok ? "YES" : "NO") << endl;
 }

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#define N 10
using namespace std;
long func(int a[], int i, int l, long Sn, long S){
    if (i == l){
        return S + Sn;
    }else{
        return func(a, i + 1, l, 10 * Sn + a[l-i-1], S) + func(a, i + 1, l, a[l-i-1], S + Sn);
    }
}

long solve(int a[N], int l){
    return func(a, 1, l, a[l-1], 0);
}

int main(int argc, char const *argv[])
{
    long S;
    cin >> S;
    int b, c = 0, a[N];
    for(int i = 0; i < N; i ++){
        b = S % 10;
        if (b != 0){
            a[i] = b;
            S = (S - b) / 10;
            c ++;
        }else{
            break;
        }
    }
    cout << solve(a, c) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    if (a == 0 && b == 0) {
        REP(i,0,h) {
            REP(j,0,w) cout << 0;
            cout << endl;
        }
        return;
    }
    REP(i,0,h) {
        REP(j,0,w) {
            if ((i < b) == (j < a)) cout << 1;
            else cout << 0;
        }
        cout << endl;
    }
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>

int main(void){
	int m[128][128] = {0},w,h,n,x,y,i,j,k,a,c=0;
	scanf("%d%d%d",&w,&h,&n);
	for(i = 1;i<= n;i++){
		scanf("%d%d%d",&x,&y,&a);
		if(a == 1){
			for(j = 0;j < x;j++){
				for(k = 0;k < h;k++){m[j][k] = 1;}
			}
		}
		if(a == 2){
			for(j = x;j < w;j++){
				for(k = 0;k < h;k++){m[j][k] = 1;}
			}
		}
		if(a == 3){
			for(j = 0;j < w;j++){
				for(k = 0;k < y;k++){m[j][k] = 1;}
			}
		}
		if(a == 4){
			for(j = 0;j < w;j++){
				for(k = y;k < h;k++){m[j][k] = 1;}
			}
		}
	}
	for(i = 0;i < w;i++){
		for(j = 0;j < h;j++){
			if(m[i][j] == 0){c++;}
		}
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,r;
	cin>>n>>r;
	if(n>=10){
		cout<<r;
	}
	else{
		cout<<(r+100*(10-n));
	}
	return 0;
}

Measured memory_bytes: 256