akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp>   
using namespace std;
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  tree_order_statistics_node_update>  ordered_set; 
//#define num 1000000007
#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.00000000001)
#define side 1e9
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[200005];
void power()
{
    powe[0]=1;
    REP(i,1,200005)
    {
        powe[i]=mymod(2*powe[i-1],num);
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
}
struct node
{
	vll adj;
    ll dist;
   // ll max_depth;
    ll cwgd;
};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll A[n];
    REP(i,0,n)
    {
        cin>>A[i];
    }
    ll pre[n+1];
    pre[0] = 0;
    REP(i,1,n+1)
    {
        pre[i] = pre[i-1] + A[i-1];
    }
    ll dp[n][n];     // dp[i][j] :  answer for the segment from i to j
    for(ll i=n-1;i>=0;i--)
    {
        REP(j,i,n)
        {
            dp[i][j] = 1e18;
            if(i==j)
            {
                dp[i][j] = 0;
                continue;
            }
            else
            {
                REP(k,i,j)
                {
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + pre[j+1] - pre[i]);
                }
            }
        }
    }
    cout<<dp[0][n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 1536
N = int(input())
S = list(input())

ans = S.count('R')*S.count('G')*S.count('B')

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)

Measured memory_bytes: 9144
n = int(input())
total = 0
out = 1
for _ in range(n):
    a, b = map(int, input().split())
    if a == b:
        total += 1
    else:
        if total >= 3:
            out = 0
        else:
            total = 0
if total >= 3:
    out = 0
if out:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 62256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int cnt = 0;
        int n = sc.nextInt();
        int S[] = new int[n];
        for(int i = 0 ; i < n ; i++)
            S[i] = sc.nextInt();
        int q = sc.nextInt();
        int T[] = new int[q];
        for(int i = 0 ; i < q ; i++)
            T[i] = sc.nextInt();
        for(int i = 0 ; i < q ; i++){
            for(int j = 0 ; j < n ; j++){
                if(S[j] == T[i]){
                    cnt++;
                    break;
                }
            }
        }
        System.out.println(cnt);
    }
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

pair<ll,ll> dp[401][401];

int main(){
    int n;
    cin >> n;
    vector<ll> a(n+1);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    a[n] = INF;

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            dp[i][j] = make_pair(0,0);
            if(i +1 == j){
                dp[i][j].second = a[i];
            }
        }
    }

    for(int l = 2; l <= n; l++){
        for(int i = 0; i+l <= n; i++){
            int j = i+l;
            ll v = INF;
            ll s = 0;
            for(int k = 1; k < l; k++){
                if(dp[i+k][j].first+dp[i][i+k].first+dp[i+k][j].second+dp[i][i+k].second < v){
                    v = dp[i+k][j].first+dp[i][i+k].first+dp[i+k][j].second+dp[i][i+k].second;
                    s = dp[i+k][j].second+dp[i][i+k].second;
                }
            }
            dp[i][j].first = v;
            dp[i][j].second = s;
            }
        }
 
    cout << dp[0][n].first << endl;

    return 0;
}

Measured memory_bytes: 2816
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;


int main() {

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

	ll sum = 0, xr=0, ans = 0;
	int right = 0;

	for (int left = 0; left < n; left++) {
		while (right < n&&((sum + a[right]) == (xr^a[right]))) {
			sum += a[right];
			xr ^= a[right];
			right++;
		}

		ans += (right - left);

		if (right == left)right++;
		else {
			sum -= a[left];
			xr ^= a[left];
		}

	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    ll n,m,x;
    cin >> n >> m >> x;
    ll c[n+1];
    ll a[n+1][m+1];
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }

    ll dp[(1<<12)+1];
    ll ans = INF;
    for(ll i = 0; i < (1<<n); i++){
        vector<ll> st(m,0);
        ll amount = 0;
        for(int j = 0; j < n; j++){
            bool buy = ((i>>j) & 1);
            if(buy){
                amount += c[j];
                for(int k = 0; k < m; k++){
                    st[k] += a[j][k]; 
                }
            }
        }
        bool meet = true;
        for(int k = 0; k < m; k++){
            if(st[k] < x){
                meet = false;
                break;
            }
        }
        if(meet){
            ans = min(ans, amount);
        }
    }

    if(ans == INF){
        ans = -1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mp make_pair
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define f first
#define s second
#define inp(a) cin >> a
#define out(a) cout<<a<<endl
#define in_edges(m) repp(i, 1, m){ ll a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define MOD 1000000007
ll power(ll x,ll y); 
int main()
{
	    // freopen("in.txt","r",stdin);
	    // freopen("out","w",stdout);
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	    ll t;t=1;
	    // cin >> t;
	    while(t--)
	    {
	    	ll a,b,c;
	    	cin >> a >> b>>c;
	    	swap(a,b);
	    	swap(a,c);
	    	cout << a <<" "<<b<<" "<<c;
	    	cout <<endl;

	    }

}
ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

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

typedef long long ll;

const int Maxn = 5005;
const ll Inf = 1000000000000000000ll;

int n, k;
int P[Maxn];
int C[Maxn];
bool tk[Maxn];
vector <int> seq;
ll res = -Inf;

int main()
{
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &P[i]);
    for (int i = 1; i <= n; i++)
        scanf("%d", &C[i]);
    for (int i = 1; i <= n; i++) if (!tk[i]) {
        seq.clear();
        int cur = i;
        ll sum = 0;
        while (!tk[cur]) {
            sum += C[cur];
            seq.push_back(C[cur]);
            tk[cur] = true;
            cur = P[cur];
        }
        for (int i = 0; i < seq.size(); i++) {
            ll cand = 0;
            for (int j = 0; j < seq.size() && j + 1 <= k; j++) {
                cand += seq[(i + j) % int(seq.size())];
                if (sum > 0) res = max(res, cand + ll(k - j - 1) / ll(seq.size()) * sum);
                else res = max(res, cand);
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3860
#include <climits>
#include <iostream>
#include <vector>

using namespace std;

double cal_cost(int w, int t) {
  vector<vector<int>> params = {
      {200, 380, 5, 20}, {300, 550, 4, 15}, {500, 850, 3, 12}};
  int cost = INT_MAX;
  int a = params[t][0];
  int b = params[t][1];
  int c = params[t][2];
  int d = params[t][3];
  return (w / a / c) * c * b * (100. - d) / 100. +
         (w - w / a / c * c * a) * double(b) / a;
}

int main() {
  int w;
  while (cin >> w, w) {
    double cost = 1e10;
    for (int a = 0; a <= w; a += 200) {
      for (int b = 0; b <= w; b += 300) {
        for (int c = 0; c <= w; c += 500) {
          if (a + b + c != w)
            continue;
          double tmp = cal_cost(a, 0) + cal_cost(b, 1) + cal_cost(c, 2);
          cost = (tmp < cost) ? tmp : cost;
        }
      }
    }
    cout << cost << endl;
  }
}


Measured memory_bytes: 3200
import bisect

N=int(input())
S=str(input())

L=[[] for index1 in range(10)]
Set=set()
for index in range(N):
    L[int(S[index])].append(index)
    Set.add(int(S[index]))

ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if i in Set and j in Set and k in Set:
                wi=L[i][0]
                wj_index=bisect.bisect(L[j],wi)
                if wj_index==len(L[j]):
                    continue
                else:
                    wj=L[j][wj_index]
                    wk_index=bisect.bisect(L[k],wj)
                    if wk_index==len(L[k]):
                        continue
                    else:
                        ans+=1

print(ans)






Measured memory_bytes: 4444
import scala.io.StdIn._
import scala.collection.mutable

object Main {
  def main(args: Array[String]) {
    val (buildings, floors, rooms) = (4, 3, 10)
    val officailHouseInfo: mutable.ListBuffer[(Int, Int)] =
      mutable.ListBuffer(
        (for(b <- 1 to buildings; f <- 1 to floors; r <- 1 to rooms)
          yield (s"$b$f$r".toInt, 0)): _*)

    def updateOfficialHouseInfo(limit: Int, i:Int = 0): Unit ={
      if(i < limit) {
        val Array(b, f, r, v) = readLine().split(" ")
        val room = (b + f + r).toInt
        val findRoomIndex = officailHouseInfo.indexWhere(_._1 == room)
        officailHouseInfo(findRoomIndex) = (room, officailHouseInfo(findRoomIndex)._2 + v.toInt)

        updateOfficialHouseInfo(limit, i + 1)
      }
    }

    updateOfficialHouseInfo(readInt())
    val officailHouseInfoValue = for((i, j) <- officailHouseInfo) yield j

    var i = 1
    officailHouseInfoValue.foreach { value =>
      if(i % (floors * rooms) == 0 &&
        i < buildings * floors * rooms) print(" " + value + "\n####################\n")
      else if(i % rooms == 0) print(" " + value + "\n")
      else print(" " + value)
      i += 1
    }
  }
}

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

long long n;

int main(){
    scanf("%lld", &n);
    string ans = "";
    while (n > 0){
        ans = (char) ((n-1)%26 + 'a') + ans;
        n = (n-1) / 26;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3692
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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<_>>()
    };

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"20 2 5"# => r#"84"#,

}


fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
        a: usize,
        b: usize,
    }
    let mut ans = 0;

    for i in 1..n + 1 {
        let sum = i.to_string().chars().map(|i| (i as u8 - '0' as u8) as usize).sum::<usize>();

        // print!("i: {}", i);
        if a <= sum && sum <= b {
            ans += i;
            // print!(", ok ({})", ans);
        }
        // print!("\n");
    }

    ans.to_string()
}

Measured memory_bytes: 4352
<?php
$input=trim(fgets(STDIN));
$length=strlen($input);
$output="";
for($i=0;$i<$length;++$i){
    switch ($input{$i}) {
        case '0':
            $output.='0';
            break;
        case '1':
            $output.='1';
            break;
        case 'B':
            $output=substr($output,0,-1);
            break;
        default:
            break;
    }
}
echo $output;
?>

Measured memory_bytes: 3704
package main

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

type direction int

const (
	RISING  direction = 0
	FALLING direction = 0
)

type edge struct {
	d   direction
	idx int
}

type span struct {
	val   byte
	start int
	end   int
}

func (s *span) len() int {
	return s.end - s.start + 1
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')
	s = strings.TrimSuffix(s, "\n")
	//fmt.Println([]byte(s))

	spans := make([]*span, 0)

	spans = append(spans, &span{s[0], 0, 0})

	for i := 0; i < len(s)-1; i++ {
		if s[i] != s[i+1] {
			tmp := spans[len(spans)-1]
			tmp.end = i
			spans = append(spans, &span{s[i+1], i + 1, i + 1})
		}
	}
	spans[len(spans)-1].end = len(s) - 1

	// spans[i].val == '1' とそうでない場合で本当は処理を共通化できそうと直感的に思う
	ans := 0
	flipped := 0
	kk := 0
	if spans[0].val == '1' {
		kk = 2*k
		for i := 0; i < 2*k+1 && i < len(spans); i++ {
			if spans[i].val == '0' {
				flipped++
			}
			ans += spans[i].len()
		}
	} else {
		kk = 2*k - 1
		for i := 0; i < 2*k && i < len(spans); i++ {
			if spans[i].val == '0' {
				flipped++
			}
			ans += spans[i].len()
		}
	}
	//fmt.Println("val", ans)
	prev := ans
	for i := 1; i < len(spans); i++ {
		//fmt.Println("prev", prev)
		//fmt.Println("removing", spans[i-1].len())
		val := prev - spans[i-1].len()
		if spans[i-1].val == '0' {
			flipped--
		}
		for ;; {
			if kk + 1 >= len(spans) {
				break
			}
			if flipped + 1 > k && spans[kk+1].val == '0' {
				break
			}
			kk++ // increment here
			if spans[kk].val == '0' {
				flipped++
			}
			//fmt.Println("adding", spans[kk].len())
			val += spans[kk].len()
		}
		prev = val
		//fmt.Println("val", prev)
		if prev > ans {
			ans = prev
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vvi g(n, vi());
    int a, b;
    REP(i, m) {
        cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    vector<int> visited(n, -1);
    visited[0] = INF;
    deque<int> q;
    q.emplace_back(0);

    while (!q.empty()) {
        auto p = q.front(); q.pop_front();
        // cout << "p?" << p << endl;

        for (auto v : g[p]) {
            // cout << v << " ";
            if (visited[v] >= 0) continue;
            visited[v] = p;
            q.emplace_back(v);
        }
        // cout << endl;
    }
    // printv(visited);
    cout << "Yes" << endl;
    REP1(i, n - 1) cout << visited[i] + 1 << endl;

}


Measured memory_bytes: 10140
dic = {}
n = int(input())
for i in range(1,n+1):
    a = i
    counter = 0
    while a%2==0:
        counter += 1
        a /= 2
    dic[i] = counter

dic = sorted(dic.items(),key=lambda x:x[1],reverse=True)
#print(dic)
print(dic[0][0])

Measured memory_bytes: 38512
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    // 準備
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int k;

    // パクPGは3からなので2が入力パターンのやつをカバー
    if( x == 2) {
      System.out.println(2);
      System.exit(0);
    }

    // 素数を求めるPGをパクってくる
    // グルグルは最大で1,395,441の為十分耐えられる
    for(int i=3;i<=1_000_000;i+=2)
    {
      k=0;
      for(int j=3;j<=Math.sqrt(i);j+=2)
      {
        if(i%j==0)
        {
          k=1; break;
        }
      }

      if( k==0 && i >= x ) {
        System.out.println(i); break;
      }
    }
  }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define mp make_pair
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
    IOS;
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=min(k,a);
    k-=min(k,a);
    k-=min(k,b);
    ans-=min(k,c);
    cout<<ans<<endl;
}


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

int main(){
    int n;
    cin >> n;
    int flag = 0;
    for(int i=0; i < n; i++){
        string s = "a";
        cin >> s;
        if(s == "Y") flag = 1;
    }

    if(flag) cout << "Four" << endl;
    else cout << "Three" << endl;

    return 0;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
ll in(int a, int b, int c, int d, int e, int f) {
	return a*d + b*e + c*f;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	vl x(n), y(n), z(n),r(n),l(n);
	REP(i, n)cin >> x[i] >> y[i] >> z[i] >>r[i] >>l[i];
	int sx, sy, sz, dx, dy, dz;
	REP(i, q) {
		cin >> sx >> sy >> sz >> dx >> dy >> dz;
		int vx = dx - sx, vy = dy - sy, vz = dz - sz;
		ll ans = 0;
		REP(j, n) {
			int a = sx - x[j], b = sy - y[j], c = sz - z[j];
			ll D = in(a, b, c, vx, vy, vz)*in(a, b, c, vx, vy, vz) - in(vx, vy, vz, vx, vy, vz)*(in(a, b, c, a, b, c) - r[j] * r[j]);
			if (D < 0)continue;
			double t1 = (-in(a, b, c, vx, vy, vz) + sqrt(D)) / in(vx, vy, vz, vx, vy, vz), t2 = (-in(a, b, c, vx, vy, vz) - sqrt(D)) / in(vx, vy, vz, vx, vy, vz);
			if ((t1 >= 0 && t1 <= 1) || (t2 >= 0 && t1 <= 1))ans += l[j];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3204
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define uint unsigned int

long long calc_diff(long long a, long long b, long long c, long long d){
    long long _max = max(max(a,b), max(c,d));
    long long _min = min(min(a,b), min(c,d));
    return _max - _min;
}

int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    long long a;

    cin >> a;
    A[0] = a;
    for(long long i=1; i<N; i++){
        cin >> a;
        A[i] = a + A[i-1];
    }

    long long min = 10e10;
    long long b,c,d,e;
    long long diff;
    long long left = 0;
    long long right = 2;
    for(long long mid = 1; mid < N-1; mid++){
        //L
        diff = abs(A[mid] - 2*A[left]);
        while(left+1 < mid && abs(A[mid] - 2*A[left+1]) < diff){
           diff = abs(A[mid] - 2*A[left+1]);
           left++; 
        }

        //R
        diff = abs(A[N-1] + A[mid] - 2*A[right]);
        while(right+1 < N-1 && abs(A[N-1] + A[mid] - 2*A[right+1]) < diff){
           diff = abs(A[N-1] + A[mid] - 2*A[right+1]);
           right++; 
        }
        if(mid == right) right++;

        long long m = calc_diff(A[left], A[mid] - A[left], A[right] - A[mid], A[N-1] - A[right]);
        //printf("left:%d, mid:%d, right:%d   m = %d\n",left,mid,right,m);
        if(m < min)
            min = m;
        //else
        //    break;
    }
    
    cout << min << endl;
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <string.h>
#include <stdio.h>
using namespace std;

int main()
{
	char  s[100];
	cin >> s;
	int len = strlen(s);

	for (int i=0; i<len; i = i+2)
	{
		if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') continue;
		else {
			cout<<"No"<<endl;
			return 0;
		}

	}

	for (int i = 1; i<len; i = i+ 2)
	{
		if (s[i] == 'L' || s[i]=='U' || s[i]=='D') continue;
		else {
			cout<<"No" <<endl;
			return 0;
		}
	}

	cout<<"Yes" <<endl; return 0;
}



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

using namespace std;

vector<pair<int, int>> solve(int n, int m) {
    vector<pair<int, int>> res;
    if (n % 2 == 1) {
        for (int i = 0; i < m; ++i) {
            res.emplace_back(1 + i, n - i);
        }
    } else {
        for (int i = 0; i < m; ++i) {
            int shift = 0;
            if (i >= n / 4)
                shift = 1;
            res.emplace_back(1 + i, n - i - shift);

        }
    }
    return res;
}
void test(int n, int m) {
    auto r = solve(n, m);
    assert(r.size() == m);
    vector<bool> seen(1 + n);
    vector<bool> deltas(1 + n);
    for (int i = 0; i < m; ++i) {
        int a = r[i].first;
        int b = r[i].second;
        assert(!seen[a]);
        seen[a] = true;
        assert(!seen[b]);
        seen[b] = true;
        int d1 = abs(a - b);
        int d2 = n - d1;
        assert(!deltas[d1]);
        deltas[d1] = true;
        assert(!deltas[d2]);
        deltas[d2] = true;
    }
}
void print(int n, int m) {
    auto res = solve(n, m);
    for (int i = 0; i < m; ++i)
        cout << res[i].first << " " << res[i].second << "\n";
}
int main() {
//    for (int n = 2; n <= 100; ++n) {
//        for (int m = 1; 2 * m + 1 <= n; ++m) {
//            cout << "nm = "  << n << " " << m << "\n";
//            print(n, m);
//            test(n, m);
//        }
//    }
//    return 0;
    int n, m;
    cin >> n >> m;
    print(n, m);
    return 0;
}


Measured memory_bytes: 4212
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
using Graph = vector<VE>;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	COMinit();
	int n, k; cin >> n >> k;
	rep(i, k) {
		cout << COM(n - k + 1, i + 1)*COM(k - 1, i) % MOD << endl;
	}
	return 0;
}

Measured memory_bytes: 12160
def main():
    s = list(input())
    
    odd_s = s[0::2]
    even_s = s[1::2]
    
    if "L" not in odd_s and "R" not in even_s:
        print("Yes")
    else:
        print("No")
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
int n,l,r,ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	    cin>>l>>r,ans+=r-l+1;
	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
coin=[]
ans=0
for i in range(3):
    coin+=map(int,input().split())
X=int(input())
for a in range(coin[0]+1):
    for b in range(coin[1]+1):
        for c in range(coin[2]+1):
            total=a*500+b*100+c*50
            if total==X:
                ans +=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <set>
using namespace std;
 
int main()
{
  string s;
  cin >> s;
  string k = "None";
  set<char> a;
  for (int i = 0; i < s.length(); i++)
  {
    a.insert(s[i]);
  }
  if (a.size() < 26)
  {
    char ca = 'a';
    for (int i = 0; i < 26; i++)
    {
      if (a.find(ca) == a.end())
      {
        k = ca;
        //cout << "tarinai全部じゃなかった" << endl;
        break;
      }
      else
      {
        ca += 1; //ascii?
      }
    }
  }
  cout << k << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main()
{
	int n,m;
	int a,b;
	int vis[100];
	scanf("%d %d",&n,&m);
	memset(vis,0,sizeof(vis));
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&a,&b);
		vis[a]++;
		vis[b]++;
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d\n",vis[i]);
	}
	return 0;
 } 

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

ll modpow(ll a, ll p)
{
    if (p == 0)
        return 1;
    if (!(p % 2))
    {
        ll halfP = p / 2;
        ll half = modpow(a, halfP);
        return half * half % mod;
    }
    else
    {
        return a * modpow(a, p - 1) % mod;
    }
}

ll comb(int a, int b)
{
    if (a < b) return 0;
    if (b > a - b)
        return comb(a, a - b);
    ll ansMul = 1;
    ll ansDiv = 1;
    for (int i = 0; i < b; i++)
    {
        ansMul *= a - i;
        ansDiv *= i + 1;
        ansMul %= mod;
        ansDiv %= mod;
    }
    ll ans = ansMul * modpow(ansDiv, mod - 2) % mod;
    return ans;
}

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

    int N, K; cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
    int num = 200010;
    vector<ll> fact(num), ifact(num);
    fact[0] = 1;
    fact[1] = 1;
    for (int i = 2; i < num; i++)
    {
        fact[i] = fact[i - 1] * i;
        fact[i] %= mod;
    }
    for (int i = 0; i < num; i++)
    {
        ifact[i] = modpow(fact[i], mod - 2);
        ifact[i] %= mod;
    }
    ll ans = 0;
    rep(i, N) {
        if (i - (K - 1) < 0) continue;
        ans += fact[i] * ifact[K-1] % mod * ifact[i-(K-1)] % mod * A[i];
        ans %= mod;
    }
    sort(rall(A));
    rep(i, N) {
        if (i - (K - 1) < 0) continue;
        ans -= fact[i] * ifact[K-1] % mod * ifact[i-(K-1)] % mod* A[i];
        ans = (ans + mod) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;


int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
    A.at(i) -= 1;
  }
  ll cnt = 0;
  ll now = 0;
  vector<ll> went(N, -1);
  ll pattern = K;
  went.at(0) = 0;
  ll start = 0;
  while (cnt <= K) {
    now = A.at(now);
    cnt += 1;
    if (went.at(now) != -1) {
      pattern = cnt - went.at(now);
      start = now;
      pattern = ((K - went.at(now)) % pattern);
      break;
    }
    went.at(now) = cnt;
  }
  ll ans = start;
  for (ll i = 0; i < pattern; ++i) {
    ans = A.at(ans);
  }
  cout << ans + 1 << "\n";
}


Measured memory_bytes: 6428
n = int(input())
w = list(map(int, input().split()))
ws = sorted(w)
d = {v:i for i, v in enumerate(ws)}
checked = [False] * n
cost = 0
wmin = min(w)

for i in range(n):
    if checked[i] or d[w[i]] == i:
        continue
    # 循環群をさがす
    gcnt = 0
    gmin = gtot = w[i]
    nexti = d[w[i]]
    while nexti != i:
        checked[nexti] = True
        gcnt += 1
        gmin = min(gmin, w[nexti])
        gtot += w[nexti]
        nexti = d[w[nexti]]
    cost += gtot + min(gmin * (gcnt - 1), wmin * (gcnt + 2) + gmin)
print(cost)



Measured memory_bytes: 5720
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ");
//#define double long double

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int MAX = 200060;
const double pi = acos(-1);
const ll INF = 1e16;


void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N)cin >> A[i];
	sort(all(A));
	ll ans = 0;
	REP(i, N - 2) {
		FOR(j, i + 1, N - 1) {
			FOR(k, j + 1, N) {
				if (A[i] + A[j] <= A[k])break;
				if (A[i] < A[j] + A[k] && A[j] < A[i] + A[k] && A[k] < A[i] + A[j])ans++;
			}
		}
	}
	print(ans);
}


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

	solve();
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();

        if (a >= 13) {
            System.out.println(b);
        } else if(a >= 6) {
            System.out.println(b / 2);
        } else {
            System.out.println(0);
        }
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

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

    rep(i,n) {
        string a,b;
        cin >> a >> b;

        for(int j=a.size()-1;j>=0;j--) {
            if(a[j] == 'J') {
                rotate(b.rbegin(),b.rbegin()+1,b.rend());
            }
            if(a[j] == 'C') {
                rotate(b.begin(),b.begin()+1,b.end());
            }
            if(a[j] == 'E') {
                stringstream ss;

                if(b.size()%2 == 0) {
                    REP(k,b.size()/2,b.size()) {
                        ss << b[k];
                    }
                    rep(k,b.size()/2) {
                        ss << b[k];
                    }
                }
                else {
                    REP(k,b.size()/2+1,b.size()) {
                        ss << b[k];
                    }

                    ss << b[b.size()/2];

                    rep(k,b.size()/2) {
                        ss << b[k];
                    }
                }

                b = ss.str();
            }
            if(a[j] == 'A') {
                reverse(b.begin(),b.end());
            }
            if(a[j] == 'P') {
                rep(k,b.size()) {
                    if(b[k] == '0') b[k] = '9';
                    else if('1' <= b[k] && b[k] <= '9') b[k]--;
                }
            }
            if(a[j] == 'M') {
                rep(k,b.size()) {
                    if(b[k] == '9') b[k] = '0';
                    else if('0' <= b[k] && b[k] <= '8') b[k]++;
                }
            }
        }

        cout << b << endl;

    }

    return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

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

    string s;
    cin >> s;

    int n = s.length();
    int tar[n];
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'L') {
            tar[i] = s[i-1] == 'L' ? tar[i-1] : i - 1;
        }
    }
    for (int i = s.length() - 1; i >= 0; i--) {
        if (s[i] == 'R') {
            tar[i] = s[i+1] == 'R' ? tar[i+1] : i + 1;
        }
    }

    int ans[n];
    memset(ans, 0, sizeof(ans));
    for (int i = 0; i < n; i++) {
        if (s[i] == 'L') {
            ans[(i-tar[i])%2?tar[i]+1:tar[i]]++;
        } else {
            ans[(tar[i]-i)%2?tar[i]-1:tar[i]]++;
        }
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] << (i == n - 1 ? '\n' : ' ');
    }

    return 0;
}


Measured memory_bytes: 1488
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

int main(){
	std::string s;
	std::cin>>s;
	int ans=0;

	for(int i=1; i<s.size(); i++){
		if((s.size()-i) %2 != 0)
			continue;

		int hf= (s.size()-i)/2;
		bool isCorrect=true;

		for(int j=0; j< hf; j++){
			if(s[j]!=s[hf+j])
				isCorrect=false;
		}


		if(isCorrect){
			ans= s.size()-i;
			break;
		}
	}

	std::cout<<ans<<std::endl;

	return 0;
}

Measured memory_bytes: 384
import Data.List
import qualified Data.Set as S

main :: IO ()
main = interact $ unlines . map (show . bfs) . parse . map (map read . words) . lines
 where
  parse [[0,0]] = []
  parse ([t,o]:xs) = (t, map (\[a,b]->(a,b)) os, (x,y)) : parse xs'
   where (os,([x,y]:xs')) = splitAt o xs

bfs :: (Int, [(Int,Int)], (Int,Int)) -> Int
bfs (t,os,i) = S.size $ advance 0 (S.singleton i) (S.singleton i)
 where
  os' = S.fromList os
  advance t' b r
   | t' == t = r
   | S.null b' = r
   | otherwise = advance (t'+1) (S.difference b' r) (S.union r b')
   where
    b' = S.difference (S.foldl' (\acc x -> S.union acc (S.fromList (neighbors x))) b b) os'
    neighbors (x,y) = [(x+1,y),(x-1,y),(x,y+1),(x,y-1),(x+1,y+1),(x-1,y-1)]

Measured memory_bytes: 5536
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end(), greater<int>());
  int alice = 0;
  int bob = 0;
  rep(i, N) {
    if (i % 2 == 0)
      alice += A[i];
    else
      bob += A[i];
  }
  cout << alice - bob << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}




int main() {

	int N, K;
	cin >> N >> K;

	vector<bool> okashi(N, false);

	for (int i = 0; i < K; i++) {
		int d;
		cin >> d;
		for (int j = 0; j < d; j++) {
			int sunuke;
			cin >> sunuke;
			okashi[sunuke - 1] = true;
		}
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (!okashi[i]) ans++;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

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


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

k, a, b = [int(item) for item in input().split()]
if a >= k:
    print(1)
    exit()
if abs(a) - abs(b) <= 0:
    print(-1)
    exit()
diff = abs(a) - abs(b)
print(1 + (k - a + diff - 1) // diff * 2)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define LL long long
using namespace std;
int X,Y,Z;
LL A[505050],B[505050];
struct Node{
	LL a,b,c;
	Node(LL a=0,LL b=0,LL c=0):
	a(a),b(b),c(c){}
	void InIt(){
		scanf("%lld %lld %lld",&a,&b,&c);
		a-=c; b-=c;
	}
	bool operator < (const Node &A)const{
		return a-b>A.a-A.b;
	}
}q[500100];
priority_queue <LL,vector<LL>, greater<LL> > Q;
int main(){
	scanf("%d %d %d",&X,&Y,&Z);
	LL sum=0;
	for (int i=1;i<=X+Y+Z;i++) 
		q[i].InIt(),sum+=q[i].c;
	sort(q+1,q+X+Y+Z+1);
	
	LL Cur=0;
	for (int i=1;i<=X;i++)
		Q.push(q[i].a),Cur+=q[i].a;
	A[X]=Cur;
	for (int i=X+1;i<=X+Z;i++){
		Q.push(q[i].a);
		Cur+=q[i].a;
		Cur-=Q.top();
		Q.pop();
		A[i]=Cur;
	}
	Cur=0;
	
	while (!Q.empty()) Q.pop();
	for (int i=X+Z+1;i<=X+Y+Z;i++) 
		Q.push(q[i].b),Cur+=q[i].b;
	B[X+Z+1]=Cur;
	for (int i=X+Z;i>=X;i--){
		Q.push(q[i].b);
		Cur+=q[i].b;
		Cur-=Q.top();
		Q.pop();
		
		B[i]=Cur;
	}
	LL Max=-2100101010101010ll;
	for (int i=X;i<=X+Z;i++)
		if (A[i]+B[i+1]>Max)
			Max=A[i]+B[i+1];
	Max+=sum;
	cout<<Max;
}

Measured memory_bytes: 19444
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end() 
#define MOD 1000000007
#define N 100005
#define pll pair<ll,ll>
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));


void solve()
{ 
     ll n;
     cin >> n;
     string s;
     cin >> s;
     s = 'a' + s;
     ll pre[n+2][3];
     memset(pre,0,sizeof(pre));
     for(ll i=1;i<=n;i++)
     {
          if(s[i]=='R')     pre[i][0]++;
          if(s[i]=='G')     pre[i][1]++;
          if(s[i]=='B')     pre[i][2]++;
     }
     for(ll i=n-1;i>=0;i--) 
     {
          pre[i][0] += pre[i+1][0];
          pre[i][1] += pre[i+1][1];
          pre[i][2] += pre[i+1][2];
     }
     ll ans = 0;
     for(ll i=1;i<=n;i++)
     {
          for(ll j=i+1;j<=n;j++)
          {
               if(s[i]!=s[j])
               {
                    char c = 'R' + 'G' + 'B' - s[i] - s[j];
                    ll id;
                    if(c=='R')   id = 0;
                    if(c=='G')   id = 1;
                    if(c=='B')   id = 2;
                    ans += pre[j+1][id];
                    ll dif = j - i;
                    ll newi = j + dif;
                    if(newi<=n && s[newi]==c)   ans--;
               }
          }
     }
     cout<<ans;
}

int main()
{
     FAST;
     ll t = 1;
  ///   cin >> t;
     while(t--)
     {     
          solve();
     }
}

Measured memory_bytes: 3724
void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}
  
int Partition(int A[],int p,int r){
  int x = A[r];
  int i=p-1,j;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}
  
int main(){
  int n,i,x;
  int A[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x=Partition(A,0,n-1);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==x)printf("[");
    printf("%d",A[i]);
    if(i==x)printf("]");
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2132
import numpy as np

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
RA = [A[0]]

killed = []
for i in range(N):
    killed.append(min(RA[i], B[i]))
    RB = B[i] - killed[-1]
    killed[-1] += min(A[i+1], RB)
    RA.append(max(0, A[i+1]-RB))

print(sum(killed))

Measured memory_bytes: 28676