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

using namespace std;

#define MAX 24

int N,x[MAX],y[MAX],r[MAX],c[MAX];

int dist(int a,int b){
    return (x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b]);
}

bool check(int a,int b){
    int d = dist(a,b);
    int add = r[a]+r[b],sub = r[a]-r[b];
    return ((sub*sub < d && d < add*add) || d <= sub*sub);
}

int main(){
    while(cin >> N, N){
        for(int i = 0 ; i < N ; i++){
            cin >> x[i] >> y[i] >> r[i] >> c[i];
        }
        int bit[MAX] = {0};
        for(int i = 0 ; i < N ; i++){
            for(int j = 0 ; j < i ; j++){
                if(check(i,j)) bit[i] |= (1<<j);
            }
        }
        vector<bool> dp(1<<N,0);
        dp[(1<<N)-1] = 1;
        int res = 0;
        for(int i = (1<<N)-1 ; i >= 0 ; i--){
            if(dp[i] == 0) continue;
            if(N%2 == 0 && __builtin_popcount(i) % 2 == 1) continue;
            if(N%2 == 1 && __builtin_popcount(i) % 2 == 0) continue;
            for(int j = 0 ; j < N ; j++){
                if((i&bit[j]) > 0) continue;
                for(int k = j+1 ; k < N ; k++){
                    if(c[j] != c[k]) continue;
                    if((i&bit[k]) > 0) continue;
                    int S = i & ~((1<<j) | (1<<k));
                    dp[S] = 1;
                    res = max(res,N-__builtin_popcount(i));
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> Pii;
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1000000000
#define rep(i,a,b) for(int i =(a);i<(b);i++)
#define fs first
#define ss second
inline int Scan() {
    int x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

template<typename T, typename U>
static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}

// call by reference is used in x
template<typename T, typename U>
static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
//////////////////////////////////////end of template//////////////////////////////////////

int main(){

  int a,b,c;
  cin >> a >> b >> c;
  
  if( a + b+ c >=22) cout <<"bust"<<endl;
  else cout <<"win"<<endl;  



}




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

typedef pair<int,int> P;
typedef vector<P> vec;
typedef vector<vec> mat;

int main() {
    int N, M;

    cin >> N >> M;

    mat v(N);
    vector<int> sum(N);

    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        v[a].push_back(P(b,c));
        sum[b]++;
    }

    queue<int> que;
    que.push(0);

    vector<int> cost(N);

    while (que.size()) {
        int now = que.front();
        que.pop();

        for (auto p : v[now]) {
            int next = p.first;
            int ncost = cost[now] + p.second;

            cost[next] = max(cost[next], ncost);

            sum[next]--;

            if (!sum[next]) {
                que.push(next);
            }
        }
    }

    cout << cost[N-1] << endl;

    return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i < n; i++)
#define INF 1001001001
#define LINF (1LL << 62)
using namespace std;
using ll = long long;
using P = pair<int,int>;

void solv() {
    int N, M;
    cin >> N >> M;
    cout << (N == M ? "Yes" : "No") << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    int n; cin>>n;
    OUT(n*n*n);
}


Measured memory_bytes: 256
#pragma GCC optimize "03"
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

signed main() {
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	IOS;
	int n;
	cin >> n;
	ld cur = 0;
	int v[55];
	for(int i = 1; i <= n; i++)
		cin >> v[i];
	sort(v + 1, v + n + 1);
	cur = v[1];
	for(int i = 2; i <= n; i++)
		cur = (cur + v[i])/2.0;
	cout << setprecision(6) << fixed << cur;
	return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
struct edge {
    int to;
    int idx;
};

signed main() {
    int N;
    cin >> N;
    vector<vector<edge>> table(N);

    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        table[a].push_back({b, i});
        table[b].push_back({a, i});
    }

    auto dfs = [&](auto f, int node, int par, int goal, vector<int> &edge_idxs) -> bool {
        if (node == goal) return true;

        bool flag = false;
        for (auto &edge : table[node]) {
            int next = edge.to;
            if (next == par) continue;
            flag |= f(f, next, node, goal, edge_idxs);
            if (flag) {
                edge_idxs.push_back(edge.idx);
                break;
            }
        }

        return flag;
    };

    vector<int> effects(N-1, 0);
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        vector<int> edges;
        assert(dfs(dfs, u, -1, v, edges));
        for (int idx : edges) {
            effects[idx] |= (1 << i);
        }
    }

    vector<vector<int>> dp(N, vector<int>(1 << M, 0));
    dp[0][0] = 1;

    for (int i = 0; i < N - 1; i++) {
        for (int mask = 0; mask < (1 << M); mask++) {
            dp[i+1][mask] += dp[i][mask];
            dp[i+1][mask | effects[i]] += dp[i][mask];
        }
    }

    cout << dp[N-1][(1 << M)-1] << endl;
    return 0;
}

Measured memory_bytes: 418304
def count(lb, rb):
    assert lb[0] == '1'
    assert rb[0] == '1'
    assert len(lb) == len(rb)
    dp = [1, 0, 0, 0]
    for lc, rc in zip(lb[1:], rb[1:]):
        ndp = [dp[0], 0, 0, 0]
        if rc == '0':
            ndp[1] += dp[1]
            if lc == '1':
                ndp[0] = 0
        else:
            ndp[1] += dp[1] * 2
            ndp[2] += dp[1]
            if lc == '0':
                ndp[1] += dp[0]
                ndp[3] += dp[0]
        if lc == '0':
            ndp[2] += dp[3]
            ndp[3] += dp[3] * 2
        else:
            ndp[3] += dp[3]
        ndp[2] += dp[2] * 3
        dp = ndp
    return sum(dp)


l, r = map(int, input().split())
lb = bin(l)[2:]
rb = bin(r)[2:]
ld = len(lb)
rd = len(rb)
ans = 0
MOD = 10 ** 9 + 7
for d in range(ld, rd + 1):
    tlb = lb if d == ld else '1' + '0' * (d - 1)
    trb = rb if d == rd else '1' * d
    ans = (ans + count(tlb, trb)) % MOD
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main(){
	int a, b, d, r;
	double f;
	scanf("%d %d\n", &a, &b);
	d = a / b;
	r = a % b;
	f = (double)a / b;
	printf("%d %d %.5lf\n", d, r, f);
	return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
int sx,sy,tx,ty;
char s1[1000000],s2[1000000];
int main()
{
	cin>>sx>>sy>>tx>>ty;
	int k=tx-sx;
	int l=ty-sy;
	if(k<0&&l<0)
	{
		k=-k;
		l=-l;
		for(int i=0;i<l;i++)
			printf("D");
		for(int i=0;i<k;i++)
			printf("L");
		for(int i=0;i<l;i++)
			printf("U");
		for(int i=0;i<k;i++)
			printf("R");
		printf("RD");
		for(int i=0;i<l;i++)
			printf("D");
		for(int i=0;i<k;i++)
			printf("L");
		printf("LU");
		printf("LU");
		for(int i=0;i<l;i++)
			printf("U");
		for(int i=0;i<k;i++)
			printf("R");
		printf("RD");
	}
	else if(k<0&&l>0)
	{
		k=-k;
		for(int i=0;i<l;i++)
			printf("U");
		for(int i=0;i<k;i++)
			printf("L");
		for(int i=0;i<l;i++)
			printf("D");
		for(int i=0;i<k;i++)
			printf("R");
		printf("RU");
		for(int i=0;i<l;i++)
			printf("U");
		for(int i=0;i<k;i++)
			printf("L");
		printf("LD");
		printf("LD");
		for(int i=0;i<l;i++)
			printf("D");
		for(int i=0;i<k;i++)
			printf("R");
		printf("RU");
	}
	else if(k>0&&l<0)
	{
		l=-l;
		for(int i=0;i<l;i++)
			printf("D");
		for(int i=0;i<k;i++)
			printf("R");
		for(int i=0;i<l;i++)
			printf("U");
		for(int i=0;i<k;i++)
			printf("L");
		printf("LD");
		for(int i=0;i<l;i++)
			printf("D");
		for(int i=0;i<k;i++)
			printf("R");
		printf("RU");
		printf("RU");
		for(int i=0;i<l;i++)
			printf("U");
		for(int i=0;i<k;i++)
			printf("L");
		printf("LD");
	}
	else
	{
		for(int i=0;i<l;i++)
			printf("U");
		for(int i=0;i<k;i++)
			printf("R");
		for(int i=0;i<l;i++)
			printf("D");
		for(int i=0;i<k;i++)
			printf("L");
		printf("LU");
		for(int i=0;i<l;i++)
			printf("U");
		for(int i=0;i<k;i++)
			printf("R");
		printf("RD");
		printf("RD");
		for(int i=0;i<l;i++)
			printf("D");
		for(int i=0;i<k;i++)
			printf("L");
		printf("LU");
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(L):

    e = []
    n = 1
    l = L - 1

    r = math.floor(math.log(L, 2))
    for j in range(r):
        e.append((n, n+1, 0))
        e.append((n, n+1, 2**j))
        n += 1

    for t in range(n-1, 0, -1):
        if L - 2**(t-1) >= 2**r:
            e.append((t, n, L - 2**(t-1)))
            L -= 2**(t-1)

    print(n, len(e))
    for u, v, c in e:
        print(u, v, c)


def main():
    L = read_int()
    slv(L)


if __name__ == '__main__':
    main()


Measured memory_bytes: 59756
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;

// keyence-string.rs --- KEYENCE String
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        cs: chars,
    };

    let ans = cs.starts_with(&['k', 'e', 'y', 'e', 'n', 'c', 'e'])
        || (cs.starts_with(&['k', 'e', 'y', 'e', 'n', 'c']) && cs.ends_with(&['e']))
        || (cs.starts_with(&['k', 'e', 'y', 'e', 'n']) && cs.ends_with(&['c', 'e']))
        || (cs.starts_with(&['k', 'e', 'y', 'e']) && cs.ends_with(&['n', 'c', 'e']))
        || (cs.starts_with(&['k', 'e', 'y']) && cs.ends_with(&['e', 'n', 'c', 'e']))
        || (cs.starts_with(&['k', 'e']) && cs.ends_with(&['y', 'e', 'n', 'c', 'e']))
        || (cs.starts_with(&['k']) && cs.ends_with(&['e', 'y', 'e', 'n', 'c', 'e']))
        || cs.ends_with(&['k', 'e', 'y', 'e', 'n', 'c', 'e']);
    println!("{}", if ans { "YES" } else { "NO" });
}


Measured memory_bytes: 4352
#include <stdio.h>

int main (void) {
  int n, i, tmp, ans = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &tmp);
    if ((i+1)%2 == 1 && tmp%2 == 1) ans++;
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 1732
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int x, y, a, b, c;
    std::cin >> x >> y >> a >> b >> c;
    std::vector<int> p(a), q(b), r(c);
    rep(i, a) std::cin >> p[i];
    rep(i, b) std::cin >> q[i];
    rep(i, c) std::cin >> r[i];
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    sort(r.begin(), r.end());
    int ok = -1, ng = 1e9 + 1;
    // いくら以上のものをとることにすれば赤からX個，緑からY個を達成できるか
    // 達成できるための条件はaとcからx個以上，bとcからy個以上，合計でx+y個以上
    while(std::abs(ng - ok) > 1) {
        int mid = ok + (ng - ok) / 2;
        int cnt_a = p.end() - std::lower_bound(p.begin(), p.end(), mid);
        int cnt_b = q.end() - std::lower_bound(q.begin(), q.end(), mid);
        int cnt_c = r.end() - std::lower_bound(r.begin(), r.end(), mid);
        // std::cout << mid << " " << cnt_a << " " << cnt_b << " " << cnt_c << std::endl;
        if(cnt_a + cnt_c >= x and cnt_b + cnt_c >= y and cnt_a + cnt_b + cnt_c >= x + y) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    // std::cout << ok << " " << ng << std::endl;
    int cnt_a = p.end() - std::lower_bound(p.begin(), p.end(), ng);
    int cnt_b = q.end() - std::lower_bound(q.begin(), q.end(), ng);
    int cnt_c = r.end() - std::lower_bound(r.begin(), r.end(), ng);
    int ans_a = std::min(cnt_a, x);
    int ans_b = std::min(cnt_b, y);
    int ans_c = std::min(cnt_c, x + y - ans_a - ans_b);
    // std::cout << ans_a << " " << ans_b << " " << ans_c << std::endl;
    std::cout << std::accumulate(p.begin() + (a - ans_a), p.end(), 0LL) + std::accumulate(q.begin() + (b - ans_b), q.end(), 0LL) + std::accumulate(r.begin() + (c - ans_c), r.end(), 0LL) + ok * (x + y - ans_a - ans_b - ans_c) << std::endl;
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 1408
N,M=map(int,input().split())
br=set([int(input()) for _ in range(M)])
dp=[0]*(N+1)
dp[0]=1
if not 1 in br:
    dp[1]=1

for i in range(2,N+1):
    if not i in br:
        dp[i]+=(dp[i-1]+dp[i-2])%1000000007
print(dp[-1])

Measured memory_bytes: 19000
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h1 = sc.nextInt();
        int w1 = sc.nextInt();
        int h2 = sc.nextInt();
        int w2 = sc.nextInt();
        sc.close();

        int ans = h1 * w1 - h2 * w1 - (h1 - h2) * w2;
        System.out.println(ans);
    }

}


Measured memory_bytes: 23764
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val task = (1..n).map { readLine()!!.split(" ").map { it.toInt() } }.sortedBy { it[1] }

    val time = task.map { it[0] }.summed()
    val deadLine = task.map { it[1] }

    if(task.indices.all { time[it] <= deadLine[it] })
        println("Yes")
    else
        println("No")
}

fun List<Int>.summed(): List<Long> { var sum = 0L; return this.map { sum += it; sum } }


Measured memory_bytes: 131612
#include <stdio.h>

typedef long long ll;

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

int main() {
  ll n;
  scanf("%lld", &n);

  ll ans = n;
  for (ll i = 1; i*i <= n; i++) {
    if (n % i == 0) {
      ans = min(ans, i + n/i - 2);
    }
  }
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 128
import sys
def f(x):
    N = 1000
    for a in range(-N, N+1):
        A = a**5
        B = A-x
        for j in range(-N, N+1):
            if j ** 5 == B:
                print(a, j)
                return 
x, = map(int, input().split())
f(x)


Measured memory_bytes: 64512
#include <bits/stdc++.h>
using namespace std;
int main() {
  string str, ans;
  char a,b;
  int N,i=0, t=1;
  cin >> str;
  N = str.size();
  ans = "yes";
  
  if(str.at(0)=='L'){
    ans = "no";
  }
  
  while(N >= 2*i+1){
    if(str.at(2*i) == 'L' ){
      ans = "no";
    }
    i++;
  }
  
  while(N >= 2*t){
    if(str.at(2*t-1) == 'R' ){
      ans = "no";
    }
    t++;
  }
  
  if(ans == "yes"){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define fors(i,a,b) for(int i=(a);i<=(b);++i)
#define ford(i,a,b) for(int i=(a);i>=(b);--i)
#define min(x,y) ((x) < (y) ? (x) : (y))
#define max(x,y) ((x) < (y) ? (y) : (x))
#define swap(x,y) ((x)^=(y),(y)^=(x),(x)^=(y))
#define abs(x) ((x) < 0 ? -(x) : (x)) 
const int maxn=1e6+7;
typedef long long ll;
const int inf=1<<25;
int read(){
    int s=0,f=1;
    char c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1; c=getchar();}
    while(c>='0' && c<='9') {s=s*10+c-48;c=getchar();}
    return s*f;
}
void write(int x){
    if(x<0) {putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(x%10+48);
}
int t[101010];
long long d[101010];
int siz[101010],fa[101010];
bool cmp(const int &x,const int &y)
{
    return d[x]<d[y];
}
map<long long,int> mp;
int main()
{
    int n;
    scanf("%d",&n);
    mp.clear();
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&d[i]);
        siz[i]=1;
        mp[d[i]]=i;
        t[i]=i;
    }
    sort(t+1,t+n+1,cmp);
    for(int i=n;i>1;i--)
    {
        fa[t[i]]=mp[d[t[i]]+2*siz[t[i]]-n];
        if(fa[t[i]]==0)
        {
            printf("-1");
            return 0;
        }
        siz[fa[t[i]]]+=siz[t[i]];
    }
    for(int i=2;i<=n;i++)
        d[t[1]]-=siz[t[i]];
    if(d[t[1]]!=0)
    {
        printf("-1");
        return 0;
    }
    for(int i=2;i<=n;i++)
        printf("%d %d\n",fa[t[i]],t[i]);
    return 0;
}

Measured memory_bytes: 9600
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

require 'bigdecimal'

W, H, x, y = get_ints

half = (W * H) / BigDecimal(2)

multi = (x * 2 == W && y * 2 == H) ? 1 : 0

puts "#{half.to_f} #{multi}"


Measured memory_bytes: 14636
#include<iostream>
#include<cstdio>
using namespace std;
int com(int t,int x,int y)
{
	if(x+y==t)
	return 1;
	if(x+y>t)
	return 0;
	if((t-x-y)%2==0&&x+y<t)
	return 1;
	if((t-x-y)%2==1&&x+y<t)
	return 0;
}
int main()
{
	int n,t,x,y,flag=0;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d%d",&t,&x,&y);
		if(com(t,x,y)==0)
		flag=1;
	}
	if(flag==0)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}

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

int main() {
    int n,k; cin >> n >> k;
    int tall[100010];
    int m=1999999999;
    rep(i,n){
        cin >> tall[i];
    }
    sort(tall,tall+n);
    rep(i,n-k+1){
        m=min(m,tall[i+k-1]-tall[i]);
    }
    cout << m << endl;

    return 0;
}

Measured memory_bytes: 640
x, k, d = map(int, input().split())
if abs(k * d) > abs(x):
    pos = abs(x) % d
    left_turn = k - abs(x) // d
    if left_turn % 2 == 1:
        ans = d - pos
    else:
        ans = pos
else:
    ans = abs(x) - abs(k * d)
print(ans)

Measured memory_bytes: 9192
from collections import deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
#kを法とする配列を作る
a = [(i - 1) for i in a]
acc_a = [0 for i in range(n+1)]
acc_a[0] = 0
acc_a[1] = a[0] % k
#kを法とする累積和
for i in range(2,len(a) + 1):
    acc_a[i] = (a[i - 1] + acc_a[i-1]) % k
ans = 0
count = {}
q = deque()
for i in acc_a:
    if i not in count:
        count[i] = 0
    ans += count[i]
    count[i] += 1
    q.append(i)
    if len(q) == k:
        count[q.popleft()] -= 1
print(ans)


Measured memory_bytes: 113692
#cording by utf-8

n = int(input())
#maxv ?????§???
#minv ????°????
minv = int(input()) #?????????????°????
#print("minv",minv)
maxp = int(input()) #??????????????§???
maxp = maxp - minv
if maxp + minv < minv:
    minv = maxp + minv
for i in range(2,n):
    stock = int(input())
    if minv > stock:
        minv = stock
        #print("minv",minv)
    else:
        profit = stock - minv
        if profit > maxp:
            maxp = profit
            #print("maxp",maxp)

print(maxp)

Measured memory_bytes: 7668
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fr(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front


int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
	int n,d;
	cin>>n>>d;
	int x=2*d +1;
	int q=n/x;
	int r=n-q*x;
	if(r==0){
		cout<<q;
	}

	else{
		cout<<q+1;
	}

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
string MAP[100];
int H,W,ans;
int dx[4]={1,0,-1,0};
bool dfs(int x,int y,char t){
	if(t==0||MAP[x][y]!=t)return false;
	if(MAP[x][y]==t)MAP[x][y]=0;
	for(int k=0;k<4;k++){
		int nx=x+dx[k],ny=y+dx[k^1];
		if(nx>=0&&nx<H&&ny>=0&&ny<W)dfs(nx,ny,t);
	}
	return true;
}
int main() {
	while(cin>>H>>W,H){
		for(int i=0;i<H;i++)cin>>MAP[i];
		ans=0;
		for(int i=0;i<H;i++)for(int j=0;j<W;j++){
			if(dfs(i,j,MAP[i][j]))ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main() {
	int s=0;
	char c;
	int count=0;
	int del = 0;
	while(scanf("%c",&c) > 0){
		if(c=='\n') break;
		if(c=='S'){
			s++;
		}
		if(c=='T'){
			if(s>0){
				del++;
				s--;
			}else{
				s=0;
			}
		}
		//printf("%d\n",s);
		count++;
	}
	printf("%d\n",count-del*2);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[m];
		int[] d = new int[m];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
			b[i] = Integer.parseInt(sc.next());
		}
		for (int i = 0; i < m; i++) {
			c[i] = Integer.parseInt(sc.next());
			d[i] = Integer.parseInt(sc.next());
		}

		for (int i = 0; i < n; i++) {
			int ans = Integer.MAX_VALUE;
			int tmp = 0;
			int sum = Integer.MAX_VALUE;
			for (int j = 0; j < m; j++) {
				tmp = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
				if (sum > tmp) {
					sum = tmp;
					ans = j + 1;
				}
			}
			System.out.println(ans);
		}
		sc.close();
	}
}

Measured memory_bytes: 23764
n, k = map(int, input().split())

x = n
if n < k:
    a = abs(x - k)
    b = abs(a - k)
    print(min(a, b))
elif n == k:
    print(0)
else:
    x = n % k
    if x == 0:
        print(0)
    else:
        t = x - k
        print(abs(t))

Measured memory_bytes: 3064
import java.util.Scanner

object Main {


  case class GF(representative: Long) extends AnyVal {
    def +(that: GF): GF = GF((this.representative + that.representative) % GF.mod)

    def -(that: GF): GF = GF((this.representative - that.representative + GF.mod) % GF.mod)

    def *(that: GF): GF = GF((this.representative * that.representative) % GF.mod)

    def /(that: GF): GF = this * that.inv

    def unary_- : GF = GF((-this.representative + GF.mod) % GF.mod)

    def inv: GF = GF.powGF(this, GF.mod - 2)
  }


  object GF {
    val mod: Long = (1e9 + 7).toLong

    val _0: GF = GF(0)
    val _1: GF = GF(1)

    def powGF(x: GF, t: Long): GF = {
      if (t == 0) {
        return GF(1)
      }
      val y = powGF(x, t / 2)
      if (t % 2 == 0) {
        y * y
      } else {
        x * y * y
      }
    }
  }


  def read() = {
    val sc = new Scanner(System.in)
    val n, m, k = sc.nextInt()
    (n, m, k)
  }

  def fracGF(n: Int): GF = (1 to n).map(GF(_)).foldLeft(GF(1))(_ * _)

  def combGF(n: Int, r: Int): GF = fracGF(n) / (fracGF(r) * fracGF(n - r))

  def solve2(h: Int, w: Int, k: Int): Long = {
    // 1 + 2 + ... + tを求める
    def sum(t: Long) = t * (t + 1) / 2

    def sumDist(x: Long, y: Long): GF = {
      // 0-origin
      // xより左側: [0,x) (xマス)
      // xより右側: [x+1,w) (w-x-1マス)
      // yより上側: [0,y) (yマス)
      // yより下側: [y+1, h) (h-y-1マス)
      GF(sum(x) + sum(w - x - 1)) * GF(h) + GF(sum(y) + sum(h - y - 1)) * GF(w)
    }

    val nComb = combGF(w * h - 2, k - 2)
    val distAll = (for (y <- 0 until h; x <- 0 until w) yield sumDist(x, y) / GF(2)).foldLeft(GF(0))(_ + _)
    val result = nComb * distAll
    result.representative
  }

  def main(args: Array[String]): Unit = {
    val (n, m, k) = read()
    println(solve2(n, m, k))
  }
}

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

int main()
{
    int n;
    scanf("%d",&n);
    vector <int> p(n);
    for(int&i : p)
        scanf("%d",&i) ,i--;

    vector <int> a(n) ,b(n);
    for(int i=0; i<n; i++)
        a[i] = n*i+1;
    for(int i=0; i<n; i++)
        b[p[i]] = n*n-a[p[i]]+i;

    for(int&i:a) printf("%d ",i); printf("\n");
    for(int&i:b) printf("%d ",i); printf("\n");
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n; cin>>n;
	vector<ll> arr(n);
	bool ok=1;
	for(auto i=0;i<n;++i){
		cin>>arr[i];
		if(arr[i]%2==0){
			if(arr[i]%3!=0 && arr[i]%5!=0)ok=0;
		}
	}
	if(ok)cout<<"APPROVED\n";
	else
		cout<<"DENIED\n";
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

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

int main(){
  int n;
  cin >> n;
  int a[210];
  int counter = 0;
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }

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

  cout << counter << endl;
}


Measured memory_bytes: 3528
/**

    ___         ___           ____        __      __        ____         ___        _    _     ____
   / __ \      / __ \        / __ \       \ \    / /       / __ \       |  _ \     | |  | |  _/  _/
  | |  \ \    / /  | |      / /  \ \       \ \  / /       / /  \ \      | | \ \    | |  | |_/  _/
  | |   \ \  / /   | |     / /____\ \       \ \/ /       / /____\ \     | |  \ \   | |  |    _/
  | |    \ \/ /    | |    / /______\ \       \  /       / /______\ \    | |   \ \  | |  |  _ \__
  | |     \__/     | |   / /        \ \       | |      / /        \ \   | |    \ \_| |  | | \__ \__
  |_|              |_|  /_/          \_\  .   |_|     /_/          \_\  |_|     \ ___|  |_|    \___\


   ________         ____         _________   ___________    __________      ___________     _________ 
  |  ____  \       / __ \       | _______/  |____  _____|  /  ______  \    / _________/    |___   ___|     
  | |____|  \     / /  \ \      | |______        | |      /  /       \ \   | /                 | |
  |    ____ /    / /____\ \     |______  |       | |     /  /         \ \  | |  _________      | |
  | |\_\        / /______\ \           | |       | |     \  \         / /  | | |_______  |     | |
  | |  \_\     / /        \ \   _______| |       | |      \  \_______/ /   | |_________| |  ___| |___
  |_|    \_\  /_/          \_\  \________|       |_|       \__________/    \_____________| |_________|


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


int n,m;
bool a[100010];
int pen[100010];
int main(){
	cin>>n>>m;
	int pe =0 ;
	int ac =0;
	for(int i=0;i<m;++i){
		int val;
		cin>>val;
		string s;
		cin>>s;
		if(!a[val] && s=="WA"){
			pen[val]++;
		}
		if(!a[val] && s=="AC"){
			a[val] = true;
			ac++;
		}
	}
	for(int i=1;i<=n;++i){
		if(a[i]){
			pe+=pen[i];
		}
	}
	cout<<ac<< ' ' << pe<<'\n';
	return 0;
}

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

int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	if((a[0]==a[1] and a[0]!=a[2]) or (a[1]==a[2] and a[0]!=a[2])){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            if (s.Length == 2)
            {
                if (s[0] == s[1])
                    Console.WriteLine("1 2");
                else
                    Console.WriteLine("-1 -1");

                return;
            }

            for (var i = 2; i < s.Length; i++)
            {
                var set = new HashSet<int>();
                set.Add(s[i - 2]);
                set.Add(s[i - 1]);
                set.Add(s[i]);
                if (set.Count < 3)
                {
                    Console.WriteLine($"{i-1} {i+1}");
                    return;
                }
            }

            Console.WriteLine("-1 -1");
        }
    }
}


Measured memory_bytes: 17760
#include<cstdio>
const int MAXN=20005,MAXV=30001;

int ans[MAXN];
bool used[MAXV];
int gcd(int a,int b)
{return b==0?a:gcd(b,a%b);}

int main()
{
    int n,sum=0,i,j;
    scanf("%d",&n);
    for(i=1,j=1;j<n;i++)//添加n-1个2、3的倍数
        if(i%2==0||i%3==0)
        {
            ans[j++]=i;
            used[i]=true;
            sum+=i;
        }
    int r2=sum%2,r3=sum%3;
    for(i=1;j<=n;i++)//枚举最后一个数
        if(!used[i]&&(i+r2)%2==0&&(i+r3)%3==0&&gcd(i,sum)!=1)
            ans[j++]=i;
    for(int i=1;i<n;i++)
        printf("%d ",ans[i]);
    printf("%d\n",ans[n]);

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,q;
int c[100001],v,d;
vector<int>e[100001];
int dp[100001][11];
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=1; i<=m ;i++){
		cin >> v >> d;
		e[v].push_back(d);
		e[d].push_back(v);
	}
	cin >> q;
	for(int i=1; i<=q ;i++){
		cin >> v >> d >> c[i];
		dp[v][d]=i;
	}
	for(int i=9; i>=0 ;i--){
		for(int j=1; j<=n ;j++){
			dp[j][i]=max(dp[j][i],dp[j][i+1]);
			for(int k=0; k<e[j].size() ;k++){
				dp[j][i]=max(dp[j][i],dp[e[j][k]][i+1]);
			}
		}
	}
	for(int i=1; i<=n ;i++){
		cout << c[dp[i][0]] << '\n';
	}
}

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


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n,m; cin >> n >> m;
    vector<int> k(m),p(m);
    vector<vector<int> > s(m,vector<int>(0));

    for(int i = 0;i < m;i ++){
        cin >> k.at(i);
        for(int j = 0;j < k.at(i);j ++){
            s.at(i).push_back(0);
            cin >> s.at(i).at(j);
            s.at(i).at(j) --;
        }
    }
    for(int i = 0;i < m;i ++){
        cin >> p.at(i);
    }

    int ans = 0;

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

        bool hantei = true;

        for(int j = 0;j < m;j ++){
            int count = 0;
            for(int k = 0;k < s.at(j).size();k ++){
                if(i & (1 << s.at(j).at(k))) count ++;
            }

            if(count % 2 != p.at(j)) hantei = false;
        }

        if(hantei == true) ans ++;
    }

    cout << ans << endl;


}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	int a[M], b[M];
	for(int i = 0; i < M; i++){
		cin >> a[i] >> b[i];
	}

	int count[N] = {0};
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			if((i + 1) == a[j]){
				count[i]++;
			}
			if((i + 1) == b[j]){
				count[i]++;
			}
		}
	}

	for(int i = 0; i < N; i++){
		cout << count[i] << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint n;
llint a[5];

void solve(){
	cin >> n;
	for(int i=0;i<5;i++)cin >> a[i];
	llint mn=inf;
	for(int i=0;i<5;i++)chmin(mn,a[i]);
	llint ans;
	if(n%mn==0)ans=5+n/mn;
	else ans=6+n/mn;
	cout << ans-1 << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] c1 = sc.next().toCharArray();
        char[] c2 = sc.next().toCharArray();
        int num1 = c1.length;
        int num2 = c2.length;
        int count = 0;
        
        for(int i=0; i<(num1-num2+1); i++){
          int cc = 0;
          for(int j=0; j<c2.length; j++){
              if(c1[i+j]==c2[j]){
                  cc++;
              }
          }
          if(count<cc){
              count = cc;
              //System.out.println("i "+ i);
              //System.out.println("cc "+ cc);
              
          }
        }

        System.out.println(num2-count);
        
    }
}

Measured memory_bytes: 35548
n = int(input())
cnt = {c:50 for c in "abcdefghijklmnopqrstuvwxyz"}
for _ in [0]*n:
    cnt2 = {c:0 for c in "abcdefghijklmnopqrstuvwxyz"}
    S = input()
    for s in S:
        cnt2[s] += 1
    for c in cnt.keys():
        cnt[c] = min(cnt[c],cnt2[c])
ans = ""
for c,i in sorted(cnt.items()):
    ans += c*i
print(ans)

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

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

Measured memory_bytes: 256
/*Rabbi Zidni Ilma*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define mod 1000000007
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)

ll L[3005][3005];

int main()
{
	ll l1,l2,i,j;
    string s,t;
    cin >> s >> t;
    l1=s.size();
    l2=t.size();
    for(i=0;i<=l1;i++)
    {
    	for(j=0;j<=l2;j++)
    	{
    		if(i==0||j==0)
    		L[i][j]=0;
    		else if(s[i-1]==t[j-1])
    		L[i][j]=1+L[i-1][j-1];
    		else
    		L[i][j]=max(L[i-1][j],L[i][j-1]);
		}
	}
	
	string ans;
	i=l1,j=l2;
	while(i>0&&j>0)
	{
		if(s[i-1]==t[j-1])
		{
			ans.pb(s[i-1]);
			i--;
			j--;
		}
		else if(L[i-1][j]>L[i][j-1])
		i--;
		else 
		j--;
	}
	reverse(ans.begin(),ans.end());
	cout << ans <<"\n";
}





Measured memory_bytes: 74092
using System;
class icpc_1633{
  public static void Main(){
    const int MAX_ASCII = 127;
    Pos cur = new Pos();
    Pos next = new Pos();
    Calc c = new Calc();
    while(true){
      int count = 0;
      c.init(cur);
      c.init(next);
      String[] str = Console.ReadLine().Split(' ');
      int h = int.Parse(str[0]);
      int w = int.Parse(str[1]);
      if(h ==0 && w == 0)
        break;
      String[] display = new String[h];
      for(int i=0; i<h; i++){
        display[i] = Console.ReadLine();
      }
      String input = Console.ReadLine();
      bool[] isal = new bool[MAX_ASCII];
      Pos[] ispos = new Pos[MAX_ASCII];
      for(int i=0; i<MAX_ASCII; i++){
        isal[i] = false;
      }
      foreach(char ch in input){
        if(isal[(int)ch]){
          count += Math.Abs(cur.H - ispos[(int)ch].H);
          count += Math.Abs(cur.W - ispos[(int)ch].W);
          count++;
          cur = ispos[(int)ch];
        }
        else{
          next = c.search(ch, display, w,h);
          isal[(int)ch] = true;
          ispos[(int)ch] = next;
          count += Math.Abs(cur.H - next.H);
          count += Math.Abs(cur.W - next.W);
          count++;
          cur = next;
        }
        //c.printpos(ch,cur);
        //Console.WriteLine("Count is {0}",count);
        //Console.WriteLine("----------");
      }
      Console.WriteLine(count);
    }
  }
}

class Calc{
  public Pos search(char c, String[] sr, int w, int h){
    Pos ret = new Pos();
    bool flag = true;
    for(int i=0; i<h && flag; i++){
      String s = sr[i];
      for(int j=0; j<w && flag; j++){
        if(s[j] == c){
          ret.H = i;
          ret.W = j;
          flag = false;
        }
      }
    }
    return ret;
  }
  public void printpos(char c, Pos p){
    Console.WriteLine("{0} is [{1}, {2}]",c,p.H,p.W);
  }
  public void init(Pos p){
    p.H = 0;
    p.W = 0;
  }
}

class Pos{
  int h,w;
  public Pos(){
    h = 0;
    w = 0;
  }
  public int H{
    set{ h=value; }
    get{ return h; }
  }
  public int W{
    set{ w=value; }
    get{ return w; }
  }
}



Measured memory_bytes: 15948
use proconio::fastout;
use proconio::input;
use proconio::marker::Chars;

#[fastout]
fn main() {
    input! {
        _: usize,
        ss: Chars,
    }
    let mut ans = 0;
    for i in 0..1000 {
        let num: Vec<char> = format!("{:>03}", i).chars().collect();
        let mut index = 0;
        for &s in &ss {
            if s == num[index] {
                index += 1;
            }
            if index == 3 {
                ans += 1;
                break;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2320
#include <bits/stdc++.h>
using namespace std;
#define data_type long long
#define endl "\n"
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    data_type n,a,b,temp;

    string str,str1;
    cin>>str>>str1;
    int i;


    for( i=0; str[i]; i++)
        {
            if(str1[i]==str[i])
                continue;
            else
                break;
        }

    cout<<(i==str.size()?"Yes":"No")<<endl;



    return 0;
}


Measured memory_bytes: 3652
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(n: i32,);

    match n % 10 {
        2 | 4 | 5 | 7 | 9 => println!("hon"),
        0 | 1 | 6 | 8 => println!("pon"),
        3 => println!("bon"),
        _ => {},
    }
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define MAX 200009
#define PI 3.141592653589793238
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in2.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tp, T)
	{
		//cout << "Case #" << tp << ": ";
		int x; cin >> x;
		int curr = 100;
		for(int i = 1; i <= 4000; i++){
			curr = curr + 0.01*curr;
			if(curr >= x){
				cout << i;
				break;
			}
		}
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> vec(n);
    for (int i = 0; i < n; i++)
    {
        cin>>vec.at(i);
    }
    
    for (int i = k; i < n; i++)
    {
        if (vec.at(i)>vec.at(i-k))
        {
            cout<<"Yes"<<endl;
        }else
        {
            cout<<"No"<<endl;
        }
        
        
    }
    
    

    
    

    return 0;
}

Measured memory_bytes: 3980
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, A, B = read_ints()
sa = abs(A - B)
if sa % 2 == 0:
    print(sa // 2)
    exit()

to_haji = min(A - 1, N - B)
ans1 = to_haji + sa

# 一回端でとどまったほうが早い場合
ans2 = to_haji + 1 + (sa - 1) // 2
print(min(ans1, ans2))


Measured memory_bytes: 3064