money, number = list(map(int, input().strip().split())) money = money // 10 main = [[[0, 0], [0, 0], [0, 0]] for _ in range(number + 2)] for i in range(1, 1 + number): v, p, q = list(map(int, input().strip().split())) if q == 0: # 主件 main[i][0] = [v // 10, v * p] else: i...