Problem p02612 (python)

Fixed submission:
N = int(input())

if N % 1000 == 0:
    print(0)
else:
    hasu = N - (N // 1000)*1000
    print(1000-hasu)

Buggy submission (verdict: Runtime Error):
import numpy as np

n, k = map(int,input().split())
a = list(map(int,input().split()))

a = np.array(a)

a_sort_raw = sorted(a)
a_arg_raw = np.argsort(a)

a_abs = list(map(abs,a))
a_abs = np.array(a_abs)

a_sort = sorted(a_abs,reverse=True)

a_arg = np.argsort(-a_abs)

a_arg_k = a_arg[0:k]
a_arg_k_ = a_arg[k:]

a_pow = 1

if all([1 if i < 0 else 0 for i in a]) and (k % 2 != 0):
    for i in range(n-1,k,-1):
        a_pow *= a[a_arg_raw[i]]

else:
    for i in range(k):
        a_pow *= a[a_arg[i]]
    
    if a_pow < 0:
        a_pow_p = 1
        for i in reversed(a_arg_k):
            if a[i] < 0:
                for j in a_arg_k_:
                    if a[j] > 0:
                        a_pow_p = a_pow/a[i]*a[j]
                        break
                break
                
        a_pow_m = 1
        for i in reversed(a_arg_k):
            if a[i] > 0:
                for j in a_arg_k_:
                    if a[j] < 0:
                        a_pow_m = a_pow/a[i]*a[j]
                        break
                break
        if a_pow_p > a_pow_m:
            a_pow = a_pow_p
        else:
            a_pow = a_pow_m

output = a_pow % (10**9 + 7)
print(output)

Buggy submission (verdict: Runtime Error):
import numpy as np

n, k = map(int,input().split())
a = list(map(int,input().split()))

a = np.array(a)

a_abs = list(map(abs,a))
a_abs = np.array(a_abs)

a_sort = sorted(a_abs,reverse=True)

a_arg = np.argsort(-a_abs)

a_arg_k = a_arg[0:k]
a_arg_k_ = a_arg[k:]

a_pow = 1

if all([1 if i < 0 else 0 for i in a]) and (k % 2 != 0):
    for i in range(n-1,k-1,-1):
        a_pow *= a[a_arg[i]]

else:
    for i in range(k):
        a_pow *= a[a_arg[i]]
    
    if a_pow < 0:
        a_pow_p = 1
        for i in reversed(a_arg_k):
            if a[i] < 0:
                for j in a_arg_k_:
                    if a[j] > 0:
                        a_pow_p = a_pow/a[i]*a[j]
                        break
                break
                
        a_pow_m = 1
        for i in reversed(a_arg_k):
            if a[i] > 0:
                for j in a_arg_k_:
                    if a[j] < 0:
                        a_pow_m = a_pow/a[i]*a[j]
                        break
                break
        if a_pow_p > a_pow_m:
            a_pow = a_pow_p
        else:
            a_pow = a_pow_m

output = a_pow % (10**9 + 7)
print(output)

Buggy submission (verdict: Runtime Error):
import numpy as np

n, k = map(int,input().split())
a = list(map(int,input().split()))

a = np.array(a)

a_abs = list(map(abs,a))
a_abs = np.array(a_abs)

a_sort = sorted(a_abs,reverse=True)

a_arg = np.argsort(-a_abs)

a_arg_k = a_arg[0:k]
a_arg_k_ = a_arg[k:]

a_pow = 1

if all([1 if i < 0 else 0 for i in a]) and (k % 2 != 0):
    for i in range(n,k-1,-1):
        a_pow *= a[a_arg[i-1]]

else:
    for i in range(k):
        a_pow *= a[a_arg[i]]
    
    if a_pow < 0:
        a_pow_p = 1
        for i in reversed(a_arg_k):
            if a[i] < 0:
                for j in a_arg_k_:
                    if a[j] > 0:
                        a_pow_p = a_pow/a[i]*a[j]
                        break
                break
                
        a_pow_m = 1
        for i in reversed(a_arg_k):
            if a[i] > 0:
                for j in a_arg_k_:
                    if a[j] < 0:
                        a_pow_m = a_pow/a[i]*a[j]
                        break
                break
        if a_pow_p > a_pow_m:
            a_pow = a_pow_p
        else:
            a_pow = a_pow_m

output = a_pow % (10**9 + 7)
print(output)

Buggy submission (verdict: Runtime Error):
N = int(input())

if N > 1000:
    hasu = N - (N // 1000)*1000
    
print(1000-hasu)

Buggy submission (verdict: Runtime Error):
if N > 1000:
    hasu = N - (N // 1000)*1000
else:
    hasu = N
    
print(1000-hasu)