akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template <typename V>
struct fhnode {
	V val;
	fhnode *l, *r, *p, *c;
	int deg;
	bool m;
	template <typename ...T>
	fhnode(T &&...t) :val(t...), deg(0), m(false),
		l(this), r(this), p(nullptr), c(nullptr) {}
};
template <typename V, typename P = less<>>
class FibHeap {
	fhnode<V> root, *min;
	int size_;
	P pr;
public:
	typedef fhnode<V> *ptr;
	FibHeap() :size_(0) {}
	~FibHeap() {
		queue<ptr> q;
		q.push(&root);
		while (!q.empty()) {
			ptr r = q.front();
			q.pop();
			for (ptr p = r->r; p != r;) {
				if (p->c != nullptr)
					q.push(p->c);
				p = p->r;
				delete p->l;
			}
			if (r != &root)
				delete r;
		}
	}
	int size() const { return size_; }
	bool empty() const { return !size_; }
	const V &top() const { return min->val; }
	template <typename ...T>
	ptr push(T &&...t) {
		ptr m = new fhnode<V>(t...);
		root.r->l = m;
		m->r = root.r;
		root.r = m;
		m->l = &root;
		if (!size_ || pr(m->val, min->val))
			min = m;
		size_++;
		return m;
	}
	void merge(FibHeap &h) {
		merge(move(h));
	}
	void merge(FibHeap &&h) {
		root.r->l = h.root.l;
		h.root.l->r = root.r;
		root.r = h.root.r;
		h.root.r->l = &root;
		h.root.r = &h.root;
		if (h.size_ && (!size_ || pr(h.min->val, min->val)))
			min = h.min;
		size_ += h.size_;
	}
	void pop() {
		size_--;
		//1
		if (min->c == nullptr) {
			min->l->r = min->r;
			min->r->l = min->l;
		}
		else {
			for (ptr p = min->c->r; p != min->c; p = p->r)
				p->p = nullptr, p->m = false;
			min->l->r = min->c->r;
			min->c->r->l = min->l;
			min->r->l = min->c->l;
			min->c->l->r = min->r;
		}
		delete min->c, delete min;
		//2
		ptr deg[48] = {};
		for (ptr p = root.r; p != &root; p = p->r) {
			int d = p->deg;
			if (deg[d] == nullptr)
				deg[d] = p;
			if (deg[d] == p)
				continue;
			ptr q = p, r = deg[d];
			if (pr(r->val, q->val))
				swap(q, r), p = p->l;
			r->l->r = r->r;
			r->r->l = r->l;
			r->p = q;
			if (!d) q->c = new fhnode<V>;
			q->c->r->l = r;
			r->r = q->c->r;
			q->c->r = r;
			r->l = q->c;
			deg[d] = nullptr;
			deg[d + 1] = q;
			q->deg++;
		}
		//3
		min = root.r;
		for (ptr p = root.r; p != &root; p = p->r)
			if (pr(p->val, min->val))
				min = p;
	}
	template <typename ...T>
	void dec(ptr p, T &&...t) {
		dec(p, V(t...));
	}
	void dec(ptr p, V &&t) {
		if (pr(p->val, t))
			return;
		p->val = t;
		if (p->p == nullptr || !pr(p->val, p->p->val))
			return;
		ptr q = root.r;
		do {
			p->l->r = p->r;
			p->r->l = p->l;
			if (!--p->p->deg)
				delete p->r, p->p->c = nullptr;
			q->l = p;
			p->r = q;
			if (pr(p->val, min->val))
				min = p;
			q = p;
			p = p->p;
			q->p = nullptr;
			q->m = false;
		} while (p->m);
		if (p->p != nullptr)
			p->m = true;
		q->l = &root;
		root.r = q;
	}
};

int a[111111];
int main() {
	int n, m;
	cin >> n >> m;
	FibHeap<pair<int, int>, greater<>> q;
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
		q.push(a[i], i);
	}
	for (int i = 0; i < m; i++) {
		int x = q.top().second;
		q.pop();
		q.push(a[x] /= 2, x);
	}
	long r = 0;
	for (int i = 0; i < n; i++)
		r += a[i];
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 10368
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		String ans;
		String ans2;
		int answer = 0;
		for(int i = 1; i < str.length()+1; i++){
			ans = str.substring(0, str.length()-i);
			if(ans.length() % 2 == 0){
				if(ans.substring(0, ans.length()/2).equals(ans.substring(ans.length()/2, ans.length()))){
					answer = ans.length();
					break;
				}
			}
		}
		System.out.println(answer);

	}

}


Measured memory_bytes: 21844
import math

N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'

input()
d = None
u = set()
for x in map(int, input().split()):
  d = math.gcd(d or x, x);
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r = 'setwise'
    s.add(p)
    x //= p
  u |= s
print('not' if d > 1 else r, 'coprime')


Measured memory_bytes: 179332
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 

using namespace std;

int main() {
    int C[3][3];
    int b[3];

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> C[i][j];
        }
        cout << endl;
    }

    for (int a = 0; a <= 100; a++) {
        b[0] = C[0][0] - a;
        b[1] = C[0][1] - a;
        b[2] = C[0][2] - a;

        if ((C[1][0] - b[0] == C[1][1] - b[1]) && (C[1][1] - b[1] == C[1][2] - b[2])) {
            if ((C[2][0] - b[0] == C[2][1] - b[1]) && (C[2][1] - b[1] == C[2][2] - b[2])) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		for(int i = 0; i < k; i++) {
			if(i % 2 == 0) {
				if(a % 2 != 0)a--;
				a /= 2;
				b += a;
			}
			else {
				if(b % 2 != 0)b--;
				b /= 2;
				a += b;
			}
		}
		System.out.println(a + " " + b);
	}
	Main(){doIt();}
	public static void main(String[] args) {
		new Main();
	}

}


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#define P 100003
#define N 100000
using namespace std;

int main(){
    int n,counter=0;
    string s;
     
    cin >> n;
    cin >> s;

    for(int i= 0;i<n-2;i++){
        
        if(s[i] -  'A' == 0)
            if(s[i+1] - 'B' == 0)
                if(s[i+2] - 'C' == 0)
                    counter++;

            
    }

    cout <<counter;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);

  int max,min;
  if(A>C){
    max = A;
  }else{
    max = C;
  }

  if(B>D){
    min = D;
  }else{
    min = B;
  }
  
  if(max < min){
    printf("%d",min-max);
  }else{
    printf("0");
  }

  return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
const int INF = 1e9;

int h, w, k;
int sx, sy, gx, gy;
vector<vector<char>> MP;
vector<vector<int>> dis;

bool outside(int x, int y) {
	return x < 0 or x >= h or y < 0 or y >= w;
}

bool bad(int x, int y, int nd) {
	return MP[x][y] == '@' or dis[x][y] < nd;
}

void bfs() {
	queue<pair<int, int>> que;
	que.push({sx, sy});
	dis[sx][sy] = 0;
	while (!que.empty()) {
		int x = que.front().first;
		int y = que.front().second;
		que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = x, ny = y;
			int nd = dis[x][y] + 1;
			for (int j = 1; j <= k; j++) {
				nx += dir[i][0];
				ny += dir[i][1];
				if (outside(nx, ny) or bad(nx, ny, nd))
					break;
				if (dis[nx][ny] > nd) {
					que.push({nx, ny});
					dis[nx][ny] = nd;
				}
			}
		}
	}
}

int main() {
	cin >> h >> w >> k >> sx >> sy >> gx >> gy;
	--sx, --sy, --gx, --gy;
	MP.resize(h, vector<char>(w));
	dis.resize(h, vector<int>(w));
	for (int i = 0; i < h; i++) 
		for (int j = 0; j < w; j++)
			cin >> MP[i][j], dis[i][j] = INF;
	bfs();
	cout << (dis[gx][gy] == INF ? -1 : dis[gx][gy]);
}


Measured memory_bytes: 12044
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int b[] = new int[n - 1];

		String str[] = br.readLine().split(" ");

		for (int i = 0; i < n - 1; i++) {
			b[i] = Integer.parseInt(str[i]);
		}

		long ans = b[0] + b[(n - 1) - 1];

		for (int i = 1; i < n - 1; i++) {
			ans += Math.min(b[i - 1], b[i]);
		}

		System.out.println(ans);
	}
}

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

#define F(i, a, b) for (ll i = a; i <= b; i ++)
#define G(i, a, b) for (ll i = a; i >= b; i --)
#define out4(x, y, z, w) { if (debug) printf(#x" = "),W(x),printf(" "#y" = "),W(y),printf(" "#z" = "),W(z),printf(" "#w" = "),W(w),putc('\n'); }
#define out3(x, y, z) { if (debug) printf(#x" = "), W(x), printf(" "#y" = "), W(y), printf(" "#z" = "), W(z), putc('\n'); }
#define out2(x, y) { if (debug) printf(#x" = "), W(x), printf(" "#y" = "), W(y), putc('\n'); }
#define out1(x) { if (debug) printf(#x" = "), W(x), putc('\n'); }
#define outline(x) { if (debug) puts("-------------------------------------------"#x"----------------------------------------"); }
#define outarr(a, L, R) { if (debug) { printf(#a"[%d..%d] = ", L, R); F(i, L, R) W(a[i]), putc(' '); putc('\n'); } }
#define Assert(x) { if ((debug) && (!(x))) { puts("Wrong Answer"); exit(0); } }
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define mem(a, b) memset(a, b, sizeof a)
#define mec(a, b) memcpy(a, b, sizeof a)
#define mx(a, b) ((a) = max(a, b))
#define mn(a, b) ((a) = min(a, b))
#define lowbit(x) ((x) & (-(x)))
#define abs(x) ((max(x, - (x))))
#define get getchar()
#define pb push_back
#define putc putchar
#define inf 2e9

template <typename Int>
void R(Int &x) {
	char c = get; x = 0; Int t = 1;
	for (; !isdigit(c); c = get) t = (c == '-' ? - 1 : t);
	for (; isdigit(c); x = (x << 3) + (x << 1) + c - '0', c = get); x *= t;
}
template <typename Int>
void W(Int x) {
	if (x < 0) { putc('-'); x = - x ; }
	if (x > 9) W(x / 10); putc(x % 10 + '0');
}

#define debug (0)

using namespace std;

#define ll long long
const ll N = 1e5 + 10;
ll n, s, x[N], p[N];
struct node { ll s, v; };

node Dfs(ll l, ll r) {
	out2(l, r);
	outarr(p, 1, n);
	if (s <= x[l]) return {x[r], x[r] - s};
	if (s >= x[r]) return {x[l], s - x[l]};
	if (p[l] < p[r]) {
		p[r] += p[l];
		node a = Dfs(l + 1, r);
		return {x[l], a.v + a.s - x[l]};
	}
	else {
		p[l] += p[r];
		node a = Dfs(l, r - 1);
		return {x[r], a.v + x[r] - a.s};
	}
}

int main() {
//	freopen("data.in","r",stdin);

	R(n), R(s);
	F(i, 1, n) R(x[i]), R(p[i]);

	W(Dfs(1, n).v);
}

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

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

    ll n,x;
    cin >> n >> x;
    vector<ll> s(n);
    for (ll i = 0;i < n;i++){
        cin >> s[i];
    }
    vector<ll> d(n);
    for (ll i = 0;i < n;i++){
        d[i] = abs(s[i]-x);
    }
    ll ans = d[0];
    for (ll i = 1; i < n; i++){
        ans = gcd(ans,d[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int a;
    string s;
    cin >> a >> s;
    if(a >= 3200) cout << s;
    else cout << "red";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846

void solve()
{
    int n,m;cin>>n>>m;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    vector<int> adj[n];
    for(int i=0;i<m;i++)
    {
        int x,y;cin>>x>>y;
        adj[x-1].push_back(h[y-1]);
        adj[y-1].push_back(h[x-1]);
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(adj[i].size()>0){
        int hi=*max_element(adj[i].begin(),adj[i].end());
        if(h[i]>hi)
            ans++;
        }
        else
            ans++;
    }
    cout<<ans<<nl;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 10280
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL n, s;

int main()
{
	in >> n >> s;
	if (n < s)
	{
		out << -1 << std::endl;
		return 0;
	}
	if (n == s)
	{
		out << n + 1 << std::endl;
		return 0;
	}
	for (LL b = 2; b <= sqrt(n); ++b)
	{
		LL n_ = n, res = 0;
		while (n_ > 0)
		{
			res += n_ % b;
			n_ /= b;
		}
		if (res == s)
		{
			out << b << std::endl;
			return 0;
		}
	}
	LL ans = 112345678901;
	for (LL p = 1; p < sqrt(n); ++p)
	{
		LL b = (n - s) / p + 1, n_ = n, res = 0;
		if (b < 2) continue;
		while (n_ > 0)
		{
			res += n_ % b;
			n_ /= b;
		}
		if (res == s) ans = std::min(ans, b);
	}
	out << (ans == 112345678901 ? -1 : ans) << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;

char s[MAXN+1]; int n;

ll solve() {
	int na=0; bool haveb=false; ll ret=0;
	REP(i,n) {
		if(!haveb) {
			if(s[i]=='A') {
				++na;
			} else if(s[i]=='B') {
				haveb=true;
			} else if(s[i]=='C') {
				na=0,haveb=false;
			}
		} else {
			if(s[i]=='A') {
				na=1,haveb=false;
			} else if(s[i]=='B') {
				na=0,haveb=true;
			} else if(s[i]=='C') {
				ret+=na,haveb=false;
			}
		}
	}
	return ret;
}

void run() {
	scanf("%s",s); n=strlen(s);
	printf("%lld\n",solve());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,a,b,x=0,count=0;
  while(1){
    cin >> n;
    if(n == 0) break;
    cin >> m;
    int data[n][n];
    int str[501]={0};
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	data[i][j]=0;
      }
    }
    for(int i=0;i<m;i++){
      cin >> a >> b;
      data[a-1][b-1]++;
      data[b-1][a-1]++;
      if( a == 1 ){
	str[x]=b-1;
	x++;
      } else if( b == 1){
	str[x]=a-1;
	x++;
      }
    }
    for(int i=0;i<x;i++){
      for(int j=1;j<n;j++){
	if(data[str[i]][j] != 0 && data[0][j] == 0){
	  data[0][j]++;
	}
      }
    }
    for(int i=1;i<n;i++){
      if( data[0][i] != 0){
      	count++;
      }
    }
    cout << count << endl;
    count=0;
    x=0;
  }
  return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);
  ll cur = 0;
  ll res = 0;
  rep(i, n) {
    ll tmp = a.at(i);
    if (i == 0) {
      cur = tmp;
      continue;
    }
    ll add = 0;
    if (cur > tmp) {
      add = cur - tmp;
      res += add;
    }
    cur = tmp + add;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4784
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    string S;
    cin >> S;
    int Q;
    scanf("%d\n", &Q);
    int T[200000];
    int F[200000];
    char C[200000];
    for(int i=0; i<Q; i++){
        scanf("%d", &T[i]);
        if(T[i] == 2){
            scanf("%d %c", &F[i], &C[i]);
        }
    }

    string top;
    string bottom;
    bool rev = false;
    for(int i=0; i<Q; i++){
        if(T[i] == 1){
            rev = !rev;
            continue;
        }else{
            if(F[i] == 1){
                if(!rev){
                    top = C[i] + top;
                }else{
                    bottom = bottom + C[i];
                }
            }else{
                if(!rev){
                    bottom = bottom + C[i];
                }else{
                    top = C[i] + top;
                }
            }
        }
    }

    string ans;
    if(!rev){
        ans = top + S + bottom;
    }else{
        reverse(top.begin(), top.end());
        reverse(S.begin(), S.end());
        reverse(bottom.begin(), bottom.end());
        ans = bottom + S + top;
    }


    cout << ans << "\n";
    return 0;
    
}

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

int main(){
  int n;
  long double ans;
  cin>>n;
  vector<long double> v(n,0);
  REP(i,n) cin>>v.at(i);
  sort(v.begin(),v.end());
  REP(i,n-1) v.at(i+1)=(v.at(i)+v.at(i+1))/2;
  ans = v.at(n-1);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001
 
#define ad(x) int i = 100;
typedef long long ll;


int nums[4];

int main() {
    
    char op[2];
    op[0] = '+';
    op[1] = '-';
    
    int s;
    cin >> s;
    for(int i = 3; i >= 0; i--) {
        nums[i] = s  % 10;
        s /= 10;
    }

// REP(i,0,4) cout << nums[i] << endl;

if (nums[0] + nums[1] + nums[2] + nums[3]==7) printf("%d+%d+%d+%d=7",nums[0],nums[1],nums[2],nums[3]); 
else if (nums[0] + nums[1] + nums[2] - nums[3]==7) printf("%d+%d+%d-%d=7",nums[0],nums[1],nums[2],nums[3]);
else if (nums[0] + nums[1] - nums[2] + nums[3]==7) printf("%d+%d-%d+%d=7",nums[0],nums[1],nums[2],nums[3]);
else if (nums[0] + nums[1] - nums[2] - nums[3]==7) printf("%d+%d-%d-%d=7",nums[0],nums[1],nums[2],nums[3]);
else if (nums[0] - nums[1] + nums[2] + nums[3]==7) printf("%d-%d+%d+%d=7",nums[0],nums[1],nums[2],nums[3]);
else if (nums[0] - nums[1] + nums[2] - nums[3]==7) printf("%d-%d+%d-%d=7",nums[0],nums[1],nums[2],nums[3]);
else if (nums[0] - nums[1] - nums[2] + nums[3]==7) printf("%d-%d-%d+%d=7",nums[0],nums[1],nums[2],nums[3]);
else if (nums[0] - nums[1] - nums[2] - nums[3]==7) printf("%d-%d-%d-%d=7",nums[0],nums[1],nums[2],nums[3]);
    
    
    // REP(i,0,2) REP(j,0,2) REP(k,0,2) {
    //     printf("if (nums[0] %c nums[1] %c nums[2] %c nums[3]==7) ",op[i],op[j],op[k]);
    //     printf("printf(\"%%d%c%%d%c%%d%c%%d=7\",nums[0],nums[1],nums[2],nums[3]); return 0;\n",op[i],op[j],op[k]);
        // printf("nums[0] %c nums[1] %c nums[2] %c nums[3]=7\n",op[i],op[j],op[k]);
        // if (nums[0] + nums[1] + nums[2] + nums[3]==7 || nums[0] + nums[1] + nums[2] - nums[3]==7 || nums[0] + nums[1] - nums[2] + nums[3]==7 || nums[0] + nums[1] - nums[2] - nums[3]==7 || nums[0] - nums[1] + nums[2] + nums[3]==7 || nums[0] - nums[1] + nums[2] - nums[3]==7 || nums[0] - nums[1] - nums[2] + nums[3]==7 || nums[0] - nums[1] - nums[2] - nums[3]==7){
        //     printf("%d%c%d%c%d%c%d=7",nums[0],op[i],nums[1],op[j],nums[2],op[k],nums[3]);
        //     break;
        // }
    // }
}

Measured memory_bytes: 256
from collections import deque

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n = int(input())
a = [int(i) for i in input().split()]

left_gcd = deque()
left_gcd.append(0)
right_gcd = deque()
right_gcd.append(0)

for i in range(n):
    left_gcd.append(gcd(left_gcd[-1], a[i]))
    right_gcd.appendleft(gcd(right_gcd[0], a[(n - 1) - i]))

max_gcd = 0

for i in range(n):
    get_gcd = gcd(left_gcd[i], right_gcd[i + 1])
    if get_gcd > max_gcd:
        max_gcd = get_gcd

print(max_gcd)


Measured memory_bytes: 14436
N, M = map(int, input().split())
anlist=[]
for a in map(int, input().split()):
    anlist.append([1,a])
for _ in range(M):
    anlist.append(list(map(int, input().split())))
anlist=sorted(anlist, key=lambda x: x[1], reverse=True)
cnt = 0
ans = 0
for b, c in anlist:
    if cnt + b > N:
        ans += c*(N-cnt)
        break
    else:
        ans +=b*c
        cnt += b
print(ans)

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


int main(){
    int64_t  n, x, t, ans = 0;
    cin >> n >> x >> t;
    if(n % x == 0){
        ans = (n / x) * t;
    }else{
        ans = (n / x + 1) * t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int a, b, ans;
	scanf("%d%d", &a, &b);
	ans = (a*b) > (a + b) ? (a*b) : (a + b);
	ans = ans > (a - b) ? ans : (a - b);
	printf("%d", ans);
	return 0;
}

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

int main(){
    int n;
    int a[300000];
    cin>>n;
    for(int i=0; i<3*n; i++) cin>>a[i];
    multiset<int, greater<int> > fn, s;
    long long int sumf=0, sums=0;
    {
        int ta[200000];
        for(int i=0; i<2*n; i++) ta[i]=a[i];
        sort(ta, ta+2*n, greater<int>());
        for(int i=0; i<n; i++) sumf+=ta[i];
        for(int i=n; i<2*n; i++) fn.insert(ta[i]);
    }
    for(int i=2*n; i<3*n; i++){
        sums+=a[i];
        s.insert(a[i]);
    }

    long long int ans=sumf-sums;
    for(int i=2*n-1; i>=n; i--){
        if(a[i] > *(fn.begin())){
            sumf=sumf-a[i]+ *(fn.begin());
            fn.erase(fn.begin());
        }
        else{
            fn.erase(fn.find(a[i]));
        }
        if(a[i]< *(s.begin())){
            sums=sums- *(s.begin()) +a[i];
            s.erase(s.begin());
            s.insert(a[i]);
        }
        ans=max(ans, sumf-sums);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 11520
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int N,a=0,b=0;
  string s;
  cin>>N>>s;
  for(int i=0;i<N;i++){
    if(s[i]=='R') a++;
    else b++;
  }
  if(a>b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

using namespace std;

long long MOD = 1e9+7;

struct block {
  int w;
  int s;
  long long v;
};

int main() {
  // X: sort, and then do a DP like LIS (i.e. involving bsearch)
  int n; cin >> n;
  vector<block> blocks(n);
  for(int i = 0; i<n; ++i) {
    cin >> blocks[i].w >> blocks[i].s >> blocks[i].v;
  }
  sort(blocks.begin(), blocks.end(), 
      [](const block& b1, const block& b2) {
        return b1.s+b1.w < b2.s+b2.w;
      });
  // do we care if two blocks have the same weight?  I think
  // we don't really
  long long dp[n+1][10000+2];
  for(int i = 0; i<n+1; ++i) {
    for(int j = 0; j<1e4+2; ++j) {
      dp[i][j] = -1;
    }
  }
  dp[0][0] = 0;
  long long ret = 0;
  for(int i = 0; i<n; ++i) {
    for(int j = 0; j<1e4+2; ++j) {
      // wait do we even need bsearch?
      if(dp[i][j] == -1) continue;
      // don't take this block
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
      ret = max(ret, dp[i+1][j]);

      // do take this block
      if(j <= blocks[i].s) {
        ret = max(ret, dp[i][j] + blocks[i].v);
        if(j+blocks[i].w < 1e4+2) {
          dp[i+1][j+blocks[i].w] = max(dp[i+1][j+blocks[i].w], dp[i][j] + blocks[i].v);
        }
      }
    }
  }

  cout << ret << endl;
}


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

using namespace std;
using ll = long long;
using P = pair<int, uint>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 3;
bool comp(pair<int, P> a, pair<int, P> b) {
    if(a.second.second != b.second.second){
        return a.second.second < b.second.second;
    }
    else{
        return a.first < b.first;
    }
}

void solve(){
    int N, M, Q; cin >> N >> M >> Q;
    vector< pair<int, P> > vec(M + Q);
    for(int i = 0; i < M; ++i){
        int L, R; cin >> L >> R;
        vec[i] = {0, {L, R}};
    }
    for(int i = 0; i < Q; ++i){
        int L, R; cin >> L >> R;
        vec[M + i] = {i + 1, {L, R}};
    }
    stable_sort(vec.begin(), vec.end(), comp);


    vector<int> arr(510, 0);
    vector<int> ans_arr(Q, 0);
    for(int i = 0; i < M + Q; ++i){
        int type = vec[i].first;
        if(type == 0){
            ++arr[vec[i].second.first];
        }
        else{
            int ans = 0;
            for(int j = vec[i].second.first; j <= vec[i].second.second; ++j){
                ans += arr[j];
            }
            ans_arr[type-1] = ans;
        }
    }
    for(int i = 0; i < Q; ++i){
        cout << ans_arr[i] << '\n';
    }

    return;
}





int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 7296
/* generated by esotope-bfc */
#include <stdio.h>
#include <stdint.h>
#define GETC() (fflush(stdout), fgetc(stdin))
#define PUTC(c) fputc(c, stdout)
#define PUTS(s) fwrite(s, 1, sizeof(s)-1, stdout)
static uint8_t m[30000], *p = m;
int main(void) {
	p[15] = GETC();
	++p[15];
	p[16] = 0;
	while (p[15]) {
		--p[15];
		p[16] = GETC();
		++p[16];
		++p;
	}
	while (p[9]) {
		p[9] = 49;
		p[10] = 0;
		p += 15;
		PUTS("1");
	}
	while (p[14]) {
		while (p[11]) {
			while (p[10]) {
				p[9] += 7;
				p[10] -= 7*p[9];
				p[9] = 0;
				while (p[10]) {
					p[9] += 7;
					p[8] += 7*p[9];
					p[9] = 0;
					PUTC(p[8]);
					p += 8;
				}
				while (p[11]) {
					p[11] += 10;
					--p;
				}
				++p;
			}
			while (p[11]) {
				p[10] += 6;
				p[11] -= 8*p[10];
				p[9] += 6;
				p[10] = 8*p[9];
				p[9] = 0;
				p[12] -= p[10];
				p[13] -= p[10];
				p[10] = 10*p[12];
				p[12] = 0;
				if (p[13]) {
					--p[13];
					if (p[13]) {
						if ((p[13] == 0 || (5 <= p[13] && p[13] <= 255))) {
							p[10] += 5;
						}
						p[13] = 0;
					}
					p[13] = 0;
					p[10] += 5;
				}
				p[13] = 0;
				p[11] -= 205*p[10];
				p[10] = 0;
				if (p[11]) {
					if ((p[11] == 0 || (21 <= p[11] && p[11] <= 255))) {
						--p[13];
					}
					p[11] = 0;
				}
				p[11] = 0;
				p[12] += 7;
				p[13] += 7*p[12];
				p[12] = 0;
				PUTC(p[13]);
				p[13] = 0;
				p += 2;
				PUTS("\n");
			}
		}
		while (p[14]) {
			p[15] += 5*p[14]-2;
			p[14] = 0;
			PUTC(p[15]);
			p[15] = 0;
			++p;
		}
	}
	return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var x = int.Parse(input[0]);
        var y = int.Parse(input[1]);

        var MOD = 1000000007;

        var countMax = (x + y) / 3;

        if (x < countMax || y < countMax)
        {
            Console.WriteLine(0);
            return;
        }

        if ((x + y) % 3 != 0)
        {
            Console.WriteLine(0);
            return;
        }

        if (countMax == 1)
        {
            Console.WriteLine(1);
            return;
        }

        var ans = Mod.ModCombination(countMax, x - countMax, MOD);

        Console.WriteLine(ans);
        Console.ReadLine();
    }
}

class Mod
{
    public static long ModFactorial(long n, long mod)
    {
        var result = n;

        if (n > 0)
        {

            while (n > 1)
            {
                n--;
                result *= n;
                result %= mod;
            }

            return result;
        }
        else
        {
            return 1;
        }
    }

    public static long ModPow(long b, long pow, long mod)
    {
        if (pow == 1)
        {
            return b % mod;
        }

        long n = ModPow(b, pow / 2, mod) % mod;

        if (pow % 2 == 0)
        {
            return (n * n) % mod;
        }
        else
        {
            return (b * ((n * n) % mod)) % mod;
        }
    }

    public static long ModCombination(long sum, long num, long mod)
    {
        long x = 1;
        for (var i = 0; i < num; i++)
        {
            x *= (sum - i);
            x %= mod;
        }

        var result = (x * (ModPow(ModFactorial(num, mod), 1000000005, 1000000007))) % 1000000007;

        return result;
    }
}

Measured memory_bytes: 13140
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
int main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans=0;
    for(int i=0;i<n/2;i++){
      if(s[i]!=s[n-i-1])ans++;
    }
cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

long long lmin(long long a, long long b) {
    if (a > b) return b;
    else return a;
}

int main() {
    ll N; cin >> N;
    vll A(5);
    ll x = 1e15 + 1;
    rep(i, 5) {
        cin >> A[i];
        x = lmin(x, A[i]);
    }

    cout << ((N + x - 1) / x) + 4 << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;

const int MOD = 1e9+7;
vector<int> G[100005];
int dp[100005][2];
bool mark[100005][2];

void mult(int &a, int b) {
    ll aux = (ll)a*b;
    a = aux%MOD;
}

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

int dfs(int v, int p, bool s) {
    if(mark[v][s]) return dp[v][s];
    int ret = 1;
    
    for(int x : G[v]) {
        if(x == p) continue;
        int aux = dfs(x, v, 0);
        if(s == 0) add(aux, dfs(x, v, 1));
        mult(ret, aux);
    }

    mark[v][s] = true;
    return dp[v][s] = ret;
}

int main() {
    int n;
	scanf("%d", &n);
    
    for(int i = 1; i < n; i++) {
        int a,b;
        scanf("%d%d", &a, &b);
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int ans = dfs(1,1,0) + dfs(1,1,1);

    printf("%d\n", ans%MOD);
	
    return 0;
}

Measured memory_bytes: 15104
#include <vector>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cassert>
#include <cstring>
#include <sys/time.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[]){
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if(a1+a2+a3>=22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

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

    int ans = 1e9;

    for(int i = 0; i <= 2*max(x, y); i += 2)
    {
        int j = i/2;
        int sum = c*i;
        if(x - j > 0) sum += (x - j)*a;
        if(y - j > 0) sum += (y - j)*b;
        ans = min(ans, sum);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

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

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

	vll c(N, 0);
	rep(i, N - 1){
		ll x, y, a;
		cin >> x >> y >> a;
		c[x] ^= a;
		c[y] ^= a;
	}

	ll M = 16;

	vll cnt(M, 0);
	rep(i, N)cnt[c[i]]++;

	ll comp = 0;
	ll X = 0;
	comp += cnt[0];

	repn(i, M - 1) {
		comp += cnt[i] / 2;
		if (cnt[i] % 2 == 1) { X += 1 << i; }
	}

	vll zero(1 << M, 0);
	rep(i, 1 << M) {
		ll t = 0;
		rep(j, M) {
			if ((i >> j) & 1) { t ^= j; }
		}
		if (t == 0) { zero[i] = 1; }
	}

	vll dp(1 << M, 0);
	repn(i, (1 << M) - 1) {
		for (ll j = i; j > 0; j = (j - 1) & i) {
			if (zero[j] == 0) { continue; }
			ll k = i & ~j;
			dp[i] = max(dp[i], dp[k] + 1);
		}
	}

	comp += dp[X];

	cout << N - comp << endl;

}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
uint64_t bits_msb(uint64_t v) {
  v = v | (v >>  1);
  v = v | (v >>  2);
  v = v | (v >>  4);
  v = v | (v >>  8);
  v = v | (v >> 16);
  v = v | (v >> 32);
  return v ^ (v >> 1);
}
int main() {
  uint64_t h;
  cin >> h;
  cout << bits_msb(h) * 2 - 1 << endl;
  return 0;
}

Measured memory_bytes: 256
/*
 *  Created on: 23 / 4 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n)
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)

ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ll mod = 1e9 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(20);
    Eslam__Waheed
        ss s; cin >> s;
    int a = s.find('7');
    if (a < sz(s) && a > -1)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 3648
#include <stdio.h>

int main (void)
{
long int A,B,C,D;
 scanf("%ld", &A);
 C = A;
 for(int i = 1;i<C;i++){
    if(A%i == 0){
        C = A/i;
        B = i;
        D=0;
    }
    D = D+1;
    if(D == 1000000){
        break;
    }
 }
 long int d;
 d = (B-1) + (C-1);
 printf("%ld",d);
 return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

#define mid ((tl+tr)>>1)
const int maxn = 2e5+5;
vector<int>g[maxn],a(maxn),old(maxn),ans(maxn),t(maxn<<2),all;
int n;
void update(int rt,int l,int r,int pos,int new_val){
	if(l==r){t[rt]=new_val;return;}
	if(pos<=((l+r)>>1))update(rt<<1,l,(l+r)>>1,pos,new_val);
	else update((rt<<1)+1,((l+r)>>1)+1,r,pos,new_val);
	t[rt]=max(t[rt<<1],t[(rt<<1)+1]);
}
int query(int rt,int tl,int tr,int l,int r){
	if(l>r || l==0 || r == 0)return 0;
	if(l==tl&&r==tr)return t[rt];
	return max(query(rt<<1,tl,(tl+tr)>>1,l,min(r,(tl+tr)>>1)),query((rt<<1)+1,((tl+tr)>>1)+1,tr,max(l,((tl+tr)>>1)+1),r));
}

void dfs(int u,int p){
	old[u] = query(1,1,n,a[u],a[u]);
	update(1,1,n,a[u],query(1,1,n,1,a[u]-1)+1);
	ans[u] = query(1,1,n,1,n);
	//bug4(u,a[u],old[u],ans[u]);
	for(auto v:g[u]){
		if( v != p ){
			dfs(v,u);
		}
	}
	update(1,1,n,a[u],old[u]);
}
int32_t main(){
	IOS
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		all.push_back(a[i]);
	}
	for(int i=1;i<n;i++){
		int u,v;cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	sort(all.begin(),all.end());
	all.erase(unique(all.begin(),all.end()),all.end());
	for(int i=1;i<=n;i++){
		a[i] = lower_bound(all.begin(),all.end(),a[i]) - all.begin() + 1;
		//bug2(i,a[i]);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++){
		cout << ans[i] <<" ";
	}
	cout<<endl;
	
	
}
/*
 * long long or int?
 * index out of bound?
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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

using Graph = vector<vector<int> >;
Graph G;

void dfs(int v, vector<bool> &seen, int &res) {
    bool end = true;
    for (int i = 0; i < seen.size(); ++i) if (!seen[i] && i != v) end = false;
    if (end) {
        ++res;
        return;
    }

    seen[v] = true;
    for (auto nv : G[v]) {
        if (seen[nv]) continue;
        dfs(nv, seen, res);
    }
    seen[v] = false;
}

int main() {
    int N, M; cin >> N >> M;
    G.assign(N, vector<int>());
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<bool> seen(N, false);
    int res = 0;
    dfs(0, seen, res);
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <tuple>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;
vector<int> to[2505];
vector<int> rto[2505];
bool from1[2505];
bool toN[2505];

void dfs(int v){
  if(from1[v]) return;
  from1[v] = true;
  for(int u : to[v]){
    dfs(u);
  }
}
void rdfs(int v){
  if(toN[v]) return;
  toN[v] = true;
  for(int u : rto[v]){
    rdfs(u);
  }
}

bool ok[2525];

int main(){
  int n,m,p;
  cin >> n >> m >> p;
  vector<tuple<int,int,int> > edges;
  rep(i,m){
    int a,b,c;
    cin >> a >> b >> c;
    a--; b--;
    c -= p;
    c = -c;
    edges.emplace_back(a,b,c);
    to[a].push_back(b);
    rto[b].push_back(a);
  }
  dfs(0);
  rdfs(n-1);
  rep(i,n) ok[i] = from1[i] & toN[i];
  //bellman_ford
  vector<int> d(n,1001001001);
  d[0] = 0;
  bool upd = true;
  int step = 0;
  while(upd){
    upd = false;
    rep(i,m){
      int a,b,c;
      tie(a,b,c) = edges[i];
      if(!ok[a]) continue;
      if(!ok[b]) continue;
      int newD = d[a]+c;
      if(newD < d[b]){
        upd = true;
        d[b] = newD;
      }
    }
    step++;
    if(step > n){
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = -d[n-1];
  ans = max(0,ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  double average = 0;
  double d = 0;
  int s[1000];
  cin >> n;
  while (n != 0)
  {
    for (int i = 0; i < n; i++)
    {
      cin >> s[i];
      average += s[i];
    }
    average = average / n;
  //  cout << average << endl;
    
    for (int i = 0; i < n; i++)
    {
      d += pow((s[i] - average),2);
     // cout << d << endl;
    }
    d = d/n;
    printf("%.8lf\n", sqrt(d));
    cin >> n;
    d = 0;
    average = 0;
  }
}


Measured memory_bytes: 3144
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int X;
    cin >> X;
    int cnt = 1;
    while(1) {
        if((X * cnt) % 360 == 0) {
            cout << cnt << endl;
            return 0;
        }
        cnt++;
    }
    return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

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

const int mod = INF+7;
int main(){
    int n,k;cin>>n>>k;
    string s;cin>>s;
    ll res = 0;
    vector<ll>cnt(2);
    for(int i=0;i<n;){
        char c = s[i];
        do{
            res++;
            i++;
        }while(c==s[i] && i<n);
        res--;
        if(c=='L')cnt[0]++;
        else cnt[1]++;
    }
    ll num = min(cnt[0],cnt[1]);
    bool f = (cnt[0]==cnt[1]);
    while(k>0 && num>0){
        if(num==1 && f)res += 1;
        else res += 2;
        num--;k--;
    }
    cout<<res<<endl;
}



Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

ll n,a;
ll t[10001];
vector<ll> u,v;

ll calc(ll a,ll b){
  ll x=b;
  while(x>0LL){
    a*=10LL;
    x/=10LL;
  }
  return a+b;
}

int main(){
  scanf("%lld",&n);
  for(int i=0;i<10001;i++)t[i]=0;
  for(int i=0;i<n;i++){
    scanf("%lld",&a);
    t[a]++;
  }
  
  for(int i=1;i<=10000;i++){
    for(int j=0;j<t[i]&&(int)u.size()<30;j++){
      u.push_back(i);
    }
  }

  for(int i=0;i<(int)u.size();i++){
    for(int j=0;j<(int)u.size();j++){
      if(i==j)continue;
      v.push_back(calc(u[i],u[j]));
    }
  }
  sort(v.begin(),v.end());
  cout<<v[2]<<endl;
  return 0;
}

Measured memory_bytes: 1324
/*A - Odds of Oddness*/
/*C - Next Prime*/
#include <bits/stdc++.h>
using namespace std;

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

	double nums = 0.0;
	double ans = 0.0;
	
	int N;
	cin >> N;

	nums = ceil((double)N/2);
	
	ans = nums / (double)N;

	cout << fixed << setprecision(10) << ans << endl;

	

	return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())

a1 = a//2
a2 = a - (a//2)
b1 = b//2
b2 = b - (b//2)
c1 = c//2
c2 = c - c//2

ans = min(a2*b*c - a1*b*c, b2 * a*c - b1*a*c)
ans = min(ans, c2 * a*b - c1 * a * b)
print(ans)


Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(v) v.begin(),v.end()
#define mod 1000000007


int main(){
  string s;
  ll n;
  ll a,b;
  cin >> a >> b;
  ll ans=0;
  if(a>b)ans=2*a-1;
  else if(a<b)ans=2*b-1;
  else ans=2*a;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
using namespace std;

int main(){
	int n;
	int check[6];
	rep(i,6)check[i]=0;
	cin>>n;
	rep(i,n){
		int w,a;
		cin>>w;
		int one=1,two=2,three=3;
		rep(j,w){
			cin>>a;
			if(a==0){
				int alt=one;
				one=two;
				two=alt;
			}else{
				int alt=two;
				two=three;
				three=alt;
			}
		}
		if(one==1){
			if(two==2)check[0]++;
			else check[2]++;
		}else if(one==2){
			if(two==1)check[1]++;
			else check[4]++;
		}else{
			if(two==1)check[5]++;
			else check[3]++;
		}
	}
	bool ans=false;
	if(check[0])ans=true;
	if(check[1]>1 || check[2]>1 || check[3]>1)ans=true;
	if(check[4] && check[5])ans=true;
	if(check[4]>2 || check[5]>2)ans=true;
	if((check[4] || check[5]) && ((check[1]&&check[2])||(check[2]&&check[3])||(check[3]&&check[1])))ans=true;
	cout<<(ans?"yes":"no")<<endl;
	return 0;
}


Measured memory_bytes: 3100
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AHEX solver = new AHEX();
        solver.solve(1, in, out);
        out.close();
    }

    static class AHEX {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            char x = in.next().charAt(0), y = in.next().charAt(0);
            if (x == y) {
                out.println("=");
            } else if (x > y) {
                out.println(">");
            } else {
                out.println("<");
            }
        }

    }
}



Measured memory_bytes: 22996