akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

using namespace std;

int a[200000];
int b[400001];
int c[400001];

int main() {
    int n, m, ans = 0, p = 200000, i, j;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        a[i] += p;
    }
    
    for (i = 0; i < n; i++) b[a[i]]++;
    
    for (i = p + 1; i <= p + n; i++) {
        for (j = 0; j < b[i]; j++) c[i - j]++;
    }
    
    for (i = p + 1; i <= p + n; i++) {
        if (c[i] == 0) ans++;
    }
    
    for (i = 0; i < m; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        y += p;
        
        if (a[x] != y) {
            b[a[x]]--;
            c[a[x] - b[a[x]]]--;
            if (a[x] - b[a[x]] > p && c[a[x] - b[a[x]]] == 0) ans++;
            
            c[y - b[y]]++;
            if (y - b[y] > p && c[y - b[y]] == 1) ans--;
            b[y]++;
            
            a[x] = y;
        }
        
        printf("%d\n", ans);
    }
    
    return 0;
}


Measured memory_bytes: 3840
from math import sqrt
from itertools import accumulate


def common_divisors(x):
    ret = []
    for i in range(1, int(sqrt(x)) + 1):
        if x % i == 0:
            ret.append(i)
            ret.append(x // i)

    return ret


n, k = map(int, input().split())
a = list(map(int, input().split()))

sm = sum(a)
cd = common_divisors(sm)

ans = 0
for ecd in cd:
    r = [e % ecd for e in a]
    r.sort()
    sub = [0] + list(accumulate(r))
    add = [0] + list(accumulate(ecd - e for e in r[::-1]))
    add = add[::-1]
    for sb, ad in zip(sub, add):
        if sb == ad and sb <= k:
            ans = max(ans, ecd)

print(ans)


Measured memory_bytes: 3192
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//227
	ll x,y;
	cin>>x>>y;
	ll cnt=0;
	while(x<=y){
		x*=2;
		cnt++;
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3540
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
x = A.index(1)
y = len(A[:x]) // (K - 1)
z = len(A[x+1:]) // (K - 1)
ans += y + z
if y > 0:
    A = A[y*(K-1):]
if z > 0:
    A = A[:-1*z*(K-1)]
if len(A) == 1:
    ans += 0
elif len(A) <= K:
    ans += 1
else:
    ans += 2
#print(y,z,A)
print(ans)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
#define r(i,n) for(long long i = 0; i<n; i++)
typedef long long ll;
using namespace std;

int main() {
  bool flag=true;
  int n;
  cin >> n;
  map<int,int> mp;
  r(i,n){
    int a;
    cin >> a;
    mp[a]++;
  }
  for(auto it=mp.begin(); it!=mp.end();++it){
    if((*it).second!=1)flag=false;
  }
  if(flag)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    int a, b;
    cin >> a >> b;
    if (a == b)
    {
        cout << a + b;
    }
    else
    {
        cout << max(a, b) * 2 - 1;
    }
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let a:i32 = read();
    let b:i32 = read();

    println!("{}", if a-2*b <= 0 {0} else {a-2*b});

}


Measured memory_bytes: 4352
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");
    const N = parseInt(input[0].split(" ")[0]);
    const S = "" + input[1].split(" ")[0];
    let ans = 0;
    for (let num = 0; num < 1000; num++) {
        // 整数にする
        const i1 = parseInt(num / 100) % 10;
        const i2 = parseInt(num / 10) % 10;
        const i3 = num % 10;
        const idx1 = S.indexOf("" + i1);
        if (idx1 >= 0) {
            const idx2 = S.indexOf("" + i2, idx1 + 1);
            if (idx2 >= 0) {
                const idx3 = S.indexOf("" + i3, idx2 + 1);
                if (idx3 >= 0) {
                    ans++;
                }
            }
        }
    }
    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29708
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

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

    int n = s.size();
    int zero = 0;
    int one = 0;
    rep(i, n){
        if (s[i] == '0') {
            zero++;
        } else {
            one++;
        }
    }
    cout << min(zero, one) * 2 << endl;

}


Measured memory_bytes: 1144
# post-placed for
# counter for counter in iterator
#  

#Shiti Go San
def sgs(s:str)->bool:
    return True if all( s.count(c)>0 for c in "753") else False





n = int( input() )


def recursive(s:str)->int:
    if n < int(s):
        return 0

    ret = 1 if sgs(s) else 0

    for x in "753":
       ret += recursive( s + x )
    
    return ret

print( recursive('0') )

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>
#include <set>
#include <cassert>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <cstring>

using namespace std;

template<typename T1, typename T2> inline void chkmin(T1 & a, const T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chkmax(T1 & a, const T2 b) { if (a < b) a = b; }

const int MAXN = 1 << 18;
const int INF = 1e3;

int a[MAXN];
vector<int> g[MAXN];
int ans[MAXN];

struct SegTree {
	vector<int> tr;

	SegTree() {
		tr.resize(MAXN * 2);
	}
	int get(int v, int vl, int vr, int l, int r) {
		if (vl > r || vr < l) return 0;
		if (l <= vl && vr <= r) return tr[v];
		int vm = (vl + vr) / 2;
		return max(get(v * 2, vl, vm, l, r), get(v * 2 + 1, vm + 1, vr, l, r));
	}
	int get(int l, int r) {
		return get(1, 0, MAXN - 1, l, r);
	}
	void set(int pos, int val) {
		pos += MAXN; // TODO
		tr[pos] = val;
		while (pos > 1) {
			pos /= 2;
			tr[pos] = max(tr[pos * 2], tr[pos * 2 + 1]);
		}
	}
};

void dfs(int v, int pr, SegTree& tr) {
	int old_val = tr.get(a[v], a[v]);
	int new_val = 1;
	if (a[v] > 0) {
		new_val = max(new_val, tr.get(0, a[v] - 1) + 1);
	}
	if (old_val < new_val)
		tr.set(a[v], new_val);
	ans[v] = tr.get(0, MAXN - 1);
	for (int u : g[v]) {
		if (u != pr)
			dfs(u, v, tr);
	}
	tr.set(a[v], old_val);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    // freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    vector<int> as;
    for (int i = 1; i <= n; ++i) {
    	cin >> a[i];
    	as.push_back(a[i]);
    }
    sort(as.begin(), as.end());
    as.resize(unique(as.begin(), as.end()) - as.begin());
    for (int i = 1; i <= n; ++i)
    	a[i] = lower_bound(as.begin(), as.end(), a[i]) - as.begin();

    for (int i = 1; i < n; ++i) {
    	int u, v;
    	cin >> u >> v;
    	g[u].push_back(v);
    	g[v].push_back(u);
    }
    SegTree tr;
    dfs(1, -1, tr);
    for (int i = 1; i <= n; ++i)
    	cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 31024
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] data = Console.ReadLine().Split(' ');
        int N = int.Parse(data[0]);
        int M = int.Parse(data[1]);
        int C = int.Parse(data[2]);
        string[] B_data = Console.ReadLine().Split(' ');
        int[] B = new int[M];
        for (int i = 0; i < M; i++)
        {
            B[i] = int.Parse(B_data[i]);
        }
        int[,] A = new int[N,M];
        int count = 0;
        for (int j = 0; j < N; j++)
        {
            string[] A_data = Console.ReadLine().Split(' ');
            for (int i = 0; i < M; i++)
            {
                A[j,i] = int.Parse(A_data[i]);
                if (i == M - 1)
                {
                    int sum = 0;
                    for(int k = 0; k < M; k++)
                    {
                        sum += A[j, k] * B[k];
                    }
                    sum += C;
                    if (sum > 0) { count++; }
                }
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13140
import java.io.PrintWriter
import java.util.*

const val LAST_S = "zyxwvutsrqponmlkjihgfedcba"

fun main(args: Array<String>) = IO().exec {
    val s = string()
    val kind = s.toSet()
    if (s == LAST_S) println(-1)
    else if (kind.size < 26) {
        var d = 'z'
        for (c in 'a'..'z') if(!kind.contains(c)) {
            d = c
            break
        }
        println(s + d)
    } else {
        var d = 0
        for (i in s.length-1 downTo 1) if (s[i-1] < s[i]) {
            d = i-1
            break
        }
        var e = 'z'
        for (c in s[d].inc()..'z') if (!s.substring(0 until d).contains(c)) {
            e = c
            break
        }
        println(s.substring(0 until d) + e)
    }
}


class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = System.`in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double {
        return string().toDouble()
    }
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}

Measured memory_bytes: 31392
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] c = new int[10][10];
		for(int i = 0; i < 10; i++){
		    for(int j = 0; j < 10; j++){
		        c[i][j] = sc.nextInt();
		    }
		}
		wf(c);
		int sum = 0;
		for(int i = 0; i < h; i++){
		    for(int j = 0; j < w; j++){
		        int a = sc.nextInt();
		        if(a > -1) sum += c[a][1];
		    }
		}
		
		// 計算
		int result = sum;
		
		// 出力
		System.out.println(result);
	}
	
	static void wf(int[][] dist) {
		int n = dist[0].length;
		int INF = 1001001001;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(dist[i][j] == 0) dist[i][j] = INF;
				if(i == j) dist[i][j] = 0;
			}
		}

		for(int k = 0; k < n; k++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
	}
	
}



Measured memory_bytes: 44832
n, k = map(int, input().split())
l = [0 for _ in range(n)]
for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in a:
        l[j - 1] += 1
ans = 0
for i in l:
    if i == 0:
        ans += 1
        
print(ans)

Measured memory_bytes: 67880
N,M,Q=map(int,input().split())
A=[[0 for y in range(N+2)] for x in range(N+2)]
for i in range(M):
    L,R=map(int,input().split())
    A[L][R]+=1
B=[[0 for y in range(N+2)] for x in range(N+2)]
for x in range(N+2):
    for y in range(N+1):
        B[x][y+1]=B[x][y]+A[x][y]
C=[[0 for y in range(N+2)] for x in range(N+2)]
for y in range(N+2):
    for x in range(N+1):
        C[x+1][y]=C[x][y]+B[x][y]
for i in range(Q):
    p,q=map(int,input().split())
    print(C[q+1][q+1]-C[p][q+1]-C[q+1][p]+C[p][p])

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

typedef long long ll;

#define v(T) vector<T>
#define ttt(T) tuple<T, T, T>
#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define poiu(n) for(int i=0; i < n; i++)
#define MOD (int)10e9+7
#define endl '\n'

template<typename T>
void max_self(T& a, T b) { a=a>b?a:b; }
template<typename T>
void min_self(T& a, T b) { a=a<b?a:b; }

using namespace std;

double n;


int main() {
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    
    n /= 3;
    double temp;
    temp = n*n*n;

    printf("%.12lf\n", temp);
    return 0;

}



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

// 同じ文字を圧縮する
// O(N)
vector<int> run_length(const string &s) {
    vector<int> ans(1, 1);
    for (int i = 1; i < s.size(); i++) {
        if (s[i - 1] == s[i])
            ans[ans.size() - 1]++;
        else
            ans.emplace_back(1);
    }
    return ans;
}

int main() {
    string S;
    ll K;
    cin >> S >> K;

    auto run = run_length(S);
    ll ans   = 0;
    // 全部同じ文字のとき
    if (run.size() == 1) {
        ans = ((ll)run[0]) * K / 2;
        cout << ans << endl;
        exit(0);
    }

    for (auto &&i : run) {
        ans += i / 2;
    }
    ans *= K;
    // 両端が同じ文字のとき
    if (S[0] == S[S.size() - 1]) {
        ll a = run[0];
        ll b = run[run.size() - 1];
        ans += (a % 2 == 1 && b % 2 == 1) ? K - 1 : 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
c=0
for i in range(n):
    if a[i]<0:
        c+=1
a=list(map(abs,a))
#print(c)
if c%2==0:
    print(sum(a))
else:
    print(sum(a)-2*min(a))


Measured memory_bytes: 14252
from fractions import gcd
from functools import reduce

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
diff = []
for i in range(N):
    diff.append(abs(x[i] - X))

while len(diff) > 1:
    a, b = diff.pop(), diff.pop()
    diff.append(gcd(a, b))

print(diff[0])


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<int,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

const int  INF=1<<28;

VI bfs(int s, vector<VI>& r, VI& pth){
	int n=sz(r);
	VI ds(n, INF), pre(n, -1);
	ds[s]=0;
	queue<int> q;
	for( q.push(s) ;!q.empty();){
		int v = q.front(); q.pop();
		for(auto x: r[v]){
			if(ds[x]==INF){
				ds[x] = ds[v] +1;
				pre[x] = v;
				q.push(x);
			}
		}
	}
	pth = {n-1};
	int cr=n-1;
	while(pre[cr] !=-1){
		pth.push_back(pre[cr]);
		cr = pre[cr];
	}
	reverse(all(pth));
	return ds;
}

void dfs(int s, int c, vector<VI>& r, VI& res){
	
	for(auto x: r[s]){
		if(res[x] ==-1){
			res[x] = c;
			dfs(x, c, r, res);
		}
	}
}


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	
	vector<VI> r(n);
	rep(i, n-1){
		int a,b;
		cin >>a >>b;
		r[a-1].push_back(b-1);
		r[b-1].push_back(a-1);
	}
	VI pth, res(n, -1);
	auto rv = bfs(0, r, pth);
	int pz=sz(pth);
	rep(i, pz) res[pth[i]] = (i < (pz+1)/2)? 1:2;
	rep(i, n) if(res[i] !=-1){
		dfs(i, res[i], r, res);
	}
	//for(auto x :res) printf("%d, ",x); puts("");
	int sma = count(all(res), 1);
	//dbg(sma, n-sma);
	cout <<((sma <= n-sma)? "Snuke\n": "Fennec\n");
	return 0;
}

Measured memory_bytes: 7932
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    ll x, y;
    cin >> x >> y;
    int cnt = 1;
    while(1) {
        x *= 2;
        if(x > y) {
            cout << cnt << endl;
            return 0;
        }
        cnt++;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
 
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){
  	int n;
  	string s;
  	cin>>n>>s;
  	char left='(',right=')';
  	int now=0,Lmax=0,Rmax=0;
  	REP(i,0,n){
    	if(s[i]==left) now--;
      	if(s[i]==right) now++;
      	chmax(Lmax,now);
    }
  	now=0;
  	REPR(i,n-1,-1){
    	if(s[i]==left) now++;
      	if(s[i]==right) now--;
      	chmax(Rmax,now);
    }
	REP(i,0,Lmax) cout<<left;
  	cout<<s;
  	REP(i,0,Rmax) cout<<right;
  	cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    print(len([i for i in h if i >= K]))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12520
#include <bits/stdc++.h>
#define rep(i,  x,  y) for(int i = x; i <= y; i ++)
#define ll unsigned long long
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define ls rt << 1
#define rs rt << 1 | 1
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;
inline ll read()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
char ch[200010];
int main()
{
	scanf("%s", ch + 1);
	int n = strlen(ch + 1);
	rep(i, 1, n) ch[i] -= '0';
	for(int i = n + 1; i >= 1; i --) ch[i] ^= ch[i - 1];
	int ans = n;
	rep(i, 0, n + 1)
		if(ch[i]) ans = min(ans, max(i - 1, n + 1 - i));
    cout << ans;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
#define INF 1234567812345678;

/*
    Ears (600)
*/

int main() {
    int n;
    cin >> n;
    ll a[n];
    ll sum[n+1] = {};
    rep(i,n){
        cin >> a[i];
        sum[i+1] = sum[i] + a[i];
    }
    ll dp[4][n+1];
    
    rep(i,4){
        rep(j,n+1){
            dp[i][j] = INF;
        }
    }

    // 右方向、帰ってくる
    dp[0][n] = 0;
    drep(i,n){
        ll x = 0;
        if(a[i]==0){
            x = 2;
        }else if(a[i]%2==1){
            x = 1;
        }
        dp[0][i] = min(sum[n]-sum[i], x + dp[0][i+1]);
    }

    // 右方向、帰ってこない
    dp[1][n] = 0;
    drep(i,n){
        ll x = 0;
        if(a[i]%2==0)x = 1;
        dp[1][i] = min(dp[0][i], x + dp[1][i+1]);
    }

    // 左方向、帰ってくる
    dp[2][0] = 0;
    srep(i,1,n+1){
        ll x = 0;
        if(a[i-1]==0){
            x = 2;
        }else if(a[i-1]%2==1){
            x = 1;
        }
        dp[2][i] = min(sum[i], x + dp[2][i-1]);
    }

    // 左方向、帰ってこない
    dp[3][0] = 0;
    srep(i,1,n+1){
        ll x = 0;
        if(a[i-1]%2==0)x = 1;
        dp[3][i] = min(dp[2][i], x + dp[3][i-1]);
    }

    ll ans = INF;

    rep(i,n+1){
        ans = min(ans,dp[2][i]+dp[1][i]);
        ans = min(ans,dp[0][i]+dp[3][i]);
    }

    /*
    rep(i,4){
        rep(j,n+1){
            cout << dp[i][j] << ' ';
        }
        cout << endl;
    }
    */

    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;

	//  正方形の中心点を (xc,yc) とおくと、
	// (x1,y1) から中心点(xc,yc) に対して90度回転した点が(x2,y2) なので
	//  複素数の回転の公式より
	// (x2 - xc) + (y2 - yc)i = ((x1 - xc) + (y1 - yc)i)(cos(90)+i*sin(90))
	// (x2 - xc) + (y2 - yc)i = ((x1 - xc) + (y1 - yc)i)*i
	// (x2 - xc) + (y2 - yc)i = -(y1 - yc) + (x1 - xc)i
	// x2 - xc = -y1 + yc...(1)
	// y2 - yc =  x1 - xc...(2)
	// (1) - (2) より
	// x2 - y2 - xc + yc = -x1 -y1 + yc + xc
	// x1 + y1 + x2 - y2 = 2xc
	// xc = (x1 + y1 + x2 - y2) / 2...(3) 
	// (1) + (2) より
	// x2 + y2 - xc -yc = -y1 + x1 -xc + yc
	// -x1 + y1 + x2 + y2 = 2yc
 	// yc = (-x1 + y1 + x2 + y2) / 2...(4)
	// 同様にして、(x2,y2) から 中心点(xc,yc) に対して90度回転した点を(x3,y3) とすると
	// (x3 - xc) + (y3 - yc)i = ((x2 - xc) + (y2 - yc)i)(cos(90)+i*sin(90))
	// (x3 - xc) + (y3 - yc)i = ((x2 - xc) + (y2 - yc)i)*i
	// (x3 - xc) + (y3 - yc)i = -(y2 - yc) + (x2 - xc)i
	// x3 - xc = -y2 + yc
	// y3 - yc =  x2 - xc
	// x3 =  xc + yc - y2...(5)	
	// y3 = -xc + yc + x2...(6)
	// (3),(4) を(5)に代入すると
	// x3 = (x1 + y1 + x2 - y2) / 2 + (-x1 + y1 + x2 + y2) / 2 - y2
	// x3 = y1 + x2 - y2
	// (3),(4) を(6)に代入すると
	// y3 = -(x1 + y1 + x2 - y2) / 2 + (-x1 + y1 + x2 + y2) / 2 + x2
	// y3 = (-x1 -y1 -x2 + y2) / 2 + (-x1 + y1 + x2 + y2) / 2 + x2
	// y3 = -x1 + x2 + y2
  	// また、(x1,y1) から 中心点(xc,yc) に対して-90度回転した点を(x4,y4)とすると
	// (x4 - xc) + (y4 - yc)i = ((x1 - xc) + (y1 - yc)i)(cos(-90)*i*sin(-90))
	// (x4 - xc) + (y4 - yc)i = ((x1 - xc) + (y1 - yc)i)*(-i)
	// (x4 - xc) + (y4 - yc)i = (y1 - yc) -(x1 -xc)i
	// x4 - xc =  y1 - yc
	// y4 - yc = -x1 + xc
	// x4 = xc - yc + y1...(7)
	// y4 = xc + yc - x1...(8)
	// (3),(4)を(7)に代入すると
	// x4 = (x1 + y1 + x2 - y2) / 2 - (-x1 + y1 + x2 + y2) / 2 + y1
	// x4 = (x1 + y1 + x2 - y2) / 2 + (x1 - y1 - x2 - y2) / 2 + y1
	// x4 = x1 + y1 - y2
	// (3),(4)を(8)に代入すると
	// y4 = (x1 + y1 + x2 - y2) / 2 + (-x1 + y1 + x2 + y2) / 2 - x1
	// y4 = -x1 + y1 + x2

	int x3 = y1 + x2 - y2;
	int y3 =-x1 + x2 + y2;
	int x4 = x1 + y1 - y2;
	int y4 =-x1 + y1 + x2;  
	cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;

	return 0;
}

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

int main(){
  int N,D;
  cin >> N >> D;
  int counter = 0;
  for(int i=0; i<N; i=i+2*D+1){
    counter++;
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 5e5 + 10;
const int K = 1e3 + 10;
vector<int> a[N];
int deg[N];
int id[K][K];

int main() {
  int n;
  scanf("%d", &n);
  int k = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      id[j][i] = id[i][j] = k++;
    }
  }
  for (int i = 0; i < n; ++i) {
    int pre = -1, cur;
    for (int j = 1; j < n; ++j) {
      int k;
      scanf("%d", &k);
      --k;
      cur = id[i][k];
      if (pre >= 0) {
        // trace(pre, cur);
        a[pre].push_back(cur);
        deg[cur]++;
      }
      pre = cur;
    }
  }
  vector<int> Q;
  for (int i = 0; i < n * (n - 1) / 2; ++i) {
    if (deg[i] == 0) Q.push_back(i);
  }
  // trace(Q.size());
  int ret = 0;
  for (int k = 0; k < Q.size(); ) {
    int len = Q.size();
    for (; k < len; ++k) {
      int x = Q[k];
      for (auto& y : a[x]) {
        if (--deg[y] == 0) {
          Q.push_back(y);
        }
      }
    }
    ++ret;
  }
  if (Q.size() == n * (n - 1) / 2) {
    printf("%d\n", ret);
  } else {
    puts("-1");
  }
  return 0;
}


Measured memory_bytes: 35704
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	char[] S = sc.next().toCharArray();
      	char[] T = sc.next().toCharArray();
      	boolean isTrue = true;
      	for(int i = 0; i < T.length-1; i++){
        	if(S[i] != T[i]){
              isTrue = false;
              break;
            }
        }
      	if(isTrue) System.out.println("Yes");
      	else System.out.println("No");
    }
}

Measured memory_bytes: 35352
def main():
    N,M = map(int,input().split())
    a = list(map(int,input().split()))
    sum = 0
    for i in range(M):
        sum += a[i]
    
    if N - sum >= 0:
        print(N-sum)
    else:
        print('-1')

if __name__ == "__main__":
    main()


Measured memory_bytes: 10048
import java.util.HashMap;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String str= sc.nextLine();
		for (int i=0; i<n; i++) {
			map.put(sc.nextLine(),"");
		}
		sc.close();

		System.out.println(map.size());
	}
}


Measured memory_bytes: 72140
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()

	cnt := 0
	prev := -1
	ans := 0
	for i := 0; i < n; i++ {
		tmp := sc.NextInt()
		if tmp != prev {
			ans += cnt / 2
			cnt = 1
			prev = tmp
		} else {
			cnt++
		}
	}
	if cnt != 0 {
		ans += cnt / 2
	}
	fmt.Printf("%+v\n", ans) // output for debug

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{  int n,m,i;
char a[4];
	while(~scanf("%s",&a))
	{  
	m=0;
	for(i=0;i<4;i++)
	if(a[i]==a[i+1])
    m=1;
	if(m==1)
	printf("Bad\n");
	else
	printf("Good\n");	
	
	}
	
}


Measured memory_bytes: 256
n = int(input())
v = list(map(int,input().split()))

import numpy as np
odd  =np.array(v)[1::2]
even =np.array(v)[0::2]
odd_count = np.bincount(odd)
odd_mode = np.argmax(odd_count)
even_count = np.bincount(even)
even_mode = np.argmax(even_count)

ans = 0
if odd_mode!=even_mode:
    ans += len(odd) - odd_count.max()
    ans += len(even) - even_count.max()
    print(ans)
else:
    odd_max = odd_count.max()
    odd_result=list(odd_count)
    odd_result.remove(odd_max)
    
    even_max = even_count.max()
    even_result=list(even_count)
    even_result.remove(even_max)
    
    ans1 = len(odd) - odd_count.max()
    ans1 += len(even) - np.array(even_result).max()
    
    ans2 = len(even) - even_count.max()
    ans2 += len(odd) - np.array(odd_result).max()
    print(min(ans1,ans2))

Measured memory_bytes: 28272
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repr(i,a,b) for (int i = a; i > b; --i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)
 
#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
#define _ <<" "<<
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 	
 //
	//freopen ("test.txt","r",stdin);
	ll n;cin>>n;
	string arr[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
		sort(arr[i].begin() , arr[i].end());
	}


	sort(arr,arr+n);

	/*for (int i = 0; i < n; ++i)
	{
		cout<<arr[i]<<" ";
	}
	cout<<endl;*/
	
	ll ans = 0;
	ll c =1 ;
	for (int i = 0; i < n-1; ++i)
	{
		if(arr[i] != arr[i+1]){
			if(c>=2)
			{
				ans += (c*(c-1))/2;
				c= 1 ;
				
			}
			continue;
		}

		c++;
		
	}
	//cout<<c<<endl;
	if(c>=2){
		ans += (c*(c-1))/2; 
	}

	cout<<ans;

} 

Measured memory_bytes: 5760
#!/usr/bin/env python3

MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

S = input()
if S[2]==S[3] and S[4]==S[5]: print('Yes')
else: print('No')


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n;
	cin>>n;
	vector<int>a(n+1);
	int ans=0;
 	rep(i,n){
		 cin>>a[i];
	}
	rep(i,n){
		if(a[i]>=a[i+1])++ans;
	}
	cout<<ans<<endl;
	cout<<n<<endl;
	return 0;
}


Measured memory_bytes: 3128
check=200000

import sys

input=sys.stdin.readline

N=int(input())
U=[]
R=[]
D=[]
L=[]
for i in range(N):
    x,y,u=input().split()
    x,y=int(x),int(y)
    if u=="U":
        U.append((x,y,u))
    elif u=="R":
        R.append((x,y,u))
    elif u=="D":
        D.append((x,y,u))
    else:
        L.append((x,y,u))

ans=10**18

#DR
DR=D+R
DR.sort()
data=[[] for i in range(2*check+1)]
for x,y,u in DR:
    t=y-x+check
    if u=="R":
        data[t].append(x)
    else:
        if data[t]:
            X=data[t][-1]
            ans=min(ans,2*x-2*X)

#DL
DL=D+L
DL.sort(reverse=True)
data=[[] for i in range(2*check+1)]
for x,y,u in DL:
    t=x+y
    if u=="L":
        data[t].append(x)
    else:
        if data[t]:
            X=data[t][-1]
            ans=min(ans,2*X-2*x)

#UR
UR=U+R
UR.sort()
data=[[] for i in range(2*check+1)]
for x,y,u in UR:
    t=x+y
    if u=="R":
        data[t].append(x)
    else:
        if data[t]:
            X=data[t][-1]
            ans=min(ans,2*x-2*X)

#UL
UL=U+L
UL.sort(reverse=True)
data=[[] for i in range(2*check+1)]
for x,y,u in UL:
    t=y-x+check
    if u=="L":
        data[t].append(x)
    else:
        if data[t]:
            X=data[t][-1]
            ans=min(ans,2*X-2*x)

#UD
UD=U+D
UD.sort(key=lambda x:x[1])
data=[[] for i in range(check+1)]
for x,y,u in UD:
    if u=="U":
        data[x].append(y)
    else:
        if data[x]:
            Y=data[x][-1]
            ans=min(ans,(y-Y))

#LR
LR=L+R
LR.sort()
data=[[] for i in range(check+1)]
for x,y,u in LR:
    if u=="R":
        data[y].append(x)
    else:
        if data[y]:
            X=data[y][-1]
            ans=min(ans,(x-X))

if ans==10**18:
    print("SAFE")
    exit()
print(int(ans*5))


Measured memory_bytes: 222924
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
 
int main(void)
{
  int i,j,k,l;
  while(1) {
	int x,y,z;
	int e;
	int tmp_ans,ans;
	scanf("%d",&e);
	if(e == 0) break;
	tmp_ans = e;
	for(z=0;z*z*z <= e;z++) {
	  for(y=0;;y++) {
		x = e - z*z*z - y*y;
		if(0 > x) break;
		if(tmp_ans > x+y+z)
		  tmp_ans = x+y+z;
	  }
	}
	ans = tmp_ans;
	printf("%d\n",ans);
  }
   return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<vector>
#include<cstring>

#define LL      long long
using namespace std;
#define MAXN    60
#define MAXA    60

int N, M, S;

struct edge {
    int v, a, b;
};
vector<edge> G[MAXN];
int C[MAXN], D[MAXN];
LL dp[MAXN][MAXA*MAXN];
LL ans[MAXN];

inline void add(int u, int v, int a, int b) {
    G[u].push_back({v, a, b});
    G[v].push_back({u, a, b});
}
int main() {
    scanf("%d%d%d", &N, &M, &S);
    int u, v, a, b;
    for(int i=1; i<=M; i++) {
        scanf("%d%d%d%d", &u, &v, &a, &b);
        add(u, v, a, b);
    }
    for(int i=1; i<=N; i++) {
        scanf("%d%d", &C[i], &D[i]);
    }

    memset(dp, 0x3f, sizeof(dp));
    memset(ans, 0x3f, sizeof(ans));
  
	if(S>2500) S=2500;
    dp[1][S] = 0;
    for(int t = 0; t<=N; t++) {
	    for(int i=1; i<=N; i++) {
	            for(int k=0; k<G[i].size(); k++) {
	            	for(int j=0; j<=2500; j++) {
	            		if(j+G[i][k].a<=2500)
		            		dp[i][j] = min(dp[i][j], dp[G[i][k].v][j+G[i][k].a]+G[i][k].b);
		                if(ans[i]>dp[i][j]) {
	                		ans[i] = dp[i][j];
	        			}
	            	}
	            }

	            for(int j=0; j<=2500; j++) {
		            if(j>=C[i]) 
		            	dp[i][j] = min(dp[i][j], dp[i][j-C[i]]+D[i]);
		            if(ans[i]>dp[i][j]) {
	                	ans[i] = dp[i][j];
	        		}
	            }

	    }
    }
    for(int i=2; i<=N; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 5416
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))
    cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#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>;

int main() {
  
  int n;
  cin >> n;
  vector<ll> vec(n);
  vector<ll> mo(n-1);
  
  for (int i =0;i<n;i++) cin >> vec.at(i);
  mo.at(n-2) = vec.at(n-1);
  for (int i=3;i<n+1;i++){
    mo.at(n-i) = (mo.at(n-i+1)+vec.at(n-i+1))%1000000007;
  }
  ll sum=0;
  for (int i=0;i<n-1;i++){
    sum += (vec.at(i)*mo.at(i))%1000000007;
    ;
    sum %= 1000000007;
  }
  cout << sum <<endl;
 
}


Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b;
  c = a * b;
  d = c % 2;
  if(d == 0)
    cout << "Even" << endl;
  else
    cout << "Odd" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#define PI acos(-1)
int main()
{
    char s[4];
    int t=0;
    scanf("%s", s);
    for(int i=0; i<4; i++)
    {
    	if(s[i]== '+') t++;
    	else t--;
    }
    printf("%d\n", t);
    return 0;
}

Measured memory_bytes: 128
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let s = "";
    println!("{}", dfs(n, &s.to_string()));

    use std::collections::HashSet;
    fn dfs(n: usize, s: &String) -> usize {
        if s.is_empty() || s.parse::<usize>().unwrap() <= n {
            let mut ans = if s.chars().collect::<HashSet<_>>().len() == 3 {
                1
            } else {
                0
            };
            for c in "753".chars() {
                ans += dfs(n, &format!("{}{}", s, c))
            }
            ans
        } else {
            0
        }
    }
}


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

long half(long long L,long long count,long long total)
{
    if(L == 1) return total;
    return half(L/2,count+1,total+pow(2,count));
}

int main()
{
    long long H;
    cin >> H;
    long long count = half(H,1,0);
    cout << count+1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
int lis(int n,vector<int>& A){
  vector<int> L(A.size()+1,0);
  L[0]=A[0];
  int length=1;
  for(int i=1;i<n;i++){
    if(L[length-1]<A[i]){
      L[length++]=A[i];
    }else{
      *lower_bound(L.begin(),L.begin()+length,A[i])=A[i];
    }
  }
  return length;
}
//END CUT HERE
signed main(){
  int n;
  cin>>n;
  vector<int> A(n);
  for(int i=0;i<n;i++) cin>>A[i];
  cout<<lis(n,A)<<endl;
  return 0;
}
/*
verified on 2017/06/29
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D&lang=jp
*/

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL dp[105][100005];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N, W;
  cin >> N >> W;
  int w[105], v[105];
  memset(dp, 0, sizeof(LL));
  for (int i = 1; i <= N; ++i)
    {
      cin >> w[i] >> v[i];
    }
  //dp[i][j] = max value of items 1 to i with max weight j
  for (int i = 1; i <= N; ++i)
    for (int j = 0; j <= W; ++j)
      {
        if (w[i] > j) dp[i][j] = dp[i - 1][j];
        else dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
      }
  cout << dp[N][W] << endl;
  return 0;
}


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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "YES"
#define NO  "NO"

using namespace std;

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

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int a, b, c, d; cin >> a >> b >> c >> d;
  num = max(a * b, c * d);
  
  cout << num << endl;
  // cout << (flag ? "H" : "D") << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a - b * 2 <= 0) {
			System.out.println(0);
		} else {
			System.out.println(a - b * 2);
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int sum;
  sum=0;
  for(int i=n;i>0;i--){
    int x;
    cin>>x;
    int lk;
    if((x-k)>=0){
      lk=x-k;
      sum=sum+lk;
    }
    else{
      lk=k-x;
      if(lk>x){
        sum=sum+x;
      }
      else{
        sum=sum+lk;
      }
    }
  }
  cout<<sum*2<<endl;
}

Measured memory_bytes: 256
function Main( input ){

	var t = input.split( '\n' ),
			arr = t[ 1 ].split( '' ),
			c = 0;

	var i = 0, l = t[ 0 ];
	for( ; i < l; i = ( i + 1 )|0 ){
		if( arr[ i ] !== arr[ i + 1 ] ) c = ( c + 1 )|0;
	}

	console.log( c );
	
}

Main( require( 'fs' ).readFileSync( '/dev/stdin', 'utf8' ) );

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main(){
    int n; cin >> n;
    vi a(n); rep(i,n) cin >> a[i];
    
    multiset<int> tail;
    for(int i : a){
        auto it = tail.lower_bound(i);
        if(it != tail.begin()){
            it--;
            tail.erase(it);
        }
        tail.insert(i);
    }
    
    cout << tail.size() << endl;
}

Measured memory_bytes: 8588