akhauriyash/Code-Regression huggingface dataset:
M, K = map(int, input().split())
if K >= 2**M:
    print(-1)
elif M == 1:
    if K == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
else:
    A = list(range(K)) + list(range(K+1,2**M))
    print(" ".join(map(str,A+[K]+A[::-1]+[K])))

Measured memory_bytes: 26860
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

ll N, M, V, P;
ll A[100001];

bool judge(int c){
    if(c-(P-1) > (N-V)) {
        ll rem = (c-(P-1) - (N-V))*M;
        for(int i = P-1; i < c; i++){
            if(A[c]+M-A[i] < 0) return false;
            rem -= min(M, A[c]+M-A[i]);
        }
        if(rem <= 0) return true;
        else return false;
    }else{
        if(A[P-1] <= A[c]+M) return true;
        else return false;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M >> V >> P;
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A, A+N, greater<ll>());
    
    int r = N-1;
    int l = P-1;
    if(judge(N-1)){
        cout << N << endl;
        return 0;
    }
    while(r-l > 1){
        int c = (r+l)/2;
        if(judge(c)) l = c;
        else r = c;
    }
    cout << l+1 << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define int lint
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define pb push_back
signed main(){
    double a, b;
    cin >> a >> b;
    printf("%.6lf\n", a / b);
    return 0;
}

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

using namespace std;
using ll=long long ;

void solve() {
    int n; cin >> n;
    vector<int> a(3*n);
    for (auto& x: a) {
        cin >> x;
    }
    vector<ll> L(n+1), R(n+1);
    L[0] = 0;
    priority_queue<int, vector<int>, greater<int>> min_heap;
    for (int i = 0; i < n; i++) {
        L[0] += a[i];
        min_heap.push(a[i]);
    }
    for (int i = 0; i < n; i++) {
        L[i+1] = L[i] + a[i+n];
        min_heap.push(a[i+n]);
        L[i+1] -= min_heap.top();
        min_heap.pop();
    }

    R[n] = 0;
    priority_queue<int> max_heap;
    for (int i = 0; i < n; i++) {
        R[n] += a[i+2*n];
        max_heap.push(a[i+2*n]);
    }
    for (int i = n-1; i >= 0; i--) {
        R[i] = R[i+1] + a[i+n];
        max_heap.push(a[i+n]);
        R[i] -= max_heap.top();
        max_heap.pop();
    }

    ll res = -(1ll<<60);
    for (int i = 0; i <= n; i++) {
        res = max(res, L[i]-R[i]);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

int main() {
  string s; cin >> s;
  set<string> S;
  int ans = 0;
  string sb, si;
  rep(i,s.size()) {
    si += s[i];
    if (sb != si) {
      sb = si;
      si.clear();
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3724
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN


int main(void){
	ll a[3],K;
	scanf("%lld%lld%lld%lld",&a[0],&a[1],&a[2],&K);
	sort(a,a+3);
	rep(i,K)a[2]*=2;
	printf("%lld\n",a[0]+a[1]+a[2]);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

long long func(long long x,long long y){
	if(y == 0)return 1;
	else if(y % 2 == 0){
		return func(x*x%1000000007,y/2);
	}else{
		return x*func(x,y-1)%1000000007;
	}
}

int main(){
	int m,n;

	scanf("%d %d",&m,&n);

	printf("%lld\n",func(m,n)%1000000007);
}

Measured memory_bytes: 2724
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int n, m;

int a[55][55];
int x[] = {-1,-1,-1, 0,0,  +1,+1,+1};
int y[] = {0,+1,-1, -1,+1, 0,-1,+1};
int main(){
	int i, j;
	cin >> n >> m;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			char c;
			cin >> c;
			if(c == '#'){
				a[i][j] = -1;
				for(int k=0;k<8;k++)if(a[i+x[k]][j+y[k]]>=0)a[i+x[k]][j+y[k]]++;
			}
		}
	}for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(a[i][j]==-1)cout << '#';
			else cout << a[i][j];
		}cout << '\n';
	}
}


Measured memory_bytes: 3520
N = int(input())
words = list(input())
if(len(words) % 2 == 1 ):
    print("No")
else:
    center = int(len(words) / 2)
    words_f = words[:center]
    words_b = words[center:]
    if(words_f == words_b):
        print("Yes")
    else:
        print("No")


    

Measured memory_bytes: 2940
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;


#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }
 

void solve()
{
	ll n,m,x,y;
	cin>>n>>m;
	vll cnt(n,0);
	for(ll i=0;i<m;i++)
	{
		cin>>x>>y;
		cnt[x-1]++;
		cnt[y-1]++;
	}
	for(ll i=0;i<n;i++)
		cout<<cnt[i]<<endl;
	
	return;
}

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N,K,sum=0;
      cin >> N >> K;
      for(int i=0; i<N; i++){
        int x;
        cin >> x;
        sum += 2*min(x,abs(K-x));
      }
      cout << sum;
    }

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
     
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
     
    private void solv() {
        Scanner input = new Scanner(System.in);
        Map<Character, Integer> map = new HashMap<Character, Integer>();
        for (char c = 'a'; c <= 'z'; c++) {
            map.put(c, 0);
        }
        while (input.hasNext()) {
            char[] cs = input.nextLine().toCharArray();
            for (int i = 0; i < cs.length; i++) {
                if ('A' <= cs[i] && cs[i] <= 'Z') cs[i] -= 'A' - 'a';
                if ('a' <= cs[i] && cs[i] <= 'z') map.put(cs[i], map.get(cs[i]) + 1);
            }
        }
        for (char c = 'a'; c <= 'z'; c++) {
            System.out.println(String.format("%c : %d", c, map.get(c)));
        }
    }
}

Measured memory_bytes: 17380
#include<bits/stdc++.h>
int n,m,i,j,h[1500],w[1500],p[1<<21],q[1<<21],x,a,b;
void c(int n,int*p,int*h){
  for(i=0;i<n;++i)for(x=0,j=i;j<n;++p[x])x+=h[j++];
}
main(){
  while(scanf("%d%d",&n,&m),n){
    for(a=i=0;i<n;a+=h[i++])scanf("%d",h+i);c(n,p,h);
    for(b=i=0;i<m;b+=w[i++])scanf("%d",w+i);c(m,q,w);
    for(x=i=0;i<=(a<b?b:a);p[i]=q[i++]=0)x+=p[i]*q[i];
    printf("%d\n",x);
  }
}

Measured memory_bytes: 7164
fun main(args: Array<String>) {
    val (n, p) = readLine()!!.split(" ").map(String::toInt)
    val aList = readLine()!!.split(" ").map(String::toInt)

    val oddNum = aList.count { it % 2 == 1 }
    val evenNum = aList.count { it % 2 == 0 }

    var ans = 0L

    for (i in 0..evenNum) {
        val ic = comb(evenNum, i)
        for (j in 0..oddNum) {
            if (j % 2 == p) ans += ic * comb(oddNum, j)
        }
    }
    println(ans)
}

private fun comb(n: Int, r: Int): Long {
    var r = r
    if (n < 0 || r < 0 || n < r) {
        return 0
    }
    if (r > n / 2) {
        r = n - r
    }
    var ans = 1.0
    for (i in 0..(r - 1)) {
        ans = ans * (n - (r - 1) + i) / (i + 1)
    }
    return ans.toLong()
}



Measured memory_bytes: 35952
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n;
vector<pair<string, ll>> p;
map<pair<string, ll>, ll> m;
int main() {
	cin >> n;
	REP(i, n) {
		ll a;
		string s;
		cin >> s >> a;
		m[pair<string, ll>(s, a)] = i + 1;
		p.push_back(pair<string, ll>(s, a * -1));
	}
	sort(ALL(p));
	REP(i, p.size()) {
		cout << m[pair<string, ll>(p[i].first, p[i].second * -1)] << endl;
	}
}

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

long long a, b, c, x, y;

long long solve();

int main() {
  cin >> a >> b >> c >> x >> y;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = a * x + b * y;
  c *= 2;
  ans =
      min(ans, min(x, y) * c + (x - min(x, y)) * min(a, c) +
                   (y - min(x, y)) * min(b, c));
  return ans;
}

Measured memory_bytes: 256
//C - A x B + C
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define LL long long
#define Cl(X,Y) memset((X),(Y),sizeof(X))
#define FOR(i,A,B) for(int i=A;i<=B;i++)
#define BOR(i,A,B) for(int i=A;i>=B;i--)
#define Lowbit(X) (X & (-X))
#define INF 0x3f3f3f3f
#define Rson (X<<1|1)
#define Lson (X<<1)
using namespace std;
const int MaxN=1e6+10;

int n;
int num[MaxN],prime[MaxN],d[MaxN];
bool vis[MaxN];

inline void File() {
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
}

void fun(int n)
{
	memset(vis,0,sizeof(vis));
	num[1]=1;
	d[1]=1;
	prime[0]=0;
	for(int i=2;i<=n;i++)
	{
		if(!vis[i])
		{
			prime[++prime[0]]=i;
			d[i]=1;
			num[i]=2;
		}
		for(int j=1;j<=prime[0]&&i<=n/prime[j];j++)
		{
			vis[i*prime[j]]=1;
			if(i%prime[j]==0)
			{
				d[i*prime[j]]=d[i]+1;
				num[i*prime[j]]=num[i]/(d[i]+1)*(d[i]+2);
				break;
			}
			d[i*prime[j]]=1;
			num[i*prime[j]]=num[i]*2;
		}
	}
}

int main() {
    // File();
    ios::sync_with_stdio(false);
    cin>>n;
    fun(n);
    LL Ans=0;
    FOR(i,1,n-1) 
        Ans+=num[i];
    cout<<Ans<<endl;
    // fclose(stdin);
    // fclose(stdout);
   // system("pause");
    return 0;
}

Measured memory_bytes: 12676
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

int main() {
  double T, X;
  cin >> T >> X;
  cout << T / X << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := newScanner()
	N := sc.nextInt()
	W := sc.nextInt()
	var s [4][]int
	var w1 int
	for i := 0; i < N; i++ {
		w := sc.nextInt()
		v := sc.nextInt()
		if i == 0 {
			w1 = w
		}
		s[w-w1] = append(s[w-w1], v)
	}
	for i := 0; i < 4; i++ {
		sort.Sort(sort.Reverse(sort.IntSlice(s[i])))
		s[i] = append([]int{0}, s[i]...)
		for j := 1; j < len(s[i]); j++ {
			s[i][j] += s[i][j-1]
		}
	}
	var ans int
	for i := 0; i < len(s[0]); i++ {
		for j := 0; j < len(s[1]); j++ {
			for k := 0; k < len(s[2]); k++ {
				for l := 0; l < len(s[3]); l++ {
					f := w1*i + (w1+1)*j + (w1+2)*k + (w1+3)*l
					if f <= W {
						ans = max(ans, s[0][i]+s[1][j]+s[2][k]+s[3][l])
					}
				}
			}
		}
	}
	fmt.Println(ans)
}

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

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) nextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) nextInt() int {
	v, _ := strconv.Atoi(s.next())
	return v
}

func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main(){
    while(1){
        int a,b,c;
        cin >> a >> b >> c;
        if(a == 0) break;

        vector<int> factor_a;
        for(int i=1; i<=a; i++){
            if(a%i == 0) factor_a.push_back(i);
        }
        vector<int> factor_c;
        for(int i=1; i<=abs(c); i++){
            if(abs(c)%i == 0){
                factor_c.push_back(i);
                factor_c.push_back(-i);
            }
        }
        sort(factor_c.begin(), factor_c.end());

        bool found = false;
        for(auto r: factor_a){
            for(auto s: factor_c){
                int p = a/r;
                int q = c/s;    
                if(p*s +r*q == b){
                    cout << p << " " << q << " " << r << " " << s << endl;
                    found = true;
                    break;
                }
            }
            if(found) break;
        }
        if(c == 0){
            if(a == 1 and b < 0){
                cout << "1 0 1 " << b << endl;
            }else{
                cout << a << " " << b << " 1 0" << endl;
            }
            found = true;
        }
        if(!found){
            cout << "Impossible" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3136
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I,N) for(i8t I=0,I##_N=N;I<I##_N;I++)
#define FR(I,N) for(i8t I=N;I--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;
int main() {
  R(N)R(A)R(B)R(C);RL(dummy);
  i8t t[3]={A,B,C};
  std::string lines[3];
  std::vector<char> out;

  auto check = [&](){
    for(int s=0;s<8;s++) {
      i8t t2[3]={t[0],t[1],t[2]};
      bool fail=false;
      for(int i=0;i<3;i++){
        int a=lines[i][0]-'A',b=lines[i][1]-'A';
        if (s>>i&1) std::swap(a,b);
        t2[a]++;
        t2[b]--;
        if (t2[b]<0){
          fail=true;
          break;
        }
      }
      if(!fail){
        out.push_back(lines[0][s&1]);
        int a=lines[0][0]-'A',b=lines[0][1]-'A';
        if (s&1) std::swap(a,b);
        t[a]++;
        t[b]--;
        return true;
      }
    }
    return false;
  };

  F(I,N){
    RL1(lines[2]);
    if(I>=2){
      if(!check())goto No;
    }
    lines[0]=lines[1];
    lines[1]=lines[2];
  }
  lines[2]="AA";
  if(N>=2&&!check())goto No;
  lines[0]=lines[1];
  lines[1]=lines[2];
  lines[2]="AA";
  if(!check())goto No;
  P("Yes");
  for(char c:out)P(c);
  return 0;
No:
  P("No");
  return 0;
}


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

using namespace std;

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

    int s;cin>>s;

    int a=s/100;
    int b=s-a*100;
    // cout<<a<<" "<<b;
    if(a>=1&&a<=12){
        if(b>=1&&b<=12){
            cout<<"AMBIGUOUS";
        }else {
            cout<<"MMYY";
        }
    }else{
        if(b>=1&&b<=12){
            cout<<"YYMM";
        }else {
            cout<<"NA";
        }
    }
    cout<<endl;
}

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    FOR(i, n){
        cin >> p[i];
    }

    int sol = 0;
    vector<int> b(n, 1);
    int cntrun = 0;
    FOR1(i, n-1){
        if (p[i] > p[i-1])
            b[i] = b[i-1]+1;
        else
            b[i] = 1;
        if (b[i] >= k)
            cntrun++;
    }
    sol += cntrun>0;

    set<int> S;
    FOR(i, k)
        S.insert(p[i]);
    FOR(i, n-k+1){
        if (i + k < n) {
            S.insert(p[i + k]);
            if (*S.begin() == p[i] && *S.rbegin() == p[i + k]) {

            } else if ((b[i+k-1] < k)){
                sol++;
            }
        }
        else if ((b[i+k-1] < k))
            sol++;
        S.erase(p[i]);
    }
    cout << sol << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


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

int main(){
	int N;
  	cin >> N;
	vector<int> d(N);
	for(int i = 0; i < N; i++) cin >> d.at(i);
	sort(d.begin(), d.end());
	int ans = d.at(N / 2) - d.at(N / 2 - 1);
	cout << ans << endl;
}

Measured memory_bytes: 640
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let s = read_as_string().chars().collect::<Vec<char>>();
    let n = s.len();
    let t = read_as_vec::<usize>()[0];

    if s.iter().all(|x| s[0] == *x){
    //if (s.len() == 1) || (s.len() == 2 && s[0] == s[1]){
        println!("{}", s.len()*t/2);
        return;
    }else if s.len() == 2{
        println!("0");
        return;
    }

    let mut i = 0;
    let mut x = 0;
    let (mut first_len, mut last_len) = (0, 0);
    while i < n{
        let mut j = 0;
        while i+j < n && s[i] == s[i+j]{
            j += 1;
        }
        if i == 0{
            first_len = j;
        }

        if i + j == n{
            last_len = j;
        }
        i += j;
        x += j/2;
    }
    let mut y = 0;
    if first_len%2 == 1 && last_len%2 == 1 && s[0] == s[n-1]{
        y = 1;
    }
    println!("{}", x*t + y*(t-1));
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;
double eps = 1e-11;

struct unionFind {
    vector<int> data;
    unionFind(int size) : data(size, -1) {}
    
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if(data[y] < data[x]) {
                swap(x, y);
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int root(int x) {
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }

    int rank(int x) {
        return -data[root(x)];
    }
};

//cost,from,toの順
vector<tiii> T;
vector<tiii> Krusans;

ll Kruskal(int n) {
    sort(T.begin(), T.end());
    ll ans = 0;
    ll num = 0;
    unionFind u(n);
    int size = T.size();
    for (int i = 0; i < size; i++) {
        int cost = get<0>(T[i]);
        int from = get<1>(T[i]);
        int to = get<2>(T[i]);
        if (u.root(from) != u.root(to)) {
            u.unite(from, to);
            ans += cost;
            num++;
            tiii t = make_tuple(cost, from, to);
            Krusans.push_back(t);
        }
        if (num == n - 1) {
            break;
        }
    }
    return ans;
}

pii x[200000], y[200000];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int xx, yy;
        cin >> xx >> yy;
        x[i] = pii(xx, i);
        y[i] = pii(yy, i);
    }
    sort(x, x + N);
    sort(y, y + N);
    for(int i = 0; i < N - 1; i++) {
        tiii t1 = make_tuple(x[i + 1].first - x[i].first, x[i].second, x[i + 1].second);
        T.push_back(t1);
        tiii t2 = make_tuple(y[i + 1].first - y[i].first, y[i].second, y[i + 1].second);
        T.push_back(t2);
    }
    ll ans = Kruskal(2 * (N - 1));
    cout << ans << endl;
}


Measured memory_bytes: 8304
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    global a
    ans = 0
    i = 1
    piv = a[0]
    while i<n:
        while a[i]<piv:
            ans += piv-a[i]
            i += 1
            if n<=i:
                break
        if i<n:
            piv = a[i]
            i += 1
    print(ans)
    return

if __name__=='__main__':
    n = I()
    a = list(IL())
    solve()

Measured memory_bytes: 50816
#include<bits/stdc++.h> 
using namespace std; 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define scan(a,n) for (ll i = 0; i < n; ++i) cin >> a[i]
typedef long long int ll;
int main() 
{ 
	// ios_base::sync_with_stdio(false);
 //    cin.tie(NULL);
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
		ll n,x,y;
		cin>>n>>x>>y;
		// ll a[n];
		// scan(a,n);
		if(n%x==0)
			cout<<y*(n/x);
		else
			cout<<y*(n/x+1);
	return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int a, b, c;
    cin >>a >> b >> c;
    if(a > b)swap(a,b);
    if(a <= c and c <= b){
        puts("Yes");
    }else{
        puts("No");
    }
}

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

// ??°???input????????????string??¨??????????´??????????????????¨
// ???????????????????????\???char??¨????????????????????????c - '0'??§int???

int main() {
	vector<string> v;
	string temp;
	int n;
	long sum = 0;
	while(1) {
		cin >> temp;
		if (temp == "0") break;
		v.push_back(temp);
	}

	for (auto str : v) {
		temp = str;
		for (char& c : str) {
			n = c - '0';
			sum += n;
		}
		cout << sum << endl;
		sum = 0;
	}
	return 0;
}

Measured memory_bytes: 3120
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

//#define int long long
#define endl '\n'
#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())     
#define all(x) (x).begin(), (x).end()
#define test int _; cin >> _; while(_--)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MOD = 1e9+7;

ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
inline ll mod(ll a, ll b){return ((a%b)+b)%b;}
inline ll expo(ll b, ll p, ll m = MOD){
  ll ans = 1; 
  while(p > 0){
    if(p&1LL) ans = mod(ans*b, m); 
    b = mod(b*b, m); 
    p >>= 1LL;
  } 
  return ans;
}
 
////////////////////////// Solution starts below. //////////////////////////////

const int N = 105;
const int K = 1e5+5;

int dp[2][K], v[N];
int n, k;

int solve(int cara, int quant){
  int& ans = dp[cara][quant];
  if(quant == 0) return ans = 0;
  if(ans != -1) return ans;
  ans = 0;
  for(int i = 0; i < n; i++){
    if(v[i] <= quant and !solve(cara^1, quant - v[i])){
      return ans = 1;
    }
  }
  return ans;
}

int32_t main(){
  fastio;
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(v, v+n);
  int ans = solve(0, k);
  cout << (ans ? "First" : "Second") << endl;
  return 0;
}

Measured memory_bytes: 7296
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<cstring>
#define INF 1e9+10
using namespace std;
map <char,int>leta;
map <char,int>letb;
string s,t;
int num=1,sn[200005],tn[200005],yes=1;
int main(){
    cin>>s;
    cin>>t;
    for(int i=0;i<s.size();i++){
        if(!leta[s[i]])
            leta[s[i]]=num++;
        sn[i]=leta[s[i]];
    }
    num=1;
    for(int i=0;i<t.size();i++){
        if(!letb[t[i]])
            letb[t[i]]=num++;
        tn[i]=letb[t[i]];
    }
    for(int i=0;i<s.size();i++){
        if(sn[i]!=tn[i]||s.size()!=t.size()){
            yes=0;
            break;
        }
    }
    if(yes)
        printf("Yes");
    else
        printf("No");

}


Measured memory_bytes: 4904
#include <iostream>
#include <string>
using namespace std;
int s[100005];
int t[100005];
int main() {
  ios::sync_with_stdio(false);
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  char prev = '*';
  int idx = -1;
  for (int i=0; i<S.size(); i++) {
    if (prev != S[i]) {
      idx++;
      s[idx] = 1;
    } else {
      s[idx]++;
    }
    prev = S[i];
  }
  int start = S[0] - '0';
  int num = idx+1;
  t[0] = 0;
  for (int i=0; i<num; i++) {
    t[i+1] = t[i] + s[i];
    //cout << t[i+1] << endl;
  }
  int ret;
  if (start == 0) {
    ret = t[min(K*2, num)];
  } else {
    ret = t[min(K*2+1, num)];
  }
  //cout << ret << endl;
  start = 1 - start;
  for (int i=1; i<num; i++) {
    int d;
    if (start == 0) {
      d = t[min(K*2+i, num)] - t[i];
    } else {
      d = t[min(K*2+1+i, num)] - t[i];
    }
    ret = max(ret, d);
    start = 1 - start;
    //cout << d << endl;
  }
  cout << ret << endl;
}

Measured memory_bytes: 1232
N=int(input())
h=list(map(int,input().split()))
def calc(h):
        if h==[]:
                return 0
        if 0 not in h:
                return calc(list(map(lambda x:x-1,h)))+1
        if h[0]==0:
                return calc(h[1:])
        elif h[-1]==0:
                return calc(h[:-1])
        for i in range(1,len(h)-1):
                if h[i]==0:
                        return calc(h[:i])+calc(h[i+1:])
print(calc(h))

Measured memory_bytes: 3188
from math import pi, sin, cos

count = int(input())
p1 = [0,0]
p2 = [100,0]

def koch(p1, p2, count):

    if count == 0:
        return

    p3 = [ (2*p1[0] + p2[0]) / 3, (2*p1[1] + p2[1]) / 3]

    p5 = [ (p1[0] + 2*p2[0]) / 3, (p1[1] + 2*p2[1]) / 3]

    p4 = [ (p5[0]-p3[0])*cos(pi/3) - (p5[1]-p3[1])*sin(pi/3) + p3[0], \
        (p5[0]-p3[0])*sin(pi/3) + (p5[1]-p3[1])*cos(pi/3) + p3[1]] # なぜ

    koch(p1, p3, count - 1)
    print(*p3) # 配列の[]を外す
    koch(p3, p4, count - 1)
    print(*p4) # 配列の[]を外す
    koch(p4, p5, count - 1)
    print(*p5) # 配列の[]を外す
    koch(p5, p2, count - 1)

print(*p1)
koch(p1, p2, count)
print(*p2)


Measured memory_bytes: 5784
import collections

MODBY = 7 + 10**9

N = int(input())
A_list = [int(e) for e in input().split()]

c = collections.Counter(A_list)

if N%2 == 0:
    for j in c.items():
        if j[1] != 2 or j[0]%2 != 1:
            print(0)
            break
    else:
        print(2**(N//2)%MODBY)
elif N%2 == 1:
    if c[0] != 1:
        print(0)
    else:
        for j in c.items():
            if (j[1] != 2 and j[0] != 0) or j[0]%2 != 0:
                print(0)
                break
        else:
            print(2**(N//2)%MODBY)

Measured memory_bytes: 14820
a, b, c, x, y = map(int, input().split())
price = a * x + b * y
for i in range(min(x,y)):
    if a + b > 2 * c:
        price = price - (a + b) + 2 * c
    else:
        break

for i in range(max(x, y) - min(x, y)):
    if (x > y):
        if (a > 2 * c):
            price = price - a + 2 * c
        else:
            break
    else:
        if (b > 2 * c):
            price = price - b + 2 * c 
print(price)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;

int main(){
	int n, p; cin >> n >> p;
	int a[n], s = 0, t = 0;
	Rep(i, n){
		cin >> a[i];
		a[i] %= 2;
		if(a[i] == 0){
			s++;
		}else{
			t++;
		}
	}
	if(n == 1){
		if(a[0] == p){
			cout << 1 << endl;
		}else{
			cout << 0 << endl;
		}
	}else if(t == 0){
		if(p){
			cout << 0 << endl;
		}else{
			ll ans = 1;
			Rep(i, s){
				ans *= 2;
			}
			cout << ans << endl;
		}
	}else{
		ll ans = 1;
		Rep(i, s){
			ans *= 2;
		}
		Rep(i, t - 1){
			ans *= 2;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
int k=0,n=0, m=0, l=0,a=0, b=0, c=0, d=0,ans=0,ans2=0,x=0,y=0;
string s,t,S;
signed main() {
    cin >> n;
    //n >> x >> y;
    //cin >> s >> t;
  cout <<pow(n,3);
}

Measured memory_bytes: 4244
lists = input().split()
a = int(lists[0])
b = int(lists[1])
x = int(lists[2]) * 2
answer  = []
next = 0
for num in range(0, x):
    if(a == b):
        answer.append(a)
        break
    answer.append(a)
    answer.append(b)
    a += 1
    b -= 1
    if(len(answer) >= x or a > b or b < 0):
        break
    if(a == b):
        answer.append(a)
        if(a + num < b - num):
            for b_num in range(b, a):
                answer.append(b_num)
                if (len(answer) > x):
                    break
        elif(a + num > b - num):
            for a_num in range(a, b):
                answer.append(a_num)
                if (len(answer) > x):
                    break
        break
answer.sort()
for a in answer:
    print(a)

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

using namespace std;
int a[305][305], cop[305][305];
bool used[305][305];

int main()
{
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            cin >> a[i][j];
            cop[i][j] = a[i][j];
        }

    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                cop[i][j] = min(cop[i][j], cop[i][k] + cop[k][j]);

    bool fl = true;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (a[i][j] != cop[i][j])
                fl = false;
    if (!fl)
    {
        cout << -1;
        return 0;
    }

    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
            {
                if (a[i][j] == a[i][k] + a[k][j] && k != i && k != j)
                    used[i][j] = true;
            }
    long long sum = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            if (!used[i][j])
                sum += (long long) a[i][j];
        }
    sum /= 2;
    cout << sum;
    return 0;
}


Measured memory_bytes: 1024
// Problem : C - Walk on Multiplication Table
// Contest : AtCoder - AtCoder Beginner Contest 144
// URL : https://atcoder.jp/contests/abc144/tasks/abc144_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
    return (x>=0 and y>=0 and x<n and y<m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
    mem(isprime,true);
    for(ll p=2;p*p<=n;p++)
    {
        if(isprime[p]==true)
        {
            for(ll i=p*p;i<=n;i+=p)
                isprime[i]=false;
        }
    }
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
void solve()
{
    ll n;
    cin>>n;
    vector<ll> v;
    for(ll i=1;i*i<=n;i++)
    {
    	if(n%i==0)
    	{
    		v.pb(i);
    		if(i!=n/i)
    			v.pb(n/i);
    	}
    }
    ll ans=n-1;
    
    for(ll i=0;i<(v.size()-v.size()%2);i+=2)
    {
    	ans=min(ans,v[i]+v[i+1]-2);
    }
    if(v.size()&1)
   	{
   		ans=min(ans,v.back()*2 -2);
   	}
   	cout<<ans;
}
int main()
{
    ll inpoup = 0;
    if(inpoup==1)
    {
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
    }
    IOS
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string>
int main(){
    int A,B;
    scanf("%d %d",&A,&B);

    int count = 0;
    for (int i = A;i <= B;i++){
        std::string str = std::to_string(i);
        if (str[0] == str[4] && str[1] == str[3]){
            count++;
        }
    }

    printf("%d\n",count);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string n; cin >> n;
    rep(i,n.size()) {
        if (n[i]=='7'){
            ct("Yes");
            return 0;
        }
    }
    ct("No");

}



Measured memory_bytes: 3612
import java.util.Scanner;


public class Main {
    public static void main(String[] args){
        Scanner scan  = new Scanner(System.in);
        String[] s = scan.next().split("");
        boolean firstc = false;
        boolean f = false;

        for (int i = 0; i < s.length; i++){
            if (s[i].equals("C") && !firstc){
                firstc = true;
            }else if (firstc && !f && s[i].equals("F") ){
                f = true;
            }
        }

        if (f) System.out.println("Yes");
        else System.out.println("No");


    }
}


Measured memory_bytes: 9684
import java.util.ArrayDeque
import kotlin.math.max

//

fun main() {
    abc173d()
}

fun abc173d() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }
    val sorted = a.sortedDescending()
    var total = 0L
    val queue = ArrayDeque<Long>()
    queue.add(sorted[0])
    for (i in 1 until n) {
        val good = if (i % 2 == 1) {
            queue.poll()
        } else {
            queue.peek()
        }
        queue.add(sorted[i])
        total += good
    }
    println(total)
}


Measured memory_bytes: 71072
from collections import defaultdict
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n = int(input())
dic = defaultdict(int)
for i in range(n):
    s = ''.join(sorted(input()))
    dic[s] += 1
count = 0
for key, value in dic.items():
    if value >= 2:
        count += cmb(value, 2)
print(count)

Measured memory_bytes: 18228
let N = stdin.ReadLine() |> int

let v =
    stdin.ReadLine().Split()
    |> Array.map float
    |> Array.sortDescending

let rec resolver l =
    if l <= 1 then ()
    else
        v.[l - 2] <- (v.[l - 2] + v.[l - 1]) / 2.0
        resolver (l - 1)

resolver v.Length
v.[0] |> stdout.WriteLine

Measured memory_bytes: 13652
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    int N;
    Scanner sc = new Scanner(System.in);
    
    N = sc.nextInt();
    if (N % 2 == 0){
      System.out.println(N / 2 - 1);
    }else{
      System.out.println((N-1)/2);
    }
  }
}

Measured memory_bytes: 21712
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	int n = s.size();
	bool ok = (s[0] == '1') && (s.back() == '0');
	for (int i = 0; i < n - 1; ++i) {
		ok = ok && (s[i] == s[n - 2 - i]);
	}

	if (!ok) {
		cout << "-1\n";
		return 0;
	}

	vector<pair<int, int>> ans;
	int r = n;
	for (int i = n - 1; i > 0; --i) {
		ans.emplace_back(r, i);
		if (s[i - 1] == '1') { r = i; }
	}
	
	for (auto p : ans) {
		cout << p.first << " " << p.second << endl;
	}

	return 0;
}


Measured memory_bytes: 2548
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
const int inf=INT_MAX;
const int nmax=2e5+5;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
int n,i,lo,hi,cur;
ll a[nmax],ans[nmax];
int main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<=n;i++)cin>>a[i];
    lo=0,hi=cur=n+1;
    for(i=1;i<=n;i++)
	{
		if(i%2!=0)ans[++lo]=a[--cur];
		else ans[--hi]=a[--cur];
	}
	for(i=1;i<=n;i++)cout<<ans[i]<<" ";cout<<endl;
	return 0;
}

Measured memory_bytes: 5376
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    int b[] = new int[n];
    int c[] = new int[n-1];
    int total = 0;

    for(int i=0 ; i<n ; i++){
      a[i] = sc.nextInt();
    }
    for(int j=0 ; j<n ; j++){
      b[j] = sc.nextInt();
    }
    for(int k=0 ; k<n-1 ; k++){
      c[k] = sc.nextInt();
    }

    for(int l=0 ; l<n ; l++){
      total = total +b[l];
    }
    for(int m=0 ; m<n-1 ; m++){
      if(a[m]+1 == a[m+1]){
        total = total + c[a[m]-1];
      }
    }
    System.out.println(total);
  }
}


Measured memory_bytes: 23380
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	vector<ll> s(n + 1, 0);
	map<ll, ll> nums;
	rep(i, n) {
		s[i + 1] = s[i] + a[i];
	}
	rep(i, n + 1) {
		nums[s[i]]++;
	}

	ll res = 0;
	for (auto it : nums) {
		ll num = it.second;
		res += num * (num - 1) / 2;	//nC2
	}

	out(res);

	return 0;
}

Measured memory_bytes: 15104
#include <stdio.h>
int min(int x, int y) {
	return x < y ? x : y;
}
int max(int x, int y) {
	return x > y ? x : y;
}
int main() {
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	printf("%d %d\n", min(a, b), max(a + b - n, 0));
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

int main() {
    while (true) {
        int x, y, s;
        cin >> x >> y >> s;
        if ( x == 0 ) { break; }
        vi bef(s);
        vi aft(s);
        rep (i, s) {
            bef[i] = (int)((double)i*(100+x)/100);
            aft[i] = (int)((double)i*(100+y)/100);
        }
        int maxaft = INT_MIN;
        FOR (i, 1, s-1) {
            FOR (j, i, s) {
                if ( bef[i]+bef[j] == s ) {
                    maxaft = max(maxaft, aft[i]+aft[j]);
                }
            }
        }
        printf("%d\n", maxaft);
    }

    return 0;
}

Measured memory_bytes: 3076
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	ll n;
	cin>>n;
	vector<ll>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	ll ans=0;
	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<n;j++){
			ans=max(ans,abs(v[i]-v[j]));
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256