akhauriyash/Code-Regression huggingface dataset:
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,m,p;cin>>n>>m>>p;
    vector<ll>G(n);
    vector<ll>t(n);
    vector<ll>ans(n);
    vector<ll>a(m);
    vector<ll>b(m);
    vector<ll>c(m);
    for(int i=0;i<n;i++)
        G[i]=-INF;
    G[0]=0;
    /*for(int i=0;i<n;i++)
        t[i]=-INF;
    t[0]=0;
    for(int i=0;i<n;i++)
        ans[i]=-INF;
   ans[0]=0;*/
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;
        c[i]-=p;
        //chmax(G[b],G[a]+c);
    }
    
    for(int j=0;j<n;j++){
        for(int i=0;i<m;i++){
            if(G[a[i]]==-INF)continue;
            chmax(G[b[i]],G[a[i]]+c[i]);
   
        }
    }
    bool broken[3000];
    memset(broken, 0, sizeof(broken));
    for(int j=0;j<n;j++){
        for(int i=0;i<m;i++){
            if(G[a[i]]==-INF)continue;
            ll mmgv=G[b[i]];
            chmax(G[b[i]],G[a[i]]+c[i]);
            if(mmgv!=G[b[i]]){
                broken[b[i]]=1;
            }
            broken[b[i]]|=broken[a[i]];
        }
    }
    if(broken[n-1])cout<<-1<<endl;
    else
    cout<<mmax(G[n-1],0LL)<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;
long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}
ll modinv(ll a){ ll b=mod,u=1,v=0,t; while(b){ t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return (u+mod)%mod; }
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
ll modncr(ll n,ll r){ ll i,plus=1; rep(i,r){ plus=(plus*(n-i))%mod; plus=moddevide(plus,i+1); } return plus; }
ll euclidean_gcd(ll a, ll b) { if(a<b) return euclidean_gcd(b, a); ll r; while ((r=a%b)){a=b;b=r;} return b; }
ll countdigits(ll n){ ll ans=0; while(n){n/=10;ans++;} return ans; }
ll sumdigits(ll n){ ll ans=0; while(n){ans+=n%10;n/=10;} return ans; }
void printmap(vector<ll>& a,ll H,ll W){ ll i,j; For(i,0,H+2){ For(j,0,W+2){cout<<a[i*(W+2)+j];} cout<<endl; } } void inputmap(vector<ll>& a,ll H,ll W){ ll i,j; string ss; For(i,1,H+1){ cin>>ss; For(j,1,W+1){ if(ss[j-1]=='#'){ a[i*(W+2)+j]=1; }else{ a[i*(W+2)+j]=0; } } } }
int main(){
  ll i,j,N,M,K,a,f;
  string ss;
  cin>>N>>M;
  vec v(10,0);
  rep(i,M){
    cin>>a;
    v[a]=1;
  }
  i=N;
  while(1){
    K=i;
    f=1;
    while(K){
      a=K%10;
      if(v[a]){f=0;break;}
      K/=10;
    }
    if(f){cout<<i<<endl;return 0;}
    i++;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;

typedef pair<int,int> pii;

const int INF = 1000000001;

int main(){
  int n;
  vector<pair<int,pii> > event;
  set<int> list;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int x1,y1,x2,y2;
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    if(y1==y2){
      event.push_back(make_pair(min(x1,x2),pii(-INF,y1)));
      event.push_back(make_pair(max(x1,x2),pii(INF,y1)));
    }else if(x1==x2){
      event.push_back(make_pair(x1,pii(min(y1,y2),max(y1,y2))));
    }
  }
  sort(event.begin(),event.end());
  int ans = 0;
  for(int i=0;i<event.size();i++){
    int y1 = event[i].second.first, y2 = event[i].second.second;
    if(y1==-INF) list.insert(y2);
    else if(y1==INF) list.erase(y2);
    else ans += distance(list.lower_bound(y1),list.upper_bound(y2));
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 7564
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int Maxn=3010;
int N;
int A[Maxn];
int Dp[Maxn][Maxn];
signed main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
	}
	for(int dLen=1;dLen<=N;dLen++)
	{
		for(int Left=0;Left+dLen<=N;Left++)
		{
			int Right=Left+dLen;
			bool Turn=(N-dLen)%2;
			if(!Turn)
			{
				Dp[Left][Right]=max(Dp[Left][Right-1]+A[Right-1],Dp[Left+1][Right]+A[Left]);
			}
			else
			{
				Dp[Left][Right]=min(Dp[Left][Right-1]-A[Right-1],Dp[Left+1][Right]-A[Left]);
			}
		}
	}
	cout<<Dp[0][N]<<endl;
	return 0;
}

Measured memory_bytes: 70144
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100005;
int A[MAXN],B[MAXN];
int main()
{
	int N,K;
	scanf("%d%d",&N,&K);
	for(int i=1;i<=N;i++)
		scanf("%d%d",A+i,B+i);
	long long ans=0,sum;
	int maxbit=1<<30;
	bool flag;
	do
	{
		maxbit>>=1;
		if((maxbit&K)==0&&maxbit!=0)
			continue;
		sum=0LL;
		for(int i=1;i<=N;i++)
		{
			if(A[i]&maxbit)
				continue;
			flag=true;
			for(int bit=1<<30;bit>maxbit;bit>>=1)
				if((K&bit)==0&&(A[i]&bit))
				{
					flag=false;
					break;
				}
			if(flag)
				sum+=1LL*B[i];
		}
		ans=max(ans,sum);
	}while(maxbit);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

int main() {
	string S;
	cin>>S;
	int N = S.size();
	ll ans = 0;
	int cntw = 0;
	for (int i = N-1; i >= 0; i--){
		if(S[i] == 'W')cntw++;
		else{
			ans+= cntw;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(ll i = a; i < n; i++)

#include<stdio.h>
#include<iostream>
#include<vector>
#include<sstream>
#include<algorithm>
#include<limits.h>
#include<stack>
#include<queue>
#include<set>
//#pragma comment(linker, "/STACK:12822822 ")

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
const ll power = 17;
const ll inf = 9223372036854775807LL;

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

	/*
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	*/


	ll n;
	cin >> n;
	vector<ll> a(n);
	forn(i, 0, n)
		cin >> a[i];
	multiset<ll> s;
	forn(i, 0, n)
		s.insert(a[i]);
	ll res = 0;
	ll prev = 0;
	prev = *s.begin();
	s.erase(s.begin());
	ll le, ri;
	le = prev;
	ri = prev;
	while (s.size())
	{
		ll fir, sec;
		fir = *s.begin();
		sec = *(--s.end());
		ll fm, sm;
		ll next;
		fm = max(abs(le - fir), abs(ri - fir));
		sm = max(abs(le - sec), abs(ri - sec));
		if (fm > sm)
		{
			s.erase(s.begin());
			next = fir;
		}
		else
		{
			s.erase((--s.end()));
			next = sec;
		}
		if (abs(next - le) > abs(next - ri))
		{
			res += abs(next - le);
			le = next;
		}
		else
		{
			res += abs(next - ri);
			ri = next;
		}
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 5760
///
// File:  c.go
// Author: ymiyamoto
//
// Created on Sun Jun 10 21:06:08 2018
//
package main

import (
	"fmt"
	"sort"
)

var N int

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func pow(a, b int) int {
	ans := 1
	for i := 0; i < b; i++ {
		ans *= a
	}
	return ans
}

func main() {
	fmt.Scan(&N)

	arr := []int{1, pow(6, 1), pow(6, 2), pow(6, 3), pow(6, 4), pow(6, 5), pow(6, 6), pow(6, 7), pow(9, 1), pow(9, 2), pow(9, 3), pow(9, 4), pow(9, 5), pow(9, 6)}
	sort.Ints(arr)

	dp := make([]int, N+1)
	for i := range dp {
		dp[i] = 1 << 30
	}
	dp[0] = 0
	for i := range dp {
		for j := range arr {
			if i-arr[j] >= 0 {
				dp[i] = min(dp[i], dp[i-arr[j]]+1)
			}
		}
	}

	fmt.Println(dp[N])
}


Measured memory_bytes: 1280
N,M = (int(x) for x in input().split()) 
H = list(map(int, input().split()))
A = [0]*M
B = [0]*M
ANS = [0]*N
for i in range(M):
    A[i],B[i] = (int(x) for x in input().split()) 
for i in range(M):
    if(H[A[i]-1] < H[B[i]-1]):
        ANS[A[i]-1] = 1
    elif(H[A[i]-1] > H[B[i]-1]):
        ANS[B[i]-1] = 1
    else:
        ANS[A[i]-1] = 1
        ANS[B[i]-1] = 2
print(ANS.count(0))

Measured memory_bytes: 21856
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int n,W;
int weight[110], value[110];

int dp[110][10010];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> W;
  REP(i,n) cin >> value[i] >> weight[i]; 
  REP(w,W) dp[0][w] = 0;

  REP(i,n){
      for(int w=0;w<=W;w++){
          if(w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
          else dp[i+1][w] = dp[i][w];
      }
  }

  cout << dp[n][W] << endl;
}


Measured memory_bytes: 7172
import sys
import math

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

divisor_set=set()
for i in range(1,int(math.sqrt(M)+1)):
  if M%i==0:
    divisor_set.add(i)
    divisor_set.add(M//i)
#print(divisor_set)

divisor_list=list(divisor_set)
divisor_list.sort()

for l in divisor_list:
  if l>=N:
    answer=M//l
    print(answer)
    break


Measured memory_bytes: 3060
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vector<string> ans(h);

    string s1(w, ' '), s2(w, ' ');
    for(int i=0;i<w;i++){
        s1[i] = (i < a ? '0':'1');
        s2[i] = (i < a ? '1': '0');
    }

    for(int i=0;i<h;i++){
        ans[i] = (i < b ? s1 : s2);
    }
    for(auto s: ans)
        cout << s << endl;
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
 
void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const ll MAXN = 1e6 + 10;
const ll N = 4000 + 10;
const int mod = 1e6;


int main()
{
	faster();
	int x , a , b;
	cin >> x >> a >> b;
	x -= a;
	cout << x % b << endl;
}	

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
n=int(input())
p=factorization(n)
ans=0
if n==1:
    print(0)
    exit()
for i in range(len(p)):
    k=1
    while p[i][1]>0:
        p[i][1]-=k
        if p[i][1]>=0:
            ans+=1
            k+=1
        else:
            break
print(ans)

Measured memory_bytes: 9532
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1)
    {
        if(b==2)
            cout<<"3"<<endl;
        else
            cout<<"2"<<endl;
    }
    else if(a==2)
    {
        if(b==1)
            cout<<"3"<<endl;
        else
             cout<<"1"<<endl;
    }
    else if(a==3)
    {
        if(b==1)
            cout<<"2"<<endl;
        else
            cout<<"1"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3548
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<math.h>
#include<stdlib.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int A[4000100];
int N;
char q[20];

void Delete(int v){
    if(v > N)return;
    int l = v * 2;
    int r = v * 2 + 1;
    if(A[l] > A[r]){
        A[v] = A[l];
        Delete(l);
    }
    else {
        A[v] = A[r];
        Delete(r);
    }
}

void extract(){
    printf("%d\n", A[1]);
    Delete(1);
}

void insert(int v){
    int par = v / 2;
    if(par < 1)return;
    if(A[par] < A[v]){
        swap(A[par], A[v]);
        insert(par);
    }
}

signed main(){
    memset(A, -1, sizeof(A));
    while(1){
        cin >> q;
        if(q[0] == 'i'){
           int val;
            cin >> val;
            N++;
            A[N] = val;
            insert(N);
        }
        else if(q[1] == 'x'){
            extract();
        }
        else {
            break;
        }
    }


    return 0;
}

/*

*/


Measured memory_bytes: 18848
n, a, b = map(int, input().split())
mod = 10**9 + 7
def inv(a, p):
    return pow(a, p-2, p)

def comb(n, r, p = mod):
    x, y = 1, 1
    for i in range(r):
        x = (x * (n - i)) % p
        y = (y * (i + 1)) % p
    return x * inv(y, p) % p

answer = (pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)) % mod
print(answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ld = long double;
#define PI 3.14159265358979323846264338327950L
int main(){
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    ld rad=PI*2*((ld)h/12+((ld)m/60)/12-(ld)m/60);
    ld rsq=a*a+b*b-2*a*b*cosl(rad);
    printf("%20.20Lf\n",sqrt(rsq));

}

Measured memory_bytes: 4108
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int N, A, B, C;
vector<int> L;
int ans = 1000000000;
void dfs(int n, int a, int b, int c, int f) {
    if (n == N) {
        if (a != 0 && b != 0 && c != 0) {
            int mp = abs(A - a) + abs(B - b) + abs(C - c) + f * 10;
            ans = min(ans, mp);
        }
    } else {
        for (int i = 0; i < 4; i++) {
            if (i == 0) {
                if (a == 0) {
                    dfs(n + 1, a + L[n], b, c, f);
                } else {
                    dfs(n + 1, a + L[n], b, c, f + 1);
                }
            } else if (i == 1) {
                if (b == 0) {
                    dfs(n + 1, a, b + L[n], c, f);
                } else {
                    dfs(n + 1, a, b + L[n], c, f + 1);
                }
            } else if (i == 2) {
                if (c == 0) {
                    dfs(n + 1, a, b, c + L[n], f);
                } else {
                    dfs(n + 1, a, b, c + L[n], f + 1);
                }
            } else {
                dfs(n + 1, a, b, c, f);
            }
        }
    }
}

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

    cin >> N >> A >> B >> C;
    L.assign(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

    dfs(0, 0, 0, 0, 0);

    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef long long 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 FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

template <typename T>
void printVector(const std::vector<T> &data)
{
    stringstream ss;
    ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    copy(ALL(data) - 1, out_it);
    ss << data.back() << "]";
    cout << ss.str() << endl;
    return;
}

int main()
{
  int a, b; cin >> a >> b;
  int ans = -1;
  int MAX  = 1250;
  REP(i, MAX) {
    if (i == 0) continue;
    if ((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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 long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,t;
  cin>>n>>t;
  ll res=0;
  ll nt,pt=0;
  rep(i,n){
    cin>>nt;
    res+=min(t,nt-pt);
    pt=nt;
  }
  cout<<res+t<<endl;

  return 0;

}


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

int main(){
    int N;
    vector<long long> a;
    long long sum=1;
    cin>>N;
    for(int i=1;i<=N;i++){
        long long temp;
        cin>>temp;
        a.push_back(temp);
        if(temp==0){
            cout<<"0"<<endl;
            return 0;
        }
    }
    sum=1;
    long long prev=1;
    for(auto s : a){
        prev=sum;
        sum*=s;
        if(sum>1000000000000000000||prev>sum){
            cout<<"-1"<<endl;
            return 0;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 4220
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    Int n,a,b,ans;
    cin>>n>>a>>b;
    if(a>b)ans=0;
    else if(n==1){
        if(a==b)ans=1;
        else ans=0;
    }
    else ans=(b-a)*(n-2)+1;
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		Arrays.setAll(A, i -> sc.nextInt());
		Arrays.sort(A);
		long ans = 0;
		boolean ok = true;
		int j = N-1;
		for(int i = 0; i < N-1; i++) {
			ans += A[j];
			if(ok) {
				j--;
				ok = false;
			}
			else
				ok = true;
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 59908
#include <bits/stdc++.h>
using namespace std;
int dp[100005];
int val[100005];
int main()
{
  int n;
  cin>>n;
  for (int i=0 ; i<n ; i++) cin>>val[i];
  dp[0]=0;
  for (int i=1 ; i< n ; i++){
    int y, x= dp[i-1]+abs(val[i]- val[i-1]);
    if(i==1)y=1000003;
    else y= dp[i-2]+abs(val[i]-val[i-2]);
    dp[i]= min(x,y);
  }
  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
import itertools
H,W,K = map(int,input().split())
sx = list(itertools.product([0,1],repeat = H))
sy = list(itertools.product([0,1],repeat = W))
data = list(input() for num in range(int(H)))
data2 = []
for num in range(int(H)):
  data2 += [list(data[num])]
ans = 0
for numx in range(len(sx)):
  for numy in range(len(sy)):
    count = 0
    for i in range(H):
      for j in range(W):
        if(sx[numx][i]==1)&(sy[numy][j]==1)&(data2[i][j]=="#"):
          count += 1
    if(count == K):
      ans += 1
      
print(ans)

Measured memory_bytes: 9180
import numpy as np
a, b = map(int, input().split())
if  b == 100:
    z = a*1000 + b
elif b >= 10 and  b < 100:
    z = a*100 + b
elif b >= 0 and  b < 10:
    z = a*10 + b

e = np.sqrt(z)
f = float(e) - int(e)
if bool(f) == False:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 12480
n = int(input())
mod = 10**9 + 7
a = list(map(int, input().split()))
b = [sum(1 for x in a if x&(1<<i)) for i in range(60)]
ans = 0
for i in range(60):
  t = b[i]*(n-b[i])
  m = (1<<i)%mod
  ans = (ans + t*m%mod)%mod
print(ans)

Measured memory_bytes: 122936
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int a[n];
for(int i = 0; i < n; ++i){
	cin >> a[i];
}
sort(a, a+n);
long long count= 0;
for(int i = 0; i < n - 2; ++i){
	for(int j = i + 1; j < n - 1; ++j){
		for(int k = j + 1; k < n; ++k){
			if(a[i] + a[j] > a[k]) count++;
		}
	}
}
cout << count;
return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split().Select(int.Parse).ToArray();

        var s = 0L;
        var c = 0;
        for (int i = 0; i < N; i++)
        {
            if (A[i] < 0) c++;
            s += Abs(A[i]);
        }
        if (c % 2 == 0)
        {
            WriteLine(s);
            return;
        }
        else
        {
            WriteLine(s-A.Select(x=>Abs(x)).Min()*2);
        }
    }
}

public class SegmentTree<T> where T : struct
{
    T[] buffer;
    int N;
    T IE;
    Func<T, T, T> Op;


    public SegmentTree(T[] init, T E, Func<T, T, T> op)
    {
        var c = 1;
        while (c < init.Length) c <<= 1;
        N = c;
        buffer = new T[N * 2 - 1];
        for (int i = 0; i < buffer.Length; i++)
        {
            buffer[i] = E;
        }
        Array.Copy(init, 0, buffer, N - 1, init.Length);
        for (int i = N - 2; i >= 0; i--)
        {
            buffer[i] = op(buffer[i * 2 + 1], buffer[i * 2 + 2]);
        }
        Op = op;
        IE = E;
    }

    public void Update(int index, T value)
    {
        index += N - 1;
        buffer[index] = value;
        while (index > 0)
        {
            index = (index - 1) / 2;
            buffer[index] = Op(buffer[index * 2 + 1], buffer[index * 2 + 2]);
        }
    }

    public T this[int index]
    {
        set
        {
            Update(index, value);
        }
        get
        {
            return buffer[index + N - 1];
        }
    }

    public T Query(int l, int r)
    {
        var y = IE;
        l += N - 1;
        r += N - 1;
        while (l < r)
        {
            if ((l & 1) == 0)
            {
                y = Op(y, buffer[l]);
            }
            if ((r & 1) == 0)
            {
                y = Op(y, buffer[r - 1]);
            }
            l /= 2;
            r = (r - 1) / 2;
        }
        return y;
    }
}

Measured memory_bytes: 32220
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
using namespace std;

#define ll long long
using vt = int; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	int n;
	double s = 0;
	cin >> n;
	rep(i, n) {
		double a;
		cin >> a;
		s += 1 / a;
	}
	cout << fixed << setprecision(6) << 1 / s;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	long long n;
	long long m;
	long long ans = 0;
	scanf("%lld", &n);
	if (n > 2)ans += n - 1;
	else {
		printf("0\n");
		return 0;
	}
	for (long long i = 2; i <= 2000 * 1000; i++) {
		if (n % i == 0) {
			if (n / i <= i) {
				printf("%lld\n", ans);
				return 0;
			}
			else {
				if (i - 1 > n / i)ans += i - 1;
				m = n / i;
				if (m - 1 > n / m)ans += m - 1;
			}
		}
		if (i * i > n) {
			printf("%lld\n", ans);
			return 0;
		}
	}
}

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

int main() {
  vector<int> v(3);
  for (int &e : v) cin >> e;
  sort(v.rbegin(), v.rend());
  int N1 = v[0] - v[1];
  int N2 = v[1] - v[2];
  if (N2 % 2 != 0) N2 += 4;
  cout << N1 + N2 / 2 << endl;
}

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

#define MAX_N 105
int N,T;


int main(){
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(0);
    int c,t;
    while(cin >> N >> T){
        int ans = INT_MAX;
        for(int i = 1; i <= N; ++i){
            cin >> c >> t;
            if(t <= T) ans = min(ans, c);
        }
        if(ans == INT_MAX) cout << "TLE" << endl;
        else cout << ans << endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
#define MAX 100000
 
int parent(int);
int left(int);
int right(int);
 
int main(){
  int i,n,A[MAX+1];
 
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
 
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) >= 1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= n)printf("left key = %d, ",A[left(i)]);
    if(right(i) <= n)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
 
  return 0;
}
 
int parent(int i){
 
  return i/2;
}
 
int left(int i){
 
  return 2 * i;
}
 
int right(int i){
 
  return 2 * i + 1;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
int main(){
string s,t,u;
  int c,ans=1000;
  cin>>s>>t;
  for(int i=0;i<s.size()-t.size()+1;i++){
  u=s.substr(i,t.size());
    c=0;
    for(int j=0;j<t.size();j++){
    if(u[j]!=t[j]){c++;}
    }
    ans=min(ans,c);
  }
  cout<<ans;
return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    ll m = t.size();

    ll ans = INF;
    exrep(i, 0, n-m) {
        ll now = 0;
        rep(j, m) {
            if(s[i+j] != t[j]) {
                now++;
            }
        }
        chmin(ans, now);
    }
    
    out(ans);
    re0;
}

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

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

using namespace std;

typedef long long ll;

#define DIR_W false
#define DIR_H true

struct Data {
  ll v;
  bool dir;
  bool operator < (const Data &data) const {
    if( v != data.v ) return v < data.v;
    return dir < data.dir;
  }
};

#define MAX 100010

int W,H;
ll p[MAX], q[MAX];

void compute() {
  vector<Data> vec;
  rep(i,W) vec.push_back((Data){p[i],DIR_W});
  rep(i,H) vec.push_back((Data){q[i],DIR_H});
  sort(vec.begin(),vec.end());
  int used_H = 0, used_W = 0;
  ll mini = 0;
  rep(i,(W+H)) {
    if( vec[i].dir == DIR_W ) {
      mini += ( (H+1) - used_H ) * vec[i].v;
      ++used_W;
    } else {
      mini += ( (W+1) - used_W ) * vec[i].v;
      ++used_H;
    }
  }
  cout << mini << endl;
}

int main() {
  cin >> W >> H;
  rep(i,W) cin >> p[i];
  rep(i,H) cin >> q[i];
  compute();
  return 0;
}


Measured memory_bytes: 6000
#include <iostream>
#include <algorithm>

using namespace std;

int f(int a, int b, int c){
    return (a-5)*(a-5)+(b-5)*(b-5)+(c-7)*(c-7);
}

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    if(f(a[0],a[1],a[2])){
        cout << "NO"<< endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

typedef vector<int> vi;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define ALL(a) (a).begin(),a.end()
#define MAXE(a) *max_element(ALL(a))
#define MINE(a) *min_element(ALL(a))

int main(){
	int n;
	cin >> n;
	vi a(n);
	REP(i,n) cin >> a[i];
	cout << MAXE(a) - MINE(a) << endl;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  
  a = a%2;
  b = b%2;
  if((a*b)%2 == 0){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" <<endl;
  }
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  int n, m; cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2;
  return 0;
}

Measured memory_bytes: 256
program reconciled
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer(8) :: n, m, i, x = 1_8
  read(*,*) n, m
  if (abs(n-m) > 1_8) then
    write(*,'(i0)') 0
  else
    if (n == m) x = 2_8
    do i = 1_8, min(n,m)
      x = mod(mod(i*i,md)*x,md)
    end do
    do i = min(n,m)+1_8, max(n,m)
      x = mod(i*x,md)
    end do
    write(*,'(i0)') x
  end if
end program reconciled

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int P = 1e9 + 7 , N = 23000000;
inline void pp(int &x,int d) {if((x+=d)>=P)x-=P;}
int Pow(int x,int t) {int r(1);for(;t;t>>=1,x=ll(x)*x%P)if(t&1)r=ll(r)*x%P;return r;}
int S;
char num[N];

int main(){
  cin >> S;
  int ans = 0;
  int lim = 1e7;
  int _ = 0;
  rep(i,1,9) {
    int tot = 9 * Pow(10 , i - 1);
    rep(j,0,tot) {
      if(_ + 1 == N) break;
      num[++_] = i;
    }
  }
  for(int l=1,r=1,s=1;l<lim;s-=num[l++]) {
    while(s < S) s+=num[++r];
    if(s == S) ans++;
  }
  pp(ans , S / 8);
  for(int i = 1;i * i <= S;++i) if(S % i == 0) {
    auto add = [&](int x) {
      if(x >= 8) pp(ans , ((9ll * Pow(10 , x - 1) % P - S / x) + P) % P);
    };
    add(i);
    if(i * i != S) add(S / i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 22656
#include<bits/stdc++.h>
#define PB push_back
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define FI first
#define SE second
#define mem(a) memset(a,0,sizeof(a))
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
const LL maxn = 1<<17;
const int mod = 1e9+7;
const int N = 4e5+5;
LL gcd(LL a,LL b) {
	return b?gcd(b,a%b):a;
}
LL lcm(LL a,LL b) {
	return a*b/gcd(a,b);
}
int a[10010];
int main() {
	ios;
	for(int i=1;i<=105;i++){
		for(int j=1;j<=105;j++){
			for(int k=1;k<=105;k++){
				int t=i*i+j*j+k*k+i*j+i*k+j*k;
				if(t<=10000)a[t]++;
			}
		}
	}
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		cout<<a[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
int main(void){
    // Your code here!
    int i,flag;
    int N;
    long H[100001];
    
    flag = 0;
    
    scanf("%d",&N);
    for(i=1;N>=i;i++){
        scanf("%ld",&H[i]);
        if(i>1){
            if(H[i]>H[i-1]) H[i]--;
        }
    }
    
    for(i=2;N>=i;i++){
        if(H[i-1]>H[i]) flag=1;
    }
    
    if(flag) printf("No\n");
    else     printf("Yes\n");
    
    return 0;
}


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

int const MAX = 200005;
long long a[MAX];

int main() {
	long long a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k % 2 == 0) {
		cout << a - b << endl;
	}
	else {
		cout << b - a << endl;
	}
}


Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))

def color(a):
    if a < 400:
        return 1
    elif a < 800:
        return 2
    elif a < 1200:
        return 3
    elif a < 1600:
        return 4
    elif a < 2000:
        return 5
    elif a < 2400:
        return 6
    elif a < 2800:
        return 7
    elif a < 3200:
        return 8
    else:
        return 0

freq = [0] * 9
for a in As:
    freq[color(a)] += 1

cum = 0
for c in freq[1:]:
    if c: cum += 1
an = freq[0]

if cum == 0:
    print(1, an)
else:
    print(cum, cum + an)


Measured memory_bytes: 3188
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

/*
  UnionFind Tree
*/
class UnionFind {
    private: 
        vector<int> par;
        vector<int> rank;
        vector<int> cnt;
    
    public:
        UnionFind(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        int count(int x);
        void printStatus();
};

UnionFind::UnionFind(int n) {
    for (int i = 0; i < n; i++) {
        par.push_back(i);
        rank.push_back(0);
        cnt.push_back(1);
    }
}
int UnionFind::find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}
void UnionFind::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
        cnt[y] += cnt[x];
        par[x] = y;
    } else {
        cnt[x] += cnt[y];
        par[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}
bool UnionFind::same(int x, int y) {
    return find(x) == find(y);
}
int UnionFind::count(int x) {
    return cnt[find(x)];
}
void UnionFind::printStatus() {
    printf("----------------\n");
    for (int i = 0; i < par.size(); i++) {
        printf("[node %d]: parent = %d, rank = %d, count = %d\n", i, par[i], rank[i], cnt[i]);
    }
}

int main() {
    int N;
    cin >> N;
    vector<P> x(N), y(N);
    rep(i,N) {
        cin >> x[i].first >> y[i].first;
        x[i].second = i;
        y[i].second = i;
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    vector< pair<int, P> > edges;
    rep(i,N-1) {
        edges.push_back(make_pair(x[i + 1].first - x[i].first, make_pair(x[i].second, x[i + 1].second)));
        edges.push_back(make_pair(y[i + 1].first - y[i].first, make_pair(y[i].second, y[i + 1].second)));
    }

    sort(edges.begin(), edges.end());
    UnionFind tree(N);
    long long ans = 0;
    rep(i,edges.size()) {
        if (!tree.same(edges[i].second.first, edges[i].second.second)) {
            ans += edges[i].first;
            tree.unite(edges[i].second.first, edges[i].second.second);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n,k;
    ci(n>>k);
  ll ans=0;
  ll count=0;
  FOR(i,1,n+1){
    if(i%k==0) ans++;
    else if((2*i)%k==0) count++;
  }
  if(k%2==1) co(ans*ans*ans)
  else co(ans*ans*ans+count*count*count)
    }

Measured memory_bytes: 256
N, C = gets.split.map(&:to_i)
ss, ts, cs = [], [], []
N.times do |i|
    ss[i], ts[i], cs[i] = gets.split.map(&:to_i)
end

tmax = ts.max

imos = Array.new(C + 1){Array.new(tmax + 2, 0)}

N.times do |i|
    s, t, c = ss[i], ts[i], cs[i]
    imos[c][s] += 1
    imos[c][t] -= 1
end

(1..C).each do |chan|
    (0...tmax).each do |tim|
        if imos[chan][tim + 1] == 1
            imos[chan][tim] += 1
            imos[chan][tim + 1] -= 1
        end
    end
end

(1..C).each do |chan|
    (1..tmax).each do |tim|
        imos[chan][tim] += imos[chan][tim - 1]
    end
end

max = 0
(0..tmax).each do |tim|
    sum = 0
    (1..C).each do |chan|
        sum += imos[chan][tim]
    end
    max = sum if sum > max
end

print max


Measured memory_bytes: 28612
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,m;cin>>n>>m;
  vector<int> x(m);
  for(int i=0; i<m; ++i) cin>>x[i];
  sort(x.begin(),x.end());
  vector<int> dis(m-1);
  for(int i=1; i<m; ++i) dis[i-1]=x[i]-x[i-1];
  sort(dis.rbegin(),dis.rend());
  int res=x.back()-x[0];
  for(int i=0; i<min(m-1,n-1); ++i) res-=dis[i];
  cout<<res<<endl;
  return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int count = 0;
  int hole = 1;
  while(true){
    if(hole < b){
      hole += a-1;
      count++;
    }
    else
      break;
  }
  cout << count;
}


Measured memory_bytes: 3636
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int w, n;
    int[] a;
    int i, j, k, x, y, t, tmp;
    String str;
    char[] ch;

    w = sc.nextInt();
    n = sc.nextInt();
    a = new int[w];
    for(i = 0;i < w;i++)a[i] = i;

    for(i = 0;i < n;i++){
      str = sc.next();
      ch = new char[str.length()];
      x = 0; y = 0;

      for(j = 0;j < str.length();j++){
        if(str.charAt(j) == ','){
          t = 1;
          for(k = 0;k < j;k++){
            x += t * (int)(ch[j - 1 - k] - '0');
            t *= 10;
          }
          j++; break;
        }else ch[j] = str.charAt(j);
      }

      t = 1;
      for(k = str.length() - 1;k >= j;k--){
        ch[k] = str.charAt(k);
        y += (int)(ch[k] - '0') * t;
        t *= 10;
      }
      tmp = a[x - 1]; a[x - 1] = a[y - 1]; a[y - 1] = tmp;
    }

    for(i = 0;i < w;i++)out.println(a[i] + 1);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

vector<string> S;

int main(){
  int N, L;
  cin >> N >> L;
  for(int i=0; i<N; i++){
    string str; cin >> str;
    S.push_back(str);
  }
  sort(S.begin(), S.end());
  string ans ="";
  for(int i=0;i<N; i++){
    ans+=S[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	int m,d;cin >> m>>d;
	int cnt=0;
	for(int i=1;i<d+1;++i){
		int d1= i%10;
		int d10= i/10;
		if(d1<2 || d10<2) continue;
		if(d1*d10<=m &&d1*d10>0) ++cnt; 
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int A, B;
  cin >> A >> B;
  if (A - B * 2 <= 0)
  {
    cout << 0 << endl;
  }
  else
  {
    cout << A - B * 2 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	while (true) {
		int n, p;
		cin >> n >> p;
		if (n == 0 && p == 0)break;
		int stone[50] = {};
		int owan = p;
		int idx = 0;
		while (true) {
			if (owan != 0) {
				stone[idx]++;
				owan--;
			}
			else {
				owan += stone[idx];
				stone[idx] = 0;
			}
			if (stone[idx] == p) {
				cout << idx << endl;
				break;
			}
			idx = (idx + 1) % n;
		}
	}
	return 0;
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
#include<atcoder/all>
#define int long long
using namespace std;
using namespace atcoder;
constexpr int mod=998244353;
int op(int a,int b){
    return max(a,b);
}
int e(){
    return 0;
}
signed main(){
    int n,k,a;
    cin>>n>>k;
    segtree<int,op,e>seg(300001);
    while(cin>>a){
        seg.set(a,seg.prod(max(0ll,a-k),min(300001ll,a+k+1))+1);
    }
    cout<<seg.all_prod()<<endl;
}


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

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


if __name__ == '__main__':
    n = int(input())
    n = n % 10
    if n in [2, 4, 5, 7, 9]:
        print("hon")
    elif n in [0, 1, 6, 8]:
        print("pon")
    else:
        print("bon")

    #print('\33[32m' + 'end' + '\033[0m') # debug


Measured memory_bytes: 68492
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;
namespace mp = boost::multiprecision;

const long long MOD = 1000000007;

struct query {
	ll n;
	ll x;
	ll m;
};

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

	int k, q;
	cin >> k >> q;
	ll* d;
	query* qu;
	d = new ll[k];
	qu = new query[k];
	rep(i, k) cin >> d[i];
	rep(i, q) cin >> qu[i].n >> qu[i].x >> qu[i].m;

	rep(i, q) {
		ll t = (qu[i].n-1) / k;
		ll s = (qu[i].n-1) % k;

		ll sum = 0;
		ll r = 0, zero = 0, zeros = 0;
		rep(j, k) {
			sum += d[j] % qu[i].m;
			if (d[j] % qu[i].m == 0) ++zero;
			if (j + 1 == s) {
				r = sum;
				zeros = zero;
			}
		}

		ll ans = qu[i].n - 1 - (sum / qu[i].m)*t - ((sum%qu[i].m)*t + r + qu[i].x) / qu[i].m;
		ans += qu[i].x / qu[i].m;
		ans -= zero * t + zeros;

		cout << ans << "\n";
	}

	return 0;
}
 

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, i, ans=0, cnt=0;
    cin >> n;
    vector<long long> a;
    for(i=0;i<n*3;i++){
        long long x;
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    while(cnt<n){
        i=i-2;
        ans+=a.at(i);
        cnt++;
    }

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

Measured memory_bytes: 5360
#include <stdio.h>


int main(){
	long long int n;
	scanf("%lld", &n);
	long long int total = 0;
	
	for(int i = 1; i <= n; i++){
		if(i % 3 == 0 && i % 5 == 0){
			continue;
		} else if(i % 3 == 0){
			continue;
		} else if(i % 5 == 0){
			continue;
		} else {
			total += i;
		} 
	}
		printf("%lld", total);
	return 0;
}

Measured memory_bytes: 1720