akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include <string.h>
#include <iomanip>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
const ll mod=1e9+7;

int main(void){
    double W,H,x,y;
    cin>>W>>H>>x>>y;
    double sizewh=W*H/2;
    cout<<setprecision(10)<<sizewh<<" ";
    if(2*x==W && 2*y==H) cout<<1<<endl;
    else cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
t,l,b,a,i,j,I,J,s;
main(n){
        while(scanf("%d%d%d%d",&n,&t,&l,&b),n){
                double d[101][101]={{}},o=0;
                int f[101]={};
                while(l--)scanf("%d",&a),f[a]=1;
                while(b--)scanf("%d",&a),f[a]=2;
                d[0][0]=1;
                for(i=0;i<=t;i++){
                        o+=d[i][n];
                        d[i][n]=0;
                        for(j=0;j<=n;j++){
                                I=i+(f[j]==1?2:1);
                                if(I>t)continue;
                                for(s=1;s<7;s++){
                                        J=j+s;
                                        if(J>n)J=n-J+n;
                                        J=f[J]-2?J:0;
                                        d[I][J]+=d[i][j]/6;
                                }
                        }
                }
                printf("%.9lf\n",o);
        }
}

Measured memory_bytes: 1924
var
 n,m,i,j,s:longint;
 ch:char;
begin
 readln(n,m);
 for i:=1 to n do
  begin
   for j:=1 to m do begin read(ch);if ch='#' then inc(s); end;
   readln;
  end;
 if s=n+m-1 then writeln('Possible')
  else writeln('Impossible');
end.

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

int main()
{
    /*A
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<endl;
    */
    /*B
    int n;
    double m;
    cin>>n>>m;
    vector <double> a(n);
    double total = 0;
    rep(i,n)
    {
        cin>>a[i];
        total+= a[i];
    }
    
    sort(a.rbegin(),a.rend());
    bool flag = true;
    for(int i=0;i<m;i++)
    {
        if(1/(4*m)>a[i]/total)
        {
            flag = false;
            break;
        }
    }
    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    */
    ll n,k;
    cin>>n>>k;
    if(n>k)
    {
        n=n%k;
    }
    if(k-n<n)
    {
        cout<<k-n<<endl;
    }
    else
    {
        cout<<n<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc133/tasks/abc133_d

# Ai= xi+x(i+1) と置くと
# x1は即座に求まる。なぜならば、A1-A2+A3-A4...+AN = 2*x1となることは式変形からすぐにわかる。
# x1がわかるとx2以降は芋づる式に求まる。
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


N = int(input())
A = read_ints()

x1 = 0
for i, a in enumerate(A):
    if i & 1:  # 奇数ならば
        x1 -= a
    else:  # 偶数ならば
        x1 += a
# x1 //= 2

ans = [x1]
xi = x1
for a in A:
    xi = 2 * a - xi
    ans.append(xi)
print(*ans[:-1])


Measured memory_bytes: 14316
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>

#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>

#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

struct __scanner__{ bool e; operator bool(){ return e; } } IN = { false };
inline __scanner__& operator>>(__scanner__& in,int &n)
{ in.e = scanf("%d",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,ll &n)
{ in.e = scanf("%lld",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,double &n)
{ in.e = scanf("%lf",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,char &n)
{ in.e = scanf(" %c",&n)==1; return in; }
inline __scanner__& operator>>(__scanner__& in,string &n) // BUFFER SIZE!
{ static char buf[1000000]; in.e = scanf(" %s",buf)==1; n = buf; return in; } 

int main(){
  int n;
  while (cin >> n) {
    int cnt = 0;
    int result = 0;
    REP(i,n) {
      int t; cin >> t; t--;
      if (i == t) cnt++;
      else {
	result += (cnt + 1) / 2;
	cnt = 0;
      }
    }
    result += (cnt + 1) / 2;
    cout << result << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
   ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
  vector<vector<bool>>d(5001,vector<bool>(5001));
int main(){
  ll a;cin>>a;
  if(a>=30)cout<<"Yes";
  else cout<<"No";
}



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

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B, N;
  cin >> N >> A >> B;
  bool find = false;
  for (; A <= B && !find; A++)
    if (A % N == 0)
      find = true;
  cout << (find? "OK" : "NG") << '\n';
  return 0;
}


Measured memory_bytes: 3644
import itertools


n = input()
v = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
dif = []

for kati,nedan in zip(v,c):
	dif.append(kati-nedan)

max = -1

for L in range(len(dif)+1):
	for subset in itertools.combinations(dif, L):
		s = sum(subset)
		if(max < s):
			max = s

print(max)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int is_it_triangle(int a, int b, int c) {
	if(a == b || b == c || c == a) {//shant be isosceles nor equilateral triangle
		return 0;
	} else if(a + b > c && b + c > a && c + a > b) {
		return 1;
	} else {
		return 0;
	}
}

int main(void) {
	int i, j, k;
	int N;
	int ans;
	int *L;
	char buf[128], *ch;
	char *g_buf;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);
	L = (int *)calloc(N, sizeof(double));
	g_buf = (char *)calloc(N*16, sizeof(double));

	fgets(g_buf, N*16, stdin);
	ch = strtok(g_buf, " ");
	L[0] = atoi(ch);
	for(i = 1; i < N; i += 1) {
		ch = strtok(NULL, " ");
		L[i] = atoi(ch);
	}

	ans = 0;
	for(i = 0; i < N; i += 1) {
		for(j = 0; j < i; j += 1) {
			for(k = 0; k < j; k += 1) {
				ans += is_it_triangle(L[i], L[j], L[k]);
			}
		}
	}

	printf("%d\n", ans);

	free(g_buf);
	free(L);
	return 0;
}


Measured memory_bytes: 2156
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = [a for a in a_list if a % 2 == 0]
    for b in b_list:
        if b % 3 != 0 and b % 5 != 0:
            print("DENIED")
            return
    print("APPROVED")
main()

Measured memory_bytes: 2940
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <string>
#include <iomanip>
using namespace std;
#define int long long
map <int, vector <int> > mmm;
int cnt = 0;
signed main() {
#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n, all;
	cin >> n >> all;
	int minn = -1234567890;
	for (int i = 1; i <= n; ++i) {
		int a, b;
		cin >> a >> b;
		if (minn == -1234567890) minn = a;
		else minn = min(a, minn);
		mmm[a].push_back(b);
	}

	for (auto it = mmm.begin(); it != mmm.end(); ++it) {
		sort(it->second.rbegin(), it->second.rend());
		for (int i = 0; i < it->second.size(); ++i) {
			if (i != 0) it->second[i] += it->second[i - 1];
		}
	}
	int ans = 0;
	for (int i = 0; i <= mmm[minn].size(); ++i) {
		for (int j = 0; j <= mmm[minn + 1].size(); ++j) {
			for (int k = 0; k <= mmm[minn + 2].size(); ++k) {
				for (int t = 0; t <= mmm[minn + 3].size(); ++t) {
					int ves = i * minn + j * (minn + 1) + k * (minn + 2) + t * (minn + 3);
					if (ves <= all) {
						ans = max(ans, (i == 0 ? 0 : mmm[minn][i - 1]) + (j == 0 ? 0 : mmm[minn + 1][j - 1]) + (k == 0 ? 0 : mmm[minn + 2][k - 1]) + (t == 0 ? 0 : mmm[minn + 3][t - 1]));
					}
				}
			}
		}
	}
	cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int main() {
	const ll MOD = 1e9 + 7;
	const int A = 0, C = 1, G = 2, T = 3;

	int N;
	cin >> N;

	int dp[110][4][4][4] = { 0 };
	dp[0][T][T][T] = 1;
	for (int i = 1; i < N; ++i) {
		for (int j = 0; j < 4; ++j) {
			for (int k = 0; k < 4; ++k) {
				for (int l = 0; l < 4; ++l) {
					for (int m = 0; m < 4; ++m) {
						if (j == A && k == G && l == C) { continue; }
						if (j == G && k == A && l == C) { continue; }
						if (j == A && k == C && l == G) { continue; }
						if (j == A && l == G && m == C) { continue; }
						if (j == A && k == G && m == C) { continue; }

						(dp[i][j][k][l] += dp[i - 1][k][l][m]) %= MOD;
					}
				}
			}
		}
	}

	ll res = 0;
	for (int j = 0; j < 4; ++j) {
		for (int k = 0; k < 4; ++k) {
			for (int l = 0; l < 4; ++l) {
				for (int m = 0; m < 4; ++m) {
					if (j == A && k == G && l == C) { continue; }
					if (j == G && k == A && l == C) { continue; }
					if (j == A && k == C && l == G) { continue; }
					if (j == A && l == G && m == C) { continue; }
					if (j == A && k == G && m == C) { continue; }

					(res += dp[N - 1][k][l][m]) %= MOD;
				}
			}
		}
	}

	cout << res % MOD << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long


using namespace std;
const int N = 500077;
int n, m, k, l, r, d;
int a[N];
int b[N];


signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    int col = 0;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        if (a[i] % 2 == 1 && i % 2 == 1){
            col++;
        }
    }
    cout << col << endl;


}


Measured memory_bytes: 3640
#include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>
#include <vector>

using namespace std;

int max(int a, int b);
int min(int a, int b);
int is_prime(int n);

int main(int argc, char const* argv[])
{
    int n,p;
    while (cin >> n >> p) 
    {
        if ( n==-1 && p==-1 ) { break; }
        vector<int> arr;

        //テァツエツ?ヲツ閉ーテ・ツ按療」ツつ津ヲツ?シテァツエツ?
        int count=0;
        int i=n+1;
        while ( count <  p ) 
        {
            if ( is_prime(i) ) 
            {
                //cout << "i = " << i << endl;
                arr.push_back(i);    
                count++;
            }
            i++;
        }

        //
        //for (int i = 0; i < p; i++) 
        //{
        //    cout << arr[i] << endl;
        //}

        //ティツカツウテ」ツ?療」ツ?淌ァツエツ?ヲツ閉ーテ」ツつ津ヲツ?シテァツエツ?
        vector<int> sum;
        for (int i = 0; i < p; i++) 
        {
            for (int j = i; j < p; j++) 
            {
                sum.push_back( arr[i] + arr[j] );
            }
        }
        sort(sum.begin(), sum.end());
        cout << sum[p-1] << endl;    
    }
    return 0;
}

int is_prime(int n)
{
    if (n ==1 || n== 0) 
    {
        return 0;
    }
    for (int i = 2; i*i <= n; i++) 
    {
        if (n % i == 0) 
        {
            return 0;
        }
    }
    return 1;

}


int max(int a, int b)
{
    if (a > b) 
    {
        return a;
    }
    else{
        return b;
    }
}
int min(int a, int b)
{
    if (a > b) 
    {
        return b;
    }
    else{
        return a;
    }
}

Measured memory_bytes: 1272
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max

fun main(args: Array<String>) {

    // IO Templates
    val br = BufferedReader(InputStreamReader(System.`in`))
    val out = PrintWriter(System.out)

    val (a, b, c, d) = br.readLine()!!.split(' ').map { it.toLong() }

    out.println(listOf(a * c, a * d, b * c, b * d).max())

    out.flush()
}

Measured memory_bytes: 39032
#include<stdio.h>

int main(void)

{ 

 int i, n, a[10000];

 scanf("%d",&n);





 for(i = 0 ; i < n ; i++){


   scanf("%d",&a[i]);


}


int min = a[0], max = a[0];


 long long int sum = 0;


for( i = 0 ; i < n ; i++){


  if( a[i] < min){


   min = a[i];


}else if( a[i] > max){


  max = a[i];


}


  sum += a[i];


}





printf("%d %d %lld\n",min,max,sum);


return 0;


}

Measured memory_bytes: 640
import math
Q_SIZE = int(math.pow(10,5))
Q = int(input())

Check_Prime = [True for i in range(Q_SIZE+1)]
Count_like = [0 for i in range(Q_SIZE//2)]

Check_Prime[0] = False
Check_Prime[1] = False

for i in range(2,Q_SIZE+1):
    if(Check_Prime[i] == True):
        for j in range(i+i,Q_SIZE+1,i):
            Check_Prime[j] = False
            
for i in range(1,Q_SIZE//2):
    if(Check_Prime[i*2+1] == True and Check_Prime[int(((i*2+1)+1)/2)] == True):
        Count_like[i] = Count_like[i-1] + 1
    else:
        Count_like[i] = Count_like[i-1]

for i in range(Q):
    l,r = map(int,input().split())
    if( l == 1):
        print(Count_like[r//2] - Count_like[l//2])
    else:
        print(Count_like[r//2] - Count_like[l//2 - 1]) 

Measured memory_bytes: 4776
import fractions
def CntMultiples(a, b, n):
    return b//n - a//n + int(a%n==0)

A,B,C,D = map(int,input().split())
print(B-A+1-(CntMultiples(A, B, C) + CntMultiples(A, B, D) - \
             CntMultiples(A, B, (C*D)//(fractions.gcd(C, D)))))

Measured memory_bytes: 5052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main()
{
  int n;
  ll h;
  cin >> n >> h;
  vector<pair<ll, string>> k;
  rep(i, n)
  {
    int x, y;
    cin >> x >> y;
    k.push_back({x, "a"});
    k.push_back({y, "b"});
  }

  sort(k.rbegin(), k.rend());

  ll ans = 0;
  for (;;) {
    for(auto p : k) {
      if(p.second == "a"){
        while(h > 0){
          h -= p.first;
          ans++;
        }
      }else {
        h -= p.first;
        ans++;
      }

      if(h <= 0){
        cout << ans << endl;
        return 0;
      }
    }
  }
    return 0;
}

Measured memory_bytes: 13292
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <pthread.h>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(int64_t i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
  ios::sync_with_stdio(NULL);
  cin.tie(NULL); cout.tie(NULL);
  int64_t h,c;  cin >> h >> c;
  if(h == 1 || c == 1){
    cout << 1 << endl;
  }else if(h*c % 2 == 0){
    cout << (h*c)/2 << endl;
  }
  else{
    cout << ((h*c)+1)/2 << endl;
  }
  return 0;
}


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

int k;
bool d[11];
char n[10];

int main()
{
    n[0] = '0';
    d[10] = 1;
    scanf("%s", n+1);
    cin >> k;
    while(k--)
    {
        int x;
        cin >> x;
        d[x] = 1;
    }

    int ptr = 1;

    while(n[ptr] && !d[n[ptr]-'0']) ptr++;

    while(n[ptr] && d[n[ptr]-'0'])
    {
        while(d[n[ptr]-'0']) n[ptr]++;
        if(n[ptr] > '9')
        {
            n[ptr] = '0';
            n[ptr-1]++;
            ptr--;
        }
    }

    ptr++;
    while(n[ptr])
    {
        n[ptr] ='0';
        while(d[n[ptr]-'0']) n[ptr]++;
        ptr++;
    }

    int x = n[0] == '0';
    cout << n+x << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int main(){
    string s;
    cin >> s;

    if(s == "AAA" or s == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<double> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<vector<double>> dp(n + 1, vector<double>(n + 1));
    dp[0][0] = 1.0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            dp[i + 1][j + 1] += p[i] * dp[i][j];
            dp[i + 1][j] +=  (1 - p[i]) * dp[i][j];
        }
    }
    double ans = 0;
    for (int i = n / 2 + 1; i <= n; i++) {
        ans += dp[n][i];
    }
    cout.precision(16);
    cout << fixed << ans << endl;
}


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

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

    int cnt = 0; // ドーナツの個数

    int A[N];
    int m;
    int min_m = 100001;
    for (int i = 0; i < N; i++)
    {
        // 一番コストが低いものを記憶しておく。
        cin >> m;
        if (min_m > m)
            min_m = m;

        // とりあえず一つずつつくる。
        X -= m;
        cnt++;
    }

    while (X >= min_m)
    {
        cnt++;
        X -= min_m;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
typedef long long ll;
using namespace std;
int n;
vector<int> a[MAXN];
ll val[MAXN];
int u,v;
ll dfs(int x,int fa){
	ll sum=0,mx=0;
	if(a[x].size()==1&&fa!=0)
		return val[x];
	for(int i=0;i<int(a[x].size());i++){
		int u=a[x][i];
		if(u==fa)
			continue;
		ll s=dfs(u,x);
		mx=max(mx,s);
		sum+=s;
	}
	if(sum<val[x]||sum>val[x]*2){
		PF("NO");
		exit(0);
	}
	ll nx=2ll*val[x]-sum;
	if((sum-nx)/2ll<mx-nx){
		PF("NO");
		exit(0);	
	}
	return 2ll*val[x]-sum;
}
int main(){
	//freopen("tree.in","r",stdin);
	//freopen("tree.out","w",stdout);
	SF("%d",&n);
	for(int i=1;i<=n;i++)
		SF("%lld",&val[i]);
	for(int i=1;i<n;i++){
		SF("%d%d",&u,&v);	
		a[u].push_back(v);
		a[v].push_back(u);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(a[i].size()==1){
			ans=(dfs(i,0)==val[i]);
			break;
		}
	if(ans==0)
		PF("NO");
	else
		PF("YES");
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int ans = INT_MAX;
int n,a[3];
vi l(8);
//stack<int> g[4];
vi g[4];
enum ppos{ap,bp,cp,dp};
void dfs(int i){
    
    if(i<n){
        REP(j,4){
            g[j].emplace_back(l[i]);
            dfs(i+1);
            g[j].erase(g[j].end()-1, g[j].end());
        }

        return;
    }

    //竹がないと伸縮させようがないのでスルー
    if(!(g[ap].size()>0 && g[bp].size()>0 && g[cp].size()>0))
        return;

    int temp = 0;

    REP(j,4-1){
        int total = 0;
        REP(k,g[j].size()){
            total += g[j][k];
        }
        temp += abs(total - a[j]);
        if(!g[j].empty()) temp += (g[j].size()-1) * 10;
        
    }

    //DEBUG(temp);
    // if(temp==120)
    //     REP(j,4){
    //         REP(k,g[j].size()){
    //             DEBUG2(j,k);
    //             DEBUG(g[j][k]);
    //         }
    //     }

    ans = min(ans, temp);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    
    cin>>n>>a[0]>>a[1]>>a[2];
    
    REP(i,n){
        cin>>l[i];
    }

    dfs(0);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
x=gi
def divisors(num)
  return [1] if num == 1

  pows = []
  # 0乗、1乗・・・した値を入れる
  num.prime_division.each do |b, r|
    pow = []
    0.upto(r).each do |n|
      pow << b ** n
    end

    pows << pow
  end

  first_array = pows.shift
  return first_array if pows.size == 0

  result = first_array.product(*pows)
  result.map do |item|
    item.inject { |sum, i| sum * i }
  end.sort
end

bb = -(x**(1.0/5))
if (bb-bb.to_i).abs<0.00000001
  b=bb.to_i
  ar=[b-1,b,b+1]
  ar.each do |i|
    putsend([0,i].join(" ")) if i**5==-x
  end
end

divs=divisors x

divs.each do |i|
  pair=x/i
  0.upto 1000 do |a|
    b=a-i
    if a**5-b**5==x
      putsend([a,b].join(" "))
    end
  end
end

Measured memory_bytes: 14804
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
double ans;

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>n;
    rep(i,n){
        cin>>a;
        ans=ans+(double)1.0/(double)a;
    }
    ans=1.0/ans;
    doublecout(ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,i,x;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		if(i%3==0){
			printf(" %d",i);
		}else{
			x=i;
			while(x!=0){
				if(x%10==3){
					printf(" %d",i);
					break;
				}else{
					x/=10;
				}
			}
		}
	}
	printf("\n");
}
				


Measured memory_bytes: 2104
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


const int MAX_N = 2100000;
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

long long inv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a/b;
        a -= t*b; swap(a, b);
        u -= t*v; swap(u, v);
    }
    return mod(u, m);
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

long long n, a, b;

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    while (cin >> n >> a >> b) {
        if (n == 0) break;
        long long d = gcd(a, b);
        a /= d; b /= d;
        long long r = inv(a, b);

        int res = n;
        for (long long i = 1; i <= n; ++i) {
            if (i % d != 0) continue;
            long long c = i / d;
            long long x = mod(r * c, b);
            
            if (x * a <= c) --res;
        }
        
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

const int mod=1000000007;
int *fact=NULL;
int *ifact=NULL;
void init(int n){
  fact=(int *)malloc(sizeof(int)*(n+1));
  ifact=(int *)malloc(sizeof(int)*(n+1));
  fact[0]=1;
  int i;
  for(i=1;i<=n;i++) fact[i]=(int64)fact[i-1]*i%mod;
  int t=1;
  int s=fact[n];
  int m=mod-2;
  while(m>0){
    if(m&0x01) t=(int64)t*s%mod;
    s=(int64)s*s%mod;
    m>>=1;
  }
  ifact[n]=t;
  for(i=n-1;i>=0;i--) ifact[i]=(int64)ifact[i+1]*(i+1)%mod;
  return;
}

int comb(int n,int k){
  return (int64)fact[n]*ifact[k]%mod*ifact[n-k]%mod;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  init(n+100);
  int ans=1;
  int k;
  for(k=2;k*k<=m;k++){
    if(m%k==0){
      int c=0;
      while(m%k==0){
	c++;
	m/=k;
      }
      ans=(int64)ans*comb(n-1+c,c)%mod;
    }
  }
  if(m>1){
    ans=(int64)ans*comb(n-1+1,1)%mod;
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;

int main(){
    int H,N;
    cin >> H >> N;
    vector<int> A(N);
    int sum=0;
    for(int i=0; i<N; i++){
        cin >> A.at(i);
        sum += A.at(i);
    }
    if(sum<H) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 640
import heapq

def dijkstra(G, s, dist):
    dist[s] = 0
    Q = [[0,s]]
    heapq.heapify(Q)

    while(len(Q) > 0):
        cur_d, cur_v = heapq.heappop(Q)
        cur_d *= -1
        
        if(cur_d > dist[cur_v]): continue

        for e in G[cur_v]:
            to, cost = e[0], e[1]
            if(dist[cur_v] + cost < dist[to]):
                dist[to] = dist[cur_v] + cost
                heapq.heappush(Q, [-dist[to], to])

N = int(input())

G = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int,input().split())
    u, v = u-1, v-1
    G[u].append([v,w])
    G[v].append([u,w])

dist = [1e18] * N
dijkstra(G,0,dist)

for d in dist:
    if d % 2 == 0:
        print(0)
    if d % 2 == 1:
        print(1)



Measured memory_bytes: 50332
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define p push
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	string s;
	scans(s);
	int ans = 7;
	if (s == "SUN") {
		ans -= 0;
	}
	else if (s == "MON") {
		ans -= 1;
	}
	else if (s == "TUE") {
		ans -= 2;
	}
	else if (s == "WED") {
		ans -= 3;
	}
	else if (s == "THU") {
		ans -= 4;
	}
	else if (s == "FRI") {
		ans -= 5;
	}
	else {
		ans -= 6;
	}
	printf("%d\n", ans);

	Please AC;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
g = {}
ans = 0
for i, a in enumerate(A):
    g[a] = N
    for j, b in enumerate(A):
        if a < b:
            g[a] -= 1
        if  i < j and a > b:
            ans += 1

ans = ans * K
S = (K * (K-1))//2
for v in A:
    i = g[v]
    ans += S * (N - i)

print(ans % (10**9+7))

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var H = long.Parse(ReadLine());

        var attackCount = 0L;

        while(H != 0)
        {
            H /= 2;
            attackCount = attackCount * 2 + 1;
        }

        WriteLine(attackCount);
    }
}


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

int		main()
{
	int A,B,C,X;
	cin >> A >> B >> C >> X;
	int h = 0,i, count = 0;
	while (h <= A)
	{
		i = 0;
		while (i <= B)
		{
			if ((X - 500 * h - 100 * i) / 50 <= C && (X - 500 * h - 100 * i) % 50 == 0
			&& (X - 500 * h - 100 * i) >= 0)
				count++;
			i++;
		}
		h++;
	}
	cout << count << endl;
}

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

int main(){
    for(;;){
        int n, x;
        cin >> n >> x;
        if(n == 0 && x == 0) break;
        int count = 0;
        for(int i = 1; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                for(int k = j+1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}


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

int main(void) {
  long long N;
  cin >> N;
  vector<long long> A(N), B(N), C(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (long long i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (long long i = 0; i < N; i++) {
    cin >> C[i];
  }
  A.push_back(0);
  A.push_back(LONG_LONG_MAX);
  C.push_back(0);
  C.push_back(LONG_LONG_MAX);
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  long long ans = 0;
  for (long long i = 0; i < N; i++) {
    long long A_num = 0;
    long long ok = 0;
    long long ng = N + 1;
    while (abs(ok - ng) > 1) {
      long long mid = (ok + ng) / 2;
      if (A[mid] < B[i])
        ok = mid;
      else
        ng = mid;
    }

    A_num = ok;

    ok = N + 1;
    ng = 0;
    while (abs(ok - ng) > 1) {
      long long mid = (ok + ng) / 2;
      if (C[mid] > B[i])
        ok = mid;
      else
        ng = mid;
    }

    ans += A_num * (N + 1 - ok);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,X;
  cin >> N >> X;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  int sum=0,count=0;
  for(int i=0;i<N;i++){
    sum+=A.at(i);
    count++;
    if(sum>X){
      count--;
      break;
    }
    else if(sum==X){
      break;
    }
  }
  if(sum<X){
    count--;
  }
  cout << count << endl;
}

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

int main() {
	int  right = 0, diamond = 0;
	int a, b, c;
	while (scanf("%d,%d,%d", &a, &b, &c) == 3) {
		if (a*a + b*b == c*c) right++;
		if (a == b) diamond++;
	}
	cout << right << endl << diamond << endl;
	return 0;
}

Measured memory_bytes: 0
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var N, M int
	fmt.Fscan(reader, &N, &M)
	uf := newUF(N)
	for i := 0; i < M; i++ {
		var a, b int
		fmt.Fscan(reader, &a, &b)
		uf.unite(a-1, b-1)
	}
	fmt.Println(uf.countTree() - 1)

}

type unionFind struct {
	pair []int
	n    int
}

func newUF(N int) *unionFind {
	uf := new(unionFind)
	uf.n = N
	pair := make([]int, N)
	for i := 0; i < N; i++ {
		pair[i] = -1
	}
	uf.pair = pair
	return uf
}
func (uf unionFind) unite(x int, y int) {
	rx := uf.root(x)
	ry := uf.root(y)
	if rx != ry {
		uf.pair[ry] += uf.pair[rx]
		uf.pair[rx] = ry
	}
}
func (uf unionFind) root(x int) int {
	if uf.pair[x] < 0 {
		return x
	}
	uf.pair[x] = uf.root(uf.pair[x])
	return uf.pair[x]
}
func (uf unionFind) same(x int, y int) bool {
	rx := uf.root(x)
	ry := uf.root(y)
	return rx == ry
}
func (uf unionFind) countTree() int {
	ans := 0
	checked := make([]bool, uf.n)
	for i := range checked {
		r := uf.root(i)
		if !checked[r] {
			checked[r] = true
			ans++
		}
	}
	return ans
}
func (uf unionFind) size(x int) int {
	return -uf.pair[uf.root(x)]
}


Measured memory_bytes: 6044
import sys
readline = sys.stdin.readline
from collections import deque
directions = ((-1, 0), (1, 0), (0, -1), (0, 1))

def main():
    H, W = map(int, readline().rstrip().split())
    mat = [list(readline().rstrip()) for _ in range(H)]

    start = []
    for h in range(H):
        for w in range(W):
            if mat[h][w] == '#':
                start.append((h, w))
    
    res = 0
    que = deque(start)
    while que:
        next_que = deque()
        for h, w in que:
            for dh, dw in directions:
                if not (0 <= h+dh < H and 0 <= w+dw < W):
                    continue
                if mat[h+dh][w+dw] == '#':
                    continue
                mat[h+dh][w+dw] = '#'
                next_que.append((h+dh, w+dw))

        res += 1
        que = next_que

    print(res - 1)


if __name__ == '__main__':
    main()

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

int main()
{
  int x[5];
  for(int i=0;i<5;i++)
  {
    cin >> x[i];
    if(x[i]==0)
    {
      cout << i +1 << endl;
      return 0;
    }
  }
  return 0; 
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long x = sc.NextLong();

        string answer = x >= 30 ? "Yes" : "No";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

using namespace std;
typedef long long ll;

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int cnt = 0;
    for (int i = l; i <= r; i++) {
        if (i % d == 0) cnt++;
    }
    cout << cnt << "\n";
}


Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int A, B, C, K; cin >> A >> B >> C >> K;
    int ans = 0;
    ans += min(A, K);
    K -= min(A, K);
    if (K > 0)
    {
        K -= min(B, K);
    }
    if (K > 0)
    {
        ans -= K;
    }
    cout << ans << endl;
}

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

struct Node {
  int parent;  // 節点の親
  int left;    // 節点の一番左の子
  int right;   // 節点の右隣の兄弟
  int depth;
  int height;
};

int setHeight(Node T[], int u) {
  int h1 = 0, h2 = 0;
  if (T[u].right != NIL) h1 = setHeight(T, T[u].right) + 1;
  if (T[u].left != NIL)  h2 = setHeight(T, T[u].left)  + 1;
  return T[u].height = max(h1, h2);
  // return T[u] = max(h1, h2);
}

void setDepth(Node T[], int u, int d) {
  if (u == NIL) return;
  T[u].depth = d;
  setDepth(T, T[u].right, d+1);
  setDepth(T, T[u].left, d+1);
}

int getSibling(Node T[], int u) {
  if (T[u].parent == NIL) return NIL;
  else if (T[T[u].parent].left == u) return T[T[u].parent].right;
  else return T[T[u].parent].left;
}

int getDegree(Node T[], int u) {
  int sum = 0;
  // if(T[u].right != NIL) sum += getDegree(T, T[u].right) + 1;
  // if(T[u].left  != NIL) sum += getDegree(T, T[u].left) + 1;
  if(T[u].right != NIL) sum += 1;
  if(T[u].left != NIL) sum += 1;
  return sum;
}

string getType(Node T[], int u) {
  if(T[u].parent == NIL) return "root";
  else if(T[u].left == NIL && T[u].right == NIL) return "leaf";
  else return "internal node";
}

int main() {
  int n; cin>>n;
  Node T[n];

  rep(i, n) T[i].parent = T[i].right = T[i].left = NIL;

  rep(i, n) {
    int id, l_child, r_child;
    cin>>id>>l_child>>r_child;

    T[id].left = l_child;
    T[id].right = r_child;

    if(l_child != NIL) T[l_child].parent = id;
    if(r_child != NIL) T[r_child].parent = id;
  }

  int root;
  rep(i, n) if(T[i].parent == NIL) root = i;
  setDepth(T, root, 0);
  setHeight(T, root);

  rep(i, n) {
    cout << "node " << i << ": ";
    cout << "parent = " << T[i].parent << ", ";
    cout << "sibling = " << getSibling(T, i) << ", ";
    cout << "degree = " << getDegree(T, i) << ", ";
    cout << "depth = " << T[i].depth << ", ";
    cout << "height = " << T[i].height << ", ";
    cout << getType(T, i) << endl;
  }
  return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
// #include<vor>
using namespace std;
typedef long long int ll;
#define pb push_back
ll mod = 1e9+7;

ll powm(ll a , ll b , ll mod)
{
  ll res = 1;
  while(b)
  {
    if(b & 1)
    res = (res *a)%mod;
    a = (a*a)%mod;
    b>>1;
  }
  return res;
}
ll gcd(ll a , ll b);
ll power(ll x , ll y , ll m);

ll modInverse(ll a , ll m)
{
  ll g = gcd(a,m);
  if(g != 1)
  return 1;
  else
  return power(a,m-2,m);

}

ll power(ll x , ll y , ll m)
{
  if(y == 0)
  return 1;
  ll p = power(x , y/2 , m)%m;
  p = (p*p)%m;

  return (y%2 == 0) ? p : (x *p) % m;
}

ll gcd(ll a , ll b)
{
  if(a == 0)
  return b;
  return gcd(b%a , a);
}

void solve()
{
  ll k;
  cin>>k;
  ll sum = 0;
  for(ll i = 1 ;i<=k;i++)
  {
    for(ll j = 1 ; j<= k; j++)
    {
      for(ll p = 1; p<=k ;p++)
      {
        ll gcd = __gcd(j , p);
        gcd = __gcd(gcd, i);
        sum += gcd;
      }
    }
  }
  cout<<sum<<"\n";
}

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


Measured memory_bytes: 3628
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAXN 512
typedef long long ll;

int n, m;
bool done[MAXN] = {false};
vector<int> f[MAXN]; // friendのf

int main(void) {
    while (1) {
        cin >> n;
        cin >> m;
        if (n == 0 && m == 0) break;
        for (int i = 0; i <= n; i++) {
            done[i] = false;
            f[i].clear();
        }
        for (int i = 0; i < m; i++) {
            int a, b;
            cin >> a >> b;
            f[a].push_back(b); f[b].push_back(a);
        }
        for (int i = 0; i < f[1].size(); i++) {
            int a = f[1][i];
            done[a] = true;
            for (int j = 0; j < f[a].size(); j++) {
                done[f[a][j]] = true;
            }
        }
        int ret = 0;
        done[1] = false;
        for (int i = 1; i <= n; i++) {
            if (done[i]) {
                ret++;
            }
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 1360
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  cout << min(A+C, min(A+B, B+C)) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD				1000000007
#define MOD1			998244353
#define EPS				1e-9
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int tam = 100010;int ara[100010], arb[100010];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n;
	cin>>n;
	int maxa = 0, maxa1 = 0, ina, maxb = 0, maxb1 = 0, inb, a;
	mem(ara, 0), mem(arb, 0);
	fore(i, 0, n)
	{
		cin>>a;
		if(i&1)
		{
			ara[a]++;
		}
		else
			arb[a]++;
	}
	fore(i, 0, 100010)
	{
		if(ara[i] >= maxa)
		{
			maxa1 = maxa;
			maxa = ara[i];
			ina = i;
		}
		else
		{
			if(ara[i] > maxa1)
			{
				maxa1 = ara[i];
			}
		}
	}
	fore(i, 0, 100010)
	{
		if(arb[i] >= maxb)
		{
			maxb1 = maxb;
			maxb = arb[i];
			inb = i;
		}
		else
		{
			if(arb[i] > maxb1)
				maxb1 = ara[i];
		}
	}
	//cout<<ina<<' '<<maxa<<' '<<maxa1<<' '<<inb<<' '<<maxb<<' '<<maxb1<<'\n';
	if(ina == inb)
	{
		if(maxa1 + maxb > maxa + maxb1)
			maxa = maxa1;
		else
			maxb = maxb1;
	}
	cout<<n - maxb - maxa<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

s = []
for i in range(M):
    _, *tmp_s = map(int, input().split())
    s.append(tmp_s)
    
p = list(map(int, input().split()))

import numpy as np

s_matrix = []

for i in range(M):
    s_matrix.append([1 if x+1 in s[i] else 0 for x in range(N)])
    
s_matrix = np.array(s_matrix)

ans = 0

for i in range(2**N):
    on_off_pattern = list(format(i, '0%db' %N))
    on_nums = np.dot(s_matrix, np.array(list(map(int, on_off_pattern))))
    on_nums_mod2 = on_nums % 2

    if not False in (on_nums_mod2 == p):
        ans += 1
        
print(ans)

Measured memory_bytes: 12424
#include<bits/stdc++.h>
using namespace std;
int main()
{



        int a, b;

        cin >> a >> b;

        for (int i = 1; i <= 1000; i++) {
            if (i * 8/100 == a && i * 10/100 == b) {
                cout << i << endl;
                return 0;
            }
        }
        cout << -1 << endl;

        return 0;
    }



Measured memory_bytes: 256