akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    static int N;
    static int D;
    static int[][] x;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        D = scanner.nextInt();

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

        scanner.close();

        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

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

lmax = 1
rmin = N
for _ in range(M):
  l, r = map(int, input().split())
  lmax = max(lmax, l)
  rmin = min(rmin, r)
  
print(rmin - lmax + 1 if rmin - lmax + 1 > 0 else 0)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
long long MaxDivisor(long long a, long long b);
long long MinMultiple(long long a, long long b);
int main()
{
	long long m, n;
	while (cin >> m >> n) {
		cout << MaxDivisor(m, n) << " " 
			<< MinMultiple(m, n) << endl;
	}

	//system("pause");
	return 0;
}
///??相除法求最大公?数
long long MaxDivisor(long long a, long long b) {
	long long temp, r;
	if (a < b) {
		temp = a;
		a = b;
		b = temp;
	}
	r = a % b;
	while (0 != r) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
long long MinMultiple(long long a, long long b) {
	return (a * b / MaxDivisor(a, b));
}

Measured memory_bytes: 3056
n=input()
if n<10:
	print n
	quit(0)
if str(n)[1:].count('9')==len(str(n)[1:]):
	print sum([ord(ch)-ord('0') for ch in str(n)])
else:
	print ord(str(n)[0])-ord('0')-1+9*len(str(n)[1:])


Measured memory_bytes: 2568
// Author : MohamedSameh
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<deque>
#include <sstream>
#include <string.h>

typedef long long ll ;
// random in each run --> srand(time(NULL));

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
#define debug(x) cout<<#x<<" = { "<<x<<" }\n"
void fo (){fflush(stdout);}
using namespace std;
int n , m , M = 1e9+7;
string x[1000];
int dp[1000][1000];
ll sol (int i , int j )
{
  if (i >= n || j >= m || i < 0 || j < 0 || x[i][j] == '#')return 0 ;
  if (i == n-1 && j == m-1)return 1 ;
  int &ret = dp[i][j];
  if (~ret)return ret ;
  ret = 0 ;
  return ret = (ret + sol(i+1 , j)%M + sol (i , j+1 )%M)%M ;
}
int main ()
{
memset (dp , -1 ,sizeof dp );
scanf ("%d%d" , &n ,&m );
for (int i =0 ; i < n ;i++)cin >> x[i];
printf ("%lld\n" ,sol (0,0)%M );
  return 0;
}


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

#define ll long long
#define ar array

const int mxN=2e5, M=998244353;
int n;
ar<int, 2> a[mxN];
ll dp[mxN+1];

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

	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> a[i][0] >> a[i][1];
	sort(a, a+n);
	dp[n]=1;
	vector<ar<int, 2>> st{{n, (int)2e9}};
	for(int i=n-1; ~i; --i) {
		//int p=lower_bound(a, a+n, ar<int, 2>{a[i][0]+a[i][1], 0})-a;
		//dp[i]=dp[p];
		while(st.back()[1]<a[i][0]+a[i][1])
			st.pop_back();
		int p=st.back()[0];
		dp[i]=dp[p];
		st.push_back({i, a[i][0]});
		//cout << i << " " << p << endl;
		dp[i]=(dp[i]+dp[i+1])%M;
	}
	cout << dp[0];
}


Measured memory_bytes: 4340
using System;

class main{
    public static void Main(String[] args){
        int n = int.Parse(Console.ReadLine());
        int[] ary = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);

        int cnt = bubbleSort(ary,n);

        for(int i = 0;i < ary.Length;i++){
            if(i != ary.Length - 1){
                Console.Write(ary[i] + " ");
            }else{
                Console.WriteLine(ary[i]);
            }
        }

        Console.WriteLine(cnt);
    }

    internal static int bubbleSort(int[] a,int n){
        bool flag = true;
        int cnt = 0;

        while(flag){
            flag = false;

            for(int j = n - 1;j > 0;j--){
                if(a[j] < a[j - 1]){
                    int temp = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = temp;
                    flag = true;
                    cnt++;
                }
            }
        }

        return cnt;
    }
}

Measured memory_bytes: 9160
import java.util.Scanner;

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

		int count = z;
		int ans = 0;
		for(int i = 0; x >= count + y + z; i++){
			count += y + z;
			ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits>

using namespace std;

using ll = unsigned long long;

//M*max(C)+1 (最長の最短経路)
const ll inf = (ll)(300*299/2)*1000000000+1;

int main(void){
    int N, M, L, Q;

    cin >> N >> M >> L;

    vector<vector<ll>> dist(N, vector<ll>(N, inf));

    for(int i=0; i<N; i++){
        dist[i][i] = 0;
    }
    for(int q=0; q<M; q++){
        int a, b, c;
        cin >> a >> b >> c;

        dist[a-1][b-1] = dist[b-1][a-1] = c;
    }

    //ワーシャルフロイド法
    for(int k=0; k<N; k++){
        for(int i=0; i<N; i++){
            for(int j=0; j<N; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    
    vector<vector<ll>> fcnt(N, vector<ll>(N, inf));
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(dist[i][j] <= L)
                fcnt[i][j] = 1;
        }
    }

    //ワーシャルフロイド法
    for(int k=0; k<N; k++){
        for(int i=0; i<N; i++){
            for(int j=0; j<N; j++){
                fcnt[i][j] = min(fcnt[i][j], fcnt[i][k] + fcnt[k][j]);
            }
        }
    }

    cin >> Q;
    for(int q=0; q<Q; q++){
        int s, t;
        cin >> s >> t;

        int ans = fcnt[s-1][t-1]-1;
        if(fcnt[s-1][t-1] == inf)
            ans = -1;

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1920
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())
#define REP(i, n) for(int i = 0; i < n; i++)
const int MOD = 1e9+7;
typedef long long ll;

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    int ma=max({2*a-b-c,2*b-a-c,2*c-a-b});
    if(ma%2) cout<<ma/2+2<<endl;
    else cout<<ma/2<<endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[10010];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>a[i];
		n-=a[i];
	}
	if(n<0)
	{
		cout<<-1;
		return 0;
	}
	cout<<n;
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	string s;
	cin >> s;
	int N=s.size();
	int K;
	cin >> K;
	set<string> ans;
	rep(i,N){
		rep(j,K){
			if(i+j<N) ans.insert(s.substr(i,j+1));
		}
	}
	auto itr=ans.begin();
	rep(i,K-1) itr++;
	cout << *itr << endl;

	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
using namespace std;
int aa[1000][1000]={};
int main()
{
    int  i=0,j=0,n=0,a=0,b=0,c=0,d=0;
    while(1){
        cin >>a>>b;
        if(a==0&&b==0)break;
        cin >> n;
        for(i=0;i<a;i++){
            for(j=0;j<b;j++){
                aa[i+1][j+1]=1;
            }
        }
        for(i=0;i<n;i++){
            cin >> c >> d;
            aa[c][d]=0;
        }
        
        for(i=1;i<a+1;i++){
            for(j=1;j<b+1;j++){
                if(aa[i][j]>0 ){
                    aa[i][j]=aa[i-1][j]+aa[i][j-1];
                    if(i==1&&j==1)aa[i][j]=1;
                }
            }
        }

        cout << aa[a][b] << endl;
    }

}

Measured memory_bytes: 1220
/* 

	 - If you fail to prepare, you are prepared to fail.	

	(C) Mark Spitz

*/

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;

const bool dbg_flg = 1;
#define NAME(x) #x
#define debug if (dbg_flg) cerr

const int inf = 1e9 + 7;
const int MAXN = 1e5 + 5;

int n;
ll a;
map<ll, ll> ct;
ll res;

void solve() {
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> a;

		res += ct[i - a];

		ct[i + a]++;
	}

	cout << res;
}

int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 26292
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
typedef long long ll;
using namespace std;
int n;
ll gcd(ll x,ll y){
	if (x%y==0) return y; else return gcd(y,x%y);
}
int main(){
	cin>>n;
	ll a,b,c;
	for (ll i=1;i<=3500;i++){
		for (ll j=i;j<=3500;j++){
			ll g=gcd(gcd(i,j),n);
			g=i*j*n/g;
			a=4*(g/n);
			b=g/i;
			c=g/j;
			if (a-(b+c)>0){
				ll d=a-(b+c);
				if (g%d==0){
					cout<<i<<' '<<j<<' '<<g/d;
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 256
import java.util.*;

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

    Scanner sc = new Scanner(System.in);
    while(true){
      int H = sc.nextInt();
      int W = sc.nextInt();
      if(H==0&&W==0)  break;
      for(int i=0;i<H;i++){
        System.out.print("#");
        for(int j=1;j<W-1;j++){
          if(i==0||i==H-1) System.out.print("#");
          else             System.out.print(".");
        }
        System.out.print("#");
        System.out.print("\n");
      }
      System.out.print("\n");
    }
  }
}



Measured memory_bytes: 37332
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.at(0) == '7' || s.at(1) == '7' || s.at(2) == '7') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>


#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back 
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define mod2 998244353
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 1000000000000

// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int n,m,t,i,l,k,r,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U;
    // int x,y,a,b,c;
    cin>>n>>m>>k;
  set<int> a;
 a.insert(n);
  a.insert(m);
  a.insert(k);
  if(sz(a)==2) cout<<"Yes";
  else cout<<"No";
}


signed main()
{

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    int T=0;
    while(t--)
    {
        T++;
        // if(T>1) cout<<"\n";
        // cout<<"Case #"<<T<<": ";
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <set>

using namespace std;

set<int> s;

int main(){
    int N;
    cin >> N;
    int a;
    for(int i=0;i<N;i++){
        cin >> a;
        if(s.find(a)==s.end()){
            s.insert(a);
        }else{
            s.erase(a);
        }
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const bool debug = 0;
//---------------------------------//

ll mod_pow(ll x, ll n, ll mod = MOD) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	
	return res;
}

int N, A[112345];
ll sum[112345];

int main() {
	cin >> N;
	REP(i, N) scanf("%lld", A + i);
	
	FOR(i, 1, N + 1) sum[i] = (sum[i - 1] + mod_pow(i, MOD - 2, MOD)) % MOD;
	
	ll ans = 0;
	REP(i, N) {
		ll pat = 1;
		pat += sum[i + 1] - sum[1];
		pat += sum[N - i] - sum[1];
		pat %= MOD;
		
		(ans += pat * A[i] % MOD) %= MOD;
	}
	
	FOR(i, 1, N + 1) ans = ans * i % MOD;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1408
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 10010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

LL T,n,m,i,j,k,g,x,y,z,Ans,cnt,sum,res,Sum;
LL a[N],b[N],c[N],d[N*4],s[N];
bool v[N];

vector <LL> l[N];

IL LL Abs(LL x){return (x<0)?-x:x;}
IL void Swap(LL &a,LL &b){a^=b^=a^=b;}
IL LL Min(LL a,LL b){return (a<b)?a:b;}
IL LL Max(LL a,LL b){return (a>b)?a:b;}

IL LL Mi(LL x,LL y){
	LL p=x,t=1,Res=1;
	for (;t<=y;(t&y)?Res=(Res*p)%MOD:0,p=(p*p)%MOD,t<<=1);
	return Res;
}

IL LL read(){
	LL p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

IL void Dfs(int x){
	if (v[x])	return;
	c[cnt]+=b[x];	v[x]=1;
	l[cnt].push_back(b[x]);	Dfs(a[x]);
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();	k=read();
	for (i=1;i<=n;i++)	a[i]=read();
	for (i=1;i<=n;i++)	b[i]=read();
	for (i=1;i<=n;i++){
		if (!v[i])	++cnt,Dfs(i);
	}
/*	cout<<cnt<<endl;
	for (i=1;i<=cnt;i++)	cout<<c[i]<<endl;
	cout<<"---------"<<endl;
*/
	Ans=-INF;	sum=0;
	for (i=1;i<=cnt;i++){
		sum=0;
		for (j=0;j<l[i].size();j++)
			d[j+1]=d[j+1+l[i].size()]=l[i][j];
		s[0]=0;
		for (j=1;j<=l[i].size()*2;j++)	s[j]=s[j-1]+d[j];
		
		if (c[i]>0){
			sum=k/(l[i].size())*c[i];
			res=k%l[i].size();
			Sum=-INF;
			for (j=1;j<=l[i].size();j++)
				for (g=j;g<j+l[i].size();g++){
					if (g-j+1>res)	break;
					Sum=Max(Sum,s[g]-s[j-1]);
				}
			if (Sum!=-INF)	sum+=Sum;
			Ans=Max(Ans,sum);
			//total

			if (k>=l[i].size()){
				sum=((k-l[i].size())/l[i].size())*c[i];
				Sum=-INF;
				res=l[i].size();
				for (j=1;j<=l[i].size();j++)
					for (g=j;g<j+l[i].size();g++){
						if (g-j+1>res)	break;
						Sum=Max(Sum,s[g]-s[j-1]);
					}
				if (Sum!=-INF)	sum+=Sum;
				Ans=Max(Ans,sum);
			}
		}	else {
			res=l[i].size();
			Sum=-INF;
			for (j=1;j<=l[i].size();j++)
				for (g=j;g<j+l[i].size();g++){
					if (g-j+1>res)	break;
					Sum=Max(Sum,s[g]-s[j-1]);
				}
			Ans=Max(Ans,Sum);
		}
		//cout<<Ans<<endl;
	}
	cout<<Ans<<endl;
	return 0;
}

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


int main()
{
    int a,b;
    cin>>a>>b;
    if(a>0)
        cout<<"Positive";
    else if(a==0||(a<0&&b>0))
        cout<<"Zero";
    else if((abs(b)-abs(a))%2!=0)
        cout<<"Positive";
    else
        cout<<"Negative";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int N;
	cin >> N;
	int ans;
	for (int x = 111; x <= 999; x += 111) {
		if (N == x) {
			ans = x;
			break;
		}
		if (N < x) {
			ans = x;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, K;
string S;
signed main() {
    cin >> N >> K >> S;
    S[K - 1] += 'a' - 'A';
    cout << S << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (A, B): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let compute_factorizations = |X| {
        let mut res = std::collections::HashSet::new();
        let mut x = X;
        res.insert(1);
        for i in 2..1_000_000 {
            if x % i == 0 {
                res.insert(i);
                while x % i == 0 {
                    x /= i;
                }
            }
        }
        if x > 1 {
            res.insert(x);
        }
        res
    };

    let P = compute_factorizations(A);
    let Q = compute_factorizations(B);
    let R = P.intersection(&Q);
    let ans = R.count();

    println!("{}", ans);
}


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

ll solve() {
    ll N, C, K;
    cin >> N >> C >> K;
    vector<ll> T(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> T[i];
    }
    sort(T.begin(), T.end());
    ll ans = 1, n = 0, t = T[0];
    for ( int i = 0; i < N; i++ ) {
        if ( n >= C || T[i] > t + K) {
            ans++;
            t = T[i];
            n = 0;
        }
        n++;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int x,y,p;
	
	while(1){
		scanf("%d %d",&x,&y);
		if(x == 0 && y == 0) break;
		if(x>y){
			p = x;
			x = y;
			y = p;
		}
		printf("%d %d\n",x,y);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<cmath>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int read(){
	int f=1,x=0;
	char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return f*x;
}
#define MAXN 200000
#define INF 0x3f3f3f3f
int n,m;
struct node{
	int v,w;
	node(){}
	node(int V,int W){v=V,w=W;}
};
LL Min=1,Max=INF;
int vis[MAXN+5],dis[MAXN+5];
vector<node> G[MAXN+5];
void DFS(int u,int f,int x,int fa){
	if(x<=0){
		if(!f) Min=max(Min,(-x+2)*1ll);
		else printf("0\n"),exit(0);
	}
	if(f) Max=min(Max,x*1ll);
 	dis[u]=x,vis[u]=f+1;
	int siz=G[u].size();
	for(int i=0;i<siz;i++){
		int v=G[u][i].v,w=G[u][i].w;
		if(v==fa) continue;
		if(vis[v]){
			if(vis[u]==vis[v]){
				if(((dis[u]+dis[v])%2+4)%2!=w%2)
					printf("0\n"),exit(0);
				if(vis[v]==1)
					Min=max(Min,(1+(w-(dis[u]+dis[v]))/2)*1ll),
					Max=min(Max,(1+(w-(dis[u]+dis[v]))/2)*1ll);
				else 
					Min=max(Min,(1+((dis[u]+dis[v])-w)/2)*1ll),
					Max=min(Max,(1+((dis[u]+dis[v])-w)/2)*1ll);
				if(Min!=Max)
					printf("0\n"),exit(0);
			}
			else//vis[u]=0
				if(dis[u]+dis[v]!=w)
						printf("0\n"),exit(0);
			continue;
		}
		DFS(v,(f+1)%2,w-dis[u],u);
	}
	return ;
}
int main(){
	//freopen("graph.in ","r",stdin);
	n=read(),m=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read(),w=read();
		G[u].push_back(node(v,w));
		G[v].push_back(node(u,w));
	}
	dis[1]=1,DFS(1,0,1,0);
	if(Min>Max)
		printf("0\n");
	else printf("%lld\n",Max-Min+1);
	return 0;
}


Measured memory_bytes: 17280
n,m=map(int,input().split())
a=0
if m!=0:
    a=int(input())
    
b=1
s=[1]*(n+1)
for i in range(1,n+1):
    if i!=a:
        if i-2>=0:
            s[i]=(s[i-1]+s[i-2])%1000000007
        else:
            s[i]=s[i-1]%1000000007
    elif b!=m:
        s[i]=0
        a=int(input())
        b+=1
    else:
        s[i]=0
print(s[n])
        


Measured memory_bytes: 6900
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++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(obj) (obj).begin(), (obj).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 uni(x) x.erase(unique(rng(x)),x.end())
#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) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
const int MX = 200005;
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------

void Main(){
  ll x,y;
  cin>>x>>y;
  int ans=0;
  ll a = x;
  while(a<=y){
    ans++;
    a*=2;
  }
  cout<<ans<<endl;
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


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

    
    string s;
    cin>>s;
    int n = s.size();
    int ans = n;
    for(int i=1;i<n;i++){
        if(s[i] != s[i-1]){
            chmin(ans, max(i,n-i));
        }
    }
    cout << ans << endl;

}

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

int main() {
    int n;
    cin >> n;
    int c = 0;
    int x = 0;
    for(int i=0; i<n; ++i) {
        int a;
        cin >> a;
        if(a%2!=0) c++;
        if(a%4==0) x++;
    }
    if(c==0) cout << "Yes" << endl;
    else {
        if(x>=c) cout << "Yes" << endl;
        else if(n%2!=0&&x+1>=c) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	int n,k;
	cin>>n>>k;
	vi v(n);
	REP(i,0,n-1)cin>>v[i];
	sort(v.begin(),v.end());
	int sum=0;
	REP(i,0,k-1){
		sum+=v[i];
	}
	cout<<sum;
	return 0;

//   TimeTaken();
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define int long long
typedef std::pair<int,int> P;
using namespace std;
struct edge{
    int to,cost;
};
class dijkstra{
    int V;
    int d[100002];
    priority_queue<P,vector<P>,greater<P>>que;
    void update(int s,vector<edge> G[]){
        fill(d,d+V+1,LLONG_MAX);
        d[s]=0;
        que.push(make_pair(0,s));
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            rep(i,G[v].size()){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(make_pair(d[e.to],e.to));
                }
            }
        }
    }
public:
    dijkstra(int v,int s,vector<edge> G[]){
        V=v;
        update(s,G);
    }
    int find(int e){
        return d[e];
;    }
};
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
  int n,m,s,t;
  const int yen=(int)1e15;
  vector<edge> ag[100002],bg[100002];
  cin>>n>>m>>s>>t;
  rep(i,m){
    int u,v,a,b;
    cin>>u>>v>>a>>b;
    ag[u].push_back({v,a});
    ag[v].push_back({u,a});
    bg[u].push_back({v,b});
    bg[v].push_back({u,b});
  }
  dijkstra ad(n,s,ag),bd(n,t,bg);
  vector<int> ans(n);
  fill(ans.begin(),ans.end(),0);
  ans[n-1]=yen-ad.find(n)-bd.find(n);
  rep(i,n-1){
    ans[n-2-i]=max(ans[n-1-i],yen-ad.find(n-i-1)-bd.find(n-i-1));
  }
  rep(i,n)cout<<ans[i]<<endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define F first
#define S second
#define int long long

const int maxn = 5e5+10;
const ll inf = 1e18+10;
const int mod = 998244353;

int n, m, k;
vector<pair<int,int>> edge;

void add(int u, int v)
{
    edge.push_back({u,v});
}

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

    string s;
    cin>> s; n = s.size();
    s = "*" + s;

    vector<int> a;
    for(int i = 1; i < n; i++)
    {
        if(s[i] != s[n-i])
            return cout<< -1 <<"\n", 0;
        if(s[i] == '1')
            a.push_back(i);
    }
    if(s[n] == '1' || s[1] == '0')
        return cout<< -1 <<"\n", 0;

    int nd = 1;
    for(int i = 1; i < a[0]; i++)
        nd++, add(nd,1);

    int lst = 1;
    for(int i = 1; i < a.size(); i++)
    {
        nd++;
        int X = nd;
        for(int j = 1; j < a[i]-a[i-1]; j++)
            nd++, add(nd,X);
        add(X,lst);
        lst = X;
    }
    nd++;
    add(nd,lst);

    for(auto e : edge)
        cout<< e.F <<" "<< e.S <<"\n";
}



Measured memory_bytes: 3936
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
const int p=1e9+7;
int xx,yy,n,be[5100],et,siz[5100];
struct edg{
	int y,ne;
};
edg e[11000];
long long f[5100][5100],g[5100],tmp[5100],ans;
inline void add_edge(int x,int y){
	e[++et].y=y;
	e[et].ne=be[x];
	be[x]=et;
}
void dfs(int x,int fa){
	siz[x]=1;f[x][1]=1;//f[x][0]=-1;
	for(int i=be[x];i;i=e[i].ne){
		if (e[i].y==fa) continue;
		dfs(e[i].y,x);
		fo(j,1,siz[x]){
			tmp[j]=f[x][j];
			f[x][j]=0;
		}
		fo(j,1,siz[x])
			fo(k,0,siz[e[i].y]){
				f[x][j+k]+=tmp[j]*f[e[i].y][k]%p;
			}
		siz[x]+=siz[e[i].y];
		fo(j,1,siz[x]) f[x][j]%=p;
	}
	fo(j,1,siz[x]) f[x][0]-=f[x][j]*g[j]%p;
	f[x][0]%=p;//!!!!
}
int main(){
	scanf("%d",&n);
	fo(i,2,n){
		scanf("%d%d",&xx,&yy);
		add_edge(xx,yy);
		add_edge(yy,xx);
	}
	g[0]=1;
	for(int i=2;i<=n;i+=2) g[i]=g[i-2]*(i-1)%p;
	dfs(1,-1);
	printf("%lld\n",(-f[1][0]%p+p)%p);
	return 0;
}

Measured memory_bytes: 200576
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {

            
            var read = Console.ReadLine();
            read = Console.ReadLine();
            var temp_string = read.Split(' ');
            int min = 1000000,max = -1000000;
            long total = 0;


            foreach(string a in temp_string)
            {
                int temp=int.Parse(a);
                if(temp>max)
                {
                    max = temp;
                }
                if(temp<min)
                {
                    min = temp;
                }

                total += temp;
            }
            Console.WriteLine(min + " " + max + " " + total);
        }
    }
}

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)

typedef long long ll;
typedef long double ld;
const ll inf = (ll)1e14;
const ll N = (ll)1e6;

ll arr[6];
ld ret;
ll sol,sugar;

int main() {
    fast;
    for (int i = 0; i < 6; i++) cin >> arr[i];

    arr[0] = 100 * arr[0];
    arr[1] = 100 * arr[1];

    for (ll i = 0; i * arr[0] <= arr[5]; i++) {

        for (ll j = 0; i * arr[0] + j * arr[1] <= arr[5]; j++) {

            ll water = i * arr[0] + j * arr[1];

            for (ll p = 0; p * arr[2] * 100 <= arr[4] * water and (p * arr[2] + water) <= arr[5]; p++) {

                for (ll q = 0; (p * arr[2] + q * arr[3]) * 100 <= arr[4] * water and
                               (p * arr[2] + q * arr[3] + water) <= arr[5]; q++) {

                    ll sug = p * arr[2] + q * arr[3];

                    if (ret < ld(sug) * 100 / (water + sug)) {
                        ret = ld(sug) * 100 / (water + sug);
                        sol = water + sug;
                        sugar = sug;
                    }

                }

            }
        }
    }

//    cout << ret << endl;
    if (!sol) sol = arr[0];
    cout << sol << " " << sugar << endl;
    return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : (^o^).cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int a,b,t,m;
    t=0;
    m=0;
    while(1)
    {
    cin>>a>>b;
    if(a==0&&b==0){
    	return 0;
    	}while(1){
    while (1){
    	cout<<"#";
    	m++;
    	if(m==b){
    		cout<<endl;
    		m=0;
    		break;
    		}
    	cout<<".";
    	m++;
    	if(m==b){
    		cout<<endl;
    		m=0;
    		break;
    	}
    			}t++;
    			if(t==a){
    				m=0;t=0;
    				break;
    			}
    			while (1){
    			    	cout<<".";
    			    	m++;
    			    	if(m==b){
    			    		cout<<endl;
    			    		m=0;
    			    		break;
    			    		}
    			    	cout<<"#";
    			    	m++;
    			    	if(m==b){
    			    		cout<<endl;
    			    		m=0;
    			    		break;
    			    	}
    			    			}t++;if(t==a){
    			    				m=0;t=0;
    			    				break;
    			    			}

    	}cout<<endl;}
	return 0;
}



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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	vector<int> cnt(13, 0);
	cnt[0]++;
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		cnt[a]++;
	}

	bool flg=false;
	if(cnt[0]>=2 || cnt[12]>=2) flg=true;
	for(int i=1; i<12; i++){
		if(cnt[i]>=3) flg=true;
	}
	if(flg){
		cout << 0 << endl;
		return 0;
	}

	int ans=0;
	for(int i=0; i<(1<<11); i++){
		vector<int> v;
		v.push_back(0);
		if(cnt[12]==1){
			v.push_back(12);
		}

		for(int j=1; j<12; j++){
			if(cnt[j]==0) continue;
			if(cnt[j]==2){
				v.push_back(j);
				v.push_back(-j);
			}else{
				if((i>>(j-1))%2==0) v.push_back(-j);
				else v.push_back(j);
			}
		}
		sort(v.begin(), v.end());

		int m=99;
		for(int j=0; j<v.size()-1; j++){
			for(int k=j+1; k<v.size(); k++){
				if(v[j]>0 || v[k]<0){
					m=min(m, v[k]-v[j]);
				}else{
					m=min(m, min(v[k]-v[j], 24-(v[k]-v[j])));
				}
			}
		}
		ans=max(ans, m);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];

    vector<int> dp(n + 1, INT32_MAX);

    rep(i, n)
    {
        auto in = lower_bound(dp.begin(), dp.end(), a[i]);
        in[0] = a[i];
    }

    int ans = 0;
    while (dp[ans] != INT32_MAX)
    {
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3564
import math
N = int(input())
lim = int(math.sqrt(N))
ans = 9999
for i in range(1,lim+1):
    if N % i == 0:
        temp = N //i
        cand = max(len(str(i)),len(str(temp)))
        if ans > cand:
            ans = cand


print(ans)

Measured memory_bytes: 3060
n = gets.chomp.to_i
hash = {}
chars = ['M', 'A', 'R', 'C', 'H']
chars.each {|c| hash[c] = 0 }
n.times.each do
  s = gets.chomp
  c = s.chars.first
  if hash.key?(c)
    hash[c] += 1
  end
end


count = 0
0.upto(31).each do |x|
  bit = x.to_s(2).rjust(5, '0')
  next if bit.count('1') != 3
  tmp = 1
  bit.chars.each.with_index(0) do |c, i|
    next if c != '1'
    index_char = chars[i]
    tmp *= hash[index_char]
  end
  count += tmp
end
puts count


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int mod = 1e9 + 7, N = 2010;
typedef long long ll;
ll n, K, f[N][N], fac[N * N], inv[N * N];

ll quick_pow(ll a, ll b) {
	ll ret = 1;
	for (; b; b >>= 1) {
		if (b & 1) ret = ret * a % mod;
		a = a * a % mod;
	} return ret;
}

ll C(ll n, ll m) {
	if (!m) return 1;
	return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int main() {
	cin >> n >> K;
	
	if (K == 1) {
		puts("1"); return 0;
	}
	
	fac[0] = inv[0] = 1;
	rep(i, 1, n * K) fac[i] = fac[i - 1] * i % mod;
	inv[n * K] = quick_pow(fac[n * K], mod - 2);
	for (int i = n * K; i >= 1; i--) inv[i - 1] = inv[i] * i % mod;
	
	f[0][0] = 1;
	rep(i, 1, n) {
		rep(j, 0, i) {
			f[i][j] = f[i - 1][j];
			if (j)
				f[i][j] = (f[i][j] + f[i][j - 1] * (n - j + 1) % mod * C(n * K - i - (j - 1) * (K - 1) - 1, K - 2) % mod) % mod;
		}
	}
	printf("%lld\n", f[n][n]);
	return 0;
}


Measured memory_bytes: 94848
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

k = int(readline())
a, b = map(int, read().split())

flg = 0
i = 0

while i < 2000:
    if a <= k*i and b >= k*i:
        flg = 1
        break
    i += 1

if flg == 1:
    print("OK")
else:
    print("NG")


Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
const int MN = 500500;
vl zf(string st) {
	vl z(st.size(),0);
	ll l = 0,r = 0,i = 1;
	for(;i<st.size();i++) {
		if(i <= r) {
			z[i] = min(z[i-l],r-i+1);
		}
		while((i+z[i] < st.size()) && st[i+z[i]] == st[z[i]]) {z[i]++;}
		if(i+z[i]-1 > r) {
			r = i+z[i]-1;
			l = i;
		}
	}
	return z;
}
char conc[MN*6];
string mt,mtc;
int main() {
	ios::sync_with_stdio(0);
	string s,t;
	cin >> s >> t;
	vl ts = zf(t);
	ll m = t.size();
	ll cm = m;
	for(int i=1;i<ts.size();i++) {
		if(ts[i] == 0) continue;
		if((m%i)) continue;
		if(i+ts[i] == m) {
			t = t.substr(0,i);
			break;
		}
	}
	m = t.size();
	memset(conc,0,sizeof(conc));
	for(int i=0;i<m;i+=s.size()) {
		for(int j=0;j<s.size();j++) {
			conc[i+j] = s[j];
		}
	}
	s = string(conc);
	memset(conc,0,sizeof(conc));
	for(int i=0;i<6*MN-1;i++) {
		conc[i] = t[i%m];
	}
	mt = string(conc);
	mtc = mt+"$"+s+s+s;
	ll n = s.size();
	vl res = zf(mtc);
	ll ma = 0;
	for(int i=mt.size();i<res.size();i++) {
		ma = max(ma,res[i]);
	}
	if(ma >= 2*s.size()) {
		cout << -1 << '\n';
		return 0;
	}
	cout << (ma/cm) << '\n';
}


Measured memory_bytes: 70584
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
    ll H, W, N;
    cin >> H >> W >> N;
    vector<P> v;
    map<P, int> m;
    int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
        dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
    for(int i=0; i<N; ++i) {
        ll a, b;
        cin >> a >> b;
        m[make_pair(a, b)] = 1;
        if(1 < a && a < H && 1 < b && b < W) {
            v.push_back(make_pair(a, b));
        }
        for(int j=0; j<8; ++j) {
            ll ny = a + dy[j], nx = b + dx[j];
            if(1 < ny && ny < H && 1 < nx && nx < W) {
                v.push_back(make_pair(ny, nx));
            }
        }
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    vector<ll> res(10);
    for(auto& p : v) {
        int cnt = 0;
        for(int i=-1; i<=1; ++i) {
            for(int j=-1; j<=1; ++j) {
                auto p2 = make_pair(p.first + i, p.second + j);
                if(m.count(p2)) {
                    cnt++;
                }
            }
        }
        res[cnt]++;
    }
    res[0] = (H-2) * (W-2);
    for(int i=1; i<10; ++i) {
        res[0] -= res[i];
    }
    for(int i=0; i<10; ++i) {
        cout << res[i] << endl;
    }
}


Measured memory_bytes: 22372
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	int a[100];
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a, a + n);
	//cout << (1.0/(4.0*m)) * sum << endl;
	if (a[n - m] >= (1.0 /( 4.0 * m)) * sum) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<string>
#include<queue>
#include<tuple>
#include<utility>
#include<functional>
#include<algorithm>

#define LL long long

using namespace std;

int n;
map<string,int>cnt;
vector<pair<int,string>>_cnt;

int main() {
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		cnt[s]--;
	}
	for(auto itr=cnt.begin();itr!=cnt.end();itr++)
		_cnt.push_back({itr->second,itr->first});
	sort(_cnt.begin(),_cnt.end());
	int tmp=_cnt[0].first;
	for(int i=0;i<_cnt.size();i++){
		if(_cnt[i].first==tmp)cout<<_cnt[i].second<<endl;
		else break;
	}
	return 0;
}

/*
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<queue>
#include<tuple>
#include<utility>
#include<functional>
#include<algorithm>

#define LL long long

using namespace std;

int n,a[111];
bool d=true;

int main() {
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2==0)
			d&=(a[i]%3==0||a[i]%5==0);
	}
	cout<<(d?"APPROVED":"DENIED")<<endl;
	return 0;
}

*/

Measured memory_bytes: 29044
//code by lynmsakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

int n;
int x[110],y[110],h[110];
int H;
int main(void){
	scanf("%d",&n);
	for(int i = 0;i < n;i++){
		scanf("%d%d%d",&x[i],&y[i],&h[i]);
	}
	
	int cx,cy;
	for(int i = 0;i <= 100;i++)for(int j = 0;j <= 100;j++){
		cx = i,cy = j;
		for(int k = 0;k < n;k++){
			if(h[k] > 0){
				H = h[k] + abs(cx - x[k]) + abs(cy - y[k]);
				break;
			}
		}
		bool check = true;
		for(int k = 0;k < n;k++){
			if(h[k] != max(0,H - abs(cx - x[k]) - abs(cy - y[k]))){
				check = false;
				break;
			}
		}
		if(check){
			printf("%d %d %d\n",cx,cy,H);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

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

vector<int> a;
vector<P> v;
int n, m;
int main()
{
    cin >> n >> m;
    a = vector<int>(n);
    REP(i, n) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    v = vector<P>(m);
    REP(i, m) {
        int b, c;
        cin >> b >> c;
        v[i] = make_pair(c, b);
    }

    sort(v.begin(), v.end(), greater<P>());
    int k = 0;
    REP(i, n) {
        int c = v[k].first;
        // DDD(a[i], c, v[k].second);
        if (a[i] >= c) break;
        a[i] = c;
        v[k].second--;
        if (v[k].second == 0) k++;
        if (k == m) break;
    }
    // DA(a, n);
    ll ans = 0;
    REP(i, n) {
        ans += a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using i64 = long long;

long long *fact, *inv;

template <typename T, typename U, typename V>
constexpr auto pow(T x_, U n_, V mod_) {
    std::common_type_t<T, U, V> ret = 1, x = x_, n = n_, mod = mod_;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <typename T, typename U>
constexpr auto inverse(T x, U p) { return pow(x, p - 2, p); }

void init_factorial(int n, long long mod) {
    fact = new long long[n + 1];
    inv = new long long[n + 1];
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

int main() {
    constexpr i64 mod = 998244353;
    i64 n;
    std::cin >> n;
    i64 m = n / 2;
    init_factorial(m + 1, mod);

    i64 t = 0, ret = 0;
    for (int i = 1; i <= m; i++) {
        t = (t + fact[m] * inv[i - 1] % mod * inv[m - i + 1] % mod * pow(2, i - 1, mod) % mod) % mod;
        ret = (ret + fact[m] * inv[i] % mod * inv[m - i] % mod * pow(2, m - i, mod) % mod * t % mod) % mod;
    }

    ret = (pow(3, n, mod) + mod - ret * 2 % mod) % mod;

    std::cout << ret << std::endl;

    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

// 最大公約数 : 3,4 ->  1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


void solve()
{
  int a, b, k;
  cin >> a >> b >> k;

  int cd = gcd(a, b);
  for(int i = cd; i >= 0; --i)
  {
    if (cd % i == 0) k--;
    if (k == 0)
    {
      cout << i;
      break;
    }
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3532