akhauriyash/Code-Regression huggingface dataset:
N,K = map(int, input().split())
MOD = 10**9 + 7

accum = [i for i in range(1, N+1)]

for i in range(1, len(accum)):
    accum[i] += accum[i-1] 
accum = [0] + accum

backs = [i for i in range(N,-1,-1)]
cnt = [0] * (N+1)

tmp = 0
for i in range(N+1):
    tmp += backs[i]
    cnt[i] = tmp + 1 - accum[i]

ans = 0
for num in cnt[K-1:]:
    ans += num
    ans %= MOD

print(ans)

Measured memory_bytes: 36600
import sys
sys.setrecursionlimit(10**6)

n = int(input())
win = {}
# key:勝者 value:keyに負けた人(set)
for i in range(n - 1):
    a = int(input())
    a -= 1
    if a not in win.keys():win[a] = set()
    win[a].add(i+1)

def dfs(winner):
    if winner not in win.keys():return 0
    losers = win[winner]
    storong = len(losers)
    deeps = []
    for loser in losers:
        deeps.append(dfs(loser))
    deeps.sort(reverse = True)
    deep = 1
    for i,d in enumerate(deeps):
        deep = max(deep, i+1 + d)
    return deep

print(dfs(0))


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

int main() {
  int N;
  cin >> N;
  vector<int> V(N), C(N);
  for (int i = 0; i < N; i++) {
    cin >> V.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
  }

  vector<int> Z(N);//V-C
  for (int i = 0; i < N; i++) {
    Z.at(i) = V.at(i) - C.at(i);
  }

  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (Z.at(i) > 0) {
      sum += Z.at(i);
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
n,d = map(int,input().split())
i=0
num_list=[]
for k in range(n):
  num_list.append(list(map(int,input().split())))
for j in range(n):
  if num_list[j][0]**2 + num_list[j][1]**2 <= d**2:
    i = i + 1
print(i)

Measured memory_bytes: 45452
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void generate_primes(int limit, int **primes, int *prime_count);
int count_le(int prime, int *primes, int prime_count);

int main(int argc, char *argv[])
{
	int value;
	int *primes;
	int prime_count;
	generate_primes(1000000, &primes, &prime_count);

	while (scanf("%d", &value) != -1) {
		printf("%d\n", count_le(value, primes, prime_count));
	}

	free(primes);
	return 0;
}

void generate_primes(int limit, int **primes_out, int *prime_count_out)
{
	int i;
	int *primes, *remains, prime_count, prime_length;
	char *marks;
	int marks_length;

	prime_length = 1024;
	primes = calloc(prime_length, sizeof(int));
	remains = calloc(prime_length, sizeof(int));

	primes[0] = 2;
	primes[1] = 3;
	prime_count = 2;

	marks_length = 1024;
	marks = calloc(marks_length, sizeof(char));

	for (i=0; primes[prime_count-1]<limit; i++) {
		int j;
		int extend_length;
		extend_length = primes[i+1] * primes[i+1] - primes[i] * primes[i];

		/* prepare marks buffer */
		if (marks_length < extend_length) {
			while (marks_length < extend_length) {
				marks_length *= 2;
			}
			free(marks);
			marks = calloc(marks_length, sizeof(char));
		} else {
			memset(marks, 0, marks_length);
		}

		/* mark prime multiple */
		for (j = 0; j <= i; j++) {
			int pos;
			for (pos = remains[j]; pos < extend_length; pos += primes[j]) {
				marks[pos] = 1;
			}
			remains[j] = pos - extend_length;
		}

		/* append new primes */
		for (j = 0; j < extend_length; j++) {
			if (!marks[j]) {
				int prime;
				prime = primes[i] * primes[i] + j;
				if (prime_count == prime_length) {
					prime_length *= 2;
					primes = realloc(primes, prime_length * sizeof(int));
					remains = realloc(remains, prime_length * sizeof(int));
				}
				primes[prime_count] = prime;
				remains[prime_count] = 0;
				prime_count++;
			}
		}
	}

	free(remains);
	free(marks);

	*primes_out = primes;
	*prime_count_out = prime_count;
}

int count_le(int value, int *primes, int prime_count)
{
	int left, right;
	left = 0;
	right = prime_count;
	while (left < right) {
		int middle = (left + right) / 2;
		if (value < primes[middle]) {
			right = middle;
		} else {
			left = middle + 1;
		}
	}
	return left;
}

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

int main(){
  string s;
  cin >> s;
  int n=s.size();
  int cnt=0;
  for(int i=0; i<n; i++){
    if(i==0){
      if(s[i]!='A'){
        cout << "WA" << endl;
        return 0;
      }
    }
    if('A' <= s[i] && s[i] <= 'Z' && (!(i==0)) && s[i]!='C'){
      cout << "WA" << endl;
      return 0;
    }
    if(i==1) continue;
    if(2<=i && i<=n-2){
      if(s[i]=='C') cnt++;
    }
  }
  if(cnt!=1) cout << "WA" << endl;
  else cout << "AC" << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <map>
#include <vector> 
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
    int n;
    cin >> n;
    std::vector<double> v;
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        //cout << tmp << ",";
        v.push_back((double)tmp);
    }
    //cout << endl; 
    double sum = 0.0;
    std::sort(v.begin(),v.end());
    int cnt = 0;
    std::vector<double>::iterator itr = v.begin();
    while(itr != v.end()){
        cnt++;
        if(cnt == v.size()){
            break;
        }
        double x = *itr;
        ++itr;
        double y = *itr;
        double tmp = (x+y)/2.0;
        *itr = tmp;
        sum = tmp;
        //cout << x << ":" << y << " -> " << sum  << ", ";
    }
    //cout << endl; 
    cout << sum << endl; 

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//
int main() {
	cin >> N;
	if (N % 2 == 0) {
		cout << N / 2;
	}
	else {
		cout << N / 2 + 1;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN
#define fi first
#define se second
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int INF = 1 << 30;
const int p = 1000000009;
int lowbit(int x){ return x & (-x);}
int fast_power(int a, int b){ int x; for(x = 1; b; b >>= 1){ if(b & 1) x = 1ll * x * a % p; a = 1ll * a * a % p;} return x % p;}

int main(){
	char ch = getchar();
	putchar(ch + 1);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    vector<vector<int>> A(N, vector<int>(M));
    rep(i, M) { cin >> B[i]; }
    rep(i, N) {
        rep(j, M) { cin >> A[i][j]; }
    }
    int ans = 0;
    rep(i, N) {
        int k = 0;
        rep(j, M) { k += B[j] * A[i][j]; }
        if (0 < k + C) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    long long n;
    cin >> n;
    auto lcm = [&] (ll a, ll b) {
        return (a * b) / __gcd(a,b);
    };
    cout << lcm(360, n) / n << '\n';
    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define LL long long
#define M 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
	fastio
	int n, i, k, cnt=0;
	cin>>n>>k;
	for(i=0; i<n; i++){
		int a;
		cin>>a;
		if(a>=k)
			cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 384
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
int a[N],n,m,las,pos,t;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]);
	sort(a+1,a+1+n),reverse(a+1,a+1+n);
//	fp(i,1,n)printf("%d%c",a[i]," \n"[i==n]);
	fp(i,1,n)if(a[i]>=i)pos=i;else break;
	a[n+1]=0,t=1;fp(i,pos+1,n)if(a[i]==pos)t^=1;else break;
//	printf("%d %d\n",(a[pos]-pos+1)&1,t);
	puts(!(((a[pos]-pos+1)&1)&t)?"First":"Second");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

int a[N];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++)   scanf("%d", &a[i]);
	LL maxd = 0;
	LL ans = 0;
	for (int i = 1; i <= n; i ++){
		if (a[i] < maxd)  ans = ans + (maxd - a[i]);
		maxd = max(maxd, (LL)a[i]);  
	}
	
	cout << ans << endl;
	
	return 0;
}

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

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
long long a[n];
for(int i=0;i<n;++i)
    cin>>a[i];
sort(a,a+n);
long long an=0,ar=0;
for(int i=1;i<n;++i)
{
    int l=0,r=i-1;
    long long f=a[i]/2;
    int m=(l+r)/2;
    while(l!=r)
    {
        if(a[m]==f)
            break;
        if(a[m]<f)
        {
            l=m+1;
            m=(l+r)/2;
        }
        else
        {
            r=m;
            m=(l+r)/2;
        }
    }
    while(m>0&&abs(a[m]-f)>abs(a[m-1]-f))
    {--m;} 
    while(m<n-1&&abs(a[m]-f)>abs(a[m+1]-f))
    {++m;}
    if(an=0)
    {
        an=a[i];
        ar=a[m];
    }
    else
    {
        if(ar==0||ar==an)
        {
            an=a[i];
            ar=a[m];
        }
        else
        {
            an=a[i];
            ar=a[m];
        }
    }
}
cout<<an<<" "<<ar;
}


Measured memory_bytes: 1024
import bisect
n = int(input())
tris = list(map(int,input().split()))
tris.sort()
cnt = 0
for i in range(n-2):
    a = tris[i]
    for j in range(i+1,n-1):
        b = tris[j]
        r = bisect.bisect_left(tris, a+b)
        cnt += r - j - 1
print(cnt)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <assert.h>
 
#define int          long long
#define pb          push_back
#define pii         pair<int,int> 
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007 
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cout << #x << " is " << x << flush << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
using namespace std;
const int maxn = 200010;


char c;
void solve(){
	int n, m;
	cin>>n>>m;
	int a[n+1][m+1], dp[n+1][m+1];
	memset(a, 0, sizeof(a));
	memset(dp, 0, sizeof(dp));
	rep(i, 1, n+1)
	{
		rep(j,1,m+1)
		{
			cin>>c;
			if(c=='.')
				a[i][j] = 1;
		}
	}
	rep(i, 1, n+1)
	{
		if(a[i][1]==1)
			dp[i][1] = 1;
		else break;
	}
	rep(j,1,m+1)
	{
		if(a[1][j]==1)
			dp[1][j] = 1;
		else break;
	}

	rep(i, 2, n+1)
	{
		rep(j, 2, m+1)
		{
			if(a[i][j] == 1)
				dp[i][j] = (dp[i-1][j] + dp[i][j-1])%hell;
			else dp[i][j] = 0;
		}
	}
	
	cout<<dp[n][m];
	



}
 
signed main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int t=1;
     //cin>>t;
 
    while(t--)
        solve();
    
    return 0;
}

Measured memory_bytes: 15872
n,a = list(map(int,input().split()))
x = list(map(int,input().split()))

def Count(n,k,a):
	s = sum(x)
	dp=[[[0 for l in range(s+1)] for j in range(k+1)] for i in range(n+1)]
	dp[0][0][0]=1
	Sum=0
	for i in range(n):
		for j in range(k+1):
			for l in range(s+1):
				if l < x[i]:
					dp[i+1][j][l] = dp[i][j][l]
				if j >=1 and l >= x[i]:
					dp[i+1][j][l] = dp[i][j][l] + dp[i][j-1][l-x[i]]
				if j <= i+1 and l ==j*a and j >= 1:
					if dp[i+1][j][l]>=1:	
						Sum += dp[i+1][j][l]-dp[i][j][l]
	return Sum

print(Count(n,n,a))



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

int main()
{
	string s; cin >> s;
	vector<int> c(s.size()); for (int i = 0; i < s.size(); i++) c[i] = (int)(s.at(i) - '0');

	if (c[0] + c[1] + c[2] + c[3] == 7) { cout << s[0] << '+' << s[1] << '+' << s[2] << '+' << s[3] << "=7"; return 0; }
	if (c[0] + c[1] + c[2] - c[3] == 7) { cout << s[0] << '+' << s[1] << '+' << s[2] << '-' << s[3] << "=7"; return 0; }
	if (c[0] + c[1] - c[2] + c[3] == 7) { cout << s[0] << '+' << s[1] << '-' << s[2] << '+' << s[3] << "=7"; return 0; }
	if (c[0] - c[1] + c[2] + c[3] == 7) { cout << s[0] << '-' << s[1] << '+' << s[2] << '+' << s[3] << "=7"; return 0; }
	if (c[0] + c[1] - c[2] - c[3] == 7) { cout << s[0] << '+' << s[1] << '-' << s[2] << '-' << s[3] << "=7"; return 0; }
	if (c[0] - c[1] + c[2] - c[3] == 7) { cout << s[0] << '-' << s[1] << '+' << s[2] << '-' << s[3] << "=7"; return 0; }
	if (c[0] - c[1] - c[2] + c[3] == 7) { cout << s[0] << '-' << s[1] << '-' << s[2] << '+' << s[3] << "=7"; return 0; }
	if (c[0] - c[1] - c[2] - c[3] == 7) { cout << s[0] << '-' << s[1] << '-' << s[2] << '-' << s[3] << "=7"; return 0; }
		
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-
from math import factorial

def combination_formula(n, r):
    return factorial(n) // (factorial(r)*factorial(n-r))

def solve():
    N, K = list(map(int, input().split()))
    R, B = N-K, K
    MOD = 10**9+7

    for i in range(1, K+1):
        if R+1 < i:
            print(0)
            continue

        ans = combination_formula(R+1, i)%MOD  # R+1の隙間のうち、i個の箇所に青玉を入れる組み合わせ

        restB = B - i

        ans *= combination_formula(restB+(i-1), i-1)%MOD  # 残りの青玉とi-1個のしきいの、重複組み合わせ
        print(ans%MOD)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
// #include <numeric>
// #include <string>
// #include <queue>
// #include <set>
// #include <map>
// #include <iomanip>
// #include <list>
// #include <cassert>

#define MOD 1000000007
// #define INF 1000000001
#define S 100001

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;

void p_() {
    cout << "\n";
}
template<class Head, class... Body>
void p_(Head head, Body... body) {
    cout << head << ",";
    p_(body...);
}

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    for (const auto& i : v) {
        os << i << " ";
    }
    os << "]";
    return os;
}

void dfs(int from, int dist, const vector<vector<int>>& E, vector<int>& D) {
    D[from] = dist;
    for (int to : E[from]) {
        if (D[to] == -1) {
            dfs(to, dist + 1, E, D);
        }
    }
}

int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    vector<vector<int>> E(N);
    for (int i = 0; i < N-1; ++i) {
        int a, b;
        cin >> a >> b;
        E[a-1].push_back(b-1);
        E[b-1].push_back(a-1);
    }

    vector<bool> visited(N, false);
    vector<int> D1(N, -1), D2(N, -1);
    dfs(0, 0, E, D1);
    dfs(N-1, 0, E, D2);
    // cout << D1 << endl;
    // cout << D2 << endl;

    int count = 0;
    for (int i = 0; i < N; ++i) {
        if (D1[i] <= D2[i]) {
            count += 1;
        }
    }
    if (count * 2 > N) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }

    return 0;
}


Measured memory_bytes: 11264
n=int(input())

dp=[float('inf')]*(n+1)
dp[0]=0

for i in range(1,n+1):
  
  power=1
  while(power<=i):
    dp[i]=min(dp[i],dp[i-power]+1)
    power*=6
  
  power=1
  while(power<=i):
    dp[i]=min(dp[i],dp[i-power]+1)
    power*=9

print(dp[n])

Measured memory_bytes: 74612
#coding:utf-8

W , H,x,y,r =input().rstrip().split(" ")
W = int(W)
H = int(H)
x = int(x)
y = int(y)
r = int(r)

f = 0
if x - r<0:
    f = 1
elif x + r>W:
    f = 1
elif y - r<0:
    f = 1
elif y + r>H:
    f=1
else:
    pass

if f ==1:
    print("No")
else:
    print("Yes")
    
    

Measured memory_bytes: 7652
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S,T;
    cin >> S >> T;
    ll N = S.size();
    if(S == T){
        print("Yes");
        return 0;
    }
    rep(i,1,N){
        if(S.substr(N-i,i) + S.substr(0,N-i) == T){
            print("Yes");
            return 0;
        }
    }
    print("No");

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<double> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  double sum=0;
  for(int i=0;i<N;i++){
    double x=1/vec.at(i);
    sum+=x;
  }
  cout<<1/sum<<endl;
}
    

Measured memory_bytes: 3776
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(13);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI = 3.141592653589793;

const int M = 1e9+7;

int answer[100001];

void work(int n)
{
	answer[1] = 1;
	for(int i=2;i<=n;i++)
	{
		answer[i] = i*(answer[i-1] % M);
		answer[i] %= M;
	}
}

void solve()
{
	int n;
	cin >> n;
	work(n);
	cout << answer[n];
}

int32_t main()
{
	FastIO;
	Fast_D;
	solve();
	return 0;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Mat = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5+10;

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];

    vector<int> dir_x = {1,1,1,0,0,-1,-1,-1};
    vector<int> dir_y = {1,0,-1,1,-1,-1,1,0};
    rep(i,h){
        rep(j,w){
            int sum = 0; 
            rep(k,8){
                int x = i + dir_x[k];
                int y = j + dir_y[k];
                if(0<=x && x<h && 0<=y && y<w && s[x][y]=='#') ++sum;
            }
            if(s[i][j]!='#') s[i][j] = (char)(sum + '0');
        }
    }
    rep(i,h) cout(s[i]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int h,w;cin>>h>>w;
   char t[h][w];
   for(int i=0;i<h;i++){
       for(int j=0;j<w;j++){
           cin>>t[i][j];
       }
   }
   int roty1[2]={1,-1},rotx2[2]={1,-1};
   int res=0;
   int ren[h][w][4];
   for(int i=0;i<h;i++){
       for(int j=0;j<w;j++){
           for(int k=0;k<2;k++){
               ren[i][j][k]=0;//k==1のときその地点の横の距離、k==0の時は縦の距離をメモっておく
           }
       }
   }
   for(int i=0;i<h;i++){
       for(int j=0;j<w;j++){
           int ans=1;
           if(t[i][j]=='#'){
              // cout<<0<<" ";
               continue;
           }
           int x,y;x=j;y=i;
           int now=0;
           if(0<=y-1&&ren[y-1][x][0]>0){
               ren[y][x][0]=ren[y-1][x][0];
               now=ren[y][x][0];
           }else{
               for(int k=0;k<2;k++){
                   int ny=y+roty1[k];
                   while(0<=ny&&ny<h&&t[ny][x]=='.'){
                       ny+=roty1[k];
                       now++;
                   }
               }
               ren[y][x][0]=now;
           }
           ans+=now;now=0;
           if(0<=x-1&&ren[y][x-1][1]>0){
               ren[y][x][1]=ren[y][x-1][1];
               now=ren[y][x][1];
           }else{
               for(int k=0;k<2;k++){
                   int nx=x+rotx2[k];
                   while(0<=nx&&nx<w&&t[y][nx]=='.'){
                       nx+=rotx2[k];
                       now++;
                   }
               }
               ren[y][x][1]=now;
           }
           ans+=now;
           res=max(ans,res);
           //cout<<ren[i][j][0]<<" ";
       }
       //cout<<endl;
   }
   cout<<res<<endl;
}


Measured memory_bytes: 66688
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
	int n ,m,s=0,a[10000];
	cin >> n >> m;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
	}
	sort(a,a+n);
	for(int i=0;i<m;i++)
	{
		s=s+a[i];
	}
	cout << s<<"\n";
	
	
}


Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main(){
	int N,a[100],count=0,flag,val;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	flag = 1;
	while(flag==1){
		flag = 0;
		for(int j=N-1;j>=1;j--){
			if(a[j]<a[j-1]){
				val = a[j];
				a[j]=a[j-1];
				a[j-1]=val;
				flag = 1;
				count++;
			}
		}
	}
	for(int i=0;i<N;i++){
if(i>0)cout << " ";
		cout << a[i] ;
	}
	cout << "\n" << count << endl;
	return 0;
}

Measured memory_bytes: 3120
// C - Bugged
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define MAX 10000 // N*si = 100*100

int main(){
	int N; cin>>N;
	int maxi = 0;
	vi dp(MAX+1);
	dp[0] = true;
	for(int i=1; i<=N; ++i){
		int s; cin>>s;
		for(int j=MAX; j>=s; --j){
			dp[j] = max(dp[j], dp[j-s]);
			maxi = max(maxi, (dp[j]*j%10? j: 0));
		}
	}
	cout<< maxi <<endl;
}

Measured memory_bytes: 256
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))

A_max = max(A)
A_max_2 = sorted(A)[-2]
for i in range(n):
    if A[i] == A_max:
        print(A_max_2)
    else:
        print(A_max)


Measured memory_bytes: 13440
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#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 <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<long long,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
 
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

//long long A,B;
bool ok(long long key,long long index){
    if(index > key) return true;
    else if(index <= key) return false;
}
long long binary_search(long long key,long long size){
    //left,right,midはいずれもindex
    long long left = -1,right = size;
    while(right - left > 1){
        long long mid = left + (right-left)/2;
        long long hantei = ok(key,mid);
        if(hantei) right = mid;
        else left = mid;
    }
    if(left == -1)return 0;
    return left;
}

int main() {
    int N;cin >> N;
    map<string,int> M;
    for(int i = 0;i<N;i++){
        string S;cin >> S;
        M[S]++;
    }
    int K;cin >> K;
    for(int i = 0;i<K;i++){
        string T;cin >> T;
        M[T]--;
    }
    int ans = 0;
    for(pair<string,int> A : M){
        int value = A.second;
        ans = max(ans,value);
    }

    cout << ans << endl;

    // PLEASE GIVE ME THE "ACCEPTED" !
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main (void) {
    char s[201];
    char p[102];
    int k;

    fgets (s, 102, stdin);
    fgets (p, 102, stdin);

    s[strlen(s)-1] = '\0';
    p[strlen(p)-1] = '\0';
    strncat (s, s, strlen(s));
    
    if (strstr (s, p) != NULL) {
        printf ("Yes\n");
    } else {
        printf ("No\n");
    }

    return 0;
}


Measured memory_bytes: 2104
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

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

def main():
    n = int(input())
    a = readInt()
    q = int(input())
    bc = []
    mx = max(a)
    for i in range(q):
        bc.append(readInt())
        mx = max(mx,max(bc[i][0],bc[i][1]))
    A = [0 for i in range(mx+1)]
    for x in a:
        A[x] += 1
    ans = sum(a)
    for i in range(q):
        b,c = bc[i]
        ans += (c-b)*A[b]
        A[c] += A[b]
        A[b] = 0
        print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 97652
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int n;
    scanf("%d",&n);
    ll a[3*n] = {};
    rep(i,3*n){
        scanf("%lld",&a[i]);
    }
    sort(a,a+3*n);

    ll ans = 0;

    rep(i,n){
        ans += a[n+i*2];
    }
    
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

bool comp(pair<int,int> lhs, pair<int,int> rhs)
{
  return lhs.first > rhs.first;
}

int main()
{
  int N;
  ll K;
  vector<pair<int, int> > v;
  cin >> N >> K;

  rep(i,N) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a,b));
  }

  sort(v.begin(),v.end(), comp);

  ll cnt = 0;
  while(v.size()){
    pair<int, int> p = v.back();
    if(cnt + (ll)p.second >= K){
      cout << p.first << endl;
      return 0;
    }
    else {
      cnt += (ll)p.second;
    }
    v.pop_back();
  }
  return 0;
}

Measured memory_bytes: 1400
//0 :レート 1-399：灰色
//1 :レート 400-799：茶色
//2 :レート 800-1199：緑色
//3 :レート 1200-1599：水色
//4 :レート 1600-1999：青色
//5 :レート 2000-2399：黄色
//6 :レート 2400-2799：橙色
//7 :レート 2800-3199：赤色
//8 : 3200 Over
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int his[9]={};
int main(int argc , char **argv)
{
	(void)argc;
	(void)argv;

	int N;
	cin >> N;
	for(int i=1;i<=N;i++){
		int a;
		cin >> a;
		int c = a/400;
		if (3200 <= a){c = 8;}
		his[c]++;
	}

	int cc=0;
	for(int i=0;i<=7;i++){
		if( 0<his[i] ){cc++;}
	}

	printf("%d %d\n",max(1,cc),cc+his[8]);

	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
v_list = gets.split(" ").map(&:to_i)
c_list = gets.split(" ").map(&:to_i)
sum = 0
n.times do |i|
  diff = v_list[i] - c_list[i]
  if diff > 0
    sum += diff
  end
end
puts sum

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

using namespace std;

int main()
{
    int task[3];

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

    int  n = sizeof(task);

    sort(task,task+3);

    int b;
    b = task[0]-task[2];

    if(b>=0){
        cout <<b<<endl;
    }
    else
    cout <<-b<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    sort(ALL(A));
    int h = 1, t = N-1;

    // list<ll> lst;
    // lst.push_front(A[0]);

    ll ans = 0;
    ll lst1 = A[0], lst2 = A[0];
    REP(i, N-1) {
        const ll a = abs(lst1 - A[h]);
        ll b = abs(lst1 - A[t]);
        ll c = abs(lst2 - A[h]);
        ll d = abs(lst2 - A[t]);
        ll m = max(max(a, b), max(c, d));
        if(m == a) {
            lst1 = A[h++];
        } else if(m == b) {
            lst1 = A[t--];
        } else if (m == c) {
            lst2 = A[h++];
        } else {
            lst2 = A[t--];
        }
        ans += m;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

int x,n;cin>>x>>n;
bool a[300];
REP(i,300){
  a[i] = false;
}
REP(i,n){
  int t;cin>>t;
  a[t] = true;
}

int now = x;
int ans = 0;
while(1){
  if(a[now] == false){
    ans = now;
    break;
  }

  if(now>=x){
    now = (now-x)*(-1)+x-1;
  }else{
    now = (now-x)*(-1)+x;
  }

}


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

Measured memory_bytes: 3192
#include <iostream>
using namespace std;
int main(void){
    long long N,P,i,j,k,ans=1;
    cin>>N>>P;
    if(N==1){
        cout<<P<<endl;
        return 0;
    }
    for(i=2;P>1&&i*i<P+1;i++){
        k=0;
        while(P%i==0){
            k++;
            P/=i;
        }
        for(j=0;j<k/N;j++){
            ans*=i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define REP(k, n) FOR((k), 0, (n))
using namespace std;
typedef long long ll;
typedef vector<ll> VLL;
const int MOD = 1000000007;

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

    int a, b;
    cin >> a >> b;

    cout << (a - 1) * (b - 1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;

//ここから

void solve(){
  int n,m;
  cin>>n>>m;
  vector<vector<bool>>g(n,vector<bool>(n));
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a][b]=true;
    g[b][a]=true;
  }
  vector<int>v(n-1);
  rep(i,n-1)v[i]=i+1;
  int ans=0;
  do{
    if(!g[0][v[0]])continue;
    bool ng=false;
    rep(i,n-2){
      if(!g[v[i]][v[i+1]])ng=true;
    }
    if(!ng)++ans;
  }
  while(next_permutation(all(v)));
  cout<<ans;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    n %= 10;
    if (n == 3) printf("bon");
    else if (n == 0 || n == 1 || n== 6 || n==8){
        printf("pon");
    }
    else printf("hon");
}


Measured memory_bytes: 3824
n = gets.to_i
a = gets.split.map(&:to_i)
n.times do |i|
  v = a[i]
  j = i - 1
  while j >= 0 && a[j] > v
    a[j+1] = a[j]
    j-=1
  end
  a[j+1] = v
  puts a.join(' ')
end


Measured memory_bytes: 6892
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define in inline
#define reg register
#define int long long
#define MAX 20030813
using namespace std;
namespace qwq{
	in void read(int &o) {
		o=0;
		int w=1;
		char c=getchar();
		while(c<'0'||c>'9') {
			if(c=='-')w*=-1;
			c=getchar();
		}
		while(c>='0'&&c<='9') {
			o=(o<<3)+(o<<1)+(c^48);c=getchar();
		}
		o*=w;
	}
	void write(int x){
	   	if(x<0)putchar('-'),x=-x;
    	if(x>9)write(x/10);
		putchar(x%10+48);
	}
	void Write(int x) {
		write(x);putchar(' ');
	}
	in int max(int x,int y){return x>y?x:y;}
	in int min(int x,int y){return x<y?x:y;}
}
using namespace qwq;
int N,M,ans[MAX],cnt,sum;
bool isPrime(int n){
    if(n<=1)return 0;
    if(n==2||n==3)return 1;
    if((n%6!=5)&&(n%6!=1))return 0;
    for(reg int i=5;i<=sqrt(n);++i)if(n%i==0||n%(i+2)==0)return 0;
    return 1;
}
set<int>s;
signed main()
{
	read(N);read(M);
	for(reg int i=1;i<=sqrt(N);++i)
	{
		if(!(N%i))s.insert(i),s.insert(N/i);
	}
	for(reg int i=1;i<=sqrt(M);++i)
	{
		if(!(M%i))
		{
			if(s.find(i)!=s.end())ans[++cnt]=i;
			if(s.find(M/i)!=s.end())ans[++cnt]=M/i;
		}
	}
	for(reg int i=1;i<=cnt;++i){
		if(isPrime(ans[i]))++sum;
	}
	Write(sum+1); 
	return 0;
}




Measured memory_bytes: 640
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
 
N,M = I()
S = list(s())
T = list(s())
n = lcm(N,M)
l = (N-1)//(n//M)
for i in range(l+1):
    if S[i*(n//M)] != T[i*(n//N)]:
        print(-1)
        exit()
print(n)

Measured memory_bytes: 11148
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll mult(ll a,ll b)
{
	return (a*b)%MOD;
}
ll ans = 0;
VII dp(2,vector<ll>(100005,0));
vii adj;
void dfs(int v,int u)
{
	for(int x:adj[v]){
		if(x == u)continue;
		dfs(x,v);
	}
	dp[0][v] = dp[1][v] = 1;
	for(int x:adj[v])
	{
		if(x == u)continue;
		dp[0][v] = mult(dp[0][v],dp[0][x]+dp[1][x]);
		dp[1][v] = mult(dp[1][v],dp[0][x]);
	}
}
int main()
{
	int n;
	cin>>n;
	adj.resize(n);
	for(int i=0;i<n-1;i++){
		int v,u;
		cin>>v>>u;
		v--;u--;
		adj[v].pb(u);
		adj[u].pb(v);
	}
	dfs(0,-1);
	//for(int i=0;i<n;i++)cout<<dp[0][i]<<" "<<dp[1][i]<<endl;
	ll ans = dp[0][0] + dp[1][0];
	ans%=MOD;
	cout<<ans;
	
}


Measured memory_bytes: 15616
import sys

def resolve():
    x=int(input())
    i=1
    while 1:
        for j in range(i):
            if x==i**5-j**5:
                print(i,j)
                sys.exit()
            elif x==i**5+j**5:
                print(i, -1*j)
                sys.exit()
        i+=1
resolve()

Measured memory_bytes: 64108
#include <bits/stdc++.h>
using namespace std;
int main(){
  int D;
  cin >> D;
  if(D == 25)cout << "Christmas" << endl;
  if(D == 24)cout << "Christmas Eve" << endl;
  if(D == 23)cout << "Christmas Eve Eve" << endl;
  if(D == 22)cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
import sys

k = int(input())

if k % 2 == 0 or k % 10 == 5:
    print(-1)
    sys.exit()
else:
    cnt = 1
    a = 0
    while(True):
        a = (a * 10 + 7) % k
        if a % k == 0:
            print(cnt)
            break

        if cnt > 1000000:
            print(-1)
            break

        cnt += 1


Measured memory_bytes: 63116
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int A[MAX_N], B[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i];
		B[i] = abs(i - (N - i - 1));
	}
	sort(A, A + N);
	sort(B, B + N);
	rep(i, 0, N) {
		if(A[i] != B[i]) {
			cout << 0 << "\n"; return;
		}
	}
	ll res = 1;
	rep(i, 0, N / 2) MUL(res, 2);
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define lld long long int

using namespace std;
int isACTG(char c){
    if(c == 'A' || c=='C' || c=='T' ||c=='G')
    return 1;
    else
    return 0;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
// 	freopen("input.txt", "r", stdin); 
// 	freopen("output.txt", "w", stdout);

    string str;
    cin>>str;
    int n = str.length();
    int start=-1,end=-1;
    int max=-1;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(isACTG(str[i])){
            end=i;
            cnt++;
        }else{
            start = i;
            end=i;
            cnt=0;
        }
        if(cnt > max)
        max = cnt;
    }
    cout<<max;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	ll n = s.size();
	ll ans1=0, ans2=0;
	rep(i, n){
		if (i % 2 == 0){
			if (s[i] == '0') ans1++;
		}else{
			if (s[i] == '1') ans1++;
		}
	}
	rep(i, n){
		if (i % 2 == 1){
			if (s[i] == '0') ans2++;
		}else{
			if (s[i] == '1') ans2++;
		}
	}
	cout << min(ans1, ans2) << "\n";
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int N;
	cin >> N ;
	set <int>d;
	rep(i, N) {
		int a;
		cin >> a;
		d.insert(a);
	}
	int ans = 0;
	for (auto itr = d.begin(); itr != d.end(); ++itr) {
		ans++;
	}
	print(ans);
}

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

using namespace std;

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

#define int ll

main(){
	int n;
	ll a,b;

	cin >> n;

	ll ans = 1e10;
	for(int i=0;i<n;i++){
		cin >> a >> b;
		ans = min(a+b,ans);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3576