akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int p[20005];
int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	int cnt;
	for (int i = 1; i <= n; ++i)
	{
		cin >> cnt;
		p[cnt] = i;
	}
	for (int i = 1; i <= n; ++i)
	{
		printf("%d", n * i);
		if(i==n)printf("\n");
		else printf(" ");
	}
	for (int i = 1; i <= n; ++i)
	{
		printf("%d", (n - i) * n + p[i]);
		if(i==n) printf("\n");
		else printf(" ");
	}
	return 0;
}


Measured memory_bytes: 640
// Problem : B - Judge Status Summary
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;

void solve(){
	int q;
	cin>>q;
	map<string,int>f;
	while(q--)	{
		string s;
		cin>>s;
		f[s]++;
	}
	cout<<"AC x "<<f["AC"]<<endl;
	cout<<"WA x "<<f["WA"]<<endl;
	cout<<"TLE x "<<f["TLE"]<<endl;
	cout<<"RE x "<<f["RE"]<<endl;
	
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
int main(){
int S=0,h=0,m=0,s=0;
scanf("%d",&S);

h = S / 3600;
m = S % 3600 / 60;
s = S % 3600 % 60;

printf("%d:%d:%d\n", h,m,s);
return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
ll Max = 10 + 1e8;
int main()
{
	int n, k;
	cin >> n >> k;
	vector<ll> h(n);
	rep(i, n) cin >> h[i];
	sort(h.begin(), h.end(),greater<ll>());
	ll sum = 0;
	for (int i = k;i < n;i++) {
		sum += h[i];
	}
	cout << sum;
}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int max = 0;
    vector<int> V(n);
    vector<int> C(n);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> V[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> C[i];
    }
    for (int i = 0; i < n; i++)
    {
        if (V[i] > C[i])
        {
            max += V[i] - C[i];
        }
    }
    cout << max << endl;
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	long long a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a, a+n, greater<int>());
	long long sum = 0;
	int k = 0;
	for(int i=0;i<n-1;i++){
		sum += a[k];
		if(i%2==0) k++;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 5148
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;


int main() {
	string str;
	getline(cin, str);
	for (int i = 0; i < str.size(); i++) {
		if(str[i] != '.' && str[i] != ' '){
			str[i] = str[i] - 'a' + 'A';
		}
	}
	cout << str <<endl;

	return 0;
}

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

int solve(string s) {
	stack<char> st;
	for (int i = 0; i != s.length(); i++) {
		if (st.empty()) {
			st.push(s[i]);
			continue;
		}

		char temp = st.top();
		if (temp == 'S' && s[i] == 'T')
			st.pop();
		else
			st.push(s[i]);
	}
	return st.size();
}

int main() {
	string s;
	while (!(cin >> s).eof()) {
		int ans = solve(s);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 772
// C - Switches
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int main(){
	int N,M;
	cin>>N>>M;

	vi S(M);
	for(int m=0; m<M; ++m){
		int K; cin>>K;
		for(int k=0; k<K; ++k){ int s; cin>>s; S[m] += (1<<(s-1)); }
	}

	vi P(M);
	for(int p=0; p<M; ++p) cin>>P[p];

	int count = 0;
	int end = 1<<N;
	for(int s=0; s<end; ++s){//s: sw all pattern
		int match_count = 0;
		for(int m=0; m<M; ++m){// input-data sw matching
			int sw = s & S[m];
			int b = 0; while(sw){ if(sw&1) ++b; sw/=2; }//count bit '1'
			if(b%2 == P[m]) ++match_count;
		}
		if(match_count==M) ++count;
	}
	cout<< count <<endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

struct BIT {
    int n;
    vector<int> bit; // 1-indexd

    BIT(int sz) {
        bit.resize(sz + 1);
        n = sz;
    }

    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

class CLowElements {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> p(N);
        REP(i, N) cin >> p[i];

        int res = 0;
        int m = p[0];
        REP(i, N) {
            if (m >= p[i]) res++;
            m = min(m, p[i]);
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CLowElements solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1792
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int MAXN = 200228;



int dp[MAXN][2];
int pr[MAXN][2];


void solve() {
	string s;
	cin >> s;
	for (int i = 0; i <= sz(s); i++) {
		dp[i][0] = -1e9;
		dp[i][1] = -1e9;
	}
	if (s[0] == '?') {
		dp[0][0] = 0;
		dp[0][1] = 1;
	} else {
		int t = (s[0] == 'D');
		dp[0][t] = t;
	}
	for (int i = 0; i < sz(s) - 1; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				if (s[i + 1] != '?') {
					int t = s[i + 1] == 'D';
					if (t != k) {
						continue;
					}
				}
				chkmax(dp[i + 1][k], dp[i][j] + k + (k == 1 && j == 0));
				if (dp[i + 1][k] == dp[i][j] + k + (k == 1 && j == 0)) {
					pr[i + 1][k] = j;
				}
			}
		}
	}
	int opt = -1;
	int pos;
	for (int t = 0; t < 2; t++) {
		if (dp[sz(s) - 1][t] > opt) {
			opt = dp[sz(s) - 1][t];
			pos = t;
		}
	}
	string ans;
	for (int i = sz(s) - 1; i >= 0; i--) {
		ans += (pos == 0 ? 'P': 'D');
		pos = pr[i][pos];
	}
	reverse(all(ans));
	cout << ans << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	int t;
	//cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
	return 0; 	
}

Measured memory_bytes: 6920
#include <bits/stdc++.h>
using namespace std;
	int L[500002/2],R[500002/2];
	int cnt;

void merge(int A[],int n,int left,int mid,int right)
	{
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++){L[i]=A[left+i];}
  	for(int i=0;i<n2;i++){R[i]=A[mid+i];}
  	L[n1]=R[n2]=2000000000;
  	int i=0,j=0;
  	for(int k=left;k<right;k++){
    	cnt++;
    	if(L[i]<=R[j]){A[k]=L[i++];}
    	else{A[k]=R[j++];}
    }  
}

void mergeSort(int A[],int n,int left,int right){
	if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);  
    }
}

int main() {
	int A[500000],n,i; cnt=0;
  	cin >>n;
  	for(int i=0;i<n;i++){cin>>A[i];}
  	mergeSort(A,n,0,n);
  	for(int i=0;i<n;i++){
    if(i)cout<<" ";
		cout <<A[i];
    }
  	cout <<endl;
  	cout <<cnt<<endl;
}




Measured memory_bytes: 6936
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

int isVisited(int i, int j, int k, vector<vector<int>> &t) {
    int ret = INF;
    if (k == 0) return t[j][0];
    if ((i>>(k-1))%2 == 1) {
        ret = t[j][k];
    }
    return ret;
}

void print(vector<int> &dp) {
    for (int i = 0; i < dp.size(); ++i) {
        cout << "i = " << static_cast<bitset<5>>(i) << " dp[i] = " << dp[i] << endl;
    }
}

int main(int argc, char const *argv[]) {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        vector<vector<int>> t(n, vector<int>(n+1));
        REP(i,n) {
            REP(j,n+1) {
                cin >> t[i][j];
            }
        }
        vector<int> dp((1<<n), INF);
        dp[0] = 0;
        // iは集合
        for (int i = 0; i < (1<<n); ++i) {
            // jは次に行くステージ
            for (int j = 0; j < n; ++j) {
                // jが訪問済みであればcontinue
                if ((i>>j)%2 == 1) continue;
                // 次の集合にjbit目を立てる
                int next = i | (1<<j);
                // kが訪問済みであればjの攻略に際しk+1番目の装備が使用できる
                for (int k = 0; k <= n; ++k) {
                    int tmp = isVisited(i, j, k, t);
                    // cout << "i = " << static_cast<bitset<5>>(i) << " j = " << j << " k = " << k <<  " isVisited = " << tmp << endl;
                    dp[next] = min(dp[next], dp[i]+isVisited(i, j, k, t));
                }
            }
        }
        int all = (1<<n)-1;
        // print(dp);
        cout << dp[all] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3408
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	string s;
	cin >> s;

	string tmp = "";
	for(int i = 0; i < s.length(); i++){
		if(s.at(i) == '0'){
			tmp += "0";
		}else if(s.at(i) == '1'){
			tmp += "1";
		}else{
			if(s.length() > 0){
				tmp = tmp.substr(0, tmp.length() - 1);
			}
		}
	}
	cout << tmp << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    string s;
    cin >> s;
    std::sort(s.begin(), s.end());
    yorn (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]);
    return 0;
}

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

int main(){
    int n;
    int flag = 1;
    int minj;
    char c[36][5],alt[36][3] = { },tmp;
    cin >> n;
    for (int i=0;i<n;i++){
        cin >>c[i];
        alt[i][0] = c[i][0];
        alt[i][1] = c[i][1];
    }
    for (int i=0;i<n;i++)
        for (int j=n-1;j>i;j--)
            if (alt[j-1][1]> alt[j][1])
            {
                tmp = alt[j - 1][1];
				alt[j - 1][1] = alt[j][1];
				alt[j][1] = tmp;
				tmp = alt[j - 1][0];
				alt[j - 1][0] = alt[j][0];
				alt[j][0] = tmp;
            }
    for (int i=0;i<n;i++){
        if (i) cout <<" ";
        cout <<alt[i];
    }
    cout <<endl << "Stable" <<endl;
    
   
   
   
    for (int i=0;i<n;i++){
        minj = i;
		for (int j = i; j < n; j++)
			if (c[minj][1] > c[j][1]) minj = j;
		for (int j = i + 1; j < minj; j++)
			if (c[j][1] == c[i][1]) flag = 0;
		
		tmp = c[minj][0];
		c[minj][0] = c[i][0];
		c[i][0] = tmp;
		tmp = c[minj][1];
		c[minj][1] = c[i][1];
		c[i][1] = tmp;
	}
	for (int i = 0; i < n; i++){
		if (i) cout << " ";
		cout << c[i];
	}
	if (flag) cout << endl << "Stable" << endl;
	else cout << endl << "Not stable" << endl;

	return 0;
}



Measured memory_bytes: 3108
#include<iostream>
using namespace std;
const int MAXN=1e5+5;
long long T[MAXN];
int n,k;

int check(long long P){
	int i=0;
	for(int j=0;j<k;j++){
		long long s=0;
		while(s+T[i]<=P){
			s+=T[i];
			i++;
			if(i==n)return n;
		}
	}
	return i;
}

int solve(){
	long long low=0;
	long long high=1e9+5;
	long long mid;
	while(high-low>1){
		mid=(high+low)/2;
		int v=check(mid);;
		if(v>=n)high=mid;
		else low=mid;
	}
	return high;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>T[i];
	long long ans=solve();
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3872
//#include<string>
#include <iostream>
 
#define T long long
 
int main(void){
	T result=0;
	T n;
	
	std::cin >> n;
	for(int i=1;i<=n;i++){
		if(((i%5)!=0)&&((i%3)!=0)){
			result+=i;
		}
	}
	std::cout << result <<std::endl;
}

Measured memory_bytes: 3636
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = []

for i in range(n):
    if i == 0:
        dp.append([abc[0][0], abc[0][1], abc[0][2]])
        continue
    dp.append([max(dp[i-1][1]+abc[i][0], dp[i-1][2]+abc[i][0]), max(dp[i-1][2]+abc[i][1], dp[i-1][0]+abc[i][1]), max(dp[i-1][0]+abc[i][2], dp[i-1][1]+abc[i][2])])

print(max(dp[-1]))

Measured memory_bytes: 47336
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for (int i=0;i<n;i++) {cout<<"ACL";}
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3648
# https://atcoder.jp/contests/abc125/submissions/5142309
# https://twitter.com/armeria_betrue/status/1122134567765233665

N = gets.to_i
A = [0] + gets.split(' ').map(&:to_i)
gcd = []

left  = Array.new(N + 2, 0)
right = Array.new(N + 2, 0)

(1..N).each do |i|
  left[i] = left[i - 1].gcd(A[i])
end

N.downto(1).each do |i|
  right[i] = right[i + 1].gcd(A[i])
end

(1..N).each do |i|
  gcd.push(left[i - 1].gcd(right[i + 1]))
end

puts gcd.max

Measured memory_bytes: 11788
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

int main() {
   string s;
   cin >> s;
   string ans = "";
   for (int i = 0; i < (int)s.size(); ++i) {
	   if (i % 2 == 0) {
		   ans += s[i];
	   }
   }
   cout << ans;
}



















Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 50;
int A[MAXN], dp[MAXN];

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    int negs = 0;
    int sum = 0;
    for (int i=1; i<=N; i++){
        cin >> A[i];
        if (A[i] < 0) {
            negs ++;
            A[i] = -A[i];
        }
        sum += A[i];
    }
    if (negs % 2==0) cout << sum;
    else{
        cout << sum - 2*(*min_element(A+1, A+N+1));
    }
}


Measured memory_bytes: 1024
# 2020/07/18
# AtCoder Beginner Contest 142 - C

# Input
n = int(input())
a = list(map(int,input().split()))
al = [0] * (n+1)

# Calc
for i in range(n):
    al[a[i]] = i+1

al.remove(0)

# Output
print(' '.join([str(j) for j in al]))


Measured memory_bytes: 24484
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,m,k,ans=0;
  cin >> n >> m >> k;
  vector<ll> a(n),b(m),asum(n+1,0),bsum(m+1,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
    asum[i+1] += asum[i] + a[i];
  }
  for(int i=0;i<m;i++){
    cin >> b[i];
    bsum[i+1] += bsum[i] + b[i];
  }
  for(int i=0;i<=n;i++){
    ll tmp;
    if(asum[i]>k) break;
    ll l = 0,r=m+1;
    while(r-l>1){
      ll h = (r+l)/2;
      if(bsum[h]<=k-asum[i]){
        l = h;
      }else{
        r = h;
      }
    }
    tmp = i + l;
    ans = max(tmp,ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 9500
#include<stdio.h>
n[3][101];
a[200][3];
int main(void){
	int N,i,j;
	scanf("%d",&N);
	for(i=0;i<N;i++){
	for(j=0;j<3;j++){
	int k=0;
	scanf("%d",&k);
	n[j][k]++;
	a[i][j]=k;
}	
}
	for(i=0;i<N;i++){
	int l=0;
	for(j=0;j<3;j++){
	if(n[j][a[i][j]]==1){l+=a[i][j];}
}
printf("%d\n",l);
}	
	return 0;
}

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

using namespace std;

/**
 *  Name: Chris M. Perez
 *  University: Interamerican University Metro Campus
 *
**/

#define endl '\n'
#define MOD 10E9
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define gcd(x , y) __gcd(x , y)
#define all(x) (x).begin() , (x).end()
#define forn(i , a , b) for(int i=(a);i<(b);i++)
#define forrange(j , a , b) for(int j=(a);j<=(b);j++)
#define nestedforn(i , a , b , j , c , d) for(int i=(a);i<=(b);i++) for(int j=(c);j<=(d);j++)
#define sort_all(x) sort(all(x))
#define zeros_at_beginning(x) __builtin_clz(x)
#define zeros_at_end(x) __builtin_ctz(x)
#define ones(x) __builtin_popcount(x)
#define parity_even_or_odd_ones __builtin_parity(x)

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef tuple<int , int , int> tiii;
typedef vector<pii> vpii;
typedef vector<tiii> vtiii;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef long long int lli;

             
inline int input(){
  int n;
  scanf("%d" , &n);
  return n;
}
                    
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;  

#ifdef LOCAL_DEFINE
  freopen("input.txt" , "rt" , stdin);
#endif
  
  char n; cin >> n;
  if(n == 'A') cout << 'T' << endl;
  else if(n == 'T') cout << 'A' << endl;
  else if(n == 'G') cout << 'C' << endl;
  else cout << 'G' << endl;
    
         
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int ans = b / a;
            if (c < ans){
                ans = c;
            }
            out.println(ans);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


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

//--------Constants--------------
#define ll long long int

//--------Variables--------------
int a,b,c;
//--------Functions--------------

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
//--------Input------------------
    cin >> a >> b >> c;
//--------Work-------------------
    if (c>a && b>c) cout << "Yes";
    else if (a>c && c>b) cout << "Yes";
    else cout << "No";
}


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

using namespace std;
int main(void){
    char a,b;

    cin >> a >> b;
    if(a<b)cout << "<" << endl;
    else if(a>b)cout << ">" << endl;
    else cout << "=" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int ans[100100];
bool used[100100];
map<int, vector<pair<int,int>>> mp;

void dfs(int x, int which) {
  vector<pair<int,int>> v = mp[x];
  for(auto e: v) {
    if(!used[e.first]) {
      used[e.first] = true;
      if(e.second % 2 == 1) {
        ans[e.first] = 1 - which;
      } else {
        ans[e.first] = which;
      }
      dfs(e.first, ans[e.first]);
    }
  }
}

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

  // int n,m;
  // cin>>n>>m;
  // UnionFind tree(n);
  // rep(i,m) {
  //   int x,y,z;
  //   cin>>x>>y>>z;
  //   tree.unite(x-1,y-1);
  // }
  // set<int> s;
  // rep(i,n) {
  //   s.insert(tree.root(i));
  // }
  // cout << s.size() << endl;

  int n;
  cin>>n;
  int f = -1, s = -1;
  bool flag = false;
  rep(i,n-1) {
    int u,v,w;
    cin>>u>>v>>w;
    mp[u].push_back(make_pair(v,w));
    mp[v].push_back(make_pair(u,w));
    if(w % 2 == 1 && !flag) {
      f = u;s = v;
      used[f] = true;
      used[s] = true;
      ans[f] = 0;
      ans[s] = 1;
      flag = true;
    }
  }
  if(f == -1 && s == -1) {
    rep(i,n) {
      cout << 0 << endl;
    }
    return 0;
  }
  
  dfs(f,0);
  dfs(s,1);


  rep(i,n) {
    cout << ans[i+1] << endl;
  }

  return 0;
}


Measured memory_bytes: 22656
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n;
  cin>>n;
  vector<long long int> a(n);
  for(long long int i=0; i<n; i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());

  long long int all=0;
  long long int last=0;
  for(long long int i=0; i<n-1; i++){
    all+=a.at(i);
    if(2*all<a.at(i+1)){
      last=i+1;
    }
  }
  cout<<n-last<<endl;
}

Measured memory_bytes: 1024
//15
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    long long h[100][100];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin>>h[i][j];
      }
    }
    bool hd[100][100]={{}};
    for(int i=0;i<n;i++){
      long long s=1ULL<<62;
      for(int j=0;j<n;j++){
	s=min(s,h[i][j]);
      }
      for(int j=0;j<n;j++){
	hd[i][j]|=h[i][j]!=s;
      }
    }
    for(int i=0;i<n;i++){
      long long t=0;
      for(int j=0;j<n;j++){
	t=max(t,h[j][i]);
      }
      for(int j=0;j<n;j++){
	hd[j][i]|=h[j][i]!=t;
      }
    }
    long long ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(!hd[i][j]){
	  ans=max(ans,h[i][j]);
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

#define ll long long int
#define mp make_pair
#define pb push_back
using namespace std;

int main() {
    string s;
    cin >> s;
    if (s[0] != 'A') {
        printf("WA");
        return 0;
    }
    if(s[s.length()-1] < 'a' || s[s.length() - 1] > 'z' ) {
        printf("WA");
        return 0;
    }
    if (s[1] >= 'a' && s[1] <= 'z') {
        int c= 0 , index ;
        for (int i = 2; i < s.length() - 1; ++i) {
            if (s[i] == 'C'){
                c++;
                index = i;
            }
        }
        if(c != 1) {
            printf("WA");
            return 0;
        }
        else{
            c= 0;
            int x= 0 ;
            for (int i = 2; i < s.length() - 1; ++i) {
                x++;
                if(i != index){
                    if(s[i] >= 'a' && s[i] <= 'z');
                    c++;
                }
            }
            if(c+1 == x){
                printf("AC");
                return 0;
            }
            else{
                printf("WA");
            }
        }
    }
    else{
        printf("WA");
    }
    return 0;
}

Measured memory_bytes: 256
k=int(input())
l=[1,2,3,4,5,6,7,8,9]
for i in range(k):
  x=l[i]
  if x%10!=0:
    l.append(10*x+x%10-1)
  l.append(10*x+x%10)
  if x%10!=9:
    l.append(10*x+x%10+1)
print(x)

Measured memory_bytes: 15784
N, M = map(int, input().split())
routes = [[] for i in range(N-1)]
ans = [0]*(N-1)
li = []
for i in range(M):
  r = list(map(int, input().split()))
  if r[0] == 1:
    li.append(r[1])
    ans[r[1]-2] = 1
  elif r[1] == 1:
    li.append(r[0])
    ans[r[0]-2] = 1
  else:
    routes[r[0]-2].append(r[1])
    routes[r[1]-2].append(r[0])
    
flag = True
while 0 in ans:
  tmp = []
  if li == []:
    flag = False
    break
  for num in li:
    for route in routes[num-2]:
      if ans[route-2] == 0:
        ans[route-2] = num
        tmp.append(route)
  li = tmp
  
if flag:
  print('Yes')
  for i in range(N-1):
    print(ans[i])
else:
  print('No')

Measured memory_bytes: 33588
//ABC146B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <numeric>
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i=0;i<=n;i++){
		if(i*108/100 == n){
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#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 all(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int X; cin >> X;
    int t;
    t = X / 100;
    X -= t * 100;
    for(int i=0;i<=t;i++){
        for(int j=0;j<=t-i;j++){
            for(int k=0;k<=t-i-j;k++){
                for(int l=0;l<=t-i-j-k;l++){
                    for(int m=0;m<=t-i-j-k-l;m++){
                        for(int n=0;n<=t-i-j-k-l-m;n++){
                            if(1*j+2*k+3*l+4*m+5*n == X){
                                cout << "1" << endl;
                                return 0;
                            }
                        }
                    }
                }
            }
        }
    }

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

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const int mod = 1e5;
const int MAX = 1e7;

int main() {
    double r; cin >> r;
    double ans = 2 * r * 3.1415926535897;
    printf("%.10f\n",ans);
}

Measured memory_bytes: 3772
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll N, K; cin >> N >> K;
    ll Z = 0;
    vector<ll> posi, nega;
    for(int i=0; i<N; i++) {
        ll v; cin >> v;
        if(v == 0) Z++;
        else if(v > 0) posi.emplace_back(v);
        else nega.emplace_back(-v);
    }
    sort(posi.begin(), posi.end());
    sort(nega.begin(), nega.end());

    ll ub = LONGINF, lb = -LONGINF;
    while(ub - lb > 1) {
        ll mid = (ub + lb) / 2;
        ll num = 0;
        if(mid >= 0) {
            num += Z * (Z - 1);
            num += 2 * Z * (posi.size() + nega.size());
        }
        for(auto p : posi) {
            if(mid >= 0) {
                num += nega.size();
                ll X = abs(mid) / p;
                int ptr = upper_bound(posi.begin(), posi.end(), X) - posi.begin();
                num += ptr;
            }
            else {
                // nega と掛ける
                // 3 * ? <= -7
                // -3 以下
                ll X = (abs(mid) + p - 1) / p;
                int ptr = lower_bound(nega.begin(), nega.end(), X) - nega.begin();
                num += ((int)nega.size() - ptr);
            }
            if(p * p <= mid) num--;
        }
        for(auto n : nega) {
            if(mid >= 0) {
                num += posi.size();
                ll X = abs(mid) / n;
                int ptr = upper_bound(nega.begin(), nega.end(), X) - nega.begin();
                num += ptr;
            }
            else {
                // posi と掛ける
                ll X = (abs(mid) + n - 1) / n;
                // 1 2 3 4 5
                int ptr = lower_bound(posi.begin(), posi.end(), X) - posi.begin();
                num += ((int)posi.size() - ptr);
            }
            if(n * n <= mid) num--;
        }

        num /= 2;
        // fprintf(stderr, "mid = %lld, num = %lld\n", mid, num);
        if(num < K) lb = mid;
        else ub = mid;
    }
    cout << ub << endl;
    return 0;
}


Measured memory_bytes: 2420
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        n: usize,
        sp_vec: [(String, usize); n],
    }

    let mut bmap: BTreeMap<String, Vec<usize>> = BTreeMap::new();
    
    for sp in sp_vec.clone().into_iter() {
        bmap.entry(sp.0).or_insert(Vec::new()).push(sp.1);
    }
    let mut map: HashMap<String, usize> = HashMap::new();
    
    for (i, sp) in sp_vec.clone().into_iter().enumerate() {
        let k = format!("{}{}", sp.0, sp.1);
        map.insert(k, i);
    }

    for (k, v) in bmap.iter_mut() {
        v.sort();
        v.reverse();
        for vv in v.iter() {
            let k = format!("{}{}", k, vv);
            println!("{}", map.get(&k).unwrap()+1)
        }
    }


    println!("", );
}


Measured memory_bytes: 2180
#include <stdio.h>
#include <math.h>

int N;
bool flag[1001]={};
int num[1001]={};
int a;
int k=0;
long long int ans=1;

int main(){
	scanf("%d",&N);
	if(N==1)ans=1;
	if(N==2)ans=2;
	if(N>=3){
	flag[2]=true;
    for(int i=3;i<=N;i+=2){
		k=0;
		for(int j=3;j<=sqrt((double)i);j+=2){
			if(i%j==0){
				k=1;
				break;
			}
		}
        if(k==0)flag[i]=true;
	}
	for(int i=2;i<=N;i++){
		for(int j=2;j<=N;j++){
			if(flag[j] && i%j==0){
				a=i;
				while(a%j==0){
				    num[j]++;
					a=a/j;
			    }
			}
		}
	}
	for(int i=1;i<=N;i++){
		if(num[i]){
			ans=(ans*(num[i]+1))%1000000007;
		}
	}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define inf 10000
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;

ll divisor=1000000007;

int main(){
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n],b[m];
	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];
	ll sa[n+1]={},bs[m+1]={};
	rep(i,n+1){
		if(i==0)continue;
		sa[i]=sa[i-1]+a[i-1];
	}
	rep(i,m+1){
		if(i==0)continue;
		bs[i]=bs[i-1]+b[i-1];
	}
	ll ans=0;
	ll r=m;
	rep(i,n+1){
		if(sa[i]>k)break;
		if(sa[i]+bs[r]>k){
			r--;
			i--;
			continue;
		}
		ans=max(r+i,ans);
	}
	puts(ans);
}


Measured memory_bytes: 9836
#include<cstdio>
#include<stack>
#include<algorithm>
using namespace std;

int n;

int main(){
    stack<int> s;
    char c;
    while(scanf("%c",&c)!=EOF){
        if(c=='+'){
            int a=s.top();
            s.pop();
            int b=s.top();
            s.pop();
            s.push(a+b);
        }
        if(c=='-'){
            int a=s.top();
            s.pop();
            int b=s.top();
            s.pop();
            s.push(b-a);
        }
        if(c=='*'){
            int a=s.top();
            s.pop();
            int b=s.top();
            s.pop();
            s.push(a*b);
        }
        if(c>='0'&&c<='9'){
            int d=c-'0';
            while(1){
                scanf("%c",&c);
                if(c>='0'&&c<='9')d=d*10+(c-'0');
                else break;
            }
            s.push(d);
        }else scanf("%*c");
    }
    printf("%d\n",s.top());
    return 0;
}


Measured memory_bytes: 2716
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

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

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    ll X;
    cin >> X;

    ll ans = 0;

    ans += (X/500) * 1000;
    ans += ((X%500)/5) * 5;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
int a,b;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	a=read();b=read();
	if(a>b)swap(a,b);
	if((b-a)%2==1){puts("IMPOSSIBLE");return 0;}
	cout<<(a+b)/2;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int v[1000001];
int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int i,j;
        int n=1000000;
        for(i=2; i*i<=n; i++){
            if(v[i]==0){
                for(j=i*i; j<=n; j=j+i){
                    v[j]=1;
                }
            }
        }
        int x;
        cin >> x;
        for(i=x; i<=n; i++){
            if(v[i]==0){
                cout <<i;
                return 0;
            }
        }

}

Measured memory_bytes: 8064
# ABC134
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    A = list(map(int, [input() for _ in range(n)]))
    SA = sorted(A)
    ma, ma2 = SA[-1], SA[-2]
    ans = []
    for i in A:
        if i != ma:
            ans += [ma]
        else:
            ans += [ma2]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

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

int main()
{
	vector<int> P;
	int N; cin>>N;
	int K; cin>>K;

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

	sort(P.begin(),P.end());
    
    int sum=0;
	for(int i=0; i<K; i++){
		sum+=P[i];
	}
	cout<<sum<<endl;
	return 0;

}

Measured memory_bytes: 3604
x,n = map(int, input().split())
l = list(map(int, input().split()))
d = {}
for i in l:
    if i not in d:
        d[i] = 1
left, right = x,x
while left in d and right in d:
    left -= 1
    right += 1
print(left if left not in d else right)

Measured memory_bytes: 61848
def pre_order(id)
  return if id == -1

  left, right = @nodes[id]

  [id, pre_order(left), pre_order(right)].flatten.compact
end

def in_order(id)
  return if id == -1

  left, right = @nodes[id]

  [in_order(left), id, in_order(right)].flatten.compact
end

def post_order(id)
  return if id == -1

  left, right = @nodes[id]

  [post_order(left), post_order(right), id].flatten.compact
end

def find_root
  @nodes.keys.each do |k|
    if !@parents[k]
      return k
    end
  end

  raise
end

@n = gets.chomp.to_i
@nodes = Hash.new{|k, v| k[v] = []}
@parents = {}
@n.times do
  id, left, right = gets.chomp.split.map(&:to_i)

  @nodes[id] << left
  @parents[left] = id

  @nodes[id] << right
  @parents[right] = id
end

puts "Preorder"
puts " #{pre_order(find_root).map(&:to_s).join(' ')}"

puts "Inorder"
puts " #{in_order(find_root).map(&:to_s).join(' ')}"

puts "Postorder"
puts " #{post_order(find_root).map(&:to_s).join(' ')}"



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

int main(){
    long long n,k;
    cin>>n>>k;
    long long bef,aft;
    long long temp=n/k;
    bef=n-temp*k;
    aft=(temp+1)*k-n;
    cout<<min(abs(bef),abs(aft))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    vector< vector < vector <int> > > a(4,vector< vector <int> >(3,vector<int>(10)));
    int n;
    cin >> n;
    while(n--)
    {
        int b,f,r,v;
        cin >> b >> f >> r >> v;
        a[b-1][f-1][r-1] +=v;
    }
    for(int i = 0; i < 4; i++)
    {
        for(int j=0 ; j<3; j++)
        {
            for(int k=0;k<10; k++)
            {
                cout << ' ' << a[i][j][k];

            }
            cout << endl;
        }
        if(i+1 < 4)
        {
            cout << "####################" << endl;
        }
    }


    return 0;

}

Measured memory_bytes: 1216
#include<stdio.h>
int main(void)
{
	int n,q;
	int s[100000]={0},t[50000]={0};
	int i;
	int cnt=0;
	int min,max,mid,tar;
	
	//min=0;
	//max=n-1;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&s[i]);
	}
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&t[i]);
	}
	
	for(i=0;i<q;i++){
		tar=t[i];
		min=0;
		max=n-1;
		while(min<=max){
			mid=(min+max)/2;
			if(s[mid]==t[i]){
				cnt++;
				break;
			}else if(s[mid]<t[i]){
				min=mid+1;
			}else if(s[mid]>t[i]){
				max=mid-1;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2384
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ui32 = unsigned int;
constexpr ll INFLL = 1e18;

#define CHECK_IMPL1(cond)              \
if (!(cond)) {                         \
    DEBUG("expected cond: " << #cond); \
    assert(cond);                      \
}

#define CHECK_IMPL2(cond, message)                                            \
if (!(cond)) {                                                                \
    DEBUG("expected cond: " << #cond << " failed with message: " << message); \
    assert(cond);                                                             \
}
#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << std::endl;
#else
#define DEBUG(message)
#endif

void solve() {
  int n, m;
  cin >> n >> m;

  vector<vector<char>> f(n, vector<char>(m));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> f[i][j];
    }
  }

  int x = 0, y = 0;
  while (x + 1 < n || y + 1 < m) {
    f[x][y] = '.';
    if (x + 1 < n && f[x + 1][y] == '#') {
      ++x;
    } else if (f[x][y + 1] == '#') {
      ++y;
    } else {
      cout << "Impossible\n";
      return;
    }
  }
  f[x][y] = '.';

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (f[i][j] == '#') {
        cout << "Impossible\n";
        return;
      }
    }
  }

  cout << "Possible\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef __APPLE__
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  int t = 1;
//  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 256