akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov

int main(){
    string s;
    cin >> s;
    string t;
    cin >> t;
    rep(i,s.size()){
        if(s[i]!=t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    if(s.size()+1==t.size()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
a,b,c = invr()
tempa = a
tempc = c
tempb = b
a = tempc
b = tempa
c = tempb
print(a,b,c)
#print()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		n++;
		vector<int> t(n), v(n);
		t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}
		cout << *max_element(t.begin()+1, t.end()) << endl;
	}
	return 0; 
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll MOD2=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    ll A,B,N;
    cin>>A>>B>>N;
    ll x=0;
    if(N<B){
        x=N;
    }else{
        x=B-1;
    }
    ll ans=1ll*floor(A*x/B)-A*floor(x/B);
    cout<<ans<<endl;
}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


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

#include <iostream>
using namespace std;

int main() {

	int n;
	int x;
	int c=0;


	while(1){
		c=0;
		cin>>n>>x;
		if( n==0&&x==0)break;
		for(int i=1; i<n+1; i++){
			for(int j=1+i; j<n+1; j++){
				for(int k=j+1; k<n+1; k++){
					if((i+j+k)==x)c++;
				}
			}
		}
		cout<<c<<endl;
	}
}

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

int main()
{
	long long n, k, m = 0;

	cin >> n >> k;
	
	if (k % 2 == 0) {
		k /= 2;
		if ((n / k) % 2 == 0)
			m = (n / k / 2) * (n / k / 2) * (n / k / 2) * 2;
		else
			m = (n / k / 2) * (n / k / 2) * (n / k / 2) +
				(n / k / 2 + 1) * (n / k / 2 + 1) * (n / k / 2 + 1);
	}
	else
		m = (n / k) * (n / k) * (n / k);

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
# 2020/07/05
# AtCoder Beginner Contest 173 - D

# Input
n = int(input())
a = list(map(int,input().split()))

# Calc
a.sort()
a.reverse()

ans = a[0]
idx = 1
for i in range(2, n):
    ans = ans + a[idx]
    if i % 2 != 0:
        idx = idx + 1
        
# Output
print(ans)


Measured memory_bytes: 31516
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <cstring>

// ---------- PBDS -----------------

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
// slow but fast ORZ :)
// ----------------------------------

using namespace std;
using namespace __gnu_pbds; 

#define MEM(a, b) memset(a, (b), sizeof(a))
#define ALL(a) a.begin(), a.end()
#define MP(a, b) make_pair(a, b)
#define PB(a) push_back(a)
#define EB(a) emplace_back(a) // care when use
#define boost ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0),cout << fixed << setprecision(10);
// #define ll long long int
#define int long long int

#define DEBUG

#ifdef DEBUG

    #define debug(args...)(Debugger()) , args

    class Debugger{
        public:
        Debugger(const std::string& _separator = " | ") :
        first(true), separator(_separator){}

        template<typename ObjectType> Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std::cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std::cerr << std::endl;}

        private:
        
        bool first;
        std::string separator;
    };

#else
    #define debug(args...)
#endif

void solve(){

	int N;
	cin >> N;

	std::vector<int> v(N+1);

	int ans = 0;
	for(int x = 1; x*x < N; ++x){
		for(int y = 1; y*y < N; ++y){
			for(int z = 1; z*z < N; ++z){
				int temp = x*x + y*y + z*z + x*y + x*z + y*z;

				if(temp <= N){
					v[temp]++;
				}

			}
		}
	}

	for(int i = 1; i <= N; ++i){
		cout << v[i] << "\n";
	}

}


int32_t main(){

	boost;
	
	int T;

	// cin >> T;
	T = 1;
	
	while(T--){
		solve();
	}
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define MAX 100
using namespace std;

int arr[MAX+1]; 

int main(){
	int n,cnt=0;
	cin>>n;
	
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	
	for(int i=1;i<=n;i++){
		if((i&1) && (arr[i]&1)){
			cnt++;
		}
	}
	cout<<cnt<<"\n";
	return 0;
}

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

int main(){
    int h,w;
    cin>>h>>w;
    char arr[h][w];
    long long dp[h][w];
    dp[0][0]=1;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>arr[i][j];
            if(arr[i][j]=='#')
            {
                dp[i][j]=0;
            }
        }
    }
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(arr[i][j]!='#')
            {
                if(i>0)
                {
                    if(j>0)
                    {
                        dp[i][j]=(dp[i-1][j]+dp[i][j-1])%(1000000007);
                    }
                    else{
                        dp[i][j]=dp[i-1][j];
                    }
                }
                else{
                    if(j>0)
                    {
                        dp[i][j]=dp[i][j-1];
                }
            }
        }
    }}
    cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 9088
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>

using namespace std;
using LLI = long long int;

int main(void) {
	int N, K, a,res = 0;
	vector<pair<int, int>>vec;
	map<int, int>M;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> a;
		M[a]++;
	}
	for (auto i : M) {
		vec.push_back(make_pair(i.second,i.first));
	}
	sort(vec.begin(), vec.end());
	int b = M.size();
	for (int i = 0; i < b - K;i++) {
		res += vec[i].first;
	}
	cout << res << endl;
}

Measured memory_bytes: 11768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using vi = vector<int>;

int main(){
    int h,w;
    cin >>h >>w;
    vector<string> s(h);
    rep(i,h) cin >>s[i];

    vector<vi> O(h, vi(w+1)), I(w, vi(h+1));
    rep(i,h){
        for(int j=w-1; j>=0; --j){
            O[i][j] = O[i][j+1];
            if(s[i][j] == 'O') ++O[i][j];
        }
    }

    rep(i,w){
        for(int j=h-1; j>=0; --j){
            I[i][j] = I[i][j+1];
            if(s[j][i]=='I') ++I[i][j];
        }
    }

    ll ans = 0;
    rep(i,h)rep(j,w)if(s[i][j] == 'J') ans += O[i][j+1]*I[j][i+1];
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 94308
use std::io::stdin;

macro_rules! read {
    ($t: ty) => {{
        let mut line = String::new();
        stdin().read_line(&mut line);
        line.trim().parse::<$t>().unwrap()
    }};
    ($($t: ty), *) => {{
        let mut line = String::new();
        stdin().read_line(&mut line);
        let mut iter = line.split_whitespace();
        (
            $(iter.next().unwrap().parse::<$t>().unwrap(), )*
        )
    }}
}
macro_rules! reads {
    ($e:expr, $t:ty) => {{
        let mut v = vec![];
        for _ in 0..$e {
            let mut line = String::new();
            stdin().read_line(&mut line);
            v.push(line.trim().parse::<$t>().unwrap());
        }
        v
    }};
}

fn main() {
    let (a, b) = read!(u32, u32);
    if b % a == 0 {
        println!("{}", b + a);
    } else {
        println!("{}", b - a);
    }
}


Measured memory_bytes: 4352
import numpy as np

n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = []
g = []
for _ in range(n):
    g.append([])
for _ in range(m):
    a, b = map(int, input().split())
    ab.append([a, b])
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
ans = 0
for i in range(n):
    check = True
    for j in g[i]:
        if h[j] >= h[i]:
            check = False
    if check:
        ans += 1

print(ans)


Measured memory_bytes: 63404
#include <stdio.h>
int main(void)
{

  int n;
  int m;

  scanf("%d", &n);

  m = n % 10;

  if (m == 0) printf("pon\n");
  if (m == 1) printf("pon\n");
  if (m == 6) printf("pon\n");
  if (m == 8) printf("pon\n");
  if (m == 2) printf("hon\n");
  if (m == 4) printf("hon\n");
  if (m == 5) printf("hon\n");
  if (m == 7) printf("hon\n");
  if (m == 9) printf("hon\n");
  if (m == 3) printf("bon\n");


  return 0;

}


Measured memory_bytes: 1616
n=int(input())
A=list(map(int,input().split()))

#n=3
#A=[101,9901,999999000001]
cum=1
p=A.count(0)
#print(p)
if p>0:
  cum=0

for i in range(n):
  cum=cum*A[i]
  if cum>10**18:
    cum=-1
    break

print(cum)




Measured memory_bytes: 21568
def main():
    s = input()
    n = len(s)
    ans = float("inf")
    for i in range(n-2):
        if ans > abs(753 - int(s[i:i+3])):
            ans = abs(753 - int(s[i:i+3]))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n; 
vector<vector<int>> g;

void solve() {
	cin >> n;
    int ans = 0;
    rep(i, n) {
        ans += (i + 1) * (n - i);
    }
    rep(i, n - 1) {
        int u, v; cin >> u >> v;
        -- u, -- v;
        if(u > v) swap(u, v);
        ans -= (u + 1) * (n - v);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
 
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(int i=n;i<=N;++i)
#define asd(i,n,N) for(int i=n;i< N;++i)
#define rap(i,n,N) for(int i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>> " << #x << " -> " << x << endl
#define mems(x,y) memset(x,y,sizeof x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define plll pair<pll,ll>
#define piii pair<pii,int>
#define piiii pair<pii,pii>
#define psi pair<string,int>
#define endl '\n'
const int MAX = 1e6+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll MOD2 = 1000005329;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 555;

ll n,k,le,ri,mid,ans,x[MAX],hit;

int main(){
//	cout<<fixed<<setprecision(10);
//	freopen("input.txt", "r", stdin);
//	freopen("astar.out","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>k;
    rep(i,1,n)cin>>x[i];
    le = 1, ri = MOD;
    while(le<=ri){
    	mid = le+ri>>1;
    	hit = 0;
    	rep(i,1,n)hit+= (x[i]-1)/mid;
    	if(hit<=k)ans = mid, ri = mid-1;
    	else le = mid+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5168
/* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 


// Driver code to test above functions
int32_t main()
{
    
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    
    int n;
    cin >> n;
    set<string> s;
    for(int i=0;i<n;i++)
    {
        string x;
        cin >> x;
        s.insert(x);
    }

    cout << s.size();

    return 0;
}  //4 5


Measured memory_bytes: 19240
S = input()
Q = int(input())

front = ''
back = S
reverse = False

for i in range(Q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    if query[0] == '2':
        if query[1] == '1':
            if not reverse:
                front = front + query[2]
            else:
                back = back + query[2]
        if query[1] == '2':
            if not reverse:
                back = back + query[2]
            else:
                front = front + query[2]

if not reverse:
    print(front[::-1] + back)
else:
    print(back[::-1] + front)


Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;
const int INF = 1001001001;

int ps(int n){
  if(n>0)return n;
  else return 0;
}

int main(){
  int h,n;
  cin >> h >> n;
  int a[n],b[n];
  rep(i,n)cin >> a[i] >> b[i];
  int dp[10005];
  rep(i,h)dp[i+1]=INF;
  dp[0]=0;
  rep(i,h){
    rep(j,n){
      chmin(dp[i+1],dp[ps(i+1-a[j])]+b[j]);
    }
  }
  //rep(i,h)cout << dp[i+1] << endl;
  cout << dp[h] << endl;
}


Measured memory_bytes: 256
S=int(input())
MOD=1000000007
dp=[0]*2001
dp[3]=1
dp[4]=1
dp[5]=1
for i in range(6,S+1):
    tmp=1
    for j in range(3,i-2):
        tmp+=dp[j]
        tmp%=MOD
    dp[i]=tmp
print( dp[S])


Measured memory_bytes: 9168
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, Q; cin >> N >> Q;
    vpl evt;
    rep(i, N){
        ll s, t, x; cin >> s >> t >> x;
        evt.pb({s-x, x});
        evt.pb({t-x, -x});
    }
    rep(i, Q){
        ll d; cin >> d;
        evt.pb({d, LINF});
    }
    sort(evt.begin(), evt.end());
    
    multiset<ll> s; vl ans(Q); ll idx = 0;
    for(auto p : evt){
        if(p.ss == LINF){
            ans[idx] = s.empty() ? -1 : *s.begin();
            idx++;
        }
        else if(p.ss > 0) s.insert(abs(p.ss));
        else s.erase(s.lower_bound(abs(p.ss)));
        
    }
    
    rep(i, Q) cout << ans[i] << endstr;
    return 0;
}


Measured memory_bytes: 22244
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
n,q=[int(_) for _ in input().split()]
ki=[[] for _ in range(n)]
ans=[0]*n

def dfs(numQ,parent):
    for child in ki[numQ]:
        if child==parent:
            continue
        ans[child]+=ans[numQ]
        dfs(child,numQ)

for i in range(n-1):
    a,b=[int(_) for _ in input().split()]
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)

for i in range(q):
    p,x=[int(_) for _ in input().split()]
    ans[p-1]+=x

dfs(0,-1)
print(*ans)

Measured memory_bytes: 230932
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
using ll = long long;


int main() {
    ll n; cin >> n;
    if (n%2  == 1) {
        cout << 0 << endl;
        return 0;
    }
    ll a=0, b=0;
    ll tmp = 2;
    while (tmp <= n) {
        a += n/tmp;
        tmp *= 2;
    }
    tmp = 5;
    while (tmp <= n) {
        b += n/tmp/2;
        tmp *= 5;
    }
    // cout << a << ' ' << b << endl;
    cout << min(a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int A, B, C;
	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);

	if (A == 5 && B == 5 && C == 7) {
		printf("YES\n");
	}
	else if (A == 5 && B == 7 && C == 5) {
		printf("YES\n");
	}
	else if (A == 7 && B == 5 && C == 5) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
k, a, b = gets.chomp.split.map(&:to_i)
bis = 1
if a + 2 >= b
  puts k + bis
else
  loop do
    if k <= 0
      break
    end

    if bis >= a && k > 1
      cnt = [k / 2, bis / a].min
      bis += (b - a) * cnt
      k -= 2 * cnt
    elsif k == 1
      bis += 1
      k -= 1
    else
      cnt = [k, [0, a - bis].max].min
      bis += cnt
      k -= cnt
    end
  end
  puts bis
end

Measured memory_bytes: 14388
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = sc.nextInt();
		
		int sum = 0;
		int day = 0;
		
		do {
			day++;
			sum += a;
			sum += day % 7 == 0 ? b : 0 ;
		} while(sum < x);
		
		System.out.println(day);
		
	}
}



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

int main() {
	int n[4][14] = { 0 };
	int x, num;
	string s;

	cin >> x;

	for (int i = 0; i < x; i++) {
		cin >> s >> num;
		if (s == "S") {
			n[0][num] = 1;
		}
		else if (s == "H") {
			n[1][num] = 1;
		}
		else if (s == "C") {
			n[2][num] = 1;
		}
		else if (s == "D") {
			n[3][num] = 1;
		}
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 1; j < 14; j++) {
			if (n[i][j] == 0 && i == 0)		 cout << "S " << j << endl;
			else if (n[i][j] == 0 && i == 1) cout << "H " << j << endl;
			else if (n[i][j] == 0 && i == 2) cout << "C " << j << endl;
			else if (n[i][j] == 0 && i == 3) cout << "D " << j << endl;
		}
	}
	
	return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int k,x;cin>>k>>x;

  set<int> st;
  for(int i=0;i<k;i++){
    if ((x-i) >= -1000000)st.insert(x-i);
    if ((x-i) <= 1000000)st.insert(x+i);
  }
  int i=0;
  for(auto t : st) {
    if(i++)cout<<' ';
    cout<<t;
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define INF 1000000000000000000
#define ll int //long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    string s;
    cin >> s;
    ll ans = 0, tmp = 0;
    rep(i, s.size()){
        if(i%2 == 0 && s[i] == '1') tmp++;
        if(i%2 == 1 && s[i] == '0') tmp++;
    }
    ans = tmp; tmp = 0;
    rep(i, s.size()){
        if(i%2 == 1 && s[i] == '1') tmp++;
        if(i%2 == 0 && s[i] == '0') tmp++;
    } //cout << tmp;
    cout << min(ans, tmp);
}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


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

using namespace std;

struct interval

{
    string start;
int end;
   
 
};

bool compare(interval x,interval y)

{
    if(x.end==y.end)
    {

      return x.start<y.start;
}
 return x.end>y.end;
  }

int main() 

{
  long long int x,y;
  cin>>x>>y;
  if(y>(4*x)||(y<(2*x)))
  {
      cout<<"No"<<endl;
      
  }
  else
  {
      for(int i=0;i<=x;i++)
     {
         long long int z=x-i;
         long long int s=2*i+4*z;
         if(s==y)
         {
             cout<<"Yes"<<endl;
             return 0;
         }
     }
     cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<utility>
#include<queue>

/*
template<class T,std::size_t N>
class queue {
	constexpr static const auto array_size = N + 5;
	T tab[array_size];//array size has to be larger than the number of elements.
	decltype(N) head, tail;
public:
	queue() :tab{}, head{ 0 }, tail{0} {}

	auto empty()const { 
		return this->head == this->tail; 
		//return this->size() == 0;
	}

	auto size()const {
//		std::cout << "h,t " << head << ", " << tail<<"\n";
		return tail <= head ?
			head - tail : array_size - tail + head;
	}

	auto full()const { return N == this->size(); }


	template<class X>
	auto& push(X&&x){
		tab[head] = std::forward<X>(x);
		head = (head+1)%(array_size);
//		std::cout << "push:" << x << "\n";
//		std::cout <<"h,t = "<< this->head << "," << this->tail << "\n";
		return *this;
	}

	auto pop() {
		auto x = tab[tail];
		tail = (tail+1)%array_size;
//		std::cout << "pop:" << x << "\n";
		return x;
	}

	//template<class F>
	auto print() {
				
		if (head <= tail) {
			if (this->empty()) {
				std::cout << "empty !\n";
				return;
			}
			for (std::size_t i{ tail }; i < array_size ; i++) {
				std::cout << tab[i];
				std::cout << (i%10==0?"\n":" ");
			}
			auto x = (N - 1 - tail) % 10;
			for (std::size_t i{ 0 }; i < head; i++) {
				std::cout << tab[i];
				x += i; x %= 10;
				std::cout << (x % 10 == 0&&i!=0 ? "\n" : " ");
			}
			if (x % 10 != 0)std::cout << "\n";
		}
		else {
			std::size_t i{ tail };
			for (; i < head; i++) {
				std::cout << tab[i];
				std::cout << (i%10==0&&i!=0?"\n":" ");
			}
			if (i % 10 != 0)std::cout << "\n";
		}
	}


};
*/
constexpr static const auto size{ 100000 };

struct element {
	std::string name;
	int resource;
	//	bool finished =false;
	int lap;
	element() :element{"",0} {}
	element(const std::string& s, int r) :name{ s }, resource{ r },lap{} {}
	friend std::ostream& operator<<(std::ostream& os, const element& e) {
		return os << e.name << " " << e.resource;
	}
	auto result() {
		std::cout << name << " " << lap;
	} 
};
/*
auto test() {

	queue<int, 5> Q;
	for (int i{1}; i <= 5; i++) {
		Q.push(i);
	}

	Q.print();//1,2,3,4,5
//	std::cout << Q.size() << "\n";

	int accum{};
	while (!Q.empty()) {
		auto x = Q.pop();
	//	std::cout << x << "\n";

		if (x  > 1) {
			Q.push(x-1);
			std::cout << "size : " << Q.size();
			std::cout << ", x : " << x << ", all : ";
			Q.print();
		}

		++accum;
	}
	std::cout <<accum<<"\n";

}
*/
int main() {

	int N{}, cost{};
	std::cin >> N >> cost;

	std::queue<element> que;
	for (int i{}; i < N; i++) {
		std::string name{};
		int time{};
		std::cin >> name >> time;
		que.push(element{name,time});
	}

	unsigned long long acc{};
	while (!que.empty()) {

		auto x = que.front(); que.pop();
		if (x.resource <= cost) {
			acc += x.resource;
			x.resource = 0;
			std::cout << x.name << " " << acc << "\n";
		}
		else {
			x.resource -= cost;
			acc += cost;
			que.push(x);
		}
	}


	return 0;

}


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

using namespace std;

int main() {

	int n;
	cin >> n;

	int counter = 0;
	string str = "";
	for (int i = 1; i <= n; i++) {
		str = to_string(i);
		if (str.size() % 2 == 1) { counter++; }
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int h;
	int height[] = {0, 0, 0};

    while(scanf("%d",&h) != EOF){
		if(height[0] < h){
			height[2] = height[1];
			height[1] = height[0];
			height[0] = h;
		}else if(height[1] < h){
			height[2] = height[1];
			height[1] = h;
		}else if(height[2] < h){
			height[2] = h;
		}
	}

	printf("%d\n", height[0]);
	printf("%d\n", height[1]);
	printf("%d\n", height[2]);

	return 0;
}

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

int main(void){
    int a, b;
    cin >> a >> b;
    if(a == 1)
        a += 100;
    if(b == 1)
        b += 100;

    if(a > b)
        cout << "Alice" << endl;
    if(a == b)
        cout << "Draw" << endl;
    if(a < b)
        cout << "Bob" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p = sc.nextInt();
        int[] biscuits = new int[n];
        boolean isOdd = false;
        for(int i = 0; i < n; i++){
            biscuits[i] = sc.nextInt();
            if(biscuits[i] % 2 != 0){
                isOdd = true;
            }
        }
        if(isOdd){
            System.out.println((long)Math.pow(2,n-1));
        }else{
            System.out.println(p == 0 ? (long)Math.pow(2,n) : 0);
        }
        
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll d,l,r;
		cin>>l>>r>>d;
		cout<<(r)/d	-(l-1)/d<<endl;
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
	//	cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}


Measured memory_bytes: 3604
K = int(input())

def gcd(a, b):
    if a < b:
        a, b = b, a
    if a%b == 0:
        return b
    return gcd(b, a%b)

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        n = gcd(a, b)
        for c in range(1, K+1):
            ans += gcd(n, c)

print(ans)

Measured memory_bytes: 72084
#include <stdio.h>

int main(void)
{
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  if(A*B == C*D)
    printf("%d",A*B);
  else if(A*B > C*D)
    printf("%d",A*B);
  else
    printf("%d",C*D);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MOD = 1e9+7;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//C++17以上
template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main() {
    int a,b,c;cin >> a >> b >> c;
    cout << (c-(a-b)<=0?0:c-(a-b)) << endl;
    return 0;
}

Measured memory_bytes: 256
def searchDivisors(n):
    lstDivisors = []
    t = int(n ** .5)
    for a in range(1, t + 1):
        if n % a == 0:
            lstDivisors.append(a)
            b = n // a
            if b != a:
                lstDivisors.append(b)
    lstDivisors.sort()

    return lstDivisors


N = int(input())
ans = 0
lstDivisors = searchDivisors(N)


for k in lstDivisors:
    m = N // k - 1
    if k == m:
        continue
    if k > m:
        break
    ans += m


print(ans)

Measured memory_bytes: 3264
s = Hash.new
nums = Array.new
while (line = gets) != "\n" do
  num,=line.split(",").map(&:to_i)
  s[num]||=0
  s[num]+=1
end
while line = gets do
  num,=line.split(",").map(&:to_i)
  next unless s[num]
  nums << num
  s[num]+=1
end
nums.sort!
nums.each{|n|
  puts n.to_s+" "+s[n].to_s
}

Measured memory_bytes: 2384
/* 161-A.cpp
 *     Created on : Apr 4, 2020
 *     Time		  : 6:00:08 PM
 *     Author     : null_ptr
 */

#include<bits/stdc++.h>

using namespace std;

#define F_Input freopen("input.in","r",stdin)
#define push emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)

template<typename T>
void Swap(T &a,T &b){
a^=b;b^=a;a^=b;}

template<class type>
void show(type name)
{for(auto& nm:name)cerr<<nm<<' ';cerr<<'\n';}

using lint=long long;
using ivec=vector<int>;
using ipair=pair<int,int>;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int x,y,z;
	cin>>x>>y>>z;
	Swap(x,y);
	Swap(x,z);
	cout<<x<<' '<<y<<' '<<z<<'\n';
}





Measured memory_bytes: 256
from collections import Counter


def solve(n, m, sx, p):
    ans = 0
    temp_c_list = []
    for i in range(1 << (n)):
        for si in sx:
            sum_si = sum(si)
            c = Counter(bin(i & sum_si)[2:])['1']
            temp_c_list.append(c % 2)
        if px == temp_c_list:
            ans += 1
        temp_c_list = []

    return ans


if __name__ == '__main__':
    n, m = map(int, input().split())
    sx = [[0]*n for _ in range(m)]

    for i in range(m):
        tx = list(map(int, input().split()))[1:]
        for ti in tx:
            sx[i][n-ti] = 1 << ti-1

    px = list(map(int, input().split()))

    print(solve(n, m, sx, px))


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

int main()
{
	std::string s;
	while( std::cin >> s )
	{
		bool f = false;
		for( int i = 0; i != 3; ++i )
		{
			if( s[i*3] != 's' && s[i*3] == s[i*3+1] && s[i*3+1] == s[i*3+2] )
				std::cout << s[i*3] << std::endl, f = true;
			else if( s[i] != 's' && s[i] == s[i+3] && s[i+3] == s[i+6] )
				std::cout << s[i] << std::endl, f = true;
		}

		if( s[4] != 's' )
			if( ( s[0] == s[4] && s[4] == s[8] ) || ( s[2] == s[4] && s[4] == s[6] ) )
				std::cout << s[4] << std::endl, f = true;

		if( !f )
			std::cout << "d" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1176
a = []

for s in ['S', 'H', 'C', 'D']:
  for n in range(1, 14):
    a.append(f'{s} {n}')

cards = []
n = int(input())

for i in range(n):
  cards.append(input().strip())

res = set(a) ^ set(cards)

for s in ['S', 'H', 'C', 'D']:
  tmp = filter(lambda x:x[0] == s, res)
  for card in sorted(tmp, key=lambda x:int(x.split()[1])):
    print(card)


Measured memory_bytes: 5612
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,p,q;
ll L,M,R,l,r,x,y,tl,tr,m;
vector<pair<ll,ll> > v[2],tmp;
vector<pair<ll,ll> >::iterator bg,ed;
int sgn(ll x){
	return x<0?-1:x>0;
}
bool stand(){
	if(tl > M) return false;
	if(tr > M) tr = M;
	return true;
}
bool gao(){
	tmp.clear();
	for(bg = v[p].begin(),ed=v[p].end();bg!=ed;bg++){
		l = bg->first, r = bg->second;
		tl = l - y;
		tr = r - x;
		if(sgn(tl)*sgn(tr) == -1){
			tr = max(abs(tl),abs(tr));
			tl = 0;
		}
		else{
			tl = abs(tl);
			tr = abs(tr);
			if(tl > tr) swap(tl,tr);
		}
		if(stand()) tmp.push_back(make_pair(tl,tr));
		tl = l + x;
		tr = r + y;
		if(stand()) tmp.push_back(make_pair(tl,tr));
	}
	sort(tmp.begin(),tmp.end());
	tl=tr=-1;
	v[q].clear();
	for(bg=tmp.begin(),ed=tmp.end();bg!=ed;bg++){
		l = bg->first;
		r = bg->second;
		if(l > tr){
			if(tl >= 0) v[q].push_back(make_pair(tl,tr));
			tl = l;
			tr = r;
		}
		else{
			if(r > tr) tr = r;
		}
	}
	if(tl >= 0) v[q].push_back(make_pair(tl,tr));
	p = 1-p;
	q = 1-q;
	return v[p].size() > 0;
}
int main() {
	//freopen("in.txt", "r", stdin);
	while(~scanf("%d%lld%lld%lld",&n,&L,&M,&R)){
		M*=2;
		R*=2;
		v[0].clear();
		v[1].clear();
		p=0,q=1;
		v[0].push_back(make_pair(0,0));
		bool ans = true;
		while(n--){
			scanf("%lld",&m);
			x = R*m;
			y = L*m;
			if(ans) ans = gao();
		}
		puts(ans?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <complex>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i, n) for(int i=0;i<(int)n;i++)
#define REPS(i, n) for(int i=1;i<=(int)n;i++)
#define RREP(i, n) for(int i=n-1;i>=0;i--)
#define RREPS(i, n) for(int i=n;i>0;i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define pb push_back
#define eb emplace_back
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int n, m, q;

int check(const vector<vi> &req, const vector<vi> &rest, vi ave, int debug = 0){
	vi target;
	REP(i, n) if(accumulate(ALL(rest[i]), 0)) target.pb(i);
	random_shuffle(ALL(target));
	while(1){
		int update = false;
		REP(ii, target.size()){
			int i = target[ii];
			int ok = 1;
			REP(j, m)if(ave[j] < rest[i][j]){
				ok = 0;
				break;
			}
			if(ok){
				REP(j, m) ave[j] += req[i][j] - rest[i][j];
				swap(target[ii], target.back());
				target.pop_back();
				ii --;
				update = 1;
			}
		}
		if(!update) break;
	}
	return target.empty();
}

int main(){
	scanf("%d%d%d", &n, &m, &q);
	vi res(m);
	vector<vi> req(n, vi(m));
	REP(i, m) scanf("%d", &res[i]);
	REP(i, n)REP(j, m) scanf("%d", &req[i][j]);
	vector<pii> query;
	REP(i, q){
		int a, b;
		scanf("%d%d", &a, &b);a --; b --;
		query.eb(a, b);
	}
	int l = 0, r = q+1; // [0, l): ok, [0, r): NG
	
	vi checking(m);
	iota(ALL(checking), 0);
	random_shuffle(ALL(checking));

	while(l+1<r){
		int mid = (l+r)/2;
		auto rest = req;
		auto ave = res;
		REP(i, mid){
			int a, b;
			tie(a, b) = query[i];
			rest[a][b] --;
			ave[b] --;
			int f = 1;
			for(int j : checking){
				if(rest[a][j]){
					f = 0;
					break;
				}
			}
			if(f){
				for(int j : checking) ave[j] += req[a][j];
			}
		}
		if(check(req, rest, ave)) l = mid;
		else r = mid;
	}
	if(l == q) cout << -1 << endl;
	else cout << r << endl;
	return 0;
}

Measured memory_bytes: 5352
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define PI 3.14159265358979
 
 
int main()
 {
	double a,b,h,m;
	double answer,deg,adeg,bdeg,rad;
	
	scanf("%lf%lf%lf%lf",&a,&b,&h,&m);

	adeg=30.0*h+m*0.50;
	
	bdeg=6.0*m;

	deg=fabs(adeg-bdeg);

	rad=deg*PI/180.0;
	
	answer=sqrt(a*a+b*b-2.0*a*b*cos(rad));

	printf("%.10lf",answer);

			return 0;
	}


	







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

int main() {
	
	ll n, m, k; cin >> n >> m >> k;
	vector<ll> aAccum(n + 1, 0), bAccum(m + 1, 0);
	for (ll i = 1; i <= n; i++) {
		ll a;  cin >> a;
		aAccum[i] += aAccum[i - 1];
		aAccum[i] += a;	
	}
	for (ll i = 1; i <= m; i++) {
		ll b;  cin >> b;
		bAccum[i] += bAccum[i - 1];
		bAccum[i] += b;
	}
	if (k < min(aAccum[1], bAccum[1])) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		ll tmp;
		if(k < aAccum[i]) {
			tmp = i - 1;
			break;
		}
		else { // aAccum[i] <= k
			ll diff = k - aAccum[i];
			if (bAccum[m] <= diff) {
				tmp = i + m;
			}
			else { // diff < bAccum[m]
				auto iter = upper_bound(bAccum.begin(), bAccum.end(), diff);
				tmp = iter - bAccum.begin() - 1;
				tmp += i;   // add aAccum
			}
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};


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

    int N,K;
    cin>>N>>K;
    int p[N],c[N];
    rep(i,N){
        cin>>p[i];
        p[i]--;
    }
    rep(i,N){
        cin>>c[i];
    }

    int ans=-INF;
    rep(i,N){
        int sum=0;
        int r=0;
        int x=i;
        while(true){
            sum+=c[x];
            r++;
            x=p[x];
            if(x==i)break;
        }

        int s=0;
        int b=(K-r)/r;
        int a=K-b*r;
        s=max(0LL,b*sum);
        rep(i,a){
            s+=c[x];
            x=p[x];
            ans=max(ans,s);
        }
    }

    cout<<ans<<endl;

}


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

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>cnt(n);
  rep(i,n-1) {
    cin >> a[i];
    a[i]--;
    cnt[a[i]]++;
  }
  rep(i,n) cout << cnt[i] << endl;
  
  return 0;
}


Measured memory_bytes: 4848
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	int a[n];
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	priority_queue <long long>pr;
	for(int i = 0;i < n;i++){
		pr.push(a[i]);
	}
	int t;
	for(int i = 0;i < m;i++){
		t = pr.top();
		t = t/2;
		pr.pop();
		pr.push(t);
	}
	long long ans = 0;
	for(int i = 0;i < n;i++){
		ans += pr.top();
		pr.pop();
	}
	cout << ans;
	return 0;
}


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

using namespace std;

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

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


Measured memory_bytes: 256
/*B*/
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

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

	int N;
	cin >> N;

	int ans = 0;

	vector<int> a(N);
	rep(i, N) {
		cin >> a[i];
		if (a[i] % 2 == 1 && i % 2 == 0) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;

int const inf = 1e9;

template<class T> using PQ_G = priority_queue<T, vector<T>, greater<T>>;

ll dist[100][25];
ll bitcost[1 << 8];
typedef tuple<int, int, int> state; // cost, time, pos

typedef tuple<int, ll, int, int> edge;
vector<vector<edge>> g;

int dijkstra(int start, int goal, int H, int S) {
  PQ_G<state> pq;
  pq.emplace(0, 0, start);

  while(!pq.empty()) {
    ll cost, stime; int pos; tie(cost, stime, pos) = pq.top(); pq.pop();

    if(pos == goal) return cost;

    for(auto && e: g[pos]) {
      int b, c, h, r; tie(b, c, h, r) = e;
      ll ntime = stime + h;
      if(ntime > H) continue;
      if(S >> r & 1) {
        if(dist[b][ntime] <= cost) continue;
        dist[b][ntime] = cost;
        pq.emplace(dist[b][ntime], ntime, b);
      }
      else {
        ll ncost = cost + c;
        if(dist[b][ntime] <= ncost) continue;
        dist[b][ntime] = ncost;
        pq.emplace(dist[b][ntime], ntime, b);
      }
    }
  }
  return inf;
}

signed main() {

  int N, M, H, K;
  while(cin >> N >> M >> H >> K && (N|M|H|K)) {
    g.clear();
    g.resize(N);

    rep(i, M) {
      int a, b, c, h, r; cin >> a >> b >> c >> h >> r;
      a --, b --; r --;
      g[a].emplace_back(b, c, h, r);
      g[b].emplace_back(a, c, h, r);
    }

    int start, goal; cin >> start >> goal; start --, goal --;

    rep(i, 1 << 8) bitcost[i] = inf;
    bitcost[0] = 0;

    int P; cin >> P;

    rep(i, P) {
      int l, d; cin >> l >> d;
      int S = 0;
      rep(j, l) {
        int k; cin >> k; k--;
        S |= 1 << k;
      }
      bitcost[S] = d;
    }

    rep(S, 1 << K) {
      if(bitcost[S] >= inf) continue;
      rep(T, 1 << K) {
        if(bitcost[T] >= inf) continue;
        bitcost[S|T] = min(bitcost[S|T], bitcost[S] + bitcost[T]);
      }
    }

    ll ans = inf;

    rep(S, 1 << K) {
      rep(i, 100) rep(j, 25)
        dist[i][j] = inf;
      dist[start][0] = 0;
      if(bitcost[S] < inf)
        minimize(ans, dijkstra(start, goal, H, S) + bitcost[S]);
    }

    cout << (ans == inf ? -1 : ans) << endl;
    
  }
  
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back


typedef long long ll;
typedef long double ld;


const ll inf = 2e9;
const ll base = 998244353;
ll mod = 1e9 + 7;



int main() {
//    srand(time(NULL));
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
//    std::random_device rd;
//    std::mt19937 g(rd());
    auto start = clock();


    ll n, a, b; cin >> n >> a >> b;
    if (a > b) swap(a, b);
    if (a % 2 == b % 2) {
        cout << (b - a) / 2;
    } else {
        ll ans1, ans2;
        ans1 = (a) + (b - a - 1) / 2;
        ans2 = (n - b + 1) + (n - (a + (n - b + 1))) / 2;
        cout << min(ans1, ans2);
    }



    std::cerr << double(clock() - start) / CLOCKS_PER_SEC << std::endl;
    return 0;
}

Measured memory_bytes: 256