import bisect MOD = 10**9 + 7 class FenwickTree: def __init__(self, size): self.size = size self.tree = [0] * (size + 1) # 1-based indexing def update(self, index, value): while index <= self.size: self.tree[index] = (self.tree[index] + value) % MOD index += index & -index def query(self, index): res = 0 while index > 0: res = (res + self.tree[index]) % MOD index -= index & -index return res def main(): import sys input = sys.stdin.read().split() ptr = 0 K = int(input[ptr]) ptr += 1 N = int(input[ptr]) ptr += 1 x = list(map(int, input[ptr:ptr+N])) ptr += N x.sort() # Ensure x is sorted max_k = K fenwick = FenwickTree(max_k) dp = [0] * (max_k + 1) dp[0] = 1 fenwick.update(0 + 1, dp[0]) # Fenwick is 1-based for k in range(1, max_k + 1): # Find the largest x_i <= k m = bisect.bisect_right(x, k) - 1 if m < 0: dp_k = 0 else: # Compute the sum of dp[k - x_i] for i=0 to m # Since x is sorted, k - x_i may be in a non-contiguous range # Thus, we need to query each x_i individually, which is O(m) time and not feasible # This approach is incorrect as it leads to O(N) per k # Hence, the code below is incorrect for the problem constraints sum_dp = 0 for i in range(m + 1): xi = x[i] if xi > k: break j = k - xi if j < 0: continue sum_dp = (sum_dp + dp[j]) % MOD dp_k = sum_dp dp[k] = dp_k fenwick.update(k + 1, dp_k) print(dp[K] % MOD) if __name__ == "__main__": main()