akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long long mod = 1e9+7;

long long int dp[100000];

int main(){
    int n,m;
    cin >> n >> m;

    vector<bool>v(n+1,true);

    for(int i = 0;i < m;i++){
        int num;
        cin >> num;
        v[num] = false;
    }

    dp[0] = 1;

    for(int i = 0;i < n;i++){
        for(int j = i+1;j <= min(n,i+2);j++){
            if(v[i]){
                dp[j] += dp[i];
                dp[j] %= mod;
            }
        }
    }


    cout << dp[n] << endl;

    return 0;
}

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

using namespace std;

int v[100];

int main() {
#ifdef HOME
	FILE *fin = fopen("input.in", "r");
	FILE *fout = fopen("output.out", "w");
#else
	FILE *fin = stdin;
	FILE *fout = stdout;
#endif
	
	int n, x;
	fscanf(fin, "%d%d", &n, &x);
	for(int i = 0; i < n; ++i)
		fscanf(fin, "%d", &v[i]);

	std::sort(v, v + n);

	int s = 0, i = 0;
	while(i < n && s + v[i] <= x) {
		s += v[i];
		++i;
	}
	if(i == n && s < x)
		--i;
	
	fprintf(fout, "%d", i);

#ifdef HOME
	fclose(fin);
	fclose(fout);
#endif
	return 0;
}


Measured memory_bytes: 256
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll k,n;
	cin>>k>>n;
	vi v(n);
	rep(i,n){
		cin>>v[i];
	}	
	ll ans = v[n-1] - v[0];
	repa(i,1,n){
		ans = min(ans,k-v[i]+v[i-1]);
	}
	cout<<ans;
	return 0;
}

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

static const int MAX = 100;

void printStringnum(int a[],int n){
    for(int i=0;i<n-1;i++){
        cout << a[i] << " ";
    }    
    cout << a[n-1] << "\n";
}

void inserstionSort(int a[],int n){
    int v,j;
    for(int i=1;i<n;i++){
        printStringnum(a,n);
        v = a[i];
        j = i-1;
        while(j>=0 && a[j] > v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
    }
    printStringnum(a,n);
}

int bubbleSort(int a[],int n){
    int v,i,j;
    int count = 0;
    int flag = 1;
    for(i=0;flag;i++){
        flag = 0;
        for(j=n-1;j>=i+1;j--){
            v = a[j-1];
            if(v > a[j]){
                a[j-1] = a[j];
                a[j] = v;
                flag = 1;
                count++;
            }
        }
    }
    
    printStringnum(a,n);
    return count;

}


int main(){
    int n,count;

    cin >> n;
    
    int a[MAX];

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

    //inserstionSort(a,n);
    count = bubbleSort(a,n);
    cout << count << "\n";
    }


Measured memory_bytes: 3088
# AOJ 0036 A Figure on Surface

$WIDTH = $HEIGHT = 8

class Map
  FIGURES = {
    A: [
              [0, 1],
      [1, 0], [1, 1]
    ],
    B: [
      [1, 0],
      [2, 0],
      [3, 0]
    ],
    C: [
      [0, 1], [0, 2], [0, 3]
    ],
    D: [
      [1, -1], [1, 0],
      [2, -1]
    ],
    E: [
      [0, 1],
      [1, 1], [1, 2]
    ],
    F: [
      [1, 0], [1, 1],
              [2, 1]
    ],
    G: [
                       [0, 1],
      [1, -1], [1, 0]
    ]
  }

  def initialize(lines)
    @map = Array.new($HEIGHT + 4) {Array.new($WIDTH + 4, -1)}

    lines.each.with_index(1) do |row, i|
      row.each_char.with_index(1) do |c, j|
        @map[i][j] = c.to_i
      end
    end

    @figures = Hash[
      FIGURES.map {|name, cells| [name, figure?(cells)]}
    ]
  end

  def determine_figure
    (1..$HEIGHT).each do |i|
      (1..$WIDTH).each do |j|
        if @map[i][j] == 1
          @figures.each do |name, det|
            return name if det[i, j]
          end
        end
      end
    end

    nil
  end

  private
  # その形状であるかを返す lambda を返す。
  # 返された lambda には基準となる位置の i, j を渡す。
  #
  # [cells]
  # 1 でなければならない相対位置 [i_r, i_j] の配列
  def figure?(cells)
    lambda {|i, j|
      cells.map {|i_r, j_r| @map[i + i_r][j + j_r]}.all? {|v| v == 1}
    }
  end
end

while line = gets
  line.chomp!
  next if line.empty?

  lines = [line]
  ($HEIGHT - 1).times do
    lines << gets.chomp
  end

  puts Map.new(lines).determine_figure
end

Measured memory_bytes: 6124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll N = in<ll>(),X = in<ll>();
    vector<ll> tpow(N+3);
    tpow[0] = 1;
    REP(i,N+2)tpow[i+1] = 2*tpow[i];
    ll answer = 0;
    for (ll i = N; i >= 0; i--){
        if(tpow[i+1]-2 >= X){
            X--;
            if(X < 0)X = 0;
        }else if(tpow[i+1] - 1 <= X){
            answer += tpow[i];
            X-= tpow[i+1] - 1;
        }
    }
    cout << answer << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>


void selectsort(int n,int a[]);


int main(void){


   int N;
   scanf("%d",&N);
   
   int i,flag=1,array[N];
   for(i=0;i<N;i++)  {scanf("%d",&array[i]);}

   selectsort(N,array);
   return 0;
   
   

 }


void selectsort(int n,int a[]){
  int i,j,kae,count=0,minj;


 
    for(i=0;i<n-1;i++){
      minj=i;
      
      for(j=i;j<n;j++){
	if(a[j]<a[minj]){minj=j;}}


      kae=a[i];
	a[i]=a[minj];
	a[minj]=kae;

	if(i!=minj)count++;
	
      }
     
    

  
  
  for(j=0;j<n;j++){

    if(j==n-1) printf("%d",a[j]);
  else if (j!=n){printf("%d ",a[j]);}

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



Measured memory_bytes: 2124
int main(void){
 int x, y, z;

scanf("%d%d%d", &x, &y, &z);
int ispoor = 0;
if (x == y && y!= z)  ispoor = 1;
if (y == z && z != x)  ispoor = 1;
 if (z == x && x != y)  ispoor = 1;
if (ispoor) {
puts("Yes");
} else {
puts("No");
}

 return 0;
 }

 

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

int main()
{
    int n, m, c;
    int A[101][101], B[101];
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            cin >> A[i][j];
        }
    }
    for (int i = 1; i <= m; ++i)
    {
        cin >> B[i];
    }
    for (int i = 1; i <= n; ++i)
    {
        c = 0;
        for (int j = 1; j <= m; ++j)
        {
            c += A[i][j] * B[j];
        }
        cout << c << endl;
    }
    return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
const int INF = 1e9;

int main(){
	int N;string S;
	cin >> S ;
	N = S.size();
  	int ans = N, len = INF;
	for(int i = 0;i < N-1;i++){
		if(S[i]!=S[i+1]){
			len = max(i+1,N-i-1);
		}
		ans = min(ans,len);
  	}
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
long int d[100000];
bool s(int n)
{
int i;
for(i=0;i<n;i++)if(d[i]==i+1)return false;
return true;
}
void swap(int a,int b)
{int t;t=d[a];d[a]=d[b];d[b]=t;}
int main()
{
long int n,ans=0,i;
cin>>n;
for(i=0;i<n;i++)cin>>d[i];
while(!s(n))
{
for(i=0;i<n;i++)
{
if(d[i]==i+1)
{
ans++;
if(i==n-1)swap(i,i-1);
else swap(i,i+1);
}
}
}
cout<<ans;
return 0;
}




Measured memory_bytes: 1152
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class A
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = Scanner.Scan<int>();
            Console.WriteLine((N + 1) / 2);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 28212
/*input
8
27 23 76 2 3 5 62 52
*/
/**
    Author: Kristopher Paul
    Date Created: 09-06-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define pb push_back
#define INF 0x3f3f3f3f //0x3f3f3f3f = 63
#define MOD 1000000007
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int n;
    cin >> n;
    int arr[n];
    int tot = 0;
    FOR(i,0,n){
        cin >> arr[i];
        tot += arr[i];
    }
    int s = 0;
    int ans = tot;
    FOR(i,0,n-1){
        s += arr[i];
        int t = tot-s;
        remin(ans,abs(s-t));
    }
    cout << ans << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 256
import sys
def side(p1,p2):
  global D
  y1,x1=p1
  y2,x2=p2
  dy=y2-y1
  dx=x2-x1
  for p3 in D:
    if p1!=p3 and p2!=p3 and (p3[1]-x1)*dy-dx*(p3[0]-y1)<0:return 0
  else:return 1
 
while 1:
  n=input()
  if n==0:break
  D=sorted([list(input()) for i in range(n)])
  p=p1=D[0]
  while 1:
    for p2 in D:
      if p1!=p2 and side(p1,p2):break
    p1=p2
    D.remove(p2)
    if p2==p:break
  print len(D)

Measured memory_bytes: 4264
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define ll long long 
#define fab(a,b,i) for(int i=a;i<b;i++)
#define pb push_back
#define db double
#define mp make_pair
#define endl "\n"
#define f first
#define se second
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
vector< vector<int> > dp;
int n;
int cnt;
/*int recurse(int pos,int last,vector< vector<int> > v)
{
	//cnt++;
	//	cout<<cnt<<endl;
	if(dp[pos][last]!=-1)
		return dp[pos][last];
	//v[pos][last]=-1;
	if(pos==n-1)
	{
		v[pos][last]=-1;
		return dp[pos][last]=*max_element(all(v[pos]));
	}
	if(last==0)
	return dp[pos][last]=max({recurse(pos+1,1,v)+v[pos][1],recurse(pos+1,2,v)+v[pos][2]});
	else if(last==1)
		return dp[pos][last]=max({recurse(pos+1,0,v)+v[pos][0],recurse(pos+1,2,v)+v[pos][2]});
	else
		return dp[pos][last]=max(recurse(pos+1,1,v)+v[pos][1],recurse(pos+1,0,v)+v[pos][0]);
}*/
int main()
{ quick;


	cin>>n;
	vector< vector<int> > a(n, vector<int>(3));
	fab(0,n,i)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];

	}
	dp= vector< vector<int> > (n,vector<int>(3,0));
	int ans=-1;
	fab(0,3,i)
	dp[0][i]=a[0][i];
	fab(1,n,i)
	{
		fab(0,3,j)
		{
			fab(0,3,k)
			if(j!=k)
			{
				dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
			}
		}
	}
	cout<<*max_element(all(dp[n-1]))<<endl;
	//for(auto p:dp[n-1])
	//	cout<<p<< " ";

	return 0;
}

Measured memory_bytes: 11264
#include<stdio.h>

long a[100001];

int main(int argc, char const *argv[]) {
	long n,i,sum=0,num;
	scanf("%ld",&n);
	for(i=0;i<n;i++){
		scanf("%ld",&a[i]);
		sum+=a[i];
	}
	a[n]=a[0];
	for(i=0;i<n;i++){
		a[i]=a[i+1]-a[i];
	}
	num=n*(n+1)/2;
	if(sum%num==0){
		num=sum/num;
		for(i=0;i<n;i++){
			a[i]-=num;
			a[i]=-a[i];
			if(a[i]<0 || a[i]%n!=0) break;
		}
		if(i==n) printf("YES\n");
		else printf("NO\n");
	}else printf("NO\n");
	return 0;
}

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

const int M=2e5+5;
vector<int> g[M];
int val[M];

void dfs(int u,int fa)
{
	val[u]+=val[fa];
	for(int v:g[u])
	{
		if(v==fa) continue;
		dfs(v,u);
	}
}

int main()
{
	int n,q;
	scanf("%d%d",&n,&q);
	int u,v;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int p,x;
	for(int i=0;i<q;i++)
	{
		scanf("%d%d",&p,&x);
		val[p]+=x;
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
		printf("%d%c",val[i],i==n?'\n':' ');
	return 0;
}

Measured memory_bytes: 23424
#include <stdio.h>

int main(){
	int N, R, IR, results;
	scanf("%d %d", &N, &R);
	if(N >= 10){results = R; printf("%d", results);}
	else if (N < 10){IR = 10 - N; results = 100 * IR + R; printf("%d", results);}
	return 0;
}

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

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main(){
  ll n;
  cin >> n;
  if(n==1 || n==2){
    cout << 0 << endl;
    return 0;
  }
  vector<ll> vec = divisor(n);
  ll sum = 0;
  rep(i, vec.size()){
    ll m = vec[i]-1;
    if(m != 0 && n / m == n/vec[i] && n % m == n/vec[i]) sum += m;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	string s;
	cin >> s;
	vector<vector<int>>nx(10, vector<int>(N, MOD));
	for (int i = 0; i < N; i++) {
		nx[s[i] - '0'][i] = i;
	}
	for (int i = 0; i < 10; i++) {
		for (int j = N - 2; j >= 0; j--) {
			nx[i][j] = min(nx[i][j], nx[i][j + 1]);
		}
	}
	int ans = 0;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				int cn = nx[i][0];
				if (cn + 1 < N) {
					cn = nx[j][cn + 1];
					if (cn + 1 < N) {
						cn = nx[k][cn + 1];
						if (cn != MOD)ans++;
					}
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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

int main() {
	string S;int a;cin >> a >> S;
    cout << (a>=3200?S:"red") << endl;
    return 0;



}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()
s=input().rstrip()
ans=""
n=len(s)
for i in range(n):
    if i%2==0:
        ans+=s[i]
print(ans)


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

int main() {
 double k;	
 int i,hi,lo,m,b,q1,q2,c1,c2;
 while (cin >> q1 && q1!=0) {
	 cin >> b >> c1 >> c2 >> q2;
	 hi=q2+1; lo=0; 
	 for (i=0;i<30;i++) {
		 m=(hi+lo)/2;
		 k=(double)(b-c1*m)/c2;
		 if (k>=0 && (m+k)>=q1) lo=m; else hi=m;
	 }
	 if (m==0) cout << "NA" << endl; else cout << m  << ' ' << (b-c1*m)/c2 << endl;
 }    
  return 0;
}	

Measured memory_bytes: 1160
#include <stdio.h>
#include <algorithm>
using namespace std;
#define MAX 100000

struct card{
    char chara;
    int num;
    int index;
};

// card A[MAX];

int partition(card A[], int p, int r){
    int x = A[r].num;
    int i = p-1;
    for(int j=p; j<r; j++){
        if(A[j].num <= x){
            i = i+1;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

void quickSort(card A[], int p, int r){
    if(p < r){
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q+1, r);
    }
}

void isStable(card A[], int n){
    int x;
    for(int i=0; i<n; i++){
        if(A[i].num == A[i+1].num && A[i].index > A[i+1].index){
            printf("Not stable\n");
            return;
        }
    }
    printf("Stable\n");
    return;
}

int main(void){
    int n;
    card A[MAX];
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%s %d", &A[i].chara, &A[i].num);
        A[i].index = i;
    }

    quickSort(A, 0, n-1);
    isStable(A, n);
    for(int i=0; i<n; i++){
        printf("%c %d\n", A[i].chara, A[i].num);
    }
    return 0;
}


Measured memory_bytes: 3856
//package AtCoder;
import java.io.*;
import java.util.*;

public class Main {
	static int n,w;
	static long a[][],dp[][];
	static long dp(int i,int curw)
	{
		if(curw>w)
			return (int)-1e9;

		if(i==n || curw == w)
			return 0;
		if(dp[i][curw]!=-1) return dp[i][curw];
		
		long take=a[1][i]*1l+dp(i+1,curw+(int)a[0][i]);
		long leave=dp(i+1,curw);
		return dp[i][curw]=Math.max(take, leave);
	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		n=sc.nextInt();w=sc.nextInt();
		a=new long[2][n];// 0 for weight 1 for value
		dp=new long[n][w+1];
		for(int i=0;i<n;i++)
		{
			a[0][i]=sc.nextInt();
			a[1][i]=sc.nextInt();
			Arrays.fill(dp[i], -1);
		}
		System.out.println(dp(0, 0));
		pw.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		boolean hasnext() throws IOException {
			return br.ready();
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] a = new Integer[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		char[] nextCharArray() throws IOException {
			return br.readLine().toCharArray();
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] ans = new double[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextDouble();
			return ans;
		}

	}
}


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

int main()
{
    int n;
    cin >> n;
    int *a = new int[n];
    int *b = new int[n];
    int *c = new int[n];
    for( int i=0;i<n;i++)
    cin >> a[i] >> b[i] >> c[i];
    int ans[3][n];
    ans[0][0]= a[0];
    ans[1][0]= b[0];
    ans[2][0]= c[0];
    for(int i=1;i<n;i++)
    {
        ans[0][i] = a[i] + max(ans[1][i-1], ans[2][i-1]);
        ans[1][i] = b[i] + max(ans[0][i-1], ans[2][i-1]);
        ans[2][i] = c[i] + max(ans[1][i-1], ans[0][i-1]);
    }
    cout << max(ans[0][n-1],max(ans[1][n-1], ans[2][n-1]));
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, i;
    cin >> N >> i;
    cout << N - i + 1 << endl;
    return 0;
}

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

int main() {
    string a,b,c;
  cin>>a>>b>>c;
  cout<<char(a.at(0)+('A'-'a'))<<char(b.at(0)+('A'-'a'))<<char(c.at(0)+('A'-'a'))<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
typedef vector<ll> vll;
#define rall(s) s.rbegin(),s.rend()
typedef map<ll,ll> mll;
#define fr(n,x) for(ll n=0;n<x;n++)
#define pb push_back
#define EL cout<<'\n'
#define all(s) s.begin(),s.end()

void solve(){
    ios_base::sync_with_stdio(0); cin.tie(0);
	ll x,y,k;
	cin>>x>>y>>k;
	if(x>=k){
        cout<<x-k<<' '<<y;
	}
	else{
        cout<<0<<' '<<max(y-(k-x),0LL);
	}
}

int main(){
    ll T=1;
    //cin>>T;
    while(T--)solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<cctype>
#include <fstream>
#include <time.h>
#include <iterator>




#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;

vector<int>v;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	v.resize(N);
	REP(i, N) {
		cin >> v[i];
	}
	VSORT(v);
	VREVERSE(v);
	int ans = 0;
	REP(i, N) {
		ans += v[i];
	}
	ans -= v[0] / 2;
	print(ans);
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n, m = MI()
    # 明るさaは0-indexedにする
    aa = LI1()
    # 頂点xをお気に入りにしたときのスコアをpx+qで表す
    # imos法を使う
    pp = [0] * (m + 1)
    qq = [0] * (m + 1)

    for a0, a1 in zip(aa, aa[1:]):
        if a0 < a1:
            pp[a0 + 1] += -1
            pp[a1 + 1] += 1
            qq[0] += a1 - a0
            qq[a0 + 1] += a0 + 1
            qq[a1 + 1] += -a0 - 1
        else:
            pp[0] += -1
            pp[a1 + 1] += 1
            pp[a0 + 1] += -1
            qq[0] += a1 + 1
            qq[a1 + 1] += m - a0 - 1
            qq[a0 + 1] += a0 + 1
    for i in range(1, m):
        pp[i] += pp[i - 1]
        qq[i] += qq[i - 1]
    ans = min(pp[i] * i + qq[i] for i in range(m))
    print(ans)

main()


Measured memory_bytes: 17008
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

r, c, k = LI()
maze = [[0] * (c+1) for _ in range(r+1)]
for _ in range(k):
    R, C, V = LI()
    maze[R][C] = V

dp1 = [[0] * (c+1) for _ in range(r+1)]
dp2 = [[0] * (c+1) for _ in range(r+1)]
dp3 = [[0] * (c+1) for _ in range(r+1)]

for i in range(1, r+1):
    for j in range(1, c+1):
        v = maze[i][j]
        dp1[i][j] = max(dp1[i][j-1], dp1[i-1][j] + v, dp2[i-1][j] + v, dp3[i-1][j] + v)
        dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1] + v)
        dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1] + v)
ans = max(dp1[-1][-1], dp2[-1][-1], dp3[-1][-1])
print(ans)

Measured memory_bytes: 358840
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef unsigned long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

vector<ll> a;
int main(){
    vector<ll> dp(100000);
    dp[0] = 1;
    int c = 0;
    ll k;
    cin >> k;
    vector<ll> cn(8);
    cn[0] = 1;
    for(int i=1;i<5000;i++){
        bool flag = 0;
        if(i%8!=0){
            dp[i] = cn[(i%8)-1];
            cn[(i%8)] += dp[i];
        }else{
            dp[i] = 1;
            cn[0]++;
        }
        if(i%8==7){
            if(dp[i]<(ll)1e18){    
                cerr << dp[i] << endl;
                a.PB(dp[i]);
                c++;
            }else{
                flag = 1;
                break;
            }
        }
        if(flag)break;
    }
    cerr << c << endl;
    vector<ll> cnt(c);
    for(int i=c-1;i>=0;i--){
        cnt[i] = k/a[i];
        k -= a[i]*cnt[i];
        cnt[i];
    }
    rep(i,c){
        cerr << a[i] << " " << cnt[i] << endl;
    }
    string ans;
    for(int i=c-1;i>=0;i--){
        for(int j=0;j<cnt[i];j++){
            ans += "F";
        }
        ans +="ESTIVAL";
    }

    cerr << ans.size() << endl;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
using namespace std;

void print(int A[],int n) {
    for (int i = 0; i < n; i++)
        printf("%d%c", A[i], i == n - 1 ? '\n' : ' ');
}

void insertionSort(int *a, int n)
{
    for (int i = 1; i < n; i++)
    {
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && v < a[j])
        {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;

        print(a,n);
    }
}
int main()
{
    int n = 0, a[105];
    cin >> n;

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


Measured memory_bytes: 3224
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, K) = read!(usize, usize);
    let S = rl().chars().collect::<Vec<_>>();

    let mut count = 0;
    for i in 0..N {
        let happy = match S[i] {
            'L' if i >= 1 => S[i - 1] == 'L',
            'R' if i + 1 < N => S[i + 1] == 'R',
            _ => false,
        };
        if happy {
            count += 1;
        }
    }

    println!("{}", min(count + 2 * K, N - 1))
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(src,dst)    for(int i=src; i<dst;  i++)
#define rep2(src,dst)   for(int j=src; j<dst;  j++)
#define INF 1000000000000 //1e+12
#define MOD 10000007 //1e9+7
#define PI  acos(-1)
#define ll long long
template<typename T> inline void ChMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void ChMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  DivUp(T a, T b)   {return ((a+b-1)/b);}

int main(){
    int n; cin >> n;
    set<string> ans;
    rep(0,n){
        string s;
        cin >> s;
        ans.insert(s);
    }
    cout << ans.size() << endl;
    return 0;
}
/*

*/


Measured memory_bytes: 19100
#include <stdio.h>
#include <string.h>
#define rep(i, n) for ((i)=0;(i)<(n);(i)++)

typedef struct {
    int top;
    int S;
    int E;
    int W;
    int N;
    int bottom;
} Dice;

int main(void) {
    int i, n, tmp1, tmp2, tmp3;
    char commands[101] = {'\0'};
    Dice dice;
    i = 0;

    scanf("%d %d %d %d %d %d",&dice.top,&dice.S,&dice.E,&dice.W,&dice.N,&dice.bottom);
    
    scanf("%s", commands);
    n = strlen(commands);

    rep(i, n) {
        if (commands[i] == 'S') {
            tmp1 = dice.S;
            dice.S = dice.top;
            tmp2 = dice.bottom;
            dice.bottom = tmp1;
            tmp3 = dice.N;
            dice.N = tmp2;
            dice.top = tmp3;
        } else if (commands[i] == 'E') {
            tmp1 = dice.E;
            dice.E = dice.top;
            tmp2 = dice.bottom;
            dice.bottom = tmp1;
            tmp3 = dice.W;
            dice.W = tmp2;
            dice.top = tmp3;
        } else if (commands[i] == 'N') {
            tmp1 = dice.N;
            dice.N = dice.top;
            tmp2 = dice.bottom;
            dice.bottom = tmp1;
            tmp3 = dice.S;
            dice.S = tmp2;
            dice.top = tmp3;
        } else if (commands[i] == 'W') {
            tmp1 = dice.W;
            dice.W = dice.top;
            tmp2 = dice.bottom;
            dice.bottom = tmp1;
            tmp3 = dice.E;
            dice.E = tmp2;
            dice.top = tmp3;
        }
    }
    printf("%d\n", dice.top);

    return 0;
}



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

#define int long long

auto main() -> signed {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; ++i) cin >> v[i];
    sort(v.begin(), v.end());
    cout << v[v.size()-1] - v[0] << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,pair<int,int>>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int h, w;
char c[2005][2005];
int up[2005][2005], down[2005][2005], ri[2005][2005], le[2005][2005];
signed main() {
	cin >> h >> w;
	rep(i, h)rep(j, w)cin >> c[i][j];
	//UP
	rep(i, w) {
		int cnt = 0;
		rep(j, h) {
			if (c[j][i] == '.')cnt++;
			else cnt = 0;
			up[j][i] = cnt;
		}
	}
	//DOWN
	rep(i, w) {
		int cnt = 0;
		for (int j = h - 1; j >= 0; j--) {
			if (c[j][i] == '.')cnt++;
			else cnt = 0;
			down[j][i] = cnt;
		}
	}
	//LEFT
	rep(i, h) {
		int cnt = 0;
		rep(j, w) {
			if (c[i][j] == '.')cnt++;
			else cnt = 0;
			le[i][j] = cnt;
		}
	}
	//RIGHT
	rep(i, h) {
		int cnt = 0;
		for (int j = w - 1; j >= 0; j--) {
			if (c[i][j] == '.')cnt++;
			else cnt = 0;
			ri[i][j] = cnt;
		}
	}
	int ans = 0;
	rep(i, h) {
		rep(j, w) {
			if (c[i][j] == '#')continue;
			int cnt = 0;
			if (i)cnt += up[i - 1][j];
			if (j)cnt += le[i][j - 1];
			cnt += down[i + 1][j];
			cnt += ri[i][j + 1];
			cnt++;
			ans = max(ans, cnt);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 129792
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s,a;

int main(){
	cin>>a>>s;
	for(int i=0;i<s.length();i++){
		cout<<a[i]<<s[i];
	}
	if(a.length()-s.length()){
		cout<<a[a.length()-1];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
import bisect
n, k = [int(item) for item in input().split()]
x = [int(item) for item in input().split()]

lft_num = bisect.bisect(x, 0)
rgt_num = n - lft_num

ans = 10**10
for i in range(min(rgt_num, k)):
    r = x[lft_num + i]
    distance = abs(r)
    if i+1 == k: 
        ans = min(ans, distance)
        continue
    if lft_num - (k-i-1) >= 0:
        l = x[lft_num - (k-i-1)]
        distance += abs(r - l)
        ans = min(ans, distance)
for i in range(min(lft_num, k)):
    l = x[lft_num - i - 1]
    distance = abs(l)
    if i+1 == k: 
        ans = min(ans, distance)
        continue
    if lft_num + (k-i-2) < n:
        r = x[lft_num + (k-i-2)]
        distance += abs(r - l)
        ans = min(ans, distance)
    
print(ans)

Measured memory_bytes: 14096
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? ((x) : -(x)))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, K, Q, T;
int A[16];
int P[16];
vector<pair<int, int>> vec[16];

int main()
{
	int i, j;
	int x, y;
	scanf("%d", &N);
	for (i = 1; i <= N; ++i) {
		scanf("%d", &A[i]);
		for (j = 1; j <= A[i]; ++j) {
			scanf("%d%d", &x, &y);
			vec[i].push_back({ x, y });
		}
	}
	int fullset = (1 << N) - 1;
	int maxi = 0;
	for (int subset = 0; subset <= fullset; ++subset) {
		int cnt = 0;
		bool flag = true;
		for (j = 0; j < N; ++j) {
			if (subset & (1 << j)) {
				P[j + 1] = 1;
				++cnt;
			}
			else P[j + 1] = 0;
		}
		for (i = 1; i <= N; ++i) {
			if (P[i] == 1) {
				for (j = 0; j < vec[i].size(); ++j) {
					x = vec[i][j].first;
					y = vec[i][j].second;
					if (P[x] != y) {
						flag = false;
						goto L;
					}
				}
			}
		}
	L:
		if (flag) maxi = MAX(maxi, cnt);
	}
	printf("%d", maxi);


}

Measured memory_bytes: 256
from heapq import heappop,heappush
N = int(input())
V = list(map(int,input().split()))
V.sort()
while True:
    if len(V) == 1:
        break
    a = heappop(V)
    b = heappop(V)
    heappush(V,(a + b) / 2)
print(heappop(V))

Measured memory_bytes: 3060
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];
        for (int i = 0 ; i<n ; i++){
                a[i] = sc.nextInt();
            
            
        }
        int x = 0;
        int count = 0 ;
        for(int i = 0 ;i<n-1 ; i++){
             if(a[i]>=a[i+1]){
                 
                 count++;
                 b[i] =count;
             }
            
            else
                 count = 0;
        }
               Arrays.sort(b);
                
            
     System.out.println(b[n-1]);
}
}

Measured memory_bytes: 62596
#include<string.h>
#include <iostream>
#include<cstdio>
#include <stack>
#include <vector>
// this is a comment
using namespace std;
#define INF 0x7ffffff
typedef long long ll;
const int maxn=1e5+10;
int pre[maxn];
int dis[maxn];
int findset(int x)
{
    if(x==pre[x])   return x;
    int root=findset(pre[x]);
    dis[x]=dis[pre[x]]+dis[x];
    return pre[x]=root;
}
bool unionset(int x,int y,int w)
{
    int fx=findset(x),fy=findset(y);
    if(fx==fy)
        return w==dis[y]-dis[x];
    pre[fy]=fx;
    dis[fy]=dis[x]+w-dis[y];
    return true;
}
int n,m;       //input members
int main()    //main body
{
   scanf("%d%d",&n,&m);
   for(int i=1;i<=n;i++)
    pre[i]=i;
   bool lose=true;
   for(int i=0;i<m;i++)
   {
       int x,y,w;
   scanf("%d%d%d",&x,&y,&w);
        if(lose)
       lose=unionset(x,y,w);
   }
   if(lose) printf("Yes\n");          //output
   else     printf("No\n");
}
//parshant

Measured memory_bytes: 1024
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var x = int.Parse(line[0]);
        var a = int.Parse(line[1]);
        var b = int.Parse(line[2]);
        var n = int.Parse(Console.ReadLine().Trim());
        getAns(x, a, b, n);
    }
    static void getAns(int x, int a, int b, int n)
    {
        var t = x;
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim();
            if (s[0] == 'n')
            {
                t += a;
                t = Max(0, t);
            }
            else if (s[0] == 't')
            {
                t += b;
                t = Max(0, t);
            }
            else t = 0;
        }
        Console.WriteLine(t);
    }
}



Measured memory_bytes: 18024
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
vector<int> adj[2000005];
int n,m;
int d[2000005];
bool visited[2000005];
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);adj[y].push_back(x);
	}
	memset(d,-1,sizeof(d));
	queue<int> q;
	q.push(1);
	d[1]=0;
	visited[1]=1;
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int child:adj[x])
		{
			if(d[child]==-1)
			{
				d[child]=d[x]+1;
				visited[child]=true;
				q.push(child);
			}
		}
	}
	if(d[n]==2)cout<<"POSSIBLE";
	else cout<<"IMPOSSIBLE";
}
	

Measured memory_bytes: 62576
//http://agc014.contest.atcoder.jp/tasks/agc014_b
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
//    freopen("../input3.txt", "r", stdin);

    int N, M, a, b;
    int odd[200000];

    memset(odd, 0, 800000);

    scanf("%d%d", &N, &M);

    for (int i = 0; i < M; i++) {
       scanf("%d%d", &a, &b);
        odd[a - 1]++;
        odd[b - 1]++;
        if (a < 1 || a > N || b < 1 || b > N || a == b)
            goto BadEnd;
    }

    short result = 1;
    int max = 0;
    for (int i = 0; i < N; i++) {
        if (odd[i] % 2 == 1) {
            result = 0;
            break;
        }
        if (odd[i] > max)
            max = odd[i];
    }

    if (result)
        printf("YES\n");
    else
        BadEnd:
        printf("NO\n");

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define sp ' '
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;
const int mod998 = 998244353;

int N, H, W, cnt, A, B;

int main() {
	cin >> N >> H >> W;
	for (int i = 0; i < N; ++i) {
		cin >> A >> B;
		if (H <= A && W <= B)++cnt;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	makei(R);
	makei(G);
	say(2 * G - R);
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<=(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x,0,sizeof(x))
#define MINF(x) memset(x,0x3f,sizeof(x))
#define MMINUS(a) memset(a,0xff,sizeof(a))
#define ten(n) ((int)1e##n)

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1.0/LINF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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 gcd(int a,int b){return b?gcd(b,a%b):a;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

using namespace std;

class DPeopleOnALine {
public:
    int N, M;
    struct edge { int to, w; };
    vector<edge> G[ten(5)+1];
    ll val[ten(5)+1]{0};
    bool search[ten(5)+1]{false};

    void solve(std::istream& in, std::ostream& out) {
        in >> N >> M;
        REP(i, M) {
            int l, r, w; in >> l >> r >> w;
            G[l].push_back((edge){r, w});
            G[r].push_back((edge){l, -w});
        }

        FOR(i, 1, N) {
            if (!search[i]) {
                dfs(i, 0);
            }
        }

        bool ok = true;
        FOR(i, 1, N) {
            FOREACH(e, G[i]) {
                if (val[e.to] - val[i] != e.w) {
                    ok = false;
                    break;
                }
            }
            if (!ok) break;
        }

        if (ok) {
            OUT("Yes");
        } else {
            OUT("No");
        }
    }

    void dfs(int s, int sv) {
        val[s] = sv;
        search[s] = true;
        FOREACH(e, G[s]) {
            if (!search[e.to]) {
                dfs(e.to, sv + e.w);
            }
        }
    }
};


int main() {
    DPeopleOnALine solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 11008