akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

s = 0
d = defaultdict(int)
for e in A:
    d[e] += 1
k = len(set(d))

for v in d.values():
    s += v*(v-1)//2

for e in A:
    if d[e] > 1:
        res = s - (d[e]-1)
        print(res)
    else:
        print(s)


Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 200000
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	string s;
    IN(s);
    int i=0;
    vector<int>a(SZ(s));
    while(i<SZ(s)){
        int r=0;
        int l=0;
        while(i<SZ(s)&&s[i]=='R'){
            r++;
            i++;
        }
        int tmpr=i-1;
        while(i<SZ(s)&&s[i]=='L'){
            l++;
            i++;
        }
        a[tmpr]+=(r+1)/2+l/2;
        a[tmpr+1]+=r/2+(l+1)/2;
    }
    REP(i,SZ(s))OUT(a[i]);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(void)
{
	int a,n;
	bool card[52]; //S=0~12,H=13~25,C=26~38,D=39~51
	char c;

	for(int i=0 ; i<52 ; i++){
		card[i]=true;
	}

	cin >> n;

	for(int i=0 ; i<n ; i++){
		cin >> c >> a;

		switch(c){
		case 'S':
			card[a-1]=false;
			break;

		case 'H':
			card[a+12]=false;
			break;

		case 'C':
			card[a+25]=false;
			break;

		case 'D':
			card[a+38]=false;
			break;
		}
	}

	for(int i=0 ; i<52 ; i++){
		if(card[i]==true){
			switch(i/13){
			case 0:
				cout << "S " << i+1 << endl;
				break;

			case 1:
				cout << "H " << i-12 << endl;
				break;

			case 2:
				cout << "C " << i-25 << endl;
				break;

			case 3:
				cout << "D " << i-38 << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import Control.Applicative ((<$>))

main :: IO ()
main = solve <$> map read <$> words <$> getLine >>= putStrLn

solve :: [Int] -> String
solve [a, b, c, d] | abs (a - c) <= d || abs (a - b) <= d && abs (b - c) <= d = "Yes"
                   | otherwise = "No"


Measured memory_bytes: 508
from datetime import datetime as dt


def while_in_time(two_times):
    times = two_times.split()  # ???????????????

    in_time_str = ' '.join(times[:3])  # ??\????????????????????????
    out_time_str = ' '.join(times[3:])  # ???????????????????????????

    in_time = dt.strptime(in_time_str, '%H %M %S')   #??\??????????????????
    out_time = dt.strptime(out_time_str, '%H %M %S')

    while_time = out_time - in_time  # ?????????????????????????¨??????????

    seconds = while_time.seconds
    hour = seconds // 3600
    minute = seconds % 3600 // 60
    sec = seconds % 60
    str_while_time = '{} {} {}'.format(hour, minute, sec)

    return str_while_time


A_time = input()
B_time = input()
C_time = input()
print(while_in_time(A_time))
print(while_in_time(B_time))
print(while_in_time(C_time))

Measured memory_bytes: 7336
#include<iostream>
#include<set>
using namespace std;
int main(){
    int n;
    cin>>n;
    set<char>st;
    for(int i=0;i<n;i++)
    {
        char element;
        cin>>element;
        st.insert(element);
    }
    if(st.size()==3){
        cout<<"Three\n";
    }
    else
    {
        cout<<"Four\n";
    }
}

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

using namespace std;

int main(){
    int N,cnt=0;
    long int a[10005];
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    
    for(int i=0;i<N;i++){
        while(a[i]%2 == 0){
            a[i]= a[i]/2;
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int visited[100005],f[100005];
ll s[100005];
int main()
{
    ll n;
    int x,m;
    cin>>n>>x>>m;
    f[1]=x,visited[x]=1;s[1]=x;
    for(ll i=2;i<=n;i++)
    {
        f[i]=1ll*f[i-1]*f[i-1]%m;
        s[i]=s[i-1]+f[i];
        if(visited[f[i]])
        {
            int t=visited[f[i]],r=i-t;
            int c=(n-t+1)%t;
            ll tmp=s[t-1]+(n-t+1)/(i-t)*(s[i]-s[t]);
            for(int j=1;j<=(n-t+1)%r;j++)tmp+=f[t-1+j];
            printf("%lld",tmp);
            return 0;
        }
        visited[f[i]]=i;
    }
    printf("%lld",s[n]);
    return 0;
}

Measured memory_bytes: 4740
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

int main() {
    long long n, x, m;
    cin >> n >> x >> m;
    vector<int> id(m, -1);
    vector<int> a;
    int len = 0;
    long long tot = 0;
    while (id[x] == -1) {
        a.push_back(x);
        id[x] = len++;
        tot += x;
        x = (x * x) % m;
    }

    // 周期の長さ
    int c = len - id[x];

    long long s = 0;
    for (int i = id[x]; i < len; ++i) s += a[i];

    long long ans = 0;
    if (n <= len) {
        repeat(i, n) ans += a[i];
    } else {
        ans += tot;
        n -= len;
        ans += s * (n / c);
        n %= c;
        repeat(i, n) ans += a[id[x] + i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3960
using System;
class Program
{
    static void Main(string[] args)
    {
        // スペース区切りの整数の入力
        int n = int.Parse(Console.ReadLine());
        int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), i => int.Parse(i));
        int[] b = Array.ConvertAll(Console.ReadLine().Split(' '), i => int.Parse(i));

        long sum = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] >= b[i])
            {
                sum += b[i];
            }
            else
            {
                sum += a[i];
                b[i] -= a[i];
                if (a[i + 1] >= b[i])
                {
                    sum += b[i];
                    a[i + 1] -= b[i];
                }
                else
                {
                    sum += a[i + 1];
                    a[i + 1] = 0;
                }
            }
        }
        Console.WriteLine(sum);

    }
}

Measured memory_bytes: 31184
package main

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

const MAX = 1000000
var (
	par = make([]int, MAX)
	rank = make([]int, MAX)
)

func main()  {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	N, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	M, _ := strconv.Atoi(scanner.Text())
	ps := make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		ps[i], _ = strconv.Atoi(scanner.Text())
	}
	initialize(N)
	for i := 0; i < M; i++ {
		scanner.Scan()
		x, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		y, _ := strconv.Atoi(scanner.Text())
		unite(x, y)
	}
	ans := 0
	for i := 0; i < N; i++ {
		if same(i + 1, ps[i]) {
			ans++
		}
	}
	fmt.Println(ans)
}

func initialize(n int) {
	for i := 1; i <= n; i++ {
		par[i] = i
		rank[i] = 0
	}
}

func find(x int) int {
	if par[x] == x {
		return x
	} else {
		par[x] = find(par[x])
		return par[x]
	}
}

func unite(x, y int) {
	x = find(x)
	y = find(y)
	if x == y {
		return
	}

	if rank[x] < rank[y] {
		par[x] = y
	} else {
		par[y] = x
		if rank[x] == rank[y] {
			rank[x]++
		}
	}
}

func same(x, y int) bool {
	return find(x) == find(y)
}


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

int gcd(int m, int n) { //2数の最大公約数を求める関数
    vector<int> A = {m, n};
    sort(A.begin(), A.end());
    m = A.at(1);
    n = A.at(0);
    int r;
    r = m % n;
    while(r != 0) {
        m = n;
        n = r;
        r = m % n;

    }
    return n;
}

int main() {
    int K;
    cin >> K;
    long long sum = 0;

    for(int a = 1; a <= K; a++) {
        for(int b = 1; b <= K; b++) {
            for(int c = 1; c <= K; c++) {
                sum += gcd(a, gcd(b, c));
            }
        }
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;

int todos_pares(long long int v[200],int tam){

    int i;
    for(i=0;i<tam;i++){
        if(v[i]%2!=0){
            return 0;
        }
    }
    return 1;
}

void muda_vetor(long long int s[200],int tamanho){

    int j;
    for(j=0;j<tamanho;j++){
        s[j]=(s[j]/2);
    }

}

int main(){

    long long int n,a[200];
    int contador=0;

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

    int x=todos_pares(a,n);
    while(x==1){
        muda_vetor(a,n);
        contador++;
        x=todos_pares(a,n);
    }
    cout << contador << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

#define int long long 

void show_ans(ll ans) {
  cout << ans << endl;
}

signed main() {
  int n,k;
  cin >> n >> k;
  map<int, int> mp;
  // ネタの種類
  ll total = 0;
  vector<pair<int,int> > data;

  ll t,s;
  rep(i,n) {
    cin >> t >> s;
    // ネタのおいしさ、ネタの種類
    data.pb(make_pair(s,t));
    if (mp[t] == 0) total++;
    mp[t] += 1;
  }

  // ネタのおいしさで昇順にsort
  sorti(data);
  // どのネタを食べたかチェックするmap
  map<ll,ll> check;
  ll kd = 0, cnt = 0, itr = n-1, ans = 0;
  // ネタのおいしさを降順に
  priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > sushi;
  for (int i = n-1; i >= 0; --i) {
    ll various = data[i].second, value = data[i].first;
    cnt += 1;
    itr = i;
    ans += value;
    sushi.push(data[i]);
    if (check[various] == 0) kd++;
    check[various] += 1;
    
    if (cnt == k) break;
  }
  
  ll tmpans = ans;
  ans = ans + (kd * kd);
  if (itr == 0 or total == kd) {
    show_ans(ans);
    return 0;
  }

  for (int i = itr; i >= 0; --i) {
    ll various = data[i].second, value = data[i].first;
    if (check[various] > 0) continue;
    if (total == kd) break;
    while (true) {
      if(sushi.empty()) {
      show_ans(ans);
      return 0;
  	}
      pair<int,int> p = sushi.top();
      sushi.pop();
      if (check[p.second] > 1) {
        // ネタを1つ減らす
        check[p.second] -= 1;
        // おいしさを減らす
        tmpans -= p.first;
        break;
      }
    }

    kd += 1;
    check[various] += 1;
    tmpans += value;
    ans = max(ans, tmpans + (kd * kd));
    if (kd == k) break;
  }

  show_ans(ans);
}


Measured memory_bytes: 12016
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int main(){
  int s; cin>>s;
  set<int> st;
  while(st.count(s) == 0){
    st.insert(s);
    if(s%2) s = 3*s + 1;
    else s /= 2;
  }
  cout<<st.size()+1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main(void) {
    io;
    string s; cin >> s;
    string res;
    int len = (int) s.size();
    for (int i = 0; i < len; i++) {
        if (s[i] == 'B' && res.size() != 0) {
            res.pop_back();
        } else {
            if (s[i] != 'B')
                res.push_back(s[i]);
        }
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>

#include <map>

#include <set>

#include <vector>

#include <memory>

using namespace std;

typedef long long LL;

set<LL> v;

void spawn(int digits, int last_digit, LL now) {
    if (last_digit > 9) return;
    if (last_digit < 0) return;
    if (digits > 10) return;
    v.insert(now);
    spawn(digits + 1, last_digit - 1, now * 10 + last_digit - 1);
    spawn(digits + 1, last_digit, now * 10 + last_digit);
    spawn(digits + 1, last_digit + 1, now * 10 + last_digit + 1);
}


int main() {

    for (int i = 1; i < 10 ; ++i) {
        spawn(1, i, i);
    }

    vector<LL> vv(v.begin(), v.end());

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

    //for (int i = 0; i <=300; ++i)   cout << vv[i] << ' ';

    int k; cin >> k;
    cout << vv[k - 1] << endl;


   
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

typedef long long ll;

void print()
{
  std::cout << std::endl;
}

template<class T>
void print(T param)
{
  std::cout << param << std::endl;
  return;
}

template<class T, class... S>
void print(T param1, S... param2)
{
  std::cout << param1 << " "; print(std::forward<S>(param2)...);
}

int main()
{
  ll K;
  std::string S;
  std::cin >> K >> S;

  ll N = S.size();
  if (N <= K) {
    print(S);
  } else {
    print(S.substr(0, K) + std::string("..."));
  }

  return 0;
}


Measured memory_bytes: 3600
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy
from decimal import *

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N,M = input().split()
    getcontext().prec = 20
    getcontext().rounding = ROUND_DOWN
    N = Decimal(N)
    M = Decimal(M)
    res = N*M
    print(res.quantize(Decimal('1.'), rounding=ROUND_DOWN))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10596
// Code for A - Rainy Season
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

#define MOD 1000000007
#define mod(x) ( (x) % MOD + MOD ) % MOD

#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T, typename U> void view(const std::map<T, U>& m){ for(const auto& e : m){ std::cout << e.first << "=>" << e.second << " "; } std::cout << std::endl; }

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

  if (S[1] == 'S' && S[0] == 'R' && S[2] == 'R') {
    cout << 1 << endl;
    return 0;
  }

  int total = 0;
  for (int i = 0; i <= 2; i++) {
    if (S[i] == 'R') {
      total++;
    }
  }

  cout << total << endl;
  return 0;
}


Measured memory_bytes: 3616
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, x = MAP()
a = LIST()

a.sort()
ans = 0
for i in range(N-1):
	if x < a[i]:
		break
	else:
		x -= a[i]
		ans += 1
else:
	if x == a[-1]:
		ans += 1
print(ans)

Measured memory_bytes: 10508
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <unordered_map>
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

bool check_order(vector<int> &p)
{
    for (int k = 0; k < p.size() - 1; k++)
    {
        if (p[k] > p[k + 1])
        {
            return false;
        }
    }
    return true;
}

int main(void)
{
    int n;
    cin >> n;
    vector<int> p(n);

    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }

    bool sortable = false;

    if (check_order(p))
    {
        cout << "YES" << endl;
        return 0;
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            swap(p[i], p[j]);

            if (check_order(p))
            {
                cout << "YES" << endl;
                return 0;
            }

            swap(p[i], p[j]);
        }
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
def divisors(N):
    U = int(N ** 0.5)
    L = {i for i in range(1, U + 1) if N % i == 0}
    R = {N // r for r in L}
    return L | R

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))


Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
int p[100009],f[100009];
main()
{
    p[1]=1;

    for (int i=2; i<=100000; i++)
    {
        for (int j=2*i; j<=100000; j+=i)
            p[j]=1;
    }
    p[2]=0;
    for (int i=1; i<=100000; i++)
    {
        if(p[i]==0 && p[(i+1)/2]==0 && i!=2)
            {
                f[i]=f[i-1]+1;
            }
        else f[i]=f[i-1];
    }
    int q;
    cin>>q;
    while(q--)
    {
        int l,r;
        cin>>l>>r;
        cout<<f[r]-f[l-1]<<endl; 
    }
}

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

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};
struct st{int a,b,c,id;};

priority_queue<P,vector<P>,greater<P>>dat[200000];

void merge(int x,int y){
	if(dat[x].size()<dat[y].size()){
		swap(dat[x],dat[y]);
	}
	while(!dat[y].empty()){
		auto p=dat[y].top();dat[y].pop();
		dat[x].push(p);
	}
}

vector<P>E[200000],G[200000];
int ans[200000];
int in[200000],out[200000];
int cnt;

void dfs1(int v,int p){
	in[v]=cnt++;
	for(auto u:E[v]){
		if(u.second==p){
			continue;
		}
		dfs1(u.second,v);
	}
	out[v]=cnt;
}

void dfs(int v,int p){
	int id=-1;
	for(auto u:E[v]){
		if(u.second==p){
			id=u.first;
			continue;
		}
		dfs(u.second,v);
		merge(v,u.second);
	}
	for(auto u:G[v]){
		dat[v].push(u);
	}
	while(!dat[v].empty()&&in[v]<=in[dat[v].top().second]&&in[dat[v].top().second]<out[v]){
		dat[v].pop();
	}
	if(dat[v].empty()){
		ans[id]=INT_MAX;
	}
	else ans[id]=dat[v].top().first;
}

int w[200000];

int main(){
	int n,m;scanf("%d%d",&n,&m);
	vector<st>v;
	rep(i,m){
		int a,b;scanf("%d%d%d",&a,&b,&w[i]);a--;b--;
		v.push_back({a,b,w[i],i});
	}
	sort(v.begin(),v.end(),[](st a,st b){return a.c<b.c;});
	UnionFind uf(n);
	ll sum=0;
	for(auto s:v){
		if(uf.same(s.a,s.b)){
			G[s.a].push_back(P(s.c,s.b));
			G[s.b].push_back(P(s.c,s.a));
			continue;
		}
		uf.unite(s.a,s.b);
		sum+=s.c;
		E[s.a].push_back(P(s.id,s.b));
		E[s.b].push_back(P(s.id,s.a));
	}
	if(uf.size(0)!=n){
		rep(i,m){
			puts("-1");
		}
		return 0;
	}
	memset(ans,-1,sizeof(ans));
	dfs1(0,-1);
	dfs(0,-1);
	rep(i,m){
		if(ans[i]==-1){
			printf("%lld\n",sum);
		}
		else{
			if(ans[i]==INT_MAX)puts("-1");
			else printf("%lld\n",sum-w[i]+ans[i]);
		}
	}
}


Measured memory_bytes: 42972
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

/**
 * Union-Find tree.
 * Verified by yukicoder No.94 (http://yukicoder.me/submissions/82111)
 */
struct UnionFind { disj: Vec<usize> }

impl UnionFind {
    fn new(n: usize) -> Self {
        let mut disj = vec![0; n];
        for i in 0 .. n {
            disj[i] = i;
        }
        UnionFind { disj: disj }
    }
    fn root(self: &mut Self, x: usize) -> usize {
        if x != self.disj[x] {
            let par = self.disj[x];
            let r = self.root(par);
            self.disj[x] = r;
        }
        return self.disj[x];
    }
    fn unite(self: &mut Self, x: usize, y: usize) {
        let xr = self.root(x);
        let yr = self.root(y);
        self.disj[xr] = yr;
    }
    fn is_same_set(self: &mut Self, x: usize, y: usize) -> bool {
        return self.root(x) == self.root(y);
    }
}


fn ask(q: &[bool]) -> i32 {
    let mut s = String::new();
    for &c in q.iter() {
        s.push(if c { '1' } else { '0' });
    }
    println!("? {}", s);
    get()
}

fn solve() {
    let n: usize = get();
    // n == 200
    // n * (n - 1) / 2 queries
    let mut pool = Vec::new();
    let mut uf = UnionFind::new(n);
    let mut deg = vec![0; n];
    for i in 0 .. n {
        for j in i + 1 .. n {
            if pool.len() >= n - 1 {
                break;
            }
            if uf.is_same_set(i, j) { continue; }
            let mut v = vec![false; n];
            v[i] = true;
            v[j] = true;
            if (j == n - 1 && deg[i] == 0) || ask(&v) == 1 {
                pool.push((i, j));
                uf.unite(i, j);
                deg[i] += 1;
                deg[j] += 1;
            }
        }
    }
    print!("!");
    for (u, v) in pool {
        print!(" ({},{})", u, v);
    }
    println!("");
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 9040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>

using namespace std;

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

	int a, b, c, k;
	cin >> a >> b >> c >> k;

	int maxv = max(a, max(b, c));
	int ans = a + b + c - maxv;
	for (int i = 0; i < k; i++)  maxv *= 2;
	ans += maxv;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1e9+1
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n,last = 0;
  cin >> n;
  for (int i = 0; i < n; ++i)
  {
    int v;
    cin >> v;
    if (last == v)  continue;
    if (last == v-1)  continue;
    if (last < v)
    {
      last = v-1;
      continue;
    }
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  return 0;
} 


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

const int MOD = 1e9 + 7;

// https://drken1215.hatenablog.com/entry/2020/04/22/013400
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

Fp<MOD> nCk(ll n, ll k) {
	Fp<MOD> ret = 1;
	for (ll i = 0; i < k; ++i) {
		ret *= (n - i);
		ret /= (i + 1);
	}
	return ret;
}

int main(int argc, char const *argv[])
{
	int n, a, b; cin >> n >> a >> b;
	Fp<MOD> ans = modpow(Fp<MOD>(2), n) - 1;
	ans -= nCk(n, a) + nCk(n, b);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// AOJ 2362: Chicken or the Egg
// 2017.10.4 bal4u@uu

#include <stdio.h>

char buf[7003];

int main()
{
	int k, max;
	char *p, c, ans;

	scanf("%s", buf);
	max = 0;
	p = buf, k = 0, ans = c = '?';
	while (*p) {
		if (*p == c) {
			if (k > max) max = k, ans = c;
			k = 0, c = '?';
		}
		c = *p;
		if (*p == 'e') p += 3;		// egg
		else p += 7;				// chicken
		k++;
	}
	if (k > max) max = k, ans = c;
	puts(ans == 'e' ? "egg" : "chicken");
	return 0;
}

Measured memory_bytes: 1812
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  long K = input();
  long X = input();

  if(K*500 >= X){
    output("Yes");
  }
  else{
    output("No");
  }


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int s,w;cin>>s>>w;
	if(w>=s){
		cout<<"unsafe"<<endl;
	}
	else{
		cout<<"safe"<<endl;
	}
}

Measured memory_bytes: 3648
#include <stdio.h>
main(){

  int x,y;

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

  while(x!=0 && y!=0){
    if(x>=y){
      x=x%y;
    }
    else y=y%x;
  }

  if(x==0) printf("%d\n",y);
  else if(y==0) printf("%d\n",x);

  return 0;
}

Measured memory_bytes: 592
#include <stdio.h>
#include <stdlib.h>


int main(void){
   
   int N;
   
   scanf("%d",&N);
   
   int Array[N];
   int i,j;
   
   for(i = 0;i < N;i++){
      scanf("%d",&Array[i]);
   }

   int Tunk[N];
   
   for(i = 0;i < N;i++){
      Tunk[i] = 0;
   }
   
   int start,flag,count,done_flag;
   int total = 0;
   
   done_flag = 0;
   
   while(1){
      /*
      for(j = 0;j < N;j++){
         printf("ll %d(%d)\n",Tunk[j],Array[j]);
      }
      printf("*************\n");
      */
      for(j = 0;j < N;j++){
         if(Array[j] - Tunk[j] > 0){
            start = j;
            break;
         }
         if(j == N - 1){
            done_flag = 1;
         }
      }
      
      if(done_flag == 1){
         break;
      }
      
      count = start;
      flag = 0;
      while(flag == 0){
         /*
         if(count >= N){
            printf("ddd\n");
         }
          */
         if(Array[count] - Tunk[count] > 0){
            count++;
         }
         else {
            flag = 1;
         }
         if(count >= N){
            break;
         }
      }
      if(count > j){
         for(j = start;j < count;j++){
            Tunk[j] = Tunk[j] + 1;
         }
         total++;
      }
   }
   
   printf("%d\n",total);
   
  
   return 0;
}






Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            long n = ReadLong();
            long sqrt = (long)Sqrt(n);

            long ans = long.MaxValue;
            for (int i = 1; i <= sqrt; i++)
            {
                if (n % i == 0)
                {
                    ans = Min(ans, i + n / i - 2);
                }
            }

            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static string YesNo(bool condition) => condition ? "Yes" : "No";
        static string YESNO(bool condition) => condition ? "YES" : "NO";

        #endregion
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N;
    cin >> N;
    vector<int> v(N);
    for (auto &&i : v) {
        cin >> i;
    }
    ll ans   = 0;
    auto dfs = [&](auto f, int now, ll sum) {
        if (now == N) {
            if (sum % 2 == 0)
                ans++;
            return;
        }
        int a = v[now];
        f(f, now + 1, sum * a);
        f(f, now + 1, sum * (a + 1));
        f(f, now + 1, sum * (a - 1));
    };
    dfs(dfs, 0, 1);
    print(ans);

    return 0;
}

Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

war = True

for Z in range(X + 1, Y + 1):
    if max(x) < Z <= min(y):
        war = False
        break

print("War" if war else "No War")


Measured memory_bytes: 2940
//Code by Mukul Totla
#include<bits/stdc++.h>
using namespace std;
#define ll long long

bool check(ll mid, ll k , ll *arr, ll n)
{
  for(ll i=0; i<n; i++)
  {
    if(arr[i]>mid)
    {
        ll val= ((arr[i]+mid-1)/mid) -1;
        if(k-val>=0)
            k-=val;
        else
            return false;
    }
  }
  return true;
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,k,i,lo=0,hi=0;
    cin>>n>>k;
    ll arr[n];
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
        hi=max(arr[i], hi);
    }

    ll ans=hi;
    while(lo <= hi)
    {
      ll mid= (lo + hi)/2;
      bool chk;
      if(mid>0)
       chk=check(mid,k, arr, n);
      else
        chk=false;
      if(chk==true)
      {
        hi=mid-1;
        ans=min(ans,mid);
      }
      else
        lo=mid+1;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5176
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
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; }

int N, L;

int main() {
  cin >> N >> L;
  vector<int> taste(N);
  rep (i, N) taste[i] = L + i;
  
  int sum = 0;
  sum = accumulate(taste.begin(), taste.end(), sum);
  
  int m = 1e9;
  int sign;
  rep (i, N) {
    if (abs(taste[i]) < m) {
      m = abs(taste[i]);
      sign = taste[i] == 0 ? 0 : taste[i] / abs(taste[i]);
    }
  }
  cout << sum - (sign * m) << endl;
  return 0;
}


Measured memory_bytes: 256
use std::cmp;
use std::io::{self, Read};

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let n: i32 = sc.read().unwrap();
    let m: i32 = sc.read().unwrap();

    let mut min = -1;
    let mut max = 1000000;
    for _ in (0..m) {
        let li: i32 = sc.read().unwrap();
        let ri: i32 = sc.read().unwrap();

        min = cmp::max(li, min);
        max = cmp::min(ri, max);
    }

    if max - min < 0 {
        println!("{}", 0);
    } else {
        println!("{}", max - min + 1);
    }
}

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse()
            .ok()
    }

    fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Option<Vec<T>> {
        (0..n).map(|_| self.read()).collect()
    }

    fn read_vec2d<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Option<Vec<Vec<T>>> {
        (0..m).map(|_| self.read_vec(n)).collect()
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll a[N],dp[N]={0};
int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]); 
	} 
	dp[1]=0;dp[2]=abs(a[2]-a[1]);
	for(i=3;i<=n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	printf("%lld\n",dp[n]);
	return 0;
}

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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rrep(i,n) for(ll i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)
#define rrep1(i,n) for(ll i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,m,k;cin>>n>>m>>k;
  vector<ll>a(n), b(m);
  rep(i, n)cin>>a[i];
  rep(i, m)cin>>b[i];

  rep(i, n-1)a[i+1]+=a[i];
  rep(i, m-1)b[i+1]+=b[i];

//for(auto c:a)cout<<c<<' ';cout<<endl;for(auto c:b)cout<<c<<' ';cout<<endl;cout<<endl;

  ll result=0;

  rep(i, n){
    ll lim = k-a[i];
    if(lim<0)continue;
    result = max<ll>(result, i+1);

    ll t=i+1;
    result = max<ll>(result, t);

    auto it = lower_bound(b.begin(), b.end(), lim);
    if(it==b.end())continue;
    ll diff = (ll)(it-b.begin())+1;
    if(*it>lim)diff--;
    diff=max<ll>(diff, 0);

    result = max<ll>(result, t+diff);
//if(result>=176882){cout<<t<<' '<<diff<<' '<<lim<<endl;}
//  cout<<t<<' '<<diff<<' '<<lim<<endl;
  }

//cout<<"---"<<endl;

  rep(i, m){
    ll lim = k-b[i];
    if(lim<0)continue;
    result = max<ll>(result, i+1);

    ll t=i+1;
    result = max<ll>(result, t);

    auto it = lower_bound(a.begin(), a.end(), lim);
    if(it==a.end())continue;
    ll diff = (ll)(it-a.begin())+1;
    if(*it>lim)diff--;
    diff=max<ll>(diff, 0);

    result = max<ll>(result, t+diff);
//  cout<<t<<' '<<diff<<' '<<lim<<endl;
  }

  cout<<result<<endl;

  return 0;
}


Measured memory_bytes: 6428
#include<iostream>
using namespace std;
int n;
main()
{
	cin>>n;
	for(;n--;)
	{
		long a,b;cin>>a>>b;
		if(a*b<=0)
		{
			cout<<__builtin_popcountll(a<0?-a:a)+__builtin_popcountll(b<0?-b:b)<<endl;
			continue;
		}
		else
		{
			if(b<0)
			{
				long sto=b;
				b=-a;
				a=-sto;
			}
			int cnt=0;
			for(int i=0;i<=31;i++)
			{
				if(a&1LL<<i&&(a+(1LL<<i))<=b)cnt++,a+=1LL<<i;
			}
			for(int i=31;i>=0;i--)
			{
				if((a+(1LL<<i))<=b)cnt++,a+=1LL<<i;
			}
			cout<<cnt<<endl;
		}
	}
}



Measured memory_bytes: 3072
import java.util.*;

public class Main{
  static int p = 1000000007;
  static long[] fac, inv, finv;
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int Z = X+Y;
    if(Z%3 != 0){
      System.out.println(0);
      return;
    }
    
    
    int d = Z/3;
    int e = (d-Math.abs(X-Y))/2;
    
    fac = new long[Z];
    finv = new long[Z];
    inv = new long[Z];
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < Z; i++){
        fac[i] = fac[i - 1] * i % p;
        inv[i] = p - inv[p%i] * (p/i)%p;
        finv[i] = finv[i-1] * inv[i] % p;
    }
    long ans = cmb(d, e);
    System.out.println(ans);
  }
  
  public static long cmb(int n, int k){
    if(n < k){
      return 0;
    }
    if(n<0 || k<0){
      return 0;
    }
    return fac[n] * (finv[k] * finv[n - k] % p) % p;
  }
}


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

int main(){
 int N, K, min=1001, sum_price=0;
  cin >> N >> K;
 vector<int> price(N);
  rep(i,N) cin >> price.at(i);
  
  sort(price.begin(), price.end());
   
  rep(i,K) sum_price += price.at(i);
  
  cout << sum_price << endl;
  
}
    
  
  
    


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define fi first 
#define se second 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);
#define mem(a,v) memset(a,v,sizeof(a))
const ll INF=1e18;
const int mod=1e9+7;
const int iinf=1e9+10;
const int xd[4]={1,0,-1,0},yd[4]={0,1,0,-1};
int main()
{
	faster
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(a*c,max(a*d,max(b*c,b*d)));
}

Measured memory_bytes: 3648
program divide_the_problems
    implicit none
    integer(4):: n, harf_n
    integer(4),allocatable:: d(:)

    read*, n
    allocate(d(n))
    read*, d(:)
    call merge_sort(d(:),1,n)

    harf_n = n/2

    if (d(harf_n) == d(harf_n+1)) then
        print*, 0
    else
        print*, d(harf_n+1)-d(harf_n)
    end if


contains
recursive subroutine merge_sort(ar,fst,lst)
    integer(4):: ar(:), fst, lst, mid, tmp

    if (lst - fst < 2) then
        if (ar(lst) < ar(fst))then
            tmp = ar(fst)
            ar(fst) = ar(lst)
            ar(lst) = tmp
        end if
        return
    end if

    mid = (fst+lst)/2
    call merge_sort(ar, fst, mid)
    call merge_sort(ar, mid+1, lst)
    call merge_(ar, fst, mid, lst)
end subroutine

subroutine merge_(ar, fst, mid, lst)
    integer(4):: ar(:), fst, mid, lst
    integer(4):: ti, li, ri
    integer(4),allocatable:: tmp(:)

    allocate(tmp(lst-fst+1))
    ti=1
    li=fst
    ri=mid+1

    do while(li <= mid .and. ri <= lst)
        if (ar(li) <= ar(ri)) then
            tmp(ti) = ar(li)
            li=li+1
        else
            tmp(ti) = ar(ri)
            ri=ri+1
        end if
        ti=ti+1
    end do

    if (ri > lst)then
        tmp(ti:) = ar(li:mid)
    else
        tmp(ti:) = ar(ri:lst)
    end if

    ar(fst:lst) = tmp(:)
    deallocate(tmp)
end subroutine
end program divide_the_problems

Measured memory_bytes: 1724
#include <iostream>
#include <vector>
using namespace std;
int main(){
  double N;
  long long K;
  cin >> N >> K;
  double ans = 0;
  int n = (int) (N + 1e-9);
  for(int i = 1; i < n + 1; i++){
    long long a = i;
    double b = 1 / N;
    while(a < K){
      a *= 2;
      b *= 0.5;
    }
    ans += b;
  }
  printf("%.10lf\n", ans);
}

Measured memory_bytes: 3784
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const int INF = 1e9 + 10;
const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;

        string s; cin >> s;
        rep(i,sz(s)){
            if(s[i]==',')s[i]=' ';
            cout<<s[i];
        }
        cout<<endl;

return 0;
}








Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001

using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    //0 red
    //1 blue
    vector<int> stk;
    int ret = 0;
    string str; cin >> str;
    
    for(int i = 0; i < str.size(); i++)
    {
        stk.push_back(str[i] - '0');

            while(stk.size() >= 2 && stk.back() != stk[stk.size() - 2])
            {
                ret += 2;
                stk.pop_back();
                stk.pop_back();
            }
    }
    
    cout << ret << endl;
    return 0;
}


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

#define pb push_back
#define rep(i, a, n) for(int (i)=a; (i)<(n); (i)++)
#define FOR(i, n) rep(i, 0, n)
#define F(n) FOR(i, n)
#define FF(n) FOR(j, n)
#define repi(i, a, n) for(int (i)=a; (i)<=(n); (i)++)
#define FORI(i, n) repi(i, 1, n)
#define FI(n) FORI(i, n)
#define FFI(n) FORI(j, n)
#define IN(x) cin<<(x);
#define INFO(a) cout<<"info "<<a<<endl
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int> >
#define sortv(x) sort((x).begin(), (x).end())
#define sortvd(x) sort((x).begin(), (x).end(), greater<int>())
#define lboundv(x, v) lower_bound((x).begin(), (x).end(), (v))
#define uboundv(x, v) upper_bound((x).begin(), (x).end(), (v))
#define ite iterator
#define fi first
#define se second
#define mems(a, v) memset((a), (v), sizeof((a)))
#define lmid(l, r) ((l)+(r)-1)/2
#define rmid(l, r) ((l)+(r))/2+1

typedef long long ll;

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	string s;
	cin>>s;
	ll n = s.size();
	ll cnt[26] = {0};
	F(n) {
		cnt[s[i]-'a']++;
	}
	ll ans = (n*(n-1))>>1, v;
	F(26) {
		v = cnt[i];
		if(v <= 1) continue;
		ans -= (v*(v-1))>>1;
	}
	cout<<ans+1<<endl;
	return 0;
}

Measured memory_bytes: 720