akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ACirclePond solver = new ACirclePond();
        solver.solve(1, in, out);
        out.close();
    }

    static class ACirclePond {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            w.println(2 * Math.PI * s.nextInt());
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60, lmod = 1e9+7;

const int MAX_N = 100005;

ll a[3*MAX_N],dp1[MAX_N],dp2[MAX_N];
priority_queue<ll> max_que;
priority_queue<ll,vector<ll>,greater<ll>> min_que;

int main(){
  int N; cin >> N;
  rep(i,3*N) scanf("%lld",a+i);
  ll temp = 0LL;
  rep(i,N){
    temp += a[i];
    min_que.push(a[i]);
  }
  dp1[0] = temp;
  rep(i,N){
    ll m = min_que.top();
    if(a[N+i]>m){
      dp1[i+1] = dp1[i] + a[N+i] - m;
      min_que.pop();
      min_que.push(a[N+i]);
    }else{
      dp1[i+1] = dp1[i];
    }
  }
  temp = 0LL;
  RREP(i,3*N-1,2*N){
    temp += a[i];
    max_que.push(a[i]);
  }
  dp2[0] = temp;
  rep(i,N){
    ll m = max_que.top();
    if(a[2*N-i-1]<m){
      dp2[i+1] = dp2[i] + a[2*N-i-1] - m;
      max_que.pop();
      max_que.push(a[2*N-i-1]);
    }else{
      dp2[i+1] = dp2[i];
    }
  }
  ll ans = -LINF;
  rep(i,N+1){
    ans = max(ans,dp1[i]-dp2[N-i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5876
input = []
STDIN.each{|line|
  input << line.split(' ').map{|x|x.to_i}
}

cs = input[0][0]
cc = input[0][1]
s = input[1,cs]
c = input[1+cs,cc]

s.each{|sx,sy|
  ds= []
  c.each{|cx,cy|
    ds << (sx-cx).abs+(sy-cy).abs
  }
  min_d = ds.min
  cnt = 1
  ds.each{|d|
    if d == min_d
      puts cnt
      break
    end
    cnt = cnt + 1
  }
}


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <cmath>

using namespace std;

int main()
{
    string s;
    long long sum=0,r,t=0,m,l;
    cin >> s;

    long long k = 1 << (s.size()-1);
    //cout << k << endl;
    sum+=((s[s.size()-1]-'1'+1)*k);
    //cout << sum << endl;
    for (int i = s.size()-2; i>=0; i--)
    {
        r=s.size()-1-i;
        t=0;
        m = 1;
        l = (k/2);
        while (l!=0)
        {
            //cout << (s[i]-'1'+1) << " " << m << " " << l << endl;
            sum+=(s[i]-'1'+1)*m*l;
            t++;
           // cout << t << endl;
            if (t-1<r)
            m*=10;
            l/=2;

        }
        sum+=(s[i]-'1'+1)*m;
    }
    cout << sum << endl;

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    char a;
    cin >> a;
    if(a<=122 && a>=97)cout << 'a' << endl;
    else cout << 'A' << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

long long gcd(int a, int b){
  if (a%b == 0){
    return(b);
  }
  else{
    return(gcd(b, a%b));
  }
}

int main(){    
  long long R;
  cin >> R;
  long long sum = 0;


  cout << R * 2 * M_PI<< endl;

}
 


Measured memory_bytes: 3752
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;

using namespace std;

int main()
{
  ull N;

  cin >> N;

  for (auto i = N; i <= 999; i++) {
    ull a = (i / 100) % 10;
    ull b = (i / 10) % 10;
    ull c = i % 10;
    if (a == b && a == c) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut xy: Vec<(i64, i64)> = vec(n, |_| (scan(tokens), scan(tokens)));
    xy.sort_by_key(|&(_, y)| y);
    let mut ix: Vec<(usize, i64)> = xy.iter().enumerate().map(|(i, &(x, _))| (i, x)).collect();
    ix.sort_by_key(|&(_, x)| x);
    let p: Vec<usize> = ix.iter().map(|&(i, _)| i).collect();
    let mut ans = 0;
    let mut bit = vec![0; n];
    for i in 0..n {
        let mut k = i;
        let mut j = p[i] + 1;
        while j < n {
            k -= bit[j];
            j += j & !(j - 1);
        }
        let j = p[i];
        ans += power(2, n);
        ans += MODULO - power(2, i);
        ans += MODULO - power(2, n - 1 - i);
        ans += MODULO - power(2, j);
        ans += MODULO - power(2, n - 1 - j);
        ans += power(2, k);
        ans += power(2, i - k);
        ans += power(2, j - k);
        ans += power(2, (n - 1 - i) - (j - k));
        ans += MODULO - 1;
        ans %= MODULO;
        let mut j = p[i];
        while {
            bit[j] += 1;
            j != 0
        } {
            j -= j & !(j - 1);
        }
    }
    println!("{}", ans);
}

const MODULO: usize = 998244353;

fn power(mut b: usize, mut e: usize) -> usize {
    let mut a = 1;
    while e != 0 {
        if e & 1 != 0 {
            a = a * b % MODULO;
        }
        b = b * b % MODULO;
        e >>= 1;
    }
    a
}


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

int main() {
    int K, S;
    std::cin >> K >> S;

    int cnt = 0;
    for (int i = 0; i <= K; ++i) {
        for (int j = 0; j <=K; ++j) {
            if ((i + j) > S) {
                break;
            } 

            const int k = S - (i + j);
            if (k <= K) {
                ++cnt;
            }
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
r = 0
R = 0
for n in range(1,N):
    if A[n-1] > A[n]:
        r = A[n-1] - A[n]
        A[n] = A[n] + r
        R = R + r
print(R)


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    string S,T; cin >> S >> T;
    if(T.size() != S.size() + 1){
        cout << "No" << endl;
        return 0;
    }
    REP(i,S.size()){
        if(S[i] != T[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
const int fix = 1000000007;
int main()
{
  int N;
  long long pow = 1;
  cin >> N;
  for(int i = 1; i <= N; ++i)
  {
    pow = i * pow % fix;
  }
  cout << pow << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> dp,arr;
int solve(int N, int k, int cur = 0){
    if(cur == N - 1) return 0;
    if(dp[cur] != -1) return dp[cur];
    int minimum = INT_MAX;
    for(int i = 1; i <= k && cur + i < N; i++){
        minimum = min(minimum,abs(arr[cur+i] - arr[cur]) + solve(N,k,cur+i));
    }
    
    dp[cur] = minimum;
    return minimum;
}
int main(){
    int N,k;
    cin>>N>>k;
    arr = vector<int>(N);
    dp = vector<int>(N, -1);
    for(int i = 0; i < N; i++){
        cin>>arr[i];
    }
    cout<<solve(N,k);
}

Measured memory_bytes: 11796
#include <stdio.h>

void BubbleSort(int array[], int len, int *count){

	int i, j;
	for (i = 0; i < len; i++) {
		for (j = len - 1; j > i; j--) {
			if (array[j] < array[j - 1]) {
				int tmp = array[j - 1];
				array[j - 1] = array[j];
				array[j] = tmp;
				(*count)++;
			}
		}
	}
}

int main()
{
	int n, i, count = 0;
	int num[100];
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d",&num[i]);
	}
	
	BubbleSort(num, n, &count);
	
	for (i = 0; i < n - 1; i++) {
		printf("%d ", num[i]);
	}
	printf("%d\n%d\n", num[n - 1], count);
	return 0;
}

Measured memory_bytes: 600
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//ここまで標準include

using namespace std;

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < n; i++) {
		cout << s.substr(i, 1);
		cout << t.substr(i, 1);
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1000000007;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

int main(void){
    int n;
    cin>>n;
    long long n0=1,n9=1,n09=1;//0,9を含まないもの
    long long N=1;//0~9のみのn個の整数の列全体
    rep(i,n){
        n0=(n0*9)%MOD;
        n9=(n9*9)%MOD;
        n09=(n09*8)%MOD;
        N=(N*10)%MOD;
    }
    long long ans=(N+n09)%MOD;
    ans=(ans-n0)%MOD;
    ans=(ans-n9)%MOD;
    if(ans<0) ans+=MOD;
    //if(n==1) ans=0;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3644
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    a,b,c,d = LI()
    ans = max(a*c,a*d,b*c,b*d)
    print(ans)
main()


Measured memory_bytes: 68404
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

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

    return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    it.next();
    let s: Vec<char> = it.next().unwrap().chars().collect();
    it.next();
    for k in it {
        let k: usize = k.parse().unwrap();
        let mut d = 0u64;
        let mut m = 0;
        let mut dm = 0;
        let mut dmc = 0;
        for &c in s[..k].iter() {
            if c == 'C' {
                dmc += dm;
            }
            if c == 'M' {
                m += 1;
                dm += d;
            }
            if c == 'D' {
                d += 1;
            }
        }
        for (&f, &t) in s.iter().zip(s[k..].iter()) {
            if f == 'D' {
                dm -= m;
                d -= 1;
            }
            if f == 'M' {
                m -= 1;
            }
            if t == 'C' {
                dmc += dm;
            }
            if t == 'M' {
                m += 1;
                dm += d;
            }
            if t == 'D' {
                d += 1;
            }
        }
        writeln!(out, "{}", dmc).ok();
    }
}

fn main() {
    run();
}


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

int main()
{
	int N, M;
	cin >> N;
	vector<int> T( N );
	for( int i = 0; i < N; i++ ) {
		cin >> T[i];
	}
	cin >> M;
	typedef pair<int, int> P;
	vector<P> PX( M );
	for( int i = 0; i < M; i++ ) {
		int p, x;
		cin >> p >> x;
		p--;
		PX[i] = P( p, x );
	}

	for( int i = 0; i < M; i++ ) {
		int p, x;
		tie( p, x ) = PX[i];
		long long ans = 0;
		for( int j = 0; j < N; j++ ) {
			if( j == p ) ans += x;
			else ans += T[j];
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3592
import scala.io.StdIn.{readInt, readLine}

object Main extends App {
  val Zero = BigInt(0)
  val VMax = BigInt(1_000_000_000_000_000_000L)

  val n  = readInt()
  val xs = readLine().split(' ').map { BigInt(_) }

  var isOver = false
  val s =
    if (xs.contains(Zero)) Zero
    else {
      val it = xs.iterator
      var s  = BigInt(1)
      while (it.hasNext && !isOver) {
        val a = it.next()
        s *= a
        if (s > VMax) {
          isOver = true
        }
      }
      s
    }

  println(if (isOver) -1 else s)
}


Measured memory_bytes: 78724
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main() {
  vector<int> vec;
  vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int a;
  cin >> a;
  cout << vec.at(a-1);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int i,c=0,c1=0;
     string  s,t;
    cin>>s>>t;
    for(i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
        {
            c++;
        }

    }
    cout<<c<<endl;

}


Measured memory_bytes: 3872
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)


//union-find
#define UFLIMIT (1<<17)
int unicnt[UFLIMIT+10];//正ならcnt、非正なら根のindex
void ufinit(int n){rep(i,0,n)unicnt[i]=1;}
int root(int x){return unicnt[x]<=0?-(unicnt[x]=-root(-unicnt[x])):x;}
int same(int x,int y){return root(x)==root(y);}
void uni(int x,int y){if((x=root(x))==(y=root(y)))return;if(unicnt[x]<unicnt[y]){int t=x;x=y;y=t;}unicnt[x]+=unicnt[y];unicnt[y]=-x;}
#undef UFLIMIT

ll n,m;
int main(){
	scanf("%lld%lld",&n,&m);
	if(n==0){
		if(m==0)puts("0 0");
		else puts("-1");
	}else if(n==1){
		if(m==0)puts("0 0 1 1");
		else puts("-1");
	}else{
		if(m>=(1<<n))puts("-1");
		else if(m==0){
			rep(i,0,1<<n)printf("%lld %lld ",i,i);
		}else{
			ll a=m^1;
			printf("1 ");
			rep(i,0,1<<n)if(i!=a&&i!=1)printf("%lld ",i);
			printf("1 %lld ",a);
			for(int i=(1<<n)-1;i>=0;i--)if(i!=a&&i!=1)printf("%lld ",i);
			printf("%lld",a);
		}
	}
	
}

Measured memory_bytes: 1792
class Info:
    def __init__(self,arg_start,arg_end,arg_S):
        self.start = arg_start
        self.end = arg_end
        self.S = arg_S


LOC = []
POOL = []

line = input()
loc = 0
sum_S = 0

for ch in line:

    if ch == '\\':

        LOC.append(loc)

    elif ch == '/':

        if len(LOC) == 0:
            continue

        tmp_start = int(LOC.pop())
        tmp_end = loc
        tmp_S = tmp_end-tmp_start;
        sum_S += tmp_S;

        #既に突っ込まれている池の断片が、今回の断片の部分区間になるなら統合する
        while len(POOL) > 0:
            if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end:
                tmp_S += POOL[-1].S
                POOL.pop()
            else:
                break

        POOL.append(Info(tmp_start,tmp_end,tmp_S))

    else:
        pass

    loc += 1

print("%d"%(sum_S))
print("%d"%(len(POOL)),end = "")

while len(POOL) > 0:
    print(" %d"%(POOL[0].S),end = "") #先頭から
    POOL.pop(0)

print()



Measured memory_bytes: 6776
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a,_b=b;i<=_b;i++)
#define rep(i,n) REP(i,0,n-1)
#define FORD(i,b,a) for(int i=b,_a=a;i>=_a;i--)
#define ford(i,n) FORD(i,n-1,0)
#define sqr(x) ((x)*(x))
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define vll vector<ll>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define add push_back
#define len(arr) arr.size()
#define print(x) cout<<(x)<<endl
using namespace std;

int get(int x){
	int res = 0;
	while(x){
		res += x % 10;
		x /= 10;
	}
	return res;
}

int main(){
	//freopen("in.txt", "r", stdin);
	int n, ans = 1e6;
	cin >> n;
	REP(i, 1, n / 2 + 1){
		int tmp = n - i;
		//cout << i << " " << tmp << endl;
		ans = min(get(i) + get(tmp), ans);
	}
	print(ans);
	return 0;
}



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


using namespace std;
typedef long long ll;

const int N = 200;
const int inf = 0x3f3f3f3f;
const int OO = 1e9 + 100;
const ll inf_long = 1e18;

ll mod = 1e9 + 7;

ll n, k, a[N];
ll dp[N][100009];

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

	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	dp[0][0] = 1;
	for (int i = 1; i <= k; ++i)
	{
		dp[0][i] = 0;
	}
	for (int i = 1; i <= n; ++i)
	{
		ll *sum = new ll[k + 1];
		sum[0] = dp[i - 1][0];
		for (int j = 1; j <= k; ++j)
		{
			sum[j] = sum[j - 1] + dp[i - 1][j];
			sum[j] = sum[j] % mod;
		}
		for (int j = 0; j <= k; ++j)
		{
			ll finalSol = sum[j];
			int firstInvalid = a[i] + 1;
			if (j >= firstInvalid)
				finalSol = (finalSol - sum[j - firstInvalid] + mod) % mod;

			dp[i][j] = finalSol;
		}
	}
	cout << dp[n][k];


	return 0;
}


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

const int MAX = 1e5 + 10;

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

  int arr[MAX];
  fill(arr, arr + MAX, 0);
  for (int i = 0; i < N; i++) {
    arr[a[i]-1]++;
    arr[a[i]]++;
    arr[a[i]+1]++;
  }

  int ans = 0;
  for (int i = 0; i < MAX; i++) ans = max(ans, arr[i]);

  cout << ans << endl;

  return 0;
}


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

#define rep(i,c) for(int i = 0; i < (int)c; ++i)
using llint = long long int ;
using namespace std;



int main(){
    int N;
    map<int,llint> mp;
    int A[300000];
    cin>>N;
    rep(i,N){
        cin>>A[i];
        mp[A[i]]++;
    }

    llint num=0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++)
    {
        llint seco=itr->second;
        if (seco==0) continue;
        else num+=seco*(seco-1)/2;
    }
    
    for (int i = 0; i < N; i++)
    {
        if (mp[A[i]]<2) cout<<num<<endl;
        else cout<<num-(mp[A[i]]*(mp[A[i]]-1)/2)+((mp[A[i]]-1)*(mp[A[i]]-2)/2)<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 10240
#include<iostream>
#include<string>
#include<vector>

using namespace std;
vector<string> split(string expression,char delimita)
{
	vector<string> ret;
	int startIndex = 0;
	int length = 1;
	int size = expression.size();
	while ((startIndex = expression.find(delimita)) != string::npos)
	{
		string sub = expression.substr(0,startIndex);
		string next = expression.substr(startIndex + 1);
		expression = next;
		ret.push_back(sub);
	}
	if (expression.size() > 0)ret.push_back(expression);
	return ret;
}
int multi(string exp)
{
	int ret = 1;
	for (int i = 0; i < exp.size(); i+=2)
	{
		ret *= (exp[i] - '0');
	}
	return ret;
}
bool isM(int n,string s)
{
	vector<string> exps = split(s, '+');
	int ret = 0;
	for (int i = 0; i < exps.size(); i++)
	{
		ret += multi(exps[i]);
	}
	return n == ret;
}

bool isL(int n,string s)
{
	if (s.length() == 1 && s[0] - '0' == n)return true;
	int sum = -1;
	for (int i = 1; i < s.length(); i += 2)
	{
		if (i == 1)
		{
			if (s[i] == '+')
			{
				sum = s[i - 1] - '0' + (s[i + 1] - '0');
			}
			else
			{
				sum = (s[i - 1] - '0') * (s[i + 1] - '0');
			}
		}
		else
		{
			if (s[i] == '+')
			{
				sum += (s[i + 1] - '0');
			}
			else
			{
				sum *= (s[i + 1] - '0');
			}
		}
	}

	if (sum == n)return true;
	else return false;
}

int main()
{
	string exp;
	int n;
	cin >> exp;
	cin >> n;
	bool M = isM(n, exp);
	bool L = isL(n, exp);
	if (M && L)
	{
		cout << "U" << endl;
	}
	else if (M)
	{
		cout << "M" << endl;
	}
	else if (L)
	{
		cout << "L" << endl;
	}
	else
	{
		cout << "I" << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
# 解説を見た

def solve(N, t, a, g) -> int:
    import sys

    sys.setrecursionlimit(10 ** 7)

    def calc_dist(init):
        dist = [-1] * N
        dist[init] = 0

        def _calc_dist(curr):
            for next_ in g[curr]:
                if dist[next_] != -1:
                    continue
                dist[next_] = dist[curr] + 1
                _calc_dist(next_)

        _calc_dist(init)
        return dist

    dist_a = calc_dist(a)
    dist_t = calc_dist(t)

    return max(dist_a[v] for v in range(N) if dist_t[v] < dist_a[v]) - 1


if __name__ == '__main__':
    N, t, a = map(int, input().split())
    t -= 1
    a -= 1

    g = tuple(set() for _ in range(N))
    for _ in range(N - 1):
        u, v = (int(x) - 1 for x in input().split())
        g[u].add(v)
        g[v].add(u)

    print(solve(N, t, a, g))

# 青木君からの距離 > 高橋君からの距離 となる頂点Xが目的地の候補
# 青木君と高橋君の共通祖先からの距離は等しいので、
# 共通祖先への距離は、 青木君 > 高橋君 となり、高橋君は必ずXに到達できる
# Xに着いた高橋君は、手前の頂点とXとを行ったり来たりする
# a-t->at-: aが一歩進んだときに高橋君に会う(-は無人のマス目)
# at: tが手前の頂点に移動したときに青木君に会う
# いずれも手前の頂点まで青木君が移動したときにゲームが終わる
# どのXを選んでも、Xの手前でゲームが終わるので、青木君から最も遠いXを選ぶのが最善
# 頂点X: 追いつめられる位置=葉


Measured memory_bytes: 126448
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine());
		int[] A = new int[N];
		double d = 0;
		for(int i = 0;i < N;i++){
			A[i] = Integer.parseInt(sc.next());
			d += 1/(double)A[i];
		}
		sc.close();
		System.out.println(1/d);
	}
}

Measured memory_bytes: 21844
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	x := intScanner()
	y := intScanner()
	if abs(x) == abs(y) {
		if x*y < 0 {
			fmt.Println(1)
		} else {
			fmt.Println(0)
		}
	} else if abs(x) < abs(y) {
		ans := 0
		if x < 0 {
			ans++
		}
		ans += abs(y) - abs(x)
		if y < 0 {
			ans++
		}
		fmt.Println(ans)
	} else {
		ans := 0
		if x > 0 {
			ans++
		}
		ans += abs(x) - abs(y)
		if y > 0 {
			ans++
		}
		fmt.Println(ans)
	}
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}


Measured memory_bytes: 640
import math
from collections import deque 
import heapq 
N,K=map(int,input().split())
box=list(map(int,input().split()))

ans=0
for M in range(0,K+1):
    for i in range(math.ceil(M//2),min(M+1,N+1)):
        for l in range(0,i+1):
          keep=[]
          boxA=deque(box)
          for _ in range(l):
            heapq.heappush(keep, boxA.popleft())
          for _ in range(i-l):
            heapq.heappush(keep, boxA.pop())
          for _ in range(min(M-i,i)):
            S=heapq.heappop(keep)
            if int(S)>0:
                heapq.heappush(keep,S)
          ans= max(ans,sum(keep))
print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	vector<int> v;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	v.push_back(d);
	v.push_back(e);

	for (int i = 0; i < 5; ++i)
	{
		if (v[i] == 0) {
			cout << i + 1;
		}
	}
	return 0;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;
const ll INF = 1ll<<60;

std::string N;
ll dp[1000010][2];

int main()
{
  std::cin >> N;

  std::reverse( all(N) );

  N += "0";

  ll n = N.size();

  rep( i, n+1 ) rep( j, 2 )
    dp[i][j] = INF;

  dp[0][0] = 0;

  rep( i, n ) rep( j, 2 )
  {
    ll x = N[i]-'0';

    x += j;

    rep( a, 10 )
    {
      ll b = a-x;
      ll nj = 0;

      if( b < 0 )
      {
        nj = 1;
        b += 10;
      }

      chmin( dp[i+1][nj], dp[i][j]+a+b );
    }
  }

  std::cout << dp[n][0] << std::endl;

  return 0;
}

Measured memory_bytes: 17012
s = input()
ca, cb, cc = 0, 0, 0
for i in range(3):
    if s[i] == 'a':
        ca += 1
    elif s[i] == 'b':
        cb += 1
    else:
        cc += 1

if ca == 1 and cb == 1 and cc == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
gets
c=0
puts$<.map{|s|a=0
[s.bytes.map{a+=81-_1*2}.min,a-61]}.sort_by{_2>0?-_1:2e9-_2+_1}.map{_2-_1+c-=_2}.max>0||c<0?:No: :Yes

Measured memory_bytes: 102952
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
    int to, cost;
};


// dijikstra
/* int V;
vector<edge> G[10];
int d[10];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V + 1, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        REP(i, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
*/

int main(){
    int n;
    cin >> n;
    vector<int> s;
    int ans = 0;
    s.pb(0);
    REP(i, n){
        int tmp;
        cin >> tmp;
        s.pb(tmp);
        ans += tmp;
    }
    SORT(s);
    int k = 1;
    while(ans % 10 == 0){
        if(k == s.size()){
            ans = 0;
            break;
        }
        ans -= s[k] - s[k - 1];
        k++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

int main() {

    int N; cin >> N;
    string S; cin >> S;

    stack<char> sta;
    REP(i,S.size()) {
        if(sta.size() == 0) {
            sta.push(S[i]);
        } else if(sta.top() == '(' && S[i] == ')') {
            sta.pop();
        } else {
            sta.push(S[i]);
        }
    }

    int cnt1 = 0;
    int cnt2 = 0;
    while(sta.size() != 0) {
        if(sta.top() == '(') cnt1++;
        if(sta.top() == ')') cnt2++;
        sta.pop();
    }

    REP(i,cnt1) S.push_back(')');
    REP(i,cnt2) S.insert(S.begin(),'(');

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
ans = 0
if x > y:
    if x >= 0 and y >= 0: # x,yが両方とも正
        if y == 0:
            print(x-y+1)
        else:
            print(x-y+2)
    elif x < 0 and y < 0: # x,yが両方とも負
        print(x-y+2)
    else:                 # xが正、yが負
        if x > -y:
            print(x+y+1)
        elif x < -y:
            print(-y-x+1)
        else:
            print(1)
else:                     # yの方が大きい
    if x >= 0 and y >= 0: # x,yが両方とも正
        print(y-x)
    elif x < 0 and y < 0: # x,yが両方とも負
        print(y-x)
    else:                 # xが負、yが正
        if -x > y:
            if y == 0:
                print(-x-y)
            else:
                print(-x - y + 1)
        elif -x < y:
            print(y+x+1)
        else:
            print(1)


Measured memory_bytes: 9132
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	static final int INF=1<<28;
	static final double EPS=1e-9;

	int n, s;
	int[][] sum;

	void run(){
		n=10;
		s=330;
		init();
		for(; sc.hasNext();){
			n=sc.nextInt();
			s=sc.nextInt();
			if(n<=10&&s<=330){
				println(sum[n-1][s]+"");
			}else{
				println("0");
			}
		}
		sc.close();
	}

	void init(){
		int[][] dp=new int[s+1][1<<10];
		int[][] dp2=new int[s+1][1<<10];
		sum=new int[n][s+1];
		dp[0][0]=1;

		for(int j=0; j<n; j++){
			for(int i=0; i<=s; i++){
				System.arraycopy(dp[i], 0, dp2[i], 0, 1<<10);
				Arrays.fill(dp[i], 0);
			}
			for(int i=0; i<10; i++){
				int d=(j+1)*i;
				for(int b=0; b<1<<10; b++){
					if(((1<<i)&b)==0){
						for(int k=0; k+d<=s; k++){
							dp[k+d][(1<<i)|b]+=dp2[k][b];
						}
					}
				}
			}
			for(int i=0; i<=s; i++){
				for(int b=0; b<1<<10; b++){
					sum[j][i]+=dp[i][b];
				}
			}
		}

		/*
		 * int ans=0;
		 * for(int i=0; i<1<<10; i++){
		 * ans+=dp[s][i];
		 * }
		 * println(ans+"");
		 */
	}

	int rec(int sum, int flag, int k){
		if(sum>s){
			return 0;
		}
		if(k==n){
			if(sum==s){
				return 1;
			}else{
				return 0;
			}
		}
		int ret=0;
		for(int i=0; i<10; i++){
			if(((1<<i)&flag)==0){
				ret+=rec(sum+(k+1)*i, (1<<i)|flag, k+1);
			}
		}
		return ret;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 14000
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

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

        ArrayList<Integer> m = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            m.add(in.nextInt());
        }

        Collections.sort(m);

        int minimal = m.stream().mapToInt(value -> value).sum();
        int remaining = x - minimal;

        int additional = remaining / m.get(0);

        System.out.println(m.size() + additional);
    }
}


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



const int N = 105, MOD = 1e9 + 7;





int n, m, x, dp[100005], new_dp[100005], pref_dp[100005];




int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    dp[0] = 1;
    for(int i = 1; i <= n; i++){
        cin >> x;
        int sum_dp = 0;
        for(int j = 0; j <= m; j++){
            sum_dp += dp[j];
            if(sum_dp >= MOD){
                sum_dp -= MOD;
            }
            if(j - x - 1 >= 0){
                sum_dp -= dp[j - x - 1];
                sum_dp += MOD;
                if(sum_dp >= MOD){
                    sum_dp -= MOD;
                }
            }
            new_dp[j] = sum_dp;
        }
        for(int j = 0; j <= m; j++){
            dp[j] = new_dp[j];
            new_dp[j] = 0;
        }
    }
    cout << dp[m];
}


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

int main()
{
	int x,n;
	cin >> x >> n;
	vector<int> p(n);

	int res = x;
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];

	}
	
	sort(p.begin(),p.end());

	bool flg = (n==0)? true : false;
	
	if (find(p.begin(), p.end(), x) == p.end())
	{
		flg = true;
	}

	if(flg == false)
	{ 
		int count = 0;
		int low = x,high = x;
		while (100)
		{
			--low;
			++high;
			if (find(p.begin(), p.end(), low) == p.end())
			{
				res = low;
				break;
			}
			
			if (find(p.begin(), p.end(), high) == p.end())
			{
				res = high;
				break;
			}

			++count;
		}
	}
	cout << res;
}




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

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream &operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }
template<typename T>
T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; }

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

// constants
const long double eps = LDBL_EPSILON;
const int inf = 1e15;
const int modn = 1e9+7;
const int maxn = 2e5+3;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    int n;
    cin>>n;
    vi h(n);
    for(int i=0; i<n; i++) {
        cin>>h[i];
    }
    vi dp(n, inf);
    dp[n-1] = 0;
    for(int i=n-2; i>=0; i--) {
        for(int j : {i+1, i+2}) {
            if(j < n) {
                dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
            }
        }
    }
    cout << dp[0] << "\n";
    return 0;
}



Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=new int[n][];
		for(int i = 0;i<n;i++) {
			a[i]=sc.Ia;
		}
		Array.Sort(a,(u,v)=>u[0]-v[0]);
		var h=new long[]{long.MaxValue,long.MinValue,long.MaxValue,long.MinValue};
		for(int i = 0;i<n;i++) {
			h[0]=Min(a[i][0]+a[i][1],h[0]);
			h[1]=Max(a[i][0]+a[i][1],h[1]);
			h[2]=Min(a[i][0]-a[i][1],h[2]);
			h[3]=Max(a[i][0]-a[i][1],h[3]);
		}
		Console.WriteLine(Max(h[1]-h[0],h[3]-h[2]));
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, M;
  cin >> N >> M;
  map<ll, ll> num;
  rep(i, N){
    ll tmp;cin >> tmp;
    num[tmp]++;
  }

  priority_queue<pair<ll, ll>> que;
  for(auto imp: num){
    que.push(make_pair(imp.first, imp.second));
  }

  rep(i, M){
    ll a, b;
    cin >> a >> b;
    que.push(make_pair(b, a));
  }

  ll count = 0;
  ll ans = 0;
  while(count<N){
    pair<ll, ll> p=que.top();
    que.pop();
    if(count+p.second>N){
      ans += (N - count) * p.first;
      break;
    }else{
      count += p.second;
      ans += p.first*p.second;
    }
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 12660
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> Pi;

int main(){
  int n;
  Pi team[333];
  while(cin >> n,n){
    for(int i=0;i<n;i++){
      int I,U,A,B;
      cin >> I >> U >> A >> B;
      P tmp1; tmp1.first = A; tmp1.second = -B;
      P tmp2; tmp2.first = -I; tmp2.second = U;
      team[i].first = tmp1; team[i].second = tmp2;
    }
    sort(team,team+n,greater<Pi>() );
    int idx = 0;
    int cnt = 0;
    int flg[1111]={0};
    while(idx < n && cnt < 26){
      int num = team[idx].second.second;
      int ID = -team[idx].second.first;
      if(cnt < 10){
	if(flg[num] < 3){
	  flg[num]++;
	  cnt++;
	  cout << ID << endl;
	}
      } else if(cnt < 20){
	if(flg[num] < 2){
	  flg[num]++;
	  cnt++;
	  cout << ID << endl;
	}
      } else if(cnt < 26){
	if(flg[num] < 1){
	  flg[num]++;
	  cnt++;
	  cout << ID << endl;
	}
      }
      idx++;
    }
  }
}

Measured memory_bytes: 1172
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

#define SSIZE 1000006

ll A[SSIZE];
ll F[SSIZE];
ll n,k;
bool check(ll num)
{
	ll sum=0;
	for(ll i=1;i<=n;i++)
	{
		sum+=max(0LL,A[i]-(num/F[i]));
	}
	if(sum<=k)
		return true;
	return false;
}

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

	cin>>n>>k;
	for(ll i=1;i<=n;i++)
	{
		cin>>A[i];
	}
	for(ll i=1;i<=n;i++)
	{
		cin>>F[i];
	}
	sort(A+1,A+n+1,greater<ll>());
	sort(F+1,F+n+1);
	ll lo=0,hi=-1;
	for(ll i=1;i<=n;i++)
	{
	    hi=max(hi,A[i]*F[i]);
	}
	while(lo<hi)
	{
		ll mid=lo+(hi-lo)/2;
		if(check(mid))
		{
			hi=mid;
		}
		else
		{
			lo=mid+1;
		}
	}
	cout<<lo;
    return 0;
}


//252908XL

Measured memory_bytes: 5888