akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ga = sc.nextInt();
        int sa = sc.nextInt();
        int ba = sc.nextInt();
        int gb = sc.nextInt();
        int sb = sc.nextInt();
        int bb = sc.nextInt();

        long[] dp_1 = new long[N+1];
        int[] w_1 = {ga, sa, ba};
        int[] v_1 = {gb-ga, sb-sa, bb-ba};
        for (int j=0;j<N+1;j++) {
            dp_1[j] = N-j;
        }
        for (int i=0;i<3;i++) {
            for (int j=0;j<N+1;j++) {
                if (0<=j-w_1[i]) {
                    dp_1[j] = Math.max(dp_1[j], dp_1[j-w_1[i]]+v_1[i]);
                }
                if (0<=j-1) {
                    dp_1[j] = Math.max(dp_1[j], dp_1[j-1]);
                }
            }
        }

        // System.out.println(Arrays.toString(w_1));
        // System.out.println(Arrays.toString(v_1));

        int N_max = (int)dp_1[N];
        long[] dp_2 = new long[N_max+1];
        int[] w_2 = {gb, sb, bb};
        int[] v_2 = {ga-gb, sa-sb, ba-bb};
        for (int j=0;j<N_max+1;j++) {
            dp_2[j] = N_max-j;
        }
        for (int i=0;i<3;i++) {
            for (int j=0;j<N_max+1;j++) {
                if (0<=j-w_2[i]) {
                    dp_2[j] = Math.max(dp_2[j], dp_2[j-w_2[i]]+v_2[i]);
                }
                if (0<=j-1) {
                    dp_2[j] = Math.max(dp_2[j], dp_2[j-1]);
                }
            }
        }

        // System.out.println(Arrays.deepToString(dp_2));

        // System.out.println(dp_1[3][N]);
        System.out.println(dp_2[N_max]);
    }
}

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

long long calcGCD(long long x, long long y)
{
    if (x < y)
    {
        swap(x, y);
    }
    long long remain = x % y;
    while (remain != 0)
    {
        x = y;
        y = remain;
        remain = x % y;
    }
    return y;
}

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

    vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    vector<long long> gcd(N);
    gcd.front() = A.front();
    for (int i = 1; i < N; i++)
    {
        gcd[i] = calcGCD(gcd[i - 1], A[i]);
    }

    vector<long long> gcd_reverse(N);
    gcd_reverse.back() = A.back();
    for (int i = N - 2; i >= 0; i--)
    {
        gcd_reverse[i] = calcGCD(gcd_reverse[i + 1], A[i]);
    }

    long long ans = max(gcd[N - 2], gcd_reverse[1]);
    for (int i = 1; i < N - 1; i++)
    {
        ans = max(ans, calcGCD(gcd[i - 1], gcd_reverse[i + 1]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
typedef long long ll;
typedef pair<pair<int, int>, int> P;

#define INF 1000000000

#define SZ 100

bool visited[SZ*2+5][SZ*2+5];

bool isin(int x, int y){
    if((x-SZ)*(y-SZ)>=0) return x>=0 && x<=SZ*2 && y>=0 && y<=SZ*2;
    else return abs(x-SZ)+abs(y-SZ)<=SZ;
}

int main(){
    int n,t;
    while(cin>>t>>n, t|n){
        fill(visited[0], visited[SZ*2+5], false);
        rep(i,n){
            int x,y;
            cin>>x>>y;
            visited[x+SZ][y+SZ]=true;
        }
        int sx,sy;
        cin>>sx>>sy;

        queue<P> q; //<<x,y>, turn>
        q.push(mp(mp(sx+SZ, sy+SZ), 0));
        visited[sx+SZ][sy+SZ]=true;
        int res=1;
        while (!q.empty()){
            int dx[] = {1,1,0,-1,-1,0};
            int dy[] = {0,1,1,0,-1,-1};

            P p = q.front(); q.pop();
            if(p.second>=t) continue;
            int x = p.first.first, y=p.first.second;
            rep(i,6){
                int nx = x+dx[i], ny=y+dy[i];
                if(isin(nx,ny) && visited[nx][ny]==false){
                    visited[nx][ny]=true;
                    q.push(mp(mp(nx,ny), p.second+1));
                    res++;
//                    cout<<nx-SZ<<","<<ny-SZ<<endl;
                }
            }
        }
        cout<<res<<endl;

    }

    return 0;
}

Measured memory_bytes: 1260
#include <cstdio>
#include <map>

using namespace std;

int main()
{
    int n, m;
    char before, after;
    map<char, char> conversion;
    int i;
    
    while (scanf("%d", &n) * n != 0){
        conversion.clear();

        for (i = 0; i < n; i++){
            scanf(" %c %c", &before, &after);

            conversion[before] = after;
        }

        scanf("%d", &m);
        for (i = 0; i < m; i++){
            scanf(" %c", &before);

            if (conversion.count(before)){
                printf("%c", conversion[before]);
            }
            else {
                printf("%c", before);
            }
        }
        puts("");
    }

    return (0);
}

Measured memory_bytes: 1020
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define lengthof(array) (sizeof(array) / sizeof(*array))
#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it,c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end();++it)
#define RFOR(it,c) for(__typeof((c).rbegin())it=(c).rbegin(); it!=(c).rend();++it)

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
	return os;
}

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

	const int MAX = 100001;
	vector<int> cnt(MAX + 2, 0);

	int n;
	cin >> n;

	for(int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		++cnt[a];
		--cnt[b + 1];
	}

	for(int i = 0; i < MAX; ++i)
		cnt[i + 1] += cnt[i];

	for(int i = n + 1; i > 0; --i) {
		if(cnt[i] + 1 >= i) {
			cout << i - 1 << endl;
			return EXIT_SUCCESS;
		}
	}

	assert(false);
	return EXIT_SUCCESS;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <bitset>
#include <functional>

using namespace std;

int dp[100000];

void to(int &x, int y) {
  x = min(x, y);
}

void solve(int K) {
  set<int, greater<int>> can;
  int t = 1;
  while (!can.count(t)) {
    can.insert(t);
    t *= 10;
    t %= K;
  }

  if (can.size() <= 2000) {
    for (int i = 0; i < K; i++) {
      dp[i] = 1e9;
    }

    for (int i : can) {
      dp[i] = 1;
    }

    for (int k : can) {
      int j = k;
      for (int i = 0; i < K; i++) {
        to(dp[j], dp[i] + 1);
        j++;
        if (j >= K) j -= K;
      }
      for (int i = 0; i < K; i++) {
        to(dp[j], dp[i] + 1);
        j++;
        if (j >= K) j -= K;
      }
      for (int i = 0; i < K; i++) {
        to(dp[j], dp[i] + 1);
        j++;
        if (j >= K) j -= K;
      }
    }

    cout << dp[0] << endl;
  } else {
    static bitset<200000> dp;
    for (int i : can) {
      dp[i] = true;
    }
    for (int k = 2;; k++) {
      static bitset<200000> dp2;
      for (int i : can) {
        dp2 |= dp << i;
      }
      for (int i = K; i < K * 2; i += K) {
        if (dp2[i]) {
          cout << k << endl;
          return;
        }
      }
      dp = dp2 | (dp2 >> K);
    }
  }
}

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

  solve(K);
}


Measured memory_bytes: 3712
/*May The Force Be With Me*/
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#pragma GCC optimize ("Ofast")
#define ll long long
#define MOD 1000000007
#define endl "\n"
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define pb push_back
#define f first
#define s second
#define inf INT_MAX
#define size_1d 10000000
#define size_2d 1000
#define rep(i,v,n) for(ll i = v; i < n; i++)
//Snippets: delta, sieve, fastexp, dfs, bfs, dijkstra, floodfill

using namespace std;

ll n, m;

void Input() {
	cin >> n >> m;
}

void Solve() {
	char a[n][m];
	ll b[n][m];
	memset(b, 0, sizeof b);
	for (ll i = 0; i < n; i++) for (ll j = 0; j < m; j++)cin >> a[i][j];
	if (a[0][0] == '.')b[0][0] = 1;
	for (ll i = 0; i < n; i++) for (ll j = 0; j < m; j++) {
			if (a[i][j] == '#')continue;
			if (i)b[i][j] = (b[i][j] + b[i - 1][j]) % MOD;
			if (j)b[i][j] = (b[i][j] + b[i][j - 1]) % MOD;
		}
	cout << b[n - 1][m - 1];

}

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

	ll T = 1;
	//cin >> T;
	//ll t = 1;
	while (T--) {
		Input();
		//cout << "Case " << t << ": ";
		Solve();
		//t++;
	}
	return 0;
}

Measured memory_bytes: 12376
m,d=map(int,input().split())
if d<=21:
  print(0)
  exit()
hi=0
for month in range(1,m+1):
  for day in range(22,d+1):
    day_str=str(day)
    d1=int(day_str[1])
    d10=int(day_str[0])
    if d1==1 or d10==1:
      continue
    if d1*d10==month:
      hi+=1
print(hi)

Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int N;
int main(){
    cin>>N;
    cout<<(N-2)*180;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    ll answer = 1;
    for(ll i = 1;i <= n;i++){
        answer = (answer*i)%MOD;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

using namespace std;
int main() {
	int a, b;
	cin >> a >> b;

	for (int i = 1; i <= 1300; i++)
	{

		int aX = i * 0.08;
		int bX = i * 0.1;
		if (aX == a && bX == b) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
}

Measured memory_bytes: 384
n, m, l = map(int, input().split())
A = [[int(num) for num in input().split()] for i in range(n)]
B = [[int(num) for num in input().split()] for i in range(m)]
B = list(zip(*B)) # 列を行に置き換える
C = [[0 for i in range(l)] for j in range(n)]
for i, A_line in enumerate(A):
    for j, B_line in enumerate(B):
        for A_element, B_element in zip(A_line, B_line):
            C[i][j] += A_element * B_element

for line in C:
    for i, element in enumerate(line):
        if i == l - 1:
            print(element)
        else:
            print(element, end=' ')



Measured memory_bytes: 7052
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <set>
#include <sstream>
#include <vector>
using namespace std;

// S から N−3 桁
// 4 - 3 = 1
// 5 - 3 = 2
// 100 - 3 = 97

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

    int N; // 4 <= N <= 30000
    cin >> N;
    int s[N];
    for (int i = 0; i < N; i++)
    {
        char c;
        cin >> c;
        s[i] = c - '0';
    }

    int exists[1000] = {};
    for (int i = 0; i < 1000; i++)
    {
        int digits[3] = {};
        digits[0] = floor(i / 100);
        digits[1] = floor((i % 100) / 10);
        digits[2] = floor(i % 10);

        int pos = 0;
        int d = 0;
        while (pos < N && d < 3)
        {
            if (digits[d] == s[pos])
            {
                ++d;
                if (3 == d)
                {
                    exists[i] = 1;
                }
            }
            pos++;
        }
    }

    int counter = 0;
    for (int i = 0; i < 1000; i++)
    {
        if (exists[i])
        {
            counter++;
        }
    }

    cout << counter << endl;
    return 0;
}


Measured memory_bytes: 384
S = input()
Q = int(input())

added = ''
inv = 0
for i in range(Q):
  query = input().split()
  if query == ['1']:
    inv = (inv + 1)%2
  else:
    f, c = query[1], query[2]
    if (f=='1' and inv) or (f=='2' and not inv):
      S += c
    else:
      added += c

if inv:
  print(S[::-1] + added)
else:
  print(added[::-1] + S)

Measured memory_bytes: 4476
Scanf.scanf "%d" (fun n ->
    let p = Array.init n (fun _ -> Scanf.scanf " %d" (fun p -> p)) in

    let rec loop i mm acc =
        if i = n then acc else
            if p.(i) < mm then loop (i + 1) p.(i) (acc + 1)
                          else loop (i + 1) mm acc
    in
    loop 1 p.(0) 1 |> Printf.printf "%d\n"
)

Measured memory_bytes: 5888
# -*- coding: utf-8 -*-

import sys
from itertools import permutations
from math import hypot

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
XY = []
for i in range(N):
    x, y = MAP()
    XY.append((x, y))

sm = cnt = 0
for perm in permutations(XY):
    dist = 0
    prev = (0, 0)
    for i, (x, y) in enumerate(perm):
        if i == 0:
            prev = (x, y)
        else:
            x2, y2 = prev
            dist += hypot(x-x2, y-y2)
    sm += dist
    cnt += 1
print(sm/cnt)


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

int main(){
  int n;
  cin >> n;
  int a=0,b=0,c=0,d=0;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    if(s=="AC") a++;
    else if(s=="WA") b++;
    else if(s=="TLE") c++;
    else d++;
  }
  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;
}


Measured memory_bytes: 3624
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,a,b,ans=0;
  cin >> n >> a >> b;
  vector<ll> t(n);
  ans = n;
  for(int i=0;i<n;i++){
    cin >> t[i];
    if(a<=t[i]&&t[i]<b){
      ans--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())

nb_na, b_na, nb_a, b_a = 0, 0, 0, 0
ans = 0
for _ in range(N):
    s = input()
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        b_a += 1
    elif s[0] == "B":
        b_na += 1
    elif s[-1] == "A":
        nb_a += 1
    else:
        nb_na += 1
if b_a > 0 and nb_a > 0:
    b_a += 1
    nb_a -= 1
if b_a > 0 and b_na > 0:
    b_a += 1
    b_na -= 1
ans += min(nb_a, b_na)

if b_a > 0:
    ans += b_a - 1

print(ans)


Measured memory_bytes: 47852
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n,m, a, b, x = 0, y = 0, z = 0;
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> m;
		if (m <= a)x++;
		else if (m <= b)y++;
		else z++;
	}
	m = min(x, min(y, z));
	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct bian
{
	int nxt,to;
}bi[400040];
int n,m,d[100010],head[100010],num,w[200020],p[100010];
char col[100010];
inline void add(int from,int to)
{
	bi[++num]=bian{head[from],to};
	head[from]=num;
}
int cnt;
bool vis[100010];
void dfs(int x,int c)
{
	++cnt;vis[x]=1;col[x]=c?'W':'B';
	for(int i=head[x],y;i;i=bi[i].nxt)
	{
		y=bi[i].to;
		if(d[y]==d[x]&&!vis[y])w[(i+1)/2]=d[x],dfs(y,c^1);
	}
}
void work(int x)
{
	cnt=0;
	dfs(x,0);
	if(cnt==1)col[x]=0;
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d",&d[i]),p[i]=i;
	for(int i=1,x,y;i<=m;++i)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x);
	}
	sort(p+1,p+1+n,[&](int x,int y){return d[x]<d[y];});
	for(int i=1,r;i<=n;i=r+1)
	{
		r=i;
		while(r<n&&d[p[r+1]]==d[p[i]])++r;
		for(int j=i;j<=r;++j)if(!col[p[j]])work(p[j]);
		for(int j=i;j<=r;++j)
			if(!col[p[j]])
			{
				bool flag=0;
				for(int k=head[p[j]];k;k=bi[k].nxt)
					if(d[bi[k].to]<d[p[j]])
					{
						w[(k+1)/2]=d[p[j]]-d[bi[k].to];
						col[p[j]]=col[bi[k].to];
						flag=1;
						break;
					}
				if(!flag)
				{
					printf("-1");
					exit(0);
				}
			}
	}
	for(int i=1;i<=n;++i)putchar(col[i]);putchar('\n');
	for(int i=1;i<=m;++i)
		if(w[i])printf("%d\n",w[i]);
		else printf("%d\n",1000000000);
	return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  string S;
  cin >> S;
  int N = S.size();

  if (N == 26)
  {
    if (S == "zyxwvutsrqponmlkjihgfedcba")
    {
      cout << -1 << endl;
      return 0;
    }
    else
    {
      vector<bool> used(abc.size(), true);
      for (int i = N - 1; i >= 0; i--)
      {
        for (int j = 0; j < abc.size(); j++)
        {
          if (abc.at(j) == S.at(i))
          {
            used.at(j) = false;
            break;
          }
        }
        
        if (S.at(i - 1) < S.at(i))
        {
          for (int j = 0; j < abc.size(); j++)
          {
            if (!used.at(j) && abc.at(j) > S.at(i - 1))
            {
              cout << S.substr(0, i - 1) << abc.at(j) << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  else
  {
    vector<bool> used(abc.size(), false);
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < abc.size(); j++)
      {
        if (abc.at(j) == S.at(i))
        {
          used.at(j) = true;
          break;
        }
      }
    }
    
    for (int i = 0; i < abc.size(); i++)
    {
      if (!used.at(i))
      {
        cout << S << abc.at(i) << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int S;
    int h,m,s;
    scanf("%d",&S);
    h = S/3600;
    m = (S%3600)/60;
    s = S-h*3600-m*60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2764
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if(a < 9 && b < 9){
            System.out.println("Yay!");
        }else{
            System.out.println(":(");
        }
    }
}

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

int h[200000000];
int H;

void HEAP(int h[], int i) {
	int l, r, a, b, MAX;
	l = i * 2;
	r = i * 2 + 1;
	if (h[l] > h[i] && l<=H) {
		MAX = l;
	}
	else {
		MAX = i;
	}
	if (h[MAX] < h[r] && r<=H) {
		MAX = r;
	}
	if (MAX != i) {
		a = h[i];
		b = h[MAX];
		h[i] = b;
		h[MAX] = a;
		HEAP(h, MAX);
	}
}

void HEAP2(int h[]){
	for (int i = H / 2; i >= 1; i--) {
		HEAP(h, i);
	}
}

int main() {
	cin >> H;
	for (int i = 1; i <= H; i++) {
		cin >> h[i];
	}
	HEAP2(h);
	for (int i = 1; i <= H; i++) {
		cout << ' ';
		cout << h[i];
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 4968
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 55
using namespace std;
ll n,k,a[N][N],dp[N][N],ans=0;
void get1()
{
	ll i,j,l,tmp[N][N];
	memset(tmp,0,sizeof(tmp));
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			for(l=0;l<n;l++)
			{
				tmp[i][j]=(tmp[i][j]+(dp[i][l]*a[l][j])%MOD)%MOD;
			}
//			cout<<i<<" "<<j<<":"<<dp[i][j]<<" "<<a[i][j]<<endl;
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			dp[i][j]=tmp[i][j];
		}
	}
	return;
}
void get2()
{
	ll i,j,l,tmp[N][N];
	memset(tmp,0,sizeof(tmp));
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			for(l=0;l<n;l++)
			{
				tmp[i][j]=(tmp[i][j]+(a[i][l]*a[l][j])%MOD)%MOD;
			}
//			cout<<i<<" "<<j<<":"<<a[i][j]<<endl;
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			a[i][j]=tmp[i][j];
		}
	}
	return;
}
void solve()
{
	ll i;
	memset(dp,0,sizeof(dp));
	for(i=0;i<n;i++)
	{
		dp[i][i]=1;
	}
	while(k!=0)
	{
		if(k%2==1)
		{
			get1();
		}
		get2();
		k/=2;
	}
	return;
}
int main(){
	ll i,j;
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	solve();
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			ans=(ans+dp[i][j])%MOD;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

      

        int times = scan.nextInt();

        int[][] delta = new int[times][3];

        for (int i = 0; i < times; i++) {

            int edge1 = scan.nextInt();
            int edge2 = scan.nextInt();
            int edge3 = scan.nextInt();

            delta[i][0] = edge1;
            delta[i][1] = edge2;
            delta[i][2] = edge3;

        }

        for (int i = 0; i < times; i++) {
            if ((delta[i][0]) * (delta[i][0]) == (delta[i][1]) * (delta[i][1]) + (delta[i][2]) * (delta[i][2])
                    || (delta[i][1]) * (delta[i][1]) == (delta[i][0]) * (delta[i][0]) + (delta[i][2]) * (delta[i][2])
                    || (delta[i][2]) * (delta[i][2]) == (delta[i][0]) * (delta[i][0]) + (delta[i][1]) * (delta[i][1])) {

                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }

        scan.close();

    }

}

Measured memory_bytes: 32724
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long ll;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
//
int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> graph(n, vector<bool>(n));
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        graph[x - 1][y - 1] = true;
        graph[y - 1][x - 1] = true;
    }
    vector<int> a;
    for(int i = 0; i < n; i++) a.push_back(i);
    int ans = 0;
    do{
        if(a[0]) break;
        bool pos = true;
        for(int i = 0; i < n - 1; i++){
            pos &= graph[a[i]][a[i + 1]];
        }
        if(pos) ans++;
    }while(next_permutation(a.begin(), a.end()));
    cout << ans;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
#define int long long

signed main(){

   int I, O, T, J, L, S, Z;
   cin>> I>> O>> T>> J>> L>> S>> Z;

   int s=0;
   s+=(O*2);
   int t=s;
   if(I>0&&J>0&&L>0){
      t+=6;
      I--; J--; L--;
      t+=(J/2*4);
      t+=(L/2*4);
      t+=(I/2*4);
      I++; J++; L++;
   }
   s+=(J/2*4);
   s+=(L/2*4);
   s+=(I/2*4);

   cout<< max(s, t)/2<< endl;

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;


int main(){
  string s; cin >> s;
  int i = 0, j = s.size()-1;
  int ans = 0;
  while(j-i>0){
    if(s[i] == s[j]){
      i++; j--;
    }
    else if(s[i] == 'x'){
      i++;
      ans++;
    }
    else if(s[j] == 'x'){
      j--;
      ans++;
    }
    else{
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

map<ll, ll> primeFactor(ll x) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= x; i++) {
        while (x % i == 0) {
            res[i]++;
            x /= i;
        }
    }
    if (x != 1) res[x] = 1;
    return res;
}

int main() {
    ll N; cin >> N;
    ll ans = 0;
    for (int i = 1; i <= N; i += 2) {
        map<ll, ll> primes = primeFactor(i);
        ll count = 1;
        for (auto j: primes) {
            count *= j.second + 1;
        }
        if (count == 8) ans++;
    }
    cout << ans << endl;
}

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

int main(){
int x;
  cin>>x;
  if(x>=400 && x<=599){
    cout<<8<<endl;
  }else if(x>=600 &&x<= 799){
    cout<<7<<endl;
  }else if(x>=800 && x<=999){
    cout<<6<<endl;
    }
  else if(x>=1000 && x<=1199){
    cout<<5<<endl;
  }else if(x>=1200 && x<=1399){
    cout<<4<<endl;
  }else if(x>=1800 && x<=1999){
    cout<<1<<endl;
  }else if(x>=1600 && x<=1799){
    cout<<2<<endl;
  }else if(x>=1400 && x<=1599){
    cout<<3<<endl;
  }
}


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

const int N = 2e5 + 5;
long long a[N], b[N];

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    long long int n = 0;
    cin >> n;

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


    long long sum = 0;
    for(int i = 0; i < N;i ++) {
        sum += (b[i] * (b[i] - 1) / 2);
    }

    for(int i = 0; i< n; i++) {
        cout << sum - b[a[i]] + 1 << endl;
    }

    
    return 0;
}

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

int main(){
	bool arr[(int)1e6+1]={};
	int N,ipt[(int)2e5];
	cin>>N;
	for(int i=0; i<N; i++)cin>>ipt[i];
	sort(ipt,ipt+N);
	int cnt=0;
	for(int i=0; i<N-1; i++){
		if(arr[ipt[i]]==0){
			if(ipt[i]!=ipt[i+1])cnt++;
			for(int j=ipt[i]; j<=ipt[N-1]; j+=ipt[i])arr[j]=1;
		}
	}if(arr[ipt[N-1]]==0)cnt++;
	cout<<cnt<<'\n';
}

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

using namespace std;

int i,j;
long long a,b;

int main(){
	scanf("%lld%lld", &a, &b);
	
	if(a == b) return 0 * printf("1\n");
	
	int mx = -1;
	
	for(i = 0; i <= 61; i++){
		if((a & (1LL << i)) != (b & (1LL << i)))
		mx = i;
	}
	
	pair <long long, long long> r1, r2, r3;
	
	a &= ((1LL << (mx + 1)) - 1LL);
	b &= ((1LL << (mx + 1)) - 1LL);
	
	r1 = {a, (1LL << mx) - 1LL};
	
	int r = 0;
	
	r2.first = (1LL << mx);
	
	int lt = -1;
	
	for(i = 0; i <= mx; i++){
		if((1LL << mx) + (1LL << i) > b) continue;
		lt = i;
	}
	
	r2.second = (1LL << mx) + (1LL << (lt + 1)) - 1LL;
	
	r3 = {(1LL << mx) + a, (1LL << (mx + 1)) - 1LL};
	
	long long res = r1.second - r1.first + 1LL;
	
	if(r3.first <= r2.second){
		res += r2.second - r2.first + 1LL;
		res += r3.second - r3.first + 1LL;
		res -= r2.second - r3.first + 1LL;
	}
	else{
		res += r2.second - r2.first + 1LL;
		res += r3.second - r3.first + 1LL;
	}
	
	printf("%lld\n", res);
}


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

int main() {
  int n;
  int k;
  cin >> n >> k;
  priority_queue<ll> queh;
  ll tmph;
  for(int i = 0; i < n; i++){
      cin >> tmph;
      queh.push(tmph);
  }
  for(int i = 0; i < k; i++){
      if(!queh.empty()) queh.pop();
  }
  ll ansh = 0;
  while(!queh.empty()){
      ansh += queh.top();
      queh.pop();
  }
  cout << ansh << endl;
  return 0;
}

Measured memory_bytes: 2420
#include "bits/stdc++.h"
using namespace std;
vector<int> a;
int main()
{
	int n,d,x;
	int i,sum=0;
	scanf("%d",&n);
	scanf("%d %d",&d,&x);
	a.resize(n);
	d--;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum+=(d/a[i]+1);
	}
	printf("%d\n",sum+x);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,q;
int mx = -1;

struct Score {
    int a,b,c,d;
} arr[100];

void dfs(int k,int d,vector<int> A) {
    if (d == n) {
        int s = 0;
        for (int j = 0;j < q;j ++) {
            if (A[arr[j].b - 1] - A[arr[j].a - 1] == arr[j].c) {
                s += arr[j].d;
            }
        }
        mx = max(mx,s);
        return;
    }
    for (int i = k;i <= m;i ++) {
        A.push_back(i);
        dfs(i,d + 1,A);
        A.erase(A.end() - 1);
    }
}

int main()
{
    scanf("%d%d%d",&n,&m,&q);
    
    int a,b,c,d;
    for (int i = 0;i < q;i ++) {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        arr[i].a = a;
        arr[i].b = b;
        arr[i].c = c;
        arr[i].d = d;
    }
    dfs(1,0,vector<int>());
    printf("%d\n",mx);
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)
#define long long long

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<int, int> ii;
typedef pair<int, long> ill;
typedef pair<long, int> lli;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<pair<long, long>> vll;
typedef vector<ii> vii;
typedef vector<pair<ii, int>> viii;

const double PI = acos(-1.0), EPS = 1e-9;
const int MAXN = 100005, MAXM = 102, Mod = 998244353, MAXLog = 20;



int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout
            << fixed;

    int ans = 0;
    string str;
    cin >> str;
    for (char ch : str) {
        if (ch == '+')
            ++ans;
        else
            --ans;
    }
    cout << ans << '\n';


    return 0;
}

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

#define CO const
#define IN inline
typedef long long int64;
#define int int64

template<class T> IN T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}

array<int,2> operator+(CO array<int,2>&a,CO array<int,2>&b){
	return {a[0]+b[0],a[1]+b[1]};
}

CO int N=51,M=N*N*N,inf=1e18;
int fa[N];
array<int,2> a[N];

int F[M],pos[M];
array<int,2> que[M];

signed main(){
	int n=read<int>(),X=read<int>(),D=read<int>();
	a[1]={1,read<int>()};
	for(int i=2;i<=n;++i) a[i]={1,read<int>()},read(fa[i]);
	for(int i=n;i>=2;--i) a[fa[i]]=a[fa[i]]+a[i];
	sort(a+1,a+n+1,[&](CO array<int,2>&a,CO array<int,2>&b)->bool{
		return a[0]*b[1]>b[0]*a[1];
	});
	
	F[0]=0,fill(F+1,F+M+1,inf);
	int l=min(D,n),s=0;
	for(int i=1;i<=n;++i){
		s+=n*a[i][0];
		for(int r=0;r<a[i][0];++r){ // remainder
			int tot=0;
			for(int j=r;j<=s;j+=a[i][0]) pos[++tot]=j;
			int L=1,R=0;
			for(int j=tot,k=tot;j>=1;--j){
				while(L<=R and que[L][0]>j) ++L;
				for(;k>=1 and k>=j-l;--k){
					array<int,2> x={k,F[pos[k]]-a[i][1]*k};
					while(L<=R and que[R][1]>=x[1]) --R;
					que[++R]=x;
				}
				F[pos[j]]=min(F[pos[j]],que[L][1]+a[i][1]*j);
			}
		}
	}
	
	int ans=0;
	for(int i=0;i<=s;++i)if(F[i]<=X){
		int sum=X-F[i],num=i;
		for(int j=1;j<=n;++j){
			int u=sum/a[j][1];
			if(a[j][0]<n) u=min(u,D-l); // not root
			sum-=a[j][1]*u,num+=a[j][0]*u;
		}
		ans=max(ans,num);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
vector<int> dx= {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
const int INF=100000000;
int main(){
    long long n;
    cin>>n;
    priority_queue<pair<long long,long long>> pq;//(左端、右端)でpairを入れている
    for(int i=0; i<n ;i++){
        long long x,l;
        cin>>x>>l;
        pq.push(make_pair(x-l,x+l));
    }
    int ans = 0;
    long long hasi=10000000000;
    while(!pq.empty()){
        pair<long long,long long> tmp = pq.top();
        if(tmp.second>hasi){
            pq.pop();
            continue;
        }
        else{
            ans++;
            hasi = tmp.first;
            pq.pop();
        }
    }
    cout<<ans<<endl;

}

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

int main()
{
    int m;  //中間試験点数　m<=50
    int f;  //期末試験点数  f<=50
    int r;  //再試験点数    r<=100

    while(1){
        cin>>m>>f>>r;
        if(m==-1&&f==-1&&r==-1)
            break;
        else{
            if(m==-1 || f==-1)
                cout<<'F'<<endl;
            else if(m+f>=80)
                cout<<'A'<<endl;
            else if(m+f>=65)
                cout<<'B'<<endl;
            else if(m+f>=50)
                cout<<'C'<<endl;
            else if(m+f>=30){
                if(r>=50)
                    cout<<'C'<<endl;
                else
                    cout<<'D'<<endl;
            }else
                cout<<'F'<<endl;
        }
    }


      return 0;
}


Measured memory_bytes: 3092
//AtCoder ABC096 A - Day of Takahashi
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll a,b; 
    cin>>a>>b;
    ll ans=a-1;
    if(b>=a) ans+=1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#define rep(a,b,c) for(int a=b;a<c;a++)
#define rep_(a,b,c) for(int a=c-1;a>=b;a--)
using namespace std;

int main()
{
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
	int a[20005],b[20005],p[20005],t=0,n;
	cin >> n;
	rep(i,0,n) cin>>p[i],a[i]=i+1;
	rep(i,0,n) b[p[i]-1]=i-p[i];
	//rep(i,0,n) cout << a[i] << ' '; cout << endl;
	//rep(i,0,n) cout << b[i] << ' '; cout << endl;
	rep(i,1,n) 
	{
		t=max(max(0,a[i-1]-a[i]+1),max(0,b[i]-b[i-1]+1));
		b[i]-=t;
		a[i]+=t;
	}
	rep(i,0,n) cout << a[i] << ' '; cout << endl;
	rep(i,0,n) cout << b[i]-b[n-1]+1 << ' '; cout << endl;
}

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

using namespace std;

typedef long long ll;

int n, m, q;
int *a, *b, *c, *d;
int x[15];

ll func(int i, int k) {
    if (i == n) {
        ll sum = 0;
        for (int j = 0; j < q; j++) {
            if (x[b[j]]-x[a[j]] == c[j])
                sum += d[j];
        }
        return sum;
    }

    ll ans = 0;
    for (int j = k; j <= m; j++) {
        x[i] = j;
        ans = max(func(i+1, j), ans);
    }
    return ans;
}

int main() {
    cin >> n >> m >> q;
    a = new int[q], b = new int[q], c = new int[q], d = new int[q];
    for (int i = 0; i < q; i++) {
        
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }

    cout << func(0, 1) << endl;
    return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int>b(n);
rep(i,n){
    cin>>b[i];
}
vector<int>a(n);
rep(i,n){
    int idx=-1;
    rep(j,n-i){
        if(b[j]==j+1){
            idx=j;
        }
    }
    if(idx<0)continue;
    a[i]=b[idx];
    b.erase(b.begin()+idx);
}
if(b.empty()){
    rrep(i,n){
        cout<<a[i]<<endl;
    }
}
else{
    cout<<-1<<endl;
}

return 0;
}

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

int main() {
    int a, b;
    char op;
    for (;;) {
        cin >> a >> op >> b;
        if (op == '?') break;
        switch (op) {
            case '+':
                cout << a+b<< endl;
                break;
            case '-':
                cout << a-b<< endl;
                break;
            case '/':
               cout << a/b<< endl;
                break;
            
            case '*':
                cout << a*b<< endl;
                break;
            case '%':
                cout << a%b<< endl;
                break;
        }
    }
}



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

int main(void)
{
	int t,n;
	int a,b;
	int sum;

	while(1)
	{
		cin >> t;
		if(t == 0)
			return 0;

		cin >> n;

		sum = 0;
		for(int i=0;i<n;++i)
		{
			cin >> a >> b;
			sum += b - a;
		}
		if(t <= sum)
			cout << "OK" << endl;
		if(t > sum)
			cout << t - sum << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{
	int n=0, a[100],i=0;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (int i = n - 1; i > 0; i--)
	{
		printf("%d ", a[i]);
	}
	printf("%d\n",a[0]);
	return 0;
}

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

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

int N, Z, W;
int a[2005];

/*==================================================*/

/*==================================================*/

void subSolv(){
    if(N > 1){
        cout<<max(abs(a[N-1]-W), abs(a[N-2]-a[N-1]))<<endl;
    }else{
        cout<<abs(a[0]-W)<<endl;
    }
}

int dp[2005][2];

int game(int id, int player, int x, int y){
    if(id == N) return abs(x-y);

    if(dp[id][player] > -1) return dp[id][player];

    if(player == 0){ //x
        int xScore = -1;
        REP(i,id,N){
            xScore = max(xScore, game(i+1,1,a[i],y));
        }
        return dp[id][player] = xScore;
    }else{
        int yScore = INF;
        REP(i,id,N){
            yScore = min(yScore, game(i+1,0,x,a[i]));
        }
        return dp[id][player] = yScore;
    }
}


int main() {
    cin>>N>>Z>>W;
    REP(i,0,N) cin>>a[i];
    REP(i,0,N)REP(j,0,2) dp[i][j] = -1;
    cout<<game(0,0,Z,W)<<endl;
    //subSolv();
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main(){
	char c;
	int i, cnt[26] = {0};
	while((c = getchar()) != EOF){
		if((c >= 'A') && (c <= 'Z')){
			cnt[c - 'A']++;
		}
		if((c >= 'a') && (c <= 'z')){
			cnt[c - 'a']++;
		}
	}
	for(i = 0; i < 26; i++){
		printf("%c : %d\n",'a' + i, cnt[i]);
	}
	return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int flag = 0;
    int i = 0;
    while(i < S.length()) {
        //dump(S.substr(i,5));
        //dump(S.substr(i,7));
        if (S.substr(i,8) == "dreamera") {
            i += 5;
            continue;
        }
        else if (S.substr(i,8) == "dreamere") {
            i += 7;
            continue;
        }
        else if (S.substr(i,6) == "eraser") {
            i += 6;
            continue;
        }
        else if (S.substr(i,5) == "erase") {
            i += 5;
            continue;
        }
        else if (S.substr(i,7) == "dreamer") {
            i += 7;
            continue;
        }
        else if (S.substr(i,5) == "dream") {
            i += 5;
            continue;
        }

        else {
            flag = 1; break;
        }
    }
    if (flag == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll mod=1000000007;
ll fac[100010],revfac[100010],mul[100010],sum[100010],a[100010],ans;
int main()
{
    scanf("%d",&n);
    fac[0]=1;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",a+i);
        fac[i]=fac[i-1]*i;
        fac[i]%=mod;
    }
    revfac[n]=1;
    for(int i=n-1;i>0;i--)
    {
        revfac[i]=i*revfac[i+1];
        revfac[i]%=mod;
    }
    for(int i=1;i<n;i++)
    {
        mul[i]=fac[i-1]*revfac[i+1];
        mul[i]%=mod;
        sum[i]=sum[i-1]+mul[i];
        sum[i]%=mod;
    }
    for(int i=1;i<n;i++)
    {
        ans+=(a[i+1]-a[i])*sum[i];
        ans%=mod;
    }
    printf("%lld",ans);
}

Measured memory_bytes: 4096
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    long long N, H;
    cin >> N >> H;

    vector<long long> a(N), b(N);
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];

    long long maxA = *max_element(a.begin(), a.end());

    priority_queue<long long> Q;
    for (int i = 0; i < N; i++) if (b[i] > maxA) Q.push(b[i]);

    int ans = 0;
    while (!Q.empty()) {
        long long d = Q.top();
        Q.pop();
        if (H <= 0) break;
        H -= d;
        ans++;
    }

    ans += max(0LL, H) / maxA;
    if (max(0LL, H) % maxA) ans++;

    cout << ans << endl;

    return 0;
}




























Measured memory_bytes: 2936
function Main(input) {
    var input = input.split('\n');
    var nidan = input[1].split(' ').map(n => parseInt(n, 10)).sort((a, b) => a < b ? -1 : 1);
    var sum = 0;
    var n = parseInt(input[0], 10);
    for(i = 0; i < n; i++) {
        sum += nidan[2*i];
    }
    console.log(sum);

    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7624
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>





const int N=110;
ll n,a[N],sum,res;




void solve()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=-1000;i<=1000;i++)
	{
		sum=0;
		for(int j=1;j<=n;j++)
		{
			sum+=(a[j]-i)*(a[j]-i);
		}
		if(i==-1000||res>sum)res=sum;
	}
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int col(int a) {
	return a % 2 == 1 ? a * 3 + 1 : a / 2;
}

void solve() {
	int n;
	cin >> n;
	set<int> S; S.insert(n);
	rep(i, 0, 1000000) {
		n = col(n);
		if(S.count(n)) {
			cout << i + 2 << "\n";
			return;
		}
		S.insert(n);
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256