akhauriyash/Code-Regression huggingface dataset:
class PriorityQueue
  def initialize(array = [])
    @data = []
    array.each{|a| add(a)}
  end

  def add(element)
    @data.push(element)
    bottom_up
  end

  # @return Integer
  def peek
    @data[0]
  end

  # @return Integer
  def poll
    if size == 0
      return 0
    elsif size == 1
      return @data.pop
    else
      max = @data[0]
      @data[0] = @data.pop
      top_down
      return max
    end
  end

  # @return Integer
  def size
    @data.size
  end

  private

  def swap(i, j)
    @data[i], @data[j] = @data[j], @data[i]
  end


  def bottom_up
    idx = size - 1
    while(has_parent?(idx))
      parent_idx = parent_idx(idx)
      if @data[parent_idx] < @data[idx]
        swap(parent_idx, idx)
        idx = parent_idx
      else
        return
      end
    end
  end

  def top_down
    idx = 0
    while (has_child?(idx))
      a = left_child_idx(idx)
      b = right_child_idx(idx)
      if @data[b].nil?
        c = a
      else
        c = @data[a] >= @data[b] ? a : b
      end
      if @data[idx] < @data[c]
        swap(idx, c)
        idx = c
      else
        return
      end
    end
  end


  # @param Integer
  # @return Integer
  def parent_idx(idx)
    (idx - (idx.even? ? 2 : 1)) / 2
  end

  # @param Integer
  # @return Integer
  def left_child_idx(idx)
    (idx * 2) + 1
  end

  # @param Integer
  # @return Integer
  def right_child_idx(idx)
    (idx * 2) + 2
  end

  # @param Integer
  # @return Boolent
  def has_child?(idx)
    ((idx * 2) + 1) < @data.size
  end

  def has_parent?(idx)
    idx > 0
  end
end

n, m = gets.chomp.split(' ').map(&:to_i)
jobs = (1..n).map { gets.chomp.split(' ').map(&:to_i) }.group_by { |ab| ab.first }
sum = 0
pq = PriorityQueue.new
1.upto(m) do |d|
  jobs[d].map(&:last).each { |money| pq.add(money) } if jobs[d]
  sum += pq.poll
end

puts sum


Measured memory_bytes: 21628
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
 


int main()
{
	//ifstream cin("input.txt");
	string s;
	cin>>s;
	
	vi cnt(s.length(), 0);

	if(s[0] == 'A' || s[0]=='C'||s[0]=='G'||s[0]=='T')
		cnt[0] = 1;

	rep(i, 1, s.length())
		if(s[i] == 'A' || s[i]=='C'||s[i]=='G'||s[i]=='T')
			cnt[i] = cnt[i-1] + 1;

	cout<<*max_element(cnt.begin(), cnt.end());
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
typedef long long ld;

int main() {
	ll n;
    cin>>n;
    vector<ll>rta(n+1,0);
    vector<ll>a(n,0);
    ll tmp;
    for (int i=0; i<n; i++){
        cin>>tmp;
        a[i]=tmp;
        rta[tmp]++;
    }
     tmp=0;
    for (int i=0; i<n; i++){
        tmp+=(rta[i+1]*(rta[i+1]-1))/2;
    }
    for (int i=0; i<n; i++){
        cout<<tmp-rta[a[i]]+1<<endl;
    }
}

Measured memory_bytes: 6428
import collections

n = int(input())
dq = collections.deque()
dq.append('3')
dq.append('5')
dq.append('7')
cnt = 0
while dq:
    v = dq.popleft()
    int_v = int(v)
    if int_v <= n:
        for c in '357':
            dq.append(v + c)
        if all([c in v for c in '357']):
            cnt += 1
print(cnt)


Measured memory_bytes: 7540
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));

using namespace std;
using P = pair<long long, long long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////


struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

int main() {
	int N;
	cin >> N;
	vector<ll>A(N);
	ll sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		sum += A[i];
	}
	ll right = sum;
	ll left = 0;
	ll diff = sum;
	for (int i = 0; i < N;++i) {
		if (abs((left + A[i]) - (right - A[i])) < diff) {
			left += A[i];
			right -= A[i];
			diff = abs(left - right);
		}
		else break;
	}
	cout << diff << endl;
}

Measured memory_bytes: 1792
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

visit_check = [0 for i in range(len(a))]

pos=0
root = []
while(1):
    if visit_check[pos]==0:
        visit_check[pos]=1
        root.append(pos)
    else:
        loop_index = root.index(pos)
        if loop_index==0:
            root_one = []
            root_loop = root
        else:
            root_one = root[:loop_index]
            root_loop = root[loop_index:]
        break
    pos = a[pos]-1

if k+1<=len(root_one):
    ans = root_one[k]+1
else:
    k = k-len(root_one)
    index = k%len(root_loop)
    ans = root_loop[index]+1
# print(root_one)
# print(root_loop)
print(ans)


Measured memory_bytes: 32296
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef short sh;
typedef unsigned short ush;
typedef unsigned int ui;

ull D,T,S;

int main() {
	cin>>D>>T>>S;
	
	if(T*S >= D){
		cout<<"Yes"<<endl;
	} else {
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
// https://atcoder.jp/contests/arc068/tasks/arc068_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    unordered_set<int> st;
    REP(i, n) {
        int t;
        cin >> t;
        st.insert(t);
    }
    int sz = st.size();
    cout << sz - (sz % 2 == 0) << endl;

    return 0;
}


Measured memory_bytes: 4388
using System;
using System.Linq;

namespace AtCoder {
	class Program {
		public static void Main() {
			int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = input[0];
			int m = input[1];
			int k = input[2];
			for (int i = 0; i <= n; i++) {
				for (int j = 0; j <= m; j++) {
					if (i * (m - j) + j * (n - i) == k) { Console.WriteLine("Yes"); return; }
				}
			}
			Console.WriteLine("No");
		}
	}
}


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

#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())

int main() {
    int n, k;
    cin >> n >> k;
    int h[n];
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        if (h[i] >= k) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,count=0; cin>>n>>m;
    vector <int> suki(m);
    for(int i=0;i<n;i++){
        int a; cin>>a;
        for(int j=0;j<a;j++){
            int b; cin>>b;
            suki[b-1]+=1;
        }
    }
    for(int i=0;i<m;i++){
       // cout<<suki[i]<<endl;
        if(suki[i]==n) count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pair<int,pii>,vector<pair<int,pii> >,greater<pair<int,pii> > >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
    fast;
    int n;cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;cin>>x;
        if(x&1)
            continue;
        if(x%3!=0 and x%5!=0)
        {
            cout<<"DENIED";
            return 0;
        }
    }
    cout<<"APPROVED";
}

Measured memory_bytes: 256
#include<stdio.h> 
int main()
{int A,B,C,D,sum,x,y;
while(~scanf("%d%d%d%d",&A,&B,&C,&D))
{
	if(B<C||D<A)
	printf("0\n");
	else {
	x=A>C?A:C;
	y=B<D?B:D;
sum=y-x;
printf("%d\n",sum);
}}
return 0;}

Measured memory_bytes: 128
# frozen_string_literal: true

K = gets.to_i

if K <= 12
  puts K
  exit 0
end

count = 9
store = [[*1..9]]
digit = 2

catch(:goto) do
  loop do
    store[digit - 1] = [] if store[digit - 1].nil?
    store[digit - 2].each do |num|
      one = num.to_s.split('').last.to_i
      next_n = [one - 1, one, one + 1].filter { |n| n >= 0 && n < 10 }
      next_n.each do |n|
        store[digit - 1] << [num, n].map(&:to_s).join.to_i
        count += 1
        throw :goto if count == K
      end
    end
    digit += 1
  end
end

puts store[digit - 1].last


Measured memory_bytes: 15148
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int a, b, q, idx;
    cin >> a >> b >> q;

    ll s[a], t[b], x;
    for (int i = 0; i < a; i++) cin >> s[i];
    for (int i = 0; i < b; i++) cin >> t[i];

    sort(s, s+a);
    sort(t, t+b);

    for (int i = 0; i < q; i++) {
        cin >> x;

        vector <ll> p, q;

        idx = lower_bound(s, s+a, x) - s;
        if (idx < a) p.push_back(s[idx]);
        if (idx > 0) p.push_back(s[idx - 1]);

        idx = lower_bound(t, t+b, x) - t;
        if (idx < b) q.push_back(t[idx]);
        if (idx > 0) q.push_back(t[idx - 1]);

        ll mn = 1LL << 60;
        for (ll v : p) {
            for (ll u : q) {
                mn = min(mn, abs(x - u) + abs(u - v));
                mn = min(mn, abs(x - v) + abs(u - v));
            }
        }

        cout << mn << "\n";
    }

    return 0;
}

Measured memory_bytes: 2944
from collections import deque

di = [-1,0,1,0]
dj = [0,-1,0,1]

H,W = map(int, input().split())
si,sj = map(int, input().split())
ti,tj = map(int, input().split())
si -= 1
sj -= 1
ti -= 1
tj -= 1
inf = 10**9
s = list()
for i in range(H):
  s.append(input())

dist = [[inf]*W for i in range(H)]
q = deque()
dist[si][sj] = 0
q.append([si,sj])

while len(q) > 0:
  tmp = q.popleft()
  i = tmp[0]
  j = tmp[1]
  d = dist[i][j]
  if dist[i][j] != d:
    continue
  for v in range(4):
    ni = i + di[v]
    nj = j + dj[v]
    if (ni < 0) or (ni >= H) or (nj < 0) or (nj >= W):
      continue
    if s[ni][nj] == "#":
      continue
    if dist[ni][nj] <= d:
      continue
    dist[ni][nj] = d
    q.appendleft([ni,nj])
  
  for ei in range(-2,3,1):
    for ej in range(-2,3,1):
      ni = i+ei
      nj = j+ej
      if (ni < 0) or (ni >= H) or (nj < 0) or (nj >= W):
        continue
      if s[ni][nj] == "#":
        continue
      if dist[ni][nj] <= d+1:
        continue
      dist[ni][nj] = d + 1
      q.append([ni,nj])
      
ans = dist[ti][tj]
if ans == inf:
  ans = -1
print(ans)


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

const int INF = 1 << 29;
const long long int Mod = 1000000007;
using ll = long long int;
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; ++i)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)



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

	int ans = 0;

	for (int a = 1; a < n; ++a) {
		for (int b = 1; a + b <= n; ++b) {
			if (a * b - n < 0) ++ans;
			else break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3196
require 'complex'

# Complex * Complex -> Double                                                                                        

def dot(c1, c2)
  (c1.conj * c2).real
end

def cross(c1, c2)
  (c1.conj * c2).imag
end

# Complex * Complex * Complex -> Complex                                                                             
# return the proj of vector p0p to vector p0p1                                                                       
def proj(p0, p1, p)
  (p1 - p0) * dot(p1 - p0, p - p0) / ((p1 - p0).abs ** 2) + p0
end

def main
  xp0, yp0, xp1, yp1 = gets.chomp.split(/\s/).collect { |x| x.to_f}
  q = gets.chomp.to_i
  (1..q).each do |ca|
    p0 = Complex(xp0, yp0)
    p1 = Complex(xp1, yp1)
    x, y = gets.chomp.split(/\s/).collect { |x| x.to_f}
    p = Complex(x, y)
    t = proj(p0, p1, p)
    puts ("%.9f" % t.real) + " " + ("%.9f" % t.imag)
  end
end

main

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

#define pb(s) push_back(s)
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))

typedef long long ll;


int main()
{
std:
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    string a,b,c;
    cin>>a>>b>>c;
    char next=a.front();
    a.erase(a.begin());
    while(a.size()!=-1&&b.size()!=-1&&c.size()!=-1){
        if(next=='a'){
            if(a.size()==0){
                cout<<'A';
                return 0;
            }
            next=a.front();
            a.erase(a.begin());
            continue;
        }
        else if(next=='b'){
            if(b.size()==0){
                cout<<'B';
                return 0;
            }
            next=b.front();
            b.erase(b.begin());
            continue;
        }
        else{
            if(c.size()==0){
                cout<<'C';
                return 0;
            }
            next=c.front();
            c.erase(c.begin());
            continue;
        }
    }
    cout<<a<<endl;
    cout<<b<<endl;
    cout<<c<<endl;


    return 0;
}


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

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

    string s, t;
    cin >> s >> t;
    if (s == t.substr(0, t.size() - 1))
        puts("Yes");
    else
        puts("No");
    return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize("3","Ofast","inline")
#include<bits/stdc++.h>
#define _ 0
using namespace std;
typedef long long ll;
template<class T>inline void read(T &x) {
    x=0;T f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-48,ch=getchar();
    x*=f;
}
int T,n;
vector<int>G[55],F[55];
inline void dfs(int u,vector<int>Edg[55],vector<int>&f) {
	for(int i=0;i<(int)Edg[u].size();++i)
		if(Edg[u][i]!=f[u])
			f[Edg[u][i]]=u,dfs(Edg[u][i],Edg,f);
}
inline int calc(int root1,int root2) {
	vector<int>fa1(n+1,0),fa2(n+1,0),added(n+1,0),deg(n+1,0);
	dfs(root1,G,fa1),dfs(root2,F,fa2);
	added[0]=1;
	if(root1==root2) {
		for(int i=1;i<=n+1;++i)
			for(int j=1;j<=n;++j)
				if(added[fa1[j]]&&fa1[j]==fa2[j])
					added[j]=1;
	}
	for(int i=1;i<=n;++i)
		deg[fa1[i]]++;
	int res=0;
	for(int i=1;i<=n;++i) {
		int nxt=-1;
		for(int j=1;j<=n&&!~nxt;++j)
			if(!deg[j]&&!added[j]&&added[fa2[j]])
				nxt=j;
		if(!~nxt)
			break;
		added[nxt]=1;
		deg[fa1[nxt]]--;
		res++;
	}
	return !*min_element(added.begin(),added.end())?1e9:res;
}
int main() {
	read(T);
	while(T--) {
		for(int i=1;i<=50;++i)
			F[i].clear(),G[i].clear();
		read(n);
		for(int i=1,x,y;i<n;++i)
			read(x),read(y),G[x].push_back(y),G[y].push_back(x);
		for(int i=1,x,y;i<n;++i)
			read(x),read(y),F[x].push_back(y),F[y].push_back(x);
		int ans=1e9;
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				ans=min(ans,calc(i,j));
		printf("%d\n",ans==1e9?-1:ans);
	}
	return ~~(0^_^0);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

const int MX=100005;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);

    int n;
    cin>> n;
    string s;
    int a=0,b=0,c=0,d=0;
    while(n--){
        cin>> s;
        if(s=="AC") a++;
        else if(s=="WA") b++;
        else if(s=="TLE") c++;
        else if(s=="RE") d++;
    }
    cout<< "AC x " << a << "\n";
    cout<< "WA x " << b << "\n";
    cout<< "TLE x " << c << "\n";
    cout<< "RE x " << d << "\n";
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int N = n;
    int s;

    while(1)
    {
        if (n/10 != 0) {
            s += n%10;
            n = n/10;
        }
        else {
            s += n;
            break;
        }
    }

    if (N%s == 0) 
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
static const int NDATA = 500000;
static const int SENTINEL = 1000000000;

int ncomparison = 0;

void trace(int data[], int n) {
  cout << data[0];
  for (int i = 1; i < n; i++) {
    cout << " " << data[i];
  }
  cout << endl;
}

int merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;  // [0, 4, 9]  n1:5
  int n2 = right - mid; // n2: 4
  int L[n1+1], R[n2+1];
  for (int i = 0; i < n1; i++)
    L[i] = A[left + i];
  for (int i = 0; i < n2; i++)
    R[i] = A[mid + i];
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;

  int i = 0, j = 0;
  for (int k = left; k < right; k++) {
      ncomparison++;
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  }
}

int mergeSort(int A[], int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int data[NDATA];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> data[i];

  mergeSort(data, 0, n);

  trace(data, n);
  cout << ncomparison << endl;
}

Measured memory_bytes: 6988
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
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;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n, x[100], y[100], ans;

signed main() {
	cin >> n;
	rep(i, n)cin >> x[i];
	rep(i, n)cin >> y[i];
	rep(i, n) {
		if (x[i] > y[i])ans += x[i] - y[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define forn(i,n) for(int i=0;i<(int) n;i++)
#define Forn(i,n) for(int i=1;i<=(int) n;i++)
   int a[25];
   int b[25];
   int c[25];
int main()
{
   int n,i;
   cin>>n;

   for(i=1;i<=n;i++) cin>>a[i];

   for(i=1;i<=n;i++) cin>>b[i];
   for(i=1;i<n;i++) cin>>c[i];
   int sum=0;
    for(i=1;i<=n;i++)
    {
        sum+=b[a[i]];
        if(i!=1 && a[i]-a[i-1]==1)
        {
            sum+=c[a[i-1]];
        }
    }
   cout<<sum;
}






Measured memory_bytes: 3592
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>

#define N 100010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define pii pair <int, int>

using namespace std;

double n, t, a;
double h, ans;

int main()
{
	cin >> n >> t >> a;
	
	double in = 0, ans = 1e9;
	for(int i = 1; i <= n; i++) {
		cin >> h;
		
		if(ans > abs(t - 0.006 * h - a))
			ans = abs(t - 0.006 * h - a), in = i;
	}
	
	cout << in;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	LL ans = -1;

	for (int i = 1; i*i <= m; i++) {

		int j = m / i;

		if (m%i == 0) {
			
			if (j >= n) {
				ans = max(ans, (LL)i);
			}

			if (i >= n) {
				ans = max(ans, (LL)j);
			}

		}

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  
    long int num[200020] = {0}, output, input, all = 0;

    scanf("%ld", &input);
    
    for(int i = 0; i < input; i++){
        scanf("%ld", &num[i]);
        all ^= num[i];
    }

    for(int i = 0; i < input; i++){
        printf("%ld", all ^ num[i]);
        if(i == input - 1){
            printf("\n");
        } else {
            printf(" ");
        }
    }


    return 0;
}

Measured memory_bytes: 4048
while True:
	n = int(input())
	if n == 0:
		break
	count = 0
	for i in range(1, int((n+1)/2)):
		s = 0
		j = i
		while s < n:
			s += j
			j += 1
			if s == n:
				count += 1
	print(count)

Measured memory_bytes: 7612
import numpy as np
s = input()
t = input()
strs = []
t_size = len(t)
for i in np.arange(len(s)-len(t)+1):
    strs.append(s[i:i+t_size])
n = 0
max_n = 0
for ss in strs:
    for i in np.arange(len(t)):
        if t[i]==ss[i]:
            n += 1
        if max_n < n:
            max_n = n
    n = 0
print(len(t)-max_n)

Measured memory_bytes: 26612
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int a,b;cin>>a>>b;
    if(a<=0 && 0<=b){
        cout<<"Zero"<<endl;
        return 0;
    }
    if(a>0){
        cout<<"Positive"<<endl;
        return 0;
    }
    if((b-a)%2==0) cout<<"Negative"<<endl;
    else cout<<"Positive"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int mod=1e9+7;
template<typename T=int>
T gi() {
	T x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
string to_string(string s) { return '"'+s+'"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b?"true":"false"); }
template<typename A,typename B> string to_string(pair<A,B> p) {
	return "("+to_string(p.fi)+","+to_string(p.se)+")";
}
template<typename T> string to_string(T v) {
	int fst=1;string ret="{";
	for(auto x:v) {
		if(!fst) ret+=",";
		fst=0,ret+=to_string(x);
	}
	ret+="}";return ret;
}
void dbg_out() { cerr<<endl; }
template<typename Head,typename... Tail> void dbg_out(Head H,Tail... T) {
	cerr<<" "<<to_string(H);
	dbg_out(T...);
}
#define dbg(...) cerr<<"{"<<#__VA_ARGS__<<"}:",dbg_out(__VA_ARGS__)

template<typename T>
int qpow(int a,T b) {
	int ret=1;
	while(b) {
		if(b&1) ret=1ll*ret*a%mod;
		a=1ll*a*a%mod,b>>=1;
	}
	return ret;
}

const int N=1e5+10;

int n,cnt[26];
char s[N];

int main() {
	n=gi();
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) ++cnt[s[i]-'a'];
	int ans=1;
	for(int i=0;i<26;i++) ans=1ll*ans*(cnt[i]+1)%mod;
	dec(ans,1);
	printf("%d\n",ans);
	return 0;
}


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

class Dice{
	public:
	int face[6];
	
	Dice(){}
	void direction(char ch){
			if(ch == 'E') rotate(0,2,5,3);
			if(ch == 'W') rotate(0,3,5,2);
			if(ch == 'S') rotate(0,1,5,4);
			if(ch == 'N') rotate(0,4,5,1);
	}

	void rotate(int a,int b,int c,int d){
		int temp[4] = {};

		temp[0] = face[a];
		temp[1] = face[b];
		temp[2] = face[c];
		temp[3] = face[d];
		//ダイス入れ替え
		face[a] = temp[3];
		face[b] = temp[0];
		face[c] = temp[1];
		face[d] = temp[2];

	}
	int sidespin(int f){
		if(f == 0 || f == 1 || f == 5) {return 0;}
		if(f == 3) rotate(1,2,4,3);
		if(f == 2) {
				for(int i = 0;i < 3;i++){
						rotate(1,2,4,3);
				}
		}
		if(f == 4) {
				for(int i = 0;i < 2;i++){
						rotate(1,2,4,3);
				}
		}
	}
};

int main(){
	Dice dice1;
	int n,top,front,t_num = 0,f_num = 0;
	
	for(int i = 0;i < 6;i++){
		cin >> dice1.face[i];
	}
		cin >> n;
	for(int i = 0;i < n;i++){
		cin >> top >> front;
		//上の面まで回転
		
		for(t_num = 0;t_num < 6;t_num++){
			if(dice1.face[t_num] == top) break;
		}
		switch(t_num){
				case 0:break;
				case 1:
					  dice1.direction('N');
					  break;
				case 4:
					  dice1.direction('S');
					  break;
				case 5:
					  dice1.direction('N');
					  dice1.direction('N');
					  break;
				case 2:
					  dice1.direction('W');
					  break;
				case 3:
					  dice1.direction('E');
					  break;
				default: break;
		}
		//前の面まで回転
		for(f_num = 0;f_num < 6;f_num++){
			if(dice1.face[f_num] == front) break;
		}
		dice1.sidespin(f_num);
		cout << dice1.face[2] << endl;
	}
	return 0;
}

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

bool isok = false;
string f(vector<bool> &isused, string start, string s, int phase){
    int i;
    if(phase >= start.length()-1) isok = true;
    if(phase < start.length()){
        i = start[phase]-'a';
    }else{
        i = 0;
    }
    string ans = "";
    for(; i < isused.size(); i++){
        if(ans != "") break;
        if(isused[i]) continue;
        isused[i] = true;
        s += (char)(i+'a');
        if(isok && s != start){
            ans = s;
            break;
        }
        ans = f(isused, start, s, phase+1);
        isused[i] = false;
        s.pop_back();
    }
    return ans;
}

int main(){
    string s;
    cin >> s;
    vector<bool> isused(26, false);
    string ans = f(isused, s, "", 0);
    if(ans == "") ans = "-1";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
    int inputN, judgeNum[81], containCount = 0, flag = 0;

    scanf("%d", &inputN);
    for (int count = 1; count < 10; count++)
    {
        for (int count2 = 1; count2 < 10; count2++)
        {
            judgeNum[containCount] = count * count2;
            containCount++;
        }
    }

    for (int index = 0; index < 81; index++)
    {
        if (inputN == judgeNum[index])
        {
            flag = 1;
            break;
        }
    }

    if (flag == 1)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    
}

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

int main(){
	int N, i, ans = 0;
	scanf("%d", &N);
	int *a = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
	}
	for(i = 1; i < N; i++){
		if(a[i] == a[i - 1]){
			a[i] = -1;
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(int i=1;i<=n;i++)
#define FORl(i,l,n) for(int i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll mod = 1e9 + 7;

ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    string matrix[h];
    int ans = 0;
    FOR0(i, h) cin >> matrix[i];
    for (int i = 0; i < (1<<(h+w)); i++){
        string tmp[h];
        FOR0(t, h) tmp[t] = matrix[t];

        for (int d = 0; d < h; d++){
            if (i&(1<<d)){
                for (int j = 0; j < w; j++) tmp[d][j] = 'R';
            }
        }

        for (int d = 0; d < w; d++){
            if (i&(1<<(d+h))){
                for (int j = 0; j < h; j++) tmp[j][d] = 'R';
            }
        }

        int cnt = 0;
        FOR0(rows, h) FOR0(cols, w) if (tmp[rows][cols] == '#') cnt++;
        if (cnt == k) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
package main

import (
  "fmt"
)

func main() {
  var A, B, K int
  fmt.Scan(&A, &B, &K)
  
  c := 0
  var max int
  if A > B {
    max = A
  } else {
    max = B
  }
  for i := 0; i < max; i++ {
    t := max - i
    if A % t == 0 && B % t == 0 {
      c++
      if c == K {
        fmt.Println(t)
        break
      }
    }
  }
}

Measured memory_bytes: 512
'use strict';

var len = 10;
var map = new Array(len);
for (var i = 0; i < map.length; ++i) {
	map[i] = new Array(len);
	for (var j = 0; j < map.length; ++j) {
		map[i][j] = 0;
	}
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var inks = input.trim().split('\n');
//var inks = ['2,5,3','3,6,1','3,4,2','4,5,2','3,6,3','2,4,1'];
for (var i in inks) {
	var ink = inks[i].trim().split(',');
	ink[0] = parseInt(ink[0]);
	ink[1] = parseInt(ink[1]);
	++map[ink[0]][ink[1]];
	switch (ink[2]) {
		case '3':
			if (ink[0] - 2 >= 0) {
				++map[ink[0] - 2][ink[1]];
			}
			if (ink[0] + 2 < len) {
				++map[ink[0] + 2][ink[1]];
			}
			if (ink[1] - 2 >= 0) {
				++map[ink[0]][ink[1] - 2];
			}
			if (ink[1] + 2 < len) {
				++map[ink[0]][ink[1] + 2];
			}
		case '2':
			if (ink[0] - 1 >= 0 && ink[1] - 1 >= 0) {
				++map[ink[0] - 1][ink[1] - 1];
			}
			if (ink[0] - 1 >= 0 && ink[1] + 1 < len) {
				++map[ink[0] - 1][ink[1] + 1];
			}
			if (ink[0] + 1 < len && ink[1] - 1 >= 0) {
				++map[ink[0] + 1][ink[1] - 1];
			}
			if (ink[0] + 1 < len && ink[1] + 1 < len) {
				++map[ink[0] + 1][ink[1] + 1];
			}
		case '1':
			if (ink[0] - 1 >= 0) {
				++map[ink[0] - 1][ink[1]];
			}
			if (ink[0] + 1 < len) {
				++map[ink[0] + 1][ink[1]];
			}
			if (ink[1] - 1 >= 0) {
				++map[ink[0]][ink[1] - 1];
			}
			if (ink[1] + 1 < len) {
				++map[ink[0]][ink[1] + 1];
			}
			break;
	}
}

var zeroden = 0;
var maxden = 0;
for (var row in map) {
	for (var col in map[row]) {
		if (map[row][col] === 0) {
			++zeroden;
		} else if (map[row][col] > maxden) {
			maxden = map[row][col];
		}
	}
}
console.log(zeroden);
console.log(maxden);

Measured memory_bytes: 15296
package main

import (
	"fmt"
)

func main() {

	var N int
	fmt.Scanf("%d", &N)

	B := make([]int, N-1)
	for i := 0; i < N-1; i++ {
		fmt.Scanf("%d", &B[i])
	}
	var sum int = 0
	var flag int = 0
	for i := 0; i < N-1; i++ {
		if flag == 0 {
			sum += B[i]
		} else {
			flag = 0
		}

		if i < N-2 && B[i] <= B[i+1] {
			sum += B[i]
			flag = 1
		}
	}

	if flag == 0 {
		sum += B[N-2]
	}

	fmt.Println(sum)
}


Measured memory_bytes: 1836
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;



int main(){
	int N;
	long long X[200000];
	long long X2[200000];

	scanf("%d", &N);

	for(int i=0;i<N;i++){
		scanf("%lld", &X[i]);
		X2[i] = X[i];
	}

	sort(X2,X2+N);

	for(int i=0;i<N;i++){
		int k = lower_bound(X2,X2+N,X[i]) - X2;
		if(k<N/2){
			printf("%lld\n", X2[N/2]);
		}else{
			printf("%lld\n", X2[N/2-1]);
		}
	}

	return 0;
}


Measured memory_bytes: 5376
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     static Map<Integer,List<Integer>> map;
     static Map<Integer,Map<Integer,Integer>> map2;
     static int[] col;
     static int[] par;
     static int N;
     static int[] as;
     static int[] bs;
     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         N=gi();
         map= new HashMap<Integer,List<Integer>>();
         map2=new HashMap<Integer, Map<Integer,Integer>>();
         col=new int[N-1];
         par =new int[N+1];
         as =new int[N];
         bs =new int[N];
         for (int i=0; i<N-1;i++) {
        	 as[i]=gi();
        	 bs[i]=gi();
        	 par[bs[i]]=as[i];
        	 if(map2.containsKey(as[i])) {
        		 map2.get(as[i]).put(bs[i], i);
        	 } else {
        	     Map<Integer, Integer> m= new HashMap<Integer,Integer>();
        	     m.put(bs[i], i);
        	     map2.put(as[i], m);
        	 }
        	 if(map.containsKey(as[i])) {
        		 map.get(as[i]).add(bs[i]);
        	 } else {
        		 List<Integer> l=new ArrayList<Integer>();
        		 l.add(bs[i]);
        		 map.put(as[i], l);
        	 }
         }
         f(1);

         StringBuilder sb=new StringBuilder();
         int max=0;
         for (int i=0; i<N-1; i++) {
        	 int c=col[i];
        	 max=Math.max(max, c);
        	 sb.append(c);
        	 sb.append(System.lineSeparator());
         }

         System.out.println(max);
         System.out.println(sb);
     }

     public static void f(int r) {
    	 List<Integer> b=map.get(r);
    	 if(b==null) return;

         int tmp=1;
         for (int i=0; i<b.size(); i++) {
        	 int v=b.get(i);

        	 int ind=map2.get(r).get(v);
        	 if(par[r]!=0 && col[map2.get(par[r]).get(r)]==tmp)tmp++;
        	 col[ind]=tmp;
        	 tmp++;
         }
         for (int i=0; i<b.size(); i++) {
        	 int v=b.get(i);
        	 f(v);
         }
     }

     public static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> implements Comparable<Pair<K, V>> {
    		/** serialVersionUID. */
    	    private static final long serialVersionUID = 6411527075103472113L;

    	    public Pair(final K key, final V value) {
    	        super(key, value);
    	    }

    		@Override
    		public int compareTo(Pair<K, V> o) {

    			Comparable key = (Comparable)this.getKey();
    			Comparable key2 = (Comparable)o.getKey();

    			return key.compareTo(key2);
    		}

    	}
     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define PER(i,n) for (int i=(N-1);i>=0;--i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    int N, M;
    cin >> N >> M;

    priority_queue<ll> que;
    REP(i, N) {
        int A;
        cin >> A;
        que.push(A);
    }

    REP(i, M){
        ll a = que.top();
        que.pop();
        a /= 2;
        que.push(a);
    }

    ll ans = 0;
    REP(i, N) {
        ans += que.top();
        que.pop();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1400
object Main{
  def main(args:Array[String]):Unit={
    var N = readInt
    var lengths = readLine.split(" ").map(x => x.toInt)
    var lengthsBySorted = lengths.sorted

    var res = 0
    for(i <- 0 until N){
      res+=scala.math.min(lengthsBySorted(2*i),lengthsBySorted(2*i+1))
    }

    println(res)
  }
}

Measured memory_bytes: 25412
n = int(input())
p = list(map(int, input().split(' ')))
ans = 0

for i in range(1, len(p) - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define M 1000000007
#define pb push_back
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
 
 
 
int dp[100001];
int a[100001];
 
 
int solve(int n)
{
    if(n==1)
        return 0;
    if(n<1)
        return 999999999999;
    if(dp[n]!=-1)
        return dp[n];
    int x,y;
    x=abs(a[n]-a[n-1])+solve(n-1);
    y=abs(a[n]-a[n-2])+solve(n-2);
    dp[n]=min(x,y);
    return dp[n];
}
signed main()
{
    boost
    //#ifndef ONLINE_JUDGE 
    //NAYAN
    //#endif
   
    int n;
    cin >> n;
   // int a[n];
    memset(dp,-1,sizeof(dp));
    int i;
    for(i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    int ans=solve(n);
    cout << ans << endl;
 
}

Measured memory_bytes: 4992
#include<algorithm>
#include<cmath>
#include<functional> //sortのgreater
#include<iostream>
#include <math.h>
#include<numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include<string> //文字列
#include<vector>

#define rep(i,n) for (int i = 0; i < n; i++)
#define REP(i,n) for(int i=1;i<=n;i++)

using namespace std;
typedef long long ll;

int main()
{
    // Input
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = 0;

    if (a >= k) {
        ans = k;
        cout << ans;
        return 0;
    }
    ans = a;
    
    if (b >= k - a) {
        cout << ans;
        return 0;
    }

    if (c >= (k - a - b)) {
        ans -= (k - a - b);
    } else {
        ans -= c;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3132
h,w = (int(x) for x in input().split())
ab = []
for _ in range(h):
    a = input()
    a = a+'#'
    ab.append(list(a))
ab.append(list('#'*w))
dp = [[100000000000000000 for a in range(w+1)] for b in range(h+1)]
if ab[0][0] == '#':
    dp[0][0] = 1
else:
    dp[0][0] = 0
step = [[0, 0]]
 
while len(step) > 0:
    y, x = step.pop(0)
    
    if h-1<y or w-1<x :continue
    
    if dp[y+1][x] == 100000000000000000:
        step.append([y+1, x])
    if dp[y][x+1] == 100000000000000000:
        step.append([y, x+1])

    if ab[y][x+1] == '#' and ab[y][x] == '.' :
        dp[y][x+1] = min(dp[y][x] + 1, dp[y][x+1])
    else:
        dp[y][x+1] = min(dp[y][x],dp[y][x+1])
    
    if ab[y+1][x] == '#' and ab[y][x] == '.' :
        dp[y+1][x] = min(dp[y][x] + 1, dp[y+1][x])
    else:
        dp[y+1][x] = min(dp[y][x], dp[y+1][x])
    
 
print(dp[h-1][w-1])

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

int main() {
    long long int a;
    long long int b;
    scanf("%lf %lf", &a, &b);

    if(a < b) cout << "LESS" << endl;
    else if(a == b) cout << "EQUAL" << endl;
    else cout << "GREATER" << endl;
    
    return 0;
}

Measured memory_bytes: 384