akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class363
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var A = new int[N];
            var B = new int[N];
            for (int i = 0; i < N; i++)
            {
                var ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                A[i] = ab[0];
                B[i] = ab[1];
            }
            Array.Sort(A);
            Array.Sort(B);
            double min = 0;
            double max = 0;
            if (N % 2 == 0)
            {
                min = (double)(A[N / 2 - 1] + A[N / 2]) / 2;
                max = (double)(B[N / 2 - 1] + B[N / 2]) / 2;
                Console.WriteLine((long)((max - min) * 2 + 1));
            }
            else
            {
                min = A[N / 2];
                max = B[N / 2];
                Console.WriteLine(Math.Ceiling(max - min) + 1);
            }
        }
    }
}


Measured memory_bytes: 42140
x = int(input())


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


p = factorization(x)
p = make_divisors(x)
# print(p)
Bas = 0
Aas = 0

flg = False
# p.append([1, 1])
# print(p)
for i in range(len(p)):
    if flg:
        break
    _p = p[i]
    # print(_p)
    B = int(-_p/2)

    while True:

        xnew = (B + _p)**5 - B ** 5
        # print(B, xnew)
        if xnew == x:
            Bas = B
            Aas = B + _p
            flg = True
            break

        if xnew > x:
            break

        B += 1


print(f'{Aas} {Bas}')


Measured memory_bytes: 9448
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define mii map<int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define Loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define loop(n) for(int i = 0; i < n; i++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#define vec vector
#define mod 1000000007
#define all(x) x.begin(), x.end()

int n;
int a[100005], b[100005], c[100005];



void solve_itr(){
    int dp[n+5][3];
    memset(dp, -1, sizeof(dp));
    dp[n-1][0] = a[n-1];
    dp[n-1][1] = b[n-1];
    dp[n-1][2] = c[n-1];
    for(int i = n-2; i >= 0; i--){
        dp[i][0] = a[i] + max(dp[i+1][1], dp[i+1][2]);
        dp[i][1] = b[i] + max(dp[i+1][0], dp[i+1][2]);
        dp[i][2] = c[i] + max(dp[i+1][0], dp[i+1][1]);
    }
    int ans = max(dp[0][0], max(dp[0][1], dp[0][2]));
    
    cout << ans << endl;
}

int dp[100005][3];

int get(int day, int task){
    if(day >= n) return 0;
    if(dp[day][task] == -1){
        if(task == 0){
            dp[day][task] = a[day] + max(get(day+1, 1), get(day+1, 2));
        }
        else if(task == 1){
            dp[day][task] = b[day] + max(get(day+1, 0), get(day+1, 2));
        }
        else{
            dp[day][task] = c[day] + max(get(day+1, 1), get(day+1, 0));
        }
    }
    return dp[day][task];
}

void solve_rec(){
    memset(dp, -1, sizeof(dp));
    int aa = get(0, 0);
    int bb = get(0, 1);
    int cc = get(0, 2);
    int ans = max(aa, max(bb, cc));
    cout << ans << endl;
}

int32_t main(){
    cin >> n;
    loop(n) cin >> a[i] >> b[i] >> c[i];

    // solve_itr();
    solve_rec();
}

Measured memory_bytes: 12988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define REP(i, n) for(int i=0; i<n; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9+7;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    double a, b; cin >> a >> b;
    double maxim = max(ceil(a/8.0*100.0), b*10);
    if(ceil(a/8.0*100.0) >= b*10){
        if(floor(maxim * 0.1) == b) cout << maxim << endl;
        else cout << -1 << endl;
    }else{
        if(floor(maxim * 0.08) == a) cout << maxim << endl;
        else cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

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();
}

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

//math
template <class T>
inline T sqr(T x) { return x * x; }

template <class T>
inline T nCr(T n, T r)
{
    T num = 1;
    for (int i = 1; i <= r; ++i)
    {
        num *= (n - i + 1) / i;
    }
    return num;
}
template <class T>
inline T nPr(T n, T r)
{
    r = n - r;
    T sum = 1;
    int i;
    for (i = n; i >= r + 1; --i)
        sum *= i;
    return sum;
}

template <class T>
inline T facctorial(T k)
{
    T sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

//numeric
template <class T>
inline T gcd(T a, T b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

template <class T>
inline T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

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

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

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

int main()
{
    int a, b, cnt = 1, ans = 0;
    cin >> a >> b;
    while (cnt < b)
    {
        cnt += a;
        --cnt;
        ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

p=limss()
q=limss()

arr=list(permutations(range(1,n+1)))

pans=0
qans=0
if p==q:
    print(0)
    exit()

for i,j in enumerate(range(factorial(n))):

    if "".join(p)=="".join(list(map(str,arr[i]))):
        pans=j
    elif "".join(q)=="".join(list(map(str,arr[i]))):
        qans=j
    
print(abs(pans-qans))

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

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

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<pair<string, pii>> r(n);
    for(int i = 0; i < n; ++i){
        cin >> r[i].first >> r[i].second.first;
        r[i].second.first *= -1;
        r[i].second.second = i+1;
    }
    sort(begin(r), end(r));
    for(int i = 0; i < n; ++i){
        cout << r[i].second.second << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
  
int main(){
 int N,max=0,cnt=0,hgt=0;
  cin>>N;

  
  for(int i=0;i<N;i++){
    cin>>hgt;
  	if(hgt>=max){
      cnt++;
      max=hgt;
    	}
  }
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long int ll;
int main(){
	int N;
	ll L[87];

	cin >> N;
	L[0] = 2, L[1] = 1;
	for(int i = 2; i <= N; i++){
		L[i] = L[i - 1] + L[i - 2];
	}

	cout << L[N] << endl;
	return 0;
}


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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


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

    // 左に連続する < の数, 右に連続する > の数
    vector<int> left(S.size()+1);
    vector<int> right(S.size()+1);

    int cnt  = 0;

    // 左に連続する < のかずをカウント
    REP(i,S.size()+1) {
        if ( i == 0) continue;
        if (S[i-1] == '<') cnt++;
        else cnt = 0;
        left[i] = cnt;
    }

    // カウンタを使い回すため初期化
    cnt = 0;
    // 右に連続する > のかずをカウント
    REPR(i,S.size()+1) {
        if ( i == S.size() ) continue;
        if (S[i] == '>') cnt++;
        else cnt = 0;
        right[i] = cnt;
    }

    ll ans = 0;
    REP(i,S.size()+1) ans += max(left[i],right[i]);

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4740
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
   string a,b,c;
   cin>>n>>a>>b>>c;
   int sum=0;
   for(int i=0;i<a.size();i++)
   {
       if(a[i]!=b[i]&&a[i]!=c[i]&&b[i]!=c[i])sum+=2;
       else if(a[i]==b[i]&&a[i]==c[i]&&b[i]==c[i])continue;
       else sum+=1;
   }
   printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
import bisect

N = int(input())
L = list(map(int, input().split()))

L.sort()
res = 0
for i in range(N):
    for j in range(i+1, N):
        query = L[i] + L[j]
        res += bisect.bisect_left(L, query) - j - 1

print(res)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;


int main(){
    int n;
    cin >> n;
    ll l0=2, l1=1;
    ll ans=0;
    if (n == 1) {
        out(1);
        return 0;
    }
    for (int i=0; i<n-1; i++){
        ans = l0 + l1;
        l0 = l1;
        l1 = ans;
    }
    out(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    cin >> n;
    vector <long long> a(3*n);
    for(long long i = 0; i < 3*n; i++)cin>>a[i];
    sort(a.begin(),a.end());
    #if 0
    for(long long i = 0; i < 3*n; i++){
        cout << a[i] << " ";
    }
    cout << endl;
    #endif
    long long ans = 0;
    //ans = a[2] + a[4];
    //n=2, 1 2 | 3 4 | 5 6 (3,5)
    //n=3, 1 2 3 | 4 5 6 | 7 8 9 (4,6,8)
    //n=4, 1 2 3 4 | 5 6 7 8 | 9 10 11 12 (5,7,9,11)
    for(long long i = n; i < 3*n; i+=2){
        ans+=a[i];
    }
    //cout << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5616
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")

#include <cstdio>
#include <iostream>
#include <fstream>

using namespace std;

#define NMAX 200010

int a[NMAX];
int imos[NMAX];

void reset(int n) {
    for(int i = 0; i < n; i++) imos[i] = 0;
}

int max(int a, int b) {
    if(a > b) return a;
    else return b;
}

int min(int a, int b) {
    if(a > b) return b;
    else return a;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

    for(int itr = 0; itr < k; itr++) {
        int f = 0;
        reset(n+1);
        for(int i = 0; i < n; i++){
            if(a[i] != n) f = 1;
            imos[max(0, i - a[i])]++;
            imos[min(n, i + a[i] + 1)]--;
        }
        int acc = 0;
        for(int i = 0; i < n; i++){
            acc += imos[i];
            a[i] = acc;
        }
        if(!f) break;
    }

    for(int i = 0; i < n; i++) printf("%d\n", a[i]);
    return 0;
}


Measured memory_bytes: 5328
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main(){
  int n,ans=0;
  string s;
  cin>>s;
  if(s[0]=='o') ans++;
  if(s[1]=='o') ans++;
  if(s[2]=='o') ans++;
  cout<<700+100*ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
const ll MAXX = 1e18;  

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	string s, t;
	cin >> s >> t;
	ll cnt = 0;
	for (ll i = 0; i < s.size(); i++) {
		if (s[i] == t[i]) {
			cnt++;
		}
	}
	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	n, k := readInt(), readInt()
	r, s, p := readInt(), readInt(), readInt()
	score := map[byte]int{'r': p, 's': r, 'p': s}
	t := readBytes()

	ans := 0
	handResults := make([]byte, n)
	for i := range t {
		if i-k >= 0 && t[i] == handResults[i-k] {
			handResults[i] = 'a'
		} else {
			ans += score[t[i]]
			handResults[i] = t[i]
		}
	}

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 896
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int solve(int n) {
    int ans = 0;
    for (int sentou = 1; sentou < 1000; sentou++) {
        for (int kousuu = 2; kousuu < 1000; kousuu++) {
            if (kousuu * (2 * sentou + kousuu - 1) / 2 == n) {
                ans++;
                // cout << sentou << " " << kousuu << endl;
            }
        }
    }
    return ans;
}

int main(int argc, char const *argv[]) {
    cin.tie(0);

    int n;
    vector<int> ans;
    while (1) {
        cin >> n;
        if (n == 0) break;
        ans.push_back(solve(n));
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t,u;
	int a,b;
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if(s==u)
		a--;
	else
		b--;
	cout<<a<<" "<<b; 
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define _for(i,a,b) for(int i = (a);i<(b);i++)
#define endl  '\n'
using namespace std;
const int mod=1e9+7;
const int MAX=1e7+7;
 ll a[MAX];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);
    ll n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	for(int j=i;j<=n;j+=i)
    	{
    		a[j]++;
		}
	}
    for(int i=1;i<=n;i++)
    {
    	ans+=i*a[i];
	}
	cout<<ans;
    return 0;
}


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

struct Node
{
    int key;
    Node* parent = nullptr;
    Node* l_child = nullptr;
    Node* r_child = nullptr;
};
Node* root;

void Insert(int value) 
{
    Node* currentNode = root;
    Node* parent = nullptr;
    Node* newNode = new Node;
    newNode->key = value;

    while(currentNode != nullptr)
    {
        parent = currentNode;
        if (newNode->key <= currentNode->key) currentNode = currentNode->l_child;
        else currentNode = currentNode->r_child;
    }
    newNode->parent = parent;
    if (root == nullptr) root = newNode;
    else if (value <= parent->key) parent->l_child = newNode;
    else parent->r_child = newNode;
}

void Preorder_Print(const Node* currentNode) 
{
    printf(" %d", currentNode->key);
    if (currentNode->l_child != nullptr) Preorder_Print(currentNode->l_child);
    if (currentNode->r_child != nullptr) Preorder_Print(currentNode->r_child);
}

void Inorder_Print(const Node* currentNode) 
{
    if (currentNode->l_child != nullptr) Inorder_Print(currentNode->l_child);
    printf(" %d", currentNode->key);
    if (currentNode->r_child != nullptr) Inorder_Print(currentNode->r_child);
}

int main() 
{
    root = nullptr;
    int node_num, value;
    char order[10];
    scanf("%d", &node_num);
    for (int i = 0; i < node_num; ++i) 
    {
        scanf("%s %d", order, &value);
        if (order[0] == 'i')
        {
            Insert(value);
        }
        else if (order[0] == 'p')
        {
            Inorder_Print(root);
            printf("\n");
            Preorder_Print(root);
            printf("\n");
        }
    }
}


Measured memory_bytes: 26668
#define LOCAL
#include <bits/stdc++.h>
#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, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

vector<pair<char, int> > Ranlength(string str){
    vector<pair<char, int> > ranlength;

    pair<char, int> f;
    char lastChar;
    int cnt = 0;
    rep(i, str.size()){
        if(lastChar != str[i] || i == str.size()){
            if(i!=0){
                f = make_pair(lastChar, cnt);
                ranlength.push_back(f);
            }
            lastChar = str[i];
            cnt=1;
        }
        else{
            cnt++;
        }
    }
    f = make_pair(lastChar, cnt);
    ranlength.push_back(f);

    // rep(i, ranlength.size()){ // for debug
    //     cout << ranlength[i].first << ranlength[i].second << endl;
    // }
    return ranlength;
}

ll sdp[MAX+1], tdp[MAX+1];


int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	string s, t; cin >> s >> t;
	memr(sdp, 0);
	memr(tdp, 0);
	int q; cin >> q;

	rep(i, s.size()){
		sdp[i+1] = sdp[i] + (s[i] == 'A'? 1 : 2);
	}
	rep(i, t.size()){
		tdp[i+1] = tdp[i] + (t[i] == 'A'? 1 : 2);
	}

	rep(i, q){
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		ll tmp = sdp[b] - sdp[a - 1];
		tmp %= 3;
		ll tmp2 = tdp[d] - tdp[c - 1];
		tmp2 %= 3;
		if(tmp == tmp2){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;

int main(){
    string S;
    cin >> S;
    string s = "";
    for(char& c : S) {
        if(c == '1'){
            s = s + "9";
        }else {
            s = s + "1";
        }
    }
    cout << s << endl;
    return 0;
}

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
//#define int ll
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define tcase int t; cin>> t; for( ; t; --t)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

int32_t main(){
	fastio;
	int m;
	cin>> n>> m;
	priority_queue<int> q;
	for(int i =0; i<n; ++i){
		int x;
		cin>> x;
		q.push(x);
	}
	for(int i = 0; i<m; ++i){
		int x = q.top();
		q.pop();
		q.push(x/2);
	}

	ll ans = 0;
	for(int i = 0; i<n; ++i){
		ans += (ll) q.top();
		q.pop();
	}
	cout<< ans<< endl;
	return 0;
}

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

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s = r.readLine();
    String[] sl = s.split("[\\s]+");
    int a = Integer.parseInt(sl[0]);
    int b = Integer.parseInt(sl[1]);

    System.out.println((a + b + (a + b % 2 == 0 ? 0 : 1)) / 2);
  }

}


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

#define ll long long

ll MAX(ll a, ll b) {

  if (a > b)return a;
  else return b;

}
int main() {

  int N;
  vector<ll> V;
  bool flag=true;
  
  cin>>N;
  for(int i=0;i<N;i++){
    
    ll tmp;
    cin>>tmp;
    V.push_back(tmp);
    
    if(i==0&&tmp!=0)flag=false;
    if(i>0&&tmp>V[i-1]+1)flag=false;
    
  }
  if(!flag){
    
    cout<<-1<<endl;
    return 0;
    
  }
  
  ll cnt=0,ans=0;
  flag=false;
  for(int i=N-1;i>0;i--){
    
    if(i==N-1){
      
      ans+=V[i];
      
      continue;
    }
    if(V[i]==V[i+1]-1)continue;
    ans+=V[i];
    
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N,D;
int X[11][11];

bool check(int i, int j) {
  int sum = 0;
  REP(k,D) sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
  int p = 1;
  while (p * p < sum) p++;
  return p * p == sum;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N >> D;
  REP(i,N) REP(j,D) cin >> X[i][j];
  int ans = 0;
  REP(i,N) REP(j,N) if (i < j) {
    ans += check(i,j);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int H,W,K;
char S[15][1010];
int white[15][1010];//whiteチョコの個数の累積
int func(int num){
    int ret=0;
    while(num>0){
        ret+=num%2;
        num>>=1;
    }
    return ret;
}
bool ifwari(int num,int h){
    return (num>>h)%2;
}
signed main(){
    scanf("%lld %lld %lld",&H,&W,&K);
    int ans=LLINF;
    rep(i,H){
        scanf("%s",S[i]);
        rep(j,W+1){
            if(j>0)white[i][j]=white[i][j-1]+(S[i][j-1]-'0');
        }
    }
    /*
    rep(i,H){
        rep(j,W+1){
            printf("%lld ",white[i][j]);
        }
        printf("\n");
    }*/

    //1000*10*1000くらいのオーダー
    for(int i=0;i< 1<<(H-1) ;i++){//２＾Hループ
        int tatewari=0;
        tatewari=func(i);
        int white2[15][1010];
        rep(k,W+1){//Wループ
            int retsu=0;
            int sum=0;
            rep(j,H){//Hループ
                sum+=white[j][k];
                if(ifwari(i,j)||j==H-1){
                    white2[retsu][k]=sum;
                    retsu++;
                    sum=0;
                }
            }
        }
        /*
        printf("%lld!\n",i);
        rep(i,H){
            rep(j,W+1){
                printf("%lld ",white2[i][j]);
            }
            printf("\n");
        }
        */
        //white2に累積和が収納された
        //white2にKより大きい要素がないかテェックしないといけない
        bool checkifnot=false;
        rep(k,W){
            rep(j,tatewari+1){
                if(white2[j][k+1]-white2[j][k]>K){
                    checkifnot=true;
                }
            }
        }
        if(checkifnot)continue;
        int maewari=0;
        int yokowari=0;
        rep(k,W+1){
            rep(j,tatewari+1){
                if(white2[j][k]-white2[j][maewari]>K){
                    maewari=k-1;
                    yokowari++;
                    break;
                }
            }
        }
        ans=min(tatewari+yokowari,ans);
        //printf("ans=%lld,%lld,%lld\n",ans,tatewari,yokowari);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(void){
    int Ho,Mo,Ht,Mt,K;
    scanf("%d %d %d %d %d",&Ho,&Mo,&Ht,&Mt,&K);
    int ans=(Ht-Ho)*60+(Mt-Mo)-K;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{
 
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int x = 0;

            for (int i = 1; i <= n; i++)
            {
                x = i;
                if (i % 3 == 0 | i % 10 == 3)
                {

                    Console.Write(" " + i);

                }
                else
                {
                    while (x > 10)
                    {

                        x /= 10;
                        if (x % 10 == 3)
                        {
                            Console.Write(" " + i);
                            break;
                        }


                    }
                }


            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9360
N,W = map(int, input().split())
dp = [0]*(W+1)
temp = [0]*(W+1)

for i in range(1,N+1):
    v,w = map(int,input().split())
    for j in range(w, W+1):
        dp[j] = max(temp[j-w]+v,temp[j])
    temp[0:W+1] = dp[0:W+1]

print(dp[W])

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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int r,g,b,n,ans;

signed main() {
    cin >> r >> g >> b >> n;
    rep(i,3001) rep(j,3001) {
        if (n-r*i-g*j >= 0 && (n-r*i-g*j)%b == 0) ans++;
    }
    cout << ans << endl;
}












Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

INF = 2**30
n = int(input())
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
  T[p-1].append(i)
X = tuple(map(int, input().split()))
D = [-1]*n
def dfs(v):
  if D[v] != -1:
    return D[v]
  l = len(T[v])
  x = X[v]
  dp = [INF]*(x+1)
  dp[0] = 0
  for nv in T[v]:
    k = [INF]*(x+1)
    d = dfs(nv)
    for j in range(x+1):
      if j >= X[nv]:
        k[j] = min(k[j], dp[j-X[nv]]+d)
      if j >= d:
        k[j] = min(k[j], dp[j-d]+X[nv])
    dp = tuple(k)
  res = min(dp)
  D[v] = res
  return res
ans = dfs(0)
if ans == INF:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Measured memory_bytes: 100572
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    X = input()

    ans, s = 0, 0
    for i in range(len(X)):
        if X[i] == "S":
            s += 1
        elif X[i] == "T" and s > 0:
            s -= 1
            ans += 2
    print(len(X) - ans)


if __name__ == '__main__':
    main()


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

int main(){
    int n, m, f = 0;
    cin >> n;
    m = n;
    while(n > 0){
        f += n%10;
        n /= 10;
    }
    if(m%f == 0){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = int;
using graph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
    string s;cin >>s;
    int n = s.size();
    char k =s[0];
    ll ans=0;
	for(int i = 0; i < n; ++i){
        if(k!=s[i]){
            k=s[i];
            ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>> N;
  vector<vector<int>>A(N,vector<int>(2,0));
  for(int i=0; i<N; i++){
    int a;
    cin>> a;
    A[i][0]=a;
    A[i][1]=i+1;
  }
  sort(A.begin(), A.end(), [](auto& x, auto& y){return x[0] < y[0];});
  for(int i=0; i<N; i++){
    if(i<N-1) cout << A[i][1] << " ";
    else cout <<A[i][1] << endl;
  }
}

Measured memory_bytes: 6272
//#pragma region ALL(include define etc)
#include <iostream>   // swap(a, b)
#include <string>
#include <cmath>      // abs(絶対値) sin cos tan(角度 / 180.0 * 3.141592)
#include <vector>     // vec.push_back(a) vec.pop_back()
#include <algorithm>  // max(a, b) min(a, b) reverse() sort()
#include <functional> // sort(a, a + N, greater<型>());
#include <math.h>
#include <iomanip>
#define int long long
#define ll long long
#define double long double
using namespace std;
//#pragma endregion

signed main()
{
	// 10^18 = 1000000000000000000

	//int h1, h2, m1, m2, k;
	//int box, box1,box2;

	//int N;
	//int n;
	char n;
	//int a = -111, b = -111;
	//int m;
	//int k;
	//string s;
	//string t;
	//int m1, m2;
	//int a, b, c, k;
	//int x, y;

	//int box[1000000000000000000];
	//int box;
	//int box2;
	//int p[111];

	//long double aaa;

	//int k, d;
	int all = 0;
	//double all;
	//double a, b;
	//double h, m;
	//int a[30000] = { 0 };
	//double c, d, e;

	//double mbox, hbox;
	//double box, box2;

	//int box[10000] = { 0 };

	//bool flag = true;
	bool flag = false;

	//string str;

	//cin >> h1 >> m1 >> h2 >> m2 >> k;
	cin >> n;
	//cin >> a >> b;
	//cin >> x >> n;


	n = n - 'Z';


	if (n > 0)
	{
		cout << "a\n";
	}
	else
	{
		cout << "A\n";
	}
	//n = t.length();

	//cout << all << "\n";

	/*if (flag == true)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}*/

	/*if (n == 0)
	{
		cout << x;
	}*/

	//cout << fixed << setprecision(111) << all;
}


Measured memory_bytes: 3628
//20/01/2020
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b push_back
#define m_p make_pair

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};
vector<ll>v;


int main(){
    _fastio
    ll H,a;
    cin>>H>>a;

    ll x=H/a;
    if(H%a) x++;
    cout<<x<<endl;



    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
const in mdl=1000000007LL;
VI fc,invfc;
in ncr(in a, in b){
  if(b==0 || b==a)
    return 1;//even if a<0
  if(b<0 || b>a)
    return 0;
  return fc[a]*invfc[b]%mdl*invfc[a-b]%mdl;
}
void inifc(){
  const in mxfc=1001000;
  fc.resize(mxfc);
  invfc.resize(mxfc);
  fc[0]=fc[1]=invfc[0]=invfc[1]=1;
  for(in i=2;i<mxfc;++i){
    fc[i]=fc[i-1]*i%mdl;
    invfc[i]=invfc[mdl%i]*(mdl-mdl/i)%mdl;
  }
  for(in i=2;i<mxfc;++i){
    invfc[i]*=invfc[i-1];
    invfc[i]%=mdl;
  }
}
in n;
VI mar;
VI fr;
in bef(in a){
  return lower_bound(all(fr),a)-fr.begin();
}
struct fenw{
  VI fw;
  in n;
  void ini(in pn){
    n=pn;
    fw.clear();
    fw.resize(n,0);
  }
  void ad(in l, in x){
    while(l<n){
      fw[l]+=x;
      l|=(l+1);
    }
  }
  in sm(in l){
    in r=0;
    while(l>=0){
      r+=fw[l];
      l&=(l+1);
      --l;
    }
    return r;
  }
};
VI rfr;
fenw ff;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  inifc();
  in sm=0;
  cin>>n;
  ff.ini(n+3);
  mar.resize(n);
  forn(i,n)
    cin>>mar[i];
  rfr.resize(n+1,1);
  rfr[0]=0;
  forn(i,n)
    rfr[mar[i]]=0;
  for(in i=1;i<=n;++i){
    if(rfr[i])
      fr.PB(i);
  }
  in ranksum=0;
  forv(i,fr)
    ranksum+=fr[i]-1;
  ranksum%=mdl;
  in cval;
  in crank;
  in usd0=0;
  in pfr=sz(fr)-1;
  if(pfr==-1)
    pfr=0;
  else
    pfr=fc[pfr];
  sm+=fc[sz(fr)];
  in cbef;
  in inv2=(mdl+1)/2;
  forn(i,n){
    if(i==n-1)
      cval=0;
    else
      cval=fc[n-1-i];
    if(mar[i]!=0){
      crank=mar[i]-1-ff.sm(mar[i]);
      sm+=crank*cval%mdl*fc[sz(fr)];
      cbef=bef(mar[i]);
      sm-=cbef*usd0%mdl*pfr%mdl*cval;
      sm%=mdl;
      ff.ad(mar[i],1);
      ranksum-=sz(fr)-cbef;
      ranksum%=mdl;
    }
    else{
      sm+=ranksum*cval%mdl*pfr;
      sm-=fc[sz(fr)]*usd0%mdl*inv2%mdl*cval;
      sm%=mdl;
      ++usd0;
    }
  }
  sm%=mdl;
  if(sm<0)
    sm+=mdl;
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 31856
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define OREP(i,n) FOR(i,1,n)
#define GREY 2
#define WHITE 1
#define BLACK 0
//#define x first
//#define y second
ll n,f=0,s=0; vector<ll> b, a,fir,sec;
ll gomi,co=0;
int main() {
	cin >> n; ll div = (n+1) % 2;
	REP(i, n) {
		cin >> gomi; 
		if ((i+1 )% 2==div) {
			sec.push_back(gomi); s++;
		}
		else { fir.push_back(gomi); f++; }
	}
	REP(i, (f +1) / 2) { swap(fir[i], fir[f - i-1]); }
	REP(i, f) { if (i) { cout << " "; }cout << fir[i]; }
	REP(i, s) { cout << " " << sec[i]; }cout << endl;
	return 0;
}

Measured memory_bytes: 3948
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define P pair<ll, ll>

typedef vector<ll> vec;
typedef vector<vec> mat;

int main(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n, greater<ll>());
    priority_queue<ll> q;
    q.push(a[0]);
    ll ans = 0;
    for (ll i = 1; i < n; i++){
        ans += q.top();
        q.pop();
        q.push(a[i]);
        q.push(a[i]);
    }
    cout << ans << endl;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<long long> vecll;
typedef vector<unsigned long long> vecull;

int N, M;


int main(void) {
    cin >> N >> M;
    N--;

    vector<set<int>> ships(N + 1, set<int>());

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        ships[a].insert(b);
        ships[b].insert(a);
    }

    bool result = false;
    for(auto i : ships[N]) {
        auto itr = find(ALLOF(ships[i]), 0);
        if (itr != ships[i].end()) {
            result = true;
            break;
        }
    }

    if (result) {
        cout << "POSSIBLE" << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 28416
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N, A, B;
  cin >> N >> A >> B;
  if (A < B) swap(A, B);
  cout << B << " " << max(0LL, A+B-N) << endl;

  return 0;
}

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

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

	int q, com, x;
	string key, L, R;
	multimap<string, int> my_map;
	multimap<string, int>::iterator it1, it2, it;

	cin >> q;
	while (q--) {
		cin >> com >> key;
		switch (com) {
			case 0:
				cin >> x;
				my_map.insert(make_pair(key, x));
				break;
			case 1:
				it1 = my_map.lower_bound(key);
				it2 = my_map.upper_bound(key);
				for (it = it1; it != it2; it++) {
					cout << it->second << endl;
				}
				break;
			case 2:
				my_map.erase(key);
				break;
			case 3:
				L = key;
				cin >> R;
				it1 = my_map.lower_bound(L);
				it2 = my_map.upper_bound(R);
				for (it = it1; it != it2; it++) {
					cout << it->first << " " << it->second << endl;
				}
				break;
		}
	}
}


Measured memory_bytes: 24944
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main(){
  bool f = true;
  int N;
  cin >> N;
  rep(i,N){
    int a;
    cin >> a;
    if(a%2==0){
      if(!(a%3 == 0 || a%5==0)) f = false;
    }
  }
  if(f) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <fstream>
#define ni(n) scanf("%d", &n)
#define nl(n) scanf("%I64d", &n)
#define nai(a,n) for (int i = 0; i < (n); i++) ni((a)[i])
#define nal(a,n) for (int i = 0; i < (n); i++) nl((a)[i])
#define case(t) printf("Case #%d: ", (t))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
using namespace std;

int main()
{
    ll a, b;
    nl(a), nl(b);
    ll p = a * b;
    if (p & 1) cout << "Odd\n";
    else cout << "Even\n";
    return 0;
}


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

using namespace std;

typedef long long ll;

const int N = 109, M = 1e5 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int n, cap, w[N], v[N];

ll dp[N][M];

ll solve(int i, int rem){
    if(i == n)  return (rem == 0 ? 0 : 1e15);

    ll &ret = dp[i][rem];
    if(ret != llOO)    return ret;

    ret = min(solve(i + 1, rem), w[i] + solve(i + 1, rem - v[i]));

    return ret;
}

int main(){

    cin >> n >> cap;
    for(int i = 0;i < n;i++)
        cin >> w[i] >> v[i];

    memset(dp, llOO, sizeof dp);

    ll sum = accumulate(v, v + n, 0);

    for(int i = sum;i > 0;i--){
        ll minW = solve(0, i);
        if(minW <= cap) return cout << i, 0;
    }

    cout << 0;
}


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

int main() {
	int N, A[8] = {}, a, c = 0, mini = 0, maxi = 0;
	cin >> N;
	for (int i = 0; i<N; ++i) {
		cin >> a;
		if (a<3200)A[a / 400] = 1;
		else c++;
	}
	for (int i = 0; i<8; i++)
	{
		if (A[i] == 1) { mini++; maxi++; }
	}
	mini = max(1, mini);
	maxi += c;
	cout << mini << endl << maxi;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val o = readLine()!!
    val e = readLine()!!
    var s = o[0].toString()
    for (i in 0 until e.length) {
        s += e[i]
        try {
            s += o[i + 1]
        } catch (e: StringIndexOutOfBoundsException) {
        }
    }
    println(s)
}

Measured memory_bytes: 33628
use std::io::*;

fn check(x: u64, k: u64, a: &Vec<(u64, u64)>) -> bool {
    let mut count = 0;
    for i in 0..a.len() {
        if x >= a[i].0 {
            count += (x - a[i].0) / a[i].1 + 1;
        }
        if count >= k {
            return true;
        }
    }
    false
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: u64 = itr.next().unwrap().parse().unwrap();
    let a: Vec<(u64, u64)> = (0..n)
        .map(|_| {
            (
                itr.next().unwrap().parse().unwrap(),
                itr.next().unwrap().parse().unwrap(),
            )
        })
        .collect();

    // [0, n)
    let mut ng = 0;
    let mut ok = 1u64 << 62; // k以上
    while ok - ng > 1 {
        let mid = (ok + ng) >> 1;
        if check(mid, k, &a) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    println!("{}", ok);
}


Measured memory_bytes: 9464
#include <stdio.h>
#include <math.h>

int main() {
  double a,b,x;
  scanf("%lf %lf %lf",&a, &b, &x);
  double vol;

  if (x >= (a * a * b) / 2) {
    vol = (a * a * a) / (2 * (a * a * b -x));
    printf("%f\n", 90 - (atan(vol) * 180 )/ M_PI);
  }else{
    vol = (2 * x)/(a * b * b);
    printf("%f\n", 90 - (atan(vol) * 180 )/ M_PI);
  }
}


Measured memory_bytes: 128