import sys from collections import defaultdict import bisect def generate_group_sums(group, max_s): sum_counts = defaultdict(int) sum_counts[0] = 1 # Initial state: sum is 0 with 1 way (no elements selected) for a in group: temp = defaultdict(int) for sum_so_far in sum_counts: current_count = sum_counts[sum_so_far] k = 1 while True: try: power = a ** k except OverflowError: break new_sum = sum_so_far + power if new_sum > max_s: break temp[new_sum] += current_count k += 1 sum_counts = temp return sum_counts def main(): n, S = map(int, sys.stdin.readline().split()) a = list(map(int, sys.stdin.readline().split())) half = n // 2 group1 = a[:half] group2 = a[half:] sum_counts1 = generate_group_sums(group1, S) sum_counts2 = generate_group_sums(group2, S) # Process group2 for binary search sorted_s2 = sorted(sum_counts2.items()) s2_list = [] prefix_counts = [] current_total = 0 for s, cnt in sorted_s2: s2_list.append(s) current_total += cnt prefix_counts.append(current_total) total = 0 for s1, cnt1 in sum_counts1.items(): remaining = S - s1 if remaining < 0: continue # Find the largest index where s2 <= remaining idx = bisect.bisect_right(s2_list, remaining) - 1 if idx >= 0: total += cnt1 * prefix_counts[idx] print(total) if __name__ == "__main__": main()