akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()
S, T = input().split(" ")

for s, t in zip(S, T):
    print(s + t, end="")

print()

Measured memory_bytes: 43376
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    string s;
    cin>>s;
    if(s=="ARC")
    {
        cout<<"ABC";
    }
    else
    {
                cout<<"ARC";

    }
    
}


Measured memory_bytes: 3620
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.Map.Strict               as M
import           Data.Char


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

isNum :: Int -> Bool
isNum a 
    | a `mod` 5 == 0 = False
    | a `mod` 3 == 0 = False
    | otherwise = True

solve :: String -> Int
solve s = let
    withI = zip [1..] s
    rList = fst <$> filter (\(i, w) -> w == 'R' ) withI
    gList = fst <$> filter (\(i, w) -> w == 'G' ) withI
    bList = fst <$> filter (\(i, w) -> w == 'B' ) withI
    bSet = S.fromList bList
    bSize = S.size bSet
    in sum $ do
        rIndex <- rList
        gIndex <- gList
        let [a, b] = sort [rIndex, gIndex]
        let minB = a - (b - a)
        let maxB = b + (b - a)
        let midB = if odd (a + b)  then -1 
            else if (b - a) == 1 then - 1
            else (a + b)   `div` 2
        pure $ max 0 $ foldl' (\acc num -> if S.member num bSet then acc - 1 else acc ) bSize [minB, maxB, midB]

main = do
    _ <- getLine
    s <- getLine
    print $ solve s





Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
int p[10]={0,2,5,5,4,5,6,3,7,6},a[10],n,m,i,j,tmp,f[10002],v[10];
int main()
{
	cin >> n >> m;
	for(i=1;i<=m;i++){
		cin>>a[i];
		v[a[i]]=1;
	}	
	memset(f,-1,sizeof(f));
	f[0]=0;
	for(i=1;i<=m;i++)
		for(j=p[a[i]];j<=n;j++)f[j]=max(f[j],f[j-p[a[i]]]+1);
	tmp=f[n];
	for(i=1;i<=tmp;i++)
		for(j=9;j>=1;j--)
			if(v[j]&&p[j]<=n&&f[n-p[j]]==f[n]-1){
				cout<<j;
				n-=p[j];
				break;
			}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
let () =
  let a,b,c = Scanf.scanf "%d %d %d " (fun a b c -> a,b,c) in
  let l = [a;b;c] in
  let ls = List.sort compare l in
  let d2 = (List.nth ls 2) - (List.nth ls 0) in
  let d1 = (List.nth ls 2) - (List.nth ls 1) in

  Printf.printf "%d\n" @@
  if (d2+d1) mod 2 = 0 then (d2+d1)/2 else 2+((d2+d1)/2)







Measured memory_bytes: 2432
r = int(input())
N = [int(input()) for i in range(r)]

min_i = N[0]
max_d = -9999999999
for j in range(1, r):
    diff = N[j] - min_i
    if diff > max_d:
        max_d = diff
    if N[j] < min_i:
        min_i = N[j]
print(max_d)


Measured memory_bytes: 13592
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

L, R = LI()

#LRの差が2019以上の場合、答えは絶対0になる。
#例えば、2019*10098は余り0になる
if R - L >= 2019 or L == 0:
    print(0)
    exit()

# 差が2019未満の場合、全部確かめる。

result = inf
for i in range(L, R):
    for j in range(i + 1, R+1):
        result = min(result, (i*j)%2019)
print(result)


Measured memory_bytes: 67432
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

int dp[4001],n,a,b,c,i;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int h,n,i,sum=0;
    cin >> h >> n;
    int a[n];
    for(i=0;i<n;i++) {
        cin >> a[i];
        sum+=a[i];
    }
    if(sum>=h) cout << "Yes";
    else cout << "No";
    cout << "\n";
    return 0;
}



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

using namespace std;

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  stack<char> st;
  int bc = 0;
  for (char c : s) {
    if (c == 'B')
      bc++;
    else if (bc > 0)
      bc--;
    else
      st.push(c);
  }
  while (!st.empty()) {
    cout << st.top();
    st.pop();
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 175 A - Rainy Season
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/29
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
using namespace std;

int main() {

    int_fast8_t c;
    uint_fast32_t cnt = 0;
    uint_fast32_t max_cnt = 0;
    for (int i=0;i<3;i++) {
        scanf("%c", &c);
        if (c == 'R') {
            cnt++;
        } else {
            cnt = 0;
        }
        if (cnt > max_cnt)
            max_cnt = cnt;
    }
    printf("%d\n", max_cnt);

}

Measured memory_bytes: 3180
#include <iostream>
#include <map>
#include <set>
#include <string>
#include<string.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
    string S,T;
    cin>>S;
    cin>>T;
    if(T.length()>S.length()){
        printf("UNRESTORABLE\n");
    }else {
        int lens=S.length();
        int lent=T.length();
      //  printf("lens=%d,lent=%d\n",lens,lent);
        int ansl=-1;
        bool pp;
        for(int i=lens-1;i>=lent-1;i--){
            int ppcnt=0;
            int tail=i;
            int tailt=lent-1;
            pp=false;
            while(1){
                if(ppcnt==lent){
                    pp=true;
                    break;
                }
                if(S[tail]=='?'){
                    ppcnt++;
                    tail--;
                    tailt--;
                }else if(S[tail]!='?'&&S[tail]!=T[tailt]){
                    break;
                }else if(S[tail]==T[tailt]){
                    tail--;
                    tailt--;
                    ppcnt++;
                }
            }
            if(pp) {
                ansl=i-lent+1;
                break;
            }
        }
        if(ansl==-1){
            printf("UNRESTORABLE\n");
        }else{
            for(int i=0;i<lens;i++){
                if(i<ansl){
                    if(S[i]=='?') printf("a");
                    else cout<<S[i];
                }else if(i>=ansl&&i<=ansl+lent-1){
                    printf("%c",T[i-ansl]);
                }else if(i>ansl+lent-1){
                    if(S[i]=='?') printf("a");
                    else cout<<S[i];
                }
            }
        }
    }
	return 0;
}


Measured memory_bytes: 256
import sys
HW = map(int, raw_input().split())
text = []
for i in range(HW[0]):
	 text.append(raw_input())
for j in range(HW[1] + 2):
	sys.stdout.write('#')
print
for i in range(HW[0]):
	sys.stdout.write('#')
	sys.stdout.write(text[i])
	print('#')
for j in range(HW[1] + 2):
	sys.stdout.write('#')
print

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {0,0,1,-1};
const int dx[] = {1,-1,0,0};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}
int k[101][101];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h,w,n;
  cin >> h >> w >> n;
  vector<ll> v(n);
  rep(i,n){
    cin >> v[i];
  }
  ll x = 0, y = 0, d= 0;
  ll c = 0,s = 0;
  while(c < h * w){
    k[x][y] = s+1;
    v[s]--;
    ++c;
    if(v[s] == 0){
      ++s;
      d = 0;
    }
    rep(i,4){
      ll nx = x + dx[i],ny = y + dy[i];
      if(value(nx,ny,w,h) && k[nx][ny] == 0){
        x = nx,y = ny;
        break;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      if(j) cout << ' ' ;
      cout << k[j][i] ;
    }
    std::cout << std::endl;
  }
  return 0;
}


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



Measured memory_bytes: 2140
import sys
input = sys.stdin.readline
n, m = [int(x) for x in input().strip().split()]
a = list(set([int(x)//2 for x in input().strip().split()]))

def lcm(a, b):
    return a * b // gcd(a, b)

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def div2cnt(x):
    ret = 0
    while x % 2 == 0:
        ret += 1
        x //= 2
    return ret

cnt = div2cnt(a[0])

for i, aa in enumerate(a):
    if div2cnt(aa) != cnt:
        print(0)
        exit()
    a[i] >>= cnt
else:
    m >>= cnt

lcm_ = 1
for aa in a:
    lcm_ = lcm(lcm_, aa)
    if lcm_ > m:
        print(0)
        exit()

print((m // lcm_ + 1) // 2)

Measured memory_bytes: 15060
mod = 998244353
N, M, K = map(int, input().split())
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for k in range(K+1):
    tmp_c = cmb(N-1, k, mod)
    tmp_pow = pow(M-1, N-1-k, mod)
    ans += (tmp_c * tmp_pow * M) % mod

print(ans%mod)


Measured memory_bytes: 112624
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static PrintWriter out;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = Integer.parseInt(sc.next());
        int zoromeCount = 0;
        for (int i = 0; i < n; i++) {
            if (zoromeCount >= 3) {
                break;
            }
            int d1 = Integer.parseInt(sc.next());
            int d2 = Integer.parseInt(sc.next());
            if (d1 == d2) {
                zoromeCount++;
            } else {
                zoromeCount = 0;
            }
        }
        if (zoromeCount >= 3) {
            out.println("Yes");
        } else {
            out.println("No");
        }
        sc.close();
        out.close();
    }

}

Measured memory_bytes: 35692
#include<stdio.h>
int main(void) {
	int n, m;
	int k[100], a[100][100];
	int cnt = 0, ans = 0 , flag = 0;
	int i, j,l;

	scanf("%d %d", &n, &m);
	for (i = 0; i < n; i++) {
		scanf("%d", &k[i]);
		for (j = 0; j < k[i]; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	for (i = 1; i <= m; i++) {
		cnt = 0;
		for (j = 0; j < n; j++) {
			flag = 0;
			for (l = 0; l < k[j]; l++) {
				//printf("a[%d][%d]==%d\n", j, l, a[j][l]);
				if (a[j][l] == i) {
					
					//flag = 1;
					cnt++;
					//printf("check a[%d][%d]==%d cnt==%d\n", j, l, a[j][l],cnt);
					break;
				}
			}
			/*if (flag == 0) {
				break;
			}*/
		}
		if (cnt == n) {
			//printf("check2\n");
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
import numpy as np
n = int(input())
a = list(map(int, input().split()))

S = sum(a)
s = np.cumsum(a)
ans = float('INF')

for i in range(n-1):
    x = s[i]
    y = S - x
    ans = min(ans, abs(x - y))

print(ans)

Measured memory_bytes: 33072
use std::io;

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn main() {
    let n: Vec<i32> = read_vec();
    println!(
        "{}",
        if n[0] < n[1] {
            "a < b"
        } else if n[0] > n[1] {
            "a > b"
        } else {
            "a == b"
        }
    );
}



Measured memory_bytes: 5024
#import sys
#input = sys.stdin.readline
def main():
    N = int( input())
    p1, p2, p3, p4 = list( map( int, input().split()))
    t1, t2, t3, t4 = list( map( int, input().split()))
    
    ans = 10000
    for i in range(N+1):
        if i*p1 >= ans:
            break
        if i*t1 >= N:
            ans = i*p1
            break
        for j in range(N+1-i):
            if i*p1 + j*p2 >= ans:
                break
            if i*t1 + j*t2 >= N:
                ans = i*p1 + j*p2
                break
            for k in range(N+1-i-j):
                if i*t1 + j*t2 + k*t3 >= N:
                    if i*p1 + j*p2 + k*p3 < ans:
                        ans = i*p1 + j*p2 + k*p3
                    break
                else:
                    g = (N-i*t1-j*t2-k*t3 + t4-1)//t4
                    if i*p1 + j*p2 + k*p3 + g*p4 < ans:
                        ans = i*p1 + j*p2 + k*p3 + g*p4
    print(ans)

if __name__ == '__main__':
    main()




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

using namespace std;

int main(void) {
	int num, i = 0, buf, ans = 0;
	cin >> num;
	vector<int> d(num + 1, 0);
	for (; i < num; i++) {
		scanf("%d", &buf);
		if (buf > num) {
			ans++;
			continue;
		}
		d[buf]++;
	}
	for (i = 0; i <= num; i++) {
		while (i <= num && d[i] == 0)
			i++;
		if (i > num)
			break;
		if (d[i] < i)
			ans += d[i];
		else
			ans += d[i] - i;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 640
use proconio::input;

struct DP {
    dp: Vec<Vec<Option<i64>>>,
    a: Vec<i64>,
}

impl DP {
    fn new(n: usize, a: Vec<i64>) -> DP {
        DP {
            dp: vec![vec![None; n]; n],
            a: a,
        }
    }

    fn calc(self: &mut DP, l: usize, r: usize) -> i64 {
        if let Some(v) = self.dp[l][r] {
            v
        } else {
            let v = if l == r {
                self.a[l]
            } else {
                std::cmp::max(
                    self.a[l] - self.calc(l + 1, r),
                    self.a[r] - self.calc(l, r - 1)
                )
            };
            self.dp[l][r] = Some(v);
            v
        }
    }
}

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    println!("{}", DP::new(n, a).calc(0, n - 1));
}


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

using System.Collections;

class Program
{
    static void Main()
    {
        var ap = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        int A = ap[0];
        int P = ap[1];

        Console.WriteLine(((A * 3) + P) / 2);

    }
}

Measured memory_bytes: 13268
#include<stdio.h>

int main(void){
	int data[5],work;
	int i,j;

	scanf("%d %d %d %d %d",&data[0],&data[1],&data[2],&data[3],&data[4]);

	for(i=0;i<=3;i++){
		for(j=i+1;j<=4;j++){
			if(data[i]<data[j]){
				work=data[i];
				data[i]=data[j];
				data[j]=work;
			}
		}
	}
	printf("%d %d %d %d %d\n",data[0],data[1],data[2],data[3],data[4]);

	return 0;
}

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


int main(void){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int e=1;e<=10000;e++){
		if(((e*8)/100)==a&&(((e*10)/100)==b)){
			printf("%d",e);
			return 0;
		}
	}
	printf("-1");
	return 0;
}


Measured memory_bytes: 256
n = int(input())

zenbu = n * (n + 1) / 2

A = (sum(i for i in range(1, n + 1) if i % 3 == 0))
B = (sum(i for i in range(1, n + 1) if i % 5 == 0))
C = (sum(i for i in range(1, n + 1) if i % 15 == 0))

D = zenbu - A - B + C

print(int(D))

Measured memory_bytes: 9100
import sys
n, m = map(int, sys.stdin.readline().split())

students = []
points = []
for i in range(n):
    a,b = map(int, sys.stdin.readline().split())
    students.append((a,b))

for i in range(m):
    c,d = map(int, sys.stdin.readline().split())
    points.append((c,d))

for i in range(n):
    distance = 10 ** 9
    index = -1
    for j in range(m):
        tmp_dis = abs(students[i][0] - points[j][0]) + \
                  abs(students[i][1] - points[j][1])
        if tmp_dis < distance:
            distance = tmp_dis
            index = j + 1
    print(index)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long K, long long N, std::vector<long long> A){
  sort(A.begin(),A.end());
  ll mind=K+A.front()-A.back();
  REP(N){
    if(i>0)mind=max(mind,A[i]-A[i-1]);
    else{mind=max(mind,A[i]);}
  }
  cout<<K-mind<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int l;
int main()
{
	cin>>l;
	cout<<3*l*l<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define pb push_back             
#define se second                
#define fi first  
#define be begin()
#define en end()
#define all(v) v.be, v.en
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
template<typename... T> void po(T... args) { ((cout << args << " "), ...); cout<<""; }

 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
     int test=1;
     //cin>>test;
     for(int tt=1; tt<=test; tt++){
       ll n;
       cin>>n;
       string s="";
       //n--;
       while(n>0){
           int k=n%26;
           if(k==0){
               k=26;n-=26;
           }
           s+=('a'+k-1);
           n/=26;
       }
       reverse(all(s));
       pp(s);

     //cout<<"Case #"<<tt<<": ";  
     }
 
    return 0;
}

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

using namespace std;

// m > n
uint64_t gcd(uint64_t m, uint64_t n) {
    if (n == 0)
        return m;

    return gcd(n, m % n);
}

int main() {
    int64_t N;
    cin >> N;

    priority_queue<pair<int64_t, int64_t>> AB;
    int64_t a, b;
    for (int64_t i = 0; i < N; i++) {
        cin >> a >> b;
        AB.push(make_pair(-b, a));
    }

    int64_t s = 0;
    bool f = true;
    while (!AB.empty()) {
        //cout << AB.top().first << " " << AB.top().second << endl;
        s += AB.top().second;
        if (AB.top().first > -s)
            f = false;
        AB.pop();
    }

    cout << (f ? "Yes" : "No") << endl;


    return 0;
}



Measured memory_bytes: 6256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();
        int count = 0;

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            int eat = (d - 1) / a[i];
            count+= eat + 1;
        }
        System.out.println(count + x);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

vector<vector<int>> to;

void dfs(int v, ll now, vll& ans, int p=-1) {
    ans[v] += now;
    now = ans[v];
    for (int i = 0; i < to[v].size(); ++i) {
        int nv = to[v][i];
        if (nv == p) continue;
        dfs(nv, now, ans, v);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, q;
    cin >> n >> q;
    to.resize(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vi p(q), x(q);
    rep(i, q) {
        cin >> p[i] >> x[i];
        p[i]--;
    }

    vll ans(n);
    rep(i, q) {
        ans[p[i]] += x[i];
    }
    ll now = 0;
    dfs(0, now, ans);

    rep(i, n) printf("%lld%c", ans[i], i==n-1?'\n':' ');

}

Measured memory_bytes: 28928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
int n,fa[N];
ll ans,d,a[N],l[N],r[N];
int main()
{
	cin>>n>>d;
	ans=(n-1)*d;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),ans+=a[i],l[i]=r[i]=1e18;
	l[1]=a[1];
	for(int i=2;i<=n;i++)l[i]=min(l[i-1],a[i]-(i-1)*d);
	r[n]=a[n]+(n-1)*d;
	for(int i=n-1;i;i--)r[i]=min(r[i+1],a[i]+(i-1)*d);
	for(int i=2;i<n;i++)ans+=min((i-1)*d+l[i],r[i]-(i-1)*d);
	printf("%lld\n",ans);
}

Measured memory_bytes: 4992
function Main(s){
  s = s.split("\n");
  var n = +s[0];
  var a = s[1].split(" ").map(a=>+a);
  var ans = 0;
  for(var i = 0; i < n; i++){
    while(a[i] % 2 === 0){
      ans++;
      a[i] /= 2;
    }
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 21320
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int main(void)
{

	int H, W;

	while (1) {

		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0)
			break;

		for (int i = 1; i <= H; i++) {
			for (int j = 01; j <= W; j++) {
				if ((i == 1 || i == H) || (j == 1 || j == W)) {
					printf("#");
				}
				else
					printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2696
from collections import Counter

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

cnt = Counter(A) 

A = list(set(A))
A.sort()


C = [0]*(10**6+1)
ans = 0

for a in A:
    if C[a] == 0:
        i = 1
        while True:
            if a*i > 10**6:
                break
            C[a*i] = 1
            i += 1
        if cnt[a] == 1:
            ans += 1

print(ans)

Measured memory_bytes: 45308
package main 

import (
  "fmt"
  "sort"
)

func main() {
  var n int
  fmt.Scan(&n)

  v := make([]float64 ,n)
  for i := 0; i < n; i++ {
    fmt.Scan(&v[i])
  }
  
  for j := 0; j < n-1 ; j++ {
    sort.Float64s(v)
    v = append(v, (v[0]+v[1])/2)
    v = v[2:]
  }
  
  fmt.Println(v[0])
  
}


Measured memory_bytes: 512
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if 500 * a + 100 * b + 50 * c == X:
                ans += 1
print(ans)


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    ll X,Y,Z;
    cin >>X >> Y >> Z;
    ll ans = 0;

    REP(i, 1, X+1)
    {
        if( Z*2+Y+ (i-1)*(Y+Z) <= X ) chmax(ans, (ll)i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
typedef long long ll;
using namespace std;

int main(void) {
	int x[2],y[2];
	cin >> x[0] >> y[0] >> x[1] >> y[1];
	cout << x[1]+y[0]-y[1] << " " << -x[0] + x[1] + y[1] << " " << x[0] + y[0] - y[1] << " " << -x[0] + x[1] + y[0] << endl;
	return 0;
}

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

int main() {
	int r, d, x2000;
	scanf("%d %d %d", &r, &d, &x2000);
	int x = x2000;

	for (int i = 0; i < 10; i++) {
		x = r * x - d;
		printf("%d\n", x);
	}
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;

int main() {
    int a, b;
    cin >> a >> b;

    int ans = 0;
    int i = 0;
    while(a*i - (i-1) < b) {
        i++;
    }

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=[0]*(N+1)
counter=1
looper=0
start=0
loopf=0
now=1
A=[0]+A
if N>K:
    for i in range(0,K):
        now=A[now]
    print(now)
    exit()

while True:
    if B[now]==0:
        B[now]=counter
        counter+=1
        now=A[now]
    else:
        start=B[now]
        loopf=now
        looper=counter-start
        break
K=K+1-start
K=K%looper
for i in range(0,K):
    loopf=A[loopf]
print(loopf)

Measured memory_bytes: 32280
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  llint n,m;cin>>n>>m;
  if(n==1){
  if(m==1){
   cout<<1<<endl;return 0; 
  }else{
   cout<<(m-2)<<endl;return 0;
  }
  }
  if(m==1){cout<<(n-2)<<endl;return 0;}
  cout<<(n-2)*(m-2)<<endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  string ans = "No";
  int price;
  for(int i = 0; i <= N / 4; i++){
    for(int j = 0; j <= N / 7 ; j++){
      price = i * 4 + 7 * j;
      // cout << "i:" << i << ", j:" << j << ", price:" << price << endl;
      if(price == N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

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

using namespace std;

const int H = 1000 + 7;

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;

int main() {
  int n, k;
  cin >> n >> k;
  if(k == 1) cout << 0 << "\n";
  else cout << (n - (k - 1)) - 1 << "\n";
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

MOD = 1000000007
n, m = map(int, input().split())
hole = [0]*(n+1)

for i in range(m): hole[int(input())] = 1

dp = [0]*(n+1)
dp[0] = 1

for i in range(1, n+1):
    if hole[i]: dp[i] = 0
    else:
        dp[i] += dp[i-1] + dp[i-2]
        dp[i] %= MOD

print(dp[n])

Measured memory_bytes: 7796
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int[] n=new int[3];
	    n[0]=gi();
	    n[1]=gi();
	    n[2]=gi();
	    Arrays.parallelSort(n);
        System.out.println(n[0]*n[1]/2);
//        if (n==3 || n==5 || n==7) {
//        	System.out.print("YES");
//        }else {
//        	System.out.print("NO");
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35516
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<31;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

int main() {
    int x; cin >> x;
    if (x == 1) cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3564
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var k = int.Parse(Console.ReadLine());
        var x = int.Parse(Console.ReadLine());
        var y = int.Parse(Console.ReadLine());

        var val = 0;
        for (int i = 0; i < n; i++)
        {
            if (i < k)
            {
                val += x;
            }
            else
            {
                val += y;
            }
        }

        Console.WriteLine(val);
    }
}

Measured memory_bytes: 13140
#include<stdio.h>

char map[50][50];
static int Pmap[52][52];

void check_map(char Map[][50],int H,int W){
  int i,j,l,m;
  
  for(i=0;i<W;i++){
	for(j=0;j<H;j++){
	  if(Map[i][j]=='#'){
		Pmap[i+1][j+1]=9;
		for(l=-1;l<2;l++){
		  for(m=-1;m<2;m++){
			Pmap[i+1+l][j+1+m]++;
		  }
		}
	  }
	}
  }

  for(i=0;i<W;i++){
	for(j=0;j<H;j++){
	  if(Pmap[i+1][j+1]<9)
		printf("%d",Pmap[i+1][j+1]);
	  else
		printf("#");
	}
	putchar('\n');
  }

}

int main(){
  int h,w;
  int i,j;
  
  scanf("%d %d",&h,&w);

  for(i=0;i<h;i++)
	scanf("%s",&map[i]);

  check_map(map,w,h);

  return 0;
}
  


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,k,s;cin>>n>>k>>s;
	for (int i=1;i<=k;++i)cout<<s<<' ';
	if (s==1000000000)
	{
		for (int i=1;i<=n-k;++i)cout<<500000001<<' ';
		return 0;
	}
	for (int i=1;i<=n-k;++i)cout<<s+1<<' ';
}

Measured memory_bytes: 1280
import itertools

(n, m, x) = map(int, input().split())
c = []
a = []
for _ in range(n):
    words = list(map(int, input().split()))
    c.append(words[0])
    a.append(words[1:])

ans = -1
for cart in itertools.product([True, False], repeat=n):
    price = 0
    score = [0] * m
    for ni in range(n):
        if cart[ni]:
            price += c[ni]
            for mi in range(m):
                score[mi] += a[ni][mi]
    score_check = True
    for mi in range(m):
        if score[mi] < x:
            score_check = False
            break
    if score_check:
        if ans == -1:
            ans = price
        else:
            ans = min(ans, price)

print(ans)


Measured memory_bytes: 9108
#include <stdio.h>
// #include <math.h>
#include <stdlib.h>

int main(void) {

    int nelem;
    scanf("%d", &nelem);
    int* a;
    a = (int*)calloc(nelem, sizeof(int));

    for (int i=0; i<nelem; i++) {
        scanf("%d", &a[i]);
    }

    int min = a[0];
    int max = a[0];
    long sum = a[0];

    for (int i=1; i<nelem; i++) {
        if (a[i] < min)
            min = a[i];
        if (a[i] > max)
            max = a[i];
        sum += a[i];
    }

    printf("%d %d %ld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 2756
A, B, C, X, Y = map(int, input().split())

answer_1 = A * X + B * Y # すべてA、Bで買う場合
answer_2 = C * 2 * max(X, Y) # すべてCで買う場合

# answer_3: 先にA,Bを買ってからあまりをCで補う場合
# answer_4: 先にCを買ってから最後に残りA,Bで補う場合
if X > Y:
    answer_3 = A * Y + B * Y + C * (X - Y) * 2
    answer_4 = A * (X - Y) + C * Y * 2
else:
    answer_3 = A * X + B * X + C * (Y - X) * 2
    answer_4 = B * (Y - X) + C * X * 2

answer = min(answer_1, answer_2, answer_3, answer_4)
print(answer)

Measured memory_bytes: 9096
# coding: utf-8
# Your code here!
from operator import itemgetter
N = int(input())
job = [list(map(int, input().split())) for _ in range(N)]
#print(job)
job.sort(key=itemgetter(1))
#print(job)
now = 0
t = 0
for j in job:
    now += j[0]
    if now > j[1]:
        print("No")
        t = 1
        break
if t == 0:
    print("Yes")

Measured memory_bytes: 53732
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      x: chars,
    }
    let mut s = 0;
    let mut cnt = 0;
    for i in 0..x.len() {
        if x[i] == 'S' {
            s += 1;
        } else {
            if s > 0 {
                s -= 1;
                cnt += 1;
            }
        }
    }
    println!("{}", x.len()-cnt*2);
}


Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);
    scanner.nextLine();
    final int[] a = Arrays
        .stream(scanner.nextLine().split(" "))
        .mapToInt(Integer::parseInt)
        .toArray();

    int allXor = a[0];
    for (int i = 1; i < a.length; i++) {
      allXor ^= a[i];
    }

    int[] results = new int[a.length];
    for (int i = 0; i < a.length; i++) {
      results[i] = allXor ^ a[i];
    }

    System.out.println(
        Arrays.stream(results)
            .boxed()
            .map(it -> Integer.toString(it))
            .collect(Collectors.joining(" "))
    );
  }
}


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

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

    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++)
    {
        ans += i;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
H = int(input())
W = int(input())
N = int(input())
if(H<W):
    if(N % W ==0):
        ans=int(N/W)
    else:
        ans=int(N/W)+1
else:
    if(N % H ==0):
        ans=int(N/H)
    else:
        ans=int(N/H)+1

print(ans)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		
		char A = S.charAt(0);
		char B = S.charAt(1);
		char C = S.charAt(2);
		char D = S.charAt(3);
		
		boolean ans = false;
		
		if (A==B) {
			if (C==D && A!=C)
				ans = true;
		}
		
		else if (A==C) {
			if (B==D && A!=B)
				ans = true;
		}
		
		else if (A==D) {
			if (B==C && A!=B)
				ans = true;
		}
		
		if (ans==false)
			System.out.println("No");
		else 
			System.out.println("Yes");
		sc.close();

	}

}

Measured memory_bytes: 22612
#include<stdio.h>


#define limit 1 << 8




void seisuu( int over_zero )
{
	int len = 0 ;

	char out[] = { "00000000" } ;


	while( over_zero > 1 )
	{
		out[ len ] = ( over_zero % 2 ) + '0' ;

		over_zero /= 2 ;


		++len ;
	}


	out[ len ] = over_zero + '0' ;


	len = 8 ;


	while( len-- )
	{
		printf( "%c" ,out[ len ] ) ;
	}


	return ;
}




int shousuu( char *out ,double under_zero )
{
	int p = 0 ;


	while( p < 4 )
	{
		under_zero *= 2 ;

		out[ p++ ] = ( int )under_zero + '0' ;


		under_zero -= ( ( int )under_zero / 1 ) ;


		if( under_zero == 0 )
		{
			return 1 ;
		}
	}


	return -1 ;
}




int main()
{
	double num ;


	while( 1 )
	{
		char out[] = { "0000\n" } ;


		scanf( "%lf" ,&num ) ;


		if( num >= limit || shousuu( out ,num - ( int )num ) == -1 )
		{
			puts( "NA" ) ;

			continue ;
		}


		if( num < 0 )
		{
			return 0 ;
		}



		seisuu( ( int )num ) ;


		printf( "." ) ;


		printf( out ) ;
	}
}

Measured memory_bytes: 632
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;

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

  struct Node {
    int counter = 0;
    deque<int> to;
  };
  vector<Node> nodes(N);
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    nodes[a].to.push_back(b);
    nodes[b].to.push_back(a);
  }
  for (int i = 0; i < Q; ++i) {
    int p, x;
    cin >> p >> x;
    --p;
    nodes[p].counter += x;
  }
  vector<bool> visited(N, false);
  queue<int> q;
  q.push(0); visited[0] = true;
  while (!q.empty()) {
    int cur = q.front(); q.pop();
    visited[cur] = true;
    for (auto& next : nodes[cur].to) {
      if (visited[next])continue;
      nodes[next].counter += nodes[cur].counter;
      q.push(next);
    }
  }
  for (auto& node : nodes)
    cout << node.counter << " ";
}


Measured memory_bytes: 139776
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    cout << n*n*n << endl;
}


Measured memory_bytes: 256
// ------------------
// author: MatsuTaku
// date  : 27/02/2020
// ------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int INF = 1e9+7;

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

  int n; cin>>n;
  vector<int> dp(n+1, INF);
  dp[0] = -1;
  for (int i = 0; i < n; i++) {
    int a; cin>>a;
    int l=0, r=i+1;
    while (l+1<r) {
      auto c=(l+r)/2;
      if (dp[c] >= a)
        r=c;
      else
        l=c;
    }
    dp[r] = a;
  }
  cout << --lower_bound(dp.begin(), dp.end(), INF)-dp.begin() << endl;

  return 0;
}



Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
	
    cout << min(a, b) + min(c, d) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<string.h>
#include <iostream>
#include <algorithm>
#include <cstdlib>
//#include <vector.h>
//#include <malloc.h>
#include <math.h>
using namespace std;
#include<stdlib.h>
#include<stdio.h>


int main(){
    
    int n;
    cin>>n;
    
    do{
        if(n%10==7){
            cout<<"Yes\n";
            return 0;
        }
        n=n/10;
    }while (n!=0);
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

struct unionfind{
    vi data;
    unionfind(int n):data(n, -1){};
    int root(int idx){
        return data[idx] < 0 ? idx : data[idx] = root(data[idx]);
    }
    bool same(int l, int r){
        return (l = root(l))==(r = root(r));
    }
    void join(int l, int r){
        l = root(l); r = root(r);
        if(l != r){
            if(data[l] > data[r])swap(l, r);
            data[l] += data[r];
            data[r] = l;
        }
    }
    int size(int idx){
        return -data[root(idx)];
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    unionfind uf(n);
    for(int i=0;i<m;i++){
        int x, y, z;
        cin >> x >> y >> z;
        x--;y--;
        uf.join(x, y);
    }
    int ret = 0;
    for(auto&& x:uf.data)if(x < 0)ret++;
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 768
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var streams=[];function print(s){streams.push(s);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));
if(streams.length)console.log(streams.join("\n"));

function main(){
  var n = next();
  return 1-n;
}

Measured memory_bytes: 29684
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [1000000000] * n

dp[0] = 0

for i in range(1, n):

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

print(dp[-1])


Measured memory_bytes: 52448