akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = 998244353;
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

vector<ll> FactorialInv, Factorial;

void init_combination(ll MAX){
    Factorial.resize(MAX + 1);
    FactorialInv.resize(MAX + 1);
    Factorial[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = power(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    if(b < 0) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}


//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    string ans;
    while (n > 0) {
        if(n % 26)ans += char(n % 26 + 'a' - 1);
        else{
            ans += 'z';
            n -= 1;
        }
        n /= 26;
    }
    reverse(all(ans));
    pf(ans);
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

int main() {
	int X, A; cin >> X >> A;
	if (X < A)cout << 0 << endl;
	else cout << 10 << endl;
}




Measured memory_bytes: 256
from math import sqrt

N, D = map(int, input().split())

l = []
result = 0

for i in range(N):
  l.append(list(map(int, input().split())))

for i in range(N):
  for j in range(i + 1, N):
    dist = sqrt(sum( [(l[i][d] - l[j][d]) ** 2 for d in range(D)] ))
    if(dist % 1 == 0):
      result += 1
  
print(result)

Measured memory_bytes: 3064
use proconio::input;

fn main() {
  input! {
    n: usize,
    mut v: [usize;n]
  }
  v.sort();
  let mut v: Vec<f64> = v.into_iter().map(|v| v as f64).collect();
  
  let mut val = v.remove(0);
  for vv in v {
    val = (vv + val) / 2f64;
  }
  println!("{}", val);
}

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

#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define FOR(i,a,b) for(long long i=(a);i<=(b);i++)

int main() {
  string S;
  cin >> S;
  int a = S.size() - 7;
  for(int i = 0; i <= S.size() - a; i++) {
    string s = S;
    s.erase(i, a);
    if(s == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, k, d, i, j,count=0,a;
	cin >> n >> k;
	vector<int> t(n, 0);
	for (i = 0;i < k;i++) {
		cin >> d;
		for (j = 0;j < d;j++){
			cin >> a;
			t[a-1]++;
	}
}
	for (j = 0;j < n;j++)if (t[j] == 0)count++;
	cout << count << endl;
}

Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	N := nextInt()
	V := make(values, N)

	for i := 0; i < N; i++ {
		V[i] = float64(nextInt())
	}

	// vをソートして前から使っていく
	sort.Sort(V)
	ans := V[0]

	for n := 1; n < N; n++ {
		ans = (ans + V[n]) / 2
	}

	fmt.Println(ans)
}

type values []float64

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

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 640
program ccc
implicit none

integer(8) :: x, i, j, count

read*, x
x = x - 1

do i = 1, 10000
	x = x + 1
    count = 0
	do j = 2, x-1
	    if (mod(x,j)==0) then
    	count = 1
    	exit
    	end if
    end do
    if (count==0) then
	print*, x
   	return
   	end if
end do

end program

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int allSecond = sc.nextInt();
		
		int h = allSecond / 3600;
		int m = allSecond % 3600 / 60;
		int s = allSecond % 60;
		
		System.out.println(h + ":" + m + ":" + s);
		
	}

}


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf

#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)

#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()

#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))

#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >

#define nl puts("")
#define line puts("-------");
#define dbb(x) cout<<#x<<" : "<<x<<"\n";

void __print(int x) {cerr << x;} void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;} void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V> void __print(const pair<T, V> &x)
{cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T> void __print(const queue<T> &x)
{queue<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.front() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const stack<T> &x)
{stack<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.top() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const T &x)
{int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v)
{__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
    #define db(x...) cerr << "[" << #x << "] = [", _print(x)
#endif
using ll = long long;
const int N = 100005;
const int MOD = 1000000007;

int main()
{
    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt","w",stdout);
    #endif
    char ch;
    cin>>ch;
    if(ch>='A' && ch<='Z')
        cout<<"A";
    else
        cout<<"a";
}


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

using namespace std;
#define int long long
#define pii pair <int , int>
#define F first
#define S second
const int N = 1e5 + 10;
int cnt[3], cntm, c[N];
vector <pii> g[N];

bool dfs(int v, int col = 0)
{
    bool flag = 0;
    c[v] = col;
    cnt[col]++;
    cntm += g[v].size();
    for (auto u : g[v]) {
        if (c[u.F] == -1) flag |= dfs(u.F, (col + u.S) % 3);
        else if (c[u.F] != (col + u.S) % 3) flag = 1;
    }
    return flag;
}

int32_t main()
{
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        g[x].push_back({y, 1});
        g[y].push_back({x, 2});
    }
    int ans = 0;
    fill(c, c + N, -1);
    for (int i = 1; i <= n; i++) if (c[i] == -1) {
        cnt[0] = cnt[1] = cnt[2] = cntm = 0;
        if (dfs(i)) ans += (cnt[0] + cnt[1] + cnt[2]) * (cnt[0] + cnt[1] + cnt[2]);
        else {
            if (cnt[0] && cnt[1] && cnt[2]) ans += cnt[0] * cnt[1] + cnt[1] * cnt[2] +  cnt[2] * cnt[0];
            else ans += cntm/2;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    int w,h;
    cin>>w>>h;
    int d[101][101];
    for(int i=0;i<101;i++)for(int j=0;j<101;j++)d[i][j]=0;
    
    for(int i=0;i<n;i++){
      int x,y;
      cin>>x>>y;
      d[y][x]=1;
    }

    if(debug){
      for(int i=0;i<=h;i++){
	for(int j=0;j<=w;j++){
	  cout<<d[i][j]<<" ";
	}
	cout<<endl;
      }
    }
    
    int maxi=0;
    int s,t;
    cin>>s>>t;
    for(int i=0;i<=h-t+1;i++){
      for(int j=0;j<=w-s+1;j++){
	int cnt=0;
	for(int k=0;k<t;k++){
	  for(int l=0;l<s;l++){
	    if(d[k+i][l+j]==1)cnt++;
	  }
	}
	maxi=max(maxi,cnt);
      }
    }
    cout<<maxi<<endl;
  }
  return 0;
}

Measured memory_bytes: 3116
#include <stdio.h>

int main(void) {

    int i, j, n, nbuf;
    int EXS[4][13];
    char sbuf;

    for (i = 0; i < 4; i++) {
    for (j = 0; j < 13; j++) {
        EXS[i][j] = 0;
    }
    }

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        nbuf = 0;
        sbuf = '\0';
        scanf("%*c%c%d", &sbuf, &nbuf);
        switch (sbuf) {
            case 'S':
                EXS[0][nbuf - 1] = 1; break;
            case 'H':
                EXS[1][nbuf - 1] = 1; break;
            case 'C':
                EXS[2][nbuf - 1] = 1; break;
            case 'D':
                EXS[3][nbuf - 1] = 1; break;
        }
    }

    for (i = 0; i < 4; i++) {
    for (j = 0; j < 13; j++) {
        if (EXS[i][j] == 0) {
            switch (i) {
                case 0:
                    printf("S %d\n", j + 1); break;
                case 1:
                    printf("H %d\n", j + 1); break;
                case 2:
                    printf("C %d\n", j + 1); break;
                case 3:
                    printf("D %d\n", j + 1); break;
            }
        }
    }
    }

    return 0;

}

Measured memory_bytes: 596
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

//WA

int main(void){
	int N,K;
	ll ans=0;
	cin>>N>>K;
	ans=K;
	rep(i,N-1)ans*=K-1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
class SegTree
  def initialize(size, id, fill = id, &op)
    n = 1
    while n < size
      n <<= 1
    end
    @op, @n, @a = op, n, [fill] * (2*n)
  end

  def [](i); @a[i + @n]; end

  def []=(i, x)
    @a[i += @n] = x
    while (i >>= 1) > 0
      @a[i] = @op[@a[i<<1|0], @a[i<<1|1]]
    end
  end

  def fold(l, r = l + 1)
    l += @n
    r += @n
    x = y = @a[0]
    while l < r
      if (l & 1) == 1
        x = @op[x, @a[l]]
        l += 1
      end
      y = @op[@a[r -= 1], y] if (r & 1) == 1
      l >>= 1
      r >>= 1
    end
    @op[x, y]
  end
end

n = gets.to_i
st = SegTree.new(n, 0) { |a, b| a | b }

gets.chomp.each_char.with_index do |c, i|
  x = 1 << (c.ord - 'a'.ord)
  st[i] = x
end

q = gets.to_i
q.times do
  t, x, y = gets.split
  case t.to_i
  when 1
    i, c = x.to_i, y
    x = 1 << (c.ord - 'a'.ord)
    st[i-1] = x
  when 2
    l, r = x.to_i, y.to_i
    x = st.fold(l-1, r)
    cnt = (0...26).count { |b| x[b] == 1 }
    p cnt
  end
end


Measured memory_bytes: 23868
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int n; cin >> n;
  vector<int> p(n); REP(i, n) cin >> p[i];

  int ans = 0;
  for (int i = 1; i < n-1; ++i) {
    if ((p[i-1] < p[i] && p[i] < p[i+1]) ||
        p[i-1] > p[i] && p[i] > p[i+1]) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main(){
    ll N, K = 0, M = 1000;
    cin >> N;

    ll A[N+1];
    REP(i, N){
        cin >> A[i];
    }
    A[N] = 0;

    int i = 0;
    ll max_M = 0;
    bool flag = true; //買いたいとき
    while (i < N){
        if(flag){
            if (A[i+1] > A[i]){
                K = M/A[i];
                M -= K*A[i];
                flag = false;
            }
        }
        else {
            if (A[i+1] < A[i]){
                M += A[i]*K;
                K = 0;
                flag = true;
            }
        }
        i++;
        max_M = max(max_M, M);
    }

    cout << M << endl;
}


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <limits>
using namespace std;

double inf = numeric_limits<double>::infinity();

int main() {
    double n, a, b;
    cin >> n >> a >> b;
    
    double x, y;
    cin >> x >> y;
    long cst = 0;
    
    for (int i = 0; i < n - 1; i++) {
        cst += min(a * (y - x), b);
        x = y;
        if (i != n - 2) {
            cin >> y;
        }
    }
    
    cout << cst << endl;
}

Measured memory_bytes: 256
n = int(input())
L = list(map(int,input().split()))
L = [0] + L + [0]

diff1 = []
diff2 = []
sum1 = 0
for i in range(n+1):
    sum1 += abs(L[i+1]-L[i])
    diff1.append(abs(L[i+1]-L[i]))

for i in range(n):
    diff2.append(abs(L[i+2]-L[i]))

for i in range(n):
    ans = sum1-(diff1[i]+diff1[i+1]) + diff2[i]
    print(ans)

Measured memory_bytes: 20520
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	LL n, INF = 1e18;
	
	LL xRmi = +INF;
	LL xLmi = +INF;
	LL xCmi = +INF;
	LL xRma = -INF;
	LL xLma = -INF;
	LL xCma = -INF;
	LL yUmi = +INF;
	LL yDmi = +INF;
	LL yCmi = +INF;
	LL yUma = -INF;
	LL yDma = -INF;
	LL yCma = -INF;
	
	cin >> n;
	inc(i, n) {
		LL x, y; string d;
		cin >> x >> y >> d;
		x *= 4;
		y *= 4;
		
		if(d == "R") { setmin(xRmi, x); setmax(xRma, x); }
		ef(d == "L") { setmin(xLmi, x); setmax(xLma, x); }
		ef(d == "U") { setmin(yUmi, y); setmax(yUma, y); }
		ef(d == "D") { setmin(yDmi, y); setmax(yDma, y); }
		else { UR; }
		
		if(d == "R" || d == "L") { setmin(yCmi, y); setmax(yCma, y); }
		ef(d == "U" || d == "D") { setmin(xCmi, x); setmax(xCma, x); }
		else { UR; }
	}
	
	LL ans = INF;
	inc(i, 800'000'001) {
		LL xmi = min({ xRmi, xLmi, xCmi });
		LL xma = max({ xRma, xLma, xCma });
		LL ymi = min({ yUmi, yDmi, yCmi });
		LL yma = max({ yUma, yDma, yCma });
		setmin(ans, (xma - xmi) * (yma - ymi));
		
		xRmi++;
		xRma++;
		xLmi--;
		xLma--;
		yUmi++;
		yUma++;
		yDmi--;
		yDma--;
	}
	
	long double z = 16;
	printf("%.6Lf\n", ans / z);
	
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
const int Max=1e5+10;
const int mod=1e9+7;
using namespace std;
int prim[Max],phi[Max],vis[Max];
int cnt=0;
int n,k;
void init(){
 phi[1]=1;
 for(int i=2;i<Max;i++){
  if(!vis[i]){
   prim[++cnt]=i;
   phi[i]=i-1;
  }
  for(int j=1;j<=cnt&&1ll*i*prim[j]<Max;j++){
   vis[i*prim[j]]=1;
   if(i%prim[j]==0){
    phi[i*prim[j]]=phi[i]*prim[j];
    break;
   }
   else{
    phi[i*prim[j]]=phi[i]*(prim[j]-1);
   }
  }
 }
 for(int i=2;i<Max;i++){
  phi[i]=phi[i]+phi[i-1]%mod;
 }
}
ll ksm(int a,int b){
 int ans=1;
 while(b){
  if(b&1){
   ans=1ll*ans*a%mod;
  }
  a=1ll*a*a%mod;
  b>>=1;
 }
 return ans;
}
ll solve(){
 ll ans=0;
 for(int l=1,r;l<=n;l=r+1){
  r=n/(n/l);
  ans=(ans+(phi[r]-phi[l-1])*ksm(n/l,k)%mod)%mod;
 }
 return (ans+mod)%mod;
}
int main(){
 init();
 scanf("%d%d",&k,&n);
 printf("%lld\n",solve());
 return 0;
}

Measured memory_bytes: 2548
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define DB double
#define SG string
#define LL long long
#define Fp(A,B,C,D) for(A=B;A<=C;A+=D)
#define Fm(A,B,C,D) for(A=B;A>=C;A-=D)
#define Clear(A) memset(A,0,sizeof(A))
#define Copy(A,B) memcpy(A,B,sizeof(A))
using namespace std;
const LL Max=1e3+5;
const LL Mod=1e9+7;
const LL Inf=1e18;
inline LL Read(){
	LL X=0;char CH=getchar();bool F=0;
	while(CH>'9'||CH<'0'){if(CH=='-')F=1;CH=getchar();}
	while(CH>='0'&&CH<='9'){X=(X<<1)+(X<<3)+CH-'0';CH=getchar();}
	return F?-X:X;
}
inline void Write(LL X){
	if(X<0)X=-X,putchar('-');
	if(X>9)Write(X/10);
	putchar(X%10+48);
}
int main(){
	LL I,J,K;
	LL A=Read(),B=Read();
	if(A<=8&&B<=8&&A+B<=16){
		puts("Yay!");
	} else {
		puts(":(");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main(){
	sync
	ll n, k;
	cin>>n>>k;
	vector<ll> vec(n);
	FOR0(i, n) cin>>vec[i];
	vector<bool> dp(k+1, 0);
	FOR0(i, k+1){
		FOR0(j, n){
			if(i-vec[j] >= 0 && !dp[i-vec[j]])
				dp[i] = 1;
		}
	}
	string res = dp[k] ? "First" : "Second";
	cout<<res<<"\n";
	return 0;
}

Measured memory_bytes: 384
import copy

N=int(input())
a = list(map(int,input().split()))


root=[]
string = copy.deepcopy(a)
while len(string)!=0:
    temp=[]
    for i,s in enumerate(string):
        if i+1 == s:
            temp.append(i+1)
    if len(temp)==0:
        break
    
    if temp[0]==1 and len(temp)==1:
        string.pop(0)
        root.append(1)
    else:
        if 1 in temp:
            temp.remove(1)
        root.append(temp[-1])
        string.pop(temp[-1]-1)
        
if len(string)!=0:
    print(-1)
else:
    for i in root[::-1]:
        print(i)

Measured memory_bytes: 38768
def func(line):
    lp = 0
    res = []
    while lp < len(line):
        while len(res) > 0 and lp < len(line) and res[-1] != line[lp]:
            res.pop()
            lp += 1
        if lp < len(line):
            res.append(line[lp])
            lp += 1
    return res


def main():
    line = [i for i in input()]
    startsize = len(line)
    line = func(line)
    lastsize = len(line)
    print(startsize - lastsize)


if __name__ == "__main__":
    main()



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

#define ar array 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,a,b) for(int i = a; i < b; i++)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
 
 
const  int mxN = 1e5+5;
const  long long INF= 1e18;
const long long mod= 1e9+7;

string s;
ll n, k;
ll dp[10001][5][2]; // states : string size(), int constraint on digit, checker on number is small or equal

ll solve(int idx, int cnt, int check) {
	if(idx == n) {
		if(cnt == 0) return 1;
		else return 0;
	}
	ll limit = s[idx] - '0';
	if(check) limit = 9;
	
	ll &ans = dp[idx][cnt][check];
	if(ans != -1) return ans;
	ans = 0;
	for(ll i = 0; i <= limit ; i++) {
		if(i == 0) { // inserting 0; (the item without constraints)
			if(i == limit) ans += solve(idx + 1, cnt, check);
			else ans += solve(idx + 1, cnt, 1);
		}
		else {
			if(cnt == 0) continue; // the item with constraints
			if(i == limit)ans += solve(idx + 1, cnt - 1, check);
			else ans += solve(idx + 1, cnt - 1, 1);
		}
	}
	
	return ans;
}
				 
			
 	
int main(){
	cin >> s >> k;
	n = (ll)s.size();
	memset(dp, -1 , sizeof(dp));
		
	ll ans = solve(0, k, 0);
	cout << ans << endl;
}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	


Measured memory_bytes: 1024
n, y = map(int, input().split())


for i in range(n + 1):
    for j in range(n -i + 1):
        k = n - i - j
        val = 10000*i + 5000*j + 1000*k
        if val == y:
            print(i, j, k)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 40428
// D - 桁和

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll f(ll b, ll n) {
	if (n < b) {
		return n;
	}

	return f(b, n / b) + n % b;
}

int main() {
	ll n, s;
	cin >> n >> s;

	if (n == s) {
		cout << s + 1 << endl;
		return 0;
	}

	for (ll b=2; b*b<=n; b++) {
		if (f(b, n) == s) {
			cout << b << endl;
			return 0;
		}
	}

	ll max_b = -1;

	for (ll p=1; p*p < n; p++) {
		ll b = (n - s) / p + 1;
		if (b < 2) continue;
		if (f(b, n) == s) {
			max_b = b;
		}
	}

	cout << max_b << endl;

	return 0;
}

Measured memory_bytes: 256
#ABC087B - Coins

A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i + 100*j + 50*k == X:
                count += 1
print(count)


Measured memory_bytes: 3060
#include <stdio.h>

int a, b;   

int main() {
	scanf("%d %d", &a, &b);
	if (a < b) {
		printf("a < b\n");
	} else if (a > b) {
		printf("a > b\n");
	} else {
		printf("a == b\n");
	}
	
	return 0;
}




Measured memory_bytes: 2036
import sys
from collections import deque
readline = sys.stdin.readline

n, m = list(map(int, readline().split()))
a = sorted(list(map(int, readline().split())))
bc = []
for _ in range(m):
    b, c = list(map(int, readline().split()))
    bc.append([b * c, c])
bc.sort(key=lambda x: -x[1])
dbc = deque(bc)
for i in range(n):
    if len(dbc) > 0 and a[i] < dbc[0][1]:
        a[i] = dbc[0][1]
        dbc[0][0] -= dbc[0][1]
        if dbc[0][0] == 0:
            dbc.popleft()

print(sum(a))

Measured memory_bytes: 29580
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] diff = new int[n];

        int max_diff = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if(i > 0) {
                diff[i] = a[i] - a[i-1];
                max_diff = Math.max(max_diff, diff[i]);
            }
        }
        diff[0] = a[0] + k - a[a.length-1];
        max_diff = Math.max(max_diff, diff[0]);
        System.out.println(Arrays.stream(diff).sum() - max_diff);
    }
}

Measured memory_bytes: 68852
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int A, B, C; cin >> A >> B >> C;
	int ans = 0;
	// シミュレーションを行う
	for (;;)
	{
		if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) break;
		int nA = (B + C) / 2;
		int nB = (C + A) / 2;
		int nC = (A + B) / 2;
		++ans;
		// 交換後，交換前と変わらなければ無限に続く
		vector<int> prev{ A, B, C }; sort(prev.begin(), prev.end());
		vector<int> next{ nA, nB, nC }; sort(next.begin(), next.end());
		if (prev == next)
		{
			ans = -1;
			break;
		}
		A = nA;
		B = nB;
		C = nC;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

typedef pair<int, int> P;
int main(){
    int H,W;
    int h,w;
    cin>>H>>W;
    cin>>h>>w;
    cout<<H*W-h*W-H*w+h*w<<endl;

}





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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    char moji[52];
    rep(i, 26){
        moji[i] = 'A' + i;
    }
    rep(i, 26){
        moji[i+26] = 'a' + i;
    }
    int N;
    string S;
    while(true){
        string res = "";
        cin >> N;
        if(N == 0) break;
        vector<int> K(N);
        rep(i, N) cin >> K[i];
        cin >> S;
        int lenS = S.length();
        rep(i, lenS){
            //0 -> A 51 -> z
            int A;
            if(S[i] <= 'Z') A = S[i] - 'A';
            else A = S[i] - 'a' + 26;
            A -= K[i % N];
            if(A < 0) A += 52;
            res += moji[A];
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3216
import java.util.*;

class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
      	String op = sc.next();
      	int b = sc.nextInt();
      	System.out.println(op.equals("+")?a+b:a-b);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int n;
vector<pair<ll, ll>> edges[100001];
bool visited[100001];
int ans[100001];

void solve(){
    queue<int> que;
    que.push(0);
    visited[0] = true;
    ans[0] = 0;
    while(!que.empty()){
        int u = que.front();
        que.pop();
        rep(i, edges[u].size()){
            pair<ll, ll> e = edges[u][i];
            if(!visited[e.first]){
                visited[e.first] = true;
                if(e.second%2){
                    ans[e.first] = 1-ans[u];
                }else{
                    ans[e.first] = ans[u];
                }
                que.push(e.first);
            }
        }
    }
}

int main() {
    cin >> n;
    rep(i, n-1){
        ll from, to, cost;
        cin >> from >> to >> cost;
        from--; to--;
        edges[from].push_back(make_pair(to, cost));
        edges[to].push_back(make_pair(from, cost));
    }
    fill(visited, visited+n, false);
    fill(ans, ans+n, 0);
    solve();
    rep(i, n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
typedef signed long long lint;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  char c;
  cin >> c;
  cout << (char)(c+1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long

using namespace std;

ll gcd(ll a, ll b) {
    if(a*b == 0)return max(a, b);
    if (a < b) {
        ll tmp = a;
        a = b;
        b = tmp;
    }
    if (a%b == 0)return b;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> T(N,0);
    for(int i=0;i<N;i++){
        cin >> T[i];
    }
    ll ans = T[0];
    for(int i=1;i<N;i++){
        ans = lcm(ans,T[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
signed main(){
    int N;
    cin >> N;
    int min = 299999;
    int P[N];
    int ans = 0;
    for(int i = 0;i < N;i++){
        cin >> P[i];
        if(min > P[i]){min = P[i];ans++;}
    }
    cout << ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int) (n); i++)
#define _GLIBCXX_DEBUG

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

const int max_n = 1010;
int n;
int a[max_n];

int main(){
    cin >> n;
    rep(i, n) cin >> a[i];

    bool succ = true;
    rep(i, n){
        if(a[i] % 2 == 0){
            if(a[i] % 3 != 0 && a[i] % 5 != 0) succ = false;
        }
    }
    if(succ) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 3608
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#include <set>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int k;
int n;

vector<pair<int, int>> a;

void input() {
  cin >> k >> n;

  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;

    a[i].second = i;
  }
}

int ans(vi& b) {
  int ans = 0;

  for (int i = 1, cur = 0; i < k; ++i) {
    if (b[i] == b[i - 1]) {
      ++cur;
    } else {
      cur = 0;
    }

    ans = max(ans, cur);
  }

  return ans;
}

void solve() {
  set<pair<int, int>, greater<pair<int, int>>> cur(a.cbegin(), a.cend());

  vi b;

  while (!cur.empty()) {
    auto it1 = cur.cbegin();

    b.push_back(it1->second);

    int val1 = it1->first;

    cur.erase(it1);

    if (cur.empty()) {
      if (val1 > 1)
        cur.emplace(val1 - 1, b.back());

      continue;
    }

    auto it2 = cur.cbegin();

    b.push_back(it2->second);

    int val2 = it2->first;

    cur.erase(it2);

    if (val1 > 1)
      cur.emplace(val1 - 1, b[b.size() - 2]);

    if (val2 > 1)
      cur.emplace(val2 - 1, b.back());
  }

  cout << ans(b) << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  cin >> _times;
#endif

  while (_times--) {
    input();
    solve();
  }
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    for(int i = 2 ; i <= n ; ++i){
        int now = i;
        for(int j = 2 ; j * j <= now ; ++j){
            int cnt = 0;
            while(now % j == 0){
                now /= j;
                ++cnt;
            }
            if(cnt > 0){
                mp[j] += cnt;
            }
        }
        if(now > 1){
            ++mp[now];
        }
    }
    int ans = 0;
    for(auto x : mp){
        if(x.second >= 74){
            ++ans;
        }
        for(auto y : mp){
            if(x.first == y.first){
                continue;
            }
            if(x.second >= 2 && y.second >= 24){
                ++ans;
            }
            if(x.second >= 4 && y.second >= 14){
                ++ans;
            }
            for(auto z : mp){
                if(x.first == z.first || y.first <= z.first){
                    continue;
                }
                if(x.second >= 2 && y.second >= 4 && y.second >= 4){
                    ++ans;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);

  int ans = 0;
  for (int i = 1; i <= n; i += 2) {
    int cnt = 0;
    for (int j = 1; j <= i; j++) {
      cnt += i % j ? 0 : 1;
    }
    ans += cnt == 8 ? 1 : 0;
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}

vector<int> G[200005];
int parent[200005];
int cnt[200005];

int dfs(int now, int prev){
  int ret = 0;
  parent[now] = prev;
  
  rep(i,G[now].size()){
    if(G[now][i] == prev) continue;
    ret += dfs(G[now][i], now);
  }
  
  ret++;
  return cnt[now] = ret;
}


int main(){
  int N;
  cin >> N;
  rep(i,N-1){
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(1, -1);

  mint ans(0);
  REP(i,1,N+1){
    vector<int> w;
    rep(j,G[i].size()){
      int c = 0;
      if(G[i][j] == parent[i]){
        c = N - cnt[i];
      }else{
        c = cnt[G[i][j]];
      }
      w.push_back(c);
    }
    mint sum(1);
    rep(i,w.size()){
      sum += mint(2).pow(w[i]) - 1;
    }
    ans += mint(2).pow(N-1) - sum;
  }

  ans /= mint(2).pow(N);

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


Measured memory_bytes: 24828
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vl c(n);
  REP(i, n) { cin >> c[i]; }
  sort(c.rbegin(), c.rend());

  ll ans = 0LL;
  ll pow = modpow(4LL, n - 1, MOD);

  REP(i, n) {
    ll tmp = (c[i] * (i + 2)) % MOD;
    ans = (ans + tmp) % MOD;
  }
  ans = (ans * pow) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 1792
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]
b = [0]
for i in range(n):
    a.append(a[i] + A[i])
for i in range(m):
    b.append(b[i] + B[i])

ans = 0

for i in range(n + 1):
    if a[i] > k:
        break
    while  a[i] + b[m] > k:
        m -= 1
    ans = max(ans, i + m)

print(ans)

Measured memory_bytes: 47456
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main(void){
    int N; cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i] >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if (N % 2 == 0){
        ll l = A[N / 2 - 1] + A[N / 2];
        ll r = B[N / 2 - 1] + B[N / 2];
        cout << (r - l + 1) << endl;
    }
    else{
        ll l = A[N / 2];
        ll r = B[N / 2];
        cout << (r - l + 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 4844
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <string.h>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	int cnt = 0;
	string ans = "";
	for (int i = 0; i < N; ++i)
	{
		if (S[i] == '(')
		{
			++cnt;
		}
		else
		{
			if (cnt == 0)
			{
				ans += '(';
			}
			else
			{
				--cnt;
			}
		}
	}
	cout << ans << S;
	for (int i = 0; i < cnt; ++i)
	{
		cout << ')';
	}
	cout << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ld x=0.0,sum=0.0;
    for(int i=0;i<n;i++){
        cin>>x;
        sum+=(ld)1.0/x;
    }
    cout<<fixed<<setprecision(15)<<(ld)1.0/sum<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
const int MOD = 1000000007;

long long int* fac, *finv, *inv;

void comInit( int max ) {
	max++;
	fac = new long long int[ max ];
	finv = new long long int[ max ];
	inv = new long long int[ max ];
	fac[ 0 ] = fac[ 1 ] = inv[ 1 ] = finv[ 0 ] = finv[ 1 ] = 1;
	for (int i = 2; i < max; ++i){
		fac[ i ] = fac[ i - 1 ] * i % MOD;
		inv[ i ] = MOD - inv[ MOD % i ] * ( MOD / i ) % MOD;
		finv[ i ] = finv[ i - 1 ] * inv[ i ] % MOD;
	}
}
long long nCr( int n, int r ) {
	if (n < r || n < 0 || r < 0) return 0;
	return fac[ n ] * ( finv[ r ] * finv[ n - r ] % MOD ) % MOD;
}

int main( void ){
	int N, K;
	cin >> N >> K;
	comInit( N );
	ll* array = new ll[ N ];
	rep( i, 0, N ) cin >> array[ i ];
	sort( array, array + N );
	ll ans = 0;
	rep( i, 0, N ){
		int comb = nCr( i, K - 1 );
		ans += array[ i ] * comb;
		ans %= k_mod;
	}
	reverse( array, array + N );
	rep( i, 0, N ){
		int comb = nCr( i, K - 1 );
		ans -= array[ i ] * comb;
		ans %= k_mod;
	}
	cout << ans << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
    ll i,j;
    ll n,q;
    cin>>n>>q;
    vector<pair<ll,P> > v;
    for(i=0;i<n;i++){
        ll s,t,x;
        cin>>s>>t>>x;
        v.pb(make_pair(s-x,P(1,x)));
        v.pb(make_pair(t-x,P(0,x)));
    }
    for(i=0;i<q;i++) {
        ll d;
        cin>>d;
        v.pb(make_pair(d,P(2,i)));
    }
    ll ans[q];
    sort(v.begin(),v.end());
    multiset<ll> se;
    for(i=0;i<v.size();i++){
        ll type=v[i].se.fi;
        ll f=v[i].se.se;
        if(type==1) se.insert(f);
        else if(type==0) se.erase(se.lower_bound(f));
        else {
            if(!se.empty()) ans[f]=*se.begin();
            else ans[f]=-1;
        }
    }
    for(i=0;i<q;i++) cout<<ans[i]<<endl;
    
}

Measured memory_bytes: 27236
using System;
using System.Linq;
using System.Collections.Generic;

class Program {
  static void Main(string[] args) {
    var s = Console.ReadLine();
    var t = Console.ReadLine();

    if (Numbering(s).SequenceEqual(Numbering(t))) {
      Console.WriteLine("Yes");
    } else {  
      Console.WriteLine("No");
    }
  }

  static int[] Numbering(string s) {
    var d = new Dictionary<char, int>();
    var n = new int[s.Length];

    for (int i = 0; i < s.Length; i++) {
      var c = s[i];
      if (!d.ContainsKey(c)) {
        d.Add(c, d.Count); 
      }

      n[i] = d[c];
    }
  
    return n;
  }
}


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

vector<int> vi[200010];
bool vis[200010]={false};
int maxi=0,res=0;

void DFS(int s,int depth){
    maxi--;
    vis[s]=true;
    //maxi=max(maxi,depth+1);
    for(int i=0;i<vi[s].size();i++){
        if(vis[vi[s][i]]==false){
            DFS(vi[s][i],depth+1);
        }
    }
}

void  init(int s){
    for(int i=1;i<=s;i++){
        vi[i].clear();
    }
    memset(vis,false,sizeof(vis));
}

int main(){
   int n,m;
   scanf("%d%d",&n,&m);
   init(n);
   for(int i=0;i<m;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    vi[a].push_back(b);
    vi[b].push_back(a);
   }
   int s=n;
   maxi=n;
   for(int i=1;i<=n;i++){
        if(vis[i]==false){
            int ori=s;
            //printf("%d\n",ori);
            DFS(i,0);
            res=max(res,ori-maxi);
            s=maxi;
        }
   }
    printf("%d",res);
    return 0;
}


Measured memory_bytes: 24232
#include <bits/stdc++.h>
using namespace std;
int v, e;
pair<int, int> a[200010];
int s[100001];
int g[100001];
int n[100001];
int p[100001];
int l[100001];
int u[100001]={};
int c, t;
int x, y;
int k;

void dfs(int f, int z)
{
	n[f]=t;
	l[f]=t;
	t++;
	u[f]=1;
	for(int i=s[f]; i<=g[f]; i++)
	{
		if(u[a[i].second]==0)
		{
			p[a[i].second]=f;
			dfs(a[i].second, f);
			l[f]=min(l[f], l[a[i].second]);
		}
		else if(a[i].second!=z)
		{
			l[f]=min(l[f], n[a[i].second]);
		}
	}
}

int main()
{
	cin >> v >> e;
	for(int i=0; i<e; i++)
	{
		cin >> x >> y;
		a[2*i]=make_pair(x, y);
		a[2*i+1]=make_pair(y, x);
	}
	sort(a, a+(2*e));
	s[0]=0;
	g[v-1]=2*e-1;
	c=0;
	for(int i=1; i<2*e; i++)
	{
		if(a[i].first>a[i-1].first)
		{
			g[c]=i-1;
			c++;
			s[c]=i;
		}
	}
	t=0;
	dfs(0, -1);
	k=0;
	for(int i=1; i<v; i++)
	{
		if(p[i]==0)
		{
			k++;
		}
	}
	if(k>1)
	{
		for(int i=s[0]; i<=g[0]; i++)
		{
			if(p[a[i].second]==0)
			{
				cout << 0 << " " << a[i].second << endl;
			}
		}
	}
	else if(s[0]==g[0])
	{
		cout << 0 << " " << a[g[0]].second << endl;
	}
	for(int i=s[1]; i<2*e; i++)
	{
		if(a[i].first<a[i].second)
		{
			if(p[a[i].first]==a[i].second)
			{
				if(n[a[i].second]<l[a[i].first])
				{
					cout << a[i].first << " " << a[i].second << endl;
				}
			}
			else if(p[a[i].second]==a[i].first)
			{
				if(n[a[i].first]<l[a[i].second])
				{
					cout << a[i].first << " " << a[i].second << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4504