Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = readline().decode().strip()
K = int(readline())
cnt = 0
ans = 0
for i in N:
    if len(N) == 1:
        ans = N[0]
        break
    if i == '1':
        cnt += 1
        continue
    else:
        if int(i) * 5000 * 10 ** 12 + cnt >= K:
            ans = i
            break
        else:
            ans = N[N.find(i) + 1]
            break

print(ans)


Fixed submission:
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *d = map(int, read().split())
d.sort()

ans = d[N // 2] - d[N // 2 - 1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
LR = [[int(x) for x in readline().split()] for _ in range(M)]
se = set(range(LR[0][0], LR[0][1]+1))
for i in LR:
    sa = set(range(i[0], i[1]+1))
    se = se & sa

print(len(se))



Fixed submission:
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
A = [None]*M
B = [None]*M
for i in range(M):
    A[i], B[i] = map(int, readline().split())

ans = min(B) - max(A)

print(ans + 1 if ans >= 0 else 0)
Buggy python submission (verdict: Runtime Error):
#include <stdio.h>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
    int N, ans = 0;
    vector<int> V(N), C(N);
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        scanf("%d", V.at(i));
    }
    for (int i = 0; i < N; i++)
    {
        scanf("%d", C.at(i));
    }

    for (int i = 0; i < N; i++)
    {
        if (V.at(i) - C.at(i) >= 0)
        {
            ans += V.at(i) - C.at(i);
        }
    }

    printf("%d", ans);

    return 0;
}

Fixed submission:
"""
author : halo2halo
date : 12, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
V = map(int, readline().split())
C = map(int, readline().split())
ans = 0
for v, c in zip(V, C):
    if v - c > 0:
        ans += v - c

print(ans)
Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *H = map(int, readline().split())
dp = [0] * N
dp[1] = abs(H[1] - H[0])

for i in range(2, N):
    dp[i] = min(dp[i - k] + abs(H[i] - H[i - k]) for k in [1, 2])

ans = dp[-1]
print(ans)


Fixed submission:
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *H = map(int, read().split())
dp = [0] * N
dp[1] = abs(H[1] - H[0])

for i in range(2, N):
    dp[i] = min(dp[i - k] + abs(H[i] - H[i - k]) for k in [1, 2])

ans = dp[-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, *H = map(int, read().split())
H.sort()
ans = 10 ** 9
for i in range(N - K + 1):
    ans = min(max(H[i:i + K]) - min(H[i:i + K]), ans)
print(ans)


Fixed submission:
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, *H = map(int, read().split())
H.sort()
print(min(H[i+K-1]-H[i] for i in range(N-K+1)))
Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 25,Oct,2019
"""

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline().rstrip())
T, a = map(int, readline().rstrip().split())
lis = list(map(int, readline().rstrip().split()))
cnt = 100000
for num, area in enumerate(lis):
    res = abs(T * 1000 - area * 6 - a * 1000)
    if res <= cnt:
        cnt = res
        ans = num


print(ans+1)


Fixed submission:
"""
author : halo2halo
date : 16, Jan, 2020
"""

import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
T, A = map(int, readline().split())
H = np.array([int(x) for x in readline().split()])
# print(H)
H = 1000 * T - H * 6
# print(H)
H = abs(H - A*1000)
# print(H)

ans = 0
tmp = 10000000
for num, i in enumerate(H):
    if tmp >= i:
        ans = num
        tmp = i
print(ans + 1)
Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, i = map(int, readline())
print(N - i + 1)


Fixed submission:
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, i = map(int, readline().split())
print(N - i + 1)
Buggy python submission (verdict: Runtime Error):
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = readline().decode().strip()
K = int(readline())
cnt = 0
tmp = 0

for i in N:
    if i == '1':
        cnt += 1
        continue
    else:
        tmp = i
        break
ans = N[tmp-1] if K <= cnt else tmp

print(ans)


Fixed submission:
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = readline().decode().strip()
K = int(readline())
cnt = 0
tmp = 0

for i in N:
    if i == '1':
        cnt += 1
        continue
    else:
        tmp = int(i)
        break
ans = N[tmp-1] if K <= cnt else tmp

print(ans)
Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = readline().decode('utf8').rstrip()
lis = list(S)
# print(lis)
print(lis.index('C'))
print(len(lis))
if lis[0] == 'A' and 2 <= lis.index('C') <= len(lis) - 2:
    st = ''.join(lis[1:lis.index('C')] + lis[lis.index('C') + 1:])
    # print(st)
    if st.lower():
        print('AC')
    else:
        print('WA')

else:
    print('WA')


Fixed submission:
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = list(readline().decode('utf8').rstrip())
bl = S[0] == 'A'
bl &= ('C' in S[2:-1])

if bl:
    S.remove('A')
    S.remove('C')

bl &= all('a' <= x <= 'z' for x in S)

print('AC' if bl else 'WA')

Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = readline().decode('utf8').rstrip()
lis = list(S)
# print(lis)
if lis[0] == 'A' and 2 <= lis.index('C') <= len(lis) - 1:
    st = ''.join(lis[1:lis.index('C')] + lis[lis.index('C') + 1:])
    # print(st)
    if st.lower():
        print('AC')
    else:
        print('WA')

else:
    print('WA')


Fixed submission:
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = list(readline().decode('utf8').rstrip())
bl = S[0] == 'A'
bl &= ('C' in S[2:-1])

if bl:
    S.remove('A')
    S.remove('C')

bl &= all('a' <= x <= 'z' for x in S)

print('AC' if bl else 'WA')

Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = readline().decode('utf8').rstrip()
lis = list(S)
print(lis)
if lis[0] == 'A' and 2 <= lis.index('C') <= len(lis) - 1:
    st = ''.join(lis[1:lis.index('C')] + lis[lis.index('C') + 1:])
    print(st)
    if st.lower():
        print('AC')
    else:
        print('WA')

else:
    print('WA')


Fixed submission:
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = list(readline().decode('utf8').rstrip())
bl = S[0] == 'A'
bl &= ('C' in S[2:-1])

if bl:
    S.remove('A')
    S.remove('C')

bl &= all('a' <= x <= 'z' for x in S)

print('AC' if bl else 'WA')
Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A, B, K = map(int, readline().split())
se = set(range(A, A + K) | range(B - K + 1, B + 1))
li = list(se)
li = [x for x in li if A << x << B]

li.sort()
print(*li, sep='\n')


Fixed submission:
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A, B, K = map(int, readline().split())
ans=''
if B-A+1 <= 2 * K:
    ans += '\n'.join(str(x) for x in range(A, B + 1))
else:
    ans += '\n'.join(str(x) for x in range(A, A + K))
    ans+='\n'
    ans += '\n'.join(str(x) for x in range(B + 1 - K, B + 1))
print(ans)
Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c, d = map(int, readline().split())
print(min(a, b) + min(c,d))


Fixed submission:
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c, d = map(int, read().split())
print(min(a, b) + min(c,d))

Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c, d = map(int, readline().split())
print(min(a, b) + min(c + d))


Fixed submission:
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c, d = map(int, read().split())
print(min(a, b) + min(c,d))
Buggy python submission (verdict: Runtime Error):
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        int N, A, B, ans = 0;
        cin >> N >> A >> B;
        rep(i, N + 1)
        {
                int t = i, cnt = 0;
                while (t > 0)
                {
                        cnt += t % 10;
                        t /= 10;
                }
                if (A <= cnt && cnt <= B)
                        ans += i;
        }
        cout << ans << endl;

        return 0;
}


Fixed submission:
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, A, B = map(int, readline().split())
ans = 0
for i in range(N + 1):
    s = 0
    t = i
    while t:
        s += t % 10
        t = t // 10

    if A <= s <= B:
        ans += i
print(ans)
Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s, t = readline().decode('utf8').split()
s.sort()
t.sort()
print('Yes' if s < t[::-1] else 'No')


Fixed submission:
"""
author : halo2halo
date : 25,Oct,2019
"""

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

a = readline().rstrip()
b = readline().rstrip()

print("Yes" if ''.join(sorted(a)) < ''.join(sorted(b)[::-1]) else "No")
Buggy python submission (verdict: Time Limit Exceeded):
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def luner(n):
    if n == 0:
        return 2
    if n == 1:
        return 1

    return luner(n - 1) + luner(n - 2)


N = int(readline())
print(luner(N))

Fixed submission:
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

L=[2,1]
for _ in range(90):
    L.append(L[-1]+L[-2])
N = int(readline())
print(L[N])
Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B = read().decode('utf8').split()
print(2*B-A)


Fixed submission:
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B = map(int,read().decode('utf8').split())
print(2*B-A)
Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A,B,C,D = map(int,readline().decode('utf8').rstrip())

print(B-C if B>C else 0)


Fixed submission:
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, C, D = map(int, readline().split())

start = max(A, C)
end = min(B, D)
ans = max(0, end - start)
print(ans)
Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().decode('utf8')


print(S[0]+len(S[1:-1])+S[-1])

Fixed submission:
"""
author : halo2halo
date : 25,Oct,2019
"""

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = readline().rstrip()

print(N[0]+str(len(N)-2)+N[-1])
Buggy python submission (verdict: Runtime Error):
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int, readline().split())
A.sort()
print(A[-1]-A[0])


Fixed submission:
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int, read().split())
A.sort()
print(A[-1]-A[0])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

from functools import reduce
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a

def gcd_list(numbers):
  return reduce(gcd, numbers)

m = 0
for i in range(N):
  if i == 0:
    tmp = A[1:]
  elif i == N-1:
    tmp = A[:N-1]
  else:
    tmp = A[:i] + A[i+1:]
  #print(tmp)
  a = gcd_list(tmp)
  if a > m:
    m = a

print(m)



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

def gcd(a, b):
  while b:
    a, b = b, a % b
  return a

L = []
R = []

for i in range(N-1):
  if i == 0:
    L.append(A[0])
  else:
    L.append(gcd(L[i-1], A[i]))

for i in range(N-1):
  if i == 0:
    R.append(A[N-1])
  else:
    R.append(gcd(R[i-1], A[N-1-i]))

M = []
for i in range(N):
  if i == 0:
    M.append(R[N-2])
  elif i == N-1:
    M.append(L[N-2])
  else:
    M.append(gcd(L[i-1], R[N-2-i]))

print(max(M))
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

for i in range(Q):
  l, r = map(int, input().split())
  tmp = S[l-1:r]
  cnt = 0
  for j in range(len(tmp)-1):
    if tmp[j] == 'A' and tmp[j+1] == 'C':
      cnt += 1
  print(cnt)


Fixed submission:
N, Q = map(int, input().split())
S = input()
f = [0] * N
for i in range(N-1):
  add = 0
  if S[i:i+2] == 'AC':
    add = 1
  if i == 0:
    f[i+1] = add
  else:
    f[i+1] = f[i] + add

#print(f)
for i in range(Q):
  l, r = map(int, input().split())
  print(f[r-1]-f[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

for i in range(Q):
  l, r = map(int, input().split())
  tmp = S[l-1:r]
  print((r - l + 1 - len(tmp.replace('AC', '')))//2)


Fixed submission:
N, Q = map(int, input().split())
S = input()
f = [0] * N
for i in range(N-1):
  add = 0
  if S[i:i+2] == 'AC':
    add = 1
  if i == 0:
    f[i+1] = add
  else:
    f[i+1] = f[i] + add

#print(f)
for i in range(Q):
  l, r = map(int, input().split())
  print(f[r-1]-f[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
L = [list(map(int, input().split())) for i in range(Q)]

for i in range(Q):
  tmp = S[L[i][0]-1:L[i][1]]
  print((len(tmp) - len(tmp.replace('AC', '')))//2)


Fixed submission:
N, Q = map(int, input().split())
S = input()
f = [0] * N
for i in range(N-1):
  add = 0
  if S[i:i+2] == 'AC':
    add = 1
  if i == 0:
    f[i+1] = add
  else:
    f[i+1] = f[i] + add

#print(f)
for i in range(Q):
  l, r = map(int, input().split())
  print(f[r-1]-f[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
b = list(map(int, input().split()))
s = list(set(b))

ans = []

def f(q, i, x):
  cnt = 0
  if i > N:
    if b == q:
      ans.append(x)
    return
  for j in s:
    if j > i:
      continue
    f(q[:j-1] + [j] + q[j-1:], i+1, x + [j])
  return

f([], 1, [])

if len(ans) == 0:
  print(-1)
else:
  for v in ans[0]:
    print(v)

Fixed submission:
import copy
N = int(input())
b = list(map(int, input().split()))
ans = []
while len(b) > 0:
  n = len(b)
  f = False
  for i in range(n):
    if b[n-i-1] == n-i:
      ans.append(b.pop(n-i-1))
      f = True
      break
  if not f:
    print('-1')
    break
  if len(ans) == N:
    ans.reverse()
    for v in ans:
      print(v)
    break

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
b = list(map(int, input().split()))
s = list(set(b))

ans = []

def f(q, i, x):
  cnt = 0
  if i > N:
    if b == q:
      ans.append(x)
    return
  for j in s:
    if j > i:
      continue
    f(q[:j-1] + [j] + q[j-1:], i+1, x + [j])
  return

f([], 1, [])

if len(ans) == 0:
  print(-1)
else:
  for v in ans[0]:
    print(v)

Fixed submission:
import copy
N = int(input())
b = list(map(int, input().split()))
ans = []
while len(b) > 0:
  n = len(b)
  f = False
  for i in range(n):
    if b[n-i-1] == n-i:
      ans.append(b.pop(n-i-1))
      f = True
      break
  if not f:
    print('-1')
    break
  if len(ans) == N:
    ans.reverse()
    for v in ans:
      print(v)
    break
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)

#print(S)

while '01' in S or '10' in S:
  S = S.replace('01', '')
  S = S.replace('10', '')
  #print(S)

print(N - len(S))


Fixed submission:
S = input()
N = len(S)

print(N - abs(S.count('0') - S.count('1')))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)

#print(S)

while '01' in S or '10' in S:
  S = S.replace('01', '')
  S = S.replace('10', '')
  #print(S)

print(N - len(S))


Fixed submission:
S = input()
N = len(S)

print(N - abs(S.count('0') - S.count('1')))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
cnt = 0
while True:
  tmpcnt = 0
  for i in range(N-1):
    #print(S[N-2-i:N-i])
    if S[N-2-i:N-i] == 'BW':
      S = S[:N-2-i] + 'WB' + S[N-i:]
      #print(S)
      cnt += 1
      tmpcnt += 1
  if tmpcnt == 0:
    break
print(cnt)


Fixed submission:
S = input()
N = len(S)
sum = 0
cnt = 0
for i in range(N):
  if S[i] == 'B':
    cnt += 1
  else:
    sum += cnt
print(sum)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
s = [input() for _ in range(H)]
#print(s)

f1 = True
for i in range(H):
  if not f1:
    break
  for j in range(W):
    if not f1:
      break
    if s[i][j] == '.':
      continue
    f = False
    if i >= 1 and s[i-1][j] == '#':
      f = True
    if j <= W-2 and s[i][j+1] == '#':
      f = True
    if i <= H-2 and s[i+1][j] == '#':
      f = True
    if j >= 1 and s[i][j-1] == '#':
      f = True
    if not f:
      f1 = False

#print(s)
if f:
  print('Yes')
else:
  print('No')


Fixed submission:
H, W = map(int, input().split())
s = [input() for _ in range(H)]
#print(s)

f1 = True
for i in range(H):
  if not f1:
    break
  for j in range(W):
    if not f1:
      break
    if s[i][j] == '.':
      continue
    f = False
    if i >= 1 and s[i-1][j] == '#':
      f = True
    if j <= W-2 and s[i][j+1] == '#':
      f = True
    if i <= H-2 and s[i+1][j] == '#':
      f = True
    if j >= 1 and s[i][j-1] == '#':
      f = True
    if not f:
      f1 = False

#print(s)
if f1:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
b = list(set(A))
if len(b) <= K:
  print(0)
else:
  q = []
  for i in range(len(b)):
    q.append(A.count(b[i]))
  q.sort(reverse=True)
  s = 0
  for i in range(K):
    s += q[i]
  print(N-s)


Fixed submission:
import collections
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = collections.Counter(A)
a = list(c.values())
if len(a) <= K:
  print(0)
else:
  a.sort(reverse=True)
  print(N-sum(a[:K]))