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

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

bool check(const vector<vector<int>>& e, const vector<int>& cycle) 
{
    bool ok = true;
    set<int> s;
    rep(i, cycle.size()) s.insert(cycle[i]);
    for (int i = 0; ok && i < cycle.size(); ++i) {
        int count = 0;
        for (int x: e[cycle[i]]) {
            if (s.find(x) != s.end()) {
                ++count;
                if (1 < count) {
                    break;
                }
            }
        }
        ok = (count == 1);
    }
    return ok;
}

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> e(N);

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        e[a].push_back(b);
    }

    rep(s, N) {
        vector<bool> visited(N);
        queue<vector<int>> q;
        q.push(vector<int>(1, s));
        visited[s] = true;
        int minLen = N+1;
        while (!q.empty()) {
            vector<int> curr = q.front(); 
            q.pop();
            for (int next: e[curr.back()]) {
                if (next == s) {
                    //! came back to the start point
                    if (check(e, curr)) {
                        //! found the answer
                        cout << curr.size() << endl;
                        rep(x, curr.size()) cout << (curr[x]+1) << endl;
                        return 0;
                    } else {
                        if (minLen < curr.size()) {
                            q = queue<vector<int>>(); //! go to the next s
                            break;
                        } else {
                            minLen = curr.size();
                        }
                    }
                } else if (!visited[next]) {
                    visited[next] = true;
                    vector<int> currPlus = curr;
                    currPlus.push_back(next);
                    q.push(currPlus);
                }
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


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

const int N = 1000;
int a[N];

int main() 
{
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; ++i) scanf("%d", a + i);
	sort(a, a + n);
	int sum = 0;
	for (int i = 0; i < k; ++i) sum += a[i];
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 1712
#include <iostream>

using namespace std;

int main(){
    int a, b, c, i;
    c = 0;
    cin >> a >> b;
    
    for( i = 0; i < 2; i++)
    {
        
        if (a > b) {
            c += a;
            a -= 1;
        }else{
            c += b;
            b-= 1;
        }
        
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long ll;

int main(){
    while(true){
        string f;
        int n;
        cin >> f >> n;
        if(f=="0" && n==0) break;
        vector<string> S;
        S.push_back(f);
        for(int i=1;;i++){
            stringstream ins;
            ins << setw(n) << setfill('0') << f;
            string os;
            ins >> os;
            string mis,mas;
            sort(os.begin(),os.end());
            mis = os;
            reverse(os.begin(),os.end());
            mas = os;

            stringstream miss,mass;
            miss << mis;
            mass << mas;

            ll mii,mai;
            miss >> mii;
            mass >> mai;

            ll fi = mai - mii;
            stringstream fs;
            fs << setw(n) << setfill('0') << fi;
            string newf;
            fs >> newf;
            if((find(S.begin(),S.end(),newf)) != S.end()){
                vector<string>::iterator it=find(S.begin(),S.end(),newf);
                int ind = it - S.begin();
                cout << ind << " " << fi << " " <<  i-ind <<  endl;
                break;
            }
            f = newf;
            S.push_back(newf);
        }
    }
}

Measured memory_bytes: 1280
#include<iostream>
#include<map>
#include<string>

using namespace std;

int main(){
int n;
cin>>n;
string tmp;
map<string, int> score;
for(int i=0; i<n; ++i){
cin>>tmp;
score[tmp]++;
}
cin>>n;
for(int i=0; i<n; ++i){
cin>>tmp;
score[tmp]--;
}
int s=0;
for(auto i:score) s=max(s, i.second);
cout<<s<<endl;
}

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

int main(){

    int a,b,c;

    cin >> a >> b >> c;

    if((a<=c && c<=b) || (b<=c && c<=a)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int odd,even,n,four,flag;
int main(){
//	freopen("ex.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		int tmp;
		scanf("%d",&tmp);
		if(tmp%4==0) four++;
		else if(tmp%2==0) even++;
		else odd++;
	}
	if(even&&four>=odd) flag=1;
	if(even==0&&four>=odd-1 ) flag=1;
	if(flag) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
#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()
#define _GLIBCXX_DEBUG
int main() {
    int n;
    long long w;
    long long inf=100000000000;
    cin>>n>>w;
    long long dp[n+10][100010];
    long long weight[n+1],value[n+1];
    rep(i,n){
        cin>>weight[i+1]>>value[i+1];
    }
    rep(i,n+1){
      rep(j,100010){
        dp[i][j]=inf;
    }
    }
    rep(i,n+1){
        dp[i][0]=0;
    }
    for (int i=1;i<n+1;i++){
        for (int j=1;j<1000*100+1;j++){
            if (j<value[i]){
              dp[i][j]=dp[i-1][j];
            }
            else{
              dp[i][j]=min(dp[i-1][j],dp[i-1][j-value[i]]+weight[i]);
            }
        }
    }
    long long ans=0;
    for (int j=1;j<1000*100+1;j++){
        if (dp[n][j]<=w){
            ans=j;
        }
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 81024
n = int(input())
t = [int(input())for _ in range(n)]
def gcd(x,y):
    if x%y == 0:return y
    return gcd(y%x,x)
def lcm(x,y):
    return (x*y)//gcd(x,y)

ans = t[0]
for i in range(n-1):
    ans = lcm(ans,t[i+1])
    
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{   
    char s[4], t[4];
    gets(s); gets(t);

    int res;
    for (int i=0; i < 3; i++){
        if (s[i] == t[i]) res++;
    }

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

    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using ll = long long;

int main()
{
    ll n, q;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    cin >> q;
    vector<ll> b(q), c(q);
    rep(i,q) cin >> b[i] >> c[i];
    
    ll sum = accumulate( a.begin(), a.end(), 0 );
    
    unordered_map< int, int > mp;
    ll ans = 0;
    rep(i,n) {
        ans += a[i];
        mp[a[i]] ++;
    }
    
    rep(i,q) {
        ans += c[i] * mp[b[i]];
        ans -= b[i] * mp[b[i]];
        mp[c[i]] += mp[b[i]];
        mp[b[i]] = 0;
        cout << ans << endl;
    }
    


    return 0;
}


Measured memory_bytes: 9372
S = input()
n = len(S)
a = [0]*(n+1)
for i in range(n):
    if S[i] == '<':
        a[i+1] = max(a[i+1], a[i] + 1)
for i in range(n)[::-1]:
    if S[i] == '>':
        a[i] = max(a[i], a[i+1] + 1)
# print(a)
print(sum(a))

Measured memory_bytes: 23336
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
a=A
b=B
c=C
d=D
e=E
a_=0
b_=0
c_=0
d_=0
e_=0
if A%10!=0:
  a=(((A//10)+1)*10)
  a_=10-A%10
if B%10!=0:
  b=(((B//10)+1)*10)
  b_=10-B%10
if C%10!=0:
  c=(((C//10)+1)*10)
  c_=10-C%10
if D%10!=0:
  d=(((D//10)+1)*10)
  d_=10-D%10
if E%10!=0:
  e=(((E//10)+1)*10)
  e_=10-E%10
print(a+b+c+d+e-max(a_,b_,c_,d_,e_))

Measured memory_bytes: 3064
//Author: Abitnav
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
int M=1e9+7;
int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M

signed main(){

ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//string s;
	int n,m,c=0,t=1,i,j,k,sum=0,ans,f=0,x,y;
	//cin>>t;
	while(t--){
		//vector<int> v;map<int,int> mp;set<int> st;
		cin>>m>>n;
		int a[n];rep(i,n) {
			cin>>a[i];
			sum+=a[i];	
		}
		if(sum>m) cout<<-1;
		else cout<<m-sum;

	}
	return 0;
}













Measured memory_bytes: 3684
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,m,q,k,i,j;
    // cin>>T;
    while(T--)
    {
        string st,a="",b="";
        cin>>st;
        FOR(i,0,st.length())
        {
            if(i%2==0){
                a += '0';
                b += '1';
            }
            else{
                a += '1';
                b += '0';
            }
        }
        ll ans=0,res=0;
        FOR(i,0,st.length())
        {
            ans += (st[i]!=a[i]);
            res += (st[i]!=b[i]);
        }
        cout<<min(ans,res)<<endl;
    }
}

Measured memory_bytes: 3932
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left

import sys
# sys.setrecursionlimit(1000000)
# list(map(int, input().split()))
mod = 10 ** 9 + 7

from collections import deque

# まず、Kの最小値を求める
#　頂点に繋がる辺の数 <= Kを全ての頂点で満たす
N, K = getNM()
R, S, P = getNM()
T = input()
# 手を出したか出してないか
flag = [0] * N
ans = 0
for i in range(N):
    if i - K >= 0 and T[i - K] == T[i] and flag[i - K]:
        continue
    if T[i] == 'r':
        ans+=P
    elif T[i] == 's':
        ans+=R
    else:
        ans+=S
    flag[i] = True
print(ans)

Measured memory_bytes: 43764
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cin >> s.at(i).at(j);
    }
  }
  for(int i=1; i<h-1; i++) {
    for(int j=1; j<w-1; j++) {
      if(s.at(i).at(j) == '#') {
	    if(s.at(i).at(j-1)!='#' && s.at(i).at(j+1)!='#'
           && s.at(i-1).at(j)!='#' && s.at(i+1).at(j)!= '#') {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  for(int j=1; j<w-1; j++) {
    if(s.at(0).at(j) == '#') {
      if(s.at(0).at(j-1)!='#' && s.at(0).at(j+1)!='#'
         && s.at(1).at(j)!='#') {
        cout << "No" << endl;
        return 0;
      }
    }
    if(s.at(h-1).at(j) == '#') {
      if(s.at(h-1).at(j-1)!='#' && s.at(h-1).at(j+1)!='#'
         && s.at(h-2).at(j)!='#') {
        cout << "No" << endl;
        return 0;
      }
    } 
  }
  for(int i=1; i<h-1; i++) {
    if(s.at(i).at(0) == '#') {
      if(s.at(i-1).at(0)!='#' && s.at(i+1).at(0)!='#'
         && s.at(i).at(1)!='#') {
        cout << "No" << endl;
        return 0;
      }
    }
    if(s.at(i).at(w-1) == '#') {
      if(s.at(i-1).at(w-1)!='#' && s.at(i+1).at(w-1)!='#'
         && s.at(i).at(w-2)!='#') {
        cout << "No" << endl;
        return 0;
      }
    } 
  }
  if(s.at(0).at(0)=='#' && s.at(1).at(0)!='#' && s.at(0).at(1)!='#') {
    cout<< "No" << endl;
    return 0;
  }
  if(s.at(0).at(w-1)=='#' && s.at(1).at(w-1)!='#' && s.at(0).at(w-2)!='#') {
    cout<< "No" << endl;
    return 0;
  }
  if(s.at(h-1).at(0)=='#' && s.at(h-2).at(0)!='#' && s.at(h-1).at(1)!='#') {
    cout<< "No" << endl;
    return 0;
  }
  if(s.at(h-1).at(w-1)=='#' && s.at(h-2).at(w-1)!='#' && s.at(h-1).at(w-2)!='#') {
    cout<< "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (int argc, char * argv[])
{
    char a;//文字列
    char ch ='a';
    char b;
    int count[26]={0};//分布
    //出現回数のを配列countに格納
    while ( scanf("%c", &a) != EOF){
        if(('A'<= a && a<='Z')){
            count[a-'A']++;

        }else if( ('a'<= a && a<='z')){
             count[a - 'a']++;
        }
    }
    //出現回数の出力
    for(int i=0; i<26;i++){
        printf("%c : %d\n",ch,count[i]);
        ch ++;
    }
    return 0;
}



Measured memory_bytes: 2100
#include <cstdio>

using namespace std;

int main() {
	int n, m, a, b;
	bool A[200000] = {}, B[200000] = {}, check = false;

	scanf("%d %d", &n, &m);
	for (int i = 0;i < m;i++) {
		scanf("%d %d", &a, &b);
		if (a == 1) {
			A[b - 1] = true;
		}
		else if(b == n){
			B[a - 1] = true;
		}
	}

	for (int i = 0;i < m;i++) {
		if (A[i] == true && B[i] == true) {
			check = true;
			break;
		}
	}

	if (check == true) {
		printf("POSSIBLE\n");
	}
	else {
		printf("IMPOSSIBLE\n");
	}

	return 0;
}

Measured memory_bytes: 512
N=int(input())
S=list(map(int,input().split()))
m=10**9+7
x=sum(S)%m
r=0
m=10**9+7
def div(a,b):
    return (a*pow(b,m-2,m))%m
for s in S:
    r=(r+s*(x-s))%m
print(div(r,2))

Measured memory_bytes: 31508
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < int(n); i++)
using namespace std;
 
int main() {
  string S;
  int sum = 0;
  cin >> S;
    if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3] ){
      cout <<  "Bad" << endl;
  }else{
      cout << "Good" << endl;
  }

  
  

}


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

int main(){
    double A,B,H,M;
    cin >> A >> B >> H >> M;
    double argh=0,argm=0;
    double pi = 3.14159265358979;
    argm=2*pi*M/60;
    //cout << argm << endl;
    argh=2*pi*H/12+pi/6*M/60;
    //cout << argh << endl;
    double arg = abs(argm-argh);
    double ans = A*A + B*B - 2*A*B*cos(arg);
    printf("%.11lf",sqrt(ans));
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define nl '\n'
void solve(){
}
int main() {
    ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n,testCase;
   // int n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
        for(int k=1;k<=n;k++){
          ans+=(__gcd(__gcd(i,j),k));
        }
      }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3600
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoldenCoins solver = new BGoldenCoins();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoldenCoins {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long ans = 0;
            ans += (n / 500) * 1000;
            n = n % 500;
            ans += (n / 5) * 5;
            out.println(ans);
        }

    }
}



Measured memory_bytes: 22228
#ABC175  C
x, k, d = map(int, input().split())
x = abs(x)
num = x // d
# print(num)
if num >= k:
  print(abs(x-k*d))
else:
  temp = x - num*d
  k -= num
  if k % 2 == 0:
    print(abs(temp))
  else:
    print(abs(temp-d))

Measured memory_bytes: 9188
n = gets.to_i

require 'prime'

pd = n.prime_division

cand = []

pd.each do |pr, c|
  c.times do |i|
    cand.push(pr ** (i+1))
  end
end

cand.sort!

count = 0

cand.each do |z|
  div, mod = n.divmod z
  if mod == 0
    n = div
    count += 1
  end
end

puts count



Measured memory_bytes: 14496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e3+5;
int main() {
    int n, m, a, b, ans = 0, flag = 1;
    cin >> n >> m;
    if(m == 0) {
    	if(n == 1) cout << 0 << endl;
    	else cout << pow(10.0, n - 1) << endl;
    	return 0;
	}
    map<int, int> mp;
	while(m--) {
		cin >> a >> b;
		if(mp[a] && mp[a] - 1 != b || (a + b == 1 && n != 1)) { flag = 0; cout << "-1" << endl; }
		else {
			if(!mp[a]) ans += (int)pow(10.0, (double)n - a) * b;
			mp[a] = b + 1;	
		}	
	}
	if(n != 1 && m != 1 && ans < pow(10.0, n - 1)) ans += pow(10.0, n - 1);
	if(flag) cout << ans << endl;
}


Measured memory_bytes: 256
# pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define all(x) (x).begin(),(x).end()
#define lla(x) (x).rbegin(),(x).rend()
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i <= n; i++)

const int INF = 1001001001;

vvi a(100100);

int n, m, d[100100][2];

int main(){
    cin >> n >> m;
    int b, c;
    rep(i, m){
        cin >> b >> c;
        b--;c--;
        a[b].push_back(c);
        a[c].push_back(b);
    }
    rep(i, n) d[i][0] = INF;
    queue<int> que;
    que.push(0);
    d[0][0] = 0;
    while(!que.empty()){
        int x = que.front(); que.pop();
        for(int i : a[x]){
            if(d[i][0] == INF){
                que.push(i);
                d[i][0] = d[x][0] + 1;
                d[i][1] = x;
            }
        }
    }
    cout << "Yes" << endl;
    for(int i=1; i<n; i++){
        cout << d[i][1]+1 << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
	int k, n;
	cin >> k >> n;
	int longestInterval = 0;
	int first;
	cin >> first;
	int x;
	int pre = first;
	for(int i = 1; i < n; i++) {
		cin >> x;
		longestInterval = max(longestInterval, x-pre);
		pre = x;
	}
	longestInterval = max(longestInterval, k-x+first);
	cout << k - longestInterval << "\n";
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
	char str[7];
	std::cin >> str;
	bool likeCoffee = false;
	
	if(str[2]==str[3])
	{
		if(str[4]==str[5])
		{
			likeCoffee = true;
		}
	}

	std::cout << (likeCoffee ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int gcd(int a, int b){
	if(b == 0){
		return a;
	}else{
		return gcd(b, a%b);
	}
}

int main(){
	int K, l, m;
	scanf("%d", &K);

	int sum_n = 0;
	for(int i = 1; i <= K; i++){
		for(int j = 1; j<=K; j++){
			if(i > j){
				l = gcd(i, j);
			}else{
				l = gcd(j, i);
			}
			for(int k = 1; k <= K; k++){
				if(k > l){
					m = gcd(k, l);
				}else{
					m = gcd(l, k);
				}
				sum_n += m;
			}
		}

	}
	printf("%d", sum_n);
	return 0;
}

Measured memory_bytes: 1736
import java.util.Scanner;

public class Main {

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

		String[] a = { "A", "C", "G", "T" };

		int cnt = 0;
		int maxCnt = 0;
		boolean flg = false;
		boolean bflg = false;
		for (int i = 0; i < S.length(); i++) {
			if(!flg) {
				cnt = 0;
			}
			flg = false;
			for (int j = 0; j < a.length; j++) {
				if (String.valueOf(S.charAt(i)).equals(a[j])) {
					cnt++;
					maxCnt = Math.max(cnt, maxCnt);
					flg = true;
					break;
				}
			}
			
		}
		System.out.println(maxCnt);

	}

}


Measured memory_bytes: 23764
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

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

    vector<vector<long long>> in(n, vector<long long>(0)), out(n, vector<long long>(0));
    vector<long long> c(m);
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r >> c[i];
        in[l - 1].push_back(i);
        out[r - 1].push_back(i);
    }

    vector<long long> dist(n, 1LL << 48), dist_c(m, 1LL << 48);
    dist[0] = 0;

    multiset<long long> dist_set;

    for (int i = 0; i < n; i++) {
        if (dist_set.size() > 0) {
            dist[i] = min(dist[i], *dist_set.begin());
        }

        for (int j = 0; j < static_cast<int>(in[i].size()); j++) {
            dist_c[in[i][j]] = dist[i] + c[in[i][j]];
            dist_set.insert(dist_c[in[i][j]]);
        }

        for (int j = 0; j < static_cast<int>(out[i].size()); j++) {
            dist_set.erase(dist_set.find(dist_c[out[i][j]]));
        }
    }

    if (dist[n - 1] < (1LL << 48)) {
        cout << dist[n - 1] << endl;
    } else {
        cout << "-1" << endl;
    }
}


Measured memory_bytes: 13312
//*********************************************************************************************************************************
//*																																**
//*		SSSSSSSSSSSS											MMMM			MMMM	HHHH		HHHH	DDDDDDDDDDDD		**
//*		SSSSSSSSSSSS	CSAA Numbered							MMMMM		   MMMMM	HHHH		HHHH	DDDDDDDDDDDDD		**
//*		SSSS				A PROGRAM BY:						MMMMMM		  MMMMMM	HHHH		HHHH	DDDD	 DDDDD		**
//*		SSSS													MMMMMMM		 MMMMMMM	HHHH		HHHH	DDDD	   DDDD		**
//*		SSSSSSSSSSSS	AAAAAAAAAAAA	MMMMMMMMMMMMMMMMMMMM	MMMMMMMM	MMMMMMMM	HHHHHHHHHHHHHHHH	DDDD	    DDD		**
//*		SSSSSSSSSSSS	AAAAAAAAAAAA	MMMMMMMMMMMMMMMMMMMM	MMMM MMMM  MMMM MMMM	HHHHHHHHHHHHHHHH	DDDD	    DDD		**
//*				SSSS	AAAA	AAAA	MMMM	MMMM	MMMM	MMMM  MMMMMMMM	MMMM	HHHH		HHHH	DDDD	   DDDD		**
//*				SSSS	AAAA	AAAA	MMMM	MMMM	MMMM	MMMM   MMMMMM	MMMM	HHHH		HHHH	DDDD	  DDDD		**
//*		SSSSSSSSSSSS	AAAAAAAAAAAAA	MMMM	MMMM	MMMM	MMMM    MMMM	MMMM	HHHH		HHHH	DDDDDDDDDDDDD		**
//*		SSSSSSSSSSSS	AAAAAAAAAAAAAA	MMMM	MMMM	MMMM	MMMM			MMMM	HHHH		HHHH	DDDDDDDDDDDD		**
//*																																**
//********************************************************************************************************************************
//||											||
//||	CSAA AA###B ddmmYYYY					||
//||	?? SMP(SAM-MHD-PGM) @ AEH_COT96			||
//||	Program Name:							||
//||			AA###B_<xxxxNAMExxxx>			||
//||											||
/////******************************************\\

#include <iostream>
#include <vector>

using namespace std;
const int maxn = 1e4+3;
const int oo   = 3e7+3;

typedef pair <int, int> pii;
vector <pii> G[maxn];
vector <pii> ans;
bool used[maxn]; // Already in MST
long long pim [maxn]; // Partner in MST
long long mdti[maxn]; // Min_dis to MST :: Minimal Distance to Include
long long n, m;
long long ansvalue;

bool MST(){
	
	fill_n(mdti, n, oo); 
	fill_n(pim, n, -1);  
	fill_n(used, n, false); 
	
	mdti[0] = 0;
	
	for (int i = 0; i < n; i++) {
		
		int v = -1;
		
		for (int j=0; j<n; j++)
			if ( !used[j] && (v == -1 || mdti[j] < mdti[v]))
				v = j;
 
//		if (mdti[v] == oo) 
//			return false;
 
		used[v] = true;
		
		if (pim[v] != -1){
			ans.push_back ( make_pair( pim[v], v ) );
			ansvalue += mdti[v];
		} 
 
		for (int j = 0; j < G[v].size(); j++) 
			if ( G[v][j].second < mdti[ G[v][j].first ] ) {
				mdti[ G[v][j].first ] = G[v][j].second;
				pim [ G[v][j].first ] = v;
			}
	}
	return true;
}

int main() {
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a, b, w;
		cin >> a >> b >> w;
		G [a].push_back( make_pair( b, w) );
		G [b].push_back( make_pair( a, w) ); 
	}
	
//	if (MST())
//		for (pii e : ans)
//			cout << e.first << " " << e.second << endl;
//	else cout << -1;
	if (MST())
		cout << ansvalue << endl;
	
}
/**/

// ?? SMP(SAM-MHD-PGM) @ AEH_COT96
//   SamMHD (Saman Mahdanian)

Measured memory_bytes: 6316
#include<iostream>
#include<vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);

	for(int i=0;i<n;i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}

	vector<vector<int>> dp(n,vector<int>(3,0));

	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];

	for(int i=1;i<n;i++)
	{
		dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
	}

	cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
}


Measured memory_bytes: 6912
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(s: String);

    let mut v = s.into_bytes();
    v.sort();

    if v[0] == v[1] && v[2] == v[3] && v[0] != v[2] {
        println!("{}", "Yes");
        return;
    }

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


Measured memory_bytes: 2144
# C - Boxes and Candies

N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
for idx in range(1,N):
    if a[idx-1] + a[idx] > x:
        n_eat = a[idx-1] + a[idx] - x
        ans += n_eat
        a[idx] = max(0, a[idx] - n_eat)        
        
print(ans)

Measured memory_bytes: 14052
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {

	ll a, b;
	cin >> a >> b;
	ll ans = 0;
	fori(i, a, b + 1) {
		string s = to_string(i), t = s = to_string(i);
		reverse(all(t));
		if (s == t) ++ans;
	}
	cout << ans << endl;
}

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

int main()
{
    int n; cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s.at(i);

    int ac=0,wa=0,tle=0,re=0;

    for(string x: s) {
        if(x == "AC") ac++;
        else if(x == "WA") wa++;
        else if(x == "TLE") tle++;
        else re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

Measured memory_bytes: 6420
#include<stdio.h>
int main()
{
    double x;

    unsigned long long n = 100,t = 0;
    scanf("%lf",&x);
    while(n<x){
        n = (unsigned long long)(n*1.01);
        t++;
    }
    printf("%I64u\n",t);
    return 0;
}


Measured memory_bytes: 1748
#!/usr/bin/env python3
import sys
import bisect

inf = float('inf')

def solve(N: int, K: int, V: "List[int]"):
    res = -inf
    for k in range(min(K+1, N+1)):
        for left in range(k+1):
            right = k - left
            L = V[:left] + V[N-right:]
            L.sort()
            i = min(bisect.bisect(L, 0), K - k)
            res = max(res, sum(L[i:]))
    print(res)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, V)

if __name__ == '__main__':
    main()


Measured memory_bytes: 41836
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M = LI()
    p = LI_()
    G = [[] for _ in range(N)]
    for _ in range(M):
        x, y = LI_()
        G[x].append(y)
        G[y].append(x)
    # print(G)

    visited = [False] * N
    def dfs(c, tmp):
        visited[c] = True
        tmp.append(c)
        for n in G[c]:
            if not visited[n]:
                dfs(n, tmp)

    # 連結成分内はswapで自由な位置に移動可能
    c = []
    for i in range(N):
        if not visited[i]:
            tmp = []
            dfs(i, tmp)
            c.append(tmp)
    # print(c)

    ans = sum([len({p[j] for j in i} & set(i)) for i in c])
    print(ans)



if __name__ == '__main__':
    resolve()


Measured memory_bytes: 105936
#include <stdio.h>
int main()
{
    long long int X,i,sum=0;
    scanf("%lld",&X);
    for (i=1; i<X+1; i++) {
        sum+=i;
        if(sum>=X){
            printf("%lld\n",i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=105;
bool exist[maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=k;i++)
    {
        int d;
        cin>>d;
        for(int j=1;j<=d;j++)
        {
            int a;
            cin>>a;
            exist[a]=true;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        ans+=(!exist[i]);
    cout<<ans<<'\n';
    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    for (int i = 0; i <= 50000; i++) {
        int m = (int)(floor((double)(1.08)*i));
        if (m == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(\n";
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,n,s,r,i;
  while(scanf("%d %d %d",&a,&b,&n)!=EOF){
    r=a%b;
    for(i=s=0;i<n;i++){
      r*=10;
      s+=r/b;
      r%=b;
    }
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 596
def solve(S):
        index = 0
        while index < len(S):
            if S[index] != "d" and S[index] != "e":
                print("NO")
                return
            if S[index] == "d":
                if index + 6 < len(S) and S[index:index+7] == "dreamer" and (index + 7 == len(S) or (S[index + 7] == "d" or S[index + 7] == "e")):
                    index += 7
                elif index + 4 < len(S) and S[index:index + 5] == "dream":
                    index += 5
                else:
                    print("NO")
                    return
            elif S[index] == "e":
                if index + 5 < len(S) and S[index:index + 6] == "eraser":
                    index += 6
                elif index + 4 < len(S) and S[index:index + 5] == "erase":
                    index += 5
                else:
                    print("NO")
                    return
        print("YES")



S = input()
solve(S)

Measured memory_bytes: 3188
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    private static final int[] dy = {0, 1, 0, -1};
    private static final int[] dx = {1, 0, -1, 0};
    private static final int INF = 10000;

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

        int h = sc.nextInt();
        int w = sc.nextInt();
        boolean[][] field = new boolean[h][w];
        int black = 0;
        for(int i = 0; i < h; i++) {
            String str = sc.next();
            for(int j = 0; j < w; j++) {
                field[i][j] = str.charAt(j) == '.';
                if(!field[i][j]) black++;
            }
        }

        int[][] dist = new int[h][w];
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                dist[i][j] = INF;
            }
        }
        dist[0][0] = 0;
        Deque<Point> que = new ArrayDeque<>();
        que.add(new Point(0, 0));
        while(!que.isEmpty()) {
            Point p = que.poll();
            int x = p.x;
            int y = p.y;
            if(x == h - 1 && y == w - 1) break;

            for(int i = 0; i < 4; i++) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if(0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny] && dist[nx][ny] == INF) {
                    dist[nx][ny] = dist[x][y] + 1;
                    que.add(new Point(nx, ny));
                }
            }
        }

        if(dist[h - 1][w - 1] == INF) System.out.println(-1);
        else System.out.println(h * w - black - dist[h - 1][w - 1] - 1);

        sc.close();
    }
}

Measured memory_bytes: 23124
X, Y, A, B, C = map(int, input().split()) 
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
ALL = P[0:X]+Q[0:Y]+R
ALL.sort(reverse=True)
print(sum(ALL[0:X+Y]))

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

int main() {
int n;
cin >> n;
int x[n];
for(int i=0;i<n;i++){
    cin >>x[i];
}
double avg;
avg=0;
for(int i=0;i<n;i++){
    avg+=x[i];
}
avg/=n;
avg=round(avg);
double ans;
ans=0;
for(int i=0;i<n;i++){
    ans+=pow(x[i]-avg,2);
}
cout << ceil(ans);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for ( int i = 0; i < (n); ++i )
using namespace std;
using ll = long long int;
const long long int INF = 1001001001001001LL;
const int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;


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

    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(3));
    rep(i, n) rep(j, 3) cin >> v[i][j];

    vector<vector<int>> dp(n+1, vector<int>(3, 0));
    
    rep(i, n) {
        rep(j, 3) {
            rep(k, 3) {
                if( j != k ) dp[i+1][j] = max( dp[i+1][j], dp[i][k] + v[i][j] );
            }
        }
    }

    int ans = 0;
    rep(i, 3)  ans = max( ans, dp[n][i] );

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
typedef long long giant;
template<typename T> inline T& Min(T &x,const T &y) {return y<x?(x=y):x;}
template<typename T> inline T& Max(T &x,const T &y) {return x<y?(x=y):x;}
inline int read() {
	int x=0,f=1;
	char c=getchar();
	for (;!isdigit(c);c=getchar()) if (c=='-') f=-1;
	for (;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int maxn=3e3+10;
int n,L,T[maxn];
double ansx,ansy,tl;
int calc(int l,int r) {
	if (l<=r) return r-l+1;
	return n-l+1+r;
}
int main() {
	n=read(),L=read(),tl=acos(-1.0)/L;
	for (int i=1;i<=n;++i) T[i]=read();
	for (int i=1;i<=n;++i) for (int j=i+1;j<=n;++j) {
		double c=(T[i]+T[j])*tl;
		int cnt=calc(j,i)-calc(i,j);
		ansx+=cos(c)*cnt;
		ansy+=sin(c)*cnt;
	}
	ansx=ansx/n/(n-1)/(n-2)*6;
	ansy=ansy/n/(n-1)/(n-2)*6;
	printf("%.15lf %.15lf\n",ansx,ansy);
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;

int func(int depth, int idx, int n, string str){
	if(depth >= 3) return 1;
	int sum = 0;
	bool used[10];
	fill(used, used+10, false);
	rep2(i, idx, n){
		if(used[str[i]-'0']) continue;
		sum += func(depth+1, i+1, n, str);
		used[str[i]-'0'] = true;
	}
	return sum;
}

int main(void){
	int n; cin >> n;
	string str; cin >> str;
	cout << func(0, 0, n, str) << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
char matrix[25][25];
int H, W;
bool fix[25][25];
void maxx(int x, int y, int &res){
	queue < pair < pair < int, int > , int > > q;
	q.push({{x, y}, 0});
	while(q.size()){
		int x = q.front().first.first;
		int y = q.front().first.second;
		int z = q.front().second;
		q.pop();
		if(x < 0 || x >= H || y < 0 || y >= W || matrix[x][y] != '.' || fix[x][y])continue;
		fix[x][y] = true;
		res = max(res, z);
		q.push({{x, y + 1}, z + 1});
		q.push({{x, y - 1}, z + 1});
		q.push({{x - 1, y}, z + 1});
		q.push({{x + 1, y}, z + 1});
	}
}
int main(){
	int ans = 0;
	cin >> H >> W;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> matrix[i][j];
		}
	} 
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			for(int x = 0; x < H; x++)
				for(int y = 0; y < W; y++)
					fix[x][y] = 0;
			maxx(i, j, ans);
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	int n = s.length(), i, j, k;
	vector<int> a(n, 1), ans(n, 0);
	for (i = 0; i < n - 1; i++) {
		if ((s[i] == 'R') && (s[i + 1] == 'R')) {
			a[i + 1] += a[i];
			a[i] = 0;
		}
	}
	for (i = n - 1; i > 0; i--) {
		if ((s[i] == 'L') && (s[i - 1] == 'L')) {
			a[i - 1] += a[i];
			a[i] = 0;
		}
	}

	for (i = 0; i < n; i++) {
		if (a[i] > 0) {
			if (s[i] == 'R') {
				ans[i] += (a[i] + 1) / 2;
				ans[i + 1] += a[i] / 2;
			}
			else {
				ans[i] += (a[i] + 1) / 2;
				ans[i - 1] += a[i] / 2;
			}
		}
	}

	for (auto p : ans) cout << p << " ";
	cout << "\n";

	return 0;
}


Measured memory_bytes: 1472
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s;
    cin >> s;
    ll lcnt = 0;
    for(auto c : s) {
        if (c == 'x') lcnt++;
    }
    if (lcnt <= 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

maxi = max(a,b,c,d,e)
mini = min(a,b,c,d,e)
diff = maxi - mini
if diff <= k:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3064
import math


def main():
    p = [0, 0]
    x = math.radians(90)
    while True:
        d, angle = map(int, input().split(","))
        if d == 0 and angle == 0:
            break
        p[0] += math.cos(x) * d
        p[1] += math.sin(x) * d
        x -= math.radians(angle)
    for i in (0,1):
        p[i] = int(p[i])
    print(*p, sep="\n")


if __name__ == "__main__":
    main()

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

li n;
li a[100100];

li res[100100];

int main() {
    cin >> n;
    rin{
        cin >> a[i];
    }
    li sum = 0;
    rin{
        sum += a[i] * (i % 2 == 0 ? 1 : -1);
    }
    res[0] = sum / 2;
    repp(i, 1, n) {
        res[i] = a[i - 1] - res[i - 1];
    }

    rin{
        cout << res[i] * 2 << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P; 
#define INF 100000000
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
    int n;
   string s,t,ans;
   cin>>n>>s>>t;
    REP(i,n){
        ans=ans+s[i]+t[i];
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 256
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

class UnionFind():
	"""docstring for UnionFind"""
	def __init__(self, n):
		self.parents = [-1]*n

	def find(self,x):
		if self.parents[x] < 0: #自分が親である時
			return x
		else: #自分が子供である時
			self.parents[x]=self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		# 各要素の親要素を返す
		x=self.find(x)
		y=self.find(y)

		if x==y:
			return
		if self.parents[x] > self.parents[y]:
			x,y=y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x
		# print(self.parents)

		
n,m=input2()
S=[input_array() for _ in range(m)]

uf=UnionFind(n) #uf.parents==[-1]*n

for s in S:
	uf.union(s[0]-1,s[1]-1)
ans=min(uf.parents)

print(-ans)

Measured memory_bytes: 50080
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0
for i in range(b + 1):
    for j in range(c + 1):
        a500 = (x//50 - 2 * i - j) /10
        if 0 <= a500 <=a and a500.is_integer():
            cnt +=1
print(cnt)

Measured memory_bytes: 3060
import heapq

N, M = map(int, input().split())
XM = list(map(int, input().split()))

if N >= M:
    print(0)
    exit()

XM.sort()
diffs = [XM[i + 1] - XM[i] for i in range(M - 1)]
nmin_diffs = heapq.nlargest(N - 1, diffs)
nmin_diffs_ind = [diffs.index(nmin_diffs[i]) for i in range(N - 1)]
nmin_diffs_ind.sort()
nmin_diffs_ind.append(len(XM) - 1)

dist = XM[nmin_diffs_ind[0]] - XM[0]
for i in range(N - 1):
    dist += XM[nmin_diffs_ind[i + 1]] - XM[nmin_diffs_ind[i] + 1]

print(dist)

Measured memory_bytes: 16720
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    int S[A+2];
    int T[B+2];
    S[0] = -INF;
    T[0] = -INF;
    S[A+1] = INF;
    T[B+1] = INF;
    for (int i = 1; i < A+1; i++) cin >> S[i];
    for (int i = 1; i < B+1; i++) cin >> T[i];

    for (int i = 0; i < Q; i++) {
        int x;
        cin >> x;

        int sr = *lower_bound(S, S + A+2, x);
        int tr = *lower_bound(T, T + B+2, x);
        int sl = *(upper_bound(S, S + A+2, x) - 1);
        int tl = *(upper_bound(T, T + B+2, x) - 1);

        sr = abs(sr - x);
        tr = abs(tr - x);
        sl = abs(sl - x);
        tl = abs(tl - x);

        int ret = INF;
        ret = min(ret, max(sr, tr));
        ret = min(ret, min(2*sr+tl, 2*tr + sl));
        ret = min(ret, min(2*tl+sr, 2*sl + tr));
        ret = min(ret, max(sl, tl));

        cout << ret << endl;
    }

    return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;

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

int main(){
  ll a,b; cin>>a>>b;
  ll c=gcd(a,b);
  c=a/c*b/c*c;
  cout<<c<<endl;

  return 0;
}


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

int main() {
	stack<int> order;
	stack< pair<int,int> > area;//first...area second...x1
	
	int tmpOrder=1;
	int totalArea=0;
	int tmpArea=0;
	char c;
	while(cin>>c){
		int x1=0;
		int x2=0;
		
		switch(c){
			case '/':
				if(order.empty()){
					continue;
				}
				x1=order.top();order.pop();
				x2=tmpOrder;
				tmpArea=x2-x1;
					while(!area.empty()){
						if(area.top().second>x1){
							tmpArea += area.top().first;
							area.pop();
						}else{
							break;
						}
					}
				area.push(make_pair(tmpArea,x1));
				break;
			case '_':
				break;
			default:
				order.push(tmpOrder);
				break;
		}
		tmpOrder++;
	}
	
	int size1= area.size();
	int size2= area.size();
	stack<int> ans;
	
	while(size1--){
		totalArea += area.top().first;
		ans.push(area.top().first);
		area.pop();
	}
	cout<<totalArea<<endl;
	cout<<size2;
	size2 = ans.size();
	
	while(size2--){
		cout<<" "<<ans.top();
		ans.pop();
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 1284