akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,m;
//mapの使い方
#include <map>


int main(){
  ll ans=0;
  cin >> n >> m;
  vi a(n);
  map<long long, long long> nums;
  REP(i,n){
	  cin>>a[i];
	  nums[a[i]]++;
  }

  REP(i,m){
	  auto itr=nums.end();
	  itr--;
	  itr->second--;
	  nums[(itr->first)/2]++;
	  if (itr->second==0){
		  nums.erase(itr->first);
	  }
  }
  

    for (auto it : nums) {
        //long long num = it.second; // it.first が it.second 個ある
		ans+=it.first*it.second;
    }


cout<<ans<<endl;



  return 0;
}

Measured memory_bytes: 7296
import java.util.HashMap;
import java.util.Scanner;

class Main{

	static Scanner scanner = new Scanner(System.in);
	static HashMap<Integer, Integer> map;

	public static void main(String args[]){
		while(true){
			int n = scanner.nextInt();
			if(n == 0) break;
			map = new HashMap<Integer, Integer>();
			System.out.println(solve(n));
		}
	}

	static String solve(int n){
		int i = 0;
		Integer m;
		Integer num;
		String result = "NO COLOR";
		for(i = 0; i < n; i++){
			m = scanner.nextInt();
			num = map.get(m);
			if(num != null){
				num++;
				map.put(m, num);
				if(num > n/2) result = m + "";
			}else{
				map.put(m, 1);
				num = 1;
				if(num > n/2) result = m + "";
			}
			if(i % 100000 == 0) System.gc();
		}
		return result;
	}
}

Measured memory_bytes: 114188
#include<stdio.h>
#include<string.h>
 
int main(){
	char input[11];
	scanf("%s",input);
	int tanda=0;
	int len=strlen(input);
	char c[11]={'\0'};
	int d=0;
	
	for(int i=0;i<len;i++){
		if(input[i]=='0'){
			c[d]='0';
			d++;
		}
		else if(input[i]=='1'){
			c[d]='1';
			d++;
		}
		else if(input[i]=='B'){
			if(d!=0){
				d--;
				c[d]='\0';
			}
		}
	}
	
	printf("%s", c);
	
	return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int N;
vector<int> stones;
vector<int> dp;

int calcCost(int i, int j) {
    return abs(stones[i] - stones[j]);
}

int solve(int currStone) {
    if (dp[currStone] != -1) {
        return dp[currStone];
    }

    if (currStone == N) {
        return 0;
    }

    int prev_max = 0x3f3f3f3f;
    if (currStone <= N-1) {
        prev_max = min(prev_max, solve(currStone + 1) + calcCost(currStone, currStone + 1));
    }
    if (currStone <= N-2) {
        prev_max = min(prev_max, solve(currStone + 2) + calcCost(currStone, currStone + 2));
    }

    return dp[currStone] = prev_max;
}

int main() {
    cin >> N;

    stones = vector<int>(N+1);
    dp = vector<int>(N+1, -1);
    for (int i = 1; i <= N; i++) {
        cin >> stones[i];
    }

    cout << solve(1) << endl;

    return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl 	"\n"
 
typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;
#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define tr(c,i) 	for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) 	((c).find(x) != (c).end())
 
#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
 
int main()
{	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	ll n;
 cin>>n;
 ll a[n];
 for(ll i=0;i<n;i++)
 {
   cin>>a[i];
 }
 ll sum=0;
 for(ll i=0;i<n-1;i++)
 {
   for(ll j=i+1;j<n;j++)
   {
     
     sum+=a[i]*a[j];
   }
 }
 cout<<sum;
 return 0;
}
 
 

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

vector<ll> v;

void dfs(string tmp)
{
    v.push_back(stoll(tmp));
    if(stoll(tmp) > 3234566667) return ;
    int n = tmp.size();
    char last = tmp[n-1];
    for(int i = -1; i <=1 ;i++){
        char append = last + i;
        if(append >= '0' && append <= '9'){
            string k = tmp+append;
            dfs(k);
        }
    }
    
}

int main()
{
    int n;cin >> n;
    for(int i = 1; i < 10; i++){
        dfs(to_string(i));
    }
    sort(v.begin(),v.end());
    cout << v[n-1];
}

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

map<string,int> sys;

int N, M;
string s;
bool locked = true;

int main() {
    cin >> N;
    for (int i=0; i<N; ++i) {
        cin >> s;
        sys[s] = 1;
    }
    cin >> M;
    for (int i=0; i<M; ++i) {
        cin >> s;
        if (sys[s]) {
            if (locked) {
                locked = false;
                cout << "Opened by " << s << endl;
            } else {
                locked = true;
                cout << "Closed by " << s << endl;
            }
        } else {
            cout << "Unknown " << s << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void sorti(vi &a) {sort(a.begin(), a.end());}
void sortll(vll &a) {sort(a.begin(), a.end());}
void sorts(vs &a) {sort(a.begin(), a.end());}

int main() {
  string s;
  ll k;
  cin >> s >> k;
  ll m = s.size();
  if (m < k) {
    cout << 0 << endl;
    return 0;
  }
  string ss;
  for (ll i = 0; i < m; i++) ss.push_back('0');
  if (k == 1) {
    ll ans = s[0] - '0';
    ans += 9 * (m - 1);
    cout << ans << endl;
  }
  else if (k == 2) {
    ll ans = (m - 1) * (m - 2) / 2 * 81;
    for (ll a = 1; a <= s[0] - '0'; a++) {
      for (ll b = 1; b < 10; b++) {
        for (ll x = 1; x < m; x++) {
          string sss = ss;
          sss[0] = a + '0';
          sss[x] = b + '0';
          if (sss <= s) ans++;
        }
      }
    }
    cout << ans << endl;
  }
  else {
    ll ans = 243 * (m - 3) * (m - 2) / 2 * (m - 1);
    for (ll a = 1; a <= s[0] - '0'; a++) {
      for (ll b = 1; b < 10; b++) {
        for (ll c = 1; c < 10; c++) {
          for (ll y = 1; y < m - 1; y++) {
            for (ll z = y + 1; z < m; z++) {
              string sss = ss;
              sss[0] = a + '0';
              sss[y] = b + '0';
              sss[z] = c + '0';
              if (sss <= s) ans++;
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
}


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

using namespace std;

long int gcd(long int a,long int b){
	long int r,tmp;
	if(a<b){
		tmp = a; a = b; b = tmp;
	}
	r = a % b;
	while(r != 0){
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
int main(void){
	long int a,b;
	cin>>a>>b;
	long int k,ans;
	k = gcd(a,b);
	ans = a*b;
	ans = ans / k;
	cout<<ans<<endl;
	/*
	for(i = 1; i <= a*b; i++){
		if(i % a == 0 && i % b == 0){
			cout<<i<<endl;
			return 0;
		}
	}
	*/
	return 0;
}




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

int S[100000];
int n, q;
int C;

int main() {
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> S[i];
    }
    cin >> q;
    for(int i=0; i<q; i++){
        int t;
        cin >> t;
        int a=0, b=n;
        while(a<b){
            int m = (a+b)/2;
            if(t == S[m]){
                C++;
                break;
            }
            if(t < S[m])
                b = m;
            else
                a = m + 1;
        }
    }
    cout << C << endl;
}

Measured memory_bytes: 3372
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Chain{
   int p, l, r;
};

struct Chain
   T[MAX];

int n;

void preParse(int u){
   if (u==NIL)
      return;
   printf(" %d", u);
   preParse(T[u].l);
   preParse(T[u].r);
}

void inParse(int u){
   if (u==NIL)
      return;
   inParse(T[u].l);
   printf(" %d", u);
   inParse(T[u].r);
}

void postParse(int u){
   if (u==NIL)
      return;
   postParse(T[u].l);
   postParse(T[u].r);
   printf(" %d", u);
}

int main()
{
   int i, id, l, r, root;

   scanf("%d", &n);
   for (i=0; i<n; i++){
      T[i].p = NIL;
   }

   for (i=0; i<n; i++){
      scanf("%d %d %d", &id, &l, &r);
      T[id].l = l;
      T[id].r = r;
      if (l!=NIL)
         T[l].p = id;
      if (r!=NIL)
         T[r].p = id;
   }

   for (i=0; i<n; i++)
      if (T[i].p==NIL)
         root = i;

   puts("Preorder");
   preParse(root);
   printf("\n");
   puts("Inorder");
   inParse(root);
   printf("\n");
   puts("Postorder");
   postParse(root);
   printf("\n");

   return 0;
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+7;
int a[N];
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	queue<pair<int,int> > q;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n,greater<int>() );
	ll ans = 0;
	for(int i=0;i<n;i++){
		if(q.empty()) q.push(make_pair(a[i],a[i]));
		else{
			int x1 = q.front().first;
			int x2 = q.front().second;
			ans += min(x1,x2);
			q.pop();
			q.push(make_pair(x1,a[i]));
			q.push(make_pair(a[i],x2));
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5516
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

int main() {
	string p;
	cin >> p;
	bool f = 0;
	for (int i = 0; i < p.size(); i++) {
		if (i % 2) {
			if (p[i] == 'L' || p[i] == 'U' || p[i] == 'D')continue;
			else {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (p[i] == 'R' || p[i] == 'U' || p[i] == 'D')continue;
			else {
				cout << "No" << endl;
				return 0;
			}
		}

	}
	cout << "Yes" << endl;

	return 0;


}

Measured memory_bytes: 256
=begin
A A A
A A A
A A A
N
b1
...
bn
=end
as1 = gets.chomp.split(" ").map(&:to_i)
as2 = gets.chomp.split(" ").map(&:to_i)
as3 = gets.chomp.split(" ").map(&:to_i)
as = as1 + as2 + as3

n = gets.chomp.to_i
bs = []

for i in (0...n) do
  bs << gets.chomp.to_i
end

bingos = Array.new(9, false)

bs.each do |b|
  if (i = as.index(b))
    bingos[i] = true
  end
end

answer = false

[
  [0,1,2],
  [3,4,5],
  [6,7,8],

  [0,3,6],
  [1,4,7],
  [2,5,8],

  [0,4,8],
  [2,4,6],
].each do |i1,j1,k1|
  if bingos[i1] && bingos[j1] && bingos[k1]
    answer = true
  end
end

if answer
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include<stdio.h>
int main(void) {
	long long int q, h, s, d, n;
	int min;
	long long int p;
	scanf("%llu%llu%llu%llu%llu", &q, &h, &s, &d, &n);

	if (q * 8 < h * 4) {
		if (q * 8 < s * 2)
		{
			if (q * 8 < d)	min = 0;
			else	min = 30;
		}
		else
		{
			if (s * 2 < d)	min = 2;
			else	min = 32;
		}
	}
	else
	{
		if (h * 4 < s * 2)
		{
			if (h * 4 < d)	min = 1;
			else	min = 31;
		}
		else
		{
			if (s * 2 < d)	min = 2;
			else	min = 32;
		}
	}

	switch (min)
	{
	case 0:
		p = q*n * 4;
		break;
	case 1:
		p = h*n * 2;
		break;
	case 2:
		p = s*n;
		break;
	case 30:
		p = d*(n / 2) + q*(n % 2) * 4;
		break;
	case 31:
		p = d*(n / 2) + h*(n % 2) * 2;
		break;
	case 32:
		p = d*(n / 2) + s*(n % 2);
		break;
	default:
		break;
	}

	printf("%llu", p);

	return 0;
}

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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (abs(x - a) < abs(x - b)) {
    cout << "A" << endl;
  }
  else {
    cout << "B" << endl;
  }
  return 0;
}

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

using namespace std;

#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
ll dp[2005];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("A.inp", "r")){
                freopen("test.inp", "r", stdin);
                freopen("test.out", "w", stdout);
        }
        ll n;
        cin >> n;
        dp[0] = 1;
        for (int i = 1; i <= n; i++){
                for (int j = 3; j <= i; j++){
                        dp[i] = (dp[i] + dp[i - j]) % mod;
                }
        }
        cout << dp[n];
}
/*
*/


Measured memory_bytes: 3632
# Aizu Problem ITP_1_10_D: Distance II
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


n = int(input())
X = [int(_) for _ in input().split()]
Y = [int(_) for _ in input().split()]
for p in range(1, 4):
    D = 0
    for i in range(n):
        D += pow(abs(X[i] - Y[i]), p)
    D = pow(D, 1 / p)
    print("%.6f" % D)
D = 0
for i in range(n):
    D = max(D, abs(X[i] - Y[i]))
print("%.6f" % D)

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

int main(){
  string S;
  cin>>S;
  int sum=0;
  for(int i=0;i<S.size();i++){
    sum+=(S.at(i)-'0');
  }
  if(sum%9==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  else {
    cout<<"No"<<endl;
    return 0;
  }
}


Measured memory_bytes: 3712
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
int main() {
    int l,r,d;
    cin >> l >> r >> d;
    int count = 0;
    for(int i=l;i<=r;i++){
        if(i%d == 0){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

int main(){
  int N;
  cin>>N;
  
  string Nstr=to_string(N);
  char current_char='a';
  int count=0;
  string good="No";
  for(char c:Nstr){
    if(current_char==c){
      count++;
      if(count>=3)
        good="Yes";
    }else{
      current_char=c;
      count=1;
    }
  }
  cout<<good<<endl;
}
  

Measured memory_bytes: 3664
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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



VB isPrime;

void Eratosthenes(int n){
    if(n + 1 <= SZ(isPrime)) return;
    isPrime.resize(n+1, true);
    isPrime[0] = isPrime[1] = false;

    for(int i = 2; i * i <= n; ++i){
        if(isPrime[i]){
            for(int j = i; i * j <= n; ++j)
                isPrime[i*j] = false;
        }
    }
}
int main(){
    int n; cin >> n;
    Eratosthenes(100003);
    for(int i = n; ; ++i){
        if(isPrime[i]){
            cout << i << endl; return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
a = [26, 702, 18278, 475254, 12356630, 321272406, 8353082582, 217180147158, 5646683826134, 146813779479510,
     3817158266467286]
b = [26, 702 - 26,
     18278 - 702, 475254 - 18278,
     12356630 - 475254, 321272406 - 12356630,
     8353082582 - 321272406, 217180147158 - 8353082582,
     5646683826134 - 217180147158, 146813779479510 - 5646683826134,
     3817158266467286 - 146813779479510]
c = 'abcdefghijklmnopqrstuvwxyz'

n = int(input())
d = 0

for i in range(11):
    if n < a[i] +1:
        d = i
        break

if d == 0:
    print(c[n-1])
    exit(0)

cnt = [0] * (d+1)
n -= a[d-1] +1

for i in range(d):
    cnt[i] = n // (b[d-1 - i])
    n = n-cnt[i]*(b[d-1-i])

cnt[d] = n

for i in range(d+1):
    if i == d:
        print(c[cnt[i]])
    else:
        print(c[cnt[i]],end="")


Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
int main(){
    int cnt=0;
    string a,b;cin >> a>>b;
    fo(i,a.size()){
        if(a[i]!=b[i]){++cnt;}
    }
    cout << cnt;
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
 
const ll INF = 2e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod){ll x=1;while(b){while(!(b&1)){(a*=a)%=mod;b>>=1;}(x*=a)%=mod;b--;}return x;}
void YES(bool cond){ if(cond){ p("YES");}else{ p("NO");} return;}
void Yes(bool cond){ if(cond){ p("Yes");}else{ p("No");} return;}


ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}


bool multicase = false;

ll n,m,num,a,b,c,d,e,h,q;
ll w, k, ans;

ll x[500005], y[500005], z[500005];
ll dp[5005][5005];
string s;

ll mul(ll a, ll b){
    if(b == 0)return 0;
    if(a > INF / b){
        return INF;
    }else{
        return a * b;
    }
}

void solve(){
    cin >> n;
    ll res = 1;
    for(ll i=0;i<n;i++){
        cin >> x[i];
        res = mul(res, x[i]);
    }
    if(res > 1000000000000000000ll){
        p(-1);
    }else{
        p(res);
    }
    
    return;
}


int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if(multicase){
        cin >> q;
    }else{
        q = 1; 
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}
















Measured memory_bytes: 4440
import sys

readline = sys.stdin.buffer.readline

K, T = map(int, readline().split())
A = sorted(list(map(int, readline().split())))[::-1]

B = [-1 for _ in range(K)]

j = 0
for i, a in enumerate(A):
    for _ in range(a):
        if j <= K // 2 - 1:
            B[2 * j] = i
        else:
            B[2 * (j - K // 2) - 1] = i
        j += 1

cnt = 0
for i in range(1, K):
    if B[i - 1] == B[i]:
        cnt += 1

print(cnt)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N, K, H[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;
    rep(i, 0, N) cin >> H[i];

    int ans = 0;
    rep(i, 0, N) if (K <= H[i]) ans++;
    cout << ans << endl;
}








Measured memory_bytes: 640
import itertools
import collections
A = [list(map(int, input().split())) for i in range(3)]
A2 = list(itertools.chain.from_iterable(A))
N = int(input())
B = [list(map(int, input().split())) for i in range(N)]
B2 = list(itertools.chain.from_iterable(B))
cnt = collections.Counter(B2)

bingo = [0] * 9

for i in range(len(A2)):
    if cnt[A2[i]] == 0:
        continue
    else:
        bingo[i] = 1

if sum(bingo) < 3:
    print('No')
    exit()
elif (bingo[0] == 1 and bingo[1] == 1 and bingo[2] == 1):
    print('Yes')
elif (bingo[0] == 1 and bingo[4] == 1 and bingo[8] == 1):
    print('Yes')
elif (bingo[0] == 1 and bingo[3] == 1 and bingo[6] == 1):
    print('Yes')
elif (bingo[1] == 1 and bingo[4] == 1 and bingo[7] == 1):
    print('Yes')
elif (bingo[2] == 1 and bingo[5] == 1 and bingo[8] == 1):
    print('Yes')
elif (bingo[2] == 1 and bingo[4] == 1 and bingo[6] == 1):
    print('Yes')
elif (bingo[3] == 1 and bingo[4] == 1 and bingo[5] == 1):
    print('Yes')
elif (bingo[6] == 1 and bingo[7] == 1 and bingo[8] == 1):
    print('Yes')
else:
    print('No')


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

int main(void) {
	int *arr, x, i;
    int max, min;
    long sum;
	
	scanf("%d", &x);
	arr=(int*)malloc(sizeof(int)*x);
	for(i=0;i<x;i++)
	  scanf("%d", &arr[i]);
	
		max=arr[0];
		min=arr[0];
		sum=arr[0];
		
	for(i=0; i<x-1; i++)
	{
         if(arr[i]<arr[i+1] && max<arr[i+1])
        max=arr[i+1];
      	
      	 if(arr[i]>arr[i+1] && min>arr[i+1])
      	min=arr[i+1];
      	
      	sum+=arr[i+1];
	}
	
	printf("%d %d %li\n", min, max, sum);
	free(arr);
	
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P=pair<int,int>;
int main(){
  int N,M;
  cin>>N>>M;
  
  int ans=0;
  ans+=N*(N-1)/2;
  ans+=M*(M-1)/2;
  cout<<ans<<endl;

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

H, W = mi()
C = li2(10)
a = li2(H)
memo = [C[i][1] for i in range(10)]
'''
tmp = -1
def dfs(column, m):
    if column == 1:
        global tmp
        tmp = max(m, tmp)
    for i in range(10):
        if i != column and C[column][i] < m:
            dfs(i, m-C[column][i])
    #return

for i in range(10):
    if i != 1:
        dfs(i, C[i][1])
        if tmp != -1:
            memo[i] = C[i][1] - tmp
        tmp = -1
'''
INF = 10**9
tmp = 10**9
'''
def dfs(col, m):
    if col == 1:
        global tmp
        tmp = min(m, tmp)
    for i in range(10):
        if i != col and m + C[col][i] < lim:
            dfs(i, m + C[col][i])

for i in range(10):
    if i != 1:
        tmp = INF
        lim = C[i][1]
        dfs(i, 0)
        memo[i] = min(tmp, memo[i])
'''
from collections import deque
for i in range(10):
    que = deque()
    lim = C[i][1]
    for j in range(10):
        if C[i][j] < lim:
            que.append([j, C[i][j]])
    while que != deque():
        #print(que)
        k = que.popleft()
        for j in range(10):
            if C[k[0]][j] + k[1] < lim and k[0] != j:
                if j == 1:
                    memo[i] = min(memo[i], C[k[0]][j] + k[1])
                else:
                    que.append([j, C[k[0]][j] + k[1]])

ans = 0
for i in range(H):
    for j in range(W):
        if abs(a[i][j]) != 1:
            ans += memo[a[i][j]]

print(ans)

Measured memory_bytes: 3956
import math
import collections

n=int(input())
a=[list(input()) for i in range(n)]
b=[str(sorted(list(i))) for i in a]
count=list(collections.Counter(b).values())
count=[i for i in count if i>1]
print(int(sum([math.factorial(x)/(math.factorial(x-2)*2) for x in count])))


Measured memory_bytes: 45716
#include<cstdio>
#include<map>
#include<cmath>
#include<vector>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=101101;
int a[N];
int n,m;
map<int,int>st;
int main(){
	int x,y;
	ll sum=0;
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		scanf("%d",&a[i]),st[a[i]]++,sum=sum+a[i];
	scanf("%d",&m);
	for (int i=1; i<=m; i++){
		scanf("%d%d",&x,&y);
		sum=sum+1ll*st[x]*(y-x);
		st[y]=st[y]+st[x];
		st[x]=0;
		printf("%lld\n",sum);
	}
    return 0;
}

Measured memory_bytes: 8096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    cout << S.substr(0,3) << '\n';
}

Measured memory_bytes: 3656
import sys
c = input()
n = len(c)
for i in range(int((n-1)/2)):
    if c[i] != c[-(i+1)]:
        print("No") 
        sys.exit()
temp = c[:int((n-1)/2)]
l_temp = len(temp)
for i in range(int((l_temp/2))):
    if temp[i] != temp[-(i+1)]:
        print("No") 
        sys.exit()
temp = c[int((n+3)/2)-1:]
l_temp = len(temp)
for i in range(int((l_temp/2))):
    if temp[i] != temp[-(i+1)]:
        print("No") 
        sys.exit()
print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int x, n;
	cin >> x >> n;
	vector<int> p(n);
	for(int i = 0; i < n; ++i){ cin >> p[i]; }
	sort(p.begin(), p.end());
	int best = -1000000000;
	for(int i = x - n - 1; i <= x + n + 1; ++i){
		if(binary_search(p.begin(), p.end(), i)){ continue; }
		const int d0 = abs(i - x);
		const int d1 = abs(best - x);
		if(d0 < d1){ best = i; }
	}
	cout << best << endl;
	return 0;
}



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

int main(){
	char pass[21];
	int len;
	int c1,c2,c3,c4;

	while(cin >> pass){
		len = strlen(pass);
		c1 = 1; c2 = 1; c3 = 1; c4 = 1;
		if(len >= 6){
			c4 = 0;
		}

		for(int i = 0; i < len; i++){
			if(pass[i] >= '0' && pass[i] <= '9'){
				c1 = 0;
			}
			if(pass[i] >= 'a' && pass[i] <= 'z'){
				c2 = 0;
			}
			if(pass[i] >= 'A' && pass[i] <= 'Z'){
				c3 = 0;
			}
		}

		if(c1 || c2 || c3 || c4) cout << "INVALID" << endl;
		else cout << "VALID" << endl;
	}
}

Measured memory_bytes: 1136
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>x;
        y+= x;
    }
    if(y>n)
        cout<<-1<<endl;
    else cout<<n-y<<endl;
    return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    string ans = "";
    int n = s.length();
    for(int i = 8;i < n; i++){
        ans += s[i];
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
using namespace std;
const long long N = 1e10 + 7;
const int maxn = 2e5 + 5;
const long long INF = 8e18;
typedef long long ll;
#define for0(i,n) for(int i = 0;i < n;i++)
#define for1(i,n) for(int i = 1;i <= n;i++)


int main()
{
    int a,b,c,n;
    cin >> a >> b >> c >> n;
    while(n && a >= b){
        b *= 2;
        n--;
    }
    while(n && b >= c){
        c *= 2;
        n--;
    }
    if(b > a && c > b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	int[][][] cost;
	boolean[] visit;
	int[] ans;
	int m;
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			m = scan.nextInt();
			if(n == 0 && m == 0){
				break;
			}
			cost = new int[2][m][m];
			for(int i = 0;i < m;i++){
				Arrays.fill(cost[0][i],10000);
				Arrays.fill(cost[1][i], 10000);
			}
			for(int i = 0;i < n;i++){
				int a = scan.nextInt() - 1;
				int b = scan.nextInt() - 1;
				int tcost = scan.nextInt();
				int time = scan.nextInt();
				cost[0][a][b] = tcost;
				cost[0][b][a] = tcost;
				cost[1][b][a] = time;
				cost[1][a][b] = time;
			}
			int k = scan.nextInt();
			visit = new boolean[m];
			ans = new int[m];
			for(int i = 0;i < k;i++){
				int p = scan.nextInt() - 1;
				int q = scan.nextInt() - 1;
				int r = scan.nextInt();
				Arrays.fill(visit, false);
				Arrays.fill(ans,10000000);
				dijkstra(p,r);
				System.out.println(ans[q]);
			}
		}
	}
	public void dijkstra(int start,int r){
		ans[start] = 0;
		while(true){
			int min = 10000000;
			int next = -1;
			for(int u = 0;u < m;u++){
				if(visit[u]){
					continue;
				}
				ans[u] = Math.min(ans[u],ans[start]+cost[r][start][u]);
				if(ans[u] < min){
					min = ans[u];
					next = u;
				}
			}
			visit[start] = true;
			start = next;
			if(start == -1){
				break;
			}
		}
	}
}

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

using namespace std;

int a[55], b[55];
int n, m;
int x[55], y[55];

int dist(int a, int b, int i) {
  return abs(a - x[i]) + abs(b - y[i]);
}

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &a[i], &b[i]);
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &x[i], &y[i]);
  }
  for (int i = 0; i < n; ++i) {
    int mn = 0;
    for (int j = 1; j < m; ++j) {
      if (dist(a[i], b[i], mn) > dist(a[i], b[i], j)) {
        mn = j;
      }
    }
    printf("%d\n", mn + 1);
  }
  return 0;
}


Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim.**/
#include<bits/stdc++.h>
using namespace std;
typedef long long int            ll;
typedef long double              ld;
#define Faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi                 acos(-1);
#define test        int t; cin>>t; while(t--)
//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());
//cin.getline(array,size);
int main()
{
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    Faster
    int n;
    cin>>n;
    while(n--)
        cout<<"ACL";
    cout<<endl;
    
    #ifndef ONLINE_JUDGE
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	string s;
	cin>> n >> k;
	cin >> s;
	s[k-1] -= 'A'-'a';
	
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll n; cin >> n;
	ll a[100001] = {};

	rep(i, 0, n) {
		cin >> a[i];
	}
	sort(a, a + n);

	ll maxV = a[n - 1];

	ll distance = 1 << 29;
	ll middleValue = 0;
	if (maxV % 2 == 0) {
		rep(i, 0, n) {
			if (distance > abs(maxV / 2 - a[i])) {
				distance = abs(maxV / 2 - a[i]);
				middleValue = a[i];
			}
		}
	}
	else {
		rep(i, 0, n) {
			ll x = abs(maxV / 2 - a[i]);
			ll y = abs((maxV / 2 + 1) - a[i]);
			x = (x > y) ? y : x;

			if (distance > x) {
				distance = x;
				middleValue = a[i];
			}
		}
	}

	cout << maxV << " " << middleValue << endl;
	return 0;
}

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

#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;

int BIG = 1000000007;

int main() {
  long N, K, result;
  cin >> N >> K;
  result = 0;
  int memo[N + 10];
  memo[0] = 0;
  rep(i, N + 1) {
    memo[i + 1] = (memo[i] + N - i - (i) + BIG) % BIG;
    // cout << memo[i + 1] << endl;
  }

  //   cout << memo[N + 1] << endl;

  for (int i = K; i <= N + 1; i++) {
    result = (result + memo[i] + 1) % BIG;
    // cout << result << endl;
  }

  cout << result << endl;
}

Measured memory_bytes: 4376
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr int N_MAX = 200000;

int n;
vector<int> a(N_MAX), graph[N_MAX], ans(N_MAX);
vector<int> lis(N_MAX+1, INF);
stack<Pii> st;

void dfs(int node, int par) {
    auto itr = lower_bound(lis.begin(), lis.end(), a[node]);
    st.emplace(int(itr - lis.begin()), *itr);
    *itr = a[node];
    ans[node] = lower_bound(lis.begin(), lis.end(), INF) - lis.begin();

    for(int child: graph[node]) {
        if(child == par) continue;
        dfs(child, node);
    }

    Pii p = st.top(); st.pop();
    lis[p.first] = p.second;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    for(int i=0;i<n;++i) {
        cin >> a[i];
    }

    int u, v;
    for(int i=0;i<n-1;++i) {
        cin >> u >> v;
        --u; --v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(0, -1);

    for(int i=0;i<n;++i) cout << ans[i] << endl;
}


Measured memory_bytes: 35324
#include <iostream>
#include <vector>

int main(void){
    int N;
    std::cin >> N;
    std::vector<int> D(N);
    for (int i = 0; i < N; i++){
        std::cin >> D[i];
    }

    int sum_recovery = 0;
    for(int i = 0; i < N; i++){
        for (int j = i + 1; j < N; j++){
            sum_recovery += D[i] * D[j];
        }
    }

    std::cout << sum_recovery << std::endl;

    return 0;
}

Measured memory_bytes: 384
awk 'NR==1{
    n = $1
    d = $2
}
NR > 1 {
    for (i = 1; i <= d; ++i) X[(NR-1) * d + i] = $i;
}
END {
    ans = 0
    for (i=1; i<=n; ++i) {
        for (j=1; j<i; ++j) {
            norm = 0;
            for (k=1; k<=d; ++k) {
                norm += (X[i*d+k] - X[j*d+k]) * (X[i*d+k] - X[j*d+k])
            }
            rt = int(sqrt(norm + 0.5))
            if (rt * rt == norm) ans++;
        }
    }
    print ans
}'


Measured memory_bytes: 552
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define double long double
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
#define PI 3.141592653589793238
using namespace std;
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1 == 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int a, b, h, m;
        cin >> a >> b >> h >> m;
        h = h * 60 + m;
        double hangle = h /2.0;
        double mangle = m * 6;
        double angle = fmod(abs(hangle - mangle),360);
        if (angle >= 180) {
            angle = 360 - angle;
        }
        angle = (angle * PI) / 180.0;
        double ans = a*a + b*b - (2 * a * b * cos(angle));
        cout << setprecision(20) << sqrt(ans) << endl;
    }
    return 0;
}


Measured memory_bytes: 4176
#include <iostream>
using namespace std;
bool has3(int x){
    while(x){
        if(x % 10 == 3) return true;
        x /= 10;
    }
    return false;
}
void call(int n){
    for (int x = 1; x <= n; x++){
        if (x % 3 == 0 || has3(x)) cout << " " << x;
    }
    cout << endl;
}
int main(){
    int n;
    cin >> n;
    call(n);
    
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>

using namespace std;

class ttime{
public:
	int h,m,s;
};

int main(){

	ttime as,af,bs,bf,cs,cf;
	cin >> as.h >> as.m >> as.s >> af.h >> af.m >> af.s;
	cin >> bs.h >> bs.m >> bs.s >> bf.h >> bf.m >> bf.s;
	cin >> cs.h >> cs.m >> cs.s >> cf.h >> cf.m >> cf.s;
	
	int amin = (af.h)*60*60 + (af.m)*60 + af.s - ((as.h)*60*60 + (as.m)*60 + as.s);
	int bmin = (bf.h)*60*60 + (bf.m)*60 + bf.s - ((bs.h)*60*60 + (bs.m)*60 + bs.s);
	int cmin = (cf.h)*60*60 + (cf.m)*60 + cf.s - ((cs.h)*60*60 + (cs.m)*60 + cs.s);

	ttime retA;
	retA.h = amin / 3600;
	retA.m = (amin % 3600) / 60;
	retA.s = (amin % 3600) % 60;
	ttime retB;
	retB.h = bmin / 3600;
	retB.m = (bmin % 3600) / 60;
	retB.s = (bmin % 3600) % 60;
	ttime retC;
	retC.h = cmin / 3600;
	retC.m = (cmin % 3600) / 60;
	retC.s = (cmin % 3600) % 60;

	cout << retA.h << " " << retA.m << " " << retA.s << endl;
	cout << retB.h << " " << retB.m << " " << retB.s << endl;
	cout << retC.h << " " << retC.m << " " << retC.s << endl;

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int operate(int num, string way, int count, vector<vector<int>>& stone_place, int& get_num, vector<int>& robot)
{
	if(way == "N"){
		for(int i = 0; i < num; i++){
			if(stone_place[i][0] == robot[0] && robot[1] <= stone_place[i][1] && stone_place[i][1] <= robot[1] + count){
				get_num += 1;
				stone_place[i] = { -1, -1 };
			}
		}
		robot[1] += count;
	}else if(way == "S"){
		for(int i = 0; i < num; i++){
			if(stone_place[i][0] == robot[0] && robot[1] - count <= stone_place[i][1] && stone_place[i][1] <= robot[1]){
				get_num += 1;
				stone_place[i] = { -1, -1 };
			}
		}
		robot[1] -= count;
	}else if(way == "E"){
		for(int i = 0; i < num; i++){
			if(stone_place[i][1] == robot[1] && robot[0] <= stone_place[i][0] && stone_place[i][0] <= robot[0] + count){
				get_num += 1;
				stone_place[i] = { -1, -1 };
			}
		}
		robot[0] += count;
	}else if(way == "W"){
		for(int i = 0; i < num; i++){
			if(stone_place[i][1] == robot[1] && robot[0] - count <= stone_place[i][0] && stone_place[i][0] <= robot[0]){
				get_num += 1;
				stone_place[i] = { -1, -1 };
			}
		}
		robot[0] -= count;
	}
	return 0;
}

int main(void)
{
	int num, step, get_num;
	vector<int> robot;

	while(1){
		robot = { 10, 10 };
		get_num = 0;
		cin >> num;
		if(num == 0)
			break;

		vector<vector<int>> stone_place;
		stone_place = vector<vector<int>>(num, vector<int>(2));
		for(int i = 0; i < num; i++){
			cin >> stone_place[i][0] >> stone_place[i][1];
		}

		cin >> step;
		for(int i = 0; i < step; i++){
			string way;
			int count;

			cin >> way >> count;
			operate(num, way, count, stone_place, get_num, robot);
		}
		
		if(get_num >= num)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3204
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[3001][3001];

ll solve(ll sum,ll arr[],ll start,ll end){
	if(start>end)
		return 0;
	if(start==end)
		return arr[start];
	if(dp[start][end]!=-1)
		return dp[start][end];
	
	ll op1=sum-solve(sum-arr[start],arr,start+1,end);
	ll op2=sum-solve(sum-arr[end],arr,start,end-1);
	dp[start][end]=max(op1,op2);
	return dp[start][end];
}

int main(){
	ll N;
	cin>>N;
	ll arr[N];
	ll sum=0;
	for(ll i=0;i<N;i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	for(ll i=0;i<=N;i++){
		for(ll j=0;j<=N;j++){
			dp[i][j]=-1;
		}
	}
	cout<<2*solve(sum,arr,0,N-1)-sum<<endl;
	
}

Measured memory_bytes: 74176