import sys from collections import defaultdict def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 M = int(input[ptr]) ptr += 1 B = int(10**5 ** 0.5) # Approximately 316 small_groups = defaultdict(list) large_groups = defaultdict(list) for _ in range(N): L = int(input[ptr]) ptr += 1 R = int(input[ptr]) ptr += 1 X = int(input[ptr]) ptr += 1 Y = int(input[ptr]) ptr += 1 if X <= B: key = (X, Y) small_groups[key].append((L, R)) else: key = Y large_groups[key].append((X, L, R)) A = list(map(int, input[ptr:ptr+M])) ptr += M for a in A: count = 0 # Check small X groups for X in range(1, B + 1): Y_val = a % X key = (X, Y_val) if key in small_groups: for (L, R) in small_groups[key]: if L <= a <= R: count += 1 # Check large X groups Y_val = a if Y_val in large_groups: for (X, L, R) in large_groups[Y_val]: if X > B and L <= a <= R: count += 1 print(count) if __name__ == "__main__": main()