Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

import math

N = int(raw_input())

h = int(math.ceil(N/4.0))
n = int(math.ceil(h*4*N/4.0/(h*4-N)))
w = 11451419198101145141919810
print h, n, w

Fixed submission:
def solver():
    N = int(raw_input())

    for h in xrange(1, 3501):
        for n in xrange(1, 3501):
            x = N * h * n;
            y = 4 * n * h - N * n - N * h;
            if y > 0 and x % y == 0:
                w = x / y
                return map(str, [h, n, w])


print " ".join(solver())

Buggy python submission (verdict: Runtime Error):
# coding: utf-8

import math

N = int(raw_input())

h = int(math.ceil(N/4.0))
n = int(math.ceil(h*4*N/4.0/(h*4-N)))
w = 1145141919810
print h, n, w

Fixed submission:
def solver():
    N = int(raw_input())

    for h in xrange(1, 3501):
        for n in xrange(1, 3501):
            x = N * h * n;
            y = 4 * n * h - N * n - N * h;
            if y > 0 and x % y == 0:
                w = x / y
                return map(str, [h, n, w])


print " ".join(solver())

Buggy python submission (verdict: Runtime Error):
# coding: utf-8

import math

N = int(raw_input())

h = int(math.ceil(N/4.0))
n = int(math.ceil(h*4*N/4.0/(h*4-N)))
w = int(math.ceil(N*n*h-4*n-4*h))
print h, n, w

Fixed submission:
def solver():
    N = int(raw_input())

    for h in xrange(1, 3501):
        for n in xrange(1, 3501):
            x = N * h * n;
            y = 4 * n * h - N * n - N * h;
            if y > 0 and x % y == 0:
                w = x / y
                return map(str, [h, n, w])


print " ".join(solver())

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

N = int(raw_input())

for h in range(1, 3501):
    for n in range(1, 3501):
        for w in range(1, 3501):
            if 4 * h * n * w == N * n * w + N * h * w + N * h * n:
                print h, n, w
                exit()


Fixed submission:
def solver():
    N = int(raw_input())

    for h in xrange(1, 3501):
        for n in xrange(1, 3501):
            x = N * h * n;
            y = 4 * n * h - N * n - N * h;
            if y > 0 and x % y == 0:
                w = x / y
                return map(str, [h, n, w])


print " ".join(solver())
Buggy python submission (verdict: Runtime Error):
#include <stdio.h>

int main() {
    int N;

    scanf("%d", &N);

    if ( (N % 10 == 9) || (N / 10 == 9) ) {
        puts("Yes");
    }
    else {
        puts("No");
    }

    return 0;
}

Fixed submission:
N = int(raw_input())

print "Yes" if (N % 10 == 9) or (N / 10 == 9) else "No"
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
A = [0] * 100001

for i in range(N):
    a = int(raw_input())
    A[a] += 1

print sum([ 0 if A[i] % 2 == 0 else 1 for i in range(100001)])


Fixed submission:
N = int(raw_input())
S = set()

for _ in range(N):
    A = int(raw_input())
    if A in S:
        S.remove(A)
    else:
        S.add(A)

print len(S)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
table = {}
for i in range(n):
    a = int(input())
    table[i] = a-1

is_visited = [ False for _ in range(n) ]
is_visited[0] = True

cnt = 0
now = 0
while True:
    if now == 1:
        print(cnt)
        break
    nxt = table[now]
    if is_visited[nxt]:
        print(-1)
        break
    now = nxt
    cnt += 1

Fixed submission:
n = int(input())
table = {}
for i in range(n):
    a = int(input())
    table[i] = a-1

is_visited = [ False for _ in range(n) ]
is_visited[0] = True

cnt = 0
now = 0
while True:
    is_visited[now] = True
    if now == 1:
        print(cnt)
        break
    nxt = table[now]
    if is_visited[nxt]:
        print(-1)
        break
    now = nxt
    cnt += 1
Buggy python submission (verdict: Runtime Error):
s = raw_input()

ans = "yes"

for i in s:
    if s.count(s[i]) != 1:
        ans = "no"

print ans

Fixed submission:
s = raw_input()

ans = "yes"

for i in s:
    if s.count(i) != 1:
        ans = "no"

print ans
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())

s = [int(raw_input()) for _ in xrange(N)] 
s.sort()

ans = sum(s)
k = 0

for i in range(N):
    if S[i] % 10 != 0:
        k = S[i]
        break

if ans % 10 == 0 and k == 0:
    print 0
elif ans % 10 != 0:
    print ans
else:
    print ans-k

Fixed submission:
N = int(raw_input())

s = []

for i in range(N):
    s.append(int(raw_input()))

s.sort()

ans = sum(s)

for i in range(N):
    if ans % 10 == 0:
        if s[i] % 10 == 0:
            pass
        else:
            ans -= s[i]
    else:
        break

if ans % 10 == 0:
    print 0
else:
    print ans
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
t = 1

for i in xrange(1, N):

    if i*i > N:
        break

    elif i*i == N:
        t = i
        break

    if N % i == 0:
        t = i

print len(str(N/t))

Fixed submission:
A, B = map(int, raw_input().split())

print (A + B) % 24
Buggy python submission (verdict: Runtime Error):
N, M = map(int, raw_input().split())

a, b = [map(int, raw_input().split()) for _ in xrange(N)]
c, d = [map(int, raw_input().split()) for _ in xrange(M)]

for i in xrange(N):
    for j in xrange(M):

        d = abs(a[i]-c[j]) + abs(b[i]-d[j])

        if j == 0:
            t = d
            ans = 1

        elif t > d:
            t = d
            ans = j+1

    print ans

Fixed submission:
import math

N, M = map(int, raw_input().split())

a, b, c, d = [], [], [], []

for i in xrange(N):
    s = map(int, raw_input().split())
    a.append(s[0])
    b.append(s[1])

for i in xrange(M):
    s = map(int, raw_input().split())
    c.append(s[0])
    d.append(s[1])


ans = 0
t = 0
for i in xrange(N):
    for j in xrange(M):
        if j == 0:
            t = abs(a[i]-c[j]) + abs(b[i]-d[j])
            ans = 1
        elif t > abs(a[i]-c[j]) + abs(b[i]-d[j]):
            t = abs(a[i]-c[j]) + abs(b[i]-d[j])
            ans = j+1
        #print "t = %d" % t
        #print "ans=%d" % ans
    print ans
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())

for i in xrange(1, N):

    if i*i == N:
        t = i
        break

    elif i*i > N:
        break

    if N % i == 0:
        t = i

print len(str(N/t))

Fixed submission:
N = int(raw_input())
t = 1
for i in xrange(1, N):

    if i*i > N:
        break

    elif i*i == N:
        t = i
        break

    if N % i == 0:
        t = i

print max(len(str(t)), len(str(N/t)))

Buggy python submission (verdict: Runtime Error):
N = int(raw_input())

for i in xrange(1, N):

    if i*i > N:
        break

    elif i*i == N:
        t = i
        break

    if N % i == 0:
        t = i

print len(str(N/t))

Fixed submission:
N = int(raw_input())
t = 1
for i in xrange(1, N):

    if i*i > N:
        break

    elif i*i == N:
        t = i
        break

    if N % i == 0:
        t = i

print max(len(str(t)), len(str(N/t)))

Buggy python submission (verdict: Runtime Error):
N = int(raw_input())

for i in xrange(1, N):

    if i*i > N:
        break

    if N % i == 0:
        ans = len(str(N/i))

print ans

Fixed submission:
N = int(raw_input())
t = 1
for i in xrange(1, N):

    if i*i > N:
        break

    elif i*i == N:
        t = i
        break

    if N % i == 0:
        t = i

print max(len(str(t)), len(str(N/t)))

Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
t = 0
for i in xrange(1, N):

    if i*i > N:
        break

    elif i*i == N:
        t = i
        break

    if N % i == 0:
        t = i

print max(len(str(t)), len(str(N/t)))

Fixed submission:
N = int(raw_input())
t = 1
for i in xrange(1, N):

    if i*i > N:
        break

    elif i*i == N:
        t = i
        break

    if N % i == 0:
        t = i

print max(len(str(t)), len(str(N/t)))
Buggy python submission (verdict: Runtime Error):
from math import factorial

N, A, B = map(int, raw_input().split())
v = map(int, raw_input().split())

C = [[0 for i in range(51)] for j in range(51)] #C[n][k] => nCk

for i in range(1, N+1):
    for j in rane(1, i+1):
        if (j == 0 or j == i):
            C[i][j] = 1
        else:
            C[i][j] = C[i-1][j-1] + C[i-1][j]

v.sort(reverse = True)

t = v[A-1]

ans = 0
X, Y = v.count(t), v[:A].count(t)

if (v[0] != v[A-1]):
    ans = C[X][Y]

else:
    for i in range(A, B+1):
        if(i <= X):
            ans += comb[X][i]

print float(sum(v[0:A]))/A
print ans

Fixed submission:
from math import factorial

def comb(n, k):
    f = factorial
    return f(n) / f(k) / f(n-k)

N, A, B = map(int, raw_input().split())
v = map(int, raw_input().split())

v.sort(reverse = True)

print float(sum(v[0:A]))/A

X, Y = 0, 0
ans = 0

for i in range(N):
    if (v[i] == v[A-1]):
        X += 1
    if (v[i] == v[A-1]) and (i < A):
        Y += 1

if (v[0] != v[A-1]):
    ans = comb(X, Y)

else:
    for i in range(A, B+1):
        if(i <= X):
            ans += comb(X, i)

print ans
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())
 
L = [abs((N-1) - 2*i) for i in range(N)]
 
L.sort(); A.sort()
 
print(pow(2, (N-N%2)//2, 10**9+7) if L == A else 0)

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

L = [abs((N-1) - 2*i) for i in range(N)]

L.sort(); A.sort()

print(pow(2, (N-N%2)//2, 10**9+7) if L == A else 0)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())

L = [abs((N-1) - 2*i) for i in range(N)]

L.sort(); A.sort()

print(pow(2, (N-N%2)/2, 10**9+7) if L == A else 0)

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

L = [abs((N-1) - 2*i) for i in range(N)]

L.sort(); A.sort()

print(pow(2, (N-N%2)//2, 10**9+7) if L == A else 0)

Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
A = map(int, raw_input().split())

L = [ abs((N-1) - 2*i) for i in range(N)]

L.sort(); A.sort()

print(pow(2, (N-N%2)/2, 10**9+7) if L == A else 0)

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

L = [abs((N-1) - 2*i) for i in range(N)]

L.sort(); A.sort()

print(pow(2, (N-N%2)//2, 10**9+7) if L == A else 0)
Buggy python submission (verdict: Runtime Error):
class uf_tree:
    def __init__(self, n):
        self.sizes = [0] * n
        self.par = range(n)

    def find(self, x):
        if x == self.par[x]:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.par[y] = x
        self.sizes[x] += self.sizes[y]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self.sizes[find(x)]


N, K, L = map(int, raw_input().split())

uf_1 = uf_tree(N+1)
uf_2 = uf_tree(N+1)

for i in range(K):
    p, q = map(int, raw_input().split())
    uf_1.unite(p, q)

for i in range(L):
    r, s = map(int, raw_input().split())
    uf_2.unite(r, s);

dic = {}
for i in range(1, N+1):
    key = (uf_1.find(i), uf_2.find(i))
    dic[key] = dic.get(key, 0) + 1

for i in range(1, N+1):
    print dic[(d.find(i), t.find(i))],


Fixed submission:
class uf_tree:
    def __init__(self, n):
        self.sizes = [0] * n
        self.par = range(n)

    def find(self, x):
        if x == self.par[x]:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.par[y] = x
        self.sizes[x] += self.sizes[y]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self.sizes[find(x)]


N, K, L = map(int, raw_input().split())

uf_1 = uf_tree(N+1)
uf_2 = uf_tree(N+1)

for i in range(K):
    p, q = map(int, raw_input().split())
    uf_1.unite(p, q)

for i in range(L):
    r, s = map(int, raw_input().split())
    uf_2.unite(r, s);

dic = {}

for i in range(1, N+1):
    key = (uf_1.find(i), uf_2.find(i))
    dic[key] = dic.get(key, 0) + 1

for i in range(1, N+1):
    print dic[(uf_1.find(i), uf_2.find(i))],
Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, raw_input().split())
ans = 0
for i in range(a, b+1):
    if i % x == 0:
        ans += 1
print ans

Fixed submission:
a, b, x = map(int, raw_input().split())

ans = (b/x) - ((a-1)/x)

print ans
Buggy python submission (verdict: Time Limit Exceeded):
s = raw_input()
n = 0

while (len(s) > 2):
    for i in xrange(1, len(s)-1):
        if s[i-1] != s[i+1]:
            s = s[0:i] + s[i+1:len(s)]
            n += 1
            break
    if len(s) == 3 and s[0] == s[2]:
        break

if n % 2 == 1:
    print "First"
else:
    print "Second"

Fixed submission:
s = raw_input()
n = len(s)-2

if s[0] == s[len(s)-1]:
    n -= 1

if n % 2 == 1:
    print "First"
else:
    print "Second"
Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
 
T = map(int, raw_input().split())
A = map(int, raw_input().split())
 
ans = 1
mod = 10 ** 9 + 7
 
if T[N - 1] != A[0]:
    print (0)
    exit()
 
for i in xrange(N):
    if i == 0 or i == N - 1:
        continue
    elif T[i] > T[i-1]:
        if A[i] < T[i] and A[i] == A[i + 1]:
            print (0)
            exit()
        elif A[i] != T[i] and A[i] != A[i + 1]:
            print (0)
            exit()
    else:
        if T[i] == A[i]:
            if A[i] == A[i + 1]:
                ans *= T[i]
        elif T[i] > A[i]:
            if A[i] == A[i + 1]:
                ans *= A[i]
        else:
            if A[i] == A[i + 1]:
                ans *= T[i]
            else:
                print (0)
                exit()
 
print (ans % mod)

Fixed submission:
s = raw_input()

flag = 0
flag2 = 0

for i in s:
    if i == "C":
        flag += 1
    if flag > 0 and i == "F":
        flag2 += 1

if flag2 > 0:
    print "Yes"

else:
    print "No"
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

N  = int(input())

ans = 0
T, A = [0] * 1001, [0] * 1001

for i in range(N):
    T[i], A[i] = map(int, input().split())

    if i != 0 and T[i-1] >= T[i] or A[i-1] >= A[i]:
        t = T[i-1] // T[i] if T[i-1] % T[i] == 0 else T[i-1] // T[i] + 1
        s = A[i-1] // A[i] if A[i-1] % A[i] == 0 else A[i-1] // A[i] + 1

        m = max(t, s)

        T[i] *= m
        A[i] *= m

    ans = sum([T[i], A[i]])

print (ans)


Fixed submission:
a, b, c = map(int, raw_input().split())

ans = 0

if a == b == c:
    ans = 1

elif a == b or b == c or c == a:
    ans = 2

else:
    ans = 3

print ans
Buggy python submission (verdict: Time Limit Exceeded):
n, a = map(int, input().split())
x = [ int(i) for i in input().split() ]

dp = [ [[0] * 3000 for _ in range(55)] for __ in range(55) ]
dp[0][0][0] = 1

for j in range(n+1):
    for k in range(n+1):
        for s in range(2555):
            if j > 0 and x[j-1] > s:
                dp[j][k][s] = dp[j-1][k][s]
            elif j > 0 and k >= 1 and s >= x[j-1]:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]

ans = 0

for k in range(1, n+1):
    ans += dp[n][k][k*a]

print(ans)


Fixed submission:
n, a = map(int, input().split())
x = [ int(i) for i in input().split() ]

dp = [ [[0] * 3000 for _ in range(55)] for __ in range(55) ]
dp[0][0][0] = 1

for j in range(n+1):
    for k in range(n+1):
        for s in range(2555):
            if j > 0 and x[j-1] > s:
                dp[j][k][s] = dp[j-1][k][s]
            elif j > 0 and k >= 1 and s >= x[j-1]:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]

ans = 0

for k in range(1, n+1):
    ans += dp[n][k][k*a]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

ans = 0

N, A = map(int, raw_input().split())

x = map(int, raw_input().split())

for i in range(N):
  for element in itertools.combinations(x, i + 1):
    if sum(element) / (i + 1.0) == A:
      ans += 1

print ans

Fixed submission:
n, a = map(int, input().split())
x = [ int(i) for i in input().split() ]

dp = [ [[0] * 3000 for _ in range(55)] for __ in range(55) ]
dp[0][0][0] = 1

for j in range(n+1):
    for k in range(n+1):
        for s in range(2555):
            if j > 0 and x[j-1] > s:
                dp[j][k][s] = dp[j-1][k][s]
            elif j > 0 and k >= 1 and s >= x[j-1]:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]

ans = 0

for k in range(1, n+1):
    ans += dp[n][k][k*a]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
ans = 0

N = int(raw_input())

A = []

for i in range(N):
  A.append(int(raw_input()))

A.append(0)

for i in range(N):

  while True:

    if A[i] == 0:
      break

    elif A[i] == 1:

      if A[i + 1] >= 1:
        A[i + 1] -= 1
        ans += 1

      break

    A[i] -= 2
    ans += 1

print ans

Fixed submission:
ans = 0

N = int(raw_input())

A = []

for i in range(N):
  A.append(int(raw_input()))

A.append(0)

for i in range(N):

  while True:

    if A[i] == 0:
      break

    elif A[i] == 1:

      if A[i + 1] >= 1:
        A[i + 1] -= 1
        ans += 1

      break

    ans += A[i] / 2

    A[i] = A[i] % 2

print ans
Buggy python submission (verdict: Runtime Error):
def cost(n, a, m):

  hihumi = 0  #hihumi => 滝本ひふみ

  for i in range(n):
    hihumi += (a[i] - m) ** 2

  return hihumi

N = int(raw_input())
a = map(int, raw_input().split())

ans = 100

for i in range(min(a), max(a) + 1):
  if (ans > cost(N, a, i)):
    ans = const(N, a, i)

print ans

Fixed submission:
# coding: utf-8

def cost(n, a, m):

  hihumi = 0  #hihumi => 滝本ひふみ

  for i in range(n):
    hihumi += (a[i] - m) ** 2

  return hihumi

N = int(raw_input())
a = map(int, raw_input().split())

ans = 1000000000000

for i in range(min(a), max(a) + 1):
  if (ans > cost(N, a, i)):
    ans = cost(N, a, i)

print ans
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
 
def count_char_max(text):
 
  a = "abcdefghijklmnopqrstuvwxyz"
  l = [0] * 26
 
  for i in text:
 
    ascNum = ord(i.lower()) - 97
 
    if ascNum < 0 or 25 < ascNum:
      continue
 
    l[ascNum] += 1
 
  return max(l)
 
s = raw_input()

for i in len(s):

  if (s[i] == s[i + 1]):
    print "%d %d" % (i + 1, i + 2)
    quit()

  elif (count_char_max(s[i:i+3]) == 2):
    print "%d %d" % (i + 1, i + 3)
    quit()

print "-1 -1"

Fixed submission:
# coding: utf-8
 
def count_char_max(text):
 
  a = "abcdefghijklmnopqrstuvwxyz"
  l = [0] * 26
 
  for i in text:
 
    ascNum = ord(i.lower()) - 97
 
    if ascNum < 0 or 25 < ascNum:
      continue
 
    l[ascNum] += 1
 
  return max(l)
 
s = raw_input()

for i in range(len(s) - 1):

  if (s[i] == s[i + 1]):
    print "%d %d" % (i + 1, i + 2)
    quit()

for i in range(len(s) - 2):

  if (count_char_max(s[i:i+3]) == 2):
    print "%d %d" % (i + 1, i + 3)
    quit()

print "-1 -1"
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

a, b = map(int, raw_input().split())

ans = 1

for i in range(a, b+1):
  ans *= i

if ans > 0:
  print "Positive"

elif ans == 0:
  print "Zero" #Fate/Zeroは神アニメ

else:
  print "Negative"

Fixed submission:
# coding: utf-8

a, b = map(int, raw_input().split())

if a > 0:
  print "Positive"

elif b >= 0:
  print "Zero" #Fate/Zeroは神アニメ

else:

  if (b - a) % 2 == 0:
    print "Negative"

  else:
    print "Positive"
Buggy python submission (verdict: Runtime Error):
a=input().split()
if a[0]+a[1]+a[2]<=21:
  print('win')
elif a[0]+a[1]+a[2]>21:
  print('bust')

Fixed submission:
a=list(map(int, input().split()))
if a[0]+a[1]+a[2]<=21:
  print('win')
elif a[0]+a[1]+a[2]>21:
  print('bust')
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int(input()).split())
print(max(a*c,a*d,b*c,b*d))

Fixed submission:
a,b,c,d=map(int,input().split())
print(max(a*c,a*d,b*c,b*d))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=int(input().split())
print(max(abs(a),abs(b))*max(abs(c),abs(d)))


Fixed submission:
a,b,c,d=map(int,input().split())
print(max(a*c,a*d,b*c,b*d))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=int(input()).split()
print(max(abs(a),abs(b))*max(abs(c),abs(d)))

Fixed submission:
a,b,c,d=map(int,input().split())
print(max(a*c,a*d,b*c,b*d))
Buggy python submission (verdict: Runtime Error):
a=int(100)
x=int(input())
i=0
for i in range(10000):
  if a < x:
    a*=1.01
    a=int(a)
    i+=1
  elif a>=x:
    break
print(i)


Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
     
p = sorted(p)

ans=0
for i in range(k):
       ans+=p[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
a=int(100)
x=int(input())
for i in range(10000):
  if a < x:
    a*=101//100
    a=int(a)
    i+=1
  else:
    break
print(i)


Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
     
p = sorted(p)

ans=0
for i in range(k):
       ans+=p[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m, v, p = map(int, input().split())
# n:問題数 m:人数 v:投じる標数 p:選ばれるもの
prob_set = list(map(int, input().split()))
prob_set.sort(reverse=True)
ruiseki_prob = [0 for i in range(n)]
ruiseki_prob[0] = prob_set[0]
high = n - 1
low = 0
mid = (high + low) // 2
# 下げるときはhigh = mid-1
# 上げるときはlow = mid
for i in range(1, n):
    ruiseki_prob[i] = ruiseki_prob[i - 1] + prob_set[i]

# print(prob_set)
# print(ruiseki_prob)

while low <= high:
    mid = (low + high) // 2
    # print(mid)
    f = True
    # まず上からp個以内であれば問答無用でOK (つまりindexがp>i)
    if mid < p:
        # print("<p")
        f = True
    else:
        # i~nには全員が票を投じると考えてよい (ここまででn-i票)
        # 次に上からp-1個に全員が票をいれてもよい(ここまでn-i + p-1)
        # それでも無理ならp ~ i-1までに残りを入れる必要がある.これがp[i] + m以下であればいいことがわかる
        if prob_set[mid] + m < prob_set[p - 1]:
            # どうあがいても無理
            # print("too short")
            f = False
        else:
            # どうにかなる
            if p - 1 + n - mid >= v:
                # print("OK for voting")
                f = True
            else:
                # mid
                amari_hyou = m * (v - (p - 1) - (n - mid))
                if ruiseki_prob[mid - 1] - ruiseki_prob[p - 2] + amari_hyou <= (prob_set[mid] + m) * (
                        (mid - 1) - (p - 2)):
                    # print("OK for super-voting")
                    f = True
                else:
                    # print("cannot EVEN super-voting")
                    f = False
    if f:
        low = mid + 1
    else:
        high = mid


print(low)

# 昇順に並んでいるとき,a_i が選ばれる → i > jなるa_jも選ばれる
# 二分探索することで間に合いそう
# あるiについて評価するとき,以下の観点に注意する


Fixed submission:
n, m, v, p = map(int, input().split())
# n:問題数 m:人数 v:投じる標数 p:選ばれるもの
prob_set = list(map(int, input().split()))
prob_set.sort(reverse=True)
ruiseki_prob = [0 for i in range(n)]
ruiseki_prob[0] = prob_set[0]
high = n
low = 0
mid = (high + low) // 2
f = True


for i in range(1, n):
    ruiseki_prob[i] = ruiseki_prob[i - 1] + prob_set[i]

while low < high:
    mid = (low + high) // 2
    if mid <= p-1:
        f = True
    elif prob_set[mid] + m < prob_set[p - 1]:
        f = False
    else:
        hyou = m * (p - 1) + m * (n - mid)
        for i in range(p-1,mid):
            hyou += prob_set[mid] + m - prob_set[i]
        # まず0 ~ p-2まで(1,2,,,p-1まで) :p-1
        # 次にmid,mid+1,,,n-1まで       :n-mid
        # 上限はp-1,p,,,mid-1は(mid)+mずつ
        # 和はmid-1 - p-2
        if hyou < m*v:
            f = False
        else:
            f = True
    if f:
        low = mid + 1
    else:
        high = mid

print(high)

# 昇順に並んでいるとき,a_i が選ばれる → i > jなるa_jも選ばれる
# 二分探索することで間に合いそう
# あるiについて評価するとき,以下の観点に注意する