akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

#define MAX_CIPHER_LEN 20
#define append(str, pos, c) ((str)[(pos)] = (c), (str)[(pos)+1] = '\0')
#define ring(x)  ((x) >= 10 ? ((x) - 5) % 5 + 5 : (x))
#define initResult() (resultPos = nResult = 0)

char result[10][MAX_CIPHER_LEN + 1];
int resultPos = 0;
int nResult = 0;

void addResult(const char candidate[])
{
  nResult++;
  strcpy(result[resultPos], candidate);
  resultPos = ring(resultPos + 1);
}

void showResult()
{
  int i;
  printf("%d\n", nResult);
  if (nResult <= 10) {
    for (i = 0; i < nResult; i++) {
      printf("%s\n", result[i]);
    }
  } else {
    for (i = 0; i < 5; i++) {
      printf("%s\n", result[i]);  /* first five */
    }
    for (i = 0; i < 5; i++) {
      printf("%s\n", result[ring(i + resultPos)]);  /* last five */
    }
  }
}

/**
 * ?§£?????¢?´¢??????.
 * @param cipher ?????????
 * @param pos    ?????????????§£???????????????
 * @oaram candidate ?????¨?§???????????§£????£?
 * @return ?§£????????°
 */
void search(const char cipher[], int pos, char candidate[])
{
  char c = cipher[pos];
  if (c == '\0') { /* ?§£????????? */
    addResult(candidate);
    return;
  }

  if (c == 'a' || strchr(candidate, c) != NULL) {
    append(candidate, pos, c);
    search(cipher, pos + 1, candidate);
    candidate[pos] = '\0';
  }
  if (c != 'z' && strchr(candidate, c + 1) == NULL) {
    append(candidate, pos, c + 1);
    search(cipher, pos + 1, candidate);
    candidate[pos] = '\0';
  }
}

int main()
{
  static char cipher   [MAX_CIPHER_LEN + 1];
  static char candidate[MAX_CIPHER_LEN + 1];
  for (;;) {
    scanf("%s", cipher);
    if (strcmp(cipher, "#") == 0) break;

    candidate[0] = '\0';
    initResult();
    search(cipher, 0, candidate); /* ?§£?????¢?´¢ */
    showResult();
  }
  return 0;
}

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

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

	vector<int> l(n);
	for (int i = 0; i < n; i++)
	{
		cin >> l.at(i);
	}

	vector<int> d(n + 1);
	d.at(0) = 0;
	int count = 0;
	if (d.at(0) <= x)
	{
		count++;
	}
	for (int i = 1; i < n + 1; i++)
	{
		d.at(i) = d.at(i - 1) + l.at(i - 1);
		if (d.at(i) <= x)
		{
			count++;
		}
	}

	cout << count << endl;
}


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

using namespace std;

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

	int n, k;
	cin >> n >> k;
	vector<int> d(k);
	for (int i = 0; i < k; i++) {
		cin >> d[i];
	}
	int res;
	bool g = true;
	for (res = n; g; res++) {
		g = false;
		int cur = res;
		while (cur > 0 && !g) {
			int dg = cur % 10;
			for (int w : d) {
				if (dg == w) {
					g = true;
					break;
				}
			}
			cur /= 10;
		}
	}
	cout << res - 1 << '\n';

	return 0;
}



Measured memory_bytes: 256
local unpack = table.unpack or unpack
local INF = math.floor(10^10)
local N, M, P = io.read("*n", "*n", "*n")
local edges = {}
for i=1,M do
    local a, b, c = io.read("*n", "*n", "*n")
    edges[i] = {a, b, -1 * (c - P)}
end


-- Bellman-Ford
local function bf()
    -- distance from 1
    local d = {}
    for i=1,N do
        d[i] = INF
    end
    d[1] = 0
    for i=1,N-1 do
        for j=1,M do
            local a, b, w = unpack(edges[j])
            if d[a] ~= INF then
                local new_d = d[a] + w
                if new_d < d[b] then
                    d[b] = new_d
                end
            end
        end
    end
    for i=1,N do
        for j=1,M do
            local a, b, w = unpack(edges[j])
            if d[a] ~= INF then
                if d[a] + w < d[b] or d[a] == -INF then
                    d[b] = -INF
                end
            end
        end
    end
    return d
end

local d = bf()
local negloop = d[N] == -INF
if negloop then
    print(-1)
else
    local a = math.max(0,-d[N])
    if a == 0 then a = 0 end
    print(a)
end

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

typedef long long ll;

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

    
    string s;
    cin >> s;
    int sum = 0;
    
    int dp[s.size() + 1][2];
    dp[0][0] = 0;
    dp[0][1] = 1;
    for (int i = 1; i <= s.size(); i ++) {
        dp[i][0] = min(dp[i - 1][0] + s[i - 1] - '0',       dp[i - 1][1] + 10 - s[i - 1] + '0');
        dp[i][1] = min(dp[i - 1][0] + s[i - 1] - '0' + 1,   dp[i - 1][1] + 9 - s[i - 1] + '0');
   }

    cout << dp[s.size() ][0];
    return 0;

}

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
int k,s,c;
int main()
{
cin>>k>>s;
for(int x=0;x<=k;x++)
for(int y=0;y<=k;y++)
if(s-x-y>=0&&s-x-y<=k)c++;
cout<<c<<endl;
}

Measured memory_bytes: 256
/* Copyright 2016 AcrossTheSky */
#include <iostream>
#include <cstdio>
#include <utility>
#include <cassert>
#include <map>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <sstream>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define PER(i, a, b) for (int i = (a); i >= (b); --i)
#define RVC(i, c) fot (int i = 0; i < (c).size(); ++i)
#define RED(k, u) for (int k = head[(u)]; k; k = edge[k].next)
#define SQR(k) (k) * (k)
#define lowbit(x) ((x) & (-(x)))
#define CL(x, v) memset(x, v, sizeof x)
#define MP std::make_pair
#define PB push_back
#define FR first
#define SC second
#define rank rankk
#define next nextt
#define link linkk
#define index indexx
#define abs(x) ((x) > 0 ? (x) : (-(x)))
using namespace std;
typedef long long LL; typedef pair<int, int> PII;

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

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

template<class T> inline
void read(T *a) {
    char c;
    while (isspace(c = getchar())) {}
    bool flag = 0;
    if (c == '-') flag = 1, *a = 0;
    else
        *a = c - 48;
    while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
    if (flag) *a = -*a;
}

const int mo = 1000000007;
template<class T>
T pow(T a, T b, int c = mo) {
    T res = 1;
    for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c) if (b & i) res = 1LL * res * a % c;
    return res;
}
/*======================= TEMPLATE =======================*/
const int N = 100001;
int x[N], a[N];
LL y[N];
int f[N][64];
int ans[N];
int t[N];
int n, m;
LL K;
int main() {
    cin >> n;
    REP(i, 1, n) read(&x[i]), y[i] = x[i] - x[i - 1];
    cin >> m >> K;
    REP(i, 1, m) read(a + i);
    REP(i, 1, n) f[i][0] = ans[i] = i;
    REP(i, 1, m) swap(f[a[i]][0], f[a[i] + 1][0]);
    REP(h, 1, 63) REP(i, 1, n) f[i][h] = f[f[i][h - 1]][h - 1];
    PER(h, 62, 0) if (K >= (1LL << h)) {
        K -= (1LL << h);
        REP(i, 1, n) t[i] = ans[f[i][h]];
        REP(i, 1, n) ans[i] = t[i];
    }
    LL s = 0;
    REP(i, 1, n) {
        s = s + y[ans[i]];
        printf("%lld\n", s);
    }
    return 0;
}


Measured memory_bytes: 28544
#include <iostream>
#include <cmath>
#include <utility>
#include <algorithm>
using namespace std;
int n, d;
pair<int, int> a[200000];
int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i].first, a[i].second = i;
    sort(a, a + n, greater<pair<int, int>>());
    for (int i = 0; i < n; ++i)
        if (i != a[0].second)
            cout << a[0].first << endl;
        else
            cout << a[1].first << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  ll a,b,c;
  cin>>a>>b>>c;
  if(a<=b*c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    vector<int> x;
    vector<int> y;
    int xtmp, ytmp;
    for(int ix=0;ix<=30;ix++) {
        for(int jx=0;jx<=30;jx++) {
            xtmp = 100*a*ix+100*b*jx;
            if(xtmp<=f) x.push_back(xtmp);
        }
    }
    for(int iy=0;iy<=3000;iy++) {
        for(int jy=0;jy<=3000;jy++) {
            ytmp = c*iy+d*jy;
            if(ytmp<=f) y.push_back(ytmp);
        }
    }

    int dmaxsum = 1, dmaxsugar = 0;
    int sum = 0, sugar = 0;
    for(std::vector<int>::const_iterator ix = x.begin(), ex = x.end(); ix != ex; ++ix) {
        for(std::vector<int>::const_iterator iy = y.begin(), ey = y.end(); iy != ey; ++iy) {
            if(*ix+*iy==0) continue;
            if((dmaxsugar*(*ix+*iy)<*iy*(dmaxsum))&&((*ix+*iy)<=f)&&(e*(*ix+*iy)>=*iy*(100+e))) {
                dmaxsum = *ix+*iy;
                dmaxsugar = *iy;
            }
        }
    }
    if(dmaxsum==1&&dmaxsugar==0) {
        dmaxsum = 100*a;
        dmaxsugar = 0;
    }
    cout << dmaxsum << " " << dmaxsugar << endl;
    return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
    using namespace std;
    const int N=300005;
    long long z;
    int n,l,c0,c1,c2,x[N],t[N],f[N];
    int main() 
    {
    	scanf("%d%d",&n,&l);
    	for (int i=0;i<n;i++)scanf("%d",&x[i]);
    	z=1;
    	for (int i=0;i<n;i++)
    	 {
    		scanf("%d",&t[i]);
    		z+=t[i]/(2*l);t[i]%=2*l;
    		if (t[i]>0)
    		 {
    			z++;
    			int f=(t[i]<=(l-x[i])*2),g=(t[i]<=(x[i])*2);
    			if (i==n-1)
    			 {
    				if (f)z--;
    				break;
    			 }
    			if (g)
    			 {
    				c0++;
    				if (f)c2++;
    			 }
    			else if (f)c1++;
    			while (c0-c2<c1+c2)
    			 {
    				if (c2>0)c2--;
    				else c1--;
    			 }
    		 }
    	 }
    	z-=c1+c2;
    	printf("%lld\n",z*l*2);
    	return 0;
    }

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

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

long long cnt(long long N){
    long long i = 1;
    long long count = -1;
    while(N >= 0){
        N -= i;
        i++;
        count++;
    }
    return count;
}

int main() {
    long long N;
    long long ans = 0;
    cin >> N;
    const auto &res = prime_factorize(N);
    for (auto p : res) {
        ans += cnt(p.second);

    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
def count(n)
  return 1 if n == 1
  return 2 if n == 2
  return 4 if n == 3
  return count(n-1) + count(n-2) + count(n-3)
end

while n = gets.to_i
  break if n.zero?
  puts count(n) / 3650 + 1
end

Measured memory_bytes: 6084
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int N=scan.nextInt();
    Double[] v=new Double[N];
    for(int i=0;i<N;i++){
      v[i]=scan.nextDouble();
    }
    Arrays.sort(v);
    double ans=v[0];
    for(int i=0;i<N;i++){
      ans=(double)(v[i]+ans)/2;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23252
from collections import defaultdict,deque
import math
def main():
    n,d=map(int, input().split())
    res = 0
    for i in range(n):
        x,y=map(int, input().split())
        if(math.sqrt(x**2+y**2)<=d):
            res+=1
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 70020
#include <bits/stdc++.h> 
#define ll long long int
#define DEBUG(x) cerr<<"> "<< #x << ':' <<x<<endl;
using namespace std;
ll INF = 1e15;
ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b;
    cin>>a>>b;
    cout<<(a*b)<<"\n";
    return 0;
}

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

#define ll long long
#define pb push_back
#define INF 1e9+7
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	char a;
	cin>>a;
	if(a<'a'){
		cout<<'A';
	}
	else{
		cout<<'a';
	}
	
	
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

#define Pair pair<LL,LL>
using namespace std;

struct P{int x,y,r;};

struct edge{int to;long double cost;};
int N;
vector<edge> G[1003];
long double d[1003];

void dijkstra(int s){

    priority_queue<Pair,vector<Pair>,greater<Pair> > que;
    fill(d,d+N+2,100000000000000LL);
    d[s]=0;
    que.push(Pair(0,s));

    while(!que.empty()){
        Pair p=que.top();que.pop();
        int v = p.second;
        if(d[v]<p.first)continue;
        REP(i,G[v].size()){
            edge e = G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(Pair(d[e.to],e.to));
            }
        }
    }

}

long double dis(LL x1,LL y1,LL x2,LL y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main(){

    LL xs,ys,xt,yt;
    cin>>xs>>ys>>xt>>yt;
    cin>>N;
    vector<P> bar;
    REP(i,N){
        LL x,y,r;
        cin>>x>>y>>r;
        bar.push_back(P{x,y,r});
    }

    REP(i,N){
        REP(j,N){
            if(i==j)continue;
            G[i].push_back(edge{j,max(dis(bar[i].x,bar[i].y,bar[j].x,bar[j].y)-bar[i].r-bar[j].r,0.0L)});
            G[j].push_back(edge{i,max(dis(bar[i].x,bar[i].y,bar[j].x,bar[j].y)-bar[i].r-bar[j].r,0.0L)});
        }
    }

    REP(i,N){
        G[N].push_back(edge{i,max(dis(bar[i].x,bar[i].y,xs,ys)-bar[i].r,0.0L)});
        G[i].push_back(edge{N,max(dis(bar[i].x,bar[i].y,xs,ys)-bar[i].r,0.0L)});
        G[i].push_back(edge{N+1,max(dis(bar[i].x,bar[i].y,xt,yt)-bar[i].r,0.0L)});
        G[N+1].push_back(edge{i,max(dis(bar[i].x,bar[i].y,xt,yt)-bar[i].r,0.0L)});
    }
    G[N].push_back(edge{N+1,dis(xs,ys,xt,yt)});
    G[N+1].push_back(edge{N,dis(xs,ys,xt,yt)});

    dijkstra(N);
    cout<<fixed<<setprecision(10)<<d[N+1]<<endl;




    return 0;
}

Measured memory_bytes: 70000
#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int maxn = 300000+10;

int r[maxn], c[maxn];

int32_t main(){
    fast_io;
    int n, q;
    cin >> n >> q;
    set<int> cols, rows;
    int ans = (n - 2) * (n - 2);
    while(q--){
    	int t, x;
    	cin >> t >> x;
    	if(t == 1){
    		//cols
    		int curr = 0;
    		if(cols.empty() or *(cols.begin()) > x){
    			int val = n - 1;
	    		if(!rows.empty()) val = *(rows.begin()) - 1;
	    			curr = val - 1;
	    			c[x] = val;
    		}
    		else{
    			auto it = cols.upper_bound(x);
    			it--;
    			curr = c[*it];
    			c[x] = curr;
    			curr--;
    		}
    		// show(t, x, curr);
    		cols.insert(x);
    		ans -= curr;
    	}
    	else{
    		// rows
    		int curr = 0;
    		if(rows.empty() or *(rows.begin()) > x){
    			int val = n - 1;
    			if(!cols.empty()) val = *(cols.begin()) - 1;
    			curr = val - 1;
    			r[x] = val;
    		}
    		else{
    			auto it = rows.upper_bound(x);
    			it--;
    			curr = r[*it];
    			r[x] = curr;
    			curr--;
    		}
    		rows.insert(x);
    		ans -= curr;
    	}
    	// show(ans);
    }
    show(ans);
    return 0;
}

Measured memory_bytes: 16156
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.nextLine();
		int length = -1;
		for(int i = S.length() - 2; i >= 2; i -= 2) {
			if(S.substring(0, i / 2).equals(S.substring(i / 2, i))) {
				length = i;
				break;
			}
		}
		System.out.println(length);
		scan.close();
	}

}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

const int MOD = 1000000007;


void add_self(int& a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

void sub_self(int& a, int b) {
	a -= b;
	if (a < 0) {
		a += MOD;
	}
}


int main() {

	// fast input/output
	FAST_IO;

	int n, k;
	cin >> n >> k;
	vector<int> h(n + 1);
	vector<int> dp(n + 1, INT_MAX);
	for (int i = 1; i <= n; ++i) {
		cin >> h[i];
	}
	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);

	for (int i = 3; i <= n; ++i) {
		for (int j = 1; j <= k; ++j) {
			if (i > j)
				dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}
	cout << dp[n];
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>
#include <climits>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
typedef long long ll;
typedef std::vector<int> VI;
typedef std::pair<int, int> PII;

using namespace std;


int main()
{
  int N;
  cin >> N;
  ll ans = 0;
  VI B(N-1);
  REP(i, N-1) {
    cin >> B[i];
  }
  ans += B[0] + B[N-2];
  for (int i = 1; i < N-1; i++) {
    ans += std::min(B[i-1],B[i]);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

const int MaxN = 300 + 30;
const int MOD = 1e9 + 7;
const long long INF = 1e18;

int d[2];
int c[2][2 * MaxN][2 * MaxN];

vector <pair<int, int> > v[2];
vector <pair<int, int> > ans[4];

int n;

void dfs(int k, int x, int y, int q)
{
    c[k][x][y] = q;

    for(auto p : v[k])
    {
        int xx = x + p.first;
        int yy = y + p.second;

        if(xx >= 0 && xx < n + n && yy >= 0 && yy < n + n && !c[k][xx][yy])
            dfs(k, xx, yy, 3 - q);
    }
}

int main()
{
//    freopen("output.txt", "r", stdin);

    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> d[0] >> d[1];

    for(int i = -n - n; i <= n + n; ++i)
        for(int j = -n - n; j <= n + n; ++j)
            for(int k = 0; k < 2; ++k)
                if(i * i + j * j == d[k])
                    v[k].push_back({i, j});

    for(int i = 0; i < n + n; ++i)
        for(int j = 0; j < n + n; ++j)
            for(int k = 0; k < 2; ++k)
                if(!c[k][i][j])
                    dfs(k, i, j, 1);

    for(int i = 0; i < n + n; ++i)
        for(int j = 0; j < n + n; ++j)
            ans[2 * (c[0][i][j] - 1) + c[1][i][j] - 1].push_back({i, j});

    for(int i = 0; i < 4; ++i)
    {
        if(ans[i].size() >= n * n)
        {
            ans[i].resize(n * n);
            for(auto x : ans[i])
                cout << x.first << ' ' << x.second << '\n';
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 35160
import fractions

n = int(input())
a = list(map(int, input().split()))
L = 1
for i in range(n):
  L = L // fractions.gcd(L, a[i]) * a[i]
ans = 0
for i in range(n):
    ans += L // a[i]
print(ans % (10**9 + 7))
  

Measured memory_bytes: 6072
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

unordered_multiset<int> st;

signed main() {
	int N, M;
	vector<int> D, T;
	cin >> N;
	inputVector(D, N);
	cin >> M;
	inputVector(T, M);

	rep(i, N) st.insert(D[i]);

	bool ok = true;
	rep(i, M) {
		auto it = st.find(T[i]);
		if (it == st.end()) {
			ok = false;
			break;
		}
		st.erase(it);
	}

	cout << (ok ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 11592
import java.util.Scanner;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(true){
            int N =sc.nextInt();
            if(N==0)break;
            int[] key = new int[N];
            for (int i = 0; i < key.length; i++) {
                key[i]=sc.nextInt();
            }
            StringBuilder sb=new StringBuilder();
            StringBuilder ans=new StringBuilder();
            for (int i = 0; i < 26;i++){
                sb.append((char)('a'+i));
            }
            for (int i = 0; i < 26;i++){
                sb.append((char)('A'+i));
            }
            char[] s = sc.next().toCharArray();
            
            for (int i = 0; i < s.length; i++) {
                int j = i%key.length;
                int c = s[i]-'a';
                if(Character.isUpperCase(s[i])){
                    c = s[i]-'A'+26;
                }
                c = c - key[j];
                c += 52;
                ans.append(sb.charAt(c%52));
            }
            System.out.println(ans);
        }
    }

}

Measured memory_bytes: 24996
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

bool in(ll y, ll x, ll h, ll w){
    return 0 <= y && y < h && 0 <= x && x < w;
}

int main(){
    while(1){
        ll t,n; cin >> t >> n;
        if(!t && !n) break;
        int s[130][130];
        rep(i,130) rep(j,130) s[i][j] = 1;
        rep(i,n){
            ll x,y; cin >> x >> y;
            x += 60; y += 60;
            s[x][y] = 0;
        }
        ll sx,sy; cin >> sx >> sy;
        sx += 60; sy += 60;
        queue<pair<P,ll>> q;
        q.emplace(P(sx,sy),0);
        ll ans = 1;
        bool visit[130][130];
        rep(i,130) rep(j,130) visit[i][j] = false;
        visit[sx][sy] = true;
        while(!q.empty()){
            auto p = q.front(); q.pop();
            ll y = p.first.first;
            ll x = p.first.second;
            if(p.second >= t) continue;
            rep(i,6){
                ll ny = y + dy[i];
                ll nx = x + dx[i];
                if(in(ny,nx,130,130) && s[ny][nx] && !visit[ny][nx]){
                    visit[ny][nx] = true;
                    ans++;
                    q.emplace(P(ny,nx),p.second+1);
                }
            }
        }
        cout << ans << "\n";
    }
}


Measured memory_bytes: 3232
A,B,C,X,Y=map(int,input().split())
if A>=2*C:
  if B>=2*C:
    print(2*C*max(X,Y))
    exit()
  else:
    print(2*C*X+B*max(0,(Y-X)))
    exit()
elif B>=2*C:
  print(2*C*Y+A*max(0,(X-Y)))
  exit()
else:
  ans=A*X+B*Y
  for i in range(1,min(X,Y)+1):
    p=A*(X-i)+B*(Y-i)+2*C*i
    ans=min(ans,p)
  print(ans)

Measured memory_bytes: 9204
import sys
a,b = map(str, input().split()) #a1 a2 a3 // b1 b2 b3
keta=len(b)-b.find('.')

if keta==3:
  print(int(a)*int(b.replace(".",""))//100)
elif keta==2:
  print(int(a)*int(b.replace(".",""))//10)
else:
  print(int(a)*int(b))

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

#define MAX 500007
#define INFTY 2000000000
int S[MAX];
int compareCount;
int L[MAX/2+2], R[MAX/2+2];

void merge(int S[], int n, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = S[left+i]; 
    for (int i = 0; i < n2; i++) R[i] = S[mid+i];
    
    L[n1] = R[n2] = INFTY;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) S[k] = L[i++];
        else S[k] = R[j++];
        compareCount++;
    }
}

void mergeSort(int S[], int n, int left, int right) {
    if (left + 1 < right) { // if left + 1 == right (only one elements), it's a leaf, so already sorted!
        int mid = (left + right) / 2;
        mergeSort(S, n, left, mid);
        mergeSort(S, n, mid, right);
        merge(S, n, left, mid, right);
    }
}

int main(void)
{
    int n;
    compareCount = 0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> S[i];
    
    mergeSort(S, n, 0, n);
    
    for (int i = 0; i < n-1; i++) cout << S[i] << " ";
    cout << S[n-1] << endl;
    cout << compareCount << endl;
    return 0;
}


Measured memory_bytes: 6948
class Dice:
    """Dice class"""

    def __init__(self):                  # ?????????????????????
        self.eyeIndex = 1        #center
        self.eyeIndex_E = 3      #east
        self.eyeIndex_W = 4      #west
        self.eyeIndex_N = 5      #north
        self.eyeIndex_S = 2      #south
        self.eye = 0
        
    def shakeDice(self, in_command):

        pre_eyeIndex = self.eyeIndex
        if in_command == "E":
            self.eyeIndex = self.eyeIndex_W 
            self.eyeIndex_E = pre_eyeIndex 
            self.eyeIndex_W = 7 - self.eyeIndex_E
            
        elif in_command == "W":
            self.eyeIndex = self.eyeIndex_E 
            self.eyeIndex_W = pre_eyeIndex
            self.eyeIndex_E = 7 - self.eyeIndex_W
            
        elif in_command == "N":
            self.eyeIndex = self.eyeIndex_S 
            self.eyeIndex_N = pre_eyeIndex 
            self.eyeIndex_S = 7 - self.eyeIndex_N

        elif in_command == "S":
            self.eyeIndex = self.eyeIndex_N         
            self.eyeIndex_S = pre_eyeIndex 
            self.eyeIndex_N = 7 - self.eyeIndex_S 
            
        self.eye = self.eyes[self.eyeIndex]

    def getEye(self):
        return self.eye

    def setEyes(self, eyes):             # setEyes()???????????? ???????????????
        
        #index???1???????????????????????§,??????????????????????????????
        eyes = "0 " + eyes
        self.eyes = list(map(int, eyes.split(" ")))


dice_1 = Dice()
dice_1.setEyes(input().rstrip())

input_commands = input().rstrip()

for i in range(len(input_commands)):
    #Shake dice!!
    dice_1.shakeDice(input_commands[i])

print(dice_1.getEye())

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

int main(){
  int N,count=1;
  cin>>N;
  vector<int> mochi(N);
  for(int i=0;i<N;i++){
    cin>>mochi.at(i);
  }
  sort(mochi.begin(),mochi.end());
  reverse(mochi.begin(),mochi.end());
  int size=mochi.at(0);
  for(int i=0;i<N;i++){
    if(mochi.at(i)<size){
      count++;
      size=mochi.at(i);
    }
  }
  cout<<count<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007

int main(void)
{
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> A(a), B(b);
    rep(i, a) cin >> A.at(i);
    rep(i, b) cin >> B.at(i);

    int min_A = 1123456;
    int min_B = 1123456;
    rep(i, a) min_A = min(min_A, A.at(i));
    rep(i, b) min_B = min(min_B, B.at(i));

    int min_cost = min_A+min_B;

    rep(i,m){
        int x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;

        min_cost =min(min_cost,A.at(x) + B.at(y) - c);
    }
    cout << min_cost << endl;

    return 0;
}

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

int main()
{
  string s;
  int ans=1;
  cin>>s;
  for(int i=0;i<s.size();i++)
  {
    if(s.at(i)==s.at(s.size()-i-1))
    {
      if(i<s.size()/2)
      {
        if(s.at(i)!=s.at(s.size()/2-1-i))
        {
          ans=0;
          break;
        }
      }
      else if(i>s.size()/2)
      {
        if(s.at(i)!=s.at(s.size()*3/2-i))
        {
          ans=0;
          break;
        }
      }
    }
    else
    {
      ans=0;
      break;
    }
  }
  if(ans==1)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


Int n, L;
Int x[330000], t[330000];

int main(){
    Int ans = 0;
    cin >> n >> L;
    for(int i = 0;i < n;i++)cin >> x[i];
    for(int i = 0;i < n;i++){
        cin >> t[i];
        ans += t[i] / (2*L) * 2*L;
        t[i] %= 2*L;
        if(t[i] == 0){
            t[i] = 2*L;
            ans -= 2*L;
        }
    }
    string str = "";
    
    for(int i = 0;i < n;i++){
        bool flip_left = t[i] <= 2 * (L - x[i]);
        bool flip_right = t[i] <= 2 * x[i];
        if(i == n-1){
            if(!flip_left)ans += 2*L;
            continue;
        }
        if(!flip_left && !flip_right)ans += 2*L;
        if(flip_left && !flip_right)str += 'l';
        if(flip_left && flip_right)str += 'x';
        if(!flip_left && flip_right)str += 'r';
    }
    int last_l = -1, first_r = str.size();
    for(int i = 0;i < str.size();i++)if(str[i] == 'l')last_l = i;
    for(int i = (int)str.size() - 1;i >= 0;i--)if(str[i] == 'r')first_r = i;
    int l_stack = 0, r_stack = 0;
    for(int i = 0;i <= last_l;i++){
        if(str[i] == 'x')l_stack++;
        else if(l_stack > 0){
            l_stack--;
            ans += 2*L;
        }
        else{
            ans += 2*L;
        }
    }
    for(int i = (int)str.size() - 1;i >= first_r;i--){
        if(str[i] == 'x')r_stack++;
        else if(r_stack > 0){
            r_stack--;
            ans += 2*L;
        }
        else{
            ans += 2*L;
        }
    }
    int x_cnt = l_stack + r_stack;
    for(int i = last_l + 1;i < first_r;i++)x_cnt++;
    
    ans += x_cnt * 2 * L;
    ans -= x_cnt / 2 * 2 * L;
    ans += 2*L;
    cout << ans << endl;    
    return 0;
}

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int h, a;
  cin>>h>>a;
  cout<<(h-1)/a+1<<'\n';
  return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    n,k=map(int, input().split())
    l = sorted(list(map(int, [input() for i in range(n)])),reverse=False)
    # print(l)
    ans=1000000000
    for i in range(n-k+1):
        m=int(l[i+k-1]-l[i])
        if ans>m:
            ans=m
    print(ans)

Measured memory_bytes: 14236
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int a, b, c, d;

signed main() {
	cin >> a >> b >> c >> d;
	cout << string(c - a, 'R') << string(d - b + 1, 'U') << string(c - a + 1, 'L') << string(d - b + 1, 'D') << "RD" << string(c - a + 1, 'R') << string(d - b + 1, 'U') << string(c - a + 1, 'L') << string(d - b, 'D') << endl;
	return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#  define _CRT_SECURE_NO_WARNINGS
#  define _USE_MATH_DEFINES
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double;
using u32 = unsigned int; using u64 = unsigned long long int; using str = string;
template <typename T> using vec = vector<T>; void in() { }
template <typename T, typename...TS> void in(T &&x, TS &&...xs) { cin >> x; in(move(xs)...); }
template <typename T> void out(T &&x) { cout << x << "\n"; }
template <typename T, typename...TS> void out(T &&x, TS &&...xs) { cout << x << " "; out(move(xs)...); }
#define indef(t, ...) t __VA_ARGS__; in(__VA_ARGS__)
#define get(t) []{ t x; cin >> x; return x; }()
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define even(x) ((abs(x) & 1) == 0)
#define odd(x) ((abs(x) & 1) == 1)
#define bit(x, i) (((x) >> i) & 1)
#define append emplace_back
#define bisect_left lower_bound
#define bisect_right upper_bound
#define bound(a, x, b) (a <= x && x <= b)
const i64 MOD = 1000000007ll;
const f64 EPS = 1e-10;

i32 a[4][4];
i32 oy[4] = { 0, -1, 0, 1 };
i32 ox[4] = { -1, 0, 1, 0 };

i32 solve() {
    indef(i32, a, b, c, d);
    i32 s = max(a, c);
    i32 e = min(b, d);
    return max(0, e-s);
}

i32 main()
{
    ios::sync_with_stdio(false);

#ifdef _MSC_VER
    /**
    ifstream fin("input.txt"); cin.rdbuf(fin.rdbuf()); assert(fin);
    ofstream fout("output.txt"); cout.rdbuf(fout.rdbuf()); assert(fout);
    /**/
#endif

    //cout << fixed << setprecision(9);
    out(solve());

#ifdef _MSC_VER
    /**/
    /**/
#endif
    return 0;
}

Measured memory_bytes: 256
unittest
{
//	assert( [ "3" ].parse.expand.solve == "Yes\n3\n2 1 2\n2 3 1\n2 2 3" );
	assert( [ "3" ].parse.expand.solve == "Yes\n3\n2 1 2\n2 1 3\n2 2 3" );
	assert( [ "4" ].parse.expand.solve == "No" );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	auto ansss = [ [ 1L ], [ 1L ] ];
	auto s = 1L;
	while( s < n )
	{
		auto k = ansss.length.signed;
		ansss.length++;
		for( auto i = 0L; i < k; i++ )
		{
			s++;
			ansss[ i ] ~= s;
			ansss[ k ] ~= s;
		}
	}
	if( s != n ) return "No";
	else         return format( "Yes\n%s\n%s", ansss.length, ansss.map!( ( a ) => format( "%s %s", a.length, a.to!( string[] ).join( " " ) ) ).join( "\n" ) );
}


Measured memory_bytes: 13180
# Reference: https://qiita.com/dn6049949/items/afa12d5d079f518de368
# self.data: 1-indexed
#    __1__
#  _2_   _3_
# 4   5 6   7
# f(f(a, b), c) == f(a, f(b, c))

class SegmentTree:
    # a = [default] * n
    def __init__(self, n, f=max, default=-10**18):
        self.num_leaf = 1
        while self.num_leaf < n:
            self.num_leaf *= 2
        self.data = [default] * (2*self.num_leaf)
        self.f = f

    # a[i] = x
    def update(self, i, x):
        i += self.num_leaf
        self.data[i] = x
        i >>= 1
        while i > 0:
            self.data[i] = self.f(self.data[2*i], self.data[2*i+1])
            i >>= 1

    # return f(a[l:r])
    def query(self, l, r):
        l += self.num_leaf
        r += self.num_leaf - 1
        lres, rres = self.data[0], self.data[0] # self.data[0] == default
        while l < r:
            if l & 1: # l % 2 == 1
                lres = self.f(lres, self.data[l])
                l += 1
            if not r & 1: # r % 2 == 0
                rres = self.f(self.data[r], rres)
                r -= 1
            l >>= 1 # l //= 2
            r >>= 1 # r //= 2
        if l == r:
            res = self.f(self.f(lres, self.data[l]), rres)
        else:
            res = self.f(lres, rres)
        return res

    # You can use lower_bound only if f == max.
    # return min({i | x <= i and v <= a[i]}, self.num_leaf)
    def lower_bound(self, x, v):
        x += self.num_leaf
        while self.data[x] < v:
            if x & 1: # x % 2 == 1
                if len(bin(x)) == len(bin(x+1)):
                    x += 1
                else:
                    return self.num_leaf
            else:
                x >>= 1
        while x < self.num_leaf:
            if self.data[2*x] >= v:
                x = 2*x
            else:
                x = 2*x + 1
        return x - self.num_leaf

def main():
    from sys import stdin
    input = stdin.buffer.readline

    n, q = map(int, input().split())
    a = list(map(int, input().split()))

    st = SegmentTree(n=n, f=max, default=-1)
    for i, ai in enumerate(a):
        st.update(i, ai)

    ans = []
    for _ in range(q):
        t, x, v = map(int, input().split())
        if t == 1:
            st.update(x-1, v)
        elif t == 2:
            ans.append(st.query(x-1, v))
        else:
            ans.append(min(st.lower_bound(x-1, v), n) + 1)
    
    for i in ans:
        print(i)

main()

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, m; cin >> n >> m;
  vector<bool> a(n);
  REP(i, m) {
    int s, t; cin >> s >> t;
    s--; t--;
    a[s] = !a[s];
    a[t] = !a[t];
  }
  REP(i, n) {
    if(a[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 256
//om namah shivaaay//
#include <bits/stdc++.h>
#define input int t;cin>>t;while(t--)
#define Om_namah_Shivaay ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL),cout.precision(10)
 #define ll long long
 #define vi(x)  vector<int>vec(x)
 #define pb push_back
 #define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
 #define f(i, a, b) for (int i = 0; i<(b); i++)
 #define w(t) int t;cin>>t;while(t --)
#define fr(i, a, b) for (int i = (a); i >= (b); i--)
 const int N=1e5 +5;
 using namespace std;
 int32_t main()
 {
    Om_namah_Shivaay;
    int n;
    cin>>n ;
   n=n%10;
   
    if(n==2 or n== 4 or n==5 or n==7 or n==9)
    cout<<"hon"<<endl;
    else if(n==3)
    cout<<"bon"<<endl;
    else cout<<"pon"<<endl;
  
}


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

int main(){
	int w,a,b;
	scanf("%d %d %d",&w,&a,&b);
	if(b>a+w){
		printf("%d\n",b-(a+w));
	}else if(a>b+w){
		printf("%d\n",a-(b+w));
	}else{
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int m1,d1,m2,d2;
int main(){
	cin>>m1>>d1>>m2>>d2;
	if(m1!=m2){
		cout<<1<<endl;
	}else{
		cout<<0<<endl;
	}
	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:
ll n,a,b;
ll h[100010];

bool check(ll num){
	vector<ll> ch(n);
	rep(i,n) ch[i] = max(0LL,h[i]-1LL*b*num);

	ll rest = num;
	rep(i,n){
		const ll need = (ch[i] + (a-b - 1) ) /(a-b);
		rest -= need;
	}
	if(rest < 0) return false;
	return true;
}


int main(void){
	cin >> n >> a >> b;
	rep(i,n) cin >> h[i];

	ll low = -1LL, high = 1LL << 30;

	
	while(high - low > 1){
		const ll mid = (low + high) /2LL;
		if(check(mid))
			high = mid;
		else
			low = mid;
	}

	cout << high << endl; 
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;typedef string S;int64_t n,r,i,j;S s;map<pair<S,S>,int64_t> a;main(){cin>>n>>s;for(;i<1<<n;++i){S x,y;for(j=0;j<n;++j)(i>>j&1?x:y)+=s[j];a[{x,y}]++;}while(i--){S x,y;for(j=n-1;j>=0;--j)(i>>j&1?y:x)+=s[n+j];r+=a[{x,y}];}cout<<r;}


Measured memory_bytes: 91904
#include<iostream>
#include<string>
using namespace std;
int main() {
    
    string s;
    string p;
    
    getline(cin, s);
    getline(cin, p);
    
    s = s + s;

    bool e = false;
    for (int i = 0; i < s.size(); i++) {
        
        for (int j = 0; j < p.size(); j++) {
            if (s[i + j] == p[j]) {
                e = true;
            } else {
                e = false;
                break;
            }
        }
        if (e) break;
    }

    cout << (e ? "Yes" : "No") << endl;    

    return 0;
}


Measured memory_bytes: 3204
N = int(input())

for h in range((N + 3) // 4, 3501):
    for n in range((N + 3) // 4, 3501):
        a = N * h * n
        b = 4 * h * n - N * (h + n)
        if a > 0 and b > 0 and a % b == 0:
            print("{0} {1} {2}".format(h, n, a//b))
            exit()

Measured memory_bytes: 3060