akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define maxN 302
#define mod 1000000007
using namespace std;

//FILE *fin = freopen("e.in", "r", stdin);

/* ---------------- */
int n, m;
/* ---------------- */
struct Cond
{
    int l, nrC;
};
vector < Cond > cond[maxN];
int dp[maxN][maxN][maxN];
/* ---------------- */
int ans;

void Mod(int &val)
{
    if (val >= mod)
        val -= mod;
}

void comp(int l0, int l1, int l2)
{
    int i = max(l0, max(l1, l2)) + 1;
    bool valid = 1, valid1 = 1, valid2 = 1;
    for (Cond x : cond[i])
    {
        if (valid)
            valid = (1 + (l1 >= x.l) + (l2 >= x.l)) == x.nrC;
        if (valid1)
            valid1 = (1 + (l0 >= x.l) + (l2 >= x.l)) == x.nrC;
        if (valid2)
            valid2 = (1 + (l1 >= x.l) + (l0 >= x.l)) == x.nrC;
    }
    if (valid)
    {
        dp[i][l1][l2] += dp[l0][l1][l2];
        Mod(dp[i][l1][l2]);
    }
    if (valid1)
    {
        dp[l0][i][l2] += dp[l0][l1][l2];
        Mod(dp[l0][i][l2]);
    }
    if (valid2)
    {
        dp[l0][l1][i] += dp[l0][l1][l2];
        Mod(dp[l0][l1][i]);
    }
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; ++ i)
    {
        int l, r, nr;
        scanf("%d %d %d", &l, &r, &nr);
        cond[r].push_back({l, nr});
    }

    for (Cond x : cond[1])
        if (x.nrC > 1 || x.l != 1)
        {
            printf("0\n");
            return 0;
        }

    dp[1][0][0] = dp[0][1][0] = dp[0][0][1] = 1;
    for (int l0 = 1; l0 < n; ++ l0)
        for (int l1 = 0; l1 < l0; ++ l1)
            for (int l2 = 0; l2 < l0; ++ l2)
                if (l1 != l2 || l1 == 0)
                {
                    comp(l0, l1, l2);
                    comp(l1, l0, l2);
                    comp(l1, l2, l0);
                }

    for (int l1 = 0; l1 < n; ++ l1)
        for (int l2 = 0; l2 < n; ++ l2)
            if (l1 != l2 || l1 == 0)
            {
                ans += dp[n][l1][l2];
                Mod(ans);
                ans += dp[l1][n][l2];
                Mod(ans);
                ans += dp[l1][l2][n];
                Mod(ans);
            }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 107520
#include <bits/stdc++.h>
using namespace std;
int mem[26];
int main() {
  string S; cin >> S;
  for(char c:S) ++mem[c-'a'];
  for(int i=0; i<26; ++i) {
    if(mem[i] > 1) {
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  return 0;
}


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

typedef pair <int, int> ii;

const int Maxn = 2005;

int n, k, q;
int a[Maxn];
ii seq[Maxn];
bool tk[Maxn];
int res = 2000000007;

int getBest()
{
	vector <int> cur;
	vector <int> tot;
	for (int i = 0; i < n; i++)
		if (tk[i]) {
			sort(cur.begin(), cur.end());
			for (int j = 0; j + k <= cur.size(); j++)
				tot.push_back(cur[j]);
			cur.clear();
		} else cur.push_back(a[i]);
	sort(cur.begin(), cur.end());
	for (int j = 0; j + k <= cur.size(); j++)
		tot.push_back(cur[j]);
	sort(tot.begin(), tot.end());
	if (tot.size() < q) return -1;
	return tot[q - 1];
}

int main()
{
	scanf("%d %d %d", &n, &k, &q);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		seq[i] = ii(a[i], i);
	}
	sort(seq, seq + n);
	for (int i = 0; i + q <= n; i++) {
		int best = getBest();
		if (best == -1) break;
		res = min(res, best - seq[i].first);
		tk[seq[i].second] = true;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
from functools import reduce
n = int(input())
d = (int(s) for s in input().split())
if next(d) != 0:
    print(0)
    quit(0)
c = Counter(d)
if c[0] != 0:
    print(0)
    quit(0)
print(reduce(lambda x, y: x * y, (c[k - 1] ** x if k > 1 else 1 for k, x in c.items()), 1) % 998244353)




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

int main(){
  long long N, T[5], m = 1e18;
  cin >> N;
  for(int i = 0; i < 5; ++i) cin >> T[i], m = min(m,T[i]);
  long long t = (N+m-1)/m;
  cout << t+4 << endl;
}


Measured memory_bytes: 256
import itertools
import sys
import math
import numpy as np
from collections import deque
from itertools import combinations
from functools import lru_cache
sys.setrecursionlimit(10**9)


def main():
    N,K = map(int,input().split())
    H = list(map(int,input().split()))
    H_sorted = sorted(H)

    target_count = len(H) - K
    sum = 0
    for i in range(target_count):
        sum += H_sorted[i]

    print(sum )


if __name__ == "__main__":
  main()


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

using namespace std;

int main()
{
    int a,b;
    int m1,m2,m3,ans;
    cin>>a>>b;
    m1=a+b;
    m2=a-b;
    m3=a*b;
    ans=max(m1,m2);
    ans=max(ans,m3);
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 256
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 4e5 + 5;
const long long MNN = 2e3 + 200;
const long long MOD = 10;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n, m;
int p[MNN];
int ans = OO;
vector<int> v;
vector<int> q[MNN];

int main(){
    ios;
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        q[u].pb(v);
    }
    for(int i = 1; i <= m; i++){
        for(int i = 1; i <= n; i++){
            p[i] = 0;
        }
        queue<int> lol;
        for(int j = 0; j < q[i].size(); j++){
            p[q[i][j]] = i;
            lol.push(q[i][j]);
        }
        while(!lol.empty()){
            int x = lol.front();
            lol.pop();
            if(x == i){
                vector<int> t;
                while(p[x] != i){
                    t.pb(p[x]);
                    x = p[x];
                }
                t.pb(i);
                if(t.size() < ans){
                    ans = t.size();
                    v = t;
                }
            }
            for(int j = 0; j < q[x].size(); j++){
                int to = q[x][j];
                if(p[to] == 0){
                    p[to] = x;
                    lol.push(to);
                }
            }
        }
    }
    if(ans == OO) return cout << -1, 0;
    cout << ans << nl;
    for(int i = 0; i < v.size(); i++){
        cout << v[i] << nl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,n,d[123456];
	cin>>n;
	for(int i=0;i<n;i++)cin>>d[i];
	sort(d,d+n);
	a=d[n/2]-d[n/2-1];
	cout<<a<<endl;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
string s;
int k=1;
int par[100100];
int val[100100];
vector<int> child[100100];
int rec(int v){
	if(val[v]!=0){
		return (val[v]+1)/2;
	}
	vector<int> vec;
	for(int i=0;i<child[v].size();i++){
		vec.pb(rec(child[v][i]));
	}
	sort(all(vec));
	int res = 0;
	for(int i=0;i<((int)vec.size()+1)/2;i++){
		res += vec[i];
	}
	return res;
}
void init(){
	k=1;
	memset(par,-1,sizeof(par));
	memset(val,0,sizeof(val));
	for(int i=0;i<100100;i++)child[i].clear();
}
void solve(){
	string s;
	cin >> s;
	init();
	int cur = 0;
	par[0]=-1;
	for(int i=0;i<s.size();i++){
		if(s[i]=='['){
			par[k]=cur;
			child[cur].pb(k);
			cur = k;
			k++;
		}else if(s[i]==']'){
			cur = par[cur];
		}else{
			val[cur]=(val[cur]*10+(s[i]-'0'));
		}
	}
	assert(cur==0);
	cout << rec(0) << endl;
}
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++)solve();
	return 0;
}


Measured memory_bytes: 6452
class Dice
 
  def initialize (a, b, c, d, e, f)
  @dice = [a, b, c, d, e, f]
 end 

  def move(command)
    if(command == "E") 
      @dice[0], @dice[3], @dice[5], @dice[2] = @dice[3], @dice[5], @dice[2], @dice[0]
    elsif(command == "N") 
      @dice[0], @dice[1], @dice[5], @dice[4] = @dice[1], @dice[5], @dice[4], @dice[0]
    elsif(command == "S") 
      @dice[0], @dice[1], @dice[5], @dice[4] = @dice[4], @dice[0], @dice[1], @dice[5]
    elsif(command == "W") 
      @dice[0], @dice[3], @dice[5], @dice[2] = @dice[2], @dice[0], @dice[3], @dice[5]
    end
  end

  def top
    printf "%d\n", @dice[0]
  end
end

a, b, c, d, e, f = gets.split.map{|s| s.to_i}
dice = Dice.new(a, b, c, d, e, f)
commands = gets.chomp.split("")
commands.each {|command|
  dice.move(command)
}
dice.top


Measured memory_bytes: 8916
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int n;
    cin >> n;
    if(n % 2 == 0)
        cout << n;
    else
        cout << n * 2;
    return 0;
}

Measured memory_bytes: 256
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    

const int N = 2e5 + 10;

vi g[N];
vi dp, a, ans;

void dfs(int v, int p = -1){
    int idx = lower_bound(all(dp), a[v]) - dp.begin();
    int temp = dp[idx];
    dp[idx] = a[v];
    ans[v] = lower_bound(dp.begin(), dp.end(), 2e9) - dp.begin();

    for(auto c : g[v])
        if(c != p)
            dfs(c, v);

    dp[idx] = temp;
}


int main(){
   IOS

   int n; cin>>n;

   a.resize(n);
   for(int &x : a)cin>>x;

   dp.resize(n, 2e9); ans.resize(n, 0);

   for(int i = 0; i < n-1; i++){
       int u, v; cin>>u>>v; u--, v--;
       g[u].pb(v); g[v].pb(u);
   }

   dfs(0);

   for(int i : ans)cout<<i<<"\n";


}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 27964
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> A;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        A.push_back(a);
    }
    for(int i=0;i<n;i++){
        cout<<A[i]<<((i==n-1)?"":" ");
    }
    cout<<endl;
    for(int i=1;i<n;i++){
        int key=A[i];
        int j;
        for(j=i-1;j>=0&&A[j]>key;j--){
            A[j+1]=A[j];
        }
        A[j+1]=key;
        for(int k=0;k<n;k++){
            cout<<A[k]<<((k==n-1)?"":" ");
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3140
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int sum = r*100+g*10+b;
        if(sum%4 == 0) System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 25172
#include<stdio.h>

int main(){
	int h,w,i,j;
	while(scanf("%d %d",&h,&w),h!=0 && w!=0){
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(i==0 || i==h-1 || j==0 || j==w-1)
				printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 1924
#include<bits/stdc++.h>
using namespace std;
const int INF = 1000*1000*1000;
const int MOD = 1000000007;

int main(){

    //cout << "a" << endl;
    int n, K; cin >> n >> K;
    vector<long long> a(n + 1);
    for(int i = 0; i < n; i++) cin >> a[i + 1];

    long long f[110];      //階乗！
    f[0] = 1;
    f[1] = 1;

    for(int i = 2; i < 110; i++){
        (f[i] = i * f[i - 1]) %= MOD;
    }

    //cout << f[4] << endl;

    long long dp[102][257][102] = {};                 //dp[i][j][k] := i番目までを使って 値がjになるとき（aからk個つかっている）の組み合わせ
    dp[0][0][0] = 1;
    //cout << "ok" << endl;

    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 257; j++){
            for(int k = 0; k <= n; k++){

                //cout << i << " " << j << " " << k << endl;

                //選ばない
                (dp[i][j][k] += dp[i-1][j][k] )%= MOD;

                //if(i == 3) cout << j << " " (j^a[i]) << " " << endl;
                //選ぶ
                if(k) (dp[i][j][k] += dp[i-1][j^a[i]][k-1]) %= MOD;


                //cout << i << " " << j << " " << k << endl;
                
            }
        }
    }

    //cout << "ok" << endl;

    long long ans = 0;
    for(int i = 0; i <= n; i++){
        //cout << dp[n][K][i] << endl;
        (ans += (dp[n][K][i] * f[i])) %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 21120
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func r() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := r()

	a := make(map[int]int, n)
	for i := 0; i < n; i++ {
		x := r()
		if _, ok := a[x]; !ok {
			a[x] = 1
		} else {
			a[x]++
		}
	}
	var ans int
	for _, v := range a {
		if v%2 != 0 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3584
#include <stdio.h>

int main(void)
{
	unsigned char table[256];
	char c[2];
	int n, m;
	
	while (1){
		for (int i = 0; i < 256; i++){
			table[i] = i;
		}
		
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		for (int i = 0; i < n; i++){
			char c1[2], c2[2];
			scanf("%s%s", c1, c2);
			
			table[c1[0]] = c2[0];
		}
		scanf("%d", &m);
		for (int i = 0; i < m; i++){
			scanf("%s", c);
			
			printf("%c", table[c[0]]);
		}
		
		puts("");
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
#define for1(i, n) for (ll i = 1; i <= n; ++i)
#define for0(i, n) for (ll i = 0; i < n; ++i)
#define vll vector<ll>
#define fast std::ios_base::sync_with_stdio(false);
#define ll long long int
#define etc \
  ll t;     \
  cin >> t; \
  while (t--) solve();
#define ntc solve();
#define pb push_back
#define mp make_pair
 
void solve() {
  
  ll n,k;
  cin>>n>>k;
  
  ll arr[n];
  
  for0(i,n)
  cin>>arr[i];
  
  sort(arr,arr+n);
  
  if(k>=n)
  {
  	cout<<0;
  	return;
  }
  
  ll ans=0;
  for0(i,n-k)
  ans+=arr[i];
  
  cout<<ans;
}
 
int main() { fast ntc return 0; }

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=1E5+7;
struct stu{
    double a,b;
    bool friend operator <(const stu &x,const stu &y){
        return atan2(x.b,x.a)<atan2(y.b,y.a);
    }
}arr[N];
int nxt[N];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)    cin>>arr[i].a>>arr[i].b;    
    for(int i=1;i<=n;i++) nxt[i]=i+1;
    nxt[n]=1;
    sort(arr+1,arr+1+n);
    double ans=0;
    for(int i=1;i<=n;i++){
        double dx=arr[i].a;
        double dy=arr[i].b;
        ans=max(ans,arr[i].a*arr[i].a+arr[i].b*arr[i].b);
        
        for(int j=nxt[i];j!=i;j=nxt[j]){
            dx+=arr[j].a;
            dy+=arr[j].b;
            ans=max(ans,dx*dx+dy*dy);
        }
    }
    printf("%.15lf\n",sqrt(ans));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
int MOD;
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}

void radd(int &a, int b)
{
	a=add(a,b); return ;
}
	
int dp[5011][5011];
int dt[5011];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n>>MOD;
	dp[0][0]=1;
	dt[1]=1;
	int l=2; int r=n-1; int cur=2;
	for(;l<=r;l++,r--)
	{
		dt[l]=dt[r]=cur; cur++;
	}
	for(int i=1;i<=n-1;i++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int k=0;k*dt[i]<=j;k++)
			{
				radd(dp[i][j],dp[i-1][j-k*dt[i]]);
			}
		}
	}
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		radd(ans,mult(dp[n-1][i],n-i));
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 98176
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,x,y,i,s,u,md,f[N];
char c[N];
vector<int>e[N];
int dfs(int x,int fa){
	int ret=0,deg=fa>0;
	if(c[x]=='W')ret=1;
	for(int y:e[x])if(y!=fa && dfs(y,x))ret=1,s+=2,deg++;
	if(ret)s+=f[x]=(deg&1)!=(c[x]=='W'),f[x]=f[x]?2:0;else f[x]=-1;
	return ret;
}
void dfss(int x,int fa,int d){
	d+=f[x];if(d>=md)md=d,u=x;
	for(int y:e[x])if(y!=fa && f[y]!=-1)dfss(y,x,d);
}
int main(){
	scanf("%d",&n);
	for(i=1;i<n;++i)scanf("%d%d",&x,&y),e[x].push_back(y),e[y].push_back(x);
	scanf("%s",c+1);
	for(i=1;i<=n;++i)if(c[i]=='W')break;
	if(i>n){puts("0");return 0;}
	dfs(i,0);md=-N;dfss(i,0,0);md=-N;dfss(u,0,0);
	printf("%d\n",s>1?s-md:1);
	return 0;
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 998244353
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pll a, pll b)//true for a before b
{
	if(a.F*b.S < b.F*a.S)
		return 1;
	if(a.F*b.S > b.F*a.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (1e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;
const int SQRT = BUCK+9;



void solve()
{
	long long a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k % 2LL == 0LL)
		cout << (a-b) << '\n';
	else
		cout << (b-a) << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file; fffff
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool a[10];
int main(){
    int t;
    for(int i=0;i<4;++i){
        cin >> t; a[t] = true;
    }
    if(a[1]&&a[9]&&a[7]&&a[4]) cout<<"YES";
    else cout<<"NO";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

// string rotation...

inline void solve(){
    string str;
    cin>>str;
    int s=0,n=0,e=0,w=0;
    int len=sz(str) ; 
    for (int i=0;i<len;i++){
        if (str[i]=='N') n++;
        if (str[i]=='S') s++;
        if (str[i]=='E') e++;
        if (str[i]=='W') w++;
    }
    if ((s && !n) || (!s && n) || (e && !w) || (!e && w)) cout << "No" << endl;
    else cout << "Yes" << endl;
    
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n,W;
    map<int,Vi> ma;
    cin>>n>>W;
    Vi w(n),v(n);
    vin(w,v);
    int wmin=*min_element(ALL(w));
    VVi wa(4);
    REP(i,0,n){
        wa[w[i]-wmin].pb(v[i]);
    }
    REP(i,0,4){
        sort(ALL(wa[i]),greater<int>());
        wa[i].insert(wa[i].begin(),0);
    }
    REP(i,0,4){
        REP(j,1,wa[i].size()){
            wa[i][j]+=wa[i][j-1];
        }
    }
    
    int ans=0;
    REP(i,0,wa[0].size()){
        REP(j,0,wa[1].size()){
            REP(k,0,wa[2].size()){
                REP(l,0,wa[3].size()){
                    if((i+j+k+l)*wmin+j+2*k+3*l<=W) chmax(ans,wa[0][i]+wa[1][j]+wa[2][k]+wa[3][l]);
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define min(a, b) ((a)<(b)?(a):(b))
#define max(a, b) ((a)>(b)?(a):(b))
long long d[2100];
long long n, i;

int main(){
    for(i = 0;i <= 2000;i++){
	d[i] = min(1000, i - 0) - max(0, i - 1000) + 1;
    }
    while(scanf("%lld", &n) != EOF){
	long long res = 0;
	for(i = 0;i <= min(n, 2000);i++){
	    int p = n - i;
	    if(p > 2000)continue;
	    res += d[i] * d[p];
	}
	printf("%lld\n", res);
    }
    return 0;
}

Measured memory_bytes: 612
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

int st[30][100000];
ll dp[52][2510];
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int B[30];
int t[100010];
struct edge {
	int t;
	ll cost;
	edge(int _t,ll _cost) : t(_t)
							, cost(_cost){
	}
};
int table[15][15];
ll h;

bool use[15];
int ct[15];
bool memo[15][15][15];
string format(int val){
	ostringstream sout;
	sout << std::setfill('0') << setw(2) << val;
	return sout.str();
}
int ng[3];
bool check(int nm) {
	if (ng[0] == nm || ng[2] == nm || ng[1] == nm) return false;
	return true;
}
int f(int v) {
	if (v % 2 == 0) {
		return v / 2;
	}else return 3 * v + 1;
}
void Solve() {

	int s;
	cin >> s;
	map<int, int> m;
	int a = s;
	m[a] = 1;
	int i = 1;
	while (true)
	{
		i++;
		int nx = f(a);
		m[nx]++;
		if (m[nx] > 1) {
			cout << i << endl;
			return;
		}
		a = nx;
	} 


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



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

double calc(double a, double b){
  return sqrt(a * a - b * b);
}

main(){
  double a, l, x, h, ans;
  while(cin >> a >> l >> x){
    h = calc(l, a / 2);
    ans = a * h / 2;
    h = calc((l + x) / 2, l / 2);
    ans += l * h;
    printf("%.10f\n", ans);
  }
}

Measured memory_bytes: 1240
#include<iostream>
#include<string>
#include<stdio.h>
int main() {

	char a[12];
	int count = 1000;
	int year = 0;
	int month = 0;
	int day = 0;
	std::cin >> a;



		for (int i = 0; i < 4; i++) {
			year += ((a[i] - '0') * count);
			count /= 10;
		}
		count = 10;
		for (int i = 5; i < 7; i++) {
			month += (a[i] - '0') * count;
			
			count /= 10;
		}
		count = 10;
		for (int i = 8; i < 10; i++) {
			day += (a[i] - '0') * count;
			//std::cout << (a[i] - '0') << std::endl;
			count /= 10;
		}

	//	std::cout << year << " : " << month << " : " << day << std::endl;
		if (year < 2019) {
			std::cout << "Heisei" << std::endl;
		}
		else if (year == 2019 && month < 4) {
			std::cout << "Heisei" << std::endl;
		}
		else if (year == 2019 && month == 4 && day <= 30) {
			std::cout << "Heisei" << std::endl;
		}
		else {
			std::cout << "TBD" << std::endl;
		}


	//std::cin.get();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n,m=0,i,j,k,l,a,b,d,e,f;
    char c[500009];
    scanf("%s",&c);
    l=0;
    n=strlen(c);
    for(i=0;i<n;i++){
                j=i;
            while(j<n-1 && c[j]==c[j+1])
            j++;
        if(c[i]=='>'){
            a=j-i;
            d=a;
            a=(a*(a+1))/2;
            m+=a;
            k=i-1;
            while(k>0 && c[k]==c[k-1])
                k--;
            if(k<0)
                k=0;
            else
                k=i-k;
                if(k>0)
                    k--;
                e=k;
                //k=(k*(k+1))/2;
                f=max(e,d);
                //m+=k;
                m+=f;
                m++;

        }
        else{
            a=j-i;
            d=a;
            a=(a*(a+1))/2;
            m+=a;
            if(j==n-1)
                m+=d+1;
        }
        //printf("%d %d\n",m,i);
        i=j;
    }
    printf("%lld\n",m);
}


Measured memory_bytes: 768
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(BufferedReader in) throws IOException {
        int N = Integer.parseInt(in.readLine());
        long[] A = new long[N];
        long[] B = new long[N];
        for (int i = 0; i < N; ++i) {
            String[] s = in.readLine().split(" ");
            A[i] = Long.parseLong(s[0]);
            B[i] = Long.parseLong(s[1]);
        }

        long ans = 0;
        for (int i = N - 1; i >= 0; --i) {
            A[i] += ans;
            long r = A[i] % B[i];
            if (r > 0) {
                ans += B[i] - r;
            }
        }
        _out.println(ans);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) throws IOException {
        long S = System.currentTimeMillis();

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        new Main().solve(in);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 48400
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int n,m;
Graph G(1000000);
int memo[1000000];
int dp(int v){
  if(memo[v] != -1)return memo[v];
  int res = 0;
  for(auto i : G[v])res = max(res,dp(i));
  return memo[v] = res + 1;
}
int main(){
  rep(i,1000000)memo[i] = -1;
  cin >> n >> m;
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--,b--;
    G[a].push_back(b);
  }
  int ans = 0;
  rep(i,n)ans = max(ans,dp(i));
  cout << ans - 1 << endl;
  return 0;
}


Measured memory_bytes: 32768
import java.util.*;
public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int p=sc.nextInt();
    int n=sc.nextInt();
    int[] a=new int[n];
	for(int i=0;i<n;i++)
    {
	a[i]=sc.nextInt();
    }        
      Arrays.sort(a);

    int min=a[a.length-1]-a[0];

    for(int i=1;i<a.length;i++)
    {
      int sum=p-(a[i]-a[i-1]);
      if(sum<min)
      {
        min=sum;
      }
    }
    System.out.println(min);
    
  }
}


Measured memory_bytes: 66748
n=int(input())
a=list(map(int,input().split()))
b=[0 for i in range(n)]
c=0
d=[]
for i in range(n-1,-1,-1):
  j=2
  c=b[i]
  while((i+1)*j<=n):
    c=c^b[(i+1)*j-1]
    j+=1
  if (c!=a[i]):
    b[i]=1
  c=0
  j=2
print('{0}'.format(sum(b)))
for i in range(n):
  if(b[i]==1):
    d.append(i+1)
e=list(map(str,d))
f=' '.join(e)
print('{0}'.format(f))

Measured memory_bytes: 22324
#include <iostream>
#include <list>
#include <string>

using namespace std;
int main(){
    int n;
    cin>>n;
    string com;
    int num;
    list <int>a;
    for(int i=0;i<n;i++){
        cin>>com;
        if(com=="insert"){
            cin>>num;
            a.push_front(num);
        }else if(com=="delete"){
            cin>>num;
            for(list<int>::iterator it=a.begin(); it!=a.end();it++){
                if(*it == num){
                    a.erase(it);
                    break;
                }
            }
        }else if(com=="deleteFirst"){
            a.pop_front();
        }else if(com=="deleteLast"){
            a.pop_back();
        }
    }
    int i =0;
    for(list<int>::iterator it=a.begin(); it!=a.end(); it++){
        if(i++) cout << " ";
        cout << *it;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 34416
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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 ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N, W; cin >> N >> W;
  vector<ll> weight(N), value(N);
  rep(i, N) cin >> weight[i] >> value[i];

  vector<vector<ll>> dp(N + 10, vector<ll>(100010, INF));
  rep(i, N) dp[i][0] = 0;

  for (int i = 0; i < N; ++i){
    for (int j = 0; j <= 100000; ++j){
      chmin(dp[i + 1][j], dp[i][j]);
      if (j - value[i] >= 0) chmin(dp[i + 1][j], dp[i][j - value[i]] + weight[i]);
    }
  }
  int res = 0;
  for (int j = 0; j <= 100000; ++j){
    if (dp[N][j] <= W) res = j;
  }
  cout << res << endl;
}


Measured memory_bytes: 87296
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define NUM_MAX 2000
#define LEN_MAX 1000
#define NUM2_MAX (NUM_MAX*(NUM_MAX-1)/2)
#define BUF_SIZE (NUM_MAX*5+100)

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}


// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

int asc(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int lower_bound(int *arr, int size, int key) {
    int low = -1;
    int high = size;
    while(low + 1 < high) {
        int middle = (low+high)/2;
        if(arr[middle] > key) {
            high = middle;
        } else {
            low = middle;
        }
    }
    return high;
}

int main(void) {
    int num = get_int();
    int arr[NUM_MAX];

    fget_array(arr, num);
    qsort(arr, num, sizeof(int), asc);
    int i, j;

    int cnt = 0;
    // In this time, len<=1000 is very small, so it's enough to use map
    static int map[LEN_MAX*2+1];
    for(i = 2; i < num; i++) {
        int pivot = arr[i];
        for(j = 0; j < i-1; j++) {
            map[arr[i-1] + arr[j]]++;
        }
        // a < b+c (s.t. a>b>c)
        for(j = pivot+1; j <= LEN_MAX*2; j++) {
            cnt += map[j];
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 252
_, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    if k < sum(map(lambda a: (a-1)//m, A)): ng = m
    else: ok = m
print(ok)


Measured memory_bytes: 30796
#include<iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll cost[105][2];    //cost[][0] - represents weight 
ll dp[105][1000005];      //cost[][1] - represents val  
ll n,W,maxc;
ll fun(ll i, ll w)
{ 
    if(i==n || w>W)
     return 0;
   if(dp[i][w]!=-1)
      return dp[i][w];
   
   
   if(w+cost[i][0]>W)
     return fun(i+1,w);
    else
    {
        return dp[i][w]=max(fun(i+1,w),fun(i+1,w+cost[i][0])  + cost[i][1]);
    }
    
     
}


int main()
{
    
    memset(dp,-1,sizeof(dp));
    cin>>n>>W;
    
    for(ll i=0;i<n;i++)    
      cin>>cost[i][0]>>cost[i][1];
      
    maxc=fun(0,0); 
    
    cout<<maxc<<"\n"; 
    
    return 0;
}

Measured memory_bytes: 820608
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

use std::cmp::max;
use std::cmp::min;
fn main() {
    let v : Vec<i32> = get_vec();
    println!("{}", max(0, max(v[1],v[2]) - (min(v[1],v[2]) + v[0])))
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

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

		System.out.println(String.valueOf(s.charAt(0)) + (s.length() - 2) + String.valueOf(s.charAt(s.length() - 1)));

		sc.close();

	}

}

Measured memory_bytes: 39380
// i hope i get better                                                           
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=2e5+9;
int n,a[sz];
int cnt[sz];
ll ans;

int main(){
	cin>>n;
	for(int i=0; i < n; ++i){
		cin>>a[i];
		ans+=cnt[a[i]];
		cnt[a[i]]++;
	}
	for(int i=0; i < n; ++i){
		cout<<ans-cnt[a[i]]+1<<'\n';
	}
    return 0;
}

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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r)
{
	if (l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve()
{
	pos = 0;
	rec(0, pre.size());
	for (int i = 0; i < post.size(); i++){
		if (i) printf(" ");
		printf("%d", post[i]);
	}
	puts("");
}

int main()
{
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++){
		int k;
		scanf("%d", &k);
		pre.push_back(k);
	}
	
	for (int i = 0; i < n; i++){
		int k;
		scanf("%d", &k);
		in.push_back(k);
	}
	
	solve();
	
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
int a[301][301]={0};
int main()
{
    int nplayed[301]={0};
    int counter[301]={0};
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
            cin>>a[i][j];
    }
    int ans=INT_MAX;
    for(int i=0;i<m;i++)
    {
        int freq[301]={0};
        for(int j=0;j<n;j++)
        {
            freq[a[j][counter[j]]]++;
        }
        int max1=0,pos=0;
        for(int j=0;j<=m;j++)
        {
            if(freq[j]>=max1)
            {
                max1=freq[j];
                pos=j;
            }
        }
        ans=min(ans,max1);
        nplayed[pos]=1;
        //cout<<pos<<"\n";
        int flag=0;
        for(int j=0;j<n;j++)
        {
            while(nplayed[a[j][counter[j]]]==1&&counter[j]<m)
                counter[j]++;
            //cout<<j<<counter[j]<<"\n";
            if(counter[j]==m)
            {
                flag=1;
                break;
            }
        }
        if(flag==1)
            break;
    }
    cout<<ans<<"\n";
    return 0;
}



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

using namespace std;

char a[1005][1005];

int main(){
	int m, n, res = 0;
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
		cin >> a[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			res = 0;
			if(a[i][j] == '#'){
				cout << '#';
				continue;
			}
			if(a[i][j + 1] == '#') res++;
			if(a[i][j - 1] == '#') res++;
			if(a[i + 1][j] == '#') res++;
			if(a[i - 1][j] == '#') res++;
			if(a[i + 1][j + 1] == '#') res++;
			if(a[i - 1][j - 1] == '#') res++;
			if(a[i + 1][j - 1] == '#') res++;
			if(a[i - 1][j + 1] == '#') res++;
				cout << res;
		}
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
def examA():
    N = I()
    ans = N + N**2 + N**3
    print(ans)
    return

def examB():
    S = SI()
    T = SI()
    ans = 0
    for s,t in zip(S,T):
        if s!=t:
            ans += 1
    print(ans)
    return

def examC():
    N, M, K = LI()
    A = LI()
    B = LI()
    SA = 0
    b = 0
    SB = 0
    for i in range(M):
        if SB+B[i]>K:
            break
        SB += B[i]
        b += 1
    #print(b,SB)
    ans = 0
    ans = max(ans,b)
    for i in range(N):
        SA += A[i]
        if SA+SB>K:
            while(b>=0):
                if SA+SB<=K:
                    break
                SB -= B[b-1]
                b -= 1
        if b==-1:
            break
        #print(i,b,SA,SB)

        ans = max(ans,b+i+1)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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

int main()
{
	using P = pair<int,int>;
	string s;
	cin >> s;
	s.push_back('T');
	int x,y;
	cin >> x >> y;
	vector<P> mv;
	bool tate = false;
	int n = s.size();
	int l = 0;
	for(int i = 0;i<n;i++)
	{
		if(s[i]=='T')
		{
			mv.emplace_back(tate,l);
			tate = !tate;
			l=0;
		}
		else
		{
			l++;
		}
	}


	x += 8000;
	y += 8000;
	
	vector<bool> dpx(16001),dpy(16001);
	n = mv.size();
	dpx[mv[0].second+8000]=1;
	dpy[8000]=1;
	//for(auto i:mv)cout << i.first << ' ' << i.second << endl;
	for(int i = 1;i<n;i++)
	{
		auto tmp = vector<bool>(16001,false);
		if(mv[i].first)
		{
			for(int j = 0;j<16001;j++)
			{
				if(dpy[j])
				{
					tmp[j-mv[i].second]=true;
					tmp[j+mv[i].second]=true;
				}
			}
			dpy = tmp;
		}
		else
		{
			for(int j = 0;j<16001;j++)
			{
				if(dpx[j])
				{
					tmp[j-mv[i].second]=true;
					tmp[j+mv[i].second]=true;
				}
			}
			dpx = tmp;
		}
	}
	if(dpx[x]&&dpy[y])cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3676
#include <iostream>

int main(void)
{
  const int kLoan = 100000;
  const double kInterestRate = 0.05;

  int n;
  std::cin >> n;

  int total = kLoan;
  for (int i = 0; i < n; i++) {
    total += kInterestRate * total;
    int mod = total % 1000;
    if (mod != 0) {
      total += 1000 - mod;
    }
  }

  std::cout << total << '\n';
  return 0;
}

Measured memory_bytes: 3072
import java.util.*;

public class Main {

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

        int n = sc.nextInt();

        Integer array[] = new Integer[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        Arrays.sort(array, Collections.reverseOrder());

        long ans = 0;

        for (int i = 0; i < n; i++) {
            if (i == 0)  continue;

            ans += array[i/2];

        }

        System.out.println(ans);

        sc.close();

    }

}

Measured memory_bytes: 63152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n;
	while(scanf("%d",&n)&&n){
		bool f=false;
		int num[1000];
		int P[1000];
		int Q[1000];
		int R[1000];
		for(int i=0;i<n;i++){
			int a,b,c,d;
			scanf("%d%d%d%d",&num[i],&P[i],&Q[i],&R[i]);
		}
		int p,q,r,c;
		scanf("%d%d%d%d",&p,&q,&r,&c);
		for(int i=0;i<n;i++){
			if(P[i]<=p&&Q[i]<=q&&R[i]<=r&&(P[i]+R[i])*4+Q[i]*9<=c){
				printf("%d\n",num[i]);
				f=true;
			}
		}
		if(!f)printf("NA\n");
	}
}

Measured memory_bytes: 1212
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
int main()
{
    int a[200];
    int p = -1;
    char s[7];
    while(scanf("%s",s)!=EOF)
    {
        if(s[0]=='+')
        {
            a[p-1] += a[p];
            --p;
        }
        else if(s[0]=='-')
        {
            a[p-1] -= a[p];
            --p;
        }
        else if(s[0]=='*')
        {
            a[p-1] *= a[p];
            --p;
        }
        else
        {
            a[p+1] = atoi(s);
            ++p;
        }
    }
    cout<<a[0]<<endl;
    return 0;
}

Measured memory_bytes: 3236
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    ll N;
    string S;
    cin >> N >> S;
    vector<int> lucky(N);
    REP(i, N) lucky[i] = S[i] - '0';

    ll ans = 0;
    REP(i, 10)
        REP(j, 10)
            REP(k, 10) {
                vector<bool> ok(3, false);
                REP(idx, S.length()) {
                    if(ok[0] == false && lucky[idx] == i)
                        ok[0] = true;
                    else if(ok[0] == true && ok[1] == false && lucky[idx] == j)
                        ok[1] = true;
                    else if(ok[1] == true && ok[2] == false && lucky[idx] == k) {
                        ok[2] = true;
                        ans++;
                        break;
                    }
                }
            }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384