akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#define it register int
#define ct const int
#define il inline
using namespace std;
typedef long long ll;
#define rll register ll
#define cll const ll
const int N=1000005,M=N<<1;
int t[M][27],s[M][27],l[N],len,cnt=1,n,cn[N];
string S,str[N];
long long ans;
il void ins(){
	len=S.length();it i,j,rt=1,c,x=0;
	for(i=0;i<len;++i) ++cn[S[i]-'a'];
	for(i=len-1;~i;--i){
		for(j=0;j<26;++j) s[rt][j]+=(cn[j]>0);
		if(!t[rt][c=S[i]-'a']) t[rt][c]=++cnt;
		rt=t[rt][c],--cn[c];
	}
}
il void que(){
	it i,rt=1,c;
	for(i=len-1;rt&&i;--i) rt=t[rt][c=S[i]-'a'];
	ans+=s[rt][S[0]-'a']-1;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;it i;
	for(i=1;i<=n;++i) cin>>S,ins(),str[i]=S,l[i]=len;
	for(i=1;i<=n;++i) S=str[i],len=l[i],que();
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 246668
#pragma GCC optimize("O3")

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	set<pair<int, int>> st;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		st.insert({ a[i], i });
	}

	vector<int> cnt(n);

	for (int i = 0; i < m; i++) {
		auto p = *st.rbegin();
		st.erase(p);
		if (!p.first) break;
		int id = p.second;
		cnt[id]++;
		int y = 1LL << cnt[id];
		int x = a[id] / y;
		st.insert({x, id});
	}

	int ans = 0;
	for (auto& p : st) ans += p.first;
	cout << ans;
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

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

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  if (s[0] == '1') ++cnt;
  if (s[1] == '1') ++cnt;
  if (s[2] == '1') ++cnt;
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <atcoder/segtree>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
#define sz(x) int(x.size())
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

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

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

using namespace atcoder;

const int MAX_A = 300005;

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return (int)(0);
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    repeat(i, n) cin >> a[i];
    segtree<int, op, e> dp(MAX_A);
    repeat(i, n) {
        int x = a[i];
        int l = max(0, x - k);
        int r = min(x + k + 1, MAX_A);
        int now = dp.prod(l, r) + 1;
        dp.set(x, now);
    }
    int ans = dp.all_prod();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9528
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for ( i = 0; i <= VMAX; i++ ) C[i] = 0;

  for ( i = 0; i < n; i++ ){
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for ( i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i - 1];

  for ( j = 1; j <= n; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<climits>
#include<set>
#include<map>
#include<stack>
#define ll long long
using namespace std;

int main() {
	ll n,ans=0;
	cin >> n;
	vector<vector<ll>>a(3, vector<ll>(n+1,0));
	vector<vector<ll>>dp(3, vector<ll>(n + 1, 0));
	for (ll i = 1; i <= 2; i++) {
		for (ll j = 1; j <= n; j++) {
			cin >> a[i][j];
		}
	}
	dp[1][1] = a[1][1];
	for (ll i = 1; i <=2; i++) {
		for (ll j = 1; j <= n; j++) {
			dp[i][j] = max(dp[i - 1][j] + a[i][j], dp[i][j - 1] + a[i][j]);
		}
	}
	cout<< dp[2][n] << endl;
}


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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int x = 0, y = 0;
  int g[h][w];
  for (int i = 0; i < n; i ++) {
    int a; cin >> a;
    for (int j = 0; j < a; j ++) {
      if (x == -1 && y % 2 == 1)y ++, x ++;
      else if (x == w && y % 2 == 0) y ++, x --;

      g[y][x] = i + 1;

      if (y % 2 == 0) x ++;
      else x --;
    }
  }

  for (int i = 0; i < h; i ++) {
    for (int j = 0; j < w; j ++) {
      if (j) cout << " " << g[i][j];
      else cout << g[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include <stdio.h>
 
int main(void)
{
    int n;
 
    while(1){
        scanf("%d", &n);
        if(!n)
        break;
        
        
        int point[128] = {0};
        int max = 0;
        int min = 1000;
        int i=0;
        int j=0;
        int k=0;
        int x=0;
        i = n;
        while(i-- > 0){
           scanf("%d",&x);
          
           if(x>max){
           point[j] = max;
           max = x;
           j++;
           }
           else if(x<min){
           point[j] = min;
           min = x; 
           j++;
           }
           //if(min < x && max > x)
           else{
           point[j] = x;
           j++;
           }
        }
        int sum = 0;
        for(j=0;j<n+2;j++)
            sum = sum + point[j];
         if(min == 1000)
        	sum = sum-point[1];
         else   
         sum = sum-1000;
        printf("%d\n", sum/(n-2));
    }
 
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr long long LONGINF = 1005000000000000000;



/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/



/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


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

	cout << max({ a + b,a - b,a*b }) << endl;


	return 0;
}


Measured memory_bytes: 256
PROGRAM ATCODER

implicit none
integer :: n, m, i, j, a, ans
integer,allocatable :: x(:), dx(:)

read(*,*) n, m
allocate(x(m))
allocate(dx(m-1))
read(*,*) (x(i), i=1,m)

if(n >= m) then
	ans = 0
	write(*,'(i0)') ans
    stop
end if

call qs(x,m) !昇順に並び替え

if(n == 1) then
	ans = x(m) - x(1)
    write(*,'(i0)') ans
    stop
end if

do i = 1, m-1
	dx(i) = x(i+1) - x(i)
end do

call qs(dx,m-1)

ans = x(m) - x(1)

do i = m-1, m-n+1, -1
	ans = ans - dx(i)
end do

write(*,'(i0)') ans

END PROGRAM ATCODER


recursive subroutine qs(x,n)
   integer,intent(in) :: n
   integer,intent(inout) :: x(n)
   integer :: p,i,imin,imax,it,is
   if(n == 1) return    
   p = x(1)   
   imin = 1   
   imax = n   
   do while(imin < imax)
      do while(x(imin) < p .and. imin < imax)
         imin = imin + 1
      enddo
      do while(p <= x(imax) .and. imin < imax)
         imax = imax - 1
      enddo
      if(imin < imax)then
         it = x(imax)
         x(imax) = x(imin)
         x(imin) = it
      endif
   enddo
   is = imax - 1
   if(is == 0) is = 1
   call qs(x(1:is),is)
   call qs(x(is + 1:n),n - is)
end subroutine qs


Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
struct P {int x,y,z;};

int main() {
  int n,m,a,d,k;
  cin >> n >> a >> d >> m;
  P p[m];
  map<int,int> ma;
  for(int i=0; i<m; i++) {
    cin >> p[i].x >> p[i].y >> p[i].z;
    ma[p[i].y]=a+d*(p[i].y-1);
    ma[p[i].z]=a+d*(p[i].z-1);
  }
  cin >> k;
  ma[k]=a+d*(k-1);
  for(int i=0; i<m; i++) {
    if(!p[i].x) swap(ma[p[i].y],ma[p[i].z]);
    else ma[p[i].y]=ma[p[i].z];
  }
  cout << ma[k] << endl;
  return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n;
    cin >> n;
    vector<bool> ans;

    ll index = 0;
    ll diff = 1;
    while (n != 0) {
        if (n & (1 << index)) {
            ans.push_back(true);
            n -= diff;
        } else {
            ans.push_back(false);
        }
        index++;
        diff *= -2;
    }

    if (ans.size() == 0) {
        ans.push_back(false);
    }
    ll num = ans.size();
    repb(i, num) { cout << int(ans[i]); }
    cout << endl;
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1000000000;
/****** define constant end ********/



/****** define variable start ******/
ll h, n;
vl a, b;
/******* define variable end *******/

ll solve(){
    cin >> h >> n;
    a.resize(n);
    b.resize(n);
    REP(i, n){
        cin >> a[i] >> b[i];
    }
    vl dp(h+5,INF);//hp:iを倒す最小間力
    dp[0] = 0;
    REP(i, h+5){
        REP(j, n){
            if(i-a[j] < 0){
                dp[i] = min(dp[i], b[j]);
            }else{
                dp[i] = min(dp[i], dp[i-a[j]] + b[j]);
            }
        }
    }
    cout << dp[h] << endl;
    return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    return (int)end_solve;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>

#define int long long

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)

#define INF (3e9)

using namespace std;

int N, M, X;

signed main()
{
    cin >> N >> M >> X;
    int ans1 = 0;
    int ans2 = 0;
    REP(i, M)
    {
        int a;
        cin >> a;
        if ( a < X ) ++ans1;
        if ( a > X ) ++ans2;
    }
    int ans = min(ans1, ans2);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

total_value = 0
last_index = -2

for i in range(n):
  index = a_list[i] - 1
  total_value += b_list[index]
  
  if last_index + 1 == index:
    total_value += c_list[last_index]
  
  last_index = index
  
print(total_value)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

struct UnionFind{
    vector<int> par;
    UnionFind(int n) : par(n) {
        rep(i, n) par[i] = i;
    }
    int root(int x){
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x), ry = root(y);
        if(rx != ry)par[rx] = ry;
    }
    bool same(int x, int  y){
        return root(x) == root(y);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i, n)cin >> p.at(i);
    UnionFind tree(n);
    rep(i, m){
        int x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1);
    }
    int ans = 0;
    rep(i, n){
        if(tree.same(i,p.at(i)-1))ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int n,a[1<<18],b[1<<18],ans,x,y;
int main(void){
    cin>>n;
    for(int i=0;i<1<<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<1<<n;j++){
            if(j&(1<<i)){
                x=a[j^(1<<i)],y=b[j^(1<<i)];
                if(a[j]<x)swap(a[j],x);
                b[j]=max(b[j],max(x,y));
            }
        }
    }
    for(int i=1;i<1<<n;i++){
        ans=max(ans,a[i]+b[i]);
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 5120
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  int n;
  cin >> n; cin.ignore();
  REP(i, n) {
    string s;
    getline(cin, s);
    FOR(j, 6, s.size()) {
      if(s.substr(j-6, 7) == "Hoshino") s[j] = 'a';
    }
    cout << s << endl;
  }

  return 0;
}

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

using namespace std;

int main(){
  string a; cin >> a;
  if((a[0]==a[1] && a[0]!=a[2])
  || (a[1]==a[2] && a[0]!=a[1])
  ||(a[0]==a[2] && a[0]!=a[1]))
  {cout << "Yes";}
  else{cout << "No";}

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

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

	bool seat[100001] = {};

	while(N-- > 0){
		int l, r;
		cin >> l >> r;
		for(int i = l; i <= r; ++i){
			seat[i] = true;
		}
	}

	int count = 0;
	for(int i = 0; i <= 100000; ++i){
		if(seat[i]) count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt() * -1;
		int B = sc.nextInt();
		if(A + B > X) {
			System.out.println("dangerous");
		} else if(A + B > 0){
			System.out.println("safe");
		} else {
			System.out.println("delicious");
		}
	}
}


Measured memory_bytes: 22996
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicLong;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        scanner.nextLine();
        final Map<String, AtomicLong> counter = new HashMap<>();

        for (int i = 0; i < n; i++) {
            final char[] chars = scanner.nextLine().toCharArray();
            Arrays.sort(chars);
            final String string = new String(chars);

            counter.computeIfAbsent(string, e -> new AtomicLong(-1)).incrementAndGet();
        }

        long sum = 0;
        for (final AtomicLong value : counter.values()) {
            sum += getIncrementalSum(value.get());
        }

        System.out.println(sum);
    }

    private static long getIncrementalSum(final long value) {
        if (value == 0 || value == 1) {
            return value;
        }

        return (value + 1) * value / 2;
    }
}


Measured memory_bytes: 112296
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

int next(int u){
  for(int v=nt[u];v<n;v++){
    nt[u] = v+1;
    if(M[u][v]) return v;
  }
  return -1;
}

void dfs_visit(int r){
  for(int i=0;i<n;i++) nt[i] = 0;

  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  d[r] = ++tt;

  while(!S.empty()){
    int u = S.top();
    int v = next(u);
    if(v != -1){
      if(color[v] == WHITE){
        color[v] = GRAY;
        d[v] = ++tt;
        S.push(v);
      }
    }else{
      S.pop();
      color[u] = BLACK;
      f[u] = ++tt;
    }
  }
}

void dfs(){
  for(int i=0;i<n;i++){
    color[i] = WHITE;
    nt[i] = 0;
  }
  tt = 0;

  for(int u=0;u<n;u++){
    if(color[u] == WHITE) dfs_visit(u);
  }
  for(int i=0;i<n;i++){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
}

int main(){
  int u,k,v;

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

  for(int i=0;i<n;i++){
    cin >> u >> k;
    u--;
    for(int j=0;j<k;j++){
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  dfs();
  return 0;
}



Measured memory_bytes: 3136
#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 h, w, a[88][88], b[88][88];

bool dp[88][88][25600];

int main(){
    cin >> h >> w;
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            cin >> b[i][j];
            a[i][j] -= b[i][j];
        }
    }
    dp[0][0][a[0][0] + 12800] = true;
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            for(int k = 0;k < 25600;k++){
                if(!dp[i][j][k])continue;
                if(i+1 < h){
                    dp[i+1][j][k+a[i+1][j]] = true;
                    dp[i+1][j][k-a[i+1][j]] = true;
                }
                if(j+1 < w){
                    dp[i][j+1][k+a[i][j+1]] = true;
                    dp[i][j+1][k-a[i][j+1]] = true;
                }
            }
        }
    }
    int ans = 2560000;
    for(int i = 0;i < 25600;i++){
        if(dp[h-1][w-1][i]){
            ans = min(ans, abs(i - 12800));
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

int main()
{
    ll n, t, ans = 0, now = 0;
    cin >> n >> t;
    ll tmp, be;
    cin >> be;
    now = be + t;

    for (int i = 1; i < n; i++) {
        cin >> tmp;
        if (now >= tmp) ans += tmp - be;
        else ans += t;

        now = tmp + t;
        be = tmp;
    }
    cout << ans + t << endl;
    
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


class Seg():
    def __init__(self, na, default, func):
        if isinstance(na, list):
            n = len(na)
        else:
            n = na
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        if isinstance(na, list):
            self.A = [default] * (self.N) + na + [default] * (self.N-n)
            for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
        else:
            self.A = [default] * (self.N*2)
        self.F = func

    def find(self, i):
        return self.A[i + self.N]

    def update(self, i, x):
        i += self.N
        self.A[i] = x
        while i > 1:
            i = i // 2
            self.A[i] = self.merge(self.A[i*2], self.A[i*2+1])

    def merge(self, a, b):
        return self.F(a, b)

    def total(self):
        return self.A[1]

    def query(self, a, b):
        A = self.A
        l = a + self.N
        r = b + self.N
        res = self.D
        while l < r:
            if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
            l >>= 1
            r >>= 1

        return res

def main():
    n,q = LI()
    a = [LI() for _ in range(q)]
    def f(a,b):
        if a < b:
            return a
        return b
    seg = Seg(n+10, 2**31-1, f)
    r = []
    for c,x,y in a:
        if c == 0:
            seg.update(x,y)
        else:
            r.append(seg.query(x,y+1))

    return '\n'.join(map(str,r))


print(main())

Measured memory_bytes: 37260
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <deque>
#define ll long long

using namespace std;

struct Card { char mark; int val; };

vector<Card>A;

int partition(int p,int r) {
	Card x = A[r];
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j].val <= x.val) {
			i++;
			Card mp = A[i];
			A[i] = A[j];
			A[j] = mp;
		}
	}
	Card kp = A[i + 1];
	A[i + 1] = A[r];
	A[r] = kp;
	return i + 1;
}

void quickSort(int p, int r) {
	if (p < r) {
		int q = partition(p, r);
		quickSort(p, q - 1);
		quickSort(q + 1, r);
	}
}

vector<Card>B;

void merge(int p, int m, int r) {
	vector<Card> L(m - p + 1);
	vector<Card> R(r - m + 1);
	for (int i = 0; i < m - p; i++) {
		L[i] = B[p + i];
	}
	for (int i = 0; i < r - m; i++) {
		R[i] = B[m + i];
	}
	L[m - p].mark = 'X';
	L[m - p].val = 100010;
	R[r - m].mark = 'X';
	R[r - m].val = 100010;
	int curL = 0;
	int curR = 0;


	for (int i = p; i < r; i++) {
		if (L[curL].val <= R[curR].val) {
			B[i] = L[curL];
			curL++;
		}
		else {
			B[i] = R[curR];
			curR++;
		}
	}
}


void mergeSort(int p, int r) {
	if (p + 1 < r) {
		int md = (p + r) / 2;
		mergeSort(p, md);
		mergeSort(md, r);
		merge(p, md, r);
	}
}


int main() {
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		Card c; cin >> c.mark >> c.val;
		A.push_back(c);
		B.push_back(c);
	}
	quickSort(0, N - 1);
	mergeSort(0, N);
	bool isStable = true;
	for (int i = 0; i < N; i++) {
		if (A[i].mark != B[i].mark) {
			isStable = false;
			break;
		}
	}
	if (isStable) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	for (int i = 0; i < A.size();i++) {
		Card c = A[i];
		cout << c.mark << " " << c.val << endl;
	}

	return 0;
}





Measured memory_bytes: 5196
from sys import stdin


def main():
    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    # mtx = [[True for x in range(M)] for y in range(N)]
    # for x in range(M):
    #     for y in range(N):
    #         ps = [(x - 1, y - 1), (x, y - 1), (x + 1, y - 1),
    #               (x - 1, y), (x, y), (x + 1, y),
    #               (x - 1, y + 1), (x, y + 1), (x + 1, y + 1)]
    #         for px, py in ps:
    #             if px < 0 or py < 0 or M - 1 < px or N - 1 < py:
    #                 continue
    #             mtx[py][px] = not mtx[py][px]
    # for m in mtx:
    #     print(m)

    MIN = min(N, M)
    MAX = max(N, M)
    if MIN == 1 and MAX == 1:
        result = 1
    elif MIN == 1:
        result = MAX - 2
    elif MIN == 2:
        result = 0
    else:
        result = (MIN - 2) * (MAX - 2)
    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n = int(input())

count = [[0]*10 for i in range(10)]

for i in range(1,n+1):
    first = int(str(i)[0])
    last = int(str(i)[-1])

    if first == 0 or last == 0:
        continue
    else:
        count[first][last] += 1

ans = 0
for first in range(1,10):
  for last in range(1,10):
    ans += count[first][last] * count[last][first]
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#include <atcoder/all>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, Q;
    cin >> N >> Q;
    dsu d(N);
    REP(i, 0, Q) {
        ll t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }
}


Measured memory_bytes: 3940
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int y = sc.nextInt();
		int a = 0;

		if (x == 0 && y == 100) a = 101;
		else if (x == 1 && y == 100) a = 10100;
		else if (x == 2 && y == 100) a = 1010000;
		else a = (int)Math.pow(100,  x) * y;
		System.out.println(a);
	}
}

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

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back

int box[100001];


int main(void){
  int n,m;
  int cnt = 0;
  int x, y;
  cin >> n >> m;
  rep(i,n)box[i] = 1;
  box[0] = -1;
  rep(i,m){
    cin >> x >> y;
    x--;y--;
    if(box[x] == -1){
      box[x] = 0;
      box[y] = -(abs(box[y])+1);
    }else if(box[x] < 0){
      box[x]++;
      box[y] = -(abs(box[y])+1);
    }else{
      box[x]--;
      if(box[y] < 0) box[y]--;
      else box[y]++;
    }
  }
  rep(i,n){
    if(box[i] < 0)cnt++;
  }
  cout << cnt << endl;


  return 0;
}



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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n, a, b; cin >> n >> a >> b;

    if (a > b) {
        cout << 0 << endl;
        return 0;
    }

    if (n == 1 && a == b) {
        cout << 1 << endl;
        return 0;
    }

    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }

    ll mn = a + b + a * (n - 2);
    ll mx = a + b + b * (n - 2);

    cout << mx - mn + 1 << endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())
    
    if N == M:
        print('Yes')
    else:
        print('No')
    
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61868
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    k=int(input())
    ans=list(range(1,51))
    ans[49-k%50]-=1
    for i in range(50):
        ans[i]+=(k//50)
    
    print(50)
    print(*ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 5312
#include <iostream>
#include <algorithm>

using namespace std;

long long int K;

long long int dp[15][10][2][2];

long long int calc(long long int M) {

	for (int i = 1; i <= 12; i++) {
		for (int j = 0; j <= 9; j++) {
			for (int g = 0; g <= 1; g++) {
				for (int k = 0; k <= 1; k++) {
					dp[i][j][g][k] = 0;
				}
			}
		}
	}

	dp[12][0][0][0] = 1;

	int m[15];

	for (int i = 1; i <= 13; i++) {
		m[i] = M % 10;
		M /= 10;
	}
	/*int I = 0;
	for (int i = 13; i >= 1; i--) {
		if (m[i] != 0) {
			for (int k = 0; k < m[i]; k++) { dp[i][k][1][1] = 1; }
			dp[i][m[i]][1][0] = 1; dp[i][0][0][0] = 1;
			I = i;
			break;
		}
	}*/

	//for (int i = 1; i <= 10; i++) { cout << "m[" << i << "]= " << m[i] << endl; }

	int u[10], l[10];

	for (int k = 0; k <= 8; k++) { u[k] = k + 1; } u[9] = 9;
	l[0] = 0; for (int k = 1; k <= 9; k++) { l[k] = k - 1; }

	for (int i = 13; i >= 2; i--) {
		for (int k = 0; k <= 9; k++) {
            for (int g = 0; g <= 1; g++) {
				for(int flag=0;flag<=1;flag++){
					int upper, lower;
					if (g == 1 && flag==1) { upper = u[k]; lower = l[k]; }
					else if (g == 1 && flag == 0) { upper = min(u[k], m[i - 1]); lower = l[k]; }
					else if (g == 0 && flag == 1) { upper = 9; lower = 0; }
					else if (g == 0 && flag == 0) { upper = m[i - 1]; lower = 0; }
				
					for (int j = lower; j <= upper; j++) {
						dp[i - 1][j][g || j][flag || (j < m[i - 1])] += dp[i][k][g][flag];
						//if ((i - 1) == 1 && j == 0 && (g || j) == 1 && (flag || (j < m[i - 1])) == 1) { cout << i << " " << k << " " << g << " " << flag << " " <<dp[i][k][g][flag]<<endl; }
					 }
				
				}
			}
		}
	}

	long long int ret = 0;
	
	for (int flag = 0; flag <= 1; flag++) {
			for (int k = 0; k <= 9; k++) {
				ret += dp[1][k][1][flag];
		}
	}


	return ret;
}

long long int BINARY(long long int K) {

	long long int right = 9999999999;
	long long int left = 0;

	while (right > left + 1) {
		long long int med = (right + left) / 2;
		if (calc(med) >= K) { right = med; }
		else { left = med; }
	}

	return right;
}

int main(void) {
	cin >> K;

	cout << BINARY(K) << endl;

	return 0;
}

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

using namespace std;

const int MaxN = 1e5 + 15;
const int MOD = 1e9 + 7;
const long long INF = 1e18;

map<pair<long long, long long>, int> mp[50];

int main()
{
//    freopen("input.txt", "r", stdin);
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    string s;
    cin >> s;

    string srev = s;
    reverse(srev.begin(), srev.end());

    long long ans = 0;

    for(int mask = 0; mask < (1 << n); ++mask)
    {
        int d = __builtin_popcount(mask);
        long long h = 0;
        long long h1 = 0;

        for(int i = n; i < n + n; ++i)
        {
            if((1 << (i - n)) & mask)
                h = h * 31ll + s[i] - 'a' + 1;
        }

        for(int i = n + n - 1; i >= n; --i)
            if(!((1 << (i - n)) & mask))
                h1 = h1 * 31ll + s[i] - 'a' + 1;

//        cout << mask << ' ' << h << ' ' << h1 << '\n';

        ++mp[d][{h, h1}];
    }

    //cout << '\n';

    for(int mask = 0; mask < (1 << n); ++mask)
    {
        int d = n - __builtin_popcount(mask);

        long long h = 0;
        long long h1 = 0;

        for(int i = n - 1; i >= 0; --i)
            if(!((1 << i) & mask))
            {
                //cout << srev[n + n - 1 - i];
                h = h * 31ll + srev[n + n - 1 - i] - 'a' + 1;
            }

        //cout << ' ';

        for(int i = 0; i < n; ++i)
            if((1 << i) & mask)
                h1 = h1 * 31ll + s[i] - 'a' + 1;

        //cout << mask << ' ' << h << ' ' << h1 << '\n';

//        swap(h, h1);

        ans += mp[d][{h, h1}];
    }

    cout << ans << '\n';

    return 0;
}


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

int main(){
    
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
        b.at(i)=a.at(i);
    }
    sort(b.begin(),b.end());
    
    int num1,num2;
    num1=b.at(n/2-1);
    num2=b.at(n/2);

    for(int i=0; i<n; i++){
        if(a.at(i)<=num1) cout << num2 << endl;
        else cout << num1 << endl;
    }

}

Measured memory_bytes: 4808
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int a[2][110];
int b[110];

int main() {
    int n;
    cin >> n;
    rep(i,2) {
        rep(j,n) {
            int x;
            cin >> x;
            a[i][j+1] = a[i][j] + x;
        }
    }
    int ans = 0;
    rep(i,n) {
        ans = max(ans, a[0][i+1] + a[1][n] - a[1][i]);
    }
    cout << ans << endl;
}

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


const int END_OF_INPUT = 0;


int main() {
	int l;
	while (cin >> l && l != 0){
		int m, n;
		int total_money = 0;
		int achieve_month = 0;
		bool  isAchieved = false;
		for (int i = 0; i < 12; ++i){
			cin >> m >> n;
			total_money += (m - n);
			if (total_money >= l && isAchieved == false){
				achieve_month = (i + 1);
				cout << achieve_month << endl;
				isAchieved = true;
			}
		}
		if (achieve_month == 0){
			cout << "NA" << endl;
		}

	}
	


	


}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

map<ll,ll> prime;
int res;

void factorization(ll x){
    for(ll i=2;i*i<=x;i++){
        res=0;
        while(x%i==0){
            res++;
            x/=i;
        }
        if(prime[i]<res)prime[i]=res;
    }
    if(x!=1&&prime[x]==0)prime[x]=1;
    return;
}

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

ll mondiv(ll a,ll m=inf){
    ll b=m;ll u=1;ll v=0;
    while(b){
        ll t=a/b;
        a-=t*b;swap(a,b);
        u-=t*v;swap(u,v);
    }
    u%=m;
    if(u<0)u+=m;
    return u;
}

int main(){
    int n;cin>>n;
    vll a(n);
    rep(i,n){
        cin>>a[i];
        factorization(a[i]);
    }
    ll l=(ll)1;
    for(auto m=prime.begin();m!=prime.end();m++){
        l*=modpow(m->first,m->second);
        l%=inf;
    }
    //cout<<l<<endl;
    ll sum=(ll)0;
    rep(i,n){
        sum+=(l*mondiv(a[i]))%inf;
        sum%=inf;
    }
    cout<<sum<<endl;
}

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

int main() {
  string S;
  cin >> S;
  if(S=="AKIHABARA")cout << "YES";
  else if(S=="AKIHABAR")cout << "YES";
  else if(S=="AKIHABRA")cout << "YES";
  else if(S=="AKIHBARA")cout << "YES";
  else if(S=="KIHABARA")cout << "YES";
  else if(S=="AKIHABR")cout << "YES";
  else if(S=="AKIHBAR")cout << "YES";
  else if(S=="KIHABAR")cout << "YES";
  else if(S=="AKIHBRA")cout << "YES";
  else if(S=="KIHABRA")cout << "YES";
  else if(S=="KIHBARA")cout << "YES";
  else if(S=="KIHBRA")cout << "YES";
  else if(S=="KIHBAR")cout << "YES";
  else if(S=="KIHABR")cout << "YES";
  else if(S=="AKIHBR")cout << "YES";
  else if(S=="KIHBR")cout << "YES";
  else cout << "NO";
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

int main()
{
  int n, a[101], b[101]={0};
  int c=0, i, k=10000;
  cin >> n;

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

  for(int j=1; j<n; j++){
    if(a[j-1]==a[j]){
      c++;
      a[j] = a[j]+a[j+1];
    }
  }

  cout << c << endl;
  return 0;
}


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

const int MAX = 200010;
long long accum[MAX];
const long long INF = 1LL<<62;

int main(){
    long long i, j, k;
    long long N, X;
    cin >> N >> X;
    long long x[MAX];
    for(i=1; i<=N; i++) scanf("%lld", &x[i]);
    for(i=1; i<=N; i++) accum[i] = x[i] + accum[i-1];

    long long ans = INF;
    for(k=1; k<=N; k++){
        long long result = k*X;
        for(j=0; j<(N-1)/k+1; j++){
            int M = N - j*k;
            int m = max(0LL, M-k);
            long long c = j==0 ? 5 : 2*j+3;
            result += c * (accum[M] - accum[m]);
            if(result < 0) break;
        }
        if(result > 0) ans = min(ans, result);
    }
    cout << ans+N*X << endl;
    return 0;
}

Measured memory_bytes: 3328
def divisor(n):
  cd = []
  i = 1
  while i*i <= n:
    if n%i==0:
      cd.append(i)
      if i != n//i:
        cd.append(n//i)
    i += 1
  return cd
 
N, M = map(int, input().split())
cd = divisor(M)
cd.sort(reverse=True)
for d in cd:
  if M//d>=N:
    print(d)
    break

Measured memory_bytes: 9200
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e5+4;
int n;
int a[N];
int s[N],len;
int ans[N];
struct Edge {
	int v,nxt;
}e[N<<1];
int head[N],etot;
inline void adde(int u,int v) {
	e[++etot].nxt=head[u],e[etot].v=v,head[u]=etot;
}
inline int read() {
	int x=0;char c=getchar();
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x;
}
inline void discretize() {
	int temp[N];
	for (register int i=1;i<=n;++i) temp[i]=a[i];
	sort(temp+1,temp+n+1);
	for (register int i=1;i<=n;++i) a[i]=lower_bound(temp+1,temp+n+1,a[i])-temp;
}
inline void dfs(int p,int fa) {
	for (int i=head[p];~i;i=e[i].nxt) {
		int v=e[i].v;
		if (v^fa) {
			int x=a[v];
			if (x>s[len]) {
				s[++len]=x;
				ans[v]=len;
				dfs(v,p);
				s[len--]=0;
			}
			else {
				int pos=lower_bound(s+1,s+len+1,x)-s;
				ans[v]=len;
				int t=s[pos];
				s[pos]=x;
				dfs(v,p);
				s[pos]=t;
			}
		}
	}
}
int main() {
//	freopen("in.txt","r",stdin);
	memset(head,-1,sizeof(head));
	n=read();
	for (register int i=1;i<=n;++i) a[i]=read();
	for (register int i=1;i<n;++i) {
		int u=read(),v=read();
		adde(u,v);
		adde(v,u);
	}
	s[++len]=a[1],ans[1]=1;
	dfs(1,0);
	for (register int i=1;i<=n;++i) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 23452
#152 Low Elements
n = int(input())
seq = list(map(int,input().split()))
c = []
cnt = 0
for i in range(n):
    if i == 0:
        cnt+=1
        c.append(seq[0])
    else:
        if c[-1] >= seq[i]:
            cnt += 1
            c.append(seq[i])
        
print(cnt)
    

Measured memory_bytes: 24744
#include <bits/stdc++.h>
#include <math.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9

using namespace std;
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
const db pi = acos(-1);
const int N = 1e5 + 10;
string ch;
int main()
{
	cin >> ch;
	int n = ch.size();
	int x = ch.size() - 2;
	rep(i, 1, n - 1)
		if(ch[i - 1] != ch[i + 1]) break;
		else x --;
	rrep(i, n - 2, 1)
		if(ch[i - 1] != ch[i + 1]) break;
		else x --;
	if(x <= 0) puts("Second");
	else puts((ch.size() + (ch[0] == ch[n - 1] ? 1 : 0)) % 2 == 0 ? "Second" : "First");
	return 0;
}


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

#define INF 1000000007
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl << "\n" ;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		string s;
		cin >> s;
		if(s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
		else cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    if(s[1] == 'S'){
        if(s[0] == 'R' || s[2] == 'R'){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        if(s[0] == 'R'){
            if(s[2] == 'R'){
                cout << 3 << endl;
            }else{
                cout << 2 << endl;
            }
        }else{
            if(s[2] == 'R'){
                cout << 2 << endl;
            }else{
                cout << 1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3648
import numpy as np
H, W = map(int,input().split())

lst = []
for i in range(H):
    lst += [list(input())]

arr = np.array(lst)

lstH = []
for i in range(H):
    if all(arr[i,:] == '.'):
        lstH += [i]

arr = np.delete(arr, lstH, 0)

lstW = []

for j in range(W):
    if all(arr[:,j] == '.'):
        lstW += [j]

arr = np.delete(arr, lstW, 1)

for k in arr:
    for l in k:
        print(l, end = '')
    print()


Measured memory_bytes: 17052
///-----Bismillahir Rahmanir Rahim-----///

#include<bits/stdc++.h>
using namespace std;

///---FAST I/O---///
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///---DATA TYPE---///
typedef long long ll;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

///---LOOP---///
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)

///---I/O---///
#define sf scanf
#define pf printf

///---OTHERS---///
#define pb push_back
#define all(c)		c.begin(),c.end()
#define MK make_pair
#define F first
#define S second
#define endl '\n'


///---INITIALIZATION---//
#define mem(a,b) memset(a, b, sizeof(a) )

///---CALCULATE---///
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

///---BIT OPERATION---///
inline bool checkBit(ll n, int i)
{
    return n&(1LL<<i);
}
inline ll setBit(ll n, int i)
{
    return n|(1LL<<i);;
}
inline ll resetBit(ll n, int i)
{
    return n&(~(1LL<<i));
}

///------String/Char Related Functions-----///
string makeintString(int x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
string makellString(ll x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
char cpp(char c)
{
    return static_cast<char>(c + 1);
}

///------------Sorting STL----------///
struct func
{
    //this is a sample overloading function for sorting stl
    bool operator()(pii const &a, pii const &b)
    {
        if(a.F==b.F)
            return (a.S<b.S);
        return (a.F<b.F);
    }
};

///---CONSTANT---///
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

int main()
{
    Boost();

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        ll n,m,k,x,ans=0;
        cin>>n>>m>>k;
        vector<ll>a(n+1,0);
//        a.pb(0LL);
        for(ll i=1; i<=n; i++)
        {
            cin>>a[i];
//            a.pb(x);
            a[i]+=a[i-1];
        }
        vector<ll>b(m+1,0);
//        b.pb(0LL);
        for(ll i=1; i<=m; i++)
        {
            cin>>b[i];
//            b.pb(x);
            b[i]+=b[i-1];
        }
//        for(ll i=0; i<=m; i++)
//        {
//            cout<<b[i]<<" ";
//        }
//        cout<<endl;
        for(ll i=0; i<=n; i++)
        {
            if(a[i]>k) break;
            ll baki=k-a[i];
            ll lb=upper_bound(b.begin(),b.end(),baki)-b.begin();
            lb--;
            //cout<<" baki: "<<baki<<"lb: "<<lb<<endl;
            ans=max(ans,i+lb);
            //cout<<ans<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 6376