akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
inline int popcount(const int x) { return __builtin_popcount(x);}
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;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

int main() {
  int x;
  cin >> x;
  if (x < 600) cout << 8 << endl;
  else if (x < 800) cout << 7 << endl;
  else if ( x < 1000) cout << 6 << endl;
  else if (x < 1200) cout << 5 << endl;
  else if (x < 1400)  cout << 4 << endl;
  else if (x < 1600)  cout << 3 << endl;
  else if (x < 1800)  cout << 2 << endl;
  else cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#define INF 20000000

int H[200000001],heap_size=0;

int parent(int n){
  return ((double)1/2)*n;
}

int left(int n){
  return 2*n;
}

int right(int n){
  return 2*n+1;
}

void maxHeapify(int n){
  int l = left(n),r = right(n),largest,temp;
  if (l <= heap_size && H[l] > H[n]){
    largest = l;
  } else {
    largest = n;
  }
  if (r <= heap_size && H[r] > H[largest]){
    largest = r;
  }
  if (largest != n){
    temp = H[n];
    H[n] = H[largest];
    H[largest] = temp;
    maxHeapify(largest);
  }
}

void heapIncreaseKey(int i,int key){
  int temp;
  if (key < H[i]){
    printf("New key ha now key yori tittayi");
  }
  H[i] = key;
  while(i>1 && H[parent(i)] < H[i]) {
    temp = H[i];
    H[i] = H[parent(i)];
    H[parent(i)] = temp;
    i = parent(i);
  }
}

void maxHeapInsert (int key){
  heap_size++;
  H[heap_size] = -INF;
  heapIncreaseKey(heap_size, key);
}

int heapExtractMax(){
  int max;
  if (heap_size<1){
    return NULL;
  }
  max = H[1];
  H[1] = H[heap_size];
  heap_size--;
  maxHeapify(1);
  return max;
}

int main(){
  int i,x;
  char com[20];
  scanf("%d", &heap_size);

  while(1){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      maxHeapInsert(x);
    } else if ( com[0] == 'e' && com[1] == 'x'){
      printf("%d\n",heapExtractMax());
    } else if ( com[0] == 'e' && com[1] == 'n'){
      break;
    }

  }

  return 0;
}

Measured memory_bytes: 4692
#include<stdio.h>
#include<math.h>

int counting(long n){
    long i;
    long count=n;
    double l=sqrt(n);

    for(i=2;i<=l;i++){
        if(!(n%i)){
            while(!(n%i)){
                n/=i;
            }
            count=(count*(i-1))/i;
        }
    }

    if(n!=1)count=(count*(n-1))/n;

    return count;
}

int main(void){
    long n;
    long count;
    
    scanf("%ld", &n);

    count=counting(n);

    printf("%ld\n", count);
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

struct POINT
{
	int r, c;

	POINT(int r, int c) :r(r), c(c) {}
};

#define MOD (int)(1e9+7)

typedef long long ll;

int main()
{
	int H, W; cin >> H >> W;
	vector<vector<int>>A(H, vector<int>(W));
	vector<vector<int>>B(H, vector<int>(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];
	}

	vector<vector<vector<char>>>GRID(H, vector<vector<char>>(W, vector<char>(13000)));

	int v = abs(A[0][0] - B[0][0]);
	GRID[0][0][v + 6500] = true;
	GRID[0][0][-v + 6500] = true;

	queue<POINT>que;
	que.push(POINT(1, 0));
	que.push(POINT(W, 0));

	vector<vector<char>>used(H*W, vector<char>(H*W));
	while (que.size())
	{
		POINT p = que.front();
		que.pop();

		int pos = p.r;
		int pre_pos = p.c;
		if (used[pos][pre_pos])continue;
		used[pos][pre_pos] = true;

		int pr = pos / W;
		int pc = pos % W;	

		int ppr = pre_pos / W;
		int ppc = pre_pos % W;

		int value = abs(A[pr][pc] - B[pr][pc]);

		for (int j = 100; j <= 12900; j++)
		{
			if (GRID[ppr][ppc][j])
			{
				GRID[pr][pc][j + value] = true;
				GRID[pr][pc][j - value] = true;
			}
		}

		if(pc < W-1)que.push(POINT(pos+1, pos));
		if(pr < H-1)que.push(POINT(pos+W, pos));
	}

	int ans = 1e9;
	for (int j = 100; j <= 12900; j++)
	{
		int k = j-6500;
		if(GRID[H-1][W-1][j])ans = min(ans, abs(k));
	}

	cout<<ans<<endl;

	return 0;
}

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

using namespace std;
using ll = long long;

#define mx 1000006
bitset <mx> mark;
vector <int> primes;

void sieve() {
    mark[0] = mark[1] = 1;
    primes.push_back(2);
    int lim = sqrt(mx * 1.0) + 2;
    for (int i = 4; i < mx; i += 2) mark[i] = 1;
    for (int i = 3; i < mx; i += 2) {
        if (!mark[i]) {
            primes.push_back(i);
            if (i <= lim)
                for (int j = i * i; j < mx; j += i)
                    mark[j] = 1;
        }
    }
}

int main() {
    sieve();
    ll a, b;
    cin >> a >> b;
    set <ll> stA, stB;
    for (auto x: primes) {
        if (a % x == 0) {
            stA.insert(x);
            while (a % x == 0) {
                a /= x;
            }
        }
    }

    if (a > 1) stA.insert(a);

    for (auto x: primes) {
        if (b % x == 0) {
            stB.insert(x);
            while (b % x == 0) {
                b /= x;
            }
        }
    }

    if (b > 1) stB.insert(b);

    int ans = 0;
    for (auto x: stA) {
        if (stB.find(x) != stB.end()) ans++;
    }

    ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1020
N = int(input())
F = [[int(i) for i in input().split()] for i in range(N)]
P = [[int(i) for i in input().split()] for i in range(N)]

ans = -float('inf')
for i in range(1, 2 ** 10):
    A = []
    while i > 0:
        A.append(i % 2)
        i //= 2
    while len(A) < 10:
        A.append(0)
        
    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if F[j][k] == 1 and A[k] == 1:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans, tmp)
    
print(ans)

Measured memory_bytes: 3064
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val As = Array.tabulate(N)(i => in.nextLong - i - 1).sorted
  val median = if (N % 2 == 0) (As(N / 2 - 1) + As(N / 2)) / 2 else As(N / 2)
  println(As.map(i => math.abs(i - median)).sum)
}

Measured memory_bytes: 72028
n, k = map(int, input().split())
a = list(map(int, input().split()))
minus = [-x for x in a if x < 0]
plus = [x for x in a if x >= 0]

minus.sort()
plus.sort()

def cnt(x):
    ans = 0
    if x < 0:
        x = -x
        r = 0
        for num in minus[::-1]:
            while r < len(plus) and plus[r] * num < x:
                r += 1
            ans += len(plus) -  r
        return ans

    r = 0
    for num in minus[::-1]:
        if num * num <= x: ans -= 1
        while r < len(minus) and minus[r] * num <= x:
            r += 1
        ans += r
    r = 0
    for num in plus[::-1]:
        if num * num <= x: ans -= 1
        while r < len(plus) and plus[r] * num <= x:
            r += 1
        ans += r
    ans //= 2
    ans += len(minus) * len(plus)
    return ans

bottom = 0
top = 2*(10**18) + 2


while top - bottom > 1:
    mid = (top + bottom) // 2
    if cnt(mid - 10**18-1) < k:
        bottom = mid
    else:
        top = mid

print(int(top - 10**18-1))


Measured memory_bytes: 119556
w, h, x, y = (int(i) for i in input().split())
a1 = w*h/2
a2 = 0
if( ((w==h) and (x == y and not((x==0 and y==0) or (x==w and y==h)))) or ((w!=h) and (x==w/2) and (y==h/2))  ):
    a2=1
print(a1, a2)

Measured memory_bytes: 3060
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <math.h>

using namespace std;

int N,K;
int D[10];
int S;
int KETA;
int Y[6];
int ANS=0;
int kari;
int main(){
	scanf("%d %d",&N,&K);
	for(int i=0;i<K;i++){
		scanf("%d",&S);
		D[S]=-1;
	}
	for(int l=N;;l++){
		kari=l;
		KETA=(int)log10((double)l);
		for(int i=0;i<=KETA;i++){
			if(kari>9){
				Y[i]=kari-(int)floor(kari/10)*10;
				kari=(kari-Y[i])/10;
			}
			else Y[i]=kari;
		}
		for(int i=0;i<=KETA;i++){
			if(D[Y[i]]==-1)i=KETA;
			else if(i==KETA){ANS=l;break;}	
		}
		if(ANS>0)break;		
	}
	printf("%d\n",ANS);
return 0;
}

Measured memory_bytes: 256
import sys
import math
import bisect
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')

def main():
    n = int(input())
    l = list(map(int,input().split()))
    l.sort()
    ans = 0

    for i in range(n):
        a = l[i]
        for j in range(i+1, n):
            b = l[j]
            x = bisect.bisect_left(l, a+b)
            ans += max(x - (j+1), 0)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 42204
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define abs(a,b) (a-b>0?a-b:b-a)


int main(){
    vi a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a);
    cout << (a[1]-a[0])+(a[2]-a[1]) << endl;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int> mp;
    rep(i,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    int ans = mp.size();
    if ((n - ans) % 2 != 0) {
        ans --;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
//
// using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i < 10; i++) {
    if(n % i == 0 && n / i <= 9 && n / i >= 1){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))

s1 = [a1[0]]
s2 = [a2[-1]]
for i in range(1, n):
  s1.append(s1[i-1] + a1[i])
  s2.append(s2[i-1] + a2[-i-1])
  
ans = 0
for i in range(n):
  ans = max(ans, s1[i]+s2[n-1-i])
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
struct node{
	int pre, to, val;
}edge[200010];
int head[100010], tot;
int k;
void add(int u, int v, int l) {
	edge[++tot] = node{head[u], v, l};
	head[u] = tot;
}
int dis[100010], vis[100010];
queue<int> q;
void spfa() {
	memset(dis, 0x3f, sizeof(dis));
	dis[1] = 1;
	vis[1] = 1;
	q.push(1);
	while (!q.empty()) {
		int x = q.front(); q.pop();
		for (int i = head[x]; i; i = edge[i].pre) {
			int y = edge[i].to;
			if (dis[y] > dis[x] + edge[i].val) {
				dis[y] = dis[x] + edge[i].val;
				if (!vis[y]) {
					vis[y] = 1;
					q.push(y);
				}
			}
		}
		vis[x] = 0;
	}
}
int main() {
	cin >> k;
	for (int i = 0; i < k; i++) {
		add(i, (i + 1) % k, 1);
		add(i, i * 10 % k, 0);
	}
	spfa();
	cout << dis[0];
	return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  bool sec = true;
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    if (a % 2 == 1) {
      sec = false;
    }
  }
  if (sec) {
    cout << "second" << endl;
  }
  else {
    cout << "first" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())
lst = list(map(int,input().split()))

def pri(lst):
    for i in range(len(lst)-1):
        print(lst[i],end=" ")
    print(lst[-1])

pri(lst)
for i in range(1,n):
    v = lst[i]
    j = i-1
    while True:
        if j < 0:
            lst[0] = v
            break
        if lst[j] > v:
            lst[j+1] = lst[j]
            j -= 1
        else:
            lst[j+1] = v
            break
    pri(lst)



Measured memory_bytes: 5976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int a,b,c,d,e,f,i,j,k,l;
    ll answ=0,anss=0;
    double density=INT_MIN;
    cin>>a>>b>>c>>d>>e>>f;
    int a1=f/a;
    int b1=f/b;
    for(i=0; i<=a1; i++)
    {
        for(j=0; j<=b1; j++)
        {
            ll water=(a*i+b*j)*100;
            if(water>f)
                break;
            ll temp=e*(water/100);
            ll c1=temp/c;
            ll d1=temp/d;
            for(k=0;k<=c1;k++)
            {
                for(l=0;l<=d1;l++)
                {
                    ll salt=c*k+l*d;
                    if(salt>temp)
                        break;
                    if(salt+water>f)
                        break;
                    double dentemp=((100.0*salt)/((double)(salt+water)));
                    if(dentemp>density)
                    {
                        density=dentemp;
                        answ=water;
                        anss=salt;
                    }
                }
            }

        }
    }
    cout<<answ+anss<<' '<<anss<<endl;
    return 0;
}


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

using namespace std;

int main(){
  int N, T;
  cin >> N >> T;
  vector<int> A(N);
  for(int i = 0; i < N; i++) cin >> A[i];
  vector<int> max_sell(N, 0);
  max_sell[N - 1] = A[N - 1];
  for(int i = N - 1; i > 0; i--){
    max_sell[i - 1] = max(A[i - 1], max_sell[i]);
  }
  
  int max_diff = 0;
  for(int i = 0; i < N - 1; i++){
    max_diff = max(max_sell[i + 1] - A[i], max_diff);
  }
  
  int cnt = 0;
  for(int i = 0; i < N - 1; i++){
    if(max_sell[i + 1] - A[i] == max_diff){
      cnt++;
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int H, W, K;
    cin >> H >> W >> K;
    V(string) cake(H);
    rep(i, H) cin >> cake[i];

    V(bool) done(H, false);
    vvi res(H, vi(W, 0));
    int now = 1;
    rep(i, H) {
        int cnt = 0;
        rep(j, W) {
            if(cake[i][j] == '#') {
                done[i] = true;
                FOR(k, j-cnt, j+1) {
                    res[i][k] = now;
                }
                now += 1;
                cnt = 0;
            } else cnt++;
            if(j==W-1 && cnt && done[i]) {
                FOR(k, j-cnt, j+1) {
                    res[i][k] = now-1;
                }
            }            
        }  
    }

    rep(i, H) {
        if(!done[i]) continue;
        else {
            for(int j=i-1; j>=0; j--) {
                if(done[j]) break;
                rep(k, W) res[j][k] = res[i][k];
            }
            for(int j=i+1; j<H; j++) {
                if(done[j]) break;
                rep(k, W) res[j][k] = res[i][k];
            }
        }
    }


    rep(i, H) {
        rep(j, W) {
            cout << res[i][j] << " ";
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1664
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
// #define mp make_pair
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
// #define int ll
vector<ll> ft(1, 1LL);
/*======================================================================*/
const int faxsize = 50;
vector<pair<int, int> >fax[faxsize];

void solve(){
    int a, b;
    cin >> a >> b;
    if(a <= b)cout << "unsafe\n";
    else cout << "safe";
}
signed main() {
    rep(i, 2, faxsize+1)if(fax[i].size() == 0)repc(j, i, faxsize+1, i){int k = j, c = 0;while(k%i == 0)k/= i, c++;fax[j].push_back({i, c});}
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

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

int main() {
  ll x, y;
  cin >> x >> y;

  ll ans = 0;
  for (ll i = x; i <= y; i *= 2) ans++;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag){
    if (flag) cout << "Yes" << endl; else  cout << "No" << endl;
}

void ansYES(bool flag){
    if (flag) cout << "YES" << endl; else  cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

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

int nanko(string s,Int n,Int i){
    Int length = min(n - i - 1,i);
    Int ans = 0;
    for (int k = i-length;k < i;k++){
        if (s.at(k) == 'R' && s.at(i +  (i - k) == 'B')) ans++;
    }
    return ans;
}


int main(){
    double x;
    cin >> x;
    double z = 100;
    int cnt = 0;
    while(z < x) {
        cnt++;
        z *= 1.01;
        z = floor(z);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3760
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n = 0;
	static int m = 0;
	
	public static void main(String[] args) {
		n = sc.nextInt();
		m = sc.nextInt();
		ArrayList<Integer> mDivisors = getSortedDivisors(m);
		int ans = 0;
		for(int i = 0; i < mDivisors.size(); ++i) {
			int div = mDivisors.get(i);
			if(div > m / n) break;
			ans = div;
		}
		System.out.println(ans);
	}
	
	static ArrayList<Integer> getSortedDivisors(int m) {
		ArrayList<Integer> divisors = new ArrayList<>();
		for(int i = 1; i * i <= m; ++i) {
			if(i * i == m) divisors.add(i);
			else if(m % i == 0) {
				divisors.add(i);
				divisors.add(m / i);
			}
		}
		Collections.sort(divisors);
		return divisors;
	}
}

Measured memory_bytes: 23892
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt(),b=sc.nextInt();
        sc.close();
        if(a*b%2==0)System.out.print("No");
        else System.out.print("Yes");
    }
}

Measured memory_bytes: 22740
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int M = scanner.nextInt();
		int a = 1;
		for (int i = 0; i < M; i++) {
			a *= 2;
		}
		System.out.println((1900 * M + 100 * (N - M)) * a);
	}
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int c[3][3];
int main(){
  for(int i=0; i<3; i++)
    for(int j=0; j<3; j++)
      cin >> c[i][j];
  bool flag = true;
  for(int i=0; i<2; i++)
    for(int j=0; j<2; j++)
    if(c[i][j+1] - c[i][j] != c[i+1][j+1] - c[i+1][j])
      flag = false;
    
  for(int i=0; i<2; i++)
  for(int j=0; j<2; j++)
    if(c[i+1][j] - c[i][j] != c[i+1][j+1] - c[i][j+1])
      flag = false;
    
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
  }
    


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

int n,m,q;
static const int N=100005;
vector<int> G[N];
void branch(int a,int b){
    G[a].push_back(b);
    G[b].push_back(a);
}
int color[N];
void dfs(int r,int c){
    stack<int>s;
    s.push(r);
    while(!s.empty()){
        int u=s.top();s.pop();color[u]=c;
        for(int i=0;i<G[u].size();i++){
            if(color[G[u][i]]==0)s.push(G[u][i]);
        }
    }
}
void assigncolor(){
    int id=1;
    for(int u=0;u<n;u++){
        if(color[u]==0){
            dfs(u,id);
            id++;
        }
    }
}
void check(int a,int b){
    if(color[a]==color[b])printf("yes");
    else printf("no");
    printf("\n");
}
int main() {
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int a,b;cin>>a>>b;
        branch(a,b);
    }
    assigncolor();
    cin>>q;
    for(int i=1;i<=q;i++){
        int a,b;cin>>a>>b;check(a,b);
    }
    return 0;
}

Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
char s[200010];
bool a[200010];
 
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	for (int i = 0; i < n; i ++) 
		a[i] = (s[i] == 'B');
	int x = 0, st = a[0];
	while (x < n && k)
	{
		k --;
		if (!st) {st = 1; continue;}
		x ++;
		if (x < n) st = a[x] ^ (x & 1); 
		else st = (n & 1) ^ 1;
	}
	if (k) 
		if (!st) 
			st ^= (k & 1);
	putchar(st + 'A');
	for (int i = 1; i < n; i ++)
		if (i + x < n) putchar((a[i + x] ^ (x & 1)) + 'A'); 
		else putchar(((n - i + 1) & 1) + 'A');
	return 0;
}

Measured memory_bytes: 768
from math import factorial as fact
import math
import sys
from itertools import product
import numpy as np
from collections import Counter
import datetime
from collections import deque
from bisect import bisect_left, bisect_right
import heapq



#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))


n,m=input2()
AB=[[] for _ in range(m)]


for i in range(n):
	a,b=input2()
	if a-1 < m: #報酬受取日がmを超える仕事は除外する
		AB[a-1].append(-b) #heapqの仕様のため，-を追加

ans=0
heap=[]
for i in range(m):
	for b in AB[i]:
		heapq.heappush(heap,b)
	#最大値をheapから取り出し
	if len(heap)>0:
		MAX=heapq.heappop(heap)
		ans+= -MAX
print(ans)












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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


ll hoge(ll L,ll R) {
	if(L==R) return 1;
	
	ll r=1;
	while(r*2<=R) r*=2;
	
	if(L&r) return hoge(L^r,R^r);
	
	ll k=1;
	while(k<=(R^r)) k*=2;
	
	//only a
	ll ret=r-L;
	
	// only B
	ll x=r,y=r+k-1;
	// A+B
	ll a=r+L,b=2*r-1;
	
	if(y<a) return ret+y-x+1+b-a+1;
	else return ret+b-x+1;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	ll A,B;
	
	cin>>A>>B;
	cout<<hoge(A,B)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main () 
    {
        String[] line = Console.ReadLine().Split(' ');
        long n = long.Parse(line[0]);
        long k = long.Parse(line[1]);

        long[] list = new long[n];
        line = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            list[i] = long.Parse(line[i]);
        }
        Array.Sort(list);
        long ans = 0;
        for(int i = 0; i < k; i++)
        {
            ans += list[i];
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27884
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#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;
 
/*
template <typename T>  using ordered_set =
    tree<T, null_type, less<T>,   /// greater<T> for sorting decreasingly
    rb_tree_tag, tree_order_statistics_node_update>;
*/

#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;


int main(){
    ll n,x,s=0,f=0;
    sfl(n);
    for(ll i=1;i<=n;i++){
        sfl(x);
        if(x&1){
            f=1;
        }
    }
    if(f){
        printf("first\n");
    }
    else{
        printf("second\n");
    }
    return 0;
}

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

int main(){
    long long n;
    cin>>n;
    if(n==0 || n==1){ cout<<0; return 0;}
    vi a(n);
    for(vi::iterator i=a.begin(); i!=a.end(); i++) cin>>*i;
    long long ans = 0;
    for(vi::iterator i=a.begin()+1; i!=a.end(); i++){
        if(*(i-1)>*(i)){ ans += *(i-1) - *(i); *(i) = *(i-1);}
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4760
import java.util.Scanner;


public class Main {

	static int[][] board;
	static boolean[][] delete;
	static boolean[][] check;
	static int sum;
	static int H;

	public static void main(String[] args){

		Scanner sc=new Scanner(System.in);

		while(true){


			//??\??????
			H = sc.nextInt();
			if(H == 0)
				return;

			board = new int[H][5];
			delete = new boolean[H][5];
			check = new boolean[H][5];

			int sumarray[] = new int[H];

		     sum = 0;


			for(int i=0;i<H;i++)
			{
				for(int j=0;j<5;j++)
				{
					board[i][j] = sc.nextInt();
					delete[i][j] = false;
					check[i][j] = false;
				}
			}

			//??????
			boolean flag = true;
			int count=0;

			while(flag)
			{

			fall();
			for(int j=0;j<5;j++)
			{
				for(int i=H-1;i>=0;i--)
					check[i][j] = false;

			}
			del();
				int x=0;
				int y=0;
				boolean fl = true;

				for(x=0;x<H;x++)
				{
					for(y=0;y<5;y++)
					{


			//			System.out.print(" "+board[x][y]);
					   if(delete[x][y]){
						   fl = false;

					//	   break;
					   }
					}
			//		System.out.println();
				}

				//System.out.println();
				if(fl)
				{
					flag = false;
				}
		}

			System.out.println(sum);


		}//while??????

		}//main?????????


	public static int check(int i,int j){

		if(i < 0)
			return 0;

		if(check[i][j])
			return check(i-1,j);
		else
		{
			check[i][j] = true;
			return board[i][j];
		}

		/*
		if(i < 0)
			return 0;
		else if(check[i][j])
			return check(i-1,j);
		else
			return board[i][j];
		*/

	}

	public static boolean fall()
	{

		for(int j=0;j<5;j++)
		{
			int count = 0;
			for(int i=H-1;i>=0;i--)
			{
				board[i][j] = check(i,j);
				check[i][j] = true;
			    if(delete[i][j])
			    	delete[i][j] = false;


				/*
				int tmp =count;
				if(delete[i][j])
				{
					count = count(i,j,count);
					delete[i][j] = false;
				}
				if(i -count >0 && delete[i-count][j])
				{
					delete[i-count][j] = false;
					count = count(i-count,j,count);
				}
				if(i-count < 0)
					board[i][j] = 0;
				else if(board)
				    board[i][j] =board[i-(count+tmp)][j];
				else
					board[i][j] = board[i-count][j];

*/
			}
		}
		return true;

	}

	public static int count(int i,int j,int count){

		count++;
		if(i > 0&&  delete[i-1][j] == true)
		{
			return count(i-1,j,count);
		}
		else
			return count;

	}

	public static void del()
	{

		for(int i=0;i<H;i++)
		{
			int num = board[i][0];
			int count = 1;


			for(int j=1;j<5;j++)
			{



				if(board[i][j] == num && num !=0)
				{
					count++;

					if(j == 4 && count >= 3)
					{
						//?????£??¨?????????????????????
						sum += count * num;
						for(int k=0;k<count;k++)
						{
							delete[i][j-k] = true;
							check[i][j-k] = true;
						}
					}
				}
				else
				{
					if(count >= 3)
					{
						//?????£??¨?????????????????????
						sum += count * num;
						for(int k=1;k<=count;k++)
						{
							delete[i][j-k] = true;
							check[i][j-k] = true;
						}
					}
					num = board[i][j];
					count = 1;
				}

			}

		}//??????????????????



	}


}

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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//プロトタイプ宣言
void faster(void);
template <class T>
T gcd(T , T);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);


int main(){
  faster();
  ll a,b,k;
  cin >> a >> b >> k;
  if(a>=k) a -= k;
  else{
    k -= a;
    a = 0;
    if(b>=k) b -= k;
    else{
      k -= b;
      b = 0;
    }
  }
  cout << a << " " << b;
}



























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
template <class T>
T gcd(T a, T b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 



Measured memory_bytes: 256
import sys

N, K = map(int, input().split())
H = list(map(int, sys.stdin.readline().rsplit()))

dp = [10 ** 9] * (N + K)
dp[0] = 0

for i in range(N):
    for k in range(1, K + 1):
        if i + k < N:
            dp[i + k] = min(
                dp[i + k],
                dp[i] + abs(H[i] - H[i + k])
            )

print(dp[N - 1])


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

int x, y, z;
int ta = 0;

int main() {
	cin >> x >> y >> z;
	for (int i = 1;; i++) {
		if (i*y + (i + 1)*z > x) {
			break;
		}
		else {
			ta = i;
		}
	}
	cout << ta << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,m ; cin >> n >> m ;
	vector<vector<pll>> g(n,vector<pll>(0)) ;
	vvll d(n,vll(n,INF)) ;
	for(int i=0;i<m;i++){
		ll a,b,c ;
		cin >> a >> b >> c ;
		a-- ; b-- ;
		g.at(a).emplace_back(b,c) ;
		g.at(b).emplace_back(a,c) ;
		d.at(a).at(b) = c ;
		d.at(b).at(a) = c ;
	}
	for(int i=0;i<n;i++) d.at(i).at(i) = 0 ;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) for(int k=0;k<n;k++) d.at(j).at(k) = min(d.at(j).at(k),d.at(j).at(i)+d.at(i).at(k)) ;
	ll cnt = 0 ;
	for(int i=0;i<n;i++){
		for(int j=0;j<g.at(i).size();j++){
			ll pi = i ;
			ll pj = g.at(i).at(j).first ;
			ll cost = g.at(i).at(j).second ;
			bool ok = false ;
			for(int k=0;k<n;k++){
				if(d.at(k).at(pi)+cost==d.at(k).at(pj)) ok = true ;
			}
			cnt += ok ;
		}
	}
	cnt /= 2 ;
	cout << m-cnt << endl ;
}


Measured memory_bytes: 384
#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 pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<P> s(m);
    vector<int> ans(n, 0);
    ans[0] = 1;
    rep(i, m){
        cin >> s[i].first >> s[i].second;
        s[i].first--;
        ans[s[i].first]=s[i].second;
    }
    bool ok = true;
    rep(i, m){
        if(ans[s[i].first] != s[i].second)ok = false;
    }
    if(ok){
        if(n != 1 && ans[0] == 0)cout << -1;
        else if(n == 1 && m == 0)cout << 0;
        else rep(i, n)cout << ans[i];
    }
    else cout << -1;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include <unordered_map> 
#include<vector>
#include<queue>
#include <bits/stdc++.h> 
#include<string>
#define ll long long int
#define N 3001
#define MOD 1e9+7
using namespace std;
string s1,s2;
template <typename T> void max_self(T &a, T b){
	if(b>=a){
		a = b;
	}
}
ll dp[N][N];
int vis[N][N];
ll a[N];
//itn dp[N];
ll solve(int i, int j){
	if(i==j)
		return a[i];
	if(i>j)
		return 0;

	if(vis[i][j])
		return dp[i][j];
	ll pos1a = a[i] + solve(i+1,j-1);
	ll pos1b = a[i] +solve(i+2,j);
 	ll pos2a = a[j] + solve(i+1,j-1);
 	ll pos2b = a[j] + solve(i,j-2);
 	ll pos1 = min(pos1a,pos1b);
 	ll pos2 = min(pos2a,pos2b);
 	ll ans = max(pos1,pos2);
 	dp[i][j] = ans;
 	vis[i][j] = 1;
 	return ans;
}
int main(){
	int n;
	cin>>n;
	ll sum = 0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	ll x = solve(1,n);
	cout<<2*x-sum;
	
}


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

d = {N}
temp = N
for i in range(2, 10**7):
    if temp%2 == 0:
        temp //= 2
    else:
        temp = 3*temp + 1
    if {temp} & d:
        print(i)
        break
    else:
        d.add(temp)

Measured memory_bytes: 9004
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
  if p[i-1]<p[i] and p[i]<p[i+1]:
    ans += 1
  if p[i-1]>p[i] and p[i]>p[i+1]:
    ans += 1
print(ans)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <string>
#include <string.h>
#include <limits>
#include <utility>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <chrono>

using namespace std;

namespace
{

}

#if 1
int main()
{
	int a, b, c;
	cin >> a;
	cin >> b;
	cin >> c;

	int aa = b < c ? b : c;

	int ab = b + c - a;
	ab = ab < 0 ? 0 : ab;

	printf("%d %d", aa, ab);
	return 0;
}
#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=512;
int d[mx];
int o[mx];
int ans[mx*mx];
bool cmp(int i,int j){ return d[i]<d[j]; }
int main(){
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%d",d+i);
    o[i]=i;
    ans[d[i]]=i;
  }
  sort(o+1,o+1+n,cmp);
  int lft=1;
  bool ok=true;
  for(int i=1;i<=n && ok;i++){
    int v=o[i];
    int cnt=0;
    while(lft<d[v] && cnt<v-1){
      if(ans[lft]==0){
        ans[lft]=v;
        cnt++;
      }
      lft++;
    }
    if(cnt<v-1)ok=false;
  }
  int rht=n*n;
  for(int i=n;i>=1;i--){
    int v=o[i];
    int cnt=0;
    while(rht>d[v] && cnt<n-v){
      if(ans[rht]==0){
        ans[rht]=v;
        cnt++;
      }
      rht--;
    }
    if(cnt<n-v)ok=false;
  }
  if(ok){
    puts("Yes");
    for(int i=1;i<=n*n;i++){
      if(i!=1)printf(" ");
      printf("%d",ans[i]);
    }
    puts("");
  }
  else puts("No");
  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
typedef long long ll;
#define inf 0x3f3f3f3f
int main() {
    int N; scanf("%d", &N);
    ll powsum = 0; ll addsum = 0;
    for (int i = 1; i <= N; i++) {
        int x; scanf("%d", &x);
        powsum += x*x;
        addsum += x;
    }
    ll P = addsum / (1ll * N);
    // printf("P = %lld\n", P);
    ll res = inf; 
    res = std::min(res, 0 - 2 * P * addsum + N * P * P);
    P--;
    res = std::min(res, 0- 2 *P * addsum + N * P * P);
    P++; P++;
    res = std::min(res, 0- 2 *P * addsum + N * P * P);
    printf("%lld\n", powsum + res);
}

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

int SG[100001];

vector<int> e[100001];

void dfs(int x,int p){
	for(int it:e[x])
		if(it!=p){
			dfs(it,x);
			SG[x]^=(1+SG[it]);
		}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1,u,v;i<n;i++)
		cin>>u>>v,e[u].emplace_back(v),e[v].emplace_back(u);
	dfs(1,0);
	if(SG[1])
		cout<<"Alice"<<endl;
	else
		cout<<"Bob"<<endl;
}


Measured memory_bytes: 12416
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int to[30][5010];
ll sum[30][5010];
ll mx[30][5010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vi p(n), c(n);
    cin >> p >> c;
    rep(i, n) {
        to[0][i] = p[i] - 1;
        sum[0][i] = mx[0][i] = c[p[i] - 1];
    }
    rep(i, 29) {
        rep(j, n) {
            to[i + 1][j] = to[i][to[i][j]];
            sum[i + 1][j] = sum[i][j] + sum[i][to[i][j]];
            mx[i + 1][j] = max(mx[i][j], sum[i][j] + mx[i][to[i][j]]);
        }
    }
    ll ans = -linf;
    rep(i, n) {
        int pos = i, nk = k;
        ll nsum = 0, nmx = -linf;
        int now = 0;
        while (nk > 0) {
            if (nk & 1) {
                chmax(nmx, nsum + mx[now][pos]);
                nsum += sum[now][pos];
                pos = to[now][pos];
            }
            nk >>= 1;
            now++;
        }
        chmax(ans, nmx);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6612
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    GI(N);
    GVI(H,N);
    int last=H[0];
    int ans=1;
    for(int i=1;i<N;++i){
        if(last<=H[i])ans++;
        last=max(last,H[i]);
    }
    print(ans);
    return 0;
}

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

int main(){
	int H; cin>>H;
	int *A;
	A = new int[H];
	A = A-1;
	for(int i=1;i<=H;i++)
		cin>>A[i];

	for(int i=1;i<=H;i++){
		cout<<"node "<<i<<": key = "<<A[i]<<", ";
		if(i!=1){
			int parent = i/2;
			cout<<"parent key = "<<A[parent]<<", ";
		}
		int left,right;
		left = 2*i; right = left+1;
		if(left>0 && left<=H)
			cout<<"left key = "<<A[left]<<", ";
		if(right>0 && right<=H)
			cout<<"right key = "<<A[right]<<", ";
		cout<<endl;
	}

	delete [] (A+1);
} 

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

int count(int n) {
  int c = 0;
  while(n) {
    c++;
    n /=10;
  }
  return c;
}

signed main() {
  int N; cin >> N;
  int ans = 0;
  for(int i=1; i<=N; i++) if(count(i) % 2) ++ans;
  cout << ans << endl;
}


Measured memory_bytes: 256