Buggy python submission (verdict: Time Limit Exceeded):
DIV = 998244353

N = input()
a = []
for i in range(N):
    a.append(input())
a.sort()
suma = sum(a)
dp = [[0] * (suma+1) for i in range(N)]
dp2 = [[0] * (suma+1) for i in range(N)]
dp[0][0] = 2
dp[0][a[0]] = 1
dp2[0][0] = 1
dp2[0][a[0]] = 1 
allc = 3
flag = 0
if(suma%2 == 0):
	flag = 1
for i in range(1,N/2+1):
	allc = allc*9
	if(i*2 >= N):
		allc = allc/3
		k = a[i*2-1]
		for j in range(suma+1):
			if(j < k):
				dp[i][j] = dp[i-1][j]*2
				dp2[i][j] = dp2[i-1][j]
			else:
				dp[i][j] = dp[i-1][j]*2+dp[i-1][j-k]
				dp2[i][j] = dp2[i-1][j]+dp2[i-1][j-k]
	else:
		k = a[i*2-1]
		l = a[i*2]
		if(k<l):
			k,l = l,k
		for j in range(sum(a[:i*2+1])+1):
			if(j < l):
				dp[i][j] = dp[i-1][j]*4
				if(flag == 1):
					dp2[i][j] = dp2[i-1][j]
			elif(j < k):
				dp[i][j] = dp[i-1][j]*4 + dp[i-1][j-l]*2
				if(flag == 1):
					dp2[i][j] = dp2[i-1][j] + dp2[i-1][j-l]
			elif(j < k+l):
				dp[i][j] = dp[i-1][j]*4 + dp[i-1][j-l]*2 + dp[i-1][j-k]*2
				if(flag == 1):
					dp2[i][j] = dp2[i-1][j] + dp2[i-1][j-l] + dp2[i-1][j-k]
			else:
				dp[i][j] = dp[i-1][j]*4+ dp[i-1][j-l]*2 + dp[i-1][j-k]*2 + dp[i-1][j-k-l]
				if(flag == 1):
					dp2[i][j] = dp2[i-1][j]+ dp2[i-1][j-l] + dp2[i-1][j-k] + dp2[i-1][j-k-l]
allc = allc - sum(dp[N/2][suma-suma/2:])*3
if(flag == 1):			
	allc += dp2[N/2][suma/2]*3
print(allc%DIV)

Fixed submission:
import numpy as np

DIV = 998244353

N = input()
a = []
for i in range(N):
    a.append(input())
a.sort()
suma = sum(a)

dp = np.zeros((N,suma+1,2),dtype = np.int)
dp[0,0,0] = 2
dp[0,a[0],0] = 1
dp[0,0,1] = 1
dp[0,a[0],1] = 1

allc = 3
for i in range(1,N):
	allc = allc*3
	k = a[i]
	dp[i,k:,0] += dp[i-1,:-k,0]
	dp[i,:,0] += dp[i-1,:,0]*2
	dp[i,k:,1] += dp[i-1,:-k,1]
	dp[i,:,1] += dp[i-1,:,1]
	if(i%10 == 0):
		dp[i,:,:] = dp[i,:,:]%DIV
allc = allc - sum(dp[N-1,suma-suma/2:,0])*3
if(suma % 2 == 0):			
	allc += dp[N-1,suma/2,1]*3
print(int(allc%DIV))

Buggy python submission (verdict: Time Limit Exceeded):
DIV = 998244353

N = input()
a = []
for i in range(N):
    a.append(input())
a.sort()
suma = sum(a)
dp = [[0] * (suma+1) for i in range(N)]
dp2 = [[0] * (suma+1) for i in range(N)]
dp[0][0] = 2
dp[0][a[0]] = 1
dp2[0][0] = 1
dp2[0][a[0]] = 1 
allc = 3
flag = 0
if(suma%2 == 0):
	flag = 1
for i in range(1,N):
	allc = allc*3
	k = a[i]
	for j in range(sum(a[:i+1])+1):
		if(j < k):
			dp[i][j] = dp[i-1][j]*2
			if(flag == 1):
				dp2[i][j] = dp2[i-1][j]
		else:
			dp[i][j] = dp[i-1][j]*2+dp[i-1][j-k]
			if(flag == 1):
				dp2[i][j] = dp2[i-1][j]+dp2[i-1][j-k]
allc = allc - sum(dp[N-1][suma-suma/2:])*3
if(flag == 1):			
	allc += dp2[N-1][suma/2]*3
print(allc%DIV)

Fixed submission:
import numpy as np

DIV = 998244353

N = input()
a = []
for i in range(N):
    a.append(input())
a.sort()
suma = sum(a)

dp = np.zeros((N,suma+1,2),dtype = np.int)
dp[0,0,0] = 2
dp[0,a[0],0] = 1
dp[0,0,1] = 1
dp[0,a[0],1] = 1

allc = 3
for i in range(1,N):
	allc = allc*3
	k = a[i]
	dp[i,k:,0] += dp[i-1,:-k,0]
	dp[i,:,0] += dp[i-1,:,0]*2
	dp[i,k:,1] += dp[i-1,:-k,1]
	dp[i,:,1] += dp[i-1,:,1]
	if(i%10 == 0):
		dp[i,:,:] = dp[i,:,:]%DIV
allc = allc - sum(dp[N-1,suma-suma/2:,0])*3
if(suma % 2 == 0):			
	allc += dp[N-1,suma/2,1]*3
print(int(allc%DIV))

Buggy python submission (verdict: Time Limit Exceeded):
DIV = 998244353

N = input()
a = []
for i in range(N):
    a.append(input())
a.sort()
suma = sum(a)
dp = [[0] * (suma+1) for i in range(N)]
dp[0][0] = 2
dp[0][a[0]] = 1
allc = 3
for i in range(1,N):
	allc = allc*3
	k = a[i]
	for j in range(sum(a[:i+1])+1):
		if(j < k):
			dp[i][j] = dp[i-1][j]*2
		else:
			dp[i][j] = dp[i-1][j]*2+dp[i-1][j-k]
allc = allc - sum(dp[N-1][suma-suma/2:])*3
if(suma%2 == 0):
	dp2 = [[0] * (suma+1) for i in range(N)]
	dp2[0][0] = 1
	dp2[0][a[0]] = 1 
	for i in range(1,N):
		k = a[i]
		for j in range(sum(a[:i+1])+1):
			if(j < k):
				dp2[i][j] = dp2[i-1][j]
			else:
				dp2[i][j] = dp2[i-1][j]+dp2[i-1][j-k]
	allc += dp2[N-1][suma/2]*3
print(allc%DIV)

Fixed submission:
import numpy as np

DIV = 998244353

N = input()
a = []
for i in range(N):
    a.append(input())
a.sort()
suma = sum(a)

dp = np.zeros((N,suma+1,2),dtype = np.int)
dp[0,0,0] = 2
dp[0,a[0],0] = 1
dp[0,0,1] = 1
dp[0,a[0],1] = 1

allc = 3
for i in range(1,N):
	allc = allc*3
	k = a[i]
	dp[i,k:,0] += dp[i-1,:-k,0]
	dp[i,:,0] += dp[i-1,:,0]*2
	dp[i,k:,1] += dp[i-1,:-k,1]
	dp[i,:,1] += dp[i-1,:,1]
	if(i%10 == 0):
		dp[i,:,:] = dp[i,:,:]%DIV
allc = allc - sum(dp[N-1,suma-suma/2:,0])*3
if(suma % 2 == 0):			
	allc += dp[N-1,suma/2,1]*3
print(int(allc%DIV))

Buggy python submission (verdict: Time Limit Exceeded):
DIV = 998244353

N = input()
a = []
for i in range(N):
    a.append(input())
count = 0
suma = sum(a)
dp = [[0] * (suma+1) for i in range(N)]
dp[0][0] = 2
dp[0][a[0]] = 1
allc = 3
for i in range(1,N):
	allc = allc*3
	k = a[i]
	for j in range(sum(a[:i+1])+1):
		if(j < k):
			dp[i][j] = dp[i-1][j]*2
		else:
			dp[i][j] = dp[i-1][j]*2+dp[i-1][j-k]
allc = allc - sum(dp[N-1][suma-suma/2:])*3
if(suma%2 == 0):
	dp2 = [[0] * (suma+1) for i in range(N)]
	dp2[0][0] = 1
	dp2[0][a[0]] = 1 
	for i in range(1,N):
		k = a[i]
		for j in range(sum(a[:i+1])+1):
			if(j < k):
				dp2[i][j] = dp2[i-1][j]
			else:
				dp2[i][j] = dp2[i-1][j]+dp2[i-1][j-k]
	allc += dp2[N-1][suma/2]*3
print(allc%DIV)

Fixed submission:
import numpy as np

DIV = 998244353

N = input()
a = []
for i in range(N):
    a.append(input())
a.sort()
suma = sum(a)

dp = np.zeros((N,suma+1,2),dtype = np.int)
dp[0,0,0] = 2
dp[0,a[0],0] = 1
dp[0,0,1] = 1
dp[0,a[0],1] = 1

allc = 3
for i in range(1,N):
	allc = allc*3
	k = a[i]
	dp[i,k:,0] += dp[i-1,:-k,0]
	dp[i,:,0] += dp[i-1,:,0]*2
	dp[i,k:,1] += dp[i-1,:-k,1]
	dp[i,:,1] += dp[i-1,:,1]
	if(i%10 == 0):
		dp[i,:,:] = dp[i,:,:]%DIV
allc = allc - sum(dp[N-1,suma-suma/2:,0])*3
if(suma % 2 == 0):			
	allc += dp[N-1,suma/2,1]*3
print(int(allc%DIV))

Buggy python submission (verdict: Time Limit Exceeded):
def mm(k,s1,s2,s3):
	if(len(k) == 1):
		if(s1 == k[0] or s2 == k[0] or s3 == k[0]):
			return 1
		else:
			return 0
	else:
		t = 0
		if(k[0] <= s1):
			t += mm(k[1:],s1-k[0],s2,s3)
		if(k[0] <= s2):
			t += mm(k[1:],s1,s2-k[0],s3)
		if(k[0] <= s3):
			t += mm(k[1:],s1,s2,s3-k[0])
		return t

N = input()
a = []
for i in range(N):
    a.append(input())
a.sort(reverse=True)
count = 0
suma = sum(a)
for i in range(suma-suma*2/3,suma-(suma/2)):
	for j in range(suma-i-(suma-i)/2,i+1):
		temp = mm(a,i,j,suma-i-j)
		if(i == j or j == suma-i-j):
			if(i == suma-i-j):
				count += temp
			else:
				count += temp*3
		else:
			count += temp*6
print(count)

Fixed submission:
import numpy as np

DIV = 998244353

N = input()
a = []
for i in range(N):
    a.append(input())
a.sort()
suma = sum(a)

dp = np.zeros((N,suma+1,2),dtype = np.int)
dp[0,0,0] = 2
dp[0,a[0],0] = 1
dp[0,0,1] = 1
dp[0,a[0],1] = 1

allc = 3
for i in range(1,N):
	allc = allc*3
	k = a[i]
	dp[i,k:,0] += dp[i-1,:-k,0]
	dp[i,:,0] += dp[i-1,:,0]*2
	dp[i,k:,1] += dp[i-1,:-k,1]
	dp[i,:,1] += dp[i-1,:,1]
	if(i%10 == 0):
		dp[i,:,:] = dp[i,:,:]%DIV
allc = allc - sum(dp[N-1,suma-suma/2:,0])*3
if(suma % 2 == 0):			
	allc += dp[N-1,suma/2,1]*3
print(int(allc%DIV))