akhauriyash/Code-Regression huggingface dataset:
# 再帰呼び出しのとき付ける
import sys
sys.setrecursionlimit(10**9)

def readInt():
    return list(map(int, input().split()))

n, m = readInt()

root = [-1] * n

def r(x):
    # print("root[x]=",root[x])
    if root[x] < 0:
        # print("r(x)=",x)
        return x
    else:
        root[x] = r(root[x])
        # print(root[x])
        return root[x]

def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x
    # print(root)

def size(x):
    x = r(x)
    # print(x, root[x])
    return -root[x]

for i in range(m):
    x, y = readInt()
    x -= 1
    y -= 1
    unite(x, y)
    # print('size={}'.format(size(i)))

# max_size = 0

# for i in range(n):
#     max_size = max(max_size, size(i))

# print(max_size)

# print(root)
ans = -1
for i in root:
    if i < 0:
        ans += 1
print(ans)

Measured memory_bytes: 75552
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
#define ALL(V) V.begin(), V.end()
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}


int Main(int N, VI &H)
{
    int counter = 0;
    int ans = 0;
    REP2(i, 1, N) {
        if(H[i-1] >= H[i]) counter++;
        else {
            chmax(ans, counter);
            counter = 0;
        }
    }
    chmax(ans, counter);
    return ans;
}

int main(void){
    int N;
    cin >> N;
    VI H(N);
    REP(i, N) cin >> H[i];
    cout << Main(N, H) << endl;
    return 0;
}

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

struct Dat{
	ll v, x; int i;
	bool operator<(const Dat &oth) const {
		return (v == oth.v) ? (x < oth.x) : (v < oth.v);
	}
};

int n, a, b;
ll D, x[100010], y[100010], ans;
Dat uv[100010], dv[100010];
set<Dat> us, ds;
vector<Dat> ua, da;
vector<int> av;

void del(int i){
	us.erase(uv[i]);
	ds.erase(dv[i]);
}

void f(int i);

void g(set<Dat> &ss, ll tv, ll s, ll e){
	Dat st = {tv, s, 0};
	while(true){
		auto t = ss.lower_bound(st);
		if(t == ss.end() || t->v != tv || t->x > e) break;
		del(t->i);
		f(t->i);
	}
}

void f(int i){
	av.push_back(i);
	g(us, uv[i].v - D, x[i] - D, x[i]);
	g(us, uv[i].v + D, x[i], x[i] + D);
	g(ds, dv[i].v - D, x[i] - D + 1, x[i] - 1);
	g(ds, dv[i].v + D, x[i] + 1, x[i] + D - 1);
}

int h(vector<Dat> &v, ll tv, ll s, ll e){
	return int(upper_bound(v.begin(), v.end(), (Dat){tv, e, 0}) - 
			   lower_bound(v.begin(), v.end(), (Dat){tv, s, 0}));
}

int main(){
	scanf("%d%d%d", &n, &a, &b);
	for(int i = 1; i <= n; i++){
		scanf("%lld%lld", x + i, y + i);
		uv[i] = {x[i] - y[i], x[i], i};
		dv[i] = {x[i] + y[i], x[i], i};
		us.insert(uv[i]);
		ds.insert(dv[i]);
	}
	for(auto &i : us) ua.push_back(i);
	for(auto &i : ds) da.push_back(i);
	D = abs(x[a] - x[b]) + abs(y[a] - y[b]);
	del(a);
	f(a);
	for(auto &i : av){
		ans += h(ua, uv[i].v - D, x[i] - D, x[i]);
		ans += h(ua, uv[i].v + D, x[i], x[i] + D);
		ans += h(da, dv[i].v - D, x[i] - D + 1, x[i] - 1);
		ans += h(da, dv[i].v + D, x[i] + 1, x[i] + D - 1);
	}
	printf("%lld\n", ans / 2);
}

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

int main() {
    int N;
    cin >> N;
    int mi = N+1, res = 0;
    for (int i = 0; i < N; ++i) {
        int p; cin >> p;
        mi = min(mi, p);
        if (mi== p) ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
n=int(input())

def func(cur,use):
    global res
    if cur>n:
        return
    if use==0b111:
        res+=1
    func(cur*10+7,use | 0b001)
    func(cur*10+5,use | 0b010)
    func(cur*10+3,use | 0b100)

res=0
func(0,0)
print(res)

Measured memory_bytes: 3060
# from math import *
from fractions import *

def next_int():
    return int(input())

def next_ints():
    return list(map(int, input().split()))

a, b = next_ints()
n = gcd(a, b)
ans = 1
i = 2
while i*i <= n:
    if n%i == 0:
        ans += 1
        while n%i == 0:
            n //= i
    i += 1
if n != 1:
    ans += 1
print(ans)


Measured memory_bytes: 5048
var
a,t1,t2:array[0..500005]of longint;
 n,m,i,j,k1,k2,tot1,tot2,j1,j2,p1,p2:longint;
 ans:int64;
function max(x,y:longint):longint;
 begin
  if x>y then exit(x) else exit(y);
 end;
begin
readln(n);
for i:=1 to n do
 begin
  read(a[i]);
  if m<a[i] then m:=a[i];
 end;
for i:=1 to n do
 begin
   if i mod 2=0 then begin inc(t1[a[i]]);  end;
   if i mod 2=1 then begin inc(t2[a[i]]);  end;
 end;
  for i:=1 to m do
  begin
    if k1<t1[i] then begin k1:=t1[i];p1:=i; end;
    if k2<t2[i] then begin k2:=t2[i];p2:=i; end;
  end;
  if p1<>p2 then
   begin
     ans:=n-k1-k2;
   end
    else
      begin
      j1:=0;j2:=0;
       for i:=1 to m do
        begin
         if i=p1 then continue;
         if j1<t1[i] then begin j1:=t1[i]; end;
         if j2<t2[i] then begin j2:=t2[i]; end;
        end;
       if j1<j2 then ans:=n-j2-k1 else ans:=n-j1-k2;
      end;
      writeln(ans);
end.


Measured memory_bytes: 2944
#include <iostream>
using namespace std;
const int NUM = 3;
int main(void) {
	int array[NUM];
	cin >> array[0] >> array[1] >> array[2];
	for (int i = 0; i < NUM; i++) {
		for (int j = 1; j < NUM; j++) {
			if (array[j-1] > array[j]) {
				int temp = array[j-1];
				array[j-1] = array[j];
				array[j] = temp;
			}
		}
	}
	cout << array[0] << " " << array[1] << " " << array [2] << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9+1;
const ll LINF = 1e18+1;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}
template<typename T> T lcm(T a,T b){return a*b/gcd(a, b);}


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
int main() {
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    REP(i, k){
        if(a>=b){
            b*=2;
        }else if (b>=c){
            c*=2;
        }
    }
    Yes(a<b&&b<c);
    
}


Measured memory_bytes: 3632
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
tmp = []
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if i * 500 + j * 100 + k * 50 == X:
                ans += 1
print(ans)

Measured memory_bytes: 3060
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*(n+1)
for i in range(n):
  if s[i : i + 2] == 'AC': #if s[i]=='A' and s[i+1]=='C':だとerror
    ans[i+1]=ans[i]+1
  else:
    ans[i+1]=ans[i]
#ti =「S の 1 文字目から i 文字目までに出現する a の数」として数列 t = {t0, t1, . . . , tN } を考えると、問 i の答えは tri−1 − tli−1
for i in range(q):
  l, r = map(int, input().split()) #ループ内で一行ずつ読み込む
  print(ans[r-1]-ans[l-1])

Measured memory_bytes: 6060
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

int main(void){
    ll A,B,C;
    cin >> A >> B >> C;
    cout << C <<" "<<A <<" "<<B;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int32 i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int32 i = (b) - 1; i >= (a); --i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(),(x).end()
#define C(x) cout << #x << " : " << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;



int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int32 n, x;
	cin >> n >> x;
	vector<int32> a(n);
	rep(i, 0, n)
		cin >> a[i];
	int32 ans = 0;
	int32 temp;
	rep(i, 1, n) {
		if (a[i] + a[i - 1] <= x) continue;
		if (a[i - 1] <= x) {
			ans += a[i] - (x - a[i - 1]);
			a[i] -= a[i] - (x - a[i - 1]);
		}
		else {
			ans += a[i];
			a[i] = 0;
			ans += a[i - 1] - x;
			a[i - 1] = x;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    map<char,int> cnt;
    bool ans = true;

    rep(i,s.size()){
        cnt[s[i]]++;
    }
    rep(i,s.size()){
        if(cnt[s[i]]>1) ans =false;
    }
    if (ans) cout << "yes" << endl;
    else        cout << "no" << endl;
}
//他の方のコード

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int B_sum = 0;
  for(int i=0; i<N; ++i) if(S[i]=='B') B_sum++;
  
  long long ans = 0;
  for(int i=0; i<N; ++i){
    for(int j=i+1; j<N; ++j){
      if(S[i]=='R' && S[j]=='G') goto LABEL;
      if(S[i]=='G' && S[j]=='R') goto LABEL;
      continue;
LABEL:
      // BRG or BGR
      ans += B_sum;
      int k1 = i-(j-i);
      if(k1>=0){
        if(S[k1]=='B') ans--;
      }
      
      int k2 = (i+j)/2;
      if((i+j)%2==0){
        if(S[k2]=='B') ans--;
      }
      
      int k3 = j+(j-i);
      if(k3<N){
        if(S[k3]=='B') ans--;
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

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

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }
	if (n == r) { return 1; }

	if (r > n / 2) { r = n / 2; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(llvec array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return -1LL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int main() {
	string s; cin>>s;
	if(s.at(0)!=s.at(1)||s.at(0)!=s.at(2)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


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

int main(){
  string s;
  cin >> s;
  if(s[int(s.size()-1)] == 's')cout << s << "es\n";
  else cout << s << "s\n";
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll a[100000],b[100000],c[1000000],dp[100000][3];
ll n,k;
int main(){
	ll ans=0;
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		cin>>b[i];
		cin>>c[i];
	
		}
	dp[1][0]=a[1];
	dp[1][1]=b[1];
	dp[1][2]=c[1];
		for(ll i=2;i<=n;i++){
			dp[i][0]=max(a[i]+dp[i-1][1],a[i]+dp[i-1][2]);
			dp[i][1]=max(b[i]+dp[i-1][0],b[i]+dp[i-1][2]);
			dp[i][2]=max(c[i]+dp[i-1][0],c[i]+dp[i-1][1]);
			}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
		
	}

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

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

    if(A < B) {
        swap(A, B);
    }
    cout << max(A * 2 - 1, A + B) << endl;

    return 0;
}


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

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

    int t[100100] = {0};
    int x[100100] = {0};
    int y[100100] = {0};

    for (int i = 0; i < N; ++i) {
        cin >> t[i+1] >> x[i+1] >> y[i+1]; 
    }

    bool can = true;
    for (int i = 0; i < N; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);

        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct EulerTour {
  vector< vector<int> > graph;
  vector<int> tour, s, t;
  int idx, root;
  EulerTour(){}
  EulerTour(int n):idx(0), root(0), graph(n), s(n), t(n){}
  void add_edge(int u, int v) {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  void dfs(int cur, int par) {
    s[cur] = idx;
    tour.push_back(cur);
    idx++;
    for(int to : graph[cur]) {
      if(to == par) continue;
      dfs(to, cur);
    }
    t[cur] = idx;
  }
  void build() {
    dfs(root, -1);
  }
};

EulerTour graph;

struct SegmentTree {
  vector<int> data, lazy;
  int sz;
  SegmentTree(){}
  SegmentTree(int n) {
    sz = 1; while(sz < n) sz *= 2;
    data.resize(2*sz-1, 0);
    lazy.resize(2*sz-1, -1);
  }
  void push(int k, int l, int r) {
    if(~lazy[k]) {
      chmax(data[k], lazy[k]);
      if(r - l > 1) {
	chmax(lazy[2*k+1], lazy[k]);
	chmax(lazy[2*k+2], lazy[k]);
      }
      lazy[k] = -1;
    }
  }
  void update(int a, int b, int x, int k, int l, int r) {
    push(k, l, r);
    if(r <= a || b <= l) return;
    if(a <= l && r <= b) {
      lazy[k] = x;
      push(k, l, r);
      return;
    }
    update(a, b, x, 2*k+1, l, (l+r)/2);
    update(a, b, x, 2*k+2, (l+r)/2, r);
  }
  void update(int a, int b, int x) {
    update(a, b, x, 0, 0, sz);
  }
  int query(int i, int k, int l, int r) {
    push(k, l, r);
    if(r - l == 1) return data[k];
    if(l <= i && i <= r) {
      if(i < (l+r)/2) return query(i, 2*k+1, l, (l+r)/2);
      else return query(i, 2*k+2, (l+r)/2, r);
    }
    return -1;
  }
  int query(int i) {
    return query(i, 0, 0, sz);
  }
};

int N, Q;
SegmentTree seg;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> N >> Q, N || Q) {
    graph = EulerTour(N);
    rep(i, N-1) {
      int p; cin >> p; --p;
      graph.add_edge(p, i+1);
    }
    graph.build();
    seg = SegmentTree(N);
    int ans = 0;
    rep(i, Q) {
      char c; int v;
      cin >> c >> v; --v;
      if(c == 'M') {
	seg.update(graph.s[v], graph.t[v], graph.s[v]);
      } else if(c == 'Q') {
	ans += graph.tour[seg.query(graph.s[v])]+1;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 24888
#include<iostream>
#include <cstdlib>
#include<vector>
using namespace std;
#define vc vector<int>;
#define vcl vector<long int>
#define cin(a)
void merge(vector<long int> &arr, long int l, long int m, long int r) 
{ 
    long int i, j, k; 
    long int n1 = m - l + 1; 
    long int n2 =  r - m; 
  
    /* create temp arrays */
    long int L[n1], R[n2]; 
  
    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++){
        L[i] = arr[l + i];
    }
    for (j = 0; j < n2; j++){ 
        R[j] = arr[m + 1+ j];
    }
  
    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray 
    j = 0; // Initial index of second subarray 
    k = l; // Initial index of merged subarray 
    while (i < n1 && j < n2) 
    { 
        if (L[i] <= R[j]) 
        { 
            arr[k] = L[i];
            i++; 
        } 
        else
        { 
            arr[k] = R[j]; 
            j++; 
        } 
        k++; 
    } 
  
    /* Copy the remaining elements of L[], if there 
       are any */
    while (i < n1) 
    { 
        arr[k] = L[i]; 
        i++; 
        k++; 
    } 
  
    /* Copy the remaining elements of R[], if there 
       are any */
    while (j < n2) 
    { 
        arr[k] = R[j]; 
        j++; 
        k++; 
    } 
} 
  
/* l is for left index and r is right index of the 
   sub-array of arr to be sorted */
void mergeSort(vector<long int> &arr, long int l, long int r) 
{ 
    if (l < r) 
    { 
        // Same as (l+r)/2, but avoids overflow for 
        // large l and h 
        int m = l+(r-l)/2; 
  
        // Sort first and second halves 
        mergeSort(arr, l, m); 
        mergeSort(arr, m+1, r); 
  
        merge(arr, l, m, r); 
    } 
}
int gcd(int a,int b){
    if(b==0)return a;
    else return gcd(b,a%b);
}

int main(){
    int t;
    cin>>t;
    long long sum=0;
    for(int i=1;i<=t;i++){
        for(int j=1;j<=t;j++){
            for(int k=1;k<=t;k++)
                sum=sum+gcd(gcd(i,j),k);
        }
    }
    cout<<sum;
} 

Measured memory_bytes: 3624
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('');
   let xs1 = input.trim().split(' '); 
   if(xs.length == 1){
   console.log(xs1[0]);
   }else if(xs.length == 2){
   console.log(9);
   }else if(xs.length == 3){
   console.log(xs1[0]-99 + 9);
   }else if(xs.length == 4){
   console.log(909);
   }else if(xs.length == 5){
   console.log(xs1[0]-9999 + 909);
   }else if(xs.length == 6){
   console.log(90909);
   }      
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
using namespace std;

// dp[N][W]
long long dp[110][100100];


int main() {
	long long N, W;

	cin >> N >> W;

	vector<long long> w(N);
	vector<long long> v(N);

	for(long long i=0; i<N; i++) {
		cin >> w.at(i) >> v.at(i);
	}

	for(long long i=0; i<110; i++) {
		for(long long j=0; j<100100; j++){
			dp[i][j] = 0;
		}
	}

	for(long long j=1; j<=N; j++) {
		for(long long i=0; i<=W; i++) {
			if(i-w.at(j-1) >= 0) {
				if(dp[j][i] < (v.at(j-1) + dp[j-1][i-w.at(j-1)])) {
					dp[j][i] = v.at(j-1) + dp[j-1][i-w.at(j-1)];
				}
			}

			if(dp[j][i] < dp[j-1][i]) {
				dp[j][i] = dp[j-1][i];
			}
		}
	}

	cout << dp[N][W] << endl;


}


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

int main() {
    int a,b,c;
    
    cin>>a>>b>>c; 
    
    if (a<b&&b<c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
        
    return 0;        
         
}

Measured memory_bytes: 1156
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 200200;
char s[N];
ll cnt[1000];
int n;
ll ans = 1;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%s", s);
	n = strlen(s);
	for (int i = 0; i < n; i++) {
		ans += i - cnt[s[i]];
		cnt[s[i]]++;
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ll long long
#define ld long double
#define ii pair<int, int>
#define iii pair<int, ii>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue
using namespace std;
const int ms = 2e5+100;
const int sigma = 30;
int n, m, k, t = 1;
string s;

void solve(){
  cin>>n;
  cin>>s;
  int ans = 0;
  for(int i=0; i<n-2; i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ans++;
  }
  cout<<ans<<endl;
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  while(t--){
    solve();
  }
}

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

int main()
{
	int x, max = 1, box = 1;
	cin >> x;

	for (int i = 1; i < x; i++) {
		for (int j = 2; j < x; j++) {
			box = 1;
			for (int k = 0; k < j; k++)
				box *= i;
			if (max < box&& box <=x)
				max = box;
		}
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    unsigned long long int n,m;
    unsigned long long int a[2000000],b[2000000];
    scanf("%llu %llu",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%llu %llu",&a[i],&b[i]);
    }
    unsigned long long int f1go[2000000]={},fngo[2000000]={};
    for(int i=0;i<m;i++){
        if(a[i]==1){
            f1go[b[i]]=1;
        }
        if(b[i]==n){
            fngo[a[i]]=1;
        }
    }
    if(m==1){
        printf("IMPOSSIBLE\n");
        return 0;
    }
    for(int i=0;i<=n;i++){
        if(f1go[i]==fngo[i]&&f1go[i]==1){
            printf("POSSIBLE\n");
            return 0;
        }
    }
    printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 40192
#開始限界が早い順でよいか

import sys

n = int(input())
J = []

for i in range(n):
    a, b = map(int, input().split( ))
    J.append([b,a])


J.sort()

time = 0

for i in range(n):
    time += J[i][1]
    if time > J[i][0]:
        print("No")
        sys.exit()

print("Yes")    


Measured memory_bytes: 36288
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
map<string,bool> k;
int main()
{
	ios_base::sync_with_stdio();
	cin.tie(0);cout.tie(0);
	ll n;
	string s;
	cin >> n;
	ll ans=0;
	while(n--){
		cin >> s;
		if(!k[s]){
			ans++;
			k[s]=true;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 19056
use std::cmp;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: f64 = sc.read();
    let x = n / 1.08;

    let ans = x.ceil() as u64;
    let from = cmp::max(100, ans) - 100;
    let to = ans + 200;
    for v in from..to {
        let n2 = v * 108 / 100;
        if n2 == n as u64 {
            println!("{}", v);
            return;
        }
    }
    println!(":(");
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0;i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

typedef long long ll;

using namespace std;


void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    vector<pair<ll,ll>> vec(N);
    REP(i,N) vec[i] = pair<ll,ll>(A[i],B[i]);

    ll rest = M;
    ll cost = 0;

    sort(ALL(vec));

    for (int i=0;rest>0;i++){
        cost += vec[i].first * min(vec[i].second, rest);
        rest -= min(vec[i].second, rest);
    }
    cout << cost << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 3328
use proconio::input;
use std::cmp::{max, min};

const MAX_L: u32 = 100_000;
const BASE_SIZE: usize = 1 << 10;

fn main() {
    input! {
        n: usize,
        vw: [(u32, u32); n],
        q: usize,
        vl: [(usize, usize); q],
    }
    let dp = make_dp(&vw);
    for vlq in vl {
        println!("{}", calc(&vw, vlq.0 - 1, vlq.1, &dp));
    }
}

fn make_dp(vw: &Vec<(u32, u32)>) -> Vec<Vec<u32>> {
    let mut dp = Vec::<Vec<u32>>::new();

    dp.push(
        (0..=MAX_L)
        .map(|i| if i < vw[0].1 { 0 } else { vw[0].0 })
        .collect()
    );

    let n = min(vw.len(), BASE_SIZE - 1);
    for c in 1..n {
        let p = (c - 1) / 2;
        dp.push(
            (0..=MAX_L)
            .map(|i| {
                let w = vw[c].1;
                let v = if i < w { 0 } else { dp[p][(i - w) as usize] + vw[c].0 };
                max(dp[p][i as usize], v)
            })
            .collect()
        );
    }

    dp
}

fn calc(
    vw: &Vec<(u32, u32)>,
    u: usize, 
    l: usize,
    dp: &Vec<Vec<u32>>
) -> u32 {
    if u < dp.len() {
        dp[u][l]
    } else {
        let p = (u - 1) / 2;
        let w = vw[u].1;
        let pv1 = calc(vw, p, l, dp);
        let pv2 = if l < w as usize { 0 } else { calc(vw, p, l - w as usize, dp) + vw[u].0 };
        max(pv1, pv2)
    }
}


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

int main(){
    int N, K; cin >> N >> K;
    if((N*(N-1)/2) - (N-1) < K){
        cout << -1 << endl;
        return 0;
    }
    int M = N*(N-1)/2 - K;
    vector<P> edge;
    // とりあえず連結グラフにするのに必要な辺を追加する
    rep(i, N-1){
        edge.push_back({1, i+2});
    }
    int cnt = N-1;
    for(int i = 2;i <= N; i++){
        for(int j = i+1;j <= N; j++){
            if(cnt >= M) break;
            edge.push_back({i, j});
            cnt++;
        }
        if(cnt >= M) break;
    }
    cout << M << endl;
    rep(i, M){
        cout << edge[i].first << " " << edge[i].second << endl;
    }
    return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;

    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >>h.at(i);

    sort(h.begin(), h.end());

    long long sum = 0;
    for (int i = 0; i < n-k; i++) {
        sum += h.at(i);
    }

    cout << sum << endl;

    return 0;
}


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

using namespace std;

int main(){
 int n;
  cin >> n;
  
  for(int i=11;i<=55555;i+=10){
    bool flag=true;
    for(int j=2;j*j<=i;j++) if(!(i%j)) flag=false; 
    if(flag) {
      cout << i << " ";
      n--;
    }
  if(!n) break;
  }
  
}

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

#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    string S;
    cin >> S;
    if (S[0] == S[1] && S[1] == S[2]){
        cout << "No";
    } else {
        cout << "Yes";
    }
    return 0;
}



Measured memory_bytes: 256
import sys,queue,math,copy,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]

N = int(input())
A = LI()+[-1]


ans = 0
l = 0
r = 0
xor = 0
s = 0

while r < N:

    if xor & A[r] == 0:
        xor ^= A[r]
        r += 1
        ans += (r - l)
    else:
        s = xor & A[r]
        while s:
            s -= s & A[l]
            xor ^= A[l]
            l += 1
            if l == r : break
print (ans)

Measured memory_bytes: 96200
#include <stdio.h>
#define DATA 10000
int main(){
    int i, j;
    int x;
    int data[DATA];

    for(j=0; j<DATA; j++){
      scanf("%d", &x);
      data[j] = x;
      if(x == 0){
        break;
      }
    }

    for(i=0; i<j; i++){
      printf("Case %d: %d\n", i+1, data[i]);
    }

}



Measured memory_bytes: 1976
n,m = map(int,input().split())
edge = [[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)
def dfs(visited,i):
    visited.append(i)
    if len(visited) == n:
        return 1
    count = 0
    for j in edge[i]:
        if j in visited:
            continue
        count += dfs(visited[:],j)
    return count
print(dfs([],0))

Measured memory_bytes: 41564
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

ll LCM(ll x , ll y){
	return (x*y) / __gcd(x,y) ;
}

ll NumOfDiv(ll a , ll b , ll k){
	return b/k - a/k + (a%k == 0) ;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// ----------------------
	int n , t , a; 
	cin >> n >> t >> a; 
	pair<double , int> x[n] ;
	for (int i = 0; i < n; ++i)
	{
		int h ; cin >> h ;
		x[i].f = abs(a - (t - h*0.006)) ;
		x[i].s = i+1;
	}
	sort(x , x+n) ;
	cout << x[0].s << endl ;
	return 0 ;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

typedef long LL;

int N,x;
int a[100010];

int main(){
	scanf("%d%d" , &N , &x);
	repp(i,0,N){
		scanf("%d" , a + i);
	}
	LL ans = max(0,a[0]-x);
	a[0] = min(a[0],x);
	repp(i,1,N){
		ans += max(0,a[i]-x+a[i-1]);
		a[i] = min(a[i],x-a[i-1]);
	}
	printf("%lld\n" , ans);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int n, a[100] = {0}; //100回
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    for(int i = n-1; i > -1; i--) {
        if (i == n-1){
            cout << a[i];
        }
        else{
            cout << " " << a[i];
        }
    }
    cout << endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
#define MP make_pair
#define	pb push_back
#define x first
#define y second
#define next fake_next

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define count jaskdasbj
const LD PI = acos(-1.0);
const LD EPS = 1e-9;
const int INF = 1e9;
const int MAX = 1 << 17;
const int mod = 1000 * 1000 * 1000 + 7;
int N;
int A[1 << 18];
int G[1 << 18];
pair<pair<int , int> , pair<int , int>> F[1 << 18];
pair<int , int> a[4];
void update(pair<pair<int , int> , pair<int , int> > &u , pair<pair<int , int> , pair<int , int>> v)
{
	a[0] = u.first , a[1] = u.second , a[2] = v.first , a[3] = v.second;
	sort(a , a + 4);
	int sz = unique(a , a + 4) - a;
	u = {a[sz - 1] , a[sz - 2]};
}
int main()
{
	//freopen("input.txt" , "r" , stdin);
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for(int i = 0; i < (1 << N); i++)
	{
		cin >> A[i];
	}


	for(int mask = 0; mask < (1<<N); ++mask)
	{
		update(F[mask] , {{A[mask] , mask} , {-1 , 0}});
		for(int i = 0;i < N; ++i)
		{
			if(~mask & (1<<i))
			{
				update(F[mask ^ (1 << i)] , F[mask]);
			}
		}
	}
	for(int mask = 1; mask < (1 << N); mask++)
	{
		G[mask] = F[mask].first.first + F[mask].second.first;
	}
	//cout << F[mask].first << " " << F[mask].second << endl;
	for(int mask = 1; mask < (1 << N); mask++)
	{
		G[mask] = max(G[mask] , G[mask - 1]);
		cout << G[mask] << endl;
	}

	return 0;
}



Measured memory_bytes: 9216
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef SHUBHAM107
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD) {
	a %= m; ll res = 1; while (b) {if (b & 1)res = res * a % m; a = a * a % m; b >>= 1;}
	return res;
}
ll bpow(ll a, ll b) {ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a) {return modpow(a, MOD - 2, MOD);}
void graph(vvi &adj, int m) {int x, y; forn(i, m) {cin >> x >> y; adj[x - 1].pb(y - 1); adj[y - 1].pb(x - 1);}}

const int mxN = 2e5 + 5;
void solve() {
	int n;
	cin >> n;
	map<string, int> mp;
	string str;
	forn(i, n) cin >> str, mp[str]++;
	cout << sz(mp);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef SHUBHAM107
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}


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

/*-------------------------------TEMPLATE ------ START-------------------*/
//defines
#define openin freopen("input.txt","r",stdin)
#define openout freopen("output.txt","w",stdout)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pii pair<int,int>
#define vii vector<int>
#define ll long long
#define int long long
#define repr(i,x,y) for (__typeof(x) i=x;i>=y;i--)
#define rep(i,x,y) for (__typeof(x) i=x;i<=y;i++)
#define all(c) (c).begin(),(c).end()
#define allr(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
#define mp make_pair

#define mod 1000000007
#define M_PI 3.141592653589793
#define eps 1e-9

/* Print pair */
template <typename T,typename S>
ostream & operator << (ostream &os , const pair<T,S> &v) {
    os << "(" ;
    os << v.first << "," << v.second << ")" ;
    return os ;
}
/* Print vector */
template <typename T>
ostream & operator << (ostream &os , const vector<T> &v) {
    os << "[" ;
    int sz = v.size() ;
    for(int i = 0 ; i < sz ; ++i) {
        os << v[i] ;
        if(i!=sz-1)os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print set */
template <typename T>
ostream & operator << (ostream &os , const set<T> &v) {
    T last = *v.rbegin() ;
    os << "[" ;
    for(auto it : v) {
        os << it  ;
        if(it != last) os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print Map */
template <typename T,typename S>
ostream & operator << (ostream &os , const map<T,S> &v) {
    for(auto it : v) {
        os << it.first << " : " << it.second << "\n" ;
    }
    return os ;
}
int power(int a , int b)
{
    int res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % mod ;
        }
        b/=2 ;
        a = (a*a) % mod ;
    }
    return res ;
}

int fact(int k){
    if(k == 1 || k == 2)
        return k;
    int a=1,b=1;
    while(a<=k){
        b = ((b%mod) * (a%mod))%mod;
        a++;
    }
    return b;
}
/* String to int */
uint64_t toint(const string &s){
    istringstream src(s);
    uint64_t v;
    src>>v;
    return v;
}

/*Int to string */
string tostring(uint64_t v){
    ostringstream src;
    src<<v;
    return src.str();
}


/*-------------------------------TEMPLATE ------ END-------------------*/
//SOLUTION
const int N = 2e5+5;
int n,k,res;

int32_t main()
{
    fast;//openin;
    cin>>n>>k;
    for(int i =1 ; i<n; i+=(k-1)){
        res++;
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 256
import sys, math
from functools import lru_cache
import datetime
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, M = mi()
    A = list(mi())
    A.sort()
    BC = [list(mi()) for i in range(M)]
    BC.sort(reverse=True, key=lambda x: x[1])

    D = []

    for i in range(M):
        for j in range(BC[i][0]):
            D.append(BC[i][1])
            if len(D) == N:
                break
        if len(D) == N:
            break

    while len(D) < N:
        D.append(0)

    print(sum(max(A[i], D[i]) for i in range(N)))


if __name__ == '__main__':
    main()

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

using namespace std;

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

struct E {
	int s, e, c;
};

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int L; cin >> L;
	vector<E> es;

	vector<int> vs;
	while (L > 0) {
		vs.push_back(L);
		L >>= 1;
	}
	reverse(ALL(vs));

	int v = vs.size();
	REPU(i, 1, vs.size()) {
		es.push_back((E) {v - 1, v, 0});
		es.push_back((E) {v - 1, v, vs[i - 1]});
		if (vs[i] & 1) {
			es.push_back((E) {v - 1, vs.size(), vs[i] - 1});
		}
		v--;
	}
	printf("%d %d\n", vs.size(), es.size());
	for (auto e : es) {
		printf("%d %d %d\n", e.s, e.e, e.c);
	}

	return 0;
}


Measured memory_bytes: 256
/*
h s, d't skp th si tll i's svedclTabCtrl
 * ABC141 E
 * ABC145 D
 * ABC147 F
 * ABC174 F
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
int ans=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
for(int k=j+1;k<n;k++)
{
if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k])
{
ans++;
}
}
}
}
cout<<ans;
}

/*
 *||||

 */

Measured memory_bytes: 3620
using System;
using System.Linq;

namespace aoj
{
    class Program
    {
        static void Main(string[] args)
        {
            var length = int.Parse(Console.ReadLine());
            int[] array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            bubbleSort(ref array, length);
        }

        static void bubbleSort(ref int[] _array, int _length)
        {
            var count = 0;

            // 逆の隣接要素が存在する
            var flag = true;
            while (flag)
            {
                flag = false;
                for (var i = _length - 1; 0 < i; --i)
                {
                    if (_array[i] < _array[i - 1])
                    {
                        Swap(ref _array[i], ref _array[i - 1]);
                        ++count;
                        flag = true;
                    }
                }
            }

            for (var i = 0; i < _length; ++i)
            {
                Console.Write(_array[i]);
                if (i != _length - 1)
                {
                    Console.Write(" ");
                }
            }
            Console.WriteLine();
            Console.WriteLine(count);
        }

        static void Swap(ref int _a, ref int _b)
        {
            var tmp = _a;
            _a = _b;
            _b = tmp;
        }
    }
}



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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

struct ResidualGraph{
    int V;
    std::vector<std::vector<std::tuple<int, int, int>>> graph;
     
    ResidualGraph(int V) : V(V), graph(V) { };
 
    void add(int v, int w, int capacity){
        graph[v].emplace_back(w, capacity, graph[w].size());
        graph[w].emplace_back(v, 0, graph[v].size() - 1);
    }
 
    std::vector<std::tuple<int, int, int>>& operator[](int v){
        return graph[v];
    }
};
 
struct Dinitz{
    ResidualGraph &graph;
    std::vector<int> level, lastIndex;
 
    Dinitz(ResidualGraph &graph) : graph(graph), level(graph.V), lastIndex(graph.V) { }
 
    void bfs(int s){
        std::fill(level.begin(), level.end(), -1);
 
        std::queue<int> q;
        q.emplace(s);
        level[s] = 0;
 
        while(!q.empty()){
            int v = q.front();
            q.pop();
             
            for(auto &e : graph[v]){
                int w, cap;
                std::tie(w, cap, std::ignore) = e;
 
                if(cap > 0 && level[w] < 0){
                    level[w] = level[v] + 1;
                    q.emplace(w);
                }
            }
        }
    }
 
    int dfs(int v, int t, int flow){
        if(v == t){
            return flow;
        }
 
        for(int i=lastIndex[v];i<(int)graph[v].size();++i){
            int w, rev;
            int &cap = std::get<1>(graph[v][i]);
            std::tie(w, std::ignore, rev) = graph[v][i];
            int &rev_cap = std::get<1>(graph[w][rev]);
             
            if(cap > 0 && level[w] > level[v]){
                int f = dfs(w, t, std::min(flow, cap));
                if(f > 0){
                    cap -= f;
                    rev_cap += f;
                    return f;
                }
            }
        }
 
        return 0;
    }
 
    int64_t solve(int s, int t){
        int64_t res = 0;
        while(true){
            bfs(s);
            if(level[t] < 0){
                return res;
            }
            std::fill(lastIndex.begin(), lastIndex.end(), 0);
            int f;
            while((f = dfs(s, t, std::numeric_limits<int>::max())) > 0){
                res += f;
            }
        }
         
        return 0;
    }
};

int N, M;
std::string U;
int A[500];

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

    std::cin >> N >> M >> U;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    ResidualGraph g(N + 2);
    
    for(int i=1;i<=N;++i){
        if(U[i - 1] == 'R'){
            g.add(0, i, A[i - 1]);
            g.add(i, N + 1, 0);
        }else{
            g.add(0, i, 0);
            g.add(i, N + 1, A[i - 1]);
        }
    }

    for(int i=0;i<M;++i){
        int S, T, B;
        std::cin >> S >> T >> B;

        if(S > T){
            std::swap(S, T);
        }

        g.add(S, T, B);
    }

    Dinitz d(g);
    ll res = d.solve(0, N + 1);
    std::cout << res << std::endl;
}



Measured memory_bytes: 3328