Problem p03557 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while high - low > 1:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while high - low > 1:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        else:
            high = mid2
    mid2 = high
    total += mid1 * (N + 1 - mid2)

print(total)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1 + 1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2 + 1
        else:
            high = mid2
    mid2 = high
    total = total + mid1 * (N - mid2)

print(total)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    ans += bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    ans += bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
#A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
#C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        else:
            high = mid2
    mid2 = high
    total = total + mid1 * (N + 1 - mid2)

print(total)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
#A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
#C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        if A[mid1] >= B[i]:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        if C[mid2] > B[i]:
            high = mid2
    mid2 = high
    total = total + (mid1 + 1) * (N - mid2)

print(total)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        if A[mid1] >= B[i]:
            high = mid1
    mid1 = low
    low = -1
    high = N
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        if C[mid2] > B[i]:
            high = mid2
    mid2 = high
    total = total + (mid1 + 1) * (N - mid2)

print(total)