akhauriyash/Code-Regression huggingface dataset:
#include <cstdint>
#include <iostream>

using namespace std;

int32_t main() {
  bool start = true;
  while (true) {
    uint32_t amount;
    cin >> amount;
    if (amount == 0) break;

    if (!start) {
      cout << endl;
    }
    start = false;

    uint32_t c10, c50, c100, c500;
    cin >> c10 >> c50 >> c100 >> c500;

    uint32_t total = c10 + c50 + c100 + c500;
    uint32_t min_remain = UINT32_MAX;
    uint32_t min_c10 = 0;
    uint32_t min_c50 = 0;
    uint32_t min_c100 = 0;
    uint32_t min_c500 = 0;
    for (uint32_t l = 0; l <= c500; l++) {
      for (uint32_t k = 0; k <= c100; k++) {
        for (uint32_t j = 0; j <= c50; j++) {
          for (uint32_t i = 0; i <= c10; i++) {
            uint32_t payment = 10 * i + 50 * j + 100 * k + 500 * l;
            if (amount <= payment) {
              uint32_t change = payment - amount;
              uint32_t r500 = change / 500;
              change %= 500;
              uint32_t r100 = change / 100;
              change %= 100;
              uint32_t r50 = change / 50;
              change %= 50;
              uint32_t r10 = change / 10;
              uint32_t remain = c10 - i + r10 + c50 - j + r50 + c100 - k +
                                r100 + c500 - l + r500;
              if (remain < min_remain) {
                min_remain = remain;
                min_c10 = i;
                min_c50 = j;
                min_c100 = k;
                min_c500 = l;
              }
            }
          }
        }
      }
    }
    if (min_c10) {
      cout << 10 << " " << min_c10 << endl;
    }
    if (min_c50) {
      cout << 50 << " " << min_c50 << endl;
    }
    if (min_c100) {
      cout << 100 << " " << min_c100 << endl;
    }
    if (min_c500) {
      cout << 500 << " " << min_c500 << endl;
    }
  }

  return 0;
}

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

using namespace std;

int par[512];

void init(int n)
{
    memset(par, -1, sizeof(par));
}

int find(int x)
{
    return (par[x] < 0 ? x : par[x] = find(par[x]));
}

void merge(int x, int y)
{
    x = find(x);
    y = find(y);
    
    if (x == y) return;
    
    if (-par[x] < -par[y]) swap(y, x);
    
    par[x] += par[y];
    par[y] = x;
}

bool same(int x, int y)
{
    return (find(x) == find(y));
}

struct Edge {
    int from, to, cost, id;
    
    Edge(int cost, int from, int to, int id) :
        cost(cost), from(from), to(to), id(id){}
};

bool operator < (const Edge &a, const Edge &b)
{
    return (a.cost < b.cost);
}

vector<Edge> G[512], edges, bridges;
int ehead[512];
int ord[512], low[512], vis[512];
bool done[100000];

void dfs(int v, int &k, int id)
{
    vis[v] = done[id] = true;
    ord[v] = low[v] = k++;
    
    for (int i = ehead[v]; i < G[v].size(); i++){
        if (!vis[G[v][i].to]){
            dfs(G[v][i].to, k, G[v][i].id);
            low[v] = min(low[v], low[G[v][i].to]);
        }
        else if (!done[G[v][i].id]){
            done[G[v][i].id] = true;
            low[v] = min(low[v], ord[G[v][i].to]);
        }
    }
    
    for (int i = ehead[v]; i < G[v].size(); i++){
        if (ord[v] < low[G[v][i].to]){
            bridges.push_back(G[v][i]);
        }
    }
}

int main()
{
    int N, M;
    
    scanf("%d %d", &N, &M);
    
    for (int i = 0; i < M; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        edges.push_back(Edge(c, a, b, i));
    }
    
    sort(edges.begin(), edges.end());
    
    init(N);
    
    for (int i = 0; i < M;){
        vector<Edge> cand;
        
        cand.push_back(edges[i++]);
        while (i < M && edges[i].cost == cand[0].cost){
            cand.push_back(edges[i++]);
        }
        
        int ncost = cand[0].cost;
        for (int j = 0; j < cand.size(); j++){
            pair<int, int> p = make_pair(cand[j].from, cand[j].to);
            int x = find(p.first), y = find(p.second);
            //if (x != y){
                G[x].push_back(Edge(ncost, x, y, cand[j].id));
                G[y].push_back(Edge(ncost, y, x, cand[j].id));
            //}
        }
        memset(ord, 0, sizeof(ord));
        memset(low, 0, sizeof(low));
        memset(vis, 0, sizeof(vis));
        
        for (int j = 0; j < cand.size(); j++){
            if (!done[cand[j].id]){
                int k = 1;
                dfs(find(cand[j].from), k, cand[j].id);
            }
            ehead[find(cand[j].from)]++;
            ehead[find(cand[j].to)]++;
        }
        
        for (int j = 0; j < cand.size(); j++){
            merge(cand[j].from, cand[j].to);
        }
    }
    
    printf("%d ", bridges.size());
    
    int s = 0;
    
    for (int i = 0; i < bridges.size(); i++){
        s += bridges[i].cost;
    }
    
    printf("%d\n", s);
    
    return (0);
}

Measured memory_bytes: 5112
// cout << "Case #" << test << ": ";
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<ll> a(3 * n);
    for(int i = 0; i < 3 * n; i++) {
        cin >> a[i];
    }
    sort(all(a), greater<ll>());
    ll ans = 0;
    for(int i = 2; i <= 2 * n; i += 2) {
        ans += a[i - 1];
    }
    cout << ans << endl;
}


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

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


    if ( abs(n-k) > n) {
        cout << n << endl;
    }
    else if (n == k) {
        cout << 0 << endl;
    }
    else {
        n = n % k;

        if ( abs(n-k) > n) {
            cout << n << endl;
        }
        else if (n == k) {
            cout << 0 << endl;
        }
        else {
            cout << abs(n-k) << endl;
        }
    }

    
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    
    int count = 0;
    if (!(A%2==B%2 && B%2==C%2)) {
        if (A%2==B%2) {
            ++A;
            ++B;
            ++count;
        } else if(A%2==C%2) {
            ++A;
            ++C;
            ++count;
        } else {
            ++B;
            ++C;
            ++count;
        }
    }
    int maxnum = max(max(A, B), C);
    count += (maxnum-A)/2;
    count += (maxnum-B)/2;
    count += (maxnum-C)/2;

    cout << count << endl;
    return 0;
    
}

Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	ll N, Y;
	
	cin >> N >> Y;
	bool find = false;

	for(int i = 0; i <= Y / 10000; i++)
	{
		for (int j = 0; j <= Y / 5000; j++)
		{
			ll remaining = Y - 10000 * i - 5000 * j;
			ll r_ = N - i - j;

			if ((remaining == r_ * 1000) && (r_ >=0) )
			{
				cout << i << " " << j << " " << r_ << endl;
				find = true;
				break;
			}
		}
		if (find)
		{
			break;
		}
	}

	if (!find)
	{
		cout << -1 << " " << -1 << " " << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int pos;
	string str;
	string search;
	string kari;
	cin >> str;
	
	for(int i=str.length()-1;i>0;i--){
		search = str.substr(0,i);
		pos = search.length()/2;
		
		if((kari = search.substr(0,pos = search.length()/2)) + kari == (search.substr(0,pos) + search.substr(pos,search.length())))
			break;
	}
	cout << search.length() << endl;
}

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

	int n, k;
  	vector<int> d;
  	vector<vector<int>> a;

	int ans = 0;

int main(void){
  	cin >> n >> k;
    d.resize(k);
    a.resize(k, vector<int>());
  	for(int i=0; i<k; i++){
      	cin >> d[i];
        a[i].resize(d[i]);
    	for(int j=0; j<d[i]; j++){
          cin >> a[i][j];
        }
    }
    
 	for(int i=1; i<=n; i++){
    	bool have = false;
      	for(auto v : a){
        	for(auto p : v){
            	if(p == i) have = true;
            }
        }
      	if(!have) ans++;
    }
  	cout << ans;
	return 0;
}

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

ll k;
vector<pair<ll,ll>> adj[100005];

ll napravigraf(ll s,ll k)
{
    vector<ll> d(k+1,100005);
    deque<ll> q;
    d[s]=0;
    q.push_front(s);
    while (!q.empty())
    {
        int v=q.front();
        q.pop_front();
        for(auto edge: adj[v])
        {
            int u=edge.first;
            int w=edge.second;
            if(d[v]+w<d[u])
            {
                d[u]=d[v]+w;
                if(w==1)
                    q.push_back(u);
                else
                    q.push_front(u);
            }
        }
    }
    return d[k]+1;
}

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

    cin>>k;
    for(ll i=1;i<k;i++)
        adj[i].push_back({(i+1),1});
    for(ll i=1;i<k;i++)
    {   if((10*i)%k==0)
            adj[i].push_back({k,0});
        else
            adj[i].push_back({(10*i)%k,0});
    }
    cout<<napravigraf(1,k)<<endl;

    return 0;
}


Measured memory_bytes: 11472
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(void) {
	int A, B, C, D, E;
	cin >> A >> B >> C >> D >> E;

	int ans = 0;
	if (A < 0) {
		if (B == 0)ans += D + abs(A)*C;
		else if (B < 0) ans += (B - A)*C;
		else ans += D + B*E + abs(A)*C;
	}
	else {
		ans += (B - A)*E;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    for(int i = 0; i <= 999; i++) {
        string t;
        t = "";
        if(i < 10) {
            t = "00";
        }
        if(i >= 10 && i < 100) {
            t = "0";
        }
        t = t + to_string(i);
        int p = 0;
        for(int i = 0; i < n; i++) {
            if(t[p] == s[i]) {
                p++;
            }
            if(p == 3) {
                break;
            }
        }
        ans += (p == 3);
    }
    cout << ans << endl;
}


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

bool ok(int n, const vector<char>& good) {
    vector<int> digs;
    if (n == 0) digs.push_back(0);
    while (n > 0) {
        digs.push_back(n % 10);
        n /= 10;
    }
    for (int x : digs) {
        if (!good[x]) return false;
    }
    return true;
}

int main() {
    int n, k;
    scanf("%d%d", &n, &k);

    vector<char> good(10, true);
    for (int i = 0; i < k; ++i) {
        int x;
        scanf("%d", &x);
        good[x] = false;
    }

    while (!ok(n, good)) {
        ++n;
    }
    printf("%d\n", n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min((dp[i-1]+abs(arr[i]-arr[i-1])),(dp[i-2]+abs(arr[i]-arr[i-2])));
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    map<string, int> cnt;
    int t; cin >> t; while (t--) {
        string s; cin >> s;
        cnt[s]++;
    }
    for (auto &s : {"AC", "WA", "TLE", "RE"} ) {
        cout << s << " x " << cnt[s] << '\n';
    }
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  int N, X, Y; cin >> N >> X >> Y;
  vector<int> ans(N-1);
  for (int i = 1; i <= N-1; i++){
    for (int j = i+1; j <= N; j++){
      int dis;
      if(i <= X && j >= Y){
        dis = (j-i)-(Y-X)+1;
      } else if (j <= X || i >= Y){
        dis = j-i;
      } else if (i <= X && j < Y){
        dis = X - i + min(j-X,Y-j+1);
      } else if (i > X && j >= Y){
        dis = j - Y + min(Y-i,i-X+1);
      } else {
        dis = min(j-i,Y-X+1-(j-i));
      }
    ans.at(dis-1)++;
    }
  }
  rep(i,N-1) cout << ans.at(i) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,k ; cin>>n>>k;
  vector<long long>a(200000);
  for(int i=0;i<n;i++){
    long long A; cin>>A;
    a[A-1]++;
  }
  sort(a.begin(),a.end());
  
  int sum=0;
  for(int i=0; i<k ;i++ ){
    sum+=a[200000-1-i];
  }
  if(n-sum>0)cout<<n-sum<<endl;
  else cout<<0<<endl;
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)
#define REP(i, n, m) for (long long i = (long long)(n); i < (long long)(m); i++)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll N, K;
  bool A[110];

  void init() {
    scanf("%lld %lld", &N, &K);
    rep(i, K) {
      ll d;
      scanf("%lld", &d);
      rep(j, d) {
        ll a;
        scanf("%lld", &a);
        a--;
        A[a] = true;
      }
    }
  }

  void solve() {
    ll ans = 0;
    rep(i, N) {
      if(!A[i]) ans++;
    }
    cout << ans << endl;
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

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


int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans=0;
    for (int i=0;i<10;i++) {
        for (int j=0;j<10;j++) {
            for (int k=0;k<10;k++) {
                vector<int> a={i,j,k};
                int m=0;
                for (int l=0;l<n;l++) {
                    if (s[l]-'0'==a[m]) m++;
                    if (m==3) {
                        ans++;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
} 

struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // get lcp of S[a:] and T[b:]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};



int main(){
    ll n;cin >> n;
    string s;cin >> s;
    RollingHash rh(s);
    ll ok=0,ng=n;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2; 
        map<pl,ll> mp;
        bool judge=false;
        rep(i,n){
            if(mid+i>n)break;
            pl p=rh.get(i,mid+i);
            if(mp.count(p)){
                if(mp[p]+mid<=i){
                    judge=true;
                }
            }
            else mp[p]=i;
        }
        if(judge)ok=mid;
        else ng=mid;
    }
    cout << ok <<endl;
}

Measured memory_bytes: 4100
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	vector<int>v(10);
	vector<int>w(10);
	for (int i = 0; i < 10; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < 10; i++) {
		cin >> w[i];
	}
	sort(v.begin(), v.end());
	sort(w.begin(), w.end());
	cout << v[7] + v[8] + v[9] << " " << w[7] + w[8] + w[9] << endl;
	return 0;
}


Measured memory_bytes: 3212
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

test = max([a,b,c,d,e]) - min([a,b,c,d,e])
if test <= k:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 3064
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 998244353;
const long long int INF = 1e18;




long long int N,S,K,A[200050]={},dp[3005]={},sum[3005]={},res=0,x=0,y=0;
long long int findp[3005][3005];
string s;
int main()
{
    cout << fixed << setprecision(18);
    cin>>s;
    for(long long int i = 0; i < s.size(); i++){
        if(s[i]=='0'){x++;}
        else{y++;}
    }
    cout<<min(x,y)*2<<endl;
    
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n,m;
  int i,j;
  int h,r;

  while(1){

    int doll[1005][1005]={};
    int dp[1005][1005]={};

    scanf("%d",&n);
    if(n==0)break;
    rep(i,n){
      scanf("%d %d",&h,&r);
      doll[h][r]=1;
    }

    scanf("%d",&m);
    rep(i,m){
      scanf("%d %d",&h,&r);
      doll[h][r]=1;
    }
  
    for(i=1;i<1001;i++){
      for(j=1;j<1001;j++){
	dp[i][j]=max(max(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1]+doll[i][j]);
      }
    }
 
    cout<<dp[1000][1000]<<endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int ans=0, tmp, n;
	string s;
	cin>> s;

	n=stoi(s);

	rep(i, s.size()) ans+=(int)(s[i]-'0');

	if(n%ans==0) cout<< "Yes" << endl;
	else cout<< "No" <<endl;
 
	return 0;
}

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

const ll MOD = 1e+9+7;
const int INF = 1e+9+7;

int main(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int ans=INF;
    int money=0;
    rep(i,max(X,Y)+1){
        money= max(0,A*(X-i))+max(0,B*(Y-i))+2*i*C;
        ans=min(ans,money);
    }
    cout << ans << endl;
}

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

class Prize{

  public:
    Prize *left;
    Prize *right;
    string name;

    void init(){
      left = NULL;
      right = NULL;
    }

    void addLeft(){
      Prize *new_prize = new Prize;
      new_prize->init();
      this->left = new_prize;
    }

    void addRight(){
      Prize *new_prize = new Prize;
      new_prize->init();
      this->right = new_prize;
    }
};

int searchSameNamePrize(Prize *current, string target){
  int ret_check = target.compare(current->name);
  if(ret_check < 0){
    if(current->left != NULL){
      return searchSameNamePrize(current->left, target);
    }
    else{
      current->addLeft();
      current->left->name = target;
      return 1;
    }
  }
  else if(ret_check > 0){
    if(current->right != NULL){
      return searchSameNamePrize(current->right, target);
    }
    else{
      current->addRight();
      current->right->name = target;
      return 1;
    }
  }
  return 0;
}
 
int main(){
  int n, kind_num = 0;
  int ret=0, i;
  string s_i;

  cin >> n;

  Prize root_prize;
  root_prize.init();

  for(i=0; i<n; i++){
    cin >> s_i;
    kind_num += searchSameNamePrize(&root_prize, s_i);
  }
  cout << kind_num << endl;
}

Measured memory_bytes: 12564
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
long int ans=0;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

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

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

int main() {
    lint N, Q;
    cin >> N >> Q;

    UnionFind tree(N);

    for(lint i = 0; i < Q; i++) {
        lint p, x, y;
        cin >> p >> x >> y;p--;x--;
        tree.unite(x, p); // xの木とyの木を併合する
    }
  
    cout<<(N-ans)<<endl;
    return 0;
}

Measured memory_bytes: 768
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>

using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 1e9+7;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rer(i,l,r) for(int(i)=(l); (i)<(r); ++(i))
#define rep(i,n) rer(i,0,n)
#define gnr(i,l,r) for(int (i)=(r)-1; (i)>=(l); --(i))
#define pri(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<(p).fi<<' '<<(p).se<<'\n'
#define priend(a) {cout<<(a)<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

int main(){
  cin.tie(nullptr); ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);
  
  cin>>n; map<Int,Int>a;
  rep(i,n){
    cin>>x; a[x]++;
  }
  Int ans=0;
  for(Pl p:a){
    if(p.se<p.fi)ans+=p.se;
    else ans+=p.se-p.fi;
  }
  END
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

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

char T[600][600];
int main() {
  int N;
  scanf("%d", &N);
  bool has_any = false;
  REP(i,N) {
    scanf("%s", T[i]);
    REP(j,N) {
      T[i][j] = (T[i][j] == '#');
      if (T[i][j]) has_any = true;
    }
  }
  if (!has_any) {
    printf("-1\n");
    return 0;
  }

  int non_full_columns = 0;
  REP(j,N) {
    bool full = true;
    REP(i,N) full = full && T[i][j];
    if (!full) ++non_full_columns;
  }

  int result = 1e9;
  REP(i,N) {
    int additional = 1;
    REP(k,N) if (T[k][i]) additional = 0;
    int cnt = 0;
    REP(j,N) if (!T[i][j])++cnt;

    result = min(result, cnt + additional + non_full_columns);
  }
  printf("%d\n", result);
}


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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	string s[55];
	int b = h * w;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
		for (auto c : s[i])
			if (c != '.') b--;
	}
	int sh[] = { 0,1,0,-1,0 };
	int d[51][51] = {};
	queue<pair<int, int>> q;
	q.push(make_pair(0, 0));
	d[0][0] = 1;
	while (!q.empty()) {
		auto i = q.front();
		if (i.first == h - 1 && i.second == w - 1)
			break;
		q.pop();
		for (int j = 0; j < 4; j++) {
			int x = i.first + sh[j];
			int y = i.second + sh[j + 1];
			if (x >= 0 && x < h&&y >= 0 && y < w&&s[x][y] == '.' && !d[x][y])
				q.push(make_pair(x, y)), d[x][y] = d[i.first][i.second] + 1;
		}
	}
	cout << (d[h - 1][w - 1] ? b - d[h - 1][w - 1] : -1) << endl;
	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()
b = LIST()

tmp1 = 0
tmp2 = 0
for i, j in zip(a, b):
	if i > j:
		tmp1 += i-j
	elif j > i:
		tmp2 += (j-i)//2

if tmp2 >= tmp1:
	print("Yes")
else:
	print("No")


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

int dist[100001];
int C[100001];
vector<int> e[100001];
void color(int x,int d,int c){
	if(d<=dist[x]||d<0)	return;
	dist[x]=d;
	if(!C[x])	C[x]=c;
	for(int it:e[x])
		color(it,d-1,c);
}
int V[100001],D[100001],CC[100001];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,q;
	cin>>n>>m;
	for(int i=1,u,v;i<=m;i++){
		cin>>u>>v;
		e[u].emplace_back(v);
		e[v].emplace_back(u);
	}
	cin>>q;
	memset(dist,-1,sizeof dist);
	for(int i=1;i<=q;i++)
		cin>>V[i]>>D[i]>>CC[i];
	for(int i=q;i>=1;i--)
		color(V[i],D[i],CC[i]);
	for(int i=1;i<=n;i++)
		cout<<C[i]<<'\n';
}



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

int main(){
	string str;
	cin >> str;
	for(int i = 0; i < str.size(); i++){
		if(str.at(i) == '1'){
			str.at(i) = '9';
		} else {
			str.at(i) = '1';
		}
	}
	cout << str << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef struct
{
	int x,y;
}T;
T k[5];
int main()
{
	int n,m,a,b,flag=0,sum,i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	{
		if(i==1&&n>1)
			k[i].x=1;
		else
			k[i].x=0;
		k[i].y=0;
	}
	while(m--)
	{
		scanf("%d%d",&a,&b);
		if(a==1&&b==0&&n>1)	
		{
			flag=1;
			break;
		}
		if(k[a].y==0||k[a].x==b)
		{
			k[a].x=b;
			k[a].y=1;
		}
		else
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
		printf("%d",-1);
	else
	{
		sum=0;
		for(i=1;i<=n;i++)
			sum=sum*10+k[i].x;
		printf("%d",sum);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a;
bool dp[100010];

int main(){
	cin >> n; dp[0]=true;
	REP(i,0,n){
		cin >> a;
		RREP(j,100009,0) if(dp[j]) dp[j+a]=true;
	}
	
	RREP(j,100010,0) if(j%10 and dp[j]){cout << j << endl; return 0;}
	cout << 0 << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;





int main(){
    ll n,k,q;
    cin>>n>>k>>q;
    vector<ll> a(n,k-q);
    rep(i,q){
        ll x;
        cin>>x;
        a[x-1]++;
    }
    rep(i,n){
        if(a[i]>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1536
#c
n,m = map(int,input().split())
res = 0
q = []
for i in range(m):
    q.append(list(map(int,input().split())))
p = list(map(int,input().split()))

#s(あるm桁のビット列)のX桁目が1ならX個目のスイッチがON
for s in range(2**n):#ビット輩出
    judge = True
    for i in range(m):#各ビット桁を見る
        cnt = 0
        for j in range(1,len(q[i])):#スイッチの状態についてそれぞれ見る
            w = q[i][j]#あるスイッチの状態
            if s>>(w-1) &1 == 1:#スイッチの場所がついていたらカウントする
                cnt += 1
        if cnt % 2 != p[i]:#カウントのあまりがOKかどうか
            judge = False
    if judge:#各ビット桁でfalseが一度も出なかったら
        res += 1
print(res)

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

int main(){
  int n, k;
  cin >> n >> k;
  priority_queue<int, vector<int>, greater<int>> price;
  int p;
  int s = 0;

  rep(i,n){
    cin >> p;
    price.push(p);
  }
  rep(i,k){
    s += price.top();
    price.pop();
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3636
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

class WarshallFloyd():
    def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときは'inf')

    def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

    def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行ける
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d

n,m,o = na()
r = na()
g = WarshallFloyd(n)

for i in range(m):
    a,b,c = na()
    g.add(a-1,b-1,c)

import itertools
p = min(8,n)
rs = list(itertools.permutations(r))

ans = 10000000000000
d = g.WarshallFloyd_search()
for l in rs:
    q = 0
    for j in range(len(l)-1):
        q += d[l[j+1]-1][l[j]-1]
    ans = min(ans, q)

print(ans)

Measured memory_bytes: 61660
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(ReadLine());
        }

        public static long[] Reads()
        {
            return ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x,long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }

        public static long C(long n,long k)
        {
            long x=1;
            for (long i = 1; i <=k; i++)
            {
                x *= n - i + 1;
                x /= i;
            }
            return x;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var q = Reads();
            var n = q[0];
            var c = q[1];
            var k = q[2];
            var t = new long[n];
            for (int i = 0; i < n; i++)
            {
                t[i] = Read();
            }
            Array.Sort(t);
            long ans = 0;
            for (int i = 0; i < n; i++)
            {
                var time = t[i];
                ans++;
                var memo = 0;
                for (int j = i; j < n&& j < i + c && time + k >= t[j]; j++)
                {
                    memo = j;
                    //Write(i);
                }
                i = memo;
                //WriteLine();
                
            }
            WriteLine(ans);
            

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 23460
#include<cstdio>
#include<algorithm>
using namespace std;
void func(int,int);
int main(void)
{
	int jin[18];
	char s[18][4]={"","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei",
					"Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"};
	int m,n,i,j;
	while(1)	{
		scanf("%d %d",&m,&n);
		if(m==0 && n==0)	break;
		for(i=0;i<18;i++)	jin[i]=0;
		jin[0]=m;
		for(i=2;i<=n;i++)	{
			for(j=0;j<18;j++)	{
				jin[j]*=m;
			}
			for(j=0;j<17;j++)	{
				jin[j+1]+=jin[j]/10000;
				jin[j]=jin[j]%10000;
			}
		}
		for(i=17;i>=0;i--)	{
			if(jin[i]!=0)	{
				printf("%d%s",jin[i],s[i]);
			}
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; ++i)

main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    rep(i, 0, h) {
        rep(j, 0, w) {
            bool f1 = (j < a && i < b);
            bool f2 = (j >= a && i >= b);
            if (f1 || f2) cout << 1;
            else cout << 0;
        }
        cout << '\n';
    }
}

Measured memory_bytes: 1280
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());

    let a: i32 = sc.next();
    let b: i32 = sc.next();
    println!("{} {}", a * b, (a + b) * 2);
}

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}



Measured memory_bytes: 5032
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,d;
	int n;
	cin>>n>>a>>b;
	if(a>b)swap(a,b);
	if(n>=a+b)c=0;
	else c=a+b-n;
	cout<<a<<" "<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

double entoropy(vector<int> a, vector<int> b ){
    vector<int> O(a.size());
    rep(i,a.size()){
        O[i] = (a[i]+b[i+1])%256;
    }

    vector<int> hist(256,0);
    rep(i,O.size()){
        hist[O[i]]++;
    }

    int n = a.size();
    double ret = 0;
    rep(i,256){
        if(hist[i]==0)continue;
        ret -= (double)hist[i]/n*log((double)hist[i]/n);
    }
    return ret;
}

int main(){
    int n;
    while(cin>>n&&n){
        vector<int> I(n);

        rep(i,n)cin>>I[i];

        double h = INF;

        int S,A,C;
        rep(s,15+1){
            rep(a,15+1){
                rep(c,15+1){
                    vector<int> R(n+1);
                    R[0] = s;
                    for(int i=1;i<=n;i++){
                        R[i] = (a*R[i-1]+c) % 256;
                    }

                    double th = entoropy(I,R);
                    if(h-(1e-12)>th){
                        S = s;
                        A = a;
                        C = c;
                        h = th;
                    }
                }
            }
        }
        cout<<S<<" "<<A<<" "<<C<<endl;
    }
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

long long dijkstra(const WGraph &G, const int s, const int t) {
    int n = (int)G.size();
    std::vector<long long> dis(n, LINF);
    dis.at(s) = 0;
    using P = std::pair<long long, int>;
    std::priority_queue<P, std::vector<P>, std::greater<P>> que;
    que.push(std::make_pair(0, s));

    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        int v = p.second;
        if (dis.at(v) < p.first) {
            continue;
        }
        for (auto e : G.at(v)) {
            if (dis.at(e.first) > dis.at(v) + e.second) {
                dis.at(e.first) = dis.at(v) + e.second;
                que.push(std::make_pair(dis.at(e.first), e.first));
            }
        }
    }
    return dis.at(t) == LINF ? -1 : dis.at(t);
}

void solve() {
    int n, m;
    cin >> n >> m;

    WGraph G(n);
    for (int i=0; i<n-1; ++i) {
        G.at(i+1).push_back({i, 0});
    }
    for (int i=0; i<m; ++i) {
        int l, r, c;
        cin >> l >> r >> c;
        G.at(l-1).push_back({r-1, c});
    }

    cout << dijkstra(G, 0, n-1) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 10112
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}

vector<vecpii> G;
vec dfs(int x,int p,int y,int num){
    vec res={num};
    if(x==y)return {num};
    for(auto e:G[x]){
        vec t;
        if(e.first!=p){
            t=dfs(e.first,x,y,e.se);
            if(t.size()){
                for(auto ee:t)res.pb(ee);
            }
        }
    }
    if(res.size()==1){
        return vec();
    }
    else return res;
}
main(){
    int n=in();
    G.resize(n);
    rep(i,n-1){
        int a=in()-1,b=in()-1;
        G[a].eb(b,i);G[b].eb(a,i);
    }
    int m=in();
    vector<vec> v;
    rep(i,m){
        int x=in()-1,y=in()-1;
        vec s=dfs(x,-1,y,n);
        v.pb(s);
    }
    ll ans=1ll<<(n-1);
    rep(mask,1<<m){
        if(mask==0)continue;
        int k=0;
        rep(i,m){
            if((1<<i)&mask)k++;
        }
        ll d=(k%2 ? -1:1);
        vec used(n+1);
        rep(i,m){
            if((1<<i)&mask){
                rep(j,(int)v[i].size()){
                    used[v[i][j]]++;
                }
            }
        }
        ll t=0;
        rep(i,n-1)t+=(!(used[i]));
        ans+=d*(1ll<<(t));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vec vector <ll>
#define pa pair<ll,ll>
#define mp make_pair
#define pb push_back
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll ans=0;
	ll  a=n/500;
	ans+=a*1000;
	n=n%500;
	ll b=n/5;
	ans+=b*5;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    long long a[n]; rep(i,n) cin>>a[i];
    int r=0;
    long long ans=0,sum=0;
    for(int l=0;l<n;l++){
        while(r<n&&(sum+a[r]==(sum^a[r]))){
            sum+=a[r];
            r++;
        }
        // cout<<l<<" "<<r<<" "<<sum<<endl;
        ans+=r-l;
        if(l==r) r++;
        else sum-=a[l];
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  double L;
  cin >> L;
  double ans = L*L*L/27;
  cout << std::fixed;
  cout << std::setprecision(9) << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


def checkC(N,A,B):
    ans = -1
    shortage = np.array([a-b if a<b else 0 for a,b in zip(A,B)])
    exceed = np.array([a-b if a>b else 0 for a,b in zip(A,B)])
    ss = shortage[shortage!=0]
    ee = exceed[exceed!=0]
    # print(ss)
    ssum = -ss.sum()
    ans = ss.shape[0]
    eesort = np.sort(exceed)[::-1]
    # print(eesort)
    k = 0
    i = 0
    while k < ssum:
        k +=  eesort[i]
        i += 1
        ans += 1
    # print(exceed[exceed!=0].shape)

    return ans


if sum(A) < sum(B):
    print(-1)
else:
    print(checkC(N,A,B))

Measured memory_bytes: 27080