akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/rope>
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
//
//template<class T> using Tree = tree<T, null_type, less<T>, rb_t_tag,t_order_statistics_node_update>;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
//const long long mod = 1000000007;
const long long mod = 998244353;

// watch this
//using ll = long long;
//typedef long long LL;
#define ll long long
#undef ll

const int mxN = 300010;

long long pow_mod(long long base, long long power) {
	long long res = 1;
	while (power) {
		if (power & 1)
			res = res * base % mod;
		base = base * base % mod;
		power >>= 1;
	}
	return res;
}

long long fact[mxN], inv[mxN];

void init() {
	fact[0] = fact[1] = inv[0] = inv[1] = 1;
	for (int i = 2; i < mxN; i++)
		fact[i] = i * fact[i - 1] % mod, inv[i] = pow_mod(fact[i], mod - 2);
}

long long NcR(long long N, long long R) {
	if (N < R)
		return 0;
	return (fact[N] * inv[R] % mod) * inv[N - R] % mod;
}

int main(int argc, char** argv) {
//#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
//#endif

	init();

	int N;
	long long A, B, K;
	cin >> N >> A >> B >> K;
	long long res = 0;
	for (long long a = 0; a <= N; a++) {
		long long b = K - a * A;
		if (b % B)
			continue;
		b /= B;
		if (b < 0 || b > N)
			continue;
		res = (res + NcR(N, a) * NcR(N, b)) % mod;
	}
	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 4992
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var ans = n % 1000;
            Console.WriteLine(ans > 0?1000-ans:0);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 27544
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
	int a, b, d, r;
	double f;
	cin >>a >>b;
	d=a/b;
	r=a%b;
	f=(double)a/b;
	cout <<d <<" " <<r <<" ";
	printf("%.8lf\n", f);
	return 0;
}

Measured memory_bytes: 1240
//vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
//includeとusing
#include <bits/stdc++.h>
using namespace std;
//型名省略
using ll = long long;
using st = string;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using pcc = pair<char, char>;
//定数
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define REP(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define RREP(i,x,n) for(ll i = (ll) n - 1; i >= x; i--)
#define each(i,A) for(ll i: (vl) A)
#define all(A) A.begin(), A.end()
#define Size(A) ll(A.size())
//入力
template<typename T> T input() {T x; cin >> x; return x;}
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
//余り切り上げ
ll ceil(ll a,ll b) {return (a + b - 1) / b;}
//最大値・最小値
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b) {a = b; return true;} return false;}
//最大公約数
ll gcd(ll a,ll b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
//最小公倍数
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//n乗の余り
ll modpow(ll x,ll n,ll mod){ll res=1;for(ll i=0;i<n;i++){res=res*x%mod;}return res;}
ll MODpow(ll x,ll n){ll res=1;for(ll i=0;i<n;i++){res=res*x%MOD;}return res;}


/*--------------------------------------------------------------------------*/

//main関数
int main() {
    set<ll> st;
    rep(i,3){
        ll a;
        cin >> a;
        st.insert(a);
    }
    cout << st.size() << endl;
}



Measured memory_bytes: 3576
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        List<Long> list = new ArrayList<>();
        for(long i = 1; i * i <= N; i++) {
            if (N % i == 0) {
                list.add(i);
            }
        }
        long answer = String.valueOf(N).length();
        for (long x : list) {
            long y = N / x;
            answer = Math.min(answer, Math.max(String.valueOf(x).length(), String.valueOf(y).length()));
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23764
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace C_ABC171
{
    class MainClass
    {

        static long[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            long n = s[0];
            var ans = new StringBuilder("");

            while (n!=0)
            {
                n--;
                // WriteLine("n : {0}",n);
                ans.Append((char)(n%26 + 'a'));
                n /= 26;
            }
               

            var sb = ans.ToString();
            var rev = new string(sb.Reverse().ToArray());
            WriteLine(rev);

        }
    }
}


Measured memory_bytes: 28272
import java.util.Scanner;

public class Main { //クラス名はMain
    public static void main(String[] args) {
        //コード
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        boolean j = true;

        for(int i=0; i<n ; i++){
            int a = Integer.parseInt(sc.next());
            if(a%2 == 0){
                if(a%3 != 0 && a%5 != 0){
                    j = false;
                }
            }
        }
        if(j){
            System.out.println("APPROVED");
        }else{
            System.out.println("DENIED");
        }
    }
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

int solve(int, const vector<int>& xs)
{
    map<int, int> hs;

    for (auto x : xs)
        ++hs[x];

    int ans = 0;

    for (auto x : xs)
    {
        --hs[x];

        bool ok = true;

        for (int d = 1; d * d <= x; ++d)
        {
            if (x % d)
                continue;

            auto k = x / d;

            if ((hs.count(d) and hs[d] > 0) or (hs.count(k) and hs[k] > 0))
            {
                ok = false;
                break;
            }
        }

        ans += (ok ? 1 : 0);
        ++hs[x];
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> xs(N);

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

    auto ans = solve(N, xs);

    cout << ans << '\n';

    return 0;
}


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

t = 1
ans = 0
for i in range(n):
  if t != a[i]:
    ans += 1
    a[i] = -1
  else:
    t += 1

if all([i == -1 for i in a]):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 26580
#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 N;
  cin >> N;
  vector<int> d(N);
  REP(i, N) cin >> d[i];
  
  sort(ALL(d));
  if(d.size()%2 == 0){
    cout << d.at(N/2) - d.at(N/2-1) << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 640
from math import pi, tan
EPS = 0.0000000001

def f(a, b, theta):
    if theta > pi * 0.5 - EPS:
        ret = 0.0
    elif a * tan(theta) <= b:
        ret = a**2 * b - a**3 * tan(theta) * 0.5
    else:
        ret = a * b**2 * 0.5 / tan(theta)

    return ret

a, b, x = map(int, input().split())

ok = pi * 0.5
ng = 0.0
while ok - ng >= EPS:
    mid = (ok + ng) * 0.5
    if f(a, b, mid) < x:
        ok = mid
    else:
        ng = mid
print("{:.10f}".format(ok / pi * 180))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


main(){
  int m,k;
  cin>>m>>k;
  int n=(1<<m);

  if(m==0&&k==0){
    cout<<0<<' '<<0<<endl;
    return 0;
  }

  bool b[(1<<m)]={};
  vector<P> v;
  rep(i,n){
    if(b[i]) continue;
    int a=i^k;
    if(a>=n){
      cout<<-1<<endl;
      return 0;
    }
    
    b[i]=true;
    b[a]=true;
    v.PB(P(i,a));
//    cout<<i<<' '<<a<<endl;
  }


 

  if(v.size()%2){
    cout<<-1<<endl;
    return 0;
  }

  if(v[0].F==v[0].S){
    rep(i,v.size()){
      cout<<v[i].F<<' '<<v[i].S<<' ';
    }
    cout<<endl;
  }

  else{
    for(int i=0;i<v.size();i+=2){
      cout<<v[i].F<<' '<<v[i+1].S<<' '<<v[i+1].F<<' '<<v[i].F<<' '<<v[i].S<<' '<<v[i+1].F<<' '<<v[i+1].S<<' '<<v[i].S<<' ';
    }
    cout<<endl;
  }

}



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

using ll = long long;

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> p(A), q(B), r(C);
    vector<pair<int, int>> t;
    rep(i, A) {
        cin >> p[i];
        t.push_back(make_pair(p[i], 1));
    }
    rep(i, B) {
        cin >> q[i];
        t.push_back(make_pair(q[i], 2));
    }
    rep(i, C) {
        cin >> r[i];
        t.push_back(make_pair(r[i], 0));
    }
    ll ans = 0;
    int red = 0, green = 0, nocolor = 0;
    sort(t.begin(), t.end());
    for (int i = t.size() - 1; i >= 0; i--) {
        int c = t[i].second;
        if (c == 1) {
            if (red < X) {
                red++;
                ans += t[i].first;
            }
        }
        if (c == 2) {
            if (green < Y) {
                green++;
                ans += t[i].first;
            }
        }
        if (c == 0) {
            nocolor++;
            ans += t[i].first;
        }
        if (red + green + nocolor == X + Y) break;
    }
    cout << ans << "\n";
}

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

ans = 0
if N >= 3 and M >= 3:
    ans = (N - 2) * (M - 2)
elif N == 1 and M >= 3:
    ans = M - 2
elif N >= 3 and M == 1:
    ans = N - 2
elif N == 1 and M == 1:
    ans = 1
else:
    ans = 0

print(ans)


Measured memory_bytes: 2940
from math import gcd
while True:
  try:
    n = int(input())
    if not n: break
    lst = [[]]
    weight = [-1 for i in range(n + 1)]
    def setWeight(n):
      p,q,r,b = lst[n]
      if weight[n] != -1:pass
      elif r == 0 and b == 0:
        weight[n] = (p + q) // gcd(p,q)
      elif r == 0:
        setWeight(b)
        wb = weight[b]
        g = gcd(wb * q, p)
        lcm = wb * q * p // g
        weight[n] = lcm // q + lcm // p
#        print("wr:",str(lcm//p),"wb:",str(wb),"g:",g,"p:",p,"lcm",lcm)
      elif b == 0:
        setWeight(r)
        wr = weight[r]
        g = gcd(wr * p, q)
        lcm = wr * p * q // g
        weight[n] = lcm // p + lcm // q
      else:
        if weight[r] == -1: setWeight(r)
        if weight[b] == -1: setWeight(b)
        wr = weight[r]
        wb = weight[b]
        g = gcd(wr * p, wb * q)
        lcm = wr * p * wb  * q // g
        weight[n] = lcm // p + lcm // q
    for i in range(n):
      lst.append(list(map(int,input().split())))
    for i in range(0,n):
      if weight[i + 1] == -1:
        setWeight(i+1)
    print(max(weight))
#    print(weight)
  except EOFError:
    break




Measured memory_bytes: 5684
#ソートしてでかいやつから割引券使っていって、次に値段が高いやつよりも値段が低くなれば次にいく。
#これを繰り返せばいい。
#一周してもまだ割引券が余っていればもう一度ソートして同じことをする。
#途中で割引券がなくなれば終了して、合計を計算する。
#実際に買い物をする順番は気にしなくていい。どこで何枚使うのが最適かが分かればいい
#ということは割引券を使うたび毎回ソートする？
#毎回ソートしてるとやっぱりTLEになる。次に値段が高いやつよりも値段が低くなれば次にいく。でいい

#n,m = map(int,input().split())
#A = list(map(int,input().split()))
#print(A)
#A.sort(reverse=True)
#while m!=0:
#  while A[0] > A[1]:
 #   M_A = max(A)
  #  A[0] = M_A //2
   # m -= 1
  #A.sort(reverse=True)
#print(sum(A))

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=a[i]*(-1)
  
import heapq
#小さい順に並べる
heapq.heapify(a)
for j in range(m):
  # 最小値を取り出して-1をかけ,bとする。
  b=heapq.heappop(a)*(-1)
  # b//2に-1をかけて,aに入れる。
  heapq.heappush(a,(b//2)*(-1))
  #print(a)
c=sum(a)
print(c*(-1))
  
  



Measured memory_bytes: 14252
import collections
import math

url = "https://atcoder.jp//contests/abc159/tasks/abc159_d"


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    input()
    t = list(map(int, input().split()))
    col = collections.Counter(t)
    com = {}
    al = 0
    for key in col:
        if col[key] < 2:
            com[key] = 0
        else:
            com[key] = combinations_count(col[key], 2)
        al += com[key]
    for v in t:
        c = col[v] - 1
        if c <= 1:
            c = 0
        else:
            c = com[v] - c
        tmp = (al - com[v]) + c
        print(tmp)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32032
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections


def solve(N: int, A: "List[int]"):
    c = collections.Counter(A)
    d = list(c.values())
    print(len([dd for dd in d if dd % 2 == 1]))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18360
#include <bits/stdc++.h>
//#include <boost/array.hpp>
//#include <boost/range/numeric.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
//using namespace boost::multiprecision;

constexpr long long INF = LLONG_MAX;
constexpr long long MOD = 1000000007;
constexpr long double PI = M_PI;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define CALL(x) x.cbegin(),x.cend()
#define RALL(x) x.rbegin(),x.rend()
#define CRALL(x) x.crbegin(),x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\n'

#define ACCM(arr) accumulate(ALL(arr),0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void veccin(vector<T>& v) {
    for (auto && e : v) { cin >> e; }
}

template < typename T >
inline void dbg(T a) { cerr << a << ' '; }

ll n, m, k;
ll ans = 0, sum = 0, cnt = 0;
//ld d;
string s, t/*1, s2, s3*/;
char c/*1, c2, c3*/;
bool flag = false;

/*--------------------template--------------------*/

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

    cin >> s >> t;
    Yes(s[0]==t[0]&&t.find(s)!=string::npos);
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define setbits __builtin_popcount 
#define big 1e9+7
using namespace std;
ll n,k,m,flag,mod,cnt;
ll a[500005];
string s;
int main()
{
	IOS
	ll x,y;
	char ch;
	cin>>ch;
	if(ch != 'z')
		cout<<(char)(ch+1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <cstdlib>
#include <queue>
#include <vector>

using namespace std;
int main() {
	string s;
	int q;
	priority_queue <int> Q;
	while (cin >> s ) {
		if ( s == "insert" ) {
			cin >> q;
			Q.push(q);
		}
		else
			if ( s == "extract" ) {
				int n = Q.top();
				Q.pop();
				cout << n << endl;
			}
		}
}

Measured memory_bytes: 6240
#include <cstdio>

double abs(double n) {return n>0?n:-n;}

int main() {
  double q;
  while(scanf("%lf",&q), q>0) {
    double x = q/2;
    while (abs(x*x*x-q) >= 0.00001*q)
      x = x-(x*x*x-q)/(3*x*x);
    printf("%lf\n",x);
  }
}

Measured memory_bytes: 1076
s=str(input())
n=len(s)
ans=0
l=[0 for i in range(2019)]
now=l[int(s[n-1])]
r=1
for i in range(1,n+1):
  now=(now+int(s[-i])*r)%2019
  l[now]+=1
  r=r*10
  r=r%2019
ans+=l[0]
for i in l:
  ans+=int(i*(i-1)//2)
print(ans)
#print(l)

Measured memory_bytes: 9300
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int a, b;
    string s;
    cin >> a >> b >> s;

    bool is_postal_code = true;
    for (int i = 0; i < a+b+1; i++) {
        if (i == a){
            if (s[i] != '-') {
                is_postal_code = false;
                break;
            }
        } else {
            if (s[i] < '0' || '9' < s[i]) {
                is_postal_code = false;
                break;
            }
        }
    }

    cout << (is_postal_code ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#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);
	int n;
	cin>>n;
	ll ans =0 ;
	for(int i = 1 ; i<=n; i++)
		if(i%3!=0 && i%5!=0)
			ans +=i;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables ***************/
int h, w;
vector<string> s;
int g[55][55];
/**********************************************/

void bfs(int y, int x, int cnt){
    g[y][x] = cnt;
    if(y == h-1 && x == w-1) return;
    
    if(x+1 < w && g[y][x+1] > cnt+1 && s[y][x+1] == '.') bfs(y, x+1, cnt+1);
    if(x-1 >= 0 && g[y][x-1] > cnt+1 && s[y][x-1] == '.') bfs(y, x-1, cnt+1);
    if(y+1 < h && g[y+1][x] > cnt+1 && s[y+1][x] == '.') bfs(y+1, x, cnt+1);
    if(y-1 >= 0 && g[y-1][x] > cnt+1 && s[y-1][x] == '.') bfs(y-1, x, cnt+1);
    
}

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

    cin >> h >> w;
    s.resize(h);
    REP(i, 55) REP(j, 55) g[i][j] = INF;
    REP(i, h) cin >> s[i];

    int ans = 0;
    REP(i, h) REP(j, w) if(s[i][j] == '.') ans++;
    bfs(0, 0, 1);
    if(g[h-1][w-1] != INF) cout << ans - g[h-1][w-1] << endl;
    else cout << (-1) << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
ll s;

ll calc3(ll x) {
    return x / 3;
}

ll calc5(ll x) {
    return x / 5;
}

ll calc15(ll x) {
    return x / 15;
}

ll calc3(ll a,ll b) {//[a,b)の3の倍数
    return calc3(b-1) - calc3(a-1);
}

ll calc5(ll a,ll b) {//[a,b)の5の倍数
    return calc5(b-1) - calc5(a-1);
}

ll calc15(ll a,ll b) {//[a,b)の15の倍数
    return calc15(b-1) - calc15(a-1);
}

ll calc(const ll x) {
    ll beki = 10;
    ll ret = 0;
    ll i = 1;
    for(i = 1;beki < x;i++,beki*=10) {
        ll I = beki - beki / 10;
        ll a = calc3(beki/10,beki);
        ll b = calc5(beki/10,beki);
        ll c = calc15(beki/10,beki);

        ret += 4 * a + 4 * b + (I - a - b + c) * i;
    }

    ll I = x + 1 - (beki / 10);
    ll a = calc3(beki/10,x+1);
    ll b = calc5(beki/10,x+1);
    ll c = calc15(beki/10,x+1);

    ret += 4 * a + 4 * b + (I - a - b + c) * i;

    return ret;
}

ll C(ll x) {
    return (calc(x) >= s);
}

ll lower_bound(ll s,ll t) {
    ll lb = s - 1,ub = t;

    while(ub - lb > 1) {
        ll mid = (ub + lb) / 2;
        (C(mid) ? ub : lb) = mid;
    }
    return ub;
}


int main() {
    /*for(int i = 1;i <= 10000;i++) {
        ll cou = 0;
        for(int j = 1;j <= i;j++) {
            if(j % 3 == 0 || j % 5 == 0) {
                if(j % 3 == 0)cou+=4;
                if(j % 5 == 0)cou+=4;
            }else {
                ll k = j;
                while(k > 0) {
                    cou++;
                    k/=10;
                }
            }
        }
        cout << cou << " " << calc(i) << endl;
    }*/
    cin >> s;

    ll start = lower_bound(1,1e18 + 1);

    string ans = "";
    for(ll i = start;i < start + 21;i++) {
        if(i % 3 == 0 || i % 5 == 0) {
            if(i % 3 == 0) {
                ans += "Fizz";
            }
            if(i % 5 == 0) {
                ans += "Buzz";
            }
        }else {
            ans += to_string(i);
        }
    }

    ll b;
    if(start % 15 == 0)b = 8;
    else if(start % 3 == 0 || start % 5 == 0){
        b = 4;
    }
    else b = to_string(start).size();
    ll d = b - (calc(start) - s) - 1;
    cout << ans.substr(d,20) << endl;
    return 0;
}


Measured memory_bytes: 3280
<?php
  fscanf(STDIN, "%d%d", $n, $k);
  fscanf(STDIN, "%d%d%d", $r, $s, $p);
  $t = trim(fgets(STDIN));
  $sco = array(
      "r" => $p,
      "s" => $r,
      "p" => $s
      );
//   print_r($sco);
  $ans = 0;
  for($i=0; $i<$k; $i++){
      $ans += $sco[$t[$i]];
  }
  for($i=$k; $i<$n; $i++){
      if($t[$i] == $t[$i-$k]){
          $t[$i] = "f";
      }else{
          $ans += $sco[$t[$i]];
      }
  }
  
  echo $ans;
  

Measured memory_bytes: 16468
cards = [[False for i in range(13)] for j in range(4)]
pattern = {"S": 0,  "H": 1,  "C": 2,  "D": 3}
Mark = ["S", "H", "C", "D"]


L = int(input())
for N in range(L):
    a = list(input().split())

    cards[pattern[a[0]]][int(a[1])-1] = True

for i in range(4):
    for j in range(13):
        if not cards[i][j]:
            print("{0} {1}".format(Mark[i], j+1))




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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<vector<int>> table(m, vector<int>(n));
  rep(i, m)
  {
    int k;
    cin >> k;
    rep(j, k)
    {
      int s;
      cin >> s;
      table[i][s - 1] = 1;
    }
  }
  vector<int> p(m);
  rep(i, m) cin >> p[i];
  int ans = 0;
  rep(i, 1 << n)
  {
    bool ok = true;
    rep(j, m)
    {
      int on = 0;
      rep(k, n)
      {
        if (table[j][k] == 1 && i & (1 << k))
          on++;
      }
      if (p[j] != on % 2)
        ok = false;
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

bool binarySearch(int A[], int x, int n)
{
	int left = 0;
	int right = n;
	while (left < right) {
		int mid = (left + right) / 2;
		if (A[mid] == x) return 1;
		else if (A[mid] < x) left = mid + 1;
		else right = mid;
	}
	return 0;	
}

int main()
{
	int *A, n, q, t, result = 0;

	scanf("%d", &n);
	A = new int[n];

	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);

	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d", &t);
		if (binarySearch(A, t, n)) result++;
	}
	printf("%d\n", result);

	delete[] A;
	return 0;
}

Measured memory_bytes: 1528
n, X = map(int, input().split())
x = list(map(int, input().split()))

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)

x.append(X)

dis = x[1] - x[0]
for i in range(n):
    dis = gcd(x[i + 1] - x[i], dis)

print(abs(dis))

Measured memory_bytes: 14224
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var input1 = Console.ReadLine().Split(' ');
			int n = int.Parse(input1[0]);
			int x = int.Parse(input1[1]);
			var input2 = Console.ReadLine().Split(' ');
			var q = from a in input2
					select int.Parse(a);
			var l = new List<int>(q);

			int count = 0;
			int d = 0;

			for (int i = 0; i < n + 1; i++)
			{
				if (0 < i)
				{
					d += l[i - 1];
				}
				if (d <= x)
				{
					count++;
				}
				else
				{
					break;
				}
			}
			Console.WriteLine(count);
		}
	}
}


Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 3005;
const int mod = 1000000007;

int f[maxn][maxn];

struct P {
  int x, y;

  bool operator<(const P &a) const {
    return x<a.x;
  }
} p[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> p[i].x >> p[i].y;
  }
  sort(p, p + n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= m; j++) {
      f[i + 1][j] = max(f[i][j], f[i + 1][j]);
      if(j==m)continue;
      int nxt = j + p[i].x;
      if (nxt >= m)nxt = m;
      f[i + 1][nxt] = max(f[i + 1][nxt], f[i][j] + p[i].y);
    }
  int ret = 0;
  for (int i = 0; i <= m; i++)ret = max(ret, f[n][i]);
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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

int main()
{
  int N; cin >> N;
  vector<int> a(N), b(N);
  REP(i, N) {
    a[i] = N*(i + 1);
    b[i] = N*(N - i);
  }
  REP(i, N) {
    int p; cin >> p;
    a[p - 1] += i;
  }
  REP(i, N) cout << a[i] << ' ';
  cout << endl;
  REP(i, N) cout << b[i] << ' ';
  cout << endl;

  return 0;
}

Measured memory_bytes: 768
n = int(input())
aList = list(map(int, input().split()))
count = 0

while True:
  flag = True
  for i in range(n):
    if aList[i] % 2 != 0:
      flag = False
    aList[i] /= 2
   
  if flag == False:
    break

  count += 1

print(count)

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

int main(){
  int N,l=10000000;
  cin>>N;
  vector<int> X(N);
  for(int &i:X)
    cin>>i;
  for(int i=1;i<100;i++){
    int k=0;
    for(int &j:X)
      k+=(j-i)*(j-i);
    l=min(l,k);
  }
  cout<<l<<endl;
}

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

/* 3
12 15 18
gcd = 3
-> 4 5 6
*/

int main()
{
    int n;

    cin>>n;
    vector<int> d(n),l(n),r(n);
    for(int i=0;i<n;++i)
        cin>>d[i];
    l[0] = d[0];
    r[n-1] = d[n-1];
    for(int i=1;i<n;++i)
        l[i] = __gcd(l[i-1], d[i]);
    for(int i=n-1;i>=0;--i)
        r[i] = __gcd(r[i+1], d[i]);
    int ans = 0;
    for(int i=1;i<n-1;++i)
        ans = max(ans, __gcd(l[i-1],r[i+1]));
    ans = max(ans,r[1]);
    ans = max(ans,l[n-2]);
    cout<<ans<<endl;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  double L;
  cin >> L;
 
  cout << fixed << setprecision(10) << (L/3.0)*(L/3.0)*(L/3.0) << endl;
  return 0;
}




Measured memory_bytes: 3840
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <deque>
#include <queue>
#include <climits>

using namespace std;

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v) sort(v.begin(), v.end())
#define SORTFUNC(v, func) sort(v.begin(), v.end(), func)
#define PRINT(v) REP(i, v.size()) printf("%d ", v[i]); cout << endl
#define SCI(n) int (n); scanf("%d", &(n))
#define SCL(n) ll (n); scanf("%I64d", &(n))
#define IN(n) scanf("%d", &(n))



int main(){
  int q;
  int l, r;
  cin >> q;
  bool issimilar[100010];
  bool isprime[100010];
  memset(issimilar, false, sizeof(issimilar));
  memset(isprime, true, 100010);
  FOR(i, 2, 100010){
    if(i%2 == 0){
      isprime[i] = false;
      continue;
    }
    for(int j = 3; j <= (int)pow(i, 0.5); j++){
      if(i%j==0){
        isprime[i] = false;
        break;
      }
    }
  }
  cout << endl;
  isprime[1] = false;
  isprime[2] = true;
  FOR(i, 2, 100010){
    issimilar[i] = isprime[i] && isprime[(i+1)/2];
  }
  int issimsum[100010];
  issimsum[2] = 0;
  FOR(i, 3, 100010){
    issimsum[i] = (issimilar[i] ? 1 : 0) + issimsum[i-1];
  }
  REP(i, q){
    cin >> l >> r;
    cout << issimsum[r] - issimsum[l-1] << endl;
  }

  return 0;
}
























// I'd like to scroll past the end of document using Atom but I seemigly have to use these blank lines instead


Measured memory_bytes: 1536
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
if k==0:
    sm = 0
    for i in range(n):
        a,b = inm()
        if a==0:
            sm += b
    print(sm)
    exit()
pat = [k]
for i in range(29,-1,-1):
    if (k>>i)%2>0:
        pat.append((k^(1<<i))|((1<<i)-1))
vpat = [0 for x in pat]
for i in range(n):
    a,b = inm()
    for m,p in enumerate(pat):
        ok = True
        for j in range(30):
            if (p>>j)%2 < (a>>j)%2:
                ok = False
                break
        if ok:
            vpat[m] += b
print(max(vpat))


Measured memory_bytes: 76524
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
/*
10 40 70
20 50 80
30 60 90
clang++ -x c++ -std=c++11 c.pp
 */
int main(){
    int n;
    cin >> n;
    vector< vector<int> > arr(n, vector<int>(3, 0));
    for(int i = 0; i < n; i++){
        for(int& x : arr[i]){
            cin >> x;
        }
    }

    for(int i = 1; i < n; i++){
        arr[i][0] += max(arr[i-1][1], arr[i-1][2]);
        arr[i][1] += max(arr[i-1][0], arr[i-1][2]);
        arr[i][2] += max(arr[i-1][1], arr[i-1][0]);
    }

    cout << max(arr[n-1][0], max(arr[n-1][1], arr[n-1][2]));
    return 0;
}

Measured memory_bytes: 5760
// ＡＢＣのＡ過去問を解くだけだよ

// フォント:Electroharmonix
// x:小文字(ｘ)    X:大文字(Ｘ)
// +:プラス(＋)    &:アンド(＆)

#include <bits/stdc++.h>

using namespace std;

void Main()
{
    int n;
    cin >> n;

    if (n <= 999)
        cout << "ABC";
    else
        cout << "ABD";
}

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

    //std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    return 0;
}

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

using namespace std;

int main(void)
{
	int N;
	cin >> N;
	int W;
	cin >> W;
	int w[N], v[N];
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	int V = 100 * 1000;
	unsigned long d[N][V+1];
	d[0][0] = 0;
	for (int j = 1; j <= v[0]; j++) {
		d[0][j] = w[0];
	}
	for (int j = v[0]+1; j < V+1; j++) {
		d[0][j] = LONG_MAX;
	}
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < V+1; j++) {
			unsigned long a = LONG_MAX, b = LONG_MAX;
			if (j >= v[i]) {
				a = d[i-1][j-v[i]] + w[i];
			}
			b = d[i-1][j];
			d[i][j] = min(a, b);
		}
	}
	for (int j = V; j >= 0; j--) {
		if (d[N-1][j] <= W) {
			cout << j << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 78336
N = str(input())
if N[-1] == '2' or N[-1] == '4' or N[-1] == '5' or N[-1] == '7' or N[-1] == '9':
    print('hon')
elif N[-1] == '0' or N[-1] == '1' or N[-1] == '6' or N[-1] == '8':
    print('pon')
elif N[-1] == '3': 
    print('bon')
else:
    pass

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

#define ll long long
#define ld long double
#define fi first
#define se second
#define pi 3.1415926535
#define mod1 1000000007
#define mod2 1000000009
#define mp make_pair
#define no_of_digits(n) floor(log10(n)) + 1
#define lcm(a, b) (a/__gcd(a,b)*b)
#define sdebug(n) cout << "\n' n = " << n << " '\n";

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  int dp[n];
  for(int i = 0; i < n; i++){
    dp[i] = mod1;
  }
  dp[0] = 0;
  for(int i = 0; i < n; i++){
    if(i < n-1){
      dp[i+1] = min(dp[i+1], dp[i]+abs(a[i]-a[i+1]));
    }
    if(i < n-2){
      dp[i+2] = min(dp[i+2], dp[i]+abs(a[i]-a[i+2]));
    }
  }
  cout << dp[n-1];
  return 0;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
  double W,H;
  cin >> W >> H;
  ll x,y;
  cin >> x >> y;
  double half = (W * H) / 2.00000;
  double half_x = W / 2;
  double half_y = H / 2;
  bool flag = false;
  if(x==half_x && y==half_y)flag = true;
  cout << half << " " << flag << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int in()
{
    int n = 0, c = getchar_unlocked();
    do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
    return n;
}
 
int dp[45];
 
int main()
{
    int n, i;
 
    n = in();
    dp[0] = 1, dp[1] = 1;
    for (i = 2; i <= n; i++) dp[i] = dp[i-1]+dp[i-2];
    printf("%d\n", dp[n]);
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {

int main(void) {
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a) {
    pr(k);
  } else if(k<=a+b) {
    pr(a);
  } else {
    pr(a-(k-a-b));
  }
  return 0;
}


Measured memory_bytes: 3632
# include "iostream"
# include "cstdio"

using namespace std;

const int maxn=2e1+10;
const int maxm=(1<<17)+10;

int N,Map[maxn][maxn],Max;
long long DP[maxm];

int main(){
	register int i,j,k;
	scanf("%d",&N);
	for(i=1;i<=N;i++){
		for(j=1;j<=N;j++){
			scanf("%d",&Map[i][j]);
		}
	}
	Max=(1<<N)-1;
	for(i=1;i<=Max;i++){
		for(j=1;j<=N;j++){
			if(!(i&(1<<(j-1)))) continue;
			for(k=j+1;k<=N;k++){
				if(!(i&(1<<(k-1)))) continue;
				DP[i]+=Map[j][k];
			}
		}
	}
	for(i=1;i<=Max;i++){
		for(j=i&(i-1);j;j=i&(j-1)){
			DP[i]=max(DP[i],DP[i^j]+DP[j]);
		}
	}
	printf("%lld",DP[Max]);
	return 0;
}

Measured memory_bytes: 768
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<cctype>
#include<cmath>
using namespace std;
int main()
{
	int a,b,k;
	cin >> a >> b >> k;
	if(2*k>=max(a,b)-min(a,b)+1)
	{
		for(int i=min(a,b);i<=max(a,b);i++)
		{
			cout << i << endl;
		}
		return 0;
	}
	for(int i=0;i<k;i++)
	{
		cout << min(a,b)+i << endl;
	}
	for(int i=k-1;i>=0;i--)
	{
		cout << max(a,b)-i << endl;
	}
	return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  int ans = INF;
  for(int i = 1; i <= 10000; i++) {
    if(i*8/100 == a && i*10/100 == b) ans = min(ans,i);
  }
  cout << (ans == INF? -1: ans) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
typedef long long LL;
int main() {
  LL N, A, B;
  scanf("%lld%lld%lld", &N, &A, &B);
  if (A >= N) printf("1\n");
  else if (A <= B) printf("-1\n");
  else {
    N -= A;
    printf("%lld\n", (N + A - B - 1) / (A - B) * 2 + 1);
  }
  return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

int roulette[4];
int X,Y,Z;
double dp[51][5001];

struct Data{
	int ev;
	int val;
};

int main(){
	while(~scanf("%d %d %d",&X,&Y,&Z)){
		if(X==Y && Y==Z && Z==0) break;

		for(int i=0;i<X;i++){
			scanf("%d",roulette+i);
		}
		map<int,Data> stage;
		for(int i=0;i<Z;i++){
			int N,E,A;
			scanf("%d %d %d",&N,&E,&A);
			Data d = {E,A};
			stage[N] = d;
		}


		fill((double*)dp,(double*)dp+51*5001,0.0);
		dp[0][0] = 1.0;

		for(int pos = 0; pos < Y; pos++){
			for(int coin=0;coin <= Y*100; coin++){
				if(dp[pos][coin]==0) continue;
				for(int i=0;i<X;i++){
					int next_pos = min(pos + roulette[i],Y);
					int next_coin = coin;

					if(next_pos < Y){
						if(stage[next_pos].ev==1){
							next_pos  = min(next_pos + stage[next_pos].val,Y);
						}
						else if(stage[next_pos].ev==2){
							next_coin += stage[next_pos].val;
						}
						else if(stage[next_pos].ev==3){
							next_coin -= stage[next_pos].val;
							if(next_coin <= 0) next_coin = 0;
						}
					}

					next_pos = min(next_pos,Y);
					dp[next_pos][next_coin] += dp[pos][coin]/(double)X;
				}
			}
		}

		double exp = 0.0;

		for(int coin=0;coin<=5000;coin++){
			exp += coin*dp[Y][coin];
		}

		printf("%d\n",(int)(exp));
	}
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<string> ans;
    vector<char> use{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'};
    ans.emplace_back("a");
    rep2(i, 1, N) {
        vector<string> tmp;
        rep(j, i + 1) {
            for (string s: ans) {
                set<char> ex;
                for (char c: s) {
                    ex.insert(c);
                }
                if (ex.size() >= j) {
                    tmp.push_back(s + use[j]);
                }
            }
        }
        ans = tmp;
    }
    sort(ans.begin(), ans.end());
    for (string s: ans) {
        cout << s << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 11036