Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

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

@njit((i8[:], i8, i8), cache=True)
def test(A, keta, n):
    # 10^keta の位を n にできるか
    MOD = 10**(keta + 1)
    I = [(n * 10**keta, (n + 1) * 10**keta)]  # [l, r)
    for x in A:
        if I[0][0] == 0:
            return True
        newI = I.copy()
        x %= MOD
        for l, r in I:
            l, r = l + MOD - x, r + MOD - x
            if l >= MOD:
                l, r = l - MOD, r - MOD
            if r <= MOD:
                newI.append((l, r))
            else:
                newI.append((l, MOD))
                newI.append((0, r - MOD))
        I = newI
        I.sort(key=lambda x: x[1])
        newI = [(0, 0)] * 0
        for x, y in I:
            while newI and newI[-1][1] >= x:  # つなぐ
                x, y = min(x, newI[-1][0]), y
                newI.pop()
            newI.append((x, y))
        I = newI
    return I[0][0] == 0

def main(A):
    N = len(A)
    ans = 0
    for keta in range(18):
        for x in range(9, 0, -1):
            if test(A, keta, x):
                ans += x
                break
    return ans

A = np.array(read().split(), np.int64)[1:]
np.random.shuffle(A)
print(main(A))

Fixed submission:
import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

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

@njit((i8[:], i8), cache=True)
def solve(A, keta):
    # 10^keta の位を n にできるか
    MOD = 10**(keta + 1)
    B = 10**keta
    nums = [0]
    for x in A:
        x %= MOD
        n = len(nums)
        for i in range(n):
            s = nums[i] + x
            if s >= MOD:
                s -= MOD
            nums.append(s)
        nums.sort()
        # x, y, z とあって、x + z < B ならば、y は捨ててよい
        tmp = []
        for x in nums:
            while len(tmp) >= 2 and tmp[-2] + B > x:
                tmp.pop()
            tmp.append(x)
        nums = tmp
    return nums[-1] // B

def main(A):
    N = len(A)
    ans = 0
    for keta in range(18):
        x = solve(A, keta)
        ans += x
    return ans

A = np.array(read().split(), np.int64)[1:]
np.random.shuffle(A)
print(main(A))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

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

@njit((i8[:], i8, i8), cache=True)
def test(A, keta, n):
    # 10^keta の位を n にできるか
    MOD = 10**(keta + 1)
    I = [(n * 10**keta, (n + 1) * 10**keta)]  # [l, r)
    for x in A:
        if I[0][0] == 0:
            return True
        newI = I.copy()
        x %= MOD
        for l, r in I:
            l, r = l + MOD - x, r + MOD - x
            if l >= MOD:
                l, r = l - MOD, r - MOD
            if r <= MOD:
                newI.append((l, r))
            else:
                newI.append((l, MOD))
                newI.append((0, r - MOD))
        I = newI
        I.sort(key=lambda x: x[1])
        newI = [(0, 0)] * 0
        for x, y in I:
            while newI and newI[-1][1] >= x:  # つなぐ
                x, y = min(x, newI[-1][0]), y
                newI.pop()
            newI.append((x, y))
        I = newI
    return I[0][0] == 0

def main(A):
    N = len(A)
    ans = 0
    for keta in range(18):
        for x in range(9, 0, -1):
            if test(A, keta, x):
                ans += x
                break
    return ans

A = np.array(read().split(), np.int64)[1:]
print(main(A))

Fixed submission:
import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

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

@njit((i8[:], i8), cache=True)
def solve(A, keta):
    # 10^keta の位を n にできるか
    MOD = 10**(keta + 1)
    B = 10**keta
    nums = [0]
    for x in A:
        x %= MOD
        n = len(nums)
        for i in range(n):
            s = nums[i] + x
            if s >= MOD:
                s -= MOD
            nums.append(s)
        nums.sort()
        # x, y, z とあって、x + z < B ならば、y は捨ててよい
        tmp = []
        for x in nums:
            while len(tmp) >= 2 and tmp[-2] + B > x:
                tmp.pop()
            tmp.append(x)
        nums = tmp
    return nums[-1] // B

def main(A):
    N = len(A)
    ans = 0
    for keta in range(18):
        x = solve(A, keta)
        ans += x
    return ans

A = np.array(read().split(), np.int64)[1:]
np.random.shuffle(A)
print(main(A))