akhauriyash/Code-Regression huggingface dataset:
import heapq as hp
class MinimumCostFlow():
    def __init__(self, N, INF=10**18):
        self.graph = [{} for _ in range(N)]
        self.N = N
        self.INF = INF
    
    def add_edge(self, u, v, cap, cost, undirected=False):
        # u -> v (maxflow, cost)
        if cap == 0: return
        if undirected:
            self.graph[u][v] = [cap, cost]
            self.graph[v][u] = [cap, -cost]
        elif v in self.graph[u]:
            self.graph[u][v] = [cap, cost]
        else:
            self.graph[u][v] = [cap, cost]
            self.graph[v][u] = [0, -cost]       
    
    def dijkstra(self, start):
        self.dist = [self.INF]*self.N # nearest distance
        self.dist[start] = 0
        self.que = [(0, start)]
        while self.que:
            d, v = hp.heappop(self.que)
            if self.dist[v] < d: continue
            for nv, (ncap, ncost) in self.graph[v].items():
                if ncap > 0 and self.dist[nv] > self.dist[v] + ncost + self.H[v] - self.H[nv]:
                    self.dist[nv] = self.dist[v] + ncost + self.H[v] - self.H[nv]
                    self.prevv[nv] = v
                    hp.heappush(self.que, (self.dist[nv], nv))
                
    
    def min_cost_flow(self, start, finish, flow):
        self.res = 0
        self.prevv = [-1]*self.N
        self.H = [0]*self.N # potential
        while flow > 0:
            self.dijkstra(start)
            if self.dist[finish] == self.INF: return -1 # cant run flow anymore
            for i in range(self.N):
                self.H[i] += self.dist[i]
            
            d = flow
            v = finish
            while v != start:
                d = min(d, self.graph[self.prevv[v]][v][0])
                v = self.prevv[v]
            flow -= d
            self.res += d*self.H[finish]

            v = finish
            while v != start:
                self.graph[self.prevv[v]][v][0] -= d
                self.graph[v][self.prevv[v]][0] += d
                v = self.prevv[v]
        return self.res
    

if __name__ == "__main__":
    import sys
    input = sys.stdin.readline

    V, E, F = map(int, input().split())
    fl = MinimumCostFlow(V)
    for _ in range(E):
        u, v, c, d = map(int, input().split())
        fl.add_edge(u, v, c, d)
    
    print(fl.min_cost_flow(0, V-1, F))


Measured memory_bytes: 6016
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<functional>
#include<map>
using namespace std;
#pragma warning(disable: 4996)
string S[1000]; int H, W;
int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++)cin >> S[i];
	int dx[8] = { 0,1,1,1,0,-1,-1,-1 };
	int dy[8] = { 1,1,0,-1,-1,-1,0,1 };
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#')cout << "#";
			else {
				int cnt = 0;
				for (int k = 0; k < 8; k++) {
					int cx = i + dx[k], cy = j + dy[k];
					if (cx < 0 || cx >= H || cy < 0 || cy >= W)continue;
					if (S[cx][cy] == '#')cnt++;
				}
				cout << cnt;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  rep(i,S.size()){
    cout << (char)('A' + ((S[i]-'A')+N)%26);
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 256
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("out.txt", "w", stdout);
//    cin.tie(0);
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);


    int n;
    cin >> n;
    vector<int> a(n);

    for (int& x : a)
        cin >> x;

    vector<int> ans;
    for (int val = 1; val <= n; ++val) {
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] == val) {
                if (cnt - val + 1 > ans.size())
                    FINAL_OUT(-1);
                ans.insert(ans.end() - cnt + val - 1, val);
            }
            cnt += a[i] <= val;
        }
    }
    for (int x : ans)
        cout << x << '\n';



}


Measured memory_bytes: 256
//
// Created on 2020/02/22.
//

//#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {
    int ans = 0;
    int n;
    int k;
    cin>>n>>k;

    while(n>0){
        n = n/k;
        ans++;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST         ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll           long long
#define ld           long double
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<long long>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define mod          998244353
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define endl         '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

bool isval(int x, int y, int n, int m)
{
    return (x>=0 and x<n and y>=0 and y<m);
}
void solve()
{
    int n,m; cin>>n>>m;
    vector<vll> dp(n,vll(m,0));
    vector<vector<char>> a(n,vector<char>(m));
    rep(i,0,n) rep(j,0,m) cin>>a[i][j];
    dp[0][0]=1;
    rep(i,0,n)
    {
        rep(j,0,m)
        {
            if(a[i][j]!='.') continue;
            if(i == 0 and j == 0) continue;
            if(isval(i-1,j,n,m)) dp[i][j] = (dp[i][j]+dp[i-1][j])%lul;
            if(isval(i,j-1,n,m)) dp[i][j] = (dp[i][j] + dp[i][j-1])%lul;
            dp[i][j]+=lul, dp[i][j]%=lul;
        }
    }
    cout<<dp[n-1][m-1];
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1; //cin>>t;
    while(t--){
       solve();
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<pair<int,int>> d(n);
    for (int i = 0; i < n; i++) cin >> d[i].first >> d[i].second;

    for (int i = 0; i < n-2; i++) {
        if (d[i].first==d[i].second &&
            d[i+1].first==d[i+1].second &&
            d[i+2].first==d[i+2].second) {
                cout << "Yes" << endl;
                return 0;
            }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <string>
#include <functional>
#include <cassert>
#include <cmath>
#define SIZE 2005
#define MOD 1000000007

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

int A[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	ll K;
	scanf("%lld",&K);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	ll ret=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(A[i]>A[j])
			{
				ll mul=K*(K+1)/2LL;
				ret+=mul%MOD;
				if(ret>=MOD) ret-=MOD;
			}
			else if(A[i]<A[j])
			{
				ll mul=K*(K-1)/2LL;
				ret+=mul%MOD;
				if(ret>=MOD) ret-=MOD;
			}
		}
	}
	printf("%lld\n",ret);
	return 0;
}


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

bitset<48> func(int64_t n) {
  bitset<48> ret;
  int64_t d = 1;
  for (int i = 0; i < 48; i++) {
    int64_t q = (n+1) / (2*d);
    int64_t r = (n+1) % (2*d);
    if ((q * d + (r-d > 0 ? r-d : 0)) % 2 == 1) ret.set(i);
    d *= 2;
  }
  return ret;
}

int main() {
  int64_t a, b; cin >> a >> b;
  bitset<48> bit;
  if (a == 0) bit = func(b);
  else bit = func(b) ^ func(a-1);
  int64_t ans = 0;
  int64_t k = 1;
  for (int i = 0; i < 48; i++) {
    ans += k * (bit.test(i) ? 1 : 0);
    k *= 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,q;
	string s;
	cin>>n>>s>>q;
	vector<set<ll>> st(26);
	rep(i,n){
		st[s[i]-'a'].insert(i+1);
	}
	while(q--){
		ll type,idx,l,r;
		char c;
		cin>>type;
		if(type==1){
			cin>>idx>>c;
			rep(i,26){
				if(st[i].find(idx)!=st[i].end())st[i].erase(idx);
			}
			st[c-'a'].insert(idx);
		}
		else{
			cin>>l>>r;
			ll ans=0;
			rep(i,26){
				if(st[i].lower_bound(l)!=st[i].lower_bound(r+1))ans++;
			}
			puta(ans);
		}
	}
}


Measured memory_bytes: 24220
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    string s;
    
    cin >> s;
    int n = s.size();
    string fs = s.substr(0, (n-1)/2);
    string ls = s.substr((n-1)/2+1, (n-1)/2);
    string rs = s;
    string rfs = fs;
    string rls = ls;
    reverse(rs.begin(), rs.end());
    reverse(rfs.begin(), rfs.end());
    reverse(rls.begin(), rls.end());

    
    bool ans = true;
    if (ls != rls) ans = false;
    if (fs != rfs) ans = false;
    if (s != rs) ans = false;
    
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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


int main() {
    int x;
    int i = 1;
    while (cin >> x) {
        if (x == 0) break;
        cout << "Case" << " " << i << ":" << " " << x << endl; 
        ++i;
    }
    
    return 0;
}


Measured memory_bytes: 3076
n=int(input())
r=[[] for i in range(n+1)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    r[a].append((b,c))
    r[b].append((a,c))
ans=[-1 for i in range(n+1)]
Q,k=map(int,input().split())
q=[(k,0)]
while len(q)>0:
    v,l=q.pop()
    ans[v]=l
    for V,L in r[v]:
        if(ans[V]==-1):
            q.append((V,l+L))
for i in range(Q):
    x,y=map(int,input().split())
    print(ans[x]+ans[y])

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

int main(){
  
  int n;
  cin >> n;
  
  vector<int> lists(n);
  for(int i=0; i<n;i++){
    cin >> lists.at(i);
  }
  
  int ans = 1;
  int std = lists.at(0);
  
  for(int i=1;i<n;i++){
    if(lists.at(i) < std){
      ans += 1;
      std = lists.at(i);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
//#include <iostream>
//#include <iomanip>
//#include <vector>
//#include <cmath>
//#include <algorithm>
using namespace std;


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

typedef unsigned long long ll;

ll p = pow(10, 9) + 7;





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

    int n;
    cin >> n;
    double sum = 0;
    vector<int> arr(n);
    for(int i = 0; i < n; i++)
    {

        cin >> arr[i];
        sum += arr[i];
    }
    int P = ceil(sum / n);
    int Pl = floor(sum / n);
    int ans = 0;
    int ansL = 0;
    for(int i = 0; i < n; i++)
    {
        ans += pow(arr[i] - P, 2);
        ansL += pow(arr[i] - Pl, 2);
    }
    cout << min(ans, ansL) << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if (abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d))
	puts ("Yes");
	else 
	puts("No");
	return 0;
}

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

//queを使えないが、横に見ていきたいときに使う新技
//それぞれの配列を用意してやる→全て用意すると数が多いので値をswapしていく。
int main()
{
    ll k;
    cin >> k;
    vector<ll> a; //これは入れて行く配列。桁ごとに分けて行く感じのやつ
    for (int i = 1; i < 10; i++)
    {
        a.push_back(i);
    }

    while ((k = k - a.size()) > 0)
    {
        vector<ll> old;
        swap(old, a);
        for (ll x : old)
        {
            if (x%10 != 0)
            {
                a.push_back(x * 10 + x % 10 - 1);
            }
            a.push_back(x * 10 + x % 10);
            if (x %10 != 9)
            {
                a.push_back(x * 10 + x % 10 + 1);
            }
        }
    }
    //0になるということはちょうど端っこということなので、それはよし
    k+=a.size();
    cout <<a[k-1];
}

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

int main() {
	
	
	
	int n; cin >> n;
	
	vector<vector<ll>> a(n,vector<ll>(3));
	rep(i,n) cin >> a[i][0] >> a[i][1] >> a[i][2];
	//sort(a.begin(),a.end());
	
	
	vector<vector<ll>> hp(n,(vector<ll>(3,0)));
	
	
	

	for(int i=0;i<n;i++){
		rep(j,3){
			rep(k,3){
				if(i==0) hp[i][j]=a[i][j];
				else{
					if(k==j) continue;
					else chmax(hp[i][j],hp[i-1][k]+a[i][j]);
				}
			}
		}
	}

	ll ans=max(hp[n-1][0],hp[n-1][1]);
	ans=max(ans,hp[n-1][2]);

	cout << ans << '\n';
	return 0;

}

Measured memory_bytes: 11136
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

#define repd(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int main(){
	//source
	int d=inputValue();
	string str;
	if(d==25){
		str="Christmas";
	}else if(d==24){
		str="Christmas Eve";
	}else if(d==23){
		str="Christmas Eve Eve";
	}else if(d==22){
		str="Christmas Eve Eve Eve";
	}
	cout << str << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);

	ll n, a[100000];
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	
	for(int i = 0; i < n; i++) if(a[i] == 0) {
		cout << 0 << endl;
		return 0;
	}	
	
	ll res = 1;
	for(int i = 0; i < n; i++) {
		if(a[i] <= 1000000000000000000/res) res *= a[i];
		else {
			cout << -1 << endl;
			return 0;
		}
	}
	
	cout << res << endl;
	return 0;
}

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

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> A(N);
  int sum = 0;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    sum += A[i];
  }
  
  int count = 0;
  for(int i = 0; i < N; i++){
    if(4 * A[i] * M >= sum) count++;
  }
  
  if(count >= M) puts("Yes");
  else puts("No");
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    unordered_set<int64_t> s;
    for (auto aa : a) {
        if (s.count(aa)) {
            cout << "NO" << endl;
            return 0;
        }

        s.insert(aa);
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 10056
#include <bits/stdc++.h>
using namespace std;
string s;
vector<string> st {"maerd", "remaerd", "esare", "resare"};

int main() {
    cin >> s;
    int slen = s.length();
    reverse(s.begin(), s.end());
    int fst = 0;
    bool flg = true;
    while(1) {
        if(fst >= slen) break;
        vector<bool> inflg(4, true);
        for(int i = 0; i < 4; ++i) {
            int tlen = st.at(i).length();
            for(int j = 0; j < tlen; ++j) {
                if(s.at(fst+j) != st.at(i).at(j)) {
                    inflg.at(i) = false;
                    break;
                }
            }
        }

        bool intflg = false;
        for(int i = 0; i < 4; ++i) {
            if(inflg.at(i)) {
                fst += st.at(i).length();
                intflg = true;
                break;
            }
        }

        if(!intflg) {
            flg = false;
            break;
        }
    }
    
    if(flg) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		
		int N = scan.nextInt();
		int[] number = new int[N];
		double sum = 0;
		
		for (int i = 0; i < N; i++) {
			number[i] = scan.nextInt();
			sum += (double)1 / number[i];
		}
	
		System.out.println(1 / sum);
	}
}

Measured memory_bytes: 22100
def main():
    N1, N2, N3, N4 = input().split()
    lis = ['1', '9', '7', '4']
    if N1 in lis:
        lis.remove(N1)
    if N2 in lis:
        lis.remove(N2)
    if N3 in lis:
        lis.remove(N3)
    if N4 in lis:
        lis.remove(N4)
    if not lis:
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n; cin >> n;
  string s; cin >> s;
  map<char, ll> M;
  for (auto&&c: s) M[c]++;
  ll ans = M['R'] * M['G'] * M['B'];
  for (int len=1; len<=n/2; len++) {
    for (int j=1; j<n-1; j++) {
      int i = j-len, k = j+len;
      if (i < 0 or k >= n) continue;
      ans -= s[i] != s[j] and s[j] != s[k] and s[k] != s[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
# Di = Di-1 + Li-1
n, x = map(int, input().split())
L = list(map(int, input().split()))
ans = 0
ct = 1 
for i in range(n):
    ans = ans + L[i]
    if ans > x:
        break
    else:
        ct += 1
print(ct)


Measured memory_bytes: 9144
N,M,Q = map(int,input().split())

li = [list(map(int,input().split())) for i in range(Q) ]

from itertools import combinations_with_replacement
counter = []

for comb in combinations_with_replacement(range(1,M+1),N):
    A = list(comb)
    tmp = 0
   
    for i in li:
        if A[i[1]-1] - A[i[0]-1] == i[2]:
            tmp += i[3]

    counter.append(tmp)


print(max(counter))

Measured memory_bytes: 12520
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

typedef long long ll;

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

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

double solve1(const int a, const int b, const int x) {
    double k = ((double) 2 * a * a * b - 2 * x) / ((double) a * a);
    double rad = atan2(a, k);
    return 90.0 - rad * 180.0 / M_PI;
}

double solve2(const int a, const int b, const int x) {
    double l = 2.0 * double(x) / ((double) (a * b));
    double rad = atan2(l, double(b));
    return 90.0 - rad * 180.0 / M_PI;
}

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

    if (2 * x >= a * a * b) {
        printf("%.10f\n", solve1(a, b, x));
    } else {
        printf("%.10f\n", solve2(a, b, x));
    }

    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
S=str(input())
s=S[K-1:K]
s1=S[0:K-1]
s2=S[K:N]
if s=='A':
    ans=s1+'a'+s2
elif s=='B':
    ans=s1+'b'+s2
else:
    ans=s1+'c'+s2
print(ans)


Measured memory_bytes: 3060
from numpy import*
M=10**9+7
m=lambda*z:map(int,raw_input().split())
n,k=m()
b=[1]*n
a=matrix(map(m,b),'O')
while k:b*=[1,a][k&1];a=a*a%M;k/=2
print sum(b)%M

Measured memory_bytes: 10672
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    string w[n];

    for(int i=0;i<n;i++){
        cin >> w[i];
    }

    int flag = 0;
    int c;

    for(int i=0;i<n;i++){
        c = 0;
        for(int j=0;j<n;j++){
            if(w[i]==w[j]){
                c++;
            }
        }
        if(c >= 2){
            flag = 1;
        }
    }
    //cout << c << flag << endl;
    char first;
    char last;
    for(int i=1; i<n;i++){
        first = w[i][0];
        last = w[i-1][w[i-1].size()-1];
        if(first != last){
            flag++;
        }
        //cout << last << endl;
    }
    if(flag == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
/* Akshat Sharma @akshat98 */
#include <iostream>
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp   make_pair
#define pb   push_back
#define F    first
#define S    second
#define ll   long long
#define MOD  1000000007
#define MAX  1000000001
#define vi 	 vector<int>
#define vl   vector<ll>
#define vpi  vector<pair<int,int> >
#define vpl  vector<pair<ll,ll> >
#define rep(i,a,b) for(i=a;i<b;i++)
#define reqp(i,a,b) for(i=a;i<=b;i++)
#define ren for(i=0;i<n;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;


int main()
{
	#ifndef ONLINE_JUDGE
	//freopen("input_file.txt", "r", stdin);
	//freopen("output_file.txt", "w", stdout);
	#endif
	int i,j,k,l,n,test_case,m,r,u,v;
	test_case=1;
	//cin>>test_case;
	while(test_case--){
		cin>>n>>m;
		int arr[m+1][2];
		int cnt=0;
		int x=0,y=n+1;
		rep(i,0,m){
			cin>>u>>v;
			x=max(u,x);
			y=min(v,y);
		}
		// cout<<x<<"_"<<y<<"\n";
		if(y>=x){
			cout<<(y-x+1);
		}else cout<<0;


	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}

// cf IO: I64d
// atcoder IO: ｌｌｄ
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int main(){
	int n;
	scanf("%d",&n);
	int s1=0,s2=0;
	for (int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if (x&1) s1++;
		if (x%4==0) s2++;
	} 
	if (s1+s2==n){
		if (s2+1>=s1){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	else{
		if (s2>=s1){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res


n,m = l_in()
A = l_in()

print(max(n-sum(A),-1))


Measured memory_bytes: 67980
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

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

  lint cntR = 0, cntG = 0, cntB = 0;
  REP(i,n){
    if(s[i] == 'R') cntR++;
    if(s[i] == 'G') cntG++;
    if(s[i] == 'B') cntB++;
  }
  lint cnt = 0;
  REP(i,n){
    FOR(j,1,n){
      if(i+j*2 > n-1) break;
      if(s[i] != s[i+j] && s[i] != s[i+j*2] && s[i+j] != s[i+j*2]) cnt++;
    }
  }
  cout <<  cntR*cntG*cntB - cnt << "\n";
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define time efsfdsf
using namespace std;
typedef long long ll;
struct dats{ll x,y,p[10];};
struct datp{ll v,p;}; 
int n,m,W,T;
map<string,int>M;
dats shop[10];
datp prod[10];
vector<ll> time(1<<10,1e9);
void Min(ll &a,ll b){a=min(a,b);}
void Max(ll &a,ll b){a=max(a,b);}
int dis(int a,int b){return abs(shop[a].x-shop[b].x)+abs(shop[a].y-shop[b].y);}

void calc_time(int bit,ll cost,int pre){
  for(int i=0;i<n;i++){
    if(bit&(1<<i))continue;
    int nbit = bit|(1<<i);
    ll ncost = cost+dis(i,pre);
    Min(time[nbit],ncost+dis(i,n));
    calc_time(nbit,ncost,i);
  }
}

ll dp[1<<7][10010];
void calc_w(){
  for(int i=0;i<(1<<n);i++){
    vector<ll> p(10,1e9);
    for(int j=0;j<n;j++)
      if(i&(1<<j))for(int k=0;k<m;k++)Min(p[k],shop[j].p[k]);

    for(int j=0;j<m;j++)
      for(int k=0,w=prod[j].v;k<=W-w;k++)Max(dp[i][k+w],dp[i][k]+prod[j].p-p[j]);

    for(int j=1;j<=W;j++) Max(dp[i][j],dp[i][j-1]);
  }
}


ll DP[100010];
ll calc_p(){
  for(int i=0;i<(1<<n);i++)
    for(int k=0;k<=T-time[i];k++)Max(DP[k+time[i]],DP[k]+dp[i][W]);
  ll res=0;
  for(int i=0;i<=T;i++) Max(res,DP[i]);
  return res;
}

int main(){
  cin>>n>>m>>W>>T;
  for(int i=0,v,p;i<m;i++){
    string s;
    cin>>s>>v>>p;
    M[s]=i;
    prod[i] = (datp){v,p};
  }

  shop[n] = (dats){0,0,0};
  for(int i=0,l;i<n;i++){
    cin>>l>>shop[i].x>>shop[i].y;
    string s;
    for(int j=0;j<m;j++) shop[i].p[j] = 1e9;
    for(int j=0,p;j<l;j++)cin>>s>>p,shop[i].p[M[s]] = p;
  }
  calc_time(0,0,n);
  calc_w();  
  cout<<calc_p()<<endl;
  return 0;
}

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

int main() {
    long long n;
    cin >> n;
    long long ans = 0;
    vector<int> memo;
    long long nmax = 1000000000000;
    for(long long i=2; i<=sqrt(nmax); i++) {
        if(n%i==0){
            memo.push_back(0);
        }
        long long tmp = n;
        while(n%i==0) {
            n /= i; 
            memo[memo.size()-1]++;
        }
    }
    if(n != 1) {
        ans++;
    }
    for(int i=0; i<memo.size(); i++){
        for(int j=1;;j++) {
            if(memo[i] >= j) {
                memo[i] -= j;
                ans++;
            }else{
                break;
            }
        }
    }
    cout<< ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <string.h>
#define ll long long int
int main(void){
	ll i,ans=0,b=0;
	char S[200001];
	scanf("%s",S);
	for(i=0;i<strlen(S);i++){
		if(S[i] == 'B')	b++;
		else ans += b;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){
    string str;
    cin >> str;
    int cnt = 0, max = 0;
    for(int i = 0; i < 3; i++){
        if(str[i] == 'R'){
            cnt++;
        } else {
            cnt = 0;
        }
        if(max < cnt) max = cnt;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s.at(i)=='1') s.at(i)='9';
        else if(s.at(i)=='9') s.at(i)='1';
    }
    cout<<s<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << # x << "; "<< x << endl


int main() {
	int A, B;
	cin >> A >> B;
	int total = 1;
	int count = 0;
	while (total < B) {
		total += A - 1;
		count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 3580
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    N, M = read_values()
    K = []
    for _ in range(M):
        a, _ = read_values()
        T = read_list()
        K.append((a, T))

    dp = [10 ** 8] * (2 ** N + 10)
    dp[0] = 0
    for a, T in K:
        k = 0
        for t in T:
            k += 1 << (t - 1)
        for i in range(2 ** N):
            dp[i | k] = min(dp[i | k], dp[i] + a) 

    res = dp[2 ** N - 1]
    print(res if res != 10 ** 8 else -1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 40560
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#include <stdio.h>
#define ll long long
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>QUE;//きゅー

int length(char* str) {
	int len = strlen(str);
	return len;
}
struct ans{
    int cost;
    int count;
    bool operator<(const ans& b)const {
        return cost < b.cost;
    };
};
ll LCM(ll a,ll b)
{

    ll r, x, tmp;
    ll i, j;
    ll lcm;
    i = a;
    j = b;

    /* 自然数 a > b を確認・入替 */
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    lcm = (i / b) * j;

    return lcm;
}
int A[100010000];
int a[100010], b[100010];
int main()
{
    ll N, K;
    cin >> N >> K;
    ans Ans[100010];
    for (int i = 0; i < N; i++) {
        cin >> Ans[i].cost >> Ans[i].count;
    }
    sort(Ans, Ans + N);
    ll T = 0;
    for (int i = 0; i < N; i++) {
        T += Ans[i].count;
        if (T >= K) {
            cout << Ans[i].cost;
            break;
        }
    }


}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<LL> a(n);
    rep(i, n) cin >> a[i];

    sort(all(a));
    vector<LL> ans1, ans2;
    ans1.push_back(a[0]);
    ans2.push_back(a[0]);
    int i=0, j=1;
    LL last;
    while(i+j<n-1){
        ans1.push_back(a[n-i-1]);
        i++; if(i+j>=n-1){
            last = a[n-i-1];
            break;
        }
        ans2.push_back(a[n-i-1]);
        i++; if(i+j>=n-1){
            last = a[j];
            break;
        }
        ans1.push_back(a[j]);
        j++; if(i+j>=n-1){
            last = a[j];
            break;
        }
        ans2.push_back(a[j]);
        j++; if(i+j>=n-1){
            last = a[n-i-1];
            break;
        }
    }
    // repe(i, ans1) cout << i << " "; cout << endl;
    // repe(i, ans2) cout << i << " "; cout << endl;

    LL ans = 0;
    rep(i, ans1.size()-1) ans += abs(ans1[i+1]-ans1[i]);
    rep(i, ans2.size()-1) ans += abs(ans2[i+1]-ans2[i]);
    ans += max(abs(ans1.back()-last), abs(ans2.back()-last));
    if(n==2) ans = a[1]-a[0];
    cout << ans << endl;




}



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

typedef long long ll;

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

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

double PI=3.1415926535897932384626;

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

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

#define fi first
#define se second

ll r,s,p;

ll f(char no)
{
	if(no=='r')
	{
		return p;
	}
	else if(no=='p')
	{
		return s;
	}
	else
	{
		return r;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	cin>>r>>s>>p;
	string t;
	cin>>t;
	ll ans=0;
	for(ll i=0;i<t.size();i++)
	{
		if(t[i]=='x')
			continue;
		ll j=i+k;
		if(j<t.size())
		{
			if(t[i]==t[j])
			{
				t[j]='x';
			}
			ans+=f(t[i]);
		}
		else
		{
			ans+=f(t[i]);
		}
	}
    cout<<ans;
    return 0;
}


//252908XL

Measured memory_bytes: 512
#include <iostream>

using namespace std;
typedef long long ll;

int main() {
    ll x, y;
    cin >> x >> y;

    if (x % y == 0ll) {
        cout << -1 << endl;
    } else {
        for (ll i = 2ll; x * i < 1000000000000000000ll; i++) {
            if (x * i % y != 0) {
                cout << x * i << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//素数を指数と共に返す関数。pが底でnumが指数
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(){
  ll n,m; cin >> n >> m;
  COMinit();
  auto v = prime_factorize(m);
  
  ll ans = 1;
  
  for(auto v1:v){
    ll p,num;
    tie(p,num) = v1;
    ans *= COM(num+n-1,n-1);
    ans %= MOD;
  }
  
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;
typedef long long ll;

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

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

  ll ans = 1LL;
  for (int i = 0; i < N; i++) {
    ll T;
    cin >> T;
    ans = lcm(ans, T);
  }
  cout << ans << endl;
  return 0;
}

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

int N;
long long a[50];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    bool complete = false;
    long long ans = 0;
    while(!complete){
        long long s[50] = {}, s_sum = 0;
        for(int i = 0; i < N; i++){
            s[i] = a[i] / N;
            a[i] -= s[i] * N;
            s_sum += s[i];
        }
        complete = true;
        for(int i = 0; i < N; i++){
            a[i] += (s_sum - s[i]);
            if(a[i] >= N){
                complete = false;
            }
        }
        ans += s_sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <math.h>

using namespace std;
typedef long long LL;
const int maxn = 100005;
int o[maxn],X,n,Q,t[maxn],a[maxn];
int l[maxn],fl[maxn],r[maxn];
int main()
{
	#ifdef Amberframe
		freopen("arc082f.in","r",stdin);
		freopen("arc082f.out","w",stdout);
	#endif
	scanf("%d %d",&X,&n);r[0]=X;
	for (int i=1;i<=n;i++) scanf("%d",&o[i]);
	for (int i=1;i<=n;i++)
	if (i&1) {
		int d=o[i]-o[i-1];
		if (l[i-1]==r[i-1])
			l[i]=r[i]=l[i-1],fl[i]=max(0,fl[i-1]-d);
		else if (fl[i-1]>=d)
			l[i]=l[i-1],r[i]=r[i-1],fl[i]=fl[i-1]-d;
		else if (l[i-1]+d-fl[i-1]>=r[i-1])
			l[i]=r[i]=0,fl[i]=0;
		else
			l[i]=l[i-1]+d-fl[i-1],r[i]=r[i-1],fl[i]=0;
	}
	else {
		int d=o[i]-o[i-1];
		if (l[i-1]==r[i-1])
			l[i]=r[i]=l[i-1],fl[i]=min(X,fl[i-1]+d);
		else if (fl[i-1]+r[i-1]-l[i-1]+d<=X)
			l[i]=l[i-1],r[i]=r[i-1],fl[i]=fl[i-1]+d;
		else if (fl[i-1]+d>=X)
			l[i]=r[i]=0,fl[i]=X;
		else
			l[i]=l[i-1],r[i]=r[i-1]-(fl[i-1]+r[i-1]-l[i-1]+d-X),fl[i]=fl[i-1]+d;
	}
	scanf("%d",&Q);
	for (int i=1;i<=Q;i++)
		scanf("%d %d",&t[i],&a[i]);
	for (int pos=0,i=1;i<=Q;i++)
	{
		while (pos<n&&o[pos+1]<=t[i]) ++pos;
		int cur=(a[i]<=l[pos]?fl[pos]:fl[pos]+min(r[pos],a[i])-l[pos]);
		int d=t[i]-o[pos];pos&1?cur=min(cur+d,X):cur=max(cur-d,0);
		printf("%d\n",cur);
	}
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

#define rep(i,m,n) for(int i=m;i<n;i++)
#define ll long long
#define MOD 1000000007

ll mult_num(ll a, ll b, ll n) {
  ll q = (b-a+1)/n;
  ll r = (b-a+1)%n;
  if(b%n < r) q++;

  return q;
}

int main(int argc, char *argv[]) {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;

  ll ans = b-a+1;
  ans -= mult_num(a,b,c);
  ans -= mult_num(a,b,d);

  ll g1 = c, g2 = d;
  while(g1 > 0 && g2 > 0) {
    if(g1 > g2) g1 -= g2;
    else g2 -= g1;
  }
  ll g = max(g1,g2);
  ans += mult_num(a,b,(c*d)/g);

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


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

# 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():
    N, l = map(int,input().split())
    s_sorted = sorted([input() for i in range(N)])
    print("".join(s_sorted))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define mll map<ll,ll>
#define sll set<ll>
#define fo(i,n) for(i=0;i<n;i++)
#define MOD 1000000007
using namespace std;

bool vis[100001];
vll v[100001];
ll c[100001],lev[100001],pa[100001];
ll dfs(ll i,ll j)
{
    lev[i]=j;
    vis[i]=true;
    ll ans=1,k;
    fo(k,v[i].size())
    {
        if(!vis[v[i][k]])
        {
            pa[v[i][k]]=i;
            ans+=dfs(v[i][k],j+1);
        }
    }
    c[i]=ans;
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    //freopen("000.txt","r",stdin);
    ll n,i,j,k,t,a,b;

    cin>>n;
    fo(i,n-1)
    {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    dfs(1,0);

    j=n;
    fo(i,(lev[n]-1)/2)
        j=pa[j];
    //cout<<c[j]<<" "<<j<<" "<<c[1]<<endl;

    if(c[1]-c[j]>c[j])
        cout<<"Fennec";
    else
        cout<<"Snuke";

    return 0;
}


Measured memory_bytes: 14464
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
using ll = long long;
using vi = vector<int>;
#define loop(i, n) for (int i = 0; i < (int)n; i++)
#define rloop(i, n) for (int i = (int)n - 1; i >= 0; i--)
 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
 
int main() {
    string s; cin >> s;
	vi a(2019, 0);
	a[0] = 1;
	int t = 0;
	rloop(i, s.size()) {
		t = (modpow(10, s.size() - i - 1, 2019) * (s[i] - 48) + t) % 2019;
		a[t]++;
	}
	ll sum = 0;
	loop(i, 2019) {
		sum += a[i] * (a[i] - 1) / 2;
	}
	cout << sum << endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define MAXN 2010
#define MAXB 4000010
int n,a[MAXN];
bitset<MAXB> r;
int main() {
	cin >> n;
	int ksum = 0;
	r[0] = 1;
	for (int i=0; i<n; i++) {
		cin >> a[i];
		ksum += a[i];
		r = (r | (r << a[i]));
	}
	ksum = (ksum + 1) >> 1;
	while (r[ksum] == 0) {
		ksum++;
	}
	cout << ksum << endl;
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
#define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
// #define inf 1e15
    
const int N=1e6+5;
const int M=1e9+7;
void solve()
{
	int n;
	cin>>n;
	int a[n+1];
	int tot=0;
	int inf=1e15;
	f(i,0,n) cin>>a[i],tot+=a[i];
	int curr=1;
	int ans=0;
	f(i,0,n)
	{
		if(curr<a[i])
		{
			cout<<"-1";
			return;
		}
		curr-=a[i];
		curr=curr*2;
		curr=min(curr,inf);
	}
	curr=1;
	f(i,0,n)
	{
		ans+=curr;
		curr-=a[i];
		tot-=a[i];
		curr*=2;
		curr=min(curr,tot);
	}
	cout<<ans<<endl;
}
signed main()  
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    double T,X;
    cin >>  T >> X;
    double ans = T/X;
    printf("%.8lf", ans);
    //cout << T / X << endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 int main(){
 int n,m,best=0,gain;
 scanf("%d",&n);
 char s[n][10];
 for (int i=0;i<n;i++){
 scanf(" %s",s[i]);
 }
 scanf("%d",&m);
 char t[m][10];
 for (int i=0;i<m;i++){
 scanf(" %s",t[i]);
 }
 for (int i=0;i<n;i++){
 gain=0;
 for (int j=0;j<n;j++){
 if (0==strcmp(s[i],s[j])){
 gain++;
 }
 }
 for (int j=0;j<m;j++){
 if (0==strcmp(s[i],t[j])){
 gain--;
 }
 }
 if (best<gain){
 best=gain;
 }
 }
 printf("%d\n",best);
 return 0;
 }

Measured memory_bytes: 128