akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MAX_V 100001
#define MOD 1000000007
typedef vector<vector<int> > Graph;

int main(){
    int n;cin>>n;
    set<string> s;
    for(int i=0;i<n;i++){
        string ss;cin>>ss;
        s.insert(ss);
    }
    cout<<s.size()<<endl;
}


Measured memory_bytes: 19228
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

int main(){
    ll n;
    cin>>n;
    ll ga,sa,ba;
    cin>>ga>>sa>>ba;
    ll gb,sb,bb;
    cin>>gb>>sb>>bb;
    
    auto calc=[](ll n,ll ga,ll sa,ll ba,ll gb,ll sb,ll bb){
        vector<ll> w={ga,sa,ba};
        vector<ll> v={max(gb-ga,0LL),max(sb-sa,0LL),max(bb-ba,0LL)};
        vector<vector<ll>> dp(4,vector<ll>(n+1));
        for(int i=0;i<3;i++){
            for(int j=0;j<=n;j++){
                dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
                if(j>=w[i]){
                    dp[i+1][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
                }
            }
        }
        return n+*max_element(dp[3].begin(),dp[3].end());
    };
    n=calc(n,ga,sa,ba,gb,sb,bb);
    n=calc(n,gb,sb,bb,ga,sa,ba);
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 976996
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int a[100];
    int sum=1;
    int n;
    for(int i=0;i<100;)
        {
            sum=sum+10;
            int j;
            int m=sqrt(sum);
            for( j=2;j<=m;j++)
            {
                if(sum%j==0)
                    break;
            }
              if(j>m)
           {
               a[i++]=sum;
           }
        }
    cin>>n;
    for(int i=0;i<n;i++)
    {
        if(i==n-1)
            cout<<a[i];
        else
            cout<<a[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n; i++)
#define all(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;


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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    priority_queue<pair<LL, int>> q;
    rep(i, n) q.push(mp((LL)a[i]+b[i], i));
    LL ans = 0;
    rep(i, n){
        if(i%2 == 0){
            ans += a[q.top().second];
        }else{
            ans -= b[q.top().second];
        }
        q.pop();
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll h,w,k,an=0; ll fl[7][7],f1[7],f2[7];
void bruteforce2(ll j){
	if(j==w+1){
		ll cnt=0,a,b;
		for(a=1;a<=h;a++){
			for(b=1;b<=w;b++){
				if(f1[a]==1||f2[b]==1) continue;
				if(fl[a][b]==0) cnt++;
			}
		}
		if(cnt==k) an++;
		return ;
	}

	bruteforce2(j+1);
	f2[j]=1;
	bruteforce2(j+1);
	f2[j]=0;
}
void bruteforce(ll i){
	if(i==h+1){
		bruteforce2(1);
		return;
	}
	bruteforce(i+1);
	f1[i]=1;
	bruteforce(i+1);
	f1[i]=0;
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll i,j,l;
	cin>>h>>w>>k;
	char c;
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			cin>>c;
			if(c=='.') fl[i][j]=1;
			else fl[i][j]=0;
		}
	}

	bruteforce(1);
	cout<<an;
	return 0;	
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a, b, c;
        a = in.nextInt();
        b = in.nextInt();
        c = in.nextInt();
        int countFive = 0;
        int countSeven = 0;

        if (a == 5) {
            countFive++;
        }
        else if( a == 7){
            countSeven++;
        }
        if (b == 5) {
            countFive++;
        }
        else if (b == 7) {
            countSeven++;
        }
        if(c == 5 ) {
            countFive++;
        }
        else if(c == 7 ){
            countSeven++;
        }
        if( countFive == 2 && countSeven == 1){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23636
#include <iostream>

using namespace std;

void solve()
{
	int A, B;
	cin >> A >> B;
	if (A == B)
	{
		cout << "Draw" << endl;
	}
	else
	{
		if (A == 1)
		{
			A += 13;
		}
		if (B == 1)
		{
			B += 13;
		}
		if (A > B)
		{
			cout << "Alice" << endl;
		}
		else
		{
			cout << "Bob" << endl;
		}
	}
}

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

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

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

// 0-1 BFS 
int main()
{
    int h, w;
    cin >> h >> w;
    int si, sj;
    cin >> si >> sj;
    int ti, tj;
    cin >> ti >> tj;
    --si; --sj; --ti; --tj;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    const int INF = 1e9;
    vector<vector<int>> dist(h, vector<int>(w,INF));
    deque<P> q;
    dist[si][sj] = 0;
    q.emplace_back(si, sj);
    while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        int d = dist[i][j];
        q.pop_front();
        if (dist[i][j] != d) continue;
        rep(v,4) {
            int ni = i+di[v], nj = j+dj[v];
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (s[ni][nj] == '#') continue;
            if (dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(ni, nj);
        }
        for (int ei = -2; ei <= 2; ++ei) {
            for (int ej = -2; ej <= 2; ++ej) {
                int ni = i+ei, nj = j+ej;
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if (s[ni][nj] == '#') continue;
                if (dist[ni][nj] <= d+1) continue;
                dist[ni][nj] = d+1;
                q.emplace_back(ni, nj);
            }
        }

    }
    int ans = dist[ti][tj];
    if (ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9492
#include <stdio.h>
int main()
{
  int N;
  int A[1000];
  int key,k,i,j;
  scanf("%d",&N);
  for(i = 0;i <= N-1;i++){
  scanf("%d",&A[i]);
  }
  for(i = 0; i < N; i++){
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    for(k=0;k<N;k++){
      printf("%d",A[k]);
      if(k < N-1){
	printf(" ");
      }
    }
    printf("\n");
  }
  return 0;
}





Measured memory_bytes: 2128
N, M = map(int, input().split())

if M == 1:
	print(1)
	exit()

import math

prob = 0
for i in range (1, N+1):
	if i>=M:
		prob+=1/N
	else:
		prob+=((1/N)*1/2**math.ceil(math.log(M/i, 2)))

print(prob)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

bool ext(int x, int y, int z){
	if(x<y&&y>z) return true;
	if(x>y&&y<z) return true;
	return false;
}

int main(void) {
	int n; cin >> n;
	vi a(n); rep(i,n) cin >> a[i];
	int ans = 1;
	int i=0;
	while(i<n-1){
		while(i<n-1&&a[i]==a[i+1])i++;
		if(a[i]<a[i+1]){
			while(i<n-1&&a[i]<=a[i+1])i++;
			if(i==n-1) break;			
			ans++;
			i++;
//			cout << i << endl;
			continue;
		}
		if(a[i]>a[i+1]){
			while(i<n-1&&a[i]>=a[i+1])i++;
			if(i==n-1) break;
			ans++;
			i++;
//			cout << i << endl;			
			continue;
		}		
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
from collections import OrderedDict

n = int(input())
a_list = map(int, input().split())

a_dict = {i+1: a for i, a in enumerate(a_list)}  # {No.nの生徒が: m番目に来た}
# print(a_dict)

a_dict_sorted = OrderedDict(sorted(a_dict.items(), key=lambda kv: kv[1]))  # valueを基にソート
# print(a_dict_sorted)

for k, v in a_dict_sorted.items():
    print(k, end=" ")

Measured memory_bytes: 110252
#include<stdio.h>
#include<string>
#include<vector>
#include<iostream>

using namespace std;

int main(void)
{
  	int X,A;
  	scanf("%d",&X);
  	scanf("%d",&A);
  
  	if(X<A)
    	printf("0\n");  
    else
    	printf("10\n");  
	return 0;  
}


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

int main(){
    int N;
    cin>>N;
    vector<vector<int>> h(N,vector<int>(3));
    vector<vector<int>> dp(100000+10,vector<int>(3,0));
    
    for(int i=0; i<N; i++){
        for(int j=0; j<3; j++){
            cin>>h[i][j];
        }
    }

    for(int i=0; i<N; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(k == j) continue;
                dp[i+1][k] = max(dp[i][j]+h[i][k],dp[i+1][k]); 
            }
        }
    }

    int ans = 0;

    for(int i=0; i<3; i++){
        ans = max(dp[N][i],ans);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  

void solve(){
	int a, b, c;
	re(a,b,c);
	cout << max(0LL,c - (a - b))  << endl;
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


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

#pragma region template


// -type-
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;


// -const-
const ll MOD = 1000000007;

const string YES = "Yes";

const string NO = "No";

const ll MAX = (ll)0x3f0000003f000000;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


// -define-
#define F first
#define S second

#define reps(i, k, n) for (int i = (k), i##_len = (n); i < i##_len; ++i)
#define rep(i, n) reps(i, 0, n)
#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n';


// -functions-

inline bool in(string s, string c) {
    return (s.find(c) != string::npos);
}
inline bool in(string s, char c) {
    return (s.find(c) != string::npos);
}

template <class T>
void print(T& x) {
    cout << x << '\n';
}

struct setup_main {
    setup_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(15);
    }
} setup_main_;

#pragma endregion

ll ans = 0;

void solve(long long A, long long B, long long C){
    if(A == B and A != C) print(YES);
    else if (A == C and A != B)
        print(YES);
    else if (B == C and A != C)
        print(YES);
    else
        print(NO);
}
signed main() {
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Pair implements Comparable<Pair> {

    final int cost;
    final int to;

    Pair( int cost, int to ) {
	this.cost = cost;
	this.to = to;
    }

    public int compareTo( Pair p ) {
	return cost - p.cost;
    }    
}

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	final int n = Integer.parseInt( stdin.nextLine() );
	final int m = Integer.parseInt( stdin.nextLine() );
	List< List<Pair> > map = new ArrayList< List<Pair> >();
	for ( int i = 0; i <= n; i++ ) {
	    map.add( new ArrayList<Pair>() );
	}
	for ( int i = 0; i < m; i++ ) {
	    String[] input = stdin.nextLine().trim().split( "," );
	    final int from = Integer.parseInt( input[ 0 ] );
	    final int to = Integer.parseInt( input[ 1 ] );
	    final int cost = Integer.parseInt( input[ 2 ] );
	    final int revCost = Integer.parseInt( input[ 3 ] );
	    map.get( from ).add( new Pair( cost, to ) );
	    map.get( to ).add( new Pair( revCost, from ) );
	}
	String[] input = stdin.nextLine().split( "," );
	int x1 = Integer.parseInt( input[ 0 ] );
	int x2 = Integer.parseInt( input[ 1 ] );
	int y1 = Integer.parseInt( input[ 2 ] );
	int y2 = Integer.parseInt( input[ 3 ] );
	System.out.println( y1 - y2 - dijkstra( x1, x2, map ) - dijkstra( x2, x1, map ) );
    }

    static int dijkstra( int start, int end, List< List< Pair > > map ) {
	int[] minDist = new int[ map.size() ];
	Arrays.fill( minDist, 10000000 );
	minDist[ start ] = 0;
	
	PriorityQueue<Pair> que = new PriorityQueue<Pair>();
	que.add( new Pair( 0, start ) );
	
	while ( !que.isEmpty() ) {
	    Pair p = que.poll();
	    if ( minDist[ p.to ] < p.cost ) {
		continue;
	    }
	    if ( p.to == end ) {
		return p.cost;
	    }
	    for ( Pair edge : map.get( p.to ) ){
		que.add( new Pair( p.cost + edge.cost, edge.to ) );
		minDist[ edge.to ] = min( minDist[ edge.to ], p.cost + edge.cost );
	    }
	}
	return -1;
    }    
}

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

using namespace std;

int N, x;
int a[100];

void solve() {
    int num = 0, tmp = x;
    sort(a, a + N);
    for (int i = 0; i < N; ++i) {
        if (x >= a[i]) {
            x -= a[i];
            num++;
        } else {
            break;
        }
    }
    if (num == N && x) --num;
    cout << num << endl;
}

int main() {
    cin >> N >> x;
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x = 0, y = 0;
		int angle = 90;
		while(sc.hasNext()){
			String[] xy = sc.next().split(",");
			int des = Integer.valueOf(xy[0]);
			int a = Integer.valueOf(xy[1]);
			if(des==0 && a==0)break;
			x += des * Math.cos(Math.toRadians(angle));
			y += des * Math.sin(Math.toRadians(angle));
			angle -= Integer.valueOf(xy[1]);
		}
		System.out.println((int)x);
		System.out.println((int)y);
	}
}

Measured memory_bytes: 26192
#include <bits/stdc++.h>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;


int main(){

	int N; std::cin >> N;
	std::vector<int> A(N + 2, 0);
	int S = 0;
	for(int i = 1; i < N + 1; i ++){
		std::cin >> A[i];
		S += abs(A[i - 1] - A[i]);
	}
	S += abs(A[N] - A[N + 1]);


	for(int i = 0; i < N; i++){
		int ans = S + abs(A[i] - A[i + 2]) - (abs(A[i] - A[i + 1]) + abs(A[i + 2] - A[i + 1]));
		std::cout << ans << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1664
q,h,s,d=map(int,input().split())
n=int(input())
s=min(4*q,2*h,s)
if d<2*s:
    if n%2==0:
        print(d*(n//2))
    else:
        print(d*(n//2)+s)
else:
    print(n*s)


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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

#define rep(n) for (int i = 0; i < n; ++i)

#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
typedef double D;
typedef complex<D> P;
typedef vector<string> vs;

#define SZ(x) ((int)(x).size())

#define fill(x,y) memset(x,y,sizeof(x))

// with compile option -DLOCAL
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

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

#define pcnt __builtin_popcount
#define pcntll __builtin_popcountll

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
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};



#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    int n, x;
    cin >> n >> x;
    vi a;
    rep(n){
        int val;
        cin >> val;
        a.pb(val);
    }

    sort(all(a));
    int ret = 0;

    rep(n) {
        if(a[i] > x) break;
        ret++;
        x -= a[i];

        if(i == n - 1 && x != 0) ret--;
    }

    cout << ret << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long ll;

const int maxn = 2e5 + 7;

int n, x;

struct node {
  ll b, l, u, sorce;
  friend bool operator < (const node& x, const node& y) {
    //if (x.sorce == y.sorce) return 1;
    return x.sorce > y.sorce;
  }
} a[maxn];

ll check(ll t) {
  ll tim = t / x;
  ll res = t - tim * x;
  ll sum = 0;
  for (int i = 1; i <= tim; i++) {
    sum += a[i].sorce;
  }
  ll ans = 0;
  ans = sum;
  for (int i = 1; i <= n; i++) {
    ll now = 0;
    if (res <= a[i].b) 
      now = res * a[i].l;
    else 
      now = a[i].b * a[i].l + (res - a[i].b) * a[i].u;
    if (i <= tim) ans = max(ans, sum - a[i].sorce + now + a[tim + 1].sorce);
    else ans = max(ans, sum + now);
  }
  return ans;
}


int main() {
  scanf("%d%d", &n, &x);
  ll goal = 0, maxx = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &a[i].b, &a[i].l, &a[i].u);
    maxx += a[i].b;
    goal += a[i].b * a[i].l;
    a[i].sorce = a[i].b * a[i].l + (x - a[i].b) * a[i].u;
  }
  sort(a + 1, a + n + 1);
  ll l = 0, r = (long long)n * x;
  while (l < r) {
    ll mid = (l + r) / 2;
    if (check(mid) >= goal) r = mid;
    else l = mid + 1;
  }
  printf("%lld\n", r);
}


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

int main(){
	ll a, b, c, d, e;
  	cin>>a>>b>>c>>d>>e;
  	if(a==0){
      cout<<1<<endl;
    }
  	else if(b==0){
      cout<<2<<endl;
    }
  	else if(c==0){
      cout<<3<<endl;
    }
  	else if(d==0){
      cout<<4<<endl;
    }
  	else{
      cout<<5<<endl;
    }
}

Measured memory_bytes: 3588
#include <stdio.h>
 
int main(void) {
    int a,b,c,d,e,f,g;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a < c){
        f = c;
    } else {
        f = a;
    }
    if(b < d){
        g = b;
    } else { 
        g = d;
    }
    e = g - f; 
    if(e < 0){
        e = 0;
    }
    printf("%d\n",e);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
  int n, l;cin>>n>>l;
  vector<string> s(n);
  for(int i=0;i<n;i++)cin>>s[i];
  sort(s.begin(), s.end());
  for(int i=0;i<n;i++)cout<<s[i];
  cout << endl;
}

Measured memory_bytes: 256
h1, m1, h2, m2, k = map(int, input().split())

if h1 == h2:
    if k > (m2 - m1):
        print(0)
    else:
        print(m2-m1-k)
else:
    if k > (h2-h1)*60 + m2-m1:
        print(0)
    else:
        print((h2-h1)*60 + m2-m1-k)



Measured memory_bytes: 61592
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main(){
	int A, B, C, D, P;
	scanf("%d%d%d%d%d", &A, &B, &C, &D, &P);
	int buf;
	if (P <= C){
		buf = B;
	}
	else{
		buf = B + (P - C) * D;
	}
	printf("%d\n", min(A * P, buf));
	return 0;
}

Measured memory_bytes: 2752
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,x,y,i,j,k;
    scanf("%d%d%d",&n,&x,&y);
    if(y-x==1)
    {
        printf("Borys\n");
        return 0;
    }
    k=y-x-1;
    if(k%2==1)
    printf("Alice\n");
    else
    printf("Borys\n");
    return 0;
}


Measured memory_bytes: 128
#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 = 1777777777;
// 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;
}

using ld = long double;

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

    int N;
    cin >> N;
    vector<int> c(4, 0);
    for(int i = 0; i < N; ++i){
        int a;
        cin >> a;
        ++c[a];
    }

    vector<vector<vector<ld>>> dp(N + 1, vector<vector<ld>>(N + 1, vector<ld>(N + 1, -1)));
    auto MemoRec = [&](auto&& self, int i, int j, int k) -> ld {
        if(dp[i][j][k] != -1)   return dp[i][j][k];
        if(i + j + k == 0)  return dp[i][j][k] = 0;
        
        ld res = N;
        if(i != 0)  res += self(self, i - 1, j, k) * i;
        if(j != 0)  res += self(self, i + 1, j - 1, k) * j;
        if(k != 0)  res += self(self, i, j + 1, k - 1) * k;
        res /= i + j + k;

        return dp[i][j][k] = res;
    };

    cout << fixed << setprecision(15);
    cout << MemoRec(MemoRec, c[1], c[2], c[3]) << endl;
}

Measured memory_bytes: 434280
#include <stdio.h>

int main(void)
{
	int h[3][1000], n, i, temp;
	scanf("%d", &i);
	for (n = 0; n < i; n++){
		scanf("%d %d %d", &h[0][n], &h[1][n], &h[2][n]);
		if (h[0][n]<=h[1][n]){
			temp=h[0][n];
			h[0][n]=h[1][n];
			h[1][n]=temp;
		}
		if(h[0][n]<=h[2][n]){
			temp=h[0][n];
			h[0][n]=h[2][n];
			h[2][n]=temp;
		}
	}
	for (n = 0; n < i; n++){
		if ((h[0][n]*h[0][n])==(h[1][n]*h[1][n]+h[2][n]*h[2][n])){
			printf("YES\n");
		} else printf("NO\n");
	}
	return 0;
}

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


void solve(long long N, std::vector<long long> A){
  map<long long, long long> tab;

  for(long long i = 0; i < N; i++){
    tab[A[i]]++;
  }
  long long acc = 0;
  for(auto x: tab){
    acc += ((x.second * (x.second - 1)) / 2);
  }

  for(long long i = 0; i < N; i++){
    cout << ((acc - (((tab[A[i]]) * (tab[A[i]] - 1)) / 2)) + (((tab[A[i]] - 1) * (tab[A[i]] - 2)) / 2)) << endl;;
  }
}

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


Measured memory_bytes: 11008
x1,y1,x2,y2 = map(int,input().split())
dx = (x1-x2)
# dy = (y1-y2)
dy = (y2-y1)

# x3 = x2 - dy
# y3 = y2 + dx
# x4 = x1 - dy
# y4 = y1 + dx
x3 = x2 - dy
y3 = y2 - dx
x4 = x1 - dy
y4 = y1 - dx

print(x3,y3,x4,y4)


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

bool is_four(int cards[5]){
	int num;
	for(int i = 0; i < 2; i++){
		num = cards[i];
		for(int j = 0; j < 4; j++){
			if(cards[i+j] != num) break;
			if(j == 3) return true;
		}
	}
	return false;
}

bool is_full(int cards[5]){
	if(cards[0] == cards[1] && cards[3] == cards[4] 
	&& (cards[2] == cards[0] || cards[2] == cards[4]))
		return true;
	return false;
}

bool is_st(int cards[5]){
	int num = cards[0];
	for(int i = 1; i < 5; i++){
		if(cards[i] != (num + i)) break;
		if(i == 4) return true;
	}
	if(cards[0] == 1 && cards[1] == 10 && cards[2] == 11 
		&& cards[3] == 12 && cards[4] == 13)
		return true;
	return false;
}

bool is_three(int cards[5]){
	int num;
	for(int i = 0; i < 3; i++){
		num = cards[i];
		for(int j = 0; j < 3; j++){
			if(cards[i+j] != num) break;
			if(j == 2) return true;
		}
	}
	return false;
}

bool is_two(int cards[5]){
	int count = 0;
	if(cards[0] == cards[1] || cards[1] == cards[2]) count++;
	if(cards[2] == cards[3] || cards[3] == cards[4]) count++;
	if(count == 2) return true;
	return false;
}

bool is_one(int cards[5]){
	for(int i = 0; i < 4 ; i++){
		if(cards[i] == cards[i+1]) return true;
	}
	return false;
}

int main(){
	int cards[5];
	char c;
	while(cin >> cards[0] >> c >> cards[1] >> c 
		>> cards[2]	>> c >> cards[3] >> c >> cards[4])
	{
		sort(cards, cards + 5);
		if(is_four(cards)){
			cout << "four card" << endl;
		}else if(is_full(cards)){
			cout << "full house" << endl;
		}else if(is_st(cards)){
			cout << "straight" << endl;
		}else if(is_three(cards)){
			cout << "three card" << endl;
		}else if(is_two(cards)){
			cout << "two pair" << endl;
		}else if(is_one(cards)){
			cout << "one pair" << endl;
		}else {
			cout << "null" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
s = input()
s = s[::-1]
n = len(s)

num = [0]*2019
num[0] = 1
number = 0
d = 1

for i in s:
    number += int(i)*d
    num[number%2019] += 1
    d *= 10
    d %= 2019

ans = 0

for i in num:
    ans += i*(i-1)//2

print(ans)

Measured memory_bytes: 68692
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<ld> r(n);
    for (int i = 0; i < n; i++)
        cin >> r[i];
    vector<ld> dp(n, INF);
    ld res = 0;
    for (int i = 0; i < n; i++)
    {
        dp[i] = r[i];
        for (int j = 0; j <= i - 1; j++)
        {
            ld d = sqrt((r[i] + r[j]) * (r[i] + r[j]) - (r[i] - r[j]) * (r[i] - r[j]));
            dp[i] = max(dp[i], dp[j] + d);
        }
        // cout<<i<<" "<<dp[i]<<endl;
        res = max(res, dp[i] + r[i]);
    }
    cout << fixed << setprecision(10) << res << endl;
}



Measured memory_bytes: 3304
#include <stdio.h>

int main(void)
{
        int i,s=0;
        char a[3];

        for (i=0;i<3;i++){
                scanf("%c",&a[i]);
                if (a[i]=='1')
                        s++;
        }

        printf("%d\n",s);       

        return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define  pb push_back
#define sort1(v) sort(v.begin(),v.end())
ll a[3002][3002];
void upd(int i,int j,int n)
{
    a[i+1][j+1]++;
    a[j][j+1]--;
    a[i+1][n+1]--;
    a[j][n+1]++;
}
int cmo(string a,string b)
{
    int c=0;
    for(int i=0;i<(int)a.size();i++)
    {
        if(a[i]!=b[i])
            c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    int min=t.size();
    int l1=s.size(),l2=min;
    for(int i=0;i<=l1-l2;i++)
    {
        int ans=cmo(s.substr(i,l2),t);
        if(ans<min)
            min=ans;
    }
    cout<<min<<"\n";
}








Measured memory_bytes: 3632
#include<iostream>
#include<queue>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846264338327950L
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
	//return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	ll g = gcd(a, b);
	return a / g * b; // Be careful not to overflow
	//return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数

//素数判定
template<typename T>
bool IsPrime(T 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;
}

template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
//vector<vector<int>> data(3, vector<int>(4));
//vector<vector<Type>> vv(n);
//cout << fixed << setprecision(20) << endl;

int main() {
	ll N, Y;cin >> N >> Y;
	ll i, k,j;
	for (i = 0;i <= N;i++) {
		for (k = 0;k <= N-i;k++) {
			j = N - i - k;
			if (j < 0) continue;
			ll sum = i * 10000 + 5000 * k + 1000 * j;
			if (sum == Y) {
				cout << i << " " << k << " " << j << endl;
				exit(0);
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1<< endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n;
	cin >> n;
	ll x1 = 0,y1 = 0,t1 = 0,x2,y2,t2;
	ll dx,dy,dt,d;
	int flag = 1;
	for(ll i = 0; i < n; i++) {
		cin >> t2 >> x2 >> y2;
		dt = t2 - t1;
		dx = abs(x2 - x1);
		dy = abs(y2 - y1);
		d = dx + dy;
		if (dt < d || (dt - d) % 2 != 0){
			flag = 0;
			for(ll j = i+1;j < n;j++){
				cin >> t2 >> x2 >> y2;
			}
			break;
		}
		t1 = t2;
		x1 = x2;
		y1 = y2;
	}
	if(flag == 1){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
set<int> to[maxn];
int main(){
	string s; cin >> s;
	int len = s.size();
	int u = (len - 1) / 2, v = len / 2;
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		int l, r; cin >> l >> r; l--; r--;
		vector<pair<int,int> > ways;
		/**
		  abeba
		   3 4 -> 0 1
		   0 3 -> 0 0
		   1 4 -> 0 0 
		  **/
		if(r <= u){
			to[l].insert(r);
		} else if (l >= v){
			to[len - r - 1].insert(len - l - 1);
		}  else {
			int dl = u - l, dr = r - v;
			if(dl > dr) to[l].insert(u - dr - 1);
			else if(dl < dr) to[len - r - 1].insert(len - 1 - (v + dl + 1));
		}
	}
	if(u == v) to[u].insert(u);
	vector<int> val(len, 0), pref(2 * len + 10, 0);
	for(int i = 0; i <= u; i++){
		val[i] = s[v + u - i] - s[i] + 26;
		val[i] %= 26;
	}
	for(int i = 0; i <= u; i++){
		if(i) pref[i] += pref[i - 1];
		val[i] += pref[i];
		val[i] %= 26;
		val[i] += 26;
		val[i] %= 26;
		int pk = -1;
		{
			vector<int> now;
			for(int j : to[i]){
				now.push_back(j);
			}
			int sz = now.size();
			for(int i = 1; i < sz; i++){
				to[now[i - 1] + 1].insert(now[i]);
			}
			if(sz) pk = now[0];
		}
		if(val[i]){
			if(pk == -1) return cout << "NO" << endl, 0;
			pref[i] += 26 - val[i];
			pref[pk + 1] += val[i];
		}
	}
	cout << "YES" << endl;
	return 0;
}	


Measured memory_bytes: 25472
#include <iostream>

using namespace std;

void output(int Array[], char mark) {
    for (int i = 1; i <= 13; i++) {
        if (Array[i] == 0) cout << mark << " " << i << endl;
    }
}

int main() {
    int n;

    cin >> n;
    int s[14], h[14], c[14], d[14];
    for (int i = 0; i < 14; i++) {
        s[i] = h[i] = c[i] = d[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        char mark;
        int rank;
        cin >> mark >> rank;
        switch (mark) {
            case 'S':
                s[rank] = 1;
                break;
            case 'H':
                h[rank] = 1;
                break;
            case 'C':
                c[rank] = 1;
                break;
            case 'D':
                d[rank] = 1;
                break;
        }
    }
    output(s, 'S');
    output(h, 'H');
    output(c, 'C');
    output(d, 'D');

    return 0;
}


Measured memory_bytes: 3100
import sys
A,B,T = map(int,input().split())
if not ( 1 <= A <= 20 and 1 <= B <= 20 and 1 <= T <= 20 ): sys.exit()

time_remind = T+0.5
sum = 0
for I in range(1,T+1):
    time_remind -= A
    if time_remind >= 0: sum += B
print(sum)

Measured memory_bytes: 9148
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;


int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll x,y;
    sfl(x),sfl(y);
    for(ll i=0;i<=x;i++){
        ll j = x-i;
        if(i*2+j*4==y){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 3756
n,k = map(int,input().split())
mod = 10**9+7

frac = [1]*(n+1)
finv = [1]*(n+1)
for i in range(n):
    frac[i+1] = (i+1)*frac[i]%mod
finv[-1] = pow(frac[-1],mod-2,mod)
for i in range(1,n+1):
    finv[n-i] = finv[n-i+1]*(n-i+1)%mod
def nCr(n,r):
    if n<0 or r<0 or n<r: return 0
    r = min(r,n-r)
    return frac[n]*finv[n-r]*finv[r]%mod

#n+1Ci * k-1Ci-1
for i in range(1,k+1):
    val = (nCr(n+1-k,i)*nCr(k-1,i-1))%mod
    print(val)

Measured memory_bytes: 73752
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

//グラフのテンプレート
template<typename T>
struct edge {
	int from, to;
	T cost;
	
	edge(int to,T cost):from(0),to(to),cost(cost){}
	edge(int from, int to, T cost) :from(from), to(to), cost(cost) {}
};


template<typename T>
struct SegmentTree{//セグ木によるRMQ
  private:
      int n;
      vector<T>node;
      T MAXV=numeric_limits<T>::max();

  public:
      SegmentTree(vector<T>v){
        //構築O(N)

        int sz=v.size();
        n=1;
        while(n<sz)n*=2;//nは配列のサイズ以上となる最小の2の冪
        node.resize(2*n-1,MAXV);

        //最下段から順番に値を代入していく
        for(int i=0;i<sz;i++)node[i+n-1]=v[i];
        //最下段までにn-1個のノードがある

        for(int i=n-2;i>=0;i--)node[i]=min(node[2*i+1],node[2*i+2]);
        //自分の子を参照
      }

      void update(int k,T val){//値の更新
        //最下段のノードにアクセス
        k+=(n-1);

        node[k]=val;
        //あとはのぼりながら更新
        while(k>0){
          k=(k-1)/2;//親
          node[k]=min(node[2*k+1],node[2*k+2]);
        }
      }

      T getv(int k){
          k+=n-1;
          return node[k];
      }

      T query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        //クエリ[a,b),今見ている節点番号k,それに対応する区間[l,r)

        //[a,b)と[l,r)が交差しないとき
        if(r<=a||l>=b)return MAXV;

        //[a,b)が[l,r)を完全に被覆するとき
        if(a<=l&&b>=r)return node[k];//対象区間のノードの値を返す

        //一部を被覆するとき,子について探索を行う
        T vl=query(a,b,2*k+1,l,(l+r)/2);
        T vr=query(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
      }
};

ll dp[100005];

void solve(){
    int n,m;
    cin>>n>>m;
    vector<ll>v(n,INF);
    SegmentTree<ll>sg(v);
    vector<pair<pair<int,int>,ll>>d;
    rep(i,m){
        int l,r;
        ll c;
        cin>>l>>r>>c;
        l--;r--;
        d.eb(make_pair(l,r),c);
    }
    sort(d.begin(),d.end());
    sg.update(0,0);
    rep(i,m){
        ll a=sg.query(d[i].first.first,d[i].first.second);//右端だけ更新していけばok
        ll b=sg.getv(d[i].first.second);
        sg.update(d[i].first.second,min(a+d[i].second,b));
    }
    ll ans=sg.getv(n-1);
    if(ans>=INF)cout<<-1<<endl;
    else cout<<ans<<endl;
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 7188
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector< vector<int> > x(n);
	vector< vector<int> > y(n);
	int xtemp,ytemp;
	rep(i,n) {
		cin >> a[i];
		rep(j, a[i]) {
			cin >> xtemp >> ytemp;
			x[i].pb(xtemp - 1);
			y[i].pb(ytemp);
		}
	}
	bool flag;
	int max = 0;
	for (int bit = 0; bit < (1<<n); ++bit) {
		flag = true;
		rep(i,n) {
			rep(j, a[i]) {
				if ((bit >> i) & 1) {
					if ((bit >> x[i][j] & 1) != y[i][j]) {
						flag = false;
						//cout << "false1!";
						//cout << "i:" << i << " j:" << j << " bit:" << bit << " bitshift:" << ((bit >> x[i][j])%2) << " x[i][j]:" << x[i][j] <<  " y[i][j]:" << y[i][j] << endl;
						break;
					}
				}
				else {
					/*if ((bit >> x[i][j]) % 2 == y[i][j]) {
						flag = false;
						cout << "false2!";
						cout << "i:" << i << " j:" << j << " bit:" << bit << " bitshift:" << ((bit >> x[i][j])%2) << " x[i][j]:" << x[i][j] <<  " y[i][j]:" << y[i][j] <<  endl;
						break;
					}
					*/
				}
			}
			if (flag == false) break;
		}
		if (flag == false) continue;
		//cout << "bit:" << bit << endl;
		/*int temp = bit;
		int count = 0;
		while(temp > 0) {
			if(temp % 2 == 1) count++;
			temp /= 2;
		}*/
		max = std::max(max, __builtin_popcount(bit));
	}

	cout << max << endl;

  return 0;
}


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

int main(){
  char X, Y;
  int a=0, b=0;
  cin >> X >> Y;

  if(X=='A'){
    a=10;
  }else if(X=='B'){
    a=11;
  }else if(X=='C'){
    a=12;
  }else if(X=='D'){
    a=13;
  }else if(X=='E'){
    a=14;
  }else if(X=='F'){
    a=15;
  }

  if(Y=='A'){
    b=10;
  }else if(Y=='B'){
    b=11;
  }else if(Y=='C'){
    b=12;
  }else if(Y=='D'){
    b=13;
  }else if(Y=='E'){
    b=14;
  }else if(Y=='F'){
    b=15;
  }

  if(a<b){
    cout << '<' << endl;
  }

  else if(a>b){
    cout << '>' << endl;
  }

  else{
    cout << "=" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main
{
    static PrintWriter out = new PrintWriter((System.out));

    public static void main(String args[]) throws IOException
    {
        Kioken sc = new Kioken();
        int k=sc.nextInt();
        int n=sc.nextInt();
        HashSet<Integer> set=new HashSet<>();
        for(int x=0;x<n;x++)
        {
            set.add(sc.nextInt());
        }
        int d=0;
        int ans=0;
        while(true)
        {
            if(!set.contains(k-d))
            {
                ans=k-d;
                break;
            }
            if(!set.contains(k+d))
            {
                ans=k+d;
                break;
            }
            d++;
        }
        out.println(ans);
        out.close();
    }

    public static void kamehameha()
    {
    }

    static class Kioken
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        public String next()
        {
            while (!st.hasMoreTokens())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        public long nextLong()
        {
            return Long.parseLong(next());
        }

        public double nextDouble()
        {
            return Double.parseDouble(next());
        }

        public String nextLine()
        {
            try
            {
                return br.readLine();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext()
        {
            String next = null;
            try
            {
                next = br.readLine();
            }
            catch (Exception e)
            {
            }
            if (next == null)
            {
                return false;
            }
            st = new StringTokenizer(next);
            return true;
        }
    }
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/combine.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    char a;
    cin >> a;

    if (iswlower(a)) {
        cout << "a" << endl;
    } else {
        cout << "A" << endl;
    }
}

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

// Input
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)*} }; }
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)*} };}
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") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        a: i64,
        b: i64,
    }
    let d = b-a;
    println!("{}", d*(d+1)/2 - b);
}

Measured memory_bytes: 4352