akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        a: usize,
        b: usize
    }
    if a + b == 0 {
        println!("0");
        return;
    }
    println!("{}", n / (a + b) * a + min(n % (a + b), a));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int p[205];
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> p[i];
    int ans = 0;
    for(int i = 2; i < n; i++) {
        if(max(p[i], max(p[i-1], p[i+1])) == p[i]) continue;
        if(min(p[i], min(p[i-1], p[i+1])) == p[i]) continue;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
const int N = 100010;
const ll mod = 1e9 + 7;

int n, k, a[N];
ll f[101][N], sum[101][N];
/*
 f[i][j]表示前i个人，一共分了j份。
 */
int main() {
	int cur = 1;
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	sum[0][1] = f[0][1] = 1;
	for(int i = 1; i <= k + 1; ++i) sum[0][i] = 1; 
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= k + 1; ++j) {
			(f[i][j] = sum[i - 1][j] - sum[i - 1][max(j - a[i] - 1, 0)]) %= mod;
			sum[i][j] = (f[i][j] + sum[i][j - 1]) % mod;
		}
	}
	printf("%lld\n", (f[n][k + 1] % mod + mod) % mod);
/*	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= k + 1; ++j) printf("%d ", sum[i][j]);
		puts("");
	}*/
}

Measured memory_bytes: 158080
#include <iostream>
 using namespace std;
 
 int main()
 {
     long long nn;
     long long h, n, w;
     long long i, j, k;
     long long x, y;
     //long long h, n, w;
     //long long x1, x2, y, y1, y2;
     cin>>nn;
     if(nn%2 == 0)
     {
         h = nn;
         n = nn;
         w = nn/2;
     }
     else
     {
         for(i = 1; i <= 3500; i++)
         {
             for(j = 1; j <= 3500; j++)
             {
                 k = 4*i*j - nn*i - nn*j;
                 if(k <= 0)
                 {
                     continue;
                 }
                 else
                 {
                     y = i * j * nn;
                     if(y%k == 0)
                     {
                         h = i;
                         n = j;
                         w = y/k;
                     }
                 }
 
 
             }
         }
     }   
     cout<<h<<" "<<n<<" "<<w<<endl;
     return 0;
 }

Measured memory_bytes: 384
function Main(input){
	input=input.split(/\n|\s/);
	input.forEach(function(e,i,a){a[i]=Number(a[i]);});
	for(var i=input[0];i<input[0]+input[2]&&i<=input[1];i=(i+1)|0){
		console.log(i);
	}
	for(var j=(1+input[1]-input[2])<i?i:(1+input[1]-input[2]);j<=input[1];j=(j+1)|0){
		console.log(j);
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
    int a, b;
    cin >> a >> b;
    if(a >= b){
        for(int i = 0; i < a; ++i) cout << b;
    }else {
        for(int i = 0; i < b; ++i) cout << a;
    }
     cout << endl;
}

Measured memory_bytes: 256
n,m,c=list(map(int,input().split(" ")))
b=list(map(int,input().split(" ")))
a=[]
for i in range(n):
    a.append(list(map(int,input().split(" "))))

num=0
for i in range(n):
    suma=c
    for j in range(m):
        suma+=a[i][j]*b[j]
    if suma>0:
        num+=1

print(num)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,c,k; cin >> n >> c >> k;
    vector<int> time(n);
    rep(i,n) cin >> time[i];
    sort(ALL(time));
    int ans = 1;
    int cnt = 1;
    int maxt = time[0]+k;
    REP(i,1,n) {
        if(time[i]<=maxt && cnt < c) {
            cnt++;
        }
        else {
            maxt = time[i]+k;
            cnt = 1;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
input_num = input()
input_num = int(input_num)
for i in range(1,10,1):
  flag = False
  for j in range(1,10,1):
    if input_num == i * j:
      print("Yes")
      flag = True
      break
  if flag:
    break
if not flag:
	print("No")

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

int main(){
  int a, b, c;
  cin>>a>>b>>c;
  
  int cnt = 0;
  for(int x = a; x <= b; x++){
    if(c % x == 0) cnt++;
  }

  cout<<cnt<<endl;

  return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    string s;
    cin >> s;
    cout << (s != string(3, 'A') && s != string(3, 'B') ? "Yes" : "No") << endl;
    return 0;
}


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

bool has3(int x){
	while(x){
		if (x % 10 == 3) return true;
		x /= 10;
	}
		return false;
}

void call(int n){
	for(int x=1; x<=n; x++){
		if(x % 3 == 0 || has3(x)){
			cout << " " << x;
			}
	}
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	call(n);
	
	return 0;

}

Measured memory_bytes: 1160
//Author : Sidiq Tri Pratikto
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
//order_of_key(x) = number of elements stricly smaller than x
//find_by_order(x) = return x-th largest element
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	LL ans = 0;
	int N, K;
	LL l = 0, r = 0;
	scanf("%d%d", &N, &K);
	for (int i = K; i <= N + 1; i++) {
		ans += (((LL)(N + 1 - i) * (LL)i) % MOD + 1) % MOD;
		ans %= MOD;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  string s;
  cin>>s;
  int ans = MOD;
  for(char i = 'a'; i <= 'z'; i++)
  {
    int mx = 0;
    int cnt = 0;
    rep(j, s.size()) {
      if(s[j] == i) {
        mx = max(mx, cnt);
        cnt = 0;
      } else if(j == s.size() - 1){
        cnt++;
        mx = max(mx, cnt);
      } else {
        cnt++;
      }
    }
    ans = min(ans, mx);
  }
  cout << ans << endl;

  return 0;

}


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

int memo[10];
int n;
int keta;
int ans;

int t,f,s;
int tt;

void dfs(int d)
{
	if(d==keta)return;
	
	memo[d]=3;
	t=0;
	f=0;
	s=0;
	tt=0;
	for(int i=d;i>=0;i--)
	{
		tt*=10;
		tt+=memo[i];
		if(memo[i]==3)t=1;
		if(memo[i]==5)f=1;
		if(memo[i]==7)s=1;
	}
	//cout << tt << endl;
	if(t==1 && f==1 && s==1 && tt<=n)ans++;
	dfs(d+1);
	memo[d]=5;
	t=0;
	f=0;
	s=0;
	tt=0;
	for(int i=d;i>=0;i--)
	{
		tt*=10;
		tt+=memo[i];
		if(memo[i]==3)t=1;
		if(memo[i]==5)f=1;
		if(memo[i]==7)s=1;
	}
	//cout << tt << endl;
	if(t==1 && f==1 && s==1 && tt<=n)ans++;
	dfs(d+1);
	memo[d]=7;
	t=0;
	f=0;
	s=0;
	tt=0;
	for(int i=d;i>=0;i--)
	{
		tt*=10;
		tt+=memo[i];
		if(memo[i]==3)t=1;
		if(memo[i]==5)f=1;
		if(memo[i]==7)s=1;
	}
	//cout << tt << endl;
	if(t==1 && f==1 && s==1 && tt<=n)ans++;
	dfs(d+1);
}

int main()
{
	int tmp;
	cin >> n;
	
	tmp=n;
	while(tmp>0)
	{
		tmp/=10;
		keta++;
	}
	dfs(0);
	cout << ans << endl;
	return 0;
}



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

using namespace std;

int main()
{
    int a,a2,a3,ans;
    scanf("%d",&a);
    a2=a*a;
    a3=a2*a;
    ans = a+ a2+a3;

    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3824
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int X;cin>>X;
    if(X<=599) cout << 8 << endl;
    else if(X<=799) cout << 7 << endl;
    else if(X<=999) cout << 6 << endl;
    else if(X<=1199) cout << 5 << endl;
    else if(X<=1399) cout << 4 << endl;
    else if(X<=1599) cout << 3 << endl;
    else if(X<=1799) cout << 2 << endl;
    else if(X<=1999) cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3672
#include<iostream>

using namespace std;

int main(){
  
  int A, B, C, D;
  
  cin >> A >> B;
  
  D = A + B;
  
  if(D==3) C = 3;
  
  if(D==4) C = 2;
  
  if(D==5) C = 1;
  
  cout << C;
  
}

Measured memory_bytes: 256
from math import log2


def closest_power_of_2(x: int):
    return int(log2(x))


def attacks(x: int):
    return int(2 ** (log2(2 ** closest_power_of_2(x)) + 1) - 1)


if __name__ == '__main__':
    h = int(input())

    print(attacks(h))


Measured memory_bytes: 2940
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "tmp.cpp"

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

  int x;
  cin >> x;
  int ans = 1;
  while (ans * x % 360 != 0) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
 vl a(5);rep(i,5)cin>>a[i];
 rep(i,5){
     if(a[i]==0){
         cout<<i+1<<endl;
     }
 }
}

Measured memory_bytes: 3592
#include<stdio.h>

int main(void)
{ int a;
  int b;
  scanf("%d %d" , &a , &b );
  if(a<b){
     printf("a < b\n");
     }
   else if(a>b){
     printf("a > b\n");
     }
   else{
     printf("a == b\n");
     }
   return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
constexpr int time_limit = 2000;
chrono::system_clock::time_point start, current;
int c[26];
int64_t s[366][26];

int64_t eval(const vector<int> &state, int d){
    int last[26] = {0};
    int64_t csum = 0;
    for(int i=0;i<26;++i) csum += c[i];
    int64_t decl = -csum;
    int64_t score = 0;

    for(int i=1;i<=d;++i){
        score += s[i][state[i]];
        decl += (i - last[state[i]])*c[state[i]];
        last[state[i]] = i;
        score += decl;
        decl -= csum;
        cout << score << endl;
    }
    return score;
}

int main(){
    start = chrono::system_clock::now();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);

    int d;
    cin >> d;
    for(int i=0;i<26;++i) cin >> c[i];
    for(int i=1;i<=d;++i){
        for(int j=0;j<26;++j) cin >> s[i][j];
    }
    vector<int> state;
    state.push_back(0);
    for(int i=1;i<=d;++i){ int t; cin >> t; state.emplace_back(t-1); }
    eval(state, d);

    return 0;
}

Measured memory_bytes: 3692
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

int main(int argc, char* argv[])
{
  std::string s, t;
  std::cin >> s >> t;

  std::sort(s.begin(), s.end());
  std::sort(t.begin(), t.end());
  std::reverse(t.begin(), t.end());

  if (s < t) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b > 0 {
		a, b = b, a%b
	}
	return a
}

func main() {
	A := readInt()
	B := readInt()

	N := gcd(A, B)
	if N == 1 {
		fmt.Println(1)
		return
	}

	result := 1
	r := int(math.Sqrt(float64(N)))
	for x := 2; x < r+1; x++ {
		if N%x == 0 {
			result++
			for N%x == 0 {
				N /= x
			}
			if N == 1 {
				break
			}
		}
	}
	if N != 1 {
		result++
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
int main(){
    int n;
    string s,x="",y="";
    cin>>n>>s;
    if(n%2==1) cout<<"No"<<endl;
    else{
        REP(i,n/2) x+=s[i];
        FOR(i,n/2,n) y+=s[i];
        if(x.compare(y)==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
from collections import Counter

S = list(input())

c = Counter(S)
flag1 = False
flag2 = False
if "S" in c and "N" in c:
    flag1 = True
elif "S" not in c and "N" not in c:
    flag1 = True

if "W" in c and "E" in c:
    flag2 = True
elif "W" not in c and "E" not in c:
    flag2 = True

if flag1 and flag2:
    print("Yes")
else:
    print("No")


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

int blk = floor(sqrt(5*10e5));
struct query{
    int l;
    int r;
    int j;
};

bool rev(query a , query b)
{
    if(a.l/blk != b.l/blk)
    {
       return a.l/blk < b.l/blk;
    }

    return a.r < b.r;
}

int main()
{
    int n,q;
    cin>>n>>q;
    blk = floor(sqrt(n));
    vector<int> v(n);
    vector<int> freq(n+1);
    int count = 0;
    vector<query> qu(q);
    for(int i = 0;i<n;i++)
    {
        cin>>v[i];
    }
    int x,y;
    for(int i = 0;i<q;i++)
    {
        int x,y;
        cin>>x>>y;
        qu[i].l = x-1;
        qu[i].r = y-1;
        qu[i].j = i;
    }

    sort(qu.begin(),qu.end(),rev);

    vector<int> answers(q);
    int sl = 0,sr = -1;
    for(int i = 0;i<qu.size();i++)
    {
        int left = qu[i].l;
        int right = qu[i].r;
        while(left < sl)
        {
            sl--;
            freq[v[sl]]++;
            if(freq[v[sl]] == 1)
            {
                count++;
            }
        }

         while(right > sr)
        {
            sr++;
            freq[v[sr]]++;
            if(freq[v[sr]] == 1)
            {
                count++;
            }
        }

        while(left > sl)
        {
        
            freq[v[sl]]--;
            if(freq[v[sl]] == 0)
            {
                count--;
            }
            sl++;
        }


        while(right < sr)
        {
            freq[v[sr]]--;
            if(freq[v[sr]] == 0)
            {
                count--;
            }
            sr--;
        }
        answers[qu[i].j] = count;
    }

    for(int i:answers)
    {
        cout<<i<<"\n";
    }

    return 0;
}

Measured memory_bytes: 15464
import numpy as np

n = int(input())
d = list(map(int, input().split()))
d = np.array(d)
d_sorted = np.sort(d)

half = int(n/2)
if d_sorted[half] == d_sorted[half-1]:
    cnt = 0
else:
    cnt = (d_sorted[half]) - (d_sorted[half-1])
#print(half, d_sorted)

print(cnt)

Measured memory_bytes: 23412
#include "bits/stdc++.h"
using namespace std;


int main()
{
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l.at(i);
	}

	int ans = 1;
	int p = 0;
	for (auto l_ele : l) {
		p += l_ele;
		if (p <= x) {
			ans++;
		} else {
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n;
    cin >> n;
    int dp[n + 1];
    rep (i, n + 1) dp[i] = i;
    //配るDP
    /*rep (i, n + 1) {
        for (int j = 1; i + j <= n; j *= 6) {
            dp[i + j] = min (dp[i + j], dp[i] + 1);
        }
        for (int j = 1; i + j <= n; j *= 9) {
            dp[i + j] = min (dp[i + j], dp[i] + 1);
        }
    }*/
    //貰うDP
    rep (j, n + 1) {
        for (int i = 1; i <= j; i *= 6) {
            dp[j] = min (dp[j], dp[j - i] + 1);
        }
        for (int i = 1; i <= j; i *= 9) {
            dp[j] = min (dp[j], dp[j - i] + 1);
        }
    }
    cout << dp[n] << "\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 100000
using namespace std;
int main() {
  vector<char> v;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') {
      if (v.size() > 0) {
        v.pop_back();
      }
    } else {
      v.push_back(s[i]);
    }
  }
  for (char c : v) {
    cout << c;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n, x;
    int a[110]; 
    int ans = 0;
    long int sum = 0;
    long int s = 0;

    for (int i = 0; i < 110; i++){
        a[i] = 0;
    }
    cin >> n >> x;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    if (sum == x) {
        cout << n << endl;
    } else{ 
        sort(a, a+n);

        for (int i = 0; i < n; i++){
            if (x > s){
                s += a[i];
                ans++;      
            }
            else{
                break;
            } 
        }

        if (x == s){
            ans++;
        }

        cout << (ans-1) << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#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 llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(void){
    int N;
    cin>>N;
    N/=3;
    cout<<N;
    return 0;
}


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

using namespace std;

int main(void) {
  int N, K; cin >> N >> K;
  int p[N];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }

  int sum = 0;
  for (int i = 0; i < K; i++) {
    sum += p[i];
  }

  int max = sum;
  for (int i = K; i < N; i++) {
    sum = sum + p[i] - p[i-K];
    if (sum > max) {
      max = sum;
    }
  }
  
  cout << (max + K) / 2;
  if ((max+K)%2 != 0) {
    cout << ".5";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  string str;
  cin >> str;
  int ans = 0;
  for (char c : str) {
    if (c == '+')
      ans++;
    else
      ans--;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int main()
{
	ll n, m;
	scanf("%lld %lld", &n, &m);
	if (n == m)
	{
		printf("%lld", n + 1);
		return 0;
	}
	int la = sqrt(n);
	if (n <= 10000)
		la = n;
	for (ll i = 2; i <= la; i++)
	{
		ll xx = n;
		ll sum = 0;
		while (xx)
		{
			sum += (xx%i);
			xx /= i;
		}
		if (sum == m)
		{
			printf("%lld", i);
			return 0;
		}
	}
	for(ll i=sqrt(n)-1;i>=1;i--){
		ll cc = n / i;
		ll oo = n / (i + 1) + 1;
		ll xx = n / cc + (n%cc);
		ll xx1 = n / oo + (n%oo);
		if (xx <= m&&m <= xx1) {
			ll xxx = n /cc + (n%cc);
			ll chch = m - xxx;
			if (chch%i == 0) {
				printf("%lld\n", cc - chch/i);
				return 0;
			}
		}
	}
	puts("-1");
}

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

int main(){
  int n,i,kotae=1;
  cin>>n;
  string s[n];
  for(i=0;i<n;i++){
    cin>>s[i];
  }
  sort(s,s+n);
  for(i=1;i<n;i++){
    if(s[i]!=s[i-1]){
      kotae++;
    }
  }
  cout<<kotae;
}


Measured memory_bytes: 9888
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    vector<int> b(n + 1, 0);
    rep(i, n) {
        int mi = max(0LL, i - a[i]);
        b[mi] ++;
        int ma = min(n, i + a[i] + 1);
        b[ma] --;
    }
    rep(i, n) {
        b[i + 1] += b[i];
    }
    -- k;
    rep(j, min(300LL, k)) {
        vector<int> c(n + 1);
        rep(i, n) {
            int mi = max(0LL, i - b[i]);
            c[mi] ++;
            int ma = min(n, i + b[i] + 1);
            c[ma] --;
        }
        rep(i, n) {
            c[i + 1] += c[i];
        }
        swap(c, b);
    }
    rep(i, n) {
        if(i) cout << " ";
        cout << b[i];
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 7952
#include <stdio.h>

int main() {
    int cnt = 0;

    int X;
    scanf("%d", &X);

    while (100 <= X) {
        cnt++;
        X -= 100;
    }

    while (0 < cnt && 5 <= X) {
        cnt--;
        X -= 5;
    }

    while (0 < cnt && 4 <= X) {
        cnt--;
        X -= 4;
    }

    while (0 < cnt && 3 <= X) {
        cnt--;
        X -= 3;
    }

    while (0 < cnt && 2 <= X) {
        cnt--;
        X -= 2;
    }

    while (0 < cnt && 1 <= X) {
        cnt--;
        X -= 1;
    }

    if (0 <= cnt && X == 0) {
        printf("%d\n", 1);
        return 0;
    } else {
        printf("%d\n", 0);
        return 0;
    }    
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  int c[n],num[n];
  for(int i=0;i<n;i++){
    cin>>c[i];
    num[i]=0;
    }
  int ans=0;
  
  for(int i=0;i<n;i++){
    if(c[i]<=n){
    num[c[i]]+=1;
      if(num[c[i]]==c[i]){ans+=num[c[i]];}
    }
    }
  cout<<n-ans<<endl;
  return 0;
  }
  

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

int main(void) {
    int a[4], t;
    string inp, ans;
    cin >> inp;
    for(int i = 0; i < 4; i++){
        a[i] = inp[i] - '0';
    }

    for(int i = 0; i < 1 << 3; i++){
        t = a[0];
        ans = "";
        for(int j = 0; j < 3; ++j){
            if(i & (1 << j)){
                t += a[j + 1];
                ans += '+';
            }
            else{
                t -= a[j + 1];
                ans += '-';
            }
        }
        if(t == 7) {
            printf("%d%c%d%c%d%c%d=7\n", a[0], ans[0], a[1], ans[1], a[2], ans[2], a[3]);
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.rmi.server.UnicastRemoteObject;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n = sc.nextInt();
        int d[] = new int[2*100005];
        int a[] = sc.nextIntArray(n);
        int b[] = new int[n];

        for (int i = 0; i < a.length; i++) {
			d[a[i]]++;
			b[i]=a[i];
		}
        sort(b);
        int mx=b[n-1], mx2=b[n-2];
        
        for (int i = 0; i < a.length; i++) {
			if(mx>a[i])out.println(mx);
			else if(d[mx]>1)out.println(mx);
			else out.println(mx2);
		}
        
        
        out.flush();
    }



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P {
	int x, y;
	P(int  x, int y) {
	  this.x=x;
	  this.y=y;
	}
}


//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return b-p.b;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 47860
<?php
// D
fscanf(STDIN, '%d %d', $n, $m);
for ($i  = 0; $i < $m; $i++) {
    fscanf(STDIN, '%d %d', $a, $b);
    $a--;
    $b--;
    if (isset($x[$a])) {
        $x[$a] = min($x[$a], $b);
    } else {
        $x[$a] = $b;
    }
}
ksort($x);
$ans = 0;
$ok = -1;
foreach ($x as $i => $v) {
    if ($i > $ok) {
        $ans++;
        $ok = $v - 1;
    } else {
        $ok = min($ok, $v - 1);
    }
}
echo $ans;

Measured memory_bytes: 13048
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    string S, T;
    cin >> S >> T;
    bool ans = false;
    char s[100], t[100];
    rep(i, S.size()) s[i] = S[i];
    rep(i, T.size()) t[i] = T[i];
    int lens = S.size();
    int lent = T.size();
    sort(s, s + lens);
    sort(t, t + lent, greater<char>());
    S = "", T = "";
    rep(i, lens) S += s[i], T += t[i];
    if (strcmp(t, s) > 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(void){
   while(1){
      int field[41][41] = {0};
      field[1][1] = 1;

      int w,h; scanf("%d%d",&w,&h);
      if(w == 0 && h == 0) break;

      int n; scanf("%d",&n);
      for(int i = 0;i < n;i++){
         int a,b;
            scanf("%d%d",&a,&b);
            field[b][a] = -1;
      }
      for(int i = 1;i <= h;i++){
         for(int j = 1;j <= w;j++){
               if(i == 1 && j == 1) continue;
               if(field[i][j] == -1){
                  field[i][j] = 0;
               }
               else{
                  field[i][j] = field[i-1][j] +field[i][j-1];
               }
         }
      }
      printf("%d\n",field[h][w]);
   }
   return 0;
}

Measured memory_bytes: 1032
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
   ll n,i,j,cc=0,m;
   cin>>n;
   ll ara[n+1],bra[n];
   for(i=0;i<=n;i++)cin>>ara[i];
   for(i=0;i<n;i++)cin>>bra[i];
   for(i=0;i<n;i++){
      if(ara[i]>bra[i]){
        cc+=bra[i];bra[i]=0;
      }
      else{
        cc+=ara[i];bra[i]-=ara[i];
        ll x=min(bra[i],ara[i+1]);
        cc+=x;
        ara[i+1]-=x;

      }
   }
   cout<<cc<<endl;
return 0;
}


Measured memory_bytes: 6528
import itertools
N = int(input())
S = [0]*5
for i in range(N):
    a = input()
    if a[0] == 'M':
        S[0] += 1
    if a[0] == 'A':
        S[1] += 1
    if a[0] == 'R':
        S[2] += 1
    if a[0] == 'C':
        S[3] += 1
    if a[0] == 'H':
        S[4] += 1
S.sort(reverse=True)
if S[2] == 0:
    print(0)
elif S[3] == 0:
    print(S[0]*S[1]*S[2])
elif S[4] == 0:
    print(S[0]*S[1]*S[2]+S[3]*S[1]*S[2]+S[0]*S[1]*S[3]+S[0]*S[2]*S[3])
else:
    ans = 0
    for x,y,z in itertools.combinations([0,1,2,3,4], 3):
        ans += S[x]*S[y]*S[z]
    print(ans)

Measured memory_bytes: 44888
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>

using namespace std;
int main() {
  int n;
  char s[11];
  scanf("%s", s);
  n = strlen(s);
  if (n % 2) {
    printf("No\n");
    return 0;
  }
  for (int i = 0; i < n; i += 2) {
    if (s[i] != 'h' || s[i + 1] != 'i') {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int n = Integer.parseInt(sc.next());
      int m = Integer.parseInt(sc.next());

      int[] L = new int[m];
      int[] R = new int[m];


      for(int i=0;i<m;i++){
        L[i] = Integer.parseInt(sc.next());
        R[i] = Integer.parseInt(sc.next());
      }

      int max = cmax(L,m);
      int min = cmin(R,m);

      int ans = min - max + 1;

      if(ans>=0){
        System.out.println(ans);
      }
      else{
        System.out.println("0");
      }

    }

    public static int cmax(int[] aa,int nn){
      int max1=aa[0];
      for(int j=1;j<nn;j++){
        if(aa[j]>max1){
          max1=aa[j];
        }
      }
      return max1;
    }
    public static int cmin(int[] bb,int nn){
      int min1=bb[0];
      for(int j=1;j<nn;j++){
        if(bb[j]<min1){
          min1=bb[j];
        }
      }
      return min1;
    }

}


Measured memory_bytes: 50904
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

int N, M;

// 素因数
vector<int> getPrimeFactors(int a) {
    vector<int> s;
    for (int i = 2; i * i <= a; i++) {
        if (a % i != 0) continue;
        while (a % i == 0) {
            s.push_back(i);
            a /= i;
        }
    }
    if (a > 1) s.push_back(a);
    return s;
}

int dfs(map<int, int>& cnt, vector<int>& v, vector<int>& num, int i) {
    if (i == v.size()) {
        int t = 1;
        REP(ii, v.size()) {
            REP(k, num[ii]) {
                t *= v[ii];
            }
        }
        return t;
    }

    int res = INF;
    FOR(j, 0, cnt[v[i]]) {
        num.push_back(j);
        int tmp = dfs(cnt, v, num, i + 1);
        if (tmp >= N) {
            res = min(res, dfs(cnt, v, num, i + 1));
        }
        num.pop_back();
    }

    return res;
}

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

    cin >> N >> M;
    if (N == 1) {
        cout << M << endl;
        return 0;
    }

    vector<int> v = getPrimeFactors(M);
    sort(v.begin(), v.end());

    vector<int> s;
    s.push_back(v[0]);
    map<int, int> cnt;
    REP(i, v.size()) {
        cnt[v[i]]++;
        if (s.back() != v[i]) {
            s.push_back(v[i]);
        }
    }

    int ans = 1;
    int t = v[0];
    int r = 0;

    vector<int> num;
    int res = dfs(cnt, s, num, 0);

    cout << M / res << endl;

    return 0;
}


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

#define INF (1<<31)-1
#define LINF (1LL<<63)-1LL
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

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

    if(k <= a)ans = k;
    else if(k <= a+b)ans = a;
    else ans = a - (k-a-b);


    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
 
using namespace std;
 
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
typedef vector<int> vi;

int main(void){
	int n,m,l;
	cin >> n;
	cin >> m;
	cout << pow(2,m)*((n-m)*100+m*1900) << endl;
	return 0;
}

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

int main()
{
  int64_t N;
  cin >> N;
  
  int64_t T = 0;
  int64_t Q; //Qは文字列の桁数
  string answer; //答えの文字列
  int U;

  vector<char> C = {'a', 'b', 'c', 'd', 'e', 'f', 'g',
                    'h', 'i', 'j', 'k', 'l', 'm',
                    'n', 'o', 'p', 'q', 'r', 's', 't',
                    'u', 'v', 'w', 'x', 'y', 'z'};
  
  for(int i = 0; i < 11; i++)
  {
    if(1 <= N - T && N - T <= pow(26, i + 1))
    {
      Q = i + 1;
      break;
    }
    else{T += pow(26, i + 1);}
  }
  
  vector<char> A(Q);
  N -= T;
  
  for(int i = 0; i < Q; i++)
  {
    U = (N - 1) / pow(26, Q - 1 - i);
    A.at(i) = C.at(U);
    answer += A.at(i);
    N -= U * pow(26, Q - 1 - i);
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 4104
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,n) for(int i=0;i<n;i++)
#define lop(i,a,b) for(int i=a;i<=b;i++)
#define int long long int
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp make_pair
#define sz(a) int((a).size())
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define so(v) sort(all(v))
#define sod(v) sort(allr(v))
#define mfind(c, element) (c.find(element) != c.end())
#define gfind(c, element) (find(all(c),element) != c.end())
#define gfindindex(c, element) (find(all(c),element)-c.begin())
#define vp(x) cout << #x << " --> " << x << endl;
#define cp1(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define cpp1(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define ccp1(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define bsnp np3(low,high,mid);
#define hmm1 high=mid-1;
#define lmp1 low=mid+1;
#define hmp1 high=mid+1;
#define lmm1 low=mid-1;
#define fi first
#define se second
#define endl "\n"
#define np1(x) cout<<#x<<"="<<x<<'\n'
#define np2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define np3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
// upper_bound(all(a),k,greater<int>()) gives first no smaller(not greater) than k
 
struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};//comparison used for sorting set<pair<i,i>,cmp>
bool myComparison(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
//increasing ordr basedd on 2nd
};
const int mod=1e9 +7;
main()
{
IOS;
int n;cin>>n;
vi a(n);
int s=0,ans=0;
vi pref(n+1,0);
loop(i,n)
{cin>>a[i];pref[i+1]=pref[i]+a[i];}
loop(i,n)
{   
    int s=pref[n]-pref[i];
    int x=((   (s%mod)-(a[i]%mod) + mod )%mod )*(a[i]%mod);
    x=(x+mod)%mod;
    ans=(ans+x)%mod;
}
 
cout<<ans<<endl;
 
return 0;
}

Measured memory_bytes: 6300
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include<algorithm> 
using namespace std;
// main() is where program execution begins.


int main() {
int N;
cin >> N;
int arry[N];

for (int i = 0; i < N; ++i)
{
	cin >> arry[i];
}

long long int dp[N] = {0};
dp[0] = 0;
dp[1] = abs(arry[1] - arry[0]);

for (int i = 2; i < N; ++i)
{
	dp[i] = min(dp[i-1] + abs(arry[i] - arry[i-1]), dp[i-2] + abs(arry[i] - arry[i-2]));
}
   
	cout << dp[N-1] << endl;
   return 0;
}

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

int main () {
  int N , A ,B ;
  cin >> N >> A >> B ;
  int sum = 0 ;
  for(int i = 1; i<= N ; i++){
    if(i<10){
      if( A <= i && i <=B){
        sum += i ;
      }
    }
    else if (i<100){
      if( A<= (i%10 + i/10) && (i%10 + i/10) <= B ){
        sum += i ;
      }
    }
    else if (i<1000){
      if ( A<= (i/100 + (i%100)/10 + i%10) && (i/100 + (i%100)/10 + i%10)  <= B ){
        sum += i ;
      }
    }
    else if (i<10000){
      if ( A<= (i/1000 + (i%1000)/100 + (i%100)/10 + i%10) && (i/1000 + (i%1000)/100 + (i%100)/10 + i%10) <= B ){
        sum += i ;
      }
    }
    else{
      if (A<=1 && 1<=B){
        sum += i ;
      }
    }
  }
  cout << sum << endl;
}

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

const long long mod = 1000000007;

long long fpow(long long a, long long p)
{
	long long r = 1;
	while (p){
		if (p & 1) r = r * a % mod;
		a = a * a % mod;
		p /= 2;
	}
	return r;
}

int N, b[303][303];
long long first[303], mul[303];
long long cnt[303][303][303];

long long go(int n, int m, int r)
{
	if (r < 0) return 0;
	if (n == 0 || m == 0) return r == 0;
	if (cnt[n][m][r] != -1) return cnt[n][m][r];
	long long &res = cnt[n][m][r]; res = 0;
	res = go(n, m - 1, r-1);
	res = (res + go(n - 1, m - 1, r) * (fpow(2, n) - 1) % mod * fpow(2, m - 1)) % mod;
	return res;
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) scanf("%d", &b[i][j]);

	for (int i = 0; i <= N; i++) for (int j = 0; j <= N; j++) for (int k = 0; k <= N; k++) cnt[i][j][k] = -1;

	int rank = 0;
	for (int i = 0, s = 0; i < N; i++, s++){
		bool g = 0;
		for (int j = i; j < N; j++) if (b[j][s]){
			if (i != j) for (int k = 0; k < N; k++) swap(b[i][k], b[j][k]);
			g = 1;
		}
		if (!g){
			rank++;
			continue;
		}
		for (int j = i + 1; j < N; j++) if (b[j][s]){
			for (int k = 0; k < N; k++) b[j][k] ^= b[i][k];
		}
	}

	first[1] = 1;
	mul[0] = 3;
	for (int i = 2; i <= N; i++){
		first[i] = first[i - 1] * fpow(2, i - 1) % mod * (fpow(2, i) - 1) % mod;
		long long sum = 0, now = first[i];
		for (int j = 0; j < i; j++){
			sum = (sum + now * go(i, i, j)) % mod;
			if (j < i-1) now = now * mul[j] % mod;
		}
		mul[i-1] = (fpow(2,i*i*2) - sum + mod)* fpow(now, mod - 2) % mod;
	}
	long long ans = first[N];
	for (int i = 0; i < rank; i++) ans = ans * mul[i] % mod;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 216192