akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cctype>
#include<queue>
#include<cstdio>
#include<cmath>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<map>
#include<utility>
#include<iomanip>
#include<set>
#include<stack>
//#include<Windows.h>
using namespace std;
typedef long long ll;typedef pair<int,int> pii;
typedef pair<ll,ll> pll;typedef vector<string> vss;
typedef vector<int> vii;typedef vector<pii> vpi;
typedef vector<ll> vll;typedef vector<pll> vpl;
typedef unsigned long long ul;typedef queue<int> qii;typedef queue<pii> qpi;
ll n,a[3][100005],ans;
int main()
{
	cin>>n;
	for(int i=0;i<3;i++){
		for(int j=0;j<n;j++)
			cin>>a[i][j];
		sort(a[i],a[i]+n);
	}
	for(ll i=0,j=0,k=0;j<n;j++){
		while(i<n&&a[0][i]<a[1][j]) i++;
		while(k<n&&a[2][k]<=a[1][j]) k++;
		ans+=i*(n-k);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 2560
/* C Koch Curve */

#include<stdio.h>
#include<math.h>

#define PI 3.1415926585

typedef struct XY{
  double x;
  double y;
}Point;

Point KochCurve(Point,Point,int);

int main(){
  Point lp={0,0},rp={100,0};
  int n;

  scanf("%d",&n);
  KochCurve(lp,rp,n);
  printf("%f %f\n",rp.x,rp.y);

  return 0;
}
/*(0,0),(100,0)*/
Point KochCurve(Point lp, Point rp, int n){
  Point left, mid, right, d;
  if(n==0){
    printf("%f %f\n",lp.x,lp.y);

  }else{
  d.x=rp.x-lp.x;
  d.y=rp.y-lp.y;

  left.x=lp.x+d.x/3;
  left.y=lp.y+d.y/3;

  right.x=lp.x+d.x*2/3;
  right.y=lp.y+d.y*2/3;

  mid.x=left.x+(d.x/3)*cos(PI/3)-(d.y/3)*sin(PI/3);
  mid.y=left.y+(d.x/3)*sin(PI/3)+(d.y/3)*cos(PI/3);


  KochCurve(lp,left,n-1);
  KochCurve(left,mid,n-1);
  KochCurve(mid,right,n-1);
  KochCurve(right,rp,n-1);
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
signed main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
 
    int n = 0;
    while(true) {
        sort(v.begin(), v.end());
        if(v[0]==v[1] && v[0]==v[2]) {
            cout << n << endl;
            return 0;
        }
        if(v[0]+2 <= v[2]) {
            n++;
            v[0] += 2;
            continue;
        } else {
            v[0]++;
            v[1]++;
            n++;
        }
    }
    return 0;
}

Measured memory_bytes: 256
use proconio::input;

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
pub fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}


fn main() {
    input!{
        n: usize,
        x: usize,
        t: usize,
    }
    if n % x == 0 {
        println!("{}", (n / x) * t);
    }
    else {
        println!("{}", (n / x + 1) * t);
    }
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define ll long long
using namespace std;
/*int max(int arr[]){
	for(int i=0;i<k;i++){
		
	}
}*/
int main() {
	ll n,k;
	cin>>n;
	int a[n][3];
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<n;i++){
		a[i][0]+=max(a[i-1][1],a[i-1][2]);
		a[i][1]+=max(a[i-1][0],a[i-1][2]);
		a[i][2]+=max(a[i-1][0],a[i-1][1]);
	}
	cout<<max(a[n-1][0],max(a[n-1][1],a[n-1][2]));
	return 0;
}

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

signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  rep(i, n) cin >> p[i], p[i]--;
  rep(i, n) cin >> c[i];
  ll ans = -1001001001;
  rep (i, n) {
    int now = i;
    vector<ll> vs;
    ll res = 0;
    do {
      now = p[now];
      res += c[now];
      vs.push_back(res);
    } while (now != i);
    int sz = vs.size();
    rep (j, min(sz, k)) ans = max(ans, vs[j] + ((k - j - 1) / sz) * max(0ll, res));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;

using P = pair<int, int>;

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n, -1) {}
    int root(int x) {
        if(d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {return (root(x) == root(y));}
    int size(int x) {return -d[root(x)];}
};

vector<int> to[100005];
int frie[100005];
signed main(){
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i, m) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        frie[a]++;
        frie[b]++;
        uf.unite(a, b);
    }

    rep(i, k) {
        int c, d;
        cin >> c >> d;
        --c; --d;

        to[c].push_back(d);
        to[d].push_back(c);
    }

    rep(i, n) {
        int ans = uf.size(i)-1-frie[i];
        int aaa = ans;
        for(int u: to[i]) {
            if(uf.same(i, u)) --ans;
        }
        cout << ans<<" " << flush;
    }
    cout << "" << endl;
    return 0;
}



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

int main()
{
	int a[4], i, j, x, y, b[3], ans;
	string s;
	memset(b, 0, sizeof(b));

	cin >> s;

	for(i=0; i<4; i+=1)
	{
		string s1;
		s1+=s[i];
		a[i]=stoi(s1);
	}

	for(i=0; i<8; i+=1)
	{
		y=0;
		x=i;
		while(x>0)
		{
			b[y]=x%2;
			y+=1;
			x/=2;
		}

		ans=a[0];
		for(j=0; j<3; j+=1)
		{
			if(b[j]==1)
				ans+=a[j+1];
			else
				ans-=a[j+1];
		}
		if(ans==7)
			break;
	}

	for(i=0; i<=3; i+=1)
	{
		cout << a[i];
		if(i<3)
		{
			if(b[i]==1)
				cout << '+';
			else
				cout << '-';
		}
		else
			cout << "=7" << endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1000000007;

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

    ll s = 0;
    vector<ll> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
        if(a[i] > 0){
            s += a[i];
        }
    }

    ll k_sum = 0, k_posi_sum = 0;
    for(int k=0;k<K;k++){
        if(a[k] > 0){
            k_posi_sum += a[k];
        }
        k_sum += a[k];
    }

    ll ans = 0;
    for(int i=0;i<N;i++){
        // the final operation is white
        ans = max(ans, s - k_posi_sum);
        // the final operation is black
        ans = max(ans, s - k_posi_sum + k_sum);
        if(i + K >= N) break;
        k_sum += a[i + K] - a[i];
        if(a[i] > 0) k_posi_sum -= a[i];
        if(a[i+K] > 0) k_posi_sum += a[i + K];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;

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

	int a, b;

	int p[101]{};
	p[0] = 0;
	p[1] = 0;
	p[2] = 1;
	p[3] = 3;
	for (int i = 4; i <= 100; i++)
	{
		p[i] = p[i - 1] + i-1;
	}

	cin >> a >> b;

	cout << p[a] + p[b];

	return 0;
}

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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let c: i32 = read();
    let d: i32 = read();
    let start = std::cmp::max(a, c);
    let end = std::cmp::min(b, d);
    let ans = std::cmp::max(0, end - start);

    println!("{}", ans)
}



Measured memory_bytes: 4352
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
const long long int mod=1e9+7;
typedef long long ll;

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

bool issq(int n){
    int i=1;
    while(i*i<=n){
        if(i*i==n){
            return true;
        }
        i++;
    }
    return false;
}
int main(){
    int N;
    cin >>N;
    int A[N];
    int max=-1,second=-1;
    FOR(i,N){
        cin >>A[i];
        if(max<A[i]){
            second=max;
            max=A[i];
        }else if(second<A[i]){
            second=A[i];
        }
    }
    FOR(i,N){
        if(A[i]==max){
            cout<<second<<endl;
        }else{
            cout<<max<<endl;
        }
    }
    //cout <<ans<<endl;
    return 0;
}




Measured memory_bytes: 2432
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> inline void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> inline void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int sum1 = h1*60+m1;
    int sum2 = h2*60+m2;

    print(sum2-sum1-k);
    return 0;
}


Measured memory_bytes: 3672
#include <cstdio>
#include <algorithm>

using namespace std;

#define rep1(i,x) for(int i=1;i<=(x);++i)

int d[100001];

int main()
{
	int N, M; scanf("%d %d", &N, &M);

	rep1(i, N - 1) {
		int s; scanf("%d", &s);
		d[i] = s + d[i - 1];
	}

	int ans = 0;

	int now = 0;

	rep1(i, M) {
		int a; scanf("%d", &a);
		int nxt = now + a;
		ans += d[max(now, nxt)] - d[min(now, nxt)];
		ans %= 100000;
		now = nxt;
	}

	printf("%d\n", ans);
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

int main() {
    int n;
    cin >> n;
    vector<int> c(n - 1), s(n - 1), f(n - 1);
    for (int i = 0; i < n - 1; i++) {
        cin >> c[i] >> s[i] >> f[i];
    }
    for (int i = 0; i < n - 1; i++) {
        int now = 0;
        for (int j = i; j < n - 1; j++) {
            if (now < s[j]) {
                now = s[j] + c[j];
            } else if (now % f[j]) {
                now += f[j] - now % f[j] + c[j];
            } else {
                now += c[j];
            }
        }
        cout << now << endl;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3576
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 2e9;



int main() {
	string s; cin >> s;
	if ((s[0] == s[s.size() - 1]) ^ (s.size() % 2)) printf("First");
	else printf("Second");
	return 0;
}


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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {

    let mut ans = 0;
    let n:usize = read();
    let s: Vec<char> = read::<String>().chars().collect();
    let mut now_c:char = '9';
    
    for c in s.iter() {
        if *c != now_c {
            now_c = *c;
            ans += 1;
        }
    }

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

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }
typedef pair<int,int> P;

int main(){
  ll x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  ll p[a],q[b],r[c];
  rep(i,a)cin >> p[i];
  rep(i,b)cin >> q[i];
  rep(i,c)cin >> r[i];
  sort(p,p+a,greater<>());
  sort(q,q+b,greater<>());
  //sort(r,r+c,greater<>());
  //rep(i,a)cout << p[i] << endl;
  priority_queue<ll, vector<ll>, less<ll>> bk;
  rep(i,x)bk.push(p[i]);
  rep(i,y)bk.push(q[i]);
  rep(i,c)bk.push(r[i]);
  ll ans=0;
  rep(i,x+y){
    ans += bk.top();
    bk.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 8688
/**
 * Created by karayuu on 2018/12/08
 */
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.toInt()

    if (n % 500 <= a) {
        //500は無限に払えるので、端数が払えるかどうか確認する
        println("Yes")
    } else {
        println("No")
    }
}


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

int main() {
  int N;
  cin >> N;
  int nazo=-1;
  vector<int> button(N+1);
  vector <int> a(N+1);
  button.at(1) = 1;
  for (int i=1; i<=N; i++)
  {
    cin >> a.at(i);
  }
  for (int i=1; i<=N-1; i++)
  {
    button.at(i+1) = a.at(button.at(i));
  }
  
  for (int i=1; i<=N; i++)
  {
    if (button.at(i) == 2)
    {
      nazo = i-1;
      break;
    }
  }
  cout << nazo << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int A, B; cin >> A >> B;
    if (A <= 9 and B <= 9) cout << A * B << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll solve(ll a[], ll b[], ll c[],ll n){
    ll dp[n][3];
    memset(dp,0,sizeof(dp));
    dp[0][0]=a[0],dp[0][1]=b[0],dp[0][2]=c[0];
    for(ll 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][1],dp[i-1][0]);
    }
    return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
int main(){
    ll n;
    cin>>n;
    ll a[n],b[n],c[n],i;
    for(i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    cout<<solve(a,b,c,n);
}

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

int main(){
  int a, b, c;
  int temp;
  
  cin >> a >> b >> c;
  
  temp = a;
  a = b;
  b = temp;
  
  temp = a;
  a = c;
  c = temp;
  
  cout << a << ' ' << b << ' ' << c << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

const llong origin = 160 * 80;

llong h, w;
llong a[80][80];
llong b[80][80];

llong s[80][80];
llong t[80][80];
bool dp[81][81][160 * 160 + 80];
const llong M = 160 * 160 + 80;

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> b[i][j];
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            s[i][j] = a[i][j] - b[i][j];
            t[i][j] = b[i][j] - a[i][j];
        }
    }

    dp[0][0][s[0][0] + origin] = true;
    dp[0][0][t[0][0] + origin] = true;
    for (llong i = 0; i < h; i++) {
        for (llong j = 0; j < w; j++) {
            if (i - 1 >= 0) {
                for (int k = 0; k < M; k++) {
                    if (dp[i - 1][j][k]) {
                        dp[i][j][k + s[i][j]] = true;
                        dp[i][j][k + t[i][j]] = true;
                    }
                }
            }
            if (j - 1 >= 0) {
                for (int k = 0; k < M; k++) {
                    if (dp[i][j - 1][k]) {
                        dp[i][j][k + s[i][j]] = true;
                        dp[i][j][k + t[i][j]] = true;
                    }
                }
            }
        }
    }

    llong ans = 1ll << 60ll;
    for (int k = 0; k < M; k++) {
        if (dp[h - 1][w - 1][k]) {
            ans = min(ans, llabs(k - origin));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 163072
#include<stdio.h>
#include<string.h>
int main()
{

  int i,j;
  char a[10][10];
  for(i=0;i<=3;i++)
  {
      for(j=0;j<3;j++)
      {
          scanf("%c",&a[i][j]);
      }
  }
    printf("%c%c%c\n",a[0][0],a[1][2],a[3][1]);
        return 0;
}


Measured memory_bytes: 1668
#include<bits/stdc++.h>
 
#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();
 
using namespace std;
const int N=1e5+1, mod=998244353;
ll sgt[4*N];

void upd(int l,int r,int a,int b,ll val,int i){
	if(l>b||r<a||a>b) return;
	if(l>=a&&r<=b){
		sgt[i]=min(sgt[i],val);
		return;
	}
	
	if(sgt[i]!=1e18){
		sgt[2*i]=min(sgt[2*i],sgt[i]);
		sgt[2*i+1]=min(sgt[2*i+1],sgt[i]);
		sgt[i]=1e18;
	}
	int mid=(l+r)/2;
	upd(l,mid,a,b,val,2*i);	
	upd(mid+1,r,a,b,val,2*i+1);
}

ll get(int l,int r,int id,int i){
	if(l>id||r<id) return 0;
	if(l==r) return sgt[i];
	
	if(sgt[i]!=1e18){
		sgt[2*i]=min(sgt[2*i],sgt[i]);
		sgt[2*i+1]=min(sgt[2*i+1],sgt[i]);
		sgt[i]=1e18;
	}
	
	int mid=(l+r)/2;
	return get(l,mid,id,2*i)+get(mid+1,r,id,2*i+1);
}

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	
	fill(sgt,sgt+4*N,1e18);
	
	int n,m;
	cin>>n>>m;
	
	map<int,vector<pair<int,int>> > mp;
	
	for(int i=0;i<m;i++){
		int l,r,c;
		cin>>l>>r>>c;
		mp[l].pb({c,r});
	}
	
	upd(1,n,1,1,0,1);
	
	for(int i=1;i<=n;i++){
		for(auto x:mp[i]){
			ll cur= get(1,n,i,1);
			upd(1,n,i+1,x.yy,cur+x.xx,1);
		}
	}
	ll res=get(1,n,n,1);
	cout<<(res==1e18?-1:res);
	
    yogeshk972();
}


Measured memory_bytes: 14080
# import sys 
# try:
#     sys.stdin = open('input.txt', 'r') 
#     sys.stdout = open('output.txt', 'w')
# except:
#     pass

n = int(input())
s = input()
r =[]
g = []
b = []
for i in range(n):
	if s[i] == 'R':
		r.append(i)
	elif s[i] == 'G':
		g.append(i)
	else:
		b.append(i)
temp2 = []
for i in r:
	for j in g:
		temp = []
		if (i+j)%2 == 0:
			temp.append((i+j)//2)
		temp.append(min(i,j)-abs(i-j))
		temp.append(max(i,j)+abs(i-j))
		temp2.append(temp)
l = len(b)
d = {}
for i in b:
	d[i] = 1
res = 0
for i in temp2:
	x = l
	for j in i:
		if j in d:
			x -= 1
	res += x
print(res)

Measured memory_bytes: 305304
#include <iostream>

using namespace std;

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

    for (int i = 1; i <= n; ++i) {
        int x = i;
        if (x % 3 == 0) {
            cout << " " << i;
        } else {
            while (x) {
                if (x % 10 == 3) {
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3096
import sys,itertools
if sys.version_info[0]>=3: raw_input=input

def dfs(a):
	if len(a)<2: yield (a[0],str(a[0]))
	for i in range(len(a)-1):
		for l in dfs(a[:i+1]):
			for r in dfs(a[i+1:]):
				yield (l[0]+r[0],'(%s + %s)'%(l[1],r[1]))
				yield (l[0]-r[0],'(%s - %s)'%(l[1],r[1]))
				yield (l[0]*r[0],'(%s * %s)'%(l[1],r[1]))

def solve(a):
	for e in itertools.permutations(a):
		for n,s in dfs(e):
			if n==10:
				print(s)
				return True

try:
	while True:
		a=[int(e) for e in raw_input().split()]
		if a==[0,0,0,0]: break
		if not solve(a): print(0)
except EOFError:
	pass

Measured memory_bytes: 6772
#include<iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int table[100000] = {0};
    for (int i = 0; i < n; ++i) {
        int tmp; cin >> tmp;
        table[tmp]++;;
        table[tmp - 1]++;
        table[tmp + 1]++;
    }
    int Max = 0;
    for (int i = 0; i < 100000; ++i) {
        if (table[i] > Max) {
            Max = table[i];
        }
    }
    cout << Max << endl;
    return 0;
}


Measured memory_bytes: 640
from collections import Counter
N=int(input())
X=[]
for i in range(N):
    X.append(input())
Y=[X[i][0] for i in range(N)]
c = Counter(Y)
count=0
count=c.get('M',0)*c.get('A',0)*c.get('R',0)+ c.get('M',0)*c.get('A',0)*c.get('C',0)+ c.get('M',0)*c.get('A',0)*c.get('H',0)+ c.get('M',0)*c.get('R',0)*c.get('C',0)+\
      c.get('M',0)*c.get('R',0)*c.get('H',0)+ c.get('M',0)*c.get('C',0)*c.get('H',0)+ c.get('A',0)*c.get('R',0)*c.get('C',0)+ c.get('A',0)*c.get('R',0)*c.get('H',0)+\
      c.get('A',0)*c.get('C',0)*c.get('H',0)+ c.get('R',0)*c.get('C',0)*c.get('H',0)
print(count)

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define in2(x, y) int x,y;cin>>x>>y
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 100002
#define lim9 1000000002

#define deg(rad) (((rad)/2/M_PI)*360)
#define pow(x) (x)*(x)
#define mid(min, max) ((min + max) / 2)


int main() {
	in(x);
	int a = x % 100;
	int n = (x - a) / 100;

	rep(i, n) {
		if (a > 5)
			a -= 5;
		else
			a -= a;

		if (a == 0) {
			out(1);
			return 0;
		}
	}

	out(0);
	return 0;
}


Measured memory_bytes: 256
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j,k,a,b;
            cin>>n>>k;
            int ar[n+1];
            for(i=0;i<=n;++i)
                ar[i]=0;
            for(i=1;i<=k;++i)
            {
                cin>>a;
                while(a--)
                {
                    cin>>b;
                    ar[b]++;
                }
            }
            int ans=0;
            for(i=1;i<=n;++i)
            {
                if(ar[i]==0)
                    ++ans;
            }
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3620
n=int(input())
l=sorted(list(map(int,input().split())))
l.reverse()
if(n%2==0):
    print(l[0]+2*sum(l[1:n//2]))
else:
    print(l[0]+(2*sum(l[1:(n//2)+1]))-l[n//2])

    
    



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

int main(){
    int N, M;
    cin >> N >> M;
    int A[M];

    for (int i = 0; i < M; i++){
        cin >> A[i]; 
    }

    int sum = 0;

    for (int i = 0; i < M; i++){
        sum += A[i];
    }
    if (sum <= N) cout << N - sum << endl;
    else cout << -1 << endl;

}

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

#define REP(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) REP(i, 0, n)

int main() {
	int sum = 0;
	rep(i, 5) {
		int score;
		cin >> score;
		sum += (score < 40 ? 40 : score);
	}

	cout << sum / 5 << endl;

	return EXIT_SUCCESS;
}

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

int main() {
    int n,k,h[100010],ans =0;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> h[i];
        if(h[i] >= k)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import re

def f(s):
    for i in range(0,10):
        t = s.replace("X", str(i))
        a, b, c = map(int, re.split(r'\+|\=', t))
        if a + b == c and str(a) + "+" + str(b) + "=" + str(c) == t:
            return i
    return "NA"

while True:
    try:
        print f(raw_input())
    except:
        break

Measured memory_bytes: 4248
let n = Scanf.scanf "%d\n" (fun x -> x)
let a_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a))

let change i minj a = 
	let ai = a.(i) and aminj = a.(minj) in
	a.(i) <- aminj; a.(minj) <- ai; a
	
let print_array a = Array.to_list a |> List.map string_of_int
|> String.concat " " |> print_endline 

let rec selectionSort i j a min cnt =
 if (i = n) && (j = n) then (a, cnt) 
 else if (j = n) then 
  if i = min then selectionSort (i+1) (i+1) a (i+1) cnt 
  else selectionSort (i+1) (i+1) (change i min a) (i+1) (cnt+1) 
 else if a.(j) < a.(min) then selectionSort i (j+1) a j cnt
 else selectionSort i (j+1) a min cnt 
 
let () =
 let a, cnt = selectionSort 0 0 a_ 0 0 in
 print_array a; Printf.printf "%d\n" cnt

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;

Int n, m;
vector<Int> G[100005];
bool visited[100005];
vector<Int> v[100005];
Int a[100005];

Int cnt;

void dfs(Int x) {
    if (visited[x]) return;
    visited[x] = true;
    v[cnt].emplace_back(a[x]);
    for (Int i = 0; i < (Int)G[x].size(); i++) {
        Int to = G[x][i];
        if (!visited[to]) {
            dfs(to);
        }
    }
}

int main() {
    cin >> n >> m;
    for (Int i = 0 ; i < n; i++) cin >> a[i];   
    for (Int i = 0; i < m; i++) {
        Int x, y;
        cin >> x >> y;
        G[x].emplace_back(y);
        G[y].emplace_back(x);
    }
    if (m == n - 1) {
        dump(0);
        return 0;
    }
    if (n < 2 * (n - m - 1)) {
        dump("Impossible");
        return 0;
    }
    for (Int i = 0; i < n; i++) {
        if (visited[i]) continue;
        dfs(i);
        cnt++;
    }
    Int res = 0;
    priority_queue<Int, vector<Int>, greater<Int>> q;
    for (Int i = 0; i < cnt; i++) {
        sort(v[i].begin(), v[i].end());
        res += v[i][0];
        for (Int j = 1; j < (Int)v[i].size(); j++) {
            q.push(v[i][j]);
        }
    }
    while (!q.empty() && cnt < 2 * (n - m - 1)) {
        res += q.top();
        q.pop();
        cnt++;
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 11768
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    char op;
    string s;

    cin >> a >> op >> b;

    if(op=='+') cout <<  a+b;
    else cout << a-b;
    return 0;
}

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

int main(){
  string A, B, C;
  cin >> A >> B >> C;

  if(A.back() == B.front() && B.back() == C.front()){
    printf("%s\n", "YES");
  } else {
    printf("%s\n", "NO");
  }

  return 0; 
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>

using namespace std;

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

int main()
{
	int h,w;
	string s[20];

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

	int res=0;

	for(int si=0;si<h;si++)
	for(int sj=0;sj<w;sj++)
	{
		if(s[si][sj]=='#') continue;

		int dis[25][25];
		for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			dis[i][j]=1e9;

		typedef pair<int,pair<int,int>> P;
		priority_queue<P,vector<P>,greater<P>> q;
		q.push({0,{si,sj}});

		while(q.size())
		{
			auto p = q.top();
			q.pop();

			int i= p.second.first;
			int j= p.second.second;

			if(dis[i][j]<=p.first) continue;
			if(s[i][j]=='#') continue;

			dis[i][j]=p.first;

			for(int k=0;k<4;k++)
			{
				int ni=i+di[k];
				int nj=j+dj[k];

				if(ni<0||h<=ni||nj<0||w<=nj)continue;
				if(p.first+1>=dis[ni][nj])continue;

				q.push({p.first+1,{ni,nj}});
			}
		}


	for(int gi=0;gi<h;gi++)
	for(int gj=0;gj<w;gj++)
	if(s[gi][gj]!='#')
		res = max(res,dis[gi][gj]);
	}
			
	cout<<res<<endl;
}


Measured memory_bytes: 256
package main

import(
    "fmt"
)



func main() {
    var n,m,c int
    fmt.Scan(&n,&m,&c)
    b := make([]int,m)
    for i:=0; i<m; i++{
        fmt.Scan(&b[i])
    }
    ans := 0
    for i:=0; i<n; i++{
        sum := c
        for j:=0; j<m; j++{
            a := 0
            fmt.Scan(&a)
            sum += a*b[j]
        }
        if sum > 0{
            ans++
        }
    }
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}


Measured memory_bytes: 512
s = raw_input()
lut = {}

for c in s:
    if lut.has_key(c) :
        lut[c] += 1
    else:
        lut[c] = 1

ret = "Yes"
for c in range(ord('a'),ord('z')+1):
    c = chr(c)
    if lut.has_key(c) and lut[c] % 2 != 0:
        ret = "No"
        break

print ret

Measured memory_bytes: 2568
#include"bits/stdc++.h"
using namespace std;

int main()
{
  string S;
  string T;
  cin >> S;
  cin >> T;

  int cnt=0;

  for (int i=0; i<3; i++) {
    if (S[i] == T[i]) {
      cnt++;
    }
  }

  cout << cnt << endl;
    
  return 0;
}


Measured memory_bytes: 256
// ABC65-D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る

struct za{int x,y,ind;};
struct edge{int u,v,cost;};
bool comp_x(za a,za b){
    return a.x<b.x;
}
bool comp_y(za a,za b){
    return a.y<b.y;
}
bool comp(edge a,edge b){
    return a.cost<b.cost;
}
struct unionfind{
    vector<int> par;
    void init(int n){
        par.assign(n,-1);
    }
    int find(int x){
        if(par[x]<=-1) return x;
        par[x]=find(par[x]);
        return par[x];
    }
    int size(int x){
        return -1*par[find(x)];
    }
    void unite(int x,int y){
        x=find(x),y=find(y);
        if(x==y) return;
        if(size(x)<size(y)) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
    }
    bool same_set(int x,int y){
        return find(x)==find(y);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n;
    cin>>n;
    vector<za> ten(n);
    rep(i,n){
        za now;
        cin>>now.x>>now.y;
        now.ind=i;
        ten[i]=now;
    }
    vector<edge> hen;
    sort(all(ten),comp_x);
    int bef_x=ten[0].x,bef_y=ten[0].y;
    for(int i=1;i<n;i++){
        edge now;
        now.u=ten[i-1].ind,now.v=ten[i].ind,now.cost=abs(ten[i].x-bef_x);
        hen.e_b(now);
        bef_x=ten[i].x;
    } 
    sort(all(ten),comp_y);
    bef_y=ten[0].y;
    for(int i=1;i<n;i++){
        edge now;
        now.u=ten[i-1].ind,now.v=ten[i].ind,now.cost=abs(ten[i].y-bef_y);
        hen.e_b(now);
        bef_y=ten[i].y;
    } 
    sort(all(hen),comp);
    unionfind uf;
    uf.init(n);
    ll total=0;
    rep(i,sz(hen)){
        edge cur=hen[i];
        if(!uf.same_set(cur.u,cur.v)){
            uf.unite(cur.u,cur.v);
            total+=cur.cost;
        }
    }
    cout<<total<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1ll << 62)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){
  
  ll  n,m,R;
  cin >> n >> m >> R;
  vector<ll> r(R);
  REP(i,R)cin >> r[i],r[i]--;
  sort(ALL(r));
  vector<vector<ll>> dist(n,vector<ll>(n,(1 << 30)));
  REP(i,n)dist[i][i] = 0;
  REP(i,m){
    ll a,b,c;cin >> a >> b >> c;
    a--,b--;
    dist[a][b] = dist[b][a] = c;
  }
  REP(k,n)REP(i,n)REP(j,n)dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
  ll res = INF;
  do{
    ll sum = 0;
    REP(i,R-1)sum += dist[r[i]][r[i+1]];
    res = min(res,sum);
  }while(next_permutation(ALL(r)));
  cout << res << endl;


  

  return 0;
}

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;
using P = pair<int,int>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> s, t;
  rep(i,n) {
    cin >> a[i];
    if (a[i] < 0) t.push_back(a[i]);
    else s.push_back(a[i]);
  }

  int S = s.size();
  int T = t.size();
  bool ok = false;
  if (S > 0) {
    if (n == k) ok = (T%2==0);
    else ok = true;
  } else {
    ok = (k%2==0);
  }

  mint ans = 1;
  if (!ok) {
    sort(a.begin(), a.end(), [](int x, int y) {
      return abs(x) < abs(y);
    });
    rep(i,k) ans *= a[i];
  } else {
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if (k%2 == 1) {
      ans *= s.back();
      s.pop_back();
    }
    vector<ll> p;
    while (s.size() >= 2) {
      ll x = s.back(); s.pop_back();
      x *= s.back(); s.pop_back();
      p.push_back(x);
    }
    while (t.size() >= 2) {
      ll x = t.back(); t.pop_back();
      x *= t.back(); t.pop_back();
      p.push_back(x);
    }
    sort(p.rbegin(), p.rend());
    rep(i,k/2) ans *= p[i];
  }

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


Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,ans=0;
int main(){
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(int i=0;i<=a;i++)
	for(int j=0;j<=b;j++)
	for(int k=0;k<=c;k++)
	if (i*500+j*100+k*50==x) ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
<?php
  $rest=trim(fgets(STDIN));
  for($i=0;$i<$rest;$i++){
    $line=fgets(STDIN);
    $num[]=trim($line);
  }
  foreach($num as $ele2){
    $trinum=explode(" ",$ele2);
    $maxnum=max($trinum);
    $key=array_search($maxnum,$trinum);
    unset($trinum[$key]);
    $sum=0;
    foreach($trinum as $ele){
      $sum+=pow($ele,2);
    }
    /* echo "max:".(int)$maxnum; */
    if($sum==pow((int)$maxnum,2))
      echo "YES\n";
    else
      echo "NO\n";
  }

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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



ll N;
ll A[202020], B[202020], AB[202020];
set<ll> ABst;
vector<ll> ABt;
ll i, j, k;

ll calc(ll aaa){
    ll ai = 0, bi = 0;
    ll i;
    ll ret = -1;
    fornum(i,0,ABt.size()){
        ll num = ABt[i];
        
        while(ai<N&&A[ai]==num){
            ++ai;
        }
        if(ai>=aaa&&ret==-1){
            ret = num;
        }
        while(bi<N&&B[bi]==num){
            ++bi;
        }
        if(bi>=aaa){
            //printf("%lld,%lld\n", num, ret);
            return num - ret + 1;
        }
    }
    return 0;
}

int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        ll a, b;
        scanf("%lld%lld", &A[i], &B[i]);
        ABst.insert(A[i]);
        ABst.insert(B[i]);
    }
    sort(A, A + N);
    sort(B, B + N);
    ABst.insert(0);
    for(auto ab:ABst){
        ABt.push_back(ab);
    }
    ll ans = 0;
    if(N%2==0){
        ans += calc(N / 2);
        ans += calc(N / 2 + 1);
        --ans;
    }else{
        ans += calc(N - N / 2);
        
    }

    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 29336
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;


int main(){
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int s = 0;
    rep(i,n-1){
        s = max(s,a[i+1]-a[i]);
    }
    s = max(s,a[0] + k - a[n-1]);
    cout << k-s;
}


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

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

using namespace std;

int main() {
    string str;
    cin >> str;
    int n[2] = {};
    rep(i, str.length()){
        if(str[i] == '0'){
            n[0]++;
        }else{
            n[1]++;
        }
    }
    cout << min(n[0],n[1]) * 2 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

/*
テストケース全てに目を通す
テストケースが2個以下だったらなんかある
N最小のコーナーケースがないか調べる
制約をしっかりと確認する（1からNまでの順列、全て異なる値などの制約も含め）
操作の逆順を考える
Codeforcesではscanfを使う
 */

int main() {
    int a,b;
    cin >> a >> b;
    cout << max(0,a-2*b);
    


}

/*



 */



Measured memory_bytes: 256
import Control.Applicative

main :: IO ()
main = solve <$> f >>= putStrLn
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> String
solve [a, b, k]
  | k >= a + b = "0 0"
  | k >= a = unwords $ map show $ [0, a + b - k]
  | otherwise = unwords $ map show $ [a - k, b]


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int b[n-1],a[n]={0};
	for(int i=0;i<n-1;i++)
	{
	    cin>>b[i];
	    if(i==0)
	    {
	        a[0]=b[i];
	        a[1]=b[i];
	    }
	    else
	    {
	        if(b[i]>=a[i])
	        {
	            a[i+1]=b[i];
	        }
	        else
	        {
	            a[i]=b[i];
	            a[i+1]=b[i];
	        }
	    }
	}
	int sum=0;
	for(int i=0;i<n;i++)
	{
	    sum+=a[i];
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int x, y;
	scanf("%d %d", &x, &y);
	
	int X = abs(x), Y = abs(y);
	if ((x >= 0 && y > 0) || (x < 0 && y <= 0)) {
		if (x < y) printf("%d\n", y - x);
		else printf("%d\n", x - y + 2);
	} else printf("%d\n", abs(X - Y) + 1);
	fflush(stdout);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,p; cin>>a>>p;
    cout<<(3*a+p)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  int N, M;
  cin >> N >> M;
  int L[M], R[M];
  REP(i, M) { cin >> L[i] >> R[i]; }
  sort(L, L + M);
  sort(R, R + M);
  int cnt = 0;
  REP(i, N + 1) {
    if (L[M - 1] <= i && i <= R[0]) {
      cnt++;
    }
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <algorithm>
#include <map>
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	bool x = false;
	for (int i = 0; i <= B; i++) {
		if (i*A%B == C)x = true;
	}
	if (x)cout << "YES" << endl;
	else cout << "NO" << endl;

}


Measured memory_bytes: 256
"use strict";
const main = arg => {
  let Nums = arg.split(" ");
  let ans = Nums[0] - 2*Nums[1] > 0 ? Nums[0] - 2*Nums[1] :0;
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int dp[100005];

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n) {
    cin >> h[i];
  }
  dp[0] = 0;
  dp[1] = abs(h[0]-h[1]);
  for(int i=2;i<n;i++) {
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int a,b,c,S;
	cin>>a>>b>>c;
	S=0;
	for(int i=a; i<=b;i++){
		if (c%i ==0)S+=1;
	}





	cout<<S<<endl;
	return 0;
}

Measured memory_bytes: 3108
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define lowbit(x) x&(-x)
using namespace std;
typedef long long ll;
const ll INF=0x3f3f3f3f;
const int N=1e5+10;
const int M=(1<<24)+10;
const ll MOD=1e9+7;
const double E=1e-7;
int main(){
	int n,d;
	int ans=0;
	cin >> n >> d;
	for(int i=1;i<=n;i++){
		double x,y;
		cin >> x >> y;
		if(sqrt(x*x+y*y)>d){
			ans++;
		}
	}
	cout << n-ans << endl;
    return 0;
}

Measured memory_bytes: 3800
// B - ss
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S; cin>>S;
	for(int n=S.size()-2; n>1; n-=2){
		if(S.substr(0, n/2) == S.substr(n/2, n/2)){
			cout<< n <<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main(){
	int a, b; cin >> a >> b;
	string bstr = to_string(b);
	int c = b;
	for (int i = 0; i < bstr.size(); i++) {
		a *= 10;
	}
	c += a;

	int dev = 1;
	while (dev*dev <= c) {
		if (dev*dev == c) {
			print("Yes");
			return 0;
		}
		dev++;
	}
	print("No");
	





	return 0;
}

Measured memory_bytes: 256