akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cctype>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cctype>
#include<cstring>
#include<utility>
const int inf=0x7fffffff;
typedef long long int ll;
using namespace std;
char s[100+10];
struct DICE{
	int u,s,e,w,n,d;
	DICE (int u=0,int s=0,int e=0,int w=0,int n=0,int d=0):u(u),s(s),e(e),w(w),n(n),d(d){}
	DICE fW(){
		DICE tmp;
		tmp.s=this->s;
		tmp.n=this->n;
		tmp.e=this->d;
		tmp.w=this->u;
		tmp.u=this->e;
		tmp.d=this->w;
		return tmp;
	}
	DICE fS(){
		DICE tmp;
		tmp.s=this->u;
		tmp.n=this->d;
		tmp.e=this->e;
		tmp.w=this->w;
		tmp.d=this->s;
		tmp.u=this->n;
		return tmp;
	}
	DICE fE(){
		DICE tmp;
		tmp.s=this->s;
		tmp.n=this->n;
		tmp.e=this->u;
		tmp.w=this->d;
		tmp.d=this->e;
		tmp.u=this->w;
		return tmp;
	}
	DICE fN(){
		DICE tmp;
		tmp.s=this->d;
		tmp.n=this->u;
		tmp.e=this->e;
		tmp.w=this->w;
		tmp.d=this->n;
		tmp.u=this->s;
		return tmp;
	}
	int right(int t,int f){
		if(t==this->u)
		{
			if(f==this->s)return this->e;
			else if(f==this->e)return this->n;
			else if(f==this->n)return this->w;
			else if(f==this->w)return this->s;
		}
		else if(t==this->s){
			DICE tmp=(*this).fN();
			return tmp.right(t,f);
		}
		else if(t==this->e){
			DICE tmp=(*this).fW();
			return tmp.right(t,f);
		}
		else if(t==this->n){
			DICE tmp=(*this).fS();
			return tmp.right(t,f);
		}
		else if(t==this->w){
			DICE tmp=(*this).fE();
			return tmp.right(t,f);
		}
		else if(t==this->d){
			DICE tmp=(*this).fE().fE();
			return tmp.right(t,f);
		}
		}
};
int main()
{
//#ifdef DEBUG
//	freopen("in", "r", stdin);
////	freopen("out", "w", stdout);
//#endif
	
	int a[6];
	for(int i=0;i<6;i++){
		scanf("%d", &a[i]);
	}
	DICE dice(a[0],a[1],a[2],a[3],a[4],a[5]);
//	DICE I
//	scanf("%s", s);
//	int len=strlen(s);
//	for(int i=0;i<len;i++){
//		switch(s[i]){
//			case'S':dice=dice.fS();break;
//			case'E':dice=dice.fE();break;
//			case'W':dice=dice.fW();break;
//			case'N':dice=dice.fN();break;
//		}
//	}
//	printf("%d\n", dice.u);
//
	int x,y;
	int q;
	scanf("%d", &q);
	while(q--){
		scanf("%d%d",&x,&y);
		printf("%d\n",dice.right(x,y));
	}
	return 0;
}
//aoj1_11_a.cc

Measured memory_bytes: 1188
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    [n, t] <- map strToInteger . words <$> getLine
    -- スペース区切り整数の入力
    ts <- map strToInteger . words <$> getLine
    -- 出力
    putStrLn $ show $ solve ts t 0
solve :: [Integer] -> Integer -> Integer -> Integer
solve [t0] t acc = acc + t
solve (t0:t1:ts) t acc = if t0 + t < t1 then solve (t1:ts) t (acc+t) else solve (t1:ts) t (acc+t1-t0)


Measured memory_bytes: 70012
m = map(int,raw_input().split())

W = m[0]
H = m[1]
x = m[2]
y = m[3]
r = m[4]


if 0 <= x-r and x+r <= W and 0 <= y-r and y+r <= H:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 6444
#include<stdio.h>
int main(void)
{
	int x1,x2,x3;
	int x;
	scanf("%d %d %d",&x1,&x2,&x3);
	if(x1>x2){
		x=x1;
		x1=x2;
		x2=x;
		x=0;
	}
	if(x1>x3){
		x=x1;
		x1=x3;
		x3=x;
		x=0;
	}
	if(x2>x3){
		x=x2;
		x2=x3;
		x3=x;
		x=0;
	}

	printf("%d %d %d\n",x1,x2,x3);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
struct Node{
  int key;
  int id,parent,left,right;
};


Node A[20000000];
int H;

void heap(int H){
  for(int i=1;i<=H;i++){
    if(i==1){
      A[i].left=A[2*i].key;
      A[i].right=A[2*i+1].key;
    }
    else {
      A[i].parent=A[i/2].key;
      A[i].left=A[2*i].key;
      A[i].right=A[2*i+1].key;
    }
  }
}
void maxheap(int i){
  int l=0,r=0;
  int lag;
  int tmp;
  l=2*i;
  r=2*i+1;
  if(l<=H && A[l].key>A[i].key){
    lag=l;
  }
  else {
    lag=i;
  }
  if(r<=H&&A[r].key>A[lag].key){
    lag=r;
  }
  if(lag!=i){
    tmp=A[i].key;
    A[i].key=A[lag].key;
    A[lag].key=tmp;
    maxheap(lag);
  }
  
}


int main(){
  cin>>H;
  for(int i=1;i<=H;i++){
    cin>>A[i].key;
    A[i].id=i;
  }
  heap(H);
  for(int i=H/2;i>=1;i--){
    maxheap(i);
  }
  for(int i=1;i<=H;i++){
    cout<<" "<<A[i].key;
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 12860
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;


const int n = (int)10e6;
vector<bool> prime(n+1 , true);
void sieve_cnt()  ////O(n*log(log(n)))
{

    prime[0] = false;
    prime[1] = false;

    for(int i = 2 ; i*i<=n; i++) //we
    {
        if(prime[i])
        {
            for(int j = i*2 ; j<=n ; j+=i)
                prime[j]=false;
        }
    }
}


int main()
{


 int x; cin>>x;
 sieve_cnt();
 for(int i = x ; i<n ; i++)
 {
     if(prime[i])
     {
         cout<<i<<endl;
         return 0;
     }

 }


    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 1e5 + 10;
int a[MAXN], dp[MAXN], p[MAXN];
void solve() {
    int n, k = 2;
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i], dp[i] = 2e9;
    dp[1] = 0;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; i + j <= n && j <= k; ++j) {
            int res = dp[i] + abs(a[i + j] - a[i]);
            if(res < dp[i + j]) {
                dp[i + j] = res;
                p[i + j] = i;
            }
        }
    }
    cout << dp[n];
    /// << '\n';
    ///while(n != 0) cout << n << ' ', n = p[n];
}


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


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

int main()
{
	int v[] = {500, 100, 50, 10, 5, 1};
	while (1){
		int price;
		cin >> price;
		if (price == 0) return 0;
		price = 1000 - price;
		int ans = 0;

		for (int i = 0; i < 6; i++){
			ans += price / v[i];
			price %= v[i];
		}
		cout << ans << endl;
	}

}




Measured memory_bytes: 2996
#include "bits/stdc++.h"

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

#define rep(i,n) for (ll i = 0; i < (n); i++)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;

	int tmp = a;
	a = b;
	b = tmp;

	tmp = a;
	a = c;
	c = tmp;


	cout << a << " " << b << " " << c << " " << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int main() {
	// input
	string s; cin >> s;
	int n = s.length();
	// 自明に不可能なものに-1を出力
	if (s[0] != '1' || s[n - 1] != '0' || s[n - 2] != '1') {
		cout << "-1" << endl;
		return 0;
	}
	for (int i = 2; i < n; ++i) {
		if (s[i - 1] != s[n - i - 1]) {
			cout << "-1" << endl;
			return 0;
		}
	}
	// 構築
	cout << "1 2" << endl;
	int on_path = 2;
	for (int i = 1; i < n - 1; ++i) {
		cout << on_path << " " << (i + 2) << endl;
		if (s[i] == '1') on_path = (i + 2);
	}
	return 0;
}

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

const int MAX_N = 2999;

int main(){
    int N; cin >> N;
    double p[MAX_N];
    for (int i = 0; i < N; i++)
    {
        cin >> p[i];
    }

    long double dp[MAX_N + 1][MAX_N + 1] = {0}; //dp[i][j] := i番目まででj枚の表のコインをだす確率
    dp[0][0] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= N; j++){
            if(j != 0)dp[i][j] = dp[i-1][j] * (1 - p[i-1]) + dp[i-1][j-1] * p[i-1];
            else dp[i][j] = dp[i-1][j] * (1 - p[i-1]);
        }
    }
    long double ans = 0;
    for(int i = (N + 2) / 2; i <= N; i++){
        ans += dp[N][i];
    }
    cout << fixed << setprecision(10) <<  ans << endl;
}

Measured memory_bytes: 141056
# GET AX
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

ac_num = 0
a = [0]*len(S)
for i in range(N-1):
	a[i] = ac_num
	if S[i] == 'A' and S[i+1] == 'C':
		ac_num += 1
a[-1] = ac_num

for l, r in lr:
	print(a[r-1] - a[l-1])

Measured memory_bytes: 30684
N = int(input())
list_candi = []
for A in range(1, N):
  B = N - A
  list_A = list(map(int, list(str(A))))
  list_B = list(map(int, list(str(B))))
  sum_list= sum(list_A) + sum(list_B)
  list_candi.append(sum_list)
print(min(list_candi))

Measured memory_bytes: 4052
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    char c;
    int num;
    bool flag;
    for(int i=0;i<10;i++){
        cin >> c;
        if(i == 5){
            num = atoi(&c);
            if(num == 1){
                flag = true;
                break;
            }
        }
        else if(i == 6){
            num = atoi(&c);
            if(num > 4){
                flag = true;
                break;
            }
            else if(num < 4){
                flag = false;
                break;
            }
        }
        else if(i == 8){
            num = atoi(&c);
            if(num <= 3){
                flag = false;
                break;
            }
        }
    }
    if(flag) cout << "TBD";
    else cout << "Heisei";
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 3005
using namespace std;

int main() {
  int d, n,s=1;
  cin >> d >> n;
  if(n == 100) {
    n = 101;
  }
  for(int i=0;i<d;i++) {
    s *= 100;
  }
  cout << n*s << endl;
  return 0;
}

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

int main() {
    long long n, c, a_, ans = 0;
    cin >> n;
    vector<int> a;
    for(int i = 0; i < n; ++i) {
        cin >> a_;
        a.push_back(a_);
        a.push_back(a_-1);
        a.push_back(a_+1);
    }
    sort(a.begin(), a.end());
    c = 0;
    for(int i = 0; i < a.size()-1; ++i) {
        if(a[i] == a[i+1]) {
            c++;
            if(c > ans) ans = c;
        } else {
            c = 0;
        }
    }
    cout << ans+1 << endl;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,m,i,temp,l,r,sum=0;
    cin>>n>>m;
    ll pre[n+5]={};
    vector<ll> arr;
    map<ll,ll> m1;
    vector<pair<ll,ll> > v;
    for(i=0;i<n;i++){
        cin>>temp;
        arr.push_back(temp);
    }
    sort(arr.begin(),arr.end());
    for(i=0;i<m;i++){
        cin>>l>>r;
        m1[l]+=r;
        v.push_back(make_pair(r,l));
    }
    sort(v.rbegin(),v.rend());
    temp=0;
    for(i=0;i<n;i++){
        if(temp>=m)
            sum+=arr[i];
        else{
            sum+=max(arr[i],v[temp].first);
            v[temp].second-=1;
            if(v[temp].second==0)
                temp+=1;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 7280
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);

        int N;
        N = sc.nextInt();
        int num_group=0;
        int num_ma=0;
        num_ma = N/3;
        System.out.println(num_ma);
    }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    cout << d.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits>
#include <cfenv>
#include <cmath>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <list>
#include <random>
#include <functional>


#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

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;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


constexpr int N = 1000;
constexpr int mod = 1e9 + 7;
std::array<std::array<lli, N + 1>, N + 1> A;
std::array<lli, N+1> F, invF;

lli power(lli a, int n = mod - 2){
    if(n == 0) return 1;
    lli p = power(a * a % mod, n / 2);
    if(n & 1) return (p * a) % mod;
    return p;
}

/* n人でp人グループを k 個作る分け方は
    nCpk * pkCp * (k-1)pCp * ... * pCp / k!
    = {n!/(n-pk)!pk!} * {pk!/(k-1)p!p!} * {(p-1)k!/(k-2)p!p!} * ... * pCp / k!
    = {n!/(n-pk)!pk!} * pk! / (p!)^k / k!
    = n! / { (n - pk)! * (p!)^k * k! }
*/

int main(void){
    int n, a, b, c, d; scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
    F[0] = 1; for(int x = 1; x <= n; ++x) F[x] = (F[x-1] * x) % mod;
    invF[n] = power(F[n]);
    for(int x = n; x > 0; --x) invF[x-1] = (invF[x] * x) % mod;

    int bMa = b - a;
    A[0][0] = 1;
    for(int i = 0; i <= bMa; ++i){
        int p = a + i;
        for(int j = 0; j <= n; ++j){
            (A[i+1][j] += A[i][j]) %= mod;

            for(int k = c; k <= d and j + k * p <= n; ++k){
                lli c = F[j + k * p] * invF[j] % mod; (c *= invF[k]) %= mod;
                (c *= power(power(F[p], k))) %= mod;
                (A[i + 1][j + k * p] += c * A[i][j]) %= mod;
            }
        }
    }

    printf("%lld\n", A[bMa+1][n]);
    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N, i = 0, a, b;
  cin >> N;
  vector<ll> p(N), q(N), v(N);
  rep(i, N) cin >> p[i];
  rep(i, N) cin >> q[i];
  iota(v.begin(), v.end(), 1);
  do {
    // for (auto x : v)
    //  cout << x << " ";
    // cout << "\n";
    if (v == p)
      a = i;
    if (v == q)
      b = i;
    i++;
  } while (next_permutation(v.begin(), v.end()));
  cout << abs(a - b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

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

const ll mod = static_cast<ll>(1e9) + 7;

int main()
{
    ll X;
    cin >> X;

    ll ans = 0;
    ans += (X / 500LL) * 1000LL;
    ans += ((X % 500LL) / 5LL) * 5LL;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int INF = 1<<29;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b || b==c || c==a){
		if(a==b && a==c)cout<<1<<endl;
		else cout<<2<<endl;
	}else{
		cout<<3<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
using ll = long long;
int main(){
	ll n,w;
  	scanf("%lld%lld",&n,&w);
  	vector<ll> we(n);
  	vector<ll> val(n);
	ll su=0;
  	for(int i=0;i<n;i++){
  		scanf("%lld%lld",&we[i],&val[i]);
    	su+=val[i];
    }
  
    vector<ll> dp1(su+1,1e18L+5);
    dp1[0]=0;
    for(int i=0;i<n;i++){
     	for(int j=su;j>=0;j--){
      		if(j>=val[i]) dp1[j]=min(dp1[j-val[i]]+we[i],dp1[j]);
     	}
    }

	ll answer = 0;
   	for(int i=0;i<=su;i++) {
        if(dp1[i]<=w) answer=max(answer,(ll) i);
   	}
   	printf("%lld\n", answer);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=200010;
int n,a[maxn]; ll ans;
int gcd(int x,int y) {
	if (!x||!y) return x+y;
	return gcd(y,x%y);
}
bool ck() {
	int flag=0; ans=0;
	for (int i=1;i<=n;i++) ans+=a[i];
	if ((ans-n)%2==1) return 1;
	for (int i=1;i<=n;i++)
		if ((a[i]&1)&&a[i]>1) {
			if (flag) return 0;
			flag=1; a[i]--;
		}
	if (!flag) return 0;
	int g=a[1];
	for (int i=2;i<=n;i++) g=gcd(g,a[i]);
	for (int i=1;i<=n;i++) a[i]/=g;
	return ck()^1;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(a[i]);
	if (ck()) printf("First\n");
	else printf("Second\n");
	return 0;
}

Measured memory_bytes: 640
N = int(input())
S = input()
alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def get_str_leading_n(string, alphabets, N):
    index_ = (alphabets.index(string.upper()) + N) % 26
    return alphabets[index_]
output = "".join(list(map(lambda p: get_str_leading_n(p, alphabets, N), S)))
print(output)


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

int main() {
	int n;cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;++i)cin>>a[i];
	int m;cin>>m;
	vector<int> b(m);
	for(int i=0;i<m;++i)cin>>b[i];

	vector<int> ans;
	set_intersection(begin(a),end(a),begin(b),end(b),inserter(ans, end(ans)));

	for(auto &&ai: ans){
		cout<<ai<<endl;
	}
  return 0;
}



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

using namespace std;

#define int long long
#define M 1000000007

signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	double d,t,s;
	cin >> d >> t >> s;
	if(d/s<=t){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
} 

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main()
{
        int a,b;
        cin >>a>>b;
        int one;
if(a>= 1)
{
  one =0;
        for(int i = (a-1); i>0; i--)
        {
                one += i;
        }
}
  else 
  {
    one = 0;
  }
        int sec=0;
  if(b >= 1)
  {
        for(int i = (b-1); i > 0;i--)
        {
                sec+= i;
        }
  }
  else 
  {
    sec = 0;
  }
        int ans = one + sec;
        cout << ans<< endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
string s;
int a,b,c,d,e[2]={1,-1};
int main()
{
	cin>>s;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			for(int k=0;k<2;k++)
			{
				int x=b*e[i],y=c*e[j],z=d*e[k];
				if((x+y+z+a)==7)
				{
					cout<<a;
					if(i==0)
					{
						cout<<'+';
					}
					cout<<x;
					if(j==0)
					{
						cout<<'+';
					}
					cout<<y;
					if(k==0)
					{
						cout<<'+';
					}
					cout<<z<<"=7"<<endl;
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<cmath>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define DBG cout << '!' << endl;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n;
	ll ans = 0;
	cin >> n;
	
	REP(i,n)
	{
		int a,b;
		cin >> a >> b;
		ans += b - a + 1;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
public class B{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        double[] ta = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        double t = ta[0]; double a = ta[1];
        List<double> h = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
        
        for (int i = 0;i<n;i++){
            h[i]*=-0.006; h[i] += t;
        }
        
        double diff = 10000;
        int ans = -1;
        for (int i = 0;i<n;i++){
            if (diff > a-h[i] & diff > h[i]-a){
                ans = i;
                diff = Math.Abs(a-h[i]);
            }
        }
        
        Console.WriteLine(ans+1);
    }
}


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

#define endl '\n'
#define all(x) (x).begin(),(x).end()

namespace atcoder {
	using intv = vector<int>;
	using charv = vector<char>;
	using boolv = vector<bool>;
	using floatv = vector<float>;
	using doublev = vector<double>;
	using stringv = vector<string>;

	template<typename T>
	void sort(vector<T>& v){
		sort(all(v));
	}
	template<typename T>
	void sortInv(vector<T>& v){
		sort(all(v), greater<T>());
	}

	template<typename T>
	T sum(const vector<T>& v){
		T ret = 0;
		for(const auto& e : v) ret += e;
		return ret;
	}

	template<typename T>
	inline vector<T>& operator+=(vector<T>& v, const T e){
		v.push_back(e);
		return v;
	}

	template<typename T>
	void in(vector<T>& v){
		for(auto& e : v) cin >> e;
	}

	template<typename T>
	istream& operator>>(istream &stream, vector<T>& v){
		for(auto& e : v) stream >> e;
		return stream;
	}

	template<typename T>
	void out(const vector<T>& v){
		for(const auto& e : v) cout << e << ' ';
		cout << endl;
	}

	template<typename T>
	void outln(const vector<T>& v){
		for(const auto& e : v) cout << e << endl;
	}

	void inline init(){
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}

using namespace atcoder;

int main(){
	init();

	int N;
	cin >> N;
	cout << ((N%10==7||(N/10)%10==7||N/100==7)?"Yes":"No") << endl;
}

Measured memory_bytes: 3612
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	String a = sc.next();
    a=a.replace(","," ");
    System.out.println(a);
  }
}

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

#define pb push_back
#define PQ priority_queue
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

typedef long long ll;
typedef long double ld;

//__builtin_popcount(x)

using namespace std;

/*const int mod = 1e9 + 7;

ll add(ll a, ll b) {
    ll res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

ll sub(ll a, ll b) {
    ll res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

ll mul(ll a, ll b) {
    return (((a % mod) * (b % mod)) % mod);
}

int powm(int a, long long n) {
	if (n == 0) {
		return 1;
	}
	else if (n & 1) {
		return mul(a, powm(a, n - 1));
	}
	else {
		return powm(mul(a, a), n / 2);
	}
}*/

/* Z-FUNCTION
ll l = 0, r = 0, n = (int)s.size();
vector<int> z(n, 0);
for (int i = 1; i < n; i++) {
    if (r >= i) {
        z[i] = min(1ll*z[i-l], r-i+1);
    }
    while (z[i] + i < n && s[z[i]] == s[z[i] + i]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
}
*/

/*vector<ll> find_dividers(ll x) {
    vector<ll> dividers;

    for (ll i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
           dividers.push_back(i);
            if (1ll*i * i != x) {
                dividers.push_back(1ll*x / 1ll*i);
            }
        }
    }

    return dividers;
}*/

/*int nok(int a, int b) {
    return a / __gcd(a, b) * b;
}*/

// ceil(a/b) = (a+b-1)/b

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> vp;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        vp.pb({x, y});
    }

    bool ok = false;
    for (int i = 0; i < n; i++) {
        if (i + 2 < n && vp[i].first == vp[i].second && vp[i+1].first == vp[i+1].second &&
            vp[i + 2].first == vp[i+2].second) {
                ok = true; break;
            }
    }

    ok ? puts("Yes") : puts("No");

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(10);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x);
#define PUT(x) cout << x << endl
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };


int main(void)
{

	string answer = "AKIHABARA";

	//状態機械による遷移を考える。
	string input;
	cin >> input;
	int n = input.size(), j = 0;

	if (answer.size() < n) {
		cout << "NO" << endl;
		return 0;
	}

	for (int i = 0; i < n; i++) {

		if (j >= answer.size()) {
			cout << "NO" << endl;
			return 0;
		}

		cerr << i << " " << j << endl;

		if (answer[j] == input[i]) {
			j++;
		}
		else {
			if (answer[j] == 'A') {
				j++;
				i--;
			}
			else {
				cout << "NO" << endl;
				return 0;
			}
		}

	}

	if(j >= 8)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll N, A, B;
	cin >> N >> A >> B;
	ll ans = N / (A + B) * A;
	N %= (A + B);
	ans += min(N, A);
	cout << ans << endl;
}


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

#define ll long long int

int main() {
  int n;
  scanf("%d", &n);
  ll *a = malloc(sizeof(ll) * n);
  int i, j;
  for(i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  j = 0;
  ll type[3] = {0};
  ll count[3] = {0};
  int ans = 1;
  for(i = 0; i < n; i++) {
    if((j == 0)
    || (j == 1 && type[0] != a[i])
    || (j == 2 && type[0] != a[i] && type[1] != a[i])) {
      type[j] = a[i];
      count[j]++;
      j++;
    } else if(j == 3 && type[0] != a[i] && type[1] != a[i] && type[2] != a[i]) {
      ans = 0;
      break;
    } else {
      if(type[0] == a[i])      count[0]++;
      else if(type[1] == a[i]) count[1]++;
      else                     count[2]++;
    }
  }
  // for(i = 0; i < 3; i++) printf("%lld\n", count[i]);
  if(ans == 1) {
    ans = 0;
    if((count[0] == count[1] && count[1] == count[2] && (type[0] ^ type[1]) == type[2])
    || (type[0] == 0 && type[2] == 0 && count[0] * 2 == count[1])
    || (type[1] == 0 && type[2] == 0 && count[1] * 2 == count[0])
    || (type[0] == 0 && type[1] == 0 && type[2] == 0)) ans = 1;
  }
  if(ans == 1) printf("Yes\n");
  else         printf("No\n");
  return 0;
}

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

int main() {
	int N, A[100000], ans = 1, check = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N - 1; i++) {
		if (A[i] < A[i + 1] && check == -1) {
			ans++;
			check = 0;
		}
		else if (A[i] > A[i + 1] && check == 1) {
			ans++;
			check = 0;
		}
		else if (A[i] < A[i + 1] && check == 0) check = 1;
		else if (A[i] > A[i + 1] && check == 0) check = -1;
	}
	cout << ans;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

string convert(int n){ 
        string s = ""; 
        while(n){
                s += n%8 + '0';
                n /= 8;
        }   
        string _s = ""; 
        for(int i = s.size()-1; i >= 0; i--){
                char c = s[i];
                if(c >= '4') c++;
                if(c >= '6') c++;
                _s += c;
        }   
        return _s; 
}

int main(){
        int n;
        cin >> n;
        while(n){
                cout << convert(n) << endl;
                cin >> n;
        }   
}

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

typedef long long ll;

using namespace std;
const int INF = 1e9 + 5;

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> h(n);
	for(int &i : h)
	{
		cin >> i;
	}
	vector<int> dp(n,INF);
	dp[0] = 0;
	for(int i = 0 ; i < n ; i++)
	{
		for (int j  = i +1 ;j  <= i + k ; j++ )
		{
			if (j < n)
				dp[j] = min(dp[j],dp[i] + abs(h[i] - h[j]));
		}
	}
	cout << dp[n-1];
}


Measured memory_bytes: 4044
n = int(input())
C = []
S = []
F = []

for i in range(n - 1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for start in range(n - 1):
    t = 0

    for i in range(start, n - 1):
        if S[i] <= t:
            t = F[i] * (t // F[i] + (t % F[i] != 0))
        else:
            t = S[i]

        t += C[i]

    print(t)

print(0)

Measured memory_bytes: 3064
#include<stdio.h>
long mod=1000000007;
int main(void){
  int n,k;
  scanf("%d%d",&n,&k);
  //前提:個数の違う組み合わせなら重複はしない
  //個数同じ時:最大値-最小値+1でおｋ
  long total=0;
  long max=0,min=0;
  for(int i=0;i<k;i++){
	min+=i;
    max+=n-i;
  }
  total+=max-min+1;
  for(int j=k;j<=n;j++){
	min+=j;
    max+=n-j;
    total+=max-min+1;
  }
  printf("%ld",total%mod);
  return 0;
}

Measured memory_bytes: 1732
#include<stdio.h>

int main(void)
{
  int flag=0;
  char S[7];
  
  scanf("%s",S);
  if(S[2]==S[3])
    if(S[4]==S[5])
      flag=1;
  if(flag)
    printf("Yes");
  else 
    printf("No");
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;

int main(){
  string S;
  cin >> S;
  string ans;
  
  for( int i=0; i<3; i++ ){
    if( S.at(i) == S.at(i+1) ){
      ans = "Bad";
      break;
    }else ans = "Good";
  }
  cout << ans;
  return 0;
}


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

int main(){
  int a[3][3];
  rep(i,0,3){
    rep(j,0,3){
      cin>>a[i][j];
    }
  }
  bool b[3][3];
  rep(i,0,3){
    rep(j,0,3){
      b[i][j]=false;
    }
  }
  int n;
  cin>>n;
  rep(i,0,n){
    int c;
    cin>>c;
    rep(j,0,3){
      rep(k,0,3){
        if(a[j][k]==c) b[j][k]=true;
      }
    }
  }
  bool p=false;
  rep(i,0,3){
    if(b[i][0]==true && b[i][1]==true && b[i][2]==true) p=true;
  }
  rep(i,0,3){
    if(b[0][i]==true && b[1][i]==true && b[2][i]==true) p=true;
  }
  if(b[0][0]==true && b[1][1]==true && b[2][2]==true) p=true;
  if(b[2][0]==true && b[1][1]==true && b[2][0]==true) p=true;
  if(p) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string S;
  ll K;
  cin >> S >> K;
  vector<ll> cnt;

  if(S.length() > 1){
    ll tmp = 1;
    for(int i = 0; i < S.length()-1; i++){
      if(S[i] == S[i+1]){
        tmp++;
      }else{
        cnt.push_back(tmp);
        tmp = 1;
      }
    }
    if(tmp > 1){
      cnt.push_back(tmp);
    }
  }

  if(S.length() == 1){
    cout << K / 2 << endl;
  }else if(cnt.size() == 1){
    cout << K * S.length() / 2 << endl;
  }else if(S[0] == S[S.length()-1] && (cnt[0] + cnt[cnt.size()-1])%2==0){
    
    ll ans_base = 0;
    for(int i = 1; i < cnt.size()-1; i++){
      ans_base += cnt[i]/2;
    }

    ll ans = 0;
    ans = ans_base * K;
    ans += cnt[0]/2;
    ans += cnt[cnt.size()-1]/2;

    ans += (K-1) * ((cnt[0] + cnt[cnt.size()-1])/2);
    
    cout << ans << endl;
  }else{
    ll ans_base = 0;
    for(int i = 0; i < cnt.size(); i++){
      ans_base += cnt[i]/2;
    }

    ll ans = 0;
    ans = ans_base * K;

    cout << ans << endl;
  }

  

  return 0;
}


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

namespace msolutions2020
{
    class SolverC
    {
        static void Main()
        {
            Solve();
        }

        public static void Solve()
        {
            SetOut(new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false});
            var _nk = ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
            (int N, int K) = (_nk[0], _nk[1]);
            int[] A = ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
            for (int i=K; i<N; i++)
            {
                WriteLine(A[i-K] < A[i] ? "Yes" : "No");
            }
            Out.Flush();
        }
    }
}


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

int main()
{
	int N, D = 0;
	cin >> N >> D;
	int res = N / (2 * D + 1);
	int mod = N % (2 * D + 1);
	int ans = (mod == 0) ? res : res + 1;

	cout << ans;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

#define ll long long

int N, Y;

bool solve(){
    int diff = N * 10000 - Y; //全て1万円だった時との差分

    if(diff < 0) return false; //減らせないので無理

    for(int z = 0; z <= N; z++){
        int diff_buff = diff - 9000*z;
        int y = diff_buff / 5000;
        if(diff_buff % 5000 == 0 && 0 <= y && y <= N - z){
            cout << N - (y+z) << " " << y << " " << z << endl;
            return true;
        }
    }

    return false;
}

int main(){
    cin >> N >> Y;

    if(!solve()) cout << "-1 -1 -1" << endl;
}


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

int main(){
  long long int N, K;
  
  cin >> N >> K;
  
  vector<long long int> cnt(1e5 + 1);
  for(int i = 0;i < N;i++){
    int a, b;
    cin >> a >> b;
    cnt.at(a) += b;
  }
  
  for(int i = 1;;i++){
    if(K <= cnt.at(i)){
      cout << i << endl;
      return 0;
    }
    K -= cnt.at(i);
  }
  
  return 0;
}

Measured memory_bytes: 4040
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(ll a=b;a<=c;a++)
#define PER(a,b,c) for(ll a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<ll,ll>
#define pii pair<pair<ll,ll>,ll>
using namespace std;
const ll MAXN=1e6+5;
ll n,m,t;
ll f(ll x){
    return x*x*x*x*x;
}
int main(){
    cin>>n;
    pi ans;
    REP(i,-1000,1000){
        REP(j,-1000,1000){
            if(f(i)-f(j)==n){
                ans={i,j};
            }
        }
    }
    cout<<ans.first<<' '<<ans.second;
}

Measured memory_bytes: 3184
# Treap
#平衡二分木　乱数を用いてできるだけ平衡を保つらしい　
#priorityには乱数を入れること
# d = 0: right rotation
# d = 1: left rotation
def rotate(nd, d):
    c = nd[d]
    if d:
        e = c[1]
        nd[1] = c[0]
        c[0] = nd
    else:
        e = c[0]
        nd[0] = c[1]
        c[1] = nd

    r = c[4] = nd[4]
    nd[4] = r - (e[4] if e else 0) - 1
    return c

root = None
def insert(val, pri):
    global root
    st = []
    dr = []
    x = root
    while x:
        st.append(x)
        if x[2] == val:
            return
        d = (x[2] < val)
        dr.append(d)
        x = x[d]

    # [<left>, <right>, <key>, <priority>, <count>]
    nd = [None, None, val, pri, 1]
    while st:
        x = st.pop(); d = dr.pop()
        x[d] = nd
        x[4] += 1
        if x[3] >= nd[3]:
            break
        rotate(x, d)
    else:
        root = nd

    for x in st:
        x[4] += 1

def __delete(nd):
    st = []; dr = []
    while nd[0] or nd[1]:
        l = nd[0]; r = nd[1]
        d = (l[3] <= r[3]) if l and r else (l is None)
        st.append(rotate(nd, d))
        dr.append(d ^ 1)
    nd = x = None
    while st:
        nd = x; x = st.pop(); d = dr.pop()
        x[d] = nd
        x[4] -= 1
    return x

def delete(val):
    global root
    x = root

    st = []
    y = None
    while x:
        if val == x[2]:
            break
        y = x; d = (x[2] < val)
        st.append(y)
        x = x[d]
    else:
        return

    if y:
        y[d] = __delete(x)
        for x in st:
            x[4] -= 1
    else:
        root = __delete(x)

def find(val):
    global root
    x = root
    while x:
        if val == x[2]:
            return 1
        x = x[x[2] < val]
    return 0

def search1(val):
    global root
    x = root
    ans=-1
    while x:
        if val==x[2]:
            return val
        if val>x[2]:
            ans=max(ans,x[2])
            if x[1]==None:
                return ans
            else:
                x=x[1]
        if val<x[2]:
            if x[0]==None:
                return ans
            else:
                x=x[0]
    return ans

def search2(val):
    global root,N
    x=root
    ans=N
    while x:
        if val==x[2]:
            return val
        if val>x[2]:
            if x[1]==None:
                return ans
            else:
                x=x[1]
        if val<x[2]:
            ans=min(ans,x[2])
            if x[0]==None:
                return ans
            else:
                x=x[0]
    return ans

import random

N=int(input())
P=list(map(int,input().split()))
dic={key:-1 for key in range(1,N+1)}
for i in range(0,N):
    dic[P[i]]=i

answer=0
for i in range(0,N):
    k=N-i
    l1=search1(dic[k])
    l2=search1(l1-1)
    r1=search2(dic[k])
    r2=search2(r1+1)
    answer+=k*(dic[k]-l1)*(r2-r1)+k*(l1-l2)*(r1-dic[k])
    insert(dic[k],random.randint(1,100000))

print(answer)

Measured memory_bytes: 105576
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long L = Integer.parseInt(sc.next());
        long R = Integer.parseInt(sc.next());
        
        if(L % 2019 == 0) {
            System.out.println(0);
        }else if(R - L >= 2019) {
            System.out.println(0);
        }else {
            long min = 2018;
            for(long i = L; i < R; i++) {
                for(long j = L+1; j <= R; j++) {
                    if((i%2019)*(j%2019) % 2019 == 0) {
                        min = 0;
                        break;
                    }else {
                        if(min > (i%2019)*(j%2019) % 2019) {
                            min = (i%2019)*(j%2019) % 2019;
                        }
                    }
                }
            }
            
            System.out.println(min);
        }
    }
}

Measured memory_bytes: 22996
a,b,c,d=map(int,input().split())
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
g=lcm(c,d)
c_div=b//c-(a-1)//c
d_div=b//d-(a-1)//d
cd_div=b//g-(a-1)//g
print(b-a+1-c_div-d_div+cd_div)


Measured memory_bytes: 5104
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
#define test ll t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define pop pop_back
#define int long long int
#define mod 1000000007
#define inf 1LL<<60

struct flower{
int hi;
int bty;
};
int solve(vector<flower>& v,int n)
{
    vector<int>dp(n+1);
    map<int,int>meaningful;
    dp[1]=v[1].bty;
    int ans = dp[1];
    meaningful[v[1].hi] = dp[1];

    for(int i=2;i<=n;i++)
    {
        dp[i] = v[i].bty;
         auto it = meaningful.lower_bound(v[i].hi+1);

         if(it!=meaningful.begin())
         {
             it--;
             dp[i]+= it->second;
         }
         meaningful[v[i].hi] = dp[i];

         it = meaningful.upper_bound(v[i].hi);

         while(it!=meaningful.end() && it->second<=dp[i])
         {
             auto temp = it;
             temp++;
             meaningful.erase(it);

             it = temp;
         }
        ans = max(ans,dp[i]);
    }

    return ans;
}
int32_t main()
{
	fast;
	int n;
    cin>>n;

    vector<flower>v(n+1);

    for(int i=1;i<=n;i++)
        cin>>v[i].hi;

    for(int i=1;i<=n;i++)
        cin>>v[i].bty;

    cout<<solve(v,n);

	return 0;
}



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

int main(){
    int n; cin >> n;
    string a,b,c; cin >> a >> b >> c;
    int ans = 0;
    for(int i=0;i<n;i++){
        if(a[i]==b[i] && c[i] == a[i]) ans += 0;
        else if(a[i] == b[i] || c[i] == a[i] || b[i]==c[i]) ans += 1;
        else ans+= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
macro_rules! fn_memo{
    ($fun:ident : $memo:ident ( $($param:ident : usize),* ) -> $out:ty $body:block) => {
        fn $fun($memo:&mut memo_inner!(type $out; $($param),*), $($param : usize),*) -> $out $body
    };
    ($fun:ident : $memo:ident ( $($eparam:ident : $epty:ty),* ; $($param:ident : usize),* ) -> $out:ty $body:block) => {
        fn $fun($memo:&mut memo_inner!(type $out; $($param),*), $($eparam:$epty),* , $($param : usize),*) -> $out $body
    };
}
macro_rules! memo{
    ($fun:ident : $memo:ident ( $($inf_arg:expr),* ) -> $out:ty) => {
        let mut $memo = &mut memo_inner!(vec $out; $($inf_arg),*);
    };
}
macro_rules! memo_inner {
    (type $out:ty ; $param:ident) => {
        Vec<Option<$out>>
    };
    (type $out:ty ; $param:ident, $($p:ident),*) => {
        Vec<fn_vec!($out; $($p),*)>
    };
    (vec $out:ty; $marg:expr) => {
        vec![None as Option<$out>; $marg]
    };
    (vec $out:ty; $marg:expr, $(m:expr),*) => {
        vec![memo!($out; $($m),*); $marg]
    };
}
macro_rules! get{
    ($fun:ident : $memo:ident ( $($arg:expr),* )) => {{
        if $memo$([$arg])*.is_none() {
            $memo$([$arg])* = Some($fun($memo, $($arg),*));
        }
        $memo$([$arg])*.unwrap()
    }};
    ($fun:ident : $memo:ident ( $($earg:expr),* ; $($arg:expr),* )) => {{
        if $memo$([$arg])*.is_none() {
            $memo$([$arg])* = Some($fun($memo, $($earg),* , $($arg),*));
        }
        $memo$([$arg])*.unwrap()
    }};
}

fn main(){
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf);
    let mut sw = buf.split_whitespace();
    
    let n: usize = sw.next().unwrap().parse().ok().unwrap();
    let m: usize = sw.next().unwrap().parse().ok().unwrap();
    let mut broken = vec![false; n+1];
    for _ in 0..m {
        let a:usize = sw.next().unwrap().parse().ok().unwrap();
        broken[a] = true;
    }
    let broken = broken;
    
    memo!{ solve:sm(100_001) -> u64 };
    println!("{}", get!{ solve:sm( &broken; n ) });
}

fn_memo!{ solve:sm( broken: &Vec<bool>; n:usize ) -> u64 {
    if broken[n] {
        0
    } else if n <= 1 { 
        1
    } else {
        ((get!{solve:sm(broken; n-1)}) + (get!{solve:sm(broken; n-2)})) % 1_000_000_007
    }
}}



Measured memory_bytes: 11004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N, A, ans;
    double T, temp, min = 1000;
    cin >> N >> T >> A;
    double H[1000];
    for(int i=0;i<N;i++)
        cin >> H[i];

    for(int i=0;i<N;i++){
        temp = T - H[i]*0.006;
        if(abs(A - temp) < min){
            min = abs(A - temp);
            ans = i+1;
        }            
    }
    
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> w(n);
    int ans = 0;
    for(auto& i : w)
    {
        cin >> i;
        ans += i;
    }
    for (int i = 1; i < n; ++i)
    {
        int aux1 = 0, aux2 = 0;
        for(int k = 0; k < i; ++k) aux1 += w[k];
        for(int k = i; k < n; ++k) aux2 += w[k];
        ans = min(ans, abs(aux1 - aux2));
    }
    cout << ans << endl;
}

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

int main(void)
{
    char m[2], d[2];
    scanf("2019/%s/%s", m, d);
    int counter = 0;
    int month = atoi(m);
    int day = atoi(d);
    if (month > 4)
    {
        counter++;
    }
    else if (month == 4 && day == 30)
    {
        counter++;
    }
    if (counter > 0.5)
    {
        printf("TBD\n");
    }
    else
    {
        printf("Heisei\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
int a[101][101],b[101];
int n,m,c;
int ans;
int sum;
int main()
{
	cin>>n>>m>>c;
	for(int i=1;i<=m;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++)
	{
		sum=0;
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
			sum+=a[i][j]*b[j]; 
		} 
		sum+=c;
		if(sum>0)
			ans++; 
	} 
	cout<<ans;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)
from collections import deque

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, M = MI()
adj = [list() for _ in range(N)]
for _ in range(M):
    u, v = map(lambda s: int(s) - 1, sys.stdin.readline().split())
    adj[u].append(v)
S, T = map(lambda s: int(s) - 1, sys.stdin.readline().split())

q = deque([(0, S, 0)])
seen = {S}
while len(q) > 0:
    dim, v, cnt = q.popleft()
    if v == T and dim == 0:
        print(cnt // 3)
        exit(0)
    ndim = (dim + 1) % 3
    for nxt in adj[v]:
        if (ndim * N + nxt) not in seen:
            q.append((ndim, nxt, cnt + 1))
            seen.add(ndim * N + nxt)
print(-1)

Measured memory_bytes: 72056