akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int lowerBounds(int* a,int key,int length){
    // 存在しない場合
    if(a[length - 1] < key) return length;
    int left = 0;
    int right = length;
    int center;
    int targetIndex = 0;

    while(1){
        center = (left + right) / 2;
        if(a[center] == key){
            targetIndex = center;
            break;
        }
        else if(a[center] > key){
            right = center;
        }else{
            left = center + 1;
        }
        if(left >= right){
            targetIndex = right;
            break;
        }
    }

    while(targetIndex > 0){
        if(a[targetIndex - 1] < key){
            break;
        }
        targetIndex--;
    }
    return targetIndex;
}

int upperBounds(int* a,int key,int length){
    // 存在しない場合
    if(a[length - 1] <= key) return length;
    int left = 0;
    int right = length;
    int center;
    int targetIndex = 0;
    
    while(1){
        center = (left + right) / 2;
        if(a[center] == key){
            targetIndex = center;
            break;
        }
        else if(a[center] > key){
            right =  center;
        }else{
            left = center + 1;
        }
        if(left >= right){
            targetIndex = left;
            break;
        }
    }
    
    while(targetIndex < length - 1){
        if(a[targetIndex] > key){
            break;
        }
        targetIndex++;
    }
    return targetIndex;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,n2,key;
    cin >> n;
    int a[n];
    for (int i = 0;i < n;++i) {
        cin >> a[i];
    }
    cin >> n2;
    for(int i = 0;i < n2;++i){
        cin >> key;
        cout << lowerBounds(a,key,n) << " " << upperBounds(a,key,n) << endl;
    }
}


Measured memory_bytes: 3552
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
int ceil(int a,int b){
    return (a+b-1)/b;
}
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int t=-max(a,c)+min(b,d);
    if(t>0) cout<<t<<endl;
    else cout<<"0"<<endl;
    return 0;
}

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;


void solve(){
    int n, k;
    cin>>n>>k;
    int a[n];
    fr(i, n) cin>>a[i];

    vector<bool> dp(k + 1);
    /// dp[i] = whether players with the chance in hand wins or not with i stones left
    for(int stones = 0; stones <= k; ++stones){
        repn(i, n-1, 0){
            int x = a[i];
            if(stones >= x && !dp[stones - x]){
                dp[stones] = true;
            }
        }
    }

    cout<<(dp[k] ? "First" : "Second");

}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



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

using namespace std;

int main()
{
    int MAX = 10000;
    // 添字が素数ならば true
    vector<bool> isPrime(MAX+1, true);

    isPrime[1] = false;
    for (int i = 2; i <= MAX; i++) {
        // i が素数 = 2 から √i で割り切れない
        // 試し割り法
        for (int j = 2; j*j <= i; j++) {
            if (i%j == 0) isPrime[i] = false;
        }
    }

    int N;
    while (cin >> N)
    {
        int count = 0;
        for (int i = 1; i <= N; i++) {
            if (isPrime[i] && isPrime[N-i+1]) count++;
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 1196
<?php
  
 fscanf(STDIN,"%s",$s);
 $memo=array();
 for($i=0;$i<strlen($s);$i++){
   if(in_array($s[$i],$memo)){
     echo "no\n";
     exit;
   }
   $memo[]=$s[$i];
 }
	
      
echo "yes\n";

Measured memory_bytes: 4604
program strings_with_the_same_length
    implicit none
    integer(4):: n,i
    character(:),allocatable:: s,t,st
    
    read*, n
    allocate(character(n):: s, t)
    allocate(character(2*n):: st)
    read*, s,t
    
    do i=1,n
        st(2*i-1:2*i) = s(i:i)//t(i:i)
    end do
    print*, st
end program strings_with_the_same_length

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


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

    // solution comes here
    string a, b;
    cin >> a >> b;
    a += b;
    ll X = stoi(a);
    for(ll i=1; i*i<=X; i++) {
        if(i*i==X) {
            cout << "Yes" << nl;
            return 0;
        }
    }
    cout << "No" << nl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a, b, c;
    cin >>a >>b >>c;
    
    if(a<=b && b<=c) cout<<a <<" "<<b <<" "<<c<<endl;
    else if(a<=c && c<=b)cout<<a <<" "<<c <<" "<<b<<endl;
    else if(b<=a && a<=c)cout<<b <<" "<<a <<" "<<c<<endl;
    else if(b<=c && c<=a)cout<<b <<" "<<c <<" "<<a<<endl;
    else if(c<=a && a<=b)cout<<c <<" "<<a <<" "<<b<<endl;
    else if(c<=b && b<=a)cout<<c <<" "<<b <<" "<<a<<endl;
 
    
    
    
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    int x, y;
    while(cin >> x >> y && x)
    {
        int ans = 0;
        if(x<y) swap(x,y);

        while(y)
        {
            x = x % y;
            swap(x,y);
            ans += 1;
        }
        cout << x << " " << ans << endl;

    }
    return 0;
}

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

int main()
{
  long long A, B, K;
  cin >> A >> B >> K;
  
  if(A+B<=K){
    cout << 0 << " " << 0 << endl;
    return 0;
  }
  
  if(A>=K){
    cout << A-K << " " << B << endl;
  }else{
    cout << 0 << " " << A+B-K << endl;
  }
  
  return 0;
} 

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

int main(){
  int n , k ,x;
  cin >> n >> k;
  x = 1;
  
  for(int i = 0; i < n; i++){
    if(k >= x)
      x *= 2;
    else
      x += k;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
const int N=2e5+5;
int n,k,p[N],i,s[N],ans;
bool b[N],bb[N];
struct Q{
	pii q[N];int t,w,O;
	inline void ins(pii u){
		for(;t<=w && (q[w]<u)==O;--w);
		q[++w]=u;
	}
	inline int ask(int x){
		for(;q[t].second<x;)++t;
		return q[t].first;
	}
}q0,q1;
int main(){
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;++i)scanf("%d",p+i);
	for(i=1;i<=n;++i)s[i]=s[i-1]+(p[i]>p[i+1]);
	q0.O=0;q1.O=1;q0.t=q1.t=1;
	for(i=2;i<n;++i){
		q0.ins(pii(p[i],i)),q1.ins(pii(p[i],i));
		if(i>=k){
			if(q0.ask(i-k+2)>p[i-k+1]){
				if(q1.ask(i-k+2)<p[i+1])
					b[i+1]=1;
			}
		}
	}
	for(i=k;i<=n;++i)ans+=bb[i]=s[i-1]-s[i-k]>0;
	for(i=k+1;i<=n;++i)ans-=bb[i-1] && bb[i] && b[i];
	for(i=k;i<=n;++i)if(!bb[i]){ans++;break;}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5376
#include<iostream>
int temp[100001];

using namespace std;
int main(){
	int m,n;
	bool result=true;
	if(cin>>n>>m){
		 result=true;
		for(int i=0;i<n+1;i++){
		   temp[i]=0;
		}
		int a,b;
		for(int j=0;j<m;j++){
		   cin>>a>>b;
		   temp[a]++;
		   temp[b]++;
		}

		for(int k=1;k<n+1;k++){
		   if(temp[k]%2!=0) result=false;
		}

		if(result) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
   return 0;
}

Measured memory_bytes: 640
#include <cstdio>
typedef long long LL;
LL n;

LL gcd(LL a,LL b)
{return b==0 ? a : gcd(b,a%b);}

LL lcm(LL a,LL b)
{return a/gcd(a,b)*b;}

int main()
{
    //freopen("1.txt","r",stdin);
    while (scanf("%I64d",&n)!=EOF)
    {
        printf("%I64d\n",lcm(n,2));
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)

void recursive_debug(string) { cerr << endl; }

template<class H,class... T>
void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}

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

template<class T>
ostream& operator<<(ostream &ost, const vector<T> &v) {
    ost << "[";
    for(T t : v) ost << t << ",";
    ost << "]";
    return ost;
}

struct State {
    ll score;
    vector<int> last;
    vector<int> types;
    bool operator<(const State& rhs) const {
        return (score < rhs.score);
    }
    bool operator>(const State& rhs) const {
        return (score > rhs.score);
    }
};


int main(void){
    int D, M = 26;
    cin >> D;
    vector<ll> c(M);
    rep(m,M) cin >> c[m];
    vector<vector<ll>> s(D, vector<ll>(26));
    rep(d,D) rep(m,M) cin >> s[d][m];

    set<State> cur_states = {{0, vector<int>(M, -1), {}}};
    size_t SIZE = 200;

    rep(d,D) {
        set<State> nxt_states;
        for (auto cur_itr : cur_states) {
            State state = cur_itr;
            rep(m,M) {
                State nxt_state;
                nxt_state.score = state.score + s[d][m];
                nxt_state.last = state.last;
                nxt_state.last[m] = d;
                nxt_state.types = state.types;
                nxt_state.types.push_back(m);

                rep(i,M) {
                    nxt_state.score -= c[i] * (d - nxt_state.last[i]);
                }
                nxt_states.insert(nxt_state);
                if (nxt_states.size() > SIZE) {
                    nxt_states.erase(nxt_states.begin());
                }
            }
        }

        cur_states = std::move(nxt_states);
    }

    for (int t : cur_states.begin()->types) {
        cout << t+1 << endl;
    }
    // debug(cur_states[0].score);

    return 0;
}


Measured memory_bytes: 4800
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>
#include <string>
#include <valarray>
// #include <cctype>

#define INF -1

using namespace std;
/*  class   */
class Dice
{
    private:
        // vector<int> face(6);
        int face[7];
        // string west = "face4", east = "face3",
        //         south = "face2" , north = "face5",
        //         bottom = "face6", top = "face1";
        int W = 4, E = 3, S = 2, N = 5, B = 6, T = 1;

    public:
        void assign()
        {
            int i = 0;
            while (i++ < 6)
            {
                cin >> face[i];
            }
            cin.ignore();

        }

        void roll(char ch)
        {
            if (ch == 'W')
                roll_W();
            else if (ch == 'E')
                roll_E();
            else if (ch == 'S')
                roll_S();
            else
                roll_N();
        }


        void roll_W()
        {
            int temp = W;
            W = T;
            T = E;
            E = B;
            B = temp;
        }

        void roll_E()
        {
            int temp = E;
            E = T;
            T = W;
            W = B;
            B = temp;
        }
        
        void roll_S()
        {
            int temp = S;
            S = T;
            T = N;
            N = B;
            B = temp;
        }

        void roll_N()
        {
            int temp = N;
            N = T;
            T = S;
            S = B;
            B = temp;
        }

        void rotate()
        {
            int temp = S;
            S = W;
            W = N;
            N = E;
            E = temp;            
        }

        int top()
        {
            return face[T];
        }

        int front()
        {
            return face[S];
        }

        int right()
        {
            return face[E];
        }
};


int main()
{
    Dice dice;

    dice.assign();

    int n;
    cin >> n;
    while (n--)
    {
        int T, F;
        cin >> T >> F;
        for (int i = 0; i < 4; i++)
        {
            if (dice.top() == T && dice.front() == F)
                break;

            dice.roll_W();

            for (int j = 0; j < 4; j++)
            {
                if (dice.top() == T && dice.front() == F)
                    break;
                
                dice.roll_N();

                for (int k = 0; k < 4; k++)
                {
                    if (dice.top() == T && dice.front() == F)
                        break;
                    
                    dice.rotate();                    
                }

                
            }
        }

        cout << dice.right() << endl;        
    }

}


Measured memory_bytes: 3020
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
const int MaxN = 100 + 5;
int n, m;
int pre[2 * MaxN], last[MaxN], other[2 * MaxN];
int all = -1;
bool vis[MaxN];
int ans;
void Build(int u, int v){
	pre[++all] = last[u];
	last[u] = all;
	other[all] = v;
}
void Dfs(int x, int cont){
	if(vis[x]) return;
	vis[x] = true;
	cont++;
	int ed, dr;
	ed = last[x];
	while(ed != -1){
		dr = other[ed];
		Dfs(dr, cont);
		ed = pre[ed];
	}
	if(cont == n) ans++;
	cont--;
	vis[x] = false;
}
	
int main(){
	while(~scanf("%d %d", &n, &m)){
		memset(pre, 0, sizeof(pre));
		memset(last, - 1, sizeof(last));
		memset(other, 0, sizeof(other));
		all = -1;
		ans = 0;
		int u, v;
		for(int i = 1; i <= m; i++){
			scanf("%d %d", &u, &v);
			Build(u, v);
			Build(v, u);
		}
		Dfs(1, 0);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>

using namespace std;

long long N,M,a,b;

int main()
{
  cin >> N >> M;
  
  priority_queue<long long,vector<long long>,greater<long long>> A;
  
  vector<pair<long long,long long>> B(M);
  

  long long i,j,k;

  for(i=0;i<N;i++)
  {
    cin >> j;
    A.push(j);
  }
    for(i=0;i<M;i++)
  {
    cin >> a >> b;
      B[i]=make_pair(-b,a);
  }
  
  sort(B.begin(),B.end());
  
  for(i=0;i<M;i++)
  {
    
    for(k=0;k<B[i].second;k++)
    {
      j=A.top();
      if(j<-B[i].first)
      {
        A.pop();
        A.push(-B[i].first);
      }
      else
      {
        break;
      }
    }
  }

  j=0;
  for(i=0;i<N;i++)
  {
    j+=A.top();
    A.pop();
  }
    
  cout << j;


}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
using sint = int64_t;

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

template<class T> vector<T> read_vector(sint n) {
	vector<T> vs;
	for (sint i = 0; i < n; ++i) {
		vs.push_back(read<T>());
	}
	return vs;
}

inline void write() {
}

template<class T> void write(T const& t) {
	cout << t;
}

template<class T> void write(vector<T> const& ts) {
	if (ts.size() > 0) {
		cout << ts[0];
	}
	for (size_t i = 1; i < ts.size(); ++i) {
		cout << ' ' << ts[i];
	}
}

template<class T, class... Args> void write(T const& t, Args const&... args) {
	cout << t << ' ';
	write(args...);
}

template<class... Args> void writeln(Args const&... args) {
	write(args...);
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin .exceptions(ios_base::badbit | ios_base::failbit);
	cout.exceptions(ios_base::badbit | ios_base::failbit);
	cin .tie(nullptr);
	cout.tie(nullptr);
	cout.precision(16);
	void run();
	run();
	return 0;
}

void run() {
	auto const n = read<sint>();
	writeln(double((n + 1) / 2) / double(n));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> A(100010);

int GCD(int a, int b) {
    if(a == 0) {
        return b; 
    }else if(b == 0) {
        return a;
    }else {
        int r, tmp;
        if(a < b) {
            tmp = a;
            a = b;
            b = tmp;
        }

        r = a % b;
        while(r != 0) {
            a = b;
            b = r;
            r = a % b;
        }
        return b;
    }
}

vector<int> M(100010, 0);
vector<int> L(100010, 0);
vector<int> R(100010, 0);

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

    L.at(0) = 0; R.at(N+1) = 0;

    for(int i = 0; i < N; ++i) {
        L.at(i+1) = GCD(L.at(i), A.at(i));
    }

    for(int i = N; i > 0; --i) {
        R.at(i) = GCD(R.at(i+1), A.at(i));
    }

    /*for(int i = 0; i < N; ++i) {
        cout << L.at(i) << " " << R.at(i+1) << endl;
    }*/

    int max = 0;

    for(int i = 0; i < N; ++i) {
        M.at(i) = GCD(L.at(i), R.at(i+1));
        if(max < M.at(i)) max = M.at(i);
    }

    cout << max << endl;

}

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

string s, t;
int sl, tl;
int dp[4000][4000];

void print(int sp, int tp)
{
    if (sp == sl || tp == tl)
        return;
    if (s[sp] == t[tp])
    {
        if (dp[sp + 1][tp + 1] + 1 >= dp[sp + 1][tp] && dp[sp + 1][tp + 1] + 1 >= dp[sp][tp + 1])
        {
            cout << s[sp];
            print(sp + 1, tp + 1);
        }
        else if (dp[sp + 1][tp] >= dp[sp + 1][tp + 1] + 1 && dp[sp + 1][tp] >= dp[sp][tp + 1])
            print(sp + 1, tp);
        else if (dp[sp][tp + 1] >= dp[sp + 1][tp + 1] + 1 && dp[sp][tp + 1] >= dp[sp + 1][tp])
            print(sp, tp + 1);
    }
    else
    {
        if (dp[sp + 1][tp] > dp[sp][tp + 1])
            print(sp + 1, tp);
        else
            print(sp, tp + 1);
    }
}

int rec(int sp, int tp)
{
    if (sp == sl || tp == tl)
        return 0;
    if (dp[sp][tp] != -1)
        return dp[sp][tp];
    if (s[sp] == t[tp])
    {
        dp[sp][tp] = max(rec(sp + 1, tp + 1) + 1, rec(sp + 1, tp));
        return dp[sp][tp] = max(dp[sp][tp], rec(sp, tp + 1));
    }
    return dp[sp][tp] = max(rec(sp + 1, tp), rec(sp, tp + 1));
}

int main()
{
    cin >> s >> t;
    sl = s.length();
    tl = t.length();
    for (int i = 0; i < 4000; i++)
        for (int j = 0; j < 4000; j++)
            dp[i][j] = -1;
    rec(0, 0);
    print(0, 0);
    cout << endl;
    return 0;
}

Measured memory_bytes: 63232
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
int ans[200];
int cnt[200];
char an[200];
int minn(int a,int b){
    return a<b? a:b;
}
int main(){
    int n;
    while(~scanf("%d",&n)){
        for(int i=0;i<200;i++) ans[i]=100100;
        for(int i=1;i<=n;i++){
            memset(cnt,0,sizeof(cnt));
            scanf("%s",an);
            for(int j=0;j<strlen(an);j++){
                cnt[an[j]]++;
            }
            for(int j=0;j<200;j++){
                ans[j]=minn(ans[j],cnt[j]);
            }
        }

        for(int i=97;i<97+26;i++){
            while(ans[i]){
                printf("%c",i);
                ans[i]--;
            }
        }
        printf("\n");
    }
    return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

vector<int> next_num(int n) {
    vector<int> v;
    if (n == 0) {
        v.push_back(0);
        v.push_back(1);
        return v;
    } else if (n == 9) {
        v.push_back(8);
        v.push_back(9);
        return v;
    } else {
        v.push_back(n - 1);
        v.push_back(n);
        v.push_back(n + 1);
        return v;
    }
}


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

    int k; cin >> k;

    priority_queue<ll, vector<ll>, greater<ll>> que;

    for (int i = 1; i < 10; i++) {
        que.push(i);
    }

    for (int i = 0; i < k - 1; i++) {

        ll num = que.top();
        que.pop();
        int least_num = num % 10;
        vector<int> v = next_num(least_num);
        for (auto x:v) {
            que.push(num*10 + x);
        }
    }

    cout << que.top() << endl;



    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
  	cin>>s>>t;
  	int count=0;
  	for(int i=0;i<3;i++){
    	if(s.at(i)==t.at(i)){
        	count++;
        }
    }
  	cout<<count<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;

namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };

        

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            int N = int.Parse(Console.ReadLine());
            var a = cin.SplitRead();
            bool[] pair = new bool[N];
            Initialize(ref pair, false);
            for (var i = 0; i < N; i++) a[i]--;
            long ans = 0;
            for(var i = 0; i < N; i++)
            {
                if (a[a[i]] == i && !pair[a[i]]) { ans++;pair[i] = true;pair[a[i]] = true; }
            }
            Console.WriteLine(ans);
            //Console.Out.Flush();

        }
    }


    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }
    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
    }

}


Measured memory_bytes: 20192
import java.util.Scanner;

public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(; ;)
		{
			int t = scanner.nextInt();
			int h = scanner.nextInt();
			int s = scanner.nextInt();
			if(t==-1 && h==-1 && s==-1)
			{
				break;
			}
			int record = (t*3600 + h*60 + s);
			int time = 7200 - record;
			System.out.printf("%1$02d:%2$02d:%3$02d\n", time/3600, (time/60)%60, time%60);
			time *= 3;
			System.out.printf("%1$02d:%2$02d:%3$02d\n", time/3600, (time/60)%60, time%60);
		}
	}
}

Measured memory_bytes: 26532
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    string s;
    cin >> s;
    cout << s.substr(0, 4) << " " << s.substr(4, 8) << endl;
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[8];
	int data;
	int ans[1000000];

	for(int i=0;i<n;i++){
		cin >> data;
		a[0] = data%10;
		a[1] = data/10%10;
		a[2] = data/100%10;
		a[3] = data/1000%10;
		a[4] = data/10000%10;
		a[5] = data/100000%10;
		a[6] = data/1000000%10;
		a[7] = data/10000000%10;

		sort(a,a+8);

		int mb = a[7]*10000000+a[6]*1000000+a[5]*100000+a[4]*10000+
				a[3]*1000+a[2]*100+a[1]*10+a[0];

		int ms = a[0]*10000000+a[1]*1000000+a[2]*100000+a[3]*10000+
				a[4]*1000+a[5]*100+a[6]*10+a[7];

		ans[i] = mb-ms;
	}

	for(int i=0;i<n;i++){
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1184
import numpy as np

N, D = map(int, input().split())
#print(N)
#print(D)

listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

#print(listA)
#[[1, 2, 2, 3, 1], [4, 5, 3, 4, 1, 2, 3, 4], [2, 3, 5, 6, 0, 2]]


cnt = 0

for i in range(N):
	for j in range(N):
		if i!=j and i < j: 
			dist = 0
			for k in range(D):
				dist += (listA[i][k] - listA[j][k])**2
			#print(np.sqrt(dist))
			if np.sqrt(dist).is_integer()==1:
				cnt += 1


print(cnt)

Measured memory_bytes: 12472
#include<stdio.h>
int main(){
  int a,b,c;
  int d;
   scanf("%d %d %d",&a,&b,&c);
   if(a > b){

       d = a;
       a = b;
       b = d;
   }
   if(b > c){
       d = b;
       b = c;
       c = d;

   }
   if(a > b){
       d = a;
       a = b;
       b = d;
   }

   printf("%d %d %d\n",a,b,c);


   return 0;
}



Measured memory_bytes: 2096
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;

ll dp[102][100002], n, W, w[102], c[102];

ll recur(int pos, int weight) {
	if(weight > W) return -INF;
	if(pos >= n) return 0;

	ll &ret = dp[pos][weight];

	if(ret != -1) return ret;

	ret = recur(pos+1, weight);
	ret = max(ret, recur(pos+1, weight + w[pos]) + c[pos]);
	return ret;
}



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

	for(int i = 0; i < n; ++i)
		cin >> w[i] >> c[i];

	memset(dp, -1, sizeof dp);
	cout << recur(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 80000
#include <bits/stdc++.h>
using namespace std;
 
bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
int n,a,b;
int ar[101] = {};

int main(){
    cin >> n >> a >> b;
    if(a-1 == b || a+1 == b){
        cout << "Borys" << endl;
        return 0;
    }
    if((a-b)%2==0){
        cout << "Alice" << endl;
    }
    else    cout << "Borys" << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define line cout<<"----------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
#define bug(x) cerr << "[" << #x << "] = ["<<x<<"]"<<'\n'
using namespace std;
int n;
int ara[200009];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++) cin>>ara[i];
    int maxi=INT_MAX;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(ara[i]<maxi)
        {
            ans++;
            maxi=ara[i];
        }
    }
    cout<<ans<<endl;
}


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

string s, t;
int dp[3001][3001];

string solve()
{
    string ans = "";
    int i = (int) s.length();
    int j = (int) t.length();
    while (dp[i][j])
    {
        if (s[i-1] == t[j-1] && dp[i][j] == 1 + dp[i-1][j-1])
        {
            ans = s[i-1] + ans;
            i -= 1;
            j -= 1;
        }
        else if (dp[i][j] == dp[i-1][j])
        {
            i -= 1;
        }
        else
        {
            j -= 1;
        }
    }
    return ans;
}

int main()
{
    cin >> s >> t;
    for (int i = 0; s[i]; i++)
    {
        for (int j = 0; t[j]; j++)
        {
            if (s[i] == t[j]) dp[i+1][j+1] = 1 + dp[i][j];
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
        }
    }
    cout << solve() << endl;
    return 0;
}


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

string s[10];
int main(){
	int H,W;
	cin >> H >> W;
	int cnt = 0;
	for(int i = 0 ; i < H ; i++){
		cin >> s[i];
		cnt += count(s[i].begin(),s[i].end(),'#');
	}
	int ans = 0;
	if( cnt != H + W - 1 ){
		cout << "Impossible" << endl;
		return 0;
	}
	
	for(int i = 0 ; i < (1<<(H + W - 2)) ; i++){
		int x = 0, y = 0;
		int res = 1;
		for(int j = 0 ; j < H + W - 2 ; j++){
			if( i >> j & 1 ){
				x += 1;
			}else{
				y += 1;
			}
			if( y >= H or x >= W or s[y][x] != '#'){
				res = 0;
			}
		}
		if( res ) ans = 1;
	}
	if( !ans ){
		cout << "Impossible" << endl;
	}else{
		cout << "Possible" << endl;
	}
	
}

Measured memory_bytes: 256
<?PHP
$single_line_input = fgets(STDIN);
// 取得した入力値を半角スペースで分解します
$array = explode(" ", $single_line_input);
$item_num = $array[0];
$weight_upper = $array[1];
for($i=0;$i<$array[0];++$i){
    fscanf(STDIN,"%d %d ",$x,$y);
    $weight[$i]=$x;
    $value[$i]=$y;
}

$dp = [];
foreach (range(0, $item_num-1) as $item_index) {
    $i_value = $value[$item_index];
    $i_weight = $weight[$item_index];
    foreach (range(1, $weight_upper) as $weight_index) {
        $zantei=$dp[$item_index-1][$weight_index]?? 0;

        if($weight[$item_index] <= $weight_index) {
$new=($dp[$item_index-1][$weight_index-$weight[$item_index]] +$i_value);
            $dp[$item_index][$weight_index]=$zantei >=$new ? $zantei:$new;
        }else{    $dp[$item_index][$weight_index] = $zantei;};
    }
}
echo $dp[(int)$item_num-1][(int)$weight_upper];


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string s; std::cin >> s;
  bool ok = true;
  auto check = [](string s) {
    string ss = s;
    reverse(rng(ss));
    return ss == s;
  };
  if (!check(s)) ok = false;
  if (!check(s.substr(0, (s.size()-1)/2))) ok = false;
  if (!check(s.substr((s.size()+3)/2-1))) ok = false;
  std::cout << (ok ? "Yes" : "No") << "\n";
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	ll n,m;
	cin>>n>>m;
	vector<int> p(m);
	vector<string> s(m);
	rep(i,m)cin>>p[i]>>s[i];
	vector<int> ac(n,0),wa(n,0);
	rep(i,m){
		if(s[i]=="AC"){
			ac[p[i]-1]=1;
		}else{
			if(ac[p[i]-1]==0)wa[p[i]-1]++;
		}
	}
	
	int ans_ac=0,ans_wa=0;
	ans_ac = accumulate(all(ac),0);
	rep(i,n){
		if(ac[i]>0)ans_wa += wa[i];
	}
	cout<<ans_ac <<" "<< ans_wa<<endl;

	return 0;
}

Measured memory_bytes: 6912
import sys
input = sys.stdin.readline
from bisect import bisect_left
inf = float('inf')

class SegmentTree:
    def __init__(self, N):
        tmp = 1
        while tmp < N:
            tmp <<= 1
        self.N = tmp
        self.data = [inf for _ in range(2*self.N-1)]
    
    def update(self, l, r, x):
        L = l + self.N - 1
        R = r + self.N - 1
        while L < R:
            if R & 1:
                R -= 1
                self.data[R] = min(self.data[R], x)
            if L & 1:
                self.data[L] = min(self.data[L], x)
                L += 1
            L >>= 1; R >>= 1
    
    def value(self, k):
        k += self.N - 1
        res = self.data[k]
        while k != 0:
            k >>= 1
            res = min(res, self.data[k])
        return res

N, Q = map(int,input().split())
STX = [list(map(int,input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

st = SegmentTree(Q)
for S, T, X in STX:
    l = bisect_left(D, S-X)
    r = bisect_left(D, T-X)
    st.update(l, r, X)

for k in range(Q):
    ans = st.value(k)
    if ans == inf:
        ans = -1
    print(ans)

Measured memory_bytes: 118880
#include <iostream>
#include <string>

using namespace std;

int main() {
    string n;
    cin >> n;
    cout << ((n[0] == n[1] && n[1] == n[2] && n[2] == n[3])
            || (n[0] == n[1] && n[1] == n[2] && n[2] != n[3])
            || (n[0] != n[1] && n[1] == n[2] && n[2] == n[3]) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<set>
#include<math.h>
#include<list>
#include<vector>
#include<map>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)



int main(){
    int N;
    cin >> N;
    int A[100];
    rep(i, N){
        cin >> A[i];
    }
    std::map<int,long long> mp;
    for(int i=-100;i<=100;i++)mp[i]=0;
    rep(i, N){
        for(int j=-100;j<=100;j++)mp[j]+=(j-A[i])*(j-A[i]);
    }

    long long ans= 1 << 20;
    for(int i=-100;i<=100;i++)ans=min(ans, mp[i]);

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DBG(x) cerr << #x << " = " << x << endl

using namespace std;
typedef long long LL;

int main(int argc, char **argv) {
    int a, b, c;
    while(~scanf("%d/%d/%d", &a, &b, &c)) {
        printf("2018/%02d/%02d\n", b, c);
    }
    return 0;
}


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

#define ll long long

const int N = 1e5 + 5;

int n, S;
ll X[N], P[N];

int main() {
	scanf("%d%d", &n, &S);
	for (int i = 1; i <= n; i++) {
		scanf("%lld%lld", X + i, P + i);
	}
	int L = 1, R = n, d = 0;
	ll ans = 0;
	while (true) {
		if (X[R] <= S) {
			ans += S - X[L];
			break;
		} else if (X[L] >= S) {
			ans += X[R] - S;
			break;
		}
		if (P[L] >= P[R]) {
			(d != -1) && (ans += X[R] - X[L]);
			P[L] += P[R], d = -1, R--;
		} else {
			(d != 1) && (ans += X[R] - X[L]);
			P[R] += P[L], d = 1, L++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	long long int g;
	int n,max=-999999999,min=999999999,f,i;
	scanf("%d",&n);
	g=0;
	for(i=0;i<n;i++){
		scanf("%d",&f);
		if(max<f) max=f;
		if(min>f) min=f;
		g+=f;
	}
	printf("%d %d %lld\n",min,max,g);

	return 0;
}

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

int main(void) {
  int a, b;
  int i;
  scanf("%d", &a);
  scanf("%d", &b);
  if (a > b) {
    for (i = 0; i < a; ++i) {
      printf("%d", b);
    }
  } else {
    for (i = 0; i < b; ++i) {
      printf("%d", a);
    }
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int r; cin >> r;
	cout << r * r << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

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

    pair<bool, bool> pbbs[200000];
    REP(i, N) pbbs[i] = {false, false};
    int a, b;
    REP(i, M) {
        cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);
        if (a == 0) pbbs[b] = {true, pbbs[b].second};
        if (b == N - 1) pbbs[a] = {pbbs[a].first, true};
    }

    REP(i, N) if (pbbs[i].first && pbbs[i].second) {
        cout << "POSSIBLE" << endl;
        return 0;
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

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

	map<string, int> m;
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		++m[s];
	}

	long long ans = 0;
	for (auto &e: m) {
		long long v = e.second;
		ans += v * (v - 1) / 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 100100;
int n, d[N], p[N], ans, k;
vector <int> v[N];

void dfs(int node) {
	// dbg(node);
	for(auto i : v[node]) {
		dfs(i);
		d[node] = max(d[node], d[i] + 1);
	}

	// dbg(node, d[node]);

	if(d[node] == k - 1 && p[node] != 1 && node != 1) {
		ans++;
		// dbg("12", node);
		d[node] = -1;
	}
}

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

	cin >> n >> k;
	for(int i = 1; i <= n; i++) {
		cin >> p[i];
		if(i == 1) {
			if(p[i] != 1) ans++;
			continue;
		}
		// dbg(p[i], i);
		v[p[i]].push_back(i);
	}

	dfs(1);
	cout << ans << '\n';
}	

	

Measured memory_bytes: 11264
n= int(input())
arr = [int(x) for x in input().strip().split()]


def Greedy(arr):
    
    curr = 1000
    for i in range(len(arr)-1):
        if arr[i+1]>arr[i]:
            stocks = curr // arr[i]
            curr += (arr[i+1] - arr[i])*stocks
    return curr

print(Greedy(arr))

        
# mem = {}
# def helper(i, mon, stk):
#     key = (i, mon, stk)
#     if key in mem:
#         return mem[key]
    
#     if i==len(arr):
#         return mon
    
#     ans = helper(i+1, mon, stk)
#     buy = 1
#     while True:
#         if arr[i]*buy<=mon:
#             ans = max(ans, helper(i+1, mon - arr[i]*buy, stk+buy))
#         else:
#             break
        
#         buy += 1
    
#     for s in range(1, stk+1):
#         ans = max(ans, helper(i+1, mon+arr[i]*s, stk-s))
    
#     mem[key] = ans
#     return ans

    
# print(helper(0, 1000, 0))

Measured memory_bytes: 61888
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        StringBuilder result = new StringBuilder();

        while (s.contains("LR")) {
            
            int indexLR = s.indexOf("LR");
            int lastIndexOfFirstRLBlock;
            if(indexLR ==1){
                lastIndexOfFirstRLBlock = 1;
            }else {
                lastIndexOfFirstRLBlock = indexLR;
            }
            
            String firstRLBlock = s.substring(0, lastIndexOfFirstRLBlock + 1);
            s = s.substring(lastIndexOfFirstRLBlock + 1);
            result.append(makeSubResult(firstRLBlock));
        }
        result.append(makeSubResult(s));

        System.out.println(result.toString());
    }

    private static String makeSubResult(String rlBlock) {
        int lastIndexOfR = rlBlock.lastIndexOf("R");
        int countR = lastIndexOfR + 1;
        int countL = rlBlock.length() - countR;

        String result = rlBlock.replace("RL", "AB");
        result = result.replace("R", "0 ");
        result = result.replace("L", "0 ");

        int halfCountR = countR / 2;
        int halfCountL = countL / 2;

        int A = halfCountR + countR % 2 + halfCountL;
        int B = halfCountR +              halfCountL + countL % 2;

        result = result.replace("A", A + " ");
        return result.replace("B", B + " ");
    }

}

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

using namespace std;

#define int long long

const int mod = 1e9+7;
int n,k;

int p(int a,int b)
{
	if (b == 0)
		return 1;
	int tmp = p(a,b/2);
	if (b%2 == 0) return (tmp * tmp)%mod;
	return ((tmp * tmp)%mod * a)%mod;
}

int fact[400001];
int re_fact[400001];

int comb(int n,int k)
{
	int tmp = ((fact[n] * re_fact[k])%mod * re_fact[n-k])%mod;
	return tmp;
}

int comb_r(int n,int k)
{
	int tmp = ((fact[n+k-1] * re_fact[k])%mod * re_fact[n-1])%mod;
	return tmp;
}

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

	fact[0] = 1;
	for (int i=1;i<=400000;i++)
		fact[i] = (fact[i-1] * i)%mod;
	re_fact[400000] = p(fact[400000],mod-2);
	for (int i=400000;i>=1;i--)
		re_fact[i-1] = (re_fact[i] * i)%mod;	
	cin >> n >> k;
	int ans = 1;
	for (int rem=1;rem<=min(n-1,k);rem++)
		ans = (ans + (comb(n,rem) * comb_r(n-rem,rem))%mod)%mod;
	cout << ans;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

struct UFweight
{
    int i;
    vector<int> par;
    vector<int> size;
    vector<int> rank;
    vector<ll> diff_weight;
    UFweight(int n, ll sum_unity = 0){
        par.resize(n);  rank.resize(n); size.resize(n); diff_weight.resize(n);
        for(i = 0;i < n;++i){
            par.at(i) = i;
            rank.at(i) = 0;
            size.at(i) = 1;
            diff_weight.at(i) = sum_unity;
        }
    }
    
    int root(int x){
        if(par.at(x) == x){
            return x;
        }else{
            int r = root(par.at(x));
            diff_weight.at(x) += diff_weight.at(par.at(x));
            return par.at(x) = r;
        }
    }
    
    ll weight(int x){
        root(x);
        return diff_weight.at(x);
    }
    
    ll get_diff(int x, int y){
        return weight(y) - weight(x);
    }
    
    // weight(y) - weight(x) = wとなるようにmerge
    bool merge(int x, int y, ll w){
        w += weight(x); w -= weight(y);
        int rx = root(x);
        int ry = root(y);
        if(rx == ry){
            ll weight_diff = get_diff(rx, ry);
            if(weight_diff == w) return true;
            else return false;
        }
        
        if(rank.at(rx) < rank.at(ry)){
            swap(rx,ry);
            w *= -1;
        }
        if(rank.at(rx) == rank.at(ry)) ++rank.at(rx);
        par.at(ry) = rx;
        diff_weight.at(ry) = w;
        size.at(rx) += size.at(ry);
        
        return true;
    }
    
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int get_size(int x){
        return size.at(root(x));
    }
};

int main()
{
    ll i,j;
    ll n,q;
    cin >> n >> q;
    UFweight uf(n);
    for(i = 0;i < q;++i){
        ll com;
        cin >> com;
        if(com == 0){
            ll x,y,z;
            cin >> x >> y >> z;
            uf.merge(x, y, z);
        }else{
            ll x, y;
            cin >> x >> y;
            if(uf.same(x, y)){
                cout << uf.get_diff(x, y) << endl;
            }else{
                cout << '?' << endl;
            }
        }
    }

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s,ans="";
	stack<char>st;
	cin >> s;
	for (auto c : s) {
		if (c != 'B')st.push(c);
		else {
			if (!st.empty())st.pop();
		}
	}
	while (!st.empty()) { ans +=  st.top(); st.pop(); }
	reverse(all(ans));
	cout << ans <<endl;
	return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	string s;
	cin >> s;
	ll n = s.size();
	vector<bool> chk(26, false);
	for (ll i = 0; i < n; i++) chk[s[i] - 'a'] = true;

	if (n < 26) {
		for (ll i = 0; i < 26; i++) {
			if (!chk[i]) {
				cout << s << (char)('a' + i) << endl;
				break;
			}
		}
	}
	else {
		string t = s;
		reverse(all(t));
		if (t == "abcdefghijklmnopqrstuvwxyz") {
			cout << -1 << endl;
			return 0;
		}
		for (ll i = 24; i >= 0; i--) {
			vector<bool> v(26, false);
			for (ll j = i + 1; j < 26; j++) v[s[j] - 'a'] = true;
			for (ll j = s[i] - 'a' + 1; j < 26; j++) {
				if (v[j]) {
					cout << s.substr(0, i) << (char)('a' + j) << endl;
					return 0;
				}
			}
		}
	}
}


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

using namespace std;

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

	string ans;

	for (int i = 0; i < S.length(); i++){
		if (S[i] == '0'){ ans += '0'; }
		if (S[i] == '1'){ ans += '1'; }
		if (S[i] == 'B'&&ans.length()!=0){ ans.erase(ans.length() - 1); }
	}

	
	cout << ans << endl;

	return 0;
}

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

using namespace std;

int f(int n)
{
  if (n <= 1) {
    return n;
  }
  return 3 * f(n - 1) + 1;
}

int main()
{
  int n;
  while (scanf("%d ", &n) == 1) {
    int m = 0;
    for (int i = 1; i <= n; i++) {
      m += 2 * f(min(i - 1, n - i));
    }
    cout << n + m << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import math
S = int(input())
ans = 0
for i in range(1000):
  S -= 3
  if S < 0:
    break
  if i > 0:
    ans += math.factorial(S+i) // (math.factorial(S) * math.factorial(i))
    ans %= (10**9)+7
  else:
    ans += 1
print(ans%((10**9)+7))

Measured memory_bytes: 9184
#include <iostream>
#include <string>

using namespace std;

int main(){
  int a;
  cin >> a;
  string s;
  cin >> s;
  if (a < 3200) cout << "red" << endl;
  else if (a > 3200 || a == 3200) cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc= new Scanner (System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		System.out.println(Math.min(A, B)+Math.min(C, D));
	}
}


Measured memory_bytes: 27088
#include <iostream>
using namespace std;
int main(){
    int K;
    cin >> K;
    int Ans = 7 % K;
    for(int i = 1;i <= K;i++){
          if(Ans == 0){
                cout << i << endl;
                return 0;
          }
          Ans = (Ans * 10 + 7) % K;
    }
    cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3572