akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 200010, INF = 1e9;

map <int, int> MP;

int arr[N];

int32_t main() {
    int n, sum = 0;
    cin >> n;
    for(int i = 1; i <= n; i++) {
           cin >> arr[i];
           MP[arr[i]]++;
    }

    sort(arr + 1, arr + n + 1, greater <int> ());

    for(int i = 1; i <= n; i++) {
            int f = 0;
            if(MP[arr[i]]) {
                    MP[arr[i]]--;
                    for(int j = 30; j > 0; j--) {
                            if((1 << j) > arr[i] && MP[(1 << j) - arr[i]] > 0) {
                                       MP[(1 << j) - arr[i]]--;
                                       f = 1;
                                       break;
                            }
                    }
            }
            sum += f;
    }
    cout << sum << endl;


}


Measured memory_bytes: 40192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=(1ll<<20);
ll n,a[N],rmq[20][N],pos[N],lg[N];
priority_queue< pair<ll, pair<ll,ll> > >pq;
ll query(ll l,ll r){
    ll mid = (r-l)/2 + 1;
    ll d = lg[mid];
    return min(rmq[d][l] , rmq[d][r-2*((1ll<<d)-1)]);
}
void add(ll l,ll r){
    if(l>r)return;
    ll val = query(l,r-1);
    pq.push({-val,{l,r}});
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=0;i<n;i++)cin>>a[i],a[i]--,pos[a[i]]=i;
    lg[0]=0;
    for(ll i=1;i<=n;i++){
        ll d = lg[i-1];
        if( (1<<(d+1))<=i )d++;
        lg[i]=d;
    }
    for(ll i=0;i<n;i++)rmq[0][i]=a[i];
    for(ll d=1,l=2;d<20;d++,l*=2){
        for(ll i=0;i<n;i++){
            rmq[d][i] = rmq[d-1][i];
            if(i+l<n)rmq[d][i] = min(rmq[d][i] , rmq[d-1][i+l]);
        }
    }

    add(0,n-1);
    for(ll i=0;i<n/2;i++){
        auto node = pq.top();
        pq.pop();

        ll l = node.second.first;
        ll r = node.second.second;

        ll v1 = query(l,r-1);
        ll p1 = pos[v1];

        ll v2 = query(p1+1,r);
        ll p2 = pos[v2];

        cout<<v1+1<<" "<<v2+1<<" ";
        add(l,p1-1);
        add(p1+1,p2-1);
        add(p2+1,r);
    }
}


Measured memory_bytes: 49268
#include<cstdio>
using namespace std;
int n,a[505],b[505];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&a[i],&b[i]);
	for(int i=1;i<=n-2;++i)
		if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2])
		{
			printf("Yes");
			return 0;
		}
	printf("No");
	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

// 参考URL
// https://drken1215.hatenablog.com/entry/2019/02/10/014800
// https://betrue12.hateblo.jp/entry/2019/02/10/014031

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    auto calc = [&](int nxt, int val) -> int {
        if(nxt == 0 || nxt == 4)    return val;
        else if(nxt == 1 || nxt == 3){
            if(val == 0)    return 2;
            else    return val % 2;
        }
        else    return (val % 2) ^ 1;
    };
    constexpr ll inf = 1e+15;
    vector<vector<ll>> dp(n + 1, vector<ll>(5, inf));
    dp[0][0] = 0;
    for(int i = 0; i < n; ++i){
        // cout << "i:" << i << endl;
        for(int j = 0; j < 5; ++j){
            for(int k = j; k < 5; ++k){
                // cout << k << ' ' << a[i] << ' ' << calc(k, a[i]) << endl;
                chmin(dp[i + 1][k], dp[i][j] + calc(k, a[i]));
            }
        }
    }
    ll ans = inf;
    for(int i = 0; i < 5; ++i)  chmin(ans, dp[n][i]);
    cout << ans << endl;
    // cout << "DP\n";
    // for(int i = 0; i <= n; ++i){
    //     for(int j = 0; j < 5; ++j){
    //         if(dp[i][j] == inf) cout << "x ";
    //         else    cout << dp[i][j] << ' ';
    //     } cout << endl;
    // }
}

Measured memory_bytes: 17852
function Main(input) {
  input=input.split("\n");
　var string=input[0];
  var ret=[];
  for(var i=0;i<string.length;i++){
    if(string[i]==="B"){
      ret.pop();
    }else{
      ret.push(string[i]);
    }
  }
  console.log(ret.join(""));
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


Measured memory_bytes: 29564
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<int,int> P;


int main(){
    int H, W, K;
    cin >> H >> W >> K;
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;
    x2--;
    y1--;
    y2--;

    vector<int> dx(4), dy(4);
    dx[0] = 1; dx[1] = 0; dx[2] = -1; dx[3] = 0;
    dy[0] = 0; dy[1] = 1; dy[2] = 0; dy[3] = -1;

    vector<string> lotus(H);

    vector<vector<int>> cnt(H, vector<int>(W, -1));

    rep(i,H) {
        cin >> lotus[i];
    }

    cnt[x1][y1] = 0;

    queue<P> q;
    q.push(make_pair(x1,y1));

    while(!q.empty()) {
        P now = q.front();
        q.pop();
        int nx = now.first, ny = now.second;
        rep(i,4) {
            rep1(j,K) {
                int tx = nx + dx[i] * j;
                int ty = ny + dy[i] * j;
                if (tx < 0 || tx >= H || ty < 0 || ty >= W) break;
                if (lotus[tx][ty] == '@') break;
                if (cnt[tx][ty] == -1) {
                    cnt[tx][ty] = cnt[nx][ny] + 1;
                    q.push(make_pair(tx,ty));
                    continue;
                }
                if (cnt[tx][ty] <= cnt[nx][ny]) break;
                if (cnt[tx][ty] > cnt[nx][ny]+1) q.push(make_pair(tx,ty));
                cnt[tx][ty] = min(cnt[tx][ty],cnt[nx][ny]+1);
            }
        }
    }

    cout << cnt[x2][y2] << endl;
}

Measured memory_bytes: 11112
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)
#define AAA (1000000007)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


int main() {
	int i, j, k;
	ll N, M;
	cin >> N;

	ll X = (ll) N / 1.08;

	if ((ll)(X * 1.08) != N && (ll)(X * 1.08 + 1.08) != N)
		cout << ":(";
	else if ((ll)(X * 1.08 + 1.08) == N)
		cout << X +1;
	else
		cout << X;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, m;
    cin >> n >> m;
    ll cnt = 0;
    cnt += min(n, m/2);
    n -= cnt;
    m -= 2*cnt;
    cnt += m/4;
    cout << cnt << endl;
}

Measured memory_bytes: 256
use std::collections::HashMap;
use std::cmp::min;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n:usize = read();
    let mut v:Vec<Vec<char>> = vec![];
    for _ in 0..n{
        v.push(read::<String>().chars().collect());
    }
    let count_v:Vec<_> = v.into_iter().map(|x| {
        x.into_iter().fold(HashMap::new(),|mut map,x|{
            let y = map.get(&x).map(|i| i+1).unwrap_or(1);
            map.insert(x,y);
            map
        })
    }).collect();
    let char_v = (b'a'..b'z'+1).map(|x| x as char).collect::<Vec<char>>();
    let mut ans= char_v.into_iter()
    .fold(HashMap::new(),|mut map,x|{
        let min =  count_v.iter()
        .fold(1e10 as i64,|a,b|{
            let v: i64 = b.get(&x).map(|i| *i).unwrap_or(0);
            min(a,v)
        });
        map.insert(x,min);
        map
    }).into_iter().collect::<Vec<_>>();
    ans.sort();
    let ans:String = ans
    .into_iter()
    .flat_map(|(c,x)| vec![c;x as usize])
    .collect();
    println!("{}",ans );
}

Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(2000000)
n,m=map(int,input().split())
path={i:[] for i in range(n)}
for i in range(m):
  a,b=map(int,input().split())
  path[a-1].append(b)
  path[b-1].append(a)
sign=[0]*n

def bfs(poslist,sign):
  if len(poslist)==0:
    return sign
  nex=[]
  for pos in poslist:
    lis = [x for x in path[pos-1] if sign[x-1]==0]
    for i in lis:
      sign[i-1]=pos
      nex.append(i)
  return bfs(nex,sign)
      
  
sign=bfs([1],sign)
print('Yes')
for i in range(1,n):
  print(sign[i])

Measured memory_bytes: 166596
N = int(input())
S = [input() for _ in range(N)]

AC = 0
WA = 0
TLE = 0
RE = 0

for s in S:
    if s == 'AC':
        AC += 1
    elif s == 'WA':
        WA += 1
    elif s == 'TLE':
        TLE += 1
    elif s == 'RE':
        RE += 1
    else:
        pass

print('AC x ' + str(AC))
print('WA x ' + str(WA))
print('TLE x ' + str(TLE))
print('RE x ' + str(RE))


Measured memory_bytes: 79180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, n, m;
  in2(n, m);
  a = b = 0;
  vector<pair<ll, ll>> c(n);
  rep(i, n)
    in2(c[i].first, c[i].second);
  sort(all(c));
  priority_queue<ll> d;
  rep2(i, 1, m + 1){
    if(b < n){
      while(c[b].first == i){
        d.push(c[b].second);
        b++;
        if(b == n)
          break;
      }
    }
    if(!d.empty()){
      a += d.top();
      d.pop();
    }
  }
  out(a);
  memi;
}


Measured memory_bytes: 2936
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int n;
    cin >> n;
    ll ans=0;
    REP(i,n+1){
        if(i%3==0 || i%5==0) continue;
        ans+=i;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=2e6+7;
int a[MAXN],b[MAXN],cnt[10005];
int main () {
	int n,mx=0;
	scanf ("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf ("%d",&a[i]);
		cnt[a[i]]++;
		mx=max(mx,a[i]);
	}
	for (int i=1;i<=mx;i++) {
		cnt[i]+=cnt[i-1];
	}
	for (int i=n;i>0;i--) {
		b[cnt[a[i]]]=a[i];
		cnt[a[i]]--;
	}
	printf ("%d",b[1]);
	for (int i=2;i<=n;i++) {
		printf (" %d",b[i]);
	}
	printf ("\n");
    return 0;
}


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

int main(void){
    int X;cin>>X;
    int ans=0;
    for(int i=1;i<=X;i++){
        for(int j=1;j<33;j++){
            for(int k=2;k<10;k++){
                if(i==pow(j,k)&&ans<pow(j,k)){
                    ans=pow(j,k);
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4048
#include<iostream>
#include<cmath>
#include<unordered_map>
#include<math.h>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#include<iomanip>
#include<string>
#include<map>
#define PI 3.14159265
#define mod 998244353    
using namespace std;

 

void func(){
    long long n,ans = 0 , k ;
    cin >> n  ;
    long long arr[3][n] , dp[3][n] = {0};

    for(int i = 0 ; i < n ; ++i){
      cin >> arr[0][i] >> arr[1][i] >> arr[2][i];
      //cout << arr[2][i] << "\n";
    }

    dp[0][0] = arr[0][0];
    dp[1][0] = arr[1][0];
    dp[2][0] = arr[2][0];

    for(int i = 1 ; i < n ; ++i){
      dp[0][i] = max(dp[1][i - 1] , dp[2][i - 1]) + arr[0][i];
      dp[1][i] = max(dp[0][i - 1] , dp[2][i - 1]) + arr[1][i];
      dp[2][i] = max(dp[1][i - 1] , dp[0][i - 1]) + arr[2][i];
    }
cout << max(dp[0][n - 1] , max(dp[1][n - 1] , dp[2][n - 1]));
return;
     
}
int main(){
    int t = 1 , cnt = 0 ;
  // cin >> t;
    
    while(t--){
        
        func();
    }
}

Measured memory_bytes: 4992
Period, WorkingDay, PausePeriod = map(int, input().split())
S = input()
SReverse = S[::-1]

"""
Calculate the day that you can work the fastest and the day that you can work
the slowest. If two days coincide, that day is always a working day.
"""
earliest_days = [-1 for _ in range(Period)]
slowest_days = [-2 for _ in range(Period)]

for days in (earliest_days, slowest_days):
    i_day = 0
    if days == earliest_days:
        i_work_day = 1
        diff_from_next_work = 1
        passion_days = S
    else:
        i_work_day = WorkingDay
        diff_from_next_work = - 1
        passion_days = SReverse
    
    while 1 <= i_work_day and i_work_day <= WorkingDay:
        if passion_days[i_day] == 'o':
            days[i_day] = i_work_day
            i_work_day += diff_from_next_work
            i_day += PausePeriod
        i_day += 1

slowest_days.reverse()
for i_day in range(Period):
    if earliest_days[i_day] == slowest_days[i_day]:
        print(i_day + 1)

exit()

Measured memory_bytes: 58216
import java.util.*;

class Main {
    public static void main(String[] args) throws Exception {
        int H1;
        int M1;
        int H2;
        int M2;
        int K;
        try (Scanner scanner = new Scanner(System.in)) {
            H1 = scanner.nextInt();
            M1 = scanner.nextInt();
            H2 = scanner.nextInt();
            M2 = scanner.nextInt();
            K = scanner.nextInt();
        } catch (Exception e) {
            throw e;
        }

        int start = H1 * 60 + M1;
        int end = H2 * 60 + M2;
        System.out.println(end-start-K);
    }
}

Measured memory_bytes: 35700
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
const int mod=1e9+7;

int main()
{
  int n;
  while(true){
  	cin>>n;
  	if(n==1) break;
  	int ref = n;
  	std::vector<int> v;
  	for(int i =2; i <= sqrt(n) ;i++){
  		if(n%i==0) {
  			v.push_back(i);
  			if(i==n/i) continue;
  			v.push_back(n/i);
  		}
  	}
  	std::vector<int> ans;
  	v.push_back(ref);
  	sort(v.begin(),v.end());
  	for(int i =0;i<v.size();i++){
  		std::vector<int> p;
  		bool pp = false;
  		if(v[i]%7==1 or v[i]%7==6) pp=true;
  		if(!pp) continue;
  		for(int j =2;j<sqrt(v[i])+1;j++){
  			// cout<<j<<endl;64

  			if(v[i]%j==0) {
  				p.push_back(j);
  				p.push_back(n/j);
  			}
		}

  		bool flg = true;
  		for(int j=0;j<p.size();j++){
  			if(p[j]%7==1 or p[j]%7==6) flg=false;
  		}
  		if(flg==true) ans.push_back(v[i]);
  	}
  	cout<<ref<<":";
  	// int prev=-1;
  	for(int i = 0;i<ans.size()-1;i++){
        // if(prev==ans[i]) continue;
  		cout<<" "<<ans[i];
  		// prev=ans[i];
  	}
  	cout<<" "<<ans[ans.size()-1]<<endl;
}
}


Measured memory_bytes: 3000
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        System.out.println(z + " " + x + " " + y);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
pair<int,int> book[10];
double dis(pair<int,int> a,pair<int,int> b)
{
	return sqrt((a.fi-b.fi)*(a.fi-b.fi)+(a.se-b.se)*(a.se-b.se));
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cin>>book[i].fi>>book[i].se;
	double ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			ans+=dis(book[i],book[j])*2/n;
		}
	}
	cout<<fixed<<setprecision(8)<<ans<<'\n';
    return 0;
}



Measured memory_bytes: 256
import math
a = list(map(int, input().split()))
ans = [max([a[0] / 0.08, a[1] / 0.1]),
       min([(a[0] + 1) / 0.08, (a[1] + 1) / 0.1])]
if ((a[0]) / 0.08 >= (a[1] + 1) / 0.1) or (a[1] / 0.1 >= (a[0] + 1) / 0.08):
    print(-1)
else:
    if math.ceil(ans[0]) > ans[1]:
        print(-1)
    else:
        print(math.ceil(ans[0]))

Measured memory_bytes: 38384
def main():
    n = int(input())
    a = list(map(int,input().split()))
    ans = 1
    if 0 in a: 
        print (0)
        return
    for i in range(n):
        ans = ans*a[i]
        if ans>10**18:
            print(-1)
            break
        else:
            pass
    

    if ans<=10**18:
        print(ans)
   

    
main()


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

using namespace std;

#define ll long long

const int N = 3003;
ll dp[N][N];
int a[N];

int main() {
	int n;
	scanf("%d", &n);
	bool b = n & 1;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		dp[i][i] = b ? a[i] : -a[i];
	}
	for (int i = 2; i <= n; i++) {
		for (int l = 0, r = i - 1; r < n; l++, r++) {
			if (b ^ (i & 1)) {
				dp[l][r] = min(dp[l+1][r] - a[l], dp[l][r-1] - a[r]);
			} else {
				dp[l][r] = max(dp[l+1][r] + a[l], dp[l][r-1] + a[r]);
			}
		}
	}
	printf("%lld", dp[0][n-1]);
	return 0;
}


Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
#ifdef DEBUG
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)\
	{cerr << #a << " = {";\
	for(int qwq = (st); qwq <= (n); ++qwq) {\
		if(qwq == (st)) cerr << a[qwq];\
		else cerr << ", " << a[qwq];\
	} cerr << "}" << endl;}
#define displayv(v) displaya(v, 0, (int)(v).size() - 1)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define display(x) ;
#define displaya(a, st, n) ;
#define displayv(v) ;
#define eprintf(...) if(0) fprintf(stderr, "...")
#endif
template<typename T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template<typename T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; }

const int maxN = 100000 + 233;
int n;
LL X;
LL b[maxN], l[maxN], u[maxN];

LL got(int i, LL t) {
	if(t <= b[i]) return t * l[i];
	else return t * u[i] - (u[i] - l[i]) * b[i];
}

LL check(LL T) {
	vector< pair<LL, int> > vp;
	for(int i = 1; i <= n; ++i)
		vp.emplace_back(got(i, X), i);
	sort(vp.begin(), vp.end());
	
	int cnt = T / X;
	LL res = T % X;
	
	if(cnt == n) {
		LL ans = 0;
		for(int i = 1; i <= n; ++i) ans += got(i, X);
		return ans;
	}
	
	LL base = 0;
	LL mxd = -vp.back().first;
	while(cnt--) {
		base += vp.back().first;
		int i = vp.back().second;
		chmax(mxd, got(i, res) - got(i, X));
		vp.pop_back();
	}
	mxd += vp.back().first;
	while(vp.size()) {
		int i = vp.back().second;
		chmax(mxd, got(i, res));
		vp.pop_back();
	}
	return base + mxd;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> X;
	for(int i = 1; i <= n; ++i) cin >> b[i] >> l[i] >> u[i];
	LL L = 0, R = std::accumulate(b + 1, b + n + 1, 0LL);
	LL sum = 0;
	for(int i = 1; i <= n; ++i) sum += l[i] * b[i];
	while(L < R) {
		LL M = (L + R) >> 1;
		if(check(M) >= sum) R = M;
		else L = M + 1;
	}
	cout << L << endl;
	return 0;
}


Measured memory_bytes: 6812
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <climits>
#include <functional>
#include <string>
#include <sstream>

#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    int a[H][W];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> a[i][j];
        }
    }
    int count = 0;
    bool carry = false;
    stringstream ans;
    stringstream tmp;
    
    for(int i = 0; i < H; i+=2){
        for(int j = 0; j < W; j++){
            if(carry){
                a[i][j]++;
                //ans = ans +"\n"+tmp+ to_string(i+1) +" "+ to_string(j+1);
                ans << "\n"<<tmp.str()<< to_string(i+1) <<" "<< to_string(j+1);
                carry = false;
                count++;
            }
            if(a[i][j] % 2 == 0){
                continue;
            }else{
                a[i][j]--;
                carry = true;
                tmp.str("");
                tmp <<to_string(i+1) <<" "<< to_string(j+1) << " ";
            }
        }
        if(i+1 < H){
            for(int j = W-1; j >= 0; j--){
                if(carry){
                    a[i+1][j]++;
                    ans <<"\n"<<tmp.str()<< to_string(i+1+1) <<" "<< to_string(j+1);
                    carry = false;
                    count++;
                }
                if(a[i+1][j] % 2 == 0){
                    continue;
                }else{
                    a[i+1][j]--;
                    carry = true;
                    tmp.str("");
                    tmp << to_string(i+1+1) <<" "<< to_string(j+1) + " ";
                }
            }
        }
    }
    string final = to_string(count) +ans.str();
        
    cout << final << endl;
    return 0;
}

Measured memory_bytes: 6916
import java.util.Scanner;

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

/**
 *
 * @author Jiakang Chen
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int M = sc.nextInt();
        
        Box[] B = new Box[N];
        B[0] = new Box(1, true);
        
        for (int i = 1; i < N; i++) {
            B[i] = new Box(1, false);
        }
        
        for (int i = 0; i < M; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            
            B[x].moveTo(B[y]);
        }
        
        int counter = 0;
        
        for (Box b : B) {
            if (b.red) {
                counter++;
            }
        }
        
        System.out.println(counter);
    }
}

class Box {
    public int num;
    public boolean red;
    
    public Box(int n, boolean r) {
        num = n;
        red = r;
    }
    
    public void moveTo(Box other) {
        if (num == 0) {
            return;
        } else if (num == 1) {
            num = 0;
            other.num++;
            
            if (red) {
                other.red = true;
            }
            
            red = false;
        } else {
            num--;
            other.num++;
            
            if (red) {
                other.red = true;
            }
        }
    }
}

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


int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  
  bool oneabsence = true;
  
  for (int i =0; i<n; i++){
    cin >> a.at(i);
    oneabsence *= (a.at(i) != 1);
  }
  
  int ans;
  if (oneabsence){
    ans = -1;
  }else{
    ans = 0;
    int searchedFor = 1;
    
    for(int i = 0; i< n; i++){
      if( a.at(i) == searchedFor){
        searchedFor++;
      }else{
        ans++;
      }
    }
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  ll x;
  cin >> x;
  ll a = 100;
  for(int i = 1; i < 10000; i++) {
    a = a * 1.01;
    if(a >= x){
      cout << i << endl;
      return 0;
    }
  }
    return 0;
}

Measured memory_bytes: 3624
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const int SIZE = 30;
const int AREA = SIZE * SIZE;
const int VOLUME = AREA * SIZE;

int w, h;
int p[10][10], label[10][10];
bool visited[10][10];
vector<int> sum;
vector<map<int, int> > to;

bool out(int x, int y) {
	return x < 0 || y < 0 || x >= w || y >= h;
}

int labelling(int x, int y, int idx) {
	int res = 1;
	label[y][x] = idx;
	for(int i = 0; i < 4; ++i) {
		const int nx = x + dx[i], ny = y + dy[i];
		if(out(nx, ny))
			continue;

		if(label[ny][nx] == -1 && p[ny][nx] == p[y][x])
			res += labelling(nx, ny, idx);
	}

	return res;
}

void dfs(int x, int y) {
	visited[y][x] = true;
	for(int i = 0; i < 4; ++i) {
		const int nx = x + dx[i], ny = y + dy[i];
		if(out(nx, ny)) {
			++sum[label[y][x]];
			continue;
		}

		if(label[ny][nx] == label[y][x]) {
			if(!visited[ny][nx])
				dfs(nx, ny);
		}

		else if(p[ny][nx] < p[y][x]) {
			if(p[ny][nx])
				++to[label[y][x]][label[ny][nx]];
			
			++sum[label[y][x]];
		}
	}
}

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

	while(cin >> w >> h, w) {
		int fx, fy, fq;
		cin >> fx >> fy >> fq;

		for(int i = 0; i < h; ++i)
			for(int j = 0; j < w; ++j)
				cin >> p[i][j];

		memset(label, -1, sizeof(label));
		vector<int> components;
		int num = 0;
		for(int i = 0; i < h; ++i)
			for(int j = 0; j < w; ++j)
				if(p[i][j] > 0 && label[i][j] == -1)
					components.push_back(labelling(j, i, num++));

		vector<bool> used(num, false);
		sum.clear();
		sum.resize(num, 0);
		to.clear();
		to.resize(num);
		set<pair<int, int> > s;

		for(int i = 0; i < h; ++i)
			for(int j = 0; j < w; ++j)
				if(label[i][j] >= 0 && !used[label[i][j]]) {
					used[label[i][j]] = true;
					memset(visited, false, sizeof(visited));
					dfs(j, i);
					s.insert(make_pair(p[i][j], label[i][j]));
				}

		int l;
		cin >> l;

		for(int i = 0; i < l; ++i) {
			int t, x, y;
			cin >> t >> x >> y;

			const int target = label[y][x];

			vector<double> flow(num, 0);
			flow[label[fy][fx]] = t * fq;

			set<pair<int, int> >::reverse_iterator it = s.rbegin();
			for(; it != s.rend(); ++it) {
				const int l = it->second;
				if(l == target) {
					const int ans = flow[l] / (AREA * components[l]);
					cout << (ans > SIZE ? 30 : ans) << endl;
					break;
				}

				if(flow[l] > (VOLUME * components[l])) {
					const double over = flow[l] - (VOLUME * components[l]);
					map<int, int>::const_iterator it2 = to[l].begin();
					for(; it2 != to[l].end(); ++it2) {
						flow[it2->first] += over * ((double)it2->second / sum[l]);
					}
				}
			}
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1260
num = int(input())

times = []
limits = []
for i in range(num):
	line = input().split(' ')
	times.append(int(line[0]))
	limits.append(int(line[1]))

time_limit = zip(limits, times)
test = sorted(time_limit)

times, limits = [], []
for limit, time in test:
	times.append(int(time))
	limits.append(int(limit))

now = 0
judge = True

for time, limit in zip(times, limits):
	now += time
	if now > limit:
		judge = False
		print('No')
		break

if judge:
	print('Yes')


Measured memory_bytes: 35660
using System;
using System.Linq;

class Program
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        long[] x = (from elem in Console.ReadLine().Split(' ') select long.Parse(elem)).ToArray();
        long[] y = (from elem in Console.ReadLine().Split(' ') select long.Parse(elem)).ToArray();
        long[] abss = x.Select((elem, index) => Math.Abs(elem - y[index])).ToArray();
        Console.WriteLine(abss.Sum());
        Console.WriteLine(Math.Sqrt(abss.Select(elem => elem * elem).Sum()));
        Console.WriteLine(Math.Pow(abss.Select(elem => elem * elem * elem).Sum(), 1.0 / 3.0));
        Console.WriteLine(abss.Max());
    }
}


Measured memory_bytes: 18420
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

vector<int> tsort_Kahn(const vector<vector<int>>& g){
  const int V = g.size();
  vector<int> indeg(V, 0);
  stack<int> S;

  for(auto& u_out_edges : g){
    for(auto& v : u_out_edges){
      indeg[v]++;
    }
  }

  REP(i, V) if(indeg[i] == 0) S.push(i);

  vector<int> ans;
  while(S.size()){
    int u = S.top(); S.pop();
    ans.emplace_back(u);
    for(auto& v : g[u]){
      indeg[v]--;
      if(indeg[v] == 0) S.push(v);
    }
  }
  return ans;
}

signed main() {
  int N, M; 
  cin >> N >> M;

  vector<int> x(N+M-1), y(N+M-1);
  vector<vector<int>> graph(N);
  REP(i, N+M-1){
    cin >> x[i] >> y[i];
    x[i]--; y[i]--;
    graph[x[i]].emplace_back(y[i]);
  }

  vector<int> vec = tsort_Kahn(graph);

  vector<int> pos(N, 0);
  REP(i, N){
    pos[vec[i]] = i;
  }

  vector<int> parent(N, -1);
  REP(i, N+M-1){
    chmax(parent[pos[y[i]]], pos[x[i]]);
  }

  vector<int> ans(N);
  REP(i, N){
    if(parent[i] == -1) ans[vec[i]] = 0;
    else ans[vec[i]] = vec[parent[i]]+1;
  }

  REP(i, N){
    cout << ans[i] << endl;
  }

  return 0;
}

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

int main() {
  
int A, B; cin >> A >> B;
int r = 0;
for(int i = A; i <= B; i++){
  
  int s = i % 10, t = i / 10000 % 10;
  int u = i / 10 % 10, v = i / 1000 % 10;
  
  if (s==t && u==v){r++;}
}
cout << r << endl;
}



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

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 5005;
const int KMAX = 5005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
// #define DEBUG


// frequently used macros
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << "(DUMP) " << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<vec> mat;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// freawuently used structs
struct edge{
    int to,cost;
};

// printf for debug
void debug(const char* format, ...){
    #ifndef DEBUG
    return;
    #else
    va_list arg;
    va_start(arg, format);
    vprintf(format, arg);
    va_end(arg);
    #endif
}

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
    cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
    mid = (_begin + _end) / 2LL;
    if(f(mid)) {
      debug("BSearch: f(%d) == true\n", mid);
      _end = mid;
    }
    else
    {
      debug("BSearch: f(%d) == false\n", mid);
      _begin = mid;
    }
  }
  return _end;
}


int N,M,K,A[NMAX],B,D,E;
bool dp[NMAX][KMAX] = {};

string S;
vec v;

ll ans = 0;

bool C(int x){
  debug("x == %d, A[x] == %d\n", x, A[x]);
  Fill(dp, false);
  dp[0][0] = true;
  for (int i = 1; i <= N; ++i)
  {
    for (int j = 0; j < K; ++j)
    {
      if (!dp[i-1][j]) continue;

      dp[i][j] = true;
      if(i != x) dp[i][min(j + A[i], K)] = true;

      if (j >= K - A[x]
      || (i != x && j + A[i] >= K - A[x] && j + A[i] < K))
        return true;
    }
    DUMPV(dp[i], K);
  }
  return false;
}

void solve(){
    // main algorithm
    sort(A+1, A+1+N);
    DUMPV(A, N+1);
    ans = BSearch(0, N + 1, C) - 1LL;
}
void debug(){
    // output debug information
}
void answer(){
    // output answer
    printf("%lld\n", ans);
}
int main(int argc, char const *argv[])
{
    // operate inputs

    // Fill(dp, -1);
    scanf("%lld%lld", &N,&K);
    for (int i = 1; i <= N; ++i)
    {
        scanf("%lld", &A[i]);
    }
    solve();
    #ifdef DEBUG
    debug();
    #endif
    answer();

    return 0;
}

Measured memory_bytes: 24704
#include<stdio.h>
#include<algorithm>
int n,k,t,u,v,l,stock=0,p=0,c=0;
bool carrot[10000];
int main(){
    scanf("%d %d %d %d %d %d",&n,&k,&t,&u,&v,&l);
    for(int i=0;i<n;i++){
        int d;
        scanf("%d",&d);
        carrot[d]=true;
    }
    for(int i=0;i<l;i++){
        if(carrot[i]&&stock==k){
            p=v*t;
        }
        if(carrot[i]&&stock<k){
            stock++;
        }
        if(!p&&stock){
            p=v*t;
            stock--;
        }
        if(p){
            c++;
            p--;
        }
    }
    printf("%.9f\n",(double)c/v+(double)(l-c)/u);
}

Measured memory_bytes: 1072
function Main(input){
  const splitted = input.split(' ').map(elem => parseInt(elem));
  const ab = splitted[0];
  const bc = splitted[1];
  const ca = splitted[2];
  
  console.log(ab * bc / 2);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}





///////////////////////////




int main() {
	ll K, N;
	cin >> N >> K;

	cout << (N - 2) / (K - 1) + 1;


	system("PAUSE");

}


Measured memory_bytes: 504
#b faster
#m_i(k) = min(m_i(k-1), a_(i-k))
# http://agc004.contest.atcoder.jp/data/agc/004/editorial.pdf
n,x =  [int(i) for i in input().split()]
a   =  [int(i) for i in input().split()]
m   =  a[::]
a.extend(a)

min_cost = sum(m)

for k in range(n):
    #cost = x * k
    for i in range(n,2*n):
        m[i-n] = min(m[i-n], a[i-k])
        #cost += mini
    min_cost = min(min_cost, x*k + sum(m))
print(min_cost)

Measured memory_bytes: 3188
from fractions import gcd
A, B, K = map(int, input().split())
c = 0
for i in range(min(A,B)):
  j = min(A,B)-i
  if A%j==0 and B%j==0:
    c += 1
    #print(j)
    if c == K:
      print(j)
      exit()
  

Measured memory_bytes: 5048
N, M, X = map(int, input().split())
books = [input() for i in range(N)]
result = 12 * 10**5 + 1
for i in range(1, 1 << N):
  cost = 0
  skill = [0 for i in range(M)]
  for j in range(N):
    if (i >> j) & 1:
      book = books[j].split()
      cost += int(book[0])
      for k in range(M):
        skill[k] += int(book[k + 1])
  if all(j >= X for j in skill):
    result = min(result, cost)
if result == 12 * 10**5 + 1:
  print(-1)
else:
  print(result)

Measured memory_bytes: 9064
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K<=A) cout << K;
    if(A<K && K<=A+B) cout << A;
    if(A+B<K) cout << A-(K-A-B);
    return 0;
}

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


int main(){
	LL a, b;cin >> a >> b;
    LL ans = 1;
	if(a<=0&&0<=b) {
		cout << "Zero" << endl;
		return 0;
	}
	if(0<a||(b-a)%2!=0) {
		cout << "Positive" << endl;
		return 0;
	}
	if((b-a)%2==0){
		cout << "Negative" << endl;
		return 0;
	}	
	return 0;
}












Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = 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;
    }
}
// 二項係数計算
long long 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;
}
vector<int> Eratosthenes(const int N)
{
    vector<bool> is_prime(N+1, true);
    vector<int> P;
    for(int i=2; i<=N; i++) {
        if (is_prime[i]) {
            for(int j=2*i; j<=N; j+=i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i,n) {
        cin >> h[i];
    }
    if (n==1) {
        cout << "Yes" << "\n";
        return 0;
    }
    bool j = true;
    rep(i,n-1) {
        if (h[i] < h[i+1]) {
            h[i+1]--;
        } else if (h[i]==h[i+1]) {
            continue;
        }
        if (h[i] > h[i+1]) {
            cout << "No" << "\n";
            return 0;
        } 
    }
    cout << "Yes" << "\n";
}

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

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

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

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

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

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

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

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

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

use std::collections::BTreeMap;

fn main() {
    input!{
        n: usize,
        m: usize,
        s: chars,
        t: chars,
    }

    let l = n * m / gcd(n, m);
    let mut mm = BTreeMap::new();

    for (i, c) in s.into_iter().enumerate() {
        mm.insert(l / n * i, c);
    }

    let mut ok = true;
    for (i, c) in t.into_iter().enumerate() {
        if let Some(d) = mm.get(&(l / m * i)) {
            if c != *d {
                ok = false;
            }
        }
    }

    let ans = if ok { l as i64 } else { -1 };

    println!("{}", ans);
}

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (c <= a + b) cout << b + c << endl;
    else cout << a + 2*b + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF ((int)1e9)
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  vector<vector<int>> dp(s.length() + 1, vector<int>(2));
  dp[0][1] = 1;
  for(int i = 0; i < s.length(); i++) {
    int d = s[i] - '0';
    dp[i + 1][0] = min(dp[i][0] + d, dp[i][1] + 10 - d);
    dp[i + 1][1] = min(dp[i][0] + d + 1, dp[i][1] + 9 - d);
  }
  cout << dp[s.length()][0] << '\n';
}

Measured memory_bytes: 55964
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
struct node
{
	ll x;
	ll val;
	ll type;
	node() {}
	node(ll xx, ll vv, ll tt)
	{
		x = xx;
		val = vv;
		type = tt;
	}
	bool operator < (const node & b) const
	{
		if (x != b.x)
		{
			return x > b.x;
		} else
		{
			return type > b.type;
		}
	}
	void debug()
	{
		cout << x << " " << val << " " << type << endl;
	}
};
// type 1-> monster
// 2-> hp
int n;
ll d, a;
priority_queue<node> heap;
ll CEIL(ll x, ll y)
{
	return (x + y - 1) / y;
}
int main()
{
	//freopen("D:\\code\\text\\input.txt","r",stdin);
	//freopen("D:\\code\\text\\output.txt","w",stdout);
	n = readint(); d = readll(); a = readll();
	repd(i, 1, n)
	{
		ll x, y;
		x = readll(); y = readll();
		heap.push(node(x, y, 1));
	}
	ll now = 0ll;
	node temp;
	ll ans = 0ll;
	while (!heap.empty())
	{
		temp = heap.top();
		// temp.debug();
		heap.pop();
		if (temp.type == 2)
		{
			now -= temp.val;
		} else
		{
			temp.val -= now;
			if (temp.val > 0)
			{
				ll cnt = CEIL(temp.val , a);
				// chu(cnt);
				ans += cnt;
				now += cnt * a;
				heap.push(node(temp.x + 2ll * d, cnt * a, 2));
			}
		}
	}
	printf("%lld\n", ans );
	return 0;
}




Measured memory_bytes: 8432