akhauriyash/Code-Regression huggingface dataset:
/// input macro from https://qiita.com/tanakh/items/1ba42c7ca36cd29d0ac8
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 , 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" ) } ; }
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 ) * } } ; }
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 ) * } } ; }

fn solve() {
    input!(s: chars, t: chars);

    let mut diff = 0;
    for i in 0..(s.len() - t.len() + 1) {
        let mut tmp = 0;
        for j in 0..t.len() {
            if s[i + j] == t[j] {
                tmp += 1;
            }
        }

        if tmp > diff {
            diff = tmp;
        }
    }

    println!("{}", t.len() - diff);
}

fn main() {
    std::thread::Builder::new()
        .name("solve".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto G = new Tuple!(int, int)[][](N);
    auto uf = new UnionFind(N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, s[2] & 1);
        G[s[1]-1] ~= tuple(s[0]-1, s[2] & 1);
        uf.unite(s[0]-1, s[1]-1);
    }

    uf.table.map!(u => u < 0).sum.writeln;
}


class UnionFind {
    int N;
    int[] table;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
    }
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s.substr(i,1)=="7"){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main(){
    int n ,a[1001]={}, i, j, tmp, k;
    scanf("%d", &n);
    for( i = 0; i < n ; i++){
        scanf("%d", &a[i]);
        if( i == n -1 ){
        printf("%d", a[i]);
        }else printf("%d ", a[i]);
    }
    printf("\n");
    for( i = 1; i < n; i++ ){
        tmp = a[i];
        j = i - 1;
        while( j >= 0 && a[j] > tmp ){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = tmp;
        for( k = 0; k < n; k++ ){
            if( k == n-1 ){
                printf("%d", a[k]);
            }else{
                printf("%d ", a[k]);
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 608
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	n := oneInt()

	fmt.Println((n - 2) * 180)
}

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

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

func scanNums(len int) (nums []int) {
	for i := 0; i < len; i++ {
		nums = append(nums, oneInt())
	}
	return nums
}

func scanStrings(len int) (strs []string) {
	for i := 0; i < len; i++ {
		strs = append(strs, oneStr())
	}
	return strs
}

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

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func cumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define N             (int)(1e6+5)
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int c[100005],c1[100005];
int solve(){
    cin>>n>>m;
    int s1=0,s2=0;
    rep(i,1,m){
        int t; cin>>t>>str;
        if(c[t]) ;
        else if(str=="AC"){
            c[t]=1;
            s1++;
        }
        else{
            c1[t]++;
        }
    }
    rep(i,1,100000){
        if(c[i]){
            s2+=c1[i];
        }
    }
    cout<<s1<<" "<<s2;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}


Measured memory_bytes: 1792
X = int(input())
happiness = 0
while X > 0:
    if X >= 500:
        temp = int(X / 500)
        X = X - (500 * temp)
        happiness = 1000 * temp
    else:
        temp = int(X / 5)
        X = X - (500 * temp)
        happiness = happiness + (5 * temp)
        break
print(happiness)

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

int main()
{
	long long n,m;
	cin>>n>>m;
	vector<pair<long long,long long>>take;
	long long a[n];
	long long sm=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sm+=a[i];
	}
	long long l,g;
	
	for(int i=0;i<m;i++)
	{
		cin>>l>>g;
		take.push_back(make_pair(g,l));
		
	}
	sort(take.rbegin(),take.rend());
	sort(a,a+n);
	long long k=0;
	//for(auto x: take){cout<<x.first;}
	int allowed=1;
	int quer=0;
	for(int i=0;i<n;i++)
	{
		if(quer>m)
		{
			break;
		}
		if(a[i]<take[k].first&&allowed<=take[k].second)
		{
			sm-=a[i];
			sm+=take[k].first;
			allowed++;
		}
		else
		{
		  
		   k++;
		   i--;
		   allowed=1;
		   quer++;
		}
		
		
	}		
	cout<<sm;
}



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

using namespace std;

long long func (long long x) {
    long long cnt1 = (x + 1) / 2;
    long long ans = cnt1 % 2;
    if ( x % 2 == 0 )
        ans ^= x;
    return ans;
}

int main (void) {
    long long A, B;
    cin >> A >> B;
    long long ans = func(A-1) ^ func(B);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	#define MAX 100000
	bool sosu[MAX];
	memset(sosu,1,MAX);
	for(int i=4;i<MAX;i+=2)sosu[i]=false;
	for(int i=3;i<MAX;i+=2)if(sosu[i])
		for(int j=i*3;j<MAX;j+=2*i)sosu[j]=false;
	
	int n;
	while(cin>>n,n){
		int co=0;
		loop(i,2,n/2+1)if(sosu[i]&&sosu[n-i])co++;
		cout<<co<<endl;
	}
}

Measured memory_bytes: 1264
#include<stdio.h>
#include<stdlib.h>

struct edge {
  int a;
  int b;
  int weight;
};
int *ufp, *ufr;
struct edge *ed;

void qsort1(int, int);
int UF_find(int);
void UF_union(int, int);
int Kruskal(int, int);

int main(void)
{
  int i, j, v, e, s, t, w, cost;
  scanf("%d %d", &v, &e);
  ufp = (int*)malloc(sizeof(int) * v);
  ufr = (int*)malloc(sizeof(int) * v);
  ed = (struct edge*)malloc(sizeof(struct edge) * e);
  for (i = 0; i < v; i++) {
    ufp[i] = i;
    ufr[i] = 0;
  }
  for (i = 0; i < e; i++) {
    scanf("%d %d %d", &s, &t, &w);
    ed[i].weight = w;
    ed[i].a = s;
    ed[i].b = t;
  }
  cost = Kruskal(v, e);
  printf("%d\n", cost);
  free(ufp);
  free(ufr);
  free(ed);
}

void qsort1(int left, int right)
{
  int pivot = ed[(left + right) / 2].weight, i = left, j = right;
  if (i >= j) return;
  do {
    while (ed[i].weight < pivot) i++;
    while (ed[j].weight > pivot) j--;
    if (i <= j) {
      struct edge temp = ed[i];
      ed[i] = ed[j];
      ed[j] = temp;
      i++;
      j--;
    }
  } while (i <= j);
  qsort1(left, j);
  qsort1(i, right);
}

int UF_find(int a)
{
  if (ufp[a] == a) return a;
  else {
    ufp[a] = UF_find(ufp[a]);
    return ufp[a];
  }
}

void UF_union(int a, int b)
{
  if (ufr[a] < ufr[b]) ufp[a] = b;
  else {
    ufp[b] = a;
    if (ufr[a] == ufr[b]) ufr[a]++;
  }
}

int Kruskal(int size, int esize)
{
  int i, cost = 0;
  qsort1(0, esize - 1);
  for (i = 0; i < esize; i++) {
    int ea = UF_find(ed[i].a), eb = UF_find(ed[i].b);
    if (ea != eb) {
      UF_union(ea, eb);
      cost += ed[i].weight;
    }

  }
  return cost;
}


Measured memory_bytes: 2984
from collections import deque
#
# H, W, = 4, 4
# CH, CW = 1, 1
# DH, DW = 4, 4
#
# ARR = [
#     "..#.",
#     "..#.",
#     ".#..",
#     ".#.."
# ]
#
#
#
# H,W = 4, 4
# CH, CW = 1, 4
# DH, DW = 4, 1
# ARR = [
#     ".##.",
#     "####",
#     "####",
#     ".##."
# ]
#
#
#
# H,W = 4, 4
# CH,CW = 2, 2
# DH,DW = 3, 3
# ARR = [
#     "....",
#     "....",
#     "....",
#     "...."
# ]
#
#
# H,W = 4, 5
# CH,CW = 1, 2
# DH,DW = 2, 5
#
# ARR = [
#     "#.###",
#     "####.",
#     "#..##",
#     "#..##"
# ]
#
#

H,W = map(int,input().split())
CH,CW = map(int,input().split())
DH,DW = map(int,input().split())
ARR = []

for i in range(H):
    ARR.append(input())




def calculate(h, w, ch, cw, dh, dw, arr):

    status = [[-1 for j in range(w)] for i in range(h)]

    q = deque()

    q.append((ch - 1, cw - 1))
    status[ch - 1][cw - 1] = 0

    while len(q) > 0:
        currentY, currentX = q.popleft()
        childrens = [(currentY, currentX - 1), (currentY + 1, currentX), (currentY, currentX + 1),
                     (currentY - 1, currentX)]

        for child in childrens:
            childY, childX = child
            if childX >= 0 and childX < w and childY >= 0 and childY < h:
                if arr[childY][childX] == ".":
                    if status[childY][childX] == -1:
                        q.insert(0,(childY, childX))
                        status[childY][childX] = status[currentY][currentX]
                    else:
                        if status[childY][childX] > status[currentY][currentX]:
                            status[childY][childX] = status[currentY][currentX]
                            q.insert(0,(childY, childX))

        for i in range(-2, 3):
            for j in range(-2, 3):
                childY = currentY + i
                childX = currentX + j
                if (childY, childX) in childrens:
                    continue

                if childX >= 0 and childX < w and childY >= 0 and childY < h:
                    if arr[childY][childX] == ".":
                        if status[childY][childX] == -1:
                            status[childY][childX] = (status[currentY][currentX] + 1)
                            q.append((childY, childX))
                        else:
                            if status[childY][childX] > (status[currentY][currentX] + 1):
                                status[childY][childX] = (status[currentY][currentX] + 1)
                                q.append((childY, childX))
    print(status[dh-1][dw-1])
calculate(H,W,CH,CW,DH,DW,ARR)


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

int main() {
	int N;
	cin >> N;
	vector<int>H(N);
	for (int n = 0; n < N; ++n) {
		cin >> H[n];
	}
	for (int n = 0;n<N;++n) {
		if (0 == n) {
			H[n]--;
			continue;
		}
		if (H[n] < H[n - 1]) {
			cout << "No" << endl;
			return 0;
		}
		if (H[n] > H[n-1]) {
			H[n]--;
		}
	}
	cout << "Yes" <<endl;
	return 0;
}


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

using namespace std;

int main() {
    int W, a, b;
    scanf("%d %d %d", &W, &a, &b);
    int ans;
    if ((a + W) <= b) {
        ans = b - (a + W);
    } else if (a >= (b + W)) {
        ans = a - (b + W);
    } else {
        ans = 0;
    }

    printf("%d\n", ans);
}


Measured memory_bytes: 128
w,h,n = list(map(int, input().split()))
data = [list(map(int, input().split())) for _ in range(n)]
x1 = y1 = 0
x2,y2 = w,h
for x,y,a in data:
    if a==1:
        x1=max(x1, x)
    elif a==2:
        x2=min(x2, x)
    elif a==3:
        y1=max(y1, y)
    else:
        y2=min(y2, y)
print(max(x2-x1,0)*max(y2-y1,0))

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, k;
  std::cin >> n >> k;
  std::vector<int64_t> par(n);
  std::cin >> par;

  for (auto &i : par) {
    i--;
  }

  std::vector<std::set<int64_t>> child(n);

  for (int64_t i = 0; i < n; i++) {
    child[par[i]].insert(i);
  }

  std::vector<int64_t> dis(n, 0);

  std::deque<int64_t> deq;
  deq.push_back(0);
  dis[0] = 0;

  std::multimap<int64_t, int64_t> m;

  while (!deq.empty()) {
    const auto i = deq.front();
    m.insert(std::make_pair(dis[i], i));
    deq.pop_front();

    for (const auto j : child[i]) {
      if (j == 0) {
        continue;
      }
      dis[j] = dis[i] + 1;
      deq.push_back(j);
    }
  }

  int64_t ans = 0;
  if (par[0] != 0) {
    ans++;
  }

  for (auto itr = m.crbegin(); itr != m.crend(); itr++) {
    const auto i = itr->second;
    if (itr->first <= k) {
      break;
    }
    if (dis[i] <= k) {
      continue;
    }
    ans++;

    int64_t j = i;
    for (int64_t l = 0; l < k - 1; l++) {
      j = par[j];
    }
    child[par[j]].erase(j);
    par[j] = 0;
    dis[j] = 1;

    std::deque<int64_t> deq;
    deq.push_back(j);
    while (!deq.empty()) {
      const auto i = deq.front();
      deq.pop_front();

      for (const auto j : child[i]) {
        dis[j] = dis[i] + 1;
        deq.push_back(j);
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 17920
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
//#define INF 2e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    string n;
    int len,sum=0;

    cin >> n;
    len = n.size();
    rep(i,len){
        sum += n[i]-'0';
    }
    if(sum%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3720
#include<stdio.h>
#include<string.h>
int main()
{
	char s[200000];
	char t[100];
	scanf("%s", s);
	scanf("%s", t);
	int aim;
	int ls, lt,i,flag=0;
	ls = strlen(s);
	lt = strlen(t);
	for (aim = ls - lt; aim > -1; aim--)
	{
		if (!flag)
		{
			flag = 1;
			for (i = 0; i < lt; i++)
			{
				if (s[aim + i] != '?'&&s[aim + i] != t[i])
				{
					flag = 0;
					break;
				}
			}
		}
		else
			break;
	}
	aim++;
	if (flag)
	{
		for (i = 0; i < aim; i++)
		{
			if (s[i] == '?')
				printf("a");
			else
				printf("%c", s[i]);
		}
		printf("%s", t);
		for (i = aim + lt; i < ls; i++)
		{
			if (s[i] == '?')
				printf("a");
			else
				printf("%c",s[i]);
		}
	}
	else
		printf("UNRESTORABLE");
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"

//region Template
#include "ext/pb_ds/assoc_container.hpp"
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;

using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
void print() {}
template<typename T, typename... Args>
void print(T firstArg, Args... args) {
	#ifdef LOCAL
	cout << firstArg << "\t";
	print(args...);
	#endif
}
//endregion

/* Notes:
 * Farah </3
 */

const int MAXN = 2e5 + 6;
const ll INF = 2e18;
int t1[4 * MAXN];
int t2[4 * MAXN];

map<int, int> pos;

int mn(int par, int v, int tl, int tr, int l, int r) {
	auto &t = (par == 0 ? t1 : t2);

	if (l > r)
		return 1e9;
	if (l == tl && r == tr) {
		return t[v];
	}
	int tm = (tl + tr) / 2;
	return min(mn(par, v*2, tl, tm, l, min(r, tm)),
		    mn(par, v*2+1, tm+1, tr, max(l, tm+1), r));
}

void update(int par, int v, int tl, int tr, int pos, int new_val) {
	auto &t = (par == 0 ? t1 : t2);

	if (tl == tr) {
		t[v] = new_val;
	} else {
		int tm = (tl + tr) / 2;
		if (pos <= tm)
			update(par, v*2, tl, tm, pos, new_val);
		else
			update(par, v*2+1, tm+1, tr, pos, new_val);
		t[v] = min(t[v*2], t[v*2+1]);
	}
}

int a[MAXN];
set<int> s;

set<pair<pair<int, int>, int>> p;

int b[MAXN];

int main() {
	#ifdef LOCAL
	setIn("in.txt");
	setOut("out.txt");
	#endif

	int n;
	cin >> n;

	p.insert({{n - 1, 0}, 0});
	for(int i = 0; i < n; i++){
		update(0, 1, 0, n - 1, i, 1e9);
		update(1, 1, 0, n - 1, i, 1e9);

	}

	for(int i = 0; i < n; i++){
		cin >> a[i];
		pos[a[i]] = i;

		update(i % 2, 1, 0, n - 1, i, a[i]);
	}
	s.insert(mn(0, 1, 0, n - 1, 0, n - 1));
	for(int i = 0; i < n / 2; i++){
		auto cur = s.begin();
		b[2 * i] = *cur;

		auto interval = p.upper_bound({{pos[*cur], 1e9}, -1});
		int l = interval->first.second, r = interval->first.first;
		int par = interval->second;
		p.erase(interval);

		int m = mn(!par, 1, 0, n - 1, pos[*cur] + 1, r);
		b[2 * i + 1] = m;
		update(!par, 1, 0, n - 1, pos[m], 1e9);

		if(pos[*cur] + 1 != pos[m] + 1){
			s.insert(mn((pos[*cur] + 1) % 2, 1, 0, n - 1, pos[*cur] + 1, pos[m] - 1));
			p.insert({{pos[m] - 1, pos[*cur] + 1}, (pos[*cur] + 1) % 2});
		}

		if(pos[*cur] - 1 > l) {
			s.insert(mn(l % 2, 1, 0, n - 1, l, pos[*cur] - 1));
			p.insert({{pos[*cur] - 1, l}, par});
		}
		if(r > pos[m] + 1) {
			p.insert({{r, pos[m] + 1}, par});
			s.insert(mn((pos[m] + 1) % 2, 1, 0, n - 1, pos[m] + 1, r));
		}

		s.erase(cur);
	}

	for(int i = 0; i < n; i++){
		cout << b[i] << " " ;
	}
}


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

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

using namespace std;

int main(){
  double A,B,H,M;
  cin >> A >> B >> H >> M;
  H = H*5;
  H += (double)M/12;

  double buffer=abs(H-M);
  buffer=6*buffer;

  printf("%.12lf",pow(pow(A,2)+pow(B,2)-2*A*B*cos((double)buffer*3.14159265358979/180),0.5));
  return 0;
}


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

using namespace std;

int main(){
	string s,t; cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	if(t[t.size()-1] > s[0] || (s.size() < t.size() && s[s.size()-1] <= t[s.size() -1])){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++ i)
#define per(i,a,b) for(int i = (a); i >= (b); -- i)
#define pb push_back
#define VI vector<int>
#define VVI vector<VI>
#define Pii pair<int,int>
#define Pll pair<ll,ll>
#define Pli pair<ll,int>
#define fi first
#define se second
#define Ppi pair<Pii,int>
#define VII vector<Pii>

using namespace std;

typedef long long ll;
typedef int (*funI_I) (int);
typedef int (*funI_II) (int, int);

constexpr int N = 4000100;
constexpr int P = 1e9 + 7;
ll qpow(ll a, ll b) {
    ll ans = 1;
    for( ;b; b >>= 1, a = a * a % P) if(b & 1) ans = ans * a % P;
    return ans;
}

ll n, a, b;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> a >> b;
    ll Ca = 1, Cb = 1, CC = 1;
    for(ll i = 1; i <= b; ++ i) {
        CC = (CC * (n-i+1ll) % P)  * qpow(i,P-2) % P;
        if(i == a) {
            Ca = CC;
        }
        else if(i == b) {
            Cb = CC;
        }
        // cerr << CC << " ";
    } //cerr << "\n";
    ll ans = (qpow(2,n) - 1 + P) % P;
    ans = (ans - Ca + P) % P;
    ans = (ans - Cb + P) % P;
    cout << ans << "\n";
}
// 2^4-1 = 16-1
// - C(4,1) - C(4,3)
// C(n,0) = n!/0!(n-0)!
// C(n,1) = n!/1!(n-1)!

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
B_C = []
for _ in range(M):
    B, C = map(int, input().split())
    B_C.append((C, B))
B_C = sorted(B_C, reverse=True)
Cs = []
rem = N
for c, b in B_C:
    if rem >= b:
        Cs += [c]*b
        rem -= b
    else:
        Cs += [c]*rem
        break
ans = sum(sorted(A+Cs, reverse=True)[:N])
print(ans)

Measured memory_bytes: 25580
N,M,X=map(int,input().split())
A=[int(i) for i in input().split()]
#print(A)
left=0
right=0
#通過した数をカウント
for i in A:
  if i>X:
    right+=1 #右端へ移動
  else:
    left+=1
ans=min(left,right)
print(ans)

Measured memory_bytes: 3060
(let* ((n (read))
       (ll (loop :repeat n :collect (list (read) (read) (read)))))
  (loop :for (an xn yn) :in ll
        :for a := an :then (- an a)
        :for x := xn :then (abs (- xn x))
        :for y := yn :then (abs (- yn y))
        :if (not (and (<= (+ x y) a) (= (mod (+ x y) 2) (mod a 2))))
          :return (princ "No")
        :finally (princ "Yes")))

Measured memory_bytes: 63848
n = input()
input_char = input()
input_char = input_char.split(" ")

mountains_heigh = [int(h) for h in input_char]

viewable_count = 1
for idx,h in enumerate(mountains_heigh):
    if idx >0 :
        max_h_behind = max(mountains_heigh[:idx])
        if max_h_behind <= h :
            viewable_count+= 1

print(viewable_count)

Measured memory_bytes: 3060
#include<stdio.h>

#define DATA_NUM 10
#define RANK 3

int main(){

        int i = 0, j = 0;
        int kioku = 0;
        int input[DATA_NUM];

        for(i = 0; i < DATA_NUM ; i++)
        {
                input[i] = 0;
                scanf("%d", &input[i]);
        }

        for(i = 0; i < DATA_NUM ; i++)
        {
                for(j = i + 1; j < DATA_NUM ; j++)
                {
                        if(input[i] < input[j])
                        {
                                kioku = input[i];
                                input[i] = input[j];
                                input[j] = kioku;
                        }
                }
        }
        for(i = 0;i < RANK; i++)
        {
                printf("%d\n",input[i]);
        }
        return 0;
}

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

typedef long long ll;

int main(int argc, char const *argv[])
{
    int n;scanf("%d",&n);
    vector<ll> a(n);for(int i = 0;i < n;i++)scanf("%lld",&a[i]);
    
    long long sum = 0;
    long long cost = 0;
    long long ans = LONG_MAX;

    for(int i = 0;i < n;i++){
        if(i%2==0){
            //正
            if((sum += a[i]) <= 0){
                cost += 1 - sum;
                sum = 1;
            }
        }else{
            //負
            if((sum += a[i]) >= 0){
                cost += sum + 1;
                sum = -1;
            }
        }
    }
    ans = min(ans,cost);
    sum = cost = 0;
    for(int i = 0;i < n;i++){
        if(i%2==1){
            //正
            if((sum += a[i]) <= 0){
                cost += 1 - sum;
                sum = 1;
            }
        }else{
            //負
            if((sum += a[i]) >= 0){
                cost += sum + 1;
                sum = -1;
            }
        }
    }
    ans = min(ans,cost);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.util.stream.Collectors;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        String[] S = new String[N];
        for (int i = 0; i < N; i++) {
            S[i] = scanner.next();
        }
        Arrays.sort(S, String::compareTo);

        int maxCnt = 0;
        int cnt = 0;
        String prev = null;
        for (int i = 0; i < N; i++) {
            if (prev == null || prev.equals(S[i])) {
                prev = S[i];
                cnt++;
            } else {
                maxCnt = Math.max(maxCnt, cnt);
                prev = S[i];
                cnt = 1;
            }
        }
        maxCnt = Math.max(maxCnt, cnt);

        cnt = 0;
        prev = null;
        List<String> sb = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            if (prev == null || prev.equals(S[i])) {
                prev = S[i];
                cnt++;
                if (cnt == maxCnt) {
                    sb.add(prev);
                    prev = null;
                    cnt = 0;
                }
            } else {
                prev = S[i];
                cnt = 1;
            }
        }

        if (cnt == maxCnt) {
            sb.add(prev);
        }

        System.out.println(String.join("\n", sb));
    }

}



Measured memory_bytes: 73800
# -*- coding: utf-8 -*-
n = input()

s = [input() for i in range(n)]
s2 = sorted(s)
ans = sum(s2)
flg = 0
if(ans%10 == 0):
    for i in range(n):
        if(s2[i]%10 != 0):
            ans -= s2[i]
            flg = 1
            break
    print(ans if flg else 0)
else:
    print(ans)

Measured memory_bytes: 2568
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
    int a, b;
    while (cin >> a >> b) {
        int sum = a + b;
        int digit = 0;
        while (sum > 0) {
            sum /= 10;
            digit++;
        }
        cout << digit << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
//by kcz 1552920354@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;

template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mp make_pair
#define gc (c=getchar())
char readc()
{
	char c;
	while(gc<'-');
	return c;
}
int read()
{
    char c;
    while(gc<'-');
    if(c=='-')
    {
        int x=gc-'0';
        while(gc>='0')x=x*10+c-'0';
        return -x;
    }
    int x=c-'0';
    while(gc>='0')x=x*10+c-'0';
    return x;
}
#undef gc

const int N=2e5+5,inf=1e9+5;

int main()
{
	//freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
	int n;cin>>n;
	ll sum=0;int mn=inf;
	rep(i,1,n)
	{
		int a=read(),b=read();
		sum+=a;
		if(a>b)chmin(mn,b);
	}
	if(mn==inf)puts("0");
	else cout<<sum-mn<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (auto& vv : v) {
    for (auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}


void solve() {
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  F0R (i, SZ(s)) {
    if (s[i] != t[i]) ++cnt;
  }
  cout << cnt << endl;
}

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

  int tt = 1;
  FOR (t, 1, tt + 1) {
    // cout << "Case #" << t << ": ";
    solve();
  }
  
  return 0;
}


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

int main() {
	int n;
	while (cin >> n, n) {
		int k = 1, zeronum = 0;
		while (n/5 >= k) {
			k *= 5;
			zeronum += n/k;
		}
		cout << zeronum << endl;
	}
	return 0;
}

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

int main(){
  int n; cin >> n;
  vector<long> p(n);
  for(int i = 0; i < n; i++)
    cin >> p.at(i);
  long minn = p.at(0);
  int ans = 1;
  for(int i = 1; i < n; i++){
    if(minn >= p.at(i)){
      //cout << p.at(i) << endl;
      ans++;
      minn = p.at(i);
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 4832
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

struct UnionFind
{
	void init(int n) { par = new int[](n); foreach (i; 0..n) par[i] = i; cnt = new int[](n); fill(cnt, 1); }
	int root(int i) { return par[i] == i ? i : (par[i] = root(par[i])); }
	bool same(int i, int j) { return root(i) == root(j); }
	void unite(int i, int j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; cnt[j] += cnt[i]; }
	int size(int i) { return cnt[root(i)]; }
	int[] par, cnt;
}

void main()
{
	auto N = RD!int;
	auto M = RD;
	auto K = RD;
	auto AB = new int[][](M);
	foreach (i; 0..M)
	{
		AB[i] = [RD!int-1, RD!int-1];
	}
	auto CD = new int[][](K);
	foreach (i; 0..K)
	{
		CD[i] = [RD!int-1, RD!int-1];
	}

	UnionFind uf;
	uf.init(N);
	foreach (i; 0..M)
	{
		uf.unite(AB[i][0], AB[i][1]);
	}

	auto ans = new long[](N);
	foreach (i; 0..N)
	{
		ans[i] = uf.size(i) - 1;
	}

	foreach (i; 0..M)
	{
		auto a = AB[i][0];
		auto b = AB[i][1];
		--ans[a];
		--ans[b];
	}

	foreach (i; 0..K)
	{
		auto c = CD[i][0];
		auto d = CD[i][1];
		if (uf.same(c, d))
		{
			--ans[c];
			--ans[d];
		}
	}

	ans.map!(to!string).join(" ").writeln;
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 16380
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}
func main() {
    let S = Array(readLine()!)
    var ans = 0
    for i in stride(from: 0, to: S.count/2, by: 1){
        if S[i] != S[S.count-i-1]{
            ans += 1
        }
    }
    print(ans)
}
main()

Measured memory_bytes: 13264
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a) (0<a&&a<5001)
using namespace std;
bool isP[5001][5001];
int x[5000],y[5000];
int main(){
	int n,mx;
	while(cin>>n,n){
		rep(i,n)cin>>x[i]>>y[i],isP[x[i]][y[i]]=1; mx=0;
		rep(i,n)rep(j,n){
			int dx=x[j]-x[i],dy=y[j]-y[i],a=x[j]-dy,b=y[j]+dx,c=x[i]-dy,d=y[i]+dx;
			if(ck(a)&&ck(b)&&ck(c)&&ck(d)&&isP[a][b]&&isP[c][d]&&mx<dx*dx+dy*dy)mx=dx*dx+dy*dy;
		}
		cout<<mx<<endl;
		rep(i,n)isP[x[i]][y[i]]=0;
	}
	return 0;
}

Measured memory_bytes: 24000
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 998244353

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int n;
    cin >> n;
    
    ll ans = 0;

    for(int i = 1; i <= n; i++)
    {
        ll q = n / i;
        ans += i * (q * (q + 1) / 2);
    }

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

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

    int T = 1;
//    cin >> T;
    
    while (T--)
    {
        solve();
    }
    
    return 0;
}




Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
vector<int> s(100100);
int n;
bool b_s(int x);
int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }

    int ans = 0;
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int t; cin >> t;
        if(b_s(t)) ans++;
    }
    cout << ans << endl;
}

bool b_s(int x){
    int l = 0, r = n;

    while(l<r){
        int p = (l+r)/2;
        if(s[p] == x) return true;
        if(x < s[p]){r = p;}
        if(x > s[p]){l = p+1;}
    }
    return false;
}


Measured memory_bytes: 3092
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int h, w;
  cin >> h >> w;
  int ch, cw, dh, dw;
  cin >> ch >> cw >> dh >> dw;
  ch--, cw--;
  dh--, dw--;
  vector<string> s(h);
  for(int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<vector<int>> a(h, vector<int>(w, 1001001001)), b(h, vector<int>(w, 0));
  deque<pair<int, int>> que;
  que.push_back({ch, cw});
  a[ch][cw] = 0;
  b[ch][cw] = 1;
  while(!que.empty()) {
    int nowh, noww;
    nowh = que.front().first;
    noww = que.front().second;
    // nowh = que.top().first;
    // noww = que.top().second;
    b[nowh][noww] = 0;
    que.pop_front();
    int dist = a[nowh][noww];
    if(nowh + 1 < h && a[nowh + 1][noww] > dist && s[nowh + 1][noww] != '#') {
      a[nowh + 1][noww] = dist;
      if(b[nowh + 1][noww] == 0) {
        b[nowh + 1][noww] = 1;
        que.push_front({nowh + 1, noww});
      }
    }
    if(nowh - 1 >= 0 && a[nowh - 1][noww] > dist && s[nowh - 1][noww] != '#') {
      a[nowh - 1][noww] = dist;
      if(b[nowh - 1][noww] == 0) {
        b[nowh - 1][noww] = 1;
        que.push_front({nowh - 1, noww});
      }
    }
    if(noww + 1 < w && a[nowh][noww + 1] > dist && s[nowh][noww + 1] != '#') {
      a[nowh][noww + 1] = dist;
      if(b[nowh][noww + 1] == 0) {
        b[nowh][noww + 1] = 1;
        que.push_front({nowh, noww + 1});
      }
    }
    if(noww - 1 >= 0 && a[nowh][noww - 1] > dist && s[nowh][noww - 1] != '#') {
      a[nowh][noww - 1] = dist;
      if(b[nowh][noww - 1] == 0) {
        b[nowh][noww - 1] = 1;
        que.push_front({nowh, noww - 1});
      }
    }

    for(int i = -2; i <= 2; i++) {
      for(int j = -2; j <= 2; j++) {
        if(nowh + i < h && nowh + i >= 0) {
          if(noww + j < w && noww + j >= 0) {
            if(a[nowh + i][noww + j] > dist + 1 &&
               s[nowh + i][noww + j] != '#') {
              a[nowh + i][noww + j] = dist + 1;
              if(b[nowh + i][noww + j] == 0) {
                b[nowh + i][noww + j] = 1;
                que.push_back({nowh + i, noww + j});
              }
            }
          }
        }
      }
    }
  }
  if(a[dh][dw] == 1001001001) {
    cout << -1 << endl;
  } else {
    cout << a[dh][dw] << endl;
  }
  return 0;
}

Measured memory_bytes: 13412
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


def get_divisors(n):
    """
    n の約数をリストで返す
    :param int n:
    :rtype: list of int
    """
    ret = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


N = int(sys.stdin.readline())
ans = IINF
for d in get_divisors(N):
    c = N // d
    f = max(len(str(c)), len(str(d)))
    ans = min(ans, f)
print(ans)




Measured memory_bytes: 13672
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
//printf("%.12lf\n",mid);
//const long long sze = 2*(2^(long long)(ceil(log(100000)/log(2))));
/*
// get part of decimal
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
const long long mod = 1000000007;
const double eps = .0000000001;
inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
};

int main(){
    prep();
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << " " << max(0, (a+b)-n);
   
    return 0;
}      

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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
const double PI = 3.1415926535897932;

int main()
{
    ll n,k; cin >> n >> k;
    ll a[n],f[n];
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(a,a+n);
    sort(f,f+n);
    reverse(f,f+n);
    ll ng = -1, ok = 1e12+5;
    ll x;
    while(ok - ng > 1){
        x = k;
        ll mid = (ok+ng)/2;
        rep(i,n){
            if(a[i] * f[i] > mid){
                x -= (a[i] - mid/f[i]);
            }
        }
        if(x >= 0) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

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

signed main(void)
{
	long long n, k, ans;
	cin >> n >> k;
	long long x[n];

	rep(i, n) cin >> x[i];
	ans = 10000000000000;
	rep(i, n)
	{
		if (i + k - 1 < n)
		{
			if (x[i + k - 1] < 0)
				ans = min(ans,abs(x[i]));
			else if (x[i] > 0)
				ans = min(ans,abs(x[i + k - 1]));
			else
				ans = min(ans, min(abs(x[i + k - 1]) + abs(x[i]) * 2\
						,abs(x[i]) + abs(x[i + k - 1]) * 2));
		}	
		else
			break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
def bs_left(list, target):
    low = 0
    high = len(list)

    while low < high:
        mid = (low + high) // 2
        if target > list[mid]:
            low = mid + 1
        else:
            high = mid
    return low

def bs_right(list, target):
    low = 0
    high = len(list)
    while low < high:
        mid = (low + high) // 2
        if target < list[mid]:
            high = mid
        else:
            low = mid + 1
    return low

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()

ans = 0
for b in B:
    ans += (bs_left(A, b) * (n - bs_right(C, b)))
print(ans)

Measured memory_bytes: 29504
PROGRAM tableTennisTraining
      IMPLICIT NONE
      integer(16) :: n,a,b
      integer(16) :: sub,ans,sma,big,ans1,ansn
      
      read*,n,a,b
      
      
      
      sub = abs( a-b )
      if( mod(sub,2)==0 )then
        ans = sub/2
      else
        sma = min(a,b)
        big = max(a,b)
        
        ans1 = (sma-1) + 1 + (big-1-(sma-1+1))/2
        ansn = (n-big) + 1 + (n-(sma+(n-big)+1))/2
        ans = min(ans1,ansn)
      endif
      
      
      
      print*,ans
      
      
      END PROGRAM

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n,i,j,count=0,max=0;
  char s[101],frag_a[26],frag_b[26];
  scanf("%d",&n);
  scanf("%s",s);
  for(i=1;i<n-1;i++)
    {
      count = 0;
      for(j=0;j<26;j++)
	{
	  frag_a[j] = 0;
	  frag_b[j] = 0;
	}
      for(j=0;j<i;j++)
	{
	  frag_a[(int)s[j]-97] = 1;
	}
      for(j=i;j<n;j++)
	{
	  frag_b[(int)s[j]-97] = 1;
	}
      for(j=0;j<26;j++)
	{
	  if(frag_a[j] == 1 && frag_b[j] == 1)
	    {
	      count++;
	    }
	}
      if(count > max)
	{
	  max = count;
	}
    }
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>

struct Node{
  int key;
  struct Node *p;
  struct Node *l;
  struct Node *r;
};
typedef struct Node * Nodepointer;

Nodepointer root,nil;

void insert(int i){
  Nodepointer x = root;
  Nodepointer y = nil; /*parent*/
  Nodepointer z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = i;
  z->l = nil;
  z->r = nil;

  while(x != nil){
    y = x;
    if(x->key > z->key) x = x->l;
    else x = x->r;
  }

  z->p = y;

  if(y == nil) root = z;
  else{
    if(y->key > z->key) y->l = z;
    else y->r = z;
  }

}

void inorder(Nodepointer x){
    if(x == nil) return;
    inorder(x->l);
    printf(" %d",x->key);
    inorder(x->r);
}

void preorder(Nodepointer x){
    if(x == nil) return;
    printf(" %d",x->key);
    preorder(x->l);
    preorder(x->r);
}

int main(){
  int n,i,num;
  char c[20];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%s",&c);
    if(c[0] == 'i'){
      scanf("%d",&num);
      insert(num);
    }
    else if(c[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 25208
import sys
import math

N=int(input())

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


for i in range(N):
    if A[i]==0:
        print(0)
        sys.exit(0)

mult=1
for i in range(N):
    mult *= A[i]
    if mult > 1E18:
        print(-1)
        sys.exit(0)

print(mult)

Measured memory_bytes: 22828
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int l;
	cin >> l;
	vector<string> a(n);
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++)
	{
		cout << a[i];
	}
	return 0;
}

Measured memory_bytes: 384