from typing import List, Optional # Returns (safe sheep, caught sheep) def process_lunch_time(sheep: List[List[int]], steps: List[int], L: int) -> tuple[List[int], Optional[int]]: right_side = [] right_chase = None left_chase = None for i, me in enumerate(sheep): if sum(me) == 0: continue # Already eliminated if sum(steps) == 0: continue # <-- No movement happened this round, optimistically early exit so this isn't the only reason the inequality below is triggered. location = 0 for num, (hour, size) in zip(steps, enumerate(me)): location += num * (hour + 1) * size if location > L: location = L D = min(L - location, location) runs_right = location >= L // 2 can_catch = ( L < 4 * D or (L == 4 * D and not runs_right) # Wrong inequality here ) if runs_right: right_side.append(i) if runs_right and can_catch: if right_chase is None: right_chase = i if not runs_right and can_catch: if left_chase is None: left_chase = i caught = None if right_chase is not None: right_side.remove(right_chase) caught = right_chase elif left_chase is not None: caught = left_chase return right_side, caught n, m, L = map(int, input().split()) sheep = [list(map(int, input().split())) for _ in range(n)] steps = [0] * 11 for _ in range(m): X = int(input()) if 1 <= X <= 11: steps[X - 1] += 1 continue right_side, caught = process_lunch_time(sheep, steps, L) print(" ".join(str(x + 1) for x in right_side) if len(right_side) > 0 else "None") print(caught + 1 if caught is not None else "None") steps = [0] * 11 for idx in right_side + ([caught] if caught is not None else []): sheep[idx] = [0] * 11 # Will forever be stuck on the left.