akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::cmp;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let n: usize = s.trim().parse().unwrap();

    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let xs: Vec<u64> = s.trim().split(' ').map(|x| x.parse().unwrap()).collect();

    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let ys: Vec<u64> = s.trim().split(' ').map(|x| x.parse().unwrap()).collect();

    let mut tbs = vec![false; n];

    let mut p = 0;
    for i in 0..n {
        if p < xs[i] {
            tbs[i] = true;
            p = xs[i];
        }
    }

    let mut abs = vec![false; n];

    p = 0;
    for j in 1..(n + 1) {
        let i = n - j;

        if p < ys[i] {
            abs[i] = true;
            p = ys[i];
        }
    }

    let m = 1000000007;

    let mut r = 1;
    for i in 0..n {
        if tbs[i] && abs[i] && xs[i] != ys[i]{
            r = 0;
            break;
        }
        else if !tbs[i] && !abs[i] {
            r *= cmp::min(xs[i], ys[i]);
            r %= m;
        }
        else if tbs[i] != abs[i] {
            if (tbs[i] && xs[i] > ys[i]) || (abs[i] && ys[i] > xs[i]) {
                r = 0;
                break;
            }
        }
    }

    println!("{}", r);
}


Measured memory_bytes: 5560
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	int N;
	cin >> N;

	int cnt = 1;

	int odd = 2 * cnt - 1;

	int ans = 0;

	int val = 0;

	while (odd <= N) {
		val = 0;
		for (int i = 1; i <= odd; i++) {
			if (odd % i == 0) {
				val += 1;
			}
		}
		if (val == 8) {
			ans += 1;
		}
		cnt += 1;
		odd = 2 * cnt - 1;
	}

	cout << ans << endl;

	return 0;
}



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

#define MAX_N (200000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N + 1];
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &as[i]);
  }

  // solve
  vector<int> bs;
  int cnts[MAX_N] = {};
  for (int i = N; i > 0; i--) {
    // add to match as[i]
    if (cnts[i] % 2 != as[i]) {
      bs.push_back(i);
      // count all factors of i
      for (int j = 1; j * j <= i; j++) {
        if (i % j == 0) {
          if (j * j < i) {
            cnts[j]++;
            cnts[i / j]++;
          } else {
            cnts[j]++;
          }
        }
      }
    }
  }

  // print answers
  printf("%d\n", (int)bs.size());
  if (bs.size() > 0) {
    for (int b : bs) {
      printf("%d ", b);
    }
    printf("\n");
  }

  return 0;
}


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

int main()
{
    int k,s,ans = 0;
    cin >> k >> s;
    for( int x = 0; x <= k; x++ )
    {
        for( int y = 0; y <= k; y++ )
        {
            if( s - ( x + y ) >= 0 && s - ( x + y ) <= k )
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = 0;
		for(int i = a; i < b + 1; i++) {
			if(i / 10000 == i % 10 && (i / 1000) % 10 == (i / 10) % 10) {
				ans++;
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 21588
#include<iostream>
 #include<algorithm>
 #include<cmath>
 #include<iomanip>
 #include<string.h>
 #include<cmath>
 #include<map>
 #include<vector>
using namespace std;
typedef long long ll;
char s[4005];
int main()
{
ll x;
cin>>x;
ll mmid=100;
for(int i=1;;i++)
{
  mmid=(ll)(1.0*mmid*1.01);  
//    cout<<mmid<<endl;
    if(mmid>=x)
    {
        cout<<i;
        break;
    }
}

}


Measured memory_bytes: 3640
N, M, X = list(map(int, input().split()))
A_list  = list(map(int, input().split()))

forward_cost = 0
backward_cost = 0

i = X
while i <= N:
    i += 1

    if i in A_list:
        forward_cost += 1

i = X
while i >= 0:
    i -= 1

    if i in A_list:
        backward_cost += 1

print(min(forward_cost, backward_cost))



Measured memory_bytes: 3060
/**Bismillahir Rahmanir Rahim.**/
#include<bits/stdc++.h>
#define ll 	long long
#define pb push_back
#define mp make_pair
using namespace std;

int main() {

ll n; cin>>n;
ll d=100;
ll cnt=0;
while(d<n)
{
	
	d+=d/100;
	cnt++;
	//if(d==n)
	//break;
	
}
cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3584
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
V<V<int>> id(const string &s){
    int n=s.size();
    V<V<int>> num(n+1,V<int>(26,n));
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<26;j++)num[i][j]=num[i+1][j];
        num[i][int(s[i]-'a')]=i;
    }
    return num;
}
int main(){
    string s;
    cin>>s;
    int n=s.size();
    V<V<int>> num=id(s);
    V<int> dp(n+1,int(1e7));
    V<char> res(n+1,'a');
    dp[n]=1;
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<26;j++){
            if(num[i][j]==n){
                if(dp[i]>1){
                    dp[i]=1;
                    res[i]=char(j+'a');
                }
            }else{
                if(chmin(dp[i],dp[num[i][j]+1]+1)){
                    res[i]=char(j+'a');
                }
            }
        }
    }
    string ans={};
    int ind=0;
    while(ind<=n){
        ans.push_back(res[ind]);
        ind=num[ind][res[ind]-'a']+1;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 31020
#include <stdio.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int a[10];

int main() {
    rep (i, 10) scanf("%d", a+i);
    sort(a, a+10);
    reverse(a, a+10);
    rep (i, 3) printf("%d\n", a[i]);
    return 0;
}

Measured memory_bytes: 0
N = int(input())
balls = [tuple(map(int, input().split())) for _ in range(N)]

ans = N
for i in range(N):
    for j in range(i+1, N):
        p, q = balls[j][0]-balls[i][0], balls[j][1]-balls[i][1]
        cost = N
        for a in range(N):
            x1, y1 = balls[a]
            for b in range(N):
                x2, y2 = balls[b]
                if (x2-x1, y2-y1) == (p, q):
                    cost -= 1
                    break
        ans = min(ans, cost)

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
int main(void) {
    int n, k;
    static double ans = 0.0, x[100000];
    int i, temp;
    int cnt = 0;

    scanf("%d %d", &n, &k);

    for (i = 1; i <= n; i++) {
        temp = i;
        x[i - 1] = 1 / (double)n;
        while (temp < k) {
            x[i - 1] *= 1 / 2.0;
            temp *= 2;
            cnt++;
        }
    }
    for (i = 0; i < n; i++) {
        ans += x[i];
    }
    printf("%.12lf\n", ans);
    return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int main(){
    int n,m;
    while(cin>>n>>m){
        vector<int>c(m);
        rep(i,m)cin>>c[i];
        int dp[n+1];
        rep(i,n+1)dp[i] = INF;
        dp[0] = 0;
        REP(i,1,n){
            rep(j,m){
                if(i-c[j]>=0)dp[i] = min(dp[i],dp[i-c[j]]+1);
            }
        }
        cout<<dp[n]<<endl;
    }
}




Measured memory_bytes: 3300
#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define LSOne(i) (i&(-i))
#define rep(i,a,b) for(int(i)=(a);(i)<(b);i++)
#define BUG(x) {cout<<#x<<" = "<<x<<endl;}
#define left(x) (x<<1)
#define right(x) ((x<<1) +1)
#define middle(s,e)(s+(e-s)/2)
#define size_tree(n) 2*(int)pow(2,ceil(log2(n)))
#define CL(A,I) (memset(A,I,sizeof(A)))
#define endl '\n'
#define PHAS(_n) (pbits[(_n)>>5] & (1u << ((_n) & 0x1f)))
#define PSET(_n) (pbits[(_n)>>5] |= (1u << ((_n) & 0x1f)))
//unsigned int pbits[200000000/32+1];

static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const long double epsilon = 1e-15;
static const long double pi = acos((long double) -1);
using namespace std;
inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef long long ll;
const int MAX_N = 300001;


struct data{
  string s;
  int p,i;
  data():s(""), p(0), i(0){};
  data(string s_, int p_, int i_) : s(s_),p(p_), i(i_){};
  bool operator < (data other) const {
	if(s==other.s)
		return p>other.p;
    return s < other.s;
  }
};


int arr[MAX_N];
data ss[101];
int main()
{
        init_io();
        int a,b;
        cin>>a>>b;
        cout<<(a*3 + b)/2<<endl;
        return 0;
        
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const ll mod=1000000000;
int main()
{
        ll s;
        ll q=0;
        ll w=1;
        cin>>s;
        /*if(s<=mod)
        printf("%lld %lld %lld %lld %lld %lld\n",q,q,q,w,s,q);
        else
        {
             printf("%lld %lld %lld %lld ",q,q,mod,w);
             ll re=(ll)s/mod;

              ll yu=s%mod;
              printf("%lld %lld\n",yu,re);

        }*/
        ll re=sqrt(s);
        while(re*re<s)re++;

        cout<<"0 0 "<<re<<' '<<1<<' '<<re*re-s<<' '<<re<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> C(N - 1);
  vector<int> S(N - 1);
  vector<int> F(N - 1);
  REP(i, N - 1) { cin >> C[i] >> S[i] >> F[i]; }
  //さいしょにいる駅: i
  REP(i, N - 1) {
    int tmp = S[i] + C[i];
    FOR(j, i + 1, N - 1) {
      if(tmp < S[j]) {
        tmp = S[j] + C[j];
      } else {
        if(tmp % F[j] == 0) {
          tmp = tmp + C[j];
        } else {
          tmp = (tmp / F[j] + 1) * F[j] + C[j];
        }
      }
    }
    cout << tmp << endl;
  }
  cout << 0 << endl;
  return 0;
}

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

int main(){
    int count=0;
    int A[100],n;
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> A[i];
    }
    
    for (int i=0;i<n;i++){
        int minj = i;
        for (int j=i;j<n;j++){
            if (A[j] < A[minj]){
                minj = j;
            }
        }
        if (i!=minj){
                swap(A[i],A[minj]);
                count++;
        }
    }
    for (int i=0;i<n;i++){
        if (i!=0){cout << " ";};
        cout << A[i];
    }
    cout << endl;
    cout << count << endl;
}




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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

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

  vector<vector<int>> edge(n,vector<int>());
  REP(i,n){
    int node, k;
    cin >> node;
    cin >> k;
    REP(j,k){
      int v;
      cin >> v;
      v--;
      edge[i].emplace_back(v);
    }
  }

  VI dist(n,-1);

  queue<int> q;
  q.push(0);
  dist[0]=0;
  
  while(!q.empty()){
    int v = q.front(); q.pop();

    for(auto &iter: edge[v]){
      if(dist[iter]!=-1)continue;

      dist[iter] = dist[v]+1;
      q.push(iter);
    }
  }

  REP(i,n){
    cout << i+1 << " " << dist[i] << endl;
  }
}



Measured memory_bytes: 3156
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<ctime>

#define int long long
#define R register
#define IL inline
#define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))
#define Tf(a,b,c) for(R int (a)=(b);(a)>=(c);--(a))
#define MP make_pair
#define PA pair<int,int>
#define MES(a,b) memset((a),(b),sizeof((a)))
#define MEC(a,b) memcpy((a),(b),sizeof((b)))
#define D double

using namespace std;

int x;

IL int read() {
    int x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x*=10;x+=(ch-'0');ch=getchar();}
    return x*f;
}
IL void write(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

signed main()
{
	x=read();
	Rf(a,-1000,1000) Rf(b,-1000,1000) {
		if(a*a*a*a*a-b*b*b*b*b==x) {
			printf("%lld %lld",a,b);
			return 0;
		}
	} 


    return 0;
}


Measured memory_bytes: 3748
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
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();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int n;

main(){
	cin>>n;
	for(int i=0;i*4<=n;i++){
		for(int j=0;j*7+i*4<=n;j++){
			if(n==i*4+j*7){
				dump("Yes");
				return 0;
			}
		}
	}
	dump("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int64_t f(int64_t x,int64_t y){
if(y==0)
  return 1;
  else if(y%2==0)
    return (f(x,y/2)*f(x,y/2))%mod;
  else
    return (x*((f(x,y/2)*f(x,y/2))%mod))%mod;
}
int main(){
 int64_t N,K;cin>>N>>K;
  vector<int64_t>A(K);
  for(int i=0;i<K;i++)
    cin>>A.at(i);
  vector<int64_t>r(1001);
  for(int64_t i=0;i<=1000;i++)
    r.at(i)=f(i,mod-2);
  
  vector<int64_t>CombN(1+N);
  CombN[0]=1;
  for(int i=1;i<=N;i++)
    CombN[i]=(((CombN[i-1]*(N+1-i))%mod)*r[i])%mod;
  vector<vector<int64_t>>dp(1+K,vector<int64_t>(1+N,0));
  dp[0][0]=1;
  for(int i=1;i<=K;i++)
    for(int j=0;j<=N;j++){
    int64_t Min;
      if(j<=A[i-1])Min=j;
      else
        Min=A[i-1];
      vector<int64_t>C(1+Min);C[0]=1;
      vector<int64_t>D(1+Min);D[0]=CombN[N-A[i-1]];
      for(int64_t  k=1;k<=Min;k++)
        C[k]=(((C[k-1]*(N+k-j))%mod)*r[k])%mod;
      for(int64_t k=1;k<=Min;k++)
        D[k]=(((D[k-1]*(A[i-1]-k+1))%mod)*r[N+1-k])%mod;
      int64_t sum=0;
      for(int64_t l=0;l<=Min;l++){
      int64_t a=(C[l]*D[l])%mod;
        a=(a*dp[i-1][j-l])%mod;
      sum=(sum+a)%mod;
      }dp[i][j]=sum;
        
      
      }cout<<dp[K][N]<<endl;
   return 0;
}

Measured memory_bytes: 3852
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
x = [xy[i][0] for i in range(N)]
y = [xy[i][1] for i in range(N)]
if N == 1:
    print(1)
    exit()
else:
    ans = N
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            dx,dy = x[j]-x[i],y[j]-y[i]
            cnt = 0
            for k in range(N):
                for l in range(N):
                    if k == l:
                        continue
                    if dx == x[k]-x[l] and dy == y[k]-y[l]:
                        cnt += 1
            ans = min(ans,N-cnt)

print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        int putFirst = 0;
        int putLast = 0;
        int nowCount = 0;

        for(int i = 0; i < N; i++){
            if(S[i] == '('){
                nowCount++;
            }
            else{
                nowCount--;
                if(nowCount == -1){
                    nowCount = 0;
                    putFirst++;
                }
            }
        }
        putLast = nowCount;

        for(int i = 0; i < putFirst; i++){
            Console.Write('(');
        }
        Console.Write(S);
        for(int i = 0; i < putLast; i++){
            Console.Write(')');
        }
        Console.WriteLine();
    }
}



Measured memory_bytes: 11092
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    deque<char> left, right;
    bool start1 = true, start2 = false, rev = false;
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            start1 = !start1;
            start2 = !start2;
            rev = !rev;
            swap(left, right);
        }
        else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                if (start1) left.push_front(c);
                else left.push_back(c);
            }
            else {
                if (start2) right.push_front(c);
                else right.push_back(c);
            }
        }
    }

    if (rev) reverse(all(s));

    string res;
    while (!left.empty()) {
        char c;
        if (start1) {
            c = left.front();
            left.pop_front();
        }
        else {
            c = left.back();
            left.pop_back();
        }
        res.push_back(c);
    }

    res.append(s);
    start2 = !start2;
    while (!right.empty()) {
        char c;
        if (start2) {
            c = right.front();
            right.pop_front();
        }
        else {
            c = right.back();
            right.pop_back();
        }
        res.push_back(c);
    }
    cout << res;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
}

Measured memory_bytes: 1328
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] a=new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    int x=0;
    int y=0;
    for(int i=0;i<n;i++){
      if(a[i]%2==0){
        x++;
        if(a[i]%3==0){
          y++;
        }else{
          if(a[i]%5==0){
            y++;
          }
        }
      }
    }
    if(x==y){
      System.out.println("APPROVED");
    }else{
      System.out.println("DENIED");
    }
  }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

int n;
cin >> n;
vi a(n);
rep(i,n) cin >> a[i];

rep(i,n) {
    if(a[i] % 2 != 0) {
        cout << "first" << endl;
        return 0;
    }
}

cout << "second" << endl;

return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    long long a[5] = {0};
    for ( int i = 0; i < N; i++ ) {
        string s;
        cin >> s;
        if ( s[0] == 'M' ) { a[0]++; }
        if ( s[0] == 'A' ) { a[1]++; }
        if ( s[0] == 'R' ) { a[2]++; }
        if ( s[0] == 'C' ) { a[3]++; }
        if ( s[0] == 'H' ) { a[4]++; }
    }
    long long ans = 0;
    for ( int i = 0; i < 5; i++ ) {
    for ( int j = i+1; j < 5; j++ ) {
    for ( int k = j+1; k < 5; k++ ) {
        ans += a[i] * a[j] * a[k];
    }
    }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

SUM=[]

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            sum = 500*i + 100*j + 50*k
            SUM.append(sum)

print(SUM.count(X))


Measured memory_bytes: 48496
#include <iostream>

using namespace std;

long long int A, B, C, D, E, F, ans[3] = {}, largest = 0;

int main() {
	cin >> A >> B >> C >> D >> E >> F;
	ans[1] = A*100;
	ans[2] = 0;
	for (int i = 1; i <= F / 100; i++) {
		if (i * 100 + C <= F) {
			for (int j = 0; j <= i / B; j++) {
				if ((i - j*B) % A == 0) {
					if (i*E + i * 100 <= F) {
						for (int k = i*E; k >= C; k--) {
							for (int l = 0; l <= i*E / D; l++) {
								if ((k - (l*D)) % C == 0) {
									if (largest < 10000 * k / (i * 100 + k)) {
										largest = 10000 * k / (i * 100 + k);
										ans[1] = i * 100 + k;
										ans[2] = k;
										if (k == i*E) {
											cout << ans[1] << " " << ans[2] << endl;
											return 0;
										}
									}
									break;
								}
							}
						}
					}
					else {
						for (int k = F - i * 100; k >= C; k--) {
							for (int l = 0; l <= (F - i * 100) / D; l++) {
								if ((k - (l*D)) % C == 0) {
									if (largest < 10000 * k / (i * 100 + k)) {
										largest = 10000 * k / (i * 100 + k);
										ans[1] = i * 100 + k;
										ans[2] = k;
									}
									break;
								}
							}
						}
					}
				}
			}
		}
		else {
			break;
		}
	}
	cout << ans[1] << " " << ans[2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long int pow107 = (int)pow(10, 9) + 7;
long int limit = LONG_MAX;

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

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

//最大limit
//10^9+7    pow107
//素数pn
//n乗jou
//コンビネーションfactorial
//
int main(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i+=2){
        cout << s[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

int main() {
	int h, w;
	char a[100][100];
	int i, j;
	char x;
	vector<int> hi, wj;

	cin >> h >> w;

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			cin >> x;
			a[i][j] = x;
		}
		hi.push_back(i);
		wj.push_back(i);
	}

	for (i = 0; i < h; i++) {
		if (a[i][0] != '.')
			continue;
		for (j = 1; j < w; j++) {
			if (a[i][j] != '.')
				break;
		}
		if (j == w) {
			hi[i] = -1;
		}
	}
	for (j = 0; j < w; j++) {
		if (a[0][j] != '.')
			continue;
		for (i = 1; i < h; i++) {
			if (a[i][j] != '.')
				break;
		}
		if (i == h) {
			wj[j] = -1;
		}
	}

	for (i = 0; i < h; i++) {
		if (hi[i] == -1)
			continue;
		for (j = 0; j < w; j++) {
			if (wj[j] == -1)
				continue;
			cout << a[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
col = []
f = [0]*8
sp = 0

for v in a:
    if v >= 3200:
        sp += 1
    else:
        f[v//400] = 1

if sum(f) > 0:
    min = sum(f)
    max = sum(f) + sp
else:
    min = 1
    max = sp
    
print(min,max)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, x; 
    cin >> n >> x;
    ll a[n];
    for(int i=0;i<n;i++){
    	cin >> a[i];

    }
    vector<ll> b;
    for(int i=1;i<n;i++){
    	b.pb(abs(a[i] - a[i-1]));
    }
    b.pb(abs(a[0] - x));
    ll g = b[0];
    for(auto& i: b){
    	g = __gcd(g, i);
    }
    cout << g << endl;
    return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll M=100000;
	int N=in();
	REP(i,N){
		ll DM = (ll)(M*1.05);
		ll f = DM%1000;
		if(f){
			DM = DM-f+1000;
		}
		M = DM;
	}
	
	out(M);
	return 0;
}


Measured memory_bytes: 3192
use whiteread::parse_line;

fn calc(n: usize, lucas: &mut Vec<usize>) -> usize {
    if lucas[n] == 0 {
        lucas[n] = calc(n - 1, lucas) + calc(n - 2, lucas)
    }
    lucas[n]
}

fn main() {
    let n: usize = parse_line().unwrap();
    let mut lucas = vec![0; n + 1];
    lucas[0] = 2;
    lucas[1] = 1;

    println!("{}", calc(n, &mut lucas));
}


Measured memory_bytes: 2192
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;


void solve()
{
	char a;
	cin>>a;
	if(a>='a' && a<='z')
		a='a';
	if(a>='A' && a<='Z')
		a='A';
	cout<<a<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    double a;
    cin >> a ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/
    
    /*
    if( a < 10 && b < 10 ){
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }
    //*/
    
    cout << ((floor(a / 2) + fmod(a, 2)) / a) << endl;
    
    //printf("%lf\n", ((a / 2 + a % 2) / a));

    return 0; 
}


Measured memory_bytes: 3836
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x) {
	S[++top] = x;
}

int pop() {
	top--;
	return S[top+1];
}

int main(void) {
	int a,b;
	char s[100];
	
	top = 0;

	while(scanf("%s",s) != EOF) {
		if(s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		} else if(s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		} else if(s[0] == '*') {
			b = pop();
			a = pop();
			push(a * b);
		} else {
			push(atoi(s));
		}
	}
	
	printf("%d\n",pop());
	
	return 0;
}

Measured memory_bytes: 548
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys
import io
import re
import math
import itertools
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.141592653589
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
#start = time.clock()
n=int(raw_input())
a=map(int,raw_input().split())
ans=chk=0
def prin(l):
    for i in l:
        print i,
    print

prin(a)
for i in range(1,n):
    v=a[i]
    j=i-1
    while(j>=0 and a[j]>v):
        a[j+1]=a[j]
        j-=1
    a[j+1]=v
    prin(a)

Measured memory_bytes: 4668
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
using namespace std;
#define MOD          1000000007
#define PI           3.14159265358979
#define rep(i, n)    for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v)   for (auto i : v)
#define all(x)       (x).begin(), (x).end()
#define rall(x)      (x).rbegin(), (x).rend()
#define pb(x)        push_back(x)
#define mp(x, y)     make_pair((x), (y))
#define fi           first
#define se           second
#define setp(x)      setprecision(x)
#define mset(m, v)   memset(m, v, sizeof(m))
#define int          long long
//static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
static const int INF =        0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef long long             ll;
typedef vector<int>           vi;
typedef vector<double>        vd;
typedef vector<long long>     vll;
typedef vector<string>        vs;
typedef vector<bool>          vb;
typedef pair<int, int>        pii;
typedef pair<long, long>      pll;
typedef vector<pii>           vpii;
typedef vector<pll>           vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
    
signed main() { 
        int a, b, c;
        cin >> a >> b >> c;
        int ans = 0;
        while (ans < 1000000 && a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
                int aa = (b + c) / 2;
                int bb = (a + c) / 2;
                int cc = (a + b) / 2;
                a = aa;
                b = bb;
                c = cc;
                ans ++;
        }
        if (ans == 1000000) cout << -1 << endl;
        else cout << ans << endl;
        return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <set>
#include <utility>
#include <numeric>
using namespace std;

#define FOR(I, J, P) \
    for(int I = P.first - 1; I <= P.first + 1; I++) \
        for(int J = P.second - 1; J <= P.second + 1; J++)

set<pair<int, int>> painted, computed;
int main() {
    int h, w, n;
    scanf("%d %d %d", &h, &w, &n);
    for(int i = 0; i < n; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--, b--;
        painted.insert(make_pair(a, b));
    }
    long long ans[10] = {};
    for(auto p : painted) {
        FOR(i, j, p) {
            if(computed.count(make_pair(i, j)))
                continue;
            computed.insert(make_pair(i, j));
            int cnt = 0;
            FOR(k, l, make_pair(i, j)) {
                if(k < 0 || k >= h || l < 0 || l >= w)
                    cnt += 100;
                else
                    cnt += painted.count(make_pair(k, l));
            }
            if(cnt <= 9)
                ans[cnt]++;
        }
    }
    ans[0] = (h - 2LL) * (w - 2) - accumulate(ans + 1, ans + 10, 0);
    for(int i = 0; i <= 9; i++)
        printf("%lld\n", ans[i]);
}



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

#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

int main()
{
    ll N, tmp;
    cin >> N;
    vector <ll> A(N+1, 0);
    map <ll, ll> num;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        A[i+1] = A[i] + tmp;
    }

    sort(A.begin(), A.end());

    ll ans = 0, now = A[0], cnt=0;
    A.emplace_back(inf);

    for (ll i = 0; i < N+2; i++) {
        if (A[i] == now) cnt++;
        else {
            ans += cnt*(cnt-1)/2;
            cnt = 1;
            now = A[i];
        }
    }

    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 4352
#3問目
import math
from decimal import *
N = int(input())
MAX = 10 ** 9 + 7
result = 1

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

Soinsuu = [0] * (N + 1)
for i in range(1, N + 1):
    factorize = prime_factorize(i)
    for j in factorize:
        Soinsuu[j] += 1

for i in Soinsuu:
    if i != 0:
        result *= i+1

print(result % MAX)

Measured memory_bytes: 62312
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
	int h,w; cin>>h>>w;
	char a[101][101];
	FOR(i,0,h)FOR(j,0,w)cin>>a[i][j];
	vector<int> hi,wi;
	FOR(i,0,h){
		int sum=0;
		FOR(j,0,w){
			sum+=(a[i][j]=='.'?0:1);
		}
		if(sum!=0) hi.PB(i);
	}
	FOR(j,0,w){
		int sum=0;
		FOR(i,0,h){
			sum+=(a[i][j]=='.'?0:1);
		}
		if(sum!=0) wi.PB(j);
	}
	FOR(i,0,hi.size()){
		FOR(j,0,wi.size()){
			cout<<a[hi[i]][wi[j]];
		}
		cout<<endl;
	}
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		
		long ans = (N/(A+B))*A;
		ans += Math.min(A, (N%(A+B)));
		System.out.println(ans);
	}
}

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

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

    int x, y;
    cin>>x>>y;
    int a = (4*x-y)/2;
    int b = (y-2*x)/2;
    int ok = (y%2==0) && (a>=0) && (b>=0);
    cout<<(ok?"Yes":"No")<<endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
int main(){
	cin>>n;
	int t=-1;
	for(int i=1;i*(i+1)<=1e5*2;i++){
		if(i*(i+1)/2==n){
			t=i;
		}
	}
	if(t==-1){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	cout<<t+1<<endl;
	int ans[t+1][t];
	int co=1;
	REP(i,t+1){
		for(int j=i;j<t;j++){
			ans[i][j]=co;
			ans[j+1][i]=co;
			co++;
		}
	}
	REP(i,t+1){
		cout<<t<<" ";
		REP(j,t){
			cout<<ans[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 2176
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
def pow_k(x, n):

    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x
def main():  #startline-------------------------------------------
    print("Yes" if int(input()) >= 30 else "No")
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 38764
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	static final long MOD = 1000000007;

	static long solve(int N, int[] T, int[] A) {
		long pat = 1;
		for (int i = 0; i < N && pat != 0; i++) {
			boolean fixed = false;
			int h = Math.min(T[i], A[i]);
			if (i > 0) {
				if (T[i-1] > T[i]) return 0;
				if (T[i-1] < T[i]) {
					if (h != T[i]) return 0;
					fixed = true;
				}
			} else {
				if (h != T[i]) return 0;
				fixed = true;
			}

			if (i < N - 1) {
				if (A[i] < A[i+1]) return 0;
				if (A[i] > A[i+1]) {
					if (h != A[i]) return 0;
					fixed = true;
				}
			} else {
				if (h != A[i]) return 0;
				fixed = true;
			}

			if (fixed) {
				// System.out.println(1);
			} else {
				// System.out.println(h);
				pat *= h;
				pat %= MOD;
			}
		}
		return pat;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] T = nextIntArray(sc, N);
		int[] A = nextIntArray(sc, N);
		System.out.println(solve(N, T, A));
	}
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	string ans = "Yes";
	if(a!=b && b!=c && c!=a){
		ans = "No";
	}
	if(a == b && b == c){
		ans = "No";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

r = ri()
print(r**2)

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

using namespace std;
using int64 = long long;

int main() {
    string s1 = "", s2;
    int q;
    cin >> s2 >> q;
    
    for (int i=0; i<q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            swap(s1, s2);
            continue;
        }

        int f;
        char c;
        cin >> f >> c;

        if (f==1)
            s1 += c;
        else
            s2 += c;
    }

    reverse(s1.begin(), s1.end());
    cout << s1+s2 << endl;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans = 0, N, K, minVal, maxVal;

vector<ll> csum;

void solve(){
    for(int k = K; k <= N+1; ++k){
        maxVal = csum[N+1] - csum[N+1-k];
        minVal = csum[k] - csum[1];
        // cout << maxVal << " - " << minVal << endl;
        ans += maxVal - minVal + 1;
        ans %= MOD;
    }

    cout << ans << endl;
}

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

    csum.resize(N+1);

    csum[0] = 0;
    rep(i, N+1) csum[i+1] = csum[i] + i;

    // cout << csum[2] << endl;

    solve();
}


Measured memory_bytes: 4820
#include<stdio.h>

int stack[100], top=0;

void push(int);
int pop(void);

int main(){
  int i, num;
  char data;
  
  while(scanf("%c",&data)!=EOF && data!='\n'){

    //+
    if(data=='+'){
      num=pop()+pop();
      push(num);
    }

    
    //-
    else if(data=='-'){
      num=pop()-pop();
      num*=-1;
      push(num);
    }

    
    //*
    else if(data=='*'){
      num=pop()*pop();
      push(num);
    }

    //numbers
    else if(data>='0' && data<='9'){
      num=data-'0';
      while(scanf("%c",&data)!=EOF && data!=' '){
	num*=10;
	num+=data-'0';
      }
      push(num);
    }


  }
  
  printf("%d\n",pop());
  return 0;
}


void push(int data){
  stack[top]=data;
  top++;
}

int pop(void){
  return stack[--top];
}



Measured memory_bytes: 2096
#include <stdio.h>

int main(){

  int a,b;  
  scanf("%d %d",&a,&b);
 
  if(a < b){
    printf("a < b\n");
  }

  if(a == b){
    printf("a == b\n");
  }

  if(a > b){
    printf("a > b\n");
  }
  
 

  return 0; 
}

Measured memory_bytes: 580
# Merge Sortを元に分割統治で反転数を求める
cnt = 0
def merge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = [A[i] for i in range(left, mid)]
    R = [A[i] for i in range(mid, right)]
    L.append(float("inf"))
    R.append(float("inf"))
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
# R[j]について，Lに含まれマージ後にR[j]よりも後に移動するような要素の数
            cnt += n1 - i
            A[k] = R[j]
            j += 1

def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)

input()
a = list(map(int, input().split()))
merge_sort(a, 0, len(a))
print(cnt)


Measured memory_bytes: 27696