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

int main(){
    int N;cin>>N;
    int ans = 111;
    if(N<=111){
      ans = 111;
    }else if(N<=222){
      ans = 222;
    }else if(N<=333){
      ans = 333;
    }else if(N<=444){
      ans = 444;
    }else if(N<=555){
      ans = 555;
    }else if(N<=666){
      ans = 666;
    }else if(N<=777){
      ans = 777;
    }else if(N<=888){
      ans = 888;
    }else if(N<=999){
      ans = 999;
    }
    cout<<ans<<endl;    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
int main()
{
	int n;
	cin>>n;


	vector<int> fac(1e6+1);


	for(int i=1;i<=1e6;i++)
	{
		for(int j=i;j<=1e6;j+=i)
		{
			fac[j]+=1;
		}
	}

	int ans=0;

	for(int i=1;i<=n;i++)
	{	
		if(n-i<=0)
			break;

		int mine=fac[n-i]/2;

		mine*=2;

		ans+=mine;

		if(fac[n-i]%2!=0)
		{
			ans++;
		}
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 7208
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
typedef long long ll;
const int MOD = 1000000007;
#define PI 3.141592653589
using namespace std;

int main() {
	int k, a, b;
	cin >> k >> a >> b;
	for(int i=a; i<=b; i++)
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	cout << "NG" << endl;
	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
int main(){
	int ans; cin >> ans;
	cout << 48 - ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n, k;
		n = sc.nextInt();
		k = sc.nextInt();
		sc.close();
		int ans = 1;
		for(int i = 0; i < n; ++i) {
			int tmp = ans * 2;
			int tmp2 = ans + k;
			ans = Math.min(tmp,  tmp2);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,s1,s2;

  while(1){
  cin >> s;
  if(s == "-")return 0;
  int n;
  cin >> n;
  for(int i=0;i<n;i++)
    {
      int a;
      cin >> a;

      s1 = s.substr(0,a);
      s2 = s.substr(a ,s.size());
      s = s2 + s1;
 
    }
  cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 3208
# -*- coding: utf-8 -*-
from itertools import permutations

N = int(input().strip())
pat_P = tuple(map(int, input().rstrip().split()))
pat_Q = tuple(map(int, input().rstrip().split()))
#-----

perm_list = [ pat for pat in permutations(range(1,N+1))]

a = perm_list.index(pat_P) + 1
b = perm_list.index(pat_Q) + 1
print(abs(a-b))


Measured memory_bytes: 7924
h,w,kk = map(int,input().split())
s = [list(map(int, input())) for i in range(h)]

ans = h+w-2
for i in range(1 << (h-1)):
    tate = 0
    index = [0] * h
    # しきりはh-1個なので2個目から考える
    for j in range(h-1):
        if i & (1 << j):
            tate += 1
        index[j+1] = tate # チョコ軍の番号
    chocos = [0]*(tate + 1) # チョコ軍
    yoko = 0
    ok = True
    for j in range(w):
        for k in range(h):
            chocos[index[k]] += s[k][j]
            # kkを超えるたびにその直前に仕切りをいれて新しいチョコ軍について考える
        if max(chocos) > kk:
            yoko += 1
            chocos = [0]*(tate+1)
            for l in range(h):
                chocos[index[l]] += s[l][j]
            if max(chocos) > kk:# その列だけで超える
                ok = False
        if not ok:
            break
    if ok:
        ans = min(ans, tate + yoko)

print(ans)

Measured memory_bytes: 74392
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define line cout<<"----------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll mx=200009;
ll facto[mx]; 
ll invfacto[mx]; 
ll getfacto(ll a, ll b, ll m)
{
	ll ans=1; 
	a%=m; 
	while(b)
	{
		if(b&1) ans=(ans*a)%m;
		a=(a*a)%m ; 
		b>>=1; 
	}
	return ans; 
}
void pre()
{
	facto[0]=1; 
	for(ll i=1;i<mx;i++) facto[i]=(facto[i-1]*i)%mod; 
	invfacto[0]=1; 
	for(ll i=1;i<mx;i++) invfacto[i]=getfacto(facto[i],mod-2,mod);
}
ll findway(ll a , ll b)
{
	ll way=(facto[a]*invfacto[b])%mod; 
	way=way*invfacto[a-b]; 
	return way%mod ; 
}
ll dp[4000];
bool cmp(pair<ll,ll> a, pair<ll,ll> b)
{
	return a.first+a.second<b.first+b.second; 
}
int main()
{
	pre(); 
	ll r,c,n; 
	cin>>r>>c>>n; 
	vector<pair<ll,ll> > v; 
	for(ll i=0;i<n;i++)
	{
		ll a,b; 
		cin>>a>>b ; 
		v.pb(mp(a,b));
	}
	v.pb(mp(r,c));
	sort(v.begin(),v.end(),cmp);
	for(ll i=0;i<(ll)v.size();i++)
	{
		ll x=v[i].first-1; ll y=v[i].second-1; 
		ll way=findway(x+y,x);
		for(ll j=0;j<i;j++)
		{
			ll x1=v[j].first-1; ll y1=v[j].second-1; 
			if(x1<=x and y1<=y)
			{
				ll xx=v[i].first-v[j].first; 
				ll yy=v[i].second-v[j].second; 
				ll way1=findway(xx+yy,xx);
				way=way-(dp[j]*way1)%mod;  
				way%=mod; 
				way=(way+mod)%mod; 
			}
		}
		dp[i]=way; 
	}
	cout<<dp[n]<<endl; 
}
/*

*/
 

 


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

long long h, w,y, mn=100000000000, mx, ms,i;

int main(){
cin >> h >> w;
if(h%3==0||w%3==0)return 0*printf("%d", 0);
for(i=1; i<=w; i++){
    mx = max((w-i)*h, i*((h+1)/2));
    ms = min((w-i)*h, i*(h/2));
    y =mx-ms;
    mn = min(y, mn);
    mx = max(h*i, (w-i+1)/2*h);
    ms = min(h*i, ((w-i)/2)*h);
    y = mx-ms;
    mn = min(mn,y);
}

for(i=1; i<=h; i++){
    mx = max((h-i)*w, i*((w+1)/2));
    ms = min((h-i)*w, i*(w/2));
    y = mx-ms;
    mn = min(mn , y);
    mx = max(w*i, (h-i+1)/2*w);
    ms = min(w*i, ((h-i)/2)*w);
    y = mx-ms;
    mn = min(mn,y);
}
cout << mn << endl;

return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define vii vector<vector<int>>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
   ll n;
   cin >> n;
    vector<ll> a(1e7+1,1);

    for(ll i=2; i<n+1; i++){
        for(ll j=i; j<n+1; j+=i){
            a[j]++;
        }
    }

    ll res=0;
    for(ll i=1; i<=n; i++){
        res+=i*a[i];
    }
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 81344
import Foundation
let main: () = {
    let N = nextInt()
    let A = listOfInt()
    var dp = Array(N) { [0, 0] }
    dp[1][1] = A[1]
    dp[1][0] = A[0]
    for n in 2 ..< N {
        if (n.isEven) {
            if (n < 3) {
                dp[n][1] = A[n] + [dp[n - 2][1], dp[n - 2][0]].max()!
                dp[n][0] = [dp[n - 1][1], dp[n - 1][0]].max()!
            } else {
                dp[n][1] = A[n] + [dp[n - 3][1], dp[n - 3][0], dp[n - 2][1], dp[n - 2][0]].max()!
                dp[n][0] = [dp[n - 1][1], dp[n - 1][0], A[n - 2] + dp[n - 3][0]].max()!
            }
        } else {
            dp[n][1] = A[n] + [dp[n - 2][1], dp[n - 2][0], dp[n - 1][0]].max()!
            dp[n][0] = A[n - 1] + dp[n - 2][0]
        }
    }
    let ans = dp.last!.max()!
    print(ans)
}()

@inlinable func next() -> String { readLine()! }
@inlinable func nextInt() -> Int { Int(next())! }
@inlinable func listOfString() -> [String] { next().split(separator: " ").map(String.init) }
@inlinable func listOfInt() -> [Int] { listOfString().map { Int($0)! } }
extension Int {
    var isEven: Bool { self.isMultiple(of: 2) }
}

extension Array {
    init(_ size: Int, _ initValue: (() -> Element)) {
        self = [Element]()
        for _ in 0 ..< size {
            let value = initValue()
            self.append(value)
        }
    }
}


Measured memory_bytes: 28916
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){   
   int h,w,n;
   cin>>h>>w>>n;
   int ans=max(h,w);
   if(n%ans==0) cout<<n/ans;
   else cout<<n/ans+1;
   
   return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const long long md=1e9+7;
struct node{
	long long a[3][3];
	void print(){
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++)
				printf("%lld ",a[i][j]);
			printf("\n");
		}
		printf("\n");
	}
	void mem(){
		memset(a,0,sizeof(a));
	}
	void csh(){
		mem();
		for(int i=0;i<3;i++)
			a[i][i]=1;
	}
	void bebase(){
		mem();
		a[0][1]=1,a[1][2]=1;
		a[2][0]=1,a[2][1]=md-2,a[2][2]=4;
	}
}base;
node operator * (const node &A,const node &B){
	node res;
	res.mem();
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++)
				res.a[i][j]+=A.a[i][k]*B.a[k][j]%md;
			res.a[i][j]%=md;
		}
	return res;
}
node powd(node x,int y){
	node res;
	res.csh();
	while(y){
		if(y&1) res=res*x;
		x=x*x;
		y>>=1;
	}
	return res;
}
long long getval(const node &A){
	return (1*A.a[0][1]+5*A.a[0][2])%md;
}
int a[100100];
int main(){
//	freopen("E.in","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d",&a[i]);
	a[++m]=n;
	base.bebase();
	node tot,st;
	tot.mem();
	long long ans;
	for(int i=1;i<=m;i++)
	{
		st=powd(base,a[i]-a[i-1]);
		tot=tot*st;
		ans=(getval(powd(base,a[i]))-getval(tot)+md)%md;
//		printf("%lld\n",ans);
		for(int j=0;j<3;j++)
			(tot.a[j][j]+=ans)%=md;
	}
	printf("%lld\n",ans);
	return 0;
}


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

// #include "prettyprint.hpp"

using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    int red = 0, blue = 0;
    for (int i = 0; i < N; ++i)
    {
        if (s[i] == 'R')
        {
            red++;
        }
        else
        {
            blue++;
        }
    }
    if (red > blue)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
 
int main()
{
  long long N,M;
  int i,j;
  int number;
  char s[10];
  long long  cnt=0;

//    int k=0;
  scanf("%lld", &N);
  scanf("%lld", &M);
  

      if(N==1&&M==1){
        cnt=1;
      } else if(N==1){
        if(M==2){
          cnt=0;
        } else {
          cnt=M-2;
        }
      } else if(M==1){
        if(N==2){
          cnt=0;
        } else {
          cnt=N-2;
        }
      } else if(M==2||N==2){
        cnt=0;
      } else  {
          cnt=(N-2) *(M-2);
      }
    
  printf("%lld\n",cnt);
//     printf("%c%c%c\n",s[0][0],s[1][1],s[2][2]);

return 0;
}


Measured memory_bytes: 128
import kotlin.math.max

fun main() {
    solve()
}

private fun solve() {
    val arr = readLongs()

    var ans = Long.MIN_VALUE
    for (i in 0..1) {
        for (j in 2..3) {
            ans = max(arr[i] * arr[j], ans)
        }
    }
    println(ans)
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of ints

Measured memory_bytes: 36472
import sys
input = sys.stdin.readline
from collections import *

def f(i):
    if C==1:
        if i==mark:
            return 0
        else:
            if X[i]=='0':
                nex = (d[p+1]+pow(2, N-1-i, p+1))%(p+1)
            else:
                nex = (d[p-1]-pow(2, N-1-i, p-1))%(p-1)
    
            res = 1
    
            while nex>0:
                pc = 0
        
                for i in range(20):
                    if (nex>>i)&1:
                        pc += 1
        
                nex %= pc
                res += 1
    
            return res
        
            
    if X[i]=='0':
        nex = (d[p+1]+pow(2, N-1-i, p+1))%(p+1)
    else:
        nex = (d[p-1]-pow(2, N-1-i, p-1))%(p-1)
    
    res = 1
    
    while nex>0:
        pc = 0
        
        for i in range(20):
            if (nex>>i)&1:
                pc += 1
        
        nex %= pc
        res += 1
    
    return res

N = int(input())
X = list(input()[:-1])

if X=='0'*N:
    for i in range(N):
        print(1)
    exit()

C = X.count('1')

for i in range(N):
    if X[i]=='1':
        mark = i
    
p = 0

for Xi in X:
    if Xi=='1':
        p += 1

d = defaultdict(int)

if C==1:
    for i in [p, p+1]:
        for j in range(N):
            if X[j]=='1':
                d[i] += pow(2, N-1-j, i)
else:
    for i in [p-1, p, p+1]:
        for j in range(N):
            if X[j]=='1':
                d[i] += pow(2, N-1-j, i)

for i in range(N):
    print(f(i))

Measured memory_bytes: 92864
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  int before = 0, cnt = 0;
  rep(i, n){
    int h;
    cin >> h;
    if(i){
      if(before > h + 1){
        cout << "No" << endl;
        return 0;
      }else if(before > h){
        cnt++;
        if(cnt >= 2){
          cout << "No" << endl;
          return 0;
        }
      }else if(before != h) cnt = 0;
    }
    before = h;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left
A, B, Q = map(int, input().split())
BIG = 10**10 + 1
S = [-BIG] + sorted([int(input()) for _ in range(A)]) + [BIG*2]
T = [-BIG] + sorted([int(input()) for _ in range(B)]) + [BIG*2]
for _ in range(Q):
  x = int(input())
  shrine_b = bisect_left(S, x)
  shrine_l = S[shrine_b-1]
  shrine_r = S[shrine_b]
  temple_b = bisect_left(T, x)
  temple_l = T[temple_b-1]
  temple_r = T[temple_b]
  print(min(
    x-shrine_l if shrine_l < temple_l else x-temple_l,
    shrine_r-x if shrine_r > temple_r else temple_r-x,
    (x-shrine_l) * 2 + temple_r-x,
    x-shrine_l + (temple_r-x) * 2,
    (shrine_r-x) * 2 + x-temple_l,
    shrine_r-x + (x-temple_l) * 2
  ))

Measured memory_bytes: 14176
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 100005;

int main(){
	int m,k;		
	cin >> m >> k;
	if(k == 0 && m == 1){
		cout << "0 0 1 1"<< '\n';	
	}
	else if(k < (1 << m) && !(m == 1 && k == 1)){
		cu(i,0,1 << m){
			if(i != k){
				cout << i << " ";
			}
		}
		cout << k << " ";
		cd(i,1 << m,0){
			if(i != k){
				cout << i << " ";
			}
		}
		cout << k << " ";
	}
	else{
		cout << -1 << '\n';
	}
}


Measured memory_bytes: 1792
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    S=ST().split()
    S=set(list(S))
    if len(S)==4:
        print("Four")
    else:
        print("Three")
if __name__ == '__main__':
    main()

Measured memory_bytes: 63468
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;

int main(){
	IOS
	int n, k;
	cin >> n >> k;
	cout << ceil((double)(n)/k) << '\n';
}



Measured memory_bytes: 3776
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 2005;
const int mod = 1e9 + 7;
LL n , k;
LL fac[MAXN * MAXN] , inv[MAXN * MAXN] , finv[MAXN * MAXN];
LL C(LL a , LL b) {
	if(a == 0 || b == 0 || a == b) return 1;
	return fac[a] * finv[a - b] % mod * finv[b] % mod;
}
LL dp[MAXN][MAXN];
int main() {
	scanf("%lld %lld" , &n , &k);
	if(k == 1) {
		printf("1");
		return 0;
	}
	fac[0] = 1;
	for (LL i = 1; i <= n * k; ++i) fac[i] = fac[i - 1] * i % mod;
	finv[1] = inv[1] = 1;
	for (LL i = 2; i <= n * k; ++i) inv[i] = (mod - mod / i) * inv[mod % i] % mod , finv[i] = finv[i - 1] * inv[i] % mod;
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= i; ++j) {
			if(j) dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] * C(n * k - (k - 1) * (j - 1) - i - 1 , k - 2) % mod) % mod;
			else dp[i][j] = dp[i - 1][j];
		}
	}
	printf("%lld" , dp[n][n] * fac[n] % mod);
	return 0;
}

Measured memory_bytes: 119540
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;
typedef long long ll;

int main(){
  int ans=0;
  int n[4];
  for(int i=0;i<4;++i)
    cin >> n[i];
  sort(n,n+4);
  if(n[0]==n[1] && n[2]==n[3] )
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}



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

int main()
{
	int n, k;
	cin >> n >> k;
	int a = 1;
	for (int i = 0; i < n; i++)
	{
		if (k > a)
			a *= 2;
		else 
			a += k;
	}
	cout << a << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
int n;
int A[100010];
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n);
  for(int i=1;i<=n;++i) read(A[i]);
  int res=0;
  for(int i=1;i<=n;++i) {
    int p1=i,p2=i;
    while(p1!=n&&A[p1+1]<=A[p1]) ++p1;
    while(p2!=n&&A[p2+1]>=A[p2]) ++p2;
    ++res;
    if(p1>p2) i=p1;
    else i=p2;
  }
  printf("%d\n",res);
  return 0;
}



Measured memory_bytes: 640
cin = open(0).read().strip().split('\n')
n, k = map(int, cin[0].split(' '))
a = list(map(int, cin[1].split(' ')))

ret = float('inf')
for idx in range(2**(n)):
    colors = 0
    res = 0
    left = 0
    for i in range(n):
        if (idx>>i) & 1:
            colors += 1
            res += max(left+1 - a[i] , 0)
            left += 1
        # else:
        #     colors += 1 if left < a[i] else 0

        left = max(a[i], left)

    if colors >= k:
        ret = min(ret, res)

print(ret)

Measured memory_bytes: 3064
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List
import Data.Ord

main :: IO ()
main = do
    [_,k] <- map read . words <$> getLine :: IO [Int]
    a <- map (fst . fromJust . BS.readInt)
        . BS.words <$> BS.getLine :: IO [Int]
    let g = sortOn Down . map length . group . sort $ a
    print $ sum . drop k $ g


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

using namespace std;
// #define int long long
mt19937 rnd(time(0));
typedef long long ll;
typedef long double ld;

// #define _GLIBCXX_DEBUG
#define f first
#define s second
#define pb push_back
#define pii pair<int, int> 
#define vi vector<int>
#define int ll

void solve(){
    int n;
    cin >> n;
    map<pii, int> mp;
    for (int i = 1; i <= n; ++i) {
        int j = i;
        while (j >= 10)
            j /= 10;
        mp[{j, i % 10}]++;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int j = i;
        while (j >= 10)
            j /= 10;
        ans += mp[{i % 10, j}];
    }
    cout << ans << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int t = 1;
    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
    int A, B;

    cin >> A >> B;

    int ans = 1;

    if(B == 1) {
        cout << 0 << endl;
        return 0;
    }

    while (A * ans - (ans - 1) < B)
    {
        ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int bs(long long A, int x){
	int b = -(A+1e3);
	int e = 1e3;
	while(e-b > 1){
		int mid = (b+e)/2;
		int a = (A+mid);
		if(pow(a,5) - pow(mid, 5) > x) e=mid;
		else if(pow(a,5) - pow(mid, 5) < x)b=mid;
		else if(pow(a,5) - pow(mid, 5) == x)return mid;
	}
	return e;
}

int main() {
	int x; cin>>x;
	for(long long i=1; i*i<=x; i++){
		if(x%i==0){
			int b = bs(i , x);
			int a = i+b;
			if(pow(a,5) - pow(b,5) == x){
				cout<<a<<" "<<b<<endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 4092
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[100];
    scanf("%s",s);
    int l=strlen(s);
    int i;
    char a=s[l-1];
    if(l>=3 && l<=100)
    {
        for(i=0; i<l-2; i++)
        {

        }
        cout<<s[0];
        cout<<i;
        cout<<a;

    }
    else
    {
        cout<<s;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int h,w; cin>>h>>w;
	string s[h+5]; rep(i,h) cin>>s[i];
	ll dp[h+5][w+5]; memset(dp,INF,sizeof(dp));
	if(s[0][0]=='#') dp[0][0]=1; else dp[0][0]=0;
	rep(i,h){
		rep(j,w){
			if(i+1<h){
				if(s[i+1][j]=='.') dp[i+1][j]=chmin(dp[i+1][j],dp[i][j]);
				else if(s[i][j]==s[i+1][j]) dp[i+1][j]=chmin(dp[i+1][j],dp[i][j]);
				else dp[i+1][j]=chmin(dp[i+1][j],dp[i][j]+1);
			}
			if(j+1<w){
				if(s[i][j+1]=='.') dp[i][j+1]=chmin(dp[i][j+1],dp[i][j]);
				else if(s[i][j]==s[i][j+1]) dp[i][j+1]=chmin(dp[i][j+1],dp[i][j]);
				else dp[i][j+1]=chmin(dp[i][j+1],dp[i][j]+1);
			}
		}
	}
	rep(i,h){
		rep(j,w) cerr << dp[i][j] << ' ';
		cerr << endl;
	}
	cout << dp[h-1][w-1] << endl;

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
vector<int> adj[N];
long long dp[N][3];
void dfs(int x,int p){
	for(int i=0;i<adj[x].size();i++){
		if(adj[x][i]!=p){
			dfs(adj[x][i],x);
			dp[x][0]*=dp[adj[x][i]][1];
			dp[x][0]%=mod;
			dp[x][1]*=(dp[adj[x][i]][0]+dp[adj[x][i]][1]);
			dp[x][1]%=mod;
		}
	}
}
int main(){
	int n,i,j,k;
	cin>>n;
	for(i=1;i<n;i++){
		dp[i][1]=1;
		dp[i][0]=1;
		cin>>j>>k;
		adj[j].push_back(k);
		adj[k].push_back(j);
	}
	dp[n][0]=1;
	dp[n][1]=1;
	dfs(1,1);
	cout<<(dp[1][0]+dp[1][1])%mod;
}

Measured memory_bytes: 13568
#include <stdio.h>

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
int main(int argc, char **argv) {
    int n = get_uint();
    int fib[45] = {1, 1};
    for(int i = 2; i < 45; ++i) fib[i] = fib[i - 1] + fib[i - 2];
    put_uint(fib[n]);
    putchar_unlocked('\n');
    return 0;
}



Measured memory_bytes: 2108
fn main() {
    proconio::input! {
        n: usize,
        mut a: [i32;n],
    }
    a.sort();
    let mut t=0;
    let s: std::collections::BTreeSet<_>=a.iter().collect();
    for k in 0..n {
        if k>0 && a[k]==a[k-1] || k<n-1 && a[k]==a[k+1] {
            continue;
        }
        let mut v=vec![];
        let mut x=a[k];
        let mut i=2;
        while x>=i*i {
            while x%i==0 {
                v.push(i);
                x/=i;
            }
            i+=1;
        }
        if x>1 {
            v.push(x);
        }
        let mut f=true;
        for b in 0..(1<<v.len())as u32-1 {
            let mut w=1;
            let mut c=b;
            while c>0 {
                w*=v[c.trailing_zeros()as usize];
                c&=c-1;
            }
            if s.contains(&w) {
                f=false;
                break;
            }
        }
        if f {
            t+=1;
        }
    }
    println!("{}",t);
}

Measured memory_bytes: 8264
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int L=1e6+2;
LL cM[L];
LL cC[L];
LL sM[L];
char S[L];
int main() {
	int N,Q;
	scanf("%d%s%d",&N,S+1,&Q);
	for(int i=1;i<=N;i++){
		cM[i]=cM[i-1];
		sM[i]=sM[i-1];
		cC[i]=cC[i-1];
		switch(S[i]){
			case 'M':
				cM[i]++;
				break;
			case 'C':
				cC[i]++;
				sM[i]+=cM[i];
				break;
		}
	}
	for(int q=0;q<Q;q++){
		LL ret=0;
		int k;
		scanf("%d",&k);
		for(int i=1;i<=N;i++){
			if(S[i]=='D'){
				ret+=sM[min(N,i+k-1)]-sM[i];
				ret-=cM[i]*(cC[min(N,i+k-1)]-cC[i]);
			}
		}
		printf("%lld\n",ret);
	}

	return 0;
}



Measured memory_bytes: 24704
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <atcoder/all>
using namespace atcoder;
using namespace std;

int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
    	long long int n, m, a, b;
    	cin >> n >> m >> a >> b;
    	cout << floor_sum(n, m, a, b) << endl;
    }
}






Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

struct union_find{
  vector<int> par,r;

  union_find(int n){
  	par.resize(n);
  	r.resize(n);
  	init(n);
  }

  void init(int n){
    for(int i = 0; i < n; i++) par[i] = i;
    for(int i = 0; i < n; i++) r[i] = 0;
  }

  int find(int x){
    if(par[x] == x) return x;
    else return find(par[x]);
  }

  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(r[x] < r[y]){
      par[x] = y;
    }else{
      par[y] = x;
      if(r[x] == r[y]) r[x]++;
    }
  }

  bool same(int x,int y){
  	return find(x) == find(y);
  }
};

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

	vector<pair<int,int> > e(m);

	for(int i = 0; i < m; i++){
		cin >> e[i].first >> e[i].second;
		e[i].first--;
		e[i].second--;
	}

	int ans = 0;
	for(int i = 0; i < m; i++){
		union_find uf(n);

		for(int j = 0; j < m; j++){
			if(i!=j && !uf.same(e[j].first,e[j].second)){
				uf.unite(e[j].first,e[j].second);
			}
		}
		set<int> s;
		for(int j = 0; j < n; j++){
			if(uf.par[j]==j) s.insert(uf.par[j]);
		}
		if(s.size()>1) ans++;
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{
  string s;
  cin >> s;
  if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


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

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef __int128 INT;
const int mod = 998244353;
map<INT,LL> ff[128];
map<INT,LL> gg[128];
vector<int> divisor[128];
constexpr INT one = 1;
/*
inline LL count(INT x){
    LL a = x&((one<<64)-1);
    LL b = x>>64;
    int c = __builtin_popcountll(a)+__builtin_popcountll(b);
    return (LL)((one<<c)%mod);
}
*/
void print(INT a,int N){
    REP(i,N){
        cout<<(int)(a&1);
        a>>=1;
    }
}
LL f(INT a,int N);
LL g(INT a,int N);

LL g(INT a,int N){
    if(gg[N].count(a))return gg[N][a];
    if(N==1)return 1+a;
    LL ret = 0;
    for(auto &d:divisor[N]){
        const INT mask = (one<<d)-1;
        INT nxt = mask;
        INT b = a;
        for(int i = 0;i < N;i+=d){
            nxt&=b&mask;
            b>>=d;
        }
        ret+=f(nxt,d);
    }
    return gg[N][a] = ret%mod;
}
LL f(INT a,int N){
    if(ff[N].count(a))return ff[N][a];
    vector<LL> dp(N+1,0);
    dp[0] = 1;
    INT b = a;
    REP(i,N){
        INT c = 2;
        FOR(j,i+1,N+1){
            dp[j]+=dp[i]*g(b&(c-1),j-i);
            dp[j]%=mod;
            c<<=1;
        }
        b>>=1;
    }    
    return ff[N][a] = dp.back()%mod;
}
int main(){
    string s;
    cin>>s;
    int N = s.size();
    INT in = 0;
    REP(i,N){
        in<<=1;
        in+=s[i]-'0';
    }
    FOR(i,1,128){
        FOR(j,1,i){
            if(i%j==0)divisor[i].pb(j);
        }
    }
    cout<<f(in,N)<<endl;
    return 0;
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l,r,d;
    cin>>l>>r>>d;
    int count=0;
    for(int i=l/d;i<=r;i++)
    {
       if(d*i>=l && d*i<=r)
            count++;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3576
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict
from operator import itemgetter

def main():
    N, M = LI()
    A = LI()
    BC = []
    for _ in range(M):
        BC.append(LI())
    for a in A:
        BC.append([1, a])
    BC.sort(reverse=True, key=itemgetter(1))
    cnt = 0
    ans = 0
    for B, C in BC:
        if cnt + B >= len(A):
            ans += C * (len(A) - cnt)
            break
        ans += C * B
        cnt += B
    return ans

print(main())

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

using namespace std;

const int NULLNodeKey = 2000000001;
const int heap_offset = 1;

int get_left(vector<int> binary_heap, int index) {
  int left_child_index = 2 * index;

  if(left_child_index > binary_heap.size() - heap_offset) {
    return NULLNodeKey;
  }

  return binary_heap[left_child_index];
}

int get_right(vector<int> binary_heap, int index) {
  int right_child_index = 2 * index + 1;

  if(right_child_index > binary_heap.size() - heap_offset) {
    return NULLNodeKey;
  }

  return binary_heap[right_child_index];
}

int get_parent(vector<int> binary_heap, int index) {
  int parent_index = (index % 2 == 0 ? index : index - 1) / 2;

  if(parent_index < 1) {
    return NULLNodeKey;
  }

  return binary_heap[parent_index];
}

int main() {
  int heap_size;
  vector<int> binary_heap;

  cin >> heap_size;
  binary_heap.resize(heap_size + 1);

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


  for(int i = 1; i <= heap_size; i++ ) {
    cout <<  "node " << i << ": ";
    cout << "key = " << binary_heap[i] << ", ";

    int parent = get_parent(binary_heap, i);
    if(parent != NULLNodeKey) {
      cout << "parent key = " << parent << ", ";
    }

    int left = get_left(binary_heap, i);
    if(left != NULLNodeKey) {
      cout << "left key = " << left << ", ";
    }

    int right = get_right(binary_heap, i);
    if(right != NULLNodeKey) {
      cout << "right key = " << right << ", ";
    }

    cout << endl;
  }
}



Measured memory_bytes: 3108
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int INF = 10000000;

int main(int argc, char *argv[])
{
  int N, K;
  string S;
  cin >> N;
  cin >> S;
  cin >> K;
  char c = S[K - 1];

  for (int i = 0; i < N; i++) {
    if (c == S[i]) {
      cout << c;
    } else {
      cout << "*";
    }
  }
  puts("");

  return 0;
}


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

#define int long long
#define inf 1000000007LL

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)

class Dinic {
public:
  vector<vector<pair<int, int>>> v;
  vector<int> e;

  vector<int> k;
  vector<int> j;

  Dinic(int n) {
    v.resize(n);
    k.resize(n);
    j.resize(n);
  }
  void add_edge(int a, int b, int atob, int btoa = 0) {
    v[a].push_back(make_pair(b, e.size()));
    e.push_back(atob);
    v[b].push_back(make_pair(a, e.size()));
    e.push_back(btoa);
  }
  void dyk(int s) {
    for(auto& i : k) {
      i = inf;
    }
    queue<pair<int, int>> pq;
    pq.push(make_pair(0, s));
    while(!pq.empty()) {
      int w = pq.front().first;
      int b = pq.front().second;
      pq.pop();
      if(k[b] > w) {
        k[b] = w;
        for(auto i : v[b]) {
          if(e[i.second] > 0) {
            pq.push(make_pair(w + 1, i.first));
          }
        }
      }
    }
  }
  int dfs(int s, int t, int p, int c) {
    if(p == t) {
      return c;
    }
    int all = 0;
    while(c > all && j[p] < v[p].size()) {
      if(k[v[p][j[p]].first] == k[p] + 1) {
        int r = dfs(s, t, v[p][j[p]].first, min(c - all, e[v[p][j[p]].second]));
        e[v[p][j[p]].second] -= r;
        e[v[p][j[p]].second ^ 1] += r;
        if(r < c - all) {
          j[p]++;
        }
        all += r;
      }
      else {
        j[p]++;
      }
    }
    return all;
  }
  int solve(int s, int t) {
    int all = 0;
    while(1) {
      dyk(s);
      for(auto& i : j) {
        i = 0;
      }
      int r = dfs(s, t, s, inf);
      if(r == 0) {
        return all;
      }
      all += r;
    }
  }
};

pair<int, int> d[334334];

signed main() {
  int n;
  cin >> n;
  int ma = 0;
  int mi = inf;
  rep(i, n) {
    cin >> d[i].first >> d[i].second;
    ma = max(ma, max(d[i].first, d[i].second));
    mi = min(mi, min(d[i].first, d[i].second));
  }
  int mami = inf;
  int mima = 0;
  rep(i, n) {
    mami = min(mami, max(d[i].first, d[i].second));
    mima = max(mima, min(d[i].first, d[i].second));
  }
  int ans = (ma - mami) * (mima - mi);
  int h = inf;
  int ww = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
  rep(i, n) {
    pq.push(make_pair(min(d[i].first, d[i].second), i));
    ww = max(ww, min(d[i].first, d[i].second));
  }
  rep(i, n) {
    auto w = pq.top();
    pq.pop();
    h = min(h, ww - w.first);
    if(max(d[w.second].first, d[w.second].second) == w.first) {
      break;
    }
    ww = max(ww, max(d[w.second].first, d[w.second].second));
    pq.push(make_pair(max(d[w.second].first, d[w.second].second), w.second));
  }
  ans = min(ans, (ma - mi) * h);
  cout << ans << endl;
}


Measured memory_bytes: 10608
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	string str;
	cin>>str;
	int i;
	for(i=0;i<str.size();i++){
		str[i]-=3;
		if(str[i]<'A')str[i]+=26;
		cout<<str[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
// #define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
// void fileio()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }
 
 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}
void selfadd(int& a, int b){
    a = a+b;
    if(a>=mod)
        a = a-mod;
}
void selfsub(int& a, int b){
    a = a-b+mod;
    if(a>=mod)
        a = a-mod;
}  
const int N = 200005; 
 
int dp[10003][103][2];
int D;
string s;
int rec(int index,int d, int state){
    
    if(index==s.size()){
        if(d==0)
            return 1;
        else
            return 0;
    }
    if(dp[index][d][state] != -1){
        return dp[index][d][state];
    }
 
    int a = s[index]-'0';
 
    int ans = 0;
    if(state){
        for(int i=0;i<a;i++){
            ans  = ans + rec(index+1,(d+i)%D, 0); 
            if(ans > mod)
                ans -= mod;
        }
        ans = ans +rec(index+1,(d+a)%D,1);
        if(ans > mod)
            ans -= mod;
    }
    else{
        for(int i=0;i<=9;i++){
            ans  = ans +rec(index+1,(d+i)%D, 0); 
            if(ans > mod)
                ans -= mod;
        }
    }
    // if(ans )
    // cout<<index<<" "<<d<<" "<<state<<" "<<ans<<endl;
    return dp[index][d][state] = ans;
 
}

 
int32_t main()
{
    // fileio();
    fast;
    cin>>s;
    cin>>D;
    // memset(dp,-1,sizeof(dp));
    for(int i=0;i<10003;i++){
        for(int j = 0;j<103;j++){
            for(int k = 0;k<2;k++){
                dp[i][j][k] = -1;
            }
        }
    }
    cout<<(rec(0,0,1)-1)%mod;
    return 0;
} 

Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int ans=0;
	int a,b;
	cin>>a>>b;
	int cnt=1;
	while(cnt<b){
		cnt+=a-1;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3592
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

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

	if (n%k == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define UNVISITED -1
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
using namespace std;

typedef long long int64;
typedef pair<int, int> ii;

int main(){ _
  int n;  cin >> n;
  string last, cur;  cin >> last;
  set<string> pass;
  pass.insert(last);
  bool flag = true;
  for(int i = 1; i < n; ++i) {
    cin >> cur;
    if(pass.count(cur)) flag = false;
    if(cur.front() != last.back()) {
      // cout << "front = " << cur.front() << " back = " << last.back() << endl;
      flag = false;
    }
    pass.insert(cur);
    last = cur;
  }

  if(flag)  cout << "Yes" << endl;
  else  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, K) = readInputLine().split(" ").map{it.toInt()}

    println((N - 1) / (K - 1) + if (((N - 1) % (K - 1)) != 0) 1 else 0)
}

fun readInputLine(): String {
    return readLine()!!
}


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

using namespace std;

int main(int argc, char *argv[]) {
  int n, m;
  vector< pair<int, int> > gem;

  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      gem.push_back(pair<int, int>(a, b));
    }

    cin >> m;
    int x = 10, y = 10;
    for (int i = 0; i < m; i++) {
      char news;
      int len;
      cin >> news >> len;
      if (news == 'N') {
        vector< pair<int, int> >::iterator itr = find(gem.begin(), gem.end(), pair<int, int>(x, y));
        if (itr != gem.end()) {
          gem.erase(itr);
        }
        for (int j = 0; j < len; j++) {
          y++;
          itr = find(gem.begin(), gem.end(), pair<int, int>(x, y));
          if (itr != gem.end()) {
            gem.erase(itr);
          }
        }
      } else if (news == 'E') {
        vector <pair<int, int> >::iterator itr = find(gem.begin(), gem.end(), pair<int, int>(x, y));
        if (itr != gem.end()) {
          gem.erase(itr);
        }
        for (int j = 0; j < len; j++) {
          x++;
          itr = find(gem.begin(), gem.end(), pair<int, int>(x, y));
          if (itr != gem.end()) {
            gem.erase(itr);
          }
        }
      } else if (news == 'W') {
        vector <pair<int, int> >::iterator itr = find(gem.begin(), gem.end(), pair<int, int>(x, y));
        if (itr != gem.end()) {
          gem.erase(itr);
        }
        for (int j = 0; j < len; j++) {
          x--;
          itr = find(gem.begin(), gem.end(), pair<int, int>(x, y));
          if (itr != gem.end()) {
            gem.erase(itr);
          }
        }
      } else {
        vector <pair<int, int> >::iterator itr = find(gem.begin(), gem.end(), pair<int, int>(x, y));
        if (itr != gem.end()) {
          gem.erase(itr);
        }
        for (int j = 0; j < len; j++) {
          y--;
          itr = find(gem.begin(), gem.end(), pair<int, int>(x, y));
          if (itr != gem.end()) {
            gem.erase(itr);
          }
        }
      }
    }
    cout << (gem.empty() ? "Yes" : "No") << endl;
    gem.clear();
  }
  return 0;
}

Measured memory_bytes: 1192