akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b = map(int, read().split())
cnt_a = []
ans = 0
check = 1
while check <= a - 1:
    x, y = divmod(a, check * 2)
    cnt_a.append(x * check + max(0, y - check))
    check *= 2
check = 1
while check <= b:
    if len(cnt_a) != 0:
        aa = cnt_a.pop(0)
    else:
        aa = 0
    x, y = divmod(b + 1, check * 2)
    cnt = x * check + max(0, y - check) - aa
    if cnt % 2 == 1:
        ans += check
    check *= 2
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

const int Z = 1e9+7;

pii dfs(vi e[], int n, int x, int p, int ipow2[]) {
    int r = 0, cur = ipow2[n-1];
    int ssum = 1;
    for (int y : e[x]) {
        if (y != p) {
            pii t = dfs(e, n, y, x, ipow2);
            r = (r + t.first) % Z;
            ssum += t.second;
            cur = (0ll + cur + ipow2[n-1-t.second] + Z - ipow2[n-1]) % Z;
        }
    }
    cur = (0ll + cur + ipow2[ssum-1] + Z - ipow2[n-1]) % Z;
    cur = 1ll * (1 + Z - cur) * ipow2[1] % Z;
    r = (r + cur) % Z;
    return {r, ssum};
}

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

    int n;
    cin >> n;
    vi e[n];
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    int ipow2[n];
    for (int i = 0; i < n; i++) {
        ipow2[i] = i == 0 ? 1 : 1ll * ipow2[i-1] * (Z - Z / 2) % Z;
    }

    cout << dfs(e, n, 0, -1, ipow2).first << endl;

    return 0;
}


Measured memory_bytes: 25344
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int dp[n];dp[0]=0;dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {   
        dp[i]=1000000000;
        for(int j=i-1;j>=i-k;j--)
        {
            if(j>=0)
            {
                dp[i]=min((dp[j]+abs(arr[i]-arr[j])),dp[i]);
            }
        }
        //dp[i]=min((dp[i-1]+abs(arr[i]-arr[i-1])),(dp[i-2]+abs(arr[i]-arr[i-2])));
        //cout<<dp[i]<<" ";
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
Q,H,S,D=[int(i) for i in input().split(" ")]
N=int(input())

q=Q
h=min(2*Q,H)
s=min(4*Q,2*H,S)
d=min(8*Q,4*H,2*S,D)

fee=int(N/2)*d

N-=int(N/2)*2

while N>=1:
    fee+=s
    N-=1

while N>=0.5:
    fee+=h
    N-=0.5

while N>0:
    fee+=q
    N-=0.25

print(fee)


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int a[3];
   rep (i, 3) {
      cin >> a[i];
   }

   int ans = 1e8;
   sort(a, a+3);
   do {
      ans = min(ans, abs(a[0]-a[1])+abs(a[1]-a[2]));
   } while(next_permutation(a, a+3));

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 10010
#define M 110
using namespace std;
string s;
ll d,n,dp[N][M][2];//0->the number is already smaller than the original number 1->the number equals to the original number. 
int main(){
	ll i,j,k;
	cin>>s>>d;
	n=s.size();
	memset(dp,0,sizeof(dp));
	dp[0][(s[0]-'0')%d][1]=1;
	for(i=0;i<s[0]-'0';i++)
	{
		dp[0][i%d][0]++;
	}
	for(i=1;i<n;i++)
	{
		for(j=0;j<d;j++)
		{
			for(k=0;k<10;k++)
			{
				if(k<s[i]-'0')
				{
					dp[i][(j+k)%d][0]=(dp[i][(j+k)%d][0]+dp[i-1][j][1]+dp[i-1][j][0])%MOD;
				}
				else if(k==s[i]-'0')
				{
					dp[i][(j+k)%d][0]=(dp[i][(j+k)%d][0]+dp[i-1][j][0])%MOD;
					dp[i][(j+k)%d][1]=(dp[i][(j+k)%d][1]+dp[i-1][j][1])%MOD;
				}
				else
				{
					dp[i][(j+k)%d][0]=(dp[i][(j+k)%d][0]+dp[i-1][j][0])%MOD;
				}
			}
		}
	}
	cout<<(dp[n-1][0][0]+dp[n-1][0][1]-1+MOD)%MOD<<endl;
	return 0;
}

Measured memory_bytes: 17536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication25
{
    class Program
    {
        static void Main()
        {
            int[] a = new int[4];
            int[] b = new int[2];
            for(int c = 0;c < 4 ; c++)
            {
               a[c] = int.Parse(Console.ReadLine());
            }
            for (int c = 0; c < 2; c++)
            {
                b[c] = int.Parse(Console.ReadLine());
            }
            Array.Sort(a);
            Array.Sort(b);
            Console.WriteLine(a[1] + a[2] + a[3] + b[1]);




        }
    }
}

Measured memory_bytes: 9364
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def primeFactorization(n):
    ans = []
    temp = n
    while temp%2 == 0:
        ans.append(2)
        temp //= 2
    for i in range(3, int(n**0.5)+1, 2):
        while temp%i == 0:
            ans.append(i)
            temp //= i
    if temp > 1:
        ans.append(temp)
    return collections.Counter(ans)

def resolve():
    N, P = LI()

    pf = primeFactorization(P)
    ans = 1
    for k, v in pf.items():
        ans *= k ** (v // N)

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
int main(){
    int n;ll k;cin>>n>>k;
    int a[n+1];rep1(i,n)cin>>a[i];
    int index = 1;
    bool flag[n+1]={false};
    int last;
    vector<int>lg;
    lg.push_back(1);
    flag[1]=true;
    while(1){
        if(flag[a[index]]){last = a[index];break;}
        flag[a[index]]=true;lg.push_back(a[index]);index = a[index];
    }
    int ind;
    rep(i,lg.size()){
        if(lg[i]==last){ind=i;break;}
    }
    int roop = lg.size()-ind;
    if(k<lg.size())co(lg[k]);
    else{
        co(lg[(k-ind)%roop+ind]);
    }
}


Measured memory_bytes: 5292
while True:
    a,op,b = map(str,input().split())
    a = int(a)
    b = int(b)
    
    if op == '?':
        break
    
    if op == '+':
        print('{}'.format(a+b))
    elif op == '-':
        print('{}'.format(a-b))
    elif op == '*':
        print('{}'.format(a*b))
    else :print('{}'.format(int(a/b))) 

Measured memory_bytes: 5600
using System;

class Program
{
    static void Main(string[] args)
    {
        ulong N = ulong.Parse(Console.ReadLine());
        ulong A = 1;
        for (ulong i = 1; i * i <= N; i++)
        {
            if (N % i == 0)
            {
                A = i;
            }
        }
        Console.WriteLine((N/A).ToString().Length);
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define INF 2000000000
#define MOD 1000000007

int main() {
    intt n, m;
    scanf("%lld %lld", &n, &m);
    int ans = 0;
    while (n<=m) {
        n*=2;
        ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
c1 = S()
c2 = S()
if c1 == c2[::-1]:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 74100
#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
#include <cmath>
#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
using namespace std;
int main()
{
	int n,sm,bg,ans,t,c;
	LL d=999999999999;
	cin>>n;
	vector <int> a(n);
	rep(i,n) cin>>a[i];
	sort(a.begin(),a.end());
	int p=a[n-1]/2;
	for(int i=0;i<n-1;i++)
	{
		c=p;
		if(a[i]>=p+1) c++;
		t=abs(a[i]-c);
		if(t<d) 
		{
			ans=a[i];
			d=t;
		}
	}
	cout<<a[n-1]<<" "<<ans;
    rt0;
}

Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            string[] S = Console.ReadLine().Split(' ');
            Console.ReadLine();
            string[] T = Console.ReadLine().Split(' ');

            int cnt = 0;

            foreach (var t in T)
            {
                if (BinarySearch(S, t)) cnt++;
            }

            Console.WriteLine(cnt);
        }

        static bool BinarySearch(string[] S,string key)
        {
            int left = 0;
            int right = S.Length;

            while (left < right)
            {
                int mid = (left + right) / 2;

                if (S[mid] == key) return true;
                else if (int.Parse(key) < int.Parse(S[mid])) right = mid;
                else left = mid + 1;
            }
            return false;
        }
    }
}

Measured memory_bytes: 19192
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
	ll n;
	double k;
	cin>>n>>k;
	double p[n];
	rp(i,0,n)cin>>p[i];
	rp(i,0,n)p[i]=p[i]*(p[i]+1.0)/2.0/p[i];
	//ca(n,p);
	double ans=0;
	double t=0;
	rp(i,0,k)t+=p[i];
	rp(i,k,n){
		ans=max(t,ans);
		t-=p[i-ll(k)];
		t+=p[i];
	}
	ans=max(t,ans);
	cout<<fixed<<setprecision(10)<<ans<<endl;
}


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

int main()
{
  int n, ans = 1;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec[i];
  
  int tmp_min = vec[0];
  
  for (int i = 1; i < n; i++)
  {
    tmp_min = min(tmp_min, vec[i]);
    if (vec[i] == tmp_min) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define _ << " " <<
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	if (k == 1) cout << 0 << endl;
	else cout << n - k << endl;
	return 0;
}

// A......
// 3 - 1 4 - 2 5 - 2 6 - 3 7 - 3

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

int num[10010],n;
char s[10010][20];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	n=rd();
	for (int i=1;i<=n;i++) scanf("%s",s[i]+1);
	int ans=0;
	for (int i=1;i<=n;i++)
	{
		int len=strlen(s[i]+1);num[i]=len;
		for (int j=1;j<len;j++) if (s[i][j]=='A'&&s[i][j+1]=='B') ans++;
	}
	int sum1=0,sum2=0,sum3=0;
	for (int i=1;i<=n;i++)
	{
		if (s[i][num[i]]=='A'&&s[i][1]!='B') sum1++;
		if (s[i][num[i]]!='A'&&s[i][1]=='B') sum2++;
		if (s[i][num[i]]=='A'&&s[i][1]=='B') sum3++;
	}
	if (!sum3) ans+=min(sum1,sum2);
	else
	{
		ans+=sum3-1;
		if (sum1==sum2)
		{
			if (sum1>0) ans+=sum1+1;
		}
		else ans+=min(sum1,sum2)+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int dp[3010][3010] = {0};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
int main()
{
    char s[3010], t[3010];
    scanf("%s%s", s, t);
    int x = strlen(s), y = strlen(t);
    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            if (s[i] == t[j])
            {
                chmax(dp[i + 1][j + 1], dp[i][j] + 1);
            }
            chmax(dp[i + 1][j + 1], dp[i + 1][j]);
            chmax(dp[i + 1][j + 1], dp[i][j + 1]);
        }
    }
    string k = "";
    int i = x, j = y;
    while (i && j)
    {
        if (dp[i][j] == dp[i - 1][j])
        {
            i--;
        }
        else if (dp[i][j] == dp[i][j - 1])
        {
            j--;
        }
        else
        {
            k = s[i - 1] + k;
            i--;
            j--;
        }
    }
    char l[3030] = {""};
    for (int i = 0; i < k.size(); i++)
    {
        l[i] = k[i];
    }
    printf("%s\n", l);
}

Measured memory_bytes: 35584
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int a[15] = { 0,1,2,3,4,5,6,7,8,9,5,4,3,2,1 };
	int s, t;
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> s >> t;
		int sum = 100000, sum2 = 100000, s2 = s,count=0;
		bool sumb = false, sum2b = false;
		vector<int> go;
		vector<int>go2;
		for (int j = 0; j < 15; j++)
		{
			if (a[j] == s) {
				s2 = j;
				while (a[s2] != t) {
					if (count == 0) {
						if (!sumb) {
							sum = 0; sumb = true;
						}
						go.push_back(a[s2]);
						sum++;
					}
					else {
						if (!sum2b) {
							sum2 = 0; sum2b = true;
						}
						go2.push_back(a[s2]);
						sum2++;
					}
					s2++;
					if (s2 > 14) s2 = 0;
				}
				if (count == 0) {
					go.push_back(t);
					sum++;
				}
				else {
					go2.push_back(t);
					sum2++;
				}
				count++;
				s2 = s;
			}
		}
		if (sum < sum2) {
			for (int i = 0; i < sum; i++) {
				if (i == 0) cout << go[i];
				else cout << " " << go[i];
			}
			cout << endl;
		}
		else {
			for (int i = 0; i < sum2; i++) {
				if (i == 0) cout << go2[i];
				else cout << " " << go2[i];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793


   
int main(){
  string s;
  cin >> s;
  int n=s.size();
  int ans1=0;
  int ans2=0;
  int ans;
  rep(i,n){
   if((i+1)%2==1){
     if(s.at(i)!='0')ans1++;
     else if(s.at(i)!='1')ans2++;
   }
   else{
     if(s.at(i)!='1')ans1++;
     else if(s.at(i)!='0')ans2++;
   }
  }
  ans=min(ans1,ans2);
  cout << ans << endl;
}

Measured memory_bytes: 512
N, Q=map(int, input().split())
S=input()
count=0
ac=[0]
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    count+=1
  ac.append(count)
for _ in range(Q):
  l, r=map(int, input().split())
  l-=1
  r-=1
  print(ac[r]-ac[l])

Measured memory_bytes: 11644
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    A.sort();

    auto B = new long[](N);
    B[0] = A[0];
    foreach (i; 1..N) {
        B[i] = B[i-1] + A[i];
    }

    int ans = 1;
    for (int i = N-2; i >= 0; i--) {
        if (B[i]*2 < A[i+1]) break;
        ans += 1;
    }

    ans.writeln;
}


Measured memory_bytes: 6836
#include<bits/stdc++.h>
using namespace std;
long long x;
long long a[43]={0,6,14,30,62,126,254,510,1022,2046,4094,8190,16382,32766,65534,131070,262142,524286,1048574,2097150,4194302,8388606,16777214,33554430,67108862,134217726,268435454,536870910,1073741822,2147483646,4294967294,8589934590,17179869182,34359738366,68719476734,137438953470,274877906942,549755813886,1099511627774,2199023255550,4398046511102};
int main()
{
	cin>>x;
	cout<<a[x];
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
const int N = 45;
char str[N][N];
LL f[N][N][N] , g[N][N][N];
int main()
{
	int n; scanf("%d" , &n); n <<= 1;
	for(int i = 1 ; i <= n ; ++i) scanf("%s" , str[i] + 1);
	for(int i = 1 ; i < n ; ++i)
	{
		f[i][i][i] = 1;
		for(int j = i + 1 ; j <= n ; ++j) 
			if(str[i][j] == '1') g[i][i][j] = 1;
	}
	for(int i = 3 ; i < n ; i += 2)
		for(int j = 1 ; i + j <= n ; ++j)
		{
			int k = i + j - 1;
			for(int l = j ; l <= k ; l += 2)
				for(int r = k ; r > l ; r -= 2)
				{
					LL s = 0;
					for(int t = r ; t <= k ; ++t) s += g[j][l][t] * f[r][k][t];
					for(int t = l + 1 ; t < r ; ++t) f[j][k][t] += f[l+1][r-1][t] * s;
				}
			// int k = i + j - 1;
			// for(int l = j ; l <= k ; l += 2)
			// 	for(int r = k ; r > l ; r -= 2) 
			// 	{
			// 		LL s = 0;
			// 		for(int t = r; t <= k; t++) s += g[j][l][t] * f[r][k][t];
			// 		for(int t = l + 1; t < r; t++) f[j][k][t] += f[l + 1][r - 1][t] * s;
			// 	}
			for(int t1 = j + 1 ; t1 < k ; ++t1)
				for(int t2 = k + 1 ; t2 < n ; ++t2)
					if(str[t1][t2] == '1') g[j][k][t2] += f[j][k][t1];
		}
	LL ans = 0;
	for(int i = 1 ; i < n ; ++i) if(str[i][n] == '1') ans += f[1][n-1][i];
	cout << ans << '\n'; return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

ll n,k,res=0;
vector<int> a(100000);
vector<vector<int>> g(100000);

int dfs(int node){
    if(g[node].size()==0){
        // leaf
        if(k==1){
            if(a[node]!=0){
                a[node]=0;
                res++;
            }
            return 0;
        }
        return 1;
    }
    int ma=0;
    for(int i=0;i<(int)g[node].size();i++){
        int next=g[node][i];
        ma=max(ma,dfs(next));
    }
    ma++;
    if(ma==k){
        if(a[node]!=0){
            a[node]=0;
            res++;
        }
        return 0;
    }
    return ma;
}

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

    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i]; a[i]--;
        if(i==0){
            if(a[i]!=0) res++;
            a[i]=0;
            continue;
        }
        g[a[i]].push_back(i);
    }
    dfs(0);
    cout<<res<<endl;
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define clr(x) memset(x, 0, sizeof(x))
#define all(a) a.begin(),a.end()
#define forn(i, a,b) for(int i = int(a); i < int(b); ++i)
#define forn_r(i, b, a) for(int i = int(b); i > int(a); i--)
#define trav(a,x) for (auto& a : x)
#define printArray(array, length) for(int i = 0; i < length; i++) cout<< array[i] << (i == length - 1 ? '\n' : ' '); 
#define print(x) cout << x << '\n'
#define print2(x, y) cout << x << ' ' << y << '\n'
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
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 (m > q) {m = q; return true;} else return false; }
 
using namespace std;
typedef long long ll; 
const int INF = 0x3f3f3f3f;
const ll LNF  = 0x3f3f3f3f3f3f;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline ll  gcd(ll  a, ll  b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
 
bool possi(ll mid, vector<ll> a ,ll k){
	for(auto x:a){
		k-=(x+mid-1)/mid -1;
	}
	return k>=0;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t =1;
    //cin>>t;
    while(t--){
    	ll n, k; cin>>n>>k;
    	vector<ll> a(n);forn(i,0,n) cin>>a[i];
    	
    	ll mini =1, maxi =1e9+1;
    	ll mid;
    	while(mini<=maxi){
    		mid = (mini+maxi)/2;
    		if(possi(mid,a,k)){
    			maxi=mid-1;
    		}
    		else{
    			mini=mid+1;
    		}
    		
    	}
    	print(mini);
       	 
    }
    return 0;
}

Measured memory_bytes: 6316
/*  -*- coding: utf-8 -*-
 *
 * 2885.cc: Divide and Conquer
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;

/* global variables */

vi nbrs[MAX_N];
int ds[MAX_N], pns[2];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n, m;
    scanf("%d%d", &n, &m);
    if (n == 0) break;

    for (int i = 0; i < n; i++) nbrs[i].clear();
    memset(ds, -1, sizeof(ds));

    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      u--, v--;
      nbrs[u].push_back(v);
      nbrs[v].push_back(u);
    }

    ds[0] = 0;
    pns[0] = 1, pns[1] = 0;
    bool ok = true;
    qi q;
    q.push(0);

    while (ok && ! q.empty()) {
      int u = q.front(); q.pop();
      int vd = ds[u] ^ 1;
      vi &nbru = nbrs[u];
      for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
	int &v = *vit;
	if (ds[v] < 0) {
	  ds[v] = vd;
	  pns[vd]++;
	  q.push(v);
	}
	else if (ds[v] != vd) {
	  ok = false;
	  break;
	}
      }
    }

    if (ok) {
      //printf("%d %d\n", pns[0], pns[1]);
      int kn = 0, ks[2];
      for (int i = 0; i < 2; i++)
	if (! (pns[i] & 1)) ks[kn++] = pns[i] / 2;
      sort(ks, ks + kn);
      kn = unique(ks, ks + kn) - ks;
      printf("%d\n", kn);
      for (int i = 0; i < kn; i++) printf("%d\n", ks[i]);
    }
    else
      puts("0");
  }
  return 0;
}



Measured memory_bytes: 3360
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;

    static int N;
    static void input()
    {
        cin = new Scanner();
        N = cin.nextInt();
    }
    static void solve()
    {
        input();
        if (N == 0)
        {
            WriteLine(0);
            return;
        }
        Stack<char> ans = new Stack<char>();
        while(N != 0)
        {
            ans.Push((N % -2).ToString().Last());
            N = (N % 2 < 0 ? 1 : 0) + N / -2;
        }
        
        foreach(var i in ans)
        {
            Write(i);
        }
        WriteLine();
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,num)for(int i=0;i<(num);++i)

using namespace std;

map<int,int> getFactor(long long N){
    map<int,int> res;
    for(long long i=2;i*i<=N;++i){
        while(N%i==0){
            res[i]++;
            N/=i;
        }
    }
    if(N>1)res[N]++;
    return res;
}

long long cache[100050][100];
long long nCk(int N,int K){
    if (N == K || K == 0) return 1;
    if (cache[N][K]!=0) return cache[N][K];
    long long res = (nCk(N-1,K-1) + nCk(N-1,K)) % MOD;
    cache[N][K] = res;
    return res;
}
// 1 1 1
int nHk(int N,int K){
    if(N==0&&K==0)return 1;
    if(N<=0||K<0)return 0;
    return (int)nCk(N+K-1,K);
}

int main() {
    long long N,M;
    cin>>N>>M;
    long long ans=1;
    map<int,int> factors=getFactor(M);
    for(auto &factor:factors){
        ans = (ans * nHk(N, factor.second)) % MOD;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 83072
import collections
N = int(input())
A = list(map(int,input().split()))
ans = 1
if 0 in A:
    A.remove(0)
Acounter = collections.Counter(A)
for i in Acounter.values():
    if i == 2:
        continue
    else:
        ans = 0
        break
if ans == 0:
    pass
if ans != 0:
    for i in range(N//2):
        ans = (ans * 2) % (10**9 + 7)
print(ans)

Measured memory_bytes: 20412
#include<bits/stdc++.h>
#pragma GCC optimize("O999")
#define long long ll
const int INF = 0x3f3f3f3f;
int maxn=5000005;
using namespace std;
int main()
{
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
    int n,k;
    cin>>n>>k;
    int h[n],s=0;
    for(int i=0;i<n;i++)
    {
    	cin>>h[i];
    	if(h[i]>=k)
    	s++;
	}
	cout<<s;
	return 0;
}


Measured memory_bytes: 640
/**
 *    author:  tootal    
 *    created: 2020/04/11 15:49:59
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int len = s.length();
    for (int i = 0; i < len; ++i) {
        if (s[i] >= '1' && s[i] <= '9') {
            s[i] = '9' - s[i] + '1';
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int N;
  scanf("%d",&N);
  char s[N];
  char t[N];
  scanf("%s %s",&s,&t);
  int j;
  for(j=0;j<N;j++){printf("%c%c",s[j],t[j]);
  }return 0;
}


Measured memory_bytes: 1684
#include <bits/stdc++.h>
#define MAX 10000
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
struct Node{int p,l,r;};
Node T[MAX];
int D[MAX],H[MAX];
void preorder(int u){
	if(u==-1)return;
	printf(" %d",u);
	preorder(T[u].l);
	preorder(T[u].r);
}
void inorder(int u){
	if(u==-1)return;
	inorder(T[u].l);
	printf(" %d",u);
	inorder(T[u].r);
}
void postrder(int u){
	if(u==-1)return;
	postrder(T[u].l);
	postrder(T[u].r);
	printf(" %d",u);
}
int main(){
    int root,n,a,b,c;
	cin>>n;
	r(i,n)T[i].p=-1;
	r(i,n){
	  cin>>a>>b>>c;
	  T[a].l=b;
	  T[a].r=c;
	  if(b!=-1)T[b].p=a;
	  if(c!=-1)T[c].p=a;
	}
	r(i,n)if(T[i].p==-1)root=i;
	printf("Preorder\n");
	preorder(root);
	cout<<endl;
	printf("Inorder\n");
	inorder(root);
	cout<<endl;
	printf("Postorder\n");
	postrder(root);
	cout<<endl;
}

Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#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(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " -> " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" -> ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, k;
    cin >> n >> k;
    int snuke[110] = {0};
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int a;
            cin >> a;
            snuke[a]++;
        }
    }
    int ans = 0;
    rep(i, n) {
        ans += snuke[i + 1] == 0;
    }
    cout << ans << endl;
}

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


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

using namespace std;

/***template***/
#define ll                   long long
#define dd                   double
#define scl(n)               scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define pi                   pair<ll,ll>
#define pb                   push_back
#define mp                   make_pair
#define uu                   first
#define vv                   second
#define FOR(i,n)             for(ll i=1;i<=n;i++)
#define LOOP(i,n)            for(ll i=0;i<n;i++)
#define FOOR(i,a,b)          for(ll i=a;i<=b;i++)
#define LOP(i,a,b)           for(ll i=a;i<b;i++)
#define sorted(s)            sort(s.begin(),s.end())
#define reversed(s)          reverse(s.begin(),s.end())
#define contains(a,b)        (find((a).begin(), (a).end(), (b)) != (a).end())
#define MAXN                 10004
#define pii                  3.1415926536
#define mod                  1000000007
#define eps                  0.0000000001
#define inf                  9000000000000000
#define mstt(a,b)            memset((a),(b),sizeof (a))


int main()
{
    ll n,a,b;
    scl(n);
    scl(a);
    scl(b);
    if(b+n<=a)
        cout<<a-b-n<<endl;
    else if(b>=a+n)
        cout<<b-a-n<<endl;
    else
        cout<<0<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5;
vector<int> mp[MAX_N + 5];
bool vis[MAX_N + 5], flag;
int n, m, ans[MAX_N + 5], cnt = 0;
void dfs(int x)
{
    int i;
    for (i = 0; i < mp[x].size(); i++) {
        if (!vis[mp[x][i]]) {
            vis[mp[x][i]] = 1;
            dfs(mp[x][i]);
            if (flag) {
                ans[cnt++] = x;
                return;
            }
        }
    }
    if (i == mp[x].size()) {
        flag = 1;
        ans[cnt++] = x;
        return;
    }
}
int main()
{
    int u, v;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &u, &v);
        mp[u].push_back(v);
        mp[v].push_back(u);
    }
    memset(vis, 0, sizeof(vis));
    vis[1] = 1;
    flag = 0;
    for (int i = 0; i < mp[1].size(); i++) {
        if (!vis[mp[1][i]]) {
            vis[mp[1][i]] = 1;
            dfs(mp[1][i]);
            break;
        }
    }
    int cnt1 = cnt;
    flag = 0;
    for (int i = 0; i < mp[1].size(); i++) {
        if (!vis[mp[1][i]]) {
            vis[mp[1][i]] = 1;
            dfs(mp[1][i]);
            break;
        }
    }
    printf("%d\n", cnt + 1);
    for (int i = 0; i < cnt1; i++) {
        printf("%d ", ans[i]);
    }
    printf("1");
    for (int i = cnt - 1; i >= cnt1; i--) {
        printf(" %d", ans[i]);
    }
    puts("");
    return 0;
}


Measured memory_bytes: 11008
from sys import stdin, stderr
from itertools import groupby, permutations, combinations
from bisect import bisect_right
import numpy as np


def main():
    N = int(input())
    L = sorted([int(x) for x in input().split()])
    ret = 0
    # print(L, file=stderr)
    # for ij in combinations(range(N - 1), 2):
    #     i, j = ij
    #     c = L[i] + L[j] - 1
    #     k = bisect_right(L, c)
    # #     k = np.searchsorted(L, c, side='right')
    #     ret += k - j - 1

    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            c = L[i] + L[j] - 1
            # k = np.searchsorted(L, c, side='right')
            k = bisect_right(L, c)
            # print(L[i], L[j], k, ret, file=stderr)
            ret += k - j - 1
    return ret


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 14220
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	a,b,x = readline() |> split |> parseMap
	if a*a*b*0.5>=x
		println(atand(a*b*b/(2*x)))
	else
		println(atand((2*(a*a*b-x))/(a^3)))
	end
end

main()

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    string ss;
    cin >> ss;
    for(ll i = 0 ; i < ss.size(); i++) cout << 'x';
}


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

int main() {
    int N, K, S;
    cin >> N >> K >> S;
    int rem = S+1;
    if (rem > 1000000000) rem = 1;
    for (int i = 0; i < K; ++i) cout << S << " ";
    for (int i = K; i < N; ++i) cout << rem << " ";
    cout << endl;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, res;
  rd(A);
  rd(B);
  if(A >= 13){
    res = B;
  }
  else if(A >= 6){
    res = B/2;
  }
  else{
    res = 0;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190526-1

// --- original code ---
// {
//   int A, B, res;
//   rd(A, B);
//   if(A >= 13){
//     res = B;
//   } else if(A >= 6){
//     res = B/2;
//   } else {
//     res = 0;
//   }
//   wt(res);
// }


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  int X;
  cin >> X;
  if(X >= 30){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

int main()
{
    int N;
    cin >> N;
    map<int, int> a;
    for (int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    int ans = 0;
    for (auto v : a)
    {
        if(v.second>=v.first)
        {
            ans += v.second - v.first;
        }
        else
        {
            ans += v.second;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4736
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

# dijkstra（経路復元できるパターン）
from collections import defaultdict
import heapq
# sからすべての頂点への最小距離を求める O(|E| log |V|)
# 戻り値は min_dist_list, routelist。
# m_d_l : [0への最小距離, 1への最小距離, 2への最小距離, ...]
#  辿り着けないノードの場合、関数内で定義した定数INFを返す
# rl : [0の直前ノード, 1の直前ノード, ...] ただしlist[始点]は-1が入る
#  （注）本来到着不可能なノードでも、INF距離で辿り着けく設定なので経路が返る
# s: startノード
# n: 頂点数
# グラフデータは辞書を使っている。{ノードID:[(to,cost)を格納したリスト],...}
#  graph[nodeID] = [(to1, cost1), (to2, cost2), ...]
# 存在しないキーがエラーになってしまうと困るので、
# graph = defaultdict(list)として、要素を空リストで初期化して生成する
def dijkstra(s: int, n: int, graph: dict) -> list:
  INF = 10 ** 10 #INF以上の経路が存在する可能性がある場合は注意か？？
  que = []    # [(最短距離, node番号)]
  routelist = [-1] * n # routelist[node番号] = 最短経路における1つ前のノード
  heapq.heappush(que, (0, s))
  min_dist_list = [INF] * n
  min_dist_list[s] = 0
  while que:
    now_dist, node = heapq.heappop(que)

    if min_dist_list[node] < now_dist:
      continue

    for to, dist in graph[node]:
      new_dist = now_dist + dist
      if min_dist_list[to] > new_dist:
        min_dist_list[to] = new_dist
        routelist[to] = node
        heapq.heappush(que, (new_dist, to))

  return min_dist_list, routelist

N, M = mi()
SGDs = [tuple(mi()) for _ in range(M)] #start, goal, distance

#dijkstra()に渡すためのグラフデータを生成する
Graph = defaultdict(list) #辞書をlist()で初期化
for s, g, d in SGDs: #start, goal, distance
  s, g = s-1, g-1 #入力が1スタートなので0スタートに訂正
  Graph[s].append((g, d)) #nodeIDがkeyになっているdict-->dict[key]（list）に(行き先番号, 距離を入れていく)
  Graph[g].append((s, d)) #無向グラフなので逆向きも入れる

#最短経路に含まれる辺をこの集合に格納していく
#格納するのはタプル(s, g)。無向グラフなので両面を入れるように注意
Contained_Edge = set()
for eachstart in range(N): #各ノードをスタート地点にする全探索
  routelist = dijkstra(eachstart, N, Graph)[1] #経路復元リストを得る
  for i, prev in enumerate(routelist):
    #prev->iというルートだと分かるので、それをContained_Edgeに入れる
    if prev+1: #prev=-1の場合は実行されない（スタート地点なので無視）
      Contained_Edge.add((i,prev))
      Contained_Edge.add((prev,i))

#全ての辺の集合
All_Edges = {(s-1,g-1) for s, g, d in SGDs}

#print(All_Edges)
#print(Contained_Edge)
#print(All_Edges - Contained_Edge)
print(len(All_Edges - Contained_Edge))



Measured memory_bytes: 53596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int[] a = in.nextIntArray(n);

			int count = 0;

			for (int l = 0, r = 0; l < n; l = r) {
				while (r < n && a[l] == a[r]) {
					r++;
				}
				int len = r-l;
				count += len/2;
			}

			out.println(count);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21588
console.log((args=>{
  const [S,T] = args.trim().split`\n`;
  const sl = S.length, tl = T.length;
  let min = tl;
  for ( let i = 0; i <= sl-tl; i++ ) {
    let count = 0;
    for ( let j = 0; j < tl; j++ ) {
      if ( S[i+j] !== T[j] ) count++;
    }
    if ( min > count ) min = count;
  }
  return min;
})(require('fs').readFileSync('/dev/stdin','utf8')));


Measured memory_bytes: 32388
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
		    h -= sc.nextInt();
		}
		if (h <= 0) {
		    System.out.println("Yes");
		} else {
		    System.out.println("No");
		}
	}
}


Measured memory_bytes: 50392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// 隣接リスト
vvll g(200010, vll());
vi visited(200010, 0);

ll n;
void pr(bool x){
    cout << (x ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    exit(0);
}

// グラフに対する幅優先探索
void bfs(ll start){
    queue<pll> q;
    visited[start] = 1;
    ll depth = 0;
    ll now = start;
    q.push(make_pair(now, depth));
    while(!q.empty()){
        now = q.front().first;
        depth = q.front().second;
        q.pop();
        if(now == n && depth <= 2){
            pr(1);
        }
        rep(i, SZ(g[now])){
            ll next = g[now][i];
            if(!visited[next]){
                visited[next] = 1;
                q.push(make_pair(next, depth+1));
            }
        }
    }
    pr(0);
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll m;
    cin >> n >> m;
    vll a(m), b(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        g[a[i]].emplace_back(b[i]);
        g[b[i]].emplace_back(a[i]);
    }
    bfs(1);
    return 0;
}

Measured memory_bytes: 18280
#include<iostream>
#include<algorithm>
#include<utility>
#include<queue>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<LL, LL>P;
#define F first
#define S second
LL tm[222222];
vector<P>v;
queue<P>Q;
int main() {
	LL n, t;
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		cin >> tm[i];
		Q.push(P(tm[i], tm[i] + t));
	}

	v.push_back(Q.front());
	Q.pop();
	while (Q.size()) {
		if (v[v.size() - 1].S >= Q.front().F) {
			P p = v[v.size() - 1];
			v.pop_back();
			v.push_back(P(p.first, Q.front().S));
			Q.pop();
		}
		else {
			v.push_back(Q.front());
			Q.pop();
		}
	}
	LL ans = 0;
	for (int i = 0; i < v.size(); i++) {
		ans += v[i].second - v[i].first;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll t=1;
   //cin>>t;
   while(t--)
   {
       ll n;
       cin>>n;
       ll a[n+1],i;
       for(i=0;i<n;i++)
        cin>>a[i];
        ll ans=0,sum=1000;
       for(i=0;i<n-1;i++)
       {
           if(a[i+1]>a[i])
           {
               ans+=a[i+1]*(sum/a[i])+sum%a[i];
               sum=a[i+1]*(sum/a[i])+sum%a[i];

           }


       }
       cout<<sum<<endl;
   }

}


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

int main() {
    string c;
    cin >> c;
    
    if (c == "a" || c == "i" || c == "u" || c == "e" || c == "o"){
        cout << "vowel" << endl;
    }
    else {
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		FastScanner scan = new FastScanner();

		int n = scan.nextInt();

		int result = 0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				for (int k = 0; k < n; k++)
					result++;

		out.println(result);
		out.flush();
	}
}


class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

Measured memory_bytes: 21460