akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

    int a = sc.nextInt();
    
    int b = sc.nextInt();

    if ( a%2==0 || b%2==0 ){

       System.out.println("Even");

  }
    else{

       System.out.println("Odd");
  }


  }
 }

Measured memory_bytes: 21588
//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define ld long double
#define F first
#define y1 LOL
#define ld long double
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll INF = (ll)1e18 + 123;
const int inf=(int)2e9 + 123; 
const int mod=1e9+7;
using namespace std;
int n, A, B, d[21][21], f[111][111];
int main(){
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  	srand(FOR);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> A >> B;
	for(int i = 1; i <= A; i ++){
		for(int j = 1; j <= B; j ++){
			cin >> d[i][j];
		}
	}
	int n = 1;
	for(int i = 0; i <= 100; i ++){
		for(int j = 0; j <= 100; j ++){
			for(int a = 1; a <= A; a ++){
				for(int b = 1; b <= B; b ++){
					f[i][j] = max(f[i][j], d[a][b] - a * i - b * j);
				}
			}
		}
	}
	for(int a = 1; a <= A; a ++){
		for(int b = 1; b <= B; b ++){
			int res = inf;
			for(int i = 0; i <= 100; i ++){
				for(int j = 0; j <= 100; j ++){
					res = min(res, f[i][j] + a * i + b * j);
				}
			}
			if(res != d[a][b]){
				cout << "Impossible";
				return 0;
			}
		}
	}
	cout << "Possible\n";
	int s = 1, t = 202;
	cout << t << " " << 101 * 101 + 200 << endl;
	for(int i = 2; i <= 101; i ++){
		cout << i - 1 << " " << i << " X\n";
	}
	for(int i = 103; i <= t; i ++){
		cout << i - 1 << " " << i << " Y\n";
	}
	for(int i = 0; i <= 100; i ++){
		for(int j = 0; j <= 100; j ++){
			cout << i + 1 << " " << t - j << " " << f[i][j] << endl;
		}
	}
	cout << s << " " << t;
	return 0;
}                     

Measured memory_bytes: 384
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
-- import Data.Array
import Data.Array.Unboxed

import Control.Monad.ST
import Data.Array.ST
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.Vector.Mutable as VM

import Data.Array.IO
import Data.Array.ST

import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
readInt = fst . fromJust . B.readInt
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
read2dInts = map (map (fst . fromJust . B.readInt) . B.words) . B.lines <$> B.getContents

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- readInts
  countingSort''' (0, 10000) as

countingSort''' :: (Int, Int) -> [Int] -> IO ()
countingSort''' (s,e) as = do
      arr <- newArray (s,e) 0 :: IO (IOUArray Int Int)
      forM_ as (\a -> do
        val <- readArray arr a
        writeArray arr a (val + 1) 
        )
      ass <- getAssocs arr
      putStrLn . unwords . map show $ concatMap (\(i, n) -> replicate n i) ass



Measured memory_bytes: 23032
#include<bits/stdc++.h>
const int MN=1000+5;
using namespace std;
typedef long long ll;
template<typename T>inline T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n,m;
char c[MN][MN],a[MN][MN],b[MN][MN];
void input(){
	IN(n),IN(m);
	for(int i=1;i<=n;++i){
		a[i][1]=b[i][m]='#';
		a[i][m]=b[i][1]='.';
		scanf("%s",c[i]+1);
		for(int j=2;j<m;++j){
			a[i][j]=b[i][j]=c[i][j];
			if(i%2)a[i][j]='#';
			else b[i][j]='#';
		}
	}
	for(int i=1;i<=n;++i,puts(""))for(int j=1;j<=m;++j)printf("%c",a[i][j]);
	puts("");
	for(int i=1;i<=n;++i,puts(""))for(int j=1;j<=m;++j)printf("%c",b[i][j]);
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 2176
from heapq import heappush, heappop


def main():
    W, H = map(int, input().split())
    h = []
    for _ in range(W):
        p = int(input())
        heappush(h, (p, 0))
    for _ in range(H):
        q = int(input())
        heappush(h, (q, 1))
    ans = 0
    while len(h):
        v, d = heappop(h)
        if d == 0:
            ans += v * (H+1)
            W -= 1
        else:
            ans += v * (W+1)
            H -= 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 79448
a = input().split()
k = int(a[0])
s = int(a[1])

count = 0

for x in range(k + 1):
    if x > s:
        break
    for y in range(k + 1):
        if x + y > s:
            break
        else:
            if (k + 1) > (s - x - y):
                # print(x, y, (s - x - y))
                count = count + 1

print(count)


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

typedef long long ll;

int main() {
	int n;
	cin >> n;
	int k = 8;
	for (int i=600; i<=2000; i+=200) {
		if (n<i) {
			break;
		}
		k--;
	}
	cout << k << '\n';
	
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>

int main() {
    while (true) {
        int h, w;
        std::cin >> h >> w;
        if (h == 0 && w == 0) {
            return 0;
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if ((i+j)%2 == 0) {
                    std::cout << '#';
                } else {
                    std::cout << '.';
                }
            }
            std::cout << std::endl;
        }
        std::cout << std::endl;
    }
    return 0;
}



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

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	char s[n][11];
	for(int i=0;i<n;i++){
		scanf("%s",s[i]);
	}
	map<vector<int>,int> check;
	long long int ans=0ll;
	for(int i=0;i<n;i++){
		vector<int> freq(26,0);
		for(int j=0;j<10;j++){
			freq[s[i][j]-'a']++;
		}
		ans+=(0ll+check[freq]);
		check[freq]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 22144
K, N = map(int, input().split())
A=sorted(map(int, input().split()))

maxD=0

for i in range(N-1):
  if (A[i+1]-A[i])>=maxD:
    maxD=(A[i+1]-A[i])
if (A[0]+K-A[N-1])>=maxD:
  maxD=(A[0]+K-A[N-1])

print(K-maxD)

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

int main() {
  int input;
  cin >>input;
 
  int num=input % 10;
  string str;

  if(num == 3){
    str = "bon";
  }else if(num == 0 || num == 1 ||num == 6||num == 8){
    str = "pon";
  }else{
    str = "hon";
  }
  cout << str<< endl;

  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
	cin>>a;
	cin>>b;
	if(a.size()>10) 
	{
		printf("No\n");
		return 0;
	}
	for(int i=0;i<26;++i)
	{
		string c=a+(char)(i+'a');
		if(c==b)
		{
			 printf("Yes\n");
			 return 0;
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 3628
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char rbuf[2800014];
char wbuf[699997];
int rbufl, wbufl;

#define getchar_unlocked() rbuf[rbufl++]
#define putchar_unlocked(c) wbuf[wbufl++]=(c)

uint32_t nextpint(void){ char c=getchar_unlocked(); uint32_t x=0; while('0'<=c){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
void printpint(int32_t x){ if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }

int edge[200000][2];

int qmem[400000];

int *e[100001];
int el[100001];

int prev[100001];

int s[100000];
int sl, sr;

int main(void){
	read(STDIN_FILENO, rbuf, sizeof(rbuf));
	int n=nextpint();
	int m=nextpint();
	for(int i=0; i<m; i++){
		int A=nextpint();
		int B=nextpint();
		edge[i][0]=A;
		edge[i][1]=B;
		el[A]++;
		el[B]++;
	}
	int ne=0;
	for(int i=1; i<=n; i++){
		e[i]=&qmem[ne];
		ne+=el[i];
		el[i]=0;
	}
	for(int i=0; i<m; i++){
		int A=edge[i][0];
		int B=edge[i][1];
		e[A][el[A]++]=B;
		e[B][el[B]++]=A;
	}
	int k=0;
	prev[1]=1;
	s[sr++]=1;
	while(sl<sr){
		k++;
		int from = s[sl++];
		for(int i=0; i<el[from]; i++){
			int to = e[from][i];
			if(prev[to]==0){
				prev[to]=from;
				s[sr++]=to;
			}
		}
	}
	if(k==n){
		putchar_unlocked('Y');
		putchar_unlocked('e');
		putchar_unlocked('s');
		putchar_unlocked('\n');
		for(int i=2; i<=n; i++){
			printpint(prev[i]);
		}
		write(STDOUT_FILENO, wbuf, wbufl);
	}else{
		puts("No");
	}
}


Measured memory_bytes: 9248
import sys
from fractions import gcd


scan = sys.stdin.readline


def lcm(x, y):
  return (x * y) // gcd(x, y)


def main():
  a, b, c, d = map(int, scan().rstrip().split())
  
  # swap
  if c > d:
    _ = c
    c = d
    d = _
  
  cd_mul_to_a = -((a-1) // lcm(c, d))
  cd_mul_to_b = -(b // lcm(c, d))
  
  cd_mul_to_a += (a-1) // c
  cd_mul_to_b += b // c
  
  cd_mul_to_a += (a-1) // d
  cd_mul_to_b += b // d
  
  total = (b - a + 1) - (cd_mul_to_b - cd_mul_to_a)
  
  print(total)


main()




Measured memory_bytes: 5048
import Control.Monad
import Control.Applicative ((<$>))
import Data.Vector.Unboxed ((//), generate, minIndex, (!))
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.List as L
import Debug.Trace (trace)


type AdjM = V.Vector (VU.Vector Int)
type Costs = VU.Vector Int
type Verified = VU.Vector Bool


main :: IO ()
main = do
    n    <- readLn :: IO Int
    adjm <- V.replicateM n $ adj n . toCs [] . map read . drop 2 . words <$> getLine :: IO AdjM
    let vs = VU.replicate n False                :: Verified
        ws = VU.cons 0 (VU.replicate (n - 1) (n * 100001)) :: Costs
        cs = snd $ dijkstra n adjm (vs, ws)
    VU.forM_ (generate n id) $ \i -> do
        putStrLn $ show i ++ " " ++ show (cs ! i)
  where
    adj n cs = (VU.replicate n (n * 100001)) // cs
    toCs accum []         = accum
    toCs accum (a:b:rest) = toCs ((a, b) : accum) rest


dijkstra :: Int -> AdjM -> (Verified, Costs) -> (Verified, Costs)
dijkstra n adjm (vs, cs)
    | VU.all id vs = (vs, cs)
    | otherwise    = dijkstra n adjm (vs', cs')
  where
    vs' = vs // [(mi, True)]
    mi  = (\(i,_,_) -> i) . VU.foldl' f (-1, False, n * 100001) $ VU.zip3 (generate n id) vs cs
      where
        f (ai, av, ac) (i, v, c)
            | v == False && c < ac = (i, v, c)
            | otherwise            = (ai, av, ac)

    cs' = cs // updatelist
    updatelist = VU.foldl' g [] $ VU.zip3 (generate n id) cs (adjm V.! mi)
    mc  = cs ! mi
    g accum (i, a, b)
        | a > mc + b = (i, mc + b) : accum
        | otherwise  = accum



Measured memory_bytes: 7780
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(x...) {                                       \
   cerr << "\e[91m";                                        \
   cerr << __LINE__ << ": " << #x << " = "; DBG::_print(x); \
   cerr <<"\e[39m";                                         \
}
#else
#define DEBUG(x...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int MOD = 1e9 + 7;

#define MAXN 2000004
int F[MAXN+4];
int inv[MAXN+4]; 
int invF[MAXN+4];
void build_factorial_tables() {
   F[0] = 1;
   for (int i = 1; i <= MAXN; ++i)
      F[i] = (F[i-1] * 1LL * i) % MOD;

   inv[0]  = inv[1] = 1;
   invF[0] = invF[1] = 1;
   for (int i = 2; i <= MAXN; ++i) {
      inv[i] = (MOD - (MOD / i) * 1LL * inv[MOD % i] % MOD) % MOD;
      invF[i] = (invF[i-1] * 1LL * inv[i]) % MOD;
   }
}

int nCk(int n, int k) {
   if (n < 0 || k < 0 || k > n)  // invalid n or k
      return 0;
   long long res = F[n];
   res = (res * invF[k]) % MOD;
   res = (res * invF[n-k]) % MOD;
   return res;
}

int P25[MAXN+4];
int P26[MAXN+4];

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

   build_factorial_tables();   

   P25[0] = 1;
   FOR(n, 1, MAXN)
      P25[n] = (P25[n-1] * 25LL) % MOD;

   P26[0] = 1;
   FOR(n, 1, MAXN)
      P26[n] = (P26[n-1] * 26LL) % MOD;

   int K;
   cin >> K;

   string S;
   cin >> S;

   int N = SZ(S);

   llong res = 0;
   FOR(lg, 0, K) {
      llong ways = nCk(K - lg + N - 1, N - 1);
      ways = (ways * P25[K - lg]) % MOD;
      ways = (ways * P26[lg]) % MOD;
   // DEBUG(lg, ways);
      res += ways;
      if (res >= MOD)
         res -= MOD;
   }

   cout << res << endl;

   return 0;
}


Measured memory_bytes: 43332
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String arg[]){
		Scanner sc = new Scanner(System.in);
		String nf;
		nf = sc.nextLine();
		
		String[] A = nf.split(" ");
		int[] n = new int[A.length];
		int st = 0;

		for (int i=0; i<A.length; i++) {
			if(A[i].equals("+")){
				st--;
				n[st-1] = n[st-1] + n[st];
			} else if (A[i].equals("-")){
				st--;
				n[st-1] = n[st-1] - n[st];
			} else if (A[i].equals("*")){
				st--;
				n[st-1] = n[st-1] * n[st];
			} else {
				n[st] = Integer.parseInt(A[i]);
				st++;
			}
		}
		System.out.println(n[st-1]);
	}
}


Measured memory_bytes: 26012
K, S = map(int, input().split())
count = 0

for x in range(K + 1):
    if x > S:
        break
    for y in range(K + 1):
        z = S - (x + y)
        if z < 0:
            break
        if 0 <= z and z <= K:
            count += 1

print(count)


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

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i = 0; i < n; i++)
#define for1(i,n) for(int i = 1; i <= n; i++)
#define ford(i,n) for(int i = n-1; i >= 0; i--)
#define fore(i,a,b) for(int i = a; i <= b; i++)

using namespace std;

typedef long long ll;
typedef double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

const ld pi = acos(-1);

const  int MAXn= 3e5+5;
const  long long INF= 1e18;
const long long mod= 1e9+7;


int main(){
       ld a, b, x;
       cin >> a >> b >> x;
       ld ans;
       if(a * a * b  < x*2 ){
		   ans = atan(2 * (a * a * b - x) / (a * a * a));
	   }
	   
	   else{
		   ans = (pi/(ld)2.0) - atan(2 * x / (a * b * b));
	   }
	   cout << fixed << setprecision(20) << ans * ((ld)180.0/pi) ;
     }
       
       
       
       
       
       
       
       
       
       
       
       
       
        
    


Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑



int main() {
	long long a, b, c, d, e, mon;
	cin >> a >> b >> c >> d >> e;
	mon = min(e * 4 * a, min(e * 2 * b, e*c));
	cout << min(e / 2 * d + e % 2 * mon / e, mon) << endl;
}

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

int main() {
    ll x, y;
    cin >> x >> y;
    int ans = 0;
    
    while(x <= y) {
        y >>= 1;
        ans++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int A, B;
	int a,b,c;
	scanf("%d%d", &A, &B);

	a = A + B;
	b = A - B;
	c = A * B;

	if (a >= b && a >= c) {
		printf("%d", a);
	}
	else if (b >= a && b >= c) {
		printf("%d", b);
	}
	else {
		printf("%d", c);
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans=0;
    for(int i=0; i*r<=n; i++){
        for(int j=0; j*g<=n; j++){
            int a=n-i*r-j*g;
            if(a>=0 && a%b==0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	string s = "";
	while (n) {
		int num = 0;
		num = n % 2;
		if (num < 0) {
			num += 2;
		}
		s += char(num + '0');
		n = (n - num) / (-2);
	}
	reverse(s.begin(), s.end());
	if (s == "") cout << 0 << endl;
	else cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
s = input()

if c < d:
    if s[a-1:c].find('##')==-1 and s[b-1:d].find('##')==-1:
        print('Yes')
    else:
        print('No')
else:
    if s[a-1:c].find('##')==-1 and s[b-1:d].find('##')==-1 and s[b-2:d+1].find('...')!=-1:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[500005];
char s[100005];
int main()
{
    scanf("%s",s);
    int len=strlen(s);
    int l=200005,r=200005+len-1;
    for(int i=0;i<len;i++)
    {
        a[l+i]=s[i];
    }
    bool f=0;
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int x;
        scanf("%d",&x);
        if(x==1)
        {
            f^=1;
        }
        else
        {
            int y;
            char p[2];
            scanf("%d%s",&y,p);
            if(y==1)
            {
                if(f==0)
                {
                    a[--l]=p[0];
                }
                else a[++r]=p[0];
            }
            else
            {
                if(f)
                {
                    a[--l]=p[0];
                }
                else a[++r]=p[0];
            }
        }
    }
    if(f==0)
    {
        for(int i=l;i<=r;i++)printf("%c",a[i]);
        printf("\n");
    }
    else
    {
        for(int i=r;i>=l;i--)printf("%c",a[i]);
        printf("\n");
    }
}


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

template <typename _Tp> inline _Tp read(_Tp&x){
	char c11=getchar(),ob=0;x=0;
	while(c11^'-'&&!isdigit(c11))c11=getchar();if(c11=='-')ob=1,c11=getchar();
	while(isdigit(c11))x=x*10+c11-'0',c11=getchar();if(ob)x=-x;return x;
}

const int N=101000;
struct Edge{int v,nxt;}a[N];
int head[N],n,k,_,ans;

int dfs(int x){
	int res=1,t;
	for(int i=head[x];i;i=a[i].nxt){
		t=dfs(a[i].v);
		if(t>=k&&x!=1)++ans,t=-1;
		res=max(res,t+1);
	}
	return res;
}

int main(){
	read(n),read(k);
	int x;read(x);if(x!=1)++ans;
	for(int i=2;i<=n;++i)
		read(x),a[++_].v=i,a[_].nxt=head[x],head[x]=_;
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  bool is_ok = false;
  if (A == B && B != C)
    is_ok = true;
  if (B == C && C != A)
    is_ok = true;
  if (C == A && A != B)
    is_ok = true;

  if (is_ok)
  {
    printYes();
  }
  else
  {
    printNo();
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int a[N];

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   a[1] = 300000;
   a[2] = 200000;
   a[3] = 100000;
   int x,y;
   cin >> x >> y;
   int ans = a[x]+a[y];
   if(x==1 and y==1){
      ans += 2*a[2];
   }
   cout << ans << '\n';
   return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N;
    cin >> N;
    if (N%10 == 2 || N%10 == 4 || N%10 == 5 || N%10 == 7 || N%10 == 9)
    {
        cout << "hon";
    }else if (N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8)
    {
        cout << "pon";
    }else if (N%10 == 3)
    {
        cout << "bon";
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const int INF = 100000000;

int main()
{
    int n, m;
    int a[100];
    cin >> n >> m;
    ll total = 0;
    rep(i, n) {
        cin >> a[i];
        total += a[i];
    }
    double kizyun = total / (4.0 * m);

    int count = 0;
    rep(i, n) {
        if (a[i] >= kizyun) count++;
    }
    if (count >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<math.h>
#include<complex>
#include<iomanip>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
double dis(double x1,double x2,double y1,double y2){
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
	double x[3],y[3];
	lol(i,3)cin>>x[i]>>y[i];
	lol(i,2)x[i]-=x[2],y[i]-=y[2];x[2]=0,y[2]=0;
	double a=dis(x[0],x[1],y[0],y[1]);
	double b=dis(x[0],x[2],y[0],y[2]);
	double c=dis(x[1],x[2],y[1],y[2]);
	double w=max(a,max(b,c))*0.5;
	double h=abs(x[0]*y[1]-x[1]*y[0])/(a+b+c);
	double r=h*w/(h+w);
	cout<<fixed<<setprecision(10)<<r<<endl;
	return 0;
}


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

using i64 = int64_t;

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i=0;i<n;++i){
        int h;
        cin >> h;
        if(h >= k)ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  VV<> g(n);
  V<> deg(n);
  for (int _ = 0; _ < n - 1; ++_) {
    int u, v; cin >> u >> v, --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
    ++deg[u], ++deg[v];
  }
  cout << count_if(begin(deg), end(deg), [](int x) { return x & 1; }) / 2 << ' ';
  auto chk = [&](int x) -> bool {
    V<> dp(n, 1e9);
    auto dfs = [&](const auto& dfs, int v, int p) -> void {
      V<> a;
      for (int w : g[v]) if (w != p) {
        dfs(dfs, w, v);
        a.push_back(dp[w] + 1);
      }
      if (~a.size() & 1) a.push_back(0);
      sort(begin(a), end(a));
      int m = a.size(), ng = -1, ok = m;
      while (ok - ng > 1) {
        int mid = ng + ok >> 1;
        V<> b;
        for (int i = 0; i < m; ++i) if (i != mid) {
          b.push_back(a[i]);
        }
        int mx = 0;
        for (int i = 0; i < m / 2; ++i) {
          mx = max(mx, b[i] + b[b.size() + ~i]);
        }
        (mx <= x ? ok : ng) = mid;
      }
      if (ok == m) return;
      dp[v] = a[ok];
    };
    int r = -1;
    for (int v = 0; v < n; ++v) if (deg[v] == 1) {
      r = v;
      break;
    }
    dfs(dfs, r, -1);
    return dp[r] <= x;
  };
  int ng = 0, ok = n - 1;
  while (ok - ng > 1) {
    int mid = ng + ok >> 1;
    (chk(mid) ? ok : ng) = mid;
  }
  cout << ok << '\n';
}

Measured memory_bytes: 18176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// input
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		int[] pre = new int[n];
		String[] str = br.readLine().split(" ");
		for(int i = 0; i < n; ++i) {
			 pre[i] = Integer.parseInt(str[i]);
		}
		
		int[] in = new int[n];
		str = br.readLine().split(" ");
		for(int i = 0; i < n; ++i) {
			 in[i] = Integer.parseInt(str[i]);
		}

		// make post and print
		System.out.println(post(pre, in));
	}
	public static String post(int[] pre, int[] in) {
		// search centre
		int i = 0;
		int n = pre.length;
		while(pre[0] != in[i]){
			i += 1;
		}
		
		String str = "";
		
		// left
		// num of left element = i
		if(i == 0){
		}else if(i == 1){
			if(str != "") {
				str += " ";
			}
			str += String.valueOf(in[0]);
		}else{
			if(str != "") {
				str += " ";
			}
			str += post(Arrays.copyOfRange(pre, 1, i + 1), Arrays.copyOfRange(in, 0, i));
		}
		
		// right
		int nr = n - 1 - i;// num of right element == 1
		if(nr == 0){
		}else if(nr == 1){ 
			if(str != "") {
				str += " ";
			}
			str += String.valueOf(in[n - 1]);
		}else{
			if(str != "") {
				str += " ";
			}
			str += post(Arrays.copyOfRange(pre, 1 + i, pre.length), Arrays.copyOfRange(in, i + 1, pre.length));
		}
		
		// centre
		if(str != "") {
			str += " ";
		}
		str += String.valueOf(in[i]); // or pre[0]
		
		return str;
	}
}

Measured memory_bytes: 24408
N = int(input())
A = list(map(int,input().split()))
B = [-10000 for i in range(N)]
for i in range(N):
    if (N-i)%2 != 0:#from front
        index = (N-i)//2
        B[index] = A[i]
    else:# from backward
        index = N - (N-i)//2
        B[index] = A[i]
ans = ''
for e in B:
    ans += str(e)+' '
print(ans[:-1])

Measured memory_bytes: 26180
N, K = map(int, input().split())
MOD = 10**9 + 7

dp = [0] * (K + 1)
ans = 0
for k in range(K, 0, -1):
    num = K // k
    dp[k] = pow(num, N, MOD)
    for n in range(2, num+1):
        if n*k <= K:
            dp[k] -= dp[n*k]
            dp[k] %= MOD

    ans += dp[k] * k % MOD
    ans %= MOD

print(ans)

Measured memory_bytes: 69116
#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

class PRO{
public:
  int num;
  int cnt;
  bool first;
  bool second;
  void init(){num = 0; cnt = 0; first = second = false;}
};

bool cmp(PRO lhs, PRO rhs)
{
  return (lhs.num < rhs.num);
}

signed main()
{
  ios::sync_with_stdio(false);
  vector<PRO> pro;
  string s;

  while (getline(cin, s), !s.empty()){
    stringstream ss(s);
    int num, day;
    char c;
    ss >> num >> c >> day;
    bool first = true;
    REP(i, pro.size()){
      if (pro[i].num == num){
        pro[i].cnt++;
        pro[i].first = true;
        first = false;
      }
    }
    if (first){
      pro.pb((PRO){num, 1, true, false});
    }
  }

  while (getline(cin, s), !s.empty()){
    stringstream ss(s);
    int num, day;
    char c;
    ss >> num >> c >> day;
    bool first = true;
    REP(i, pro.size()){
      if (pro[i].num == num){
        pro[i].cnt++;
        pro[i].second = true;
        first = false;
      }
    }
    if (first){
      pro.pb((PRO){num, 1, false, true});
    }
  }

  sort(pro.begin(), pro.end(), cmp);
  REP(i, pro.size()){
    if (pro[i].cnt >= 2 && pro[i].first && pro[i].second){
      cout << pro[i].num << " " << pro[i].cnt << '\n';
    }
    //cout << pro[i].num << " " << pro[i].cnt << " " << pro[i].first << " " << pro[i].second << endl;
  }

  return (0);
}

Measured memory_bytes: 1244
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s=scan.nextLine();
		String t=scan.nextLine();
		int c=0;
		for(int i=0;i<3;i++)
		{
			if(s.charAt(i)==t.charAt(i)) c++;
		}
		System.out.println(c);
	}

}


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

using namespace std;
typedef long long LL;
static LL INF = (1LL<<62);

const int MAX = 100004;
int PARENT[MAX] = {0};
int RANK[MAX] = {0};
int CHLDS[MAX] = {0};

void init(int L){
	if(L<1) return;
	for(int i=0; i<L; i++){
		PARENT[i]=i; RANK[i]=0; CHLDS[i] = 1;
	}
}

int root(int x){
	if(x<0) return -1;
	if(PARENT[x]==x){
		return x;
	}
	else{
		int p = root(PARENT[x]);
		if(p != PARENT[x]){
			if(CHLDS[x] != 0){
				CHLDS[p] += CHLDS[x];
				CHLDS[x] = 0;
			}
			PARENT[x] = p;
		}
		return PARENT[x];
	}
}

int same(int x, int y){
	if(x==y) return 1;
	if(root(x)==root(y)){
		return 1;
	}
	else{
		return 0;
	}
}

void combine(int x, int y){
	if(x==y) return;
  
	int a = root(x);
	int b = root(y);
	if(a==b) return;
  
	if(RANK[x]<RANK[y]){
		PARENT[b] = a;
		CHLDS[a] += CHLDS[b]; CHLDS[b] = 0;
	}
	else{
		PARENT[a] = b;
		if(RANK[x]==RANK[y]) RANK[x] += RANK[y];
		CHLDS[b] += CHLDS[a]; CHLDS[a] = 0;
	}
}

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

	LL N, M; cin >> N >> M;
	vector<pair<int, int>> V;
	for(int i=0; i<M; i++){
		int a, b; cin >> a >> b; a--; b--;
		V.push_back(make_pair(a, b));
	}

	init(N);
	vector<LL> A;
	LL w = (N*(N-1))/2;
	A.push_back(w); 
	for(int i=V.size()-1; i>=0; i--){
		LL tmp = A[A.size()-1];
		auto br = V[i];
		int x = br.first;
		int y = br.second;
		int rx = root(x);
		int ry = root(y);
		LL ca = CHLDS[rx];
		LL cb = CHLDS[ry];
		if(same(rx, ry) != 1){
			tmp -= (ca*cb);
		}
		if(i > 0){
			A.push_back(tmp);
		}
		combine(x, y);
	}
	for(int i=A.size()-1; i>=0; i--) printf("%lld\n", A[i]);
	return 0;
}

Measured memory_bytes: 7008
#include <vector>
#include <iostream>
#include <algorithm>
#define INF (1LL << 60)
using namespace std;
int n, u[2], mode, tar; long long d, x[30], y[30], ret, seg[16777216], val[8388608]; pair<long long, long long> t[2][8388608];
inline void rec(int pos, long long a, long long b) {
	if (pos == tar) {
		if(b <= 0) t[mode][u[mode]++] = make_pair(a, b);
		return;
	}
	rec(pos + 1, a + x[pos], b + y[pos]);
	rec(pos + 1, a - x[pos], b - y[pos]);
	rec(pos + 1, a, b);
}
inline long long query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l) return INF;
	if (a <= l && r <= b) return seg[k];
	long long lch = query(a, b, k << 1, l, (l + r) >> 1);
	long long rch = query(a, b, (k << 1) + 1, (l + r) >> 1, r);
	return min(lch, rch);
}
int main() {
	scanf("%d%lld", &n, &d);
	for (int i = 0; i < n; i++) scanf("%lld%lld", &x[i], &y[i]);
	mode = 0; tar = n / 2; rec(0, 0, 0);
	mode = 1; tar = n; rec(n / 2, 0, 0);
	sort(t[1], t[1] + u[1]);
	for (int i = 0; i < u[1]; i++) val[i] = t[1][i].first;
	for (int i = 0; i < u[1]; i++) seg[i + 8388608] = t[1][i].second;
	for (int i = u[1]; i < 8388608; i++) seg[i + 8388608] = INF;
	for (int i = 8388608; i >= 1; i--) seg[i] = min(seg[2 * i], seg[2 * i + 1]);
	for (int i = 0; i < u[0]; i++) {
		int pl = lower_bound(val, val + u[1], -t[0][i].first - d) - val;
		int pr = upper_bound(val, val + u[1], -t[0][i].first + d) - val;
		long long res = query(pl, pr, 1, 0, 8388608);
		ret = max(ret, -t[0][i].second - res);
	}
	printf("%lld\n", ret);
	return 0;
}

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


ll lcd(ll a, ll b) {
  if (a < b) {
    swap(a, b);
  }
  if (b == 0) {
    return a;
  }
  return lcd(b, a % b);
}

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  ll max_v = 0, min_v = pow(10, 9) + 1;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    max_v = max(max_v, A[i]);
    min_v = min(min_v, A[i]);
  }
  if (max_v < K) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    if (A.size() == 1) {
      if (A[0] == K) {
        cout << "POSSIBLE";
      } else {
        cout << "IMPOSSIBLE";
      }
    } else {
      ll div;
    for (int i = 1; i < A.size(); ++i) {
      if (i == 1) {
        div = lcd(A[i - 1], A[i]);
      } else {
        div = lcd(A[i], div);
      }
    }
    if (K % div == 0) {
      cout << "POSSIBLE" << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
    }
  }
}

Measured memory_bytes: 1024
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;



int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	int n;
	cin>>n;
	while(n--){
		string s,t;
		cin>>s>>t;
		for(int i=sz(s)-1;i>=0;i--){
			if(s[i]=='C'){
				t = t.substr(1) + t.substr(0,1);
			}
			if(s[i]=='J'){
				t = t.substr(sz(t)-1) + t.substr(0,sz(t)-1);
			}
			if(s[i]=='E'){
				if(sz(t)%2==0){
					t = t.substr(sz(t)/2) + t.substr(0,sz(t)/2);
				}else{
					t = t.substr(sz(t)/2+1) + t.substr(sz(t)/2,1) + t.substr(0,sz(t)/2);
				}
			}
			if(s[i]=='A'){
				reverse(t.begin(),t.end());
			}
			if(s[i]=='M'){
				rep(j,sz(t)){
					if(t[j]=='9')t[j]='0';
					else if(isdigit(t[j]))t[j]++;
				}
			}
			if(s[i]=='P'){
				rep(j,sz(t)){
					if(t[j]=='0')t[j]='9';
					else if(isdigit(t[j]))t[j]--;
				}
			}
			
		}
		cout<<t<<endl;
	}
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct node{
    int pc,g,l,r;
    node(int a,int b,int c,int d):pc(a),g(b),l(c),r(d){}
    node(){pc=g=l=r=-1;}
};
node e;
inline node add(const node &a,const node &b){
    if(a.pc==-1)return b;
    if(b.pc==-1)return a;
    node c;
    c.pc=a.pc+b.pc;
    c.g=a.g+b.g+a.r*b.l;
    c.l=a.l;
    c.r=b.r;
    return c;
}

struct segtree{
    static const int SEG=1<<17;
    vector<node>dat;
    vector<int>put;
    segtree(string &s):dat(SEG*2),put(SEG*2,-1){
        for(int i=0;i<s.size();i++){
            node d;
            int a=s[i]-'0';
            d.pc=a;
            d.g=0;
            d.l=d.r=a;
            dat[i+SEG-1]=d;
        }
        for(int i=SEG-2;i>=0;i--){
            dat[i]=add(dat[i*2+1],dat[i*2+2]);
        }
    }
    inline void push(int k,int l,int r){
        if(put[k]==-1)return;
        dat[k].pc=(r-l)*put[k];
        dat[k].g=(r-l-1)*put[k];
        dat[k].l=dat[k].r=put[k];

        if(k<SEG-1){
            put[k*2+1]=put[k*2+2]=put[k];
        }
        put[k]=-1;
    }
    void update(int a,int b,int x,int k=0,int l=0,int r=SEG){
        push(k,l,r);
        if(r<=a||b<=l)return;
        if(a<=l&&r<=b){
            put[k]=x;
            push(k,l,r);
            return;
        }
        update(a,b,x,k*2+1,l,(l+r)/2);
        update(a,b,x,k*2+2,(l+r)/2,r);
        dat[k]=add(dat[k*2+1],dat[k*2+2]);
    }
    node query(int a,int b,int k=0,int l=0,int r=SEG){
        push(k,l,r);
        if(r<=a||b<=l)return e;
        if(a<=l&&r<=b)return dat[k];
        return add(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
};

signed main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int N;
    string S;
    cin>>N>>S;
    segtree seg(S);

     int Q;cin>>Q;
     while(Q--){
        int l,r,b;
        cin>>l>>r>>b;
        l--;
        seg.update(l,r,b);
        node d=seg.query(0,N);
        cout<<d.pc-d.g<<endl;
     }
    return 0;
}

Measured memory_bytes: 13476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll N,M;
  cin>>N>>M;
  if(N>=1&&N<=9&&M>=1&&M<=9)
    cout<<N*M<<"\n";
  else
    cout<<-1<<"\n";
  return 0;
}

Measured memory_bytes: 256
/*
 * 
 * */

#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << ":\t" << x << endl
#define _ << " " <<

#define s_time clock_t time_start = clock()
#define t_time cout << double(clock() - time_start) / 1000 << endl

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int N = 1e5 + 3;
const ll M = 1e9 + 7;

int n;
vector<int> g[N];
ll dp[N][2];

void dfs(int v, int pr = -1) {
	dp[v][0] = dp[v][1] = 1;
	for (auto& u: g[v]) {
		if (u != pr) {
			dfs(u, v);
			dp[v][0] = (dp[v][0] * (dp[u][0] + dp[u][1]) % M) % M;
			dp[v][1] = dp[v][1] * dp[u][0] % M;
		}
	}
}

int main(int argc, char** argv) {
//	mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> n;
	while (--n) {
		int x, y; cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}
	
	dfs(1);
	cout << (dp[1][0] + dp[1][1]) % M;
	
	return 0;
}

/*
 * 
 * */


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
int n,a[100005],cnt1,cnt2,cur;
int main()
{
    cin >>n;
    for (int i=0;i<n;i++)
        cin >>a[i];
    sort(a,a+n);
    for (int i=n-1;i>=0;i--)
    {
        if (!cur)
            cnt1+=a[i];
        else
            cnt2+=a[i];
        cur++;
        cur%=2;
    }
    cout <<cnt1-cnt2;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] heishts = new int[n];
		for (int i = 0; i < n; i++) {
		    heishts[i] = sc.nextInt();
		}
		long total = 0;
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = n - 1; i > 0; i--) {
		    int x = i + 1 - heishts[i];
		    if (map.containsKey(x)) {
		        map.put(x, map.get(x) + 1);
		    } else {
		        map.put(x, 1);
		    }
		    int y = heishts[i - 1] + i;
		    if (map.containsKey(y)) {
		        total += map.get(y);
		    }
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 67392
using System;
using System.Collections.Generic;
using System.Linq;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var d = Console.ReadLine().Split().Select(i => int.Parse(i)).OrderBy(i => i).ToList();

            var idx = (n / 2) - 1;
            var x = d[idx] + 1;
            var y = d[idx + 1];
            var count = 0;
            while(x <= y){
                count++;
                x++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 21728
#include <bits/stdc++.h>
using namespace std;
struct node {
	int kind;
	int pos, sz, u, v;
	node *l, *r;
};
string s;
node* build(int x, int y){
	node* ans = new node();
	if(s[x] == '_' || s[x] == '^'){
		int l = x + 2, r = y;
		while(s[r] != ')') r--; r--;
		int stk = 0, comma = 0;
		for(int i = l; i <= r; i++){
			if(s[i] == '(') stk++;
			else if(s[i] == ')') stk--;
			if(stk == 0 && s[i] == ','){
				comma = i;
				break;
			}
		}
		ans->l = build(l, comma - 1);
		ans->r = build(comma + 1, r);
		if(s[x] == '_') ans->kind = 1;
		else ans->kind = 2;
	} else {
		ans->kind = 3;
		if(x == y){
			ans->pos = x;
			ans->sz = 1;
			ans->u = s[x] - '0';
		} else {
			ans->pos = x;
			ans->sz = 2;
			ans->u = s[x] - '0';
			ans->v = s[x+1] - '0';
		}
	}
	return ans;
}
int main(){
	int q; cin >> q;
	while(q--){
		cin >> s;
		int len = s.size();
		node *root = build(0, len - 2);
		int lo = 0, hi = len - 2, ans = len - 1;
		function<pair<int,int>(node*, int)> chk = [&](node *root, int p){
			pair<int,int> ans, l, r;
			if(root->kind == 3){
				if(p == root->pos){
					ans.first = root->u;
					ans.second = root->u == 0 ? 0 : root->u * 10 + 9;
				} else if(p < root->pos){
					ans.first = 0;
					ans.second = 99;
				} else {
					if(root->sz == 1) ans.first = ans.second = root->u;
					else ans.first = ans.second = root->u * 10 + root->v;
				}
			} else {
				l = chk(root->l, p);
				r = chk(root->r, p);
				if(root->kind == 1){
					ans.first = min(l.first, r.first);
					ans.second = min(l.second, r.second);
				} else {
					ans.first = max(l.first, r.first);
					ans.second = max(l.second, r.second);
				}
			}
			return ans;
		};
		while(lo <= hi){
			int mid = (lo + hi)>>1;
			auto p = chk(root, mid);
			if(p.first == p.second) ans = mid, hi = mid - 1;
			else lo = mid + 1;
		}
		cout << chk(root, ans).first << " " << ans + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <cstdlib>
#include<vector>
#include<string>
#include<cmath>
#include <algorithm>
#include<complex>

using namespace std;
typedef long long LL;


int main() {
	LL N;
	LL x=0, y=0;

	cin >> N;

	y = (N/15) * 200;
	x = N * 800;

	cout << x - y << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 200010;

bool check(int mid, vector<string> &s, int n){
    if(mid == 0) return false;
    vector<string> t(n);
    rep(i, n){
        t[i] += s[i][0];
        int cur = 1;
        rep(j, s[i].size()-1){
            if(cur == mid) break;
            if(s[i][j]=='a' || s[i][j]=='i' || s[i][j]=='u' || s[i][j]=='e' ||s[i][j]=='o'){
                t[i] += s[i][j+1];
                ++cur;
            }
        }
    }
    set<string> S;
    rep(i, n){
        if(S.find(t[i]) != S.end()) return false;
        S.insert(t[i]);
    }
    return true;
}

int main(){
    int n;
    while(scanf("%d", &n) && n){
        vector<string> s(n);
        rep(i, n) cin >> s[i];
        int low = 0, high = 50;
        if(!check(high, s, n)){
            puts("-1");
            continue;
        }
        while(high-low > 1){
            int mid = (high + low) / 2;
            (check(mid, s, n) ? high : low) = mid;
        }
        printf("%d\n", high);
    }
}


Measured memory_bytes: 3312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        vp r, b;
        vector<bool> used(n, false);
        ans = 0;
        rep(i, n){
            cin >> x >> y;
            r.pb(mp(x, y));
        }
        rep(i, n){
            cin >> x >> y;
            b.pb(mp(x, y));
        }
        sort(all(r));
        sort(all(b));
        each(p, b){
            cnt = -1;
            y = -1;
            rep(i, n){
                if(used[i]){
                    continue;
                }else if(r[i].first >= p.first){
                    break;
                }else if(r[i].second >= p.second){
                    continue;
                }
                if(r[i].second >= y){
                    cnt = i;
                    y = r[i].second;
                }
            }
            if(cnt != -1){
                ans++;
                used[cnt] = true;
            }
        }
        print(ans);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(ll (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(ll (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	string s1, s2;
	cin >> s1 >> s2;
	ll ans = 1, prev = 0;
	rep(i, n){
		if(s1[i] == s2[i]){
			ans *= 3-prev;
			ans %= MOD;
			prev = 1;
		}else{
			if(prev == 0) ans *= 6;
			else if(prev == 1) ans *= 2;
			else ans *= 3;
			ans %= MOD;
			prev = 2;
			i++;
		}
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean f = false;
		if(n%10==7){
			f = true;
		}
		if((n/10)%10==7){
			f = true;
		}
		if((n/100)%10==7){
			f = true;
		}
		if(f){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 27092
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  
  int n;
  cin >> n;
  
  int sum = 0, x = 26;
  
  while(1){
    
    if( sum + x + 1 > n ){
      n -= sum;
      break;
    }
    
    sum += x;
    x *= 26;
    
  }
  
  while(1){
    
    int w = x / 26;
    
    cout << (char)( ( n - 1 ) /  w + 'a' );
    
    n = ( n - 1 ) % w + 1;
    
    if( x == 26 ) break;
    
    x /= 26;
    
  }

  cout << endl;
  
  return 0;
}


Measured memory_bytes: 3680