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

using namespace std;

int main() {
    int A, B, C, D, flag = 0;
    cin >> A >> B >> C >> D;
    while (A > 0 && C > 0) {
        if (C - B > 0) {
            C -= B;
        } else {
            flag = 2;
            break;
        }
        if (A - D > 0) {
            A -= D;
        } else {
            flag = 1;
            break;
        }
    }
    if (flag == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
package main

import "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)
	if group(x) == group(y) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func group(i int) int {
	for _, a := range []int{1, 3, 5, 7, 8, 10, 12} {
		if a == i {
			return 1
		}
	}
	for _, a := range []int{4, 6, 9, 11} {
		if a == i {
			return 2
		}
	}
	return 3
}


Measured memory_bytes: 512
//resに文字列Sの中にある検索文字列sのすべての一致箇所の開始位置が入る(0_indexed)
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(kbrni,n)cout<<" "<<a[kbrni];cout<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define svecp(v) cout<<#v<<":";each(kbrni,v)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

class KMP
{
public:
    vector<int> table, res;
    string pattern;
    int plen;
    KMP(const string s){
        pattern = s;
        plen = (int)pattern.size();
        table.resize(plen+1);
        table[0] = -1;
        int j = -1;
        rep(i,plen){
            while(j >= 0 && pattern[i] != pattern[j]){
                j = table[j];
            }
            table[i+1] = ++j;
        }
    }
    void search(const string& text){
        int head = 0, j = 0, tlen = (int)text.size();
        while(head + j < tlen){
            if(pattern[j] == text[head + j]) {
                if(++j == plen){
                    res.push_back(head);
                    head = head + j - table[j];
                    j = table[j];
                }
            }else{
                head = head + j - table[j];
                if(j){
                    j = table[j];
                }
            }
        }
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string t,p;
    cin >> t >> p;
    KMP kmp(p);
    kmp.search(t);
    vi& res = kmp.res;
    rep(i,len(res)){
        cout << res[i] << "\n";
    }
}



Measured memory_bytes: 8892
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

ll mod = 1e9+7;

int main() {
    int N, K;   cin >> N >> K;
    
    int c_p = 0, c_n = 0;
    ll *a = new ll[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (a[i] >= 0)
            c_p++;
        else
            c_n++;
    }

    ll ans = 1;

    if (N == K) {
        for (int i = 0; i < N; i++) {
            ans *= a[i];
            ans %= mod;
        }
        ans = (ans + mod) % mod;
        cout << ans << endl;

        return 0;
    }

    if (K % 2 == 1 && c_p == 0) {
        sort(a, a+N, greater<ll>());
        for (int i = 0; i < K; i++) {
            ans *= a[i];
            ans %= mod;
        }
        ans = (ans + mod) % mod;
        cout << ans << endl;
        return 0;
    }

    vector<ll> b, c;
    priority_queue<ll> que_p, que_n;
    for (int i = 0; i < N; i++) {
        if (a[i] >= 0)
            que_p.push(a[i]);
        else 
            que_n.push(-a[i]);
    }

    for (int i = 0; i < K; i++) {
        if (que_p.empty()) {
            c.push_back(que_n.top());
            que_n.pop();
        }
        else if (que_n.empty()) {
            b.push_back(que_p.top());
            que_p.pop();
        }
        else {
            ll p = que_p.top(), n = que_n.top();
            if (p >= n) {
                b.push_back(p);
                que_p.pop();
            }
            else {
                c.push_back(n);
                que_n.pop();
            }
        }
    }

    if (c.size() % 2 == 0) {
        for (int i = 0; (ll)i < (ll)b.size(); i++) {
            ans *= b[i];
            ans %= mod;
        }
        for (int i = 0; (ll)i < (ll)c.size(); i++) {
            ans *= c[i];
            ans %= mod;
        }
        ans = (ans + mod) % mod;
        cout << ans << endl;

        return 0;
    }

    if ((ll)b.size() == (ll)c_p) {
        b.pop_back();
        c.push_back(que_n.top());
    }
    else if ((ll)c.size() == (ll)c_n) {
        c.pop_back();
        b.push_back(que_p.top());
    }
    else {
        int k = b.size(), l = c.size();
        if (k >= 1 && l >= 1) {
            if (b[k-1] * que_p.top() <= c[l-1] * que_n.top()) {
                b.pop_back();
                c.push_back(que_n.top());
            }
            else {
                c.pop_back();
                b.push_back(que_p.top());
            }
        }

        else if (l >= 1) {
            c.pop_back();
                b.push_back(que_p.top());
        }
        else {
            b.pop_back();
                c.push_back(que_n.top());
        }
    }

    for (int i = 0; (ll)i < (ll)b.size(); i++) {
        ans *= b[i];
        ans %= mod;
    }
    for (int i = 0; (ll)i < (ll)c.size(); i++) {
        ans *= c[i];
        ans %= mod;
    }

    ans = (ans + mod) % mod;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9460
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

n = 0

0.upto(a) do |i|
  0.upto(b) do |j|
    0.upto(c) do |k|
      #print "#{i},#{j},#{k}\n"
      n += 1 if i * 500 + j * 100 + k * 50 == x
    end
  end
end

puts n

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,a,n) for(int i=a;i>=n;i-- )
 ll fun(ll a)
 {   if(a<0){return 0;}
     if(a==1){return 1;}
     
     ll ans=2*fun(a/2);
     return ans+1;
 }
int main() {
 ll h;
 cin>>h;
 cout<<fun(h);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int s,w;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s>>w;
	if(w>=s)
		cout<<"unsafe"<<endl;
	else
		cout<<"safe"<<endl;
	return 0;
}


Measured memory_bytes: 3596
N, M = map(int, input().split())
num = [list(map(int, input().split())) for _ in range(M)]
ans = [-1] *N
call = True
for k in range(M):
    if ans[num[k][0] -1] == -1 or ans[num[k][0] -1] == num[k][1]:
        ans[num[k][0] -1] = num[k][1]
    else:
        call = False
        break

if call == True:
    
    if N != 1:
        if ans[0] == 0:
            print(-1)
        else:
            ans = [0 if a == -1 else a for a in ans]
            if ans[0] == 0:
                ans[0] = 1
            print(''.join(map(str,ans)))
    else:
        if ans[0] == -1:
            print(0)
        else:
            print(''.join(map(str,ans)))
else:
    print(-1)

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int MOD = 1e9+7;
const long long INF = 1LL << 60;
const int inf = 1e9;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int h[n];
    rep(i,n)cin>>h[i];
    h[0]--;
    int max_num = h[0];
    for (int i = 1; i < n; i++)
    {
        if(h[i]<max_num){
            cout<<"No"<<endl;
            return 0;
        }
        h[i]--;
        max_num = max(max_num,h[i]);
        //min_h = h[i];
    }
    cout<<"Yes"<<endl;
}

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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N;
ll A[25];
ll B[25];
ll C[25];
ll ans;
int main(){
	cin >> N;
	REP(i,0,N){
		cin >> A[i];
		A[i]--;
	}

	REP(i,0,N){
		cin >> B[i];
		ans += B[i];
	}

	REP(i,0,N-1){
		cin >> C[i];
	}

	REP(i,0,N-1){
		if(A[i]==A[i+1]-1){
			ans += C[A[i]];
		}
	}

	p(ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
ll mod = 1e9 + 7;
//const double pi = acos(-1.0);
/*
ll kmp(string x)
{
    ll n= x.length();
    //cout<<x<<endl;
    vector<ll> lcp(x.length(), 0);
    for(ll i=1;i<n;i++)
    {
        ll j=lcp[i-1];
        while(j>0 && x[j]!=x[i])
            j=lcp[j-1];
        if(x[i]==x[j])
            j++;
        lcp[i]=j;
    }
    return lcp[n-1];
}

int N = 1000002;
int ar[100002];
void sieve()
{
    for(int i=1;i<=N;i++)
        ar[i] = 1;
    ar[0] = 0;
    for(int i=2;i*i<=N;i++)
    {
        if(ar[i] && i*i<=N)
        {
            for(int j = i*i; j<=N;j+=i)
                ar[j] = 0;
        }
    }
}

ll modex(ll a,ll b){
    if(b<=0){
        return 1;
    }
    if(b%2==0)
    {
        ll x = modex(a, b/2);
        return ((x*x)%mod);
    }
    else
        return ((a%mod * modex(a, b-1))%mod);
}

ll c[1010][1010];

ll combina(ll i, ll j){
        for (int i=0;i<=1005;i++)
        for (int j=0;j<=i;j++)
        {
            if (j==i||j==0)
                c[i][j]=1;
            else
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            c[i][j]%=mod;
        }
        return c[i][j];
}
void find_fac(int x){
    vector<ll> di;
    for(ll i = 2; i*i <= x; i++)
    {
        if(x%i==0){
            di.push_back(i);
            while(x%i==0)
                x/=i;
        }
    }
    if(x > 1)
        di.push_back(x);
}
*/


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)
        cin>>a[i];
    vector<ll> pr(n);
    pr[n-1] = a[n-1];
    for(ll i=n-2;i>=0;i--){
        pr[i] = (pr[i+1] + a[i])%mod;
    }
    ll an = 0;
    for(ll i=0;i<n-1;i++){
        ll x = (a[i] * pr[i+1])%mod;
        an = ( an + x)%mod;
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 6344
A,B,C,D = parse.(split(readline()))

C_count = div(B,C) - cld(A,C) + 1
D_count = div(B,D) - cld(A,D) + 1
DC = lcm(D,C)
DC_count = div(B,DC) - cld(A,DC) + 1

println(B - A - (C_count + D_count - DC_count) + 1)

Measured memory_bytes: 174176
//
// main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
	ll N;
	cin >> N;
	vector<ll> ts(N);
	rep(i,0,N) {
		cin >> ts[i];
	}
	vector<ll> ts_sums(N+1);
	rep(i,1,N+1) {
		ts_sums[i] = ts_sums[i-1] + ts[i-1];
	}
	vector<ll> vs(N);
	rep(i,0,N) {
		cin >> vs[i];
	}
	vector<ll> max_speed(N+1, numeric_limits<ll>::max());
	max_speed[0] = 0;
	max_speed[N] = 0;
	rep(i,0,N) {
		max_speed[i] = min(max_speed[i], vs[i]);
		max_speed[i+1] = min(max_speed[i+1], vs[i]);
	}
	rep(i,0,N+1) {
		rep(j,0,N+1) {
			max_speed[j] = min(max_speed[j],
							   max_speed[i] + abs(ts_sums[i]-ts_sums[j]));
		}
	}
	/*
	rep(i,0,N+1) {
		cout << "max_speed[" << i << "] = " << max_speed[i] << endl;
	}
	*/
	double ans = 0;
	rep(i,0,N) {
		double ans_loc = 0;
		double x = (-max_speed[i] + max_speed[i+1] + ts[i]) / 2.0;
		double y = (max_speed[i] + max_speed[i+1] + ts[i]) / 2.0;
		if (y < vs[i]) {
			ans_loc += x * (max_speed[i] + y) / 2.0;
			ans_loc += (ts[i] - x) * (max_speed[i+1] + y) / 2.0;
		} else {
			double x0 = vs[i] - max_speed[i];
			double x1 = -vs[i] + max_speed[i+1] + ts[i];
			ans_loc += x0 * (max_speed[i] + vs[i]) / 2.0;
			ans_loc += (x1 - x0) * vs[i];
			ans_loc += (ts[i] - x1) * (vs[i] + max_speed[i+1]) / 2.0;
		}
		ans += ans_loc;
	}
	cout << fixed << setprecision(10) << ans << endl;
}


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

namespace AtCorder
{
	public class Program
	{

		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			var st = new Tuple<string, int>[n];
			for (int i = 0; i < n; i++) {
				string s = cin.Next();
				int t = cin.Int();
				st[i] = new Tuple<string, int>(s, t);
			}

			string x = cin.Next();
			bool sleep = false;
			int ans = 0;
			for (int i = 0; i < n; i++) {
				if (sleep) {
					ans += st[i].Item2;
				} else {
					if (st[i].Item1 == x) {
						sleep = true;
					}
				}
			}

			Console.WriteLine(ans);
		}
	}


	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin >> n;
	deque<ll> ans;
	if (n % 2 == 0) {
		for (int i = 0; i < n; i++) {
			ll t;
			cin >> t;
			if ((i + 1)% 2 == 0) {
				ans.push_front(t);
			}
			else {
				ans.push_back(t);
			}
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			ll t;
			cin >> t;
			if ((i+1) % 2 == 0) {
				ans.push_back(t);
			}
			else {
				ans.push_front(t);
			}
		}
	}
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 3840
N = int(input())
h = list(map(int, input().split()))

dp = [0,abs(h[1]-h[0])]
for i in range(2,N):
    a = dp[i-2] + abs(h[i] - h[i-2])
    b = dp[i-1] + abs(h[i] - h[i-1])
    dp.append(min(a,b))

ans = dp[N-1]
print(ans)

Measured memory_bytes: 13980
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  int cnt = 0;
  for(int i = 0; i < n; i++){
    int x = v[i];
    while(x % 2 == 0){
      x /= 2;
      cnt++;
    }
  }
  cout << cnt << endl;
  return;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

int main(){
    int A,B,ans = 0;
    cin >> A >> B;

    if(A > B){
        ans += A;
        A--;
    }else{
        ans += B;
        B--;
    }

    if(A > B){
        ans += A;
    }else{
        ans += B;
    }

    cout << ans << endl;
}

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

const int MAXN = 1e5 + 10;
const long long MOD = 1e9 + 7;

int N;
string S;
long long C[26];
long long I[MAXN];
long long val = 1;
int main(void){
    cin >> N >> S;
    long long ans = 0;

    I[1] = 1;
    for(int i = 2 ; i < MAXN ; i++) I[i] = MOD - I[MOD % i] * (MOD / i) % MOD;
    for(int i = 0 ; i < S.length() ; i++) {
        long long &x= C[S[i] - 'a'];
        ans += val * I[x + 1]; ans %= MOD;
        val *= I[x + 1]; val %= MOD;  
        x += 1;    
        val *= (x + 1);   val %= MOD;
        //cout << val << '\n';
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1280
#include <cstdio>

template<class T>void fr(T &a) {
    T w=0,s=1;char c=getchar();
    while(c<'0'||c>'9') {if(c=='-')s=-1;c=getchar();}
    while(c>='0'&&c<='9') w=w*10+c-'0',c=getchar();
    a=w*s;
}
template<class T>T fr() {T a;fr(a);return a;}
#define R() fr<int>()

int main() {
    int x=R();
    for(int i=1;i<=9;i++)
        for(int j=1;j<=9;j++)
            if(i*j==x)return !printf("Yes\n");
    return !printf("No\n");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int n;
    cin >> n;
    int sz = 0, res = 0;
    fore(i, 0, n) {
        int a, b;
        cin >> a >> b;
        if (a == b) {
            sz++;
        }
        else {
            sz = 0;
        }
        res = max(res, sz);
    }
    if (res >= 3) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}
// Dinosaurs are cool!

Measured memory_bytes: 3644
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;

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

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, d, a; cin >> n >> d >> a;
  vector<pii> p(n);
  for(int i=0; i<n; i++) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  for(int i=0; i<n; i++) {
    p[i].second = (p[i].second+a-1) / a;
  }

  int j = 0;
  ll cur = 0;
  queue<pii> q;
  ll res = 0;
  for(int i=0; i<n; i++) {
    while(j < n && p[i].first + 2*d >= p[j].first) j++;
    while(q.size() && q.front().first <= i) {
      cur += q.front().second;
      q.pop();
    }

    ll t = max(p[i].second + cur, 0LL);
    p[i].second -= t;
    cur -= t;
    res += t;
    q.push({j, t});
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3456
function main(input) {
  const [a, v] = input[0].trim().split(" ").map(i => parseInt(i));
  const [b, w] = input[1].trim().split(" ").map(i => parseInt(i));
  const t = parseInt(input[2]);

  const result = ((v*t) >= ((w*t)+Math.abs(b-a)))
  console.log(result?"YES":"NO");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 29624
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll int64_t
#define ull uint64_t
using namespace std;
using namespace std;

ll max(ll a, ll b)
{
	if(a>b)
	 return a;
	return b;
}

ll max1(ll a, ll b, ll  c,ll d)
{
	return max(a,max(b,max(c,d)));
}
int main()
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("err.txt","w",stderr);
  #endif
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max1((a*c),(b*d),(a*d),(b*c))<<endl;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define N 2000010
#define pb emplace_back
#define mr make_pair
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
struct Info{int x,y,z;}st[N],g[N];
int a[N],b[N],m,n,k,ns,ng;
char ch;
int main(){
	read(n);read(m);read(k);
	for (int i=n-1;i>=0;i--){ch=getchar();while (ch!='1'&&ch!='0')ch=getchar();a[i]=ch-'0';}
	for (int i=m-1;i>=0;i--){ch=getchar();while (ch!='1'&&ch!='0')ch=getchar();b[i]=ch-'0';}
	n=max(m,n);
	for (int i=n;i>=0;i--){
		if (a[i]||b[i]){
			if (a[i]&&b[i]){
				int n1=1,n2=1,n3=k-1,n4=i+1;
				while (1){
					if(ns==0||st[ns].z!=n4){
						if (n1==1&&n2==1){
							if (ns==0||st[ns].z>n4+n3){st[++ns]=(Info){n1,n2,n4+n3};break;}
							else{n3-=st[ns].z-n4;n4=st[ns].z;}
						}else{st[++ns]=(Info){n1,n2,n4};break;}
					}else{
						n1+=st[ns].x;n2+=st[ns].y;ns--;
						if (n1==2&&n2==0){n4++;n1=1;}
						if (n1==1&&n2==1){if (n3==0){st[++ns]=(Info){1,1,n4};break;}else n3--,n4++;}
						if (n1==2&&n2==1){g[++ng]=(Info){0,1,n4};n1=1;n2=0;n4++;}
						if (n1==0&&n2==2){n2=1;n4++;}
						if (n1==1&&n2==2){g[++ng]=(Info){1,0,n4};n1=0;n2=1;n4++;}
					}
				}
				for (int i=ng;i>=1;i--)st[++ns]=g[i];ng=0;
			}else st[++ns]=(Info){a[i],b[i],i};
		}
	}
	memset(a,0,sizeof(a));memset(b,0,sizeof(b));
	for (int i=1;i<=ns;i++)a[st[i].z]=st[i].x,b[st[i].z]=st[i].y;
	n+=k;m=n;
	while (a[n]==0)n--;while (b[m]==0)m--;
	for (int i=n;i>=0;i--)putchar(a[i]+'0');puts("");
	for (int i=m;i>=0;i--)putchar(b[i]+'0');puts("");
	return 0;
}

Measured memory_bytes: 30720
#!/usr/bin/env ruby -n
BEGIN{
  is_prime = [false, false] + Array.new(999999, true)
  is_prime.each.with_index do |p, i|
    next unless p
    ((i*i)...is_prime.size).step(i).each do |j|
      is_prime[j] = false
    end
  end
}
p is_prime.take($_.to_i+1).select{|a|a}.size

Measured memory_bytes: 21560
import fractions
a, b, c, d = map(int, input().split())
cCan = b//c-(a-1)//c
dCan = b//d-(a-1)//d
cdSK = c*d//fractions.gcd(c, d)
cdCan = b//cdSK-(a-1)//cdSK
print(int(b-(a-1)-cCan-dCan+cdCan))

Measured memory_bytes: 5344
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self._size = [1 for _ in range(n)]
        self._edges = 0

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self._size[y] += self._size[x]
            self._edges += 1
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self._size[x] += self._size[y]
            self._edges += 1
    
    def size(self, x):
        x = self.find(x)
        return self._size[x]
    
    def trees(self):
        return self.n - self._edges

    def same(self, x, y):
        return self.find(x) == self.find(y)

n = ni()
s = nsn(n)

def floyd_warshall(n, dist):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])

def ok(n, dist):
    uf = UnionFind(2 * n)
    for i in range(n):
        for j in range(n):
            if s[i][j] == '1':
                uf.unite(i, j + n)
                uf.unite(i + n, j)
    for i in range(n):
        if uf.same(i, i + n):
            return False
    return True

dist = [[inf] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if s[i][j] == '1':
            dist[i][j] = 1
    dist[i][i] = 0

floyd_warshall(n, dist)

if ok(n, dist):
    ans = 0
    for i in range(n):
        for j in range(n):
            if dist[i][j] != inf:
                ans = max(dist[i][j], ans)
    print(ans + 1)
else:
    print(-1)

Measured memory_bytes: 44396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sum1, sum2, ans1, ans2, x;
int n;
int main()
{
    sum1 = sum2 = ans1 = ans2;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &x);
        sum1 += x;
        sum2 += x;
        if (i & 1) {
            if (sum1 >= 0) {
                ans1 += sum1 + 1;
                sum1 = -1;
            }
            if (sum2 <= 0) {
                ans2 += 1 - sum2;
                sum2 = 1;
            }
        }
        else {
            if (sum1 <= 0) {
                ans1 += 1 - sum1;
                sum1 = 1;
            }
            if (sum2 >= 0) {
                ans2 += sum2 + 1;
                sum2 = -1;
            }
        }
    }
    printf("%lld\n", min(ans1, ans2));
    return 0;
}


Measured memory_bytes: 256
s=str(input())

s_1=int(s[0]+s[1])
s_2=int(s[2]+s[3])

#print(s_1,s_2)

if (s_1>=1) & (s_1<=12) & (s_2>=1) & (s_2<=12):
	print("AMBIGUOUS")
	
elif ((s_1>=1) & (s_1<=12)) & ((s_2==0) | (s_2>=13)):
	print("MMYY")

elif ((s_1==0) | (s_1>=13)) & ((s_2>=1) & (s_2<=12)):
	print("YYMM")
	
else:
	print("NA")

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

using namespace std;

int main(void){
  long long n, k, i;
  cin >> n >> k;
  long long h[n], tmp;
  for(i = 0; n > i; i++){
    cin >> tmp;
    h[i] = tmp;
  }
  sort(h, h+n);
  long long ans = 0;
  for(i = 0; n-k > i; i++){
    ans += h[i];
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <array>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;

void Solve() {
	UL N; cin >> N;
	UL A[200000]; rep(i, N) cin >> A[i];
	UL p = 1;
	rep(i, N) {
		if (A[i] == p) p++;
	}
	if (p == 1) cout << -1;
	else cout << N - (p - 1) << endl;
}
int main() { Solve(); return 0; }


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <cassert>
using namespace std;
using ll = int64_t;

// For row query R: find first column queried so far. That was before any higher row queries.
// Sorting by low/high and by time.
//
// Find earliest row query < R = ER
// Find first column query that occurred earlier than ER

// given points (x,y)
// Support queries: give me smallest y s.t. exists point (x,y) with x<X
// store them sorted by X descending by Y.
// Query: lookup first thing in map <X. Return corresponding y.
//
// Add: If thing to my left is smaller, delete me.
// While thing to my right is bigger, delete it.
struct Query {
  Query(ll n_) : n(n_) {}
  void add(ll x, ll y) {
    assert(M.count(x)==0);
    if(M.size() > 0) {
      auto it = M.lower_bound(x);
      if(it != M.begin()) {
        it--;
        if(it->second < y) { return; } // I am worse
        it++;
      }
      while(it!=M.end() && it->second > y) {
        it = M.erase(it);
      }
    }
    M.insert({x, y});
  }
  ll query(ll X) {
    auto it = M.lower_bound(X);
    if(it==M.begin()) {
      return n;
    } else {
      it--;
      return it->second;
    }
  }
  map<ll,ll> M;
  ll n;
};

struct Slow {
   Slow(ll n) { 
     ans = (n-2)*(n-2);
     G = vector<vector<int>>(n-2, vector<int>(n-2, true));
   }
   void query(ll typ, ll idx) {
     idx-=2;
     assert(0<=idx && idx<G.size());
     if(typ==1) { // col
       for(ll r=0; r<G.size(); r++) {
         if(G[r][idx]) {
           G[r][idx] = false;
           ans--;
         } else {
           break;
         }
       }
     } else {
       for(ll c=0; c<G.size(); c++) {
         if(G[idx][c]) {
           G[idx][c] = false;
           ans--;
         } else {
           break;
         }
       }
     }
   }
   vector<vector<int>> G;
   ll ans;
};

int main() {
  ll n,q;
  cin >> n >> q;
  ll ans = (n-2)*(n-2);
  //Slow slow(n);
  Query EC(5*n); // pos -> earliest column < pos
  Query FC(n); // time -> first column earlier than time
  Query ER(5*n);
  Query FR(n);
  /*EC.add(n, 0);
  FC.add(0, n);
  ER.add(n, 0);
  FR.add(0, n);*/
  for(ll i=1; i<=q; i++) {
    ll typ,pos;
    cin >> typ >> pos;
    ll removed = 0;
    if(typ == 1) { // col
      ll ec = EC.query(pos);
      ll fr = FR.query(ec);
      removed = fr-2;
      EC.add(pos, i);
      FC.add(i, pos);
    } else {
      ll er = ER.query(pos);
      ll fc = FC.query(er);
      //cerr << "pos=" << pos << " er=" << er << " fc=" << fc << endl;
      removed = fc-2;
      ER.add(pos, i);
      FR.add(i, pos);
    }
    ans -= removed;
    //slow.query(typ, pos);
    //cerr << "i=" << i << " typ=" << typ << " pos=" << pos << " removed=" << removed << " ans=" << ans << " slow.ans=" << slow.ans << endl;
    //assert(slow.ans == ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 27956
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Random;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;

public class Main {

	class P {
		double x, y;

		P(double x_, double y_) {
			x = x_;
			y = y_;
		}

		P add(P p) {
			return new P(x + p.x, y + p.y);
		}

		P sub(P p) {
			return new P(x - p.x, y - p.y);
		}

		P mul(double v) {
			return new P(x * v, y * v);
		}

		P div(double v) {
			return new P(x / v, y / v);
		}

		double dot(P p) {
			return x * p.x + y * p.y;
		}

		double det(P p) {
			return x * p.y - y * p.x;
		}

		double abs2() {
			return x * x + y * y;
		}

		double abs() {
			return Math.sqrt(abs2());
		}

		P norm() {
			return div(abs());
		}

		P rot90() {
			return new P(-y, x);
		}

		P proj(P src, P dst) {
			P p_sd = dst.sub(src).norm();
			return src.add(p_sd.mul(sub(src).dot(p_sd)));
		}

		P reflect(P src, P dst) {
			P middle = proj(src, dst);
			return add(middle.sub(this).mul(2));
		}
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		P src = new P(sc.nextDouble(), sc.nextDouble());
		P dst = new P(sc.nextDouble(), sc.nextDouble());
		int q = sc.nextInt();
		while (q-- > 0) {
			P p = new P(sc.nextDouble(), sc.nextDouble());
			P x = p.reflect(src, dst);
			System.out.println(String.format("%.20f %.20f", x.x, x.y));
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 44996
import qualified Data.Vector.Unboxed as VU
import Data.List (tails)

main :: IO ()
main = do
  ds <- map unsafeCharToInt <$> getLine :: IO [Int]
  let
    tailRems :: [Int]
    tailRems = map snd . scanr step (10, 0) $ ds
      where
        step :: Int -> (Int, Int) -> (Int, Int)
        step d (l, d') = (l * 10 `mod` 2019, (d * l + d') `mod` 2019)
    cs :: VU.Vector Int
    cs = count tailRems
  print . VU.sum . VU.map (\k -> k * pred k `div` 2) $ cs

count :: [Int] -> VU.Vector Int
count = VU.accum (+) (VU.replicate 2019 0) . map (flip (,) 1)

unsafeCharToInt :: Char -> Int
unsafeCharToInt c = fromEnum c - 48

readInt :: String -> Int
readInt "" = 0
readInt s = read s


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

int main() {
	int N,s;
	string ans = "No";
	cin >> N;
	for (int i1 = 0; i1 < 9; i1++) {
		int k1 = i1 + 1;
		for (int i2 = 0; i2 < 9; i2++) {
			int k2 = i2 + 1;
			s = k1 * k2;
			if (s == N) {
				ans = "Yes";
			}
		}
	}
cout << ans<< endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String gg[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        if((k*500) >= x){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

int main(){
    const long long int M = 1000000007;

    long long int N, K;
    cin >> N >> K;

    vector<long long int> A(N);
    for(long long int i = 0; i < N; ++i){
        cin >> A[i];
    }

    vector<long long int> cnt(2001, 0);
    for(long long int i = 1; i < N; ++i){
        for(long long int j = 0; j < i; ++j){
            if(A[i] > A[j]){
                ++cnt[i];
            }
        }
    }

    long long int ans = 0;

    long long int k;
    if (K & 1){
        k = (K+1)/2;
        k *= K;
        k %= M;
    }else{
        k = K/2;
        k *= K+1;
        k %= M;
    }

    for(long long int i = 0; i < N; ++i){
        long long int x = 0;
        for(long long int j = i+1; j < N; ++j){
            if(A[i] > A[j]){
                ++x;
                x %= M;
            }
        }
        x *= k;
        x %= M;

        ans += x;
        ans %= M;

        x = cnt[i];
        x *= ((K*(K-1))/2)%M;
        x %= M;
        // x *= k;
        // x %= M;

        // long long int a = K*cnt[A[i]];
        // a %= M;
        // x -= a;
        // if(x <= 0){
        //     x += M;
        // }
        // x %= M;

        ans += x;
        ans %= M;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <tuple>

using namespace std;
mt19937_64 rng(58);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;
    cin >> s;
    if (s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3096
#include <stdio.h>
#include <math.h>

int main () {
    int i,num,sum = 0,con = 0,point[1001] = {0};
    double ave,bef_var,var,sta_dev,ans[1001] = {0.0};

    
    while (1) { //calculate standard deviations
        scanf ("%d",&num); //how many people
        if (num == 0) {
            break;
        }
        
        sum = 0; //initialize at every loop
        
        for (i = 0;i < num;i ++) {
            scanf ("%d",&point[i]);
            sum += point[i];
        }
        ave = (double) sum / num;
        
        bef_var = 0.0;
        
        for (i = 0;i < num;i ++) {
            bef_var += (point[i] - ave) * (point[i] - ave);
            //before variance
        }
        var = bef_var / num;
        sta_dev = sqrt (var);
        
        ans[con] = sta_dev;
        con ++;
    }
    
    for (i = 0;i < con;i ++) {
        printf ("%f\n",ans[i]);
    }
    return 0;
}



Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
 
main(){
 
 
int n,k;
cin>>n>>k;
 vector <long long int > h(n);
 for(int i=0;i<n;i++)cin>>h[i];
  vector <long long  int > dp(n,1e10);
  dp[0]=0;
  
  for(int i=0;i<n-1;i++){
	  for(int j=1;j<=k;j++)
 
	  {if((i+j)<n){
    
    dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
		      }
    }   
  }
  cout<<dp[n-1];

}


Measured memory_bytes: 1792
"use strict";
const s = require("fs").readFileSync("/dev/stdin", "utf8");
const n = parseInt(s.split("\n")[0].split(" ")[0], 10);
let x = parseInt(s.split("\n")[0].split(" ")[1], 10);
let a = s.split("\n")[1].split(" ").map(e => parseInt(e, 10)).sort((a, b) => a - b);
let cnt = 0;
for (let i = 0; i < n; i++) {
  if (x >= a[i]) {
    x -= a[i];
    cnt++;
  } else {
    break;
  }
}
if (x > 0 && cnt >= n) {
  cnt--;
}
console.log(cnt);


Measured memory_bytes: 21064
N = int(input())
b = []

def seve(a):
    a = int(a)
    if a > N:
        return len(b)
    else:
        a = str(a)
        if a.count('3') >= 1 and a.count('5') >= 1 and a.count('7') >= 1:
            b.append(a)
        return seve(a+'3') + seve(a+'5') + seve(a+'7')

seve('7')
seve('5')
seve('3')
print(len(b))


Measured memory_bytes: 4816
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    int H, A, D, S; cin >> H >> A >> D >> S;

    vector< tuple<int, int, int, int> > enemies;
    for(int i=0; i<N; i++) {
        int h, a, d, s; cin >> h >> a >> d >> s;

        // 主人公が攻撃しても意味ない
        if(A - d <= 0) {
            // 敵がつよい
            if(a - D > 0) {
                cout << -1 << endl;
                return 0;
            }
            // 戦闘不能判定に関係ないからいらなさそう
            else {
                continue;
            }
        }
        // 敵が攻撃しても意味ない
        if(a - D <= 0) {
            continue;
        }
        
        enemies.emplace_back(h, a, d, s);
    }

    sort(enemies.begin(), enemies.end(), [&](auto x, auto y) {
            int xh, xa, xd, xs; tie(xh, xa, xd, xs) = x;
            int yh, ya, yd, ys; tie(yh, ya, yd, ys) = y;

            // 何ターンで死ぬか
            int xdam = A - xd; int xturn = (xh + xdam - 1) / xdam;
            int ydam = A - yd; int yturn = (yh + ydam - 1) / ydam;

            // 敵の攻撃はいくつ？
            int xinj = xa - D, yinj = ya - D;

            // 何回攻撃するか (x -> y)
            int xatkl = (xs > S ? xturn : xturn - 1);
            int yatkl = (ys > S ? xturn + yturn : xturn + yturn - 1);

            // 何回攻撃するか (y -> x)
            int yatkr = (ys > S ? yturn : yturn - 1);
            int xatkr = (xs > S ? xturn + yturn : xturn + yturn - 1);

            int suml = xinj * xatkl + yinj * yatkl;
            int sumr = xinj * xatkr + yinj * yatkr;
            return suml < sumr;
        });

    int turn_sum = 0, mi = 0;
    for(auto e : enemies) {
        int h, a, d, s; tie(h, a, d, s) = e;
        int dam = A - d, turn = (h + dam - 1) / dam;
        int inj = a - D;

        // fprintf(stderr, "dam = %lld, turn = %lld, inj = %lld\n", dam, turn, inj);
        turn_sum += turn;
        int atk = (s > S ? turn_sum : turn_sum - 1);

        mi += atk * inj;
        if(mi >= H) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << mi << endl;
    return 0;
}



Measured memory_bytes: 4760
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr ll R=5e4+69, INF=5e18+6969;

int qq;
ll A,B,C,D;
map <ll,ll> F;

ll f(ll x)
{
	if(F.find(x)!=F.end()) return F[x];
	vector <ll> mul {2,3,5}, cost{A,B,C};
	ll wyn = INF;
	if(INF/D > x) wyn = x*D;
	for(int i=0;i<3;++i)
	{
		if(x%mul[i]==0)
		{
			wyn = min(wyn, cost[i] + f(x/mul[i]));
		}
		else
		{
			ll down = x/mul[i] * mul[i];
			wyn = min(wyn, D*(x - down) + cost[i] + f(x/mul[i]));
			ll up = down + mul[i];
			wyn = min(wyn, D*(up-x) + cost[i] + f(x/mul[i] + 1));
		}
	}
	F[x]=wyn;
	return wyn;
}

int main()
{
	scanf("%d", &qq);
	while(qq--)
	{
		ll n;
		scanf("%lld", &n);
		scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
		F.clear();
		F[0]=0;
		F[1]=D;
		printf("%lld\n", f(n));
	}
	return 0;
}


Measured memory_bytes: 4500
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main(){

    long long n, m;
    cin >> n >> m;
    
    if(n >= 2 && m >= 2){
        cout << (n - 2) * (m -2) << endl;
    }
    else if( n == 2 || m == 2){
        cout << 0 << endl;
    }
    else if(n == 1 && m == 1){
        cout << 1 << endl;
    }
    else{
        cout << max(n, m) - 2 << endl;
    }

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;
int inf=1<<30;
long long llinf=1ll<<60;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
int main(void){
    int n,s[100],ans,i;
    while(1){
        n=in();
        if(!n)break;
        rep(i,n)s[i]=in();
        sort(s,n);
        ans=0;
        for(i=1;i<n-1;i++)ans+=s[i];
        print(ans/(n-2));
    }
    return 0;
}


Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int x,n;cin>>x>>n;
    set <int> s;for(int i=0;i<=200;i++) s.insert(i);
    for(int i=0;i<n;i++)
    {
        int z;cin>>z;
        s.erase(s.find(z));
    }
    int mnd=111111,ans=-1;
    for(int z : s)
    {
        if((int)abs(z-x)<mnd)
        {
            mnd=abs(z-x);
            ans=z;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

vector<char> Button[9];

void hoge(){

    Button[0].push_back('.');
    Button[0].push_back(',');
    Button[0].push_back('!');
    Button[0].push_back('?');
    Button[0].push_back(' ');
    string s="abcdefghijklmnopqrstuvwxyz";
    int k=0;
    for(int i=1; i<=8; i++){
        for(int j=0; j<(i==6||i==8? 4: 3); j++){
            Button[i].push_back(s[k]);
            k++;
        }
    }
}

int main(){

    hoge();

    int n;
    cin>> n;
    for(int i=0; i<n; i++){
        string s;
        cin>> s;
        char p='0';
        int k=0;
        for(int j=0; j<s.size(); j++){
            if(s[j]=='0'){
                if(p!='0'){
                    int mo=(p=='1'? 5: (p=='7'||p=='9'? 4: 3));
                    cout<< Button[p-'0'-1][(k-1+mo)%mo];
                }
                k=0;
            }else{
                k++;
            }
            p=s[j];
        }
        cout<< endl;
    }

    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using i64=long long int;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = b;

    ans += min(c, a+b+1);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
using namespace std;
#define pi M_PI

int main(){
    string a, b;
    cin >> a >> b;

    if(a.at(0) == b.at(2) && a.at(1) == b.at(1) && a.at(2) == b.at(0)){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int       long long
#define w(x)      int x;cin >> x;while (x--)
#define rep(d,a,n)  for(int d=a;d<=n;d++) 
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define oj  freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
const int inf=1e18;
int fun(int arr[],int n=5){
    rep(i,0,n-1){
        if(arr[i]==0){
            return i+1;
        }
    }
    return -1;
}
int32_t main()
{
    fast_io;
    int arr[5];
    rep(i,0,4){
        cin>>arr[i];
    }
    int ans=fun(arr);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3592