akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <bitset>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

bool contain(const std::string& s, const std::string& t) {
    auto it = t.begin();
    for (char c : s) {
        if (it != t.end() && c == *it) ++it;
    }
    return it == t.end();
}

void solve() {
    int n, k;
    std::cin >> n >> k;

    std::vector<std::pair<std::string, std::string>> ss;
    for (int i = 0; i < n; ++i) {
        std::string s;
        std::cin >> s;

        std::string t;
        for (char c = 'A'; c < 'A' + n; ++c) {
            if (!std::count(s.begin(), s.end(), c)) {
                t.push_back(c);
            }
        }

        do {
            ss.emplace_back(s, t);
        } while (std::next_permutation(t.begin(), t.end()));
    }

    int d = (int)ss.size() / n;

    std::vector<std::vector<int>> to(n * d);
    for (int u = 0; u < n * d; ++u) {
        auto pu = ss[u];

        for (int v = 0; v < n * d; ++v) {
            auto pv = ss[v];

            // uの後に得られる文字列
            auto s = std::string(pu.first.rbegin(), pu.first.rend()) +
                     pu.second;

            if (contain(s, pv.first) &&
                contain(s, pv.second)) {
                to[u].push_back(v);
            }
        }
    }

    auto dp = vec(1 << n, vec(n * d, std::string(1, '$')));
    for (int v = 0; v < n * d; ++v) {
        char c = 'A' + v / d;
        dp.back()[v] = std::string(1, c);
    }

    std::function<std::string(int, int)> dfs =
        [&](int b, int v) -> std::string {
        auto& ret = dp[b][v];
        if (ret != "$") return ret;

        ret = "";
        for (auto u : to[v]) {
            int j = u / d;
            if ((b >> j) & 1) continue;

            auto res = dfs(b | (1 << j), u);
            if (res.empty()) continue;

            if (ret.empty() || res < ret) ret = res;
        }

        if (ret.empty()) return ret;

        char c = 'A' + v / d;
        ret = c + ret;
        return ret;
    };

    std::string ans(n, 'Z');
    for (int v = 0; v < n * d; ++v) {
        int i = v / d;
        auto res = dfs(1 << i, v);

        if (res.empty()) continue;
        ans = std::min(ans, res);
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}



Measured memory_bytes: 84428
//Coalbert Ramirez
//AtCoder Begginer Contest A - Station and Bus
#include <bits/stdc++.h>
using namespace std;

int main(){
  char station[3];
  cin >> station[0] >> station[1] >> station[2];
  cout << ((station[0]!=station[1] || station[0]!=station[2])? "Yes\n": "No\n");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
using namespace std;
typedef long long llong;

int N;
pair<string, int> p[1000];
pair<pair<string, int>, int> q[100];


bool ope(pair<pair<string, int>, int>a, pair<pair<string, int>,int>b)
{
	if (a.first.first != b.first.first) return a.first.first <= b.first.first;
	else return a.first.second > b.first.second;
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++) {
		string s;
		int po;
		cin >> s >> po;
		p[i] = make_pair(s, po);
		q[i] = make_pair(p[i], i);
	}

	sort(q, q + N, ope);
	for (int i = 0; i < N; i++) cout << q[i].second + 1 << '\n';

	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<unordered_map>
#define int long long
const int inf=1145141919810893;
const int mod=1000000007;
using namespace std;
template<class T>bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<class T>bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<class T>void debug(T *a,int l,int r,const char *name){
	for(int i=l;i<r;i++)
		cout<<name<<"["<<i<<"]="<<a[i]<<endl;
}
int N,Z,W;
int p[2000];
signed main(){
	int i,j,k;
	cin>>N>>Z>>W;
	for(i=0;i<N;i++)
		cin>>p[i];
	int ans=abs(p[N-1]-W);
	if(N>1)
		chmax(ans,abs(p[N-1]-p[N-2]));
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#! /usr/bin/python
# -*- coding: utf-8 -*-

# 数字入力　行数＋数字
n=int(input()) #行数

num_list=[int(input()) for i in range(n)]

# print(num_list)

# Derive the maximum profit under the condition j > i
# max_profit = num_list[1] - num_list[0]
# min_value = num_list[0]
# max_value = num_list[1]
# i, j = 0, 0
# # Before
# for j in range(1, n):
#     for i in range(0, j):
#         max_profit = max(max_profit, num_list[j]-num_list[i])
# print("max_profit with algorithm 1 is "+ str(max_profit))

min_value = num_list[0]
max_profit = -10**9
# After
for i in range(1,n):
        max_profit = max(max_profit, num_list[i] - min_value)
        min_value = min(num_list[i], min_value)

# print("max profit with algorithm 2 is " + str(max_profit))
print(max_profit)


Measured memory_bytes: 13596
using System;

namespace A___Kenken_Race
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var N = read[0];
            var A = read[1];
            var B = read[2];
            var C = read[3];
            var D = read[4];
            var S = Console.ReadLine();

            var subS = S.Substring(A-1,Math.Max(C,D)-A+1);
            Console.WriteLine(solver(A-1,B-A,C-A,D-A,subS) ? "Yes":"No");            
        }
        static bool solver(int A,int B,int C,int D,string S)
        {
            if(S.IndexOf("##") >= 0) return false;
            if(C<D) return true;
            if(S.Substring(B,D-B+1).IndexOf("...")>=0) return true;
            if(S.Substring(D-1,3) == "...") return true;
            if(S.Substring(B-1,3) == "...") return true;
            return false;
        }
    }
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    string s;
    cin >> s;

    int t = 700;
    t += s[0] == 'o' ? 100 : 0;
    t += s[1] == 'o' ? 100 : 0;
    t += s[2] == 'o' ? 100 : 0;

    cout << t << endl;
}


Measured memory_bytes: 256
///ABC_127_B
#include <iostream>
#include <cstdio>
using namespace std;
main()
{
    int r,d,x;
    cin >> r >> d >> x;
    for( int i = 0; i < 10; i++ )
    {
        x = r * x - d;
        cout << x << endl;
    }    
    return 0;
}

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

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

    int n, t;
    cin >> n >> t;

    if (t == 1 || t == 2 * n - 1) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    if (n == 2) {
        cout << 1 << endl;
        cout << 2 << endl;
        cout << 3 << endl;
        return 0;
    }

    vector<pair<int, int>> posValue;

    if (t == 2 * n - 2) {
        posValue = {
            make_pair(n - 2, 2),
            make_pair(n - 1, 2 * n - 1),
            make_pair(n, 2 * n - 2),
            make_pair(n + 1, 1)
        };
    } else {
        posValue = {
            make_pair(n, t),
            make_pair(n - 1, t - 1),
            make_pair(n - 2, 2 * n - 1),
            make_pair(n + 1, t + 1)
        };
    }

    vector<bool> usedPos(2 * n, false);
    vector<bool> usedValue(2 * n, false);
    vector<int> result(2 * n);
    for (const pair<int, int>& p : posValue) {
        usedPos[p.first] = true;
        usedValue[p.second] = true;
        result[p.first] = p.second;
    }

    queue<int> values;
    for (int i = 1; i < 2 * n; ++i) {
        if (!usedValue[i]) {
            values.push(i);
        }
    }

    for (int i = 1; i < 2 * n; ++i) {
        if (!usedPos[i]) {
            result[i] = values.front();
            values.pop();
        }
    }

    for (int i = 1; i < 2 * n; ++i) {
        cout << result[i] << '\n';
    }
    cout.flush();

    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
int n, a[maxn], b[maxn];
vector<int> vec;
ll ans;
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d%d", &a[i], &b[i]);
		if(a[i] > b[i]) vec.push_back(b[i]);
		ans += a[i];
	}
	if(vec.empty())
	{
		puts("0");
		return 0;
	}
	printf("%lld\n", ans - *min_element(vec.begin(), vec.end()));
	return 0;
}

Measured memory_bytes: 512
import numpy as np
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [np.array(list(map(int, input().split()))) for _ in range(N)]
answer = 0
for i in range(N):
    if sum(A[i]*B)+C > 0:
        answer += 1
print(answer)

Measured memory_bytes: 12420
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> II;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N, M; cin >> N >> M;
	vector<int> P(M,0), Y(M,0);
	rep (i, M){
		cin >> P[i] >> Y[i];
		--P[i];
	} // end rep

	vector<II> ken[N];
	rep (i, N) ken[i].clear();
	rep (i, M){
		ken[P[i]].push_back(II(Y[i],i));
	} // end rep

	rep (i, N){
		if ((int)ken[i].size() > 0){
			sort(ALL(ken[i]));
		} // end if
	} // end rep

	map<int,int> trans[N];
	rep (i, N){
		trans[i].clear();
	} // end rep

	rep (i, N){
		rep (j, (int)ken[i].size()){
			int k = ken[i][j].second;
			trans[i][k] = j;
		} // end rep
	} // end rep

	rep (i, M){
		int state = P[i] + 1;
		int city  = trans[P[i]][i] + 1; 
		cout << setw(6) << setfill('0') << state << setw(6) << setfill('0') << city << endl;
	} // end rep
 
	return 0;
}

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

long long dist[300][300];
long long refuel[300][300];

int main(){
	int N,M,Q;
	long long L;
	cin >> N >> M >> L;
	
	for(int i=0;i<N;i++)for(int j=0;j<N;j++){
		dist[i][j]=(i==j ? 0 : 999999999999LL);
		refuel[i][j]=(i==j ? 0 : 999999999999LL);
	}
	
	for(int i=0;i<M;i++){
		int a,b;
		long long c;
		cin >> a >> b >> c;
		a--;
		b--;
		if(c<=L){
			dist[a][b]=dist[b][a]=c;
		}
	}
	
	for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++)
		dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
	
	for(int i=0;i<N;i++)for(int j=0;j<N;j++){
		if(i==j)continue;
		if(dist[i][j]<=L)refuel[i][j]=refuel[j][i]=1;
	}
	
	for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++)
		refuel[i][j]=min(refuel[i][j],refuel[i][k]+refuel[k][j]);
	
	cin >> Q;
	for(int q=0;q<Q;q++){
		int s,t;
		cin >> s >> t;
		s--;
		t--;
		if(refuel[s][t]>100000000)cout << "-1" << endl;
		else cout << refuel[s][t]-1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=6;
static const int D=365;
static const int ntype=26;
static int ans[D+1];
static int max_score=0;
static int t=3e5;

class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int Score(int type){
    int sum=0;
    contest[type].last=0;
    for(int day=1;day<=D;++day){
        if(ans[day]==type){
            sum+=contest[type].s[day];
            int n=day-contest[type].last;
            sum-=contest[type].c*(n*(n-1)/2);
            contest[type].last=day;
        }
    }
    if(ans[D]!=type){
        int n=D-contest[type].last;
        sum-=contest[type].c*(n*(n+1)/2);
    }
    return sum;   
}

void Output(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for(int d=1;d<=D;++d) cout<<ans[d]<<'\n';
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void Greedy(){
    vector<int> l(ntype+1,0);
    int score=0;
    for(int d=1;d<=D;++d){
        for(int i=1;i<=ntype;++i) score-=contest[i].c*(d-l[i]);
        int temp=score;
        int t=-1;
        for(int i=1;i<=ntype;++i){
            int k=contest[i].s[d]+contest[i].c*(d-l[i])+score;
            if(k>temp){
                temp=k;
                t=i;
            }
        }
        ans[d]=t;
        l[t]=d;
    }
}

void change(){
    int p=rand()%D+1;
    int temp=ans[p];
    int before_score=Score(temp);
    ans[p]=rand()%ntype+1;
    //cout<<"p: "<<p<<" from: "<<temp<<" to: "<<ans[p]<<endl;
    int delta=Score(ans[p])-before_score;
    if(delta>0){
        max_score+=delta;
    }
    else ans[p]=temp;
}

void swap(){
    int p1=rand()%D+1;
    int p2=rand()%D+1;
    while(p1==p2) p2=rand()%D+1;
    int temp_score=Score(ans[p1])+Score(ans[p2]);
    int temp=ans[p1];
    ans[p1]=ans[p2];
    ans[p2]=temp;
    int delta=Score(ans[p2])+Score(ans[p1])-temp_score;
    if(delta>0){
        max_score+=delta;
    }
    else{
        ans[p2]=ans[p1];
        ans[p1]=temp;
    }
}

void Solve(int times){
    Greedy();
    for(int i=1;i<=ntype;++i) max_score+=Score(i);
    //cout<<max_score<<endl;
    for(int i=0;i<times;++i){
        swap();
        //change();
    }
}

int main(){
    srand(seed);
    Input();
    Solve(t);
    Output();
}


Measured memory_bytes: 3716
let reads f = stdin.ReadLine().Split(' ') |> Array.map f
let (|Even|Odd|) i = if i % 2 = 0 then Even else Odd

reads int
|> (fun xs -> xs.[0] + xs.[1])
|> (fun x -> match x with Even -> string (x / 2) | Odd -> "IMPOSSIBLE")
|> printfn "%s"

Measured memory_bytes: 14044
#include<stdio.h>
#include <iostream>
#include <string.h>
#include <cstdlib>
 
using namespace std;
 
#define BUF_SIZE 1024
 
struct Node{
    int data;
    Node* prev;
    Node* next;
};
 
class ConnectedList{
public:
    ConnectedList(){
        motherNode = new Node();
        motherNode->data = -1;
        motherNode->prev = motherNode;   
        motherNode->next = motherNode;
    };
    ~ConnectedList(){
        Node* tmpNode = motherNode->next;
        Node* nextNode;
        while(tmpNode != motherNode){
            nextNode = tmpNode->next;
            delete tmpNode;
            tmpNode = nextNode;
        }
        delete motherNode;
    };
    void insertNode(int x){
        Node* tmpNode = motherNode->next;
        motherNode->next = new Node();
        motherNode->next->data = x;
        motherNode->next->next = tmpNode;
        motherNode->next->prev = motherNode;
        tmpNode->prev = motherNode->next;
    };
    void deleteNode(int x){
        Node* tmpNode = motherNode->next;
        while(tmpNode != motherNode && tmpNode->data != x){
            tmpNode = tmpNode->next;
        }
        if(tmpNode != motherNode){  
            tmpNode->prev->next = tmpNode->next;
            tmpNode->next->prev = tmpNode->prev;
            delete tmpNode;
        }
    };
 
    void deleteFirst(){
        Node* tmpNode = motherNode->next;
        motherNode->next = motherNode->next->next;
        motherNode->next->prev = motherNode;
        delete tmpNode; 
    };
 
    void deleteLast(){
        Node* tmpNode = motherNode->prev;
        motherNode->prev = motherNode->prev->prev;
        motherNode->prev->next = motherNode;
        delete tmpNode; 
    };
 
    void showList(){
        Node* tmpNode = motherNode->next;
        printf("%d",tmpNode->data);
        tmpNode = tmpNode->next;
        while(tmpNode != motherNode){
            printf(" %d",tmpNode->data);
            tmpNode = tmpNode->next;
        }
        printf("\n");
    }
 
private:
    Node* motherNode;
};
 
 
int main(){
 
    char buf[BUF_SIZE];
    int n = atoi(fgets(buf,BUF_SIZE,stdin));
 
    ConnectedList list;
 
    for(int i = 0; i < n; i++){
 
        fgets(buf,BUF_SIZE,stdin);
 
        if(buf[6] == 'F'){
            list.deleteFirst();
        }else if(buf[6] == 'L'){
            list.deleteLast();
        }else{
            int S = 0;
             
            if(buf[0] == 'i'){  //insert x
 
                for(int i = 0; buf[i] != '\0';i++){
                    if(buf[i] >= '0' && buf[i] <= '9'){
                        S = 10*S + (buf[i] - '0');
                    }
                }
                list.insertNode(S);
            }else{  
                for(int i = 0;buf[i] != '\0';i++){
                    if(buf[i] >= '0' && buf[i] <= '9'){
                        S = 10*S + (buf[i] - '0');
                    }
                }
                list.deleteNode(S);
            }
 
        }
 
    }
 
    list.showList();
 
}


Measured memory_bytes: 34452
#include<stdio.h>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<math.h>
#include<map>
#include<algorithm>
#include<queue>
#include<string>
#include<climits>
#include<bitset>
#include<set>
#include<functional>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
#ifdef _WIN32
    #define gx getchar
    #define px putchar
    #define ps putchar(' ')
    #define pn putchar('\n')
    #define DEBUG 1
#else
    #define gx getchar_unlocked
    #define px putchar_unlocked
    #define ps putchar_unlocked(' ')
    #define pn putchar_unlocked('\n')
    #define DEBUG 0
#endif
 
//input
void scan(int &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' ) sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * sign;
}
void lscan(ll &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' )
        sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * (ll)(sign);
}
int sscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
int wscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n' && c!=' ')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
 
//output
void print(int n)
{
    if(n<0)
    {
        n=-n;
        px('-');
    }
    int i=10;
    char o[10];
    do{o[--i] = (n%10) + '0'; n/=10;}while(n);
    do{px(o[i]);}while(++i<10);
}
void lprint(ll n)
{
    if(n<0LL)
    {
        n=-n;
        px('-');
    }
    int i=21;
    char o[21];
    do{o[--i] = (n%10LL) + '0'; n/=10LL;}while(n);
    do{px(o[i]);}while(++i<21);
}
void sprint(const char a[])
{
    const char *p=a;
    while(*p)px(*p++);
}
 
 
ll po(ll a, ll b, ll m)
{
	ll x=1,y=a;
	while(b > 0)
	{
		if(b%2 == 1)
		{
			x=(x*y);
			if(x>m) x%=m;
		}
		y = (y*y);
		if(y>m) y%=m;
		b /= 2;
	}
	return x;
}
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int v[] = {
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};

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

  cout << v[K-1] << endl;
  
  return 0;
}



Measured memory_bytes: 764
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int N = 3;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int k = parseInt(sc.next());
		int x = parseInt(sc.next());
		int y = parseInt(sc.next());
		sc.close();
		out.println(k<n?k*x+(n-k)*y:n*x);
	}
}


Measured memory_bytes: 23892
#include <iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,n;
    cin >> h >> n;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        h -= a;
    }
    if (h <= 0)
    {
        cout << "Yes" << "\n";
    } else
    {
        cout << "No" << "\n";
    }
    
    
    return 0;
}

Measured memory_bytes: 256
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue
# sys.setrecursionlimit(2000000)

import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

MOD = 1000000007

def main():
    # N = int(input())

    N, K = [int(s) for s in input().split()]

    # sum of 0~i
    s = 0
    comm_sum = [0]
    for i in range(1, N+1):
        s += i
        comm_sum.append(s)

    # sys.stderr.write('{}\n'.format(comm_sum))

    ans = 0
    for k in range(K, N+1 + 1):
        if k == N + 1:
            ans = (ans + 1) % MOD
            continue
        max_a = comm_sum[N] - comm_sum[N - k]
        min_a = comm_sum[k - 1]
        diff = max_a - min_a + 1
        ans = (ans + diff) % MOD
        # sys.stderr.write('k = {}\n'.format(k))
        # sys.stderr.write('{}\n'.format(min_a))
        # sys.stderr.write('{}\n'.format(max_a))
        # sys.stderr.write('{}\n'.format(diff))
        # sys.stderr.write('--\n')

    print(ans)

    return 0

if __name__ == '__main__':
    sys.exit(main())


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

int main() {
	int N, K, min = 30;
  	cin >> N;
  
		for (int i = 0; i < N; i++) {
          int A;
          cin >> A;
          K = 0;
          
          while (A%2 == 0) {
              K++;
              A /= 2;
          }
          
          if (K <= min) min = K;
        }
  
  cout << min << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
  cin>>i>>j;
  cout<<i*j;
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3696
/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
int main()
{
	string st;
	cin>>st;
	if(st[2]==st[3]&&st[4]==st[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long a,b;

int main()
{
    cin >> a >> b;
    if (a == 1 || b == 1) cout << 1;
    else 
    {
        if (a%2 != 0)
            if (b%2 != 0)
                cout << (a/2+1)*(b/2+1)+(a-(a/2+1))*(b-(b/2+1));
            else 
                cout << (a/2+1)*(b/2)+(a-(a/2+1))*(b-b/2);
        else 
            if (b%2 != 0)
                cout << (a/2)*(b/2+1)+(a-a/2)*(b-(b/2+1));
            else 
                cout << (a/2)*(b/2)+(a-a/2)*(b-b/2);
    }
}

Measured memory_bytes: 256
import Control.Monad
import Data.Bits

main = do
    n <- read <$> getLine
    putStrLn $ solve n 1

solve :: Int -> Int -> String
solve n b | n == 0    = "0"
          | n == b    = "1"
          | cond      = solve  n      (b * (-2)) ++ "0"
          | otherwise = solve (n - b) (b * (-2)) ++ "1"
  where
    cond = abs n .&. abs b == 0


Measured memory_bytes: 508
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define maxn 300005
#define eps 1e-5
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,p,k;
char ch[1005];
int a[200005];
ll val[200005];
ll ans;
int main()
{
	int i,j,l,op,x,y;
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    n=read();
    for(i=1;i<=n;i++) a[i]=read(),val[a[i]]++;
    for(i=1;i<=n;i++) ans+=val[i]*(val[i]-1)/2;
    for(i=1;i<=n;i++) {
    	ans-=val[a[i]]*(val[a[i]]-1)/2;
    	ans+=(val[a[i]]-1)*(val[a[i]]-2)/2;
    	printf("%lld\n",ans);
    	ans+=val[a[i]]*(val[a[i]]-1)/2;
    	ans-=(val[a[i]]-1)*(val[a[i]]-2)/2;
    }
    return 0;
} 

Measured memory_bytes: 3968
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        String s=in.next();
        StringBuilder ans=new StringBuilder(s);
        if(s.charAt(s.length()-1)=='s')
            ans.append("es");
        else
            ans.append("s");
        System.out.println(ans.toString());
    }

}


Measured memory_bytes: 35572
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int s=gi();
	    int w=gi();

	    //System.out.print(nr*2*Math.PI);
	    if (s>w) {
	    	System.out.print("safe");
	    }else {
	    	System.out.print("unsafe");
	    }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35744
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
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; }
const long long INF = 1LL << 60;

const int MAX_N = 110;
const int MAX_V = 100100;

int N;
long long W, weight[MAX_N], value[MAX_N];

long long dp[MAX_N][MAX_V];

int main()
{
    cin >> N >> W;
    rep(i,N) cin >> weight[i] >> value[i];

    rep(i,MAX_N) rep(j,MAX_V) dp[i][j] = INF;

    dp[0][0] = 0;

    rep(i,N){
        rep(sum_v,MAX_V){

            //i番目の品物を選ぶ場合
            if(sum_v - value[i] >= 0) chmin(dp[i+1][sum_v],dp[i][sum_v - value[i]] + weight[i]);

            //i番目の品物を選ばない場合
            chmin(dp[i+1][sum_v],dp[i][sum_v]);
        }
    }

    long long res = 0;
    rep(sum_v,MAX_V){
        if(dp[N][sum_v] <= W) res = sum_v;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 86272
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val abc: Array[Int] = sc.nextLine.split(" ").map(_.toInt).sorted.reverse
    val k: Int = sc.nextLine.toInt

    val ans: Int = (1 to k).foldLeft(abc) {
      (tempAbc, _) => Array(2 * tempAbc.head, tempAbc(1), tempAbc.last)
    }.sum
    println(ans)
  }

}


Measured memory_bytes: 25632
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a[]=sc.nextLine().split (" ");
		String b=a[0]+a[1]+a[2];
		int ans=Integer.parseInt(b,2);
		if(ans==6||ans==1)System.out.println("Open");
		else System.out.println("Close");
	}
}

Measured memory_bytes: 17304
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(strength(s)&&strength(s.substring(0,s.length()/2))&&strength(s.substring((s.length()+1)/2,s.length()))){
            System.out.println("Yes");
        }
        else System.out.println("No");

    }
    private static boolean strength(String s){
        for(int i=0;i<s.length()/2;i++){
            if(s.charAt(i)!=s.charAt(s.length()-i-1))return false;

        }
        return true;
    }
}


Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
import sys
import cmath
import math

class Point(object):
    def __init__(self, x, y):
        self.point = complex(x, y)

    def __str__(self):
        return "x = {0}, y = {1}".format(self.point.real, self.point.imag)


class Triangle(Point):
    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c

        # ３辺の長さ
        self.edgeA = abs(b.point-c.point)
        self.edgeB = abs(c.point-a.point)
        self.edgeC = abs(a.point-b.point)

        # ３角の大きさ
        self.angleA = Triangle.angle(self.edgeA, self.edgeB, self.edgeC)
        self.angleB = Triangle.angle(self.edgeB, self.edgeC, self.edgeA)
        self.angleC = Triangle.angle(self.edgeC, self.edgeA, self.edgeB)

    # 角度を求める
    def angle(A, B, C):
        return cmath.acos( (B*B+C*C-A*A)/(2*B*C) ).real


eps = 0.0001
for line in sys.stdin:
    line = [float(x) for x in line.split()]
    p1 = Point(line[0], line[1])
    p2 = Point(line[2], line[3])
    p3 = Point(line[4], line[5])
    P  = Point(line[6], line[7])
    t1 = Triangle(p1, p2, P)
    t2 = Triangle(p2, p3, P)
    t3 = Triangle(p3, p1, P)
    if (math.degrees(t1.angleC + t2.angleC + t3.angleC) <= 360+eps) and (math.degrees(t1.angleC + t2.angleC + t3.angleC) >= 360-eps):
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 7000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int ans=0;
	bool flag=false;
	rep(i,n){
		int a;
		cin>>a;
		if(a%2==0){
			while(a%2==0 && a!=0){
				ans++;
				a/=2;
			}
			flag=true;
		}
	}
	if(!flag) ans=0;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
#define enld endl
typedef long long ll;
using namespace std;

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

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll A;
    string B; 
    cin >> A >> B;
    string BB = "";
    for(int i=0;i<B.size();i++){
        if(B[i] != '.'){
            BB += B[i];
        }
    }
    ll BBB = (ll)stoi(BB);
    cout << A*BBB/100 << enld;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    if(s.size() == 1 || n % 2 == 1)
    {
        cout << "No";
        return 0;
    }
    for(int i = 0;i < s.size() / 2;i++)
    {
        if(s[i] != s[i + s.size() / 2])
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";

    return 0;
}

Measured memory_bytes: 256
import * as fs from 'fs'
import {debug} from '../../util'
const output = (x: any) => console.log(x)

const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n')
const [N] = input[0].split(' ').map(n => parseInt(n, 10))
const A = input[1].split(' ').map(n => parseInt(n, 10))
const counter = Array(N).fill(0)
A.map(a => {
    counter[a-1]++
})
counter.map(count => output(count))

Measured memory_bytes: 62780
sids = input()
side_list = []

side_list = [int(s) for s in sids.split(' ', )]

a = side_list[0]
b = side_list[1]

if a > b:
	print('a > b')

elif a < b:
	print('a < b')

elif a == b:
	print('a == b')

Measured memory_bytes: 6724
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);


int main(){
    IOS;
    ll n;cin>>n;
    map<ll,ll>m;
    f(i,0,n-1){
        ll a;cin>>a;
        m[a]++;
    }
    f(i,1,n+1)cout<<m[i]<<"\n";
    return 0;  
} 





Measured memory_bytes: 16124
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;   

const int mo = 1e9 + 7;

ll ksm(ll x, ll y) {
	ll s = 1;
	for(; y; y /= 2, x = x
			* x % mo)
		if(y & 1) s = s * x % mo;
	return s;
}

const ll ni2 = ksm(2, mo - 2);

const int N = 2e5 + 5;

int n, a[N], d[N];
int cnt[N];
ll b[N], c[N];

int cmp(int x, int y) {
	if(a[x] == a[y]) return x < y;
	return a[x] < a[y];
}

ll w[N];

ll sum, ans;
void dg(int x, int y, int u, int v) {
	if(u >= v) return;
	if(x == y) {
		ans = (ans + sum * (v - u + 1) % mo * (v - u) % mo * ni2 % mo * ni2) % mo;
		return;
	}
	int mi = x + y >> 1, m = u - 1;
	while(m < v && a[d[m + 1]] <= mi) m ++;
	dg(x, mi, u, m); dg(mi + 1, y, m + 1, v);

	w[mi] = 1;
	fd(i, mi - 1, x) w[i] = w[i + 1] * c[i + 1] % mo;
	w[mi + 1] = c[mi + 1];
	fo(i, mi + 2, y) w[i] = w[i - 1] * c[i] % mo;

	int l = u; ll s = 0;
	fo(i, m + 1, v) {
		while(l <= m && d[l] <= d[i]) s = (s + w[a[d[l]]]) % mo, l ++;
		ans = (ans + sum * s % mo * w[a[d[i]]] % mo * ni2) % mo;
	}
	l = m, s = 0;
	fd(i, v, m + 1) {
		while(l >= u && d[l] > d[i]) s = (s + w[a[d[l]]]) % mo, l --;
		ans = (ans + sum * (m - l) - sum * s % mo * w[a[d[i]]] % mo * ni2) % mo;
	}
	sort(d + u, d + v + 1);
}

int main() {
	scanf("%d", &n);
	fo(i, 1, n) {
		scanf("%d", &a[i]);
		if(a[i] > n) a[i] = n;
		cnt[a[i]] ++;
	}
	fd(i, n, 1) cnt[i] += cnt[i + 1];
	sum = 1;
	fo(i, 1, n) {
		b[i] = cnt[i] - n + i;
		sum = sum * max(0ll, b[i]) % mo;
	}
	fo(i, 1, n) {
		c[i] = ksm(b[i], mo - 2) * (b[i] - 1) % mo;
	} 
	fo(i, 1, n) d[i] = i;
	sort(d + 1, d + n + 1, cmp);
	dg(1, n, 1, n);
	ans = (ans % mo + mo) % mo;
	pp("%lld\n", ans);
}


Measured memory_bytes: 7296
N = int(input())
 
for h in range(1, 3501):
  for n in range(1, 3501):
    a = (4 * h * n) - N * h - N * n
    if a <= 0:
      continue
    w = (N * h * n) / a
    if w.is_integer() and 0 < w:
      print(h, n, int(w))
      exit(0)

Measured memory_bytes: 9200
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 0) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;
  std::vector<ll> va(N, 0);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  ll ans = *std::max_element(va.begin(),va.end()) - *std::min_element(va.begin(),va.end());
  print(ans);

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] p = new int[N];
    for (int i =0; i<N; i++) {
      p[i] = sc.nextInt();
    }
    Arrays.sort(p);
    int ans =0;
    for (int i =0; i<K; i++) {
      ans += p[i];
    }
    System.out.println(ans);
  }
}  

Measured memory_bytes: 39036
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
	long long a,b,c;
	cin >> a >> b >> c;
	long long x=min(a,c);
	a-=x; c-=x;
	b-=min(c,b);
	cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL<<50;

struct edge{
    ll to;
    ll cost;
    edge(ll t, ll c){
        to = t;
        cost = c;
    }
};

//* dijkstra algorithm with adjacency list
void dijkstra(vector<vector<edge> > &G, vll &dist, ll s){
    fill(dist.begin(), dist.end(), INF);
    priority_queue<pll, vector<pll>, greater<pll> > que;
    dist[s] = 0;
    que.push(pll(0, s));
    while(!que.empty()){
        ll score = que.top().first;
        ll u = que.top().second;
        que.pop();
        for(ll i=0; i< G[u].size(); i++){
            edge e = G[u][i];
            if(dist[e.to] > score + e.cost){
                dist[e.to] = score + e.cost;
                que.push(pll(dist[e.to], e.to));
            }
        }
    }
    return;
}

void solve(long long N, long long M, std::vector<long long> L, std::vector<long long> R, std::vector<long long> C){
    vector<vector<edge> > G(N);
    rep(i, M){
        G[L[i]].push_back(edge(R[i], C[i]));
    }
    for(ll i=1; i< N; i++){
        G[i].push_back(edge(i-1, 0));
    }
    vll dist(N, INF);
    dijkstra(G, dist, 0);


    cout << (dist[N-1]>=INF? -1: dist[N-1]) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> L(M);
    std::vector<long long> R(M);
    std::vector<long long> C(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
        scanf("%lld",&C[i]);
        L[i]--; R[i]--;
    }
    solve(N, M, std::move(L), std::move(R), std::move(C));
    return 0;
}


Measured memory_bytes: 11516
#include<stdio.h>
#define MAX 100000
int main(){
  int n,q,i,j,count=0;
  int S[MAX],T[MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
    for(j=0;j<n;j++){
      if(T[i]==S[j]){
	count+=1;
	break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        for(int i=0;i<3;i++){
            a[i] = Integer.parseInt(sc.next());
        }
        sort(a, 0, 2);
        int cost = (a[1]- a[0]);
        cost += (a[2] - a[1]);
        System.out.println(cost);
    }
    
    private static void sort(int[] d, int left, int right){
        if(left>=right){return;}
        int p = d[(left+right)/2];
        int l=left, r=right;
        int tmp;
        while(l<=r){
            while(d[l]<p){l++;}
            while(d[r]>p){r--;}
            if(l<=r){
                tmp=d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++; r--;
            }
        }
        sort(d, left, r);
        sort(d, l, right);
    }
}


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

using namespace std;
vector<long long> factors;
#define ll long long


#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

template<typename T>
int BS(vector<T> &mas, T val)
{
	int l, r;
	l = 0;
	r = mas.size() - 1;
	while (r - l > 1)
	{
		int mid = l + (r - l) / 2;
		if (mas[mid] < val)
		{
			l = mid;
		} else
			r = mid;
	}
	if (mas[r] == val)
		return r;
	if (mas[l] == val)
		return l;
	return -1;
}

template<typename T>
int UBS(vector<T> &mas, T val)
{
	int l, r;
	l = 0;
	r = mas.size() - 1;
	while (r - l > 1)
	{
		int mid = l + (r - l) / 2;
		if (mas[mid] < val)
		{
			l = mid;
		} else
			r = mid;
	}

	if (mas[l] >= val)
		return l;
	if (mas[r] >= val)
		return r;
	return -1;
}

ll mod(ll a, ll m)
{ return (a + (abs(a) / m) * m + m) % m; }


bool check(ll i, vector<bitset<64>> &a)
{
	ll one = 0;
	ll zero = 0;
	for (auto e : a)
	{
		if (e[i] == 1)
			one++;
		if (e[i] == 0)
			zero++;
	}
	if (one < zero)
		return true;
	return false;
}

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

	ll n;
	ll temp;
	cin >> n;

	bitset<64> bits;
	cin >> temp;
	bits = temp;

	vector<bitset<64>> a(n);
	for (auto i = 0; i < n; i++)
	{
		cin >> temp;
		a[i] = temp;
	}
	bool f = true;
	bitset<64> res(0);
	ll left = 63;
	for (ll i = left; i >= 0; i--)
	{
		if (f)
		{
			if (bits[i] == 0)
			{
				continue;
			}
			if (bits[i] == 1)
			{
				ll b = check(i, a);
				if (b == 0)
					f = false;
				res[i] = b;
			}
		} else
		{
			ll b = check(i, a);
			res[i] = b;
		}
	}


	ll ans = 0;
	for (auto e : a)
	{
		ans += res.to_ulong() ^ e.to_ulong();
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#define MOD 1000000007
using namespace std;

long pow(long a, int p)
{
	if (p == 0)
		return 1;

	if (p % 2 == 0)
	{
		long half = pow(a, p / 2);
		return half * half % MOD;
	}
	else
	{
		return a * pow(a, p - 1) % MOD;
	}
}

int comb(int a, int b)
{
	if (a - b < b) return comb(a, a - b);

	long ansMul = 1;
	long ansDiv = 1;
	for (int i = 0; i < b; i++)
	{
		ansMul *= (a - i);
		ansDiv *= (i + 1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}
	long ans = ansMul * pow(ansDiv, MOD - 2) % MOD;
	return ans; 
}

int main()
{
	int N, M;
	cin >> N >> M;
	long ans = 1;
	int Mres = M;
	for (int i = 2; i*i <= Mres; i++)
	{
		if (Mres % i == 0)
		{
			int cnt = 0;
			while(Mres % i == 0)
			{
				Mres /= i;
				cnt++;
			}
			ans *= comb(cnt + N - 1, N - 1);
			ans %= MOD;
		}
	}
	if (Mres != 1)
	{
		ans *= comb(N + 1 - 1, N - 1);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n=1,len;
    bool flag=false;
    for(int i=1;i<=11;i++){
        cout<<"? "<<n<<endl;
        char ret;
        cin>>ret;
        if(ret=='N'){
            flag=true;
            len=i-1;
            break;
        }
        n*=10;
    }
    if(!flag){
        int n=2;
        for(int i=1;i<=11;i++){
            cout<<"? "<<n<<endl;
            char ret;
            cin>>ret;
            if(ret=='Y'){
                len=i;
                break;
            }
            n*=10;
        }
    }
    int ok=1,ng=1;
    rep(_,len-1)ng*=10;
    ok=ng*10;
    ng--;
    while(ok-ng>1){
        int mid=(ok+ng)/2;
        cout<<"? "<<10*mid<<endl;
        char ret;
        cin>>ret;
        if(ret=='Y'){
            ok=mid;
        }
        else{
            ng=mid;
        }
    }
    cout<<"! "<<ok<<endl;
    return 0;
}

Measured memory_bytes: 3716