akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
 	string vec;
   cin >> vec;
  if (vec.at(0) == vec.at(1) && vec.at(1) == vec.at(2)){
    cout << "Yes" << endl;
  }
    else if (vec.at(1) == vec.at(2) && vec.at(2) == vec.at(3)){
      cout << "Yes" << endl;
    }
  else {
    cout << "No" << endl;
  }
  
     
}

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

string re(string s);

int main() {
	int n, k;
	string s;
	cin >> n >> k >> s;
	int a;
	a = s[k-1];
	a = tolower(a);
	s[k-1] = a;
	cout << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
int main() {
    int n;cin>>n;
    vector<int> a(n+1),b(n);
    rep(i,n+1)cin>>a[i];
    rep(i,n)cin>>b[i];
    ll ans = 0;
    rep(i,n){
        rep(j,2){
            if(b[i] >= a[i+j]){
                ans += a[i+j];
                b[i] -= a[i+j];
                a[i+j]=0;
            }else{
                ans += b[i];
                a[i+j] -= b[i];
                b[i]=0;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int a[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  fill(a, a + n, 0);
  REP(i, n) {
    int b;
    cin >> b;
    a[b]++;
  }

  for(int i = n - 1; i >= 0; i -= 2) {
    if(i == 0) {
      if(a[i] != 1) {
        cout << 0 << endl;
        return 0;
      }
    } else {
      if(a[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
  }

  ll ans = 1;
  REP(i, n / 2) {
    ans *= 2;
    ans %= mod;
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound, __gcd, count, find, next_permutation
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cassert> // assert
#include <cctype>  // isupper, islower, isdigit, toupper, tolower
#include <cmath>   // abs, sin, cos, tan
#include <ctime>   // clock

// __builtin_popcountll

using namespace std;
using Graph = vector<vector<int>>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  str s, t; cin >> s >> t;
  ll ans = 0;
  for(ll i = 0;i < s.size();i++)
  {
    if(s[i] != t[i]) ans ++;
  }
  fin(ans);
  return;
}

//前処理
int main()
{
  int ti = clock();
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  //printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
  return 0;
}

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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;

int main() {
    ll n;
    cin >> n;
    vll nums(n);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
        if (i > 0) nums[i] += nums[i - 1];
    }
    int l = 1;
    int r = 3;
    ll l1, l2, l1t, l2t;
    ll r1, r2, r1t, r2t;
    ll ans = 1e9;
    ll tmin, tmax;
    for (int middle = 2; middle < n - 1; ++middle) {
        while (l < middle - 1) {
            l1 = nums[l - 1];
            l2 = nums[middle - 1] - l1;
            l1t = nums[l];
            l2t = nums[middle - 1] - l1t;
            if (abs(l1 - l2) > abs(l1t - l2t)) ++l;
            else break;
        }
        l1 = nums[l - 1];
        l2 = nums[middle - 1] - l1;

        while (r < n - 1) {
            while (r <= middle) ++r;
            r1 = nums[r - 1] - nums[middle - 1];
            r2 = nums[n - 1] - nums[r - 1];
            r1t = nums[r] - nums[middle - 1];
            r2t = nums[n - 1] - nums[r];
            if (abs(r1 - r2) > abs(r1t - r2t)) ++r;
            else break;
        }
        r1 = nums[r - 1] - nums[middle - 1];
        r2 = nums[n - 1] - nums[r - 1];
        tmin = min({l1, l2, r1, r2});
        tmax = max({l1, l2, r1, r2});
        ans = min(tmax - tmin, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista 

def yen_coins():
    X, K = wczytaj_liste()
    if X * 500 >= K:
        print("Yes")
    else: 
        print("No")
        
yen_coins()

Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main(){

	char ans;
	char a, b;
	int p, q;
	cin >> a >> b;

	p = (a == 'H') ? 1 : -1;
	q = (b == 'H') ? 1 : -1;
	ans = (p*q == 1) ? 'H' : 'D';

	cout << ans << endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int n = cin.nextInt();
		int a = cin.nextInt();
		int b = cin.nextInt();
		long[] hs = new long[n];
		for (int i = 0; i < n; i++)
			hs[i] = cin.nextInt();
		long ans = solve(n, a, b, hs);
		cout.println(ans);
	}

	private static long solve(int n, long a, long b, long[] hs) {
		// 二分法
		long abdif = a - b;
		long l = 0;
		long r = (long) 1e9;
		while (l + 1 != r) {
			long m = (l + r) / 2;
			boolean ok = false;
			long yoha = b * m;
			long tgt = 0;
			for (long h : hs) {
				if (h - yoha <= 0)
					continue;
				tgt += (h - yoha + abdif - 1) / abdif;
			}
			ok = tgt <= m;
			if (ok)
				r = m;
			else
				l = m;
		}
		return r;
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 36476
# 数値の取得
people,hlimit = map(int,input().split())
height = list(map(int,input().split()))

# 条件に適合する人数をチェックし出力
check = []
for i in range(0,people,1):
  if height[i] >= hlimit:
    check.append("OK")
  else:
    check.append("NG")
hcnt = check.count("OK")
print(hcnt)

Measured memory_bytes: 18352
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var a = cin.ArrayLong(n);

            Array.Sort(a);
            Array.Reverse(a);

            var list = new List<long>();
            list.Add(a[0]);
            for (int i = 1; i < a.Length; i++)
            {
                list.Add(a[i]);
                list.Add(a[i]);
            }

            var ans = 0L;
            for (int i = 0; i < n-1; i++)
            {
                ans += list[i];
            }
            
            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


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

long long UA,TA,TP;
long long wyn;

int main(){
	cin>>UA>>TA>>TP;
	int k = min(TA, TP);
	wyn += 2*k;
	TP -= k;
	TA -= k;
	//cout<<wyn<<endl;
	//cout<<UA<<" "<<TA<<" "<<TP<<endl;
	k = min(UA, max(TA,TP));
	wyn += k;
	TA -= k;
	TP -= k;
	UA -= k;
	TA = max(TA , (long long)0);
	TP = max(TP , (long long)0);
	UA = max(UA , (long long)0);	
	if(TP > 0) wyn += 1;
	cout<<wyn<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll,ll,ll>>>;

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


int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),T(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> T[i];
    ll AX = 0,BX = 0,AM = 0,BM = 0;
    rep(i,N){
        if(AM < A[i]){
            AM = A[i];
            AX = i;
        }
    }
    rrep(i,N){
        if(BM < T[i]){
            BM = T[i];
            BX = i;
        }
    }
    if(AM != BM || AX > BX){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    ans *= max(0LL,modpow(AM,(BX-AX-1),MOD));
    ans %= MOD;
    ll memo = 0,cnt = 0;;
    FOR(i,0,AX){
        memo = A[i];
        cnt = 0;
        while(memo >= A[i]){
            cnt++;
            i++;
        }
        i--;
        ans *= modpow(memo,cnt-1,MOD);
        ans %= MOD;
    }
    RFOR(i,BX+1,N){
        memo = T[i];
        cnt = 0;
        while(memo >= T[i]){
            cnt++;
            i--;
        }
        i++;
        ans *= modpow(memo,cnt-1,MOD);
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
N,M=gets.split.map(&:to_i)
price,stock=N.times.map{gets.split.map(&:to_i)}.sort_by{|x| x[0]}.transpose

count=0
total_cost=0

N.times {|a|
    if M-count>stock[a]
        total_cost+=price[a]*stock[a]
        count+=stock[a]
    else
        total_cost+=price[a]*(M-count)
        break
    end
}

puts total_cost

Measured memory_bytes: 13584
#include <iostream>

using namespace std;

int main(){
    int N, L;
    int a[100000];
    int w[100000];
    cin >> N >> L;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    for(int i = 1; i < N; i++){
        if((a[i] + a[i-1]) >= L){
            cout << "Possible" << endl;
            for(int j = 0; j < i-1; j++){
                cout << j+1 << ' ';
            } 
            for(int j = N-1; j > i; j--){
                cout << j << ' ';
            }
            cout << i << endl;
            return 0;
        }
    }
    cout <<  "Impossible" << endl;
}

Measured memory_bytes: 1152
import itertools

n, k = map(int, input().split())
xy = [tuple(map(int, input().split())) for i in range(n)]
ans = float("INF")
for a, b in itertools.combinations(xy, 2):
    for c, d in itertools.combinations(xy, 2):
        x1, x2 = sorted([a[0], b[0]])
        y1, y2 = sorted([c[1], d[1]])
        count = 0
        for x, y in xy:
            if x1 <= x <= x2 and y1 <= y <= y2:
                count += 1
        if count >= k:
            ans = min(ans, (x2 - x1) * (y2 - y1))
print(ans)

Measured memory_bytes: 53340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int n;

char change(char c) {
    int num = c + n;
    if (num > 90) num -= 26;
    return (char)(num);
}

int main() {
    cin >> n;
    string s;
    cin >> s;
    rep(i, 0, s.size()) {
        s[i] = change(s[i]);
    }
    cout << s << endl;
    return 0;
}


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

using namespace std;

int main() {
    int n; cin >> n;
    if (n == 1) {
        cout << 1;
        return 0;
    }
    vector<int> primes;
    int arr[100000];
    for (int i = 2; i < 100000; i++) arr[i] = 0;
    for (int i = 2;i  < 100000; i++) {
        if (arr[i] == 0) {
            primes.push_back(i);
            for (int j = 1; j*i < 100000; j++) arr[i*j] = 1;
        }
    }
    int res = 1;
    for (int i:primes) {
        if (n%i == 0) {
            int p = 1;
            while(n%i == 0) {
                p *= i;
                n /= i;
            }
            res *= (i - 1)*p/i;
        }
    }
    if (n != 1) res *= n - 1;
    cout << res << endl;
}


Measured memory_bytes: 3656
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        k = int(tokens[1])
        q = int(tokens[2])
        for i in range(q):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        k = int(tokens[1])
        q = int(tokens[2])

    a = []
    for i in range(q):
        a.append(int(lines[i+1]))

    return (n, k, q, a)


def solve(n, k, q, a):

    win = []
    for i in range(n):
        win.append(0)

    for i in range(q):
        win[a[i]-1] = win[a[i]-1] + 1

    result = []
    for i in range(n):

        if k - (q - win[i]) > 0:
            result.append("Yes")
        else:
            result.append("No")

    return result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r)
    else:
        print("%s" % result)


if __name__ == '__main__':

    main()
	


Measured memory_bytes: 13372
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define PI            (acos(-1.0))
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)    for(int i=0;i<n;i++)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define w(t)          int t;cin>>t;while(t--)
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    ll x,cnt=0,gu=100,mut=100;
    cin>>x;
    while(gu<x)
    {
        cnt++;
        mut/=100;
        gu+=mut;
        mut=gu;
    }
    cout<<cnt<<nl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue

#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 2005
int n;
int a[MN];

bitset<MN*MN> ree;

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

    cin >> n;
    int sm = 0;
    F0R(i, n){
        cin >> a[i];
        sm += a[i];
    }
    sort(a, a+n);
    ree[0] = 1;
    F0R(i, n){
        ree = ree | (ree << a[i]);
    }

    int mid = (sm+1)/2;
    while(!ree[mid]) mid++;
    cout << mid << "\n";

    return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 924844033;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll a[300000];
ll ma1[100001], ma2[100001];
int main() {
	int n; cin >> n;
	ll sum = 0;
	ll csum1 = 0;
	ll csum2 = 0;
	priority_queue <ll,vector<ll>,greater<ll>> q1,q2;
	ll out = -INF;
	rep(i, 3 * n) {
		cin >> a[i];
		if (i < n) {
			q1.push(a[i]); csum1 += a[i];
		}
		if (i >= 2 * n) {
			q2.push(-a[i]); csum2 -= a[i];
		}
	}
	ma1[0] = csum1;
	rep(i, n) {
		csum1 += a[n + i]; q1.push(a[n + i]);
		ll x = q1.top(); q1.pop(); csum1 -= x;
		ma1[i + 1] = csum1;
	}
	ma2[0] = csum2;
	rep(i, n) {
		csum2 -= a[2 * n - 1 - i]; q2.push(-a[2 * n - 1 - i]);
		ll x = q2.top(); q2.pop(); csum2 -= x;
		ma2[i + 1] = csum2;
	}
	rep(i, n + 1) {
		out = max(out, ma1[i] + ma2[n - i]);
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 5876
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		long sum = 0;
		for (int i = 1; i <= N; i++) {
			if (i % 5 == 0 || i % 3 == 0) continue;
			sum += i;
		}
		System.out.println(sum);
	}
}

class Main {
	public static void main(String... args) {
		var reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<>() {
			private StringTokenizer line;

			public String get() {
				try {
					return (line = line != null && line.hasMoreTokens() ? line : new StringTokenizer(reader.readLine())).nextToken();
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
		});
	}
}

Measured memory_bytes: 32756
#include <bits/stdc++.h>
using namespace std;
int main () {
    string div[4] = {"dream","dreamer","erase","eraser"};
    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    for(int i = 0; i<4; i++) reverse(div[i].begin(), div[i].end());

    string res = "YES";
    for(int i = 0; i < s.size();) {
        bool check = false;
        for(int j = 0; j<4; j++) {
            string tmp = div[j];
            if(s.substr(i, tmp.size()) == tmp) {
                check = true;
                i += tmp.size();
            }
        }
        if(!check) {
            res = "NO";
            break;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
import sys
import heapq

n, q = map(int, input().split())

Q = [[] for _ in range(n)]
ans = []
heapq.heapify(Q)
for query in (line.split() for line in sys.stdin):
    t = int(query[1])
    if query[0] == '0':
        u = int(query[2])
        heapq.heappush(Q[t], -u)
    elif query[0] == '1' and Q[t]:
        ans.append(-Q[t][0])
    elif query[0] == '2' and Q[t]:
        heapq.heappop(Q[t])

for i in ans:
    print(i)


    


Measured memory_bytes: 14196
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>

using namespace std;
const int INF = numeric_limits<int>::max();

int main() {
    int n;
    cin >> n;
    vector<int> open(n, 0);
    vector<vector<int>> p((size_t)n, vector<int>(11, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 10; ++j) {
            int b;
            cin >> b;
            open[i] |= b << j;
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= 10; ++j) {
            cin >> p[i][j];
        }
    }

    int ans = -INF;
    for (int bit = 1; bit < 1 << 10; ++bit) {
        int x = 0;
        for (int i = 0; i < n; ++i) {
            bitset<10> bs = bit & open[i];
            x += p[i][bs.count()];
        }
        ans = max(ans, x);
    }

    cout << ans << endl;

}



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

int main() {
	float a, b, t;
	cin >> a >> b >> t;
	
	float time = a;
	int biscuit = 0;
	while (time <= (t + 0.5)) {
		time += a;
		biscuit += b;
	}

	cout << biscuit << endl;

	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: i32,
        d: i64,
        points: [(i64, i64); n]
    }

    let mut cnt: i32 = 0;
    for point in points.iter() {
        if num::pow(point.0, 2) + num::pow(point.1, 2) <= num::pow(d, 2) {
            cnt += 1;
        }
    }

    println!("{}", cnt);
}

Measured memory_bytes: 7912
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n;
  cin>>n;
  if(n%10==9 || n/10==9)
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl; 
}

Measured memory_bytes: 256
order_num = int(input())
jisho = {}
for _i in range(order_num):
    order, key = input().split()
    if order == 'insert':
        jisho[key] = ''
    elif order == 'find':
        try:
            jisho[key]
            print('yes')
        except KeyError:
            print('no')


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

int N, X;
vector<int> p;

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

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

  int x;                                                //各座標
  for(int i = 0; i < N; i++){
    cin >> x;
    p.push_back(abs(x-X));
  }

  if(N == 1)
    cout << abs(X-x) << endl;
  else{
    int GCD = gcd(p[0], p[1]);
    for(int i = 2; i < N; i++)  GCD = gcd(p[i], GCD);       //O(NlogN)
    cout << GCD;
  }
  return 0;

}

Measured memory_bytes: 892
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class EColorfulHats2 {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll n;
        in >> n;
        vector<ll> a(n);
        ll mo = 1000000007;
        rep(i,n){
            in >> a[i];
        }
        vector<pair<int,int>> cnt(n,{0,3});
        vector<int> bb={-1},cc={-1},dd={-1};
        rep(i,n){
            if(bb.back()==a[i]-1){
                cnt[i].first++;
            }
            if(cc.back()==a[i]-1){
                cnt[i].first++;
            }
            if(dd.back()==a[i]-1){
                cnt[i].first++;
            }
            if(bb.back()>a[i]-1){
                cnt[i].second--;
            }
            if(cc.back()>a[i]-1){
                cnt[i].second--;
            }
            if(dd.back()>a[i]-1){
                cnt[i].second--;
            }
            if(bb.back()==a[i]-1){
                bb.push_back(a[i]);
            }else if(cc.back()==a[i]-1){
                cc.push_back(a[i]);
            }else if(dd.back()==a[i]-1){
                dd.push_back(a[i]);
            }
        }
        ll ans = 1L;
        rep(i,n){
            ans*=min(cnt[i].first,cnt[i].second);
            ans%=mo;
        }
//        if(dd.size()!=1){
//            ans*=6;
//            ans%=mo;
//        }
        out << ans << endl;
	}
};


int main() {
	EColorfulHats2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n; cin >> n;
  vector<int> ans(n,0);
  for(int i=0; i<n-1; i++){
    int a; cin >> a;
    ans.at(a-1)++;
  }
  for(int i=0; i<n; i++)
    cout << ans.at(i) << endl;
}

Measured memory_bytes: 4052
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MOD = 1000000007;
const int MAXN = 2000;

int nr, nb;
int C[MAXN + 1][MAXN + 1];
int Csum[MAXN + 1][MAXN + 1]; // Csum[n][k]=C[n][k]+Csum[n][k-1]

void run() {
	REPE(i, MAXN) { C[i][0] = C[i][i] = 1; FOR(j, 1, i) if ((C[i][j] = C[i - 1][j - 1] + C[i - 1][j]) >= MOD) C[i][j] -= MOD; }
	REPE(i, MAXN) { Csum[i][0] = C[i][0]; FORE(j, 1, i) if ((Csum[i][j] = C[i][j] + Csum[i][j - 1]) >= MOD) Csum[i][j] -= MOD; }

	scanf("%d%d", &nr, &nb);
	int ret = nr + 1;
	FORE(y, 1, nb - 1) REPE(xz, nr - y) {
		int cur = (ll)(xz + 1)*C[nb - 1][y] % MOD*Csum[y - 1][min(y - 1, nr - y - xz)] % MOD;
		//printf("y=%d xz=%d: cur=%d\n", y, xz, cur);
		if ((ret += cur) >= MOD) ret -= MOD;
	}
	printf("%d\n", ret);
}

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


Measured memory_bytes: 30720
#include <stdio.h>
#include <iostream>

using namespace std;

int main () {
	int number1,number2;
	int a[4],b[4];

	while (1) {
		int B = 0;
		int H = 0;
		cin >> number1 >> number2;
		if (number1 == 0 && number2 == 0) {
			break;
		} else {
			for (int i = 0; i < 4; i++) {
				a[i] = number1 % 10;
				b[i] = number2 % 10;
				number1 = number1 / 10;
				number2 = number2 / 10;
			}
			for (int i = 0; i < 4; i++) {
				if (a[0] == b[i] || a[1] == b[i] || a[2] == b[i] || a[3] == b[i]) {
					B++;
				}
				if (a[i] == b[i]) {
					if (B > 0) {
						B--;
					}
					H++;
				}
			}
			cout << H << " " << B << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;



int main(){
    int n, A[10001],q,key,sum=0;
    cin >> n;
    for(int i=0;i<n;i++)cin >> A[i];

    cin >> q;
    for(int i =0;i<q;i++){
        cin >> key;
         int j =0;
    A[n] = key;
    while(A[j] != key) j++;
    int a= j !=n;
        if(a)sum++;
    }
    cout << sum <<endl;
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <numeric>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <tuple>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder{
    void judge_outer(bool judge_exp,string ok = "Yes",string ng = "No"){
        if(judge_exp){
            cout << ok << endl;
        }else{
            cout << ng << endl;
        }
    }
    
    int ncr(int left,int right){
        right = min(left - right,right);
        int ans =1;
        for(int i=1;i<=right;i++){
            ans = ans * (left-right+i)/i;
        }
        return ans;
    }
    
    const int LIMIT = 1000000256;
    const int tenfive = 100000;
    
    
}

using namespace atcoder;

int main(void){
    array<string,60> a;
    a.fill("...........................................................");
    int h,w;
    cin >> h >> w;
    for(int i=1;i<=h;i++){
        cin >> a[i];
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<w;j++){
            if(a[i][j] == '#'){
                if(a[i+1][j] == '#' || a[i][j+1] == '#' || a[i-1][j] == '#' || a[i][j-1] == '#'){}
                else{
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b;
	char ch;
	long long sum=0;
	scanf("%d %c %d",&a,&ch,&b);
	if(ch=='+')
	sum=a+b;
	else 
	sum=a-b;
	printf("%d\n",sum);
	
	return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int ans = 1;
  for(int i = 0; i < s.length(); i++){
    if(s[i] == 'L')
      ans = 0;
    i++;
    if(s[i] == 'R')
      ans = 0;
  }
  if(ans == 1)
    cout << "Yes";
  else
    cout << "No";
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let sum = a
        .into_iter()
        .fold((0, 0), |(height, sum), a_i| {
            if height > a_i {
                (height, sum + height - a_i)
            } else {
                (a_i, sum)
            }
        })
        .1;

    println!("{}", sum);
}


Measured memory_bytes: 5548
a , b , c = gets.split.map(&:to_i)
d = 0
if a == 0 then
  a += 1
  d += 1
end
if a % c != 0 then
  a = a + c - (a % c)
end
a += 1
d = d + (b - a + 1) / c
d += 1
puts d

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin>>n;
  vector<ll> a(n),b(n);
  ll sum1=0,sum2=0;
  rep(i,n){
    cin>>a[i];
    sum1+=a[i];
  }
  rep(i,n){
    cin>>b[i];
    sum2+=b[i];
  }
  //cout<<sum1<<' '<<sum2<<endl;
  if(sum1>sum2){
    cout<<"No"<<endl;
    return 0;
  }
  ll k=sum2-sum1;//操作の回数
  ll cnt1=0,cnt2=0;
  rep(i,n){
    if(a[i]<b[i]) cnt2+=(b[i]-a[i]+2-1)/2;
    if(a[i]>b[i]) cnt1+=a[i]-b[i];
  }
  if(cnt1<=k && cnt2<=k) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
ll N,A,B;
vector<ll> h;

bool enough(ll T){
	ll t=0;
	rep(i,N){
		ll r=h[i]-B*T;
		if(r>0)t+=(r-1)/(A-B)+1;
	}
	return t<=T;
}

int main(void){
	cin>>N>>A>>B;
	h.resize(N);
	rep(i,N)cin>>h[i];

	ll l=0,r=1e9,mid;
	while(l+1<r){
		mid=(l+r)/2;
		if(enough(mid))r=mid;
		else l=mid;
	}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 1024
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    ans = 0
    Ai = [(a, i + 1) for i, a in enumerate(A)]
    Ai.sort(key=lambda x: x[0])
    st = SegmentTree(n=N + 2, f=lambda x, y: x + y)
    st.set_val(0, 1)
    st.set_val(N + 1, 1)
    for a, i in Ai:
        lc = st.query(0, i)
        l = st.bisect_left(lambda x: x < lc)
        r = st.bisect_left(lambda x: x < lc + 1)
        ans += a * (i - l) * (r - i)
        st.set_val(i, 1)
    print(ans)

class SegmentTree:
    def __init__(self, n=None, f=max, identity_factory=int, initial_values=None):
        assert(n or initial_values)
        size = n if n else len(initial_values)
        d = [identity_factory() for _ in range(2 * size + 1)]
        self.__n, self.__d, self.__f, self.__e = size, d, f, identity_factory
        if initial_values:
            for i, v in enumerate(initial_values): d[size + i] = v
            for i in range(size - 1, 0, -1): d[i] = f(d[i << 1], d[i << 1 | 1])

    def get_val(self, index):
        return self.__d[index + self.__n]

    def set_val(self, index, new_value):
        i, d, f = index + self.__n, self.__d, self.__f
        if d[i] == new_value: return
        d[i] = new_value
        i = i >> 1
        while i:
            d[i] = f(d[i << 1], d[i << 1 | 1])
            i = i >> 1

    def modify(self, index, value):
        self.set_val(index, self.__f(self.__d[index + self.__n], value))

    def query(self, from_inclusive, to_exclusive):
        ans = self.__e()
        if to_exclusive <= from_inclusive: return ans
        l, r, d, f = from_inclusive + self.__n, to_exclusive + self.__n, self.__d, self.__f
        while l < r:
            if l & 1: ans, l = f(ans, d[l]), l + 1
            if r & 1: ans, r = f(d[r - 1], ans), r - 1
            l, r = l >> 1, r >> 1
        return ans

    def bisect_left(self, func):
        '''func()がFalseになるもっとも左のindexを探す
        '''
        i, n, f, d, v = 1, self.__n, self.__f, self.__d, self.__e()
        i = n
        j = n + n
        while i < j:
            if i & 1:
                nv = f(v, d[i])
                if not func(nv):
                    break
                v = nv
                i += 1
            i >>= 1
            j >>= 1
        while i < n:
            nv = f(v, d[i << 1])
            if func(nv):
                v, i = nv, i << 1 | 1
            else:
                i = i << 1
        return i - n

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)


Measured memory_bytes: 136508
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int digitSum(int n){
   int res = 0;
   while(n){
       res += n % 10;
       n /= 10;
   }
   return res;
}

int sum[100010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i, 0, n + 1) sum[i] = digitSum(i);
    int ans = INF;
    rep(i, 1, n){
        ans = min(ans, sum[i] + sum[n - i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < S.length(); i++)
  {
    if (S[i] == '+')
      ans++;
    else
      ans--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>
#include <functional>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;

using namespace std;

#ifndef LOCAL
#define cerr _cer
struct _cert
{
    template <typename T> _cert& operator << (T) { return *this; }
};
_cert _cer;
#endif

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}
const int MAXN = 210000;
const ll INF = 1e15;

ll rm1[MAXN * 4];
ll rm2[MAXN * 4];

void upd(int v, int tl, int tr, int x, ll y) {
    if (tl + 1 == tr) {
        rm1[v] = y - tl;
        rm2[v] = y + tl;
        return;
    }
    int m = (tl + tr) >> 1;
    if (x < m)
        upd(v * 2 + 1, tl, m, x, y);
    else
        upd(v * 2 + 2, m, tr, x, y);
    rm1[v] = min(rm1[v * 2 + 1], rm1[v * 2 + 2]);
    rm2[v] = min(rm2[v * 2 + 1], rm2[v * 2 + 2]);
}

ll get(int v, int tl, int tr) {
    if (tl + 1 == tr) {
        return rm1[v] + tl;
    }
    int m = (tl + tr) >> 1;
    return min(get(v * 2 + 1, tl, m), get(v * 2 + 2, m, tr));
}

ll get1(int v, int tl, int tr, int l, int r) {
    if (r <= tl || tr <= l)
        return INF;
    if (l <= tl && tr <= r)
        return rm1[v];
    int m = (tl + tr) >> 1;
    return min(get1(v * 2 + 1, tl, m, l, r), get1(v * 2 + 2, m, tr, l, r));
}

ll get2(int v, int tl, int tr, int l, int r) {
    if (r <= tl || tr <= l)
        return INF;
    if (l <= tl && tr <= r)
        return rm2[v];
    int m = (tl + tr) >> 1;
    return min(get2(v * 2 + 1, tl, m, l, r), get2(v * 2 + 2, m, tr, l, r));
}

ll dd;

int n, q, a, b;
int main() {
    cin >> n >> q >> a >> b;
    --a, --b;
    fill(rm1, rm1 + 4 * n, INF);
    fill(rm2, rm2 + 4 * n, INF);
    upd(0, 0, n, a, 0);
    int lst = b;
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        --x;
        ll bst = min(get1(0, 0, n, 0, x) + dd + x, get2(0, 0, n, x, n) + dd - x);
        dd += abs(lst - x);
        upd(0, 0, n, lst, bst - dd);
        lst = x;
    }
    cout << get(0, 0, n) + dd << "\n";
    return 0;
}




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

M = []
A = []
R = []
C = []
H = []
for _ in range(N):
  s = input()
  if s[0] == 'M':
    M.append(s)
  if s[0] == 'A':
    A.append(s)
  if s[0] == 'R':
    R.append(s)
  if s[0] == 'C':
    C.append(s)
  if s[0] == 'H':
    H.append(s)
m_len = len(M)
a_len = len(A)
r_len = len(R)
c_len = len(C)
h_len = len(H)
ans = 0
ans += m_len * a_len * r_len
ans += m_len * a_len * c_len
ans += m_len * a_len * h_len
ans += m_len * r_len * c_len
ans += m_len * r_len * h_len
ans += m_len * c_len * h_len
ans += a_len * r_len * c_len
ans += a_len * r_len * h_len
ans += a_len * c_len * h_len
ans += r_len * c_len * h_len

print(ans)

Measured memory_bytes: 10228
class Node
  attr_accessor :id, :left, :right, :parent
  def initialize(input)
    @id, @left, @right = input
    @parent = nil
  end
end

class Binary_tree
  def initialize(n, inputs)
    #nodesを生成
    @nodes = inputs.inject({}) do |memo, input|
      memo[input[0]] = Node.new(input)
      memo
    end

    #left, rightにポインタを代入
    @nodes.each do |key, node|
      @nodes[key].left = (@nodes[key].left != -1 ? @nodes[@nodes[key].left] : nil)
      @nodes[key].right = (@nodes[key].left != -1 ? @nodes[@nodes[key].right] : nil)
    end

    @root = get_root()
  end

  def get_root
    @nodes.each do |key, node|
      if @nodes[key].left
        @nodes[key].left.parent = @nodes[key]
      end

      if @nodes[key].right
        @nodes[key].right.parent = @nodes[key]
      end
    end

    @nodes.each do |key, node|
      if !node.parent
        return key
      end
    end
  end


  def preorder(node)
    if !node
      return
    end
    print " %d" % [node.id.to_s]
    preorder(node.left)
    preorder(node.right)
  end

  def inorder(node)
    if !node
      return
    end
    inorder(node.left)
    print " %d" % [node.id.to_s]
    inorder(node.right)
  end

  def postorder(node)
    if !node
      return
    end
    postorder(node.left)
    postorder(node.right)
    print " %d" % [node.id.to_s]
  end

  def run
    #p @nodes
    puts "Preorder"
    preorder(@nodes[@root])
    print "\n"

    puts "Inorder"
    inorder(@nodes[@root])
    print "\n"

    puts "Postorder"
    postorder(@nodes[@root])
    print "\n"
  end
end

n = gets.to_i
inputs = Array.new(n){gets.split.map(&:to_i)}
Binary_tree.new(n, inputs).run


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

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

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, -1, 1, 1, -1};

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    long long a;
    std::cin >> a;
    long long b;
    std::cin >> b;
    long long c;
    std::cin >> c;

    if (c >= a + b && 4 * a * b < (c - a - b) * (c - a - b))
        cout << YES << endl;
    else
        cout << NO << endl;

    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
spots = gets.chomp.split.map(&:to_i)
spots.unshift(0)
spots.push(0)
distances = Array.new(n + 1).map{Array.new(2,0)}
(n + 1).times do |i|
  if (i == 0)
    distances[0][i] = 0
    distances[1][i] = spots[i+1].abs
  else
    distances[0][i] = (spots[i-1] - spots[i+1]).abs
    distances[1][i] = (spots[i] - spots[i+1]).abs
  end
end
sum = distances[1].inject(:+)
n.times do |i|
  puts sum - distances[1][i] - distances[1][i+1] + distances[0][i+1]
end


Measured memory_bytes: 21124
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
         string s = ReadLine();
         string t = ReadLine();
         for(int i = 0; i < s.Count(); i++){
             if(s[i] != t[i]){
                 WriteLine("No");
                 return;
             }
         }
         WriteLine("Yes");
      }
   }
}

Measured memory_bytes: 26152