akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define nl n<<1
#define nr (n<<1)|1
#define first fi
#define second se
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-9;
const ll mod=1e9+7;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' | ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void Out(int aa)
{
    if(aa>9)
        Out(aa/10);
    putchar(aa%10+'0');
}
int vis[100010];
int main()
{
    int n=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();
        vis[x]++;
        vis[x-1]++;
        vis[x+1]++;
    }
    sort(vis,vis+100005);
    printf("%d\n",vis[100004]);
    return 0;
}


Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let n:usize = read();
    let k:usize = read();
    let a: Vec<usize> = (0..n).map(|_| read::<usize>()-1).collect();
    let mut reach: Vec<(bool,usize)> = vec![(false,0);n];
    let mut step = 0;
    let mut now:usize = 0;

    //println!("{:?}",a);
    for _ in 0..k{
        //println!("now{}, a[]{}, reach{:?}",now,a[now],reach[now]);
        if reach[now].0 {
            //println!("{:?}",reach);
            let m = (k-reach[now].1)%(step-reach[now].1);
            //m回テレポートする
            for _ in 0..m{
                now = a[now];
            }
            //println!("k:{} m:{} reach[now].1:{} step:{}",k,m,reach[now].1,step);
            println!("{}",now + 1 );
            return;
        }
        reach[now].0 = true;
        reach[now].1 = step;
        now = a[now];
        //println!("now:{}",now);
        step += 1;
    }

    println!("{}",now + 1);
}

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

using namespace std;

int n, a[1005], cnt;

int main(void)
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 2; i < n; ++i)
        if ((a[i] > a[i - 1] && a[i] < a[i + 1]) || (a[i] > a[i + 1] && a[i] < a[i - 1])) ++cnt;
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 256
N= input()
A = list([int(i) for i in N])

patterns = ['000', '001', '010', '011', '100', '101', '110', '111']

rem = ''

for pattern in patterns:
    S=A[0]
    for i, s in enumerate(pattern):
        if int(s):S+=A[i+1]
        else:S-=A[i+1]
    if S==7:
        rem = pattern
        break

pattern = pattern.replace('0','-').replace('1', '+')
lst = []
for i, j in zip(A, pattern):
    lst.append(i)
    lst.append(j)
lst.append(A[3])
lst.append('=7')
print(*lst,sep='')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define int long long
#define INF 1<<29
#define MAX 100000
using namespace std;

int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];

void solve(){
 cin>>n>>m;
 ZERO(sum);
 FOR(i,m) cin>>p[i];
 FOR(i,n-1) cin>>a[i]>>b[i]>>c[i];
 FOR(i,m) p[i]--;
 FOR(i,m-1){
  sum[max(p[i],p[i+1])]--;
  sum[min(p[i],p[i+1])]++;
 }
 int ans=0LL;
 FOR(i,n-1){
  sum[i+1]+=sum[i];
  ans+=min(sum[i]*a[i],sum[i]*b[i]+c[i]);
 }
 cout<<ans<<endl;
}

signed main(){
 solve();
 return 0;
}

Measured memory_bytes: 5072
#include <stdio.h>

void hantei(char c) {
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    printf("vowel\n");
  else
    printf("consonant\n");
}

int main(void) {
  char c;
  scanf("%c", &c);
  hantei(c);
  return 0;
}

Measured memory_bytes: 128
/**
 *    author:  tourist
 *    created: 30.09.2017 14:53:43       
**/
#include <bits/stdc++.h>

using namespace std;

const int N = 1234567;

int a[N], b[N];

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i], &b[i]);
  }
  k++;
  int cant = 0;
  long long ans = 0;
  for (int bit = 30; bit >= 0; bit--) {
    if (k & (1 << bit)) {
      cant ^= (1 << bit);
      long long cur = 0;
      for (int i = 0; i < n; i++) {
        if ((a[i] & cant) == 0) {
          cur += b[i];
        }
      }
      ans = max(ans, cur);
      cant ^= (1 << bit);
    } else {
      cant ^= (1 << bit);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3200
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>



/* エラトステネスのふるい

   O(n log log n) だいたい線形。 10万とかは余裕
*/
template<typename T>
std::vector<T> sieve(T n)
{
    std::vector<T> primes;
    std::vector<bool> is_prime(n, true);
    is_prime[0] = is_prime[1] = false;

    for (T i = 2; i <= n; ++i) {
        if (is_prime[i]) {
            primes.push_back(i);
            for (T j = 2 * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return primes;
}


/** 素因数分解
 */
template<typename T>
std::map<T, size_t>&
factor( T n, const std::vector<T>& primes, std::map<T, size_t>& ret) {
    auto f = primes.begin();
    while (n > 1) {
        while (n % *f == 0) {
            ret[*f] = ret[*f] + 1;
            n /= *f;
        }
        ++f;
    }

    return ret;
}


int main()
{
    int N;
    std::cin >> N;

    const int64_t DIV = 1000000007;

    auto primes = sieve(N);
    std::map<int, size_t> pf;
    int64_t ans = 1;
    for (int i = 1; i <= N; ++i) {
        factor(i, primes, pf);
    }

    for (auto p: pf) {
        ans *= p.second + 1;
        ans %= DIV;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n,k;
    cin >> n >> k;
    int ans = 0;
    int h;
    rep(i,n){
        cin >> h;
        if(k <= h) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3668
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define INF 1e9
using ll = int64_t;
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

void Main() {
  //自動整形防止用コメント
  int a, b, c, d;
  std::cin >> a >> b >> c >> d;
  std::cout << (min(b, d) - max(a, c) > 0 ? min(b, d) - max(a, c) : 0) << '\n';

  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n, q = map(int, input().split())

size = 2**((n-1).bit_length())
tree = [None]*(size*2)
INF = (-1, 2**31-1)

def _find(i):
    ind = size+i
    s = INF
    while ind:
        if tree[ind]:
            s = max(s, tree[ind])
        ind = ind//2
    return s
def find(i):
    return _find(i)[1]

def update(s, t, v):
    L = s+size;R = t+size
    while L<R:
        if L&1:
            tree[L]=v
            L+=1
        if R&1:
            R-=1
            tree[R]=v

        L>>=1;R>>=1

res = []
for i in range(q):
    a, *b = map(int, input().split())
    if a:res.append(find(b[0]))
    else:update(b[0],b[1]+1,(i,b[2]))
print('\n'.join(map(str,res)))


Measured memory_bytes: 16064
#include <iostream>
#include <cstring>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b) 

int g[12][12][12];
int h[12][12];
int n, m, p;

bool valid(int x, int y, int z){
    return 0 <= x && x < n && 0 <= y && y < n && 0 <= z && z < n;
}

bool check(int turn){
    int dx[] = { 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 };
    int dy[] = { 0, 1, 0, 1, -1, 0, 0, 1, 1, 1, 1, -1, -1 };
    int dz[] = { 0, 0, 1, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1 };
    rep(i, n)rep(j, n)rep(k, n){
        rep(l, 13){
            int ix = j, iy = i, iz = k, c = 0;
            while (valid(ix, iy, iz) && g[iy][ix][iz] == turn){
                ix += dx[l];
                iy += dy[l];
                iz += dz[l];
                c++;
            }
            if (m <= c) return true;
        }
    }
    return false;
}

int main(){
    while (cin >> n >> m >> p && n){
        memset(g, -1, sizeof(g));
        memset(h, 0, sizeof(h));
        int ans = -1;
        rep(i, p){
            int x, y;
            cin >> x >> y;
            x--; y--;
            g[y][x][h[y][x]] = i & 1;
            h[y][x]++;
            if (ans == -1 && check(i & 1)) {
                ans = i + 1;
            }
        }
        if (ans == -1) cout << "Draw";
        else if (ans & 1 == 1) cout << "Black" << " " << ans;
        else cout << "White" << " " << ans;
        cout << endl;
    }
}

Measured memory_bytes: 1176
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

int main () {
    
    int n; cin >> n;
    vector<int> h(n);
    REP(i,n) {
        cin >> h[i];
    }

    int res = 0;
    for (int i = n-1; i >= 0; i--) {
        int mx = -1;
        for (int j = 0; j < i; j++) {
            mx = max(mx, h[j]);
        }
        if(mx <= h[i]) {
            res += 1;
        } 
    }
    
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
// 2014/07/21 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int m, f, r;
		cin >> m >> f >> r;

		if(m==-1 && f==-1 && r==-1)
			break;

		if(m==-1 || f==-1){
			cout << 'F' << endl;
		}
		else if(m+f>=80){
			cout << 'A' << endl;
		}
		else if(m+f>=65){
			cout << 'B' << endl;
		}
		else if(m+f>=50){
			cout << 'C' << endl;
		}
		else if(m+f>=30){
			if(r>=50){
				cout << 'C' << endl;
			}
			else{
				cout << 'D' << endl;
			}
		}
		else{
			cout << 'F' << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main(){
	int a,x[9999],i;
	i=1;
	cin >> a;
	while(a!=0){
		x[i]=a;
		i++;
		cin >> a;
	}
	a=i;
	for(i=1;i<a;i++){
		cout <<"Case "<<i<<": "<< x[i] <<endl;
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

ll dp[100005][2];

void Main() {
    string L;
    cin >> L;
    dp[0][0] = 1;
    int n = L.size();
    rep(i, n) {
        if(L[i] == '1'){
            dp[i+1][0] += dp[i][0] * 2;
            dp[i+1][0] %= MOD;
            dp[i+1][1] += dp[i][0];
            dp[i+1][1] %= MOD;
        }else{
            dp[i+1][0] += dp[i][0];
            dp[i+1][0] %= MOD;
        }
        dp[i+1][1] += dp[i][1] * 3;
        dp[i+1][1] %= MOD;
    }
    cout << (dp[n][0] + dp[n][1]) % MOD << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


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

int f(int x){
  if(x % 2 == 0){
    return x / 2;
  }else{
    return 3 * x + 1;
  }
}

int main(){
  int s;
  cin >> s;
  int i = 1;
  while(s != 4 && s != 2 && s != 1){
    s = f(s);
    i++;
  }
  cout << i + 3 << endl;
}


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

class Disjoint{
private:
    vector<int> S;
    vector<int> rank;
    int find(int x){
        if (x == S[x]) {
            return x;
        }
        return x = find(S[x]);
    }
public:
    Disjoint(int n) {
        for (int i = 0; i < n; i++) {
            S.push_back(i);
            rank.push_back(0);
        }
    }
    void unite(int x, int y){
        int x_p = find(x);
        int y_p = find(y);
        if (rank[x_p] == rank[y_p]) {
            S[x_p] = y_p;
            rank[y_p]++;
            return;
        }
        if (rank[x_p] < rank[y_p]) {
            S[x_p] = y_p;
        } else {
            S[y_p] = x_p;
        }
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    Disjoint D(n);

    for (int i = 0; i < q; i++) {
        int command, x, y;
        cin >> command >> x >> y;
        if (command == 0) {
            D.unite(x, y);
        } else {
            cout << D.same(x, y) << endl;
        }
    }

    return 0;
}



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

a.sort()
a.reverse()

cnt = a[0]
for i in range(1, (n-2)//2 +1):
    cnt += a[i]*2

if n % 2 ==1:
    cnt += a[(n-2)//2 +1]
print(cnt)

Measured memory_bytes: 31612
#include<bits/stdc++.h>
using namespace std;
 
# define INF 0x3f3f3f3f
#define MOD 1000000007
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d%d",&x,&y)
#define siii(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d%d",x,y)
#define piii(x,y,z) printf("%d%d%d",x,y,z) 
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld%lld",&x,&y)
#define slll(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld%lld",x,y)
#define plll(x,y,z) printf("%lld%lld%lld",x,y,z) 
 
#define ll long long
#define mp make_pair
#define pb push_back
#define pp pop_back
#define nl printf("\n");
#define sf scanf
#define pf printf
#define rep(i,n) for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int> 
#define tci int t;scanf("%d",&t);while(t--)
#define tcl ll t;sl(t);while(t--) 
int main() 
{
    int n,m;
    sii(n,m);
    cout<<(n-1)*(m-1);nl;
    return 0;
}   

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
S = LIST()


if S[0][-1] == S[1][0] and S[1][-1] == S[2][0]:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 13804
<?php
$n=trim(fgets(STDIN));
$nums_array=explode(" ", trim(fgets(STDIN)));
$ans = 0;
for($i=0; $i-1<$n; $i++){
	 for($j=$i+1; $j<$n; $j++){
	 	$ans += $nums_array[$i] * $nums_array[$j];
	 }
}

echo $ans . "\n";

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    string ans = a * b % 2 == 0 ? "Even" : "Odd";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
f=0
while 1:
    n=int(input())
    if f and n!=0:
        print()
    f+=1
    if n==0:
        break
    a,b,c,d=map(int,input().split())
    mny=a*10+b*50+c*100+d*500
    mny=mny-n
    m500=mny//500
    mny-=500*(mny//500)
    m100=mny//100
    mny-=100*(mny//100)
    m50=mny//50
    mny-=50*(mny//50)
    m10=mny//10
    mny-=10*(mny//10)
    print('10 %d\n'%(max(a-m10,0)) if max(a-m10,0)!=0 else '', end='')
    print('50 %d\n'%(max(b-m50,0)) if max(b-m50,0)!=0 else '', end='')
    print('100 %d\n'%(max(c-m100,0)) if max(c-m100,0)!=0 else '', end='')
    print('500 %d\n'%(max(d-m500,0)) if max(d-m500,0)!=0 else '', end='')



Measured memory_bytes: 5628
#include <iostream>
#include <cstring>
#include <cstdio>
#include<algorithm>
#include <queue>
#include <cmath>
#include <limits>
#include <map>
#include <iomanip>
using namespace std;
#define ll long long int


int main () {
  int s, w;
  cin >> s >> w;
  if (w >= s)
    cout << "unsafe" << endl;
    else cout << "safe" << endl;
  return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
ll n, k, ans = 1e18;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    ll arr[n];
    --k;
    for(int i = 0;i < n;++i)
        cin >> arr[i];
    for(int i = 0;i < n;++i)
    {
        ll dis = abs(arr[i]);
        ll mn = 1e18;
        if(i + k < n)   mn = min(mn, abs(arr[i + k] - arr[i]));
        if(i - k >= 0)  mn = min(mn, abs(arr[i - k] - arr[i]));
        dis += mn;
        ans = min(ans, dis);
    }
    cout << ans;
    return 0;
}


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

typedef long long LL;
typedef unsigned long long LONG;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
using namespace std;
typedef pair<int, int> PII;
#define ft fisrt
#define sd second
#define eb emplace_back
#define END '\n'

template <class T>
inline bool Read(T &ret)
{
	char c;
	int sgn;
	if (static_cast<void>(c = getchar()), c == EOF)
		return 0;
	while (c != '-' && (c < '0' || c > '9'))
		c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
		ret = ret * 10 + (c - '0');
	ret *= sgn;
	return 1;
}

template <class T>
inline void Write(T x)
{
	if (x < 0)
		putchar('-'), Write(x);
	if (x > 9)
		Write(x / 10);
	putchar(x % 10 + '0');
}



void solve(int question_num)
{
	while (question_num--)
	{
		LL n,m;cin>>n;
		LL ans=0;
		m=n-1;
		for(LL i=1;i*i<=m;++i){
			if(m%i==0){
				ans++;
				if(m/i!=i) ans++;
			}
		}
		ans--;
		for(LL i=2;i*i<=n;++i){
			if(n%i==0){
				LL k=n;
				while(k%i==0){
					k/=i;
				}
				if(k%i==1) ans++;
			}
		}
		cout<<ans+1;
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t = 1;
	// cin >> t;
	solve(t);
	return 0;
}


Measured memory_bytes: 256
# D
#入力
n,a,b=map(int,input().split())

#諸関数
def pront(X):
    #デバッグ用プリント
    #環境変数としてdebugを確保して、それが1なら内容を出力
    if debug==0:
        print(X)

#デバッグ用
debug=1#0:本番,1:デバッグ中

#処理
#定数
base=(10**9)+7

#関数
    #10*9+7で割ったあまりを返し続ける
def add(a,b):#a+b
    return(((a%base)+(b%base))%base)
def sub(a,b):#a-b
    return (((a%base)-(b%base))%base)
def multi(a,b):#a*b
    return(((a%base)*(b%base))%base)
def exp(a,b):#a**b
    x=1
    c=a
    d=b
    while d!=0:
        if d%2==1:
            x=multi(x,c)
        c=(c**2)%base
        d=d//2
    return x

#割り算はフェルマーの小定理に基づいて考える
def div(a,b):#a/b
    return(multi(a,exp(b,base-2)))

    #その他演算
def fact(m,n):#m~nの積(m<n)
    x=1
    for i in range(m,n+1):
        x=multi(x,i)
    return x
def comb(n,r):
    return div(fact(n-r+1,n),fact(1,r))
#処理
Z=sub(sub(sub(exp(2,n),comb(n,a)),comb(n,b)),1)
print(Z)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
int i,x,y;
for(i >= 0; i <= 3000; i++){
        scanf("%d %d",&x,&y);
        if ( x == 0&&y == 0)break;
        if (x > y){
        printf("%d %d\n",y ,x);
    }else{
        printf("%d %d\n",x ,y);
    }

}
return 0;
}



Measured memory_bytes: 2040
# AOJ 0259 All Numbers Lead to 6174

while line = gets
  line.chomp!
  break if line == "0000"

  if line == "6174"
    puts 0
    next
  elsif line.to_i % 1111 == 0
    puts "NA"
    next
  end

  n = line
  n_op = 0
  loop do
    n_op += 1

    digits = n.each_char.map {|c| c.to_i}.sort
    l = digits.reverse.join("").to_i
    s = digits.join("").to_i

    break if l - s == 6174

    n = "%04d".%(l - s)
  end

  puts n_op
end

Measured memory_bytes: 6124
#include<stdio.h>

int main(){
  	int N,K;
  	scanf("%d",&N);
  	char mozi[N],m[1];
  	scanf("%s",mozi);
  	scanf("%d",&K);
  	m[0] = mozi[K - 1];
  	for(int i = 0 ; i < N ; i ++){
    	if(mozi[i] != m[0]) mozi[i] = '*';
    }
  	printf("%s\n",mozi);
	return 0;
}

Measured memory_bytes: 128
n,m = map(int,raw_input().split())

def f(n,m):
	if n == 1:
		return m
	divisors = []
	for d in range(2, int(m ** 0.5)+1)[::-1]:
		if m % d == 0:
			divisors.append(d)
			if d != m/d: divisors.append(m/d)
	divisors.sort(key = lambda x:-x)
	for d in divisors:
		if m/d >= n:
			return d

	return 1

print f(n,m)

Measured memory_bytes: 67096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		boolean win = true;
		while (true) {
			C -= B;
			if (C <= 0) {
				break;
			}
			A -= D;
			if (A <= 0) {
				win = false;
				break;
			}
		}
		if (win) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 35752
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
if n<1000:
    print("ABC")
else:
    print("ABD")

Measured memory_bytes: 77420
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
using namespace std;
typedef long long ll;

int n;
ll x[100005];

bool can(int k){
	ll s=x[k];
	fore(i,0,n){
		if(i==k)continue;
		if(2*s<x[i])return false;
		s+=x[i];
	}
	return true;
}

int main(){
	scanf("%d",&n);
	fore(i,0,n)scanf("%lld",x+i);
	sort(x,x+n);
	int s=0,e=n+1;
	while(e-s>1){
		int m=(s+e)/2;
		if(can(n-m))s=m;
		else e=m;
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using ll = long long;
using namespace std;

ll maxPow5(ll n) {
   ll ans = 0;
   ll cur = 1;
   while(cur * 5 <= n) {
      cur *= 5;
      ans += n / cur;
   }
   return ans;
}

void solve() {
   ll n;
   cin >> n;
   if(n % 2) {
      //7.5.3.1
      cout << 0 << endl;
   } else {
      //12.10.8
      cout << maxPow5(n / 2) << endl;
   }
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<cmath>
using namespace std;

int main(void)
{
	int X;
	cin >> X;

	int ret = 1;
	for(int i=1; i<X; i++){
		for(int j=2; j<X; j++){
			int n = pow(i, j);
			if(n<=X)
				ret = max(ret, n);
		}
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include<string.h>
int main(void){
    // Your code here!
    char s[200010];
    scanf("%s",s);
    int len = strlen(s);
    int sum=0;
    
    for(int i=0;i<len;i++){
        sum += s[i] - '0';
    }
    if(sum%9==0) printf("Yes\n");
    else printf("No\n");
    
    return 0;
}


Measured memory_bytes: 1848
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <queue>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

template <typename T>
class Wgraph{
public:
    Wgraph(int _n){
        n = _n;
        node.resize(n);
        adj.resize(n);
        REP(i, n) { node[i] = i; }
    }
    ~Wgraph(){

    }

    //a → b
    void connect(T from,T to,int cost){
        adj[from].push_back(make_pair(to,cost));
        //cout << from<<" " << to<<" "<<cost<<endl;
    }

    void dij(int start){
        
        priority_queue<pair<T,T>,vector<pair<T,T>>,greater<pair<T,T>>> pq;
        vector<T> dist(n,numeric_limits<T>::max());
        vector<bool> is_used(n,false);

        pq.push(make_pair(0,start));
        T to,d;

        while(!pq.empty()){
            tie(d,to) = pq.top();
            pq.pop();
            if(is_used[to]){
                continue;
            }else{
                is_used[to] = true;
                dist[to] = d;
                for(auto x:adj[to]){
                    if(dist[x.first]>d+x.second){
                        pq.push(make_pair(d+x.second,x.first));
                    }
                }
            }

        }
        REP(i,n){
            printf("%d %d\n", i, dist[i]);
        }
    }

  private:
    int n;
    vector<T> node;
    vector<vector<pair<T, T>>> adj;
    
};

int main(){
    int n;
    cin >> n;
    unique_ptr<Wgraph<int>> wg(new Wgraph<int>(n));

    
    {
        int tmp_from,tmp_edgenum, tmp_to,tmp_cost;

        REP(i,n){
            
            scanf("%d %d,", &tmp_from,&tmp_edgenum);

            REP(j,tmp_edgenum){
                scanf("%d %d", &tmp_to, &tmp_cost);
                wg->connect(tmp_from, tmp_to, tmp_cost);
            }


        }
    }
    wg->dij(0);

    return 0;
}



Measured memory_bytes: 3284
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    string s;
    cin>>s;
    ll ans=0;
    vector<int> bw;
    int size=0;
    bool b=(s[0]=='B');
    int ssize=s.size();
    int i=0;
    while(i<ssize){
        int cnt=0;
        int j=i;
        for(j; j<ssize; j++){
            if(s[j]=='B' && b) cnt++;
            else if(s[j]=='W' && !b) cnt++;
            else{
                break;
            }
        }
        bw.push_back(cnt);
        size++;
        b=!b;
        i=j;
    }
    i=0;
    ll bcnt=0;
    if(s[0]=='W') i++;
    for(i; i+1<size; i+=2){
        bcnt+=bw[i];
        ans+=bcnt*bw[i+1];
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

typedef long long ll;

const int N = 1e7 + 10;

int f[N];

void init() {
	for (int i = 1; i < N; i++) {
		for (int j = i; j < N; j += i) {
			f[j]++;
		}
	}
}

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

	init();

	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += (ll)i * f[i];
	}
	cout << ans << '\n';
}


Measured memory_bytes: 42260
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String result = "Good";
		for(int i = 0; i < s.length() - 1; i++) {
			if(s.substring(i, i + 1).equals(s.substring(i + 1, i + 2))) result = "Bad";
		}
      System.out.println(result);
	}

}


Measured memory_bytes: 35540
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    string ans = "";
    repd(i, sx, tx) ans += "R";
    repd(i, sy, ty) ans += "U";
    for (int i = tx; i > sx; i--) ans += "L";
    for (int i = ty; i > sy; i--) ans += "D";

    ans += "L";
    repd(i, sy, ty + 1) ans += "U";
    repd(i, sx, tx + 1) ans += "R";
    ans += "D";

    ans += "R";
    repd(i, sy, ty + 1) ans += "D";
    repd(i, sx, tx + 1) ans += "L";
    ans += "U";
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }




int main() {
	int NUM = 1, N, K;
	int tmp = 1, cnt = 0, ans = 0;
	scanf("%d%d", &N, &K);

	while (cnt < N) {
		if (tmp <= K) {
			tmp = tmp * 2;
			cnt++;
		}
		else {
			tmp += K;
			cnt++;
		}
	}

	ans = tmp;
	printf("%d\n", ans);



#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val c = sc.nextInt()

    val coefficients = parseList(sc, m)
    val result = calc(sc, n, coefficients, c)
    println(result.size)
}

private fun parseList(scanner: Scanner, length: Int): List<Int> {
    return (0 until length).map {
        scanner.nextInt()
    }
}

private fun calc(scanner: Scanner, length: Int, coefficients: List<Int>, c: Int): List<Int> {
    return (0 until length).map {
        coefficients.map { co ->
            val num = scanner.nextInt()
            num * co
        }.sum() + c
    }.filter { it > 0 }
}


Measured memory_bytes: 31516
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 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;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            int min = m;
            for (int i = 1; i <= (int) Math.sqrt(m); i++) {
                if (m % i == 0) {
                    if (i >= n)
                        min = i < min ? i : min;
                    int ni = m / i;
                    if (ni >= n)
                        min = ni < min ? ni : min;
                }
            }

            out.println(m / min);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,a,b) for(int i= (int)(a); i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
const int N = 1e6+7 ;
string s ;

int main(){fast ;
	ld n,k ;
	cin >> n >> k ;
	ld p = 1 / n ;
	ld sm = 0.0 ;
	for(int i = 1 ; i <= n ; i++){
		int cnt = 0 ;
		while((i << cnt) < k){
			cnt++ ;
		}
		sm += pow(0.5 , cnt) ;	
	}
	 ld ans = p * sm ;
	 
	 cout << fixed << setprecision(20) << ans << endl ;
}



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

int main(){
	string str;
	int q, l;
	deque<char> de;
	deque<char> :: iterator it;
	cin >> str >> q;
	l = str.size();
	for(int i = 0; i < l; i++)
		de.push_back(str[i]);

	bool f = false;
	int t, c;
	char s;
	for(int i = 0; i < q; i++){
		scanf("%d",&t);
		if(t == 1) f = !f;
		else if(t == 2){
			scanf("%d %c", &c, &s);
			if(!f){
				if(c == 1) de.push_front(s);
				else if(c == 2) de.push_back(s);
			}
			else {
				if(c == 2) de.push_front(s);
				else if(c == 1) de.push_back(s);				
			}
		}
	}
	if(!f){
		for(it = de.begin(); it != de.end(); it++)
			printf("%c", *it);		
	}
	else{
		for(it = de.end() - 1; it != de.begin() - 1; it--)
			printf("%c", *it);			
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
const int N=305;
int n,K,mod;
inline void add(int &x,ri y){
	x=(x+=y)>=mod?x-mod:x;
}
namespace sub1{
	int f[N][N][N];
	inline void solve(){
		ri i,j,k,x,y,v,c,ans;
		f[0][0][0]=1;
		for(i=1;;++i){
			y=2*i;
			x=y-K;
			if((x<1||x>n)&&(y<1||y>n)) break;
			for(j=0;j<=i&&j<=K+1;++j)
				for(k=0;k<i&&k<=n/2;++k)
					if(v=f[i-1][j][k]){
						add(f[i][0][0],v); // 00
						if(x>=1&&j+(j>0)<=K+1)
							add(f[i][j+(j>0)][0],v); // 10
						if(y<=n){
							add(f[i][0][k+1],v); // 01
							if(x>=1&&(c=max(j+1,k+2))<=K+1)
								add(f[i][c][k+1],v); // 11
						}
					}
		}
		--i;ans=0;
		for(j=0;j<=i+1&&j<=K+1;++j)
			for(k=0;k<=i&&k<=n/2;++k)
				add(ans,f[i][j][k]);
		printf("%d\n",ans);
	}
}
namespace sub0{
	int f[N]; // dp的是不在环上的人 
	inline void solve(){
		ri i,j,res0,res1,ans;
		f[0]=1;
		for(i=1;i<=(n+1)/2;++i)
			for(j=max(i-K/2-1,0);j<i;++j)
				add(f[i],f[j]);
		res0=res1=0;
		for(i=max(0,n/2-K/2);i<=n/2;++i)
			add(res0,f[i]);
		for(i=max(0,(n+1)/2-K/2);i<=(n+1)/2;++i)
			add(res1,f[i]);
		ans=(ll)res0*res1%mod;
		printf("%d\n",ans); 
	}
}
int main(){
	scanf("%d%d%d",&n,&K,&mod);
	if(K&1)
		sub1::solve();
	else
		sub0::solve();
    return 0;
}

Measured memory_bytes: 53504
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

mini = (-1, pow(10, 15) + 5)
for i, x in enumerate([a, b, c, d, e]):
  if mini[1] >= x:
    mini = (i, x)

if mini[1] >= n:
  print(5)
else:
  print(n // mini[1] + (1 if n % mini[1] != 0 else 0) + 4)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
 
typedef tree<pair<long long,int>, null_type, less<pair<long long,int>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
 
#define f first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pi pair<int, int>
#define all(num) num.begin(), num.end()
#define lp(i, nodess) for (int i = 0; i < nodess; i++)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define X real()
#define Y imag()
#define angle(u) (atan2(u.Y, u.X))
#define vec(u, v) ((v) - (u))
//#define length(u) (hypot(u.Y , u.X))
#define normalize(u) (u) / length(u)
#define dotP(u, v) ((conj(u) * v).X)
#define crossP(u, v) ((conj(u) * v).Y)
#define same(p1, p2) (dotP(vec(p1, p2), vec(p1, p2)) < EPS)
#define lengthSqr(u) dotP(u, u)
#define rotate0(p, ang) ((p)*exp(point(0, ang)))
#define rotateA(p, ang, about) (rotate0(vec(about, p), ang) + about)
#define reflect0(vis, m) conj(vis / m) * m
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const double PI = acos(-1.0);
const double EPS = (1e-10);
const long long int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
typedef long long int ll;
typedef unsigned long long ull;
typedef complex<double> point;
long long fastpow(ll nodess, ll num, ll m) {
  if (!num)
    return 1;
  if (num % 2)
    return nodess * fastpow(nodess, num - 1, m)%m;
  ll p = fastpow(nodess, num / 2, m);
  p %= m;
  p *= p;
  p %= m;
  return p;
}
 
ll my_mod(ll num, ll mod) {
  ll reto = num % mod;
  while (reto < 0)
    reto += mod;
  return reto;
}
 
ll gcd(ll u, ll v) { return !u ? v : gcd(v % u, u); }
long long dist(pair<ll, ll> u, pair<ll, ll> v) {
  return 
      abs(u.f - v.f)  + abs(u.se - v.se);
}
long long getDist(pair<ll, ll> &u, pair<ll, ll> &v) {
  return 
     (u.f - v.f)*(u.f - v.f)  + (u.se - v.se)*(u.se-v.se);
}
 
 
 
/*vector<int> ap;
int np[MX+5];
void s(){
    mem(np , 1);
    np[1] = np[0] = 0;
    for(ll i = 2 ; i*i<= MX ;i++){
        if(np[i]){
            for(ll j= i*i ; j <=MX; j+=i) np[j] = 0;
        }
    }
    int idx = 1;
    for(ll i = 2 ; i<= MX ; i++){
		if(np[i]){
			np[i] = idx;
			idx++; 
			ap.pb(i);
		}
	}
	//cout<<idx;
}*/
const int MX = 10009;

int main()
{
    IO;
	int n;
	cin>>n;
	vector<int> a(n), b(n);
	for(int &i : a) cin>>i;
	for(int &i : b) cin>>i;
	vector<int> c(n);
	for(int i = 0 ;i < n; i++) c[i] = i+1;
	int id = 1;
	vector<int> arr;
	do{
		bool f1 = 1, f2 = 1;
		for(int j = 0 ;j < n; j++){
			f1 &= a[j] == c[j];
			f2 &= b[j] == c[j];
		}
		if(f1||f2)arr.pb(id);
		id++;
		
	}while(next_permutation(all(c)));
	if(arr.size() == 1) cout<<0<<"\n";
	else cout<<abs(arr[0] - arr[1]);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

  public void solve() {

    Scanner input = new Scanner(System.in);
    int n = input.nextInt();

    int[] P = new int[n];
    for (int i = 0; i < n; i++) {
      P[i] = input.nextInt();
    }

    int[] Q = new int[n];
    for (int i = 0; i < n; i++) {
      Q[P[i] - 1] = i;
    }

    int cnt = 0;
    int maxLen = 0;
    for (int i = 0; i < n - 1; i++) {
      if (Q[i] < Q[i + 1]) {
        cnt++;
      } else {
        maxLen = Math.max(maxLen, cnt);
        cnt = 0;
      }
    }
    maxLen = Math.max(maxLen, cnt);
    System.out.println(n - maxLen - 1);
  }
}


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

const ll INF = (ll)(1e18)+1;

int main () {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  reverse(all(s));
  int p = 0, ans = 0;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    int d = s[i] - '0' + p;
    if (d > 5) {
      ans += (10 - d);
      p = 1;
    } else if (d < 5) {
      ans += d;
      p = 0;
    } else {
      ans += 5;
      p = 0;
      if (i != n-1 && s[i+1]-'0' >= 5) p = 1;
    }
  }
  ans += p;
  cout << ans << endl;
}

Measured memory_bytes: 1948
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <utility>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5+5;

long long N, A, B;

int main() {
//#define LOCAL
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif 
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> A >> B;
	if(A + B >= N) {
		if(A >= N) cout << N << endl;
		else cout << A << endl;
	} else {
		long long ans = N / (A + B) * A;
		long long mod = N % (A + B);
		if(mod <= A) ans += mod;
		else ans += A;
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
   
        signed main() {
           int n;
           cin>>n;
           if(n%2)cout<<2*n;
           else cout<<n;

           return 0;

        }


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(std::vector<long long> x){

    REP(i,0,5){
        if(x[i]==0){
            cout<<i+1<<endl;
            return;
        }
    }

}

int main(){
    // cout << fixed << setprecision(5);

    std::vector<long long> x(5);
    for(int i = 0 ; i < 5 ; i++){
        scanf("%lld",&x[i]);
    }
    func(std::move(x));
    return 0;
}


Measured memory_bytes: 3676
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    n, = read_h()
    arr = read_v(n)

    max_asc = [0]
    for a in arr[:n - 1]:
        max_asc.append(max(max_asc[-1], a))
    #  print(max_asc)

    max_desc = [0]
    for a in arr[::-1][:n - 1]:
        max_desc.append(max(max_desc[-1], a))
    max_desc = max_desc[::-1]
    #  print(max_desc)

    #  assert len(max_asc) == len(max_desc)
    #  print(len(max_asc))

    for a, d in zip(max_asc, max_desc):
        print(max(a, d))


if __name__ == '__main__':
    main()


Measured memory_bytes: 17280