Buggy python submission (verdict: Time Limit Exceeded):
import array
N = int(input())
a = [int(input()) for _ in range(N)]
s = sum(a)
m = (s + 1) // 2

c10 = [0] * (m + 1)
c1 = array.array('l', c10)
c1[m] = 1
for i in range(N):
    d = a[i]
    for j in range(m - d + 1):
        c1[j] = (2 * c1[j] + c1[j + d]) % 998244353
    for j in range(m - d + 1, m + 1):
        c1[j] = (2 * c1[j] + c1[m]) % 998244353

ans1 = c1[0]

if s % 2:
    c1[0] = 0
else:
    for j in range(m):
        c1[j] = 0
    c1[m] = 1
    for i in range(N):
        d = a[i]
        for j in range(m - d + 1):
            c1[j] = (c1[j] + c1[j + d]) % 998244353
        for j in range(m - d + 1, m + 1):
            c1[j] = c1[j]

ans = (3 ** N % 998244353 - 3 * ans1 + 3 * c1[0]) % 998244353
print(ans)

Fixed submission:
import numpy as np

N = int(input())
a = sorted([int(input()) for _ in range(N)])

s = sum(a)
m = (s + 1) // 2
m1 = m + 1


def func():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (2 * ab[i, :-c] + ab[i, c:]) % 998244353
        ab[i + 1, -c:] = (2 * ab[i, -c:] + ab[i, m]) % 998244353
    return ab[N, 0]


def func1():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (ab[i, :-c] + ab[i, c:]) % 998244353 
        ab[i + 1, -c:] = ab[i, -c:]
    return ab[N, 0]


ans = 3 ** N % 998244353 - 3 * func()
if s % 2 == 0:
     ans += 3 * func1()
print(ans % 998244353)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(input()) for _ in range(N)]
s = sum(a)
m = (s + 1) // 2

c1 = [0] * (m + 1)
c1[m] = 1
for i in range(N):
    d = a[i]
    for j in range(m - d + 1):
        c1[j] = (2 * c1[j] + c1[j + d]) % 998244353
    for j in range(m - d + 1, m + 1):
        c1[j] = (2 * c1[j] + c1[m]) % 998244353

ans1 = c1[0]

if s % 2:
    c1[0] = 0
else:
    for j in range(m):
        c1[j] = 0
    c1[m] = 1
    for i in range(N):
        d = a[i]
        for j in range(m - d + 1):
            c1[j] = (c1[j] + c1[j + d]) % 998244353
        for j in range(m - d + 1, m + 1):
            c1[j] = c1[j]

ans = (3 ** N % 998244353 - 3 * ans1 + 3 * c1[0]) % 998244353
print(ans)

Fixed submission:
import numpy as np

N = int(input())
a = sorted([int(input()) for _ in range(N)])

s = sum(a)
m = (s + 1) // 2
m1 = m + 1


def func():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (2 * ab[i, :-c] + ab[i, c:]) % 998244353
        ab[i + 1, -c:] = (2 * ab[i, -c:] + ab[i, m]) % 998244353
    return ab[N, 0]


def func1():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (ab[i, :-c] + ab[i, c:]) % 998244353 
        ab[i + 1, -c:] = ab[i, -c:]
    return ab[N, 0]


ans = 3 ** N % 998244353 - 3 * func()
if s % 2 == 0:
     ans += 3 * func1()
print(ans % 998244353)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(input()) for _ in range(N)]
s = sum(a)
m = (s + 1) // 2
m1 = m + 1

ab = [[-1] * m1 for _ in range(N + 1)]
for j in range(m):
    ab[N][j] = 0
ab[N][m] = 1
for j in range(N - 1, 0, -1):
    ab[j][m] = (3 * ab[j + 1][m]) % 998244353


def func(n, r):
    if r >= m:
        return ab[n][m]
    else:
        if ab[n][r] > -1:
            return ab[n][r]
        else:
            ret = (func(n + 1, r + a[n]) + 2 * func(n + 1, r)) % 998244353
            ab[n][r] = ret
            return ret


def func1(n, r):
    if n == N - 1:
        if r + a[n] == m:
            return 1
        else:
            return 0
    elif r + a[n] > m:
        return func1(n + 1, r)
    elif r + a[n] == m:
        return 1 + func1(n + 1, r)
    else:
        return (func1(n + 1, r + a[n]) + func1(n + 1, r)) % 998244353


ans1 = func(0, 0)
ans = 3 ** N % 998244353 - 3 * ans1
if s % 2 == 0:
    ans2 = func1(0, 0)
    ans += 3 * ans2

print(ans % 998244353)

Fixed submission:
import numpy as np

N = int(input())
a = sorted([int(input()) for _ in range(N)])

s = sum(a)
m = (s + 1) // 2
m1 = m + 1


def func():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (2 * ab[i, :-c] + ab[i, c:]) % 998244353
        ab[i + 1, -c:] = (2 * ab[i, -c:] + ab[i, m]) % 998244353
    return ab[N, 0]


def func1():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (ab[i, :-c] + ab[i, c:]) % 998244353 
        ab[i + 1, -c:] = ab[i, -c:]
    return ab[N, 0]


ans = 3 ** N % 998244353 - 3 * func()
if s % 2 == 0:
     ans += 3 * func1()
print(ans % 998244353)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = sorted([int(input()) for _ in range(N)], reverse=True)

s = sum(a)
m = (s + 1) // 2
m1 = m + 1

ab = [[-1] * m1 for _ in range(N)]
ab.append([0] * m1)
ab[N][m] = 1
for j in range(N -1, 0, -1):
    ab[j][m] = (3 * ab[j + 1][m]) % 998244353


def func(n, r):
    if r >= m:
        return ab[n][m]
    else:
        if ab[n][r] > -1:
            return ab[n][r]
        else:
            ret = (func(n + 1, r + a[n]) + 2 * func(n + 1, r)) % 998244353
            ab[n][r] = ret
            return ret


def func1(n, r):
    if n == N - 1:
        if r + a[n] == m:
            return 1
        else:
            return 0
    elif r + a[n] > m:
        return func1(n + 1, r)
    elif r + a[n] == m:
        return 1 + func1(n + 1, r)
    else:
        return (func1(n + 1, r + a[n]) + func1(n + 1, r)) % 998244353


ans1 = func(0, 0)
ans = 3 ** N % 998244353 - 3 * ans1
if s % 2 == 0:
    ans2 = func1(0, 0)
    ans += 3 * ans2

print(ans % 998244353)


Fixed submission:
import numpy as np

N = int(input())
a = sorted([int(input()) for _ in range(N)])

s = sum(a)
m = (s + 1) // 2
m1 = m + 1


def func():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (2 * ab[i, :-c] + ab[i, c:]) % 998244353
        ab[i + 1, -c:] = (2 * ab[i, -c:] + ab[i, m]) % 998244353
    return ab[N, 0]


def func1():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (ab[i, :-c] + ab[i, c:]) % 998244353 
        ab[i + 1, -c:] = ab[i, -c:]
    return ab[N, 0]


ans = 3 ** N % 998244353 - 3 * func()
if s % 2 == 0:
     ans += 3 * func1()
print(ans % 998244353)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = sorted([int(input()) for _ in range(N)])

s = sum(a)
m = (s + 1) // 2
m1 = m + 1


def func():
    ab = [[0] * m1 for _ in range(N + 1)]
    ab[0][m] = 1
    for i in range(N):
        c = a[i]
        for j in range(m1 - c):
            ab[i + 1][j] = (2 * ab[i][j] + ab[i][j + c]) % 998244353
        for j in range(m1 - c, m1):
            ab[i + 1][j] = (2 * ab[i][j] + ab[i][m]) % 998244353
    return ab[N][0]


def func1():
    ab = [[0] * m1 for _ in range(N + 1)]
    ab[0][m] = 1
    for i in range(N):
        c = a[i]
        for j in range(m1 - c):
            ab[i + 1][j] = (ab[i][j] + ab[i][j + c]) % 998244353
        for j in range(m1 - c, m1):
            ab[i + 1][j] = ab[i][j]
    return ab[N][0]


ans = 3 ** N % 998244353 - 3 * func()
if s % 2 == 0:
    ans += 3 * func1()
print(ans % 998244353)

Fixed submission:
import numpy as np

N = int(input())
a = sorted([int(input()) for _ in range(N)])

s = sum(a)
m = (s + 1) // 2
m1 = m + 1


def func():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (2 * ab[i, :-c] + ab[i, c:]) % 998244353
        ab[i + 1, -c:] = (2 * ab[i, -c:] + ab[i, m]) % 998244353
    return ab[N, 0]


def func1():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (ab[i, :-c] + ab[i, c:]) % 998244353 
        ab[i + 1, -c:] = ab[i, -c:]
    return ab[N, 0]


ans = 3 ** N % 998244353 - 3 * func()
if s % 2 == 0:
     ans += 3 * func1()
print(ans % 998244353)