akhauriyash/Code-Regression huggingface dataset:
// Space Coconut Crab
#include <iostream>
using namespace std;
int count = 0; // ?¨???¬??¨ global ?????°
int solve(int E) {
  // ?????´????±???????
  // x+y*y+z*z*z=E
  int ans = E; // ?????§??? 
  for (int z=0; z*z*z<=E; ++z)
    for (int y=0; y*y<=E-z*z*z; ++y){
        int x = E - y*y - z*z*z;
        ++count;
        if (x+y+z < ans) // x+y+z??????????°??????????ans?????´??°
            ans = x+y+z;
    }
  return ans;
}
int main() {
  int E;
  while (cin >> E && E>0) {
    cout << solve(E) << endl; 
  }
}
// ?????´?????????????????¨?????????????????????????????? 10^11???...8?§???\?????????

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

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

    ll r,g,b;
    r = g = b = 0;
    rep(i,N) {
        if (S[i]=='R') r++;
        else if (S[i]=='G') g++;
        else if (S[i]=='B') b++;
    }
    ll ans = r*g*b;

    rep(i,N) {
        rep(j,N) {
            if (i-j<0 || i+j>=N) continue;
            else {
                if (S[i]!=S[i-j] && S[i]!=S[i+j] && S[i-j]!=S[i+j]) ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: Streamline
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_M = 100000;

/* typedef */

/* global variables */

int xs[MAX_M], ds[MAX_M];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) scanf("%d", xs + i);
  sort(xs, xs + m);

  for (int i = 0; i < m - 1; i++) ds[i] = xs[i + 1] - xs[i];
  sort(ds, ds + m - 1);

  int k = m - n, sum = 0;
  for (int i = 0; i < k; i++) sum += ds[i];
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int INF = INT_MAX / 2;

vector<int> dp;

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

    dp.resize(N + 1, INF);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        if (dp[i] == INF) {
            continue;
        }
        for (ll x = 1; i + x <= N; x *= 6) {
            chmin(dp[i + x], dp[i] + 1);
        }
        for (ll x = 1; i + x <= N; x *= 9) {
            chmin(dp[i + x], dp[i] + 1);
        }
    }

    cout << dp[N] << endl;

    // for (int i = 0; i <= N; i++) {
    //     cout << dp[i] << " ";
    // }
    // cout << endl;

    return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    a, b, c, d = map(int, input().split())

    t = min(b, d) - max(a, c)
    if t < 0:
        print(0)
        return

    print(t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#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)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    string s;
    cin >> s;

    if(s=="AKIHABARA" || s=="KIHABARA" || s=="AKIHBARA" || s=="KIHBARA" || s=="AKIHABRA" || s=="KIHABRA" || s=="AKIHBRA" || s=="KIHBRA" || s=="AKIHABAR" || s=="KIHABAR" || s=="AKIHBAR" || s=="KIHBAR" || s=="AKIHABR" || s=="KIHABR" || s=="AKIHBR" || s=="KIHBR"){
        puts("YES");
    }
    else puts("NO");

    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
ng = 0

for i in range(1, H):
    for j in range(1, W):
        if s[i][j] == '#':
            if i < H - 1 and j < W - 1:
                if '#' not in [s[i-1][j], s[i+1][j], s[i][j-1], s[i][j+1]]:
                    ng += 1
            elif i == H - 1 and j == W - 1:
                if '#' not in [s[i-1][j], s[i][j-1]]:
                    ng += 1
            elif j == W - 1:
                if '#' not in [s[i-1][j], s[i+1][j], s[i][j-1]]:
                    ng += 1
            elif i == H - 1:
                if '#' not in [s[i-1][j], s[i][j-1], s[i][j+1]]:
                    ng += 1
    if ng > 0:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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



















int main(){
    ll n;
    cin >> n;
    vector<string> s(n);
    ll ans = 0, a = 0, b = 0, ab = 0;
    REP(i, n){
        string t;
        cin >> t;
        REP(j, t.size()){
            if(j == t.size() - 1){
                s[i] += t[j];
                break;
            }
            if(t[j] == 'A' && t[j + 1] == 'B'){
                s[i] += '.';
                ans++;
                j++;
            }
            else{
                s[i] += t[j];
            }
        }
        if(s[i].size() > 0){
            if(s[i][0] == 'B') b++;
            if(s[i][s[i].size() - 1] == 'A') a++;
            if(s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A'){
                a--;
                b--;
                ab++;
            }
        }
    }
    if(ab > 0){
        if(a > 0){
            a--;
            ans++;
        }
        else if(ab > 1){
            ab--;
            ans++;
        }
        if(b > 0){
            b--;
            ans++;
        }
        else if(ab > 1){
            ab--;
            ans++;
        }
        ans += ab - 1;
    }
    cout << ans + min(a, b) << endl;
}

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


int main()
{
    long long a,b,n;
    cin>>a>>b>>n;
    long long sol=0;
    ///caz 1 x=n
    sol=(a*n)/b-a*(n/b);
    long long r=n/b;
    long long x=b*r-1;
    sol=max(sol,(x*a)/b-a*(x/b));
    cout<<sol;



}


Measured memory_bytes: 3636
from collections import defaultdict, Counter, deque

NA, NB, NM = list(map(int, input().split()))

A = list(map(int, input().split()))
B = list(map(int, input().split()))


best = min(A) + min(B)

for i in range(NM):
    x, y, c = list(map(int, input().split()))
    best = min(best, A[x - 1] + B[y - 1] - c)


print(best)


Measured memory_bytes: 69700
<?php
define('MOD', 10 ** 9 + 7);
list($s) = strs();
$l = strlen($s);
// dp[i][flg] := 上からi桁目までを見たときに、L以下であることがflag（未確定/確定）であるような、条件を満たす組み合わせ数
$dp[0][0] = 1;
$dp[0][1] = 0;
for ($i = 1; $i <= $l; ++$i) {
    if ($s[$i - 1] === '0') {
        $dp[$i][0] = $dp[$i - 1][0];
        $dp[$i][1] = modMul($dp[$i - 1][1], 3);
    } else {
        $dp[$i][0] = modMul($dp[$i - 1][0], 2);
        $dp[$i][1] = modAdd(modMul($dp[$i - 1][1], 3), $dp[$i - 1][0]);
    }
}
echo modAdd($dp[$l][0], $dp[$l][1]);
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return modMul($n, modFac($n - 1));
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return modMul(nPr($n, $r - 1), $n - $r + 1);
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modDiv(nPr($n, $r), modFac($r));
}

// 階乗、逆元を前処理
function init($n)
{
    global $fact, $ifact;
    $fact[0] = 1;
    for ($i = 1; $i <= $n; ++$i) $fact[$i] = modMul($fact[$i - 1], $i);
    $ifact[$n] = modDiv(1, $fact[$n]);
    for ($i = $n; $i >= 1; --$i)
        $ifact[$i - 1] = modMul($ifact[$i], $i);
}

// 順列（前処理）
function nPr2($n, $r)
{
    global $fact, $ifact;
    return modMul($fact[$n], $ifact[$n - $r]);
}

// 組み合わせ（前処理）
function nCr2($n, $r)
{
    global $fact, $ifact;
    return modMul(modMul($fact[$n], $ifact[$r]), $ifact[$n - $r]);
}


Measured memory_bytes: 55852
def get_GCD(a, b)
  while ((r = a%b) != 0) do
    a = b
    b = r
  end
  b
end

def get_LCM(a, b, gcd)
  a * b / gcd
end

while s = gets do
  a, b = s.split(/\s/).map(&:to_i).sort

  gcd = get_GCD(a, b)
  lcm = get_LCM(a, b, gcd)
  puts "#{gcd} #{lcm}"
end

Measured memory_bytes: 6100
//InTheNameOfGod
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
#define int ll
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn =1e5+5;
set<pair<int,int> > rs,ls;
int n,l[maxn],r[maxn],ans,x;
void er(int u)
{
    ls.erase({l[u],u});
    rs.erase({r[u],u});
}
int chk(int t)
{
    if(rs.size()==0)return 0;
    int re=0;
    pair<int,int> p,q;
    p=*rs.begin();
    q=*ls.rbegin();
    if(t==0)
    {
        if(q.first<=x)return 0;
        re+=abs(x-q.first);
        er(q.second);
        x=q.first;
        return re+chk(t^1);
    }
    else
    {
        if(p.first>=x)return 0;
        re+=abs(x-p.first);
        er(p.second);
        x=p.first;
        return re+chk(t^1);
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    rep(i,0,n)
    {
        cin>>l[i]>>r[i];
        rs.insert({r[i],i});
        ls.insert({l[i],i});
    }
    x=0;
    int s=chk(0);
    ans=max(ans,s+abs(x));
    x=0;
    rep(i,0,n)
    {
        rs.insert({r[i],i});
        ls.insert({l[i],i});
    }
    s=chk(1);
    ans=max(ans,s+abs(x));
    cout<<ans;
    return 0;
}

Measured memory_bytes: 17408
N = int(input())
is_approved = True
l = list(map(int, input().split()))
for i in l:
    if i % 2 == 0:
        if not (i % 5 == 0 or i % 3 == 0):
            is_approved = False
            break
print('APPROVED' if is_approved else 'DENIED')

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int M = Integer.parseInt(scan.next());
		int X = Integer.parseInt(scan.next());
		int Y = Integer.parseInt(scan.next());
		int[] x = new int[N];
		int[] y = new int[M];
		for (int i = 0; i < N; i++) {
			x[i] = Integer.parseInt(scan.next());
		}
		for (int i = 0; i < M; i++) {
			y[i] = Integer.parseInt(scan.next());
		}
		Arrays.sort(x);
		Arrays.sort(y);
		if (x[x.length - 1] >= y[0]) {
			System.out.println("War");
			return;
		}
		if (X >= y[0] || Y <= x[x.length - 1]) {
			System.out.println("War");
			return;
		}
		System.out.println("No War");
	}
}


Measured memory_bytes: 21844
def factorize(n):
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

N,P = list(map(int, input().split()))
ans = 1
fct = factorize(P)
for f in fct:
    ans = ans * max(1,(f[0] ** (f[1]//N)))

print(ans)

Measured memory_bytes: 3064
open System

let n = Console.ReadLine() |> Int64.Parse
let ss =
    seq {
        for i in 1 .. int(n) do
            yield Console.ReadLine()
    }

let ans =
    let march = ['M'; 'A'; 'R'; 'C'; 'H']
    let m =
        let mutable m =
            new Map<char, Int64> (
                march
                |> List.toSeq
                |> Seq.map (fun c -> (c, 0L))
            )

        for s in ss do
            let c = s.[0]
            match List.tryFind (fun x -> x = c) march with
                | Some _ -> m <- m |> Map.add c (m.[c] + 1L)
                | _ -> ()

        m

    let rec dfs (cs: char list) rest =
        match rest with
        | [] ->
            if cs.Length = 3 then
                cs
                |> List.map (fun c -> m.[c])
                |> List.fold (*) 1L
            else
                0L
        | c :: rest ->
            (dfs cs rest) + (dfs (c :: cs) rest)

    dfs [] march

ans |> Console.WriteLine



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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    void go(int now, vector<int> &visited, const vector<vector<int>> &E) {
        visited[now] = true;
        for(int nxt : E[now]) if(not visited[nxt]) go(nxt, visited, E);
    }

    bool solve() {
        int N, M; cin >> N >> M;
        vector<int> X(M), Y(M), Z(M);
        vector<vector<int>> E(N);
        rep(i, M) {
            cin >> X[i] >> Y[i] >> Z[i];
            X[i]--;
            Y[i]--;
            E[X[i]].push_back(Y[i]);
            E[Y[i]].push_back(X[i]);
        }

        int ans = 0;
        vector<int> visited(N);
        rep(i, N) {
            if(not visited[i]) {
                go(i, visited, E);
                ans++;
            }
        }
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int eval(string d)
{
    d = d.substr(1, d.length()-2);
    if (d[0] >= '0' && d[0] <= '9') {
        return stoi(d) / 2 + 1;
    }
    vector<int> vs;
    int i = 0;
    while (i < d.length()) {
        int j = i, cnt = 1;
        while (cnt) {
            j++;
            if (d[j] == '[') cnt++;
            if (d[j] == ']') cnt--;
        }
        vs.push_back(eval(d.substr(i, j-i+1)));
        i = j + 1;
    }
    sort(all(vs));
    int ans = 0;
    loop (vs.size()/2+1, i) ans += vs[i];
    return ans;
}

int main()
{
    int n; cin >> n;
    while (n--) {
        string d; cin >> d;
        cout << eval(d) << endl;
    }
    return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

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

Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// #define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%MOD,e/2);
    return e%2==0 ? temp : (temp*n)%MOD;
}
bool check(string s)
{
	for (int i=0; i<sz(s); i++)
	{
		if (s[i]!=s[sz(s)-i-1])
			return false;
	}
	return true;
}
void solve()
{
//Read Comments below main
	int n;
	cin>>n;
	v64 arr(n+1);
	map<ll,ll> counter;
	for (int i=1; i<=n; i++)
	{
		cin>>arr[i];
		counter[arr[i]]++;
	}
	ll ans=0;
	for (auto it=counter.begin(); it!=counter.end(); it++)
	{
		ll a=it->second;
		ans+=(a*(a-1))/2;
	}
	for (int i=1; i<=n; i++)
	{
		ll a=counter[arr[i]];
		ll ans2=ans-(a*(a-1))/2 + ((a-1)*(a-2))/2;
		cout<<ans2<<endl;
	}
}
 
int main() {
    fast_cin();
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}
// BITMASK:
// 1)When some constraint is of the order of 15-20, think of bitmask DP.
// 2)When some constraint is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algo

Measured memory_bytes: 11136
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
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; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}

int main() {
  int n; cin >> n;
  vector<int> x(n);
  rep(i, n) cin >> x[i];

  ll ans = 1e19;
  for(int i = 1; i <= 100; i++){
    ll sum = 0;
    rep(j, n){
      sum += (x[j] - i) * (x[j] - i);
    }
    chmin(ans, sum);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3580
a,b,c,d = map(int, input().split())

if c%b == 0:
    e = c//b
else:
    e = c//b+1
if a%d == 0:
    f = a//d
else:
    f = a//d+1
if e <= f:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9176
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
// long long C(int a,int b){
// 	if(a<b||b<0)return 0;
// 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
// }
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
int p[23];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	int ret=0;
	for(int i=1;i<a-1;i++){
		if(p[i-1]<p[i]&&p[i]<p[i+1])ret++;
		if(p[i+1]<p[i]&&p[i]<p[i-1])ret++;
	}
	printf("%d\n",ret);
}

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

char F[102][102];

void DFS(int Y,int X, char now)
{
  if(F[Y][X]!=now)
	return;
  
  F[Y][X]='.';

  DFS(Y-1,X  ,now);	//上
  //DFS(Y-1,X+1,now);	//右上
  DFS(Y  ,X+1,now);	//右
  //DFS(Y+1,X+1,now);	//右下
  DFS(Y+1,X  ,now);	//下
  //DFS(Y+1,X-1,now);	//左下
  DFS(Y  ,X-1,now);	//左
  //DFS(Y-1,X-1,now);	//左上
}

int main()
{
  int N,M;
  cin >> N >> M;
  for(int y=1;y<=N;y++){
	for(int x=1;x<=M;x++){
		cin >> F[y][x];
	}
  }

  while(N!=0||M!=0){

  int cnt=0;
  for(int y=1;y<=N;y++){
	for(int x=1;x<=M;x++){
		if(F[y][x]=='@'){
			cnt++;
			DFS(y,x,F[y][x]);
		}
		else if(F[y][x]=='#'){
			cnt++;
			DFS(y,x,F[y][x]);
		}
		else if(F[y][x]=='*'){
			cnt++;
			DFS(y,x,F[y][x]);
		}
	}
  }

  cout << cnt << endl;

  cin >> N >> M;
  for(int y=1;y<=N;y++){
	for(int x=1;x<=M;x++){
		cin >> F[y][x];
	}
  }

  }

  return 0;
}


Measured memory_bytes: 1476
#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
*/
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
#include <typeinfo>
/**/ 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;

ll ans=1;

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

ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

void solve()
{
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
int n,a[N],b[N];
void work(){
	puts("No");
	exit(0);
}
void check(int l,int r){
	for(int i=l,ml=0,mr=0;i<=r;i++)
		if(a[i]<i){
			if(ml>a[i]||a[i]>r||a[i]<l)	work();
			ml=max(ml,a[i]);
		}
		else	if(a[i]>i){
			if(mr>a[i]||a[i]>r||a[i]<l)	work();
			mr=max(mr,a[i]);
		}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)	scanf("%d",&a[i]),b[i]=a[i]==i;
	for(int i=2;i<n;i++)	if(!b[i-1]&&!b[i]&&!b[i+1])	work();
	for(int l=1;l<=n;l++)
		if(!b[l]){
			int r=l,now=1;
			while(r<=n&&b[r]^now)	++r,now^=1;
			check(l,--r),l=r;
		}
	puts("Yes");
	return 0;
}


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

T = []
for i in range(N-1):
  C, S, F = map(int, input().split())
  T.append((C, S, F))

for i in range(N-1):
  count = T[i][1]
  for j in range(i, N-1):
    c, s, f = map(int, T[j])

    if count >= s and (count - s) % f == 0:
      count += c
    elif count >= s:
      count += c + f - (count - s) % f
    else:
      count = s + c
  print(count)

print(0)

Measured memory_bytes: 3188
/*
 * ITP1_1_D.c
 *
 *  Created on: 2017/05/11
 *      Author: sl2-user
 */
#include<stdio.h>

int main(void){
int i , j ;
for (i=1;i<10;i++){
   for(j=1;j<10;j++){
      printf("%dx%d=%d\n",i,j,i*j);
      }
   }
return 0;
}

Measured memory_bytes: 2508
def solve(s):
    for i, j in zip(range(0, len(s) - 1), range(1, len(s))):
        if s[i] == s[j]:
            return "%d %d" % (i + 1, j + 1)

    for i, j in zip(range(0, len(s) - 2), range(2, len(s))):
        if s[i] == s[j]:
            return "%d %d" % (i + 1, j + 1)

    return "%d %d" % (-1, -1)


if __name__ == "__main__":
    print(solve(input()))


Measured memory_bytes: 3188
if __name__ == "__main__":
    Q,H,S,D = map(int, input().split())
    N = int(input())
    result = 2 ** 100

    TQ = N * 4 * Q
    result = min(result, TQ)

    TH = N * 2 * H
    result = min(result, TH)

    TS = N * S
    result = min(result, TS)

    if (N >= 2):
        tmp_N = N
        res = tmp_N // 2 * D
        tmp_N -=  tmp_N // 2 * 2

        TQ = tmp_N * 4 * Q
        result = min(result, TQ + res)
        TH = tmp_N * 2* H
        result = min(result, TH + res)
        TS = tmp_N * S
        result = min(result, TS + res)

    print (result)


Measured memory_bytes: 3316
l=[11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381, 1451, 1471, 1481, 1511, 1531, 1571, 1601, 1621, 1721, 1741, 1801, 1811, 1831, 1861, 1871, 1901, 1931, 1951]
print(*l[:int(input())])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, M;
vector<ll> A;
ll sum[105000];

ll f(ll x) {
    ll ret = 0;
    for(int i = 0; i < N; i++) {
        auto itr = lower_bound(A.begin(), A.end(), x - A[i]);
        ret += distance(itr, A.end());
    }
    return ret;
}


int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    A.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    for(int i = 0; i < N; i++) {
        sum[i+1] = sum[i] + A[i];
    }
    ll ok = 0;
    ll ng = 2e5 + 1;
    while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if(f(mid) >= M) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ll ans = 0;
    cerr << ok << endl;
    for(int i = 0; i < N; i++) {
        auto itr = lower_bound(A.begin(), A.end(), ok - A[i]);
        int index = distance(A.begin(), itr);
        ans += distance(itr, A.end()) * A[i];
        ans += sum[N] - sum[index];
    }
    ans -= (f(ok) - M) * ok;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

bool cmp(int a, int b)
{
    return a<b;
}

struct compare
{
  bool operator()(const int& l, const int& r)
  {
      return l>r;
  }
};
ll inf=1e18;
int mod=1e9+7;

int tim=0;
int color;
int dp[2005][2005];
int arr[2005][2005];
int h,w;
int fun(int x,int y)
{
    if(x>h || y>w)
        return 0;
    if(x==h && y==w)
        return 1;
    if(dp[x][y]!=-1)
        return dp[x][y];
    int ans=0;
    if(arr[x+1][y]==0)
    ans+=fun(x+1,y);
    ans%=mod;
    if(arr[x][y+1]==0)
    ans+=fun(x,y+1);
    ans%=mod;
    return dp[x][y]=ans;
}
int main()
{
//    READ;
    mem(dp,-1);
    int n,m,x,y;
    sf2(h,w);
    char c;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++){
            scanf(" %c",&c);
            if(c=='.')
                arr[i][j]=0;
            else
                arr[i][j]=1;
        }
    }
    cout<<fun(1,1)<<endl;
    return 0;
}


Measured memory_bytes: 25600
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m,k;
  cin >> n >> m >> k;
  string s[n];
  rep(i,n) R s[i];
  int a[n][m],x=1;
  mem(a);
  rep(i,n) {
    bool f=0;
    rep(j,m) {
      a[i][j]=x;
      if(s[i][j]=='#') {
        x++;
        f=1;
      }
    }
    x--;
    rrep(j,m) {
      a[i][j]=x;
      if(s[i][j]=='#') break;
    }
    x++;
    if(!f&&i) {
      rep(j,m) a[i][j]=a[i-1][j];
    }
  }
  rrep(i,n) {
    bool f=0;
    rep(j,m) {
      if(s[i][j]=='#') f=1;
    }
    if(!f&&i!=n-1) {
      rep(j,m) a[i][j]=a[i+1][j];
    }
  }
  rep(i,n) PR(a[i],m);
}

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


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
 
int main(){
    int N, C[200000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> C[i];
 
    int left[200001];
    for(int i=0; i<=200000; i++) left[i] = -1;
    static int64_t dp[200001];
    dp[0] = 1;
    for(int i=0; i<N; i++){
        add(dp[i+1], dp[i]);
        int c = C[i];
        if(left[c] >= 0 && left[c] < i-1) add(dp[i+1], dp[left[c]+1]);
        left[c] = i;
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
long long dp[maxn][3];
int n;
int val[maxn],pos[maxn];
char op[3];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&val[i]);
		if(i!=n)
		{
			scanf("%s",op+1);
			if(op[1]=='+')pos[i+1]=0;
			else pos[i+1]=1;		
		}
	}
	memset(dp,128,sizeof(dp));
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		if(pos[i])
		{
			dp[i][0]=max(dp[i-1][0]-val[i],max(dp[i-1][1]+val[i],dp[i-1][2]-val[i]));
			dp[i][1]=max(dp[i-1][0]-val[i],max(dp[i-1][1]+val[i],dp[i-1][2]-val[i]));
			dp[i][2]=max(dp[i-1][1]+val[i],dp[i-1][2]-val[i]);
		}
		else 
		{
			dp[i][0]=max(max(dp[i-1][1]-val[i],dp[i-1][2]+val[i]),dp[i-1][0]+val[i]);
			dp[i][1]=max(dp[i-1][1]-val[i],dp[i-1][2]+val[i]);
			dp[i][2]=dp[i-1][2]+val[i];
		}
	}
	printf("%lld\n",dp[n][0]);
}

Measured memory_bytes: 3328
h, w = map(int, input().split())
s = [input() for _ in range(h) ]
domain = [[10000]*w for _ in range(h)]

domain[0][0]= int(s[0][0]=="#")

for x in range(1,h):
    domain[x][0] = domain[x-1][0] + (int(s[x][0]=="#") if s[x-1][0]=="." else 0)
for y in range(1, w):
    domain[0][y] = domain[0][y-1] + int(s[0][y]=="#" if s[0][y-1]=="." else 0)
    for x in range(1,h):
        domain[x][y]= min(
            domain[x-1][y] + int(s[x][y]=="#" if s[x-1][y]=="." else 0),
            domain[x][y-1] + int(s[x][y]=="#" if s[x][y-1]=="." else 0)
        )

print(domain[-1][-1])

Measured memory_bytes: 3188
n = int(input())
a = []
x = [[0 for _ in range(15)] for _ in range(15)]
y = [[0 for _ in range(15)] for _ in range(15)]
for i in range(n):
    ai = int(input())
    a.append(ai)
    for j in range(ai):
        x[i][j], y[i][j] = map(int, input().split())
        x[i][j] -= 1

ans = 0
for i in range(1 << n):
    ok = True
    cnt = 0
    t = [-1] * n
    for j in range(n):
        if (i & (1 << j)) and ok:
            if t[j] == -1:
                t[j] = 1
            elif t[j] == 0:
                ok = False
                break
            cnt += 1
            for k in range(a[j]):
                if t[x[j][k]] == -1:
                    t[x[j][k]] = y[j][k]
                elif t[x[j][k]] != y[j][k]:
                    ok = False
                    break
        else:
            if t[j] == -1:
                t[j] = 0
            elif t[j] == 1:
                ok = False
                break
    if ok:
        ans = max(ans, cnt)
        #print(i)

print(ans)


Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int left = 1;
        int right = N;
        for(int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > left)left=L;
            if(R < right)right=R;
        }
        if(right < left){
            System.out.println(0);
        }
        else{
            System.out.println(right-left+1);
        }
    }
}

Measured memory_bytes: 63452
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int main() {
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	if (abs(A - C) <= D || (abs(A - B) <= D && abs(B - C) <= D)) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

//問題文より、入力されるデータの最大個数
#define MAXCOUNT 100

//ソートの途中結果を表示する関数
void print(int array[], int size);

int main(void)
{
	//i、jは繰り返し変数、tempは挿入するデータを格納
	int i, j, temp;
	//sizeは配列の要素数を、arrayは入力される数値を格納
	int size;
	int array[MAXCOUNT];

	//データの個数を入力
	scanf("%d", &size);

	//データを入力
	for(i = 0; i < size; i++){
		scanf("%d", &array[i]);
	}

	//配列の先頭の一つ後ろから開始
	for(i = 1; i < size; i++){
		//途中経過を表示
		print(array, size);

		//コピーを取る
		temp = array[i];
		//適切挿入位置まで整列済みのデータを後方にずらす
		for(j = i; (j > 0) && (temp < array[j - 1]); j--){
			array[j] = array[j - 1];
		}
		//データを挿入する
		array[j] = temp;
	}

	//最終結果を表示
	print(array, size);

	return 0;
}

void print(int array[], int size)
{
	int i;

	//配列の中身を1行で表示し、最後に改行する
	for(i = 0; i < (size - 1); i++){
		printf("%d ", array[i]);
	}

	printf("%d\n", array[i]);
}


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

typedef long long LL;
const int N = 205, K = 62;
LL a[N];

LL rep[K];

void add(LL x) {
    for (int i=0; i<K; i++) {
        if ((x&(1LL<<i)) == 0)  continue;
        if (rep[i])     x^=rep[i];
        else {
            rep[i] = x;
            break;
        }
    }
}

bool check(LL x) {
    for (int i=0; i<K; i++) {
        if ((x&(1LL<<i)) == 0)  continue;
        if (rep[i]) x^=rep[i];
        else        return false;
    }
    return true;
}

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

    int t;
    cin>>t;

    while (t--) {
        int n;
        cin>>n;

        memset(rep, 0, sizeof rep);

        for (int i=0; i<n; i++)    cin>>a[i];
        string s;
        cin>>s;

        bool ans = 0;
        for (int i=n-1; i>=0; i--) {
            if (s[i] == '0')    add(a[i]);
            else {
                if (!check(a[i])) {
                    ans = 1;
                    break;
                }
            }
        }
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,m;cin>>n>>m;
    vector<vector<ll>> t(m+10);
    rep(i,n){
        ll a,b;cin>>a>>b;
        if(a>m)continue;
        t[a].push_back(b);
    }
    ll res=0;
    priority_queue<ll> que;
    rep(i,m+1){
        if(i==0)continue;
        rep(j,t[i].size())que.push(t[i][j]);
        if(que.size()==0)continue;
        res+=que.top();que.pop();
    }
    cout<<res<<endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

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

	int N=in();
	string S=in<string>();
	vector<int> LT(N,0),RT(N,0),ST(N,0);
	int minS = 1e9;
	REP(i,N-1){
		LT[i+1]=LT[i];
		if(S[i]=='W') LT[i+1]++;
		RT[N-2-i]=RT[N-i-1];
		if(S[N-1-i]=='E') RT[N-2-i]++;
	}
	REP(i,N){
		ST[i]=LT[i]+RT[i];
	}
	
	cout << *min_element(ALL(ST)) << endl;
	return 0;
}


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

int a, b, c, d;

int main() {

  cin >> a >> b >> c >> d;

  while (true) {

    c = c - b;
    if (c <= 0) {
      printf("Yes");
      break;
    }
    a = a - d;
    if (a <= 0) {
      printf("No");
      break;
    }
  
  }
}

Measured memory_bytes: 3688
#include<iostream>
#include<iomanip>

using namespace std;

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

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

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

    double h;
    double ma = -1;
    double mi = 101010101;
    while(cin >> h){
        chmax(ma, h);
        chmin(mi, h);
    }

    cout << fixed << setprecision(3) << ma - mi << endl;

    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s,a,b,c;
  cin >> s;
  c=(s%100)%10;
  b=((s-c)/10)%10;
  a=(s-(b+c))/100;
  cout << a+b+c << endl;
}

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

using namespace std;

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

    string s;
    int K;

    cin >> s;

    cin >> K;

    for(int i=0;i<s.length();i++)
    {
    	if(s[i]=='a')
    	{
    		continue;
    	}
    	int val = 26 - (s[i]-'a');
    	if(K >= val)
    	{
    		K-=val;
    		s[i] = 'a';
    	}
    }

    int val = s[s.length()-1] - 'a';
    val += K;
    val%=26;
    s[s.length()-1] = (char)(val+'a');

    cout << s << '\n';

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i)
    cin >> A[i];
  map<int, int> m;
  for (int i = 0; i < N; ++i)
    ++m[A[i]];
  if (m.size() % 2 == 1)
    cout << m.size() << endl;
  else
    cout << m.size() - 1 << endl;
}


Measured memory_bytes: 5376
/*ex9-1 B- バイナリハックイージー
ryo_1129*/

#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE+1];
    char *top;
} stack;

void initialize_stack(stack *stk);
void push(stack *stk, char elem);
void pop(stack *stk);
void print_stk(stack *stk);

int main(void){
    stack stk;
    char str[SIZE+1];
    scanf("%s",str);
    //スタックを初期化
    initialize_stack(&stk);
    //スタックにデータを追加
    for (int i=0; str[i] != '\0'; i++ ){
        if (str[i] == 'B'){
            pop(&stk);
        }else{
            push(&stk,str[i]);
        }
    }
    //出力
    print_stk(&stk);
    return 0;
}

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[0]);
}

//文字の追加
void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk->top++;
        *(stk->top) = elem;
        stk->count++;
    }
}

//バックスペース
void pop(stack *stk){
    if(stk->count <= 0){
        return;
    }
    else{
        stk->top--;
        stk->count--;
    }
}

//stack内のデータの表示
void print_stk(stack *stk){
    for(int i=1; i<= stk->count; i++){
        printf("%c", stk->data[i]);
    }
    putchar('\n');
}

Measured memory_bytes: 1604
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split();
	struct Point
	{
		public readonly int x, y;
		public Point(int[] a) : this(a[0], a[1]) { }
		public Point(int a, int b) { x = a; y = b; }
		public bool SmallerThan(Point p) => x < p.x && y < p.y;
	}
	public K()
	{
		var N = F;
		var a = new Point[N];
		var b = new Point[N];
		for (var i = 0; i < N; i++) a[i] = new Point(G);
		for (var i = 0; i < N; i++) b[i] = new Point(G);
		var g = new Dinic(2 * N + 2);
		for (var i = 0; i < N; i++) for (var j = 0; j < N; j++) if (a[i].SmallerThan(b[j])) g.AddEdge(i + 1, j + N + 1);
		for (var i = 0; i < N; i++) { g.AddEdge(0, i + 1); g.AddEdge(i + N + 1, 2 * N + 1); }
		WriteLine(g.MaxFlow(0, 2 * N + 1));
	}
}
class Dinic
{
	public const long INF = 4011686018427387913L;
	class Edge
	{
		public readonly int To;
		public long Capacity;
		public Edge Reverse;
		public Edge(int t, long c, Edge r) { To = t; Capacity = c; Reverse = r; }
	}
	public Dinic(int v)
	{
		V = v;
		level = new int[V];
		es = new List<Edge>[v];
		for (var i = 0; i < V; i++) es[i] = new List<Edge>();
	}
	readonly int V;
	int[] iter;
	readonly int[] level;
	readonly List<Edge>[] es;
	public void AddEdge(int f, int t, long c = 1)
	{
		var e1 = new Edge(t, c, null);
		var e2 = new Edge(f, 0, e1);
		e1.Reverse = e2;
		es[f].Add(e1);
		es[t].Add(e2);
	}
	long DFS(int v, int t, long f)
	{
		if (v == t) return f;
		for (; iter[v] < es[v].Count; iter[v]++)
		{
			var e = es[v][iter[v]];
			if (level[v] >= level[e.To] || e.Capacity <= 0) continue;
			var g = DFS(e.To, t, Min(e.Capacity, f));
			if (g > 0) { e.Capacity -= g; e.Reverse.Capacity += g; return g; }
		}
		return 0;
	}
	void BFS(int s)
	{
		for (var i = 0; i < V; i++) level[i] = -1;
		var queue = new Queue<int>();
		level[s] = 0;
		queue.Enqueue(s);
		while (queue.Count > 0)
		{
			var v = queue.Dequeue();
			foreach (var e in es[v]) if (e.Capacity > 0 && level[e.To] < 0) { level[e.To] = level[v] + 1; queue.Enqueue(e.To); }
		}
	}
	public long MaxFlow(int s, int t)
	{
		var flow = 0L;
		while (true)
		{
			BFS(s);
			if (level[t] < 0) return flow;
			iter = new int[V];
			while (true)
			{
				var f = DFS(s, t, INF);
				if (f <= 0) break;
				flow += f;
			}
		}
	}
}

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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const ll mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vector<vector<int>> a(3, vector<int>(3));
    vector<vector<int>> usd(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    while (n--) {
        int x;
        cin >> x;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (a[i][j] == x) usd[i][j] = 1;
            }
        }
    }
    bool f = false;
    for (int i = 0; i < 3; i++) {
        if (usd[i][0] && usd[i][1] && usd[i][2]) f = true;
        if (usd[0][i] && usd[1][i] && usd[2][i]) f = true;
    }
    if (usd[0][0] && usd[1][1] && usd[2][2]) f = true;
    if (usd[0][2] && usd[1][1] && usd[2][0]) f = true;
    cout << (f ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3564