TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.  Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.  How many combinations of "on" and "off" states of the switches light all the bulbs?

Submission attempts (in order):
import itertools

def is_lit(i, bit):
    l = [bit[j-1] for j in sockets[i]]
    return p[i] == l.count(True) // 2

count = 0
N, M = map(int, input().split())
bit_list = list(itertools.product([True, False], repeat = N))

sockets = []
for i in range(M):
    args = input().split(' ')
    k = int(args[0])
    sockets.append([int(args[i+1]) for i in range(k)])

p = [int(x) for x in input().split(' ')]

for bit in bit_list:
    o = [is_lit(i, bit) for i in range(M)]
    if o.count(True):
        count += 1

print(count)


import itertools

def is_lit(i, bit):
    l = [bit[j-1] for j in sockets[i]]
    return p[i] == l.count(True) % 2

count = 0
N, M = map(int, input().split())
bit_list = list(itertools.product([True, False], repeat = N))

sockets = []
for i in range(M):
    args = input().split(' ')
    k = int(args[0])
    sockets.append([int(args[i+1]) for i in range(k)])

p = [int(x) for x in input().split(' ')]

for bit in bit_list:
    o = [is_lit(i, bit) for i in range(M)]
    if o.count(True):
        count += 1

print(count)


import itertools

def is_lit(i, bit):
    l = [bit[j-1] for j in sockets[i]]
    return p[i] == l.count(True) % 2

count = 0
N, M = map(int, input().split())
bit_list = list(itertools.product([True, False], repeat = N))

sockets = []
for i in range(M):
    args = input().split(' ')
    k = int(args[0])
    sockets.append([int(args[i+1]) for i in range(k)])

p = [int(x) for x in input().split(' ')]

for bit in bit_list:
    o = [is_lit(i, bit) for i in range(M)]
    if o.count(True) == len(o):
        count += 1

print(count)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.  Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.  How many combinations of "on" and "off" states of the switches light all the bulbs?

Submission attempts (in order):
import itertools
N,M=map(int,input().split())
kslist=[(list(map(int,input().split()))) for i in range(M)]
plist=list(map(int,input().split()))
ls=list((itertools.product(range(2),repeat=N)))
n=0
for tup in ls:
    if [tup[kslist[j][k in range(1,kslist[j][0]+1)]-1]%2 for j in range(M)]==plist:
        n+=1
print(n)     

import itertools
N,M=map(int,input().split())
kslist=[(list(map(int,input().split()))) for i in range(M)]
plist=list(map(int,input().split()))
ls=list((itertools.product(range(2),repeat=N)))
n=0
for tup in ls:
    n+=1
    for j in range(M):
        sum1=0
        for k in range(1,kslist[j][0]+1):
            sum1+=tup[kslist[j][k]-1]
        if sum1%2!=plist[j]:
            n=n-1
            break
print(n)            
    

Verdicts: Runtime Error

Accepted
Problem: We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.  Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.  How many combinations of "on" and "off" states of the switches light all the bulbs?

Submission attempts (in order):
def light(l,i):
    k=1<<i
    if l&k:
        return 1
    else:
        return 0

N, M = map(int,input().split())
s=list()
for j in range(0,M):
    s.append(0)
for j in range(0,M):
    s[j]=list(map(int,input().split()))
p=list(map(int,input().split()))

a=0
for l in range(0,1<<N):
    b=0
    for j in range(0,M):
        c=0
        for i in range(1,s[j][0]+1):
            c+=light(l,s[j][i])
        if c%2==p[j]:
            b+=1
    if b==M:
        a+=1
print(a)
            






def light(l,i):
    k=1<<(i-1)
    if l&k:
        return 1
    else:
        return 0

N, M = map(int,input().split())
s=list()
for j in range(0,M):
    s.append(0)
for j in range(0,M):
    s[j]=list(map(int,input().split()))
p=list(map(int,input().split()))

a=0
for l in range(0,1<<N):
    b=0
    for j in range(0,M):
        c=0
        for i in range(1,s[j][0]+1):
            c+=light(l,s[j][i])
        if c%2==p[j]:
            b+=1
    if b==M:
        a+=1
print(a)

Verdicts: Wrong Answer

Accepted
Problem: We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.  Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.  How many combinations of "on" and "off" states of the switches light all the bulbs?

Submission attempts (in order):
def judgeAllBulbsOn(switchOn, conds, p):
  m = len(conds)
  flag = True
  for i in range(m):
    k = conds[i][0]
    numOfBulbOn = 0
    for i in range(k):
      if switchOn[conds[i][k]] == True:
        numOfBulbOn +=1
    if numOfBulbOn % 2 != p[m]:
      flag = False
      break
  return flag
      

#n:switch, m:bulb
n, m = map(int, input().split())

conds = []
for i in range(m):
  connect = list(map(int, input().split()))
  conds.append(connect)
  
p = list(map(int, input().split()))

switchOn = [False]*n

ans = 0
for bit in range(1<<n):
  for i in range(n):
    if bit & 1<<i == 1:
      switchOn[i] = True
    else:
      switchOn[i] = False
  if judgeAllBulbsOn(switchOn, conds, p):
    ans+=1
print(ans)

def judgeAllBulbsOn(switchOn, conds, p):
    m = len(conds)
    bulbOnFlag = True
    for i in range(m):
        k = conds[i][0]
        numOfSwitchOn = 0
        for j in range(1, k + 1):

            # switchOn is 0 - index
            if switchOn[conds[i][j] - 1] is True:
                numOfSwitchOn += 1
        if numOfSwitchOn % 2 != p[i]:
            bulbOnFlag = False
            break
    return bulbOnFlag


# n:switch, m:bulb
n, m = map(int, input().split())

conds = []
for i in range(m):
    connect = list(map(int, input().split()))
    conds.append(connect)

p = list(map(int, input().split()))

switchOn = [False] * n

ans = 0
for bit in range(1 << n):
    for i in range(n):
        if bit & 1 << i:
            switchOn[i] = True
        else:
            switchOn[i] = False
    if judgeAllBulbsOn(switchOn, conds, p):
        ans += 1
print(ans)


Verdicts: Runtime Error

Accepted
Problem: We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.  Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.  How many combinations of "on" and "off" states of the switches light all the bulbs?

Submission attempts (in order):
N , M = map(int , input().split())
switch = []
bit_switch = []
for _ in range(M):
    switch = list(map(int ,input().split()))
    del switch[0]
    k = 0
    for i in switch:
        k += 1 << (i - 1)
    bit_switch.append(k)
p = list(map(int,input().split()))
cnt = 0
dp = [[] for _ in range(M + 1)]
dp[0] = [i for i in range(2 ** N)]
print(bit_switch)
print(dp)
for i in range(M):
    for j in dp[i]:
        if str(bin(j & bit_switch[i])).count('1')% 2 == p[i]:
            dp[i + 1].append(j)
print(dp)
print(len(dp[M]))

N , M = map(int , input().split())
switch = []
bit_switch = []
for _ in range(M):
    switch = list(map(int ,input().split()))
    del switch[0]
    k = 0
    for i in switch:
        k += 1 << (i - 1)
    bit_switch.append(k)
p = list(map(int,input().split()))
cnt = 0
dp = [[] for _ in range(M + 1)]
dp[0] = [i for i in range(2 ** N)]
#print(bit_switch)
#print(dp)
for i in range(M):
    for j in dp[i]:
        if str(bin(j & bit_switch[i])).count('1')% 2 == p[i]:
            dp[i + 1].append(j)
#print(dp)
print(len(dp[M]))

Verdicts: Wrong Answer

Accepted
Problem: We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.  Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.  How many combinations of "on" and "off" states of the switches light all the bulbs?

Submission attempts (in order):
N,M = map(int,input().split())
target = [[num-1 for num in list(map(int,input().split()))[1:]] for _ in range(M)]

judge = list(map(int,input().split()))

cnt = 0

for i in range(2 ** N):


	switches = [0] * M
	for k in range(M):
	
		for j in range(N):
		
			if ((i >> j) & 1) and j in target[k]:
			
			
			
			
				switches[k] += 1

	switches =	[switch % 2 for switch in switches]
	print(switches)
	
	if switches == judge:
		cnt += 1
		
print(cnt)

N,M = map(int,input().split())
K = [list(map(int,input().split()))[1:] for i in range(M)]
P = list(map(int,input().split()))
ans = 0
for i in range(0,2 ** N):#0 ~ 3:00 ~ 11
  S = [0] * M
  for j in range(M):
    for k in range(N):
      if (i >> k & 1) and k + 1 in K[j]:
        S[j] += 1
  S = [i % 2 for i in S]
  if S == P:
    ans += 1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.  Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.  How many combinations of "on" and "off" states of the switches light all the bulbs?

Submission attempts (in order):
#!/usr/bin/env python

# input
n, m = map(int, input().split())
t = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
k = [t[i][0] for i in range(m)]
s = [t[i][1:] for i in range(m)]

# calc
# bit full search
ans = 0 
for i in range(2**n):
    tmp = i 
    sw = []
    if i == 0:
        sw = [0] 
    while tmp > 0:
        sw.append(tmp&1)
        tmp = tmp>>1
    while len(sw) < n:
        sw.append(0)

    #print('sw =', sw)
    
    # check whether current sw satisfies the condision.
    ok = True
    # light bulb j
    for j in range(m):
        tmp = 0 
        for a in range(k[j]):
            tmp += sw[a+1]
        if tmp%2 != p[j]%2:
            ok = False
            break
    if ok: 
        print('sw =', sw) 
        ans += 1

print(ans)


#!/usr/bin/env python

# input
n, m = map(int, input().split())
t = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
k = [t[i][0] for i in range(m)]
s = [t[i][1:] for i in range(m)]

# calc
# bit full search
ans = 0 
for i in range(2**n):
    tmp = i 
    sw = []
    if i == 0:
        sw = [0] 
    while tmp > 0:
        sw.append(tmp&1)
        tmp = tmp>>1
    while len(sw) < n:
        sw.append(0)

    #print('sw =', sw)
    
    # check whether current sw satisfies the condision.
    ok = True
    # light bulb j
    for j in range(m):
        tmp = 0 
        for a in range(k[j]):
            tmp += sw[a+1]
        if tmp%2 != p[j]%2:
            ok = False
            break
    if ok: 
        # print('sw =', sw)
        ans += 1

print(ans)


#!/usr/bin/env python

# input
n, m = map(int, input().split())
t = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
k = [t[i][0] for i in range(m)]
s = [t[i][1:] for i in range(m)]

# calc
# bit full search
ans = 0 
for i in range(2**n):
    tmp = i 
    sw = []
    if i == 0:
        sw = [0] 
    while tmp > 0:
        sw.append(tmp&1)
        tmp = tmp>>1
    while len(sw) < n:
        sw.append(0)

    #print('sw =', sw)
    
    # check whether current sw satisfies the condision.
    ok = True
    # light bulb j
    for j in range(m):
        tmp = 0 
        for a in range(k[j]):
            tmp += sw[s[j][a]-1]
        if tmp%2 != p[j]:
            ok = False
            break
    if ok: 
        # print('sw =', sw)
        ans += 1

print(ans)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
import itertools
import numpy as np
import copy

def main():
	N, K = map(int,input().split())

	Vs = list(map(int,input().split()))

	allCandidates = []
	for i in range(int(K / 2) + 1):
		for one in range(0, K - i + 1):
			allCandidates.extend([[0] * one + [1] * (K - i - one) + [-1] * i])

	maxScore = 0
	for candidate in allCandidates:
		have = []
		vs = copy.deepcopy(Vs)
		exceptFlag = False
		for k in candidate:
			if k == 0:
				try:
					have.append(vs[0])
					del vs[0]
					zeroCount += 1
				except:
					exceptFlag = True
					break
			if k == 1:
				try:
					have.append(vs[-1])
					del vs[-1]
				except:
					exceptFlag = True
					break
			if k == -1:
				try:
					if have[np.argmin(have)] < 0:
						del have[np.argmin(have)]
				except:
					exceptFlag = True
					break
		if not exceptFlag:
			score = sum(have)
			if score > maxScore:
				maxScore = score
	print(maxScore)

if __name__ == '__main__':
	main()


import itertools
import numpy as np
import copy

def main():
	N, K = map(int,input().split())

	Vs = list(map(int,input().split()))

	allCandidates = []
	for i in range(K + 1):
		for one in range(0, K - i + 1):
			allCandidates.extend([[0] * one + [1] * (K - i - one) + [-1] * i])

	maxScore = 0
	for candidate in allCandidates:
		have = []
		vs = copy.deepcopy(Vs)
		exceptFlag = False
		for k in candidate:
			if k == 0:
				try:
					have.append(vs[0])
					del vs[0]
				except:
					exceptFlag = True
					break
			if k == 1:
				try:
					have.append(vs[-1])
					del vs[-1]
				except:
					exceptFlag = True
					break
			if k == -1:
				try:
					if have[np.argmin(have)] < 0:
						del have[np.argmin(have)]
				except:
					exceptFlag = True
					break
		if not exceptFlag:
			score = sum(have)
			if score > maxScore:
				maxScore = score

	print(maxScore)

if __name__ == '__main__':
	main()


Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
from itertools import islice
 
R = lambda: map(int, input().split())
n, k = R()
v = list(R())
a = sorted((x, i) for i, x in enumerate(v) if x < 0)
ans = max(sum(v[:i - j] + v[n - j:])) -
          sum(islice((x for x, m in a if m < i - j or m >= n - j), k - i))
          for i in range(1, min(n, k) + 1) for j in range(i))
print(ans)


R = lambda: map(int, input().split())
n, k = R()
v = list(R())
ans = 0
for i in range(1, min(n, k) + 1):
    for j in range(i):
        t = v[:i - j] + v[n - j:]
        ans = max(ans, sum(t) - sum(sorted(x for x in t if x < 0)[: k - i]))
print(ans)


Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N, K = map(int, input().split())
V = [int(i) for i in input().split()]
ans = 0
for M in range(K+1):
    for m in range(M+1):
        ls = []
        cur1 = 0
        for i, x in enumerate(V):
            if i < m:
                ls.append(x)
                cur += 1
        cur2 = 0
        for i, x in enumerate(V[::-1]):
            if i < min(M-m, N-cur1):
                ls.append(x)
                cur2 += 1
        ls.sort()
        s = sum(ls)
        for i, x in enumerate(ls):
            if i < K-(cur1+cur2):
                s -= x
        ans = max(ans, s)
print(ans)

N, K = map(int, input().split())
V = [int(i) for i in input().split()]
ans = 0
for M in range(K+1):
    for m in range(M+1):
        ls = []
        for i, x in enumerate(V):
            if i < m:
                ls.append(x)
        for i, x in enumerate(V[::-1]):
            if i < min(M-m, N-m):
                ls.append(x)
        ls.sort()
        s = sum(ls)
        for i, x in enumerate(ls):
            if i < K-M and x < 0:
                s -= x
        ans = max(ans, s)
print(ans)


Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
read = input 
rn = lambda :list(map(int, read().split()))
# O(N^2)
n, k = rn()
V = rn() # 0 ~ n-1
best = 0
for i in range(0, n + 1): # [0, n]
    for j in range(i + 1, n+1): # [i + 1, n]
        # take [0,i), [j, n)
        yes = V[0:i] + V[j: n]
        if len(yes) > k:
            continue
        leftout = k - len(yes)
        yes.sort()
        skip = 0
        for skip in range(len(yes)):
            if yes[skip] <0 and leftout > 0:
                leftout -= 1
            else :
                break
        if best < sum(yes[skip:]):
            best = sum(yes[skip:])
            print(yes[skip:], k, best)
print(best)

read = input 
rn = lambda :list(map(int, read().split()))
# O(N^2)
n, k = rn()
V = rn() # 0 ~ n-1
best = 0
for i in range(0, n + 1): # [0, n]
    for j in range(i, n+1): # [i + 1, n]
        # take [0,i), [j, n)
        yes = V[0:i] + V[j: n]
        if len(yes) > k:
            continue
        leftout = k - len(yes)
        yes.sort()
        skip = 0
        for skip in range(len(yes)):
            if yes[skip] <0 and leftout > 0:
                leftout -= 1
            else :
                break
        if best < sum(yes[skip:]):
            best = sum(yes[skip:])

print(best)

Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N,K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
nums = min(N, K)
for i in range(nums+1): 
    for j in range(nums+1-i): 
        for k in range(nums+1-i-j): 
            L = V[:i]
            R = V[N-j:]
            print(L, R, i, j, k)

            LR = L + R
            LR.sort()
            total = sum(LR)
            idx = 0
            while idx < k and idx < len(LR):
                if LR[idx] < 0:
                    total -= LR[idx]
                    idx += 1
                else:
                    break
            ans = max(ans, total)
            

print(ans)

N, K = map(int, input().split())

V = list(map(int, input().split()))

ans = 0
for l in range(min(N+1,K+1)):
    for r in range(min(N+1,K+1)-l):
        left = V[:min(l, N+1)] 
        right = V[max(0, N-r):] 

        if len(left) + len(right) > N: 
            continue
        else:
            gem = left + right

        gem.sort()

        
        drop = min(K-l-r, len(gem))
        idx = 0
        total = sum(gem)
        while idx < drop:
            if gem[idx] < 0:
                total -= gem[idx]
                idx += 1
            else:
                break
        ans = max(ans, total)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N,K=map(int,input().split())
V=list(map(int,input().split()))
R=min(N,K)
L=[]
for r in range(R+1):
    for A in range(R -r + 1):
        B = R - r-A
        I = sorted((V[:A] + V[::-1][:B]))
        for i in range(len(I)):
            p=K-A-B
            if I[i] >= 0:
                p = i
                break
        for ii in range(min(p,K-A-B)):
            while len(I)>0:
                I.pop(0)
            L.append(sum(I))
print(max(L))








N,K=map(int,input().split())
V=list(map(int,input().split()))
R=min(N,K)
L=[]
for r in range(R+1):
    for A in range(R -r + 1):
        B = R - r-A
        I = sorted((V[:A] + V[::-1][:B]))
        p=K-A-B
        for i in range(len(I)):
            if I[i] >= 0:
                p = i
                break
        for ii in range(min(p,K-A-B)):
            if len(I)>0:
                I.pop(0)
            else:break
        L.append(sum(I))
print(max(L))

Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N,K=map(int,input().split())
V=list(map(int,input().split()))
r,ans=min(N,K),0
for a in range(r+1):
  for b in range(r-a+1):
    tmp,minus=0,[]
    for i in range(a):
      tmp+=V[i]
      if V[i]<0:
        minus.append(V[i])
    for j in range(b):
      tmp+=V[j]
      if V[j]<0:
        minus.append(V[j])
    tmp-=sum(sorted(minus)[:r-(a+b)])
    ans=max(ans,tmp)
print(ans)

N,K=map(int,input().split())
V=list(map(int,input().split()))
r=min(N,K)
ans=0
for i in range(r):
    for j in range(r-i):
        tmp,minus,m=0,[],0
        for ii in range(i):
            a=V[ii]
            tmp+=a
            if a<0:
                minus.append(a)
                m+=1
        for jj in range(j):
            a=V[N-1-jj]
            tmp+=a
            if a<0:
                minus.append(a)
                m+=1
        tmp-=sum(sorted(minus)[:min(r-(i+j),m)])
        ans=max(ans,tmp)

N,K=map(int,input().split())
V=list(map(int,input().split()))
r,ans=min(N,K),0
for a in range(r+1):
  for b in range(r-a+1):
    tmp,minus=0,[]
    for i in range(a):
      tmp+=V[i]
      if V[i]<0:
        minus.append(V[i])
    for j in range(b):
      tmp+=V[N-j-1]
      if V[N-j-1]<0:
        minus.append(V[N-j-1])
    tmp-=sum(sorted(minus)[:K-(a+b)])
    ans=max(ans,tmp)
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
from collections import deque
N, K = map(int,input().split())
V = list(map(int,input().split()))

V = deque(V)

ans = []
for i in range(min(N,K)):
  for j in range(min(N,K)-i):
    Vc = V.copy()
    cal = deque([])
    for k in range(i):
      cal.append(Vc.popleft())
    for l in range(j):
      cal.append(Vc.pop())
    cal = sorted(cal)
    for m in range(K-i-j):
      if cal[0] < 0:
        cal.popleft()
      else:
        break
    ans.append(sum(cal))

print(max(ans))
    



from collections import deque
N, K = map(int,input().split())
V = list(map(int,input().split()))

ans = []
for i in range(min(N,K)+1):
  for j in range(min(N,K)+1-i):
    Vc = deque(V.copy())
    cal = deque([0])
    for k in range(i):
      cal.append(Vc.popleft())
    for l in range(j):
      cal.append(Vc.pop())
    cal = deque(sorted(cal))
    for m in range(K-i-j):
      if cal[0] < 0:
        cal.popleft()
      else:
        break
    ans.append(sum(cal))

print(max(ans))


Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N, K = map(int, input().split())
V = list(map(int, input().split()))



ans = 0
for pop_cnt in range(K + 1):
    enqueue_cnt = K - pop_cnt
    if (pop_cnt > N) or (enqueue_cnt > pop_cnt):
        continue

    for l in range(pop_cnt + 1):
        holding = []

        r = pop_cnt - l
        holding += V[:l]
        holding += V[N - r:]

        holding.sort()
        tmp_ans = sum(holding)

        for e in range(enqueue_cnt + 1):
            if e >= len(holding):
                break

            if holding[e] < 0:
                tmp_ans += -holding[e]

        ans = max(ans, tmp_ans)

print(ans)


N, K = map(int, input().split())
V = list(map(int, input().split()))



ans = 0
for pop_cnt in range(K + 1):
    enqueue_cnt = K - pop_cnt

    if pop_cnt > N:
        continue

    for l in range(pop_cnt + 1):
        holding = []

        r = pop_cnt - l
        holding += V[:l]
        holding += V[N - r:]

        holding.sort()
        tmp_ans = sum(holding)

        for e in range(enqueue_cnt):
            if e >= len(holding):
                break

            if holding[e] < 0:
                tmp_ans += -holding[e]

        ans = max(ans, tmp_ans)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N, K = map(int, input().split())
V = list(map(int, input().split()))

value = 0

for cd in range(K):
    ab = min(N, K-cd)
    for left_ab in range(ab+1):
        right_ab = ab - left_ab
        pick = V[:left_ab] + V[-right_ab:]
        pick.sort()
        neg = 0
        while True:
            if pick[neg]<0:
                neg+=1
                continue
            else:
                break
        v = sum(pick[min(neg,K):])
        value = max(value,v)
        
print(value)

N, K = map(int, input().split())
V = list(map(int, input().split()))
value = 0

for cd in range(K):
    ab = min(N, K-cd)
    for left_ab in range(ab+1):
        right_ab = ab - left_ab
        if right_ab > 0:
            pick = V[:left_ab] + V[-right_ab:]
        else:
            pick = V[:left_ab]
        pick.sort()
        neg = 0
        while neg < len(pick):
            if pick[neg]<0:
                neg+=1
                continue
            else:
                break
        v = sum(pick[min(neg,cd):])
        value = max(value,v)
        
print(value)

Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
N, K = map(int, input().split())
D = [int(x) for x in input().split()]
# S = input()

ans = 0
for l in range(N + 1):
    if l > K:
        break

    for r in range(N - l + 1):
        if l + r > K:
            break

        value_list = D[0 : l] + D[N - r : N]
        sort(value_list)
        
        for i in range(K - (l + r) + 1):
            ans = max(ans, sum(value_list[i:]))
        
print(ans)


# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
N, K = map(int, input().split())
D = [int(x) for x in input().split()]
# S = input()

ans = 0
for l in range(N + 1):
    if l > K:
        break

    for r in range(N - l + 1):
        if l + r > K:
            break

        value_list = D[0 : l] + D[N - r : N]
        value_list.sort()
        
        for i in range(K - (l + r) + 1):
            ans = max(ans, sum(value_list[i:]))
        
print(ans)


Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):



N,K = map(int,input().split())
V = [int(x) for x in input().split()]

max_value = 0 

for L in range(N):
  for R in range(N):
    if L+R > K:
      break
    if L+R > N:
      break
    #get = V[:L] + V[-R:]
    get = V[:L].copy()
    if R > 0:
      get += V[-R:].copy()
    get.sort()
    rest = K - (L+R)
    minus = 0
    for x in get:
      if x < 0:
        minus += 1
    if minus > rest:
      value = sum(get[rest:])
    else:
      value = sum((x for x in get if x > 0))
    if value > max_value:
      max_value = value
    print(L,R,rest,get,value)
      
      
   
print(max_value)
    





N,K = map(int,input().split())
V = [int(x) for x in input().split()]

max_value = 0 

for L in range(N+1):
  for R in range(N+1):
    if L+R > K:
      break
    if L+R > N:
      break
    #get = V[:L] + V[-R:]
    get = V[:L].copy()
    if R > 0:
      get += V[-R:].copy()
    get.sort()
    rest = K - (L+R)
    minus = sum((1 if x < 0 else 0 for x in get))
    if minus > rest:
      value = sum(get[rest:])
    else:
      value = sum((x for x in get if x > 0))
    if value > max_value:
      max_value = value
    print(L,R,rest,get,value)
      
      
   
print(max_value)
    


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

N,K,*V = map(int,read().split())

vals = []
for L in range(N+1):
    for R in range(N+1):
        if L+R > N:
            break
        get = V[:L] + V[N-R:]
        rest = K - (L+R)
        if rest < 0:
            break
        get.sort(reverse=True)
        for _ in range(min(len(get),rest)):
            if get[-1] < 0:
                get.pop()
            else:
                break
        vals.append(sum(get))

answer = max(vals)
print(answer)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N,K=map(int,input().split())
A=list(map(int,input().split()))
ret = 0
for a in range(min(N,K)+1):
  for b in range(min(N,K)-a+1):
    W=A[:a]+A[N-b:]
    W.sort()
    sl=min(sum([1 for i in W if i<0]),K-a-b)
    print(W,W[sl:],a,b,K-a-b)
    ret=max(ret,sum(W[sl:]))
print(ret)

N,K=map(int,input().split())
A=list(map(int,input().split()))
ret = 0
for a in range(N):
  for b in range(N-a+1):
    cmax = K-a-b
    if cmax >= 0:
      W=A[:a]+A[N-b:]
      W.sort()
      tmp=0
      for i in range(len(W)):
        if i<cmax and W[i]<0:
          continue
        else:
          tmp=sum(W[i:])
          break
      ret=max(ret,tmp)
print(ret)

Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(k+1):
  for j in range(k+1):
    if i+j > k or i+j > n:
      continue
    t = k-(i+j)
    s = v[:i] + v[(n-j):]
    s.sort()
    u = 0
    print (s,t)
    while u < t:
      u += 1
      if len(s) < 1:
        break
      if s[0] < 0:
        s.pop(0)
      else:
        break
    ans = max(ans, sum(s))
print (ans)

n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(k+1):
  for j in range(k+1):
    if i+j > k or i+j > n:
      continue
    t = k-(i+j)
    s = v[:i] + v[(n-j):]
    s.sort()
    u = 0
    # print (s,t)
    while u < t:
      u += 1
      if len(s) < 1:
        break
      if s[0] < 0:
        s.pop(0)
      else:
        break
    ans = max(ans, sum(s))
print (ans)

Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = 0
R = min(N,K)
for A in range(R+1):
    for B in range(R-A+1):
        s = V[:A]+V[N-B:]
        print(s)
        s.sort()
        S = sum(s)
        for k in range(min(K-A-B,len(s))):
            if s[k] < 0:
                S -= s[k]
        ans = max(ans,S)
print(ans)


N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = 0
R = min(N,K)
for A in range(R+1):
    for B in range(R-A+1):
        s = V[:A]+V[N-B:]
        #print(s)
        s.sort()
        S = sum(s)
        for k in range(min(K-A-B,len(s))):
            if s[k] < 0:
                S -= s[k]
        ans = max(ans,S)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
n, k = map(int, input().split())
lst = list(map(int, input().split()))

def heap_push(my_lst, a):
    heapq.heappush(my_lst, a)
    return my_lst


def dfs(k, lst, my_lst):
    if k == 0:
        return max(sum(my_lst), 0)
    
    if len(my_lst) == 0:
        a = dfs(k-1, lst[1:], heap_push(my_lst[:], lst[0]))
        b = dfs(k-1, lst[:-1], heap_push(my_lst[:], lst[-1]))
        return max(a, b)
                
    if len(lst) == 0:
        return dfs(k-1, lst + heapq.nsmallest(1,my_lst), my_lst[1:])
                
    else:
        a = dfs(k-1, lst[1:], heap_push(my_lst[:], lst[0]))
        b = dfs(k-1, lst[:-1], heap_push(my_lst[:], lst[-1]))
        
        c = dfs(k-1, lst + heapq.nsmallest(1,my_lst), my_lst[1:])
        d = dfs(k-1, heapq.nsmallest(1,my_lst) + lst, my_lst[1:])
        return max(a,b,c,d)
    
my_lst = []
heapq.heapify(my_lst)
print(dfs(k, lst, []))

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

res = 0
max_num = min(n, k)
for i in range(max_num+1):
    for j in range(max_num+1 - i):
        my_lst = []
        my_lst += lst[:i]
        if j != 0:
            my_lst += lst[-j:]
        
        s = sum(my_lst)
        sorted_my_lst = sorted(my_lst)
        #print('my_lst :', my_lst)
        for l in range(k- i - j):
            if len(my_lst) > l:
                if sorted_my_lst[l] < 0:
                    s -= sorted_my_lst[l]
        res = max(res, s)

print(res)

Verdicts: Runtime Error

Accepted