akhauriyash/Code-Regression huggingface dataset:
//
// B - Training Camp
//

#include <iostream>
#include <cmath>

using namespace std;
using LL = long long;

const LL MOD = 1000000007L;

bool *primeB(bool *p, int n) {

    int n_ = (int) sqrt(n) + 1;

    fill(p, p + n + 1, true);
    p[0] = false;
    if (n >= 1) p[1] = false;

    for (int i = 2; i <= n_; ++i) {
        if (p[i]) {
            for (int j = i + i; j <= n; j += i) {
                if (p[j]) p[j] = false;
            }
        }
    }

    return p;
}

template<typename T>
T power(T x, T n, T mod) {
    if (n == 0) return 1;
    long ret = power(x * x % mod, n / 2, mod);
    if (n & 1) ret = ret * x % mod;
    return ret;
}

int main() {

    int N;
    cin >> N;

    bool primes[N + 1];
    int factors[N + 1];

    primeB(primes, N);
    fill(factors, factors + N + 1, 0);

    for (int i = 2; i <= N; i++) {
        if (primes[i]) {
            for (int j = i; j <= N; j *= i) {
                factors[i] += N / j;
            }
        }
    }

    LL ans = 1;

    for (int i = 2; i <= N; i++) {
        if (factors[i]) {
            ans *= power((LL) i, (LL) factors[i], MOD);
            ans %= MOD;
        }
    }

    cout << ans << endl;
}

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


int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for( int i = 0; i < N; ++i ) cin >> a[i];


    vector<int> numSushi(4);
    int total = 0;
    for( int i = 0; i < N; ++i ){
        ++numSushi[a[i]];
        total += a[i];
    }
    // dp[i][j][k]: 寿司が1個, 2個, 3個の皿が i枚, j枚, k枚のとき、全ての寿司を食べるのに必要な操作回数の期待値
    double dp[301][301][301] = {};
    for( int k = 0; k <= N; ++k ){
        for( int j = 0; j <= N; ++j ){
            for( int i = 0; i <= N; ++i ){
                if( 0 < i+j+k and i+j+k <= N ){
                    if( i != 0 ) dp[i][j][k] += dp[i-1][j][k] * i;
                    if( j != 0 ) dp[i][j][k] += dp[i+1][j-1][k] * j;
                    if( k != 0 ) dp[i][j][k] += dp[i][j+1][k-1] * k;
                    dp[i][j][k] = (dp[i][j][k] + N) / (i+j+k);
                }
            }
        }
    }
    cout << fixed << setprecision(9) << dp[numSushi[1]][numSushi[2]][numSushi[3]] << endl;

    return 0;
}

Measured memory_bytes: 213376
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


int main() {
	int A, B, M;
	cin >> A >> B >> M;
	vector<int> a(A), b(B);
	vector<int> x(M), y(M), c(M);
	rep(i, A) cin >> a[i];
	rep(i, B) cin >> b[i];
	rep(i, M) {
		int X, Y;
		cin >> X >> Y >> c[i];
		x[i] = X-1;
		y[i] = Y-1;
	}
	int res = INF;
	rep(i, M) {
		res = min(res, a[x[i]] + b[y[i]] - c[i]);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	res = min(res, a[0] + b[0]);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    string s; cin >> s;
    int c = 0;
    int ans = 0;
    rep(i, 3) {
        if(s[i] == 'R') c++;
        else if(s[i] == 'S') c = 0;
        chmax(ans, c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=100005;
int n,m,a[N],s[N],v[N],k,ans,l,r,sz;
signed main()
{
	cin>>n>>a[1]>>m;
	s[1]=a[1];
	for(k=2;;k++)
	{
		a[k]=a[k-1]*a[k-1]%m;
		if(v[a[k]])
		{
			l=v[a[k]];
			r=k-1;
			sz=r-l+1;
			break;
		}
		s[k]=s[k-1]+a[k];
		v[a[k]]=k;
	}
	if(n<=l)
	{
		cout<<s[n]<<endl;
		return 0;
	}
	ans+=s[l-1];
	n-=l-1;
	ans+=n/sz*(s[r]-s[l-1]);
	ans+=s[l+n%sz-1]-s[l-1];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5152
def f(n):
    res = 0
    s = 0
    for i in range(1,n+1):
        s += i
        if s <=n:
            res = i
        else:
            break
    return res
n = int(input())
p =2
ans = 0
while p*p <= n:
    e = 0
    while n%p == 0:
        e += 1
        n//=p
    ans += f(e)
    p +=1
if n >1:
    ans += 1
print(ans)

Measured memory_bytes: 9220
# Z-Algorithm
#############################################################
def z_algo(s):
    n = len(s)
    z = [0] * n
    z[0] = n
    i, j = 1, 0
    while i < n:
        while i + j < n and s[j] == s[i + j]:
            j += 1
        z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < n and k + z[k] < j:
            z[i + k] = z[k]
            k += 1
        i += k
        j -= k
    return z
#############################################################

N = int(input())
S = input()

ans = 0
for i in range(N):
    z = z_algo(S[i:])
    # j = 0,1,...,N-i-1
    # zのindexは0,1,...,N-i-1
    for j in range(N - i):
        # z[j]>jの時、部分文字列が重なってしまう
        if z[j] <= j:
            ans = max(ans, z[j])

print(ans)


Measured memory_bytes: 79440
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	llong h;
	cin>>h;
	
	llong ans=0;
	llong now=1;
	while(h>0){
		ans+=now;
		h/=2;
		now*=2;
	}
	
	cout<<ans<<endl;
}

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

int main() {
  int n, Rt;
  int maxv = -2e9;
  int minv = 2e9;

  cin >> n;

  for ( int i = 0; i < n; i++ ) {
    cin >> Rt;
    maxv = max(maxv, Rt - minv);
    minv = min(minv, Rt);
  }

  cout << maxv << endl;

  return 0;
}


Measured memory_bytes: 3116
N = int(input())
xl = []
for i in range(N):
    tmp = list(map(int, input().split()))
    if tmp[0] - tmp[1] < 0:
        xl.append((tmp[0] + tmp[1], 0))
    else:
        # 終了範囲，開始範囲
        xl.append((tmp[0] + tmp[1], tmp[0] - tmp[1]))
        
xl_sorted = sorted(xl, key=lambda x: x[0])
#print(xl_sorted)
ans = 0
t = 0
# tは前のロボットの後ろの範囲
for i in range(N):
    if t <= xl_sorted[i][1]:
        ans += 1
        t = xl_sorted[i][0]
print(ans)

Measured memory_bytes: 19096
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ta,tb,tc;
    
    vector<string> vs;
    vs.push_back("1");
    vs.push_back("2");
    vs.push_back("3");

    string str = "123";
    int k;
    cin >> k;

    rep(i,k-1){
        vector<string> vs2;
        for(auto e: vs){
            rep(j,3){
                vs2.push_back(e+str[j]);
            }
        }
        vs.clear();
        for(auto e: vs2){
            vs.push_back(e);
        }
    }

    for(auto e:vs){
        ta = a;
        tb = b;
        tc = c;
        //cout << e << endl;
        rep(i,k){
            if(e[i] == '1'){
                ta *= 2;
            }else if(e[i] == '2'){
                tb *= 2;
            }else{
                tc *= 2;
            }
        }
        if(ta < tb && tb < tc){
            cout <<"Yes" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 3736
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),k=sc.nextLong();
    if(Math.abs(a-b)>1000000000000000000L) {
    	System.out.println("Unfair");
    }else {
    	if(k%2==0) {
    		System.out.println(a-b);
    	}else {
    		System.out.println(b-a);
    	}
    }
  }
}


Measured memory_bytes: 21460
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#l=deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え
#start 4:00
N = int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]



A = list(map(int, input().split()))
edge = [[] for i in range(N)]
for i in range(N-1):
    x,y = map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)


#始点sから各頂点への最短距離
inf=10**10
dp = [inf]*N
visited=[False]*N
q=[]
q=deque(q)
ans=[0]*N

def dfs(e):
    visited[e]=True
    a=A[e]
    ci=bisect_left(dp,a)
    q.append((ci,dp[ci]))
    dp[ci]=a
    ans[e]=bisect_left(dp,inf)
    #print(edge[e])
    for ne in edge[e]:
        if not visited[ne]:
            dfs(ne)
            pi,px=q.pop()
            dp[pi]=px


dfs(0)
    #print(d)
    
for x in ans:
    print(x)
#print(d[4])



Measured memory_bytes: 380336
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b):return (a + b - 1) // b


def solve(S):
    S = list(S)
    S[3] = "8"
    return "".join(S)


def main():
    S = input()
    print(solve(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
import itertools, copy

n = input().split()

ans = 0
for p0, p1 in itertools.permutations(n, 2):
    n_ = copy.copy(n)
    n_.remove(p0)
    n_.remove(p1)
    
    total = int(''.join([p0, p1])) + int(n_[0])
    ans = max(ans, total)

print(ans)

Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

int n, m;
int height[N];
int maxHeight[N];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%d", &height[i]);
    for (int i = 1; i <= m; ++i) {
        int u, v;
        scanf("%d %d", &u, &v);
        maxHeight[u] = max(maxHeight[u], height[v]);
        maxHeight[v] = max(maxHeight[v], height[u]);
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        if (height[i] > maxHeight[i]) ++cnt;
    }
    printf("%d\n", cnt);
}

Measured memory_bytes: 4504
H, W = map(int, raw_input().split())
dungeon = []
memo = []
whitecount = 0
for i in range(0, H):
	dlst = []
	nlst = []
	s = raw_input()
	for j in range(0, W):
		if s[j] == '.': whitecount += 1
		dlst.append(s[j]=='.')
		nlst.append(H*W+1)
	dungeon.append(dlst)
	memo.append(nlst)
max = -1
queue = [[0, 0, 1]]
while queue != []:
	now = queue.pop(0)
	if now[2] < memo[now[0]][now[1]] and dungeon[now[0]][now[1]]:
		memo[now[0]][now[1]] = now[2]
		for i in range(0, 2):
			nexth = now[0] - 1 + 2*i
			nextw = now[1] - 1 + 2*i
			if 0 <= nexth and nexth < H:
				queue.append([nexth, now[1], now[2]+1])
			if 0 <= nextw and nextw < W:
				queue.append([now[0], nextw, now[2]+1])
if max < whitecount - memo[H-1][W-1]:
	max = whitecount-memo[H-1][W-1]
print max

Measured memory_bytes: 2820
import sys

sys.setrecursionlimit(10**9)
nCr = {}
def comb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = comb(n-1,r) + comb(n-1,r-1)
    return nCr[(n,r)]

def count(q):
    res = 0
    if q >= 1:
        res += comb(q, 1) * comb(3, 3)
    if q >= 2:
        res += comb(q, 2) * comb(2, 1) * comb(3, 2)
    if q >= 3:
        res += comb(q, 3) * comb(3, 1) * comb(2, 1)
    return res

n, k = map(int, sys.stdin.readline().split())

def main():
    cnt1 = n // k
    res = count(cnt1)
    if k & 1:
        return res
    else:
        if n - k * cnt1 < k // 2:
            res *= 2
        else:
            cnt2 = cnt1 + 1
            res += count(cnt2)
        return res

if __name__ == '__main__':
    ans = main()
    print(ans)

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

int main() {
  int N, a, b;
  cin >> N;
  long long Y;
  cin >> Y;
  Y = Y / 1000;
  bool bb = false;
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= N-i; j++) {
      if(9*i + 4*j + N == Y) {
        bb = true;
        a = i;
        b = j;
        break;
      }
    }
  }
  if(bb) {
    cout << a << " " << b << " " << (N-a-b) << endl;
  }
  else {
    cout << "-1 -1 -1" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>                   
#include<string>                      
using namespace std;                  
int main(void){                       
  string s;                           
  cin >> s;                           
  int n = s.size(),ans = 0;           
  int num0 = 0,num1 = 0;              
  for(int i = 0; i < n;++i){          
    if(s[i] == '0') num0++;           
    else  num1++;                     
  }                                   
  if(num0 > num1) ans = 2*num1;       
  else ans = 2 *num0;                 
  cout << ans << endl;                
  return 0;                           
}                                     
                                      
                                      

Measured memory_bytes: 512
import math

n = int(input())
a = [0]
mod = 998244353
p = pow(3, n, mod)

for i in range(0, n):
    a.append(int(input()))

s = sum(a)
hs = math.ceil(s / 2)
dp = [[0 for j in range(0, s + 1)] for i in range(0, n + 1)]
dp[0][0] = 1

for i in range(1, n + 1):
    for j in range(0, s + 1):
        dp[i][j] = (2 * dp[i - 1][j] + (0 if j - a[i] < 0 else dp[i - 1][j - a[i]])) % mod

p = (p - 3 * sum(dp[n][hs:])) % mod

if s % 2 == 0:
    for i in range(1, n + 1):
        for j in range(0, s // 2 + 1):
            dp[i][j] = (dp[i - 1][j] + (0 if j - a[i] < 0 else dp[i - 1][j - a[i]])) % mod

    p = (p + 3 * dp[n][hs]) % mod

print(p)

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

int main(){
  char s[10];
  
  for(int i=0; i<10; i++){
    cin >> s[i];
  }
  
  if(s[5]!='1'){
    if(s[6]=='1'||s[6]=='2'||s[6]=='3'||s[6]=='4'){
      cout << "Heisei";
    }
    else{
      cout << "TBD";
    }
  }
  else{
    cout << "TBD";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define N 1000
int n,ans=1;
int dp[N+5];
using namespace std;
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        int num=i;
        for(int j=2;j*j<=i;j++) {
            int ok=0;
            while(num%j==0) ok++,num/=j;
            dp[j]+=ok;
        }
        if(num>1) dp[num]++;
    }
    for(int i=1;i<=N;i++) {
        ans=1ll*ans*(dp[i]+1)%MOD;
    }
    cout<<ans;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]


def solve():
    s = input()
    w = set()
    for e in s:
        if e in w:
            print('no')
            return
        w.add(e)
    print("yes")

        
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()



"""

1 4
7
RRRR
1 1 0 1
----
4

1 4
47
RCRR
1 1 0 1
----
-1

2 2
10
RR
RR
1 7
4 1
----
4

2 2
10
RR
RR
7 4
7 4
----
-1

3 3
8
RCR
RRC
RRR
1 1 1
1 1 1
1 3 1


3 3
1
RCR
RRC
RRR
1 1 1
1 1 1
1 3 1


"""





Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	long long N;
	cin >> N;

	long long result = 0;
	for (int i = 1; i <= N; i++)
	{
		long long k = N / i;
		long long val = (k * (k + 1) * i) / 2;
		result += val;
	}

	cout << result;
	
	return 0;
}


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

int main() {
  int h, w;
  std::cin >> h >> w;
  std::vector<std::string> s(h);

  for (auto &i : s) {
    std::cin >> i;
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        int n = 0;
        for (int k = i - 1; k <= i + 1; k++) {
          for (int l = j - 1; l <= j + 1; l++) {
            if (0 <= k && k < h && 0 <= l && l < w && s[k][l] == '#') {
              n++;
            }
          }
        }
        s[i][j] = std::to_string(n)[0];
      }
    }
  }

  for (const auto &i : s) {
    std::cout << i << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iomanip>

using namespace std;

char s[200000];

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%s",s);
	int i,j,k1=0,k2=0,n = strlen(s);
	char c='0';
	for(int i=0;i<n;i++){
		if(s[i]!=c)k1++;
		if(c=='0')c='1';
		else c = '0';
	}
	c='1';
	for(int i=0;i<n;i++){
		if(s[i]!=c)k2++;
		if(c=='0')c='1';
		else c = '0';
	}
	cout<<min(k1,k2)<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main()
{
    long long ans=0,sum=0;
    int n;scanf("%d",&n);
    while(n--)
    {
        int x;scanf("%d",&x);
        ans+=sum*x%mod;sum+=x;sum%=mod;
    }
    printf("%lld\n",ans%mod);
}


Measured memory_bytes: 3764
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const double INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

// 最大公約数（ユークリッドの互除法による）
ll gcd(ll n, ll m) {
	if (n > m) {
		ll l = n;
		n = m;
		m = l;
	}
	while (1) {
		ll l = n;
		n = m % n;
		m = l;
		if (n == 0) {
			break;
		}
	}
	return m;
}

ll subans(ll A, ll B, ll X) {
	ll a = (A / X) * X + X;
	if (A % X == 0) {
		a -= X;
	}
	ll b = (B / X) * X;
	ll ans = (b - a) / X + 1;
	return ans;
}

int main() {
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << (B - A + 1) - subans(A, B, C) - subans(A, B, D) + subans(A, B, C * D / gcd(C, D)) << endl;
	return 0;
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int div = n / 3;
    cout << div << endl;

    return 0;
}


Measured memory_bytes: 256
s = ""
try:
	while True:
		t = input()
		if t == "":
			break
		s += t
except EOFError:
	pass

s = str.lower("".join(s))

al_list = [chr(i) for i in range(97,97+26)]
ans = []

for i in range(len(s)):
    ans.append(s[i:i+1])

for i in range(26):
    if al_list[i] in ans:
        x = ans.count(al_list[i])
        print(al_list[i], ":", x)
    else:
        print(al_list[i], ":", 0)



Measured memory_bytes: 5584
#include<stdio.h>

int main(){
	int n,m,d,x,y,i;
	
	for( ; scanf("%d",&n) , n ; puts(n?"No":"Yes") ){
		int f[21][21] = {0};
		
		for( i=n ; i-- ; ){
			scanf("%d %d",&x,&y);
			f[y][x] = 1;
		}
		scanf("%d",&m);
		x=y=10;
		for( i=m ; i-- ; ){
			scanf(" %c %d",&m,&d);
			for( ; d-- ; ){
				x += (m=='E')? 1 : (m=='W')? -1 : 0;
				y += (m=='N')? 1 : (m=='S')? -1 : 0;
				if( f[y][x] ){
					n--;
					f[y][x] = 0;
				}
			}
		}
	}
}

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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  int i, j;
  int mini;
  int h = 0;
  for(i = 0; i < n; i++)
  {
    if(s.at(i)!= '#')
    {
      h++;
    }
  }
  mini = h;
  for(i = 0; i < n; i++)
  {
    if(s.at(i) == '.')
    {
      h--;
    }
    else
    {
      h++;
    }
    if(h < mini)
    {
      mini = h;
    }
  }
  cout << mini << endl;
}


Measured memory_bytes: 640
n = int(input())
ns = list(map(int, input().split()))
cnt = 0
for i in range(n-1):
    if i+1 == ns[i]:
        ns[i], ns[i+1] = ns[i+1], ns[i]
        cnt += 1
if ns[-1] == n:
    cnt += 1
print(cnt)


Measured memory_bytes: 14008
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	static int COUNT = 0;

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] input = br.readLine().split(" ");

		for(int i = 0; i < n; i++){
			a[i] = Integer.parseInt(input[i]);
		}

		a = bubbleSort(a, n);

		for(int i = 0; i < n; i++){
			
			System.out.print(a[i]);

			if(i != (n - 1)){
				System.out.print(" ");
			}else{
				System.out.print("\n");
			}

		}

		System.out.println(COUNT);

	}

	static int[] bubbleSort(int[] a, int n){

		for(int j = 0; j < (n - 1); j++){
			for(int i = (n - 1); i > 0; i--){

				if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			}
		}

		return a;

	}

}

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

int main() {
  int a,b,a1,b1,c,d;
  cin>>a>>b;
  int k=0;
  for(int i=a;i<b+1;i++){
    a1=i%10;
    b1=(i/10)%10;
    c=(i/1000)%10;
    d=(i/10000)%10;
    if(a1==d&&b1==c)k++;
  }
  cout<<k<<endl;
}


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

int f(int k){
	int r=7%k, i=1;
	set<int> s;
	while(s.find(r) == s.end()){
		if(!r) return i;
		i++;
		s.insert(r);
		r = (r*10 + 7) % k;
	}
	return -1;
}

int main(){
	int k; cin>>k;
	cout<< f(k) <<endl;
}


Measured memory_bytes: 50468
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var d = new Dictionary<char, int>();
        var c = new char[] { 'M', 'A', 'R', 'C', 'H' };
        var c2 = new string[] { "RCH", "ACH", "ARH", "ARC", "MCH", "MRH", "MRC", "MAH", "MAC", "MAR" };
        foreach (var x in c) d[x] = 0;
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim();
            if (d.ContainsKey(s[0])) d[s[0]]++;
        }
        var ans = 0L;
        for (int i = 0; i < 10; i++)
        {
            var ret = 1L;
            for (int j = 0; j < 3; j++)
                ret *= d[c2[i][j]];
            ans += ret;
        }
        Console.WriteLine(ans);
    }
}

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

using namespace std;

int main(){
	int m,n;
	scanf("%d%d",&m,&n);
	
	if(m*10000<n){
		printf("-1 -1 -1");
		return 0;
	}
	if(m*1000>n){
		printf("-1 -1 -1");
		return 0;
	}
	if(n%1000!=0){
		printf("-1 -1 -1");
		return 0;
	}
	for(int i=0;i<=m;i++)
	 for(int j=0;j<=m;j++)
	  for(int k=0;k<=m,i+j+k<=m;k++)
	   {
	   		if(i+j+k==m && i*1000+j*5000+k*10000==n)
	   		{
	   			printf("%d %d %d",k,j,i);
				return 0;	
			}
	   }
	printf("-1 -1 -1");
	return 0;
}

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

typedef long long int llint;

int main()
{
  int n;
  int c[501], s[501], f[501];

  cin>> n;
  for(int i = 0; i < n - 1; i++) {
    cin>> c[i] >> s[i] >> f[i];
  }

  for(int i= 0; i < n; i++) {
    
    int t = 0;
    for(int j = i; j < n - 1; j++) {
      if(t < s[j]) {
	     t = s[j];
      } else if(t % f[j] != 0) {
	     t = (t / f[j] + 1) * f[j];
      }
      t += c[j];
    }

    cout<< t <<endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader stdln = new BufferedReader(new InputStreamReader(System.in));
        int[] count= new int[26];
        String st;
        
        while((st=stdln.readLine())!=null){
        for(char c:st.toCharArray()){
            c|=0x20;
            if(c>='a'&&c<='z')count[c-'a']++;
            }
        }
        for(int i=0;i<26;i++){
        System.out.printf("%c : %d\n",'a'+i,count[i]);
        }
    }
}


Measured memory_bytes: 24592
from sys import exit
s = input()
if "N" in s:
    if "S" not in s:
        exit(print("No"))
if "S" in s:
    if "N" not in s:
        exit(print("No"))
if "W" in s:
    if "E" not in s:
        exit(print("No"))
if "E" in s:
    if "W" not in s:
        exit(print("No"))
print("Yes")

Measured memory_bytes: 9024
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const ll inf = (ll)1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i, j, k;
    float b;
    ll a, c;
    cin >> a >> b;
    c = 100 * b;
    cout << (a * c / (ll)100);
    return 0;
}
//664706138336385 9.79

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

typedef long long ll;

int main()
{
    int n, a[11000], b[11000];
    ll one = 0, two = 0;

    cin >> n;
    REP(i, n)
    cin >> a[i];

    REP(i, n)
    {
        cin >> b[i];

        if (a[i] > b[i])
            one += a[i] - b[i];
        if (a[i] < b[i])
        {
            two += (b[i] - a[i] + 2 - 1) / 2;
            one += (b[i] - a[i]) % 2;
        }
    }

    bool res = false;

    if (two >= one)
        res = true;

    cout << (res ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int score[] = new int[5];
		int average = 0;
		for(int i=0;i<5;i++){
			score[i] = sc.nextInt();
			if(score[i]<40) score[i] = 40;
			average += score[i];
		}
		average /= 5;
		System.out.println(average);
	}

}

Measured memory_bytes: 25948
w,h,n = map(int,input().split())
w0 = 0
h0 = 0

for _ in range(n):
    x,y,a = map(int,input().split())

    if a == 1:
        w0 = max(w0,x)
    
    if a == 2:
        w  = min(w,x)

    if a == 3:
        h0 = max(h0,y)
    
    if a == 4:
        h  = min(h,y)

print(max(0,w-w0)*max(0,h-h0))  

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

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i=0; i<N; ++i) cin >> H[i];
    --H[0];
    for(int i=1; i<N; ++i) {
        if(H[i - 1] > H[i]) {
            cout << "No" << endl;
            return 0;
        } else if(H[i - 1] < H[i]) {
            --H[i];
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	int n;cin>>n;
	int ans=0;
	rep(i,pow(4,9)){
		int c[]={0,0,0,0},b=1,m=0,t=i;
		do{
			c[t%4]++;
			if(t%4==1) m+=3*b;
			else if(t%4==2) m+=5*b;
			else if(t%4==3) m+=7*b;
			else {m=0;break;}
			t/=4;
			b*=10;
		}while(t>0);
//		cout<<i<<' '<<m<<endl;
		if(m>n) break;
		if(c[0]==0&&c[1]>0&&c[2]>0&&c[3]>0) ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(long long i=0;i<(n);i++)
#define ll long long
using namespace std;
int main(){
    ll L,N,T;
    cin >> N >> L >> T;
    vector<ll> X(N);
    vector<int> W(N);
    rep(i,N) cin >> X[i] >> W[i];
    vector<ll> tmp(N); ll count = 0;
    rep(i,N){
        ll d = (W[i] == 1) ? (X[i] + T) : (X[i] - T)%L + L;
        d %= L; 
        tmp[i] = d;
    }
    /*
    rep(i,N){
        ll d = (W[i] == 1) ? (X[i] + T) : (X[i] - T);
        if(W[i] == 1) count += d/L; 
        else {if(d < 0) count += -1 + d/L;};
    }
    count = (count % N + N)%N;
*/    
    for (int i = 0; i < N; ++i) {
        if (W[i] == 1) count -= (T - (L - X[i]) + L) / L;
        else count += (T - (X[i] + 1) + L) / L;
    }
    
    sort(tmp.begin(), tmp.end());
    count = (count % N + N) % N;
    //cout << "count = " << count << endl;
    vector<long long> res(N);
    for (int i = 0; i < N; ++i) res[(i+count)%N] = tmp[i];
    for (int i = 0; i < N; ++i) cout << res[i] << endl;
    //for (int i = 0; i < N; ++i) cout << tmp[(i+count)%N] << endl;

    return 0;
}

Measured memory_bytes: 3968
/***************************************** START OF TEMPLATE *********************************************/

#include<bits/stdc++.h>

using namespace std;

#define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  newl           cout<<"\n";
#define  f              first
#define  s              second
#define  pb             push_back
#define  mp             make_pair
#define  sym(s)         s="#"+s+"#";   
#define  all(x)         (x).begin(),(x).end()
#define  alll(x, n)     x+1, x+n+1
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  mset1d(a,n,v)  foo(i,0,n+5)a[i]=v;
#define  mset2d(a,n,m,v)foo(i,0,n+5)foo(j,0,m+5)a[i][j]=v;
#define  INP(a,n)       foo(i,1,n) cin>>a[i];
#define  deb1d(a,n)     foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)   foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}    
#define  debm(a)        for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  debp(a,n)      foo(i,1,n)cout<<"{"<<a[i].f<<","<<a[i].s<<"}, ";newl;
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<" ";newl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" ";newl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" ";newl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d;newl;
#define  ll             long long
#define  ld             long double
#define  pll            pair<ll,ll>
#define  vll            vector<ll>
#define  vpll           vector<pll>

const ld   PI    =  3.14159265358979323846; 
const ll   MOD   =  1e+9+7;
const ll   INF   =  LLONG_MAX;
const int  INFi  =  INT_MAX;
const ll   N     =  1e+6+8;

vll adj[N]; ll vis[N];
ll dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

ll test_cases = 1; randomINIT;

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ll n, x, a[N];


/***************************************** FUNCTION IMPLEMENTATIONS **************************************/



/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN(ll tc){
    cin>>n;
    foo(i,1,n){
        cin>>a[i];  
        vis[a[i]]++;
    }   

    ll res = 0;
    foo(i,1,n){ 
        ll ok = 1;
        vis[a[i]]--;
        for(ll j=1; j*j<=a[i]; j++){
            if(a[i]%j==0){
                if(vis[j]>0 || vis[a[i]/j]>0){
                    ok=0;
                    break;
                }
            }
        }
        vis[a[i]]++;
        res+=ok;
    }

    cout<<res;

}

int main(){
    SPEED;

    //cin>>test_cases;
    foo(i,1,test_cases){
        MAIN(i);
    }
}

Measured memory_bytes: 36336
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}


Measured memory_bytes: 3624
N = int(input())
A = list(map(int,input().split(' ')))

def divisors2_count(n):
  num = 0
  while n % 2 == 0:
    num += 1
    n = int(n/2)
  return num

ans = 0
for x in A:
  ans += divisors2_count(x)

print(ans)
    

Measured memory_bytes: 4148
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(System.in);
		int k = parseInt(sc.next());
		int x = parseInt(sc.next());
		sc.close();
		int s = Math.max(x-k+1, -1000000);
		int e = Math.min(x+k-1, 1000000);
		for (i = s; i <= e; i++) {
			out.print(i);
			out.print(" ");
		}
	}
}


Measured memory_bytes: 21716
#pragma region head
    #include <bits/stdc++.h>
    #include <atcoder/all>
    using namespace std;
    using namespace atcoder;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main(){
    int n, q; cin >> n >> q;
    dsu d(n);
    while(q--){
        int t, u, v;cin >> t >> u >> v;
        if(t){
            cout << d.same(u,v) << '\n';
            
        } else {
            d.merge(u,v);
        }
    }
}

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

int main() {
  int N;
  cin >> N; //ひなあられの個数
  int count;
  count = 0;
  
  for (int i = 0; i < N; i++) {
    char s;
    cin >> s;
    if (s == 'Y') {
      count += 1;
    }
  }
  
  if (count == 0) {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
}
    

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ll n,k;
  cin >> n >>k;
  pair<ll, ll> ab[n];
  ll a,b;
  ll sum[n+1];
  rep(i,n){
    cin >> a >> b;
    ab[i]=mp(a,b);
  }
  sort(ab,ab+n);
  sum[0]=0;
  rep1(i,n){
    sum[i]=sum[i-1]+ab[i-1].second;
  }
  ll ind = lower_bound(sum,sum+n+1,k)- sum;
  cout <<ab[ind-1].first << endl;
  

  

  return 0;

}


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

vector<int> x;

vector<int> yakusu(int n){
  vector<int> p;
  for(int i = 1;i*i <= n;i++){
      if(n % i == 0){
      p.push_back(i);
      if(i*i != n){
        p.push_back(n/i);
      }
    }
  }
  return p;
}

int main(){
  int n,m;
  cin >> n >> m;
  x = yakusu(m);
  int result = 0;
  for(int i = 0;i < x.size();i++){
    if(m / x.at(i) >= n){
      result = max(result,x.at(i));
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner scanner = new Scanner(System.in);
    int ballNum = scanner.nextInt();
    int ballTypeCount = scanner.nextInt();

    Map<Integer, Integer> bMap = new HashMap<Integer, Integer>();

    for (int i = 0; i < ballNum; i++) {
      int num = scanner.nextInt();
      Integer o = bMap.get(num);
      if (o != null) {
        o++;
      } else {
        o = 1;
      }
      bMap.put(num, o);
    }
    List<Integer> list = new ArrayList<Integer>(bMap.values());
    Collections.sort(list, Collections.reverseOrder());

    int writeCount = 0;

    while (list.size() > ballTypeCount) {
      writeCount = writeCount + list.get(list.size() - 1);
      list.remove(list.size() - 1);
    }

    System.out.println(writeCount);


  }

}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define prvp(a) for(auto x : a) cout << "{" << x.ff << ',' << x.ss << "}";cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(int a, int b){return (int)((long long) a * b % mod);}
inline int modexpo(int a, int b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(int a, int b){ return mul(a, modexpo(b, mod - 2));}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  int n, i, j, k;
  int ans = 0;
  cin >> n;
  vector<int> p(n);
  forn(0, n, i){
    cin >> p[i];
  }
  int mx = p[0], mn = p[0];
  forn(0, n, i){
    if(p[i] <= mn){
      ans++;
    }
    mx = max(mx, p[i]);
    mn = min(mn, p[i]);
  }
  cout << ans << '\n';
}

int main(){
  fastio

  pre();

  int t = 1;
  // cin >> t;
  while(t--){
    solve();
  }

  ktj();
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  int N; cin >> N;
  vector <int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P[i]; P[i]--;
  }
  
  vector <int> A(N), B(N);
  for (int i = 0; i < N; i++){
    A[i] = 20001 * i + 1;
    B[i] = 20001 * (N - 1 - i) + 1;
  }

  for (int i = 0; i < N; i++){
    int now = P[i];
    A[now] += i;
  }
  
  for (int i = 0; i < N; i++){
    cout << A[i];
    if (i != N - 1) cout << " ";
    else cout << endl;
  }
  for (int i = 0; i < N; i++){
    cout << B[i];
    if (i != N - 1) cout << " ";
    else cout << endl;
  }  
  

  return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
int main (void){
	int h[4],m[4],s[4],n,i;
	for(i=1;i<=3;i++){
		scanf("%d %d %d",&h[i],&m[i],&s[i]);
		n=h[i]*3600+m[i]*60+s[i];
		scanf("%d %d %d",&h[i],&m[i],&s[i]);
		s[i]+=h[i]*3600+m[i]*60;
		s[i]-=n;
		h[i]=s[i]/3600;
		s[i]-=h[i]*3600;
		m[i]=s[i]/60;
		s[i]-=m[i]*60;
	}
	for(i=1;i<=3;i++)printf("%d %d %d\n",h[i],m[i],s[i]);
	return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
  int A, B;
  std::cin >> A >> B;

  int ans = 0;
  for ( int i = A; i <= B; i++ ) {
    std::string s = std::to_string(i);
    std::string org = s;
    std::reverse(s.begin(), s.end());
    std::cerr << s << ' ' << org << std::endl;
    if ( s == org ) ans++;
  }

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


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

int main()
{
    int n, ans = 1;
    double t, a, minn = 9999999.9;
    scanf("%d", &n);
    scanf("%lf%lf", &t, &a);
    for(int i=1; i<=n; i++){
        double temp;
        scanf("%lf", &temp);
        temp = t - 0.006*temp;
        temp = fabs(temp - a);
        if( temp < minn)
        {
            minn = temp;
            ans = i;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    A, B = map(int, readline().split())

    x, y, z = A + B, A - B, A * B

    print(max(x, y, z))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61660
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>

#define long long long int

using std::vector;
using std::map;
using std::string;
using std::pair;
using std::cin;
using std::cout;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    string s;
    cin >> s;

    int n = s.size();

    vector<int> next(26, n);
    vector<int> d(n + 2);
    vector<int> c(n + 2);
    vector<int> p(n + 2);
    d[n] = 1;
    p[n] = n + 1;

    for (int i = n - 1; i >= 0; i--) {
        next[s[i] - 'a'] = i;
        d[i] = 1000000000;
        for (int j = 0; j < 26; j++) {
            int s = 1 + d[next[j] + 1];
            if (s < d[i]) {
                d[i] = s;
                c[i] = j;
                p[i] = next[j] + 1;
            }
        }
    }

    string ss = "";
    for (int i = 0; i < n; i = p[i]) {
        ss += (char)('a' + c[i]);
    }

    cout << ss;

    return 0;
}

Measured memory_bytes: 2964
#include <iostream>
#include <vector>

using namespace std;

int N,M,X;



void dfs_search(int *min, int *B, vector<vector<int> > A, vector<int> C , int N, int i)
{
    if(i==N){
        vector<int> U(M);
        int cost=0;
        for(int k=0;k<N;k++){
            if(B[k]==1){
                cost+=C[k];
                for(int j=0;j<M;j++){
                    U[j]+=A[k][j];
                }
            }
        }
        for(auto u : U){
            if(u<X) return;
        }
        if(cost<*min) *min=cost;
        return;
    }

    B[i]=0;
    dfs_search(min,B,A,C,N,i+1);

    B[i]=1;
    dfs_search(min,B,A,C,N,i+1);
}


int main()
{
    cin>>N>>M>>X;
    vector<int> C;
    vector<vector<int> > A(N);
    vector<int> U(M);
    for(int i=0;i<N;i++){
        int c;cin>>c;
        C.push_back(c);
        for(int j=0;j<M;j++){
            int a;cin>>a;
            U[j]+=a;
            A[i].push_back(a);
        }
    }

    for(auto u : U){
        if(u<X){
            cout << -1 << endl;
            return 0;
        }
    }
    int *min;min=new int[1];*min=10000000;
    int *B;B = new int[N];
    dfs_search(min,B,A,C,N,0);
    cout << *min << endl;

    return 0;
}



Measured memory_bytes: 3640
def calc_mincowski_distance(n, p, x, y):
    distance = 0
    for i in range(n):
        distance += abs((x[i]-y[i]) ** p )
    distance **= 1/p
    return distance

def calc_chebyshev_distance(n, x, y):
    max_distance = -1
    for i in range(n):
        distance = abs(x[i] - y[i])
        if distance > max_distance:
            max_distance = distance
    return max_distance

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

d1 = calc_mincowski_distance(n, 1, x, y)
d2 = calc_mincowski_distance(n, 2, x, y)
d3 = calc_mincowski_distance(n, 3, x, y)
d_infinity = calc_chebyshev_distance(n, x, y)

print(d1, d2, d3, d_infinity, sep='\n')


Measured memory_bytes: 5652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
    long long n, a, b, c;
    long long ans = 0;
    cin >> n >> a >> b;
    c = a + b;
    ans += n / c * a;
    if (n % c != 0) {
        if (n % c < a) {
            ans += n % c;
        }
        else {
            ans += a;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256