akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

struct Node
{
    int key;
    Node *parent, *right, *left;
};

Node *NIL;
Node *root = NIL;

void Insert(int key)
{
    Node *y = NIL; //親
    Node *x = root;
    Node *z = new Node;
    z->key = key;
    z->right = NIL;
    z->left = NIL;

    while (x != NIL)
    {
        y = x;
        if (z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }

    z->parent = y;

    if (y == NIL)
    {
        root = z;
    }
    else if (z->key < y->key)
    {
        y->left = z;
    }
    else
    {
        y->right = z;
    }
}

void inorder(Node *u)
{
    if (u == NIL)
    {
        return;
    }
    inorder(u->left);
    cout << ' ' << u->key;
    inorder(u->right);
}

void preorder(Node *u)
{
    if (u == NIL)
    {
        return;
    }
    cout << ' ' << u->key;
    preorder(u->left);
    preorder(u->right);
}

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

    int n, k;
    string com;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> com;
        if (com == "insert")
        {
            cin >> k;
            Insert(k);
        }
        else if (com == "print")
        {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 26592
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=210;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
struct EDGE { int v,w,nx; }lb[N*N*N<<3]; int tot=1,top[N*N],cur[N*N];
void add (int u,int v,int w)
{
	lb[++tot]=(EDGE){v,w,top[u]},top[u]=tot;
	lb[++tot]=(EDGE){u,0,top[v]},top[v]=tot;
}
int s,t,dep[N*N];
bool bfs ()
{
	memcpy (cur,top,sizeof (int)*(t+1));
	memset (dep,0,sizeof (int)*(t+1));
	queue <int> q;
	dep[s]=1,q.push (s);
	while (q.size ())
	{
		int u=q.front (); q.pop ();
		for (int kb=top[u]; kb; kb=lb[kb].nx)
		{
			int v=lb[kb].v,w=lb[kb].w;
			if (w&&!dep[v]) dep[v]=dep[u]+1,q.push (v);
		}
	}
	return dep[t];
}
int dinic (int u,int flow)
{
	if (u==t) return flow;
	int rest=flow;
	for (int &kb=cur[u]; kb; kb=lb[kb].nx)
	{
		int v=lb[kb].v,w=lb[kb].w;
		if (w&&dep[v]==dep[u]+1)
		{
			int k=dinic (v,min (rest,w));
			if (!k) dep[v]=1;
			rest-=k;
			lb[kb].w-=k,lb[kb^1].w+=k;
			if (!rest) break;
		}
	}
	return flow-rest;
}
int n,m,a[N][N],p[N*N],id[N][N],pos[N][N],b[N][N],c[N][N];
bool us[N][N];
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n),sc(m);
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++)
			sc(a[i][j]),p[(i-1)*m+j]=i;
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++)
			id[i][j]=++id[0][0];
	s=n*m+n*2+1,t=s+1;
	for (int l=1; l<=m; l++)
	{
		memset (top,0,sizeof (int)*(t+1));
		for (int i=1; i<=n; i++)
		{
			add (s,n*m+i,1),add (n*m+n+i,t,1);
			for (int j=1; j<=m; j++) if (!us[i][j])
				add (n*m+i,id[i][j],1),add (id[i][j],n*m+n+p[a[i][j]],1),pos[i][j]=tot;
		}
		while (bfs ())
			while (dinic (s,oo));
		for (int i=1; i<=n; i++)
			for (int j=1; j<=m; j++) if (!us[i][j])
				if (lb[pos[i][j]].w) b[i][l]=a[i][j],us[i][j]=1;
	}
	for (int i=1; i<=n; i++,putchar('\n'))
		for (int j=1; j<=m; j++,putchar(' '))
			print(b[i][j]);
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++)
			c[p[b[i][j]]][j]=b[i][j];
	for (int i=1; i<=n; i++,putchar('\n'))
		for (int j=1; j<=m; j++,putchar(' '))
			print(c[i][j]);

    return 0;
}


Measured memory_bytes: 25984
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    set<int> st;
    REP(i, n){
        int x; cin >> x;
        st.insert(x);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
dists = list(map(int, input().split()))
 
import sys
n = N - 1
idists = [d - 1 for d in dists]
visits = [-1] * N
 
# 手レポーターがループしてる部分を探す
now = 0
count = 0
while True:
#     print(now, visits)
    if visits[now] >= 0:
        break
    visits[now] = count
    now = idists[now]
    count += 1
    if count == K:#早く着いちゃった
        print(now + 1)
        sys.exit()
 
# ループを端折る
cycle = count - visits[now]
rest = (K - count) % cycle
for _ in range(rest):
#     print(" ", now)
    now = idists[now]
print(now + 1)

Measured memory_bytes: 100660
#include <iostream>
#include <string>
#include <stdlib.h>
#include <sstream>

using namespace std;
 
int main() {
    int n;
    string num;
    cin >> n;
    std::ostringstream oss;

    oss << n;
    num = oss.str();

    char check;
    check = '7';
    string rslt;

    for (int i=0; i < num.size(); i++) {
        char target = num[i];
        if ( check == target ) {
            rslt = "Yes";
            break;
        } else {
            rslt = "No";
        }
    }
    cout << rslt << endl;
}

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

int main() 
{
  int n, k;
  cin >> n >> k;
  vector<int> data(n);
  for(int i = 0; i < n; i++)
  {
    cin >> data.at(i);
  }
  sort(begin(data), end(data));
  reverse(begin(data), end(data));
  int answer = 0;
  for(int i = 0; i < k; i++){
    answer += data.at(i);
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	val n = f.readLine().toInt()
	val array = BooleanArray(n){
		val (a,b) = f.readLine().split(" ").map{it.toInt()}
		a==b
	}

	fun check() : Boolean{
		for(i in 0 until n-2){
			if(array[i] && array[i+1] && array[i+2]) return true
		}
		return false
	}

	if(check()){
		println("Yes")
	} else {
		println("No")
	}

}


Measured memory_bytes: 36456
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {

	private static final int N = 3;

	@SuppressWarnings("unchecked")
	private static final Set<Integer>[] SETS = new Set[N];

	static {
		IntStream.range(0, N).forEach(i -> SETS[i] = new HashSet<>());
	}

	static {
		SETS[0].add(1);
		SETS[0].add(3);
		SETS[0].add(5);
		SETS[0].add(7);
		SETS[0].add(8);
		SETS[0].add(10);
		SETS[0].add(12);
	}

	static {
		SETS[1].add(4);
		SETS[1].add(6);
		SETS[1].add(9);
		SETS[1].add(11);
	}

	static {
		SETS[2].add(2);
	}

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			System.out.println((getSet(x) == getSet(y)) ? "Yes" : "No");
		}
	}

	/**
	 * @param n 入力数字
	 * @return 入力数字を含まれるセット
	 */
	private static Set<Integer> getSet(int n) {
		for (Set<Integer> set : SETS) {
			if (set.contains(n)) {
				return set;
			}
		}
		return null;
	}
}


Measured memory_bytes: 28228
from heapq import heappop, heappush

n, m = map(int, input().split())
xy = [tuple(int(x)-1 for x in input().split()) for _ in range(m)]

R = [[] for _ in range(n)]
h = [0] * n

for x, y in xy:
    R[x].append(y)
    h[y] += 1

S = []

st = []

for i in range(n):
    if h[i] == 0:
        heappush(st, i)

while len(st) > 0:
    temp = heappop(st)
    S.append(temp)
    for x in R[temp]:
        h[x] -= 1
        if h[x] == 0:
            heappush(st, x)

if len(S) != n:
    print(-99999)
else:
    print(-1)

Measured memory_bytes: 3444
import Control.Applicative
main = do
  ns <- map (read :: String -> Int) . lines <$> getContents
  mapM print . map solve $ ns
  where solve n = length . filter ((==) n) $ [a + b + c + d| a <- [0..9], b <- [0..9], c <- [0..9], d <- [0..9]]

Measured memory_bytes: 4096
A, B ,K  = (int(x) for x in input().split())
i = 1
ans = []
while True:
    if min(A,B) < i:
        break
    if (A % i == 0) & (B % i == 0):
        ans.append(i)
    i = i + 1
print(ans[len(ans)-K])

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

using namespace std;
vector<int> v;
int main(){
	int n, a;

	cin >> n;

	while(n !=  0){
		a = n % 10;
		v.push_back(a);
		n /= 10;
	}

	for(int i = v.size() - 1; i >= 0; i--){
		if(v[i] == 9){
			cout << 1;
		}
		else{
			cout << 9;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    string S;
  	cin >> S;
  	int ans1=0;
  	int ans2=0;
    int length = S.size();
    for(int i=0; i < length; ++i){
  	if(i%2 == S[i]-'0'){
    ans1++;
    }
    else if(i%2 != S[i]-'0'){
    ans2++;
    }
    }
  cout << min(ans1,ans2) <<endl;
}


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

long long int m=1000000007;
long long int ans=0;

long long int nextPowerOf2(long long int n)   
{ 
    n--; 
    n |= n >> 1; 
    n |= n >> 2; 
    n |= n >> 4; 
    n |= n >> 8; 
    n |= n >> 16; 
    n++; 
    return n; 
}

int isPowerOfTwo(long long int n)  
{  
    if (n == 0)  
        return 0;  
    while (n != 1)  
    {  
        if (n%2 != 0)  
            return 0;  
        n = n/2;  
    }  
    return 1;  
}

int main(){
	// your code goes here
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	cout.tie(NULL);
	
	long long int h;
	cin>>h;
	if(h!=0){
	    ans=nextPowerOf2(h);
	    if(isPowerOfTwo(h)==1){
	        ans=ans*2;
	    }
	    ans--;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll N; cin>>N;
    vector<ll>a(N);
    ll a4=0,a2=0,as=0;
    rep(i,N){
        cin>>a[i];
        if(a[i]%4==0)a4++;
        else if(a[i]%2==0)a2++;
        else as++;
    }
    ll mn =min(a4,as);
    ll cnt=0;
    cnt+=mn*2;
    a4-=mn; as-=mn;
    if(a4==0){
        if(as==0){
            cout<<"Yes"<<endl;
        }
        else if(as==1&&cnt==N-1){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    else cout<<"Yes"<<endl;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr int INF = 1001001001;
int N;
int dp[100100];
std::vector<int> v;

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

    std::cin >> N;

    v.emplace_back(1);

    {
        int pr = 1;
        for(int i=0;i<6;++i){
            pr *= 6;
            v.emplace_back(pr);
        }
    }

    {
        int pr = 1;
        for(int i=0;i<5;++i){
            pr *= 9;
            v.emplace_back(pr);
        }
    }

    std::fill(dp + 1, dp + N + 1, INF);
    
    for(int i=1;i<=N;++i){
        for(int j : v){
            if(i - j >= 0){
                dp[i] = std::min(dp[i], dp[i - j] + 1);
            }
        }
    }

    std::cout << dp[N] << std::endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    ll n,y;cin>>n>>y;
    rep(i,0,n+1){
        rep(j,0,n+1){
            if(10000*i + 5000*j + 1000*(n-(i+j)) == y && (n-(i+j)) >= 0){
                cout << i << " " << j << " " << (n-(i+j)) << ednl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926535897932384626433
int main()
{
  //freopen("in.txt","r",stdin);  
  int r;
  cin>>r;
  double c;
  c= 2*pi*r;

  cout<<setprecision(30)<<c<<endl;
  return 0;


}

Measured memory_bytes: 3732
AL = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
 
N = int(input())
 
S = input()
A = []
 
for i in range(len(S)):
  B = AL.index(S[i])+N
  if B >= 26:
    B = B -26
  A.append(AL[B])
  
for j in range(len(S)):
  print(A[j], end='')

Measured memory_bytes: 4596
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int main()
{
  int n;
  int count[100] = { 0 };
  int ans[100] = { 0 };
  int bigcnt = 0;

  while(scanf("%d",&n) != EOF){
    count[n-1]++;
  }

  for(int i = 0;i < 100;i++){
    if(bigcnt < count[i]){
      bigcnt = count[i];
    }
  }
  
  int j = 0;

  for(int i = 0;i < 100;i++){
    if(bigcnt == count[i]){
      ans[j] = i+1;
      j++;
    }
  }
  
  for(int i = 0;i < j;i++){
    cout << ans[i] << endl;
  }
  
}

Measured memory_bytes: 1208
import itertools

def dist(x1,y1,x2,y2):
    return ((x1-x2)**2+(y1-y2)**2)**0.5

def fact(n):
    ans=1
    for i in range(n):
        ans*=(i+1)
    return ans

n=int(input())
d=[[] for _ in range(n)]
for i in range(n):
    d[i]=list(map(int,input().split()))

ls=list(itertools.permutations(range(n)))
ans=0
for l in ls:
   for i in range(n-1):
       ans+=dist(d[l[i]][0],d[l[i]][1],d[l[i+1]][0],d[l[i+1]][1])
ans/=fact(n)
print(ans)

Measured memory_bytes: 13916
#include <stdio.h>
#define REP(i, n) for(i = 0; i < n; ++i)
#define FOR(i, a, b) for(i = a; i < b; ++i)
#define BORDER 400

void yes_or_no(char boolean){
    if(boolean){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
}

int main(){
    int N, i;
    int score = 0;
    int tourist = 0;
    char exist[8];
    scanf("%d", &N);

    REP(i, 8){
        exist[i] = 0;
    }

    REP(i, N){
        scanf("%d", &score);
        if(score < BORDER * 8) exist[score/BORDER] = 1;
        else{
            tourist++;
        }
    }

    int min = 0;

    REP(i, 8){
        if(exist[i]){
            min++;
        }
    }
    if(min == 0){
        printf("1 %d\n", tourist);
    }else{
        printf("%d %d\n", min, min + tourist);
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int tairyoku = scanner.nextInt();
        int kougekiryoku = scanner.nextInt();

        int kaisuu = tairyoku/kougekiryoku;
        if (tairyoku%kougekiryoku>0){
            kaisuu++;
        }

        System.out.println(kaisuu);
    }
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int n = s.size();
    for(int i=(n-1)/2;i>0;i--){
        if (s.substr(0,i)==s.substr(i,i)){
            cout<<i*2;
            exit(0);
        }
    }
    
}


Measured memory_bytes: 3540
use strict;
use warnings;

use List::Util qw(max min);

my $n = <>;
my $s = <>;
chomp $s;

my $bl = 0;
my $wh = 0;

for(my $i = 0; $i < length $s; $i++){
    if(substr($s, $i, 1) eq '#'){
        $bl++;
    } else {
        $wh++;
    }
}

my $cn = 0;

my $nowmax = min($bl, $wh);

my $bln = 0;
my $whn = 0;

for(my $i = 0; $i < length $s; $i++){
    if(substr($s, $i, 1) eq '#'){
        $bln++;
        $bl--;
    } else {
        $whn++;
        $wh--;
    }
    my $now = $bln + $wh;
    $nowmax = min($now, $nowmax);
}

print $nowmax;


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;

int main(){
  int n;
  cin >> n;
  ll a[n],b[n];
  rep(i,n){
    cin >> a[i];
    b[i]=a[i];
  }
  rep(i,n){
    b[i]*=-1;
    b[i]+=i+1;
  }
  ll ans=0;
  sort(b,b+n);
  rep(i,n){
    ans+=upper_bound(b,b+n,a[i]+i+1)-lower_bound(b,b+n,a[i]+i+1);
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 6736
#include <iostream>
#include <math.h>
using namespace std;
#define mod 1000000007

long long int POWER(long long int K,long long int r,long long int N,int count){//ans=k^n
    count++;
    if(pow(2,count)<N){
        r=(r*r)%mod;
        return POWER(K,r,N,count);
    }else{
        count--;
        int m=N-pow(2,count);
        if(m==0){
            return r;
        }else{
            return (r*(POWER(K,K,m,0)%mod))%mod;
        }
    }
}

int main(){
    long long int N,K;
    cin >> N >> K;
    long long int ans[K+1];
    for(int i=K;i>=1;i--){
        ans[i]=POWER(K/i,K/i,N,0);
        int j=2*i;
        while(j<=K){
            ans[i]=(ans[i]-ans[j])%mod;
            j+=i;
        }
    }
    long long int Ans=0;
    for(int i=1;i<=K;i++){
        long long int m = i*ans[i]%mod;
        Ans=(Ans+m)%mod;
    }
    cout << Ans <<endl;
    return 0;
    return 0;
}

Measured memory_bytes: 4880
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a,ll b){
	ll c;
	while(a%b!=0){
		c = b;//小さい方の数を保存しておく
		b = a%b;//大きい方で小さい方を割ってそのあまりを求める bはaよりも絶対に小さくなる
		a = c;//最初に保存した小さい方の数を復元する
	}
	return b;
}


int main(void){
	int N;
	cin >> N;
	vector<ll> A(N);
	ll ans;
	for(int i=0;i<N;i++){
		cin >> A[i];
		if(i==0)ans=A[i];
		else ans = gcd(ans,A[i]);
	}
	cout << ans << endl;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<long> dp(N + 1), dp2(N * 5000 + 1);
    for(unsigned long i = 0; i <= N; ++i)dp[i] = i;
    for(unsigned long i = 0; i <= N * 5000; ++i)dp2[i] = i;
    long gA, sA, bA, gB, sB, bB;
    cin >> gA >> sA >> bA >> gB >> sB >> bB;
    for(long i = gB; i <= N * 5000; ++i)dp2[i] = max(dp2[i], dp2[i - gB] + gA);
    for(long i = sB; i <= N * 5000; ++i)dp2[i] = max(dp2[i], dp2[i - sB] + sA);
    for(long i = bB; i <= N * 5000; ++i)dp2[i] = max(dp2[i], dp2[i - bB] + bA);
    for(long i = gA; i <= N; ++i)dp[i] = max(dp[i], dp[i - gA] + gB);
    for(long i = sA; i <= N; ++i)dp[i] = max(dp[i], dp[i - sA] + sB);
    for(long i = bA; i <= N; ++i)dp[i] = max(dp[i], dp[i - bA] + bB);
    /*for(const auto i : dp)cout << i << " ";
    cout << endl;
    for(const auto i : dp2)cout << i << " ";
    cout << endl;*/
    cout << dp2[dp.back()] << endl;
    return 0;
}

Measured memory_bytes: 195712
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    if(n%1000==0) cout<<0<<endl;
    else cout<<1000 - n%1000<<endl;

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    map<ll, vector<ll>> B;
    rep(i,N) {
        ll a, b; cin >> a >> b;
        A.at(i) = a;
        B[b].push_back(i);
    }

    ll cur = 0;
    for (auto [L, V] : B) {
        for (auto x : V) {
            cur += A[x];
        }        
        if (cur > L) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

int main() {

int N;
scanf("%d",&N);
char Text[10001];
scanf("%s",&Text);

int  ASC[10001];
for (int i=0;i<strlen(Text);i++)
{
    ASC[i]=Text[i]-0;
    ASC[i]+=N;
    if (ASC[i]>90)ASC[i]=ASC[i]-90+64;
}



for (int i=0;i<strlen(Text);i++)
printf("%c",ASC[i]);

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
         long long int n,a,b,s;
         cin>>n>>a>>b;
         s=a+b;
         long long int ans=n/s;
         long long int r=n%s;
         long long int z=min(r,a);
         long long int ans2=z+ans*a;
         cout<<ans2<<endl;
         return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: int):
    first0 = 0
    first1 = 0
    for i in range(len(S)):
        c = S[i]
        if i % 2 == 0:
            if c == '0':
                first0 += 1
            else:
                first1 += 1
        else:
            if c == '0':
                first1 += 1
            else:
                first0 += 1
    print(min(first0, first1))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: int
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define vi vector <int>
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    int l = a+b-1;
    cout << l/b*c;
    return 0;
}

Measured memory_bytes: 3624
K, N = map(int,input().split())
a_list = list(map(int,input().split()))


dist_list = []

for i in range(len(a_list)-1):
    dist_list.append(a_list[i+1]-a_list[i])

dist_list.append(K+a_list[0]-a_list[-1])

max_dist = max(dist_list)

print(K-max_dist)

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

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;

	vector<int> A;
	char group = S[0];//'0'のグループか '1'のグループかを格納
	int cnt = 0;
	for(int i=0; i<N; i++){
		if(S[i] == group) cnt++;
		else{
			A.push_back(cnt);
			group = S[i];
			cnt = 1;
		}
	}
	A.push_back(cnt);

	if(A.size() == 1){
		cout << N << endl;
		return 0;
	}
	vector<int> wa;
	wa.push_back(0);
	for(int i=0; i<A.size(); i++) wa.push_back(wa.back()+A[i]);
	// cout << " A: "; print_vec(A);

	int ans = 0;
	if(S[0] == '0'){
		int tmp = 0;
		for(int i=0; i<2*K; i++){
			if(i<A.size()) tmp += A[i];
		}
		ans = max(ans, tmp);	
	}
	if(S.back() == '0'){
		int tmp = 0;
		for(int i=0; i<2*K; i++){
			if(A.size()-1-i >= 0) tmp += A[A.size()-1 - i];
		}
		ans = max(ans, tmp);
	}
	if(S[0] == '0'){
		reverse(wa.begin(), wa.end());
		wa.pop_back();
		reverse(wa.begin(), wa.end());
	}
	if(wa.size() > 0 && S.back() == '0') wa.pop_back();
	

	int range = 2*K + 1;
	for(int left = 0; left<wa.size(); left +=2){
		int right = left + range;
		if(right > wa.size()-1) right = wa.size() - 1;
		if(right < left) continue;
		ans = max(ans, wa[right]-wa[left]);
	}

	cout << ans << endl;
	
	


}



Measured memory_bytes: 4332
def Minimization(N,K,Alist):
    minindex = Alist.index(min(Alist))
    leftnum = minindex
    rightnum = N - (minindex + 1)
    print(-(-(leftnum+rightnum) // (K-1)))
N,K = list(map(int,input().split()))
Alist = input().split()
Alist = list(map(int,Alist))
Minimization(N,K,Alist)

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

int main() {
    int n;
    vector<int> h;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int input;
        cin >> input;
        h.push_back(input);
    }

    h[0] = h[0]-1;
    for (int i = 1; i < n-1; i++) {
        if (h[i-1] <= h[i]-1 && h[i]-1 <= h[i+1]) {
            h[i] = h[i]-1;
            continue;
        } else if (h[i-1] <= h[i] && h[i] <= h[i+1]) {
            continue;
        } else {
            cout << "No" << endl;
            exit(0);
        }
    }
    cout << "Yes" << endl;
}

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

using namespace std;

const int MAX = 2000001;
const int VMAX = 10001;

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

  vector <int> A(N + 1), B(N + 1), C(VMAX + 1, 0);

  for(int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  for(int j = 1; j <= N ; j++){
    C[A[j]] = C[A[j]] + 1;
  }
  for(int i = 1; i <= VMAX; i++){
    C[i] = C[i] + C[i-1];
  }

  for(int j = N; j >= 1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]] - 1;
  }

  for(int i = 1 ; i <= N; i++){
    if (i > 1) {
      cout << " ";
    }
    cout << B[i];
  }
  cout << endl;
}


Measured memory_bytes: 18320
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

vector<int>ve[120000];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,k;
	cin>>n>>k;
	int x,y;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		if(x>k) continue;
		int tt=k-x+1;
		ve[tt].push_back(y);
	}
	
	priority_queue<int>q;
	int ans=0;
	for(int i=k;i>=1;i--){
		for(int j=0;j<ve[i].size();j++) q.push(ve[i][j]);
		if(!q.empty()){
			ans+=q.top();
			q.pop();	
		}
	}
	cout<<ans<<"\n";
	
	return 0;
} 

Measured memory_bytes: 6144
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)
  
  
ans = 0
k = int(input())
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1): 
            ans += gcd(gcd(a, b), c)
print(ans)
       

Measured memory_bytes: 76872
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define int long long
#define maxn (100010)
int n, m, top, s[maxn], cnt[maxn], sum[maxn];

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
		ch == '-' ? f = -1, ch = getchar() : ch = getchar();
	while (ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return x * f;
}

void sol(int x, int del) {
//	printf("X %lld %lld\n", x, del);
	if (!x) return;
	int pos = upper_bound(s + 1, s + top + 1, x) - s - 1; // 找到比他大的，然后-1 
//	printf("POS %lld\n", pos);
	if (!pos) sum[1] += del, sum[x + 1] -= del;
	else cnt[pos] += (x / s[pos]) * del, sol(x % s[pos], del);
}

signed main() {
	n = read(), m = read();
	s[++top] = n;
	int x;
	for (int i = 1; i <= m; ++i) {
		x = read();
		while (top && s[top] >= x) --top;
		s[++top] = x;
	}
	cnt[top] = 1;
	for (int i = top; i >= 2; --i) {
		cnt[i - 1] += (s[i] / s[i - 1]) * cnt[i];
//		printf("	%lld %lld %lld\n", s[i] % s[i - 1], cnt[i], i);
		sol(s[i] % s[i - 1], cnt[i]);
	}
//	for (int i = 1; i <= top; ++i) printf("%lld\n", cnt[i]);
	sum[1] += cnt[1], sum[s[1] + 1] -= cnt[1]; // s[1]为最长长度
	for (int i = 1; i <= n; ++i) sum[i] += sum[i - 1];
	for (int i = 1; i <= n; ++i) printf("%lld\n", sum[i]); 
	return 0;
}


Measured memory_bytes: 3968
#include <stdio.h>
#include <stdlib.h>

int a[100]={0};

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

int main(){
    int N;
    int ans=0;

    scanf("%d",&N);
    for (int i=0;i<N;i++){
	scanf("%d",&a[i]);
    }
    qsort((void*)a,N,sizeof(a[0]),sort);

    for (int i=0;i<N;i++){
	if (i%2 == 0) ans+=a[i];
	else ans-=a[i];
    }

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

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int n = sc.nextInt();
        int[] num = new int[w];
        for(int i = 0; i < w; i++){
            num[i] = i+1;
        }
        int c;
        for(int i = 0; i < n; i++){
            String str = sc.next();
            String[] ab = str.split(",");
            int a = Integer.parseInt(ab[0])-1;
            int b = Integer.parseInt(ab[1])-1;
            c = num[a];
            num[a] = num[b];
            num[b] = c;
        }
        for(int i = 0;i < w; i++){
            System.out.println(num[i]);
        }
    }    
}


Measured memory_bytes: 26392
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

int n,r;
vi d(3);

int main(){
	while(1){
		cin>>d[0]>>d[1]>>d[2];
		if(d[0]+d[1]+d[2]==0) break;
		sort(d.begin(),d.end());
		double tmp=(double)sqrt(d[0]*d[0]+d[1]*d[1]);
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>r;
			if(2*r>tmp) cout<<"OK"<<endl;
			else cout<<"NA"<<endl;
		}
	}
}

Measured memory_bytes: 1200
#include <iostream>
using namespace std;
int main(){
      int a,i;
      while(cin>>a){
            for(i=0;i<=9;i++){
                  if(a&(1<<i)){
                        cout<<(1<<i);
                        if(a<(2<<i))break;
                        cout<<' ';
                  }
            }
            cout<<endl;
      }
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int main() {
  string in;
  cin >> in;

  if (in[0] > in[1]) {
    for (int i = 0; i < in.size(); i++) {
      cout << in[0];
    }    
    cout << endl;
    return 0;
  } else if (in[0] < in[1]) {
    for (int i = 0; i < in.size(); i++) {
      cout << char(int(in[0]) + 1);
    }    
    cout << endl;
    return 0;
  } else if (in[0] >= in[2]) {
    for (int i = 0; i < in.size(); i++) {
      cout << in[0];
    }    
    cout << endl;
    return 0;
  } else {
    for (int i = 0; i < in.size(); i++) {
      cout << char(int(in[0]) + 1);
    }    
    cout << endl;
    return 0;
  }

  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int l, r;
    cin >> l >> r;

    if (r - l + 1 >= 2019) {
        cout << 0 << endl;
        return 0;
    }
    ll res = INF;
    for (ll i = l; i < r; ++i) {
        for (ll j = l+1; j <= r; ++j) {
            chmin(res, (i*j) % 2019);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin>>n;
  ll s=0;
  ll c=0;
  for(ll i=1;i<=n;i++){
    if((i%3==0&&i%5==0)||i%3==0||i%5==0)
        c=1;
        else
            s+=i;
  }
  cout<<s<<endl;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
    unsigned long long h,sum=0,x=0;
    scanf("%llu",&h);

    for(x=1;h!=0;){
        h/=2;
        sum+=x;
        x*=2;
    }
    
    printf("%llu\n",x-1);

    return 0;
}

Measured memory_bytes: 128
def f(max_weight, baggages)
  memo = {}
  r_v = 0
  dp = lambda{|i, w|
    return memo[[i, w]] if memo[[i, w]]
    memo[[i, w]] = if i >= baggages.size
      0
    elsif w < baggages[i][0]
      dp[i+1, w]
    else
      [dp[i+1, w], baggages[i][1] + dp[i+1, w - baggages[i][0]]].max
    end
  }
  dp[0, max_weight]
  # p memo
  memo[[0, max_weight]]
end

N, W = gets.split.take(2).map(&:to_i)
Baggages = N.times.map{gets.split.take(2).map(&:to_i)}.sort_by{|w, v| [w, -v]}
# p N, W, Baggages
p f(W, Baggages)


Measured memory_bytes: 15352
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N, D = MI()
    X = [0] * N
    Y = [0] * N
    ans = 0

    for i in range(N):
        X[i], Y[i] = MI()

    for i in range(N):
        d = math.sqrt(X[i] ** 2 + Y[i] ** 2)

        if d <= D:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

void solve() {
    int k;
    cin >> k;

    queue<ll> que;
    rep(i, 9) que.push(i+1);
    int cnt = 0;
    while (true) {
        cnt++;
        ll t = que.front();
        que.pop();

        if (cnt == k) {
            cout << t << endl;
            return;
        }

        ll r = t % 10;
        if (r != 0) que.push(t * 10 + (r - 1));
        que.push(t * 10 + r);
        if (r != 9) que.push(t * 10 + r + 1);
    }
}

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


Measured memory_bytes: 5096
/// @file

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

namespace {

bool run(std::istream& is, std::ostream& os);
}  // unnamed namespace

/// @brief エントリポイント
#ifdef _TEST
static int run()
#else
int main()
#endif
{
  try {
    if (run(std::cin, std::cout) == false) {
      std::cerr << "main funciton error.\n";
      return EXIT_FAILURE;
    }
  } catch (const std::exception& e) {
    std::cerr << "catch exception\n";
    std::cerr << e.what() << "\n";
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

namespace {

/// @brief 実行処理
bool run(std::istream& is, std::ostream& os)
{
  const int MAX_DISHES(5);
  std::vector<int> dishes(MAX_DISHES);
  for (auto& v: dishes) is >> v;

  std::vector<int> diffMinues;
  for (const auto& v: dishes) diffMinues.emplace_back(v % 10);
  for (auto& v: diffMinues) v = (10 - v) % 10;
  const auto MAX_DIFF = std::max_element(diffMinues.begin(), diffMinues.end());

  int count(0);
  bool last(false);
  for (int i = 0; i < MAX_DISHES; ++i) {
    if ((last == false) && diffMinues[i] == *MAX_DIFF) {
      count += dishes[i];
      last = true;
      continue;
    }

    count += dishes[i] + diffMinues[i];
  }

  os << count << "\n";

  return true;
}
}  // unnamed namespace


Measured memory_bytes: 256
import numpy as np

n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
side = 0 # alice
for game_time in range(n):
    max_card = max(a)
    max_index = a.index(max_card)
    del a[max_index]
    if side == 0:
        alice += max_card
        side = 1
    else:
        bob += max_card
        side = 0
print(alice-bob)


Measured memory_bytes: 12484
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

long long gcd(long long a, long long b){
    long long c;
    if (a < b) {
        a+=b;
        b=a-b;
        a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}


int main(){
  int n;cin>>n;
  for(int i=0;i<n;i++){
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a < b){
      cout<<"No"<<endl;
      continue;
    }

    if(b > d){
      cout<<"No"<<endl;
      continue;
    }

    if(c >= (b-1)){
      cout<<"Yes"<<endl;
      continue;
    }

    a %= b;

    if(c < a){
      cout<<"No"<<endl;
      continue;
    }


    long long g = gcd(b,d);

    long long tmp = (((c-a)/g)*g+g+a)%b;
    //cout<<c<<" "<<g<<" "<<tmp<<endl;
    if(tmp > c){
      cout<<"No"<<endl;
    }else{
      cout<<"Yes"<<endl;
    }

  }

  return 0;
}


Measured memory_bytes: 256
import numpy as np

h, n = map(int, input().split())
ab = np.array([tuple(map(int, input().split())) for _ in range(n)])

a, b = ab[:, 0], ab[:, 1]
dp = np.zeros(h+1, dtype=np.int)
for i in range(1, h+1):
    dp[i] = np.min(dp[np.maximum(i-a, 0)] + b)

print(dp[h])

Measured memory_bytes: 12512
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
end

N, M = gets.split.map(&:to_i)
ABs = N.times.map{gets.split.map(&:to_i)}
LRs = M.times.map{gets.split.map(&:to_i)}

as, bs = ABs.sort_by(&:first).transpose
as << 10**9 + 1
@bs = ([0] + bs + [0]).each_cons(2).map{|x, y| x^y}
lrs = LRs.map.with_index{|(l, r), i| [as.bsearch_index{|a| a >= l}, as.bsearch_index{|a| a > r}, i + 1]}
@g = lrs.each_with_object(Array.new(N + 1){[]}){|(l, r, i), o| (o[l] << [r, i]; o[r] << [l, i]) unless l == r}
@ans, @d = [], Array.new(N + 1, false)

def dfs(u)
  @d[u] = true
  @g[u].each do |v, i|
    next if @d[v]
    if dfs(v)
      @bs[u] ^= 1
      @bs[v] ^= 1
      @ans << i
    end
  end
  @bs[u] == 1 ? true : false
end

(N + 1).times{|i| dfs(i) unless @d[i]}
puts @bs.inject(:+) > 0 ? -1 : [@ans.size, @ans.sort.join(' ')]

Measured memory_bytes: 209020
#include <iostream>

int main()
{
	int n, d, x;
	std::cin >> n >> d >> x;
	
	d--;
	x += n;
	int a;
	for (int i = 0; i < n; i++) {
		std::cin >> a;
		x += d / a;
	}
	
	std::cout << x << std::endl;
	
	return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int x, y; cin >> x >> y;
	int s[3] = { 300000, 200000, 100000 };
	int ans = 0;
	if (x <= 3)
		ans += s[x - 1];
	if (y <= 3)
		ans += s[y - 1];
	if (x == 1 && y == 1)
		ans += 400000;
	cout << ans;
}

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

typedef long long ll;
const int N = 200005;

int n, d;
int a[N];
ll ans, opt;
vector<pair<ll,int>> vals;

int main() {
	scanf("%d %d", &n, &d);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
	}
	for (int i = 2; i <= n; ++i) {
		ll x = (ll) a[i] + (ll) i * d;
		while (vals.size() && vals.back().first >= x) {
			vals.pop_back();
		}
		vals.push_back(make_pair(x, i));
	}
	int now = 2;
	opt = a[1] - d;
	for (auto p : vals) {
		int nxt = p.second;
		ans += p.first + opt;
		for (int i = now; i < nxt; ++i) {
			ans += a[i] + min(p.first - (ll) i * d, opt + (ll) i * d);
			opt = min(opt, a[i] - (ll) i * d);
		}
		opt = min(opt, a[nxt] - (ll) nxt * d);
		now = nxt + 1;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 6768
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}




int main()
{ 

  IOS;

ll x,y;
cin>>x>>y;
ll tot=0;

if(x==1)tot+=300000;
else if(x==2)tot+=200000;
else if(x==3)tot+=100000;



if(y==1)tot+=300000;
else if(y==2)tot+=200000;
else if(y==3)tot+=100000;

if(x+y==2)tot+=400000;

cout<<tot<<endl;

return 0;
 
}



Measured memory_bytes: 3604
import sys
from heapq import heappush, heappop

n, m, *ab = map(int, sys.stdin.read().split())
ab = sorted(zip(*[iter(ab)] * 2))

def main():
    res = [0] * m
    hq = []
    i = 0
    for j in range(1, m+1):
        while i < n:
            a, b = ab[i]
            if a <= j:
                heappush(hq, -b)
                i += 1
            else:
                break
        if not hq:
            continue
        res[-j] = -heappop(hq)
    
    return sum(res)
        
if __name__ == '__main__':
    ans = main()
    print(ans)

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

using namespace std;

string s,p,tmp;
void solve(){
    cin>>s>>p;
    tmp=s;
    tmp+=p[p.size()-1];
    cout<<(tmp==p?"Yes":"No")<<endl;
}

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

Measured memory_bytes: 3660
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define en '\n'
#define rep(i,n)    for(ll i=0; i<n; i++)
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(1);
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;

int main()
{
    godspeed
    ll n;
    cin>>n;
    if(n)
    cout<<0<<endl;
    else cout<<1<<endl;
    
    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <algorithm>
#include <set>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

typedef long long ll;

const int N_MAX = 200000;

typedef pair<int, int> P;

int N;
int x[N_MAX];
int y[N_MAX];
P p[N_MAX];
int z[N_MAX * 2];
multiset<int> bs;

void erase_one(multiset<int> &st, int v) {
  auto it = st.find(v);
  if (it != st.end()) st.erase(it);
}

void solve() {
  REP(i, N) {
    int zi = min(x[i], y[i]);
    int zx = max(x[i], y[i]);
    p[i] = { zi, zx };
    z[i] = zi;
    z[N + i] = zx;
  }
  sort(p, p + N);
  sort(z, z + N * 2);
  int zx = z[N * 2 - 1];
  int zi = z[0];
  // printf("(1) zx: %d, zi: %d\n", zx, zi);

  int rx = zx, ri = zx, bx = zi, bi = zi;
  REP(i, N) {
    ri = min(ri, p[i].second);
    bx = max(bx, p[i].first);
  }
  ll ans1 = (ll) (rx - ri) * (bx - bi);
  // printf("(2) rx: %d, ri: %d, bx: %d, bi: %d, ans1: %lld\n", rx, ri, bx, bi, ans1);

  rx = zx; ri = zi;
  REP(i, N) bs.insert(p[i].first);
  REP(i, N) {
    int bw = *bs.rbegin() - *bs.begin();
    erase_one(bs, p[i].first);
    bs.insert(p[i].second);
    if (*bs.rbegin() - *bs.begin() > bw) {
      erase_one(bs, p[i].second);
      bs.insert(p[i].first);
    }
  }
  bx = *bs.rbegin(), bi = *bs.begin();
  ll ans2 = (ll) (rx - ri) * (bx - bi);
  // printf("(3) rx: %d, ri: %d, bx: %d, bi: %d, ans2: %lld\n", rx, ri, bx, bi, ans2);

  printf("%lld\n", min(ans1, ans2));
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d%d", x + i, y + i);
}

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


Measured memory_bytes: 14336