Inspired by the top c++ answer.Use set to get the results n = int(input()) m = list(map(int, input().split())) x = list(map(int, input().split())) weights = [] res = set() res.add(0) for i in range(n): weights += [m[i]] * x[i] for elm in weights: for j in list(res): res.add(elm+j) print(len(res))