akhauriyash/Code-Regression huggingface dataset:
# Acceptance of input

import sys

file_input = sys.stdin

V, E = map(int, file_input.readline().split())

adj_mat = [[0] * V for i in range(V)]

for line in file_input:
    u, v, c = map(int, line.split())
    adj_mat[u][v] = c

# Ford???Fulkerson algorithm

import collections

# BFS for residual capacity network
def bfs(start, goal, parent):
    unvisited = [True] * V
    queue = collections.deque()
    queue.append(start)
    unvisited[start] = False
    while queue:
        u = queue.popleft()
        for v, flow in enumerate(adj_mat[u]):
            if unvisited[v] and (flow > 0):
                queue.append(v)
                unvisited[v] = False
                parent[v] = u
                if v == goal:
                    return True

def ford_fulkerson(source, sink):
    parent = [None] * V
    max_flow = 0
    while bfs(source, sink, parent):
        aug_path_flow = 10000
        v = sink
        while (v != source):
            aug_path_flow = min(aug_path_flow, adj_mat[parent[v]][v])
            v = parent[v]
        max_flow += aug_path_flow
        v = sink
        while (v != source):
            u = parent[v]
            adj_mat[u][v] -= aug_path_flow
            adj_mat[v][u] += aug_path_flow
            v = u
    return max_flow

# output
print(ford_fulkerson(0, V - 1))

Measured memory_bytes: 8164
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>=1;
    }
    return res;
}



int main(){
    ll n;
    cin >> n;
    string s="";
    while(n>0){
        n--;
        char r = n%26;
        s = (char)(r+97) + s;
        n = n/26;
    }
    cout << s << endl;
}




Measured memory_bytes: 3616
using System;
using System.Linq;
using System.Collections.Generic;

namespace cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var pg = new Program();
            pg.Execute();

        }

        private void Execute()
        {
            var input = ReadLinesLongList;
            var N = input.ElementAt(0);
            var M = input.ElementAt(1);
            var input2 = ReadLinesLongList;
            var res = input2.Sum() > N ? -1 : N - input2.Sum();
        
            OutputResult(res);
        }

        private void OutputResult<Type>(Type result)
        {
            Console.WriteLine(result);
        }

        static long ReadLineLong => long.Parse(Console.ReadLine());
        static string ReadLineString => Console.ReadLine();
        static IEnumerable<long> ReadLinesLongList => Console.ReadLine().Split(' ').Select(i => long.Parse(i));
        static IEnumerable<string> ReadLinesStringList => Console.ReadLine().Split(' ');

        public static int Gcd(int a, int b) {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }

    }
}


Measured memory_bytes: 29232
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readTuple4 :: IO (Int, Int, Int, Int)
readTuple4 = do
    [a, b, c, d] <- readInts
    return (a, b, c, d)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

main = do
    (a, b, c, k) <- readTuple4
    print $ if k <= (a + b) then min a k
        else a - (min c $ (k - a - b))


Measured memory_bytes: 3740
#include <stdio.h>

int main()
{
	int u, v, w, N, dist[301][301] = {};
	scanf("%d", &N);
	for (u = 1; u <= N; u++) {
		for (w = 1; w <= N; w++) scanf("%d", &(dist[u][w]));
	}
	for (v = 1; v <= N; v++) {
		for (u = 1; u < N; u++) {
			for (w = u + 1; w <= N; w++) {
				if (dist[u][v] + dist[v][w] < dist[u][w]) break;
			}
			if (w <= N) break;
		}
		if (u < N) break;
	}
	if (v <= N) {
		printf("-1\n");
		fflush(stdout);
		return 0;
	}
	
	long long ans = 0;
	for (u = 1; u < N; u++) {
		for (w = u + 1; w <= N; w++) {
			for (v = 1; v <= N; v++) if (dist[u][v] + dist[v][w] == dist[u][w] && v != u && v != w) break;
			if (v > N) ans += dist[u][w];
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 512
package main
 
import "fmt"
 
func ExchangeNumber(x, y ,z int) (int, int, int) {
	tmp := x
	x = y
	y = tmp
	tmp = x
	x = z
	z = tmp
	return x, y, z
}
 
func main()  {
	var x, y, z int
	fmt.Scan(&x, &y, &z)
	fmt.Println(ExchangeNumber(x, y, z))
}


Measured memory_bytes: 512
#include<stdio.h>
#define ll long long
ll gcd(ll m, ll n)
{
    return (m==0)?n:gcd(n%m, m);
}
int main()
{
    int n,i;
    ll a,b;
    while(~scanf("%d",&n))
    {
        scanf("%lld",&a);
        for(i=1;i<n;i++)
        {
            scanf("%lld",&b);
            b/=gcd(a,b);
            a*=b;
        }
        printf("%lld\n",a);
    }
    return 0;
}


Measured memory_bytes: 128
from collections import deque

n, m, x = map(int,input().split())
books = []
costs = []

for i in range(n):
    book = list(map(int,input().split()))
    books.append(book[1:len(book)])
    costs.append(book[0])

know = [0 for i in range(m)]
money = 0
perf = 1000000000000000000000000
book_id = 0

q = deque([])
q.append([book_id,know,money])

while len(q) != 0:
    book_id, know, money = q.pop()
    know_buy = [x+y for x,y in zip(know, books[book_id])]
    money_buy = money + costs[book_id]
    temp = 0
    for i in range(m):
        if know_buy[i] >= x:
            temp += 1
    if temp == m and perf > money_buy:
        perf = money_buy
    elif temp != m and money_buy < perf and book_id+1 != n:
        q.append([book_id+1, know_buy, money_buy])
    if book_id+1 != n:
        q.append([book_id+1, know, money])

if perf != 1000000000000000000000000:
    print(perf)
else:
    print(-1)


Measured memory_bytes: 9440
a = int(input())

if 400<=a and a<=599:
    print('8')
elif 600<=a and a<=799:
    print('7')
elif 800<=a and a<=999:
    print('6')
elif 1000<=a and a<=1199:
    print('5')
elif 1200<=a and a<=1399:
    print('4')
elif 1400<=a and a<=1599:
    print('3')
elif 1600<=a and a<=1799:
    print('2')
elif 1800<=a and a<=1999:
    print('1')

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

int main() {
  	long long goal_money;
  	cin >> goal_money;
  
  	long long P = 100, step = 0;
  	while(P < goal_money)
    {
    	P += P / 100;
      	step++;

    }
	cout << step << endl;
  	return 0;

}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

signed
main(){
		string L;
		cin >> L;
		ll len = L.size();

		//j=0: その時点でL以下が確定
		//j=1: その時点でL以下かわからない
		vector<vector<ll> > dp(len+2, vector<ll>(2, 0));
		dp[1][0] = 1;
		dp[1][1] = 2;

		for(ll i=1;i<len;i++)
		{
				if(L[i]=='1')
				{
						dp[i+1][0] = dp[i][0]*3 + dp[i][1];
						dp[i+1][1] = dp[i][1]*2;
				}else
				{
						dp[i+1][0] = dp[i][0]*3;
						dp[i+1][1] = dp[i][1];
				}
				dp[i+1][1] %= MOD;
				dp[i+1][0] %= MOD;
		}
		cout << (dp[len][0]+dp[len][1])%MOD << endl;
}

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

int main() {
    int N;
    cin >> N;
    ll ans = 0;
    map<ll, int> num;
    rep(i, N) {
        ll a;
        cin >> a;
        if (num.count(a)) {
            num[a]++;
        }
        else {
            num[a] = 1;
        }
    }
    for (auto p : num) {
        ll key = p.first;
        int count = p.second;
        if (key < count) {
            ans += count-key;
        }
        else if (count < key) {
            ans += count;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6272
import math
min = math.inf
S = input()
T = input()

len_t = len(T)
for s in range(0,len(S)-len_t+1):
    sub = S[s: s+len_t]
    diff = 0
    for i in range(len_t):
        if sub[i] != T[i]:
            diff += 1
            if diff > min:
                break
    else:
        if diff < min:
            min = diff
print(min)

Measured memory_bytes: 9056
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
monsters=sum(a)

for i in range(n):
    if a[i]>=b[i]:
        a[i]-=b[i]
    else:
        b[i]-=a[i]
        a[i]=0
        a[i+1]=max(0,a[i+1]-b[i])

print(monsters-sum(a))

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

int main(){
    int n=0;
    cin>>n;
    
    vector<int>a(n);
    
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }

    int b=0;
    for(int i=0;i<n;i+=2){
        if(a.at(i)%2==1){
            b++;
        }
    }

    cout<<b<<endl;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
using LL = long long;
using PII = pair<int, int>;
#define F first
#define S second

int n;
LL a[300010], s;

int main() {
  scanf("%d", &n);
  REP(i, n * 3) scanf("%lld", &a[i]);
  sort(a, a + n * 3);
  int k = n * 3 - 2;
  REP(i, n) {
    s += a[k];
    k -= 2;
  }
  printf("%lld\n", s);
  return 0;
}



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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

long long h[100010][3];

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    rep(i,N){
      rep(j,3){
        cin >> h[i][j];
      }
    }

    rep(i,100010)rep(j,3){
      dp[i][j]=0;
    }

    // ループ
    for(int i=0; i<N; i++){
        chmax(dp[i+1][0],dp[i][1]+h[i][0]);
        chmax(dp[i+1][0],dp[i][2]+h[i][0]);
        chmax(dp[i+1][1],dp[i][0]+h[i][1]);
        chmax(dp[i+1][1],dp[i][2]+h[i][1]);
        chmax(dp[i+1][2],dp[i][0]+h[i][2]);
        chmax(dp[i+1][2],dp[i][1]+h[i][2]);
    }
    // 答え
    cout<<max({dp[N][0],dp[N][1],dp[N][2]})<<endl;
}

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

typedef long long ll;
#define fore(i,ii,iii) for(int i=ii;i<iii;i++)
#define mset(a,b) memset(a,b,sizeof(a))

const ll N=405,INF=1e15;
ll n,dp[N][N],sp[N];

ll solve(int l,int r) {
  if(dp[l][r]!=-1)return dp[l][r];
  ll res=INF*(l!=r);
  fore(m,l,r)res=min(res,sp[r]-sp[l-1]+solve(l,m)+solve(m+1,r));
  return dp[l][r]=res;
}

int main() {
  ios::sync_with_stdio(false);
  mset(dp,-1);
  cin>>n;
  fore(i,1,n+1)cin>>sp[i],sp[i]+=sp[i-1];
  cout<<solve(1,n)<<endl;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int N,T;
 
vector< P > t;
 
int main(){
  cin>>N>>T;
  for(int i=0;i<N;i++){
    int l,r;
    cin>>l>>r;
    t.push_back( P(l,1) );
    t.push_back( P(r,-1) );
  }
  sort(t.begin(),t.end());
  int sum=0;
  int ans=0;
  for(int i=0;i<N+N;i++){
    sum+=t[i].second;
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4840
def factorization(n):
    L=[]
    temp=n
    print(n,end='')
    print(':',end='')
    for i in range(2,int(n**(1/2)//1)+1):
        if temp%i==0:
            c=0
            while temp%i==0:
                c+=1
                temp//=i
            L.append([i,c])
            for j in range(c):
                print('',i,end='')
                
    if temp!=1:
        print('',temp,end='')
    print()
        
n=int(input())
factorization(n)


Measured memory_bytes: 5628
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = list(input())
k = inp()
n = len(s)
nxa = ord('z') + 1

for i,x in enumerate(s):
    if x == 'a':
        continue
    rem = nxa - ord(x)
    if rem <= k:
        s[i] = 'a'
        k -= rem
if k > 0:
    s[-1] = chr(ord('a') + (ord(s[-1])-ord('a')+k)%26)
print(''.join(s))

Measured memory_bytes: 11292
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(),l.end(),greater<int>());
    int cnt=0;
    for(int i=0;i<n-2;i++){
        int a = l[i];
        for (int j = i+1;j<n-1;j++){
            int b = l[j];
            for(int k =j+1 ; k<n;k++){
                int c = l[k];

                if(a<b+c) cnt++;
            }
        }
    }
    cout << cnt <<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int w1 = sc.nextInt();
    int d1 = sc.nextInt();
    int w2 = sc.nextInt();
    int d2 = sc.nextInt();
    int ans = 0;
    
    if(w1!=w2){
      ans = 1;
    }

    System.out.println(ans);
    
  }
}

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

int main() {
  int a;
  int b, c, d, e;
  cin >> a;
  b = int(a / 1000);
  c = int((a % 1000) / 100);
  d = int((a % 100) / 10);
  e = a % 10;
  if (((b == c) and (c == d)) or ((c == d) and (d == e))){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
  


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int a[105];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int vote=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        vote+=a[i];
    }
    sort(a,a+n,greater<int>());
    if(a[m-1]*(4*m)>=vote)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 888
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << "[" << pa.first << ", " << pa.second << "]";
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  os << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "}";
  return os;
}

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

//非再帰累乗(mod付き)
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }

  ll x = 1;

  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

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

  ll n,a,b,c,d;
  std::cin>>n>>a>>b>>c>>d;

  std::vector<ll> facto(1010,1),factoinv(1010,1);
  rep(i,1,1010)facto[i]=(facto[i-1]*i)%MOD;
  rep(i,0,1010)factoinv[i]=pow_mod(facto[i],MOD-2,MOD);

  std::vector<std::vector<ll>> dp(b+2,std::vector<ll>(n+1,0));

  dp[a-1][0]=1;

  rep(i,a,b+1){
    rep(j,0,n+1){
      ll sum=dp[i-1][j];
      ll mul=pow_mod(facto[i],c,MOD);
      mul=pow_mod(mul,MOD-2,MOD);
      mul=(mul*facto[n-j+i*c])%MOD;
      mul=(mul*factoinv[n-j])%MOD;
      mul=(mul*factoinv[c])%MOD;
      rep(k,c,std::min(j/i+1,d+1)){
        sum=(sum+(dp[i-1][j-k*i]*mul)%MOD)%MOD;
        if(k+1<std::min(j/i+1,d+1)){
          mul=(mul*facto[n-j+i*k+i])%MOD;
          mul=(mul*factoinv[n-j+i*k])%MOD;
          mul=(mul*factoinv[i])%MOD;
          mul=(mul*facto[k])%MOD;
          mul=(mul*factoinv[k+1])%MOD;
        }
      }
      dp[i][j]=sum;
    }
  }

  std::cout<<dp[b][n];

  return 0;
}






Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int n; cin >> n;
    vector<ll> a(3*n);
    rep(i,3*n) cin >> a[i];
    priority_queue<ll, vector<ll>, greater<ll>> que_left; //最小値を出すために，逆順で持たせる
    priority_queue<ll> que_right;
    ll sum_left = 0, sum_right = 0, ans = -LINF;
    vector<ll> left(n+1,0), right(n+1,0);
    rep(i,n) {
        que_left.push(a[i]);
        sum_left += a[i];
    }
    left[0] = sum_left;
    rep(i,n) {
        que_right.push(a[3*n-1-i]);
        sum_right += a[3*n-1-i];
    }
    right[n] = sum_right;

    for (int k=n; k<2*n; k++) {
        if (que_left.top() < a[k]) { //もともとの最小値より次に見る要素が大きい場合
            sum_left += a[k] - que_left.top();
            que_left.pop();
            que_left.push(a[k]);
        }
        if (que_right.top() > a[3*n-1-k]) {
            sum_right += a[3*n-1-k] - que_right.top();
            que_right.pop();
            que_right.push(a[3*n-1-k]);
        }
        left[k-n+1] = sum_left;
        right[2*n-k-1] = sum_right;
    }

    rep(i,n+1) {
        chmax(ans, left[i]-right[i]);
    }

    cout << ans << endl;
}

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

int main(){
	string s,p="";
	int position = 0;
	int temp_i = 0;
	string output = "No";
	cin >> s;
	cin >> p;

	for(int i=0; i<s.length(); i++){
		if(s[i] == p[0]){
			output = "Yes";
			temp_i = i+1;
			for(int ip=1; ip<p.length(); ip++){
				position = temp_i% s.length();
				if(s[position] != p[ip] ){
					output = "No";
					break;
				}
				++temp_i;
			}	
		}
		if(output == "Yes")
			break;
	}
	cout << output << endl;
 return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

Vec v, w;
VecB fin;
Vec2<ll> dp;

ll f(ll m, ll l){
	// co({m, l});
	if (l < 0) return -LINF;
	if (m >= 512) return max(f(m / 2, l), f(m / 2, l - w[m]) + v[m]);
	if (!fin[m / 2]) f(m / 2, l);
	if(!fin[m]){
		rep(i, 100005) dp[m][i] = dp[m / 2][i];
		rep(i, 100005) if(i - w[m] >= 0) chmax(dp[m][i], dp[m / 2][i - w[m]] + v[m]);
		fin[m] = true;
	}
	return dp[m][l];
}

int main(void){
	ll n;
	cin >> n;
	v.resize(n + 1);
	w.resize(n + 1);
	repn(i, n) cin >> v[i] >> w[i];

	fin.assign(1024, false);
	fin[0] = true;
	dp.resize(1024);
	rep(i, 1024) dp[i].assign(100005, 0);

	ll q;
	cin >> q;
	rep(i, q){
		ll m, l;
		cin >> m >> l;
		co(f(m, l));
	}

	return 0;
}


Measured memory_bytes: 810252
#include<iostream>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if(a+b == c || c+a == b || b+c == a) {
    cout << "Yes" << endl;
  }else {
    cout << "No" <<  endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<atcoder/all>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int n,m; cin >>n >>m;
  vector<string> ground(n); for(string& x:ground) cin >>x;
  int s=n*m;
  atcoder::mf_graph<int> graph(s+2);

  rep(i,n) rep(j,m){
    int a=i*m+j;
    if((i+j)%2==0){
      graph.add_edge(s,a,1);
      if(df)print(s,a);
    }
    else{
      graph.add_edge(a,s+1,1);
      if(df)print(a,s+1);
    }
  }
  rep(i,n) rep(j,m){
    if(ground[i][j]=='#') continue;
    if(j+1<m and ground[i][j+1]=='.'){
      int a=i*m+j,b=i*m+j+1;
      if((i+j)%2) swap(a,b);
      graph.add_edge(a,b,1);
      if(df)print(a,b);
    }
    if(i+1<n and ground[i+1][j]=='.'){
      int a=i*m+j,b=(i+1)*m+j;
      if((i+j)%2) swap(a,b);
      graph.add_edge(a,b,1);
      if(df)print(a,b);
    }
  }
  int f=graph.flow(s,s+1);
  print(f);
  vector<atcoder::mf_graph<int>::edge> edges=graph.edges();
  for(auto e:edges){
    if(e.flow==0) continue;
    if(e.from==s or e.to==s+1) continue;
    int a=e.from,b=e.to;
    if(a>b) swap(a,b);
    if(b%m-a%m==1){
      ground[a/m][a%m]='>';
      ground[b/m][b%m]='<';
    }else{
      ground[a/m][a%m]='v';
      ground[b/m][b%m]='^';
    }
  }
  rep(i,n) print(ground[i]);
}


Measured memory_bytes: 5528
#include <stdio.h>
int search(int A[],int key, int n){
  int i=0;
  A[n] = key;
  while(A[i]!=key) i++;
  return i !=n;
}

int main(){
  int n,q;
  int S[10000],T[500],i,j,count=0,key;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    count += search(S,key,n);
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2104
import numpy as np
N = int(input())
A = list(map(int, input().split()))
C = [1 if i == 0 or i == N-1 else 0 for i in range(N)]
A = np.fft.fft(A)
C = np.fft.fft(C)
print(" ".join(map(lambda x:str(int(round(x.real))), 2*np.fft.ifft(A/C))))

Measured memory_bytes: 26992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

pair<int, int> operator+(const pair<int, int>& x, const pair<int, int>& y) {
    return make_pair(x.first+y.first, x.second+y.second);
}
pair<int, int> plusHW(const pair<int, int>& x, const pair<int, int>& y, const int H, const int W) {
    return make_pair(min(max(1, x.first+y.first), H), min(max(1,x.second+y.second), W));
}

int main() {
    int H, W;
    cin >> H >> W;
    int Ch, Cw;
    cin >> Ch >> Cw;
    int Dh, Dw;
    cin >> Dh >> Dw;
    vector<vector<string>> S(H+1, vector<string>(W+1));
    vector<vector<bool>> wallOrVisited(H+1, vector<bool>(W+1));
    for (int h = 1; h <= H; ++h) {
        string str;
        cin >> str;
        for (int w = 1; w <= W; ++w) {
            S[h][w] = str[w-1];
            wallOrVisited[h][w] = (S[h][w] == "#");
        } 
    }
    vector<vector<int>> A(H+1, vector<int>(W+1, -1));
    queue<pair<int, int>> I;
    queue<pair<int, int>> R;
    vector<pair<int, int>> oneStep{{1,0}, {-1,0}, {0,1}, {0,-1}};
    vector<pair<int, int>> jump;
    for (int i = -2; i <= 2; ++i) {
        for (int j = -2; j <= 2; ++j) {
            jump.push_back(make_pair(i, j));
        }
    }
    jump.erase(find(jump.begin(), jump.end(), make_pair(0,0)));
    for (auto x : oneStep) {
        jump.erase(find(jump.begin(), jump.end(), x));
    }


    wallOrVisited[Ch][Cw] = true;
    I.push(make_pair(Ch, Cw));
    int stage = 0;
    while(!I.empty()) {
        while (!I.empty()) 
        {
            auto x = I.front();
            I.pop();
            R.push(x);
            for (auto d : oneStep) {
                auto y = plusHW(x, d, H, W);
                if (!wallOrVisited[y.first][y.second]) {
                    A[y.first][y.second] = stage;
                    I.push(y); wallOrVisited[y.first][y.second] = true;
                }
            }
        }
        ++stage;
        while(!R.empty()) {
            auto r = R.front();
            R.pop();
            for (auto d : jump) {
                auto x = plusHW(r, d, H, W);
                if (!wallOrVisited[x.first][x.second]) {
                    A[x.first][x.second] = stage;
                    I.push(x);
                    wallOrVisited[x.first][x.second] = true;
                }
            }
        }
    }
    cout << A[Dh][Dw] << endl;

   
}

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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

int main()
{
    //Fast_IO();
    ll a; cin >> a;
    ll ans = a;
    ans += a * a;
    ans += a * a * a;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;


int main(){
    int n,m;
    cin >> n;
    map<string, int> u;
    rep(i, n){
        string a;
        cin >> a;
        u[a]=1;
    }
    cin >> m;
    bool open=false;
    rep(i, m){
        string a;
        cin >> a;
        if (u[a]==1) {
            if (open) {
                open = false;
                cout << "Closed by "<<a<<endl;
            }else{
                open = true;
                cout << "Opened by "<<a<<endl;
            }
            continue;
        }else{
            cout << "Unknown "<<a<<endl;
        }
    }
}

Measured memory_bytes: 1244
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    set<string>s;for(ll i=in();i;--i)s.insert(in<string>());cout<<s.size()<<endl;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }


const string YES = "YES";
const string NO = "NO";

void func(long long A, long long V, long long B, long long W, long long T){

    if(W>=V){
        cout<<NO<<endl;
        return;
    }

    lli diff = V-W;
    lli length = abs(A-B);

    if(length/diff < T){
        cout<<YES<<endl;
    }
    else if(length/diff == T && (length%diff==0)){
        cout<<YES<<endl;
    }
    else{
        cout<<NO<<endl;
    }

}

int main(){
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld",&A);
    long long V;
    scanf("%lld",&V);
    long long B;
    scanf("%lld",&B);
    long long W;
    scanf("%lld",&W);
    long long T;
    scanf("%lld",&T);
    func(A, V, B, W, T);
    return 0;
}


Measured memory_bytes: 3768
program name
    implicit none
    integer(4):: n,m,i
    integer(4),allocatable:: a(:)
    read*, n,m
    allocate(a(n))
    read*, a(:)

    call merge_sort(a,1,n)

    do i=1,m
        if (dble(a(i)) < dble(sum(a))/dble(4*m)) then
            print*, 'No'
            stop
        end if
    end do

    print*, 'Yes'
contains
    recursive subroutine merge_sort(ar, fst, lst)
    integer(4),intent(inout):: ar(:)
    integer(4),intent(in):: fst,lst
    integer(4):: mdl

    if (lst-fst < 2) then
        if (ar(fst) < ar(lst)) call swap(ar(fst),ar(lst))
        return
    end if

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

subroutine merge_(ar, fst, mdl, lst)
    integer(4),intent(inout):: ar(:)
    integer(4),intent(in):: fst, mdl, lst
    integer(4),allocatable:: tmp(:)
    integer(4):: li, ri, ti

    allocate(tmp(lst-fst+1))

    li=fst
    ri=mdl+1   
    ti=1

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

    if (li <= mdl) then
        tmp(ti:) = ar(li:mdl)
    else
        tmp(ti:) = ar(ri:lst)
    end if

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

subroutine swap(x,y)
    integer(4),intent(inout):: x,y
    integer(4):: tmp
    tmp = x
    x = y
    y = tmp
end subroutine
end program name

Measured memory_bytes: 768
n, m = map(int, input().split())
ks = [[int(i) for i in input().split()][1:] for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for i in range(2 ** n):
    for j in range(m):
        cnt = 0
        for k in range(n):
            if i >> k & 1 and k + 1 in ks[j]:
                cnt += 1
        if cnt % 2 != p[j]:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 9204
#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }
int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }

vector<int> get_bits(int mask) {
	vector<int> bb;
	while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }
	reverse(all(bb));
	return bb;
}

int get_mask(vector<int> v) {
	int mask = 0;
	for(int x : v) { mask ^= (1 << x); }
	return mask;
}

template<typename T>
void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

void sc() {}

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// #ifndef LOCAL
// string to_string(__int128 x) {
// 	string s = "";
// 	bool neg = 0;
// 	if(x < 0) { s += "-"; neg = 1; x = -x; }
// 	if(!x) s += '0';
// 	while(x) {
// 		int rem = x % 10;
// 		s += to_string(rem);
// 		x /= 10;
// 	}
// 	reverse(s.begin() + neg, s.end());
// 	return s;
// }
// #endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,ll b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
	Read problem statement carefully!!!
*/

const int N = 2e4 + 5;
int p[N], a[N], b[N];

void solve() {
	int n;
    sc(n);
    fr(i, 1, n) {
        sc(p[i]);
    }
    int B = n + 5;
    fr(i, 1, n) {
        a[i] = i * B;
        b[i] = (n - i + 1) * B;
    }
    fr(i, 2, n) {
        if(p[i] > p[i - 1]) {
            a[p[i]] += i - 1;
        }
        else {
            b[p[i]] += i - 1;
        }
    }
    fr(i, 1, n) {
        cout << a[i] << " ";
    }
    cout << endl;
    fr(i, 1, n) {
        cout << b[i] << " ";
    }
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3920
M = 1000000007
n = int(input())
a = list(map(int,input().split()))
S = [0]
for i in range(n):
 S.append((S[-1]+a[i])%M)
sum = 0
for i in range(n-1):
 sum += (a[i]*(S[n]-S[i+1]))%M
print(sum%M)

Measured memory_bytes: 31536
using System;
using System.Globalization;
using System.IO.Pipes;
using System.Runtime.InteropServices;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            double A, B;
            A = double.Parse(str[0]);
            B = double.Parse(str[1]);
            Console.WriteLine(A / B);

        }

    }
}


Measured memory_bytes: 27572
fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line);
    let v: Vec<i64> = line.split_whitespace().map(|a|a.parse().unwrap()).collect();
    let (k, x) = (v[0], v[1]);
    let mut first = true;
    for c in -1000000i64..1000001i64 {
        if (c - x).abs() <= k - 1 {
            if !first {
                print!(" ");
            }
            first = false;
            print!("{}", c);
        }
    }
}


Measured memory_bytes: 4476
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <cmath>
#include <string>

using namespace std;

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

#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define ins insert
#define iter ::iterator
#define upb upper_bound
#define lwb lower_bound

#define sz(v) v.size()
#define aloc(i, a, n) i *a = new i[n]

#define for0(i,a) for(ll i = 0; i < a; i++)
#define fori(i,a,b) for(ll i = a; i < b; ++i)
#define rfor0(i,a) for(ll i = a; i >= 0; --i)
#define rfor(i,a,b) for(ll i = a; i >= b; --i)
//##############################################################################

int main(){
	
	int N;
	cin >> N;
	aloc(int, A, N);
	aloc(int, B, N);
	aloc(int, C, N - 1);
	
	for0(i, N) cin >> A[i];
	for0(i, N) cin >> B[i];
	for0(i, N - 1) cin >> C[i];

	int dice = -1;
	ll result = 0;

	for0(i, N){

		if(A[i] - 1 == dice) result += C[A[i-1]-1];
		result += B[A[i]-1];
		dice = A[i];
		//cout << result << endl;
	}
	cout << result << endl;

 return 0;
}


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

int main() {
    int k;
    cin >> k;
    vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << vec[k-1] << endl;
    return 0;
}


Measured memory_bytes: 3572
#include<stdio.h>

int A[500001];
int H;

void buildMaxHeap();
void maxHeapify(int*, int);

int main(){

int n,i;
  
  scanf("%d",&H);

  for(i=1; i<=H; i++)
    scanf("%d",&A[i]);
  
  buildMaxHeap();
    
  for(i=1; i<=H; i++)
    printf(" %d",A[i]);

  printf("\n");

  return 0;
}

void buildMaxHeap(){
  int i;
  for(i=H/2; i>=1; i--)
    maxHeapify(A, i);
}

void maxHeapify(int *A, int i){
  int l,r,N,largest;
  
  l = 2*i;
  r = 2*i+1;
  
  if((l <= H) && (A[l] > A[i]))
    largest = l;
  else
    largest = i;

  if(r <= H && A[r] > A[largest])
    largest = r;  

  if(largest != i){
    N = A[i];
    A[i] = A[largest];
    A[largest] = N;  
    maxHeapify(A,largest);
  }
}

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

using namespace std;

vector<int> edge[3050];

int A[3050];
bool flg[3050];

void chk(int pos)
{
	flg[pos] = 0;
	for(auto v : edge[pos])
		if(A[v] < A[pos])
		{
			chk(v);
			if(!flg[v])
			{
				flg[pos] = 1;
				return ;
			}
		}
}

int main()
{
	int n; scanf("%d",&n);
	for(int i = 1;i <= n; ++ i) scanf("%d",&A[i]);
	for(int i = 1;i < n; ++ i)
	{
		int u,v; scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	for(int i = 1;i <= n; ++ i)
	{
		chk(i);
		if(flg[i]) printf("%d ",i);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 4e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

void bad()
{
    cout << "Impossible";
    exit(0);
}
void good()
{
    cout << "Possible";
    exit(0);
}

signed main()
{
    Start();
    // There should be test:
    // 7
    // 6 6 3 4 5 5 5
    int n;
    cin >> n;
    vector <int> a(n);
    cin >> a;
    sort(all(a));
    if (a[n - 1] != a[n - 2])
        bad();
    if (a[0] != (a[n - 1] + 1) / 2)
        bad();
    if (a[n - 1] % 2 == 0)
    {
        if (a[0] == a[1])
            bad();
    }
    else
    {
        if (n > 2 && a[0] == a[1] && a[1] == a[2])
            bad();
    }
    set <int> s;
    for (auto &i : a)
        s.emplace(i);
    for (int i = a[0]; i < a[n - 1]; ++i)
        if (!s.count(i))
            bad();
    good();
    return 0;
}



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

typedef pair<int, int> pr;

#define N 10005

int n;

vector<pr> to[N];

array<int, N> ans;
array<int, N> dis1;
array<int, N> pre1;
array<int, N> dis2;
array<int, N> pre2;

void dfs1(int u, int f)
{
	dis1[u] = dis2[u] = 0;
	
	for (auto e : to[u])
	{
		int v = e.first;
		int w = e.second;
		
		if (v == f)
			continue;
			
		dfs1(v, u);
		
		int tmp = dis1[v] + w;
		
		if (tmp >= dis1[u])
		{
			dis2[u] = dis1[u];
			pre2[u] = pre1[u];
			dis1[u] = tmp;
			pre1[u] = v;
		}
		else if (tmp >= dis2[u])
		{
			dis2[u] = tmp;
			pre2[u] = v;
		}
	}
}

void dfs2(int u, int f, int d)
{
	ans[u] = max(dis1[u], d);
	
	for (auto e : to[u])
	{
		int v = e.first;
		int w = e.second;
		
		if (v == f)
			continue;
		
		if (v == pre1[u])
			dfs2(v, u, max(d, dis2[u]) + w);
		else
			dfs2(v, u, max(d, dis1[u]) + w);
	}
}

signed main(void)
{
	cin >> n;
	
	for (int i = 1; i < n; ++i)
	{
		int x, y, w; 
		cin >> x >> y >> w;
		to[x].push_back(make_pair(y, w));
		to[y].push_back(make_pair(x, w));
	}
	
	memset(begin(pre1), -1, sizeof(pre1));
	memset(begin(pre2), -1, sizeof(pre2));
	
	dfs1(0, -1);
	dfs2(0, -1, 0);
	
	for (int i = 0; i < n; ++i)
		cout << ans[i] << endl;
}

Measured memory_bytes: 4620
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
ll a[20];
ll r,d;

int main()
{
    cin>>r>>d>>a[0];
    for (int i=1; i<=10; ++i)
    {
        a[i] = a[i-1]*r-d;
        cout<<a[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n;
	scanf("%d", &n);

	if (n == 25){
		printf("Christmas");
	}
	else if (n == 24){
		printf("Christmas Eve");
	}
	else if (n == 23){
		printf("Christmas Eve Eve");
	}
	else if (n == 22){
		printf("Christmas Eve Eve Eve");
	}
	return 0;

}

Measured memory_bytes: 128
import sys

n=int(input())
alst=list(map(int,sys.stdin.readline().strip().split()))

cumsum=[[0]*(n+1) for i in range(60)]

md=10**9+7

for i in range(1,n+1):
    a=alst[i-1]
    dig=0
    while dig<60:
        bit=a%2
        cumsum[dig][i]=cumsum[dig][i-1]+bit
        dig+=1
        a//=2

ans=0
ceff=1

for d in range(60):
    ret=0
    for i in range(1,n):
        ret+=(cumsum[d][i]-cumsum[d][i-1])*(n-i-cumsum[d][n]+cumsum[d][i])
        ret+=(1-cumsum[d][i]+cumsum[d][i-1])*(cumsum[d][n]-cumsum[d][i])
    ans=(ans+ceff*ret)%md
    ceff=(2*ceff)%md

print(ans)



Measured memory_bytes: 193240
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip("\n") for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst): print(*lst)
def OutV(lst): print(*lst, sep="\n")
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

S = input()
T = input()

cnt = 0
for i in range(len(S)):
    if S[i] != T[i]:
        cnt += 1

print(cnt)


Measured memory_bytes: 67584
//
// Created by tac on 2016/10/27.
//

#include <cstdlib>
#include <algorithm>
#include <functional>
#include <vector>
#include <iostream>

const int N_SIZE = 10000;

int main() {
    std::vector<int> v(N_SIZE);
    int n = 10;
    int s;
    for (int i = 0; i < n; ++i) {
        std::cin >> s;
        v.push_back(s);
    }
    std::sort(v.begin(), v.end(), std::greater<int>());
    for (int j = 0; j < 3; ++j) {
        std::cout << v[j] << std::endl;
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3220