akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N=sc.nextInt();

        if(N%2==1) {
            System.out.println(((N - 1) + (N - 2) * (N - 1)) / 2);
            for (int i = N; i > 0; i--) {
                for (int j = i-1; j > 0; j--) {
                    if (i + j != N) {
                        System.out.println(i + " " + j);
                    }
                }
            }
        }else{
            System.out.println((N - 2)*N / 2);
            for (int i = N; i > 0; i--) {
                for (int j = i-1; j > 0; j--) {
                    if (i + j-1 != N) {
                        System.out.println(i + " " + j);
                    }
                }
            }

        }

    }
}

Measured memory_bytes: 26580
import java.util.*;

public class Main {
		public static void main(String[] args) {
			int i = 0;
			int h_p = 0;
			int h_b = 0;
			int kaisu = 0;
			int max = 0;
			Scanner scanner = new Scanner(System.in);
			int n = scanner.nextInt();
			h_b = scanner.nextInt();
			for (i=1; i<n; i++) {
				h_p = scanner.nextInt();
				if (h_p <= h_b) {
					kaisu++;
					if (i == n - 1) {
						if (kaisu > max) {
							max = kaisu;
						}
					}
				} else {
					if (kaisu > max) {
						max = kaisu;
					}
					kaisu = 0;
				}
				h_b = h_p;
			}
			System.out.println(max);
		}
}

Measured memory_bytes: 48584
#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 n, k, q;
  cin >> n >> k >> q;
  vector<int> p(n,k-q);
  rep(i,q) {
    int a;
    cin >> a;
    a--;
    p[a]++;
  }
  rep(i,n) {
    cout << (p[i] > 0? "Yes":"No") << endl;
  }
  return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
typedef long long ll;
int n;
ll tmp[N];
ll a[N], b[N], c[N], y[N];

inline long long crs(int x1,int x2,int x3){
	return 1ll*(x2-x1)*(y[x3]-y[x1])-1ll*(y[x2]-y[x1])*(x3-x1);
}
int stk[N],top;

long double ans[N];

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	for(int i=0;i<n;i++)scanf("%lld",&b[i]);
	int mx=0;
	for(int i=1;i<n;i++)if(a[i]>=a[mx])mx=i;
	for(int i=0;i<n;i++)tmp[i]=a[i];
	for(int i=0;i<=n;i++)a[i]=tmp[(mx+i)%n];
	for(int i=0;i<n;i++)tmp[i]=b[i];
	for(int i=0;i<=n;i++)b[i]=tmp[(mx+i)%n];
	// for(int i=0;i<=n;i++)cout << a[i] << ":" << b[i] << endl;
	for(int i=2;i<=n;i++)c[i]=2*(c[i-1]+b[i-1])-c[i-2];
	for(int i=0;i<=n;i++)y[i] = a[i]-c[i];
	for(int i=0;i<=n;i++){
		while(top>1&&crs(stk[top-1],stk[top],i)>=0)--top;
		stk[++top]=i;
	}
	ll ans = 0;
	for(int i=1;i<top;i++){
		ll dx = stk[i+1]-stk[i];
		ans += y[stk[i]]*(dx+1) + y[stk[i+1]]*(dx-1);
	}
	for(int i=0;i<n;i++){
		ans+=2*c[i];
	}
	// cout << ans << endl;
	double ret=ans;
	ret/=2.00*n;
	printf("%.12lf\n",ret);
}

Measured memory_bytes: 12268
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    X = Scanner.map_int()
    print(X.index(0) + 1)


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    #     print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10712
#include<bits/stdc++.h>
using namespace std;
const int ms = 2e5+9;
vector<int> jump_pos;
vector<int> g[ms], path;
int n, first_repeated_node, visitooo[ms], solution = 0;
long long int k, cycle_size;

int dfs(int node, int t22 =1){
  path.push_back(node);
  visitooo[node] = t22++;

  for(auto &v : g[node]){
    if(visitooo[v]){
      cycle_size = t22 - visitooo[v];
      return v;
    } else {
      int v2 = dfs(v, t22);
      if(v2 != -1){
        return v2;
        }
    }
  }

  return -1;
}


int solve(){
  int t = 0;
  for(t = 0; t < path.size() and k; t++, k--){
    if(path[t] == first_repeated_node){
      break;
    }
  }
  if(k == 0)
    return path[t];

  k%=cycle_size;


  return path[k + visitooo[first_repeated_node] - 1];
}

int main(){
  cin >> n >> k;
  jump_pos.resize(n+1);

  for(int i = 1; i <= n; i++){
    cin >> jump_pos[i];
    g[i].push_back(jump_pos[i]);
  }

    first_repeated_node = dfs(1);

  cout<<solve()<<endl;

}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

bool eq[105];

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

    int n;
    cin >> n;
    bool ok = false;
    for (int i=0; i<n; i++) {
        int d1, d2;
        cin >> d1 >> d2;
        eq[i] = d1 == d2;
        if (i >= 2)
            ok |= eq[i-2] && eq[i-1] && eq[i];
    }
    cout << (ok ? "Yes" : "No") << "\n";

    return 0;
}


Measured memory_bytes: 3664
import collections

N = int(input())

A = list(map(int, input().split()))

c = collections.Counter(A)
# print(c)
# dic = {}
ans = 0
# for k,v in c.items():
#     dic[k] = int(v*(v-1)/2)
# print(dic)
for v in c.values():
    ans += int(v*(v-1)/2)

for k in range(N):
    Ak = A[k]
    cAk = c[Ak]
    ansk = ans - cAk + 1
    # ans[Ak] = int((cAk-1)*(cAk-2)/2)
    # print(dic,ans)
    print(ansk)

Measured memory_bytes: 26772
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<std::vector<int>> edg(n), id(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; std::cin >> a >> b;
        a--; b--;
        edg[a].push_back(b);
        edg[b].push_back(a);
        id[a].push_back(i);
        id[b].push_back(i);
    }
    std::vector<int> ans(n - 1);
    auto dfs = [&](auto &self, int pos = 0,
        int prev = -1, int prevc = -1) -> void {
        
        int cnt = 1;
        for (int i = 0; i < edg[pos].size(); i++) {
            int c = edg[pos][i];
            if (c == prev) continue;
            if (cnt == prevc) cnt++;
            ans[id[pos][i]] = cnt++;
            self(self, c, pos, ans[id[pos][i]]);
        }
    };
    dfs(dfs);
    std::cout << *std::max_element(ans.begin(), ans.end()) << std::endl;
    for (int i = 0; i < n - 1; i++) std::cout << ans[i] << "\n";
    return 0;
}


Measured memory_bytes: 12032
<?php
while(fscanf(STDIN, "%d", $n)){
    $ans = 100000;
    while($n-- > 0){
        $ans *= 1.05;
        $rem = $ans % 1000;

        if($rem > 0){
            $ans = $ans - $rem + 1000;
        }
    }
    echo $ans . "\n";
}

Measured memory_bytes: 6580
import heapq

N=int(input())
A=list(map(int,input().split()))

R=sorted(A[:N])
SUM1=[sum(A[:N])]
for i in range(N,2*N):
    heapq.heappush(R,A[i])
    tmp=heapq.heappop(R)
    SUM1.append(SUM1[-1]+A[i]-tmp)

B=list(map(lambda x:x*(-1),A[2*N:3*N]))
B.sort()
SUM2=[-sum(B)]
for i in range(2*N-1,N-1,-1):
    heapq.heappush(B,-A[i])
    tmp=heapq.heappop(B)
    SUM2.append(SUM2[-1]+A[i]+tmp)

ans=-float("inf")
for i in range(N+1):
    ans=max(ans,SUM1[i]-SUM2[-(i+1)])
print(ans)

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

ll digit(ll n) {
	ll ret = 0;
	while (n > 0) {
		ret++;
		n /= 10;
	}
	return ret;
}

int main() {
	ll N; cin >> N;
	ll ans = 30;
	for (ll i = 1; i*i <= N; i++) {
		if (N%i == 0) {
			ll A = i, B = N / i;
			ans = min(max(digit(A),digit(B)), ans);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  int s = 0;
  REP(i, n) s += a[i];
  int cnt = 0;
  REP(i, n) if (a[i]*(4*m) >= s) cnt++;
  if (cnt >= m) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )
import Data.List

import qualified Data.Vector.Unboxed as U

cReadLn :: IO Int
cReadLn = fst . fromJust . C.readInt <$> C.getLine

getParms :: IO [Int]
getParms = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [n,k] <- getParms
  as    <- getParms
  print $ f k as

f :: Int -> [Int] -> Int
f k as 
  | k >= l = 0 -- There are enough, no need to rewrite.
  | k <  l = g ns (l-k) 0
  where
    as' = group . sort $ as
    l   = length as' -- # of kinds.
    ns  = sort . map (U.length . U.fromList) $ as' -- A list of # of kinds.

    g :: [Int] -> Int -> Int -> Int
    g _      0 x = x -- Assuming k<=n.
    g (n:ns) k x = g ns (k-1) (x + n)

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

#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++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
const ll INF = 1e15;

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;

  map<ll, ll> mp;
  REP(i, 10) { mp[i] = INF; }
  REP(i, n) {
    ll tmp = s[i] - '0';
    if (mp[tmp] == INF) {
      mp[tmp] = i;
    }
  }
  ll ans = 0;
  REP(i, 10) REP(j, 10) {
    if (mp[i] == INF || mp[j] == INF) continue;

    bool ok = false;
    map<ll, ll> visited;
    FOR(k, mp[i] + 1, n) {
      ll tmp = s[k] - '0';

      if (ok) {
        if (visited[tmp] == 0) {
          visited[tmp]++;
          ans++;
        }
      }

      if (tmp == j) ok = true;
    }
  }

  cout << ans << endl;
  return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in<ll>();

	vector<vector<int>> C(10,vector<int>(10,0));

	REP(i,N){
		int V=i+1;
		int T=V%10;
		int H,Q=V;
		while(Q){
			H=Q%10;
			Q/=10;
		}
		C[H][T]++;
	}

	int S=0;
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			S += C[i][j]*C[j][i];
		}
	}
	
	out(S);

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int m = sc.nextInt();

		boolean[][] edges = new boolean[n][n];
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;

			edges[a][b] = true;
			edges[b][a] = true;
		}

		Permutation np = new Permutation(n);
		int cnt = 0;
		out:
		for (List<Integer> perm : np) {
			if (perm == null) {
				break;
			}

			if (perm.get(0) != 0) {
				continue;
			}

			for (int i = 1; i < n; i++) {
				if (!edges[perm.get(i - 1)][perm.get(i)]) {
					continue out;
				}
			}
			cnt++;
		}

		pr.println(cnt);
	}

	private static class Permutation implements Iterable<List<Integer>>{
		int n;

		boolean[] used;
		List<Integer> perm;
		Deque<Integer> ist;
		PermutationIterator it;

		Permutation(int n) {
			this.n = n;
			used = new boolean[n];
			perm = new ArrayList<Integer>();
			ist = new ArrayDeque<Integer>();
			ist.add(-1);
			it = new PermutationIterator(this);
		}

		List<Integer> next() {
			out:
			while (!ist.isEmpty()) {
				int k = ist.pop();

				if (k != -1) {
					// ループ途中での戻り
					used[k] = false;
					perm.remove(perm.size() - 1);
				} else {
					// 最初から
					int pos = perm.size();

					if (pos == n) {
						// perm に対する操作 =========================
						return perm;
						// perm に対する操作 =========================
					}
				}

				for (int i = k + 1; i < n; i++) {
					if (!used[i]) {
						ist.push(i);

						used[i] = true;
						perm.add(i);
						ist.push(-1);
						continue out;
					}
				}
			}

		return null;
		}

		@Override
		public Iterator<List<Integer>> iterator() {
			return it;
		}

		private static class PermutationIterator implements Iterator<List<Integer>> {

			Permutation p;
			PermutationIterator(Permutation p) {
				this.p = p;
			}

			@Override
			public boolean hasNext() {
				return !p.ist.isEmpty();
			}

			@Override
			public List<Integer> next() {
				return p.next();
			}

		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 22924
#include <stdio.h>

int main(void)
{
	int H, W, h, w, flag = 0;

	while (flag == 0)
	{
		scanf("%d %d", &H, &W);

		if ((H == 0) && (W == 0))
			break;

		for (h = 0; h < (H / 2); h++)
		{
			for (w = 0; w < (W / 2); w++)
			{
				printf("#.");
			}

			if ((W % 2) == 1)
			{
				printf("#");
			}

			printf("\n");

			for (w = 0; w < (W / 2); w++)
			{
				printf(".#");
			}

			if ((W % 2) == 1)
			{
				printf(".");
			}

			printf("\n");
		}

		if ((H % 2) == 1)
		{
			for (w = 0; w < (W / 2); w++)
			{
				printf("#.");
			}

			if ((W % 2) == 1)
			{
				printf("#");
			}

			printf("\n");
		}

		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2040
#include <stdio.h>

#define MAX 1000000001

int w[100001], n, k;

int f(int m){
	int ans=0,sum=0;
	for(int i=0;i<n;i++){
		if(w[i] > m){
            return MAX;
        }
		if(sum + w[i] <= m){
            sum += w[i];
        }
		else{
			ans++;
			sum = w[i];
		}
	}
	return ans;
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
        scanf("%d",w+i);
    }
	int l=0,r=MAX;
	while(r-l > 1){
		int m = (l+r)/2;
		if( f(m) <= k-1){
            r = m;
        }
		else {
            l = m;
        }
	}
	printf("%d\n",r);

    return 0;
} 



Measured memory_bytes: 2236
from functools import lru_cache
import sys

sys.setrecursionlimit(2000)

s = int(input())
mod = 10 ** 9 + 7


@lru_cache(maxsize=None)
def dfs(n):
    if n <= 2:
        return 0
    elif 3<=n<=5:
        return 1
    else:
        count = 1
        for i in range(3, n + 1):
            count += dfs(n - i)
            count %= mod

        return count % mod


ans = dfs(s)
print(ans)


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

 
int main(){
  int n; cin >> n;
  string s; cin >> s;
  ll r=0;
  ll g=0;
  ll b=0;
  rep(i, n){
    if(s[i]=='R') r++;
    else if(s[i]=='G') g++;
    else b++;
  }
  ll mu = r*g*b;
  int a, ba, c;
  for(int i=0; i<n; i++){
    for(int j=1; i+j*2<n; j++){
      a = i;
      ba = i+j;
      c = i+j*2;
      if(s[a]!=s[ba] && s[a]!=s[c] && s[ba]!=s[c]) mu--;
    }
  }
  cout << mu << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;

    string ans="";
    while(N){
        if(N%2){
            N--;
            ans='1'+ans;
        }
        else{
            ans='0'+ans;
        }
        N/=-2;
    }
    if(ans=="") ans="0";
    cout<<ans<<endl;

}


Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    for (i=0; i < input.length-1; i++) {
        tmp = input[i].split(" ")
        var a = parseInt(tmp[0])
        var b = parseInt(tmp[1])
        var d = Math.floor(a / b)
        var r = a % b
        var f = Math.floor(a / b * Math.pow(10, 5)) / Math.pow(10, 5)
        console.log(d, r, f)
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main()
{
	int n, crd[4][13] = {}, num;
	char mrk;

	cin >> n;

	for (n; n > 0; n--) {
		cin >> mrk >> num;

		if (mrk == 'S') crd[0][num - 1] = 1;
		else if (mrk == 'H') crd[1][num - 1] = 1;
		else if (mrk == 'C') crd[2][num - 1] = 1;
		else if (mrk == 'D') crd[3][num - 1] = 1;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (crd[i][j] == 0) {
				if (i == 0) cout << "S " << j + 1 << endl;
				else if (i == 1) cout << "H " << j + 1 << endl;
				else if (i == 2) cout << "C " << j + 1 << endl;
				else if (i == 3) cout << "D " << j + 1 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, n - 1) {
        ll d = max(0ll, a[i + 1] + a[i] - x);
        ans += d;
        a[i + 1] = max(0ll, a[i + 1] - d);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorders
{
	public class Program
	{
		static void Main(string[] args)
		{
			string n = Console.ReadLine();
			int l = n.Length;
			int max = int.Parse(n);
			
			var str = new List<char>();
			int ans = 0;
			ans += DFS(str, '0', l, max);
			ans += DFS(str, '3', l, max);
			ans += DFS(str, '5', l, max);
			ans += DFS(str, '7', l, max);

			Console.WriteLine(ans);
		}

		static int DFS(List<char> str, char next, int l, int max)
		{
			str.Add(next);
			try {
				if (str.Count == l) {
					string ss = new string(str.ToArray()).TrimStart('0');
					if (string.IsNullOrWhiteSpace(ss) == false) {
						int num = int.Parse(ss);
						if (num <= max && ss.Contains('0') == false && str.Contains('3') && str.Contains('5') && str.Contains('7')) {
							return 1;
						}
					}

					return 0;
				}

				int count = 0;
				count += DFS(str, '0', l, max);
				count += DFS(str, '3', l, max);
				count += DFS(str, '5', l, max);
				count += DFS(str, '7', l, max);

				return count;
			} finally {
				str.RemoveAt(str.Count - 1);
			}
		}
	}
}

Measured memory_bytes: 17324
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int i,a[105],n,ans;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<=n;i++)cin>>a[i];
    for(i=2;i<=n;i++)
    {
        if(a[i]==a[i-1])ans++,i++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string> 
#include <set>
typedef long long ll;
using namespace std;

int inf = 1000001;

int main() {
    string s, t; cin >> s >> t;
    int cnt = inf;
    int len = s.size() - t.size();
    for (int i = 0; i <= len; ++i) {
        int temp = 0;
        for (int j = i, k = 0; j < s.size() && k < t.size(); j++, k++) {
            if (t[k] != s[j]) {
                temp++;
            }
        }
        
       // cout << "temp " << temp << endl;
        cnt = min(cnt, temp);
        //cout << "cnt " << cnt << endl;
        
    }
    cout << cnt << endl;
    return 0;
}


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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define reg register int
#define pii pair<int,int>
#define cr const reg&
using namespace std;
const int inf = 2147483647;
const int N = 1e5 + 2;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I LL read() {
	LL x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

LL a[N], b[N];
map<LL, LL> mp[N];

int main() {
	reg n = read(), q = read(), tp = 0; b[tp] = n;
	for(reg i = 1; i <= q; i++) {
		LL x = read();
		while(tp >= 0 && b[tp] > x) --tp; b[++tp] = x;
	} q = tp, mp[q][b[q]] = 1;
	for(reg i = q; i >= 0; i--) {
		for(auto hh : mp[i]) {
			LL x = hh.fi, val = hh.se;
			if(i == 0 || x <= b[0]) {a[x] += val; continue;}
			reg tt = lower_bound(b, b + i, x) - b - 1;
			mp[tt][b[tt]] += val * (x / b[tt]);
			if(x % b[tt]) mp[tt][x % b[tt]] += val;
		}
	} for(reg i = n; i; i--) a[i] += a[i + 1];
	for(reg i = 1; i <= n; i++) pr2(a[i]);
	return 0;
}



Measured memory_bytes: 34944
#include <cstdio>
#include <cmath>
#include <algorithm>

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

using namespace std;

typedef long double ld;

int k;
ld r, l, p, e, t;

ld solve(int k, ld r, ld l){
	if(k == 0){
		return fabs((r + l) / 2 - t) <= e;
	}
	if(t + e <= r || l <= t - e){
		return 0;
	}
	if(t - e <= r && l <= t + e){
		return 1;
	}
	ld f = solve(k - 1, r, (r + l) / 2);
	ld g = solve(k - 1, (r + l) / 2, l);
	if((r + l) / 2 >= t){
		return f * (1 - p) + g * p;
	}
	else{
		return f * p + g * (1 - p);
	}
}

int main(){
	scanf("%d%Lf%Lf%Lf%Lf%Lf", &k, &r, &l, &p, &e, &t);
	printf("%Lf\n", solve(k, r, l));
	return 0;
}

Measured memory_bytes: 1084
#include<bits/stdc++.h>
using namespace std;
int g[2010][2010];
int ans[2010];
int n,x,y;
int main(){
    cin>>n>>x>>y;
    if(y<x)swap(x,y);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(i<=x&&y<=j)ans[min(x-i+j-y+1,j-i)]++;//ac
            else if(x<i&&j<y)ans[min(j-i,i-x+y-j+1)]++;//bb
            else if(y<=i&&y<=j)ans[j-i]++;//cc
            else if(i<=x&&j<=x)ans[j-i]++;//aa
            else if(i<=x){//ab
                int dis=min(j-i,y-j+1+x-i);
                ans[dis]++;
            }else if(y<=j){//bc
                int dis=min(j-i,j-y+1+i-x);
                ans[dis]++;
            }
        }
    }
    for(int i=1;i<=n-1;i++)cout<<ans[i]<<endl;
    return 0;
}
/*
10 2 9
10
12
13
8
2
0
0
0
0
*/

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

using namespace std;

int main() {
  vector < vector < int >> C(3, vector < int > (3));

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> C.at(i).at(j);
    }
  }

  for (int a1 = 0; a1 <= 100; a1++) {
    int b1 = C.at(0).at(0) - a1;
    int b2 = C.at(0).at(1) - a1;
    int b3 = C.at(0).at(2) - a1;
    for (int a2 = 0; a2 <= 100; a2++) {
      if (
        a2 + b1 == C.at(1).at(0) && a2 + b2 == C.at(1).at(1) && a2 + b3 == C.at(1).at(2)
      ) {

        for (int a3 = 0; a3 <= 100; a3++) {

          if (
            a3 + b1 == C.at(2).at(0) && a3 + b2 == C.at(2).at(1) && a3 + b3 == C.at(2).at(2)
          ) {            
            cout << "Yes" << endl;
            return 0;
          }

        }

      }

    }

  }

  cout << "No" << endl;
}

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

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n";
#define print(a) for(auto &x : a) cout << x << " "; cout << "\n";

const int inf = 1e18 + 5;
const int N = 2e5 + 50;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes\n";
    else cout << "No\n";
}

int32_t main()
{
    DESYNC
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

struct dice{
    int s[6];
    void roll(char c) {
        int tmp;
        if (c == 'E') {
            tmp = s[0];
            s[0] = s[3];
            s[3] = s[5];
            s[5] = s[2];
            s[2] = tmp;
        } else if (c == 'W') {
            tmp = s[0];
            s[0] = s[2];
            s[2] = s[5];
            s[5] = s[3];
            s[3] = tmp;
        } else if (c == 'N') {
            tmp = s[0];
            s[0] = s[1];
            s[1] = s[5];
            s[5] = s[4];
            s[4] = tmp;
        } else if (c == 'S') {
            tmp = s[0];
            s[0] = s[4];
            s[4] = s[5];
            s[5] = s[1];
            s[1] = tmp;
        } else if (c == 'R') {
            tmp = s[1];
            s[1] = s[2];
            s[2] = s[4];
            s[4] = s[3];
            s[3] = tmp;
        }
    }
    int top() {
        return s[0];
    }
    int front() {
        return s[1];
    }
    int right() {
        return s[2];
    }
    int left() {
        return s[3];
    }
    int back() {
        return s[4];
    }
    int bottom() {
        return s[5];
    }
};

bool check(dice d1, dice d2) {
    rep(i, 0, 6) {
        if (d1.s[i] != d2.s[i]) return false;
    }
    return true;
}

int main()
{
    dice d1, d2;
    rep(i, 0, 6) cin >> d1.s[i];
    rep(i, 0, 6) cin >> d2.s[i];

    rep(i, 0, 4) {
        d2.roll('N');
        rep(j, 0, 4) {
            d2.roll('R');
            if (check(d1, d2)) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    d2.roll('E');
    rep(i, 0, 4) {
        d2.roll('R');
        if (check(d1, d2)) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    d2.roll('W');
    d2.roll('W');
    rep(i, 0, 4) {
        d2.roll('R');
        if (check(d1, d2)) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}



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

long long int a,b,q,i;
vector<long long int> s,t,x;


int main(){
    cin>>a>>b>>q;
    s.resize(a+2);
    t.resize(b+2);
    x.resize(q);
    for(i=1;i<=a;i++){
        cin>>s[i];
    }
    for(i=1;i<=b;i++){
        cin>>t[i];
    }
    for(i=0;i<q;i++){
        cin>>x[i];
    }
    s[0]=t[0]=-500000000000;
    s[a+1]=t[b+1]=500000000000;//番兵

    sort(s.begin(),s.end());
    sort(t.begin(),t.end());

    vector<long long int> ans(q);
    long long int key1,key2;
    vector<long long int>::iterator position;
    
    for(i=0;i<q;i++){
        position=lower_bound(s.begin(),s.end(),x[i]);
        key1=distance(s.begin(),position);

        position=lower_bound(t.begin(),t.end(),x[i]);
        key2=distance(t.begin(),position);

        ans[i]=500000000000;
        
        ans[i]=min(ans[i],max(s[key1]-x[i],t[key2]-x[i]));
        ans[i]=min(ans[i],max(x[i]-s[key1-1],x[i]-t[key2-1]));
        ans[i]=min(ans[i],s[key1]+x[i]-2*t[key2-1]);
        ans[i]=min(ans[i],2*s[key1]-x[i]-t[key2-1]);
        ans[i]=min(ans[i],t[key2]+x[i]-2*s[key1-1]);
        ans[i]=min(ans[i],2*t[key2]-x[i]-s[key1-1]);
    }
    for(i=0;i<q;i++){
        printf("%lld\n",ans[i]);
    }
    return 0;
}

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

int main() {
  int64_t A, B;
  cin >> A >> B;
  int64_t tmp;
  if (A > B){
    swap(A, B);
  }
  int64_t a = A;
  int64_t b = B;
  while (true){
    tmp = b % a;
    if (tmp == 0){
      break;
    }
    b = a;
    a = tmp;
  }
  cout << A * B / a << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);

if((a+b)>(c+d)){
	printf("Left\n");
}else if((a+b)<(c+d)){
	printf("Right\n");
}else{
	printf("Balanced\n");
}

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2005;
int a[maxn], b[maxn];

int main(){
    int n, x;
    scanf("%d%d", &n, &x);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        b[i] = a[i];
    }
    LL ans = (1LL << 63) - 1;
    for(int t = 1; t <= n; t++){
        LL ret = (LL)x * (t - 1);
        for(int i = 0; i < n; i++){
            ret += b[i];
        }
        ans = min(ans, ret);
        for(int i = 0; i < n; i++){
            b[i] = min(b[i], a[(i - t + n) % n]);
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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




int main(){
   int n,m;
   cin>>n>>m;
   vector<int> v[101010];
   priority_queue<int> al;
   rep(i,n){
       int a,b;
       cin>>a>>b;
       v[a-1].push_back(b);
   }
   int sum=0;
   rep(i,m){
       for(int j:v[i]){
           al.push(j);
       }
       if(!al.empty()){
           sum+=al.top();
           al.pop();
       }
   }
   cout<<sum<<endl;
   return 0;
}



Measured memory_bytes: 5632
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		int N=s.nextInt();
		int Debt=100000;
		for(int i=0;i<N;i++){
			Debt=Debt*105/100;
			if(Debt%1000!=0)Debt=Debt+1000-Debt%1000;
		}
		System.out.println(Debt);
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
unsigned long long n,ans;

int main(){
    speed;
    cin >> n;
    for ( int i = 1 ;i <= n-1;i++){
        ans+=i;
    }
    cout << ans;
}





Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 3005;

int n;
struct edge{
	int x,nxt;
}e[N*2];
int h[N],tot;
bool f[N],bz[N];
int a[N];

void inse(int x,int y){
	e[++tot].x=y;
	e[tot].nxt=h[x];
	h[x]=tot;
}

void dfs(int x){
	bz[x]=1;
	f[x]=0;
	for(int p=h[x];p;p=e[p].nxt)
	if (!bz[e[p].x]){
		dfs(e[p].x);
		if (a[e[p].x]<a[x]&&!f[e[p].x])f[x]=1;
	}
}

int main(){
	n=get();
	fo(i,1,n)a[i]=get();
	fo(i,2,n){
		int x=get(),y=get();
		inse(x,y);
		inse(y,x);
	}
	fo(rt,1,n){
		fo(i,1,n)f[i]=bz[i]=0;
		dfs(rt);
		if (f[rt])printf("%d ",rt);
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main(){
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var N, M int
	mp1 := make(map[int]int)
	fmt.Fscan(r, &N)
	for i := 0; i < N; i++{
		var D int
		fmt.Fscan(r, &D)
		mp1[D]++
	}
	fmt.Fscan(r, &M)
	var ans string = "YES"
	for i:=0; i < M; i++{
		var T int
		fmt.Fscan(r, &T)
		v, ok := mp1[T]
		if(v <= 0 || !ok){
			ans = "NO"
		}
		mp1[T]--
	}
	fmt.Println(ans)
}

Measured memory_bytes: 15456
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, m, d) = in.readLine().split("\\s+").map(_.toInt)

    if (d == 0) {
      out.println(f"${1.0 / n * (m - 1)}%1.10f")
    } else {
      out.println(f"${2.0 * (n - d) / n / n * (m - 1)}%1.10f")
    }
    out.flush()
  }
}


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

using namespace std;

using PII = pair<int,int>;
#define MP make_pair
#define FF first
#define SS second

double P, X;
int N;
vector<PII> G[100010];

double dfs1(int u, int p){
  double res = 0.;
  for(auto e: G[u]){
	if(e.FF == p) continue;
	res += P * (e.SS + dfs1(e.FF, u));
  }
  
  return res;
}

double dfs2(int u, int p){
  double res = X;
  for(auto e: G[u]){
	if(e.FF == p) continue;
	res += P * (e.SS + dfs2(e.FF, u));
  }
  
  return res;
}

int main(){
  cin >> P;
  cin >> N;
  for(int i=0;i<N-1;++i){
	int u, v, c;
	cin >> u >> v >> c;
	--u;
	--v;
	G[u].push_back(MP(v,c));
	G[v].push_back(MP(u,c));
  }

  X = dfs1(0, -1);
  cout << fixed << setprecision(9) << dfs2(0, -1) << endl;
  
  return 0;
}

Measured memory_bytes: 14984
#include <stdio.h>
int main (void)
{
	int z,i,j,k,n,count;
	scanf("%d",&n);
	int x[n];
	count=0;
	j=n;
	for(i=0;i<n;i++)
	{
		scanf("%d",&x[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=n-1;j>=i+1;j--)
		{
			if(x[j]<x[j-1])
			{
				z=x[j-1];
				x[j-1]=x[j];
				x[j]=z;
				count++;
			}
		}
	}
	for(k=0;k<n;k++)
			{
				printf("%d",x[k]);
				if(k==n-1)
				{
					break;
				}
				printf(" ");
			}
			printf("\n");
		printf("%d",count);
		printf("\n");

}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

void check(vector<ll> A, ll K, int N)
{
  for_each(A.begin(), A.end(), [K, N](ll& val) { val -= (K / N); });
  for (int i = 0; i < (K % N); ++i) {
    for_each(A.begin(), A.end(), [](ll& val) { ++val; });
    int ix = distance(A.begin(), max_element(A.begin(), A.end()));
    A[ix] -= (N + 1);
  }
  fprintf(stderr, "DEBUG: A=\n");
  copy(A.begin(), A.end(), ostream_iterator<ll>(cerr, ", "));
  fprintf(stderr, "done\n");
}

int main()
{
  ll K; scanf("%lld", &K);
  int N = 50;
  vector<ll> A(N);
  for (int i = 0; i < N; ++i) {
    A[i] = i + (K / N);
  }
  for (int i = 0; i < (K % N); ++i) {
    for_each(A.begin(), A.end(), [](ll& val) { --val; });
    A[i] += (N + 1);
  }

  // check(A, K, N);

  printf("%d\n", N);
  printf("%lld", A[0]);
  for (int i = 1; i < N; ++i) {
    printf(" %lld", A[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vi h(n);
  rep(i, n) cin >> h[i];
  vvi root(n);
  rep(i, m){
    int a,b;
    cin >> a >> b;
    a--; b--;
    root[a].push_back(b);
    root[b].push_back(a);
  }
  int ans = 0;
  rep(i, n){
    bool ok = true;
    for(int num : root[i]){
      if(h[num] >= h[i]){
        ok = false;
        break;
      }
    }
    if(ok) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 8804
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		if(Math.abs(m - n) > 1) {
			System.out.println("0");
		}
		else {
			long factorial = 1;
			if(Math.abs(m - n) == 0) factorial *= 2;
			for(int i = 2; i <= n; i++) {
				factorial = factorial * i % 1000000007;
			}
			for(int i = 2; i <= m; i++) {
				factorial = factorial * i % 1000000007;
			}
			System.out.println(factorial);
		}
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n; 
    double a, b, c = 0, ans;
    cin >> n;

    rep(i, n) {
        cin >> a;
        b = 1.0 / a;
        c += b;
    }

    ans = 1.0 / c;

    printf("%.10f\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
 
bool codejam = 0;
 
typedef long long li;
typedef long double ld;
 
void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}
const int N = 550;
vector<int> arr;
vector<int> get_divisors (int n) {
	vector<int> ans;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i)
			continue;
		ans.push_back(i);
		if (i * i != n)
			ans.push_back(n / i);
	}
	return ans;
}
bool check (vector<int> arr, int d, int k) {
	for (auto &i : arr) {
		i %= d;
	}
	sort(arr.begin(), arr.end());	
	int i = 0, j = (int) arr.size() - 1;
	int taken = 0;
	while (i < j) {
		taken += min(arr[i], d - arr[j]);
		int taken_here = min(arr[i], d - arr[j]);
		arr[i] -= taken_here;
		arr[j] += taken_here;
		arr[i] %= d, arr[j] %= d;
		if (arr[i] == 0) i += 1;
		if (arr[j] == 0) j -= 1;
	}
	if (taken > k)
		return false;
	for (auto i: arr)
		if (i != 0)
			return false;
	return true;
}
void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> arr(n);
	int S = 0;
	for (int i = 0; i < n; ++i)
		cin >> arr[i], S += arr[i];
	auto d = get_divisors(S);
	sort(d.begin(), d.end());
	int mx = -1;
	for (auto dd : d) {
		if (check(arr, dd, k)) mx = max(mx, dd);
	}
	cout << mx;
}	


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
double p;
void dfs(int d,int x){
  if(d==0)
    if(x-k<=0)p+=1;
    else p+=x-k;
  else
    for(int i=1;i<=m;i++)
      dfs(d-1,x+i);
}
int main(){
  while(cin>>n>>m>>k,n){
    p=0;dfs(n,0);
    printf("%.8f\n",p/(double)(pow(m,n)));
  }
}

Measured memory_bytes: 3304
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long fact[200001];
long long pow(long long a,long long b,long long mod){
	long long x=1,y=a;
	while(b){
		if(b%2==1){
			x*=y;
			x%=mod;
		}
		y=(y*y);
		y%=mod;
		b/=2;
	}
	return x;
}
long long inverse(long long x,long long mod){
	return pow(x,mod-2,mod);
}
long long C(long long n,long long r){
	return (fact[n]*((inverse(fact[r],mod)*inverse(fact[n-r],mod))%mod))%mod;
}
int main(){
	fact[0]=1;
	for(int i=1;i<=200000;i++) fact[i]=(fact[i-1]*i)%mod;
	long long h,w,a,b;
	cin>>h>>w>>a>>b;
	long long res=0;
	for(int i=b+1;i<=w;i++){
		res+=(C(h-a-2+i,h-a-1)*C(a-1+w-i,a-1));
		res%=mod;
	}
	cout<<res;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(l, r);
    if (r - l < 10000) {
        int ans = INF;
        for (int i = l; i <= r; i++) {
            for (int j = i+1; j <= r; j++) {
                ans = min(ans, (i * j) % 2019);
            }
        }
        std::cout << ans << std::endl;
    } else {
        std::cout << 0 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	long n,i,min = 1000000, max = -1000000;
	long long sum = 0;
	
	scanf("%ld",&n);
	while(n-- > 0)
	{
		scanf("%ld",&i);
		if(i < min)
		{
			min = i;
		}
		if(i > max)
		{
			max = i;
		}
		sum += i;
	}
	printf("%ld %ld %ld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 600
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val n = in.readLine().toInt

    out.println(
      n / 2 + n % 2
    )
    out.flush()
  }
}


Measured memory_bytes: 27192
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2005;
int n,z,w,a[N],ans,Mn_g[N],Mx_f[N],f[N][N],g[N][N];
int main()
{
   scanf("%d%d%d",&n,&z,&w);
   for (int i=1;i<=n;i++) scanf("%d",&a[i]);
   a[0]=w;
   for (int i=0;i<n;i++) f[n][i]=g[n][i]=Mx_f[i]=Mn_g[i]=abs(a[n]-a[i]);
   for (int i=n-1;i>=0;i--)
     for (int j=0;j<i;j++)
     {
       if (i) f[i][j]=Mn_g[i],Mx_f[j]=max(Mx_f[j],f[i][j]);
       if (j) g[i][j]=Mx_f[i],Mn_g[j]=min(Mn_g[j],g[i][j]);
     }
   for (int i=1;i<=n;i++) ans=max(ans,f[i][0]);
   printf("%d\n",ans);
   return 0;
}

Measured memory_bytes: 30720
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;


typedef long long ll;
const int MAX_N = 100025;
int dp[MAX_N],in[MAX_N];
vector<int > G[MAX_N];
int main()
{
   
    queue<int > q;
    int n,m,a,b,ans = 0;scanf("%d%d",&n,&m);
    for(int i = 1;i<=m;++i) 
	scanf("%d%d",&a,&b),in[b]++,G[a].push_back(b);
    for(int i = 1;i<=n;++i) if(!in[i]) q.push(i);
    while(!q.empty())
    {
        int now = q.front();
        q.pop();
        int sz = G[now].size();
        for(int i = 0;i<sz;++i)
        {
            dp[G[now][i]] = max(dp[G[now][i]],dp[now]+1);
            in[G[now][i]]--;
            if(in[G[now][i]]==0) q.push(G[now][i]);
        }
    }
    for(int i = 1;i<=n;++i) ans = max(ans,dp[i]);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 9984
import java.util.*;

public class Main {

    private static int sweepOne(List<char[]> board, int i, int j) {
        if (i < 0 || i >= board.size() || j < 0 || j >= board.get(i).length
                || board.get(i)[j] == '.')
            return 0;

        if (board.get(i)[j] == '#')
            return 1;

        return 0;
    }

    private static int sweep(List<char[]> board, int i, int j) {
        int left = sweepOne(board, i - 1, j);
        int right = sweepOne(board, i + 1, j);
        int up = sweepOne(board, i, j + 1);
        int down = sweepOne(board, i, j - 1);
        int a = sweepOne(board, i - 1, j - 1);
        int b = sweepOne(board, i + 1, j + 1);
        int c = sweepOne(board, i - 1, j + 1);
        int d = sweepOne(board, i + 1, j - 1);

        return left + right + up + down + a + b + c + d;

    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int row = sc.nextInt();
        int col = sc.nextInt();
        sc.nextLine();
        List<char[]> board = new ArrayList<>();
        String[] msg = new String[row];
        for (int i = 0; i < row; i++) {
            String tmp = sc.nextLine();
            board.add(tmp.toCharArray());
        }


        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                if (board.get(i)[j] == '.') {
                    board.get(i)[j] = (char)(sweep(board, i, j) + 48);
                }
            }
        }

        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                System.out.print(board.get(i)[j]);
            }
            System.out.println();
        }
    }

}

Measured memory_bytes: 22868