akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <complex>
#include <vector>

using namespace std;

typedef complex<double> P;

const double EPS = 1e-8;
const double INF = 1e12;

double cross(P a, P b) { return imag(conj(a)*b); }
double angle(P a, P b) { return arg(conj(a)*b); }

P crossPoint(P lp, P lq, P mp, P mq){
	double A = cross(lq-lp, mq-mp);
	double B = cross(lq-lp, lq-mp);
	return mp + B / A * (mq-mp);
}

bool inTriangle(P a, P b, P c, P p){
	double A = cross(a-p,b-p);
	double B = cross(b-p,c-p);
	double C = cross(c-p,a-p);
	if(abs(A) < EPS || abs(B) < EPS || abs(C) < EPS) return false; 
	if(A*B < EPS || B*C < EPS || C*A < EPS) return false;
	return true;
}

int main(){
	int m, n, x, y;
	while(cin >> m >> n, m){
		vector<P> vl, vh;
		for(int i=0;i<m;i++){
			cin >> x >> y; vl.push_back(P(x,y));
		}
		for(int i=0;i<n;i++){
			cin >> x >> y; vh.push_back(P(x,y));
		}
		vector<P> path;     path.push_back(vl[0]);
		vector<double> rot; rot.push_back(INF);
		P prev(vl[0]), cur(vl[1]);
		for(int i=2;i<m;i++){
			P next(vl[i]);
			while(true){
				P tmp = P(-1,-1);
				double minagl = 1e12;
				for(int j=0;j<n;j++){
					if(inTriangle(prev, cur, next, vh[j])){
						double a = abs(angle(cur-prev, vh[j]-prev));
						if(a < minagl){
							minagl = a;
							tmp = vh[j];
						}
					}
				}
				double agl;
				if(real(tmp)<0) agl = angle(cur-prev,next-prev);
				else            agl = angle(cur-prev,tmp-prev);
				if(rot.back()*(rot.back()+agl) < -EPS){
					path.pop_back();
					rot.pop_back();
					cur = crossPoint(prev, path.back(), cur, next);
					prev = path.back();
				} else {
					rot.back() += agl;
					if(real(tmp) < 0){
						prev = path.back();
						cur = next;
						break;
					} else {
						path.push_back(tmp);
						rot.push_back(0);
						cur = crossPoint(prev, tmp, cur, next);
						prev = tmp;
					}
				}
			}
		}
		path.push_back(vl.back());
		double ans = 0.0;
		for(int i=1;i<path.size();i++) ans += abs(path[i]-path[i-1]);
		printf("%.5f\n", ans);
	}
}

Measured memory_bytes: 980
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
//use std::cmp::*;
//use std::num;

fn main() {
    input! {
       x:i32
    }
    let a = x / 500;
    let b = (x % 500) / 5;
    println!("{}", a * 1000 + b * 5);
}


Measured memory_bytes: 2152
import math
K = int(input())

def gcd(a,b):
    return math.gcd(a,b)
cnt=0
for i in range(1,K+1):
    for m in range(1,K+1):
        d = math.gcd(i,m)
        for u in range(1,K+1):
            cnt+=math.gcd(d,u)
            
print(cnt)
                

Measured memory_bytes: 9192
S = input()
if len(S) <26:
    for i in range(97,97+26):
        if chr(i) in S:
            continue
        else:
            print(S+chr(i))
            exit()
else:
    for i in range(25,0,-1):
        s =S[:i]
        for j in range(97,97+26):
            if chr(j)>s[-1] and chr(j) not in s:
                print(s[:-1]+chr(j))
                exit()
print(-1)
                
        


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


signed main(){

  double n,t,a;

  cin >> n >> t >> a;

  vector<double> h(n);

  int min_idx = 0;

  for(int i=0;i<n;i++){
    cin >> h[i];
    h[i] = abs((t - h[i] * 0.006) - a);

    if(h[min_idx] > h[i]){
      min_idx = i;
    }
  }

  cout << min_idx + 1 << endl;


  for(int i=0;i<n;i++){
//    cout <<  h[i] << endl;
  }


}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef int64_t i64;

int main(){
	int H,N;
  	cin >> H >> N;
  	int A,B;
  	for(int i=0; i < N; i++){
    	cin >> A;
      	B = B + A;
    }
    if(H <= B){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, X;
    cin >> K >> X;
    if (500 * K >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            //Console.WriteLine(string.Compare("a", "b"));//-1ならでかい
            //Console.WriteLine(string.Compare("abcdefghijklmnopqrstuvwzyx", "abcdefghijklmnopqrstuvx"));
            Console.WriteLine(NextStr(S));
        }

        static string NextStr(string S)
        {
            var alphabets = Enumerable.Range(0, 26).Select(x => Convert.ToChar(x + 97)).ToArray();
            //切り出し位置
            for (var i = 0; i <= S.Length; i++)
            {
                var origin = S.Substring(0, S.Length - i);
                //使える文字
                var useableChar = alphabets.Except(origin.ToCharArray()).ToArray();
                foreach(var u in useableChar)
                {
                    var test = origin + u;
                    if(string.Compare(S, test) == -1)
                    {
                        return test;
                    }
                }
            }
            return "-1";
        }
    }
}


Measured memory_bytes: 13660
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	n := nextInt()
	a, b, c, d := n/1000, (n/100)%10, (n/10)%10, n%10

	if a+b+c+d == 7 {
		fmt.Printf("%d+%d+%d+%d=7\n", a, b, c, d)
	} else if a+b+c-d == 7 {
		fmt.Printf("%d+%d+%d-%d=7\n", a, b, c, d)
	} else if a+b-c+d == 7 {
		fmt.Printf("%d+%d-%d+%d=7\n", a, b, c, d)
	} else if a+b-c-d == 7 {
		fmt.Printf("%d+%d-%d-%d=7\n", a, b, c, d)
	} else if a-b+c+d == 7 {
		fmt.Printf("%d-%d+%d+%d=7\n", a, b, c, d)
	} else if a-b+c-d == 7 {
		fmt.Printf("%d-%d+%d-%d=7\n", a, b, c, d)
	} else if a-b-c+d == 7 {
		fmt.Printf("%d-%d-%d+%d=7\n", a, b, c, d)
	} else if a-b-c-d == 7 {
		fmt.Printf("%d-%d-%d-%d=7\n", a, b, c, d)
	}
}


Measured memory_bytes: 640
#include"bits/stdc++.h";
using namespace std;
typedef long long ll;

int main(){

     string a,b,c;
     cin>>a;
     for(int i=0;i<a.size();i++){
        if(a[i]=='9')cout<<1;
        else if(a[i]=='1')cout<<9;
     }
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    num = [0] * 4
    for i in range(4):
        num[i] = int(s[i])

    for bit in range(1 << 3):
        x = num[0]
        for i in range(3):
            if bit >> i & 1:
                x += num[i + 1]
            else:
                x -= num[i + 1]
        if x == 7:
            res = ""
            for j in range(3):
                res += str(num[j])
                if bit >> j & 1:
                    res += "+"
                else:
                    res += "-"
            res += str(num[3])
            res += "=7"
            print(res)
            sys.exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
#define PB push_back
#define INF 1000000001
#define INFL 1000000000000000001
#define M 1000000007
int main(void){
	int n,m;
	cin>>n>>m;
	cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{

    lint n, m;
    cin >> n >> m;

    lint ans=0, tmp;
    priority_queue<lint> que;

    vector<lint> a(n);
    lint x;
    REP(i, n) { cin >> x;
        que.push(x);
    }

    REP(i, m)
    {
        int top = que.top();
        que.pop();
        que.push(top/2);
    }
    REP(i, n)
    {
        int top = que.top();
        que.pop();
        ans += top;
    }

    cout << ans << "\n";

    return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;

    vector<bool> dp(n + 1);
    dp[4] = dp[7] = true;
    for(int i = 8; i <= n; i++)
    {
        if(dp[i - 4] || dp[i - 7])
            dp[i] = true;
        else
            dp[i] = false;
    }

    if(dp[n])
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 998244353
#define maxn 8200
using namespace std;
typedef long long ll;
int n,m,dp[210][maxn<<1],wn[2][maxn<<1],bh[maxn<<1];
int A[maxn<<1],M,fac[maxn<<1],k,inv[maxn<<1];
int qpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)ans=1ll*ans*a%mod;
	return ans;
}
void init(){
	for(int i=1,p;i<M;i<<=1){
		wn[0][i]=1,p=qpow(3,(mod-1)/(i<<1));
		for(int j=1;j<i;++j)wn[0][i+j]=(ll)wn[0][i+j-1]*p%mod;
		wn[1][i]=1,p=qpow(3,mod-1-(mod-1)/(i<<1));
		for(int j=1;j<i;++j)wn[1][i+j]=(ll)wn[1][i+j-1]*p%mod;
	}
}
void fft(int h[],int len,int flag){
	for(int i=0;i<len;++i)if(i<bh[i])swap(h[i],h[bh[i]]);
	for(int i=1;i<len;i<<=1)
		for(int j=0;j<len;j+=(i<<1))
			for(int k=0;k<i;++k){
				int x=h[j+k],y=(ll)h[j+k+i]*wn[flag][i+k]%mod;
				h[j+k]=(x+y)%mod,h[j+k+i]=(x-y+mod)%mod;
			}
	if(flag==1){
		int iv=qpow(len,mod-2);
		for(int i=0;i<len;++i)h[i]=1ll*h[i]*iv%mod;
	}
}
int C(int x,int y){
	if(x>y||x<0)return 0;
	return (ll)fac[y]*inv[x]%mod*inv[y-x]%mod;
}
int main(){
	scanf("%d%d",&n,&m),M=1,k=0,fac[0]=inv[0]=1;
	while(M<2*n)M<<=1,k++;
	for(int i=1;i<=n+2;++i)fac[i]=1ll*fac[i-1]*i%mod;
	inv[n+2]=qpow(fac[n+2],mod-2);
	for(int i=n+1;i>=1;--i)inv[i]=1ll*inv[i+1]*(i+1)%mod;
	for(int i=0;i<M;++i)bh[i]=(bh[i>>1]>>1)|((i&1)<<(k-1));
	init();
	dp[0][0]=1;
	for(int i=0;i<m;++i){
		for(int j=0;j<=n;++j)
			dp[i+1][j]=(ll)(j*(j+1)/2+1)*dp[i][j]%mod,
			dp[i][j]=(ll)dp[i][j]*inv[j]%mod;
		for(int j=0;j<=M;++j)A[j]=0;
		for(int j=1;j<=n;++j)A[j]=inv[j+2];
		fft(dp[i],M,0),fft(A,M,0);
		for(int j=0;j<M;++j)A[j]=(ll)A[j]*dp[i][j]%mod;
		fft(A,M,1);
		for(int j=1;j<=n;++j)
			dp[i+1][j]=(dp[i+1][j]+(ll)A[j]*fac[j+2])%mod;
	}
	int ans=0;
//	for(int i=0;i<=n;++i)printf("[%d]",dp[m][i]);
	for(int i=0;i<=n;++i)ans=(ans+(ll)C(i,n)*dp[m][i])%mod;
	printf("%d",ans);
} 

Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
struct UnionFind {
private:
    ll N;
    vector<ll> parent;
    vector<ll> num;
    vector<ll> diff_weight;
    vector<ll> rank;

public:
    UnionFind(ll n){
        N = n;
        rep(i,0,N) parent.push_back(i);
        rep(i,0,N) num.push_back(1);
        rep(i,0,N) diff_weight.push_back(0);
        rep(i,0,N) rank.push_back(0);
    }
    ll root(ll x){
        if(x == parent[x]){
            return x;
        }else{
            ll r = root(parent[x]);
            diff_weight[x] += diff_weight[parent[x]];
            return parent[x] = r;
        }
    }
    void unite(ll a, ll b){
        a = root(a); b = root(b);
        if(a == b) return;
        parent[a] = b;
        ll sum = num[a] + num[b];
        num[a] = sum;
        num[b] = sum;
    }
    void merge(ll a, ll b, ll w){
        w += weight(a); w -= weight(b);
        a = root(a); b = root(b);
        if(a == b) return;
        // if(rank[a] < rank[b]) swap(a,b), w = -w;
        // if(rank[a] == rank[b]) ++rank[a];
        parent[b] = a;
        ll sum = num[a] + num[b];
        num[a] = sum;
        num[b] = sum;
        diff_weight[b] = w;
    }
    bool same(ll a, ll b){ return root(a) == root(b);}
    ll sz(ll x){ return num[x];}

    ll weight(ll x){
        root(x);
        return diff_weight[x];
    }

    ll diff(ll a, ll b){
        return weight(b) - weight(a);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    UnionFind uf(100010);
    ll N,M;
    cin >> N >> M;
    ll L[200010], R[200010], D[200010];
    rep(i,0,M){
        cin >> L[i] >> R[i] >> D[i];
        L[i]--; R[i]--;
    }
    bool ok = true;
    rep(i,0,M){
        if(not uf.same(L[i], R[i])){
            uf.merge(L[i], R[i], D[i]);
        }else{
            ll diff = uf.diff(L[i],R[i]);
            if(diff != D[i]){
                ok = false;
            }
        }
    }
    if(ok){
        print("Yes");
    }else{
        print("No");
    }
    
}

Measured memory_bytes: 8180
#include "bits/stdc++.h"

using namespace std;

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

    vector<int> pnums(300000,0);
    for(int i=2;i<300000;i++) pnums[i]=1;
    for(int i=2;i*i<300000;i++){
        if(pnums[i]){
            for(int j=i*i;j<300000;j+=i){
                pnums[j]=0;
            }
        }
    }
    vector<int> res(300000,0);
    for(int i=1;i<300000;i++) res[i]=res[i-1]+pnums[i];
    int n;
    while(cin>>n,n){
        cout<<res[2*n]-res[n]<<endl;
    }
}

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

int main(){
  int N;
  cin >> N;
  for(int i=0; i<=N/7; i++){
    for(int j=0; j<=N/4; j++){
      if(7*i+4*j==N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

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

int main(){
	int k;
	cin>>k;
	int a,b;
	cin>>a>>b;
	bool flag = true;
	for(int i = a;i<=b;i++){
		if(i%k == 0){
			flag = false;
			cout<<"OK"<<endl;
			break;
		}
		
	}
	if(flag)
		cout<<"NG"<<endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b != c) {
    cout << "Yes" << endl;
  } else if (c == b && b != a) {
    cout << "Yes" << endl;
  } else if (a == c && b != c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int gray = 0;
	static int brown = 0;
	static int green = 0;
	static int sky = 0;
	static int blue = 0;
	static int yellow = 0;
	static int orange = 0;
	static int red = 0;
	static int other = 0;

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int min = 0;
		int max = 0;
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			color(a[i]);
		}

		int kind = sum();
		if (kind == 0) {
			min = 1;
			max = other;
		} else {
			min = kind;
			max = kind + other;
		}

		System.out.println(min + " "+ max);
	}

	public static void color(int x) {
		if (1 <= x && x < 400) {
			gray++;
		}
		else if (400 <= x && x < 800) {
			brown++;
		}
		else if (800 <= x && x < 1200) {
			green++;
		}
		else if (1200 <= x && x < 1600) {
			sky++;
		}
		else if (1600 <= x && x < 2000) {
			blue++;
		}
		else if (2000 <= x && x < 2400) {
			yellow++;
		}
		else if (2400 <= x && x < 2800) {
			orange++;
		}
		else if (2800 <= x && x < 3200) {
			red++;
		}
		else if (3200 <= x) {
			other++;
		}
		return;
	}
	public static int sum() {
		int kind = 0;
		if (gray != 0) {
			kind++;
		}
		if (brown != 0) {
			kind++;
		}
		if (green != 0) {
			kind++;
		}
		if (sky != 0) {
			kind++;
		}
		if (blue != 0) {
			kind++;
		}
		if (yellow != 0) {
			kind++;
		}
		if (orange != 0) {
			kind++;
		}
		if (red != 0) {
			kind++;
		}

		return kind;
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
bool hori(int di, int dj) { return abs(di) == 0 and abs(dj) == 1; }
bool vert(int di, int dj) { return abs(di) == 1 and abs(dj) == 0; }
bool diag(int di, int dj) { return abs(di) == 1 and abs(dj) == 1; }
template <typename signature> using f = const function<signature>&;
void flood(vector<vector<int>>& a, f<bool(int, int)> can, f<void(int, int, int, int)> f) {
    int n = a.size() - 2, m = a[0].size() - 2;
    vector<vector<bool>> vis(n + 2, vector<bool>(m + 2));
    function<void(int, int, int, int)> dfs = [&](int i, int j, int from_i, int from_j) {
        if(a[i][j] and not vis[i][j]) {
            f(i, j, from_i, from_j);
            vis[i][j] = true;
            for(int di = -1; di <= 1; di++) {
                for(int dj = -1; dj <= 1; dj++) {
                    if(can(di, dj)) {
                        dfs(i + di, j + dj, i, j);
                    }
                }
            }
        }
    };
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(not vis[i][j]) {
                dfs(i, j, 0, 0);
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int w, h;
    while(cin >> w >> h and w and h) {
        vector<vector<int>> a(h + 2, vector<int>(w + 2));
        for(int i = 1; i <= h; i++) {
            for(int j = 1; j <= w; j++) {
                cin >> a[i][j];
            }
        }
        int ans = 0;
        flood(a, [](int di, int dj) { return true; }, [&](int i, int j, int from, int) {
            ans += not from;
        });
        cout << ans << endl;
    }
    return 0;
}



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

int main() {
  string a,b,c;cin>>a>>b>>c;
  bool ans = a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0);
  cout << (ans ? "YES" : "NO") << endl;
}


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

int main(){
    int n,l,sum=0,Min=1000;
    cin>>n>>l;
    for(int i=0;i<n;i++){
        sum+=l;
        if(abs(Min)>abs(l)){
            Min=l;
        }
        l++;
    }
    cout<<sum-Min<<endl;
    return 0;
}

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

int main()
{
    int n, a[100], b[100];

    cin >> n;

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

    int max = 0;
    bool judge= true;
    while( judge )
    {
        max++;
        for( int i = 0; i < n; i++ )
            b[i] = a[i];

        for( int i = 0; i < n - 1; i++ )
        {
            b[0] -= max;
            if( b[0] < 0 )
            {
                judge = false;
                break;
            }
            b[0] += b[i+1];
        }
    }

    cout << max - 1 << endl;

    return 0;
}


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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;
#define fastio ios_base::sync_with_stdio(false); \
			cin.tie(0);							 \
			cout.tie(0);

using namespace std;

using ll = long long;
const int MOD = 1e9 + 7;
const ll INF = 5e18 + 9;
#define PI 3.141592654

ll powmod(ll base, ll exp, const ll MOD) { ll ans = 1; while (exp) { if (exp & 1)	ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; }return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }


map<ll, ll> dp;
ll N, A, B, C, D;

ll f(ll goal) {
	if (goal == 0)
		return 0;
	if (goal == 1)
		return D;
	if (dp.count(goal)) return dp[goal];

	ll best = INF;
	if (D < INF / goal)
		best = min(best, D * goal);


	for (int i = 0; i < 3; ++i) {
		int mul = vector<int>{ 2,3,5 }[i];
		ll cost = vector<ll>{ A,B,C }[i];
		if (goal % mul == 0)
			best = min(best, cost + f(goal / mul));
		else {
			ll down = goal / mul * mul;
			best = min(best, cost + (goal - down) * D + f(goal / mul));
			ll up = down + mul;
			best = min(best, cost + (up - goal) * D + f(goal / mul + 1));
		}
	}
	return dp[goal] = best;
}

void test_case() {

	cin >> N >> A >> B >> C >> D;
	cout << f(N) << "\n";
	dp.clear();
}

int main() {
	fastio;
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	//#endif // !ONLINE_JUDGE
	int t;
	cin >> t;
	while (t--) {
		test_case();
	}
	return 0;
}



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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    if (s[0] == 'S') cout << "Cloudy" << endl;
    else if (s[0] == 'C') cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    
    return 0;
}



Measured memory_bytes: 256
import sys
import fractions
input = sys.stdin.readline
def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)


A, B, C, D = map(int, input().split())
lcm=lcm(C,D)
ans = B-A+1 - (B//C-(A-1)//C) - (B//D-(A-1)//D) + (B//(lcm)-(A-1)//(lcm)) 


print(ans)

Measured memory_bytes: 5048
// selection sort
#include <stdio.h>
int main() {
  int i, j, min, tmp, N, count = 0;
  int num[100];

  // input the number of element for array
  scanf("%d", &N);

  for (i = 0; i < N; i++)
    scanf("%d", &num[i]);

  for (i = 0; i < N - 1; i++) {
    min = i;
    for (j = i; j < N; j++) {
      if (num[min] > num[j])
        min = j;
    }
    tmp = num[min];
    num[min] = num[i];
    num[i] = tmp;
    if (i != min)
      count++;
  }

  for (i = 0; i < N; i++) {
    if (i == N - 1)
      printf("%d\n", num[i]);
    else
      printf("%d ", num[i]);
  }

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

  return 0;
}

//選択ソート
//選択ソートは配列の最小値(最大値)をもつ要素を探して、それを配列の先頭と交換することで整列を行うアルゴリズムである
//アルゴリズム分析。
// 1. 配列の先頭要素を仮の最小値をもつ要素(A0)としておく。
// 2.
// (A0)と(A0)以外の要素の値を比較して(A0)より小さい値を持つ要素(A1)が見つかれば(A1)と(A0)の値を交換する。
// 3. 2.を繰り返すことで(A0)には配列内での最小値がセットされる。
// 4.
// 次は(A0)をのぞいて(A1)と(A1)以外の要素、(A1)をのぞいて(A2)と(A2)以外の要素を比較/交換して整列が完了する。


Measured memory_bytes: 2140
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iomanip>
#include<complex>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
#define PI  acos(-1.0)
//cin.tie(0);ios::sync_with_stdio(false);
////////////////////////////////////////////////
int main()
{
	int n=0;
	cin>>n;
	cout<<n/3<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr double PI = atan2(0, -1);
struct Point {
    int x, y;
    Point() {}
    Point(int x, int y) : x(x), y(y) {}
};
bool operator<(const Point &lhs, const Point &rhs) {return lhs.x < rhs.x || lhs.x == rhs.x && lhs.y < rhs.y;}
Point operator-(const Point &lhs, const Point &rhs) {return Point(lhs.x - rhs.x, lhs.y - rhs.y);}
LL cross(const Point &lhs, const Point &rhs) {return 1LL * lhs.x * rhs.y - 1LL * lhs.y * rhs.x;}
LL dot(const Point &lhs, const Point &rhs) {return 1LL * lhs.x * rhs.x + 1LL * lhs.y * rhs.y;}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<Point> p(n);
    for (int i = 0; i < n; ++i)
        cin >> p[i].x >> p[i].y;
    vector<int> q(n);
    iota(q.begin(), q.end(), 0);
    sort(q.begin(), q.end(), [&](int i, int j) {return p[i] < p[j];});
    vector<int> hull, pts;
    vector<Point> vecs;
    for (int i = 0; i < n; ++i) {
        while ((int)pts.size() >= 2 && cross(vecs.back(), p[q[i]] - p[pts.back()]) <= 0) {
            pts.pop_back();
            vecs.pop_back();
        }
        if (!pts.empty())
            vecs.push_back(p[q[i]] - p[pts.back()]);
        pts.push_back(q[i]);
    }
    hull = pts;
    pts.clear();
    vecs.clear();
    for (int i = 0; i < n; ++i) {
        while ((int)pts.size() >= 2 && cross(vecs.back(), p[q[i]] - p[pts.back()]) >= 0) {
            pts.pop_back();
            vecs.pop_back();
        }
        if (!pts.empty())
            vecs.push_back(p[q[i]] - p[pts.back()]);
        pts.push_back(q[i]);
    }
    pts.pop_back();
    reverse(pts.begin(), pts.end());
    pts.pop_back();
    hull.insert(hull.end(), pts.begin(), pts.end());
    vector<double> ans(n);
    for (int i = 0; i < (int)hull.size(); ++i) {
        auto r = p[i == (int)hull.size() - 1 ? hull[0] : hull[i + 1]] - p[hull[i]], l = p[hull[i]] - p[i == 0 ? hull.back() : hull[i - 1]];
        ans[hull[i]] = acos(1.0 * dot(l, r) / sqrt(1.0 * dot(l, l) * dot(r, r))) / (2 * PI);
    }
    cout << setprecision(10) << fixed;
    for (auto i : ans)
        cout << i << "\n";
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<limits.h>
#define rep(i,l,p) for(int i=l;i<=p;i++)
using namespace std;
int c[4][4];
int a[4],b[4];
bool tryAns(int x){
	a[1] = x;
	b[1] = c[1][1] - a[1];
	b[2] = c[1][2] - a[1];
	b[3] = c[1][3] - a[1];
	
	a[2] = c[2][1] - b[1];
	a[3] = c[3][1] - b[1];
//	rep(i,1,3){
//		cout << "a:" << a[i] << "  b:"<< b[i] << endl;
//	}
	rep(i,1,3){
		rep(j,1,3){
			if ( c[i][j] != a[i] + b[j] ) return false;
		}
	}
	return true;
}
int main(){
	rep(i,1,3){
		rep(j,1,3){
			scanf("%d",&c[i][j]);
		}
	}
	int tmp = 0;
	rep(i,1,3) tmp = max(tmp,c[1][i]);
	//cout << tmp << endl;
	rep(i,0,tmp){
		if ( tryAns(i) ) {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string.h>
#include<string>
#include<map>
#include<utility>
#include<functional>
typedef long long ll;
using namespace std;
typedef pair<int,float> p;

vector<ll> a,b,c;
int n,m;
string s;

int main(){
  cin >> n >> m;
  int a = n - m;
  printf("%d\n",(a>=0) ? a : 0);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin>>n>>m;
  lvector A(m,0),B(m,0);
  rep(i,m) {A[i]=i;B[i]=2*m-1-A[i];}
  rep(i,m/2) B[i]-=2*m+1;
  rep(i,m) {
    A[i]%=n,B[i]%=n;
    while(A[i]<0) A[i]+=n;
    while(B[i]<0) B[i]+=n; 
    A[i]++,B[i]++;
    printf("%lld %lld\n",A[i],B[i]);
  }
  return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
long dp[1<<21] = {0};
int main() {
    int n, i, j;
    cin >> n;
    int a[n][n];
    dp[0] = 1;
    for(i = 0; i < n; ++i)
        for(j = 0; j < n; ++j)
            cin >> a[i][j];
    for(i = 1; i < (1<<n); ++i)
        for(j = 0, dp[i] = 0; j < n; ++j)
            if(a[__builtin_popcount(i)-1][j] && i&(1<<j))
                dp[i] = (dp[i] + dp[i^(1<<j)]) % 1000000007;
    cout << dp[(1<<n)-1];
    return 0;
}


Measured memory_bytes: 19976
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
  public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
  public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};


int main(){
  int n; cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  
  vector<pii> ai(n);//<値, 実際にいる場所>
  rep(i,n) ai[i] = mp(a[i],i);

  sort(all(ai));

  int cnt = 0;
  rep(i,n) {
    int num = ai[i].second;
    if(abs(num-i)%2 == 1) cnt++;
  }

  cout << cnt/2 << endl;

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
 
typedef long long int ll;
const ll N = 1e6 +9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf= 1e14;
const ll mod = 1e9+7;
#define w first
#define v second
#define pb push_back
#define mp make_pair

const int MAX_N = 105, MAX_K = 1e5 + 5, MOD = 1e9 + 7;

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

     ll q = 1;
     // cin>>q;
     while(q--){
          ll n,k;cin>>n>>k;
          ll h[n];
          for(int i = 0;i<n;i++){
               cin>>h[i];
          }
          ll ans = 0;
          sort(h,h+n);
          reverse(h,h+n);
          for(int i = 0;i<n;i++){
               if(i>=k){
                    ans+=h[i];
               }
          }
          cout<<ans<<'\n';
     }
}         

Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();

            out.println(a <= b ? a : a - 1);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 23252
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max((min(b,d)-max(a,c)),1LL*0)<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bla
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            string s = Console.ReadLine();
            int[] b = new int[26];
            int[] a = new int[26];
            for (int i = 0; i < s.Length; i++)
            {
                b[s[i] - 'a']++;
            }
            int max = 0;
            for (int i = 0; i < s.Length; i++)
            {
                max = Math.Max(max, count(a, b));
                b[s[i] - 'a']--;
                a[s[i] - 'a']++;
            }
            Console.WriteLine(max);
        }

        static int count(int[] a, int[] b)
        {
            int r = 0;
            for (int i = 0; i < 26; i++)
            {
                if(a[i] != 0 && b[i] != 0)
                {
                    r++;
                }
            }
            return r;
        }
    }
}


Measured memory_bytes: 13140
#
# abc064 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
2 3 7 9"""
        output = """7"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """8
3 1 4 1 5 9 2 6"""
        output = """8"""
        self.assertIO(input, output)


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

    a.sort()
    print(a[-1]-a[0])


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16216
import kotlin.math.abs
import kotlin.math.max

class MaxHappinessCalculator(
    private val n: Int,
    private val a: Array<Long>
) {
    private val memo = Array(n + 1) { Array(n + 1) { null as Long?} }
    private val sorted = (0 until n).sortedByDescending { a[it] }

    private fun calcFromMemo(l: Int, r: Int): Long {
        val memoed = memo[l][r]
        if (memoed != null) {
            return memoed
        }

        val ans = calc(l, r)
        memo[l][r] = ans
        return ans
    }

    fun calc(l: Int, r: Int): Long {
        val m = l + r
        if (m == n) {
            return 0
        }

        val i = sorted[m]
        val lans = calcFromMemo(l + 1, r) + a[i] * abs(l - i)
        val rans = calcFromMemo(l, r + 1) + a[i] * abs((n - r - 1) - i)

        return max(lans, rans)
    }
}

fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }.toTypedArray()

    val ans = MaxHappinessCalculator(n, a).calc(0, 0)
    println(ans)
}


Measured memory_bytes: 116924
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

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

    int n,d,ans = 0;
    cin>>n>>d;
    vector<int>x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];

    rep(i,n)if(sqrt(pow(x[i],2)+pow(y[i],2)) <= d)ans++;
    
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 4772
#include <stdio.h>
#define MAX 40
int N;
char C1[MAX],C2[MAX];
int D1[MAX],D2[MAX];
void Printf1(void){
  int i;
  for(i=0;i<N-1;i++){
    printf("%c%d ",C1[i],D1[i]);
  }
  printf("%c%d",C1[N-1],D1[N-1]);

}
void Printf2(void){
  int i;
  for(i=0;i<N-1;i++){
    printf("%c%d ",C2[i],D2[i]);
  }
  printf("%c%d",C2[N-1],D2[N-1]);

}
void BubbleSort(void){
  int i,j,c;
  char m;
  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
      if(D1[j]<D1[j-1]){
	c=D1[j-1];
	D1[j-1]=D1[j];
	D1[j]=c;
	m=C1[j-1];
        C1[j-1]=C1[j];
        C1[j]=m;

      }

    }
  }
  Printf1();
  printf("\nStable\n");
}
void SelectionSort(void){
  int x=0,i,miji,j;
  char m;
  for(i=0;i<N;i++){
    miji=i;
    for(j=i;j<N;j++){
      if(D2[j]<D2[miji])miji=j;
    }
    x=D2[i];
    D2[i]=D2[miji];
    D2[miji]=x;
    m=C2[i];
    C2[i]=C2[miji];
    C2[miji]=m;
  }
  Printf2();
  for(i=0;i<N;i++){
    if(C1[i]!=C2[i]||D2[i]!=D1[i]){
      printf("\nNot stable\n");
      return;
    }
  }
  
 printf("\nStable\n");
  
}
int main(){
  int x,i;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf(" %c%d",&C1[i],&D1[i]);
    D2[i]=D1[i];
    C2[i]=C1[i];
}
BubbleSort();
 SelectionSort();

  return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

vector<pint> pv;
stack<int> st;
int r,c;
int ck(int x,int y){
    if(x==0) return y;
    else if(y==c) return c+x;
    else if(x==r) return c+r+c-y;
    else if(y==0) return c+r+c+r-x;
    else return -1;
}
int main(){
    int n;
    cin>>r>>c>>n;
    int fx,fy,sx,sy;
    rep(i,n){
        cin>>fx>>fy>>sx>>sy;
        int fs=ck(fx,fy),sd=ck(sx,sy);
        if(fs>sd) swap(fs,sd);
        if(fs!=-1&&sd!=-1){
            pv.pb(fs,sd);
        }
    }
    sort(pv.begin(),pv.end());
    for(auto p:pv){
        while(!st.empty()&&st.top()<p.first) st.pop();
        if(!st.empty()&&st.top()<p.second){
            cout<<"NO"<<endl;return 0;
        }
        else st.push(p.second);
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 1400
n,h = map(int,input().split())

b_sum = 0
a_max = 0

a_li = []
b_li = []

for i in range(n):
    a,b = map(int,input().split())
    a_li.append(a)
    b_li.append(b)


a_li.sort(reverse=True)
b_li.sort(reverse=True)

pt = 0
a_num = 0
b_num = 0
ans = 0

for i in range(2*n):
    if b_num >= n:
        ans += (h-pt+a_li[a_num]-1) // a_li[a_num]
        print(ans)
        exit()
    if a_li[a_num] < b_li[b_num]:
        pt += b_li[b_num]
        b_num += 1
        ans += 1
        if pt >= h:
            print(ans)
            exit()
    else:
        ans += (h-pt+a_li[a_num]-1) // a_li[a_num]
        print(ans)
        exit()

Measured memory_bytes: 11336
#include "bits/stdc++.h"
using namespace std;

struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

signed main() {
	char b;

	cin >> b;

	if( b=='A' ){ cout << 'T' << endl; }
	if (b == 'T') { cout << 'A' << endl; }
	if (b == 'C') { cout << 'G' << endl; }
	if (b == 'G') { cout << 'C' << endl; }



	return 0;
}


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

ll f(ll station_idx, ll start_time, long long N, const std::vector<long long>& C, const std::vector<long long>& S, const std::vector<long long>& F)
{
    if (station_idx == N - 1) {
        return start_time;
    }

    ll ride_time = max((start_time + F[station_idx] - 1) / F[station_idx] * F[station_idx], S[station_idx]);

    return f(station_idx + 1, ride_time + C[station_idx], N, C, S, F);
}

void solve(long long N, std::vector<long long>&& C, std::vector<long long>&& S, std::vector<long long>&& F)
{
    for (ll i = 0; i < N; ++i) {
        cout << f(i, 0, N, C, S, F) << "\n";
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> C(N-1);
    std::vector<long long> S(N-1);
    std::vector<long long> F(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&C[i]);
        scanf("%lld",&S[i]);
        scanf("%lld",&F[i]);
    }
    solve(N, std::move(C), std::move(S), std::move(F));
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
        long long x, y, a, b, c;
        cin>>x>>y>>a>>b>>c;
        long long p[a], q[b], r[c];
        for(long long i=0;i<a;i++){
                cin>>p[i];
        }sort(p,p+a);
        for(long long i=0;i<b;i++){
                cin>>q[i];
        }sort(q,q+b);
        for(long long i=0;i<c;i++){
                cin>>r[i];
        }sort(r,r+c);
        long long ans[x+y];
        for(long long i=0;i<x;i++){
                ans[i]=p[a-1-i];
        }for(long long i=0;i<y;i++){
                ans[x+i]=q[b-1-i];
        }sort(ans, ans+(x+y));
        for(long long i=0;i<c;i++){
                if(ans[i]<r[c-1-i]){
                        ans[i]=r[c-1-i];
                }else{
                        break;
                }
        }long long total=0;
        for(long long i=0;i<(x+y);i++){
                total+=ans[i];
        }cout<<total<<endl;
        return 0;
}

Measured memory_bytes: 3968
#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

int main(){

    int n,m;

    cin >> n >> m;

    vector<int> elev(n);



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

    vector<int> road[n];
    for(int i = 0; i < m; i++){

        int a, b;
        cin >> a >> b;

        a--; b--;
        road[a].push_back(b);
        road[b].push_back(a);
    }

    int countGood = 0;

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

        bool good = true;;

        int count = 0;

        while(good && count < road[i].size()){

            int comp = road[i][count];

            if(elev[i] <= elev[comp]){
                good = false;
            }
            count++;

        }

        if(good)
            countGood++;

    }

    cout << countGood << endl;
}

Measured memory_bytes: 8808
import numpy as np

def solve(n, k, aaa, fff):
  aaa = np.sort(aaa)
  fff = np.sort(fff)[::-1]
  
  l = 0
  r = 10**12
  while l<=r:
    m = (l+r)//2
    req = np.clip(aaa - m//fff, 0, None).sum()

    if req <= k:
      r = m-1
    else:
      l = m+1

  return l


N, K = map(int,input().split())
aaa = np.array(list(map(int,input().split())))
fff = np.array(list(map(int,input().split())))

print(solve(N, K, aaa, fff))


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

int main(){
    int n, w = 0, r = 0;
    cin >> n;
    vector<char> c(n);
    for (int i = 0; i < n; ++i){
        cin >> c[i];
        if (c[i] == 'W') ++w;
        else ++r;
    }
    int leftW = 0, rightR = r;
    int ans = r;
    for (int i = 0; i < n; ++i){
        if (c[i] == 'W') ++leftW;
        else --rightR;
        int temp = max(leftW, rightR);
        if (temp < ans) ans = temp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, M;
    cin >> N >> M;

    vector<P> PY(M), PYO(M);
    map<P, int> ans;
    map<int, int> cnt;

    rep(i, M) {
        cin >> PY[i].first >> PY[i].second;
        PYO[i] = PY[i];
    }

    sort(all(PYO));
    rep(i, M) {
        if (cnt.count(PYO[i].first) == 0) {
            cnt[PYO[i].first] = 1;
        }
        else {
            cnt[PYO[i].first]++;
        }
        ans[PYO[i]] = cnt[PYO[i].first];
    }

    rep(i, M) {
        printf("%06d%06d\n", PY[i].first, ans[PY[i]]);
    }
    return 0;
}

Measured memory_bytes: 13952
#include <iostream>
#include <vector>

#define MAX_S 1000000

using namespace std;

string s;
int ren[MAX_S];

int main() {

    cin >> s;

    int cnt = 1;
    int j = 0;
    for (int i = 1; i < s.length(); i++) {
        if (s[i] != s[i - 1]) {
            ren[j] = cnt;
            cnt = 1;
            j++;
        } else {
            cnt++;
        }
    }
    ren[j] = cnt;

    int min = MAX_S;
    int head = 0;
    int tail;
    for (tail = 0; tail < MAX_S && ren[tail] != 0; tail++) {
        //cout << ren[tail];
    }
    //cout << endl;
    tail--;

    if (tail == 0) {
        cout << s.length() << endl;
        return 0;
    }

    while(head < tail) {


        if(s.length() - ren[tail] >= s.length() - ren[head]) {
            if (min > s.length() - ren[tail]) min = s.length() - ren[tail];
            ren[tail - 1] += ren[tail];
            tail--;
        } else {

            if (min > s.length() - ren[head]) min = s.length() - ren[head];
            ren[head + 1] += ren[head];
            head++;
        }
    }

    cout << min << endl;
}

Measured memory_bytes: 640