akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using Int = long long;
#define REP(i, n) for (int i = 0; i < n; i++)
int main()
{
    string s; cin >> s;
    cout << (s[0] == s[2] ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

int h[999];

void gen() {exit(0);}
int main() {
    #ifdef DEBUG
//    freopen("input", "r", stdin);
//    freopen("output", "w", stdout);
//    gen();
    #endif
    int a, b;
    scanf("%d %d", &a, &b);
    
    int ch = 1;
    for (int i = 0; i < 999; i++) {
        h[i] = ch;
        ch += (i + 2);
    }
    for (int x = 0; x < 998; x++) {
        if (h[x] >= a) {
            int d = h[x] - a;
            if (h[x + 1] - b == d) {
                printf("%d\n", d);
                exit(0);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long i,j,n,m,l,r,c,rez,a,b;
string s,t;
long long gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a % b);
}
int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    cin >> n >> m >> s >> t;
    if (s[0]!=t[0])
    {
        cout << "-1";
        return 0;
    }
    c=n*m/gcd(n,m);
    rez=c;
    while (rez<=n*m/gcd(n,m))
    {
        i=0;
        j=0;
        a=0;
        b=0;
        while (a<n&&b<m)
        {
            if (i<j)
            {
                i+=rez/n;
                a++;
            }
            else if (i>j)
            {
                j+=rez/m;
                b++;
            }
            else
            {
                if (s[a]!=t[b])
                {
                    i=n+7;
                    j=n+7;
                    a=n;
                    b=m;
                }
                else
                {
                    i+=rez/n;
                    a++;
                }
            }
        }
        if (i==n+7&&j==n+7)
        {
            rez+=c;
        }
        else
        {
            cout << rez;
            return 0;
        }
    }
    cout << "-1";
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using namespace std::literals;
using Int = long long;
using Double = long double;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define PUTS(x) cout << (x) << endl;
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define F first
#define S second
#define perm(c)   \
    sort(ALL(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))
#define IntsIn(v, n)                                 \
    auto v = vector<Int>(0);                         \
    for (int v##_i = 0; v##_i < (int)(n); v##_i++) { \
        Int v##_a;                                   \
        cin >> v##_a;                                \
        v.push_back(v##_a);                          \
    }
void setPrecision(int num = 20) {
    std::cout << std::fixed << std::setprecision(num);
}
template <typename T>
T Max(T a) {
    return a;
}
template <typename T, typename... Args>
T Max(T a, Args... args) {
    return std::max(Max(args...), a);
}
template <typename T>
T Min(T a) {
    return a;
}
template <typename T, typename... Args>
T Min(T a, Args... args) {
    return std::min(Min(args...), a);
}
template <typename T>
bool vector_contains(std::vector<T> vec, T value) {
    return (std::distance(vec.begin(), std::find(vec.begin(), vec.end(), value)) != vec.size());
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename... Args>
std::string format(const std::string &fmt, Args... args) {
    size_t len = std::snprintf(nullptr, 0, fmt.c_str(), args...);
    std::vector<char> buf(len + 1);
    std::snprintf(&buf[0], len + 1, fmt.c_str(), args...);
    return std::string(&buf[0], &buf[0] + len);
}
string toStringWithBase(Int value, int base) {
    auto r = value % base;
    auto q = value / base;
    auto s = (r < 10) ? ('0' + r) : ('A' + (r - 10));
    if (q == 0) {
        return format("%c", s);
    } else {
        return format("%s%c", toStringWithBase(q, base).c_str(), s);
    }
}
string toStringWithBase(Int value, int base, int padding) {
    auto result = toStringWithBase(value, base);
    auto n = result.size();
    auto Result = ""s;
    for (int i = n + 1; i <= padding; i++) {
        Result += "0"s;
    }
    return Result + result;
}
const auto MOD = 1000000007LL;
int main() {
    Int n;
    cin >> n;
    IntsIn(v, n);
    auto counts = vector<Int>(64, 0);
    rep(i, 63) {
        for (auto a : v) {
            if ((((1LL << i) & a) >> i) == 1) counts[i]++;
        }
    }
    Int ans = 0;
    rep(i, 63) {
        auto x = (counts[i] % MOD) * ((n - counts[i]) % MOD) % MOD;
        rep(j, i) {
            x *= 2;
            x %= MOD;
        }
        ans += x;
        ans %= MOD;
    }
    PUTS(ans);
}


Measured memory_bytes: 5232
import itertools

N, M, Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for _ in range(Q)]

# 1 ~ Mまでの数を用いたN項の重複組合せを作成する
arrs = []
for arr in itertools.combinations_with_replacement(range(1, M + 1), N):
    arrs.append(list(arr))
#print(len(arrs))

# 各組合せに対し、全クエリを実行して最大値を求める　(計算量: 10H10 x 50)
answer = - float("inf")
for arr in arrs:
    tmp = 0
    for a, b, c, d in ABCD:
        if arr[b - 1] - arr[a - 1] == c:
            tmp += d
    answer = max(answer, tmp)

print(answer)

Measured memory_bytes: 90316
/***

   Author : Md. Jashim Uddin
   From   : RMSTU

 ***/
#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     ll              long  long int
#define     fast            ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)
#define     forn(i,n)       for(int i=1;i<=n;i++)
#define      mx               10001
int main()
{

    ll a,b;
    cin>>a>>b;
    if((a>=1 && a<=9) && (b>=1 && b<=9))
    {
        cout<<a*b<<endl;
    }
    else cout<<"-1"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    long long ans = 1;
    for (int i = 0;i<a;i++){
        if(i == 0){
            ans = b;
        }else{
            ans *= (b-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String x = sc.next();
		String y = sc.next();
		if (x.compareTo(y) < 0) {
			System.out.println("<");
		} else if (x.compareTo(y) > 0) {
			System.out.println(">");
		} else {
			System.out.println("=");
		}
	}
}

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

using namespace std;
using ll = long long;

int main() {
    ll n, x;
    cin >> n >> x;

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

    ll ans = 0;
    for (int i = 0; i < n-1; i++) {
        ll t = max((ll) 0, a[i] + a[i + 1] - x);
        ans += t;
        a[i + 1] = max((ll)0, a[i + 1] - t);
    }

    cout << ans << endl;
} 

Measured memory_bytes: 4044
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;

	writeln(180 * (N - 2));
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
require 'prime'
 
$primes_u10000 = Prime.each(10000).to_a
 
def prime?(n)
    return n == $primes_u10000.bsearch{|x| n <= x} if n <= 10000
 
    # trial division
    limit = Math.sqrt(n).floor
    $primes_u10000.each do |d|
        break if limit < d
        return false if n % d == 0
    end
 
    return true
end
 
p gets.to_i.times.count { prime? gets.to_i }

Measured memory_bytes: 9040
// 2020-08-26 16:05:35
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  int n;
  cin >> n;
  vector<int> p(55555 + 55, 1), ans;
  p[0] = p[1] = 0;
  ans.push_back(2);
  REP(i, 2, 55555 + 5) if (p[i]) {
    for (int j = 2 * i; j < 55555 + 5; j += i) p[j] = 0;
    if (i % 5 == 1) {
      ans.push_back(i);
      if (ans.size() == n) break;
    }
  }
  rep(i, ans.size()) {
    if (i) cout << ' ';
    cout << ans[i];
  }
  cout << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_b(pair<int, long long> a, pair<int, long long> b) {
    if(a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<long long> a(M);
    vector<int> b(M);
    vector<vector<int>> c(M);
    rep(i, 0, M) {
        cin >> a[i] >> b[i];
        rep(j, 0, b[i]) {
            int inc;
            cin >> inc;
            inc--;
            c[i].push_back(inc);
        }
    }
    int all = 1 << N;
    vector<vector<long long>> dp(N, vector<long long>(all, INF));
    rep(i, 0, M) {
        long long tmp = 0LL;
        rep(t, 0, b[i]) { tmp += (1 << c[i][t]); }
        // cout << bitset<12>(tmp) << endl;
        rep(t, 0, all) { dp[0][tmp] = min(dp[0][tmp], a[i]); }
    }
    rep(k, 0, N - 1) {
        rep(i, 0, M) {
            long long tmp = 0LL;
            rep(t, 0, b[i]) { tmp += (1 << c[i][t]); }
            // cout << bitset<12>(tmp) << endl;
            rep(t, 0, all) {
                dp[k + 1][t | tmp] =
                    1LL *
                    min({dp[k + 1][t | tmp], dp[k][t] + a[i], dp[k][t | tmp]});
            }
        }
    }
    // rep(i, 0, N) {
    //     rep(j, 0, all) { cout << dp[i][j] << " "; }
    //     cout << endl;
    // }
    if(dp[N - 1][all - 1] != INF) {
        cout << dp[N - 1][all - 1] << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 768
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> S;
  T = S.substr(5, 2);
  N =atoi(T.c_str());
  //cout << N << endl;
  if (N>=5) cout << "TBD" << endl;
  else cout <<"Heisei"<<endl;

}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = []
x = 0
for i in A:
    if i % 2 == 0:
        B.append(i)

for j in B:
    if j % 3 != 0:
        if j % 5 != 0:
            x += 1

if x != 0:
    print('DENIED')
else:
    print('APPROVED')


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int x = Integer.parseInt(str[0]);
		int y = Integer.parseInt(str[1]);
		int z = Integer.parseInt(str[2]);

		System.out.println(z + " " + x + " " + y);
	}
}


Measured memory_bytes: 21072
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  ll i,j;
  ll H,W,A,B; cin >> H >> W >> A >> B;
  ll ans = 0;
  
  ll t=1000000;
  fact[0]=1;
  REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
  fact_inv[t]=power(fact[t], MOD-2);
  FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;

  FOR(i,0,H-A){
      ans += comb(B+i-1,B-1) * comb(W-B+H-i-2,W-B-1);
      ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


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

string s;

int pr[200004], sl[200003];

int main( ){
	string s;
	cin>>s;
	int i, n = s.size();
	for(i=1;i<=n;i++){
		char c= s[i-1];
		if(c=='R')
			pr[i] = pr[i-1] + 1;
		else
			pr[i]= 0;
	}
	for(i=n;i>=1;i--){
		char c= s[i-1];
		if(c=='L')
			sl[i] = sl[i+1] + 1;
		else
			sl[i]= 0;
	}
	for(i=0;i<n;i++){
		if(s[i]=='R' && s[i+1]=='L') {
			int cntr = pr[i +1];
			int cntl = sl[i+2];
			int sum = cntr + cntl;
			int ls = sum/2;
			int mr = sum -ls;
			if( (cntr > cntl && cntr%2==0) ||(cntr < cntl && cntl%2==1)  ) {
				cout<<ls<<" "<<mr<<" ";
			} else {
				cout<<mr<<" "<<ls<<" ";
			}
			i++;
		} else {
			cout<<(0)<<" ";
		}
	}
	cout<<"\n";


}

Measured memory_bytes: 1408
import time

def main():
    h, n = map(int, input().split())
    INF = 10 ** 9
    magic = []

    for i in range(n):
        a, b = map(int, input().split())
        magic.append((a, b))

    # t = time.time()

    magic.sort(reverse=True, key=lambda x: x[0])

    dp = [INF] * (h + 10 ** 4)
    dp[0] = 0

    for a, b in magic:
        for i in range(h):
            if dp[i] != INF:
                tmp = dp[i] + b
                if tmp < dp[i + a]:
                    dp[i + a] = tmp

    ans = min(dp[h:])

    print(ans)
    # print(time.time() - t)

main()

Measured memory_bytes: 3736
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <ctime>
#include <set>
#include <sstream>
#include <map>
#include <cstring>
#include <algorithm>
//头文件这么多是因为我都塞缺省源里了……无视就好
using namespace std;
typedef long long ll;
string s,k;
int main(){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    cin>>s>>k;//读入2个字符（串）
    if(s<k)//三种情况比较
    {
        printf("<\n");
        return 0;
    }
    if(s>k)
    {
        printf(">\n");
        return 0;
    }
    if(s==k)
    {
        printf("=\n");
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#define PI atan(1.0)*4.0
using namespace std;
int main() {
	double a,b,c,cl,s,h;
	cin>>a>>b>>cl;
	s=a*b*sin(PI*cl/180)/2;
	c=sqrt((a*a)+(b*b)-(2*a*b*cos(PI*cl/180)));
	h=s*2/a;
	printf("%.8lf\n",s);
	printf("%.8lf\n",a+b+c);
	printf("%.8lf\n",h);
	return 0;
}



Measured memory_bytes: 3508
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, M := ReadInt(), ReadInt()
	S := ReadString()

	dp := make([]int, N+1)
	for i := 0; i < N; i++ {
		dp[i] = 1 << 62
	}
	dp[N] = 0
	q := []int{0}
	for i := N - 1; i >= 0; i-- {
		for {
			if len(q) == 0 {
				fmt.Println(-1)
				return
			}
			if q[0] < 1<<62 && len(q) <= M {
				break
			}
			q = q[1:]
		}
		if S[i] == '0' {
			dp[i] = q[0] + 1
		}
		q = append(q, dp[i])
	}

	ans := make([]int, 0)
	x := 0
	rest := dp[0]
	for x < N {
		rest--
		i := 1
		for dp[x+i] != rest {
			i++
		}
		ans = append(ans, i)
		x += i
	}
	for _, v := range ans {
		fmt.Printf("%d ", v)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 7708
#pragma region header
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define ts to_string
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector <string>
#define vvs vector <vector<string>>
#define pq  priority_queue<int>
using ll = long long;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }
    // 素数である
    return true;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll kind(vi SYURUI) {//vector<int>型の配列の要素の種類数
    int size = SYURUI.size();
    sort(all(SYURUI));
    int cnt = 1;
    rep(i, size-1) {
        if (SYURUI[i] != SYURUI[i + 1])cnt++;
    }
    return cnt;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int N, H, W; cin >> N >> H >> W;
    vector<pair<int, int>>A(N); rep(i, N)cin >> A[i].first >> A[i].second;
    int cnt = 0;
    rep(i, N) {
        if (A[i].first >= H && A[i].second >= W)cnt++;
    }
    cout << cnt << endl;
}





Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;

int main() {
	bool e[30]={0};
    for(int i=0;i<28;i++) {
		int n;
		scanf("%d",&n);
		e[n-1]=1;
	}
	for(int i=0;i<30;i++) {
		if(!e[i]) printf("%d\n",i+1);
	}
}

Measured memory_bytes: 1024
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define MAX_DWORD				(0xFFFFFFFF)
#define	MAX_SDWORD				((SDWORD)0x7FFFFFFF)
#define	MIN_SDWORD				((SDWORD)0x80000000)
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846

typedef long					SDWORD;
typedef long long				SQWORD;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef long long ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int r;
	cin >> r;
	cout << r * r;
	return 0;
}


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

int main() {
  string S,T,U;
  int A,B;
  cin>>S>>T>>A>>B>>U;
  
  if(U==S){
    cout<<A-1<<" "<<B<< endl;
  }
  else if(U==T){
    cout<<A<<" "<< B-1<< endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int N;
vector<int> L;
vector<int> A;

int main(){
  int N; cin>>N;
  A.resize(3);
  for(int i=0;i<3;i++)cin>>A[i];
  L.resize(N);
  for(int i=0;i<N;i++) cin>>L[i];

  int res=1<<29;

  vector<int> bit(3);
  for(bit[0]=1;bit[0]<(1<<N);bit[0]++){
    for(bit[1]=1;bit[1]<(1<<N);bit[1]++){
      if(bit[1]&bit[0]) continue;
      for(bit[2]=1;bit[2]<(1<<N);bit[2]++){
        if(bit[2]&bit[0]) continue;
        if(bit[2]&bit[1]) continue;
        vector<int> sums(3,0),nums(3,0);
        for(int i=0;i<N;i++){
          for(int j=0;j<3;j++){
            if(bit[j]&(1<<i)){
              sums[j]+=L[i];
              nums[j]++;
            }
          }
        }
        int score=0;
        for(int i=0;i<3;i++){
          score+=abs(sums[i]-A[i]);
          score+=(nums[i]-1)*10;
        }
        res=min(res,score);
      }
    }
  }
  cout<<res<<endl;

  return 0;
}



Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
ns = Hash.new(0)
a.each{|an| ns[an] += 1}
flag = 1
ns.each do |k, v|
  if v != 1
    flag = 0
    break
  end
end
(flag == 1) ? (puts "YES"):(puts "NO")

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

namespace IntModulo
{
	const int mod = 1e9 + 7;

	inline int add(int x, int y, int m = mod)
	{
		if (x + y < m)
			return x + y;
		return x + y - m;
	}

	inline int sub(int x, int y, int m = mod)
	{
		if (x >= y)
			return x - y;
		return x - y + m;
	}

	inline int mult(int x, int y, int m = mod)
	{
		return x * (LL) y % m;
	}

	inline int power(int x, int y, int m = mod)
	{
		int r = 1;
		while(y)
		{
			if (y & 1)
				r = mult(r, x, m);
			x = mult(x, x, m);
			y >>= 1;
		}
		
		return r;
	}
	
	inline int inverse(int x, int m = mod)
	{
		return power(x, m - 2, m);
	}
	
	inline void ADD(int& x, int y, int m = mod)
	{
		x += y;
		if (x >= m) x -= m;
	}
	
	inline void SUB(int& x, int y, int m = mod)
	{
		x -= y;
		if (x < 0) x += m;
	}
	
	inline void MULT(int& x, int y, int m = mod)
	{
		x = (x * (LL) y) % m;
	}
};

using namespace IntModulo;
const int N = 1 << 18;
int n;
VI g[N];
int sz[N];
int pw[N];

void dfs_ans(int v, int p, int& ans)
{
	sz[v]++;
	vector<int> s;
	for(auto i: g[v]) if (i != p)
	{
		dfs_ans(i, v, ans);
		sz[v] += sz[i];
		s.PB(sz[i]);
	}
	
	s.PB(n - sz[v]);
	
	int val = 1;
	for(auto i: s) ADD(val, pw[i] - 1);	
	ADD(ans, pw[n - 1]);
	SUB(ans, val);
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n;
	FOR(i, 0, n - 1)
	{
		int u, v;
		cin >> u >> v;
		g[u].PB(v);
		g[v].PB(u);
	}
	
	pw[0] = 1;
	FOR(i, 1, N) pw[i] = add(pw[i - 1], pw[i - 1]);
		
	int ans = 0;
	dfs_ans(1, -1, ans);		
	ans = mult(ans, inverse(pw[n]));
	cout << ans << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 32512
class Dice:
    def __init__(self, men):
        self.men = men

    def throw(self, direction):
        if direction == "E":
            pmen = men[:]
            men[0] = pmen[3]
            men[1] = pmen[1]
            men[2] = pmen[0]
            men[3] = pmen[5]
            men[4] = pmen[4]
            men[5] = pmen[2]
        elif direction == "W":
            pmen = men[:]
            men[0] = pmen[2]
            men[1] = pmen[1]
            men[2] = pmen[5]
            men[3] = pmen[0]
            men[4] = pmen[4]
            men[5] = pmen[3]
        elif direction == "S":
            pmen = men[:]
            men[0] = pmen[4]
            men[1] = pmen[0]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[5]
            men[5] = pmen[1]
        elif direction == "N":
            pmen = men[:]
            men[0] = pmen[1]
            men[1] = pmen[5]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[0]
            men[5] = pmen[4]


    def printUe(self):
        print (self.men)[0]

    def printMen(self):
        print self.men

men = map(int, (raw_input()).split(" "))
d = Dice(men)

S = raw_input()
for s in S:
    d.throw(s)
d.printUe()

Measured memory_bytes: 6456
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;cin>>N>>M;
  int count=0;
  for(int i=0;i<M;i++){int a;cin>>a;count=max(count,a);}
  cout<<max(0,count*2-N-1)<<endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

vector< bool > get_prime(int n){
  vector< bool > prime( n + 1, true);
  
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  
  for(int i = 2; i * i <= n; i++){
    if(prime[i]){
      for(int j = i + i; j <= n; j += i) prime[j] = false;
    }
  }
  
  return(prime);
}

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    vector<string> slist;
    unordered_map<string, bool> mp;
    REP(i, s.length()){
        int flag = min(5, (int)s.length() - i);
        for(int j = 0; j < flag; j ++){
            string key = s.substr(i, j + 1);
            if(mp.find(key) == mp.end()){
                slist.push_back(key);
            }
            mp[key] = true;
        }
    }
    SORT(slist);
    cout << slist[k - 1] << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

typedef signed long long ll;
typedef long double ld;

#define sq(x) (x) * (x)
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(x) x.begin(),x,end()
#define OUT(x) cout<<x<<endl

#define __INT_MAX__ 2147483647

#define DEBUG

int main()
{
	int r;
	cin >> r;
	cout << 3 * r * r << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
class ModInt{
  static const int default_mod = 1e9 + 7;
public:
  ModInt(long long val, int mod)
    : val(val % mod), mod(mod)
  {
  }
  ModInt(long long val)
    : ModInt(val, default_mod)
  {
  }
  ModInt operator* (const ModInt& another){
    return ModInt(val * another.val);
  }
  ModInt& operator*=(const long long rhs){
    this->val *= rhs;
    this->val %= mod;
    return *this;
  }
  
  ModInt pow(long long exponent){
    exponent %= mod;
    if(exponent == 0){
      return ModInt(1, mod);
    }else{
      if(exponent % 2){
        return ((*this) * (*this)).pow(exponent / 2) * (*this);
      }else{
        return ((*this) * (*this)).pow(exponent / 2);
      }
    }
  }
  ModInt inv(){
    return this->pow(mod - 2);
  }
  static ModInt fact(long long n, int mod){
    n %= mod;
    auto ret = ModInt(1, mod);
    while(n > 1){
      ret *= n;
      n--;
    }
    return ret;
  }
  static ModInt fact(long long n){
    return ModInt::fact(n, default_mod);
  }
  static ModInt comb(long long n, long long r, int mod){
    if(r > n){
      return ModInt(0, mod);
    }
    return ModInt::fact(n) * ModInt::fact(r).inv() * ModInt::fact(n - r).inv();
  }
  static ModInt comb(long long n, long long r){
    return ModInt::comb(n, r, default_mod);
  }
 
  friend ostream& operator<< (ostream& os, const ModInt& modint){
    os << modint.val;
    return os;
  }
  friend istream& operator>>(istream& is, ModInt& modint){
    long long val;
    cin >> val;
    modint.val = val % modint.mod;
  }
private:
  long long val;
  int mod;
};
 
 
int main(){
  int N, K;
  cin >> N >> K;
 
  for(int i = 1; i <= K; i++){
    ModInt blue_comb = ModInt::comb(K - 1, i - 1);
    ModInt red_comb = ModInt::comb(N - K + 1, i);
    cout << blue_comb * red_comb << endl;
  }
 
}

Measured memory_bytes: 256
#include<string>
#include<iostream>

int main(){
  std::string s,t,u;
  std::cin >> s >> t;
  int a,b;
  std::cin >> a >> b;
  std::cin >> u;
  if(u == s)
    std::cout << a - 1 << " " << b << std::endl;
  if(u == t)
    std::cout << a << " " << b - 1 << std::endl;
  return  0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
      int a,b,c,x,y,ans=0;
	  cin>>a>>b>>c>>x>>y;
	   int p=abs(x-y);	int k;
	  if ((a+b)>2*c) 
	  {
	  
	  	if (x>y) 
		  {
		  k=x;
	      ans+=p*a;
	   }
	  	else
	  	{
	  		ans+=p*b;
	  	k=y;
	  }
       k=k-p;
	  	ans+=k*2*c;
       k=k+p;
       if (k*c*2<ans) ans=k*c*2;
	  }
	  else
	  {
	  	ans+=(x*a+b*y);
	  }
	  cout<<ans<<endl;
}

Measured memory_bytes: 256
import itertools
s = input()
num_place = len(s) - 1

if num_place == 0:
  result = int(s)
else:
  list_place_plus = list(itertools.product(range(2), repeat=num_place))
  result = 0
  for one_place in list_place_plus:
    start = 0
    for place, check in enumerate(one_place):
      if check == 1:
        result += int(s[start:place+1])
        start = place + 1
      if place + 1 == num_place:
        result += int(s[start:])
print(result)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int p = 1e9+7;

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

ll gcd(ll a,ll b){
    if(a<b) swap(a,b);
    if(a%b==0) return b;
    return gcd(a%b,b);
}

ll lcm(ll a,ll b){
    // cout << a << " " << b << " " << endl;
    return a * b / gcd(a,b);
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);

    vector<int> b(1e6+1);

    rep(i,n){
        int tmp = a.at(i);
        int cnt = 0;
        for(int j=2;j<1e3;j++){
            cnt = 0;
            while(tmp % j == 0){
                tmp/=j;
                cnt++;
            }
            b.at(j) = max(b.at(j), cnt);
        }
        b.at(tmp) = max(b.at(tmp),1);
    }

    ll l=1;
    rep(i,b.size()){
        if(b.at(i) > 0){
            l *= powmod(i,b.at(i));
            l %= p;
        }
    }

    ll ans=0;
    rep(i,n){
        ans += powmod(a.at(i),p-2);
        ans %= p;
    }
    ans *= l;
    ans %= p;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int ans,pre;
	string S,T;
	cin>>S>>T;
	ans=T.length();
	for(int i=0;i<=S.length()-T.length();i++){
		pre=0;
		for(int j=0;j<T.length();j++){
			pre+=S[i+j]!=T[j];
		}
		ans=min(ans,pre);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

int main() {
    int x, y, z; cin >> x >> y >> z;

    int tmp = y + 2 * z;
    int cnt = 1;
    while(tmp<=x){
        cnt++;
        tmp += y + z;
    }

    cnt--;
    cout << cnt << endl;
}

Measured memory_bytes: 256
N,D=map(int,input().split())
X=[]
for n in range(N):
    x=list(map(int,input().split()))
    X.append(x)
#print(X)
import math
def calculate_dis(x1,x2,D):
    distance=0
    for d in range(D):
        distance+=(x1[d]-x2[d])**2
    return math.sqrt(distance)


#print(calculate_dis(X[0],X[1],D))
#print(calculate_dis(X[0],X[2],D))
count=0
for n in range(N):
    #すでに計算してある組みは考慮したくない
    for m in range(n,N):
        if n==m:
            continue
        #print(f"n{n}:m{m}")
        dis=calculate_dis(X[n],X[m],D)
        #print(f"X[{n}],X[{m}]:{dis}")
        if dis%1==0:
            count+=1
print(count)


Measured memory_bytes: 3064
#include <stdio.h>
int main(){
     
 int n, i;
 scanf("%d",&n);
     
 for(i = 1; i <= n; i++) {
  if(i%3 == 0) {
   printf(" %d",i);
  } else if(i%10 == 3 || (i/10)%10 == 3 || (i/100)%10 == 3 || (i/1000)%10 == 3) {
   printf(" %d",i);
  }
 }
 printf("\n");
     
 return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin >> S;
  int N = S.size();

  long long ans = 0;
  for (int bit = 0; bit < (1 << (N-1) ); bit++) {
    long long sum = 0;
 //   cout << "bit : " << bit << " " << bitset<4>(bit) << endl;
    for(int j=0;j<N-1;j++){
      sum *= 10;
      sum += S.at(j) -'0';
 //     cout << "sum : " << sum << endl;
 //     cout << "if : " << bitset<4>(bit)  << " " << bitset<4>(1<<j) << endl;
      if(bit & (1<<j)){
        ans += sum;
        sum =0;
      }
    }
    sum *= 10;
    sum += S.back() - '0';
    ans += sum;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3564
n = int(input())
s = input()
idx = 0
idx = 1
ans = 1
if n == 1:
    print(1)
else:
    tmp = s[0]
    while(idx<n):
        if s[idx]==tmp:
            idx += 1
        else:
            tmp = s[idx]
            idx += 1
            ans +=1
    print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll X;
ll B[101010],L[101010],R[101010];
pair<ll,int> P[101010];

int ok(ll v) {
	if(v<0) return 0;
	ll A=0,C=0;
	ll num=v/X;
	ll lef=v%X;
	int i,j;
	FOR(i,N) {
		j=P[i].second;
		if(i<num) {
			A+=X*R[j];
			C+=B[j]*R[j];
		}
		else {
			C+=B[j]*L[j];
		}
	}
	if(lef==0) return A>=C;
	if(A>=C) return 1;
	
	FOR(i,N) {
		if(i<num) {
			int x=P[i].second;
			int y=P[num].second;
			ll A2=A-X*R[x]+X*R[y];
			ll C2=C+B[y]*(R[y]-L[y])-B[x]*(R[x]-L[x]);
			if(B[x]<=lef) {
				if(A2+lef*R[x]>=C2+B[x]*(R[x]-L[x])) return 1;
			}
			else {
				if(A2+lef*L[x]>=C2) return 1;
			}
		}
		else {
			j=P[i].second;
			if(B[j]<=lef) {
				if(A+lef*R[j]>=C+B[j]*(R[j]-L[j])) return 1;
			}
			else {
				if(A+lef*L[j]>=C) return 1;
			}
		}
	}
	return 0;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>X;
	FOR(i,N) {
		cin>>B[i]>>L[i]>>R[i];
		P[i]={-((X-B[i])*R[i]+B[i]*L[i]),i};
	}
	sort(P,P+N);
	
	ll ret=X*N;;
	for(i=40;i>=0;i--) if(ok(ret-(1LL<<i))) ret-=1LL<<i;
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 4224
N = int(input())
work = []
for i in range(N):
  work.append(list(map(int, input().split())))
work = sorted(work, key=lambda x: x[1])
time = 0
for i in range(N):
  time += work[i][0]
  if time > work[i][1]:
    print('No')
    exit()
print('Yes')



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

int main(){
    int sum = 0, n = 0;
    string s;

    while( getline(cin,s) ){
        for(int i=0 ; i<s.size() ; i++){
            if( s[i]>='0' && s[i]<='9'){
                n *= 10;
                n += s[i]-'0';
            }else{
                sum += n;
                n = 0;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 0
N,K,Q=map(int, input().split())
Ns=[0]*N
def yes_or_no(value):
  if K-(Q-value) <= 0:
    return "No"
  else:
    return "Yes"

for _ in range(Q):
  A=int(input())
  Ns[A-1] +=1

for i in Ns:
  print(yes_or_no(i))

Measured memory_bytes: 4808
// A - Takahashi Calendar
#include <bits/stdc++.h>
using namespace std;
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))

int main(){
	int M,D; cin>>M>>D;
	int ans = 0;
	up(m,1,M+1,1)
		up(d,2,D+1,1){
			int d10 = d / 10, d1 = d % 10;
			if(d10>1 && d1>1 && m==d10*d1) ans++;
		}
	cout<< ans <<endl;
}

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

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

int main()
{
  int h, m, s;

  while (cin >> h >> m >> s, h + m + s != -3){
    int a = 3600 * 2 - (h * 3600 + m * 60 + s);
    printf("%02d:%02d:%02d\n", a / 3600, a % 3600 / 60, a % 60);
    printf("%02d:%02d:%02d\n", a * 3 / 3600, a * 3 % 3600 / 60, a * 3 % 60);
  }
}

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

ll n, m, a, b;

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
	return s * w;
}

inline void work(){
	n = read(), a = read(), m = read(), b = read();
	if (n == m){
		if (a < b){
			if (a < n) puts("No");
			else puts("Yes");
		} else puts("Yes");
		exit(0);
	}
	while (n > 0 && m > 0){
		m -= a;
		n -= b;
	}
	if (m < 1) puts("Yes");
	else puts("No");
}

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

Measured memory_bytes: 3648
import heapq
N, M = map(int, input().split())
A = list(list(map(lambda x: int(x) * (-1), input().split())))
heapq.heapify(A)
for i in range(M):
  heapq.heappush(A, (-1) * ((-1 * heapq.heappop(A)) // 2))
print(-1 * sum(A))  

Measured memory_bytes: 87232
#include<iostream>
using namespace std;
int main(){
int n;
  cin >> n;
  int ans = 0;
  int highest = 0;
  for(int i=0;i<n;i++)
  {
    int h;
    cin >> h;
    if(h >= highest){
    	ans++;
        highest = h;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef long long ll;

const int MOD = 1000000007;

ll extgcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll d = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

void cmb_init(int n, vll &fac, vll &finv) {
  ll x, y;
  for (int i = 2; i <= n; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    extgcd(i, MOD, x, y);
    finv[i] = finv[i - 1] * (MOD + x % MOD) % MOD;
  }
}

// void cmb_init(int n, vll &fac, vll &finv) {
//   vll inv(n + 1, 1);
//   for (int i = 2; i <= n; i++) {
//     fac[i] = fac[i - 1] * i % MOD;
//     inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
//     finv[i] = finv[i - 1] * inv[i] % MOD;
//   }
// }

ll cmb(int n, int k, vll &fac, vll &finv) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve() {
  int N, K;
  cin >> N >> K;
  vi A(N, 0);
  vll fac(N + 1, 1), finv(N + 1, 1);
  cmb_init(N, fac, finv);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(all(A));
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    sum -= (ll)A[i] * cmb(N - i - 1, K - 1, fac, finv) % MOD;
    sum += (ll)A[i] * cmb(i, K - 1, fac, finv) % MOD;
    sum %= MOD;
  }
  cout << sum << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 2176
n = gets.chomp.to_i
v = gets.chomp.split(" ")
a_map = {}
b_map = {}
v.each_slice(2) do |pair|
  a_map[pair[0]] ||= 0
  b_map[pair[1]] ||= 0
  a_map[pair[0]] += 1 
  b_map[pair[1]] += 1 
end

a_max = a_map.max{|a,b| a[1] <=> b[1]}
b_max = b_map.max{|a,b| a[1] <=> b[1]}
if a_max[0] == b_max[0]
  b_map.delete b_max[0]
  b_second = b_map.max{|a,b| a[1] <=> b[1]} || [nil, 0]
  a_map.delete a_max[0]
  a_second = a_map.max{|a,b| a[1] <=> b[1]} || [nil, 0]

  if a_max[1] + b_second[1] >= b_max[1] + a_second[1]
    puts n - a_max[1] - b_second[1]
  else
    puts n - b_max[1] - a_second[1]
  end
else
  puts n - a_max[1] - b_max[1]
end


Measured memory_bytes: 22420
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0}; 
using P = pair<int, int>;
const double pi = acos(-1.0);

int main(){
  int n;
  cin>>n;
  cout<<n*(n+1)/2<<endl;
    
    
  return 0;
}


Measured memory_bytes: 3628
import sys
a,b,c = map(int,input().split())
if a < 0 or b < 0 or c < 0 or a > 100 or b > 100 or c > 100:
    sys.exit()

diff_a_b = b - a
diff_b_c = c - b

if diff_a_b == diff_b_c:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9116
n ,t = [int(x) for x in input().split()]
arr = [list(map(int, input().split())) for _ in range(n)]

ans = 9999
for i in range(n):
    if arr[i][1] <= t:
        if arr[i][0] <= ans:
            ans = arr[i][0]
if ans == 9999:
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3060