akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans;
    if (k <= a) ans = k;
    else if (a < k && k <= b) ans = a;
    else ans = a-(k-a-b);
    cout << ans << endl;
}


Measured memory_bytes: 3188
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    int D, alp = 26;
    cin >> D;
    vector<int> c(alp);
    vector<vector<int>> s(D, vector<int>(alp));
    for (int i = 0; i < alp; i++) {
        cin >> c[i];
    }
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < alp; j++) {
            cin >> s[i][j];
        }
    }

    int ans = 0;
    vector<int> last(alp, 0);
    for (int i = 0; i < D; i++) {
        int lastchoise = -1;
        int lastans = -(1 << 30);

        for (int j = 0; j < alp; j++) {
            int diff = s[i][j];

            for (int k = 0; k < alp; k++) {
                if (k != j) {
                    diff -= c[k] * (i + 1 - last[k]);
                }
            }

            if (lastans < diff) {
                lastans = diff;
                lastchoise = j;
            }
        }

        ans += lastans;
        last[lastchoise] = i + 1;

        cout << lastchoise + 1 << endl;
    }

    return 0;
}

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

using namespace std;

void rotate(vector<string> &v){
	vector<string> nv(8,"");
	for(int i = 0; i < 8; i++){
		for(int j = 0; j < 8; j++){
			nv[i]+=v[7-j][i];
		}
	}
	v=nv;
}

int main(){

	vector<string> v;
	for(int i = 0; i < 8; i++){
		string s;
		cin>>s;
		v.push_back(s);
	}
	int sum=0;
	for(int i = 0; i < 3; i++){
		sum+=90;
		rotate(v);
		cout<<sum<<endl;
		for(int i = 0; i < 8; i++)
			cout<<v[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define inf 100000000000LL
#define N 200005
using namespace std;
ll n,m,a[N],y,tg[N*4];
struct T
{
	ll x,y;
}s1[N*4],s2[N*4];
void up(ll k)
{
	ll l=k<<1,r=l^1;
	s1[k]=s1[l].y-s1[l].x<s1[r].y-s1[r].x?s1[l]:s1[r];
	s2[k]=s2[l].y+s2[l].x<s2[r].y+s2[r].x?s2[l]:s2[r];
}
void add(ll k,ll x)
{
	tg[k]+=x;
	s1[k].y+=x;
	s2[k].y+=x;
}
void dn(ll k)
{
	if (tg[k])
	{
		add(k<<1,tg[k]);add(k<<1|1,tg[k]);
		tg[k]=0;
	}
}
void build(ll k,ll l,ll r)
{
	if (l==r){s1[k]=s2[k]=(T){l,inf};return;}
	ll mid=l+r>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	up(k);
}
void add(ll k,ll l,ll r,ll x,ll y,ll p)
{
	if (x<=l&&r<=y){add(k,p);return;}
	ll mid=l+r>>1;dn(k);
	if (x<=mid) add(k<<1,l,mid,x,y,p);
	if (y>mid) add(k<<1|1,mid+1,r,x,y,p);
	up(k);
}
ll Get1(ll k,ll l,ll r,ll x,ll y)
{
	if (x<=l&&r<=y) return s1[k].y-s1[k].x;
	ll mid=l+r>>1,ans=inf*10;dn(k);
	if (x<=mid) ans=min(ans,Get1(k<<1,l,mid,x,y));
	if (y>mid) ans=min(ans,Get1(k<<1|1,mid+1,r,x,y));
	return ans;
}
ll Get2(ll k,ll l,ll r,ll x,ll y)
{
	if (x<=l&&r<=y) return s2[k].y+s2[k].x;
	ll mid=l+r>>1,ans=inf*10;dn(k);
	if (x<=mid) ans=min(ans,Get2(k<<1,l,mid,x,y));
	if (y>mid) ans=min(ans,Get2(k<<1|1,mid+1,r,x,y));
	return ans;
}
ll Get(ll k,ll l,ll r)
{
	if (l==r)
	{
		return s1[k].y;
	}
	ll mid=l+r>>1;dn(k);
	return min(Get(k<<1|1,mid+1,r),Get(k<<1,l,mid));
}
int main()
{
	scanf("%lld%lld%lld%lld",&n,&m,&a[0],&y);
	build(1,1,n);
	add(1,1,n,y,y,-inf);
	Get(1,1,n);
	for (ll i=1;i<=m;i++)
	{
		scanf("%lld",&a[i]);
//a[i]=rand()%n+1;
//cout<<i<<endl;
		ll t1=Get1(1,1,n,1,a[i])+a[i],t2=Get2(1,1,n,a[i],n)-a[i];
		ll tmp=min(t1,t2);
		add(1,1,n,1,n,abs(a[i]-a[i-1]));
		ll t3=Get1(1,1,n,a[i-1],a[i-1])+a[i-1];
		if (tmp<t3)add(1,1,n,a[i-1],a[i-1],tmp-t3);
		//Get(1,1,n);
	}
	printf("%lld\n",Get(1,1,n));
}

Measured memory_bytes: 29056
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    int n,a;
    cin >> n >> a;
    cout << (n%500 <= a?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, ans = 0;
    cin >> n;
    for(int i=0;i<n;i++){
    	cin >> a;
    	while(a%2 == 0){
    		a /= 2;
    		ans++;
    	}
    }
    cout << ans << endl;
    return 0;
}


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



void solve(){
    string s;
    cin >> s;
    int siz = s.size();
    int a,b;
    a=0;
    b=1;
    bool c=true;
    while(a<siz){
      if(s[a]=='L') c=false;
      a = a+2;
    }
    while(b<siz){
      if(s[b]=='R') c=false;
      b = b+2;
    }
    if(c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

Measured memory_bytes: 256
N, K = gets.split(' ').map(&:to_i)
S = gets

lr = Array.new(N){Array.new}
c = 0
k = 0
N.times do |i|
  if c == 0 and S[i] == "1"
    c = 1
    lr[k][0] = i
  end
  if c == 1 and S[i] == "0"
    c = 0
    lr[k][1] = i - 1
    k += 1
  end
  if i == N - 1 and S[i] == "1"
    lr[k][1] = i
  end
end

val = 0
maxval = 0
if K > k
  maxval = N
else
  lr.reject!{|i| i.size == 0}
  lr.unshift([0, -1])
  lr.push([N, N-1])
  0.upto(k - K + 1) do |j|
    val = lr[j + K][1] - lr[j][0] + 1
    maxval = [val, maxval].max
  end
end

puts maxval

Measured memory_bytes: 9468
#!/usr/bin/python3
# -*- coding: utf-8 -*-


"""
https://beta.atcoder.jp/contests/abc009/tasks/abc51_1
"""

import sys
import math
from inspect import currentframe

def debug(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=sys.stderr)

s = input()
print(s.replace(',',' '))







Measured memory_bytes: 43376
import sys
sys.setrecursionlimit(1000000)

def main():
    h, w = map(int, input().split())
    mp = ["X" * (w + 2)] + ["X" + input() + "X" for _ in range(h)] + ["X" * (w + 2)]
    checked = [[False] * (w + 2) for _ in range(h + 2)]
    vec = ((1, 0), (0, -1), (-1, 0), (0, 1))


    def search(stack):
        x, y = stack.pop()
        if mp[y][x] == "#":
            b_cnt = 1
            w_cnt = 0
            another = "."
        else:
            b_cnt = 0
            w_cnt = 1
            another = "#"
        for dx, dy in vec:
            nx, ny = x + dx, y + dy
            if not checked[ny][nx] and mp[ny][nx] == another:
                checked[ny][nx] = True
                stack.append((nx, ny))
        return w_cnt, b_cnt

    ans = 0
    for y in range(1, h + 1):
        for x in range(1, w + 1):
            if not checked[y][x]:
                checked[y][x] = True
                stack = []
                stack.append((x, y))
                w_cnt = b_cnt = 0
                while stack:
                    w_add, b_add = search(stack)
                    w_cnt += w_add
                    b_cnt += b_add
                ans += w_cnt * b_cnt

    print(ans)

main()

Measured memory_bytes: 50396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;
set<int> s;

int main() {
  cin >> N;
  rep(i, N) {
    int A;
    cin >> A;
    if (s.find(A) == s.end()) {
      s.insert(A);
    } else {
      s.erase(A);
    }
  }
  cout << s.size() << endl;
  return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <utility>

using namespace std;

typedef long long ll;

#define min(a, b) ((a) < (b)? (a):(b))
#define max(a, b) ((a) > (b)? (a):(b))
#define abs(a) ((a) < (0)? -(a):(a))
#define D 1000000007
#define mul(a, b) (((a)%D) * ((b)%D)) % D

ll factorial(ll x) {
    if(x == 0) return 1;
    return mul(x, factorial(x-1));
}

int main() {
    ll N, M; cin >> N >> M;
    if(abs(N-M) > 1) {cout << 0 << endl; return 0;}
    ll ans = mul(factorial(N), factorial(M));

    if(N == M) ans = mul(ans, 2);
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    double t, x;
    cin>>t>>x;

    cout<<fixed<<setprecision(10)<<t/x<<endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:(x[1],x[0]),reverse=True)
cd.sort()

ans=0
for i in range(len(cd)):
  for j in range(len(ab)):
    c,d=cd[i]
    a,b=ab[j]
    if int(a)<int(c) and int(b)<int(d):
      ans+=1
      ab.pop(j)
      break
    
print(ans)

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

int main(){
    int N, A[200000];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    bool bits[20] = {};
    int r = 0;
    long long ans = 0;
    for(int l = 0; l < N; l++){
        while(r < N){
            bool is_ok = true;
            for(int i = 0; i < 20; i++){
                if((bits[i]) && (A[r] & (1 << i))){
                    is_ok = false;
                }
            }
            if(is_ok){
                for(int i = 0; i < 20; i++){
                    if(A[r] & (1 << i)){
                        bits[i] = true;
                    }
                }
                r++;
            }else{
                break;
            }
        }
        //cout << l << ", " << r << endl;
        long long d = r - l;
        ans += d;
        for(int i = 0; i < 20; i++){
            if(A[l] & (1 << i)){
                bits[i] = false;
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<double> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    vector<int> bit(n);
    rep(i, n) bit[i] = i;

    double ans = 0;
    int cnt = 0;
    do
    {
        rep(i, n - 1)
        {
            ans += sqrt(pow(x[bit[i + 1]] - x[bit[i]], 2.0) + pow(y[bit[i + 1]] - y[bit[i]], 2.0));
        }
        cnt++;
    } while (next_permutation(all(bit)));

    printf("%6lf\n", ans / cnt);

    return (0);
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

    int m1,m2,d1,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(d2==1){
        cout<<1<<endl;
        return 0;
    }else{
        cout << 0<<endl;
    }
    return 0;
}

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

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

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

    sort(d.begin(), d.end(), greater<int>());

    int counter = 1;
    for (int i = 1; i < N; ++i){
        if (d[i] < d[i-1]) ++counter;
    }

    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

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

int main(void)
{
    int n;
    cin >> n;
    
    int cnt = 0;
    rep2(i,1,n) {
        if(i%2!=0) { cnt++; }
    }
    printf("%f\n",(double)cnt/n);
    return 0;
} /*atcoder*/



Measured memory_bytes: 3724
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n = int(input())
  ans = 0
  cnt = 0
  
  for i in range(1,n+1,2):
    ans = 0
    for j in range(1,i+1):
      if i%j == 0:
        ans+=1
    if ans == 8:
      cnt += 1
  print(cnt)
if __name__ == '__main__':
  main()

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

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

	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());

	if(s<t){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, b) for (int i = 0; i < (b); i++ )

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

const int INF = 100000000;
const double PI=acos(-1);

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

    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());

    int k = max(s.size(),t.size());

    string ans = "No";
    rep(i,k) {
        if (i>s.size()-1) {
            ans = "Yes";
            break;
        }
        else if (i>t.size()-1) {
            break;
        }
        else if (s[i]<t[i]) {
            ans = "Yes";
            break;
        }
        else if (s[i]>t[i]) {
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np

MOD=998244353
N=int(input())
A=np.array([int(input()) for _ in range(N)])
TOTAL=pow(3,N,MOD)
ASum=sum(A)
sumEnd=0
sumEnd=ASum//2+1

dp=np.array([0 for _ in range(sumEnd)],dtype=np.int64)
dp[0] = 1

for n in range(N):
	dp[A[n]:] += dp[:-A[n]]*2 % MOD

plus = 0
if ASum % 2 == 0:
	# 合計が偶数
	dpOther=np.array([0 for _ in range(sumEnd+1)],dtype=np.int64)
	dpOther[0] = 1
	for n in range(N):
		dpOther[A[n]:] += dpOther[:-A[n]] % MOD
	plus = (dpOther[ASum//2]*3) % MOD

exceptCnt=0
for s in range(0,sumEnd):
	exceptCnt = (exceptCnt + dp[s]*3) % MOD

exceptCnt -= plus
print((TOTAL - exceptCnt) % MOD )



Measured memory_bytes: 13520
#include <cstdio>
#include <iostream>
typedef long long LL;
LL gcd(LL a,LL b){
    LL t=1;
    while (b) {
        t=b;
        b=a%b;
        a=t;
    }
    return t;
}
int n;
LL x;
int main() {
    scanf("%d%lld",&n,&x);
    LL t,y;
    scanf("%lld",&t);
    t=abs(t-x);
    for(int i=2;i<=n;i++){
        scanf("%lld",&y);
        t=gcd(t, abs(x-y));
    }
    printf("%lld\n",t);
    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
D=[0]*(10**5+1)
ans=0
for i in A:
  if i > 10**5:
    ans+=1
  else:
    D[i]+=1

for i in range(1,10**5+1):
  if i <= D[i]:
    ans+=D[i]-i
  else:
    ans+=D[i]
print(ans)

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

void print() {
  cout << endl;
}

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
}

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
}

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

  int H, W;
  cin >> H >> W;
  vector<vector<char>> grid(H+2, vector<char> (W+2, '#'));
  rep(i, 1, H+1) {
    rep(j, 1, W+1) {
      cin >> grid[i][j];
    }
  }

  rep(i, 0, H+2) {
    rep(j, 0, W+2) {
      cout << grid[i][j];
    }
    cout << endl;
  }

  return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<ll> A(N);
    for(size_t i=0;i<N; i++)
    {
        ll a;
        cin >> a;
        A[i] = a - (i+1);
    }
    ll total = 0;
    //ll min_total = INF;
    sort(A.begin(), A.end());
    //cerr << A[N/2] << endl;
    for(size_t i=0;i<N; i++)
    {
        total += abs(A[i] - A[N/2]);
    }
    cout << total << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 1792
//
//  sublime text 3,
//  emre yazicioglu
//

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
typedef vector <pll> vpll;
#define pb push_back
#define fi first
#define se second
#define INF (ll) (1e18 + 7)
#define MOD (ll) (1e9 + 7)

const int N = 2e6 + 7;
ll mn = INF, mx = -INF;
ll n, m, k, s, q, t;
ll a[N], b[N], c, d, e;
ll ans, cur, sum, cnt;
ll ar[N], p[N], dp[N];
string str; bool h[N];
pll pp[N]; vll v[N];
map <pll, ll> mp;

void f(int node, int last) {
  if(h[node]) return;
  h[node] = 1;
  ll cur = 0;
  for(auto i : v[node]) {
    if(h[i]) continue;
    cur++;
    cur += (cur == last);
    f(i, cur);
    mp[{i, node}] = mp[{node, i}] = cur;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);

  // freopen("../in.txt","r",stdin);
  // freopen("../out.txt","w",stdout);

  cin >> n;
  for(int i = 1; i <= n - 1; i++) {
    cin >> a[i] >> b[i];
    v[a[i]].pb(b[i]);
    v[b[i]].pb(a[i]);
  }
  for(int i = 1; i <= n; i++)
    if(!h[i]) f(i, -1);
  for(int i = 1; i <= n - 1; i++)
    ans = max(ans, mp[{a[i], b[i]}]);
  cout << ans << '\n';
  for(int i = 1; i <= n - 1; i++)
    cout << mp[{a[i], b[i]}] << '\n';
}

Measured memory_bytes: 76032
#[allow(unused)]
use proconio::marker::*;
use proconio::{fastout, input};
#[allow(unused)]
use std::cmp::{max, min, Reverse};
#[allow(unused)]
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

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

    let mut i = 0;
    let mut ts = 26;
    let m = 25 * n + 1;
    while m >= ts {
        ts *= 26;
        i += 1;
    }
    // println! {"i: {}", i};

    let mut o = n;
    let mut ts = 26;
    for j in 0..i - 1 {
        o -= ts;
        ts *= 26;
    }
    o -= 1;
    // println!("o: {}", o);

    let mut ts = {
        let mut ts = 1;
        for j in 0..i - 1 {
            ts *= 26;
        }
        ts
    };
    // println!("{}", ts);

    let mut ans = vec![];
    for j in 0..i {
        let q = o / ts;
        let r = o % ts;
        ans.push(q);
        o = r;
        ts /= 26;
    }
    // println!("{:?}", ans);

    for &a in ans.iter() {
        let p = format!("{}", ('a' as u8 + a as u8) as char);
        print!("{}", p);
    }
    println!("");
}

fn r(n: usize) {}


Measured memory_bytes: 2208
# -*- coding: utf-8 -*-

H,W = map(int, input().split())

# # どちらかの辺が3の倍数なら確実に3等分できる
# if H % 3 == 0 or W % 3 == 0:
#     print(0)
#     exit()

# T字で区切るパターンを縦横それぞれ試す
mnval = float("inf")
for i in range(1,H):
    tmpA = i * W
    tmpB = (H-i) * (W // 2)
    tmpC = (H-i) * (W // 2 + W % 2)
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))

for i in range(1,W):
    tmpA = i * H
    tmpB = (W-i) * (H // 2)
    tmpC = (W-i) * (H // 2 + H % 2)
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))

# 縦並び横並びパターンをそれぞれ試す
if W >= 3:
    tmpA = H * (W // 3)
    tmpB = H * (W // 3 + ((W % 3) // 2))
    tmpC = H * (W // 3 + ((W % 3) // 2 + (W % 3) % 2))
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))
if H >= 3:
    tmpA = W * (H // 3)
    tmpB = W * (H // 3 + ((H % 3) // 2))
    tmpC = W * (H // 3 + ((H % 3) // 2 + (H % 3) % 2))
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))

print(mnval)

Measured memory_bytes: 3064
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int i,flag=0;
	for(i=1;i<=s.size();i++)
	{
		flag++;
	}
	cout<<s[0]<<flag-2<<s[s.size()-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;
  if(s.size() % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  for(int i = 0; i<s.size(); i += 2) {
    if(s[i] != 'h' || s[i + 1] != 'i') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,n;cin>>k>>n;
  int tmp;
  int ans=0;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin >>a.at(i);
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n-1;i++){
    tmp=a.at(i+1)-a.at(i);
    if(tmp>k/2)
    tmp=k-tmp;
    ans=max(ans,tmp);
  }
  tmp=a.at(n-1)-a.at(0);
  if(tmp>k/2)
    tmp=k-tmp;
  ans=max(ans,tmp);
  cout <<k-ans<<endl;
}


Measured memory_bytes: 1024
A = []
q = gets.chomp.to_i
q.times{
    input = gets.chomp
    choice, d, x = input.split(" ")
    case choice
    when "0"
        if d == "0"
            A.unshift(x)
        elsif d == "1"
            A.push(x)
        end
    when "1"
        puts A[d.to_i]
    when "2"
        if d == "0"
            A.shift()
        elsif d == "1"
            A.pop()
        end
    else
    end
}


Measured memory_bytes: 35936
# 0028
array = []
while True:
    try:
        a = input()
        array.append(int(a))
    except EOFError:
        break
s = set(array)
mx = array.count(max(s, key = array.count))
for a in sorted(s):
    if array.count(a) == mx:
        print(a)

Measured memory_bytes: 7576
//{
//    author: Manas Singh
//    created on Saturday, 17 August, 2019 at 16:08:58 UTC+5:30
//    atdp2
//}

/*
    _____                                  _________ __               .__
   /     \ _____    ____ _____    ______  /   _____/|__| ____    ____ |  |____
  /  \ /  \__   \  /    \__  \  /  ___ /  \_____  \ |  |/    \  / ___\|  |  \  /
 /    Y    \/ __ \|   |  \/ __ \_\___ \   /        \|  |   |  \/ /_/  >   Y   /
 \____|__  (____  /___|  (____  /____  > /_______  /|__|___|  /\___  /|___|  /
         \/     \/     \/     \/     \/          \/         \//_____/      \/
*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define MOD 1000000007
#define inf 1e18 + 5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define __                            \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
#define vi vector<int>
#define vpii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define rep(a, b, i) for (int i = a; i < b; i++)
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                    \
    sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
    {
sim > struct rge
{
    c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
    ~debug()
    {
        cerr << endl;
    }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c &)
    {
        ris;
    }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int, int> pii;

//-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------

const int maxn = 100005;
int32_t main()
{
    __;

    int n, k;
    cin >> n >> k;
    int arr[n + 1];
    rep(1, n + 1, i) cin >> arr[i];

    int dp[n + 1];
    dp[1] = 0;
    dp[2] = abs(arr[2] - arr[1]);

    rep(3, n + 1, i)
    {
        int q = INT_MAX;
        rep(max(1, i - k), i, j)
            q = min(q, dp[j] + abs(arr[i] - arr[j]));
        dp[i] = q;
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<short> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int n;

map<vi, short> bfs(vi v)
{
	map<vi, short> mp;
	queue<vi> que;
	que.push(v); mp[v] = 0;
	while (que.size())
	{
		vi tmp = que.front();
		que.pop();
		int t = mp[tmp];
		if (t >= (n-1) / 2) continue;
		REP(i, n)REP(j, i)
		{
			vi nx = tmp;
			reverse(nx.begin() + j, nx.begin() + i + 1);
			if (mp.find(nx) != mp.end()) continue;
			else
			{
				mp[nx] = t + 1;
				que.push(nx);
			}
		}
	}
	return mp;
}

signed main()
{
	cin >> n;
	vi a(n), b;
	REP(i, n) cin >> a[i];
	b = a;
	sort(ALL(b));
	auto mp1 = bfs(a);
	auto mp2 = bfs(b);
	int ans = n - 1;
	for (auto it = mp1.begin(); it != mp1.end(); it++)
	{
		if (mp2.find(it->first) != mp2.end()) chmin(ans, it->second + mp2[it->first]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 71524
#参考https://qiita.com/takayg1/items/c811bd07c21923d7ec69

#####segfunc#####
def segfunc(x, y):
    return max(x,y)
#################

#####ide_ele初期値#####
ide_ele = 0
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る ※区間注意
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

N, K = map(int, input().split())
A = [int(input())+1 for _ in range(N)]
seg = SegTree([0 for i in range(300050)], segfunc, ide_ele)

answer = 0
for i in range(N):
    
    under = max(0,A[i]-K)
    upper = min(300050,A[i]+K)
    now = seg.query(under, upper+1)
    seg.update(A[i], now+1)
    
print(seg.query(0,300050))

Measured memory_bytes: 127340
N=int(input())
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
ans=[0]*100

for i in range(N):
    for j in range(i+1):
        ans[i]+=A1[j]
    for j in range(i,N):
        ans[i]+=A2[j]

print(max(ans))

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

int N;
char c753[3] = {'3', '5', '7'};

int dfs(string s) {
  if ( s != "" ) { if ( s.length() > 9 || stoi(s) > N ) { return 0; } }

  int ct = 1;
  for ( int i = 0; i < 3; i++ ) {
    bool non753 = true;
    for ( int c = 0; c < s.length(); c++ ) {
      if ( c753[i] == s[c] ) { non753 = false; break; }
    }
    if ( non753 ) { ct--; break; }
  }

  for ( int i = 0; i < 3; i++ ) {
    ct += dfs(s + c753[i]);
  }

  return ct;
}

int main() {
  int n;
  cin >> n;
  N = n;
  cout << dfs("") << endl;
  return 0;
}


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

using namespace std;

int main()
{
  int n;
  double x[1001], y[1001], r=0.0;
  for(int i = 0; i < 1001; i++) x[i] = y[i] = 0;

  for(int i = 1; i < 1001; i++){
    x[i] += (cos(r)+x[i-1]);
    y[i] += (sin(r)+y[i-1]);
    r = atan2(y[i], x[i])+M_PI/2.0;
  }

  while(cin>>n && n != -1){
    printf("%0.2lf\n%0.2lf\n", x[n], y[n]);
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const  long long     mx=1e5+100;

#define      mod     1e9+7
#define      pai     acos(-1)
#define      ff      first
#define      ss      second
#define      ll      long long
#define      pb      push_back
#define      mp      make_pair
#define      fi      freopen("input.txt","r",stdin);
#define      fo      freopen("output.txt","w",stdout);
#define      fast    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

//typedef pair<ll,ll> pi;
//typedef map<ll,ll> mi;


int main()
{
    fast;
    ll i,j,a,b,c,d,n,m,k,x,y,t;
    cin>>n;
    ll arr[n];
    ll mx=0,mn=mod;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        mx=max(mx,arr[i]);
        mn=min(mn,arr[i]);
    }
    sort(arr,arr+n);
    ll cost=1e17+10000;
    for(i=mn;i<=mx;i++)
    {
        ll tem=0;
        for(j=0;j<n;j++)
        {
            tem+=abs(arr[j]-i)*abs(arr[j]-i);
        }
        cost=min(cost,tem);
    }
    cout<<cost<<endl;
    return 0;
}



Measured memory_bytes: 3548
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
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;}
const ll INF = 1LL << 60;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    string s,t;
    cin >> s >> t;
    ll ans=INF;
    for (ll i=0;i<=s.size()-t.size();i++){
        ll count=0;
        for (ll j=0;j<t.size();j++){
            if (s[i+j]!=t[j]){
                count++;
            }
        }
        ans=min(ans,count);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
/*input
5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
void solve()
{
	lld n,m,k;
	cin >> n >> m >> k;
	vi a(n),b(m);
	rep(i,0,n){
		cin >> a[i];
	}
	rep(j,0,m){
		cin >> b[j];
	}
	lld res=0;
	rep(i,1,n){
		a[i]+=a[i-1];
	}
	rep(i,1,m){
		b[i]+=b[i-1];
	}
	rep(i,0,n){
		if(a[i]>k){
			break;
		}
		else{
			lld tot=i+1;
			lld rem=k-a[i];
			lld p=ubnd(all(b),rem)-b.begin();
			res=max(res,i+p+1);
		}
	}
	rep(j,0,m){
		if(b[j]>k){
			break;
		}
		else{
			lld rem=k-b[j];
			lld p=ubnd(all(a),rem)-a.begin();
			res=max(res,j+p+1);
		}
	}
	cout << res << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 6364
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    using ll = long long;
    using P = pair<int,int>; 
    
    
    int main() {
     ll k,n;
     cin >> k >> n;
     int a[n];
     
     rep(i,n)  cin >> a[i];
     
     
     int length[n];
     
     rep(i,n){
      if(i!=n-1)    length[i] = a[i+1] - a[i];
      else           length[i] = (k-a[i])+a[0];
     } 
     
     
     int sum = 0;
     rep(i,n)	sum+=length[i];
     int fin[n];
     
     rep(i,n){
     	fin[i] = sum - length[i];
     	
     }
     
     sort(fin,fin+n);
     
     
     
     			cout << fin[0] << '\n';
     			return 0;
     	
     
    }

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

int main(void){
	long N,T;
	std::vector<long> ts;
	std::cin>>N>>T;
	for(int i=0;i<N;i++){
		long t;
		std::cin>>t;
		ts.push_back(t);
	}

	long ans = T;
	for(int i=0;i<N-1;i++){
		long t = ts.at(i+1) - ts.at(i);
		if(t > T){
			ans += T;
		}else{
			ans += t;
		}
	}


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


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    lint N, M, K;
    cin >> N >> M >> K;
    vector<lint> A(0), B(0);

    lint sum  = 0;
    bool flag = false;
    rep(i, N) {
        lint tmp;
        cin >> tmp;
        if (flag or sum + tmp > K) {
            flag = true;
            continue;
        };
        A.push_back(tmp);
        sum += tmp;
    };
    sum  = 0;
    flag = false;
    rep(i, M) {
        lint tmp;
        cin >> tmp;
        if (flag or sum + tmp > K) {
            flag = true;
            continue;
        };
        B.push_back(tmp);
        sum += tmp;
    };

    vector<lint> LA(A.size() + 1, 0), LB(B.size() + 1, 0);
    rep(i, A.size()) { LA[i + 1] = LA[i] + A[i]; }
    rep(i, B.size()) { LB[i + 1] = LB[i] + B[i]; }

    // dump(A);
    // dump(B);
    // dump(LA);
    // dump(LB);

    int ma = -1;
    for (int cnt_a = 0; cnt_a <= A.size(); cnt_a++) {
        lint sum1 = K - LA[cnt_a];
        auto itr  = upper_bound(all(LB), sum1);
        int cnt_b = itr - LB.begin() - 1;
        // dd(cnt_a, cnt_b);
        ma = max(ma, cnt_a + cnt_b);
    }

    cout << ma << endl;
    return 0;
}


Measured memory_bytes: 9532
N,M=gets.split.map(&:to_i)
f=Array.new(N,false)
c=Array.new(N,0)
ac=0
M.times do
  a,b=gets.chomp.split
  a=a.to_i-1
  if !f[a]
    if b=="AC"
      f[a]=true
      ac+=1
    else
      c[a]+=1
    end
  end
end
res=0
N.times do |i|
  res+=!f[i] ? 0 : c[i]
end
puts [ac,res].join(" ")
      

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define ia(n, a) rp(ia_i, 0, n) cin >> a[ia_i]
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll x, n;
    cin >> x >> n;
    ll p[n];
    rp(i, 0, n) cin >> p[i];
    rp(i, 0, 100)
    {
        bool sig = true;
        bool sig2 = true;

        rp(j, 0, n) if (p[j] == x + i)
        {
            sig = false;
        }
        rp(j, 0, n) if (p[j] == x - i)
        {
            sig2 = false;
        }
        if (sig2)
        {
            ce(x - i);
            break;
        }
        if (sig)
        {
            ce(x + i);
            break;
        }
    }
}

Measured memory_bytes: 3588
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

#define SHEAP 'S'
#define WOLF 'W'
#define SAME 'o'
#define NOTSAME 'x'

bool isOk(int pos, const string& s, const string& temp)
{
	int left = pos-1, right = pos+1;
	if(pos == 0)
		left = temp.size() - 1;
	else if(pos == temp.size() - 1)
		right = 0;

	bool flag = true;
	if(s[pos] == SAME && temp[left] != temp[right])
		flag = false;
	else if(s[pos] == NOTSAME && temp[left] == temp[right])
		flag = false;

	if(temp[pos] == WOLF)
		flag = !flag;

	return flag;
}

int main(void)
{
	int N;
	cin >> N;

	string s;
	cin >> s;
	
	const string animal = "SW";
	string ret = "-1";
	for(int i=0; i<2; i++)
	{
		string temp = s;
		temp[0] = animal[i];

		for(int j=0; j<2; j++)
		{
			temp[1] = animal[j];
			
			for(int k=1; k<N-1; k++)
			{
				char c = temp[k-1];
				if(temp[k] == SHEAP && s[k] == NOTSAME)
					c = (c == animal[0]) ? animal[1] : animal[0];
				else if(temp[k] == WOLF && s[k] == SAME)
					c = (c == animal[0]) ? animal[1] : animal[0];

				temp[k+1] = c;
			}

			if(isOk(0, s, temp) && isOk(N-1, s, temp))
			{
				ret = temp;
				i = j = 3;
			}
		}
	}
	
	cout << ret << endl;

	return 0;
}


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

typedef long long ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";
#define pb push_back

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
    for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
    os << "("; os << v.first << ", " << v.second << ")"; return os;
}
void go() {
    cin.tie(nullptr) -> sync_with_stdio(false);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
}
const int N = 1e5 + 5;
vector<vector<int>> adj(N), parent(N);
vector<int> vis(N), topo, dp(N);
void dfs(int node) {
    vis[node] = 1;
    for (int x : parent[node]) {
        if (!vis[x]) {
            dfs(x);
        }
        dp[node] = max(dp[node], dp[x] + 1);
    }
}
int32_t main() {
    go();
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        parent[y].push_back(x);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            dfs(i);
        }
        ans = max(ans, dp[i]);
    }
    cout << ans;
}

Measured memory_bytes: 16272
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,l;
	cin>>n>>l;
	string s[100];
	for(int i=0;i<n;i++) cin>>s[i];
	sort(s,s+n);
	for(int i=0;i<n;i++) cout<<s[i];
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
/*
ID: jerrywcy
TASK: AtCoder ABC 105 Problem A
LINK: https://abc105.contest.atcoder.jp/tasks/abc105_a
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n;

int main()
{
    int n;
    string s="";
    cin>>n;
    while(n){
        if(n%-2){
          	n--;
          	s="1"+s;
        }else
          	s="0"+s;
        n/=-2;
      }
    if(s=="")s="0";
    
    cout<<s<<endl;
    
	return 0;
}



Measured memory_bytes: 256