akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    ll a, b, k; cin >> a >> b >> k;
    if (a > k){
        a -= k;
        cout << a << " " << b << endl;
        return 0;
    }
    else {
        k -= a;
        a = 0;
        b -= min(b,k);
        cout << a << " " << b << endl;
        return 0;
    }
}

Measured memory_bytes: 256
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

A, B, K = map(int, input().split())
if A >= K:
    print(A - K, B)
elif A + B >= K:
    print(0, A + B - K)
else:
    print(0, 0)


Measured memory_bytes: 5080
#include <bits/stdc++.h>
using namespace std;
#define INFTY 20000000000

int N, K;
vector<int> A(15);

int main()
{
  cin >> N >> K;
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  long long min_cost = INFTY, tmp;
  int obstacle;
  // O(N×2^N)のアルゴリズム
  for (int bit = 0; bit < (1 << N); bit++)
  {
    if (__builtin_popcount(bit) != K)
    {
      continue;
    }
    tmp = 0;
    obstacle = 0;
    for (int i = 0; i < N; i++)
    {
      if (bit & (1 << i))
      {
        if (obstacle >= A.at(i))
        {
          tmp += obstacle - A.at(i) + 1;
          obstacle++;
        }
        else
        {
          obstacle = A.at(i);
        }
      }
      else
      {
        obstacle = max(obstacle, A.at(i));
      }
    }
    min_cost = min(min_cost, tmp);
  }
  cout << min_cost << endl;
}

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

using namespace std;

const int NMAX = 300000;

int f[NMAX+2], N, K, Ans = 0, cnt = 0;

int main()
{
    cin >> N >>  K;
    for( int i = 1;  i <= N;  ++i ) {
        int x;
        cin >> x;
        if( !f[x] ) ++cnt;
        f[x]++;
    }
    sort( f+1, f+NMAX+1 );
    reverse( f+1, f+NMAX+1 );
    for( int i = 1;  i <= min(K,cnt);  ++i ) {
        Ans += f[i];
    }
    Ans = N - Ans;
    cout << Ans << '\n';
    return 0;
}


Measured memory_bytes: 1408
from collections import deque
INF = 10**9 + 7
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append([a, b])
    g[b].append([b, a])
res = [INF for _ in range(n+1)]
res[1] = 0
q = deque(g[1])
while q:
    q_ = q.popleft()
    if res[q_[1]] == INF:
        for gi in g[q_[1]]: q.append(gi)
        res[q_[1]] = q_[0]
print("Yes")
for i in res[2:]: print(i)

Measured memory_bytes: 66572
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

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

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	c0 := getString()
	c1 := getString()
	c2 := getString()

	out(string(c0[0]) + string(c1[1]) + string(c2[2]))
}


Measured memory_bytes: 640
use proconio::*;
use std::collections::BinaryHeap;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut score = 0;
    let mut lasts = [-1; 26];
    let mut t = vec![26; d];
    let depth = 6;
    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let tmp = search(i, j, &c, &s, &mut lasts, depth, d, 0);
            if tmp > max_score {
                max_score = tmp;
                t[i] = j;
            }
        }
        score += max_score;
        lasts[t[i]] = i as i64;
    }

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}

fn search(
    i: usize,
    t: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    depth: usize,
    d: usize,
    cscore: i64,
) -> i64 {
    if depth == 0 || i == d - 1 {
        return calc_score(i, t, &c, &s, lasts) + cscore;
    }

    let mut max_score = -1000000;
    let tmp_last = lasts[t];
    lasts[t] = i as i64;
    let tmp_score = calc_score(i, t, &c, &s, lasts);
    let mut cands = BinaryHeap::new();
    for j in 0..26 {
        let tmp_score = calc_score(i + 1, j, &c, &s, lasts);
        cands.push((tmp_score, j));
    }
    for &(_, j) in cands.iter().take(3) {
        let tmp = search(i + 1, j, &c, &s, lasts, depth - 1, d, cscore + tmp_score);

        if tmp > max_score {
            max_score = tmp;
        }
    }

    lasts[t] = tmp_last;
    max_score + cscore
}


Measured memory_bytes: 2352
#include <stdio.h>

int main(void) {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);

	int sum;
	if (a >= b && a >= c) sum = b+c;
	else if (b >= a && b >= c) sum = a+c;
	else sum = a+b;
	printf("%d\n", sum);
}


Measured memory_bytes: 128
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> s;
  rep(i, Size(s) / 2) {
    if (s[i] == s[Size(s) - i - 1]) continue;
    ans++;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long ll;
#define pair<int,int> P
#define sc(N) scanf("%lld",&N);
using namespace std;
int N;
string s;
int A[100005];

int main()
{
    cin>>s;
    int n=s.length();
    int j=0;
    for(int i=0; i<n;)
    {
       // cout<<i<<endl;
        if(s[i]=='R')
        {
            while(s[i+j]=='R')
            {
                j++;
            }

            int k=i+j;i=i+j;
            while(j>0)
            {
                if(j&1)A[k-1]++;
                else A[k]++;
                j--;
            }

        }
        else
        i++;

    }


     for(int i=n-1; i>=0;)
    {
        //cout<<i<<endl;
        j=0;
        if(s[i]=='L')
        {
            while(s[i-j]=='L')
            {
                j++;
            }
            //i=i-j;
            int k=i-j;i=i-j;
            while(j>0)
            {
                if(j&1)A[k+1]++;
                else A[k]++;
                j--;
            }


        }
        else
        i--;

    }
    for(int i=0;i<n;i++){
        cout<<A[i]<<' ';
    }
    cout<<'\n';

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<int> vec;
    for (int i = 0; i < n; ++i) {
        int tmp; cin >> tmp;
        vec.push_back(tmp);
    }
    sort(vec.begin(), vec.end());
    vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
    if (n == vec.size()) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    if(n < 1200) cout << "ABC" << endl;
    else if(n < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    return 0;
}

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

using namespace std;

const int N = 4010;
int n, suf[N][3];
char c[] = {'R', 'G', 'B'};
string s;
long long ans = 0;

void calc(int type1, int type2, int j) {
    for (int i = 0; i < j; i++) {
        if (s[i] == type1) {
            ans += 1LL * suf[j + 1][type2];
            if (2 * j - i >= 0 && 2 * j - i < n && s[2 * j - i] == type2)
                ans--;
        }
    }
}

void solve() {
    cin >> n >> s;
    for (int i = n - 1; i >= 0; i--) {
        for (int k = 0; k < 3; k++) {
            suf[i][k] = suf[i + 1][k];
            if (s[i] == c[k]) {
                suf[i][k]++;
                s[i] = k;
            }
        }
    }
    for (int j = 1; j < n; j++) {
        if (s[j] == 0) {
            calc(1, 2, j);
            calc(2, 1, j);
        }
        else if (s[j] == 1) {
            calc(0, 2, j);
            calc(2, 0, j);
        }
        else {
            calc(0, 1, j);
            calc(1, 0, j);
        }
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 3688
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aizu
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var vertices = new Dictionary<int, int[]>();
            var isArrived = new Dictionary<int, bool>();

            for (var i = 0; i < n; i++)
            {
                var line = Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
                vertices.Add(line[0], line.Skip(2).ToArray());
                isArrived.Add(line[0], false);
            }

            var output = new Dictionary<int, int[]>();

            var count = 0;
            foreach (var id in vertices.Keys)
            {
                if (!isArrived[id])
                {
                    count = Dfs(id, vertices, count, isArrived, output);
                }
            }

            var sortedOutput = output.OrderBy(keyValuePair => keyValuePair.Key);

            foreach (var keyValuePair in sortedOutput)
            {
                Console.WriteLine($"{keyValuePair.Key} {keyValuePair.Value[0]} {keyValuePair.Value[1]}");
            }
        }

        private static int Dfs(int id, Dictionary<int, int[]> vertices, int count, Dictionary<int, bool> isArrived, Dictionary<int, int[]> output)
        {
            count++;
            var startCount = count;
            isArrived[id] = true;

            for(var i = 0; i < vertices[id].Length; i++)
            {
                if (!isArrived[vertices[id][i]])
                {
                    count = Dfs(vertices[id][i], vertices, count, isArrived, output);
                }
            }

            count++;
            output.Add(id, new int[2] { startCount, count });
            return count;
        }
    }
}



Measured memory_bytes: 18664
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int a,b,m;
	cin >> a >> b >> m;
	vector<int> aa(a);
	vector<int> bb(b);
	for(int i=0;i<a;++i)cin >> aa[i];
	for(int i=0;i<b;++i)cin >> bb[i];
	vector<int> mm(m);
	for(int i=0;i<m;++i){
		int x,y,c;
		cin >> x >> y >> c;
		mm[i] = aa[x-1] + bb[y-1] - c;
	}
	sort(mm.begin(),mm.end());
	sort(aa.begin(),aa.end());
	sort(bb.begin(),bb.end());
	int min = aa[0] + bb[0];
	for(int i=0;i<m;++i){
		if(mm[i] < min)min = mm[i];
	}
	cout << min << endl;
}

Measured memory_bytes: 1408
def main():
    A = [list(map(int, input().split())) for i in range(3)]
    N = int(input())
    b = [int(input()) for i in range(N)]
    
    for i in range(3):
        for j in range(3):
            for k in range(N):
                if A[i][j] == b[k]:
                    A[i][j] = 0
    
    ans = "No"
    for i in range(3):
        if A[i][0]+A[i][1]+A[i][2]==0:
            ans = "Yes"
        if A[0][i]+A[1][i]+A[2][i]==0:
            ans = "Yes"
    if A[0][0]+A[1][1]+A[2][2]==0:
        ans = "Yes"
    if A[0][2]+A[1][1]+A[2][0]==0:
        ans = "Yes"
    print(ans)
main()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main{
    public static void main(String args[]){
	try{
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String str;
	    int count = 0;
	    int[] val = new int[4];
	    while(null != (str = br.readLine())){
		int n = Integer.parseInt(str);
		count =0;
		if(n >= 37){ //満たすものなし
		    System.out.println("0");
		    continue;
		}
		else{
		    for (val[0] = 0; val[0] < 10; val[0]++) {
			for (val[1] = 0; val[1] < 10; val[1]++) {
			    for (val[2] = 0; val[2] < 10; val[2]++) {
				for (val[3] = 0; val[3] < 10; val[3]++) {
				    if((val[0]+val[1]+val[2]+val[3]) == n){
					count++;
				    }
				}
			    }
			}
		    }
		}
		System.out.println(count);
	    }
	}
	catch(Exception e){
	    System.exit(0);
	}
    }
}

Measured memory_bytes: 19704
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

type Katana = (i64, i64);

fn main() {
    let (n, h): (usize, i64) = read();
    let mut katana: Vec<Katana> = readn(n);
    katana.sort_by_key(|k| -k.1);

    let mut slash = 0;
    for k in &katana {
        slash = max(slash, k.0);
    }

    let mut best = (h + slash - 1) / slash;
    let mut throw = 0;
    for i in 0..n {
        throw += katana[i].1;
        let mut sl = i as i64 + 1;
        if h > throw {
            sl += (h - throw + slash - 1) / slash;
        }
        best = min(best, sl);
    }
    println!("{}", best);
}


Measured memory_bytes: 6396
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long

using namespace std;

ll v[55];
ll ans=0;
void cnt(int a,int b){
	double sum=1;
	if(a>b/2)	
		a=b-a;
	for(int i=b,j=1;i>=b-a+1;i--,j++){
		sum*=i*1.0/j;
	}
	ans+=sum;	
}

bool cmp(ll a,ll b){
	return a>b;//从大到小排序 
}

int main(){
	int n,min_,max_;
	scanf("%d %d %d",&n,&min_,&max_);
	for(int i=1;i<=n;i++){
		scanf("%lld",&v[i]);
	}
	
	sort(v+1,v+n+1,cmp);
	int num=min_;
	double ave=0;
	ave+=v[1];
	int same=1,dsam;
	for(int i=2;i<=min_;i++){
		ave+=v[i];
		if(v[i]==v[i-1]){
			same++;
		}
		else {
			same=1;
		}
	}
	ave/=num;//计算选最少的数时最大平均值
	dsam=min_-same;//已选择的不同的数 

	for(int i=min_+1;v[i]==v[min_]&&i<=n;i++){
		same++;//已选择+未选择的相同的数 
	} 
	if(dsam==0){//如果所有的数都相同 
		for(int k=min_;k<=max_;k++){
			if(k>same)	
				break;
			cnt(k,same);
		}
	}
	else {
		cnt(min_-dsam,same);
	}
	printf("%.6lf\n%lld\n",ave,ans);
	return 0; 
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#define MAXN 200010
std::map<int, int> M;
int a[MAXN], b[MAXN], c[MAXN], d[MAXN], p[MAXN], n, m;
inline int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[0] ^= a[i];
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]), b[0] ^= b[i];
	memcpy(c, a, sizeof(c));
	memcpy(d, b, sizeof(d));
	std::sort(c, c + n + 1);
	std::sort(d, d + n + 1);
	for (int i = 0; i <= n; i++)
		if (c[i] != d[i]) return puts("-1"), 0;
	for (int i = 0; i <= n; i++)
		if (a[i] != b[i]) goto fail;
	return puts("0"), 0;
fail:
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		if (!i || a[i] != b[i]) {
			if (!M.count(a[i])) {
				M[a[i]] = ++m;
				p[m] = m;
			}
			if (!M.count(b[i])) {
				M[b[i]] = ++m;
				p[m] = m;
			}
			int A = find(M[a[i]]), B = find(M[b[i]]);
			if (A != B) p[A] = B;
			ans += i > 0;
		}
	}
	for (int i = 1; i <= m; i++)
		if (find(i) == i) ans++;
	printf("%d\n", ans - 1);
	return 0;
}

Measured memory_bytes: 8576
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

a,b,c,d=rl()
v2_1 = [a-c,b-d]
v2_3 = [v2_1[1],-v2_1[0]]
x3 = c+v2_3[0]
y3 = d+v2_3[1]
x4 = x3+v2_1[0]
y4 = y3+v2_1[1]

print(x3,y3,x4,y4)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const ll mod = 1000000007;
vector<vector<int>> G;
vector<int> K;
int main() {
	int N, M;
	cin >> N >> M;
	double v;
	multiset<double, std::greater<double>> A;
	rep(i, 0, N)cin >> v, A.insert(v);
	rep(i, 0, M) {
		double v = *A.begin();
		A.erase(A.begin());
		A.insert(v / 2);
	}
	ll S = 0;
	for(auto v : A)S += (ll)v;
	printf("%lld\n", S);
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

ll dp[110][110][2];

int main() {
    string n;
    int K;

    cin >> n >> K;
    vector<int> N;

    for(auto a: n){
        N.push_back(a-'0');
    }
    int l = n.size();

    dp[0][0][0] = 1;
    for(int i=0; i<l; i++){
        for(int j=0; j<=K; j++){
            for(int k=0; k<2; k++){
                for(int x=0; x<10; x++){    
                    int ni=i+1, nj=j, nk=k;
                    if(k==0){
                        if(x>N.at(i)) continue;
                        else if(x<N.at(i)) nk=1;
                    }
                    if(x!=0) nj++;
                    dp[ni][nj][nk] += dp[i][j][k];
                }
            }
        }
    }

    std::cout << dp[l][K][0] + dp[l][K][1] << endl;


}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define inf 1e9
#define F first
#define S second
#define dbg(x) cout<<#x<<" value : "<<x<<"\n";
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--)
#define mst(a,b) memset(a,b,sizeof(a))
#define sf(n) scanf("%d",&n)
#define stf(n,m) scanf("%d%d",&n,&m)
#define pf(n) printf("%d\n",n)
#define slf(n) scanf("%lld",&n)
#define plf(n) printf("%lld\n",n)
priority_queue<int,vector<int>,less<int> > q;
const int N=4e6+10;
const int mod=1e9+7;
int r;
void solve(){
	sf(r);
	printf("%d\n",r*r);
	return;
} 

int main()
{
	solve();
	return 0;
} 

Measured memory_bytes: 256
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


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

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
//#define int long long
#define ll long long
#define all(x) x.begin(),x.end()
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18

int h[100005];
int dp[100005];
int solve(int n, int i){
    if(i==n)
        return 0;
    //int a=INT_MAX,b=INT_MAX;
    //if(i+1<=n)
    if(dp[i]!=-1)
        return dp[i];
    dp[i] = solve(n,i+1) + abs(h[i]-h[i+1]) ;
     if(i+2<=n){
         int b = solve(n,i+2);
        dp[i] = min(dp[i],b+abs(h[i]-h[i+2]));
     }

    //dp[i] a + abs(h[i]-h[i+1]);
    return dp[i];
}

signed main(){
IOS;
int n;
cin>>n;
for(int i=1;i<=n;i++){
    cin>>h[i];dp[i]=-1;
}


    /*
    dp[n]=0;
    for(int i=n-1;i>=1;i--){
        dp[i]=dp[i+1] + abs(h[i]-h[i+1]);
        if(i+2 <= n){
            dp[i]=min(dp[i],dp[i+2]+abs(h[i]-h[i+2]));
        }
    }
    cout << dp[1] <<endl;
    */
 cout << solve(n,1);
return 0;
}



Measured memory_bytes: 5760
void main() {
	auto N = ri;
	ulong[ulong] a;
	foreach(i; readAs!(ulong[])) {
		a[i]++;
	}
	ulong count;
	foreach(i, v; a) {
		if(i > v) {
			count += v;
		} else {
			count += v - i;
		}
	}
	count.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

T[] deepcopy(T)(T[] a) {
	static if(isArray!T) {
		T[] res;
		foreach(i; a) {
			res ~= deepcopy(i);
		}
		return res;
	} else {
		return a.dup;
	}
}

Measured memory_bytes: 8920
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int main()
{
	long long d,n;
	cin>>d>>n;
	if(n==100)
	{
		n++;
	}
	cout<<(long long)pow(100,d)*n;
}

Measured memory_bytes: 256
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
int n;
int time;
int A[101][101]; /* 1<= n <= 100 */
int color[101];
int d[101];
int head=0,tail=0;
 
 
void BFS(int s);
void Enqueue(int Q[],int s);
int Dequeue(int Q[]);
 
int main(){
  int i,j;
  int u,k,v;
 
  scanf("%d",&n);
 
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      A[i][j]=0;
    }
  }
   
 
  for(i=1;i<=n;i++){
    scanf("%d %d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&v);
      A[u][v]=1;
    }
  }
   
  BFS(1);
 
  for(i=1;i<=n;i++){
    printf("%d %d\n",i, d[i]);
  }
 
  return 0;
}
 
void Enqueue(int Q[],int s){
  Q[tail]=s;
  tail++;
}
 
int Dequeue(int Q[]){
  head++;
  return Q[head-1];
}
 
void BFS(int s){
  int i;
  int Q[101];
  int u;
 
  for(i=1;i<=n;i++){
    color[i]=WHITE;
    d[i]=-1;
  }
  color[s]=GRAY;
  d[s]=0;
  Enqueue(Q,s);
   
  while(head!=tail){
    u=Dequeue(Q);
    for(i=1;i<=n;i++){
      if(A[u][i]==1){   /* check array element */
    if(color[i]==WHITE){
      color[i]=GRAY;
      d[i]=d[u]+1;
      Enqueue(Q,i);
    }
      }
    }
    color[u]=BLACK;
  }
}


Measured memory_bytes: 1992
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
typedef long long ll;
const int INF = 1001001001;
const int mod = 1000000007;

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

    //for prime mod
    mint inv() const
    {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const
    {
        mint res(*this);
        return res /= a;
    }
};

/*
- 余事象を求める
- 繰り返しニ乗法
- こんな感じの式を使う
*/

mint f(int n)
{
    if (n == 0)
        return 1;
    mint x = f(n / 2);
    x *= x;
    if (n % 2 == 1)
        x *= 2;
    return x;
}

mint choose(int n, int a)
{
    mint x = 1, y = 1;
    rep(i, a)
    {
        x *= n - i;
        y *= i + 1;
    }
    // cout << x.x / y.x << endl;
    return x / y;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    mint ans = f(n);
    // cout << ans.x << endl;
    ans -= 1;
    ans -= choose(n, a);
    ans -= choose(n, b);
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(raw_input())
p = [0 for i in range(0, 101)]
m = [[0 for i in range(0, 101)] for j in range(0, 101)]
for i in range(1, n+1):
    p[i-1], p[i] = map(int, raw_input().split())
    
for l in range(2, n+1):
    for i in range(1, n-l+2):
        j = i+l-1
        m[i][j] = float("inf")
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j])

print m[1][n]

Measured memory_bytes: 6552
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    Hello
    int arr[4][4], n;
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
            cin >> arr[i][j];
    cin >> n;
    while(n--)
    {
        int a;
        cin >> a;
        for(int i = 0; i < 3; i++)
            for(int j = 0; j < 3; j++)
                if(arr[i][j] == a)
                    arr[i][j] = -1;
    }
    int cntr = 0;
    for(int i = 0; i < 3; i++)
    {
        bool ok = true;
        for(int j = 0; j < 3; j++)
        {
            if(arr[i][j] != -1)
            {
                ok = false;
                break;
            }
        }
        cntr += ok;
    }
    if(cntr)
        return cout << "Yes", 0;
    cntr = 0;
    for(int j = 0; j < 3; j++)
    {
        bool ok = true;
        for(int i = 0; i < 3; i++)
        {
            if(arr[i][j] != -1)
            {
                ok = false;
                break;
            }
        }
        cntr += ok;
    }
    if(cntr)
        return cout << "Yes", 0;
    if((arr[0][0] == -1 && arr[1][1] == -1 && arr[2][2] == -1) ||
       (arr[0][2] == -1 && arr[1][1] == -1 && arr[2][0] == -1))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,d,e,f,g,h;
  int S,T;
  scanf("%d %d %d %d\n %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h);
  S=a+b+c+d;
  T=e+f+g+h;
  if(S<T){
    printf("%d\n",T);
  }
  else if(S>T) printf("%d\n",S);
  else if(S==T) printf("%d\n",T);
  return(0);
}

Measured memory_bytes: 592
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
bool check(string,string);
int main(){
	int n,p;
	string s;
	cin>>s;
	n=s.size();
	for(int i=0;i<n;i++){
		p=n-i;
		string a=s.substr(0,(n-i)/2);
		string b=s.substr((n-i)/2,(n-i)/2);
		if(i!=0 && p%2==0 && check(a,b)==true){
			break;
		}
	}
	cout<<p<<endl;
	return 0;
}
bool check(string M,string N){
	int sum=0;
	for(int i=0;i<M.size();i++){
		if(M[i]==N[i]){
			sum++;
		}
	}
	if(sum==M.size()){
		return true;
	}
	else{
		return false;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

typedef long long ll;

const int MAXN = 5005;
const ll INF = 1e18;

int n,A,B;
int p[MAXN];

ll ans;
ll f[MAXN][MAXN];
ll MIN[MAXN][MAXN];

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> A >> B;
	for (int v,i = 1;i <= n;i++)
	{
		cin >> v;
		p[v] = i;
	}
	ans = INF;
	for (int i = 0;i <= n;i++)
		for (int j = 0;j <= n;j++)
			f[i][j] = MIN[i][j] = INF;
	f[0][0] = 0;
	for (int i = 0;i <= n;i++)
		MIN[0][i] = 0;
	for (int i = 1;i <= n;i++)
		for (int j = 0;j <= n;j++)
		{
			if (j == p[i])
				f[i][j] = MIN[i - 1][j - 1];
			else if (j < p[i])
				f[i][j] = MIN[i - 1][j] + B;
			else
				f[i][j] = MIN[i - 1][j] + A;
			if (!j)
				MIN[i][j] = f[i][j];
			else
				MIN[i][j] = min(MIN[i][j - 1],f[i][j]);
			if (i == n)
				ans = min(ans,f[i][j]);
		}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 391552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;







void Main() {
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    static int dp[3005][3005];
    static pair<int, int> previ[3005][3005];
    previ[0][0] = {-1, -1};
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (s[i] == t[j]) {
                if (dp[i][j] + 1 > dp[i+1][j+1]) {
                    dp[i+1][j+1] = dp[i][j] + 1;
                    previ[i+1][j+1] = {i, j};
                }
            }
            if (dp[i][j] > dp[i+1][j]) {
                dp[i+1][j] = dp[i][j];
                previ[i+1][j] = {i, j};
            }
            if (dp[i][j] > dp[i][j+1]) {
                dp[i][j+1] = dp[i][j];
                previ[i][j+1] = {i, j};
            }
        }
    }
    int bi = 0, bj = 0;
    for (int i = 0; i <= n; ++i) {
        if (dp[i][m] > dp[bi][bj]) {
            bi = i, bj = m;
        }
    }
    for (int j = 0; j <= m; ++j) {
        if (dp[n][j] > dp[bi][bj]) {
            bi = n, bj = j;
        }
    }
    string ans = "";
    while (bi != 0 || bj != 0) {
        auto previous = previ[bi][bj];
        if (previous.first == bi-1 && previous.second == bj-1) {
            ans += s[bi-1];
        }
        bi = previous.first, bj = previous.second;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
}

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


Measured memory_bytes: 105984
n,x,y=map(int,input().split())
x-=1
y-=1
cnt=[0]*n
for i in range(n):
  for j in range(i+1,n):
    dist=min(j-i,abs(j-x)+1+abs(i-y),abs(j-y)+1+abs(i-x))
    cnt[dist]+=1
for i in range(1,n):
  print(cnt[i])

Measured memory_bytes: 3444
l=[]
while True:
    ll=[]
    a,op,b=input().split()
    ll.append(int(a))
    ll.append(op)
    ll.append(int(b))
    if op=="?":
        break
    l.append(ll)

for i in range(len(l)):
    if l[i][1]=="+":
        print(int(l[i][0]+l[i][2]))
    elif l[i][1]=="-":
        print(int(l[i][0]-l[i][2]))
    elif l[i][1]=="*":
        print(int(l[i][0]*l[i][2]))
    else:
        print(int(l[i][0]/l[i][2]))


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, A[200010];

signed main(){
    cin >> N;
    REP(i, N) cin >> A[i];
    ll m = A[0], ans = 0;
    REP(i, N){
        if(m > A[i]){
            ans += m - A[i];
        }
        m = max(m, A[i]);
    }
    PRINT(ans);
    return 0;
}

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

const int N = 600;
const int mo = 1e9 + 7;

int n, m;
int dp[N + 5][N + 5];
int f[N + 5], lnk[N + 5];
int a[N + 5], b[N + 5], s[N + 5];

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; ++i) {
        scanf("%d%d", a + i, b + i);
        ++ s[a[i]], ++ s[b[i]];
        lnk[lnk[b[i]] = a[i]] = b[i];
    }

    n <<= 1;
    for(int i = 1; i <= n; ++i) s[i] += s[i-1];
    
    f[0] = f[2] = 1;
    for(int i = 4; i <= N; i += 2) f[i] = 1ll * (i - 1) * f[i - 2] % mo;

    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        for(int j = i + 1; j <= n; j += 2) {
            bool flag = true;
            for(int k = i; k <= j; ++k) if(lnk[k] && (lnk[k] < i || lnk[k] > j)) {
                flag = false;
                break;
            }
            if(!flag) continue;

            dp[i][j] = f[j - i + 1 - (s[j] - s[i-1])];
            for(int k = i; k < j; ++k) dp[i][j] = (dp[i][j] - 1ll * dp[i][k] * f[j - k - (s[j] - s[k])]) % mo;

            ans = (ans + 1ll * dp[i][j] * f[n - (j - i + 1) - (2 * m - (s[j] - s[i-1]))]) % mo;
        }
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1664
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    static final boolean OPEN = true;
    static final boolean CLOSE = false;

    static final String toString( final boolean state ) {
	return state == CLOSE ? "Opened by %s\n" : "Closed by %s\n";
    }
    
    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	final int N = Integer.parseInt( stdin.nextLine() );
	Set<String> dict = new HashSet<String>();
	for ( int i = 0; i < N; i++ ) {
	    dict.add( stdin.nextLine() );
	}
	
	boolean state = CLOSE;
	final int M = Integer.parseInt( stdin.nextLine() );
	for ( int i = 0; i < M; i++ ) {
	    final String id = stdin.nextLine();
	    if ( dict.contains( id ) ) {
		System.out.printf( toString( state ), id );
		state = !state;
	    } else {
		System.out.printf( "Unknown %s\n", id );
	    }
	}	
    }    
}

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

class A7{
  struct Tree{
    public int id;
    public int parent;
    public int depth;
    public int height;
    public int left, right;
    public int sibling;
    public int degree;
    public string type;
  }

  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    var tree = new Tree[n];

    for(int i = 0;i < n;i++){
      tree[i].parent = -1;
    }
    for(int i = 0;i < n;i++){
      var input = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
      var id = input[0];
      var l = input[1];
      var r = input[2];
      tree[id].id = id;
      tree[id].left = l;
      tree[id].right = r;
      tree[id].type = "leaf";
      if(l != -1){
        tree[id].type = "internal node";
        tree[id].degree++;
        tree[l].parent = id;
        tree[l].sibling = r;
      }
      if(r != -1){
        tree[id].type = "internal node";
        tree[id].degree++;
        tree[r].parent = id;
        tree[r].sibling = l;
      }
    }
    for(int i = 0;i < n;i++)
      if(tree[i].parent == -1){
        tree[i].type = "root";
        tree[i].sibling = -1;
        Depth(tree,i,0);
        break;
      }
    for(int j = 0;j < n;j++){
        Console.Write("node ");
        Console.Write(tree[j].id);
        Console.Write(": parent = ");
        Console.Write(tree[j].parent);
        Console.Write(", sibling = ");
        Console.Write(tree[j].sibling);
        Console.Write(", degree = ");
        Console.Write(tree[j].degree);
        Console.Write(", depth = ");
        Console.Write(tree[j].depth);
        Console.Write(", height = ");
        Console.Write(tree[j].height);
        Console.Write(", ");
        Console.WriteLine(tree[j].type);
      }
  }

  static int Depth(Tree[] tree,int id,int depth){
    if(id == -1) return depth - 1;
    tree[id].depth = depth;
    var lh = Depth(tree,tree[id].left,depth + 1);
    var rh = Depth(tree,tree[id].right,depth + 1);
    var h = Math.Max(lh,rh);
    tree[id].height = h - depth;
    return h;
  }
}


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

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

	priority_queue<int> q;
	int sum = 0;
	rep(i,n-1){
		if(s[i] == s[i+1] && sum>0){
			q.push(sum);
			sum = 0;
		}else if(s[i] != s[i+1]){
			sum++;
			if(i == n-2) q.push(sum);
		}
	}
	if(n == 1){
		cout << 0 << endl;
		return 0;
	}

	while(k>0 && q.size()>0){
		int x = q.top();q.pop();
		if(x > 1){
			x -= 2;
			q.push(x);
		}else if(x == 1&& q.size()>0){
			q.pop();
		}
		k--;
	}

	int ans=0;
	while(!q.empty()){
		int x = q.top();q.pop();
		ans += x;
	}
	

	ans = n-1 - ans;
	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
bool visit[55555];
int prime[5000];
inline int read()
{
    int x=0,t=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return x*t;
}
void buildprime(){
	for(int i=2;i*i<=55555;i++){
		if(!visit[i]){
			for(int j=i*i;j<55555;j+=i){
				visit[j]=true;
			}
		}
	}
	int k=0;
	for(int i=11;i<55555;i+=5){
		if(!visit[i]&&i%10==1)
		prime[k++]=i;
	}
}
int main(){
	int n;
	n=read();
	buildprime(); 
	for(int i=0;i<n-1;i++)
	cout<<prime[i]<<" ";
	cout<<prime[n-1];
}

Measured memory_bytes: 256
n,k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
if k == 0
  puts a.max
  exit
end
left = 0
right = a.max
ans = 0
while right - left > 1
  mid = left + (right - left) / 2
  cnt = 0
  a.each do |x|
    cnt += (x-1) / mid
  end
  if cnt <= k
    right = mid
  else
    left = mid
  end
end
puts right

Measured memory_bytes: 29844
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONG_INF 800000000000000000
int main() {
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 0;i < n;++i) {
		int tmp;
		cin >> tmp;
		cnt += tmp % 2;
	}
	cnt %= 2;
	if (cnt == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 764
def calc(c, s):
    itr, maxa = -1, 0
    for i in range(len(s)):
        if(s[i] == c):
            maxa = max(i - itr - 1, maxa)
            itr = i
    maxa = max(maxa, len(s) - 1 - itr)
    return maxa


s = input()
mini = 1 << 30
for c in range(ord('a'), ord('z') + 1):
    mini = min(calc(chr(c), s), mini)
print(mini)


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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

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

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
    os << "[";
    for (auto x : V) os << x << ", ";
    return os << "]";
}
//--------------------------------------------------//
int n, m;
vector<int> adj[100010], rev[100010];
int indeg[100010];
vector<int> ord;
int ans[100010];
int dep[100010];

int main() {
    use_cio();
    cin >> n >> m;
    rep(i, n + m - 1) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        rev[v].push_back(u);
        indeg[v]++;
    }
    queue<int> que;
    repp(i, 1, n + 1) if (indeg[i] == 0) que.push(i);
    int pv = 0;
    while (!que.empty()) {
        auto cur = que.front();
        que.pop();
        ord.push_back(cur);
        for (auto nxt : adj[cur]) {
            indeg[nxt]--;
            if (indeg[nxt] == 0) que.push(nxt);
        }
    }
    rep(i, n) {
        if (i == 0)
            ans[ord[i]] = 0;
        else {
            int mx = -1, mh = -1;
            for (auto nxt : rev[ord[i]]) {
                if (dep[nxt] > mx) {
                    mx = dep[nxt];
                    mh = nxt;
                }
            }
            ans[ord[i]] = mh;
            dep[ord[i]] = dep[mh] + 1;
        }
    }
    repp(i, 1, n + 1) cout << ans[i] << endl;
}


Measured memory_bytes: 13436
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

main(){
 int n, A[1000];
 while(1){
  cin >> n;
  if(n==0)break;
  for(int i=0; i<n; i++) cin >> A[i];
  int sum=0;
 for(int i=0; i<n; i++) sum +=A[i];
 double avg=1.0*sum/n;
 double dist=0.0;
 for(int i=0; i<n; i++){
  dist+=(avg-A[i])*(avg-A[i]);
 }
 printf("%lf\n", sqrt(dist/n));
}
return 0;
}


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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  for (int i = 0; i < N; i++)
    cin >> m.at(i);
  int M = 0;
  for (int i = 0; i < N; i++)
    M = M + m.at(i);
  M = X - M;
  sort(m.begin(), m.end());
  cout << N + M / m.at(0) << endl;
}


Measured memory_bytes: 256
N,H=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(N)]
ab.sort()
M=ab[-1][0]
B=[b for a,b in ab]
B.sort()
B=B[::-1]
ans=0
for b in B:
    if H>0 and b>M:
        H-=b
        ans+=1
    else:
        break
ans+=0--max(0,H)//M
print(ans)

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

int main() {
  int N;
  cin >> N;
  vector<vector<pair<int, int>>> V(N);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    while (A--) {
      int x, y;
      cin >> x >> y;
      V.at(i).push_back({--x, y});
    }
  }

  int ans = 0;
  for (int bit = 0; bit < 1 << N; bit++) {
    vector<int> tmp(N, -1);
    for (int i = 0; i < N; i++) {
      if (bit >> i & 1) {
        for (auto [x, y] : V.at(i)) {
          if ((bit >> x & 1) ^ y) goto NG;
          if (tmp.at(x) == -1) tmp.at(x) = y;
          else if (tmp.at(x) != y) goto NG;
        }
      }
    }
    ans = max(ans, __builtin_popcount(bit));
    NG:;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main()
{
    int H, W;
    int N;
    cin >> H >> W >> N;

    int grid[100][100];
    int x = 0, y = 0;
    int dir = 1;

    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++)
        {
            grid[y][x] = i + 1;
            if ((dir == 1 && x == W - 1) || (dir == -1 && x == 0))
            {
                y++;
                dir *= -1;
            }
            else
            {
                x += dir;
            }
        }
    }

    for (int i = 0; i < H;i++)
    {
        for (int j = 0; j < W;j++)
        {
            cout << grid[i][j];
            if(j != W - 1)
            {
                cout << " ";
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384