https://www.nowcoder.com/practice/f9a4c19050fc477e9e27eb75f3bfd49c?tpId=37&&tqId=21264&rp=1&ru=/ta/huawei&qru=/ta/huawei/question-ranking

# 第二行:m1 m2 m3 ... mn --- 每个砝码的重量(范围[1,2000]) 每种吧?!
# 第三行:x1 x2 x3 .... xn --- 每个砝码的数量(范围[1,6])
while 1:
    try:
        n=int(input())
        zl=list(map( int, input().split() ) )
        sl=list(map( int, input().split() ) )
        n_class = len(zl)
        if n_class==1: 
            print(sl[0]+1)
            continue
        big_lt=[
                [zl[i]*s for s in range(0, sl[i]+1) ] for i in range(n_class)    
                ]

        for i in range(n_class-2):
#           merge_two_lt
            merged=set((0,))
            #这里如果用list存数据,超时。可能是因为多了一个判断 :是否在list里
            #用set则将原本的2s,缩短至50ms左右。
            for ele_q in big_lt[0]: 
                for ele_h in big_lt[1]:
                    merged.add(ele_q+ele_h)
            big_lt.pop(0)
            big_lt[0] = merged

        merged=set((0,))
        for ele_q in big_lt[0]: 
            for ele_h in big_lt[1]:
                merged.add(ele_q+ele_h)

        print(len(merged))

    except Exception as e:
        if not isinstance(e,EOFError):
            print('leo_you_have_Error:  '  , e)
        break