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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  vector< int > V(N);
  cin >> V;
  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    ret += V[i] - i - 1;
  }
  cout << ret << endl;
}


Measured memory_bytes: 3368
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,now_max=-1;
	long long ans=0;
	cin>>a;
	for (int i=0;i<a;i++)
	{
		cin>>b;
		now_max=max(now_max,b);
		ans+=now_max-b;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using ll=long long;

const ll INF = pow(10,18)+1;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}
template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}
 
int main(){
    int N, X;
    cin >> N >> X;
    int L[N+10], D[N+10];
    D[0] = 0;
    REP(i,N){
        cin >> L[i];
        if (i > 0) D[i] = D[i-1] + L[i-1];
    }
    D[N] = D[N-1] + L[N-1];
    int count = 0;
    REP(i,N+1){
        if(D[i] <= X) count++;
        else break;
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;

#define REPEAT(i, N) for (int i = 0; i < (N); i++)

int main() {
  int N, ans = 0;
  
  cin >> N;
  
  vector<string> s;
  
  REPEAT(i, N) {
    string _s;
    
    cin >> _s;
    
    s.push_back(_s);
  }  
  
  sort(s.begin(), s.end());
  
  string _s = "";
  
  for (int i = 0; i < N; i++) {
    if (s[i] != _s) {
      ans++;
      _s = s[i];
    }
  }
  
  
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 11664
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=998244353;

int qpow(int x,int y){
    int ret=1;
    while(y){
        if(y&1) ret=ret*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ret;
}

int fac[1000005];
int C(int n,int m){
    if(n<m) return 0;
    return fac[n]*qpow(fac[m],MOD-2)%MOD*qpow(fac[n-m],MOD-2)%MOD;
}
int A,B,k,n;
signed main()
{
    scanf("%lld%lld%lld%lld",&n,&A,&B,&k);
    fac[0]=0;
    int ans=0; fac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%MOD;
    for(int i=0;i<=n;i++){
        int x=i;
        if((k-A*i)%B!=0||k<A*i) continue;
        int y=(k-A*i)/B;
        ans=(ans+C(n,x)*C(n,y)%MOD)%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6104
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

int Pow(int N, int P) {
	int ans = 1;
	for (int i = 0; i<P; ++i) {
		ans *= N;
	}
	return ans;
}

int main() {
	int x;
	cin >> x;
	int ans = 0;
	for (int i = 10; i >= 2; i--) {
		for (int j = 1; j <= x; j++) {
			if(Pow(j, i)<=x)ans = max(Pow(j, i), ans);
		}
	}

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

Measured memory_bytes: 256
N = int(input())
S = [int(input()) for n in range(N)]
A = sum(S)

if A%10!=0:
  ans = A
else:
  T = [s for s in S if s%10!=0]
  if len(T)==0:
    ans = 0
  else:
    ans = A-min(T)

print(ans)

Measured memory_bytes: 9068
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int N, int A, int B, int C, int X) {
    int turn = 0;
    int id = 0;
    VI Y(N);
    REP(i, N) cin >> Y[i];
    for (;turn <= 10000; turn++, X = (A * X + B) % C) {
        if (X == Y[id]) id++;
        if (id == N) {
            cout << turn << endl;
            return;
        }
    }
    cout << -1 << endl;
}

signed main(void) {
    int n, m, p, a, b, c, x;
    string s;
    while (cin >> n >> a >> b >> c >> x) {
        if (n == 0) return 0;
        solve(n, a, b, c, x);
    }
}

Measured memory_bytes: 3116
from sys import stdin
N = int(stdin.readline().rstrip())
num_list = [int(i) for i in stdin.readline().rstrip().split()]
output = 0
min_value = float("inf")
for n in range(0, N):
    now_value = num_list[n]
    if min_value > now_value:
        output += 1
        min_value = now_value
    # over_list = [i for i in num_list[:n] if i > now_value]
    # if len(over_list) == len(num_list[:n]):
    #     output += 1
print(output)

Measured memory_bytes: 25768
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;


int main(){
    int a,b,c,d; cin>>a>>b>>c>>d;
    int w = abs(a-c);
    int h = abs(d-b);
    int D = __gcd(w,h);
    cout << (w/D+h/D-1)*D << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  int i;
  i = 0;
  int c;
  c = 1;
  while(c < b)
  {
    c = a + i*(a-1);
    i++;
  }
  printf("%d",i);
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(a) (a).begin(), (a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x, 0, sizeof(x))
#define MINF(x) memset(x, 0x3f, sizeof(x))
#define MMINUS(a) memset(a, 0xff, sizeof(a))
#define ten(n) ((int)1e##n)

const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1.0 / INF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

using namespace std;

//===================================== template =========================================================

int main() {
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    ll res = 0;
    int val = (K % 2 == 0) ? K/2 : K;
    for (int a = val; a <= N; a += val) {
        ll temp = (N+a)/K - a/K;
        res += temp * temp;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using p = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止

int main(void){
    ll n;
    cin >> n;
    string ans;
    while (n){
        n--;
        ans += 'a'+n%26;
        n/=26; 
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;





int main()
{
long long N;

cin >> N;

long long A[N];

long long B[N];


for(int ix=0;ix<N;ix++){
   

    B[ix] = 0;



}



A[0] =0;

for(int i=1;i<N;i++){
    cin >> A[i];

    B[A[i]-1]++;



}


for(int j=0;j<N;j++){



   
    


     cout << B[j] << endl;
}






return 0;

}

Measured memory_bytes: 6744
import java.util.Scanner;

public class Main {

	private static Node2[] nodes;

	private static int[] degree;

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

		nodes = new Node2[n];

		degree = new int[n];

		int[] depth = new int[n];

		int[] height = new int[n];

		String[] type = new String[n];

		for (int i = 0; i < n; i++) {
			nodes[i] = new Node2(-1, -1, -1, -1);
		}

		for (int i = 0; i < n; i++) {
			int node = sc.nextInt();
			int left = sc.nextInt();
			int right = sc.nextInt();

			if (left == -1) {
				if (right == -1) {
					degree[node] = 0;
				} else {
					nodes[right].parent = node;
					nodes[node].right = right;
					degree[node] = 1;
				}
			} else {
				if (right == -1) {
					nodes[left].parent = node;
					nodes[node].left = left;
					degree[node] = 1;
				} else {
					nodes[right].parent = node;
					nodes[left].parent = node;
					nodes[right].sibling = left;
					nodes[left].sibling = right;
					nodes[node].right = right;
					nodes[node].left = left;
					degree[node] = 2;
				}
			}
		}

		for (int i = 0; i < n; i++) {
			if (nodes[i].parent == -1) {
				type[i] = "root";
			} else if (degree[i] == 0) {
				type[i] = "leaf";
			} else {
				type[i] = "internal node";
			}
		}

		for (int i = 0; i < n; i++) {
			depth[i] = setDepth(i);
		}

		for (int i = 0; i < n; i++) {
			height[i] = setHeight(i);
		}

		for (int i = 0; i < n; i++) {
			StringBuilder kari = new StringBuilder();
			kari.append("node ");
			kari.append(i);
			kari.append(": parent = ");
			kari.append(nodes[i].parent);
			kari.append(", sibling = ");
			kari.append(nodes[i].sibling);
			kari.append(", degree = ");
			kari.append(degree[i]);
			kari.append(", depth = ");
			kari.append(depth[i]);
			kari.append(", height = ");
			kari.append(height[i]);
			kari.append(", ");
			kari.append(type[i]);
			System.out.println(kari);

		}
	}

	public static int setDepth(int u) {
		if (nodes[u].parent == -1) {
			return 0;
		} else {
			return setDepth(nodes[u].parent) + 1;
		}
	}

	public static int setHeight(int u) {
		if (degree[u] == 0) {
			return 0;
		} else if (nodes[u].left == -1) {
			return setHeight(nodes[u].right) + 1;
		} else if (nodes[u].right == -1) {
			return setHeight(nodes[u].left) + 1;
		} else {
			return Math
					.max(setHeight(nodes[u].left), setHeight(nodes[u].right)) + 1;
		}
	}
}

class Node2 {
	int parent;
	int sibling;
	int left;
	int right;

	public Node2(int parent, int sibling, int left, int right) {
		super();
		this.parent = parent;
		this.sibling = sibling;
		this.left = left;
		this.right = right;
	}

}

Measured memory_bytes: 26316
A, B, C, D = list(map(int, input().split()))
if A < C:
    if B < D:
        if B < C:
            ans = 0
        else:
            ans = B-C
    else:
        ans = D-C
else:
    if B < D:
        ans = B-A
    else:
        if A < D:
            ans = D-A
        else:
            ans = 0
print(ans)


Measured memory_bytes: 2940
H, W, K = map( int, input().split())
C = [1, 1, 2, 3, 5, 8, 13, 21] #0に横棒が隣接している
Q = 10**9 + 7
dp = [[1]+[0]*(W-1) for _ in range(H+1)]
if W == 1:
    H = 0
for i in range(1,H+1):
    for j in range(W):
        if j == 0:
            dp[i][0] = (dp[i-1][0]*C[W-1] + dp[i-1][1]*C[W-2])%Q
        elif j == W-1:
            dp[i][W-1] = (dp[i-1][W-1]*C[W-1] + dp[i-1][W-2]*C[W-2])%Q
        else:
            dp[i][j] = (dp[i-1][j]*C[j]*C[W-j-1] + dp[i-1][j-1]*C[j-1]*C[W-j-1] + dp[i-1][j+1]*C[j]*C[W-j-2])%Q
print(dp[H][K-1])


Measured memory_bytes: 3064
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt

    val pattern = for {
      x <- (1 to 9)
      y <- (1 to 9)
      if (x * y == n)
    } yield (x, y)

    println(if (pattern.length > 0) "Yes" else "No")
  }
}

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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    rep(i, sz(v)) cout << v[i] << ",";
    cout << "]";
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}


int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int N, X; cin >> N >> X;
    int c = 0;
    rep(i, N) {
        int t; cin >> t; c += t;
        if (c > X) return cout << i+1 << endl, 0;
    }
    cout << N+1 << endl;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto &x : v)
        cin >> x;
    sort(v.begin(), v.end());
    cout << v[n/2] - v[n/2 - 1] << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cfenv>
#include <cmath>

using namespace std;

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

  int ans=0;
  if(a>=k)
  cout<<k<<endl;
  else if(a+b>=k)
    cout<<a<<endl;
  else 
    cout<<a - (k-a-b)<<endl;


  return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec A(M);
    REP(i,0,M) cin >> A[i];

    vec dp(N+1, INF);
    if(N == 1) {
        dp[1] = 1;
        REP(i,0,M) dp[A[i]] = 0;
    }
    else {
        dp[0] = 1;
        dp[1] = 1;
        dp[2] = 2;
        REP(i,0,M) dp[A[i]] = 0;
        REP(i,2,N+1) {
            if(dp[i] != 0) dp[i] = (dp[i-1] + dp[i-2]) % MOD;
        }
    }
    PR(dp[N]);

    return 0;
}

/*



*/

Measured memory_bytes: 4792
n = gets.to_i
s = gets.chomp
sum = 0
dif = (n-1)/2
for i in 1..dif
  for j in 0..(n-1-2*i)
    if s[j] != s[j+i] && s[j+i] != s[j+2*i] && s[j+2*i] != s[j]
      sum += 1
    end
  end
end

puts s.count("R") * s.count("G") * s.count("B") - sum

Measured memory_bytes: 14332
#include "bits/stdc++.h"
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;
 
#define REP(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define RREP(i, a, n) for(ll i = n-1; i >= (ll)(a); i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007
#define _SPLIT " "
 
template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T,class ...Args> void read(T& a, Args&... args){cin >> a; read(args...);} 
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << setprecision(24) << a << endl;}
template<class T,class ...Args> void write(T a, Args... args){cout << setprecision(24) << a << _SPLIT; write(args...);}
template<class T> void warr(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int main(void)
{
    string s;
    read(s);
    int n=s.size();
    int nn=pow(2,n-1);
    ll res=0;
    rep(i,nn){
        ll sum=s[0]-'0';
        REP(j,1,n){
            int d=s[j]-'0';
            if( ( i & ( 1 << (j-1) ) ) == 0 ){
                sum=sum*10+d;
            }
            else{
                res+=sum;
                //write(sum);
                sum=d;
            }
        }
        res+=sum;
        //write(sum);
    }
    write(res);
    return 0;
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

b_sum = 0
for i in range(M):
    b_sum += B[i]
    if b_sum > K:
        b_sum -= B[i]
        j = i - 1
        break
else:
    j = M - 1
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)


Measured memory_bytes: 40552
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}
 
using namespace std;
int main() {
	int a, b ,c,d;
	cin >> a >> b >> c >> d;
 
 
		
	while(true){
		c = c - b;
		if (c <= 0) {
			cout << "Yes" << endl;
			return 0;
		}
		a = a - d;
		if (a <= 0) {
			cout << "No" << endl;
			return 0;
		}
	}
 
 
 
 
}

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

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    ll ans = 0LL;
    rep(i, n) {
        int a;
        cin >> a;
        ans += min(a, abs(k-a))*2;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
const int INF = 1000000007;

int N,M,R;
int d[201][201];
int r[9];
int A,B,C;
int res;
bool used[9];

void dfs (int c, int las, int dist) {
    if (c == R + 1) {
        res = min(res, dist);
        return;
    }

    for (int i = 1; i <= R; i++) {
        if (!used[i]) {
            used[i] = true;
            if (las == -1) {
                dfs(c + 1, i, 0);
            } else {
                dfs(c + 1, i, dist + d[r[las]][r[i]]);
            }
            used[i] = false;
        }
    }
}

int main () {
    cin >> N >> M >> R;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (i != j) d[i][j] = INF;
        }
    }

    for (int i = 1; i <= R; i++) {
        cin >> r[i];
    }

    for (int i = 1; i <= M; i++) {
        cin >> A >> B >> C;
        if (d[A][B] > C) {
            d[A][B] = d[B][A] = C;
        }
    }

    for (int k = 1; k <= N; k++){
        for (int i = 1; i <= N; i++){
            for (int j = 1; j <= N; j++){
                if (d[i][j] > d[i][k] + d[k][j]) {
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }

    res = INF;
    dfs(1, -1, 0);
    cout << res;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int main(){
    int H, W; cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W));
    rep(i,H) rep(j,W) cin >> a[i][j];

    vector<vector<bool>> operated(H, vector<bool>(W,false));
    int ans = 0;
    rep(i,H){
        rep(j,W){
            // 一番下の段以外
            if (i != H-1){
                if (a[i][j]%2==1){
                    a[i][j]--;
                    a[i+1][j]++;
                    operated[i][j] = true;
                    ans++;
                }
            }
            // 一番下の段
            else{
                if(j != W-1){
                    if (a[i][j]%2==1){
                        a[i][j]--;
                        a[i][j+1]++;
                        operated[i][j] = true;
                        ans++;
                    }
                }
            }
        }
    }

    cout << ans << endl;
    rep(i,H){
        rep(j,W){
            if (i != H-1){
                if (operated[i][j]){
                    cout << i+1 << " " << j+1 << " " << i+2 << " " << j+1 << endl;
                }
            }
            else{
                if (operated[i][j]){
                    cout << i+1  << " " << j+1 << " " << i+1 << " " << j+2 << endl;
                }
            }
        }
    }
/*
    rep(i,H){
        rep(j,W){
            cout << a[i][j] << "";
        }
        cout << endl;
    }
*/

}

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

struct UnionFind {
    vector <ll> par;
    vector <ll> siz;

    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }

    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

int main()
{
    int N, M, K; cin >> N >> M >> K;

    UnionFind uf(N);
    vector<vector<int>> nears(N);
    int a = 0, b = 0;

    rep(i, M) {
        cin >> a >> b;
        a--; b--;
        nears[a].push_back(b);
        nears[b].push_back(a);
        uf.merge(a, b);
    }

    vector<int> ans(N);
    rep(i, N) {
        ans[i] = uf.size(i) - nears[i].size() - 1;
    }

    int c = 0, d = 0;
    rep(i, K) {
        cin >> c >> d;
        c--; d--;

        if (uf.issame(c, d)) {
            ans[c]--;
            ans[d]--;
        }
    }
    
    rep(i, N) {
        cout << ans[i];
        if (i < N - 1)
            cout << " ";
    }
    cout << endl;
}


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

int main(){
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int rn = n / r;
    int gn = n / g;
    int cnt = 0;
    for(int i = 0; i < rn + 1; i++){
        int res = n - r * i;
        if (res >= 0) {
            for (int j = 0; j < gn + 1; j++) {
                if((res - g * j) >= 0 && (res - g * j) % b == 0){
                    cnt++;
                }
                if(res - g * j < 0) break;
            }
        }
        else break;
    }
    cout << cnt << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
const int inf=1e9+7;
int n,T;
ll ans;
vector<pair<int,int> >r1,r2;
int main(){
//    freopen("in.txt","r",stdin);
    scanf("%d",&T);
    while(T--){
        ans=0;
        r1.clear(),r2.clear();
        scanf("%d",&n);
        rep(i,1,n){
            int k,l,r;
            scanf("%d%d%d",&k,&l,&r);
            if(l>r)r1.push_back(make_pair(k,l-r)),ans+=r;
            else if(l<r)r2.push_back(make_pair(n-k,r-l)),ans+=l;
            else ans+=l;
        }
        if(!r1.empty())sort(r1.begin(),r1.end());
        if(!r2.empty())sort(r2.begin(),r2.end());
        priority_queue<int,vector<int>,greater<> >q;
        for(auto v:r1){
            q.push(v.second);
            ans+=v.second;
            while(q.size()>v.first)ans-=q.top(),q.pop();
        }
        while(!q.empty())q.pop();
        for(auto v:r2){
            q.push(v.second);
            ans+=v.second;
            while(q.size()>v.first)ans-=q.top(),q.pop();
        }
        printf("%lld\n",ans);



    }

    return 0;
}

Measured memory_bytes: 5592
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static final boolean debugMode = false;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = readInt(sc);
		char[] s = sc.next().toCharArray();

		Set<Integer> r = new HashSet<>();
		Set<Integer> g = new HashSet<>();
		Set<Integer> b = new HashSet<>();

		for (int i = 0; i < n; i++) {
			if (s[i] == 'R')
				r.add(i);
			else if (s[i] == 'G')
				g.add(i);
			else
				b.add(i);
		}

		long cnt = 0;
		for (int i : r) {
			for (int j : g) {

				// lk
				int lk = 2 * j - i;
				if (lk >= 0 && lk < n && b.contains(lk)) {
					cnt++;
				}

				// rk
				int rk = 2 * i - j;
				if (rk >= 0 && rk < n && b.contains(rk)) {
					cnt++;
				}

				// sk
				if ((i + j) % 2 != 0)
					continue;

				int sk = (i + j) / 2;
				if (sk >= 0 && sk < n && b.contains(sk)) {
					cnt++;
				}
			}
		}

		long total = (long) r.size() * (long) g.size() * (long) b.size();
		System.out.println(total - cnt);

	}

//	public static void main(String[] args) {
//		Scanner sc = new Scanner(System.in);
//		int n = readInt(sc);
//		char[] s = sc.next().toCharArray();
//		
//		long cnt = 0;
//		
//		for (int i = 0; i < n; i++) {
//			for (int j = i+1; j < n; j++) {
//				if(s[i] == s[j])
//					continue;
//				
//				for (int k = j+1; k < n; k++) {
//					if(j-i == k-j)
//						continue;
//					if(s[i] == s[k]|| s[j] == s[k])
//						continue;
//					cnt++;
//				}
//			}
//		}
//		
//		System.out.println(cnt);
//		
//		
//	}

	// con.) a >= b
	static int gcd(int a, int b) {
		while (true) {
			if (b == 0)
				break;

			int mod = a % b;
			a = b;
			b = mod;
		}
		return a;
	}

	static int readInt(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	static void log(String s) {
		if (debugMode) {
			System.out.println(s);
		}
		return;
	}
}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

}

Measured memory_bytes: 46764
N = int(input())
H = list(map(int, input().split()))

tmp = 0
min = 0
for i in range(N-1):
    if H[i+1] - H[i] > 0:
        tmp = 0
    else:
        tmp -= 1

    if tmp < min:
        min = tmp

    # if N - i - 1 < -min:
    #     break

print(-min)

Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int dp[100010];
int main() {
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	memset(dp, -1, sizeof(dp));
	dp[0] = 0;
	for(int i=1; i<=k; i++) {
		rep(j,n) {
			if(i - a[j] >= 0) {
				if(dp[i-a[j]] == 0) {
					dp[i] = 1;
					break;
				}
			}
		}
		if(dp[i] == -1) dp[i] = 0;
	}
	if(dp[k] == 1) cout << "First" << endl;
	else cout << "Second" << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 5*(int)1e5 + 10;
// make sure N size is correctttt!!!!!!!!!


int n, a, b;
int32_t main(){_

   cin>>n>>a>>b;

   cout<<min(a, b)<<' '<<max(0LL, a+b-n);

   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 256
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog ender-zzm.enbar.cn
*/
#include <bits/stdc++.h>
using namespace std;

inline int Isdigit(char c) {
	if (c < '0' || c > '9') return 0;
	return 1;
}
inline int readint(){
    register int x = 0, flag = 1;
    register char ch;
    while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}

inline long long readlong() {
	register long long x = 0, flag = 1;
	register char ch;
	while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}
template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 
#define ri readint
#define rl readlong

#define int long long
const int Mod = 1e9 + 7;
const int maxn = 1010100;
const int maxm = 5040;
int n;
int a[maxn], b[maxn];
int dp[maxm][maxm];
int fac[maxn], inv[maxn];
int Pow(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = 1ll * ans * x % Mod;
		y >>= 1;
		x = 1ll * x * x % Mod;
	}
	return ans;
}
long long C(int n, int m) {
	int tmp = 1ll * fac[m] * fac[n - m] % Mod;
	tmp = Pow(tmp, Mod - 2);
	return 1ll * tmp * fac[n] % Mod;
}
signed main() {
	n = ri();
	int K = 2010;
	fac[0] = 1;
	for (int i = 1; i <= 4 * K; i++) {
		fac[i] = 1ll * fac[i - 1] * i % Mod;
	}

	inv[4 * K] = Pow(fac[4 * K], Mod - 2);
	for (int i = 4 * K - 1; i >= 0; i--) {
		inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
	}

	for (int i = 1; i <= n; i++) {
		a[i] = ri(), b[i] = ri();
		dp[-1 * a[i] + K][-1 * b[i] + K] += 1;
	}
	for (int i = 0; i <= 2 * K; i++) {
		for (int j = 0; j <= 2 * K; j++) {
			if (i - 1 >= 0) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % Mod;
			if (j - 1 >= 0) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % Mod;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		(ans += dp[a[i] + K][b[i] + K]) %= Mod;
	}
	for (int i = 1; i <= n; i++) {
		ans = (ans - C(2 * a[i] + 2 * b[i], 2 * a[i]) + Mod) % Mod;
	}
	ans = 1ll * ans * Pow(2, Mod - 2) % Mod;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 149268
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
 
		Scanner s=new Scanner(System.in);
		int a=s.nextInt();
		int b=s.nextInt();
		 
		if(a>b)System.out.print(a-1);
		else System.out.print(a);
	}
 
}

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

int main(){
  int N,K,A,B;
  cin >> N >> K >> A >> B;
  int ans = 0;
  for(int i=0; i<N; i++){
    if(i < K) ans += A;
    else ans += B;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <set>
#include <queue>
#include <map>
using namespace std;
struct p
{
    int x,y;
};
int n,m;
p pre[100][100];
char mp[100][100];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int vis[100][100];
int dp[100][100];

int bfs(){
    queue<p> q;
    p s;
    s.x = 0; s.y = 0;
    while (!q.empty())  q.pop();
    q.push(s);
    vis[0][0] = 1;
    while (!q.empty())
    {
        p fr = q.front();
        q.pop();
        if (fr.x == n - 1 && fr.y == m - 1) 
        {
            return 1;
        }
        for (int i = 0; i < 4; i++){
             int xx = dx[i] + fr.x;
             int yy = dy[i] + fr.y;
             if (xx >= 0 && xx < n && yy >= 0 && yy < m && mp[xx][yy] == '.')
             {
                    if (!vis[xx][yy])
                    {
                        p t;
                        t.x = xx;
                        t.y = yy;
                        vis[xx][yy] = 1;
                        pre[xx][yy].x = fr.x;
                        pre[xx][yy].y = fr.y;
                        q.push(t);
                    }
             } 
        }

    }
    return 0;
    
}
void get(int x,int y){
    if (x == 0 && y == 0)
    {
        return;
    }
    dp[x][y] = 1;
    get(pre[x][y].x,pre[x][y].y);
}
int main(){
    scanf("%d%d",&n,&m);
    for (int i = 0; i < n; i++){
        scanf("%s",mp[i]);
    }
    int t = bfs();
    if (!t)
    {
        printf("-1\n");
        return 0;
    }
    get(n - 1,m - 1);
    /*for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++){
            printf("%d",dp[i][j]);
        }
        printf("\n");
    }*/
    dp[0][0] = 1;
    int cnt = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (dp[i][j] == 0)
            {
                if (mp[i][j] == '.')
                {
                    cnt++;
                }
            }
        }
    }
    printf("%d\n",cnt);

}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::string s;
	std::cin >> s;
	
	int q = ri();
	for (int i = 0; i < q; i++) {
		int k = ri();
		std::deque<std::pair<int, int> > ds;
		int64_t sum = 0;
		int added = 0;
		int64_t res = 0;
		for (int j = 0; j < n; j++) {
			if (ds.size() && ds.front().second <= j - k) sum -= added + ds.front().first, ds.pop_front();
			if (s[j] == 'D') ds.push_back({-added, j});
			else if (s[j] == 'M') added++, sum += ds.size();
			else if (s[j] == 'C') res += sum;
		}
		printf("%" PRId64 "\n", res);
	}
	return 0;
}


Measured memory_bytes: 9448
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

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

int main(){
    ll N;
    cin >> N;
    deque<ll> yakusu;
    yakusu.emplace_back(N);
    for(ll i=2;i*i<=N;i++){
        if(N%i==0){
            yakusu.emplace_back(i);
            if(i*i!=N)
            yakusu.emplace_back(N/i);
        }
    ;}
    ll counter=0;
    while(yakusu.size()){
        ll k=yakusu.front();
        yakusu.pop_front();
        ll N2=N;
        while(N2%k==0){
            N2/=k;
        }
        if((N2-1)%k==0){counter++;}
    }
    ll X=1;
    for(auto x:prime_factor(N-1)){
        X*=x.second+1;
    }
    counter+=X;
    cout<<counter-1<<endl;

return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.LinkedList;

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long ans = 0;
        String S[] = new String[N];
        long s[] = new long[5];
        Arrays.fill(s, 0);
        for (int i = 0; i < N; i++) {
            S[i] = sc.next();
        }
        for (int i = 0; i < N; i++) {
            if (S[i].charAt(0) == 'M') {
                s[0]++;
            }
            if (S[i].charAt(0) == 'A') {
                s[1]++;
            }
            if (S[i].charAt(0) == 'R') {
                s[2]++;
            }
            if (S[i].charAt(0) == 'C') {
                s[3]++;
            }
            if (S[i].charAt(0) == 'H') {
                s[4]++;
            }
        }
        for (int i = 0; i < 5; i++) {
            for (int j = i + 1; j < 5; j++) {
                for (int k = j + 1; k < 5; k++) {
                    ans += s[i] * s[j] * s[k];
                }
            }
        }
        System.out.println(ans);
    }
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int h, w;
char s[405][405];
int d[405][405];
int num;
int bla, whi;

void go(int i, int j) {
    if (s[i][j] == '#') ++bla;
    else ++whi;
    d[i][j] = num;
    if (i > 0 && d[i - 1][j] == -1 && s[i - 1][j] != s[i][j]) {
        go(i - 1, j);
    }
    if (j > 0 && d[i][j - 1] == -1 && s[i][j - 1] != s[i][j]) {
        go(i, j - 1);
    }
    if (i < h - 1 && d[i + 1][j] == -1 && s[i + 1][j] != s[i][j]) {
        go(i + 1, j);
    }
    if (j < w - 1 && d[i][j + 1] == -1 && s[i][j + 1] != s[i][j]) {
        go(i, j + 1);
    }
}

int main() {
    scanf("%d%d", &h, &w);
    forn(i, h) scanf("%s", s[i]);
    memset(d, -1, sizeof d);
    num = 0;
    LL ans = 0;
    forn(i, h) forn(j, w) {
        if (d[i][j] == -1) {
            bla = 0;
            whi = 0;
            go(i, j);
            ++num;
            ans += (LL)bla * whi;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){

    
    ll n;
    while(cin>>n){
        ll ans=0;
       /* ll j=1;
        for(int i=n*j;n*j<=600-n;i=n*j){
            ans+=pow(j*n,2)*n;
            j++;
        }
        
        cout<<ans<<endl;
        
        
        }*/
        ll j=1;
        ll fd=j*n;
        while(true){
            if(fd==600)break;
            ans+=pow(fd,2)*n;
            j++;
            fd=j*n;
            
            
        }
        cout<<ans<<endl;
    }
    
    
    
    return 0;
}



Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define MOD (long int)10e9 + 7
#define LD long double


int main(){
    int k;
    cin >> k;
    string s;
    cin >> s;


    cout << (s.size() <= k ? s : s.substr(0,k) + "...") << endl;
    return 0;
}

Measured memory_bytes: 3632
import sys
from itertools import permutations

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *PQ = map(int, read().split())
    P = tuple(PQ[:N])
    Q = tuple(PQ[N:])

    perm = tuple(permutations(range(1, N + 1)))
    print(abs(perm.index(P) - perm.index(Q)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 71332
#include <bits/stdc++.h>
using namespace std;
string rev(string S){
  reverse(S.begin(), S.end());
  return S;
}
int main(){
  int m;
  cin >> m;
  for (int i = 0; i < m; i++){
    string S;
    cin >> S;
    int N = S.size();
    set<string> st;
    for (int j = 1; j < N; j++){
      string s1 = S.substr(0, j);
      string s2 = S.substr(j);
      st.insert(s1 + s2);
      st.insert(s2 + s1);
      st.insert(rev(s1) + s2);
      st.insert(s2 + rev(s1));
      st.insert(s1 + rev(s2));
      st.insert(rev(s2) + s1);
      st.insert(rev(s1) + rev(s2));
      st.insert(rev(s2) + rev(s1));
    }
    cout << st.size() << endl;
  }
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
int r, c, n, x, y, t[2], st[200005], u;
vector<P> v;
inline int trans(int x, int y){
	return y ? y-c ? x ? x-r ? -1 : r+y : r*2+c*2-y : r*2+c-x : x;
}
int main(){
	scanf("%d%d%d", &r, &c, &n);
	rep(i,n){
		rep(j,2){
			scanf("%d%d", &x, &y);
			t[j] = trans(x,y);
		}
		if(t[0] == -1 || t[1] == -1) continue;
		v.push_back(P(t[0],i));
		v.push_back(P(t[1],i));
	}
	sort(v.begin(), v.end());
	for(auto it: v){
		if(u && st[u-1] == it.second) u--;
		else st[u++] = it.second;
	}
	puts(u ? "NO" : "YES");
}

Measured memory_bytes: 2420
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N = d_in()

happiness = [0] * 3
for _ in range(N):
    today = ds_in()
    pre = happiness.copy()
    happiness[0] = max(pre[1], pre[2]) + today[0]
    happiness[1] = max(pre[0], pre[2]) + today[1]
    happiness[2] = max(pre[1], pre[0]) + today[2]

print(max(happiness))


Measured memory_bytes: 3064