akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 4e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vii a(n);
    vii b(n - 1);
    rep(i, n - 1) cin >> b[i];
    a[0] = b[0];
    rep(i,n-2){
        a[i + 1] = min(b[i], b[i + 1]);
    }
    a[n - 1] = b[n - 2];
    int ans = 0;
    rep(i, n) ans += a[i];
    cout << ans << ENDL;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> a(100005);
int num = 0;

int f(int x) {
    if (a.at(x) == 0) {
        cout << -1 << endl;
        return 0;
    }
    if (a.at(x) == 2) {
        num++;
        cout << num << endl;
        return 0;
    }
    int y = a.at(x);
    a.at(x) = 0;
    num++;
    f(y);
    return 0;
}

int main() {
    int N;
    cin >> N;
    
    for (int i = 1; i <= N; i++) cin >> a.at(i);

    f(1);
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = 3.1415926535898; //

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

bool cont(string s) {
    for (auto c : s) {
        if (c != s[0]) return true;
    }
    return false;
}

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

    int cnt[26] = {};

    rep(i, 26) {
        string t = s;
        char c = (char) ('a' + i);
        while (cont(t)) {
            string u = "";

            rep(j, t.length() - 1) {
                if (t[j] == c || t[j + 1] == c) u.push_back(c);
                else u.push_back(t[j]);
            }
            cnt[i]++;
            t = u;
        }
    }

    int Min = INF;
    rep(i, 26) Min = min(Min, cnt[i]);
    cout << Min << endl;

    return 0;
}


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

int n;
ll a[30][30];
ll dp[1<<21];

int main(){
    cin >> n;
    rep(i,n){
        rep(j,n){
            cin >> a[i][j];
        }
    }

    dp[0] = 1;
    for(int S=1;S < 1<<n; S++){
        int i = __builtin_popcount(S);
        rep(j,n){
            if((S>>j) & 1 && a[i-1][j]){
                dp[S] = (dp[S] + dp[S^(1<<j)]) % MOD;
            }
        }
    }

    cout << dp[(1<<n)-1] << endl;
}

Measured memory_bytes: 20012
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<map>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n;
  cin >> n;
  ll a[n],ans=1,sum[n],val[3]={};
  bool can=true;
  fill(sum,sum+n,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum[a[i]]++;
    if(sum[a[i]]>3){
      can = false;
    }
  }
  if(a[0]!=0||!can){
    cout <<"0\n";
    return 0;
  }
  fill(sum,sum+n,0);
  val[0]=1;
  ans = 3;
  for(int i=1;i<n;i++){
    ll cnt=0,idx=-1;
    for(int j=0;j<3;j++){
      if(val[j]==a[i]){
        cnt++;
        if(idx==-1) idx=j;
      }
    }
    if(idx==-1){
      cout <<"0\n";
      return 0;
    }
    ans *= cnt;
    ans %= MOD;
    val[idx]++;
  }
  cout << ans << endl;
}


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

int main(void)
{
    // H=行 W=列
    int H, W;
    int h, w;
    cin >> H >> W >> h >> w;

    vector<vector<int>> map(H, vector<int>(W, 0));
    for (int i = 0; i < H; i++) // 2
    {
        for (int j = 0; j < W; j++) // 1
        {
            if (i < h)
                map.at(i).at(j)++;
            if (j < w)
                map.at(i).at(j)++;
        }
    }

    int counter = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (map.at(i).at(j) == 0)
                counter++;
        }
    }

    // for (int i = 0; i < H; i++)
    // {
    //     for (int j = 0; j < W; j++)
    //     {
    //         cout << map.at(i).at(j) << " ";
    //     }
    //     cout << endl;
    // }

    cout << counter << endl;
    return (0);
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
#include<stdlib.h>
int main(void){
    int w,h,i,j;
    char c;
    scanf("%d %d %c",&w,&h,&c);
    for(i=1;i<=h;i++){
        for(j=1;j<=w;j++){
            if((i==1||i==h)&&(j==1||j==w)){
                printf("+");
            }
            else if((i==1||i==h)&&(j!=1||j!=w)){
                printf("-");
            }
            else if(i==(h+1)/2&&j==(w+1)/2){
                printf("%c",c);
            }
            else if((i!=1||i!=h)&&(j==1||j==w)){
                printf("|");
            }
            else{
                printf(".");
            }
            
            
        }
        printf("\n");
    }
    
    
    
    
    
}



Measured memory_bytes: 2112
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_A() {}


int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    string N; cin >> N;

    string ans = "ABC" + N;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7;
const int larg = 1e5;

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

int main() {
	double N,K;
	double prob = 0;
	cin >> N >> K;
	for(int i=1;i<=N;i++){
		double temp = 1.0/N;
		double now = i;
		while(now < K){
			temp /= 2;
			now *= 2;
		}
		prob += temp;
	}
	cout << setprecision(10) <<prob;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long R){
	if (N >= 10) cout << R << endl; else cout << R+100*(10-N) << endl;
}

int main(){	
	long long R;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&R);
	solve(N, R);
	return 0;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BTwoSwitches {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int[] a = in.ints(4);
            boolean[] b = new boolean[101];
            for (int i = a[0]; i <= a[1]; i++) {
                b[i] = true;
            }
            int ans = 0;
            for (int i = a[2]; i <= a[3]; i++) {
                if (b[i]) {
                    ans++;
                }
            }
            out.println(Math.max(0, ans - 1));
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

        public int[] ints(int length) {
            return IntStream.range(0, length).map(x -> ints()).toArray();
        }

    }
}



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

int main(){
	int n, MAX=1, x;
	cin>>n;
	for(int i=2;i<n;i++){
		x=i;
		x*=i;
		while(n>=x){
			MAX=max(MAX,x);
			x*=i;
		}
	}
	cout<<MAX<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, list(input() for _ in range(n))))
visited = list(False for _ in range(n))

if (2 in a) == False:
    print(-1)
    exit()
    
idx = 1
cnt = 0
while True:
    cnt += 1
    if a[idx - 1] == 2:
        print(cnt)
        exit()
    else:
        if visited[idx - 1] == True:
            print(-1)
            exit()
        else:
            visited[idx - 1] = True
            idx = a[idx - 1] ##次のボタン

Measured memory_bytes: 13448
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    string s;
    cin>>s;
    int n=s.size();
    int dame=0;
    for(int i=0;i<n;i++){
        if(i%2==0){//kisuu
            if(s[i]=='R'||s[i]=='U'||s[i]=='D'){

            }
            else{
                dame++;
            }
        }
        else{
            if(s[i]=='L'||s[i]=='U'||s[i]=='D'){

            }
            else{
                dame++;
            }
        }
    }

    if(dame==0){
        cout<<"Yes";

    }
    else{
        cout<<"No";
    }
}

Measured memory_bytes: 256
from collections import deque

Q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

K = int(input())

for i in range(K):
    q = Q.popleft()
    
    next_cand = q * 10 + q % 10
    
    if (q % 10 != 0):
        Q.append(next_cand - 1)
    
    Q.append(next_cand)
    
    if (q % 10 != 9):
        Q.append(next_cand + 1)
    
print(q)

Measured memory_bytes: 11864
s = input()

si = []
so = []
for i in range(len(s)):
  si.append(int(s[i]))
  so.append(int(s[i]))

so[0] = (so[0] + 1) % 2

cnti = 0
cnto = 1
for i in range(1, len(s)):
  if si[i] == si[i-1]:
    si[i] = (si[i] + 1) % 2
    cnti += 1
  if so[i] == so[i-1]:
    so[i] = (so[i] + 1) % 2
    cnto += 1

print(min(cnti, cnto))

Measured memory_bytes: 47964
using System;
using System.Collections.Generic;
using System.IO;

class Solve{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var P = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var Q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int a = 1, b = 1;
        var set = new HashSet<int>();
        for (int i = 0; i < N; i++){
            var pi = P[i];
            int count = 0;
            foreach (var s in set){
                if (s < pi) count++;}
            var x = pi - count;
            a += (x - 1) * Factorial(N - 1 - i);
            set.Add(pi);}
        set.Clear();
        for (int i = 0; i < N; i++){
            var qi = Q[i];
            int count = 0;
            foreach (var s in set){
                if (s < qi) count++;}
            var x = qi - count;
            b += (x - 1) * Factorial(N - 1 - i);
            set.Add(qi);}
        var answer = Math.Abs(a - b);
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}

    public static int Factorial(int n){
        int result = 1;
        for (int i = n; i > 1; i--){
            result *= i;}
        return result;}}

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

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

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

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

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

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

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

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

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

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

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

fn main() {
    input!{
      n: usize,
      a: chars,
      b: chars,
      c: chars,
    }

    let mut ans = 0;
    for i in 0..n {
        let ac = a[i];
        let bc = b[i];
        let cc = c[i];

        if ac == cc && ac == bc {
        } else if ac == bc || ac == cc || bc == cc {
            ans += 1;
        } else {
            ans += 2;
        }
    }
    println!("{}", ans);
}


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

using namespace std;

int main()
{
	int x,n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(x%2==0 && (x%5!=0 && x%3!=0))
		{
			cout<<"DENIED"<<'\n';
			return 0;
		}
	}    
   	cout<<"APPROVED"<<'\n';
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

signed main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a * b) / 2 << endl;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;


int main() {
  ll n; cin >> n;

  int ans = INF;
  rep2(a, 1, n) {
    int b = n - a;
    int z = 0;
    for (auto &c : to_string(a)) z += (c - '0');
    for (auto &c : to_string(b)) z += (c - '0');
    chmin(ans, z);
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) throws Exception{
	Scanner sc = new Scanner(System.in);
    String rgb = sc.nextLine().replace(" ","");
    String result = Integer.parseInt(rgb) % 4 == 0 ? "YES" : "NO";
    System.out.println(result);
  }
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    string a;
    cin >> n >> a;
    int odp = 0;
    int i = 0, j = n - 1;
    while (i < n)
    {
        if (a[i] == 'W')
        {
            while (j > i && a[j] == 'W')
                --j;
            if (j > i)
            {
                ++odp;
                a[i] = 'R';
                a[j] = 'W';
                ++i;
            }
            else
            {
                cout << odp;
                return 0;
            }
        }
        else
            ++i;
    }
    cout << "0";
    return 0;
}


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

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    COMinit();

    string S;
    cin >> S;
    ll Q;
    cin >> Q;

    int reverse_flg = 0;
    string front = "";
    string rear = "";

    for(int i = 0; i < Q; i++) {
        int T;
        cin >> T;
        if(T==1) reverse_flg++;
        else {
            int F;
            cin >> F;
            char C;
            cin >> C;
            if((reverse_flg+F) % 2 == 0) rear = rear + C;
            else front = C + front;
        }
    }

    //if(reverse_flg % 2 == 1) reverse(S.begin(), S.end());
    S =  front + S + rear;
    if(reverse_flg % 2 == 1) reverse(S.begin(), S.end());
    cout << S << endl;

    return 0;
}


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

int N, K;
int h[100000], ans = 1000000000;

int main()
{
    scanf("%d %d", &N, &K);
    for (int i = 0; i < N; i++)
        scanf("%d", h + i);
    sort(h, h+N);
    for (int i = 0; i < N - K + 1; i++)
        ans = min(ans, h[i + K - 1] - h[i]);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <assert.h>

using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
#define each(i,n) for(auto &i : n)

int main() {
	
	int n, x;
	cin >> n >> x;

	int m = 2 * n - 1;

	if (x == 1 || x == m) {
		cout << "No" << endl; return 0;
	}
	cout << "Yes" << endl;
	
	vector<int> ans(m, -1);

	set<int> use;
	ans[m / 2] = x; use.insert(x);

	if (x <= m - 2) {
		ans[m / 2 + 1] = 1; use.insert(1);
		ans[m / 2 - 1] = m; use.insert(m);
		ans[m / 2 + 2] = m - 1; use.insert(m-1);
	}
	else {
		ans[m / 2 + 1] = m; use.insert(m);
		ans[m / 2 - 1] = 1; use.insert(1);
		ans[m / 2 + 2] = 2; use.insert(2);
	}

	int c = 1;
	rep(i, m) {
		if (ans[i] == -1) {
			while (use.count(c)) {
				c++;
			}
			ans[i] = c;
			use.insert(c);
		}
	}

	rep(i, m) {
		cout << ans[i] << endl;
	}

	return 0;
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	int ones = n % 10;
	if (ones == 2 || ones == 4 || ones == 5 || ones == 7 || ones == 9) cout << "hon\n";
	else if (ones == 0 || ones == 1 || ones == 6 || ones == 8) cout << "pon\n";
	else cout << "bon\n";
	return 0;
}

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

    string op1 = s.substr(0, n/2);
    string op2 = s.substr(n/2);

    if(op1 == op2)
        cout <<  "Yes" ;
    else
    {
        cout << "No";
    }
    

    return 0;
}

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

int t[5];

int main(){
  for(int i=0;i<3;i++){
    int a,b;
    cin>>a>>b;
    t[a]++;
    t[b]++;
  }
  for(int i=1;i<=4;i++){
    if(t[i]>2){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
 
class DandA {
    static void Main(string[] args) {
        long n = ReadLineLong();
        long rtn = 0;
        if (n % 2 == 1) {
            rtn = ((n - 1) / 2) * n;
        } else {
            rtn = ((n - 1) / 2) * n;
            rtn += n / 2;
        }
        Console.WriteLine(rtn);
    }
 
    static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static string[] strAry = new string[] {"L", "R", "U", "D"}; 
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private long ReadLineLong() {return long.Parse(Console.ReadLine());}
    static private double ReadLineDouble() {return double.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private double[] ReadLineDoubleArray() {return Console.ReadLine().Trim().Split().Select(a => double.Parse(a)).ToArray();}
    static private decimal[] ReadLineDecimalArray() {return Console.ReadLine().Trim().Split().Select(a => decimal.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
 
    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
  
    static private string IntToNString(int x, int n) {
        var nstring = "";
        var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
        int r = 1;
        int q = x;
        while (q > 0) {
            r = q % n;
            nstring += numbers[r];
            q = q / n;
        }
        return string.Join("",nstring.Reverse());
     }
}

Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <deque>
#include <string>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <map>
#include <unordered_map>
#include <bitset>

#define _crt_secure_no_warnings
#define FREEELO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F
#define MAX 101
#define MOD 1000000007
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;


int main(){
    ll a, b, c; cin >> a >> b >> c;
    cout << (b * c >= a ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3088
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#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;
typedef pair<int, int> pi;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int n,m,k;
vector<vector<int>> adj;

class DSU
{
    private:
        vector<int> parent;
        vector<int> siz;
    public:
        DSU(int n)
        {
            F0R(i,n)
            {
                parent.pb(i);
                siz.pb(1);
            }
        }
        int find_set(int v)
        {
            if(parent[v]==v)
                return v;
            return parent[v]=find_set(parent[v]);
        }
        void union_sets(int f, int s)
        {
            f=find_set(f);
            s=find_set(s);
            if(s==f)
                return;
            if(siz[f]>siz[s])
                swap(f,s);
            parent[f]=s;
            siz[s]+=siz[f];
        }
        int size(int v)
        {
            return siz[find_set(v)];
        }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> k;
    adj.assign(n,{});
    DSU inst(n);
    vector<int> block(n,0),edges(n,0);
    F0R(i,m)
    {
        int a,b;
        cin >> a >> b;
        a--; b--;
        inst.union_sets(a,b);
        edges[a]++; edges[b]++;
    }
    F0R(i,k)
    {
        int a,b;
        cin >> a >> b;
        a--; b--;
        if(inst.find_set(a)==inst.find_set(b))
            block[a]++,block[b]++;
    }
    F0R(i,n)
        cout << inst.size(i)-1-edges[i]-block[i] << " ";

    return 0;
}


Measured memory_bytes: 4980
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int get(int n,int k){
	int res=0;
	while(n>0){
		n=n/k;
		res++;
	}
	return res;
}

int32_t main(){
	boost;
	int n,r;
	cin>>n>>r;
	cout<<get(n,r);
	return 0;
}

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

//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int n,m,c;
  cin >> n >> m >>c;
  int ans;
  VI a(m),b(m);
  REP(i,m){
    cin >> b[i];
  }
  REP(i,n){
  int eq=c;
    REP(j,m){
      cin >> a[j];
      eq+=a[j]*b[j];
    }
    if(eq>0)ans++;
  }
  
//  VI cd(n);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstring>
#include <cmath>
using namespace std;
int maxx=0;
char a[1010][1010];
int vis[1010][1010];
int h,w;
struct node
{
    int x,y,cnt;
    char c;

};
bool jud()
{
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(a[i][j]=='.')
                return false;
        }
    }
    return true;
}
void bfs()
{
    queue<node> q;

    memset(vis,0,sizeof(vis));
    while(jud()==false)
    {

        for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(a[i][j]=='#')
            {
                vis[i][j]=1;
                node b;
                b.c=a[i][j]; b.x=i; b.y=j;b.cnt=0;
                q.push(b);

            }
        }
    }
        while(q.empty()==false)
        {

            node d=q.front();//d.cnt++;
            q.pop();
            //d.cnt++;
            maxx=max(maxx,d.cnt);
            if(d.x+1<h&&vis[1+d.x][d.y]==0&&a[1+d.x][d.y]=='.')
            {
                a[1+d.x][d.y]='#';//cout<<"a";
                node e;e.c='#';e.cnt=d.cnt+1;e.x=1+d.x;e.y=d.y;
                q.push(e);
            }
            if(d.x-1>=0&&vis[d.x-1][d.y]==0&&a[d.x-1][d.y]=='.')
            {
                a[d.x-1][d.y]='#';
                node e;e.c='#';e.cnt=d.cnt+1;e.x=d.x-1;e.y=d.y;
                q.push(e);
            }
            if(d.y+1<w&&vis[d.x][d.y+1]==0&&a[d.x][d.y+1]=='.')
            {
                a[d.x][d.y+1]='#';
                node e;e.c='#';e.cnt=d.cnt+1;e.x=d.x;e.y=d.y+1;
                q.push(e);
            }
            if(d.y-1>=0&&vis[d.x][d.y-1]==0&&a[d.x][d.y-1]=='.')
            {
                a[d.x][d.y-1]='#';
                 node e;e.c='#';e.cnt=d.cnt+1;e.x=d.x;e.y=d.y-1;
                q.push(e);
            }
//cout<<"a"<<maxx<<endl;
       }
    }


}

int main()
{
    cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>a[i][j];
        }
    }
    bfs();
    cout<<maxx;
    return 0;
}


Measured memory_bytes: 15376
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double eps=1e-6;
double PI=acos(-1);
 
P getCrossPoint(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
bool isParallel(P a,P b,P c,P d){
  return (abs(imag( (b-a)*conj(d-c) ) )<eps);
}
 
int lcm(int a,int b){
  return a/ __gcd(a,b) * b;
}
 
int n;
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
     
    double R=1.0/sqrt(3.0);
    P a=P(R,0);
    P b=P(R-0.5*sqrt(3.0),0.5);
     
    double lc=lcm(n,3);
    double ti=2.0*PI/lc;
 
    P c=a,d=b;
 
    if(lc==3){
      printf("0.433013\n");
      continue;
    }
     
    double T=1e9;
    for(int i=1;i<=lc/3;i++){
      c=a*P(cos(ti*i),sin(ti*i));
      d=b*P(cos(ti*i),sin(ti*i));
      if(!isParallel(a,b,c,d)){
        P target=getCrossPoint(a,b,c,d);
        double k=min(abs(target-a),abs(target-b));
        if(k>eps)T=min(T,k);
      }

      if(i==3)break;
    }
    for(int i=lc/3;i>=1;i--){
      c=a*P(cos(ti*i),sin(ti*i));
      d=b*P(cos(ti*i),sin(ti*i));
      if(!isParallel(a,b,c,d)){
        P target=getCrossPoint(a,b,c,d);
        double k=min(abs(target-a),abs(target-b));
        if(k>eps)T=min(T,k);
      }

      if(i==lc/3-2)break;
    }
    
    double ans=T*R*0.5;
    printf("%.8f\n",ans*lc);
  }
}

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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;



struct CentroidGraph{
    int n;
    vector<vector<int>> g;
    vector<int> centroid;
    vector<int> sz;
    CentroidGraph(int n_):n(n_),g(n_),sz(n_){}
    void add_edge(int a,int b){
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> findCentroid(){
        function<void (int, int)> dfs = [&](int u, int prev) {
            sz[u] = 1;
            bool is_centroid = true;
            for (auto v : g[u]) if (v != prev) {
                dfs(v, u);
                sz[u] += sz[v];
                if (sz[v] > n / 2) is_centroid = false;
            }
            if (n - sz[u] > n / 2) is_centroid = false;
            if (is_centroid) centroid.push_back(u);
        };
        dfs(0, -1);
        return centroid;
    }
    //重心ｃ周りの部分木のサイズ
    int size(int k,int c=0){
        return sz[k]>n/2? n-sz[centroid[c]]:sz[k];
    }

    vector<int> operator[](const int& k){
        return g[k];
    }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  CentroidGraph G(N);
  vector<tuple<ll,ll> > E(N-1);
  vll val(N);
  for(ll i=0;i<N-1;i++){
    ll a,b;cin>>a>>b;a--;b--;
    E[i] = make_tuple(a,b);
    G.add_edge(a,b);
  }
  vll C(N);
  for(ll i=0;i<N;i++){
    cin>>C[i];
  }
  sort(C.begin(),C.end());
  vector<int> cent=G.findCentroid();
  queue<ll> Q;
  Q.push(cent[0]);
  vector<bool> used(N,false);
  ll cnt=N;
  while(!Q.empty()){
    ll v=Q.front();
    Q.pop();
    if(used[v])continue;
    used[v]=true;
    val[v]=C[--cnt];
    for(ll u:G.g[v]){
      Q.push(u);
    }
  }
  ll ans = 0;
  for(ll i=0;i<N-1;i++){
    ll a,b;
    tie(a,b)=E[i];
    ans += min(val[a],val[b]);
  }
  cout<<ans<<endl;
  for(ll i=0;i<N;i++){
    cout<<val[i]<<(i<N-1?" ":"\n");
  }
  return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
#include<math.h>
int main()
{
    int x, y, j, k, i, m;
    scanf("%d%d",&x,&y);
    if(x>=500)
    {
        m=x%500;
        if(m<=y)
        {
            printf("Yes");
        }
        else
        {
            printf("No");
        }
    }
    else if(x<=500)
    {
        if(y>=x)
        {
            printf("Yes");
        }
        else
        {
            printf("No");
        }
    }
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
using namespace std;
int main(void)
{
    int K = 0 ,X = 0;
    cin >> K >> X;
    int henka = K - 1;
    int shoki = X - henka;
    for (int i = 0; i < K + henka; i++)
    {
        cout << shoki + i << " ";
    }
    cout << endl;
    
    return 0;
}

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

typedef long long int LL;
typedef unsigned long long uLL;
typedef pair< int,int > ii;
typedef pair< int,ii > iii;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 100005;
const int MOD = 1e9+7;
const double EPS = 1e-6;
const double PI = acos(-1.0);

LL x = 10000 , y = 5000 , z = 1000;

int main( int argc, char const *argv[] ) {
    LL n , val;
    cin >> n >> val;
    for( LL i = 0; i <= n && x*i <= val ; i++ ) {
        for( LL j = 0; j <= n && ( x*i+y*j <= val ); j++ ) {
            LL tot = x*i+y*j;
            if( tot > val ) break;
            if( tot == val && ( i+j == n ) ) {
                cout <<i << " " << j << " " << 0 <<endl;
                return 0;
            }
            LL rem = val-tot;
            if( rem < 0 ) break;
            if( rem%1000 == 0 ) {
                LL k = rem/1000;
                if( i+j+k == n ) {
                    cout << i << " " << j << " " << k <<endl;
                    return 0;
                }
            }
        }
    }
    cout << "-1 -1 -1" <<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0)
#define pb push_back
#define N 100005
int main(){

	ll n;
	cin>>n;

	ll a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];

	ll dp[n+5];
	memset(dp,0,sizeof(dp));

	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);

	for(int i=2;i<n;i++){
		dp[i] = min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);

	}

	cout<<dp[n-1]<<"\n";
}


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

#define ll long long
#define ld long double

ll ceil(ll a, ll b) {
    if(a % b) return a/b + 1LL;
    return a/b;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(auto &it : a) cin >> it;
    
    ll ans = 0, mx = a[0];
    
    for(int i=1; i<n; ++i) {
        if(mx > a[i]) ans += mx - a[i];
        else mx = a[i];
    }
    
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    // int t;
    // cin >> t;
    // while(t--)
        solve();
    
    return 0;
}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
#define P pair<long long, long long>
#define PP pair<long long, P>
#define MAX 300000
#define MOD 1000000007
using namespace std;

int n;
P p[MAX];
long long pw[MAX];
P line[MAX];

long long gcd( long long a, long long b){
    return !b ? a : gcd(b, a % b);
}

P get( P p1, P p2 ){
    long long A = p1.second - p2.second;
    long long B = p2.first - p1.first;
    long long C = p1.first * p2.second - p2.first * p1.second;
    //cout << A << ' ' << B << ' ' << C << endl;
    long long g = gcd(abs(A), abs(B));
    g = gcd(g, abs(C));
    A /= g;
    B /= g;
    C /= g;
    if( A < 0 ){
        A = -A;
        B = -B;
        C = -C;
    }
    else if(A == 0 ){
        if( B < 0 )
            B = -B, C = -C;
    }
    return P(A, B);
}

map<P, long long> mp;
set<P> mark;

P orth(P L){
    P ret(L.second, -L.first);
    if(ret.first < 0 || ( ret.first == 0 && ret.second < 0 ))
        ret.first *= -1, ret.second *= -1;
    return ret;
}

int main()
{
    pw[0] = 1;
    for( long long i = 1; i < MAX; i++ ){
        pw[i] = ( 2LL * pw[i - 1] ) % MOD;
    }
    cin >> n;
    long long zero = 0;
    for( int i = 0; i < n; i++ ){
        long long a, b;
        cin >> a >> b;
        p[i] = P(a, b);
        if(a == 0 && b == 0){
            zero++;
            continue;
        }
        line[i] = get(P(a, b), P(0, 0));
        mp[line[i]]++;
        //cout << "HERE " << line[i].first << ' ' << line[i].second << endl;
    }
    long long res = 1;
    for( int i = 0; i < n; i++ ){
        if(p[i].first == 0 && p[i].second == 0)
            continue;
        if( mark.count(line[i]) )
            continue;
        
        P o = orth(line[i]);
        int sz1 = mp[line[i]];       
        int sz2 = mp[o];

        //cout << line[i].first << ' ' << line[i].second << ' ' << o.first << ' ' << o.second << ' ' << sz1 << ' ' << sz2 << endl;
        
        res *= ( pw[sz1] + pw[sz2] - 1 );
        res %= MOD;
        mark.insert(line[i]);
        mark.insert(o);
    }
    res += zero;
    res--;
    res = ( res + MOD ) % MOD;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 62236
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int x = int.Parse(input[1]);
        int t = int.Parse(input[2]);

        int s;
        if (n % x == 0)
        {
            s = n / x;
        }
        else
        {
            s = n / x + 1;
        }
        Console.WriteLine(s * t);
    }
}

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

int main(){
  int n;
  double xa,ya,ra,xb,yb,rb,d;
  cin>>n;
  for(;n>0;n--){
    cin>>xa>>ya>>ra>>xb>>yb>>rb;
    d = sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
    if(d>ra+rb)
      cout<<0<<endl;
    if(abs(ra-rb)<=d&&d<=ra+rb)
      cout<<1<<endl;
    if(d<ra-rb)
      cout<<2<<endl;
    if(d<rb-ra)
      cout<<-2<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
 

int main()
{
	string S, T, U;
	int A, B;

	cin >> S >> T;
	cin >> A >> B;
	cin >> U;

	if(U==S){
		cout << A-1 << ' ' << B;
	}
	if(U==T){
		cout << A << ' ' << B-1;
	}

	return 0;
}

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

int32_t main()
{
  int n;int k;cin>>n>>k;
  vector<int>arr(n+1,0);
  for(int i=1;i<=n;i++)
    cin>>arr[i];
 
 
        if(k>n)
    {
          vector<int>kaha;
          kaha.push_back(0);
          set<int>st;
          int i;
          int prev=1;
          for(i=1;i<=n;i++)
          {
              if(st.find(arr[prev])==st.end())
              kaha.push_back(arr[prev]);
              else
              break;
              
              st.insert(arr[prev]);
              prev=arr[prev];
          }
          
          int ele=arr[prev];
          int pos=find(kaha.begin(),kaha.end(),ele)-kaha.begin();
          vector<int>res;
          res.assign(kaha.begin()+pos,kaha.end());
          k=k-kaha.size();
          int index=k%res.size();
          cout<<res[index]<<endl;
    }
    else
    {
        int prev=1;int pos=1;
        for(int i=1;i<=k;i++)
        {
            pos=arr[prev];
            prev=pos;
        }
        cout<<pos<<endl;
    }
}
  
  
  


Measured memory_bytes: 13364
N = int(input())
keta = len(str(N))
cnt = 0

for i in range(keta):
    if i % 2 == 1:
        cnt += 10**(i) - 10**(i-1)

if keta % 2 == 1:
    cnt += N - 10**(keta-1) + 1

print(cnt)

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

const int MAXN = 300010;
void bye() { std::cout << "No" << std::endl; exit(0); }
int A[MAXN], n;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> A[i];
	auto typ = [] (int i) { return (A[i] == i) ^ (i & 1); };
	for (int l = 1, r; l <= n; l = r + 1) {
		if (A[l] == l) { r = l; continue; }
		for (r = l; r <= n; ++r)
			if (typ(l) != typ(r))
				break;
		--r;
		int inc = 0, dec = 0;
		for (int j = l; j <= r; j += 2) {
			if (A[j] > j) { if (A[j] < inc) bye(); inc = A[j]; }
			else { if (A[j] < dec) bye(); dec = A[j]; }
			if (dec != 0 && dec < l) bye();
			if (inc != 0 && inc > r) bye();
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}


Measured memory_bytes: 1536