akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main()
{
  int N,K;
  cin >> N >> K;
  int h;
  int ans=0;
  rep(i,N){
    cin >> h;
    if (h >= K) ans++;
  }
  cout << ans << endl;
}

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

#define INF 2000000000
#define MAX_sumV 100000

struct obj{
  int weight,value;
  obj(int weight=0,int value=0): weight(weight),value(value) {}
};

using ll=long long;

int main(){

  int N,W;
  cin >> N >> W;

  vector<obj> objct(N);
  for(int i=0;i<N;i++){
    cin >> objct[i].weight >> objct[i].value;
  }

  vector<vector<ll>> dp(N+1,vector<ll>(MAX_sumV+1,INF));
  dp[0][0]=0;

  for(int i=0;i<N;i++){
    for(ll sum_V=0;sum_V<=MAX_sumV;sum_V++){
      //obj[i]を選ぶ場合
      if(sum_V>=objct[i].value){
        dp[i+1][sum_V]=min(dp[i][sum_V],dp[i][sum_V-objct[i].value]+objct[i].weight);
      }else{
        dp[i+1][sum_V]=dp[i][sum_V];
      }
    }
  }



  ll ans;
  for(int sum_V=0;sum_V<=MAX_sumV;sum_V++){
    if(dp[N][sum_V]<=W){
      ans=sum_V;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 80256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {

    int n,k;
    cin>>n>>k;
    vector<int> v(n);


    rep(i,n){
        cin>>v[i];

    }

    int ans=0;
    int lim=min(n,k);
    for(int l=0;l<=lim;l++){
        for(int r=0;r<=lim-l;r++){

            vector<int> te;
            int sum=0;

            for(int i=0;i<l;i++){
                sum+=v[i];
                //  if(v[i]<0) {
                te.push_back(v[i]);
                //}
            }
            for(int i=0;i<r;i++){
                sum+=v[n-i-1];
                //  if(v[n-i-1]<0) {
                te.push_back(v[n - i - 1]);
                //}
            }

            int a=k-(l+r);
            int b=te.size();
            sort(te.begin(),te.end());
            for (int tt = 0; tt <= min(a, b); tt++) {
                if(tt!=0){ sum -= te[tt-1];}
                if (ans < sum) {
                    ans = sum;
                }
            }
        }
    }

    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 256
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	ll dp[100001] = { INF };
	dp[0] = 0;
	fori(i, 1, 100001) {
		dp[i] = dp[i - 1] + 1;
		ll t6 = 1;
		for (ll i6 = 0; t6 * 6 <= i; ++i6) {
			t6 *= 6;
			dp[i] = min(dp[i], dp[i - t6] + 1);
		}
		ll t9 = 1;
		for (ll i9 = 0; t9 * 9 <= i; ++i9) {
			t9 *= 9;
			dp[i] = min(dp[i], dp[i - t9] + 1);
		}
	}

	ll N;
	cin >> N;
	cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 1000000

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	set<ll> ans;

	ll k,x;cin>>k>>x;

	Fod(i,x,x-(k-1)){
		ans.insert(i);
	}
	ans.insert(x);
	For(i,x+1,x+(k-1)+1){
		ans.insert(i);
	}

	for(ll x:ans){
		if(x>=(-MAX) && x<=MAX){
			cout<<x<<" ";
		}
	}
	cout<<endl;






























	
}

Measured memory_bytes: 256
import Control.Applicative

calcArea :: Int -> Int -> Int

calcArea x y
    = x * y
    
calcLength :: Int -> Int -> Int

calcLength x y
    = 2 * (x + y)
    
lineUp :: Show a => [a] -> String

lineUp xs
    = init $ concat [show x ++ " " | x <- xs]
    
solve :: [Int] -> [Int]

solve input
    = [calcArea x y, calcLength x y] where
        x = input !! 0
        y = input !! 1

main :: IO ()
    
main
    = do
        input <- map read.words <$> getLine
        putStrLn $ lineUp $ solve input

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

int main(){
  int a, b, c, d;
  int r1, r2;
  cin >> a >> b >> c >> d;
  
  r1 = a*b;
  r2 = c*d;
  
  cout << max(r1, r2);
  
  return 0;
}


Measured memory_bytes: 3656
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n + 1 - i):
        if 1000 * i + 5000 * j + 10000 * (n - i - j) == y:
            print(n - i - j, j, i)
            exit()
print('-1 -1 -1')

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
using namespace std;

#define ll long long int
#define ld long long double
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl


int main(){
  vector<int> v(100);
  ll P;
  ll N;
  

  while(cin>>N>>P,N,P){
    ll ans = P;
    ll ans_ind = -1;
    rep(i,N) v[i] = 0;
    while(1){
      rep(i,N){
	if( P == 0){
	  P = v[i];
	  v[i] = 0;
	}
	else{
	  v[i]++;
	  P--;
	}
	if(v[i] == ans){
	  ans_ind = i;
	  break;
	}
      }
      if(ans_ind != -1){
	cout<<ans_ind<<endl;
	break;
	  }
    }
  }
  return 0;
}
      
	
	  
	    
	  
	  

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
 
/* -----  2017/06/03  Problem: ARC 075 C / Link: http://arc075.contest.atcoder.jp/tasks/arc075_c  ----- */
/* ------問題------
 
 
 
-----問題ここまで----- */
/* -----解説等-----
 
 
 
----解説ここまで---- */
 
ll N,K;
ll a[200010];
ll ans = 0LL;
ll sum[200010];
 
template<class V, int ME> class BIT {
public:
	V bit[1 << ME], val[1 << ME];
	V total(int e) { V s = 0; e++; while (e) s += bit[e - 1], e -= e&-e; return s; }
	V add(int e, V v) { val[e++] += v; while (e <= 1 << ME) bit[e - 1] += v, e += e&-e; }
	V set(int e, V v) { add(e, v - val[e]); }
	int lower_bound(V val) {
		V tv = 0; int i, ent = 0;
		for (i = ME - 1; i >= 0; i--) if (tv + bit[ent + (1 << i) - 1]<val) tv += bit[ent + (1 << i) - 1], ent += (1 << i);
		return ent;
	}
};
 
 
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
 
  cin >> N>>K;
  FOR(i, 0, N)cin >> a[i];
  FOR(i, 0, N)a[i] -= K;
  
  vector < ll >v;
  v.push_back(-1LL<<60);
  v.push_back(0);
  FOR(i, 1, N + 1) {
	  sum[i] += sum[i - 1] + a[i-1];
	  v.push_back(sum[i]);
  }
  sort(v.begin(), v.end());
  
  
  int added = 0;
  BIT<int, 20>bit;
  for (int i = N - 1; i >= 0; i--) {
	  int x = lower_bound(v.begin(), v.end(), sum[i + 1]) - v.begin();
	  added++;
	  bit.add(x, 1);
	  int y = lower_bound(v.begin(), v.end(), sum[i]) - v.begin();
	  ans += added - bit.total(y - 1);
  }
 
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 9968
import java.util.Scanner;
class Main {

    
    public static void main(String[] args) {
        Scanner x = new Scanner(System.in);
        int a, b, c;
        a = x.nextInt(); b = x.nextInt(); c = x.nextInt();
        if(a >= 0 && a<= 1000 && b >= 0 && b<= 1000 && c >= 0 && b<= 1000){
            if(a < b && b < c){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        
        }
    }
}

Measured memory_bytes: 26144
function main(arg){
  	var out = arg.trim().split('\n');
	var ball = out[0].split(' ');
  	var num = out[1].split(' ').map(str => parseInt(str, 10)); 
  	var fall = out[2];
 
  	var result;
  	if(ball[0] === fall) {
    	num[0]--;
      	result = num.join(' ');
    } else if (ball[1] === fall){
    	num[1]--;
      	result = num.join(' ');
    }
	console.log(result);
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
use std::collections::BTreeSet;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let s = read::<String>();
    let kk = read::<usize>();
    let mut sets = BTreeSet::new();
    for i in 0..s.len() {
        for j in 0..kk{
            if i+j >= s.len() {break;}
            sets.insert(&s[i..i+j+1]);
        }
    }
    let mut sub = Vec::new();
    for st in sets{
        sub.push(st);
    }
    sub.sort();
    println!("{}",sub[kk-1]);
}

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

using namespace std;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    --p[i];
  }
  bool valid = true;
  for (int l = 0, r = 1; l < n; l = r++) {
    while (r + 1 < n && p[r] == r && p[r + 1] != r + 1) {
      r += 2;
    }
    int ll = n - 1, rr = 0;
    for (int i = l; i < r; ++i) {
      ll = min(ll, p[i]);
      rr = max(rr, p[i]);
    }
    if (ll != l || rr != r - 1) {
      valid = false;
      break;
    }
    int foo = -1, bar = -1;
    for (int i = l; i < r; i += 2) {
      if (i > p[i]) {
        if (foo > p[i]) {
          valid = false;
          break;
        }
        foo = p[i];
      } else {
        if (bar > p[i]) {
          valid = false;
          break;
        }
        bar = p[i];
      }
    }
    if (!valid) {
      break;
    }
  }
  cout << (valid ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 1408
import math

N,A,B = map(int,input().split())
H = [int(input()) for _ in range(N)]
INF = 10**9
cnt = 0

def check(K):
  tmp = 0
  for i in range(N):
    rem = H[i] - B * K
    if rem > 0:
      tmp += math.floor((rem + (A - B - 1)) / (A - B))
  return tmp <= K

def binary_search(ok,ng):
  while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if check(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(binary_search(INF,0))

Measured memory_bytes: 7068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	char C;
	cin >> C;
 
	string all = "bcdefghijklmnopqrstuvwxyz";
 
	for (int i = 0; i < 25; i++) {
    if (C < all.at(i)) {
      cout << all.at(i) << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
from sys import stdin

def main():
    for l in stdin:
        n, x = map(int, l.split(' '))
        if 0 == n == x:
            break

        print(len(num_sets(n, x)))

def num_sets(n, x):
    num_sets = []

    for i in range(1, n-1):
        for j in [m for m in range(i+1, n)]:
            k = x - (i+j)

            if n < k:
                continue

            if k <= j:
                break

            num_sets.append((i, j, k))

    return num_sets

if __name__ == '__main__': main()

Measured memory_bytes: 7768
import collections
from pprint import pprint as pp

N,M = tuple(map(int, input().split()))
LRD = collections.defaultdict(list)
Lset = set()
Rset = set()
for _ in range(M):
  l,r,d = map(int, input().split())
  l -= 1
  r -= 1
  LRD[l].append((r,d))
  Lset.add(l)
  Rset.add(r)

n = [ None for _ in range(N) ]

deq = collections.deque()

def func(l):
  lst = LRD.pop(l,[])
  for r,d in lst:
    if n[l] != None:
      d2 = n[l] + d
    else:
      n[l] = 0
      d2 = d
    if n[r] not in (d2, None):
      return True
    n[r] = d2
    deq.append(r)
  return False

def func2():
  lst = Lset-Rset
  for l in lst:
    n[l] = 0
    deq.append(l)
  while deq:
    l = deq.popleft()
    if l in LRD:
      if func(l):
        return True
  deq.extend(LRD.keys())
  while deq:
    l = deq.popleft()
    if l in LRD:
      if func(l):
        return True
  return False

if func2():
  print('No')
else:
  print('Yes')


Measured memory_bytes: 50752
from itertools import combinations_with_replacement as combination
n=int(input())
lst=[[0]*10 for i in range(10)]
for i in range(1,n+1):
	s=str(i)
	l=int(s[0])
	r=int(s[-1])
	lst[l][r]+=1
cmb=list(combination([i for i in range(1,10)],2))
ans=0
for i in range(len(cmb)):
	if cmb[i][0]!=cmb[i][1]:
		ans+=lst[cmb[i][0]][cmb[i][1]]*lst[cmb[i][1]][cmb[i][0]]
	ans+=lst[cmb[i][0]][cmb[i][1]]*lst[cmb[i][1]][cmb[i][0]]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 1e9 + 7;
class {
   public:
    int n, k;
    int a[maxn];
    i64 b[maxn], fac[maxn], infac[maxn];
    void solve() {
        cin >> n >> k;
        for (int i = 0; i < n; ++i) cin >> a[i];
        sort(a, a + n);
        if (k == 1) {
            cout << 0;
            return;
        }
        int A = k - 2, B = k - 2;
        fac[0] = 1;
        for (int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % MOD;
        infac[maxn - 1] = pw(fac[maxn - 1], MOD - 2);
        for (int i = maxn - 2; i >= 0; --i) infac[i] = infac[i + 1] * (i + 1) % MOD;
        for (int i = 0; i < n; ++i) {
            b[i] = C(A + i, B);
            if (i)
                b[i] += b[i - 1];
            b[i] %= MOD;
        }
        i64 ans = 0;
        for (int i = 0; i + k - 1 < n; ++i) {
            int r = i + k - 1;
            (ans += (MOD - a[i]) * b[n - 1 - r] % MOD) %= MOD;
        }
        for (int i = n - 1; i + 1 - k >= 0; --i) {
            int r = i + 1 - k;
            (ans += a[i] * b[r] % MOD) %= MOD;
        }
        cout << (ans % MOD + MOD) % MOD << '\n';
    }
    i64 C(i64 a, i64 b) {
        return fac[a] * infac[b] % MOD * infac[a - b] % MOD;
    }
    i64 pw(i64 a, i64 b) {
        i64 c = 1;
        while (b) {
            if (b & 1ll)
                c = a * c % MOD;
            a = a * a % MOD;
            b >>= 1;
        }
        return c;
    }

} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 4864
import bisect
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
C.sort()
ans=0
for b in B:
    ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))
print(ans)


Measured memory_bytes: 105572
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

N = intput()
K = 1
while K*(K+1)//2<N:
    K += 1
for i in range(1,K+1):
    if i!=K*(K+1)//2-N:
        print(i)

Measured memory_bytes: 74636
#include<bits/stdc++.h>
using namespace std;
int n,W,w,v,ans;
map<int,int>wv;
int main(){
 scanf("%d%d",&n,&W);
 wv[0]=0;
 while(n--){
  scanf("%d%d",&w,&v);
  for(auto it=--wv.end();;--it){
   if(it->first+w<=W)wv[it->first+w]=max(wv[it->first+w],it->second+v);
   if(it==wv.begin())break;
  }
 }
 for(auto x:wv)ans=max(ans,x.second);
 printf("%d\n",ans);
}


Measured memory_bytes: 384
n, m = gets.split.map(&:to_i)
prefectures, years, cities_hash = [], [], Hash.new{|hash, key| hash[key] = []}
(1..m).each do |city|
  prefecture, year = gets.split.map(&:to_i)
  
  prefectures[city] = prefecture
  years[city] = year
  cities_hash[prefecture] << city
end

sequences = []
cities_hash.each_value do |cities|
  cities.sort_by{|city| years[city]}.each.with_index(1){|city, sequence| sequences[city] = sequence}
end

(1..m).each do |city|
  printf("%06d%06d\n", prefectures[city], sequences[city])
end







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

int a,b,x,y,w;
int main()
{
    cin >> w >> a >> b;
    x = w + a;
    y = w + b;
    
    if (a>y)
    {
        cout << a - y << endl;
    }
    else if (x<b)
    {
        cout << b - x << endl;
    }
    else
    {
        cout << 0 << endl;
    }

return 0;
}

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

int main() {
  
  int64_t N; cin >> N; N++;
  
  string S = to_string(N);
  
  int headDigit = stoi(S.substr(0, 1)) - 1;
  
  int sum = headDigit + 9 * (S.size() - 1);
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int bound = 1;
  int cor_x = 0;
  int D = 0;

  for(int i = 0; i < N; i++){
    int L;
    cin >> L; 
    D = D + L;
    if(D <= X){
      bound++;
    }else{
      break;
    }
  }

  cout << bound << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.TreeSet;
public class Main {
 
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        boolean dp[][]=new boolean[25][2500];
        for(int i=0;i<25;i++){
            for(int j=0;j<2005;j++){
                dp[i][j]=false;
            }
        }
        dp[0][0]=true;
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<2500;j++){
                if(j-a[i]>=0)dp[i+1][j]=dp[i][j-a[i]]||dp[i][j];
                else dp[i+1][j]=dp[i][j];
            }
        }
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int x=sc.nextInt();
            if(dp[n][x])System.out.println("yes");
            else System.out.println("no");
        }
    }
}



Measured memory_bytes: 26636
'use strict'

const main = (input) => {
    const S = input.split('\n')[0]
    const chars = S.split('')

    const first = chars.shift()
    if (first !== 'A') {
        console.log('WA')
        return
    }
    
    const arr = chars.slice(1, -1)
    if(arr.filter(v => v === 'C').length !== 1) {
        console.log('WA')
        return
    }
    let count = 0
    chars.forEach((v) => {
        if(v !== v.toLowerCase()){
            count++
        }
    })
    if(count === 1){
        console.log('AC')
    }else{
        console.log('WA')
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    
    int count = 0;
    for (int i = 2; i < n; i++) {
        if (s.at(i - 2) == 'A' && s.at(i - 1) == 'B' && s.at(i) == 'C') {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
def main():
    x, y = map(int, input().split())
    count = 2 * x
    if count == y:
        print('Yes')
        sys.exit()
    for i in range(x):
        count += 2
        if count == y:
            print('Yes')
            sys.exit()
    print('No')



if __name__ == '__main__':
    main()


Measured memory_bytes: 67936
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
 
ll power(ll a, ll b){//a^b
    ll res=1;
    while(b>0){
        if(b&1){res=(res*a);b--;}
        a=(a*a);
        b>>=1;
    }
    return res;
}
 
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	ll a[n];
	ll sum=0;
	ll freq[100005]={0};
	for(ll i=0;i<n;i++){
		cin>>a[i];
		freq[a[i]]++;
		sum+=a[i];
	}
	ll q;
	cin>>q;
	while(q--){
		ll b,c;
		cin>>b>>c;
		sum-=freq[b]*b;
		sum+=freq[b]*c;
		//cout<<freq[b]<<" "<<freq[c]<<"\n";
		freq[c]+=freq[b];
		if(b!=c)
			freq[b]=0;
		
		cout<<sum<<"\n";
	}
	
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

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

  YesNo(s[2] == s[3] && s[4] == s[5]);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
	long long n,k,r,s,p,ans = 0;
	string t,player;
	
	cin >> n >> k;
	cin >> r >> s >> p;
	cin >> t;

	for (long long i = 0;i < n; i++)
	{
		if (i < k)
		{
			if (t[i] == 'r')
			{
				player.push_back('r');
				ans += p;
			}
			else if (t[i] == 's')
			{
				player.push_back('s');
				ans += r;
			}
			else
			{
				player.push_back('p');
				ans += s;
			}
		}
		else
		{
			if (t[i] == 'r')
			{
				if (player[i - k] == 'r')
				{
					if (i + k < n)
					{
						if (t[i + k] == 's')
						{
							player.push_back('p');
						}
						else
						{
							player.push_back('s');
						}
					}
					else
					{
						player.push_back('p');
					}
				}
				else
				{
					player.push_back('r');
					ans += p;
				}
			}
			else if (t[i] == 's')
			{
				if (player[i - k] == 's')
				{
					if (i + k < n)
					{
						if (t[i + k] == 'r')
						{
							player.push_back('p');
						}
						else
						{
							player.push_back('r');
						}
					}
					else
					{
						player.push_back('p');
					}
					
				}
				else
				{
					player.push_back('s');
					ans += r;
				}
			}
			else
			{
				if (player[i - k] == 'p')
				{
					if (i + k < n)
					{
						if (t[i + k] == 'r')
						{
							player.push_back('s');
						}
						else
						{
							player.push_back('r');
						}
					}
					else
					{
						player.push_back('r');
					}
					
				}
				else
				{
					player.push_back('p');
					ans += s;
				}
			}
		}
		
	}


	cout << ans << endl;
}

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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  rep(i,k){
    if(a>=b) b *= 2;
    else if(b>=c) c*=2;
  }
  if(a < b && b < c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define F first
#define S second
const long long MOD = 1e9+7;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pii;
typedef long long ll;
// Mod int
// const int MOD = 1000000007;
struct mint{
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  mint operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
mint powmod(mint x,ll y){
	mint a(1);
	while(y){
		if(y&1) a=a*x;
		x=x*x;
		y/=2;
	}
	return a;
}
vector<vector<mint>> dp[5];
int main(){
	int n;
	cin>>n;
	vector<pii> v(n);
	bool zero=false;
	rep(i,n) cin>>v[i].F;
	rep(i,n){
		if(v[i].F==0){
			zero=true;
			v[i].S=1;
		}
		else{
			int cnt=0;
			int t=v[i].F;
			while(t){
				t/=10;
				cnt++;
			}
			v[i].S=cnt;
		}
	}
	int cc[5]={};
	rep(i,n){
		cc[v[i].S]++;
	}
	mint ans[2];
	rep(i,2) ans[i].x=0;
	vector<mint> fun(210,mint(0LL));
	vector<mint> fun_sum(210,mint(0LL));
	fun[0]+=mint(1);
	reep(i,1,210){
		fun[i]=mint(i)*fun[i-1];
	}
	mint combi[210][210];
	rep(i,210) rep(j,210) combi[i][j].x=0LL;
	rep(i,210){
		combi[i][0]=combi[i][i]=mint(1);
		reep(j,1,i){
			combi[i][j]=combi[i-1][j]+combi[i-1][j-1];
		}
	}
	rep(i,210){
		if(i==0){
			fun_sum[0]=mint(1);
			continue;
		}
		rep(j,i+1){
			fun_sum[i]+=combi[i][j]*fun[j];
		}
	}
	rep(o,2){
		if(o){
			if(!zero) continue;
			else cc[1]--;
		}
		rep(i,5) dp[i]=vector<vector<mint>>(1000,vector<mint>(210));
		rep(i,5){
			dp[i][0][0].x=1;
			if(!cc[i]) continue;
			cc[i]--;
			rep(j,5){
				rep(k,cc[j]){
					vector<vector<mint>> tmp=dp[i];
					for(int p=999;p>=0;p--){
						for(int q=209;q>=0;q--){
							if(!tmp[p][q].x) continue;
							dp[i][p+j][q+1]+=tmp[p][q];
						}
					}
				}
			}
			cc[i]++;
		}
		rep(i,n){
			// cout<<ans.x<<endl;
			rep(j,1000){
				ll t=0;
				rep(k,210){
					t+=(dp[v[i].S][j][k]*fun[k]*fun_sum[n-o-k-1]).x;
				}
				ans[o]+=mint(v[i].F)*powmod(mint(10),j)*mint(t);
			}
		}
	}
	cout<<(ans[0]-ans[1]).x<<endl;
}

Measured memory_bytes: 11588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char x, y;
  string ans;
  
  cin >> x >> y;
  
  ans = "=";
  if(x<y) ans = "<";
  if(x>y) ans = ">";
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	char a[3],b[3];
	scanf("%s",a);
	scanf("%s",b);
	for(int i=0;i<3;i++)
		{
			if(a[i]!=b[2-i]) 
			{
				printf("NO\n");
				return 0;
			}
		}
	printf("YES\n");
}

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

int main() {
    string str;
    cin >> str;
    bool f = false;
    int s, e;
    for (int i = 0; i < str.size(); i++) {
        if (str[i] == 'A' && !f) {
            s = i;
            f = true;
        }
        if (str[i] == 'Z') e = i;
    }
    cout << e - s + 1 << endl;
}

Measured memory_bytes: 640
#T=(0,0,...,0)
#に変換するためのコストの2^N倍
N=int(input())
c=sorted([int(i) for i in input().split()])
mod=10**9+7
ans=0
for k in range(N):
    a1=pow(2,(N-2)%(mod-1),mod)
    a2=(N-k+1)
    tmp=(a1*a2)%mod
    ans+=(c[k]*tmp)%mod
    ans%=mod
    #print(k,tmp)
ans=ans*pow(2,N,mod)
ans%=mod
print(ans)


Measured memory_bytes: 26800
using System;
using System.Linq;

namespace ProgramingStydying
{
    class Program
    {
        static void Main(string[] args)
        {
            var nx = Console.ReadLine().Split().Select(int.Parse).ToList();
            var n = nx[0];
            var x = nx[1];

            var a = Console.ReadLine().Split().Select(int.Parse).ToList();
            a.Sort();
            var ans = 0;

            for (int i = 0; i < n; i++)
            {
                if (x - a[i] >= 0)
                {
                    x -= a[i];
                    ans++;
                }
                else
                {
                    break;
                }
            }

            if(x > 0 && ans == a.Count)
            {
                ans--;
            }
            
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 28252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  int n,k,q,hairu;
  cin>>n>>k>>q;
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    vec.at(i)=0;
  }
  for(int i=0; i<q; i++){
    cin>>hairu;
    vec.at(hairu-1)=vec.at(hairu-1)+1;
  }
  for(int i=0; i<n; i++){
    if(q-vec.at(i)<k){
      str="Yes";
      cout<<str<<endl;
    }
    else{
      str="No";
      cout<<str<<endl;
    }
  }
}

Measured memory_bytes: 1024
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Tree = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

VecS s;
VecVec dp;

int main(void){
	ll h, w;
	cin >> h >> w;
	s.resize(h);
	rep(i, h) cin >> s[i];
	dp.resize(h);
	rep(i, h) dp[i].resize(w);

	dp[0][0] = 1;
	rep(i, h) rep(j, w){
		if(s[i][j] == '.'){
			if(i) dp[i][j] += dp[i-1][j];
			if(j) dp[i][j] += dp[i][j-1];
			dp[i][j] %= MOD;
		}
	}
	co(dp[h-1][w-1]);

	return 0;
}


Measured memory_bytes: 9216
#include<iostream>
using namespace std;
int main()
{
	int N;
	cin >> N;
	int pv=0,v=0;
	int result = 0;
	for(int i=0;i<N;i++)
	{
		pv 	=  v;
		cin >> v;
		if(pv==v)
		{
			result++;
			v=0;
		}
	}
	cout << result << std::endl;
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int h,w;
    string str("#");
    string ing(".");
    while(1){
        cin>>h>>w;
        if(h==0&&w==0){
            break;
        }
        for(int i=0;i<w;i++){
            cout<<str;
        }
        cout<<endl;
            for(int i=0;i<h-2;i++){
                cout<<str;
                for(int i=0;i<w-2;i++){
                cout<<ing;
                }
                cout<<str<<endl;
            }
        for(int i=0;i<w;i++){
            cout<<str;
        }
        cout<<endl<<endl;
    }
}

Measured memory_bytes: 1192
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define MAX 100002
using namespace std;
int n;
int nums[4][MAX];
int dp[MAX][4];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d %d",&nums[1][i],&nums[2][i],&nums[3][i]);
	}
//	memset(memo,-1,sizeof(memo));
//	printf("%d",dfs(0,0));
	memset(dp,-1,sizeof(dp));
	dp[0][0]=0;
	dp[1][1]=nums[1][0];
	dp[1][2]=nums[2][0];
	dp[1][3]=nums[3][0];
	
	for(int i=2;i<=n;i++){
		for(int j=1;j<=3;j++){
			for(int flag=1;flag<=3;flag++){
				if(flag!=j) dp[i][j]=max(dp[i][j],dp[i-1][flag]+nums[j][i-1]);
			} 
		}
	}
	int ans=max(max(dp[n][1],dp[n][2]),dp[n][3]);
	printf("%d",ans);
	

	return 0;
}


Measured memory_bytes: 6560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int k;
	cin >> k;
	queue<ll> q;
	for (int i = 1; i <= 9; i++) q.push(i);
	int cnt = 0;
	while (true) {
		ll cur = q.front(); q.pop();
		cnt++;
		if (cnt == k) {
			cout << cur << endl;
			return;
		} else {
			int x = cur % 10;
			for (int i = -1; i <= 1; i++) {
				if (0 <= x + i && x + i <= 9) q.push(cur * 10 + x + i);
			}
		}
	}
}

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

Measured memory_bytes: 5128
<?php
// 1,20のみ　１行目
$g = rtrim(fgets(STDIN));
$a = preg_split("/[\s,]+/", $g);

$ranking = [];
while ($a[0] != 0){
    $ranking[] = ['team'=>$a[0], 'point'=>$a[1]];
    // ２行目以降の呼び出し文
    $g = rtrim(fgets(STDIN));
    $a = preg_split("/[\s,]+/", $g);
}

foreach ($ranking as $key => $value) {
    $point[$key] = $value['point'];
}
array_multisort($point, SORT_DESC, $ranking);

$rank = 1;
$temp_point = $ranking[0]['point'];
for ($i=0; $i < count($ranking); $i++) { 
    if($temp_point !== $ranking[$i]['point']){
        $rank++;
        $temp_point = $ranking[$i]['point'];
    }
    //連想配列の値の追加
    $ranking[$i]['rank'] = $rank;
}

while ($g = rtrim(fgets(STDIN))){
    $keyIndex = array_search($g, array_column($ranking, 'team'));
    $result = $ranking[$keyIndex];
    // print_r($result);
    print $result['rank'];
    print PHP_EOL;
}


Measured memory_bytes: 9464
'''ika tako  コードはSatoooh
優先度付きキューを使うが、最大値を扱いたいのでマイナスを付ける。
popで取り出し。 pushで格納。
高い順に割引券を多く使いたい。1枚使ってもまだ他より高ければ
2枚、3枚、、、と使えばよいが、ある程度使って他の商品が高くなれば、
そちらに使った方がよい。なので、「今の最高額の商品を、
半額で置き換える」ことを  M  回繰り返す。heapqを使うと1回の操作に  
O(logN)  かかるので、全体で  O(MlogN)  となる。
pop()してpush()してもよいが、replace()を使えば2つの操作を1度に行え、
heap構造を保つための比較処理も1回で済むので定数倍高速。
heapreplace(aaa, aaa[0] // 2 + aaa[0] % 2)　ika tako
この+の後が、なぜ必要か、良く分からない。
'''
import heapq
N, M = map(int, input().split())
A = [-i for i in list(map(int, input().split()))]
#最大値を取り出したいので、マイナスを付ける
heapq.heapify(A)#リストをヒープ(二分木)へ変換
for m in range(M):
    A_max = -heapq.heappop(A)  # Aの最大値を削除して取り出す
    heapq.heappush(A, -(A_max // 2))#半分にして、ヒープに入れる
print(-sum(A))#マイナスを忘れないこと

Measured memory_bytes: 14380
import sys
sys.setrecursionlimit(30000)

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

def lcm_list(li):
    if len(li) == 2:
        return lcm(li[0], li[1])

    else:
        li = [lcm(li[0], li[1])] + li[2:]
        return lcm_list(li)

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


i = max(lcm_list(a) - 1, 1)
print(sum([i % j for j in a]))


Measured memory_bytes: 50676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    ll n, k, q;    cin >> n >> k >> q;
    vector<ll> a(n, 0);
    for(int i=0; i<q; i++){
        int x;  cin >> x;
        a.at(x-1) += 1;
    }
    string ans;
    for(int i=0; i<n; i++){
        if(q-k<a.at(i)) ans = "Yes";
        else ans = "No";
        cout << ans << endl;
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
//#define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;})

 int main(){

  ll n,ans=0;
  cin>>n;

  for(int i=1;i<=n;i++)
  {
    for(int j=2;j<=10;j++)
    {
      long long y = pow(i,j);

      if(y<=n) ans = max(ans,y);
    }
  }

  cout<<ans<<endl;

 return 0;
 }

Measured memory_bytes: 4164
n = int(input())
l = list(map(int, input().split()))
m = list(map(int, input().split()))
a = 0
b = 0

for j in range(n):
  b = sum(l[0:j+1]) + sum(m[j:n+1])
  if a < b:
    a = b
  else:
    pass
  
print(a)
   

Measured memory_bytes: 9160
import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.geom.*;
import java.math.*;
import java.text.*;
import java.math.BigInteger.*;
import java.util.Arrays; 

public class   Main
{
  BufferedReader in;
  StringTokenizer as;
  int nums[],nums2[];
  ArrayList < String > [] ar;
  
  public static void main (String[] args)
  {
    new Main  ();
  }
  
  
  public int GCD(int a, int b) {
    if (b==0) return a;
    return GCD(b,a%b);
  }
  
  public Main  ()
  {
    try
    {
      
      in = new BufferedReader (new InputStreamReader (System.in));
      int a = nextInt();
      nums = new int [a];
      nums2 = new int [a];
      for(int x = 0;x<a;x++)
      {
        nums[x] = nextInt();
      }
      nums2[0] = 0;
      nums2[1] = Math.abs(nums[1] - nums[0]);
      for(int x = 2;x<a;x++)
      {
        nums2[x] = Math.min(nums2[x-2] + Math.abs(nums[x] - nums[x-2]),nums2[x-1] + Math.abs(nums[x]-nums[x-1]));
      }
      System.out.println(nums2[a-1]);
    }
    
    catch(IOException e)
    {
      
    }
  }
  
  
  
  
  
  
  
  String next () throws IOException
  {
    while (as == null || !as.hasMoreTokens ())
    {
      as = new StringTokenizer (in.readLine ().trim ());
    }
    
    
    return as.nextToken ();
  }
  
  
  
  long nextLong () throws IOException
  {
    return Long.parseLong (next ());
  }
  
  
  int nextInt () throws IOException
  {
    return Integer.parseInt (next ());
  }
  
  
  double nextDouble () throws IOException
  {
    return Double.parseDouble (next ());
  }
  
  
  String nextLine () throws IOException
  {
    return in.readLine ().trim ();
  }
}

Measured memory_bytes: 30856
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main() {
	long long n;
	while (cin >> n&&n!=0) {
		int i = 0;
		while (n != 1) {
			if (n % 2 == 0) 
				n /= 2;
			else
				n = n * 3 + 1;
			i++;
		}
		cout << i << endl;
	}
}

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

using namespace std;
int euclid(int a, int b){
	int l = max(a, b);
	int r = min(a, b);
	int buf;
	if(a==0 || b==0) return 0;

	while(r!=0){
		buf = r;
		r = l%r;
		l = buf;
	}
	return l;
}
int main(){
	int a,b,ret;
	while(cin>>a>>b, !cin.eof()){
		ret = 0;
		cout<<euclid(a,b)<<endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  int N;  cin >> N;
  vi d(N);
  REP(i, N) cin >> d[i];
  int ans = 0;
  for(int i=0; i<N; i++)  for(int j=i+1; j<N; j++){
    ans += d[i]*d[j];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
let () =
  let (n,k) = Scanf.scanf "%d %d\n" (fun x y->(x,y)) in
  let a = Array.init n (fun _ -> Scanf.scanf "%d\n" (fun x->x)) in
  let l = Array.fold_left (fun x y -> max x y) 0 a and
      r = 100000*100000 in
  let rec load ((i,j,s,p):int*int*int*int):bool =
    if i=n then true
    else if j=k then false
    else
      if s+a.(i) <= p then load ((i+1), j, (s+a.(i)), p) else load (i,(j+1),0,p)
  in
  let rec loop (left:int) (right:int):int =
    if left < right then
      let mid = (left+right)/2 in
      if load (0,0,0,mid) then loop left mid
      else loop (mid+1) right
    else right
  in
  Printf.printf "%d\n" (loop l r)
;;

Measured memory_bytes: 5372
#include <bits/stdc++.h>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

const int N=2e6+5;
const int mod=1e9+7;
int fact[N];
int invFact[N];
int inverseMod(int x,int mod);

void precompute(){
    fact[0]=fact[1]=1;

    for(int i=2;i<N;i++){
        fact[i]=fact[i-1]*i;
        fact[i]%=mod;
    }
    invFact[N-1]=inverseMod(fact[N-1],mod);

    for(int i=N-2;i>=0;i--){
        invFact[i]=invFact[i+1]*(i+1);
        invFact[i]%=mod;
    }
}
int NCR(int n,int r){

    if(r>n)return 0;
    int num=fact[n];
    num*=invFact[r];
    num%=mod;
    num*=invFact[n-r];
    num%=mod;
    return num;
}
int NCR2(int n,int r){

    if(r>n)return 0;
    int ans=fact[n];
    ans*=inverseMod(fact[r],mod);
    ans%=mod;
    ans*=inverseMod(fact[n-r],mod);
    ans%=mod;
    return ans;
}

int power(int x,int n,int mod){
    //(x^n)%mod
    int result=1;
    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

int inverseMod(int x,int mod){
    return power(x,mod-2,mod);
}




int32_t main() {

    simplify
    precompute();
    int k,n;
    string s;
    cin>>k;
    cin>>s;

    n=s.size();

    int ans=0;

    for(int i=n;i<=(n+k);i++){
        int other=NCR(n+k,i)*power(25,n+k-i,mod);
        other%=mod;
        ans+=other;
        ans%=mod;
    }

    cout<<ans<<endl;



    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(ll i = a; i < b; i++)
#define DB( x ) cout << #x << " = " << x << endl;
#define sz(s) ((int)((s).size()))
#define endl '\n'

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef pair<int, pii> tri;
typedef vector <vector <ll>> matrix;
typedef pair<string, string> pss;

const ll mod = (ll)1e9 + 7;
const int MAX = (int)1e5 + 100;

const ll oo = 0x3f3f3f3f3f3f3f3f;

ll a[MAX][5];

ll dp[MAX][5];

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

    int n; cin >> n;

    for(int i = 1;i <= n;++i)
        cin >> a[i][1] >> a[i][2] >> a[i][3];

    for(int i = 1;i <= n;++i){
        for(int k = 1;k <= 3;++k){
            for(int j = 1;j <= 3;++j){
                if(k == j) continue;
                dp[i][k] = max(dp[i - 1][j] + a[i][k], dp[i][k]);
            }
        }
    }

    cout << max(dp[n][1], max(dp[n][2], dp[n][3])) << endl;
}


Measured memory_bytes: 8064
n,k = map(int, input().split())
a = list(map(int ,input().split()))

time = 10 ** 10
for i in range(0, n-k+1):
  p = a[i]
  q = a[i+k-1]
  if q < 0:
    t = abs(p)
  elif p > 0:
    t = q
  else:
    t = abs(p) + q + min(abs(p), q)
  if t < time:
    time = t

print(time)

Measured memory_bytes: 19872
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pll pair<ll,ll>
#define sll set<ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define vpl vector<pll>
#define gll greater<ll>
#define prq priority_queue
#define mp make_pair
#define pb push_back
#define rapido ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef long double ld;
ll mx=INT_MAX;
ll mn=INT_MIN;
ll mod=1e9+7;
const ll maxs=2e6+6;
ll max2d=1e3+3;


ll v;
vll *g;
ll *p;
ll *lvl;
mll m;
ll *clr;


ll fast(ll base , ll power)
{
    ll res=1;
    while(power)
    {
        if(power&1)
            res=res*base;
        base = base*base;
        power>>=1;
    }
    return res;
}


void addEdge(ll x,ll y)
{
    g[x].pb(y);
    g[y].pb(x);
}


bool isPal(string s, ll strt, ll end)
{
    while(strt < end)
    {
        //cout<<s[strt]
        if(s[strt]==s[end])
        {
            strt++;
            end--;
        }
        else
            return false;
    }
    return true;
}


int main()
{
    string s;
    cin>>s;
    
    ll n = s.size();
    
    if(isPal(s , 0 , n-1) and isPal(s, 0 , ((n-1)/2) - 1 ) and isPal(s, ((n+3)/2) - 1 , n-1))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    
    return 0;
}

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

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

#%%

A.sort()

keyz = 0
for a in A:
    if a<0:
        keyz += 1

if keyz==0:
    keyz = 1
elif keyz == N:
    keyz = N-1


M = 0
M += -sum(A[:keyz])
M += sum(A[keyz:])
print(M)

# A[0:keyz]までを負とする
    

# A[keyz:]は反転させる必要あり

if keyz == N-1:
    cur = A[-1]
    for i in range(N-1):
        print(cur,A[i])
        cur -= A[i]
    
else:            
    cur = A[0]
    for i in range(keyz,N-1):
        print(cur,A[i])
        cur = cur - A[i]
    print(A[N-1],cur)
    cur = A[N-1] - cur
    for i in range(1,keyz):
        print(cur,A[i])
        cur -= A[i]
        
        





Measured memory_bytes: 14088