akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Numerics;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		public static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush =
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadInt;
			var S = cin.ReadLine;
			var count = 0;
			List<int> Whites = new List<int>(), Reds = new List<int>();
			for(int i = 0; i < N; i++) {
				if(S[i] == 'W') {
					Whites.Add(i);
				} else {
					Reds.Add(i);
				}
			}
			Reds.Reverse();
			var pairMax = Min(Whites.Count, Reds.Count);
			while(count<pairMax && Whites[count]<Reds[count]) {
				count++;
			}
			Console.WriteLine(count);
		}

	}

	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ")
			=> string.Join(separator, X);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i < N; ++i)
				ret[i] = Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek() == -1; }
		}
	}
	
}

Measured memory_bytes: 30628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

ll mod(ll a) {
	if (a > 0) return a % MOD;
	if (a % MOD == 0) return 0;
	ll x = -a / MOD + 1;
	a += x * MOD;
	return a % MOD;
}

template <typename T> void dump(T x) { cout << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
// int dx[4]    = {1, 0, -1, 0};
// int dy[4]    = {0, 1, 0, -1};
// ll pas[5001][5002];

ll cnt[26] = {};

int main() {
	IOS();
	ll n;
	string a, b, c;
	cin >> n >> a >> b >> c;
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] == b[i] && b[i] == c[i])
			continue;
		else if (a[i] == b[i] || b[i] == c[i] || a[i] == c[i])
			ans++;
		else
			ans += 2;
	}
	dump(ans);
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(int, "val", int, "num");

void main() {
    int n, m;
    scan(n, m);
    auto a = readln.split.to!(int[]);

    auto bh = new BinaryHeap!(Array!Pair, "a.val < b.val")();

    foreach (ai ; a) {
        bh.insert(Pair(ai, 1));
    }

    foreach (i ; 0 .. m) {
        int bi, ci;
        scan(bi, ci);
        bh.insert(Pair(ci, bi));
    }

    long ans;
    int cnt;

    while (cnt < n) {
        auto p = bh.front; bh.popFront();
        auto t = min(n - cnt, p.num);
        n -= t;
        ans += 1L * p.val * t;
    }

    writeln(ans);
}





















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 7208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p = sc.nextInt();
		int[] biscuitsInfo = new int[n];
		int odd =0;
		int even =0;
		for(int i =0;i < n;i++) {
			int biscuit = sc.nextInt();
			biscuitsInfo[i] = biscuit;
			if(biscuit % 2 ==0) {
				even++;
			}else {
				odd++;
			}
		}
		if(odd ==0) {
			if(p ==0) {
				System.out.println((long)Math.pow(2,even));
			}else {
				System.out.println(0);
			}
			return;
		}
		if(even ==0) {
			System.out.println((long)(Math.pow(2,odd) / 2));
			return;
		}
		System.out.println((long)(Math.pow(2,odd) / 2) * (long)Math.pow(2,even));
	}
}

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

void rec(int parent, int self, int cntsum, vector<set<int>> &connect, vector<int> &cntarr, vector<int> &ans) {
    connect[self].erase(parent);
    for (auto itr = connect[self].begin(); itr != connect[self].end(); itr++) {
        int child  = *itr;
        int copycntsum = cntsum + cntarr[child];
        rec(self, child, copycntsum, connect, cntarr, ans);
    }
    ans[self] = cntsum;
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<set<int>> connect(n);
    rep(i,n-1) {
        int a, b;
        cin >> a >> b; a--, b--;
        connect[a].insert(b);
        connect[b].insert(a);
    }
    vector<int> cntarr(n);
    rep(i,q) {
        int p, x;
        cin >> p >> x; p--;
        cntarr[p] += x;
    }
    vector<int> ans(n);
    rec(-1, 0, cntarr[0], connect, cntarr, ans);
    rep(i,n) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

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

int main()
{
    string S;
    cin >> S;
    int co0=0;
    int co1=0;
    int ce0=0;
    int ce1=0;
    for(int i=0;i<S.size();i++){
        if(i%2==0){
            if(S[i]=='0') ce0++;
            else          ce1++;
        }else{
            if(S[i]=='0') co0++;
            else          co1++;
        }
    }
    cout<<min(ce0+co1, ce1+co0)<<endl;

    return 0;
}

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

using namespace std;

int main(){
    int N = (int)(1e5 + 0.5);
    // エラトステネスの篩
    vector<bool> isPrime(N, true);
    isPrime.at(0) = isPrime.at(1) = false;
    for(int i=2; i<N; i++){
        if(!isPrime.at(i))continue;
        for(int j = i*2; j<N; j+=i)isPrime.at(j) = false;
    }

    // 2017-like数か否か
    vector<bool> is2017like(N, false);
    for(int i=0; i<N; i++){
        if(i % 2 == 0)continue;
        if(isPrime.at(i) && isPrime.at((i+1)/2))is2017like.at(i) = true;
    }

    // is2017likeの累積和
    vector<int> cs(N+1, 0);
    for(int i=0; i<N; i++)cs.at(i+1) = cs.at(i) + is2017like.at(i);

    int Q;
    cin >> Q;
    for(int i=0; i<Q; i++){
        int l,r;
        cin >> l >> r;
        cout << cs.at(r+1) - cs.at(l) << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main() {
  int a, b;
  scanf("%d %d", &a, &b);

  int s = 1;
  int r = 0;
  while (s < b) {
    s--;
    s += a;
    r++;
  }

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def popcnt(n):
    return bin(n).count("1")


def mod(n, cnt):
    if n == 0:
        return cnt
    n = n % popcnt(n)
    cnt += 1
    return mod(n, cnt)


n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c - 1 != 0 else 0

for i in range(n):
    if x2[i] == '0':
        t = (mod1 + pow(2, n - i - 1, c + 1)) % (c + 1)
    else:
        if c - 1 != 0:
            t = (mod2 - pow(2, n - i - 1, c - 1)) % (c - 1)
        else:
            print(0)
            continue
    print(mod(t, 1))


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

signed main(){
    int x;
    cin>>x;
    int sum=0;
    int p=x/500;
    sum+=p*1000;
    x=x-500*p;
    p=x/5;
    sum+=5*p;
    cout<<sum;
}

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

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

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

#define endl '\n'
#define re return

#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define repd(i,a,b) for (ll i = (a); i >= b; i--)
#define repdz(i,a) for (ll i = a; i >=0; i--)
#define trav(a, x) for (auto& a : x)

#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define llin(a) ll a; cin>>a;
#define llin2(a,b) ll a,b; cin >>a>>b;
#define llin3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define full(v) v.begin(),v.end()

void solve()
{
    int n,m;
    cin >> n >> m;
    int sum=0;
    repz(i,m)
    {
        int x;
        cin >> x;
        sum += x;
    }
    if (n-sum <0)
        cout << -1 << endl;
    else
    cout << n-sum << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    //llin(t);
    //while (t--)
    //{
        solve();
    //}
}


Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
using namespace std;

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

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

Measured memory_bytes: 256
/*
Abdullah All Rawaha Anik
American International University - Bangladesh
18-*****-1
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<ll,ll>
#define mp make_pair
#define  pb push_back
#define pf push_front
#define ll long long
const ll MAXN = 1e5+7;
ll arr[MAXN];
pii A[MAXN];
ll power(ll x, ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}
ll bigmod(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a;
    cin>>a;
    ll p=a.length();
    for(ll i=0;i<p;i++)
        printf("x");
    printf("\n");
}




Measured memory_bytes: 256
S = input() 
Q = int(input())
rlist, llist = [], []
flag, cnt = 0, 0

def trans(f):
    if f == 1:
        f = 0
    elif f == 0:
        f = 1
    return f

def pros(f, r, add):
    if f == 0:
        if r == "1":
            llist.append(lists[2])
        elif r == "2":
            rlist.append(lists[2])
    elif f == 1:
        if r == "2":
            llist.append(lists[2])
        elif r == "1":
            rlist.append(lists[2])

for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        flag = trans(flag)
        cnt += 1
    else:
        pros(flag, lists[1], lists[2])
        
llist.reverse()
        
S = "".join(llist) + S + "".join(rlist)

if cnt % 2 == 1:
    S = S[::-1]
print(S)

Measured memory_bytes: 5704
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N; cin >> N;
  double odd;
  if (N % 2 == 0) odd = N / 2;
  else odd = N / 2 + 1;
  printf("%.7f\n", odd/N);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000
int C[VMAX+1];
int B[MAX];
void CountingSort(int A[],int n)
{
  int i,j;
    for(i=0; i<=VMAX+1; i++){
      C[i] = 0;
    }
    for(j=1; j<=n; j++){
      C[A[j]]++;
    }
    for(i=1; i<=VMAX+1; i++){
      C[i] = C[i]+C[i-1];
    }
    for(j=n; j>=1; j--){
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }
    for(i=1; i<n; i++){
      printf("%d ",B[i]);
    }
    printf("%d\n",B[n]);
}
int main(){
  int A[MAX],n;  
  int i, j;

  scanf("%d", &n);
 
  for(i=1; i<=n; i++){
    scanf("%d",&A[i]);
  }
  CountingSort(A, n);
  
  return 0;
}



Measured memory_bytes: 17372
#include <bits/stdc++.h>
#include <math.h>
#include <stdlib.h>
using namespace std;
int main(){

int N;
cin >> N;
vector<unsigned long long> L(N);
for (int i = 0; i < N; i++){
    cin >> L.at(i);
}

sort(L.begin(), L.end());
long long a = 0;
long long b = 0;
long long c = 0;
int ans = 0;

for (int i = 0; i < N; i++){
    a = L.at(i);
    for (int j = 0; j < N; j++){
        if(L.at(j) > a){
            b = L.at(j);
            for (int k = 0; k < N; k++){
                if(L.at(k) > b){
                    c = L.at(k);
                    if(a + b > c){
                        ans ++;
                    }
                }
            }
        }
    }
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 3628
#ifdef _DEBUG
#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 LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int A, B, C; cin >> A >> B >> C;
    int D; cin >> D;

    string ans = "No";
    if (abs(C - A) <= D ||
        abs(B - A) <= D && abs(B - C) <= D) ans = "Yes";

    cout << ans << endl;

    return 0;
}

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

ll dp[4002][2002][2];
ll fact[2002];

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

    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    int line_num = min(N, 2 * K);
    int prev;
    for(int i=0;i<line_num;i++){
        prev = i / 2 + i%2 * N;
        for(int j=1;i/2+j*K<N;j++){
            int npos = i/2 + j * K + N * ((j+i) % 2);
            dp[npos][0][0] = 1;
            for(int n=1;n<=N;n++){
                dp[npos][n][1] += dp[prev][n-1][0];
                dp[npos][n][1] %= MOD;
                dp[npos][n][0] += dp[prev][n][0] + dp[prev][n][1];
                dp[npos][n][0] %= MOD;
            }
            prev = npos;
        }
        if(i != line_num - 1){
            int pos_ni = (i+1)/2 + (i+1)%2 * N;
            dp[pos_ni][0][0] = 1;
            for(int n=1;n<=N;n++){
                dp[pos_ni][n][0] = dp[prev][n][0] + dp[prev][n][1];
                dp[pos_ni][n][0] %= MOD;
            }
        }
    }

    fact[0] = 1;
    for(int i=1;i<=N;i++){
        fact[i] = (i * fact[i-1]) % MOD;
    }

    ll ans = fact[N];
    for(int i=1;i<=N;i++){
        ll s = ((dp[prev][i][0] + dp[prev][i][1]) * fact[N-i]) % MOD;
        if(i % 2 == 0) ans = (ans + s) % MOD;
        else ans = (ans - s + MOD) % MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 125568
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			
			int[] dig = new int[N];
			for(int i = 0; i < M; i++){
				dig[sc.nextInt() - 1]++;
				dig[sc.nextInt() - 1]++;
			}
			
			for(int i = 0; i < N; i++){
				System.out.println(dig[i]);
			}
		}
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
		
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
auto find_pair(Int a){
    for(Int i = 1; i < 32; ++i){
        Int bit = (1LL << i);
        if( bit > a) return bit - a;
    }
    return 0LL;
}
signed main(){
    Int N; cin >> N;
    vector<Int>A(N);
    for(auto& e : A) cin >> e;
    map<Int,Int,greater<>>cnt;
    for(auto e : A) cnt[e]++;
    Int ans = 0;
    for(auto itr : cnt){
        Int key = itr.first;
        Int value = itr.second;
        if(value == 0) continue;
        Int pir = find_pair(key);
        if(pir == key){
            ans  += value /2;
        } else {
            if(cnt.find(pir) == cnt.end()) continue;
            ans += min(value, cnt[pir]);
            cnt[pir] -= min(value, cnt[pir]);
            
        }
        cnt[key] = 0;
    }
    cout << ans << endl;
}





Measured memory_bytes: 14336
s=gets.chomp
range=(1..12)
first=range.include?(s[0..1].to_i)
second=range.include?(s[2..3].to_i)
if first && second
  puts "AMBIGUOUS"
elsif first && !second
  puts "MMYY"
elsif !first && second
  puts "YYMM"
else
  puts "NA"
end


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

using namespace std;

#define int long long 
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, x, a[2001];
int tmp[2001];

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

    cin >> N >> x;
    for(int i = 0; i < N; ++i) {
        cin >> a[i];
        tmp[i] = a[i];
    }
    int res = LINF;
    for(int i = 0; i < N; ++i) {
        int ret = i * x;
        for(int j = 0; j < N; ++j) {
            chmin(tmp[j], a[(j - i + N) % N]);
            ret += tmp[j];
        }
        chmin(res, ret);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

inline int calcDiff(int limit, int n, int a, int b){
	int result = a - b;
	if(result < 0){ result += n; }
	if(result > limit){ result = n - result; }
	return result;
}

int main(){
	while(true){
		int n;
		scanf("%d", &n);
		if(n == 0){ break; }
		vector<int> numbers;
		for(int i = n - 1; i > 0; --i){ numbers.push_back(i * i % n); }
		sort(numbers.begin(), numbers.end());
		numbers.erase(unique(numbers.begin(), numbers.end()), numbers.end());
		int limit = (n - 1) / 2;
		vector<int> answers(limit + 1, 0);
		for(int i = numbers.size() - 1; i >= 0; --i){
			for(int j = i - 1; j >= 0; --j){
				answers[calcDiff(limit, n, numbers[i], numbers[j])] += 2;
			}
		}
		for(int i = 1; i <= limit; ++i){
			printf("%d\n", answers[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  cin >> n;
  int mx = -1;
  int64 ans = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ans += max(0, mx - x);
    mx = max(mx, x);
  }
  cout << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



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

const int INF = 1e7;
typedef long long ll;

int main(){
    int n, K;
    cin >> n >> K;
    vector<int> ax(n), ay(n), az(n), bx(n), by(n), bz(n), x, y, z;
    for(int i = 0; i < n; i++){
        cin >> ax[i] >> ay[i] >> az[i] >> bx[i] >> by[i] >> bz[i];
        x.push_back(ax[i]), x.push_back(bx[i]);
        y.push_back(ay[i]), y.push_back(by[i]);
        z.push_back(az[i]), z.push_back(bz[i]);
    }
    x.push_back(-INF), x.push_back(INF);
    y.push_back(-INF), y.push_back(INF);
    z.push_back(-INF), z.push_back(INF);
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    sort(z.begin(), z.end());
    x.erase(unique(x.begin(),x.end()),x.end());
    y.erase(unique(y.begin(),y.end()),y.end());
    z.erase(unique(z.begin(),z.end()),z.end());
    int xn = x.size(), yn = y.size(), zn = z.size();
    int imos[xn][yn][zn];
    memset(imos, 0, sizeof(imos));
    for(int i = 0; i < n; i++){
        int ix = lower_bound(x.begin(),x.end(),ax[i])-x.begin();
        int iy = lower_bound(y.begin(),y.end(),ay[i])-y.begin();
        int iz = lower_bound(z.begin(),z.end(),az[i])-z.begin();
        int jx = lower_bound(x.begin(),x.end(),bx[i])-x.begin();
        int jy = lower_bound(y.begin(),y.end(),by[i])-y.begin();
        int jz = lower_bound(z.begin(),z.end(),bz[i])-z.begin();
        imos[ix][iy][iz]++;
        imos[ix][jy][iz]--;
        imos[jx][iy][iz]--;
        imos[jx][jy][iz]++;
        imos[ix][iy][jz]--;
        imos[ix][jy][jz]++;
        imos[jx][iy][jz]++;
        imos[jx][jy][jz]--;
    }

    for(int k = 0; k < zn; k++){
        for(int j = 0; j < yn; j++){
            for(int i = 1; i < xn; i++){
                imos[i][j][k] += imos[i-1][j][k];
            }
        }
    }
    for(int k = 0; k < zn; k++){
        for(int i = 0; i < xn; i++){
            for(int j = 1; j < yn; j++){
                imos[i][j][k] += imos[i][j-1][k];
            }
        }
    }
    for(int i = 0; i < xn; i++){
        for(int j = 0; j < yn; j++){
            for(int k = 1; k < zn; k++){
                imos[i][j][k] += imos[i][j][k-1];
            }
        }
    }

    ll ans = 0;
    for(int i = 0; i < xn; i++){
        for(int j = 0; j < yn; j++){
            for(int k = 0; k < zn; k++){
                if(imos[i][j][k] < K)   continue;
                ans += (ll)(x[i+1]-x[i])*(y[j+1]-y[j])*(z[k+1]-z[k]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7296
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int i,j,a,b;
	string s;
	cin>>a>>b;
	cin>>s;
	j=0;
	for(i=0;i<s.size();i++)	
	{
		if(i==a)
		{
			if(s[i]!='-')
			{
				j=1;
				break;
			}
		}
		else
		{
			if(s[i]-'0'<0||s[i]-'9'>9)
			{
				j=1;
				break;
			}
		}
	}
	if(j==0)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
} 

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

void fnInput(vector<int>& rvnNum)
{
  int nSize;
  cin >> nSize;
  rvnNum.resize(nSize);

  for (int& rnElm : rvnNum)
    cin >> rnElm;
}

long long fnSignChgTimes(const vector<int>& cnrvnNum)
{ 
  vector<long long> vnTimes(2);

  for (int nParity = 0; nParity < vnTimes.size(); nParity++)
  {
    long long nTimes = 0;
    long long nSum   = 0;
    for (int n = 0; n < cnrvnNum.size(); n++)
    {
      nSum += cnrvnNum[n];
      if (n % 2 == nParity)
        if (nSum > 0);
        else
        {
          nTimes += 1 - nSum;
          nSum = 1;
        }
      else
        if (nSum >= 0)
        {
          nTimes += 1 + nSum;
          nSum = -1;
        }
        else;
    }
    vnTimes[nParity] = nTimes;
  }
  auto itElm = min_element(begin(vnTimes), end(vnTimes));
  return *itElm;
}

int main()
{
  vector<int> vnNum;

  fnInput(vnNum);
  cout << fnSignChgTimes(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ba = sorted((y, x) for x, y in zip(a, b))
a = [x for y, x in ba]
b = [y for y, x in ba]

ap = sorted((x, i) for i, x in enumerate(a))
if any(ap[i][0] > b[i] for i in range(n)):
    print('No')
    exit()
if any(ap[i + 1][0] <= b[i] for i in range(n - 1)):
    print('Yes')
    exit()

rep = [ap[i][1] for i in range(n)]
p = 0
c = 0
while True:
    c += 1
    p = rep[p]
    if p == 0:
        break
print(['No', 'Yes'][c != n])


Measured memory_bytes: 29672
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define repp(i,n) for((i)=1;(i)<=(n);(i)++)
int main(){
  ll i,n,k,c[100010]={0},a,b,cnt=0;
  cin >> n >> k;
  rep(i,n){
    cin >> a >> b;
    c[a] += b;
    cnt += b;
  }
  repp(i,100000){
    k -= c[i];
    if(k<=0){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 4328
#include <iostream>
#include<math.h>
#include<string>
#include<iomanip>
#include <numeric>
#include <limits>
using namespace std;
 
int main()
{
int h,w; string s[1000]; cin>>h>>w;
for(int i=0; i<h;i++) cin>>s[i];
for(int i=0;i<w+2;i++) cout<<"#"; cout<<"\n";
for(int i=0;i<h;i++)
{
    cout<<"#"<<s[i]<<"#"<<"\n";
}
for(int i=0;i<w+2;i++) cout<<"#";
return 0;
}

Measured memory_bytes: 3656
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(S: str):
    idx = [i for i in range(len(S)) if S[i] == 'W']
    print(sum([v-i for i,v in enumerate(idx)]))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12980
#include<stdio.h>
int main(){
  char s[2][2];
  s[0][0] = '+';
  s[1][0] = '-';
  int n;
  scanf("%d",&n);
  int a[4],b,c,d;
  for(int i = 3;i > -1;i--){
    a[i] = n % 10;
    n /= 10;
  }
  for(int i = 0;i < 2;i++){
    if(i < 1){
      b = a[0] + a[1];
    }else{
      b = a[0] - a[1];
    }
    for(int j = 0;j < 2;j++){
      if(j < 1){
        c = b + a[2];
      }else{
        c = b - a[2];
      }
      for(int k = 0;k < 2;k++){
        if(k < 1){
          d = c + a[3];
        }else{
          d = c - a[3];
        }
        if(d == 7){
          printf("%d%c%d%c%d%c%d=7\n",a[0],s[i][0],a[1],s[j][0],a[2],s[k][0],a[3]);
          return 0;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef pair<int,int> ii;
const ll mod = 1000000007;
const int maxn = (int) 1e5 + 5;

int n, res, a[maxn];
ll s[maxn];

int main() {
    //freopen("test.txt", "r", stdin);
    cin >> n;
    rep(i, 1, n + 1) cin >> a[i];
    sort(a + 1, a + 1 + n);
    rep(i, 1, n + 1) s[i] = s[i - 1] + a[i];
    res = 0;
    //rep(i, 1, n + 1) cout << s[i] << endl;
    per(i, 1, n + 1) {
        if(3 * s[i] < s[i + 1]) break;
        res ++;
    }
    cout << res << endl;
}




Measured memory_bytes: 1408
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    C = Counter(A)

    total = 0
    for n in C.values():
        total += n * (n - 1) // 2

    ans = [0] * N
    for i, a in enumerate(A):
        ans[i] = total - C[a] + 1

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 45632
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<bitset>
using namespace std;

int main(){
	int H, W, K,n,ans=0;
	cin >> H >> W >> K;
	char s[10][10];
	for (int i = 0; i < H; i++){
		for (int k = 0; k < W; k++){
			cin >> s[i][k];
		}
	}
	for (int i = 0; i < (1<<H); i++){
		bitset<6> hh(i);
		for (int k = 0; k < (1<<W); k++){
			bitset<6> ww(k);
			n = 0;
			for (int a = 0; a < H; a++){
				for (int b = 0; b < W; b++){
					if (hh.test(a) && ww.test(b) && s[a][b] == '#'){
						n++;
					}
				}
			}
			if (n == K){
				ans++;
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

struct Point {
  int i;
  int j;

  bool operator==(const Point &other) const {
    return (i == other.i && j == other.j);
  }
  bool operator<(const Point &other) const {
    return (i < other.i || (i==other.i && j < other.j));
  }
};

int main() {
  map<Point, int> passed;
  set<Point> whites;
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '#') {
        continue;
      }
      whites.insert(Point{i, j});
    }
  }
  queue<Point> nexts;
  Point p = Point{0, 0};
  nexts.push(p);
  passed[p] = 0;
  while (!nexts.empty()) {
    Point n = nexts.front();
    int dis = passed.at(n);
    nexts.pop();
    Point p;
    p = Point{n.i - 1, n.j};
    if (whites.find(p) != whites.end() && passed.find(p) == passed.end()) {
      passed[p] = dis + 1;
      nexts.push(p);
    }
    p = Point{n.i, n.j - 1};
    if (whites.find(p) != whites.end() && passed.find(p) == passed.end()) {
      passed[p] = dis + 1;
      nexts.push(p);
    }
    p = Point{n.i + 1, n.j};
    if (whites.find(p) != whites.end() && passed.find(p) == passed.end()) {
      passed[p] = dis + 1;
      nexts.push(p);
    }
    p = Point{n.i, n.j + 1};
    if (whites.find(p) != whites.end() && passed.find(p) == passed.end()) {
      passed[p] = dis + 1;
      nexts.push(p);
    }
  }
  Point goal = Point{h-1, w-1};
  if (passed.find(goal)!=passed.end()) {
    cout << whites.size() - passed[goal] -1 << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}

Measured memory_bytes: 512
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
q = int(input())
query = [list(map(int, input().split())) for _ in range(q)]

s = 0
d = defaultdict(int)
for i in range(n):
    s += a[i]
    d[a[i]] += 1

for b, c in query:
    nb = d[b]
    d[b] = 0
    d[c] += nb
    s += (c-b)*nb
    print(s)

Measured memory_bytes: 107852
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
 
using namespace std;
typedef long long int ll;
 
int n;
ll a[200010],r=0;
vector<ll> z={0},q;
 
vector<ll> krk(vector<ll> target){
    vector<ll> result;
    ll repeats=1,number=target[0];
    for(ll i=1;i<target.size();i++){
        if(number==target[i])repeats++;
        else{
            number=target[i];
            result.push_back(repeats);
            repeats=1;
        }
    }
    result.push_back(repeats);
    return result;
}
 
ll nCr(ll maxnum,ll target){
    if(maxnum==target or target==0)return 1;
    else{
        maxnum++;
        ll numerator=1,denominator=1;
        for(ll i=1;i<=target;i++){
            denominator*=i;
            numerator*=(maxnum-i);
        }
        return numerator/denominator;
    }
}
 
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        z.push_back(z[i]+a[i]);
    }
    sort(z.begin(),z.end());
    q=krk(z);
    for(auto itr:q){
        r+=nCr(itr,2);
    }
    printf("%lld\n",r);
    
}

Measured memory_bytes: 8048
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long sum_b=0,ans=0;
	char tmp;
	while(scanf("%c",&tmp)!=EOF)
	{
		if(tmp=='B')
		{
			sum_b++;
		}
		else if(tmp=='W')
		{
			ans+=sum_b;
		}
	}
	printf("%lld",ans);
	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    bool prime[300005];
    
    fill_n(prime, 300005, true);
    
    prime[0] = prime[1] = false;
    for (int i = 2; i * i <= 300004; i++) {
        if (!prime[i]) continue;
        for (int j = i * i; j <= 300004; j += i) {
            prime[j] = false;
        }
    }
    int X;
    cin >> X;
    for (int i = X; i <= 300004; i++) {
        if (prime[i]) {
            cout << i << endl;
            return (0);
        }
    }
    return (0);
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int n, m;
    cin>>n>>m;
    int a[n][m];
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    int c=0;
    for (int k=0;k<n-1;k++)
    {
        for (int i=k+1;i<n;i++)
        {
            int x=0;
            for (int j=0;j<m;j++)
            {
                x+=pow(a[i][j]-a[k][j], 2);
            }
            if (sqrt(x)==floor(sqrt(x)))
            {
                c++;
            }
        }
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 3672
import java.io.*;

public class Main {

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] in;
    in = br.readLine().split(" ");
    long k = Long.parseLong(in[0]);
    long a = Long.parseLong(in[1]);
    long b = Long.parseLong(in[2]);

    br.close();

    long ans = k + 1;

    if(b > a + 2 && k > a){
      ans = a + (k - a + 1) / 2 * (b - a);
      ans += (k - a - 1) % 2;
    }

    System.out.println(ans);
    
  }
}

Measured memory_bytes: 23252
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (4e18) + 9;
const int MOD = (1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { r, d, l, u };
int dx[] = { 0, 1, 0,-1 };
int dy[] = { 1, 0,-1, 0 };

//enum diR { d, r, u, l , dr, ur, dl, ul };
int dX[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dY[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiou"; //and sometimes "aeiouy"

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
//convert index from 2D matrix to 1D array. (Zero-indexed)
int ord(int r, int c, int nCol) { return (nCol*r) + c + 1; }
//convert index from 1D array to 2D matrix . (One-indexed)
ii rord(int n, int nCol) {
	int r = n%nCol, c = n / nCol;
	if (n%nCol == 0) c--, r = nCol;
	return ii(r, c);
}

ll poww(ll num, ll p, ll md = MOD) {
	num %= md;
	ll ret = 1;
	while (p > 0) {
		if (p & 1) ret = (ret * num) % md;
		num = (num * num) % md;
		p >>= 1;
	}
	return ret;
}

ll nCr(ll n, ll r) {
	if (n < r)
		return 0;
	if (r == 0)
		return 1;
	return n * nCr(n - 1, r - 1) / r;
}

const int N = 1e5 + 10;
ll dp[N], h[N];
int n;
ll solve(int idx) {
	if (idx == n-1) return 0;
	if (idx == n - 2) return abs(h[idx] - h[idx + 1]);
	if (dp[idx] != -1) return dp[idx];
	return dp[idx] = min(abs(h[idx] - h[idx + 1]) + solve(idx + 1), abs(h[idx] - h[idx + 2]) + solve(idx + 2));
}


int main()
{
#ifndef ONLINE_JUDGE

#else
	//freopen("pyramid.in", "r", stdin);
#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	lop(i, n) cin >> h[i];
	mem(dp, -1);
	cout << solve(0) << endl;



	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 262144;
int N;
int p[MAXN];
int ivp[MAXN];
int idx1[MAXN*2], idx2[MAXN*2];
void init(int *idx){ memset(idx, 0x3f, sizeof(int)*MAXN*2);}
int getv(int a, int b, int *idx)
{
    
    int minv = 0x3f3f3f3f;
    a += MAXN; b += MAXN;
    while(a<=b)
    {
        if(a%2==1) minv = min(minv, idx[a++]);
        if(b%2==0) minv = min(minv, idx[b--]);
        a/=2; b/=2;
    }
    return minv;
}
void setv(int a, int v, int *idx)
{
    a += MAXN; idx[a] = v;
    while(a = a/2)
    {
        idx[a] = min(idx[2*a], idx[2*a+1]);
    }
    
}

int geta1(int l, int r)
{
    int *i1;
    if(l&1) i1 = idx1;
    else i1 = idx2;
    return getv(l, r, i1);
}
set<pair<int, pair<int, int> > >S;
void solve(int l, int r)
{
    //printf("%d %d\n", l, r);
    int *i1, *i2;
    if(l&1)
    {
        i1 = idx1; i2 = idx2;
    }
    else
    {
        i2 = idx1; i1 = idx2;
    }
    int a1 = getv(l, r, i1);
    int pa1 = ivp[a1];
    int a2 = getv(pa1, r, i2);
    int pa2 = ivp[a2];
    
    printf("%d %d ", a1, a2);
   
    vector<pair<int, int> > V;
    V.emplace_back((int)l, pa1-1);
    V.emplace_back(pa1+1, pa2-1);
    V.emplace_back(pa2+1, (int)r);
    for(auto x: V)
    {
        if(x.first<=x.second)
        S.insert(make_pair(geta1(x.first, x.second), make_pair(x.first, x.second)));
    }
    
}
int main()
{
    scanf("%d", &N);
    init(idx1); init(idx2);
    for(int i=1; i<=N; ++i)
    {
        scanf("%d", p+i);
        ivp[p[i]] = i;
        if(i%2==1) setv(i, p[i], idx1);
        else setv(i, p[i], idx2);
    }
    S.insert(make_pair(-1, make_pair(1, N)));
    while(!S.empty())
    {
        auto v = S.begin();
        //printf("%d %d %d\n", v->first, v->second.first, v->second.second);
        solve(v->second.first, v->second.second);
        S.erase(v);
    }
}

Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   int a;
   int b;

   int r;

   cin >> a >> b;
   
   for (int i = a; i <= b; i++) {
      int s=i%10;
      int t=i/10%10;
      int u=i/1000%10;
      int v=i/10000%10;
      
      if (s==v&&t==u)
         r++;
}
   cout << r;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <numeric>
#include <iomanip>
#define ll long long
#define pi 3.14159265358979323846
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};
/*　BFS
 vector<vector<ll>> g(n+1);
    for(ll i = 0; i < m; i++){
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<ll> dist(n+1, -1);
    queue<ll> que;
    que.push(1);
    dist[1] = 0;
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(ll nv : g[v]){
            if(dist[nv]!=-1) continue;
            dist[nv] = dist[v]+1;
            que.push(nv);
        }
    }
*/

int main(){
    ll n, u, v;
    cin >> n >> u >> v;
     vector<vector<ll>> g(n+1);
    for(ll i = 0; i < n-1; i++){
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<ll> dist(n+1, -1);
    queue<ll> que;
    que.push(v);
    dist[v] = 0;
    ll MAX = 0;
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(ll nv : g[v]){
            if(dist[nv]!=-1) continue;
            dist[nv] = dist[v]+1;
            que.push(nv);
        }
    }
    vector<ll> du(n+1, -1);
    que.push(u);
    du[u] = 0;
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(ll nv : g[v]){
            if(du[nv]!=-1) continue;
            du[nv] = du[v]+1;
            que.push(nv);
        }
    }
    for(ll i = 1; i <= n; i++){
        if(dist[i]>du[i]) MAX = max(dist[i]-1, MAX);
    }
    cout << MAX << endl;
    return 0;
}


Measured memory_bytes: 8064