akhauriyash/Code-Regression huggingface dataset:
#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++)

using ll = long long;

int main(){
  int n;
  cin>>n;
  vector<int> a(n+2);
  ll sum = 0;
  a.at(0) = 0;
  a.at(n+1) = 0;
  rep(i,n){
    cin >> a.at(i+1);
    sum += abs(a.at(i+1)-a.at(i));
  }
  sum += abs(a.at(n));
  rep1(i,n){
    ll ans = sum;
    //a.at(i)のルートを飛ばす。
    if(a.at(i-1)<a.at(i)&&a.at(i)>a.at(i+1)){
      ans += (abs(a.at(i+1)-a.at(i-1))-(a.at(i)-a.at(i-1))-(a.at(i)-a.at(i+1)));
    }else if(a.at(i-1)>a.at(i)&&a.at(i)<a.at(i+1)){
      ans += (abs(a.at(i+1)-a.at(i-1))+(a.at(i)-a.at(i-1))+(a.at(i)-a.at(i+1)));
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;} template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

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

int main() {
    while(1){
	int n,m;cin >>n>> m;
	if(n==0 && m==0) return 0;
	vector<long long> C(m),v(n);
	for(int i=0;i<m;i++) cin >> C[i];
	for(int i=0;i<n;i++) cin >> v[i];
	vector<vector<long long> > dp(n+1,vector<long long>(256));
	rep(i,n+1)rep(j,256) dp[i][j] = inf;
	dp[0][128] = 0;
	for(int i=0;i<n;i++){
	    for(int j=0;j<=255;j++){
		for(int k=0;k<C.size();k++){
		    if(dp[i][j] == inf) continue;
		    if((j+C[k])<0){
			chmin(dp[i+1][0],dp[i][j]+v[i]*v[i]);
		    }else if((j+C[k])<256){ chmin(dp[i+1][j+C[k]],dp[i][j]+(v[i]-(j+C[k]))*(v[i]-(j+C[k])));
			/*
			if(i==0){
			cout << "j=" <<j << endl;
			cout << "dp[i][j]=" << dp[i][j] << endl;
			cout << "dp[i][j]+(v[i]-(j+C[k]))*(v[i]-(j+C[k])) =" << dp[i][j]+(v[i]-(j+C[k]))*(v[i]-(j+C[k])) << endl;
		    
			}
			*/
		    }else chmin(dp[i+1][255],dp[i][j]+(v[i]-255)*(v[i]-255));
		}	
	    }
	}
	/*
	for(int i=0;i<=n;i++){
	    for(int j=0;j<=255;j++){
		cout << dp[2][j] << " " ;
	    }
	    cout << endl;
	}
	*/
	long long  ans = inf;
	for(int i=0;i<256;i++) chmin(ans,dp[n][i]);
	cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 43720
#include <stdio.h>
#include <limits.h>
 
int a[2005];
int b[2005];
long long c[2005];
long long d[1005];
int fn[1005];
 
int main(){
    int n,m,i,j;

    scanf("%d %d",&n,&m);
 
    for(i=0;i<m;i++){
        scanf("%d %d %lld",&a[i],&b[i],&c[i]);
        a[i]--;
        b[i]--;
        c[i]=-c[i];
    }
 
    for(i=0;i<n;i++){
        d[i]=LLONG_MAX;
    }
    d[0]=0ll;
 
    for(i=0;i<n-1;i++){
        for(j=0;j<m;j++){
            if(d[a[j]]==LLONG_MAX) continue;
            if(d[b[j]]>d[a[j]]+c[j]) d[b[j]]=d[a[j]]+c[j];
        }
    }
 
    long long ans=d[n-1];
 
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            if(d[a[j]]==LLONG_MAX) continue;
            if(d[b[j]]>d[a[j]]+c[j]){
                d[b[j]]=d[a[j]]+c[j];
                fn[b[j]]=1;
            }
            if(fn[a[j]]==1) fn[b[j]]=1;
        }
    }
 
    if(fn[n-1]==1) printf("inf\n");
    else printf("%lld\n",-ans);
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

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

    for (int i = 0; i < S.size() - 1; i++) {
        if (S.substr(i, 2) == "AC") {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#from collections import *
from itertools import *
#from bisect import *
#from heapq import *
#import copy
#N=int(input())
#X,Y=map(int,input().split())
#S=list(map(int,input().split()))
#S=[list(map(int,input().split())) for i in range(N)]
#import math
S=input()

K=len(S)
for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        K=min(K,max(i+1,len(S)-(i+1)))
print(K)


Measured memory_bytes: 40176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		int train = 0;
		int bus = 0;
		if (a<b) {
			train = a;
		}
		else {
			train = b;
		}
		if (c<d) {
			bus = c;
		}
		else {
			bus = d;
		}
		
		System.out.println(train+bus);
		
		sc.close();
	}

}


Measured memory_bytes: 23252
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int main(){
    fastIO;
    int n;
    cin >> n;
    ll x[n], y[n];
    for(int i = 0 ; i < n; i ++ ){
        cin >> x[i] >> y[i];
    }
    int mx = 0;
    ll p, q;
    int cur;
    for(int i = 0 ; i < n; i ++ ){
        for(int j = 0 ; j < n ; j ++ ){
            if(i == j)
                continue;
            p = x[i] - x[j];
            q = y[i] - y[j];
            cur = 0;
            for(int t = 0 ; t < n ; t ++ ){
                for(int z = 0 ; z < n ; z ++ ){
                    if(t != z){
                        if(x[z] - x[t] == p && y[z] - y[t] == q){
                            cur ++ ;
                        }
                    }
                }
            }
            mx = max(mx, cur);
        }
    }
    cout << n - mx;
    return 0;
}


Measured memory_bytes: 256
input()
w=list(map(int,input().split()))
x=min(w)
m={k:v for k,v in zip(sorted(w),w)if k!=v}
l=list(m.keys())
p=[]
while l:
 a=l.pop();b=m[a];l.remove(b)
 if a==m[b]:p+=[[a,b]]
 else:
  t=[b]
  while 1:
   c=m[b];t+=[c]
   if c==a:p+=[t];break
   else:b=c;l.remove(c)
n=0
for s in p:
 n+=sum(s);t=len(s);y=min(s)
 if t>2:n+=min((t-2)*y,y+(t+1)*x)
print(n)


Measured memory_bytes: 5720
#include <vector>
#include <cstdio>
#define M(x,y)push_back(std::make_pair(x,y))
typedef std::pair<int,int>P;
main(){
	int n,x,i,q;
	P p;
	for(;scanf("%d%d",&n,&x),n;printf("%d\n",x)){
		std::vector<P>v;
		v.M(x,1);
		for(i=1;i<n;i++)
			if(p=v.back(),scanf("%d",&x),x==p.first)v.back().second++;
			else if(i&1){
				if(v.pop_back(),q=0,v.size())q=v.back().second,v.pop_back();
				v.M(x,q+p.second+1);
			}else v.M(x,1);
		for(x=i=0;i<v.size();i++)if(!v[i].first)x+=v[i].second;
	}
}

Measured memory_bytes: 1032
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout << fixed; cout << setprecision(x); cout << y;
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

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

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
int32_t main()
{
	g_b();
	string s, t; cin >> s >> t;
	int n = s.size();
	int m = t.size();
	if (s == t)
	{
		cout << "0\n";
		return 0;
	}
	int k = 0;
	int ans = 100000, c = 0;
	for (int i = 0; i < n; i++)
	{
		k = i, c = 0;
		if (n - i  >= m)
			for (int j = 0; j < m && k < n; j++)
			{

				if (s[k] != t[j])
				{
					c++;
				}
				k++;
			}
		error(c);
		if ( n - i < m) break;
		ans = min(ans, c);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3636
<?php

    // ??\???????????????????????????????????????
    while(true){

        // ??\??????????????????
        $x = intval(fgets(STDIN));

        // 0?????\????????????????????????????????????
        if($x == 0){

            break;

        // ??\???????????????????????????????´?
        }else{

            $array[] = $x;

        }
    }

    // ?????????????????°?????¨???
    $i = 1;

    // ???????????\??£???????????°?????????????????????
    foreach ($array as $result){

        if($i != count($array)){
            echo("Case " . $i . ": " . $result . "\n");
            $i++;
        }else{
            echo("Case " . $i . ": " . $result);
        }


    }
?>

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

int main(){
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if (e-a<=k){
    cout<<"Yay!";
  }
  else {
    cout<<":(";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
#ifdef LOCAL
#include "1.h"
#else
#define dbg(...) 
#endif
ll n,m,i,j,k,in,cnt = 0,l,r,u,v,x,y,tc = 1,mod = 1000000007 ,ans,inf = 1e18;
const ll  mx = 100001 ;
vector<ll> a(mx);
vector<int> dp(mx,-1);
ll foo(int src){

    if(dp[src]!=-1)
        return dp[src];
    if(src==(n-1)){
        return 0;
    }
    else{
        ll ans = inf;
        for (int i = src+1; i <= min(src+k,n-1); ++i)
        {
            ll ans_here = abs(a[src]-a[i]) + foo(i);
            dbg(ans_here , ans , src);
            ans = min(ans,ans_here);

        }
    
        return dp[src]=ans;
    }
}
void solve(){
    cin>>n>>k;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    cout<<foo(0)<<endl;
    dbg(dp,0,n);
}
signed main(){                                          //F
    clock_t time = clock();                             //A
    ios_base::sync_with_stdio(0);                       //S
    cin.tie(0);                                         //T
    cout.tie(0);                                        //I
    cerr.tie(0);                                        //O
    if(0) cin>>tc;
    while(tc--)
        solve();
    dbg("Author - Amit dwivedi");
    return 0&fprintf(stderr, "Time ::%.3lf ms.\n",((clock() - time)*1000.0)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 9216
n, m = map(int, input().split())
need = [list(map(int, input().split())) for i in range(m)]
need = sorted(need, key=lambda x: x[1])

ans = 1
stock = need[0][1]
for i in range(m):
  if stock <= need[i][0]:
    ans += 1
    stock = need[i][1]
    
print(ans)

Measured memory_bytes: 65240
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e6+1;
int d[MAXN];
bool prime[MAXN];
int n;
 
void sieve(){
    memset(prime,true,sizeof(prime));
    for(int p=2; p*p<MAXN; p++){
        if(prime[p]){
            for(int i=p*p; i<MAXN; i+=p){
                prime[i] = false;
                d[i] = p;
            }
        }
    }
    d[1]=1;
    for(int i=2; i<MAXN; i++) if(prime[i]) d[i] = i;
}
 
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    int a[n]; for(int i=0; i<n; i++) cin >> a[i];
    int b[n]; for(int i=0; i<n; i++) b[i] = a[i];
    sieve();
    bool pairwise = true;
    map<int,int> m;
    for(int i=0; i<n; i++){
        set<int> s;
        while(a[i]>1){
            s.insert(d[a[i]]);
            a[i]/=d[a[i]];
        }
        for(auto& a : s){
            m[a]++;
            if(m[a]>1){
                pairwise = false;
                break;
            }
        }
        if(!pairwise) break;
    }
    if(pairwise) cout << "pairwise coprime" << endl;
    else{
        int curr = gcd(b[0],b[1]);
        for(int i=2; i<n; i++){
            curr = gcd(curr,b[i]);
        }
        if(curr==1) cout << "setwise coprime" << endl;
        else cout << "not coprime" << endl;
    }
}

Measured memory_bytes: 16328
#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline int
const int Mod=998244353;
int n,m,ans,fac[505000],inv[505000],sum;
I add(int &x,int y){(x+=y)>=Mod?x-=Mod:0;}
IN Plus(int x,int y){(x+=y)>=Mod?x-=Mod:0;return x;}
IN C(int x,int y){return (ll)fac[x]*inv[y]%Mod*inv[x-y]%Mod;}
IN A(int x,int y){return (ll)fac[x]*inv[x-y]%Mod;}
IN Pow(int x,int y=Mod-2){
	re res=1;
	while(y){
		if(y&1)res=(ll)res*x%Mod;
		x=(ll)x*x%Mod;
		y>>=1;
	}
	return res;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n>>m;if(n>=m)swap(n,m);
	fac[0]=1;F(i,1,m)fac[i]=(ll)fac[i-1]*i%Mod;
	inv[m]=Pow(fac[m]);FOR(i,m-1,0)inv[i]=(ll)inv[i+1]*(i+1)%Mod;	
	sum=Pow(n+1,m-n);
	FOR(k,n,0){
		if(k&1)add(ans,Mod-(ll)C(n,k)*A(m,k)%Mod*sum%Mod);
		else add(ans,(ll)C(n,k)*A(m,k)%Mod*sum%Mod);
		sum=(ll)sum*(n+1)%Mod*(m+1)%Mod;
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 7532
my $s = <STDIN>;
my @dat =  split(//,$s);
my $N =  $dat[0] ;
my $M =  $dat[1] ;
my $L =  $dat[2] ;
my $flag = 0;
if($N ==7 ){ $flag = 1;}
if($M ==7 ){ $flag = 1;}
if($L ==7 ){ $flag = 1;}
if($flag == 1){
    print "Yes";
}else{
    print "No";
}


Measured memory_bytes: 4784
S = input()
T = input()

flag = False
count = 0
while True:
    if S == T:
        flag = True
        break

    if count == len(S):
        break
    
    S = S[-1] + S[:len(S) - 1]
    count += 1

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9044
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	V := sc.nextIntSlice(N)
	C := sc.nextIntSlice(N)
	ans := 0
	for i := 0; i < N; i++ {
		if V[i] > C[i] {
			ans += V[i] - C[i]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
import sys
n,r=map(int,input().split())
roop_n=0
ans=0
min_=2019

if r-n>=2019:
    roop_n=n+2019
else:
    roop_n=r
for i in range(n,roop_n):
    for j in range(n+1,roop_n+1):
        ans=(i*j)%2019
        if min_>ans:
            min_=ans
            if ans==0:
                print(0)
                sys.exit()
print(min_)


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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> ans(3,0);
  vector<int> flg(3,0);

  bool chk = true; 

  for(int i = 0; i < m; i++){
    int tmps,tmpc;
    cin >> tmps >>  tmpc;
    // チェック済みかどうか
    if(flg[tmps-1] == 0){
      ans[tmps-1] = tmpc;
      flg[tmps-1] = 1;
    } else{
      // チェック済みなら、過去ののものと一致していたらOK
      if(ans[tmps-1] == tmpc){
        continue;
      } else { 
        chk = false;
        break;
      }
    }
  }

  // 後処理
  for(int i = 0; i < n; i++){
    // 先頭は、指定がなければ1, 1桁なら0
    if(i==0){
      if(flg[i] == 0){
        if(n==1){
          ans[i] = 0;
        } else {
          ans[i] = 1;
        }
      } else if(ans[i] == 0){
        if( n != 1){
          chk = false;
        }
      }
    } else { 
      if(flg[i] == 0){
        ans[i] = 0;
      }
    }
  }
  int result = 0;
  if(chk){
    for(int i = 0; i < n; i ++){
      result = result + ans[i]*pow(10,n-i-1);
      cerr << ans[i] << endl;
    }
  } else { 
    result = -1;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;

int cnt[100100];

int main() {
	cin >> n;
	rep(i, n) {
		cin >> cnt[i];
		cnt[i]--;
	}
	int ans = 0;
	rep(i, n - 1) {
		if (cnt[i] == i) {
			ans++;
			swap(cnt[i], cnt[i + 1]);
		}
	}
	cout << ans + (cnt[n - 1] == n - 1) << endl;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static HashMap<Long,Long>map = new HashMap<>();
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int K = nextInt();

		long ans =0;
		long min=0;
		long max=0;
		for(long i=0;i<=N;i++){

			min+=i;
			max+=N-i;
			if(i+1>=K){
				long n=max-min+1;
				ans=(ans+n)%MOD;
			}
		}
		System.out.println(ans);
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 25656
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  ll n; cin>>n; ll a[n]; ll m=1000000000000000000LL;
  for(int i=0;i<n;i++){
    cin>>a[i]; 
  }
  sort(a,a+n);
  ll product=1;
  if(a[0]==0){
    cout<<0;
  }else{
    bool b=true;
    for(int i=0;i<n;i++){
      if(product>((long double)m)/a[i]){
        b=false;
      }else{
        product*=a[i];
      }
    }
    if(b){
      cout<<product;
    }else{
      cout<<-1;
    }
  }
}


Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
string n;
int k,m;
int f(int i,int x){
    if(x==0)return 0;
    if(i>=m)return 0;
    int res=0;
    if(n[i]=='0'){
        res+=9*comb(m-i-1,x-1)*pow(9,x-1);
        return res+f(i+1,x);
    }
    else{
        res+=(9-(n[i]-'0'))*comb(m-i-1,x-1)*pow(9,x-1);
        return res+f(i+1,x-1);
    }
}
signed main(){
    cin>>n>>k;
    m=n.size();
    if(m<k){
        cout<<0<<endl;
        return 0;
    }
    init_fact();
    int ans=comb(m,k)*pow(9,k);
    ans-=f(0,k);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15872
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll inf = 1000000009;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
const int intmax = 2147483647;
struct SegT {
private:
	int n; vector<int> node;
public:
	SegT(int sz) {
		n = 1;
		while (n < sz)n <<= 1;
		//nodeの初期化
		node.resize(2 * n - 1, 2147483647);
	}
	int f(int a, int b) {
		return min(a, b);
	}
	void init(vector<int> v) {
		rep(i, v.size()) {
			node[i + n - 1] = v[i];
		}
		per(i, n - 1) {
			node[i] = f(node[2 * i + 1], node[2 * i + 2]);
		}
	}
	void update(int x, int val) {

		random_device rnd;
		mt19937 mt(rnd());
		uniform_int_distribution<> rnd100(1, 2000);
		int t = rnd100(mt);
		
		//tは1以上100以下の数を一様に選ばれ、1が出ると更新をサボる
		if (t == 1)return;
		x += (n - 1);
		node[x] = val;
		while (x > 0) {
			x = (x - 1) >> 1;
			node[x] = f(node[2 * x + 1], node[2 * x + 2]);
		}
	}
	int query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		if (r <= a || b <= l)return intmax;
		if (a <= l&&r <= b)return node[k];
		int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
		return f(vl, vr);
	}
};

int main() {
	int n, q; cin >> n >> q;
	SegT s(n);
	rep(i, q) {
		int ope; cin >> ope; int x, y; cin >> x >> y;
		if (ope == 0) {
			s.update(x, y);
		}
		else {
			cout << s.query(x, y + 1) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3792
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	char ca[55],cb[55]="AKIHABARA";
	int n=0;
	bool s=true;
	int i,j,k;
	cin>>ca;
	for(i=0;i<strlen(ca);i++){
		if(n<9 && ca[i]!=cb[n] && cb[n]=='A')n++;
		if(n>=9 || ca[i]!=cb[n]){
			s=false;
			break;
		}
		n++;
	}
	if(n!=8 && n!=9)s=false;
	if(s)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}
	


Measured memory_bytes: 256
N,C = $stdin.gets.chomp.split(" ").map{ |a| a.to_i }
xs = []
vs = []
N.times{
  x,v = $stdin.gets.chomp.split(" ").map{ |a| a.to_i }
  xs << x
  vs << v
}

t = 0
A = (0...N).map{ |i| t += vs[i]; t-xs[i] }
t = 0
B = (0...N).map{ |k| i = N-1-k; t += vs[i]; t-(C-xs[i]) }.reverse

ans = [0, A.max, B.max].max
#p A
#p B

$stderr.puts ans

wmax = 0
(0...N-1).map{ |k|
  i = N-k-2
  #p [i, wmax, B[i+1]]
  wmax = [wmax, B[i+1]].max
  ans = [ans, A[i] - xs[i] + wmax].max
}

$stderr.puts ans

wmax = 0
(1...N).map{ |j|
  wmax = [wmax, A[j-1]].max
  ans = [ans, B[j] - (C-xs[j]) + wmax].max
}

puts ans


Measured memory_bytes: 6764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string[] s = Console.ReadLine().Split(' ');
			ulong a = ulong.Parse(s[0]);
			ulong b = ulong.Parse(s[1]);
			ulong x = ulong.Parse(s[2]);
			ulong ans = 0;
			ulong tmp;
			if (a % x == 0)
			{
				ans++;
				tmp = a;
			}
			else
			{
				tmp = a + x - (a % x);
				if (tmp <= b)
					ans++;
			}
			if(b >= tmp)
				ans += (b - tmp) / x;
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 2904
#include <bits/stdc++.h>
using namespace std;
int main () {
int N , M ; cin >> N >> M ;
vector <int > cnt (M , 0);
for ( int i = 0; i < N ; ++ i ) {
int K; cin >> K ;
for ( int j = 0; j < K ; ++ j ) {
int A; cin >> A ; --A ;
++ cnt [ A ];
}
}
int ans = 0;
for ( int i = 0; i < M ; ++ i ) {
if ( cnt [ i ] == N ) {
++ ans ;
}
}
cout << ans << endl ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define mx 1e18
#define mod 998244353
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll bino()
{
        vector<ll>inv(200005);vector<ll>fact(200005); vector<ll>inversef(200005);
    inv[0] = 1;inv[1]=1;
for(int i = 2; i < 200005; ++i)
    inv[i] = (inv[mod%i]*(mod-mod/i)) % mod;
    
    fact[0]=1;
    for(int i=1;i<200005;i++)
    fact[i]=(i*fact[i-1])%mod;
   
    inversef[0]=1;inversef[1]=1;
    for(int i=2;i<200005;i++)
    inversef[i]=(inversef[i-1]*inv[i])%mod;
}
ll powe(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return powe(((x%mod)*(x%mod))%mod,n/2);
    else                             //n is odd
        return ((x%mod*(powe(((x%mod)*(x%mod))%mod,(n-1)/2))%mod)%mod);
}
int main()
{
   io
   int n,k;cin>>n>>k;int p=k;map<int,int>m;
   
   while(p--)
   {
     int d;cin>>d;int x;
     for(int i=0;i<d;i++)
     {cin>>x;
     m[x]=d;
     }
   }int cc=0;
   for(int i=1;i<=n;i++)
   {
      if(m.find(i)==m.end())cc++;
   }cout<<cc<<endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n, a, x, y, b, c, p;
    cin >> x >> y >> a >> b >> c;
    vector<pair<lli, lli>> v;

    for (lli i = 0; i < a; i++) {
        cin >> p;
        v.pb({p, 1});
    }
    for (lli i = 0; i < b; i++) {
        cin >> p;
        v.pb({p, 2});
    }
    for (lli i = 0; i < c; i++) {
        cin >> p;
        v.pb({p, 0});
    }

    sort(v.rbegin(), v.rend());
    lli ans = 0, red = 0, white = 0, cnt = 0;

    for (lli i = 0; i < v.size(); i++) {
        if (cnt == x + y) {
            break;
        }
        if (v[i].second == 1 && red < x) {
            ans += v[i].first;
            red++;
            cnt++;
        }
        if (v[i].second == 2 && white < y) {
            ans += v[i].first;
            white++;
            cnt++;
        }
        if (v[i].second == 0) {
            ans += v[i].first;
            cnt++;
        }
    }

    cout << ans << endl;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

Measured memory_bytes: 10476
#include <bits/stdc++.h>
#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 rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=1e5+10;
const ll INF=1e18+10;

int N, M;
ll L;
ll cost[305][305];
void input(){
  	cin>>N>>M>>L;
	rep1(i, N)rep1(j, N){
		if(i == j) cost[i][j]=0;
		else cost[i][j] = INF;
	}
	rep(_, M){
		int A, B;
		ll C;
		cin>>A>>B>>C;
		cost[A][B]=C;
		cost[B][A]=C;
	}

}
int ch[305][305];
void solve(){
	rep1(k, N)rep1(i, N)rep1(j, N)cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
	rep1(i, N)rep1(j, N){
		if(i == j)ch[i][j]=0;
		else if(cost[i][j]<=L) ch[i][j]=1;
		else ch[i][j] = MAX;
	}
	rep1(k ,N)rep1(i, N)rep1(j, N) ch[i][j]= min(ch[i][j], ch[i][k]+ch[k][j]);

}

void output(){
	int Q;
	cin>>Q;
	rep(_,Q){
		int s, t;
		cin>>s>>t;
		if(ch[s][t] == MAX) cout<<-1<<endl;
		else cout<<ch[s][t]-1<<endl;
	}
}

int main(){
	input();
    solve();
    output();
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
long long n,k,cnt[100005],dp[100005],ans;
const long long mod = 1000000007;
long long exp(long long a , long long b){
    if(b==0)return 1;
    long long tmp = (exp(a,b/2));
    if(b%2==0)return (tmp*tmp)%mod;
    return (a*((tmp*tmp)%mod))%mod;
}

int main(){
    cin>>n>>k;
    for(int i =1;i<=k;i++){
        cnt[i]=1;
        for(int j =2*i;j<=k;j+=i)cnt[i]++;
    }
    // cout<<cnt[1]<<endl;
    for(int i =1;i<=k;i++){

        dp[i]=exp(cnt[i],n);
        // cout<<dp[i]<<endl;
    }
    for(int i =k;i>0;i--){
        for(int j = i*2;j<=k;j+=i){
            dp[i]= (dp[i]+mod-dp[j])%mod;
        }
        ans= (ans+ ((dp[i]*i)%mod))%mod;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 5144
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
#define rep(i, s, n) for(int i = s; i < n; i++)
#define ll long long 

int main() {
    string s, t;
    cin >> s >> t;
    cout << t+s << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class MyScanner {
    BufferedReader br;

    MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public int intLine() throws IOException {
        return Integer.parseInt(br.readLine());
    }

    public String line() throws IOException {
        return br.readLine();
    }

    public int[] intArray() throws IOException {
        String[] in = br.readLine().split(" ");
        int n = in.length;
        int[] res = new int[n];
        for(int i = 0; i < n; i++) {
            res[i] = Integer.parseInt(in[i]);
        }
        return res;
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        /*
        MyScanner sc = new MyScanner();

        int[] nd = sc.intArray();
        int n = nd[0];
        int d = nd[1];
        int[][] x = new int[n][d];
        for(int i = 0; i < n; i++) {
            x[i] = sc.intArray();
        }
        */

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int d = Integer.parseInt(in[1]);
        int[][] x = new int[n][d];
        for(int i = 0; i < n; i++) {
            in = br.readLine().split(" ");
            for(int j = 0; j < d; j++) {
                x[i][j] = Integer.parseInt(in[j]);
            }
        }

        int ans = 0;
        for(int i = 0; i < n; i++) {
            for(int j = i + 1; j < n; j++) {
                int d2 = 0;
                for(int k = 0; k < d; k++) {
                    d2 += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean flag = false;
                for(int k = 1; k <= d2; k++) {
                    if(k * k == d2) {
                        flag = true;
                        break;
                    }
                }
                if(flag) ans++;
            }
        }

        System.out.println(ans);
        //sc.br.close();
    }
}

Measured memory_bytes: 23124
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
int main ()
{
	int a,b,x;
	scanf("%d%d%d",&a,&b,&x);
	if (x >= a && x <= a+b) printf("YES");
	else printf("NO");
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    
    for(int i=0;i<n;i++)
    cin>>a[i];
    ll sum=1000;
    ll x=0;
    for(int i=0;i<n-1;i++)
    {
        if(a[i]<a[i+1])
        {
            x=sum/a[i];
            sum=sum%a[i];
            
            sum+=x*a[i+1];
            x=0;
        }
        
    }
    cout<<sum;

    return 0;
}


Measured memory_bytes: 3628
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n,x;
    cin>>n>>x;
    ll d=0,ans=0;
    forn(i,n){
        int l;
        cin>>l;
        d=(d+l);
        if(d<=x)ans++;
    }
    cout<<ans+1<<endl;
    return 0;
}


Measured memory_bytes: 3540
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
        int ans = 0;
        int suko[] = new int[M];
        for (int i=0;i<M;i++){
          suko[i] = 0;
        }
      
        for (int i=0;i<N;i++){
          int K = Integer.parseInt(sc.next());
          for (int j=0;j<K;j++){
            int A = Integer.parseInt(sc.next());
            suko[A-1] += 1;
          }
        }
        for (int i=0;i<M;i++){
          if (suko[i] == N){
            ans += 1;
          }
        }
     out.println(ans);
     out.flush();
    }
}

Measured memory_bytes: 21968
#include <iostream>
using namespace std;
int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a == b){
        cout << c << endl;
    }else if(b == c){
        cout << a << endl;
    }else{
        cout << b << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define S second
#define F first
#define ll long long
using namespace std;

const int N = 1e5 + 5;

int arr[N], mxl[N], mxr[N], mx[N<<3], n;

void build(int ind, int l, int r)
{
    if(l == r)
    {
        mx[ind] = arr[l];
        return;
    }
    int mid = (l+r)>>1;
    build(ind<<1, l, mid);
    build(ind<<1|1, mid+1, r);
    mx[ind] = max(mx[ind<<1], mx[ind<<1|1]);
}

int getL(int ind, int l, int r, int s, int e, int v)
{
    if(e < l or s > r or mx[ind] < v) return n;
    if(l == r) return l;
    int mid = (l+r)>>1;
    if(l >= s and r <= e)
    {
        if(mx[ind<<1] > v)
        {
            return getL(ind<<1, l, mid, s, e, v);
        }
        else if(mx[ind<<1|1] > v) return getL(ind<<1|1, mid+1, r, s, e, v);
        else return n;
    }
    else return min(getL(ind<<1|1, mid+1, r, s, e, v), getL(ind<<1, l, mid, s, e, v));
}

int getR(int ind, int l, int r, int s, int e, int v)
{
    if(e < l or s > r or mx[ind] < v) return -1;
    if(l == r) return l;
    int mid = (l+r)>>1;
    if(l >= s and r <= e)
    {
        if(mx[ind<<1|1] > v)
        {
            return getR(ind<<1|1, mid+1, r, s, e, v);
        }
        else if(mx[ind<<1] > v) return getR(ind<<1, l, mid, s, e, v);
        else return -1;
    }
    else return max(getR(ind<<1|1, mid+1, r, s, e, v), getR(ind<<1, l, mid, s, e, v));
}

int main()
{
    cin>>n;
    ll ans = 0, l, r;
    stack<pair<int, int> > st;
    for(int i = 0 ; i < n ; i++)
    {
        cin>>arr[i];
        while(st.size() and st.top().F < arr[i]) st.pop();
        if(st.empty()) mxl[i] = -1;
        else
        {
            mxl[i] = st.top().S;
        }
        st.push({arr[i], i});
    }
    while(st.size()) st.pop();
    for(int i = n-1 ; ~i ; i--)
    {
        while(st.size() and st.top().F < arr[i]) st.pop();
        if(st.empty()) mxr[i] = n;
        else
        {
            mxr[i] = st.top().S;
        }
        st.push({arr[i], i});
    }
    build(1, 0, n-1);
    for(ll i = 0 ; i < n ; i++)
    {
        l = mxl[i] + 1;
        if(mxr[i] < n)
        {
            r = max(getL(1, 0, n-1, min(mxr[i] + 1, n-1), n-1, arr[i]) - 1, mxr[i]);
            ans += max(0LL, 1LL * arr[i] * (i - l + 1) * (r - mxr[i] + 1));
            // cout<<"L "<<l<<" "<<r<<" "<<i<<" "<<max(0LL, 1LL * arr[i] * (i - l + 1) * (r - mxr[i] + 1))<<endl;
        }
        r = mxr[i] - 1;
        if(mxl[i] >= 0)
        {
            l = min(mxl[i], getR(1, 0, n-1, 0, max(mxl[i] - 1, 0), arr[i]) + 1);
            ans += max(0LL, 1LL * arr[i] * (r - i + 1) * (mxl[i] - l + 1));
            // cout<<"R "<<l<<" "<<r<<" "<<i<<" "<<max(0LL, 1LL * arr[i] * (r - i + 1) * (l - mxl[i] + 1))<<endl;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long mod = (long) (Math.pow(10, 9) + 7);
    long n = sc.nextLong();
    long pow = 1;
    
    for (int i = 1; i <= n; i++) {
      pow = (pow * i) % mod;
    }
    
    System.out.println(pow);

  }
}

Measured memory_bytes: 35580
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input())
arr = [int(input()) for i in range(n)]
count = arr[0]-1
m = 2
for a in arr[1:]:
    if a > m:
        count += (a - 1) // m
    if a == m:
        m += 1
print(count)


Measured memory_bytes: 7848
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  int ans=0;
  vector<int> D(N);
  vector<int> E(N);
  for(int i=0;i<N;i++){
    cin>>D[i]>>E[i];
  }
  for(int i=0;i<N;i++){
    if(D[i]!=E[i]){
      continue;
    }
     if(i==N-1){
        break;
      }
    i++;
   
    if(D[i]!=E[i]){
      continue;
      
    }
    if(i==N-1){
        break;
      }
    i++;
    if(D[i]==E[i]){
	  cout<<"Yes"<<endl;
      ans++;
      break;
    }
    else{
      continue;
    }
    
  }
  if(ans==0){
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3632
n,m,k = map(int,input().split())
arr1 = list(map(int,input().split()))
arr2 = list(map(int,input().split()))

acum1 = [0]
for _ in range(n):
    acum1.append(acum1[-1] + arr1[_])

acum2 = [0]
for _ in range(m):
    acum2.append(acum2[-1] + arr2[_])

ans = 0
j = m
for i in range(n+1):
    if acum1[i]>k:
        break
    while acum2[j]>k-acum1[i] and j>0:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Measured memory_bytes: 47508
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;} 
int main(){
  int r=0,i;
  char s[100010],c[100010];
  scanf("%s",s);
  for(i=0;s[i];i++){
    if(s[i]=='B')r=MAX(r-1,0);
    else c[r++]=s[i];
  }
  c[r]=0;
  printf("%s\n",c);
  return 0;
}

Measured memory_bytes: 128
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <iostream>
# include <math.h>
# include <algorithm>
using namespace std;
typedef long long ll;

namespace IO {
	const int maxn(1 << 21 | 1);

	char ibuf[maxn], *iS, *iT, c;
	int f;

	inline char Getc() {
		return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), (iS == iT ? EOF : *iS++)) : *iS++;
	}
	
	template <class Int> inline void In(Int &x) {
		for (f = 1, c = Getc(); c < '0' || c > '9'; c = Getc()) f = c == '-' ? -1 : 1;
		for (x = 0; c >= '0' && c <= '9'; c = Getc()) x = (x << 1) + (x << 3) + (c ^ 48);
		x *= f;
	}
}

using IO :: In;

const int mod(1e9 + 7);
const int maxm(8005);
const int maxn(2e5 + 5);

inline void Inc(int &x, int y) {
	if ((x += y) >= mod) x -= mod;
}

int fac[maxm], ifac[maxm], n, a[maxn], b[maxn], ans, f[4005][4005], cnt[4005][4005];

inline int C(int x, int y) {
	if (y > x) return 0;
	return 1LL * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}

int main() {
	fac[1] = fac[0] = 1, ifac[1] = ifac[0] = 1, In(n);
	register int i, j;
	for (i = 2; i <= 8000; ++i) {
		fac[i] = 1LL * fac[i - 1] * i % mod;
		ifac[i] = 1LL * (mod - mod / i) * ifac[mod % i] % mod;
	}
	for (i = 2; i <= 8000; ++i) ifac[i] = 1LL * ifac[i] * ifac[i - 1] % mod;
	for (i = 1; i <= n; ++i) {
		In(a[i]), In(b[i]);
		Inc(ans, mod - C(a[i] + a[i] + b[i] + b[i], a[i] + a[i]));
		++f[2000 - a[i]][2000 - b[i]];
		a[i] += 2000, b[i] += 2000, ++cnt[a[i]][b[i]];
	}
	for (i = 0; i <= 4000; ++i)
		for (j = 0; j <= 4000; ++j) {
			if (i) Inc(f[i][j], f[i - 1][j]);
			if (j) Inc(f[i][j], f[i][j - 1]);
			if (cnt[i][j]) Inc(ans, 1LL * f[i][j] * cnt[i][j] % mod);
		}
	ans = 1LL * ans * ((mod + 1) / 2) % mod;
	printf("%d\n", ans);
	return 0;
}

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

int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    int n=sizeof(a)/sizeof(0);
   sort(a,a+n);

   for(int i=0;i<n;i++)
       cout<<a[i]<<((i==n-1) ? "\n" : " ");
    return 0;
}



Measured memory_bytes: 3124
n = int(input())
h = list(map(int, input().split()))

can = True

for i in range(1, n):
    if h[i] - h[i - 1] >= 1:
        h[i] -= 1
    elif h[i] == h[i - 1]:
        pass
    else:
        can &= False

print("Yes" if can else "No")


Measured memory_bytes: 14396
#include<stdio.h>
int main(){
  int n = 0;
  long a[100001] = {};
  long b[100001] = {};
  int i = 0;
  long long sum = 0;
  scanf("%d",&n);
  for(i=0;i<n+1;i++){
    scanf("%ld",&a[i]);
  }
  for(i=0;i<n;i++){
    scanf("%ld",&b[i]);
  }
  for(i=0;i<n;i++){
    if(a[i]+a[i+1]<=b[i]){
      sum += a[i]+a[i+1];
      a[i+1]=0;
      a[i]=0;
    }else if(a[i] <= b[i] && a[i]+a[i+1] > b[i]){
      sum += b[i];
      a[i+1] -= b[i]-a[i];
      a[i] = 0;
    }else{
      sum += b[i];
      a[i] -= b[i];
    }
  }
  printf("%lld",sum);
  return 0;
}
      

Measured memory_bytes: 1664
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class FFractalShortestPath {
public:

    vector<ll> e3;

    ll calc(ll a, ll b, ll c, ll d) {
      a--; b--; c--; d--;
      for(int i=29; i>=0; i--) {
        //debug(i);
        auto e = e3[i];
        auto a3 = a/e;
        auto b3 = b/e;
        auto c3 = c/e;
        auto d3 = d/e;
        if (a3 != c3 && b3 != d3) {
          return abs(b-d) + abs(a-c);
        }
        //debug(a3, b3, c3, d3);
        if (a3 == c3 && b3 == d3) {
          a %= e;
          b %= e;
          c %= e;
          d %= e;
          continue;
        }

        if (a3 != c3) {
          swap(a, b); swap(c, d);
          swap(a3, b3); swap(c3, d3);
        }
        //debug(a, b, c, d);

        // a3 == c3, b3 != d3
        while(a3 == c3 && e > 0) {
          //debug(a, c, a3, c3, e);
          if (a3%3 == 1 && c3%3 == 1 && abs(b/e-d/e) > 1) {
            ll left = a%e+c%e+2;
            ll right = e*2-a%e-c%e;
            return abs(b-d)+min(left, right);
          }
          e /= 3;
          if (e==0) break;
          a3 = a/e;
          c3 = c/e;
          //debug(a3, c3, e);
        }
        return abs(b-d) + abs(a-c);
      }
      return abs(b-d) + abs(a-c);
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int q; cin >> q;
      e3.resize(31, 1);
      for(int i=1; i<=30; i++) {
        e3[i] = e3[i-1]*3;
      }
      while(q--) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        cout << calc(a, b, c, d) << '\n';
      }
    }
};

signed main() {
  FFractalShortestPath solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

int main()
{
  int64_t H ;
  cin>>H ;
  
  int64_t N=0;
  int64_t tmp=1 ;
  while(tmp*2<=H){
    tmp*=2 ;
    N++ ;
  }
  
  cout<<2*tmp-1<<endl ;
  
  return 0 ;
}



Measured memory_bytes: 256