Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
N, K = input().split()
N = int(N)
K = int(K)
def P(n, r):
  return math.factorial(n)//math.factorial(n-r)
def C(n, r):
  return P(n, r)//math.factorial(r)
for i in range(K):
  ans= (C(K-1,i)*C(N-K+1,i+1))%(10**9+7)
  print(ans)

Fixed submission:
import math
N, K = input().split()
N = int(N)
K = int(K)
def P(n, r):
  return math.factorial(n)//math.factorial(n-r)
def C(n, r):
  return P(n, r)//math.factorial(r)
for i in range(1,K+1):
  if N-K+1<i:
    print(0)
  else:
  	ans= (C(K-1,i-1)*C(N-K+1,i))%(10**9+7)
  	print(ans)

Buggy python submission (verdict: Runtime Error):
import math
N, K = input().split()
N = int(N)
K = int(K)
def P(n, r):
  return math.factorial(n)//math.factorial(n-r)
def C(n, r):
  return P(n, r)//math.factorial(r)
for i in range(K):
  ans= C(K-1,i)*C(N-K+1,i+1)
  print(ans%(10**9+7))

Fixed submission:
import math
N, K = input().split()
N = int(N)
K = int(K)
def P(n, r):
  return math.factorial(n)//math.factorial(n-r)
def C(n, r):
  return P(n, r)//math.factorial(r)
for i in range(1,K+1):
  if N-K+1<i:
    print(0)
  else:
  	ans= (C(K-1,i-1)*C(N-K+1,i))%(10**9+7)
  	print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N=int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

x=np.array(x)
y=np.array(y)
z=np.vstack((x,y))
zz=np.argsort(z[1,:])[::-1]
z=z[:,zz]

left=z[1,0]
flag='Yes'
for i in range(N):
  if min(left,z[1,i])<z[0,i:].sum():
    flag='No'
    break
  else:
    left=z[1,i]-z[0,i]
print(flag)

Fixed submission:
import numpy as np
N=int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

x=np.array(x)
y=np.array(y)
z=np.vstack((x,y))
zz=np.argsort(z[1,:])[::-1]
z=z[:,zz]

left=z[1,0]
flag='Yes'
sumarray=np.cumsum(z[0][::-1])[::-1]
for i in range(N):
  
  if min(left,z[1,i])<sumarray[i]:
    flag='No'
    break
  else:
    left=z[1,i]-z[0,i]
print(flag)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N=int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

x=np.array(x)
y=np.array(y)
z=np.vstack((x,y))
zz=np.argsort(z[1,:])[::-1]
z=z[:,zz]


left=z[1,0]
flag='Yes'
for i in range(N):
  
  if min(left,z[1,i])<sum(z[0,i:]):
    flag='No'

    break
  else:
    left=z[1,i]-z[0,i]
print(flag)

Fixed submission:
import numpy as np
N=int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

x=np.array(x)
y=np.array(y)
z=np.vstack((x,y))
zz=np.argsort(z[1,:])[::-1]
z=z[:,zz]

left=z[1,0]
flag='Yes'
sumarray=np.cumsum(z[0][::-1])[::-1]
for i in range(N):
  
  if min(left,z[1,i])<sumarray[i]:
    flag='No'
    break
  else:
    left=z[1,i]-z[0,i]
print(flag)
Buggy python submission (verdict: Runtime Error):
H,W = map(int, input().split())
a = []
for_at = []
at = []
for i in range(H):
  new_a = str(input())
  for_at.append(list(new_a))
  a.append(new_a)

for i in range(W):
  ai = ''
  for j in range(H):
    ai = ai+for_at[j][i]
  at.append(ai)
tate=0
yoko=0
max_len = '.'*W
max_j = -1
for i in range(W):
  max_len = '.'*(W-i)
  for j in range(H):
    if max_len in a[j]:
      max_j = j
      tate=W-i
      break
  if max_j != -1:
    break


max_len = '.'*W
max_j = -1
for i in range(W):
  max_len = '.'*(W-i)
  for j in range(H):
    if max_len in at[j]:
      max_j = j
      yoko=W-i
      break
  if max_j != -1:
    break
print(tate+yoko-1)

Fixed submission:
a=[int(x) for x in input().split()]
min_h = min([a[0]+a[1],a[1]+a[2],a[2]+a[0]])

print(min_h)
Buggy python submission (verdict: Runtime Error):
A,B = input().split()
if B%A == 0:
  print(A + B)
else:
  print(A - B)

Fixed submission:
A, B = (int(i) for i in input().split())  
if B%A == 0:
  print(A + B)
else:
  print(B - A)
Buggy python submission (verdict: Runtime Error):
N = int(input())
h = [i for i in map(int, input().split())]

def dp(i):
    if i==0:
        return 0
    elif i==1:
        return abs(h[1]-h[0])
    else:
        return min(dp(i-1)+abs(h[i]-h[i-1]), dp(i-2)+abs(h[i]-h[i-2]))

print(dp(N-1))

Fixed submission:
N = int(input())
h = [i for i in map(int, input().split())]

dp = [0]*N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(N-2):
    dp[i+2] = min(dp[i]+abs(h[i+2]-h[i]), dp[i+1]+abs(h[i+2]-h[i+1]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*N
for i in range(1,N):
    start = max(0,i-K)
    dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(start,i)])
print(dp[-1])

Fixed submission:
def calc_dp():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [0]*N
    for i in range(1,N):
        start = max(0,i-K)
        dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(start,i)])
    print(dp[-1])

if __name__ == "__main__":
    calc_dp()

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [i for i in map(int, input().split())]

dp = [0]*N
for i in range(1,N):
    start = max(0,i-K)
    dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(start,i)])
print(dp[-1])

Fixed submission:
def calc_dp():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [0]*N
    for i in range(1,N):
        start = max(0,i-K)
        dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(start,i)])
    print(dp[-1])

if __name__ == "__main__":
    calc_dp()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, W = map(int, input().split())
wv = []
for i in range(N):
    w, v = map(int, input().split())
    wv.append([w,v])

#i番目までを使ってjの重さで入れたときの価値の最大値を記録する
dp = np.zeros((N+1,W+1))
for j in range(1,W+1):
    for i in range(1,N+1):
        if j < wv[i-1][0]:
            dp[i,j] = dp[i-1,j]
        else:
            dp[i,j] = max(dp[i-1,j-wv[i-1][0]] + wv[i-1][1], dp[i-1,j])
print(int(dp[-1][-1]))

Fixed submission:
import numpy as np

N, W = map(int, input().split())
wv = []
#i番目までを詰めたときの最大の価値を記録
dp = np.zeros(W+1)
for i in range(N):
    w, v = map(int, input().split())
    dp[w:] = np.maximum(dp[:-w]+v, dp[w:])

print(int(dp[-1]))
Buggy python submission (verdict: Runtime Error):
s = str(input())
s_list = []
for i in range(len(s)):
  s_list.append(s[i])

#print(s_list)
L = len(s_list)

sum_a = 0
for k in range(2**(L-1)):
  plus_list = [0]*(L-1)
  p = list(bin(k)[2:])
  for l in range(len(p)):
    plus_list[L-len(p)+l-1] = int(p[l])
  
  #print("p_list:",plus_list)
  #print("p:",p)
  num_list = []
  start = 0
  for i in range(len(plus_list)):
    if plus_list[i]:
      num_list.append(s_list[start:i+1])
      start = i+1
  num_list.append(s_list[start:])
  ans = 0
  for i in num_list:
    s = ''
    for j in i:
      s = s+j
    ans += int(s)
  sum_a += ans
  #print("num_list:",num_list)
  #print("ans:",ans)
print(sum_a)

Fixed submission:
s = str(input())
s_list = []
for i in range(len(s)):
  s_list.append(s[i])

#print(s_list)
L = len(s_list)

sum_a = 0
if L == 1:
  print(int(s))
else:
  for k in range(2**(L-1)):
    plus_list = [0]*(L-1)
    p = list(bin(k)[2:])
    for l in range(len(p)):
      plus_list[L-len(p)+l-1] = int(p[l])

    #print("p_list:",plus_list)
    #print("p:",p)
    num_list = []
    start = 0
    for i in range(len(plus_list)):
      if plus_list[i]:
        num_list.append(s_list[start:i+1])
        start = i+1
    num_list.append(s_list[start:])
    ans = 0
    for i in num_list:
      s = ''
      for j in i:
        s = s+j
      ans += int(s)
    sum_a += ans
    #print("num_list:",num_list)
    #print("ans:",ans)
  print(sum_a)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque as dq
L=dq(list(input()))
for _ in range(int(input())):
    S=input().split()
    if S == ['1']:
        L.reverse()
    else:
        if S[1]=='1':
        	L.appendleft(S[2])
        else:
        	L.append(S[2])
print(''.join(L))
          
          

Fixed submission:
import os
import sys
from io import BytesIO, IOBase
from collections import deque as dq

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##############################################################################
from collections import deque as dq
L=dq(list(input()))
C=0
for _ in range(int(input())):
    S=input().split()
    if S == ['1']:
        C+=1
    elif C%2==0:
        if S[1]=='1':
        	L.appendleft(S[2])
        else:
        	L.append(S[2])
    elif C%2!=0:
        if S[1]=='1':
        	L.append(S[2])
        else:
        	L.appendleft(S[2])
if C%2!=0:
    L.reverse()
print(''.join(L))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n, m = [int(x) for x in input().rstrip().split()]
a = [int(x)//2 for x in input().rstrip().split()]
a = list(set(a))

def find_gcd(a, b):
    if b == 0:
        return a
    return find_gcd(b, a % b)


gcd = a[0]
product = 1
for x in a:
    gcd = find_gcd(gcd, x)
    product *= x

lcm = product // gcd

for x in a:
    if (lcm // x) % 2 == 0:
        print(0)
        sys.exit(0)

print((m // lcm + 1) // 2)


Fixed submission:
import sys
input = sys.stdin.readline

k, x = [int(x) for x in input().rstrip().split()]
print('Yes' if k * 500 >= x else 'No')
Buggy python submission (verdict: Runtime Error):
import sys
import math
input = sys.stdin.readline

n, m = [int(x) for x in input().rstrip().split()]
a = [int(x)//2 for x in input().rstrip().split()]
a = list(set(a))

gcd = a[0]
product = 1
for x in a:
    gcd = math.gcd(gcd, x)
    product *= x

lcm = product // gcd

for x in a:
    if (lcm // x) % 2 == 0:
        print(0)
        sys.exit(0)

print((m // lcm + 1) // 2)

Fixed submission:
import sys
import fractions
from functools import reduce
input = sys.stdin.readline
n, m = [int(x) for x in input().strip().split()]
a = [int(x)//2 for x in input().strip().split()]
a = list(set(a))

def lcm_base(x, y): return x * y // fractions.gcd(x, y)
lcm = reduce(lcm_base, a, 1)


for x in a:
    if (lcm // x) % 2 == 0:
        print(0)
        break
else:
    print((m // lcm + 1) // 2)

Buggy python submission (verdict: Runtime Error):
import sys
import math
input = sys.stdin.readline

n, m = [int(x) for x in input().rstrip().split()]
a = [int(x)//2 for x in input().rstrip().split()]
a = list(dict.fromkeys(a))

gcd = a[0]
product = 1
for x in a:
    gcd = math.gcd(gcd, x)
    product *= x

lcm = product // gcd

for x in a:
    if (lcm // x) % 2 == 0:
        print(0)
        sys.exit(0)

print((m // lcm + 1) // 2)


Fixed submission:
import sys
import fractions
from functools import reduce
input = sys.stdin.readline
n, m = [int(x) for x in input().strip().split()]
a = [int(x)//2 for x in input().strip().split()]
a = list(set(a))

def lcm_base(x, y): return x * y // fractions.gcd(x, y)
lcm = reduce(lcm_base, a, 1)


for x in a:
    if (lcm // x) % 2 == 0:
        print(0)
        break
else:
    print((m // lcm + 1) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
# pylint: disable=invalid-name
# pylint: disable=missing-docstring


def main():
    N, K = map(int, input().split())
    H = [0] + [int(x) for x in input().split()]
    DP = [[-1 for _ in range(K + 1)] for _ in range(N + 1)]
    DP[0] = [0 for _ in range(K + 1)]
    for i in range(1, N + 1):
        for j in range(K + 1):
            for k in range(max(i - j - 1, 0), i):
                previous = DP[k][j - (i - k - 1)]
                if previous == -1:
                    continue

                if DP[i][j] == -1 or previous + max(H[i] - H[k], 0) < DP[i][j]:
                    DP[i][j] = previous + max(H[i] - H[k], 0)

                if j > 0 and DP[i][j - 1] != -1 and DP[i][j - 1] < DP[i][j]:
                    DP[i][j] = DP[i][j - 1]
                # print('i {} j {} k {} j - (i - k - 1) {} DP_targ {} DP {}'.
                #       format(i, j, k, j - (i - k - 1),
                #              previous + max(H[i] - H[k], 0), DP[i][j]))
    ans = -1
    for i in range(N + 1):
        if K < (N - i):
            continue
        if ans == -1 or DP[i][min(K - (N - i), K)] < ans:
            ans = DP[i][min(K - (N - i), K)]
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
# pylint: disable=invalid-name
# pylint: disable=missing-docstring


def main():
    N, K = map(int, input().split())
    H = [0] + [int(x) for x in input().split()]
    DP = [[-1 for _ in range(K + 1)] for _ in range(N + 1)]
    DP[0] = [0 for _ in range(K + 1)]
    for i in range(1, N + 1):
        for j in range(K + 1):
            for k in range(max(i - j - 1, 0), i):
                previous = DP[k][j - (i - k - 1)]
                if previous == -1:
                    continue

                if DP[i][j] == -1 or previous + max(H[i] - H[k], 0) < DP[i][j]:
                    DP[i][j] = previous + max(H[i] - H[k], 0)

                if j > 0 and DP[i][j - 1] != -1 and DP[i][j - 1] < DP[i][j]:
                    DP[i][j] = DP[i][j - 1]
                # print('i {} j {} k {} j - (i - k - 1) {} DP_targ {} DP {}'.
                #       format(i, j, k, j - (i - k - 1),
                #              previous + max(H[i] - H[k], 0), DP[i][j]))
    ans = -1
    for i in range(N + 1):
        if K < (N - i):
            continue
        if ans == -1 or DP[i][min(K - (N - i), K)] < ans:
            ans = DP[i][min(K - (N - i), K)]
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

Q = int(input())

for _ in range(Q):
    op = input().split()
    if len(op) == 1:
        S = S[::-1]
    else:
        if op[1] == '1':
            S = op[2] + S
        else:
            S = S + op[2]
print(S)


Fixed submission:
import collections

S = input()

Q = int(input())

list1 = collections.deque()
list2 = []
flag = 1

for _ in range(Q):
    op = input().split()
    if len(op) == 1:
        flag *= -1
    else:
        if flag == 1:
            if op[1] == '1':
                list1.appendleft(op[2])
            else:
                list2.append(op[2])
        else:
            if op[1] == '1':
                list2.append(op[2])
            else:
                list1.appendleft(op[2])

if flag == 1:
    print("".join(list1) + S + "".join(list2))
else:
    print(("".join(list1) + S + "".join(list2))[::-1])
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict
import math

N = int(input())
H = defaultdict(int)

for i in range(N):
    s = "".join(sorted(input()))
    H[s] += 1

ret = 0
for v in H.values():
    ret += math.factorial(v) // (math.factorial(v - 2) * math.factorial(2))
print(ret)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict
import math

N = int(input())
H = defaultdict(int)

for i in range(N):
    s = "".join(sorted(input()))
    H[s] += 1

ret = 0
for v in H.values():
    if v >= 2:
        ret += math.factorial(v) // (math.factorial(v - 2) * math.factorial(2))
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict
from itertools import combinations

N = int(input())
H = defaultdict(list)

for i in range(N):
    s = "".join(sorted(input()))
    H[s].append(i)

ret = 0
for v in H.values():
    ret += len(list(combinations(v, 2)))
print(ret)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict
import math

N = int(input())
H = defaultdict(int)

for i in range(N):
    s = "".join(sorted(input()))
    H[s] += 1

ret = 0
for v in H.values():
    if v >= 2:
        ret += math.factorial(v) // (math.factorial(v - 2) * math.factorial(2))
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict
from itertools import combinations

N = int(input())
H = defaultdict(list)

for i in range(N):
    s = "".join(sorted(input()))
    H[s].append(i)

ret = 0
for v in H.values():
    ret += len(list(combinations(v, 2)))
print(ret)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict
import math

N = int(input())
H = defaultdict(int)

for i in range(N):
    s = "".join(sorted(input()))
    H[s] += 1

ret = 0
for v in H.values():
    if v >= 2:
        ret += math.factorial(v) // (math.factorial(v - 2) * math.factorial(2))
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, nlargest

def main():
    X, Y, Z, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    h = []
    for i in A:
        for j in B:
            for k in C:
                heappush(h, i + j + k)
    for i in nlargest(K, h):
        print(i)


if __name__ == "__main__":
    main()

Fixed submission:
from heapq import heappush, nlargest

def main():
    X, Y, Z, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    h = []
    for i in A:
        for j in B:
            heappush(h, i + j)
    H = []
    for i in nlargest(K, h):
        for j in C:
            heappush(H, i+j)
    for i in nlargest(K, H):
        print(i)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    S = [int(s) for s in list(input())]
    K = int(input())
    for i in S:
        if i != 1:
            print(i)
            break


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    A, B = map(int, input().split())
    print(A*B-(A+B)+1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

s = set()
acc = 0
for i in range(1, 1000):
    acc += i
    s.add(acc)

for i in range(1, 4995001):
    if (a + i) in s and (b + i) in s:
        print(i)

Fixed submission:
N = int(input())

if N <= 999:
    print("ABC")
else:
    print("ABD")
Buggy python submission (verdict: Runtime Error):
print(input().replace(",", " ")

Fixed submission:
def main():
    print(input().replace(",", " "))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]

day_to_cost = {}
for a, b in AB:
    if day_to_cost.get(a) is None:
        day_to_cost[a] = [b]
    else:
        day_to_cost[a].append(b)

ans = 0
candidate = []
for i in range(1, M+1):
    candidate += day_to_cost.get(i, [])
    if candidate:
        work_cost = max(candidate)
        candidate.remove(work_cost)
        ans += work_cost


print(ans)


Fixed submission:
import heapq as pq

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]

day_to_reward = {}
for a, b in AB:
    if day_to_reward.get(a) is None:
        day_to_reward[a] = [b]
    else:
        day_to_reward[a].append(b)

ans = 0
candidate = []
for i in range(1, M+1):
    for reward in day_to_reward.get(i, []):
        pq.heappush(candidate, - reward)
    if candidate:
        work_reward = - pq.heappop(candidate)
        ans += work_reward


print(ans)
Buggy python submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())

lcm_cd = C * D // math.gcd(C, D)

under_c = (A - 1) // C
under_d = (A - 1) // D
under_cd = (A - 1) // lcm_cd

top_c = B // C
top_d = B // D
top_cd = B // lcm_cd

ans = (B -
       (A - 1)) - (top_c - under_c) - (top_d - under_d) + (top_cd - under_cd)

print(ans)


Fixed submission:
import fractions
A, B, C, D = map(int, input().split())

lcm_cd = C * D // fractions.gcd(C, D)

under_c = (A - 1) // C
under_d = (A - 1) // D
under_cd = (A - 1) // lcm_cd

top_c = B // C
top_d = B // D
top_cd = B // lcm_cd

ans = (B -
       (A - 1)) - (top_c - under_c) - (top_d - under_d) + (top_cd - under_cd)

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter as c
N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
XY.sort(key=lambda xy: xy[0])

inclination = []
for i in range(1, N):
    inclination.append((XY[i][0] - XY[i-1][0], XY[i][1] - XY[i-1][1]))

ans = N - sorted(list(c(inclination).items()), key=lambda x: x[1])[-1][1]
print(ans)

Fixed submission:
from collections import Counter as c
N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
XY.sort(key=lambda xy: (xy[0], xy[1]))
if N == 1 or N == 2:
    print(1)
    exit()

inclination = []
for i in range(0, N-1):
    for j in range(i+1, N):
        inclination.append((XY[j][0] - XY[i][0], XY[j][1] - XY[i][1]))

print(N - sorted(list(c(inclination).items()), key=lambda x: x[1])[-1][1])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

cnt = 0
while True:
    updated = S.replace('ABC', 'BCA', 1)
    if updated == S:
        print(cnt)
        break
    cnt += 1
    S = updated


Fixed submission:
S = input().replace('BC', '*')

a = 0
cnt = 0
for s in S:
    if s != 'A' and s != '*':
        a = 0
    elif s == 'A':
        a += 1
    elif s == '*':
        cnt += a

print(cnt)