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

#define MAX 100000

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

node d[MAX+1];
int depth[MAX+1];

int dep(int key, int num){
  depth[key] = num;
  if(d[key].r != -1) dep(d[key].r, num);
  if(d[key].l != -1) dep(d[key].l, num+1);
}


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

  for(int i = 0; i < n; i++){
    d[i].l = -1;
    d[i].r = -1;
    d[i].p = -1;
  }

  for(int i = 0; i < n; i++){
    int id, k, tmp;
    cin >> id >> k;
    for(int j = 0; j < k; j++){
      int c;
      cin >> c;
      if(j == 0) d[id].l = c;
      else d[tmp].r = c;
      tmp = c;
      d[c].p = id;
    }
  }
  int x;
  for(int i = 0; i < n; i++){
    if(d[i].p == -1) x = i;
  }
  dep(x,0);
  for(int i = 0; i < n; i++){
    cout << "node " << i << ":" << " parent = " << d[i].p << ", depth = " << depth[i] << ",";
    if(d[i].p == -1) cout << " root, ";
    else if(d[i].l != -1) cout << " internal node, ";
    else if(d[i].l == -1) cout << " leaf, ";

    cout << "[";
    int judge = 0;
    for(int v = d[i].l; v != -1; v = d[v].r){
      if(judge != 0) cout << ", ";
      cout << v;
      judge = 1;
    }
    cout << "]" << endl;

  }




}

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

int main() {
  int n;
  cin>>n;
  bool edge[n+1][n+1];
  int k;
  if (n % 2 == 0) {
    k = n + 1;
  } else {
    k = n;
  }
  for (int i=1; i<n+1; i++) {
    for (int j=1; j<n+1; j++) {
      if (i == j || i + j == k) {
        edge[i][j] = false;
      } else {
        edge[i][j] = true;
      }
    }
  }
  int m = 0;
  for (int i=1; i<n+1; i++) {
    for (int j=i+1; j<n+1; j++) {
      m += edge[i][j];
    }
  }
  cout<<m<<endl;
  for (int i=1; i<n+1; i++) {
    for (int j=i+1; j<n+1; j++) {
      if (edge[i][j]) {
        cout<<i<<" "<<j<<endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N, L, max = 0, sum = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &L);
		if (L > max) max = L;
		sum += L;
	}
	if (max < sum - max) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);i++)
vector<int> v[3],ttl[3];

int main(){
  int N,W,w1,v1;
  ll ans=0;
  cin>>N>>W>>w1>>v1;
  v[0].emplace_back(v1);
  for(int i=2;i<=N;i++){
    int wt,vt;
    cin>>wt>>vt;
    wt-=w1;
    v[wt].emplace_back(vt);
  }
  REP(i,4) if(v[i].size()>0) sort(v[i].rbegin(),v[i].rend());

  REP(i,4){
    ttl[i].emplace_back(0);
    REP(j,v[i].size()){
      ttl[i].emplace_back(ttl[i].at(j)+v[i].at(j));
    }
  }

  REP(i,ttl[0].size()){
    REP(j,ttl[1].size()){
      REP(k,ttl[2].size()){
        REP(l,ttl[3].size()){
          ll wght=(ll)w1*(ll)(i+j+k+l)+(ll)(j+2*k+3*l);
          if(wght<=(ll)W){
            ans=max(ans,(ll)ttl[0].at(i)+(ll)ttl[1].at(j)+(ll)ttl[2].at(k)+(ll)ttl[3].at(l));
          }
        }
      }
    }
  }

  cout<<ans;
}

Measured memory_bytes: 3628
import java.util.HashSet;
import java.util.Scanner;
import java.util.stream.IntStream;

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

        char[][] map = new char[h][w];
        for (int i = 0; i < h; i++) {
            map[i] = sc.next().toCharArray();
        }

        HashSet<Integer> yset = new HashSet<>(), xset = new HashSet<>();
        IntStream.range(0, h).forEach(yset::add);
        IntStream.range(0, w).forEach(xset::add);

        outer:
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++)
                if (map[y][x] != '.') continue outer;
            yset.remove(y);
        }
        outer:
        for (int x = 0; x < w; x++) {
            for (int y = 0; y < h; y++)
                if (map[y][x] != '.') continue outer;
            xset.remove(x);
        }
        
        yset.forEach(y -> {
            xset.forEach(x -> System.out.print(map[y][x]));
            System.out.println();
        });
    }
}

Measured memory_bytes: 29340
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr ll INF = 1e18;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i,h) cin >> a[i];
  vector<int> oh(h, 0), ow(w, 0);

  for (int i = 0; i < h; i++) {
    bool ok = false;
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') ok = true;
    }
    if (!ok) oh[i] = 1;
  }
  for (int i = 0; i < w; i++) {
    bool ok = false;
    for (int j = 0; j < h; j++) {
      if (a[j][i] == '#') ok = true;
    }
    if (!ok) ow[i] = 1;
  }

  for (int i = 0; i < h; i++) {
    bool f = false;
    for (int j = 0; j < w; j++) {
      if (oh[i] || ow[j]) continue;
      f = true;
      cout << a[i][j];
    }
    if (f) cout << endl;
  }
  return 0;
} 

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main (int argc, char * const argv[]) {
    // insert code here...
    int n, N=1000000;
	bool p[1000000]={0};

	for(int i=2;i<N;i++){
		if(!p[i]){
			for(int j=i+i;j<N;j+=i){
				p[j]=1;
			}
		}
	}
	
	while(cin >> n){
		int count =0;
		for(int i=2;i<=n;i++){
			if(!p[i])count++;
		}
		cout<<count<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 2140
#AtCoder Begginer Contest 087 B Coins

a = int(input()) #counts of 500
b = int(input()) #counts of 100
c = int(input()) #counts of 50
x = int(input()) #total value

cnt = 0

def judge(x,a,b,c):
    if 500*a + 100 * b + 50*c == x:
        return True
    
for i in reversed(range(a+1)):
    if judge(x, i, 0, 0):
                cnt += 1
                continue
    for j in reversed(range(b+1)):
        if judge(x, i, j, 0):
                cnt += 1
                continue
        for k in reversed(range(c+1)):
            if judge(x, i, j, k):
                cnt += 1

print(cnt)







Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=100050;
const int mod=1e9+7;
int dp[2][N];
void add(int &a, int b)
{ a+=b;if(a>=mod) a-=mod;}
void sub(int &a, int b)
{ a-=b;if(a<0) a+=mod;}
void mul(int &a, int b)
{ a=(ll)a*b%mod;}
vector<int> E[N];
void DFS(int u, int p)
{
dp[0][u]=dp[1][u]=1;
for(int v:E[u]) if(v!=p)
{
DFS(v,u);
mul(dp[1][u],dp[0][v]);
mul(dp[0][u],dp[0][v]+dp[1][v]);
}
}
int main()
{
int n,u,v;
scanf("%i",&n);
for(int i=1;i<n;i++)
scanf("%i %i",&u,&v),
E[u].pb(v),
E[v].pb(u);
DFS(1,0);
int ans=dp[0][1];
add(ans,dp[1][1]);
printf("%i",ans);
return 0;
}

Measured memory_bytes: 13440
#include <iostream>
#include <string>

using namespace std;

int main(){
    int n;
    string s;

    cin >> n >> s;

    char* cstr = new char[s.size() + 1];
    char_traits<char>::copy(cstr, s.c_str(), s.size() + 1);

    int total = 0;
    char latest = '0';
    for (int i = 0; i < s.size(); i++)
    {
        if(latest != cstr[i]){
            total++;
        }
        latest = cstr[i];
    }

    cout << total << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		List<Edge> edges = new ArrayList<>();
		long INF = Long.MAX_VALUE / 2;
		for(int i=0; i<M; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			long c = sc.nextLong();

			edges.add(new Edge(a, b, -c));
		}

		BF bf = new BF(N, edges, INF);
		long[] weights = bf.getMinWeightArray(1);
		long ans = weights[N-1];

		boolean[] negative = new boolean[N];
		Arrays.fill(negative, false);
		for(int i=0; i<N; i++) {
			for(int j=0; j<edges.size(); j++) {
				Edge e = edges.get(j);

				if(weights[e.from-1] == INF)
					continue;

				//すでに最短の重みの和になっているにもかかわらず、更新する場合負の閉路
				if(weights[e.to-1] > weights[e.from-1] + e.weight) {
					weights[e.to-1] = weights[e.from-1] + e.weight;
					negative[e.to-1] = true;
				}

				//負の閉路を通ってたどり着ける
				if(negative[e.from-1]) {
					negative[e.to-1] = true;
				}
			}
		}

		if(negative[N-1]) {
			System.out.println("inf");
		}else {
			System.out.println(-ans);
		}

	}

	public static class BF{
		int V;
		List<Edge> edges;
		long[] weights;
		long INF;

		public BF(int V, List<Edge> e, long INF) {
			this.V = V;
			edges = e;
			weights = new long[V];
			this.INF = INF;
		}

		//負の辺ありの最短距離の重み(ベルマンフォード法)(O(VE))
		public long getMinWeight(int start, int goal) {
			Arrays.fill(weights, INF);
			weights[start-1] = 0;

			for(int i=0; i<V; i++) {
				for(int j=0; j<edges.size(); j++) {
					Edge e = edges.get(j);

					if(weights[e.from-1] == INF)
						continue;

					if(weights[e.to-1] > weights[e.from-1] + e.weight) {
						weights[e.to-1] = weights[e.from-1] + e.weight;

						//負の閉路判定(あるときINFを返す)
						if(i == V-1) {
							return INF;
						}
					}
				}
			}

			return weights[goal-1];
		}

		//負の辺ありの最短距離の重みの集合(ベルマンフォード法)(O(VE))
		public long[] getMinWeightArray(int start) {
			Arrays.fill(weights, INF);
			weights[start-1] = 0;

			for(int i=0; i<V-1; i++) {
				for(int j=0; j<edges.size(); j++) {
					Edge e = edges.get(j);

					if(weights[e.from-1] == INF)
						continue;

					if(weights[e.to-1] > weights[e.from-1] + e.weight) {
						weights[e.to-1] = weights[e.from-1] + e.weight;

//						//負の閉路判定(あるときは空の配列を返す)
//						if(i == V-1) {
//							return new long[0];
//						}
					}
				}
			}

			return weights;
		}
	}

	//エッジを表すクラス(一般的なグラフのエッジとは異なる)
	public static class Edge{
		int from;
		int to;
		long weight;

		public Edge(int f, int t, long w) {
			from = f;
			to = t;
			weight = w;
		}
	}

}


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

using namespace std;
using ll = long long int;

int main() {
    int N;
    string S, T;
    cin >> N;
    cin >> S >> T;
    for (int i = 0; i < N; i++){
        cout << S[i] << T[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
// 
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;

int main()
{
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> is(26);
    rep(i, 0, n) is[s[i]-'a'].insert(i);
    rep(qi, 0, q) {
        int ty;
        cin >> ty;
        if (ty == 1) {
            int i; char c;
            cin >> i >> c;
            --i;
            is[s[i]-'a'].erase(i);
            s[i] = c;
            is[s[i]-'a'].insert(i);
        } else {
            int l, r;
            cin >> l >> r;
            --l;
            int ans = 0;
            rep(i, 0, 26) {
                auto it = is[i].lower_bound(l);
                if (it != is[i].end() && *it < r) ++ans;
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}

Measured memory_bytes: 24196
#include <iostream>
#include <algorithm>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int numYasumi;
    int numShuku;

    cin >> numYasumi >> numShuku;

    //    vector<int> numDays(numShuku+1, 0);

    int sum = 0;
    int input;

    for (int i = 1; i <= numShuku; i++)
    {
        cin >> input;
        sum = sum + input;
    }

    int ans = numYasumi - sum;

    if (ans >= 0)
    {
        cout << ans << endl;
    }
    else
    {
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 3588
from itertools import permutations
import math
n=int(input())
xy=[[int(i) for i in input().split()] for j in range(n)]
li=[]
for i in range(1,n+1):
    li.append(i)

ans = 0
for p in permutations(li):
    for i in range(1,len(p)):
        now = p[i]-1
        bef = p[i-1]-1
        ans+=((xy[now][0]-xy[bef][0])**2 + (xy[now][1]-xy[bef][1])**2)**0.5

ans = ans/math.factorial(n)
print(ans)
        


Measured memory_bytes: 3188
import Control.Monad
main = do
 n <- readLn
 ts<-replicateM n readLn
 print $ foldr mylcm 1 ts
 
 
mygcd a b 
    |a `mod` b /= 0 = mygcd b (a `mod` b)
    |otherwise = b
mylcm a b = (a*b) `div` (mygcd a b)

Measured memory_bytes: 1020
#include<iostream>
using namespace std;
int main(){
    int n,m,l;
    long long A[100][100]={{}},B[100][100]={{}},C[100][100]={{}};
    cin >> n >> m >> l;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> A[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            cin >> B[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
            C[i][j]+=A[i][k]*B[k][j];
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j) cout << " " << C[i][j];
            else cout << C[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
 
 using namespace std;
 typedef long long ll;
 #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
 
 
 
 int main() {
     int a, b, c; cin >> a >> b >> c;
 
     int zero_count=0;
     int tmp = 1;
     while(zero_count < 1) {
         int tmp_c = a*tmp%b;
         if(tmp_c == c) {
             cout << "YES" << endl;
             return 0;
         }
         if(tmp_c == 0) zero_count++;
         tmp++;
     }
 
     cout << "NO" << endl;
     return 0;
     
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b[21];
int main()
{
	int n,m,ans=0,i,j,c,sum;
	cin>>n>>m>>c;
	for(i=1;i<=m;i++)
	 cin>>b[i];
	for(i=1;i<=n;i++)
	 {sum=0;
	  for(j=1;j<=m;j++)
	   {cin>>a;
	    sum+=a*b[j];
	   }
	  if(sum+c>0)ans++;
	 }
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<vector>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int N=300005;
/*int f[N],use[N],a[N],n,mn=1e9,mx=0;
inline void check()
{
	register int i,j,mx1=0,mx2=0;
	for(i=1;i<=n;i++)
	{
		f[i]=1;
		for(j=1;j<i;j++)
			if(a[j]<a[i])	f[i]=max(f[i],f[j]+1);
		mx1=max(mx1,f[i]);
	}
	for(i=1;i<=n;i++)
	{
		f[i]=1;
		for(j=1;j<i;j++)
			if(a[j]>a[i])	f[i]=max(f[i],f[j]+1);
		mx2=max(mx2,f[i]);
	}
	if(mx1+mx2<n/2+2||mx1+mx2>n+1)
	{
//		for(i=1;i<=n;i++)	printf("%d ",a[i]);
//		printf("mx1=%d mx2=%d sum=%d\n",mx1,mx2,mx1+mx2);
	}
	mn=min(mn,mx1+mx2);
	mx=max(mx,mx1+mx2);
}
void dfs(int x)
{
	if(x==n+1)	check();
	else
	{
		for(int i=1;i<=n;i++)	if(!use[i])
		{
			use[i]=1;a[x]=i;
			dfs(x+1);
			use[i]=0;
		}
	}
}*/
vector<int> v[N];
inline void gg()
{
	puts("-1");
	exit(0);
}
int main()
{
/*	n=ri();
	dfs(1);
	printf("mn=%d mx=%d\n",mn,mx);*/
	int n=ri(),a=ri(),b=ri(),j,i,d=n/a,now=n-a+1,tot=d;
	for(i=1;i<=d;i++,now-=a)
		for(j=1;j<=a;j++)
			v[i].push_back(now+j-1);
	if(n%a)
	{
		tot++;
		for(j=1;j<=n%a;j++)
			v[tot].push_back(j);
//		reverse(v[tot].begin(),v[tot].end());
	}
	if(b<tot||a+b>n+1)	gg();b-=tot;
/*	for(i=1;i<=tot;i++)
		for(j=0;j<v[i].size();j++)
			printf("i=%d %d\n",i,v[i][j]);*/
	for(i=tot;i>1;b-=v[i].size()-1,i--)
	{
		if(b<v[i].size()-1)	break;
		reverse(v[i].begin(),v[i].end());
	}
	if(b)
	{
		reverse(v[i].begin(),v[i].begin()+b+1);
	}
	for(i=1;i<=tot;i++)
		for(j=0;j<v[i].size();j++)
			printf("%d ",v[i][j]);
	puts("");
	return 0;
}


Measured memory_bytes: 11008
import sys

input=sys.stdin.readline

n=int(input())
b=list(map(int,input().split()))
ope=[[] for i in range(n)]
Q=int(input())
for i in range(Q):
    l,r=map(int,input().split())
    ope[r-1].append(l-1)

res=b.count(0)

Data=[(-1)**((b[i]==1)+1) for i in range(n)]
for i in range(1,n):
    Data[i]+=Data[i-1]
Data=[0]+Data

for i in range(n):
    ope[i].sort(reverse=True)

# N: 処理する区間の長さ
N=n+1
N0 = 2**(N-1).bit_length()
data = [None]*(2*N0)
INF = (-2**31, -2**31)
# 区間[l, r+1)の値をvに書き換える
# vは(t, value)という値にする (新しい値ほどtは大きくなる)
def update(l, r, v):
    L = l + N0; R = r + N0
    while L < R:
        if R & 1:
            R -= 1
            if data[R-1]:
                data[R-1] = max(v,data[R-1])
            else:
                data[R-1]=v

        if L & 1:
            if data[L-1]:
                data[L-1] = max(v,data[L-1])
            else:
                data[L-1]=v
            L += 1
        L >>= 1; R >>= 1
# a_iの現在の値を取得
def _query(k):
    k += N0-1
    s = INF
    while k >= 0:
        if data[k]:
            s = max(s, data[k])
        k = (k - 1) // 2
    return s
# これを呼び出す
def query(k):
    return _query(k)[1]

for i in range(n+1):
    update(i,i+1,(-Data[i],-Data[i]))
if ope[0]:
    update(1,2,(0,0))

for i in range(1,n):
    val=query(i)
    update(i+1,i+2,(val+Data[i]-Data[i+1],val+Data[i]-Data[i+1]))
    for l in ope[i]:
        val=query(l)
        update(l+1,i+2,(val,val))



print(n-(res+query(n)+Data[n]))


Measured memory_bytes: 132232
#include<cstdio>
using namespace std;
int main(){
    int n;

    while(scanf("%d",&n),n){

        long long int mem[4500][3] = {{0}};
        long long int a,x,y;
        long long int cnt = 0;

        for(long long int i = 0;i < n; i++){
            scanf("%lld%lld%lld",&a,&x,&y);
            for(long long int j = 0;j < i; j++){
                if(mem[j][1] != a){
                   cnt++;
                }
                else {
                    mem[j][0] += x*y;
                    break;
                }
            }
            if(cnt == i){
                mem[i][0] += x*y;
                mem[i][1] = a;
                cnt = 0;
            }
        }

        bool flg = 0;
        for(int i = 0;i < n; i++){
            if(mem[i][0] >= 1000000){
                printf("%lld\n",mem[i][1]);
                flg = 1;
            }
        }
        if(flg == 0)printf("NA\n");
    }
    return 0;
}

Measured memory_bytes: 1152
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def isParindrom(l):
    invers = l[::-1]
    if l == invers:
        return True
    return False

def solve(S: str):
    N = len(S)
    if N % 2 == 0:
        print(NO)
        return

    if not isParindrom(S):
        print(NO)
        return 
    
    num = (N - 1) // 2
    p = S[:num]

    if not isParindrom(p):
        print(NO)
        return
    
    num = (N + 3) // 2 - 1
    r = S[num:]

    if not isParindrom(r):
        print(NO)
        return
    
    print(YES)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

#define MAX 100000

int parent(int a){
  return a/2;
}

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

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

int main(){
  int h,a[MAX+1];
  cin >> h;

  for(int i=1;i<=h;i++) cin >> a[i];

  for(int i=1;i<=h;i++){
    cout << "node " << i << ": key = " << a[i] << ", ";
    if(parent(i)>=1) cout << "parent key = " << a[parent(i)] << ", ";
    if(left(i)<=h) cout << "left key = " << a[left(i)] << ", ";
    if(right(i)<=h) cout << "right key = " << a[right(i)] << ", ";
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <cstdio>
using namespace std; 
typedef long double decimal; 
int main()
{
	// freopen("ARC085-C.in", "r", stdin); 
	int n, m; 
	scanf("%d%d", &n, &m); 
	decimal t = 1; 
	for (int i = 0; i < m; i++)
		t /= 2; 
	int res = m * 1900 + (n - m) * 100; 
	decimal ans = 0, cur = 1; 
	for (int i = 1; i <= 1000000; i++)
	{
		ans += i * cur * t * res; 
		cur *= 1 - t; 
	}
	printf("%d\n", (int)(ans + 0.5));
	return 0; 
}


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

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    if(a+b<=c*2){
        int ans = a*x + b*y;
        cout << ans << endl;
        return 0;
    }else{
        int ans = 0;
        if(x>y){
            swap(x,y);
            swap(a,b);
        }
        ans += c*2*x;
        ans += (y-x)*(min(b,2*c));
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 256
local mmi = math.min
local inf = 1000000007
local n = io.read("*n")
local a, b = {}, {}
for i = 1, n do
  a[i] = io.read("*n")
end
for i = 1, n do
  b[i] = io.read("*n")
end
local alltask = {}
local tot = 1
local stagetask = {}

local function heldkarp_prepare()
  for i = 1, n do
    tot = tot * 2
    alltask[i] = {}
    stagetask[i] = {}
  end
  for i = 1, n do
    for j = 1, tot - 1 do
      -- set inf value
      alltask[i][j] = 1000000007
    end
  end
  for i = 1, tot - 1 do
    local ti = i
    local cnt = 0
    for j = 1, n do
      if ti % 2 == 1 then
        cnt = cnt + 1
        ti = ti - 1
      end
      ti = ti / 2
    end
    table.insert(stagetask[cnt], i)
  end
  -- set first state
  local tmp = 1
  for i = 1, n do
    alltask[i][tmp] = i - 1
    tmp = tmp * 2
  end
end

local function heldkarp_doall()
  for stage = 1, n - 1 do
    local stlen = #stagetask[stage]
    for i_stagetask = 1, stlen do
      local used = stagetask[stage][i_stagetask]
      local t_used = used
      for i = 1, n do
        if t_used % 2 == 1 then
          local curcost = alltask[i][used]
          local v = (i + stage) % 2 == 0 and a[i] or b[i]
          local mul = 1
          local tmp = used
          local remcnt = 0
          for j = 1, n do
            if tmp % 2 == 0 then
              remcnt = remcnt + 1
              local jlen = remcnt - 1
              local nxtv = (j + stage + 1) % 2 == 0 and a[j] or b[j]
              if v <= nxtv then
                alltask[j][used + mul] = mmi(alltask[j][used + mul], jlen + curcost)
              end
            else
              tmp = tmp - 1
            end
            tmp = tmp / 2
            mul = mul * 2
          end
          t_used = t_used - 1
        end
        t_used = t_used / 2
      end
    end
  end
end

local function heldkarp_getresult()
  local ret = 1000000007
  for i = 1, n do
    ret = mmi(ret, alltask[i][tot - 1])
  end
  return ret
end
heldkarp_prepare()
heldkarp_doall()
local ans = heldkarp_getresult()
print(ans == 1000000007 and -1 or ans)


Measured memory_bytes: 42756
n = int(input())
a = [-1] + list(map(int, input().split()))

b = [0] * (n+1)
for i in reversed(range(1, n+1)):
    bi = 0
    for j in range(2, n//i + 1):
        bi += b[i*j]
    bi %= 2

    if bi != a[i]:
        b[i] = 1
    else:
        b[i] = 0



m = sum(b[1:])
print(m)
if m > 0:
    b_idx = [str(i) for i in range(1, n+1) if b[i] == 1]
    print(' '.join(b_idx))


Measured memory_bytes: 17204
N,K,Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
points = [K for _ in range(N)]

for a in A:
  points[a - 1] += 1
for p in points:
  if p - Q > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 10460
<?php
  fscanf(STDIN, "%d %d %d", $a, $b,$c);
  fscanf(STDIN, "%d", $k);
for($i=0;$i<$k;++$i){
  if($a>=$b){
  $b=$b*2;
  }elseif($b>=$c){
  $c=$c*2;
  }
}
//echo $a." ".$b." ".$c."\n";
if($a<$b&&$b<$c){
echo "Yes";
}else{
echo "No";
}
?>

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

long long fac[MAX_N], finv[MAX_N], inv[MAX_N];
// テーブルを作る前処理 from: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_N; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// factorial
long long fact(int n) {
    if (n == 1) return fac[n] = 1;
    if (fac[n]) return fac[n];
    return fac[n] = (fact(n - 1) * n) % MOD;
}

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

    int r, g, b, n;
    cin >> r >> g >> b >> n;

    ll cnt = 0;
    rep(ir, n / r + 1) rep(rg, n / g + 1) {
        int sum = ir * r + rg * g;
        if ((n - sum) >= 0 and (n - sum) % b == 0) cnt++;
    }

    out(cnt);
}


Measured memory_bytes: 256
#include<stdio.h>
#define  N 2000000
#define INF -2100000000

int h,a[N+1];

void maxHeapify(int);
int extract(void);
void increasekey(int, int);
void insert(int);

int main(){
  int key;
  char c[10];

  while(1){
    scanf("%s", c);
    if(c[0] == 'e' && c[1] == 'n') break;
    
    if(c[0] == 'i'){
      scanf("%d", &key);
      insert(key);
    }
    else{
      printf("%d\n", extract());
    }
  }
  
  return 0;
}

void maxHeapify(int i){
  int l,r,largest,temp;
  
  l=2*i;
  r=2*i+1;

  if(l<=h&&a[l]>a[i]) {
    largest=l;
  }else{
     largest=i;
  }
  
  if(r <= h && a[r] > a[largest]) largest = r;

  if(largest != i){
    temp = a[i];
    a[i] = a[largest];
    a[largest] = temp;
    maxHeapify(largest);
  }
}

int extract(){
  int max;
  if(h < 1) return INF;
  max = a[1];
  a[1] = a[h--];
  maxHeapify(1);
  return max;
}

void increasekey(int i,int key){
  int temp;
  
  if(key < a[i]) return;
  a[i] = key;
  
  while(i > 1 && a[i/2] < a[i]){
    temp = a[i];
    a[i] = a[i/2];
    a[i/2] = temp;
    i = i/2;
  }
}

void insert(int key){
  h++;
  a[h] = INF;
  increasekey(h, key);
}


Measured memory_bytes: 5628
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define watch(x); cout<<#x<<"="<<x<<endl;
#define watch2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define endl "\n"
#define int long long
using namespace std;        
 


int32_t main(){

    fast
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<(a+b)){
        cout<<k;
        //cout<<"HERE";
    }
    else{
        int ans=a-(k-(a+b));
        cout<<ans;
    }



    return 0;
}



Measured memory_bytes: 3648
/*
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
ordered_set -> less -> less_equal
ordered_set find_by_order() -> возвращает k-ый элемент(отсчёт с нуля)
ordered_set order_of_key() -> возвращает количество элементов в множестве,строго меньших,чем наш элемент
*/
#include <bits/stdc++.h>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;
using namespace __gnu_pbds;

template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int> > matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e3+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=(1ll<<61)-1;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};
int dist[maxn][maxn],n,ans[maxn];
bool used[maxn];
vector<int>g[maxn];
void dfs(int v){
    used[v]=1;
    for(auto to:g[v]){
        if(used[to]==0){
            for(int i=1;i<=n;i++){
                dist[to][i]=min(dist[to][i],1+min(dist[v][i],dist[i][v]));
                dist[i][to]=min(dist[i][to],1+min(dist[v][i],dist[i][v]));
            }
            dfs(to);
            for(int i=1;i<=n;i++){
                dist[v][i]=min(dist[v][i],1+min(dist[to][i],dist[i][to]));
                dist[i][v]=min(dist[i][v],1+min(dist[to][i],dist[i][to]));
            }
        }
    }
}
int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int x,y;
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dist[i][j]=inf;
            dist[j][i]=inf;
        }
    }
    g[x].pb(y);
    g[y].pb(x);
    dist[x][y]=1;
    dist[y][x]=1;
    for(int i=1;i<n;i++){
        g[i].pb(i+1);
        g[i+1].pb(i);
        dist[i][i+1]=1;
        dist[i+1][i]=1;
    }
    dfs(1);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(i!=j){
                ans[dist[i][j]]++;
            }
        }
    }
    for(int i=1;i<n;i++){
        cout<<ans[i]/2<<"\n";
    }
	exit(0);
}


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

int main(){
  int X;
  cin >> X;
  int ans=1;
  for(int i=2;i<X+1;i++){
    int P=i*i;
    for(int j=2;;j++){
      if(P>X){
        break;
      }
      ans=max(P,ans);
      P*=i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOR(i,n,m) for (int i=n; i<(int)(m); ++i)
#define ALL(x) x.begin(), x.end()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define in(i, n) (0 <= (i) && (i) < (n))
#define on(bit, i) (((bit >> i) & 1) == 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
const int INF = 1e9+7;

string s;

int main(void) {

  cin >> s;
  int c = INF, f = -1;
  REP(i, s.size()) {
    if (s[i] == 'C') c = min(c, i);
    if (s[i] == 'F') f = max(f, i);
  }

  if (c < f) cout << "Yes" <<endl;
  else cout << "No" << endl;
  
  return 0;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N, A, B, C, D;
	string s;
	cin>>N>>A>>B>>C>>D>>s; --A; --B; --C; --D;
	for(int i=A+1;i<=C;i++) if(s[i-1]=='#' && s[i]=='#') {
		cout<<"No\n";
		return 0;
	}
	for(int i=B+1;i<=D;i++) if(s[i-1]=='#' && s[i]=='#') {
		cout<<"No\n";
		return 0;
	}
	if(D<C) {
		for(int i=B;i<=D;i++) if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.') {
			cout<<"Yes\n";
			return 0;
		}
		cout<<"No\n";
	}
	else cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 592
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int NA, NB;
	static int[] XA, YA, XB, YB;
	static final double INF = 1e300;

	public static void main(String[] args) {
		NA = sc.nextInt();
		NB = sc.nextInt();
		XA = new int[NA];
		YA = new int[NA];
		XB = new int[NB];
		YB = new int[NB];
		for (int i = 0; i < NA; ++i) {
			XA[i] = sc.nextInt();
			YA[i] = sc.nextInt();
		}
		for (int i = 0; i < NB; ++i) {
			XB[i] = sc.nextInt();
			YB[i] = sc.nextInt();
		}
		double a1 = solve(XA, YA, XB, YB);
		double a2 = solve(XB, YB, XA, YA);
		double ans = Math.min(a1, a2);
		if (ans == INF) {
			System.out.println(-1);
		} else {
			System.out.printf("%.9f\n", ans);
		}
	}

	static double solve(int[] X1, int[] Y1, int[] X2, int[] Y2) {
		int N = X2.length;
		PriorityQueue<State> q = new PriorityQueue<State>();
		q.add(new State(0, 0));
		boolean[] visited = new boolean[N];
		while (!q.isEmpty()) {
			State cur = q.poll();
			if (cur.v == 1) {
				return cur.d + dist(X1[0], Y1[0], X1[1], Y1[1]);
			}
			if (visited[cur.v]) continue;
			visited[cur.v] = true;
			for (int i = 0; i < N; ++i) {
				if (visited[i]) continue;
				if (cross(X1[0], Y1[0], X1[1], Y1[1], X2[cur.v], Y2[cur.v], X2[i], Y2[i])) continue;
				q.add(new State(i, cur.d + dist(X2[cur.v], Y2[cur.v], X2[i], Y2[i])));
			}
		}
		return INF;
	}

	static class State implements Comparable<State> {
		int v;
		double d;

		State(int v, double d) {
			this.v = v;
			this.d = d;
		}

		public int compareTo(State o) {
			return Double.compare(this.d, o.d);
		}
	}

	static double dist(int x1, int y1, int x2, int y2) {
		return Math.sqrt(sq(x2 - x1) + sq(y2 - y1));
	}

	static double sq(double v) {
		return v * v;
	}

	static boolean cross(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
		long v1 = (x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3);
		long v2 = (x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4);
		long v3 = (x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1);
		long v4 = (x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2);
		if (v3 == 0 && v4 == 0) {
			return Math.min(x1, x2) <= x3 && x3 <= Math.max(x1, x2) && Math.min(y1, y2) <= y3 && y3 <= Math.max(y1, y2);
		}
		return v1 * v2 <= 0 && v3 * v4 <= 0;
	}

}

Measured memory_bytes: 48220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int d, n;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        d = sc.nextInt();
        n = sc.nextInt();
        solve();
    }

    void solve() {
        int start = 1;
        if (d == 1) {
            start = 100;
        } else if (d == 2) {
            start = 10000;
        }
        if (n < 100) {
            System.out.println(start * n);
        } else {
            System.out.println(start * 101);
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22612
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.exception, std.typecons;
  
  int n, m; rd(n, m);
  auto a=readln.split.to!(long[]);
  auto g=new int[][](n);
  foreach(i; 0..m){
    int x, y; rd(x, y);
    g[x]~=y; g[y]~=x;
  }

  if(m==n-1){writeln(0); return;}
  if((n-m-1)*2>n){writeln("Impossible"); return;}

  alias T=Tuple!(long, "val", int, "id");
  void chmin(ref T l, T r){
    if(l.val>r.val){
      l.val=r.val;
      l.id=r.id;
    }
  }
  auto vis=new bool[](n);
  T dfs(int i, int p=-1){
    vis[i]=true;
    auto ret=T(a[i], i);
    foreach(j; g[i])if(j!=p){
      if(vis[j]) continue;
      auto sub=dfs(j, i);
      chmin(ret, sub);
    }
    return ret;
  }

  auto c=0L, used=new bool[](n);
  foreach(i; 0..n)if(vis[i]==false){
    auto res=dfs(i);
    c+=res.val; used[res.id]=true;
  }
  auto as=new T[](n);
  foreach(i; 0..n) as[i]=T(a[i], i);
  sort!((l, r)=>(l.val==r.val ? l.id<r.id : l.val<r.val))(as);
  int tot=n-m;
  foreach(j; 0..n){
    if(tot==(n-m-1)*2) break;
    auto e=as[j];
    if(used[e.id]) continue;
    c+=e.val; tot++;
  }

  writeln(c);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}


Measured memory_bytes: 20540
def m():
    N = int(input())
    a = list(map(int, input().split()))
    fours = []
    twes = []
    others = []
    for i in range(N):
        if a[i] % 4 == 0:
            fours.append(a[i])
            continue

        if a[i] % 2 == 0:
            twes.append(a[i])
            continue
        others.append(a[i])

    len4s = len(fours)
    len2s = len(twes)
    others = len(others)
    if len2s:
        others += 1
    if others <= len4s + 1:
        return 'Yes'
    return 'No'


print(m())


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;
#define INF 1e9
int N;
int gcd(int a, int b){
  if(b == 0){
    return a;
  }
  return gcd(b, a%b);
}
int main(){
  cin >> N;
  vector<ll> T(N), A(N);
  pair<ll, ll> ans = make_pair(0,0);

  REP(i, N){
    cin >> T[i] >> A[i];
  }
  REP(i, N){
    if(i==0){
      ans = make_pair(T[0], A[0]);
      continue;
    }
    
    ll a = ans.first / T[i];
    ll b = ans.second / A[i];
    if(a ==0 && b==0){
      ans = make_pair(T[i], A[i]);
    }
    else if(a == b){
      if(ans.first % T[i] || ans.second % A[i])
        ++a;
      //cout << "++a1" << endl;
      ans = make_pair(T[i] *a, A[i]*a);
    }
    else if(a > b){
      if(ans.first % T[i]){
        ++a;
        //cout << "++a2" << endl;
      }
      ans = make_pair(T[i]*a, A[i]*a);
    }
    else if(a < b){
      if(ans.second % A[i]){
        ++b;
        //cout << "++b1" << endl;
      }
      ans = make_pair(T[i] * b, A[i] *b);
    }
    //cout << ans.first << " " <<  ans.second << endl;
  }
  cout << ans.first + ans.second << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };


string s;
int k;

ll dp[107][5][2];

ll solve(int idx, int count, bool good) {
	if (idx == s.size())
		return k == count;

	if (count > k)
		return 0;

	if (dp[idx][count][good] != -1)
		return dp[idx][count][good];

	ll ans = 0;
	if (good) {
		for (int i = 0; i < 10; i++) {
			ans += solve(idx+1, count + (i != 0), 1);
		}
	}
	else {
		for (int i = 0; i+'0' < s[idx]; i++) {
			ans += solve(idx+1, count + (i != 0), 1);
		}
		ans += solve(idx+1, count + (s[idx] != '0'), 0);
	}

	return dp[idx][count][good] = ans;

}


int main() {
	fastIO;
	memset(dp, -1, sizeof dp);
	cin >> s >> k;
	cout << solve(0, 0, 0);


}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  scanf("%d\n",&n);
  int p[n];
  for(int i = 0; i < n; ++i) scanf("%d",&p[i]);
  int answer = 0;
  for(int i = 0; i < n-2; ++i){
    if(p[i] < p[i+1] && p[i+1] < p[i+2]) answer++;
    else if(p[i] > p[i+1] && p[i+1] > p[i+2]) answer++;
  }
  printf("%d",answer);
  return 0;
}

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

using pii = pair<int, int>;

int main() {
    int n, w, d;
    cin >> n >> w >> d;
    vector<pii> v;
    for(int i=0; i<n; ++i) {
        int x, y;
        char f;
        cin >> x >> y >> f;
        if(f == 'W') {
            v.emplace_back(x + y, -x + y);
        } else if(f == 'N') {
            v.emplace_back(2*d + x - y, x + y);
        } else if(f == 'E') {
            v.emplace_back(2*(d+w) - x - y, 2*d + x - y);
        } else {
            v.emplace_back(2*(d+w) - x + y ,2*(d+w) - x - y);
        }
    }
    sort(v.begin(), v.end());
    int L = 2*(w + d);
    int res = 1e9;
    for(int i=0; i<n; ++i) {
        auto tmp = v;
        for(int j=i-1; j>=0; --j) {
            if(tmp[j].first < tmp[i].first) {
                tmp[j].first += L;
                tmp[j].second += L;
            }
        }
        sort(tmp.begin(), tmp.end());
        int cnt = 1;
        int now = tmp[0].first;
        for(int j=0; j<n; ++j) {
            if(tmp[j].second > now) {
                now = tmp[j].first;
                cnt++;
            }
        }
        res = min(res, cnt);
    }
    cout << res << endl;
}


Measured memory_bytes: 3096
#include<stdio.h>
int main(){
int H,W,i,j;

while(1){
scanf("%d %d", &H, &W);
if(H==0 && W==0)
break;

for(i=0; i<H; i++){
 for(j=0; j<W; j++){
  if(i==0 || i==H-1){
    printf("#");
   }else{
    if(j==0 || j==W-1){
     printf("#");
    }else{
     printf(".");}
   }
  }
 printf("\n");
 }
 printf("\n");
}

return 0;

}
  

Measured memory_bytes: 572
import bisect

n = int(input())
a = list(map(int, input().split()))

a.sort()
ai = a.pop()
i = bisect.bisect_left(a, ai / 2)
if i == 0:
    aj = a[0]
elif i == n - 1:
    aj = a[n - 2]
else:
    aj = a[i - 1] if ai / 2 - a[i - 1] <= a[i] - ai / 2 else a[i]

print(ai, aj)


Measured memory_bytes: 14052
n, x, m = map(int, input().split())
S = [0]
F = [None] * m
for i in range(m + 1):
    S.append(S[-1] + x)
    if F[x] is not None:
        j = F[x]
        q, r = (n - j) // (i - j), (n - j) % (i - j)
        print((S[i] - S[j]) * q + S[j + r])
        exit()
    F[x] = i
    x = pow(x, 2, m)


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

int main(void)
{   
    int needle_i[8] = {0,1,1,1,0,-1,-1,-1};
    int needle_j[8] = {1,1,0,-1,-1,-1,0,1};

    int h, w; cin >> h >> w;

    vector<vector<int> > canGo(h+2, vector<int>(w+2, 0));

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            char input; cin >> input;
            if(input == '#') canGo[i][j] = -1;
            if(input == '.') canGo[i][j] = 0;
        }
    }



    int counter = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(canGo[i][j] == 0){
                counter = 0;        
                for(int k = 0; k < 8; k++){
                    if(canGo[i + needle_i[k]][j + needle_j[k]] == -1) counter++;
                }
            canGo[i][j] = counter;
            }
        }
    }

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(canGo[i][j] == -1){
                cout << '#';
                continue;
            }
            cout << canGo[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//
//  sublime text 3,
//  emre yazicioglu
//

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
typedef vector <pll> vpll;
#define pb push_back
#define fi first
#define se second
#define INF (ll) (1e18 + 7)
#define MOD (ll) (1e9 + 7)

const int N = 2e6 + 7;
ll mn = INF, mx = -INF;
ll n, m, k, s, q, t;
ll a, b, c, d, e;
ll ans, cur, sum, cnt;
ll ar[N], p[N], dp[N];
string str; bool h[N];
pll pp[N]; vll v;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);

  // freopen("../in.txt","r",stdin);
  // freopen("../out.txt","w",stdout);

  cin >> str;
  if(str == "Sunny")
    cout << "Cloudy";
  else if(str == "Rainy")
    cout << "Sunny";
  else
    cout << "Rainy";
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する

int main(){
    int n;
    cin>>n;
    for(int x=1;x<=n;x++){
        if(n==int(x*1.08)){
            cout<<x<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        long[] A = new long[N];
        long[] F = new long[N];
        long allcost = 0;

        for(int i=0; i<N; i++){
            A[i]=sc.nextLong();
            allcost = allcost + A[i];
        }

        for(int i=0; i<N; i++){
            F[i]=sc.nextLong();
        }

        if(allcost<=K){
            System.out.println(0);
            return;
        }
        Arrays.sort(A);
        Arrays.sort(F);

       long ok = A[N-1]*F[N-1];
        long ng = 0;

        while(ok-ng>1){
            long h = (ok+ng)/2;
            long tot = 0;
            for(int i=0; i<N; i++){
                tot = tot+Math.max(A[N-i-1]-h/F[i], 0);
            }
            if(tot>K){
                ng = h;
            }else{
                ok = h;
            }
        }
        System.out.println(ok);
        
    }
}


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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,p;cin>>n>>p;
    ll ans = 1;
    if(n>40){cout<<1<<endl;return 0;}
    if(n==1){cout<<p<<endl;return 0;}
    for(int i=2; pow(i,n)<=p; i++){
        int cnt = 0;
        while(p%i==0){
            if(p%i==0){p/=i;cnt++;}
            else break;
        }
        ans*=pow(i,cnt/n);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512