akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	ll N, D, A;
	ll ans = 0;
	cin >> N >> D >> A;
	pairs(X);
	fx(N) {
		pairsp(X);
	}

	sorts(X);
	vector<pair<int, ll>> Z;
	ll sum = 0;
	int index = 0;
	fx(N) {
		while(Z.size()>index&&Z[index].first < X[x].first) {
			sum -= Z[index].second;
			index++;
		}
		if (sum>=X[x].second) {
			continue;
		}
		ll count= (X[x].second-sum + A - 1) / A;
		ans += count;
		pb(Z, make_pair(min((int)X[N-1].first, (int)(X[x].first + 2 * D)), count * A));
		sum += count * A;
	}
	ce(ans)
    return 0;
}



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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define vi vector<int>

#define ll long long int

int ctoi(char c) {return c-'0';}
int ord(char c) {return c-'a';}
int len(string s) {return s.length();}
int itoc(int i) {return i+'a';}


int main() {
string x,s,t;
map<string,int> mapa;
cin>>s>>t;
cin>>mapa[s]>>mapa[t]>>x;
mapa[x]--;
cout<<mapa[s]<<" "<<mapa[t]<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"


void solve()
{
    int n;cin>>n;string s;cin>>s;
    string ans="";
    for(char c:s)
    {
        int d=c-'A';
        d+=n;
        d=d%26;
        // if(d==0)
        // d=26;
        ans+=(char)('A'+d);
        
    }
    cout<<ans<<endl;
    
}
int32_t main()
{
    rapido;
    int t;
    //cin>>t;
      t=1;
    while(t--)
    solve();
}


//NOPQRSTUVWXYZABCDEFGHIJKLM
//NOPQRSTUVWXYZZBCDEFGHIJKLM

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;
const int inf=1001001001;

int main(){
    int h,w;
    int ans=0;
    cin>>h>>w;
    char maze[h][w];
    for (int i=0;i<h;i++){
        for (int j=0;j<w;j++){
            cin>>maze[i][j];
            if (maze[i][j]=='.') ans++;
        }
    }
    //cout<<ans<<endl;
    ans--;
    
    int dx[4]={0,1,0,-1};
    int dy[4]={1,0,-1,0};
    
    vector<vector<int>> dp(h,vector<int>(w,inf));
    dp[0][0]=0;
    queue<pair<int,int>> q;
    q.push(make_pair(0,0));
    while (q.size()){
        int x,y;
        x=q.front().first;  //xがhと対応
        y=q.front().second;q.pop();
        rep(i,4){
            if (x+dx[i]<0 || h<=x+dx[i]) continue;
            if (y+dy[i]<0 || w<=y+dy[i]) continue;
            if (maze[x+dx[i]][y+dy[i]]=='#') continue;
            
            if (dp[x+dx[i]][y+dy[i]]==inf) q.push(make_pair(x+dx[i],y+dy[i]));
            dp[x+dx[i]][y+dy[i]]=min(dp[x][y]+1,dp[x+dx[i]][y+dy[i]]);
            
        }
    }
    
	if (dp[h-1][w-1]==inf) {
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans-dp[h-1][w-1]<<endl;
    
    
    return 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<dp[i][j]<<',';
        }
        cout<<endl;
    }
}


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

using namespace std;

typedef long long ll;

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

	int train = n*a;
	int taxi = b;

	int ans = min(train,taxi);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 764
using System;

namespace ABC_056_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            string a = (word[0]);
            string b = (word[1]);
            if (a == "H" && b == "H" || a == "D" && b == "D")
            {
                Console.WriteLine("H");
            }
            else if (a == "D" || b == "D")
            {
                Console.WriteLine("D");
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
using namespace std;
int N;
int A[100000];

int n;

long long ans;

int main() {
    scanf("%d", &N);
    for(int i=0; i<N;i++){
        scanf("%d", &A[i]);
    }
    sort(A, A+N);

    if(A[0]>=0){
        /*A[0]だけマイナス、あとはプラス */
        n = 0;
    }else if(A[N-1]<=0){
        /*A[N-1]だけプラス、あとはマイナス */
        n = N-2;
    }else{
        /*A[i]がプラスならプラス、あとはマイナス */
        for(int i=0;i<N;i++){
            if(A[i]>0){
                n = i-1;
                break;
            }
        }
    }
    long long ans;
    ans = 0;
    for(int i=0;i<N;i++){
        if(i <= n){
            ans -= A[i];
        }else{
            ans += A[i];
        }
    }
    printf("%lld\n", ans);

    long long sb = A[0];
    for(int i = n+2; i<N;i++){
        printf("%lld %d\n", sb, A[i]);
        sb -= A[i];
    }
    long long sb2 = A[n+1];
    printf("%lld %lld\n", sb2, sb);
    sb2 -= sb;

    for(int i=1;i<=n;i++){
        printf("%lld %d\n", sb2, A[i]);
        sb2 -= A[i];
    }

}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define LL long long
#define maxn 100010 
using namespace std;
LL seg[maxn],a,b,d,n;
bool ok(int k){
	int ans=0;
	for(int i=n;i>=1&&seg[i]>(LL)k*b;i--){
		ans+=((seg[i]-k*b-1)/d+1);
		if(ans>k) return false;
	}
	if(ans<=k) return true;
	return false;
}
int main(){
	cin>>n>>a>>b;
	d=a-b;
	for(int i=1;i<=n;i++) scanf("%lld",&seg[i]);
	sort(seg+1,seg+1+n);
	int l=0,r=1002000009LL,mid,res;
	while(l<=r){
		mid=(l+r)>>1;
		if(ok(mid)){
			res=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1024
/*
Educational DP Contest - K - Stones
https://atcoder.jp/contests/dp/tasks/dp_k
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)


void solve() {

}

int main()
{
    FAST_INP;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    // #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	int n, k;
	cin >> n >> k;
	vi a(n);
	READ(a);
	// dp[i]=0: first player wins;
	// dp[i]=1: second player wins
	vi dp(k+1,0); 
	FORN(i,1,k){
		EACH(x,a){
			if(i>=x&&!dp[i-x]){
				dp[i]=1;
			}
		}
	}
	OUT((dp[k]?"First":"Second"));
    return 0;
}


Measured memory_bytes: 3712
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define inf int(1e9)
#define half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int mod = 1000000007;

int main() {
    string n;
    cin >> n;
    int ans = 0;
    rep(i, n.length()) if (n[i] == '2') ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define endl "\n"
#ifdef LOCAL
#define lout cerr
#else
ostream devnull(0);
#define lout devnull
#endif
#define AMULET \
  cin.tie(0);  \
  ios::sync_with_stdio(false);
// https://github.com/kurokoji/.cpp-Template/blob/master/template/template2.cpp
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...)                                 \
  GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1) \
  (__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, d) rep5(i, a, n, d, <)
#define rep5(i, a, n, d, o) for (auto i = decltype(n)(a), _n = (n); i o _n; i += (d))

#define rrep(...)                                    \
  GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1) \
  (__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, -1)
#define rrep4(i, a, n, d) rep5(i, (a)-1, n, d, >=)

#define dump(x) lout << #x << " = " << x << endl;
// alias
typedef long long ll;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
// func
template <class C>
inline void vcin(C &c);
template <class C, class D>
inline void vcin(C &c, D &d);
template <class C>
inline void vcout(const C &c, const string separate = "\n");
template <class T = int>
inline T in();

int dp[105][10005];

void solve()
{
  int n, W;
  cin >> n >> W;

  vector<int> value(n), weight(n);
  vcin(value, weight);

  rep(w, W+1)
      dp[0][w] = 0;

  rep(i, n)
      rep(w, W+1)
  {
    if (w >= weight[i])
      dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w]);
    else
      dp[i + 1][w] = dp[i][w];
  }

  cout << dp[n][W] << endl;
}

signed main()
{
  AMULET
  solve();
  return 0;
}

template <class C>
inline void vcin(C &c)
{
  for (auto &a : c)
  {
    cin >> a;
  }
}
template <class C, class D>
inline void vcin(C &c, D &d)
{
  for (auto it1 = c.begin(), it2 = d.begin(); it1 != c.end() && it2 != d.end(); it1++, it2++)
  {
    cin >> *it1 >> *it2;
  }
}
template <class C>
inline void vcout(const C &c, const string separate)
{
  for (auto it = c.begin(); it != c.end(); it++)
  {
    if (it != c.begin())
      cout << separate;
    cout << *it;
  }
}
template <class T = int>
inline T in()
{
  T x;
  cin >> x;
  return (x);
}



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

const int inf = 1 << 30;

int dist[100010][10];

int main() {
  int K;
  cin >> K;
  for (int m = 0; m < K; m++) {
    for (int t = 0; t < 10; t++) {
      dist[m][t] = inf;
    }
  }
  deque<pair<int, int>> deq;
  deq.emplace_back(1, 1);
  dist[1][1] = 1;
  while (!deq.empty()) {
    auto v = deq.front(); deq.pop_front();
    int m = v.first, t = v.second;
    int d = dist[m][t];
    {
      int mm = (m * 10) % K, tt = 0;
      int dd = d;  
      if (dd < dist[mm][tt]) {
        dist[mm][tt] = dd;
        deq.emplace_front(mm ,tt);
      }
    }
    if (t < 9) {
      int mm = (m + 1) % K, tt = t + 1;
      int dd = d + 1;
      if (dd < dist[mm][tt]) {
        dist[mm][tt] = dd;
        deq.emplace_back(mm, tt);
      }
    }
  }
  int res = inf;
  for (int t = 0; t < 10; t++) {
    res = min(res, dist[0][t]);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4992
/* ex6_1.12
   tamayama */

#include<stdio.h>
#define SIZE 100

int main(void){
    char str1[SIZE];    /*文字列の配列を用意*/
    int i;
    int count=0;
    char first;
    char last;

    for(i=0;i<SIZE;i++){    /*ヌル文字を挿入*/
        str1[i] = '\0';
    }

    scanf("%s",str1);    /*入力された文字数をカウントする*/
    for(i=0;i<SIZE;i++){
        if(str1[i] != '\0'){
            count++;
        }
    }
    first = str1[0];    /*最初の文字*/
    last = str1[count-1];    /*最後の文字*/
    printf("%c%d%c\n",first,count-2,last);    /*真ん中の文字数は、（全体の文字数）-2*/
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <algorithm>
#include <utility>
using namespace std;
int main() {
	string S, T; 
	cin >> S >> T; 
	int M, N; 
	int count = 0; 
	M = S.size(), N = T.size(); 
	if(M < N){cout << "UNRESTORABLE" << endl;}
	else{for(int i = M-N; i >= 0; i--){
		bool restore = true; 
		for(int j = i; j < i + N; j++){
			if(S.at(j) != '?' && S.at(j) != T.at(j-i)){
				restore = false; 
				break; 
			}
		}
		if(restore){
			S = S.substr(0, i) + T + S.substr(i + N); 
			count ++; 
			break; 
		}
    }
	if(count == 0){cout << "UNRESTORABLE" << endl;}
	else{for(int i = 0; i < M; i++){
		if(S.at(i) == '?'){S.at(i) = 'a';}	
	}
	cout << S << endl; 
	}
    }
}

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

int main() {
  int n,d;
  cin>>n>>d;
  vector<vector<int>> vec(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>vec.at(i).at(j);
    }
  }
  
  int count=0,a=0,c;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      for(int k=0;k<d;k++){
        a+=(vec.at(i).at(k)-vec.at(j).at(k))*(vec.at(i).at(k)-vec.at(j).at(k));
      }
      //cout<<a<<endl;
      for(int i=0;i<7000;i++){
        if(i*i==a){
          count++;
        }
      }
      a=0;
    }
  }
  cout<<count<<endl;
}

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

pair<int, int> team[1000000];
//team[i].firstはかかった時間[s]
//team[i].secondはチーム番号

int main()
{
	int n;
	int m, s;
	while (cin >> n)
	{
		if (n == 0)
		{
			return 0;
		}

		for (int i = 0; i < n; i++)
		{
			team[i].first = 0;
			cin >> team[i].second;
			for (int j = 0; j < 4; j++)
			{
				cin >> m >> s;
				team[i].first += m * 60 + s;
			}
		}

		sort(team, team + n);
		cout << team[0].second << endl;
		cout << team[1].second << endl;
		cout << team[n - 2].second << endl;
	}
}

Measured memory_bytes: 8976
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
        long [] ans = new long [a+1];
        if(b>0){int [] in = new int [b];
        for(int i=0;i<b;i++){
                             in[i] = sc.nextInt();
                            }
		int c = 0;
        long mod = 1000000007;
        ans [0] = 1;
        if(in[c]==1){c++;}
        else{ans[1]=1;}
        for(int i=2;i<=a;i++){if(c<b && in[c]==i){c++;}
                              else{ans[i]=(ans[i-1]+ans[i-2])%mod;}
                             }       
		System.out.println(ans[a]);}
        else{long mod = 1000000007;
        ans [0] = 1;
        ans [1] = 1;
        for(int i=2;i<=a;i++){
                              ans[i]=(ans[i-1]+ans[i-2])%mod;
                             }       
		System.out.println(ans[a]);}
	}
}

Measured memory_bytes: 49068
#include<cstdio>
#define MAX 100000
int A[MAX],n;
int partition(int p,int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
    t=A[i];
  t=A[i+1];
  A[i+1]=A[r];
  A[j]=t;
  return i+1;
}

int main(){
  int i,q;
  scanf("%d", &n);
  q=partition(0,n-1);
  for(i=0;i<n;i++)scanf("%d", &A[i]);

  q=partition(0,n-1);
  
  for(i=0;i<n;i++){
    if(i==0)printf("%d", A[i]);
    else if(i==q){
      printf(" [");
      printf("%d", A[i]);
    }
    else printf(" %d", A[i]);
    if(i==q)printf("]");
  }
  printf("\n");
  return 0;
}

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

int main(){
    char c;
    //cout << "Please input a letter you like." << endl;
    cin >> c;
    string vowel = "aiueo";
    if(vowel.find(c) != string::npos)
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

map<LL,int> prime_factor(LL n){
  map<LL,int> ret;
  for(LL i = 2; i * i <= n; i++){
    while(n % i == 0){
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}


auto GCD(auto a,auto b){ //ユークリッドの互助法で最大公約数
    if (a%b == 0){
        return b;
    }
    else {
        return GCD(b,a%b);
    }
}

int main(){
   LL A,B;cin >> A >> B;
   auto Alist = prime_factor(A);
   auto Blist = prime_factor(B);
   map<LL,int> gcdlist;
   for(auto itr = Alist.begin() ; itr != Alist.end() ;itr++){
       if(Blist.count(itr -> F)){
           int tmpa = itr -> S;
           int tmpb = Blist[itr -> F];
           gcdlist[itr -> F] = min(tmpa,tmpb);
       }
   }
   gcdlist[1] = 1;
   // ここまでで公約数リスト完成

   cout << gcdlist.size() << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const int INF = 1 << 30;


template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

mint com(long long n, long long r) {
mint res = 1;
for (long long i = 0; i < r; ++i) {
res *= (n-i);
res /= (i+1);
}
return res;
}

map< int, int > prime_factor(int n) {
  map< int, int > ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}


int main() 
{
    int n,m;
    cin >> n >> m;

    mint res = 1;
    map<int,int> mp = prime_factor(m);
    for(auto [x,c] : mp) res *= com(c+n-1,c);

    cout << res << endl;
    return 0;
}

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

long long int f(int i, int j, vector<vector<bool>>& vis,
     vector<vector<long long int>>& dp, vector<int>& a)
{
  auto& ret = dp[i][j];
  if (vis[i][j])
    return ret;
  if (i == j)
    return a[i];
  vis[i][j] = true;

    return ret = max(a[i] - f(i + 1, j, vis, dp, a), a[j] - f(i, j - 1,  vis, dp,a));
}



int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  vector<vector<bool>> vis(n, vector<bool>(n));
  vector<vector<long long int>> dp(n, vector<long long int>(n));
  cout << f (0, n-1, vis, dp, a) << '\n';

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  string str1, str2;
  cin >> str1 >> str2;
  string res = "";
  for(int i=0; i<n; i++){
    res += str1[i];
    res += str2[i];
  }
  cout << res << endl;
  return 0;
}

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

struct d{
	char M[101];
	int p;
	int r;
	int rk[101];
};
d t[101];
int v[101];

int func(int n){
	int c=t[n].rk[0];
	int a=0;
	v[n]=1;
	if(t[n].rk[0]==0){
		return t[n].p;
	}
	for(int i=1;i<=c;i++){
		if(v[t[n].rk[i]]==1){
			a+=t[t[n].rk[i]].p;
		}
		else if(t[t[n].rk[i]].r==0){
			a+=t[t[n].rk[i]].p;
		}
		else {
			a+=func(t[n].rk[i]);
		}
	}
	if(a<t[n].p)
		t[n].p=a;
	
	return t[n].p;
}
			

int main(void){
	int n,i,j,l;
	while(scanf("%d",&n),n){
		
		int m,k,V;
		char T[101];
		for(i=0;i<n;i++){
			scanf("%s %d",t[i].M,&t[i].p);
		}
		scanf("%d",&m);
		for(i=0;i<m;i++){
			
			scanf("%s",T);
			for(j=0;j<n;j++){
				if(!(strcmp(t[j].M,T))){
					t[j].r=1;
					break;
				}
			}
			V=j;
			scanf("%d",&k);
			t[V].rk[0]=k;
			for(j=0;j<k;j++){
				scanf("%s",T);
				for(l=0;l<n;l++){
					if(!(strcmp(t[l].M,T))){
						t[V].rk[j+1]=l;
						break;
					}
				}
			}
		}
		scanf("%s",T);
		for(i=0;i<n;i++){
			if(!(strcmp(t[i].M,T))){
				break;
			}
		}
		printf("%d\n",func(i));
		
		for(i=0;i<101;i++){
			v[i]=0;
			t[i].r=0;
			t[i].p=0;
		}
	}
}

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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') ch = getchar(), f = -1;
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> void out(Tp x) {
	if (x > 9) out(x / 10);
	putchar(x % 10 + '0');
	return;
}

template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}

const int MAXN = 100010;

int n;
int A[MAXN];

int main()
{
	in(n);
	FOR(i, 1, n) in(A[i]);

	LL L = 2, R = 2;

	DNF(i, n, 1) {
		if (R / A[i] - (L - 1) / A[i] <= 0) {
			puts("-1");
			return 0;
		}
		L = (L / A[i] + (L % A[i] != 0)) * A[i];
		R = (R / A[i] + 1) * A[i] - 1;
	}

	printf("%lld %lld\n", L, R);
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

const ll mod = 1e9 + 7;

ll N;
vector<ll> A;

int main()
{
    cin >> N;
    A.resize(N + 5);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    ll ans = 0;
    ll sum = 0;
    for (int i = 0; i < N - 1; i++)
    {
        sum = (sum + A[i]) % mod;
        ans += ((sum * A[i + 1]) % mod);
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
}

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

int n, mx, i, t, s, ans;
int main()
{
	cin >> n;
	for (i =1; i <= n; i++) {
			scanf("%d",&t);
			if (t == i) s++;
			else {
					if (s > 0) ans += (s + 1) / 2;
					s = 0;
			}
	}
					if (s > 0) ans += (s + 1) / 2;
	cout << ans;
    return 0;
}


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

int main(){

    int n;
    char str[12];
    cin >> n;
    sprintf(str, "%d", n);
    if (str[0] == str[strlen(str) -1]) cout << "Yes"  << endl;
    else cout << "No"  << endl;


    return 0;
}

Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
  string S;
  cin >> S;
  if(S == "Sunny") printf("Cloudy\n");
  if(S == "Cloudy") printf("Rainy\n");
  if(S == "Rainy") printf("Sunny\n");
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int count;

	scanf("%d",&count);

	long long ans = 0;
	for(int i = 1;i <= count;i++){
		if(!(i % 3) && !(i % 5)){
			//FizzBuzz;
		}
		else if(!(i % 3) || !(i % 5)){
			;
		}
		else{
			ans += i;
		}

	}


	printf("%lld\n",ans);
}

/*
1000000
*/


Measured memory_bytes: 1728
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <string>

using namespace std;

int hpi,hpm;
int r,c;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int fie[101][101];
int t;
int td[31];
int s;
int move[1001];
int p;
int pr[20];
int dp[1005][1<<13];

int main(void){
	while(1){
		scanf("%d%d",&hpi,&hpm);
		if(hpi+hpm==0)break;
		scanf("%d%d",&r,&c);
		for(int i=0;i<r;i++){
			string str;
			cin >> str;
			for(int j=0;j<c;j++){
				fie[i][j]=str[j]-'A';
			}
		}
		scanf("%d%*c",&t);
		for(int i=0;i<t;i++){
			char type;
			int dam;
			scanf("%c%d%*c",&type,&dam);
			td[type-'A']=dam;
		}
		scanf("%d%*c",&s);
		int all=0;
		for(int i=0;i<s;i++){
			char d;
			int dir,a;
			scanf("%c%d%*c",&d,&a);
			if(d=='U')dir=3;
			if(d=='D')dir=1;
			if(d=='R')dir=0;
			if(d=='L')dir=2;
			for(int j=0;j<a;j++){
				move[all++]=dir;
			}
		}
		scanf("%d",&p);
		for(int i=0;i<p;i++){
			scanf("%d",&pr[i]);
		}
		memset(dp,0,sizeof(dp));
		dp[0][0]=hpi;
		int x=0,y=0;
		int dall=0;
		for(int i=0;i<all;i++){
			x+=dx[move[i]];
			y+=dy[move[i]];
			int dam=td[fie[y][x]];
			dall+=dam;
			for(int j=0;j<(1<<p);j++){
				if(dp[i][j]>0){
					dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
					for(int k=0;k<p;k++){
						if(j>>k & 1)continue;
						dp[i][j|(1<<k)]=max(dp[i][j|(1<<k)],min(hpm,dp[i][j]+pr[k]));
					}
				}
			}
			for(int j=0;j<(1<<p);j++){
				dp[i+1][j]-=dam;
			}
		}
		bool flag=false;
		for(int j=0;j<(1<<p);j++){
			if(dp[all][j]>0)flag=true;
		}
		printf("%s\n",flag?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 33424
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> listX = new ArrayList<Integer>();
		List<Integer> listY = new ArrayList<Integer>();
		for(;;){
			int x = scan.nextInt();
			int y = scan.nextInt();
			if((x == 0) && (y == 0)){
				break;
			}
			if(x > y){
				int work = x;
				x = y;
				y = work;
			}
			listX.add(x);
			listY.add(y);
		}

		for(int i = 0; i < listX.size(); i++){
			System.out.printf("%d %d\n", listX.get(i), listY.get(i));
		}
	}
}

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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define endl "\n"

int main()
{
	faster;
	
	string n;
	map<char,int> cnt;
	cin >> n;
	for(int i = 0; i < n.size(); i++){
		cnt[n[i]]++;
	}
	
	bool flag = true;
	for(auto i: cnt) if(i.second % 2 != 0) flag = false;
	
	cout << (flag ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 3648
def gcd(x,y):
    if x<y:
        x,y = y,x
    while y>0:
        x,y = y,x%y
    return x
INFTY = 10**6
P = [1 for i in range(INFTY+1)]
P[0] = 0
P[1] = 0
for i in range(2,int((INFTY+1)**0.5)+1):
    for j in range(i*i,INFTY+1,i):
        P[j] = 0
Q = []
for i in range(INFTY):
    if P[i]==1:
        Q.append(i)
A,B = map(int,input().split())
x = gcd(A,B)
cnt = 1
for y in Q:
    if x%y==0:
        cnt += 1
        while x%y==0:
            x = x//y
if x>1:
    cnt += 1
print(cnt)

Measured memory_bytes: 14076
n = int(input())
A = list(map(int, input().split()))
a_max = max(A)


def find_nearest(arr, target):
    m = min(arr)
    dist = abs(m-target)
    for a in arr:
        if abs(a-target) < dist:
            dist = abs(a - target)
            m = a
            # print(m, dist)
    return m


print(a_max, find_nearest(A, a_max/2))


Measured memory_bytes: 14428
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;
    a--;
    b--;
    c--;
    d--;
    auto check = [&s](int x, int y, int len, string str) {
        REP(i, x, y) {
            if (s.substr(i, len) == str) return false;
        }
        return true;
    };
    if (c == d or !check(a, c, 2, "##") or !check(b, d, 2, "##")) {
        cout << "No" << endl;
    } else {
        if (c < d) {
            cout << "Yes" << endl;
        } else {
            if (!check(b - 1, d, 3, "...")) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }
    }

    return 0;
}


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

int main() {
  // エラトステネスのふるい
  int MAX = 101010;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (int i = 2; i < MAX; i++) {
    if (!is_prime[i]) continue;
    for (int j = i * 2; j < MAX; j += i)
      is_prime[j] = 0;
  }

  vector<int> a(MAX, 0);
  for (int i = 0; i < MAX; i++) {
    if (i % 2 == 0) continue;
    if (is_prime[i] && is_prime[(i + 1) / 2]) a[i] = 1;
  }

  vector<int> s(MAX + 1, 0);
  for (int i = 0; i < MAX; i++)
    s[i + 1] = s[i] + a[i];

  int Q;
  cin >> Q;

  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    r++;

    cout << s[r] - s[l] << endl;
  }
}

Measured memory_bytes: 1792
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord

--import qualified Data.IntSet as S
import qualified Data.Sequence as S

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)

main :: IO ()
main = do
    n <- readLn :: IO Int
    as <- r' :: IO [Int]
    bs <- r' :: IO [Int]
    print $ solve as bs 0

solve :: [Int] -> [Int] -> Int -> Int
solve _ [] ac = ac
solve (a:a':as) (b:bs) ac = if a < b then
    let monstInNext = max 0 (a'-(b-a))
        defInNext = a' - monstInNext
    in solve (monstInNext:as) bs (ac+a+defInNext)
    else solve (a':as) bs (ac+b)


Measured memory_bytes: 5628
import java.io.*;
class Main {
    public static void main(String argv[]) {
        try{
	int x;
        BufferedReader d =new BufferedReader(new InputStreamReader(System.in));
	x= Integer.parseInt(d.readLine());
        System.out.println(x=x*x*x);
	}catch(IOException e){}
    }
}

Measured memory_bytes: 24360
N,M = map(int,input().split(" "))
h_list = list(map(int,input().split(" ")))
road = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split(" "))
    road[a-1].append(b-1)
    road[b-1].append(a-1)
good_obs = [0 for i in range(N)]
for i in range(N):
    if len(road[i]) == 0:
        good_obs[i] = 1
    else:
        h_max = 0
        for j in road[i]:
            h_max = max(h_max,h_list[j])
        if h_max < h_list[i]:
            good_obs[i] = 1
print(good_obs.count(1))


Measured memory_bytes: 97776
str=list(input())
N=int(input())
for i in range(N):
    order=list(input().split())
    x=int(order[1])
    y=int(order[2])
    z=len(str)
    if order[0]=='replace':
        str[x:y+1]=order[3]
    elif order[0]=='reverse':
        strage=str[::-1]
        str[x:y+1]=strage[z-1-y:z-x]
    else:
        printstr=''.join(str[x:y+1])
        print(printstr)



Measured memory_bytes: 5628
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,A,B;
  cin >> A >> B;
  if(A % 3 == 0 || B % 3 == 0 || (A+B)%3==0)
    cout << "Possible" <<  endl;
  else
    cout << "Impossible" <<  endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,p,tmp,j=0;
  cin >> N >> M;
  vector<int> num(N,-1);
  for(int i=0;i<M;i++) {
    cin >> p >> tmp;
    if(num.at(p-1)==-1||num.at(p-1)==tmp) {
      num.at(p-1)=tmp;
    } else{
      j--;
    }
  }  
  if(N!=1&&num.at(0)==0||j<0){
    cout << -1 << endl;
  } else {
    for(int i=0;i<N;i++) {
      if(N!=1&&i==0&&num.at(i)==-1) cout << 1;
      else if(num.at(i)==-1) cout << 0;
      else cout << num.at(i);
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
using System;

namespace ITP1
{
    class ITP1_3_C
    {
        static void Main(string[] args)
        {
            int i=0;
            int[][] input = new int[1000000][];

            
            while (true)
            {

                input[i] = new int[2];
                string[] suchi = Console.ReadLine().Split(' ');
                input[i][0] = int.Parse(suchi[0]);
                input[i][1] = int.Parse(suchi[1]);
                 if (input[i][0] == 0 & input[i][1] == 0) break;
                i++;
                
            }
            for (int t = 0; t < i ; t++)
            {
                if (input[t][0] > input[t][1])
                {
                    Console.WriteLine(input[t][1]+" "+ input[t][0]);
                }
                else
                {
                    Console.WriteLine(input[t][0] + " " + input[t][1]);
                }

            }
        }
    }
}

Measured memory_bytes: 17664
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int i;
	cin>>s;
	bool flag=false;
	for(i=0;i<s.length();i++){
		if(s[i]=='C'){
			flag=true;
		}
		if(s[i]=='F'&&flag==true){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define w 1000000007

long min(long a,long b){
	return a < b ?  a : b;
}

long fact(long k){
	long res = 1;
	while(k > 1){
		res = (res * k) % w;
		k--;
	}
	return res;
}

int main(){
	long m,n;
	cin >> m >> n;
	long k = min(m,n);
	long res = fact(k);
	if(m == n){
		cout <<  res * res * 2 % w << endl;
	}else if(abs(m-n)==1){
		res = res * res % w;
		res = res * (k+1) % w;
		cout << res << endl;
	}else{
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
import std.stdio;
import std.bigint;
import std.conv;
import std.string;

string[] c;
bool isNumber[][];
BigInt dp[][];

void main()
{
  int w,h;
  string[] input;
  while(true){
    input=readln.split;
    w=input[0].to!int;
    h=input[1].to!int;
    if((w|h)==0)break;
    c=new string[h];
    isNumber=new bool[][h];
    dp=new BigInt[][h];
    for(int i=0;i<h;i++){
      c[i]=readln;
      isNumber[i]=new bool[w];
      dp[i]=new BigInt[w];
      for(int j=0;j<w;j++)
	isNumber[i][j]=('0'<=c[i][j]&&c[i][j]<='9');
    }
    dp[0][0]=isNumber[0][0]?c[0][0]-'0':0;
    BigInt max=dp[0][0];
    for(int i=1;i<h;i++){
      if(!isNumber[i][0]){
	dp[i][0]=0;
	continue;
      }
      dp[i][0]=dp[i-1][0]*10+(c[i][0]-'0');
      max=dp[i][0]>max?dp[i][0]:max;
    }
    for(int j=1;j<w;j++){
      if(!isNumber[0][j]){
	dp[0][j]=0;
	continue;
      }
      dp[0][j]=dp[0][j-1]*10+(c[0][j]-'0');
      max=dp[0][j]>max?dp[0][j]:max;
    }
    for(int i=1;i<h;i++){
      for(int j=1;j<w;j++){
	if(!isNumber[i][j]){
	  dp[i][j]=0;
	  continue;
	}
	BigInt localmax=dp[i-1][j]>dp[i][j-1]?dp[i-1][j]:dp[i][j-1];
	dp[i][j]=localmax*10+(c[i][j]-'0');
	max=dp[i][j]>max?dp[i][j]:max;
      }
    }

    writeln(max);
  }
}

Measured memory_bytes: 3156
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val k = nextInt()

    var score = 1
    repeat(n) {
        if (score * 2 < score + k) {
            score *= 2
        } else {
            score += k
        }
    }

    println(score)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33648
#include<iostream>
#include<functional>
#include<iomanip>
#include<algorithm>
#include<vector>

using namespace std;
using ll = long long;

#define rep(i,n) for(int i = 0; i <(n); ++i)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}

int main(){
  int n; cin >> n;
  double ans = 0.0;
  rep(i,n){
    double in; string d;
    cin >> in >> d;
    if(d == "JPY")
      ans += in;
    else
      ans += in* 380000.0;
  }
  cout << fixed << setprecision(10) << ans << endl;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

double T, X;

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    std::cin >> T >> X;
    
    double t = T / X;
    printf("%.10f\n", t);
}


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

int main(void){
    int x[11000];
    for(int i = 0;i<10000;i++){
        cin >> x[i];
        if(x[i] == 0){
            continue;
        }
        
        cout << "Case " << i+1 << ": " << x[i] << endl;;
    }
}



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


def solve(N: int, A: int, B: int, X: "List[int]"):
    ans = 0

    for i in range(N-1):
        ans += min(abs(X[i+1]-X[i])*A, B)

    print(ans)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 15384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	d := make(map[int]int)
	for i := 0; i < n; i++ {
		d[intScanner()]++
	}
	m := intScanner()
	f := true
	for i := 0; i < m; i++ {
		x := intScanner()
		d[x]--
		if d[x] < 0 {
			f = false
		}
	}
	if f {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

public class P
{
    public string via { get; set; }
    public string via2 { get; set; }
}

public class hello
{
    public static void Main()
    {
        var d = new Dictionary<char, int>()
        { { 'R', 1 }, { 'r', -1 }, { 'G', 2 }, { 'g', -2 }, { 'B', 3 }, { 'b', -3 }, { 'W', 4 }, { 'w', -4 } };
        var n = int.Parse(Console.ReadLine().Trim());
        var z = 0;
        while (z++ < n)
        {
            var ps = new int[9, 4, 4];
            string[] line = Console.ReadLine().Trim().Split(' ');
            for (int i = 0; i < 9; i++)
            {
                var t = line[i];
                for (int j = 0; j < 4; j++) ps[i, 0, j] = d[t[j]];
            }
            getPs(ps);
            getAns(ps);
        }
    }
    static void getAns(int[,,] ps)
    {
        var ans = 0;
        var st = new Stack<P>();
        for (int i = 0; i < 9; i++)
            for (int j = 0; j < 4; j++)
                st.Push(new P { via = i.ToString(), via2 = j.ToString() });
        while (st.Count() > 0)
        {
            var w = st.Pop();
            if (w.via.Length == 9) { ans++; continue; }
            for (int i = 0; i < 9; i++)
            {
                if (!w.via.Contains(i.ToString()))
                {
                    for (int j = 0; j < 4; j++)
                        if (check(ps, w.via, w.via2, i, j))
                            st.Push(new P { via = w.via + i.ToString(), via2 = w.via2 + j.ToString() });
                }
            }
        }
        Console.WriteLine(ans);
    }
    static bool check(int[,,] ps, string via, string via2, int i, int j)
    {
        var vL = via.Length;
        if (vL == 1 | vL == 2)
        {
            var t = ps[via[vL - 1] - '0', via2[vL - 1] - '0', 1];
            return ps[i, j, 3] + t == 0;
        }
        else if (vL == 3 | vL == 6)
        {
            var t = ps[via[vL - 3] - '0', via2[vL - 3] - '0', 2];
            return ps[i, j, 0] + t == 0;
        }
        else
        {
            var t = ps[via[vL - 3] - '0', via2[vL - 3] - '0', 2];
            var t2 = ps[via[vL - 1] - '0', via2[vL - 1] - '0', 1];
            return (ps[i, j, 0] + t == 0) && (ps[i, j, 3] + t2 == 0);
        }
    }
    static void getPs(int[,,] ps)
    {
        for (int i = 0; i < 9; i++)
        {
            ps[i, 1, 0] = ps[i, 0, 3];
            ps[i, 1, 1] = ps[i, 0, 0];
            ps[i, 1, 2] = ps[i, 0, 1];
            ps[i, 1, 3] = ps[i, 0, 2];

            ps[i, 2, 0] = ps[i, 0, 2];
            ps[i, 2, 1] = ps[i, 0, 3];
            ps[i, 2, 2] = ps[i, 0, 0];
            ps[i, 2, 3] = ps[i, 0, 1];

            ps[i, 3, 0] = ps[i, 0, 1];
            ps[i, 3, 1] = ps[i, 0, 2];
            ps[i, 3, 2] = ps[i, 0, 3];
            ps[i, 3, 3] = ps[i, 0, 0];
        }
    }
}


Measured memory_bytes: 20792
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<(int)(n);i++)
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int n=int(s.size());
  rep(i,0,2*n){
    s=s[n-1]+s.substr(0,n-1);
    if(s==t){
      cout<<"Yes"<<endl;
        return 0;
    }
  }
  cout<<"No"<<endl;
}
  

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

int main() {
  int N, K, ubound = 1, dbound = 0, cutnum = 0, center;
  long double A[200000] = {};
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    cin >> A[i];
    if (ubound < A[i]) ubound = A[i];
  }
  while(ubound != dbound + 1){
    cutnum = 0;
    center = (ubound+dbound)/2;
    for (int j = 0; j < N; j++){
      cutnum += ceil(A[j]/center)-1;
    }
    if(cutnum > K) dbound = center;
    else ubound = center;
  }
  cout << ubound << endl;
  return 0;
}

Measured memory_bytes: 6852