akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k=-1;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<n;i++){
    if(a[i]+1<k){
      cout << "No" << endl;
      return 0;
    }
    k=max(k,a[i]);
  }
  cout << "Yes" << endl;
  return 0;
}
    

Measured memory_bytes: 4020
#include <cstdio>
#include <cstring>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>

const int N = 100000 + 10;

int n, a[N], b[N], c[N];

inline int f(int x) { return std::lower_bound(c, c + n + 1, x) - c; }

int res, match[N];
int dist[N];

void bfs() {
  static int sum[N];
  static std::vector<std::pair<int, int>> adj[N];
  for (int i = 1; i <= n; ++i) {
    int j = match[i];
    if (j >= a[i]) {
      ++sum[a[i]];
      adj[b[i]].emplace_back(a[i], -1);
    } else {
      ++sum[b[i]];
      adj[a[i]].emplace_back(b[i], 1);
    }
    --sum[j];
  }
  for (int i = 1; i <= n; ++i) sum[i] += sum[i - 1];
  for (int i = 0; i < n; ++i) if (sum[i]) adj[i].emplace_back(i + 1, 0);
  for (int i = 0; i < n; ++i) adj[i + 1].emplace_back(i, 0);
  memset(dist, -0x3f, sizeof dist);
  std::queue<int> q;
  static bool flag[N];
  dist[0] = 0;
  for (q.push(0); !q.empty(); q.pop()) {
    int a = q.front();
    flag[a] = false;
    for (auto it : adj[a]) {
      int b = it.first, c = it.second;
      if (dist[a] + c > dist[b]) {
        dist[b] = dist[a] + c;
        if (!flag[b]) q.push(b), flag[b] = true;
      }
    }
  }
}

int init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i], &b[i]);
  for (int i = 0; i <= n; ++i) scanf("%d", &c[i]);
  std::sort(c, c + n + 1);
  for (int i = 1; i <= n; ++i) a[i] = f(a[i]), b[i] = f(b[i]);
  static std::pair<int, int> info[N];
  for (int i = 1; i <= n; ++i) info[i] = {std::min(a[i], b[i]), i};
  std::sort(info + 1, info + n + 1);
  std::set<std::pair<int, int>> pool;
  res = 0;
  for (int i = 1, j = 1; i <= n; ++i) {
    for (; j <= n && info[j].first <= i; ++j) pool.emplace(a[info[j].second], info[j].second);
    if (pool.empty()) {
      res = -1;
      break;
    }
    auto x = *pool.begin();
    if (x.first > i) x = *pool.rbegin(); else ++res;
    match[x.second] = i;
    pool.erase(x);
  }
  if (res >= 0) bfs();
  int q;
  scanf("%d", &q);
  return q;
}

int main() {
  for (int q = init(); q--;) {
    int d, e;
    scanf("%d%d", &d, &e);
    if (res < 0) puts("-1"); else printf("%d\n", std::max(-1, res + std::max(dist[f(d)] + 1, dist[f(e)])));
  }
  return 0;
}


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

const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b(n);
  rep(i, n) cin >> b[i];
  vector<int> c(n);
  rep(i, n) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  ll ans = 0;
  rep(i, n){
    auto a_tmp = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    auto c_tmp = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
    ans += a_tmp * (n-c_tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4552
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

const int MAX_N = 200100;
int N; ll K;
ll A[MAX_N];
const ll INF = (ll)1e18 + 1LL;

int b_search(ll key, ll X, bool right_true) {
    int ng = right_true ? N : -1;
    int ok = right_true ? -1 : N;

    while(abs(ok - ng) > 1) {
        int mid = (ok + ng)/2;
        if(key*A[mid] < X) ok = mid;
        else ng = mid;
    }
    return ok;
}

ll order_ascending(ll X) { // 積がX未満になるのが何個あるか
    ll res = 0;
    for(int i = 0; i < N; ++i) {
        if(A[i] >= 0){
            int candidate = b_search(A[i], X, true);
            res += (ll)candidate + 1;
        } else {
            int candidate = b_search(A[i], X, false);
            res += (ll)N - candidate;
        }
        if(A[i]*A[i] < X) --res;
    }
    return res/2LL;
}

int main()
{
    scanf("%d %lld", &N, &K);
    for(int i = 0; i < N; ++i) scanf("%lld", &A[i]);
    sort(A, A + N);

    ll low = -INF, high = INF;
    while(abs(high - low) > 1) {
        ll mid = (low + high)/2;
        if(order_ascending(mid) < K) low = mid;
        else high = mid;
    }
    printf("%lld\n", low);
    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vr vector
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()

ll pow(ll x,ll n,ll p,ll res)
{
    if(n==0)
        return res%p;
    if(n&1)
    {
        res=((res%p)*(x%p))%p;
        n--;
    }
    x=((x%p)*(x%p))%p;
    n>>=1;
    return pow(x,n,p,res);
}





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

//ll t;
//cin>>t;
//while(t--)
{



 int n,m,h[200001],ma[200001];
 cin>>n>>m;
 for(int i=1;i<=n;i++){
 cin>>h[i];
 ma[i]=0;
 }
 for(int i=0;i<m;i++){
 int a,b;
 cin>>a>>b;
 ma[a]=max(ma[a],h[b]);
ma[b]=max(ma[b],h[a]);
 }
int ans=0;
 for(int i=1;i<=n;i++){
 ans+=h[i]>ma[i];
 }
 cout<<ans<<endl;
 }


    return 0;
}





Measured memory_bytes: 4448
let () = Scanf.scanf "%d %d" @@ fun n l ->
  let apples = Array.init n @@ ( + ) l in
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 apples
  - Array.fold_left (fun acc a ->
    if abs acc <= abs a then acc else a) max_int apples


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int n;
const int MOD=1e9+7;
int main()
{
	 long long a[2],b[2];
	 cin>>a[0]>>a[1]>>b[0]>>b[1];
	 long long res=-8e18;
	 for(int i=0;i<2;i++)
	 	for(int j=0;j<2;j++)
	 		res=max(res,a[i]*b[j]);
	 		
	cout<<res;
} 

Measured memory_bytes: 3632
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};

int N, M, A, B, C, T;
int s[55];

// matrix operation
typedef int mat_type;
typedef vector< mat_type > mArray;
typedef vector< mArray > mMatrix;

mMatrix operator * (const mMatrix& _a, const mMatrix& _b) {
	int _n = size_of(_a), _m = size_of(_b[0]), b_size = size_of(_b);
	mMatrix res(_n, mArray(_m, 0));
	for_(i,0,_n) {
		for_(k,0,b_size) {
			for_(j,0,_m) {
				res[i][j] += _a[i][k] * _b[k][j];
				res[i][j] %= M;
			}
		}
	}
	return res;
}

mMatrix mMatrixI(int _n) {
	mMatrix res(_n, mArray(_n, 0));
	for_(i,0,_n) res[i][i] = 1;
	return res;
}

mMatrix POW(mMatrix& _a, lint _k) {
	int _n = size_of(_a);
	mMatrix res = mMatrixI(_n);
	
	while (_k > 0) {
		if (_k & 1) res = res * _a;
		_a = _a * _a;
		_k >>= 1;
	}
	return res;
}

void solve() {
	mMatrix pows(N, mArray(N, 0));
	
	int p = -1;
	for_(i,0,N) {
		if (p >= 0) pows[i][p] = A;
		pows[i][p + 1] = B;
		if (p + 2 < N) pows[i][p + 2] = C;
		p++;
	}
	
	mMatrix mul = POW(pows, T);
	
	
	mMatrix ans(N, mArray(1, 0));
	for_(i,0,N) ans[i][0] = s[i];
	
	ans = mul * ans;
	
	for_(i,0,N) {
		if (i < N - 1) cout << ans[i][0] << " ";
		else cout << ans[i][0] << endl;
	}
}

int main() {
	while (cin >> N >> M >> A >> B >> C >> T, N) {
		for_(i,0,N) cin >> s[i];
		solve();
	}
	return 0;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = n;
    int now = 1;
    int pos = 0;
    while(pos < n){
        if(a[pos] == now){
            ans--;
            now++;
        }
        pos++;
    }
    if(ans == n) cout << "-1" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in(), x = in();
	vector<ll>a(n); REP(i, n)a[i] = in(); sort(ALL(a));
	ll sum = 0;
	REP(i, n) {
		sum += a[i];
		if (sum > x) {
			cout << i << endl;
			return 0;
		}
	}
	cout << n - (sum == x ? 0 : 1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
void A() {
    int n;
    cin >> n;
    int res = max(0, (n + 999) / 1000 * 1000 - n);
    cout << res << endl;
}
void B() {
    int n;
    cin >> n;
    unordered_map<string, int>cnt;
    cnt["AC"] = 0;
    cnt["WA"] = 0;
    cnt["RE"] = 0;
    cnt["TLE"] = 0;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        cnt[s]++;
    }
    cout << "AC x " << cnt["AC"] << endl;
    cout << "WA x " << cnt["WA"] << endl;
    cout << "TLE x " << cnt["TLE"] << endl;
    cout << "RE x " << cnt["RE"] << endl;
}
void C() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> grid(h, vector<char>(w, '.'));
    int bl = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> grid[i][j];
            if(grid[i][j] == '#')
                bl++;
        }
    }
    int res = 0;
    for(int i = 0; i < (1 << h); i++) {

        for(int j = 0; j < (1 << w); j++) {
            int cnt = bl;
            for(int x = 0; x < h; x++) {
                for(int y = 0; y < w; y++) {
                    if(grid[x][y] == '.')
                        continue;
                    if(i & (1 << x) || j & (1 << y))
                        cnt--;
                }
            }
            if(cnt == k)
                res++;
        }
    }
    cout << res << endl;
}

void D() {
    int n;
    cin >> n;
    vector<ll> a(n, 0);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    ll res = 0;
    int len = (n + 1) / 2; //使用a的前len个
    vector<ll> sum(len + 1, 0);
    for(int i = 1; i <= len; i++) {
        sum[i] = sum[i - 1] + a[i - 1];
    }
    res = sum[len] - a[len - 1] + sum[len] - a[0];
    if(n % 2 == 0)
        res += a[len - 1];
    cout << res << endl;
}
void E() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n, 0);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(),a.end());
    ll res = 1;
    int l = 0, r = n - 1;
    ll sign = 1;
    if (k % 2) {
        res = a[r--];
        --k;
        if(res < 0)
            sign = -1;
    }
    while(k) {
        ll x = (ll)a[l] * a[l + 1], y = (ll)a[r - 1] * a[r];
        if(x * sign > y * sign) {
            res = x % mod * res % mod;
            l += 2;
        } else {
            res = y % mod * res % mod;
            r -= 2;
        }
        k -= 2;
    }
    cout << ((res + mod) % mod) << endl;
}
void F() {

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


Measured memory_bytes: 4780
n=gets.to_i
x=[]
y=[]
sum=0
s=[*1..n].inject(1){|wa,k|wa*=k}
n.times do |i|
  x[i],y[i]=gets.split.map &:to_f
end
a=((0...n).to_a).permutation(n).to_a
a.each do|i|
  (n-1).times do |j|
    sum+=Math.sqrt((x[i[j]]-x[i[j+1]])**2+(y[i[j]]-y[i[j+1]])**2)
  end
end
puts format("%6f",sum/s)


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

const int N = 2e5 + 10, mod = 1e9 + 7;

int n, dp[N], sz[N], res[N], fact[N], invfact[N];
vector<int> adj[N];
vector<pair<int, int>> pref[N], suf[N];

int fp(int a, int b) {
    int ret = 1;
    while(b) {
        if(b & 1) ret = 1ll * ret * a % mod;
        b >>= 1;
        a = 1ll * a * a % mod;
    }
    return ret;
}

int com(int m, int r) {
    return 1ll * fact[m] * invfact[r] % mod * invfact[m - r] % mod;
}

int merge(int w1, int w2, int s1, int s2) {
    //cout << s1 + s2 << ' ' << s1 << ' ' << com(s1 + s2, s1) << '\n';
    return 1ll * w1 * w2 % mod * com(s1 + s2, s1) % mod;
}

void dfs(int u, int pa) {
    dp[u] = 1;
    sz[u] = 0;
    for(int v : adj[u]) {
        if(v == pa) continue;
        dfs(v, u);
        dp[u] = 1ll * dp[u] * dp[v] % mod * com(sz[u] + sz[v], sz[u]) % mod;
        pref[u].push_back({dp[u], sz[u] + sz[v]});
        sz[u] += sz[v];
    }
    pair<int, int> t = {1, 0};
    int j = -1;
    for(int i = adj[u].size() - 1; i >= 0 ; i--) {
        int v = adj[u][i];
        if(v == pa) {
            j = i;
            continue;
        }
        t.first = merge(t.first, dp[v], t.second, sz[v]);
        t.second += sz[v];
        suf[u].push_back(t);
    }
    reverse(suf[u].begin(), suf[u].end());
    if(j > -1) adj[u].erase(adj[u].begin() + j);
    sz[u]++;
}

void dfs1(int u, int pa, int up = 1, int upsz = 0) {
    //cout << u << ' ' << up << ' ' << upsz << ' ' << dp[u] << '\n';
    res[u] = merge(dp[u], up, sz[u] - 1, upsz);
    //if(u == 2) cout << adj[u].size() << '\n';
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == pa) continue;
        int Up = up, Upsz = upsz;
        if(i) Up = merge(Up, pref[u][i - 1].first, Upsz, pref[u][i - 1].second), Upsz += pref[u][i - 1].second;
        if(i < adj[u].size() - 1) Up = merge(Up, suf[u][i + 1].first, Upsz, suf[u][i + 1].second), Upsz += suf[u][i + 1].second;
        dfs1(v, u, Up, Upsz + 1);
    }
}

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    fact[0] = invfact[0] = 1;
    for(int i = 1; i < N; i++) {
        fact[i] = 1ll * fact[i - 1] * i % mod;
        invfact[i] = fp(fact[i], mod - 2);
    }
    int tc = 1; 
    //scanf("%d", &tc);
    while(tc--) {
        scanf("%d", &n);
        for(int i = 0; i < n - 1; i++) {
            int u, v; scanf("%d%d", &u, &v);
            adj[u].push_back(v);
            adj[v].push_back(u);
        }

        dfs(1, 1);
        dfs1(1, 1);

        for(int i = 1; i <= n; i++) printf("%d\n", res[i]);
    }    
    return 0;
}

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

int main(){

    int a, b, h, m;

    cin >> a >> b >> h >> m;

    double hk, mk;

    static const double pi = 3.141592653589793;

    hk = (double)(h*60 + m) / 720;
    mk = (double)m / 60;

    double t = pow(a * cos(hk*2*pi) - b * cos(mk*2*pi), 2.0) + pow(a * sin(hk*2*pi) - b * sin(mk*2*pi), 2.0);

    printf("%.10f\n", sqrt(t));


    return 0;
} 


Measured memory_bytes: 4028
import java.util.*; 
import java.io.*;

public class Main {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));

        int K = nextInt();
        int A = nextInt();
        int B = nextInt();

        int mod =  B % K;    
        if(B-mod>=A){
            System.out.println("OK");
        }
        else{
            System.out.println("NG");
        }


    }
    
      
    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}

Measured memory_bytes: 32736
#include<stdio.h>
#include<string.h>

int main(void)
{
    char w[7];

    scanf("%s",w);
    if(strcmp(w,"Sunny")==0)
    {
        printf("Cloudy\n");
    }
    else if(strcmp(w,"Cloudy")==0)
    {
        printf("Rainy\n");
    }
    else if(strcmp(w,"Rainy")==0)
    {
        printf("Sunny\n");
    }
    else
    {
        printf("Error\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int n;
    cin>>n;
    bool t=false;
    int count=0;
    for(int i=0;i<n;i++)
    {
        int d1,d2;
        cin>>d1>>d2;
        if(d1==d2)
        count++;
        else
        count=0;

        if(count>=3)
        {
        t=true;
        break;
        }
    }
    if(t==true)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int A, B;
    cin >> A >> B;
    if(A<=9&&B<=9){
        cout << A * B << endl;
    }
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3640
n = int(input())

pn = list( map(int, input().split()) )

log = []
for i in range(n):
    if pn[i] != i+1:
        log.append( (pn[i],i+1) )



ans = ''

if len(log)==0:
    ans = 'YES'

elif len(log)==2:
    xv,xi = log[0]
    yv,yi = log[1]

    ans = 'YES' if xv == yi and yv == xi else 'NO'
else :
    ans = "NO"

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int W, H; cin >> W >> H;
    vec p(W); readv(p);
    vec q(H); readv(q);

    vector<Pii> P(0);
    REP(i, W) P.push_back(Pii(p[i], 0));
    REP(i, H) P.push_back(Pii(q[i], 1));
    SORT(P);

    int ans = 0, w = 0, h = 0;
    REP(i, H + W){
        int c = P[i].first;
        if(P[i].second == 0){
            ans += c * (H + 1 - h);
            w++;
        }else{
            ans += c * (W + 1 - w);
            h++;
        }
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 8048
#include<stdio.h>

int main(void) {

	int N;
	char S[100];
	scanf("%d", &N);
	scanf("%s", S);

	if (N % 2 == 0) {
		for (int i = 0; i < (N / 2); i++) {
			if (S[i] != S[i + (N / 2)]) {
				printf("No\n");
				return 0;
			}
		}
		printf("Yes\n");
		return 0;
	}
	printf("No\n");

	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static PrintWriter out;

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(System.out);
		int N = sc.nextInt();
		char[][] words = new char[N][];
		for (int i = 0; i < N; i++) {
			words[i] = sc.next().toCharArray();
			insert(words[i], 0, words[i].length - 1);
		}
		//print(0, "\t");
		long ans = 0;
		for (int i = 0; i < N; i++) {
			ans += calc(words[i]);
		}
		out.println(ans);
		
		out.flush();
	}

	static int[][] count = new int[26][1000002];
	static int[][] next = new int[26][1000002];
	static int size = 1;

	static int insert(char[] word, int node, int pos) {
		if (pos == -1) return 0;
		int idx = word[pos] - 'a';
		int child = next[idx][node];
		if (child == 0) {
			next[idx][node] = child = size++;
		}
		int ret = insert(word, child, pos - 1) | (1 << idx);
		for (int i = 0; i < 26; i++) if (contains(ret, i)) {
			count[i][node]++;
		}
		return ret | (1 << idx);
	}

	static int calc(char[] word) {
		int cur = 0;
		for (int i = word.length - 1; i >= 1; i--) {
			cur = next[word[i] - 'a'][cur];
		}
		//System.err.println(new String(word) + " => " + cur.count[word[0] - 'a']);
		return count[word[0] - 'a'][cur] - 1;
	}

	static void print(int node, String tab) {
		for (int i = 0; i < 26; i++) {
			if (count[i][node] > 0) {
				System.err.print(tab + " count= " + (char) (i + 'a') + " => " + count[i][node]);
			}
		}
		System.err.println();
		for (int i = 0; i < 26; i++) {
			if (next[i][node] != 0) {
				print(next[i][node], tab + (char) (i + 'a'));
			}
		}
	}

	static boolean contains(int mask, int pos) {
		return (mask & (1<<pos)) != 0;
	}

	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 323320
#include<iostream>
#include<iomanip>

int main()
{
    int a, b;
    double f;

    std::cin>>a>>b;

    f = (double)a/b;
    std::cout<<a/b<<" "<<a%b<<" "<<std::fixed<<std::setprecision(5)<<f<<std::endl;
    return 0;
}



Measured memory_bytes: 3240
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> l(Q), r(Q);
    for (int i=0; i<Q; i++) {
        cin >> l[i] >> r[i];
    }
    
    vector<int> sum_AC(N);
    int sum=0;
    sum_AC[0] = 0;
    for (int i=1; i<N; i++) {
        if (S[i-1]=='A' && S[i]=='C') {
            sum++;
        }
        sum_AC[i] = sum;
    }
    
    for(int i=0; i<Q; i++){
        cout << sum_AC[r[i]-1] - sum_AC[l[i]-1] << endl;
    }
    
}


Measured memory_bytes: 2176
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int r = 0;
		int t = 0;
		String str = "";
		//判定
		for(int i = 1; i <= 9; i++){
			t = n / i;
			r = n % i;
			 if((1 <= t && t <= 9 )&& r == 0){
				 str = "Yes";
				 break;
			 }
		}
		//出力文字決定
		if(str.isEmpty()){
			str = "No";
		}
		System.out.println(str);
	}
}


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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/
const ll mod=1e9+7;
const ll INF=1e18;
/*****************************************************************************/

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,x,t; cin >>n >>x >>t;
	int num=n/x;
	if (n%x!=0) num++;
	cout <<num*t;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t
int main(){
    intf a,b,n;
    cin >>a >>b >>n;

    intf c=min(n,b-1);

    cout << a*c/b - a*(c/b) <<endl;
}

Measured memory_bytes: 3636
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
void Main(){
    int n, k;
    double ans=0, al = 0;
    cin >> n >>k;
    vector<double> e(n), p(n);
    REP(i, n){
        cin >> p[i];
        e[i] = (p[i]+1.0)/2.0;
    }
    REP(i, k){
        al += e[i];
    }
    ans = al;
    FOR(i, k, n){
        al-= e[i-k];
        al+= e[i];
        ans = max(ans, al);
       //cout << ans << endl;
    }
    cout << (ans) << endl;   
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(7);
	Main();
    return 0;
}

    




Measured memory_bytes: 3456
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();
            long ans = 0;

            int n = S.length();
            char s[] = S.toCharArray();
            int ptr = n;

            // {0, 1, ..., n-1} の部分集合の全探索
            for (int bit = 0; bit < (1 << n - 1); ++bit) {
                /* bit で表される集合の処理を書く */

                // 整数値 bit から、「いくつか選ぶ方法」を復元
                long tmp = 0;
                tmp = s[0] - '0';
                for (int i = 1; i < n; ++i) {

                    if ((bit & (1 << i - 1)) > 0) {
                        ans += tmp;
                        tmp = s[i] - '0';
                    } else {
                        tmp *= 10;
                        tmp += s[i] - '0';
                    }
                }
                ans += tmp;

            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int n,a,b,s=0;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		s+=b-a+1;
	}
	cout<<s<<endl;
	return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define UF_NUM 505050

li cnt[2];

int main() {
    map<char, char> m;
    m['A'] = 'T';
    m['T'] = 'A';
    m['C'] = 'G';
    m['G'] = 'C';
    char c;
    cin >> c;
    cout << m[c] << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a+b>=a-b&&a+b>=a*b)
  cout<<a+b<<endl;
  else if(a-b>=a+b&&a-b>=a*b)
  cout<<a-b<<endl;
  else
  cout<<a*b<<endl;
}

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

int main(void){
  long long N;
  int X, M;
  cin >> N >> X >> M;
  vector<long long> A, Asum;
  A.push_back(X);
  Asum.push_back(X);
  int lps;
  int lpl;
  for(int i = 0; i < N-1; i++){
    A.push_back(A[i]*A[i]%M);
    Asum.push_back((Asum[i]+A[i+1]));
    for(int j = 0; j < A.size()-1; j++){
      if(A[i+1] == A[j]){
        lps = j;
        lpl = i-j+1;
        goto lpfind;
      }
    }
  }
  lpfind:
  
  if(A.size() == N){
    cout << Asum[N-1] << endl;
    return 0;
  }
  
  long long ans;
  long long lpc = (N - lps)/lpl;
  
  if(lps == 0){
    ans = Asum[lpl-1]*lpc;
  }
  else{
    ans = Asum[lps-1];
    ans += (Asum[lps+lpl-1] - Asum[lps -1])*lpc;
  }
  
  int residual = 0;
  for(long long i = lps + lpl*lpc; i < N; i++){
    ans += A[lps+residual];
    residual++;
  }
  
  cout << ans << endl;
}

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

int main(){

int n;
int max;
int min;

cin >> n;

int a[n];

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

max = a[0];
min = a[0];

for(int i=0;i<n;i++){
if(max<a[i])max=a[i];
if(min>a[i])min=a[i];
}

cout << max-min << endl;

}

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

int k;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> k;
    vector<ll> a(k);
    for (auto& i : a) cin >> i;
    reverse(a.begin(), a.end());

    if (a[0] != 2) {
        cout << -1;
        return 0;
    }
    
    ll lb = 2, rb = 3;
    for (int i = 1; i < k; ++i) {
        ll nlb = a[i] * ceil((long double)lb / a[i]);
        ll nrb = a[i] * (rb / a[i]) + a[i] - 1;
        if (nlb > rb) {
            cout << -1;
            return 0;
        }
        lb = nlb, rb = nrb;
    }

    cout << lb << ' ' << rb;
}


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

int main(){
  int N;
  cin>>N;
  const int INF=1e9;
  std::vector<queue<int>> que(N),que1(N),que2(N);
  int a,b;
  for(int i=0;i<N-1;i++){
    cin>>a>>b;
    a--;b--;
    que[a].push(b);
    que[b].push(a);
    que1[a].push(b);
    que1[b].push(a);
    que2[a].push(b);
    que2[b].push(a);
  }
  std::vector<int> da(N,INF),db(N,INF);
  da[0]=0;
  db[N-1]=0;
  queue<int> d;
  d.push(0);
  while(d.size()){
    int k=d.front();
    d.pop();
    while(que1[k].size()){
      int c=que1[k].front();
      que1[k].pop();
      if(da[c]==INF){
        da[c]=da[k]+1;
        d.push(c);
      }
    }
  }
  d.push(N-1);
  while(d.size()){
    int k=d.front();
    d.pop();
    while(que2[k].size()){
      int c=que2[k].front();
      que2[k].pop();
      if(db[c]==INF){
        db[c]=db[k]+1;
        d.push(c);
      }
    }
  }
  int m=INF;
  int mm=INF;
  int j;
  for(int i=0;i<N;i++){
    if(m>abs(da[i]-db[i])){
      m=abs(da[i]-db[i]);
      mm=da[i];
      j=i;
    }
  }
  for(int i=0;i<N;i++){
    if(m==abs(da[i]-db[i])&&mm>da[i]){
      mm=da[i];
      j=i;
    }
  }
  if(da[j]-db[j]<=0){
    int k=N-1;
    int ans=0;
    queue<int> ll;
    ll.push(k);
    std::vector<int> pp(N,INF);
    pp[j]=0;
    while(ll.size()){
      int tt=ll.front();
      ll.pop();
      if(pp[tt]){
        pp[tt]=0;
        ans++;
        while(que[tt].size()){
          int ii=que[tt].front();
          que[tt].pop();
          ll.push(ii);
        }
      }
    }
    if(ans>=(N+1)/2)cout<<"Snuke"<<endl;
    else cout<<"Fennec"<<endl;
    //cout<<333<<ans<<endl;
  }
  else{
    int k=0;
    int ans=0;
    queue<int> ll;
    ll.push(k);
    std::vector<int> pp(N,INF);
    pp[j]=0;
    while(ll.size()){
      int tt=ll.front();
      ll.pop();
      if(pp[tt]){
        pp[tt]=0;
        ans++;
        while(que[tt].size()){
          int ii=que[tt].front();
          que[tt].pop();
          ll.push(ii);
        }
      }
    }
    if(ans>=N/2+1)cout<<"Fennec"<<endl;
    else cout<<"Snuke"<<endl;
    //cout<<555<<ans<<endl;
  }
}


Measured memory_bytes: 203008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	pair<ll,int> p[n];
	rep(i,n) cin>>p[i].first>>p[i].second;
	map<pair<ll,int>,int> mp;
	
	rep(i,n){//すべてのパターンを試す(mpの中には合計n*(n-1)個入っているはず)
		rep(j,n){
			if(i!=j){
				pair<ll,int> q;
				q.first=p[j].first-p[i].first;
				q.second=p[j].second-p[i].second;
				mp[q]++;
			}
		}
	}
		
	int cnt=0;
	for(auto m:mp){
		cnt=max(m.second,cnt);
		//cout<<m.second<<"\n";
	}

	int ans=n-cnt;

	cout<<ans<<"\n";
}


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

using namespace std;
#define MX 1e5+1
#define pb push_back
#define prr pair<int,int> 
#define int long long
#define fir first
#define sec second


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
    int n,m;
    cin>>n>>m;
    int arr[n];
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    sort(arr,arr+n,greater<int>());
    int a1=arr[m-1];
    int b1=ceil((double)sum/(4*m));
    if(a1>=b1){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }

       
}










Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {

	long long int n, d;	
	long long int x, y;
	int ii, count = 0;

	scanf("%d%d", &n, &d);


	for (ii = 0; ii < n; ii++) {
		scanf("%lld%lld", &x, &y);
		
		if (x * x + y * y <= d * d) {
			count++;
		}
	}

	printf("%d", count);

	return 0;

}

Measured memory_bytes: 1704
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    //そのまま割ると割り切れない場合は1回少なくなってしまう。1回多くはならないギリギリ=(ダメージ-1)を足す。
    ll x = (a+d-1)/d;
    ll y = (c+b-1)/b;
    cout<<(x>=y?"Yes":"No")<<"\n";
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;
typedef long long LL;
int n, A, B;
int a[maxn];
bool check(LL k) {
    LL base = k * B, diff = A - B, sum = 0;
    for (int i = n-1; i >= 0; --i) {
        if (a[i] <= base) continue;
        sum += ceil(1.0 * (a[i] - base) / diff);
    }
    return sum <= k;
}
int main() {
//    freopen("in.txt", "r", stdin);
    scanf("%d%d%d", &n, &A, &B);
    LL ri = 0;
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]), ri += a[i]/B+1;
    sort(a, a+n);

    LL le = 1;
    while (ri > le) {
        LL mid = le + ri >> 1;
        if (check(mid)) ri = mid;
        else le = mid + 1;
    }
    printf("%lld\n", le);
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include <vector>

struct Node{
    std::vector<Node*> neighber;
    int id;
    int delete_flag;
};

void infect(Node *node){
    node->delete_flag = 1;
    //printf("infected %d\n", node->id);
    for(auto itr = node->neighber.begin(); itr != node->neighber.end(); ++itr){
        if((*itr)->delete_flag == 0){
           infect(*itr);
        }
    }
}

int main(){
    int number, m;
    scanf("%d %d", &number, &m);
    std::vector<Node> nodes;
    Node nil;
    nil.id = 0;
    nodes.push_back(nil); // for 1-origin of id
    for(int i = 1; i < number + 1; i++){ //id is 1-origin
        Node node;
        node.id = i;
        nodes.push_back(node);
    }
    for(int i = 0; i < m; i++){
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        nodes[x].neighber.push_back(&nodes[y]);
        nodes[y].neighber.push_back(&nodes[x]);
    }
    int count = 0;
    for(auto itr = nodes.begin() + 1; itr != nodes.end(); itr++){
        if(itr->delete_flag == 0){
            infect(&*itr);
            count++;
        }
    }
    printf("%d\n", count);
}

Measured memory_bytes: 9580
n,k,q = map(int, input().split())
a=[int(input()) for _ in range(q)]
b=[0]*n#正解数
init=[k]*n #最初の点数
c=[q]*n#問題数
d=[0]*n#結果

for i in range(q):
    b[a[i]-1] += 1

for i in range(n):
    d[i] = init[i]-c[i]+b[i]

# print(d)
for i in range(len(d)):
    print('Yes' if d[i]>0 else 'No')

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

int main() {
  int N, M;
  cin >> N >> M;
  Graph edge(N);
  rep(i,M) {
    int x, y, z;
    cin >> x >> y >> z;
    --x; --y;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }

  vector<bool> visited(N, false);
  int ans = 0;
  rep(i,N) {
    if (visited[i]) continue;
    visited[i] = true;
    ++ans;

    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (auto nv : edge[v]) {
        if (visited[nv]) continue;
        visited[nv] = true;
        q.push(nv);
      }
    }
  }

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


Measured memory_bytes: 6520
import sys
sys.setrecursionlimit(10**6)
N,M=map(int, input().split())
S=[[] for _ in range(N)]
for i in range(M):
  a,b=map(int, input().split())
  S[a-1].append((i,b-1))
  S[b-1].append((i,a-1))
  
def dfs(start, goal, exclude):
  for i,b in S[start]:
    if i==exclude or (b in dones):
      continue
    if b==goal:
      dones.append(b)
      break
    else:
      dones.append(b)
      dfs(b,goal,exclude)
  if goal not in dones:
    return True
ans=[]
for i in range(N):
  #m番目の辺について考える
  for m,b in S[i]:
    dones=[]
    is_bridge=dfs(i,b,m)
    #print(is_bridge)
    if is_bridge and m not in ans:
      ans.append(m)
      
print(len(ans))

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template <typename X>
struct BIT
{
  vector<X> dat;
  int n;

  BIT(int _n){
    n = _n+1;
    dat.assign(n,0);
  }
  
  X sum(int i)
  {
    X s = 0;
    while(i > 0){
      s += dat[i];
      i -= i&(-i);
    }
    return s;
  }

  void add(int i,X x)
  {
    while(i<=n){
      dat[i] += x;
      i += i&(-i);
    }
  }

};




int main()
{
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    cin >> b[i];
  }
  // rep(i,n){
  //   cout << i << ":" << __builtin_popcount(a[i]) << "\n";
  // }
  
  const int inf = 1e+9;

  vector<vector<int>> dp((1<<n),vector<int>(51,inf));
  dp[0][1] = 0;
  
  rep(S,(1<<n)){
    int cnt = __builtin_popcount(S);
    rep1(i,50){
      if(dp[S][i]==inf){
	continue;
      }
      int cnt2=0;
      rep(j,n){
	if((S>>j)&1){
	  cnt2++;
	}
	else{
	  if(cnt%2==j%2){
	    if(i<=a[j]){
	      dp[S|(1<<j)][a[j]] = min(dp[S|(1<<j)][a[j]],dp[S][i]+(cnt-cnt2));
	    }
	  }
	  else{
	    if(i<=b[j]){
	      dp[S|(1<<j)][b[j]] = min(dp[S|(1<<j)][b[j]],dp[S][i]+(cnt-cnt2));
	    }
	  }	  
	}
      }
    }
  }

  int res = inf;
  rep1(i,50){
    res = min(res,dp[(1<<n)-1][i]);
  }
  if(res==inf) cout << -1 << "\n";
  else cout << res << "\n";
  
  return 0;
}


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




int main()
{


    long long int  l , r , d;

    cin >> l >> r >> d;



    int count = 0;

    for(int i=l; i<=r; i++)
    {
        if(i%d==0)
            count++;
    }

    cout << count << endl;





    return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	char a,b;
	cin >> a >> b;
	if(a == b){
		cout << "H\n";
	}else{
		cout << "D\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define show(x) cout<<#x" = "<<x<<endl;
#define show2(x,y) cout<<#x" = "<<x<<" "<<#y<<" = "<<y<<endl;
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> iipair;
typedef pair<unsigned,unsigned> uupair;
typedef vector<int> vec;
typedef vector<unsigned> uvec;

const unsigned LIMIT=100;

ll dp[LIMIT+1][5][2][2];

unsigned k;
string a,b;

ll call(unsigned pos,ll count,bool f1,bool f2)
{
    if(dp[pos][count][f1][f2] != -1 ) return dp[pos][count][f1][f2];
    if(pos==b.length()) return dp[pos][count][f1][f2]=(count==k);
    if(count > k) return dp[pos][count][f1][f2]=0;
    int digit_min,digit_max;
    digit_max=(f1?9:b[pos]);
    digit_min=(f2?0:a[pos]);
    ll res=0;
    for(int i=digit_min;i<=digit_max;++i)
    {
        unsigned npos=pos+1;
        ll ncount=count+(i!=0);
        bool nf1,nf2;
        nf1=f1;
        nf2=f2;
        if(!f1 && i<b[pos]) nf1=1;
        if(!f2 && i>a[pos]) nf2=1;
        res+=call(npos,ncount,nf1,nf2);
    }
    return dp[pos][count][f1][f2] = res;
}

ll solve()
{
    while(a.length()!=b.length()) a="0"+a;
    for(auto &item : a) item-='0';
    for(auto &item : b) item-='0';
    memset(dp,-1,sizeof(dp));
    return call(0,0,0,0);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>b>>k;
    cout<<solve()<<"\n";
}

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

#define int long long int
#define float long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define inf LLONG_MAX
int exp(int x,int y,int mod){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x,int mod){return exp(x,mod-2,mod);}


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

	int n,ans=0;
	cin>>n;
	mii m;
	while(n%2==0)
	{
		n/=2;
		m[2]++;
	}
	for(int j=3;j*j<=n;j+=2)
	{
		while(n%j==0)
		{
			n/=j;
			m[j]++;
		}
	}
	if(n>2)
		m[n]++;
	for(auto x:m)
	{
		int i=1;
		for(i=1;;i++)
		{
			int val=(i*(i+1))/2;
			if(val>x.se)
				break;
		}
		--i;
		ans+=i;
	}
	cout<<ans;
	return 0;
}


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

string day;
map<string, int> mapping = {{"MON", 6}, {"TUE", 5}, {"WED", 4}, {"THU", 3}, {"FRI", 2}, {"SAT", 1}, {"SUN", 7}};

int main()
{
    cin >> day;
    cout << mapping[day] << '\n';
}

Measured memory_bytes: 256