akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];

    
    while (K--) {
        vector<int> B(N, 0);
        REP(i, 0, N) {
            B[max(0, i - A[i])]++;
            if (i + A[i] + 1 < N) B[i + A[i] + 1]--;
        }
        bool done = true;
        REP(i, 1, N) {
            B[i] += B[i - 1];
            if (B[i] != N) done = false;
        }

        A = B;
        if (done) break;
    }
    for (auto a : A) cout << a << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
int n[10000];
int main(){
  int a,b;
  cin >> a >> b;
  for(int i = 0;i < a;i++){
    cin >> n[i];
  }
  sort(n,n+a);
  int cook = 0;
  int count = 0;
  for(int i = 0;i < a;i++){
    b -= n[i];
     if(b < 0) break;
     count++;
    }
  if(b > 0) count--;
      cout << count << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll dp[2][1010101];
const ll INF = (1ll<<60);

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

    string S;
    cin >> S;
    S = '0' + S;

    ll N = S.size();

    REP(i, 2) REP(j, 1010101) dp[i][j] = INF;
    dp[0][0] = 0;

    REP(i, N){
    	ll val = S[N-1-i] - '0';
    	REP(j, 10){
    		ll kuri = (val + j)/10;
    		ll kazu = (val + j)%10;
    		chmin(dp[kuri][i+1], dp[0][i] + j + kazu);

    		kuri = (val + j + 1)/10;
    		kazu = (val + j + 1)%10;
    		chmin(dp[kuri][i+1], dp[1][i] + j + kazu);
    	}
    }

    /*
    REP(i, 2){
    	REP(j, N+1){
    		cout << dp[i][j] << " ";
    	}
    	cout << endl;
    }
    */

    cout << min(dp[0][N], dp[1][N]) << endl;
    return 0;
}

Measured memory_bytes: 17096
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        p: usize,
        v: [usize; n]
    }
    if v.iter().filter(|&x| x & 1 == 0).count() == n {
        println!("{}", if p == 0 {1usize << n} else {0});
    } else {
        println!("{}", 1usize << n - 1);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int n,id;
char ch;
char s[200];
int t[26];
P a[26];
 
void solve(){
  fill(t,t+26,0);
  for(int i=0;i<n;i++){
    id=s[i]-'A';
    t[id]++;
    for(int j=0;j<26;j++)a[j]=P(t[j],j);
    sort(a,a+26);
    reverse(a,a+26);
    if(a[0].first>a[1].first+(n-1-i)){
      cout<<(char)(a[0].second+'A')<<' '<<i+1<<endl;
      return;
    }
  }
  cout<<"TIE"<<endl;
}
 
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>s[i];
    solve();
  }
  return 0;
}

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

int main(void) {
    int n, m, a, h, p, q, i;
    while (1) {
        cin >> n >> m >> a;
        if (n + m + a == 0) break;
        vector<vector<int> > bar;
        for (i = 0; i < m; i++) {
            cin >> h >> p >> q;
            vector<int> b;
            b.push_back(h); b.push_back(p); b.push_back(q);
            bar.push_back(b);
        }
    
        sort(bar.begin(), bar.end());

        h = 0;
        for (i = m - 1; i >= 0; i--) {
            if (bar[i][0] == h) continue;
            if (bar[i][1] == a) {
                a = bar[i][2];
                h = bar[i][0];
            }
            else if (bar[i][2] == a) {
                a = bar[i][1];
                h = bar[i][0];
            } 
        }
        cout << a << endl;
    }
    return 0;
}

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

int main()
{
    string s;
    cin>>s;
    if(s == "Sunny")
        cout<<"Cloudy"<<endl;
    else if(s == "Cloudy")
        cout<<"Rainy"<<endl;
    else
        cout<<"Sunny"<<endl;
}

Measured memory_bytes: 384
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007


int main(int argc, char const *argv[]) {
  ll a,b,ans=0;
  std::cin >> a >> b;
  for(int i=0; i<=b-a; i++) ans+=i;
  std::cout << ans-b << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int n, a[100], i;
   double x=0;

   scanf("%d",&n);
   for(i=0;i<n;i++){
      scanf("%d",&a[i]);
      x+=1/(double)a[i];
   }

   x=1/x;
   printf("%lf\n",x);
   return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;
    int S,T;
    S = T = 1;
    for(int i = N; i > N - 2; i--){
        S *= i;
    }
    for(int i = M; i > M - 2; i--){
        T *= i;
    }
    //cout << S/2 << T / 2 << endl;
    cout << S/2 + T/2 << endl;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  rep(i,n) std::cin >> a[i];
  std::sort(all(a));
  int amin = a[0];
  int amax = a[n-1];
  std::vector<std::pair<int,int> > procedure;
  procedure.reserve(n-1);
  for(int i=1;i<n-1;i++) {
    if(a[i]>=0) {
      procedure.emplace_back(amin,a[i]);
      amin -= a[i];
    }
    else {
      procedure.emplace_back(amax,a[i]);
      amax -= a[i];
    }
  }
  print(amax-amin);
  procedure.emplace_back(amax,amin);
  rep(i,n-1) {
    std::cout << procedure[i].first << " " << procedure[i].second << "\n";
  }
  return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 128
ll a[N], b[N] = {1000};

int main(){
	int n; scanf("%d", &n);
	REP(i, n) scanf("%lld", a+i);
	REP(i, n){
		FOR(j, i+1, n) LAR(b[j], b[i]);
		FOR(j, i+1, n) LAR(b[j], b[i] / a[i] * a[j] + b[i] % a[i]);
	}
	printf("%lld\n", b[n-1]);
}


Measured memory_bytes: 3840
// header {{{
// header {{{
#include <bits/stdc++.h>
using namespace std;
 
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
 
#define ASSERT(expr...) assert((expr))
 
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
 
using f32 = float;
using f64 = double;
// }}}
 
constexpr i64 INF = 1'010'000'000'000'000'017LL;
 
constexpr i64 MOD = 1'000'000'007LL;
 
constexpr f64 EPS = 1e-12;
 
constexpr f64 PI = 3.14159265358979323846;
 
#define M5 100007
 
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define ll long long int
#define VI vector <ll>
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
 
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
 
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
 
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}
 
// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
 
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}
 
//--------------------------------------------------------------------
 
 
 
void solve() {
    ll N,A,B;
    cin >> N >> A >> B;
    ll s = N/(A+B);
    ll p = N - N/(A+B)*(A+B);
    cout << fixed << setprecision(0) << s*A+min(p,A);
}
 
signed main() {
 
    solve();
 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N, X;
    cin >> N >> X;
    VLL x(N);
    rep(i,N){
        cin >> x[i];
    }
    VLL ans(N);
    ll a=abs(x[0]-X);
    rep(i,N){
        ans[i]=abs(x[i]-X);
        a=gcd(a,ans[i]);
    }
    cout << a << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <queue>
using namespace std;
int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    long long int a[n];
    priority_queue<long long int> q;
    for(int i=0;i<n;i++){
      scanf("%lld",&a[i]);
      q.push(a[i]);
    } 
    long long int p=0;
    while(m!=0){
        q.push( q.top()/2 );
        q.pop();
        m--;
    }
    
    while(!q.empty()){
        p += q.top();
        q.pop();
    }
    
    printf("%lld\n",p);
    return 0;
}


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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

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

    int n, m;
    cin >> n >> m;
    vector<string> grid(n);
    for (auto& r : grid)
        cin >> r;

    vector<vi> left(n, vi(m, -1)), right(n, vi(m, -1)), up(n, vi(m, -1)), down(n, vi(m, -1));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (grid[i][j] == '#') continue;
            if (j == 0) left[i][j] = 0;
            else left[i][j] = 1 + left[i][j - 1];
        }
        for (int j = m - 1; j >= 0; --j) {
            if (grid[i][j] == '#') continue;
            if (j == m - 1) right[i][j] = 0;
            else right[i][j] = 1 + right[i][j + 1];
        }
    }

    for (int j = 0; j < m; ++j) {
        for (int i = 0; i < n; ++i) {
            if (grid[i][j] == '#') continue;
            if (i == 0) up[i][j] = 0;
            else up[i][j] = up[i - 1][j] + 1;
        }
        for (int i = n - 1; i >= 0; --i) {
            if (grid[i][j] == '#') continue;
            if (i == n - 1) down[i][j] = 0;
            else down[i][j] = down[i + 1][j] + 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            int x = up[i][j] + right[i][j] + down[i][j] + left[i][j] + 1;
            ans = max(ans, x);
        }
    }

    cout << ans << '\n';

    return 0;
}


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

long long mod = 1e9+7;

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

    vector<long long> a(n);

    for(long long i = 0; i < n; i++){
        cin >> a[i];
    }

    long long res = 0;
    long long two_factor = 1;

    for(long long d = 0; d < 60; d++){
        long long even = 0, odd = 0;
        for(long long i = 0; i < n; i++){
            if(a[i] & ((long long)1 << d)) odd++;
            else even++;
        }
        long long add = ((odd*even) % mod) *(two_factor % mod);
        res = (res + add) % mod;
        two_factor = (two_factor* 2) % mod;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int N;
	int A[100001];
	int cnt = 1;
	cin >> N;
	REP(i, 0, N) cin >> A[i];

	bool flag; // false:-, true:+
	int i = 0;
	while (i + 1 < N && A[i] == A[i + 1]) {
		i++;
	}
	if (i == N - 1) {
		cout << cnt << endl;
		return 0;
	}

	if (A[i] < A[i + 1]) flag = true;
	else flag = false;
	i++;

	while(i<N){
		if (flag && A[i - 1] <= A[i]) {
			i++;
			continue;
		}
		else if (!flag && A[i - 1] >= A[i]) {
			i++;
			continue;
		}
		else if (flag && A[i - 1] > A[i]) {
			cnt++;
			if (i + 1 < N) {
				while (i + 1 < N && A[i] == A[i + 1]) {
					i++;
				}
				if (A[i] < A[i + 1]) flag = true;
				else flag = false;
			}
		}
		else {
			cnt++;
			if (i + 1 < N) {
				while (i + 1 < N && A[i] == A[i + 1]) {
					i++;
				}
				if (A[i] < A[i + 1]) flag = true;
				else flag = false;
			}
		}
		i++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+7,mod=1e9+7;
int read() {
	int x=0,f=1;char s=getchar();
	for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
	for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
	return x*f;
}
int n,a[N],lat[N],fdt[N],f[N];
int main() {
	n=read();
	for(int i=1;i<=n;++i) {
		a[i]=read();
		lat[i]=fdt[a[i]];
		fdt[a[i]]=i;
	}
	f[1]=1;
	for(int i=2;i<=n;++i) {
		f[i]=f[i-1];
		if(lat[i]!=i-1) f[i]+=f[lat[i]],f[i]%=mod;
	}
	cout<<f[n]%mod<<"\n";
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

// UnionFind 木 ; 頂点 = 0, 1, 2, ...,  n-1
class UnionFindTree{
private:
    using Vint = std::vector<int>;
    const int n; // 集合の大きさ
    Vint Parent; // 親のインデックスを指し示す
    Vint SetSize; // 各集合の大きさ(要素数)を保持する関数
public:
    // コンストラクタ
    UnionFindTree(int nn): n(nn){
        SetSize.resize(n, 1);
        Parent.resize(n);
        // 初めは, 全ての頂点は根である
        for(int i = 0; i < n; ++i) Parent[i] = i;
    }
    // デコンストラクタ
    ~UnionFindTree(void){}
    // 頂点 x の属する集合の根を返す関数
    int rootOf(int x){
        // x が 根であるなら終了
        if(Parent[x] == x) return x;
        // そうでないなら, 親を属する集合の根に付け替える
        return Parent[x] = rootOf(Parent[x]);
    }
    // 頂点 x, y を併合する
    void unite(int x, int y){
        int root_x = rootOf(x);
        int root_y = rootOf(y);
        // 異なる集合に属する場合
        if(root_x == root_y) return;
        if(SetSize[root_x] < SetSize[root_y]) std::swap(root_x, root_y);
        Parent[root_y] = root_x;
        SetSize[root_x] += SetSize[root_y];
    }
    // 頂点 x, y が 同じ集合に属しているかを判定する
    bool sameSet(int x, int y){
        return rootOf(x) == rootOf(y);
    }
    // 頂点 x の属する集合の要素数
    int sizeOf(int x){
        return SetSize[rootOf(x)];
    }
};

std::vector<int> A;


int main(void){
    int n, m; scanf("%d%d", &n, &m);
    A.resize(n); REP(i, n){scanf("%d", &A[i]); --A[i];}
    UnionFindTree UFT(n);

    REP(i, m){
        int x, y; scanf("%d%d", &x, &y); x--; y--;
        UFT.unite(x, y);
    }
    int cnt = 0;
    REP(i, n){
        if(UFT.sameSet(i, A[i])) cnt++;
    }
    printf("%d\n", cnt);
    
    return 0;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count_ans = 0;
    for (int i = 1; i <= n; i += 2) {
      int count_tmp = 0;
      for (int j = 1; j <= i; j += 2) {
        if (i % j == 0) {
          count_tmp++;
        }
      }
      if (count_tmp == 8) {
        count_ans++;
      }
    }
    System.out.println(count_ans);
  }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
struct SegmentTree {
    ll n;
    vector<l_l> node;

    SegmentTree() {
        int sz = 100050;
        n = 1;
        while(n < sz) n *= 2;
        node.resize(2*n-1);
        for(int i = 0; i < sz; i++) {
            node[i+n-1] = {0, 0};
        }
        for(int i = n - 2; i >= 0; i--) node[i] = {0, 0};
    }
    void update(ll x, l_l val) {
         x += n - 1;
         node[x] = val;
         while(x > 0) {
             x = (x - 1) / 2;
             node[x] = max(node[2*x+1], node[2*x+2]);
         }
    }

    l_l getmax(int a, int b, int k = 0, int l=0, int r=-1) {
        if(r<0) r = n;
        if(r <= a || b <= l) return {0, 0};
        if(a<=l && r <= b) return node[k];
        l_l vl = getmax(a,b,2*k+1,l,(l+r)/2);
        l_l vr = getmax(a,b,2*k+2,(l+r)/2, r);
        return max(vl, vr);
    }
};

int main() {
    ll N;
    cin >> N;
    SegmentTree seg;
    vector<l_l> A(N);
    for(ll i = 1; i <= N; i++) {
        A[i-1].second = i;
        cin >> A[i-1].first;
        A[i-1].first = -A[i-1].first;
    }
    sort(A.begin(), A.end());
    for(int i = 0; i < N; i++) {
        A[i].first = -A[i].first;
        int index = A[i].second;
        l_l maximum = seg.getmax(index, N + 1);
        l_l NEW = maximum;
        NEW.first++;
        NEW.second += A[i].first;
        seg.update(index, NEW);
        //cout << endl << i << endl;
        //for(int j = 1; j <= N; j++) {
            //l_l now = seg.getmax(j, j+1);
            //cout << j << " " << now.first << " " << now.second << endl;
        //}
        //cout << i << " " << index << " " << NEW.first << " "<< NEW.second << endl;

    }
    ll ans = 0;
    ll longest = 0;
    for(int i = 1; i <= N; i++) {
        longest = max(longest, seg.getmax(i,i+1).first);
    }
    for(int i = 1; i <= N; i++) {
        l_l val = seg.getmax(i, i+1);
        if(val.first != longest) continue;
        //cout << i << " " << val.first << "s " << val.second << endl;
        ans = max(ans, val.second);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8352
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
const int nmax=40,abmax=10,inf = 1000000;

 int a[nmax],b[nmax],c[nmax];
 int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];

 int main(void){
 int n,ma,mb;
 cin >> n >> ma >> mb;

 for(int i=0;i<n;++i){
 cin >> a[i] >> b[i] >> c[i];
 }

 for(int i = 0; i <= n; ++i){
 for(int ca = 0; ca <= nmax*abmax; ++ca){
 for(int cb = 0; cb <= nmax*abmax; ++cb){
 dp[i][ca][cb]=inf;
}
}
}

dp[0][0][0]=0;


 for(int i = 0; i < n; ++i){
 for(int ca = 0; ca <= nmax*abmax; ++ca){
 for(int cb = 0; cb <= nmax*abmax; ++cb){
 if(dp[i][ca][cb]==inf) continue;
 dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb]);
 dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]);
 }
 }
 }

 int ans=inf;
 for(int ca = 1; ca <= nmax*abmax; ++ca){
 for(int cb = 1; cb <= nmax*abmax; ++cb){
 if(ca*mb==cb*ma) ans=min(ans,dp[n][ca][cb]);
 }
 }

 if(ans==inf) ans=-1;
 cout << ans << endl;

 return 0;
 }


Measured memory_bytes: 25984
#include <cstdio>
#include <cstring>
#define N 10000000
#define mod_32(n) (n&((1<<5)-1))
int prime[(N>>5)+1];

void init(){
	memset(prime,-1,sizeof(prime));
	prime[0] = prime[0] - (1<<0) - (1<<1);
	for(int i=2;i*i <= N;i++){
		if( prime[i>>5] & (1 << mod_32(i)) ){
			for(int j=i*i;j<=N;j+=i){
				prime[j>>5] -= (prime[j>>5] & (1<<mod_32(j)));
			}
		}
	}
}
inline bool isprime(int n){
	return !!(prime[n>>5] & (1<<mod_32(n)));
}
int main(){
	int n;
	init();
	while(~scanf("%d",&n)){
		while(n){
			if( isprime(n) & isprime(n-2) & isprime(n-6) & isprime(n-8) ){printf("%d\n",n);break;}
			n--;
		}
	}
}

Measured memory_bytes: 1984
#include<cstdio>
#include<algorithm>

using namespace std;

#define MAX 1400

int dp[MAX][MAX], G[MAX][MAX];


int getLargestSquare(int H, int W) {
  int maxWidth = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      dp[i][j] = (G[i][j] + 1) % 2;
      maxWidth |= dp[i][j];
    }
  }

  for (int i = 1; i < H; i++) {
    for (int j = 1; j < W; j++) {
      if (G[i][j]) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
        maxWidth = max(maxWidth, dp[i][j]);
      }
    }
  }

  return maxWidth * maxWidth;
}

int main() {
  int H, W;
  scanf("%d %d", &H, &W);

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf("%d", &G[i][j]);
    }
  }

  printf("%d\n", getLargestSquare(H, W));

  return 0;
}




Measured memory_bytes: 17988
n = int(input())

a = list(map(int, input().split()))

M = 1000000007


def mod(a, b):
    return (a % b + b) % b

def gcd(a ,b):
    if b == 0:
        return a
    return gcd(b, a % b)

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

def extGCD(a,b):
    if b==0:
        return a,1,0
    d, y, x = extGCD(b, a%b)
    y -= a // b * x
    return d, x, y

def modinv(a,p):
    b, x, y = extGCD(a, p)
    return mod(x,p)


gcdval = a[0]
modpi = 1
lcmval = 1
for i in range(n):
    modpi = mod(modpi * a[i], M)
    gcdval = gcd(gcdval, a[i])
    lcmval = lcm(lcmval, a[i])

#print("GCD: {}".format(gcdval))
#print("pi: {}".format(modpi))    
#print("lcm: {}".format(lcmval))

sum = 0
for i in range(n):
    sum = sum + mod(lcmval * modinv(a[i], M), M)
    #print("{}".format(mod(lcmval * modinv(a[i], M), M)))
    sum = mod(sum, M)

print("{}".format(sum))


Measured memory_bytes: 4084
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int SZ = 200000;
class UF {
public:
	int P[SZ + 1], saidai;
	UF() : P(), saidai() {
		saidai = -1;
		rep1(i, SZ) P[i] = -1;
	}
	int find(int A) {
		if (P[A] < 0) return A;
		return P[A] = find(P[A]);
	}
	bool unite(int A, int B) {
		int a = find(A);
		int b = find(B);
		if (a == b) return false;
		if (P[a] > P[b]) swap(a, b);
		P[a] += P[b];
		if (P[a] < saidai) saidai = P[a];
		P[b] = a;
		return true;
	}
} uf;

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

	int N = getint(), M = getint();

	rep(i, M) {
		uf.unite(getint(), getint());
	}

	printf("%d\n", -uf.saidai);


	Would you please return 0;
}

Measured memory_bytes: 2492
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans=0,o=1;
    rep(i,60){
        ll u=0;
        rep(j,n){
            if ((a[j]&1)==1) u++;
            a[j]/=2;
        }
        ans=(ans+(u*(n-u)%MOD)*o%MOD)%MOD;
        o=(o*2)%MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2688
//package atcoder;
 
import java.util.*;
//import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println(A*B);
	}
}

Measured memory_bytes: 35784
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <cctype>
using namespace std;
int main() {
	int n, a;
	string ss;
	vector< pair < string, pair<int, int>>>s;
	
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> ss >> a;
		s.push_back(make_pair(ss,make_pair( -a,i+1)));
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < n; ++i) {
		cout << s[i].second.second << endl;
	}

}

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

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N, M; cin >> N >> M;
  vector<vector<int>> jobs(M);
  rep(i, N){
    int a, b; cin >> a >> b;
    if (a > M) continue;
    jobs[M - a].push_back(b);
  }
  priority_queue<int, vector<int>> q;
  ll ans = 0;
  for (int i = M - 1; i >= 0; --i){
    for (int b: jobs[i]){
      q.push(b);
    }
    if (!q.empty()){
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5504
nums = list(map(int, input().split()))
A, B = nums[0], nums[1]

if A == B:
    print(A)
else:
    ans = 0
    if A % 2 == 0:
        if B % 2 == 0:
            ans += ((B-A) // 2) % 2
        else:
            ans += ((B-A) // 2 + 1) % 2
    else:
        ans += ((B-A) // 2 + 1) % 2

    def up(n, a):
        if a % (2 ** n) <= 2 ** (n-1):
            return 2 ** (n - 1)
        else:
            return (2 ** n) - (a % (2 ** n))

    def down(n, a):
        if a % (2 ** n) < 2 ** (n-1):
            return 0
        else:
            return (a % (2 ** n)) - (2 ** (n-1)) + 1
    n = 2
    while 2 ** (n-1) <= B:
        u = up(n, A)
        d = down(n, B)
        num = (u + d) % 2
        ans += (2**(n-1)) * num
        n += 1

    print(ans)


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

int main(){
	
	int n; cin>>n;
	int b{};
	for(int i=0; i<n; i++){
		int a; cin>>a;
		b ^= a;
	}
	if(!b) cout << "Yes" << endl;
	else cout << "No" << endl;
	
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string instr1,instr2;
    cin >> instr1 >> instr2;
    if(instr1[0]==instr2[2] && instr1[1]==instr2[1] && instr1[2]==instr2[0]) {
        cout << "YES" <<endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

H,W = map(int,readline().split())
DIV = 10 ** 9 + 7
G = [None] * H
for i in range(H):
  G[i] = readline().rstrip()

dp = [[0] * (W + 1) for i in range(H + 1)]
dp[0][1] = 1

for i in range(H):
  for j in range(W):
    if G[i][j] == "#":
      dp[i + 1][j + 1] = 0
    else:
      dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1]
      dp[i + 1][j + 1] %= DIV
      
print(dp[-1][-1])


Measured memory_bytes: 49448
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c,d;
  while(scanf("%d %d",&a,&b)!=EOF){
    d=0;
    c=a+b;
    while(true){
      if(c==0) break;
      d++;
      c=c/10;
    }
    printf("%d\n",d);
  }
}



Measured memory_bytes: 3216
while 1:
	try:
		x = float(input())
	except:
		break
	s=x
	for i in range(9):
		if i % 2 == 0:
			s = s*2
			x+=s
		if i % 2 == 1:
			s = s/3
			x+=s
	print(x)


Measured memory_bytes: 5584
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int a,b;
    while(cin >> a >> b,a|b){
        vector<vector<int> > dp(a+1,vector<int>(b+1,0));
        vector<vector<int> > mp(a+1,vector<int>(b+1,1));
        
        int N;cin >> N;
        rep(i,N){
            int c,d;cin >> c >> d;
            mp[c][d]=0;
        }
        dp[1][1]=1;
        for(int i=1;i<=a;i++){
            for(int j=1;j<=b;j++){
                if(i==1&&j==1)continue;
                if(!mp[i][j])dp[i][j]=0;
                else dp[i][j]=dp[i-1][j]+dp[i][j-1];
            }
        }
        cout << dp[a][b] << endl;
    }
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> num(m);
  rep(i, m) cin >> num[i].first >> num[i].second;
  rep(i, 1000) {
    int keta = 1;
    int x = i/10;
    vector<int> d(1, i%10);
    while(x) {
      keta++;
      d.push_back(x%10);
      x /= 10;
    }
    if(keta != n) continue;
    reverse(d.begin(), d.end());
    bool flag = true;
    rep(i, m) {
      if(d[num[i].first-1] != num[i].second) flag = false;
    }
    if(flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <cmath>
using namespace std;
#define fio ios::sync_with_stdio(0),cin.tie(0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



char S[100005];
ll K;
int main() {
	scanf("%s", S+1);
	scanf("%lld", &K);
	int base = 0;
	for (int i = 1;S[i];i++) {
		if (S[i] == '1') base = i;
		else break;
	}
	if (K <= base) printf("1");
	else printf("%c", S[base + 1]);
}



Measured memory_bytes: 256
base = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))

counter = [0 for i in range(N)]

flag = True
for i in A:
  counter[i] += 1
  
for i in range(N):
  if counter[i] > 2:
    flag = False
if counter[0] > 1:
  flag = False
  
if flag:
  if N % 2 == 0:
    print(2**(N//2) % base)
  else:
    print(2**((N-1)//2) % base)
else:
  print(0)

Measured memory_bytes: 14008
# 2回前までのを保存しておく全探索？
# -> ATGC ACGC AGGC の場合も条件を満たしてしまうので、3つ前までかも（気づくのに長時間かかった）
# -> AGxCの場合も気づかなかった...

# なぜかサンプル3が合わないがコードが間違ってるわけないので表記ミスと判断して提出（傲慢
# -> MODしてないだけだった...

n = int(input())
if n == 3:
    print(61)
    exit()

memo = {}
MOD = 10**9 + 7


def rec(i, pre3, pre2, pre1):
    if pre3 == "A" and pre2 == "G" and pre1 == "C":
        return 0
    if pre3 == "G" and pre2 == "A" and pre1 == "C":
        return 0
    if pre3 == "A" and pre2 == "C" and pre1 == "G":
        return 0
    if (i, pre1, pre2, pre3) in memo:
        return memo[(i, pre1, pre2, pre3)]
    if i == n - 3:
        return 1
    else:
        ret = 0
        if (pre1 == "G" and pre2 == "A") or (pre1 == "A" and pre2 == "G"):
            ret = rec(i + 1, pre2, pre1, "A") % MOD + rec(
                i + 1, pre2, pre1, "G") % MOD + rec(i + 1, pre2, pre1,
                                                    "T") % MOD
        elif pre1 == "C" and pre2 == "A":
            ret = rec(i + 1, pre2, pre1, "C") % MOD + rec(
                i + 1, pre2, pre1, "A") % MOD + rec(i + 1, pre2, pre1,
                                                    "T") % MOD
        elif pre3 == "A" and pre1 == "G":
            ret = rec(i + 1, pre2, pre1, "A") % MOD + rec(
                i + 1, pre2, pre1, "G") % MOD + rec(i + 1, pre2, pre1,
                                                    "T") % MOD
        elif pre3 == "A" and pre2 == "G":
            ret = rec(i + 1, pre2, pre1, "A") % MOD + rec(
                i + 1, pre2, pre1, "G") % MOD + rec(i + 1, pre2, pre1,
                                                    "T") % MOD
        else:
            ret = rec(i + 1, pre2, pre1,
                      "A") + rec(i + 1, pre2, pre1, "G") % MOD + rec(
                          i + 1, pre2, pre1, "C") % MOD + rec(
                              i + 1, pre2, pre1, "T") % MOD
        ret %= MOD
        memo[(i, pre1, pre2, pre3)] = ret
        return ret


# 最初とりうるやつ（めんどい）
ans = 0
for i in ["A", "G", "C", "T"]:
    for j in ["A", "G", "C", "T"]:
        for k in ["A", "G", "C", "T"]:
            ans += rec(0, i, j, k)

print(ans % MOD)


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

int N;
int u[100000+1], v[100000+1], w[100000+1];

typedef struct {
  long to;
	long len;
} S_NODE;

int edgeCount[100000+1];
S_NODE* edges[100000+1];

void addEdge(int from, int to, int len) {
	edges[from] = realloc(edges[from], sizeof(*edges[from]) * (edgeCount[from] + 1));
	if (edges[from] == NULL) exit(2);
	edges[from][edgeCount[from]].to = to;
	edges[from][edgeCount[from]].len = len;
	edgeCount[from]++;
}

int tree[100000+1];

void dfs(int node, int color) {
	if (tree[node] == 0) {
		int i;
		tree[node] = color + 1;
		for (i = 0; i < edgeCount[node]; i++) {
			dfs(edges[node][i].to, edges[node][i].len % 2 == 0 ? color : 1 - color);
		}
	}
}

int main(void) {
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N - 1; i++) {
		if (scanf("%d%d%d", &u[i], &v[i], &w[i]) != 3) return 1;
		addEdge(u[i], v[i], w[i]);
		addEdge(v[i], u[i], w[i]);
	}
	dfs(1, 0);
	for (i = 1; i <= N; i++) {
		printf("%d\n", tree[i] - 1);
	}
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

//桁数
int calc_digit(ll x) {
   int res = 0;
   while(x > 0) {
       x /= 10;
       res++;
   }
   return res;
}

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

    int ans = 114514;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ll j = n / i;
            int tmp = max(calc_digit(i), calc_digit(j));
            ans = min(ans, tmp);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author G. Guarnieri
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            int[] outcome = new int[n];
            int mid = n / 2;
            int switchPoint = n % 2;
            for (int i = 0; i < n; i++) {
                int index = mid - Math.floorDiv(-i, 2) * (i % 2 == switchPoint ? 1 : -1);
                outcome[index] = a[i];
            }

            final String collect = Arrays.stream(outcome).mapToObj(Integer::toString).collect(Collectors.joining(" "));
            out.println(collect);
        }

    }
}



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

int main(){
    int V, E;
    cin >> V >> E;
    vector<pair<int, int> > edge(E);
    for (int i = 0; i < E; i++) {
        cin >> edge[i].first >> edge[i].second;
    }
    vector<int> ans;
    vector<int> state(V, 0);

    for (int i = 0; i < E; i++) {
        state[edge[i].second]++;
    }

    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            if (state[i] == 0) {
                ans.push_back(i);
                for (int j = 0; j < E; j++) {
                    if (edge[j].first == i) state[edge[j].second]--;
                }
                state[i]--;
                break;
            }
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }

    return 0;
}



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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

int C[200005];
int X[200005];
int main()
{
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    vector<ll> C(N);
    rep(i, N)cin >> A[i], A[i]--;
    
    int p = 0;
    rep(j, K){
        X[j] = p;
        //cout << p << endl;
        if (C[p]){
            int cycle = j - C[p];
            cout << X[C[p] + (K - C[p])%cycle] + 1;
            return 0;
        }
        C[p] = j;
        p = A[p];
    }
    cout << p + 1;
    return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int l, r; cin >> l >> r;
        vector<int> vis(2019);
        int sum = 0;
        for (int i = l; i <= r; i++) {
                sum += !vis[i % 2019];
                vis[i % 2019] = 1;
                if (sum == 2019) break;
        }

        int ans = 1e9;
        for (int i = 0; i < sz(vis); i++) {
                for (int j = 0; j < i; j++) {
                        if (vis[i] && vis[j]) ans = min(ans, (i * j) % 2019);
                }
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3588
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int l, a, b, c, d;
        l = Integer.parseInt(sc.nextLine());
        a = Integer.parseInt(sc.nextLine());
        b = Integer.parseInt(sc.nextLine());
        c = Integer.parseInt(sc.nextLine());
        d = Integer.parseInt(sc.nextLine());
        while (a > 0 || b > 0) {
            l -= 1;
            a -= c;
            b -= d;
        }
        System.out.println(l);
    }
}

Measured memory_bytes: 17128
#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-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){
    const int MAX = 100005;
    int n, q;
    cin >> n;
    vector<ll> numcount(MAX, 0);
    ll ans = 0;
    rep (i, n) {
        int tmp;
        cin >> tmp;
        numcount[tmp]++;
        ans += tmp;
    }

    cin >> q;
    rep (i, q) {
        int tmp_b, tmp_c;
        cin >> tmp_b >> tmp_c;
        ans -= tmp_b * numcount[tmp_b];
        ans += tmp_c * numcount[tmp_b];
        numcount[tmp_c] += numcount[tmp_b];
        numcount[tmp_b] = 0;
        cout << ans << endl;
    }

  return 0;
}

Measured memory_bytes: 4004
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;

bool sht[400][400];
ii dp[400][400];
int arr[400];

ii rec(int l, int r)
{
    if (sht[l][r]) return dp[l][r];
    sht[l][r] = 1;
    
    if (l == r) return dp[l][r] = {0, arr[l]};
    
    for (int i = l; i != r; ++i)
    {
        ii s = rec(l, i), t = rec(i + 1, r);
        dp[l][r].second = s.second + t.second;
        if (dp[l][r].first)
            dp[l][r].first = min(dp[l][r].first, dp[l][r].second + s.first + t.first);
        else
            dp[l][r].first = dp[l][r].second + s.first + t.first;
    }
    
    return dp[l][r];
}

signed main()
{
    int n;
    cin >> n;
    for (int i = 0; i != n; ++i) cin >> arr[i];
    
    cout << rec(0, n - 1).first;
    return 0;
}

Measured memory_bytes: 2816
m, n = gets.split.map(&:to_i)
p = 1000000007
def pow(a, b, m)
  return 1 if b.zero?
  mod = pow(a, b / 2, m)
  mod = (mod * mod) % m
  mod = (mod * a) % m if b.odd?
  return mod
end
puts pow(m, n, p)


Measured memory_bytes: 6864
n,k= map(int,input().split())
A  = [0]
A += list(map(int,input().split()))
B = [-1 for _ in range(n+1)]
B[1] = 0
now =1
cnt = 0
cic = 0
for i in range(1,n+1):
    now = A[now]
    cnt +=1
    if B[now] ==-1:
        B[now] = cnt
    else:
        cic = cnt - B[now]
        road = B[now] 
        break

if k <= road:
    print(B.index(k)) 
else:
    print(B.index(((k-road)%cic+road)))

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll l, r;
  cin >> l >> r;
  ll minv = LLONG_MAX;
  for (ll i = l; i <= l+2019; i++) {
    if(i == r+1) break;
    for (ll j = i+1; j <= i+1+2019; j++) {
      // cout << j << endl;
      if(j == r+1) break;
      minv = min((i*j) % 2019, minv);
    }

    // cout << i << minv << endl;
  }

  cout << minv << endl;
}
    // if(minv == 0){
    //   if(r <= minv + 2019){
    //     cout << 0 << endl;
    //     return 0;
    //   }else if(r == minv){
    //     cout << ((l % 2019) * ((l + 1) % 2019)) % 2019 << endl;
    //     return 0;
    //   }
    // }


Measured memory_bytes: 256