akhauriyash/Code-Regression huggingface dataset:
#define CPP17
#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#ifdef CPP17
#include <variant>
#endif

// Yay!!
#define endl codeforces

// macros for iterator
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)

// alias
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;

// variadic min/max
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }

// variadic chmin/chmax
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

// multi demension array
template <typename T, std::size_t Head, std::size_t... Tail> struct multi_dim_array { using type = std::array<typename multi_dim_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dim_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t... Args> using mdarray = typename multi_dim_array<T, Args...>::type;

#ifdef CPP17
// fill container
template <typename T, typename F, typename... Args> 
void fill_seq(T &t, F f, Args... args) { if constexpr (std::is_invocable<F, Args...>::value) { t = f(args...); } else { for (ssize_t i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); } }
#endif

// make multi dimension vector
template <typename T> vec<T> make_v(ssize_t sz) { return vec<T>(sz); }
template <typename T, typename... Tail> auto make_v(ssize_t hs, Tail&&... ts) { auto v = std::move(make_v<T>(std::forward<Tail>(ts)...)); return vec<decltype(v)>(hs, v); }

// init
namespace init__ { 
struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; 
}


int main() {
    ll h1, m1, h2, m2, k;
    std::cin >> h1 >> m1 >> h2 >> m2 >> k;
    if (h1 == h2) {
        std::cout << m2 - m1 - k << "\n";
    } else {
        ll len = 60 - m1;
        h1++;
        len += (h2 - h1) * 60;
        len += m2;
        std::cout << len - k << "\n";
    }
    return 0;
}


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

typedef long long ll;

const ll maxn = 1e3 + 1e2;
const ll mod = 1e9 + 7;
ll n;
ll a, b, c, d;
ll dp[maxn][maxn];
ll dpb[maxn][maxn];

ll binom(ll a, ll b){
	if(dpb[a][b] == -1){
		if(a == 0 or a <= b or b == 0){
			dpb[a][b] = 1;
		} else {
			dpb[a][b] = binom(a - 1, b) + binom(a - 1, b - 1);
			dpb[a][b] %= mod;
		}
	}

	return dpb[a][b];
}

ll calc(ll a, ll b, ll c){
	if(b == 0){
		return 1;
	} else {
		return calc(a - c, b - 1, c) * binom(a - 1, c - 1) % mod;
	}
}

ll dfs(ll people_left, ll curr_group){
	if(dp[people_left][curr_group] == -1){
		ll& v = dp[people_left][curr_group];

		if(people_left == 0 and curr_group == b + 1){
			v = 1;
		} else if(people_left != 0 and curr_group == b + 1){
			v = 0;
		} else {
			v = 0;

			v += dfs(people_left, curr_group + 1);
			for(ll i = c; i <= d and people_left - i * curr_group >= 0; i++){
				ll x = binom(people_left, i * curr_group) * calc(i * curr_group, i, curr_group);
				x %= mod;
				v += x * dfs(people_left - i * curr_group, curr_group + 1);
				v %= mod;
			}
		}
	}

	return dp[people_left][curr_group];
}

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

	std::cin >> n;

	std::cin >> a >> b >> c >> d;

	for(ll i = 0; i < maxn; i++){
		for(ll j = 0; j < maxn; j++){
			dp[i][j] = -1;
			dpb[i][j] = -1;
		}
	}

	std::cout << dfs(n, a) << '\n';
}

Measured memory_bytes: 19328
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

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

using namespace std;

const ll MOD = 1e9 + 7;

ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}

const int MAXN = 120000;

int n;
ll a[MAXN];
ll h[MAXN];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	h[0] = 0;
	for (int i = 1; i <= n; ++i)
		h[i] = (h[i - 1] + pw(i, MOD - 2)) % MOD;
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		ans = (ans + a[i] * ((h[i + 1] + h[n - i] + MOD - 1) % MOD)) % MOD;
	}
	for (int i = 1; i <= n; ++i)
		ans = (ans * i) % MOD;
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 1792
import java.util.Scanner;



public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	
		long x = Math.abs(sc.nextLong());
		long k = sc.nextLong();
		long d = sc.nextLong();
		long ans = 0;
		long move = x / d;
		
		
		
		if(x /d < k) {
			ans = Math.abs(x - d*move - d*((k-move)%2));
		}else {
			ans = x - (k * d);
		}

		
		System.out.println(ans);
	}
	
}



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

vector<pair<ll,int>> pfact(ll n){
    vector<pair<ll,int>> fs = {};

    if(n<=1) return fs;

    for(ll i=2;i*i<=n;i++){
        int tmp = 0;
        while(n%i==0){
            n /= i;
            tmp++;
        }
        if(tmp>0) fs.push_back(make_pair(i,tmp));
    }
    if(n!=1) fs.push_back(make_pair(n,1));
    return fs;
}

ll gcd(ll a, ll b){
    if(a%b==0) return b;
    else return gcd(b,a%b);
}

int main(void){
    ll a,b;
    cin >> a >> b;

    ll g = gcd(a,b);

    vector<pair<ll,int>> plist = pfact(g);
    cout << (int)plist.size()+1 << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void) {

  int a,b;
  scanf("%d %d", &a, &b);
  char grid[100][100];
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 100; j++) {
      grid[i][j] = '#';
    }
  }
  for (int i = 50; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      grid[i][j] = '.';
    }
  }
  int white = 0;
  int black = 0;
  for (int i = 0; i < 50; i += 2) {
    if (white == a-1) {
      break;
    }
    for (int j = 0; j < 100; j += 2) {
      if (white == a-1) {
        break;
      }
      grid[i][j] = '.';
      white++;
    }
  }
  for (int i = 99; i >= 50; i -= 2) {
    if (black == b-1) {
      break;
    }
    for (int j = 0; j < 100; j += 2) {
      if (black == b-1) {
        break;
      }
      grid[i][j] = '#';
      black++;
    }
  }
  printf("100 100\n");
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      printf("%c", grid[i][j]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 128
require 'bigdecimal'
require 'bigdecimal/util'

A, V = gets.chomp.split(" ").map(&:to_d)
B, W = gets.chomp.split(" ").map(&:to_d)
T = gets.chomp.to_d
d = (A-B).abs
v = (V-W)*T
if (v >= d)
    print "YES"
else
    print "NO"
end


Measured memory_bytes: 14404
import java.util.*;

public class Main {
    void swap(int[] A, int a, int b) {
        int tmp = A[a];
        A[a] = A[b];
        A[b] = tmp;
    }
int partition(int[] A, int p, int r) {
        int x = A[r];
        int i = p - 1;
        for (int j = p; j < r; j++) {
            if (A[j] <= x) {
                i++;
                swap(A, i, j);
            }
        }
        swap(A, i+1, r);
        return i+1;
    }
    void printArray(int[] a, int x) {
        if (x == 0) {
            System.out.print("["+a[0]+"]");
        } else {
            System.out.print(a[0]);
        }
        for (int i = 1; i < a.length; i++) {
            if (x == i) {
                System.out.print(" ["+a[i]+"]");
            } else {
                System.out.print(" " + a[i]);
            }
        }
        System.out.println();
    }
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = sc.nextInt();
        }
        int x = partition(A, 0, n-1);
        printArray(A, x);
    }
    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 69248
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll a, b, c, d, n, k, x,l;
    string s, t;
    ll ans = 0;
    double dans = 0;
    string sans = "Good";

    cin  >> n >> x;
    ll before = 0;
    ans++;
    rep(i,n){
        cin >> d;
        if(x >= before + d) {ans++;before+=d;}
        else break;
    }

    std::cout << ans << endl; 
    // std::cout << sans << endl; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD (long long)(1e9+7)
bool comp(const pair<int,int>a,const pair<int,int>b){
	if(a.first!=b.first)return a.first<b.first;
	else{
		return a.second>b.second;
	}
}
int main(){
	int num[9]={2,5,5,4,5,6,3,7,6},n,m;
	cin>>n>>m;
	vector<pair<int,int>>a(m);//firstに数字のコスト,secondに数字
	for(int i=0;i<m;i++){
		cin>>a[i].second;
		a[i].first=num[a[i].second-1];
	}
	sort(a.begin(),a.end(),comp);
	vector<string>dp(n+1,"");//nまでのdpテーブル
	for(int i=1;i<n+1;i++){
		for(int j=0;j<m;j++){
			if(i-a[j].first==0||i-a[j].first>=0&&dp[i-a[j].first]!="\0"){
				string hoge=to_string(a[j].second)+dp[i-a[j].first];//足す順番は関係ない
				if(hoge.length()>dp[i].length())dp[i]=hoge;
				else if(dp[i].length()==hoge.length()){
					dp[i]=max(hoge,dp[i]);
				}
			}
		}
	}
	cout<<dp[n]<<endl;
	
}



Measured memory_bytes: 32384
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s; i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int h, w; cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    vector<bool> vert(h, false), trans(w, false); //黒のある行、列
    REP(i, h) REP(j, w){
        cin >> a[i][j];
        if(a[i][j] == '#'){
            vert[i] = true; trans[j] = true;
        }
    }
    REP(i, h){
        REP(j, w){
            if(vert[i] && trans[j]) cout << a[i][j];
        }
        if(vert[i]) cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 10*60
#define EPS 1e-9

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

ll mod_pow(ll x,ll n,ll m){
    if(n==0) return 1;
    ll res=mod_pow(x*x%m,n/2,m);
    if(n&1) {
      res=res*x%m;
    }
    return res;
}


signed main(){
  int N,M;cin>>N>>M;
  string ans=(N==M?"Yes":"No");
  print(ans)
 
}

Measured memory_bytes: 256
toInt :: String -> Int
toInt = read :: String -> Int

isGoodNumber :: Int -> Bool
isGoodNumber n = mod (div n 10) 111 == 0 || mod (mod n 1000) 111 == 0

main = do
  n <- toInt <$> getLine
  putStrLn $ if isGoodNumber n then "Yes" else "No"


Measured memory_bytes: 508
N, K = map(int, input().split())
d = []
A = []
for k in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())) )

check = []

for k in range(K):
    for i in range(d[k]):
        if A[k][i] not in check:
            check.append(A[k][i])

count = 0

for n in range(N):
    if n+1 not in check:
        count += 1
        
print(count)

Measured memory_bytes: 67908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,x,t;
    cin >> n >> x >> t;
    ll kai=n/x;
    if(n%x!=0) kai++;
    cout << t*kai << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	std::string s;

	std::cin >> s;

	char alpha = 'a';

	std::sort(s.begin(), s.end());

	s.erase(std::unique(s.begin(), s.end()), s.end());

	for (size_t i = 0; i < s.length(); i++)
	{
		if (s[i] == alpha) {
			alpha++;
		}
		else {
			std::cout << (char)alpha << std::endl;
			return 0;
		}
	}

	if (alpha <= 'z') {
		std::cout << alpha << std::endl;
		return 0;
	}

	std::cout << "None" << std::endl;
}


Measured memory_bytes: 512
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Sat Dec  8 18:53:55 2018
//
package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var D, G int

	fmt.Scan(&D, &G)

	arr1 := make([]int, D)
	arr2 := make([]int, D)
	for i := 0; i < D; i++ {
		fmt.Scan(&arr1[i], &arr2[i])
	}

	ans := 1 << 31
	for i := 0; i < (1 << uint8(D)); i++ {
		total := 0
		cnt := 0
		for j := 0; j < D; j++ {
			if i&(1<<uint8(j)) != 0 {
				total += arr1[j]*(j+1)*100 + arr2[j]
				cnt += arr1[j]
			}
		}

		if total < G {
			for j := D - 1; j >= 0; j-- {
				if i&(1<<uint8(j)) == 0 {
					num := (G - total + (j+1)*100 - 1) / ((j + 1) * 100)
					if num <= arr1[j]-1 {
						cnt += num
						total += num * (j + 1) * 100
					}
					break
				}
			}
		}

		if G <= total {
			ans = min(ans, cnt)
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type PQ []int

func (pq PQ) Len() int { return len(pq) }
func (pq PQ) Less(i, j int) bool {
	return pq[i] > pq[j]
}
func (pq PQ) Swap(i, j int) { pq[i], pq[j] = pq[j], pq[i] }
func (pq *PQ) Push(x interface{}) {
	item := x.(int)
	*pq = append(*pq, item)
}
func (pq *PQ) Pop() interface{} {
	old := (*pq)
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([][]int, n)
	for i := range as {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		as[i] = []int{a, b}
	}
	sort.Slice(as, func(i, j int) bool { return as[i][0] < as[j][0] })

	qs := make(PQ, 0)
	heap.Init(&qs)

	var sum, j int
	for i := 1; i <= m; i++ {
		for ; j < n && as[j][0] <= i; j++ {
			heap.Push(&qs, as[j][1])
		}
		if qs.Len() > 0 {
			b := heap.Pop(&qs).(int)
			sum += b
		}
	}
	fmt.Println(sum)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 12348
n,k=map(int,input().split())
A=list(map(int,input().split()))
x=0
y=0
for i in range(n):
  for j in A[i+1:]:
    if A[i]>j:
      x+=1
for i in range(n):
  for j in A:
    if A[i]>j:
      y+=1
print((x*k+y*k*(k-1)//2)%1000000007)

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0; i<a.length; i++){
            a[i] = sc.nextInt();
        }
        for(int i=0; i<(int)(a.length)/2; i++){
            int tmp = a[i];
            a[i] = a[(a.length-1)-i];
            a[a.length-i-1] = tmp;
        }
        for(int i=0; i<a.length-1; i++){
            System.out.print(a[i]+" ");
        }
        System.out.print(a[a.length-1]);
        System.out.println();
    }
}


Measured memory_bytes: 26288
#include<stdio.h>
//#include<stdlib.h>
#define INTFY 2000000000
long int S[500000],l;

void mergesort(long int*,long int,long int);
void merge(long int*,long int,long int,long int);

int main(){
  long int n,i;
  scanf("%ld",&n);
   for(i=0;i<n;i++){
     scanf("%ld",&S[i]);
  }
  mergesort(S,0,n);
  for(i=0;i<n;i++){
    if(i>0)printf(" ");
    printf("%ld",S[i]);
 }
 printf("\n");
    printf("%ld\n",l);
  return 0;
}

void mergesort(long int A[],long int left,long int right){
  long int mid,i;

  if(left+1<right){
    mid = (left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}

void merge(long int A[],long int left,long int mid,long int right){
  long int n1=mid-left;
  long int n2=right-mid;
  long int L[500000],R[500000],i,j=0,k;
  L[n1]=INTFY;
  R[n2]=INTFY;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }

  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  i=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i+=1;
      l++;
    }
    else{
      A[k]=R[j];
      j=j+1;
      l++;
    }
  }
}



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

int n,ans;
map <pair <int,int>,int> m;

int f(int l,int r)
{
	if(m.find({l,r})==m.end()) return 0;
	return m[{l,r}];
}

int main()
{
	cin>>n;
	
	for(int i=1;i<=n;i++)
	{
		string s=to_string(i);
		m[{s.front()-'0',s.back()-'0'}]++;
	}

	for(auto i:m)
	{
		int l=i.first.first,r=i.first.second;
		ans+=i.second*f(r,l);
	}

	cout<<ans;
}

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

using namespace std;

int n, tmp, x, y;
vector< vector<int> > vx, vy;
vector<int> bi, che;
int pa, ma=-1;

//0~pa-1を長さnで生成、合計pa^n個生成
void bitgen(int m) {

	//生成完了時の処理
	if (m == 0) {
		//cout << "#" << endl;
		//for (int i = 0;i<bi.size();i++) cout << bi[i] << " ";

		/*for (int i = 0;i < n;i++) {
			if (bi[i] == 1) che[i] = 1;
			else che[i] = 0;
		}*/

		for (int i = 0;i < n;i++) {
			if (bi[i] == 0) continue;
			for (int j = 0;j < vx[i].size();j++) {
				if (bi[vx[i][j]-1] != vy[i][j]) {
					ma = max(ma, 0);
					//cout << endl;
					return;
				}
				/*if(che[vx[i][j]]!=-1) che[vx[i][j]] = vy[i][j];*/
			}
		}

		/*for (int i = 0;i < n;i++) {
			cout << che[i];
		}
		cout << endl;*/

		/*for (int i = 0;i < n;i++) {
			//if (che[i]!=-1 && che[i]!=bi[i]) {
			if (che[i] == 1 && bi[i] == 0) {
				ma = max(ma, 0);
				return;
			}
		}*/

		tmp = 0;
		for (int i = 0;i < n;i++) {
			tmp += bi[i];
			//cout << bi[i];
		}
		//cout << " " << tmp << endl;

		ma = max(ma, tmp);

		return;

	}

	//再帰部分
	for (int i = 0;i<pa;i++) {
		bi[m - 1] = i;
		bitgen(m - 1);
	}
}

int main() {

	cin >> n;

	pa = 2;

	vx.resize(n);
	vy.resize(n);
	che.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> tmp;
		for (int j = 0;j < tmp;j++) {
			cin >> x >> y;
			vx[i].emplace_back(x);
			vy[i].emplace_back(y);
		}
	}

	bi.resize(n);
	bitgen(n);

	cout << ma << endl;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,m,a;
  scanf("%d",&n);
  scanf("%d",&m);
  for(;m>0;m--){
    scanf("%d",&a);
    n-=a;
  }
  if(n<0) n=-1;
  printf("%d",n);
  return(0);
}

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

int main(){
	int n,m;
	cin >> n >> m;
	string a[50],b[50];
	for(int i=0;i<n;++i)cin >> a[i];
	for(int i=0;i<m;++i)cin >> b[i];
	for(int i=0;i<=n-m;++i){
		for(int j=0;j<=n-m;++j){
			int x;
			for(x=0;x<m;++x){
				if(a[i+x].substr(j,m)!=b[x])break;
			}
			if(x==m){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


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

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
    }

    bool check = true;
    int counter = 0;
    while(check){
        for(int i = 0; i < n; i++){
            if(a[i]%2 == 0 && !(a[i] == 0)){
                a[i] = a[i]/2;
            }
            else{
                check = false;
            }
        }
        counter++;
    }

    std::cout << counter - 1;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#define int long long
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,a[200005],b[200005],c[200005],d[200005];
int mp[4005][4005],dp[4005][4005],fac[8005],inv[8005],ans;
ll qpow(ll a,ll b)
{
	ll ans=1,base=a;
	while(b)
	{
		if(b&1) ans=ans*base%mod;
		base=base*base%mod;
		b>>=1;
	}
	return ans;
}
void pre()
{
	int i;
	fac[0]=1;
	for(i=1;i<=8000;i++) fac[i]=1LL*fac[i-1]*i%mod;
	inv[8000]=qpow(fac[8000],mod-2);
	for(i=8000;i>=1;i--) inv[i-1]=1LL*inv[i]*i%mod;
}
int C(int n,int m)
{
	if(m>n) return 0;
	return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
 main()
{
	int i,j;
	n=read();pre();
	for(i=1;i<=n;i++) a[i]=read()+2000,b[i]=read()+2000,mp[a[i]][b[i]]++;
	for(i=4000;i>=0;i--)
	{
		for(j=4000;j>=0;j--)
		{
			dp[i][j]=((dp[i][j+1]+dp[i+1][j])%mod+mp[i][j])%mod;
		}
	}
	for(i=1;i<=n;i++) 
	{
		c[i]=4000-a[i],d[i]=4000-b[i];
		ans=(ans+dp[c[i]][d[i]])%mod;
		ans=((ans-C(a[i]-c[i]+b[i]-d[i],a[i]-c[i]))%mod+mod)%mod;
	}
	ans=ans*qpow(2,mod-2)%mod;
	printf("%lld",ans);
}

Measured memory_bytes: 197888
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def divisor(n):
        i = 1
        table = []
        while i * i <= n:
            if n % i == 0:
                table.append(i)
                table.append(n // i)
            i += 1
        table = list(set(table))
        return table


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e30)


def main():
    # sys.stdin = open("Sample.txt")
    A, B = Scanner.map_int()
    ans = 0
    for a in Math.divisor(Math.gcd(A, B)):
        if Math.isPrime(a):
            ans += 1
    ans += 1
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 40172
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
const int INF = 1e9;

int main() {

    string S;
    cin >> S;

    string T[4] = {"maerd", "remaerd", "esare", "resare"};
    reverse(S.begin(), S.end());
    rep(i, S.size()) {
        bool flag = false;
        rep(j, 4) {
            if (strncmp(&S[i], T[j].c_str(), T[j].size()) == 0) {
                i += T[j].size() - 1;
                flag = true;
            }
        }
        if (!flag) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <queue>
#define N 30
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
int dijkstra();
int R,C,sy,sx,gy,gx,d[N][N];
string s[N];

int main(){
  cin>>R>>C;
  for(int i=0;i<R;i++) cin>>s[i];
  for(int i=0;i<R;i++)
    for(int j=0;j<C;j++){
      if(s[i][j]=='S') sy=i,sx=j;
      if(s[i][j]=='G') s[i][j]='.',gy=i,gx=j;
    }
  cout<<dijkstra()<<endl;
  return 0;
}

int dijkstra(){
  priority_queue<P1> q;
  int dy[4]={-1,0,1,0};
  int dx[4]={0,1,0,-1};
  for(int i=0;i<R;i++)
    for(int j=0;j<C;j++) d[i][j]=(1e9);
  q.push(P1(0,P(sy,sx)));
  d[sy][sx]=0;
  while(!q.empty()){
    P1 t=q.top(); q.pop();
    int c=t.first,y=t.second.first,x=t.second.second;
    if(d[y][x]<c) continue;
    for(int i=0;i<4;i++){
      int pc=0;
      for(int j=1;j<=3;j++){
	int ny=y+dy[i]*j,nx=x+dx[i]*j;
	if(ny<0||nx<0||R<=ny||C<=nx||s[ny][nx]=='#'||s[ny][nx]=='x') break;
	if(s[ny][nx]=='.') pc+=2;
	if(s[ny][nx]=='o') pc+=1;
	if(d[ny][nx]>c+pc){
	  d[ny][nx]=c+pc;
	  q.push(P1(d[ny][nx],P(ny,nx)));
	}
      }
    }
    for(int i=0;i<4;i++){
      int pc=2;
      for(int j=1;j<=3;j++){
	int ny=y+dy[i]*j,nx=x+dx[i]*j;
	if(ny<0||nx<0||R<=ny||C<=nx||s[ny][nx]=='#') break;
	pc++;
	if(d[ny][nx]>c+pc){
	  d[ny][nx]=c+pc;
	  q.push(P1(d[ny][nx],P(ny,nx)));
	}
      }
    }
  }
  return d[gy][gx];
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;

int main() {
    int N, M;
    int count = 0;
    string s;
    string ans = "No";
    cin >> N >> M;
    vector<string>A;
    vector<string>B;

    for (int i = 0; i < N; i++) {
        cin >> s;
        A.push_back(s);
    }

    for (int i = 0; i < M; i++) {
        cin >> s;
        B.push_back(s);
    }

    for (int i = 0; i < N-M+1; i++) {
        for (int j = 0; j < N-M+1; j++) {
            count = 0;
            for (int k = 0; k < M; k++) {
                for (int l = 0; l < M; l++) {
                    if (A[j+l][i+k] == B[l][k]) {
                        count++;
                    } else {
                        goto L1;
                    }
                }
            }
            L1:
            if (count==M*M) {
                ans = "Yes";
                goto L2;
            }
        }
    }
L2:
    cout <<  ans << endl;
}


Measured memory_bytes: 256
s = input("")
n = 0

if s[0] == "R":
    if s[1] == "R":
        if s[2] == "R":
            n = 3
        else:
            n = 2
    else:
        n = 1

elif s[1] == "R":
    if s[2] == "R":
        n = 2
    else:
        n = 1

elif s[2] == "R":
    n = 1

else:
    n = 0

print(n)

Measured memory_bytes: 9048
#include <iostream>
using namespace std;
 
int main(){
int x,y,z,ans;
	while(true){
		ans=0;
		cin>>x>>y;
		if(x==0||y==0)break;
		if(x<y){
			z=x;
			x=y;
			y=z;
		}
		while(y!=0){
		x=x%y;
		z=x;
		x=y;
		y=z;
		ans++;
		}
		cout<<x<<' '<<ans<<endl;
	}
}	

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;

    int a[100];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    sort(a, a + N);

    int ans = 0, cnt = 0;
    for (int i = N-1; i > -1; i--)
    {
        if(cnt%2 == 0) ans += a[i];
        else ans -= a[i];
        cnt++;
    }
    cout << ans << endl;
}

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

int main()
{
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;

    vector<int> h(n + 1);
    for (int i = 0; i <= n; i++) cin >> h[i];

    for (int i = 0; i <= n; i++) {
      vector<int> v = h;
      v.erase(v.begin() + i);

      int kanade = v[1] - v[0];
      bool f = false;
      for (int j = 1; j < v.size(); j++) {
        if (kanade != v[j] - v[j - 1]) {
          f = true;
          break;
        }
      }

      if (!f) {
        cout << h[i] << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;void solve();int main(){ios::sync_with_stdio(0);cin.tie(0);solve();};typedef long long ll;
template<typename Type>void print_collection(Type coll){cout<<"{ ";for(auto e:coll)cout<<e<<' ';cout<<"}\n";}
void solve() {
  int n;
  string s;
  cin >> n >> s;
  const char B = '#', W = '.';
  int moves = count(s.begin(), s.end(), W);
  int min_moves = moves;
  for (char c : s) {
    moves += c == B ? 1 : -1;
    min_moves = min(moves, min_moves);
  }
  cout << min_moves << '\n';
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> pot(0,0);
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    pot.push_back(a);
  }
  sort(pot.begin(), pot.end());
  double ans=pot[0];
  for(int i=1; i<N; i++){
    ans=(ans+pot[i])/2;    
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>
 
using namespace std;
typedef long long ll;
 
int main(){
ll n;
  cin>>n;
  ll h[n];
  for(ll i=0;i<n;i++){
  cin>>h[i];
  }
  ll count=1;
    for(ll i=1;i<n;i++){
      ll flag=1;
      for(ll j=0;j<i;j++){
      if(h[i]-h[j]<0)
        flag=0;
      }
      if(flag==1){
        count++;
      }
  
  }
  cout<<count;
  return 0;
 
}
 

Measured memory_bytes: 256
from collections import Counter
from itertools import accumulate
import bisect

printRows = lambda x:print('\n'.join(map(str,x)))

n = int(input())
a = list(map(int, input().split()))
b = sorted(Counter(a).values())
exist = len(b)
b = [0]*(n-exist)+b
c = list(accumulate([0]+b))

ans = [n]
for k in range(2,n//2+1):
    if k>exist:
        ans.append(0)
        continue
    l = 0
    r = n//k+1
    while r-l>1:
        x = (r+l)//2
        i = bisect.bisect_left(b,x)
        if c[i]+(n-i)*x>=x*k:
            l = x
        else:
            r = x
    ans.append(l)

for k in range(max(n//2+1,2),n+1):
    if exist>=k:
        ans.append(1)
    else:
        ans.append(0)

printRows(ans)

Measured memory_bytes: 126756
#include <bits/stdc++.h>
using namespace std;
# define ll long long
const int M =  1e9+7;
char arr[1005][1005];
ll ans[1005][1005];
int h,w;
ll calc(int x,int y)
{
    if(ans[x][y]!=-1)
        return ans[x][y];
    if(x==h-1&&y==w-1)
        return 1;
    ll a=0,b=0;
    if(arr[x][y+1]!='#'&&x<h&&y+1<w)
        a=calc(x,y+1);
    if(arr[x+1][y]!='#'&&x+1<h&&y<w)
        b=calc(x+1,y);
    a=a%M;
    b=b%M;
    ans[x][y]=a+b;
    return (a+b)%M;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>arr[i][j];
        }
    }
    memset(ans,-1,sizeof(ans));
    cout<<calc(0,0);

    //code goes here
	return 0;
}



Measured memory_bytes: 9216
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int mod = 100000;

int main()
{
int n, m;
vector<int> s;

scanf("%d%d", &n, &m);
s.resize(n, 0);
for(int i = 1; i < n; ++i) {
int temp;
scanf("%d", &temp);
s[i] = s[i - 1] + temp;
}

int total = 0;
int pos = 0;

for(int i = 0; i < m; ++i) {
int diff, next;
scanf("%d", &diff);
next = pos + diff;
total += abs(s[pos] - s[next]);
total %= mod;
pos = next;
}

printf("%d\n", total);

return 0;
}

Measured memory_bytes: 1268
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	x, _ := strconv.ParseUint(text[0:len(text)-1], 10, 64)
	var p1, p2 uint64

	if x >= 500 {
		p1 = (x / 500) * 500 * 2
	}
	p2 = ((x % 500) / 5) * 5
	fmt.Println(p1 + p2)
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

void maxHeapify(int*, int index, int n);

int main() {
	int n;
	cin >> n;
	int* a = new int[n+1];
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
	}
	for (int i = n / 2;i >= 1;i--) {
		maxHeapify(a, i, n);
	}
	for (int i = 1;i <= n;i++) {
		cout << " " << a[i];
	}
	cout << endl;
}

void maxHeapify(int* a, int index,int n) {
	int l = 2 * index;
	int r = l + 1;
	int largest = index;
	if (l <= n) {
		if (a[l] > a[index]) {
			largest = l;
		}
	}
	if (r <= n) {
		if (a[r] > a[largest]) {
			largest = r;
		}
	}
	if (largest != index) {
		swap(a[index], a[largest]);
		maxHeapify(a, largest, n);
	}
}


Measured memory_bytes: 5020
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n-1);
  REP(i,n-1) cin >> b[i];

  a[0] = b[0];
  a[n-1] = b[n-2];

  for(int i = 1; i < n-1; i++){
    a[i] = min(b[i], b[i-1]);
  }

  int ans = 0;
  REP(i,n) ans += a[i];

  //for(auto x: a) cout << x << endl;

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

Measured memory_bytes: 3636
N, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
children = [0] * N
a.sort()
kashi = 0
n = N
if a[0] > x:
    print(0)
elif sum(a) == x:
    print(N)
else:
    for i in range(0,n):
        if kashi > x:
            break        
        kashi += a[i]
        children[i] += 1
#     print(kashi)
    if kashi == x :
        print(N - children.count(0))
    else:
        print(N - children.count(0) - 1)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println((a - b) + (a - b - 1) * (a - b) / 2 - a);
	}
}


Measured memory_bytes: 27100
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int d,n,m;
int s[111111];
int main(void){
  while(cin >> d && d){
    cin >> n >> m;
    memset(s,0,sizeof(s));
    s[0] = 0;
    s[n] = d;
    for(int i = 1; i < n; i++){
      cin >> s[i];
    }
    sort(s,s+n+1);


    int res = 0;
    for(int i = 0; i < m; i++){
      int k;
      cin >> k;
      int *p = upper_bound(s,s+n+1,k);
      res += min(*p-k,k-*(p-1));
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1612
#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
#include<set>
#define mod  998244353
#define int long long int
int32_t main()
{
	int n;
	cin>>n;
	int j,arr[n+1];
	for(j=1;j<=n;j++)
	    cin>>arr[j];
	int answer=0;
	int position[n+1];
	for(j=1;j<=n;j++)
	{
		position[arr[j]]=j;
	}
	set<int> s;
	s.insert(0);
	s.insert(n+1);
	for(j=1;j<=n;j++)
	{
		int x=position[j];
		auto it=s.upper_bound(x);
		int right=*it;
		right--;
		it--;
		int left=*it;
		left++;
		answer+=j*(x-left+1)*(right-x+1);
		s.insert(x);

	}
	cout<<answer<<endl;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define R register
#define L 200002

inline void read(int &x){
    static int ch; static bool flag;
    for(flag=0,ch=getchar(); ch>'9'||ch<'0'; ch=getchar()) flag |= ch=='-';
    for(x=0; ch>='0'&&ch<='9'; ch=getchar()) x = (x<<1) + (x<<3) + ch-48;
    x = flag ? -x : x; 
}

int N,M;
long long f[52][2];

int main()
{
	read(N),read(M);
	f[0][0]=1;
	for(R int i=1,j;i<=N;++i){
		read(j); j=j&1;
		f[i][0]=f[i-1][0]+f[i-1][j^0];
		f[i][1]=f[i-1][1]+f[i-1][j^1];
	}	
	printf("%lld\n",f[N][M]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF (ll)1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
//constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
//

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int ans = 0,k, n, one = 0, mini, maxx;
	cin >> n>>k;
	vi v(n);
	rep(i, n) {
		cin >> v[i];
		if (v[i] == 1)one = i+1;
	}
	mini = 1,maxx=n;
	while (mini < one) {
		ans++;
		mini += (k - (ans == 1 ? 1 : 1));
	}
	while (maxx > mini) {
		ans++;
		maxx -= (k - (maxx==n?1:1));
	}
	cout << ans << endl;


}


Measured memory_bytes: 640
#pragma region def
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
using pint = pair<int, int>;
const int INF = 1e9;
const long long llINF = 1e18;
#pragma endregion

int main () {
    llint n;
    cin >> n;
    vector<llint> x(n + 1);
    llint m = 0;
    rep(i, n) {
        cin >> x[i + 1];
        m = max(m, x[i + 1]);
    }
    //m = max(m, n);
    //vector<llint> HP;
    llint ans = INF;

    for (llint P = 1; P <= m; P++) {
        //HP[P] = 0;
        llint needHP = 0;
        for (llint i = 1; i <= n; i++) {
            needHP += pow((x[i] - P), 2);
        }
        //HP.push_back(needHP);
        //ans = min(ans, HP[P]);
        ans = min(ans, needHP);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

using namespace std;


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

    int ans[10][10];
    for(int i=0; i<10; i++){
        for(int j=0; j<10 ;j++){
            ans[i][j] = 0;
        }
    }

    for(int i=1; i<=N; i++){
        string sn = to_string(i);

        int ss = sn[0]-'0';
        int se = sn[sn.length()-1]-'0';

        ans[ss][se] += 1;

    }

    long sum = 0;
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            if(j==0) continue;
            sum += ans[i][j]* ans[j][i];
        }
    }

    cout << sum;

    return 0;
}

Measured memory_bytes: 256
def bubbles(N):
    count = 0
    for i in range(len(N)):
        for j in range(len(N)-1, i, -1):
            if N[j] < N[j-1]:
                N[j], N[j-1] = N[j-1], N[j]
                count += 1
    c = 1
    for i in N:
        print(i, end='')
        if c < len(N):
            print(' ', end='')
            c += 1
    print('')
    return count

n = int(input())
numbers = list(map(int, input().split()))

print(bubbles(numbers))

Measured memory_bytes: 7712
#include <bits/stdc++.h>
#define f(i, a, b) for (int i = a; i < (b); ++i)
#define f1(i, a, b) for (int i = a; i <= (b); ++i)
#define rep(i, n) f(i, 0, n)
using namespace std;
using ll = long long;

int main(void) {
  int n;
  cin >> n;
  map<string, int> s;
  rep(i, n) {
    string t;
    cin >> t;
    s[t] += 1;
  }
  int maxmum = 0;
  for (auto x : s) {
    int y = x.second;
    maxmum = max(y, maxmum);
  }
  for (auto x : s) {
    if (s[x.first] == maxmum) cout << x.first << '\n';
  }
  return 0;
}

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

main(){
  char ch;
  int H, W, c;
  int dp[55][55];
  cin >> H >> W;
  for ( int i = 0; i < H; i++ ){
    for ( int j = 0; j < W; j++ ){
      cin >> ch;
      c = ch - '0';
      if ( i == 0 && j == 0 ){
      } else if ( i == 0 ){
	dp[i][j] = c + dp[i][j-1];
      } else if ( j == 0 ){
	dp[i][j] = c + dp[i-1][j];
      } else {
	dp[i][j] = c + min(dp[i-1][j], dp[i][j-1]);
      }
    }
  }
  cout << dp[H-1][W-1] << endl;
}

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

using namespace std;

int main(){
  string str_orig;
  string order;
  int q;
  cin >> str_orig >> q;
  while(q > 0){
    int a, b;
    cin >> order >> a >> b;
    if(order == "replace"){
      string p;
      cin >> p;
      for(string::size_type i = a, j = 0; i <= b; i++,j++)
        str_orig[i] = p[j];
      
    }else if(order == "reverse"){
      string c = str_orig;
      for(string::size_type i = a, j = b; i <= b; i++, j--){
        // 入れ替え
        char temp;
        temp = str_orig[i];
        str_orig[i] = str_orig[j];
        str_orig[j] = temp;
        if(i == a + (b-a)/2) break;
      }
      
    }else{
      for(string::size_type i = a; i <= b; i++)
        cout << str_orig[i];
      cout << endl;
    }

    q--;
  }
}


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

int main(){
        int N,R;
        cin >> N >> R;
        if(N >= 10) cout << R << endl;
        else cout << (R + 100 * (10 - N)) << endl;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
L = list(map(int,input().split()))
mod = 10**9 +7

cnt = 0
for i in range(n-1):
    tmp = 0
    for j in range(i+1,n):
        if L[i] > L[j]:
            cnt +=1
cnt2 = 0
li = []
for i in range(n):
    tmp = 0
    for j in range(n):
        if L[i] > L[j]:
            cnt2 +=1

ans = cnt*k%mod
ans += cnt2*k*(k-1)//2%mod
print((ans)%mod)


Measured memory_bytes: 9260
#include  <stdio.h>

int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

	if((x+r>W||x-r<0)||(y+r>H||y-r<0))
	{
		printf("No\n");
	}
	else 
	{
		printf("Yes\n");
	}
	return  0;
}

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

int main() {
  string N;
  cin >> N;
  if ( (N[0] == N[1] && N[1] == N[2]) || (N[1] == N[2] && N[2] == N[3]) ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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


main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,o,p;

    char s[1000009];
while(cin>>m>>n){
    if(m>n)cout<<"safe"<<endl;
    else cout<<"unsafe"<<endl;
}
    return 0;


}


Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    string t = "";
    t += s;
    reverse(t.begin(), t.end());
    if(s.substr(0, (n-1)/2) == s.substr((n+1)/2, (n-1)/2) && s.substr(0, (n-1)/2) == t.substr(0, (n-1)/2) && s.substr(0, (n-1)/2) == t.substr((n+1)/2, (n-1)/2)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

int B[20];

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

  int N, M, C;
  cin >> N >> M >> C;
  REP(i, M) { cin >> B[i]; }

  int ans = 0;
  int sum = 0;

  int tmp_a = 0;

  REP(i, N) {
    sum = 0;
    REP(j, M) {
      cin >> tmp_a;
      sum += B[j] * tmp_a;
    }
    if (sum + C > 0) {
      ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256