akhauriyash/Code-Regression huggingface dataset:
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;
use std::ops::Range;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<i64>();
    let a = scan.read::<i64>();
    let b = scan.read::<i64>();
    let c = scan.read::<i64>();
    let d = scan.read::<i64>();
    let mut ret = false;
    if n % 2 == 1 {
        let r = a + (n / 2) * (c - d) .. a + (n / 2) * (d - c) + 1;
        for i in 0..n / 2 {
            let rn = r.start + (c + d) * i .. r.end + (c + d) * i;
            let rp = r.start - (c + d) * i .. r.end - (c + d) * i;
            ret |= contains(rn, b);
            ret |= contains(rp, b);
        }
    } else {
        let r = a + (n / 2) * c - (n / 2 - 1) * d .. a - (n / 2 - 1) * c + (n / 2) * d + 1;
        for i in 0..n / 2 - 1 {
            let rn = r.start + (c + d) * i .. r.end + (c + d) * i;
            ret |= contains(rn, b);
        }
        for i in 1..n/2 + 1 {
            let rp = r.start - (c + d) * i .. r.end - (c + d) * i;
            ret |= contains(rp, b);
        }
    }
    println!("{}", if ret {"YES"} else {"NO"});
}

fn contains(r: Range<i64>, x: i64) -> bool {
    r.start <= x && x < r.end
}


// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
use std::cmp;

fn main() {
  let N = read::<usize>()[0];
  let mut dp: Vec<(i64, i64, i64)> = Vec::new();
  dp.push((0, 0, 0));
  for i in 0..N {
    let abc = read::<i64>();
    dp.push((
      cmp::max(dp[i].1, dp[i].2) + abc[0],
      cmp::max(dp[i].2, dp[i].0) + abc[1],
      cmp::max(dp[i].0, dp[i].1) + abc[2]
      ));
  }
  let max = cmp::max(dp[N].0, cmp::max(dp[N].1, dp[N].2));
  
  println!("{}", max);
}

fn read<T: std::str::FromStr>() -> Vec<T> {
  gets().split_whitespace().filter_map(|s|s.parse().ok()).collect()
}

fn gets() -> String {
  let mut line = String::new();
  std::io::stdin().read_line(&mut line).ok();
  line.trim().to_string()
}


Measured memory_bytes: 4508
<?php
// 標準入力から取得
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}
 
class SubmitAnswer {
    public static function println($answer = "") {
        echo $answer . PHP_EOL;
    }
}
 
$sc = new Scanner();
$n = $sc->nextInt();
$minDelta = $n;
$array = [];
 
for ($i=0;$i<$n;$i++) {
    $array[] = $sc->nextInt();
}
 
$average = array_sum($array) / count($array);
$arrayReversed = array_reverse($array);
 
for ($i=0;$i<100;$i++) {
    if (abs($arrayReversed[$i] - $average) <= $minDelta){
        $answer = $n - $i -1;
        $minDelta = abs($arrayReversed[$i] - $average);
    }
}
 
SubmitAnswer::println("$answer");

Measured memory_bytes: 3956
#include <stdio.h>

int main()
{
	int primeTable[1300];
	int index = 0;
	for (int i = 2; i < 10000; i++)
	{
		for (int j = 0; j < index; j++)
		{
			if (i % primeTable[j] == 0)
				goto BREAK_1;
		}
		primeTable[index] = i;
		index++;
	BREAK_1:;
	}
	int start, end, pointer, tempSum, input, output;
	for (; (scanf("%d", &input)) && input != 0; printf("%d\n", output))
	{
		start = output = tempSum = end = 0;
		do
		{
			if (tempSum + primeTable[end] <= input)
			{
				tempSum += primeTable[end];
				if (tempSum == input)
					output++;
				end++;
			}
			else
			{
				tempSum -= primeTable[start];
				start++;
			}
		} while (start <= end);
	}
	return 0;
}


Measured memory_bytes: 2028
from fractions import gcd


def solve():
    N, *A = map(int, open(0).read().split())
    
    ans = 0
    left = [0 for _ in range(N+1)]
    right = [0 for _ in range(N+1)]
    for i in range(N):
        left[i+1] = gcd(left[i], A[i])
    for i in range(N-1, -1, -1):
        right[i] = gcd(right[i+1], A[i])
    for i in range(N):
        ans = max(ans, gcd(left[i], right[i+1]))
    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 16116
import java.util.*;
class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	String str = scan.next();
    	int N = Integer.parseInt(str);
      	str = scan.next();
      	int L = Integer.parseInt(str);
      	ArrayList<String> list = new ArrayList<>();
      	
      	for(int i = 0; i < N; i++){
        	String input = scan.next();
          	list.add(input);
        }
      	
      	Collections.sort(list);
      	for(int i = 0; i < N ; i++){
        	String input = list.get(i);
          	System.out.print(input);
        }
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

constexpr double EPS = 1e-7;
constexpr int INF = 1e9;
#define PI (acos(-1))

constexpr int MOD = 1e9 + 7;

vector<int> sieveOfEratosthenes(int n) {
	vector<int> primes(n + 1);
	for (int i = 2; i <= n; ++i)
		primes[i] = i;
	for (int i = 2; i * i <= n; ++i)
		if (primes[i])
			for (int j = i * i; j <= n; j += i)
				primes[j] = 0;
	return primes;
}

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int Q;
	cin >> Q;
	vector<int> l(Q);
	vector<int> r(Q);
	int r_max = -1;
	for (int i = 0; i < Q; i++) {
		cin >> l[i] >> r[i];
		if (r[i] > r_max) {
			r_max = r[i];
		}
	}

	auto primes = sieveOfEratosthenes(r_max);

	vector<int> cum(r_max + 1, 0);
	for (int i = 1; i <= r_max; i++) {
		cum[i] = cum[i - 1];
		if (i % 2 == 0) {
			continue;
		}

		if (primes[i] > 0 && primes[(i + 1) / 2] > 0) {
			cum[i]++;
		}
	}
	for (int i = 0; i < Q; i++) {
		if (primes[l[i]] > 0 && primes[(l[i] + 1) / 2] > 0) {
			cout << (cum[r[i]] - cum[l[i]] + 1) << endl;
		} else {
			cout << (cum[r[i]] - cum[l[i]]) << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 2176
n,x,y=list(map(int,input().split()))
if x+y<=n:
    Min=0
    if x<=y:
        Max=x
    else:
        Max=y
else:
    Min=(x+y)-n
    if x<=y:
        Max=x
    else:
        Max=y
print("{} {}".format(Max,Min))


Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int N,a,b,count=0;
  scanf("%d %d %d",&N,&a,&b);
  for(int k=1;k<=N;k++){
    int keta = log10(k)+1;int tmp = k;int stock=0;
    //printf("%d:keta:%d\n",k,keta);
    int num[keta];
    for(int i=0;i<keta;i++){
      num[i]=tmp%10;
      tmp = (tmp-num[i])/10;
    }
    for(int j=0;j<keta;j++)stock += num[j];
      //printf("%d\n",stock);
    if(stock >= a && stock <= b){
      count+=k;//printf("%d\n",k );
    }
  }
  printf("%d",count);
  return 0;
}


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

using namespace std;

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

    int now = 1;
    int tmp = 0;
    vector<int> nums;
    for (int i = 0; i < n; i++) {
        if (s[i] == now + '0') tmp++;
        else {
            nums.push_back(tmp);
            tmp = 1;
            now = 1 - now;
        }
    }
    nums.push_back(tmp);
    if (now == 0) nums.push_back(0);

    int ans = 0;

    int left = 0;
    int right = 0;
    int sum = 0;
    for (int i = 0; i < nums.size(); i += 2) {
        int nextLeft = i;
        int nextRight = min((int) nums.size(), 2 * k + i + 1);

        while (nextLeft > left) {
            sum -= nums[left];
            left++;
        }

        while (nextRight > right) {
            sum += nums[right];
            right++;
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int n;
pair<int,int> p[25];

int main(){
	while(cin>>n&&n){
		rep(i,n)cin>>p[i].second>>p[i].first;
		sort(p,p+n);
		int f=1,sum=0;
		rep(i,n){sum+=p[i].second;if(sum>p[i].first)f=0;}
		cout<<(f?"Yes":"No")<<endl;
	}
}

Measured memory_bytes: 0
##templete
n, k = gets.chomp.split(" ").map { |e|  e.to_i }
s = gets.chomp

nums = []
num = "1"
count = 0

for i in 0..n-1 do
  if s[i] == num
    count += 1
  else
    nums.push(count)
    num = ((num.to_i + 1) % 2).to_s  #文字の切り替え
    count = 1
  end
end

nums.push(count)

if nums.length % 2 == 0
  nums.push(0)
end



# まず累積和を作成する
sums = [0]

for i in 0..nums.length-1 do
  sums[i+1] = sums[i] + nums[i]
end

ans = 0
add = 2 * k + 1

0.step(nums.length-1, 2) do |i|

  left = i
  right = [i + add, nums.length].min
  # [left, right)の区間のsumを計算
  tmp = sums[right] - sums[left]
  ans = ans > tmp ? ans : tmp
end




puts ans


Measured memory_bytes: 3708
n, m = map(int, input().split())
kl = []
for i in range(n):#h:高さ
    kl.append([int(m) for m in input().split()])
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n + 1)

    # 検索
    # 根ならその番号を返す
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

        # 併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
        # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

u = UnionFind(n + m)
for i in range(n):
    ki = kl[i][0]
    for j in range(1, ki + 1):
        u.union(m + i + 1, kl[i][j])
print(('NO', 'YES')[all(u.same_check(m + 1, m + i + 1) for i in range(n))])

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

const int maxn = 1e5 + 10;
char s[maxn];
struct Point {
    int l, r;
} G[maxn];

int main() {
    int len, k;
    scanf("%d%d", &len, &k);
    scanf("%s", s);
    int l = 0;
    int cnt = 0;
    s[len] = '0';
    G[0].l = G[0].r = 0;
    cnt = 1;
    for (int i = 0; i <= len; i++) {
        if (s[i] == '1') {
            if (!l) G[cnt++].l = i;
            l++;
        } else {
            if (l) G[cnt-1].r = i - 1;
            l = 0;
        }
    }
    G[cnt].l = G[cnt].r = len - 1;
    cnt++;
    int ans = 0;
    if (k + 1 >= cnt) {
        printf("%d\n", len);
        return 0;
    }
    for (int i = 0; i < cnt; i++) {
        int temp = i + k;
        if (temp >= cnt) break;
        ans = max(ans, G[temp].r - G[i].l + 1);
    }
    ans = min(ans, len);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
	for(int n;scanf("%d",&n),n;){
		vector<int> a,b;
		for(int i=0;i<n;i++){
			int c; scanf("%d",&c);
			if(i&1){
				int cnt=0;
				while(a.size()>0 && a.back()!=c){
					cnt+=b.back();
					a.pop_back();
					b.pop_back();
				}
				if(a.size()==0){
					a.push_back(c);
					b.push_back(0);
				}
				b.back()+=cnt+1;
			}
			else{
				int cnt=0;
				while(a.size()>0 && a.back()==c){
					cnt+=b.back();
					a.pop_back();
					b.pop_back();
				}
				a.push_back(c);
				b.push_back(cnt+1);
			}
		}
		int res=0;
		for(int i=0;i<a.size();i++)
			if(a[i]==0)
				res+=b[i];
		printf("%d\n",res);
	}
	
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];

	sort(a.begin(),a.end());

	COMinit();
	lli sum = 0;
	//最小を選択する
	lli cnt=0;
	for(lli j=n-1;j>=m-1;j--){
		if(DEBUG)cout<<"a[i]="<<a[j]<<"COM="<<COM(j,m-1)<<endl;
		sum += (a[j] * COM(j,m-1))%MOD;
		sum %= MOD;
		cnt++;
	}
	REP(i,0,n-m+1){
		if(DEBUG)cout<<"a[i]="<<a[i]<<"COM="<<COM(n-1-i,m-1)<<endl;
		sum += MOD;
		sum -= (a[i] * COM(n-1-i,m-1))%MOD;
		while(sum<0)sum+=MOD;
		sum %= MOD;
	}

	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

bool isprime(int n)
{
	for (int i = 2; i*i <= n; i++)
	{
		if (n%i == 0) return false;
	}
	return true;
}

int main()
{
	int n;
	set<int> used;
	while (cin >> n)
	{
		if (isprime(n)) used.insert(n);
	}
	cout << used.size() << endl;
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long h,sum;
	int k=0;
	cin>>h;
	sum=0;
	while(h)
	{

		sum+=1LL<<k;
		k++;
		h>>=1LL;
		
	}
	cout<<sum<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n);
	LL ones = n % 10;
	if(ones == 3)	puts("bon");
	else if(ones == 0 || ones == 1 || ones == 6 || ones == 8)	puts("pon");
	else	puts("hon");
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k; cin >> n >> k;
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  int res = 1001001001;
  for (int i = 0; i < n - k + 1; i++) {
    int j = i + k - 1;
    int d;
    if (x[i] < 0) {
      d = (x[j] <= 0) ? -x[i] : min(-x[i], x[j]) * 2 + max(-x[i], x[j]);
    } else {
      d = x[j];
    }
    res = min(res, d);
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 4e+4+5;

int n,m;
struct key_point{
	int x,id,tid;
	key_point(const int x_=0,const int id_=0,const int tid_=0){x=x_;id=id_;tid=tid_;}
	friend bool operator <(key_point a,key_point b){return a.x<b.x;}
}key[N*2];
int id[N][2],k;
struct flag{int x,y;}a[N];
struct node{
	int id,l,r;
}tree[N*4];
int tot;
struct edge{
	int x,nxt;
}e[N*200];
int h[N*6],et;
int dfn[N*6],f[N*6],be[N*6],u,t;
int sta[N*6],top;
bool pd[N*6];

void inse(int x,int y){e[++et].x=y;e[et].nxt=h[x];h[x]=et;}

void add(int now,int l,int r,int x,int y,int st){
	if (x<=l&&r<=y){inse(st,tree[now].id);return;}
	int mid=(l+r)/2;
	if (x<=mid)add(tree[now].l,l,mid,x,y,st);
	if (y>mid)add(tree[now].r,mid+1,r,x,y,st);
}

int min(int x,int y){return x<=y?x:y;}

int S[N*6],T;
int H[N*6],lst[N*6];

void tarjan(int st){
	S[T=1]=st;
	while(T){
		int x=S[T];
		if (!dfn[x]){
			dfn[x]=f[x]=++u;
			pd[sta[++top]=x]=1;
			H[x]=h[x];
			lst[x]=-1;
			continue;
		}
		if (H[x]){
			if (lst[x]==0)f[x]=min(f[x],f[e[H[x]].x]);
			if (lst[x]>-1)H[x]=e[H[x]].nxt;
			if (!dfn[e[H[x]].x]){
				S[++T]=e[H[x]].x;
				lst[x]=0;
			}
			else{
				if (pd[e[H[x]].x])f[x]=min(f[x],dfn[e[H[x]].x]);
				lst[x]=1;
			}
		}
		else{
			if (f[x]==dfn[x]){
				t++;
				for(;sta[top+1]!=x;top--){
					pd[sta[top]]=0;
					be[sta[top]]=t;
				}
			}
			T--;
		}
	}
}

bool check(int val){
	int qet=et;
	fo(i,1,n*2)h[i]=0;
	int l=1,r=1;
	fo(i,1,m){
		while(key[i].x-key[l].x>=val)l++;
		while(r<m&&key[r+1].x-key[i].x<val)r++;
		if (l<i)add(1,1,m,l,i-1,key[i].id);
		if (r>i)add(1,1,m,i+1,r,key[i].id);
	}
	u=t=0;
	fo(i,1,k)dfn[i]=be[i]=0;
	fo(i,1,k)
	if (!dfn[i])tarjan(i);
	et=qet;
	fo(i,1,n)
	if (be[id[i][0]]==be[id[i][1]])return 0;
	return 1;
}

void build(int &now,int l,int r){
	now=++tot;
	tree[now].id=++k;
	fo(i,l,r)inse(tree[now].id,key[i].tid);
	if (l==r)return;
	int mid=(l+r)/2;
	build(tree[now].l,l,mid);
	build(tree[now].r,mid+1,r);
}

int main(){
	//freopen("data.in","r",stdin);
	n=get();
	fo(i,1,n){id[i][0]=++k;id[i][1]=++k;}
	fo(i,1,n){
		a[i].x=get();a[i].y=get();
		key[++m]=key_point(a[i].x,id[i][0],id[i][1]);
		key[++m]=key_point(a[i].y,id[i][1],id[i][0]);
	}
	sort(key+1,key+1+m);
	int rt;
	build(rt,1,m);
	int l=1,r=1e+9,ans=0;
	while(l<=r){
		int mid=(l+r)/2;
		if (check(mid))ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 18304
import java.util.Scanner;

class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int cse = 1;
//		int t = sc.nextInt();
		StringBuilder sb = new StringBuilder();
//		while(t-->0) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int a[] = new int[m];
			int sum=0;
			for(int i=0;i<m;i++) {
				a[i] = sc.nextInt();
				sum+=a[i];
			}
			if(sum<=n)
				sb.append(n-sum);
			else
				sb.append("-1");
			sb.append("\n");
			cse++;
//		}
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 46264
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
  double L;
  cin>>L;
  double ee = L/3;

  printf("%.20f\n",ee*ee*ee);








}

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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			var a = new long[n, n];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					long temp = cin.Long();
					a[i, j] = temp;
				}
			}

			for (int k = 0; k < n; k++) {
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < n; j++) {
						long s = a[i, j];
						long d = a[i, k] + a[k, j];
						if (d < s) {
							Console.WriteLine(-1);
							return;
						}
					}
				}
			}

			long sum = 0;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					bool ok = true;
					for (int k = 0; k < n; k++) {
						if (i != k && j != k && a[i, j] == a[i, k] + a[k, j]) {
							ok = false;
							break;
						}
					}

					if (ok) {
						sum += a[i, j];
					}
				}
			}

			long ans = sum / 2;
			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 19416
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL X, A;
	in >> X >> A;
	if (X < A) out << 0 << std::endl;
	else out << 10 << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 
 int main (){
 string s;
 
 cin >> s;
 
 if (s[0] != s[1] && s[0] != s[2] && s[1] != s[2])
 	cout << "Yes" << endl;
 else
 	cout << "No" << endl;
 
 return 0;
 }

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

    ll n;
    cin>>n;
    char a[26];
    string s;
    for(char c='a';c<='z';c++)
    	a[c-'a']=c;

    while(n)
    {
    	int rem=n%26;
    	if(rem==0)
    	{
    		s+='z';
    		n=n/26-1;
    	}
    	else
    	{
    		s+=(rem-1)+'a';
    		n/=26;
    	}
    }

    reverse(all(s));

    cout<<s<<endl;
    
    return 0;
}

Measured memory_bytes: 3608
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		int c = parseInt(sc.next());
		sc.close();
		if(a==b) {
			out.println(c);
		} else if(a==c) {
			out.println(b);
		} else {
			out.println(a);
		}
	}
}


Measured memory_bytes: 23892
list = {'a':0,'b':25,'c':24,'d':23,'e':22,'f':21,'g':20,'h':19,
         'i': 18,'j':17,'k':16,'l':15,'m':14,'n':13,'o':12,'p':11,
         'q': 10,"r":9,'s':8,'t':7,'u':6,'v':5,'w':4,'x':3,'y':2,'z':1}
list2 = {0:'a',1:'b',2:'c',3:'d',4:'e',5:'f',6:'g',7:'h',
         8:'i',9:'j',10:'k',11:'l',12:'m',13:'n',14:'o',15:'p',
         16:'q',17:"r",18:'s',19:'t',20:'u',21:'v',22:'w',23:'x',24:'y',25:'z'}
list3 = {'a':0,'b':1,'c':2,'d':3,'e':4,'f':5,'g':6,'h':7,
         'i': 8,'j':9,'k':10,'l':11,'m':12,'n':13,'o':14,'p':15,
         'q': 16,"r":17,'s':18,'t':19,'u':20,'v':21,'w':22,'x':23,'y':24,'z':25}
s = input()

K = int(input())

for i in range(len(s)):
    num = list[s[i]]
    if num <=K:
        s = s[:i] + 'a' + s[i+1:]
        K -= num

if K >0:
    print(s[:-1]+list2[(list3[s[-1]]+K)%26])
else:
    print(s)

Measured memory_bytes: 178688
#include <stdio.h>

int main(void)
{ 
	int a[3];
	int i,j,m;
	for(i=0;i<3;i++) scanf("%d",&a[i]);
	for(i=0;i<3;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				m=a[i];
				a[i]=a[j];
				a[j]=m;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
	return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N ;
  int a, b, c, d;
  
   for(int i = 0;i < N; i++){
     string S;
     cin >> S; 
     if (S == "P")
       a++;
     else if (S == "W")
       b++;
     else if (S == "G")
       c++;
     else
       d++;
   }
  bool Y = a && b && c && d;
    if (Y == 1)
      cout << "Four" << endl;
    else
      cout << "Three" << endl;
}

Measured memory_bytes: 256
o, *dots = readlines.map{|l| l.split(",").map(&:to_f) }
puts(dots.each_cons(2).map do |i,j|
  a = Math.sqrt((o[0]-i[0])**2 + (o[1]-i[1])**2)
  b = Math.sqrt((o[0]-j[0])**2 + (o[1]-j[1])**2)
  c = Math.sqrt((j[0]-i[0])**2 + (j[1]-i[1])**2)
  z = (a+b+c)/2
  Math.sqrt(z*(z-a)*(z-b)*(z-c))
end.inject(:+))

Measured memory_bytes: 6168
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
ans = 1

def search(A,a,b):
    import bisect
    ans = bisect.bisect_right(A,b) - bisect.bisect_left(A,a)
    return ans

for i in range(A[-1]+1):
    ans = max(ans,search(A,i-1,i+1))
print(ans)

Measured memory_bytes: 14004
#include <cstdio>
#include <iomanip>    // setw 控制输出间隔函数
#include <iostream>   // cin, cout, abs
#include <algorithm>  // max, min, swap, sort
#include <cmath>      // pow
#include <cstring>    // strlen
#include <set>        // set 集合
#include <stack>      // stack 栈
#include <queue>      // queue 队列
#include <string>     // string 字(yang)符(rou)串, substr
#include <map>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    string h;
    cin >> h;
    int t = 0;
    int maxx = 0;
    for( int i = 0; i < n; i++)
    {
        if( h[i] == 'I') t++;
        else t--;
        maxx = max( maxx, t);
    }
    printf("%d\n", maxx);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
  S.append(input())
S = sorted(S)
#print(S)

max_letter = []
max_count = 0
tmp_S = S[0]
count = 0

for i in range(len(S)):
  if i == 0:
    count=1
    max_letter.append(S[i])
    tmp_S = S[i]
  elif tmp_S != S[i]:
    if max_count < count:
      max_count = count
      max_letter = []
      max_letter.append(tmp_S)
    elif max_count == count:
      max_letter.append(tmp_S)
    tmp_S = S[i]
    count=1
  else:
    count+=1
if max_count < count:
  max_letter = list([tmp_S])
elif max_count == count:
  max_letter.append(tmp_S)
  
for i in range(len(max_letter)):
  print(max_letter[i])

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

using namespace std;

string S;

int main(void) {

	cin >> S;

	int N = S.size();

	long long int count = 0;
	long long int ans = 0;
	for (int i = N - 1; i >= 0; i--) {
		
		if (S[i] == 'W') { count++; }
		else { ans+=count; }
	}

	cout << ans << endl;


	//system("pause");
	return 0;

}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
int N, K;

void solve() {

	cin >> N >> K;

	cout << ((K == 1) ? 0 : N - K) << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  string s;
  cin>>s;
  int n,i,j;
  int ans=1,flag=1;
  for(i=1;i<s.length();++i)
  {
    //cout<<i<<" "<<ans<<" "<<flag<<endl;
    if(flag==0)
    {
      ++ans;
      flag=1;
      continue;
    }
    if(s[i]!=s[i-1])
    {
      flag=1;
      ++ans;
      continue;
    }
    if((i+1)<s.length())
    {
      ++ans;
      i=i+1;
      flag=0;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;
 
vector<int> divisor(int a){
    vector<int> res;
    for(int i=2; i<=sqrt(a); i++){
        if(a%i==0){
            res.push_back(i);
            if(i!=a/i) res.push_back(a/i);
        }
    }
    res.push_back(a);
    sort(all(res));
    return res;
}


int main(){
    int n,k; cin >> n >> k;
    vector<int> a(n);
    int sum=0;
    rep(i,n){
        cin >> a[i];
        sum+=a[i];
    }

    vector<int> p=divisor(sum);
    reverse(all(p));

    rep(i,p.size()){
        vector<ll> moda;
        rep(j,n){
            if(a[j]%p[i]) moda.push_back(a[j]%p[i]);
        }
        int ms=moda.size();
        /*if(!ms){
            cout << p[i] << endl;
            return 0;
        }*/
        sort(all(moda));
        vector<ll> rmoda(ms+1);
        rmoda[0]=0;
        rep(j,ms) rmoda[j+1]=p[i]-moda[j]+rmoda[j];
        ll now=0;
        rep(j,ms){
            now+=moda[j];
            if(now==rmoda[ms]-rmoda[j+1]){
                if(now<=k){
                    cout << p[i] << endl;
                    return 0;
                }
                break;
            }
            else if(now>rmoda[ms]-rmoda[j+1]) break;
        }
    }
    cout << 1 << endl;
return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
count=0
if sum(A)<sum(B):
    print(-1)
else:
    dif=[A[i]-B[i] for i in range(N)]
    if min(dif)>=0:
        print(0)
    else:
        difsort=sorted(dif)
        plist=[i for i in difsort if i>=0][::-1]
        mlist=[i for i in difsort if i<0]
        mnum=len(mlist)
        msum=sum(mlist)
        for i in range(len(plist)):
            if msum>=0:
                break
            msum+=plist[i]
            count+=1
            
        
        print(count+mnum)

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

int main() {
  
  int S=0;
  
  cin >> S;
  
  int a = S/100;
  int b = S%100;
  
  if(0<a && a<13 && 0<b && b<13) {
    
    cout << "AMBIGUOUS" << endl;
    
  } else if(0<b && b<13) {
      
      cout << "YYMM" << endl;
      
  } else if(0<a && a<13) {
    
    cout << "MMYY" << endl;
    
  } else {
    
    cout << "NA" << endl;
    
  }
  
  return 0;
  
}


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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

vector<long long> bg_len(51);
vector<long long> pt(51);
long long f(int N, long long X) {
  if(N == 0) return 1;
  if(X == 1) {
    return 0;
  } else if(1 < X && X <= bg_len[N - 1] + 1) {
    return f(N - 1, X - 1);
  } else if(X == bg_len[N - 1] + 2) {
    return pt[N - 1] + 1;
  } else if(bg_len[N - 1] + 2 < X && X <= 2 * bg_len[N - 1] + 2) {
    return pt[N - 1] + 1 + f(N - 1, X - bg_len[N - 1] - 2);
  } else {
    return pt[N];
  }
}

int main() {
  int N;
  long long X;
  cin >> N >> X;
  bg_len[0] = 1;
  pt[0] = 1;
  REP(i, 50) {
    bg_len[i + 1] = 2 * bg_len[i] + 3;
    pt[i + 1] = 2 * pt[i] + 1;
  }
  long long ans = f(N, X);
  cout << ans << endl;
  return 0;
}


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

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int N, long[] A)
        {
            long x = 0;
            long y = A.Sum();
            long min = long.MaxValue;
            foreach (long a in A)
            {
                x += a;
                y -= a;
                min = Math.Min(Math.Abs(y - x), min);
            }
            return min;
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            long[] A = ReadLongs();
            Console.WriteLine(Solve(N, A));
        }
    }
}


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

int main() {
	string s; cin >> s;
	int ans = s.length();
	for (int i = 0; ; i++) {
		if (s[i] == 'A') break;
		ans--;
	}
	for (int i = s.length() - 1; ; i--) {
		if (s[i] == 'Z') break;
		ans--;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<string> v(3);
    rep(i, 0, 3) cin >> v[i];
    string ans = string(1, v[0][0]);
    ans += v[1][1];
    ans += v[2][2];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,d;
  int m=0;
  cin >> n >> d;
  vector<double>a(n);
  vector<double>b(n);
  for (int i=0;i<n;i++) {
    cin >> a.at(i) >> b.at(i); 
    if(sqrt(a[i]*a[i]+b[i]*b[i])<=d){
      m++;
    }
  }
  cout << m << endl;
}

Measured memory_bytes: 6404
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let tbl = Hashtbl.create ~random:true 1000000 in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["find"; s] -> print_endline (if Hashtbl.mem tbl s then "yes" else "no")
    | [_; s] -> Hashtbl.add tbl s ()
    | _ -> assert false
  done

Measured memory_bytes: 43872
#include <stdio.h>

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    int mat[n][m];
    int vec[m];
    int sum[n];
    
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            scanf("%d", &mat[i][j]);
        }
    }
    
    for (int k=0; k<m; k++) {
        scanf("%d", &vec[k]);
    }
    
    for (int l=0; l<n; l++) {
        sum[l] = 0;
    }
    
    for (int s=0; s<n; s++) {
        for (int t=0; t<m; t++) {
            sum[s] += (mat[s][t] * vec[t]);
        }
        printf("%d\n", sum[s]);
    }
    return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VLL;

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


int main(void){
	ll N, K;
    VL H;
    cin >> N >> K;
    rep(i,N){
        ll h;
        cin >> h;
        H.PB(h);
    }

    sort(all(H));

    ll ans = 0;
    ll M = N-K;
    if(M>0){
        rep(i,M){
            ans += H[i];
        }
    }
    

    cout << ans << endl;

    return 0;
}


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

int main() {
  int N, x, a[N];
  cin >> N >> x;
  for (int i = 0; i < N; i++) cin >> a[i];
  sort(a, a + N);
  int counter = 0;
  for (int i = 0; i < N; i++) {
    if (x >= a[i]) {
      x -= a[i];
      counter++;
    }
  }
  if (counter == N && x > 0) counter--;
  cout << counter << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<P> A(N);
    rep(i,N) cin>>A[i].first;
    rep(i,N) A[i].second=i;
    SORT(A);
    set<ll> se;
    se.emplace(-1);
    se.emplace(N);
    ll ans=0;
    rep(i,N){
        ans+=(A[i].second-*(--se.lower_bound(A[i].second)))*(*(se.lower_bound(A[i].second))-A[i].second)*A[i].first;
        se.emplace(A[i].second);
    }
    cout<< ans <<"\n";

}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 12800
def abc168d_double_dots():
    n, m = map(int, input().split())
    path_dict = {}
    for _ in range(m):
        a, b = map(int, input().split())
        if b not in path_dict.keys():
            path_dict[b] = [a]
        else:
            path_dict[b].append(a)
        a, b = b, a
        if b not in path_dict.keys():
            path_dict[b] = [a]
        else:
            path_dict[b].append(a)

    q = [1]
    cnt = 0
    ans = [0] * n
    ans[0] = 1
    while len(q) != 0:
        no = q.pop(0)
        for next_room in path_dict[no]:
            if ans[next_room - 1] == 0:
                ans[next_room - 1] = no
                q.append(next_room)
                cnt += 1

    if cnt != n-1:
        print('No')
        return
    print('Yes')
    for a in ans[1:]:
        print(a)


abc168d_double_dots()

Measured memory_bytes: 40376
#include<stdio.h>
#include<math.h>
int prime(int n)
{
    int i;
    if (n < 2)
        return 0;
    if (n == 2)
        return 1;
    for (i = 2; i <= sqrt(n); i++)
        if (n%i == 0)
            return 0;
    return 1;
}
int main()
{
    int n;
    scanf("%d", &n);
    int ans[55];
    int i = 0;
    int p = 0;
    while (p < n)
    {
        for (;;)
        {
            if (prime(10 * i + 7) == 1)
                break;
            i++;
        }
        ans[p] = 10 * i + 7;
        i++;
        p++;
    }
    for (i = 0; i < n - 1; i++)
        printf("%d ", ans[i]);
    printf("%d\n", ans[n - 1]);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cassert>
#include<map>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
const double infty = 1e40;
int path[30];

map<int,double> M[20];
double solve(int n,int now,int prev,const int *in){
  if (now < 0)return 0;
  map<int,double>::iterator itr = M[now].find(prev);
  if (now < n-2){
    if (itr != M[now].end()){
      return (*itr).second;
    }
  }
  double ret=1e20;
  if (now == n-1){
    for(int i=1;i<= 1000000;i++){
      double tmp = abs((double)i-in[now])/in[now];
      if (tmp < ret)ret=min(ret,max(tmp,solve(n,now-1,i,in)));
    }
  }else {
    for(int i=1;(ll)i*i<=prev;i++){
      if (prev%i != 0)continue;
      double tmp = abs((double)i-in[now])/(double)in[now];
      //if (now == 1 && prev == 12)cout <<i <<" " << tmp << endl;
      if (tmp < ret)ret=min(ret,max(tmp,solve(n,now-1,i,in)));
      //if (now == 0 && prev == 12)cout <<i <<" " << tmp << " " << ret << endl;
      if (prev/i != i){
	tmp=abs((double)prev/i-in[now])/(double)in[now];
	if (tmp < ret)ret=min(ret,max(tmp,solve(n,now-1,prev/i,in)));
	//if (now == 1 && prev == 12)cout <<prev/i <<" " << tmp << " " << ret << endl;
	//if (now == 0 && prev == 12)cout <<prev/i <<" " << tmp << " " << ret << endl;
      }
    }
  }
  //if (now == 1 && prev == 12)cout << ret <<" " << prev << endl;
  //if (now == 0 && prev == 12)cout << ret <<" " << prev << endl;
  if (now < n-2)return M[now][prev]=ret;
  else return ret;
  return M[now][prev]=ret;
}

main(){
  int n;
  while(cin>>n){
    int in[n];
    rep(i,n)cin>>in[i];
    rep(i,n)M[i].clear();
    sort(in,in+n);
    double ans=solve(n,n-1,-1,in);
    printf("%.12lf\n",ans);
#ifdef DEBUG
    cout << "end " << endl;
#endif
  }
  return false;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)

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

using namespace std;

int main(void){
	int n;
	while(cin>>n,n) {
		int res = 0;
		int lr[2]={0};
		int cur=0;
		while(n--) {
			string op; cin>>op;
			if(op[0]=='l') {
				lr[0] = (op[1]=='u')?1:0;
			}
			else {
				lr[1] = (op[1]=='u')?1:0;
			}
			if(lr[0]==lr[1] && cur!=lr[0]) res++;
			if(lr[0]==lr[1]) cur = lr[0];
		}
		cout << res << endl;
	}
        
	return 0;
}

Measured memory_bytes: 3104