akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N, M;
	cin >> N >> M;
	vector<int>H(N);
	for (int i = 0; i < N; i++) cin >> H.at(i);
	vector<pair<int, int>>A(M);
	vector<bool>ans(N, true);
	for (int i = 0; i < M; i++) {
		cin >> A.at(i).first >> A.at(i).second;
		if (H.at(A.at(i).first - 1) < H.at(A.at(i).second - 1)) ans.at(A.at(i).first - 1) = false;
		else if (H.at(A.at(i).first - 1) > H.at(A.at(i).second - 1)) ans.at(A.at(i).second - 1) = false;
		else {
			ans.at(A.at(i).first - 1) = false;
			ans.at(A.at(i).second - 1) = false;
		}
	}
	int out = 0;
	for (int i = 0; i < N; i++) 
	{ 
		if (ans.at(i))out++;
	}
	cout << out << endl;
}

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n; cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    int t = 0,j = i;
    while(j > 0){
      j /= 10;
      t++;
    }
    if(t%2 == 1) ans++;
  }
  cout << ans << endl;

  return 0;
}


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


int main() {
  int n;
  cin >> n;
  vector<int> fibo(n);
  
  for(int i = 0;i < n;i++){
      if(i == 0){
          fibo.at(i) = 1;
      }else if(i == 1){
          fibo.at(i) = 2;
      }else{
          fibo.at(i) = fibo.at(i-1)+fibo.at(i-2);
      }
  }
  cout << fibo.at(n-1) << endl;
  
}


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

const long long mod=1000000007ll;

int main()
{
  int n;
  scanf("%d",&n);
  static int a[100000];
  for(int i=0;i<n;i++){
    scanf("%d",a+i);
    a[i]--;
  }
  vector<vector<int> > e(n);
  for(int i=0;i<n;i++){
    e[a[i]].push_back(i);
  }
  static int b[100000];
  static int T[100000];
  for(int i=0;i<n;i++){
    b[i]=-1;
  }
  int C[100001]={0};
  long long ans=1ll;
  for(int t=0;t<n;t++){
    if(b[t]!=-1){
      continue;
    }
    int i=t;
    while(b[i]==-1){
      b[i]=t;
      i=a[i];
    }
    if(b[i]!=t){
      continue;
    }
    int p=i;
    i=a[i];
    int ini=i;
    int N=0;
    bool F=0;
    do{
      if(e[i].size()>2){
	ans=0ll;
	goto ZERO;
      }
      if(e[i].size()==1){
	T[N]=0;
      }
      else{
	F=1;
	int q=e[i][0]+e[i][1]-p;
	T[N]=1;
	while(e[q].size()>0){
	  if(e[q].size()>1){
	    ans=0ll;
	    goto ZERO;
	  }
	  q=e[q][0];
	  T[N]++;
	}
      }
      N++;
      p=i;
      i=a[i];
    }while(i!=ini);
    if(!F){
      C[N]++;
    }
    else{
      for(int i=0;i<N;i++){
	if(T[i]==0){
	  continue;
	}
	int j=1;
	while(T[(i+N-j)%N]==0){
	  j++;
	}
	if(j>=T[i]+1){
	  ans*=2;
	  ans%=mod;
	}
	else if(j<T[i]){
	  ans=0;
	  goto ZERO;
	}
      }
    }
  }
  for(int i=1;i<=n;i++){
    if(C[i]==0){
      continue;
    }
    vector<long long> dp(C[i]+1);
    dp[0]=1ll;
    dp[1]=(i>1&&i%2==1?2:1);
    for(int j=2;j<=C[i];j++){
      dp[j]=(dp[j-1]*dp[1]%mod+dp[j-2]*(j-1)%mod*i%mod)%mod;
    }
    ans*=dp[C[i]];
    ans%=mod;
  }
 ZERO:
  printf("%lld\n",ans);
  return 0;
}


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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n, k;
    cin >> n >> k;
    vector<double> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    Int ok = 1e9;
    Int ng = 0;
    while (abs(ok - ng) > 1) {
        Int mid = (ok + ng) / 2;
        Int cnt = 0;
        for (Int i = 0; i < n; i++) {
            if (a[i] <= mid) continue;
            cnt += floor(a[i] / (double)mid);
        }
        if (cnt <= k) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    print(ok);
    return 0;
}


Measured memory_bytes: 4720
//package ac144;
import java.lang.*;
import java.math.*;
import java.util.ArrayList;
import java.util.*;
import java.io.*;
public class Main {
	static Scanner scn = new Scanner(System.in);
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		long n =scn.nextLong();
//		ArrayList<Long> al = new ArrayList<>();
		int s = (int) Math.sqrt(n);
		boolean flag = true;
		long n1 = -1;
		long n2 = -1;
		while(flag) {
			if(n%s==0) {
				flag = false;
				n1 = s;
				n2 = n/s;
			}else {
				s--;
			}

		}
		
		long ans = n1+n2-2;
		System.out.println(ans);
	}

}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

void solve (void)
{
  int N;
  cin>>N;
  int D;cin>>D;
  D = 2*D+1;
  cout<<N/D + (N%D>0)<<endl;
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let a:usize = read();
    let b:usize = read();
    let c:usize = read();
    let d:usize = read();
    println!("{}", num(b, c, d) - num(a-1, c, d));
}

fn gcd(a:usize, b:usize) -> usize {
    if b == 0 {
        return a
    }
    return gcd(b, a%b)
}

fn num(a:usize, b:usize, c:usize) -> usize {
    let lcm = b / gcd(b, c) * c;
    return a - a/b - a / c + a / lcm
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int mn = min(a+b,min(b+c,c+a));
  cout<<mn<<endl;
  return 0;
}


Measured memory_bytes: 764
#include<stdio.h>
#define MAX 100
#define INF (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2


int prim();

int n,N[MAX][MAX];


int main(){
  int i,j,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&r);
      N[i][j]=(r ==-1) ? INF:r;
    }
  }
  printf("%d\n",prim());
  return 0;
}

int prim(){
  int i,x,minv,a[MAX],b[MAX],color[MAX];
  for(i=0;i<n;i++){
    a[i]=INF;
    b[i]=-1;
    color[i]=WHITE;
  }
  a[0] = 0;
  while(1){
    minv = INF;
    x = -1;
    for(i=0;i<n;i++){
      if(minv > a[i] && color[i] != BLACK){
        x=i;
        minv = a[i];
      }
    }
    if(x == -1){
      break;
}
color[x] = BLACK;
    int v;
    for(v=0;v<n;v++){
      if(color[v] != BLACK && N[x][v] != INF){
        if(a[v] > N[x][v]){
        a[v] = N[x][v];
        b[v]=x;
        color[v]=GRAY;
      }

      }
    }
  }
    int sum =0;
    for(i=0;i<n;i++){
      if(b[i] != -1){
        sum += N[i][b[i]];
      }
    }
    return sum;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
  lint T;
  cin >> T;

  while(T--) {
    int N;
    cin >> N;

    vector<lint> A(N);
    for(auto& elem : A) cin >> elem;

    string S;
    cin >> S;
    if(S[N-1] == '1') {
      cout << 1 << endl;
      continue;
    }

    reverse(A.begin(), A.end());
    reverse(S.begin(), S.end());

    multiset<lint> st;
    bool zero = true;
    for(lint i=0; i<N; i++) {
      if(S[i] == '0') {
        st.insert(A[i]);
      } else {
        vector<lint> a(st.begin(), st.end());
        lint K = A[i];
        // 移植：https://atcoder.jp/contests/code-thanks-festival-2017-open/submissions/1834702

        lint kakutei=0;
        for(lint k=60;k>=0;k--){
          lint po=0;
          for(lint j=a.size()-1;j>=0;j--){
            if(po==0&&a[j]>>(k+1)==0&&a[j]>>k==1&&(a[j]^kakutei)>>k==K>>k){po=a[j];kakutei^=po;}
            else if(po==0&&a[j]>>(k+1)==0&&a[j]>>k==1)po=a[j];
            else if(po!=0&&a[j]>(po^a[j]))a[j]=po^a[j];
          }
        }
        zero &= (kakutei == K);
      }
    }

    cout << 1 - zero << endl;
  }
}

Measured memory_bytes: 3680
B, A = map(int, input().split())

L = [['.' for i in range(100)] for j in range(100)]

for i in range(100):
    for j in range(100):
        if i >=50:
            L[i][j] = '#'
            
count = 1
now = 0
for i in range(49):
    for j in range(100):
        if count == A:
            break
        if  now%2 == 0 and j%2 == 0:
            L[now][j] = '#'
            count += 1
    now += 1

    if count == A:
        break  
        
count = 1
now = 51
for i in range(51, 100):
    for j in range(100):
        if count == B:
            break
        if  now%2 == 0 and j%2 == 0:
            L[now][j] = '.'
            count += 1

    now += 1
    if count == B:
        break  

print(100, 100)
for i in range(100):
    res = ''
    for j in range(100):
        res += L[i][j]
    print(res)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int m,n;
int s[100111];
int main()
{
	scanf("%d%d",&m,&n);
	int last = 0;
	for(int i=1;i<=m;i++)
		scanf("%d",&s[i]);
	for(int i=1;i<m;i++)
		if(s[i]+s[i+1]>=n)
		{
			last=i;
			break;
		}
		if(last==0)
			cout<<"Impossible"<<endl;
		else
		{
			cout<<"Possible"<<endl;
			for(int i=1;i<last;i++)cout<<i<<"\n";
			for(int i=m-1;i>last;i--)cout<<i<<"\n";
			cout<<last<<endl;
		}
		return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r;
ll x[500005],y[500005],z[500005];
char s[1005][1005];
ll dp[1005][1005];
bool flag,dame;

int main(){
	cin >> h >> w;
	queue<P> q;
	for(i=0;i<h;i++){
		cin >> s[i];
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			dp[i][j] = INF;
		}
	}

	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(s[i][j] == '#'){
				q.push(P(2000 * i + j,0));
				//dp[i][j] = 0;
			}
		}
	}
	while(!q.empty()){
		P p = q.front();
		q.pop();
		ll x,y;
		x = p.first / 2000;
		y = p.first % 2000;
		if(dp[x][y] != INF)continue;
		dp[x][y] = p.second;
		for(int i=0;i<4;i++){
			ll nx,ny;
			nx = x + dx[i];
			ny = y + dy[i];
			if(0 <= nx && nx < h && 0 <= ny && ny < w && dp[nx][ny] == INF){
				q.push(P(nx*2000+ny,p.second + 1));
			}
		}
	}
	ans = -1;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			//pe(dp[i][j]);
			ans = max(ans,dp[i][j]);
		}
	}
	p(ans);



	return 0;
}

Measured memory_bytes: 66820
#include <bits/stdc++.h>
#define ll long long int
#define li long int
#define ld long double
const ll len=1e6+1;
using namespace std;

int main()
{
    int k;
    cin>>k;
    if(k%2==0 || k%5==0)
    {
        cout<<-1<<endl;
    }
    else
    {
        int curr=7%k;
        int ans=1;
        while(curr!=0)
        {
            curr=curr*10+7;
            curr%=k;
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		char[] a = sc.next().toCharArray(), b = sc.next().toCharArray(), c = sc.next().toCharArray();
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == b[i] && a[i] == c[i]) {
			} else if (a[i] == b[i] || a[i] == c[i] || b[i] == c[i]) {
				ans += 1;
			} else {
				ans += 2;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21588
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    vector <string> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec[i];
        sort(vec[i].begin(), vec[i].end());
    }

    sort(vec.begin(), vec.end());

    ll count = 1;
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        if (vec[i] != vec[i - 1]) {
            ans += count * (count - 1) / 2LL;
            count = 1;
        } else {
            count++;
        }
    }

    ans += count * (count - 1) / 2LL;
    cout << ans << "\n";
    return 0;
}

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

int main() {
  int N;
  string color;
  bool Y = false;
  cin >> N;
  
  for(int i=0; i<N; i++){
    cin >> color;
    if (color == "Y"){
      Y = true;
      break;
    }
  }
  
  if (Y)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}

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

int main() {
  ll n;
  cin>>n;
  int a[n];
  rep(i,0,n){
    cin>>a[i];
    a[i]--;
  }
  int b[n];
  rep(i,0,n) b[a[i]]=i;
  
  ll ans=0;
  set<int> s,t;
  s.insert(-1);
  s.insert(n);
  t.insert(-1);
  t.insert(n);
  rep(i,0,n){
    int c,d,e,f;
    e=*s.upper_bound(b[n-1-i]);
    if(e==n) f=n;
    else f=*s.upper_bound(e);
    d=*t.upper_bound(n-1-b[n-1-i]);
    if(d==n) c=n;
    else c=*t.upper_bound(d);
    d=n-1-d;
    c=n-1-c;
    ans+=(n-i)*((d-c)*(e-b[n-1-i])+(f-e)*(b[n-1-i]-d));
    s.insert(b[n-1-i]);
    t.insert(n-1-b[n-1-i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 10368
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    int S = 0;
    REP(i, N) {
        cin >> A[i];
        S += A[i];
    }
    int res = 0;
    vector<int> ds;
    for (int d = 1; d * d <= S; d++) {
        if (S % d != 0) {
            continue;
        }
        ds.push_back(d);
        if (d != S / d) {
            ds.push_back(S / d);
        }
    }
    SORT(ds);
    for (auto d : ds) {
        vector<int> rs;
        int p = 0, m = 0;
        REP(i, N) {
            int r = A[i] % d;
            if (r != 0) {
                rs.push_back(r);
                p += d - r;
            }
        }
        if (p == 0) {
            res = d;
            continue;
        }
        SORT(rs);
        for (auto r : rs) {
            p -= d - r;
            m += r;
            if (p == m && p <= K) {
                res = d;
                break;
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import System.IO (isEOF)

main = do
    quit <- isEOF
    if quit then return () else do
        input >>= return . solve >>= output
        main

input :: IO (Int)
input = readLn

output :: (Int,Int) -> IO ()
output (a,b) = putStrLn $ unwords [show a, show b]

solve :: Int -> (Int,Int)
solve n = (maxPrimeLT n, minPrimeGT n)
    where
    maxPrimeLT n = head $ filter isPrime [n-1,n-2..]
    minPrimeGT n = head $ filter isPrime [n+1,n+2..]

isPrime n = isPrime' n 2
    where
    isPrime' n m
        | n < m^2 = True
        | n `mod` m == 0 = False
        | otherwise = isPrime' n (m+1)

Measured memory_bytes: 4236
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    int a,b;cin >>a>>b;
    int ans=max({a+b,a*b,a-b});
    cout <<ans <<endl;
}



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

signed main() {
  int n; cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; i++) cin >> v.at(i);

  int m; cin >> m;
  vector<int> cp;
  for(int i = 0; i < m; i++) {
    int p, x;
    cp = v;
    cin >> p >> x;
    cp.at(p-1) = x;
    int ans = 0;
    for(int j = 0; j < cp.size(); j++) {
      ans += cp.at(j);
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, c int
	fmt.Scan(&n, &c)

	ds := [31][31]int{}
	for i := 1; i <= c; i++ {
		for j := 1; j <= c; j++ {
			fmt.Scan(&ds[i][j])
		}
	}

	ms := [3][31]int{}
	cs := make([][]int, n+1)
	for i := 1; i <= n; i++ {
		cs[i] = make([]int, n+1)
		for j := 1; j <= n; j++ {
			fmt.Scan(&cs[i][j])
			ms[(i+j)%3][cs[i][j]]++
		}
	}

	ans := int(1e9)
	for c1 := 1; c1 <= c; c1++ {
		for c2 := 1; c2 <= c; c2++ {
			if c1 == c2 {
				continue
			}
			for c3 := 1; c3 <= c; c3++ {
				if c1 == c3 || c2 == c3 {
					continue
				}

				d := 0
				for sc := 1; sc <= c; sc++ {
					d += ms[0][sc] * ds[sc][c1]
				}
				for sc := 1; sc <= c; sc++ {
					d += ms[1][sc] * ds[sc][c2]
				}
				for sc := 1; sc <= c; sc++ {
					d += ms[2][sc] * ds[sc][c3]
				}

				ans = min(ans, d)
			}
		}
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 6784
# coding: utf-8
# Your code here!
N = int(input())
a = list(map(int, (input().rstrip().split())))
a_sort = sorted(a, reverse=True)
A = 0
B = 0
for i in range(len(a_sort)):
    if i % 2 == 0:
        A += a_sort[i]
    else:
        B += a_sort[i]
print(A - B)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    if(n >= 1000) cout << "ABD" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>

int main(){
	int N, M;
	std::cin >> N >> M;
	std::vector<int> v;
	int tmp = 0;
	while(std::cin >> tmp) v.push_back(tmp);

	double sum = 0;
	for(auto x : v){
		sum += x;
	}

	int m = 0;
	for(auto x : v){
		if( x>=(double)(sum/4/M) ) m++;
	}

	if(m < M){
		std::cout << "No" << std::endl;
	}else{
		std::cout << "Yes" << std::endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> 
#define int long long 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> hashing;
int pow(int x,int n,int mod){int res = 1;while (n){if (n&1){res = (res*x)%mod;n--;}else{x = (x*x)%mod;n/=2;}}return res;}
const int MOD = 1e9 + 7;

/////////////////////////////////////" Please Don't ruin it "//////////////////////////////////////


vector<int>arr;
vector<vector<int>>res;


void subs(int pt,vector<int>ans){

    int n = arr.size();

    if (pt == n){
        res.push_back(ans);
        return;
    }

    ans.push_back(arr[pt]);
    subs(pt+1,ans);
    ans.pop_back();
    subs(pt+1,ans);
}


int32_t main(){

    int n,m,x;
    cin>>n>>m>>x;

    int mat[n][m+1];
    for (int i=0;i<n;i++){
        for (int j=0;j<=m;j++) cin>>mat[i][j];
    }
    
    for (int i=1;i<=n;i++)arr.push_back(i);
    subs(0,{});
    
    
    int pakka=5e18;

    for (auto k : res){

        bool f=1;
        int cost = 0;
        vector<int>verify(m,0);

        for (auto p : k){

            cost+=mat[p-1][0];
            for (int i=0;i<m;i++) verify[i]+=mat[p-1][i+1];
        }

        for (int i=0;i<m;i++) if (verify[i]<x) f=0;

        if (f){
            pakka = min(pakka,cost);
        }
    }

    if (pakka == 5e18)
        cout<<"-1\n";
    else
        cout<<pakka<<'\n';

    


    return 0;
}

Measured memory_bytes: 3988
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: BufRead> {
  reader: R,
  iter: std::vec::IntoIter<String>
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader, iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
  fn get_as_vec<T: FromStr>(&mut self) -> Vec<T> {
    self.iter.clone().map(|v| v.parse().ok().unwrap()).collect()
  }
  fn get_line(&mut self) -> String {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    line.trim().to_string()
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  sc.new_line();
  let (a, b, c) = scan!(sc; i32, i32, i32);
  println!("{}", if a == b && b == c { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)1e5+5

void solve(){
    ll n;
    cin>>n;
    ll a[n+1];
    ll b[n+1]={0};
    loop(i,0+1,n+1){
        cin>>a[i];
    }
    for(ll i=n; i>=1; i--){
        // debug(i);
        ll sum=0;
        for(ll j=2*i; j<=n; j+=i){
            // debug(j);
            sum=sum+b[j];
        }
        if(sum%2==0){
            if(a[i]==0) b[i]=0;
            else if(a[i]==1) b[i]=1;
        }
        else if(sum%2==1){
            if(a[i]==0) b[i]=1;
            else if(a[i]==1) b[i]=0;
        }
    }
    ll cnt=0;
    loop(i,1,n+1){
        if(b[i]) cnt++;
    }
    print(cnt);
    loop(i,1,n+1){
        if(b[i]){
            cout<<i<<" ";
        }
    }
    cout<<endl;
}

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

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



Measured memory_bytes: 3968
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>

using namespace std;
typedef long long ll;

int main() {
	int N, x;
	cin >> N >> x;
	if (x == 1 || x == 2*N-1) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
		vector<int> ans(2*N-1);
		for (int i = 0; i < N; i++) {
			ans[i+N] = (x+i)%(2*N-1) + 1;
			ans[N-i-1] = (x+2*N-2-i)%(2*N-1) + 1;
		}
		for (int el : ans)
			cout << el << endl;
	}
	return 0;
}


Measured memory_bytes: 2304
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        DJSet ds = new DJSet(n);
        int[][] b = new int[m][2];
        for (int i = 0; i < m; i++) b[i] = new int[]{sc.nextInt()-1, sc.nextInt()-1};
        long ans[] = new long[m];
        ans[m-1] = (long)n * (n-1) /2;
        for (int i = m-1; i > 0; i--) {
            int x = b[i][0];
            int y = b[i][1];
            if(ds.same(x, y)){
                ans[i-1] = ans[i];
            }else{
                ans[i-1] = ans[i] - (ds.upper[ds.root(x)] * ds.upper[ds.root(y)]);
            }
            ds.union(x, y);
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < m; i++) {
            sb.append(ans[i]).append("\n");
        }

        System.out.println(sb.toString());
        sc.close();
    }

}

class DJSet {
    /**
     * 各要素の親を保持する配列。
     * 自信が根である要素は負の数を持つ。
     * （負の数の場合、絶対値がその集合の要素数）
     */
    public int[] upper;

    /**
     * コンストラクタ。
     * @param n 対象となる要素数
     */
    public DJSet(int n) {
        upper = new int[n];
        Arrays.fill(upper, -1);
    }

    /**
     * 要素xが含まれる集合のrootを求める。
     * rootを求める過程で経路圧縮しrootが親になるようにする。
     * @param x 要素x
     * @return 要素xが含まれる集合のroot
     */
    public int root(int x) {
        return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
    }

    /**
     * 要素xと要素yが同じ集合か判定する。
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yが同じ集合であればtrue、そうでなければfalseを返す。
     */
    public boolean same(int x, int y) {
        return root(x) == root(y);
    }

    /**
     * 要素xと要素yを含むそれぞれの集合を合併する。
     * 要素数の多い集合のrootを残し、少ないほうのrootをその下に合併する。
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yを含むそれぞれの集合を合併できたらtrue、もともと同じ集合で合併しなかったらfalseを返す。
     */
    public boolean union(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (upper[y] < upper[x]) {
                int t = x;
                x = y;
                y = t;
            }
            upper[x] += upper[y];
            upper[y] = x;
        }
        return x != y;
    }

    /**
     * 集合の数を数える。
     * @return 集合の数
     */
    public int countSet() {
        int c = 0;
        for (int u : upper) {
            if (u < 0)
                c++;
        }
        return c;
    }

    /**
     * 要素ｘが含まれる集合の要素数を数える。
     * @param x 要素ｘ
     * @return 要素ｘが含まれる集合の要素数
     */
    public int countElement(int x) {
        return upper[root(x)] * -1;
    }
}


Measured memory_bytes: 94212
n,k=map(int,input().split())
d=[[] for i in range(k)]
dlist=[]
memb=[i+1 for i in range(n)]
for i in range(k):
    d[i]=int(input())
    dklist=list(map(int,input().split()))
    dlist.append(dklist)
    for j in dklist:
        if j in memb:
            memb.remove(j)
print(len(list(memb)))

Measured memory_bytes: 9152
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;


int main() {
	ll a, b; cin >> a >> b;
	ll ans = 0;
	for (ll i = a; i <= b; i++) {
		ll k = i;
		vector<ll> v(0);
		while (k > 0) {
			v.emplace_back(k % 10);
			k /= 10;
		}
		bool flag = true;
		rep(j, v.size() / 2) {
			if (v[j] != v[v.size() - 1 - j]) {
				flag = false;
				break;
			}
		}
		if (flag) ans += 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

void yakusuu_zeta(int n,ll*dp){
	//g(x)=Σ[k|x]f(k)のとき、fからgを作る
	for(int i=n-1;i>0;i--)if(dp[i])repp(j,2*i,n+1,i)dp[j]+=dp[i];
}

int n;
int a[200010];
ll aa[1000010];
int main(){
	scanf("%d",&n);
	rep(i,0,n)scanf("%d",a+i);
	rep(i,0,n)aa[a[i]]++;
	yakusuu_zeta(1000000,aa);

	int ans=0;
	rep(i,0,n)if(aa[a[i]]==1)ans++;
	printf("%d",ans);
}

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

int a[105][105];

int main() {
	int h, w, n; cin >> h >> w >> n;

	int w_cnt = 0, h_cnt = 0;
	bool rev = false;
	for (int i = 0; i < n; i++) {
		int tmp; cin >> tmp;

		while (tmp > 0) {
			if (w_cnt == w||w_cnt==-1){
				rev = !rev;
				h_cnt++;
				w_cnt += w_cnt == w ? -1 : 1;
			}
			a[h_cnt][w_cnt] = i + 1;
			tmp--;
			w_cnt += (!rev ? 1 : -1);
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << a[i][j] << ' ';
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 384
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        
        long[] l = new long[87];
        l[0] = 2;
        l[1] = 1;
        for(int i=2; i<=N; i++){
            l[i] = l[i-1] + l[i-2];
        }
        
        System.out.println(l[N]);
    }
}

Measured memory_bytes: 23892
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int a, b;
	char c;
	double rad = M_PI / 2.0, x = 0, y = 0;
	for (cin >> a >> c >> b; a || b; cin >> a >> c >> b) {
		x += a*cos(rad);
		y += a*sin(rad);
		rad -= (b / 180.0 * M_PI);
		/*
		if (rad < -M_PI) {
			rad += (2 * M_PI);
		}
		else if (rad>M_PI) {
			rad -= (2 * M_PI);
		}*/
	}
	cout << int(x) << endl << int(y) << endl;
	return 0;
}

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

vector<int> buf;

int black(vector<vector<char>> c, int h, int w) {
    int count = 0;
    rep(i, h) {
        rep(j, w) {
            if (c[i][j] == '#') count++;
        }
    }
    return count;
}

void f(int i, int n, int d, vector<vector<int>> &vec) { // n進数でdigit桁の数を全列挙
    buf.resize(d);
    if (i == d) {
        vector<int> x;
        for (int a : buf) {
            x.push_back(a);
        }
        vec.push_back(x);
    } else {
        rep(j,n) {
            buf[i] = j;
            f(i+1,n,d,vec);
        }
    }
}

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h,vector<char>(w,'-'));
    rep(i, h) {
        rep(j, w) {
            cin >> c[i][j];
        }
    }

    vector<vector<int>> hw;
    f(0,2,h+w,hw);
    
    // rep(i, hw.size()) {
    //     rep(j, hw[i].size()) {
    //         cout << hw[i][j];
    //     }
    //     cout << endl;
    // }
    int ans = 0;
    rep(i, hw.size()) {
        vector<vector<char>> c_copy = c;
        rep(j, hw[i].size()) {
            if (hw[i][j] == 1) {
                if (j < h) {
                    rep(k, w) {
                        c_copy[j][k] = 'r';
                    }
                } else {
                    rep(k, h) {
                        c_copy[k][j-h] = 'r';
                    }
                }
            }
        }
        // rep(j, c_copy.size()) {
        //     rep(k, c_copy[j].size()) {
        //         cout << c_copy[j][k];
        //     }
        //     cout << endl;
        // }
        if (black(c_copy,h,w) == k) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3832
input_list = list(map(int, input().split(' ')))
n, x = input_list[0], input_list[1]

weight_list = [int(input()) for _ in range(n)]
sum_weight = sum(weight_list)
min_weight = min(weight_list)
rest = x - sum_weight
total_num = n + rest // min_weight

print(total_num)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  ll a;
  ll cnt4 = 0, cntodd = 0;
  rep(i, N){
    cin >> a;

    if(a % 2 == 1)
      cntodd++;
    if(a % 4 == 0)
      cnt4++;
  }

  if(cntodd <= cnt4)
    cout << "Yes" << endl;
  else if((cntodd == cnt4 + 1) && (cntodd + cnt4 == N))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


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

int main(){
	string s1,s2;cin>>s1>>s2;
	int ans=0;
	for(int i=0;i<s1.size();i++)
		if(s1[i]==s2[i])
			ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
a=[]
for x in input().split(" "):
    a.append(int(x))

i=0
j=0
b=[]
bn=[]
bb=[]
bc=[]

while i < a[0] - a[3]:
    bb = ["0"] * (a[1] - a[2])
    bc = ["1"] * a[2]
    bn = bb + bc
    b.append(bn)
    i += 1
    bb = []
    bc = []
while i < a[0]:
    bb = ["1"] * (a[1] - a[2])
    bc = ["0"] * a[2]
    bn = bb + bc
    b.append(bn)
    i += 1
    bb = []
    bc = []

for x in b:
    print(''.join(x))

Measured memory_bytes: 11892
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
 
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

a, b, c, k = Is()

a = min(a, k)
k -= a

b = min(b, k)
k -= b

c = min(c, k)
k -= c

print(a-c)

Measured memory_bytes: 27040
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    lint M;
    cin >> N >> M;
    VEC(int) A(N);
    READVEC(A);
    sort(ALL(A));

    auto count = [&](int H) {
        lint ret = 0;
        FOR(i, 0, N) {
            if (A[i] + A[i] < H)
                continue;
            ret++;
            int mn = max(H - A[i], 0);
            // how many in A[0 ... (i - 1)] greater >= mn
            int cnt = (BEGIN(A) + i) - lower_bound(ALL(A), mn);
            ret += cnt * 2;
        }

        return ret;
    };

    int lo = 2, hi = 200000;
    while (hi - lo > 1) {
        int md = (lo + hi) / 2;
        if (count(md) >= M)
            lo = md;
        else
            hi = md - 1;
    }

    if (count(hi) < M)
        hi = lo;

    // hi is the smallest happiness value s.t there are atleast M pairs
    // with atleast that value.

    lint Mbigger = count(hi + 1);
    lint ret = (M - Mbigger) * hi;

    VEC(lint) C(N + 1, 0LL);
    FOR(i, 0, N) {
        C[i + 1] = C[i] + A[i];
    }

    hi++;
    FOR(i, 0, N) {
        if (A[i] + A[i] < hi)
            continue;
        ret += 2 * A[i];
        int j = lower_bound(ALL(A), max(0, hi - A[i])) - BEGIN(A);
        // Need (A[j] + A[i]) + ... + (A[i - 1] + A[i])
        ret += (i - j) * 2LL * A[i];
        ret += 2LL * (C[i] - C[j]);
    }

    cout << ret << endl;
    return 0;
};

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

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

  int prev_h;
  cin >> prev_h;

  int max_h = prev_h;
  for (int i = 0; i < N - 1; i++) {
	int h;
	cin >> h;

	if (h < max_h - 1) {
	  cout << "No" << endl;
	  return 0;
	} 

	max_h = max(max_h, h);
  }

  cout << "Yes" << endl;


  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
	int n;
	cin >> n;
	vector<ll> h(n);
	rep(i, n) cin >> h[i];

	int ans = 0, now = 0;
	rep(i, n-1) {
		if (h[i] >= h[i + 1]) {
			now++;
		}
		else {
			ans = max(ans, now);
			now = 0;
		}
	}
	ans = max(ans, now);
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
using namespace std;
int main() {
	int h, a;
	cin >> h >> a;
	if (h % a == 0) {
		cout << h / a << endl;
	}
	else {
		cout << h / a + 1 << endl;
	}
	return 0;
}



Measured memory_bytes: 256
import sys
#import numpy as np
#from collections import defaultdict
#import math
#from collections import deque

input = sys.stdin.readline



def main():


    N ,K= map(int,input().split())
    H = list(map(int,input().split()))
    H = [0] + H
    dp= [0] *(N+1)
    dp = [10**5] * (N + 1)
    dp[1] = 0

    for i in range(2, N + 1):
        way =[10**10]*(K+2)
        for j in range(1, K+1):
            if j<i:
                way[j]=(dp[i-j]+abs(H[i]-H[i-j]))
        dp[i] = min(way)


    print(dp[N])





if __name__ == "__main__":
    main()

Measured memory_bytes: 86184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n, 0);
    ll sum = 0;
    ll res = 0;
    rep1(i, n){
        cin >> a[i];
        res += a[i]*a[i]%MOD;
        res %= MOD;
        sum += a[i];
        sum %= MOD;
    }
    ll ans = (sum * sum - res) % MOD;
    cout << (ans * modinv(2, MOD)%MOD) << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 4844
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__ == "__main__":
    n,m = map(int,input().split())
    if n == 1 and m == 1:
        print(1)
    elif n == 1:
        print(m-2)
    elif m == 1:
        print(n-2)
    else:
        print((n-2)*(m-2))

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

using ll = long long;
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n+1), b(n);
	for(int i = 0; i <= n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	ll ans = 0;
	for(int i = 0; i < n; i++){
		int r = min(a[i], b[i]);
		ans += r;
		a[i] -= r;
		b[i] -= r;
		int s = min(a[i+1], b[i]);
		ans += s;
		a[i+1] -= s;
		b[i] -= s;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(0);
        String s1 = sc.next();
        if (s1.equals("Vacant")) {
            return;
        }
        System.out.println(n - 1);
        String s2 = sc.next();
        if (s2.equals("Vacant")) {
            return;
        }
        int left = -1;
        int right = n;
        while (right - left > 1) {
            int mid = left + (right - left) / 2;
            System.out.println(mid);
            String s = sc.next();
            if (s.equals("Vacant")) {
                return;
            }
            if (mid % 2 == 0 && s.equals(s1)
                || mid % 2 != 0 && s.equals(s2)) {
                left = mid;
            } else {
                right = mid;
            }
        }

    }

}


Measured memory_bytes: 36064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);

        double sum = (arr[0] + arr[1]) / (double) 2;
        for (int i = 2; i < n; i++) {
            sum = (sum + arr[i]) / (double) 2;
        }

        System.out.println(sum);
    }


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

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 22996