akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  if(x->left==NIL)
    return x;
  else
    return treeMinimum(x->left);

}

Node treeMaximum(Node x){
  if(x->right==NIL)
    return x;
  else
    return treeMaximum(x->right);
  

}

Node treeSearch(Node u, int k){
  if(u==NIL)
    return u;
  
  else if(u->key>k)
    return treeSearch(u->left,k);
  else if(u->key<k)
    return treeSearch(u->right,k);
  else
    return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    return treeMinimum(x->right);
  y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
  y=y->parent;
}
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)
    y=z;
  else
    y=treeSuccessor(z);
  if(y->left!=NIL)
    x=y->left;
  else
    x=y->right;
  if(x!=NIL)
    x->parent=y->parent;
  if(y->parent==NIL)
    root=x;
  else if(y==y->parent->left)
    y->parent->left=x;
  else
    y->parent->right=x;
  if(y!=z)
    z->key=y->key;


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node np,z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  if(x==NULL){
    root=z;
    root->parent=NIL;
  }
  else{
  
  for(np=x;;){
    if(np->key>k){
      if(np->left!=NIL)
      np=np->left;
      else{
	np->left=z;
	break;
      }
    }
    else{
      if(np->right!=NIL){
	np=np->right;
	}
    else{
      np->right=z;
      break;
    }
	}
  }
  z->parent=np;
  }

}

void inorder(Node u){
  if (u==NIL)
    return;
  inorder(u->left);
    printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)
    return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20472
#include <bits/stdc++.h>
using namespace std;
#define int LL
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "


int32_t main()
  {
  ios_base::sync_with_stdio(0); 
  LL n;
  cin >> n;
  string ans;

  LL pot = 1;
  FOR(l, 0, 20)
    {
    if(n < pot)
      {
      pot /= 26;
      debug(pot);
      while(pot != 0)
        {
        char c = 'a' + (n / pot) % 26;
        if(c < 'a')c = 'z';
        ans += c;
        pot /= 26;
        }
      break;
      }
    else n -= pot;
    pot *= 26;
    }
  cout << ans << endl;
  }


Measured memory_bytes: 3652
import sys
bbn=1000000007
	
#+++++
		
def main():
	a, b, k = map(int, input().split())
	ret_a=a
	ret_b=b
	if a >= k:
		print(str(a-k)+' '+str(b))
	elif a+b >= k:
		print('0 '+str(a+b-k))
	else:
		print('0 0')
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; i++) cin >> a[i];

    ll sum[n + 1];
    sum[0] = 0;
    for (int i = 1; i <= n; i++) {
        sum[i] = sum[i - 1] + a[i - 1];
    }

    ll ans = 0;

    map<ll, int> cnt;
    for (int i = 0; i <= n; i++) {
        ans += cnt[sum[i]];
        cnt[sum[i]]++;
    }

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

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

const int MAX_N=1000;
int n, a[MAX_N];

int MAX(){
	int ma=0;
	for(int i=0;i<n;i++){
		ma=max(ma, a[i]);
	}
	return ma;
}

int MIN(){
	int mi=MAX_N;
	for(int i=0;i<n;i++){
		mi=min(mi, a[i]);
	}
	return mi;
}

int main(){
	cin >> n;
	for(int i=0;i<n;i++){		
		cin >> a[i];
	}
	
	cout << MAX()-MIN() << endl;
	return 0;
}


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

def main():
    n=int(input())
    a=[0 for _ in range(n)]
    for i in range(n):
        a[i]=int(input())
    check={}
    for i in a:
        if not (i in check):
            check[i]=1
        elif(check[i]==1):
            check[i]=0
        elif(check[i]==0):
            check[i]=1
    ans=0
    for i in check:
        if(check[i]==1):
            ans+=1
 
    print(ans)
    
    
main()


Measured memory_bytes: 16292
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,num[100005],ans,cnt;
int minv=1e9+5;
inline int sabs(int a) {
	return a<0?-a:a;
} 
signed main() {
	cin>>n;
	for (int i=1;i<=n;++i) cin>>num[i];
	for (int i=1;i<=n;++i) {
		ans+=fabs(num[i]);
		if (num[i]<0) ++cnt;
	}
//	cout<<cnt<<endl;
	if (!(cnt%2)) {
		cout<<ans<<endl;
		return 0;
	}
	else {
		for (int i=1;i<=n;++i) {
			minv=min(minv,sabs((int)(num[i]+num[i])));
		}
		cout<<ans-minv<<endl;
		return 0;
	}
}
/*
3
-10 5 -4

19
*/

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

int main() {
  int A,B,C,D  ;
cin >> A >>B>>C>>D  ;
if (A+B==C+D)
 cout << "Balanced";
else if (A+B>C+D)
 cout << "Left";
else 
 cout << "Right";
 


}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
using namespace std;
vector<int>G[200005];
int main()
{
    int n,m;
    int x,y;
    bool flag;
    int count;
    scanf("%d%d",&n,&m);
    flag=false;
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&x,&y);
        G[x].push_back(y);
        G[y].push_back(x);
    }
    for(int i=0;i<G[1].size();i++)
    {
        if(G[1][i]==n)
        {
            printf("POSSIBLE\n");
            return 0;
        }
        else
        {
            int j=G[1][i];
            for(int k=0;k<G[j].size();k++)
            {
                if(G[j][k]==n)
                {
                    printf("POSSIBLE\n");
                    return 0;
                }
            }
        }
    }
    printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 12016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(0, a - 2 * b) << endl;
    return 0;
}


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

int64_t push1(int64_t x){
  int64_t a=x%10-1;
  if(a==-1) return 5000000000;
  else return 10*x+a;
}
int64_t push2(int64_t x){
  int64_t a=x%10;
  return 10*x+a;
}
int64_t push3(int64_t x){
  int64_t a=x%10+1;
  if(a==10) return 50000000000;
  else return 10*x+a;
}

int main() {
  vector<int64_t> vec,vec2,vec3,vec4,vec5,vec6,vec7,vec8,vec9,vec10;
  rep(i,9){
    vec.push_back(push1(i+1));
    vec.push_back(push2(i+1));
    vec.push_back(push3(i+1));
  }
  for(int64_t i:vec){
    vec2.push_back(push1(i));
    vec2.push_back(push2(i));
    vec2.push_back(push3(i));
  }
  for(int64_t i:vec2){
    vec3.push_back(push1(i));
    vec3.push_back(push2(i));
    vec3.push_back(push3(i));
  }
  for(int64_t i:vec3){
    vec4.push_back(push1(i));
    vec4.push_back(push2(i));
    vec4.push_back(push3(i));
  }
  for(int64_t i:vec4){
    vec5.push_back(push1(i));
    vec5.push_back(push2(i));
    vec5.push_back(push3(i));
  }
  for(int64_t i:vec5){
    vec6.push_back(push1(i));
    vec6.push_back(push2(i));
    vec6.push_back(push3(i));
  }
  for(int64_t i:vec6){
    vec7.push_back(push1(i));
    vec7.push_back(push2(i));
    vec7.push_back(push3(i));
  }
  for(int64_t i:vec7){
    vec8.push_back(push1(i));
    vec8.push_back(push2(i));
    vec8.push_back(push3(i));
  }
  for(int64_t i:vec8){
    vec9.push_back(push1(i));
    vec9.push_back(push2(i));
    vec9.push_back(push3(i));
  }
  vec10={1,2,3,4,5,6,7,8,9};
  vector<int64_t> fial;
  for(int64_t x:vec10) fial.push_back(x);
  for(int64_t x:vec) fial.push_back(x);
  for(int64_t x:vec2) fial.push_back(x);
  for(int64_t x:vec3) fial.push_back(x);
  for(int64_t x:vec4) fial.push_back(x);
  for(int64_t x:vec5) fial.push_back(x);
  for(int64_t x:vec6) fial.push_back(x);
  for(int64_t x:vec7) fial.push_back(x);
  for(int64_t x:vec8) fial.push_back(x);
  for(int64_t x:vec9) fial.push_back(x);
  sort(fial.begin(),fial.end());
    
  int k;
  cin >> k;
  cout << fial.at(k-1) << endl;
}


Measured memory_bytes: 8592
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;

#define ll              long long
#define int             long long
#define ld             long double
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vi>
#define vip            vector<pii>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define lb(x)           (x&(-x))
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define itr(it,v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fir(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff               first 
#define ss               second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);

const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0,  1, -1, 1, -1, 0, 1 };

int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);

const int N=5*(1e5)+10;
vii adj(N);
int a[N],ind[N];

void  solve(){

}
void dfs(int s,int vis[],int a[]){
    vis[s]=1;
    for(auto u:adj[s]){
        if(!vis[u]) dfs(u,vis,a);
         a[s]=max(a[s],a[u]+1);
    }
}
int32_t main()
{
    FIO
    int n,m; cin>>n>>m;
    fi(i,n) ind[i]=0;
    ipgraph(m);
    int a[n+1]={0},vis[n+1]={0};
    int idx=-1;
    vi v;
    for(int i=0;i<n;i++){
        if(ind[i]==0){
            v.pb(i);
        }
    }
    itr(it,v){
        // cout<<it<<"\n";
        if(vis[it]==0) dfs(it,vis,a);
    }
    int maxz=0;
    fi(i,n) maxz=max(a[i],maxz);
    cout<<maxz<<"\n";
    return 0;

}

void ipgraph(int m){
    int i, u, v;
    while(m--){
          cin>>u>>v;
         u--, v--;
    adj[u].pb(v);
    ind[v]++;
    // adj[v].pb(u);
    }
}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}

Measured memory_bytes: 23680
#include <cstdio>

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <array>

#include <boost/format.hpp>
#include <boost/range/irange.hpp>

int main() {
   int a, b, c;
   ::scanf("%d %d %d", &a, &b, &c);
   if (a + b + c >= 22) {
      std::cout << "bust\n";
   } else {
      std::cout << "win\n";
   }
   return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

const int M = 100000;
LL n, c, x[M + 2], v[M + 2];

LL a[M + 2], b[M + 2];
LL f() {
	LL s = 0;
	inc1(i, n) {
		s += v[i] - abs(x[i] - x[i - 1]) * 2;
		a[i] = max(s, a[i - 1]);
	}
	
	s = 0;
	dec1(i, n) {
		s += v[i] - abs(x[i] - x[i + 1]);
		b[i] = max(s, b[i + 1]);
	}
	
	LL ans = 0;
	incII(i, 0, n) { setmax(ans, a[i] + b[i + 1]); }
	
	return ans;
}

void flip() {
	inc(i, (n + 2) / 2) {
		swap(x[i], x[n + 1 - i]);
		swap(v[i], v[n + 1 - i]);
	}
	inc(i, n + 2) { x[i] = c - x[i]; }
}

int main() {
	cin >> n >> c;
	x[0] = 0; v[0] = 0;
	inc1(i, n) { cin >> x[i] >> v[i]; }
	x[n + 1] = c; v[n + 1] = 0;
	
	LL ans = 0;
	setmax(ans, f()); flip();
	setmax(ans, f());
	
	cout << ans << endl;
	
	return 0;
}


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

int main () {
  int i, min=INT_MAX, N, X, v, sum;
  
  cin >> N >> X;
  
  rep(i,N){
    cin >> v;
    if(v<min)min=v;
    X -= v;
  }
  
 
  cout << N + X/min;
}







Measured memory_bytes: 3612
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
vector<vector<int> > G(100005);
int col[100005];
bool dfs(int v) {
  for(int to : G[v]) {
    if(col[to] == -1) {
      col[to] = col[v] ^ 1;
      if(!dfs(to)) return false;
    } else {
      if(col[to] == col[v]) return false;
    }
  }
  return true;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M; cin >> N >> M;
  FOR(i,0,M) {
    int a, b; cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  FOR(i,0,N+1) col[i] = -1;
  col[1] = 0;
  // 2部グラフ
  if(dfs(1)) {
    ll x = 0;
    FOR(i,1,N+1) if(col[i] == 0) x++;
    cout << x * (N - x) - M << endl;
  } else {
    cout << N * (N - 1) / 2 - M << endl;
  }
  return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
map<int,int> t;
int n,m,x;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&x),t[x]++;
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		scanf("%d",&x);
		t[x]--;
		if(t[x]<0){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}

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

int main()
{
	int a, b, i = 10;
	while (cin >> a >> b) {
		for (int j = 1;; j++) {
			if (a + b < (int)pow(10, j)) {
				cout << j << endl; 
				break;
			}
		}
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
#define max(a,b) (a)>=(b)? (a) : (b) 
#define fileio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
const double pi = 3.14159265358979323846;



#define F first
#define S second
const int MX = 1e5 + 10, MD = 1e9 + 7;
long long n, m, a[MX], ans, tmp, mx, t1, t2, ind, res;
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] > mx) {
			mx = a[i];
			ind = i;
		}
	}
	ans = mx + 1;
	ll t = 50000000000000;
	for (ll i = 0; i < pow(10, 9); )
	{
		printf("");
		i++; t /= abs(t-i);
	}
	if (mx % 2 == 0) {
		t1 = mx / 2;
		for (int i = 0; i < n; i++) {
			if (ind == i)continue;
			if (abs(a[i] - t1) < ans) {
				ans = abs(a[i] - t1);
				res = a[i];
			}
		}
	}
	else {
		t1 = mx / 2;
		t2 = mx / 2 + 1;
		for (int i = 0; i < n; i++) {
			if (ind == i)continue;
			if (abs(a[i] - t1) < ans) {
				ans = abs(a[i] - t1);
				res = a[i];
			}
			else if (abs(a[i] - t2) < ans) {
				ans = abs(a[i] - t2);
				res = a[i];
			}
		}
	}
	cout << mx << " " << res;

}






Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
template<typename T>
T gcd(T a, T b){
	return b != 0 ? gcd(b, a % b) : a;
}    
template<typename T>
T lcm(T a, T b){
    return a/gcd(a,b)*b;
}       

int main(){
    int c=0,d=0,di=0,n,h,w,l,r,min=0,ptr=0;
    string s,s1,s2;
    cin >> n;
    min = n;
    for(int i=0;i<=n; i++){
        c=0;
        di=i;
        while(di>0)
            c += di%6 , di /= 6;
        di = n - i;
        while(di>0)
            c += di%9 , di /= 9;

        if(min > c)
            min = c;
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;
int main(){
  int a,b;
  bool flag = true;
  string s;
  cin >> a >> b >> s;
  if(s[a] != '-') flag = false;
  for(int i=0;i<a+b+1;i++){
    if(i == a) continue;
    if(s[i] >= '0' && s[i] <= '9') continue;
    flag = false;
  } 
  if(flag) std::cout << "Yes" << endl;
  else std::cout << "No" << endl;
}

Measured memory_bytes: 256
#define		_CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

#define		MAX			1200

int main()
{
	int		moji['z' - 'a' + 1] = { 0 };
	char	m;

	while (cin >> m)
	{
		if (('A' <= m) && (m <= 'Z'))
		{
			m = tolower(m);
		}

		if (('a' <= m) && (m <= 'z'))
		{
			moji[m - 'a']++;
		}
	}

	for (char c = 'a'; c <= 'z'; c++)
	{
		printf("%c : %d\n", c, moji[c - 'a']);
	}


	return 0;
}

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

int main() {
	int N,K,h;
	int count=0;
	cin>>N>>K;	
	vector<int> vec(N);
	
	for(int i=0; i<N;i++){
		cin>>h;
		vec[i]=h;
	}
	for(int i=0; i<N; i++){
		if(vec[i]>=K)count++;
	}
	cout<<count<<endl;
}


Measured memory_bytes: 640
#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;
typedef long long ll;




int main()
{

    int x;
    cin >> x;
    if (x == 7 || x == 5 || x == 3) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    
    return 0;
}



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

typedef pair<double, int> pdi;
const int MAX = 2e5+10;

int n, U[MAX], P[MAX], V[MAX], C[MAX][2];
double e = 1e-9;
int find(int x){ return x==U[x] ? x : U[x]=find(U[x]); }

priority_queue<pdi> Q;

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

	cin>>n;
	for(int i=2; i<=n; i++) cin>>P[i];
	for(int i=1; i<=n; i++) cin>>V[i], C[i][V[i]]++;
	for(int i=1; i<=n; i++) U[i] = i;
	for(int i=2; i<=n; i++) Q.push({C[i][0]/(C[i][1]+e), i});

	long long ans = 0;
	while(!Q.empty()){
		double d; int v; tie(d,v) = Q.top();
		int p = find(P[v]); Q.pop();
		if(d != C[v][0]/(C[v][1]+e) || v!=find(v)) continue;

		ans += 1LL * C[v][0] * C[p][1];
		C[p][0] += C[v][0], C[p][1] += C[v][1];

		if(p!=1) Q.push({C[p][0]/(C[p][1]+e), p});
		U[find(v)] = p;
	}
	cout<<ans<<'\n';

	return 0;
}

Measured memory_bytes: 10352
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
 
int main(void) {
    int a, b;
    cin >> a >> b;
    if(b % a == 0){
        cout << a + b << endl;
    }else{
        cout << b - a << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
from itertools import permutations

N,M = map(int,input().split())

Matrix = [[False for x in range(N)] for y in range(N)]
for i in range(N) :
    Matrix[i][i] = True
for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    Matrix[a][b] = True
    Matrix[b][a] = True

arange = permutations(range(1,N))
ans = 0
for i in arange :
    pm = [0] + list(i)
    for a,b in zip(pm, pm[1:]) :
        if not Matrix[a][b] :
            break
    else :
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int count,count2;
    int n;
    int r=0,b=0,w;
    int a[105];
    double sum=0;
  	double bunbo=0;
    char s[1050];
    scanf("%d",&n);
    for(count=1;count<=n;count++){
        scanf("%d",&a[count]);
    }
    for(count=1;count<=n;count++){
        bunbo=bunbo+1.0/a[count];
    }
  sum=1.0/bunbo;
    printf("%lf\n",sum);
    return 0;
}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	r := intScanner()
	g := intScanner()
	fmt.Println(g + (g - r))
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;

int main(){
    ll N,K; cin>>N>>K;
    string s; cin>>s;
    ll x = 0;
    ll y = 0;
    for(int i=0;i<N-1;++i){
        if(i==0 && s[i]=='L'){
            ++y;
        }
        else if(s[i]=='R' && s[i+1]=='L'){
            ++x; 
        }
    }
    if(s[N-1]=='R'){
        ++y;
    }
    if(K>x){
        K -= x;
        x = 0;
        y = max( y-K ,0LL);
    }else{
        x -= K;
    }
    ll ans = min(N-x*2-y,N-1);
    cout << ans << "\n";
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--q >= 0){
        int n;
        cin >> n;

        int ret = 0;
        while(n >= 10){
            ++ ret;

            int maxNum = -1;
            int tmp = 10;
            while(tmp < n){
                maxNum = max(maxNum, (n % tmp) * (n / tmp));
                tmp *= 10;
            }
            n = maxNum;
        }

        cout << ret << endl;
    }

    return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	for(int i = 0; i < n; ++i){ cin >> x[i] >> y[i]; }
	int answer = n;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			if(i == j){ continue; }
			const int p = x[j] - x[i], q = y[j] - y[i];
			int skip = 0;
			for(int k = 0; k < n; ++k){
				for(int l = 0; l < n; ++l){
					if(k == l){ continue; }
					if(x[l] - x[k] == p && y[l] - y[k] == q){ ++skip; }
				}
			}
			answer = min(answer, n - skip);
		}
	}
	cout << answer << endl;
	return 0;
}



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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    ll a,b; scanf("%lld%lld",&a,&b);
    ll g=__gcd(a,b); ll p=2,cnt=0;
    while(g!=1&&g>=p*p){
        if(g%p==0){
            cnt++; 
            while(g%p==0)g/=p;
        }
        p++;
    }
    if(g!=1)cnt++;
    printf("%lld\n",cnt+1);
    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint dp[2016][2016];
lint inv[4114514];
vector<lint> zyo,rz;
lint mo=1000000007;
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
lint co(int a,int b){
	if(a<0 || b<0 || b>a) return 0;
	return ((zyo[a]*rz[b])%mo*rz[a-b])%mo;
}
int main()
{
	int n,k;
	cin>>n>>k;
	if(k==1 || n==1){
		cout<<1<<endl;return 0;
	}
	inv[1]=1;
	REP(i,2,4114510) inv[i]=inv[mo%i]*(mo-mo/i)%mo;
	zyo.pb(1);rep(i,4114514) zyo.pb((zyo[i]*(i+1))%mo);
	rz.pb(1);rep(i,zyo.size()) rz.pb((rz[i]*inv[i+1])%mo);
	memset(dp,0,sizeof(dp));dp[0][0]=1;
	rep(i,n+1) rep(j,i+1){
		//cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
		dp[i][j]%=mo;
		if(i<n) dp[i+1][j]+=dp[i][j];
		if(j<i) dp[i][j+1]+=dp[i][j]*co(n*k-i-j*(k-1)-1,k-2);
	}
	cout<<(dp[n][n]*zyo[n])%mo<<endl;
}


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int ans = 0;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; k <= C; k++) {
        if (500 * i + 100 * j + 50 * k == X)
          ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	int N;
	int A;
	cin >> N;
	vector<int>B(N, 0);
	for (int i = 0; i < N; ++i) {
		cin >> A;
		B[i] += A - (i + 1);
	}
	sort(B.begin(), B.end());
	ll ans = 0;
	ll b;
	if (N % 2) {
		b = B[N / 2];
		for (int i = 0; i < N; ++i) {
			ans += abs(B[i] - b);
		}
		cout << ans << endl;
	}
	else {
		b = round((B[N / 2] + B[N / 2 - 1]) / 2);
		for (int i = 0; i < N; ++i) {
			ans += abs(B[i] - b);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
// Problem : F - LCS
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define ff first
#define fs second
#define lb lower_bound
#define ub upper_bound

#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector< vi >
#define vpii vector< pii >
#define vb vector<bool>
#define si set<int>
#define mii map<int, int>
#define mci map<char, int>
#define md 1000000007
#define pb push_back
#define eb emplace_back
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL);  cout.tie (NULL);
#define qw1(x) cerr<<#x<<": "<<x<<" "<<endl
#define qw2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define qw3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define qw4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl


#define f(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define rl(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define all(x) x.begin(),x.end()
#define endl '\n'
void printv(vector<int>  v){ for(int i=0;i<v.size();i++) cout<<v[i]<<' '; cout<<endl;   }
int bem(int m , int n, int mod) { int res=1; while(n){
	     			        if(n%2!=0) { res*=m; res%=mod; }
	    			        m*=m;   m%=mod;   n/=2;
			                          }
				return res;	}
int be(int a, int b) { int res=1; 	while(b){
				if(b%2!=0) res*=a;
				a*=a; b/=2;
				}
			return res;	}
void sieve(int n, vb &prime){
    prime[0]=false;     prime[1]=false;
    for(int i=2;i*i<=n;i++){
         if(prime[i]==true){
              for(int j=i*i;j<=n;j+=i)    prime[j]=false;
             	  }
    	 }
	}
string s, t;
vvi dp;
void solve()
  {
s.clear();
t.clear();
cin>>s>>t;
int a=s.size(); int b=t.size();
dp.resize(a+2, vi(b+2, 0));
f(i, 1, a)
{
	f(j, 1, b)
	{
		if(s[i-1]==t[j-1]) dp[i][j]=1+dp[i-1][j-1];
		else dp[i][j]=max(dp[i][j-1], dp[i-1][j]);
	}
}
// f(i,1,a) { f(j, 1, b) cout<<dp[i][j]<<' '; cout<<endl;}
int z=dp[a][b];
int l=a, h=b; string ans(z--,' '); int cnt=0;
while(l>=1 && h>=1)
{
	if(s[l-1]==t[h-1]) {ans[z--]=s[l-1]; l--; h--; }
	else if(dp[l-1][h] > dp[l][h-1]) l--;
	else h--;
}
cout<<ans<<endl;



  }

int32_t main ()
{
//fio
int tt=1; 
//cin>>t; 
while(tt--){
	solve();
}
 
}








Measured memory_bytes: 70784
r,c = [int(x) for x in input().split()]
s_row = [0 for x in range(c+1)]
for i in range(r):
    row = [int(x) for x in input().split()]
    row.append(sum(row))
    print(" ".join([str(x) for x in row]))
    s_row = [x+y for x,y in zip(s_row,row)]
print(" ".join([str(x) for x in s_row]))


Measured memory_bytes: 5624
N,K=map(int,input().split())

S=list(input())

eng=["a","b","c"]
ENG=["A","B","C"]

x=ENG.index(S[K-1])
S[K-1]=eng[x]

s=""
for i in range(len(S)):
    s+=S[i]
print(s)


Measured memory_bytes: 9004
import sys

def revBit(Ai):
    return '1' if Ai == '0' else '0'

def rec(binA, binB):
    if len(binA) == 1:
        return [binA, binB]

    for i, (Ai, Bi) in enumerate(zip(binA, binB)):
        if Ai != Bi:
            x = i
            Ax, Bx = Ai, Bi
            break

    binA2 = binA[:x] + binA[x+1:]
    binB2 = binB[:x] + binB[x+1:]
    binC = binA2[:-1] + revBit(binA2[-1])

    ptn1s = rec(binA2, binC)
    ptn2s = rec(binC, binB2)

    ptns = []
    for ptn1 in ptn1s:
        ptns.append(ptn1[:x] + Ax + ptn1[x:])
    for ptn2 in ptn2s:
        ptns.append(ptn2[:x] + Bx + ptn2[x:])

    return ptns


N, A, B = map(int, input().split())

binA, binB = bin(A)[2:].zfill(N), bin(B)[2:].zfill(N)
numDiff = sum([Ai != Bi for Ai, Bi in zip(binA, binB)])

if numDiff % 2 == 0:
    print('NO')
    sys.exit()

ptns = rec(binA, binB)
print('YES')
print(' '.join([str(int(ptn, 2)) for ptn in ptns]))


Measured memory_bytes: 24208
#include<bits/stdc++.h>
using namespace std;
int main(){
  int l,r,d,x,y;
  cin >> l >> r >> d;
  x = l/d;
  y = r/d;
  if(l%d==0){
    cout << y-x+1 << endl;
  }else{
  cout << y-x << endl;
}
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>

using namespace std;

int main() {

	string N, K;
	cin >> N;

	//vector<int> vNum(N, 0);
	//for (int i = 0; i < vNum.size(); i++)
	//{
	//	cin >> vNum[i];
	//}

	map<char, int> mapper;
	bool aa = false;
	int count = 0;
	for (int i = 0; i < N.length(); i++)
	{
		int counter = 0;
		for (int j = 0; j < N.length(); j++)
		{
			if (N[i] == N[j])
			{
				++counter;
			}
		}
		if (counter != 2)
		{
			aa = true;
			break;
		}
		mapper.insert(make_pair(N[i], 1));
	}
	if (mapper.size() != 2)
	{
		aa = true;
	}

	cout << (aa ? "No" : "Yes" ) << endl;

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

typedef long long ll;

using namespace std;

int getOrder(vector<int> &v, int n);

int getNth(int v, vector<int> &used);

int factorial(int i);

int main() {
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  rep(i, N) {
    cin >> P[i];
  }
  rep(i, N) {
    cin >> Q[i];
  }

  int order1 = getOrder(P, N);
  int order2 = getOrder(Q, N);

  int result = abs(order1 - order2);
  cout << result << endl;

  return 0;
}

int getOrder(vector<int> &v, int n) {
  int order = 0;
  vector<int> used;
  rep(i, n) {
    int target = v[i];
    int nth = getNth(target, used);
    order += (nth - 1) * factorial(n - 1 - i);
    used.push_back(target);
  }
  return order;
}

int factorial(int i) {
  if (i == 0) {
    return 1;
  }
  return i * factorial(i - 1);
}

int getNth(int v, vector<int> &used) {
  int result = v;
  for (int c : used) {
    if (c < v) {
      result--;
    }
  }
  return result;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def list_lcm(number_list):
    lcm_number = 1
    for j in number_list:
        lcm_number = lcm(lcm_number, j)

    return lcm_number


def list_gcd(number_list):
    gcd_number = number_list[0]
    for i in number_list:
        gcd_number = gcd(gcd_number, i)

    return gcd_number


if __name__ == '__main__':
    n = input()
    number_list = list(map(int, input().split()))
    print(list_gcd(number_list))


Measured memory_bytes: 14480
#include<stdio.h>
int isinThree(int n) {
	while(n > 0) {
		if (n % 10 == 3) {
			return 1;
		}
		n /= 10;
	}
	return 0;
}
int main () {
	int n;
	int i;
	scanf("%d" , &n);
	for(i = 3; i <= n; i++) {
		if (i % 3 == 0 || isinThree(i)) {
			printf(" %d" , i);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int a;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int q;
  cin >> q;
  rep(_,q){
    ll a,b;
    cin >> a >> b;
    ll l = min(a,b),r=max(a,b);
    while(l+1<r){
      ll x = (l+r)/2;
      if(x*x<a*b){
        l = x;
      }else{
        r = x;
      }
    }
    ll ans = 2*l-2;
    if(l*(l+1)<a*b) ++ans;
    cout << ans << endl;
  }
}

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

int main() {
	int d;
	cin>>d;
	if(d<=25)
	  {
	  	cout<<"Christmas";
	  }
	if(d<=24)
	  {
	  	cout<<" Eve";
	  }
	if(d<=23)
	  {
	  	cout<<" Eve";
	  }
	if(d<=22)
	  {
		cout<<" Eve";	  	
	  }  
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <string>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<ll> VL;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)

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

  ll N, K;
  cin >> N >> K;

  double ans = 0;

  double ruiseki[K];
  ruiseki[0] = 1.0/2;
  for (ll i = 1; i < K; ++i) {
    ruiseki[i] = ruiseki[i-1] / 2.0;
  }

  ll nums[N];
  for (ll i = 0; i < N; ++i) {
    ll num = 0;
    ll val = i + 1;
    while (true) {
      if (val < K) {
        val *= 2;
        ++num;
      } else {
        nums[i] = num - 1;
        break;
      }
    }
  }

  for (ll i = N; i > 0; --i) {
    if (i >= K) {
      ans += (1.0 / N);
    } else {
      ll num = nums[i-1];
      ans += (1.0 / N) * ruiseki[num];
    }
  }

  cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 1152
N = int(input())

isPrime = [True]*(N+1)

isPrime[0] = False
isPrime[1] = False

for i in range(2, N + 1):
    if isPrime[i]:
        for j in range(2*i, N + 1, i):
            isPrime[j] = False


factors = []

for p in range(2, N+1):
    if not isPrime[p]:
        continue

    f = 0
    base = p
    while base <= N:
        f += N // base
        base *= p

    if f > 0:
        factors.append(f)

ans = 1
m = 10**9 + 7
for f in factors:
    ans *= (f+1)
    if ans >= m:
        ans %= m

print(ans)


Measured memory_bytes: 39024
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#include <stack>
#include <algorithm>
typedef long long int ll;
using namespace std;

int gcd(int a,int b)
{
    return b==0? a:gcd(b, a%b);
}
int main(){
    //freopen("/Users/mac/Desktop/C++?¨????/test/test.txt", "r", stdin);
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n",gcd(a, b));
    return 0;
}

Measured memory_bytes: 3216
N = int(input())
A = [int(a) for a in input().split(" ")]
swapnum = 0
for i in range(N):
    mini = i
    swap = False
    for j in range(i, N):
        if A[j] < A[mini]:
            mini = j
            swap = True
    if swap:
        tmp = A[i]
        A[i] = A[mini]
        A[mini] = tmp
        swapnum += 1
print(" ".join([str(a) for a in A]))
print(swapnum)

Measured memory_bytes: 7748
local mfl, mce = math.floor, math.ceil
local msq = math.sqrt
local function getprimes(x)
  local primes = {}
  local allnums = {}
  for i = 1, x do allnums[i] = true end
  for i = 2, x do
    if allnums[i] then
      table.insert(primes, i)
      local lim = mfl(x / i)
      for j = 2, lim do
        allnums[j * i] = false
      end
    end
  end
  return primes
end

local primes = getprimes(mce(msq(1000000)))

local function getdivisorparts(x)
  local prime_num = #primes
  local tmp = {}
  local lim = mce(msq(x))
  local primepos = 1
  local dv = primes[primepos]
  while primepos <= prime_num and dv <= lim do
    if x % dv == 0 then
      local t = {}
      t.p = dv
      t.cnt = 1
      x = mfl(x / dv)
      while x % dv == 0 do
        x = mfl(x / dv)
        t.cnt = t.cnt + 1
      end
      table.insert(tmp, t)
      lim = mce(msq(x))
    end
    if primepos == prime_num then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if x ~= 1 then
    local t = {}
    t.p, t.cnt = x, 1
    table.insert(tmp, t)
  end
  return tmp
end

local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local t = {}
local test1 = false
for i = 1, n do
  local dvp = getdivisorparts(a[i])
  for j = 1, #dvp do
    local k = dvp[j].p
    if t[k] then
      test1 = true break
    else
      t[k] = true
    end
  end
  if test1 then break end
end
if not test1 then
  print("pairwise coprime")
  os.exit()
end
local gcd = a[1]

local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end

for i = 2, n do
  gcd = getgcd(gcd, a[i])
  if gcd == 1 then
    print("setwise coprime") os.exit()
  end
end
print("not coprime")


Measured memory_bytes: 21020
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

N = int(input())
L = [input() for _ in range(N)]

up = []
do = []
for li in L:
    l = li.count("(")
    r = li.count(")")
    ext_neg = 0
    ext_pos = 0
    tl, tr = 0, 0
    if 0 <= l - r:
        for op in li:
            if op == "(":
                tl += 1
            elif op == ")":
                tr += 1
            ext_neg = min(ext_neg, tl - tr)
            ext_pos = max(ext_pos, tl - tr)
        up.append((l - r, ext_neg, ext_pos))
    else:
        for op in li[::-1]:
            if op == ")":
                tl += 1
            elif op == "(":
                tr += 1
            ext_neg = min(ext_neg, tl - tr)
            ext_pos = max(ext_pos, tl - r)
        do.append((r - l, ext_neg, ext_pos))
up.sort(key=lambda tup: (-tup[1], -tup[0]))
do.sort(key=lambda tup: (-tup[1], -tup[0]))
# print(up)
# print(do)

curl = 0
for upi in up:
    dif, ext_neg, ext_pos = upi
    if curl + ext_neg < 0:
        print("No")
        exit()
    curl += dif
curr = 0
for doi in do:
    dif, ext_neg, ext_pos = doi
    if curr + ext_neg < 0:
        print("No")
        exit()
    curr += dif
if curl == curr:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 276424
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner stdin = new Scanner(System.in);
	int a = stdin.nextInt();
	int b = stdin.nextInt();
	int c = stdin.nextInt();
	int ab = b-a;
	int bc = c-b;
	if(ab>0){
	    if(bc<0){
		bc = -bc;
		if(bc>ab){
		System.out.println(c+" "+a+" "+b);
		}
	        else{
		    System.out.println(a+" "+c+" "+b);
		}
	    }
	    else{
		System.out.println(a+" "+b+" "+c);
	    }
	}else{
	    ab = -ab;
	    if(bc>0){
		if(bc>ab){
		    System.out.println(b+" "+a+" "+c);
		}else{
		    System.out.println(b+" "+c+" "+a);
		}
	    }else{
		System.out.println(c+" "+b+" "+a);
	    }
	}
    }
}

Measured memory_bytes: 26096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
int main(void)
{
    int A,B,C;
    cin>>A>>B>>C;

    if(A==B&&B!=C)cout<<"Yes"<<endl;
    else if ( A==C&&C!=B)cout <<"Yes"<<endl;
    
    else if(B==C&&C!=A)cout <<"Yes"<<endl;
    else cout <<"No"<< endl;
    return 0;
}
 

Measured memory_bytes: 256