akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n:usize,
        a:[u64; n],
    }
    let mut sum=0;
    for i in 0..n {
        sum+=a[i]-1;
    }
    println!("{}", sum);
}

Measured memory_bytes: 4352
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int x,i=1;
    
    while(1){
        scanf("%d",&x);
        if(x==0){
            break;
        }
        printf("Case %d: %d\n",i,x);
        i++;
    }
    return 0;
}



Measured memory_bytes: 2036
import Foundation

func readInt() -> Int {
    return Int(readLine()!)!
}

func readString() -> String {
    return readLine()!
}

func readLines(times: Int) -> [String] {
    var array = [String]()
    for _ in 0..<times {
        array.append(readLine()!)
    }
    return array
}

func readSeparatedStrings() -> [String] {
    return readLine()!.split(separator: " ").map({String($0)})
}

func readStringToStrings() -> [String] {
    return readLine()!.map({String($0)})
}

func readSeparatedInts() -> [Int] {
    return readLine()!.split(separator: " ").map({Int($0)!})
}
func readSeparatedDouble() -> [Double] {
    return readLine()!.split(separator: " ").map({Double($0)!/100000})
}

let N = readInt()
let numbers = readSeparatedInts()
var _numbers = [Int]()
for n in 0..<N {
    if n % 2 == 0 {
        if numbers[n] % 2 == 1 {
            _numbers.append(numbers[n])
        }
    }
}
print(_numbers.count)



Measured memory_bytes: 13508
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define INF 0x3f3f3f3f 
#define MEM(x,y) memset(x,y,sizeof(x))
#define int long long
#define rep(i , a , b) for(int i = a ; i <= b ; i ++)
#define P pair<int,int>
#define  sc(a) scanf("%lld",&a)
#define pf(a) printf("%lld ",a)
using namespace std;
string  s;
signed main()
{
	int n;
	sc(n);
	int a, b;
	sc(a);
	sc(b);
	int ans = n / (a + b)*a + min(n % (a + b), a);
	cout << ans;
}










Measured memory_bytes: 256
def dfs(l):
    x = len(l[0])
    if l[0][-1] == "+":
        b = 0
        i = 1
        while i < len(l):
            if len(l[i]) == x + 1 and "0" <= l[i][-1] <= "9":
                b += int(l[i][-1])
                i += 1
            elif len(l[i]) == x + 1 and (l[i][-1] == "+" or l[i][-1] == "*"):
                f = i
                i += 1
                while i < len(l):
                    if len(l[i]) == x + 1:
                        break
                    i += 1
                b += dfs(l[f:i])

    elif l[0][-1] == "*":
        b = 1
        i = 1
        while i < len(l):
            if len(l[i]) == x + 1 and "0" <= l[i][-1] <= "9":
                b *= int(l[i][-1])
                i += 1
            elif len(l[i]) == x + 1 and (l[i][-1] == "+" or l[i][-1] == "*"):
                f = i
                i += 1
                while i < len(l):
                    if len(l[i]) == x + 1:
                        break
                    i += 1
                b *= dfs(l[f:i])
    else:
        b = int(l[0][-1])

    return b

def main(n):
    l = [input() for i in range(n)]
    print(dfs(l))

while 1:
    n = int(input())
    if n == 0:
        break
    main(n)


Measured memory_bytes: 5612
import sys
input = sys.stdin.readline

def main():
    H, W, d = map(int, input().split())
    d2 = d * 2
    for i in range(H):
        for j in range(W):
            x = (i+j) % d2
            y = (i-j) % d2
            if x < d:
                if y < d:
                    print("R", end="")
                else:
                    print("Y", end="")
            else:
                if y < d:
                    print("G", end="")
                else:
                    print("B", end="")
        print()


if __name__ == "__main__":
    main()

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

int main(){
  unsigned long N;
  cin >> N;
  vector<long> a(N);
  for(auto& i : a)cin >> i;
  long C;
  cin >> C;
  long u{C};
  for(const auto i : a)u = __gcd(u, abs(i));

  vector<long> sieve(31622, 1);
  for(long i = 2; i < 31622; ++i)if(sieve[i]){
    if(u % i == 0 && cout << i << endl)
      while(u % i == 0)u /= i;
    else if(C % i == 0 && i <= N){
      vector<long> v(i);
      for(unsigned long j = 0, k = 0; j < N; ++j, k = k == i - 2 ? 0 : ++k)v[k] += a[j];
      if(none_of(v.begin(), v.end(), [&i](auto x){return x % i;}))cout << i << endl;
    }
    for(auto j = i * i; j < 31622; j += i)sieve[j] = 0;
  }
  if(u ^ 1)cout << u << endl;
}

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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair

typedef long long LL;
typedef pair<int,int> Interval;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){
    os << v.first <<" "<<v.second<<endl;
    return os;
}

const int mod = 1e9+7;
const int maxn = 1e5+5;
const int maxh = 2e3+5;

int N,M;
vector<int> A;
vector<int> B;

int dp[maxh][maxh];

int add(LL a,LL b){return (int)((a+b)%mod);}
int sub(LL a,LL b){return (int)((a-b+mod)%mod);}

int main()
{
    cin >> N >> M;
    _for(i,0,N){
        int num;
        scanf("%d",&num);
        A.push_back(num);
    }
    _for(i,0,M){
        int num;
        scanf("%d",&num);
        B.push_back(num);
    }
    _rep(i,0,N){
        dp[0][i] = 1;
    }
    _rep(i,0,M){
        dp[i][0] = 1;
    }

    _rep(i,1,M){
        _rep(j,1,N){
            if(B[i-1] == A[j-1]){
                dp[i][j] = add(dp[i-1][j],dp[i][j-1]);
            }
            else{
                dp[i][j] = add(dp[i-1][j],dp[i][j-1]);
                dp[i][j] = sub(dp[i][j],dp[i-1][j-1]);
            }
        }
    }
    /*
    _rep(i,0,M){
        _rep(j,0,N){
            printf("%d ",dp[i][j]);
        }
        printf("\n");
    }
    */
    cout << dp[M][N] << endl;
    return 0;
}

Measured memory_bytes: 16000
#include<iostream>
using namespace std;
int main(){
  int ans=0;
  char a,b,c,d,e,f;
  cin >> a >> b >> c;
  cin >> d >> e >> f;
  if(a==d){
    ans++;
  }
  if(b==e){
    ans++;
  }
  if(c==f){
    ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

struct edge{
	int v,id;
	edge(int v, int id):v(v),id(id){};
};

vector<edge>adj[55];
vector<int>path;

bool dfs(int u, int target, int p=-1){
	if(u==target)return 1;
	for(edge e:adj[u]){
		int v = e.v, id = e.id;
		if(v==p)continue;
		if(dfs(v,target,u)){
			path.eb(id);
			return 1;
		}
	}
	return 0;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	for(int i=0; i<n-1; i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		adj[a].eb(b,i);
		adj[b].eb(a,i);
	}
	int m; cin >> m;
	vector<ll>idd(m);
	for(int i=0; i<m; i++){
		int u,v;
		cin >> u >> v;
		u--; v--;
		path=vector<int>();
		dfs(u,v);
		for(int id:path)
			idd[i]|=(1LL<<id);
	}
	ll ans = 0LL;
	for(ll i=0LL; i<(1<<m); i++){
		ll mask = 0LL;
		for(int j=0; j<m; j++){
			if(i>>j&1) mask |= idd[j];
		}
		int white = __builtin_popcountll(mask);
		ll now = 1LL<<(n-1-white); // cnt # of edges that're not used
		if(__builtin_popcountll(i)%2==0)ans += now;
		else ans -= now;
	}
	cout << ans << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << 
 << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

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

int main() {
    LL n,m;
    cin >> n >> m;
    if (n * 2 >= m) cout << m / 2 << endl;
    else {
        m -= n * 2;
        cout << n + m / 4 << endl;
    }
    
    return 0;
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N; cin >> N;
    VI A(N); REP(i,N) cin >> A[i];
    REVERSE(A);
    VI dp(N,INT_INF);
    REP(i,N){
        int it = UB(dp, A[i]);
        chmin(dp[it], A[i]);
    }
    int ans = 0;
    REP(i,N){
        if(dp[i] == INT_INF) break;
        ans = i+1;
    }
    cout << ans << en;
    return 0;
}

Measured memory_bytes: 1024
n  = int(input())
ps = []

for _ in range(0, n):
  x, l = [int(y) for y in input().split()]
  ps.append((x + l, x - l))

ps.sort()

x = ps[0][0]
d = 0

for i in range(1, n):
  p = ps[i]
  
  if p[1] < x:
    d += 1
  else:
    x = p[0]

print(n - d)


Measured memory_bytes: 16928
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiWayIf       #-}
main :: IO ()
main = do
  x <- readLn :: IO Int
  let y = (x `div` 11) * 2
      z = x `mod` 11
  print $ if | z == 0 -> y
             | z > 0 && z <= 6 -> y + 1
             | otherwise -> y + 2


Measured memory_bytes: 3820
/*
▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
 
*/
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <iomanip>
#include <random>

 
using namespace std;
 
 
 
#define ll long long
#define ld double
#define null NULL
#define prev prev228
#define index index228
#define left left228
#define right right228
#define hash hash228
#define y1 y1228
#define firn(i, n) for (int i = 0; i < (int)n; ++i)
#define forn(i, n) for (int i = 1; i <= (int)n; ++i)
#define int long long


template<typename T> inline void uin(T &a, T b) {
    if (b < a) a = b;
}

template<typename T> inline void uax(T &a, T b) {
    if (b > a) a = b;
}




signed main() {
	ios_base::sync_with_stdio(false);
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int mn = min(x, y);
	int solvea = a;
	int solveb = b;
	uin(solvea, 2 * c);
	uin(solveb, 2 * c);
	int res1 = mn * 2 * c + (x - mn) * solvea + (y - mn) * solveb;
	int res2 = x * solvea + y * solveb;
	cout << min(res1, res2) << "\n";
	return 0;
}






// kek



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;

int main(){
  ll N;
  cin >> N;
  vector<ll> h(N);
  for (int i = 0; i < N; i++) cin >> h[i];

  ll out = 0;
  bool check = true;
  while (check) {
    int i = 0;
    check = false;
    while (i < N) {
      if(h[i]>0){
        out++;
        check = true;
        for (i; h[i] > 0; i++) h[i]--;
      }
      i++;
    }
  }
  cout << out << endl;
  return 0;
}

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

struct tup {
    int cst, idx;
    bool isW;
    tup() : cst(0), idx(0), isW(false) {}
    tup(int cst, int idx, bool isW) : cst(cst), idx(idx), isW(isW) {}
    bool operator<(const tup &t) const {
        return cst < t.cst;
    }
};

struct UnionFind {
    vector<int> parent;
    long long __size;
    UnionFind(int size_) : parent(size_, -1), __size(size_) {}
    bool unite(int x,int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            __size--;
            return true;
        }
        return false;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x){ return -parent[find(x)]; }
    long long size(){ return __size; }
};

int W, H;
long long res;
vector<tup> v;

int main() {

    cin >> W >> H;

    REP(i, W) {
        int p; cin >> p;
        v.emplace_back(tup(p, i, true));
    }
    REP(i, H) {
        int p; cin >> p;
        v.emplace_back(tup(p, i, false));
    }
    sort(v.begin(), v.end());

    UnionFind uf_h(H + 1), uf_w(W + 1);

    for (auto& e : v) {
        if (uf_h.size() == 1 and uf_w.size() == 1) break;
        if (e.isW) {
            res += uf_h.size() * e.cst;
            uf_w.unite(e.idx, e.idx + 1);
        } else {
            res += uf_w.size() * e.cst;
            uf_h.unite(e.idx, e.idx + 1);
        }
    }
    
    cout << res << endl;

}


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

using namespace std;

int main(){
    int N,count=0;
    cin >> N;
    for(int p = 1;p<N;p++){
        for(int q = 1;q <= p;q++){
            if((p*q)>=N)break;
            for(int r = 1;true;r++){
                if((p*q+r)==N){
                    if(p==q)count++;
                    else count += 2;
                    break;
                }
            }
        }
    }
    cout << count << "\n";
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {

    int x;
    cin >> x;

    // 1 2 3 4 5 6
    // i で i jump
    // 1+2 = 3
    // 1+3 = 4
    // 2+3 = 5
    // 2+5 = 6
    // tまでの総和 = (t*(t+1))/2
    // (t * (t+1)) /2

    for (int i = 1; i <= 10e9; ++i) {

        if ((i*(i+1))/2 >= x) {
            cout << i << endl;
            return 0;
        }
    }

    return -1; 
}

Measured memory_bytes: 256
import math
from itertools import combinations
n, d = map(int, input().split())

def is_distance_int(y, z):
    ans = 0
    for i, j in zip(y, z):
        ans += (i-j)**2
    for k in range(1, ans+1):
        if k**2 == ans:
            return 1
    return 0

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

c = [i for i in range(n)]
c = combinations(c, 2)

ans = 0
for i, j in c:
    ans += is_distance_int(x[i], x[j])

print(ans)

Measured memory_bytes: 9044
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  int n;
  cin >> n;
  double x[n],y[n];
  int p[n];
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    p[i] = i;
  }
  double ans = 0.0;
  int count = 0;
  do{
    count++;
  	for(int i = 0;i < n-1;i++){
      ans += sqrt((x[p[i]]-x[p[i+1]])*(x[p[i]]-x[p[i+1]])+(y[p[i]]-y[p[i+1]])*(y[p[i]]-y[p[i+1]]));
    }
  }while(next_permutation(p,p+n));
  cout << fixed << (ans/count) << endl;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

ll dp[11][310][11];

int main()
{
    cout << fixed << setprecision(15);
    ll N, W;
    cin >> N >> W;

    vector<ll> w(N);
    vector<ll> v(N);

    REP(i, N){
        cin >> w[i] >> v[i];
    }

    ll k = w[0];
    ll a = 0;
    ll b = 0;
    ll c = 0;
    ll d = 0;

    vector<ll> A(N, 0);
    vector<ll> B(N, 0);
    vector<ll> C(N, 0);
    vector<ll> D(N, 0);

    REP(i, N){
        if(w[i] == k){
            A[a] = v[i];
            a++;
        }
        if(w[i] == k+1){
            B[b] = v[i];
            b++;
        }
        if(w[i] == k+2){
            C[c] = v[i];
            c++;
        }
        if(w[i] == k+3){
            D[d] = v[i];
            d++;
        }
    }
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());
    sort(D.rbegin(), D.rend());

    vector<ll> A2(a+1, 0);
    vector<ll> B2(b+1, 0);
    vector<ll> C2(c+1, 0);
    vector<ll> D2(d+1, 0);

    REP(i, a+1){
        if(i==0){
            A2[i] = 0;
            continue;
        }
        A2[i] = A2[i-1] + A[i-1];
    }
    REP(i, b+1){
        if(i==0){
            B2[i] = 0;
            continue;
        }
        B2[i] = B2[i-1] + B[i-1];
    }
    REP(i, c+1){
        if(i==0){
            C2[i] = 0;
            continue;
        }
        C2[i] = C2[i-1] + C[i-1];
    }
    REP(i, d+1){
        if(i==0){
            D2[i] = 0;
            continue;
        }
        D2[i] = D2[i-1] + D[i-1];
    }
    // cout << A2[1]+C2[1] << endl;
    ll ans = 0;
    REP(p, a+1){
        REP(q, b+1){
            REP(r, c+1){
                REP(s, d+1){
                    if(k*p + (k+1)*q + (k+2)*r + (k+3)*s > W) continue;
                    ans = max(ans, A2[p]+B2[q]+C2[r]+D2[s]);
                    // cout << "i:" << i << " j:" << j << " k:" << k << " l:" << l << " " << ans << endl;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    loop {
        let n: usize = sc.get();
        let x: usize = sc.get();
        if n == 0 && x == 0 {
            break;
        }
        let mut ans = 0;
        for i in 1..n-1 {
            for j in i+1..n {
                for k in j+1..n+1 {
                    if i + j + k == x {
                        ans += 1;
                    }
                }
            }
        }
        println!("{}", ans);
    }
}



Measured memory_bytes: 5036
#include <cstdio>
#include <vector>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> four(3);
  for (size_t i = 0; i < N; ++i) {
    int a;
    scanf("%d", &a);
    if (a % 4 == 0) {
      ++four[2];
    } else if (a % 4 == 2) {
      ++four[1];
    } else {
      ++four[0];
    }
  }

  if (four[0] > four[2]+1)
    return puts("No"), 0;

  if (four[0] == four[2]+1 && four[1])
    return puts("No"), 0;

  puts("Yes");
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Varun
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
    StringTokenizer st = new StringTokenizer(br.readLine());
   // BigInteger a = new BigInteger(st.nextToken());
     final BigDecimal a = new BigDecimal( st.nextToken() );
    final BigDecimal orig = new BigDecimal( st.nextToken() );
    //BigInteger c = new BigInteger(String.valueOf(b));
    //BigInteger d = a.multiply(c);
    //System.out.println(orig);
   BigDecimal res = a.multiply(orig);
   System.out.println(res.toBigInteger().longValueExact());
   
   // System.out.printf("%.f",res);
    
    }
    
}


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

int main() {
  string s, t; cin >> s >> t;

  s.push_back(t.back());
  if (s == t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3628
public class Main {
  private static void solve() {
    char[] s = ns();
    int n = s.length;
    if (s[0] != s[n - 1]) {
      System.out.println(n % 2 == 0 ? "Second" : "First");
    } else {
      System.out.println(n % 2 == 1 ? "Second" : "First");
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 27348
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {
        FastReader fastReader = new FastReader();
        int H1 = fastReader.nextInt();
        int M1 = fastReader.nextInt();
        int H2 = fastReader.nextInt();
        int M2 = fastReader.nextInt();
        int K = fastReader.nextInt();
        int minutes = (H2 * 60 + M2) - (H1 * 60 + M1);
        System.out.println(minutes - K);
    }


}

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



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

    int a, b, c;
    cin >> a >> b >> c;
    a + b + c >= 22 ? cout << "bust" : cout << "win";


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vvchar vector<vector<char>>
#define vchar vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vint dp(1e7+1,0);
    for(int i=1; i<=n; i++){
        for(int j=i; j<=n; j+=i){
            dp[j]++;
        }
    }
    int res=0;
    for(int i=1; i<=n; i++){
        res+=i*dp[i];
    }
    cout<<res<<endl;
    

    


}

Measured memory_bytes: 81320
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <time.h>
#include <ctype.h>

int cmp(const void *a, const void *b) { return *(int*)a - *(int*)b; }
int max(int a, int b) { return a >= b ? a : b; }
int min(int a, int b) { return a <= b ? a : b; }
int dsum(int x) { int r=0; while(x){ r+=(x%10); x/=10; } return r;}
void swap(int *a, int *b) { int tmp; tmp = *a; *a = *b; *b = tmp; return; }

int main(void) {
  int a,b;
  while(scanf("%d%d",&a,&b) != EOF) {
    printf("%d\n",a-b);
  }
  return 0;
}


Measured memory_bytes: 2052
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long ans = 0;
        if(n < m/2){
            ans += n;
            m -= n * 2;
            ans += m / 4;
        }else{
            ans += m / 2;
        }

        System.out.println(ans);
        sc.close();
    }

}


Measured memory_bytes: 21716
from collections import Counter

def prime(n):
    for a in range(2,int(n**0.5)+1):
        if n%a==0:
            return False
    return True

N = int(input())
nums = [int(input()) for i in range(N)]
Nums = Counter(nums)
c = 0
for a in Nums.keys():
    if prime(a):
        c += Nums[a]
print(c)


Measured memory_bytes: 6944
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	while (true) {
		int n,m;
		std::cin >> n >> m;
		if(n==0&&m==0) break;
		std::vector<int> t(n);
		std::vector<int> h(m);
		int tsum = 0;
		int hsum = 0;
		rep(i,n) {
			std::cin >> t[i];
			tsum += t[i];
		}
		rep(i,m) {
			std::cin >> h[i];
			hsum += h[i];
		}
		int diff = hsum-tsum;
		rep(i,n) {
			rep(j,m) {
				if(2*(h[j]-t[i])==diff) {
					std::cout << t[i] << " " << h[j] << ENDL;
					goto stop;
				}
			}
		}
		print(-1);
stop:;
	}
	return 0;
}



Measured memory_bytes: 3112
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class Task {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            long a = in.nextLong(), b = in.nextLong(), n = in.nextLong();
            long x = Math.min(n, b - 1);
            out.println(a * x / b - a * (x / b));
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public long nextLong() {
            long ret = 0;
            int c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

    }
}



Measured memory_bytes: 32348
//////// Multiple_of_9 
// https://atcoder.jp/contests/abc176/tasks/abc176_b
// date: 2020-08-22T21:00:10.586803
// memo: 
    
//<editor-fold desc="my macro">

#include<bits/stdc++.h>
#ifdef LOCAL
    #include<my/dump.h>
#else
    #define dump(...) 42 
    #define dumpi(x) 42 
#endif

typedef long long ll;
using namespace std;

#define foe(x, a) for(auto& (x) : (a))
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rep3(i, a, b) for(ll i=a, i##_len=(b);i<i##_len;i++)
#define _rep2(i, n) _rep3(i,0,n)
#define repd(...) _overload3(__VA_ARGS__,_repd3,_repd2,)(__VA_ARGS__)
#define _repd3(i, a, b) for(ll i=b-1, i##_len=(a);i>=i##_len;i--)
#define _repd2(i, n) _repd3(i,0,n)
#define loop(...) _overload3(__VA_ARGS__,,_loop2,_loop1)(__VA_ARGS__)
#define _loop2(i, a) for(ll i=a;; i++)
#define _loop1(i) _loop2(i,0)

#define all(x) x.begin(),x.end()
#define SIZE(x) ((ll)(x).size())

#define pb(a) push_back(a)
#define mp make_pair
#define F first
#define S second
#define vec vector
#define umap unordered_map
#define uset unordered_set

ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename T, typename ...Args>
void ci(T& first, Args&... args) {
    ((cin >> first), ..., (cin >> args)); //C++17
}

template<char Sep, typename T, typename ...Args>
void print_seq(const T& first, const Args&... args) {
    ((cout << first), ..., (cout << Sep << args)); //C++17
}

void co(){ cout << endl; }
template<typename... Words>
void co(Words... words) {
    print_seq<' '>(words...);
    cout << endl;
}
#define coi(x) cout<<(x)<<" "

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define sankou(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define asrt(expr...) assert((expr))
//</editor-fold>

#define INF 1e19
#define MOD 1e9+7
#define MAXR 1e5

int solve() {
    string s;
    ci(s);
    ll sum=0;
    rep(i,s.size()) {
        sum += (int)(s[i]-48);
        dump(s[i],(int)s[i],(int)(s[i]-48));
    }
    Yes(sum % 9 == 0);
    dump(s, sum);
    return 0;
}

int main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    
    solve();
    return 0;
}


Measured memory_bytes: 3756
//If you are trying to hack me I wish you can get it, Good Luck :D.
#include <bits/stdc++.h>
using namespace std;

#define debug(args...) fprintf (stderr,args)
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX = 2123;
const int INF = 0x3f3f3f3f;
const ll  MOD = 1000000007;

vector<int> adj[MAX];
int dist[MAX][MAX];
int ans[MAX];
int n, x, y;

void build_graph() {
   for (int i = 1; i < n; i++) {
      adj[i].pb(i + 1);
      adj[i + 1].pb(i);
   }
   adj[x].pb(y);
   adj[y].pb(x);
}

void bfs(int source) {
   queue<int> Q;
   Q.push(source);
   dist[source][source] = 0;

   while (!Q.empty()) {
      int u = Q.front();
      Q.pop();

      for (int v : adj[u]) {
         if (dist[source][u] + 1 < dist[source][v]) {
            dist[source][v] = dist[source][u] + 1;
            Q.push(v);
         }
      }
   }
}

int main() {
   memset(dist, INF, sizeof(dist));
   cin >> n >> x >> y;
   build_graph();
   for (int i = 1; i <= n; i++) bfs(i);

   for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
         ans[dist[i][j]]++;
      }
   }

   for (int i = 1; i < n; i++) {
      cout << ans[i] << '\n';
   }
}


Measured memory_bytes: 17920
n = int(input())
s = input()

num = 0
lmax = 0
rmax = 0
for i in range(n):
    if s[i] == ")":
        num += 1
    else:
        num -= 1
    lmax = max(lmax, num)

num = 0
for i in range(n-1, -1, -1):
    if s[i] == "(":
        num += 1
    else:
        num -= 1
    rmax = max(rmax, num)

print("("*lmax + s + ")"*rmax)

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using Pair = pair<int, int>;
const ll mod = 1e9 + 7;

int main(int argc, char const* argv[])
{
  int n, k;
  cin >> n >> k;
  priority_queue<int, vector<int>, less<int>> q;

  REP(i, n) {
    int h;
    cin >> h;
    q.push(h);
  }
  for (int i = 0; i < min(k, n); i++) {
    q.pop();
  }
  ll ans = 0;
  while(q.size()) {
    ans += (ll)q.top();
    q.pop();
  }

  cout << ans << endl;

  return 0;
}

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

bool solve() {
    int N;
    cin >> N;
    vector<int> X(N+1);
    for ( int i = 1; i <= N; i++ ) {
        cin >> X[i];
    }
    vector<pair<int,int>> xi;
    for ( int i = 1; i <= N; i++ ) {
        xi.emplace_back(X[i], i);
    }
    sort(xi.begin(), xi.end());
    vector<int> ans(N*N+1);
    for ( int i = 1; i <= N; i++ ) {
        ans[X[i]] = i;
    }
    int h = 1;
    for ( int k = 0; k < N; k++ ) {
        int x = xi[k].first;
        int i = xi[k].second;
        for ( int j = 0; j < i-1; j++ ) {
            while( h < x && ans[h] > 0 ) h++;
            if ( h >= x ) return false;
            ans[h] = i;
            h++;
        }
    }
    h = N*N;
    for ( int k = N-1; k >= 0; k-- ) {
        int x = xi[k].first;
        int i = xi[k].second;
        for ( int j = i; j < N; j++ ) {
            while( h > x && ans[h] > 0 ) h--;
            if ( h <= x ) return false;
            ans[h] = i;
            h--;
        }
    }
    cout << "Yes" << "\n";
    for ( int i = 1; i <= N*N; i++ ) {
        cout << (i != 1 ? " " : "") << ans[i];
    }
    cout << "\n";
    return true;
}

int main() {
    auto ans = solve();
    if ( !ans ) cout << "No" << "\n";
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define PI 3.141592653589793
#define endl "\n"

struct COM{
  ll modpow(ll x, ll nn){
    ll res = 1;
    while(nn > 0){
      if(nn & 1) res = res * x % MOD;
      x = x * x % MOD;
      nn >>= 1;
    }
    return res;
  }
  vll fact, ifact;
  COM(ll n): fact(n+1), ifact(n+1){
    assert(n < MOD);
    fact[0] = 1LL;
    for(ll i = 1; i <= n; i++) fact[i] = fact[i-1]*i%MOD;
    ifact[n] = modpow(fact[n], MOD-2);
    for(ll i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i%MOD;
  }
  ll operator()(int n, int k){
    if(k < 0 || k > n) return 0;
    return fact[n]*ifact[k]%MOD*ifact[n-k]%MOD;
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  COM c(100);
  ll N, K;
  cin >> N >> K;
  ll maxi = c(N-1, 2);
  if(K > maxi){
    cout << -1 << endl;
    return 0;
  }
  ll del = maxi - K;
  cout << N-1 + del << endl;
  for(int i = 2; i <= N; i++){
    cout << 1 << ' ' << i << endl;
  }
  if(del == 0) return 0;
  ll counter = 0;
  for(int i = 2; i <= N-1; i++){
    for(int j = i+1; j <= N; j++){
      cout << i << ' ' << j << endl;
      counter++;
      if(counter == del) return 0;
    }
  }
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ll n, c, k;
    cin >> n >> c >> k;
    vi t(n);
    rep(i, n) {
        cin >> t[i];
    }

    sort(all(t));

    int ans = 0;
    rep(i, n) {
        int i_ = i;
        int now = 0;
        while(i != n) {
            if(now == c or t[i] - t[i_] > k) {
                --i;
                break;
            }
            ++now;
            ++i;
        }
        //cout << i << endl;
        ans++;
    }

    cout << ans << endl;
}

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

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  struct pos {
    int x;
    int y;
  };
  int n;
  cin >> n;
  vector<pos> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].x >> a[i].y;
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i].x >> b[i].y;
  }
  sort(a.begin(), a.end(),
       [](const pos& l, const pos& r) { return l.y > r.y; });
  sort(b.begin(), b.end(),
       [](const pos& l, const pos& r) { return l.x < r.x; });
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (size_t j = 0; j < a.size(); ++j) {
      if (a[j].x < b[i].x && a[j].y < b[i].y) {
        ++ans;
        auto it = a.begin();
        advance(it, j);
        a.erase(it);
        break;
      }
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Work> works = new ArrayList<Work>();
		for (int i=0; i<n; i++) {
			works.add(new Main().new Work(sc.nextInt(), sc.nextInt()));
		}

		Collections.sort(works, new java.util.Comparator<Work>() {

			@Override
			public int compare(Work w1, Work w2) {
				if (w1.limit > w2.limit) {
					return 1;
				} else if (w1.limit == w2.limit) {
					return 0;
				} else {
					return 1;
				}
			}
		});

		works.sort((a,b)-> a.limit - b.limit);

		long sum = 0;
		boolean valid = true;
		for (Work work : works) {
			sum += work.time;
			if (work.limit < sum) {
				valid = false;
			}
		}

		System.out.println(valid ? "Yes" : "No");

	}

	class Work {
		int time;
		int limit;

		public Work(int time, int limit) {
			this.time = time;
			this.limit = limit;
		}
	}

}

Measured memory_bytes: 118372