akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <utility>
using namespace std;

template <typename T>
void print_vec(const vector<T> &v) {
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    if (i > 0) cout << ' ';
    cout << v[i];
  }
  cout << '\n';
}

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  int d1, d2;
  bool flag = false;
  for (int i = 0; i < n; ++i) {
    cin >> d1 >> d2;
    if (d1 == d2) {
      ++cnt;
    } else {
      cnt = 0;
    }
    if (cnt == 3) {
      flag = true;
    }
  }

  if (flag) cout << "Yes\n";
  else cout << "No\n";

  return 0;
}


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

#define EPS 1e-6
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using namespace std; 

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

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

  int n, k; cin >> n >> k;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x; cin >> x;
    ans += (x >= k);
  }

  cout << ans << ende;
  return 0;
}


Measured memory_bytes: 256
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    t,x = map(int,input().split())
    ans = t / x
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38508
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;

	char buf[L], *S , *T, c;

	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}

	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}

	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	char B[45], *outs=B+40, *outr=B+40;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;

		if(!a)*--outs = '0';
		else
			while(a)
				*--outs = (a % 10) + 48, a /= 10;

		if(x)
			*--outs = x;

		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

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

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 1<<21;

int n;
int p[MAXN];

int main()
{
	
	cin >> n;
	for (int i = 1; i <= n; ++ i)
		cin >> p[i];
	int ans = 0;
	for (int i = 2; i < n; ++ i)
	{
		int L = max({p[i-1], p[i], p[i+1]});
		int R = min({p[i-1], p[i], p[i+1]});
		if (p[i] != L && p[i] != R) ++ ans;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<pair<ll, ll> > node1(N), node2(N);
  ll x1, y1, x2, y2;
  vector<ll>xarr, yarr;
  map<ll, int> xmap, ymap;
  for(int i=0;i<N;++i) {
    cin>>x1>>y1>>x2>>y2;
    node1[i] = mp(x1, y1);
    node2[i] = mp(x2, y2);
    if(xmap[x1]==0) xarr.push_back(x1);
    xmap[x1]++;
    if(xmap[x2]==0) xarr.push_back(x2);
    xmap[x2]++;
    if(ymap[y1]==0) yarr.push_back(y1);
    ymap[y1]++;
    if(ymap[y2]==0) yarr.push_back(y2);
    ymap[y2]++;
  }
  sort(xarr.begin(), xarr.end());
  sort(yarr.begin(), yarr.end());
  map<ll, ll> x1map, x0map, y1map, y0map;
  for(int i=0;i<xarr.size();++i) {
    x1map[xarr[i]] = i;
    x0map[i] = xarr[i];
  }
  for(int i=0;i<yarr.size();++i) {
    y1map[yarr[i]] = i;
    y0map[i] = yarr[i];
  }
  int H=x1map[xarr[xarr.size()-1]]+1, W=y1map[yarr[yarr.size()-1]]+1;;
  int zaatu[H][W];
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      zaatu[i][j] = 0;
    }
  }
  for(int i=0;i<N;++i) {
    x1 = x1map[node1[i].fi];
    y1 = y1map[node1[i].se];
    x2 = x1map[node2[i].fi];
    y2 = y1map[node2[i].se];
    for(int i=x1;i<x2;++i) {
      zaatu[i][y1]++;
      zaatu[i][y2]--;
    }
  }
  for(int i=0;i<H;++i) {
    for(int j=1;j<W;++j) {
      zaatu[i][j] += zaatu[i][j-1];
    }
  }
  ll ans = 0;
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      if(zaatu[i][j]>0) ans += (x0map[i+1]-x0map[i])*(y0map[j+1]-y0map[j]);
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 67008
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int N = 1e6 + 5;

int main(){
    fast;
    ll k;
    cin >> k;
    ll ans = 0;
    for(int i = 1; i <= k; ++i){
        for(int j = 1; j <= k; ++j){
            for(int u = 1; u <= k; ++u){
                ans += __gcd(i, __gcd(j,u));
            }
        }
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

vector<P> d;

//RMQ
struct SegTree {
    int N;
    vector<int> dat;
    SegTree() {}
    SegTree(int n) {
        N = 1;
        while(N < n) N *= 2;
        dat.resize(2 * N, INF);
        // for(int i = 0; i < 2*N-1; i++)
        //     dat[i] = INF;
    }
    // update k th element
    void update(int k, int a) {
        k += N-1; // leaf
        dat[k] = a; 
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = min(dat[k*2+1], dat[k*2+2]);
        }
    }
    // min [a, b)
    int query(int a, int b) { return query(a, b, 0, 0, N); }
    int query(int a, int b, int k, int l, int r) {
        if(r <= a or b <= l) return INF;
        if(a <= l and r <= b) return dat[k];
        int m = (l + r) / 2;
        return min(query(a, b, k*2+1, l, m), query(a, b, k*2+2, m, r));
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i, 0, n){
        cin >> x[i] >> y[i];
        if(x[i] > y[i]) swap(x[i], y[i]);
        d. push_back(P(x[i], y[i]));
    }
    SegTree r(n), r2(n);
    sort(all(d));
    rep(i, 0, n){
        r.update(i, -d[i].second);
        r2.update(i, d[i].second);
    }
    int rMIN = 1e12, rMAX = 0, bMIN = 1e12, bMAX = 0;
    rep(i, 0, n){
        chmax(rMAX, x[i]);
        chmin(rMIN, x[i]);
        chmax(bMAX, y[i]);
        chmin(bMIN, y[i]);
    }
    int ans = (rMAX - rMIN) * (bMAX - bMIN);
    // cout << rMAX << " " << rMIN << " " << bMAX << " " << bMIN << endl;
    rep(i, 1, n){
        rMIN = d[i].first;
        rMAX = max(d[n - 1].first, -r.query(0, i));
        int cMIN = r2.query(0, i);
        if(cMIN < rMIN){
            chmax(rMAX, rMIN);            
            rMIN = cMIN;
        }
        bMIN = d[0].first;
        bMAX = -r.query(i, n);
        // cout << rMAX << " " << rMIN << " " << bMAX << " " << bMIN << endl;
        chmin(ans, (rMAX - rMIN) * (bMAX - bMIN));
    }
    cout << ans << endl; 
}

Measured memory_bytes: 15852
#include <bits/stdc++.h>
using namespace std;
int main() {
  long N,A=0;
  cin >> N;
  for(int i=1;i<N+1;i++){
    if(i%3==0 || i%5==0){
    }
    else{
      A=A+i;
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 3640
main :: IO ()
main = do
  s <- getLine
  putStrLn $ if (('N' `elem` s) `xor` ('S' `elem` s)) && (('E' `elem` s) `xor` ('W' `elem` s))
    then "Yes"
    else "No"

xor :: Bool -> Bool -> Bool
xor True True = True
xor False False = True
xor True False = False
xor False True = False


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

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

using namespace std;

ll solve(void)
{
	ui N{};
	cin >> N;
	
	vector<ll> arrayW(N);
	ll sum{ 0 };
	for (size_t i = 0; i < arrayW.size(); ++i)
	{
		cin >> arrayW[i];
		sum += arrayW[i];
	}
	
	ll half_sum{ 0 };
	for (auto w : arrayW)
	{
		half_sum += w;
		if (half_sum >= sum / 2)
		{
			return min(abs((2 * half_sum) - sum), abs(sum - 2 * (half_sum - w)));
		}
	}
	
	return -1;
}

int main(void)
{
	ll ans = solve();
	cout << ans << endl;

	return 0;
}


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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define PI 3.14159265
#define sizes 1000010


//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    ll red[a],green[b],color[c],ans=0;
    for(int i=0;i<a;i++)
        cin>>red[i];
    for(int i=0;i<b;i++)
        cin>>green[i];
    for(int i=0;i<c;i++)
        cin>>color[i];
    sort(red,red+a,greater<ll>());
    sort(green,green+b,greater<ll>());
    sort(color,color+c,greater<ll>());
    stack<ll > v1,v2; 
    for(int i=0;i<x;i++)
    {
        v1.push(red[i]);
    }
    for(int i=0;i<y;i++)
    {
        v2.push(green[i]);
    }
    int i=0;
    while(1)
    {
        if(i<c && !v1.empty() && !v2.empty() && v1.top()<color[i] && v2.top()<color[i])
        {
            // cout<<color[i]<<" "<<v1.top()<<" "<<v2.top()<<"\n";
            if(v1.top()<v2.top())
            {
                v1.pop();
            }
            else 
            {
                v2.pop();
                // cout<<"hah";
            }
            i++;
        }
        else if(i<c && !v1.empty() && v1.top()<color[i])
        {
            v1.pop();
            i++;
        } 
        else if(i<c && !v2.empty() && v2.top()<color[i])
        {
            v2.pop();
            i++;
        }
        else
        {
            break;
        }
    }
    for(int j=0;j<i;j++)
        ans+=color[j];
    // cout<<ans<<"\n";
    while(!v1.empty())
    {
        ans+=v1.top();
        // cout<<v1.top()<<" ";
        v1.pop();
    }
    // cout<<"\n";
    while(!v2.empty())
    {
        ans+=v2.top();
        // cout<<v2.top()<<" ";
        v2.pop();
    }
    // cout<<"\n"   ;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?') s[i] = 'D';
  }
  cout << s << endl;
  return 0;
}

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

bool IsPrime(long long num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2){
    if (num % i == 0){
      return false;
    }
  }
  return true;
}

int main(){
  long long A, B;
  cin >> A >> B;
  long long t = max(A, B), s = min(A, B);
  while(t % s != 0){
    long long a = t % s;
    t = s;
    s = a;
  }
  double sqrts = sqrt(s);
  queue<long long> q;
  for(long long i= 1; i <= sqrts; i++){
    if(s % i ==0){
      q.push(i);
      if(i != s / i){
        q.push(s / i);
      }
    }
  }
  long long ans = 1;
  while(!q.empty()){
    long long p = q.front();
    if(IsPrime(p)){
      ans++;
    }
    q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll N; cin >> N;
  vector<vector<ll>> dish(N);
  REP(i,N){
    ll a,b; cin >> a >> b;
    dish.push_back({a+b,a,b});
  }
  sort(ALL(dish), greater<>());
  ll ans = 0;
  REP(i,N){
    if(i%2==0) ans += dish[i][1];
    else ans -= dish[i][2];
  }
  cout << ans << endl;
}

Measured memory_bytes: 8024
from collections import deque

K = int(input())

list = deque(range(1,10))
i = 0
for i in range(K):
    v = list.popleft()

    t = v%10

    if t != 0:
        list.append(10*v + (t-1))

    list.append(10*v + t)

    if t != 9:
        list.append(10*v + (t+1))


print(v)


Measured memory_bytes: 12404
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9+7;
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n,r;
  cin>>n>>r;
  if(n<=10){
    cout<<r+100*(10-n)<<endl;
  }
  else cout<<r<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int k = getInt(sc);
		int[] h = getIntArray(sc);

		int count = 0;
		for (int i = 0; i < n; i++) {
			if (h[i] >= k) {
				count++;
			}
		}
		System.out.println(count);

	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}
}


Measured memory_bytes: 36272
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    a,b = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    print(max(a+b,a-b,a*b))




if __name__ == "__main__":
    main()

Measured memory_bytes: 77368
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public int solve(int N, int[] hs) {
		return getTimes(hs, 0, 0, N-1);
	}
	
	public int getTimes(int[] hs, int height, int start, int end) {
		if (start > end) {
			return 0;
		} else if (start == end) {
			return hs[start] - height;
		}
		
		List<Integer> list = new LinkedList<Integer>();
		int min = Integer.MAX_VALUE;
		
		for (int i=start; i<=end; i++) {
			if (hs[i] < min) {
				min = hs[i];
				list.clear();
				list.add(i);
			} else if (hs[i] == min) {
				list.add(i);
			}
		}

		int result = min - height;	// start~endの範囲の一番低い高さまで水を入れる
		
		int nextIndex = start;
		for (int x : list) {
			// minの高さで区切られた領域の回数を数える
			result += getTimes(hs, min, nextIndex, x-1);
			nextIndex = x+1;
		}
		// 最後のminのIndex～endの領域も忘れない
		result += getTimes(hs, min, nextIndex, end);

		return result;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] hs = new int[N];
		
		for (int i=0; i<N; i++) {
			hs[i] = in.nextInt();
		}
		in.close();
		
		Main main = new Main();
		int result = main.solve(N, hs);
		
		System.out.println(result);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int res = 0;
    res += min(a, k);
    k = max(0, k - a);
    k = max(0, k - b);
    res -= min(k, c);
    cout << res << endl;
}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-

import numpy as np #1.11.0
#import matplotlib as plt #1.5.1
import copy 
import math

n = int(input())
a = list(map(int, input().split())) 

a.sort(reverse = True)
alice = a[0::2]
bob = a[1::2]
ans = sum(alice) - sum(bob)
print(ans)


Measured memory_bytes: 12504
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <tuple>

using int64 = long long int;
using namespace std;

namespace std
{
template<>
struct hash<tuple<size_t, size_t, size_t>>
{
	size_t operator()(const tuple<size_t, size_t, size_t> &t) const
	{
		return get<0>(t) ^ get<1>(t) ^ get<2>(t);
	}
};
}

struct Pair
{
	int64 x, y, z;
	size_t a, b, c;

	int64 Sum() const
	{
		return x + y + z;
	}

	bool operator<(const Pair &p) const
	{
		return Sum() < p.Sum();
	}
};

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

	std::vector<int64> X(x), Y(y), Z(z);

	for (int i = 0; i < x; i++)
		cin >> X[i];
	for (int i = 0; i < y; i++)
		cin >> Y[i];
	for (int i = 0; i < z; i++)
		cin >> Z[i];

	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	sort(Z.begin(), Z.end());

	priority_queue<Pair> queue;
	unordered_set<std::tuple<size_t, size_t, size_t>> visited;
	auto Push = [&queue, &visited, &X, &Y, &Z](size_t x, size_t y, size_t z)
	{
		if (visited.find(std::make_tuple(x, y, z)) == visited.end() && x < X.size() && y < Y.size() && z < Z.size())
		{
			queue.push({ X[x], Y[y], Z[z], x, y, z });
			visited.emplace(x, y, z);
		}
	};

	Push(x - 1, y - 1, z - 1);

	for (int i = 0; i < k; i++)
	{
		auto p = queue.top();
		queue.pop();
		cout << p.Sum() << endl;
		//cout << p.a << " " << p.b << " " << p.c << endl;

		Push(p.a - 1, p.b, p.c);
		Push(p.a, p.b - 1, p.c);
		Push(p.a, p.b, p.c - 1);
	}
}

Measured memory_bytes: 896
#include <stdio.h>
#include <limits.h>

using namespace std;

int main(){
	int n,tmp,min=INT_MAX,max=INT_MIN;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&tmp);
		if(max < tmp-min) max = tmp - min;
		if(min > tmp) min = tmp;
	}
	printf("%d\n",max);
	return 0;
}

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

n,m=map(int,input().split())
leftgate=[]
rightgate=[]
for i in range(m):
  l,r=map(int,input().split())
  leftgate.append(l)
  rightgate.append(r)
if (min(rightgate)-max(leftgate))>-1:
  print(min(rightgate)-max(leftgate)+1)
else:
  print(0)

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

int main(){
	while(true){
		int x,y;
		cin>>x>>y;
		if(x==0 && y==0){
			break;
		}
		if(x<=y){
			cout<<x<<" "<<y<<endl;
		}
		if(x>y){
			cout<<y<<" "<<x<<endl;
		}
	}
	return 0;
}


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

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

    for(int i = 0; i <= 25; i++){
        for(int j = 0; j <= 14; j++){
            if(4 * i + 7 * j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	int r,g;
	cin >> r >> g;

  	cout << r+(g-r)*2 << endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int a, b, c, d;

int main() {
	cin >> a >> b >> c >> d;
	if (a + b < c + d)cout << "Right" << endl;
	else if (a + b > c + d)cout << "Left" << endl;
	else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int n,m;
  cin >> n >> m;
  char s[n][n],t[m][m];
  rep(i,n){
    rep(j,n){
      cin >> s[i][j];
    }
  }
  rep(i,m){
    rep(j,m){
      cin >> t[i][j];
    }
  }
  int i,j,k,l;
  string ans="No";
  for(i=0;i<n-m+1;i++){
    for(j=0;j<n-m+1;j++){
      bool is=true;
      for(k=0;k<m;k++){
        for(l=0;l<m;l++){
          if(s[i+k][j+l]!=t[k][l]){
            is=false;
          }
        }
      }
      if(is){
        ans="Yes";
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int data[][] = new int[N][3];
		
		for(int i=0; i<N; i++){
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
			data[i][2] = sc.nextInt();
		}
		
		int correct = 1;
		int H = 0;
		loop: for(int i=0; i<101; i++){
			for(int j=0; j<101; j++){
				for(int k=0; k<N; k++){
					if(data[k][2] > 0){
						H = data[k][2] + Math.abs(i - data[k][0]) + Math.abs(j - data[k][1]);
						break;
					}
				}
				correct = 1;
				int h = 0;
				for(int k=0; k<N; k++){
					h = H - Math.abs(i - data[k][0]) - Math.abs(j - data[k][1]);
					if(h != data[k][2] && (h >= 0 || data[k][2] != 0)){
						correct = 0;
						break;
					}
				}
				if(correct == 1){
					System.out.println(String.format("%d %d %d", i, j, H));
					break loop;
				}
			}
		}
	}
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int n_w = 0, n_e = 0, w[2][n+1], e[2][n+1]; //w:0, e:1
  for ( int i = 0; i < n; i++){
    if ( s[i] == 'W'){
      n_w++;
    } else {
      n_e++;
    }
    w[0][i+1] = n_w;
    w[1][i+1] = n_e;
  }

  w[0][0] = w[1][0] = 0;

  for ( int i = 0; i < n; i++){
    if(s[i] == 'W'){
      e[0][i] = n_w - w[0][i] - 1;
      e[1][i] = n_e - w[1][i];
    } else {
      e[0][i] = n_w - w[0][i];
      e[1][i] = n_e - w[1][i] - 1;
    }
  }

  int ans = 1 << 28;
  for ( int i = 0; i < n; i++){
    ans = min(ans, w[0][i] + e[1][i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5380
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;
const int MAX = 1001001; // > 10^6
ll fac[MAX];
ll finv[MAX];
ll inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = 1;
    fac[1] = 1;
    finv[0] = 1;
    finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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 COM(int n, int k){
    if (n < k) {
        return 0;
    }
    if (n < 0 || k < 0) {
        return 0;
    }
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {

    // 前処理
    COMinit();

    int h,w,a,b; cin >>h>>w>>a>>b;

    ll ans = 0;
    int i = h - a;
    for (int j = b + 1; j <= w; j++) {
        ll this_ans = COM(i+j-2, min(i-1, j-1));
        int c = w + 1  - j;
        this_ans *= COM(a+c-2, min(a-1,c-1));
        ans += this_ans;
        ans %= MODLL;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(ALL(a));
  reverse(ALL(a));
  int k;
  cin >> k;
  rep(i,0,k) a[0] *= 2;
  cout << a[0] + a[1] + a[2] << endl;
}


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

typedef long long ll;
using namespace std;

string t;

int dfs(int i, string s){
  if (i == 4){
    int tot=s[0]-'0',k=0;
    for (int j = s.length()-1;j>0;j--){
      if (s[j] == '+'){
	tot += k;
      }else if (s[j] == '-'){
	tot -= k;
      }else{
	k = s[j] - '0';
      }
    }
    if (tot == 7){
      s.insert(s.length(),"=7");
      t=s;
    }
    return 0;
  }
  string s1 = s;
  s1.insert(s1.length()-(4-i),"+");
  dfs(i+1,s1);
  string s2 = s;
  s2.insert(s2.length()-(4-i),"-");
  dfs(i+1,s2);
  return 0;
}

int main(){
  string s;
  cin >> s;
  dfs(1,s);
  cout << t << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

int N, K;

int main() {
    cin >> N >> K;
    int ans = 1;

    rep(i, N) {
        ans = min(ans * 2, ans + K);
    }

    cout << ans << endl;
}

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

int main(){
	long long n,m;
	long long x,y,z;
	long long first[3];
	long long min[8],ans[8];
	long long **temp;
	long long ans_max;
	
	cin >> n >> m;
	// x = new long long[n];
	// y = new long long[n];
	// z = new long long[n];
	
	temp = new long long*[8];
	for(int i=0;i<8;i++){
		temp[i] = new long long[n];
		//cout << "OK "<<i<<endl;
		for(int j=0;j<n;j++){
			temp[i][j]=0;
		}
	}
	for(int i=0;i<n;i++){
		cin>>x>>y>>z;
		temp[0][i]=x+y+z;
		temp[1][i]=x+y-z;
		temp[2][i]=x-y+z;
		temp[3][i]=x-y-z;
		temp[4][i]=-x+y+z;
		temp[5][i]=-x+y-z;
		temp[6][i]=-x-y+z;
		temp[7][i]=-x-y-z;
		for(int j=0;j<8;j++){
			//cout<<temp[j][i]<<" ";
		}
		//cout<<endl;
	}
	for(int i=0;i<8;i++){
		sort(temp[i],temp[i]+n);
	}
	for(int i=0;i<8;i++){
		ans[i]=0;
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<8;j++){
			//cout << ans[j]<<" "<<temp[j][n-i-1]<<" "<<n-i-1<<endl;
			ans[j] += temp[j][n-i-1];
		}
	}
	ans_max=0;
	for(int i=0;i<8;i++){
		if(ans_max<ans[i])ans_max=ans[i];
	}
	
	cout << ans_max << endl;
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Io.Read<long>();

            var output = 11;
            for (var A = 1; A <= Math.Sqrt(N); A++)
            {
                if (N % A != 0) continue;

                var B = N / A;
                output = Math.Min(output, Math.Max(NumberOfDigits(A), NumberOfDigits(B)));
            }

            Console.WriteLine(output);
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }
    }

    class Io
    {
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static IEnumerable<string> ReadRepeat(int count)
        {
            return Enumerable.Range(0, count).Select(_ => Read());
        }

        public static T Read<T>()
        {
            return (T)Convert.ChangeType(Read(), typeof(T));
        }

        public static IEnumerable<T> ReadRepeat<T>(int count)
        {
            return Enumerable.Range(0, count).Select(_ => Read<T>());
        }

        public static string[] ReadSplit(char devide = ' ')
        {
            return Read().Split(devide);
        }

        public static T[] ReadSplit<T>(char devide = ' ')
        {
            return ReadSplit(devide)
                .Select(s => (T)Convert.ChangeType(s, typeof(T)))
                .ToArray();
        }

        public static IEnumerable<T[]> ReadSplitRepeat<T>(int count, char devide = ' ')
        {
            return Enumerable.Range(0, count).Select(_ => ReadSplit<T>(devide));
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
long ans=0;
void calc(int x,int y){
  if(y+2==x) {
    ans++;}
  if(y+3==x){
    ans++;}
  if(y+1==x) {
    ans++;
    return;
  }
  if(y>x) return;
  calc(x,y+1);
  calc(x,y+2);
  calc(x,y+3);
}
  
int main(){
  int a;
  while(1){
    ans=0;
    cin>>a;
    if(a==0) break;
    int c=0,b=0;
    calc(a,0);
    b=ans;
    while(1){
      if(b<=3650){
	c++;
	break;
      }
      c++;
      b-=3650;
    }
    cout<<c<<endl;
  }
  return 0;
}



Measured memory_bytes: 3004
def solv(arr):
    cnt = [[0, i] for i in range(100000+1)]
    for x in arr:
        cnt[x][0] += 1
    cnt.sort()
    cnt.reverse()
    return cnt


n = int(input())
v = [int(x) for x in input().split()]
even = []
odd = []
for i in range(len(v)):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])
cnt1 = solv(even)
cnt2 = solv(odd)
ans = min(n-cnt1[0][0]-cnt2[1][0], n-cnt1[1][0]-cnt2[0][0]
          ) if cnt1[0][1] == cnt2[0][1] else n - cnt1[0][0] - cnt2[0][0]
print(ans)


Measured memory_bytes: 34844
from math import sqrt, cos, radians
a, b, h, m = map(int, input().split())
x = h * 30
if m != 0:
    x += 30 / (60 / m)
y = m * 6
c = min(abs(x - y), 360 - abs(x - y))
#print(abs(x - y) % 180, 2 * a * b * cos(abs(x - y) % 180), cos(radians(abs(x - y) % 180)))
print(sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(radians(c))))

Measured memory_bytes: 9448
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
//#define endl "\n"
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
ll mod = 998244353;
const double pi = acos(-1.0);



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    ll n;
    cin>>n;
    vector<pair<ll, ll> > a(n);
    for(ll i=0;i<n;i++){
        ll x, y;
        cin>>x>>y;
        a[i] = {x, y};
    }
    int f1 = 0;
    for(ll i=0;i<n-2;i++){
        int f = 1;
        for(ll j=0;j<3;j++){
            if(a[i+j].first!=a[i+j].second)
            {
                f = 0;
                break;
            }
        }
        if(f)
        {
            f1 = 1;
            break;
        }
    }
    if(f1)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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

int main() {
  int n;
  string s;

  cin >> n >> s;

  int ans = 1;
  char tmp = s[0];

  REP(i, n) {
    if (s[i] == tmp) {
    } else {
      ans++;
      tmp = s[i];
    }
  }

  ANS(ans);
  return 0;
}


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

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef int64_t s64;
typedef uint64_t u64;
typedef uint32_t u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

const int N=1e5+5;
int n,X,b[N],l[N],u[N];
s64 w[N];int q[N];

s64 W(int i,int x)
{
	return max(s64(x-b[i])*u[i]+(s64)b[i]*l[i],(s64)x*l[i]);
}
bool check(s64 mid)
{
	int c=mid/X,y=mid%X;
	s64 mx=0;
	rep(i,1,n-c)chmax(mx,W(q[i],y));
	s64 sum=0;
	rep(i,n-c+1,n)sum+=w[q[i]];
	s64 ans=sum+mx;
	rep(i,n-c+1,n)chmax(ans,sum+w[q[n-c]]-w[q[i]]+W(q[i],y));
//	if(mid>=115&&mid<200)
//		int yyx=1;
	rep(i,1,n)ans-=(s64)l[i]*b[i];
	return ans>=0;
}

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
#endif
	cin>>n>>X;
	rep(i,1,n){b[i]=read();l[i]=read();u[i]=read();}
	
	rep(i,1,n)w[q[i]=i]=W(i,X);
	sort(q+1,q+n+1,[&](int x,int y){return w[x]<w[y];}); 
	
	s64 l=-1,r=(s64)n*X;
	while(l+1!=r)
	{
		s64 mid=(l+r)/2;
		if(check(mid))r=mid;
		else l=mid;
	}
	cout<<r;
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  if ((N*A) == B ) {
    cout << B << endl;
  }
  else if ((N*A) > B)  {
      cout << B << endl;
    }
    else {
      cout<< N*A << endl;
    }
  

  
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections;
using System.Linq;
using System.Collections.Generic;

public class Sample9{

	public static void Main(){

		List <int> numList = new List<int> ();

		while (true) {
			string line = Console.ReadLine ();

			if (line != null) {
				numList.Add (int.Parse(line));
			} else {
				break;
			}
		}
			
		foreach (int n in numList) {
			int result = getResult (n);
			Console.WriteLine (result);
		}

	}

	public static int getResult(int num){

		int count = 0;

		for (int i = 0; i <= 9; i++) {

			for (int j = 0; j <= 9; j++) {

				for (int k = 0; k <= 9; k++) {

					for (int l = 0; l <= 9; l++) {
						if (i + j + k + l == num) {
							count++;
						} else if (i + j + k + l > num) {
							break;
						} else {
							continue;
						}
					}
				}
			}
		}

		return count;
	}
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  unordered_map<string, int> left[N + 1];
  multiset<string> right[N + 1];
  
  for(int b = 0; b < (1 << N); b++){
    string front = "", back = "";
    int c = 0;
    for(int i = 0; i < N; i++){
      if(b & (1 << i)){
        front += S[i];
        c++;
      }
      else back = S[i] + back;
    }
    left[c][front + back]++;
  }
  
  for(int b = 0; b < (1 << N); b++){
    string front = "", back = "";
    int c = 0;
    for(int i = N; i < (N << 1); i++){
      if(b & (1 << (i - N))) back += S[i];
      else{
        front = S[i] + front;
        c++;
      }
    }
    right[c].insert(front + back);
  }
  
  long long num = 0;
  for(int c = 0; c <= N; c++){
    for(auto p : left[c]){
      num += p.second * right[c].count(p.first);
    }
  }
  
  cout << num << endl;
  
  return 0;
}

Measured memory_bytes: 63280
#include <cstdio>

int main(){
    int a,b;
    scanf("%d %d", &a, &b);
    if (a<b) printf("a < b\n");
    else if (a>b) printf("a > b\n");
    else if (a==b) printf("a == b\n");
    return 0;
}


Measured memory_bytes: 2592
#include <stdio.h>
int main(void){
  int A,B,ans;
  scanf("%d""%d",&A,&B);
    
  if(A<10){
    if(B<10){
      ans=A*B;
    }else{
      ans=-1;
    }
  }else{
    ans=-1;
  }

  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>

void gcd(int *n,int m){
	int a,b,c;
	if(*n>m){
		a=*n;
		b=m;
	}else {
		a=m;
		b=*n;
	}
	while(b!=0){
		c=a%b;
		a=b;
		b=c;
	}
	/*int tmp=*a%b;
	int i=1;
	for(i=1;i<=tmp;i++){
		if(*a%i==0&&b%i==0){
			if(max<i)max=i;
		}
	}
	
	*a=max;*/
	*n=a;
}

int main(){
	int n,x;
	scanf("%d%d",&n,&x);
	int moto[n],sa[n],i;
	for(i=0;i<n;i++){
		scanf("%d",&moto[i]);
		sa[0]=abs(moto[0]-x);
		if(i!=0)sa[i]=abs(moto[i]-moto[i-1]);
	}
	if(n==1){
		printf("%d\n",sa[0]);
		return 0;
	}
	int tmp=sa[0];
	gcd(&tmp,sa[1]);
	for(i=1;i<n;i++)gcd(&tmp,sa[i]);
	printf("%d\n",tmp);
	return 0;
}

Measured memory_bytes: 896
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <math.h>
using namespace std;


int main() {
	long long int X, i,j,A,B;
	cin >> X;
	for ( i = 1000; i >=0; --i)
	{
		for (long long int j = i-1; j >=0; --j)
		{
			A = pow(i, 5);
			B = pow(j, 5);
			if (abs(A - B) == X  )
			{
				cout << i << " " << j << endl;
				return 0;
			}
			else if (abs(A + B) == X)
			{
				cout << i << " " << (-j) << endl;
				return 0;
			}
		}
	}

}


Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int b[n];
	for(int i=0;i<n;i++)cin>>b[i];
	int c[n-1];
	for(int i=0;i<n-1;i++)cin>>c[i];
	int res = b[a[0]-1];
	for(int i=1;i<n;i++)
	{
		res+=b[a[i]-1];
		if(a[i-1]+1==a[i])
		{
			res+=c[a[i-1]-1];
		}
	}
	cout<<res<<endl;
	return 0;	
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		int count=0;
		long blueCount=0;
		long aAmari=0;
		
		Scanner sc=new Scanner(System.in);
		long N=sc.nextLong();
		long A=sc.nextLong();
		long B=sc.nextLong();
		//何回、A+Bの組み合わせが続くか
		long syou=N/(A+B);
		//A+Bのあまり
		long kaisu=N%(A+B);
		
			if(kaisu==0) {
				blueCount=A*syou;
			}else {
				if(kaisu<A) {
					blueCount=(A*syou)+kaisu;
				}else {
				aAmari=kaisu-A;
				if(aAmari<B) {
					blueCount=(A*syou)+A;
				}else {
					aAmari=aAmari-B;
					blueCount=(A*syou)+A+aAmari;
				}
				}
			}
		System.out.println(blueCount);
		
	}
 
}

Measured memory_bytes: 23892
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(void){
   double x1,y1,x2,y2;
   cin >> x1 >> y1;
   cin >> x2 >> y2;
   double d = pow(x1-x2, 2) + pow(y1-y2, 2);
   cout << fixed << setprecision(8) << sqrt(d);
   cout << endl;
}


Measured memory_bytes: 3288
n=int(input())
dp=[100000 for i in range(n+1)]
dp[0]=0
dp[1]=1
for i in range(1,n+1):
    dp[i]=min(dp[i],dp[i-1]+1)
    j=0
    while 6**j<=i:
        dp[i]=min(dp[i],dp[i-6**j]+1)
        j+=1
    j=0
    while 9**j<=i:
        dp[i]=min(dp[i],dp[i-9**j]+1)
        j+=1
print(dp[n])

Measured memory_bytes: 3864
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

ll dp[61][2][2][2] = {0};

void add(ll& a, int64_t b) { a = (a + b) % MOD; }

int nexta(int br, int a, int y) {
  if (br) {
    return (a || !y);
  } else {
    if (!a && y) return -1;
    return a;
  }
}

int nextb(int bl, int b, int x) {
  if (bl) {
    if (!b && !x) return -1;
    return b;
  } else {
    return (b || x);
  }
}

int main() {
  //
  ll l, r;
  cin >> l >> r;
  stringstream ssl, ssr;
  ssl << bitset<62>(l);
  ssr << bitset<62>(r);
  string sl = ssl.str();
  string sr = ssr.str();
  int curl = 0, curr = 0;
  while (sl[curl] == '0') {
    curl++;
  }
  while (sr[curr] == '0') {
    curr++;
  }
  dp[0][0][0][0] = 1;
  REP(d, 1, 62) {
    rep(a, 2) {
      rep(b, 2) {
        rep(c, 2) {
          ll prev = dp[d - 1][a][b][c];
          int bl = sl[d] - '0';
          int br = sr[d] - '0';
          int na, nb;
          // 0, 0
          na = nexta(br, a, 0);
          nb = nextb(bl, b, 0);
          if (na >= 0 && nb >= 0) {
            add(dp[d][na][nb][c], prev);
          }

          // 1, 0
          na = nexta(br, a, 1);
          nb = nextb(bl, b, 0);
          if (c && na >= 0 && nb >= 0) {
            add(dp[d][na][nb][1], prev);
          }

          // 1, 1
          na = nexta(br, a, 1);
          nb = nextb(bl, b, 1);
          if (na >= 0 && nb >= 0) {
            add(dp[d][na][nb][1], prev);
          }
        }
      }
    }
  }
  ll ans = 0;
  rep(a, 2) {
    rep(b, 2) { add(ans, dp[61][a][b][1]); }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll=long long;
using namespace std;
int main(){
 int n;
 cin>>n;
 int zoro=0;
 bool nazo=false;
 for(int i=0;i<n;i++){
     int a,b;
     cin>>a>>b;
     if(a==b) zoro++;
     else zoro=0;
     if(zoro==3) nazo=true;
 }
 if(nazo) cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
}


Measured memory_bytes: 3608