akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

vector<ll> ret(MAX);

//素因数分解行列作成
void prime_factor(ll N){
  ll i;
  for(i=2;i*i<=N;i++){
    while(N%i==0){
      ret[i]++;
      N/=i;
    }
  }
  if(N!=1) ret[N]++;
}


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

  repn(i,N) prime_factor(i);

  ll ans = 1;

  repn(i,N){
    ans *= ret[i] + 1;
    ans %= MOD;
  }


  cout<<ans<<endl;
}


Measured memory_bytes: 4224
#include <iostream>
using namespace std;
int main(){
    
    int N ;
    cin >> N ;
    
    char Suit[N] ;
    int Rank[N] ;
    
    for(int i = 1 ; i <= N ; i++){
        cin >> Suit[i] >> Rank[i] ;
    }
    
    for(int j = 1 ; j <= 13 ; j++){
        int a= 0 ;
        for(int k = 1 ; k <= N ; k++){
            if((Suit[k] == 'S')&&(Rank[k] == j)){
                a = a + 1 ;
            }
        }
        if(a == 0){
            cout << "S" << " " << j << endl ;
        }
    }
    
    for(int j = 1 ; j <= 13 ; j++){
        int a= 0 ;
        for(int k = 1 ; k <= N ; k++){
            if((Suit[k] == 'H')&&(Rank[k] == j)){
                a = a + 1 ;
            }
        }
        if(a == 0){
            cout << "H" << " " << j << endl ;
        }
    }
    
    for(int j = 1 ; j <= 13 ; j++){
        int a= 0 ;
        for(int k = 1 ; k <= N ; k++){
            if((Suit[k] == 'C')&&(Rank[k] == j)){
                a = a + 1 ;
            }
        }
        if(a == 0){
            cout << "C" << " " << j << endl ;
        }
    }
    
    for(int j = 1 ; j <= 13 ; j++){
        int a= 0 ;
        for(int k = 1 ; k <= N ; k++){
            if((Suit[k] == 'D')&&(Rank[k] == j)){
                a = a + 1 ;
            }
        }
        if(a == 0){
            cout << "D" << " " << j << endl ;
        }
    }
    
    
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
lli n,k;

lli calc(lli arr[],lli ind,lli memo[])
{
    if(ind >= (n-1))
        return 0;
    if(memo[ind] != -1)
        return memo[ind];
    lli res = INT_MAX;
    for(lli i=1;i<=k;i++)
    {
        if(ind+i < n)
        {
            res = min(res,abs(arr[ind] - arr[ind+i]) + calc(arr,ind+i,memo));
        }
    }
    memo[ind] = res;
    return res;
}

int main()
{
    cin>>n;
    k = 2;
    lli arr[n];
    lli memo[n];
    for(lli i=0;i<n;i++)
    {
        memo[i] = -1;
        cin>>arr[i];
    }
    memo[n-1] = 0;
    cout<<calc(arr,0,memo)<<endl;
}


Measured memory_bytes: 9600
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef int_fast64_t ll;

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    constexpr ModFact() : fact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
    }
};
 
ModFact<100000, ll, MOD> fact;

ll ans;
int N, M, cnt = 0;
constexpr ll th = 1LL<<45;
char S[200000];

int main() {
    scanf("%d\n", &N);
    M = N << 1;
    fread_unlocked(S, 1, M, stdin);
    ans = fact.fact[N];
	for(size_t i = 0; i < M;) {
		if((S[i++]^cnt)&1) {
            ans *= cnt;
            if(ans > th) ans %= MOD;
            if(--cnt < 0) break;
        } else ++cnt;
	}
    printf("%lld\n", cnt == 0 ? ans % MOD : 0);
    return 0;
}


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

using namespace std;
const int MAXN = 1e5 + 7;

bool vis[MAXN];
int dp[MAXN];
vector<int> adj[MAXN];

int dfs(int u) {
  int &ans = dp[u];
  if (~ans) return ans;
  vis[u] = true;
  ans = 0;
  for (auto v : adj[u]) {
    ans = max(ans, dfs(v) + 1);
  }
  return ans;
}

int main() {
  memset(dp, -1, sizeof(dp));
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if(!vis[i]) {
      dfs(i);
    }
    ans = max(ans, dp[i]);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = 2019;
const int MAX_S = 200005;
ll le[MAX_S],ri[MAX_S]; //左からor右から何桁かとってMODで割ったあまり
ll cntl[2025],cntr[2025];

ll pow10(int n)
{
	if (n == 0) return ll(1);
	if (n == 1) return ll(10);
	if (n % 2 == 0)
	{
		ll p = pow10(n/2);
		return p * p % MOD;
	}
	else
	{
		return 10 * pow10(n-1) % MOD;
	}
}

int main()
{
	string S;
	cin >> S;
	int N = S.size();
	ll ans = 0;
	cntr[0]++;
	rep(i,N)
	{
		//left[i+1] = (left[i] * 10 + (S[i] - '0')) % MOD;
		ri[i+1] = (ri[i] + (S[N-1-i] - '0') * pow10(i+1) % MOD) % MOD;
		ans += cntr[ri[i+1]];
		cntr[ri[i+1]]++;
		//cout << ri[i+1] << " ";
	}
	//cout << endl;
	cout << ans << endl;
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  for (int i=0; i<W+2; i++) {
    cout << '#';
    if (i<W+1){
      continue;
    }
    cout << endl;
  }
  
  for (int i=0; i<H; i++) {
    string a;
    cin >> a;
    cout << '#' << a << '#' << endl;
  }
  
  for (int i=0; i<W+2; i++) {
    cout << '#';
    if (i<W+1){
      continue;
    }
    cout << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <iomanip>

using namespace std;

const int MAX_N = 3003;
double probability_heads[MAX_N][MAX_N], probability[MAX_N];

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

    for(int i = 1; i <= no_of_coins; i++)
        cin >> probability[i];

    memset(probability_heads, 0, sizeof(probability_heads));
    probability_heads[0][0] = 1;

    for(int i = 1; i <= no_of_coins; i++)
    {
        double head_event = probability[i], tail_event = 1 - probability[i];

        probability_heads[0][i] = tail_event*probability_heads[0][i - 1];

        for(int heads = 1; heads <= i; heads++)
        {
            probability_heads[heads][i] = head_event*probability_heads[heads - 1][i - 1] + tail_event*probability_heads[heads][i - 1];
        }
    }

    double answer = 0;
    for(int i = no_of_coins/2 + 1; i <= no_of_coins; i++)
        answer += probability_heads[i][no_of_coins];

    cout << setprecision(9) << answer;
    return 0;
}

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

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

  ll N; cin >> N;
  ll K; cin >> K;
  vector<ll> A(N + 105, 1e15); for (ll i = 0; i < N; i++) cin >> A[i];
  vector<ll> dp(N + 105, 1e15);
  dp[0] = 0;
  for (ll i = 0; i < N; i++) {
    for (ll j = 1; j < K + 1; j++) {
      dp[i + j] = min(dp[i + j], dp[i] + abs(A[i + j] - A[i]));
    }
  }
  cout << dp[N - 1] << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r;
    std::cin >> r;
    if(r < 1200){
        std::cout << "ABC" << std::endl;
    } else if(r < 2800){
        std::cout << "ARC" << std::endl;
    } else {
        std::cout << "AGC" << std::endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

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

char S[4];

int main()
{
  int cnt;
  int i;
  int bmap1 = 0;
  int bmap2 = 0;
  int i2=0xF;
  int cnt1 = 0;
  int cnt2 = 0;
  
  cnt = scanf("%s", &S);

  bmap1 = 1;
  cnt1++;
  for(i=1; i<4; i++) {
    if (S[0] == S[i]) {
      bmap1 |= (1 << i);
      cnt1++;
    }
  }
  if (cnt1 > 2) {
    printf("No");
    return 0;
  }
  for(i=0; i<4; i++) {
    if (bmap1 & (1 << i)) continue;

    if (i2 == 0xF) {
      i2=i;
      bmap2 |= (1 << i);
      continue;
    }
    if (S[i] == S[i2]) {
      bmap2 |= (1 << i);
      cnt2++;
    }
  }
  if (cnt2 > 2) {
    printf("No");
    return 0;
  }

  if (0xF == (bmap1 | bmap2)) {
    printf("Yes");
    return 0;
  }
  
  printf("No");
  return 0;
}



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

int main() {
    int K,X;
    cin >> K >> X;
    vector<int> A(K*2-1);
    for(int i=0;i<K*2-1;i++){
        A.at(i)=X-K+1+i;
        if(i!=K*2-2)cout << A.at(i) << " ";
        else cout << A.at(i) << endl;
    }    
}


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

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

  long long a, b;
  cin >> a >> b;
  cout << max(a-b-b, 0ll) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

ll com[51][51];

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

    com[0][0]=1;
    for (int i=1;i < 51;i++){
        for (int j=0;j <= i;j++){
            com[i][j]+=com[i-1][j];
            if (j > 0) com[i][j]+=com[i-1][j-1];
        }
    }
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    sort(v.begin(),v.end(),greater<ll>());

    ll sum=0;
    for (int i=0;i < a;i++) sum+=v[i];
    double ave = double(sum)/a;

    ll res=0;
    int num=0;
    for (int i=0;i <n;i++) if (v[i]==v[a-1]) num++;
    if (v[0] == v[a-1]){
        for (int j=a;j <= b;j++) res+=com[num][j];
    }
    else {
        int ta=0;
        for (int h=0;h < a;h++) if (v[h]==v[a-1]) ta++;
        res+=com[num][ta];
    }
    printf("%.8f\n",ave);
    cout << res << endl;
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int K; cin >> K;
    string S; cin >> S;
    int N = S.size();
    if(N <= K) cout << S << en;
    else{
        cout << S.substr(0,K) << "..." << en;
    }
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t = 1; //cin >> t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long n;
int main() {
    cin >> n;
    vector<long long> ain(n, 0);
    vector<long long> a(n, 0);
    vector<long long> asum(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> a.at(i);
        a.at(i)--;
        ain.at(a.at(i))++;
    }
    
    long long sum = 0;
    for(int i = 0; i < n; ++i) {
        long long ind = ain.at(i);
        // cout << ind << endl;
        asum.at(i) = (ind*(ind-1)) / 2;
        sum += asum.at(i);
    }

    for(int i = 0; i < n; ++i) {
        long long tugi = ain.at(a.at(i))-1;
        // cout << tugi << endl;
        long long ans = sum;
        ans -= asum.at(a.at(i));
        ans += (tugi*(tugi-1)) /2;
        cout << ans << endl;
    }
}

Measured memory_bytes: 7296
N = input()
L = []
S = 0
for i in range(len(N)):
  L.append(int(N[i]))
for i in range(len(N)):
  S += (sum(L[0:i])*(2**(i-1))+L[i]*(2**i))*(10**(len(N)-i-1))
print(int(S))

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

using namespace std;

template <typename T> struct SegTree { /* {{{ */
  using F = function<T(T, T)>;

  int n;
  vector<T> node;
  const F f;
  const T init_val;

  SegTree(int size, const T init_val, const F f) : SegTree(size, vector<T>(), init_val, f) {}
  SegTree(const vector<T> &v, const T init_val, const F f) : SegTree(v.size(), v, init_val, f) {}
  SegTree(int size, const vector<T> &v, const T init_val, const F f) : init_val(init_val), f(f) {
    n = 1;
    while (n < size) n *= 2;
    node.assign(n * 2, init_val);
    if (!v.empty()) {
      for (int i = 0; i < v.size(); i++) {
        node[i + n] = v[i];
      }
      for (int i = n * 2 - 1; i >= 0; i--) {
        node[i] = f(node[i * 2], node[i * 2 + 1]);
      }
    }
  }
  void update(int idx, T v) {
    node[idx + n] = v;
    for (int i = (idx + n) / 2; i >= 1; i /= 2) {
      node[i] = f(node[i * 2], node[i * 2 + 1]);
    }
  }
  T search(int a, int b, int k = 1, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a or b <= l) return init_val;
    if (a <= l and r <= b) return node[k];
    auto vl = search(a, b, k * 2, l, (l + r) / 2);
    auto vr = search(a, b, k * 2 + 1, (l + r) / 2, r);
    return f(vl, vr);
  }
}; /* }}} */

int main() {
  int N;
  cin >> N;
  vector<long long> H(N), A(N);
  for (auto &h : H) cin >> h;
  for (auto &a : A) cin >> a;
  SegTree<long long> st(N + 1, 0, [](long long a, long long b) { return max(a, b); });
  for (int i = 0; i < N; i++) {
    auto v = st.search(0, H[i]);
    st.update(H[i], v + A[i]);
  }
  auto ans = st.search(0, N + 1);
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 7424
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	ll x;
  cin>>x; x;
	vector<int> dp(x+1000);
	dp[0]=1;
	rep(i,x+10)if(dp[i]){
		rep(j,6) dp[i+100+j]=1;
	}
	cout<<!!dp[x] NL;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    double w,h,x,y,answer;
    cin >>w>>h>>x>>y;

    answer=(h*w)*0.5;

    if(x==w*0.5&&y==h*0.5){
        cout<<answer <<" 1" <<endl;
    }
    else {
        cout<<answer <<" 0" <<endl;
    }
}


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

int main(){
	int a=0,b=0,c=0;
	int e[3];
	while(scanf("%d%d%d", &e[0], &e[1], &e[2]) != EOF){
		sort(e, e+3);
		if(e[2] >= e[1]+e[0]) break;
		if(e[2]*e[2] == e[0]*e[0] +e[1]*e[1]) a++;
		if(e[2]*e[2] < e[0]*e[0] +e[1]*e[1]) b++;
		if(e[2]*e[2] > e[0]*e[0] +e[1]*e[1]) c++;
	}
	printf("%d %d %d %d\n", a+b+c, a, b, c);
	return 0;
}


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

int main(void) {
    char s[100];
    char p[100];
    char ring[200];
    
    cin >> s >> p;
    
    strcpy(ring, s);
    strcat(ring, s);
    
    if(strstr(ring, p)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=2e5+1;
ll getans(ll X)
{
	if(X==1)
	{
		return 3e5;
	}
	else if(X==2)
	{
		return 2e5;
	}
	else if(X==3)
	{
		return 1e5;
	}
	else return 0;
}
void solve()
{
	ll X,Y;
	cin>>X>>Y;
	ll ans=0;
	if(X==1&&Y==1)
	{
		ans+=4e5;
	}
	ans+=getans(X)+getans(Y);
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
int a, p;
void solve() {
    cin >> a >> p;
    cout << ((a * 3) + p) / 2 << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

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

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

const int N = 21;

int h, w, res;
char G[N][N];
bool visited[N][N];

void bfs(int i, int j) {
  memset(visited, 0, sizeof visited);
  vector<ii> dxy = {{1,0},{-1,0},{0,1},{0,-1}};
  vector<ii> cur = {{i, j}};
  vector<ii> next;
  visited[i][j] = true;
  int dist = 0;
  while (true) {
    for (auto p1 : cur) {
      int x = p1.first, y = p1.second;
      for (auto p2 : dxy) {
        int dx = p2.first, dy = p2.second;
        int nx = x + dx, ny = y + dy;
        if (nx < 0 || ny < 0 || nx == h || ny == w || visited[nx][ny]) continue;
        if (G[nx][ny] == '.') {
          visited[nx][ny] = true;
          next.push_back({nx,ny});
        }
      }
    }
    if (next.empty()) break;
    dist++;
    swap(cur, next);
    next.clear();
  }
  res = max(res, dist);
}

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

  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> G[i][j];
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (G[i][j] == '.') {
        bfs(i, j);
      }
    }
  }
  cout << res << endl;

  return 0;
}


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

int main(){
	double v, t;
	int n;
	while(cin >> v){
	n = 0;
	for(int i = 0; 4.9*(v/9.8)*(v/9.8) > 5*i-5 ; i++){
		n++;
	}
	cout << n << endl;
	}
}

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

int main(){
    int N, a, M = 0, b, i, j, num1 = 0, group;

    cin >> N;
    int array[N], out[N], boul[N];
    for(i = 0; i < N; i++){
        cin >> a;
        array[i] = a;
        out[i] = 0;
    }
    for(i = 0; i < N; i++){
        num1 = 0;
        group = N / (N-i);
        for(j = 0; j < group; j++){
            if(out[(j+1) * (N-i) - 1] == 1){
                num1++;
            }
        }
        if(array[N-i-1] != num1 % 2){
            out[N-i-1] = 1;
            boul[M] = N - i;
            M++;
        }
    }
    cout << M << endl;
    for(i = 0; i < M; i++){
        printf("%d", boul[i]);
        if(i != M - 1)printf(" ");
        else printf("\n");
    }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll n,k;
  cin>>n>>k;
  vector<ll> freq(k);
  for(int i=1; i<=n;i++) {
    freq[i%k]++;
  }
  ll ans=0;
  rep(a,k) {
    ll b = (k-a)%k;
    ll c = a;
    if((a+c)%k==0) {
      ans+=freq[a]*freq[b]*freq[c];
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  long X;
  cin >> X;
  for (long i = -500; i <= 500; i++) {
    for (long j = -500; j <= 500; j++) {
      if (pow(i, 5) - pow(j, 5) == X) {
        return cout << i << " " << j << "\n", 0;
      }
    }
  }
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main()
{
	ll n, m; cin >> n >> m;
	
	vector<bool> canNum(n + 1,true);
	for (int i = 0; i < m; i++) {
		int a; cin >> a;
		canNum[a] = false;
	}


	vector<ll> dp(n + 1, 0);
	dp[0] = 1;
	if(canNum[1]) dp[1] = 1;
	for (int i = 2; i <= n; ++i) {
		if (canNum[i]) {
			dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
		}
		else {
			dp[i] = 0;
		}
	}

	cout << dp[n] % mod << endl;
	return 0;
}

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

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }


signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;

    return 0;
}


Measured memory_bytes: 3636
n = int(input())
a_list = [int(input()) for _ in range(n)]

a_max = max(a_list)
a_max_list = [i for i, v in enumerate(a_list) if v == a_max]

if len(a_max_list) == 1:
  a_max_2 = sorted(set(a_list))[-2]
  for i in range(n):
    if i in a_max_list:
      print(a_max_2)
    else:
      print(a_max)
else:
  for i in range(n):
    print(a_max)

Measured memory_bytes: 20452
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b,c;
cin >> a >> b >> c;
if(a*b<c) {
  cout << a*b << endl;
} else {
  cout << c << endl;
}
return 0;
}


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


int main(){
    int n; cin >> n;
    vector<string> S(n);
    rep(i,n){
        string s; cin >> s;
        S[i] = s;
    }

    map<char,int> mp;
    for(char c = 'a';c<='z';c++){
        int mi=1010;
        rep(i,n){
            int cnt = 0;
            rep(j,S[i].size()){
                if(S[i][j]==c) cnt++;
            }
            mi = min(mi, cnt);
        }
        mp[c] = mi;
    }

    for(auto it : mp){
        rep(i,it.second) cout << it.first;
    }
    cout << endl;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc = new FastReader();
		int N = sc.nextInt(), W = sc.nextInt();
		int[] w = new int[N], v = new int[N]; 
		long[] dp = new long[W+10];
		for (int i=0; i<N; i++) {
			w[i] = sc.nextInt(); 
			v[i] = sc.nextInt(); 
		}
		Arrays.fill(dp, -(1L<<60));
		dp[0] = 0; 
		long ans = 0; 
		for (int i=0; i<N; i++) {
			for (int j=W; j>=w[i]; j--) {
				if (dp[j-w[i]]+v[i]>dp[j]) {
					dp[j] = dp[j-w[i]]+v[i]; 
					ans = Math.max(ans, dp[j]); 
				}
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#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")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,a[10],ans = 1,tmp = 1;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		ans *= 3;
		if(a[i] % 2 == 0) tmp *= 2;
	}
	cout << ans - tmp << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,Q;
  cin >> N>>Q;
  string S;
  cin >>S;
  int count[N];
  count[0]=0;
  for(int i=1;i<N;i++){
    if((S.at(i-1)=='A')&&(S.at(i)=='C')){
      count[i]=count[i-1]+1;
    }
    else count[i]=count[i-1];
  }
  int l,r;
  for (int i=0;i<Q;i++){
    cin>>l>>r;
    cout<<count[r-1]-count[l-1]<<endl;
  }
   return 0;
}


Measured memory_bytes: 1408
#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, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, s;
	cin >> n >> s;
	if (n < s) {
		cout << -1 << endl; return 0;
	}
	else if (n == s) {
		cout << n + 1 << endl; return 0;
	}
	ll a = n - s;
	auto check = [&](ll i) {
		ll sum = 0;
		ll tmp = n;
		while (tmp > 0) {
			sum += tmp % i;
			tmp /= i;
		}
		return sum == s;
	};
	ll ans = INF * INF;
	for (ll i = 1; i*i <= a; ++i) {
		if (a%i == 0) {
			if (check(i + 1))chmin(ans, i + 1);
			if (check(a / i + 1))chmin(ans, a / i + 1);
		}
	}
	if (ans == INF * INF)cout << -1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int dp[n];
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        ll ret1=INT_MAX;
        for(int j=1;j<=min(k,i);j++)
        {
            ll ret2=dp[i-j]+fabs(arr[i]-arr[i-j]);
            ret1=min(ret2,ret1);
        }
        dp[i]=ret1;
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 4408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] b = new int[n-1];
		for(int i=0;i<n-1;i++) b[i] = in.nextInt();
		int ans = b[0] + b[n-2];
		for(int i=1;i<n-1;i++) {
			ans += Math.min(b[i-1], b[i]);
		}
		System.out.print(ans);
		in.close();

	}

}


Measured memory_bytes: 22612
import decimal
def ncr(x,y):
	ans=1
	q=x-y
	while x>y:
		ans*=x
		x=x-1
	
	while q>1:
		ans=ans/q
		q=q-1
	
	return ans

x=input().split()
n=int(x[0])
a=int(x[1])
b=int(x[2])
v=[0]*n
x = input().split()
ind=0
M={1:0}
M2={1:0}
for i in x:
	v[ind]=int(i)
	if int(i) in M:
		M[v[ind]]+=1
	else:
		M[v[ind]]=1
	ind+=1
v.sort(reverse=True)

cnt=0
ind=0
m=0
while cnt<a:
	cnt+=1
	m=decimal.Decimal((cnt-1)*m+v[ind])/decimal.Decimal(cnt)
	if v[ind] in M2:
		M2[v[ind]]+=1
	else:
		M2[v[ind]]=1
	ind+=1
while cnt<b:
	if (cnt*m+v[ind])/(cnt+1)<m:
		break
	else:
		cnt+=1;
		if v[ind] in M2:
			M2[v[ind]]+=1
		else:
			M2[v[ind]]=1
		ind+=1
print(m)
maxw=cnt;
ways=0;
for i in range(int(cnt),a-1,-1):
	if v[ind-1] not in M2:
			M2[v[ind]]=0
	if v[ind-1] not in M:
			M[v[ind-1]]=0
	#print(M[v[ind-1]],M2[v[ind-1]])
	ways+=ncr(M[v[ind-1]],M2[v[ind-1]])
	
	M2[v[ind-1]]-=1

print(round(ways))
	

Measured memory_bytes: 5076
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);

    int x , y;

   while(true){

     x = scan.nextInt();

     y = scan.nextInt();

  if(x == 0&&y ==0)break;

  if(x<y){
      System.out.println(x+" "+y);
   } else if(x>y){
      System.out.println(y+" "+x);
   } else if(x==y){
      System.out.println(x+" "+y);
   }
  }
  }
}


Measured memory_bytes: 35416
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
  if(a % b == 0)return b;
  else{
     return(gcd(b,a% b));
  }
}
int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> m(n);
  for(int i = 0;i < n;i++){
    cin >> m[i];
  }
  sort(m.begin(),m.end());
  if(n == 1){
    if(m[0] == k)cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  if(m[0] == k){
    cout << "POSSIBLE" << endl;
    return 0;
  }
  ll now = 0;
  //now = m[1] - m[0];
  now = m[0];
  for(int i = 1;i < n - 1;i++){
    //int memo = m[i + 1]  - m[i];
    //if(memo == 0)continue;
    //now = gcd(now,memo);
    now = gcd(now,m[i]);
    if(m[i] == k){
    cout << "POSSIBLE" << endl;
    return 0;
    }
  }
  if(k > m[m.size() - 1] || k % now != 0){
    cout << "IMPOSSIBLE" << endl;
  }
  else{
    cout << "POSSIBLE" << endl;
  }
  //cout << now << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str0[16];
char str1[16];

void solve()
{
    ll a, b, c, K;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &K);
    if (K <= a) {
        printf("%lld\n", K);
    }
    else if (K <= a + b) {
        printf("%lld\n", a);
    }
    else {
        printf("%lld\n", a - (K - a - b));
    }


    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


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

int main(){

  long long N, K;
  cin >> N >> K;
  
  long long mod = 1000000007;
  
  long long cnt = 0;
  
  for(long long i = K; i <= N+1; i++){
    cnt += (i*(N-i+1)+1) % mod ;
    cnt %= mod;
  }
  
  cout << cnt << endl;

}
 


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

int main() {
	string s;
	cin >> s;
	int count[3] = {0};
	for (int i = 0; i < 3; i++) {
		if (s.at(i) == 'a') {
			count[0]++;
		} else if (s.at(i) == 'b') {
			count[1]++;
		} else if (s.at(i) == 'c') {
			count[2]++;
		}
	}
	int c = 0;
	for (int i = 0; i < 3; i++) {
		if (count[i] == 1) {
			c++;
		}
	}
	string ans;
	if (c == 3) {
		ans = "Yes";
	} else {
		ans = "No";
	}
	cout << ans << endl;
	return 0;
}


		
		

Measured memory_bytes: 256
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];
ll a[N];

int main() {
    FAST;
    ll t, i, j, k, q, r, x, y, u, v, n, m;
    cin>>n>>m>>x;
    ll p[n];
    ll inc[n][m];
    ll ans=INT_MAX;
    // cout<<n<<m<<x<<endl;
    Ff(i,0,n)
    {
      cin>>p[i];
      Ff(j,0,m)
      cin>>inc[i][j];
    }
    
    // cout<<endl;
    for(int i=0;i<pow(2,n);i++)
    {
      vc bin;
      ll temp=i;
      while(temp>0)
      {
        bin.pb(temp%2);
        temp/=2;
      }
      while(bin.size()<n)
      bin.pb(0);
      reverse(all(bin));
      ll flag=0;
      for(ll col=0;col<m;col++)
      {
        ll inner=0;
        for(ll row=0;row<n;row++)
        {
          if(bin[row]==1)
          inner+=inc[row][col];
        }
        // cout<<inner<<endl;
        if(inner<x)
        {
          flag=1;
          break;
        }
      }
      ll cost=0;
      if(flag==0)
      {
        for(ll lol=0;lol<n;lol++)
        {
          if(bin[lol]==1)
          cost+=p[lol];
        }
        // cout<<cost<<endl;
        ans=min(ans,cost);
      }
    }
    if(ans!=INT_MAX)
    cout<<ans; 
    else
    cout<<"-1";
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 11076
def solve_128b(a, b):
    if 1 <= a & a <= 12:
        if 1 <= b & b <= 12:
            return "AMBIGUOUS"
        else:
            return "MMYY"
    else:
        if 1 <= b & b <= 12:
            return "YYMM"
        else:
            return "NA"

s = int(input())
s2 = int(s / 100)
s1 = s % 100
print(solve_128b(s2, s1))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
#include <atcoder/dsu>
 
using namespace std;
using namespace __gnu_pbds;
using namespace atcoder;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	// freopen("capastaty_input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n, q;
	cin >> n >> q;

	dsu d(n);

	for(int i = 0; i < q; i++){
		int t, a, b;
		cin >> t >> a >> b;

		if(t == 0)
			d.merge(a, b);
		else
			cout << d.same(a, b) << endl;
	}

	return 0;
}


Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 800000000
#define MAX 1000
vector<int> p;
vector<bool> p_table(MAX+1,true);
void prime(){
  p_table.at(0)=false,p_table.at(1)=false;
  for(ll i=2;i<=MAX;i++){
    if(p_table.at(i)){
      p.push_back(i);
      for(int j=2;i*j<=MAX;j++){
        p_table.at(i*j)=false;
      }
    }
  }
}

long long modpow(long long a,long long n,long long mod){
  long long res=1;
  while(n>0){
    if(n&1){       //nのbitと...00001を比較  nが2で割り切れるならtrue
      res=(res*a)%mod;
    }
    a=(a*a)%mod;
    n>>=1;
  }
  return res;
}

long long modinv(long long a,long long mod){
  return modpow(a,mod-2,mod);
}

int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }

  prime();

  int n=p.size();
  ll lcm=1;
  vector<vector<int>> p_count(N,vector<int>(n,0));
  vector<int> p_max(n,0);
  set<ll> pp;
  for(int i=0;i<N;i++){
    int k=0;
    int B=A.at(i);
    while(B>1&&k<n){
      if(B%p.at(k)==0){
        p_count.at(i).at(k)++;
        B/=p.at(k);
      }else{
        k++;
      }
    }
    if(B>1){
      pp.insert(B);
    }
    for(int j=0;j<n;j++){
      p_max.at(j)=max(p_count.at(i).at(j),p_max.at(j));
    }
  }

  for(int i=0;i<n;i++){
    lcm*=modpow(p.at(i),p_max.at(i),MOD);
    lcm%=MOD;
  }
  for(auto x: pp){
    lcm*=(ll)x;
    lcm%=MOD;
  }

  ll ans=0;
  for(int i=0;i<N;i++){
    ans+=lcm*modinv(A.at(i),MOD)%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
}


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


void lok(){
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin>>t;
	unsigned ll tb=1;
	unsigned ll jib,zebi;
	vector<ll> tbaben(t);

	for(int i=0;i<t;i++){
		cin>>tbaben[i];
		if(tbaben[i]==0){
			cout<<'0'<<endl;
			return 0;
		}
	}
	for(int i=0;i<t;i++){
		jib=tbaben[i];
		zebi=tb;
		tb*=jib;
		if(tb>1000000000000000000||(tb<zebi)){
			cout<<"-1"<<endl;
			return 0;
		}
	}
	cout<<tb<<endl;
	return 0;
}


Measured memory_bytes: 3976
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

const int maxn = 1e5+7;
std::map<int, int> oo, ee;
std::vector<std::pair<int, int>> o, e;

int main(int argc, char *argv[]) {  
	int n, v[maxn];
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> v[i];
		if (i%2==0) {
			oo[v[i]]++;
		} else {
			ee[v[i]]++;
		}
	}
	for (auto it: oo) {
		o.push_back(std::make_pair(-it.second, it.first));
	}
	o.push_back({0,0});
	for (auto it: ee) {
		e.push_back(std::make_pair(-it.second, it.first));
	}
	e.push_back({0,0});
	std::sort(o.begin(), o.end());
	std::sort(e.begin(), e.end());
	int ans = 0;
	if (o[0].second != e[0].second) {
		ans = n+o[0].first+e[0].first;
	} else {
		ans = n+o[0].first+std::min(o[1].first, e[1].first);
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 6524
#include <stdio.h>
int main(int argc, const char * argv[]) {
    int n, m, l, i, j, k, A[100][100]={0}, B[100][100]={0};
    long C[100][100] = {0};
    scanf("%d %d %d",&n,&m,&l);
    for( i = 0 ; i < n ; i++ ){
        for( j = 0 ; j < m ; j++ ){
            scanf("%d",&A[i][j]);
        }
    }
    for( i = 0 ; i < m ; i++ ){
        for( j = 0 ; j < l ; j++ ){
            scanf("%d",&B[i][j]);
        }
    }
    for( i = 0 ; i < n ; i++ ){
        for( j = 0 ; j < l ; j++ ){
            for( k = 0 ; k < m ; k++ ){
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }
    for( i = 0 ; i < n ; i++ ){
        for( j = 0 ; j < l ; j++ ){
            printf("%ld",C[i][j]);
            if( j != l-1 ){
                printf(" ");
            }
            else{
                printf("\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 768
#include<stdio.h>

int main(){
	
	char c;
	int i,j,k;
	int n,m,l;
	int table_a[100][100]={0};
	int table_b[100][100]={0};
	long table_c[100][100]={0};
	
	
	scanf("%d %d %d",&n,&m,&l);
	
	/*テーブルAへ数値セット*/
	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			scanf("%d%c",&table_a[i][j],&c);
			if(c == '\n'){
				break;
			}
		}
	}
	/*テーブルBへ数値セット*/
	for(i=0; i<m; i++){
		for(j=0; j<l; j++){
			scanf("%d%c",&table_b[i][j],&c);
			if(c == '\n'){
				break;
			}
		}
	}
	/*テーブルCへ数値セット*/
	for(i=0; i<n; i++){
		for(j=0; j<l; j++){
			for(k=0; k<m; k++){
				table_c[i][j] += table_a[i][k] * table_b[k][j];
			}
		}
	}
	/*テーブルCの出力*/
	for(i=0; i<n; i++){
		for(j=0; j<l; j++){
			if(j!=0){
				printf(" ");
			}
			printf("%ld",table_c[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}




Measured memory_bytes: 2092
def culc(s):
    if len(s) == 0:
        return 0
    elif len(s) == 1:
        return int(s)
    count = 0
    for i in range(len(s)):
        count += culc(s[0:i])
        count += int(s[i:len(s)]) * (2 ** max(0, len(s[0:i])-1))
    return count

print(culc(input()))

Measured memory_bytes: 3060
n,k=map(int, input().split())
s=input()

mn=0
mt=False

pre='N'
now=0
for i, val in enumerate(s):
    if val == pre:
        now+=1
    if i != 0:
        if pre != val:
            mn+=1
    pre=val

c2=mn//2
if k > c2:
    k-=c2
    now+=(c2*2)
else:
    now+=(k*2)
    k=0

if k > 0 and mn%2 ==1:
    now+=1
print(now)



Measured memory_bytes: 3316
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

string S = "";

int main() {
	cin >> S;
	string T = S.substr(0, 2);
	string X = S.substr(2, 2);
	int flag = 0;
	int flag1 = 0;
	// cout << ("12" > "01");
	if(T <= "12" && T >= "01") {
		// cout << T << "\n";
		flag = 1;
	}
	if(X <= "12" && X >= "01") {
		// cout << X << "\n";
		flag1 = 1;
	}
	if(flag1 && flag) {
		printf("AMBIGUOUS\n");
	}
	else if(flag) {
		printf("MMYY\n");
	}
	else if(flag1) {
		printf("YYMM\n");
	}
	else {
		printf("NA\n");
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
int dig(int n) { return (log10(n) + 1); }
int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	a = b + pow(10, dig(b)) * a;
	for (int i = 0; i < 1001; i++) {
		if (i * i == a) {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 512
a = list(map(int, input().split()))
a.sort()
cnt = 0
while max(a)-min(a)>1:
    a[0] += 2
    a.sort()
    cnt += 1
if a[0]==a[1]==a[2]:
    print(cnt)
elif a[0]==a[1]:
    print(cnt+1)
else:
    print(cnt+2)

Measured memory_bytes: 3064