akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <iterator>
#include <stdio.h>

int main() {
  std::map<int, int> num_seq;
  int num;
  scanf("%d", &num);
  int tmp;
  while (num--) {
  	scanf("%d", &tmp);
	num_seq[tmp]++;
  }
  
  if (num == 0) std::cout << 0 << '\n';
  else {
    int cnt = 0;
    for (auto elem : num_seq) {
        int diff = elem.second - elem.first;
      	if (diff == 0) continue;
    	cnt += (diff > 0 ? diff : elem.second);
  	}
  	std::cout << cnt << '\n';
  }
  
  return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(1e3)+5
#define fim '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << fim
#define debug2(x, y) cout << "DEBUG " << x << " " << y << fim
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< fim
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << fim
#define max3(x, y, z) max(x, max(y, z))
#define ull unsigned long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll MOD = 1e9+7;

int main() {
	int n;
	cin >> n;
	int vet[n+5];
	int s = 0;
	for(int i = 0; i < n; i++) {
		cin >> vet[i];
		s += vet[i];
	}
	ll s2 = (s+n-1)/n;
	s /= n;
	ll ans = 0, ans2 = 0;
	for(int i = 0; i < n; i++) {
		ans += (s-vet[i])*(s-vet[i]);
		ans2 += (s2-vet[i]) * (s2-vet[i]);
	}
	cout << min(ans2, ans) << endl;
}


Measured memory_bytes: 256
for i in range(100):
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    #print(h*w)
    #print(h)
    #print(w)
    for j in range(1,h+1):
        if j%2!=0:
            for k in range(1,w+1):
                if k%2!=0:
                    print('#',end='')
                elif k%2==0:
                    print('.',end='')
                
                
        elif j%2==0:
            for l in range(1,w+1):
                if l%2!=0:
                    print('.',end='')
                elif l%2==0:
                    print('#',end='')
            
            
            
        print('')
    print('')



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

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a < c && c < b) || (b < c && c < a)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
main :: IO ()
main = do
  a <- readLn :: IO Int
  b <- readLn :: IO Int
  c <- readLn :: IO Int
  x <- readLn :: IO Int
  print $ sum $ solve a b c x

solve a b c x = do
  i <- [0 .. a]
  j <- [0 .. b]
  k <- [0 .. c]
  if 500 * i + 100 * j + 50 * k == x
    then return 1
    else return 0


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

using namespace std;

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

#define F first
#define S second

int get(int x){
	int ret = 0;
	while (x){
		ret += x % 10;
		x /= 10;
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	int ans = 1e9;
	for (int i = 1; i < n; i++)
		ans = min(ans, get(i) + get(n-i));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		double angle = sc.nextInt();
		double radian = angle * Math.PI / 180;
		double h = b * Math.sin(radian);
		double c = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(radian));
		double s = a * h / (double)2;
		double l = a + b + c;
		System.out.println(s);
		System.out.println(l);
		System.out.println(h);
	}
}



Measured memory_bytes: 26328
#include<iostream>
#include<cstdio>

using namespace std;

int D,cnt[19],ans;
long long b[20];

void dfs(int x,long long num,int len,int sum){
	if(x>(len>>1)-1){if(num==D)ans+=sum*(len&1?10:1);return;}
	long long i=-9ll;while(i<9ll&&num+(i+1ll)*(b[len-x-1]-b[x])<=D)++i;
	dfs(x+1,num+i*(b[len-x-1]-b[x]),len,sum*(x==0&&i>=0?cnt[i+9]-1:cnt[i+9]));
	if(++i<=9)dfs(x+1,num+i*(b[len-x-1]-b[x]),len,sum*(x==0&&i>=0?cnt[i+9]-1:cnt[i+9]));
}

int main(){
	scanf("%d",&D);
	b[0]=1ll;for(int i=1;i<20;++i)b[i]=b[i-1]*10ll;
	for(int i=0;i<10;++i)for(int j=0;j<10;++j)++cnt[i-j+9];
	for(int i=1;i<20;++i)dfs(0,0,i,1);
	printf("%d",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF (1e9)
#define N 100005
using namespace std;
int n,t,a[N],maxabs,mina=INF;
bool f[N];

int main(){
  cin>>n>>t;
  for(int i=0;i<n;i++){
    cin>>a[i];
    maxabs=max(maxabs,a[i]-mina);
    mina=min(mina,a[i]);
  }
  mina=INF;
  int ans=0;
  for(int i=0;i<n;i++){
    if(maxabs==a[i]-mina)ans++;
    mina=min(mina,a[i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	ll ans = 0;
	for(ll i = k; i<=n+1 ; i++)
	{
		ll t = i*(i-1)/2;
		ll y = n*(n+1)/2-(n-i+1)*(n-i)/2;
		// cout<<y<<" "<<t<<endl;
		ans += (y-t+1)%mod;
		ans %= mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
const ll maxn=2e5+5;
ll n,a[maxn],b[maxn];
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    rep(i,0,n) cin>>a[i];
    rep(i,0,n) b[a[i]]++;
    ll ans=0;
    rep(i,1,n+1) ans+=b[i]*(b[i]-1)/2;
    rep(i,0,n) cout<<ans-b[a[i]]+1<<"\n";
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
const int MAX_M = 100000;
int N, M;


int main() {
    cin >> N >> M;
    vector<pair<int, int>> requests(M);

    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        requests.at(i).first = b; 
        requests.at(i).second = a;
    }

    sort(requests.begin(), requests.end());
    int answer = 0;
    int current = 0;

    for (int i = 0; i < M; i++) {
        if (current <= requests.at(i).second) {
            answer++;
            current = requests.at(i).first;
        }
    }

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 4036
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;

typedef long long ll;
ll n, m, sz, ans, a[N], v[N], k[N];
int main()
{
	ll i, j;
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		scanf ("%lld", &a[i]);
	}
	j = a[1];
	for (i = 1; i < m; i++, j = a[j]) {
		if (v[j] != 0) {
			sz = i - v[j];
			ans = (m - v[j]) % sz + v[j];
			cout << k[ans] << endl;
			return 0;
		}
		v[j] = i;
		k[i] = j;
	}
	cout << j << endl;
    return 0;
}


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

long long int extgcd(long long int a, long long int b, long long int &x, long long int &y){
  long long int d = a;
  if(b){
    d = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }else{
    x = 1;
    y = 0;
  }
  return d;
}

void change_ans(long long int a, long long int b, long long int &X, long long int &Y, long long int x, long long int y){
  if(abs(x) + abs(y) < X + Y){
    X = abs(x);
    Y = abs(y);
  }else if(abs(x) + abs(y) == X + Y && a*abs(x) + b*abs(y) < a*abs(X) + b*abs(Y)){
    X = abs(x);
    Y = abs(y);
  }
}

int main(){
  long long int a, b, d;
  while(cin >> a >> b >> d, a){
    long long int x, y, g = extgcd(a,b,x,y), r = d/g;
    x *= r; y *= r;
    a /= g;
    b /= g;
    long long int X = abs(x), Y = abs(y);
    if(x <= 0){
      long long int x_ = (b - (-x)%b)%b;
      long long int t = (x_ - x) / b;
      y -= t*a;
      x = x_;
      change_ans(a,b,X,Y,x,y);
      x -= b;
      y += a;
      change_ans(a,b,X,Y,x,y);
      x += b;
      y -= a;
    }
    if(y <= 0){
      long long int y_ = (a - (-y)%a)%a;
      long long int t = (y_ - y) / a;
      x -= t*b;
      y = y_;
      change_ans(a,b,X,Y,x,y);
      x += b;
      y -= a;
      change_ans(a,b,X,Y,x,y);
      x -= b;
      y += a;
    }
    if(x >= 0){
      long long int x_ = x%b;
      long long int t = x / b;
      y += t*a;
      x = x_;
      change_ans(a,b,X,Y,x,y);
      x -= b;
      y += a;
      change_ans(a,b,X,Y,x,y);
      x += b;
      y -= a;
    }
    if(y >= 0){
      long long int y_ = y%a;
      long long int t = y / a;
      x += t*b;
      y = y_;
      change_ans(a,b,X,Y,x,y);
      x += b;
      y -= a;
      change_ans(a,b,X,Y,x,y);
      x -= b;
      y += a;
    }
    cout << X << " " << Y << endl;
  }
  return 0;
}

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

using namespace std;

const int INF = 1e9 + 7;

void solve()
{
  int h, w;
  cin >> h >> w;
  string a[100];
  for(int i = 0; i < h; i++) {
    cin >> a[i];
  }
  cout << string(w + 2, '#') << "\n";
  for (int i = 0; i < h; i++) {
    cout << "#" << a[i] << "#\n";
  }
  cout << string(w + 2, '#') << "\n";
}

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class GFG
{
    static public void Main()
    {
        try
        {
            var n = Console.ReadLine();
            //var input1 = Console.ReadLine().Split(' ');
            //var n = int.Parse(input1[0]);
            //var b = int.Parse(input1[1]);

            /// var aar = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();

            Remove(n);
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }
    }

    static void Remove(string s)
    {
        Stack<char> ans = new Stack<char>();

        var ss = s.ToCharArray();
        for (int i = 0; i < s.Length; i++)
        {
            if(ans.Count!=0)
            {
                if(ans.Peek()=='S'&&s[i]=='T')
                {
                    ans.Pop();
                }
                else
                {
                    ans.Push(ss[i]);
                }
            }
            else
            {
                ans.Push(ss[i]);
            }
        }



        Console.Write(ans.Count);
    }
}

Measured memory_bytes: 13152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//入力
		Scanner sc = new Scanner(System.in);

		//図形作成繰り返し
		for (int h = 0;; h++) {

			//縦の長さ
			int H = sc.nextInt();

			//横の長さ
			int W = sc.nextInt();

			//どちらも0の時は終了
			if (H == 0 && W == 0) {
				break;

			}
			//繰り返しH(縦)
			for (int i = 0; i < H; i++) {

				//繰り返しW(横)
				for (int j = 0; j < W; j++) {

					//上辺と底辺を指定
					if (i == 0 || i == H - 1) {

						System.out.print("#");
						continue;
					}

					//上辺と底辺以外を指定
					//	if (i < 0 && i < H) {

					//右辺と左辺を指定
					if (j == 0 || j == W - 1) {

						System.out.print("#");

						//内側に"."を入れる
					} else {
						System.out.print(".");

					}
					//	}

				}
				System.out.println();//縦を次の行に
			}
			System.out.println();//最後の改行
		}

	}

}



Measured memory_bytes: 34128
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    n *= 2;
    vector<int> a(n);
    in_arr(int, a, n);
    sort(a.begin(), a.end());
    int sum = 0;
    for(int i = 0; i < n; i += 2){
        sum += a[i];
    }
    cout << sum << endl;
    return 0;
}


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

using namespace std;

using Matrix = vector<vector<int>>;
using Generator = pair<vector<int>, vector<int>>;

Matrix ReadMatrix(int rows, int cols)
{
    Matrix mat(rows, vector<int>(cols));
    for (auto &row : mat) {
        for (auto &num : row) {
            cin >> num;
        }
    }
    return mat;
}

Generator MakeGenerator(const Matrix &mat, int first)
{
    Generator gen;
    gen.first.resize(mat.size());
    gen.second.resize(mat[0].size());

    gen.first[0] = first;
    for (size_t i = 0; i < mat[0].size(); i += 1) {
        gen.second[i] = mat[0][i] - gen.first[0];
    }
    for (size_t i = 1; i < mat.size(); i += 1) {
        gen.first[i] = mat[i][0] - gen.first[i];
    }
    return gen;
}

bool Valid(const Matrix &mat, const Generator &gen)
{
    for (size_t i = 0; i < mat.size(); i += 1) {
        for (size_t j = 0; j < mat[i].size(); j += 1) {
            if (mat[i][j] != gen.first[i] + gen.second[j]) {
                return false;
            }
        }
    }
    return true;
}

bool Valid(const Matrix &mat)
{
    for (int i = -100; i <= 100; i += 1) {
        if (Valid(mat, MakeGenerator(mat, i))) {
            return true;
        }
    }
    return false;
}

int main()
{
    auto mat = ReadMatrix(3, 3);
    cout << (Valid(mat) ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 256
a=input()
list_1=list(a)
length=len(list_1)
count=0
if length%2==1:
  print("No")
else:
  for k in range(0,length,2):
    if list_1[k]=='h' and list_1[k+1]=='i':
      count+=2
      if count==length:
        print("Yes")
        break
    else:
      continue
  else:
    print("No")

Measured memory_bytes: 3060
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 1000005;
//
//

struct mi {
    ll v; explicit operator ll() const { return v; }
    mi() { v = 0; }
    mi(ll _v) { 
        v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
        if (v < 0) v += MOD;
    }
    friend bool operator==(const mi& a, const mi& b) { 
        return a.v == b.v; }
    friend bool operator!=(const mi& a, const mi& b) { 
        return !(a == b); }
    friend bool operator<(const mi& a, const mi& b) { 
        return a.v < b.v; }
   
    mi& operator+=(const mi& m) { 
        if ((v += m.v) >= MOD) v -= MOD; 
        return *this; }
    mi& operator-=(const mi& m) { 
        if ((v -= m.v) < 0) v += MOD; 
        return *this; }
    mi& operator*=(const mi& m) { 
        v = v*m.v%MOD; return *this; }
    mi& operator/=(const mi& m) { return (*this) *= inv(m); }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend mi inv(const mi& a) { assert(a.v != 0); 
        return pow(a,MOD-2); }
        
    mi operator-() const { return mi(-v); }
    mi& operator++() { return *this += 1; }
    mi& operator--() { return *this -= 1; }
    mi operator++(int) { mi temp; temp.v = v++; return temp; }
    mi operator--(int) { mi temp; temp.v = v--; return temp; }
    friend mi operator+(mi a, const mi& b) { return a += b; }
    friend mi operator-(mi a, const mi& b) { return a -= b; }
    friend mi operator*(mi a, const mi& b) { return a *= b; }
    friend mi operator/(mi a, const mi& b) { return a /= b; }
    friend ostream& operator<<(ostream& os, const mi& m) {
        os << m.v; return os;
    }
    friend istream& operator>>(istream& is, mi& m) {
        ll x; is >> x;
        m.v = x;
        return is;
    }
};
typedef vector<mi> vmi;
typedef pair<mi,mi> pmi;
typedef vector<pmi> vpmi;
mi facs[MAX];
mi facInvs[MAX];
 
mi choose(mi _a, mi _b) {
    ll a = (ll) _a, b = (ll) _b;
    if (b > a) return 0;
    if (a < 0) return 0;
    if (b < 0) return 0;
    mi cur = facs[a];
    cur = cur * facInvs[b];
    cur = cur * facInvs[a-b];
    return cur;
}
 
void initFacs() {
    facs[0] = 1;
    facInvs[0] = 1;
    for(int i = 1; i < MAX; i++) {
        facs[i] = (facs[i-1] * i);
        facInvs[i] = inv(facs[i]);
    }
}


void solve(){
    int n;
    cin>>n;
    mi ans = 0;
    initFacs();
    for(int i = 1; i <= n; i++){
        if(3*i > n)
            break;
        ans += choose(n-3*i+(i-1), i-1);
        // ans += pow((mi)i, n-3*i);
    }
    cout<<ans;
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 19272
#include<iostream>
using namespace std;
int main(){
    int n,x,t;
    while(1){
        cin>>n>>x;
        t=0;
        if (n==0&&x==0) break;
        else{
            for (int a=1;a<=n;a++){
                if (a==n-1) break;
                else for (int b=a+1;b<=n;b++){
                    if (b==n) break;
                    else for (int c=b+1;c<=n;c++){
                        if (a+b+c==x) t+=1; 
                    }
                }
            }
        }
        cout<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int a[4];
char s[4];

int main()
{
    scanf("%s", s);
    for(int i = 0; i < 3; ++i)
    {
        a[s[i] - 'a']++;
    }
    if(a[0] && a[1] && a[2])
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
	int n,i,ans,tmp;
	char cmd[6];
	int dice[6];
	while(1)
	{
		ans = 1;
		for(i=0;i<6;i++)
		{
			dice[i] = i+1;
		}
		scanf("%d",&n);
		if(n == 0)return 0;
		for(i=0;i<n;i++)
		{
			scanf("%s",cmd);
			if(strcmp(cmd,"North") == 0)
			{
				tmp = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = tmp;
				ans += dice[0];
			}
			else if(strcmp(cmd,"East") == 0)
			{
				tmp = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = dice[0];
				dice[0] = tmp;
				ans += dice[0];
			}
			else if(strcmp(cmd,"West") == 0)
			{
				tmp = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = tmp;
				ans += dice[0];
			}
			else if(strcmp(cmd,"South") == 0)
			{
				tmp = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = tmp;
				ans += dice[0];
			}
			else if(strcmp(cmd,"Right") == 0)
			{
				tmp = dice[1];
				dice[1] = dice[2];
				dice[2] = dice[4];
				dice[4] = dice[3];
				dice[3] = tmp;
				ans += dice[0];
			}
			else if(strcmp(cmd,"Left") == 0)
			{
				tmp = dice[1];
				dice[1] = dice[3];
				dice[3] = dice[4];
				dice[4] = dice[2];
				dice[2] = tmp;
				ans += dice[0];
			}
			else
			{
				printf("ERROR\n");
				return 0;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'

using namespace std;
struct custom_hash 
{
    static unsigned long long splitmix64(unsigned long long x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(unsigned long long x) const 
    {
        static const unsigned long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
mt19937 random_generator(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 1e5 + 3; 

int n; 
int a[maxn];
void read()
{
	cin >> n;
	for (int i = 0; i <= n; i++)
	cin >> a[i];
}

void solve()
{
	if (n == 0)
	{
		if (a[0] != 1)
		cout << -1 << endl;
		
		else 
		cout << 1 << endl; 
		
		return; 
	}
	
	if (a[0] != 0)
	{
		cout << -1 << endl;
		return; 
	}
	
	long long ans = 1, sum = 0;
	for (int i = 1; i <= n; i++)
	sum += a[i]; 
	
	ans += sum; 
	long long last = 1;
	for (int i = 1; i <= n; i++)
	{
		if (last * 2 < a[i])
		{
			cout << -1 << endl;
			return; 
		}
		
		sum -= a[i];
		last = min(last * 2 - a[i], sum);
		ans += last;
	}
	
	cout << ans << endl; 
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	read();
	solve();
}


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

int main()
{
  int a, b;
  cin>>a>>b;
  
  if(a<500)
  {
    if(a<=b)
    {
      cout<<"Yes"<<endl;
    }
    else
    {
      cout<<"No"<<endl;
    }
  }
  else
  {
    a%=500;
    
    if(a<=b)
    {
      cout<<"Yes"<<endl;
    }
    else
    {
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 256
args = input().split()
l = int(args[0])
r = int(args[1])

ans = 0
if r - l < 2019:
    left = l % 2019
    if 2018 - left >= r - l:
        right = left + r - l
        ans = 2019
        for i in range(left, right + 1):
            for j in range(i + 1, right + 1):
                tmp = i * j % 2019
                if ans > tmp:
                    ans = tmp
                    
        
        
print(ans)

Measured memory_bytes: 3064
N, M = map(int, input().split())

lst = [0] * (N + 1)
check = [0] * (N + 1)
AC = 0
WA = 0
for _ in range(M):
    p, S = map(str, input().split())
    if S == 'WA':
        lst[int(p)] += 1
    else:
        if check[int(p)] == 0: #初めてのACのときだけ処理する
            AC += 1
            check[int(p)] = 1
            WA += lst[int(p)]

print (AC, WA)

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

// zero-based numbering
template<class T> struct Fenwick {
    vector<T> bit; int N;
    Fenwick(int n) : N(n) { bit.assign(n+1, 0); }
    // add w to a
    void add(int a, T w) {
        for (int x = ++a; x <= N; x += x & -x) bit[x] += w;
    }
    // sum [0, a)
    T sum(int a) {
        T ret = 0;
        for (int x = a; x > 0; x -= x & -x) ret += bit[x];
        return ret;
    }
    // sum [a, b)
    T sum(int a, int b) { return sum(b) - sum(a); }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<string> S(N);
    for (auto &x: S) {
        cin >> x;
        reverse(x.begin(), x.end());
    }
    sort(S.begin(), S.end());
    using Query = tuple<int, int, int, char>;
    vector<Query> Q;
    for (int i = 0; i < N; i++) {
        string T = S[i];
        char c = T.back();
        T.pop_back();
        if (T.empty()) {
            Q.emplace_back(0, 0, N, c);
        } else {
            int s = T.size();
            int l = lower_bound(S.begin(), S.end(), T) - S.begin();
            T.back()++;
            int r = lower_bound(S.begin(), S.end(), T) - S.begin();
            Q.emplace_back(s, l, r, c);
        }
    }
    set<pair<int, int>> ST;
    for (int i = 0; i < N; i++) {
        ST.emplace(S[i].size(), i);
    }
    sort(Q.rbegin(), Q.rend());
    vector<Fenwick<long long>> F(26, N);
    vector<int> R;
    long long Ans = 0;
    for (auto &[sz, l, r, c]: Q) {
        // cout << sz << " " << l << " " << r << " " << c << " " << Ans << "\n";
        while (!ST.empty()) {
            auto [szi, idx] = *ST.rbegin();
            if (szi == sz) break;
            char ci = S[idx].back();
            if (!F[ci-'a'].sum(idx, idx+1)) {
                F[ci-'a'].add(idx, 1);
            }
            S[idx].pop_back(); 
            ST.erase({szi, idx});
            if (!S[idx].empty()) ST.emplace(szi-1, idx);
        }
        Ans += F[c-'a'].sum(l, r) - 1;
    }
    cout << Ans << "\n";
    return 0;
}

Measured memory_bytes: 63956
import time
MOD = 10**9+7

n,m = map(int,input().split())

stime = time.time()
F=[0]*(n+1)
F[0]=1
F[1]=2
for i in range(2,n):
    F[i]=(F[i-1]+F[i-2])%MOD

etime =time.time()


a=[0]*(n+1)
ans=1
for i in range(m):
      a[int(input())-1]+=1

io=-1
for i in range(n-1):
      if 0!=a[i] :
            io=i+1
            if 0!=a[i+1]:
                  print("0")
                  exit()
      else:
            if a[i+1] and i-io>1 :
                  ans*=F[i-io-1]%MOD
                  s=0
i=n-1
if i-io>0 :
      ans*=F[i-io-1]%MOD
print(ans%MOD)      


Measured memory_bytes: 13568
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    v = list(map(int, input().split()))
    v.sort()
    ans = v[0]
    for i in range(1, len(v)):
        ans = (ans+v[i])/2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38416
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

int main(){
    int a,b;
    cin>>a>>b;
    if(a+b<24)
        cout<<a+b<<endl;
    else
        cout<<(a+b)%24<<endl;
 }

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<map>
#include<bitset>
#include<stack>
#include<queue>
#include<set>
#include<cmath>
#include<vector>

using namespace std;

#define INF 1000000000
#define pprint(x) print(x),putchar(' ')
#define fprint(x) print(x),putchar('\n')

//#define getchar() (SS == TT && (TT = (SS = BB) + fread(BB,1,1 << 15,stdin),TT == SS) ? EOF : *SS++)
char BB[1 << 15],*SS = BB,*TT = BB;
inline long long read()
{
	long long x = 0;int f = 1;
	char ch = getchar();
	for(;!isdigit(ch);ch = getchar())
		if(ch == '-')
			f = -1;
	for(;isdigit(ch);ch = getchar())
		x = x * 10 + (ch ^ 48);
	return x * f;
}
void print(long long x)
{
	if(x < 0)
		putchar('-'),x = -x;
	if(x > 9)
		print(x / 10);
	putchar(x % 10 + '0');
}
const int N = 410,K = 20;

int f[N][N],d[K][K];
struct edge
{
    int u,v,w;
}e[N * N];
int n,m;
int main()
{
    n = read(),m = read();
    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= m;j++)
            d[i][j] = read();
    for(int i = 0;i <= 100;i++)
        for(int j = 0;j <= 100;j++)
            for(int x = 1;x <= n;x++)
                for(int y = 1;y <= m;y++)
                    f[i][j] = max(f[i][j],d[x][y] - i * x - j * y);
    int res;
    for(int x = 1;x <= n;x++)
        for(int y = 1;y <= m;y++)
        {
            res = INF;
            for(int i = 0;i <= 100;i++)
                for(int j = 0;j <= 100;j++)
                    res = min(res,f[i][j] + i * x + j * y);
            if(res != d[x][y])
			{
                puts("Impossible");
                return 0;
            }
        }
    puts("Possible");
    puts("202 10401");
    for(int i = 1;i <= 100;i++)
        pprint(i),pprint(i + 1),puts("X");
    for(int i = 102;i < 202;i++)
        pprint(i),pprint(i + 1),puts("Y");
    for(int i = 0;i <= 100;i++)
        for(int j = 0;j <= 100;j++)
            pprint(i + 1),pprint(202 - j),fprint(f[i][j]);
    puts("1 202");
    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = sc.nextInt();
        long Ans = 1;
        for (int i =0 ; i < N; i++){
            long a = sc.nextLong();
            if(a ==0 ){
                System.out.println(0);
                return;
            }
            Ans = Ans * a;
        }
        long b = (long)Math.pow(10 , 18);
        if(Ans > b || Ans == 0){
            System.out.println(-1);
        }else{
            System.out.println(Ans);
        }
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    string S; cin >> S;
    auto i = unique(S.begin(),S.end());
    S.erase(i,S.end());
    cout << S.size() << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S;
    cin >> S;
    int res = 0;
    rep(i, S.size()) {
        if (S.at(i) == '+') {
            res++;
        } else {
            res--;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    string s, t, u = "";
    cin >> s >> t;
    rep(i, 0, s.size() + t.size()){
        if(i % 2 == 0) u += s[i / 2];
        else u += t[i / 2];
    }
    cout << u << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const int maxn = 2e5 + 5;

long long sum[maxn];

int main(int argc, char const *argv[]) {
    
    int n; cin >> n;

    for (int i = 1; i <= n; i ++) {
        long long x;
        scanf("%lld",  &x);
        sum[i] = sum[i - 1] + x;
    }

    long long ans = 2e9;
    for (int i = 1; i <= n - 1; i ++) {
        long long tmp = abs(sum[i] - (sum[n] - sum[i]));
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int dp[3001][3001];

int main() {
  int A, B, C, D, E, F;
  cin>>A>>B>>C>>D>>E>>F;
  for(int i = 0; i < 3001; i++) 
        for(int j = 0; j < 3001; j++) 
          dp[i][j] = 0;
  dp[0][0] = 1;
  int ni, nj;
  int ai = A*100, aj = 0;
  double max = 0.0;
  for(int i = 0; i < F; i++) {
        for(int j = 0; j <= (F/100+1)*E; j++) {
          if(dp[i][j]<=0) continue;
          //      cout << i << " " << j << endl;
          // op 1
          ni = i + A*100; nj = j;
          if(ni + nj <= F) {
                dp[ni][nj] = 1;
          }
          // op 2
          ni = i + B*100; nj = j;
          if(ni + nj <= F) {
                dp[ni][nj] = 1;
          }
          // op 3
          ni = i; nj = j + C;
          if(ni + nj <= F) {
                if(ni / 100 * E >= nj) {
                  dp[ni][nj] = 1;
                  double tmp = (double)nj / (ni + nj);
                  if (tmp > max) {
                        max = tmp; ai = ni; aj = nj;
                  }
                }
          }
          // op 4
          ni = i; nj = j + D;
          if(ni + nj <= F) {
                if(ni / 100 * E >= nj) {
                  dp[ni][nj] = 1;
                  double tmp = (double)nj / (ni + nj);
                  if (tmp > max) {
                        max = tmp; ai = ni; aj = nj;
                  }
                }
          }
        }
  }
  cout << (ai + aj) << " " << aj << endl;
  return 0;
}


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

#define ll long long
// #define endl '\n'

void max_self(int &a, int b){ a = max(a, b);}
void min_self(int &a, int b){ a = min(a, b);}

int n, cnt_r; string s;

bool good(int x){
	for(int i = 0; i<cnt_r; i++){
		if(s[i] == 'W') x--;
	}
	return x >= 0;
}

void solve(){
	cin>>n;
	cin>>s;
	for(char i: s){
		if(i == 'R') cnt_r++;
	}
	int l = -1; // bad
	int r = n; // good

	while(r > l + 1){
		int mid = (l + r) / 2;
		if(good(mid)){
			r = mid;
		}else{
			l = mid;
		}
	}
	cout<<r<<endl;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;// cin>>t;
	for(int i = 1; i<=t; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3764
import java.util.Scanner;

public class Main {

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

    public static void main(String[] args) {

        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int n = sc.nextInt();

        int ans = 0;
        for (int i=0; i <= n/r; i++) {
            for (int j=0; j <= n/g; j++) {
                int rem = n - i*r - j*g;
                if (rem % b == 0 && rem >= 0) {
                    ans++;
                }
            }
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 23764
n, m = map(int, input().split())
a, b = [], []
for _ in range(n):
    a_i, b_i = map(int, input().split())
    a.append(a_i)
    b.append(b_i)
c, d = [], []
for _ in range(m):
    c_i, d_i = map(int, input().split())
    c.append(c_i)
    d.append(d_i)
for i in range(n):
    min_idx = -1
    min_distance = 10**10
    for j in range(m):
        distance = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if min_distance > distance:
            min_idx = j
            min_distance = distance
    print(min_idx + 1)

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

using namespace std;

int main()
{
    int N, M, k, s, p, ans = 0, count = 0;
    cin >> N >> M;
    vector<vector<int>> switches(M);
    for (int i = 0; i < M; i++)
    {
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            cin >> s;
            switches[i].push_back(--s);
        }
    }

    for (int i = 0; i < M; i++)
    {
        cin >> p;
        ans += (p << i);
    }

    int hoge;
    bool ok;
    for (int i = 0; i < (1 << N); i++)
    {
        ok = true;
        for (int j = 0; j < M; j++)
        {
            hoge = 0;
            for (int s : switches[j])
            {
                // スイッチONの個数
                hoge += ((i >> s) & 1);
            }
            if((hoge & 1) != ((ans >> j) & 1)){
                ok = false;
                break;
            }
        }
        if(ok) count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;

int main() {
    ll n,k; cin >> n >> k;
    vl a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,n){
        ans += min(a[i],k-a[i]);
    }
    cout << ans*2 << endl;
}

Measured memory_bytes: 256
import java.util.*
import java.math.*
import java.lang.Math.*


private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readLong: ()->Long = { readLine()!!.toLong() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }
private val readListLong: ()->List<Long> = { readLine()!!.split(' ').map(String::toLong) }
private val errPrintln: (String)->Unit = { msg -> System.err.println(msg) }
//private val MOD = 1e9.toLong()+7
//private val INF = Int.MAX_VALUE/2
//private val LINF = Long.MAX_VALUE/2


class GridBfs(val G: List<String>, val Start:Char = '#',
              val ToPaint:Char = '.') {
    var H:Int = 0
    var W:Int = 0
    data class Pos(val x: Int, val y: Int)
    private val starts = ArrayList<Pos>()
    init {
        H = G.size
        W = G[0].length
        G.forEachIndexed{i, row ->
            row.forEachIndexed{j, cell ->
                if (cell == Start) starts.add(Pos(i,j))
            }
        }
    }
    private val dx = intArrayOf(0,1,0,-1)
    private val dy = intArrayOf(1,0,-1,-0)
    private val INF = Int.MAX_VALUE/2
    fun fill(): Int {
        val que = LinkedList<Pos>()
        val step = Array(H){IntArray(W){INF} }
        for (ps in starts) {
            que.addLast(ps)
            step[ps.x][ps.y] = 0
        }
        while (que.isNotEmpty()) {
            val (x, y) = que.removeFirst()
            for (i in dx.indices) {
                val nx = x + dx[i]; val ny = y + dy[i]
                if (nx<0 || H<=nx || ny<0 || W<=ny) {
                    continue
                }
                if (step[nx][ny] > step[x][y] + 1) {
                    step[nx][ny] = step[x][y] + 1
                    que.addLast(Pos(nx, ny))
                }
            }
        }

        var res = -INF
        step.forEach { it.forEach { res = max(res, it) } }
        return res
    }
}


fun solveA(A: Array<String>): Int {
    val bfs = GridBfs(A.toList())
    return bfs.fill()
}


fun main(args: Array<String>) {
    val (H, W) = readListInt()
    val A = Array<String>(H){""}
    for (i in 0 until H) {
        A[i] = readString()
    }

    val ans = solveA(A)

    println(ans)
}


Measured memory_bytes: 133600
/*
 *  Created on: 22-December-2019
 *      Author: ankur314
 */
#include <bits/stdc++.h>
#define lli long long int
#define li long int
#define db double
#define ldb long double
#define vr vector
#define it iterator
#define fi(i,a,n) for(int i=a;i<n;i++)
#define fli(i,a,n) for(long int i=a;i<n;i++)
#define flli(i,a,n) for(long long int i=a;i<n;i++)
#define pb(n) push_back(n)
#define ppf() pop_front()
#define pii pair<int,int>
#define MOD 1000000007
#define INF 1000000005
 
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define debug4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"
 
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    lli a, b;
    cin>>a>>b;
    lli g = __gcd(a, b);
    lli ans = (a*b) / g;
    cout<<ans;
    return 0;
}   

Measured memory_bytes: 256
S=str(input())
if S=="SUN":
  print(7)
elif S=="MON":
  print(6)
elif S=="TUE":
  print(5)
elif S=="WED":
  print(4)
elif S=="THU":
  print(3)
elif S=="FRI":
  print(2)
else:
  print(1)
  

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a+b == c || a+c == b || b+c == a) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3572
H, W = gets.chomp.split.map(&:to_i)

board = []
H.times do
  l = gets.chomp
  res = false
  for i in 0..(W - 1) do
    res = true if l[i] == "#"
  end
  board << l if res
end

col = []
for i in 0..(W - 1) do
  res = false
  for j in 0..(board.size - 1) do
    res = true if board[j][i] == "#"
  end
  col[i] = res
end

ans = []
for i in 0..(board.size - 1) do
  l = ""
  for j in 0..(W - 1) do
    l += board[i][j] if col[j]
  end
  ans << l
end

puts ans
  

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

int main(){

  double X;
  cin >> X;

  int ansA;
  int ansB;
  double sum;

  for(int A=-118;A<=119;A++){
    for(int B=-118;B<=119;B++){
      sum = pow(A,5) - pow(B,5);
      if(sum == X){
        ansA = A;
        ansB = B;
        break;
      }
    }
    if(sum == X) break;
  }

  cout << ansA << " " << ansB << endl;
}

Measured memory_bytes: 4088
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,m=parseMap(split(readline()))
    a=sort(parseMap(split(readline())),rev=true)
    s=sum(a)
    ans="Yes"
    for i in 1:m
        if a[i]<s/(4m)
            ans="No"
        end
    end
    println(ans)

end
main()

Measured memory_bytes: 177728
S = input()

mm = int(S[2:])
if mm == 0 or mm > 12:
    yymm = False
else:
    yymm = True

mm = int(S[:2])
if mm == 0 or mm > 12:
    mmyy = False
else:
    mmyy = True

if yymm is True and mmyy is True:
    print("AMBIGUOUS")
elif yymm is True:
    print("YYMM")
elif mmyy is True:
    print("MMYY")
else:
    print("NA")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<ii> vii;

#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e5+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	vi m(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}


lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}

lli PROD(lli a, lli b, lli mod=MOD){
	a%=mod; b%=mod;
	return a*b % mod;
}

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

vvi graph(int n, int m){
	vv(int,v,n+1,0);
	fore(i,0,m){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	return v;
}

// ---- コーディングはここから！ ('-')7

void solve(){
	int a,b,c,k; cin>>a>>b>>c>>k;
	int sum = min(k,a);
	k-=sum;
	k-=min(b,k);
	sum-=min(c,k);
	cout<<sum<<ENDL;

}

int main(){_
//	int t; cin>>t; while(t--)
	solve();
}


Measured memory_bytes: 3600
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int w = scan.nextInt();
		int[] dl = new int[w];
		for(int i = 0; i < w; i++){
			dl[i] = i + 1;
		}
		int n = scan.nextInt();
		for(int i = 0; i < n; i++){
			String input = scan.next();
			String[] nums = input.split(",");
			int a = Integer.parseInt(nums[0]);
			int b = Integer.parseInt(nums[1]);
			int work = dl[a - 1];
			dl[a - 1] = dl[b - 1];
			dl[b - 1] = work;
		}

		for(int i = 0; i < w; i++){
			System.out.printf("%d\n", dl[i]);
		}
	}
}

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

int main() {
	long long l[100];
	l[0] = 2;
	l[1] = 1;
	for (int i = 2; i < 100; i++)
		l[i] = l[i - 1] + l[i - 2];
	int n;
	scanf("%d", &n);
	printf("%lld", l[n]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string S,T;
	cin>>S;
	cin>>T;
	int i;
	int ans=0;
	for (i=0;i<S.size();i++){
		if (S[i]==T[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int i, j = 0, k = 0;
  if(S[0] != 'A'){
    cout << "WA" << endl;
  }else{
    for(i = 2; i < S.length() - 1; i++){
      if(S[i] == 'C'){
        j++;
      }
    }
    for(i = 1; i < S.length(); i++){
      if(S[i] >='A' && S[i] <= 'Z'){
        k++;
      }
    }
    if(j!=1 || k > 1){
      cout << "WA" <<endl;
    }else{
      cout << "AC" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" \
                              << "\n";

int main()
{
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    REP(i,n){
        int tmp;
        cin >> tmp;
        a.at(i) = make_pair(tmp, i);
    }
    sort(a.begin(), a.end());
    REP(i,n){
        cout << a.at(i).second+1 << "\n";
    }

    return 0;
}


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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main() {
  int a;
  cin >> a;
  if (a <= 599) {
    cout << 8;
  } else if (a <= 799) {
    cout << 7;
  } else if (a <= 999) {
    cout << 6;
  } else if (a <= 1199) {
    cout << 5;
  } else if (a <= 1399) {
    cout << 4;
  } else if (a <= 1599) {
    cout << 3;
  } else if (a <= 1799) {
    cout << 2;
  } else {
    cout << 1;
  }

}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の
string型配列と同じような感じ） map<int, string> mp; for (auto itr =mp.begin();
itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
  //ここにパーテーションがくる
} while (next_permutation(s.begin(), s.end()));

//set
set<int> hoge;
hoge.insert(50);  //hogeに挿入。重複は無視される。
hoge.insert(20);  //内部は小さい順に並ぶ
hoge.erase(50);   //hogeから消し去る。
//40以上である最小の要素を指すイテレーターを返す。
//もちろんそんなものはないからEndが出力される
auto itr1 = Set.lower_bound(40);
if (itr1 == Set.end()) cout << "End" << endl;
else cout << (*itr1) << endl;

//pair
//たくさんつくる
vector<pair<int,string>> hoge(10);
//参照
hoge[0].first
sort(all(hoge), greater<pair<int, string>>());




*/


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

int main() {
    int n; cin >> n;
    double a, ans; ans = 0.0;
    for (int i=0; i<n; ++i) {
        cin >> a;
        ans += 1.0 / a;
    }
    ans = 1.0 / ans;
    cout << setprecision(16) << ans << endl;
}

Measured memory_bytes: 256