akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
pair<int, int> E[200010];
int X[200010], H[200010];
int cnt[200010];
int ans[200010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, D, A; cin >> N >> D >> A;
    
    
    rep(i, N) {
        cin >> X[i] >> H[i];
        E[i] = {X[i], H[i]};
        
    }
    E[N].first = -INF;
    E[N].second = 0;
    sort(E, E + N);
    rep(i, N) {
        cnt[i] = (E[i].second + A - 1)/ A;
        //cout << cnt[i] << endl;
    }
    sort(X, X + N);
    rep(i, N) {
        auto L = upper_bound(X, X + i, X[i] - D * 2 - 1);
        std::size_t pos = std::distance(X, L);
        ans[i + 2] = ans[i + 1] + max(0LL, cnt[i] - (ans[i + 1] - ans[pos + 1]));
        //cout << pos << " " << ans[i + 2] << endl;
    }
    cout << ans[N + 1] << endl;


    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	lnt n;
	std::cin >> n;
	std::vector<lnt> ans;
	while(n>0) {
		n-=1;
		ans.emplace_back(n%26);
		n/=26;
	}
	std::reverse(all(ans));
	rep(i,ans.size()) std::cout << (char)(ans[i]+'a');
	std::cout << EL;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using lint = long long;
using namespace std;
using pi = pair<int, int>;
const int MAXN = 200005;
const int mod = 1e9 + 7;

int n;
int ans[MAXN];
vector<int> gph[MAXN];
vector<int> post;

void dfs(int x, int p){
	for(auto &i : gph[x]){
		if(i != p) dfs(i, x);
	}
	post.push_back(x);
}

int main(){
	scanf("%d",&n);
	vector<pi> drog;
	for(int i=0; i<n-1; i++){
		int s, e; scanf("%d %d",&s,&e);
		drog.emplace_back(s, e);
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	int root = 1;
	if(n >= 3){
		for(int i=1; i<=n; i++){
			if(gph[i].size() >= 2) root = i;
		}
	}
	dfs(root, -1);
	vector<int> c(n);
	for(auto &i : c) scanf("%d",&i);
	sort(c.begin(), c.end());
	for(int i=0; i<c.size(); i++){
		ans[post[i]] = c[i];
	}
	int ret = 0;
	for(auto &i : drog) ret += min(ans[i.first], ans[i.second]);
	cout << ret << endl;
	for(int i=1; i<=n; i++) printf("%d ", ans[i]);
}


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

a = [[0 for i in range(10)] for j in range(10)]

for i in range(1,n+1):
    b = int(str(i)[0])
    c = int(str(i)[-1])
    a[b][c] += 1

ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += a[i][j]*a[j][i]
print(ans)





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

// int main(){
//     // N円の商品を買う。 K個の数が嫌い。
//     int N, K;
//     int temp;
//     cin >> N >> K;
//     int hateNumbers[10];
//     int hateNumber;
//     for(int i = 0; i < K; i++){
//         cin >> hateNumber;
//         // 嫌いな数の要素数を１にする。
//         hateNumbers[hateNumber] = 1;
//     }
//     bool can = false;

//     while(!can){
//         temp = N;
//         while(temp != 0){
//             if(hateNumbers[temp%10] == 1) {
//                 N++;
//                 break;
//             } 
//             temp /= 10;
//         }
//         if(!temp){
//             break;
//         }
//     }
//     cout << N << endl;
// }

int main(){
    // N円の商品を買う。 K個の数が嫌い。
    int N, K;
    int temp;
    int hateNunbers[10];
    cin >> N >> K;
    for (int i = 0; i < K; i++) {
      cin >> hateNunbers[i];
   }
   int num = N;
   while(1){
       string s = to_string(num);
       bool can = true;

       for(int i = 0;i < K; i++){
           if(count(s.begin(),s.end(), hateNunbers[i]+'0')){
               can = false;
               num++;
               break;
           }
       }
       if (can) {
         cout << num << endl;
         return 0;
      }
   }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define maxn 100005
#define LL long long
#define mod 1000000007
#define INF (LL)4e18
using namespace std;
int n,f[maxn],s[maxn];
LL a,b,x[maxn];
int Get(int l,int r)
{
	if(l>r) return 0;
	if(!l) return s[r];
	else return (s[r]-s[l-1]+mod)%mod;
}
int main()
{
	scanf("%d%lld%lld",&n,&a,&b);
	if(a<b) swap(a,b);
	for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
	x[0]=-INF,x[n+1]=INF;
	f[0]=s[0]=1;
	int l=0,r=0;
	for(int i=1;i<=n+1;i++)
	{
		while(r+1<i&&x[i]-x[r+1]>=a) r++;
		if(i>=2&&x[i-1]-x[i-2]<b) l=i-2;
		if(x[i]-x[i-1]>=a) f[i]=f[i-1];
		f[i]=(f[i]+Get(l,min(i-2,r)))%mod;
		s[i]=s[i-1];
		if(x[i+1]-x[i-1]>=b) s[i]=(s[i]+f[i])%mod;
	}
	printf("%d\n",f[n+1]);
}


Measured memory_bytes: 1792
fun main(args: Array<String>) {
  val (N, K, Q) = readInts()
  val s = Array(N) { 0 }
  for (i in 0 until Q) {
    val n = readInt() - 1
    s[n]++
  }
  for (i in 0 until N) {
    println(if (K - Q + s[i] > 0) "Yes" else "No")
  }
}

fun gcd(a: Int, b: Int): Int = if (a < b) gcd(b, a) else if (b == 0) a else gcd(b, a % b)
fun gcd(a: Long, b: Long): Long = if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = (a * b) / gcd(a, b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }


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

using namespace std;

int main(){
	string S,T;
	cin>>S>>T;
	if(S.length()<T.length()){
		swap(S,T);
	}
	vector<vector<short>>memo(S.length() + 1, vector<short>(26));
	for(int i = 0; i < S.length(); i++){
		memo[i+1]=memo[i];
		memo[i+1][S[i]-'a']++;
	}
	vector<vector<short>>memo2(T.length() + 1, vector<short>(26));
	for(int i = 0; i < T.length(); i++){
		memo2[i+1]=memo2[i];
		memo2[i+1][T[i]-'a']++;
	}
	vector<short>now(26);
	int ans=0;
	set<vector<short>>SVI;
	for(int len = min(S.length(), T.length()); len >= 1; len--){
		SVI.clear();
		for(int i = 0; i + len < memo.size(); i++){
			for(int k = 0; k < 26; k++){
				now[k] = memo[i+len][k] - memo[i][k];
			}
			SVI.insert(now);
		}
		for(int i = 0; i + len < memo2.size(); i++){
			for(int k = 0; k < 26; k++){
				now[k] = memo2[i+len][k] - memo2[i][k];
			}
			if(SVI.count(now)){
				cout<<len<<endl;
				return 0;
			}
		}
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 3976
## main

while true
  n = gets.strip.to_i
  break if n == 0

  teams = []

  for id in (1..n)
    pts = gets.strip.split(' ')
    nm = pts.shift

    w = l = 0

    for pt in pts
      if pt == '0'
        w += 1
      elsif pt == '1'
        l += 1
      end
    end

    teams << [nm, w, l, id]
  end

  for t in teams.sort{|a, b|
      (c0 = b[1] <=> a[1]) != 0 ? c0 :
      (c1 = a[2] <=> b[2]) != 0 ? c1 :
      a[3] <=> b[3]
    }

    puts t[0]
  end
end

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

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

int main(){


    int n;
    cin>>n;
    int p[n+1],s[n+2],a[n+1];
    a[0]=0;
    p[0]=0;
    s[n+1]=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++){
        p[i]=gcd(p[i-1],a[i]);
    }
    for(int i=n;i>=1;i--){
        s[i]=gcd(a[i],s[i+1]);
    }
    int ma=-1;
    for(int i=1;i<=n;i++){
        ma=max(ma,gcd(p[i-1],s[i+1]));
    }
    cout<<ma;
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
const int maxn = 1e5 + 10;
//2019-1-12 atcoder 20:00
int main()
{  
	int h, w, n;
	scanf("%d %d %d", &n, &h, &w);
	int ans = (n - h + 1)*(n - w + 1);
	cout << ans << endl;
	return 0;
}
//碳烤小松鼠,油炸老蜈蚣

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int m, f, r;
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) {
            return 0;
        }
        int sum = m + f;
        if (m == -1 || f == -1) {
            cout << "F" << endl;
        } else if (sum >= 80) {
            cout << "A" << endl;
        } else if (65 <= sum && sum < 80) {
            cout << "B" << endl;
        } else if (50 <= sum && sum < 65) {
            cout << "C" << endl;
        } else if (30 <= sum && sum < 50) {
            if (r >= 50) {
                cout << "C" << endl;
            } else {
                cout << "D" << endl;
            }
        } else {
            cout << "F" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <fstream>
#include <queue>

using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");

const int NMax = 5e4 + 5;
typedef long long ll;

int A,B;

int main()
{
    cin>>A>>B;
    cout<<(A+B) % 24;
    in.close();out.close();
    return 0;
}



Measured memory_bytes: 764
import sys
input=sys.stdin.readline   
sys.setrecursionlimit(100000000)
from functools import lru_cache
INF = 1000000000
MOD = 10**9+7

def main():
    n=int(input())

    dp=[[[[0]*4 for _ in range(4)] for _ in range(4)] for _ in range(n+1)]

    dp[3]=[[[1]*4 for _ in range(4)] for _ in range(4)]    
    dp[3][0][2][1]=0
    dp[3][0][1][2]=0
    dp[3][2][0][1]=0
    
    cannot={(0,1,2),(0,2,1),(2,0,1)}

    for i in range(4,n+1):
        for j in range(4):
            for k in range(4):
                for l in range(4):
                    if (j,k,l) in cannot:
                        dp[i][j][k][l]=0
                    else:
                        for m in range(4):
                            if (m,j,l)==(0,2,1) or (m,k,l)==(0,2,1):
                                continue
                            else:
                                dp[i][j][k][l]+=dp[i-1][m][j][k]
                                dp[i][j][k][l]%=MOD

    ans=0
    for i in range(4):
        for j in range(4):
            for k in range(4):
                ans+=dp[-1][i][j][k]
                ans%=MOD
    print(ans)
if __name__=='__main__':
    main()

Measured memory_bytes: 4196
// ABC046B - 

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

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

	unsigned int ans = K;
	for (int i = 1; i < N; i++) {
		ans *= K - 1;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <limits.h>

  /* 配列の要素を交換する */
void Swap(int x[ ], int i, int j)
{
    int temp;

    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}

void QSort(int x[ ], int left, int right)
{
    int i, j;
    int pivot;

    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */

    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

    while (1) {                    /* 無限ループ */

        while (x[i] < pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */

        while (pivot < x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */

        Swap(x, i, j);             /* x[i] と x[j]を交換 */
        i++;                       /* 次のデータ */
        j--;
    }

    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}


int main(void){
    // Your code here!
    int N,K, h[100000], min = INT_MAX;
    int p[10];
    scanf("%d %d",&N,&K);
    
    for(int i = 0; i < N; i++)
    {
        scanf("%d\n",&h[i]);
    }
    QSort(h,0,N-1);
   
    for(int i = 0; i < N-K+1; i++)
    {
        if(h[i+K-1]-h[i] < min) min = h[i+K-1]-h[i];
    }
    printf("%d\n",min);
}


Measured memory_bytes: 512
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007



n, m = LI()
G = [[] for _ in range(n)]
for a, b, c in LIR(m):
    G[a - 1] += [(b - 1, c)]

# 負の閉路がなかったら高々n-1回で更新は終わるはずn回目に更新が起こったとしたら負の閉路がある。
def bellman_ford(G, s=0):
    dist = [-INF] * n
    dist[s] = 0
    v_nows = {s}
    for _ in range(n):
        v_changeds = set()
        for u in v_nows:
            for v, ci in G[u]:
                if dist[u] + ci > dist[v]:
                    dist[v] = dist[u] + ci
                    v_changeds.add(v)
        v_nows = v_changeds
    dq = deque(v_nows)
    while dq:
        u = dq.popleft()
        if u == n - 1:
            return "inf"
        for v, _ in G[u]:
            if dist[v] != INF:
                dist[v] = INF
                dq += [v]
    return dist[n - 1]



print(bellman_ford(G))



Measured memory_bytes: 84228
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

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

const ll INF = 1000000000000000000ll;

ll dist;
int n, m;
vector<ll> S, D;

bool check(int a, ll t, const vector<int> &order, vector<int> &used, const vector<ll> &stime){
	bool valid = true;
	for(int i = 0; valid && i < a; ++i){
		ll g0 = stime[order[i]] + S[order[i]] * dist;
		ll g1 = t + S[order[a]] * dist;
		bool crossing = false;
		if(order[i] < order[a]){
			if(stime[order[i]] >= t){ valid = false; }
			if(g0 > g1){ crossing = true; }
		}else{
			if(stime[order[i]] <= t){ valid = false; }
			if(g0 < g1){ crossing = true; }
		}
		if(crossing){
			int pos = -1;
			for(int j = 0; pos < 0 && j < m; ++j){
				if(used[order[i]] & (1 << j)){ continue; }
				ll ta = D[j] * S[order[i]] + stime[order[i]];
				ll tb = D[j] * S[order[a]] + t;
				if(ta == tb){ pos = j; }
			}
			if(pos < 0){
				valid = false;
			}else{
				used[order[i]] |= (1 << pos);
				used[order[a]] |= (1 << pos);
			}
		}
	}
	return valid;
}

ll solve(int a, const vector<int> &order, const vector<int> &used, vector<ll> &stime){
	if(a == 0){
		int index = order[a];
		stime[index] = 0;
		return solve(1, order, used, stime);
	}else if(a == n){
		ll start = INF, goal = -INF;
		for(int i = 0; i < n; ++i){
			start = min(start, stime[i]);
			goal = max(goal, stime[i] + S[i] * dist);
		}
		return goal - start;
	}else{
		ll result = INF;
		int index = order[a];
		for(int i = 0; i < a; ++i){
			int c = order[i];
			for(int j = 0; j <= m; ++j){
				if(used[c] & (1 << j)){ continue; }
				ll d = (j == m ? dist : D[j]);
				ll t = d * S[c] + stime[c] - d * S[index];
				vector<int> next_used(used);
				if(!check(a, t, order, next_used, stime)){ continue; }
				stime[order[a]] = t;
				result = min(solve(a + 1, order, next_used, stime), result);
			}
		}
		ll t = -INF;
		for(int i = 0; i < a; ++i){
			if(order[i] < order[a]){
				t = max(t, order[a] - order[i] + stime[order[i]]);
			}
		}
		if(t <= -INF){
			for(int i = 0; i < a; ++i){
				if(order[i] > order[a]){
					t = max(t, stime[order[i]] - (order[a] - order[i]));
				}
			}
		}
		vector<int> next_used(used);
		if(check(a, t, order, next_used, stime)){
			stime[order[a]] = t;
			result = min(solve(a + 1, order, next_used, stime), result);
		}
		return result;
	}
}

int main(){
	cin >> dist >> n;
	S.resize(n);
	for(int i = 0; i < n; ++i){ cin >> S[i]; }
	cin >> m;
	D.resize(m);
	for(int i = 0; i < m; ++i){ cin >> D[i]; }
	vector<int> order(n);
	for(int i = 0; i < n; ++i){ order[i] = i; }
	ll answer = INF;
	do {
		vector<int> used(n);
		vector<ll> stime(n);
		answer = min(answer, solve(0, order, used, stime));
	} while(next_permutation(order.begin(), order.end()));
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 1220
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

std::vector<int> ix[10];

int main() {
  int N; std::string S; std::cin >> N >> S;
  for(int i = 0; i < N; ++i) ix[S[i]-'0'].push_back(i);
  int ans = 0;
  for(int num = 0; num < 1000; ++num) {
    int d1 = num/100;
    if(ix[d1].size() < 1) continue;
    int i1 = ix[d1].front();
    int d2 = (num%100)/10;
    int i2 = std::partition_point(ix[d2].begin(), ix[d2].end(),
      [&](int x){ return x <= i1; }) -ix[d2].begin();
    if(i2 >= ix[d2].size()) continue;
    i2 = ix[d2][i2];
    int d3 = num%10;
    int i3 = std::partition_point(ix[d3].begin(), ix[d3].end(),
      [&](int x){ return x <= i2; }) -ix[d3].begin();
    if(i3 >= ix[d3].size()) continue;
    ++ans;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <array>

using namespace std;

int main() {

    ios_base::sync_with_stdio(0);
    int H, W;
    cin >> H >> W;
    int h, w;
    cin >> h >> w;
    if (H % h == 0 && W % w == 0) {
        cout << "No" << endl;
        return 0;
    }

    int each = (((int)1e9 - 2) / (h * w - 1));
    int neg = -each * (h * w - 1) - 1;

    cout << "Yes" << endl;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << ((i % h == h - 1 && j % w == w - 1) ? neg : each) << " ";
        }
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <numeric>

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

// ------------>8------------ SegmentTree ------------>8------------

// -- Query Type enum.
enum QUERY_GET { SUM, MAX, MIN };
template <class T = int>
class SegmentTree {
private:
	int ARY_SIZE;
	T initVal;
	std::vector<T> ary;
	std::function<T(T&, T&)> merge;

	void init(int n, QUERY_GET qtype) {
		switch (qtype) {
		case SUM:
			initVal = 0;
			merge = [](T& l, T& r) {return l + r; };
			break;
		case MAX:
			initVal = std::numeric_limits<T>::lowest();
			merge = [](T& l, T& r) {return (l > r) ? l : r; };
			break;
		case MIN:
			initVal = std::numeric_limits<T>::max();
			merge = [](T& l, T& r) {return (l < r) ? l : r; };
			break;
		default: struct INVALID_QUERY_TYPE_ERROR {}; throw INVALID_QUERY_TYPE_ERROR(); break;
		}
		init(n);
	}
	void init(int n) {
		while (ARY_SIZE < n) ARY_SIZE <<= 1;
		ary.resize(ARY_SIZE << 1, initVal);
	}
public:
	SegmentTree(int n, QUERY_GET qtype) : ARY_SIZE(1) { init(n, qtype); }
	SegmentTree(int n, T initVal, std::function<T(T&, T&)> f) : ARY_SIZE(1), initVal(initVal), merge(f) { init(n); }

	// -- a[i] = val;
	inline void update(int i, T val) {
		i += ARY_SIZE;
		ary[i] = val;
		while (i > 1) {
			i >>= 1;
			ary[i] = merge(ary[i << 1], ary[(i << 1) + 1]);
		}
	}
	// -- a[i] += val;
	inline void add(int i, T val) {
		update(i, ary[i + ARY_SIZE] + val);
	}
	// -- [l, r)
	inline T query(int l, int r) {
		if (l >= r) return initVal;
		T vl = initVal, vr = initVal;
		for (l += ARY_SIZE, r += ARY_SIZE; l != r; l >>= 1, r >>= 1) {
			if (l & 1) vl = merge(vl, ary[l++]);
			if (r & 1) vr = merge(ary[--r], vr);
		}
		return merge(vl, vr);
	}
	T operator[](int i) { return ary[i + ARY_SIZE]; }

	void debugShow() {
		for (int i = ARY_SIZE; i < ARY_SIZE << 1; ++i) std::cerr << ary[i] << " ";
		std::cerr << "\n";
	}
};
using ST = SegmentTree<int>;
// ------------8<------------ SegmentTree ------------8<------------

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

	int n, q;
	std::cin >> n >> q;
	std::vector<int> com(q), x(q), y(q);
	REP(i, q) std::cin >> com[i] >> x[i] >> y[i];

	ST st(n, MIN);
	REP(i, q) {
		if (com[i] == 0) st.update(x[i], y[i]);
		if (com[i] == 1) std::cout << st.query(x[i], y[i] + 1) << "\n";
	}

	return 0;
}


Measured memory_bytes: 4860
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <cstdlib>

using namespace std;
typedef long long ll;

int main(){
    ll n = 0;
    cin >> n;
    ll sum = 0;
    for(ll i = 1; i <= n; i++){
        if(i%3 != 0 && i%5 != 0) sum += i;
    }
    cout << sum << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll MOD = 1000000007;
ll INF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

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

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  cin >> n;
  vll a(n);
  REP(i,n) cin >> a[i];
  vll sum(n);
  sum[0] = a[0];
  for(ll i = 1; i < n; i++){
    sum[i] = sum[i - 1] + a[i];
    sum[i] %= MOD;
  }
  ll ans = 0;
  for(ll i = n - 1; i >= 1; i--){
    ans += (a[i] * sum[i - 1]);
    ans %= MOD;
  }
  cout << ans << endl;

    
    
  return 0;
}



Measured memory_bytes: 6328
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, k = LI()
    a = n - k
    if k == 1:
        print(0)
        return
    print(a)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39152
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,a;cin>>h>>a;
  cout<<(h-1)/a+1<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, a[100020], x, z;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		a[x]++;
	}
	for (int i = 0; i < 100001; i++) {
		z = max(z, a[i - 1] + a[i] + a[i + 1]);
	}
	printf("%d\n", z);
	return 0;
}

Measured memory_bytes: 768
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

//ll a[1000100];
pair<ll, ll> cb[1000100];
vector<pair<ll, ll>> ans;

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

  ll n, m;
  cin >> n >> m;
  REP(i,n) {
    ll x; cin >> x;
    ans.push_back({x, 1});
  }
  
  REP(i,m) {
    ll b, c;
    cin >> b >> c;
    //cin >> cb[i].first >> cb[i].second;
    ans.push_back({c, b});
  }  
  //sort(cb, cb+m);
  /*
  REP(i, n) cerr << ans[i].first << " ";
  cerr << endl;
  */
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  /*
  for(auto &e: ans) cerr << e.first << " ";
  cerr << endl;  
  */
  ll rest = n;
  ll sum = 0LL;
  for(int i=0; i<n; i++) {
    //cerr << ans[i].first << " " << ans[i].second << endl;
    if(rest < ans[i].second){
      sum += ans[i].first*rest;      
      break;
    }
    else{
      sum += ans[i].first*ans[i].second;
      rest -= ans[i].second;
    }
  }
  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 6512
function Main(input) {
  "use strict"
	const temp = input.split("\n");

	const n = parseInt(temp.shift());
  console.log(n*n*n)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21956
// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

const int cm = 1<<17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha(){
	if(ci-cn == cm){ fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

inline int getint(){
	int a = 0;
	if(ci-cn+16 > cm) while((ct=getcha()) >= '0') a = a*10 + ct - '0';
	else while ((ct=*ci++) >= '0') a = a*10 + ct - '0';
	return a;
}

const int dm = 1<<20;
char dn[dm], *di = dn;
inline void putint(int x){
	char c[10];
	int d; for(d=0; x; d++, x/=10) c[d] = x%10 + '0';
	for(int i=d-1; i>=0; --i) *di++ = c[i];
	*di++ = '\n';
}

#define NMAX 100000
int K = 1;
int C[NMAX+1];//child
int S[NMAX+1];//sibling
int colors[NMAX+1];

void dfs(int p, int p_color){
	for(int color=1, c=C[p]; c; c=S[c], color++){
		K = max(K, colors[c] = color==p_color? ++color: color);
		dfs(c, color);
	}
}

int main(){
	int N = getint();
	int Q[N];
	rp(i, 1, N){
		int p = getint(); Q[i] = getint();
		S[Q[i]] = C[p];
		C[p] = Q[i];
	}
	dfs(1, 0);
	putint(K);
	rp(i, 1, N) putint(colors[Q[i]]);
	fwrite(dn, 1, di - dn, stdout);
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define repr(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

ll d;
ll dp[365][26];
vector<ll> ans(365);
vector<ll> c(26);

ll keisan(vector<ll> vec){
    ll total=0;
    vector<ll> a(26,0);
    rep(i,d){
        total+=dp[i][vec[i]];
        a[vec[i]]=i;
        rep(j,26){
            total-=c[j]*(i-a[j]);
        }
    }
    return total;
}

int main(){
    cin >> d;
    rep(i,26) cin >> c[i];
    rep(i,d)rep(j,26) cin >> dp[i][j];
    vector<ll> t(d);
    rep(i,d) cin >> t[i];

    rep(i,d){
        ll now=-1,kazu=0;
        rep(j,26){
            if(now<dp[i][j]){
                now=dp[i][j];
                kazu=j;
            }
        }
        ans[i]=kazu;
    }
    
    //ll total=keisan(ans);
    //cout << total << endl;
    
    //rep(i,d) cout << ans[i]+1 << endl;
    
    ll total=0;
    vector<ll> a(26,-1);
    rep(i,d){
        total+=dp[i][t[i]-1];
        a[t[i]-1]=i;
        rep(j,26){
            total-=c[j]*(i-a[j]);
        }
        cout << total << endl;
    }

    return 0;
}












Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n;
	cin>>n;
	if((n/10)==9||(n-(n/10)*10)==9) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
n = int(input())
array = []

for a in range(1,n):
  b = n - a
  suma = 0
  sumb = 0
  for i in range(5):
    suma = suma + a%10
    a= a//10
  for i in range(5):
    sumb = sumb + b%10
    b= b//10
  array.append(suma+sumb)
  
print(min(array))

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


int main() {

    int A,B,C;
    cin>>A>>B>>C;

    int K;
    cin>>K;

    if(A<B && B<C){
        cout<<"Yes";
    }
    else{

        while(K && B<=A){
            B*=2;
            K--;
        }

        while(K && (C<=B || C<=A)){
            C*=2;
            K--;
        }



        if(A<B && B<C){
            cout<<"Yes";
        } else{
            cout<<"No";
        }

    }
    return 0;
}

Measured memory_bytes: 3584
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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





long long xorValue(long long x, std::vector<long long> &A,
                   std::unordered_map<long long, long long> &mp){
    if(mp.find(x) != std::end(mp)) return mp[x];
    long long ret(0);
    for(auto a: A){
        ret += (a ^ x);
    }
    return mp[x] = ret;
}

int main(){
    int N; std::cin >> N;
    long long K; std::cin >> K;
    std::vector<long long> A(N);
    for(int i(0); i < N; ++i) std::cin >> A[i];
    //10^12 < 2^40
    std::vector<long long> dp0(41), dp1(41);
    std::unordered_map<long long, long long> mp;
    for(int i(39); i >= 0; --i){
        if(xorValue(dp0[i+1], A, mp) >= xorValue(dp1[i+1], A, mp)){
            dp0[i] = dp0[i+1];
        }else{
            dp0[i] = dp1[i+1];
        }

        dp1[i] = dp0[i];
        long long a(dp0[i+1] + (1LL<<i));
        if(a <= K && xorValue(dp1[i], A, mp) < xorValue(a, A, mp)){
            dp1[i] = a;
        }
        a = dp1[i+1] + (1LL<<i);
        if(a <= K && xorValue(dp1[i], A, mp) < xorValue(a, A, mp)){
            dp1[i] = a;
        }
    }
    std::cout << std::max(xorValue(dp0[0], A, mp), xorValue(dp1[0], A, mp)) << std::endl;
    return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int n, k; scanf("%d%d", &n, &k);
  vector<pair<int, int>> v;
  for (int i = 1; i < n; ++i) {
    v.emplace_back(n, i);
  }
  int m = (n-1)*(n-2)/2;
  if (k > m) {
    printf("-1");
    return;
  }
  for (int i = 1; i < n-1; ++i) {
    for (int j = i+1; j <= n-1; ++j) {
      if (m == k) goto done;
      v.emplace_back(i, j);
      --m;
    }
  }
 done:
  printf("%d\n", (int)v.size());
  for (const auto &e: v) printf("%d %d\n", e.first, e.second);
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3820
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(q)]

a=[]
for i in range(n-1):
  a.append(1)
a.append(0)
current=0
b=[]
for i in range(n):
  b.append(m)

while True:
  i=n-1
  while a[i]==m:
    i=i-1
    if i==-1:
      break
  if i==-1:
    break
  a[i]+=1
  for j in range(i+1,n):
      a[j]=a[i]
  d=0
  for j in range(q):
    if (a[l[j][1]-1]-a[l[j][0]-1])==l[j][2]:
      d+=l[j][3]
  if d>current:
    current=d

print(current)

Measured memory_bytes: 68168
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define zad tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld%lld",&x,&y)
#define in3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define out(x) printf("%lld",x)
#define outspace(x) printf("%lld ",x)
#define outln(x) printf("%lld\n",x)
#define ll long long
#define ld long double
#define pb push_back
#define p push
#define mkp make_pair
#define ff first
#define PLL pair<ll,ll>
#define PSS pair<string,string>
#define ss second
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> >
#define all(x) x.begin(),x.end()
#define F(i,a,b) for(ll i=a;i<b;i++)
#define RF(i,a,b) for(ll i=a;i>b;i--)
#define mset(a,b) memset((a),(b),sizeof((a)))
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define MOD 1000000007
#define RMOD 998244353
#define INF 10000000000000000
#define MINF LONG_LONG_MIN
#define MAXF LONG_LONG_MAX
const ll N=200007;
#define OuterLoop ll t;scanf("%lld",&t);while(t--)
#define lcm(a,b) a*b/(__gcd(a,b))
//v =  vector< vector<ll> >(n+1);
//v.assign(n+1,vector<ll>()); this way we can assign anything.
bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    ll p=sqrt(n);
    for(int i=5;i<=p;i+=6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}
ll n;
vector<ll> v;
vector<ll> dp(N,-1);

ll dynamic(ll src)
{
    if(dp[src]!=-1) return dp[src];
    if(src>=n) return dp[src]=0;
    ll cnt=N,cnt1;
    cnt = abs(v[src]-v[src+1])+dynamic(src+1);
    if(src+2<=n) cnt1=abs(v[src]-v[src+2])+dynamic(src+2);
    //cout << src << "--" << cnt << "--" << cnt1 << "\n";
    return dp[src]=min(cnt,cnt1);
}

int main()
{  
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
      cin >> n;
      v = vector<ll>(n+1);
      for(ll i=1;i<=n;i++) cin>>v[i];
    }
    cout << dynamic(1);
    //for(ll i=1;i<=n;i++) cout<<dp[i]<<" ";
}

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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = (int)2123, mod = (int)1e9 + 7;

int n;
int ans, dp[N+N][N+N], cnt[N+N][N+N], f[10*N];
void add(int &a,int b){
	a+=b;
	if(a >= mod)
		a-=mod;
}
ll binpow(ll x,ll p){
	ll res = 1;
	while(p){
		if(p&1)
			res = res * x % mod;
		x = x * x % mod;
		p/=2;
	}
	return res;
}
ll inv(ll x){
	x%=mod;
	return binpow(x, mod - 2);
}
ll C(int k,int n){
	return 1ll * f[n] * inv( 1ll * f[k] * f[n-k]) %mod;
}
int main(){    
	f[0] = 1;
	for(int i = 1; i < 10*N; i++)
		f[i] = 1ll * f[i - 1] * i % mod;
	
	cin >> n;
    for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		add(ans, C(a+a,a+a+b+b));
		dp[N-a][N-b]++;
		cnt[N+a][N+b]++;
	}
	ans = mod - ans;
	ans%=mod;
	for(int d = 0; d <= 4*N; d++)
		for(int x = 0; x <= d; x++){
			int y = d - x;
			if(x >= N + N || y >= N + N)
				continue;                
			ans = (ans + 1ll * cnt[x][y] * dp[x][y]) % mod;
			if(x + 1 < N + N)
				add(dp[x + 1][y], dp[x][y]);
			if(y + 1 < N + N)
				add(dp[x][y + 1], dp[x][y]);
		}

	cout << ans * inv(2) % mod;
	return 0;
}


Measured memory_bytes: 106496
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int main()
{
    ll n,k;
    cin >> n >> k;
    ll ans = 1;
    for(int i = 0; i < n; i++){
        if(i == 0) ans *= k;
        else ans *= (k-1);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main()
{
int n;
cin>>n;
int ans=0;
for(int i=1; i<=n; i++)
{
    ans+=i;
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ConsoleApplication
{
    class Program
    {
        static void Main()
        {
            new Solution().answer();
        }
    }

    class Solution
    {
        string N, M, T;
        public Solution()
        {
            N = Console.ReadLine();
            M = Console.ReadLine();
            int j = Convert.ToInt32(N);
            string[] M_split = new string[j];
            string[] M_split_full = new string[j * 3];

            M_split = M.Split(' ');
            int a;
            for (a = 0; a < j; a++)
            {
                M_split_full[a] = M_split[a];
                M_split_full[j + a] = (Convert.ToInt32(M_split[a]) - 1).ToString();
                M_split_full[(2 * j) + a] = (Convert.ToInt32(M_split[a]) + 1).ToString();
            }

            var count =(from item in M_split_full
                        group item by item into g
                        select g.Count()).ToList();

            var ans = (from item in count
                       group item by item into g
                       select g.Max()).ToList();

            ans.Sort();
            T = ans[ans.Count() - 1].ToString();                          
        }

        public void answer()
        {
            Console.WriteLine(T);
        }
    }
}


Measured memory_bytes: 51232
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    n = ri()
    if n >= 30:
        print ("Yes")
    else:
        print ("No")





mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 65032
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

bool flg[100000];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, ans = 0;
	cin >> n;
	vector<int> p(n);
	REP(i, n) {
		cin >> p[i];
		if(p[i] == i + 1) flg[i] = true;
	}
	REP(i, n){
		if(flg[i] && flg[i + 1]){
			++ans;
			++i;
		}
		else if(flg[i]){
			++ans;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 768
import operator


class SegmentTree:
    # http://tsutaj.hatenablog.com/entry/2017/03/29/204841
    def __init__(self, size, fn=operator.add, default=0):
        """
        :param int size:
        :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など
        """
        # size 以上である最小の 2 冪
        n = 1
        while n < size:
            n *= 2
        self._size = n
        self._tree = [default for _ in range(self._size * 2 - 1)]
        self._fn = fn

    def set(self, i, value):
        """
        i 番目に value を設定
        :param int i:
        :param int value:
        :return:
        """
        x = self._size - 1 + i
        self._tree[x] = value

        while x > 0:
            x = (x - 1) // 2
            self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2])

    def add(self, i, value):
        """
        もとの i 番目と value に fn を適用したものを i 番目に設定
        :param int i:
        :param int value:
        :return:
        """
        x = self._size - 1 + i
        self.set(i, self._fn(self._tree[x], value))

    def get(self, from_i, to_i, k=0, L=None, r=None):
        """
        [from_i, to_i) に fn を適用した結果を返す
        :param int from_i:
        :param int to_i:
        :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ
        :param int L:
        :param int r:
        :return:
        """
        L = 0 if L is None else L
        r = self._size if r is None else r

        if from_i <= L and r <= to_i:
            return self._tree[k]

        if to_i <= L or r <= from_i:
            return None

        ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2)
        ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r)
        if ret_L is None:
            return ret_r
        if ret_r is None:
            return ret_L
        return self._fn(ret_L, ret_r)

    def __len__(self):
        return self._size


N, Q = list(map(int, input().split()))
com, X, Y = zip(*[input().split() for _ in range(Q)])
X = list(map(int, X))
Y = list(map(int, Y))

if __name__ == '__main__':
    st = SegmentTree(size=N + 1, fn=operator.add, default=0)
    for c, x, y in zip(com, X, Y):
        if c == '0':
            st.add(x, y)
        if c == '1':
            print(st.get(x, y + 1))



Measured memory_bytes: 42080
def main():
    s = input()
    count = {"a": 0, "b": 0, "c": 0}
    for ss in s:
        count[ss] += 1
    count = list(count.values())
    count.sort()
    print("YES" if count[-1] - count[0] <= 1 else "NO")


if __name__ == '__main__':
    main()



Measured memory_bytes: 3188
D, G = map(int, input().split())
p = []
c = []
for i in range(0, D):
    a, b = map(int, input().split())
    p.append(a)
    c.append(b)
    
minimum = 2**31   

for i in range(2**D):
    count = 0
    score = 0
    max_j = 0
    addcount = 0
    for j in range(D):
        if (i>>j & 1):
            score += 100 * (j+1) * p[j] + c[j]
            count += p[j]
        if (~i>>j & 1):
            max_j = j
    if score >= G:
        minimum = min(minimum, count)
    else:
        while score < G:
            score += 100 * (max_j + 1)
            addcount += 1
            count += 1
        if addcount <= p[max_j]:
            minimum = min(minimum, count)

print(minimum)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>
//#include "show_vector.hh"


using namespace std;

#define debug false

int main(int argc, char *argv[]){

  string S;
  cin >> S;
  int K;
  cin >> K;

  int length = S.length();

  vector<char> SS;
  for(int i = 0; i < S.length(); i++){
    SS.push_back(S[i]);
  }

  sort(SS.begin(), SS.end());
  SS.erase( unique(SS.begin(), SS.end()), SS.end() );

  vector<string> candidate;
  int index = 0;

  REBIRTH :

  char top = SS[index];
  vector<int> top_cand(0);
  for(int i = 0; i < length; i++){
    if(S[i] == top){
      top_cand.push_back(i);
    }
  }

  for(int i = 0; i < top_cand.size(); i++){
    int top_itr = top_cand[i];
    string st = "";
    for(int j = 0; j < K; j++){
      st = st + S[top_itr + j];
      candidate.push_back(st);
      if(top_itr+j+1 == length) break;
    }
  }
  sort(candidate.begin(), candidate.end());
  candidate.erase( unique(candidate.begin(), candidate.end()), candidate.end() );
  if(candidate.size() < K) {
    index++;
    goto REBIRTH;
  }

  cout << candidate[K-1] << endl;

  return 0;

  for(int i = 0; i < K; i++){
    cerr << i << " : " << candidate[i] << endl;;
  }
  return 0;
}


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

ll dfs(vector<ll>& d, int level, ll acc, ll sum)
{
    if (level == d.size()) {
        return sum + acc;
    }
    return dfs(d, level + 1, acc * 10 + d[level], sum) + dfs(d, level + 1, d[level], sum + acc);
}

int main()
{
    ll s;
    cin >> s;
    vector<ll> d;
    while (s != 0) {
        d.push_back(s % 10);
        s /= 10;
    }
    reverse(d.begin(), d.end());
    ll ans = dfs(d, 1, d[0], 0);
    cout << ans << endl;
}


Measured memory_bytes: 256