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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int h, w;
    while (cin >> h >> w, h || w)
    {
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if ((i + j) % 2)
                    cout << '.';
                else
                    cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}



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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define eb emplace_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;
#define MOD int(1e9+7)


void solve(){

    int n = 0,k = 0;
    cin >> n >> k;
    vector<vector<int> >c(n+1,vector<int>(n+1,0));
    rep(i, 0, n+1){
        rep(j, 0, i+1){
            if(i == 0 || j == 0) c[i][j] = 1;
            else c[i][j] = (c[i-1][j-1] + c[i-1][j])%MOD;
        }
    }

    for(int i = 1; i <= k; ++i){
        ll ans = (ll)c[n-k+1][i]*c[k-1][i-1];
        ans %= MOD;
        cout << ans << "\n";
    }

    return;
}

int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/


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

const int MAXN = 100+2;
int nums[MAXN];

int main() {
    int n,m;
    scanf("%d%d", &n, &m);

    int sum=0;
    for (int i=0; i<n; i++) {
        scanf("%d", &nums[i]);
        sum += nums[i];
    }

    int cnt = 0;
    for (int i=0; i<n; i++) {
        if (nums[i]*4*m>=sum) {
            cnt++;
            if (cnt >= m) {
                printf("Yes\n");
                return 0;
            }
        }
    }

    printf("No\n");

    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc113/tasks/abc113_b
n = int(input())
t, a = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
h2 = [abs(t - x * 0.006 - a) for x in h]
print(h2.index(min(h2)) + 1)


Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int N;
  string S;
  cin>>N>>S;
  string T="";
  for(int i=0;i<N/2;i++) T+=S[i];
  string X="No";
  if(S==T+T) X="Yes";
  cout<<X;
return 0;}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp15
{
    class Class308
    {
        static void Main()
        {
            long X = long.Parse(Console.ReadLine());

            
            for(long a = -200; a < 200; a++)
            {
                for(long b = -200; b < 200; b++)
                {
                    if (Pow(a, 5) - Pow(b, 5) == X)
                    {
                        Console.WriteLine($"{a} {b}");
                        return;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 27868
#include <bits/stdc++.h>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int N=1e5+5;
int prime[N],sum[N];
bool is_pr[N];
int cnt;
void sieve()
{
    cnt=0;
    mem(is_pr,0);
    for(int i=2; i*i<=N; i++)
    {
        if(!is_pr[i])
        {
            for(int j=i*i; j<=N; j+=i)
                is_pr[j]=1;
        }
    }
    for(int i=2; i<N; i++)
        if(!is_pr[i]) prime[cnt++]=i;
    mem(sum,0);
    for(int i=1;i<cnt;i++)
    {
        int tmp=(prime[i]+1)/2;
        int pos=lower_bound(prime,prime+i,tmp)-prime;
        if(prime[pos]==tmp) sum[prime[i]]++;
    }
    for(int i=1;i<cnt;i++) sum[prime[i]]+=sum[prime[i-1]];
}
int main()
{
    sieve();
    int q;
    ///for(int i=0;i<50;i++)
      //  if(sum[i]) printf("%d %d\n",i,sum[i]);
    while(~scanf("%d",&q))
    {
        rep(i,0,q)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            int pos1=lower_bound(prime,prime+cnt,l)-prime;
           // printf("prime  %d\n",prime[pos1]);
            int pos2=lower_bound(prime,prime+cnt,r)-prime;
            if(prime[pos2]==r) r=prime[pos2];
            else r=prime[pos2-1];
            //printf("%d %d\n",sum[r],sum[pos1]);
            printf("%d\n",sum[r]-sum[prime[pos1-1]]);
        }
    }
    return 0;
}


Measured memory_bytes: 1152
x,k,d=map(int,input().split())
if x==0:
  if k%2==0:
    print(0)
    exit()
  else:
    print(d)
    exit()
x=abs(x)
if abs(x//d)>=k:
  if k%2==0:
    print(min(abs(x-k*d),abs(x+k*d),x))
    exit()
  print(min(abs(x-k*d),abs(x+k*d)))
  exit()
else:
  a=abs(x//d)
  if x>0:
    kouho=x-a*d
    nokori=k-a
    if nokori%2==0:
      print(kouho)
      exit()
    else:
      print(abs(kouho-d))
      exit()



Measured memory_bytes: 61848
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define all(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)


ll modpow(ll x, ll n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        ll h = modpow(x, n / 2);
        return h * h % MOD;
    } else {
        return x * modpow(x, n - 1) % MOD;
    }
}

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

int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
    int N, D, X; cin >> N >> D >> X;
    vector<int> A(N);
    rep(i,N)  cin >> A[i];
    int sum = X;
    rep(i,N){
      int day = 1;
      while(day <= D){
        sum++;
        day += A[i];
      }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 105
#define ll long long
 
using namespace std;
 
int main()
{
	int m,d,ans=0;
	cin >> m >> d;
	for(int i=1;i<=m;++i){
		for(int j=22;j<=min(99,d);++j){
			if(j%10<2)
				continue;
			if( i== ( (j/10) * (j%10) ) )
				++ans;//,cout << i << "-" << j << endl;
		}
	}

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


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

int main(){
    int a, b, c, t;
    cin >> a >> b >> c;
    
    if(a > b){
        t = a; a = b; b = t;
    }
    
    if(b > c){
        t = b; b = c; c = t;
    }
    
    if(a > b){
        t = a; a = b; b = t;
    }
    
    cout << a << " " << b << " " << c << endl;
    
    return 0;
 }

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

using namespace std;

int C[100001]={0},h[100001]={0};

/*int get(int n)
{ 
	if(n==1)
		return 0;
	else if (n==2)
	{
		C[2]=abs(h[2]-h[1]);
		return C[2];
	}
	//if(C[n]==0)
	//{
		/*int tnn_1=abs(h[n]-h[n-1])+C[n-1];
		int tnn_2=abs(h[n]-h[n-2])+C[n-2];
		if(tnn_1<tnn_2)
		{
			C[n]=tnn_1;
			return tnn_1;
		}
		C[n]=tnn_2;
		return tnn_2;*/
		/*for(int i=3;i<=n;i++)
		{
			C[i]=min(abs(h[i]-h[i-1])+C[i-1],abs(h[i]-h[i-2])+C[i-2]);
		}
	
	return C[n];
}
*/
int main()
{

	int n;
	cin>>n;

	for(int x=1;x<=n;x++)
	{
		cin>>h[x];
	}


		C[2]=abs(h[2]-h[1]);

		for(int i=3;i<=n;i++)
		{
			C[i]=min(abs(h[i]-h[i-1])+C[i-1],abs(h[i]-h[i-2])+C[i-2]);
		}

	cout<<C[n];

	return 0;
}

Measured memory_bytes: 1024
#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;

int main(){
	int N;
	cin >> N;
	ll l,ans = 0; 
	for (int i= 0;i< N;i++){
		cin >> l;
		ans += l - 1;
	}
	cout <<ans <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;


int main() {
  int n;
  int a[200100], b[200100];
  pair<int, int> p[200100];

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

  sort(p, p+n);

  long long int time = 0;
  for (int i = 0; i < n; i++) {
    time += p[i].second;
    if (time > p[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

}


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


int main(void){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 0;
    if(a+b < 2*c){
        ans += a*x + b*y;
    }
    else{
        ans += 2*c*min(x,y);
        int num = abs(x-y);
        if(x>y){
            ans += num*min(a,2*c);
        }
        else{
            ans += num*min(b,2*c);
        }
    }
    cout << ans << endl;
    
    return 0;
}




























































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

int main(){
  
   int n;
   string s;
   cin>>n;
  
   for(int i=0; i<n; i++){
     cin>>s;
     st.insert(s);
   }
   
   cout<<st.size()<<endl;
   
   return 0;
}

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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld Pi = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 1e2 + 10;
const ll INF = (ll) 9223372036854775;

ll a[MAXN];

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, x;
    cin >> n >> x;
    for(int i =0;i<n;i++)cin >> a[i];
    sort(a,a + n);
    ll ans = 0;
    for(int i =0;i<n-1;i++){
        if(x >= a[i]){
            x-=a[i];
            ans++;
        } else {
            x = 0;
        }
    }
    if(x==a[n-1]) ans ++;
    cout << ans;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
  int n;
  cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  sort(all(a));
  int d;
  int flag=0;
  rep(i,n){
    if(i==0){
      d=a[i];
    }
    else{
      if(a[i]==d){
        flag=1;
        break;
      }
      else{
        d=a[i];
      }
    }
  }

  if(flag==0){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }

  
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    vector<pair<string, pair<int, int>>> m;
    for(int i = 0; i < N; i++) {
        string S;
        int P;
        cin >> S >> P;
        m.push_back({S, {-P, i + 1}});
    }
    sort(m.begin(), m.end());
    for(int i = 0; i < N; i++) {
        cout << m[i].second.second << endl;
    }
    return 0;
}

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

pub 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")
}

// use std::cmp::{max, min};

fn main() {
  let n = read::<usize>();
  let k = read::<usize>();
  let mut ans = (n / k) * (n / k) * (n / k);
  if k % 2 == 0 {
    let cnt = (n + k / 2) / k;
    ans += cnt * cnt * cnt;
  }
  println!("{}", ans);
}



Measured memory_bytes: 4352
n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
ans=0
for x in b:
    l=-1
    r=n
    while r-l>1:
        mid=(l+r)//2
        if a[mid]>=x:
            r=mid
        else:
            l=mid
    lb=r
    l=-1
    r=n
    while r-l>1:
        mid=(l+r)//2
        if a[mid]>x:
            r=mid
        else:
            l=mid
    ub=r
    ans+=ub>lb
print(ans)


Measured memory_bytes: 16708
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();

		if (Math.abs(c - a) <= d || (Math.abs(b - a) <= d && Math.abs(c - b) <= d)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

vector<ll> ZAlgorithm(string s) {
  int N = s.length();
  vector<ll> result(N); result[0] = N;
  int i = 1, j = 0;
  while (i<N) {
    while (i+j<N&&s[j]==s[i+j]) j++;
    result[i] = j;
    if (j==0) { i++; continue; }
    int k = 1;
    while (k<j&&k+result[k]<j) {
      result[i+k] = result[k];
      k++;
    }
    i+=k; j-=k;
  }
  return result;
}

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

int main() {
  string w; cin >> w;
  string wr = w; reverse(all(wr));
  ll l = w.length();
  vector<ll> za = ZAlgorithm(w), zar = ZAlgorithm(wr);
  vector<bool> use(l,true), user(l,true);
  repr(i,1,l) for (int j=i*2-1; j<i+za[i]; j+=i) use[j] = false;
  repr(i,1,l) for (int j=i*2-1; j<i+zar[i]; j+=i) user[j] = false; reverse(all(user));
  // debug(all(use)); debug(all(user));

  ll pos = 0;
  repr(i,1,l) if (i+za[i]==l&&l%i==0) { pos=i; break; }
  int len = 0, cnt = 0;
  if (pos==0) { len = 1; cnt = 1; }
  else if (pos==1) { len = l; cnt = 1; }
  else {
    len = 2;
    rep(i,l-1) if (use[i]&&user[i+1]) cnt++;
  }
  cout << len << endl;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 9500
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}



const int MAX_N = 100010;
using Graph = vector<VE>;
VE depth;
map<pair<int, int>, int>mp;
void dfs(const Graph &G, int v, int p, int d) {
	depth[v] = d;
	for (auto nv : G[v]) {
		if (nv == p) continue; // nv が親 p だったらダメ
		//cout << v << " " << nv << endl;
		dfs(G, nv, v, d + mp[make_pair(v,nv)]); // d を 1 増やして子ノードへ
	}
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	depth.resize(n);
	Graph G(n);
	rep(i, n - 1) {
		int a, b; cin >> a >> b; a--; b--;
		int c; cin >> c;
		mp[make_pair(a, b)] = c; mp[make_pair(b, a)] = c;
		G[a].push_back(b); G[b].push_back(a);
	}
	int root = 0;
	dfs(G, root, -1, 0);
	rep(i, n) {
		//cout << depth[i] << endl;
		if (depth[i] % 2 == 0)cout << 0 << endl;
		else cout << 1 << endl;
	}
	return 0;
}

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

int main (){
    int N = 0;
    cin >> N;
    int ans = 0;
    vector<long long> L(N,0);
    for(int i = 0; i < N; i++) {
    cin >> L.at(i);
    }
    for (size_t i = 0; i < N; i++)
    {
        for (size_t j = i + 1; j < N; j++)
        {
            for (size_t k = j + 1; k < N; k++)
            {
                if ((L.at(i) != L.at(j)) && (L.at(k) != L.at(j)) && (L.at(i) != L.at(k)))
                {
                    if (L.at(i) + L.at(j) + L.at(k) > 2*(max(L.at(i),max(L.at(j),L.at(k)))))
                    {
                        ans++;
                    }
                    
                }
                
            }
            
        }
        
    }

    cout << ans << endl;
    


    
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>
#include <string>
#include <math.h>

using namespace std;

void solve(vector<vector<int> >& books, vector<int>& cost, int index, vector<int>& chosen, int& best, int x) {
  if (index == books.size()) {
    int sum = 0;
    int sum_cost = 0;
    vector<int> skills(books[0].size());
    for (int i=0;i<books.size();++i) {
      if (chosen[i]) {
        for (int j=0;j<books[i].size();++j) {
          skills[j] += books[i][j];
        }
        sum_cost += cost[i];
      }
    }


    bool is_ok = true;
    for (int i=0;i<books[0].size();++i) {
      is_ok = is_ok && (skills[i] >= x);

    }

    if (is_ok && (best == -1 || sum_cost < best))
      best = sum_cost;

    return; 

  }

  chosen.push_back(0);
  solve(books, cost, index + 1, chosen, best, x);
  chosen[chosen.size() - 1] = 1;
  solve(books, cost, index + 1, chosen, best, x);
  chosen.pop_back();
}

int main() {
  int n, m, x;
  scanf("%d %d %d", &n, &m, &x);

  vector<vector<int> > books(n);
  vector<int> cost(n);
  
  for (int i=0;i<n;++i) {
    scanf("%d", &cost[i]);

    int x;
    vector<int> vec;
    for (int j=0;j<m;++j) {
      scanf("%d", &x);
      vec.push_back(x);
    }

    books[i] = vec;
  }

  int best = -1;
  vector<int> p;

  solve(books, cost, 0, p, best, x);

  printf("%d", best);

  return 0;
}


Measured memory_bytes: 3232
N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(N-1):
    if (a[i]+a[i+1]) > x and x < a[i] :
        ans += a[i+1]+a[i]-x
        
        a[i] = a[i]-(x-a[i+1])
        a[i+1] = 0
        
    elif (a[i]+a[i+1]) > x:
        ans += a[i+1]+a[i]-x
        
        a[i+1] = x-a[i]
        
print(ans)

Measured memory_bytes: 14052
import sys
import decimal # 10進法に変換，正確な計算

def input():
    return sys.stdin.readline().strip()

def main():
    a, b = map(int, input().split())
    c = a - b*2
    if c < 0:
        print(0)
        return
    print(c)
            
    
    
main()


Measured memory_bytes: 5076
H, W, K = map(int, input().split())
grid = [[c for c in str(input())] for _ in range(H)]
ans = 0
from itertools import product
for rarr in product(range(2), repeat=H):
    for carr in product(range(2), repeat=W):
        bk = 0
        for i in range(H):
            if rarr[i] == 0: continue
            for j in range(W):
                if carr[j] == 0: continue
                if grid[i][j] == '#': bk += 1
        if bk == K:
            ans += 1
print(ans)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll x, k, d;
	cin >> x >> k >> d;
	ll y = abs(x);
	ll z = y / d;
	if (z > k)
	{
		if (x < 0)
		{
			x = x + k * d;
		}
		else
		{
			x -= k * d;
		}
		cout << abs(x);
	}

	else if (z == k)
	{
		if (x < 0)
		{
			x = x + z * d;
		}
		else
		{
			x -= z * d;
		}
		cout << abs(x);
	}
	else
	{
		if (x < 0)
		{
			x = x + z * d;
		}
		else
		{
			x -= z * d;
		}
		z = k - z;
		if (z % 2 == 0)
		{
			cout << abs(x) << endl;
		}
		else
		{
			if (x < 0)
				cout <<  abs(x + d);
			else
				cout <<  abs(x - d);
		}

	}


	return 0;
}



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

bool f[1000000];

int main(){
	int n;
	while(cin>>n){
		memset(f,0,n*sizeof(bool));
		int l=sqrt(n);
		for(int i=2;i<=l;i++){
			for(int j=2;j*i<=n;j++){
				f[j*i]=true;
			}
		}
		int cnt=0;
		for(int i=2;i<=n;i++) if(!f[i])cnt++;
		cout<<cnt<<endl;
	}
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W;
string S[12];
string T[12];

bool ans;

void uku(){
    map<string,int>cnt;
    rep(j,W){
        string s;
        rep(i,H){
            if(T[i][j]=='*')s+=T[H-1-i][j];
            else s+=T[i][j];
        }
        string t=s;
        reverse(all(t));
        if(s<=t){
            cnt[s]++;
        }
        else{
            cnt[t]--;
        }
    }

    bool flag=false;
    for(auto &p:cnt){
        if(p.se==0)continue;
        string s=p.fi;
        string t=s;reverse(all(t));

        if(s!=t)return;
        if(p.se%2==0)continue;
        if(flag)return;
        flag=true;
    }
    ans=true;
}

void ei(int b,int k){
    if(b==0){
        uku();
        return;
    }

    int s=0;
    while(~b>>s&1)s++;
    T[k]=S[s];
    for(int i=s+1;i<H;i++)if(b>>i&1){
        T[H-1-k]=S[i];
        ei(b^(1<<s)^(1<<i),k+1);
    }
}

signed main(){
    cin>>H>>W;
    rep(i,H)cin>>S[i];

    if(H&1){
        S[H]=string(W,'*');
        H++;
    }
    ei((1<<H)-1,0);
    if(ans)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
program main
integer a,b,as,al,bs,bl
read *,a,b

as = ceiling(100./8.*dble(a))
al = int(100./8.*dble(a+1))
if(mod(a+1,4)==0) then
al=al-1
endif

bs = ceiling(100./10.*dble(b))
bl = int(100./10.*dble(b+1))-1

!print *,as,al
!print *,bs,bl
do i=as,al
	do j=bs,bl
    	if(i==j) then
        	print *,i
            stop
        end if
     end do
end do
print *,-1       

end

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TemplateAlgorithm
{
    class Program
    {
        public const long Inf = (long)1e18;
        public const double eps = 1e-6;
        public const string alfa = "abcdefghijklmnopqrstuvwxyz";
        public const string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const int MOD = 1000000007;
        
        // c ot i
        static int ToInt(char c) => c - '0';

        static void Main(string[] args)
        {
            int N = IO.ReadInt();
            int[] data = IO.ReadIntArr();
            int[] H = IO.ReadIntArr();

            int T = data[0];
            int A = data[1];

            var temp = new Dictionary<int, double>();            
            for (var i = 0; i < N; i++)
            {
                temp[i] = Abs(A - (T - H[i] * 0.006));                
            }
            var result = temp.OrderBy(x => x.Value).ToArray();
            WriteLine(result.ElementAt(0).Key+1);
        }

        #region  範囲

        public static bool InRange<T>(T begin, T end, T value) where T : IComparable<T> 
            => value.CompareTo(begin) >= 0 && value.CompareTo(end) <= 0;

        #endregion

        #region MIN,MAX

        /// <summary>
        /// 最大値を返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="vals"></param>
        /// <returns></returns>
        public static T MaxValue<T>(params T[] vals) => vals.Max();

        /// <summary>
        /// 最小値を返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="vals"></param>
        /// <returns></returns>
        public static T MinValue<T>(params T[] vals) => vals.Min();
        #endregion
    }

    #region IO

    /// <summary>
    /// IO
    /// </summary>
    public class IO
    {
        public static string ReadStr(bool isTrim = false) => (isTrim) ? ReadLine().Trim() : ReadLine();
        public static int ReadInt() => int.Parse(ReadStr());

        public static long ReadLong() => long.Parse(ReadStr());

        public static decimal ReadDecimal() => decimal.Parse(ReadStr());
        public static double ReadDouble() => double.Parse(ReadStr());
        public static string[] ReadStrArr(char separator = ' ') => ReadLine().Split(separator);
        public static int[] ReadIntArr() => Array.ConvertAll(ReadStrArr(), int.Parse);
        public static long[] ReadLongArr() => Array.ConvertAll(ReadStrArr(), long.Parse);

        public static decimal[] ReadDecimalArr() => Array.ConvertAll(ReadStrArr(), decimal.Parse);
        public static double[] ReadDoubleArr() => Array.ConvertAll(ReadStrArr(), double.Parse);        
    }

    #endregion    
}


Measured memory_bytes: 13536
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

typedef int Weight;

const Weight INF=10000;
struct Edge{
  	int src, dest;
  	int cap, rev;
  	Weight weight;
    bool flag;
    int id;
  	bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int src, int dest, int cap, int id) {
  g[src].push_back((Edge){src, dest, cap, int(g[dest].size()), 0, false, id});
  g[dest].push_back((Edge){dest, src, cap, int(g[src].size()) - 1, 0, true, id});
}

bool visited[400];
int dfs(Graph &g, int v, int t, int f) {
	if (v == t) return f;
	visited[v] = true;
	REP(i, g[v].size()) {
		Edge& e = g[v][i];
		if (!visited[e.dest] && e.cap > 0) {
			int d = dfs(g, e.dest, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				g[e.dest][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(Graph &g, int s, int t) {
	int flow = 0;
	for(;;) {
		memset(visited, 0, sizeof(visited));
		int f = dfs(g, s, t, INF);
		if (f == 0) return flow;
		flow += f;
	}
}

int main() {
  int n,m;
  cin>>n>>m;
  Graph g(n);
  REP(i,m){
    int x,y;
    cin>>x>>y;
    --x;--y;
    add_edge(g,x,y,1,i);
    //add_edge(g,y,x,1,true);
  }
  int s,t;
  cin>>s>>t;
  --s;--t;
  int f = max_flow(g,s,t);
  cout<<f<<endl;
  vector<int> revs;
  REP(i,n)for(Edge e:g[i])
    if(e.flag && e.cap==0){
      revs.push_back(e.id+1);
    }
  cout<<revs.size()<<endl;
  for(int id:revs)cout<<id<<endl;
  return 0;
}

Measured memory_bytes: 1344
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

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

n = int(input())
ms = []
say = []
for i in range(n):
    m = int(input())
    ms.append(m)
    say.append([])
    for j in range(m):
        p,q = list(map(int, input().split()))
        say[i].append([p,q])

#print(say)
ans=0

for i in range(2**n):
    flag = 1
    nowbit = bitlist(i,n)
    total = sum(nowbit)
    for j in range(n):
        for k in range(ms[j]):
            #print(j,k)
            #print(nowbit)
            if(nowbit[j]==1):
                if(nowbit[say[j][k][0]-1]!=say[j][k][1]):
                    flag=0
    if(flag==1 and ans<total):
        ans=total
#print()

print(ans)













Measured memory_bytes: 44352
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
int n,m,p;
struct edge{
    int from;
    int to;
    int cost;
};
edge g[5000];
int d[2500];
int shortest_path(){
    for(int i=0;i<n;i++)d[i]=INF;
    d[0]=0;
    int cnt=0;
    while(1){
        bool update=false;
        for(int i=0;i<m;i++){
            edge es=g[i];
            if(d[es.from]!=INF&&d[es.to]>d[es.from]+es.cost){
                d[es.to]=d[es.from]+es.cost;
                update=true;
            }
        }
        if(update==false)break;
        cnt++;
        if(cnt==n-1)break;
    }
    return d[n-1];
}
bool negative[2500];
void find_negative_loop(){
    for(int i=0;i<n;i++)negative[i]=false;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            edge es=g[j];
            if(d[es.to]<INF&&d[es.to]>d[es.from]+es.cost){
                d[es.to]=d[es.from]+es.cost;
                negative[es.to]=true;
            }
            if(negative[es.from]){
                negative[es.to]=true;
            }
        }
    }
}
signed main(){
    cin>>n>>m>>p;
    for(int i=0;i<m;i++){
        cin>>g[i].from>>g[i].to;
        g[i].from--;
        g[i].to--;
        int a;
        cin>>a;
        g[i].cost=-(a-p);
    }
    int ans=shortest_path();
    find_negative_loop();
    if(negative[n-1])cout<<-1<<endl;
    else if(ans>0)cout<<0<<endl;
    else cout<<-ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    int n; cin >> n;
    vint p(n);
    rep(i, n) cin >> p[i];
    int cnt = 0;
    rep(i, n - 2) {
        int minim = min({p[i], p[i+1], p[i+2]});
        int maxim = max({p[i], p[i+1], p[i+2]});
        if(minim != p[i+1] && maxim != p[i+1]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

int main()
{
	int a, b, c;

	cin >> a >> b >> c;

	if (b - a == c - b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}	
}

Measured memory_bytes: 256
def main():
    from itertools import product
    import heapq

    n = int(input())
    f = [list(map(int, input().split())) for _ in range(n)]
    p = [list(map(int, input().split())) for _ in range(n)]

    l = [[0, 0], [1, 0], [0, 1], [1, 1]]
    r = range(4)
    ans = []
    heapq.heapify(ans)
    for c in product(r, r, r, r, r):
        v = [l[i] for i in c]
        s = sum(v, [])
        if sum(s) == 0:
            continue
        t = sum(y[sum([i * j for i, j in zip(s, x)])] for x, y in zip(f, p))
        heapq.heappush(ans, -t)

    print(-1 * heapq.heappop(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N,M;
    cin >> N >> M;
    
    map<int,int> mp;
    map<int,int> mS;
    
    int p;
    string S;
    int ans1 = 0;
    int ans2 = 0;
    
    for(int i = 0; i < M;i++){
        
        cin >> p >> S;
        
        if(mS[p]==0&&S=="WA"){
            
            mp[p]++;
            
            
        }else if(mS[p]==0&&S=="AC"){
            
            //mp[p]++;
            mS[p]++;
            
            
        }
        
    }
    
    
    for(int i = 1; i <= N;i++){
        // cout << mp[i] <<" "<< mS[i] << endl;
        if(mS[i]!=0)ans1 += mp[i];
        
        ans2 += mS[i];
    }
    
    cout << ans2 << " " << ans1 << endl; 
}


Measured memory_bytes: 9600
import math

n = int(input())
li = []
total = 0
for i in range(n):
    li.append(list(map(int,input().split())))
for i in range(n):
    for j in range(i,n):
        total += math.sqrt((li[i][0] - li[j][0])**2 + (li[i][1] - li[j][1])**2)
print(total*2/n)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <math.h>
#include <iterator>
using namespace std;

int main() {
	while (true) {
		vector<int> a;
		int n;
		int P, Q, R, C;
		int t[1000] = { 0 }, p[1000] = { 0 }, q[1000] = { 0 }, r[1000] = { 0 };
		scanf("%d", &n);
		int count = 0;
		if (n == 0) goto end;
		for (int i = 0;i < n;++i) {
			scanf("%d%d%d%d", &t[i], &p[i], &q[i], &r[i]);
		}
		scanf("%d%d%d%d", &P, &Q, &R, &C);
		for (int i = 0;i < n;++i) {
			if (p[i] <= P&&q[i] <= Q&&r[i] <= R && ((p[i] * 4) + (r[i] * 4) + (q[i] * 9)) <= C) {
				printf("%d\n", t[i]);
				count++;
			}
		}
		if (count == 0) {
			printf("NA\n");
		}
	}
end:;
}


Measured memory_bytes: 1056
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x,test,out=1;
    cin>>n>>x;
    test=x;
    for(int i=1; i<n; i++)
        {
            cin>>x;
            if(test>=x)
                {
                    test=x;
                    out++;
                }
        }
    cout << out << "\n";
    return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int count = 0;
		for(int i=1; i<=N; i++) {
			int judge = 0;
			for(int j=1; j<=i; j++) {
				if(i % j == 0 && i % 2 == 1) {
					judge ++;
				}
			}if(judge == 8) {
				count ++;
			}
		}
		System.out.println(count);

	}

}


Measured memory_bytes: 21716
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                 as IM
import           Data.List
import qualified Data.Map                    as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

main = do
  [n] <- readInteger
  print $ solve n

solve n = a + b
  where
    a = (\x -> x - 1) $ foldl (\acc (_, b) -> acc * (b + 1)) 1 $ factorize (n - 1)
    b = length $ filter (== 1) $ map (f n) $ filter (/= 1) $ divisor n

f n k
  | n < k = n
  | n `mod` k == 0 = f (n `div` k) k
  | otherwise = f (n `mod` k) k

primes :: Integral a => [a]
primes = map fromIntegral primes'
  where
    primes' = [2, 3, 5] ++ f 5 7 (drop 2 primes')
    f m s (p:ps) = [n | n <- ns, gcd m n == 1] ++ f (m * p) (p * p) ps
      where
        ns = [x + y | x <- [s,s + 6 .. p * p - 2], y <- [0, 4]]

-- 素数判定 --
isPrime :: Integral a => a -> Bool
isPrime n = (n > 1) && isPrime' primes
  where
    isPrime' (x:xs)
      | x * x > n = True
      | rem n x == 0 = False
      | otherwise = isPrime' xs

-- 素因数分解
factorize :: Integral a => a -> [(a, Int)]
factorize 1 = [(1, 0)]
factorize n = format $ factorize' n primes
  where
    format ps = [(x, length xs) | xs@(x:_) <- group ps]
    factorize' n ps@(p:ps')
      | p * p > n = [n]
      | rem n p == 0 = p : factorize' (div n p) ps
      | otherwise = factorize' n ps'

-- 約数の列挙
divisor n = foldr f [] $ takeWhile ((<= n) . (^ 2)) [1 .. n]
  where
    f x ds
      | r == 0
      , q /= x = x : q : ds
      | r == 0 = x : ds
      | otherwise = ds
      where
        (q, r) = n `divMod` x


Measured memory_bytes: 7676
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}
	int rest = M - N;
	int pre;
	vi X(M);
	REP(i, M)cin >> X[i];
	so(X);
	pre = X[0];
	vi D(M - 1);
	REP(i, M - 1) {
		D[i] = abs(pre - X[i + 1]);
		pre = X[i + 1];
	}
	so(D);
	int ans = 0;
	REP(i,rest) {
		ans += D[i];
	}
	cout << ans << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 1272
import numpy as np
 
N, K = map(int, input().split())
 
def get_x(n, K):
    if n >= K:
        return 0
    else:
        x_raw = np.log2(K) - np.log2(n)
        return np.ceil(x_raw)

def get_prob(n, K):
    x = get_x(n, K)
    if x == 0:
        return 1
    else:
        return (1/2)**x
    
ans = np.mean([get_prob(n, K) for n in range(1, N+1)], dtype=np.float64)
 
print('{0:.12f}'.format(ans))

Measured memory_bytes: 14328
n=int(input())
a=[int(i) for i in input().split()]
 
enu=max(a)
 
k=(enu)/2
sa=float("inf")
 
for i in range(n):
    if abs(k-a[i])<sa and a[i]!=enu:
        sa=abs(k-a[i])
        aru=a[i]
 
print(enu,aru)

Measured memory_bytes: 14056
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i,1,sqrt(n)+1){
        if (n%i) continue;
        ll b = n/i-1;
        if (b > i){
            ans += b;
        }
    }
    PRINT(ans);
}


Measured memory_bytes: 3692
#include <iostream> 
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int a, b, c, d;
	while(cin >> a >> b >> c >> d) {
		int L = max(a, c), R = min(b, d);
		int ans = R - L;
		cout << (ans > 0 ? ans : 0) << endl;		
	}
	
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


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

    double pi=3.14159;
    double r;cin>>r;
    cout<<2*pi*r<<endl;
    return 0;
}


Measured memory_bytes: 3800
N = gets.to_i
A = gets.split.map(&:to_i)

low = 0
high = 0

ans = 1000
while A.size > 1
  loop do
    low = A.shift
    break if !A[0] || low < A[0]
  end
  break unless low && A[0]
  loop do
    high = A.shift
    break if !A[0] || A[0] < high
  end
  break unless high

  n = ans / low
  ans -= low * n
  ans += high * n
end
puts ans

Measured memory_bytes: 14364