akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, s, g) for(int i = s; i < g; i++)
#define FORR(i, s, g) for(int i = s - 1; i >= g; i--)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define DMP(a) std::cerr << "[Debug] : " << #a << " = " << a << "\n"
using namespace std;
typedef long long ll;
struct aaa{
    aaa(){
        std::cin.tie(0); std::ios::sync_with_stdio(0); std::cout<<std::fixed<<std::setprecision(20);
    };
}aaaaaaa;

bool cmp(const pair<pair<string, int>, int> &a, const pair<pair<string, int>, int> &b)
{
    if(a.first.first != b.first.first) return a.first.first < b.first.first;
    else return a.first.second > b.first.second;
}

int main() {
    int n;
    cin >> n;
    vector<pair<pair<string, int>, int>> v(n);
    REP(i, n) {
        cin >> v[i].first.first >> v[i].first.second;
        v[i].second = i + 1;

    }
    sort(ALL(v), cmp);
    REP(i, n) cout << v[i].second << "\n";

    return 0;
}


Measured memory_bytes: 256
A[1000][1000],I[1000],u[999];i,j;d;F=2;main(N){for(scanf("%d",&N);i<N;++i)for(j=0;~j+N;)scanf("%d",A[j++]+i);for(;F&2;i=N)for(d+=F=1;i--;u[i]<d&&j&&u[F&=2,--j]<d&A[I[j]][j]==i+1&&++I[u[i]=u[j]=d,++I[i],F=2,j])j=A[I[i]][i];printf("%d",F*d-1);}

Measured memory_bytes: 4096
#include <iostream>
#include<cmath>
#include<iomanip>

using namespace std;

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

    if(N==1)
    {
        cout<<showpoint<<fixed <<setprecision(10);
        cout<<(float)N<<endl;
    }
    else if(N%2!=0)
    {
        cout<<fixed<<showpoint <<setprecision(10);
        cout<<(double) ((N/2)+1)/N<<endl;
    }
    else
    {
        cout<<showpoint<<fixed <<setprecision(10);
        cout<<(double)(N/2)/N<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int s[n];
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>s[i];
    sum+=s[i];
  }
  int flag=0;
  if(sum%10!=0)
    cout<<sum<<endl;
  else{
    int sum2=sum;
    int max=0;
    for(int i=0;i<n;i++){
      if((sum2-s[i])>max&&(sum2-s[i])%10!=0)
	max=sum2-s[i];
    }
    cout<<max<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys

fin = sys.stdin.readline
N = [int(elem) for elem in fin().split()][0]
a_list = [int(elem) for elem in fin().split()]
b_list = [int(elem) for elem in fin().split()]


all_sum = 0
prev_b = 0

for i in range(len(a_list[:-1])):
    # 前の残りを引き算する
    current_a = a_list[i]
    prev_num = min(current_a, prev_b)
    current_a -= prev_num
    current_b = b_list[i]

    # 引き算する数
    current_num = min(current_a, current_b)
    # 残り
    prev_b = current_b - current_num
    # 総和
    all_sum += current_num + prev_num

all_sum += min(a_list[-1], prev_b)
print(all_sum)


Measured memory_bytes: 73316
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define SORT(v) sort(v.begin(),v.end())
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
#define REVS(v) reverse(v.begin(),v.end())
#define PI 3.14159265359
using namespace std;
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  int n,a,b,ans;
  IN3(n,a,b);
  ans = min(a*n,b);
  OUT(ans);
}

Measured memory_bytes: 256
// Why am I so dumb? :ca
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const double PI = acos(-1.0);
const int INF = (int)1e9;

vector<pair<int, int>> arr;

int ax, ay, bx, by;

double ans;

int n;

double best(vector<pair<int, int>> vv) {
	vector<int> dp(vv.size() + 1, INF);
	dp[0] = -INF;
                 
    for (int i = 0; i < vv.size(); ++i) {
    	int p = upper_bound(all(dp), vv[i].se) - dp.begin();

    	if (dp[p - 1] < vv[i].se && vv[i].se < dp[p]) {
    		dp[p] = vv[i].se;
    	}
    }

    int cnt = 1;

    while (cnt <= vv.size() && dp[cnt] != INF) {
    	++cnt;
    } 

	return (cnt - 1) * (20.0 - 5.0 * PI);
}

double calc(vector<pair<int, int>> vv) {
	if (vv.empty()) {
		return 0.0;
	}	

	double ret = -INF;

	for (int step = 0; step < 2; ++step) {
		sort(all(vv));
		int cnt = 1;

		for (int i = 1; i < vv.size(); ++i) {
			cnt += (vv[i].se > vv[i - 1].se);
		}

		if (cnt == bx - ax + 1) {
			return (20.0 - 5.0 * PI) * (bx - ax) + (20.0 - 10.0 * PI);
		}

		ret = max(ret, best(vv));

		for (pair<int, int> &x : vv) {
			swap(x.fi, x.se);
		}

		swap(ax, ay);
		swap(bx, by);
	}

	return ret;
}

void solve() {                   
	scanf("%d %d %d %d", &ax, &ay, &bx, &by);
	scanf("%d", &n);

	if (ax > bx) {
		swap(ax, bx);
		swap(ay, by);
	}

	for (int i = 1; i <= n; ++i) {
		pair<int, int> p;
		scanf("%d %d", &p.fi, &p.se);

		if (ax <= p.fi && p.fi <= bx) {
			if (min(ay, by) <= p.se && p.se <= max(ay, by)) {
				arr.pb(p);
			}
		}
	}

	ans = 100.0 * (bx - ax + abs(ay - by));

  	if (ax == bx || ay == by) {
  		if (!arr.empty()) {
  			ans = ans - 20.0 + PI * 10.0;
  		}

  		printf("%.13f\n", ans);
  		return;
  	}

	if (ay > by) {
		swap(ay, by);

		for (pair<int, int> &x : arr) {
			x.se *= -1;
		}
	}

    ans -= calc(arr);  	
    printf("%.13f\n", ans);
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 5744
n, k = gets.chomp.split(" ").map(&:to_i)
hash = [0] * (n + 1)
gets.chomp.split(" ").map(&:to_i).each{|a| hash[a] += 1}
aa = hash.select{|h| h != 0}.sort
aa = aa.slice(0,[aa.length - k,0].max).inject(&:+)
puts aa == nil ? 0 : aa

Measured memory_bytes: 22768
n = int(input())
u = sorted(map(int,input().split()))+[float('inf')]
m = sorted(map(int,input().split()))+[float('inf')]
l = sorted(map(int,input().split()))+[float('inf')]
dpm = [0]
dpl = [0]

i = 0
for j in range(n):
    cur = 0
    while u[i] < m[j]: cur+= 1; i+= 1
    dpm.append(dpm[-1]+cur)
i = 0
for j in range(n):
    cur = 0
    while m[i] < l[j]: cur+= dpm[i+1]; i+= 1
    dpl.append(dpl[-1]+cur)
print(sum(dpl))

Measured memory_bytes: 24608
#include <bits/stdc++.h>
using namespace std;
 
#define F(i,a,b) for(long long  i =a; i<b; i++)
#define rF(i,a,b) for(long long i=a-1; i>=b;i--)
#define endl "\n"
#define min1(x,y,z) min(x, min(y,z))
#define max1(x,y,z) max(x, max(y,z))
#define input_vector(v,n,type) vector<type> v;for(int i=0;i<n;i++){type x;cin>>x;v.push_back(x);}
#define IOS ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL);
#define int long long
#define inf (1LL<<61)
typedef pair<int,int> ii;
typedef vector<pair<int,int>> vii;
typedef vector<int> vi;
 
bool is(string s) {
        int n = s.length();
        for (int i = 0; i < n; i++) {
                if (s[i] != s[n-i-1])
                        return false;
        }
        return true;
}
 
int32_t main()
{
        IOS;

        string s;
        cin>>s;

        int n = s.length();
        
        if (is(s) && is(s.substr(0, (n-1)/2)) && is(s.substr((n+3)/2-1))) {
                cout<<"Yes"<<endl;
        } else {
                cout<<"No"<<endl;
        }






        
 
 
 
            
 
 
 
      
 
 
        
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

    bool is_palindrome(string s){
    string t;
    t = s;
    reverse(t.begin(),t.end());
    return s==t;
    }  

int main(void){

    string s; //文字列sに代入
    cin >> s;
    int n;
    n = s.size();//nの文字の長さ
    
    string t,u; //文字列t,uを置く
    t = s.substr(0,(n-1)/2);
    u = s.substr((n+1)/2 );//最後まで

    if( is_palindrome(s)&&is_palindrome(t)&&is_palindrome(u))
    {cout <<"Yes"<< endl;
    }
    else cout<<"No"<<endl;

    return 0;
}
 

Measured memory_bytes: 256
if __name__ == "__main__":
    A, B, C = [int(i) for i in raw_input().split()]
    flags = [False]*B
    n = A % B
    while True:
        if flags[n] == True:
            print "NO"
            break
        flags[n] = True
        n = (n+A) % B
        if flags[C] == True:
            print "YES"
            break

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

int main() {
  int n,k,d,a;
  cin>>n>>k;
  int ans=0,maxi=0;
  set<int> myset;
  while(k--) {
    cin>>d;
    while(d--) {
      cin>>a;
      myset.insert(a);
    }
  }
  int m=myset.size();
  cout<<n-m<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <climits>

using namespace std;

typedef signed long long ll;

#define MIN(a, b) (a < b) ? a : b
#define MAX(a, b) (a > b) ? a : b

int main(void)
{
    int N = 0;
    int R = 0;
    int min = INT_MAX;
    int max = -INT_MAX;

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> R;
        max = MAX(max, (R - min));
        min = MIN(R, min);
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 3092
#include<iostream>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M)){for(i=s=0;i<n;i++<k&&(M=s+=a[i-1]))std::cin>>a[i];for(i=k;i<n;M<s&&(M=s))s+=a[i]-a[i++-k];}}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl



int main(){
    int x,y;
    cin >> x >> y;
    int num = abs(abs(x)-abs(y));
    if((x<0&&y>0)||(x>0&&y<0)){
        cout << num+1 << endl;
        return 0;
    }
    else if(x==0){
        if(x<y)cout << num << endl;
        else cout << num+1 << endl;
    }
    else if(y==0){
        if(y>x)cout << num << endl;
        else cout << num+1 << endl;
    }
    else if(x<y){
        cout << num << endl;
        return 0;
    }
    else if(x>y){
        cout << num+2 << endl;
    }
    return 0;
}    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a, min_cnt;
    //bool flag = true;
    min_cnt = 1000000000;
    for (int i = 0; i < N; i ++){
        cin >> a;
        if (a % 2 != 0){
            //flag = false;
            min_cnt = 0;
            break;
        }
        int cnt = 0;
        while (a % 2 == 0){
            a /= 2;
            cnt += 1;
        }
        min_cnt = min(min_cnt, cnt);
    }
    cout << min_cnt << endl;
}

Measured memory_bytes: 3524
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
int n;
char s[50][50];
int add(int i,int j);
int mul(int i,int j);
int add(int i,int j){
    int k,l,m=0,c;
    int tmp[10];
    int ret;
    for(k=i;k<n;k++){
        for(l=c=0;s[k][l];l++)c+=(s[k][l]=='.');
        if(c>j)continue;
        if(c<j)break;
        if(s[k][j]=='+')
            tmp[m]=add(k+1,j+1);
        else if(s[k][j]=='*')
            tmp[m]=mul(k+1,j+1);
        else
            tmp[m]=s[k][j]-'0';
        m++;
    }
    ret=tmp[0];
    for(k=1;k<m;k++)
        ret+=tmp[k];
    return ret;
}
int mul(int i,int j){
    int k,l,m=0,c;
    int tmp[10];
    int ret;
    for(k=i;k<n;k++){
        for(l=c=0;s[k][l];l++)c+=(s[k][l]=='.');
        if(c>j)continue;
        if(c<j)break;
        if(s[k][j]=='+')
            tmp[m]=add(k+1,j+1);
        else if(s[k][j]=='*')
            tmp[m]=mul(k+1,j+1);
        else
            tmp[m]=s[k][j]-'0';
        m++;
    }
    ret=tmp[0];
    for(k=1;k<m;k++)
        ret*=tmp[k];
    return ret;
}
int main(void){
    int i;
    while(n=in()){
        rep(i,n)chin(s[i]);
        if(s[0][0]=='+')print(add(1,1));
        else if(s[0][0]=='*')print(mul(1,1));
        else printf("%c\n",s[0][0]);
    }
    return 0;
}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T, class Op = multiplies<T>>
constexpr T power(T a, long long n, Op op = Op(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  static constexpr unsigned mod = M;
  unsigned v;
  modular(long long x = 0) : v((x %= mod) < 0 ? x + mod : x) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m b) { if ((int)(v += b.v - mod) < 0) v += mod; return *this; }
  m& operator-=(m b) { if ((int)(v -= b.v) < 0) v += mod; return *this; }
  m& operator*=(m b) { v = (uint64_t)v * b.v % mod; return *this; }
  m& operator/=(m b) { return *this *= power(b, mod - 2); }
  friend m operator+(m a, m b) { return a += b; }
  friend m operator-(m a, m b) { return a -= b; }
  friend m operator*(m a, m b) { return a *= b; }
  friend m operator/(m a, m b) { return a /= b; }
  friend bool operator==(m a, m b) { return a.v == b.v; }
};

using mint = modular<998244353>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<int> a;
  int t = 0;
  for (char c : s) {
    if (c == '0') {
      a.push_back(t);
      t = 0;
    } else {
      ++t;
    }
  }
  a.push_back(t);
  DEBUG(a);
  int m = accumulate(begin(a), end(a), 0);
  vector dp(m + 1, vector(m + 1, mint()));
  dp[0][0] = 1;
  for (auto e : a) {
    vector ndp(m + 2, vector(m + 2, mint()));
    auto add = [&](int lx, int rx, int ly, int ry, mint x) {
      if (lx >= rx or ly >= ry) {
        return;
      }
      ndp[lx][ly] += x;
      ndp[rx][ly] -= x;
      ndp[lx][ry] -= x;
      ndp[rx][ry] += x;
    };
    for (int x = 0; x <= m; ++x) {
      for (int y = 0; y <= m; ++y) {
        // for (int i = 0; x + i <= m; ++i) {
        //   ndp[x + i][y] += dp[x][y];
        // }
        // for (int j = 1; j <= e and y + j <= x; ++j) {
        //   ndp[x][y + j] += dp[x][y];
        // }
        add(x, m + 1, y, y + 1, dp[x][y]);
        add(x, x + 1, y + 1, min(y + e, x) + 1, dp[x][y]);
      }
    }
    for (int x = 0; x <= m; ++x) {
      for (int y = 0; y < m; ++y) {
        ndp[x][y + 1] += ndp[x][y];
      }
    }
    for (int y = 0; y <= m; ++y) {
      for (int x = 0; x <= m; ++x) {
        ndp[x + 1][y] += ndp[x][y];
      }
    }
    swap(dp, ndp);
  }
  mint res;
  for (int x = 0; x <= min(m, k); ++x) {
    res += dp[x][x];
  }
  cout << res.v << '\n';
}


Measured memory_bytes: 3988
#include <stdio.h>

int erajudge(int year, int month, int day)
{
	if (year <= 1867) {
		printf("pre-meiji\n");
	} else if (year == 1868 && month <= 8) {
	    printf("pre-meiji\n");
	} else if (year == 1868 && month == 9 && day <= 7) {
		printf("pre-meiji\n");
	} else {
		if (year <= 1911) {
			printf("meiji %d %d %d\n", year - 1867, month, day);
		} else if (year == 1912 && month <= 6) {
			printf("meiji %d %d %d\n", year - 1867, month, day);
		} else if (year == 1912 && month == 7 && day <= 29) {
			printf("meiji %d %d %d\n", year - 1867, month, day);
		} else {
			if (year <= 1925) {
				printf("taisho %d %d %d\n", year - 1911, month, day);
			} else if (year == 1926 && month <= 11) {
				printf("taisho %d %d %d\n", year - 1911, month, day);
			} else if (year == 1926 && month == 12 && day <= 24) {
				printf("taisho %d %d %d\n", year - 1911, month, day);
			} else {
				if (year <= 1988) {
					printf("showa %d %d %d\n", year - 1925, month, day);
				} else if (year == 1989 && month == 1 && day <= 7) {
					printf("showa %d %d %d\n", year - 1925, month, day);
				} else {
					printf("heisei %d %d %d\n", year - 1988, month, day);
				}
			}
		}
	}
}			

int main(void)
{
    int year, month, day;
	while (scanf("%d %d %d", &year, &month, &day) != EOF) {
		erajudge(year, month, day);
	}
	return 0;
}

Measured memory_bytes: 1032
#include <iostream>
//#include <set>
//#include <map>
#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    double r;
    double ans;
    cin >> r;
    ans = 2*r*M_PI;

    cout << setprecision(10) << ans << endl;

    return 0;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 5e5 + 10;
int T;
const ll mod = 1e9 + 7;


struct zhtools {
    ll fac[N] = {1ll};

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

    void init() { for (ll i = 1; i < N; i++)fac[i] = fac[i - 1] * i % mod; }

    ll inv(ll a) { return binpow(a, mod - 2); }

    ll A(ll n, ll m) { return fac[n] * inv(fac[n - m]) % mod; }

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

int main() {
    zh.init();
    int n, m;
    scanf("%d%d", &n, &m);
    ll sum = 0;
    ll flag = 1ll;
    for (int i = 0; i <= n; i++) {
        sum += flag * zh.C(1ll * n, 1ll * i) * zh.A(1ll * (m - i), 1ll * (n - i)) % mod;
        sum = (sum + mod) % mod;
        flag = -flag;
    }
    printf("%lld\n", zh.A(m, n) * sum % mod);
    return 0;
}

Measured memory_bytes: 7736
// C
 #ifndef _GLIBCXX_NO_ASSERT
 #include <cassert>
 #endif
 #include <cctype>
 #include <cerrno>
 #include <cfloat>
 #include <ciso646>
 #include <climits>
 #include <clocale>
 #include <cmath>
 #include <csetjmp>
 #include <csignal>
 #include <cstdarg>
 #include <cstddef>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <ctime> 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 #include <ccomplex>
 #include <cfenv>
 #include <cinttypes>
 #include <cstdbool>
 #include <cstdint>
 #include <ctgmath>
 #include <cwchar>
 #include <cwctype>
 #endif
 
 // C++
 #include <algorithm>
 #include <bitset>
 #include <complex>
 #include <deque>
 #include <exception>
 #include <fstream>
 #include <functional>
 #include <iomanip>
 #include <ios>
 #include <iosfwd>
 #include <iostream>
 #include <istream>
 #include <iterator>
 #include <limits>
 #include <list>
 #include <locale>
 #include <map>
 #include <memory>
 #include <new>
 #include <numeric>
 #include <ostream>
 #include <queue>
 #include <set>
 #include <sstream>
 #include <stack>
 #include <stdexcept>
 #include <streambuf>
 #include <string>
 #include <typeinfo>
 #include <utility>
 #include <valarray>
 #include <vector> 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 #include <array>
 #include <atomic>
 #include <chrono>
 #include <condition_variable>
 #include <forward_list>
 #include <future>
 #include <initializer_list>
 #include <mutex>
 #include <random>
 #include <ratio>
 #include <regex>
 #include <system_error>
 #include <thread>
 #include <tuple>
 #include <typeindex>
 #include <type_traits>
 #include <unordered_map>
 #include <unordered_set>
 #endif
using namespace std;

struct UnionFind{
    vector<int> par;

    UnionFind(int N) : par(N){
        for(int i=0;i<N;++i) par[i] = i;
    }
    int root(int x){
        if(par[x] == x) return x;
        return par[x] = root(par[x]); 
    }

    void unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry; 
    }

    bool same(int x,int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n,q; cin >> n >> q;
    UnionFind tree(n);
    for(int i=0;i<q;++i){
        int com,x,y;
        cin >> com >> x >> y;
        if(com==0){
            tree.unite(x,y);
        }
        else{
            if(tree.same(x,y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3136
N = int(input())
S = [None] * N
ans = 0
first_b = 0
last_a = 0
both = 0
for i in range(N):
  S[i] = input()
  if (S[i][-1] == 'A' and S[i][0] == 'B'):
    both += 1
  else:
    if (S[i][-1] == 'A'):
      last_a += 1
    if (S[i][0] == 'B'):
      first_b += 1
  ans += S[i].count('AB')

if (both):
  ans += both - 1
  if (last_a):
    ans += 1
    last_a -= 1
  if (first_b):
    ans += 1
    first_b -= 1

ans = ans + (last_a + first_b - abs(last_a - first_b)) // 2
print(ans)

Measured memory_bytes: 44904
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = sr()
N = N[-1]
if N == '3':
    answer = 'bon'
elif N in ['0', '1', '6', '8']:
    answer = 'pon'
else:
    answer = 'hon'

print(answer)


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = 0;
    rep(i,n){
        cin>>a[i];
        if(a[i]%2) ans++;
    }
    cout<< (ans%2 ? "NO" :"YES") <<endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int num;
	char blood[3];
	int A_count = 0;
	int B_count = 0;
	int O_count = 0;
	int AB_count = 0;
	char comma;
	
	while (scanf("%d%c%s",&num,&comma,blood) != EOF){
		if(blood[0] == 'A' && blood[1] == '\0'){
			A_count++;
		}
		else if(blood[0] == 'B'){
			B_count++;
		}
		else if(blood[0] == 'O'){
			O_count++;
		}
		else {
			AB_count++;
		}
	}
	
	printf("%d\n",A_count);
	printf("%d\n",B_count);
	printf("%d\n",AB_count);
	printf("%d\n",O_count);
	
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define int long long
using namespace std;

using ll = __int128_t;

string addString(string s, string t){
    if(s.size() < t.size()) swap(s, t);
    char tmp;
    for(int i = s.size() - 1, j = t.size() - 1; i >= 0; i--, j--){
        if(j >= 0) s[i] += t[j] - '0';
        if(s[i] > '9'){
            s[i] -= 10;
            if(i == 0) s = '1' + s;
            else s[i - 1]++;
        }
    }
    return s;
}

string divide2String(string s){
    string res = "";
    int now = 0;
    for(int i = 0; i < s.size(); i++){
        now = now * 10 + s[i] - '0';
        int q = now / 2;
        now = now % 2;
        if(i == 0 && s.size() != 1 && q == 0) continue;
        res += '0' + q;
    }
    return res;
}

long long mod_pow(long long x, long long n){
    if(n == 0) return 1;
    long long res = mod_pow(x * x, n / 2);
    if(n & 1) res = res * x;
    return res;
}

// S以下のa, bを使った短歌数の個数
int calc(int a, int b, string s){
    int sz = s.size();
    // i桁目までで，j=0:Sに等しい，j=1:Sより小さい時の個数
    int dp[70][2] = {};
    dp[0][0] = 1;
    for(int i = 0; i < sz; i++){
        if(s[i] - '0' == a) dp[i + 1][0] += dp[i][0];
        else if(s[i] - '0' > a){
            if(!(i == 0 && a == 0)) dp[i + 1][1] += dp[i][0];
        }
        if(s[i] - '0' == b) dp[i + 1][0] += dp[i][0];
        else if(s[i] - '0' > b) dp[i + 1][1] += dp[i][0];
        dp[i + 1][1] += dp[i][1] * 2;
    }
    int res = dp[sz][0] + dp[sz][1];
    string alla = "", allb = "";
    for(int i = 0; i < sz; i++){
        alla += '0' + a;
        allb += '0' + b;
    }
    if(a != 0 && alla <= s) res--;
    if(allb <= s) res--;
    return res;
}

int n;

bool check(string m){
    int sz = m.size();
    ll res = 0;
    for(int i = 0; i < 10; i++){
        for(int j = i + 1; j < 10; j++){
            res += calc(i, j, m);
        }
    }
    for(int i = 2; i < sz; i++) res += 45 * (mod_pow(2, i) - 2) - 9 * (mod_pow(2, i - 1) - 1);
    return res >= n;
}

signed main(){
    while(cin >> n, n){
        string ng = "1", ok = "1";
        for(int i = 0; i < 61; i++) ok += "0";
        for(int i = 0; i < 300; i++){
            string mid = divide2String(addString(ok, ng));
            if(check(mid)) ok = mid;
            else ng = mid;
        }
        cout << ok << endl;
    }
}


Measured memory_bytes: 3176
#!/usr/bin/env python3
import sys
from collections import defaultdict


def solve(N: int, A: "List[int]", Q: int, B: "List[int]", C: "List[int]"):
    nums = defaultdict(int)
    for i in range(N):
        nums[A[i]] +=1
    s = 0
    for key in nums.keys():
        s += nums[key] * key
    for i in range(Q):
        count = nums[B[i]]
        nums[C[i]]+=nums[B[i]]
        nums[B[i]] = 0
        s = s - count*B[i] + count*C[i]
        print(s)

    return


# Generated by 1.1.7.1 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)) for _ in range(N)]  # type: "List[int]"
    Q = int(next(tokens))  # type: int
    B = [int()] * (Q)  # type: "List[int]"
    C = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, A, Q, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30180
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    s[m-1]=s[m-1]+('a' - 'A');
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.math.*;import java.util.*;class Main{public static void main(String[]z){int p[]=new int[10001],i=0;for(BigInteger x=BigInteger.ONE;i++<10000;p[i]=p[i-1]+x.intValue())x=x.nextProbablePrime();for(Scanner s=new Scanner(System.in);(i=s.nextInt())>0;)System.out.println(p[i]);}}

Measured memory_bytes: 187120
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

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

	int dx = x-a;
	int dy = y-b;

	cout<<string(dx,'R') << string(dy,'U');
	cout<<string(dx,'L') << string(dy,'D');
	cout<<"L"<<string(dy+1,'U') << string(dx+1,'R') << "D";
	cout<<"R"<<string(dy+1,'D') << string(dx+1,'L') << "U";
	cout<<endl;

}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N = int(readline())

ans =[0, 0, 0, 0]

for i in range(N):
  si = readline().strip()
  if si == "AC":
    ans[0] += 1
  elif si == "WA":
    ans[1] += 1
  elif si == "TLE":
    ans[2] += 1
  elif si == "RE":
    ans[3] += 1

print("AC x " + str(ans[0]))
print("WA x " + str(ans[1]))
print("TLE x " + str(ans[2]))
print("RE x " + str(ans[3]))

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

typedef long long LL;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;

const int INF = 1000000007;
const LL INFLL = 1000000000000000007;

#define st first
#define nd second
#define pb push_back
#define _boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

// ***************************** CODE ***************************** //

const int MAX = 1e5 + 7;
vector <int> v[MAX];
int dp[MAX];

void dfs(int u)
{
    for(auto i : v[u])
        if(!dp[i])  dfs(i);

    for(auto i : v[u])
        dp[u] = max((dp[i]+1), dp[u]);
}

int main() {
    _boost;

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        v[a].pb(b);
    }

    for(int i = 1; i <= n; i++)
        if(!dp[i])
            dfs(i);

    int maxx = -1;
    for(int i = 1; i <= n; i++)
        maxx = max(dp[i], maxx);

    cout << maxx;
    return 0;
}


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

int main(void)
{
    int t_flag, h_flag;
    int t_card[201], h_card[201], t_use, h_use;
    int i;
    int n;
    int temp;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        memset(t_card, 0, sizeof(t_card));
        memset(h_card, 0, sizeof(h_card));
        
        for (i = 0; i < n; i++){
            scanf("%d", &temp);
            t_card[temp - 1] = 1;
        }
        
        for (i = 0; i < 2 * n; i++){
            if (t_card[i] == 0){
                h_card[i] = 1;
            }
        }
        
        temp = 0;
        t_flag = h_flag = 1;
        t_use = h_use = n;
        while (t_flag == 1 || h_flag == 1){
            t_flag = h_flag = 0;
            for (i = temp; i < 2 * n; i++){
                if (t_card[i] == 1 && temp <= i){
                    temp = i;
                    t_card[i] = 0;
                    t_flag = 1;
                    t_use--;
                    break;
                }
            }
            if (t_use == 0){
                break;
            }
            if (t_flag == 0 && t_use != 0){
                temp = 0;
            }
            
            for (i = temp; i < 2 * n; i++){
                if (h_card[i] == 1 && temp <= i){
                    temp = i;
                    h_card[i] = 0;
                    h_flag = 1;
                    h_use--;
                    break;
                }
            }
            if (h_use == 0){
                break;
            }
            if (h_flag == 0){
                temp = 0;
            }
        }
        
        printf("%d\n%d\n", h_use, t_use);
    }
    
    return (0);
}

Measured memory_bytes: 0
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


a, b = map(int, input().split())
# 素因数分解して重複削除
a2 = list(set(prime_factorize(a)))
b2 = list(set(prime_factorize(b)))
# 連結
con = a2 + b2
# 重複のみ抽出
ans = [x for x in set(con) if con.count(x) > 1]
# 公倍数1を考慮
print(len(ans) + 1)

Measured memory_bytes: 3064
///*.......................Shadman Sakib Utshob............................*///

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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

#define Boost           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
#define pb              push_back
#define inf             1e9+8
#define mp              make_pair
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define ll              long long
#define pii             pair<ll,ll >
#define MOD             1000000007
#define fileout         freopen("output.txt","w",stdout)
#define mem(x,i)        memset(x,i,sizeof x)
#define Ones(x)         __builtin_popcount(x);
#define PI              acos(-1.0)
#define ff              first
#define ss              second
#define T               int t;cin>>t;while(t--)
#define ok              cout<<"ok"<<endl;
#define all(x)          (x).begin(),(x).end()
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define nln	            cout<<endl;

int main()
{
    Boost;
    int x,y,n,i,j,ans=1;
    string s;

    cin>>n>>s;
    //s+='#';
    for(i=1;i<s.size();i++)
    {
        if(s[i]!=s[i-1])
        {
            ans++;
        }
    }
    cout<<ans<<endl;



}


Measured memory_bytes: 3764
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

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

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    vector<bool> good(n, true);
    cin >> h;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (h[a] == h[b]) {
            good[a] = good[b] = false;
        }
        else if (h[a] < h[b]) good[a] = false;
        else good[b] = false;
    }
    int cnt = 0;
    rep(i, n) if (good[i]) cnt++;
    cout << cnt << endl;
}

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

using namespace std;

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

int main(){
    int n;
    cin >> n;
    int c[22];
    int v[22];
    for(int i = 0; i < n; i++)cin >> v[i];
    for(int i = 0; i < n; i++)cin >> c[i];
    int sum = 0;
    for(int i = 0; i < n; i++)sum+=max(0, v[i]-c[i]);
    cout << sum << endl;
    return 0;
}

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

using namespace std;

long long n, ans = 1e18;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; 1LL * i * i <= n; i++) {
        if (n % i == 0) ans = min(ans, i + n / i);
    }
    
    cout << ans - 2;
    return 0;
}

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

int main()
{
    int N, K;
    vector<int> L;
    cin >> N >> K;
    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        int l;
        cin >> l;
        L.push_back(l);
    }
    sort(L.rbegin(), L.rend());
    for (int i = 0; i < K; ++i){
        ans += L[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int l,r;
  cin>>l>>r;
  long long int d;
  cin>>d;
  long long int ans=0;
  for(long long int i=l; i<=r; i++){
    if(i%d==0){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int a[200010];
long long cnt[2][2][200010],w[2][200010];
long long st[2][200010][20];
inline long long getmx(int id,int l,int r)
{
	bool pd=false;
	if(l==0)l=1,pd=true;
	if(l>r)return 0;
	int k = (int)(log((double)(r - l + 1)) / log(2.0));
	long long mx=max(st[id][l][k],st[id][r-(1<<k)+1][k]);
	if(pd==true)mx=max(mx,0LL);
	return mx;
}
inline long long solve(int l,int r)
{
	if(l==r)return 0;
	int d=r-l+1;
	if(d&1)
	{
		long long mx=solve(l,r-1);
		mx=max(mx,solve(l+1,r));
		if(l+2<=r-2)mx=max(mx,solve(l+2,r-2)+a[l]+a[r]);
		return mx;
	}
	else
	{
		if(l&1)return cnt[1][1][r/2]-cnt[1][0][(l-1)/2]+getmx(0,(l-1)/2,r/2);
		else return cnt[0][1][(r-1)/2]-cnt[0][0][l/2-1]+getmx(1,l/2-1,(r-1)/2);
	}
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
   	int n=read(),now;
   	for(int i=1;i<=n;i++)a[i]=read();
   	now=0;
   	for(int i=1;i<=n;i+=2)
   	{
   		now++;
   		cnt[1][0][now]=cnt[1][0][now-1]+a[i];
   		cnt[1][1][now]=cnt[1][1][now-1]+a[i+1];
   		w[1][now]=cnt[1][0][now]-cnt[1][1][now];
   	}
   	for(int i=1;i<=now;i++)st[0][i][0]=w[1][i];
   	for(int i=1;(1<<i)<=now;i++)
   	{
   		for(int j=1;j+(1<<i)-1<=now;j++)st[0][j][i]=max(st[0][j][i-1],st[0][j+(1<<(i-1))][i-1]);
   	}
   	now=0;
   	for(int i=2;i<=n;i+=2)
   	{
   		now++;
   		cnt[0][0][now]=cnt[0][0][now-1]+a[i];
   		cnt[0][1][now]=cnt[0][1][now-1]+a[i+1];
   		w[0][now]=cnt[0][0][now]-cnt[0][1][now];   		
   	}
   	for(int i=1;i<=now;i++)st[1][i][0]=w[0][i];
   	for(int i=1;(1<<i)<=now;i++)
   	{
   		for(int j=1;j+(1<<i)-1<=now;j++)st[1][j][i]=max(st[1][j][i-1],st[1][j+(1<<(i-1))][i-1]);
   	}printf("%lld\n",solve(1,n));
    return 0;
}

Measured memory_bytes: 41312
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <set>
#include <map>

using namespace std;

int cnt[3];
double dp[301][301][301];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    cin >> N;
    int M = 0;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        cnt[a-1]++;
        M += a;
    }
    dp[0][0][0] = 0;
    for(int sum = 1; sum <= N; sum++){
        for(int i = 0; i <= sum; i++){
            for(int j = 0; i+j <= sum; j++){
                int k = sum-(i+j);
               // cout << i << ' ' << j << ' ' << k << endl;
                double tmp = 0.0;
                if(i >= 1) tmp += (((double)i/(double)N)*(dp[i-1][j+1][k]+1));
                if(j >= 1) tmp += (((double)j/(double)N)*(dp[i][j-1][k+1]+1));
                if(k >= 1) tmp += (((double)k/(double)N)*(dp[i][j][k-1]+1));
                //cout << tmp << endl;
                tmp += ((double)(N-sum)/(double)(N));
                tmp *= ((double)N/(double)(i+j+k));
                dp[i][j][k] = tmp;
               // cout << dp[i][j][k] << endl;
            }
        }
    }
    cout << dp[cnt[2]][cnt[1]][cnt[0]] << endl;;
}

Measured memory_bytes: 213248
#include <cstdio>

#define N 6

int main() {
	char S[N] = {0};
	scanf("%s", S);

	for (int i = 0; i < N - 1; i++) {
		if (S[i] == 'A' && S[i + 1] == 'C') {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	
}


Measured memory_bytes: 128
s=int(input())
a={s}
i=1
an_1=s
def f(num):
    if num%2==0:
        return num//2
    else:
        return num*3+1
while True:
    i+=1
    an=f(an_1)
    if an in a:
        print(i)
        break
    else:
        a.add(an)
        an_1=an

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

int main()
{
    int A, B;

    cin >> A >> B;

    if (A > 9 || B > 9)
    {
        cout << "-1" << endl;
    }
    else
    {
        int ans = A * B;

        cout << ans << endl;
    }

    return 0;
}

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

long mod = 998244353;
vector<long> fact, inv;

long power(long n, long k) {
  if (k == 0) return 1;
  long res = power(n * n % mod, k / 2);
  if (k % 2) res = res * n % mod;
  return res;
}

void init(int n) {
  fact.push_back(1);
  inv.push_back(1);
  for (int i = 0; i < n; i++) {
    fact.push_back(fact.at(i) * (i + 1) % mod);
    inv.push_back(power(fact.at(i + 1), mod - 2));
  }
}

long ncr(long n, long r) {
  return fact.at(n) * inv.at(r) % mod * inv.at(n - r) % mod;
}

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  init(N);
  long ans = 0;
  for (int i = 0; i <= K; i++) {
    (ans += M * power(M - 1, N - i - 1) % mod * ncr(N - 1, i) % mod) %= mod;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 6560
from collections import defaultdict

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def main():
    n = int(input())
    pfactor = prime_factorize(n)
    d = defaultdict(int)
    for p in pfactor:
        d[p] += 1
    hoge = []
    a = 0
    for i in range(100):
        tmp = 1 + i
        a += tmp
        hoge.append(a)
    cnt = 1
    score = []
    for i, j in zip(hoge[:-1], hoge[1:]):
        for _ in range(j - i):
            score.append(cnt)
        cnt += 1
    res = 0
    for v in d.values():
        res += score[v-1]
    print(res)

     

if __name__ == '__main__':
    main()



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

ans = 0
x = max(0, (M-2*N) // 4)
r = min(10, M//2)
for i in range(max(0, x-r), x+r):
    tmp = min(N+i, (M-2*i)//2)
    ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 38256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 1000000

void initialized( void );
void push(int);
int  pop(void);
int  isFull(void);
int  isEmpty(void);

int S[100];
int top;

void initialized( void )
{
  top = 0;
}

void push(int x)
{
  if(isFull() == 0){
  top++;
  S[top] = x;
  }
  else fprintf(stderr, "error\n");
}

int  pop(void)
{
  if(isEmpty() == 0){
  top--;
  return S[top+1];
  }
  else fprintf(stderr, "error\n");
}

int isFull( void )
{
  if(top > N -1) return 1;
  else return 0;
}

int isEmpty( void )
{
  if(top == 0) return 1;
  else return 0;
}

int main()
{
  int a, b, n;
  char C[N];
  while( scanf("%s", C) != EOF ){
    if( C[0] == '+' ){
      a = pop();
      b = pop();
      push( a + b );
    }
    else if( C[0] == '-' ){
      a = pop(); 
      b = pop();
      push( b - a );
    }
    else if( C[0] == '*' ){
      a = pop();
      b = pop();
      push( a * b );
    }
    else push( atoi(C) );
  }    

  printf("%d\n", pop());

  return 0;
}

Measured memory_bytes: 556
# -*- coding: utf-8 -*-
import numpy as np
A, B = map(int, input().split())

L = max(A, B)
S = min(A, B)
flag = 1
while(flag == 1):
  #print(L, S)
  if(L % S == 0):
    flag = 0
    lval = S
  else:
    tmp = L % S
    L = S
    S = tmp

Ar = A // lval
Br = B // lval

print(int(lval*Ar*Br))


Measured memory_bytes: 12508
N,M = map(int, input().strip().split(' '))
persons = [list(map(int, input().strip().split(' '))) for _ in range(N)]
checkpoints = [list(map(int, input().strip().split(' '))) for _ in range(M)]

def distance(person, checkpoint):
  return sum(abs(a-b) for a,b in zip(person, checkpoint))
  
for person in persons:
  print(sorted([[distance(person, checkpoint), i+1] for i,checkpoint in enumerate(checkpoints)])[0][1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  rep(i, 5) {
    int x;
    cin >> x;
    if(x==0) {
      cout << i+1 << "\n";
      return;
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

ll mod = 1000000007;

int main(){
    ll N; cin >> N;
    vll e(N);
    for(int i=0; i<N; i++){
        cin >> e[i];
    }
    ll t = 0;
    for(int i=1; i<N-1; i++){
        vi k(0); 
        k.emplace_back(e[i-1]);k.emplace_back(e[i]);k.emplace_back(e[i+1]);
        sort(k.begin(),k.end());
        if(k[1] == e[i]){
            t++;
        }
    }
    cout << t;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int main() {
	llong k, n;
	llong a[200005];
	cin >> k >> n;
	rep( i, n )
		cin >> a[i];

	std::sort( a, a + n );
	a[n] = k + a[0];

	llong ans = 0;
	llong m = 0;
	for( int i = 1; i < n+1; ++i )
	{
		llong d = a[i] - a[i - 1];
		ans += d;
		if( m < d )
			m = d;
	}
	ans -= m;

	cout << ans;
}

Measured memory_bytes: 1792
using System;
using System.Linq;

class D2
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var s = Console.ReadLine();

		var d = s.ToLookup(c => c);
		var r = d['R'].LongCount() * d['G'].Count() * d['B'].Count();
		for (int i = 0; i < n; i++)
			for (int j = i + 1; j < n; j++)
			{
				var k = 2 * j - i;
				if (k < n && s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) r--;
			}
		Console.WriteLine(r);
	}
}


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


int main () {

    long long a, b, c, k ;
    cin >> a >> b >> c >> k ;
    if (k&1) {
        printf ("%lld" , b-a) ;
    }
    else {
        printf ("%lld" , a-b) ;
    }

}


Measured memory_bytes: 256