akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]

use std::cmp;
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::ops::*;
use std::process::exit;
use std::str::FromStr;

#[macro_export]
macro_rules! minimum {
    ($($e:expr),+) => {
        {
            let mut res = Vec::new();
            $(
                res.push($e);
            )+
            res.into_iter().min().unwrap()
        }
    };
}

pub const MOD: usize = 1000000007;

fn main() {
    let (x, y): (usize, usize) = input_two();
    if x % y == 0 {
        println!("-1");
    } else {
        println!("{}", (1..).map(|r| x * r).find(|r| r % y != 0).unwrap());
    }
}

pub fn input<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

pub fn input_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>()
}

pub fn input_lines<T: FromStr>(l: usize) -> Vec<T> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input());
    }
    res
}

pub fn input_lines_two<T: FromStr, U: FromStr>(l: usize) -> Vec<(T, U)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_two());
    }
    res
}

pub fn input_lines_three<T: FromStr, U: FromStr, V: FromStr>(l: usize) -> Vec<(T, U, V)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_three());
    }
    res
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}


Measured memory_bytes: 4352
from sys import exit

def f(x):
	if x%2==0:
		return x//2
	else:
		return x*3+1
		
s=int(input())
A=[]
A.append(s)

for i in range(2,10**10):
	if f(s) in A:
		print(i)
		exit()
	else:
		s=f(s)
		A.append(s)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
t = [0] * (M + 1)
p = [0] * N
s = set()
res = float("inf")
for _ in range(M):
  t = [0] * (M + 1)
  for i in range(N): t[a[i][p[i]]] += 1
  x = 0
  y = 0
  for j in range(1, M + 1):
    if y < t[j]:
      x = j
      y = t[j]
  s.add(x)
  for i in range(N):
    while a[i][p[i]] in s:
      p[i] += 1
      if p[i] >= M:
        break
  if max(p) >= M: break
  res = min(res, max(t))
  #print(t, p)
print(min(res, N))

Measured memory_bytes: 43996
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

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

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main = do
  [n] <- readInt
  as  <- concat <$> replicateM n readInt
  mapM_ print $ solve as

solve as = map (\x -> if x == m then n else m) as
 where
  as' = sortOn Down as
  m   = head as'
  n   = head $ tail as'


Measured memory_bytes: 73340
def the_sieve_of_eratosthenes(i):
    s = [j for j in range(2, i + 1)]
    j = 0
    while True:
        if j >= i - 3:
            for k in range(len(s) - 1, 0, -1):
                if s[k] == 0:
                    del s[k]
            return s
        if s[j] != 0:
            for k in range(2 * s[j] - 2, i - 1, s[j]):
                s[k] = 0
        j += 1

n = int(input())
p = the_sieve_of_eratosthenes(55555)
ans = []
i = 0
for _ in range(n):
    while True:
        if p[i] % 10 == 1:
            ans.append(p[i])
            i += 1
            break
        i += 1
print(" ".join(map(str, ans)))

Measured memory_bytes: 5272
K,N=map(int,input().split())
A=list(map(int,input().split()))
List=[]
for i in range(N):
  b=A[i]-A[i-1]
  if b < 0:
    b=K+b
  List.append(b)
SL=sorted(List)
print(K-SL[-1])

Measured memory_bytes: 26436
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007

lli bin(lli x,lli y)
{
    lli res=1;
    while (y>0)
    {
        if(y&1)
        {
            res = (res*x)%mod;
        }
        x = (x*x)%mod;
        y=y>>1;
    }
    return res;
}

int main() {
    lli n;
    cin>>n;
    if(n==1)
    {
        cout<<0;
        return 0;
    }
    lli total=((bin(10,n)+bin(8,n))%mod-(2*bin(9,n))%mod + mod)%mod;
    cout<<total;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n;
vector<llong> arr;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        llong x;
        cin >> x;
        arr.push_back(x);
    }

    sort(arr.begin(), arr.end());
    arr.erase(unique(arr.begin(), arr.end()), arr.end());

    cout << arr.size() << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define s second
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define f first
const ll N=1e3+5;
ll bexpo(ll x,ll n){
    if(n==0)return 1;
    else if(n%2==0)return bexpo(x*x,n/2);
    else return x*bexpo(x*x,(n-1)/2);
}
ll gcd(ll a,ll b){if(!b)return a;return gcd(b,a%b);} 
int Arr[N];
void initialize()
{
    for(int i = 0;i<N;i++)
    Arr[ i ] = i ;
}
int root(int i)
{
    while(Arr[ i ] != i)       
    {
     i = Arr[ i ];
    }
    return i;
}

void unio(int A ,int B)
{
    int root_A = root(A);       
    int root_B = root(B);  
    if(root_A<root_B)
        Arr[ root_A ] = root_B ;    
    else
        Arr[root_B]=root_A;
}
bool find(int A,int B)
{
    if( root(A)==root(B) )    
    return true;
    else
    return false;
}
ll dp[N][N];
vector<ll> adj[N];
string a[N];
ll h,w;
ll dfs(ll i,ll j)
{
   if(i>h || j>w)
    return 0;
    if(dp[i][j]!=-1)
         return dp[i][j];
       if(i==h && j==w)
    return 1;
       ll cnt=0;
    for(ll x=0;x<=1;x++)
    {
      for(ll y=0;y<=1;y++)
      {
        if(x!=y && a[i+x-1][j+y-1]=='.')
          cnt=(cnt+dfs(i+x,j+y))%mod;
      }
    }
    return dp[i][j]=cnt;
}
int main() {
FIO;
  cin>>h>>w;
  ll i,j;
  for(i=0;i<h;i++)
  {
        cin>>a[i];
  }
  for(i=1;i<=h;i++)
      for(j=1;j<=w;j++)
        dp[i][j]=-1;
  cout<<dfs(1,1);
}

Measured memory_bytes: 12720
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int N;
int main()
{
	cin >> N;
	int a[100];

	rep(i, 0, N) {
		cin >> a[i];
	}

	sort(a, a + N);
	reverse(a, a + N);
	ll sum = 0;

	rep(i, 0, N) {
		sum += (i % 2 == 0) ? a[i] : -a[i];
	}
	cout << sum << endl;

	return 0;
}

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

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static long Calc(int x, int[] xs) {
        long ans = 0;
        for (int i = 1; i < xs.Length; i++) {
            int n = xs[i-1] + xs[i];

            // Console.WriteLine("i:{0} n:{1} x:{2}", i, n, x);
            if (n > x) {
                int m = n - x;

                int t = Math.Min(m, xs[i]);
                xs[i] -= t;
                m -= t;

                ans += t;
                if (m > 0) {
                    xs[i-1] -= m;
                    ans += m;
                }
            }
        }
        return ans;
    }

    static void Main() {
        var nx = ReadInts();
        var xs = ReadInts();

        var ans = Calc(nx[1], xs);
        Console.WriteLine(ans);
    }
}

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

using namespace std;

int main()
{
    int X;
    cin >> X;
    if(X < 500){
        cout<<X/5*5<<endl;
    }else if(500 <= X && X < 1000){
        cout<<1000+(X-500)/5*5<<endl;
    }else{
        cout<<X/500*1000+X%500/5*5<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,T;
cin>>N>>T;
vector<pair<int,int>>c(N);
for(int i=0;i<N;i++){
    cin>>c[i].first>>c[i].second;
}
sort(c.begin(),c.end());
for(int i=0;i<N;i++){
    if(c[i].second<=T){
        cout<<c[i].first;
        return 0;
    }
}
cout<<"TLE";
return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int solve(int n, string& s) {
  int x{}, ret = 0;
  REP(i, n) {
    if (s[i] == 'I')
      ++x;
    else
      --x;
    ret = max(ret, x);
  }
  return ret;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  cout << solve(n, s) << endl;
}


Measured memory_bytes: 256
s = int(input())
M = 1000000

a = [s]
for i in range(1, M):
    if a[i-1] % 2 == 0:
        a.append(int(a[i-1] /2))
    else:
        a.append(int(a[i-1] * 3 + 1))
    
    if a.count(a[i]) > 1:
        break
    
print(i+1)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
  int i, j, tmp;
  int w[10] = {};
  int k[10] = {};
  int sum_w = 0;
  int sum_k = 0;

  for (i = 0; i < 10; i++){
    scanf("%d", &w[i]);
  }

  for (i = 0; i < 10; i++){
    scanf("%d", &k[i]);
  }

  for (i = 0; i < 9; i++){
    for(j = 0; j < 9; j++){
      if (w[j] < w[j + 1]){
        tmp = w[j];
        w[j] = w[j + 1];
        w[j + 1] = tmp;
      }
    }
  }


    for (i = 0; i < 9; i++){
      for(j = 0; j < 9; j++){
        if (k[j] < k[j + 1]){
          tmp = k[j];
          k[j] = k[j + 1];
          k[j + 1] = tmp;
        }
      }
    }

    for (i = 0; i < 3; i++){
      sum_w += w[i];
      sum_k += k[i];
    }

    printf("%d %d\n", sum_w, sum_k);

    return (0);

}

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

int main(){
    string s;
    cin >> s;
    if(
        (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ||
        (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) ||
        (s[0] == s[3] && s[1] == s[2] && s[0] != s[1])
    ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k,n,ans;
  cin>>k>>n;
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  ans=vec.at(0)+k-vec.at(n-1);
  for(int i=1; i<n; i++){
    ans=max(ans,vec.at(i)-vec.at(i-1));
  }
  ans=k-ans;
  cout<<ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

#define ll long long

ll mul(ll a, ll b, ll Mod) {
	return ((__int128) a) * b % Mod;
}

template <typename T>
ll qpow(ll a, T p, ll Mod) {
	ll rt = 1;
	for ( ; p; a = mul(a, a, Mod), p >>= 1) {
		if (p & 1) {
			rt = mul(rt, a, Mod);
		}
	}
	return rt;
}

template <typename T>
void exgcd(T a, T b, T& d, T& x, T& y) {
	if (!b) {
		d = a, x = 1, y = 0;
	} else {
		exgcd(b, a % b, d, y, x);
		y -= (a / b) * x;
	}
}
template <typename T>
T inv(T a, T Mod) {
	T d, x, y;
	exgcd(a, Mod, d, x, y);
	assert(d == 1);
	return (x < 0) ? (x + Mod) : x;
}

boolean excrt(ll a0, ll m0, ll a1, ll m1, ll& a, ll& m) {
	// a0 + k_0 m_0 = a_1 + k_1 m_1
	// x m_0 + (-y) m_1 = a_1 - a_0
	ll d, x, y, da = a1 - a0;
	exgcd(m0, m1, d, x, y);
	if (da % d)
		return false;
	ll k0 = mul(x, da / d, m1 / d);
	m = m0 / d * m1;
	a = a0 + k0 * m0;
	(a < 0) && (a += m);
	return true;
}

#define pii pair<int, int>

vector<pii> factorize(int n) {
	vector<pii> rt;
	for (int i = 2; i * i <= n; i++) {
		if (!(n % i)) {
			int t = 0;
			while (!(n % i))
				t++, n /= i;
			rt.emplace_back(i, t);
		}
	}
	if (n > 1) {
		rt.emplace_back(n, 1);
	}
	return rt;
}

int T;
int a, m;
vector<ll> ms;
vector<ll> as;

int x;

void solve(int a, int p, int r) {
	if (!(a % p)) {
		int M = 1;
		for (int i = 0; i < r; i++, M *= p);
		ms.push_back(M);
		as.push_back(0);
		return;
	}
	ll m0 = p - 1, m1 = p, a0 = x % m0, a1;
	for (int i = 1; i <= r; i++) {
		a1 = qpow(a, a0, m1);
		assert(excrt(a0, m0, a1, m1, a0, m0));
		m1 *= p;
	}
	ms.push_back(m0);
	as.push_back(a0);
}

ll solve(int _a, vector<pii>& fac) {
	ms.clear();
	as.clear();
	for (auto x : fac) {
		solve(_a, x.first, x.second);	
	}
	ll a = 0, m = 1;
	int t = ms.size();
	for (int i = 0; i < t; i++) {
		if (!excrt(a, m, as[i], ms[i], a, m)) {
			return -1;
		}
	}
	while (a < 40)
		a += m;
	return a;
}

int	myrand() {
	const unsigned msk = (1u << 30) - 1; 
	return ((((unsigned) rand()) << 15) ^ rand()) & msk;
}

int main() {
	srand((unsigned) time (NULL));
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &a, &m);
		vector<pii> fac = factorize(m);
		int prod = 1;
		for (auto x : fac)
			prod *= (x.first - 1);
		ll ans = -1;
		while (ans == -1) {
			x = myrand() % prod;
			ans = solve(a, fac);
		}
//		cerr << x << '\n';
//		cerr << qpow(a, ans, m) << " " << ans % m << '\n';
		printf("%lld\n", ans);
	}
	return 0;
}



Measured memory_bytes: 3760
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
        while(true){
	    int n= sc.nextInt();
	    if(n==0)break;
	    int[] scores=new int[n];
	    for(int i=0;i<n;i++){
		scores[i]=sc.nextInt();
	    }
	    int sum=scores[0]+scores[1];
	    int max;
	    int min;
	    if(scores[0]>scores[1]){
		max=scores[0];
		min=scores[1];
	    }
	    else{
		max=scores[1];
		min=scores[0];
	    }
	    for(int i=2;i<n;i++){
		if(scores[i]>max) max=scores[i];
		if(scores[i]<min) min=scores[i];
		sum+=scores[i];
	    }
	    sum-=(max+min);
	    System.out.println(sum/(n-2));
	}
    }
}

Measured memory_bytes: 29472
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  string s,t;
  cin>>s>>t;
  int ans = MOD;
  int temp = 0;
  if(s.size() == t.size()){
    for(int i = 0;i<s.size();i++){
      if(s.at(i) != t.at(i)){
        temp++;
      }
    }
    ans = temp;
  }
  for(int i = 0;i<(s.size()-t.size());i++){
    temp = 0;
    for(int k = 0;k<t.size();k++){
      if(s.at(i+k) != t.at(k)){
        temp++;
      }
    }
    ans = min(ans,temp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
ng = False	
s = input()
n = len(s)
for i in range(n//2):
	if s[i] != s[n-1-i]:
		ng = True
for i in range(((n-1)//2)//2):
	if s[i] != s[(n-1)//2 - 1 - i]:
		ng = True

if ng:
	print("No")
else:
	print("Yes")

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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(ll n, ll 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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,k;
    cin>>n>>m>>k;
    COMinit();
    ll xsum=0,ysum=0;
    rep2(i,1,n){
        xsum+=(((n-i) *m %MOD) *m %MOD)*i;
        xsum%=MOD;
    }
    rep2(i,1,m){
        ysum+=(((m-i) *n %MOD) *n %MOD)*i;
        ysum%=MOD;
    }
    ll ans=(xsum+ysum)% MOD;
    ans *= COM(n*m-2,k-2);
    ans%=MOD;
    cout<<ans<<endl;
    return 0;
}

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

int main(void) {

  int N, count = 0;
  vector<int> h;

  cin >> N;
  h.reserve(N);
  for (int i = 0; i < N; i++) cin >> h[i];

  while(true) {
    int mn = 100;
    int l = -1, r = N - 1;

    for (int i = 0; i < N; i++) {
      if (h[i] > 0) {
        l = i;
        break;
      }
    }

    if (l == -1) break;

    for (int i = l; i < N; i++) {
      if (h[i] == 0) {
        r = i - 1;
        break;
      }
      mn = min(mn, h[i]);
    }

    for (int i = l; i <= r; i++) {
      h[i] -= mn;
    }
    count += mn;
  }

  cout << count;

  return 0;
}

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

int main() {
	int n;
	cin >> n;
	const ll INF = 1001001001;
	vector<int> dp(n+1, INF);
	set<int> c;
	ll tmp = 1;
	while (tmp <= n) {
		c.insert(tmp);
		tmp *= 6;
	}
	tmp = 1;
	while (tmp <= n) {
		c.insert(tmp);
		tmp *= 9;
	}
	dp[0] = 0;
	rep(i, n) {
		for(int t: c) {
			int now = i + t;
			if (now > n) continue;
			dp[now] = min(dp[now], dp[i]+1);
		}
	}
	cout << dp[n] << endl;
	return 0;
}

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

int main(){
  long long int n,i,k,kotae=0;
  cin>>n;
  long long int dp[3][n];
  for(i=0;i<n;i++){
    dp[0][i]=0;
    dp[1][i]=0;
    dp[2][i]=0;
  }
  if(n%2==1){
    cin>>k;
    dp[0][0]=k;
    cin>>k;
    dp[1][1]=k;
    cin>>k;
    dp[0][2]=dp[0][0]+k;
    dp[2][2]=k;
    for(i=3;i<n;i++){
      cin>>k;
      if(i%2==0){
        dp[0][i]=dp[0][i-2]+k;
        dp[2][i]=max(max(dp[2][i-2],dp[1][i-3]),dp[0][i-4])+k;
      }else{
        dp[1][i]=max(dp[1][i-2],dp[0][i-3])+k;
      }
    }
    kotae=max(max(dp[2][n-1],dp[1][n-2]),dp[0][n-3]);
  }else{
    cin>>k;
    dp[0][0]=k;
    cin>>k;
    dp[1][1]=k;
    for(i=2;i<n;i++){
      cin>>k;
      if(i%2==0){
        dp[0][i]=dp[0][i-2]+k;
      }else{
        dp[1][i]=max(dp[1][i-2],dp[0][i-3])+k;
      }
    }
    kotae=max(dp[1][n-1],dp[0][n-2]);
  }
  cout<<kotae;
}

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

int main()
{
    data_type a,b,c,ans;
cin>>a>>b;
   for(int i=1;i<1000000;i++)
   {
      if((i*8)/100==a && (i*10)/100==b)
      {
         cout<<i<<endl;
         return 0;
      }
   }
   cout<<-1<<endl;
    return 0;
}



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

int main() {
    double d, t, s;
    cin >> d >> t >> s;
    if(d / s <= t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    
    string s;
    
    cin>>s;
    
    if(s[2]==s[3] && s[4]==s[5])
    {
    
        cout<<"Yes";
    
    }
    else
    {
    
        cout<<"No";
    
    }
    
}


Measured memory_bytes: 256
#C
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[0])
ans = 0
count = 0
for i in range(n):
    if m < ab[i][1]:
        ans += m * ab[i][0]
        break
    ans += ab[i][0] * ab[i][1]
    m-=ab[i][1]
    if count >= m:
        break
print(ans)

Measured memory_bytes: 29024
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
#include<numeric>
#include<chrono>
#include <fstream>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
#define mkp(a,b) make_pair(a,b)
using namespace std;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	// This is code taken from geeksforgeek
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
/*ll power(ll x, ll y)
{
	// This is code taken from geeksforgeek
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}*/
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x);

		y = y >> 1;
		x = (x * x);
	}
	return res;
}


/*ll modInverse(ll n, ll p)
{
	return power(n, p - 2, p);
}*/

ll sum(ll n)
{
	return (n * (n + 1)) / 2;
}
ll sum_digit(ll n)
{
	ll ans = 0;
	while (n)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	string s;
	cin>>s;
	if(s[s.length()-1]=='s')
	{
		cout<<s<<"es";
	}
	else
	{
		cout<<s<<"s";
	}
	
	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using ll=long long;

const int di[]={-1,0,1,0};
const int dj[]={0,-1,0,1};

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;++i) cin >> s[i];

  ll ans=0;
  vector<vector<bool>> visit(h,vector<bool>(w,false));
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(visit[i][j])continue;
      visit[i][j]=true;
      vector<ll> num(2,0);
      queue<P> que;
      que.push(P(i,j));

      while(!que.empty()){
        auto p = que.front();
        que.pop();
        int x=p.first;
        int y=p.second;
        if(s[x][y]=='#') num[1]++;
        else num[0]++;
        for(int dir=0;dir<4;++dir){
          int nx=x+di[dir];
          int ny=y+dj[dir];
          if(nx<0 || nx>=h || ny<0 || ny>=w) continue;
          if(visit[nx][ny])continue;
          if(s[x][y]==s[nx][ny])continue;
          que.push(P(nx,ny));
          visit[nx][ny]=true;
        }
      }
      ans+=num[0]*num[1];
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

const int mxn = 1e5;

int a[mxn + 11];

int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		scanf("%d", a + i);
	}
	sort(a, a + m);
	vector <int> v;
	for (int i = 0; i < m - 1; i++){
		int x = a[i] - a[i + 1];
		if (x < 0)
			x = -x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	long long ans = 0;
	for (int i = 0; i < m - n; i++){
		ans += 1LL * v[i];
	}
    printf("%lld\n", ans);
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int c;
string s, t = "CODEFESTIVAL2016";

int main() {
	cin >> s;
	rep(i,16) c += (s[i] != t[i]);
	cout << c << ln;
}

Measured memory_bytes: 256
X = int(input())
count = 0
flag = False
for i in range(X, 100004):
    for k in range(2,X):
        if i%k==0:
        	break
        else:
            count += 1
        if count == X-2:
            print(i)
            flag = True
            break
    if flag:
        break
if X == 2:
    print(2)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

struct UnionFind{
    int sz;     // vertex number
    vector<int> par;
    vector<int> rank;

    UnionFind(int n) : sz(n) {
        par.resize(sz);
        rank.assign(sz, 0);
        for(int i = 0; i < sz; ++i){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x) return x;
        else    return par[x] = find(par[x]);
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y)  return;
        if(rank[x] < rank[y])   par[x] = y;
        else{
            par[y] = x;
            if(rank[x] == rank[y])  ++rank[x];
        }
    }
};


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

    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    for(int i = 0; i < n; ++i){
        cin >> p[i];
        --p[i];
    }
    UnionFind uf(n);
    for(int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        --x, --y;
        uf.unite(x, y);
    }
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(uf.same(i, p[i]))    ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

ll dp[55][2];
int a[55];

int32_t main()
{
    #ifdef DEBUG
    freopen("A.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int n,p;
    read(n); read(p);
    for0(i,n) {
        read(a[i]);
    }

    ms(dp,0);
    dp[n][0] = 1;
    for (int i=n-1; i>=0; i--) {
        for (int k=0; k<=1; k++) {
            if (a[i]%2 == 0) {
                dp[i][k] = dp[i+1][k]*2;
            }
            else
                dp[i][k] = dp[i+1][k] + dp[i+1][1-k];
        }
    }
    cout<<dp[0][p]<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce

k = int(input())

def gcd2(*numbers):
    return reduce(math.gcd,numbers)
sum = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        for c in range(b,k+1):
            if len(set([a,b,c]))==2:
                sum = sum + gcd2(a,b,c)*3
            elif len(set([a,b,c]))==1:
                sum = sum + gcd2(a,b,c)
            else:
                sum = sum + gcd2(a,b,c)*6
            #print(gcd2(a,b,c))


print(sum)
        

Measured memory_bytes: 9632
def al_cnt(k,s):
    count = 0
    if 'a' in s[:k] and 'a' in s[k:]:
        count += 1
    if 'b' in s[:k] and 'b' in s[k:]:
        count += 1
    if 'c' in s[:k] and 'c' in s[k:]:
        count += 1
    if 'd' in s[:k] and 'd' in s[k:]:
        count += 1
    if 'e' in s[:k] and 'e' in s[k:]:
        count += 1
    if 'f' in s[:k] and'f' in s[k:]:
        count += 1
    if 'g' in s[:k] and 'g' in s[k:]:
        count += 1
    if 'h' in s[:k] and 'h' in s[k:]:
        count += 1
    if 'i' in s[:k] and 'i' in s[k:]:
        count += 1
    if 'j' in s[:k] and 'j' in s[k:]:
        count += 1
    if 'k' in s[:k] and 'k' in s[k:]:
        count += 1
    if 'l' in s[:k] and 'l' in s[k:]:
        count += 1
    if 'm' in s[:k] and 'm' in s[k:]:
        count += 1
    if 'n' in s[:k] and 'n' in s[k:]:
        count += 1
    if 'o' in s[:k] and 'o' in s[k:]:
        count += 1
    if 'p' in s[:k] and 'p' in s[k:]:
        count += 1
    if 'q' in s[:k] and 'q' in s[k:]:
        count += 1
    if 'r' in s[:k] and 'r' in s[k:]:
        count += 1
    if 's' in s[:k] and 's' in s[k:]:
        count += 1
    if 't' in s[:k] and 't' in s[k:]:
        count += 1
    if 'u' in s[:k] and 'u' in s[k:]:
        count += 1
    if 'v' in s[:k] and 'v' in s[k:]:
        count += 1
    if 'w' in s[:k] and 'w' in s[k:]:
        count += 1
    if 'x' in s[:k] and 'x' in s[k:]:
        count += 1
    if 'y' in s[:k] and 'y' in s[k:]:
        count += 1
    if 'z' in s[:k] and 'z' in s[k:]:
        count += 1
    return count
n = int(input())
s = input()
ans = 0
for i in range(1,n-1):
    temp = al_cnt(i,s)
    ans = max(ans,temp)
print(ans)

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

using namespace std;

const int N = 1e5 + 5;
int n, h[N], ans, dp[N];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;++i)cin>>h[i];

	dp[2] = abs(h[2] - h[1]);
	for(int i=3;i<=n;++i){
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}
	cout<<dp[n]<<"\n";
	return 0;
}

Measured memory_bytes: 1024
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
def f(x,y):
    return int((x+y-1)/y)

if e<d:
    d=e
if d<c:
    c=d
if c<b:
    b=c
if b<a:
    a=b
print(f(n,a)+4)
    


Measured memory_bytes: 9172
#include<stdio.h>
#include<string.h>
int main(void)
{
  char s[200010],t[200010];
  int len,count=0;
  int start[26],goal[26];
  int i;
  for(i=0;i<26;i++){
    start[i] = -1;
    goal[i] = -1;
  }
  scanf("%s %s",&s,&t);
  len = strlen(s);
  for(i=0;i<len;i++){
    int a = s[i] - 'a';
    int b = t[i] - 'a';
    if(start[a] != -1 || goal[b] != -1){
      if(start[a] != b || goal[b] != a){
        count = 1;
        break;
      }
    }else{
      start[a] = b;
      goal[b] = a;
    }
  }
  puts(count==0?"Yes":"No");
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>

//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//// 任意長整数型
//using Bint = mp::cpp_int;
//// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
//
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int,int> P;

const int MOD = 1000000007;


int main(int argc, const char * argv[]) {
    ll N,K; cin >> N >> K;
    vector<ll> A(N);
    for(ll i=0;i<N;i++){
        cin >> A[i];
        A[i]--;
    }
    vector<bool> flag(N,false);
    ll next=0;
    ll i,before=0;
    ll start,end;
    for(i=0;i<N && i<K;i++){
        if(i==K){
            cout << next+1 << endl;
            return 0;
        }
        if(flag[next]==false){
            flag[next] = true;
        }else{
            start = next;
            end = before;
            break;
        }
        
        before = next;
        next = A[next];
        if(next == before){
            cout << next+1 << endl;
            return 0;
        }
    }
    if(i==K){
        cout << next+1 << endl;
        return 0;
    }
    
//    cout << "iの値は " << i<< endl;
    
    K -= i;
//    ループの長さを調べる
    ll loop_length=0;
    vector<bool> flag2(N,false);
    ll next_node=start;
    for(ll i=0;i<N;i++){
        if(flag2[next_node]==false){
            flag2[next_node]=true;
            next_node = A[next_node];
            loop_length++;
        }else{
            break;
        }
    }
//    cout << "loop_lenght : " << loop_length << endl;
    ll ans = K % loop_length;
//    cout << "ans : " << ans << endl;
    next_node = start;
    ll before_node = start;
    for(ll i=0;i<ans;i++){
        before_node = next_node;
        next_node = A[next_node];
    }
    
    cout << next_node+1 << endl;
    
    return 0;
}



Measured memory_bytes: 4848
def solve(n, m, h_list, ab_list):

    t_dict = {i:[] for i in range(1,n+1)}
    for a, b in ab_list:
        t_dict[a].append(b)
        t_dict[b].append(a)
    
    ans = 0
    for k, v in t_dict.items():
        th = h_list[k-1]
        if len([x for x in v if h_list[x-1] >= th]) == 0:
           ans += 1

    return ans

    
if __name__ == "__main__":
    n, m = [int(i) for i in input().split()]
    h_list = [int(i) for i in input().split()]
    ab_list = [[int(j) for j in input().split()] for i in range(m)]
    print(solve(n,m,h_list, ab_list))


Measured memory_bytes: 48124
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    ArrayList<Integer> ar = new ArrayList<Integer>();
    int N = sc.nextInt();
    int T = sc.nextInt();
    for(int i=0;i<N;i++){
      int c = sc.nextInt();
      int t = sc.nextInt();
      if(t <= T){
        ar.add(c);
      }
    }
    if(ar.size() != 0){
      Collections.sort(ar);
      System.out.println(ar.get(0));
    }else{
      System.out.println("TLE");
    }
  }
}


Measured memory_bytes: 22868
import sys
N,Y=map(int,input().split())

for y in range(N+1):
	for x in range(N-y+1):
		if 9000*x+4000*y==Y-1000*N:
			print(x,y,N-x-y)
			sys.exit()
		elif  9000*x+4000*y>Y-1000*N:
			break

else:
	print("-1 -1 -1")
	

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;

void chmin(long& x, long y)
{
	if (x > y)
		x = y;
}

void core()
{
	size_t N;
	cin >> N;

	string hs_str;
	std::vector<long> hs(N);
	for (size_t i = 0; i < N; ++i)
	{
		cin >> hs_str;
		hs[i] = stoi(hs_str);
		//cout << hs[i] << endl;
	}


	vector<long> dp(N + 1, 1000000000000);
	dp[1] = 0;
	chmin(dp[2], dp[1] + std::abs(hs[1] - hs[0]));


	for (size_t i = 3; i <= N; ++i)
	{
		chmin(dp[i], dp[i-1] + std::abs(hs[i - 1] - hs[i - 2]));
		chmin(dp[i], dp[i - 2] + std::abs(hs[i - 1] - hs[i - 3]));
	}

	long ret = dp[N];
	cout << ret;
}

int main()
{
	core();
	return 0;
}

Measured memory_bytes: 1792
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

dp = [float('inf')] * N
dp[0] = 0

Fmin = min
Fabs = abs
Fzip = zip
for i, hi in enumerate(h):
    if i == 0:
        continue
    x = (0 if i-K < 0 else i-K)
    dp[i] = Fmin([dpj + Fabs(hi - hj) for dpj, hj in Fzip(dp[x:i], h[x:i])])

print(dp[-1])

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

#define INF 1000000

typedef pair<int,int>P;

char maps[1001][1001];
int check[1000][1000];
int dy[4]={-1,0,1,0};
int dx[4]={0,-1,0,1};
int h,w,cheese;
int sy,sx;
char tekitou='1';

int bfs(){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      check[i][j]=INF;
    }
  }
  queue<P> que;
  que.push(P(sy,sx));
  check[sy][sx]=0;
  while(!que.empty()){
    P p=que.front();que.pop();
    int y=p.first;
    int x=p.second;
    //goal
    if(maps[y][x]==tekitou){
      tekitou+=1;
      sy=y;
      sx=x;
      return check[y][x];
    }
    for(int i=0;i<4;i++){
      int ny = y+dy[i];
      int nx = x+dx[i];
      if(ny>=0 && ny<h && nx>=0 && nx<w && check[ny][nx]==INF && maps[ny][nx]!='X'){
	check[ny][nx]=check[y][x]+1;
	que.push(P(ny,nx));
      }
    }
  }
}

int main(){
  int ans=0;
  cin>>h>>w>>cheese;
  for(int i=0;i<h;i++){
    cin>>maps[i];
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(maps[i][j]== 'S' ){
	sy=i;
	sx=j;
	break;
      }
    }
  }
  ans+=bfs();

  for(int i=0;i<cheese-1;i++){
    ans+=bfs();
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6104
#include <iostream>
#include <limits.h>
using namespace std;

int main() {
	long long k;
	cin >> k;
	long long n = 50;
	cout << n << endl;
	
	long long sho = k / n, amari = k % n;
	long long kihon = 49 + sho;
	
	for (int i = 0; i < n - amari; i++) cout << kihon - amari << " ";
	for (int i = n - amari; i < n - 1; i++) cout << kihon + n + 1 - amari << " ";
	if (amari != 0) cout << kihon + n + 1 - amari << endl;
	
}


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

int main() {
  int cou =0;
  string a;
  cin >> a;
  for(int i =0;i<3;i++){
    if(a == "RSR"){
      cou++;
      break;
    }
    if (a.at(i) == 'R'){
      cou++;
    }
   }
  cout << cou <<endl;
}


Measured memory_bytes: 3580
class PriorityQueue
  @@INF = 1.0 / 0
  #?????????
  def initialize
    @queue = Array.new(1)
    @queue[0] = -114514
  end

  #???????????????????´??????????
  def top
    @queue[1]
  end

  #???????????????????´??????????????????????????´??????????
  def pop
    return if @queue.size < 1
    top = @queue[1]
    @queue[1] = @queue[@queue.size - 1]
    @queue.pop
    max_heap(1)
    top
  end

  #?????\
  def push(n)
    @queue.push(n)
    @queue[@queue.size - 1] = -1 * @@INF
    increase_key(@queue.size - 1,n)
  end

  #????????????????
  def empty?
    @queue.size == 1
  end

  #????´???°
  def size
    @queue.size - 1
  end

  #?????\?????????
  def increase_key(i,key)
    return if key < @queue[i]
    @queue[i] = key
    while i > 1 && @queue[i / 2] < @queue[i] do
      @queue[i],@queue[i / 2] = @queue[i / 2],@queue[i]
      i = i / 2
    end
  end

  #?????§???
  def max_heap(i)
    l = 2 * i
    r = 2 * i + 1
    if l< @queue.size && @queue[l] > @queue[i] then largest = l
    else largest = i end
    largest = r if r < @queue.size && @queue[r] > @queue[largest]
    if largest != i then
      @queue[i],@queue[largest] = @queue[largest],@queue[i]
      max_heap(largest)
    end
  end

  #?????§?????´??°
  def build_max_heap!
    return if @queue.size == 2
    (@queue.size / 2).downto(1) do |i|
      max_heap(i)
    end
  end
end

pq = PriorityQueue.new
loop do
  input = gets.split
  if input[0][0] == "i" then
    pq.push(input[1].to_i)
  elsif input[0] == "extract" then
    puts pq.pop
  else
    break
  end
end


Measured memory_bytes: 16604
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	mp := map[string]int{}
	for i := 0; i < n; i++ {
		s := sc.NextLine()
		mp[s]++
	}
	n = sc.NextInt()
	for i := 0; i < n; i++ {
		s := sc.NextLine()
		mp[s]--
	}

	mx := 0

	for _, v := range mp {
		if v > mx {
			mx = v
		}
	}
	fmt.Printf("%+v\n", mx) // output for debug
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      float a = sc.nextFloat();
      float b = sc.nextFloat();
      float c = sc.nextFloat();
      float d = sc.nextFloat();
      float e = sc.nextFloat();
      float f = sc.nextFloat();
      float x = (c*e-b*f)/(a*e-d*b);
      float y = (c*d-a*f)/(b*d-a*e);
      if(x == 0) {
        x = 0;
      }
      if(y == 0) {
	y = 0;
      }
      System.out.println(String.format("%.3f %.3f", x, y));
    }    
  }
}

Measured memory_bytes: 28516
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = sorted(a - b for a, b in zip(A, B))

def f():
    i, j = 0, len(D) - 1
    p = 0
    ans = 0
    #print(D)
    while j >= i:
        # print(i, j, D[i], D[j], p)
        if D[i] >= 0:
            return ans
        if p >= -D[i]:
            p += D[i]
            i += 1
            ans += 1
            continue
        p += D[j]
        j -= 1
        ans += 1
    if p >= 0:
        return ans
    return -1

print(f())

            
        


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

int main() {
    int N,M;
    cin >> N;
    vector<string> sN(N);
    for(int i = 0; i<N; i++) cin >> sN.at(i);
    cin >> M;
    vector<string> sM(M);
    for(int i = 0; i<M; i++) cin >> sM.at(i);
    
    vector<int> ans(N,1);
    for(int i = 0; i<N; i++){
        for(int i2 = 0; i2 < N; i2++){
            if(i == i2) continue;
            else if(sN.at(i) == sN.at(i2)) ans.at(i)++;
        }
        for(int i3 = 0; i3 < M; i3++){
            if(sN.at(i) == sM.at(i3)) ans.at(i)--;
        }
    }
    int max = ans.at(0);
    for(int i = 1; i<N; i++){
        if(ans.at(i) > max) max = ans.at(i);;
    }
    if(max < 0) cout << 0 << endl;
    else cout << max << endl;
}

Measured memory_bytes: 256
class Cards:
    def __init__(self,shape,value):
        self.shape = shape
        self.value = value

n = int(input())
s = input().split(" ")
cards1 = []
for i in range(n):
    cards1.append(Cards(s[i][0],int(s[i][1])))
cards2 = list(cards1)
for i in range(n):
    for j in range(n-1,i,-1):
        if cards1[j].value < cards1[j-1].value:
            w = cards1[j]
            cards1[j] = cards1[j-1]
            cards1[j-1] = w
for i in range(n):
    if i == n-1:
        print("{0}{1}".format(cards1[i].shape,cards1[i].value))
    else:
        print("{0}{1}".format(cards1[i].shape,cards1[i].value),end=" ")
print("Stable")

for i in range(n):
    minj = i
    for j in range(i+1,n):
        if cards2[j].value < cards2[minj].value:
            minj = j
    w = cards2[i]
    cards2[i] = cards2[minj]
    cards2[minj] = w
for i in range(n):
    if i == n-1:
        print("{0}{1}".format(cards2[i].shape,cards2[i].value))
    else:
        print("{0}{1}".format(cards2[i].shape,cards2[i].value),end=" ")
for i in range(n):
    if cards1[i].shape != cards2[i].shape:
        print("Not stable")
        break
    if i == n-1:
        print("Stable")

Measured memory_bytes: 7844
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>

int main()
{
    int a,b;
    cin>>a>>b;
    string s1="",s2="";
    for(int i=1;i<=b;i++)
        s1.push_back('0'+a);
    for(int i=1;i<=a;i++)
        s2.push_back('0'+b);
    if(s1.compare(s2)<0)
        cout<<s1;
    else 
        cout<<s2;
}

Measured memory_bytes: 256