akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	int A[n];
	for(int i = 0; i < n; ++i) cin >> A[i];
	
	for(int i = 0; i < n; ++i){
    	int key = A[i];
    	/* insert A[i] into the sorted sequence A[0,...,j-1] */
    	int j = i - 1;
    	while(j >= 0 && A[j] > key){
        	A[j+1] = A[j];
        	j--;
    	}
    	A[j+1] = key;
    	for(int k = 0; k < n - 1; ++k) cout << A[k] << " ";
    	cout << A[n - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1164
n=int(input())
a=list(map(int,input().split()))
b=[0,0,0]
ans=1
mod=1000000007
for i in range(n):
    aa=a[i]
    tmp=0
    flg=False
    for j in range(3):
        if aa==b[j]:
            tmp+=1
            if flg==False:
                b[j]+=1
                flg=True
    ans*=tmp
    ans%=mod
print(ans)

Measured memory_bytes: 84156
#include <bits/stdc++.h>
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define INTXT std::ifstream in ("input.txt"); std::cin.rdbuf(in.rdbuf());
#define INTXT2 std::ifstream in ("testcase.txt"); std::cin.rdbuf(in.rdbuf());
#define INF 1e9

using namespace std;
typedef long long ll;
static const ll MOD = 1000000007LL;

vector<vector<int>> edges(100001);

ll perm(int a, int b){
  if (b == 0){
    return 1;
  }
  else{
    ll out = 1;
    REP(i, b){
      out *= (a - i);
      out %= MOD;
    } 
    return out;
  }
}

ll dfslike(int prv, int cur, ll cnt, int k){
  // cout << cur << " " << cnt << endl;
  int n_color;
  if (prv == -1){
    n_color = k - 1;
  }
  else {
    n_color = k - 2;
  }

  cnt = cnt * perm(n_color, edges.at(cur).size() - 1) % MOD;
  REP(i, edges.at(cur).size()){
    if (edges.at(cur).at(i) != prv){
      cnt = dfslike(cur, edges.at(cur).at(i), cnt, k) % MOD;
    }
  }
  return cnt;
}

signed main() {
  IOS
  // INTXT2
  int n, k;
  cin >> n >> k;
  // cout << n << " " << k << endl;
  REP(i, n - 1){
    int a, b;
    cin >> a >> b;
    edges.at(a).push_back(b);
    edges.at(b).push_back(a);
  }
  edges.at(1).push_back(-1);
  ll ans = dfslike(-1, 1, (ll)k, k) % MOD;
  cout << ans << endl;

}


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

void solve(string s) {
    stack<char> S;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != '(' && s[i] != ')' && s[i] != '[' && s[i] != ']') continue;
        if (S.empty()) S.push(s[i]);
        else {
            if (S.top() == '(' && s[i] == ')') S.pop();
            else if (S.top() == '[' && s[i] == ']') S.pop();
            else S.push(s[i]);
        }
    }
    if (S.empty()) cout << "yes" << endl;
    else cout << "no" << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    while (true) {
        getline(cin, S);
        if (S == ".") break;
        solve(S);
    }
    return 0;
}


Measured memory_bytes: 3216
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        int c = inp.nextInt();
        int d = inp.nextInt();
        int aa = a + b;
        int cc = c + d;
        if (aa == cc) System.out.println("Balanced");
        if (aa > cc) System.out.println("Left");
        if (aa < cc) System.out.println("Right");
    }
}

Measured memory_bytes: 23252
n,m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
ar = Array.new(n).map{Array.new}
m.times do
  a,b = gets.split.map(&:to_i)
  ar[a-1] << h[b-1]
  ar[b-1] << h[a-1]
end

ans = 0
for i in 0..(n-1)
  if ar[i] == [] || ar[i].max < h[i]
    ans += 1
  end
end
puts ans

Measured memory_bytes: 27368
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();

    let mut ans = Vec::new();
    for _ in 0..h {
        let s: Vec<char> = itr.next().unwrap().chars().collect();
        let mut same = true;
        for j in 0..s.len() {
            if s[j] == '#' {
                same = false;
            }
        }
        if !same {
            ans.push(s);
        }
    }

    let mut samec = vec![true; w];
    for i in 0..w {
        for j in 0..ans.len() {
            if ans[j][i] == '#' {
                samec[i] = false;
            }
        }
    }

    let mut out = Vec::new();
    for i in 0..ans.len() {
        for j in 0..w {
            if samec[j] {
                continue;
            }
            write!(out, "{}", ans[i][j]).ok();
        }
        writeln!(out, "").ok();
    }
    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 2116
#include <cstdio>

int main(){
    int n;
    char s[11234];
    scanf("%d", &n);
    scanf("%s", s);
    for(char* i=s; *i != '\0'; i++){
        *i = (*i - 'A' + n) % 26 + 'A';
    }
    printf("%s", s);
    return 0;
}

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

using namespace std;

#ifdef ACMTUYO
struct RTC{~RTC(){cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC <<" seconds\n";}} runtimecount;
#define DBG(X) cerr << #X << " = " << X << '\n';
#else
struct RTC{};
#define DBG(X)
#endif

#define fast_io() ios_base::sync_with_stdio(false)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(c) (c).begin(),(c).end()
#define forn(i, n) for (int i = 0; i < (n); i++)
typedef long long int number;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> v(n);
  forn (i, n) {
    scanf("%d", &v[i]);
  }
  sort(all(v));
  int answer = 0;
  forn (i, n)
    for (int j = i + 1; j < n; j++)
      for (int k = j + 1; k < n; k++) {
        int a = v[i], b = v[j], c = v[k];
        if (a != b and b != c and a + b > c)
          answer++;
      }
  printf("%d\n", answer);
  return 0;
}


Measured memory_bytes: 3784
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

void call(int n)
{
	int i = 1;
	int x;

	do {
		x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
		}
		else {
			do {
				if (x % 10 == 3) {
					printf(" %d", i);
					x = 0;
				}
				else x /= 10;
			} while (x);
		}
	} while (++i <= n);
	putchar('\n');
}

#if 1
int main()
{
	int n;

	scanf("%d", &n);
	call(n);
	return 0;
}
#endif



Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S ;
    cin >> S ;
    if(S == "SAT") cout << 1 << endl ;
    if(S == "FRI") cout << 2 << endl ;
    if(S == "THU") cout << 3 << endl ;
    if(S == "WED") cout << 4 << endl ;
    if(S == "TUE") cout << 5 << endl ;
    if(S == "MON") cout << 6 << endl ;
    if(S == "SUN") cout << 7 << endl ;
    return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    for(double d; cin >> d;){
        double ans = d * sqrt(2);
        for(int h = 1; h <= 10; h++){
            if(d < h)continue;
            double w = sqrt(d * d - h * h);
            ans = max(ans, h + max(w, 1.0));
        }
        printf("%.9f\n", ans);        
    }

    return 0;
}



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

using namespace std;
using i64 = int64_t;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    for(auto&& x:A)cin >> x;
    sort(A.begin(), A.end());
    int sum = 0;
    for(int i=1;i<N-1;i++)sum += abs(A[i]);
    cout << A[N-1] + sum - A[0] << endl;
    for(int i=1;i<N-1;i++){
        if(A[i] < 0){
            cout << A[N-1] << " " << A[i] << endl;
            A[N-1] -= A[i];
        }else{
            cout << A[0] << " " << A[i] << endl;
            A[0] -= A[i];
        }
    }
    cout << A[N-1] << " " << A[0] << endl;
    return 0;
}

Measured memory_bytes: 3724
#include <stdio.h>
void outp(double a) {if (a<=48.00) puts("light fly"); else if (a<=51.00) puts("fly"); else if (a<=54.00) puts("bantam"); else if (a<=57.00) puts("feather"); else if (a<=60.00) puts("light"); else if (a<=64.00) puts("light welter"); else if (a<=69.00) puts("welter"); else if (a<=75.00) puts("light middle"); else if (a<=81.00) puts("middle"); else if (a>91.00) puts("heavy"); else puts("light heavy");}
int main() {double i;while (scanf("%lf",&i)!=EOF) outp(i);return 0;}

Measured memory_bytes: 0
result = 0
odd = ["R","U","D"]
even = ["L","U","D"]
s = input()
for i in range(len(s)):
    if (i+1) % 2 == 0:
        if s[i] not  in even:
            result += 1
    else:
        if s[i] not in odd:
            result += 1
if result >=1:
    print('No')
else :
    print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 2e17;
const int mod = 1e9 + 7;

signed main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    cin >> P >> Q;
    vector<int> A(N);
    for (int i = 0; i < N; i++) A[i] = i + 1;
    int p, q;
    int count = 1;
    do {
        if (P == A) p = count;
        if (Q == A) q = count;
        ++count;
    } while (next_permutation(A.begin(), A.end()));
    cout << abs(p - q) << endl;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())

if (b-a)%2 == 0:
    print((b-a)//2)
else:
    if (a-1) <= (n-b):
        print(a-1 + 1 +(b-a-1)//2)
    else:
        print(n-b + 1 +(b-a-1)//2)

Measured memory_bytes: 2940
from collections import defaultdict

def prime_gen(limit):
    dd = defaultdict(list)
    for x in range(2, limit + 1):
        if x in dd:
            for y in dd[x]:
                dd[y + x].append(y)
        else:
            yield x
            dd[x * x].append(x)

if __name__ == '__main__':
    ps = set(prime_gen(100000))
    like2017s = {n for n in ps if (n + 1) // 2 in ps}
    acc = [0] * 100001
    for i in range(3, 100001):
        acc[i] = acc[i - 1]
        if i in like2017s:
            acc[i] += 1

    q = int(input())
    for l, r in (map(int, input().split()) for _ in range(q)):
        print(acc[r] - acc[l - 1])


Measured memory_bytes: 25728
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
vector<int> ed[100010];
string s;
bool memo[100010];
bool check(int x, char col, int deep) {

	bool res = true;
	
	for (auto v : ed[x]) {

		if (s[v - 1] != col) {
			res = false;
			break;
		}
	}
	return res;
}
ll f(ll b, ll n) {
	if (b <= 1) return -1;
	if (b > n) return n;
	return f(b, n / b) + (n % b);
}

void solv() {
	ll n,s;
	cin >> n;
	cin >> s;
	if (n == s) {
		cout << n + 1 << endl;
		return;
	}

	if (n == 1 && s > 1) {
		cout << -1 << endl;
		return;
	}
	ll pp = sqrt(n);
	ll bef = 0;
	for (ll i = 2; i <= 1000000; i++)
	{
		ll v = f(i, n);
		if (v == s) {
			cout << i << endl;
			return;
		}
		//if (bef < v)
		//	cout << i << " " << v << endl;
		//bef = v;
		//if (s == f(i, n)) {
		//	cout << i << endl;;
		//}
	}
	ll in = 1;
	ll ma = n;
	ll res = (s == 1) ? n : -1;
	while (ma >= pp)
	{
		ll tm = ma;
		in++;
		ma = (n / in) + 1;
		ll lo = ma;
		bool find = false;
		ll mid;
		ll count = 0;
		while (lo <= tm && count <= 50)
		{
			mid = (tm + lo) / 2LL;
			ll va = f(mid, n);
			if (va > s) {
				lo = mid;
			}
			else if (va < s) {
				tm = mid;
			}
			else {
				find = true;
				break;
			}
			count++;
		
		}
		if (find) {
			res = mid;
		}
	}
	if (res == -1) {
		cout << -1 << endl;
	}else
		cout << res << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  rep(i,n) cin >> a[i];
  cout << ceil(((double) (n-1))/((double) (k-1))) << endl;
  return 0;

}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main {
	
	public int calculate(char[][] map){
		int n = map.length;
		int m = map[0].length;
		int counter = 0;
		for(int i = 1; i < map.length-1; i++){
			for(int j = 1; j < map[0].length-1; j++){
				if( map[i][j] == '.' ){
					continue;
				}
				counter++;
				char key = map[i][j];
				Set<Integer> set = new HashSet<Integer>();
				Set<Integer> next = new HashSet<Integer>();
				next.add(i*n+j);
				while( next.size() != 0 ){
					for(Integer x : next){
						set.add(x);
					}
					next.clear();
					for(Integer x : set){
						int a = x/n;
						int b = x%n;
						if( map[a+1][b] == key && !set.contains((a+1)*n+b) ){
							next.add((a+1)*n+b);
						}
						if( map[a-1][b] == key && !set.contains((a-1)*n+b) ){
							next.add((a-1)*n+b);
						}
						if( map[a][b+1] == key && !set.contains(a*n+b+1) ){
							next.add((a*n+b+1));
						}
						if( map[a][b-1] == key && !set.contains(a*n+b-1) ){
							next.add((a*n+b-1));
						}
					}
				}
				for(Integer x : set){
					int a = x/n;
					int b = x%n;
					map[a][b] = '.';
				}
			}
		}
		return counter;
	}
	public void solve() throws IOException {
		int n, m;
		while( (n = nextInt()) != 0 | (m = nextInt()) != 0 ){
			String[] temp = new String[n];
			for(int i = 0; i < n; i++){
				temp[i] = nextToken();
			}			
			char[][] map = new char[n+2][m+2];
			for(int i = 0; i < map.length; i++){
				map[i][0] = '.';
				map[i][map[0].length-1] = '.';
			}
			for(int i = 0; i < map[0].length; i++){
				map[0][i] = '.';
					map[map.length-1][i] = '.';
			}
			for(int i = 1; i < map.length-1; i++){
				for(int j = 1; j < map[0].length-1; j++){
					map[i][j] = temp[i-1].charAt(j-1);
				}
			}
			System.out.println(calculate(map));
		}
	}		
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int x = scanner.nextInt();
		if (a<=x && x<=a+b) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}

}

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<bool> a(n, false);
  a[0] = true;
  vector<int> b(n, 1);
  for(int i=0; i<m; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    if(a[x]&&b[x]>1) {
      a[y] = true;
    } else if(a[x]&&b[x]==1) {
      a[x] = false;
      a[y] = true;
    }
    b[x]--; b[y]++;
  }
  ll ans =0;
  for(int i=0; i<n; i++) {
    if(a[i])ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.awt.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int h = sc.nextInt();

        Point[] array = new Point[n];

        for (int i = 0; i < n; i++) {
            array[i] = new Point(sc.nextInt(), sc.nextInt());
        }

        Arrays.sort(array, Comparator.comparingInt(v -> v.x));
        Point aMax = array[n - 1];
        Arrays.sort(array, (v1, v2) -> v2.y - v1.y);
        int count = 0;
        int index = 0;
        while (h > 0) {
            if (index < n && array[index].y >= aMax.x) {
                h -= array[index].y;
                index++;
                count++;
            } else {
                int decreased = h / aMax.x;
                if (h % aMax.x > 0) {
                    decreased++;
                }
                h -= aMax.x * decreased;
                count += decreased;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 92648
#include<stdio.h>
#include<stdlib.h>
  
struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node * Node;
#define NIL NULL
  
Node root;
  
Node treeMinimum(Node x){
  Node y;
  y=x;
  while(y->left!=NIL) y=y->left;
  
  return y;
  
}
  
Node treeMaximum(Node x){
 Node y;
  y=x;
  while(y->left!=NIL) y=y->right;
  
  return y;
  
}
  
Node treeSearch(Node u, int k){
  Node x;
  x=u;
  
  while(x!=NIL && k!=x->key){
    if(k < x->key)x=x->left;
    else x=x->right;
  }
  
  return x;
  
}
  
Node treeSuccessor(Node x){
  Node y;
  
  if(x->right!=NIL)return treeMinimum(x->right);
  
  y=x->p;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->p;
  }
  return y;
  
}
  
void treeDelete(Node z){
  Node y;
  Node x;
  
  if(z->left==NIL || z->right==NIL)y=z;
  else y=treeSuccessor(z);
  
  if(y->left!=NIL)x=y->left;
  else x=y->right;
  
  if(x!=NIL)x->p=y->p;
  if(y->p==root)root=x;
  else if(y == y->p->left)y->p->left=x;
  else y->p->right=x;
  
  if(y!=z) z->key=y->key;
  free(y);
  
}
  
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y=x;
    if(k < x->key)x=x->left;
    else x=x->right;
  }
  z->p=y;
  
  if(y==NIL)root=z;
  else if(z->key < y->key)y->left=z;
  else y->right=z;
  
}
  
void inorder(Node u){
  if (u==NIL)return;
  
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
  
}
void preorder(Node u){
if (u==NIL)return;
  
 printf(" %d",u->key);
 preorder(u->left);
 preorder(u->right);
  
}
  
  
int main(){
  int num, i, z;
  char com[20];
  Node t;
  scanf("%d", &num);
  
  for ( i = 0; i < num; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &z);
       t = treeSearch(root, z);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &z);
      insert(z);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &z);
      treeDelete(treeSearch(root, z));
    }
  }
  
  return 0;
}


Measured memory_bytes: 20460
import scala.io.StdIn.readInt
import scala.annotation.tailrec

object Main extends App {

  val n = readInt()

  val (h, m, s) = solve(n)
  println(s"$h:$m:$s")

  def solve(n: Int): (Int, Int, Int) = {
    @tailrec
    def go(h: Int, m: Int, s: Int): (Int, Int, Int) = {
      if (s >= 3600)
        go(h + 1, m, s - 3600)
      else if (s >= 60)
        go(h, m + 1, s - 60)
      else
        (h, m, s)
    }

    go(0, 0, n)
  }
}



Measured memory_bytes: 43800
#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  
  int cnt = 0;
  for (int i=0; i<n; ++i)
  {
    int l, r;
    cin >> l;
    cin >> r;
    
    cnt += r - l + 1;
  }
  
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;

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

int main() {
  int n, m; scanf("%d%d", &n, &m);
  int a[n+m], b[n+m];
  vector<int> edges[n], redges[n];
  for (int i = 0; i < n+m-1; ++i) {
    scanf("%d%d", a+i, b+i); a[i]--; b[i]--;
    edges[a[i]].push_back(b[i]);
    redges[b[i]].push_back(a[i]);
  }
  int root;
  for (int i = 0; i < n; ++i) {
    if (redges[i].size() == 0) root = i;
  }
  vector<int> ans(n);
  vector<int> cnt(n);
  queue<pii> q;
  q.push(make_pair(root, -1));
  while(q.size()) {
    int node = q.front().first;
    int prev = q.front().second;
    q.pop();
    cnt[node]++;
    //printf("node:%d cnt:%d/%lu prev:%d\n", node, cnt[node], redges[node].size(), prev);
    if (cnt[node] == redges[node].size() || node == root) {
      ans[node] = prev;
    } else {
      continue;
    }
    for (int i = 0; i < edges[node].size(); ++i) {
      int next = edges[node][i];
      q.push(make_pair(next, node));
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i == root) printf("%d\n", 0);
    else {
      printf("%d\n", ans[i] + 1);
    }
  }
  return 0;
}


Measured memory_bytes: 13312
/** omgursocute **/
#include <bits/stdc++.h>

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;

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

	int n;
	cin >> n;

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

	bool ok = 1;
	for(int i = n-1; i > 0; i--) {
		if(a[i-1] <= a[i]) continue;
		else {
			a[i-1]--;
			if(a[i-1] == a[i]) continue;
          	ok = 0;
		}
	}

	cout << ((ok) ? "Yes" : "No");

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms.\n";
}

// g++ o .cpp -O2 -std=c++11 -D cute -Wall -Wno-unused-result



Measured memory_bytes: 640
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

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

    vector<int> h(N);
    REP(i, N)
    {
        cin >> h.at(i);
    }

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

    int ans = pow(10, 9);
    REP(i, N - K + 1)
    {
        int hh = h.at(K + i - 1) - h.at(i);
        ans = min(ans, hh);
    }

    cout << ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, ans = 0;
	vector<int> a;
	vector<bool> check;	// i番目のボタンを押したかどうか
	
	cin >> n;
	for(int i = 0; i < n; i++){
		int tmp_a;
		cin >> tmp_a;
		a.push_back(tmp_a);
		check.push_back(false);
	}
	
	int idx = 0;	// 次に光るボタンの番号
	while(!check[idx]){
		if(idx == -1)	idx = 0;
		ans++;
		check[idx] = true;
		idx = a[idx] - 1;
		if(idx == 1){
			cout << ans << endl;
			return 0;
		}
	}
	
	cout << -1 << endl;
}

Measured memory_bytes: 3872
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
ll n,m,l;
vector<vector<pair<ll,ll>>> edges(400);
vector<vector<bool>> reals(400, vector<bool>(400,false));
vector<vector<ll>> costs(400, vector<ll>(400,-1));

void saiki(ll from, ll now, ll gas){
    for (auto e : edges[now]) {
        ll to = e.first;
        ll cost = e.second;
        if(cost <= gas && gas-cost > costs[from][to]){
            reals[from][to] = true;
            costs[from][to] = gas-cost;
            saiki(from, to, gas-cost);
        }
    }
}

int main() {
    
    std::cin >> n>>m>>l;
    
    for (int i = 0; i < m; i++) {
        ll a,b,c;
        std::cin >> a>>b>>c;
        a--;b--;
        edges[a].push_back({b,c});
        edges[b].push_back({a,c});
    }
    
    for (int i = 0; i < n; i++) {
        priority_queue<pair<ll,ll>> que;
        que.push({l,i});
        while(!que.empty()){
            auto qt = que.top();que.pop();
            ll now = qt.second;
            ll gas = qt.first;
            
            for (auto e : edges[now]) {
                ll to = e.first;
                ll cost = e.second;
                if(cost <= gas && gas-cost > costs[i][to]){
                    reals[i][to] = true;
                    costs[i][to] = gas-cost;
                    que.push({gas-cost,to});
                }
            }
        }
    }
    
    vector<vector<ll>> dis(400,vector<ll>(400, 1e18));
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if(i==j){
                dis[i][j] = 0;
            }else if(reals[i][j]){
                dis[i][j] = 1;
                // std::cout << i<< " "<<j << std::endl;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]);
                // std::cout << dis[j][k] <<" "<<j<<" "<<k << std::endl;
            }
        }
    }
    
    ll q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        ll s,t;
        std::cin >> s>>t;
        s--;t--;
        if(dis[s][t] == 1e18){
            std::cout << -1 << std::endl;
        }else{
            std::cout << dis[s][t]-1 << std::endl;
        }
    }
    
    
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    cin >> N;
    ll res = 0;
    for (ll i=1; i<=N; ++i) res += i * (N - i + 1);
    for (int i=0; i<N-1; ++i) {
        ll a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        res -= a * (N - b + 1);
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3644
using System;

class Program
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		if (n > 1) {
			var power = 1L;
			var max = (long)Math.Pow(10, 9) + 7L;
			for (var i = 2; i <= n; ++i) {
				power = power * i % max;
			}

			Console.WriteLine(power);
		} else {
			Console.WriteLine(1);
		}

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 17932
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll poc(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int u=n%10;
    int c[10]={1,1,0,2,0,0,1,0,1,0};
    if(c[u]==0)cout<<"hon"<<endl;
    else if(c[u]==1)cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
}


Measured memory_bytes: 3608
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *A = map(int, read().split())

A = [0] + A
answer = 0
for i in range(1, N + 1):
    if A[i - 1] and A[i]:
        answer += 1
        A[i] -= 1
    n, A[i] = divmod(A[i], 2)
    answer += n
print(answer)

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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll REM( ll a )
{
	a %= MOD;
	if ( a < 0 )
	   a += MOD;
	return a;
}

ll ADD( ll a, ll b )
{
	return REM( REM( a ) + REM( b ) );
}

ll SUB( ll a, ll b )
{
	return REM( REM( a ) - REM( b ) );
}

ll MUL( ll a, ll b )
{
	return REM( REM( a ) * REM( b ) );
}

ll POT( ll n, ll k )
{
	if ( k == 0 )
		return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 )
		return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
	return MUL( a, POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
	for ( ll i = 2;i <= sqrt( x ); i++ )
		if ( x % i == 0 )
			return false;
	return true;
}

string s;
int n;

int main()
{
	cin >> s;
	n = s.size();
	int sol = 0;
	FOR( i, 0, n / 2 )
	{
		if ( s[ i ] != s[ n - i - 1 ] )
			sol++;
	}
	
	cout << sol << "\n";
	return 0;
}


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

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

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int a, b, c; cin>>a>>b>>c;
    if(a % (b+c) >= c) cout << a / (b+c) << endl;
    else cout << (a / (b+c)) - 1 << endl;
}

Measured memory_bytes: 256
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))

def main():
  a,b,n=ints()
  flr=lambda a,b,x:floor(a*x/b)-a*floor(x/b)
  if n>=b:
    print(flr(a,b,b-1))
  else:
    print(flr(a,b,n))

if __name__ == '__main__':
    main()

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a > b){
        if(a > c){
            cout << b + c << endl;
        }else{
            cout << a + b << endl;
        }
    }else{
        if(b > c){
            cout << a + c << endl;
        }else{
            cout << a + b << endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int MAX_N = 105;
int B[MAX_N];

int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N-1; ++i)
	{
		cin >> B[i];
	}

	int ans = 0;

	ans += B[N-2];

	for (int i = N-2; i > 0; --i)
	{
		ans += min(B[i],B[i-1]);
	}

	ans += B[0];
	cout << ans << endl;
	return 0;
}

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

int main(void){
  int N;
  cin >> N;
  vector<int> color(9);
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    if(a>=3200) color.at(8)++;
    else{
      int b=a/400;
      color.at(b)++;
    }
  }
  int mini=8;
  for(int i=0;i<8;i++) if(color.at(i)==0) mini--;
  int maximum=mini+color.at(8);
  if(mini==0) mini++;
  cout << mini << " " << maximum << endl;
}

Measured memory_bytes: 256
gcd_mp = {}

def gcd(a, b):
    global gcd_mp
    key = tuple(sorted([a, b]))
    if key not in gcd_mp:
        while b:
            a, b = b, a % b
        gcd_mp[key] = a
    return gcd_mp[key]

K = int(input())

ab_gcd = {}

for a in range(1, K + 1):
    for b in range(1, K + 1):
        val = gcd(a, b)
        if val not in ab_gcd:
            ab_gcd[val] = 0
        ab_gcd[val] += 1

total = 0

for key, val in ab_gcd.items():
    for c in range(1, K + 1):
        total += gcd(key, c) * val

print(total)

Measured memory_bytes: 10960
n = int(input())
a = [0 for _ in range(n)]
for i in range(n):
	a[i] = int(input())
maxa = max(a)
basho = a.index(maxa)
a[basho] = 0
for i in range(n):
	if i != basho:
		print(maxa)
	else:
		print(max(a))

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

int main(){
  int n,x,a;
  cin >> n;
  x=0;
  a=0;
  string s;
  cin >> s;
  for(int i=0;i<n;i++){
    if(s.at(i)=='I'){
      x++;
    }else{
      x--;
    }
    if(a<x){
      a=x;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	string s;
	cin >> s;
	bool use[26] = {};
	REP(i,s.length()) use[s[i] - 'a'] = true;
	REP(i,26){
		if(use[i] == false){
			cout << (char)('a' + i) << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 512
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = []
for _ in range(n):
    d = list(map(int,input().split()))
    a.append(d)

ans = 0
for i in range(n):
    tmp = 0
    for j in range(m):
        tmp += b[j]*a[i][j]
    tmp += c
    if tmp > 0:
        ans += 1

print(ans)

Measured memory_bytes: 62236
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	int X, Y, Z; cin >> X >> Y >> Z;
	cout << Z << " " << X << " " << Y << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	static int [] inputA ;
	static int [] inputB ;
    static int K;
    static int N;
    static int flag;
    static int min;

	
	public static void main(String args[]) throws Exception{
		min=0;
		flag=0;
		Scanner sc = new Scanner(System.in);
		
	    N = sc.nextInt();
	    K = sc.nextInt();
	    inputA = new int[N];
	    inputB = new int[N];
	    int k1=0;
	    int k2=0;
	    
	    for(int i=0;i<N;i++){
	    	int x = sc.nextInt();
	    	if(x<=0) {
	    		inputA[k1++]=x;
	    		
	    	}else {
	    		inputB[k2++]=x;
	    	}
	    }
	    
	    
	    if(k1>0) {
	    	for(int i=0;i<k1;i++) {
	    		inputA[i]=0-inputA[i];
	    	}
	    }
	    
	    if(k1>0&&k2>0) {
	    	 if(inputA[0]>inputB[k2-1]) {
	 	    	min=2*inputA[0]+inputB[k2-1];
	 	    }else {
	 	    	min=inputA[0]+2*inputB[k2-1];
	 	    }
	    }
	    if(k1==0&&k2>0) {
	    	min=inputB[k2-1];
	    }
	    if(k2==0&&k1>0) {
	    	min=inputA[0];
	    }
	   
	    
	    findpath(k1,k2);
	    System.out.println(min);
	    sc.close();
	}
	
	
	public static void findpath(int l,int n) {
		if(flag==1) {
			return;
		}
		if(l>=K) {
			if(inputA[l-K]<min) {
				min=inputA[l-K];
			}
			if(n!=0) {
				findpath(K-1,n);
			}
		}
		if(l<K) {
			if(l==0&&n>=K) {
				if(inputB[K-1]<min) {
					min=inputB[K-1];
				}
			}else if(l==0&&n<K){
				flag=1;
			} else if(l>0&&K-l<=n) {
					int chg1 = 0;
					int chg2 = 0;
					chg1 = inputA[N-l-n];
					chg2 = inputB[K-l-1];
			        if(chg1>=chg2) {
			        	if(min>2*inputB[K-l-1]+inputA[N-l-n]) {
			        		min=2*inputB[K-l-1]+inputA[N-l-n];
			        	}
			        }else {
			        	if(min>inputB[K-l-1]+2*inputA[N-l-n]) {
			        		min=inputB[K-l-1]+2*inputA[N-l-n];
			        	}
			        }
					findpath(l-1,n);
			}
		}
	
	}

}


Measured memory_bytes: 62060
#include <stdio.h>

int main(void)
{
	int i = 0, num = 0, table[26] = {0};
char str[1200];
	
	scanf("%[^!]", str);

while (str[i]){
	if (str[i] >= 97 && str[i] <= 122){
	table[(int)str[i] - 97]++;
	num++;
	}
	if (str[i] >= 65 && str[i] <= 90){
	table[(int)str[i] - 65]++;
	num++;}
	i++;}
	
for (i=0; i<26; i++)
	printf("%c : %d\n", 97 + i, table[i]);

return 0;
}


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

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

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
int l[100005], r[100005], le[100005];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d%d", &l[i], &r[i]);
        le[i] = r[i]-l[i];
    }
    multiset<ll> L, R;
    L.insert(r[1]);
    R.insert(r[1]);
    ll ans = 0;

    ll sl = 0, sr = 0;
    for(int i=2;i<=n;i++){
        ll s = *L.rbegin()-sl-le[i-1], e = *R.begin()+sr+le[i];
        sl += le[i-1];
        sr += le[i];
        if(s <= r[i] && r[i] <= e){
            L.insert(r[i]+sl);
            R.insert(r[i]-sr);
        }
        else if(r[i] < s){
            ans += abs(s-r[i]);
            L.erase(--L.end());
            L.insert(r[i]+sl);
            L.insert(r[i]+sl);
            R.insert(s-sr);
        }
        else{
            ans += abs(e-r[i]);
            R.erase(R.begin());
            R.insert(r[i]-sr);
            R.insert(r[i]-sr);
            L.insert(e+sl);
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 10752
#include<stdio.h>
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<math.h>
#include<iomanip>

using namespace std;
using ll = long long int;

int n, k;

int main(void) {
	cin >> n >> k;
	long double ret = 0., tmp;
	for (int i = 1; i <= n; i++) {
		int win = ceil(log2(double(k) / i));
		tmp = pow(2, -1 * win);
		if (tmp > 1.)
			tmp = 1.;
		ret += tmp;
	}
	cout << setprecision(20) << ret / n << endl;
	return 0;
}

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

int n, W, w[100], v[100], memo[101][10001];
int rec(int i, int j) {
  if (memo[i][j] != -1) return memo[i][j];
  int res;
  if (i == n) res = 0;
  else if (j < w[i]) res = rec(i + 1, j);
  else res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]);

  return memo[i][j] = res;
}
int main() {
  cin >> n >> W;
  for (int i = 0; i < n; ++i) {
    cin >> v[i] >> w[i];
  }
  memset(memo, -1, sizeof(memo));
  cout << rec(0, W) << endl;
}

Measured memory_bytes: 7032
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  int num[100]={};
  int flag=0;
  std::cin >> a>>b>>c;

  for (int i = 0; ; i++) {
    if((a*i)%b==c){flag=1;break;}
    else{
      if(num[(a*i)%b]==1)break;
      else num[(a*i)%b]=1;
    }
  }

  if(flag==1)std::cout << "YES" << '\n';
  else std::cout << "NO" << '\n';

return 0;
}


Measured memory_bytes: 256
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }

fun main(args: Array<String>) {
    val (a, b) = readInts()

    val L = (1..999).map { (it * (1 + it)) / 2 }.toList()
    println((1..499500).first { depth ->
        val indexOfA = L.indexOf(a + depth)
        val indexOfB = L.indexOf(b + depth)

        return@first indexOfA != -1 && indexOfB == indexOfA + 1
    })
}

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

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

int main() {
	int x;
	cin >> x;
	while (!is_prime(x)) {
		x++;
	}
	cout << x << '\n';
	return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    cout << fixed << setprecision(10);
    ll n,k,s;
    cin >> n >> k >> s;
    vector<int> v(n);
    rep(i,n){
        if(i < k) v[i] = s;
        else if(s < 1e9) v[i] = s + 1;
        else v[i] = s - 1;
    }
    rep(i,n) cout << v[i] << endl;
    return 0;
}

Measured memory_bytes: 3656
H,W = gets.split.map(&:to_i)

A = []
q = []
H.times do |y|
  s = gets.chomp
  A << Array.new(W) do |x|
    if s[x] == '#'
      q << [x,y]
      0
    else
      -1
    end
  end
end

ans = 0
while q.size > 0
  x,y = q.shift

  ans = A[y][x] + 1

  q << [x-1, y].tap {|x,y| A[y][x] = ans } if x-1 >= 0 && A[y][x-1] < 0
  q << [x+1, y].tap {|x,y| A[y][x] = ans } if x+1 < W  && A[y][x+1] < 0
  q << [x, y-1].tap {|x,y| A[y][x] = ans } if y-1 >= 0 && A[y-1][x] < 0
  q << [x, y+1].tap {|x,y| A[y][x] = ans } if y+1 < H  && A[y+1][x] < 0
end
puts ans - 1


Measured memory_bytes: 87164
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int n,ans=1;
int a[200000];
int cnt=0;
signed main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n-1){
        if(cnt==0){
            if(a[i+1]>a[i])cnt++;
            else if(a[i+1]<a[i])cnt--;
        }
        else if(cnt>0){
            if(a[i+1]<a[i]){
                ans++;
                cnt=0;
            }
        }
        else{
            if(a[i+1]>a[i]){
                ans++;
                cnt=0;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.util.Map.Entry;
 
 
 
public class Main{
	
	public int num;
	public int vol;
 
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd(long a, long b) {
		if (b == 0) {
			return a;			
		}
		return gcd(b, a % b);
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}
 
 
 
	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}
 
 
	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}
 
 
	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}
 
 
	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 String S=sc.next();
	 char[] c=S.toCharArray();
	 double K=sc.nextDouble();
	 double result = 0;
	 for(int i=0;i<c.length;i++) {
		
		result+=Math.pow(Character.getNumericValue(c[i]), 5000.0*1000000000000.0);
	    //System.out.println(result);
		if(result>=K) {
			System.out.println(Character.getNumericValue(c[i]));
			break;
		}
		 
	 }
	 
    
}
}

Measured memory_bytes: 24532
#include<iostream>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<limits.h>
#include<math.h>
using namespace std;

#define rep(i,M,N) for (int i = M; i <= N; i++)
#define rep1(i,M,N) for (int i = M; i >= N; i--)
#define getArray(a,n) rep(i,0,n-1) cin >> a[i];
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))

int main() {
    string s1,s2;
    int n;
    while(cin>>n>>s1>>s2){
        long len = n;
        rep(i, 0, n){
            if(s1.substr(i) == s2.substr(0,n-i)){
                len += i;
                break;
            }
        }
        cout<<len<<endl;

    }
    return 0;
}


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

#define INF 999999999
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long unsigned int ll;
using namespace std;

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

int dy[] = { 0, 0, 1, -1 };
int dx[] = { 1, -1, 0, 0 };


int main()
{
	int k, x;
	cin >> k >> x;

	int ans = k*500;

	if (ans >= x) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256