akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toLong()
        val M = sc.next().toLong()
        var f = M
        var i = 2L
        while (i * i <= M) {
            if (M % i == 0L) {
                val i2 = M / i
                if (i >= N) f = min(f, i)
                if (i2 >= N) f = min(f, i2)
            }
            i++
        }
        if (N == 1L) pw.println(M)
        else pw.println(M / f)
    }
}


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

int main(){
  int n,k;
  cin >> n >> k;
  double ans=0;
  for(int i=0;i<n;i++){
    double j=1;
    int p=i+1;
    while(p<k){
      p*=2;
      j/=2;
    }
    ans+=j;
  }
  ans/=n;
  printf("%.15f\n",ans);
}

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

double calc(int p) {
  int ret = p * (p + 1) / 2;
  return (double)ret / (double)p;
}

int main(void) {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  map<int, double> mp;
  vector<int> P(N);
  rep(i, N) cin >> P[i];

  double current = 0;
  int left = 0;
  for (left = 0; left < K; ++left) {
    if (!mp.count(P[left])) {
      double val = calc(P[left]);
      mp[P[left]] = val;
      current += val;
    } else {
      current += mp[P[left]];
    }
  }

  double answer = current;
  int right = left;
  left = 0;
  for (; right < N; ++right) {
    current -= mp[P[left++]];
    if (!mp.count(P[right])) {
      double val = calc(P[right]);
      current += val;
      mp[P[right]] = val;
    } else {
      current += mp[P[right]];
    }
    answer = max(answer, current);
  }
  cout << setprecision(10) << answer << endl;
  return 0;
}


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

int main() {

  int N;
  cin >> N;
  int j=0;
  int S=0;
  while (j < N) {
    int l,r;
    cin >> l >> r;
      S += r-l+1 ;
    j++;
  }
  cout << S << endl;
}

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

using namespace std;

#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

const int INF = 1e9 + 5;
const int MAXN = 3e6 + 123;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
bool cmp(const string& a, const string& b) {
	return (a + b) < (b + a);
}

vector<int> Reversed(const vector<int>& s){
   vector<int> d = s;
   reverse(all(d));
   return d;
}


void solve(){
    int n, l;
    cin >> n >> l;
    vector<string> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(all(v));
    for(int i = 0; i < n; i++){
        cout << v[i];
    }
}

// ."ww"w"".ww"""...ww"".

int main(){
    //freopen("lepus.in","r",stdin);
    //freopen("lepus.out","w",stdout);
    //faster();
    int n=1;
    //cin>>n;
    while(n--){
    solve();
    //cout << endl;
    }
    //fclose(stdout);
}


Measured memory_bytes: 256
def solve(n,G):
    visited = [False] * n
    visited[0] = True
    stack = [0]
    while len(stack) != 0:
        x = stack.pop()
        visited[x] = True
        for i in G[x]:
            if visited[i] == True:
                continue
            stack.append(i)
    if not False in visited:
        return False
    return True

def main():
    n,m = map(int,input().split())
    G = [list() for i in range(n)]
    for i in range(m):
        a,b = map(int,input().split())
        a = a - 1
        b = b - 1
        G[a].append(b)
        G[b].append(a)
    ans = 0
    for i in range(n):
        for j in range(i + 1,n):
            if not j in G[i]:
                continue
            G[i].remove(j)
            G[j].remove(i)
            if solve(n,G):
                ans = ans + 1
            G[i].append(j)
            G[j].append(i)
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
import copy
row = list(map(int, input().split()))
s = [input().split() for i in range(row[0])]
for i in range(row[0]):
    s[i] = list(s[i][0])

s_copy = []
for i in range(row[0]+2):
    s_row = []
    for j in range(row[1]+2):
        if i == 0 or i == row[0]+1 or j == 0 or j == row[1]+1:
            s_row.append(0)
        else:
            s_row.append(s[i-1][j-1])
    s_copy.append(s_row)

count = 0
for i in range(row[0]):
    for j in range(row[1]):
        if s[i][j] == ".":
            h = i - 1
            while h <= i+1:
                w = j - 1
                while w <= j + 1:
                    if s_copy[h+1][w+1] == "#":
                        count += 1
                    w += 1
                h += 1
            s[i][j] = str(count)
            count = 0
     
for i in range(row[0]):
    a = ''.join(s[i])
    print(a)


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

#define endl '\n'

typedef long long ll;

struct S {
    int x, y, num;
};

char in[1005][1005];
int N, M, A[1005][1005], ans;
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
queue<S> q;

bool safe(int x, int y) {
    if(0 < x && x <= N && 0 < y && y <= M) return 1;
    return 0;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> N >> M;
    for(int i=1; i<=N; i++) cin >> in[i]+1;
    for(int i=1; i<=N; i++) {
        for(int j=1; j<=M; j++) {
            if(in[i][j] == '#') {
                A[i][j] = 1;
                q.push({i, j, 0});
            }
        }
    }
    while(!q.empty()) {
        int x = q.front().x, y = q.front().y, num = q.front().num;
        q.pop();
        ans = max(ans, num);
        for(int i=0; i<4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if(A[nx][ny] == 0 && safe(nx, ny)) {
                A[nx][ny] = 1;
                q.push({nx, ny, num+1});
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 17296
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {

    long long int a, b, c;
    cin >> a >> b >> c;

    if ( a + b + c <= 21 ) {
        cout << "win" << endl;
    } else {
        cout << "bust" << endl;
    }

    return 0;

}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    int sum = H*W;
    sum -= h*W;
    int th = H-h;
    sum -= th * w;
    cout << sum << endl;



    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{

	
	  public static void main(String[] args)
	  {
	    Scanner sc=new Scanner(System.in);
	    int i=sc.nextInt();
	    int j=sc.nextInt();
	    int flag=0;
        if(j%2!=0)
        {
          System.out.println("No");
          return;
        }
	    if(i==1)
	    {
	    	if(j==4||j==2)
            {
	              System.out.print("Yes");
            }
	    }
	    else
	    {
	    for(int k=0;k<=i;k++)
	    {
	   
	      if(((k*2+(i-k)*4)==j)||((k*4+(i-k)*2)==j))
	      {
	        System.out.println("Yes");
	        flag=1;
	        break;
	      }  
	    } 
	    if(flag==0)
	    {
	      System.out.println("No");
	    }
	    }
	  }
	}  


Measured memory_bytes: 35656
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MXN 200005
bool cmp(const pii &a,const pii &b){
    return a>b;
}
int mod=1e9+7;
int main(){
    int n;
    pii p[200005];
    scanf("%d",&n);
    for(int i = 1;i<=n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        p[i]=mp(y,x);
    }
    sort(p+1,p+n+1);
    int l[200005],r[200005];
    vector<pii> v;
    v.pb(mp(0,0));
    for(int i = 1;i<=n;i++){
        if(p[i].y>v.back().x)
            v.pb(mp(p[i].y,i));
        l[i]=lower_bound(v.begin(),v.end(),mp(p[i].y,i))->y;
    }
    v.clear();
    v.pb(mp(1e9+12,n+1));
    for(int i = n;i>=1;i--){
        if(p[i].y<v.back().x)
            v.pb(mp(p[i].y,i));
        r[i]=lower_bound(v.begin(),v.end(),mp(p[i].y,i),cmp)->y;
    }
    pii seg[200005];
    for(int i = 1;i<=n;i++){
       // printf("%d %d\n",l[i],r[i]);
        seg[i]=mp(r[i],l[i]);
    }
    sort(seg+1,seg+n+1);
    LL dp[200005];
    MEM(dp);
    dp[0]=1;
    int now=0;
    for(int i = 1;i<=n;i++){
        while(now<seg[i].x){
       //     printf("%d %d\n",dp[now],now);
            now++;
            dp[now]+=dp[now-1];
            dp[now]%=mod;
        }
        if(seg[i].y==1){
            dp[now]+=dp[now];
            dp[now]%=mod;
        }
        else{
            dp[now]+=dp[now]-dp[seg[i].y-2];
            dp[now]%=mod;
        }
    }
  //  printf("%d %d\n",dp[now],now);
    printf("%lld\n",((dp[n]-dp[n-1])%mod+mod)%mod);
}
/**/

Measured memory_bytes: 8176
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
	int sec = 0, min = 0, hour = 0;

	cin >> sec;

	while (1)
	{
		if (sec >= 60)
		{
			sec -= 60;
			min += 1;
		}
		if (min >= 60)
		{
			min -= 60;
			hour += 1;
		}
		if (sec < 60 && min < 60 && hour < 60)
		{
			cout << hour << ":" << min << ":" << sec << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
$count = 0
def merge(array, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = Array.new(n1) { nil }
  r = Array.new(n2) { nil }
  l.size.times do |i|
    l[i] = array[left + i]
  end
  r.size.times do |i|
    r[i] = array[mid + i]
  end
  l << 9999999999
  r << 9999999999
  i, j = 0, 0
  left.upto(right - 1) do |k|
    $count += 1
    if l[i] <= r[j]
      array[k] = l[i]
      i += 1
    else
      array[k] = r[j]
      j += 1
    end
  end
end

def mergeSort(array, left, right)
  if left + 1 < right
    mid = (left + right) / 2
    mergeSort(array, left, mid)
    mergeSort(array, mid, right)
    merge(array, left, mid, right)
  end
end

len = gets.to_i
array = gets.split(' ').map(&:to_i)
mergeSort(array, 0, len)
puts array.join(' ')
p $count



Measured memory_bytes: 81932
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define ppi pair<int,pair<int,int> >
#define fr first
#define sc second
#define PI acos(-1)
#define mp make_pair

using namespace std;

#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__) << "] "




int main()
{
    int k,x; cin >> k >> x;
    for(int i =max( x - k + 1 , -1000000);i<=min(1000000,x + k - 1);i++)
        cout << i << ' ' ;

	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int64_t> as(n);
    for (auto& a : as)
    {
        cin >> a;
    }
    for (int64_t i = 0; i < n; i++)
    {
        as[i] -= i;
    }
    sort(as.begin(), as.end());

    auto med = as[as.size() / 2];
    int64_t sum = 0;
    for (auto a : as)
    {
        sum += abs(a - med);
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

long int max(long int a,long int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  long int a,b,c,d;
  scanf("%ld%ld%ld%ld",&a,&b,&c,&d);

  printf("%ld\n",max(max(a*c,a*d),max(b*c,b*d)));

  return 0;
}

Measured memory_bytes: 1724
# C
import numpy as np
N, M = map(int, input().split())

alpha = np.zeros(N+1)
omega = np.zeros(N+1)

for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        alpha[b] = 1
    if b == N:
        omega[a] = 1
        
if (alpha*omega).sum() > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 23864
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();

    let mut ans = 0;

    for _ in 0..n {
        let h: usize = iter.next().unwrap().parse().unwrap();
        if h >= k {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    ll m,d;
    cin>>m>>d;
    ll d1,d2,ans;
    for(ll i=1;i<d+1;i++){
        d1=i/10;
        d2=i%10;
        if(d1>=2&&d2>=2&&d1*d2<=m)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
a=list(map(int, input().split()))
a_copy = a.copy()
b=[]
flg = 0
#print(list(range(n,0,-2)))
for i in range(n-1,0,-2):
  b.append(a[i])
  a_copy.pop(i)
b = b+ a_copy
print(*b)

Measured memory_bytes: 26180
#include<stdio.h>
const int N=105;
int n,f0,f1,a,b,m;
int main(){
	int i,c;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&b);
		if(a!=b){
			if(c)m+=c>>1;
			c=1,a=b;
		}else ++c;
	}
	if(c)m+=c>>1;
	printf("%d\n",m);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main(){
    cin>>N>>A>>B;
    ll ans = 0;
    reps(i,1,N+1){
        ll temp = 0, I = i;
        while(I > 0){
            temp += I%10;
            I /= 10;
        }
        //cout<<i<<' '<<temp<<endl;
        if((temp >= A) && (temp <= B)) ans += i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

     cin>>a>>b>>c>>d;



       ans=b/c + b/d;

       a--;

       ans-=(a/c +(a/d));

    l=lcm(c,d);

      ll aa=b/l;

      aa-=a/l;

      ans-=aa;

      cout<<(b-a)-ans<<endl;











}



Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

int main()
{
    FAST();
    ll int n,m,res;

    cin>>n;
    if(n>=1800)
        m=1;
    else if(n>=1600)
        m=2;
    else if(n>=1400)
        m=3;
    else if(n>=1200)
        m=4;
    else if(n>=1000)
        m=5;
    else if(n>=800)
        m=6;
        else if(n>=600)m=7;
        else m=8;
        cout<<m<<endl;

}



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

int main(){
  string str, p, order;
  char temp;
  int q, a, b;

  cin >> str;
  cin >> q;

  for(int i = 0; i < q; i++){
    cin >> order >> a >> b;

    if(order == "print"){
      cout << str.substr(a, b - a + 1) << endl;
    }
    else if(order == "reverse"){
      while(a < b){
        temp = str[a];
        str[a] = str[b];
        str[b] = temp;
        a++;
        b--;
      }
    }
    else if(order == "replace"){
      cin >> p;
      str.replace(a, b - a + 1, p);
    }
  }

  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

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); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int n,c[200010],anc[200010],vs[200010];
stack<int> par[200010];
vector<int> pars[200010],inds[200010];
vector<int> G[200010];

void dfs(int v,int prv){
	anc[v] = par[c[v]].top();
	vs[v] = 1;
	for(int to : G[v]){
		if(to != prv){
			par[c[v]].push(to);
			pars[c[v]].push_back(to);
			dfs(to,v);
			par[c[v]].pop();
			vs[v] += vs[to];
		}
	}
}

signed main(){
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> c[i];
		c[i]--;
		inds[c[i]].push_back(i);
	}
	for(int i = 0;i < n - 1;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i = 0;i < n;i++){
		par[i].push(0);
		pars[i].push_back(0);
	}
	dfs(0,-1);
	int vvs[200010];
	for(int i = 0;i < n;i++) vvs[i] = vs[i];
	for(int i = 0;i < n;i++){
		if(inds[i].empty()){
			cout << 0 << endl;
			continue;
		}
		int sum = 0;
		for(int v : inds[i]) vs[anc[v]] -= vvs[v];
		for(int v : pars[i]) sum += vs[v] * (vs[v] + 1) / 2;
		for(int v : inds[i]) vs[anc[v]] += vvs[v];
		cout << n * (n + 1) / 2 - sum << endl;
	}
}


Measured memory_bytes: 201988
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type Order struct {
	a, b int
}

type ByA []Order

func (a ByA) Len() int           { return len(a) }
func (a ByA) Less(i, j int) bool { return a[i].a < a[j].a }
func (a ByA) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, T := sc.nextInt(), sc.nextInt()
	O := make([]Order, N)
	for i := 0; i < N; i++ {
		a, b := sc.nextInt(), sc.nextInt()
		O[i] = Order{a, b}
	}
	sort.Sort(ByA(O))
	dp1 := make([][]int, N+1)
	for i := 0; i < N+1; i++ {
		dp1[i] = make([]int, T)
	}
	ans := 0
	for i := 0; i < N; i++ {
		for j := 0; j < T; j++ {
			a, b := O[i].a, O[i].b
			dp1[i+1][j] = dp1[i][j]
			if j >= a {
				dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j-a]+b)
			}
		}
		if i+1 <= N-1 {
			ans = max(ans, dp1[i+1][T-1]+O[i+1].b)
		}
	}
	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 75392
n, m = map(int, input().split())
a = list(map(int, input().split()))
inf = float("inf")
dp = [-inf] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    for j in a:
        cost_j = int("0255456376"[j])
        if i- cost_j >= 0:
            dp[i] = max(dp[i], j+dp[i-cost_j]*10)

ans = dp[n]
if ans == -inf:
    ans = 0
print(ans)



Measured memory_bytes: 14388
n, k = map(int, input().split())
hi = list(map(int, input().split()))

dp = [float('INF')] * n
dp[0] = 0

for i in range(n):
    for j in range(1, k+1):
        if n > i+j >= 0:
            dp[i+j] = min(dp[i+j], dp[i] + abs(hi[i] - hi[i+j]))

print(dp[-1])


Measured memory_bytes: 55264
#include<bits/stdc++.h>
#define foru(a,b,c) for(int a=b;a<=c;++a)
#define int long long
using namespace std;

int n,a[100001];
int h[100001];

main()
{
    cin >> n;
    foru(i,1,n) cin >> h[i];
    foru(i,2,n) a[i]=INT_MAX;
    a[1]=0;
    foru(i,1,n-1)
    {
        a[i+1]=min(a[i+1],a[i]+abs(h[i+1]-h[i]));
        a[i+2]=min(a[i+2],a[i]+abs(h[i+2]-h[i]));
    }
    cout << a[n];
}


Measured memory_bytes: 1792
n = int(input())

total = 10 ** n % (10 ** 9 + 7)
part1 = 2 * 9 ** n % (10 ** 9 + 7)
part2 = 8 ** n % (10 ** 9 + 7)

result = total - part1 + part2

if result < 10 ** 9 + 7:
    print(result % (10 ** 9 + 7))
elif result < (-(10 ** 9 + 7)):
    print(result % (10 ** 9 + 7) + (10 ** 9 + 7))
else:
    if result < 0:
        print(result + (10 ** 9 + 7))
    else:
        print(result)

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int main() {
  vvi c(3, vi(3));
  rep(i, 3) rep(j, 3) cin >> c[i][j];
  int maxi = 0;
  rep(i, 3) maxi = max(maxi, (int)*max_element(all(c[i])));
  maxi++;

  string res = "No";
  rep(k, maxi) rep(m, maxi) rep(n, maxi) {
    int a[3], b[3];
    a[0] = k, a[1] = m, a[2] = n;
    b[0] = c[0][0] - a[0], b[1] = c[1][1] - a[1], b[2] = c[2][2] - a[2];
    bool skip = false;
    rep(i, 3) if (b[i] < 0) skip = true;
    if (skip) continue;
    int cnt = 0;
    rep(i, 3) rep(j, 3) {
      if (c[i][j] != a[i] + b[j]) continue;
      cnt++;
    }
    if (cnt == 9) {
      res = "Yes";
      goto RES;
    }
  }

RES:
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, mn, a[300005], b[300005];
string s;
int main() {
	cin >> n >> s;
	mn = n * 2;
	for (int i = 1; i <= n; i ++) {
		a[i] = a[i - 1];
		b[i] = b[i - 1];
		if (s[i - 1] == 'E') a[i] ++;
		else b[i] ++;
	}
	for (int i = 1; i <= n; i ++)
		mn = min(mn, b[i - 1] + (a[n] - a[i]));
	cout << mn;
	return 0;
}


Measured memory_bytes: 2948
n = int(input())
txy = [[0,0,0] if i==0 else list(map(int,input().split())) for i in range(n+1)]

flag = True
for i in range(n):
	dist = abs(txy[i][1]-txy[i+1][1]) + abs(txy[i][2]-txy[i+1][2])
	time = txy[i+1][0] - txy[i][0]
	dif = time - dist
	if dif<0 or dif%2==1:			# 到達不可能
		flag = False
		break

print('Yes' if flag else 'No')


Measured memory_bytes: 27380
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n")
  tmp0 = input[0].split(" ")
  A = Number(tmp0[0])
  B = Number(tmp0[1])
  C = Number(tmp0[2])

  if((A<C && C<B) || (A>C && C>B)){
    console.log("Yes")
  }else{
    console.log("No")
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main("5 1\n00010\n")

Measured memory_bytes: 21192
N = int(input())
a = [int(i) for i in input().split()]
n2 = 0; n4 = 0
for ai in a:
    if ai%4 == 0:
        n4 += 1
    elif ai%2 == 0:
        n2 += 1

ans = "No"
if n4*2+1 >= N or n4*2 >= N-n2 or n2 == N:
    ans = "Yes"

print(ans)


Measured memory_bytes: 14252
#include <stdio.h>

int main(void)
{
    int a, b, i, j;

    while(1){

    scanf("%d %d", &a, &b);

    if(a == 0 && b == 0)
    break;

    for(i = 1; i <= a; i++)
    {
        for(j = 1; j <= b; j++)
        {
            printf("#");
        }

        printf("\n");
    }

    printf("\n");

    }

    return 0;
}


Measured memory_bytes: 2624
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 998244353;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    ll n, x, m;
    cin >> n >> x >> m;
    vector<bool> memo(m, false);
    vector<ll> kazu;
    kazu.push_back(x);
    ll ans = x;
    memo[x] = true;
    ll now = x;
    ll per = 0, cum = x;
    ll prev_val = 0;
    bool flag = false;
    for (ll i = 0; i < n-1LL; ++i) {
        prev_val = now;
        now = (now*now % m);
        if (memo[now]) {
            flag = true;
            if (now == (now*now % m)) {
                cout << ans + now* (n - 1 - i) << endl;
                return;
            }
            break;
        } else {
            memo[now] = true;
        }
        cum += now;
        kazu.push_back(cum);
        ans += now;
        ++per;
    }
    if (!flag) {
        cout << ans << endl;
    } else {
        ll ans_2 = 0, now_2 = x, cnt_2 = 0;
        while (now_2 != now) {
            /* cout << now_2 << " " <<  (now_2*now_2 % m) << endl; */
            cnt_2++;
            ans_2 += now_2;
            now_2 = (now_2*now_2 % m);
        }
        ll rem = n - cnt_2, cumnum = now;
        vector<ll> kazu_2;
        kazu_2.push_back(now);
        now_2 = (now_2*now_2 % m);
        cnt_2 = 1;
        while (now_2 != now) {
            cnt_2++;
            cumnum += now_2;
            kazu_2.push_back(cumnum);
            now_2 = (now_2*now_2 % m);
        }
        ans_2 += (rem / cnt_2) * cumnum;
        if ((rem % cnt_2) > 0) {
            ans_2 += kazu_2[(rem % cnt_2 ) -1];
        }
        cout << ans_2 << endl;
    }
}


int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



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

int main() {
  int H,W;
  cin >> H >> W;
  string S;
  for(int i = 0;i < H;i++)
  {
  	string str = "";
  	cin >> str;
  	S += str;
  }
  // i retu j ban ha S.at(H * j + i)
  // tonari 
  // (i-1,j-1)(  i,j-1)(i+1,j-1)
  // (i-1,  j)         (i+1,  j)
  // (i-1,j+1)(  i,j+1)(i+1,j+1)
  for(int k = 0;k < S.size();k++)
  {
  	int i = 0,j = 0,sum = 0;
  	i = k % W;
  	j = k / W;
  	if(S.at(k) == '#')
  	{
  		continue;
  	}
  	else
  	{
  		for(int l = i -1;l <= i + 1;l++)
  		{
  			if(l < 0 || l >= W)
  			{
  				continue;
  			}
  			else
  			{
  				for(int m = j - 1;m <= j+1 ;m++)
  				{
  					if(m < 0 || m >= H)
  					{
  						continue;
  					}
  					else
  					{
  						if(S.at(m*W+l) == '#')
  						{
  							sum++;
  						}
  					}
  				}
  			}
  		}
  	}
  //  cout << sum << endl;
   /* string q="";
    q = sum;
    cout << q << endl;*/
  	S.at(k) = to_string(sum).at(0);
   // cout << S << endl;
  }
   for(int n = 0;n < S.size();n++)
  {
  	if(n % W == W -1)
  	{
  		cout << S.at(n) << endl;
  	}
  	else
  	{
  		cout << S.at(n);
  	}
  }
}

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

void trace(vector<int> vec) {
    for(int i = 0; i < vec.size(); i++) {
        if(i > 0) cout << " ";
        cout << vec.at(i);
    }
    cout << endl;
}
void traceR(vector<int> vec) {
    for(int i = vec.size() - 1; i >= 0; i--) {
        cout << vec.at(i);
        if(i) cout << " ";
    }
    cout << endl;
}

void insertionSort(vector<int> &A, int n, int g, int &cnt) {
    int v, j;
    for(int i = g; i < n; i++) {
        v = A.at(i);
        j = i - g;
        while(j >= 0 && A.at(j) > v) {
            A.at(j + g) = A.at(j);
            j -= g;
            cnt++;
        }
        A.at(j + g) = v;
    }
}
void shellSort(vector<int> &A, int n) {
    int cnt = 0;
    int h = 1;
    vector<int> G;
    while(h <= n) {
        G.push_back(h);
        h = 3 * h + 1;
    }
    cout << G.size() << endl;
    traceR(G);

    for(int i = G.size() - 1; i >= 0; i--) {
        insertionSort(A, n, G.at(i), cnt);
    }
    cout << cnt << endl;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    shellSort(A, N);

    for(int i = 0; i < A.size(); i++) {
        cout << A.at(i) << endl;
    }
}


Measured memory_bytes: 6692
n,m=map(int,input().split())
A=[]
B=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
C=[]
D=[]
for i in range(m):
    c,d=map(int,input().split())
    C.append(c)
    D.append(d)

for i in range(n):
    d=100000000000000000
    for j in range(m):
        now=abs(A[i]-C[j])+abs(B[i]-D[j])
        if now<d:
            d=now
    for j in range(m):
        now=abs(A[i]-C[j])+abs(B[i]-D[j])
        if now==d:
            print(j+1)
            break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  long long int i,n,count=0,border;
  cin >> n;
  vector <long long int> a(n);
  for(i=0;i<n;i++)
  {
    cin >> a[i];
  }
  border=a[0];
  for (i=1;i<n;i++)
  {
    if(border > a[i])
    {
      count += border - a[i];
    }
    else if(border < a[i])
    {
      border = a[i];
    }
  }
  cout << count;
  return 0;
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back

using namespace std;

const int N  = 1e6 + 69, INF = 1e9, mod = 1e9 + 7;

const ll INFLL = 1e18;

int n, K;
ll dp[22][(1<<22)], A[30][30], sum[405][405];

int main(){

        cin >> n;

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

        for(int i = 0; i < n; i++){
                if(A[0][i] == 1){
                        dp[0][(1<<i)] = 1;
                }
        }

        for(int i = 0; i < n; i++){
                for(int mask = 0; mask < (1<<n); mask++){
                        if(!dp[i][mask]) continue;
                        for(int j = 0; j < n; j++){
                                if(mask&(1<<j) || !A[i+1][j]) continue;
                                dp[i+1][mask^(1<<j)] += dp[i][mask];
                                dp[i+1][mask^(1<<j)] %= mod;
                        }
                }
        }

        cout << dp[n-1][(1<<n)-1] << endl;

}


Measured memory_bytes: 334080
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

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

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

int main(void) {
	size_t N, K, X, Y;

	scanf("%zu\n%zu\n%zu\n%zu", &N, &K, &X, &Y);

	printf("%zu\n", X*MIN(N, K) + Y*(N <= K ? 0 : N - K));

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;


ll mod = 1000000000 + 7;

int main(){
    int N, M;

    cin >> N >> M;
    vi s(M), c(M);
    vi ans(N, 10);

    for (int i = 0; i < M; ++i) {
        cin >> s.at(i) >> c.at(i);
    }

    if(N==1 and M==0){
        cout << 0 << endl;
        return 0;
    }
    for(int i=0; i<M; i++){
        int d = ans.at(s.at(i)-1);
        if(d != c.at(i) and d != 10){
            cout << -1 << endl;
            return 0;
        }
        ans.at(s.at(i)-1) = c.at(i);
    }

    if(ans.at(0) == 0 and N !=1){
        cout << -1 << endl;
        return 0;
    }

    if(ans.at(0) == 10){
        ans.at(0) = 1;
    }
    int sum = 0;
    for(int i=0; i<N; i++){
        if(ans.at(i) == 10){
            ans.at(i) = 0;
        }
        sum += ans.at(i)*(int)pow(10, N-i-1);
    }

    cout << sum << endl;
}

Measured memory_bytes: 512
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}

const ll N=2e5+5;

ll sp[N];

void sieve(){
  for(int i=2;i<N;i++)sp[i]=i;

    for(int i=2;i*i<N;i++){
      if(sp[i]==i){
      for(int j=i*i;j<N;j+=i){
        sp[j]=i;
      }
    }
}

}
/*
//ll fac[N],inv[N];

ll p=1e9+7;

void fill(){
  fac[0]=inv[0]=1;

  for(int i=1;i<N;i++){
    fac[i]=fac[i-1]*i%p;
  }
}

*/

vl cr(ll x){
  vl d;
  while(x){
    d.pb(x%10);
    x/=10;
  }
  return d;
}

void mul(vl& a , ll n){
ll carry=0;
  for(auto& x:a){
carry+=x*n;
x=carry%10;
carry/=10;
  }
  while(carry){
    a.pb(carry%10);
    carry/=10;
  }
}

ll a[26];
int main()
{ 

  IOS;


ll n,m,k;

cin>>n>>m>>k;

vl a(n+1),b(m+1);

vl pa(n+1),pb(m+1);

for(int i=1;i<=n;i++){
  cin>>a[i];
  pa[i]+=pa[i-1]+a[i];
}

for(int i=1;i<=m;i++){
  cin>>b[i];
  pb[i]+=pb[i-1]+b[i];
}

ll ans=0;

for(int i=0;i<=n;i++){
  ll x=pa[i];
  if(x>k)break;
  ll rem=k-x;

  ll ind=upper_bound(all(pb),rem)-pb.begin();

//if(i==2)cout<<ind<<endl;

if(ind!=0)ind--;

ans=max(ans,i+ind);



}

cout<<ans<<endl;

return 0;
 
}



Measured memory_bytes: 9516
#include <stdio.h>

int main(void)
{
  int h,m,s;

 scanf("%d",&s);
 h=s/60/60;
 m=(s-h*60*60)/60;
 s=s-h*60*60-m*60;
 printf("%d:%d:%d\n",h,m,s);

  return 0;
}

Measured memory_bytes: 592
#include <stdio.h>

int main(void) {
    int n,k,na;
    long long kari,ans = 0;
    scanf("%d %d",&n,&k);
    if (k % 2 == 0) {
        kari = n / k;
        ans = kari * kari * kari;
        na = n + k / 2;
        kari = na / k;
        ans += kari * kari * kari;
    } else {
        kari = n / k;
        ans = kari * kari * kari;
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
    
    int H, W;
    
    while(true){
        
        cin >> H >> W;
        
        if(H == 0 && W == 0) break;
        
        for(int i = 0; i < H; ++i){
            
            if(i == 0 || i == H - 1){
                
                for(int k = 0; k < W; ++k) cout << "#";
            }else {
                
                for(int k = 0; k < W; ++k){
                    
                    if(k == 0 || k == W -1){
                        
                        cout << "#";
                    }else {
                        
                        cout << ".";
                    }
                }
            }
                
                cout << endl;
        }
        
        cout << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3088
S = input()
T = input()
Slen = len(S) + 1
Tlen = len(T) + 1

DP = []
for _ in range(Tlen):
    DP.append([0] * Slen)


for t in range(1, Tlen):
    for s in range(1, Slen):
        if S[s-1] == T[t-1]:
            DP[t][s] = DP[t-1][s-1] + 1
        else:
            DP[t][s] = max(DP[t][s-1], DP[t-1][s])


ans = ""
i = len(S)
j = len(T)
while i > 0 and j > 0:
    if DP[j][i] == DP[j-1][i]:
        j -= 1
    elif DP[j][i] == DP[j][i-1]:
        i -= 1
    else:
        i -= 1
        j -= 1
        ans += S[i]

print(ans[::-1])


Measured memory_bytes: 112220
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
void yes(){
  cout << "Yes" << endl;
  exit(0);
}

void no(){
  cout << "No" << endl;
  exit(0);
}

int main() {
  string s,t; cin >> s >> t;
  ll n = s.size();
  s = s + s;
  REP(i, n){
    REP(j, n){
      if(s[i+j] != t[j]) break;
      if(j == n-1) yes();
    }
  }
  no();
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n==1) cout<<1<<endl;
    if(n>=2&&n<4) cout<<2<<endl;
    if(n<8&&n>=4) cout<<4<<endl;
    if(n<16&&n>=8) cout<<8<<endl;
    if(n<32&&n>=16) cout<<16<<endl;
    if(n<64&&n>=32) cout<<32<<endl;
    if(n<128&&n>=64) cout<<64<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    int i, j, k, l;
    int input;
    int count;
    while(scanf("%d",&input)==1)
    {
        count = 0;
        for(i=0; i<=9; i++)
            for(j=0; j<=9; j++)
                for(k=0; k<=9; k++)
                    for(l=0; l<=9; l++)
                    {
                        if((i+j+k+l)==input)
                            count++;
                    }
        printf("%d\n",count);
    }

    return 0;
}

Measured memory_bytes: 1188
N, M = gets.chomp.split(" ").map(&:to_i)
C = Hash.new{|h, k| h[k] = []}
D = []
M.times{
  p, y = gets.chomp.split(" ").map(&:to_i)
  C[p] << y
  D << [p, y]
}

C.keys.each{|k|
  C[k].sort!
}

D.each{|p, y|
  printf("%06d%06d\n", p, C[p].bsearch_index{|x| x >= y} + 1)
}


Measured memory_bytes: 23548
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


use std::collections::HashSet;

fn main() {
    input! {
        s: i32,
    }
    
    let mut set = HashSet::new();
    
    let mut a = s;
    for m in 1..1000000 {
        if (set.contains(&a)) {
            println!{"{}", m};
            break;
        }
        
        set.insert(a);
        a = match a % 2 {
            0 => a / 2,
            _ => 3 * a + 1,
        };
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int x;
    cin >> x;
    for(int i = 1; i <= 360; i++) {
        if ((x*i)%360 == 0) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

#define B       (cout << "Sehen Sie mich!" << endl)
#define VB(val) (cout << val << endl)

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

        sort(s.begin(), s.end());
        sort(t.rbegin(), t.rend());

        if (s.length() < t.length()) {
                for (int i = 0; i < (int)s.length(); i++) {
                        if (s[i] != t[i])
                                goto next;
                }
                VB("Yes");
                return 0;
        }

next:
        for (int i = 0; i < (int)s.length(); i++) {
                if (s[i] < t[i]) {
                        VB("Yes");
                        return 0;
                }
                if (s[i] == t[i]) {
                        continue;
                }
        }
out:
        VB("No");
}

Measured memory_bytes: 256
import heapq
N=int(input())
A=list(map(int, input().split()))
A_rev = [-x for x in A[::-1]] #逆順にして各要素を-1倍する
left, right = A[:N], A_rev[:N]
sum_left_list, sum_right_list = [0]*(N+1), [0]*(N+1)
sum_left, sum_right = sum(left), sum(right)
sum_left_list[0], sum_right_list[0]=sum_left, sum_right
heapq.heapify(left)
heapq.heapify(right)
#left: k=N, N+1,..., 2N-1まで動かして大きい方からN個の和を求める
for k in range(N, 2*N):
	val=A[k]
	heapq.heappush(left, val)
	min_val = heapq.heappop(left)
	sum_left += val
	sum_left -= min_val
	sum_left_list[k-N+1] = sum_left

#right: k=N, N+1,..., 2N-1まで動かして大きい方からN個の和を求める
for k in range(N, 2*N):
	val = A_rev[k]
	heapq.heappush(right, val)
	min_val = heapq.heappop(right)
	sum_right += val
	sum_right -= min_val
	sum_right_list[k-N+1] = sum_right
sum_right_list=sum_right_list[::-1]

ans=-float("inf")
for i in range(N+1):
	ans=max(ans, sum_left_list[i]+sum_right_list[i])
print(ans)

Measured memory_bytes: 130020