akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 200100;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int N;
int arr[MAXN];
int oloc[MAXN];

template<class T>
struct RMQ {
    vector<vector<T>> jmp;

    RMQ(const vector<T>& V = {}) {
        int N = sz(V), on = 1, depth = 1;
        while (on < sz(V)) on *= 2, depth++;
        jmp.assign(depth, V);
        rep(i,0,depth-1) rep(j,0,N)
            jmp[i+1][j] = min(jmp[i][j],
            jmp[i][min(N - 1, j + (1 << i))]);
    }

    T query(int a, int b) {
        assert(a < b); // or return inf if a == b
        int dep = 31 - __builtin_clz(b - a);
        return min(jmp[dep][a], jmp[dep][b - (1 << dep)]);
    }
};

RMQ<int> rmq[2];

int rmq_loc (int x, int y)
{
    return oloc[rmq[x%2].query(x/2, y/2)];
}

priority_queue <pair <int, pair <int, int> > > pq;
vector <int> ans;

void add_range (int lo, int hi)
{
    int clo = rmq_loc (lo, hi);
    pq.push(make_pair (-arr[clo], make_pair (lo, hi)));
}

int main()
{
    ios_base::sync_with_stdio(0);

    vector <int> v[2];
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> arr[i];
        oloc[arr[i]] = i;
        v[i%2].push_back(arr[i]);
    }
    rmq[0] = RMQ<int>(v[0]);
    rmq[1] = RMQ<int>(v[1]);

    add_range (0, N);
    while (!pq.empty())
    {
        int lo = pq.top().second.first;
        int hi = pq.top().second.second;
        pq.pop();

        int clo = rmq_loc (lo, hi);
        int clo2 = rmq_loc (clo + 1, hi + 1);
        ans.push_back(arr[clo]);
        ans.push_back(arr[clo2]);

        if (clo > lo)
            add_range (lo, clo);
        if (clo2 > clo + 1)
            add_range (clo + 1, clo2);
        if (hi > clo2 + 1)
            add_range (clo2 + 1, hi);
    }

    for (int i = 0; i < ans.size(); i++)
    {
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << "\n";
}

Measured memory_bytes: 19692
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main()
{
    string str;
    cin >> str;
    char c1 = ' ';
    char c2 = ' ';
    string ans = "Yes";
    int n1 = 0, n2 = 0;
    
    for(int i = 0; i < 4; i++){
        if(str[i] == c1){
            n1++;
        }else if(str[i] == c2){
            n2++;
        }else if(c1 == ' '){
            c1 = str[i];
            n1++;
        }else if(c2 == ' '){
            c2 = str[i];
            n2++;
        }
    }
        if(n1 != 2 || n2 != 2){
            ans = "No";
        }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#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 al(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
  int k,n,ans=0; cin>>k>>n;
  vector<int> a(n+1,0);
  rep(i,n) cin>>a[i]; a[n]=a[0]+k;
  rep(i,n) ans=max(ans,a[i+1]-a[i]);
  cout<<k-ans<<endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define ll long long
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll n; cin >> n;
	vector<ll> a(n);
	deque<ll> deq;
	for (int i = 0; i < n;i++) {
		cin >> a[i];
		if(i %2 == 0)deq.push_back(a[i]);
		else deq.push_front(a[i]);
	}
	if (n % 2 != 0) {
		for (auto it = deq.rbegin(); it != deq.rend();it++) {
			cout << *it << " ";
		}
		cout << endl;
	}
	else {
		for (auto it = deq.begin();it != deq.end();it++) {
			cout << *it << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 5376
//
// Created on 2020/04/17.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int ans;
    int r;
    cin>>r;
    ans = 3 * r * r;

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(int argc, char** argv)
{
	int n, i;
	double x[100], y[100], max = 0, result_p1 = 0, result_p2 = 0, result_p3 = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%lf", &x[i]);
	}

	for (i = 0; i < n; i++) {
		scanf("%lf", &y[i]);
	}

	for (i = 0; i < n; i++) {
		double dis = fabs(x[i] - y[i]);

		result_p1 += dis;
		result_p2 += (dis * dis);
		result_p3 += (dis * dis * dis);

		if ((max * 100000) < (dis * 100000)) {
			max = dis;
		}
	}

	result_p2 = sqrt(result_p2);
	result_p3 = pow(result_p3, 1.0 / 3.0);

	printf("%.8lf\n%.8lf\n%.8lf\n%.8lf\n", result_p1, result_p2, result_p3, max);

	return 0;
}

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

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(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

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

    //0->A,1->B,2->C
    int dp[n+1][3];

    //最大化問題なのですべて0に
    rep(i,n+1){
        rep(j,3){
            dp[i][j]=0;
        }
    }

    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(j==k) continue;
                chmax(dp[i+1][j],(dp[i][k])+a[i][k]);
            }
        }
    }
    int res=0;
    rep(i,3) chmax(res,dp[n][i]);
    COUT(res);
}

Measured memory_bytes: 2560
def resolve():
    n, k = map(int, input().split())
    h = []
    for i in range(n):
        h.append(int(input()))
    h = sorted(h)
    ans = 10**9+2
    for i in range(n-k+1):
        test = h[i+k-1]-h[i]
        ans = min(test, ans)
    print(ans)
resolve()

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

int main(int argc, char **argv)
{
	string S; cin >> S;
	ll k; cin >> k;

	ll N = (ll)S.size();
	set<string> s;
	for (ll size = k; size > 0; --size)
	{
		for (ll i = 0; i < N - size + 1; ++i)
		{
			s.insert(S.substr(i, size));
		}
	}

	auto i = s.begin();
	advance(i, k-1);
	std::cout << *i << std::endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int x1,x2,x3,x4,y1,y2,y3,y4;
    cin >> x1 >> y1 >> x2 >> y2 ;
    int a = x2-x1;
    int b = y2-y1;
    x3 = x2-b;
    x4=x3-a;
    y3 = y2+a;
    y4 = y3-b;
    cout << x3 <<" " << y3 <<" "<< x4 << " "<< y4;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;


int main()
{
    string S;
    cin >> S;

    rep(i, S.size()) {
        if ((i + 1) % 2 == 1) { //奇数の時
            if (S.at(i) == 'L') {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            if (S.at(i) == 'R') {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int N=100005;
int dis[N],de[N+1];
vector<int> g[N];
int main(){
	int n,m;cin>>n>>m;
	memset(de,0,sizeof(de));
	memset(dis,0,sizeof(dis));	
	for(int i=0;i<m;i++){
		int x,y;cin>>x>>y;
		g[x].push_back(y);
		de[y]++;
	}
	queue<int> q;
	for(int i=1;i<=n;i++){
		if(de[i]==0){
			q.push(i);
		}
	}
	while(q.size()>0){
		int cu=q.front();
		q.pop();
		for(auto u:g[cu]){
			de[u]--;
			if(de[u]==0){
				q.push(u);
			}
			dis[u]=max(dis[u],dis[cu]+1);
		}
	}
	int mx=0;
	for(int i=1;i<=n;i++)mx=max(dis[i],mx);
	cout<<mx<<endl;
}

Measured memory_bytes: 6528
package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner.Split(bufio.ScanWords)
	dict := make(map[string]int)
	q := nextInt()
	for i := 0; i < q; i++ {
		switch nextInt() {
		case 0:
			key := nextString()
			x := nextInt()
			if _, ok := dict[key]; ok {
				dict[key] = x
			} else {
				dict[key] = x
			}
		case 1:
			key := nextString()
			fmt.Println(dict[key])
		default:
			panic("no such operation!")
		}
	}
}


Measured memory_bytes: 18928
#include<bits/stdc++.h>
using namespace std;
int main(void){
    char c[1010];
    scanf("%s",c);
    int l=strlen(c);
    for(int i=0;i<l;i++)if(c[i]==67){
        for(int j=i+1;j<l;j++)if(c[j]==70){
            printf("Yes");return 0;
        }
    }printf("No");return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

long long n, a, b, ans = 0;

bool solve( long long m )
{
	return ( m >= 1 && ( n / m == n % m ) );
}

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> n;
	for( long long i = 1; i * i <= n; ++i )
	{
		if( n % i == 0 )
		{
			a = i; b = n / i;
			if( solve( a - 1 ) )
			{
				ans += a - 1;
			}
			if( a != b && solve( b - 1 ) )
			{
				ans += b - 1;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

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

int main(){
  stack<int> S1;
  stack<pair<int, int> > S2;
  char ch;
  int sum = 0;
  for(int i = 0 ; cin >> ch ; i++){
    if(ch == '\\') S1.push(i);
    else if(ch == '/' && S1.size() > 0){
      int j = S1.top(); S1.pop();
      sum += i - j;
      int a = i - j;
      while(S2.size() > 0 && S2.top().first > j){
	a += S2.top().second; S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }

  vector<int> ans;
  int t = 0;
  while(S2.size() > 0){ans.push_back(S2.top().second); S2.pop();}
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for(int i = 0 ; i < ans.size(); i++){
    cout << " ";
    t += ans[i];
    cout << ans[i];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3256
#include<cstdio>
 
int n,m,q_n;
int a[200001],q;
 
int main(void){
    scanf("%d%d%d",&n,&m,&q_n);
    for(int i=0;i<m;i++)scanf("%d",&a[i]);
    for(int i=0;i<q_n;i++){
    	scanf("%d",&q);
       	int flag=1,p=q,b=0;
       	for(int j=0;j<m;j++){
       		if(flag==0)continue;
       		if(a[j]%2==0)b=(b+a[j])%(n-j);
       		else b=(b-a[j]+(n-j)*100)%(n-j);
       		if(p==b)flag=0;
       		else if(p>b)p--;
       		if(b==n-j-1)b=0;
       	}
        printf("%d\n",flag);
    }
    return 0;
}

Measured memory_bytes: 1808
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, 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")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        mut m:usize,
        mut an:[(usize,usize);n],
    }
    an.sort();
    let mut ans = 0;
    // an.sort_by_key(|k|k.0);
    for &(price,quantity) in &an {
        if m == 0 {break};
        if m >= quantity {
            ans += price * quantity;
            m -= quantity;
        } else {
            ans += m * price;
            m = 0;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
const int inf=0x3f3f3f3f;
const int N=1e6;
int n,m,v,p,a[N],l[N];
bool cmp(int x,int y)
{
	return a[x]<a[y];
}
ll c[N];
void add(int x,int y)
{
	for(int i=x;i<=n;i+=i&-i)c[i]+=y;
}
ll ask(int x)
{ll ret=0;
	for(int i=x;i;i-=i&-i)ret+=c[i];return ret;
}
map<int,int>mp;
main()
{
	cin>>n>>m>>v>>p;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),mp[a[i]]++,l[i]=i;sort(l+1,l+n+1,cmp);int ans=0;
	for(int i=1;i<=n;i++)add(i,a[l[i]]);int j=0;a[0]=-1;a[n+1]=-1;
	for(int i=1;i<=n;i++)
	{int x=l[i];if(a[x]==a[l[i+1]])continue;
		if(i>n-p){ans+=mp[a[x]];continue;}
		int k=a[x]+m;ll wl=1ll*(v-1)*m-1ll*(i-2+p)*m;
		if(a[l[n-p+1]]>k)continue;
		wl-=1ll*(n-p-i+1)*k-ask(n-p+1)+ask(i);
		if(wl<=0)
		{
			ans+=mp[a[x]];//cout<<i<<endl;
			continue;
		}
		
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 15488
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll A[57][57];

int main() {
    ll N,K,x[107],L;cin>>N>>K;
    rep(i,N){
        cin>>x[i];
        L+=2*min(abs(K-x[i]),x[i]);
    }
    cout << L << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
typedef std::vector <int> vi;
vi P;
vi prime(int n){
	int i=0,j=1,h=(n+1)/2,x,r=(int)pow(n,.5);
	vi s(h),p(1);
	while(j<=n){
		s[i++]=j;
		j+=2;
	}
	p[0]=2;
	for (i=1;i<h;i++)
		if (x=s[i]){
			p.push_back(x);
			if (i<=r) for (j=x*x/2;j<h;j+=x) s[j]=0;
		}
	return p;
}
int main(void){
	int n,s;
	P=prime(105000);
	while (true){
		std::cin>>n; if (n==0) break;
		for (s=0;n--;) s+=P[n];
		std::cout<<s<<"\n";
	}
}

Measured memory_bytes: 1360
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int l=1;
  for (int i=0;i<m;i++) 
  {
  	int x,y;
    cin>>x>>y;
    l=max(l,x);
    n=min(n,y);
  }
cout<<max(0,n-l+1)<<endl;
return 0;
}

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

using namespace std;
using Graph = vector<vector<int>>;
Graph G;
vector<int>color;

bool dfs(int v, int c)
{
    color[v] = c;
    for(auto nx: G[v])
    {
        if(color[nx] != -1)
        {
            if(color[nx] == c)
            {
                return false;
            }
            continue;
        }
        if(!dfs(nx,1-c))
        {
            return false;
        }
    }
    return true;
}
int main()
{
    long long int n,m;
    cin >> n >> m;
    G.resize(n);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    color.assign(n,-1);
    long long int ans;
    if(dfs(0,0))
    {
        long long int c = 0;
        long long int d = 0;
        for(auto x: color)
        {
            if(x == 0)
            {
                c++;
            }
            else
            {
                d++;
            }
        }
        ans = c*d - m;
        cout << ans << endl;
    }
    else
    {
        ans = n*(n-1) / 2 - m;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
    #define int long long
    using namespace std;
    int32_t main()
    {
        int n,ans=0;
        cin>>n;
        string s;
        cin>>s;
        
        for(int i=0;i<n-2;++i)
        {
            if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
            {
                ++ans;
            }
        }
        cout<<ans;
    }

Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();

        //三項演算子
        int price = (N <= K)? N * X : (K * X) + ((N - K) * Y );
        
        System.out.println(price);
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll evaluate(int contest, int date, vector<ll>& last, vector<ll>& c, vll& s) {
    ll point_today = 0;
    point_today += s[date][contest];
    for (ll j = 1; j <= 26; j++) {
        if(j==date){
            continue;
        }
        point_today -= c[j] * (date - last[j]);
    }
    return point_today;
}

int main(){
  ll d;
  cin >> d;//全日数
  vl c(27);
  for(ll i=1;i<=26;i++){//c_i==c[i]
    cin >> c[i];
  }
  vll s(d + 1, vl(27)); //s_d,i==s[d][i]
  for (ll i = 1; i <= d; i++){
    for (ll j = 1; j <= 26;j++){
      cin >> s[i][j];
    }
  }
  vl t;
  vl last(27, 0);//last(d,i)==last[i]
  ll satisfy = 0;
  for (ll date = 1; date <= d;date++){
    priority_queue<pair<ll, int>> q;
    for (ll contest = 1; contest <= 26;contest++){
      q.push(mp(evaluate(contest, date, last,c,s), contest));
    }
    t.pb(q.top().S);
    //satisfy += q.top().F;
    last[q.top().S] = date;
  }
  rep(i,d){
    print(t[i]);
  }
}

Measured memory_bytes: 3744
#include <stdio.h>
int main(void){
    // Your code here!
    int p,q,r,i;
    int diff[7];
    scanf("%d",&p);
    scanf("%d",&q);
    scanf("%d",&r);
    diff[0]=p+q;
    diff[1]=q+r;
    diff[2]=r+p;
    diff[3]=q+p;
    diff[4]=r+q;
    diff[5]=p+r;
    diff[6]=diff[0];
    for(i=1;i<7;i++){
        if(diff[i]<diff[6]){
            diff[6]=diff[i];
            
        }
    }
    printf("%d",diff[6]);
}


Measured memory_bytes: 128
#include<stdio.h>

int ans[200010];
int a[200010];

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


Measured memory_bytes: 3208
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
int a[3000];
int b[3000];
int c[3000];
signed main(){
  int n,k;
  cin >> n >> k;
  REP(i,n){
    cin >> a[i];
  }
  REP(i,n){
    REP(j,n){
      if(a[i]>a[j]){
        c[i] ++;
      }
      if(a[i]>a[j]&&i<j){
        b[i] ++;
      }
    }
  }
  int ans = 0;
  REP(i,n){
    ans += b[i]*k;
    ans %= MOD;
    int t2 = k*(k-1)/2;
    t2 %= MOD;
    ans += c[i] * t2;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P=pair<int ,int>;
int main(){
  int h,w; cin>>h>>w;
  vector<string> s(h);
  for(int i=0;i<h;i++){
    cin>>s[i];
  }
  int y[4]={0,0,1,-1};
  int x[4]={1,-1,0,0};
  int c=0;
  bool flag=true;
  vector<vector<bool>> vis(h,vector<bool>(w,false));
  queue<P> que,que2;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        vis[i][j]==true;
        for(int k=0;k<4;k++){
          if(0<=i+x[k] && i+x[k]<h && 0<=j+y[k] && j+y[k]<w && s[i+x[k]][j+y[k]]=='.' && !vis[i+x[k]][j+y[k]]){
            que.push(P(i+x[k],j+y[k]));
            vis[i+x[k]][j+y[k]]=true;
            if(flag){
              c++;
              flag=false;
            }
          }
        }
      }
    }
  }
  while(!que.empty() || !que2.empty()){
    flag=false;
    while(!que.empty()){
      P p=que.front(); que.pop();
      int a=p.first,b=p.second;
        for(int k=0;k<4;k++){
          if(0<=a+x[k] && a+x[k]<h && 0<=b+y[k] && b+y[k]<w && s[a+x[k]][b+y[k]]=='.' && !vis[a+x[k]][b+y[k]]){
            que2.push(P(a+x[k],b+y[k]));
            vis[a+x[k]][b+y[k]]=true;
            flag=true;
          }
        }
    }if(flag) c++;
    flag=false;
    while(!que2.empty()){
      P p2=que2.front(); que2.pop();
      int a=p2.first,b=p2.second;
      for(int k=0;k<4;k++){
        if(0<=a+x[k] && a+x[k]<h && 0<=b+y[k] && b+y[k]<w && s[a+x[k]][b+y[k]]=='.' && !vis[a+x[k]][b+y[k]]){
          que.push(P(a+x[k],b+y[k]));
          vis[a+x[k]][b+y[k]]=true;
          flag=true;
        }
      }
    }
    if(flag) c++;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define DEBUG true
#define $(x) {if (DEBUG) {cout << #x << " = " << (x) << endl;}}


LL countN(LL i, LL j, string& S) {
    //$(i);
    //$(j);
    LL na = 0;
    LL ret = 0;
    for (LL k = i; k < j; ++k) {
        if (S[k] == 'A') {
            na++;
        } else {
            ret += na;
        }
    }
    //$(ret);
    return ret;
}


int main() {
    string s;
    cin >> s;
    string S = "";
    bool flag = false;
    REP(i, SZ(s)) {
        if (flag) {
            flag = false;
        } else if (s[i] == 'A') S += 'A';
        else if (i < SZ(s) - 1 && s[i] == 'B' && s[i + 1] == 'C') {
            S += 'D';
            flag = true;
        }
        else S += 'E';
    }
    LL ans = 0;
    LL prev_pos = 0;
    LL pos = (LL)S.find('E');
    while (pos != string::npos) {
        ans += countN(prev_pos, pos, S);
        prev_pos = pos;
        pos = (LL)S.find('E', pos + 1);
    }
    ans += countN(prev_pos, SZ(S), S);
    cout << ans << endl;
	
    return 0;
}


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

using namespace std;

struct Point
{
  int64_t x, y;
  Point(int64_t x = 0, int64_t y = 0) : x(x), y(y) {}
};

istream& operator>>(istream &is, Point &p)
{
  is >> p.x >> p.y;
  return is;
}

int main()
{
  uint64_t N, K;
  cin >> N >> K;
  
  vector<int64_t> x(N), y(N);
  vector<Point> p(N);
  
  for (uint64_t n = 0; n < N; ++n) {
    cin >> p[n];
    
    x[n] = p[n].x;
    y[n] = p[n].y;
  }
  
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  
  uint64_t s_min = 1e+20;
  for (uint64_t ix = 0; ix < N; ++ix) {
    int64_t x_min = x[ix];
    for (uint64_t iy = 0; iy < N; ++iy) {
      int64_t y_min = y[iy];
      for (uint64_t jx = ix + 1; jx < N; ++jx) {
        int64_t x_max = x[jx];
        for (uint64_t jy = iy + 1; jy < N; ++jy) {
          int64_t y_max = y[jy];
          
          uint64_t k = 0;
          for (uint64_t l = 0; l < N; ++l) {
            if ( (x_min <= p[l].x && p[l].x <= x_max)
              && (y_min <= p[l].y && p[l].y <= y_max)  
            ) {
              ++k;
            }
          }
          
          if (k >= K) {
            uint64_t s = (x_max - x_min) * (y_max - y_min);
            s_min = min(s_min, s);
          }
        }
      }
    }
  }
  cout << s_min << endl;
  
  return 0;
}

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

using namespace std;

const int maxV = 1e5;

int n, even, odd;
int f[maxV+10];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        int x; scanf("%d", &x);
        f[x]++;
    }

    int ans = n;
    for (int i = 1; i <= maxV; ++i) {
        if (f[i] == 0) continue;

        if (f[i]&1) ans -= f[i] - 1, odd++;
        else ans -= f[i] - 2, even++;
    }


    ans -= even + (even&1);
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var < (end); var++)
#define RFOR(var, begin, end) for (int var = (begin) - 1; var >= (end); var--)
#define REP(var, length) FOR(var, 0, length)
#define RREP(var, length) RFOR(var, length, 0)
#define SORT(vector) sort(vector.begin(), vector.end())

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  string l;
  cin >> l;
  int n = l.size();

  vector<ll> dp1(n + 1);
  vector<ll> dp2(n + 1);

  dp1[0] = 0;
  dp2[0] = 1;

  REP(i, n) {
    if (l[i] == '1') {
      dp1[i + 1] = (dp1[i] * 3 % MOD + dp2[i]) % MOD;
      dp2[i + 1] = dp2[i] * 2 % MOD;
    } else {
      dp1[i + 1] = dp1[i] * 3 % MOD;
      dp2[i + 1] = dp2[i];
    }
  }

  cout << (dp1[n] + dp2[n]) % MOD << endl;

}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
vector<vector<int>> v(200001);
vector<ll> ans(200001,0LL);
vector<bool> used(200001);


void search(int p,int parent,ll sum){
	used[p] = true;
	sum += ans[p]; 
	ans[p] = sum;
	for(int i = 0; i < v[p].size(); i++) {
		if (v[p][i] != parent && used[v[p][i]] == false){
			search(v[p][i],p,sum);
		}
	}
}

int main(){
	int n,q;cin>>n>>q;
	int a,b;
	for(int i = 0; i < n - 1; i++) {
		cin>>a>>b;
		v[a - 1].pb(b - 1);
		v[b - 1].pb(a - 1);
	}
	for(int i = 0; i < q; i++) {
		ll a,b;cin>>a>>b;
		ans[a - 1LL] += b;
	}
	search(0, 0,0LL);

	for(int i = 0; i < n; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;




	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,m; cin>>n>>m;
  vpll ans;
  if(n%2){
    for(ll l=1, r=n-1; l<r; l++, r--){
      ans.emplace_back(l,r);
    }
  }else{
    bool flg=false;
    for(ll l=1, r=n-1; l<r; l++, r--){
      if(!flg && r-l<=n/2){
        r--;
        flg=true;
      }
      ans.emplace_back(l,r);
    }
  }
  rep(i,m){
    cout<<ans[i].first <<" "<<ans[i].second<<endl;
  }
  
}

Measured memory_bytes: 5192
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX];

void maxHeapify(int i){
	int l, r, largest;
	l=2*i;
	r=2*i+1;

	if(l<=H && A[l]>A[i])
		largest=l;
	else
		largest=i;
	if(r<=H && A[r]>A[largest])
		largest=r;
	if(largest!=i){
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}
}

int extract(){
	int maxv;
	if(H<1)	return -INFTY;
	maxv=A[1];
	A[1]=A[H--];
	maxHeapify(1);
	return maxv;
}


void incresingKey(int i, int key){
	if(key<A[i])	return ;
	A[i]=key;
	while(i>1 && A[i/2]<A[i]){
		swap(A[i], A[i/2]);
		i=i/2;
	}
}


void insert(int key){
	H++;
	A[H]=-INFTY;
	incresingKey(H, key);
}

int main(){
	int key;
	char com[10];
	while(1){
		cin>>com;
		if(com[0]=='e' && com[1]=='n')
			break;
		if(com[0]=='i'){
			cin>>key;
			insert(key);
		}
		else{
			cout<<extract()<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 6984
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
    #include "lib/dump.hpp"
#else
    #define dump(...) 42
    #define dump_1d(...) 42
    #define dump_2d(...) 42
    #define cerrendl 42
#endif
//}}}

signed main() {
    int n,x,y;cin>>n>>x>>y;
    x--;y--;

    // cout << n-1 << endl;  // for k = 1

    vector<vector<int>> dp(n, vector<int>(n, INF));

    vi cnt(n);
    rep(i, n)rep(j, i+1, n){
        dp[i][j] = min(abs(x-i) + 1 + abs(j-y), j-i);
        cnt[dp[i][j]]++;
    }

    dump_2d(dp, n, n);

    rep(k, 1, n){
        cout << cnt[k] << endl;
    }

    return 0;
}


Measured memory_bytes: 31616
program main
implicit none
integer :: i, g
integer :: n, m
integer , allocatable :: x(:)

read(*,*) n, m
allocate( x(n) )
read(*,*) x(1:n)
x = abs(x -m)
if( n == 1 ) then
   write(*,'(i0)') x(1)
else
   do i = 1, n-1
      call gcdlcm(x(i), x(i+1), g)
      x(i+1) = g
   end do
   write(*,'(i0)') g
end if

stop
contains
  subroutine gcdlcm( a, b, g )
    integer , intent(in)  :: a, b
    integer , intent(out) :: g

    integer :: i, j, k,l

    i = a
    j = b
    do while( j /= 0 )
       k = mod(i,j)
       i = j
       j = k
    end do
    g = i
    l = a*b/g
  end subroutine gcdlcm

end program main



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



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int r,b,g;
    cin>>r>>b>>g;
    cout<<((100*r+10*b+g)%4?"NO":"YES");
    
    return 0;
}

Measured memory_bytes: 256
def insertion_sort(a, n, g)
  cnt = 0
  (g..n-1).each do |i|
    v = a[i]
    j = i - g
    while j >= 0 && a[j] > v
      a[j+g] = a[j]
      j = j - g
      cnt += 1
    end
    a[j+g] = v
  end
  cnt
end

def shell_sort(a, n)
  cnt = 0
  g = []
  h = 1
  while h <= n
    g << h
    h = 3 * h + 1
  end
  g.reverse!
  m = g.length
  puts m
  puts g.join(' ')
  (0..m-1).each do |i|
    cnt += insertion_sort(a, n, g[i])
  end
  puts cnt
end

n = gets.to_i
a = []
n.times{a<<gets.to_i}
shell_sort(a, n)
a.each{|x|puts x}


Measured memory_bytes: 14796
n = int(input())
an = [int(x) for x in input().split()]

for i in an:
    if i % 2 == 0:
        flag = False
        if i % 3 == 0:
            flag = True
        if i % 5 == 0:
            flag = True
        if flag == False:
            print('DENIED')
            exit()

print('APPROVED')

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

int main() {
  int N;
  cin >> N;
  
  
  
  for (int i=0 ; i < N ; i++) {
    
    string x;
    cin >> x;
    if ( x == "Y" ) {
      cout << "Four " << endl;
        break;
    }
    if (i == N-1) {
      cout << "Three" << endl;
    }
  }
    
  // ここにプログラムを追記
}

Measured memory_bytes: 256
import math
import itertools
import statistics
#import collections
s = input()
start = -1
end = -1

for i in range(len(s)):
    if s[i]=="A" and start==-1:
        start = i
    
    if s[i]=="Z":
        end = i

#print(s[start:end+1])
print(end-start+1)
    

Measured memory_bytes: 5660
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (1LL<<57)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	ll n;
	cin>>n;
	ll cz = 1;
	for(ll i=2;i*i<=n;i++)
	{
		ll tz = n;
		while(!(tz % i))
		tz /= i;
		if((tz % i) == 1)
		cz++;	
	}
	for(ll i=1;i*i<=(n-1);i++)
	{
		if((!((n-1) % i)) && (i*i != (n-1)))
		cz++;
	}
	cout<<cz<<"\n";
	return;
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k, st[ohara], en[ohara], stcnt, encnt;
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};
unordered_map<ll, ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> n >> m;
    rep(i, m) cin >> a[i] >> b[i];
    rep(i, m)
    {
        if (a[i] == 1)
            st[stcnt++] = b[i];
        else if (b[i] == n)
            en[encnt++] = a[i];
    }
    rep(i, stcnt) mp[st[i]]++;
    rep(i, encnt) mp[en[i]]++;
    rrep(i, 2, n)
    {
        if (mp[i] >= 2)
        {
            Cout("POSSIBLE");
            return 0;
        }
    }
    Cout("IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 21576
// inputに入力データ全体が入る
    function Main(input) {
      var input1 = input.split("\n")[0];
      var k = input1.split(" ")[0];
      k = parseInt(k, 10);
      var input2 = input.split("\n")[1];
      var a = input2.split(" ");
      var max = 0;
      for (var i=0; i< a.length;i++) {
        if ( i === a.length -1) {
          var sa = a[0] - a[i] + k;
          if ( sa > max) {
            max = sa;
          }
          break;
        }
        var sa =  a[i+1] - a[i];
        if (sa > max ) {
          max = sa;
        }
      }
      console.log(k - max);
    }
    //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
    Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 34820
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		String[] s = sc.next().split("");
        String ans = s[0];
        ans += s.length - 2;
        ans += s[s.length - 1];
    
		// 出力
		System.out.println(ans);
	}
}

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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.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;
}

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;

void solve();

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

void solve()
{
    ll a, b;
    in2(a, b);
    int ans = max({a + b, a - b, a * b});
    out(ans);
}

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

 
int main() {
    int n;
    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        if(s == "AC") ac++;
        if(s == "WA") wa++;
        if(s == "TLE") tle++;
        if(s == "RE") re++;
    }
    cout << "AC x " + to_string(ac) << endl;
    cout << "WA x " + to_string(wa) << endl;
    cout << "TLE x " + to_string(tle) << endl;
    cout << "RE x " + to_string(re) << endl;
}


Measured memory_bytes: 3692
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<vector<ll>> t(n, vector<ll>(2, 0));
  for(int i = 0; i < n; i++) {
    ll x, l;
    cin >> x >> l;
    t[i][0] = x + l;
    t[i][1] = x - l;
  }
  sort(t.begin(), t.end());
  ll r = -1001001001;
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(r > t[i][1]) {
      continue;
    }
    ans++;
    r = max(r, t[i][0]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8792
#include <iostream>
#include <math.h>

using namespace std;


class point{
public:
	double x, y;
	int set();
};

int point::set()
{
	cin >> x >> y;
	return 0;
}

int main()
{
	point P1, P2;
	P1.set();
	P2.set();

	cout << fixed << sqrt((P1.x - P2.x)*(P1.x - P2.x) + (P1.y - P2.y)*(P1.y - P2.y)) << endl;

	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n, m, l;
  cin >> n >> m >> l;
  vvi dist(n, vi(n,INF));
  rep(i,n) dist[i][i] = 0;
  rep(i,m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    dist[a][b] = dist[b][a] = c;
  }
  rep(k,n)rep(i,n)rep(j,n) chmin(dist[i][j], dist[i][k]+dist[k][j]);
  vvi dist2(n,vi(n,INF));
  rep(i,n)rep(j,n) {
    if (dist[i][j] <= l) dist2[i][j] = 1;
  }
  rep(i,n) dist2[i][i] = 0;
  rep(k,n)rep(i,n)rep(j,n) chmin(dist2[i][j], dist2[i][k]+dist2[k][j]);
  int q;
  cin >> q;
  rep(qi,q) {
    int s, t;
    cin >> s >> t;
    --s; --t;
    int ans = dist2[s][t]-1;
    if (dist2[s][t] == INF) ans = -1;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1280