akhauriyash/Code-Regression huggingface dataset:
use proconio::input;

fn main() {
    input!(n: usize, a: [usize; n]);

    const AMAX: usize = 1_000_000;

    let mut cnt = vec![0; AMAX + 1];
    for &a in &a {
        cnt[a] += 1;
    }

    let mut seen = vec![false; AMAX + 1];
    let mut max_csum = 0;
    for i in 2..=AMAX {
        if seen[i] {
            continue;
        }
        let mut csum = 0;
        for j in 1..=AMAX / i {
            let j = i * j;
            seen[j] = true;
            csum += cnt[j];
        }
        max_csum = max_csum.max(csum);
    }

    let pairwise = max_csum <= 1;
    let setwise = max_csum < n;

    println!(
        "{}",
        if pairwise {
            "pairwise coprime"
        } else if setwise {
            "setwise coprime"
        } else {
            "not coprime"
        }
    );
}


Measured memory_bytes: 25240
#include<stdio.h>

#define N 501

static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,A[N][N],C[N],d[N],f[N],tt;

void dfs_a(int u){

  int v;
  
  C[u] = GRAY;

  tt++;

  d[u] = tt;

  for(v=0;v<n;v++){
    
    if(A[u][v] == 0){
      continue;
    }
    
    if(C[v] == WHITE){
      dfs_a(v);
    }

  }

  C[u] = BLACK;

  f[u] = ++tt;

}

void dfs_b(){

  int i,u;
  
  for(i=0;i<n;i++){
    C[i] = WHITE;
  }
  
  tt = 0;

  for(u=0;u<n;u++){
    
    if(C[u] == WHITE){
      dfs_a(u);
    }
  }
  
  for(i=0;i<n;i++){
    
    printf("%d %d %d\n",i+1,d[i],f[i]);
    
  }
}


int main(){

  int i,j,u,k,v;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    
    scanf("%d%d",&u,&k);

    u--;

    for(j=0;j<k;j++){
      
      scanf("%d",&v);
      
      v--;

      A[u][v] = 1;

    }
  }

  dfs_b();

  return 0;
}



Measured memory_bytes: 2112
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = S / 3600;
		int m = (S % 3600) / 60;
		int s = S % 60;
		System.out.println(h + ":" + m + ":" + s);
		sc.close();
	}
}


Measured memory_bytes: 26192
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::string s {std::to_string(N)};
  int d{0};
  for (auto&& v : s) d += (int)(v - '0');
  std::cout << (N % d == 0 ? "Yes" : "No") << std::endl;
}

Measured memory_bytes: 256
/*input
133333 329230329032 493028310923
*/
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include <tgmath.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
#define MAXN   100001  
 

std::vector<int> ans;

void factorize(long long n){
   
   int count = 0;
   while (!(n % 2)) {
      n/= 2;
      count++;
   }
   if (count)
      ans.push_back(count);
   for (long long i = 3; i <= sqrt(n); i += 2) {
      count = 0;
      while (n % i == 0) {
         count++;
         n = n / i;
      }
      if (count)
      	ans.push_back(count);
   }
   if (n > 2)
   	ans.push_back(1);
}






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

 
 	cout<<floor(a*((min(b-1,n)*1.0)/b - floor((min(b-1,n)*1.0)/b)));
 	
 	
 	
}



 


Measured memory_bytes: 3816
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  cout << (n % k != 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for (int i=n;^i;i--)
#define ALL(v) v.begin(),v.end()
// #define int ll 
#define eps 1e-9
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
typedef long long ll;

inline bool isprime(int temp){
	int i=3;
	if (temp==2) return true;
	if (!(temp&1)) return false;
	while(i<=sqrt(temp)){
		if (!(temp%i))
			return false;	
		i += 2;
	}
	return true;
}

int main(void){
	int n,count=0;
	cin >> n;
	rep(i,n){
		int temp;
		cin >> temp;
		count += isprime(temp);
	}
	cout << count << endl;
}



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

int main(){
    int N,count=0;
    long long D;
    cin >> N >> D;
    vector<long long> x(N),y(N); 
    rep(i,N){
        cin >> x.at(i) >> y.at(i);
    }
    rep(i,N){
        if(x.at(i)*x.at(i) + y.at(i)*y.at(i) <= D*D){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 6428
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> arr(N);
  std::vector<int> P(N);
  std::vector<int> Q(N);
  
  for (int i=0; i<N; ++i) arr.at(i) = i+1;
  for (int i=0; i<N; ++i) std::cin >> P.at(i);
  for (int i=0; i<N; ++i) std::cin >> Q.at(i);
  
  int a = 0, b = 0, i = 0;
  do {
    if (arr == P)
      a = i;
    if (arr == Q)
      b = i;
    ++i;
  } while (std::next_permutation(arr.begin(), arr.end()));
  
  std::cout << std::abs(a - b) << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef pair<int,int>P;
int main()
{
	int n,m,p,a,b,x,y,z,i,j,k,l;
	double dp[30][1<<8],t[8];
	vector<P>e[30];
	while(scanf("%d%d%d%d%d",&n,&m,&p,&a,&b),n)
	{
		--a,--b;
		for(i=0;i<30;++i)e[i].clear();
		for(i=0;i<n;++i)scanf("%lf",t+i);
		while(p--)
		{
			scanf("%d%d%d",&x,&y,&z);--x,--y;
			e[x].push_back(P(y,z));
			e[y].push_back(P(x,z));
		}
		fill(dp[0],dp[30],1e9);
		dp[a][(1<<n)-1]=0;
		for(i=(1<<n)-1;i>0;--i)
		{
			for(j=0;j<m;++j)
			{
				if(dp[j][i]==1e9)continue;
				for(k=0;k<e[j].size();++k)
				{
					for(l=0;l<n;++l)
					{
						if(!(i&(1<<l)))continue;
						double&r=dp[e[j][k].first][i^(1<<l)];
						r=min(r,dp[j][i]+e[j][k].second/t[l]);
					}
				}
			}
		}
		double r=*min_element(dp[b],dp[b+1]);
		if(r==1e9)puts("Impossible");
		else printf("%f\n",r);
	}
	return 0;
}

Measured memory_bytes: 936
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    vector<int> dp(N, INF);
    rep(i, N) cin >> h[i];
    dp[0] = 0;
    rep(i, N - 1)
    {
        rep2(j, 1, K + 1)
        {
            if (i + j < N)
            {
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
            }
            else
            {
                break;
            }
        }
    }
    // for (int i : dp)
    // {
    //     cout << i << " ";
    // }
    // cout << endl;
    cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

using D = double;
const int MAX_N = 303;
D dp[MAX_N][MAX_N][MAX_N];

int main(){
    int n;
    cin >> n;
    vi cnt(4);
    rep(i, n) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    rep(i, n+1) rep(j, n+1) rep(k, n+1) {
        int l = n - (i + j + k);
        if(l < 0) continue;
        dp[i][j][k] = (D)0.0;
        if(i > 0) dp[i][j][k] += (dp[i-1][j+1][k]+1)*i/n;
        if(j > 0) dp[i][j][k] += (dp[i][j-1][k+1]+1)*j/n;
        if(k > 0) dp[i][j][k] += (dp[i][j][k-1]  +1)*k/n;
        if(n != l) {
            dp[i][j][k] *= n;
            dp[i][j][k] += l;
            dp[i][j][k] /= n - l;
        }
    }
    cout << fixed << setprecision(15);
    cout << dp[cnt[3]][cnt[2]][cnt[1]] << endl;

    // rep(i, n+1) rep(j, n+1) rep(k, n+1) {
    //     cout << i << " " << j << " " << k << " -> " << dp[i][j][k] << endl;
    // }
    return 0;
}

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


void swap(int &a,int &b)
{
    int t;
    t=a;
    a=b;
    b=t;
}
int main() {
	// your code goes here
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	cin>>arr[i];
	int counter=1;
	sort(arr,arr+n);
	for(int i=1;i<n;i++)
	{
	    if(arr[i]==arr[i-1])
	    {
	    counter--;
	    arr[i]=-1;
	    }
	    else
	    counter++;
	}
	cout<<counter;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  
  int a1,a2,a3,ans;
  a1=a+b;
  a2=a-b;
  a3=a*b;
  
  ans=max(a1,a2);
  cout << max(ans,a3);
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define INF 1145141919

int H, W;
int S[1010][1010];
int dp[1010][1010][64];

int G[4] = {1, 4, 8, 32};
int GX[4] = {0, -1, 1, 0};
int GY[4] = {-1, 0, 0, 1};
int DX[2] = {0, 1};
int DY[2] = {1, 0};

// [ ] [ ] [ ]
// [#] [#] [ ]
// [?] [#] [ ]

// [ ] [#] [?]
// [ ] [#] [#]
// [ ] [ ] [ ]

// [  ] [1 ] [2]
// [4 ] [_ ] [8]
// [16] [32] [ ]

int main() {
  cin >> H >> W;
  for (int i=1; i<=H; i++) {
    for (int j=1; j<=W; j++) {
      char c;
      cin >> c;
      if (c == '.') S[i][j] = 0;
      else          S[i][j] = (int)c-(int)'0';
    }
  }
  for (int sy=0; sy<=H+1; sy++) {
    for (int sx=0; sx<=W+1; sx++) {
      for (int s=0; s<64; s++) {
        dp[sy][sx][s] = INF;
      }
    }
  }

  dp[1][1][0] = 0;
  for (int sy=1; sy<=H; sy++) {
    for (int sx=1; sx<=W; sx++) {
      for (int d=0; d<2; d++) {
        int dx = sx + DX[d], dy = sy + DY[d];

        for (int s=0; s<64; s++) {
          int state;
          if (d == 0) state = 1 + 2*((s&8)!=0) + 4*((s&16) != 0); // (sy, sx) -> (sy+1, sx)
          else        state = 1*((s&2)!=0) + 4 + 16*((s&32) != 0); // (sy, sx) -> (sy, sx+1)
          if (dp[sy][sx][s] == INF) continue;

          for (int k=0; k<16; k++) {
            int nk[4] = {(k&1)!=0, (k&2)!=0, (k&4)!=0, (k&8)!=0};
            bool ok = true;
            for (int i=0; i<4; i++) {
              // already bought
              if (nk[i] && (state & G[i]) != 0) ok = false;
            }
            if (!ok) continue;
            int sc = 0;
            if ((s & (d == 0 ? 32 : 8)) == 0) sc = S[dy][dx];
            int ns = state;
            int ctr = 0, ctr2 = 0;
            for (int i=0; i<4; i++) {
              if ((state & G[i]) != 0) continue;
              if (S[dy+GY[i]][dx+GX[i]] > 0) ctr2++;
              if (nk[i]) {
                ns |= G[i];
                sc += S[dy+GY[i]][dx+GX[i]];
              }
              else {
                if (S[dy+GY[i]][dx+GX[i]] > 0) ctr++;
              }
            }
            if (ctr != 1 && ctr2 != 0) continue;
            if (((d == 0 ? 1 : 4) & ns) == 0) continue;
            dp[dy][dx][ns] = min(dp[dy][dx][ns], dp[sy][sx][s] + sc);
          }
        }
      }
    }
  }
  int ans = INF;
  for (int s=0; s<64; s++) {
    ans = min(ans, dp[H][W][s]);
  }
  cout << ans << "\n";
  return 0;
}

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

#define LL long long

using namespace std;

const LL MAX = 1e10;

int main(){
	ios_base::sync_with_stdio(false);
	LL n,m,b;
	cin >> n >> m;
	vector<vector<LL>> keys(m);
	vector<LL> costs(m);
	for (LL i = 0; i < m; i++){
		cin >> costs[i] >> b;
		keys[i].resize(b);
		for (LL j = 0; j < b; j++){
			cin >> keys[i][j];
			keys[i][j]--;
		}
	}
	vector<vector<LL>> dp(1<<n,vector<LL>(m,MAX));
	for (LL i = 0; i < 1<<12; i++){
		LL i2 = i;
		for (LL c : keys[m-1])
			i2 &= ~(1<<c);
		if (i2 == 0)
			dp[i][m-1] = costs[m-1];
	}
	dp[0][m-1] = 0;
	for (LL j = m-2; j >= 0; j--){
		dp[0][j] = 0;
		for (LL i = 1; i < 1<<n; i++){
			dp[i][j] = dp[i][j+1];
			LL i2 = i;
			for (LL c : keys[j])
				i2 &= ~(1<<c);
			dp[i][j] = min(dp[i][j],costs[j]+dp[i2][j+1]);
		}
	}
	LL res = dp[(1<<n)-1][0];
	if (res >= MAX)
		res = -1;
	cout << res << "\n";
}


Measured memory_bytes: 32640
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let n: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let a: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    let ans = (0..n)
        .map(|i| if i < (n + 1) / 2 { a[n - 2 * i - 1] } else { a[2 * (i - (n + 1) / 2) + n % 2] })
        .map(|x| x.to_string())
        .collect::<Vec<_>>()
        .join(" ");

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

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

using namespace std;

#define int long long 
#define double long double 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SIZE 10000005

bool vis[5000005];
int n,a[200005],mx;

void func(int nn)
{
	int indx = 2;
	while(nn < mx)
	{
		int ans = nn * indx;
		indx++;
		if(ans > mx) break;
	//	else if(vis[ans] == 1) break;
		else 
		{
		    vis[ans] = 1;
		}
	}
}


int32_t main()
{
    //IOS
    map<int,int>mp;
    cin >> n;
    for(int i = 1;i<= n;i++)
    {
		cin >> a[i];
		mp[a[i]]++;
		mx = max(mx,a[i]);
	}
	sort(a+1,a+n+1);
	for(int i = 1; i<= n;i++)
	{
		if(!vis[a[i]])
		{
			func(a[i]);
		}
	}
	int coun = 0;
	for(auto it : mp)
	{
		if(it.second > 1) vis[it.first] = 1;
	}
	for(int i = 1;i<= n;i++)
	{
		if(!vis[a[i]]) coun++;
	}
	cout << coun << endl;
	return 0;
}
//3 8 11 16 24


Measured memory_bytes: 17852
def func(n):
    if n%2 == 0:
        return int(n/2)
    else:
        return int(3*n + 1)

s = int(input())
l = [s]
for i in range(1000000):
    a_i = func(l[-1])
    if a_i in l:
        l.append(a_i)
        break
    l.append(a_i)
print(len(l))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll a[n],b[n];
	for(ll i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	sort(a,a+n);
	sort(b,b+n);
	ll maxx,minn;
	if(n%2){
		ll pos = n/2;
		minn=a[pos];
		maxx= b[pos];
	}
	else {
		ll pos=n/2;
		minn = a[pos-1]+a[pos];
		maxx = b[pos-1]+b[pos];
	}
	ll ans = maxx-minn+1;
	cout<<ans;
	
	return 0;
}

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

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

 if( a<b ){
   cout << "a < b" << endl;
 }else if( a>b ){
   cout << "a > b" << endl;
 }else{
   cout << "a == b" << endl;
 }

 return 0;
}


Measured memory_bytes: 3084
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  const mx=1_000_00+5;
  auto isPrime=new bool[](mx);
  auto sub=new int[](mx);

  isPrime[2]=true;
  for(int i=3; i<=1_000_00; i+=2){
    for(int j=3; j*j<=i; j+=2){
      if(i%j==0) goto hell;
    }
    isPrime[i]=true;
    if(isPrime[(i+1)/2]) sub[i]=1;
    hell:;
  }

  foreach(i; 1..mx) sub[i]+=sub[i-1];

  int q; rd(q);
  while(q--){
    int l, r; rd(l, r);
    writeln(sub[r]-sub[l-1]);
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}

Measured memory_bytes: 4092
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int>d(N);
    set<int>value;
    for(int i=0;i<N;i++){
        cin >> d.at(i);
        value.insert(d.at(i));
    }
    cout << value.size();
    return 0;
}

Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))
S = 0
T = 0
for i in range(N):
  S += As[i]
  T += (As[i] * As[i]) % 1000000007
# print(S)
# print(T)
A = S*S % 1000000007
B = T % 1000000007
X = (A - B) % 1000000007

print((X * int((1000000007 + 1)/2)) % 1000000007)

Measured memory_bytes: 105164
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

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




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

using namespace std;

int main()
{
  int s, t, a[6], b[3];

  while(1){
    t = 0;
    for(int i = 0; i < 6; i++){
      cin >> a[i];
      t += a[i];
    }
    if(t == 0) break;
    t = 0;
    for(int i = 0; i < 3; i++){
      t += (a[i]+a[i+3])/3;
      b[i] = (a[i]+a[i+3])%3;
      a[i] = (a[i]+a[i+3])/3;
    }
    s = min(b[0], min(b[1], b[2]));
    t += s;

    for(int i = 0; i < 3; i++) b[i] -= s;
    if((b[0] >= 2 && b[1] >= 2 && a[2])
       || (a[0] && b[1] >= 2 && b[2] >= 2)
       || (b[0] >= 2 && a[1] && b[2] >= 2)) t++;

    cout << t << endl;
  }

  return 0;
}

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

#define ALL(a)  (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define REP(i,n) for(int i=0;i<(int)n;++i)

#define CLEAR(a) memset((a), 0, sizeof(a))

inline int toInt(string s) { int x; istringstream iss(s); iss >> x; return x; }
template<class T> inline string toString(T x) { ostringstream oss; oss <<x ; return oss.str(); }
template<class T> inline T sqr(T x) { return x * x; }

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

static const auto io_sync_off = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    return nullptr;
}();

int main(int argc, char *argv[]) {
    int n;
    cin >> n;
    int a = n / 100;
    int b = (n % 100) / 10;
    int c = n % 10;

    if (a == 1) a = 9; else a = 1;
    if (b == 1) b = 9; else b = 1;
    if (c == 1) c = 9; else c = 1;
    
    cout << a << b << c << endl;

    return 0;
}



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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
int A[MC],B[MC],C[MC];
LL ansB[MC];
LL ans;

int main(){
	cin >> N;
	repp(i,0,N) cin >> A[i];
	repp(i,0,N) cin >> B[i];
	repp(i,0,N) cin >> C[i];
	A[N] = B[N] = C[N] = 1e9 + 7;
	sort(A,A+N);
	sort(B,B+N);
	sort(C,C+N);
	int z = 0;
	repp(i,0,N){
		while(A[z] < B[i]) ++z;
		ansB[i+1] = ansB[i] + z;
	}
	z = 0;
	repp(i,0,N){
		while(B[z] < C[i]) ++z;
		ans += ansB[z];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2176
N,M = map(int, input().split())
r_table = [-1]*N
for _ in range(M):
    l_n, r_n = map(int, input().split())
    r_table[r_n-1] = max(l_n-1, r_table[r_n-1])

ret = 0
left = -1
for i in range(N):
    if left < r_table[i]:
        ret += 1
        left = i-1

print(ret)

Measured memory_bytes: 5952
S = input()

N = len(S)

ans = True
for i in range(N//2):
    if S[i] == S[-1-i]:
        pass
    else:
        ans = False
        
M = (N-1)//2
S2 = S[:M]
L = (N+3)//2
S3 = S[L-1:]

for i in range(len(S2)//2):
    if S2[i] == S2[-1-i]:
        pass
    else:
        ans = False
for i in range(len(S3)//2):
    if S3[i] == S3[-1-i]:
        pass
    else:
        ans = False
        


        
if ans:
    print("Yes")
else:
    print("No")

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

int main() {

	//ifstream cin("INPUT.txt");
	//ofstream cout("OUTPUT.txt");

	int n, i, j, k, l;
	char newt[26];
	char oldt[101];
	int newtlen, oldtlen;
	int check, check2;
	int sum;

	cin >> n >> newt;
	newtlen = strlen(newt);
	sum = 0;
	for(i = 0;i < n; i++) {
		cin >> oldt;
		oldtlen = strlen(oldt);
		check = 0;
		for(j = 1; j <= oldtlen - newtlen + 1; j++) {
			for(k = 0; newtlen+(newtlen-1)*k <= oldtlen-j+1; k++) {
				check2 = 0;
				for(l = 0; l < newtlen; l++) {
					if(oldt[j+(k+1)*l-1] == newt[l]) {
						check2++;
					}
				}
				if(check2 >= newtlen)
					check++;
			}
		}
	if(check != 0)
		sum++;
	}

	cout << sum << endl;

	return 0;

}

Measured memory_bytes: 1164
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();

            for (int i = 0; i < 3; i++) {
                if (S.charAt(i) == '7') {
                    out.println("Yes");
                    return;
                }
            }

            out.println("No");
        }

    }
}



Measured memory_bytes: 35804
island, fune = map(int, input().split(" "))
route = []
for i in range(fune):
    route.append(list(map(int, input().split(" "))))
temp = []
for i in range(fune):
    if route[i][0] == 1:
        temp.append(route[i][1])
for j in range(fune):
    if route[j][1] == island:
        temp.append(route[j][0])


print("POSSIBLE") if len(temp) != len(list(set(temp))) else print("IMPOSSIBLE")

Measured memory_bytes: 62592
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> v[2010];
int n,k,L;
bool vis[2010];
void DFS(int x,int len,int na){
	vis[x]=true;
	if(len==k/2)return;
	for(int i=0;i<v[x].size();i++){
		if(vis[v[x][i]]==false&&v[x][i]!=na)DFS(v[x][i],len+1,na);
	}
}

int Solve(int h,int w,bool yaru){
	for(int j=0;j<n;j++)vis[j]=false;
	DFS(h,0,w);
	if(yaru)DFS(w,0,h);
	int cnt=0;
	for(int i=0;i<n;i++)if(vis[i]==false)cnt++;
	return cnt;
}

int main(){
	cin>>n>>k;
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;a--,b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int ans=114514;
	for(int i=0;i<n;i++){
		if(k%2==0)ans=min(ans,Solve(i,i,false));
		else{
			for(int j=0;j<v[i].size();j++){
				ans=min(ans,Solve(i,v[i][j],true));
			}
		}
	}cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

int main()
{
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    s[k - 1] = s[k - 1] + 0x20;

    cout << s;
}

Measured memory_bytes: 256
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

class UnionFind():
    def __init__(self, elements):
        self.elements = elements
        self._root = {}
        self._count= {}
        for e in self.elements:
            self._root[e] = e
            self._count[e] = 1
        
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self._root[x] = y
            self._count[y] += self._count[x]
        
    def root(self, x):
        if self._root[x] != x:
            self._root[x] = self.root(self._root[x])
        return self._root[x]
    
    def size(self, x):
        return self._count[self.root(x)]

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(m)]
A.reverse()

ans = [n * (n - 1) // 2]
uf = UnionFind(range(1, n+1))
for a, b in A:
    if uf.root(a) == uf.root(b):
        ans.append(ans[-1])
        continue
    ans.append(ans[-1] - uf.size(a) * uf.size(b))
    uf.unite(a, b)

print(*ans[:-1][::-1], sep='\n')

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

int main(){ 
  
  int N; cin >> N;
  
  vector<ll> a(N); ll S = 0;
  vector<ll> r(N); vector<ll> e(N);
  
  ll ans = 0;
  
  for(int i = 0; i < N; i++){ cin >> a[i];}
  
 while(true){
  
  bool flag = true;
    
    ll res = 0;
  
  for(int i = 0; i < N; i++){
   
    res = max(res, a[i]/N); //最大値が0になるまで続行
   
  }
 
    
    if(res < 1){ break;} //この時終了
    
  ll R = 0;
    
    for(int i = 0; i < N; i++){ 
    r[i] = a[i]/N;
    e[i] = a[i]%N;
    R += r[i];
   
  }
    
    ans += R;
    
    for(int i = 0; i < N; i++){ 
      a[i] = R-r[i]+e[i];
    }
  
  }
  
  cout << ans << endl; return 0;
}
  
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}

int main() {
	run();
	int n, k;
	cin >> k >> n;
	vector<int> frq(k + 1);
	while (n--) {
		int m;
		cin >> m;
		while (m--) {
			int a;
			cin >> a;
			frq[a]++;
		}
	}
	int cnt = 0;
	for (int i = 1; i <= k; i++)
		cnt += (frq[i] == 0);
	cout << cnt << endl;
}


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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> l(N);
  for(int i = 0; i < N; i++){
    cin >> l[i];
  }
  sort(l.begin(), l.end());
  int res = 0;
  for(int i = 0; i < K; i++){
    res += l[N-1-i];
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

vvvi DP;

int dp(int a, int b, int c) {
	if (a == b && b == c) return 0;
	if (a >= 70 || b >= 70 || c >= 70) return 1e9;
	if (DP[a][b][c] != -1) return DP[a][b][c];
	return DP[a][b][c] = 1 + min({dp(a+1, b+1, c), dp(a+1, b, c+1),
		dp(a, b+1, c+1), dp(a+2, b, c), dp(a, b+2, c), dp(a, b, c+2)});
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    DP = vvvi(70, vvi(70, vi(70, -1)));
    cout << dp(a, b, c) << "\n";
    return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if (a < 10 && b < 10)
		cout << a * b;
	else
		cout << -1;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int k = in.nextInt();
			long[] an = in.nextLongArray(k);

			long min = 2;
			long max = 2;

			for (int i = k - 1; i >= 0; i--) {
				min = (min+an[i]-1)/an[i]*an[i];
				max = (max/an[i])*an[i]+an[i]-1;

				if (min > max) {
					out.println(-1);
					return;
				}

			}

			out.println(min+" "+max);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 39524
import sys
input = sys.stdin.readline
N=int(input())
b = -1
c = -1
r = 0
for i in list(map(int, input().split()))[::-1]:
    if i >= b:
        c += 1
    else:
        r = max(c, r)
        c = 0
    b = i
print(max(c, r))


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);

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

  int max = accumulate(v.begin(), v.end(), 0);
  int meio = max / 2;

  int soma = 0;
  int dif = meio;
  int flag = 0;

  for(int i = 0; i < n; i++) {
    soma += v[i];

    if(soma > meio) {
      if(soma - meio < dif) flag = 1;
      dif = min(dif, soma - meio);
      break;
    }

    dif = meio - soma; 
  }

  if(n == 1) cout << v[0] << endl;
  else if(max & 1) {
    if(flag) cout << (dif * 2) - 1 << endl;
    else cout << (dif * 2) + 1 << endl;
  }
  else cout << dif * 2 << endl;

  return 0;
}

Measured memory_bytes: 256
from decimal import *
getcontext().prec = 100
N = int(input())
Xmi, Xma, Ymi, Yma, DYmi, DYma, UYmi, UYma, RXmi, RXma, LXmi, LXma = [(10**10), -(10**10)] * 6
for _ in range(N):
    x, y, d = input().split()
    x, y = int(x), int(y)
    
    if d == "R":
        RXmi = min(RXmi, x)
        RXma = max(RXma, x)
    elif d == "L":
        LXmi = min(LXmi, x)
        LXma = max(LXma, x)
    else:
        Xmi = min(Xmi, x)
        Xma = max(Xma, x)
        
    if d == "U":
        UYmi = min(UYmi, y)
        UYma = max(UYma, y)
    elif d == "D":
        DYmi = min(DYmi, y)
        DYma = max(DYma, y)
    else:
        Ymi = min(Ymi, y)
        Yma = max(Yma, y)

def calc(t):
    xmi = min(RXmi+t, LXmi-t, Xmi)
    xma = max(RXma+t, LXma-t, Xma)
    ymi = min(UYmi+t, DYmi-t, Ymi)
    yma = max(UYma+t, DYma-t, Yma)
    return max(yma-ymi, 0)*max(xma-xmi, 0)
    
def dii(t):
    a = Decimal("0.00000001")
    return calc(t+a) - calc(t-a)

l = Decimal("0")
r = Decimal("10000000000")
for _ in range(500):
    m = (l+r)/2
    if dii(m) > 0:
        r = m
    else:
        l = m
print(calc(m))


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

using namespace std;

int main()
{
    int H,N;
    cin >> H >> N;
    vector<int> A(N);
    for (int i = 0;i < N;i++) {
        cin >> A[i];
    }
    int ans = H;
    for (int i = 0;i < N;i++) {
        ans = ans - A[i];
    }
    if(ans <= 0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}




Measured memory_bytes: 640
#include <iostream>
using namespace std;
int dp[1001][1001],S,T;
string s,t;
int main() {
    cin>>s>>t;
    S=s.size();
    T=t.size();
    for(int i=0;i<=S;i++)dp[i][0]=i;
    for(int i=0;i<=T;i++)dp[0][i]=i;
    for(int i=1;i<=S;i++){
        for(int j=1;j<=T;j++){
            int m=min(dp[i][j-1]+1,dp[i-1][j]+1);
            if(s[i-1]==t[j-1]){
                dp[i][j]=min(m,dp[i-1][j-1]);
            }
            else dp[i][j]=min(m,dp[i-1][j-1]+1);
        }
    }
    cout<<dp[S][T]<<endl;
}



Measured memory_bytes: 7120
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
int main(){
  ll N,K,ans=0;
  cin>>N>>K;
  for(ll i=0;i<N;i++){
    ll a;
    cin>>a;
    if(a>=K){ans++;}
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
fl = 0
tmp = 0
for i in range(N):
  a, b = map(int, input().split())
  if a==b:
    tmp += 1
  else:
    tmp = 0
  if tmp ==3:
    fl = 1
if fl:
  print('Yes')
else:
  print('No')




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

int main() {
int n;
cin >> n;
vector<double> vec(n);
for(int i = 0; i < n; i++){
    cin >> vec.at(i);
}
double m = 0.000000;
for(int i = 0; i < n; i++){
    m = m + (1 / vec.at(i));
}
cout << 1 / m << endl;
}


Measured memory_bytes: 256
n = int(input())
*A, = input().split()
B = A[:]
for i in range(n):
    for j in range(n-1, i, -1):
        if A[j][1] < A[j-1][1]:
            A[j], A[j-1] = A[j-1], A[j]
print(*A)
print("Stable")
 
for i in range(n):
    mj = i
    for j in range(i, n):
        if B[j][1] < B[mj][1]:
            mj = j
    B[i], B[mj] = B[mj], B[i]
print(*B)
if A == B:
    print("Stable")
else:
    print("Not stable")


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int a[m],b[m];
  for(int j = 0; j<m; j++){
    cin>>a[j]>>b[j];
  }
  

int count = 0;

   for(int i = 0; i<n; i++){
       for(int j = 0; j<m; j++){
         if(i+1 == a[j]||i+1==b[j]){
           count++;
           
         }
       
       }
       cout<<count<<endl;
       count = 0;
   }
   return 0;
}

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

int main()
{
    char x,y;
    while(cin>>x>>y)
    {
        if(x>y)
            cout<<">"<<endl;
        else if(x<y)
            cout<<"<"<<endl;
        else
            cout<<"="<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, w = ns()
    d = []
    for _ in range(n):
        tmp = na()
        d.append(tmp)

    dp = [-1 for _ in range(w + 1)]
    dp[0] = 0

    for vi, wi in d:
        for i in range(w, -1, -1):
            if dp[i] > -1 and i + wi < w + 1:
                dp[i + wi] = max(dp[i + wi], dp[i] + vi)

    print(max(dp))


if __name__ == '__main__':
    main()



Measured memory_bytes: 7628
#include <bits/stdc++.h>
using namespace std;
int main(){
        int a, b, c, d; cin >> a >> b >> c >> d;
        while (true){
            c -= b;
            if (c <= 0){
                cout << "Yes" << endl;
                return 0;
            }
            a -= d;
            if (a <= 0){
                cout << "No" << endl;
                return 0;
            }
        }
    return 0;
}



Measured memory_bytes: 3608
#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 find(Node, int);
void insert(int);
void inorder(Node);
void preorder(Node);

Node root;

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 = find(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");
    }
  }
  return 0;
}

/* ????´¢ */
Node find(Node root, int x)
{

  if(root == NIL || x == root->key) return root;
  if(x < root->key) return find(root->left, x);
  else return find(root->right, x);

}

/* ?????\ */
void insert(int k)
{

  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

}

/* ??????????????? */
void inorder(Node root)
{

  if(root != NIL){
    inorder(root->left);
    printf(" %d", root->key);
    inorder(root->right);
  }

}

/* ??????????????? */
void preorder(Node root)
{

  if(root != NIL){
    printf(" %d", root->key);
    preorder(root->left);
    preorder(root->right);
  }

}

Measured memory_bytes: 19364
#include <stdio.h>

int main() {

  int i,j,minj,N,A[100],temp,count=0; 

  scanf("%d",&N);
  for(i = 0; i < N; i++) {
    scanf("%d",&A[i]);
  }

  for(i = 0; i <= N-1; i++) {
    minj = i;
    for(j = i; j <= N-1; j++) {
      if(A[j] < A[minj]) {
	minj = j;
      }
    }
    if(minj != i) count++;
      temp = A[i];
      A[i] = A[minj];
      A[minj] = temp;    
  }

  for(i = 0; i < N; i++) {
    if(i) printf(" ");
    printf("%d",A[i]);
   
  }
  printf("\n%d\n",count);
  
  return 0;
}



Measured memory_bytes: 2124
#[warn(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1}
};

#[fastout]
fn main() {
   input! {
      n: usize,
      m: usize,
   }
   if n%2 == 1 {
      for i in 1..=m {
         println!("{} {}", i, i+1+2*(m-i));
      }
      return;
   }
   let mut diff = Vec::new();
   let mut count = 0;
   let mut i = 1;
   while i*2 < n {
      diff.push(i);
      i += 2;
      count += 1;
      if count == m {
         break;
      }
   }
   i += 1;
   while count < m {
      diff.push(i);
      i += 2;
      count += 1;
   }
   diff.reverse();
   for (i, d) in (1..=m).zip(diff.iter()) {
      println!("{} {}", i, i + d);
   }
}


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

import static java.lang.Integer.parseInt;

/**
 * Modular Query
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int N = parseInt(line.substring(0, line.indexOf(' ')));
			int Q = parseInt(line.substring(line.indexOf(' ') + 1));
			boolean[] cs = new boolean[300001];
			int max = 0;

			StringTokenizer st = new StringTokenizer(br.readLine());
			while (st.hasMoreTokens()) {
				int c = parseInt(st.nextToken());
				cs[c] = true;
				max = Math.max(max, c);
			}

			for (int i = 0; i < Q; i++) {
				int q = parseInt(br.readLine());
				int j = q - 1;
				found:
				for (; j >= 0; j--) {
					for (int k = j; k <= max; k += q) {
						if (cs[k]) break found;
					}
				}
				System.out.println(j);
			}
		}
	}
}

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

int main(){
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  if(v <= w) cout << "NO" << endl;
  else {
    ll d = abs(a - b);
    ll c = v - w;
    if(d <= c*t) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;

ll N, A, B, K;
const ll mod = 998244353;


// mod演算ライブラリ (modは素数限定)
// mod = 1000000007

ll add_mod(ll a, ll b) {  // a + b
	return (a + b) % mod;
}

ll sub_mod(ll a, ll b) {  // a - b
	return (a + mod - b) % mod;
}

ll mul_mod(ll a, ll b) {  // a * b
	return ((a % mod) * (b % mod)) % mod;
}

ll pow_mod(ll x, ll y) { // x^y 単品利用可
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) {
		ll tmp = pow_mod(x, y / 2) % mod;
		return tmp * tmp % mod;
	}
	else {
		ll tmp = pow_mod(x, y / 2) % mod;
		return ((tmp * tmp) % mod) * x % mod;
	}
}

ll dvs_mod(ll a, ll b) { // a / b (?)
	return mul_mod(a, pow_mod(b, mod - 2));
}

const ll SIZE_mod = 300005;
ll invfact[SIZE_mod];
ll fact[SIZE_mod];

void factset(int a) {  // a までの 階乗 % mod 表を作成
	fact[0] = 1;
	for (int i = 1; i <= a; ++i) {
		fact[i] = mul_mod(fact[i - 1], i);
	}
}

void cmbset(int a) {  // 1~a までの階乗と階乗数の逆元のmod(mod)を用意 O(a)
	factset(a);
	invfact[a] = pow_mod(fact[a], mod - 2);
	invfact[0] = 1;
	for (int i = a - 1; i >= 1; --i) {
		invfact[i] = mul_mod(invfact[i + 1], i + 1);
	}
}

ll cmb_mod(int n, int r) {  // nCr % mod  (cmbset後に使用)
	if (n < r || r < 0 || n < 0) return 0;
	return mul_mod(fact[n], mul_mod(invfact[r], invfact[n - r]));
}

ll prm_mod(int n, int r) {  // nPr % mod
	return mul_mod(cmb_mod(n, r), fact[n]);
}

ll homo_mod(int n, int r) {  // nHr % mod
	return cmb_mod(n + r - 1, r);
}


int main() {

	cin >> N >> A >> B >> K;
	cmbset(N + 1);

	ll ans = 0;
	for (ll p = 0; p <= K / A; ++p) {
		if ((K - p * A) % B == 0) {
			ll q = (K - p * A) / B;

			ans = add_mod(mul_mod(cmb_mod(N, p), cmb_mod(N, q)), ans);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;++i){
        if(1<=i&&i<10||100<=i&&i<1000||10000<=i&&i<100000)++ans;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func pow(x, n int) int {
	ans := 1
	for n != 0 {
		if n&1 == 1 {
			ans = ans * x
		}
		x = x * x
		n = n >> 1
	}
	return ans
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N+1)
	sum := 0
	for i := 0; i <= N; i++ {
		a[i] = getInt()
		sum += a[i]
	}

	ans := 0
	x := 1
	for i := 0; i <= N; i++ {
		ans += x
		if x < a[i] {
			out(-1)
			return
		}
		x -= a[i]
		sum -= a[i]
		x *= 2
		x = min(x, sum)
	}
	out(ans)
}


Measured memory_bytes: 3384
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pii;

int main(){
	string a, b;
	cin >> a >> b;
	
	int cnt = 0;
	for(int i = 0; i < len(a); i++)
		if(a[i] != b[i])
			cnt++;
		
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3896
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll INF=1LL<<60;
const ll mod=1E9+7;



int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll>a(n);
  rep(i,n)cin >> a[i];
  vector<int>s;
  vector<int>p(n+1,-1);
  int c=1,l=0;
  int v=1;
  while(p[v]==-1){
    p[v]=s.size();
    s.push_back(v);
    v=a[v-1];
  }
  c=s.size()-p[v];
  l=p[v];
  if(k<l)cout << s[k];
  else{
    k-=l;
    k%=c;
    cout << s[l+k];
  }
  return 0;
}



Measured memory_bytes: 6656