akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int n;
    cin >> n;

    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int q;
    cin >> q;

    vector<int> m(q);
    rep(i,q) cin >> m[i];

//  A --> m[i]
    map<int,int> A;
    rep(i,1<<n){
        int sum = 0;
        rep(j,n){
            if(i>>j&1) sum += a[j];
        }
        A[sum]++;
    }

    rep(mi,q){
        if(A[m[mi]]) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define ll long long
#define li long int
#define ld long double
#define pl pair<long long, long long>
#define pi pair<int, int>
#define ppl pair<pl, ll>
#define ppi pair<int, pi>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LLFOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define MOD 1000000007
#define M2 998244353
//std::cout <<setprecision(30) << av << endl;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--){
        int k, a, b;
        cin >> k >> a >> b;
        int d = b-a+1;
        FOR(i, a, b+1){
            if(i%k==0){
                cout << "OK" << endl;
                return 0;
            }
        }
        cout << "NG" << endl;


    }
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int N,H;
int A[100005],B[100005];
int main()
{
	cin>>N>>H;
	for(int i=0;i<N;i++)
	cin>>A[i]>>B[i];
	int x=*max_element(A,A+N);
	sort(B,B+N);
	reverse(B,B+N);
	int ans=(H+x-1)/x;
	for(int i=0;i<N;i++)
	{
		H-=B[i];
		int tmp;
		if(H<=0)tmp=0;
		else tmp=(H+x-1)/x;
		if(ans>i+1+tmp)
			ans=i+1+tmp;
	}
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
int n, t, A, ans;
double Min = INF,tem;
double abss(double x) { return x < 0 ? -x : x; }
int main()
{
	int a;
	cin >> n >> t >> A;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a);
		tem = abss((double)t - 0.006 * a - A);
		if (tem < Min)
		{
			Min = tem;
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	int color[101] = {};
	color[a] = 1;
	color[b] = 1;
	color[c] = 1;
	int sum = 0;
	for (int i = 0; i < 101; i++) sum += color[i];
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    cout<<100*(n-m)*pow(2,m)+1900*m*pow(2,m)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> sto(n);
  int a,b;
  rep(i,0,n){
    cin >> a >> b;
    sto[i] = make_pair(a,b);
  }
  sort(ALL(sto));
  int buy = m;
  int money = 0;
  rep(i,0,n){
    if(buy >= sto[i].second){
      money += sto[i].first * sto[i].second;
      buy -= sto[i].second;
    }
    else {
      money += buy * sto[i].first;
      buy = 0;
    }
    
    if(buy == 0) break;
  }
  cout << money << endl;
}


Measured memory_bytes: 1792
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N, K, M;
  while(cin >> N >> K >> M, N){
	VI st;
	REP(i,N) st.PB(i+1);
	int m = (M - 1) % SZ(st);;
	while(SZ(st)>1){
	  st.erase(st.begin()+m);
	  m = (m + K - 1) % SZ(st);
	}
	cout << st[0] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1320
#!/usr/bin/env python3

n = int(input())
a = list(map(int,input().split()))
cnt_odd = [0]*(10**5+1)# a[2k]での個数
cnt_even = [0]*(10**5+1)
for i in range(n):
    if i  %2: cnt_odd[a[i]] += 1
    else: cnt_even[a[i]] += 1
odd,idx_odd=zip(*sorted(zip(cnt_odd,list(range(10**5+1)))))
even,idx_even=zip(*sorted(zip(cnt_even,list(range(10**5+1)))))
#print(odd[-1],even[-2],odd[-2],even[-1])
if idx_even[-1]!=idx_odd[-1]:
    print(n - odd[-1] - even[-1])
else:
    print(n - max(odd[-1]+even[-2],odd[-2]+even[-1]))
#ちゃんとテストケース書かないと落ちる


Measured memory_bytes: 82396
import java.util.Scanner;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int[] list = new int[3];
		list[0] = sc.nextInt();
		list[1] = sc.nextInt();
		list[2] = sc.nextInt();
		
		change(list);
		for (int i = 0; i < list.length; i++){
			System.out.print(list[i]);
			if (i == 2){
				continue;
			}
			System.out.print(" ");
		}
		System.out.println();
		
	}
	
	public static void change(int[] li){
		for (int j = 0; j < li.length - 1; j++){
			for (int i = 0; i < li.length - j - 1; i++){
				if(li[i] > li[i+1]){
					int tmp = li[i];
					li[i] = li[i+1];
					li[i+1] = tmp;
				}
			}
		}
	}
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    string S;
    cin>>S;
    int N=S.size();
    //累積和的？
    vector<int> cs(N+2,0),ANS(N,0);
    REP(i,1,N+1){
        if(S[i-1]=='R')cs[i]=cs[i-1]+1;
    }
    for(int i=N;i>0;i--){
        if(S[i-1]=='L'){
            cs[i]=cs[i+1]-1;
            if(i!=N&&S[i]=='R')cs[i]=-1;
        }
    }
    //for(auto x:cs)cout<<x<<" ";
    //cout<<endl;
    //偶数回の移動が鍵
    bool t=true;
    REP(i,1,N+1){
        if(cs[i]<0){
            if(t){
                int a=cs[i-1]/2+cs[i-1]%2+(-cs[i])/2;
                int b=cs[i-1]/2+(-cs[i])/2+(-cs[i])%2;
                ANS[i-2]=a,ANS[i-1]=b;
                //cout<<i<<" "<<a<<" "<<b<<endl;
            }
            t=false;
        }else t=true;
    }
    for(auto x:ANS)cout<<x<<" ";
    cout<<endl;
    return 0;
}

//a=97,z=122
/*
RRRL
1110
0111
0021
RRL
110
011
011

*/

Measured memory_bytes: 1408
def main():
    import sys
    input = sys.stdin.readline

    N, M, Q = map(int, input().split())

    lst = [[0] * (N + 1) for _ in range(N + 1)]

    for _ in range(M):
        L, R = map(int, input().split())
        for l in range(L + 1):
            lst[l][R] += 1

    for l in range(N + 1):
        for r in range(N):
            lst[l][r + 1] += lst[l][r]

    # for tmp in lst:
    #     print (tmp)

    for _ in range(Q):
        p, q = map(int, input().split())
        print (lst[p][q])

if __name__ == '__main__':
    main()

Measured memory_bytes: 54236
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 110;
const int maxn2 = 1100;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};

int n, m;
int a[maxn2], b[maxn2], c[maxn2]; 
int dist[maxn][maxn]; 

int main(){
    cin >> n >> m;

    //Floyd-Warshall Initialize
    rep(i,n){
    	rep(j,n){
            dist[i][j] = INF32;
        }
        dist[i][i] = 0;
    }

    rep(i,m){
        cin >> a[i] >> b[i] >> c[i];
        --a[i], --b[i];
        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];
    }

    //Floyd-Warshall
    rep(k,n)rep(i,n)rep(j,n){
        dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
    }

    int cnt = 0;
    rep(i,m){
        if(c[i] > dist[a[i]][b[i]]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
from functools import lru_cache
import sys
sys.setrecursionlimit(30000)

N, M = map(int, input().split())
a = list(int(input()) for _ in range(M))

MOD = pow(10, 9) + 7

isOk = True
for i in range(M-1):
    if a[i] + 1 == a[i+1]:
        isOk = False
    
funcb = [-1] * 100001
def func(n):
    if n <= 0:
        return 1
    cnt = funcb[n]
    if cnt > 0:
        return cnt
    cnt = 0
    if n >= 2:
        cnt += func(n-2)
    if n >= 1:
        cnt += func(n-1)
    funcb[n] = cnt % MOD
    return funcb[n]

func(30000)
func(50000)
func(80000)
func(100000)

if not isOk:
    print(0)
else:
    ans = 1
    s = 0
    for i in range(M+1):
        if i >= M:
            e = N
        else:
            e = a[i] - 1

        ans = ans * func(e-s) % MOD

        if i >= M:
            break

        s = a[i] + 1

    print(ans)


Measured memory_bytes: 22940
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod=1000000007;
string K;
ll D;
ll dp[100005][2][105];
int main(){
  cin>>K>>D;
  ll N=K.size();
  dp[0][0][0]=1;
  for(ll i=0;i<N;i++){
  ll k=K[i]-'0';
    for(int j=0;j<D;j++){
    for(int l=0;l<10;l++)
      dp[i+1][1][(j+l)%D]=(dp[i+1][1][(j+l)%D]+dp[i][1][j])%mod;
    }
    for(int j=0;j<D;j++){
    for(int l=0;l<k;l++)
      dp[i+1][1][(j+l)%D]=(dp[i+1][1][(j+l)%D]+dp[i][0][j])%mod;
    }
    for(int j=0;j<D;j++){
      dp[i+1][0][(j+k)%D]=(dp[i+1][0][(j+k)%D]+dp[i][0][j])%mod;
    }
  
  }cout<<(dp[N][1][0]+dp[N][0][0]-1+mod)%mod<<endl;
  return 0;
}

Measured memory_bytes: 20052
#include<stdio.h>
#include<assert.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<unordered_set>
#include<map>
#include<queue>
#include<functional>
#include<list>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 1<<19;
const int MM = 1000000007;

string D;

int main()
{
	cin >> D;
	int ans = 1e9;
	for(int i = 'a'; i <= 'z'; i++){
		string E = D;
		int t = 0;
		while(E.size()){
			bool ch = 1;
			for(int c = 0; c < E.size(); c++){
				if( E[c] != E[0] ) ch = 0;
			}
			if( ch == 1 ) break;
			string F;
			for(int j = 0; j+1 < E.size(); j++){
				if( E[j] == i || E[j+1] == i ) F.push_back(i);
				else F.push_back(E[j]);
			}
			swap(E, F); t++;
		}
		ans = min(ans, t);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
n,k=map(int, input().split())
p=list(map(int, input().split()))
import numpy as np
a=np.array(p)/2+0.5
s=a[:k].sum()
m=s
for i in range(1,n-k+1):
    s=s-a[i-1]+a[i+k-1]
    if s>m:
        m=s
print(m)

Measured memory_bytes: 25604
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

ll cal(ll n){
    ll res=0;
    while(n>0&&n%2==0){
        res++;
        n/=2;
    }
    return res;
}

int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=0;
    rep(i,0,n-1){
        ans+=cal(a[i]);
    }
    cout<<ans<<endl;
    
    return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  int x = (a * b) % 2;
  if (x == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	s := readString()
	even := map[byte]bool{
		'L': true, 'U': true, 'D': true,
	}
	odd := map[byte]bool{
		'R': true, 'U': true, 'D': true,
	}
	for i := range s {
		if (i+1)%2 == 0 {
			if !even[s[i]] {
				fmt.Println("No")
				return
			}
		} else {
			if !odd[s[i]] {
				fmt.Println("No")
				return
			}
		}
	}

	fmt.Println("Yes")
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int n,c=0;
	cin>>n;
	int t[100];
	for(int i=0;i<n;i++){
		cin>>t[i];
		c+=t[i];
	}
	int m;
	cin>>m;
	int p[100],x[100];
	for(int i=0;i<m;i++){
		cin>>p[i]>>x[i];
		cout<<c-t[p[i]-1]+x[i]<<endl;
	}
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    int n, u, v[105], w[105];
    cin >> n >> u;
    for (int i = 0; i < n; i++) cin >> v[i] >> w[i];
    
    int dp[105][12005];
    for (int i = 0; i <= n; i++) {
        dp[0][0] = 0;
        for (int j = 1; j <= u; j++) dp[0][j] = -1;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= u; j++) dp[0][j] = dp[0][j];
        
        for (int j = 0; j <= u; j++) {
            if (dp[i][j] != -1) dp[0][j + w[i]] = max(dp[0][j] + v[i], dp[0][j + w[i]]);
        }
    }
    
    int mx = 0;
    for (int i = 0; i <= u; i++) {
        mx = max(mx, dp[0][i]);
        //cout << i << " " << dp[0][i] << endl;
    }
    cout << mx << endl;

    
}



Measured memory_bytes: 3144
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static Scanner in;
	
	private static int n;
	private static int k;
	private static int[] a;
	private static long[][] dp;
	private static final int MOD = (int)1e9+7;
	
	public static void main(String[] args) {
		in = new Scanner(System.in);
		n = in.nextInt();
		k = in.nextInt();
		a =  new int[n];
		for(int i=0; i<n; i++) {
			a[i] = in.nextInt();
		}
		
		dp = new long[k+1][2];
		
		for(int i=0; i<dp.length; i++)
			Arrays.fill(dp[i], -1);
		
		
		
		System.out.println(solve(k, 0)==0?"First":"Second");
	
	}
	
	private static long solve(int kLeft, int f) {
		if (kLeft<0) return f;
		
		if (dp[kLeft][f]!=-1) return dp[kLeft][f];
		
		for(int i=0; i<n; i++) {
			long winner = solve(kLeft-a[i], 1-f);
			if (winner==f) return dp[kLeft][f]=f;
		}
		
		return dp[kLeft][f]=1-f;
		
	}

}


Measured memory_bytes: 37972
import java.util.Scanner

fun sort(A: IntArray): IntArray{
	val N = A.size

	for(i in 1..N-1){
		val v = A[i]
		var j = i-1

		while(j>=0 && A[j]>v){
			A[j+1] = A[j]
			j--
		}

		A[j+1] = v
	}

	return A
}

fun main(args: Array<String>){
	val sc = Scanner(System.`in`)

	val s = sc.nextLine().split(" ")
	val N = s.size
	val A = IntArray(N)
	for(i in 0..N-1) A[i] = Integer.parseInt(s[i])

	val sorted = sort(A)
	
	var count = 0
	for(i in 1..N-1) count += sorted[i]-sorted[i-1]

	println(count)

}

Measured memory_bytes: 34164
#include<bits/stdc++.h>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
std::vector<bool> stiustir;
std::vector<long long> recordstepstir;
int N = 0;
void search(int now){
	long long step =0;
	if(stiustir[now] == false){
		recordstepstir[now] = 0;
		search(now-1);
		return;
	}
	if(now>0&&now<=N-2){
		step += recordstepstir[now+2];
		step += recordstepstir[now+1];
		recordstepstir[now] = step%1000000007;
		search(now-1);
	}else if(now==N-1){
		recordstepstir[now] = 1;
		search(now-1);
		return;
	}else if(now == 0){
		step += recordstepstir[now+2];
		step += recordstepstir[now+1];
		recordstepstir[now] = step%1000000007;
		cout << (step%1000000007);
		return;
	}
	return;
}
int main(void){
	int i,j,k,M;
	cin >> N >> M;
	int a[M];
	for(i=0;i<M;i++){
		cin >> a[i];
	}
	for(i=0;i<N;i++){
		stiustir.push_back(true);
		recordstepstir.push_back(0);
	}
	recordstepstir.push_back(1);
	stiustir.push_back(true);
	for(i=0;i<M;i++){
		stiustir[a[i]] = false;
	}
	if(N==1){
		cout << 1;
		return 0;
	}
	search(N-1);
	return 0;
}

Measured memory_bytes: 1784
#include<stdio.h>

int main()
{
	int n, a[1000], i;

	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	for(i = n - 1; i >= 0; i--) {
		if(i == n - 1) printf("%d", a[i]);
		else printf(" %d", a[i]);
	}
	printf("\n");

	return 0;
}



Measured memory_bytes: 2036
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

typedef  long long ll;

#define rep(i,a,n) for(ll (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(ll (i)=(a);(i)>=(n);(i)--)

#define INF ll 1 << 60
#define MOD 1000000007


using namespace std;

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

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

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}


void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

int dig(int d){
    int ans = 1;
    if(d == 0) return ans;
    while(d != 0){
        d--;
        ans*=100;
    }
    return ans;
}

ll divisors(ll n) {
    vector<ll> res;

    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i-1);
        if(n/i == i) continue;
        res.push_back((n/i)-1);
    }

    ll ans = 0;

    rep(i,0,res.size()){
        if(res[i] != 0)
        if(n/res[i] == n%res[i]) ans += res[i];
    } 
    return ans;
}

void solve(void){
   int n,k;
   string s;
   cin >> n >> k >> s;
   
   s[k-1] = tolower(s[k-1]); 
   cout << s<< endl;

}

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

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

bool check(string S){
    if(S[0] != 'A') return false;
    int numC = 0;
    for(int i = 2; i < S.size() - 1; i++)
    {
        if(S[i] == 'C') numC++;
    }
    if(numC != 1) return false;
    int num_upper = 0;
    rep(i, S.size())
    {
        if(S[i] >= 'A' and S[i] <= 'Z') num_upper++;
    }
    if(num_upper != 2) return false;
    return true;
}

int main(void)
{
    string S;
    cin >> S;
    if(check(S)) puts("AC");
    else puts("WA");

    return 0;
}

Measured memory_bytes: 256
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Mod-Int
constexpr int MOD = 1000000007;
struct ModInt {
    ll val;
    ModInt() = default;
    ModInt(ll x) : val(x % MOD + (x < 0 ? MOD : 0)) {}
    ModInt &operator+= (const ModInt &x) {if ((val += x.val) >= MOD) val -= MOD; return *this;}
    ModInt &operator-= (const ModInt &x) {if ((val -= x.val) < 0) val += MOD; return *this;}
    ModInt &operator*= (const ModInt &x) {(val *= x.val) %= MOD; return *this;}
    ModInt operator+ (const ModInt &x) const {return ModInt(*this) += x;}
    ModInt operator- (const ModInt &x) const {return ModInt(*this) -= x;}
    ModInt operator* (const ModInt &x) const {return ModInt(*this) *= x;}
    ModInt pow(ll t) const {
        if (!t) return ModInt(1);
        ModInt m = pow(t / 2);
        m *= m;
        if (t & 1) m *= *this;
        return m;
    }
    ModInt inv() const {return pow(MOD - 2);}
    ModInt &operator/= (const ModInt &x) {return *this *= x.inv();}
    ModInt operator/ (const ModInt &x) const {return ModInt(*this) /= x;}
    friend istream &operator>> (istream &is, ModInt &x) {is >> x.val; return is;}
    friend ostream &operator<< (ostream &os, const ModInt &x) {os << x.val; return os;}
};

// Main Code
void solve() {
    int n;
    cin >> n;
    
    vector<ModInt> dp(2 * n, ModInt(1)), sum(2 * n + 1, ModInt(0));
    for (int i = 2 * n - 1; i >= 0; --i) {
        sum[i] += sum[i + 1];
        if (i == n - 1) {
            dp[i] = ModInt(n);
        }
        if (i < n - 1) {
            dp[i] = dp[i + 1] + ModInt(n - 1) * ModInt(n - 1) + sum[i + 3] - sum[i + n + 2];
        }
        sum[i] += dp[i];
    }
    
    cout << dp[0] << "\n";
    return;
}


Measured memory_bytes: 34200
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
int s[200005], cal[400005], tot = 0;
int main() {
	int a, b, c, ans = 0;
	cin >> a >> b >> c;
	cout << b/c-(a-1)/c;
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
	long a,b,g=1;
  	cin>>a>>b;
  	for(long i=1;i<=min(a,b);i++){
    	if(a%i==0&&b%i==0){
        	g=i;
          	g=max(g,i);
        }
    }
  	cout<<(a*b)/g<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

ll factorialTable[200010];
ll inverseFactorialTable[200010];

//Aのp乗を求めるアルゴリズム。計算量はO(logp)
ll modpow(ll A, int p) {
    if(p == 0) {
        return 1;
    }
    if(p%2 == 0) {
        //pが偶数の時
        int halfP = p/2;
        ll half = modpow(A, halfP);
        //a^(p/2)をhalfとして、half*halfを計算
        return half * half % mod;
    }
    else {
        //pが奇数の時は、pを偶数にするために1減らす
        return A * modpow(A, p-1) % mod;
    }
}

void makeFactorialTable() {
    ll x = 1LL;
    factorialTable[0] = x;
    for(int i = 1; i < 200010; i++) {
        x *= i;
        x %= mod;
        factorialTable[i] = x;
    }
}

void makeInverseFactorialTable() {
    inverseFactorialTable[0] = 1LL;
    for(int i = 1; i < 200010; i++) {
        inverseFactorialTable[i] = modpow(factorialTable[i], mod-2);
    }
}

ll Comb(int n, int r) {
    ll bunbo = inverseFactorialTable[r]*inverseFactorialTable[n-r]%mod;
    return factorialTable[n]*bunbo%mod;
}

int main() {
    int h, w, a, b;
    ll ans = 0;
    cin >> h >> w >> a >> b;

    makeFactorialTable();
    makeInverseFactorialTable();
 
    for(int i = b; i < w; i++) {
        ll k = Comb(h-a-1+i, h-a-1)*Comb(w+a-2-i, w-1-i)%mod;
        ans += k;
        ans %= mod;
    }

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

Measured memory_bytes: 3328
// D

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int N,A[200000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>A[i];

  int now(1);
  for (int i(0);i<N;i++){
    if (now == A[i]) now++;
  }
  if (now != 1){
    cout << N - (now-1) << endl;
  }else{
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
n, m, q = map(int, input().split())
ans = 0
a, b, c, d = [None]*q, [None]*q, [None]*q, [None]*q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

def dfs(A):
    if len(A) == n+1:
        now = 0
        for i in range(q):
            if A[b[i]]-A[a[i]] == c[i]:
                now += d[i]
        global ans
        ans = max(ans, now)
        return
    A.append(A[-1])
    while A[-1] <= m:
        dfs(A[:])
        A[-1] += 1

if __name__ == "__main__":
    dfs([1])
    print(ans)

Measured memory_bytes: 72332
# セグ木
# 使う操作
#####segfunc#####
def segfunc1(x, y):
    return max(x, y)
#################

#####ide_ele#####
ide_ele1 = -float('inf')
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

n,k = map(int,input().split())
low = [0]*(10**5 * 3 + 1)
seg = SegTree(low, segfunc1, ide_ele1)
for i in range(n):
    a = int(input())
    ma = seg.query(max(0,a-k), min(a+k+1,10**5 * 3 + 1))
    seg.update(a, ma+1)
ans = seg.query(0,10**5 * 3 + 1)
print(ans)

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

using namespace std;



const int MAXN = 1e5 * 3 + 5;
const int mod = 998244353;

long long fakt[MAXN];

int n;
long long a, b, k;
long long sol = 0;


int mul (int a, int b) {
    return ((long long) a * b) % mod;
}
int add (int a, int b) {
    a+=b;
    if (a >= mod) return a-mod;
    return a;
}
int pow(int baza, int potencija) {
    int r = 1, a = baza, x = potencija;
    while (x) {
        if (x % 2 == 1) {
            r = mul(r,a);
        }
        a = mul(a,a);
        x/=2;
    }
    return r;
}
int divi (int a, int b) {
    return mul(a, pow(b,mod-2));
}

int main () {
    fakt[0] = 1;
    for (int i = 1 ; i < MAXN - 2; i++) {
        fakt[i] = mul(fakt[i-1],i);
    }
    cin >> n >> a >> b >> k;
    for (int i = 0  ; i <= n ; i ++) {
        long long A = a * i;
        if (A > k) break;
        if ((k - A) % b == 0 ) {
            //cout << "PROV: " <<A << " " << B;
            int j = (k-A) / b;
            if (j <= n) sol = add(sol , mul (divi (fakt[n] , mul(fakt[i] ,fakt[n-i] ) ) , divi (fakt[n] , mul(fakt[j] , fakt[n-j] ) ) ) );
        }
        else {
            continue;
        }
     }
    cout << sol;

    return 0;
}




Measured memory_bytes: 2560
n, k = map(int, input().split())

a = list(map(int, input().split()))
a_pos = sorted([i for i in a if i >= 0])
a_neg = sorted([i for i in a if i < 0], reverse=True)

mod = 10 ** 9 + 7
ans = 1

if len(a_pos) == 0 and k % 2:
    for i in a_neg[:k]:
        ans = ans * i % mod
    print(ans)
    exit()

while k > 0:
    if k == 1 or len(a_neg) <= 1:
        if len(a_pos) == 0:
            ans *= a_neg.pop()
        elif len(a_pos) > 0:
            ans *= a_pos.pop()
        k -= 1
    elif len(a_pos) <= 1:
        ans *= a_neg.pop() * a_neg.pop()
        k -= 2
    
    elif a_pos[-1] * a_pos[-2] > a_neg[-1] * a_neg[-2]:
        ans *= a_pos.pop()
        k -= 1
    elif a_pos[0] * a_pos[1] <= a_neg[-1] * a_neg[-2]:
        ans *= a_neg.pop() * a_neg.pop()
        k -= 2
    ans %= mod

print(ans)

Measured memory_bytes: 31772
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::*;

fn main() {
    input! {
        s: String,
        t: String,
    }

    let mut ans = 100000;

    for i in 0..(s.len() - t.len() + 1) {
        let mut cnt = 0;
        for j in 0..(t.len()) {
            if s.as_bytes()[i + j] != t.as_bytes()[j] {
                cnt += 1;
            }
        }
        ans = std::cmp::min(cnt, ans);
    }

    println!("{}", ans);
}


Measured memory_bytes: 2176
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    var ans = N
    for (n in 0..N) {
        var A = n
        var cnt = 0
        while (A > 0) {
            cnt += A % 9
            A /= 9
        }
        var B = N - n
        while (B > 0) {
            cnt += B % 6
            B /= 6
        }
        if (cnt < ans) ans = cnt
    }
    println(ans)
}

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

int main(){
    ll a,b,x;cin>>a>>b>>x;
    ll ans=0;
    if(a==0) ans=b/x+1;
    else ans=b/x-(a-1)/x;
    cout<<ans<<endl;
}

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define pr pair<int, int>

using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;


#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

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

// int a[10010][10010], b[1000];
// int dp[10010][3];

int S[10][1000];


int main() {

    ll A, B; cin >> A >> B;

    rep(i, 100000){
        if(i*108/100 == A+i && i*110/100 == B+i) {
            cout << i << endl;
            return 0;
        }
        PRINT(i*108/100)
        PRINT(i*110/100)
        PRINT(i)
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

map<ll,ll> pfmp; //各素因数の指数を格納
vector<ll> pfv(0); //異なる素因数を昇順に格納

void PF(ll N){
  ll n=N;
  if(n<=0) return;
  ll exp;
  if(n%2==0){
    if(pfmp[2]==0) pfv.push_back(2);
    exp=0;
    while(n%2==0){
      n/=2;
      exp++;
    }
    if(exp>pfmp[2]) pfmp[2]=exp;
  }
  if(n==1) return;
  for(ll i=3;i<=sqrt(N);i+=2){
    if(n%i==0){
      if(pfmp[i]==0) pfv.push_back(i);
      exp=0;
      while(n%i==0){
        n/=i;
        exp++;
      }
      if(exp>pfmp[i]) pfmp[i]=exp;
    }
  }
  if(n!=1){
    if(pfmp[n]==0){
      pfv.push_back(n);
      pfmp[n]=1;
    }
  } 
}

ll modinv(ll a,ll m){
  ll b=m,u=1,v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  u%=m;
  if(u<0) u+=m;
  return u;
}

int main(){
  ll N; cin >> N;
  vector<ll> a(N);
  rep(i,N) cin >> a[i];
  rep(i,N){
    PF(a[i]);
  }
  ll LCM=1;
  rep(i,pfv.size()){
    rep(j,pfmp[pfv[i]]){
      LCM*=pfv[i]%MOD;
      LCM%=MOD;
    }
  }
  ll ans=0;
  rep(i,N){
    ans+=LCM*modinv(a[i],MOD)%MOD;
    ans%=MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,i,j,wa,kotae=0;
  cin>>n;
  int a[n],b[n];
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=n-1;i>=0;i--){
    wa=0;
    for(j=(i+1)*2-1;j<n;j+=i+1){
      wa+=b[j];
    }
    b[i]=abs((wa-a[i])%2);
    kotae+=b[i];
  }
  cout<<kotae<<endl;
  for(i=0;i<n;i++){
    if(b[i]==1){
      cout<<i+1<<" ";
    }
  }
}

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

using namespace std;

int main()
{
    long long int a , b , c , k , ans;
    cin>>a>>b>>c>>k;
    if(k-a-b<=0)cout<<min(k,a)<<endl;
    else
    {   
        ans = a - min(c,k-a-b);
        cout<<ans<<endl;
    }
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    string s;

    cin >> s;

    ll n = s.length();

    ll is_ng = 0;

    REP(i, n){
      if (s[i] != s[n - 1 - i]){
        is_ng = 1;
      }
    }

    REP(i, n/2){
      if (s[i] != s[(n-1)/2 - 1 - i] || s[(n+3)/2 - 1 + i] != s[n - 1 - i]){
        is_ng = 1;
        break;
      }
    }
  
    if (is_ng == 0){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define EPS (1e-10)
class Point {
public:
    int x, y;
    Point(int x, int y) : x(x), y(y) {  }
    Point operator -(Point p) {
        return Point(x - p.x, y - p.y);
    }
};
typedef vector<Point> Polygon;
double dot(Point p1, Point p2) {
    return p1.x * p2.x + p1.y * p2.y;
}
double cross(Point p1, Point p2) {
    return p1.x * p2.y - p1.y * p2.x;
}
double norm(Point p) {
    return p.x * p.x + p.y * p.y;
}
double abs(Point p) {
    return sqrt(norm(p));
}
int contains(Polygon g, Point p) {
    int n = g.size();
    bool x = false;
    for (int i = 0; i < n; ++i) {
        Point a = g[i] - p, b = g[(i + 1) % n] - p;
        if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) {
            return 1;
        }
        if (a.y > b.y) {
            swap(a, b);
        }
        if (a.y < EPS && EPS < b.y && cross(a, b) > EPS) {
            x = !x;
        }
    }
    return x ? 2 : 0;
}

int main() {

    int n;
    scanf("%d", &n);
    Polygon g;
    for (int i = 0; i < n; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        Point p(x, y);
        g.push_back(p);
    }

    int q;
    scanf("%d", &q);
    for (int i = 0; i < q; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        Point p(x, y);
        cout << contains(g, p) << endl;
    }
    return 0;
}

Measured memory_bytes: 3240
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string S;

  std::cin >> S;

  std::cout << (S[2] == S[3] && S[4] == S[5] ? "Yes" : "No") << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
	if (a < b) {
	    System.out.println("a < b");
	} else if (a == b) {
	    System.out.println("a == b");
	} else if (a > b) {
	    System.out.println("a > b");
	}
    }
}

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

using namespace std;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
	int n;
	while(cin>>n){
		set<string> se;
		rep(i,n){
			string s;
			cin>> s;
			se.insert(s);
		}
		bool open = false;
		int m; cin >> m;
		rep(i,m){
			string s; cin >> s;
			if(se.count(s)==1){
				if(open) cout << "Closed by " << s << endl;
				else cout << "Opened by "<< s << endl;
				open^=1;
			}else{
				cout << "Unknown " << s << endl;
			}
		}
			
	}
}

Measured memory_bytes: 1232
#include <iostream>

using namespace std;

int main()
{
    int n, x;

    cin >> n >> x;

    int ans = 0;
    int sum = 0;

    for(int i = 0; i < n; ++i)
    {
        int l;
        cin >> l;

        if(sum + l <= x)
        {
            ++ans;
        }

        sum += l;
    }

    cout << ans + 1 << endl;
}

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

int main() {
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> vec(N, vector<ll>(2));
    for(int i = 0; i < N; i++){
        cin >> vec.at(i).at(0);
        cin >> vec.at(i).at(1);
    }
    sort(vec.begin(), vec.end());
    ll B = 0, cost = 0;
    for(int i = 0; i < N; i++){
        if(B + vec.at(i).at(1) >= M){
            cost += (M - B) * vec.at(i).at(0);
            cout << cost << endl;
            return 0;
        }
        B += vec.at(i).at(1);
        cost += vec.at(i).at(0) * vec.at(i).at(1);
    }

}

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

bool com(pair<int, int> &s, pair<int, int> &t)
{
    if (s.first == t.first)
        return s.second > t.second;
    return s.first < t.first;
}

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

    int n, k,ans=1e9;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
  k--;
    rep(i,n-k){
        ans = min(ans, h[i + k] - h[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>

int main(){
  long long int a,b;
  std::cin>>a>>b;
  if(a*b%2==1&&a!=1&&b!=1){
    std::cout<<(a*b+1)/2<<std::endl;
  }else if(a!=1&&b!=1){
    std::cout<<a*b/2<<std::endl;
  }else std::cout<<1<<std::endl;
  return 0;
}




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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    int r = 0;
    for(int i=0; i<n; i++) {
        r += a[i] * ((i&1) ? -1 : 1);
    }
    cout << r << endl;

}

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

int main(int argc, char *argv[]){
  using namespace std;
  vector<int> res;
  for (int i=0; i<5; ++i){
    int data;
    cin >> data;
    res.push_back(data);
  }
  sort(res.begin(), res.end(), greater<int>());
  vector<int>::iterator it = res.begin();
  while (it != res.end()){
    cout << *it;
    ++it;
    if (it != res.end()){
      cout << " ";
    }
    else{
      cout << endl;
    }
  }
  return 0;
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;


int main(){
  map<char, int> mp;
  char c;
  for(c = 'a'; c <= 'z'; c++) {
    mp[c] = 0;
  }
  char ch;
  while (cin >> ch){
    if (isalpha(ch)) {
      ch = tolower(ch);
      mp[ch]++;
    }
  }
  
  for(auto x : mp) {
    std::cout << x.first << " : " << x.second << endl;
  }
  
}


Measured memory_bytes: 3096