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

def solve():
    mod=998244353
    N=int(input())
    A=[]
    for i in range(N):
        A.append(int(input()))
    sumA=sum(A)
    sumA2=(sumA+1)//2

    # dp[N][sum] : N個目までの合計がsumの数
    dp = [collections.defaultdict(int) for i in range(N+1)]
    dp[0][0]=1
    for i in range(N):
        for j in dp[i].keys():
            if dp[i][j]==0:
                continue
            dp[i+1][j]+=dp[i][j]*2
            j2=min(sumA2,j+A[i])
            dp[i+1][j2]+=dp[i][j]
    ans=1
    for i in range(N):
        ans=(ans*3)%mod
    ans=(ans+mod-3*dp[N][sumA2])%mod

    if sumA%2==0:
        # dp[N][sum] : N個目までの合計がsumの数
        dp = [collections.defaultdict(int) for i in range(N+1)]
        dp[0][0]=1
        for i in range(N):
            for j in dp[i].keys():
                if dp[i][j]==0:
                    continue
                dp[i+1][j]+=dp[i][j]
                j2=min(sumA2+1,j+A[i])
                dp[i+1][j2]+=dp[i][j]
        ans=(ans+3*dp[N][sumA2])%mod

    return ans

print(solve())


Fixed submission:
def solve():
    mod=998244353
    N=int(input())
    A=[]
    for i in range(N):
        A.append(int(input()))
    sumA=sum(A)
    sumA2=(sumA+1)//2

    dp = [[0]*(sumA2+2) for i in range(N+1)]
    dp[0][0]=1
    for i in range(N):
        for j in range(sumA2+1):
            if dp[i][j]!=0:
                dp[i+1][j]=(dp[i+1][j]+dp[i][j]*2)%mod
                j2=min(sumA2,j+A[i])
                dp[i+1][j2]=(dp[i+1][j2]+dp[i][j])%mod
    ans=1
    for i in range(N):
        ans=(ans*3)%mod
    ans=(ans+mod-3*dp[N][sumA2])%mod

    if sumA%2==0:
        dp = [[0]*(sumA2+2) for i in range(N+1)]
        dp[0][0]=1
        for i in range(N):
            for j in range(sumA2+2):
                if dp[i][j]!=0:
                    dp[i+1][j]+=dp[i][j]
                    j2=min(sumA2+1,j+A[i])
                    dp[i+1][j2]+=dp[i][j]
        ans=(ans+3*dp[N][sumA2])%mod

    return ans

print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    mod=998244353
    N=int(input())
    A=[]
    for i in range(N):
        A.append(int(input()))
    sumA=sum(A)
    sumA2=(sumA+1)//2

    # dp[N][sum] : N個目までの合計がsumの数
    dp = [[0]*(sumA2+2) for i in range(N+1)]
    dp[0][0]=1
    for i in range(N):
        for j in range(sumA2+1):
            if dp[i][j]==0:
                continue
            dp[i+1][j]+=dp[i][j]*2
            j2=min(sumA2,j+A[i])
            dp[i+1][j2]+=dp[i][j]
    ans=1
    for i in range(N):
        ans=(ans*3)%mod
    ans=(ans+mod-3*dp[N][sumA2])%mod

    if sumA%2==0:
        # dp[N][sum] : N個目までの合計がsumの数
        dp = [[0]*(sumA2+2) for i in range(N+1)]
        dp[0][0]=1
        for i in range(N):
            for j in range(sumA2+2):
                if dp[i][j]==0:
                    continue
                dp[i+1][j]+=dp[i][j]
                j2=min(sumA2+1,j+A[i])
                dp[i+1][j2]+=dp[i][j]
        ans=(ans+3*dp[N][sumA2])%mod

    return ans

print(solve())


Fixed submission:
def solve():
    mod=998244353
    N=int(input())
    A=[]
    for i in range(N):
        A.append(int(input()))
    sumA=sum(A)
    sumA2=(sumA+1)//2

    dp = [[0]*(sumA2+2) for i in range(N+1)]
    dp[0][0]=1
    for i in range(N):
        for j in range(sumA2+1):
            if dp[i][j]!=0:
                dp[i+1][j]=(dp[i+1][j]+dp[i][j]*2)%mod
                j2=min(sumA2,j+A[i])
                dp[i+1][j2]=(dp[i+1][j2]+dp[i][j])%mod
    ans=1
    for i in range(N):
        ans=(ans*3)%mod
    ans=(ans+mod-3*dp[N][sumA2])%mod

    if sumA%2==0:
        dp = [[0]*(sumA2+2) for i in range(N+1)]
        dp[0][0]=1
        for i in range(N):
            for j in range(sumA2+2):
                if dp[i][j]!=0:
                    dp[i+1][j]+=dp[i][j]
                    j2=min(sumA2+1,j+A[i])
                    dp[i+1][j2]+=dp[i][j]
        ans=(ans+3*dp[N][sumA2])%mod

    return ans

print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    mod=998244353
    N=int(input())
    A=[]
    for i in range(N):
        A.append(int(input()))
    su=sum(A)
    su2=su//2
    A.sort()
    csum=[0]*(N+1)
    for i in range(N):
        csum[i+1]=csum[i]+A[i]

    q=[]
    q.append((N-2,0,0,A[N-1]))
    b=[0]*3
    ans=0
    try:
        while True:
            i,b[0],b[1],b[2] = q.pop()
            b.sort()
            if i==0:
                if b[0]+b[1]+A[0]>b[2] and b[1]+b[2]>b[0]+A[0]:
                    ans+=1
                if b[0]+b[1]+A[0]>b[2] and b[0]+b[2]>b[1]+A[0]:
                    ans+=1
                if b[0]+b[1]>b[2]+A[0]:
                    ans+=1
                continue
            if i>=N-3:
                q.append((i-1,b[0],b[1],b[2]+A[i]))
                q.append((i-1,b[0],b[1]+A[i],b[2]))
                q.append((i-1,b[0]+A[i],b[1],b[2]))
                continue
            if b[0]+b[1]>b[2]+csum[i+1]:
                ans+=3**(i+1)
                ans%=mod
                continue
            if b[0]+b[1]+csum[i+1]<=b[2]:
                continue
            q.append((i-1,b[0],b[1],b[2]+A[i]))
            q.append((i-1,b[0],b[1]+A[i],b[2]))
            q.append((i-1,b[0]+A[i],b[1],b[2]))
    except IndexError:
        pass
    ans*=3
    ans%=mod
    return ans

print(solve())


Fixed submission:
def solve():
    mod=998244353
    N=int(input())
    A=[]
    for i in range(N):
        A.append(int(input()))
    sumA=sum(A)
    sumA2=(sumA+1)//2

    dp = [[0]*(sumA2+2) for i in range(N+1)]
    dp[0][0]=1
    for i in range(N):
        for j in range(sumA2+1):
            if dp[i][j]!=0:
                dp[i+1][j]=(dp[i+1][j]+dp[i][j]*2)%mod
                j2=min(sumA2,j+A[i])
                dp[i+1][j2]=(dp[i+1][j2]+dp[i][j])%mod
    ans=1
    for i in range(N):
        ans=(ans*3)%mod
    ans=(ans+mod-3*dp[N][sumA2])%mod

    if sumA%2==0:
        dp = [[0]*(sumA2+2) for i in range(N+1)]
        dp[0][0]=1
        for i in range(N):
            for j in range(sumA2+2):
                if dp[i][j]!=0:
                    dp[i+1][j]+=dp[i][j]
                    j2=min(sumA2+1,j+A[i])
                    dp[i+1][j2]+=dp[i][j]
        ans=(ans+3*dp[N][sumA2])%mod

    return ans

print(solve())