akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/ruby
class TLLI
	def initialize
		@trianies=[nil,[0,0,0]]
	end
	def root_triany
		1
	end
	def allocate_triany
		siz=@trianies.size
		@trianies[siz]=[0,0,0]
		return siz
	end
	def set_a(id,value)
		return if !@trianies[id]
		@trianies[id][0]=value
	end
	def set_b(id,value)
		return if !@trianies[id]
		@trianies[id][1]=value
	end
	def set_c(id,value)
		return if !@trianies[id]
		@trianies[id][2]=value
	end
	def get_a(id)
		return if !@trianies[id]
		@trianies[id][0]
	end
	def get_b(id)
		return if !@trianies[id]
		@trianies[id][1]
	end
	def get_c(id)
		return if !@trianies[id]
		@trianies[id][2]
	end
end

$black={}
class SETI <TLLI # a=>key, b=>left, c=>right
	def set_entry(key)
		if $black[key]
			$black.delete(key)
			return
		end
		x=root_triany
		y=0
		while x!=0&&!(x==root_triany&&get_a(x)==0) #fixme
			y=x
			if key<get_a(x)
				x=get_b(x)
			else
				x=get_c(x)
			end
		end
		if y==0
			set_a(root_triany,key)
		else
			leaf=allocate_triany
			set_a(leaf,key)
			if key<get_a(y)
				set_b(y,leaf)
			else
				set_c(y,leaf)
			end
		end
	end
	def find_entry(key)
		return false if $black[key]
		t=root_triany
		loop{
			return true if key==get_a(t)
			if key<get_a(t)
				t=get_b(t)
				return false if t==0
			else
				t=get_c(t)
				return false if t==0
			end
		}
	end
	def print_preorder(t)
		return if t==0
		unless $black.has_key?(get_a(t))
			Kernel.print(' ')
			Kernel.print(get_a(t))
		end
		print_preorder(get_b(t))
		print_preorder(get_c(t))
	end
	def print_inorder(t)
		return if t==0
		print_inorder(get_b(t))
		unless $black.has_key?(get_a(t))
			Kernel.print(' ')
			Kernel.print(get_a(t))
		end
		print_inorder(get_c(t))
	end
	def print_postorder(t)
		return if t==0
		print_postorder(get_b(t))
		print_postorder(get_c(t))
		unless $black.has_key?(get_a(t))
			Kernel.print(' ')
			Kernel.print(get_a(t))
		end
	end
	def print
		print_inorder(root_triany)
		Kernel.puts
		print_preorder(root_triany)
		Kernel.puts
	end
end

seti=SETI.new
$<.drop(1).each{|l|
	a=l.chomp.split
	if a[0]=='insert'
		seti.set_entry(a[1].to_i)
	elsif a[0]=='find'
		puts seti.find_entry(a[1].to_i) ? :yes : :no
	elsif a[0]=='delete'
		$black[a[1].to_i]=1
	elsif a[0]=='print'
		seti.print
	end
}

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

using namespace std;


int n;

int main(){
    cin>> n;
    if(n==25)cout<<"Christmas";
    else if(n==24)cout<<"Christmas Eve";
    else if(n==23)cout<<"Christmas Eve Eve";
    else if(n==22)cout<<"Christmas Eve Eve Eve";
    cout<<endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//INF = 1 061 109 567 ; INF + INF = 2 122 219 134 ;
//LINF = 4 557 430 888 798 830 399 ; LINF + LINF = 9 114 861 777 597 660 798 ;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9+7;
const int N = (int)1e5+7;

//浮点型运算
const db eps = 1e-6;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }

//--------变量--------//

int n, a[N];
bool prim[N];

//--------函数--------//

void Init() {
	memset(prim, false, sizeof(prim));
	rep(i, 2, N) {
		if (!prim[i]) {
			for (int j = i+i; j < N; j+=i)
				prim[j] = true;
		}
	}
}

int Solve() {
	prim[1] = true; a[0] = 0;
	rep(i, 1, N) {
		if (!prim[i] && !prim[(i+1)/2])
			a[i] = a[i-1]+1;
		else 
			a[i] = a[i-1];
	}
	rep(i, 0, n) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", a[r] - a[l-1]);
	}
}

//--------main--------//

int main ()
{
	while (~scanf("%d", &n)) {
		Init();
		Solve();
	}
    return 0;
}

Measured memory_bytes: 1152
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(n):
    minj = i
    for j in range(i,n):
        if a[j] < a[minj]:
            minj = j
    if i != minj:
        cnt += 1
    a[i],a[minj] = a[minj],a[i]
print(*a)
print(cnt)


Measured memory_bytes: 5604
loop {
	n = gets.to_i
	break if n == 0
	points = (1..n).map{ gets.split.map(&:to_i) }
	points << [0, 0]
	points.sort!
	#p points

	route = []
	loop {
		path = [points[0]]
		1.upto(points.size-1){|i|
			if path.size >= 2
				x1, y1 = path[-2]
				x2, y2 = path[-1]
				x3, y3 = points[i]

				if x1 != x2
					if x2 == x3 || (y2 - y1).to_f / (x2 - x1) < (y3 - y2).to_f / (x3 - x2) 
						path.pop
						redo
					end
				end
			end
			path << points[i]
		}
		#p path
		if path.size == points.size
			route += path
			break
		end
		path.pop
		route += path
		points -= path
		points.reverse!
	}
	#p route
	total_dist = route.each_cons(2).map{|u, v|
		x1, y1 = u
		x2, y2 = v
		Math.sqrt((x1-x2)**2 + (y1-y2)**2)
	}.inject(:+)
	printf("%.1f\n", total_dist)
}

Measured memory_bytes: 6300
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

k = ni()

p = [[0]*10 for _ in range(10)]

for i in range(k+1):
  s = [int(_) for _ in str(i)]
  p[s[0]][s[-1]]+=1

ans=0

for i in range(1,10):
  for j in range(1,10):
    ans += p[i][j] * p[j][i]

print(ans)

Measured memory_bytes: 3064
N=gets.to_i
a=gets.chomp.split.map(&:to_i)

a.delete_if{|x| x%2!=0}
a.delete_if{|x| x%3==0}
a.delete_if{|x| x%5==0}

if a.empty?
    puts "APPROVED"
else
    puts "DENIED"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 1005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;


int n;
int l[8];
int A, B, C;

int dfs(int k, int a, int b, int c)
{
    if (k == n) {
        if (a == 0 || b == 0 || c == 0) return 1e9;
        return abs(a - A) + abs( b - B) + abs(c - C);
    }

    int ans = 1e9;
    ans = min(ans, dfs(k + 1, a + l[k], b, c) + (a > 0 ? 10 : 0));
    ans = min(ans, dfs(k + 1, a, b + l[k], c) + (b > 0 ? 10 : 0));
    ans = min(ans, dfs(k + 1, a, b, c + l[k]) + (c > 0 ? 10 : 0));
    ans = min(ans, dfs(k + 1, a, b, c));
    return ans;
}

int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    //cin >> T;
    T = 1;
    for (int cs = 1; cs <= T; cs++) {
        cin >> n >> A >> B  >> C;
        for (int i = 0; i < n; i++) cin >> l[i];
        cout << dfs(0, 0, 0, 0) << endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
xy = []
for i in range(n):
    a.append(int(input()))
    xy.append([list(map(int, input().split())) for i in range(a[-1])])
ans = 0
for i in range(2**n):
    x = [1] * n
    for j in range(n):
        if (i>>j)&1:
            x[j] = 0
    flag = False
    for j in range(n):
        for k in range(a[j]):
            if x[j] == 1:
                if x[xy[j][k][0]-1] != xy[j][k][1]:
                    flag = True
                    break
        if flag:
            break
    if flag:
        continue
    ans = max(ans, x.count(1))
print(ans)

Measured memory_bytes: 9048
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  ll H;
  cin >> H;
  int e = 0;
  ll num = 0;
  while (H > 1) {
    num += pow(2, e);
    e++;
    H = H / 2;
  }
  num += pow(2, e);
  cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, m;
    cin >> n >> m;
    if (n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

int main()
{
    int n;

    cin>>n;

    vector<int>arr(n,0);

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

    int cnt=0;

    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            for(int k=j+1; k<n; k++){
                if(arr[i]!=arr[j] && arr[j]!=arr[k] && arr[i]!=arr[k]){
                    if((arr[i]+arr[j])>arr[k] && (arr[i]+arr[k])>arr[j] && (arr[j]+arr[k])>arr[i]){
                        cnt++;
                    }
                }
            }
        }
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    while(1)
    {
        int nb_lignes,nb_colonnes;
        cin>>nb_lignes>>nb_colonnes;
        if(nb_lignes==0)
        {
            break;
        }
        vector<string> donut(nb_lignes);
        for(int c=0;c<donut.size();c++) cin>>donut[c];
        int dx[8]={1,1,1,0,0,-1,-1,-1};
        int dy[8]={0,1,-1,1,-1,0,1,-1};
        map<string,int> m;
        string best = "";
        for(int x=0;x<nb_lignes;x++)
        {
            for(int y=0;y<nb_colonnes;y++)
            {
                for(int d=0;d<8;d++)
                {
                    vector<vector<bool> > visites(nb_lignes,vector<bool>(nb_colonnes,false));
                    int xact = x;
                    int yact = y;
                    string act ="";
                    while(!visites[xact][yact])
                    {
                        act=act+donut[xact][yact];
                        m[act]++;
                        if((act.size()>best.size()||(act.size()==best.size()&&act<best))&&m[act]>1)
                            best=act;
                        visites[xact][yact]=true;
                        xact+=dx[d];
                        yact+=dy[d];
                        xact=(xact+nb_lignes)%nb_lignes;
                        yact=(yact+nb_colonnes)%nb_colonnes;
                    }
                }
            }
        }
        if(best.size()<2) cout<<0<<endl;
        else
            cout<<best<<endl;
    }
}

Measured memory_bytes: 36068
n = int(input())
num_list = list(map(int, input().split()))
     
a = 1
if 0 in num_list:
    print(0)
else:
    for x in num_list:
        a = a * x
        if (a > 1000000000000000000):
            print("-1")
            break
    if (a <= 1000000000000000000):
      print(a)

Measured memory_bytes: 21648
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
using namespace std;
int n;
ll s,x,ans;
map<ll,int> m;
int main(){
    cin>>n;
    m[0]=1;
    for(int i=1;i<=n;++i){
        cin>>x;
        s+=x;
        ans+=m[s]*1ll;
        ++m[s];
    }
    cout<<ans<<endl;
	//system("pause");
	return 0;
}


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

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

  long long int ans = 0;
  long long int k = 0;

  for ( long long int i = n - 1; i > k; i-- ) {
    if ( s[i] == 'W' ) continue;
    if ( s[k] == 'R' ) {
      i++;
      k++;
      continue;
    }
    ans++;
    s[i] = 'W';
    s[k] = 'R';
    k++;
  }
  
  cout << ans << endl;
  
  return 0;
  
}

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

int main() {
	// your code goes here
	int n,sum=0;
	cin>>n;
	int a[n],b[n],c[n-1];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
	for(int i=0;i<n-1;i++)
		cin>>c[i];
	for(int i=0;i<n;i++){
		sum+=b[a[i]-1];
		if(a[i]==(a[i-1]+1))
			sum+=c[a[i-1]-1];	
	}
	cout<<sum;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	deque<int> d;
	bool front=false;
	REP(i,0,n-1) {
		int val;
		cin>>val;
		if(front)d.PUF(val);
		else d.PUB(val);
		front=!front;
	}
	if(n&1) {
		while(!d.empty()) {
		cout<<d.back()<< " ";
		d.POB();
	} }else
	while(!d.empty()) {
		cout<<d.front()<< " ";
		d.POF();
	}
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 4460
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);


    int n, m;
    cin >> n >> m;
    vector<int> A(m);
    for (int i = 0; i < m; ++i) {
        cin >> A[i];
    } 

    int N = 1 << n;
    const long long MOD = 1000000007;

    vector<long long> FS(N + 1, 1);
    for (int i = 1; i <= N; ++i) {
        FS[i] = FS[i - 1] * i % MOD;
    }
    vector<long long> invs(N + 1, 1);
    for (int i = 2; i <= N; ++i) {
        invs[i] = (MOD - MOD / i) * invs[MOD % i] % MOD;
    }
    vector<long long> IFS(N + 1, 1);
    for (int i = 2; i <= N; ++i) {
        IFS[i] = IFS[i - 1] * invs[i] % MOD;
        assert(IFS[i] * FS[i] % MOD == 1);
    }

    auto nCr = [&](int n, int r) {
        if (r > n || r < 0) {
            return 0LL;
        }
        return FS[n] * IFS[r] % MOD * IFS[n - r] % MOD;
    };

    reverse(A.begin(), A.end());

    vector<long long> dp(N, 0);
    dp[0] = 1;

    for (auto x : A) {
        for (int i = N - 1; i >= 0; --i) {
            for (int j = 0; j < n; ++j) {
                if (i & (1 << j)) {
                    continue;
                }

                int ni = i | (1 << j);
                dp[ni] += (dp[i] * nCr(N - x - i, (1 << j) - 1) % MOD * FS[1 << j] % MOD);
                dp[ni] %= MOD;
            }
        }
    }

    long long res = 0;
    for (int i = 0; i < N; ++i) {
        int s = 1;
        for (int j = 0; j < n; ++j) {
            if (i & (1 << j)) {
                s = -s;
            }
        }
        res += (MOD + s * dp[i] * FS[N - 1 - i] % MOD) % MOD;
        res %= MOD;
    }

    for (int i = 0; i < n; ++i) {
        res <<= 1;
        res %= MOD;
    }


    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 

int main()
{ 

    int a,b;
    cin>>a>>b;

    cout<<6-a-b<<endl;
    return 0;
}

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



int main()
{
	double a, b, c, s, C;
	double S, L, h, PI=3.141592653589793; 
	
	scanf("%lf%lf%lf", &a, &b, &C);
	c = sqrt(a*a + b*b - 2*a*b*cos(C*PI/180));
	L = a+b+c;
	s = L/2;
	S = sqrt(s*(s-a)*(s-b)*(s-c));
	h = 2*S/a;
	printf("%.8lf\n%.8lf\n%.8lf\n", S, L, h);
	return 0;
}


Measured memory_bytes: 2104
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"3 1
4 1 5"# => r#"5"#,

r#"8 9
7 9 3 2 3 8 4 6"# => r#"0"#,

r#"3 0
1000000000 1000000000 1000000000"# => r#"3000000000"#,
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        n: usize,
        mut k: usize,
        mut h: [usize; n]
    }

    h.sort();
    h.reverse();
    let mut ans = 0;

    for i in 0..n {
        ans += if 0 < k { k -= 1; 0 } else { h[i] };
    }

    ans.to_string()
}

Measured memory_bytes: 9464
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef long double ldb;

const int MX = 1e5 + 5;
const int INF = 0x3f3f3f3f;

int n;
bool ans[MX];
char S[MX], op[] = "SW";

bool check() {
    for(int i = 2; i <= n; i++) {
        if(S[i] == 'o') ans[i + 1] = ans[i - 1] ^ ans[i];
        else ans[i + 1] = ans[i - 1] ^ ans[i] ^ 1;
    }

    int ret = (ans[n + 1] == ans[1]);
    if(S[1] == 'o') ret &= (ans[n] == (ans[1] ^ ans[2]));
    else ret &= (ans[n] != (ans[1] ^ ans[2]));
    return ret;
}
int main() {
    // FIN;
    bool ok = 0;
    scanf("%d%s", &n, S + 1);
    for(int i = 0; i <= 1; i++) {
        for(int j = 0; j <= 1; j++) {
            ans[1] = i; ans[2] = j;

            if(check()) {
                ok = 1; goto ans;
            }
        }
    }
ans:
    if(!ok) printf("-1\n");
    else {
        for(int i = 1; i <= n; i++) {
            printf("%c", op[ans[i]]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define int long long
#define endl "\n"
 
 
 
signed main()
{
    FAST;
    int t;
    t=1;
    while(t--)
    {
        int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
        int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
        int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
        int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
        int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
        
        string a,b;
        cin>>a>>b;
        n = a.length();
        for(i=0;i<n;i++)
        {
            if(a[i]!=b[i]) ans++;
        }
        
        cout<<ans<<endl;
    
    
        
    }
        
    
    
    
    
}

Measured memory_bytes: 3764
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.insert(場所,要素)
-1で末尾で末尾から一つ前
'''


N = int(stdin.readline().rstrip())
T = list(range(1, N+1))
t = len([x for x in T if x % 2 == 1])
print(t/len(T))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
#include <cctype>
#include <cstdio>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI 3.141592653
#define rep(i, k, n) for(ll i = k; i < n; i++)



int main(){
  ll a; cin >> a;
  cout << a+ a*a + a*a*a << endl;
}


Measured memory_bytes: 3632
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

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

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

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

	string S;
	cin >> S;

	int cur = 0;
	int ret = 0;
	EACH(c, S){
		if(c == 'S'){
			if(cur < 0) cur = 1;
			else cur++;
		}
		else{
			cur--;
		}
		if(cur < 0) ret++;
	}

	cout << ret * 2 << endl;

	return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset> 
using namespace std;
typedef long long ll;
int main(void)
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a) printf("%lld",k);
	else if(k<=a+b) printf("%lld",a);
	else printf("%lld",a-(k-a-b));
}

Measured memory_bytes: 3752
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    if(a>0){
      System.out.println("Positive");
      return;
    }
    if(a<=0&&b>=0){
      System.out.println("Zero");
      return;
    }
    if((b-a+1)%2==0){
      System.out.println("Positive");
      return;
    }else{
      System.out.println("Negative");
    }

  }
  

  
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long int
#define M 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
const double pi = acos(-1.0);
#define F  first
#define S  second
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
const int INF = 1e18L+5;
const int LG = 20;
const int N = 1e5+9;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int power(int x,int y){if(x==0)return 0;int res=1;while(y>0){if(y%2==1)res=(res*x)%M;x=(x*x)%M;y=y/2;}return res;}
bool isvowel(char c){if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U')return true;return false;};
int32_t main()
{
	//cout.precision(15);
	//cout.setf(ios::fixed,ios::floatfield);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int T=1;
	//cin>>T;
	while(T--)
	{
		int n,m,i,x,y;
		cin>>n>>m;
		vector<int> graph[n+1];
		for(i=0;i<m;i++)
		{
			cin>>x>>y;
			graph[x].pb(y);
			graph[y].pb(x);
		}
		int dis[n+1]={0},vis[n+1]={0};
		queue<int> q;
		q.push(1);
		dis[1]=0;
		vis[1]=1;
		while(!q.empty())
		{
			int v=q.front();
			q.pop();
			for(auto u:graph[v])
			{
				if(vis[u])
					continue;
				vis[u]=1;
				dis[u]=v;
				q.push(u);
			}
		}
		for(i=2;i<=n;i++)
		{
			if(dis[i]==0)
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
		cout<<"Yes"<<endl;
		for(i=2;i<=n;i++)
		cout<<dis[i]<<endl;
	}
}



Measured memory_bytes: 13740
#include <stdio.h>
 #include <string.h>
 int main()
{
 int m, h;
 char cards[256], temp[256], result[256];
 int i, j=0, len;
 while(1){ scanf("%s", cards);
 len=strlen(cards);
 if(strcmp(cards, "-")==0&&len==1)break;
 scanf("%d", &m);
 for(;m>0;m--)
{
 scanf("%d", &h);
 strcpy(temp, cards);
 for(i=0;
i<h;
i++)
{
 cards[len-h+i]=temp[i];
 }
 for(i=0;
i<len-h;
i++)
{
 cards[i]=temp[i+h];
 }
 }
 for(i=0;
i<len;
i++)
{
 result[j++]=cards[i];
 }
 result[j++]='\n';
 }
 result[j]='\0';
 printf("%s", result);
 return 0;
 }


Measured memory_bytes: 2040
import math
n = int(input())

tax = 1.08
tmp = n / tax
if tmp.is_integer():
    print(int(tmp))

else:
    tmp = math.floor(tmp)
    if int(math.floor((tmp - 1) * tax)) == n:
        print(int(math.floor(tmp - 1)))
    elif int(math.floor((tmp) * tax)) == n:
        print(int(math.floor((tmp))))
    elif int(math.floor((tmp + 1) * tax)) == n:
        print(int(math.floor((tmp + 1))))
    else:
        print(':(')

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

const int mn=1e6+7;
string s,a[mn];
int n,cnt,l,r;

struct node {
	int la,ra;
}b[mn];

bool cmp(node a,node b)
{
	if(a.la-a.ra!=b.la-b.ra) return a.la-a.ra>b.la-b.ra;
	else return a.la<b.la;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {
		cin>>s;
		int top=0;
		for(int j=0;j<s.size();++j) {
			if(s[j]=='(') top++;
			else if(s[j]==')') {
				if(top) top--;
				else a[i]+=')';
			}
		}
		while(top) a[i]+='(',top--;
	}
	sort(a+1,a+n+1);
	
	int f=1;
//	for(int i=1;i<=n;++i) cout<<a[i]<<endl;
	for(int i=1;i<=n;++i) {
		if(a[i].size()==0) continue;
		if(a[i][0]==a[i][a[i].size()-1]&&a[i][0]=='(') {l+=a[i].size();continue;}
		if(a[i][0]==a[i][a[i].size()-1]&&a[i][0]==')') {r+=a[i].size();continue;}
		int la=0,ra=0;
		for(int j=0;j<a[i].size();++j) {
			if(a[i][j]=='(') la++;
			else ra++;
		}
		b[++cnt]=(node){la,ra};
	}
	sort(b+1,b+cnt+1,cmp);
	for(int i=1;i<=cnt;++i) {
		if(l>=b[i].ra) l+=b[i].la-b[i].ra;
		else f=0;
	}
	if(l!=r) f=0;
	puts(f?"Yes":"No");
}

Measured memory_bytes: 36432
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    int ba = 0, a = 0, b = 0, c = 0;
    for (int i = 0; i < n; i++) {
        char s[11];
        cin >> s;

        int m = strlen(s);
        for (int j = 0; j < m - 1; j++) {
            if (s[j] == 'A' && s[j + 1] == 'B') c++;
        }
        if (s[0] == 'B' && s[m - 1] == 'A') ba++;
        else if (s[0] == 'B') b++;
        else if (s[m - 1] == 'A') a++;
    }

    //Aで終わる Bで始まる
    //どちらでもないものは使わない 両方に当てはまるものは悩む

    int k = 0;
    if (ba == 0) {
        k = min(a, b);
    } else {
        if (a == 0 && b == 0) k = ba - 1;
        else if (a > 0 && b > 0) k = ba - 1 + 2 + min(a, b) - 1;
        else {
            k = ba - 1 + 1;
        }
    }

    cout << c + k << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<array>
#include<algorithm>
#define MAX 50
using namespace std;

typedef struct {
  string name;
  double rate;
}hurvest;

bool cmp(const hurvest &a,const hurvest &b){
  return a.rate > b.rate;
}

int main(){
  array<hurvest,MAX> data;
  int n,seed_cost,time_sum,time,value,F,S,M,D,E;

  while(1){
  cin >> n;
  if(n==0){
    break;
  }
  for(int i=0;i<n;i++){
    cin >> data[i].name>>seed_cost;
    time_sum=0;
    for(int j=0;j<5;j++){
      cin >> time;
      if(j==3){
	D=time;
      }
      if(j==4){
	E=time;
      }
      time_sum+=time;
    }
    
    cin >> F >> S >> M;
    value=F*S;
    if(M!=1){
      value*=M;
      time_sum+=(E+D)*(M-1);
    }
    data[i].rate=(double)(value-seed_cost)/(double)time_sum;
  }

  sort(data.begin(),data.end()-(50-n),cmp);

  bool change=true;
  hurvest temp;
  while(change){
    change=false;
    for(int i=0;i<n-1;i++){
      if(data[i].rate==data[i+1].rate){
	if(data[i].name>data[i+1].name){
	  temp=data[i];
	  data[i]=data[i+1];
	  data[i+1]=temp;
	  change=true;
	}
      }
    }
  }

  for(int i=0;i<n;i++){
    cout << data[i].name<<endl;
  }
  cout << '#' <<endl;
  }


  return 0;
}



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

int main() {
  int n,tmp,a,b,cnt;
  vector<int> li;

  cin >> n;
  for(int i = 0;i<n;i++){cin >> tmp,li.push_back(tmp);}
  sort(li.begin(),li.end());
  for(int i = 0;i<n-1;i++){
    a=li[i];
    b=li[i+1];
    if(a==b){cout << "NO" << endl;break;}
    cnt++;
  }
  
  if(cnt==n-1){cout << "YES" << endl;}
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<P> g(n);
    rep(i,n) cin>>g[i].fi>>g[i].se;
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    map<P,int> mp;
    rep(i,n)rep(j,n){
        if(i==j) continue;
        ll p=g[j].fi-g[i].fi,q=g[j].se-g[i].se;
        mp[P(p,q)]++;
    }
    int cnt=0;
    for(auto itr:mp) chmax(cnt,itr.se);
    cout<<n-cnt<<endl;
}

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

int main() {
  long long n, m;
  cin >> n >> m;
  long long a[n + 1], b[n + 1];
  for (int i = 1; cin >> a[i]; i++) {
  }
  sort(a + 1, a + n + 1);
  b[0] = 0;
  for (long long i = 1; i <= n; i++) {
    b[i] = b[i - 1] + a[i];
  }
  long long left = a[1] * 2, right = a[n] * 2 + 1;
  auto count = [&](long long x) {
    pair<long long, long long> result = {0, 0};
    for (long long i = 1, j = n; j > 0; j--) {
      while (i <= n && a[i] + a[j] < x) {
        i++;
      }
      result.first += n - i + 1;
      result.second += b[n] - b[i - 1] + a[j] * (n - i + 1);
    }
    return result;
  };
  while (left < right) {
    long long mid = (left + right) / 2;
    if (count(mid).first <= m) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  auto result = count(left);
  cout << result.second + (m - result.first) * (left - 1);
  return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debug_out() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H), debug_out(T...);
}

int main() {
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
#define debug(...) 3
    fastIO;
#endif
    string s;
    cin >> s;
    int cnt = s[0] == 'R';
    int mx=cnt;
    for(int i = 1; i < sz(s); i++) {
        if(s[i] == 'R' && s[i] == s[i - 1])cnt++;
        else cnt = s[i] == 'R';
        mx = max(mx, cnt);
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin>>str;
    int c=0;
    int l=0;
    for(int i=0;i<3;i++)
    {
        if(str[i]=='R')
        l++;
        else
        {
            if(l>c)
            c=l;
            l=0;
        }
    }
     if(l>c)
     c=l;
            cout<<c<<endl;
            return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, d, x; cin >> n >> d >> x;
  VV<> p(d, V<>(n));
  for (auto&& v : p) for (auto&& e : v) cin >> e;
  int res = x;
  for (int i = 0; i + 1 < d; ++i) {
    V<> dp(1e5 + 1);
    iota(begin(dp), end(dp), 0);
    for (int k = 0; k <= 1e5; ++k) {
      for (int j = 0; j < n; ++j) {
        if (k < p[i][j]) continue;
        dp[k] = max(dp[k], dp[k - p[i][j]] + p[i + 1][j]);
      }
    }
    res = dp[res];
  }
  cout << res << '\n';
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) fo(i,0,n)
#define pln(n) printf("%lld\n",n)
#define sll(n) scanf("%lld",&n)
#define ss(n) scanf("%s",n)
#define vi vector < int >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x,y,z) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) <<" , "<< #z <<": "<<(z)<<endl; }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<int>
#define tr(c, it) \
for(decltype(c.begin()) it = c.begin(); it!= c.end(); it++)
#define pis pair<int,string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c),x) != c.end())
#define mod (int)(1e9 + 7) 
using namespace std;



int main(){
	int m, t, s;
	cin >> m >> t >> s;
	float t1 = (float)m / s;
	if(t - t1 >= -0.000001){
		cout << "Yes";
	}
	else cout << "No";
}


Measured memory_bytes: 3544
n = gets.chomp.to_i
a = []
n.times do
  a << gets.chomp.to_i
end

flag = false

a.each_with_index do |n, i|
  if n > i
    flag = true
  end
end

if !flag
  index = n-1
  max = nil
  count = 0

  while index >= 0 && !flag
    if max.nil?
      max = a[index]
    elsif a[index+1] <= a[index]
      count += max
      max = nil
      index += 1
    elsif a[index+1] - 1 > a[index]
      flag = true
    end

    index -= 1
  end
end

if max != nil
  count += max
end

if flag
  puts -1
else
  puts count
end


Measured memory_bytes: 5500
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
prices = []
for i in range(n):
    prices.append(ii())

print(sum(prices)-max(prices)//2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    vector<int> vec(3);
    rep(i,3){
        cin >> vec[i];
    }
    sort(all(vec));
    if ((vec[2] - vec[0]) % 2 == 1 && (vec[2] - vec[1]) % 2 == 0){
        cout << (vec[2] * 2 + 3 - vec[0] - vec[1])/2 << endl;
    }
    else if ((vec[2] - vec[0])% 2 == 0 && (vec[2] - vec[1]) % 2 == 1){
        cout << (vec[2] * 2 + 3 - vec[0] - vec[1])/2 << endl;
    }
    else{
        cout << (vec[2] * 2 - vec[0] - vec[1])/2 << endl;
    }
}


Measured memory_bytes: 256
N,Q=list(map(int,input().split()))
S=input()

ac_count = [0 for i in range(N+1)]
ac_flag = [False for i in range(N+1)]
acc=0
for i in range(1,N):
    if S[i]=="C" and S[i-1]=="A":
        acc+=1
        ac_flag[i]=True
    ac_count[i+1]=acc

ans = []
for i in range(Q):
    l,r = list(map(int,input().split()))
    count=ac_count[r]-ac_count[l-1]
    if ac_flag[l-1]:
        count-=1
       
    ans.append(count)

for a in ans:
    print(a)

Measured memory_bytes: 11068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int left = A + B;
  int right = C + D;
  if (left > right) {
    cout << "Left" << endl;
  }
  else if (left == right) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3612
import sys
from math import ceil as C, floor as F, sqrt, gcd as G
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data) 

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
print('ACL' * n)


Measured memory_bytes: 67568
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

string cipher(string& s, int& i);
string st(string& s, int& i);
char ch(string& s, int& i);

string cipher(string& s, int& i){
    string res=st(s,i);
    while(i!=s.size()&&s[i]!=']'){
        res+=st(s,i);
    }
    return res;
}

string st(string& s,int& i){
    if(s[i]=='['){
        i++;
        string ret=cipher(s,i);
        i++;
        reverse(ret.begin(),ret.end());
        return ret;
    }
    else {
        char res=ch(s,i);
        string ret;
        ret+=res;
        return ret;
    }
}

char ch(string& s, int& i){
    if(s[i]=='+'){
        ++i;
        char res=ch(s,i);
        if(res=='?')return '?';
        if(res=='Z')return 'A';
        else return char(++res);
    }
    if(s[i]=='-'){
        ++i;
        char res=ch(s,i);
        if(res=='?')return '?';
        if(res=='A')return 'Z';
        else return char(--res);
    }
    return s[i++];
}

void solve(string s){
    int i=0;
    string ans=cipher(s, i);
    for(auto& c:ans)if(c=='?')c='A';
    cout<<ans<<endl;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    while(cin>>s,s!=".")solve(s);
    
    return 0;
}


Measured memory_bytes: 3140
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../../../bits/stdc++.h"
#endif

#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

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

#define pb push_back
#define mp make_pair
#define ft first
#define sd second

#define INF 1000000000000000000

int N, Q, K;

struct edge { int to, cost; };
vector<edge> G[100004];
ll d[100004];

void dijkstra(int s) {
  priority_queue< pii, vector<pii>, greater<pii> > que;
  fill(d, d+N+1, INF);
  d[s] = 0;
  que.push(pii(0, s));

  while (!que.empty()) {
    pii p = que.top(); que.pop();
    int v = p.sd;
    if (d[v] < p.ft) continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pii(d[e.to], e.to));
      }
    }
  }
}

int main(){
  cin.tie(0);
  
  cin>>N;
  
  int a, b, c;
  REP(i, N-1) {
    cin>>a>>b>>c;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }

  cin>>Q>>K;
  
  dijkstra(K);

  int x, y;
  REP(i, Q) {
    cin>>x>>y;
    cout<<(d[x]+d[y])<<endl;
  }

  return 0;
}


Measured memory_bytes: 8820
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int K;
	string S;
	scan(K>>S);
	if(S.size()<=K) prin(S);
	else{
		rep(i,K){
			printf("%c",S[i]);
		}
		prin("...");
	}
	return 0;
}


Measured memory_bytes: 3628
from itertools import accumulate

class Bit:
    def __init__(self,n):
        self.size=n
        self.tree=[0]*(n+1)

    def sum(self,i):
        s=0
        while i>0:
            s+=self.tree[i]
            i-=i&-i
        return s
    
    def add(self,i,x):
        while i<=self.size:
            self.tree[i]+=x
            i+=i&-i

N,K=list(map(int,input().split()))
a=[0]*(N+1)

for i in range(N):
    a[i+1]=int(input())

accum=[(x-K*i,i) for i,x in enumerate(accumulate(a))]
accum.sort(key=lambda x: 10**10*x[0]+x[1])
plst=[x+1 for _,x in accum]
bit=Bit(N+1)
ans=0

for i,p in enumerate(plst):
    bit.add(p,1)
    ans+=i+1-bit.sum(p)

print(N*(N+1)//2-ans)

Measured memory_bytes: 90148