Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [int(input()) for _ in range(N)]
    MOD = 998244353

    S = sum(A)
    a = A[0]
    # dp[i][j]: DP table for the number of one side length is j until i-th A[i].
    dp = [[0 for _ in range(S+1)] for _ in range(N)]
    dp[0][a] = 1
    dp[0][0] = 2

    # dp2[i][j]: DP table for the number of one side length is j and the other one is 0 until i-th A{i].
    dp2 = [[0 for _ in range(S+1)] for _ in range(N)]
    dp2[0][a] = 1
    dp2[0][0] = 1
    for i in range(1, N):
        a += A[i]
        for j in range(a+1):
            dp[i][j] = dp[i-1][j] * 2
            dp2[i][j] = dp2[i-1][j]

            if j >= A[i]:
                dp[i][j] += dp[i-1][j-A[i]]
                dp2[i][j] += dp2[i-1][j-A[i]]

            dp[i][j] %= MOD
            dp2[i][j] %= MOD

    ng = 0
    if S % 2 == 1:
        for i in range(S//2 + 1, S+1):
            ng += dp[N-1][i]

        ng = (ng * 3) % MOD

    else:
        for i in range(S//2, S+1):
            ng += dp[N-1][i]

        ng = (ng * 3 - dp2[N-1][S//2] * 3) % MOD

    ans = (pow(3, N, MOD) - ng) % MOD
    return ans


if __name__ == '__main__':
    print(main())


Fixed submission:
import sys
import numpy as np

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [int(input()) for _ in range(N)]
    MOD = 998244353

    S = sum(A)
    a = A[0]
    # dp0[i][j]: DP table
    #            the number of combinations that the one side length is j 
    #            until using the i-th A[i].
    dp0 = np.zeros((N, S+1), dtype=np.int64)
    dp0[0, a] = 1
    dp0[0, 0] = 2

    # dp1[i][j]: DP table
    #            the number of one side length is j and the other one is 0
    #            until using the i-th A{i].
    dp1 = np.zeros((N, S+1), dtype=np.int64)
    dp1[0, a] = 1
    dp1[0, 0] = 1
    for i in range(1, N):
        a = A[i]

        dp0[i, :] += dp0[i-1, :] * 2
        dp0[i, a:] += dp0[i-1, :-a]
        dp0[i, :] %= MOD

        dp1[i, :] += dp1[i-1, :]
        dp1[i, a:] += dp1[i-1, :-a]
        dp1[i, :] %= MOD


    ng = 0
    if S % 2 == 1:
        ng = np.sum(dp0[N-1, S//2 + 1:])
        ng = (ng * 3) % MOD

    else:
        ng = np.sum(dp0[N-1, S//2:])
        ng = (ng * 3 - dp1[N-1][S//2] * 3) % MOD

    ans = (pow(3, N, MOD) - ng) % MOD
    return ans


if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [int(input()) for _ in range(N)]
    MOD = 998244353

    S = sum(A)
    dp = [[0 for _ in range(S+1)] for _ in range(N)]
    a = A[0]
    dp[0][a] = 1
    dp[0][0] = 2
    for i in range(1, N):
        a += A[i]
        for j in range(a+1):
            dp[i][j] = dp[i-1][j] * 2

            if j >= A[i]:
                dp[i][j] += dp[i-1][j-A[i]]

            dp[i][j] %= MOD

    dp2 = [[0 for _ in range(S+1)] for _ in range(N)]
    a = A[0]
    dp2[0][a] = 1
    dp2[0][0] = 1
    for i in range(1, N):
        a += A[i]
        for j in range(a+1):
            dp2[i][j] = dp2[i-1][j]

            if j >= A[i]:
                dp2[i][j] += dp2[i-1][j-A[i]]

            dp2[i][j] %= MOD

    ng = 0
    if S % 2 == 1:
        for i in range(S//2 + 1, S+1):
            ng += dp[N-1][i]

        ng = (ng * 3) % MOD

    else:
        for i in range(S//2, S+1):
            ng += dp[N-1][i]

        ng = (ng * 3 - dp2[N-1][S//2] * 3) % MOD

    ans = (pow(3, N, MOD) - ng) % MOD

    
    return ans


if __name__ == '__main__':
    print(main())


Fixed submission:
import sys
import numpy as np

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [int(input()) for _ in range(N)]
    MOD = 998244353

    S = sum(A)
    a = A[0]
    # dp0[i][j]: DP table
    #            the number of combinations that the one side length is j 
    #            until using the i-th A[i].
    dp0 = np.zeros((N, S+1), dtype=np.int64)
    dp0[0, a] = 1
    dp0[0, 0] = 2

    # dp1[i][j]: DP table
    #            the number of one side length is j and the other one is 0
    #            until using the i-th A{i].
    dp1 = np.zeros((N, S+1), dtype=np.int64)
    dp1[0, a] = 1
    dp1[0, 0] = 1
    for i in range(1, N):
        a = A[i]

        dp0[i, :] += dp0[i-1, :] * 2
        dp0[i, a:] += dp0[i-1, :-a]
        dp0[i, :] %= MOD

        dp1[i, :] += dp1[i-1, :]
        dp1[i, a:] += dp1[i-1, :-a]
        dp1[i, :] %= MOD


    ng = 0
    if S % 2 == 1:
        ng = np.sum(dp0[N-1, S//2 + 1:])
        ng = (ng * 3) % MOD

    else:
        ng = np.sum(dp0[N-1, S//2:])
        ng = (ng * 3 - dp1[N-1][S//2] * 3) % MOD

    ans = (pow(3, N, MOD) - ng) % MOD
    return ans


if __name__ == '__main__':
    print(main())