akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1001001001;

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

    int n;
    cin >> n;
    map<int, P> mp;     // P : (pos, cnt)
    mp[0] = P(0, 0);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        a *= -1;
        if(mp.find(a) == mp.end())  mp[a] = P(i, 1);
        else    ++mp[a].second;
    }
    vector<ll> res(n);
    for(auto it = mp.begin(); it != mp.end(); ++it){
        int pos = it->second.first;
        int cnt = it->second.second;
        if(it->first == 0)  continue;
        auto next_it = it;
        ++next_it;
        if(next_it->first == 0){
            res[pos] -= (ll)it->first * cnt;
        }
        else{
            ll num = next_it->first - it->first;
            res[pos] += num * cnt;
            next_it->second.first = min(pos, next_it->second.first);
            next_it->second.second += cnt;
        }
    }
    for(int i = 0; i < n; ++i){
        cout << res[i] << "\n";
    }
}

Measured memory_bytes: 8192
A, B = map(int, input().split())

def f(n):
    if n % 4 == 0:
        return n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return 1 ^ n
    else:
        return 0
    
print(f(A-1) ^ f(B))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n;
	cin>>n;
	ll sum = 0;
	//ll a[n];
	ll a;
	ll prev = 0;
	cin>>prev;
	for(ll i =1; i<n; i++)
	{
		cin>>a;
		if(a<prev)
		{
			sum+=abs(prev-a);
			prev = a+abs(prev-a);
		}
		else
		{
			prev = a;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3628
ans=chk=0
d=[]
for i in range(5):
    x=int(input())
    if x%10:
        d.append((x%10,x))
    else:
        ans+=x
d.sort(reverse=True)
for i in d:
    ans+=((i[1]+10)//10)*10
if len(d): ans-=10-d[-1][1]%10

print(ans)


Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using ll = unsigned long long;
using namespace std;

int main(void) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int xlen = x2 - x1;
    int ylen = y2 - y1;

    cout << x2 - ylen << " " << y2 + xlen <<" " << x1 - ylen << " " << y1 + xlen << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1e5;
int n;
struct node
{
	int x,order;
}a[MAXN+5];
bool cmp(node a,node b)
{
	if(a.x<b.x)
		return true;
	else
		return false;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].x);
		a[i].order=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
		if(i==n)
			printf("%d",a[i].order);
		else
			printf("%d ",a[i].order);
	return 0;
}


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

using namespace std;

int main(){
	//your code goes here
	string s;
	cin >> s;
	if(s.substr(s.length()-1, 1) =="s"){
		cout << s << "es\n";
	} else {
		cout << s << "s\n";
	}
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int m1,d1,m2,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(abs(d1-d2) > 1)cout << 1 << endl;
    else cout <<0 << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

class Bar
{
	static public void Main(string[] args)
	{
		int H, W;
		string[] vals = Console.ReadLine().Split(' ');
		H = int.Parse(vals[0]);
		W = int.Parse(vals[1]);
		long min1 = calcMin(H,W);
		long min2 = calcMin(W,H);
		Console.WriteLine(Math.Min(min1, min2));
	}
	
	static long calcMin(long H, long W)
	{
		long min = long.MaxValue;

		for(long h=1; h<=H-1; h++)
		{
			long SA, SB, SC;
			SA = h * W;

			long h2 = (H-h) / 2;
			long h3 = H - h - h2;
			//Console.WriteLine("h={0}, h2={1}, h3={2}", h, h2, h3);
			if(h2 > 0 && h3 > 0)
			{
				SB = h2 * W;
				SC = h3 * W;
				long[] S = {SA,SB,SC};
				Array.Sort(S);
				long d = S[2] - S[0];
				if(d >= 0 && d < min)
				{
					//Console.WriteLine("min={0}", d);
					//Console.WriteLine("h={0}, h2={1}, h3={2}", h, h2, h3);
					min = d;
				}
			}

			long w = W / 2;
			long w2 = W - w;
			if(w > 0 && w2 > 0)
			{
				SB = (H-h) * w;
				SC = (H-h) * w2;
				long[] S = {SA,SB,SC};
				Array.Sort(S);
				long d = S[2] - S[0];
				if(d >= 0 && d < min)
				{
					//Console.WriteLine("min={0}", d);
					//Console.WriteLine("h={0}, w={1}, w2={2}", h, w, w2);
					min = d;
				}
			}
		}

		return min;
	}
}


Measured memory_bytes: 17476
#include <iostream>
using namespace std;
#include<bits/stdc++.h> 
#define ll long long int
#define read(a) long long int a; cin>>a;
#define readstr(s) string s; cin>>s;
#define readarr(a,l) long long int a[l]={0}; for(ll i=0;i<l;i++) cin>>a[i];
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define ff first
#define ss second
#define readmtrx(i,j,a,b) ll arr[a][b]={0};for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) cin>>arr[i][j];
#define v(pi) vector<ll>pi
#define vp(pi) vector<pair<ll,ll>>pi
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define pb(p) push_back(p)
#define mp make_pair
#include <cmath>
int main() {
	fast;
	read(a)ll d=0;
	readarr(arr,a);ll l=0;
	loop(i,0,a-1){
		if(arr[i]>=arr[i+1]) d++;
		else {l=max(l,d);d=0;}
	}
	l=max(l,d);
	cout<<l<<endl;
	return 0;
}

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

int main()
{ 
  int n,m; 
  cin >> n >> m;
  int a[n][m],b[m],c[n];
  
  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++)
  {
    cin >> b[i];
  }

  for(int i=0;i<n;i++)
  {
    c[i]=0; 
    for(int j=0;j<m;j++)
    {
      c[i] += a[i][j] * b[j];
    }
    cout << c[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	
	vector< vector<int> > a(n, vector<int>(m, 0));
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			cin >> skipws >> a[i][j];

	vector<int> b(m, 0);
	for (int i = 0; i < m; ++i)
		cin >> b[i];

	for (int i = 0; i < n; ++i)
	{
		int sum = inner_product(a[i].begin(), a[i].end(), b.begin(), 0);
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 1256
N,K=map(int,input().split())
A=list(map(int,input().split()))

ans=0
for i in range(N-1):
  if A[i]+A[i+1]>K:
    tmp=min(A[i+1],A[i]+A[i+1]-K)
    A[i+1]-=tmp
    ans+=tmp
  if A[i]+A[i+1]>K:
    tmp=min(A[i],A[i]+A[i+1]-K)
    A[i]-=tmp
    ans+=tmp
    
if A[-1]>K:
  tmp=A[-1]-K
  A[-1]-=tmp
  ans+=tmp
print(ans)

Measured memory_bytes: 14812
#include <bits/stdc++.h>  
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N =  200010;  
const int mod = 1e9 + 7;
#define FI first
#define SE second
typedef pair<int, int>pii;
int rec[N];
int main()  
{  
  // freopen("in.txt","r",stdin);
 	int n, m;
 	while (~scanf("%d%d", &n, &m))
 	{
 		bool flag = false;
 		for (int i = 0; i < m; i++)
 		{
 			int a, b;
 			scanf("%d%d", &a, &b);
 			if (a == 1 || a == n)
 				rec[b]++;
 			if (b == 1 || b == n)
 				rec[a]++;
 		}
 		for (int i = 1; i <= n; i++)
 			if (rec[i] == 2)
 			{
 				flag = true;
 				break;
 			}
 		printf("%s\n", flag?"POSSIBLE":"IMPOSSIBLE");
 	}

   

   return 0;  
}  

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	printf("%d\n",max(a-b,max(a+b,a*b)));
}


Measured memory_bytes: 128
N, M = map(int, input().split())
a = [0] * N
b = [0] * N
c = [0] * M
d = [0] * M
for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(M):
    c[i], d[i] = map(int, input().split())

check = [[0]*M for _ in range(N)]

for i in range(N):
    for j in range(M):
        check[i][j] = max(a[i]-c[j],c[j]-a[i]) + max(b[i]-d[j],d[j]-b[i])
    print(check[i].index(min(check[i])) + 1)



Measured memory_bytes: 3064
import java.io.*
import java.util.*

fun solve(N: Long, K: Long, H: LongArray){
    H.sort()
    println(H.slice(0 until (N-K).toInt()).sum())
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val K = sc.next().toLong()
    val H = LongArray(N.toInt())
    for (i in 0 until N.toInt()) {
        H[i] = sc.next().toLong()
    }
    solve(N, K, H)
}



Measured memory_bytes: 63256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


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


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

    ll ans = 0;
    sort(a, a + n);

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            auto it = lower_bound(a, a + n, a[i] + a[j]);
            if (it > a) {
                it--;
                int ind = it - a;
                ans += ind - j;
            }
        }
    }

    cout << ans;


}

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

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

#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back

const long double PI = acos(-1);

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}

int main(){
  ll n;
  cin >> n;
  vector<vector<pair<ll, ll>>> v;
  v.resize(n);

  for(ll i = 0; i < n; i++){
    ll a = 0;
    cin >> a;
    v[i].resize(a);
    for(ll j = 0; j < a; j++){
      cin >> v[i][j].first >> v[i][j].second;
      v[i][j].first--;
    }
  }
  
  ll res = 0;
  for(ll i = 0; i < (1<<n); i++){
    bool flag = true;

    for(ll j = 0; j < n; j++){
      if(!(i & (1 << j))) continue;

      for(pair<ll, ll> xy : v[j]){
        ll x = xy.first;
        ll y = xy.second;

        if(y == 1 && !(i & (1 << x))) flag = false;
        if(y == 0 && (i & (1 << x))) flag = false;
      }
    }

    if(flag){
      ll count = 0;
      for(ll j = 0; j < n; j++){
        if(i & (1 << j)) count++;
      }
      res = max(res, count);
    }
  }

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#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)

using ll = long long;
#define INF 1e9

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

  int ans = N / (2*D+1);
  if( N > ans * (2*D+1)){
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    char a;cin>>a;
    if(a>='A'&&a<='Z')cout<<"A";
    else cout<<"a";
 
return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main() {
  ll N;
  ll cost = 0;
  cin >> N;
  vector <ll> stones(N);
  for(int i = 0; i < N; i++){
    cin >> stones[i];
  }
  vector <ll> dp(N);
  dp[0] = 0;
  dp[1] = abs(stones[1] - stones[0]);
  for(int q = 2; q < N; q++){
    ll step1 =  abs(stones[q] - stones[q-2]);
    ll step2 =  abs(stones[q] - stones[q-1]);
    dp[q] = min(dp[q-2] + step1,dp[q-1] + step2);
  }
  cout << dp[N-1];
}

Measured memory_bytes: 4776
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	string s; cin >> s;
	int sum = 0;
	for (int i = 0; i < s.size(); i++)
	{
		char c = s[i];
		sum += atoi(&c);
	}

	if (atoi(s.c_str()) % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
const int maxn=1e6+7;
typedef long long ll;
const int mod=998244353;
#define IO cin.tie(0),ios::sync_with_stdio(false);
#define pi acos(-1)
#define PII pair<ll,ll>
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()
/** keep hungry and keep calm! **/

int s[]={0,2,5,5,4,5,6,3,7,6},a[maxn],ans[maxn],n,m,dp[maxn];
int cmp(int a,int b){
    if(s[a]!=s[b]) return s[a]<s[b];
    return a>b;
}

int cmp1(int a,int b){
    return a>b;
}

int Sheryang(){

    n=read,m=read;
    for(int i=0;i<m;i++){
        a[i]=read;
    }
    memset(dp,-1,sizeof(dp));
    dp[0]=1;

    int vis[10]={0};
    for(int i=0;i<m;i++){
        for(int j=s[a[i]];j<=n;j++){
            dp[j]=max(dp[j],dp[j-s[a[i]]]+1);
        }
    }

    sort(a,a+m,cmp1);
    while(n){
        for(int i=0;i<m;i++){
            if(n>=s[a[i]] && dp[n-s[a[i]]]+1==dp[n]){
                putchar(a[i]+'0');
                n=n-s[a[i]];break;
            }
        }
    }

    puts("");
    return 0;
}


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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, n;
    string s;
    cin >> n >> a >> b >> s;
    int ct1=0, ct2=0;
    for(int i=0; i<s.length(); ++i){
        if(s[i] == 'c') {
            cout << "No\n";
        }
        else if(s[i] == 'a'){
            if(ct1 < a+b){
                cout << "Yes\n";
                ++ct1;
            }
            else
                cout << "No\n";
        }
        else{
            if(ct1 < a+b && ct2 < b){
                cout << "Yes\n";
                ++ct1, ++ct2;
            }
            else
                cout << "No\n";
        }
    }
}


/**
7 2 3
bbcccbb
*/


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    vector<ll> a(3);
    REP(i, 3) cin >> a[i];

    bool all_ = true;
    REP(i, 3) {
        if(a[i] % 2 == 0) all_ = false;
    }

    if(all_) {
        sort(ALL(a));
        ll tmp1 = 1, tmp2 = 1;
        REP(i, 3) {
            if(i == 2) {
                tmp1 *= a[i] / 2;
                tmp2 *= a[i] / 2 + 1;
            } else {
                tmp1 *= a[i];
                tmp2 *= a[i];
            }
        }
        cout << tmp2 - tmp1 << endl;
    } else {
        cout << "0" << endl;
    }

    return 0;
}

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

const int N = 105;
int in[N];

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    for (int i = 1; i <= m; ++i) {
        int x; cin >> x;
        in[x] = 1;
    }

    int t = x;
    int res = 0, cnt = 0;
    while(t > 0) {
        res += in[t];
        t--;
    }

    while(x < n) {
        cnt += in[x];
        x++;
    }

    printf("%d\n", min(res, cnt));

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 3e3+10;
const int M = 1e6+10;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}
inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}
inline ll C(ll y, ll x) { ll ans = 1; if(y < 0 || x < 0 || y < x) return 0; y %= mod; if(!y || !x) return 1; for0(i, x) ans = ans * (y-i) % mod; for1(i, x) ans = ans * Pow(i, mod-2) % mod; return ans; }
//==================================================================================================================================================================//

int dp[N][N];
char x[N], y[N];

int main() {
   scanf(" %s", x+1);
   scanf(" %s", y+1);
   int len1 = strlen(x+1), len2 = strlen(y+1);
   for(int i = len1; i; --i) for(int j = len2; j; --j) {
      if(x[i] == y[j]) dp[i][j] = dp[i+1][j+1] + 1;
      else dp[i][j] = max(dp[i+1][j], dp[i][j+1]);
   }
   for(int i = 1, j = 1; i <= len1 && j <= len2;) {
      if(x[i] == y[j]) {
         printf("%c", x[i]);
         i++, j++;
      }
      else if(dp[i][j] == dp[i+1][j]) i++;
      else j++;
   }
   return 0;
}

Measured memory_bytes: 38924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const int n_max=1e5+5;
vector<int> g[n_max];
vector<int> ans;

int dfs(int v){
  vector<int> ans;
  for(auto i:g[v]){
    ans.pb(dfs(i));
  }
  if(g[v].empty()){
    ans.pb(0);
  }
  sort(ans.begin(),ans.end());
  int next=ans[0]+1;
  rep1(i,ans.size()-1){
    if(next>ans[i]){
      next++;
    }
    else{
      next=ans[i]+1;
    }
  }
  return next;
  
}



int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  int a;
  rep1(i,n-1){
    cin >> a;
    a--;
    g[a].pb(i);
  }
  cout << dfs(0)-1 << endl;;
  

  return 0;
    

}


Measured memory_bytes: 16640
#include<stdio.h>
int main () {
	int width , height;
	int a[100][100] , b[100] , ab[100] = {0};
	int i , s;

	scanf("%d %d" , &height , &width);
	for(i = 0; i < height; i++) {
		for(s = 0; s < width; s++) {
			scanf("%d" , &a[i][s]);
		}
	}
	for(i = 0; i < width; i++) {
		scanf("%d" , &b[i]);
	}

	for(i = 0; i < height; i++) {
		for(s = 0; s < width; s++) {
			ab[i] += a[i][s] * b[s];
		}
	}

	for(i = 0; i < height; i++) {
		printf("%d\n" , ab[i]);
	}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    int N,M,Q;cin>>N>>M>>Q;
    string s[N];
    int sum[N+1][M+1];
    fill(sum[0],sum[N+1],0);
    for (int i=1;i<=N;i++){
        cin>>s[i-1];
        for (int j=1;j<=M;j++){
            sum[i][j]=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+s[i-1][j-1]-'0';
        }
    }
    int holi[N+1][M+1];
    int high[N+1][M+1];
    fill(holi[0],holi[N+1],0);
    fill(high[0],high[N+1],0);
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
            if(i*j==1)continue;
            holi[i][j]=holi[i][j-1]+holi[i-1][j]-holi[i-1][j-1];
            high[i][j]=high[i][j-1]+high[i-1][j]-high[i-1][j-1];
            if(j>=2&&s[i-1][j-1]=='1'&&s[i-1][j-2]=='1')holi[i][j]++;
            if(i>=2&&s[i-2][j-1]=='1'&&s[i-1][j-1]=='1')high[i][j]++;
        }
    }

    REP(i,Q){
        int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
        int ans=sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1];
        ans   -=holi[x2][y2]-holi[x1-1][y2]-holi[x2][y1]+holi[x1-1][y1];
        ans   -=high[x2][y2]-high[x1][y2]-high[x2][y1-1]+high[x1][y1-1];
        cout<<ans<<endl;
    }


    return 0;
}

Measured memory_bytes: 52864
def main():
    X=int(input())
    start=0
    back=-1
    while(True):
        back=X-pow(start,5)
        if back>0:
            A_back=int(pow(back,1/5))
        else:
            A_back=-int(pow(-back,1/5))

        front=X+pow(start,5)
        if front>0:
            A_front=int(pow(front,1/5))
        else:
            A_front=-int(pow(-front,1/5))
        if(pow(A_back,5)==back):
            A=A_back
            B=-start
            break
        elif(pow(A_front,5)==front):
            A=A_front
            B=start
            break
        else:
            start+=1
    print(A,B)
if __name__=='__main__':
    main()

Measured memory_bytes: 62620
/*************************************
 *プログラム名：B.c
 *
 *************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>
#include <pthread.h>

//<<<<<>>>>>//

void swap(int *a, int *b)
{
	int buf;
	
	buf = *a;
	*a = *b;
	*b = buf;
}

void bubble(int *A, int N)
{
	int i, j;
	
	for (i = 0; i < N; i++) {
		for (j = 0; j < N - 1; j++) {
			if (*(A + j) < *(A + j + 1)) {
				swap(A + j, A + j + 1);
			}
		}
	}
}

int main(void)
{
	int i, N, K, sum;
	int *l;
	
	scanf("%d %d", &N, &K);
	
	l = malloc(sizeof(int) * N);
	
	for (i = 0; i < N; i++) {
		scanf("%d", l + i);
	}
	
	bubble(l, N);
	
	/*for (i = 0; i < N; i++) {
		printf("%d\n", *(l + i));
	}*/
	
	sum = 0;
	
	for (i = 0; i < K; i++) {
		sum += *(l + i);
	}
	
	printf("%d\n", sum);
	
	return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  string X;
  cin >> X;
  stack<char> L{}, R{};
  REP(i, X.size()) { R.push(X[X.size() - 1-i]); }
  while (!R.empty()) {
    L.push(R.top());
    R.pop();
    while (!R.empty() && !L.empty()) {
      if (L.top() == 'S' && R.top() == 'T') {
        L.pop(), R.pop();
      } else {
        break;
      }
    }
  }
  ll ans = 0;
  while (!L.empty()) {
    ans++;
    L.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 3812
N = int(input())
A = list(map(int, input().split()))
chushin = sum(A)//N
chushin_1 = sum(A)//N +1
answer = 0
answer_1 = 0
for a in A:
    answer += abs(a-chushin) ** 2
    answer_1 += abs(a-chushin_1) ** 2
print(min(answer,answer_1))

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < 100; i++ {
		for j := 0; j < 100; j++ {
			if i*4+j*7 == n {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
N,K= map(int, input().split())
flags = [-1]*N
M = 1
mods = []
mods.append(0)
A = list(map(int,input().split()))
now = 0
I = 0
flags[0] = 0
if K < 1000000:
    for i in range(K):
        now = A[now] -1

    print(now+1)
else:
        
    for i in range(N):
        now = A[now]-1
        
        
        if flags[now]!=-1:
            I = i
            M=i+1-flags[now]
            break
        mods.append(now)
        flags[now] = i+1

    I += 1
    alt = mods[I-M:]

    if K-I<=0:
        print(now+1)
    else:
        print(alt[(K-I)%(len(alt))]+1)




Measured memory_bytes: 33940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    int n;
    cin >> n;
    int flag = 0;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(a%2 == 0){
            if((a%3 != 0) && (a%5 != 0)){
                flag = 1;
            }
        }
    }
    if(flag == 0) cout << "APPROVED";
    else cout << "DENIED";
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 23 02:13:44 2020

@author: Kanaru Sato
"""

s = input()
n = len(s)

count = 0

for state in range(2**(n-1)):
    nums = s
    for i in range(n-1):
        if state & (1<<i):
            nums = nums[:n-1-i]+"+"+nums[n-1-i:]
    count += sum(map(int, nums.split("+")))

print(count)

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



int n;
int cnt[303030];
string s;
void solve(){
	cin >> n >> s;
	
	for(int i = 0; i < n; i++){
		cnt[i+1] = cnt[i];
		if(s[i] == 'W') cnt[i+1]++;
	}
	int ans = INF;
	for(int i = 1; i <= n; i++){
		chmin(ans, cnt[i-1]+(n-i-cnt[n]+cnt[i]));
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1812
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

ll A;
ll V;
ll B;
ll W;
ll T;

int main() {
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;

    bool isFind = true;
    ll dif = abs(B - A);
    if (dif == 0) {
        cout << "YES" << endl;
        return 0;
    }
    if (W > V) {
        cout << "NO" << endl;
        return 0;
    }

    if ((V - W) * T >= dif) {
        cout << "YES" << endl;
        return 0;
    } else {
        cout << "NO" << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

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

		if(a == b){
			System.out.println("Draw");
		}else if(a == 1){
			System.out.println("Alice");
		}else if(b == 1){
			System.out.println("Bob");
		}else if(a > b){
			System.out.println("Alice");
		}else{
			System.out.println("Bob");
		}
	}
}


Measured memory_bytes: 21844
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

string s;

ll dfs(int &now){
    if(s[now] == '['){
        vector<int> da(0);
        now++;
        while(s[now] != ']'){
            da.push_back(dfs(now));
            // vdeb(da);
            // cout << s[now] << endl;
        }
        now++;
        sort(all(da));
        int n = da.size();
        ll ret = 0;
        rip(i,n/2+1,0) ret += da[i];
        return ret;
    }
    ll ret = 0;
    while(s[now] != ']') ret = ret*10+(s[now++]-'0');
    // now++;
    // cout << ret << endl;
    return ret/2+1;
}

int solve(){
    cin >> s;
    int now = 0;
    return dfs(now);
}

int main(){
    int t; cin >> t;
    rip(i,t,0) cout << solve() << '\n';
    return 0;
}


Measured memory_bytes: 3208
#include <stdio.h>
#include <stdbool.h>

int main(void) {
	int N;
	int S[200000] = {0};
	int A;
	
	scanf("%d", &N);
	for(int i = 1; i < N; i++) {
		scanf("%d", &A);
		S[A-1]++;
	}
	
	for(int i = 0; i < N; i++) {
		printf("%d\n", S[i]);
	}

	return 0;
}


Measured memory_bytes: 2512
/*
    Don't practice until you get it right. Practice until you can't get it wrong.
*/

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

#define ll long long
#define ld double
#define pii pair<ll,ll>
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vp vector<pii>
#define pb push_back
#define mp make_pair
#define sc(a) scanf("%lld",&a);
#define sd(a) scanf("%lf",&a);
#define test() ll tt;cin>>tt;for(ll testcase=1;testcase<=tt;testcase++)
#define all(v) v.begin(),v.end()
#define vivek_ghosh ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000055
#define mod 1000000007
#define ff first
#define ss second
const int INF=0x3f3f3f3f;
const ll int inf = LLONG_MAX;

ll power(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

ll modinv(ll a,ll m)
{
    ll g =__gcd(a, m);
    ll res=power(a, m-2, m);
    return res;
}

vb prime(MAX,true);
vl prm;
void sieve()
{
	prime[0] = prime[1] = false;
	for(ll p=2;p*p<MAX;p++)
	{
		if(prime[p])
		{
			for(ll i=p*p;i<MAX;i+=p)
				prime[i] = false;
		}
	}
	for(ll p=2;p<MAX;p++)
	{
		if(prime[p])
			prm.pb(p);
	}
}

ll n,m,t,i,j,k,q,x,y,ans=0,cnt=0,sum=0,mx=-1,mn=INT_MAX;
string s;

int main()
{
	vivek_ghosh;
	
	cin>>n>>m;
	ans = n*m;
	ans /= __gcd(n,m);
	cout<<ans<<endl;




	
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define ar array
#define endl '\n'


const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){

}

void solve(){    
 
    ll n,k;
    cin >> n >> k;
    ll a[n+1];
    for(ll i=1;i<n+1;i++)
        cin >> a[i];
    sort(a+1,a+n+1);
    ll sum=0;
    for(ll i=1;i<=k;i++){
        sum += a[i];
    }
    cout << sum << endl;

}


int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin >> T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3664
S = input()
def ok(s):
    if s[0] != 'A':
        return False
    elif s[2:-1].count('C') != 1:
        return False
    upper = 0
    for c in s:
        if c.isupper():
            upper += 1
    if upper != 2:
        return False
    return True

print('AC' if ok(S) else 'WA')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using  namespace std;
int main()
{

    int a,b,c;

    cin>>a>>b>>c;


    if(a>b)
        cout<<"0"<<"\n";
    else {

        if((b/a)>=c)
            cout<<c<<"\n";

        else
            cout<<b/a<<"\n";



    }
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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 long long INF = 1LL << 60;

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

  set<int> st;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    if(a == 1){
      if(st.count(b)){
        cout << "POSSIBLE" << endl;
        return 0;
      }
      st.insert(b);
    }
    if(b == n){
      if(st.count(a)){
        cout << "POSSIBLE" << endl;
        return 0;
      }
      st.insert(a);
    }
  }

  cout << "IMPOSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 9600
#ANS
input_all = input()
input_N = input_all.split()[0] #str型で読み込む
A,B = int(input_all.split()[1]),int(input_all.split()[2]) #int型で読み込む
input_list = [int(input_N[i]) for i in range(len(input_N))]

e = input_list[-1]
if len(input_list)>1:
    d = input_list[-2]
    if len(input_list)>2:
        c = input_list[-3]
        if len(input_list)>3:
            b = input_list[-4]
            if len(input_list)>4:
                a = input_list[-5]

count = 0
for i in range(int(input_N)+1):
    sum_all = 0
    i_str = str(i)
    for j in range(len(i_str)):
        sum_all += int(i_str[j])
    if A<=sum_all:
        if sum_all<=B:
            count += i
print(count)

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

int main(){
  int H1,M1,H2,M2,K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  
  int studystart = 0;
  
  studystart = (H2-H1)*60+(M2-M1)-K;
  
  cout << studystart << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=1000000007;
char s[100005];
int n,ans[100005][13],gkd[100005];
int add(int a,int b,int c)
{
	int sum;
	sum=(gkd[a]*b)%13;
	int p=c-sum;
	if (p<0) p+=13;
	ans[a][c]=(ans[a][c]+ans[a+1][p])%mod;
	return 0;
}
int main()
{
	scanf("%s",s);
	n=strlen(s);
	gkd[n-1]=1;
	ans[n][0]=1;
	for (int i=n-2;i>=0;i--)
		gkd[i]=(gkd[i+1]*10)%13;
	for (int i=n-1;i>=0;i--)
		for (int j=0;j<=12;j++)
		{
			if (s[i]=='?') for (int k=0;k<=9;k++) add(i,k,j);
			else add(i,s[i]-48,j);
		}
	printf("%d",ans[0][5]);
}

Measured memory_bytes: 5760
function Main(input){
	var a = parseInt(input,10);
  	if(a<1200){
    console.log('ABC')
    }else if(a<2800){
     console.log("ARC") 
    }else{
     console.log("AGC") 
    }
  
}
Main(require('fs').readFileSync('/dev/stdin','utf8')); 

Measured memory_bytes: 7372
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int main() {
    string s;cin >> s;
    int count = 0;
    rep1(i, s.size()-1) {
        if(s[i]==s[i-1]) {
            count++;
            s[i]=(s[i-1]=='0'?'1':'0');
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
// #define debug(x) cout << #x << " : " << x;
const double PI = acos(-1);

int x[4] = {0, -1, 0, 1};
int y[4] = {1, 0, -1, 0};

char arr[1010][1010];
int cnt[1010][1010];
int h, w;

int main(){
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> h >> w;

	memset(cnt, -1, sizeof(cnt));

	for (int i = 1; i <= h; i++) 
		for (int j = 1; j <= w; j++) 
			cin >> arr[i][j];

	queue<pair<ii, int > > q;

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (arr[i][j] == '#') {
				q.push({{i, j}, 0});
			}
		}
	}

	int ans = 0;

	while (!q.empty()) {
		int u = q.front().first.first;
		int v = q.front().first.second;
		int dist = q.front().second;
		q.pop();

		for (int i = 0; i < 4; i++) {
			int tx = u + x[i];
			int ty = v + y[i];

			if (tx > 0 && tx <= h && ty > 0 && ty <= w) {
				if ((cnt[tx][ty] > dist + 1 || cnt[tx][ty] == -1) && arr[tx][ty] == '.') {
					cnt[tx][ty] = dist + 1;
					q.push({{tx, ty}, cnt[tx][ty]});
				}
			}
		}
	}

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			// cout << cnt[i][j] << ' ' ;
			ans = max(ans, cnt[i][j]);
		}
		// cout << endl;
	}

	cout << ans << endl;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  ll x,y;cin>>x>>y;
  ll res=0;
  ll p = x;
  while(p<=y){
    res++;
    p *= 2;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
#define debug(x) cout<<#x<<" = { "<<x<<" }\n"
void fo (){fflush(stdout);}
using namespace std;
vector <pair<pair<int,int> , string>> v ;
bool cmp (pair<pair<int,int> , string> &a , pair<pair<int,int> , string> &b )
{

  if (a.s != b.s )return a.s < b.s ;
  return a.f.s > b.f.s ;
}
int main ()
{

  int n ;
  scanf ("%d" , &n );
  for (int i =0 ; i < n ; i++)
  {
    string x ;
    int p ;
    cin >> x >> p ;
    v.pb({{i + 1, p  } , x });
  }
  sort(all(v) , cmp );
  for (int i =0 ; i < n ;i++)
  {
    printf ("%d\n" , v[i].f.f );
  }
  cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


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

using ll = long long;

int main() {
    int D, N;
    cin >> D >> N;
    if (N == 100) N++;
    cout << N;
    rep(i, D) cout << "00";
    cout << "\n";
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
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; }
//template end

int mod=1e9+7;
struct Mint {
    int val;
    int inv() const{
        int tmp,a=val,b=mod,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        if(x<0)x+=mod; return x;
    }
    Mint():val(0){}
    Mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
    Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
    Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
    Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
    Mint& operator/=(const Mint& x){val=(ll)val*x.inv()%mod; return *this;}
    Mint operator+(const Mint& x)const{return Mint(*this)+=x;}
    Mint operator-(const Mint& x)const{return Mint(*this)-=x;}
    Mint operator*(const Mint& x)const{return Mint(*this)*=x;}
    Mint operator/(const Mint& x)const{return Mint(*this)/=x;}
    bool operator==(const Mint& x)const{return val==x.val;}
    bool operator!=(const Mint& x)const{return val!=x.val;}
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx){
        Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
    }
    Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
    Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
    Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

vector<int> g[200010];
Mint pre[200010],ans;
int n,sz[200010];
void dfs(int v,int p){
    bool f=1; int res=0;
    for(int nxt:g[v])if(nxt!=p){
        f=0; dfs(nxt,v); res+=sz[nxt]+1;
    }
    if(f){sz[v]=0; return;}
    else{sz[v]=res; return;}
}
void dfs2(int v,int p){
    int sum=n-1; Mint dec=0;
    for(int nxt:g[v])if(nxt!=p){
        dfs2(nxt,v); 
        dec+=pre[sz[nxt]+1]-1; sum-=sz[nxt]+1;
    }
    dec+=pre[sum]-1; ans+=pre[n-1]-dec-1;
}

int main(){
    scanf("%d",&n);
    rep(i,0,n-1){
        int a,b; scanf("%d%d",&a,&b); a--; b--;
        g[a].push_back(b); g[b].push_back(a);
    }
    pre[0]=1;
    rep(i,0,n)pre[i+1]=pre[i]*2;
    dfs(0,-1); dfs2(0,-1);
    ans/=pre[n]; printf("%d\n",ans.val);
    return 0;
}

Measured memory_bytes: 23936
#include <stdio.h>
int main(void){
     int i,n,tmp;
   scanf("%d",&n);
   int a[n];
   for(i=0;i<n;i++){
       scanf("%d",&a[i]);
   }
   for(i=0;i<n/2;i++){
       tmp =a[i];
       a[i]    =a[n-1-i];
       a[n-1-i]  =tmp;
   }
   for ( i = 0; i < n; i++ ){
   if ( i ) printf(" ");
   printf("%d", a[i]);
   }
   printf("\n");
return 0;
}



Measured memory_bytes: 2056
N, M = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]
lst.sort()
price = 0

for A, B in lst:
    if M == 0:
        break
    for i in range(B):
        price += A
        M -= 1
        if M == 0:
            break

print(price)

Measured memory_bytes: 27884
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,e,m,INF=((1LL<<31)-1LL),a,b,c;
vector<ll> v;
void ini(void){
    m=1;
    while(m<n)m*=2;
    v.resize(2*m-1,INF);
}
void STadd(ll a,ll b){
    a+=m-1;
    v[a]=b;
    while(a){
        a=(a-1)/2;
        v[a]=min(v[2*a+1],v[2*a+2]);
    }
    return ;
}
ll STquery(ll a,ll b,ll k,ll l,ll r){
    if(l>=b||r<=a)return INF;
    if(a<=l&&r<=b)return v[k];
    ll vr=STquery(a,b,2*k+1,l,(r+l)/2);
    ll vl=STquery(a,b,2*k+2,(r+l)/2,r);
    return min(vr,vl);
}
int main(void){
    cin>>n>>e;
    ini();
    for(int i=0;i<e;i++){
        cin>>a>>b>>c;
        if(a==0)STadd(b,c);
        else{
            cout<<STquery(b,c+1,0,0,m)<<endl;;
        }
    }
}



Measured memory_bytes: 4944
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)

s=input()
ans=[]
for i in range(len(s)):
    if(s[i]=="B" and len(ans)>0):
        ans.pop()
    if(s[i]!="B"):
        ans.append(s[i])
print("".join(ans))






Measured memory_bytes: 5120