akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	double a, b, h, m;
	double pi= 3.141592653589793;
	cin >> a >> b >> h >> m;
	double ax, ay, bx, by;

	h += m / 60;
	h = (h - 3);
	if (h < 0) {
		h += 12;
	}
	ax = a * cos( h * 30 * pi / 180 );
	ay = a * sin( h * 30 * pi / 180 );

	m = m - 15;
	if (m < 0) {
		m += 60;
	}
	bx = b * cos(m * 6 * pi / 180);
	by = b * sin(m * 6 * pi / 180);

//	cout << ax << " / " << ay << endl;
//	cout << bx << " / " << by << endl << endl;

	double ans;
	ans = (bx - ax)*(bx - ax) + (by - ay)*(by - ay);
	ans = sqrt(ans);
	printf("%.11lf\n", ans);
	return 0;
}


Measured memory_bytes: 4128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for(int i = 0; i < n; i++) list.add(sc.nextInt());
        ArrayList<Integer> list1 = (ArrayList<Integer>)list.clone();
        list1.stream().distinct();
        Collections.sort(list1);
        Integer a = list1.get(list1.size() - 1);
        Integer b = list1.get(list1.size() - 2);
        for(int i = 0; i < n; i++){
            if(list.get(i) == a)    System.out.println(b);
            else if(list.get(i) == b)    System.out.println(a);
            else System.out.println(a);
        }
    }
}

Measured memory_bytes: 96944
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int in;
    int h,m,s;
    scanf("%d",&in);
    
    h = in / 3600;
    in %= 3600;
    
    m = in / 60;
    in %= 60;
    
    s = in;
    
    printf("%d:%d:%d\n",h,m,s);
}

Measured memory_bytes: 1812
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

ll A[300000];

ll N, K;

bool can_clear(ll index){
    ll sum=0;
    rep(i, N){
        sum+=max((A[i]-1)/index, (ll)0);
        //cout<<A[i]<<sp<<max((A[i]-1)/index, (ll)0)<<endl;
    }
    //cout<<endl;
    return (sum<=K);
}
//条件に合致する最小indexを二分探索 O(logN)
//1...全indexがみたす -1...条件に合致するものがない
ll nibutan_min(ll min, ll max){
  //評価関数can_clear(ll　value) を指定すること
  ll left=min, right=max;
  while(true){
      //cout<<left<<" " <<right<<endl; //debug用
      if(left+1==right){
        if(can_clear(left)){
          if(left==min) return 1;
          else return left;
        }
        else{
          if(can_clear(right)) return right;
          else return -1;
        }
        break;
      }
      ll nibutan=(left+right)/2;
      bool can_do_it=can_clear(nibutan);
      if(can_do_it) right = nibutan;
      else left = nibutan;
  }
}


int main(void){
    cin>>N>>K;
    rep(i, N) cin>>A[i];
    cout<<nibutan_min(1, 1000000000)<<endl;
    return 0;
}


Measured memory_bytes: 5160
n = gets.to_i
ans = 0
a = b = c = 0
n.times do
    s = gets.chomp
    if s[0] == "B" && s[-1] == "A"
        c += 1
    elsif s[0] == "B"
        b += 1
    elsif s[-1] == "A"
        a += 1
    end
    (s.size-1).times do |i|
        ans += 1 if s[i,2] == "AB"
    end
end
if c > 0
    if a > 0
        ans += c
        a -= 1
        if b > 0
            ans += 1
            b -= 1
        end
        ans += [a,b].min
    else
        if b > 0
            ans += c
        else
            ans += c-1
        end
    end
else
    ans += [a,b].min
end
puts ans

Measured memory_bytes: 3836
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long length[] = new long[num];
		long max = 0;
		long sum = 0;
		for(int i = 0; i < num; i ++) {
			length[i] = sc.nextInt();
			max = Math.max(max, length[i]);
			sum += length[i];
		}
		sum -= max;
		boolean canDraw = max < sum;
		System.out.println(canDraw ? "Yes" : "No");
	}
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
/*cout <<"Debug"
cout <<x-30<<' '<<y-30<<endl;*/
vector<string>v;
vector<int>ansl;
string s;
int ary[100005] = {0};
int mp[200][200];
int cnt = 0;
int d_x[] = {1, 1, 0, -1, -1, 0};
int d_y[] = {1, 0, -1, -1, 0, 1};
int t;
/*
void dfs(int x,int y,int lpcnt){
  mp[x][y] = 1;
  cout <<"Debug ";
  cout <<x-30<<' '<<y-30<<endl;
  cnt++;
  lpcnt++;
  int watasi = lpcnt;
  int used[6] = {0};
  for(int dx = 0;dx<6;dx++){
    int nx = x+d_x[dx],ny = y+d_y[dx];
    int dft = sqrt((nx-30)*(nx-30)+(ny-30)*(ny-30));
    if((dft<=30)&&(watasi < t)&&(mp[nx][ny] == 0)){
        dfs(nx,ny,watasi);
        used[dx] = 1;
    }
    for(int i = 0;i<6;i++){
      if(used[i]){
        if((nx == x + d_x[i])&&(ny == y + d_y[i])){
          dfs(nx,ny,watasi);
        }
      }
    }
    }
}
*/
int main(){
  int n,t;

  cin >>t>>n;
  while(!((t == 0)&&(n == 0))){
    int fx,fy;
    cnt = 0;
    for(int i = 0;i<200;i++){
      for(int j = 0;j<200;j++){
        mp[i][j]=-1;
      }
    }
    for(int i = 0;i<n;i++){
      int x,y;
      cin >>x>>y;
      mp[x+100][y+100] = 1;
    }
    cin >>fx>>fy;

    cnt = 0;

    queue< pair<int, int> > qu;
    qu.push(make_pair(fx+100,fy+100));
    mp[fx+100][fy+100] = 0;
    while (!qu.empty()) {
      pair<int ,int> pr = qu.front();
      qu.pop();
      int nx = pr.first,ny= pr.second;
      cnt++;
      if(mp[nx][ny] == t)continue;
      for(int i = 0;i<6;i++){
        int cx = nx+d_x[i],cy = ny+d_y[i];
        if(mp[cx][cy] != -1)continue;
        mp[cx][cy] = mp[nx][ny] + 1;
        qu.push(make_pair(cx,cy));
      }
    }

    cout <<cnt<<endl;
    cin >>t>>n;
  }
  return 0;
}



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

typedef long long int ll;
long double pi=3.141592653589793238462643383279502884197169399375105820974944592307816406286 ;

int main()
{
	ll a,b,h,m;
	scanf("%lld %lld %lld %lld",&a,&b,&h,&m);
	long double ans=0;
	ans= a*a+b*b-2*a*b*cos((pi*h)/6+(m*pi)/360-(m*pi)/30);
	cout << setprecision(10) << fixed<<sqrt(ans);
	printf("\n");
}



Measured memory_bytes: 4228
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int A; cin >> A;
	if (A % 2 == 0) cout << (A / 2) * (A / 2) << endl;
	else cout << ((A / 2) + 1) * (A / 2) << endl;
	return;
}
int main() {
	solve();
	return 0;
}

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

int main() {
   int N;int sum=0;
   cin>>N;
   vector<int> card(N);
   for(int i=0;i<N;i++){
       cin>>card.at(i);
   }sort(card.begin(),card.end());
   for(int j=N-1;j>=0;j--){
       if((N-j)%2==0){
           sum=sum-card.at(j);
       }else{
           sum=sum+card.at(j);
       }
   }cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

vector<int> G[100'010];

int dfs(int v, vector<int>& dp, int p = -1){
  
  if(dp[v] >= 0) return dp[v];
  
  int deg = G[v].size();
  if(v != 0 && deg == 1) return dp[v] = 0;
  vector<int> temp;
  for(int nv: G[v]){
    if(nv == p) continue;
    temp.push_back(dfs(nv, dp, v));
  }
  sort(ALL(temp), greater<int>());
  int res = -1;
  int k = temp.size();
  REP(i, k) res = max(res, temp[i] + i + 1);
  return dp[v] = res;
}

int main(){
  //using namespace std;
  int n;
  cin>>n;
  int a[n];
  for(int i = 1; i < n; i++){
    cin>>a[i];
    a[i]--;
  }
  
  for(int i = 1; i < n; i++){
    G[i].push_back(a[i]);
    G[a[i]].push_back(i);
  }
  
  vector<int> dp(n, -1);
  dfs(0, dp);
  int ans = dp[0];
  cout << ans << endl;  
  return 0;
}


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

signed main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int g = abs(a - c), h = abs(b - d);
    int ans = g + h - __gcd(g, h);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll cnt=0;
    ll n,k;cin>>n>>k;
    if(k==0)cnt+=n*(n-1)/2;
    else cnt+=(n-k+1)*(n-k)/2;
    REP(i,k+1,n+1){
        cnt+=(i-k)*(max(0LL,n/i-1))+max(0LL,n%i-k+1);
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 384
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict as dd
from math import log,ceil

def main():
    n=int(input())
    l=ceil((log(25*n+26)/log(26)))-1
    d=n-26*(pow(26,l)-1)//25-1
    s=''
    for i in range(int(l)):
        s=chr(97+int(d)%26)+s
        d//=26
    print(s)
    



BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")


if __name__ == "__main__":
    main()



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

void solve() {
	int x, y, w, h;
	cin >> x >> y >> w >> h;

	int n;
	cin >> n;

	int cnt = 0;
	while(n--) {
		int cx, cy;
		cin >> cx >> cy;

		if(x <= cx && cx <= x + w && y <= cy && cy <= y + h) {
			++cnt;
		}
	}
	cout << cnt << endl;
}

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

	int t;
	cin >> t;
	while(t--) solve();

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1196
#include <stdio.h>

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

int main(){
	int N;
	char s[10001][12];
	char dm;
	scanf("%d",&N);
	scanf("%c",&dm);
	int i;
	int j;
	i=1;
	j=1;
	int p;
	while(i<=N){
		int e;
		e=0;
		while(e==0){
			p=scanf("%c",&s[i][j]);
			if(p==EOF){
				s[i][j]='\n';
			}
			if(s[i][j]=='\n'){
				i=i+1;
				e=1;
				j=1;
			}
			if(e==0){
				j=j+1;
			}
		}
	}
	int a;
	a=0;
	int ans;
	ans=0;
	int f;
	f=0;
	int b;
	b=0;
	int c;
	c=0;
	for(i=1;i<=N;i++){
		if(s[i][1]=='B'){
			f=f+1;
		}
		for(j=1;j<=10;j++){
			if(s[i][j]=='A'&&s[i][j+1]=='B'){
				a=a+1;
			}
			if(s[i][j]=='A'&&s[i][j+1]=='\n'){
				b=b+1;
				if(s[i][1]=='B'){
					c=c+1;
					b=b-1;
					f=f-1;
				}
			}
		}
		ans=ans+a;
		a=0;
	}
	ans=ans+min(f,b)+c;
	if(f==0&&b==0&&c>0){
		ans=ans-1;
	}
	printf("%d",ans);
}


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

string Shuffle ( string s, int h )
{
	string head = s.substr ( 0 , h );
	string tail = s.substr ( h , s.size()-h );
    return tail + head;
}
int main()
{
	string s;
	int m, h;

	for ( int i = 0; i <100; i++ )
	{
		cin >> s;
		if ( s == "-" )
		{
			break;
		}

		cin >> m;
		for ( int k = 0; k < m; k++ )
		{
			cin >> h;
			s = Shuffle(s ,h);
	    }
		cout << s << endl;
	}	
	return 0;
}


Measured memory_bytes: 3172
N = int(input())
A = list(map(int,input().split()))

judge = 1
for i in range(N):
  if(A[i]%2 == 0):
    if((A[i]%3 != 0)and(A[i]%5 != 0)):
      judge = 0
      break

if(judge == 1):
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 3060
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

int N;
vector<int> G[100010];

int dp(int v) {
    if (G[v].empty()) {
        return 0;
    }

    vector<int> d;
    for (int ch : G[v]) {
        d.push_back(dp(ch));
    }
    sort(all(d), greater<>());
    rep(i, 0, d.size()) { d[i] += i + 1; }

    return *max_element(all(d));
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    read(N);
    rep(i, 1, N) {
        var(int, v);
        --v;
        G[v].push_back(i);
    }

    print(dp(0));

    return 0;
}


Measured memory_bytes: 13568
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RDLU
int main(){
	int n,m;
	cin>>n>>m;
	vs in(n);
	rep(i,n)cin>>in[i];
	vi a(n),b(m);
	rep(i,n)rep(j,m)if(in[i][j]=='#')a[i]=b[j]=1;
	rep(i,n)if(a[i]){rep(j,m)if(b[j])cout<<in[i][j];cout<<endl;}
}



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

using namespace std;

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> a(n), b(m);
    for (int i = 0; i < n; ++i) cin >> a.at(i);
    for (int i = 0; i < m; ++i) cin >> b.at(i);
    cout << ((*max_element(a.begin(), a.end()) >= *min_element(b.begin(), b.end()) || *max_element(a.begin(), a.end()) >= y || *min_element(b.begin(), b.end()) <= x) ? "War" : "No War") << endl;
    return 0;
}


Measured memory_bytes: 384
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};

int main() {
	ll n;
	cin >> n;
	ll i = 0;
	while (i*(i + 1) / 2 < n) {
		i++;
	}
	ll e = i * (i + 1) / 2 - n;
	REP(j, 1, i) {
		if (j != e) {
			cout << j << endl;
		}
	}
}

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

int n;
vector<vector<pair<int,int>>> edge(MAX);
vector<int> vs(MAX);

void dfs(int v, int color, int parent)
{
  for (auto e : edge[v]) {
    int to = e.first, dist = e.second;
    
    if (to == parent) continue;
    
    int next_color;

    if (dist % 2 == 0) next_color = color;
    else next_color = color ^ 1;
    vs[to] = next_color;

    dfs(to, next_color, v);
  }
}

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

  cin >> n;
  for (int i = 0; i < n-1; ++i) {
    int u, v, w;
    cin >> u >> v >> w;

    edge[u-1].emplace_back(v-1, w);
    edge[v-1].emplace_back(u-1, w);
  }

  dfs(0, 0, -1);
  for (int i = 0; i < n; ++i) cout << vs[i] << '\n';

  return (0);
}


Measured memory_bytes: 11020
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll p=1000000007;
int main() {
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    int l=s.size(),i=0;
    s+="0";
    int total=0,carry=0;
    while(i<l) {
        int c=(int)s[i]-'0'+carry;
        carry=0;
        if(c==0) {
            i++;
            continue;
        }
        if(c<=4||c==5&&(int)s[i + 1]-'0'<5) {
            total+=c;
            i++;
            continue;
        }
        carry=1;
        total+=10-c;
        i++;
        while(i<l&&(int)s[i]-'0'==9)i++;
    }
    cout<<total+carry<<endl;
    return 0;
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
int p[110],c[110];
int main()
{
    ios::sync_with_stdio(false);
    int D,G;
    while(cin>>D>>G)
    {
        for(int i=0;i<D;i++)
            cin>>p[i]>>c[i];
        int res=INT_MAX;
        for(int i=0;i<(1<<D);i++)
        {
            int s=0,cnt=0,pos=-1;
            for(int j=0;j<D;j++)
                if(i&(1<<j))
                {
                    s+=p[j]*100*(j+1)+c[j];
                    cnt+=p[j];
                }
                else
                    pos=j;
            if(s<G)
            {
                int x=(G-s+100*pos+99)/(100*pos+100);
                if(x>=p[pos])
                    continue;
                cnt+=x;
            }
            res=min(res,cnt);
        }
        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            String O = in.next();
            String E = in.next();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < E.length(); i++) {
                sb.append(O.charAt(i));
                sb.append(E.charAt(i));
            }
            if (O.length() > E.length()) {
                sb.append(O.charAt(O.length() - 1));
            }
            System.out.println(sb.toString());
        }
    }
}


Measured memory_bytes: 22996
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let [n,k]=t.n(2)
  let c=0
  for (let i = 0; i < n; i++)if(t.n() >= k)c++;
  t.o(c)
}
main()

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

map<char, string> mp;
map<string, char> mp2;
vector<string> v;

void init() {
  mp['A'] = "00000";
  mp['B'] = "00001";
  mp['C'] = "00010";
  mp['D'] = "00011";
  mp['E'] = "00100";
  mp['F'] = "00101";
  mp['G'] = "00110";
  mp['H'] = "00111";
  mp['I'] = "01000";
  mp['J'] = "01001";
  mp['K'] = "01010";
  mp['L'] = "01011";
  mp['M'] = "01100";
  mp['N'] = "01101";
  mp['O'] = "01110";
  mp['P'] = "01111";
  mp['Q'] = "10000";
  mp['R'] = "10001";
  mp['S'] = "10010";
  mp['T'] = "10011";
  mp['U'] = "10100";
  mp['V'] = "10101";
  mp['W'] = "10110";
  mp['X'] = "10111";
  mp['Y'] = "11000";
  mp['Z'] = "11001";
  mp[' '] = "11010";
  mp['.'] = "11011";
  mp[','] = "11100";
  mp['-'] = "11101";
  mp['\''] = "11110";
  mp['?'] = "11111";

  mp2["101"] = ' ';
  mp2["000000"] = '\'';
  mp2["000011"] = ',';
  mp2["10010001"] = '-';
  mp2["010001"] = '.';
  mp2["000001"] = '?';
  mp2["100101"] = 'A';
  mp2["10011010"] = 'B';
  mp2["0101"] = 'C';
  mp2["0001"] = 'D';
  mp2["110"] = 'E';
  mp2["01001"] = 'F';
  mp2["10011011"] = 'G';
  mp2["010000"] = 'H';
  mp2["0111"] = 'I';
  mp2["10011000"] = 'J';
  mp2["0110"] = 'K';
  mp2["00100"] = 'L';
  mp2["10011001"] = 'M';
  mp2["10011110"] = 'N';
  mp2["00101"] = 'O';
  mp2["111"] = 'P';
  mp2["10011111"] = 'Q';
  mp2["1000"] = 'R';
  mp2["00110"] = 'S';
  mp2["00111"] = 'T';
  mp2["10011100"] = 'U';
  mp2["10011101"] = 'V';
  mp2["000010"] = 'W';
  mp2["10010010"] = 'X';
  mp2["10010011"] = 'Y';
  mp2["10010000"] = 'Z';
  
  v.emplace_back("101");
  v.emplace_back("000000");
  v.emplace_back("000011");
  v.emplace_back("10010001");
  v.emplace_back("010001");
  v.emplace_back("000001");
  v.emplace_back("100101");
  v.emplace_back("10011010");
  v.emplace_back("0101");
  v.emplace_back("0001");
  v.emplace_back("110");
  v.emplace_back("01001");
  v.emplace_back("10011011");
  v.emplace_back("010000");
  v.emplace_back("0111");
  v.emplace_back("10011000");
  v.emplace_back("0110");
  v.emplace_back("00100");
  v.emplace_back("10011001");
  v.emplace_back("10011110");
  v.emplace_back("00101");
  v.emplace_back("111");
  v.emplace_back("10011111");
  v.emplace_back("1000");
  v.emplace_back("00110");
  v.emplace_back("00111");
  v.emplace_back("10011100");
  v.emplace_back("10011101");
  v.emplace_back("000010");
  v.emplace_back("10010010");
  v.emplace_back("10010011");
  v.emplace_back("10010000");
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  init();
  string s;
  while (getline(cin, s)) {
    string tmp = "";
    for (int i = 0; i < (int)s.size(); i++) {
      tmp += mp[s[i]];
    }
    s = tmp;
    int pos = 0;
    string ans = "";
    while (true) {
      bool find = false;
      for (int i = 0; i < 32; i++) {
        string t = v[i];
        if (s.substr(pos, t.size()) == t) {
          ans += mp2[t];
          pos += t.size();
          find = true;
        }
      }
      if (!find) break;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  for (int _ = 0; _ < n; ++_) {
    double xa, ya, xb, yb; cin >> xa >> ya >> xb >> yb;
    double th0 = atan2(yb - ya, xb - xa);
    double xc, yc, xd, yd; cin >> xc >> yc >> xd >> yd;
    double th1 = atan2(yd - yc, xd - xc);
    cout << (abs(tan(th1) - tan(th0)) < 1e-10 ? "YES" : "NO") << '\n';
  }
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define IT iterator
#define vi vector<int>
#define TP template<class o>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N=2010,size=1<<20,mod=(int)1e9+7,inf=2e9;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
    char c=gc; x=0; int f=1;
    while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
    while(isdigit(c)) x=x*10+c-'0',c=gc;
    x*=f;
}
template<class o> void qw(o x) {
    if(x/10) qw(x/10);
    putchar(x%10+'0');
}
template<class o> void pr1(o x) {
    if(x<0)x=-x,putchar('-');
    qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
    if(x<0)x=-x,putchar('-');
    qw(x); putchar('\n');
}

int n;
ll f[N][N],ans;

ll power(ll a,ll b=mod-2) {
	ll c=1;
	while(b) {
		if(b&1) c=c*a%mod;
		b /= 2; a=a*a%mod;
	}
	return c;
}

void ad(ll &x,ll y) {x=(x+y)%mod;}

int main() {
	qr(n); 
	f[0][0]=1;
	for(int i=1;i<=n/3;i++) {
		for(int j=1;j<=n;j++) ad(f[i-1][j],f[i-1][j-1]);
		for(int j=n;j>=3*i;j--) f[i][j]=f[i-1][j-3];
		ad(ans,f[i][n]);
	}
	pr2(ans);
	return 0;
}


Measured memory_bytes: 13984
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define mod 998244353
#define int long long
using namespace std;
const int N=3*1e5+100;
int n,cnt[5],ans,vi[N],id[30];
char s[N];
vector <int> p[N];
signed main()
{
	id['R'-'A']=1;id['B'-'A']=2;id['G'-'A']=3;
	scanf("%lld",&n);
	scanf("%s",s+1);
	for (int i=1;i<=3*n;i++) p[id[s[i]-'A']].push_back(i);
	sort(p[1].begin(),p[1].end());
	sort(p[2].begin(),p[2].end());
	sort(p[3].begin(),p[3].end());
	for (int i=0;i<n;i++)
	{
		int MAX=0,MIN=inf;
		for (int j=1;j<=3;j++) MAX=max(MAX,p[j][i]),MIN=min(MIN,p[j][i]);
		vi[MAX]=1;
		vi[MIN]=3;
		for (int j=1;j<=3;j++) if (p[j][i]!=MAX && p[j][i]!=MIN) vi[p[j][i]]=2;		
	}
	ans=1;
	cnt[3]=n;
	for (int i=1;i<=3*n;i++)
	{
		ans=(ans*cnt[vi[i]])%mod;
		cnt[vi[i]]--;cnt[vi[i]-1]++;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 15320
#include<iostream>
#include<algorithm>

using namespace std;

int a[200005];
int d[200005];

int main(void)
{
    int k,n; cin>>k>>n;
    for(int i=0;i<n;++i) {
        cin>>a[i];
        if(i>=1) d[i] = a[i]-a[i-1];
    }
    d[0] = a[0]+(k-a[n-1]);
    sort(d,d+n);
    cout<<k-d[n-1];
    return 0;
}

Measured memory_bytes: 1792
from collections import Counter
def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    B = [0]
    for a in A:
        B.append((B[-1]+a)%M)
    c = Counter(B)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 16556
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long x = sc.NextLong();
        long y = sc.NextLong();

        long answer = 1;
        long before = x;
        while (true)
        {
            long after = before * 2;
            if (after <= y)
            {
                answer++;
            }
            else
            {
                break;
            }
            before = after;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
#define mod 1e9 + 7;

int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr); 
	cout.tie(nullptr); 
	cout.setf(ios::fixed); 
	cout.precision(20);

	ll n;
	cin >> n;
	map<ll, ll> mp;
	vll v(n);
	rep(i, n) {
		cin >> v[i];
	}
	sort(all(v));
	/*rep(i, n) {
		cout << v[i];
	}*/
	ll ans = 1;
	rep(i, n - 1) {
		if (v[i] != v[i + 1]) {
			ans++;
			//cout << v[i] << " " << v[i + 1] << endl;
		}
	}
	if (ans % 2 == 0)ans--;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

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

string tile[20];

int w, h;

int dfs(int x, int y){
	int ret = 1;
	if (tile[x][y] == '#') return 0;
	tile[x][y] = '#';

	for (int i = 0; i < 4; i++){
		if (x + dx[i] < 0 || x + dx[i] >= h) continue;
		if (y + dy[i] < 0 || y + dy[i] >= w) continue;
		ret += dfs(x + dx[i], y + dy[i]);
	}
	return ret;
}

int main(){
	while (cin >> w >> h,w){
		int x, y;
		for (int i = 0; i < h; i++){
			cin >> tile[i];
			for (int j = 0; j < w; j++){
				if (tile[i][j] == '@'){
					x = i;
					y = j;
				}
			}
		}
		cout << dfs(x, y) << endl;
	}
}

Measured memory_bytes: 1224
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for num_500 in range(0, a + 1):
    for num_100 in range(0, b + 1):
        for num_50 in range(0, c + 1):
            if num_500 * 500 + num_100 * 100 + num_50 * 50 == x:
                count += 1
                break
print(count)


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

using namespace std;

bool comp(pair<pair<string, int>, int> &a, pair<pair<string, int>, int> &b)
{
	if (a.first.first < b.first.first){
		return true;
	}else if((a.first.first == b.first.first) && (a.first.second > b.first.second)){
		return true;
	}
	return false;
}

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

	vector< pair<pair<string, int>, int> > vec;
	for(int i=0;i<n;i++){
		pair<string, int> p;
		cin >> p.first >> p.second;
		vec.push_back(make_pair(p, i+1));
	}

	sort(vec.begin(), vec.end(), comp);

	for(int i=0;i<n;i++){
		cout << vec[i].second << endl;
	}

		
	return 0;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){

	int n;
	cin >> n;

	int a[n], b[n];
	FOR(i, n){
		cin >> a[i];
		b[i] = a[i];
	}
	
	sort(b, b+n, greater<int>());

	FOR(i, n){
		if(a[i] == b[0]){
			cout << b[1] << endl;
		} else {
			cout << b[0] << endl;
		}
	}

    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,a,b,c[10009],d[10009],num;
vector<int> e[10009];

void dfs(int node){
	d[node]=c[num];
	num++;
	for(int i=0;i<e[node].size();i++){
		if(!d[e[node][i]])dfs(e[node][i]);
	}
}

int main(){
    cin>>n;
	for(int i=1;i<n;i++){
		cin>>a>>b;
		e[a].push_back(b);
		e[b].push_back(a);
	}int M=0;
	for(int i=0;i<n;i++){
		cin>>c[i];
		M+=c[i];
	}
	sort(c,c+n,greater<int>());
	cout<<M-c[0]<<endl;
	dfs(1);
	for(int i=1;i<=n;i++){
		if(i-1)cout<<" ";
		cout<<d[i];
	}
	cout<<endl;
    return 0;
}


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

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      long N = sc.nextLong();
      for(int w = 1; w <= 3500; w++) {
        for(int h = 1; h <= 3500; h++) {
          if((4 * h * w - w * N - h * N) > 0 && 
            N * h * w % (4 * h * w - w * N - h * N) == 0) {
            System.out.println(w + " " + h + " " + (N * h * w / (4 * h * w - w * N - h * N)));
            return;
          }
        }
      }
      
  }
}

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

typedef long long ll;

ll inf = 1000000010;
ll v_M = 100001;

int main() {
    ll N, W;    cin >> N >> W;
    ll *w = new ll[N], *v = new ll[N];

    for (ll i = 0; i < N; i++)
        cin >> w[i] >> v[i];

    ll **dp = new ll *[N+1];
    for (ll i = 0; i <= N; i++) {
        dp[i] = new ll[v_M];
        for (int j = 0; j < v_M; j++) {
            dp[i][j] = inf;
        }
    }

    for (int i = 0; i <= N; i++)
        dp[i][0] = 0;
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < v_M; j++) {
            if (j - v[i] >= 0) {
                dp[i+1][j] = min(dp[i][j-v[i]] + w[i], dp[i][j]);
            }
            else 
                dp[i+1][j] = dp[i][j];
        }
    }

    ll i = v_M-1;
    while (i >= 0 && dp[N][i] > W)
        i--;

    cout << i << endl;
    return 0;
}

Measured memory_bytes: 81408
def resolve():
    import bisect
    n,m,k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    cuma = [0]
    cumb = [0]
    for i in range(n):
        cuma.append(cuma[-1]+ a[i])
    for i in range(m):
        cumb.append(cumb[-1] + b[i])

    ans = 0
    for i in range(n+1):
        if k-cuma[i] < 0:
            continue
        ans = max(ans, i + bisect.bisect_right(cumb, k-cuma[i])-1)
    print(ans)
resolve()

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

class RUQSegmentTree {
	const int n;
	const int flag = -1;
	const int id = 1;
	vector<int> data, data2;
	int size(int n) {
		int res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	void sub(int l, int r, int node, int lb, int ub, int val) {
		if (ub <= l || r <= lb) return;
		if (data[node] == val) return;
		if (l <= lb && ub <= r) {
			data[node] = val;
			return;
		}
		int left = node * 2, right = node * 2 + 1;
		if (data[node] != flag) {
			data[left] = data[node];
			data[right] = data[node];
		}
		data[node] = flag;
		sub(l, r, left, lb, (lb + ub) / 2, val);
		sub(l, r, right, (lb + ub) / 2, ub, val);
		data2[node] = min(data[left] == flag ? data2[left] : data[left], data[right] == flag ? data2[right] : data[right]);
	}
public:
	RUQSegmentTree(int n_) :
		n(size(n_)), data(n * 2, INT_MAX), data2(n * 2, INT_MAX) {}
	void update(int l, int r, int val) {
		sub(l, r + 1, 1, 0, n, val);
	}
	int find(int i) {
		i += n;
		int res = data[i];
		while (i >>= 1) {
			if (data[i] != flag) res = data[i];
		}
		return res;
	}
};

int main()
{
	int n, q, b, i, s, t, x;
	cin >> n >> q;
	RUQSegmentTree ruq(n);
	while (q--) {
		cin >> b;
		if (b) {
			cin >> i;
			cout << ruq.find(i) << endl;
		}
		else {
			cin >> s >> t >> x;
			ruq.update(s, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 4948
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int k,s,cnt=0;
	cin>>k>>s;
	rep(i,k+1){
		rep(j,k+1){
			int res=s-i-j;
			if(res>=0 && res<=k)cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a = [int(input()) for i in range(m)]
broken = set(a)
dp=[0]*(n+1)
mod = 10**9 + 7
for i in range(n,-1,-1):
  if i in broken:
    continue
  else:
    if i==n or i==n-1:
      dp[i]=1
    else:
      dp[i]=dp[i+1]+dp[i+2]
print(dp[0]%mod)

Measured memory_bytes: 460020
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};
typedef struct node * Node;
Node treeMinimum(Node x);
Node treeSearch(Node u, int k);
Node treeSuccessor(Node x);
void treeDelete(Node z);
void insert(int k);
void inorder(Node u);
void preorder(Node u);
Node root;
Node T;
int main(){
  int n, i, x;
  char str[7];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", str);
    if ( str[0] == 'f' ){
      scanf("%d", &x);
      T = treeSearch(root, x);
      if ( T != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( str[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( str[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( str[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}
Node treeMinimum(Node x){
  while(x->l != NIL)
    x = x->l;
  return x;
}
Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->l;
    else u = u->r;
  }
  return u;
}
 
Node treeSuccessor(Node x){
  Node y;
  if(x->r != NIL) return treeMinimum(x->r);
  y = x->p;
  while(y != NIL && x == y->r){
    x = y;
    x = y->p;
  }
  return y;
}
 
void treeDelete(Node z){
  Node y;
  Node x;
  if(z->l == NIL || z->r == NIL) y = z;
  else y = treeSuccessor(z);
  if(y->l != NIL) x = y->l;
  else x = y->r;
  if(x != NIL) x->p = y->p;
  if(y->p == NIL) root = x;
  else if(y == y->p->l) y->p->l = x;
  else y->p->r = x;
  if(y != z) z->key = y->key;
  }
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;
 
  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->l;
    else  x = x->r;   
  }
  z->p = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->l = z;
  else y->r = z; 
}
 
void inorder(Node u){
  if(u == NIL) return;
  inorder(u->l);
  printf(" %d", u->key);
  inorder(u->r);
}
void preorder(Node u){ 
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->l);
  preorder(u->r);
}
 

Measured memory_bytes: 19360
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        for(int i=0; i<s.length(); i++){
            System.out.print(change(n,s.charAt(i)));
        }
        System.out.println();
    }

    public static char change(int n,char c){
        int cint = (int)c;
        if(cint + n <= 90){
            return (char)(cint + n);
        } else {
            return (char)(cint + n - 26);
        }
    }
}

Measured memory_bytes: 25424
L=list(map(int,input().split()))
L.sort()
t = 0
while not ( L[0] == 0 and L[1] == 0 ):
	# print("Case {}: {} {}".format(t+1, str(L[0]), str(L[1]) ) )
	print("{} {}".format( str(L[0]), str(L[1]) ) )
	t+=1
	L=list(map(int,input().split()))
	L.sort()



Measured memory_bytes: 5612
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, q;
    cin >> n >> q;
    dsu d(n+5);

    rep(i, q) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t==0) d.merge(u, v);
        else {
            int ans = 0;
            if (d.same(u, v)) ans = 1;
            pr(ans);
        }
    }
    
    return 0;
}


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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)
#define	INF (1<<29)
//536870912

#define	MOD 1000000007

int	main() {
	int N, M;
	cin >>N >>M;
	vector<int> B(N+1, 0);
	for (int i=0; i<M; i++) {
		int a, b;
		cin >>a >>b;
		if (a>b)
			swap(a, b);
		if (1==a) {
			B.at(b)++;
			if (B.at(b)==2) {
				cout <<"POSSIBLE" <<endl;
				return 0;
			}
		}
		if (N==b) {
			B.at(a)++;
			if (B.at(a)==2) {
				cout <<"POSSIBLE" <<endl;
				return 0;
			}
		}
	}
	cout <<"IMPOSSIBLE" <<endl;
	return 0;
}



Measured memory_bytes: 1024
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics


# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

def gettwice(n):
    counter = 0
    flg = True
    while (flg):
        if n % 2 == 1:
            flg = False
        else:
            n = n / 2
            counter += 1

    return counter


n = getInputInt()
data = getInputListInt()

ans = 0

for i in range(len(data)):
    ans += gettwice(data[i])

print(ans)


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

int main()
{
    int n;
    cin >> n;
    string s;
    set<string> st;

    for (int i = 0; i < n; i++) {
        cin >> s;
        st.insert(s);
    }

    int size = st.size();
    cout << (st.size() == 3 ? "Three" : "Four") << endl;
}


Measured memory_bytes: 256
from itertools import product

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
se = set(range(10))
for a in A:
    se ^= set([a])

def check(str_num):
    for x in str_num:
        if not int(x) in se:
            return False
    return True

while True:
    if check(str(N)):
        break
    N += 1
print(N)


Measured memory_bytes: 40668