akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(unused_variables)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};
use std::collections::{HashSet, HashMap, BinaryHeap};

fn main() {
    input! {
        h1: isize,
        m1: isize,
        h2: isize,
        m2: isize,
        k: isize,
    }
    let ans = (h2 - h1) * 60 + (m2 - m1) - k;
    println!("{}", max(ans, 0));
}


Measured memory_bytes: 2136
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int s[2005], t[2005];

const LL M = (LL)1e9 + 7;

// r_fix[i][j] = 以 s 的第 i 個、 t 的第 j 個元素爲最右所構成的共同子串列數量
LL r_fix[2005][2005];
LL s_pre_t_fix[2005][2005];
LL s_fix_t_pre[2005][2005];
LL total[2005][2005];

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

    // 初始化
    // for (int i = 0; i <= n; i++) {
    //     total[i][0] = 1;
    // }
    // for (int i = 0; i <= m; i++) {
    //     total[0][i] = 1;
    // }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            // r_fix;
            if (s[i] == t[j]) {
                r_fix[i][j] = (total[i - 1][j - 1] + 1) % M;
            } else {
                r_fix[i][j] = 0;
            }
            s_fix_t_pre[i][j] = (s_fix_t_pre[i][j - 1] + r_fix[i][j]) % M;

            total[i][j] = (total[i - 1][j] + s_fix_t_pre[i][j]) % M;
        }
    }
    printf("%lld\n", total[n][m] + 1);
}


Measured memory_bytes: 97856
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int ans = 1e9;
    string s;
    cin>>s;
    rep(i,s.size()-2){
        ans = min(ans, abs(753 - ((s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0'))));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n,maxi=INT_MIN;
	cin>>n;
	for(ll i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			maxi=max(maxi,i);
		}
	}
	cout<<(maxi+n/maxi)-2;
}

Measured memory_bytes: 256
L, R = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7
for d in range(62):  # 最上位 bit
    # dp[n] := n 桁目まで見た時に条件を満たすものが何個あるか
    # dp_small[n] := n 桁目まで見た時に、l と x が n 桁目まで一致していて条件を満たすものが何個あるか
    l = max(1<<d, L)
    r = min((2<<d)-1, R)
    if l > r:
        continue
    dp_small = [0] * (d+2)
    dp_ok = [0] * (d+2)
    dp_large = [0] * (d+2)
    dp_small_large = [0] * (d+2)
    dp_small_large[0] = 1
    for n in range(1, d+2):
        i = d-n+1
        dp_ok[n] = dp_ok[n-1] * 3 \
                 + (dp_small[n-1] if l>>i&1==0 else 0) \
                 + (dp_large[n-1] if r>>i&1 else 0)
        dp_small[n] = dp_small[n-1] * (1 if l>>i&1 else 2) \
                    + (dp_small_large[n-1] if l>>i&1 < r>>i&1 else 0)
        dp_large[n] = dp_large[n-1] * (2 if r>>i&1 else 1) \
                    + (dp_small_large[n-1] if l>>i&1 < r>>i&1 else 0)
        dp_small_large[n] = dp_small_large[n-1] if l>>i&1 <= r>>i&1 else 0
    a = dp_ok[d+1] + dp_large[d+1] + dp_small[d+1] + dp_small_large[d+1]
    ans += a
    # print(f"d={d},a={a},l={l},r={r}")
    # print(f"dp_ok={dp_ok}")
    # print(f"dp_small={dp_small}")
    # print(f"dp_large={dp_large}")
    # print(f"dp_small_large={dp_small_large}")
    # print()
print(ans % mod)


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

using namespace std;

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

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

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

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

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

  cin >> a >> b >> c;
  if (a + b + c >= 22)
    Cout("bust");
  else
    Cout("win");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
#define long long int
int32_t main()
{
int n;
cin>>n;
int *a=new int[n];
int *b=new int[n];
int *c=new int[n];

for(int i=0;i<n;i++)
{
	cin>>a[i];
}
for(int i=0;i<n;i++)
{
	cin>>b[i];
}
for(int i=0;i<n-1;i++)
{
	cin>>c[i];
}
int sum=0;

for(int i=0;i<n-1;i++)
{
	sum+=b[a[i]-1];

	if(a[i+1]-a[i]==1)
	{
		
		sum+=c[a[i]-1];
	}
	else
	{
		
	}
}
sum+=b[a[n-1]-1];
cout<<sum<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map> 
using namespace std;

#define LL long long
#define MOD (1000000007)

//A
int main() {
	LL N;

	scanf("%lld", &N);




	double result = (double)((N + 1) / 2) / (double)N;

	printf("%0.9f\n", result);

	return 0;
}

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

using namespace std;

using ll = long long;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
    cin.tie(0);
    cout << fixed << setprecision(10);

    ll n, k; cin >> n >> k;
    deque<ll> dq;
    int now = 1;
    while(now * now <= n) {
      now++;
    }
    now--;
    for(;now >= 1; --now) {
      if(n / now == now) {
        dq.push_back(now); 
      } else {
        dq.push_back(now);
        dq.push_front(n/now);
      }
    }

    vector<ll> a;
    while(!dq.empty()) {
      a.push_back(dq.back());
      dq.pop_back();
    }

    // printv(a);

    int sz = a.size();
    vector<ll> d(sz);

    d[0] = 1;
    for(int i=1;i<sz;++i) {
      d[i] = a[i] - a[i-1];
    }

    // printv(d);

    vector<ll> dp(sz, 1);
    // printv(dp);
    vector<ll> su(sz);
    for(int i=0;i<k;++i) {
      // cout << endl;
      su[0] = dp[0];
      for(int j=1;j<sz;++j) {
        su[j] = su[j-1] + (dp[j] * d[j]) % MOD;
        su[j] %= MOD;
      }
      // printv(su);

      for(int j=0;j<sz;++j) {
        dp[j] = su[sz-j-1];
      }
      // printv(dp);
    }
    
    cout << su[sz-1] << endl;
    
}

Measured memory_bytes: 2936
#include<stdio.h>
int main() {
	int N, S;
	int zcnt = 0, sum = 0, min = 105, ans;
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &S);
		sum += S;
		if (S < min && S % 10 != 0)
		{
			min = S;
		}
	}
	if (sum % 10 == 0 && min != 105)
	{
		ans = sum - min;
	}
	else if (sum % 10 == 0 && min == 105)
	{
		ans = 0;
	}
	else
	{
		ans = sum;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
package main

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

type queue struct {
	data []int
}

func (q *queue) queue(v int) {
	q.data = append(q.data, v)
}

func (q *queue) front(v *int) bool {
	if len(q.data) == 0 {
		return false
	}
	*v = q.data[0]
	return true
}
func (q *queue) dequeue(v *int) bool {
	if len(q.data) == 0 {
		return false
	}
	*v = q.data[0]
	q.data = q.data[1:]
	return true
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	q := nextInt(sc)
	ans := make([]int, 0)
	queues := make([]queue, n)
	for i := 0; i < q; i++ {
		op := nextInt(sc)
		t := nextInt(sc)
		if op == 0 {
			x := nextInt(sc)
			queues[t].queue(x)
		} else if op == 1 {
			var v int
			if queues[t].front(&v) {
				ans = append(ans, v)
			}
		} else {
			var v int
			queues[t].dequeue(&v)
		}
	}
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < len(ans); i++ {
		fmt.Fprintf(wtr, "%d\n", ans[i])
	}
	wtr.Flush()
}



Measured memory_bytes: 10540
use proconio::input;

fn main() {
    input! {
        n: usize,
        s: [String; n],
    }
    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;
    for str in s.iter() {
        if str == "AC" {
            ac += 1;
        } else if str == "WA" {
            wa += 1;
        } else if str == "TLE" {
            tle += 1;
        } else {
            re += 1;
        }
    }
    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}


Measured memory_bytes: 7812
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define ff first
#define ss second
#define ll long long
#define mod 1000000007
#define pii pair<ll,ll>
#define vi vector<ll>
#define mii map<ll,ll>
#define pb push_back
#define mp make_pair
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) ll x; cin>>x; while(x--)
#define endl '\n'
void kehsihba(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
ll gcd(ll a,ll b){
	if(a==0){return b;}
	else
		return gcd(b%a,a);
}
int32_t main() {
	//kehsihba();
	ll n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				ans+=gcd(i,gcd(j,k));
			}
		}
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3584
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main() {
	long i,j = 0,ans = 1;
  int flag = 0;
  char S[200010];
	scanf("%s", S);
  for (i = 1; S[i] != '\0'; i++) {
    if (S[i - 1] == S[i]) {
      j++;
    }
    else if (j != 0) {
      ans -= (j + 2) / 3;
      if ((j + 3) % 3 == 1) {
        if (flag == 1) {
          ans++;
          flag = 0;
        }
        else {
          flag = 1;
        }
      }
      else if ((j + 3) % 3 == 2) {
        if (flag) {
        }
        else {
          flag = 0;
        }
      }
      else {
        flag = 0;
      }
      j = 0;
    }
    else {
      flag = 0;
    }
    ans++;
  }
  if (j != 0) {
    ans -= (j + 2) / 3;
    if ((j + 3) % 3 == 1) {
      if (flag == 1) {
        ans++;
      }
    }
  }
  printf("%d", ans);
	return 0;
}

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

using namespace std;

int num[105],ans[105];
bool in[105];

int main() {
  memset(in,1,sizeof(in));
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",&num[i]);
  for(int i=n;i>0;i--) {
  	int cur=0,s=0;
    for(int j=1;j<=n;j++)
      if (in[j]) {
      	s++;
      	if (num[j]==s) cur=j;
	  }
	if (cur&&num[cur]<=i) {
		ans[i]=num[cur];
		in[cur]=0;
	}
	else {
		puts("-1");
		return 0;
	}
  }
  for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class BIT:
    """ Binary Indexed Tree """

    def __init__(self, n):
        # 0-indexed
        n += 1
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加：添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        """ 区間和の取得 [l, r) """
        # 引数が1つなら一点の値を取得
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

N = INT()
A = LIST()

bit = BIT(N)
ans = 0
for i in range(N):
    # 自分より左にある、自分より小さな数の個数
    if bit.sum(A[i]) == 0:
        ans += 1
    bit.add(A[i], 1)
print(ans)


Measured memory_bytes: 25864
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>
#include <map>

using namespace std;

int main(){
	int n, v[100001], co[100001] = {}, ce[100001] = {}, mo = -1, me = -1, ans, i, j;
	int odd[2] = {}, even[2] = {};

	cin >> n;
	for (i = 0; i < n; ++i){
		cin >> v[i];
		if (i & 1)
			++co[v[i]];
		else
			++ce[v[i]];
	}

	for (i = 0; i < n; ++i){
		if (i & 1){
			if (co[v[i]] >= co[odd[0]]){
				if (odd[0] != v[i]){
					odd[1] = odd[0];
					odd[0] = v[i];
				}
			}
			else if (co[v[i]] >= co[odd[1]]){
				odd[1] = v[i];
			}
		}
		else{
			if (ce[v[i]] >= ce[even[0]]){
				if (even[0] != v[i]){
					even[1] = even[0];
					even[0] = v[i];
				}
			}
			else if (ce[v[i]] >= ce[even[1]]){
					even[1] = v[i];
			}
		}
	}

	if (odd[0] == even[0]){
		ans = n - max(co[odd[0]] + ce[even[1]], co[odd[1]] + ce[even[0]]);
	}
	else{
		ans = (n / 2) - co[odd[0]] + (n / 2) - ce[even[0]];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
class ExponentiationTable
  
  def initialize(x, mod = nil )
    @x = x
    @mod = mod
    @table = [x]
  end
  
  def pow(n)
    res = 1
    i = 0
    while n > 0
      if (n & 1) != 0
        res *= @table[i]
        res %= @mod if @mod
      end
      i += 1
      @table[i] ||= ( @mod ? @table[i-1] ** 2 % @mod : @table[i-1] ** 2 ) 
      n >>= 1
    end
    # p @table
    res
  end
end

mod = 1_000_000_007

gets

h = Hash.new{|h, k| h[k] = [0, 0] }
genten_iwashi = 0

$<.read.split.map(&:to_i).each_slice(2) do |(a,b)|

  if 0 == a | b
    genten_iwashi += 1
  else
    f = a.zero? || (a > 0 && b > 0) || (a < 0 && b < 0)
    r = ( f ? Rational(a,b) : -Rational(b,a) )
    h[r][ f ? 0 : 1 ] += 1
  end
end

ans = 1
heiwa_iwashi = 0
two = ExponentiationTable.new(2, mod)

h.values.each do |(s, t)|
  if s == 0 || t == 0
    heiwa_iwashi += (s + t)
  else
    ans *= ( two.pow(s) + two.pow(t) - 1)
    ans %= mod
  end
end
ans = ( ans * two.pow(heiwa_iwashi) ) % mod
ans = ( ans - 1 + genten_iwashi ) % mod

puts ans

Measured memory_bytes: 70736
A,B,C,X,Y = map(int,input().split())
tmp1 = A*X+B*Y
tmp2 = C*max(X,Y)*2
if X<Y:
  tmp3 = C*X*2+B*(Y-X)
else:
  tmp3 = C*Y*2+A*(X-Y)
print(min(tmp1,tmp2,tmp3))

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int n,a,b;
	int pointa,pointb;
	int i;
	
	
	for(;;){
	pointa = 0;
	pointb = 0;
	
	scanf("%d",&n);
	if(n==0) break;
	 for(i=0;i<n;i++){
	 	scanf("%d %d",&a,&b);
	 	if(a>b){
	 		pointa += a+b;
	 	}else if(a<b){
	 		pointb += a+b;
	 	}else if(a == b){
	 		pointa += a;
	 		pointb += b;
	 	}
	 }
	 printf("%d %d\n",pointa,pointb);
	}
return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}	
};


    
int main(){
	string s, t; cin>> s >>t;
	int a, b; cin>> a >> b;
	string u; cin>> u;
	if(s.compare(u) == 0)
		cout<< a- 1<<" "<<b;
	else
		cout<<a <<" "<<b-1;
	
	return 0;
}













Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int n,i,j,r,t;(n=s.nextInt())>0;System.out.println(r))for(i=r=0;i<54;++i)for(j=1;--j<96;)if((t=i*i*i+j*++j*++j/6)<=n)r=r>t?r:t;}}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
 
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define ll long long   
 
const ll mod=1e9+7;
 
int main()
{
  ll m;
  sfl(m);
   m=24-m;
  m=m+24;
  cout<<m<<endl;
  
 
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
void bfs(vector<vector<long long>> &G, vec &dist, ll s)
{
    queue<ll> que;
    dist[s] = 0;
    que.push(s);
    while (!que.empty())
    {
        ll v = que.front();
        que.pop();
        for (auto next_v : G[v])
        {
            if (dist[next_v] != -1)
                continue;
            dist[next_v] = dist[v] + 1;
            que.push(next_v);
        }
    }
}
int main()
{
    cout << fixed << setprecision(30);
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> G(3 * N);
    loop(i, M)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b + N);
        G[a + N].push_back(b + 2 * N);
        G[a + 2 * N].push_back(b);
    }
    ll S, T;
    cin >> S >> T;
    S--;
    T--;
    vector<ll> dist(3 * N, -1);
    bfs(G, dist, S);
    if (dist[T] != -1)
        putout(dist[T] / 3);
    else
        putout(-1);
    return 0;
}


Measured memory_bytes: 21932
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)

	sc.Scan()
	s := strings.Split(sc.Text(), " ")
	r, _ := strconv.Atoi(s[0])
	c, _ := strconv.Atoi(s[1])

	t := make([][]int, r+1)
	for i := range t {
		t[i] = make([]int, c+1)
	}

	for i := 0; i < r; i++ {
		sc.Scan()
		s := strings.Split(sc.Text(), " ")
		for j := 0; j < c; j++ {
			t[i][j], _ = strconv.Atoi(s[j])
		}
	}

	for i := 0; i < r; i++ {
		for j := 0; j < c; j++ {
			t[i][c] += t[i][j]
		}
	}

	for i := 0; i < c+1; i++ {
		for j := 0; j < r; j++ {
			t[r][i] += t[j][i]
		}
	}

	for _, row := range t {
		for j, v := range row {
			if j == len(row)-1 {
				fmt.Printf("%d", v)
			} else {
				fmt.Printf("%d ", v)
			}
		}
		fmt.Println()
	}
}



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

#define int long long
typedef long double ld;

const int N = 10 + 5;
int n, d, ans, ar[N][N];

bool check(int x, int y) {
	int res = 0;
	for (int i = 0; i < d; i++)
		res += (ar[x][i] - ar[y][i]) * (ar[x][i] - ar[y][i]);
	return (ld)sqrt((ld)res) == (int)sqrt((int)res);
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> d;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < d; j++)
			cin >> ar[i][j];
	
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			if (check(i, j))
				ans++;
	cout << ans << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int a, b;
    cin >> a >> b;
    int ans = 0;
    if(a < b){
        ans += b;
        b--;
    }else{
        ans += a;
        a--;
    }
    if(a < b){
        ans += b;
        b--;
    }else{
        ans += a;
        a--;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
const int maxn=200002;
int id[maxn];
int n;

int main()
{
	scanf("%d",&n);
	for(int i=1,x;i<=n;i++)
		scanf("%d",&x),id[x]=i;
	int ans=0,now=0;
	for(int i=1;i<=n;i++)
	{
		if(id[i]<id[i-1])
		{
			if(i!=1)	now=1;
			else		now=0;
		}
		else 	ans=max(ans,++now);
	}
	printf("%d",n-ans);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
int main(void)
{
	int i;
	char t[25],s[25];

	sscanf(fgets(t,sizeof(t),stdin),"%s",s);

	i = strlen(s) - 1;
	while(i >= 0){
		printf("%c",s[i--]);
	}
	printf("\n");
	return 0;
}

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

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0; i<h; ++i) cin >> s[i];
  vector<string> ans(h);
  for(int i=0; i<h; ++i) for(int j=0; j<w; ++j){
    if(s[i][j] == '#'){
      ans[i] += '#';
      continue;
    }
    char c = '0';
    if(i>0 && j>0 && s[i-1][j-1] == '#') ++c;
    if(i>0 && s[i-1][j] == '#') ++c;
    if(i>0 && j<w-1 && s[i-1][j+1] == '#') ++c;
    if(j>0 && s[i][j-1] == '#') ++c;
    if(j<w-1 && s[i][j+1] == '#') ++c;
    if(i<h-1 && j>0 && s[i+1][j-1] == '#') ++c;
    if(i<h-1 && s[i+1][j] == '#') ++c;
    if(i<h-1 && j<w-1 && s[i+1][j+1] == '#') ++c;
    ans[i] += c;
  }
  for(int i=0; i<h; ++i){
    cout << ans[i] << endl;
  }
}

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

template <typename T>
T gcd(T x, T y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

template <typename T>
T lcm(T x, T y)
{
    if (x == 0 || y == 0)
        return 0;
    return x / gcd(x, y) * y;
}

int main()
{
    const int N = 10;
    int H, W;
    cin >> H >> W;
    vector<vector<int>> c(N, vector<int>(N));
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            cin >> c[i][j];

    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                if (c[i][j] > c[i][k] + c[k][j])
                    c[i][j] = c[i][k] + c[k][j];

    int ans = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            int A;
            cin >> A;
            if (A >= 0)
                ans += c[A][1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, w;
    cin >> n >> w;
    long long int dp[n][w+1], wt[n], v[n];
    long long int ans = 0;
    for(int i = 0; i < n; i++) {
        cin >> wt[i] >> v[i];
    }
    memset(dp, 0, sizeof(dp));
    if(wt[0] <= w) {
        dp[0][wt[0]] = v[0];
        ans = v[0];
    }
    for(int i = 1; i < n; i++) {
        for(int j = 0; j <= w; j++) {
            dp[i][j] = dp[i-1][j];
            if(j >= wt[i])
            dp[i][j] = max(dp[i][j], v[i]+ dp[i-1][j-wt[i]]);
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
}


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

void Main() {
  int n;
  cin >> n;
  long long h[n];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  for (int i = 1; i < n; i++) {
    if (h[i] - 1 >= h[i - 1]) {
      h[i] -= 1;
    }
    if (h[i] < h[i - 1]) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <cmath>
using namespace std;

int main() {
  int n; cin >> n;
  map<pair<int, int>, int> mp;
  long long ans = 0;
  for(int i = 0; i < n; i++) {
    double num; cin >> num;
    long long x = llround(num*1e9);

    int two = 0, five = 0;
    while(x % 2 == 0) two++, x /= 2;
    while(x % 5 == 0) five++, x /= 5;
    for(auto p: mp) {
      if(p.first.first+two >= 18 && p.first.second+five >= 18) ans += p.second;
    }
    mp[make_pair(two, five)]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3716
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
using namespace std;

int INF = 1e9 + 7;

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

vector<int> p(200010), q(200010);

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
		q[p[i]] = i;
	}

	int sum = 0, ans = 0;
	for (int i = 1; i < n; i++) {
		if (q[i] < q[i + 1]) {
			sum++;
		}
		else {
			sum = 0;
		}
		ans = max(ans, sum);
	}
	cout << n - ans - 1 << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    
    int result[n];
    int input[n];
    int c = 0;
    for(int i=0; i<n; i++) {
        scanf("%d", &input[i]);
    }
    
    for(int i=0; i<n; i++) {
        c = input[i];
        result[c] = (i+1);
    }
    
     for(int i=1; i<=n; i++) {
        printf("%d ", result[i]);
    } 

    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(15);
    ll N, M, X;
    cin >> N >> M >> X;
    vector<ll> A(M);
    bool flag = false;
    int zen = 0;
    int kou = 0;
    for (int i = 0; i < M; i++)
    {
        cin >> A[i];
        if(A[i] < X){
            zen += 1;
        }
        else{
            kou += 1;
        }
    }
    cout << min(zen, kou) << endl;

}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int H,W,K;
char t[1001][1001],ch;
int J[1001][1001];
int O[1001][1001];
int I[1001][1001];
int ay,ax,by,bx;
int main(){
  scanf("%d %d %d",&H,&W,&K);
  scanf("%c",&ch);
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      scanf("%c",&t[i][j]);
      J[i][j]=(t[i][j]=='J'?1:0)+J[i-1][j]+J[i][j-1]-J[i-1][j-1];
      O[i][j]=(t[i][j]=='O'?1:0)+O[i-1][j]+O[i][j-1]-O[i-1][j-1];
      I[i][j]=(t[i][j]=='I'?1:0)+I[i-1][j]+I[i][j-1]-I[i-1][j-1];
    }
    scanf("%c",&ch);
  }
  for(int i=0;i<K;i++){
    scanf("%d %d %d %d",&ay,&ax,&by,&bx);
    printf("%d ",J[by][bx]-J[ay-1][bx]-J[by][ax-1]+J[ay-1][ax-1]);
    printf("%d ",O[by][bx]-O[ay-1][bx]-O[by][ax-1]+O[ay-1][ax-1]);
    printf("%d\n",I[by][bx]-I[ay-1][bx]-I[by][ax-1]+I[ay-1][ax-1]);
  }
  
  return 0;
}

Measured memory_bytes: 13736
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
int grid[50][50][50][50] = {};
void solve(){
	while (true) {
		int h, w;
		cin >> w >> h;
		if (w == 0) return;
		vector<string> inputs[2];
		REP(i, h) {
			REP(j, 2) {
				string a;
				cin >> a;
				inputs[j].push_back(a);
			}
		}
		queue<pair<pair<int, int>, pair<int, int>>> next;
		REP(i, h) {
			REP(q, w) {
				REP(j, h) {
					REP(t, w) {
						grid[i][q][j][t] = 0;
						if (inputs[0][i][q] == 'L' && inputs[1][j][t] == 'R') {
							next.push(mp(mp(i, q), mp(j, t)));
						}
						int cnt = 0;
						if (inputs[0][i][q] == '%') {
							cnt++;
						}
						if (inputs[1][j][t] == '%') {
							cnt++;
						}
						if (cnt == 1) {
							grid[i][q][j][t] = 1;
						}
					}
				}
			}
		}
		while (next.empty() == false) {
			pair<pair<int, int>, pair<int, int>> now = next.front();
			next.pop();
			int dx[4] = { 1,-1,0,0 };
			int dy[4] = { 0,0,1,-1 };
			REP(q, 4) {
				pair<int, int> a = now.first;
				pair<int, int> b = now.second;
				a.first += dx[q];
				a.second += dy[q];
				b.first += dx[q];
				b.second += -1 * dy[q];
				if (!(a.first >= 0 && a.first < h && a.second >= 0 && a.second < w)) {
					a.first -= dx[q];
					a.second -= dy[q];
				}
				if (!(b.first >= 0 && b.first < h && b.second >= 0 && b.second < w)) {
					b.first -= dx[q];
					b.second -= -1 * dy[q];
				}
				if (inputs[0][a.first][a.second] == '#') {
					a.first -= dx[q];
					a.second -= dy[q];
				}
				if (inputs[1][b.first][b.second] == '#') {
					b.first -= dx[q];
					b.second -=  -1 * dy[q];
				}
				if (grid[a.first][a.second][b.first][b.second]) continue;
				grid[a.first][a.second][b.first][b.second] = 1;
				next.push(mp(a, b));
			}
		}

		REP(i, h) {
			REP(q, w) {
				REP(j, h) {
					REP(t, w) {
						if (inputs[0][i][q] == '%' && inputs[1][j][t] == '%') {
							if (grid[i][q][j][t] == 1) {
								cout << "Yes" << endl;
							}
							else {
								cout << "No" << endl;
							}
							goto goi;
						}
					}
				}
			}
		}
	goi:;
	}
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 53680
#include<iostream>

#include<string>
using namespace std;



int main (void){
  string S;
  cin >>S;
  for(int i=0;i<3;i++){
    if(S[i]=='1'){
      S[i]='9';
    }else if(S[i]='9'){
      S[i]='1';
    }
  }

  cout <<S<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const int MOD = 1000000007;
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(void) {
    int n, q,p; string s; cin >> n >> s >> q;
    vector<set<int>> st(26);
    rep(i, n)  st[s[i] - 'a'].insert(i);
    rep(i, q) {
        cin >> p;
        if (p == 1) {
            int t; char c;
            cin >> t >> c; t--;
            st[s[t] - 'a'].erase(t);
            s[t] = c;
            st[c - 'a'].insert(t);
        }
        else {
            int l, r,cnt = 0;
            cin >> l >> r; l--; r--;
            rep(j, 26) {
                auto it = st[j].lower_bound(l);
                if (it != st[j].end() && *it <= r) cnt++;
            }cout << cnt << endl;
        }
    }
}

Measured memory_bytes: 27256
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

int main()
{
    int n, i;
    cin >> n;

    vector <int> v(n);
    for(i = 0; i < n; i ++)
    {
    	cin >> v[i];
    }
    vector <int> prefix(n + 1, 0);
    vector <int> suffix(n + 1, 0);
    suffix[n - 1] = v[n - 1];
    prefix[0] = v[0];

    for(i = 1; i < n; i ++)
    	prefix[i] = prefix[i - 1] + v[i];

    for(i = n - 2; i > 0; i --)
    	suffix[i] = suffix[i + 1] + v[i];

    int minAns = 99999999;
    for(i = 0; i < n - 1; i ++)
    {
    	// cout << prefix[i] << " " << suffix[i + 1] << endl;
    	minAns = min(minAns, abs(suffix[i + 1] - prefix[i]));
    }
    cout << minAns << endl;
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (1) {
		c -= b;
		if (c <= 0) {
			ps(Yes);
			break;
		}
		a -= d;
		if (a <= 0) {
			ps(No);
			break;
		}
	}

	return(0);
}

Measured memory_bytes: 3516
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  Node node;

  foreach (_; n.iota) {
    auto rd = readln.chomp.splitter(' '), cmd = rd.front;
    switch (cmd) {
    case "insert":
      rd.popFront;
      node.insert(rd.front.to!int);
      break;
    case "find":
      rd.popFront;
      writeln(node.find(rd.front.to!int) ? "yes" : "no");
      break;
    case "print":
      node.inorderWalk;
      writeln;
      node.preorderWalk;
      writeln;
      break;
    default:
      assert(0);
    }
  }
}

void writeArray(T)(T[] ai)
{
  foreach (a; ai) write(" ", a);
  writeln;
}

void insert(ref Node node, int val)
{
  Node par, cur = node;
  while (cur !is null) {
    par = cur;
    if (val < cur.key) cur = cur.l;
    else cur = cur.r;
  }

  Node chi = new Node(val);
  if (par is null)
    node = chi;
  else if (val < par.key)
    par.l = chi;
  else
    par.r = chi;
}

bool find(Node node, int val)
{
  if (node.key == val) {
    return true;
  } else if (node.key > val) {
    if (node.l is null) return false;
    else return node.l.find(val);
  } else {
    if (node.r is null) return false;
    else return node.r.find(val);
  }
}

void inorderWalk(Node node)
{
  if (node.l !is null) inorderWalk(node.l);
  write(" ", node.key);
  if (node.r !is null) inorderWalk(node.r);
}

void preorderWalk(Node node)
{
  write(" ", node.key);
  if (node.l !is null) preorderWalk(node.l);
  if (node.r !is null) preorderWalk(node.r);
}

class Node
{
  int key;
  Node l, r;

  this(int key)
  {
    this.key = key;
  }
}

Measured memory_bytes: 32252
#include <iostream>
#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>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<int, int>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

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

const int mod = 1000000007;

const int MAX_V = 100005;
vector<int> G[MAX_V];

int d[2][MAX_V];

void calcDiff(int tg, int next, int diff) {
  if(d[tg][next]) return;
  d[tg][next] = diff;
  for(int g: G[next]) {
    calcDiff(tg, g, diff+1);
  }
}

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

  int n;
  cin >> n;

  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  d[0][1] = INF;
  d[1][n] = INF;
  for(int g: G[1]) {
    calcDiff(0, g, 1);
  }
  for(int g: G[n]) {
    calcDiff(1, g, 1);
  }
  d[0][1] = 0;
  d[1][n] = 0;

  int res = 0;
  rep(i, n) {
    if (d[0][i+1] > d[1][i+1]) res--;
    else res++;
  }

  cout << (res > 0 ? "Fennec" : "Snuke") << endl;
}


Measured memory_bytes: 11136
def main():
    N, K = map(int, input().split())
    cnt = 0
    for b in range(1,N+1):
        cnt += (N // b) * max(0, b - K)
        cnt += max(0, (N % b) + 1 - K)

    if K == 0:
        cnt -= N

    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 39408
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;

int main() {
  int n;
  cin >> n;
  if(n%2==0){
    cout << n << endl;
  }else{
    cout << 2*n << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	int a,b;
	cin>>s>>t>>a>>b;
	string u;
	cin>>u;
	if(u==s)
		cout<<a-1<<' '<<b<<endl;
	else	
		cout<<a<<' '<<b-1<<endl;	
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
	int n, i, j;
	cin >> n;
	vi what(n + 1, -1);
	cout << 0 << endl;
	string ans;
	cin >> ans;
	if (ans == "Vacant") {
		return 0;
	}
	else if (ans == "Male") {
		what[0] = what[n] = 1;
	}
	else {
		what[0] = what[n] = 2;
	}
	int left = 0, right = n;
	while (true) {
		int mid = (left + right) / 2;
		cout << mid << endl;
		cin >> ans;
		if (ans == "Vacant") {
			return 0;
		}
		else if (ans == "Male") {
			what[mid] = 1;
		}
		else {
			what[mid] = 2;
		}
		if (what[left] == what[right]) {
			if (what[mid] == what[left]) {
				if ((right - mid) % 2 == 1) {
					left = mid;
				}
				else {
					right = mid;
				}
			}
			else {
				if ((mid - left) % 2 == 0) {
					right = mid;
				}
				else {
					left = mid;
				}
			}
		}
		else {
			if (what[left] == what[mid]) {
				if ((mid - left) % 2 == 1) {
					right = mid;
				}
				else {
					left = mid;
				}
			}
			else {
				if ((right - mid) % 2 == 1) {
					left = mid;
				}
				else {
					right = mid;
				}
			}
		}
	}
}


Measured memory_bytes: 1236
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
for n in range(N):
    if B[n] > A[n]:
        B[n] = B[n] - A[n]
        cnt = cnt + A[n]
    else:
        cnt = cnt + B[n]
        continue

    if B[n] > 0:
        if A[n+1] >= B[n]:
            A[n+1] = A[n+1] - B[n]
            cnt = cnt + B[n]
        else:
            cnt = cnt + A[n+1]
            A[n+1] = 0


print(cnt)

Measured memory_bytes: 18476
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    long long a, b, c, d, n;
    long long cost = 0;
    cin >> a >> b >> c >> d >> n;
    long long l2, l1;
    l2 = min({a * 8, b * 4, c * 2, d});
    l1 = min({a * 4, b * 2, c});
    // cout << l2 << " " << l1 << endl;
    cost += (n / 2) * l2;
    n = n % 2;
    // cout << cost << endl;
    if (n == 0) {
        cout << cost << endl;
        return 0;
    }
    cost += l1;
    cout << cost << endl;
}

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

class Solution
{
    static void Main()
    {
        var N = long.Parse(Console.ReadLine());
        for (long h = 1; h <= 3500; h++)
        {
            for (long w = 1; w <= 3500; w++)
            {
                var numer = N * h * w;
                var denom = 4 * h * w - N * (w + h);
                if (denom > 0 && numer % denom == 0)
                {

                    long n = numer / denom;
                    if (4 * n * h * w == (n * w + w * h + n * h) * N)
                    {
                        Console.WriteLine($"{h} {n} {w}");
                        return;
                    }
                }
            }
        }
    }
}

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

int top, S[1000];

void push(int x){
	S[++top] = x;
}

int pop(){
	top--;
	return S[top + 1];
}

int main(){
	int a, b;
	top = 0;
	char s[100];

	while (scanf("%s", s) != EOF){
		if (s[0] == '+'){
			a = pop();
			b = pop();
			push(a + b);
		}
		else if(s[0]=='-'){
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*'){
			a = pop();
			b = pop();
			push(a*b);
		}
		else {
			push(atoi(s));
		}
	}

	printf("%d\n", pop());

	return 0;
}

Measured memory_bytes: 548
n,k=map(int,input().split())
x=[0]*(10**5+1)
for i in range(n):
    a,b=map(int,input().split())
    x[a]+=b
ans=0
for i in range(10**5+1):
    ans+=x[i]
    if ans>=k:
        print(i)
        break
        


Measured memory_bytes: 77108
n = int(input())
ls = []
for i in range(n):
    x,l = map(int,input().split())
    ls.append([x-l,l+x])
    
ls = sorted(ls, key=lambda x: x[1])
ans = n

for i in range(1,n):
    if ls[i][0] < ls[i-1][1]:
      ls[i][1] = ls[i-1][1]
      ans -=1
        
print(ans)


Measured memory_bytes: 92980
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int num(int n) {
  string s = to_string(n);
  int cnt = 0;
  rep(i, s.size()) {
    cnt += s[i] - '0';
  }
  return cnt;
}

int main() {
  int n;
  cin >> n;
  vector<int> b(n-1, 0), a(n);
  rep(i, n-1) {
    cin >> b[i];
  }
  a[0] = b[0], a[n-1] = b[n-2];
  for (int i = 1; i <= n-2; i++) {
    a[i] = min(b[i], b[i-1]);
  }
  int sum = 0;
  rep(i, n) sum += a[i];
  cout << sum << endl;
  return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> p(n);
    rep(i,n) cin >> p[i].second >> p[i].first;
    sort(p.begin(),p.end());
    ll t=0;
    rep(i,n){
        t += p[i].second;
        if(t > p[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1792