akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>
#pragma comment(linker, "/STACK:836777216")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define N 105

int a[N];

int main(void) {
	int n, m;
	scanf("%d%d", &n, &m);
	int sum = 0;
	REP(i, n) {
		scanf("%d", &a[i]);
		sum += a[i];
	}

	sort(a, a + n);
	int cnt = 0;
	int min_vote = (sum + 4 * m - 1) / (4 * m);
	REPD(i, n) {
		if (a[i] >= min_vote) {
			cnt++;
		}
		else {
			break;
		}
	}

	if (cnt >= m) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	//scanf("%d", &n);
}

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

typedef struct pp
{
	char chName[20];
	int nT;
}P;

P In[LEN];
int nHead, nTail;
int n;

void enqueue(P x)
{
	In[nTail] = x;
	nTail = (nTail + 1) % (n + 2);
}

P dequeue()
{
	P ret = In[nHead];
	nHead = (nHead + 1) % (n + 2);
	return ret;
}

int main()
{
	int q, nTime = 0;
	P pTemp;
	scanf("%d %d", &n, &q);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%s %d", &In[i].chName, &In[i].nT);
	}
	nHead = 1;
	nTail = n + 1;
	while (nHead != nTail)
	{
		pTemp = dequeue();
		if (pTemp.nT <= q)
		{
			nTime += pTemp.nT;
			printf("%s %d\n", pTemp.chName, nTime);
		}
		else
		{
			nTime += q;
			pTemp.nT -= q;
			enqueue(pTemp);
		}
	}
	return 0;
}


Measured memory_bytes: 2852
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
int n;
int a[200000];
int q;
int b[200000],c[200000];
int sum=0;
map<int,int>mp;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
        mp[a[i]]++;
    }
    cin>>q;
    rep(i,q){
        cin>>b[i]>>c[i];
        sum+=(c[i]-b[i])*mp[b[i]];
        mp[c[i]]+=mp[b[i]];
        mp[b[i]]=0;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 11900
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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

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


int N;
vector<ll> a;

int main () {
  cin >> N;

  int ct = 0;
  ll tmp = 0;

  Rep(i, N) {
    ll A;
    cin >> A;
    if (A >= 0) ct++;
    tmp += abs(A);
    a.push_back(abs(A));
  }

  if ((N-ct) % 2 == 0) {
    cout << tmp << "\n";
  } else {
    sort(All(a));
    ll l = a[0];
    cout << tmp - 2 * l << "\n";
  }
}

Measured memory_bytes: 1400
using System;

public class Hello
{
    public static void Main()
    {
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            var n = int.Parse(line.Trim());
            var res = n % 39;
            if (res == 0) res = 39;
            Console.WriteLine("3C{0:00}", res);
        }
    }
}

Measured memory_bytes: 9264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,k;
  cin >> n >> k;
  ll ans=0;
  n++;
  for(ll i=k;i<=n;i++) {
    (ans+=1+i*(n-i))%=mod;
  }
  cout << ans << endl;
}

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

class Program
{
    static void Main()
    {
        var s =ReadLine();
        WriteLine(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]?"Bad":"Good");
    }
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int ans = 0;
		for(int i=0;i<n;i++) {
			int a = scan.nextInt();
			if(a%2==0) {
				if(a%3!=0&&a%5!=0) {
					ans = 1;
					break;
				}
			}
		}
		
		if(ans==0) {
			System.out.println("APPROVED");
		}else {
			System.out.println("DENIED");
		}
		
	}
	
}

Measured memory_bytes: 23764
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    long long int A,B,V,W,T;
    cin>>A>>V>>B>>W>>T;
    if(A<B){
        A+=V*T;
        B+=W*T;
        if(A<B)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    else if(A>B){
        A+=V*T*-1;
        B+=W*T*-1;
        if(A>B)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
const long long MOD = 1e9+7;
//aのMODbでの逆元
long long modinv(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);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//nCk
long long combi(int n,int k){
    k = min(k,n-k);
    long long p = 1;
    for(int i = n;i>=n-k+1;i--){
        p*=i;
        p%=MOD;
    }
    for(int i = 0;i<k;i++){
        p*=modinv((i+1),MOD);
        p%=MOD;
    }
    return p;
}
int main(){
    long long n,k;
    cin >> n >> k;
    if(k>=n){
        long long ans = combi(2*n-1,n-1);
        cout << ans << endl;
        return 0;
    }
    long long ans = 0;
    long long kaiz[2*n+1],kaiz_inv[2*n+1];
    kaiz[0]=kaiz_inv[0]=1;
    kaiz[1]=1;
    long long a = 1;
    rep(i,2*n){
        kaiz[i+2]=kaiz[i+1]*(a+1); 
        a++;
        kaiz[i+2]%=MOD;
    }
    rep(i,2*n){
        kaiz_inv[i+1]=modinv(kaiz[i+1],MOD);
        kaiz_inv[i+1]%=MOD;
    }
    long long tmp = 0;
    for(int i=0;i<=k;i++){
        long long a = kaiz[n-1];//nCi
        a*=kaiz_inv[i];
        a%=MOD;
        a*=kaiz_inv[n-i-1];
        a%=MOD;
        long long b = kaiz[n];//nCi
        b*=kaiz_inv[i];
        b%=MOD;
        b*=kaiz_inv[n-i];
        b%=MOD;
        a*=b;
        a%=MOD;
        ans+=a;
        ans%=MOD;
        //cout << a << endl;
    }
    ans%=MOD;
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    LL h, w;
    cin >> h >> w;

    LL a = h/2 + h%2;
    LL b = w/2 + w%2;
    LL c = h/2;
    LL d = w/2;

    if(!a || !b || !c || !d) {
        cout << 1 << endl;
        return 0;
    }
    cout << a*b + c*d << endl;
    return 0;
}

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

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef complex<double> com;

#define MOD 1000000007
#define PI 3.14159265359
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;

void test()
{
	ll n,m,k;
	cin>>n>>m>>k;

	vector<ll> a(n);
	vector<ll> b(m); 

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

	for(int i=0;i<m;i++)
		cin>>b[i];

	vector<ll> sumA(n+1); 
	vector<ll> sumB(m+1); 

	for(int i=0;i<n;i++)
	{
		sumA[i+1] = sumA[i] + a[i];
	}

	for(int i=0;i<m;i++)
	{
		sumB[i+1] = sumB[i] + b[i];
	}

	int total = 0;

	for(int i=0;i<=n;i++)
	{
		ll other = k - sumA[i];

		if(other<0)
			continue;

		int l = lower_bound(sumB.begin(),sumB.end(),other) - sumB.begin();

		if(l>m || sumB[l]>other)
			l--;

		total = max(total,i+l);
	}

	cout<<total<<endl;
}

int main()
{   
fast_io();
cout << fixed << setprecision(15);
int t = 1;

//cin>>t;

for(int i = 0; i < t; i++)
{
	test();
}
return 0;
}

Measured memory_bytes: 9504
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int main() {

	int N;
	cin >> N;

	vector<ll>A(N);

	ll total = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		total += A[i];
	}

	ll cost = 0;

	ll sumR = 0;
	ll sumL = 0;
	int t = 0;
	for (int i = 0; i < N; i++) {
		sumL += A[i];
		if (sumL >= total/2) {
			t = i;
			sumR = total - sumL;
			sumL = sumL - A[i];
			break;
		}
	}

	ll a = abs(sumL - sumR);

	cost = A[t] - a;
	

	cout << cost << endl;


	return 0;

}

Measured memory_bytes: 1792
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

M1 , _ = list(map(int, sys.stdin.buffer.readline().split()))
M2 , _ = list(map(int, sys.stdin.buffer.readline().split()))
print((M2 - M1) % 12)


Measured memory_bytes: 13600
#include<stdio.h>

int main(){
  char b;

  scanf("%c", &b);
  if(b=='A'){
    printf("T\n");
  }else if(b=='C'){
    printf("G\n");
  }else if(b=='G'){
    printf("C\n");
  }else if(b=='T'){
    printf("A\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
 
int main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i< n; ++i) cin >> a[i];
	int ans = 1e9;
	for (int i = 0; i+k <= n; ++i) {
		int l = a[i], r = a[i+k-1];
		if (l < 0 && r > 0) ans = min(ans,min(abs(l),r)+r+abs(l));
		else if (l >= 0) ans = min(ans,r);
		else ans = min(ans,abs(l));
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	

	ll A,B,C,K;
	cin>>A>>B>>C>>K;
	if(K%2==0){
		ce(A-B)
	}else{
		ce(B-A)
	}

}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, N):
        """
        N:要素数
        root:各要素の親要素の番号を格納するリスト.
             ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
        rank:ランク
        """
        self.N = N
        self.root = [-1] * N
        self.rank = [0] * N

    def __repr__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    def find(self, x):
        """頂点xの根を見つける"""
        if self.root[x] < 0:
            return x
        else:
            while self.root[x] >= 0:
                x = self.root[x]
            return x

    def union(self, x, y):
        """x,yが属する木をunion"""
        # 根を比較する
        # すでに同じ木に属していた場合は何もしない.
        # 違う木に属していた場合はrankを見てくっつける方を決める.
        # rankが同じ時はrankを1増やす
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.rank[x] > self.rank[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def same(self, x, y):
        """xとyが同じグループに属するかどうか"""
        return self.find(x) == self.find(y)

    def count(self, x):
        """頂点xが属する木のサイズを返す"""
        return - self.root[self.find(x)]

    def members(self, x):
        """xが属する木の要素を列挙"""
        _root = self.find(x)
        return [i for i in range(self.N) if self.find == _root]

    def roots(self):
        """森の根を列挙"""
        return [i for i, x in enumerate(self.root) if x < 0]

    def group_count(self):
        """連結成分の数"""
        return len(self.roots())

    def all_group_members(self):
        """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す"""
        return {r: self.members(r) for r in self.roots()}


import sys
input = sys.stdin.readline
n, q = map(int, input().split())
uf = UnionFind(n)
for i in range(q):
    t, u, v = map(int, input().split())
    if t:
        print(int(uf.same(u, v)))
    else:
        uf.union(u, v)


Measured memory_bytes: 75156
n = int(input())
shougen = [[] for i in range(n)]
max_num = 0

def check(li):
    co = 0
    for i in li:
        if i == '1':
            co += 1
    return co

for i in range(n):
    w = []
    a = int(input())
    for j in range(a):
        array = list(map(int, input().split()))
        w.append(array)
    shougen[i] = w


for i in range(2**n):
    flag = True
    people = str(format(i, 'b').zfill(n))
    if flag == True:
        for j in range(n):
            if people[j] == '1':
                if flag is True:
                    for k in range(len(shougen[j])):
                        to_people = shougen[j][k][0] - 1
                        if str(shougen[j][k][1]) != people[to_people]:
                            flag = False
                            break
                else:
                    break
    else:
        break
    if flag is True:
        num = check(people)
    if num > max_num:
        max_num = num

print(max_num)



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>string join(const v(T)&v){ stringstream s; rep(i,0,sz(v))s<<' '<<v[i]; return s.str().substr(1); }
template<class T>istream &operator>>(istream&i, v(T)&v){ fore(x,v){ i >> v; } return i; }
template<class T>ostream &operator<<(ostream&o, const v(T)&v){ o<<"["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const deque<T>&v){ o<<"deq["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T1,class T2>ostream &operator<<(ostream &o, const pair<T1,T2>&p){ o<<"("<<p.fi<<","<<p.se<<")"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const unordered_map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b){ if (a<b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if (b<a){ a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int N, D;
  cin >> N >> D;
  D = D*2 + 1;

  int ans = (N+D-1) / D;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
struct graph
{
    int head[maxn],nxt[maxn<<1],to[maxn<<1],w[maxn<<1],sz;
    void init(){memset(head,-1,sizeof(head));}
    graph(){init();}
    void push(int a,int b,int c){nxt[sz]=head[a],to[sz]=b,w[sz]=c,head[a]=sz++;}
    int& operator[](const int a){return to[a];}
}g;
int n,a[maxn],b[maxn],m;
struct BIT
{
    int bit[maxn];
    vector<pair<int,int> > update(int x,int k){
        vector<pair<int,int> >v;
        while(x<=m){
            if(bit[x]<k){
                v.push_back(make_pair(x,bit[x]));
                bit[x]=k;
            }
            x+=x&-x;
        }
        return v;
    }
    int query(int x){
        int tmp = 0;
        while(x){
            tmp=max(tmp,bit[x]);
            x-=x&-x;
        }
        return tmp;
    }
}bit;
int ans[maxn];
void dfs(int now,int pre)
{
    ans[now]=bit.query(a[now]-1)+1;
    vector<pair<int,int> >v=bit.update(a[now],ans[now]);;
    ans[now]=max(ans[now],ans[pre]);
    for(int i = g.head[now];~i;i = g.nxt[i]){
        if(g[i]==pre)continue;
        dfs(g[i],now);
    }
    for(int i = 0;i < v.size();++i){
        bit.bit[v[i].first]=v[i].second;
    }
}
int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;++i)scanf("%d",&a[i]),b[i]=a[i];
    sort(b+1,b+1+n);
    m = unique(b+1,b+1+n)-b-1;
    for(int i = 1;i <= n;++i)a[i]=lower_bound(b+1,b+1+m,a[i])-b;
    for(int i = 1;i < n;++i){
        int c,d;
        scanf("%d%d",&c,&d);
        g.push(c,d,0),g.push(d,c,0);
    }
    dfs(1,0);
    for(int i = 1;i <= n;++i)printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 38432
li = list(int(input()) for i in range(5))
#print(li)
k = int(input())

li1 = [(x - y) for x in li for y in li if x>y]
#print(li1)
if all(li1[i]<=k for i in range(len(li1))):
    print("Yay!")
else:
    print(":(")
          

Measured memory_bytes: 3060
N = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

x = 0
y = 0
for i in range(N):
    if a[i] > b[i]:
        x += (a[i] - b[i])
    elif a[i] < b[i]:
        y += (b[i] - a[i]) // 2

if x <= y:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 4600
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main()
{
        int a, b;
        cin >> a >> b;
        
       
       for (int i = 1; i<=1e4; i++)
       {
       		int a2 = i*8/100, b2 = i*10/100;
       		if(a2 == a && b2 == b) 
       		{
       			cout << i; return 0;
       		}

       }
       cout << -1;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long intl;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int b=0,w=0;
	for(int i=0;i<n;i++){
		if(s[i]=='#'){
			b++;
		}
		else{
			w++;
		}
	}
	int ans=1e9,cb=0,cw=0;
	for(int i=0;i<n;i++){
		ans=min(ans,cb+w);
		if(s[i]=='#'){
			cb++;
			b--;
		}
		else{
			cw++;
			w--;
		}
	}
	ans=min(ans,cb+w);
	cout<<ans<<endl;
}

Measured memory_bytes: 720
import sys
sys.setrecursionlimit(10**9)
from collections import deque

INF = 10**9
H,W = map(int,input().split())
G = [input() for _ in range(H)]
C = 0
for l in G:
    C += l.count("#")

def BFS(start,end,grid):
    queue = deque([])
    visited = []
    start += [1]
    dist = INF
    queue.append(start)
    while queue:
        label = queue.popleft()
        x = label[0]
        y = label[1]
        d = label[2]
        pos = [x,y]
        if pos == end:
            if d < dist:
                dist = d
        elif pos not in visited:
            visited.append(pos)
            if x+1 <= W-1:
                if [x+1,y] not in visited:
                    if grid[y][x+1] == ".":
                        queue.append([x+1,y,d+1])
            if x-1 >= 0:
                if [x-1,y] not in visited:
                    if grid[y][x-1] == ".":
                        queue.append([x-1,y,d+1])
            if y+1 <= H-1:
                if [x,y+1] not in visited:
                    if grid[y+1][x] == ".":
                        queue.append([x,y+1,d+1])
            if y-1 >= 0:
                if [x,y-1] not in visited:
                    if grid[y-1][x] == ".":
                        queue.append([x,y-1,d+1])
    return dist
res = BFS([0,0],[W-1,H-1],G)
if res == INF:
    print(-1)
else:
    print(H*W-res-C)

Measured memory_bytes: 3572
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: Partition
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  int mind = m;
  for (int i = 1; i * i <= m; i++) {
    int j = m / i;
    if (i * j == m) {
      if (i >= n) {
	mind = i;
	break;
      }
      if (j >= n && mind > j)
	mind = j;
    }
  }

  printf("%d\n", m / mind);
  return 0;
}


Measured memory_bytes: 256
N = int(input())

time_list = []

for i in range(N - 1):
    C, S, F = map(int, input().split())
    time_list.append(C + S)
    for j in range(0, i):
        t = time_list[j]
        if t < S:
            time_list[j] += S - t + C
        elif t % F != 0:
            time_list[j] += F - t % F + C
        else:
            time_list[j] += C

time_list.append(0)

for time in time_list:
    print(time)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int S[10010];

int main() {
    int n, q, t, cnt = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> S[i];
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> t;
        for (int j = 0; j < n; ++j) if (S[j] == t){cnt++; break;}
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3092
import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  ts <- (map read . words) <$> getLine :: IO [Int]
  m <- readLn :: IO Int
  pxs <- replicateM m $ (map read . words) <$> getLine :: IO [[Int]]

  let total = sum ts
  forM_ pxs $ \[p, x] ->
    print $ total - (ts!!(p - 1) - x)


Measured memory_bytes: 1020
//
//  main.cpp
//  graph
//
//  Created by ???????????? on 2017/10/22.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, const char * argv[]) {
    int n, i, j, id, num, node;
    scanf("%d", &n);
    int A[n][n];
    
    //initialize with 0
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            A[i][j] = 0;
        }
    }
    
    for (i = 0; i < n; i++){
        scanf("%d", &id);
        scanf("%d", &num);
        for(j = 0; j < num; j++){
            scanf("%d", &node);
            A[id-1][node-1] = 1;
        }
    }
    
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            if(j) cout << " ";
            cout<<A[i][j];
        }
        cout<<endl;
    }
    
//    std::cout << "Hello, World!\n";
    return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;

int n;
int f[200][20];
int p[200][20];

int main(){
  cin >> n;
  rep(i,1,n+1){
    rep(j,1,11)cin >> f[i][j];
  }
  rep(i,1,n+1)rep(j,0,11) cin >> p[i][j];
  int ans = -INTMAX;
  rep(b,1,(1<<10)){
    int cc = 0;
    rep(i,1,n+1){//店iについて
      int c = 0;
      rep(j,1,11)if(b&1<<(j-1))c+=f[i][j];
      cc += p[i][c];
    }
    ans = max(ans, cc);
  }
  std::cout << ans << '\n';
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

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

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

// 約数を求める
vl divisor(ll n){
  vl res;
  for(ll i=1; i*i<=n; ++i){
    if(n%i==0){
      res.push_back(i);
      if(i!=n/i){
        res.push_back(n/i);
      }
    }
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  ll n;
  cin>>n;
  vl a=divisor(n);
  vl b=divisor(n-1);
  sort(ALL(a));sort(ALL(b));
  vl c;
  merge(ALL(a), ALL(b), back_inserter(c));
  c.erase(unique(ALL(c)), c.end());
  ll ans=0;
  int sz=c.size();
  REP(i, sz){
    ll tmp=c[i];
    ll cur=n;
    if(tmp!=1){
      while(cur%tmp==0){
        cur/=tmp;
        if(cur==0){
          break;
        }
      }
    }
    cur%=tmp;
    if(cur==1){
      ++ans;
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 384
n, q = map(int, input().split())

# max_num
INF = 2**31 - 1

# generate seg tree
seg_size = 2

while seg_size < n :
    seg_size *= 2
    
seg_size = seg_size * 2 - 1
seg_tree = [INF for x in range(seg_size)]

answer_stk = []

# update 
def update(i, x) :
    # leaf for index @ i
    idx = seg_size // 2 + i
    seg_tree[idx] = x
    
    while idx :
        idx = (idx - 1) // 2
        l_child = seg_tree[idx * 2 + 1]
        r_child = seg_tree[idx * 2 + 2]
        
        seg_tree[idx] = min(l_child, r_child)

# query
def query(s, t, l, r, curnode) :
    # no overlap then return INF
    if s > r or t < l :
        return INF
    
    # full overlap then return current node
    if s <= l and t >= r :
        return seg_tree[curnode]
    
    # partial overlap then return min for next
    else :
        l_child = curnode * 2 + 1
        r_child = curnode * 2 + 2
        
        l_value = query(s, t, l, (l + r) // 2, l_child)
        r_value = query(s, t, (l + r) // 2 + 1, r, r_child)
        
        return min(l_value, r_value)
    
# do main query
for i in range(q) :
    q, x, y = map(int, input().split())
    
    # update
    if q == 0 :
        update(x, y)
        
    # query 
    else :
        answer_stk.append(query(x, y, 0, seg_size // 2, 0))
        
for a in answer_stk :
    print(a)

        


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

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

  ll n, t; cin >> n >>t;
  vector<ll> time(n);
  rep(i, n) cin >> time[i];

  ll ans = 0;
  rep(i, n-1) {
    if(time[i+1]-time[i] >= t) ans += t;
    else ans += time[i+1]-time[i];
  }
  cout << ans+t << '\n';
  return 0;
}


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

struct Problem {

    ULL A[100001];

    void Solve() {
        UL N; scanf("%d", &N);
        rep(i, N) scanf("%d", &A[i]);
        ULL ans = 0;
        deque<pair<ULL, UL>> Q;
        Q.push_back({ 0,0 });
        rep(i, N + 1) {
            UL p = i;
            while (Q.back().first > A[i]) {
                ans = max(ans, Q.back().first * (i - Q.back().second));
                p = Q.back().second;
                Q.pop_back();
            }
            Q.push_back({ A[i], p });
        }
        printf("%lld\n", ans);
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}



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

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long;
using pll = pair<ll, ll>;

const ll MAXN = 1000001;
bool P[MAXN];
bool S[MAXN];
vector<ll> PS;

template<typename T> T gcdraw(T a, T b)
{
    return a ? gcdraw(b%a, a) : b;
}

template<typename T> T gcd(T a, T b)
{
    const auto aa = abs(a), bb = abs(b);
    return aa > bb ? gcdraw(aa, bb) : gcdraw(bb, aa);
}

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

    vector<ll> A(N);
    rep (i, N) { cin >> A[i]; }

    PS.emplace_back(1);
    for (ll i=2;i*i<=MAXN;++i) if (!P[i])
    {
        for (ll j=2*i;j<=MAXN;j+=i) { P[j] = true; }
        PS.emplace_back(i);
    }

    bool isPairwise = true;

    ll cur = A[0];

    for (ll i=0;i<N;++i)
    {
        for (const auto& p: PS)
        {
            if (A[i] < p * p) { break; }
            if (A[i] % p) { continue; }

            const auto x = p;
            const auto y = A[i] / p;
            // cout << x << " * " << y << " = " << A[i] << endl;

            if (x != 1 && S[x]) { isPairwise = false; }
            if (y != 1 && S[y]) { isPairwise = false; }

            S[x] = true;
            S[y] = true;
        }

        cur = gcd(cur, A[i]);
    }

    const auto isSetwise = cur == 1;

    if (isPairwise)     { cout << "pairwise coprime" << endl; }
    else if (isSetwise) { cout << "setwise coprime" << endl; }
    else                { cout << "not coprime" << endl; }

    return 0;
}


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

int main() {

  int n,m;

  while(1) {

    cin >> n;
    if(n == 0) break;

    cin >> m;
    int t;
    int count = 0;
    for(int i=n;i<=m;i++) {
      t = i;

      while(1) {
	//	cout << "t = " << t<< endl;
      if(t%2 == 0)t /= 2;
      else if(t%3 ==0)t /= 3;
      else if(t%5 ==0) t /= 5;
      else break;
      }

      if(t == 1) count++;
    }

    cout << count << endl;

  }

  return 0;

}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	int x;
	int[] kionsa = {1,2,3,4,5,6,7};
	public void nyuryoku(){
		for(x=0;x<=6;x++){
			int saiko = sc.nextInt();
			int saitei = sc.nextInt();
			kionsa[x] = saiko-saitei;
		}
	}
	
	public void nyuuryoku2(){
		for(x=0;x<=6;x++){
			System.out.println(kionsa[x]);
		}
	}
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Main hai =new Main();
		hai.nyuryoku();
		hai.nyuuryoku2();

	}

}

Measured memory_bytes: 17364
#include<stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  if(r<=x && x<=W-r && r<=y && y<=H-r){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}



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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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; }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
bool isunb(string s){
	int cnt[26]={};
	rep(i,s.size()){
		cnt[s[i]-'a']++;
	}
	bool re=false;
	rep(i,26){
		if(cnt[i]>s.size()/2)re=true;
	}
	return re;
}
int cnt(int b,int n){
	int re=0;
	while(n>0){
		re+=n%b;			
		n/=b;
	}
	return re;
}
signed main(){
	int n,s;
	cin>>n>>s;
	rep(i,2,sqrt(n)+1){
		if(cnt(i,n)==s){
			cout<<i<<endl;
			return 0;
		}
	}
	if(s<n){
		int t=n-s;
		for(int i=sqrt(t);i>0;i--){
			if(t%i==0){
				int u=t/i;
				if((u+1)>sqrt(n)&&s-i<u+1&&s>=i){
					cout<<u+1<<endl;
					return 0;
				}
			}
		}
	}else if(s==n){
		cout<<n+1<<endl;
		return 0;
	}
	cout<<-1<<endl;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  vector<pair<int,int>> cb(m);

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

  for (int i = 0; i < m; i++)
  {
    int b,c;
    cin >> b >> c;
    cb[i]=make_pair(c,b);
  }
  sort(cb.begin(),cb.end());
  reverse(cb.begin(),cb.end());
  
  int cnt=0;
  int flg=0;
  for (auto cbp:cb)
  {
    int c = cbp.first;
    int b = cbp.second;
    for (int i = cnt; i < n; i++)
    {
      if(c<a[i]){
        flg=1;
        break;
      }
      else{
        a[i]=c;
        b--;
      }
      if(b==0) {
        cnt=i+1;
        break;
      }
    }
    if(flg) break;
  }

  long long ans=0;
  for(auto ai:a){
    ans+=ai;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1408
a=input()
b=a.split()

x1=int(b[0]) #1
x2=int(b[1]) #0
x3=int(b[2]) #-1
x4=int(b[3]) #k

if x4 <= x1:
	print(x4)

elif x4 <= x1+x2:
	print(x1)

else:
	print(x1-(x4-x1-x2))




Measured memory_bytes: 9176
n,m=map(int,input().split())
s=[list(map(int,input().split()))for _ in range(n)]
a=0
for i in range(1<<3):
    t=[[v for v in u]for u in s]
    for j in range(3):
        if i>>j&1:
            for k in range(n):
                t[k][j]*=-1
    for j in range(n):
        t[j]=sum(t[j])
    a=max(a,sum(sorted(t)[::-1][:m]))
print(a)

Measured memory_bytes: 43504
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
#define all(x) x.begin(),x.end()
//name[i][j]-> vector<vector<ll>>name(i,vector<ll>(j))
//or-> ||

signed main(){
	ll N;
	cin>>N;
	vector<vector<ll>>DP(N,vector<ll>(3));
	vector<vector<ll>> a(N,vector<ll>(3));
	rep(i,0,N) cin>>a[i][0]>>a[i][1]>>a[i][2];

	DP[0][0]=a[0][0];
	DP[0][1]=a[0][1];
	DP[0][2]=a[0][2];
	rep(i,1,N){
		DP[i][0]=max(DP[i-1][1],DP[i-1][2])+a[i][0];
		DP[i][1]=max(DP[i-1][0],DP[i-1][2])+a[i][1];
		DP[i][2]=max(DP[i-1][0],DP[i-1][1])+a[i][2];
	}
	sort(all(DP[N-1]));
	cout<<DP[N-1][2]<<endl;
	return 0;
}


Measured memory_bytes: 11136
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    H,W = readInts()
    FIELD = [input() for _ in range(H)]
    ARRIVED = [[False]*W for _ in range(H)]
    def Move(y,x):
        ARRIVED[y][x] = True
        if y == H-1 and x == W-1:
            if FIELD[y][x-1] == '#' and not ARRIVED[y][x-1]:
                print('Impossible')
                exit()
            else:
                print('Possible')
                exit()
        y_ = True
        x_ = True
        if y+1 < H:
            y_ = True
        else:
            y_ = False
        if x+1 < W:
            x_ = True
        else:
            x_ = False
        xu = True if x - 1 >= 0 else False
        yu = True if y - 1 >= 0 else False
        if y_ and FIELD[y+1][x] == '#':
            if x_ and FIELD[y][x+1] == '#':
                print('Impossible')
                exit()
            elif yu and FIELD[y-1][x] == '#' and not ARRIVED[y-1][x]:
                #print(y-1,x)
                print('Impossible')
                exit()
            else:
                Move(y+1,x)
        elif x_ and FIELD[y][x+1] == '#':
            if y_ and FIELD[y+1][x] == '#':
                print('Impossible')
                exit()
            elif xu and FIELD[y][x-1] == '#'  and not ARRIVED[y][x-1]:
                #print(y,x-1)
                print('Impossible')
                exit()
            else:
                Move(y,x+1)
        else:
            print('Impossible')
            exit()
    # 最初は (0,0)です
    Move(0,0)
if __name__ == '__main__':
  main()


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

const int maxn = 1e5 + 5;

int n,k;
int a[maxn],cnt[3];
int dp[maxn][3];

int main()
{
	
	std::ios::sync_with_stdio(false);cin.tie(0);
	cin >> n >> k;
	cin >> cnt[0] >> cnt[1] >> cnt[2];
	for(int i = 0; i < n; i++) {
		char c; cin >> c;
		if(c == 'r') a[i] = 0;
		if(c == 's') a[i] = 1;
		if(c == 'p') a[i] = 2;
	}		
	
	//cout << cnt[0] << endl;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		if(i < k) {
			dp[i][(a[i] - 1 + 3) % 3] += cnt[(a[i] - 1 + 3) % 3];
		}
		else {
			for(int j = 0; j < 3; j++) {
				int v = 0;
				if((j + 1) % 3 == a[i]) v = cnt[j];
				dp[i][j] = max(dp[i][j],dp[i - k][(j + 1) % 3] + v);
				dp[i][j] = max(dp[i][j],dp[i - k][(j + 2) % 3] + v);
			}
		}
	}
	/*
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 3; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/
	for(int i = n - k; i < n; i++) {
		int maxx = 0;
		for(int j = 0; j < 3; j++){
			maxx = max(maxx, dp[i][j]);
		}
		ans += maxx;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
n,m = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(m)]
x,a,b,ans = sorted(x),0,n+1,0
for i,j in x:
	if i>=a and j<=b: a,b = i,j
	elif b>i>=a: a = i
	elif j<=b: b = j
	else: ans,a,b = ans+1,i,j
print(ans+1)

Measured memory_bytes: 22436
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int n = scanner.nextInt();
    int[] p = new int[n];
    for (int i = 0; i < n; i++) {
      p[i] = scanner.nextInt();
    }

    int cnt = 0;
    for (int i = 1; i < n - 1; i++) {
      if (p[i] > p[i - 1] && p[i] < p[i + 1]) cnt++;
      else if (p[i] < p[i - 1] && p[i] > p[i + 1]) cnt++;
    }
    System.out.println(cnt);
  }
}


Measured memory_bytes: 23380
#include"cstdio"
#include"iostream"
#include"algorithm"
using namespace std;
int a[200005],b[200005],c[200005],d[200005];
int main(){
	int N,M,i=0,j=0,k=0,p=0;
	scanf("%d%d",&N,&M);
	for(i=0;i<M;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
	}
	for(i=0;i<M;i++)
	{
		if(a[i]==N) d[j]=b[i],j++;
		if(b[i]==N) d[j]=a[i],j++;
		if(a[i]==1) c[k]=b[i],k++;
		if(b[i]==1) c[k]=a[i],k++;
	}
	sort(c,c+k);
	sort(d,d+j);
	i=0;
	for(p=0;p<j;p++)
	{
		if(c[i]==d[p])
		{
			printf("POSSIBLE\n");
			return 0;
		}
		if(c[i]<d[p]&&i<k) i++,p--;	
		if(c[i]<d[p]&&i>=k)	
		break;
	}
	printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#define ll long long
#define mod  1000000007
using namespace std;

ll fact[1000006], inv[1000006];

ll fp(ll base, ll power)
{
	if (power == 0)return 1;
	ll ans = fp(base, power / 2);
	ans = (ans * ans) % mod;
	if (power % 2 != 0)
		ans = (ans * (base % mod)) % mod;
	return ans;
}

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

ll ncr(int n, int r)
{
	return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}

int main()
{
	calc();
	ll ans = 0;
	int n, k, arr[100005];
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	if (k != 1)
	{
		sort(arr, arr + n, greater<int>());
		for (int i = 0, j = n - 1; i < n - k + 1 && j >= k - 1; i++, j--)
		{
			ll mx = (arr[i] * ncr((n - i - 1), k - 1)) % mod;
			ll mn = (arr[j] * ncr(j, k - 1)) % mod;
			ans += mx;
			ans -= mn;
		}
		cout << ((ans % mod) + mod) % mod << endl;
	}
	else cout << 0 << endl;
	return 0;
}

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

int main() {
  int n; cin >>n;
  vector<int> a(n);
  vector<int> b(n-1);
  rep(i,n-1){
    cin >> b[i];
  }
  rep(i,n) {
    if(i == 0) a[i] = b[0];
    else if(i == n-1) a[i] = b[n-2];
    else a[i] = min(b[i], b[i-1]);
  }
  int ans = 0;
  rep(i,n) {
    ans += a[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100001
#define maxa 1000005
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second
#define rep(i, a, n) for(ll i = a; i < n; i++)
#define repr(i, a, n) for(ll i = n-1; i >= a; i--)
#define meme(a, b) memset(a, b, sizeof(a))

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}
ll ceil(ll a, ll b){if((a%b) != 0) return a/b+1; return a/b;}
void flaged(bool flag){
    if(flag) cout << "YES\n";
    else cout << "NO\n";
}
ll power(ll a, ll b = MOD-2){
    if(b == 0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}

void solve(){
    string s; ll k;
    cin >> s >> k;

    ll n = s.length();
    ll dp[n+1][2][10];
    meme(dp, 0);
    dp[0][0][0] = 1;
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j < 2; j++){
            for(ll kk = 0; kk <= k; kk++){
                ll lim = s[i]-'0';
                if(j == 1) lim = 9; //cout << i << " " << j << " " << kk << " " << lim << endl;
                for(ll d = 0; d <= lim; d++){ //cout << d<< " ";
                    dp[i+1][j || d < lim][kk + (d!=0)] += dp[i][j][kk];
                }
            }
        }
    }
    cout << dp[n][0][k] + dp[n][1][k];
}

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


Measured memory_bytes: 256