akhauriyash/Code-Regression huggingface dataset:
//2020.1.9
//s1270188 xxxmk2
//alds1_08c

#include<stdio.h>
#include<stdlib.h>

//struct
struct node{
  int key;
  struct node *p, *l, *r;
};
typedef struct node *Node;

//prototype
void insert(int);
Node find(int,Node);
void pr_pre(Node);
void pr_in(Node);
void del_all(Node);
void del(Node);
Node suc(Node);

//global
Node root;

int main(){
  int num, i, j;
  char cmd[10];
  
  //input
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%s",cmd);

    if(cmd[0]=='i'){//insert
      scanf("%d",&j);
      insert(j);
    }
    
    else if(cmd[0]=='f'){//find
      scanf("%d",&j);

      if(find(j,root)==NULL) printf("no\n");
      else printf("yes\n");
    }

    else if(cmd[0]=='d'){//delete
      scanf("%d",&j);
      del(find(j,root));
    }
    
    else if(cmd[0]=='p'){//print
      pr_in(root);
      printf("\n");
      pr_pre(root);
      printf("\n");
    }
  }

  del_all(root);
  return 0;
}

void insert(int n){
  Node x=root, y=NULL, z;

  z=malloc(sizeof(struct node));
  z->key=n;
  z->l=z->r=NULL;

  while(x!=NULL){
    y=x;
    if(z->key < x->key) x=x->l;
    else x=x->r;
  }
  z->p=y;

  if(y==NULL) root=z;
  else if(z->key < y->key) y->l=z;
  else y->r=z;
  
}

void pr_pre(Node data){
  printf(" %d",data->key);
  if(data->l!=NULL) pr_pre(data->l);
  if(data->r!=NULL) pr_pre(data->r);
}

void pr_in(Node data){
  if(data->l!=NULL) pr_in(data->l);
  printf(" %d",data->key);
  if(data->r!=NULL) pr_in(data->r);
}

void del_all(Node data){
  if(data->l!=NULL) del_all(data->l);
  if(data->r!=NULL) del_all(data->r);
  free(data);
}

Node find(int n,Node data){
  if(data->key == n) return data;

  if(data->key > n){
    if(data->l==NULL) return NULL;
    else return find(n,data->l);
  }
  
  if(data->key < n){
    if(data->r==NULL) return NULL;
    else return find(n,data->r);
  }
}

void del(Node z){
  Node x, y;

  if(z==NULL) return;
  
  if(z->l==NULL || z->r==NULL) y=z;
  else y=suc(z);

  if(y->l!=NULL) x=y->l;
  else x=y->r;

  if(x!=NULL) x->p=y->p;

  if(y->p==NULL) root=x;
  else{
    if(y==y->p->l) y->p->l=x;
    else y->p->r=x;
  }
  
  if(y!=z) z->key=y->key;

  free(y);
  
}

Node suc(Node x){
  Node  y;
  
  if(x->r!=NULL){
    x=x->r;
    while(x->l!=NULL) x=x->l;
    return x;
  }

  y=x->p;
  while(y!=NULL && x==y->r){
    x=y;
    y=y->p;
  }

  return y;
}




Measured memory_bytes: 20612
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set> 
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
using namespace std;
#define assem99 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ld long double
#define ii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<ii>
#define f(i,a,b) for(int i=a; i<b; i++)
#define F first
#define S second
#define sz(a) (int)(a).size()
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
int x[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int y[] = { -1, 0, 1, 0, 1, -1, -1, 1 };
const int MOD = 998244353, N = 2e5 + 5;
const double pi = acos(-1);

vector<int> graph[N];
bool vis[N];
int dp[N];

void dfs(int node)
{
	if (vis[node]) return;
	vis[node] = true;
	for (int child : graph[node])
	{
		if(!vis[child])dfs(child);
		dp[node] = max(dp[node], dp[child] + 1);
	}
}

int main()
{
	assem99;

	int n, m; cin >> n >> m;
	f(i, 0, m)
	{
		int u, v; cin >> u >> v;
		graph[u].push_back(v);
	}
	int ans = 0;
	f(i, 1, n + 1) if (!vis[i]) dfs(i);
	f(i, 1, n + 1) ans = max(ans, dp[i]);

	cout << ans;

	return 0;
}


Measured memory_bytes: 10624
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#define MAXN 20005
#define add 30000
using namespace std;
int a[MAXN], b[MAXN];
int p[MAXN], c[MAXN];
int n;
int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &p[i]);
        c[p[i]] = i;
    }
    a[1] = 1;
    for(int i = 2; i <= n; i++)
    {
        a[i] = a[i - 1] + add;
    }
    for(int i = 1; i <= n; i++)
    {
        b[i] = c[i] - a[i];
    }
    for(int i = 1; i <= n; i++)
    {
        b[i] += (1 - b[n]);
    }
    for(int i = 1; i <= n; i++)
    {
        printf("%d", a[i]);
        if(i == n) printf("\n");
        else
            printf(" ");
    }
    for(int i = 1; i <= n; i++)
    {
        printf("%d", b[i]);
        if(i == n) printf("\n");
        else
            printf(" ");
    }
    return 0;
}


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

// void debug(vector<int> *v)
// {
// 	cout << "debug :";
// 	for (int i = 0; i<v->size(); i++)
// 		cout << " " << v->at(i);
// 	cout << endl;
// }

int main()
{
	int A, B, C;
	cin >> A >> B >> C;;

	if ((B - A) == (C - B)) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	return 0;

}


Measured memory_bytes: 256
def process(k, d, n, x, m):
  d_mod = [di % m for di in d]
  sum_d_mod = sum(d_mod)
  inc_times1 = len([d_mod_i for d_mod_i in d_mod if d_mod_i])
  rem_d_mod = sum(d_mod[0:(n-1)%k])
  inc_times2 = len([d_mod_i for d_mod_i in d_mod[0:(n-1)%k] if d_mod_i])
  last = x + sum_d_mod * ((n-1) // k) + rem_d_mod
  first = x
  ans = inc_times1 * ((n-1) // k) + inc_times2
  ans -= last // m - first // m
  print(ans)


def main():
  k, q = map(int, input().split())
  d = list(map(int, input().split())) 
  for i in range(q):
    n, x, m = map(int, input().split())
    process(k, d, n, x, m)



if __name__ == "__main__" :
  main()

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

using namespace std;

int main()
{
    long long k, l, i;
    string s;
    cin>>s>>k;
    l=s.size();
    for(i=0;i<l;i++)
    {
        if(s[i]!='1' || i+1==k)
        {
            cout<<s[i]<<endl;
            break;
        }
    }



    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

using namespace std;

struct d{
	int n;
	int t;
}drink[110];

int main()
{
	int n, m;
	int t[110];
	long long ans = 0;
	scanf("%d", &n);
	for( int i = 0; i < n; i++)
	{
		scanf("%d", &t[i]);
		ans = ans + t[i];
	}
	scanf("%d", &m);
	for(int i = 0; i < m; i++)
	{
		scanf("%d%d", &drink[i].n, &drink[i].t);
	}
	long long temp;
	for(int i = 0; i < m; i++)
	{
		temp = ans - t[drink[i].n - 1] + drink[i].t;
		printf("%d\n", temp);
	}
	return 0;
}

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

int main(){
	int n;
	int a[10000];
	long min,max;
	long sum=0;
	
	cin>>n;
	
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum=sum+a[i];
	}
	min=a[0];
	max=a[0];

	for(int i=0;i<n;i++){
		if(min>a[i])
			min=a[i];
		if(max<a[i])
			max=a[i];
	}
	cout<<min<<" "<<max<<" "<<sum<<"\n";
}
	

Measured memory_bytes: 1200
#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;
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(15);}} __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; }
int main(){
  int n;
  cin>>n;
  V<ll> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i)a[i]+=a[i-1];
  }
  int l=0,r=2;
  ll ans=inf;
  for(int i=1;i<n-2;i++){
       ll bfol=abs(a[i]-a[l]-a[l]),bfor=abs(a[n-1]-a[r]-a[r]+a[i]);
       while(l+1<i&&abs(a[i]-a[l+1]-a[l+1])<bfol){
         l++;
         bfol=abs(a[i]-a[l]-a[l]);
       }
       while(r+1<n&&abs(a[n-1]-a[r+1]-a[r+1]+a[i])<bfor){
         r++;
         bfor=abs(a[n-1]-a[r]-a[r]+a[i]);
       }
       ll res=max({a[l],a[i]-a[l],a[r]-a[i],a[n-1]-a[r]})-min({a[l],a[i]-a[l],a[r]-a[i],a[n-1]-a[r]});
       chmin(ans,res);
  }
  cout<<ans<<"\n";
}


Measured memory_bytes: 4792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    if(N%10==9 || N/10==9) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, S);

    int ab = S / 100;
    int cd = S % 100;

    bool yymm = false, mmyy = false;

    if ( 0 < cd && cd < 13 ) {
        yymm = true;
    }

    if ( 0 < ab && ab < 13 ) {
        mmyy = true;
    }

    string ans = "NA";

    if ( yymm && mmyy ) {
        ans = "AMBIGUOUS";
    }
    if ( !yymm && mmyy ) {
        ans = "MMYY";
    }
    if ( yymm && !mmyy ) {
        ans = "YYMM";
    }

    cout << ans << "\n";
    return 0;
}

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

/**
|||||||||||||       |||||     |||||    ||||||||||
||||||||||||||      |||||     |||||  |||||
|||||     |||||     |||||     |||||  |||||
||||||||||||||||    |||||||||||||||    ||||||||||
|||||||||||||||||   |||||||||||||||           |||||
|||||        |||||  |||||     |||||           |||||
|||||         ||||| |||||     |||||    ||||||||||
AHMED;HASSAN;SAEED;
*/

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    vector<vector<pair<int,int> > >p(n);
    for(int i=0;i<m;i++){
        int tp,ty;
        cin>>tp>>ty;
        tp--;
        p[tp].push_back(make_pair(ty,i));
    }
    for(int i=0;i<n;i++)
    sort(p[i].begin(),p[i].end());
    vector<string>s(m);
    for(int i=0;i<n;i++){
        int c=1;
        for(int j=0;j<p[i].size();j++){
            ostringstream oss;
            oss<<(i+1);
            s[p[i][j].second].append(6-(oss.str()).length(),'0');
            s[p[i][j].second].append(oss.str());
            ostringstream oss2;
            oss2<<c;
            s[p[i][j].second].append(6-(oss2.str()).length(),'0');
            s[p[i][j].second].append(oss2.str());
            c++;
        }
    }
    for(int i=0;i<m;i++)
        cout << s[i] << endl;
    return 0;
}


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

int main() {
    ll h,w;
    cin>>h>>w;
    ll sdiff=h*w;
    for(int i = 1;i < h;++i) {
        ll s1=w*i;
        ll rh=h-i;
        ll s2,s3;
        if(rh%2==0||w%2==0) {
            s2=rh*w/2;
            s3=rh*w/2;
        }
        else {
            if(rh<w) {
                s2=rh*(w/2);
                s3=rh*(w+1)/2;
            }
            else {
                s2=(rh/2)*w;
                s3=(rh+1)/2*w;
            }
        }
        if(s1>s3)sdiff=min(sdiff,s1-s2);
        else if(s1<s2)sdiff=min(sdiff,s3-s1);
        else sdiff=min(sdiff,s3-s2);
    }
    for(int i = 1;i < w;++i) {
        ll s1=h*i;
        ll rw=w-i;
        ll s2,s3;
        if(rw%2==0||h%2==0) {
            s2=rw*h/2;
            s3=rw*h/2;
        }
        else {
            if(rw<h) {
                s2=rw*(h/2);
                s3=rw*(h+1)/2;
            }
            else {
                s2=(rw/2)*h;
                s3=(rw+1)/2*h;
            }
        }
        if(s1>s3)sdiff=min(sdiff,s1-s2);
        else if(s1<s2)sdiff=min(sdiff,s3-s1);
        else sdiff=min(sdiff,s3-s2);
    }
    cout<<sdiff<<endl;
    return 0;
}


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


ll N;
ll a[100001];

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a, a+N);
    
    ll h1 = 0, h2 = 0;
    ll i = N-1;
    while(!h1 && i > 0){
        if(a[i] == a[i - 1]){
            h1 = a[i];
            i--;
        }
        i--;
    }
    while(!h2 && i > 0){
        if(a[i] == a[i - 1]){
            h2 = a[i];
        }
        i--;
    }

    cout << h1 * h2 << '\n';

    return 0;
    
}


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

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

    if ( N == 100 ) {
        cout << N + 1;
    } else {
        cout << N;
    }
    for ( int i = 0; i < D * 2; i++ ) cout << "0";
    cout << endl;

    return ( 0 );
}


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

int N, K;
string S;
vector<int> RL[2];

int main() {
  cin >> N >> K;
  cin >> S;
  int cnt = 1;
  int flip = 0;
  rep(i, N-1) {
    if(S[i] == S[i+1]) {
      cnt++;
    } else {
      RL[flip % 2].push_back(cnt);
      cnt = 1;
      flip++;
    }
  }
  RL[flip % 2].push_back(cnt);
  // 現在の幸福度は
  int sum = accumulate(RL[0].begin(), RL[0].end(), 0);
  sum += accumulate(RL[1].begin(), RL[1].end(), 0);
  sum -= RL[0].size();
  sum -= RL[1].size();
  if(S[0] == S[N-1]) {
    cout << sum + min(K, (int)(RL[1].size())) * 2 << endl;
  } else {
    if(K < RL[1].size()) {
      cout << sum + K * 2 << endl;
    } else {
      cout << sum + (RL[1].size()-1) * 2 + 1 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace   std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define double    long double
#define ull       unsigned long long
#define mod       1000000007
#define vi        vector<ll>
#define extreme   inline
#define ppi       pair<ll,pair<ll,ll>>
#define pb        push_back
#define mp        make_pair
#define str       string
#define pi        2*acos(0.0)
#define pr(a,x,n) for(int i=x;i<n;i++){cout<<a[i]<<" ";}
#define p(a)      cout<<a;
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define test      cout<<"THIS_AND_THIS"<<endl;
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
unordered_map<ll,ll>m;
ll go(int n){
	if(n==1){
		return 1;
	}
	else{
		ll x=go(n/2)*2;
		return 1+x;
	}
}
void solve(){
	ll n;cin>>n;
	ll ans=go(n);
	cout<<ans;
}
int32_t main(){
	kehsihba();
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

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

#define pb push_back
#define mp make_pair
#define ll long long int
int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    

 	int a,b;
 	cin >> a >> b;
 	int ans=0,free=1;
 	while (free<b)
 	{
 		free+=a-1;
 		ans++;
 	}
 	if (b==1)
 		ans=0;
 	cout << ans << endl; 

	return 0;
}

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

#define pb(a) push_back(a)
#define vi vector<int>
#define loop(i, n) for(int i=1;i<=n;i++)
#define loop0(i, n) for(int i=0;i<n;i++)
#define in(i) scanf("%lld", &i);
#define out(i) printf("%d", i)

long long int n, k, a[3001];
long long int dp[3001][3001][3];

long long int solve(long long int l, long long int r, int ch)
{
  if(dp[l][r][1+ch]!=-1)
    return dp[l][r][1+ch];
  if(l==r)
    return dp[l][r][1+ch]=ch*a[l];
  if(ch==-1)
  {
    if(l>r)
      return INT_MIN;
    if(l==r)
      return -a[l];
    return dp[l][r][1+ch]=min(solve(l+1, r, 1)-a[l], solve(l, r-1, 1)-a[r]);
  }
  else
  {
    if(l>r)
      return INT_MAX;
    if(l==r)
      return a[l];
    return dp[l][r][1+ch]=max(solve(l+1, r, -1)+a[l], solve(l, r-1, -1)+a[r]);
  }
}
int main()
{
  memset(dp, -1, sizeof(dp));
  in(n);
  loop(i, n)
  {
    in(a[i]);
  }
  if(n==1)
    cout<<a[1]<<"\n";
  else
  {
    long long int ans=max(solve(2, n, -1)+a[1], solve(1, n-1, -1)+a[n]);
    cout<<ans<<"\n";
  }
}



Measured memory_bytes: 215000
#include<iostream>
#include<cstdio>
#include<string>
#include <iostream>

using namespace std;

int main() {
  string s;
  cin >> s;
  int n=0;
  for(int i=0;i<=3;i++){
  if(s[i]=='+'){n++;}
  else{n--;}
  }
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int k,x;
  scanf("%d %d",&k,&x);
  
  for(int i=x+1-k;i<x+k;i++){
    if(i==x+k-1){
      printf("%d\n",i);
    }else{
    printf("%d ",i);
    }
  }
  return 0;
}

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

int n,a[100],b[100],c[100];
int ans;

int main()
{
	cin>>n;
	for(int i=1;i<=n;cin>>a[i++]);
	for(int i=1;i<=n;cin>>b[i++]);
	for(int i=1;i<n;cin>>c[i++]);
	for(int i=1;i<=n;i++)
	{
		ans += b[a[i]];
		if(i>1 && a[i]==a[i-1]+1)
			ans += c[a[i-1]]; 
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
SA=input()
SB=input()
SC=input()
s=["a","b","c"]
S=[SA,SB,SC]
num=[len(SA)-1,len(SB),len(SC)]
X=["A","B","C"]
k=0
for t in range(500):
    if num[k]==-1:
        print(X[k])
        exit()
    for j in range(3):
        if S[k][-num[k]-1]==s[j]:
            k=j
            num[k]-=1
            break
            

Measured memory_bytes: 3064
//IN THE NAME OF GOD

#include <iostream>
using namespace std;
typedef long long int ll;
int n,a[110],ans;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        int m=i;
        for(int j=i+1;j<n;j++){
            if(a[j]<a[m])
                m=j;
        }
        if(m!=i)
            ans++;
        swap(a[m],a[i]);
    }
    for(int i=0;i<n-1;i++)
        cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1196
function Main(input) {
	let n = parseInt(input, 10);
	
	let r = n % 1000;
	if (r===0) {
	  console.log(0);
	} else {
	  console.log( 1000 - r );
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29588
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=gets.chomp
if S.include?("AC")
    puts "Yes"
    else
        puts "No"
end

Measured memory_bytes: 1916
while True:
    cnt = 0
    (n,x) =  map(int,input().split())
    if ( n==0 and x==0):
        break
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if ( (i+j+k ) == x ):
                    cnt += 1
                    break
    print (cnt)


Measured memory_bytes: 5592
import heapq

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

graph = [[] for _ in range(N)]
for _ in range(M):
	u, v, A, B = map(int, input().strip().split())
	u -= 1
	v -= 1
	graph[u].append((v, A, B))
	graph[v].append((u, A, B))

exchanges = []
for _ in range(N):
	C, D = map(int, input().strip().split())
	exchanges.append((C, D))

queue = [(0, 0, S)]
max_fare = 2500

state_table = [[None] * (max_fare + 1) for i in range(N)]

reached = [False] * N
reached_count = 0

while queue:
#	print(len(queue))
	time, cur, money = heapq.heappop(queue)
	if not reached[cur]:
		reached[cur] = True
		reached_count += 1
		if reached_count >= N:
			break
	count, d_time = exchanges[cur]
	for n, A, B in graph[cur]:
		n_money = money - A
		n_time = time + B
		if n_money >= 0:
			states = state_table[n]
			if n_money > max_fare:
				n_money = max_fare
			if states[n_money] == None or states[n_money] > n_time:
				states[n_money] = n_time
				heapq.heappush(queue, (n_time, n, n_money))

	states = state_table[cur]
	money += count
	time += d_time
	if money >= 0:
		if money > max_fare:
			money = max_fare
		if states[money] == None or states[money] > time:
			states[money] = time
			heapq.heappush(queue, (time, cur, money))

#for i in range(N):
#	print(i, state_table[i])

for i in range(1, N):
	states = state_table[i]
	minimum = None
	for t in states:
		if t != None and (minimum == None or minimum > t):
			minimum = t
	print(minimum)


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

int main() {
  // 入力
  string S;
  cin >> S;

  int digit = S.size();
  int ans = 1000;

  for (int i = 0; i < digit - 2; i++) {
    int X = 0;
    X = S[i] - '0';
    for (int j = 1; j < 3; j++) {
      X = X * 10 + S[i + j] - '0';
    }
    if (abs(753 - X) < ans) {
      ans = abs(753 - X);
    }
  }
  cout << ans << endl;
}


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 const MAX = 1000000;
int a[MAX + 5];

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        int x;
        cin >> x;
        a[x]++;
    }

    int ans = 0;

    for (int i = 1; i <= MAX; i++) {
        if (a[i] == 1) ans++;
        if (a[i] > 0) {
            for (int j = 2; i * j <= MAX; j++) {
                a[i * j] = 0;
            }
        }
    }

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


Measured memory_bytes: 7536
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
/*
多倍長整数, cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
constexpr long double eps = 1e-9;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	string s;
	scans(s);
	printf("%s\n", s[s.length() - 1] == '3' ? "bon" : 
		(s[s.length() - 1] == '0' 
			or s[s.length() - 1] == '1' 
			or s[s.length() - 1] == '6' 
			or s[s.length() - 1] == '8' ? "pon" : "hon"));

	Please AC;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int r, g;
  cin >> r >> g;
  cout << 2*g-r << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FIO;
    int n;
    string a,b,s;
    cin>>n>>a>>b;
    for(int i=0; i<n; i++)
    {
        s.push_back(a[i]);
        s.push_back(b[i]);
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>str;
    rep(i,str.length()) cout<<'x';
    ln;
    return 0;
}


Measured memory_bytes: 3652
from itertools import permutations
from math import sqrt

N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
#順列(町の訪れ方)を作成→計算
d = 0
for route in permutations(range(N), N):
    route = list(route)
    for i in range(N-1):
        s = route[i]
        g = route[i+1]
        d += sqrt((X[g] - X[s]) ** 2 + (Y[g] - Y[s]) ** 2)
divisors = 1
for i in range(2, N+1):
    divisors *= i
print(d/divisors)



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

using ll = long long;
#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 INF 1e9

bool kaibun(string S){
  int n = S.size();
  REP(i, n/2){
    if(S[i] != S[n-1-i]){
      // cout << "false" << endl;
      return false;
    }
  }
  // cout << "true" << endl;
  return true;
}
int main(){
  string S;
  cin >> S;
  int n = S.size();
  if(kaibun(S) && kaibun(S.substr(0, (n-1)/2))&& kaibun(S.substr((n+3)/2-1, n-(n+3)/2+1))){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int visit[111],d[111],f[111],t;
//    訪問状態 　　発見　　　完了
int n,M[111][111];
static const int WHITE=0; //未訪問
static const int GRAY=1; //訪問はした
void dfs(int u){
  visit[u]=GRAY; //訪問はした
  d[u]=++t; //発見した時刻
  for(int v=0;v<n;v++){
    if(M[u][v]==0) continue; //辺がない
    if(visit[v]==WHITE) dfs(v);
  }
  f[u]=++t; //訪問完了時刻
}
int main(){
  int u,v,k;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  for(int i=0;i<n;i++){
    if(visit[i]==WHITE) dfs(i); //訪問してないか... iを始点に
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<' '<<d[i]<<' '<<f[i]<<endl;
  }
  return(0);
}



Measured memory_bytes: 3112
#include<iostream>
#include<algorithm> 
using namespace std;
const int MAX=1e5+10;
struct student
{
	int num;
	int index;	
	bool operator<(const student &p) const
	{
		if(num!=p.num) return num<p.num;
	}
};
student a[MAX];
int main()
{
	int n=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].num;
		a[i].index=i+1;
	}
	sort(a,a+n);
	cout<<a[0].index;
	for(int i=1;i<n;i++) cout<<" "<<a[i].index;
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Freed freopen ("0in.txt","r",stdin);
#define Fout freopen ("0out.txt","w",stdout);
#define ll long long int
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define Mod 1000000007
#define limit 1000008
using namespace std;
ll Fact(int n)
{
    if(n==0 || n==1)
        return 1;
    return n*Fact(n-1);
}
void solve(int t)
{
    ll i,j,n,m,dif,ans1=1,ans2=1;
    bool vis[10];
    ll A[10],B[10];
    cin >> n;
    for(i=1; i<=n; i++)
        cin >> A[i];
    for(i=1; i<=n; i++)
        cin >> B[i];
    for(i=0; i<10; i++)
        vis[i]=1;
    for(i=1; i<n; i++)
    {
        ll ct = 0;
        for(j=1; j<=n; j++)
        {
            if(j==A[i])
                break;
            if(vis[j])
                ct++;
        }
        vis[A[i]]=0;
        dif = ct*Fact(n-i);
        ans1 += dif;                     // cout <<i<<" "<<dif<<" "<<ans1<<endl;
    }
    for(i=0; i<10; i++)
        vis[i]=1;
    for(i=1; i<n; i++)
    {
        ll ct = 0;
        for(j=1; j<=n; j++)
        {
            if(j==B[i])
                break;
            if(vis[j])
                ct++;
        }
        vis[B[i]]=0;
        dif = ct*Fact(n-i);
        ans2 += dif;
    }                        // cout <<ans1<<" "<<ans2<<endl;
    cout <<abs(ans1-ans2)<<endl;
}
int  main()
{
//    Fast
//    Freed
//    Fout
    int t,tt=1;
   // cin >> tt;
    for(t=1; t<=tt; t++)
        solve(t);
  return 0;
}




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

vector<long long int > primes;
bool isprime[2000009];
int ndiv[1000009];

void div()
{
    long long int sum=0;
    for(int i=1; sum<=1000000; i++)
    {
        sum+=i;
        ndiv[sum]=i;
    }
    int c =1;
    for(int i=1; i<=1000000; i++)
    {
        if(ndiv[i]==0)
            ndiv[i]=c;
        else
            c=ndiv[i];
    }


}
void sieve()
{
    for(int i=3; i<=2000005; i+=2)
    {
        if(isprime[i]==0)
        {
            for(int j=i*2; j<=2000005; j+=i)
                isprime[j]=1;
        }
    }
    primes.push_back(2);
    for(int i=3; i<2000005; i+=2)
        if(isprime[i]==0)
            primes.push_back(i);
}

int main()
{
   /// sieve();
    ///div();

    long long num;
    map<long long int,long long  int >mp;
    vector<long long int > st;
    while(cin>>num)
    {
      long int  sum =0;
        for(long long int i=2; i*i<=num; i++)
        {
            if(num%i==0)
            {
                int c=0;
                ///st.push_back(i);
                while(num%i==0)
                {
                    c++;
                    num/= i;
                }
                int k=1;
                while(c>=k){
                        c-=k;
                    k++;sum++;
                }
                ///sum+= ndiv[c];
            }
        }
        if(num>1)
        {
            sum++;
        }
        cout<<sum<<endl;
        mp.clear();
        st.clear();
    }

    return 0;
}


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  rep(i, N) {
    cin >> p[i];
  }
  sort(all(p));
  int sum = 0;
  rep(i, K)
    sum += p[i];
  cout << sum << endl;
}


Measured memory_bytes: 3660
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    string S;
    cin >> N >> S >> K;
    K--;
    rep(i, N) {
        if(S[i] == S[K]) cout << S[i];
        else cout << "*";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3612
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mx = max(a)
mn = min(a)
res = []
if abs(mx) >= abs(mn):
  t = 0
  for i in range(N):
    if a[i] == mx:
      t = i
      break
  for i in range(N):
    res.append((t + 1, i + 1))
    a[i] += a[t]
  for i in range(N):
    for j in range(N):
      if a[j] > a[t]: t = j
    res.append((t + 1, i + 1))
    a[i] += a[t]
  print(len(res))
  for r in res: print(*r)
else:
  t = 0
  for i in range(N):
    if a[i] == mn:
      t = i
      break
  for i in range(N):
    res.append((t + 1, i + 1))
    a[i] += a[t]
  for i in range(N - 1, -1, -1):
    for j in range(N):
      if a[j] < a[t]: t = j
    res.append((t + 1, i + 1))
    a[i] += a[t]
  print(len(res))
  for r in res: print(*r)

Measured memory_bytes: 38640
#include <stdio.h>

int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a >= b && a >= c){
        a = a * 10;
        printf("%d\n",a + b + c);
    }else if(b >= a && b >= c){
        b = b * 10;
        printf("%d\n",a + b + c);
    }else if(c >= a && c >= b){
        c = c * 10;
        printf("%d\n",a + b + c);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int plan1 = N * A, plan2 = B;
  
  if(plan1 <= plan2)
    cout << plan1 << endl;
  else
    cout << plan2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim_i = (b); i < lim_i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Mar 21 21:00:20 JST 2020
 **/

template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

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

const Int INF = 1e9;
signed main() {
    Int H, W;
    cin >> H >> W;
    vector<string> t(H);
    REP(i, H) cin >> t[i];
    auto dp = make_vec<Int>(H, W, 2, INF);
    dp[0][0][0] = t[0][0] == '#' ? INF : 0;
    dp[0][0][1] = t[0][0] == '#' ? 1 : INF;
    REP(i, H) {
        REP(j, W) {
            if (i - 1 >= 0) {
                if (t[i][j] != '#') {
                    chmin(dp[i][j][0], min(dp[i - 1][j][0], dp[i - 1][j][1]));
                } else {
                    chmin(dp[i][j][1], min(dp[i - 1][j][0] + 1, dp[i - 1][j][1]));
                }
            }
            if (j - 1 >= 0) {
                if (t[i][j] != '#') {
                    chmin(dp[i][j][0], min(dp[i][j - 1][0], dp[i][j - 1][1]));
                } else {
                    chmin(dp[i][j][1], min(dp[i][j - 1][0] + 1, dp[i][j - 1][1]));
                }
            }
        }
    }
    cout << min(dp[H - 1][W - 1][0], dp[H - 1][W - 1][1]) << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x; cin >> x;
  int ans = 1;
  for(int i=2; i<x; i++) {
    ll tmp = i*i;
    while(true) {
      if(tmp > x) break;
      chmax(ans, tmp);
      tmp *= i;
    }
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;

int gcd(int a, int b)
{
    if (a%b== 0) return b;
    else
        return gcd(b, a%b);
}

int main()
{
    int K;
    cin >> K;
    ll sum = 0;
    rep(a, 1, K+1) {
        rep(b, 1, K+1) {
            rep(c, 1, K+1) {
                int tmp = gcd(a, b);
                sum += gcd(tmp, c);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3636
n = int(input())
a = map(int, input().split())

ans = 1

for x in a:
    ans *= x
    if ans > 1000000000000000000:
        break

for x in a:
    if x == 0:
        ans = x

if ans > 1000000000000000000:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 19340
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
const lol mod=998244353;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    bool ans=false;
    cin >>a>>b>>c;
    if(a==b){
      if(a!=c) ans=true;
      else ans=false;
    }else if(b==c){
      ans=true;
    } else if(a==c) ans=true;
    if(ans) cout <<"Yes\n";
    else cout <<"No\n";
    return (0);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  private static final int MAX = 1000000;
  private Scanner sc = new Scanner(System.in);

  private void run() {
    boolean[] primes = primes();

    while(sc.hasNextInt()) {
      int n = sc.nextInt();

      int x = 0;
      for(int i = 0; i <= n; i++) {
        if(primes[i]) x++;
      }

      System.out.println(x);
    }
  }

  private boolean[] primes() {
    boolean[] ns = new boolean[MAX];
    for(int i = 2; i < MAX; i++) ns[i] = true;

    for(int i = 2; i < MAX; i++) {
      if(ns[i] == false) continue;

      if(i * i > MAX) break;

      for(int j = i * i; j < MAX; j += i) {
        ns[j] = false;
      }
    }

    return ns;
  }

  public static void main(String[] args) {
    new Main().run();
  }
}

Measured memory_bytes: 13000
from numpy import*
n,*a=map(int,open(0).read().split())
a=[0]+a+[0]
b=sum(abs(array(a[1:])-array(a[:-1])))
#print(a)
for i in range(1,n+1):
    #print(a[i-1],a[i],a[i+1])
    print(b- abs(a[i-1]-a[i])-abs(a[i+1]-a[i]) +abs(a[i+1]-a[i-1]) )

Measured memory_bytes: 22992
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <deque>
using namespace std;

const int N = 200001;
int p[N], n,k;

int main(){
	scanf("%d%d", &n, &k);
	for(int i=0;i<n;++i) scanf("%d", p+i);
	deque<int> mx, mn;
	for(int i=0;i<k;++i){
		while(!mn.empty() && p[mn.back()] > p[i]) mn.pop_back();
		mn.push_back(i);
		while(!mx.empty() && p[mx.back()] < p[i]) mx.pop_back();
		mx.push_back(i);
	}
	int uno = 0, ans = 1;
	if(mn.size() == k) uno = 1;
	for(int i=k;i<n;++i){
		bool f = false;
		if(mn.front() <= i-k) mn.pop_front();
		else f = true;
		while(!mn.empty() && p[mn.back()] > p[i]) mn.pop_back();
		mn.push_back(i);
		
		if(mx.front() <= i-k) mx.pop_front();
		while(!mx.empty() && p[mx.back()] < p[i]) mx.pop_back();
		if(!mx.empty()) f = true;
		mx.push_back(i);
		
		if(f) ++ans;
		if(mn.size() == k){
			if(f && uno) --ans;
			uno = 1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>

using namespace std;

int main()
{
    int n;
    long sum=0;
    cin >> n;
    unordered_map<string, int> strs;
    string str;
    for(int i=0;i<n;i++){
        cin >> str;
        sort(str.begin(), str.end());
        strs[str]++;
    }

    for(auto str : strs){
        sum += ((long)str.second * (str.second-1)) / 2;
    }

    cout << sum << endl;
}

Measured memory_bytes: 10660
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
const int N=9e5+10;
const LL mod=1e9+7;
int n,m,k;
LL fac[N]={1},inv[N]={1,1},pw[N]={1},ans,j=1;
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline void swp(I&a,I&b){a^=b; b^=a; a^=b;}
inline LL C(int nn,int mm){return fac[nn]*inv[mm]%mod*inv[nn-mm]%mod;}
int main()
{
//	freopen("Card Game for Three.in","r",stdin);
	//freopen(".out","w",stdout);
	read(n,m,k);
	if(k>m) swp(k,m);
	for(int i=2;i<=n+k+m;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1;i<=n+k+m;i++) fac[i]=fac[i-1]*i%mod, (inv[i]*=inv[i-1])%=mod, pw[i]=pw[i-1]*3%mod;
	for(int i=0;i<=m+k;i++)
	{
		(ans+=C(n+i-1,n-1)*pw[m+k-i]%mod*j%mod)%=mod;
		if(i<k) (j<<=1)%=mod;
		else if(i>=m) (j+=j-C(i,k)+mod-C(i,m)+mod)%=mod;
		else (j+=j-C(i,k)+mod)%=mod;
	}
	printf("%lld\n",ans);
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 21376
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int l[200010], r[200010];

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

  vector<pii> v;
  REP(i,m){
    int x, y;
    cin >> x >> y;
    v.pb(MP(x, y));
  }

  SORTV(v);

  REP(i,n){
    l[i] = i;
    r[i] = i;
  }

  REP(i,m){
    int l_min, r_max;
    int lane = v[i].second;
    l_min = min(l[lane-1], l[lane]);
    r_max = max(r[lane-1], r[lane]);
    l[lane-1] = l_min; l[lane] = l_min;
    r[lane-1] = r_max, r[lane] = r_max;
  }

  REP(i,n){
    cout << r[i] - l[i] + 1;
    if(i != n-1){
      cout << " ";
    }
  }
  cout << "\n";

  return 0;
}



Measured memory_bytes: 5104
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:
	if ans > i:
		ans,i=i,ans
	while i%ans!=0:
		i,ans=ans,i%ans
	if ans ==1:
		print(1)
		break
else:
	print(ans)

Measured memory_bytes: 14252
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<functional>
using namespace std;

const int dev = 1e9+7;
typedef unsigned long long ull;

int main(){
    string S;
    cin >> S;
    int gN = 0;
    int pN = 0;
    for (int i=0;i<S.size();i++){
        if(S[i] == 'g') gN++;
        if(S[i] == 'p') pN++;
    }
    cout << (gN-pN)/2 << endl;
    return 0;
}

Measured memory_bytes: 512
L,R=map(int,input().split())
if R//2019-L//2019>=1:
  print(0)
  exit()
A=0
B=0
ans=float('inf')
for i in range(L,R):
  for j in range(1,R-i+1):
    A=i*(i+j)
    B=A%2019
    ans=min(ans,B)
print(ans)

Measured memory_bytes: 3064