Problem:


Score : 100 points

Problem Statement

We will buy a product for N yen (the currency of Japan) at a shop.

If we use only 1000-yen bills to pay the price, how much change will we receive?

Assume we use the minimum number of bills required.

Constraints

1 \leq N \leq 10000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the amount of change as an integer.

Sample Input 1

1900

Sample Output 1

100

We will use two 1000-yen bills to pay the price and receive 100 yen in change.

Sample Input 2

3000

Sample Output 2

0

We can pay the exact price.



Sample input:
1900


Sample output:
100

Submission status: Runtime Error

Solution code:
N = input()
M = int(N)

def cal(a):
	return a%1000

 
if M=1000
  print(0)


print(1000-cal(M))

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    ll n;
    cin>> n;
    if(n%1000==0){cout<<0<<endl; return 0;}
    ll ans = ((n/1000)+1)*1000-n;
    cout<<ans<<endl;
}

Submission status: Runtime Error

Solution code:
n = int(input())
print(n-(n%1000))%1000

Submission status: Runtime Error

Solution code:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 10**9+7
    ans = 1
    s, t = [], []
    for i in range(n):
        if a[i] < 0:
            t.append(a[i])
        else:
            s.append(a[i])

    S, T = len(s), len(t)
    ok = False

    if S > 0:
        if n == k:
            ok = (T % 2 == 0)
        else:
            ok = True
    else:
        ok = (k % 2 == 0)

    if not ok:
        a.sort(key=abs)
        for i in range(k):
            ans *= a[i]
            ans %= mod
    else:
        s.sort()
        t.sort(reverse=True)
        if k % 2 == 1:
            ans *= s.pop()
            ans %= mod
        p = []
        while len(s) >= 2:
            x = s.pop()
            x *= s.pop()
            p.append(x)
        while len(t) >= 2:
            x = t.pop()
            x *= t.pop()
            p.append(x)
        p.sort(reverse=True)
        for i in range(k//2):
            ans *= p[i]
            ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 10**9+7
    ans = 1
    s, t = [], []
    for i in range(n):
        if a[i] < 0:
            t.append(a[i])
        else:
            s.append(a[i])

    S, T = len(s), len(t)
    ok = False

    if S > 0:
        if n == k:
            ok = (T % 2 == 0)
        else:
            ok = True
    else:
        ok = (k % 2 == 0)

    if not ok:
        a.sort(key=abs)
        for i in range(k):
            ans *= a[i]
    else:
        s.sort()
        t.sort(reverse=True)
        if k % 2 == 1:
            ans *= s.pop()
        p = []
        while len(s) >= 2:
            x = s.pop()
            x *= s.pop()
            p.append(x)
        while len(t) >= 2:
            x = t.pop()
            x *= t.pop()
            p.append(x)
        p.sort(reverse=True)
        for i in range(k//2):
            ans *= p[i]
    print(ans % mod)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
ans = math.ceil(n/1000)*1000-n
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = math.ceil(n/1000)-n
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
H,W,K = map(int,input().split())
ll = []
for h in range(H):
    l = []
    for s in input():
        if s == ".":
            l.append(0)
        else:
            l.append(1)
    ll.append(l)
cnt = 0
for bh in range(2 ** H):
    for bw in range(2 ** W):
        nn = np.asarray(ll)
        k = 0
        for h in range(H):
            if (bh & 2 ** h) >> h == 0:
                continue
            nn[h] = np.array([0] * W)
        for w in range(W):
            if (bw & 2 ** w) >> w == 0:
                continue
            nn[:,w] = np.array([0] * W)
        for h in range(H):
            for w in range(W):
                k += nn[h][w]
        if k == K:
            cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())

for i in range(10)+1:
  if n < i * 1000:
    print(i * 1000 - n)
    break

Submission status: Runtime Error

Solution code:
n = input()

for i in range(10)+1:
  if n < i * 1000:
    print(i * 1000 - n)
    break

Submission status: Runtime Error

Solution code:
n = int(input())

d = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}

for _ in range(n):
    s = str(input())
    d[s] += 1

print('AC x {}\nWA x {}\nTLE x {}\nRE x {}\n'.format(d['AC'], d['WA'], d['TLE'], d['RE']))

Submission status: Runtime Error

Solution code:
n = int(input())
print((n//1000+1)*1000-n))

Submission status: Runtime Error

Solution code:
n = int(input())
print(print(0 if n%1000 == 0 else 1000*((n//1000)+1) - n)

Submission status: Runtime Error

Solution code:
_MULTITEST = False
##
def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    neg = sum(1 for x in a if x < 0)
    pos = sum(1 for x in a if x > 0)
    zeroes = a.count(0)
    
    ### Set lower bound for answer
    ans = 0
    if pos == 0:
        if zeroes == 0:
            ans = -1 * (10**16)
    
    ### Solve by window-sliding
    # set some initial vars
    prod = 1
    zero_counter = 0
    for i in range(n-1, n-1-k, -1):
        if a[i] == 0:
            zero_counter += 1
        else:
            prod *= a[i]
    if zero_counter > 0:
        ans = max(ans, 0)
    else:
        ans = max(ans, prod)
    
    # sliding
    p1 = 0
    p2 = (n-k)
    while p2 < n:
        if a[p1] == 0:
            zero_counter += 1
        else:
            prod *= a[p1]
        if a[p2] == 0:
            zero_counter -= 1
        else:
            prod //= a[p2]
        p1 += 1; p2 += 1;
        if zero_counter > 0:
            ans = max(ans, 0)
        else:
            ans = max(ans, prod)
    
    ###
    #print(ans)
    print(ans % (10**9 + 7))


##
if __name__ == "__main__":
    t = (int(input()) if _MULTITEST else 1)
    for tt in range(t):
        solve()

Submission status: Runtime Error

Solution code:
n=int(input())
print((1000-n%1000)%1000))

Submission status: Runtime Error

Solution code:
N = 0
try:
  N = int(input())
except:
  pass
if N == 0:
  print(0)
else:
  print(((N - 1) / 1000) + 1) * 1000 - N)

Submission status: Runtime Error

Solution code:
import sys

N = sys.argv[1]
if N == 0:
  print(0)
else:
  print(((N - 1) / 1000) + 1) * 1000 - N)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,k=map(int, input().split())
c=[list(input().split())  for i in  range(h)]
print(c)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
list_s = []
for i in range(N):
    S = input()
    list_s.append(S)

D = Counter(list_s)

print("AC x " + str(D["AC"]))
print("WA x " + str(D["WA"]))
print("TLE x " + str(D["TLE"]))
print("RE x " + str(D["RE"]))

Submission status: Runtime Error

Solution code:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()

n %= 1000
if n==0:
    print(0)
else:
    print(1000-n)

Submission status: Runtime Error

Solution code:
int = int(input())
y = 1000
for i in range(10):
    z = y*i
    if int <= z:
        o = z - int
        break;
    else:
        pass

print(o)

Submission status: Runtime Error

Solution code:
import sys
x = sys.stdin
y = 1000
for i in range(10):
    z = y*i
    if x <= z:
        o = z -x
        break;
    else:
        pass

print(o)

Submission status: Runtime Error

Solution code:
n = int(input())
rem = n%1000
if rem!=0:
  return 1000-rem
return 0

Submission status: Runtime Error

Solution code:

import numpy as np
import os

def bcount(C):
    u, counts = np.unique(C, return_counts=True)
    return counts[0]


def main():
    H, W, K = map(int,input().split())
    C = []
    form1 = '0'+str(W)+'b'
    form2 = '0'+str(H)+'b'
    h2 = [str(format(i, form2)).split('b')[0] for i in range(2**H)]
    w2 = [str(format(i, form1)).split('b')[0] for i in range(2**W)]
    default_count = 0
    black_count = 0
    for i in range(H):
        C.append(list(map(str, list(input()))))
        default_count += C[i].count("#")
    print(default_count)
    
    if default_count == K:
        print(1)
        os._exit(1)
    elif default_count < K:
        print(0)
        os._exit(1)
    C = np.array(C,dtype = str)

    for i in range(len(h2)):
        co = np.copy(C)
        tmp = list(h2[i])
        for j in range(len(tmp)):
            if(tmp[j] == '1'):
                co[j,:] = "%"
        for k in range(len(w2)):
            co2 = np.copy(co)
            tmp = list(w2[k])
            for j in range(len(tmp)):
                if(tmp[j] == '1'):
                    co2[:,j] = "%"
            if (bcount(co2) == K):
                black_count += 1

    print(black_count)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
print(int(input()[1:]))

Submission status: Runtime Error

Solution code:

t=1
# t=int(input())
for _ in range(t):
    from bisect import bisect_left
    n,k=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    m=bisect_left(a,0)
    MOD=10**9+7
    ans=1
    if m==0 or (m==n and k%2==1):
        for i in a[-k:]:
            ans=(ans*i)%MOD
    elif m==n and k%2==0:
        for i in a[:k]:
            ans=(ans*i)%MOD
    else:
        ans=1
        l,r=0,-1
        lm=a[0]*a[1]
        rm=a[-1]*a[-2]
        for i in range(k//2):
            if lm>=rm:
                ans*=lm%MOD
                l+=2
                if l<=n-2:
                    lm=a[l]*a[l+1]
            else:
                ans*=rm%MOD
                r-=2
                if 1<=n+r:
                    rm=a[r]*a[r-1]
            ans%=MOD
        if k%2==1:
            ans*=a[r]
            ans%=MOD
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
print(1000 - N%1000 if N%1000!=0 else 0)a

Submission status: Runtime Error

Solution code:
# input
N = int(input())
noguchi = [1000 * n for n in range(1, 11)]

# check
print(min([ngc - N for ngc in noguchi if (ngc - N) > 0]))

Submission status: Runtime Error

Solution code:
# input
N = int(input())
noguchi = [1000 * n for n in range(1, 11)]

# check
print(min([ngc - N for ngc in noguchi if (ngc - N) < 0]))

Submission status: Runtime Error

Solution code:
print((1000-input()%1000)%1000)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = N %% 1000
print(ans)

Submission status: Runtime Error

Solution code:
import static org.hamcrest.CoreMatchers.is;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.junit.Assert;
import org.junit.Test;

public class MainTest {

	@Test
	public void 入力例_1() throws Exception {
		String input = 
			"1900";
		String output = 
			"100";

		assertIO(input, output);
	}

	@Test
	public void 入力例_2() throws Exception {
		String input = 
			"3000";
		String output = 
			"0";

		assertIO(input, output);
	}

	private void assertIO(String input, String output) throws Exception {
		ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
		System.setIn(in);

		ByteArrayOutputStream out = new ByteArrayOutputStream();
		System.setOut(new PrintStream(out));

		Main.main(new String[0]);

		Assert.assertThat(out.toString(), is(output + System.lineSeparator()));
	}
}
n=int(input())
print(n)

Submission status: Runtime Error

Solution code:
N = int(input())
print(str(math.ceil(N) - (N)))

Submission status: Runtime Error

Solution code:
print(1000-int(input())%1000)%1000

Submission status: Runtime Error

Solution code:
n = int(input())

i = n//1000
print(min(n%(1000*i), (1000*(i+1))%n))

Submission status: Runtime Error

Solution code:
N=(input())
if int(N[1:])==0:
  print(0)
else:
  print(1000-int(N[1:]))

Submission status: Runtime Error

Solution code:
from collections import deque

N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(key=lambda x:abs(x),reverse=True)
MOD=10**9+7

P=[]
M=[]
for num in A:
    if num>=0:
        P.append(num)
    else:
        M.append(num)
       
#print(P,M)
       
if len(M)==N and K%2==1:
    ans= M[-1]
    for j in range(1,K):
        ans = (ans*M[-1-j])%MOD
       
else:
    Q=deque(P)
    R=deque(M)
    cnt=0
    ans_list=[]

    while cnt<K:

        if Q:
            tmp_p=Q.popleft()
        else:
            tmp_p=0

        if len(R)>=2 and K-cnt>=2:
            x= R.popleft()
            y= R.popleft()
            tmp_q= x*y
        else:
            tmp_q=0

        if tmp_p>=tmp_q:
            ans_list.append(tmp_p)
            if tmp_q>0:
                R.appendleft(y)
                R.appendleft(x)
            cnt +=1
        else:
            ans_list.append(x)
            ans_list.append(y)
            Q.appendleft(tmp_p)
            cnt +=2

    #print(cnt, tmp_p, tmp_q,Q,R,ans_list)
       
    ans=ans_list[0]
    for j in range(1,len(ans_list)):
        ans = (ans*ans_list[j])%MOD
       
       
print(ans)

Submission status: Runtime Error

Solution code:
print(int(int(input() / 1000 + 1) * 1000 - N)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
list = list(map(int,input().split()))
list.sort(reverse=True)
seki = 1
seki1 = 1
seki2 = 1
if list[0] <= 0 and K % 2 != 0:
    for i in range(K):
        seki *= list[i]
elif N == K:
    for i in range(K):
        seki *= list[i]
else:
    for i in range(K):
        seki1 *= list[i]
    list.sort()
    for i in range(K):
        seki2 *= list[i]
    if (seki2 >= seki1) and (seki2 >= 0):
        seki = seki2
    elif (seki2 >= seki1) and (seki2 < 0):
        while seki2 < 0:
            i = 0
            seki2 = seki2 / list[i] * list[K+1+i]
            i += 1
        seki = seki2
    elif (seki1 > seki2) and (seki1 >= 0):
        seki = seki1
    else:
        list.sort(reverse=True)
        while seki1 < 0:
            i=0
            seki1 = seki1 / list[i] * list[K+1+i]
            i += 1
        seki = seki1

print(seki % ((10**9)+7))

Submission status: Runtime Error

Solution code:

#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
 
int main() {
	ios::sync_with_stdio(0); 
	cin.tie(0);
 
ll n;
cin>>n;

n=n%1000;
if(n>0)n=1000-n;
cout<<n;


	
}

Submission status: Runtime Error

Solution code:
print((1000 - int(intput()) % 1000) % 1000)

Submission status: Runtime Error

Solution code:
n = int(input())
change = n%1000
if(change>0):
  	change = (n-change)
    print(change)
else:
  	print(0)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#
# Author: Tetsuya Ishikawa <tiskw111@gmail.com>
# Date  : July 05, 2020
##################################################### SOURCE START #####################################################

import heapq
import collections

class HeapQueue:

    def __init__(self, xs, mode):
        if   mode == "min": self.xs = [+x for x in xs]
        elif mode == "max": self.xs = [-x for x in xs]
        else              : raise NotImplementedError("HeapQueue.__init__: mode should be 'min' or 'max'")
        heapq.heapify(xs)
        self.mode = mode

    def __len__(self):
        return len(self.xs)

    def pop(self):
        if   self.mode == "min": return heapq.heappop(self.xs)
        elif self.mode == "max": return heapq.heappop(self.xs) * (-1)

    def push(self, x):
        if   self.mode == "min": return heapq.heappush(self.xs,  x)
        elif self.mode == "max": return heapq.heappush(self.xs, -x)

    # @staticmethod
    # def __test01__():
    #     xs = HeapQueue([-3, 2, 9, -4], "min")
    #     x0 = xs.pop()
    #     x1 = xs.pop()
    #     x2 = xs.pop()
    #     x3 = xs.pop()
    #     return (x0 == -4 and x1 == -3 and x2 == 2 and x3 == 9)


N, K = tuple(map(int, input().strip().split()))
As = list(map(int, input().strip().split()))

D = int(1E9 + 7)
r = 1

if N == K:

    for a in As:
        r = (r * a) % D

if all(a >= 0 for a in As):

    As = sorted(As, reverse=True)
    for a in As[:K]:
        r = (r * a) % D

elif K % 2 == 1 and all(a < 0 for a in As):

    As = sorted(As, reverse=True)
    for a in As[:K]:
        r = (r * a) % D

elif K % 2 == 0 and all(a < 0 for a in As):

    As = sorted(As)
    for a in As[:K]:
        r = (r * a) % D

else:

    As = sorted(As, key = lambda a: abs(a), reverse=True)

    used = As[:K]
    rest = As[K:]
    num_negative_sign = sum([1 if x < 0 else 0 for x in used])

    if num_negative_sign % 2 != 0:

        used_min_pos = None
        used_min_neg = None
        for k in range(K-1, -1, -1):
            if   used_min_pos is None and used[k] >= 0: used_min_pos = k
            elif used_min_neg is None and used[k] <  0: used_min_neg = k
            if used_min_pos and used_min_neg:
                break

        rest_min_pos = None
        rest_min_neg = None
        for k in range(N-K-1, -1, -1):
            if   rest_min_pos is None and rest[k] >= 0: rest_min_pos = k
            elif rest_min_neg is None and rest[k] <  0: rest_min_neg = k
            if rest_min_pos and rest_min_neg:
                break

        if used_min_pos is None or rest_min_neg is None:
            used[used_min_neg] = rest_min_pos
        elif used_min_neg is None or rest_min_pos is None:
            used[used_min_pos] = rest_min_neg
        else:
            v1 = abs(used[used_min_pos] * rest[rest_min_neg])
            v2 = abs(used[used_min_neg] * rest[rest_min_pos])
            if v1 < v2:
                used[used_min_pos] = rest_min_neg
            else:
                used[used_min_neg] = rest_min_pos

    for a in used:
        r = (r * a) % D

print(r)

##################################################### SOURCE FINISH ####################################################
# vim: expandtab tabstop=4 shiftwidth=4 fdm=marker

Submission status: Runtime Error

Solution code:
if(n%1000):
  print(1000 - n%1000)
else:
  print(0)

Submission status: Runtime Error

Solution code:
n,k = list(map(int, input().split(" ")))
a_lst = list(map(int,input().split(" ")))


plus_lst = list(filter(lambda num: num >= 0 , a_lst))
minus_lst = list(filter(lambda num: num < 0 , a_lst))
plus_lst.sort(reverse=True)
minus_lst.sort(reverse=True)


# +,-どちらもk以上ある
	# max(abs+,abs-)で大きい方をk-1回目までとる, k-1回目で+だったら+, -だったら-
# +: kない, -: kある
	# +の数が残り1になるまでabsでやる,最後に+を使って調整する
# +: kある, -: kない
	# -の数が1になるまでabsでやる, 最後に-を使って調整
# +: kない, -: kない
	# どちらかが残り1になるまでやる,最後に調整
# -のみ
	# absでできるだけ小さいものを使う

# 0を抜いたらk個なかった場合、絶対どっかで0を掛けるので0
# 全部-の場合
if(len(plus_lst) == 0):
	total = 1
	for i in range(k):
		total *=minus_lst[i]
	print(total % (10**9 + 7))
elif(len(minus_lst) == 0):
	total = 1
	for i in range(k):
		total *= plus_lst[i]
	print(total % (10**9 + 7))
else:
	total = 1
	for i in range(k):
		if(i == k - 1):
			if(total > 0):
				total *= plus_lst.pop(0)
			else:
				total *= minus_lst.pop(-1)
		else:
			# plus残り1の場合
			if(len(plus_lst) == 1):
				total *= minus_lst.pop(-1)
			# minus残り1の場合
			elif(len(minus_lst) == 1):
				total += plus_lst.pop(0)					
			# +-どっちも十分あった場合
			else:
				plus_max = plus_lst[0]
				minus_max = minus_lst[0]
				if(abs(plus_max) > abs(minus_max)):
					plus_lst.pop(0)
					total *= plus_max
				else:
					minus_lst.pop(-1)
					total *= minus_max
	print(total % (10**9 + 7))

Submission status: Runtime Error

Solution code:
N = int(input)
p = N%1000
print('p')

Submission status: Runtime Error

Solution code:
a=int(input())
if a%1000=0:
    b=a+1000
else:
    b=(a//1000+1)*1000
	
print(b-a)

Submission status: Runtime Error

Solution code:
import sys
from collections import namedtuple

import numpy as np

sys.setrecursionlimit(10**6)

length = int(sys.stdin.readline())

values = np.array([int(i) for i in sys.stdin.readline().split()], dtype=np.int32)
values = np.sort(values)[::-1]

next_ptr = np.zeros(shape=values.shape, dtype=np.int32)-1
next_ptr[0] = 0

total_score = 0
for index in range(1, len(values)):
  best_index = 0
  best_score = 0
  i = np.where(next_ptr>=0)[0]
  next_i = next_ptr[i]
  values_i = values[i]
  next_values_i = values[next_i]
  scores = np.min([values_i, next_values_i], axis=0)
  best_index = np.argmax(scores)
  
  total_score += scores[best_index]
  
  next_ptr[index] = next_ptr[best_index]
  next_ptr[best_index] = index
  
print(total_score)

Submission status: Runtime Error

Solution code:
import sys
from collections import namedtuple

import numpy as np

length = int(sys.stdin.readline())

values = np.array([int(i) for i in sys.stdin.readline().split()], dtype=np.int32)
values = np.sort(values)[::-1]

next_ptr = np.zeros(shape=values.shape, dtype=np.int32)-1
next_ptr[0] = 0

total_score = 0
for index in range(1, len(values)):
  best_index = 0
  best_score = 0
  i = np.where(next_ptr>=0)[0]
  next_i = next_ptr[i]
  values_i = values[i]
  next_values_i = values[next_i]
  scores = np.min([values_i, next_values_i], axis=0)
  best_index = np.argmax(scores)
  
  total_score += scores[best_index]
  
  next_ptr[index] = next_ptr[best_index]
  next_ptr[best_index] = index
  
print(total_score)

Submission status: Runtime Error

Solution code:
import sys
from collections import namedtuple

import numpy as np

length = int(sys.stdin.readline())

values = np.array([int(i) for i in sys.stdin.readline().split()], dtype=np.int32)
values = np.sort(values)[::-1]

next_ptr = np.zeros(shape=values.shape, dtype=np.int32)-1
next_ptr[0] = 0

total_score = 0
for index in range(1, len(values)):
  #print('----------')
  #print("ADDING {}".format(values[index]))
  best_index = 0
  best_score = 0
  i = np.where(next_ptr>=0)[0]
  next_i = next_ptr[i]
  values_i = values[i]
  next_values_i = values[next_i]
  scores = np.min([values_i, next_values_i], axis=0)
  best_index = np.argmax(scores)
  #print("CHOOSE: {}({})-{}({})-{}({}): {}".format(
  #  values[best_index], 
  #  best_index,
  #  values[index],
  #  index,
  #  values[next_ptr[best_index]], 
  #  next_ptr[best_index],
  #  best_score))
  
  total_score += scores[best_index]
  
  next_ptr[index] = next_ptr[best_index]
  next_ptr[best_index] = index
  
  #print('----- TEST -----')
  #index = 0
  #while True:
  #  print(values[index])
  #  index = next_ptr[index]
  #  if index == 0:
  #    break

#print("ANSWER")
print(total_score)

Submission status: Runtime Error

Solution code:
mod = 10 ** 9 + 7

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(key=lambda x: abs(x), reverse=True)
ans = 1
if N == K:
    for i in range(K):
        ans *= A[i]
        if abs(ans) > mod:
            ans %= mod
elif len([v for v in A if v <= 0]) == N:
    for i in range(K):
        ans *= A[-(i + 1)]
        if abs(ans) > mod:
            ans %= mod
else:
    num_hu = len([v for v in A[:K] if v < 0])
    if num_hu % 2 == 0:
        for i in range(K):
            ans *= A[i]
            if abs(ans) > mod:
                ans %= mod
    else:
        if len([v for v in A[K:] if v >= 0]) == N - K:
            idx = K - 1
            while True:
                if A[idx] < 0:
                    break
                idx -= 1
            for i in range(idx):
                ans *= A[i]
                if abs(ans) > mod:
                    ans %= mod
            ans *= A[K]
            ans %= mod
            for i in range(idx + 1, K):
                ans *= A[i]
                if abs(ans) > mod:
                    ans %= mod
        elif len([v for v in A[K:] if v <= 0]) == N - K:
            idx = K - 1
            while True:
                if A[idx] > 0:
                    break
                idx -= 1
            for i in range(idx):
                ans *= A[i]
                if abs(ans) > mod:
                    ans %= mod
            ans *= A[K]
            ans %= mod
            for i in range(idx + 1, K):
                ans *= A[i]
                if abs(ans) > mod:
                    ans %= mod
        else:
            ans_1 = 1
            ans_2 = 1
            # ans_1
            min_hu_idx = K - 1
            while True:
                if A[min_hu_idx] < 0:
                    break
                min_hu_idx -= 1
            max_sei_idx = K
            while True:
                if A[max_sei_idx] > 0:
                    break
                max_sei_idx += 1
            for i in range(K):
                if i == min_hu_idx:
                    ans_1 *= A[max_sei_idx]
                else:
                    ans_1 *= A[i]
                if abs(ans_1) > mod:
                    ans_1 %= mod
            # ans_2
            min_sei_idx = K - 1
            while True:
                if A[min_sei_idx] > 0:
                    break
                min_sei_idx -= 1
            max_hu_idx = K
            while True:
                if A[max_hu_idx] < 0:
                    break
                max_hu_idx += 1
            for i in range(K):
                if i == min_sei_idx:
                    ans_2 *= A[max_hu_idx]
                else:
                    ans_2 *= A[i]
                if abs(ans_2) > mod:
                    ans_2 %= mod
            ans = max(ans_1, ans_2)
print(ans % mod)

Submission status: Runtime Error

Solution code:
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n=ii1()
arr=iia()
arr.sort(reverse=True)
ans=0
for i in range(1,n):
    ans+=arr[i//2]
print(ans)

Submission status: Runtime Error

Solution code:
# cook your dish here
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007
# print('hi')
n,m,k=iia()
arr=[input()for i in range(n)]
res=0
for i in range(2**n):
    for j in range(2**m):
        ans=0
        for ii in range(n):
            for jj in range(m):
                if i>>ii & 1 and j>>jj &1 and arr[ii][jj]=='#':
                    ans+=1
        if ans==k:
            res+=1
print(res)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;
#define int long long
#define mod 1000000007
signed main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    int i;
    for(i=0;i<n;i++)
        cin >> a[i];
    sort(a, a+n);
    if(a[n-1] < 0)
    {
        int ans = 1;
        for(i=n-1;i>=n-k;i--)
            ans = ans*a[i]%mod;
        cout << (ans+mod)%mod; 
        return 0;
    }
    else
    {
        vector<int> pos,neg;
        int s = 0, e = n-1;
        for(int i=0;i<k;++i){
            if(abs(a[s])>abs(a[e])){
                if(a[s]<0){
                    neg.push_back(a[s]);
                }else{
                    pos.push_back(a[s]);
                }
                ++s;
            }else{
                if(a[e]<0){
                    neg.push_back(a[e]);
                }else{
                    pos.push_back(a[e]);
                }
                --e;
            }
        }
        if(neg.size()&1){
            if(e==n-1){
                //No positive
                neg.pop_back();
                pos.push_back(a[e]);
            }else{
                //Atleast one pos present
                //case remove neg add pos
                int p1=-1;
                if(a[e]>=0){
                    p1=a[e]*a[e+1];
                }
                //case add neg remove pos
                int p2=-1;
                if(a[s]<=0){
                    p2=a[s]*a[s-1];
                }
                if(p1==-1&&p2!=-1){
                    pos.pop_back();
                    neg.push_back(a[s]);
                }else if(p1!=-1&&p2==-1){
                    neg.pop_back();
                    pos.push_back(a[e]);
                }else{
                    if(p1>p2){
                        neg.pop_back();
                        pos.push_back(a[e]);
                    }else{
                        pos.pop_back();
                        neg.push_back(a[s]);
                    }
                }
            }
        }
        int ans=1;
        for(int ele:pos){
            ans=ans*abs(ele)%mod;
        }
        for(int ele:neg){
            ans=ans*abs(ele)%mod;
        }
        cout<<ans<<'\n';
    }
    
    
    
}

Submission status: Runtime Error

Solution code:
s = int(input())
change = s % 1000
if change == 0:
    print(0):
else:
    print(1000-change)

Submission status: Runtime Error

Solution code:
from collections import Counter
li=[]
d={}
t=int(input())
for i in range(t):
    p=input()
    if(p in d):
        d[p]+=1
    else:
        d[p]=1  
if('AC' not in d):
    d['AC']=0
if('WA' not in d):
    d['WA']=0
if('TLE' not in d):
    d['TLE']=0
if('RE' not in d):
    d['RE']=0
print('AC','x',d['AC'] )
print('WA','x',d['WA'])
print('TLE','x',d['TLE'])
print('RE','x',d['RE'])

Submission status: Runtime Error

Solution code:
from collections import Counter
li=[]
d={}
for i in range(int(input())):
    p=input()
    if(p in d):
        d[p]+=1
    else:
    	d[p]=1  
if('AC' not in d):
    d['AC']=0
if('WA' not in d):
    d['WA']=0
if('TLE' not in d):
    d['TLE']=0
if('RE' not in d):
    d['RE']=0
print('AC','x',d['AC'] )
print('WA','x',d['WA'])
print('TLE','x',d['TLE'])
print('RE','x',d['RE'])