akhauriyash/Code-Regression huggingface dataset:
"""
https://atcoder.jp/contests/dp/tasks/dp_b
"""
from sys import stdin

n, k = map(int, input().split())
h = list(map(int, stdin.readline().strip().split()))

dp = [float('inf') for _ in range(n)]

dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = min(
        dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, min(i + 1, k + 1)))

print(dp[n - 1])


Measured memory_bytes: 58080
#include "bits/stdc++.h"
 
#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
 
const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };
 
 
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	cout << (n - 1)*(m - 1) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int s[]={3,5,7};
int n;
int a[10];
long long dfs(long long nw,int en){
	if(nw>en)return 0;
	int cnt=0;
	if(a[3]&&a[5]&&a[7])cnt++;
	for(int i=0;i<3;i++){
		a[s[i]]++;
		cnt+=dfs(nw*10+s[i],en);
		a[s[i]]--;
	}
	return cnt;
}
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	cout<<dfs(0,n)<<endl;
    return 0;
}

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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#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 rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	ll n, m;
	ll k;
	ll h, w;
	//ll x;
	//ll a;
	string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;

	cin >> n >> k;
	V a(n);
	rep(i, n) cin >> a[i];

	deque<ll> score;
	vector<string> ans;
	rep(i, n) {
		if (i >= k) {
			if (a[i] > score[0]) {
				ans.push_back("Yes");
			}
			else {
				ans.push_back("No");
			}
			score.pop_front();
			score.push_back(a[i]);
		}
		else {
			score.push_back(a[i]);
		}
	}

	rep(i, ans.size()) {
		cout << ans[i] << "\n";
	}
}

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

	solve_abc_c();

	return 0;
}


Measured memory_bytes: 13160
<?php

$s = new Scanner();

$n=$s->nextInt();
$y=$s->nextInt();

for ($i=0; $i <=$n ; $i++) {
    # code...
    if (1000*$i<=$y) {
        for ($j=0; $j <= $n-$i; $j++) {
            # code...
            if ((1000*$i+5000*$j)<=$y) {
                if ($i*1000+$j*5000+($n-$i-$j)*10000==$y) {
                    out::println(($n-$i-$j).' '.$j.' '.$i);
                    return;
                }
            }
        }
    }
}
out::println('-1 -1 -1');






#文字列・数値の標準入力クラス
class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext()
    {
        return $this->pointer < $this->count;
    }
    public function nextInt()
    {
        return (int)$this->next();
    }
    public function nextDouble()
    {
        return (double)$this->next();
    }
}

#改行ありの標準出力クラス
class out
{
    public static function println($str = "")
    {
        echo $str . PHP_EOL;
    }
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)

using namespace std;

int f(int x, int y, int z){
  return (x*x + y*y + z*z + x*y + y*z + z*x);
}

int main()
{
  int n;
  cin >> n;
  int max = 100;
  int nt = 0;
  int ans[n+1] = {}; 
  for(int x=1; x<=max; x++){
    for(int y=1; y<=max; y++){
      for(int z=1; z<=max; z++){
	nt = f(x,y,z);
	if(nt <= n){
	  ans[nt]++;
	}
      }
    }
  }

  for(int i=1; i<=n; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 3548
function main()
  n = parse(Int, readline())
  A = parse.(Int, split(readline()))
  res = map(enumerate(A)) do (i, a)
    if i == 1 return 0 end
    if a >= A[i-1]
      return 0
    else
      ans = A[i-1] - a
      A[i] = A[i] + ans
      return ans
    end
  end
  sum(res)
end
println(main())

Measured memory_bytes: 205416
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	if(a > 9 || b > 9) {
		printf("-1\n");
		return 0;
	}
	printf("%d", a * b);
	return 0;
}

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

int main(){

  queue<int> x;
  queue<string> y;
  
  int n, head=1,total=0,i,q;

  cin>>n>>q;

  for(int i=0 ;i<n;i++){
    int time; char name[1000];
    cin>>name>>time;
    x.push(time);
    y.push(name);
    
  }

  while(!x.empty()){
    int num = x.front();
    num-=q;
    if(num<=0){
      cout<<y.front()<<' '<<total+q+num<<endl;
      total+=q+num;
    }
    else {
      x.push(num);
      y.push(y.front());
      total+=q;
    }
    x.pop();
    y.pop();
      
  }  
  return 0;
}



Measured memory_bytes: 5720
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[3][10] = {0};
	int b[3][10] = {0};
	int c[3][10] = {0};
	int d[3][10] = {0};
	int x, y, z, w;
	for(int i = 0; i < n; i++) {
		cin >> x >> y >> z >> w;
		if(x == 1) {
			a[y-1][z-1] += w;
		}
		if(x == 2) {
			b[y-1][z-1] += w;
		}
		if(x == 3) {
			c[y-1][z-1] += w;
		}
		if(x == 4) {
			d[y-1][z-1] += w;
		}
	}
	for(int i = 0; i < 3; i++) {
	    cout << " ";
		for(int j = 0; j < 10; j++) {
			cout << a[i][j];
			if(j != 9) cout << " ";
			else cout << endl;
		}
	}
	cout << "####################" << endl;
	for(int i = 0; i < 3; i++) {
	    cout << " ";
		for(int j = 0; j < 10; j++) {
			cout << b[i][j];
			if(j != 9) cout << " ";
			else cout << endl;
		}
	}
	cout << "####################" << endl;
	for(int i = 0; i < 3; i++) {
	    cout << " ";
		for(int j = 0; j < 10; j++) {
			cout << c[i][j];
			if(j != 9) cout << " ";
			else cout << endl;
		}
	}
	cout << "####################" << endl;
	for(int i = 0; i < 3; i++) {
	    cout << " ";
		for(int j = 0; j < 10; j++) {
			cout << d[i][j];
		if(j != 9) cout << " ";
		else cout << endl;
		}
	}
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


void func(long long X, long long A, long long B){
    cout<<(X-A)%B<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long X;
    scanf("%lld",&X);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    func(X, A, B);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <typeinfo>
#include <memory>


using namespace std;

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

#define fs first
#define sc second


int main(){
    string s;
    cin >> s;

    int c[26];
    fill(c, c+26, 0);
    for(int i = 0; i < 4; i++){
        c[s[i] - 'A']++;
    }

    int count = 0;
    for(int i= 0; i < 26; i++){
        if(c[i] == 2){
            count++;
        }
    }

    if(count == 2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }



    return 0;
}


Measured memory_bytes: 256
using System;
class Program {
    static void Main (string[] args) {
        string[] input = Console.ReadLine ().Split (' ');
        int X = int.Parse(input[0]);
        int Y = int.Parse(input[1]);
        int A = int.Parse(input[2]);
        int B = int.Parse(input[3]);
        int C = int.Parse(input[4]);

        string[] inputp = Console.ReadLine ().Split (' ');
        string[] inputq = Console.ReadLine ().Split (' ');
        string[] inputr = Console.ReadLine ().Split (' ');

        long[] pArray = new long[A];
        long[] qArray = new long[B];
        long[] rArray = new long[C];

        for (int i = 0; i < A; i++) {
            pArray[i] = long.Parse(inputp[i]);
        }

        for (int i = 0; i < B; i++) {
            qArray[i] = long.Parse(inputq[i]);
        }

        for (int i = 0; i < C; i++) {
            rArray[i] = long.Parse(inputr[i]);
        }

        quickSortB2S(pArray);
        quickSortB2S(qArray);
        
        long[] newArray = new long[X + Y + C];

        for (int i = 0; i < X; i++) {
            newArray[i] = pArray[i];
        }

        for (int i = 0; i < Y; i++) {
            newArray[i + X] = qArray[i];
        }

        for (int i = 0; i < C; i++) {
            newArray[i + X + Y] = rArray[i];
        }

        quickSortB2S(newArray);

        long sum = 0;
        for (int i = 0; i < X + Y; i++) {
            sum += newArray[i];
        }

        Console.WriteLine(sum);
    }

    static void quickSortB2S(long[] a) {
        quickSortB2S(a, 0, a.Length - 1);
    }

    static void quickSortB2S(long[] a, int left, int right) {
        if (left < right) {
            int i = left;
            int j = right;
            long tmp;
            long pivot = med3(a[i], a[i + (j - i) / 2], a[j]);
            while (true) {
                while (a[i] > pivot) i++;
                while (pivot > a[j]) j--;
                if (i >= j) break;
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                i++;
                j--;
            }
            quickSortB2S(a, left, i - 1);
            quickSortB2S(a, j + 1, right);
        }
    }

    static long med3(long x, long y, long z) {
        if (x < y) {
            if (y < z) {
                return y;
            } else if (z < x) {
                return x;
            } else {
                return z;
            }
        } else {
            if (z < y) {
                return y;
            } else if (x < z) {
                return x;
            } else {
                return z;
            }
        }
    }
}


Measured memory_bytes: 42616
#include<stdio.h>

int search(int A[],int n,int key){
	int i=0;
	A[n]=key;
	while(A[i]!=key)i++;
	return i!=n;
}

int main(){
	int i,n,A[10000+1],q,key,sum=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&key);
		if(search(A,n,key))sum++;
	}
	printf("%d\n",sum);
	
	return 0;
}

Measured memory_bytes: 640
n,k = gets.strip.split.map(&:to_i)
num = gets.strip.split.map(&:to_i)
t = num.uniq.size
rec = Array.new(n,0)
for i in 0..n-1
  rec[num[i]-1] += 1
end
rec.sort!
rec.delete(0)
if t <= k
  puts 0
  exit
end
#ここからは取り除きが発生する場合のみ
sum = 0
for j in 0..t-k-1
  sum += rec[j]
end
puts sum

Measured memory_bytes: 36652
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
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;}

char in[120];
pair<pair<string,int>,int> p[110];

int main(){
  int a;
  scanf("%d",&a);

  for(int i=0;i<a;i++){
    int t;
    scanf("%s%d",in,&t);

    //string tmp = in;
    p[i] = make_pair(make_pair(in,-t),i);
  }
  std::sort(p,p+a);
  for(int i=0;i<a;i++) printf("%d\n",p[i].second+1);
}


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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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

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

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

Int n, m;

int main(){
	cin >> n >> m;
	
	if(n == 2 || m == 2) cout << 0 << endl;
	else cout << max(n-2, (Int)1) * max(m-2, (Int)1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

cnt = 0
judge = 0
exp = 1
while judge == 0 do
  cnt += 1
  exp *= 2
  n.times do |i|
    judge += a[i] % exp
  end
end

puts cnt - 1

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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (x, ) = [int(e) for e in lines[0].split(' ')]

    return (x, )


def solve(x):
    
    # 切り捨てが必要
    m = (math.log10(x) - 2) / math.log10(1.01)
    n = math.ceil(m) 

    tmp = 100
    n = 0 
    for i in range(1, 3761):
        tmp = math.floor(tmp * 1.01)
        if tmp >= x:
            n = i
            break


    return n
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Measured memory_bytes: 63944
import copy
h,w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
G = [list(map(int,input().split())) for i in range(h)]
d = copy.deepcopy(c)

for k in range(10):
  for i in range(10):
    for j in range(10):
      d[i][j] = min(d[i][j],d[i][k]+d[k][j])

ans = 0
for i in range(h):
  for j in range(w):
    if G[i][j] != -1:
      ans += d[G[i][j]][1]
      
print(ans)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int main(){
    long N;
    cin>>N;
    long sum=0;
    for (int i=1;i<N+1;i++) {
        if((i%3!=0)&&(i%5!=0)){ sum += i;}
        else {continue;}
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3628
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

tmp = 0
sum = 0
a.each.with_index(0) do |e, index|
  sum += e
  if index.odd?
    if sum > 0
    else
      tmp += sum.abs + 1
      sum = 1
    end
  else
    if sum < 0
    else
      tmp += sum.abs + 1
      sum = -1
    end
  end
end
ans = tmp

tmp = 0
sum = 0
a.each.with_index(0) do |e, index|
  sum += e
  if index.even?
    if sum > 0
    else
      tmp += sum.abs + 1
      sum = 1
    end
  else
    if sum < 0
    else
      tmp += sum.abs + 1
      sum = -1
    end
  end
end

ans = tmp if tmp < ans
p ans


Measured memory_bytes: 9612
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    int X[N], Y[N];
    rep(i,N){
        cin>>X[i]>>Y[i];
        if(X[i]>Y[i]) swap(X[i],Y[i]);
    }
    
    // 全てのボールの最小値、最大値
    int all_min=*min_element(X,X+N);
    int all_max=*max_element(Y,Y+N);
    
    // 赤の最大値を最小に、青の最小値を最大に
    int Rmax=*max_element(X,X+N);
    int Bmin=*min_element(Y,Y+N);
    
    // 赤が全ボール最小値、青が全ボール最大値を取った時の最小値
    ll ret=1LL*(Rmax-all_min)*(all_max-Bmin);
    
    // 赤が全ボール最大値、最小値共に取った時、青の最大最小幅を最小にする
    vector<pii> vs(N);
    rep(i,N){
        vs[i].first=X[i];
        vs[i].second=Y[i];
    }
    
    sort(all(vs));
    int dif=all_max-all_min;
    int Bmax = vs.back().first; Bmin=all_max;
    
    rep(i,N){
        ret = min( ret, 1LL*dif*(Bmax-min(Bmin,vs[i].first)));
        if(Bmin>vs[i].second) Bmin=vs[i].second;
        if(Bmax<vs[i].second) Bmax=vs[i].second;
    }
    cout1(ret)
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    string s; cin>>s;

    int ans=0;
    for(int i=1;i<=N-1;i++){
        int cnt=0;
        for(char c='a';c<='z';c++){
            bool l=false,r=false;
            for(int j=0;j<i;j++) if(s[j]==c) l=true;
            for(int j=i;j<N;j++) if(s[j]==c) r=true;
            if(l and r) cnt++;
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t;
ll binary_search(ll a[],ll l,ll r,ll x)
{
   ll res=-1,mid;
   while(l<=r)
   {
     mid=(l+r)/2;
     if(a[mid]<=x)  l=mid+1,res=mid;
     else r=mid-1;
   }
   return res;
}
ll binary_search2(ll a[],ll l,ll r,ll x)
{
   ll res=n,mid;
   while(l<=r)
   {
     mid=(l+r)/2;
     if(a[mid]>=x)  r=mid-1,res=mid;
     else l=mid+1;
   }
   return res;
}
int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n;
      ll a[n],sum=0;
      for(int i=0;i<n;i++){
        cin>>a[i];
      }
      sort(a,a+n);
      for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
          ll x=max(binary_search(a,j+1,n-1,a[j]-a[i]),(ll)j);
          ll y=binary_search2(a,j+1,n-1,a[i]+a[j]);
          sum+=max(0ll,y-x-1);
          if(i>x&&i<y)sum--;
          if(j<y&&j>x)sum--;
        }
      }
      cout<<sum;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int ans = 0;
		if(k != 1) {
			ans = n-k;
		}
		System.out.println(ans);
		sc.close();
	}
	
	
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;


int main() {
    vector<int> Sto2nd;
    unordered_map<int, bool> secTo3rd;

    int N, M;
    cin >> N >> M;

    int a, b;
    for (int m = 0; m < M; m++) {
        cin >> a >> b;
        if (a == 1) { Sto2nd.push_back(b); }
        else {
            if (b == N) { secTo3rd[a] = true; }
        }
    }

    vector<int>::iterator i = Sto2nd.begin();
    bool isPossible = false;
    while (i != Sto2nd.end()) {
        if (secTo3rd[*i]) {
            isPossible = true;
            break;
        }
        i++;
    }

    if (isPossible) { cout << "POSSIBLE" << endl; }
    else { cout << "IMPOSSIBLE" << endl; }

    return 0;
}

Measured memory_bytes: 8896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    COMinit();
    ll n,k;
    cin>>n>>k;
    for(ll i=1;i<=k;i++){
    	cout << (COM(n-k+1,i)*COM(k-1,i-1))%inf<<endl;
    }
    // 計算例
 //   cout << COM(100000, 50000) << endl;	
	// your code goes here
	return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    string s;
    cin >> n >> k >> s;
    s[k - 1] = tolower(s[k - 1]);
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n;
	scanf("%d", &n);
	bool win = false;
	for(int i = 0; i < n; ++i){
		int a;
		scanf("%d", &a);
		win |= a % 2 == 1;
	}
	puts(win ? "first" : "second");
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 256
H,W,N=map(int, input().split())
sr,sc=map(int, input().split())
S=input()
T=input()
for (x,y),(s,t) in zip(["LR","RL","UD","DU"],[(W-sc,W),(sc-1,W),(H-sr,H),(sr-1,H)]):
    C=[s]*(N+1)
    for i in range(N):
        C[i]+=S[i]==x
        C[i+1]=max(0,C[i]-(T[i]==y))
    if max(C)>=t:
        print("NO")
        break
else:
    print("YES")

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

int main()
{
    string s,t;
    cin >> s >> t;
    int ans = 1001;

    for (int i = 0; i < s.size() - t.size() + 1; ++i)
    {
        int count = 0;
        for (int j = 0; j < t.size(); j++)
        {
            if (s[i + j] != t[j])
            {
                count++;
            }
        }
        ans = min(ans,count);
    }
    cout << ans << endl;
}   

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,t;
    cin>>n>>t;
    ll a,b;
    vector<pair<ll,ll> > v;
    for(int i=0;i<n;i++){
    	cin>>a>>b;
    	v.push_back({a,b});
    }
    sort(be(v));
    ll dp[t+1];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++){
    	a=v[i].first;
    	b=v[i].second;
    	for(int j=t-1;j>=0;j--){
    		dp[min(t,j+a)]=max(dp[min(t,j+a)],dp[j]+b);
    	}
    }
    cout << dp[t] <<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
lli n,dpa[100005],dpb[100005],dpc[100005],a[100005],b[100005],c[100005];
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dpa[1] = a[1]; dpb[1] = b[1]; dpc[1] = c[1];
    for(int i=2; i<=n; i++){
        dpa[i] = a[i] + max(dpb[i-1],dpc[i-1]);
        dpb[i] = b[i] + max(dpc[i-1],dpa[i-1]);
        dpc[i] = c[i] + max(dpa[i-1],dpb[i-1]);
        //cout<<dpa[i]<<" "<<dpb[i]<<" "<<dpc[i]<<endl;
    }
    cout<<max(dpa[n],max(dpb[n],dpc[n]))<<endl;
    return 0;
}


Measured memory_bytes: 4992
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,1);
  if(input == 3){
     myout("2\n1 3\n2 3");
    return;
  }
  if(input == 4){
     myout("4\n1 3\n2 1\n4 2\n3 4");
    return;
  }
  var output = [];
  if(input % 2 == 1){
     output.push((input-1) * 2);
    for(var i = 0; i < Math.floor(input / 2); i++){
      var mae = i + 1;
      var mae2 = mae+1;
      var ato = input - 1 - i;
      var ato2 = ato-1;
      if(i == Math.floor(input / 2)-1 || i == 0){
         output.push(mae.toString() + " " + input);
         output.push(ato.toString() + " " + input);
        if(i == Math.floor(input / 2)-1){
           break;
        }
      }
      output.push(mae.toString() + " " + mae2.toString());
      output.push(mae.toString() + " " + ato2.toString());
      output.push(ato.toString() + " " + mae2.toString());
      output.push(ato.toString() + " " + ato2.toString());
    }
    myout(output.join("\n"));
  }else{
    output.push(input * 2);
    for(var i = 0; i < input / 2; i++){
      var mae = i + 1;
      var mae2 = mae+1;
      var ato = input - i;
      var ato2 = ato-1;
      if(i == (input / 2)-1){
         mae2 = 1;
         ato2 = input;
      }
      output.push(mae.toString() + " " + mae2.toString());
      output.push(mae.toString() + " " + ato2.toString());
      output.push(ato.toString() + " " + mae2.toString());
      output.push(ato.toString() + " " + ato2.toString());
    }
    myout(output.join("\n"));
  }
}

Main(myin());

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

ull gcd(ull m, ull n){
  if(n==0) return m;
  return gcd(n,m%n);
}
ull lcm(ull m, ull n){
  return (m/gcd(m,n)*n);
}

int main(){
  int n;
  cin>>n;
  ull ans=1;
  for(int i=0;i<n;i++){
    ull t;
    cin>>t;
    ans=lcm(ans, t);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll i,j,k,a,b,c,n,t,m,p,q,d,e,f,l,nl,np,x,y,x1,y2,y1,x2;
    vector<ll > s;
    vector<ll > vv,ss,v;
    map<string,ll> ma,sa;
    string st,et,ft,pt,ct;
    deque<char> de;
    ios_base::sync_with_stdio(false);
    cin>>a;
    cin>>st;
    if(st.size()<=a)cout<<st<<endl;
    else {
        for(i=0;i<a;i++)cout<<st[i];
        cout<<"..."<<endl;
    }
}


Measured memory_bytes: 3616
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val k = scanner.nextInt()

    var i = 0
    val a = mutableListOf<Int>()
    a.add(scanner.nextInt())
    var curGcd = a.last()
    while (i < n-1) {
        a.add(scanner.nextInt())
        curGcd = gcd(curGcd,a.last())
        i++
    }

    if (k > a.max() as Int || k % curGcd!=0) {
        println("IMPOSSIBLE")
    } else {
        println("POSSIBLE")
    }

}

fun gcd(vararg nums: Int): Int {
    if (nums.size == 1) {
        return 1
    } else {
        var t: Int
        var a = nums[0]
        var b = nums[1]

        while (b != 0) {
            t = a % b
            a = b
            b = t
        }
        return a
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int64_t factorial(int64_t n) {
  if (n == 1) {
    return 1;
  }
  int64_t ans = factorial(n-1);
  return ans*n;
}

int main() {
  int64_t n, m;
  cin >> n >> m;
  vector <int64_t> a(m);
  vector <int64_t> b(m);
  rep(i, m) cin >> a.at(i) >> b.at(i);
  vector <int> v1(n, 0);
  vector <int> v2(n, 0);
  rep(i, m) {
    if (a.at(i) == 1) {
      v1.at(b.at(i)-1) = 1;
    }
    if (b.at(i) == n) {
      v2.at(a.at(i)-1) = 1;
    }
  }
  string ans = "IMPOSSIBLE";
  rep(i, n) {
    if (v1.at(i)*v2.at(i) > 0) {
      ans = "POSSIBLE";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------


int main()
{
	int n;
	cin >> n;
	int f[50];
	f[0] = f[1] = 1;
	for (int i = 2; i <= n; i++) f[i] = f[i - 1] + f[i - 2];
	cout << f[n] << endl;
	return 0;
}

Measured memory_bytes: 1164
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = "" ;count = 0 ;pro = 1

a,b,c,d=map(int,input().split())

ans+="R"*(c-a)+"U"*(d-b)
ans+="L"*(c-a)+"D"*(d-b)

ans+="D"+"R"*(c-a+1)+"U"*(d-b+1)+"L"
ans+="U"+"L"*(c-a+1)+"D"*(d-b+1)+"R"


print(ans)

Measured memory_bytes: 3316
import sys
sys.setrecursionlimit(500000)
def scc(N, G, RG):
    # https://tjkendev.github.io/procon-library/python/graph/scc.html
    order = []
    used = [0]*N
    group = [None]*N
    def dfs(s):
        used[s] = 1
        for t in G[s]:
            if not used[t]:
                dfs(t)
        order.append(s)
    def rdfs(s, col):
        group[s] = col
        used[s] = 1
        for t in RG[s]:
            if not used[t]:
                rdfs(t, col)
    for i in range(N):
        if not used[i]:
            dfs(i)
    used = [0]*N
    label = 0
    for s in reversed(order):
        if not used[s]:
            rdfs(s, label)
            label += 1
    return label, group

from collections import Counter
N, M = map(int, input().split())
E = [[] for _ in range(N+1)]
E_set = [set() for _ in range(N+1)]
E_rev = [[] for _ in range(N+1)]
E_rev_set = [set() for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    E[a].append(b)
    E_set[a].add(b)
    E_rev[b].append(a)
    E_rev_set[b].add(a)

label, group = scc(N+1, E, E_rev)
cnt = Counter(group)
Closed = [False] * (N+1)

grooo = [set() for _ in range(N+1)]
for v, gr in enumerate(group):
    grooo[gr].add(v)

from random import random
haaaaaaaaaaaaaaaaaaaaaaa = enumerate(group) if random() > 0.5 else zip(range(N, 0, -1), group[::-1])


for v, gr in haaaaaaaaaaaaaaaaaaaaaaa:
    if Closed[gr]:
        continue
    Closed[gr] = True
    if cnt[gr]==1:
        continue

    #print(gr, cnt[gr])
    groo = grooo[gr]

    path = [v]
    path_set = {v}
    while True:
        #print("v=",v)
        aaa = E_set[v]&path_set
        if aaa:
            break
        u = (groo&E_set[v]).pop()
        #print("u=",u)
        while E_rev_set[u]-{v} & path_set:
            path_set.remove(path.pop())
        path.append(u)
        path_set.add(u)
        v = u
        #print(path)
    for i, v in enumerate(path):
        if v in aaa:
            aaa.remove(v)
            if len(aaa)==0:
                break
    ans = path[i:]
    print(len(ans))
    print("\n".join(map(str, ans)))
    exit()
print(-1)


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> graph[n];

    rep(i, 0, m)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> ok(n, 0);
    for(auto next : graph[0])
    {
        ok[next] = 1;
        for (auto nnext : graph[next])
            ok[nnext] = 1;
    }

    if (ok[n - 1])
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 12784
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define MAXN 131100
#define LL long long
#define INF 40000000000
struct node
{
	LL in,out;
	node(LL _in=0,LL _out=0){in=_in,out=_out;}
};
vector<node>dp[MAXN],tmp1,tmp2;
LL lim;
void vector_merge(vector<node>&G,vector<node>&l,vector<node>&r)
{
	G.clear();
	int s1=l.size(),s2=r.size(),p1=0,p2=0;
	if(s2==0) return;
	while(p1<s1)
	{
		while(p2<s2&&l[p1].out+r[p2].in<=lim) p2++;
		if(p2) p2--;
		if(l[p1].out+r[p2].in<=lim) G.push_back(node(l[p1].in,r[p2].out));
		p1++;
	}
}
void Insert(vector<node>&G,node &x)
{
	int k=G.size();
	if(k==0) G.push_back(x);
	else if(G[k-1].out>x.out) G.push_back(x);
}
void merge_sort(vector<node>&G,vector<node>&l,vector<node>&r)
{
	G.clear();
	int s1=l.size(),s2=r.size(),p1=0,p2=0;
	while(p1!=s1||p2!=s2)
	{
		if(p1==s1) Insert(G,r[p2++]);
		else if(p2==s2) Insert(G,l[p1++]);
		else if(l[p1].in<r[p2].in) Insert(G,l[p1++]);
		else Insert(G,r[p2++]);
	}
}
int d[MAXN],ch[MAXN][2],fa[MAXN],n;
LL dep[MAXN];
void dfs(int u)
{
	if(!d[u])
	{
		dp[u].clear();
		dp[u].push_back(node(dep[u],dep[u]));
		return;
	}
	int ls=ch[u][0],rs=ch[u][1];
	dfs(ls);
	dfs(rs);
	lim+=2*dep[u];
	vector_merge(tmp1,dp[ls],dp[rs]);
	vector_merge(tmp2,dp[rs],dp[ls]);
	merge_sort(dp[u],tmp1,tmp2);
	lim-=2*dep[u];
}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		scanf("%d%lld",&fa[i],&dep[i]);
		ch[fa[i]][d[fa[i]]++]=i;
		dep[i]+=dep[fa[i]];
	}
	LL l=0,r=INF,ans;
	while(l<r)
	{
		lim=(l+r)/2;
		dfs(1);
		if(dp[1].size()) r=lim,ans=lim;
		else l=lim+1;
	}
	printf("%lld\n",ans);
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll N, A, B;
  IN(N,A,B);
  OUT(min(A*N,B));

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <unordered_map>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v)
    is >> x;
  return is;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

struct Node {
  ll u;
  ll step;

  Node(const ll &u, const ll &step) : u(u), step(step) {}

  bool operator>(const Node &rhs) const { return step > rhs.step; }
};


int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int T;
  cin >> T;
  while (T--) {
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    unordered_map<ll, ll> dist;
    priority_queue<Node, vector<Node>, greater<Node>> q;
    q.emplace(N, dist[N] = 0);
    while (!q.empty()) {
      ll u, step;
      u = q.top().u;
      step = q.top().step;
      q.pop();
      if (step != dist[u]) continue;
      if (u == 0) {
        cout << step << '\n';
        break;
      }
      auto relax = [&](ll x, ll d) {
        d += step;
        if (!dist.count(x) || dist[x] > d)
          q.emplace(x, dist[x] = d);
      };
      if (u <= 1e18 / D)
        relax(0, u * D);
      relax(u / 2, A + (u % 2) * D);
      relax(u / 2 + 1, A + (2 - u % 2) * D);
      relax(u / 3, B + (u % 3) * D);
      relax(u / 3 + 1, B + (3 - u % 3) * D);
      relax(u / 5, C + (u % 5) * D);
      relax(u / 5 + 1, C + (5 - u % 5) * D);
    }
  }

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

int main(){
  int N;
  cin >>N;
  int numbers[N];
  for(int i=0;i<N;i++){
    cin >> numbers[i];
  }
  int flag;
  int tmp;

  while(flag==0){
    flag = 1;
    for(int i=0;i<N-1;i++){
      tmp=0;
      if (numbers[i]<numbers[i+1]){
        tmp = numbers[i];
        numbers[i] = numbers[i+1];
        numbers[i+1] = tmp;
        flag = 0;
        //cout<<"done!";
      }
    }
  }
  

  int A,B;
  A=0;
  B=0;
  for(int i =0;i<N;i++){
    if(i%2==0){
      //cout<<numbers[i];
      A += numbers[i];
    }
    else{
      //cout<<numbers[i];
      B += numbers[i];
    }
  }
  cout << A-B;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	mi, ma := 100000000, -1000000000
	for i := 0; i < 3; i++ {
		sc.Scan()
		x, _ := strconv.Atoi(sc.Text())
		if x < mi {
			mi = x
		}
		if x > ma {
			ma = x
		}
	}
	fmt.Println(ma - mi)
}


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

int main(){
    int N, M; cin >> N >> M;
    vector<int> A(N);
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
        sum += A.at(i);
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    bool exist = true;
    for (int i = 0; i < M; i++)
    {
        if(A.at(i)*4*M < sum) exist = false;
    }
    if(exist) cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.replaceAll("eraser", "X").replaceAll("erase", "X").replaceAll("dreamer", "X").replaceAll("dream", "X")
				.replaceAll("X", "")
				.equals("")) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();

	}
}

Measured memory_bytes: 29036
#include<iostream>
#include<vector>

int main(void){
    int n;
    long long dv = 1;
    long long max = 1;
    for(int i = 0; i < 18; i++){
	max *= 10;
    }
    std::cin >> n;
    std::vector<long long> a(n);

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

    for(int i = 0; i < n; i++){
	if(a[i] == 0){
	    std::cout << 0 << std::endl;
	    return 0;
	}
    }

    for(int i = 0; i < n; i++){
        if(dv <= max / a[i] + 1 && dv * a[i] <= max){
            dv *= a[i];
        }
        else{
           std::cout << -1 << std::endl;
	   return 0;
        }
    }
    std::cout << dv << std::endl;
    return 0;
}


Measured memory_bytes: 4020
# include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;

int main(){
  ll N;
  cin >> N;
  vector<ll> A;
  ll tmp;
  rep(i,1,N){
    cin >> tmp;
    A.push_back(tmp);
  }
  
  sort(A.begin(),A.end());
  queue<ll> que;
  que.push(A[A.size()-1]);
  
  ll res=0;
  int rep=2;
  rrep(i,N-1,1){
    res += que.front();
    //cout << res << '\n';
    que.pop();
    for(int j=0;j<rep;j++) que.push(A[i-1]);
  }
  
  cout << res;
  return 0;
}

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

int main()
{
    int H, W, D;
    cin >> H >> W >> D;
    vector<pair<int, int>> pos(H * W + 1);

    rep(i, H) rep(j, W)
    {
        int A;
        cin >> A;
        pos[A] = make_pair(i + 1, j + 1);
    }

    vector<int> cost(H * W + 1, 0);
    for (int n = 1; n <= H * W; n++)
    {
        int next = n + D;
        if (next > H * W)
            continue;
        int move_cost = abs(pos[n].first - pos[next].first) + abs(pos[n].second - pos[next].second);
        cost[next] = cost[n] + move_cost;
    }

    int Q;
    cin >> Q;
    vector<int> ans(Q);
    rep(i, Q)
    {
        int L, R;
        cin >> L >> R;
        ans[i] = cost[R] - cost[L];
    }
    rep(i, Q)
    {
        cout << ans[i] << endl;
    }
    return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {

    int h, w;
    cin>>h>>w;
    rep(i,w+2)cout<<"#";
    cout <<endl;
    rep(i,h){
        string s;
        cin>>s;
        cout<<"#"<<s<<"#"<<endl;
    }
    rep(i,w+2)cout<<"#";
    cout <<endl;
    return 0;
}


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

int main() {
	int n,k,a,b,h,m,i;
	cin >> a >> b >> h >> m;
	double c,d,pi=acos(-1.0);
	d=abs(m*5.5-h*30.0);
	d=min(d,360-d);
	c=sqrt(a*a+b*b-2*a*b*cos(pi*d/180));
	cout << setprecision(10);
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 4160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long k = sc.nextLong();
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) != '1' || k == 1) {
				System.out.println(s.charAt(i));
				return;
			} else {
				k--;
			}
		}
		System.out.println(1);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include<cmath>

using namespace std;

int N, h[100000+5], Cost[100000+5] = {0};

void solve(){
    Cost[1] = 0;
    Cost[2] = abs(h[2]-h[1]);

    for(int i = 3; i <= N; i++)
        Cost[i] = min(abs(h[i]-h[i-1])+Cost[i-1], abs(h[i]-h[i-2])+Cost[i-2]);

    cout << Cost[N] << endl;
}

int main(){
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> h[i];

    solve();
}

Measured memory_bytes: 1024