akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public long NapSac(long N, int[] buyrate, int[] sellrate){
            long[] DP = new long[N+1];
            for(long i = 0;i<=N;i++){
                DP[i] = i;
            }
            for(long i = 0;i<=N-1;i++){
                for(int j=0;j<3;j++){
                    if(buyrate[j]>=sellrate[j]){
                        continue;
                    }
                    if(i + buyrate[j] > N){
                        continue;
                    }
                    DP[i + buyrate[j]] = Max(DP[i + buyrate[j]], DP[i] + sellrate[j]);
                }
            }
            return DP.Max();
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadLong;
            int[] Arate  = cin.ReadIntArray(3);
            int[] Brate  = cin.ReadIntArray(3);
            var donguriAB = NapSac(N,Arate,Brate);
            var ans = NapSac(donguriAB,Brate,Arate);
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator =' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 206432
#include<bits/stdc++.h>
using namespace std;
signed main(){
    string s;
    cin>>s;
    int p=0;
    int g=0;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(i<=(n+1)/2-1&&s[i]=='p'){
            p++;
        }
        else if(i>(n+1)/2-1&&s[i]=='g'){
            g++;
        }
    }
    cout<<g-p<<endl;
}


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

import numpy as np

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

start = np.zeros(n)
end = np.zeros(n)
for a, b in ab:
    if a == 1:
        start[b-1] = 1
    if b == n:
        end[a-1] = 1

ans = np.any((start * end))
print("POSSIBLE" if ans else "IMPOSSIBLE")


Measured memory_bytes: 62284
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
#define REP(i, d, n) for(int i=(d); i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;
int main() {

    int h, w;
    cin >> h >> w;
    char s[50][50];
    rep(i, h){
        rep(j, w){
            cin >> s[i][j];
        }
    }

    rep(i, h){
        rep(j, w){
            if(i==0 && j==0){
                if(s[i][j] == '#'){
                    if(s[i+1][j] != '#' && s[i][j+1] != '#'){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
            else if(i==0 && j==w-1){
                if(s[i][j] == '#'){
                    if(s[i+1][j] != '#' && s[i][j-1] != '#'){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
            else if(i==h-1 && j==0){
                if(s[i][j] == '#'){
                    if(s[i-1][j] != '#' && s[i][j+1] != '#'){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
            else if(i==h-1 && j==w-1){
                if(s[i][j] == '#'){
                    if(s[i-1][j] != '#' && s[i][j-1] != '#'){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
            else if(i == 0){
                if(s[i][j] == '#'){
                    if(s[i+1][j] != '#' && s[i][j+1] != '#' && s[i][j-1] != '#'){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
            else if(i == h-1){
                if(s[i][j] == '#'){
                    if(s[i-1][j] != '#' && s[i][j+1] != '#' && s[i][j-1] != '#'){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
            else if(j == 0){
                if(s[i][j] == '#'){
                    if(s[i+1][j] != '#' && s[i-1][j] != '#' && s[i][j+1] != '#'){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
            else if(j == w-1){
                if(s[i][j] == '#'){
                    if(s[i+1][j] != '#' && s[i-1][j] != '#' && s[i][j-1] != '#'){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
            else{
                if(s[i][j] == '#'){
                    if(s[i+1][j] != '#' && s[i-1][j] != '#' && s[i][j+1] != '#' && s[i][j-1] != '#'){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
(function(input) {
  var lines = input.split("\n");
  var colors = [
    ['black', 0x00, 0x00, 0x00],
    ['blue', 0x00, 0x00, 0xff],
    ['lime', 0x00, 0xff, 0x00],
    ['aqua', 0x00, 0xff, 0xff],
    ['red', 0xff, 0x00, 0x00],
    ['fuchsia', 0xff, 0x00, 0xff],
    ['yellow', 0xff, 0xff, 0x00],
    ['white', 0xff, 0xff, 0xff],
  ];
  for (var i = 0; i < lines.length; ++i) {
    if (lines[i][0] === '#') {
      var best_color;
      var min_d = 3 * 256 * 256 + 1;
      var r = parseInt(lines[i].substr(1, 2), 16);
      var g = parseInt(lines[i].substr(3, 2), 16);
      var b = parseInt(lines[i].substr(5, 2), 16);
      for (var j = 0; j < colors.length; ++j) {
        var d = Math.pow(r - colors[j][1], 2) + Math.pow(g - colors[j][2], 2) + Math.pow(b - colors[j][3], 2);
        if (d < min_d) {
          min_d = d;
          best_color = colors[j][0];
        }
      }
      console.log(best_color);
    }
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 18132
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
vector<ll> C[404];
ll vv[404];
int R[404];
map<ll,int> B[5];

ll getkey(vector<ll> v){
    ll r=1LL<<60;
    rep(i,4){
        rotate(v.begin(),v.begin()+1,v.end());
        r=min(r,v[0]*1000000000+v[1]*1000000+v[2]*1000+v[3]);
    }
    return r;
}

ll dfs(int cur, int n1, int n2, int n4){
    if(cur==0) return 1;
    ll ret=0;
    if(n1) ret+=n1*dfs(cur-1,n1-1,n2,n4);
    if(n2) ret+=2*n2*dfs(cur-1,n1,n2-1,n4);
    if(n4) ret+=4*n4*dfs(cur-1,n1,n2,n4-1);
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    rep(i,N){
        vector<ll> v(4,0);
        rep(j,4) cin>>v[j];
        C[i]=v;
        vv[i]=getkey(C[i]);
        R[i]=1;
        if(C[i][0]==C[i][2]&&C[i][1]==C[i][3]){
            R[i]=2;
            if(C[i][0]==C[i][1]) R[i]=4;
        }
        B[R[i]][vv[i]]++;
    }
    
    ll ret=0;
    rep(x,N){
        B[R[x]][vv[x]]--;
        for(int y=x+1;y<N;y++){
            B[R[y]][vv[y]]--;
            rep(z,4){
                map<ll,int> mp;
                mp[getkey({C[x][1],C[x][0],C[y][1],C[y][0]})]++;
                mp[getkey({C[x][2],C[x][1],C[y][0],C[y][3]})]++;
                mp[getkey({C[x][3],C[x][2],C[y][3],C[y][2]})]++;
                mp[getkey({C[x][0],C[x][3],C[y][2],C[y][1]})]++;
                
                ll tmp=1;
                for(auto r:mp){
                    tmp*=dfs(r.second,B[1][r.first],B[2][r.first],B[4][r.first]);
                    if(tmp==0)break;
                }
                ret += tmp;
                rotate(C[y].begin(),C[y].begin()+1,C[y].end());
            }
            B[R[y]][vv[y]]++;
        }
    }
    cout1(ret);
}

Measured memory_bytes: 60288
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
r,g,b = LI()
if (g*10+b)%4 == 0:
    print("YES")
else:
    print("NO")
"""
#B
n = I()
a = LI()
print(max(a)-min(a))
#C
"""
f = [0]
for i in range(1,400):
    f.append(0)
for i in range(400,800):
    f.append(1)
for i in range(800,1200):
    f.append(2)
for i in range(1200,1600):
    f.append(3)
for i in range(1600,2000):
    f.append(4)
for i in range(2000,2400):
    f.append(5)
for i in range(2400,2800):
    f.append(6)
for i in range(2800,3200):
    f.append(7)
for i in range(3200,4801):
    f.append(-1)
n = I()
a = LI()
k = [1 for i in range(8)]
s = 0
t = 0
for i in a:
    if f[i] >= 0:
        if k[f[i]]:
            k[f[i]] = 0
            s += 1
    else:
        t += 1
print(max(s,1),min(s+t,n))
"""

#D
"""
n = I()
s = S()
ans = []
k = 0
for i in range(n):
    if s[i] == ")":
        k += 1
    else:
        if k > 0:
            ans += ["("]*k
            k = 0
        k -= 1
if k < 0:
    ans += [")"]*(-k)
else:
    ans = ["("]*k+ans
i = 0
if len(ans) == 0:
    for i in s:
        print(i,end = "")
else:
    while ans[i] == "(":
        i += 1
        if i == len(ans):break
    for j in range(n):
        ans.insert(i+j,s[j])
    for i in ans:
        print(i,end = "")
print()
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38384
#include <stdio.h>

int p[10001];

int main(void)
{
	int i, k, v,n;
	for (i = 0; i <= 10000; i++){
		p[i] = 1;
	}
	for (i = 2; i*i <= 10000; i++){
		if (p[i]){
			for (k = 2 * i; k <= 10000; k += i){
				p[k] = 0;
			}
		}
	}
	while (1){
		scanf("%d", &n);
		if (n == 0)
			break;
		for (i = n; i >1; i--){
			if (p[i] * p[i - 2] == 1)
				break;
		}
		if (n >= 5)
			printf("%d %d\n", i - 2, i);
	}
        return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

int N, W;
int value[110], weight[110];
int dp[110][10010];

void print(int cnt, bool ok) {
   printf("---------- (%d, %c) ----------\n", cnt, (ok?'T':'F'));
   rep (i, 0, N+1) {
      rep (j, 0, W+1) {
         printf("%3d", dp[i][j]);
      }
      puts("");
   }
}

int main() {
   cin >> N >> W;
   for (int i = 0; i < N; i++) {
      cin >> value[i] >> weight[i];
   }

   for (int i = 0; i < W+1; i++) {
      dp[0][i] = 0;
   }

   for (int qty = 0; qty < N; qty++) { // qty個の品物を入れる
      for (int weightLim = 0; weightLim <= W; weightLim++) { // 重さの上限
         if (weight[qty] <= weightLim) { // qty個目の品物が重さ上限よりも軽い
            dp[qty+1][weightLim] = max(dp[qty][weightLim-weight[qty]] + value[qty], 
                                 dp[qty][weightLim]);
         } else {
            dp[qty+1][weightLim] = dp[qty][weightLim]; // 繰り下げ
         }
      }
   }

   cout << dp[N][W] << endl;

   return 0;
}


Measured memory_bytes: 7024
#include<stdio.h>

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

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a>> b;
    c=b-a;
    int sum=0;
    for(int i=c;i>0;i--){
        sum+=i;
    }
    cout << sum-b << endl;
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int,input().split())

ans = 100000000000000000000000000

AB = C * 2

for ab in range(100000 + 1):
  x = 0
  if X - ab > 0:
    x = X - ab
  
  y = 0
  if Y - ab > 0:
    y = Y - ab
  
  d = (x * A) + (y * B) + (AB * ab)

  if ans > d:
    ans = d

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
int main(void){
    long int i;
    long long int j, N, X;
    j=100.0;
    scanf("%lld" , &X);
    for( i=0 ; i<4000 ; i++){
        j=j+j/100;
        if(X<=j){
            //printf("%f\n" ,100.0*pow(1.01,i+1));
            printf("%ld" ,i+1);
            break;
        };
    };

    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
ll c;
ll x[maxn];
ll v[maxn];

ll a[maxn], b[maxn];
ll suffix_b[maxn];
ll prefix_a[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>c;
    for (int i=1; i<=n; i++) {
	cin>>x[i]>>v[i];
    }

    x[n+1]=c;

    for (int i=n; i>=1; i--) {
	b[i]=b[i+1] + (v[i] - (x[i+1]-x[i]));
    }
    for (int i=n; i>=1; i--) {
	suffix_b[i] = max(b[i], suffix_b[i+1]);
    }
    

    for (int i=1; i<=n; i++) {
	a[i] = a[i-1] + (v[i] - (x[i]-x[i-1]));
    }
    for (int i=1; i<=n; i++) {
	prefix_a[i] = max(prefix_a[i-1], a[i]);
    }



    ll ans = 0;
    for (int i=0; i<=n; i++) {
	ll cur = a[i];
	ans = max(ans, cur);
	cur -= x[i];
	cur += suffix_b[i+1];
	ans = max(ans, cur);
    }

    for (int i=n; i>0; i--) {
	ll cur = b[i];
	ans = max(cur, ans);
	cur -= (c-x[i]);
	cur += prefix_a[i-1];
	ans = max(ans, cur);
    }

    out(ans);
    return 0;
}


Measured memory_bytes: 15488
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/

void build(){

}
int n;
void init(){
  n = getint();
}
void solve(){
  int cnt = 0;
  while( n -- )
    cnt += getint() % 2;
  if( cnt % 2 )
    puts( "NO" );
  else puts( "YES" );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n; cin >> n;
  string s; cin >> s;

  vector<int> W(n+1, 0), R(n+1, 0);
  for(int i = 0; i < n; i++){
    W[i+1] = W[i] + (s[i] == 'W');
    R[i+1] = R[i] + (s[i] == 'R');
  }

  if(W[n] == n || R[n] == n){
    cout << 0 << endl;
    return 0;
  }

  int ans = INF;
  for(int i = 0; i < n; i++){
    int w = W[i], r = R[n] - R[i];
    ans = min(ans, max(r + max(0LL, r - w), w + max(0LL, w - r)));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6748
import heapq
import sys
N, M = map(int, input().split())
B = [[] for _ in range(M + 1)]
for _ in range(N):
    a, b = map(int, sys.stdin.readline().split())
    if a <= M:
        B[a].append(b)

ans = 0
q = []
for i in range(1, M + 1):
    for b in B[i]:
        heapq.heappush(q, -b)
    if q:
        ans += -(heapq.heappop(q))
print(ans)

Measured memory_bytes: 24312
#include <stdio.h>

int main() {
	double a, b, c, d, e, f;
	double x, y;
	/* ax + by = c
	   dx + ey = f */

	while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF) {
		x = (e * c - b * f) / (e * a - b * d) + 0.00001;
		y = (d * c - a * f) / (d * b - a * e) + 0.00001;

		printf("%.3f %.3f\n", x, y);
	}

	return 0;
}

Measured memory_bytes: 656
n,k = map(int, input().split())
a = list(map(int, input().split()))

def check(x):
    cnt = 0
    for ai in a:
        cnt += (ai-1)//x
        if cnt > k:
            return False
    return True

left = 0
right = 10**9+1
while right-left>1:
    mid = (right+left)//2
    if check(mid):
        right=mid
    else:
        left=mid
print(right)

Measured memory_bytes: 93956
//abc064_b Traveling AtCoDeer Problem


#include <bits/stdc++.h>
using namespace std;

namespace
{
int a[ 110 ];
}

int main()
{
int i;
int N;

	cin >> N;
	for( i = 0; i < N; i++ ) cin >> a[ i ];

	sort( a, a + N );

	cout << a[ N - 1 ] - a[ 0 ] << endl;

	return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
int n, d;
void solve() {
    cin >> n;
    set<int> kmochi;
    for (int i = 0; i < n; i++) {
        cin >> d;
        kmochi.insert(d);
    }
    cout << kmochi.size() << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm> // min()
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <tuple>
#include <random>

#include <climits> // INT_MAX
#include <cmath> // ceil()
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define b2e(vec) vec.begin(), vec.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int type_num = 26;

random_device rnd;     // 非決定的な乱数生成器を生成
mt19937 mt(rnd());     //  メルセンヌ・ツイスタの32ビット版、引数は初期シード値
uniform_int_distribution<> rand26(0, 25);        // [0, 99] 範囲の一様乱数


int decrease_satis(vector<int> & c, vector<int> & last, int d) {
	int y = 0;
	rep(i, type_num) y += c[i] * (d + 1 - last[i]);
	return y;
}


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

	vector<int> c(type_num);
	rep(i, type_num) cin >> c[i];

	vector<vector<int>> s(D, vector<int>(type_num));
	rep(i, D) rep(j, type_num) cin >> s[i][j];

	//vector<int> t(D);
	//rep(i, D) {
	//	cin >> t[i];
	//	t[i]--;
	//}
	rep(i, D) cout << rand26(mt) + 1 << endl;


	//vector<int> last(type_num);
	//int satis = 0;

	//rep(i, D){
	//	last[t[i]] = i + 1;
	//	satis += s[i][t[i]] - decrease_satis(c, last, i);
	//}
	//cout << satis << endl;
}

Measured memory_bytes: 3676
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);
parse_tuple!(A, B, C, D);
parse_tuple!(A, B, C, D, E);

// ===

fn main() {
    let s: String = read();
    let t: String = read();

    let mut a = s.into_bytes();
    let mut b = t.into_bytes();
    a.sort();
    b.sort();
    b.reverse();

    if a.cmp(&b) == Ordering::Less {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    strings = input()
    answers=[]
    counter=0

    for string in strings:
        if "A" in string or "C" in string or "G" in string or "T" in string:
            counter+=1
        else:
            answers.append(counter)
            counter=0
    print(max(answers))


if __name__=="__main__":
    main()

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

int main() {
    string s;
    cin >> s;
    string s_ = s;
    reverse(s_.begin(), s_.end());
    if (s_[0] == 's') {
        cout << s + "es" << endl;
    } else {
        cout << s + "s" << endl;
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) (int)s.size()
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
const int MOD=1e9+7;
void solve()
{
fastio
int n;
cin>>n;
vi v;
for(int i=0;i<n;i++)
{
	int x,y;
	cin>>x>>y;
	if(x==y)
	v.pb(i);
}
if(size(v)<3)
cout<<"No";
else
{
	for(int i=0;i<size(v)-2;i++)
	{
		if(v[i]+1==v[i+1]&&v[i+2]==v[i+1]+1)
		{
			cout<<"Yes";
			return ;
		}
	}
	cout<<"No";
}
}
int main()
{
//code
fastio
int t;
t=1;
while(t--)
{
solve();
cout<<endl;
}
}


Measured memory_bytes: 3640
#include <stdio.h>
int abs(int a){
  if(a<0){
    return (-1)*a;
  }else{
    return a;
  }
}
int main(){
  int x,y;
  scanf("%d%d", &x, &y);
  int ans = 2000000001;
  if(y>=x){
    ans = y-x;
  }
  if(-y>=x){
    if(-y-x+1<ans){
      ans = -y-x+1;
    }
  }
  if(y>=-x){
    if(y+x+1<ans){
      ans = y+x+1;
    }
  }
  if(-y>=-x){
    if(-y+x+2<ans){
      ans = -y+x+2;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n;
int a[10101],b[10101];

int main(){
	cin>>n;
  rep(i,n)cin>>a[i];
  int res=1;
  rep(i,n){
    int cnt=0;
    repl(j,-1,2){
      if((a[i]+j+200)%2!=0)cnt++;
    }
    res*=cnt;
  }
  cout<<pow(3,n)-res<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>

#define Rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())

#define eb emplace_back
#define dbg(x) cout<<#x" = "<<((x))<<endl
#define fs first
#define sc second
     
using namespace std;
     
     
typedef long long ll;
typedef pair<ll, ll> P;
     
int main(){
  ll N, K; cin >> N >> K;
  vector<ll> t(N), d(N);
  Rep(i, N){
    cin >> t[i] >> d[i];
    t[i]--;
  }
  vector<P> p(N);
  Rep(i, N) p[i] = P(d[i], t[i]);
  Sort(p);
  Reverse(p);
    
  ll tmp = 0;
  vector<ll> cnt(N, 0);
  ll v = 0;
  priority_queue<ll, vector<ll>, greater<ll>> que;
  Rep(i, K){
    tmp += p[i].fs;
    cnt[p[i].sc]++;
    if(cnt[p[i].sc] >= 2) que.push(p[i].fs);
    else v++;
  }
  ll ans = tmp + v * v;
 
  for(ll i = K; i < N; ++i){
    if(que.empty()) break;
    if(cnt[p[i].sc] >= 1) continue;
    cnt[p[i].sc]++;
    ll a = que.top(); que.pop();
    tmp -= a;
    tmp += p[i].fs;
    v++;
    ans = max(ans, tmp + v * v);
  }
  cout << ans << endl;
 
  return 0;
}


Measured memory_bytes: 4860
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

inline int read () {
    int ret = 0, t = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') t = -1, c = getchar();
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
    return ret * t;
}

int n, k;
double a[200200];

int main () {
    n = read(), k = read();
    int i, j;
    double Max = 0;
    for (i = 1; i <= n; i++) a[i] = read(), a[i] = (1 + a[i]) * a[i] / 2 / a[i];
    double s = 0;
    for (i = 1; i < k; i++) s += a[i];
    for (i = k; i <= n; i++) {
        s += a[i];
        s -= a[i - k];
        Max = max(Max, s);
    }
    printf("%.8lf\n", Max);
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define x first
#define y second
#define PII pair<int,int>
#define show(x) cerr << #x << " = " << x << '\n'
typedef long long ll;

using namespace std;
int main(int argc,char *argv[]){
    int a, b;
    cin >> a >> b;
    int c = 10 * b;
    int d2 = (int)(12.5 * (a + 1) + 1);
    for(int i = c;i <= d2;i ++){
        int e = (int)(i * 0.08);
        int f = (int)(i * 0.1);
        if(e == a && f == b){
            printf("%d\n",i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

void itoa(int x, int radix, char* dst) {
  char buf[16] = {};
  char *p = buf + 14;
  int sign = 0;
  
  if (x < 0) {
    x = -x;
    sign = 1;
  }
  
  do {
    *p = "0123456789abcdefghijklmnopqrstuvwxyz"[x % radix];
    --p;
    x /= radix;
  } while (x > 0);
  
  if (sign) {
    *p = '-';
    --p;
  }
  strcpy(dst, p + 1);
}

int main(void)
{
  char str[64];
  int n;
  while (scanf("%d", &n), ~n) {
    itoa(n, 4, str);
    printf("%s\n", str);
  }

  return (0);
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
using graph = vector<vector<int>>;

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int a, b; cin >> a >> b;
	cout << a * b << endl;
} 

Measured memory_bytes: 3656
#include <bits/stdc++.h>
int main() {
	int a, v, b, w, t;
	scanf("%d%d%d%d%d", &a, &v, &b, &w, &t);
	puts(abs(a-b)<=1ll*t*(v-w)?"YES":"NO");
	return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;

#define fori(x) for(int i=0;i<x;++i)
#define forj(x) for(int j=0;j<x;++j)

constexpr int maximum = 110000;

int main() {
	int a,p;
	cin >> a >> p;
	cout << (a * 3 + p) / 2;
	return 0;
}

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

int main(){
    int n, a;
    cin >> n >> a;
    string res = "No";
    if (n%500 <= a) res = "Yes";
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<i64> H;
  tools::read(H, N);

  std::reverse(H.begin(), H.end());
  i64 height = H.front();
  for (const i64& H_i : H) {
    if (H_i > height + 1) goto FAILED;
    height = std::min(height, H_i);
  }

  std::cout << "Yes" << std::endl;
  return 0;

FAILED:
  std::cout << "No" << std::endl;
  return 0;
}

Measured memory_bytes: 1024
# input
n = int(input())
t, a = map(int, input().split())
hs = list(map(int, input().split()))

# 1st point set
ans = 0
ans_diff = float("inf")

# check all point
for i in range(n):
    i_diff = abs(t - hs[i] * 0.006 - a)
    if i_diff < ans_diff:
        ans = i + 1
        ans_diff = i_diff
print (ans)


Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
  int n,m=1;
  int count;
  scanf("%d",&n);
  while(n>0){
    n=n/2;
  count++;
  }
  while(count>1){
  m=2*m;
  count--;}
  printf("%d",m);
  return(0);
}
  

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	long long n, br = 1;
	string s;
	cin >> n;
	cin >> s;
	for(long long i = 1; i < n; ++i) if(s[i] != s[i - 1]) ++br;
	cout << br;

	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;

double ad = 0;
int sum = 0;
double dis[10][10];

void makead(vector<int>& v){
  for(int i = 0; i < v.size() - 1; i++){
    //cout << v[i] << "->" << v[i + 1] << "\n";
    //cout << dis[v[i]][v[i + 1]] << endl;
    ad += dis[v[i]][v[i + 1]];
  }
  return;
}

void makej(vector<int>& v, int n, int c){
  if(c >= n){
    //for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << endl;
    makead(v);
    sum++;
    return;
  }
  for(int i = 0; i < n; i++){

    //cout << "c:" << c << " i:" << i << endl;
    //for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << endl;

    if(find(v.begin(), v.end(), i) != v.end()) continue;
    v.push_back(i);
    makej(v, n, c + 1);
    v.pop_back();
  }
}

void solve(){
  int n; cin >> n;
  int x[n], y[n];
  for(int i = 0; i < n; i++){
    cin >> x[i] >> y[i];
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      dis[i][j] = pow(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2), 0.5);
    }
  }
  vector<int> v;
  makej(v, n, 0);
  //cout << ad << " " << sum << endl;
  cout << fixed << setprecision(6) << ad / sum << endl;
  return;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>

using namespace std;

int main(){
    string str,buf;
    int m,h;
    while(cin >> str && (str != "-")){
        scanf("%d",&m);
        for(int i = 1;i <= m;i++){
            scanf("%d",&h);
            buf = str.substr(0,h);
            str.erase(0,h);
            str += buf;
        }
        cout << str << endl;
    }
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vl;typedef vector<vl> vvl;typedef pair<ll,ll> pl;typedef vector<pl> vp;const ll INF=1001001001;const ll LINF=1001001001001001001;const ll D4[]={0,1,0,-1,0};const ll D8[]={0,1,1,0,-1,-1,1,-1,0};template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    if(S[2]==S[3]&&S[4]==S[5]){
        cout<<YES<<endl;
    }else{
        cout<<NO<<endl;
    }
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long,long long>
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
bool prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
int a[10000005]={0};
int divisor(int n){
    for(int i=1;i<=n;i++){
    	for(int j=i;j<=n;j+=i){
    		a[j]++;
    	}
    }
    return a[n];
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    divisor(n);
    int sum=0;
    for(int i=1;i<=n;i++){
        sum+=(i*a[i]);
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 81732
//mangesh2102000

#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000000

int n,k;
int h[100005];
int dp[100005];


void solve(int t)
{
    cin >> n >> k;

    for(int i=1;i<=n;i++)
    {
        cin >> h[i];
    }

    dp[1]=0;

    for(int i=2;i<=n;i++)
    {
    	dp[i] = 1e18;
	    for(int j=1;j<=k;j++)
	    {
	        if(i-j >= 1)
	            dp[i] = min( dp[i], dp[i-j] + abs(h[i]-h[i-j]) );
	    }

    }

    cout << dp[n];
    //cout << "Case #" << t << ": " << ;
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define INF 200005

//-------------------------------------------------------------------------------------------------------------------
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "  "; err(++it, args...);cout << endl; }
//-------------------------------------------------------------------------------------------------------------------

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    cin >> n;
    string a;
    cin >> a;
    int left=0;
    int right=n-1;
    int ins=0;
    while(true)
    {
    	if(a[right]=='W')
    	{
    		right--;
    	}
    	if(a[left]=='R')
    	{
    		left++;
    	}
    	if(left>=right)
    	{
    		break;
    	}
    	if(a[left]=='W' && a[right]=='R')
    	{
    		ins++;
    		left++;
    		right--;
    	}
    	if(left>=right)
    	{
    		break;
    	}
    }
    cout << ins << "\n";
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;cin>>N;
    int H[N];int dp[N];
    for(int i=0;i<N;i++){
        cin>>H[i];
    }dp[0]=0;dp[1]=abs(H[1]-H[0]);
    for(int j=2;j<N;j++){
        dp[j]=min(dp[j-1]+abs(H[j]-H[j-1]),dp[j-2]+abs(H[j]-H[j-2]));
    }cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <cmath>
#include <math.h>
#include <ctime>
#include <cstring>
#include <climits>
#include <sstream>
#include <array>
#include <tuple>
#include <set>
#include <iterator>
#include <cstdio>
#include <string>
#include <stack>
#include <valarray>
#include <utility>
#include <iomanip>
#include <list>
#include <numeric>
#include <regex>
#include <map>
#include <queue>
#include <deque>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll          long long
#define PI          3.1415926535
#define pb          push_back
#define ins         insert
#define INF         LLONG_MAX
#define mk          make_pair
#define lb(v,x)     lower_bound(all(v),x)
#define ub(v,x)     upper_bound(all(v),x)
#define ff          first
#define ss          second
#define rev         reverse
#define uset        unordered_set
#define umap        unordered_map
#define endl        "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a)       (ll)a.size()
#define double      long double
#define minpq       priority_queue <ll,vector<ll>,greater<ll> > 
#define fill(x,y)   memset(x,y,sizeof(x))
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define MOD         1000000007 //1e9+7
#define bp(n)       __builtin_popcountll(n)
#define mxt(a)      *(max_element(a.begin(),a.end()))
#define mnt(a)      *(min_element(a.begin(),a.end())
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i, a, b) for(ll i = (a); i<= (b); ++i)
#define trav(a, x) 	 for(auto &a : x)
#define re(i,n)      for(ll i = 0; i < n; ++i) 
const ll N = 2e5 + 7;
typedef pair<ll,ll>   pii;
typedef vector<pii>   vpii;
typedef vector<ll>    vll;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
template<typename T> T gcd(T a,T b){ if(a==0) return b; return gcd(b%a,a); }
template<typename T> T powm(T a,T b, ll m){T cnt=1; while(b>0){ if(b%2==1) cnt=(cnt*a)%m; b/=2; a=(a*a)%m; }return cnt%m;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll sqr(ll x) { return x * x;}
// always use 1ll*ans to avoid signed integer overflow; 
void prec(){

}
void solve(){
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll ans=min(k,a);
	k-=min(k,a);
	k-=min(k,b);
	ans-=min(k,c);
	cout<<ans<<endl;
}

int main()
{
    ios;
    int tc=1;
    //cin>>tc;
    prec();
    while(tc--)
    	solve();
    return 0; 
}


Measured memory_bytes: 3164
Public Class Program
  Shared Sub Main()
    Dim h As Long = Cin.Lng()
    Dim b As String = Convert.ToString(h, 2)
    Dim ans As Long = b.Length()
    ans = Math.Pow(2, ans) - 1
    Console.WriteLine(ans)
  End Sub
End Class

Public Class Cin
  Public Shared Function Str() As String
    Return Console.ReadLine().Trim()
  End Function
  Public Shared Function Int() As Integer
    Return Integer.Parse(Str())
  End Function
  Public Shared Function Lng() As Long
    Return Long.Parse(Str())
  End Function
  Public Shared Function Dbl() As Double
    Return Double.Parse(Str())
  End Function
  Public Shared Function StrArr(Optional separator As String = " ") As String()
    Return Str().Split(separator)
  End Function
  Public Shared Function IntArr(Optional separator As String = " ") As Integer()
    Return Array.ConvertAll(Of String, Integer)(StrArr(separator), AddressOf Integer.Parse)
  End Function
  Public Shared Function LngArr(Optional separator As String = " ") As Long()
    Return Array.ConvertAll(Of String, Long)(StrArr(separator), AddressOf Long.Parse)
  End Function
  Public Shared Function DblArr(Optional separator As String = " ") As Double()
    Return Array.ConvertAll(Of String, Double)(StrArr(separator), AddressOf Double.Parse)
  End Function
End Class

Measured memory_bytes: 13268
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#define N 200020
using namespace std;

int a[N], b[N];

int main(void)
{
    int n;
    int i;
    long long o;

    scanf("%d", &n);
    for(i = 0; i < n; i ++)
    {
        scanf("%d", &a[i]);
        b[a[i]] ++;
    }
    for(i = 1, o = 0; i <= n; i ++)
        o += (long long)b[i] * (b[i] - 1) / 2;
    for(i = 0; i < n; i ++)
        printf("%lld\n", o - (long long)b[a[i]] * (b[a[i]] - 1) / 2 + (long long)(b[a[i]] - 1) * (b[a[i]] - 2) / 2);

    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97
#define rep(i,n) for(unsigned int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  string s;
  cin>>s;
  rep(i,s.size()){
  if(s[i]=='?'){
 s[i]='D';
  }}
    cout<<s;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  long double r; cin >> r;
  cout << setprecision(10) << r*2*M_PI << endl;
  return 0;
}


Measured memory_bytes: 3796
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = Math.abs(sc.nextLong()); // 最初の座標
        long k = sc.nextLong(); // 回数
		long d = sc.nextLong(); // 移動距離
		long num = x / d;
		boolean plusOne = false;
		if(Math.abs(x - (x / d) * d) > Math.abs(x - (x / d + 1) * d))
		plusOne = true;
		if(plusOne && (num + 1) >= k){
		System.out.println(Math.abs(x - d * k));
		System.exit(0);
		}
		else if(plusOne == false && num >= k){
		System.out.println(Math.abs(x - d * k));
		System.exit(0);
		}
		else if(x - k * d == 0) {
			System.out.println("0");
			System.exit(0);
		}
		else if(plusOne == false && ((num % 2 == 0 && k % 2 == 0) || (num % 2 == 1 && k % 2 == 1))) {
			System.out.println(x - num * d);
			System.exit(0);
		}
		else if(plusOne && ((num % 2 == 0 && k % 2 == 1) || (num % 2 == 1 && k % 2 == 0))) {
			System.out.println(Math.abs(x - (x / d + 1) * d));
			System.exit(0);
		}
		else if(plusOne == false && ((num % 2 == 0 && k % 2 == 1) || (num % 2 == 1 && k % 2 == 0))) {
			long plusNum = Math.abs(Math.abs(x - num * d) + d);
			long minusNum = Math.abs(Math.abs(x - num * d) - d);
			System.out.println(Math.min(plusNum, minusNum));
		}
		else if(plusOne && ((num % 2 == 0 && k % 2 == 0) || (num % 2 == 1 && k % 2 == 1))) {
			long plusNum = Math.abs(Math.abs(x - (num + 1) * d) + d);
			long minusNum = Math.abs(Math.abs(x - (num + 1) * d) - d);
			System.out.println(Math.min(plusNum, minusNum));
		}
    }
}

Measured memory_bytes: 35604