akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int n;
int dp[100010][3];
int a[100010][3];
int main(int argc,char** argv){
	cin>>n;
	forn(i,n){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	dp[0][0]=dp[0][1]=dp[0][2]=0;
	forn(i,n){
		rep(j,3){
			rep(k,3){
				if(k==j)continue;
				dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][k]);
			}
		}
	}
	int ans=0;
	rep(i,3){
		ans=max(ans,dp[n][i]);
	}
	cout<<ans;
	return 0;
}

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

typedef vector<int> vi;
vi v;
int n;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    while(cin >> n)
    {
        v = vi(n);
        for(int i = 0; i < n; i++)
            cin >> v[i];
        sort(v.begin(), v.end());
        int ans = min(v[n-1] - v[0], v[0]);
        int sel = v[0];
        for(int i = 1; i < n - 1; i++)
        {
            if(min(v[i], v[n-1] - v[i]) > ans)
            {
                ans = max(ans, min(v[i], v[n-1] - v[i]));
                sel = v[i];
            }
        }
        cout << v[n-1] << " " << sel << '\n';
    }
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	int i1=0;
	int i2=0;
	int i4=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%4==0){
			i4++;
		}else if(a[i]%2==0){
			i2++;
		}else{
			i1++;
		}
	}
	
	//cout<<i4<<" "<<i2<<" "<<i1<<endl;
	
	if(i2>0)i4--;
	
	if(i4+2>i1){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
	return 0;
}

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

int main() {
  int n,l;
  string s;
  vector<string> v;
  cin>>n>>l;
  for(int i=0;i<n;i++)
 	{ 	cin>>s;
  		v.push_back(s);
	}
 sort(v.begin(),v.end());
 for(int i=0;i<n;i++)
 cout<<v[i];
cout<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n, k, *P = map(int, open(0).read().split())
p = [(i + 1) / 2 for i in P]
s = [float()]
for i in range(n):
    s.append(s[i] + p[i])
print(max(s[i + k] - s[i] for i in range(n - k + 1)))


Measured memory_bytes: 118652
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int H, W, h, w; scanf("%d%d%d%d", &H, &W, &h, &w);
	
	if(!(H % h) and !(W % w)) {
		printf("No\n");
		return 0;
	}
	
	std::vector<std::vector<int>> ans(H, std::vector<int>(W, 1000));
	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			if(i % h != h - 1) continue;
			if(j % w != w - 1) continue;
			ans[i][j] = -((h * w - 1) * 1000 + 1);
		}
	}
	
	printf("Yes\n");
	for(int i = 0; i < H; i++) {
		for(auto v: ans[i]) printf("%d ", v);
		printf("\n");
	}
	return 0;
}


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


int main()
{
  int n, q;
  cin >> n >> q;
  priority_queue<tuple<int, bool, int>, vector<tuple<int, bool, int>>, greater<tuple<int, bool, int>>> event;
  rep(i, n)
  {
    int s, t, x;
    cin >> s >> t >> x;
    event.emplace(s - x, true, x);
    event.emplace(t - x, false, x);
  }
  vector<int> d(q);
  rep(i, q)
    cin >> d[i];
  sort(d.begin(), d.end());
  set<int> x;
  rep(i, q)
  {
    while (!event.empty() && get<0>(event.top()) <= d[i])
    {
      if (get<1>(event.top()))
        x.insert(get<2>(event.top()));
      else
        x.erase(get<2>(event.top()));
      event.pop();
    }
    if (x.empty())
      printf("-1\n");
    else
      printf("%d\n", *x.begin());
  }
  return 0;
}

Measured memory_bytes: 16492
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	string s;
	cin >> s;


	cout << (s[0] == s[1] || s[1] == s[2] || s[2] == s[3] ? "Bad" : "Good") << endl;



	return 0;
}

Measured memory_bytes: 256
# coding=utf-8


def main():
    r, c = map(int, raw_input().split())
    rSum = [0] * (c + 1)
    for _ in xrange(r):
        row = map(int, raw_input().split() + ['0'])
        row[-1] = sum(row)
        print ' '.join(map(str, row))
        for i in xrange(c + 1):
            rSum[i] += row[i]
    print ' '.join(map(str, rSum))

if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int n;
void dfs(string str, char mx)
{
    if ((int)str.size() == n)
    {
        cout << str << '\n';
        return;
    }

    for (char c = 'a'; c <= mx + 1; c++)
    {
        string nex = str;
        nex += c;
        dfs(nex, max(mx, c));
    }
}

int main()
{
    cin >> n;
    dfs("", 'a' - 1);
    return 0;
}


Measured memory_bytes: 3524
package com.example.itp2.one

import java.util.*

fun main(args: Array<String>) {
    try {
        val sc = Scanner(System.`in`)
        val q = sc.nextInt()
        if (q < 1 || q > 200000) {
            throw Exception("Unexpected input.")
        }
        val v = ArrayList<Int>()
        for (i in 0 until q) {
            val instruction = sc.nextInt()
            if (instruction == 0) {
                val x = sc.nextInt()
                v.add(x)
            }
            if (instruction == 1) {
                val p = sc.nextInt()
                println(v.get(p))
            }
            if (instruction == 2) {
                v.removeAt(v.lastIndex)
            }
        }
    } catch (e: Exception) {
        println(e)
    }
}



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

int main(){
  int n,l;
  cin >> n>>l;
  int a=0;
    for(int i=1;i<=n;i++){
      a+=l+i-1;
    }
    if(l>=0){
    cout <<a-l<<endl;
  }
  else if(l+n-1>=0){
    cout << a << endl;
  }
  else{
    cout << a-l-n+1 << endl;
  }
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	/* several useful subroutines */
	private static final BigDecimal BD1000000007 = new BigDecimal(1000000007);
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	private static BigDecimal mod1000000007(BigDecimal bd) {
		return bd.subtract(BD1000000007.multiply(bd.divide(BD1000000007, BigDecimal.ROUND_DOWN))) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(int i) {
		return mod1000000007(new BigDecimal(i)) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(long l) {
		return mod1000000007(new BigDecimal(l)) ;
	}

	
	/* main routine */
	public static void main(String args[]) throws IOException {
		int n = getInt();
		int b[] = getIntArray(n-1);

		int s = 0;
		for ( int i = 0 ; i < n-2 ; i++ ) {
			s += b[i] < b[i+1] ? b[i] : b[i+1];
		}
		s += b[0] + b[n-2];
		System.out.println(s);
	}
}


Measured memory_bytes: 22612
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
  string s,t;
  cin >> s;
  cin >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<char>());
  if(s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3580
from collections import deque


def get_children(ps):
    children = [set() for _ in range(n)]
    for i, p in enumerate(ps):
        children[p].add(i + 1)
    return children


def make_levels(cs):
    levels_set = []
    levels_dict = {}
    queue = deque([(0, 0)])
    while queue:
        i, l = queue.popleft()
        if fixed[i]:
            continue
        if len(levels_set) <= l:
            levels_set.append(set())
        levels_set[l].add(i)
        levels_dict[i] = l
        queue.extend((c, l + 1) for c in cs[i])
    return levels_set, levels_dict


def make_where(aa):
    where = [0] * n
    for i, a in enumerate(aa):
        where[a] = i
    return where


def get_leaves(levels):
    leaves = {}
    children_count = [-1] * n
    for l, cs in reversed(list(enumerate(levels))):
        for c in cs:
            cc = children_count[c]
            pi = ps[c - 1]
            if cc == -2:
                children_count[pi] = -2
                continue

            if cc == -1:
                if aa[c] == c:
                    fixed[c] = True
                    continue
                leaves[c] = c
                cc = c
            else:
                leaves[c] = cc

            if children_count[pi] == -1:
                children_count[pi] = cc
            else:
                children_count[pi] = -2
    return leaves


def put(i, x):
    buf.append(i)
    where[x] = i
    x, aa[i] = aa[i], x
    while i:
        pi = ps[i - 1]
        where[x] = pi
        x, aa[pi] = aa[pi], x
        i = pi


def solve():
    cs = get_children(ps)
    levels_set, levels_dict = make_levels(cs)
    while not fixed[0]:
        leaves = get_leaves(levels_set)
        while leaves:
            root = aa[0]
            if root in leaves:
                gci = leaves[root]
                while True:
                    a = aa[gci]
                    if not fixed[a] or a < root:
                        put(gci, root)
                        fixed[root] = True
                        break
                    gci = ps[gci - 1]
                del leaves[root]
            else:
                ml, mi = max((levels_dict[where[i]], where[i]) for i in leaves)
                put(mi, root)


n = int(input())
ps = list(map(int, input().split()))
aa = list(map(int, input().split()))
where = make_where(aa)
fixed = [False] * n
buf = []
solve()
print(len(buf))
print('\n'.join(map(str, buf)))


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

int n;
double a[100];

int main(){
	cin >> n;
	double sum = 0;
	rep(i,n){
		cin >> a[i];
		sum += a[i];
	}
	sum /= n;
	ll ans = -1;
	double g = INF;
	rep(i,n){
		if(g > abs(a[i] - sum)){
			g = abs(a[i] - sum);
			ans = i;
		}
	}
	cout << ans << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i);
  }

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    cnt += min(x.at(i), K - x.at(i));
  }

  cout << cnt * 2 << endl;
  return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var p = new int[N];
            for (int i = 0; i < N; i++) p[i] = ReadInt();
            Array.Sort(p);
            var ans = p.Sum() - p[N - 1] / 2;

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

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxV = 50 * 50 * 50;
ll n, x, d;
ll f[55], m[55], sze[55];
ll w[55], dp[maxV + 10];
struct node {
    ll v, w;
    friend inline int operator < (const node &a, const node &b) {
        return a.w * b.v > a.v * b.w;
    }
} a[55];
int main() {
    scanf("%lld%lld%lld", &n, &x, &d);
    for (ll i = 1; i <= n; i++) {
        scanf("%lld", m + i);
        if (i > 1) scanf("%lld", f + i);
    }
    for (ll i = n; i > 0; i--) sze[f[i]] += ++sze[i], w[f[i]] += w[i] += m[i];
    memset(dp, 0x3f, sizeof dp);
    dp[0] = 0;
    for (ll i = 1; i <= n; i++) {
        a[i].v = w[i], a[i].w = sze[i];
        ll rest = i == 1 ? n : min(n, d);
        for (ll cnt = 1; cnt <= rest; rest -= cnt, cnt <<= 1) {
            for (ll j = maxV; j >= sze[i] * cnt; j--) dp[j] = min(dp[j], dp[j - sze[i] * cnt] + cnt * w[i]);
        }
        if (rest) for (ll j = maxV; j >= sze[i] * rest; j--) dp[j] = min(dp[j], dp[j - sze[i] * rest] + rest * w[i]);
    }
    sort(a + 1, a + 1 + n);
    ll ans = 0;
    for (ll i = 0; i <= maxV; i++) {
        ll now = i;
        ll rest = x - dp[i];
        if (rest < 0) continue;
        for (ll j = 1; j <= n; j++) {
            ll cnt = a[j].w == n ? 1e9 : max(0ll, d - n);
            if ((long double) cnt * a[j].v > 1e10 || cnt * a[j].v > rest) {
                now += rest / a[j].v * a[j].w;
                break;
            }
            else {
                now += cnt * a[j].w;
                rest -= cnt * a[j].v;
            }
        }
        ans = max(ans, now);
    }
    return cout << ans << endl, 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n, m;
  cin>>n>>m;
  vector<ll> A(n);
  rep(i,n) cin >> A[i];
  sort(all(A));
  vector<P> V(m); //P(C,B)
  rep(i,m) cin >> V[i].second >> V[i].first;
  sort(all(V), greater<P>());
  vector<int> nums(m,0);
  int sum = 0;
  for (int i = 0; i < m; ++i) {
    int idx = lower_bound(all(A), V[i].first) - A.begin();
    debug(idx);
    if (idx - sum <= 0 || idx == 0) break;
    if (idx - sum - V[i].second >= 0) nums[i] = V[i].second;
    else nums[i] = idx - sum;
    sum += nums[i];
  }
  ll ans = 0;
  rep(i,m) {
    if (nums[i] == 0) break;
    ans += nums[i] * V[i].first;
    debug(ans);
  }
  for (int i = sum; i < n; ++i) {
    ans += A[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2944
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
using namespace std; 
int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 1; i < n; i++)
	{
		
		int q = 0;
		for (char k = 'a'; k <= 'z'; k++)
		{
			int aa = 0, bb = 0;
			for (int j = 0; j < i; j++)
			{
				if (s.at(j) == k)
				{
					aa = 1;
				}
			}
			for (int j = i; j <n ; j++)
			{
				if (s.at(j) == k)
				{
					bb = 1;
				}
			}
			if (aa==1&&bb==1)
			{
				q++;
			}
		}
		if (ans<q)
		{
			ans = q;
		}

	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
	char s,t;
	cin >> s >> t;
	if(s>t){cout << ">"<<endl;}else if(s<t){cout << "<" << endl;}else{cout << "=" << endl;}
	return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
int main(void){
    int n,b,t,ans=0;
    scanf("%d %d %d",&n,&b,&t);
    while(1){
        if(t<n){
            break;
        }
        ans+=b;
        t-=n;
    }
    printf("%d\n",ans);
}



Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B___I_miss_you
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int count = input.Length;

            for(int i = 0; i < count; i++)
            {
                Console.Write("x");
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K;
  cin>>N>>K;
  string s;cin>>s;
  int a=1;
  for(int i=1;i<N;i++){
    if(s[i-1]!=s[i]){
      a++;
    }
  }
  a =a - 2*K;
  if(a<1)a=1;
  
  
  cout<<N-a<<endl;
}



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

int main() {
  string s ,ans="Good";
  cin >> s;
  rep(i,sz(s)-1) if(s.at(i)==s.at(i+1)) ans="Bad";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lim 100005
#define pb push_back
#define S second
#define pb push_back
#define mp make_pair
#define INF LLONG_MAX
#define fr(i,j,k) for(ll i=j;i<=k;i++)
#define frd(i,j,k) for(ll i=j;i>=k;i--)
#define F first
#define sd(n) scanf("%lld",&n)
#define pd(n) printf("%lld\n",n)
#define db double
#define pii pair<ll,ll>
#define mod 1000000007
map<ll,ll>mm;
map<ll,ll>::iterator it;
int main()
{
   ll n;
   cin>>n;
   ll x;
   for(ll i=1;i<=n;i++)
   {
    sd(x);
    mm[x]++;
   }
   it=mm.begin();
   ll ans=0;
   ll rem=0;
   while(it!=mm.end())
   {
    if(it->S==0)
    {
        it++;
        continue;
    }
    ll val=it->S;
    if(val%2==0)
    {
        rem++;
       
    }
    ans++;
    it++;

   }
   if(rem%2==0)
    ans+=0;
else ans--;
cout<<ans<<endl;

}

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

int N, occ[10][30303];
string S;
int bs(int c, int l){
	//cout << c << " " << l << '\n';
	return lower_bound(occ[c] + l, occ[c] + N + 1, occ[c][l - 1] + 1) - occ[c];
}
int main(){
	cin >> N >> S;
	for(int i = 0; i < N; i++){
		occ[S[i] - '0'][i + 1] = 1;
	}
	for(int c = 0; c < 10; c++)
		for(int i = 1; i <= N; i++)
			occ[c][i] += occ[c][i - 1];

	int final_res = 0;
	for(int a = 0; a < 10; a++){
		int a_pos = bs(a, 1);
		if(a_pos == N + 1)continue;
		for(int b = 0; b < 10; b++){
			int b_pos = bs(b, a_pos + 1);
			if(b_pos == N + 1)continue;
			for(int c = 0; c < 10; c++){
				int c_pos = bs(c, b_pos + 1);
				if(c_pos <= N)final_res++;
			}	
		}
	}
	cout << final_res << '\n';
}

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

int main() {
  int n;
  cin >> n;
  if(n == 1) cout << 2 << endl;
  else if(n % 2 == 0) cout << n << endl;
  else if(n % 2 != 0) cout << n * 2 << endl;
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    int sum = 0;
    for(int i = 1; i <= N; i++){
        int j = i;
        int count = 0;
        while(j != 0){
            j = j / 10;
            count++;
        }
        if(count % 2 == 1){
            sum++;
        }
    }
    cout << sum << endl;
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

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

    char b;
    cin >> b;

    char res;
    if(b=='A') res = 'T';
    if(b=='T') res = 'A';
    if(b=='C') res = 'G';
    if(b=='G') res = 'C';
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
aa, bb, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

info = [list(map(int, input().split())) for i in range(m)]

ans = 10 ** 19
for i in range(m):
    x, y, c = info[i]
    x -= 1
    y -= 1
    ans = min(ans, a[x] + b[y] - c)
a_min = min(a)
b_min = min(b)
ans = min(ans, a_min + b_min)
print(ans)

Measured memory_bytes: 82284
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<par<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}
      
void run(){
    int n;
    cin>>n;
    if(n==0)return;
    vi a(n);
    int s=0;
    rep(i,n)cin>>a[i],s+=a[i];
    s/=n;
    int ans=0;
    rep(i,n)ans+=a[i]<=s;
    cout<<ans<<endl;
    run();
}


Measured memory_bytes: 3396
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //Policy Based Data Structure
// using namespace __gnu_pbds;              //Policy Based Data Structure
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; //Policy Based Data Structure
// #define gc              getchar_unlocked
// #define pqb             priority_queue<int>
// #define pqs             priority_queue<int, vi, greater<int> >
// #define mk(arr,n,type)  type *arr = new type[n]
#define fo(i,n)         for(i=0;i<n;i++)
#define Fo(i,k,n)       for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int             long long
#define endl            '\n'
#define w(t)            int t; cin>>t; while(t--)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x,y)       cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define all(x)          x.begin(), x.end()
#define clr(x)          memset(x, 0, sizeof(x))
#define sortall(x)      sort(all(x))
#define tr(it,a)        for(auto it = a.begin(); it != a.end(); it++)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define PI              3.1415926535897932384626
#define inf             1e18
// mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());  //Random Shuffler
typedef pair<int, int>   pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
typedef map<int, int>    mii;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
// const int N = 3e5, M = N;
// vi g[N];
//=======================

void sol()
{
	string s;
	cin >> s;
	if (s[s.length() - 1] == 's')
	{
		s.push_back('e');
		s.push_back('s');

	}
	else
	{
		s.push_back('s');
	}
	cout << s << endl;
}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	sol();

	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = (result * base) % mod;
		base = (base * base) % mod;
		exp >>= 1;
	}
	return result;
}

// void ipgraph(int n, int m){
//     int i, u, v;
//     while(m--){
//         cin>>u>>v;
//         g[u-1].pb(v-1);
//         g[v-1].pb(u-1);
//     }
// }
//
// void dfs(int u, int par){
//     for(int v:g[u]){
//         if (v == par) continue;
//         dfs(v, u);
//     }
// }


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	int x, y;
	cin >> x >> y;
	if (x > 9 || y > 9) {
		cout << -1;
		return 0;
	}
	cout << x * y;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


typedef struct {
    char ch;
    char value;
} Card;

Card C1[37], C2[37];

void bubble(int);
void select(int);
void swap(Card *, Card *);

//main
int main(void){ 

    int n, i;
    char ch;
    scanf("%d%c", &n, &ch);
    for (i = 0; i < n; i++) {
        scanf("%c%c%c", &C1[i].ch, &C1[i].value, &ch);
    }

    // 配列コピー
    for (i = 0; i < n; i++) {
        C2[i].ch = C1[i].ch;
        C2[i].value= C1[i].value;
    }

    bubble(n);
    select(n);

    return 0;
}


void swap(Card *x, Card *y){
    Card temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

void bubble(int n){

    int i, j;

    //sort
    for (i = 0; i < n-1; i++) {
        for (j = n-1; j > 0 ; j--) {
            if(C1[j].value < C1[j-1].value) swap(&C1[j], &C1[j-1]);
        }
    }

    // print
    for (i = 0; i < n; i++) {
        printf("%c%c", C1[i].ch, C1[i].value);
        if(i < n-1) printf(" ");
    }
    printf("\n");
    printf("Stable\n");
}

void select(int n){

    int min, i, j, cnt = 0;

    // sort
    for (i = 0; i < n-1; i++) {
        min = i;
        for (j = i; j < n; j++) {
            if(C2[j].value < C2[min].value) min = j;
        }
        swap(&C2[i], &C2[min]);
    }

    // print
    for (i = 0; i < n; i++) {
        printf("%c%c", C2[i].ch, C2[i].value);
        if(i < n-1) printf(" ");
    }
    printf("\n");

    // IsStable
    for (i = 0; i < n; i++) {
        if(C2[i].value == C1[i].value && C2[i].ch == C1[i].ch)
            cnt++;
    }
    if(n == cnt) printf("Stable\n");
    else printf("Not stable\n");
}

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

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

ll min(ll x, ll y){
    if(x<y)return x;
    return y;
}
int a[100000];
int f[100000];
int b[100000];

int gcd(int a, int b){
    if(a < b){
        int t = a;
        a = b;
        b = t;
    }
    if(a % b == 0)return b;
    else return gcd(b, a%b);
}
int main(void){
    int n;
    scanf("%d", &n);
    for(int i = 0;i < n;i++){
        scanf("%d", &a[i]);
    }
    int fr = a[0];
    for(int i = 0;i < n;i++){
        fr = gcd(fr, a[i]);
        f[i] = fr;
    }
    int ba = a[n-1];
    for(int i = n-1;i >= 0;i--){
        ba = gcd(ba, a[i]);
        b[i] = ba;
    }
    int max = 1;
    for(int i = 0;i < n;i++){
        if(i == 0){if(b[1] > max)max = b[1];}
        else if(i == n-1){if(f[n-2] > max)max = f[n-2];}
        else{
            int gg = gcd(f[i-1], b[i+1]);
            if(gg > max)max = gg;
        }
        //printf("%d\n", max);
    }
    printf("%d\n", max);
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
Int cnt[216000];
Int n;
Int c[216000];
Int res = 1;
Int tmp[216000];
int main(){
  cin >> n;
  for(int i = 0;i < n;i++)cin >> c[i];
  for(int i = 0;i < n;i++){
    if(i == 0 || c[i-1] != c[i]){
      tmp[c[i]] = res;
    }
    if(i == n-1 || c[i+1] != c[i]){
      ///cout << i << " " << cnt[c[i]] << endl;
      res += cnt[c[i]]; res %= MOD;
      cnt[c[i]] += tmp[c[i]];
      cnt[c[i]] %= MOD;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 

int mxn=1e18;
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{
    int n;
    cin>>n;int flag=0;VI ar(n);
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
        if(ar[i]==0)flag=1;
    }
    if(flag){cout<<0;continue;}
    for(int i=0;i<n;i++)
    {
        mxn/=ar[i];
    }
    if(mxn==0){cout<<-1;continue;}
    int ans=1;
    for(int i=0;i<n;i++)ans*=ar[i];
    cout<<ans<<endl;
    
    
}


return 0;
}





Measured memory_bytes: 3972
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#define N 20000

using namespace std;

struct Point {
	int start, end;
	int qty;
};

Point newP(int start, int end, int qty){
	Point *p = new Point;
	p->start = start; p->end = end; p->qty = qty;
	return *p;
}

int *stack1;
int end1;
Point *stack2;
int end2;
Point NIL = newP(-1,-1,-1);


void init(){
 	stack1 = new int[N];
 	stack2 = new Point[N];
 	end1 = end2 = 0;
}

void push1(int i){
	stack1[end1] = i;
	end1++;
}
int pop1(){
	if(end1 <= 0) return -1;
	end1--;
	return stack1[end1];
}
void push2(Point p){
	stack2[end2] = p;
	end2++;
}
Point pop2(){
	if(end2 <= 0) return NIL;
	end2--;
	return stack2[end2];
}
void st(){
	if(end2 <= 1) return;
	int now = end2-2;
	Point p = stack2[end2-1];
	while(1){
		if( now>=0 && p.start < stack2[now].start && stack2[now].end < p.end){
			p.qty += stack2[now].qty;
			now--;
		} else {
			break;
		}
	}
	stack2[now+1] = p;
	end2 = now+2;
}

int main(){
	init();
	int sum = 0;
	string inp;
	getline(cin, inp);
	for(int i=0;i<inp.size();i++){
		if(inp[i] == '\\'){
			push1(i);
		} else if(inp[i] == '/'){
			int b = pop1();
			if(b != -1){
				sum += i-b;
				push2(newP(b, i, i-b));
				st();
			}
		}
	}
	printf("%d\n%d", sum, end2);
	if(end2 != 0){
		printf(" ");
		for(int i=0;i<end2;i++){
			printf("%d", stack2[i].qty);
			if(i != end2-1) printf(" ");
		}
	}
	printf("\n");
	return 0;
}

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

int main()
{
    int n,c1=0,c2=0; cin>>n;
    int a[n];
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort (a,a+n);
    for (int i=0;i<n;i+=2)
        {
            c1+=a[i];
        }
    for (int i=1;i<n;i+=2)
    {
        c2+=a[i];
    }

    cout<<abs(c1-c2)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

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

const int N = 16;
int a[N][N];
ll group[1 << N], dp[1 << N];

int main() {
    int n;
    cin >> n;
    REP(i, n) REP(j, n) cin >> a[i][j];
    for (int mask = 1; mask < (1 << n); mask++) {
        REP(i, n) REPP(j, i + 1, n) {
            if ((mask & (1 << i)) && (mask & (1 << j))) {
                group[mask] += a[i][j];
            }
        }
    }
    dp[0] = 0;
    for (int mask = 1; mask < (1 << n); mask++) {
        int prev = mask;
        while (true) {
            prev = (prev - 1) & mask;
            dp[mask] = max(dp[mask], dp[prev] + group[mask - prev]);
            if (prev == 0) break;
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}

Measured memory_bytes: 1280
import numpy as np
n = int( input())

def f(num):
  if num%2 ==0:
    return n/2
  else :
    return 3*n+1
x=  [n]
a = 1
while True:
  n = f(n)
  if n in x :
    a+=1
    break
  else :
    x.append(n)
    a +=1
print(a)

Measured memory_bytes: 12488
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[20007];
struct node{int w, s; ll v;}a[1007];
bool cmp(node &x, node &y) {return x.w + x.s < y.w + y.s;}
int main()
{
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d%d%lld", &a[i].w, &a[i].s, &a[i].v);
    sort(a + 1, a + 1 + n, cmp);
    ll ans = 0;
    for (int i = 1; i <= n; i++)
        for (int j = a[i].s + a[i].w; j >= a[i].w; j--)
            ans = max(ans, dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v));
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner entrada= new Scanner(System.in);
        int A= entrada.nextInt();
        int B= entrada.nextInt();
        int C= entrada.nextInt();
        int N=(int)B/A;
        if (N>C){
            System.out.println(C);
        }
        else{
            System.out.println(N);
        }
    }
    
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod ((ll)1e9+7)
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3f
#define Ninf -0x3e3e3e3f
#define Ninfl -0x3e3e3e3e3e3e3e3f
#define maxx ((ll)2e5+5)
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
ll add(ll x, ll y) { x += y; if (x >= mod) return x-mod; return x;}
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + mod; return x;}
ll mult(ll x, ll y) { return (x * y) % mod;}
ll rev(ll x) { return expm(x, mod - 2);}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
vector<int> val(maxx);
vector<int> adj[maxx];
vector<int> dp(maxx,infl);
vector<int> ans(maxx);
int n;
void func(int u,int par)
{
    auto it=lower_bound(dp.begin(),dp.end(),val[u]);
    ans[u]=max(ans[par], it-dp.begin()+1LL);
    int pre=*it;
    *it=val[u];    
    for(auto v:adj[u]){
        if(v==par) continue;
        func(v,u);
    }
    *it=pre;
}

signed main(){
  fast;
  //test
  {
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>val[i];
    }
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        // cerr<<x<<" "<<y<<endl;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    func(0,0);
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }

  }
  return 0;
}

Measured memory_bytes: 30336
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
	long long int a,b,x;
	cin >> a >> b >> x;

	if(a>0){
		cout << b/x - (a-1)/x << endl;
	}
	if(a==0){
		cout << b/x +1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
a = list(map(int, input().split()))
cots = float('inf')

for i in range(a[0]):
    b = list(map(int, input().split()))
    if b[1] <= a[1]:
        if b[0] <= cots:
            cots = b[0]

if cots == float('inf'):
    print('TLE')
else:
    print(cots)


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

map<int64_t, int64_t> bunkai(int64_t N)
{
    map<int64_t, int64_t> hist;

    int64_t a = 2;
    while (N >= a * a)
    {
        if (N % a == 0)
        {
            hist[a]++;
            N /= a;
        }
        else
            a++;
    }
    hist[N]++;
    return hist;
}

int main()
{
    int64_t N, P;
    cin >> N >> P;
    auto list = bunkai(P);
    int64_t ans = 1;
    for (auto x : list)
    {
        ans *= pow(x.first, x.second / N);
    }
    cout << ans;
}

Measured memory_bytes: 4040
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;
 
ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
ll x,y;
cin>>x>>y;
if(x%y==0)
cout<<-1<<endl;
else
cout<<x<<endl;
}



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

int main(void) {
	string s, t;
	cin >> s >> t;

	int cnt = 0;
	for (int i = 0; i < 3; ++i) {
		if (s[i] == t[i])
			++cnt;
	}

	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> v;

int N;
int main (){
    cin >> N;
    int sum = 0;
    for(int i=0; i<N; i++) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    for(int i=0; i<N-1; i++) sum += v[i];
    int big = v[N-1];
    cout <<  ( big >= sum  ? "No" : "Yes" ) << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

/**
 * Library
 * --------------------------------------------------------
 */
class UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> size;
    vector<vector<int>> group;
public:
    UnionFind(int n = 1) {
        par.resize(n + 1);
        rank.resize(n + 1);
        size.resize(n + 1);
        group.resize(n + 1);
        for (int i = 0; i <= n; ++i) {
            par[i] = i;
            rank[i] = 0;
            size[i] = 1;
            group[i].push_back(i);
        }
    }

    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            int r = find(par[x]);
            return par[x] = r;
        }
    }

    bool is_same(int x, int y) {
        return find(x) == find(y);
    }

    bool unit(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        } else {
            if (rank[x] < rank[y]) {
                swap(x, y);
            }
            if (rank[x] == rank[y]) {
                ++rank[x];
            }
            par[y] = x;
            size[x] += size[y];
            return true;
        }
    }

    int get_size(int x) {
        return size[find(x)];
    }

    void merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (group[x].size() > group[y].size()) {
            swap(x, y);
        }
        copy(group[y].begin(), group[y].end(), back_inserter(group[x]));
        group[y].clear();
        par[y] = x;
    }
};

/**
 * --------------------------------------------------------
 */


void Main() {
    ll N, M;
    cin >> N >> M;
    vector<P> items(M);
    rep(i, M) cin >> items[i].first >> items[i].second;

    UnionFind unionFind(N);
    vector<ll> ans(M, 0);
    rep(i, M) {
        P p = items[M - 1 - i];
        ll a = p.first;
        ll b = p.second;
        if (unionFind.is_same(a, b)) {
            ans[i] = 0;
        } else {
            ans[i] = unionFind.get_size(a) * unionFind.get_size(b);
            unionFind.unit(a, b);
        }
    }
    reverse(ans.begin(), ans.end());
    ll prev = 0;
    rep(i, M) {
        cout << ans[i] + prev << '\n';
        prev += ans[i];
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 10368
// In the name of god
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const long long inf=1e15+5;
long long n,k,h[maxn],x,dp[maxn];
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>h[i];
		if(i==0){
	
		}
		else{
			dp[i]=inf;
			for(int j=1;j<=k;j++){
				if(i-j<0){
					break;
				}
				dp[i]=min(dp[i],(dp[i-j]+abs(h[i]-h[i-j])));
			}
		}
	}
	cout<<dp[n-1];
}



Measured memory_bytes: 1792
# Your code here!
M = 10**9+7
def square(n, m, a)
    return 1 if m == 0
    x = square(n, m/2, a)**2 % a
    x *= n if m % 2 == 1
    return x % a
end
def hoge(num, except)
    x, y = 1, 1
    except.times do |i|
        x *= num - i
        x %= M
        y *= i+1
        y %= M
    end
    x * square(y, M-2, M) % M
end

num, a, b= gets.chop.split.map(&:to_i)
all = square(2, num, M)
all -= 1
ca = M-hoge(num, a)
cb = M-hoge(num, b)
p (all + ca + cb) % M

Measured memory_bytes: 3836