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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll n, k;

ll gcdSearch(vll a, ll gcd){
  vll modPlus(n), modMinus(n);
  ll A, B;
  A = B = 0;
  REP(i, n){
    modPlus[i] = a[i] % gcd;
    //modMinus[i] = gcd - a[i] % gcd;
    B += gcd - modPlus[i];
  }
  sort(modPlus.begin(), modPlus.end());
  //sort(modMinus.begin(), modMinus.end());

  ll mpIndex, mmIndex, counter, kCounter;
  mpIndex = mmIndex = counter = kCounter = 0;
  ll need = LLINF;
  REP(i, n){
    A += modPlus[i];
    B -= gcd - modPlus[i];
    need = min(need, max(A, B));

    //if(modPlus[mpIndex] > modMinus[mmIndex]){
    //  modPlus[mpIndex] -= modMinus[mmIndex];
    //  kCounter += modMinus[mmIndex];
    //  mmIndex++;
    //  counter++;
    //}
    //else if(modPlus[mpIndex] < modMinus[mmIndex]){
    //  modMinus[mmIndex] -= modPlus[mpIndex];
    //  kCounter += modPlus[mpIndex];
    //  mpIndex++;
    //  counter++;
    //}
    //else{
    //  kCounter += modPlus[mpIndex];
    //  mmIndex++;
    //  mpIndex++;
    //  counter += 2;
    //}
    //if(kCounter > k)
    //  return false;
    //if(counter == n)
    //  return true;
  }
  return need;

}

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

  cin >> n >> k;
  vll a(n);
  ll sum = 0;
  REP(i, n){
    cin >> a[i];
    //sum += a[i];
  }

  sum = accumulate(a.begin(), a.end(), 0LL);
  set<ll> gcd;
  for(ll i = 1; i*i <= sum; i++){
    if(sum % i == 0){
      gcd.insert(i);
      gcd.insert(sum/i);
    }
  }

  ll ans = 1;
  for(ll x : gcd){
    if(gcdSearch(a, x) <= k)
      ans = max(ans, x);
  }

  cout << ans << "\n";
  
  
}


Measured memory_bytes: 384
from sys import stdin

def main():

    input = stdin.readline

    N = int(input())
    A = list(map(int,input().split()))

    over_num = 10 ** 18

    ans = 1

    if A.count(0) > 0:
        print("0")
        return

    for i in A:
        ans = ans * i
        if ans > over_num:
            print("-1")
            return

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 21600
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	ll x,y,a,b,c,ans=0;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a),q(b),r(c);
    for(int i=0;i<a;i++) cin >> p[i];
    for(int i=0;i<b;i++) cin >> q[i];
    for(int i=0;i<c;i++) cin >> r[i];
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    sort(q.begin(),q.end());
    reverse(q.begin(),q.end());
    for(int i=0;i<x;i++) r.push_back(p[i]);
    for(int i=0;i<y;i++) r.push_back(q[i]);
    sort(r.begin(),r.end());
    reverse(r.begin(),r.end());
    for(int i=0;i<x+y;i++) 
	ans+=r[i];
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5872
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    string ret = "NO";
    for (ll i = 0; i < N; i++) {
        ll mn = C * (N - 1 - i) - D * i;
        ll mx = D * (N - 1 - i) - C * i;
        if (B - A >= mn && B - A <= mx) {
            ret = "YES";
        }
    }

    cout << ret;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N, M;
vv<int> graph;

vector<bool> visited;
vector<int> vpre;

void bfs(int s) {
    visited.assign(N, false);
    vpre.assign(N, -1);
    queue<pair<int, int>> que;
    que.emplace(s, -1);

    while (!que.empty()) {
        auto v = que.front();
        que.pop();

        visited[v.first] = true;
        vpre[v.first] = v.second;

        if (v.first == s && v.second != -1) {
            break;
        }

        for (int u : graph[v.first]) {
            if (visited[u] && u != s) continue;

            que.emplace(u, v.first);
        }
    }
}

int main() {
    cin >> N >> M;
    graph.resize(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
    }

    int n_small = INF;
    vector<int> small;
    rep(s, 0, N) {
        bfs(s);

        if (vpre[s] != -1) {
            vector<int> tmp;
            tmp.push_back(s);
            int v = vpre[s];
            while (v != s) {
                tmp.push_back(v);
                v = vpre[v];
            }

            if (tmp.size() < n_small) {
                n_small = tmp.size();
                small = move(tmp);
            }
        }
    }

    if (n_small != INF) {
        write(n_small);
        sort(all(small));
        rep(i, n_small) {
            write(small[i] + 1);
        }
    }
    else {
        write(-1);
    }
}

Measured memory_bytes: 384
// ABC 152-D
// 2020.1.19 bal4u

#include <stdio.h>

#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int f1[100], f2[100];

void calc(int n) {
	int k = n % 10;
	while (n >= 10) n /= 10;
	++f1[10*k + n], ++f2[n*10 + k];
}

int main()
{
	int i, N, ans;
	
	N = in();
	while (N) calc(N--);

	ans = 0;
	for (i = 0; i < 100; ++i) ans += f1[i] * f2[i];
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

int Hit(int *rui){
	rui[0]++;
	// 塁を進める
	FOR(i, 1, 4){
		if (rui[i - 1]==2){
			rui[i]++;
			rui[i - 1] = 1;
		}
	}
	if (rui[3]!=0){
		rui[3] = 0;
		return 1;
	}
	return 0;
}

int Homerun(int *rui){
	int ret = 1;
	FOR(i, 0, 4)
		if (rui[i])
			ret++;
	return ret;
}

int main(){
	fastIO;
	int n, outCount = 0, tokuten = 0;
	string in;
	// rui[0]〜rui[2] = 1塁〜3塁, rui[3] = 本塁
	// 各値はその塁にいる人数(0〜2)
	int rui[4] = {};
	cin >> n;
	while (cin >> in){
		if (in == "OUT")
			outCount++;
		if (outCount < 3){
			if (in == "HIT"){
				tokuten += Hit(rui);
			}
			else if (in == "HOMERUN"){
				tokuten += Homerun(rui);
				FOR(i, 0, 4)	rui[i] = 0;
			}
		}
		else{
			cout << tokuten << endl;
			FOR(i, 0, 4)	rui[i] = 0;
			tokuten = 0;
			outCount = 0;
		}
	}
	return 0;
}

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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'




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


const int MOD = 1000000007;

//////////////////////////////////////////


int n;
string s;

void Input() {

    cin >> n;
    cin >> s;
}



void Solve() {


    if(n&1) {

        cout << "No" << endl;
        return ;
    }
    string s1 = "", s2 = "";
    int r = n/2;
    for(int i = 0; i < n/2; i++) {

        s1 += s[i];
        s2 += s[r];
        r++;
    }

    //cout << s1 << " " << s2 << endl;
    if(s1 == s2) cout << "Yes" << endl;
    else cout << "No" << endl;

}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}


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

int main(){
  int a,b;
  cin >> a >> b;
  if(a >= b){
    rep(i,a) cout << b;
    cout << endl;
  }
  else rep(i,b) cout << a;
  cout << endl;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
A = []
B = []
for i in range(H):
    a = list(input())
    if a != ["."]*W:
        A.append(a)
for i in range(W):
    cnt = 0
    for j in range(len(A)):
        if A[j][i] != '.':
            cnt += 1
    if cnt == 0:
        B.insert(0,i)
for i in range(len(A)):
    for j in range(len(B)):
        del A[i][B[j]]
for i in range(len(A)):
    ans = "".join(A[i])
    print(ans)



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

int main(){
    int a, b;
    cin >> a >> b;
    int ans = b;
    if(a<=5) ans = 0;
    else if(a<=12) ans = b/2;
    cout << ans << endl;
}


Measured memory_bytes: 256
A=abs;p=eval('list(map(int,input().split())),'*int(input()));x,y,h=[x for x in p if x[2]][0]
for I in range(10201):j,i=I//101,I%101;H=h+A(x-j)+A(y-i);print(*(j,i,H)*all(u==max(H-A(s-j)-A(t-i),0)for s,t,u in p))

Measured memory_bytes: 3928
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	N := len(s)
	var cnt int64
	for i := 0; i < N/2; i++ {
		if s[i] != s[N-1-i] {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    cout << t+s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;


int main()
{
	int N;
	cin >> N;
	cout << (N + 1) / 2 * (N / 2) << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

const int MAX = 10000000;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/****** define constant end ********/
/****** define variable start ******/
string n;
/******* define variable end *******/
int solve() {
	cin >> n;
	ll wa = 0;
	REP(i, n.size()){
		wa += stol(n.substr(i, 1));
	}
	if(wa % 9 == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3740
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String[] hw = sc.nextLine().split(" ");
		int h = Integer.parseInt(hw[0]) + 1;
		int w = Integer.parseInt(hw[1]) + 2;

		for (int i = 0; i <= h; i++) {
			if (i == 0 || i == h) {
				System.out.println(new String(new char[w]).replace("\0", "#"));
			}else {
				System.out.println("#" + sc.nextLine() + "#");
			}
		}
	}
}


Measured memory_bytes: 28160
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Tuple struct {
	S string
	V int
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	list := make([]Tuple, N)
	total := 0
	for i := 0; i < N; i++ {
		list[i].S = sc.Next()
		list[i].V = sc.NextInt()
		total += list[i].V
	}
	S := sc.Next()
	p := 0
	for i := 0; i < len(list); i++ {
		p += list[i].V
		if list[i].S == S {
			fmt.Println(total - p)
			return
		}
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int a,b,c;
	
	int i=0;
	int j=0;
	
	scanf("%d %d %d",&a,&b,&c);
	
	for(i=a;i<=b;i++){
	
		if(c%i == 0)
		{
			j++;
		}
	}
	
	printf("%d\n",j);
	

	
	return (0);
}

Measured memory_bytes: 596
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d  long double
#define d long double
#define pii pair<int,int>
#define pb push_back
#define N 200003
#define inf (int)1e18
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7;

 
signed main()
{
    haha
    d l;
    cin>>l;
    d x=l/3;
    cout<<setprecision(12)<<fixed;
    cout<<x*x*x;
   
    
   
 
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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

const ll MRINF = 5000000000000000;

int main() {

  ll A, B, K;
  cin >> A >> B >> K;
  map<ll, ll> ans;

  if(B-A <= K){
    ll res = A;
    while(res <= B){
      cout << res << endl;
      res++;
    }
    return 0;
  }
  REP(i, K){
    ans[A+i]++;
  }
  for(ll i=B; i>B-K; i--){
    ans[i];
  }
  for(auto itr=ans.begin(); itr != ans.end(); itr++){
    cout << itr->first << endl;
  }
  
    

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

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

int main(void) {
    int n, k, ans = 0;
    map<int, int> ball;
    vector<int> count;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (!ball[a]) ball[a] = 1;
        else ball[a]++;
    }
    for (auto it = ball.begin(); it != ball.end(); it++)
        count.push_back(it->second);
    sort(count.begin(), count.end());
    if (ball.size() <= k) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < ball.size() - k; i++)
        ans += count[i];
    cout << ans << endl;
}


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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int r;
  cin >> r;
  out(3 * r * r);
  return 0;
}


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

string s;
int k;
string ans[6];

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

    for (int i = 0; i <= k; i++) {
        ans[i] = "~";
    }

    int l = s.length();
    for (int i = 0; i < l; i++) {
        for (int j = 1; j <= l - i; j++) {
            string tmp = s.substr(i,j);
            if (ans[k-1] <= tmp) break;
            int I;
            for (I = 0; I < k; I++) {
                if (ans[I] == tmp) break;
            }
            if (I == k) {
                ans[k] = tmp;
                sort(ans, ans + k + 1);
            }
        }
    }

    cout << ans[k-1] << endl;

    return 0;
}

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

long long n;
vector<long long> nms;

const long long MXN = 3005;
long long dp[MXN][MXN];

long long best(long long l, long long r) {
	if (l > r) return 0;
	if (l == r) return nms[l];
	if (l + 1 == r) {
		return max(nms[l], nms[r]) - min(nms[l], nms[r]);
	}
	if (dp[l][r] != -1) return dp[l][r];
	return dp[l][r] = max(nms[l] - best(l+1, r), nms[r] - best(l, r-1));
}

int main() {
	
	for (int i=0; i<MXN; i++) for (int j=0; j<MXN; j++) dp[i][j] = -1;
	
	cin >> n;
	for (int i=0; i<n; i++) {
		long long x;
		cin >> x;
		nms.push_back(x);
	}
	cout << best(0, n-1) << endl;
	
}




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

using namespace std;

#define MOD 1000000007
#define deb(x) cout << #x << " = " << x << endl
#define deb2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.1415926535897932384626

typedef long long ll;

void solve()
{
    cout<<"\n";
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    ll x,k,d;
    cin>>x>>k>>d;
    ll temp = k;

    if(x<0)
    {
            ll taken = (abs(x))/d;
            k -= taken;
            if(k<=0)
            {
                cout<<abs(x + d*temp);
                return 0;
            }
            ll steps = x + ((abs(x))/d)*d;

            if(k&1LL)
            {
                cout<<abs(steps+d);
            }
            else
            {
                cout<<abs(steps);
            }
    }
    else
    {
        k -= ((x/d));
        if(k<=0)
        {
            cout<<x - d*temp;
            return 0;
        }
        ll steps = x - (x/d)*d;

        if(k&1LL)
        {
                cout<<abs(steps-d);
        }
        else cout<<steps;
    }
    

    return 0;
}

Measured memory_bytes: 3540
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    private static final String ex = "19\n" +
        "100";

    public static void main(String[] args) {
        System.out.println(solve(new Scanner(System.in)));

//        System.out.println(solve(new Scanner(ex)));
    }

    private static int solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());
        int A = Integer.parseInt(scanner.nextLine());

        return N * N - A;
    }
}


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

using namespace std;
using ll = long long;
using lli = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vlli = vector<lli>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define all(v) v.begin(), v.end()
#define debug(x) cout << x << endl
#define vout(v) rep(i, v.size()) cout << v[i] << " ";

string S;

void solve() {
	if (S.size() == 6 && S[2] == S[3] && S[4] == S[5]) {
		cout << "Yes";
	} else {
		cout << "No";
	}
}

int main() {
	cin >> S;

	solve();
	return 0;
}

Measured memory_bytes: 256
n,m=[int(i) for i in input().split()]

ans=[None]*n
muri=0
for i in range(m):
    s,c=[int(i) for i in input().split()]
    if ans[s-1]==None or ans[s-1]==str(c):
        ans[s-1]=str(c)
    else:
        muri+=1
        
        
if ans[0]=="0" and n!=1:
    muri+=1
if muri==0:
    for i in range(n):
        if i==0:
            if ans[0]==None:
                if n==1:
                    ans[0]="0"
                else:
                    ans[0]="1"
        else:
            if ans[i]==None:
                ans[i]="0"
    print("".join(ans))
else:
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N;
string s;

int main(void){
    
    scanf("%d", &N);
    cin >> s;
    
    int wsum = 0, esum = 0;
    vector<int> w, e;
    for(int i = 0; i < N; ++i){
        if(s[i] == 'W') ++wsum;
        if(s[i] == 'E') ++esum;
        w.push_back(wsum);
        e.push_back(esum);
    }
    
    int ans = INT_MAX;
    for(int i = 0; i < N; ++i){
        if(i == 0) ans = min(ans, e[N - 1] - e[i]);
        else if(i == N - 1) ans = min(ans, w[i - 1]);
        else ans = min(ans, w[i - 1] + e[N - 1] - e[i]);
    }
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 6004
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

const int maxm = 2e5+5;
LL n, k;

LL buf[maxm];

bool check(LL x) {
    LL cnt = 0, i, j;
    for(i = 0; i < n; ++i) {
        if(buf[i]*buf[i] <= x) cnt--;
        if(buf[i] > 0) {
            j = x / buf[i] + 1;
            while(j*buf[i] > x)--j;
            LL pos = upper_bound(buf, buf+n, j) - buf;
            cnt += pos; 
        } else if(buf[i] < 0) {
            j = x / buf[i] - 1;
            while(j*buf[i]>x)++j;
            LL pos = lower_bound(buf, buf+n, j) - buf;
            cnt += n - pos;
        } else {
            if(x >= 0) cnt += n;
        }
    }
    cnt /= 2;
    return cnt >= k;
}

void run_case() {
    cin >> n >> k;
    for(int i = 0; i < n; ++i) cin >> buf[i];
    sort(buf, buf+n);
    LL l = -(1LL<<60), r = 1LL<<60, ans, mid;
    while(l <= r) {
        mid = (l+r)>>1;
        if(check(mid)) {
            ans = mid;
            r = mid-1;
        } else
            l = mid+1;
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    //cout.setf(ios_base::showpoint);cout.precision(8);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int main(void)
{
    int x,a,b;
    cin >> x >> a >> b;
    if(x * a < b){cout << x * a << endl;}
    else{cout << b << endl;}
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

i = N - 1
k = 0

while i >= 0:

    if b[i] <= a[i+1]:
        k += b[i]
    elif a[i+1] < b[i] <= a[i] + a[i+1]:
        k += b[i]
        a[i] = a[i] + a[i+1] - b[i]
    else:
        k += a[i] + a[i+1]
        a[i] = 0

    i -= 1

print(k)

Measured memory_bytes: 18476
#include<string>
#include<iostream>

using namespace std;

int main()
{
	string s;	getline(cin,s);

	for(int i=0;i<s.length();i++){
		if     (s[i]=='a' && s.substr(i+1,4)=="pple")	s.replace(i,5,"peach");
		else if(s[i]=='p' && s.substr(i+1,4)=="each")	s.replace(i,5,"apple");
	}

	cout<<s<<endl;

	return 0;
}

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

using namespace std;
#define vsort(v) sort(v.begin(), v.end());
#define vunique(v) unique(v.begin(), v.end());
#define mp make_pair
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  char str[21],rts[21];

  scanf("%s",str);

  int i=0;
  while(str[i]!='\0'){
    i++;
  }

  int j=0;
  for(j;j<i;j++){
    rts[j]=str[i-j-1];
  }

  printf("%s\n",rts);


  return 0;
}

Measured memory_bytes: 0
class Union:
  def __init__(s, num):
    s.T = [-1 for i in range(num)]
 
  def root(s, x):
    if s.T[x] < 0: return x, -s.T[x]
    t, k = s.root(s.T[x])
    s.T[x] = t
    return t, k
 
  def merge(s, x, y):
    an, am = s.root(x)
    bn, bm = s.root(y)
    if an == bn: return False
    if am < bm: an, bn  = bn, an
    s.T[an] += s.T[bn]
    s.T[bn] = an
    return True
 
  def size(s, x):
    return s.root(x)[1]

  def same(s, x, y):
    return s.root(x)[0] == s.root(y)[0]

N = int(input())
uv = [list(map(int, input().split())) for _ in range(N - 1)]

for i in range(N - 1):
  u, v = uv[i]
  if u > v:
    uv[i][0] = v
    uv[i][1] = u
uv.sort()
L = [[] for _ in range(N)]
D = [[] for _ in range(N)]
for u, v in uv:
  L[u - 1].append(v - 1)
  D[v - 1].append(u - 1)

uni = Union(N)

T = [0] * N
T[0] = 1
n = 1
for i in range(1, N):
  if len(D[i]) == 0:
    n += 1
  else:
    cnt = 0
    R = {}
    for v in D[i]:
      t, k = uni.root(v)
      if t not in R:
        cnt += 1
        R[t] = 1
      uni.merge(i, v)
    n -= cnt - 1
  T[i] = n

s = sum(T)

ans = s
for i in range(1, N):
  s -= 1
  if len(L[i - 1]) != 0:
    k = L[i - 1][0]
    s -= k - i
    for j in range(1, len(L[i - 1])):
      s += N - L[i - 1][j]
  else:
    s -= N - i
  ans += s

print(ans)
  

Measured memory_bytes: 170112
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,a[100111];
int main()
{
	get1(n);
	int last=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		get1(a[i]);
		if(a[i]!=i)
		{
			ans+=(i-last)/2;
			last=i;
		}
	}
	ans+=(n+1-last)/2;
	printendl(ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include<cstring>
#include<stdio.h>
using namespace std;
const int MAX = 1e5 + 5;
int Xi[MAX]; int Li[MAX];int yes[MAX] ;
int cmp(const void *a, const void *b)
{
	return *(char *)a - *(int *)b;
}
int  main() {
	int N = 0, M = 0;
	cin >> N >> M; 
	if (M >= N)cout << "Yes"; else cout << "No";



	return 0;

}

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

int main(){
  string s;  cin >> s;
  ll n = s.size();
  ll kaz = 0;
  queue<ll> q;
  for(ll i = 0; i < n; i++){
    if(s[i] == 'B'){
      kaz++;
      q.push(i);
    }
  }
  
  ll ans = 0LL;
  for(ll i = kaz; i >= 1; i--){
    ll now = q.front();  q.pop();
    ans += n - i - now;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 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; }

template <typename T>
struct UnionFind
{
    vector<T> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool connected(T x, T y)
    {
        return (find(x) == find(y));
    }

    bool unite(T x, T y)
    {
        x = find(x), y = find(y);
        if (x == y)
            return false;
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    int find(T k)
    {
        if (data[k] < 0)
            return k;
        return (data[k] = find(data[k]));
    }
    int size(T k)
    {
        return (-data[find(k)]);
    }
};

int N, M;

int main()
{
    cin >> N >> M;
    UnionFind<int> uf(N);
    for (int i = 0; i < M; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        uf.unite(a, b);
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (uf.connected(0, i) == false)
        {
            ans++;
            uf.unite(0, i);
        }
    }
    cout << ans + 1 << endl;
}


Measured memory_bytes: 640
n = int(input())
s = sorted([input() for i in range(n)])

m = int(input())
t = sorted([input() for j in range(m)])

ans = 0

for i in range(n):
    name = s[i]
    count = s.count(name) - t.count(name)
    if count > ans:
        ans = count

print(ans)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int n;cin >>n;
    ll cnt=0;
    int a=0;
    int b=0;
    int ab=0;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        if (s.front() == 'B' && s.back() == 'A')ab++;
        else if (s.front() == 'B')b++;
        else if (s.back() == 'A')a++;
        for (int j = 0; j < (int) s.size(); ++j) {
            if (s.substr(j, 2) == "AB")cnt++;
        }
    }
    if(ab>0) {
        cnt += ab - 1;
        if(a>0){
            cnt++;
            a--;
        }
        if(b>0){
            cnt++;
            b--;
        }
    }
    cnt+=min(a,b);
    cout <<cnt<<endl;
}


Measured memory_bytes: 3632
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		A[i] *= -1;
	}
	vector<int> seq(N, 1 << 30);
	for (int i = 0; i < N; ++i) {
		*lower_bound(seq.begin(), seq.end(), A[i] + 1) = A[i];
	}
	cout << lower_bound(seq.begin(), seq.end(), 1 << 30) - seq.begin() << endl;
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl
 
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; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dx[8] = {0,1,0,-1, 1, -1, 1, -1}, dy[8] = {1,0,-1,0,1,1,-1,-1};

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

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{ 
  ll N, K;
  cin >> N >> K;
  
  vector<ll> A(N);
  REP(i, N) { 
      cin >> A[i];
  }
  
  ll left = 1;
  ll right = 1e9;
  while(right >= left) {
    ll mid = (left + right) / 2;
    ll tK = K+N;
    bool flag = false;
    REP(i, N) {
      ll n = (A[i] + mid -1) / mid;
      if (n <= tK) {
        tK -= n;
      } else {
        i = N;
        flag = true;   
      }
    }
    if (flag) {
      left = mid+1;
    } else {
      right = mid-1;
    }
  }
  cout << left << endl;
  return 0;
} 


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

#define int long long
const int maxn = 2e5 + 5, B = (1 << 30) + 7, mod = (1 << 30) + 3;
int a[maxn], b[maxn], difa[maxn], difb[maxn], hasha[maxn], hashb, pb[maxn];

int getH(int l, int r) {
	return (hasha[r] - hasha[l] * pb[r - l] % mod + mod) % mod;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	pb[0] = 1;
	for (int i = 1; i < maxn; i++)
		pb[i] = B * pb[i - 1] % mod;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++) {
		difa[i] = a[i] ^ a[(i + 1) % n];
		difb[i] = b[i] ^ b[(i + 1) % n];
//		cout << i << ' ' << difa[i] << ' ' << difb[i] << endl;
		hasha[i + 1] = (hasha[i] * B % mod + difa[i]) % mod;
		hashb = (hashb * B % mod + difb[i]) % mod;
	}
	for (int i = 0; i < n; i++) {
		if ((getH(0, i) + getH(i, n) * pb[i] % mod) % mod == hashb) {
			cout << i << ' ' << (a[i] ^ b[0]) << '\n';
		}
	}
}


Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

int main(){
  int H, N;
  cin >> H >> N;
  vector<pair<int,int>> AB;
  for(int i = 0; i < N; ++i){
    int a, b;
    cin >> a >> b;
    AB.emplace_back(a,b);
  }
  vector<int> dp(H+1,1e9);
  dp[0] = 0;
  for(auto ab : AB){
    for(int i = 0; i < H; ++i){
      int i_ = min(H,i+ab.first);
      dp[i_] = min(dp[i_],dp[i]+ab.second);
    }
  }
  cout << dp.back() << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#import math

# 整数の入力
#a = int(input())
# スペース区切りの文字列の入力
st = input().split()
st_list = []
st_list = [str(st) for st in st]

# スペース区切りの数値の入力
#a, b = map(int, input().split())

# 文字列の入力
#s = input()

# スペース区切りの文字列の入力
#a,b = map(input().split())

if(st_list[0] == st_list[1] and st_list[1] != st_list[2]):
  print("Yes")
elif(st_list[1] == st_list[2] and st_list[2] != st_list[0]):
  print("Yes")
elif(st_list[2] == st_list[0] and st_list[0] != st_list[1]):
  print("Yes")
else:
  print("No")

# 出力
#print(a,b)



Measured memory_bytes: 3060
import java.util.*;
class Main{
  public static void main(String[] args ){
    Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
double t=sc.nextDouble();
double a=sc.nextDouble();
int ans=0;
double min=Integer.MAX_VALUE;double tmp;
for(int i=0;i<n;i++){
tmp=sc.nextDouble();
if(min>  Math.abs(a-t+tmp*0.006)){
min= Math.abs(a-t+tmp*0.006);
ans=i;
}


}System.out.println(ans+1);}}

Measured memory_bytes: 27924
#include <cstdio>
#include <algorithm>

using namespace std;

long long N, A, B;

int main() {
  scanf("%lld %lld %lld", &N, &A, &B);

  if (B < A) swap(A, B);

  if ((B - A) % 2 == 0) printf("%lld\n", (B - A) / 2);
  else printf("%lld\n", min(A-1, N-B) + (B - A) / 2 + 1);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <memory>
#include <algorithm>
#include <cmath>
#include <functional>

using namespace std;


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

	auto mapping = [k](size_t i) {
		return i + i / (k - 1) + 1;
	};

	size_t v = 0;
	for (int i = 0; i < n - 1; i++) {
		v = mapping(v);
	}
	cout << v << endl;
}

Measured memory_bytes: 3084
N = int(input())
S = input()
Q = int(input())
ks = list(map(int, input().split()))

def func(ch):
    if ch == 'D':
        return 1
    if ch == 'M':
        return 2
    if ch == 'C':
        return 3
    return 0
    
S_arr = [func(ch) for ch in S]

def solve(N, S_arr, k):
    ans = 0
    D = 0
    M = 0
    DM = 0
    for i in range(k):
        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM
    for i in range(k, N):
        if S_arr[i-k] == 1:
            D -= 1
            DM -= M
        elif S_arr[i-k] == 2:
            M -= 1

        if S_arr[i] == 1:
            D += 1
        elif S_arr[i] == 2:
            DM += D
            M += 1
        elif S_arr[i] == 3:
            ans += DM

    return ans

for k in ks:
    print(solve(N, S_arr, k))
    


Measured memory_bytes: 119664
#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=1e5;
int m[L];
int p[L];
LL a[L];
LL r[L];
int main() {
	int N;
	cin >> N;
	LL sum=0;
	for(int i=0;i<N;i++){
		cin >> a[i];
		sum+=a[i];
	}
	int c=-1;
	LL v=0;
	for(int i=0;i<N;i++){
		if(a[i]>v){
			p[i]=c;
			v=a[i];
			c=i;
		}
	}
	map<int,LL> vs;
	for(int i=N-1;i>0;i--){
		vs[a[i]]++;
		if(c==i){
			c=p[i];
			while(vs.size()){
				auto it=vs.end();
				it--;
				auto w=it->second;
				if(it->first>a[c]){
					auto d=it->first-a[c];
					vs.erase(it);
					vs[a[c]]+=w;
					r[i]+=w*d;
					sum-=w*d;
				}
				else{
					break;
				}
			}
		}
	}
	r[0]=sum;
	for(int i=0;i<N;i++){
		cout << r[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 7424
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e5 + 2;
ll i,n,ans;
ll a[N],pre[N],suf[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,1,n + 1){
        cin>>a[i];
        pre[i] = __gcd(pre[i - 1],a[i]);
    }
    revrep(i,n,1) suf[i] = __gcd(suf[i + 1],a[i]);
    rep(i,1,n + 1)
        ans = max(ans,__gcd(pre[i - 1],suf[i + 1]));
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <bits/stdc++.h>
#include <algorithm>
#include <set>

using namespace std;


int main()
{
    long long int a,b,maxi,mini;
    cin>>a>>b;
    if (a>b)
    {
        maxi=a;
        mini=b;
    }
    else
    {
        maxi=b;
        mini=a;
    }
    long long int total=(a*b)/(__gcd(maxi,mini));
    cout<<total;

}


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

const int M = 1000000;

int f(int n) {
  if (n % 2 == 0)
    return n / 2;
  else
    return 3 * n + 1;
}

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

  int prev = s;
  set<int> S;
  S.insert(prev);
  for (int i = 2; i <= M; i++) {
    int curr = f(prev);
    if (S.find(curr) != S.end()) {
      cout << i << endl;
      return 0;
    }
    S.insert(curr);
    prev = curr;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
  // 整数の入力
  string S;
  cin >> S;
  bool condition1 = true;
  bool condition2 = true;
  bool condition3 = true;
  ll m = S.length()/2;
  for (int i = 0; i < S.size(); i++)
  {
    if (S[i] != S[S.size() - 1 - i])
    {
      condition1 = false;
    }
  }

  for (int i = 0; i < S.size() / 2; i++)
  {
    if (S[i] != S[S.size() / 2 - 1 - i])
    {
      condition2 = false;
    }
  }

  for (int i = 0; i < S.size()/2; i++)
  {
    // cout << i + S.size() / 2 << endl;
    if (S[i + S.size() / 2 + 1] != S[S.size() - 1 - i])
    {
      condition3 = false;
    }
  }
  // cout << condition1 << endl;
  // cout << condition2 << endl;
  // cout << condition3 << endl;
  if (condition1 && condition2 && condition3){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'


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

	ll n;
	cin >> n;
	cout << n * (n - 1) / 2ll << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char** argv) {
    int n, w;
    cin >> n >> w;

    std::vector<std::vector<long long>> dp;
    dp.push_back(std::vector<long long>(w+1));
    for (int i = 0; i <= w; ++i) dp[0][i] = 0;

    for (int i = 1; i < n+1; ++i) {
        long long wi, vi;
        cin >> wi >> vi;
        dp.emplace_back(std::vector<long long>(w+1));
        dp[i][0] = 0;
        for (int j = 1; j < w+1; ++j) {
            if (j-wi >= 0) {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-wi] + vi);
                continue;
            }
            dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[n][w] << endl;

    return 0;
}


Measured memory_bytes: 79488