akhauriyash/Code-Regression huggingface dataset:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

judge = [0 for i in range(10**5+1)]
#素数リスト
n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):    #nのルート+1
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)
for num in primes:
    judge[num] = 1
area = [0 for i in range(10**5+1)]
for num in primes[1:]:
    if judge[(num+1)//2] == 1:
        area[num] = 1
Area = [0]
for num in area:
    Area.append(Area[-1]+num)
def sumArea(l,r):
    return Area[r] - Area[l]
q = ir()
for i in range(q):
    l,r = lr()
    print(sumArea(l,r+1))

Measured memory_bytes: 109540
<?php
$n = intval(fgets(STDIN));
$a = array_map("intval", explode(" ", trim(fgets(STDIN))));

$odd = 0;
$even = 0;

foreach($a as $num){
  if($num % 2 == 0){
    $even++;
  }else{
    $odd++;
  }
}

if($odd+$even == 1){
  echo "YES\n";
}elseif($odd == 0){
  echo "YES\n";
}elseif($odd % 2 == 0){
  echo "YES\n";
}else{
  echo "NO\n";
}

Measured memory_bytes: 16884
#include <stdio.h>
#include <math.h>

/* prototype declaration */
void sum_and_aver();

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

void sum_and_aver()
{
	int sum = 0, aver = 0, s_tmp, n_tmp, n = 0, cnt = 0;
	while(scanf("%d,%d", &s_tmp, &n_tmp)!=EOF){
		sum += s_tmp*n_tmp;
		n += n_tmp;
		cnt++;
	}
	aver = round(1.0*n/cnt);
	printf("%d\n",sum);
	printf("%d\n",aver);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
using namespace std;
#define ONE 1

int c[128];

void c2i(){
    c['i'] = 1;   c['x'] = 10;
    c['c'] = 100; c['m'] = 1000;
}

int main(){
    string s1,s2;
    int n;
    
    c2i();
    
    cin >> n;
    while(n--){
        int n1 = 0,n2 = 0,k;
        cin >> s1 >> s2;
        bool flg = false;
        for(int i = 0 ; i < s1.size() ; i++){
            if('0' <= s1[i] && s1[i] <= '9'){
                flg = true;
                k = s1[i] - '0';
                continue;
            }
            else{
                if(flg){
                    n1 += k*c[s1[i]];
                    flg = false;
                }
                else n1 += c[s1[i]];
            }
        }

        int l;
        for(int j = 0 ; j < s2.size() ; j++){
            if('0' <= s2[j] && s2[j] <= '9'){
                flg = true;
                l = s2[j] - '0';
                continue;
            }
            else{
                if(flg){
                    n2 += l*c[s2[j]];
                    flg = false;
                }
                else n2 += c[s2[j]];
            }
        }
        
        int sum = n1 + n2;
        
        int ans[4] = {0};
        while(sum){
            if(sum >= 1000){
                ans[0]++;
                sum -= 1000;
            }
            else if(sum >= 100){
                ans[1]++;
                sum -= 100;
            }
            else if(sum >= 10){
                ans[2]++;
                sum -= 10;
            }
            else{
                ans[3] = sum;
                sum = 0;
            }
        }

        char fig[4] = {'m','c','x','i'};
        for(int i = 0 ; i < 4 ; i++){
            if(ans[i] > ONE) cout << ans[i] << fig[i];
            else if(ans[i] == ONE) cout << fig[i];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define ll long long

set<int> c;
int main(){
  int N; cin>>N;
  c.insert(-1);
  c.insert(N);
  int a[N],b[N];
  ll cnt=0,cp;
  for(int i=0;i<N;i++){
    cin>>a[i];
    b[a[i]-1]=i;
  }
  for(int i=0;i<N;i++){
    auto s=c.upper_bound(b[i]);
    cp=(*s-b[i]); s--;
    cp*=(b[i]-*s);
    cnt+=(i+1)*cp;
    c.insert(b[i]);
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll MOD = 1000000007;
const int MAX = 1000000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main(){
    int N; cin >> N;
    string S; cin >> S;
    int sum=0;
    for(int i=0;i<N-2;i++){
        if(S[i]=='A'){
            if(S[i+1]=='B'){
                if(S[i+2]=='C'){
                    sum++;
                }
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 888
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b = LI()
    print(min(n * a, b))
    return

#B
def B():
    n, d = LI()
    x = LIR(n)
    a = list(itertools.combinations(range(n), 2))
    ans = 0
    for a1,a2 in a:
        b = 0
        for bi in range(d):
            b += (x[a1][bi] - x[a2][bi])** 2
        if float.is_integer(math.sqrt(b)):
            ans += 1
    print(ans)
    return

#C
def C():
    l, r = LI()
    ans = 2018
    if l // 2019 == r // 2019:
        for i in range(l, r + 1):
            for k in range(i+1, r + 1):
                ans = min(ans, (i * k) % 2019)
        print(ans)
    else:
        print(0)
    return

#D
def D():
    n = II()
    a = LI()
    
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  ll x;
  cin >> N >> x;

  vector<ll> v;
  ll ret = 0;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
    ret += a;
  }

  vector<ll> mn;
  rep(i,N){
    mn.push_back(v[i]);
  }
  rep(s,N){
    ll sum = 0;
    rep(i,N){
      sum += mn[i];
    }
    ret = min(ret, s*x + sum);

    int prev = (-s-1+N)%N;
    rep(i,N){
      mn[i] = min(mn[i], v[prev]);
      prev = (prev+1+N)%N;
    }
  }
  
  cout << ret << endl;
  
  return 0;
}




Measured memory_bytes: 256
def call(n):
    i = 1
    while True:
        x = i
        if x%3 == 0:
            print(f' {i}', end = '')
        else:
            while True:
                if x%10 == 3:
                    print(f' {i}', end = '')
                    break
                x //= 10
                if x == 0:
                    break
        i = i + 1
        if i > n:
            break
    print()

call(int(input()))


Measured memory_bytes: 5892
package main

import "fmt"

func main() {
  var a, b, x int

  fmt.Scanf("%d %d %d", &a, &b, &x)

  min := int(a/x) * x
  if min < a {
    min = min + x
  }
  if b < min {
    fmt.Println(0)
    return
  }
  d := ((b - min) / x) + 1

  fmt.Println(d)
}

Measured memory_bytes: 1832
#include <iostream>

using namespace std;

int gcd(int x, int y)
{
  if (y == 0) return x;
  return gcd(y, x % y);
}

int main()
{
  int X;
  cin >> X;
  
  int lcm = X * 360 / gcd(X, 360);
  cout << lcm / X << endl;
  
  return 0;
}

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

using namespace std;
typedef long long ll;

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

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

    int ans = 1;
    while ((ans << 1) <= n)
    {
        ans = ans << 1;
    }

    cout << ans << '\n';
    return (0);
}


Measured memory_bytes: 3612
#include <iostream>

using namespace std;
int main(){
	int d;
	cin>>d;
	string buf;
	string key="Hoshino";
	string newkey="Hoshina";
	unsigned int p;
getline(cin,buf);
	while(d--){
		getline(cin,buf);
		while((p=buf.find(key,0))!=string::npos){
			buf.replace(p,key.size(),newkey);
		}
		cout<<buf<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

int main(void) {
    char c; cin >> c;
    cout << (char)(c + 1) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define p 1000000007
#define N 200005

inline int add(int x, int y) { return (x += y) >= p ? x - p : x; }
inline int mul(int x, int y) { return (long long)x * y % p; }
inline int power(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = mul(ans, x); x = mul(x, x); } return ans; }

int sum[N], inv[N];

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    k = std::min(k, n);
    sum[n + 1] = 1;
    for (int i = n; i >= n - k; --i) sum[i] = mul(sum[i + 1], i);
    int fac = 1;
    for (int i = 1; i <= k; ++i) fac = mul(fac, i);
    inv[k] = power(fac, p - 2);
    for (int i = k; i; --i) inv[i - 1] = mul(inv[i], i);
    int invn = power(n, p - 2);
    int ans = 0;
    for (int i = 0; i <= k; ++i) ans = add(ans, mul(mul(sum[n - i + 1], inv[i]), mul(mul(sum[n - i], invn), inv[i])));
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1664
//ITNOA
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <iomanip>

using namespace std;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

#define rep(i, s, e) for(int i = s; i < e; i ++)
#define X first
#define Y second

typedef long long ll;
typedef long double ld;

const int maxN = 100*1000 + 5;
const int mod = 1000*1000*1000 + 7;
const int base = 701;
const int SQ = 500;
const int maxL = 20;


int a[maxN];

int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	string s; cin >> s;
	int k; cin >> k;

	int n = s.size(); 
	for(int i = 0; i < n; i ++)
	{
		if(s[i] == 'a') continue;

		int dif = 'z' - s[i] + 1;

		if(dif <= k)
		{
			k -= dif;
			s[i] = 'a';
		}
		else
			continue;
	}

	if(k > 0)
	{
		s[n-1] += k % 26;
		if(s[n-1] > 'z')
			s[n-1] -= 26;
	}

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


Measured memory_bytes: 592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.next();
		if (str.contains("a") && str.contains("b") && str.contains("c")) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

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

int main(){
    int n; cin>>n;
    
    long long int a[n];

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

    long long int count=0;

    for(int i=1;i<n;i++){
        if(a[i-1]>a[i]){
            count+=a[i-1]-a[i];
            a[i]=a[i-1];    
        }
    }

    cout<<count<<endl;
}

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

using ll = long long;

int H, W;
vector<string> S;

void solve(){
    int v = H * W;
    vector<vector<int>> table(v, vector<int>(v, v));
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            table[i * W + j][i * W + j] = 0;
            if(S[i][j] == '.') {
                if(i + 1 < H && S[i + 1][j] == '.') table[i * W + j][(i + 1) * W + j] = 1;
                if(i - 1 >= 0 && S[i - 1][j] == '.') table[i * W + j][(i - 1) * W + j] = 1;
                if(j + 1 < W && S[i][j + 1] == '.') table[i * W + j][i * W + j + 1] = 1;
                if(j - 1 >= 0 && S[i][j - 1] == '.') table[i * W + j][i* W + j - 1] = 1;
            }
        }
    }
    for(int k = 0; k < v; ++k){
        for(int i = 0; i < v; ++i){
            for(int j = 0; j < v; ++j){
                table[i][j] = min(table[i][j], table[i][k] + table[k][j]);
            }
        }
    }
    int max = 0;
    for(int i = 0; i < v; ++i){
        for(int j = 0; j < v; ++j){
            if(table[i][j] != v && max < table[i][j]) max = table[i][j];
        }
    }
    cout << max;
}

int main(){
    cin >> H >> W;
    S.resize(H);
    for(int i = 0; i < H; ++i){
        cin >> S[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, k;
int a[2000];
int mod = 1000000007;

signed main() {
	int i, j;
	
	cin >> n >> k;
	rep(i, n) cin >> a[i];
	
	int ans = 0;
	rep(i, n) {
		int x = 0, y = 0;
		rep(j, i) { if (a[j] > a[i]) x++; }
		rep(j, n) { if (a[j] > a[i]) y++; }
		ans += k * x % mod + y * ((k * (k - 1) / 2) % mod);
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.math.*

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    val aList = mutableListOf<Long>()
    
    for (i in 1..N) {
        aList.add(readInputLine().toLong())
    }
    
    val sortedArr = aList.sorted().toLongArray()
    
    var work = LongArray(N)
    
    var l = 0
    var r = N - 1
    
    for (i in 1..N - 2) {
        work[i] = sortedArr[if (i % 2 == 1) l++ else r--]
    }
    work[0] = sortedArr[l]
    work[N - 1] = sortedArr[r]

    var ans1 = 0L
    
    for (i in 1..N - 1) {
        ans1 += Math.abs(work[i] - work[i - 1])
    }
    
    work = LongArray(N)

    l = 0
    r = N - 1
    
    for (i in 1..N - 2) {
        work[i] = sortedArr[if (i % 2 == 1) r-- else l++]
    }
    work[0] = sortedArr[l]
    work[N - 1] = sortedArr[r]

    var ans2 = 0L
    
    for (i in 1..N - 1) {
        ans2 += Math.abs(work[i] - work[i - 1])
    }
    
    println(Math.max(ans1, ans2))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 50560
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=9;i++){
		if(n%i==0&&n/i<=9){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
}

Measured memory_bytes: 256
#include <stdio.h>

#define W 0
#define G 1
#define B 2
#define N 100

void dv(int);
void dfs();

int d[N], f[N], c[N];
int time, n;
int g[N][N];

int main(){
	int i, j, u, k, v;
	
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		for(j = 0; j < n; j++){
			g[i][j] = 0;
		}
	}
	
	for(i = 0; i < n; i++){
		scanf("%d%d", &u, &k);
		u--;
		for(j = 0; j < k; j++){
			scanf("%d",&v);
			v--;
			g[u][v] = 1;
		}
	}
	dfs();
	return 0;
}

void dfs(){
	int a;
	for(a = 0; a < n; a++){
		c[a] = W;
	}
	time = 0;
	
	for(a = 0; a < n; a++){
		if(c[a] == W) dv(a);
	}
	
	for(a = 0; a < n; a++){
		printf("%d %d %d\n", a+1, d[a], f[a]);
	}
}

void dv(int b){
	int k;
	
	c[b] = G;
	d[b] = ++time;
	
	for(k = 0; k < n; k++){
		if(g[b][k] == 0) continue;
		if(c[k] == W) dv(k);
	}
	
	c[b] = B;
	f[b] = ++time;
}

Measured memory_bytes: 636
#include <iostream>
#include <utility>
#include <stdint.h>
#include <string>
#include <vector>
#include <array>

using namespace std;

int main()
{
  string sN;
  cin >> sN;
  int K;
  cin >> K;

  vector<uint16_t> N;

  for (const char sn : sN) {
    N.push_back(sn-'0');
    cerr << N.back();
  }
  cerr << endl;
  
  vector<array<uint64_t,4>> DPsmall(N.size());
  vector<array<uint64_t,4>> DPsame(N.size());

  DPsmall[0][1] = N[0] - 1;
  DPsmall[0][2] = DPsmall[0][3] = 0;

  DPsame[0][1] = 1;
  DPsame[0][2] = DPsame[0][3] = 0;

  // {
  //   int n=0;
  //   cerr << DPsmall[n][1] << " " << DPsmall[n][2] << " " << DPsmall[n][3] << "    ";
  //   cerr << DPsame[n][1] << " " << DPsame[n][2] << " " << DPsame[n][3] << " ";
  //   cerr << endl;
  // }
  
  for (int n=1; n<N.size(); ++n) {
    DPsmall[n][1] = 9;
    
    DPsmall[n][1] += DPsmall[n-1][1];
    DPsmall[n][2] += DPsmall[n-1][1]*9 + DPsmall[n-1][2];
    DPsmall[n][3] += DPsmall[n-1][2]*9 + DPsmall[n-1][3];

    if (N[n] > 0) {
      DPsmall[n][1] += DPsame[n-1][1];
      DPsmall[n][2] += DPsame[n-1][1]*(N[n]-1) + DPsame[n-1][2];
      DPsmall[n][3] += DPsame[n-1][2]*(N[n]-1) + DPsame[n-1][3];
    }

    if (N[n] == 0) {
      DPsame[n][1] = DPsame[n-1][1];
      DPsame[n][2] = DPsame[n-1][2];
      DPsame[n][3] = DPsame[n-1][3];
    } else {
      DPsame[n][1] = DPsame[n-1][0];
      DPsame[n][2] = DPsame[n-1][1];
      DPsame[n][3] = DPsame[n-1][2];
    }

    // cerr << DPsmall[n][1] << " " << DPsmall[n][2] << " " << DPsmall[n][3] << "    ";
    // cerr << DPsame[n][1] << " " << DPsame[n][2] << " " << DPsame[n][3] << " ";
    // cerr << endl;
  }

  cout << DPsmall[N.size()-1][K] + DPsame[N.size()-1][K] << endl;
  
  return 0;
}


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

int main() {
	int N, M, C;
  	cin >> N >> M >> C;
  	int B[M];
  	int A[N][M];
  	for(int i = 0; i < M; i++) {
    	cin >> B[i];
    }
  	for(int i = 0; i < N; i++) {
    	for(int j = 0; j < M; j++) {
        	cin >> A[i][j];
        }
    }
  
  	int count = 0;
  	for(int i = 0; i < N; i++) {
      	int sum = 0;
    	for(int j = 0; j < M; j++) {
        	sum += A[i][j] * B[j];
        }
      	sum += C;
      	if(sum > 0) count++;
    }
  	cout << count << endl;
  
  
  	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define max 100
int main(void)
{
    int a;
    scanf("%d", &a);
    int s[max];
    for (int i = 0; i < max; i++)
    {
        s[i] = 0;
    }
    if (a == 0)
    {
        printf("%d\n", a);
        return 0;
    }

    int disit = 0;
    while (a != 1)
    {
        s[disit] = abs(a % (-2));
        a = (s[disit] - a) / 2;
        disit++;
    }
    s[disit] = a;

    while (disit >= 0)
    {
        printf("%d", s[disit]);
        disit--;
    }
    puts("");
    return 0;
}

Measured memory_bytes: 128
from collections import deque
S=input()
d=deque(S)
rev=False
Q=int(input())
for i in range(Q):
    Que=input()
    if(Que=='1'):
        rev=True if not rev else False
    else:
        T,F,C=map(str,Que.split())
        if(F=='1'):
            if(not rev):
                d.appendleft(C)
            else:
                d.append(C)
        elif(F=='2'):
            if(not rev):
                d.append(C)
            else:
                d.appendleft(C)
if(not rev):
    for i in range(len(d)):
        print(d[i],end='')
else:
    for i in reversed(range(len(d))):
        print(d[i],end='')


Measured memory_bytes: 93784
//2020 4.19 Doubly Linked List OK 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;
NodePointer nil;

NodePointer listSearch(int);
void init();
void printList();
void deleteNode(NodePointer);
void deleteFirst();
void deleteLast();
void delete();
void insert(int);

int main()
{
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }
  printList();
  return 0;
}

void insert(int key)
{
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

NodePointer listSearch(int key)
{
  NodePointer z;
  z = nil->next;
  /*while(1)
  {
  if(key==z->key) return z;
  if(z->next==nil) break;
  z = z->next;
  }*/
  while( z != nil && z->key != key )
  {
    z = z->next;
  }
  return z;
}

void delete(int key)
{
  deleteNode(listSearch(key));
}

void deleteFirst()
{
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast()
{
  deleteNode(nil->prev);
}

void deleteNode(NodePointer t)
{
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void init() //一番最初のやつ
{
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList()
{
  NodePointer cur = nil->next;
  int isf = 1;
  
  while(1)
  {
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MAX 1000010
#define MOD 1000000007
  
using ll = long long;
using Graph = vector<vector<pair<ll,ll>>>;

int main(){
  int n,k; cin>>n>>k;
  string s; cin>>s;
  int score = 0;
  rep(i,n-1){
    if(s.at(i)==s.at(i+1))score++;
  }
  int res = min(score+2*k,n-1);
  cout<<res<<endl;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray().Where(c => c== '1');
            Console.WriteLine(s.Count());

            Console.Read();
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int dp[31];

void Make_dp(void){

  dp[0] = dp[1] = 1;
  dp[2] = 2;
  for( int i = 3 ; i <= 30 ; i++ )
    dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];

}

int main(void){

  Make_dp();
  int n;
  while( cin >> n , n )
    cout << dp[n]/10/365 + 1 << endl;

  return 0;
}

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

int main() {
    int N, A, B;
    cin >> N >> A >> B; //1 ≤ N ≤ 20 , 1 ≤ A ≤ 50 , 1 ≤ B ≤ 50
    if (N*A < B) cout << N*A;
    else cout << B;
	return 0;
}

Measured memory_bytes: 3640
n,m = map(int,input().split())
x = [i for i in map(int,input().split())]

x.sort()
diff = []
for i in range(m-1):
    diff.append(x[i+1] - x[i])
diff.sort(reverse= True)
ans = sum(diff) - sum(diff[0:n-1])
print(ans)

Measured memory_bytes: 13832
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<map>
#include<set>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  vector<int>prime;
  prime.pb(6);
  for(int i=8;i<=310000;i+=7){
    bool flag=true;
    for(int j=0;prime[j]<=sqrt(i)&&j<prime.size();j++){
      if(i%prime[j]==0){
	flag=false;
	break;
      }
    }
    if(flag){prime.pb(i);}
    flag=true;
    for(int j=0;prime[j]<=sqrt(i+5)&&j<prime.size();j++){
      if((i+5)%prime[j]==0){
	flag=false;
	break;
      }
    }
    if(flag){prime.pb(i+5);}
  }
  sort(prime.begin(),prime.end());
  while(cin>>n,n!=1){
    set<int>ans;
    for(int i=0;i<prime.size()&&prime[i]<=n;i++){
      if(n%prime[i]==0){
	ans.insert(prime[i]);
      }
    }
    cout<<n<<":";
    for(set<int>::iterator i=ans.begin();i!=ans.end();*i++){
      if(*i!=0)
	cout<<" "<<*i;
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int n;
	cin >> n;
	vector<int>p(n);
	rep(i, n) {
		cin >> p[i];
	}
	sort(p.begin(), p.end(), greater<int>());
	int ans = -p[0]/2;
	rep(i, n) {
	 ans += p[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> A;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        A.push_back(a);
    }
    for(int j=0;j<n;j++){
        cout<<(j==0?"":" ")<<A[j];
    }
    cout<<endl;
    for(int i=1;i<n;i++){
        int key=A[i];
        int j;
        for(j=i-1;j>=0&&A[j]>key;j--)A[j+1]=A[j];
        A[j+1]=key;
        for(int k=0;k<n;k++){
            cout<<(k==0?"":" ")<<A[k];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3132
#include<iostream>
#include<stack>
#include<vector>
int main(){
	std::stack<int> st;
	std::vector<int> vec;
	int a=0;
	while(1){
		int n;
		std::cin>>n;
		if(std::cin.eof())break;
		if(n!=0)st.push(n);
		else vec.push_back(st.top()),a++,st.pop();
	}
	for(int i=0;i<a;i++)std::cout<<vec[i]<<std::endl;
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(int a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

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

ll INF = 10000000;
ll mod = 1000000007;


//番号ズレ注意！！
int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    REP(i, N) { cin >> d[i]; }
    sort(d.begin(), d.end());
    int l = N / 2 - 1;
    int r = N / 2;
    printAns(d[r] - d[l]);
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
int main()
{
int n;
cin>>n;
int k;
cin>>k;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int dp[n];
dp[0]=0;
dp[1]=abs(a[0]-a[1]);
for(int i=2;i<n;i++)
{
dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
for(int j=max(0,i-k);j<i;j++)
{
dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
}
}
cout<<dp[n-1]<<endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<string, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

struct UnionFind
{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (data[y] < data[x])
                swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x)
    {
        return -data[root(x)];
    }
};

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

    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++)
    {
        int s, t;
        cin >> s >> t;
        uf.unite(s, t);
    }
    int q;
    cin >> q;
    while (q--)
    {
        int s, t;
        cin >> s >> t;
        cout << (uf.find(s, t) ? "yes" : "no") << endl;
    }
}



Measured memory_bytes: 3300
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val x = sc.nextInt
    val y = sc.nextInt

    println(calcArea(x, y) + " " + calcPerimeter(x, y))
  }

  def calcArea(x: Int, y: Int): Int = x * y
  def calcPerimeter(x: Int, y: Int): Int = 2*x + 2*y
}

Measured memory_bytes: 44972
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input;
        input = new Scanner(System.in);
        int N = input.nextInt();
        Integer[] d = new Integer[N];
        for (int i = 0; i < N; i++){
            d[i] = input.nextInt();
        }
        Arrays.sort(d,Comparator.reverseOrder());
        int now = 0;
        int ans = 0;
        for (int i = 0; i < N; i++){
            if (now != d[i]){
                ans += 1;
                now = d[i];
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
using ii = pair<int, int>;

char mt[100][100];

int main(){
    int h, w;
    scanf("%d %d", &h, &w);
    for(int i=0; i<h; ++i)
        scanf("%s", mt[i]);
        
    int ans=0;
    for(int i=0; i<h; ++i)
        for(int j=0; j<w; ++j)
            if(mt[i][j]=='.') ++ans;        
    
    queue<pair<ii, int>> q;
    q.push({{0, 0}, 1});
    mt[0][0] = '#';
    while(not q.empty()){
        int i = q.front().ff.ff;
        int j = q.front().ff.ss;
        int tam = q.front().ss; 
        q.pop();
        if(i==h-1 and j==w-1){
            ans-=tam;
            printf("%d", ans);
            return 0;
        }
        if(i>0 and mt[i-1][j]=='.') // up
            q.push({{i-1, j}, tam+1}), mt[i-1][j] = '#';
        if(i<h-1 and mt[i+1][j]=='.') // down
            q.push({{i+1, j}, tam+1}), mt[i+1][j] = '#';
        if(j>0 and mt[i][j-1]=='.') // left
            q.push({{i, j-1}, tam+1}), mt[i][j-1] = '#';
        if(j<w-1 and mt[i][j+1]=='.') // right
            q.push({{i, j+1}, tam+1}), mt[i][j+1] = '#';
    }
    cout << -1 << endl;
}   


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long

using namespace std;

struct go
{
	int u, v;
};

signed main()
{
	int n;
	cin >> n;
	vector<go> a;
	if (n % 2)
	{
		for (int i = 1; i < n; i++)
			a.push_back({ n, i });
		for (int i = 1; i < n; i++)
		{
			for (int j = 1; j < n; j++)
			{
				if (j != i && n - j != i && i < j)
				{
					a.push_back({ i, j });
				}
			}
		}
		cout << a.size() << '\n';
		for (go i : a)
			cout << i.u << " " <<  i.v << "\n";
	}
	else
	{
		a.push_back({ n, n - 1 });
		for (int i = 3; i < n - 1; i++)
		{
			a.push_back({ i, n - 1 });
			a.push_back({ i, n });
		}
		a.push_back({ 2, n });
		a.push_back({ 1, n - 1 });
		for (int i = 1; i < n - 1; i++)
		{
			for (int j = 1; j < n - 1; j++)
			{
				if (i < j && i + j != n + 1)
				{
					a.push_back({ i, j });
				}
			}
		}
		cout << a.size() << "\n";
		for (go i : a)
			cout << i.u << " " << i.v << "\n";

	}
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();

		S = S.replaceAll("eraser", "-");
		S = S.replaceAll("erase", "-");
		S = S.replaceAll("dreamer", "-");
		S = S.replaceAll("dream", "-");
		S = S.replaceAll("-", "");

		if (S.length() == 0)
			System.out.println("YES");
		else
			System.out.println("NO");
	}

}

Measured memory_bytes: 29468
if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    from math import gcd
    from collections import Counter
    import itertools

    k = int(input())
    gcd_table = [[1]*k for _ in range(k)]
    for i in range(k):
        for j in range(k):
            gcd_table[i][j] = gcd(i+1, j+1)

    c = Counter(list(itertools.chain.from_iterable(gcd_table)))

    count = 0
    for key, value in c.items():
        count += sum(gcd_table[key-1])*value
    print(count)

     
"""
    n = int(input())
    count = 0
    for i in range(1, n+1):
        if i%3!=0 and i%5!=0:
            count += i
    print(int(count))
"""

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

int x[1000][10];
int n,a,c,d,e;
string T[3]={"root","internal node","leaf"};

void depth(int s,int r){
	if(s==-1){
		return;
	}
	x[s][4]=r;
	depth(x[s][0],r+1);
	depth(x[s][1],r+1);
}

int height(int s){
	int h1=0,h2=0;
	if(x[s][0]!=-1){
		h1=height(x[s][0])+1;
	}
	if(x[s][1]!=-1){
		h2=height(x[s][1])+1;
	}
	return x[s][5]=max(h1,h2);
}

int main(){
	memset(x,-1,sizeof(x));
	cin>>n;
	for(int i=0;i<n;i++){
		x[i][5]=0;
		x[i][6]=0;
		cin>>a>>d>>e;
		x[a][0]=d;
		x[a][1]=e;
		x[d][2]=a;
		x[e][2]=a;
		x[d][3]=e;
		x[e][3]=d;
	}
	for(int i=0;i<n;i++){
		if(x[i][2]==-1){
			c=i;
			break;
		}
	}
	depth(c,0);
	height(c);
	for(int i=0;i<n;i++){
		if(x[i][0]>=0){
			x[i][6]++;
		}
		if(x[i][1]>=0){
			x[i][6]++;
		}
	}
	for(int i=0;i<n;i++){
		if(i==c){
			x[i][7]=0;
		}
		else if(x[i][6]>=1){
			x[i][7]=1;
		}
		else{
			x[i][7]=2;
		}
	}
	for(int i=0;i<n;i++){
		cout<<"node "<<i<<": parent = "<<x[i][2]<<", sibling = "<<x[i][3]<<", degree = "<<x[i][6]<<", depth = "<<x[i][4]<<", height = "<<x[i][5]<<", "<<T[x[i][7]]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1252
n,k = map(int, input().split())
a = list(map(int, input().split()))
ideal = 0
imos_b = sum([v for v in a[0:k]])
imos_w = sum([v if v>0 else 0 for v in a[0:k]])
right_b = [0 for i in range(n-k+1)]
right_w = [0 for i in range(n-k+1)]
for i,v in enumerate(a):
    if v>0:
        ideal += v
    if i < n-k+1:
        right_b[i] = imos_b
        right_w[i] = imos_w
        imos_b -= a[i]
        imos_w -= a[i] if a[i]>0 else 0
    if i < n-k:
        imos_b += a[i+k]
        imos_w += a[i+k] if a[i+k]>0 else 0
max_score = sum(a)
for i in range(n-k+1):
    max_score = max(max_score, ideal+right_b[i]-right_w[i], ideal-right_w[i])
print(max_score)



Measured memory_bytes: 15016
#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.at(i);
  for (int i = 0; i < w+2; i++)
    cout << '#';
  cout << endl;
  for (int i = 0; i < h; i++)
    cout << '#' << s.at(i) << '#' << endl;
  for (int i = 0; i < w+2; i++)
    cout << '#';
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n,k;
    cin>>n>>k;
    lli i,a[n+1],vis[n+1],timer=0;
    memset(vis, 0LL, sizeof(vis));
    vector<lli> v;
    
    for(i=1;i<=n;i++) cin>>a[i];
    
    vis[1]=timer++;
    lli cur=1;
    while(1)
    {
        cur=a[cur];
        if(vis[cur]!=0)
        break;
        
        vis[cur]=timer++;
        v.push_back(cur);
    }
    
    if(k<=v.size())
    {
        cout<<v[k-1];
        return 0;
    }
    
    
    lli diff=timer-vis[cur];
    k-=vis[cur];
    k%=diff;
    cout<<v[vis[cur]+k-1];
    return 0;
}

Measured memory_bytes: 8416
#include <iostream>
#include <algorithm>

int main()
{
	int a, b, c;
	std::cin >> a >> b >> c;

	if(a > b) {
		std::swap(a, b);
	}

	if(b > c) {
		std::swap(b, c);
	}

	if(a > b) {
		std::swap(a, b);
	}

	std::cout << a << ' ' << b << ' ' << c << std::endl;

	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>

int main(void)
{
    int a[3+1], max, mid, min, i;

    scanf("%d %d %d", &a[1], &a[2], &a[3]);
    
    //find max,mid,min
    max = a[1]; 
    mid = a[1];
    min = a[1];
    for( i = 2; i <= 3; i++ )
    {
        if ( max < a[i] ) max = a[i];
        if( min > a[i] ) min = a[i];
    }
    for( i = 1; i <= 3; i++ )
    {
        if( max != a[i] && min != a[i] ) mid = a[i];
    }

    printf("%d\n", (max - mid) + (mid - min) );
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MAXN 100000
int a[MAXN+1],b[MAXN+1];
int n;
inline long long check(int val){
   long long ans=0;
   for(int i=1;i<=n;i++)
     if(a[i]<=val)
       ans+=b[i];
   return ans;
}
int main(){
   FILE*fi,*fout;
   int i,rez,pas;
   long long k;
   //fi=fopen("A.in" ,"r");
   //fout=fopen("A.out" ,"w");
   fi=stdin;
   fout=stdout;
   fscanf(fi,"%d%lld" ,&n,&k);
   for(i=1;i<=n;i++)
      fscanf(fi,"%d%d" ,&a[i],&b[i]);
   rez=0;
   for(pas=1<<20;pas;pas>>=1)
     if(check(rez+pas)<k)
       rez+=pas;
   fprintf(fout,"%d" ,rez+1);
   //fclose(fi);
   //fclose(fout);
   return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100


struct Edge{
	Edge(int arg_to,int arg_capacity,int arg_rev_index){
		to = arg_to;
		capacity = arg_capacity;
		rev_index = arg_rev_index;
	}
	int to,capacity,rev_index;
};

int V,E;

vector<Edge> G[NUM];
int dist[NUM];
int cheked_index[NUM];


void add_edge(int from,int to,int capacity){
	G[from].push_back(Edge(to,capacity,G[to].size()));
	G[to].push_back(Edge(from,0,G[from].size()-1));
}

void bfs(int source){
	for(int i = 0; i < V; i++)dist[i] = -1;
	queue<int> Q;
	dist[source] = 0;
	Q.push(source);

	while(!Q.empty()){
		int node_id = Q.front();
		Q.pop();
		for(int i = 0; i < G[node_id].size(); i++){
			Edge &e = G[node_id][i];
			if(e.capacity > 0 && dist[e.to] < 0){
				dist[e.to] = dist[node_id]+1;
				Q.push(e.to);
			}
		}
	}
}

int dfs(int node_id,int sink,int flow){
	if(node_id == sink)return flow;

	for(int &i = cheked_index[node_id]; i < G[node_id].size(); i++){
		Edge &e = G[node_id][i];
		if(e.capacity > 0 && dist[node_id] < dist[e.to]){
			int tmp_flow = dfs(e.to,sink,min(flow,e.capacity));
			if(tmp_flow > 0){
				e.capacity -= tmp_flow;
				G[e.to][e.rev_index].capacity += tmp_flow;
				return tmp_flow;
			}
		}
	}
	return 0;
}


int max_flow(int source,int sink){
	int flow = 0,add;
	while(true){
		bfs(source);
		if(dist[sink] < 0)break;
		for(int i = 0; i < V; i++)cheked_index[i] = 0;
		while((add = dfs(source,sink,BIG_NUM)) > 0){
			flow += add;
		}
	}
	return flow;
}


int main(){

	scanf("%d %d",&V,&E);

	int from,to,cost;

	for(int loop = 0; loop < E; loop++){
		scanf("%d %d %d",&from,&to,&cost);
		add_edge(from,to,cost);
	}

	printf("%d\n",max_flow(0,V-1));

	return 0;
}




Measured memory_bytes: 3248
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct rule{
	bool operator()( int &a,int &b){
		return (a%10 > b%10 || a%10==0);
	}
};
int main(int argc, char** argv) 
{
	int i,a[10],t=0;
	for(i=0; i<5; i++)
	cin >> a[i];
	sort(a,a+5,rule());
	for(i=0; i<5; i++)
	{
		t += a[i];
		if(i<4)
		for(;t%10!=0;t++);
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 384
m=10**9+7;f=[1];n,k=map(int,input().split())
for i in range(10**6):f+=[f[i]*(i+1)%m]
def c(a,b):return f[a]*pow(f[b],m-2,m)*pow(f[a-b],m-2,m)%m
s=c(n*2-1,n-1)
if k>n-2:print(s)
else:print((s+(m-sum(c(n-1,i)*c(n,n-i)for i in range(n-1,k,-1))%m))%m)

Measured memory_bytes: 71500
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int a, b; readV(a, b);

  if (a < b) swap(a, b);
  writeln(a*2 - (a > b ? 1 : 0));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int A,B;
    cin >> A >> B;
    for(int i = 1; i <= 1500; i++) {
        if(i/10 == B && i*2/25 == A) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = 998244353;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};

bool comp(dd a ,dd b){
	dd esp = 0.0000000000000001;
	if(abs(a-b) <= esp) return 1;
	else return 0;
}
dd sq(dd a){
	return a*a;
}
void solve(){ 
    
    dd a,b,h,m;
    cin >> a >> b >> h >> m;
    dd deg1 = (dd)6 * m;
    dd deg2 = ((dd)30*h)+(m/(dd)2);
    cout << fixed << setprecision(18);
	if(comp(deg1,deg2)){
		cout << abs(a-b);
		return;
	}   
	if( comp(abs(deg1-deg2) , (dd)180) ){
		cout << a+b;
		return;
	}
	//cout << deg1 << ' ' << deg2 << '\n';
	cout << sqrt( sq(a) + sq(b) - (((dd)2*a*b)) * cos( abs(deg1-deg2) * PI/(dd)180 )  );
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


Measured memory_bytes: 4128
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from fractions import gcd
def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    m=max(A)
    g=0
    for a in A:
        g=gcd(g,a)

    print("POSSIBLE" if(k%g==0 and k<=m) else "IMPOSSIBLE")
resolve()

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

int main(){
  int64_t a, b, c, d, res=-2*pow(10,18);
  cin >> a >> b >> c >> d;
  int flag=0;
  if(a*b<=0 || c*d<=0) flag++;
  if(res<a*c) res=a*c;
  if(res<a*d) res=a*d;
  if(res<b*c) res=b*c;
  if(res<b*d) res=b*d;
  if(res<0 &&flag>0) res=0;
  cout << res;
  return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

const int64_t MOD = 1e9 + 7;

vector<vector<int>> edge;
vector<bool> isVisited;
using P = pair<int64_t, int64_t>;
P dfs(int node)
{
    isVisited[node] = true;

    int64_t w = 1, b = 1;
    for (const int ch : edge[node]) {
        if (!isVisited[ch]) {
            int64_t chw, chb;
            tie(chw, chb) = dfs(ch);
            w = ((chw + chb) % MOD * w) % MOD;
            b = (b * chw) % MOD;
        }
    }
    return P(w, b);
}

int main()
{
    int n;
    cin >> n;
    edge.resize(n);
    isVisited.resize(n, false);
    rep(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }

    int64_t w, b;
    tie(w, b) = dfs(0);
    int64_t result = (w + b) % MOD;
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

class TaskC {
public:
    void solve() {
        long long n, k, ans = 0;
        cin >> n >> k;
        vector<long long> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];
        sort(a.begin(), a.end()); reverse(a.begin(), a.end());
        for (int i = 0; i < n; i++) {
          if (i > (k - 1)) {
            ans += a[i];
          }
        }
        cout << ans;
    }
};

int main() {
    TaskC solver;
    solver.solve();
}


Measured memory_bytes: 1920
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim_right().to_owned()
    }};
}

macro_rules! parse_next {
    ($ws:expr) => {
        $ws.next().unwrap().parse().unwrap();
    };
}

fn main() {
    let (a, b) = {
        let line = read_line!();
        let mut ws = line.split_whitespace();
        let a: u64 = parse_next!(ws);
        let b: u64 = parse_next!(ws);
        (a, b)
    };
    println!("{}", g(b) ^ g(a - 1));
}

fn g(x: u64) -> u64 {
    let mut ans = 0;
    if x % 4 == 1 || x % 4 == 2 {
        ans ^= 1;
    }
    for i in 1..60 {
        let r = (x + 1) % (1 << (i + 1));
        if r > (1 << i) && r % 2 == 1 {
            ans ^= 1 << i;
        }
    }
    ans
}

Measured memory_bytes: 4352