akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long

int x[MX];
int y[MX];
int z[MX];
vector<int> ma;
int ans;
signed main() {
  int n,m;
  cin >> n >> m;
  rep(i,n) cin >> x[i] >> y[i] >> z[i];
  ma.resize(n);
  rep(i,8) {
    int a = (i&1)?-1:1;
    int b = (i>>1&1)?-1:1;
    int c = (i>>2&1)?-1:1;
    // cout <<i<<" "<< (i&1)<<" "<<(i>>1&1)<<" "<<(i>>2&1) << endl;
    // cout << c << endl;
    rep(j,n) {
      ma[j] = a*x[j]+b*y[j]+c*z[j];
    }
    sort(ma.begin(), ma.end(), greater<int>());
    int cakes = 0;
    rep(j,m) cakes += ma[j];
    // cout << cakes << endl;
    ans = max(ans, cakes);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3572
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{
// a*x + b*y = gcd(a,b) となる x, y を拡張ユークリッドの互除法によって求める。
// a, b が負の場合も動作する (多分)
i64 extGCD(i64 a, i64 b, i64 &x, i64 &y)
{
    x = 1, y = 0;
    i64 g = a;
    if (b != 0) {
        g = extGCD(b, a % b, y, x);
        y -= a / b * x;
    }
    return g;
}
// }}}


signed main()
{
    i64 a, b, x, y;
    cin >> a >> b;

    extGCD(a, b, x, y);

    cout << x << ' ' << y << endl;
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <cmath>
#include <algorithm>
#include <deque>
#include <vector>
#include <map>
using namespace std;


int main(){
  int n;
  cin >> n;
  long long a[n];
  vector<long long> kouho;
  map<long long, long long> mp;
  for(int i = 0; i < n ; i++){
    cin >> a[i];
    if(mp.find(a[i])!=mp.end()){
      kouho.push_back(a[i]);
      mp.erase(a[i]);
    }else{
      mp[a[i]] = 0;
    }
  }
  sort(kouho.begin(),kouho.end());
  if(kouho.size() < 2){
    cout << 0 << endl;
  }else{
    cout << kouho[kouho.size()-1] * kouho[kouho.size()-2] << endl;
  }

  return 0;
}


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

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

#define INF 2e9
#define ALL(v) v.begin(), v.end()

int main(){
    int n;
    cin>>n;
    vector<int>X(n);//vectorを使ってみる
    int l=101;
    int r=0;
    rep(i,n){
        cin>>X[i];//入力を配列に入れる
        l=min(l,X[i]);// max,min使える
        r=max(r,X[i]);
    }
    int ans=10000001;
    for(int p=l;p<=r;p++){
        int sum=0;
        rep(i,n){
            sum+=pow(X[i]-p,2);//距離の2乗は1回しか使わないからそのまま式に入れる
        }
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    char c;
    int voule,capital_voule;
    cin >> c;
    voule = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
    capital_voule = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
    if (voule||capital_voule){
        cout <<"vowel";
    }else{
        cout<<"consonant";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i = 1; i < n+1; i++){
    scanf("%d",&A[i]);
  }

  for(i = 0; i < VMAX+1; i++){
    C[i] = 0;
  }

  for(j = 1; j < n+1; j++){
    C[A[j]]++;
  }

  for(i = 1; i < VMAX+1; i++){
    C[i] = C[i] + C[i-1];
  }

  for(j = n; j > 0; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1; i < n+1; i++){
    printf("%d",B[i]);
    if(i == n) break;
    printf(" ");
  }
  printf("\n");

  free(A);
  free(B);


  return 0;
}



Measured memory_bytes: 9136
s = list(str(input()))
K = int(input())
N = len(s)

L = list("abcdefghijklmnopqrstuvwxyz")

def dictmin(p,q):
    ret = -1
    for i in range(len(p)):
        if i >= len(q):
            ret = q
            break
        elif L.index(p[i]) < L.index(q[i]):
            ret = p
            break
        elif L.index(p[i]) > L.index(q[i]):
            ret = q
            break
    if ret == -1:
        ret = p
    return ret

def renew(X,p):
    for i in range(K):
        if X[i] == p:
            break
        elif dictmin(X[i],p) == p:
            for j in range(K-1,i,-1):
                X[j] = X[j-1]
            X[i] = p
            break
    return X
        
count = 0
can = [["z"]*6 for i in range(K)]

for x in L:
    for i in range(N):
        if s[i] == x:
            count += N-i
            for j in range(i,min(i+5,N)):
                #print(s[i:(j+1)])
                can = renew(can,s[i:(j+1)])
                #print(x,i,count,can)
    if can[K-1] != ["z"]*6:
        break

print("".join(can[K-1]))



Measured memory_bytes: 3064
#include <iostream>
typedef long long int ll;

int main(){
    ll n,a,b;
    std::cin >> n >> a >> b;
    
    ll shou=n/(a+b);
    ll jouyo=n%(a+b);
    if(jouyo>a){
        jouyo=a;
    }
    
    std::cout << shou*a+jouyo << std::endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import product

N, M = map(int, input().split())
x, y, z = [0] * N, [0] * N, [0] * N
for i in range(N):
    x[i], y[i], z[i] = map(int, input().split())

ans = 0
for i, j, k in product([-1, 1], [-1, 1], [-1, 1]):
    a = [0] * N
    for l in range(N):
        a[l] = i * x[l] + j * y[l] + k * z[l]
    ans = max(ans, sum(sorted(a, reverse=True)[:M]))
print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main() {
	long long int n, m;

	cin >> n >> m;

	if (n == 1 && m == 1) {
		cout << 1;
	}
	else if (n == 1) {
		cout << m - 2;
	}
	else if (m == 1) {
		cout << n - 2;
	}
	else if (n == 2 || m == 2) {
		cout << 0;
	}
	else {
		cout << (n - 2)*(m - 2);
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  int N;
  cin >> N;
  vector<long long> a(N), d(N);

  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 1; i < N; i++) d[i] = a[i] - a[i-1];

  int dig = 0;
  int ans = 1;
  for (int i = 1; i < N; i++) {
    if (dig == 0) {
      if (!d[i]) continue;
      dig = d[i];
    } else if (dig * d[i] < 0) {
      ans++;
      dig = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

void main()
{
    auto N = readln.chomp.to!long;
    auto AS = readln.split.to!(ulong[]);
    long[61][] CS;
    CS.length = N;
    foreach_reverse (i; 0..N) {
        foreach (j; 0..61) {
            if (i != N-1) CS[i][j] = CS[i+1][j];
            if (AS[i] & (1L<<j)) ++CS[i][j];
        }
    }
    long r;
    foreach (i; 0..N-1) {
        auto a = AS[i];
        foreach (j; 0..61) {
            long x;
            if (a & (1L<<j)) {
                x = (((1L<<j) % P) * (N - i - 1 - CS[i+1][j])) % P;
            } else {
                x = (((1L<<j) % P) * CS[i+1][j]) % P;
            }
            r = (r + x) % P;
        }
    }
    writeln(r);
}

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

int n, r, t;
int p[100];
int a[1000];
int b[1000];
int ans;

int main(){
    cin >> n >> r >> t;
    rep(i, n){
        cin >> p[i];
    }

    rep(i, t){
        rep(j, n){
            int x = p[j] * (i + 1) % r;
            
            if(a[x] > 0){
                --a[x];
            }
            else{
                ++ans;
            }

            if(i > 0){
                ++b[x];
            }
        }

        rep(j, r){
            a[j] += b[j];
            b[j] = 0;
        }
    }

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

Measured memory_bytes: 3108
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct Card {
	char c;
	int v;
	Card() {}
	Card(char c, int v) :c(c), v(v) {};
	bool operator>(const Card &p)const {
		return v > p.v;
	}
	bool operator==(const Card &p)const {
		return p.c == c&&p.v == v;
	}
};

void BubbleSort(vector<Card>p) {
	vector<Card>q(p);
	rep(i, 0, p.size()) {
		rrep(j, i+1, p.size()) {
			if (p[j-1] > p[j])swap(p[j-1], p[j]);
		}
	}
	rep(i, 0, p.size())printf("%c%d%c", p[i].c, p[i].v, (i == p.size() - 1 ? '\n' : ' '));
	for(int i=0;i<p.size()-1;i++)
		for(int j=i+1;j<p.size();j++)
			for(int a=0;a<p.size()-1;a++)
				for(int b=a+1;b<p.size();b++)
					if (p[i] == q[b] && p[j] == q[a]&&p[i].v==q[a].v) {
						cout << "Not stable" << endl;
						return;
					}
	cout << "Stable" << endl;
	return;
}
void SelectionSort(vector<Card>p) {
	vector<Card>q(p);
	rep(i, 0, p.size()) {
		int index = i;
		rep(j, i + 1, p.size())if (p[index] > p[j])index = j;
		swap(p[index], p[i]);
	}
	rep(i, 0, p.size())printf("%c%d%c", p[i].c, p[i].v, (i == p.size() - 1 ? '\n' : ' '));
	for (int i = 0; i<p.size() - 1; i++)
		for (int j = i + 1; j<p.size(); j++)
			for (int a = 0; a<p.size() - 1; a++)
				for (int b = a + 1; b<p.size(); b++)
					if (p[i] == q[b] && p[j] == q[a] && p[i].v == q[a].v) {
						cout << "Not stable" << endl;
						return;
					}
	cout << "Stable" << endl;
	return;
}
signed main() {
	int N; cin >> N;
	vector<Card>cards(N);
	rep(i, 0, N) {
		char c; int v; cin >> c >> v;
		cards[i] = Card(c, v);
	}
	//rep(i, 0, cards.size())printf("%c%d%c", cards[i].c, cards[i].v, (i == cards.size() - 1 ? '\n' : ' '));
	BubbleSort(cards);
	SelectionSort(cards);
	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

int main(){
    vector<int> V={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin>>K;
    cout<<V[K-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
int main() {
	int k, x;
	cin >> k >> x;
	for (int i = x - k + 1; i < x + k; i++)
		cout << i << ' ';
}

Measured memory_bytes: 256
// I want to AC


#include <vector>
#include<stdio.h>
#include<string.h>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#include<cstring>
#include<queue>
#include<assert.h>
#define ll long long
#define MODD 1000000007
#define  pii  pair<int,int>
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
//#define  ll long long
using namespace std;
const int maxn = 1e6+7;
#define FOR(i, x, y) for (ll i = (x), _##i = (y); i < _##i; ++i)


string s;
int  k ;
ll dp[maxn];
int main() {
	 cin >>s;
	 int len = s.size();
	cin >>k;
	if(k==1) cout<<(len-1)*9+s[0]-'0';
	else if(k==2){
		if(len <2)cout<<0;
		else {
			int kk =0 ;int pos =0 ;
			for(int i=1;i<len;i++){
				if(s[i]!='0') {
					pos = i; break;
				}
			}
			if(pos ==0 )cout<<(len-1)*(len-2)*81/2+(s[0]-'0'-1)*9*(len-1);
			else 
			cout<<(len-1)*(len-2)*81/2+(s[0]-'0'-1)*9*(len-1)+(len-pos-1)*9+s[pos]-'0';
			//else 
		}
	}
	else {
		if(len <3)cout<<0;
			else{
				int pos =0 ;int kk=0 ;int pp =0;int f=0;
				for(int i=1;i<len;i++) {
					if(s[i]!='0'){
						if(!f)pos = i ;
						else pp= i;
						f ++;
					}
					if(f==2)break;
				}//(len - pos)*(len-1-pos)*81/2+(s[pos]-'0'-1)*9*(len-pos)+(len-pp-1)*9+s[pp]-'0';
				int llen = (len-pos-2)*(len-pos-1)*81/2+(s[pos]-'0'-1)*9*(len-pos-1)+(len-pp-1 )*9+s[pp]-'0';
				if(pos ==0)llen =0 ;
				else if(pp ==0 )llen = (len-pos-2)*(len-pos-1)*81/2+(s[pos]-'0'-1)*9*(len-pos-1);
				 cout<<(len-3)*(len-1)*(len-2)*81/6*9+(s[0]-'0'-1)*81*(len-1)*(len-2)/2+llen;
			} 
			 
	}
	return 0;



}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int seg(vector<int>a){
	return (a[4]*10000+a[3]*1000+a[2]*100+a[1]*10+a[0]);
}
int check(vector<int> a,vector<int> d){
	int k;
	if(a[4]==0){
		if(a[3]==0){
			if(a[2]==0){
				if(a[1]==0) k=1;
				else k=2;
			}else k=3;
		} else k=4;
	}else k=5;
	for(int i=0;i<k;i++){
	for(int j=0;j<d.size();j++){
		if(a[i]==d[j])return 1;
	}
	}
	return 0;
}

int add(vector<int>&a,vector<int>d){
	a[0]++;
	for(int i=0;i<4;i++){
		if(a[i]==10){
			a[i+1]++;
			a[i]=0;
		}
	}
	return 0;
}

	

int main(){
	int n,k;
	cin>>n>>k;
	vector<int> d(k);
	for(int i=0;i<k;i++){
		cin>>d[i];
	}
	vector<int> a(5,0);
		while(check(a,d)==1){
		add(a,d);
		}
	while(1){
		/*
		for(int i=0;i<5;i++){
			cout<<a[4-i];
		}
		cout<<endl;
		*/
		if(seg(a)>=n)break;
		add(a,d);
		while(check(a,d)==1){
		add(a,d);
		}
	}
	cout<<seg(a)<<endl;
	return 0;
}

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

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

using namespace std;

const int V_MAX=1000;

bool augment(int u,bool *vis,int match[2][V_MAX],const vector<int> *G){
	if(u==-1) return true;

	rep(i,G[u].size()){
		int v=G[u][i];
		if(!vis[v]){
			vis[v]=true;
			if(augment(match[1][v],vis,match,G)){
				match[0][u]=v;
				match[1][v]=u;
				return true;
			}
		}
	}
	return false;
}

int bipartite_matching(int L,int R,const vector<int> *G){
	static int match[2][V_MAX];
	rep(u,L) match[0][u]=-1;
	rep(v,R) match[1][v]=-1;

	int res=0;
	static bool vis[V_MAX];
	rep(u,L){
		rep(v,R) vis[v]=false;
		if(augment(u,vis,match,G)) res++;
	}
	return res;
}

bool solve(int h,int w,const int a[1000][1000]){
	vector<int> G[1000];
	rep(i1,h) rep(i2,h) {
		bool ok=true;
		rep(j,w) if(a[i1][j]<=a[i2][j]) { ok=false; break; }
		if(ok) G[i1].push_back(i2);
	}

	bool top=false; // 山頂が存在するかどうか
	rep(i,h) if(G[i].size()==h-1) top=true;

	return top && h-bipartite_matching(h,h,G)<=2;
}

int main(){
	int h,w; scanf("%d%d",&h,&w);
	static int a1[1000][1000],a2[1000][1000];
	rep(i,h) rep(j,w) scanf("%d",a1[i]+j), a2[j][i]=a1[i][j];

	puts(solve(h,w,a1)&&solve(w,h,a2)?"YES":"NO");

	return 0;
}

Measured memory_bytes: 11000
def main():
    s = input()

    import itertools
    x = sum(map(lambda t: t[0]==t[1], zip(s,itertools.cycle("01"))))
    y = sum(map(lambda t: t[0]==t[1], zip(s,itertools.cycle("10"))))
    print(min(x,y))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const ll INF = 1E+18;


int main(){
    ll n;
    cin >> n;
    
    ll ans = 1;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
        if (a[i]==0) {
            cout << "0" << endl;
            return 0;
        }
    }
    
    rep(i, n) {
        ll x = a[i];
        
        if (INF/ans<x) {
            cout << "-1" << endl;
            return 0;
        }
        ans *= x;
    }    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4048
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <queue>
using namespace std;
int main(){
    int n;
    int s[110];
    cin >> n;
    for(int i = 0; i < n; i++) cin >> s[i];
    int ans = -1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(abs(s[i] - s[j]) > ans) ans = abs(s[i] - s[j]);
        }
    }
    
    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++)
int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int cnt=0;
  while (a >= b) {
    b = b*2;
    cnt++;
  }
  while (b>= c) {
    c = c*2;
    cnt++;
  }
  if (cnt <= x) cout << "Yes";
  if (cnt > x) cout << "No";
}



Measured memory_bytes: 3636
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <unordered_map>
#include <map>
#include <bitset>
#include <string>
#include <cstring>

#define pb push_back
#define mp make_pair
#define l(x) x << 1
#define r(x) x << 1 | 1
#define scan(x) do {while((x=getchar())<'0') ; for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0') ; } while(0)
char _;
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<float, float> pff;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;

int N, x, s = 0, m = 101;

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &x);
        s += x;
        if (x % 10 != 0) {
            m = min(m, x);
        }
    }
    if (s != 0 && s % 10 == 0 && m != 101) {
        s -= m;
    }
    printf("%d\n", s % 10 ? s : 0);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scannerS = new Scanner(System.in);
		String S = scannerS.next();
		String T = scannerS.next();
		int A = scannerS.nextInt();
		int B = scannerS.nextInt();
		String U = scannerS.next();

		int a = A;
		int b = B;

		if (S.equals(U)) {
			a = a - 1;
		} else if (T.equals(U)) {
			b = b - 1;
		}

		System.out.println(a + " " + b);
	}

}

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

using namespace std;
typedef pair<int,int> ii;
vector<ii> ans;
int n,k,mx=0;
int main()
{
    cin >> n >> k;
    for (int i=1;i<=n-2;i++) mx+=i;
    if (k>mx)
    {
        cout << "-1";
        return 0;
    }
    if (1)
    {
        for (int i=2;i<=n;i++) ans.push_back(ii(1,i));
        int d=mx-k;
        for (int i=2;i<n;i++)
            for (int j=i+1;j<=n;j++)
            {
                if (d==0)
                {
                    cout << ans.size() << "\n";
                    for (ii v:ans) cout << v.first << " " << v.second << "\n";
                    return 0;
                }
                ans.push_back(ii(i,j));
                d--;
            }
        cout << ans.size() << "\n";
        for (ii v:ans) cout << v.first << " " << v.second << "\n";
        return 0;
    }
    /*for (int i=1;i<n;i++) ans.push_back(ii(i,i+1));
    for (int i=1;i<=(n-2-k);i++)
        for (int j=i+1;j<=n;j++) ans.push_back(ii(i,j));
    cout << ans.size() << "\n";
    for (ii v:ans) cout << v.first << " " << v.second << "\n";*/
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    const lint MOD = 1e9 + 7;
    lint N; cin >> N;
    vec<lint> A_list(N);
    range(i, 0, N) cin >> A_list.at(i);
    auto count_ups = [&](lint d) {
        lint ans = 0;
        for (const lint& A : A_list) {
            ans += (A >> d) & 1;
        }
        return ans;
    };
    lint ans = 0;
    range(d, 0, 60) {
        lint num_ups = count_ups(d);
        // cout << num_ups << "\n";
        ans += (1LL << d) % MOD * num_ups % MOD * (N - num_ups) % MOD;
        ans %= MOD;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 2560
//https://vjudge.net/contest/383153#problem/E
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define ss second
#define ff first
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 0;
int n;

ll pairMatch(int s, int t){
    return 1LL * s * (n - t + 1) ;
}

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    cin >> n;
    ll ans = 0;
    rep(i, 1, n - 1){
        int x, y; cin >> x >> y;
        ans -= pairMatch(min(x, y), max(x,y));
        ans += pairMatch(i, i);
    }
    ans += pairMatch(n, n);
    cout << ans;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define MAX_N 200010
struct Union_Find {
    int par[MAX_N];
    int rank[MAX_N];

    void init(int n){
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }

//木の根を求める
    int find(int x){
        if(par[x] == x){
            return x;
        }
        else{
            return par[x] = find(par[x]);
        }
    }

// xとyの属する集合を併合
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y)  return;

        if(rank[x] < rank[y]){
            par[x] = y;
        }
        else{
            par[y] = x;
            if(rank[x] == rank[y])  rank[x]++;
        }
    }

//xとyが同じ集合に属するかどうか
    bool same(int x, int y){
        return find(x) == find(y);
    }
};


int main(){
    int N, K, L;
    cin >> N >> K >> L;

    Union_Find u1, u2;
    u1.init(N);
    u2.init(N);

    for(int i = 0; i < K; i++){
        int p, q;   cin >> p >> q;
        p--; q--;
        u1.unite(p, q);
    }

    for(int i = 0; i < L; i++){
        int p, q;   cin >> p >> q;
        p--; q--;
        u2.unite(p, q);
    }

    map<P, int> m;
    for(int i = 0; i < N; i++){
        int x = u1.find(i);
        int y = u2.find(i);
        m[P(x, y)] += 1;
    }

    for(int i = 0; i < N; i++){
        int x = u1.find(i);
        int y = u2.find(i);
        cout << m[P(x, y)] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 15104
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1e9 + 7;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;


int N;
vector<string>S;
int ret;
int R[505], C[505];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	string s;
	REP(y, N) {
		cin >> s;
		S.push_back(s);
		REP(x, N)if (S[y][x] == '#')R[y]++, C[x]++;
	}
	if (count(R, R + N, 0) == N) { print(-1); return 0; }
	int mi = 101010;
	REP(y, N) {
		int num = 0, add = 0;
		REP(x, N)if (S[y][x] == '.')num++;
		REP(i, N)if (S[i][y] == '#')add = 1;
		if (num&&add == 0)num++;
		REP(x, N)if (C[x] != N)num++;
		mi = min(mi, num);
	}
	print(mi);
}


Measured memory_bytes: 512
import sys

n, m = map(int, sys.stdin.readline().split())
graph = [[] for _ in range(n+1)]
for l, r, d in zip(*[map(int, sys.stdin.read().split())] * 3):
    graph[l].append((r, d))
    graph[r].append((l, -d))

def main():
    dist = [None] * (n + 1)
    i = 1
    while i <= n:
        if dist[i] is not None:
            i += 1
            continue
        dist[i] = 0
        stack = [i]
        while stack:
            x = stack.pop()
            for y, d in graph[x]:
                if dist[y] is None:
                    dist[y] = dist[x] + d
                    stack.append(y)
                elif dist[y] != dist[x] + d:
                    return 'No'
    return 'Yes'

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 99184
import sys
import re
from collections import Counter

n = int(input())
p = list(map(int, input().split()))
ans = 0

for i in range(1,n-1):
    mylist = p[i-1:i+2]
    mylist.sort()
    if mylist[1] == p[i]:
        ans += 1

print(ans)


Measured memory_bytes: 3568
#include <stdio.h>

int nDigits( int );

int main( void ) {
	int a, b;

	while ( scanf( "%d %d", &a, &b ) == 2 )
		printf( "%d\n", nDigits( a + b ) );

	return 0;
}

int nDigits( int x ) {
	int d = 1;

	while ( ( x /= 10 ) > 0 )
		d++;

	return d;
}

Measured memory_bytes: 600
#include<stdio.h>
int a[30];
int pan(int a,int b){
	if (a%2!=0) return b;return a;
}

int main(){
	int n,m;
	int i,j,p;
    char c;
    int ss,k;
	scanf("%d %d",&n,&m);getchar();
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++) {scanf("%c",&c);a[c-96]++;}
		getchar();
	}
	ss=0;p=0;
	for (i=1;i<=26;i++) if (a[i]%4!=0) {
		p=p+a[i]/4*4;
        a[i]=a[i]%4;
        ss=ss+a[i]/2*2; 
		if (a[i]%2!=0) k++;
	}else p=p+a[i]/4*4;
	if (n%2==0&&m%2==0) {
		if (p==n*m) printf("Yes\n");else printf("No\n");
        return 0;
	}else if (n%2!=0&&m%2!=0){//可以放1的情况 
	
	if (k>1||ss>n+m-2) {printf("No\n");return 0;}
	printf("Yes\n");return 0;
    }else {
    	if (k>0||ss>pan(n,m)) {printf("No\n");return 0;}
	printf("Yes\n");return 0;
    }
} 


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main()
{
	int n; cin>>n;
	map<int, int> mp;
	for(int i=0; i<(1<<n); i++){
		int s; cin>>s;
		mp[s]++;
	}
	priority_queue<int> que;
	que.push(n);
	for(auto itr=mp.rbegin(); itr!=mp.rend(); itr++){
		int c=itr->second;
		if(c>que.size()){
			cout<<"No"<<endl;
			return 0;
		}
		vector<int> v;
		for(int i=0; i<c; i++){
			int x=que.top(); que.pop();
			v.push_back(x);
		}
		for(auto x:v) for(int y=0; y<x; y++) que.push(y);
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 13184
// Vicfred
// https://atcoder.jp/contests/abc168/tasks/abc168_a
import std.stdio;
import std.conv;
import std.string;

void main() {
    int n = readln.chomp.to!int;
    n = n%10;

    switch(n) {
        case 0, 1, 6, 8:
            writeln("pon");
        break;
        case 3:
            writeln("bon");
        break;
        default:
            writeln("hon");
        break;
    }
}



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

using namespace std;

int main(){
    int n, tmp;
    vector<int> d;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> tmp;
        d.push_back(tmp);
    }
    sort(d.begin(), d.end());
    int cnt=0,_sum=0;
    cout << d[n/2] - d[n/2-1] << endl;
}



Measured memory_bytes: 892
#include <iostream>
#include <vector>
using namespace std;
typedef long long i64;
typedef char str255[256];

#define BIG_PRIME 1000000007
#define remainder(x) ((x) % BIG_PRIME)

int A, B;

int GCD(int a, int b) // 最大公約数（std::gcd()はC++17から？）
{
  int r = a % b;
  while(r != 0){
    a = b; b = r; r = a % b;
  }
  return b;
}

i64 LCM(int a, int b) // 最小公倍数（std::lcm()はC++17から？）
{
  return (i64)a * b / (i64)GCD(a, b);
}
void Solve()
{
  cout << LCM(A, B) << endl;
}

void Init()
{
  cin >> A >> B;
}

void Clean(){}

int main(){ Init(); Solve(); Clean(); return 0; }


Measured memory_bytes: 256
#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;
    cin >> n;
    vector <ll> a(n);
    rep(i,n){
        cin >> a[i];
    }

    sort(a.begin(),a.end());
    ll b,c,d;
    b=a[n-1];

    
if(n>2){
    rep(i,n-1){
        if(a[i]>b/2){
            if(i!=0){
            c=a[i-1];
            }
            else{
                c=0;
            }
            d=a[i];
            break;

        }
    }
}
if(n==2){
    b=a[1];
    c=a[0];
    d=a[0];
}
//cout << c << d << endl;
    if((b/2-c)<(d-b/2)){
        cout << b << " " << c << endl;
    }
    else{
        cout << b << " " << d << endl;
    }
    

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s=="Sunny")
    {
        cout<<"Cloudy";
    }
    else if(s=="Cloudy")
    {
        cout<<"Rainy";
    }
    else
    {
        cout<<"Sunny";
    }
}

Measured memory_bytes: 3576
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::*,
    std::{cmp::*, collections::*, convert::*, iter::*, marker::*, mem::*, ops::*},
};
fn main() {
    input! {//
        n:usize,
        ab:[(Usize1,Usize1);n-1],
        mut c:[usize;n],
    }
    c.sort();
    println!("{}", c.iter().take(n - 1).fold(0, |sum, x| sum + x));
    c.reverse();
    let mut v = vec![vec![]; n];
    let mut ans = vec![0; n];
    for &(a, b) in ab.iter() {
        v[a].push(b);
        v[b].push(a);
    }

    let mut st = BTreeSet::new();
    let mut prv = BTreeSet::new();
    st.insert(0);
    st.insert(v[0][0]);
    let mut st = vec![0, v[0][0]];
    ans[0] = c[0];
    ans[v[0][0]] = c[1];
    let mut i = 2;
    prv = st.clone().into_iter().collect();
    loop {
        let mut to = BTreeSet::new();
        let now = prv.clone();
        for &x in now.iter() {
            for &nx in v[x].iter() {
                if !st.contains(&nx) {
                    to.insert(nx);
                    ans[nx] = c[i];
                    i += 1;
                }
            }
        }
        prv = to.clone();
        for &x in to.iter() {
            st.push(x);
        }
        if st.len() == n {
            break;
        }
    }

    for x in ans.iter() {
        println!("{}", x);
    }
}


Measured memory_bytes: 3580
// std = C++11~
#include <iostream>
#include <utility> // -std=c++11, swap
using namespace std;

int partition(int* A, int p, int r) {
    const int x = A[r];
    int i = p - 1;
    for (int j = p; j <= r - 1; j++)
        if (A[j] <= x) {
            i++;
            swap(A[i], A[j]);
        }
    swap(A[i + 1], A[r]);
    return i + 1;
}

int main() {
    int n; cin >> n;
    int A[n]; for (int i = 0; i < n; i++) cin >> A[i];

    const int q = partition(A, 0, n - 1); 

    for (int i = 0; i <= q - 1; i++)
        cout << A[i] << ' ';
    cout << '[' << A[q] << "] ";
    for (int i = q + 1; i < n; i++) {
        cout << A[i];
        if (i == n - 1)
            cout << endl;
        else
            cout << ' ';
    }
}


Measured memory_bytes: 3424
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort()
    Bs = [(b, c) for b, c in zip(B, C)]
    Bs.sort(key=lambda x: x[1], reverse=True)
    i = 0
    flag = False
    for b, c in Bs:
        for j in range(b):
            if i >= N:
                flag = True
                break
            if A[i] >= c:
                flag = True
                break
            A[i] = c
            i += 1
        if flag:
            break
    print(sum(A))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]" 
    C = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 69280
n, m = map(int, input().split())
l = []
r = []
for i in range(1, m + 1):
    s, t = map(int, input().split())
    l.append(s)
    r.append(t)
l.sort()
r.sort()
tmp = range(l[-1], r[0] + 1)
se = set(tmp)
print(len(se))

Measured memory_bytes: 64472
// abc172_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M);
    vector<ll> cumsumA(N+1), cumsumB(M+1);
    REP(i, N) {
        cin >> A[i];
        cumsumA[i+1] = cumsumA[i] + A[i];
    }
    REP(i, M) {
        cin >> B[i];
        cumsumB[i+1] = cumsumB[i] + B[i];
    }

//    print(cumsumA, cumsumB);

    ll ans = 0;
    REPN(i, 0, N+1){
        ll k = K - cumsumA[i];
        if (k < 0) continue;

        ll x = upper_bound(ALL(cumsumB), k) - cumsumB.begin();
//        print(i, k, x-1);
        ans = max(ans, i + x-1);
    }
    print(ans);



    return 0;
}


Measured memory_bytes: 9528
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define M 1001

using namespace std;

int n, m, minl = 0x7fffffff;
bool mapp[M][M];
bool visit[M];
int ans[M];
int real[M];

void dfs(int x, int num)
{
	if (num > minl)
		return;

	if (visit[x] == true)
	{
		int p;
		for (int i = 1; i <= num; i++)
			if (ans[i] == x)
			{
				p = i;
				break;
			}
		minl = num - p;
		int tmp = 1;
		for (int i = p + 1; i <= num; i++)
			real[i - p] = ans[i];

		return;
	}

	visit[x] = true;

	for (int i = 1; i <= n; i++)
	{
		if (mapp[x][i] == true)
		{
			num++;
			ans[num] = i;

			dfs(i, num);
			num--;
		}
	}

	visit[x] = false;
	return;
}

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		int x, y;
		cin >> x >> y;
		mapp[x][y] = true;
	}

	for (int i = 1; i <= n; i++)
	{
		ans[1] = i;
		dfs(i, 1);

		memset(visit, 0, sizeof(visit));
	}

	if (minl == 0x7fffffff)
		cout << -1 << endl;
	else
	{
		cout << minl << endl;
		for (int i = 1; i <= minl; i++)
			cout << real[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1280
from heapq import *

an, bn, cn, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
la = len(a)
lb = len(b)
lc = len(c)

ans = []
hp = [[-(a[0] + b[0] + c[0]), 0, 0, 0]]
heapify(hp)
sumi = [[0, 0, 0]]
for _ in range(k):
    hpk = heappop(hp)
    mx = hpk[0]
    ai = hpk[1]
    bi = hpk[2]
    ci = hpk[3]
    if ai + 1 < la and [ai + 1, bi, ci] not in sumi:
        heappush(hp, [mx + a[ai] - a[ai + 1], ai + 1, bi, ci])
        sumi += [[ai + 1, bi, ci]]
    if bi + 1 < lb and [ai, bi + 1, ci] not in sumi:
        heappush(hp, [mx + b[bi] - b[bi + 1], ai, bi + 1, ci])
        sumi += [[ai, bi + 1, ci]]
    if ci + 1 < lc and [ai, bi, ci + 1] not in sumi:
        heappush(hp, [mx + c[ci] - c[ci + 1], ai, bi, ci + 1])
        sumi += [[ai, bi, ci + 1]]
    ans += [-mx]

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


Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
//#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch GrandGarden | diff GrandGarden.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address GrandGarden.cpp && ./a.out

/*
 
 2/19/2019
 
 19:35-19:52 AC
 
 https://img.atcoder.jp/abc116/editorial.pdf
 https://misteer.hatenablog.com/entry/ABC116
 
 */

const int MAX_N=1e6+1;
LL H[MAX_N];
int N;

void solve() {
  int res=0;
  int cur=0;
  REP(i,N) {
    if(H[i]>cur) res+=H[i]-cur;
    cur=H[i];
  }
  cout<<res<<endl;
}

// O(N^2) time
void solve_org() {
  int res=0;
  int l=-1;
  queue<II> Q;
  auto sweep=[&]() {
    dumpC(H,H+N);
    REP(i,N) {
      if((i==0&&H[i]>0)||(H[i-1]==0&&H[i]>0)) {
        l=i;
      }
      if((i==N-1&&H[i]>0)||(H[i]>0&&H[i+1]==0)) {
        dump(l,i);
        if(l!=-1) Q.emplace(l,i+1),l=-1;
      }
    }
  };
  sweep();
  while(SZ(Q)) {
    int t=SZ(Q);
    while(t--) {
      int l,r; tie(l,r)=Q.front(); Q.pop();
      int x=*min_element(H+l,H+r);
      dump(l,r,x);
      assert(x>0);
      res+=x;
      FOR(i,l,r) H[i]-=x;
    }
    sweep();
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>H[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3+100;
const int P = 1e9+7;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)
#define pb push_back

int f[N][17];
int n;

inline int pow_mod(int x,int k){
   int res = 1,base = x;
   while(k){
      if(k&1)res = 1LL*res*base%P;
      k >>= 1; base = 1LL*base*base%P;
   }
   return res;
}

inline void add(int &x,int y){
   x += y; if(x >= P)x -= P;
}

void init(){
   memset(f,0,sizeof f);
   f[0][1] = f[0][3] = f[0][5] = f[0][7] = f[0][9] = f[0][11] = 1;
   fr(i,1,N-1){
      fr(j,1,15){
         if(j <= 10){
            if(j%2 == 0){
               for(int w = j-1;w <= 11; w += 2)
                  add(f[i][w],f[i-1][j]);
            } else {
               add(f[i][j+1],f[i-1][j]);
            }
         } else {
            fr(w,0,i-1){
               add(f[i][j+1],1LL*f[w][j]*(i-w)%P);
            }
         }
      }
      add(f[i][16],f[i-1][16]);
   }
}

int lagrange_interpolation(vector<int> val,int x){
   int sz = 15;
   int ans = 0;

   fr(i,0,sz){
      int res = val[i];
      fr(j,0,sz){
         if(j == i)continue ;
         res = 1LL*res*pow_mod(P+i-j,P-2)%P*(P+x-j)%P;
      }
      add(ans,res);
   }
   return ans;
}

void solve(){
   int n; scanf("%d",&n);
   if(n < 5)puts("0");
   else {
      int z = n%2 == 0;
      n = (n-5)/2;
      vector<int> v;
      if(z){
         for(int i = 6;i <= 36;i += 2)v.pb(f[i][16]);
      } else {
         for(int i = 5;i <= 35;i += 2)v.pb(f[i][16]);
      }
      printf("%d\n",lagrange_interpolation(v,n));
   }
   return ;
}

int main(){
   init();
   int t; scanf("%d",&t); while(t--)solve();
}


Measured memory_bytes: 3832