akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

import static java.lang.Math.*;

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

  private void solve() {
    try(InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {

      final int n = in.nextInt();
      List<Pear> task = new ArrayList<>(n);
      for (int i = 0; i < n; i++) {
        task.add(new Pear(in.nextInt(), in.nextInt()));
      }

      Collections.sort(task);
      // task.sort((a,b) -> a.compareTo(b));

      boolean isComp = true;
      int time = 0;
      for (Pear p : task) {
        time += p.c;
        if(time > p.l) {
          isComp = false;
          break;
        }
      }

      String ans = isComp ? "Yes" : "No";
      out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
  

  private class Pear implements Comparable<Pear>{
    public int c,l;
    Pear(int c, int l) {
      this.c = c;
      this.l = l;
    }

    @Override
    public int compareTo(Pear o) {
      if(this.l == o.l) return 0;
      return l > o.l ? 1 : -1;
    }
  }

  int atoi(String s) { return Integer.parseInt(s); }
  long atol(String s) { return Long.parseLong(s); }

  static class InputReader implements AutoCloseable {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream), 32768);
      st = null;
    }
    public String next() {
      if (st == null || !st.hasMoreTokens()) {
        try { st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      }
      return st.nextToken();
    }
    public int nextInt() { return Integer.parseInt(next()); }
    public long nextLong() { return Long.parseLong(next()); }
    int[] mapInt(int len) {
      int[] ret = new int[len];
      for (int i = 0; i < len; i++) ret[i] = Integer.parseInt(next());
      return ret;
    }
    long[] mapLong(int len) {
      long[] ret = new long[len];
      for (int i = 0; i < len; i++) ret[i] = Long.parseLong(next());
      return ret;
    }
    @Override public void close() throws IOException { br.close(); }
  }
}

Measured memory_bytes: 50764
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod7=1000000007LL;
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add(LL _x, LL _y, LL _mod=mod7){
  _x+=_y;
  return _x>=_mod ? _x-_mod : _x;
}
inline LL sub(LL _x, LL _y, LL _mod=mod7){
  _x-=_y;
  return _x<0 ? _x+_mod : _x;
}
inline LL mul(LL _x, LL _y ,LL _mod=mod7){
  _x*=_y;
  return _x>=_mod ? _x%_mod : _x;
}
LL mypow(LL _a, LL _x, LL _mod){
  if(_x == 0) return 1LL;
  LL _ret = mypow(mul(_a, _a, _mod), _x>>1, _mod);
  if(_x & 1) _ret=mul(_ret, _a, _mod);
  return _ret;
}
LL mymul(LL _a, LL _x, LL _mod){
  if(_x == 0) return 0LL;
  LL _ret = mymul(add(_a, _a, _mod), _x>>1, _mod);
  if(_x & 1) _ret=add(_ret, _a, _mod);
  return _ret;
}
void sleep(double sec = 1021){
  clock_t s = clock();
  while(clock() - s < CLOCKS_PER_SEC * sec);
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
const int N=202020;
void build(){

}
int n, a[N];
void init(){
  n=getint();
  for(int i=1; i<=n; i++)
    a[i]=getint();
}
void no(){
  puts("-1");
  exit(0);
}
void solve(){
  if(a[1]) no();
  LL ans=0;
  int atleast=0;
  for(int i=n; i>=1; i--){
    atleast=max(atleast, 0);
    if(a[i] < atleast) no();
    if(a[i] > atleast){
      int til=i-a[i];
      if(til < 1) no();
      ans+=a[i];
      atleast=a[i];
    }
    atleast --;
  }
  printf("%lld\n", ans);
}
int main(){
  build();
  //__ = getint();
  while(__ --){
    init();
    solve();
  }
}


Measured memory_bytes: 1024
import sys
n,m=map(int,input().split())
x=sorted(list(map(int,input().split())))
dp=[0]*(m-1)
ans=0

if n>=m:
  print(0)
  sys.exit()
for i in range(m-1):
  dp[i]=x[i+1]-x[i]
dp.sort()

for i in range(m-n):
  ans+=dp[i]
print(ans)

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,a,sum,ans;
vector<int> v;

main() {
    cin >> n;
    rep(i,n) {
        cin >> a;
        sum+=a;
        v.pb(sum)
    }
    sort(all(v));
    int cnt=1;
    if(!v[0]) ans++;
    rep1(i,n-1) {
        if (!v[i]) ans++;
        if (v[i] == v[i-1]) cnt++;
        else {
            cnt--;
            rep1(i,cnt) ans += i;
            cnt=1;
        }
    }
    cnt--;
    rep1(i,cnt) ans += i;
    ct(ans)
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin>>n>>k;
    string s;
    cin>>s;
    int h = 0;
    for(int i=0; i<n; ++i) {
        if(i>0 && s[i] == 'L' && s[i-1] == 'L')
        ++h;
        if(i<n-1 && s[i] == 'R' && s[i+1] == 'R')
        ++h;
    }
    cout<<min(n-1, h + 2*k);
}

Measured memory_bytes: 512
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let nums: Vec<f64> = get_line()
        .split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect();
    let (a, b, deg) = (nums[0], nums[1], nums[2]);

    let height = b * deg.to_radians().sin();
    let area = a * height / 2.0;
    let c = (a.powi(2) + b.powi(2) - 2.0 * a * b * deg.to_radians().cos()).sqrt();

    println!("{:.09}\n{:.09}\n{:.09}", area, a + b + c, height);
}



Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200, mx = 7;
vector<int> cycle;
int p[maxn], out[maxn], val[maxn], is_out[maxn];
set<int> has[maxn];
int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		cin >> p[i]; p[i]--;
		out[p[i]]++;
	}
	set<pair<int,int> > outs;
	for(int i = 0; i < n; i++){
		outs.insert({out[i], i});
	}
	while(!outs.empty()){
		if(outs.begin()->first) break;
		int ot, v; tie(ot, v) = *outs.begin(); outs.erase(outs.begin());
		is_out[v] = true;
		while(has[v].count(val[v])) val[v]++;
		has[p[v]].insert(val[v]);
		outs.erase({out[p[v]], p[v]});
		out[p[v]]--;
		outs.insert({out[p[v]], p[v]});
	}
	for(int i = 0; i < n; i++){
		if(!is_out[i]){
			int u = i;
			do {
				cycle.push_back(u);
				u = p[u];
			} while(u != i);
			vector<int> cand;
			for(int j = 0; j < maxn && cand.size() < 2; j++) if(!has[cycle[0]].count(j)) cand.push_back(j);
			auto check = [&](int opt){
				int len = cycle.size();
				int lst = opt;
				for(int j = 0; j < len; j++){
					int v = 0, who = cycle[(j + 1) % len];
					while(has[who].count(v) || v == lst) v++;
					lst = v;
				}
				return lst == opt;
			};
			if(check(cand[0]) || check(cand[1])) cout << "POSSIBLE" << endl;
			else cout << "IMPOSSIBLE" << endl;
			return 0;
		}
	}
	return 0;
}
	



Measured memory_bytes: 23168
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll h, w;
  cin >> h >> w;
  if(h % 3 == 0 || w % 3 == 0) {
    cout << 0 << endl;
  } else {
    ll ans = 1001001001;
    for(int i = 0; i < 2; i++) {
      ll a = h;
      ll b = w;
      if(i == 1) {
        swap(a, b);
      }
      vector<ll> c(3);
      c[0] = ((a + 1) / 3) * b;
      a -= ((a + 1) / 3);
      c[1] = b / 2 * a;
      c[2] = (b + 1) / 2 * a;
      ans = min(ans, *max_element(c.begin(), c.end()) -
                         *min_element(c.begin(), c.end()));
      swap(a, b);
      c[1] = b / 2 * a;
      c[2] = (b + 1) / 2 * a;
      ans = min(ans, *max_element(c.begin(), c.end()) -
                         *min_element(c.begin(), c.end()));
    }
    cout << ans << endl;
  }
  return 0;
}

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

ll x, k, d, ans;

int main() {
  cin >> x >> k >> d;
  ll t = ceil((double)abs(x) / (double)d);
  if (k < t) {
    ans = min(abs(x+k*d), abs(x-k*d));
  } else {
    k -= t;
    if (k%2 == 0) {
      ans = min(abs(x+t*d), abs(x-t*d));
    } else {
      ans = min(abs(x+(t-1)*d), abs(x-(t-1)*d));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3740
N = int(input())
S = input()
 
r = S.count('R')
g = S.count('G')
b = S.count('B')
 
c = 0
for i in range(N):
    for j in range(i+1, N):
        h = 2*j-i
        if h >= N:
            break
        if S[i]!=S[h] and S[i]!=S[j] and S[j]!=S[h]:
            c += 1
 
print(r*g*b-c)

Measured memory_bytes: 9084
N = int(input())
AB = [0 for _ in range(N)]
SB = 0
for i in range(N):
  A, B = map(int, input().split())
  SB += B
  AB[i] = A + B
AB.sort(reverse=True)
SAB = 0
for i in range(N):
  if i % 2 == 0:
    SAB += AB[i]
print(SAB-SB)

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

using namespace std;

int main(void) {

    int A, B; double T;
    cin >> A >> B >> T;
    T += 0.5;

    int ans = 0;
    double t = A;
    while(t <= T) {
        t += A;
        ans += B;
    }

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

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)

combs = (n - 1) * (n - 2) / 2

if combs < k
  puts -1
else
  puts (n - 1) + (combs - k)
  (n - 1).times{|i| puts "1 #{i + 2}"}
  
  count = combs - k
  x, y = 2, 3
  count.times do
    puts "#{x} #{y}"
    if y == n
      x += 1
      y = x + 1
    else
      y += 1
    end
  end
end

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

int main(){
    int x,y,ck=0;
    cin>>x>>y;
    for(int i=0;i<=x;i++){
        int c=i,t=x-i;
        if((c*2+t*4)==y){
            ck=1;
        }
    }
    if(ck){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}
	

Measured memory_bytes: 3632
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
using namespace std;
int main(){
    ll INF = 1e9;
    ll n,k;cin>>n>>k;
    ll a[n+1];
    for(int i=1;i<=n;++i)
        cin>>a[i];
    ll dp[n+1];
    for(int i=1;i<=n;++i)
        dp[i]=INF;
    dp[1]=0;
    for(int i=2;i<=n;++i)
    {
        for(int j=1;j<=k;++j)
        {
            if((i-j)>=1)
                dp[i]=min(dp[i],abs(a[i]-a[i-j])+dp[i-j]);
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

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

const ll MOD = 1000000007;

int main(void) {
  ll N, T;
  cin >> N >> T;
  vector<ll> D(N);
  REP(i, 0, N) cin >> D[i];

  sort(D.begin(), D.end());

  ll ans = 1;
  REP(i, 0, N) {
    ll x = upper_bound(D.begin() + (N - i), D.end(), D[N - i - 1] + T) - (D.begin() + N - i);
    ans *= x + 1;
    ans %= MOD;
  }
  cout << ans << endl;
}



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

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

using namespace std;

int main() {
  int r,g,b,n;

  cin >> r >> g >> b >> n;

  ll result = 0;

  REP(i,n+1) {
    REP(j,n+1) {
      if((n - i*r - j*g)%b == 0 && (n - i*r - j*g) >= 0) {
        result++;
      }
    }
  }

  cout << result << endl;



}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi p(n), q(n);
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> q[i];
	vi a;
	repn(i, 1, n + 1) a.pb(i);
	int ans = 0, ans1 = 0;
	int cnt = 0;
	do{
		cnt++;
		int f = 1;
		rep(i, n) if(a[i] != p[i]){
			f = 0;
			break;
		}
		if(f) ans = cnt;
		f = 1;
		rep(i, n) if(a[i] != q[i]){
			f = 0;
			break;
		}
		if(f) ans1 = cnt;
	} while(next_permutation(all(a)));
	cout << abs(ans - ans1) << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max = 0;
		int ans = 1;
		
		for(int i = 1; i <= n; i++) {
			int count = 0;
			int temp = i;
			
			while(true) {
				if(temp%2 == 0) {
					temp = temp/2;
					count++;
				}
				else {
					break;
				}
			}
			if(count > max) {
				max = count;
				ans = i;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

template<class T,uint mod>
struct RollingHash_{
	vector< uint > hashed, power;

	inline uint mul(uint a, uint b){
		return a*(unsigned long long)b%mod;
	}
	RollingHash_(){}
	RollingHash_(T s, uint base = 10007) {
		int sz = (int) s.size();
		hashed.assign(sz + 1, 0);
		power.assign(sz + 1, 0);
		power[0] = 1;
		for(int i = 0; i < sz; i++) {
			power[i + 1] = mul(power[i], base);
			hashed[i + 1] = mul(hashed[i], base) + s[i];
			if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
		}
	}

	uint get(int l, int r){
		uint ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
		if(ret >= mod) ret -= mod;
		return ret;
	}
};

typedef pair<uint,uint>Hash;

template<class T>
struct RollingHash{
	RollingHash_<T,998244353>RH1;
	RollingHash_<T,1000000007>RH2;
	
	RollingHash(T s){
		RH1=RollingHash_<T,998244353>(s);
		RH2=RollingHash_<T,1000000007>(s);
	}

	Hash get(int l,int r){
		return make_pair(RH1.get(l,r),RH2.get(l,r));
	}
};

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

char S[600000],T[600000];

int main(){
	scanf("%s%s",S,T);
	string s=S,t=T;
	while(s.size()<t.size())s+=S;
	string ss=s+s;
	RollingHash<string>rh1(ss),rh2(t);
	UnionFind uf(s.size());
	rep(i,s.size()){
		Hash h1=rh1.get(i,i+t.size()),h2=rh2.get(0,t.size());
		if(h1==h2){
			int nx=(i+t.size())%s.size();
			if(uf.same(i,nx)){
				puts("-1");return 0;
			}
			uf.unite(i,nx);
		}
	}
	int Max=0;
	rep(i,s.size()){
		Max=max(Max,uf.size(i)-1);
	}
	cout<<Max<<endl;
}

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


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

    cin >> N;
    if(N >= 9){
        ans += 9;
        if(N >= 999){
            ans += 900;
            if(N >= 99999){
                ans += 90000;
            }else{
                ans += max(N-9999,0);
            }
        }else{ 
            ans += max(N-99, 0);
        }
    }else{
        ans += N;
    }


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

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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    string s; cin >> s;
    bool f = (s[0]==s[1] && s[1]==s[2]) || (s[1]==s[2] && s[2]==s[3]);
    Ans(f);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sp ' '
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;
const int mod998 = 998244353;

string S;
ll res, alp[26];

int main() {
	cin >> S;
	for (char c : S) {
		++alp[c - 'a'];
	}
	res = (ll)S.size()*(S.size() - 1) / 2 + 1;
	for (int i = 0; i < 26; ++i) {
		res -= alp[i] * (alp[i] - 1) / 2;
	}
	cout << res << endl;
}


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

int main() {
	//cout<<"GfG!";
	long int n, num;
    vector <long int> c, a;
    cin>>n;
    c.push_back(0);
    for (long int i = 0; i < n-1; i++)
    {
        cin>>num;
        a.push_back(num);
        c.push_back(0);
    }
    for (long int i = 2; i <= n; i++)
        c[a[i-2]-1]++;
    for (long int j = 0; j < c.size(); j++)
        cout<<c[j]<<endl;
    a.clear();  c.clear();
	return 0;
}

Measured memory_bytes: 6648
#include<stdio.h>

int main(void){
  int i;
  int a[50];
  int n,p,c;

  while(1){
      scanf("%d %d",&n,&p);
      if(!n && !p){break;}
      c = p;
      for(i=0;i<n;i++)a[i] = 0; //óâªàÂ¬ÎÌðú»

      i = 0;
      do{
	if(i==n)i=0;  //ÅãÌlðz¦½çÅÌlÉßé
	if(c>0){    //oÉ¬Îª éÆ«
	  a[i]++;   //óâÍ¬ÎðÐÆÂæè
	  c--;      //oÌ¬ÎªêÂ¸é
	}else{      //oÉ¬ÎªÈ¢Æ«
	  c = a[i]; //óâÌ¬ÎðoÉÚµ
	  a[i] = 0; //óâÌ¬ÎÍÈ­Èé
	}
	i++;
      }while(a[i-1]<p); //óâª·×ÄÌ¬ÎðÁÄ¢½çbreak
      printf("%d\n",i-1);      
    }
  return 0;
}

Measured memory_bytes: 408
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

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

    int size = 0;
    for (int i = 1; i*i < N*2; ++i) {
        if (N*2 == i*(i+1)) {
            size = i;
            break;
        }
    }

    if (size == 0) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    cout << N*2/size << endl;
    for (int i = 0; i < N*2/size; ++i) {
        cout << size << " ";
        int tmp = i;
        int j;
        for (j = 0; j < i; ++j) {
            cout << tmp << " ";
            tmp += size-j-1;
        }
        ++tmp;
        for (; j < size; ++j) {
            cout << tmp << " ";
            ++tmp;
        }
        cout << endl;
    }



    return 0;
}


Measured memory_bytes: 1408
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    h = [int(input()) for _ in range(N)]
    h.sort()

    ans = 1 << 30
    left = 0
    while left + K - 1 < N:
        right = left + K - 1
        d = h[right] - h[left]
        if ans > d:
            ans = d
        left += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7512
#include <stdio.h>
int main(void){
  int x,y,r,W,H;
  scanf("%d %d %d %d %d\n",&W,&H,&x,&y,&r);
  if(x >= r && y >= r && x+r <= W && y+r <= H){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 2104
package main

import (
	"fmt"
	"math"
)

// MOD ...
var MOD int64 = int64(math.Pow(float64(10), float64(9)) + 7)

func main() {
	var h, w int
	fmt.Scanf("%d%d", &h, &w)
	grid := make([][]rune, h)
	for i := 0; i < h; i++ {
		grid[i] = make([]rune, w)
		var line string
		fmt.Scanf("%s", &line)
		for j := 0; j < w; j++ {
			grid[i][j] = rune(line[j])
		}
	}
	ans := numberOfPath(h, w, grid)
	fmt.Println(ans)
}

func numberOfPath(h int, w int, grid [][]rune) int {
	dp := createTable(h-1, w-1)
	for i := 0; i < w; i++ {
		if grid[0][i] == '#' {
			break
		}
		dp[0][i] = 1
	}
	for i := 0; i < h; i++ {
		if grid[i][0] == '#' {
			break
		}
		dp[i][0] = 1
	}

	for i := 1; i < h; i++ {
		for j := 1; j < w; j++ {
			if grid[i][j] == '.' {
				dp[i][j] = int(int64(dp[i-1][j]+dp[i][j-1]) % MOD)
			}
		}
	}
	return dp[h-1][w-1]
}

func createTable(n int, m int) [][]int {
	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, m+1)
	}
	dp[0][0] = 0
	return dp
}


Measured memory_bytes: 14648
#include<iostream>
#include<string.h>
using namespace std;

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

  if(S[K-1]=='A') S[K-1]='a';
  if(S[K-1]=='B') S[K-1]='b';
  if(S[K-1]=='C') S[K-1]='c';
  
  cout<<S<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int[] n = SpRead(' ').Select(a => int.Parse(a)).ToArray();
        int N = 0;
        if (n[0] == 0) N = 1;
        else if (n[0] == 1) N = 100;
        else if (n[0] == 2) N = 10000;
        int ans = N * n[1];
        if (n[1] == 100) ans = N * (n[1] + 1);
        Console.WriteLine(ans);
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }

}


Measured memory_bytes: 13268
#include<stdio.h>
int main()
{
	int n,m,s=0;
	scanf("%d%d",&n,&m);
	if(n%2==0)
	{
		if(m%2==0)
		s=n/2*(n-1)+m/2*(m-1);
		else
		s=n/2*(n-1)+m*(m-1)/2;
	}
	else
	{
		if(m%2==0)
		s=n*(n-1)/2+m/2*(m-1);
		else
		s=n*(n-1)/2+m*(m-1)/2;
	}
	printf("%d\n",s);
	return 0;
 } 

Measured memory_bytes: 128
//-----------------------------B-I-G------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define what_is(x) cerr << #x << " is " << x << endl;
const ll M = 1000000007;

void solve(){
    ll a,b,k,one,two,ans;
    cin >> k >> a >> b;
    one = b/k - (a-1)/k;
    if( one >= 1 ){
      cout << "OK" << endl;
    }else{
      cout << "NG" << endl;
    }

}

signed main(){
    fast;
    ll t=1;
    // cin >> t;
    while( t-- )
        solve();
    return 0;
}
//-----------------------------B-I-G------------------------------------------------

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    ll m;
    cin >> m;
    cout << 24 - m + 24 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n;
    cin >> n;
    int t, a;
    ll taka = 1;
    ll ao = 1;
    for (int i = 0; i < n; i++)
    {
        cin >> t >> a;
        ll tmp = ((taka % t) == 0 ? taka / t : taka / t + 1);
        ll hoge = ((ao % a) == 0 ? ao / a : ao / a + 1);
        ll ma = max(tmp, hoge);
        taka = ma * t;
        ao = ma * a;
    }
    cout << taka + ao << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  ll x;
  cin >> x;
  ll i=0;
  ll t=1;
  while( i < x){
     i+=t;
     //cout << i << endl;
     t++;
  }
  cout << t-1 << endl;

   return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
set<int> st;
int n,ans;
ll tmp=0,prevtmp=0;
vll a(100005);
bool b[100005];
int main(int argc,char const* argv[])
{
  cin >> n;
  ans=n;
  for(int i=0;i<n;i++)
    {
      cin >> a[i];
    }
  sort(a.begin(),a.begin()+n);
  for(int k=0;k<n-1;k++)
    {
      tmp+=a[k];
      prevtmp=tmp;
      if(2*tmp<a[k+1]) b[k]=false;
      else b[k]=true;
    }
  b[n-1]=true;
  for(int i=n-1;i>=0;i--)
    {
      if(!b[i])
	{
	  ans=n-(i+1);
	  break;
	}
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
int main(void){
  int n,count,pointer;
  scanf("%d",&n);
  int a[n];
  for(int i = 0;i < n;i++){
  	scanf("%d ",a+i);
  }
  pointer=0;
  count=0;
  while(pointer<n-1){
    if(a[pointer]==a[pointer+1]){
      count++;
      pointer++;
    }
    pointer++;
  }
  printf("%d",count);
  
  return 0;
}

Measured memory_bytes: 128
'use strict';
function main(input) {
  input = input.split('\n');

  let row1 = input[0].split(' ');
  let row2 = input[1].split(' ');
  
  let H = row1[0];
  let W = row1[1];
  let h = row2[0];
  let w = row2[1];

  let total = H * W;

  // console.log(H, W, h, w);
  console.log(total - (H * w + (W - w) * h));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<iostream>

using namespace std;

const int MAX = 7368800;

bool sieve[MAX];

int n, m;

int main () {
    while (true) {
        cin >> m >> n;

        if (m == 0 && n == 0) break;
        for (int i = 0; i < MAX; ++i) {
            sieve[i] = false;
        }

        int i = m;
        while (n > 0) {
            if (!sieve[i]) {
                n--;
                sieve[i] = true;
                for(int k = i + i; k < MAX; k += i) {
                    sieve[k] = true;
                }
            }
            ++i;
        }

        while (sieve[i]) ++i; 

        cout << i << endl;
    }
}

Measured memory_bytes: 10260
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
#define Forr(i,j,k) for(int i=j;i>=k;--i)
#define ll long long 
using namespace std;
const int N=10010,INF=0x3f3f3f3f;
template<class T>void read(T &x){
	x=0;char c=getchar();
	while(!isdigit(c))c=getchar();
	while( isdigit(c))x=x*10+c-48,c=getchar();
}
int n,X[N<<1],K,Lim,id[N<<1],sz[N<<2],m,Low;
vector<int>G[N<<2];
inline void add(int x,int y){G[y].push_back(x);}
inline void Add(int x,int y){add(x,y),add(y,x);}
inline void link(int x,int y){
	Add(x*2+1,y*2),Add(y*2+1,x*2);
}
inline void Link(int x,int y){
	add(x*2+1,y*2),add(y*2+1,x*2);
}
inline bool cmp(int a,int b){return X[a]<X[b];}
int pre[N<<2],sccno[N<<2],scc[N<<2],scc_cnt,low[N<<2],dfs_cnt;
stack<int>s;
void dfs(int u){
	low[u]=pre[u]=++dfs_cnt;
	sccno[u]=1;s.push(u);
	int S=G[u].size();
	For(i,0,S-1){
		int v=G[u][i];
		if(!pre[v])dfs(v),low[u]=min(low[u],low[v]);
		else if(sccno[v])low[u]=min(low[u],pre[v]);
	}
	if(pre[u]==low[u]){
		++scc_cnt;
		int w;
		do{
			w=s.top();s.pop();
			scc[w]=scc_cnt;sccno[w]=0;
		}while(w!=u);
	}
}
bool check(int dis){
	For(i,0,m)G[i].resize(sz[i]);
	For(i,0,2*n-1){
		For(j,max(i-10,0),min(i+10,2*n-1)){
			if(j==i)continue;
			if(abs(X[id[j]]-X[id[i]])>=dis)continue;
			if(abs(id[i]-id[j])==n)continue;
			Link(id[i],id[j]);
		}
	}
	dfs_cnt=0;scc_cnt=0;
	For(i,0,m)pre[i]=0,scc[i]=0;
	For(i,0,m)if(!pre[i])dfs(i);
	For(i,0,2*n-1)if(scc[i*2]==scc[i*2+1])return 0;
	return 1;
}
inline bool Check(int dis){
	int cnt=0,last=-INF;
	For(i,0,2*n-1){
		if(X[id[i]]-last>=dis)cnt++,last=X[id[i]];
		if(cnt==n)break;
	}
	return cnt==n;
}
void solveLim(){
	int L=0,R=Lim,ans=0;
	while(L<=R){
		int Mid=(L+R)>>1;
		if(Check(Mid))ans=Mid,L=Mid+1;
		else R=Mid-1;
	}
	Lim=ans;
}
int main(){
	read(n);Low=INF;
	For(i,0,n-1){
		read(X[i]),read(X[i+n]);
		link(i,i+n);
		Lim=max(Lim,max(X[i],X[i+n]));
		if(i)Low=min(Low,X[i]-X[i-1]);
	}
	m=4*n-1;
	For(i,0,2*n-1)id[i]=i;
	For(i,0,m)sz[i]=G[i].size();
	sort(id,id+2*n,cmp);
	solveLim();
	int L=Low,R=Lim,ans=0;
	while(L<=R){
		int Mid=(L+R)>>1;
		if(check(Mid))L=Mid+1,ans=Mid;
		else R=Mid-1;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6016
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	int n,k;
	cin>>n>>k;
	unordered_map<int,int> mp;
	rep(i,n){
		int a;
		cin>>a;
		mp[a]++;
	}
	vector<int> v;
	for (auto p: mp){
		v.push_back(p.second);
	}
	sort(all(v));

	if (v.size() <= k){
		cout<<0<<endl;
	}
	else{
		int s=0;
		rep(i, v.size() - k){
			s += v[i];
		}
		cout<<s<<endl;
	}



	return 0;
}

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

#pragma GCC optimuze("Ofast")
#pragma GCC optimuze("03")
#pragma GCC optimuze("unroll-loops")

#define F first
#define S second
#define pb push_back
#define llong long long
#define ld long double
#define int llong
#define endl '\n'

using namespace std;

const int N = 2e5 + 5;
const int M = 2e3 + 5;
const int MOD = 1e9 + 7;
const int rx[] = {1, 0, -1, 0};
const int ry[] = {0, 1, 0, -1};

int dp[N];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef ARINOCHKA
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
#endif // ARINOCHKA

    int n, k;
    cin >> n >> k;
    vector <int> a;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.pb(x);
    }

    for(int to : a) {
        dp[to] = 1;
    }

    for(int i = 1; i <= k; i++){
        if (dp[i]) continue;
        bool ok = 0;
        for(int to : a){
            if (i - to < 0) continue;
            if (dp[i - to]) continue;
            ok = 1;
        }
        dp[i] = ok;
    }

    if (dp[k]) cout << "First";
    else cout << "Second";


    return 0;


}


Measured memory_bytes: 1024
// abco54c: One-stroke Path
#include <bits/stdc++.h>

using namespace std;
using vi = vector<int>;

#define rep(i,n) for(int i=0;i<(n);i++)
#define in(x) cin>>(x)
#define oute(x) cout<<(x)<<endl

struct vertex{vi v; bool visit;};
using graph = vector<vertex>;

void dfs(graph g, int p, int distance, int &count){
  if(distance==g.size()-1){ count++; return; }
  g[p].visit = true;
  for(int c:g[p].v)
    if(!g[c].visit) dfs(g,c,distance+1,count);
  g[p].visit = false;
}

int main(){
  int n,m; in(n);in(m);
  graph g(n);
  rep(i,m){
    int a,b; in(a);in(b);
    g[--a].v.push_back(--b);
    g[b].v.push_back(a);
  }
  int count = 0;
  dfs(g,0,0,count);
  oute(count);
}

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

int main(){
 UL N,M; cin>>N>>M;
 deque<UL> Q[10];
 rep(i,M){
  UL c,X; cin>>c>>X;
  if(c==0){
   X--;
   cout<<Q[X].front()<<endl;
   Q[X].pop_front();
  }
  if(c==1){
   UL p=0;
   rep(j,N) if(Q[p].size()>Q[j].size()) p=j;
   Q[p].push_back(X);
  }
 }
 return 0;
}



Measured memory_bytes: 3152
/*#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include<bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define mp make_pair
#define len(s) s.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rocknroll cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0)
#define pq priority_queue
#define pii pair < int, int >
#define pll pair < ll, ll >
#define debug cout << " ---------------------------------------- "
#define kektor vector
#define int long long
typedef long long ll;
typedef long double ld;
typedef double dbl;
typedef unsigned long long ull;

using namespace std;

int d[300200];

signed main()
{
    rocknroll;
    int n, m;
    cin >> n >> m;
    vector<int>v(m);
    for(auto &i : v)
        cin >> i;
    sort(all(v));
    if(m == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    for(int i = 1; i < m; ++i)
    {
        d[i - 1] = v[i] - v[i - 1];
    }
    sort(d, d + m - 1);
    int k = m - n;
    int sum = 0;
    for(int i = 0; i < k; ++i)
        sum += d[i];
    cout << sum << endl;



    return 0;
}



Measured memory_bytes: 1792
#include<stdio.h>

int main(){
  int n,i,j,k,u,v;
  int M[101][101];

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      M[i][j]=0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    if(k==0)continue;
    for(j=1;j<=k;j++){
      scanf("%d",&v);
      M[u][v]=1;
    }
  }

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



Measured memory_bytes: 2108
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int gcd(int x, int y);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }


int main() {
    vector<int> num(3);
    rep(i, 3) cin >> num[i];
    sort(num.begin(), num.end());
    int ans = 0;
    while (num[0] < num[1]) {
        ans++;
        num[0] += 2;
    }
    sort(num.begin(), num.end());
    while (num[1] < num[2]) {
        ans++;
        num[1]++;
        num[0]++;
    }
    sort(num.begin(), num.end());
    if (num[0] < num[2]) {
        ans += 2;
    }
    cout << ans << endl;
    return 0;
}
/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define DB(x)            cout << '>' << #x << ':' << x << endl;
#define DB2(x,y) 	     cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define rep(i,a,b)       for (ll i = a; i < b; i++)
#define repr(i,a,b)      for (ll i = a; i >= b; i--)
#define pb               push_back
#define F                first
#define S                second
#define mp               make_pair
#define MOD              1000000007
#define MAX              1e9
#define MIN              -1e9
#define vec(i)           vector<i>
#define PLL           	 pair<ll,ll>
#define mem(a,v)         memset(a,v,sizeof(a))
#define pf               printf
#define sc               scanf
#define _s               "%s"
#define _d               "%d"
#define _ll              "%lld"
#define _c               "%c"
#define FAST_IO          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(c) 		     c.begin(),c.end()
typedef int ll;
using namespace std;
int main()
{
	ll cnt=0,ind=0,j=0;
	bool f=0;
	string s,ans;
	cin>>s;
	rep(i,0,s.length())
	{
		if(s[i]=='B')
			cnt++,f=0;
		else
		{
			if(!f)
			{
				ans+=s.substr(ind,max(i-2*cnt-ind,0));
				ind=i;
				f=1;
			}
			cnt=0;
		}
	}
	ll last=s.length()-2*cnt-ind;
	ans+=s.substr(ind,max(last,0));
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  //for (int i = 0; i < n; i++) cerr << a[i] << " ";
  //cerr << endl;
  long long lo = 0, hi = 2e5 + 1;
  while (hi - lo > 1) {
    long long mid = (lo + hi) >> 1;
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += a.end() - lower_bound(a.begin(), a.end(), mid - a[i]);
    }
    if (cnt >= m) lo = mid;
    else hi = mid;
  }
  //cerr << "lo = " << lo << endl;
  long long ans = 0;
  vector<long long> sum(n + 1);
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + a[i];
  }
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    long long pos = lower_bound(a.begin(), a.end(), lo + 1 - a[i]) - a.begin();
    cnt += n - pos;
    ans += sum[n] - sum[pos] + (n - pos) * a[i];
  }
  //cerr << "ans = " << ans << endl;
  ans += lo * (m - cnt);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int inf = 2e18;  
const int mod1 = 998244353;
const int mod = 1e9 + 7;
const int nax = 500005;
int n,q,ans[nax],l,r,balls[nax],last_seen[nax];
pair<pii,int> queries[nax];
bool mywish(const pair<pii,int> &a,const pair<pii,int> &b)
  {
    return a.ff.ss < b.ff.ss;
  }
struct fenwick
{
  int pref[nax];
  void update(int pos,int delta)
   {
    while(pos<=n)
       {
        pref[pos] += delta;
        pos += (pos&-pos);
       }
   }
  int range_sum(int pos)
   {
    int sum = 0;
    while(pos)
       {
        sum += pref[pos];
        pos -= (pos&-pos);
       }
    return sum;
   } 
}f;
void solve()
 {
  cin>>n>>q;
  loop(i,1,n+1)
    {
      cin>>balls[i];
      if(!last_seen[balls[i]])
         {
          last_seen[balls[i]] = i;
          f.update(i,1);
         }
    }
  loop(i,0,q)
   {
    cin>>queries[i].ff.ff>>queries[i].ff.ss;
    queries[i].ss = i;
   }
  sort(queries,queries+q,mywish);
  int rhs = 1;
  loop(i,0,q)
   {
    int lo = queries[i].ff.ff;
    int hi = queries[i].ff.ss;
    while(rhs<=hi)
       {
         f.update(last_seen[balls[rhs]],-1);
         last_seen[balls[rhs]] = rhs;
         f.update(rhs,1);
         rhs++;
       }
    ans[queries[i].ss] = f.range_sum(hi) - f.range_sum(lo-1);
   }
  loop(i,0,q)
   cout<<ans[i]<<END;
 }
signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
  solve();
  // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
} 

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M, std::vector<long long> A){
    int count = 0;
    long long sum = accumulate(A.begin(),A.end(),0LL);
    for (long long a : A){
        if (a * 4* M >= sum) count++ ;
    }
    if (count >= M) printf("Yes\n");
    else printf("No\n");

}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

struct B {
    int l, r;
};

int main() {
    int n;
    cin >> n;
    vector<string> ss;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        ss.push_back(s);
    }
    vector<B> bs;
    for (auto &s: ss) {
        B b = {0, 0};
        int re = 0;
        for (int i = 0; i < s.size(); i++) {
            // cout << "s[i] = " << s[i] << endl;
            if (s[i] == '(') {
                // cout << "re++" << endl;
                re++;
            } else if (re == 0) {
                b.l++;
            } else {
                re--;
            }
            // printf("re = %d\n", re);
        }
        re = 0;
        for (int i = s.size() - 1; i >= 0; i--) {
            if (s[i] == ')') {
                re++;
            } else if (re == 0) {
                b.r++;
            } else {
                re--;
            }
        }
        bs.push_back(b);
    }
    int sum = 0;
    int a0 = false, l0 = false, r0 = false;
    vector<B> left, right;
    for (auto b: bs) {
        // printf("l = %d, r = %d\n", b.l, b.r);
        sum -= b.l;
        sum += b.r;
        if (b.l < b.r) {
            left.push_back(b);
        } else {
            right.push_back(b);
        }
    }
    sort(left.begin(), left.end(), [](B x, B y) {
        return x.l < y.l;
    });
    sort(right.begin(), right.end(), [](B x, B y) {
        return x.r > y.r;
    });
    int p = 0;
    bool ok = true;
    for (auto b: left) {
        p -= b.l;
        if (p < 0) {ok = false;}
        p += b.r;
    }
    for (auto b: right) {
        p -= b.l;
        if (p < 0) {ok = false;}
        p += b.r;
    }
    if (sum == 0 && ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 54412
import math
n = int(input())
while 1 > 0:
    if n == 2 or n ==3:
        break
    k = 0
    l = 0
    r = int(math.sqrt(n) // 1)
    for i in range(2, r + 1):
        if n % i == 0:
            k = 1
        if i == r:
            if k == 0:
                l = 1
    if l == 1:
        break
    else:
        n += 1

print(n)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N; ll M; int V, P; cin >> N >> M >> V >> P;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    sort(all(A));
    int ub = N-P;
    int lb = -1;
    int mid;
    while(ub-lb>1) {
        mid = (ub+lb)/2;
        vector<ll> B(A);
        ll W = (ll)V*M;
        for(int i=mid; i>=0; i--){
            B[i] += min(M,W);
            W -= min(M,W);
        }
        for(int i=N-P+1; i<N; i++) {
            B[i] += min(M,W);
            W -= min(M,W);
        }
		bool flag = true;
        for(int i=mid+1; i<=N-P; i++){
            if (B[i]>B[mid]) {flag = false; break;}
            ll tmp = min(max(0LL,B[mid]-B[i]),min(M,W));
            B[i] += tmp;
            W -= tmp;
        }
        if(flag && W==0) ub = mid;
        else lb = mid;
    }
    cout << N - ub << endl;
    return 0;
}

Measured memory_bytes: 1920
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<set>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define mp make_pair
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
void outn(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(10);
}
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
//const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll quickpow(ll x, ll k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}

const int maxn = 1e5 + 5;
int par[maxn], r[maxn];
int findp(int x)
{
    if (par[x] < 0) return x;
    else{
        int fx = findp(par[x]);
        r[x] = (r[x] + r[par[x]]) % 2;
        par[x] = fx;
    }
}
void unite(int x, int y)
{
    int fx = findp(x), fy = findp(y);
    if (fx != fy){
        r[x] = (r[x] - r[y] + 1) % 2;
        par[fy] = fx;
    }
}
bool same(int x, int y){return findp(x) == findp(y);}
vector<string> vs;
int main()
{
    int n, l;
    cin >> n >> l;
    while (n--){
        string s;
        cin >> s;
        vs.push_back(s);
    }
    sort(vs.begin(), vs.end());
    for (auto e : vs){
        cout << e;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    long long int n,a,b, sum = 0;
    cin>>n>>a>>b;

    long long int d = a + b;
    
        long long int e = n/d;
        long long int f = n%d;

        sum = sum + (e*a) + min(a, f);
        cout<<sum<<"\n";

    
	return 0; 
} 


Measured memory_bytes: 256
//65 - A 90 - Z 97 - a 122 - z
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

LL a, b, c, d, n, res;
LL b1 = 1000000007;

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

    cin >> a >> b >> c >> d >> n;
    b1 = min({4 * a, 2 * b, c, b1});
    if(2 * b1 < d)
        res += (n / 2) * 2 * b1;
    else res += (n / 2) * d;
    n %= 2;
    res += n * b1;
    cout << res;
    return 0;
}


Measured memory_bytes: 256