akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
int main() {
    
    ll l, r, d, i, dap=0;
    cin>>l>>r>>d;
    for(i=l;i<=r;i++)
    dap+=(i%d==0);
    
    cout<<dap;
    
    
    
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<ii>
#define li long int
#define ll long long
#define lli long long int
#define vlli vector<lli>
#define vll vector<ll>
#define vl vector<long>
#define ld long double
#define ulli unsigned long long int
 
using namespace std;

void solve() {
    string s;
    cin>>s;
    int sum = 0;
    for(auto i : s)
        sum = (sum + (int(i) - '0')) % 9;
    if(sum % 9) cout<<"No";
    else cout<<"Yes";
}

////1 1 1 1 1 0
//0 1 2 3 4 5 5

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    solve();
}

Measured memory_bytes: 3780
#include <iostream>

using namespace std;

struct card {
    string lit;
    int value;

    bool operator>(const card &other) { return value > other.value; }

    bool operator<=(const card &other) { return !(*this > other); }

    bool operator!=(const card &other) { return lit != other.lit; }

    card() { ; }

    card(const string &s) {
        lit = s;
        value = s[1] - '0';
    }
};

card A[100], B[100];

void BubbleSort(card a[], int n) {
    for (int i = 0; i < n; ++i) {
        for (int j = n - 1; j > i; --j) {
            if (a[j - 1] <= a[j]) continue;
            swap(a[j - 1], a[j]);
        }
    }
}

void SelectionSort(card a[], int n) {
    for (int i = 0; i < n; ++i) {
        int selector = i;
        for (int j = i; j < n; ++j) {
            if (a[selector] > a[j])selector = j;
        }
        if (selector != i) {
            swap(a[i], a[selector]);
        }
    }
}

void outputArray(card a[], int n) {
    cout << a[0].lit;
    for (int i = 1; i < n; ++i) {
        cout << ' ' << a[i].lit;
    }
    cout << endl;
}

bool isEqual(card a[], card b[], int n) {
    for (int i = 0; i < n; ++i) if (a[i] != b[i]) return false;
    return true;
}

int main() {
    int n;
    string s;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        A[i] = B[i] = card(s);
    }
    BubbleSort(A, n);
    SelectionSort(B, n);
    outputArray(A, n);
    cout << "Stable" << endl;
    outputArray(B, n);
    cout << (isEqual(A, B, n) ? "Stable" : "Not stable") << endl;
    return 0;
}



Measured memory_bytes: 3160
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC174
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = NK[0]; var K = NK[1];
            var A = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            var ok = A.Max();
            var ng = 0L;

            while (1 < Math.Abs(ok - ng))
            {
                var m = (ok + ng) / 2;
                var cnt = 0L;
                for (int i = 0; i < N; i++)
                {
                    cnt += (long)Math.Ceiling((double)A[i] / (double)m) - 1;
                }

                if (cnt <= K)
                    ok = m;
                else
                    ng = m;

            }
            Console.WriteLine(ok);
        }
    }
}


Measured memory_bytes: 49640
#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>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
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 = 1e12;
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

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
map<char, ll> mci;
string table = "MARCH";

int main() {
	cin >> n;
	rep(i, n) {
		string s;
		cin >> s;
		mci[s[0]]++;
	}
	ll ans = 0;
	rep(i, 5) {
		FOR(j, i + 1, 5) {
			FOR(k, j + 1, 5) {
				ans += mci[table[i]] * mci[table[j]] * mci[table[k]];
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
use std::collections::HashMap;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let k: usize = read();
    let mut map = HashMap::new();

    for _ in 0..n {
        let x: i64 = read();
        *map.entry(x).or_insert(0) += 1;
    }
    let mut vec: Vec<_> = map.iter().collect();
    vec.sort_by_key(|&k| k.1);

    let mut ans = 0;
    for i in 0..if vec.len() < k { 0 } else { vec.len() - k } {
        ans += *vec[i].1
    }
    println!("{}", ans);
}

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


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

int main(){
    int n;
    int max_=0;
    int ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        int m;
        scanf("%d",&m);
        if(i==1)
            max_=m;
        if(m<=max_){
            ans++;
            max_=m;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
using System;
class test{
public static void Main(){
  var str = Console.ReadLine().Split(' ');
  int X = int.Parse(str[0]);
  int Y = int.Parse(str[1]);
  int count = 0;
  while(X/Y != 0){
     X /= Y; 
     count++;
  }
  count++;
  Console.Write(count);
}
}

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;


const int MAX = 150001;  
int main(){
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < s.size(); ++i){
        if (s[i] != t[i]) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 3460
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect

s = input()
n = len(s)

if s[n-1] == "1" or s[0] == "0":
    print(-1)
    sys.exit()

for i in range((n-1) // 2):
    if s[i] != s[n-2-i]:
        print(-1)
        sys.exit()

j = 0
for i in range(1,n):
    if s[i] == "1":
        for k in range(j,i):
            print(k+1,i+1)
        j = i

for k in range(j+1,n):
    print(j+1,k+1)





Measured memory_bytes: 75736
#include<stdio.h>
#include<math.h>
int main(void){
    int w,h,n;
    int X[1000],Y[1000];
    int i,j,k;
    int ans,min,difx,dify;

    scanf("%d%d%d",&w,&h,&n);
    scanf("%d%d",&X[0],&Y[0]);

    ans=0;
    for(i=1;i<n;i++){
	scanf("%d%d",&X[i],&Y[i]);
	if(X[i]>X[i-1] && Y[i]>Y[i-1]||
	   X[i]<X[i-1] && Y[i]<Y[i-1]){
	    difx=abs(X[i]-X[i-1]);
	    dify=abs(Y[i]-Y[i-1]);
	    if(difx>dify) ans+=difx;
	    else ans+=dify;
	}else{
	    if(X[i]>X[i-1]) ans+=X[i]-X[i-1];
	    else ans+=X[i-1]-X[i];
	    if(Y[i]>Y[i-1]) ans+=Y[i]-Y[i-1];
	    else ans+=Y[i-1]-Y[i];
	}
    }

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

    return 0;
}

Measured memory_bytes: 604
inp = []
i = 0
j = 0

while True:
    inp.append(input().split())
    if inp[i][1] == "?":
        break
    i += 1

for j in range(i):
    if inp[j][1] == "+":
        print("%s" % (int(inp[j][0]) + int(inp[j][2])))
    elif inp[j][1] == "-":
        print("%s" % (int(inp[j][0]) - int(inp[j][2])))
    elif inp[j][1] == "*":
        print("%s" % (int(inp[j][0]) * int(inp[j][2])))
    elif inp[j][1] == "/":
        print("%d" % (int(inp[j][0]) / int(inp[j][2])))
    elif inp[j][1] == "%":
        print("%s" % (int(inp[j][0]) % int(inp[j][2])))
    else:
        break


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N,ans;
    cin>>N;
	ans=0;
    vector<pair<int,int>>A(N);
    vector<vector<int>>dp(N+1,vector<int>(N+1,0));
    REP(i,N){
        int a;cin>>a;
      	A[i]=make_pair(a,i);
    }
    sort(A.rbegin(),A.rend());
    REP(i,N){
        int ls=A[i].second;
        int rs=N-1-ls;
      	int value=A[i].first;
        for(int j=0;j<=i+1;j++){
            if(j==0) dp[i+1][0]=dp[i][0]+value*(rs-i);
            if(j==i+1) dp[i+1][i+1]=dp[i][i]+value*(ls-i);
            if(j!=0&&j!=i+1) dp[i+1][j]=max(dp[i][j-1]+value*(ls-(j-1)),dp[i][j]+value*(rs-i+j));
            if(i==N-1)ans=max(ans,dp[N][j]);
        }
    }
    cout<<ans<<endl;
}

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

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

int main()
{
    fastio;
    ll h,w,z;cin>>h>>w>>z;
    int a[h][w];
    rep(i,0,h)rep(j,0,w)
    {
        char ch;cin>>ch;
        a[i][j]=ch-'0';
    }
    rep(i,0,h)
        rep(j,1,w)
            a[i][j]+=a[i][j-1];

    rep(i,1,h)
        rep(j,0,w)
            a[i][j]+=a[i-1][j];

    ll ans=INF;
    for(int i=0;i<(1ll<<h);i++)
    {
        ll cnt=0,li=0;
        bool cant=0;
        vector<int> lookat;
        for(int j=1;j<h;j++)
            if(i&(1ll<<j))lookat.pb(j-1);
        lookat.pb(h-1);
        int sz=lookat.size();
        for(int j=0;j<w;j++)
        {
            ll mx=0;
            for(int k=0;k<sz;k++)
            {
                ll sum;
                if(k==0)sum=a[lookat[k]][j]- (li!=0 ? a[lookat[k]][li-1] : 0);
                else sum=a[lookat[k]][j]-a[lookat[k-1]][j]- (li!=0 ? (a[lookat[k]][li-1]-a[lookat[k-1]][li-1]) : 0);
                mx=max(mx,sum);
            }
            if(mx>z)
            {
                if(j==li){cant=1;break;}
                else cnt++,li=j;
            }
        }
        if(!cant)ans=min(ans,sz-1+cnt);
    }
    cout<<ans;
}


Measured memory_bytes: 256
import java.util.*;

// ARC 98-D
// https://beta.atcoder.jp/contests/arc098/tasks/arc098_b

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int answer = 0;
		int N = in.nextInt();
		
		for (int i = 1; i <= N; i += 2) {
			int nums = 0;
			for (int j = 1; j <= i; j++) {
				if (i % j == 0) {
					nums++;
				}
			}
			
			if (nums == 8) {
				answer++;
			}
		}
		
		System.out.println(answer);
    }
}


Measured memory_bytes: 23892
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

d = [(1,0),(0,1)]
def solve():
    h,w = LI()
    s = [input() for i in range(h)]
    bfs = [[float("inf")]*w for i in range(h)]
    bfs[0][0] = 1&(s[0][0] == "#")
    q = [(bfs[0][0],0,0)]
    while q:
        b,y,x = heappop(q)
        if (y,x) == (h-1,w-1):
            print(b)
            return
        for dy,dx in d:
            ny,nx = y+dy,x+dx
            if 0 <= ny < h and 0 <= nx < w:
                if s[ny][nx] == "#" and s[y][x] != "#":
                    nb = b+1
                else:
                    nb = b
                if nb < bfs[ny][nx]:
                    bfs[ny][nx] = nb
                    heappush(q,(nb,ny,nx))
    return

#Solve
if __name__ == "__main__":
    solve()


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n;
    vl a(3);
    cin >> n >> a[0] >> a[1]>> a[2];
    vl l(n);
    rep(i,n)cin>>l[i];
    ll res = L_INF;
    for(int a1=1;a1<(1<<n);a1++){
        for(int a2=1;a2<(1<<n);a2++){
            if(a1 & a2) continue;
            for(int a3=1;a3<(1<<n);a3++){
                if(a1 & a3)continue;
                if(a2 & a3)continue;
                vl sum(3,0),cnt(3,0);
                rep(j,n){
                    if(a1 & (1<<j)){
                        sum[0]+=l[j];
                        cnt[0]++;
                    }
                    if(a2 & (1<<j)){
                        sum[1]+=l[j];
                        cnt[1]++;
                    }
                    if(a3 & (1<<j)){
                        sum[2]+=l[j];
                        cnt[2]++;
                    }
                }
                ll ans = 0;
                rep(j,3){
                    ans += abs(a[j] - sum[j]);
                    ans += 10 * (cnt[j]-1);
                }
                res = min(ans,res);
            }
        }
    }
    out(res);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+1;
int l[MAXN],r[MAXN],a[MAXN];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,i;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	l[0]=a[0];
	r[n-1]=a[n-1];
	for(i=1;i<n;i++)
	{
		l[i]=__gcd(l[i-1],a[i]);
		r[n-1-i]=__gcd(r[n-i],a[n-1-i]);
	}
	int ans=max(r[1],l[n-2]);
	for(i=1;i<n-1;i++)
		ans=max(ans,__gcd(l[i-1],r[i+1]));
	cout<<ans<<'\n';
}


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

int main() {
    ll N, K;
    cin >> N;
    cin >> K;
    ll a[N];
    rep(i, N) cin >> a[i];
    cout << ceil((double)(N-1) / (K-1)) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
    int n, i;
    long int debt = 100000;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        debt *= 1.05;
        if (debt % 1000)
            debt = debt - (debt % 1000) + 1000;
    }
    printf("%ld\n", debt);

    return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

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

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    char a;
    cin >> a;
    if(a == 'A' || a == 'B' ||a == 'C' ||a == 'D' ||a == 'E' ||a == 'F' ||a == 'G' ||a == 'H' ||a == 'I' ||
    a == 'J' ||a == 'K' ||a == 'L' ||a == 'M' ||a == 'N' ||a == 'O' ||
    a == 'P' ||a == 'Q' ||a == 'R' ||a == 'S' ||
    a == 'T' ||a == 'U' ||a == 'V' ||a == 'W' ||a == 'X' ||a == 'Y' ||a == 'Z') print('A');
    else print('a');




}




Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
vector<long long> segment;
int n,t,b[200001];

long long getmax(int a , int b , int curr , int l , int r){
    if(a > r || b < l){
        return 0;
    }
    if(a <= l && b >= r){
        return segment[curr];
    }
    int m = (l+r)/2;
    return max(getmax(a,b,2*curr,l,m),getmax(a,b,2*curr+1,m+1,r));
}

void update(int curr , long long val){
    curr += t;
    segment[curr] = val;
    curr /= 2;
    while(curr){
        segment[curr] = max(segment[2*curr],segment[2*curr+1]);
        curr /= 2;
    }
}

int main(){
    cin >> n;
    t = pow(2,ceil(log2(n)));
    segment.resize(2*t,0);
    vector<pair<int,int>> v;
    for(int i = 0 ; i < n ; i += 1){
        int a;
        cin >> a;
        v.push_back({a,i});
    }
    sort(v.rbegin(),v.rend());
    for(int i = 0 ; i < n ; i += 1){
        cin >> b[i];
    }
    long long ans = 0;
    for(pair<int,int> i : v){
        update(i.second,b[i.second]+getmax(i.second+1,t,1,1,t));
        ans = max(ans,segment[i.second+t]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6768
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector <long long> A(N), S(N);
    
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }

    S[0] = A[0];
    for (int i = 1; i < N; i++){
        S[i] = S[i - 1] + A[i];
    }
    
    

    sort(S.begin(), S.end());

    long long ans = 0, c = 1, c0 = 0;

    for (int i = 0; i < N; i++){
        if (S[i] == 0){
            c0++;
            c = 1;
        }else{
            if(i == N - 1){
                ans += c * (c - 1) / 2;
                break;
            }else if(S[i] == S[i + 1]){
                c++;
            }else{
                ans += c * (c - 1) / 2;
                c = 1;
            }
        }
    }

    if (c0 > 0){
        ans += c0 * (c0 + 1) / 2;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
def count (arr1)
  arr = Marshal.load(Marshal.dump(arr1))
  ret = 0
  (arr.length-1).times{|c|
    if arr[c] == arr[c+1] then
      ret = ret + 1
      arr[c+1] ="1"
    end
  }
  return ret
end

str = gets.chomp.split("")
n = gets.to_i
  
if str[0] != str[str.length - 1] then
  puts n*count(str)
else
  len = str.length
  c0 = str[0]
  dropstart = str.drop_while{ |c| c == c0 }
  if dropstart.length == 0 then
    puts len*n/2
  else
  s = len - dropstart.length
  center = dropstart.reverse.drop_while{ |c| c == c0 }
  e = len - s - center.length
  puts (e / 2) + (s / 2) +  ((e+s)/2)*(n-1) + n*count(center)
  end
end


Measured memory_bytes: 1788
N = int(input())
A = list(map(int, input().split()))
n0 = A.count(0)
n1 = A.count(1)
import math
ans = 1
if N-n0-n1>60:
  ans = -1
for i in range(N):
  if A[i] == 0 or ans == 0:
    ans = 0
    break
  elif ans <0:
    ans = -1
  elif math.log10(A[i])+math.log10(ans)>18:
    ans = -1
    b = 1
  else:
    ans *= A[i]

if ans == 0:
  print(0)
elif ans < 0:
  print(-1)
elif ans>10**18:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 21628
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true){
      int n = sc.nextInt();
      int r = sc.nextInt();
      if(n==0&&r==0){
        break;
      }
      int[] a = new int[n];
      for(int i=n;i>=1;i--){
        a[n-i] = i;
       // System.out.println(a[n-i]);
      }
      for(int k=0;k<r;k++){
          int p = sc.nextInt();
          int c = sc.nextInt();
          for(int i=0;i<c;i++){
            for(int j=p;j>=2;j--){
            int temp;
            temp = a[j+i-1];
            a[j+i-1] =a[j+i-2];
            a[j+i-2] = temp;
            }
           /* for(int j=0;j<n;j++){
           // System.out.println(a[j]);
              }*/
          }
      }
      System.out.println(a[0]);
    }
  }
}


Measured memory_bytes: 40632
#include<stdio.h>
#define GRAY 2
#define N 101
  
int color[N],d[N],f[N],e[N],count,A[N][N],v[N],B[N][N];
 
void DFE_Visit(int);
void DFS(int);
 
main(){
  int n,i,j,v1;
 
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      A[i][j]=0;
    }
  }
  
  scanf("%d",&n);
    
  for(i=1;i<=n;i++){
    scanf("%d%d",&v[i],&e[i]);
    for(j=1;j<=e[i];j++){
      scanf("%d",&v1);
      B[i][j]=v1;
      A[i][v1]=1;
    }
  }
  DFS(n);
  
  return 0;
}
 
 
void DFS(int n){
  int i,u;
    
  for(i=1;i<=n;i++){
    u=v[i];
    color[u]=0;
  }
 
    count=0;
    
  for(i=1;i<=n;i++){
    u=v[i];
    if(color[u]==0)DFE_Visit(u);
    printf("%d %d %d\n",u,d[u],f[u]);
  }
}
 
 
void DFE_Visit(int u){
  int v,i;
    
  color[u]=GRAY;
  d[u]=++count;
  
  for(i=1;i<=e[u];i++){
    v=B[u][i];
    if(color[v]==0)DFE_Visit(v);
  }
  color[u]=1;
  f[u]=++count;
}

Measured memory_bytes: 676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    ll n,m; cin>>n>>m;
    vector<ll> h(n);
    vector<vector<ll>> edge(n);
    rep(i,0,n) cin>>h[i];
    rep(i,0,m){
        ll x,y;
        cin>>x>>y;
        x--; y--;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }

    ll ans=0;
    rep(i,0,n){
        bool ok=true;
        rep(j,0,edge[i].size()){
            if(h[i]<=h[edge[i][j]]) ok=false;
        }
        if(ok) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

typedef vector<vector<int>> Graph; 
vector<bool> seen;
vector<ll> counter,ADD;
void dfs(Graph &T,int num,ll cnt){
    seen[num]=true;
    counter[num] = cnt;
    for(int i=0;i<T[num].size();i++){
        if(seen[T[num][i]])continue;
        dfs(T,T[num][i],cnt+ADD[T[num][i]]);
    }
}

int main(){
    int N,Q;
    cin >> N >> Q;
    Graph T(N+1,vector<int>(0));
    seen.resize(N+1,false);
    counter.resize(N+1,0);
    ADD.resize(N+1,0);
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        T[a].push_back(b);
        T[b].push_back(a);
    }
    rep(i,Q){
        ll p,x;
        cin >> p >> x;
        ADD[p]+=x;
    }
    dfs(T,1,ADD[1]);
    rep(i,N)cout << counter[i+1] << " ";
    cout << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

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

    int A, B;
    cin >> A >> B;

    vector<int> xs, ys, zs;

    for (int k = 1; k <= 10010; ++k)
        if (k * 8 / 100 == A)
            xs.push_back(k);

    for (int k = 1; k <= 10010; ++k)
        if (k * 10 / 100 == B)
            ys.push_back(k);
#ifdef DEBUG
    cout << "xs = ";
    for (auto x : xs)
        cout << x << ' ';
    cout << endl;

    cout << "ys = ";
    for (auto y : ys)
        cout << y << ' ';
    cout << endl;
#endif

    set_intersection(xs.begin(), xs.end(), ys.begin(), ys.end(), back_inserter(zs));
 
    if (not zs.empty())
        cout << zs.front() << '\n';
    else
        cout << -1 << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll A, B, M; cin >> A >> B >> M;
    vector<ll> a(A), b(B);
    rep(i, A){cin >> a.at(i);}
    rep(i, B){cin >> b.at(i);}
    ll ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    rep(i, M){
        ll x, y, z; cin >> x >> y >> z; x--; y--;
        ll tmp = a.at(x) + b.at(y) - z;
        if (tmp < ans){ans = tmp;}
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

const int N = 100005;

int n, a[N], r;

int main(){
    scanf("%d", &n);
    for(int i = 1, x; i <= n; i++){
        scanf("%d", &x);
        a[i] = (x == i);
    }
    for(int i = 1; i <= n; i++){
        if(a[i]){ r++; a[i] = a[i + 1] = 0; }
    }
    printf("%d\n", r);
}

Measured memory_bytes: 640
S = input()

N = len(S)+1
a = [0] * N
for i in range(N-1):
    if S[i] == '<':
        a[i+1] = max(a[i+1], a[i]+1)
for i in range(N-2, -1, -1):
    if S[i] == '>':
        a[i] = max(a[i], a[i+1]+1)

print(sum(a))

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

int main()
{
  string S;
  string T;

  cin >> S >> T;

  int count = 0;

  for (int i = 0; i < S.length(); i++)
  {
    if (S.at(i) != T.at(i))
    {
      count++;
    }
  }

  cout << count << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

class Edge;
class Node {
 public:
  vector<Edge *> con_edges;
  vector<Node *> con_nodes;
};

class Edge {
 public:
  Node *a;
  Node *b;
  int color;
};

Edge *EDGE_NIL;

void Paint(Node *node, Edge *parent_edge = EDGE_NIL) {
  int color = 1;
  FOR(i, 0, node->con_edges.size()) {
    if (node->con_edges[i] == parent_edge) {
      continue;
    }
    Node *child = node->con_edges[i]->a;
    if (child == node) child = node->con_edges[i]->b;

    // color
    if (parent_edge != EDGE_NIL) {
      if (parent_edge->color == color) color += 1;
    }
    node->con_edges[i]->color = color;
    color++;
    Paint(child, node->con_edges[i]);
  }
}

int main() {
  int n;
  cin >> n;
  vector<Node> nodes(n);
  vector<Edge> edges(n - 1);
  FOR(i, 0, n - 1) {
    int a, b;
    cin >> a >> b;
    edges[i].a = &nodes[a - 1];
    edges[i].b = &nodes[b - 1];
    nodes[a - 1].con_edges.push_back(&edges[i]);
    nodes[b - 1].con_edges.push_back(&edges[i]);
    nodes[b - 1].con_nodes.push_back(&nodes[a - 1]);
    nodes[a - 1].con_nodes.push_back(&nodes[b - 1]);
  }
  int k = 0;
  FOR(i, 0, n) { k = max(k, (int)nodes[i].con_edges.size()); }
  Node *seek = &nodes[0];
  Node *seek_parent;
  while (true) {
    if (seek->con_nodes.size() == 1) break;
    Node *other = seek->con_nodes[0];
    if (other == seek_parent) {
      other = seek->con_nodes[1];
    }
    seek_parent = seek;
    seek = other;
  }
  Node *root = seek;
  Paint(root);
  cout << k << endl;
  FOR(i, 0, n - 1) { cout << edges[i].color << endl; }
  return 0;
}


Measured memory_bytes: 14976
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(998244353)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

// 素数かどうかの判定
bool IsPrime(ll num){
    if(num<2) return false;
    else if(num==2) return true;
    else if(num%2==0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for(ll i=3; i<=sqrtNum; i+=2){
        if(num%i==0) return false;
    }
    return true;
}


signed main() {
	ll sum = 0LL; ll cnt[100005];
	rep(i,100005) cnt[i]=0LL;
	int n; cin>>n;
	rep(i,n){
		ll a; cin>>a; sum+=a; cnt[a]++;
	}
	int q; cin>>q;
	while(q--){
		ll b,c; cin>>b>>c;
		sum-=b*cnt[b]; sum+=c*cnt[b];
		cnt[c]+=cnt[b]; cnt[b]=0LL;
		cout<<sum<<endl;
	}
	return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define mo 1000000007
#define MAX 304
#define fast_io ios::sync_with_stdio(false)
int d[MAX][MAX], a[MAX][MAX];
std::vector<pair<int, pair<int, int> > > v;
int main()
{
	fast_io;
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			a[i][j] = 1e9 + 4;
			int x;
			cin >> x;
			d[i][j] = x;
			v.pb(mp(x,mp(i,j)));
		}

	}
	sort(v.begin(), v.end());
	long long ans = 0;
	for(int i=0;i<v.size();i++)
	{
		int x = v[i].second.first;
		int y = v[i].second.second;
		int temp = 1e9 + 4;
		for(int j=1;j<=n;j++)
		{
			if(j==x || j==y)
				continue;
			if((a[x][j] + a[j][y])<temp)
				temp = a[x][j] + a[j][y];
		}
		if(temp > v[i].first)
		{
			ans += v[i].first;
			a[x][y] = v[i].first;
			a[x][y] = v[i].first;
		}
		else
		{
			a[x][y] = temp;
			a[x][y] = temp;

		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
			if(a[i][j]!=d[i][j])
			{
				cout << -1;
				return 0;
			}
	}
	cout << (ans/2) << "\n";
	return 0;
}

Measured memory_bytes: 2424
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<tuple>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<tuple<string, int, int>> r(n);
    for(int i = 0; i < n; i++){
        string s;
        int p;
        cin >> s >> p;
        r[i] = make_tuple(s, -p, i + 1);
    }
    sort(begin(r), end(r));
    for(int i = 0; i < n; i++){
        tie(ignore, ignore, ans) = r[i];
        cout << ans << endl;
    }
    return 0;
}


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

typedef long long ll;
typedef long double ldb;

int n;
ldb d, x;

int main() {
	double dd, xx;
	scanf("%d%lf%lf", &n, &dd, &xx); d = dd, x = xx;
	
	ldb ans = 0;
	for (int i = n; i; --i) {
		ans += d + (i * 2 - 1) * x / 2;
		
		d = (d * (i * 2 + 2) + x * 5) / (i * 2);
		x = (i * 2 + 4) * x / (i * 2);
	}
	
	printf("%.12f\n", (double)ans);
	
	return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val p = (1..N).map { readLine()!!.toInt() }.sortedDescending()
    var S = p.first() / 2
    for (i in 1 until N) {
        S += p[i]
    }
    println(S)
}

Measured memory_bytes: 36300
import sys
def f0070(A,n,s):
  if n==1:return s in A
  A=sorted(A)
  A1=A[:n][::-1]
  A2=A[-n:]
  N=range(n)
  b1=0
  b2=0
  c=0
  for i in N:
    b1+=(i+1)*A1[i]
    b2+=(i+1)*A2[i]
  if b1<=s<=b2:
    for i in range(len(A)):
      b=s-A[i]*n
      c+=f0070(A[:i]+A[i+1:],n-1,b)
  return c
for a in sys.stdin:
  n,s=map(int,a.split())
  print f0070(range(10),n,s)

Measured memory_bytes: 4252
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int n;
ll x,ans,cur=2;
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>x;
    ans=x-1;
    while(--n)
	{
		cin>>x;
		if(cur==x)cur++;
		else ans+=(x-1)/cur;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int R,C,K;
  cin>>R>>C>>K;
  vector<vector<int64_t>> p(R,vector<int64_t>(C));
  for(int i=0;i<K;i++){
    int a,b;
    int64_t c;
    cin>>a>>b>>c;
    a--,b--;
    p[a][b]=c;
  }
  vector<vector<vector<int64_t>>> dp(R,vector<vector<int64_t>>(C,vector<int64_t>(4)));
  dp[0][0][1]=p[0][0];
  for(int i=0;i<R+C-1;i++){
    for(int j=max(0,i-R+1);j<min(C,i+1);j++){
      int a=i-j,b=j;
        if(a<R-1){
          dp[a+1][b][1]=max(dp[a+1][b][1],max(max(dp[a][b][0],dp[a][b][1]),max(dp[a][b][2],dp[a][b][3]))+p[a+1][b]);
          dp[a+1][b][0]=max(dp[a+1][b][0],max(max(dp[a][b][0],dp[a][b][1]),max(dp[a][b][2],dp[a][b][3])));
        }
      if(b<C-1){
        for(int k=0;k<4;k++){
          if(k!=3){
            dp[a][b+1][k+1]=max(dp[a][b+1][k+1],dp[a][b][k]+p[a][b+1]);
          }
          dp[a][b+1][k]=max(dp[a][b+1][k],dp[a][b][k]);
        }
      }
    }
  }
  int64_t Z=0;
  for(int k=0;k<4;k++){
    Z=max(Z,dp[R-1][C-1][k]);
  }
  cout<<Z<<endl;

    
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int i = 0; i < c; i++) {
		if (b) {
			b--;
			ans += 2;
		}
		else if(a) {
			a--;
			ans++;
		}
		else {
			ans++;
			break;
		}
	}
	cout << ans + b << "\n";
}

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


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

  int main() {
    vector<int> P(81);
    int N;
    int M=0;
    int count=0;
    cin >> N;
    
    for(int i=1; i<=9; i++){
      for(int j=1; j<=9; j++){
        P.at(M)=i*j;
        M++;
      }
    }

    for(int i=0; i<81; i++){
      if(N==P.at(i)){
        cout << "Yes" << endl;
        break;
      }

      else
        count++;
          
    }
    if(count==81)
      cout << "No" << endl;
      
        
   }

      

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
int main()
{
	int k, x;
	cin >> k >> x;

	for (int i =(k/-1)+1; i < k; i++) {
		cout << i+x << " ";
	}
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007
#define INF 1001001001

int n, x, l, ans = 1;

typedef struct {
    int left;
    int right;
} Pair;

Pair b[100100];

int cmp(const Pair *a, const Pair *b){
    return (*a).right - (*b).right;
}

main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d%d", &x, &l);
        b[i].left = x - l;
        b[i].right = x + l;
    }
    qsort(b, n, sizeof(Pair), cmp);
    int nyan = b[0].right;
    for(int i=1; i<n; i++){
        while(i<n && nyan > b[i].left){
            i++;
        }
        if(i<n){
            nyan = b[i].right;
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int tp;
vector<int> vl,vr;
void work(long long n)
{
	if (n==1) return;
	work(n/2);
	tp++;vl.push_back(tp);vr.push_back(tp);
	if (n&1) {tp++;vl.push_back(tp);vr.insert(vr.begin(),tp);}
}
int main()
{
	long long n;scanf("%lld",&n);
	work(n+1);
	printf("%d\n",vl.size()+vr.size());
	for (int i=0;i<vl.size();i++) printf("%d ",vl[i]);
	for (int i=0;i<vr.size();i++) printf("%d ",vr[i]);
}

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

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string S;cin >> S;

    int counter = 0;
    char c='0';

    for (auto s:S)
    {
        if (c=='0') c=s;
        else
        {
            if (s!=c)
            {
                counter++;
                c=s;
            }
        }
        
    }
    cout << counter << endl;
    return 0;
}



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

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

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int gcdEx(int a, int b, int *x, int *y){if(!a){*x=0;*y=1;return b;}
int x1,y1,gcd=gcdEx(b%a,a,&x1,&y1); *x=y1-(b/a)*x1;*y=x1; return gcd;}
int modI(int b, int m)      {int x,y;gcdEx(b,m,&x,&y);return (x%m+m)%m;}
typedef long long           ll;
typedef pair<int, int>      pii;
typedef vector<int>         vi;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define loop(i,b,n)           for(int i=b;i<n;i++)
#define loopv(b,n,a)         for(int i=b;i<n;i+=a)
#define loopr(b,n)           for(int i=n;i>=0;i--)

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define mp                  make_pair
#define ff                  first
#define ss                  second
#define pb                  push_back
#define MOD                 1000000007
#define modA(a,b)           (((a%MOD)+(b%MOD))%MOD)
#define modS(a,b)           (((((a%MOD)-(b%MOD))%MOD)<0)?(int)(MOD+((a%MOD)-(b%MOD))%MOD):(int)(((a%MOD)-(b%MOD))%MOD))
#define modM(a,b)           (int)((((ll)(a%MOD))*((ll)(b%MOD)))%MOD)
#define modD(a,b)           ((modI(b,MOD)*(a%MOD))%MOD)
ll modP(ll x, ll y)         {ll r=1; x%=MOD; while(y>0){if(y&1){r=(r*x)%MOD;}
y=y>>1; x=(x*x)%MOD;} return r;}

#define trace2(x, y)               cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
ll fib(vector<ll> f,ll n,ll a,ll b)
{
    trace2(n,f[n]);
  if(n<a)
    return 0;
    if (n == a )
        return 1;
    if(n>a)
    {
        if(n<b)
        {
            if(n%a==0)
                return 1;
            else
                return 0;
        }
        else
        {    if(n==b)
    {if(n%a==0)
            {
                f[n]=2;
                return f[n];
     }    else
    return 1;
  }



        }
    }
    if (f[n])
        return f[n];
    int k = (n & 1)? (n+1)/2 : n/2;
    f[n] = (n & 1)? modA(modM(fib(f,k,a,b),fib(f,k,a,b)) , modM(fib(f,k-1,a,b),fib(f,k-1,a,b))):
        modA(2*fib(f,k-1,a,b) ,modM( fib(f,k,a,b),fib(f,k,a,b)));
      trace2(n,f[n]);
    return f[n];
}
int main()
{
//    freopen("input.txt","r",stdin);
ll t;
t=1;
while(t--)
{
    ll n;
    cin>>n;
ll ans=n*n;
cout<<ans<<"\n";
}
return 0;
}



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

int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> X(N + 1), Y(N + 1);
  for (int i = 0, a, b; i < M && cin >> a >> b; i++) {
    if (a == 1) X.at(b) = 1;
    if (b == N) Y.at(a) = 1;
  }
  string ans = "IMPOSSIBLE";
  for (int i = 0; i < N + 1; i++) if (X.at(i) && Y.at(i)) ans = "POSSIBLE";
  cout << ans << "\n";
}

Measured memory_bytes: 1792
from collections import deque
 
n,p=map(int ,input().split())
que=deque([])
 
for i in range(n):
    name,time=input().split()
    time=int(time)
    que.append([name,time])
 
t=0
while len(que)>0:
    atop=que.popleft()
    spend=min(atop[1],p)
    atop[1]-=spend
    t+=spend
    if(atop[1]==0):
        print(atop[0],t)
    else:
        que.append(atop)


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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N;
  cin>>N;

  cout<<(N-1)/2<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define sum(a) accumulate(a.begin(),a.end(),0LL)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    string s; cin >> s;
    string t; cin >> t;
    string a;

    if(string::npos != s.find(t)){
        a = s;
        for(long long i = 0; i < a.size(); i++){
            if(a[i] == '?') a[i] = 'a';
        }
        put(a);
        return 0;
    }

    for(long long i = s.size()-1; i >= t.size()-1; i--){
        ll flag = 1;
        for(long long j = 0; j < t.size(); j++){
            if(s[i-j] != t[t.size()-j-1] and s[i-j] != '?'){
                flag = 0;
                break;
            }
            //cout << "s:" << s[i-j] << " t:" << t[t.size()-j-1] << endl;
        }
        if(flag){
            a = s;
            for(long long j = 0; j < t.size(); j++){
                a[i-j] = t[t.size()-j-1];
            }
            break;
        }
    }

    for(long long i = 0; i < a.size(); i++){
        if(a[i] == '?') a[i] = 'a';
    }

    if(a.size() > 0) put(a);
    else put("UNRESTORABLE");
}

Measured memory_bytes: 3576