akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    var mx = 0
    val mp = mutableMapOf<String, Int>()

    repeat(n) {
        val s = readLine()!!
        mp[s] = (mp[s] ?: 0) + 1
        mx = Math.max(mx, mp[s]!!)
    }

    mp.entries
            .filter { it.value == mx }
            .map { it.key }
            .sorted()
            .joinToString("\n")
            .let { println(it) }
}


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

int main(void){
  int x, a, b;

  cin >> x >> a >> b;
  
  if(a-b>=0) cout << "delicious" << endl;
  else if(b-a<=x) cout << "safe" << endl;
  else cout << "dangerous" << endl;

  return 0;
}

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

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);++(i))

const int inf=1<<29;

int w,h;
char s[30][60];


int dist[2][30][60][30][60];


// cost l foot r foot isl

struct state{
	int cost;
	int last;
	int lw,lh;
	int rw,rh;
	bool operator>(const state &arg)const{
		return cost > arg.cost;
	}
};

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

inline bool valid(int ww,int hh){
	return 0<=ww&&ww<w&&0<=hh&&hh<h;
}

int dijkstra(){
	rep(a,2)rep(b,30)rep(c,60)rep(d,30)rep(e,60)
		dist[a][b][c][d][e]=inf;

	priority_queue <state,vector<state>,greater<state> >q;

	state init;
	init.cost=0;
	init.lw=-1,init.lh=-1;
	init.rw=-1,init.rh=-1;

	rep(i,w){
		if(s[i][h-1]=='S'){
			state initl=init;
			state initr=init;
			initl.lw=i,initl.lh=h-1,initl.last=0;
			initr.rw=i,initr.rh=h-1,initr.last=1;
			q.push(initl);
			q.push(initr);
		}
	}

	while(!q.empty()){
		state cur=q.top();q.pop();
	//	cerr << cur.last << " " << cur.lw << " " << cur.lh << " " << cur.rw << " " <<cur.rh << endl;
	//	cerr << cur.cost << endl;

		if(dist[cur.last][cur.lw][cur.lh][cur.rw][cur.rh]<cur.cost)
			continue;

		if(s[cur.lw][cur.lh]=='T'||s[cur.rw][cur.rh]=='T')
			return cur.cost;

		if(cur.last){
			rep(i,9){
				state next=cur;
				next.last^=1;
				next.lw=next.rw-dx[i];
				next.lh=next.rh+dy[i];
				if(!valid(next.lw,next.lh))
					continue;

				if(s[next.lw][next.lh]=='X')
					continue;

				if(isdigit(s[next.lw][next.lh])) next.cost+=s[next.lw][next.lh]-'0';

				if(dist[next.last][next.lw][next.lh][next.rw][next.rh]>next.cost){
					dist[next.last][next.lw][next.lh][next.rw][next.rh]=next.cost;
					q.push(next);
				}
			}
		}else{
			rep(i,9){
				state next=cur;
				next.last^=1;
				next.rw=next.lw+dx[i];
				next.rh=next.lh+dy[i];
				if(!valid(next.rw,next.rh))
					continue;

				if(s[next.rw][next.rh]=='X')
					continue;

				if(isdigit(s[next.rw][next.rh])) next.cost+=s[next.rw][next.rh]-'0';

				if(dist[next.last][next.lw][next.lh][next.rw][next.rh]>next.cost){
					dist[next.last][next.lw][next.lh][next.rw][next.rh]=next.cost;
					q.push(next);
				}
			}
		}
	}
	return -1;
}

int main(void){
	while(cin >> w >> h){
		if(w==0&&h==0)
			break;
		rep(j,h)rep(i,w) cin >> s[i][j];
		cout << dijkstra() << endl;
	}
}

Measured memory_bytes: 26660
#include<bits/stdc++.h>
using namespace std;
int n,m;
long long totalsum=0;

int main()
{
	int i,j;
	
	scanf("%d %d",&n,&m);
	
	totalsum += 100*(n-m);
	totalsum += 1900*(m);
	
	int mul=1;
	for(i=0;i<m;i++)
	{
		mul *= 2;
	}
	
	printf("%lld\n",totalsum*mul);
	
	
	
}

Measured memory_bytes: 3824
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>           // sorted map so O(logn)
#include <unordered_map> // O(1)
typedef long long ll;
using namespace std;

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

    if (k <= a)
    {
        cout << k << endl;
    }
    else if (k <= a + b)
    {
        cout << a << endl;
    }
    else
    {
        cout << a - (k - a - b) << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

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

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

  string buf;
  for(pii p: b){
    buf += to_string(p.second + 1) + " ";
  }

  cout << buf << endl;

  return 0;
}


Measured memory_bytes: 2680
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef struct _data {
	int x;
	int y;
} data;

int  main()
{
	string s;
	// fstream in("in05.txt");
	// cin.rdbuf(in.rdbuf());
	cin >> s;
	vector<string> d;
	int i = 0;
	while (i < s.size())
	{
		if (s[i] == s[i + 1])
		{
			if (d.empty() && s[i + 1] != '\0')
			{
				d.push_back(s.substr(i,1));
			}
			else if (s.substr(i, 1) != d[d.size()-1])
			{
				d.push_back(s.substr(i,1));
			}
			else
			{
				d.push_back(s.substr(i,2));
				i++;
			}
		}
		else if(s[i] != s[i + 1])
		{
			if (d.empty())
			{
				d.push_back(s.substr(i,1));
			}
			else if (s.substr(i, 1) != d[d.size()-1])
			{
				d.push_back(s.substr(i,1));
			}
			else if(s[i + 1] != '\0')
			{
				d.push_back(s.substr(i, 2));
				i++;
			}
			// else if (s[i + 1] == '\0')
			// 	d.push_back(s.substr(i, 1));
		}
		i++;
	}
	// string t;
	// rep(i, d.size())
	// {
	// 	t += d[i];
	// 	cout << i+1 <<": "<< d[i] << endl;
	// }
	// cout << t << endl;
	// if (t == s) 
	cout << d.size();
	// else  cout << d.size()+1;
	return (0);
}


Measured memory_bytes: 10996
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;


int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	bool ok = true;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		if (t % 2 == 0 && !(t % 3 == 0 || t % 5 == 0))
			ok = false;
			
	}
	cout << (ok ? "APPROVED" : "DENIED");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}


int main() {

	ll n, k;
	cin >> n >> k;

	ll ans = k*pow((k-1),(n-1));
	
	cout << ans << endl;
}


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

using namespace std;
#define ll long long int
const int MAXN = 2 * 1e5 + 5;

void solve(){
    string s; cin >> s;
    bool p1 = false, p2 = false;
    for(auto & x: s){
        if( x == 'A')
            p1 = true;
        else
            p2 = true;
    }   
    if( p1 and p2)
        cout << "Yes\n";
    else 
        cout << "No\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
	//int t; cin >> t;
	//while(t--)
		solve();
}







Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repr(i, m, n) for (int (i)(m - 1); (i)>=(n); --(i))
#define repv(i, v) for (unsigned (i)(0); (i)<(v.size()); ++(i))
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define sortgi(v) sort(all(v), greater<int>())
#define sortgd(v) sort(all(v), greater<double>())
#define sortgll(v) sort(all(v), greater<ll>())
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using ll = long long;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vpii = vector<pii>;
using pqi = priority_queue<int>;
using pqd = priority_queue<double>;
using pqll = priority_queue<ll>;
using pqvi = priority_queue<vi>;
using pqvll = priority_queue<vll>;

bool toab(const string &s, const vi &ab, const bool isNode[]) {
	bool toa = false, tob = false;
	repv(j, ab) {
		if (!isNode[ab[j]]) {
			continue;
		}
		if (s[ab[j] - 1] == 'A') {
			toa = true;
			if (tob) {
				return true;
			}
		}
		if (s[ab[j] - 1] == 'B') {
			tob = true;
			if (toa) {
				return true;
			}
		}
	}
	return false;
}

int main() {
	int N, M;
	cin >> N >> M;
	string s;
	cin >> s;
	vvi ab;
	ab.resize(N + 1);
	bool isNode[200001];
	rep(i, 0, M) {
		int a, b;
		cin >> a >> b;
		ab[a].push_back(b);
		if (a != b) {
			ab[b].push_back(a);
		}
		isNode[a] = true;
		isNode[b] = true;
	}
	queue<int> q;
	rep(i, 1, N + 1) {
		if (isNode[i]) {
			q.push(i);
		}
		while(!q.empty()) {
			int j = q.front();
			q.pop();
			if (!toab(s, ab[j], isNode)) {
				isNode[j] = false;
				repv(k, ab[j]) {
					if (isNode[ab[j][k]]) {
						q.push(ab[j][k]);
					}
				}
			}
		}
	}
	rep(i, 1, N + 1) {
		if (isNode[i]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 10372
N,M = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = []
for i in range(M-1):
  b.append(a[i+1]-a[i])
b.sort()
if N >= M:
  print(0)
else:
  x = a[M-1]-a[0]
  y = M-2
  for i in range(N-1):
    x -= b[y]
    y -= 1
  print(x)

Measured memory_bytes: 13960
from itertools import accumulate
from bisect import bisect

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_ = list(accumulate(A))
B_ = list(accumulate(B))
A_all = bisect(A_, K)
B_all = bisect(B_, K)
if B_all > A_all:
    A_, B_ = B_, A_
    A_all, B_all = B_all, A_all
ans = 0
for i in range(A_all):
    ans = max(ans, i+1 + bisect(B_, K - A_[i]))
print(ans)

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

const ll MAXN = 200000;

ll H, W, A, B, flag=0;

signed main(){
    cin >> H >> W >> A >> B;
    for(int i=0;i<H;i++) {
        if(i==B) flag=1;
        for(int j=0;j<W;j++) {
            if(!flag) {
                if(j<A) cout << "1";
                else cout << "0";
            }            
            else {
                if(j<A) cout << "0";
                else cout << "1";
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	vector<string> lst={"AC","WA","TLE","RE"};
	map<string,int> ct;
	int N; cin>>N;
	for (int i=0; i<N; i++) {
		string S; cin>>S;
		ct[S]++;
	}
	for (int i=0; i<4; i++)
		cout<<lst[i]<<" x "<<ct[lst[i]]<<"\n";
	return 0;
}

Measured memory_bytes: 3636
import math
def is_prime(N):
    if N == 1:
      return False
    for k in range(2, int(math.sqrt(N))+1):
      if N % k == 0:
          return False
    return True
  
x = int(input())
while True:
  if is_prime(x):
    print(x)
    exit()
  x += 1

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	int a,b;
	cin>>a>>b;
	cout << (b+a-3)/(a-1) << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int count =0;
    for(int i=max(A,B); i>=1; i--){
        if(A%i==0 && B%i==0){
            count++;
        }
        if(count==K){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <atcoder/fenwicktree>

using namespace std;
using namespace atcoder;

int main() {
    int N,Q;
    cin >> N >> Q;
    fenwick_tree<long long int> fw(N);
    for(int i=0;i<N;i++) {
        int a;
        cin >> a;
        fw.add(i, a);
    }

    for(int i=0;i<Q;i++) {
        int t,c,d;
        cin >> t >> c >> d;
        if(t==0){
            fw.add(c, d);
        }else{
            cout << fw.sum(c, d) << endl;
        }
    }
}

Measured memory_bytes: 8232
#include<stdio.h>
int main(void)
{
	int n;
	scanf("%d",&n);
	if(n==1)
	puts("1.0");
	else if(n/2==0)
	puts("0.5");
	
	else{
		
		double m;
		double x=0;
		int i;
		for(i=1; i<=n; i++){
			if(i%2==1)
			x++;
		}
		m=x/n;
		printf("%lf",m);
	}
	
	
	

	return 0;
}

Measured memory_bytes: 1720
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;
  auto as=make_v<int>(n,m);

  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      cin>>as[i][j],as[i][j]--;

  int ans=n;
  for(int t=0;t<m;t++){
    vector<int> cnt(m,0);
    for(int i=0;i<n;i++){
      int k=m;
      for(int j=m-1;j>=0;j--)
        if(~as[i][j]) k=as[i][j];
      cnt[k]++;
    }

    int p=max_element(cnt.begin(),cnt.end())-cnt.begin();
    chmin(ans,cnt[p]);

    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        if(as[i][j]==p) as[i][j]=-1;
  }

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


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

/*bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) { // 素数ではない
			return false;
		}
	}
	// 素数である
	return true;
}*/
/*ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/
/*ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}*/
/*ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}*/
/*ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}*/
//printf("%.10f\n", n);

ll test[12345678];
signed main() {
	string s, t;
	ll n, m, k, a = 0, b = 0, c = 0, cnt = 0;
	cin >> n >> k;
	rep(i, n) { cin >> test[i]; }
	for (int h = k; h < n; h++) {
		if (test[h - k] < test[h]) { cout << "Yes" << endl; }
		else { cout << "No" << endl; }
	}
	return 0;
}

Measured memory_bytes: 5184
#!/usr/bin/env python3
import sys
from collections import deque

def solve(N: int, S: "List[str]"):
    matrix = [[] for _ in range(N)]
    d = [[10**5]*N for _ in range(N)]

    for i in range(N):
        d[i][i] = 0
        for j in range(N):
            if S[i][j] == "1":
                matrix[i].append(j)
                d[i][j] = 1
                d[j][i] = 1
    
    # ２部グラフ 判定
    stack = [(0,1)]
    color = [-1]*N

    while stack:
        node,c = stack.pop()
        color[node] = c

        for next in matrix[node]:
            if color[next] == -1:
                stack.append((next,~c))
            else:
                if c^color[next] == 0:
                    print(-1)
                    return


    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

    answer = 0
    for i in range(N):
        answer = max(answer,max(d[i]))
    print(answer+1)
    return

def main():
    N = int(input())
    S = [input() for _ in range(N)]
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 41456
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a =sc.nextInt();
    int b =sc.nextInt();
    int max = Math.max(a+b,a-b);
    max = Math.max(max,a*b);
    System.out.println(max);
  }
}

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


int N, M , Q;
vector<int> a, b ,c, d;
int ans = 0;

void dfs(vector<int> A){
  if(A.size() == N+1){
    int now = 0;
    rep(i, Q){
      if(A[b[i]] - A[a[i]] == c[i]){
        now += d[i];
      }
    }
    ans = max(ans, now);
    return ;
  }
  A.push_back(A.back());
  while(A.back() <= M){
    dfs(A);
    A.back()++;
  }
}

int main(){

  cin >> N >> M >> Q;
  a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);

  rep(i, Q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  dfs(vector<int>(1, 1));
  cout << ans << endl;
}


Measured memory_bytes: 3616
from collections import deque

n, q = map(int, input().split())
deq = deque()
for i in range(n):
  name, time = input().split()
  time = int(time)
  deq.append((name, time))


cul = 0
ans = []

while deq:
  name, time = deq.popleft()
  if time <= q:
    cul += time
    ans.append("%s %d" % (name, cul))
  else:
    cul += q
    time -= q
    deq.append((name, time))

print(*ans, sep="\n")


Measured memory_bytes: 13388
#include <bits/stdc++.h>
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;
  map<ll,ll> mp;
  rep(i,n){
    int a; cin>>a;
    mp[a]++;
  }
  vector<ll> e;
  for(auto x : mp){
    if(x.second>=2)e.push_back(x.first);
    if(x.second>=4)e.push_back(x.first);
  }
  if(e.size()<2)cout<<0<<endl;
  else cout<<(ll)e[e.size()-1]*e[e.size()-2]<<endl;
}

Measured memory_bytes: 9848
#include<iostream>
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
using namespace std;
int main()
{
    fastio;
    long long n,a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0){cout<<"Alice";}
    else{cout<<"Borys";}
    return 0;
}


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}
template <typename T>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

void solve()
{
	int n, m, x;
	cin >> n >> m >> x;
	vector<vector<int>> a(n, vector<int>(m));
	vector<int> c(n);
	for (int i = 0; i < n; i++)
	{
		cin >> c[i];
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	}
	int ans = 12345678;
	int all = 1 << n;
	for (int mask = 0; mask < all; mask++)
	{
		vi level(m);
		int cst = 0;
		for (int i = 0; i < n; i++)
		{
			if ((mask >> i) & 1)
			{
				cst += c[i];
				for (int j = 0; j < m; j++)
				{
					level[j] += a[i][j];
				}
			}
		}
		bool ok = 1;
		fork(j, m)
		{
			if (level[j] < x)
				ok = 0;
		}
		if (ok)
			ans = min(ans, cst);
	}
	if (ans == 12345678)
		cout << -1 << endl;
	else
		cout << ans << endl;
}

int main()
{
	fast;
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


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

  int a, b;
  cin >> a >> b;

  int ans = 0;
  if (a > b) {
      ans += a;
      --a;
  } else {
      ans += b;
      --b;
  }

  if (a > b) {
      ans += a;
  } else {
      ans += b;
  }

  cout << ans << endl;

}


Measured memory_bytes: 888
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("Yes\n")
#define NO() printf("No\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,a[100000],mi = INF,ma = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		mi = min(a[i],mi);
		ma = max(a[i],ma);
	}
	if(ma - mi >= 2){
		NO();
		return 0;
	}
	if(ma == mi){
		if(mi != n - 1 && n / mi < 2) NO();
		else YES();
	}else{
		int low = 0;
		for(int i = 0;i < n;i++) if(mi == a[i]) low++;
		if(ma - low == 0 || (n - low) / (ma - low) < 2) NO();
		else YES();
	}
	return 0;
}

Measured memory_bytes: 1024
/*
USER: caoash3
LANG: JAVA
TASK: 
*/

import java.io.*;
import java.util.*;

public class Main {

	static final boolean stdin = true;
	static final String filename = "";
	static FastScanner br;
	static PrintWriter pw;

	public static void main(String[] args) throws IOException {

		if (stdin) {
			br = new FastScanner();
			pw = new PrintWriter(new OutputStreamWriter(System.out));
		}

		else {
			br = new FastScanner(filename + ".in");
			pw = new PrintWriter(new FileWriter(filename + ".out"));
		}

		X solver = new X();
		solver.solve(br, pw);
	}

	static class X {
		public void solve(FastScanner br, PrintWriter pw) throws IOException {
			
			int N = br.nextInt();
			int[] in = new int[N];
			
			for(int i = 0; i < N; i++) {
				in[i] = br.nextInt();
			}
			
			long[][] dp = new long[N][N];
			long[][] size = new long[N][N];
			
			for(int i = 0; i < dp.length; i++) {
				for(int j = 0; j < N; j++) {
					dp[i][j] = Integer.MAX_VALUE;
				}
			}
			
			for(int i = 0; i < N; i++) {
				size[i][i] = in[i];
				dp[i][i] = 0;
			}
			for(int l = 1; l < N; l++) {
				for(int s = 0; s < N; s++) {
						if(s + l >= N) {
							continue;
						}
						long min = Long.MAX_VALUE;
						
						int bk = 0;
						
						for(int k = s; k < s+l; k++) {
							long val = dp[s][k] + dp[k+1][s+l] + size[s][k] + size[k+1][s+l];
							if(val < min) {
								min = val;
								bk = k;
							}
						}
						
						dp[s][s+l] = min;
						size[s][s+l] = size[s][bk] + size[bk+1][s+l];
							

					}
			}
			
			
			pw.println(dp[0][N-1]);
			
			pw.close();
		}

	}

	//fastscanner class
	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

}
 



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

int main() {

int x;cin>>x;
for(int a=-120;a<=120;a++)
{
  for (int b = -119; b <= 119; b++)
  {
    if(a*a*a*a*a+b*b*b*b*b==x)
    {cout << a<<" "<<-b<<endl;return 0;}
  }
  
}

}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define PI 3.1415926535897932384626
#define mod 1000000007
#define fo(i,n) for(i=0;i<n;i++)
#define endl "\n"
#define mset(m,v) memset(m,v,sizeof(m))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef vector<int>	vi;
#define FAST_IO  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

void solve()
{
	int n,k,i,j;
	cin >> n ;
	int x[n],y[n],ans[n];
	vi v(200001),a;
	for(i=0;i<n;i++){
	    cin >> x[i];
	    v[x[i]]++;
	}
	for(i=0;i<n;i++){
	    cin >> y[i];
	    v[y[i]]++;
	}
	for(i=0;i<200001;i++){
	    if(v[i]>n){
	        cout << "No" ;
	        return;
	    }
	}
	cout << "Yes" << endl;
	
	for(i=0,j=0,k=n-1;i<n;i++){
	    if(x[i]==y[i]){
	        if(y[i]!=y[k])swap(y[i],y[k]),k--;
	        else swap(y[i],y[j]),j++;
	    }
	}
	for(i=0,j=0,k=n-1;i<n;i++){
	    if(x[i]==y[i]){
	        if(y[i]!=y[k])swap(y[i],y[k]),k--;
	        else swap(y[i],y[j]),j++;
	    }
	}
	for(i=0;i<n;i++){
	    cout << y[i] << ' ';
	}
}

int32_t main()
{
	FAST_IO;
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}

Measured memory_bytes: 7932
#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(10);
  std::cerr << std::fixed << std::setprecision(6);

  double a, b, x;

  std::cin >> a >> b >> x;

  double l = 0.0, u = M_PI / 2;

  for (int i = 0; i < 222; i ++) {
    double m = (l + u) / 2, r, A;

    if (x / a >= a * b / 2) {
      r = a / cos(m);

      A = a * b - r * sin(m) * a / 2.0;
    }
    else {
      r = b / sin(m);

      A = r * cos(m) * b / 2.0;
    }

    (A < x / a ? u : l) = m;
  }

  std::cout << l / M_PI * 180 << std::endl;

  return 0;
}


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

#define ll long long int

int digit(ll n) {
    int ret = 0;
    while(n > 0) {
        n/=10;
        ret++;
    }
    return ret;
}

int main() {
    ll N;
    cin >> N;
    int ans = 20000000;
    for(ll i = 1LL; i * i <= N; ++i) {
        if(N % i != 0) continue;
        ll j = N / i;
        ans = min(max(digit(i),digit(j)), ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	L.append( (math.atan2(y,x),x,y) )

L.sort()
L=L+L

ans=0
for start in range(N):
	for end in range(start,start+N):
		kyori=0
		X=0
		Y=0
		for i in range(start,end+1):
			x=L[i][1]
			y=L[i][2]
			X+=x
			Y+=y
		kyori=(X**2+Y**2)**0.5
		ans=max(ans,kyori)

print ans


Measured memory_bytes: 32876
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs.shift());
const adj = inputs.map((s) => s.split(' ').map(Number));

class Node {
  constructor(id, list) {
    this.id = id;
    this.list = list;
    this.depth = -1;
  }
  toString() {
    return [this.id, this.depth].join(' ');
  }
}

class Graph {
  constructor() {
    this.queue = [];
    this.map = new Map();
  }
  get(id) {
    return this.map.get(id);
  }
  set(id, list) {
    this.map.set(id, new Node(id, list));
  }
  bfs() {
    const root = this.map.get(1);
    root.depth = 0;
    this.queue.push(root);
    while(this.queue.length) {
      const node = this.queue.shift();
      node.list.forEach(id => {
        const child = this.map.get(id);
        if (child.depth !== -1) {
          return;
        }
        child.depth = node.depth + 1;
        this.queue.push(child);
      })
    }
  }
  print() {
    for (let i = 1; i <= this.map.size; i++) {
      const node = this.map.get(i);
      console.log(node.toString());
    }
  }
}

const graph = new Graph();
adj.forEach(([id, k, ...ck]) => {
  graph.set(id, ck);
});
graph.bfs();
graph.print();



Measured memory_bytes: 16672
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[k][i][j] - number of ways from i to j in K step
    OPT[1] = A

    OPT[k] = 
    """
    N, K = read_ints()
    A = []
    modulo = 10**9+7
    for _ in range(N):
        A.append(read_ints())
    def opt(k):
        if k == 1:
            return A
        half_A = opt(k//2)
        new_A = [[0]*N for _ in range(N)]
        for i in range(N):
            for j in range(N):
                for j0 in range(N):
                    new_A[i][j] = (new_A[i][j]+half_A[i][j0]*half_A[j0][j])%modulo
        if k%2 == 0:
            return new_A
        new_A2 = [[0]*N for _ in range(N)]
        for i in range(N):
            for j in range(N):
                for j0 in range(N):
                    new_A2[i][j] = (new_A2[i][j]+new_A[i][j0]*A[j0][j])%modulo
        return new_A2
    return sum(c for row in opt(K) for c in row)%modulo



if __name__ == '__main__':
    print(solve())


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

int main(int argc, char const *argv[])
{
    int n, k; string s;
    cin >> n >> s >> k;
    char tgt = s[k-1];
    for(auto i = s.begin();i!=s.end();++i) {
        if(*i!=tgt) cout << "*";
        else cout << *i;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	static class E {
		int i, j, w;
		E(int i, int j, int w) {
			this.i = i; this.j = j; this.w = w;
		}
	}
	void main() {
		int n = sc.nextInt();
		int[][] aa = new int[n][n];
		int[][] dd = new int[n][n];
		int m = n * n;
		E[] ee = new E[m];
		m = 0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) {
				int w = sc.nextInt();
				aa[i][j] = w;
				dd[i][j] = INF;
				ee[m++] = new E(i, j, w);
			}
		Arrays.sort(ee, (e, f) -> e.w - f.w);
		long ans = 0;
		for (int h = 0; h < m; h++) {
			E e = ee[h];
			int i = e.i, j = e.j, w = e.w;
			int d = dd[i][j];
			for (int k = 0; k < n; k++)
				d = Math.min(d, dd[i][k] + dd[k][j]);
			if (d > w) {
				d = w;
				ans += w;
			}
			dd[i][j] = dd[j][i] = d;
			for (int k = 0; k < n; k++) {
				dd[i][k] = dd[k][i] = Math.min(dd[i][k], d + dd[j][k]);
				dd[j][k] = dd[k][j] = Math.min(dd[j][k], d + dd[i][k]);
			}
		}
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				if (dd[i][j] != aa[i][j]) {
					println(-1);
					return;
				}
		println(ans);
	}
}


Measured memory_bytes: 62924
k, a, b = map(int, input().split())


def intelliegnt():
    if b > a + 2 and k > a - 1:
        kk = k
        kk -= a - 1
        print(a + ((b - a) * (kk // 2)) + kk % 2)

    else:
        print(1 + k)


def greedy():
    biscuit = 1
    yen = 0

    for i in range(k):
        if yen > 0:
            yen -= 1
            biscuit += b
        elif b > a + 2 and biscuit >= a and (k - i) > 1:
            biscuit -= a
            yen += 1
        else:
            biscuit += 1

    print(biscuit)


if __name__ == "__main__":
    intelliegnt()


Measured memory_bytes: 3064
//============================================================================
// Name        : Hello.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main() {

	string s,t;
	cin>>s>>t;

	int ans=0;
	for(int i=0;i<3;i++){
		if(s[i]==t[i]){
			ans+=1;
		}
	}

	cout<<ans<<endl;





	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n;
	int x;
	int s[101];
	int i;
	int x1 = 0, co = 0;

	scanf("%d %d", &n, &x);
	for (i = 0; i < n; i++) {
		scanf("%d", &s[i]);
	}
	for (i = 0; i < n; i++) {
		if (x1 <= x) {
			co++;
		}
		x1 = x1 + s[i];
		
	}
	if (x1 <= x) {
		co++;
	}
	printf("%d\n", co);
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        for line in sys.stdin:
            lines.append(line.strip())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    s = lines[0]
    

    return (s, )


def solve(s):

    result = s
    if s[-1] == 's':
        result = result + 'es'
    else:
        result = result + 's'

    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 62112
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
long double l;
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
} 
int main()
{
	cin>>l;
	printf("%.12Lf\n",pow(l/3,3));
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define all(x) (x).begin(), (x).end()
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}

template<typename T>
vector<T> make_unique(vector<T> v) {
    sort(all(v));
    return v.resize(unique(all(v)) - v.begin());
}

int nxt() {
    int x;
    cin >> x;
    return x;
}


int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

//#############################
const int MAXN = 1000005;

int main() {
    ll a = nxt(), b = nxt(), c = nxt(), d = nxt();

    ll sum = 0;
    sum += max(0LL, min(d, a));
    d -= (a+b);
    sum -= max(0LL, min(d, c));
    d -= c;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3188
#include<iostream>

using namespace std;

int main() {
	int five, seven, a, b, c;
	five = seven = 0;
	cin >> a >> b >> c;
	if (a == 5) {
		five++;
	}
	else if (a == 7) {
		seven++;
	}
	if (b == 5) {
		five++;
	}
	else if (b == 7) {
		seven++;
	}
	if (c == 5) {
		five++;
	}
	else if (c == 7) {
		seven++;
	}
	if (five == 2 && seven == 1) {
		cout << "YES\n";
	}
	else {
		cout << "NO\n";
	}
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,cnt[30];
string s;
int main() {
	cin>>n>>s;
	for(int i=0;i<n;i++){
		ll num=s[i]-'a';
		cnt[num]++;
	}
	ll ans=1,mod=1e9+7;
	for(int i=0;i<26;i++){
		ans*=(cnt[i]+1);
		ans%=mod;
	}
	cout<<ans-1;
	return 0;
}


Measured memory_bytes: 512
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
forward = 1
f = ''
b = ''
for i in range(Q):
    if query[i][0] == '1':
        forward *= -1
    else:
        if query[i][1] == '1':
            if forward == 1:
                f += query[i][2]
            else:
                b += query[i][2] 
        else:
            if forward == 1:
                b += query[i][2] 
            else:
                f += query[i][2]
S = ''.join(list(reversed(f))) + S + b

if forward == -1:
    ans = ''.join(list(reversed(S)))
else:
    ans = S
print(ans)


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define REP(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  u64 A = 0, B;
  double Bin;
  cin >> A >> Bin;

  B = Bin * 100 + 0.9;

  cout << (u64)(A * B) / 100;

  return 0;
}


Measured memory_bytes: 3744
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, k;

signed main() {
	cin >> n >> k;
	if (k == 1)cout << 0 << endl;
	else cout << n - k << endl;
}

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;

const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,60){
        ll x = 0;
        rep(j,n) if(a[j] >> i & 1) ++x;
        ll now = x * (n - x) % MOD;
        rep(j,i) now = now * 2 % MOD;
        ans += now;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=1e5+9;
vector<int>v[N];
int h[N];
int main()
{
    FASTINOUT;
    int x,m,l,r,ans=0;
    cin>>x>>m;
    for (int i=1; i<=x; i++)
        cin>>h[i];
    for (int i=0; i<m; i++)
    {
        cin>>l>>r;
        v[l].push_back(r);
        v[r].push_back(l);
    }
    for (int i=1; i<=x; i++)
    {
        if (v[i].empty())
        {
            ans++;
            continue;
        }
        int mx=0;
        for (int j=0; j<v[i].size(); j++)
        {
            mx=max(mx,h[v[i][j]]);
        }
        if(mx<h[i])
            ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 9176
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String[] read = scan.nextLine().split(" ", 3);
    int L = Integer.parseInt(read[0]);
    int R = Integer.parseInt(read[1]);
    int d = Integer.parseInt(read[2]);
    
    int count = 0;
    for (int i=L; i<=R; i++){
      if(i%d == 0){
        count++;
      }
    }
    
    System.out.println(count);
  }
}

Measured memory_bytes: 35636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_1(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define rep_2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  int n;
  cin >> n;
  n %= 1000;
  n = 1000 - n;
  cout << n % 1000 << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI 3.14159265358979323846264338327950L

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

bool isPalindrome(string s){
    REP(i, s.length() / 2){
        if(s[i] != s[(s.length() - 1) - i]){
            return false;
        }
    }
    return true;
}

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

ll N, M, i, j, k, l, tmp, ans;
ll D, x, y;

int main(){
    cin >> N >> D;
    D *= D;
    REP(i, N){
        cin >> x >> y;
        if(x*x + y*y <= D){
            ans++;
        }
    }

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

Measured memory_bytes: 3632