akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            // var line = consoleReader.SplitInt32();
            var N = consoleReader.Int64();
            if (N < 3) return 0;

            var yakusu = Yakusu(N);
            long sum = 0;
            foreach (var y in yakusu.OrderBy(l => l))
            {
                var x = N / y - 1;
                if (x < 2)
                    break;
                if (x <= y)
                    continue;
                sum += x;
            }
            return sum;
        }

        IEnumerable<long> Yakusu(long num)
        {
            yield return 1;
            long amari;
            var sqrt = (long)Math.Sqrt(num);
            for (int l = 2; l <= sqrt; l++)
            {
                var d = Math.DivRem(num, l, out amari);
                if (amari == 0)
                {
                    yield return l;
                    yield return d;
                }
            }
        }

        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader
    {
        public virtual string String() => Console.ReadLine(); public int Int32() => int.Parse(String()); public long Int64() => long.Parse(String()); public ulong UInt64() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray(); public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); }
        public IEnumerable<int> RepeatInt32(int count) { for (int i = 0; i < count; i++) yield return Int32(); }
        public IEnumerable<long> RepeatInt64(int count) { for (int i = 0; i < count; i++) yield return Int64(); }
        public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); }
        public IEnumerable<int[]> RepeatSplitInt32(int count) { for (int i = 0; i < count; i++) yield return SplitInt32(); }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

typedef pair<ll, int> LIP;
vector<LIP> factorize(ll n) {
    vector<LIP> res;
    for(ll i=2; i*i<=n; i++) {
        if (n % i) continue;
        res.emplace_back(i, 0);
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

int wa[200];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin>>n;
    vector<LIP> t = factorize(n);
    wa[0] = 0;
    wa[1] = 1;
    for(int i=2; i<200; i++){
        wa[i] = wa[i-1]+i;
    }
    int ans = 0;
    for(auto a : t){
        rep(i,200){
            if(wa[i] > a.second){
                ans+=(i-1);
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(){
  int n;
  int i,now,num=1,b_count=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&now);
    if(now==num){
      num++;
    } else {
      b_count++;
    }
  }
  if(num!=1){
    printf("%d",b_count);
  } else {
    printf("-1");
  }
}

Measured memory_bytes: 128
#include <stdio.h>
 
int main(void)
{
    int i, j, k;
    int n, m, l;
    int a[100][100]={};
    int b[100][100]={};
    long long int c[100][100]={};
     
    scanf("%d%d%d", &n, &m, &l);
     
    for(i=0; i<n; i++) {
        for(k=0; k<m; k++)
            scanf("%d", &a[i][k]);
    }
    for(k=0; k<m; k++) {
        for(j=0; j<l; j++)
            scanf("%d", &b[k][j]);
    }
     
    for(i=0; i<n; i++) {
        for(j=0; j<l; j++) {
            for(k=0; k<m; k++)
                c[i][j]+=a[i][k]*b[k][j];
        }
    }
     
    for(i=0; i<n; i++) {
        for(j=0; j<l; j++) {
            printf("%lld", c[i][j]);
            if(j!=l-1) putchar(' ');
        }
        putchar('\n');
    }
     
    return 0;
}


Measured memory_bytes: 2072
N , X = map(int,input().split())
alist = list(map(int,input().split()))
first = sum(alist)
# 単独でXを超えている場合は減らす
for i in range(N):
    if alist[i] > X:
        alist[i] = X
# alistは最大値がXのリストになっている
for i in range(N-1):
    if alist[i]+alist[i+1] > X:
        alist[i+1] = (X - alist[i]) 

print(first - sum(alist))

Measured memory_bytes: 14540
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
    
int main() {
  int N, M;
  cin >> N >> M;

  vector<int> X;
  for (int i=0; i < M; i++) {
    int m;
    cin >> m;
    X.push_back(m);
  }
  sort(X.begin(), X.end());
  
  vector<int> diff;
  for (int j=0; j < X.size() - 1; j++) {
    diff.push_back(X[j+1] - X[j]);
  }
  sort(diff.begin(), diff.end());

  
  if (N >= M) {
    cout << 0 << endl;
  } else {
    int sum;
    for (int i=0; i < M - N; i++) {
      sum += diff[i];
    }
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 1400
// ayy
// ' lamo
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld; //CARE
typedef complex<ld> pt;
#define fi first
#define se second
#define pb push_back
const ld eps=1e-8;
const int inf=1e9+99;
const ll linf=1e18+99;
const int P=1e9+7;













int32_t main() {
	string S; cin>>S; cout<<S.substr(0,S.size()-8)<<endl;
}













Measured memory_bytes: 256
<?php
    fscanf(STDIN, "%d %d", $a, $b);
    $r1 = $a % 3;
    $r2 = $b % 3;
    $r3 = ($a+$b) % 3;
    if ($r1 > 0 && $r2 > 0 && $r3 >0) {
        echo "Impossible\n"; }
    else {
        echo "Possible\n"; }
?>


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int powint(int a, int x){
	int res = 1;
	REP(i,x){
		res = res *a; 
	}
	return res;
}

using namespace std;

int main(){
	int N;
	cin>>N;
	vector<int> a1(N);
	vector<int> a2(N);
	REP(i,N){
		cin>>a1[i];
	}
	REP(i,N){
		cin>>a2[i];
	}
	int ans=0;
	REP(i,N){
		int tmp=0;
		REP(j,i+1){
			tmp+=a1[j];
		}
		REP(j,N-i){
			tmp+=a2[N-j-1];
		}
		ans=max(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a * b % 2 == 0)System.out.println("Even");
        else System.out.println("Odd");
    }
}

Measured memory_bytes: 35236
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    string rs; rs = s; reverse(ALL(rs));
    if (!(s == rs)) { puts("No"); return 0; }
    int i = 0, j = (s.size()-1)/2-1;
    while (i<j) {
        if (!(s[i++] == s[j--])) {
            puts("No");
            return 0;
        }
    }
    int k = (s.size()+3)/2-1, l=s.size()-1;
    while (k<l) {
        if (!(s[k++] == s[l--])) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

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

using namespace std;
typedef long long ll;
ll mod = 1e9+7;

int main(void)
{
  ll N;cin>>N;
  map<string,int> mp;
  int max =0;
  for(ll i=0;i<N;i++){
    string S;
    cin>>S;
    mp[S]++;
    if(max<mp[S]){
      max = mp[S];
    }
  }
  vector<string> outs;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
    if(max == itr->second) outs.push_back(itr->first);
  }
  sort(outs.begin(),outs.end());
  for(int i=0;i<outs.size();i++){
    cout<<outs[i]<<endl;
  }
}

Measured memory_bytes: 26868
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=998244353;
const int size=2e5+1;
const int inf=1e9;
int main(){
	int N;long K; cin>>N>>K;
	int A[N]; pair<int,int> g[N];
	rep(i,0,N) cin>>A[i];
	int id[size];
	rep(i,0,size) id[i] = -1;
	rep(i,0,2*N){
		int a = A[i % N];
		if(id[a] == -1) id[a] = i;
		else{ g[id[a] % N] = {i % N, (id[a] < N & N <= i)}; id[a] = i; }
	}
	int l = 0; int v = 0;
	while(true){
		l += g[v].second;
		v = g[v].first + 1;
		if(v == N) break;
	}
	K %= l + 1; l = 0; v = 0;
    if(K == 0) return 0;
	while(true){
        if(l == K - 1) break;
		l += g[v].second;
		v = g[v].first + 1;
	}
	deque<int> dq;
	while(v < N){
		if(v < g[v].first) v = g[v].first + 1;
		else{ dq.push_back(A[v]); v++; }
	}print(dq,,dq.size());
}

Measured memory_bytes: 6656
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<P> ans(n);
	vector<int> a(n), b(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) {
		int pre = 0;
		if (i) pre = a[i - 1];
		if (pre != a[i]) {
			ans[i].first = a[i];
			ans[i].second = 1;
		}
		else {
			ans[i].first = a[i];
			ans[i].second = 0;
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		int pre = 0;
		if (i != n - 1) pre = b[i + 1];
		if (pre != b[i]) {
			if (ans[i].second == 1) {
				if (ans[i].first != b[i]) {
					cout << "0\n";
					return 0;
				}
			}
			else {
				if (ans[i].first < b[i]) {
					cout << "0\n";
					return 0;
				}
				ans[i].second = 1;
			}
		}
		else {
			if (ans[i].second == 1) {
				if (ans[i].first > b[i]) {
					cout << "0\n";
					return 0;
				}
			}
			else {
				chmin(ans[i].first, b[i]);
			}
		}
	}
	ll res = 1;
	for (P i : ans) {
		if (i.second == 0) {
			res *= i.first;
			res %= 1000000007;
		}
	}
	cout << res << '\n';
}

Measured memory_bytes: 5556
#include <stdio.h>

int main(){
  long n,v[1005],i,j,k,m,f=1;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&v[i]);
    v[i]<<=(n-1);
  }
  while(f==1){
    f=0;
    for(i=0;i<n-1;i++){
      if(v[i]<v[i+1]){
        k=v[i];
        v[i]=v[i+1];
        v[i+1]=k;
        f=1;
      }
    }
  }
  for(i=n-1;i>0;i--){
    v[i-1]+=v[i];
    v[i-1]>>=1;
  }
  printf("%ld.",v[0]>>(n-1));
  v[0]&=((long)1<<(n-1))-1;
  for(i=0;i<=6;i++){
    v[0]*=10;
    printf("%ld",v[0]>>(n-1));
    v[0]&=((long)1<<(n-1))-1;
  }
  return(0);
}


Measured memory_bytes: 128
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        ++$this->pointer;

        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int) $this->next();
    }

    public function nextDouble()
    {
        return (float) $this->next();
    }
}

$sc = new Scanner();
$n = $sc->nextInt();
$m = $sc->nextInt();
$count = 0;


if($n*$m == 1){
    $count = 1;
} else if(($n==1) || ($m==1)){
    $count = $n * $m - 2;
} else {
    $count = ($n-2)*($m-2);
}

echo $count.PHP_EOL;

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

using namespace std;
char str1[56],str2[56];
int main() {
    scanf("%s %s",str1,str2);
    int len1=strlen(str1);
    int len2=strlen(str2);
    int i=0,j=0;
    int q=1;
    while(i<len1 && j<len2) {
        if(q) {
            printf("%c",str1[i]);
            i++;
            q=!q;
        } else {
            printf("%c",str2[j]);
            j++;
            q=!q;
        }
    }
    if(i<len1) printf("%c",str1[i]);
    else printf("%c",str2[j]);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int a, b;
    cin >> a >> b;
    vint c(3, true);
    c[a-1] = false;
    c[b-1] = false;
    
    rep(i, 3) if (c[i]) cout << i+1 << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int main(){
	int N;
	cin>>N;
	ll inf = 1e18;
	V<ll> dp(5,inf);
	dp[0] = 0;

	rep(i,N){
		ll a;
		cin>>a;

		V<ll> ndp(5,inf);
		rep(t,4){
			chmin(dp[t+1],dp[t]);
		}

		rep(t,5) if(dp[t] != inf){
			if(t==0 || t==4){
				chmin(ndp[t],dp[t]+a);
			}
			if(t==1 || t==3){
				chmin(ndp[t],dp[t]+(a==0 ? 2 : a%2));
			}
			if(t==2){
				chmin(ndp[t],dp[t]+((a+1)%2));
			}
		}
		dp = ndp;
	}
	ll ans = inf;
	rep(i,5) chmin(ans,dp[i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

class SegmentTree{
public:
	vector<ll> dat;
	int n,max_n;

	SegmentTree(int n_){
		n=1;
		max_n=1<<17;
		//要素数を2のべき乗にする
		while(n<n_) n*=2;
		rep(i,2*n-1) dat.push_back(inf);//全ての要素をinfで初期化
	}

	//k番目の値をaに変更する
	void update(int k,ll a){
		k+=n-1;
		dat[k]=a;
		while(k>0){
			k=(k-1)/2;
			dat[k]=min(dat[2*k+1],dat[2*k+2]);
		}
	}

	//[a,b)の最小値を求める
	//query(a,b,0,0,st.n)で呼ぶ←ここnの呼び出し注意
	ll query(int a,int b,int k,int l,int r){
		if(r<=a || b<=l) return inf;
		if(a<=l && r<=b) return dat[k];
		else{
			ll vl=query(a,b,2*k+1,l,(l+r)/2);
			ll vr=query(a,b,2*k+2,(l+r)/2,r);
			return min(vl,vr);
		}
	}
};

struct edge{int u,v,cost;};

bool comp(const edge& e1,const edge& e2){
	return e1.v<e2.v;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<edge> g(m);
  rep(i,m){
    int l,r,c;
    cin>>l>>r>>c;
    l--,r--;
    g[i]={l,r,c};
  }
  sort(begin(g),end(g),comp);
  SegmentTree sg(n);
  sg.update(0,0);
  vector<ll> dp(n,inf);
  dp[0]=0;
  rep(i,m){
    int l=g[i].u,r=g[i].v,c=g[i].cost;
    dp[r]=min(dp[r],c+sg.query(l,r+1,0,0,sg.n));
    sg.update(r,dp[r]);
  }
  if(dp[n-1]==inf) cout<<-1<<endl;
  else cout<<dp[n-1]<<endl;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){

    

}


void solve(){

    ll n;
    cin >> n;
    string s;
    cin >> s;
    int i=0 , j=n-1;
    int ans=0;
    while(i<j){
        while(i<n  and s[i] == 'R')i++;
        while(j>=0 and s[j] == 'W')j--;
        if(i < j){
            swap(s[i],s[j]);
            i++,j--;
            ans++;
        }
    }   
    cout << ans;

}


int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
#include <algorithm>
#include<set>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
int main(void){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  vector<ll> accum1(n,0);//累積和前から
  vector<ll> accum2(n,0);//累積和後ろから
  accum1[0]=a[0];
  accum2[n-1]=a[n-1];
  rep(i,n-1){
    accum1[i+1]=accum1[i]+a[i+1];
    accum2[n-1-i-1]=accum2[n-1-i]+a[n-1-i-1];
  }
  ll result=1;
  rep(i,n-1){
    if(accum1[n-1-i-1]*2>=a[n-1-i]){
      if(result==i+1){
        result++;
        //cout<<n-1-i-1<<" "<<a[n-1-i-1]<<endl;
        continue;
      }
    }
    break;
  }
  cout<<result<<endl;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
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;}
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; }
const ll INF = 1LL << 60;
const ll mod = 1000000007;

int main(){
	int n;
    while(cin>>n,n){
    	int x; cin>>x;
    	ll ans=0;
    	rep(i,n){
    		rep(j,n){
    			if(i>j)continue;
    			rep(k,n){
    			    if(j>k)continue;
    				if(i==j||j==k||k==i)continue;
    				if(i+j+k+3==x){ans++;
    				//cout<<i+1<<":"<<j+1<<":"<<k+1<<endl;
    				}
    			}
    		}
    	}
    	cout<<ans<<endl;
    }
}


Measured memory_bytes: 3112
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// type alias
using ll = long long;
using ull = unsigned long long;

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline unsigned getMaxEffectiveBit(ull a)
{
	ll index = 0;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

// computational complexity: o(log(max(a, b))) 
template<class ll>
inline pair<ll, ll> getBezoutsIdentitySolution(ll a, ll b)
{
	if (b == 0)
	{
		return { 1, 0 };
	}
	auto sol = getBezoutsIdentitySolution(b, a % b);
	return { sol.second, sol.first - (a / b) * sol.second };
}

template<class Integer>
inline Integer getPower(Integer base, unsigned exponential)
{
	Integer res = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			res *= base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return res;
}



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

	ll N;
	cin >> N;
	
	vector<vector<pair<ll, ll>>> edges(N);
	ll u, v, w;
	for (ll i = 0; i < N; ++i)
	{
		cin >> u >> v >> w;
		edges[u - 1].emplace_back(v - 1, w);
		edges[v - 1].emplace_back(u - 1, w);
	}

	ll oneEdgeNode = 0;
	for (;; ++oneEdgeNode)
	{
		if (edges[oneEdgeNode].size() == 1)
		{
			break;
		}
	}

	vector<ll> colors(N, -1);
	queue<pair<ll, ll>> queue;
	colors[oneEdgeNode] = 0;
	queue.emplace(oneEdgeNode, 0);
	while (queue.size() > 0)
	{
		auto currNode = queue.front().first;
		auto currWeight = queue.front().second;
		queue.pop();
		for (ll i = 0; i < edges[currNode].size(); ++i)
		{
			auto nextNode = edges[currNode][i].first;
			auto nextWeight = edges[currNode][i].second + currWeight;
			if (colors[nextNode] == -1)
			{
				colors[nextNode] = nextWeight % 2;
				queue.emplace(nextNode, nextWeight);
			}
		}
	}

	for (ll i = 0; i < N; ++i)
	{
		cout << colors[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 8704
def main():
    n,k = map(int, input().split())
    h = [int(input()) for i in range(n)]
    h.sort()
    m = 10**10
    for i in range(n-k+1):
        if m > h[i+k-1] - h[i]:
            m = h[i+k-1] - h[i]
    print(m)

if __name__ == "__main__":
    main()

Measured memory_bytes: 7488
#include <stdio.h>

int gcd(long int x, long int y);

int main(void) {
	
	long int x = 0;
	long int y = 0;

	scanf("%ld %ld", &x, &y);

	printf("%d\n", gcd(x, y));

	return 0;
}

int gcd(long int x, long int y) {
	long int tmp = 0;

	if (x < y) {
		tmp = x;
		x = y;
		y = tmp;
	}

	while (y > 0) {
		tmp = x % y;
		x = y;
		y = tmp;
	}

	return x;
}

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


int main(){
    int n,k;
    cin >> n >> k;
    vector<int> d(k);
    set<int> s;
    rep(i,k){
        cin >> d[i];
        vector<int> a(d[i]);
        rep(j,d[i]){
            cin >> a[j];
            s.insert(a[j]);
        }
    }
    int t = s.size();
    cout << n - t << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
#include <math.h>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    reps(i,n){
	if(i%3==0){
	    cout<<" "<<i;
	}
	else{
	    int copy=i;
	    while(copy>0){
		if(copy%10==3){
		    cout<<" "<<i;
		    break;
		}
		copy/=10;
	    }
	}
    }
    cout<<'\n';
    return 0;
}



Measured memory_bytes: 3188
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
        ab: [[usize; 2]; m],
    }

    let mut f_1: Vec<bool> = vec![false;n+1];
    let mut f_n: Vec<bool> = vec![false;n+1];
    for i in 0..m {
        if ab[i][0]==1 {
            f_1[ab[i][1]] = true;
        }
        if ab[i][1]==1 {
            f_1[ab[i][0]] = true;
        }
        if ab[i][0]==n {
            f_n[ab[i][1]] = true;
        }
        if ab[i][1]==n {
            f_n[ab[i][0]] = true;
        }
    }

    for i in 2..n {
        if f_1[i]==true && f_n[i]==true {
            println!("POSSIBLE");
            return;
        }
    }
    println!("IMPOSSIBLE");
}


Measured memory_bytes: 15648
#include <iostream>

using namespace std;

int main(void){
	for(;;){
		int h, w;

		cin >> h >> w;
		if(h == 0 && w == 0)
			break;

		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++)
				cout << ((i+j) % 2 ? '.' : '#');
			cout << endl;
		}
		cout << endl;
	}
}



Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#define maxn 100005
using namespace std;
int inedge[maxn], ans, sz[maxn];
vector<int> G[maxn];
void dfs(int x) {
	sz[x] = 1;
	int mx = 0;
	for ( int i : G[x] ) {
		if ( sz[i] == 0 )	dfs(i);
		mx = max(mx,sz[i]);
	}
	sz[x] += mx;
}
int main() {
	ios::sync_with_stdio(false);
	//   sync_with_YinHsuan(true);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	for ( int i=0, a, b; i<m; ++i ) {
		cin >> a >> b;
		G[a].emplace_back(b);
		inedge[b]++;
	}
	for ( int i=1; i<=n; ++i )
		if ( inedge[i] == 0 ) {
			dfs(i);
			ans = max(ans,sz[i]-1);
		}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll a[200050];
int n;
ll k;
bool check(ll len){
	ll tmp=0;
	for(int i=1;i<=n;i++){
		if(a[i]%len==0)tmp--;
		tmp+=(a[i])/len;
	}
	if(tmp<=k)return 1;
	else return 0;
}
void solve(int T)
{
    scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++){
    	scanf("%lld",&a[i]);
	}
	ll l=1,r=1e9+7,mid;
	while(l<r){
		if(l==r)break;
		mid=(l+r)/2;
		if(check(mid)){
			r=mid;
		}else{
			l=mid+1;
		}
	}
	printf("%lld",l);
}

int main(){
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++){
		solve(i);
	}
}


Measured memory_bytes: 5276
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll N;

int main(){
	cin >> N;
	ll num = (1<<N);
	vector<ll> S(num);
	rep(i, num) cin >> S[i];

	sort(S.rbegin(), S.rend());
	vector<ll> next;
	next.push_back(S[0]);


	map<ll, ll> memo;
	set<ll> numset;

	rep(i, S.size()) {
		memo[S[i]]++;
		numset.insert(S[i]);
	}


	rep(_, N) {
		vector<ll> vec = next;
		for(ll n: vec) {
			set<ll>::iterator it = numset.lower_bound(n);
			if(it == numset.begin()) {
				cout << "No" << endl;
				return 0;
			}
			it--;
			ll newnum = *it;
			next.push_back(newnum);
			memo[newnum]--;
			if(memo[newnum] == 0) {
				memo.erase(newnum);
				numset.erase(newnum);
			}
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 33832
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
int color_box[9];
int main() {
	int n, hoge,ans=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> hoge;
		for (int j = 1; j < 10; j++) {
			if (j == 9) {
				color_box[j-1]++;
				break;
			}
			else if (j * 400 > hoge) {
				color_box[j-1]++;
				break;
			}
		}
	}
	for (int i = 0; i < 8; i++) {
		if (color_box[i] > 0)ans++;
	}
	cout<<endl;
	cout << max(1, ans) << " " << ans + color_box[8] << endl;

}


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

int main()
{
	int n = 0;
	cin >> n;
	int b = 0, f = 0, r = 0, v = 0;
	int First[3][10] = { 0 }, Second[3][10] = { 0 }, Third[3][10] = { 0 }, Fourth[3][10] = { 0 };
	for (int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		switch (b){
		case 1:
			First[f - 1][r - 1] += v;
			break;
		case 2:
			Second[f - 1][r - 1] += v;
			break;
		case 3:
			Third[f - 1][r - 1] += v;
			break;
		case 4:
			Fourth[f - 1][r - 1] += v;
			break;
		}
	}
	for (int j = 0; j < 3; j++){
		for (int k = 0; k < 10; k++){
			cout << " " << First[j][k];
		}
		cout << endl;
	}
	cout << "####################" << endl;
	for (int j = 0; j < 3; j++){
		for (int k = 0; k < 10; k++){
			cout << " " << Second[j][k];
		}
		cout << endl;
	}
	cout << "####################" << endl;
	for (int j = 0; j < 3; j++){
		for (int k = 0; k < 10; k++){
			cout << " " << Third[j][k];
		}
		cout << endl;
	}
	cout << "####################" << endl;
	for (int j = 0; j < 3; j++){
		for (int k = 0; k < 10; k++){
			cout << " " << Fourth[j][k];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
ll n,cnt;
map<ll,int> mp;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>n;
  REP(i,n){
    int x;cin>>x;
    mp[x]++;
  }
  for(auto it=mp.begin();it!=mp.end();++it){
    if((it->second)%2==1)cnt++;
  }
  P(cnt);

  return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

//ダイクストラ(ある一点からの最短経路)
const long long int INF = 9999999999999999;

struct edge {
	long long int  to, cost;
};
typedef pair<long long int, long long int> P;
vector<edge> G[200101];
long long int d[201000];
long long int V, E;

void dijkstra(long long int s) {

	priority_queue<P, vector<P>, greater<P>>que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		long long int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
int main() {
    const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	cout << fixed << setprecision(10);
    string str;
    priority_queue<long long int,vector<long long int>,greater<long long int>> que;
    long long int n,a[200000],b[200000],c[200000],q,k,x[200000],y[200000];
    cin>>n;
    V=n+1;E=2*n-2;
    for(int i=0;i<n-1;i++){
        cin>>a[i]>>b[i]>>c[i];
        G[a[i]].push_back({b[i],c[i]});
        G[b[i]].push_back({a[i],c[i]});
    }
    cin>>q>>k;
    for(int i=0;i<q;i++){
        cin>>x[i]>>y[i];
    }
    dijkstra(k);
    /* for(int i=0;i<E;i++){
        d2[i]=d[i];
        d[i]=INF;
    }
    for(int i=0;i<n-1;i++){
        ed[i].to=a[i];
        ed[i].from=b[i];
        ed[i].cost=c[i];
    }
    Bellman_Ford(k);
    */
    for(int i=0;i<q;i++){
        cout<<d[x[i]]+d[y[i]]<<endl;
    }
} 


Measured memory_bytes: 20464
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>

using namespace std;
int main() {
    int a,b,c,d,ans=0;
    string  s,t;
    cin>>a>>b>>c>>d;
    for(int i=a;i<b;i++)
    {
        for(int j=c;j<d;j++)
        {
            if(i==j)ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sr = new Scanner(System.in);
		int in = sr.nextInt();
		int x;
		for(int i=1;i<=in;i++){
			if(i%3==0){
				System.out.print(" "+i);
			}else if(i%10==3){
				System.out.print(" "+i);
			}else{
					x = i/10;
				while(x!=0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}else{
						x = x/10;
					}
				}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 24268
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;
using LD = long double;

const LD EPS = 1e-11;

LD T;
int N;

inline LD alpha(LD x, LD y) {
	return y / (x * (T - x));
}

inline LD tangle(LD x, LD y) {
	return alpha(x, y) * T;
}

inline LD cost(LD tilt) {
	return sqrt(T * (tilt * tilt + 1.) / (2 * tilt));
}

LD solve(const vector<pair<LD, LD>>&vec, LD& center) {
	LD res = 0.;
	set<LD>S;
	for (auto &elm : vec) {
		//ここ怪しいなあ、バグか？
		if (S.lower_bound(elm.first) == S.lower_bound(elm.second)) {
			res += elm.first;
			S.insert(elm.first);
			center = elm.first;
		}
	}
	return res;
}

int main(void)
{
	cin >> T >> N;
	bool is45 = false;
	vector<pair<LD, LD>>locos, hicos;
	vector<pair<LD, LD>>cencos;
	for (int i = 0; i < N; ++i) {
		LD X, L, H;
		cin >> X >> L >> H;
		LD lo = tangle(X, L);
		LD hi = tangle(X, H);
		if (lo <= 1. && hi >= 1.) {
			//45°線を通る
			is45 = true;
			cencos.push_back({ cost(lo) + EPS,cost(hi) + EPS });
			continue;
		}
		if (lo < 1. && hi < 1.) {
			//45°未満
			locos.push_back({ cost(hi) - EPS,cost(lo) + EPS });
		}
		else {
			//45°以上
			hicos.push_back({ cost(lo) - EPS,cost(hi) + EPS });
		}
	}
	LD ans = 0;
	sort(locos.rbegin(), locos.rend());
	sort(hicos.rbegin(), hicos.rend());
	LD locen = 1e18, hicen = 1e18;
	ans += solve(locos, locen);
	ans += solve(hicos, hicen);
	cout.precision(15);
	if (is45) {
		for (auto elm : cencos) {
			if (elm.first < locen && elm.second < hicen) {
				ans += sqrt(T);
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 8808
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	int N, M;
	cin >> N >> M;
	vector<pair<ll, int>> bs;
	vector<pair<ll, int>> be;
	for (auto i = 0; i < M; ++i)
	{
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		bs.push_back({ a, i });
		be.push_back({ b, i });
	}
	sort(bs.begin(), bs.end());
	sort(be.begin(), be.end());

	auto ans = 0;
	vector<bool> flag(M);
	auto j = 0;
	for (auto i = 0; i < M; ++i)
	{
		if (flag[be[i].second])
		{
			continue;
		}

		while (j < M && bs[j].first < be[i].first)
		{
			flag[bs[j].second] = true;
			++j;
		}
		++ans;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
//ノート　isupperで大文字の判定　islowerで小文字の判定
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int a,b;
    std::cin >> a>>b;
    std::cout << max({a+b,a-b,a*b}) << std::endl;
}

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

int main(){
	
	string str;
	int n;
	string command, rep;
	int a,b,p=0;
	
	cin >> str >> n;
	for (int i=0; i<n; i++){
		cin >> command >> a >> b ;
		p=b-a+1;
		if (command=="replace") {
			cin >> rep;
			str=str.replace(a, p, rep);
		}
		if (command=="reverse"){
			string sub,ins;
			sub=str.substr(a, p);
			ins="";
			for (int k=0; k<p; k++){
				ins+=sub[b-a-k];
			}
			str=str.replace(a, p, ins);
		}
		if (command=="print") cout << str.substr(a, p) << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>

using namespace std;

int main() {
  int a = 0, b = 0, c = 0;
  cin >> a >> b >> c;
  if (a+b+c > 21) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}


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

int main()
{
        long long MOD = 1000000000 + 7;
        int N, M;
        cin >> N >> M;

        long long ans = 1;
        if (N == M) {
                for (int i = 0; i < N; ++i) {
                        ans = ans * (i+1) % MOD;
                }
                ans = ans * ans % MOD;
                ans = ans * 2 % MOD;
        }
        else if ((N-1) == M || N == (M-1)) {
                long long a0 = 1;
                for (int i = 0; i < M; ++i) {
                        a0 = a0 * (i+1) % MOD;
                }
                long long a1 = 1;
                for (int i = 0; i < N; ++i) {
                        a1 = a1 * (i+1) % MOD;
                }
                ans = a0 * a1 % MOD;
        }
        else {
                ans = 0;
        }
        cout << ans << endl;


}


Measured memory_bytes: 256
n,m = map(int,input().split())
x,y,z = [],[],[]
for i in range(n):
    a,b,c = map(int,input().split())
    x.append(a)
    y.append(b)
    z.append(c)
def solve(x,y,z,m):
    ans = 0
    for bit in range(8):
        #print((bit>>2)&1,(bit>>1)&1,(bit>>0)&1)
        w = []
        for i in range(n):
            t = x[i]*(-1)**((bit>>2)&1)+y[i]*(-1)**((bit>>1)&1)+z[i]*(-1)**((bit>>0)&1)
            w.append(t)
        w.sort(reverse=True)
        ans = max(ans,sum(w[:m]))
    return ans

ans = solve(x,y,z,m)
print(ans)

Measured memory_bytes: 3188
#ifndef LOCAL
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const int MAXN = 120000;
int gfl = 0;

vector<int> eds[MAXN];
int n;

int dfs1(int v, int x, int p) {
	vector<int> vv;
	for (int u: eds[v]) {
		if (u == p)
			continue;
		vv.push_back(dfs1(u, x, v) + 1);
	}
	sort(vv.begin(), vv.end());
	for (int u: vv)
		if (u > x) {
			gfl = 1;
			return 0;
		}
	if (vv.size() % 2 == 0) {
		int fl = 0;
		for (int i = 0; i < vv.size(); ++i)
			if (vv[i] + vv[vv.size() - 1 - i] > x) {
				fl = 1;
				break;
			}
		if (!fl)
			return 0;
	}
	if ((p == -1 && vv.size() % 2 == 1) || (p != -1 && vv.size() % 2 == 0)) {
		if (!vv.empty())
			vv.pop_back();
		else
			vv.push_back(0);
	}
	if (p == -1) {
		for (int i = 0; i < vv.size(); ++i) {
			if (vv[i] + vv[vv.size() - 1 - i] > x) {
				gfl = 1;
				return 0;
			}
		}
		return 0;
	}
	else {
		for (int i = 0; i < (int)vv.size() - 1; ++i) {
			if (vv[i] + vv[vv.size() - 2 - i] > x) {
				gfl = 1;
				return 0;
			}
		}
		int cur = vv.size() - 1;
		while (cur > 0) {
			int oth = vv.size() - 2 - (cur - 1);
			if (oth >= cur)
				++oth;
			if (vv[cur] + vv[oth] > x)
				break;
			--cur;
		}
		return vv[cur];
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		eds[a].push_back(b);
		eds[b].push_back(a);
	}
	int l = 0;
	int r = n;
	while (r - l > 1) {
		int mid = (l + r) >> 1;
		gfl = 0;
		dfs1(0, mid, -1);
		if (gfl)
			l = mid;
		else
			r = mid;
	}
	int a = 0;
	for (int i = 1; i < n; ++i) {
		int c = eds[i].size() - 1;
		if (c)
			--c;
		a += (c + 1) / 2;
	}
	int c = eds[0].size();
	a += (c + 1) / 2;
	cout << a << " " << r << "\n";
	return 0;
}




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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

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


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

    string o, e;
    cin >> o >> e;

    rep(i, o.size()){
        if(i != o.size()-1){
            cout << o[i] << e[i];
        }else{
            if(o.size() == e.size()){
                cout << o[i] << e[i] << endl;
            }else{
                cout << o[i] << endl;
            }
        }
    }
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
string S;
LL A[100001];
LL AA[100001];
LL C[100001];
LL CC[100001];
LL MOD=1e9+7;
LL beki(LL x){
	if(x<=0)return 1;
	LL ans=1;
	LL c=3;
	while(x!=0){
		if(x%2==1){
			ans*=c;
			ans%=MOD;
		}
		x/=2;
		c*=c;
		c%=MOD;
	}
	return ans;
}

int main(){
	cin>>S;
	LL q=0;
	REP(i,S.size()){
		A[i]=0;
		C[i]=0;
		if(S[i]=='?'){
			q++;
		}
	}
	REP(i,S.size()){
		if(i!=0){
			A[i]=A[i-1];
			AA[i]=AA[i-1];
		}
		if(S[i]=='A'){
			A[i]++;
		}
		if(S[i]=='?'){
			AA[i]++;
		}
	}
	
	for(int i=S.size()-1;i>=0;i--){
		if(i!=S.size()-1){
			C[i]=C[i+1];
			CC[i]=CC[i+1];
		}
		if(S[i]=='C'){
			C[i]++;
		}
		if(S[i]=='?'){
			CC[i]++;
		}
	}
	LL ans=0;
	REP(i,S.size()){
		if(i==0||i==S.size()-1)continue;
		if(S[i]=='B'){
			LL a=A[i-1]*C[i+1];
			a%=MOD;
			a*=beki(q);
			a%=MOD;
			ans+=a;
			ans%=MOD;
			LL b=AA[i-1]*C[i+1]+A[i-1]*CC[i+1];
			b%=MOD;
			b*=beki(q-1);
			b%=MOD;
			ans+=b;
			ans%=MOD;
			LL c=AA[i-1]*CC[i+1];
			c%=MOD;
			c*=beki(q-2);
			c%=MOD;
			ans+=c;
			ans%=MOD;
		}
		if(S[i]=='?'){
			LL a=A[i-1]*C[i+1];
			a%=MOD;
			a*=beki(q-1);
			//cout<<"q"<<beki(q-1)<<endl;
			a%=MOD;
			ans+=a;
			ans%=MOD;
			LL b=AA[i-1]*C[i+1]+A[i-1]*CC[i+1];
			b%=MOD;
			b*=beki(q-2);
			b%=MOD;
			ans+=b;
			ans%=MOD;
			LL c=AA[i-1]*CC[i+1];
			c%=MOD;
			c*=beki(q-3);
			c%=MOD;
			ans+=c;
			ans%=MOD;
			//cout<<"a"<<a<<" "<<b<<" "<<c<<endl;
		}
		//cout<<A[i-1]<<" "<<AA[i-1]<<" "<<C[i+1]<<CC[i+1]<<endl;
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 3712
# -*- coding: utf-8 -*-

import sys
import os
import math
import re

class Num:
    def __str__(self):
        return str(self.x)

    def __init__(self, value):
        self.x = value

    def __add__(self,value):
        return Num(self.x + value.x)

    def __sub__(self, value):
        return Num(self.x - value.x)

    def __mul__(self, value):
        return Num(self.x * value.x)

    def __truediv__(self,value):
        return Num(int(self.x / value.x))

n = int(input())

for i in range(n):
    command = input().strip()
    command = command.replace('=', '')
    command = re.sub(r'(\d+)', r'Num(\1)', command)
    print(eval(command))

# Supplement
"""
>>> math.floor(0.5)
0
>>> -1 // 2
-1
>>> int(0.5)
0
>>> int(-0.5)
0
"""

Measured memory_bytes: 7984
N=int(input())
A=list(map(int,input().split()))
mod = 10**9+7
x,y,z=0,0,0
ans=1
for a in A:
  ans*=[x,y,z].count(a)
  ans%=mod
  if x==a:
    x+=1
  elif y==a:
    y+=1
  else:
    z+=1
print(ans)

Measured memory_bytes: 83728