akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N;
    cin >> N;
    vector<int> s(N);
    REP (i, 0, N) cin >> s[i];
    vector<vector<bool>> sum(N, vector<bool>(10110, 0));
    sum[0][s[0]] = sum[0][0] = true;
    REP (i, 0, N - 1) {
        REP (j, 0, sum[i].size()) {
            if (sum[i][j]) {
                sum[i + 1][j] = true;
                sum[i + 1][j + s[i + 1]] = true;
            }
        }
    }
    int ans = 0;
    REP (i, 0, sum[N - 1].size()) {
        if (sum[N - 1][i]) {
            int cnt = i;
            if (i % 10 == 0) cnt = 0;
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<pair<vector<int>, vector<int>>>V1;
vector<pair<vector<int>, vector<int>>>V2;
int N, M, K, l[10], r[10], s[10];
int power[10];
int main() {
	cin >> N >> M >> K;
	power[0] = 1;
	for (int i = 1; i < 8; i++) {
		power[i] = power[i - 1] * (M + 1);
	}
	int M1 = N / 2, M2 = N - M1;
	for (int i = 0; i < K; i++) {
		cin >> l[i] >> r[i] >> s[i];
		l[i]--; r[i]--;
	}
	if (N == 1) {
		for (int i = 0; i <= M; i++) {
			bool OK = false;
			for (int j = 0; j < K; j++) {
				if (i != s[i]) { OK = true; }
			}
			if (OK == false) { cout << i << endl; }
			return 0;
		}
		cout << "-1" << endl;
		return 0;
	}
	for (int i = 0; i < power[M1]; i++) {
		int BIT[10], Q[10];
		for (int j = 0; j < 10; j++) { BIT[j] = 0; Q[j] = 0; }
		for (int j = 0; j < M1; j++) {
			BIT[j] = (i / power[j]) % (M + 1);
		}
		for (int j = 0; j < M1; j++) {
			Q[j] = BIT[j];
		}
		vector<int>V_1, V_2;
		for (int j = 0; j < N; j++) { V_2.push_back(Q[j]); }
		for (int j = 0; j < K; j++) {
			int sum = 0;
			for (int k = l[j]; k <= r[j]; k++) {
				sum += Q[k];
			}
			V_1.push_back(sum);
		}
		V1.push_back(make_pair(V_1, V_2));
	}
	for (int i = 0; i < power[M2]; i++) {
		int BIT[10], Q[10];
		for (int j = 0; j < 10; j++) { BIT[j] = 0; Q[j] = 0; }
		for (int j = 0; j < M2; j++) {
			BIT[j] = (i / power[j]) % (M + 1);
		}
		for (int j = 0; j < M2; j++) {
			Q[j + M1] = BIT[j];
		}
		vector<int>V_1, V_2;
		for (int j = 0; j < N; j++) { V_2.push_back(Q[j]); }
		for (int j = 0; j < K; j++) {
			int sum = 0;
			for (int k = l[j]; k <= r[j]; k++) {
				sum += Q[k];
			}
			V_1.push_back(sum);
		}
		V2.push_back(make_pair(V_1, V_2));
	}
	sort(V2.begin(), V2.end());
	vector<int>V6; int maxn = 0;
	for (int i = 0; i < V1.size(); i++) {
		vector<int>V3, V4, V5;
		vector<int>L1 = V1[i].first;
		vector<int>L2 = V1[i].second;
		for (int j = 0; j < K; j++) {
			V3.push_back(s[j] - L1[j]);
		}
		for (int j = 0; j < M2; j++) { V4.push_back(0); }
		for (int j = 0; j < M2; j++) { V5.push_back(999); }
		int pos1 = lower_bound(V2.begin(), V2.end(), make_pair(V3, V4)) - V2.begin();
		int pos2 = lower_bound(V2.begin(), V2.end(), make_pair(V3, V5)) - V2.begin();
		for (int j = pos1; j < pos2; j++) {
			int sum2 = 0;
			for (int k = 0; k < M1; k++) { sum2 += L2[k]; }
			vector<int>V7 = V2[j].second;
			for (int k = M1; k < N; k++) { sum2 += V7[k]; }
			if (sum2 > maxn) {
				maxn = sum2;
				vector<int>V8;
				for (int k = 0; k < M1; k++) { V8.push_back(L2[k]); }
				for (int k = M1; k < N; k++) { V8.push_back(V7[k]); }
				V6.clear(); V6 = V8;
			}
		}
	}
	if (V6.size() == 0) { cout << "-1" << endl; }
	else {
		for (int i = 0; i < N; i++) {
			if (i) { cout << ' '; }
			cout << V6[i];
		}
	}
	return 0;
}

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

signed main(){
	string s; cin >> s;
	string t;
	for(lint i = 0; i < s.size(); i++){
		if(s[i] == 'B' && s[i + 1] == 'C'){
			t.push_back('D');
			i++;
		}
		else{
			t.push_back(s[i]);
		};
	}
	lint ans = 0, counter = 0;
	for(lint i = 0; i < t.size(); i++){
		if(t[i] == 'A') counter++;
		else if(t[i] == 'D') ans += counter;
		else counter = 0;
	}
	cout << ans << endl;
}

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

using namespace std;

int main() {
    string x;
    int a = 0, c = 0;
    cin >> x;
    for (int i = 0; i < x.size(); ++i) {
        switch (x.at(i)) {
            case 'S': ++c; break;
            case 'T': if (c) --c; else ++a; break;
        }
    }
    cout << a + c << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pii pair<int,int> 
#define fi first
#define pb push_back
#define si second
#define int long long int
#define mod 998244353
using namespace std;
int f[200005];
int power(int n,int p)
{
	int ans=1;
	while(p)
	{
		if(p&1)
		{
			ans=ans*n;
			ans%=mod;
		}
		n=n*n%mod;
		p=p>>1;
		
		
	}
	return ans%mod;;
}
int inverse(int n)
{
	return power(n,mod-2);
}
int nc(int n,int r)
{
	if(n<r)
		return 0;
	return f[n]%mod*inverse(f[r])%mod*inverse(f[n-r])%mod;
}

int32_t main(){
	int n,m,k,i;
	f[0]=1;
	for(i=1;i<=2e5;i++)
		f[i]=f[i-1]*i%mod;
	cin>>n>>m>>k;
	
	int ans=0;
	for(i=n-k-1;i<n;i++)
	{	ans+=nc(n-1,i)*m%mod*power(m-1,i)%mod;
		ans%=mod;
	}
	cout<<ans<<"\n";
	
	

}

Measured memory_bytes: 5208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int col = scanner.nextInt();
		final int row = scanner.nextInt();
		final int selectCol = scanner.nextInt();
		final int selectRow = scanner.nextInt();

		System.out.println((col - selectCol) * (row - selectRow));
		scanner.close();
	}

}

Measured memory_bytes: 25556
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int N;
    vector<int> a;

    cin >> N;

    int x;
    for (int i = 0; i < N; i++){
        cin >> x;
        a.push_back(x);
    }

    int s = -1;
    int sum = 0;
    bool inc;
    for (int i = s; i < N; i++){
        for (int k = s + 1; k < N; k++){
            if (a[k] > a[k+1]){
                inc = false;
                sum++;
                break;
            } else if (a[k] < a[k+1]){
                inc = true;
                sum++;
                break;
            }
        }

        for (int k = s + 1; k < N; k++){
            if (a[k] > a[k+1] && inc){
                inc = false;
                s = k;
                break;
            } else if (a[k] < a[k+1] && !inc){
                inc = true;
                s = k;
                break;
            }
            s = k;
        }
    }
            
    cout << sum << endl;
}


Measured memory_bytes: 892
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse4,sse4.2,popcnt,abm,mmx,avx")
#endif
#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

vector<int> a, b, res;

int n;

map<int, int> cnt_a, cnt_b;

const int RANDOM =
    chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);

bool validate() {
  bool valid = true;
  for (int i = 0; i < n; ++i) {
    valid &= (a[i] != res[i]);
  }
  return valid;
}

bool solve() {
  res = b;
  for (int t = 0; t < 300; ++t) {
    rotate(begin(res), begin(res) + rng() % n, end(res));
    if (validate()) return true;
  }
  res = b;
  reverse(all(res));
  for (int t = 0; t < 300; ++t) {
    if (validate()) return true;
    shuffle(all(res), rng);
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif
  cin >> n;
  a.resize(n), b.resize(n), res.resize(n);
  cin >> a >> b;
  for (int x : b) ++cnt_b[x];
  for (int x : a) {
    ++cnt_a[x];
    if (cnt_b.count(x) && cnt_b[x] + cnt_a[x] > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  if (solve()) {
    cout << "Yes" << endl;
    cout << res << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;
}


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

int main(){
    int n , m , x;
    cin >> n >> m;
    int arr[n+5] = {0};
    
    for(int i = 1; i <= m; i++){
        cin >> x;
        arr[x]++;
    }
    
    long long dp[n+5] = {0};
    dp[0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= 2; j++){
            if(i-j>=0){
                dp[i] += dp[i-j];
                dp[i]%=1000000007;
            }
        }
        if(arr[i]>0){
            dp[i] = 0;
        }
    }
    cout << dp[n] << '\n';
}

Measured memory_bytes: 1408
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cctype>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
 
using namespace std;
const int N=105;
int n,a[N],x,mx;
 
int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}
 
bool check()
{
	if(mx==1) return n!=2;
	if(a[mx]==1) return 1;
	int mn=(mx+1)>>1;
	rep(i,1,mn-1) if(a[i]) return 1;
	rep(i,mn+1,mx) if((a[i]-=2)<0) return 1;
	if(mx&1) a[mn]-=2;
	else a[mn]-=1;
	if(a[mn]) return 1;
	return 0;
}

int main()
{
	n=getint();
	rep(i,1,n) mx=max(mx,x=getint()),++a[x];
	if(check()) puts("Impossible");
	else puts("Possible");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>


	typedef struct{

		int zikoku;
		int PC;
		int gakusei;
		int login;
	}situmon1;

	typedef struct{
		int zikan1;
		int zikan2;
		int gakusei;
	}situmon2;



int main(){
	
	int pc,seito,kiroku1,i,j,a=0,kiroku2,pccount=0,login,logout,kotae[1000]={};
	situmon1 data1[1000];
	situmon2 data2[50];

	while(pc!=0&&seito!=0){
//利用時間の取得
	scanf("%d",&pc);
	scanf("%d",&seito);
	if(pc!=0&&seito!=0){
	scanf("%d",&kiroku1);
	for(i=0;i<kiroku1;i++){

		scanf("%d",&data1[i].zikoku);
		scanf("%d",&data1[i].PC);
		scanf("%d",&data1[i].gakusei);
		scanf("%d",&data1[i].login);

	}

//質問に答えるための取得
	scanf("%d",&kiroku2);
	for(j=0;j<kiroku2;j++){

		scanf("%d",&data2[j].zikan1);
		scanf("%d",&data2[j].zikan2);
		scanf("%d",&data2[j].gakusei);

	}

	for(j=0;j<kiroku2;j++){


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

			

			if(pccount==0&&data1[i].login==1&&data2[j].gakusei==data1[i].gakusei){

				pccount+=1;
				login=data1[i].zikoku; //生徒のログインした時間


		
			}else if(data1[i].login==1&&data2[j].gakusei==data1[i].gakusei){
				pccount+=1;
			}
			if(data1[i].login==0&&data2[j].gakusei==data1[i].gakusei){

				pccount-=1;
				logout=data1[i].zikoku; //生徒のログアウトした時間
			}
			if(pccount==0&&data2[j].zikan1<=login&&login<=data2[j].zikan2&&data2[j].zikan2<=logout&&data2[j].gakusei==data1[i].gakusei){

				kotae[a]+=data2[j].zikan2-login;

				break;
			}else if(pccount==0&&login<=data2[j].zikan1&&data2[j].zikan2<=logout&&data2[j].gakusei==data1[i].gakusei){

				kotae[a]+=data2[j].zikan2-data2[j].zikan1;

				break;
			}else if(pccount==0&&login<=data2[j].zikan1&&data2[j].zikan1<=logout&&logout<=data2[j].zikan2&&data2[j].gakusei==data1[i].gakusei){

				kotae[a]+=logout-data2[j].zikan1;

			}else if(pccount==0&&data2[j].zikan1<=login&&login<=data2[j].zikan2&&data2[j].zikan1<=logout&&logout<=data2[j].zikan2&&data2[j].gakusei==data1[i].gakusei){

				kotae[a]+=logout-login;
				
			}
		}
	

		a+=1;

	}

	}

	}
	for(i=0;i<a;i++){

		printf("%d\n",kotae[i]);

	}
	return 0;

	}

Measured memory_bytes: 620
def judge(A, B, C):
  if A < B:
    if B < C:
      return True
  return False
  
A, B, C = map(int, input().split())
K = int(input())
ans = "No"
for _ in range(K):
  if B <= A:
    B = B * 2
  elif C <= B:
    C = C * 2
  
  if judge(A, B, C):
    ans = "Yes"
    break
print(ans)


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

int main()
{
  int A, B, C, X, Y, r;
  int ans = 0;

  cin >> A >> B >> C >> X >> Y;
  r = X - Y;
  if (2 * C <= A && r >= 0)
  {
    if (A <= C)
      ans = 2 * C * r + A * min(r, X - r) + min(2 * C, A + B) * max(X - 2 * r, 0) / 2;
    else
      ans = 2 * C * r + min(2 * C, A + B) * (X + Y - r) / 2;
  }
  else if (2 * C <= B && r < 0)
  {
    if (B <= C)
      ans = 2 * C * abs(r) + B * min(r, Y - abs(r)) + min(2 * C, A + B) * max(Y - 2 * abs(r), 0) / 2;
    else
      ans = 2 * C * abs(r) + min(2 * C, A + B) * (X + Y - abs(r)) / 2;
  }
  else if (r >= 0)
    ans = A * r + min(2 * C, A + B) * (X + Y - r) / 2;
  else
    ans = B * abs(r) + min(2 * C, A + B) * (X + Y - abs(r)) / 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int N, M, ans = 0;
vector<set<int>> G;
bool connect(vector<set<int>> g)
{
    vector<bool> ar(N + 1);
    queue<int> q;
    int count = 0;
    if (g[1].empty())
    {
        return false;
    }
    q.push(1);
    while (!q.empty())
    {
        int node = q.front();
        q.pop();
        for (auto i : g[node])
        {
            if (ar[i] == false)
            {
                q.push(i);
                ar[i] = true;
                count++;
            }
        }
    }
    return count == N;
}
int main()
{

    cin >> N >> M;
    G.resize(N + 1);
    vint deg(N + 1);
    vector<pair<int, int>> edge(M + 1);
    rep2(i, 1, M + 1)
    {
        int a, b;
        cin >> a >> b;
        G[a].insert(b);
        G[b].insert(a);
        edge[i] = {a, b};
    }
    auto tmpG = G;
    rep2(i, 1, M + 1)
    {
        tmpG = G;
        int a = edge[i].first, b = edge[i].second;
        tmpG[a].erase(b);
        tmpG[b].erase(a);
        if (!connect(tmpG))
        {
            ans++;
        }
    }
    cout << ans;
    return 0;
}

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

using namespace std;

template <long long Mod> struct ModInt { /* {{{ */
  long long v;
  constexpr ModInt(const long long x = 0) {
    v = x % Mod;
    if (v < 0) {
      v += Mod;
    }
  }
  constexpr ModInt operator+(const ModInt rhs) const { return ModInt(*this) += rhs; }
  constexpr ModInt operator-(const ModInt rhs) const { return ModInt(*this) -= rhs; }
  constexpr ModInt operator*(const ModInt rhs) const { return ModInt(*this) *= rhs; }
  constexpr ModInt operator/(const ModInt rhs) const { return ModInt(*this) /= rhs; }
  const ModInt &operator+=(const ModInt rhs) {
    v += rhs.v;
    if (v >= Mod) {
      v -= Mod;
    }
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) {
    if (v < rhs.v) {
      v += Mod;
    }
    v -= rhs.v;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) {
    v = v * rhs.v % Mod;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) {
    long long exp = Mod - 2;
    while (exp) {
      if (exp & 1) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp >>= 1;
    }
    return *this;
  }
  friend ostream &operator<<(ostream &s, ModInt<Mod> m) {
    s << m.v;
    return s;
  }
  friend istream &operator>>(istream &s, ModInt<Mod> m) {
    s >> m.v;
    return s;
  }
}; /* }}} */

const int mod = 1e9 + 7;
using modint = ModInt<mod>;

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

modint pow_2(int exp) {
  modint a = 2;
  modint ret = 1;
  while (exp) {
    if (exp & 1) ret *= a;
    a *= a;
    exp >>= 1;
  }
  return ret;
}

int main() {
  int N;
  cin >> N;
  map<pair<long long, long long>, int> m;
  for (int i = 0; i < N; i++) {
    long long a, b;
    cin >> a >> b;
    if (a == 0 and b == 0) {
      m[{0, 0}]++;
      continue;
    } else if (a == 0) {
      m[{0, 1}]++;
      continue;
    } else if (b == 0) {
      m[{1, 0}]++;
      continue;
    }
    long long c = gcd(abs(a), abs(b));
    a /= c;
    b /= c;
    if (a < 0) {
      a *= -1;
      b *= -1;
    }
    m[{a, b}]++;
  }
  map<pair<long long, long long>, bool> done;
  modint ans = 1;
  for (auto p : m) {
    if (done[p.first]) continue;

    auto a = p.first.first;
    auto b = p.first.second;

    if (a == 0 and b == 0) continue;

    modint v = pow_2(p.second);
    done[p.first] = true;

    pair<long long, long long> p2;
    if (b > 0) {
      p2 = {b, -a};
    } else {
      p2 = {-b, a};
    }
    if (m[p2] > 0) {
      v += pow_2(m[p2]) - 1;
    }
    done[p2] = true;
    ans *= v;
  }
  if (m[{0, 0}]) ans += m[{0, 0}];
  cout << ans - 1 << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 53460
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a + (b - 1)) / b; }
int positive_surplus(int &a) { return (a + MOD) % MOD; }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}
int N, M, Q;
int a[50];
int b[50];
int c[50];
int d[50];
int maxi = 0;
void calc(vector<int> &A) {
  int ret = 0;
  rep(i, Q) if (A[b[i] - 1] - A[a[i] - 1] == c[i]) ret += d[i];
  maxi = max(maxi, ret);
}

void with_replacement(vector<int> &A, int num) {
  if (num == N - 1) {
    calc(A);
  } else {
    FOR(i, A[num], M + 1) {
      A[num + 1] = i;
      with_replacement(A, num + 1);
    }
  }
}

class CManyRequirements {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    cin >> N >> M >> Q;
    rep(i, Q) {
      cin >> a[i];
      cin >> b[i];
      cin >> c[i];
      cin >> d[i];
    }
    FOR(i, 1, M + 1) {
      vector<int> A(N);
      A[0] = i;
      with_replacement(A, 0);
    }
    cout << maxi << endl;
  }
};


signed main() {
  CManyRequirements solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Graph vector<vector<ll>>
constexpr ll INF=(1ll<<60);
constexpr ll mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int main(){
    ll n;cin>>n;
    vector<ll> a(n),ins(n);
    rep(i,n){
        cin>>a[i];
    }

    vector<ll> dp(90,-1);
    dp[0]=1000;

    rep(i,n-1){
        if(dp[i]<(dp[i]/a[i])*a[i+1]+(dp[i]%a[i])){
            dp[i+1]=(dp[i]/a[i])*a[i+1]+(dp[i]%a[i]);
        }else{
            dp[i+1]=dp[i];
        }
    }

    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct Combination {
    vector<int64_t> fact, rfact;
    Combination(int sz) : fact(sz + 1), rfact(sz + 1) {
        fact[0] = 1;
        for(int i = 1; i < fact.size(); i++){
            fact[i] = fact[i - 1] * i % mod;
        }
        rfact[sz] = inv(fact[sz]);
        for(int i = sz - 1; i >= 0; i--){
            rfact[i] = rfact[i + 1] * (i + 1) % mod;
        }
    }
    int64_t inv(int x) const {
        return pow(x, mod - 2);
    }
    int64_t pow(int64_t x, int64_t n) const {
        int64_t ret = 1;
        while(n > 0){
            if(n & 1) (ret *= x) %= mod;
            (x *= x) %= mod;
            n >>= 1;
        }
        return (ret);
    }
    int64_t P(int n, int r) const {
        if(r < 0 || n < r) return (0);
        return (fact[n] * rfact[n - r] % mod);
    }

    int64_t C(int p, int q) const {
        if(q < 0 || p < q) return (0);
        return (fact[p] * rfact[q] % mod * rfact[p - q] % mod);
    }

    int64_t H(int n, int r) const {
        if(n < 0 || r < 0) return (0);
        return (r == 0 ? 1 : C(n + r - 1, r));
    }
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    Combination cb(100000);
    for(int i = 1; i <= k; i++){
        int tmp = cb.C(k - 1, i - 1);
        int r = n - k - (i - 1);
        if(r < 0){
            cout << 0 << endl;
            continue;
        }
        tmp = tmp * cb.C(r + i, i) % mod;
        // cout << i << ' ' << cb.C(k - 1, i - 1) << ' ' << cb.C(r + i, i) << endl;
        cout << tmp << endl;
    }
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cmath>
//#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
#include<set>
//#include<map>
//#include<list>

/**/

using namespace std;
using LLI = long long int;

const int MAX_N = 25;
int n, W;
int w[MAX_N], v[MAX_N];

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//int gcd(int x, int y) {
//	int tmp, r;
//	if (x < y) {
//		tmp = x;
//		x = y;
//		y = tmp;
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}

int calc(LLI X, LLI Y, LLI &cnt) {
	if (X * 2 <= Y) {
		cnt++;
		calc(X * 2, Y, cnt);
	}
	return cnt;
}

int main(void) {
	LLI X, Y, cnt = 1;
	cin >> X >> Y;
	cout << calc(X, Y, cnt) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

typedef long long ll;

const int mod = 1000000007;
const int Maxn = 200005;

int fac[Maxn], inv[Maxn];
int n;
vector <int> neigh[Maxn];
int cnt[Maxn], ways[Maxn];
int res[Maxn];

int toPower(int a, int p)
{
    int res = 1;
    while (p) {
        if (p & 1) res = ll(res) * a % mod;
        p >>= 1; a = ll(a) * a % mod;
    }
    return res;
}

int Inv(int x) { return toPower(x, mod - 2); }

int C(int n, int k)
{
    if (n < 0 || k < 0 || k > n) return 0;
    return ll(fac[n]) * inv[k] % mod * inv[n - k] % mod;
}

void Traverse(int v, int p = 0)
{
    ways[v] = 1;
    for (int i = 0; i < neigh[v].size(); i++) {
        int u = neigh[v][i];
        if (u == p) continue;
        Traverse(u, v);
        cnt[v] += cnt[u];
        ways[v] = ll(ways[v]) * ways[u] % mod * C(cnt[v], cnt[u]) % mod;
    }
    cnt[v]++;
}

void Traverse2(int v, int p = 0, int w = 1)
{
    res[v] = ll(ways[v]) * w % mod * C(n - 1, n - cnt[v]) % mod;
    for (int i = 0; i < neigh[v].size(); i++) {
        int u = neigh[v][i];
        if (u == p) continue;
        Traverse2(u, v, ll(res[v]) * Inv(ll(C(n - 1, cnt[u])) * ways[u] % mod) % mod);
    }
}

int main()
{
    fac[0] = inv[0] = 1;
    for (int i = 1; i < Maxn; i++) {
        fac[i] = ll(i) * fac[i - 1] % mod;
        inv[i] = Inv(fac[i]);
    }
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; scanf("%d %d", &a, &b);
        neigh[a].push_back(b);
        neigh[b].push_back(a);
    }
    Traverse(1);
    Traverse2(1);
    for (int i = 1; i <= n; i++)
        printf("%d\n", res[i]);
    return 0;
}


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

using namespace std;
int x,n,n1,n2,n3,n4;
string s;
int main()
{
cin>>n;
while(n--)
{
    cin>>s;
    if(s=="AC")
        n1++;
    if(s=="WA")
        n2++;
        if(s=="TLE")
        n3++;
        if(s=="RE")
        n4++;

}
 cout<<"AC x "<<n1<<"\n";
         cout<<"WA x "<<n2<<"\n";
          cout<<"TLE x "<<n3<<"\n";
           cout<<"RE x "<<n4<<"\n";
    return 0;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e15;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  cout << N * (N + 1) / 2 - N << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
using namespace std;
const int maxn = 200005;
int pre[maxn];
const int mod = 2019;
int main(){
    string s;
    cin >> s;
    int n = s.length();
    int factor = 1;
    for(int i = n - 1; i >= 0; --i){
        int num = (int)(s[i] - '0');
        num *= factor;
        num %= mod;
        pre[i] = num;
        factor *= 10;
        factor %= 2019;
    }
    for(int i = 1; i < n; ++i){
        pre[i] += pre[i - 1];
        pre[i] %= 2019;
    }
    // for(int i = 0; i < n; ++i){
    //     cout << pre[i] << " ";
    // }
    // cout << endl;
    long long int ans = 0;
    map<int, int> mp;
    mp[0] = 1;
    for(int i = 0; i < n; ++i){
        int num = pre[i];
        int cnt = 0;
        if(mp.count(num)){
            cnt = mp[num];
        }
        ans += (long long int) cnt;
        mp[num]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4468
/* ex4_1
    nnasy */

#include <stdio.h>
#include <math.h>

int main(void) {
    // 宣言と入力
    int num, supervised;
    scanf("%d%d", &num, &supervised);

    // 切り上げ計算による必要な監視員の最小数の出力
    printf("%d\n", (num+(2*supervised+1)-1)/(2*supervised+1));

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
void Digvijay()
{
   string s,t;
   cin>>s>>t;
   int ans =0;
   for(int i=0;i<s.length();i++)
   {
       if(s[i]!=t[i])ans++;
   }
   cout<<ans<<"\n";
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=0;__<_;__++)
    {
        Digvijay();
    }
}

Measured memory_bytes: 3716
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
long long a[100010];
long long ans[100010];
//全部乘以2后再处理 

int main()
{
	scanf("%d", &n);
	
	long long sum = 0;
	for (int i = 0 ; i < n ; i++)
	{
		scanf("%d", &(a[i]));
		a[i] = a[i] * 2;
		sum = sum + a[i];
	}
	
	long long total = sum / 2;
	long long headA = 0;
	long long lineA = 0;
	for (int i = 1 ; i < n ; i += 2)
	{
		lineA = lineA + a[i];
	}
	
	int p = 0;
	while (p < n)
	{
		long long section = headA + lineA;
		ans[p] = total - section;
		headA = headA + a[p];
		lineA = lineA - a[p + 1];
		p = p + 2;
	}
	
	
	long long headB = 0;	
	long long lineB = 0;
	for (int i = 2 ; i < n ; i += 2)
		lineB = lineB + a[i];
	
	p = 1;
	while (p < n)
	{
		long long section = headB + lineB;
		ans[p] = total - section;
		headB = headB + a[p];
		lineB = lineB - a[p + 1];
		p = p + 2;
	}
	
	printf("%d", ans[0]);
	for (int i = 1 ; i < n ; i++)
		printf(" %d", ans[i]);

	
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define vec(type) vector<type>

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

	if (a <= 0 && 0 <= b) cout << "Zero" << endl;
	else if (a > 0) cout << "Positive" << endl;
	else if ((b-a)%2==1) cout << "Positive" << endl; 
	else cout << "Negative" << endl;
}

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

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
/* }}} */

signed main() 
{
  int n;
  cin >> n;
  if(n/100==n%10) print("Yes");
  else print("No");
  return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  //
  string s, t;
  cin >> s >> t;

  int ans = -1;
  for (int i = 0; i < s.size() - t.size() + 1; ++i) {
    int cnt = 0;
    for (int j = 0; j < t.size(); ++j) {
      if (s[i + j] != t[j]) {
        cnt++;
      }
    }

    if (ans < 0 || ans > cnt) {
      ans = cnt;
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define assign(x,val) memset(x,val,sizeof(x))
#define motherfucker  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define for0(i,n) for(ll i=0;i<n;++i)
#define for1(i,n) for(ll i=1;i<=n;++i)
#define ford(i,n) for(ll i=n;i>=1;--i)
#define forg(i,a,b) for(ll i=a;i<b;++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpl;
long long mod = 1000000007;
const long double PI = (long double)(3.1415926535897932384626433832795);
 
 
void solve(){
	ll a, b, n;cin>>n>>a>>b;
	cout<<((b-a)%2==0?(b-a)/2:min(a-1, n -b) + 1 + (b-a)/2)<<endl;	
}
 
int main(){
	motherfucker
	ll t = 1;
	//cin>>t;
	for0(i, t){
		solve();
	}
	return 0;
}

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

int main(){
 int A,B,C,K,i=0,d=0;
 cin >> A;
 cin >> B;
 cin >> C;
 cin >> K;
 while(i<=K){
  if(C<=B){
   C*=2;
   i++;
  }else if(B<=A){
   B*=2;
   i++;
  }else{
   cout << "Yes" << endl;
   d++;
   break;
  }
 }
 if(d==0){
  cout << "No" << endl;
 }
 return 0;
}

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

using namespace std;
using ll=int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi=vector<int>;
using vii=vector<vi>;
using vl=vector<ll>;
using vll=vector<vl>;
using tpi=tuple<int, int, int>;

int main() {
    int N;
    cin >> N;
    for (int i = 0; i <= N; i++) {
        int tmp = static_cast<int>(i * 1.08);
        if (tmp == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();

		// 子をキーにして親を記録 → 木なので根以外は必ず単一の親を持つ
		HashMap<Integer, Integer> map = new HashMap<>();
		for ( int i = 1; i < n; i++ ) {
			int a = in.nextInt();
			int b = in.nextInt();
			map.put(b, a);
		}

		long[] cnt = new long[n + 1];
		for ( int i = 1; i <= q; i++ ) {
			int p = in.nextInt();
			int x = in.nextInt();
			cnt[p] += x;
		}

		System.out.println( cnt[1] );
		for ( int i = 2; i <= n; i++ ) {
			// 子に親から降りてきたカウントを加算して表示			
			System.out.println( cnt[i] += cnt[map.get(i)] );
		}
		in.close();
	}
}

Measured memory_bytes: 188136
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int N, K; cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    int first = 0, last = K;
    rep(i, N - K){
        if(last - first != K){
            cout << "No" << endl;
            continue;
        }
        if(A[first] >= A[last]) cout << "No" << endl;
        else cout << "Yes" << endl;
        first++;
        last++;
    }
} 

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


int main() {

    string s;
    cin >> s;
    set<char> S;
    for (int i = 0; i < s.size(); ++i) {
        S.insert(s[i]);
    }
    for (char w = 'a'; w <= 'z'; ++w) {
        if (S.count(w) == 0) {
            cout << w << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
from itertools import product

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

max_ans = M // N

ans = 1
tmp = 2
tmpM = M
max_prime = int(M ** 0.5)
all_list = []
i = -1
k = 0
div = 2
while tmpM != 1:
    if tmpM % div == 0:
        tmpM = tmpM // div
        if k == 0:
            i += 1
            all_list.append(set())
            all_list[i].add(div ** k)
            k += 1
        all_list[i].add(div ** k)
        k += 1

    else:
        k = 0
        if div == 2:
            div = 3
        elif div > max_prime:
            div = tmpM
        else:
            div += 2

if all_list == []:
    print(1)
    exit()

# print(all_list)
ans = 1

for div_tuple in product(*all_list):
    tmp = 1
    for k in div_tuple:
        tmp *= k
        if tmp > max_ans:
            break
    else:
        ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int table[101];

int main(void) {
  int target;

  int num = 0;
  int max = 0;
  while(scanf("%d", &target) != EOF) {
    table[target]++;
    num++;
    if(max < table[target]) {
      max = table[target];
    }
  }
  for(int i = 1; i < 101; i++) {
    if(table[i] == max) {
      printf("%d\n", i);
    }
  }
  return 0;
}
  

Measured memory_bytes: 1028
lines = []
colums = []

while True:
  H,W = map(int,input().split())
  if H == 0 and W == 0:
    break
  lines.append(H)
  colums.append(W)

for H,W in zip(lines,colums):
  for i in range(H):
    for j in range(W):
      print("#",end="")
    print("\n",end="")
  print("\n",end="")


Measured memory_bytes: 7020
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const int maxn=505,maxm=1e6+5;

int ans;
int sum[205];
int a[205];
int main()
{  int n,l;
int minn=inf;
int sum1=0;
cin>>n>>l;
for(int i=1;i<=n;i++)
{
    a[i]=l+i-1;

    sum1+=a[i];

}
for(int i=1;i<=n;i++)
{
    sum[i]=sum1-a[i];
}
for(int i=1;i<=n;i++)
{
    if(abs(sum[i]-sum1)<=minn)
    {
        ans=sum[i];
        minn=abs(sum[i]-sum1);
    }
}
cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int,int> P;

int main(){
  int n,r,t;
  P p[7][5];
  vector<int> ans;
  for(int i=0;i<7;i++)
    for(int j=0;j<5;j++) p[i][j]=P(i*30,100*(j+1));
  cin>>n;
  while(n--){
    cin>>r>>t;
    int left,right;
    if(r%100==0)
      left=right=r/100-1;
    else
      for(int i=0;i<4;i++)
	if(p[0][i].second<r&&r<p[0][i+1].second) left=i,right=i+1;
    int up,down;
    if(t%30==0)
      up=down=t/30;
    else
      for(int i=0;i<6;i++)
	if(p[i][0].first<t&&t<p[i+1][0].first) up=i,down=i+1;
    for(int i=0;i<7;i++)
      for(int j=0;j<5;j++)
	if(up<=i&&i<=down&&left<=j&&j<=right) ans.push_back(i*5+j+1);
    for(int i=0;i<ans.size();i++){
      if(i) cout<<' ';
      cout<<ans[i];
    }
    cout<<endl;
    ans.clear();
  }
  return 0;
}

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

typedef long long int ll;
typedef double d;

#define tt int t; cin>>t; while(t--)
#define lo(i, a, b) for(int i=a; i<b; i++)
#define rlo(i, a) for(int i=a; i>0; i--)

#define be(a) a.begin(),a.end()
#define sz(x) x.size()

#define nl cout<<"\n";
#define sp cout<<" ";

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main()
{
    su;
    int a,b,c,k,s=0;
    cin>>a>>b>>c>>k;
    if(a>=k)
        s=k;
    else
    {
        s+=a;
        k-=a;
        if(b<k)
        {
            k-=b;
            if(c>=k)
            {
                s-=k;
            }
            else
            {
                s-=c;
            }
        }
    }
    cout<<s;
    nl;
    return 0;
}


Measured memory_bytes: 3648
import numpy as np
import statistics
n = int(input())
x,y = [],[]
for i in range(n):
  a,b = map(int,input().split())
  x.append([a,b])
x = sorted(x, key=lambda x:(x[0],x[1]), reverse=False)
for i in range(0,n-1):
  for j in range(i+1,n):
    y.append(list(-np.array(x[i])+np.array(x[j])))
z = [y.count(i) for i in y]
if n == 1:
  print(1)
else:
  print(-max(z)+n)

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

typedef pair<ll, ll> pll;

const int M = 100100;

int n;
pll a[M];

void read() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
  }
}

ll check(int k) {
  if (2 * k - 1 > n)
    return -1;
  if (a[n - k].first < 0)
    return -1;

  vector<ll> rs;
  for (int i = 0; i < n - k; ++i)
    rs.push_back(a[i].second);
  sort(all(rs));

  bool ok = true;
  ok &= k == 1 || rs[k - 2] <= a[n - k].first;
  if (!ok)
    return -1;

  ll ans = 0;
  for (int i = 0; i < k - 1; ++i)
    ans -= 2 * rs[i];
  for (int i = 0; i < k; ++i)
    ans += 2 * a[n - i - 1].first;
  return ans;
}

ll solve() {
  ll ans = 0;
  sort(a, a + n);

  {
    vector<ll> rs;
    vector<ll> ls;
    for (int i = 0; i < n; ++i) {
      if (a[i].first >= 0)
        ls.push_back(a[i].first);
      if (a[i].second <= 0)
        rs.push_back(a[i].second);
    }

    int t = min(rs.size(), ls.size());
    sort(all(ls));
    reverse(all(ls));
    sort(all(rs));

    for (int i = 0; i < t; ++i)
      ans += 2 * (ls[i] - rs[i]);
  }

  int l = 1, r = n;
  while (l < r) {
    int m = (l + r) / 2;
    if (check(m + 1) >= 0)
      l = m + 1;
    else
      r = m;
  }

  ans = max(ans, check(l));
  return ans;
}

void kill() {
  ll ans = 0;
  ans = solve();
  for (int i = 0; i < n; ++i) {
    a[i] = make_pair(-a[i].second, -a[i].first);
  }
  ans = max(ans, solve());
  cout << ans << endl;
}

int main() {
#ifdef LOCAL
  assert(freopen("c.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();
}



Measured memory_bytes: 3684
import java.util.*;

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

    int N = in.nextInt();
    long K = in.nextLong();

    int[] numbers = new int[N];

    for (int i = 0; i < N; i++) {
      numbers[i] = in.nextInt() - 1;
    }

    HashMap<Long, int[]> map = new HashMap<>();

    long index = 1L;
    map.put(index, numbers);
    index *= 2L;

    while (index < K) {
      int[] newNumbers = new int[N];
      long preIndex = index / 2;

      for (int i = 0; i < N; i++) {
        int preLoc = map.get(preIndex)[i];
        int curLoc = map.get(preIndex)[preLoc];
        newNumbers[i] = curLoc;
      }

      map.put(index, newNumbers);
      index *= 2;
    }

    int ans = 0;
    index /= 2;

    while (index > 0) {
      if (K >= index) {
        ans = map.get(index)[ans];
        K -= index;
      }
      index /= 2;
    }

    System.out.println(ans + 1);
  }
}

Measured memory_bytes: 119140
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};

/*
string f(int n){
  if (n == 0) return "P";
  else return "B" + f(n - 1) + "P" + f(n - 1) + "B";
}
*/

//レベルiバーガーの厚さ
ll a(int i){
  if (i == 0) return 1;
  else return 2 * a(i - 1) + 3;
}

//レベルiバーガーに含まれるパティの総数
ll p(int i){
  if (i == 0) return 1;
  else return 2 * p(i - 1) + 1;
}

//レベルNバーガーの下からX層に含まれるパティの枚数
ll f(int N, ll X){
  if (N == 0) return 1;
  else if (X == 1) return 0;
  else if (X <= 1 + a(N - 1)) return f(N - 1, X - 1);
  else if (X == 2 + a(N - 1)) return p(N - 1) + 1;
  else if (X <= 2 + 2 * a(N - 1)){
    return p(N - 1) + 1 + f(N - 1, X - 2 - a(N - 1));
  }else return 2 * p(N - 1) + 1;
}

int main(void){
  ll N, X;
  cin >> N >> X;
  cout << f(N, X) << endl;
  return 0;
}


Measured memory_bytes: 3600
a = [ list(map(int,input().split())) for i in range(3)] 
n = int(input())
d = [[0 for i in range(3)] for j in range(3)]

for k in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                d[i][j] = 1

ans = 'No'
for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[i][j]
        if count == 3:
            ans = 'Yes'
            break;

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count = 0
    for j in range(3):
        count += d[j][i]
    if count == 3:
        ans = 'Yes'
        break;

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][i]
    if count == 3:
        ans = 'Yes'

count = 0
for i in range(3):
    if ans == 'Yes':
        break;
    count += d[i][2 - i]
    if count == 3:
        ans = 'Yes'
            

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;
//二叉搜索树的搜索

struct Node {
    int key;
    Node *p, *l, *r;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node*)malloc(sizeof(Node));
    z->key = k;
    z->l = NIL;
    z->r = NIL;

    while (x != NIL)  {
        y = x;
        if (x->key > z->key) {
            x = x->l;
        } else if (x->key < z->key) {
            x = x->r;
        }
    }
    
    z->p = y;
    if (y== NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->l = z;
        } else if (z->key > y->key) {
            y->r = z;
        }
    }
}

void Inorder(Node *u) {
    if (u == NIL) return;
    
    Inorder(u->l);
    cout << " " << u->key;
    Inorder(u->r);
}

void preorder(Node *u) {
    if (u == NIL) return;
    
    cout << " " << u->key;
    preorder(u->l);
    preorder(u->r);
}

Node* find(Node *u, int k) {
    while ( u != NIL && k != u->key) {
        if (k < u->key) u = u->l;
        else if (k > u->key) u = u->r;
    }
    return u;
}

int main() {
    int n, k;
    cin >> n;
    
    string com;
    for (int i = 0; i < n; i++) {
        cin >> com;
        if (com == "insert"){
            cin >> k;
            insert(k);
        } else if (com == "find") {
            cin >> k;
            if (find(root, k) == NIL) {
                cout << "no" << "\n";
            } else {
                cout << "yes" << "\n";
            }
        } else if (com == "print") {
            Inorder(root);
            cout << "\n";
            preorder(root);
            cout << "\n";
        }
    }
    
    return 0;
}



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

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  int res;
  int quo = n / x;
  int rem = n % x;
  if (rem != 0) quo++;
  res = quo * t;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>
#include <algorithm>

using namespace std;

const int INF = 1e6;

int main(){
    int n;  cin >> n;
    double ans=0;
    for (int i=0; i<n; i++){
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY"){
            ans += x;
        }
        else {
            ans += 380000*x;
        }
    }

    cout << ans << endl;
}


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

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

	for (int i = a;i <= b;i++)
	{
		if (c % i == 0)
		{
			count++;
		}
	}

	cout << count<<'\n';

	return 0;
}


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

using namespace std;

int main() {
  
  string s;
  cin>>s;
  
  string yes = "Yes";
  string no = "No";
  
  char c1 = s[0];
  int ind1 = -1;
  int ind2 = -1;
  bool first = false;
  bool second = false;
  for(int i = 1; i < 4; i++) {
    if(c1 == s[i]) {
      first = true;
      ind1 = i;
      break;
    }
  }
  
  if(!first) {
    cout<<no<<endl;
    return 0;
  }
  
  for(int i = 1; i < 4; i++) {
    if(i == ind1) {
      continue;
    }
    if(c1 == s[i]) {
      cout<<no<<endl;
      return 0;
    }
    c1 = s[i];
    ind2 = i;
    break;
  }
  
  for(int i = 2; i < 4; i++) {
    if(i == ind1 || i == ind2) {
      continue;
    }
    if(c1 == s[i]) {
      second = true;
      break;
    }
  }
  
  if(!second) {
    cout<<no<<endl;
    return 0;
  }
  
  cout<<yes<<endl;
  return 0;
}

Measured memory_bytes: 256