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

template <class T>
inline void read(T &x) {
	static char ch; 
	static bool opt; 
	while (!isdigit(ch = getchar()) && ch != '-'); 
	x = (opt = ch == '-') ? 0 : ch - '0'; 
	while (isdigit(ch = getchar()))
		x = x * 10 + ch - '0'; 
	if (opt)
		x = ~x + 1; 
}

template <class T>
inline void putint(T x) {
	static char buf[45], *tail = buf; 
	if (!x) {
		putchar('0'); 
	} else {
		if (x < 0)
			putchar('-'), x = ~x + 1; 
		for (; x; x /= 10) *++tail = x % 10 + '0'; 
		for (; tail != buf; --tail) putchar(*tail); 
	}
}

using namespace std; 

const int MaxN = 2e5 + 5; 

int n, m, ans; 
int ufs[MaxN], sze[MaxN]; 

inline int find(int x) {
	return x == ufs[x] ? x : ufs[x] = find(ufs[x]); 
}

int main() {
	read(n), read(m); 

	for (int i = 1; i <= n; ++i) {
		ufs[i] = i; 
	}
	for (int i = 1; i <= m; ++i) {
		int a, b; 
		read(a), read(b); 
		ufs[find(a)] = find(b); 
	}

	for (int i = 1; i <= n; ++i)
		++sze[find(i)]; 

	for (int i = 1; i <= n; ++i)
		ans = max(ans, sze[i]); 

	cout << ans << '\n'; 

	return 0; 
}

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

#define check abs(vec[i] - vec[i + 1])

int main() {
	int n, num_abs; vector<int> vec;
	while (1) {
		cin >> n; if (n == 0) break;
		num_abs = INT_MAX; vec.resize(n);
		for (int i = 0; i < n; i++) cin >> vec[i];
		sort(vec.begin(), vec.end());
		for (int i = 0; i < n - 1; i++){
			if (check < num_abs) num_abs = check;
			if (check == 0) { num_abs = check; break; }
		}
		cout << num_abs << endl;
		for (int i = 0; i < n; i++) vec.pop_back();
	}
	return 0;
}


Measured memory_bytes: 3104
//vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
//includeとusing
#include <bits/stdc++.h>
using namespace std;
//型名省略
using ll = long long;
using st = string;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using pcc = pair<char, char>;
//定数
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define REP(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define RREP(i,x,n) for(ll i = (ll) n - 1; i >= x; i--)
#define each(i,A) for(ll i: (vl) A)
#define all(A) A.begin(), A.end()
#define Size(A) ll(A.size())
//入力
template<typename T> T input() {T x; cin >> x; return x;}
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
//余り切り上げ
ll ceil(ll a,ll b) {return (a + b - 1) / b;}
//最大値・最小値
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b) {a = b; return true;} return false;}
//最大公約数
ll gcd(ll a,ll b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
//最小公倍数
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//n乗の余り
ll modpow(ll x,ll n,ll mod){ll res=1;for(ll i=0;i<n;i++){res=res*x%mod;}return res;}
ll MODpow(ll x,ll n){ll res=1;for(ll i=0;i<n;i++){res=res*x%MOD;}return res;}


/*--------------------------------------------------------------------------*/

//main関数
int main() {

    ll n; cin >> n;

    cout << (n + 1) / 2 << endl;
}



Measured memory_bytes: 3628
# include "bits/stdc++.h"

using namespace std;

#define endl "\n"
typedef long long int ll;

inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}

//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;

ll INF = 1e10;
int MOD = 1e9+7;

const int mxn = 2e5 + 5;
int h[mxn], b[mxn];
int n;
ll dp[mxn];
ll val[mxn];

ll t[4*mxn] = {0}; //segtree

void update(int cur, int tl, int tr, int idx, ll num){
	if(tl == tr) t[cur] = val[idx] = num;
	else{
		int tm = (tl+tr)>>1;
		if(idx <= tm) update(2*cur+1, tl, tm, idx, num);
		else update(2*cur+2, tm+1, tr, idx, num);
		t[cur] = max(t[2*cur+1], t[2*cur+2]);
	}
}

ll query(int cur, int tl, int tr, int l, int r){
	if(l > r) return 0;
	if(tl == l && tr == r) return t[cur];
	int tm = (tl+tr)>>1;
	if(r <= tm) return query(2*cur+1, tl, tm, l, r);
	else if(l > tm) return query(2*cur+2, tm+1, tr, l, r);
	else return max(query(2*cur+1, tl, tm, l, tm), query(2*cur+2, tm+1, tr, tm+1, r));
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("debug.txt", "w", stderr);
    #endif
    fastio();
    cin>>n;
    for(int i=0;i<n;++i) {cin>>h[i]; h[i]-=1;}
    for(int i=0;i<n;++i) cin>>b[i];
    //dp[i] max beauty if ith is last element
    dp[0] = b[0];
	update(0, 0, n-1, h[0], dp[0]);
	ll ans = dp[0];
	for(int i=1;i<n;++i){
		dp[i] = query(0, 0, n-1, 0, h[i]-1) + (ll)b[i];
		update(0, 0, n-1, h[i], dp[i]);
		ans = max(ans, dp[i]);
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 12392
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=2e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int n,a,b,h[100000];

bool C(int x){
	int now = 0;
	for(int i = 0;i < n;i++){
		now += max(0ll,(h[i] - b * x + a - b - 1) / (a - b));
	}
	return now <= x;
}

signed main(){
	cin >> n >> a >> b;
	for(int i = 0;i < n;i++) cin >> h[i];
	int low = 0,up = INF;
	while(up - low > 1){
		int mid = (up + low) / 2;
		if(C(mid)) up = mid;
		else low = mid;
	}
	cout << up << endl;
	return 0;
}

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

class Dice {
private:
    int num[6];
    int top;
    int side_n;
    int side_e;

public:
    Dice(int *num);
    void Roll(char dir);
    int getTopNum() { return num[top-1]; }
};

Dice::Dice(int *num)
{
    for (int i = 0; i < 6; i++) this->num[i] = num[i];
    top = 1;
    side_n = 5;
    side_e = 3;
}
void Dice::Roll(char dir)
{
    int tmp;
    
    switch (dir) {
        case 'N': tmp = top; top = 7-side_n; side_n = tmp; break;
        case 'E': tmp = top; top = 7-side_e; side_e = tmp; break;
        case 'W': tmp = top; top = side_e; side_e = 7-tmp; break;
        case 'S': tmp = top; top = side_n; side_n = 7-tmp; break;
        default : break;
    }
}

int main()
{
  int a[6];
  char c;
  
  for (int i = 0; i < 6; i++) cin >> a[i];
  Dice dice(a);
  while (cin >> c) dice.Roll(c);
  cout << dice.getTopNum() << endl;

  return 0;
}



Measured memory_bytes: 3112
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int p, q, r;
	cin >> p >> q >> r;
	cout << p + q + r - max(p, max(q, r)) << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

void mod_inverse(int n, vector<long long>& inv, int mod)
{
    inv.assign(n+1, -1);
    inv[1] = 1;
    for(int i=2; i<=n; ++i)
        inv[i] = inv[mod % i] * (mod - mod / i) % mod;
}

class FactorialCalculation
{
private:
    const int mod;
    vector<long long> factorial;
    vector<long long> invFactorial;
public:
    FactorialCalculation(int n, int mod) : mod(mod)
    {
        factorial.resize(n+1, 1);
        invFactorial.resize(n+1, 1);
        vector<long long> inv;
        mod_inverse(n, inv, mod);
        for(int i=1; i<=n; ++i){
            factorial[i] = factorial[i-1] * i % mod;
            invFactorial[i] = invFactorial[i-1] * inv[i] % mod;
        }
    }
    long long getFactorial(int n){
        return factorial[n];
    }
    long long getInvFactorial(int n){
        return invFactorial[n];
    }
    long long getPermutation(int n, int r){
        if(n < r)
            return 0;
        return factorial[n] * invFactorial[n-r] % mod;
    }
    long long getCombination(int n, int r){
        if(n < r)
            return 0;
        return getPermutation(n, r) * invFactorial[r] % mod;
    }
    long long getHomogeneous(int n, int r){
        if(n == 0 && r == 0)
            return 1;
        return getCombination(n+r-1, r);
    }
};

const int MOD = 998244353;

int main()
{
    int m, n;
    cin >> m >> n;
    FactorialCalculation fc(n+m, MOD);

    vector<long long> dp(n+1, 0);
    vector<long long> ans(2*m+1, 0);
    dp[n] = 1;
    for(int k=2; k<=m+1; ++k){
        if(k % 2 != 0 && k <= m + 1){
            long long sum = 0;
            for(int i=n; i>=0; --i){
                long long tmp = sum;
                sum += dp[i];
                sum %= MOD;
                dp[i] += tmp * 2;
                dp[i] %= MOD;
            }
        }

        for(int i=0; i<=n; ++i){
            ans[k] += dp[i] * fc.getHomogeneous(m + 1 - k, i);
            ans[k] %= MOD;
            if(k % 2 == 0 && i > 0){
                ans[k] += dp[i] * fc.getHomogeneous(m + 1 - k, i - 1);
                ans[k] %= MOD;
            }
        }
        ans[2*m+2-k] = ans[k];
    }

    for(int k=2; k<=2*m; ++k)
        cout << ans[k] << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main(){
    ll N,K,count=0;
    cin >> N >> K;
    vector<ll> data(N);
    rep(i,N){
        cin >> data.at(i);
        if(data.at(i)>=K) count++;
    }

    cout << count << endl;
    
 
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
template <class T> inline bool chmin(T& a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}

int INF = 1e9;
int main() {
  int N;
  cin >> N;
  vector<int> l2r(N, 0);
  vector<int> r2l(N, 0);
  string S;
  cin >> S;
  { // 先頭からお尻への黒の累積和
    int count = 0;
    for(int i = 0; i < S.size(); ++i) {
      if(S[i] == '#') {
        count++;
      }
      l2r[i] = count;
    }
  }
  { // お尻から先頭への白の累積和
    int count = 0;
    for(int i = S.size() - 1; i >= 0; --i) {
      if(S[i] == '.') {
        count++;
      }
      r2l[i] = count;
    }
  }
  int ans = INF;
  for(int i = 0; i < S.size(); ++i) {
    chmin(ans, l2r[i] + r2l[i]);
  }
  cout << ans - 1 << endl;
  return 0;
}

Measured memory_bytes: 2180
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int [n];
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();

        int direction = 0;
        int last = a[0];
        int ans = 1;

        for (int val: a) {
            if (direction == 0) {
                if (val > last) direction = 1;
                if (val < last) direction = -1;
                last = val;
            }
            if (direction == 1) {
                if (val < last) {
                    direction = 0;
                    ans += 1;
                } last = val;
            }
            if (direction == -1) {
                if (val > last) {
                    direction = 0;
                    ans += 1;
                } last = val;
            }
        }
        System.out.println(ans);
    }
}


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

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

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

void solve(){
  int n;
  cin>>n;
  vector<int>s(n);
  int sum=0;
  rep(i,n)cin>>s[i],sum+=s[i];
  sort(s.begin(),s.end());
  if(sum%10)cout<<sum;
  else {
    rep(i,n){
      if(s[i]%10){
        sum-=s[i];
        cout<<sum;
        return;
      }
    }
    cout<<0;
  }
}

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


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

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

int main(){
	string T;
	cin >> T;
	string S;
	rep(i,T.size()){
		if(T[i]=='P') S+='P';
		else S+='D';
	}
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 3920
from math import gcd
n = int(input())
a = [int(i) for i in input().split()]

g = a[0]
for i in range(n):
    g = gcd(g,a[i])
if g != 1:
    print("not coprime")
    exit()

m = max(a)
fac = [1]*(m+1)
for i in range(2,m+1):
    if fac[i] != 1:
      continue
    for j in range(i,m+1,i):
      fac[j] = i
      
s = set()
for i in range(n):
    x = fac[a[i]]
    if x == 1: 
      continue
    if x in s:
      print("setwise coprime")
      exit()
    s.add(x)
print("pairwise coprime")


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

long many_number(string n, string s, int a) {
  if (a == n.size()) {
    string e = "";
    long d = 0;
    rep (i, s.size()) {
      if (s.at(i) == '+'){
        d += atol(e.c_str());
        e = "";
      }
      else {
        e += s.at(i);
      }
    }
    d += atol(e.c_str());
    return d;
  }
  
  return many_number(n, s + '+' + n.at(a), a + 1) +
  many_number(n, s + n.at(a), a + 1);

}

int main() {
  string n;
  cin >> n;
  string a;
  a = n.at(0);
  cout << many_number(n, a, 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e5 + 3;
int n, mom[nmax], sol[nmax], t1, t2, t3, p;
vector <int> v1[nmax];
vector <int> v2[nmax];

struct usu1
{
    int x;

    bool operator < (const usu1 t) const
    {
        if(v1[x].size() < v1[t.x].size()) return 1;
        if(v1[x].size() > v1[t.x].size()) return 0;
        return x < t.x;
    }
};

struct usu2
{
    int x;

    bool operator < (const usu2 t) const
    {
        if(v2[x].size() < v2[t.x].size()) return 1;
        if(v2[x].size() > v2[t.x].size()) return 0;
        return (!(x < t.x));
    }
};

priority_queue <usu1> q1;
priority_queue <usu2> q2;

int main()
{
    ios::sync_with_stdio(false);

    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> mom[i];

        v1[mom[i]].push_back(i);

        usu1 act;
        act.x = mom[i];

        if(mom[i] != mom[i - 1]) q1.push(act);
    }

    for(int i = 1; i <= n; ++i)
    {
        cin >> mom[i];

        v2[mom[i]].push_back(i);

        usu2 act;
        act.x = mom[i];

        if(mom[i] != mom[i - 1]) q2.push(act);
    }

    while(!q1.empty())
    {
        t1 = q1.top().x;
        q1.pop();

        t2 = q2.top().x;
        q2.pop();

        t3 = 0;

        if(!q2.empty())
        {
            t3 = q2.top().x;
            q2.pop();
        }

        if(t1 != t2)
        {
            p = v1[t1][v1[t1].size() - 1];
            sol[p] = t2;
            v1[t1].pop_back();
            v2[t2].pop_back();

            if(v1[t1].size() >= 1) q1.push({t1});
            if(v2[t2].size() >= 1) q2.push({t2});

            if(t3 != 0) q2.push({t3});
            continue;
        }

        q2.push({t2});

        if(t3 == 0)
        {
            cout << "No";
            return 0;
        }

        p = v1[t1][v1[t1].size() - 1];
        sol[p] = t3;
        v1[t1].pop_back();
        v2[t3].pop_back();

        if(v1[t1].size() >= 1) q1.push({t1});
        if(v2[t3].size() >= 1) q2.push({t3});
    }

    cout << "Yes\n";

    for(int i = 1; i <= n; ++i) cout << sol[i] << ' ';
    return 0;
}


Measured memory_bytes: 28036
#include <cstdio>
int main()
{
	char b;
	int a,c,d,i,j;
	scanf("%d %c %d",&a,&b,&c);
	d = b;
	if(d==43)
	{
		i=a+c;
		printf("%d\n",i);
	}
	else
	{
		j=a-c;
		printf("%d\n",j);
	}
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,a,b,N,ans=1;
  cin>>N;
  N*=2;
  mat v;
  for(i=2;i*(i-1)<=N;i++){
    if(i*(i-1)==N){
      cout<<"Yes"<<endl<<i<<endl;
      v.resize(i);
      rep(a,i){
        For(b,a+1,i){
          v[a].pb(ans);
          v[b].pb(ans++);
        }
      }
      for(auto x:v){
        cout<<x.size()<<" ";
        output(x);
      }
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

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

int main() {
string S, T; 
cin >> S >> T;

for (int i = 0; i < S.size(); ++i) { 
    if (S ==T) {
    cout << "Yes" << endl;
    return 0;
    }
    S = S.back() + S.substr(0, S.size()-1);
}

cout << "No" << endl;

return 0;
}

Measured memory_bytes: 256
//Leonidas
#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container'.',hpp>
//#include <ext/pb_ds/tree_policy'.',hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int32_t main()
{
    speed
    char a;
    cin>>a;
    if(a>='a')
        cout<<"a";
    else
        cout<<"A";
    return 0;
}


Measured memory_bytes: 3584
import java.io.InputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        final MyScanner sc = new MyScanner();
        int[] time = new int[3];
        for (int i = 0; i < 3; i++) {
            time[i] = sc.nextInt();
        }
        Arrays.sort(time);
        int answer = time[0] + time[1];
        System.out.println(answer);
    }
}

class MyScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int pointer = 0;
    private int bufLength = 0;

    private boolean hasNextByte() {
        if (pointer < bufLength) {
            return true;
        } else {
            pointer = 0;
            try {
                bufLength = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (bufLength <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[pointer++];
        } else {
            return -1;
        }
    }

    private static boolean isNumberChar(int c) {
        return '0' <= c && c <= '9';
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[pointer])) {
            pointer++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long num = 0;
        boolean isNegative = false;
        int b = readByte();
        if (b == '-') {
            isNegative = true;
            b = readByte();
        }
        if (!isNumberChar(b)) {
            throw new NumberFormatException();
        }
        while (true) {
            if (isNumberChar(b)) {
                num *= 10;
                num += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return isNegative ? -num : num;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long temp = nextLong();
        if (temp < Integer.MIN_VALUE || Integer.MAX_VALUE < temp) {
            throw new NumberFormatException();
        }
        return (int) temp;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

int main()
{
	long long N,a,b,i,m;
	while(cin>>N)
	{
		a=N;
		b=1;
		m=a+b;
		for(i=sqrt(N);i>=1;i--)
		{
			if(N%i==0){
				N=N/i;
				a=a/i;
				b=b*i;
				if(a+b<m){
					m=a+b;
				}
			
			}
		}
		cout<<m-2<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

class Path {
public:
	int to, from, id;
	Path() {};
};

int main() {
	int n, m;
	cin >> n >> m;
	vector<Path> p;
	vector<vector<int>> a;
	a.resize(n);
	p.resize(2*m);
	for (int i = 0; i < m; i++) {
		int to, from;
		cin >> to >> from;
		p[i * 2].from = from-1;
		p[i * 2].to = to -1;
		p[i * 2].id = i;
		p[i * 2 + 1].from = to-1;
		p[i * 2 + 1].to = from -1;
		p[i * 2 + 1].id = i;
		a[from - 1].push_back(i*2);
		a[to - 1].push_back(i * 2 + 1);
	}
	vector<bool> b;
	b.resize(m);
	int now = p[0].to, from = p[0].from;
	b[0] = true;
	for (int i = 1; i < m; i++) {
		int pa = -1;
		for (int j = 0; j < a[now].size(); j++) {
			pa = a[now][j];
			if (!b[p[pa].id]) {
				break;
			}
			else {
				pa = -1;
			}
		}
		if (pa == -1) {
			if (now == from) {
				cout << "YES" << endl;
		//		cin >> n;
				return 0;
			}
			cout << "NO" << endl;
		//	cin >> n;
			return 0;
		}
		b[p[pa].id] = true;
		now = p[pa].to;
		if (now == from) {
			for (int j = 0; j < m; j++) {
				if (!b[j]) {
					b[j] = true;
					now = p[j * 2].to;
					from = p[j * 2].from;
					break;
				}
			}
		}
		if (now == from) {
			int c = 0;
			for (int j = 0; j < m; j++) {
				if (b[j])
					c++;
			}
			if (c == m) {
				cout << "YES" << endl;
			//	cin >> n;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
//	cin >> n;
	return 0;
}

Measured memory_bytes: 7680
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int a, b;
  cin >> a >> b;
  if (a == b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

struct Card{
  char a;
  int b;
};

bool compare_as_ints(Card i, Card j){
  return (i.b<j.b);
}

int partition(Card A[], int p, int r){
  Card x = A[r];
  int i = p-1;
  for(int j=p; j<=r-1; j++){
    if(A[j].b<=x.b){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}

void quickSort(Card A[], int p, int r){
  if(p<r){
    int q = partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}

int main(){
  int n;
  cin >> n;
  Card A[100000],B[100000];
  for(int i=0; i<n; i++){
    cin >> A[i].a >> A[i].b;
    B[i] = A[i];
  }
  quickSort(A,0,n-1);
  stable_sort(B,B+n,compare_as_ints);

  for(int i=0; i<n; i++){
    if(A[i].a==B[i].a){
      if(i==n-1)
        cout << "Stable" << endl;
    }
    else{
      cout << "Not stable" << endl;
      break;
    }
  }

  for(int i=0; i<n; i++)
    cout << A[i].a << ' ' << A[i].b << endl;

  return 0;
}



Measured memory_bytes: 4660
n,k=map(int, input().split())
a=list(map(int, input().split()))
dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
  for j in range(1,k+1):
    if(i-j<0):
      break
    dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]))
print(dp[-1])

Measured memory_bytes: 85904
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int A, B;
    cin >> A >> B;
    if (B == 1) cout << 0 << endl;
    else {
        if (A >= B) cout << 1 << endl;
        else {
            int n = (B - A + (A - 1) - 1) / (A - 1);
            cout << n + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,u,v,a[200010];
vector<int>s[200010];
bool flag[200010];
void dfs(int x,int y){
	a[x]+=y;
	for(int i=0;i<s[x].size();i++){
		if(flag[s[x][i]]) continue;
		flag[s[x][i]]=1;
		dfs(s[x][i],a[x]);
	}
}
void input(){
	cin>>n>>m;
	for(int i=1;i<n;i++){
		cin>>u>>v;
		s[u].push_back(v);
		s[v].push_back(u);
	}
	memset(flag,0,sizeof(flag));
	for(int i=1;i<=m;i++){
		cin>>u>>v;
		a[u]+=v;
	}
}
void output(){
	memset(flag,0,sizeof(flag));
	flag[1]=1;
	dfs(1,0);
	cout<<a[1];
	for(int i=2;i<=n;i++) cout<<" "<<a[i];
}
signed main(){
	input();
	output();
}

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

int main(void){
        int n;
        char a[110], b[110], c[250];

        scanf("%d", &n);
        scanf("%s%s", a, b);
        
        int x=0;
        for(int i=0;i<n;i++){
                c[x]=a[i];
                c[x+1]=b[i];
              //  printf("%c%c\n", c[x],c[x+1]);
                x=x+2;
        }
        for(int i=0;i<2*n;i++){
                printf("%c", c[i]);
        }
        printf("\n");
        return 0;
}


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

using namespace std;

int main(){
	int n;
	string s, t;
	cin>>n;
	cin>>s>>t;
	int m=n*2;
	for(int i=1; i<=n; i++){
		bool flag=true;
		for(int j=0; j<i; j++){
			if(s[n-i+j]!=t[j]){
				flag=false;
				break;
			}
		}
		if(flag){
			if(m>2*n-i){
				m=2*n-i;
			}
		}
	}
	cout<<m<<endl;
	
	return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int)s.size();
  vector<int> rl, lr;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R' && s[i + 1] == 'L') {
      rl.emplace_back(i);
    } else if (s[i] == 'L' && s[i + 1] == 'R') {
      lr.emplace_back(i);
    }
  }
  int nrl = (int)rl.size();
  vector<int> ans(n, 0);
  lr.insert(lr.begin(), -1);
  lr.emplace_back(n - 1);
  for (int i = 0; i < nrl; i++) {
    ans[rl[i]] += (rl[i] - lr[i] + 1) / 2;
    ans[rl[i] + 1] += (rl[i] - lr[i]) / 2;
    ans[rl[i]] += (lr[i + 1] - rl[i]) / 2;
    ans[rl[i] + 1] += (lr[i + 1] - rl[i] + 1) / 2;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << ' ';
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 1612
n,a,b,*p=`dd`.split.map &:to_i
x=y=z=0
p.each{|e|
    if e<=a
        x+=1
    elsif a+1<=e && e<=b
        y+=1
    elsif e>=b+1
        z+=1
    end
}

puts [x, y, z].min


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <array>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <vector>
using namespace std;
template<typename Itr>
auto merge(Itr first1, const Itr last1, Itr first2, const Itr last2, Itr result){
  Itr cpyresult=result;
  size_t ret=0;
  for(Itr cpyfirst1=first1;; ++cpyresult){
    if(cpyfirst1==last1){
      //
      for(; first2!=last2; ++first2,++cpyresult) *cpyresult=*first2;
      break;
    }
    if(first2==last2){
      //
      for(; cpyfirst1!=last1; ++cpyfirst1,++cpyresult) *cpyresult=*cpyfirst1;
      break;
    }
    if(*cpyfirst1<=*first2){
      *cpyresult=*cpyfirst1;
      ++cpyfirst1;
    } else{
      ret+=last1-cpyfirst1; //
      *cpyresult=*first2;
      ++first2;
    }
  }
  for(; result!=cpyresult; ++first1,++result) *first1=*result;
  return ret;
}
template<typename Itr>
size_t mergeSort(Itr first, Itr last, Itr result){
  if(last-first>1){
    Itr mid=first+(last-first)/2;
    size_t ret=0;
    ret+=mergeSort(first, mid, result);
    ret+=mergeSort(mid, last, result);
    return ret+merge(first, mid, mid, last, result);
  } else return 0;
}
int32_t main(){
  size_t n; cin>>n;
  vector<uint32_t> s(n),t(n); for(auto&& e:s) cin>>e;
  const size_t c=mergeSort(begin(s), end(s), begin(t));
  cout<<c<<'\n';
}


Measured memory_bytes: 4332
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int N, A[200001], tmp;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    int *res = new int[N];
    for (int i = 1; i < N; i++) cin >> tmp, A[i] = tmp, res[tmp - 1]++;
    for (int i = 0; i < N; i++) cout << res[i] << " ";

    return 0;
}

Measured memory_bytes: 5224
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);
  for (int i = 0; i < N - 1; i++) {
    if (A[i] == A[i + 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1024
import sys
S = input()

n = len(S)

if S == S[::-1]:
  a = (n-1)//2
  b = (n+1)//2
  s1 = S[0:a]
  s2 = S[b:n]
  if s1 == s1[::-1] and s2 == s2[::-1]:
    print("Yes")
    sys.exit()
print("No")

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

vector<P>prime_factorize(ll n) {
    vector<P> res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
  ll n;
  int ans = 0;
  cin >> n;
  vector<P>data = prime_factorize(n);
  rep(i,0,data.size()){
    int t = data[i].second;
    int c = 1;
    while(true){
      if(t-c < 0) break;
      ans++;
      t -= c;
      c++;
    }
  }
  cout << ans << endl;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

char a,b;

main() {
    cin >> a >> b;
    if (a==b) ct("H")
    else ct("D")
}




Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {//階乗、その逆元も存在する。
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(500005);//100005まで計算（どこまで必要かで変更）
int main() {
int N,M;
cin>>N>>M;
mint ans=0;
rep(i,N+1){
    if(i%2==0){
        ans+=comb(N,i)*comb.fact[M]*comb.ifact[M-i]*(comb.fact[M-i]*comb.ifact[M-N]).pow(2);
    }
    else{
        ans-=comb(N,i)*comb.fact[M]*comb.ifact[M-i]*(comb.fact[M-i]*comb.ifact[M-N]).pow(2);
    }
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 10960
from itertools import product
s=input()
y=["0","1","2","3","4","5","6","7","8","9"]
yy=list((x+y for x,y in product(y,repeat=2)))
mm=["01","02","03","04","05","06","07","08","09","10","11","12"]

ans="NA"
if (s[0:2] in yy and s[2:4] in mm) and (s[0:2] not in mm or  s[2:4]  not in yy):
    ans="YYMM"
elif (s[0:2] in mm and s[2:4] in yy) and (s[0:2] not in yy or  s[2:4]  not in mm):
    ans="MMYY"
elif (s[0:2] in mm and s[2:4] in yy) and (s[0:2] in yy or  s[2:4]  in mm):
    ans="AMBIGUOUS"

print(ans)

Measured memory_bytes: 9044
# -*- coding: utf-8 -*-

N = int(input())
S = [0] * N
for i in range(N):
    S[i] = input()

lst = ['AC', 'WA', 'TLE', 'RE']
ans = [0, 0, 0, 0]

for i in range(N):
    ans[lst.index(S[i])] += 1

for s, a in zip(lst, ans):
    print(s, 'x', a)


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

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

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

  long min = 1000001;
  long max = -1000001;
  long sum = 0;
  for(int j=0;j<n;j++){
    if(t[j]<min) min = t[j];
    if(t[j]>max) max = t[j];
    sum += t[j];
  }

  cout << min << " " << max << " " << sum << endl;
  
  return 0;
}

Measured memory_bytes: 1244
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a,const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
    int n;
    scanf("%d",&n);
    int ar[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&ar[i]);
    }
    qsort(ar,n,sizeof(int),cmp);
    int ans = ar[n/2] -ar[n/2 -1];
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 892
#!/usr/bin/env python
# -*- coding: utf-8 -*-
s = list(input())
n = len(s)
p = 2019

ans = 0
d = [0] * (n + 1)
ten = 1
for i in range(n - 1, -1, -1):
    a = int(s[i]) * ten % p
    ten *= 10
    ten %= p
    d[i - 1] = (d[i] + a) % p
cnt = [0] * p
for i in range(n, -1, -1):
    ans += cnt[d[i]]
    cnt[d[i]] += 1
print(ans)

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

string S;
int K;

int main () {
    cin >> K >> S;
    if(S.size() <= K) cout << S << endl;
    else {
        for(int i=0;i<K;i++) cout << S[i] ;
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
from bisect import bisect_right
from itertools import accumulate

N,M,K = map(int,input().split())
A = [0]+list(accumulate(map(int,input().split())))
B = [0]+list(accumulate(map(int,input().split())))
ans = [0]

for n in range(1+N):
  C = bisect_right(B,K-A[n])-1
  if C!=-1:
    ans.append(C+n)

print(max(ans))

Measured memory_bytes: 48388
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <utility>
#include <queue>
#define inf 1000000000

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> State;
typedef pair<int, State> QState;

struct edge{
	int to, cost;
	edge(){}
	edge(int a, int b){
		to = a, cost = b;
	}
};

int sx, sy, gx, gy;
int n;
int map[305][305];
int Zero = 150;
int lx, ly;
int dist[305][305][6];

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

void dijkstra()
{
	for(int x = -lx; x <= lx; x++){
		for(int y = -ly; y <= ly; y++){
			for(int t = 0; t < 6; t++){
				dist[Zero+x][Zero+y][t] = inf;
			}
		}
	}
	dist[Zero+sx][Zero+sy][0] = 0;
	
	priority_queue<QState, vector<QState>, greater<QState> > Q;
	Q.push(make_pair(0, make_pair(make_pair(sx, sy), 0)));
	
	int x, y, t, d, nd;
	int nx, ny, nt;
	while(Q.size()){
		d = Q.top().first;
		x = Q.top().second.first.first;
		y = Q.top().second.first.second;
		t = Q.top().second.second;
		Q.pop();
		if(dist[Zero+x][Zero+y][t] < d) continue;
		for(int i = 0; i < 7; i++){
			int nx = x, ny = y, nt = (t+1)%6;
			if(abs(x)%2==0) nx += dx[i], ny += dy[i];
			else nx += dx2[i], ny += dy2[i];
			if(abs(nx) > lx || abs(ny) > ly) continue;
			if(map[Zero+nx][Zero+ny]) continue;
			nd = d;
			if(i != abs(x * y * t) % 6) nd++;
			if(dist[Zero+nx][Zero+ny][nt] > nd){
				dist[Zero+nx][Zero+ny][nt] = nd;
				Q.push(make_pair(nd, make_pair(make_pair(nx, ny), nt)));
			}
		}
	}
}


int main(void)
{
	cin >> sx >> sy >> gx >> gy;
	cin >> n;
	int x, y;
	for(int i = 0; i < n; i++){
		cin >> x >> y;
		map[Zero+x][Zero+y] = 1;
	}
	cin >> lx >> ly;
	
	dijkstra();
	
	int ans = inf;
	for(int i = 0; i < 6; i++) ans = min(ans, dist[Zero+gx][Zero+gy][i]);
	if(ans >= inf) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4632
#include <string>
#include <iostream>
#include <vector>

//binary search to get the left and right boundary separately
using namespace std;
int main()
{
	int N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	vector<char> t(Q);
	vector<char> d(Q);
	for(int i = 0; i < Q; i += 1)
	{
		cin >> t[i] >> d[i];
	}

	int L = -1;
	int left = 0, right = N - 1;
	while(left <= right)
	{
		int mid = (left + right) >> 1;
		int inx = mid;
		for(int i = 0; i < Q; i += 1)
		{
			if(s[inx] == t[i])
			{
				if(d[i] == 'L')
					inx -= 1;
				else
					inx += 1;
			}
			if(inx < 0 || inx > N - 1) break;
		}

		if(inx < 0)
		{
			L = mid;
			left = mid + 1;
		}
		else
			right = mid - 1;
	}

	int R = N; 
	left = 0, right = N - 1;
	while(left <= right)
	{
		int mid = (left + right) >> 1;
		int inx = mid;
		for(int i = 0; i < Q; i += 1)
		{
			if(s[inx] == t[i])
			{
				if(d[i] == 'R')
					inx += 1;
				else
					inx -= 1;
			}
			if(inx < 0 || inx > N - 1) break;
		}

		if(inx > N - 1)
		{
			R = mid;
			right = mid - 1;
		}
		else
			left = mid + 1;
	}

	std::cout << std::to_string(R - L - 1) << std::endl;

	return 0;
}



Measured memory_bytes: 900
# コンビネーション
mod = 998244353
def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NN = 10**6 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, M, K = map(int, input().split())
ans = 0
for l in range(K+1):
    ans = (ans + cmb(N-1, l)*M*pow(M-1, N-l-1, mod)) % mod
print(ans)

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

    int main (){
        int s;
        cin >> s;
        set<int> st;
        int x = s;
        while(st.count(x)==0){
           st.insert(x);
            if(x%2==0){
                x/=2;
            }
            else{
                x=x*3+1;
            }
            }

        cout << st.size()+1 << endl;
        return 0;

        }

Measured memory_bytes: 3592
class UF():
  def __init__(self, N):
    self._parent=[n for n in range(0, N)]
    self._size=[1] * N

  def find_root(self, x):
    if self._parent[x]==x:return x
    self._parent[x]=self.find_root(self._parent[x])
    return self._parent[x]

  def unite(self, x, y):
    gx=self.find_root(x)
    gy=self.find_root(y)
    if gx==gy:return

    if self._size[gx]<self._size[gy]:
      self._parent[gx]=gy
      self._size[gy]+=self._size[gx]
    else:
      self._parent[gy]=gx
      self._size[gx]+=self._size[gy]

  def size(self, x):
    return self._size[self.find_root(x)]

  def samegroup(self, x, y):
    return self.find_root(x)==self.find_root(y)

  def groupnum(self):
    N=len(self._parent)
    ans=0
    for i in range(N):
      if self.find_root(i)==i:
        ans+=1
    return ans

  def reset(self):
    self._parent=[n for n in range(0, n)]

n=int(input())
UF=UF(n)
l=[list(map(int,input().split())) for i in range(n)]
if n==1:
  print(1)
else:
  ans=[]
  for i in range(n):
    x1=l[i][0]
    y1=l[i][1]
    for j in range(n):
      if i!=j:
        x2=l[j][0]
        y2=l[j][1]
        p=x1-x2
        q=y1-y2
        for k1 in range(n):
          for k2 in range(n):
            if k1!=k2:
              if (l[k1][0]-p==l[k2][0] and l[k1][1]-q==l[k2][1]) or (l[k1][0]+p==l[k2][0] and l[k1][1]+q==l[k2][1]):
                UF.unite(k1,k2)
        ans.append(UF.groupnum())
        UF.reset()
  print(min(ans))

Measured memory_bytes: 79836