from collections import defaultdict import math def mex(arr): N=len(arr) used=[False]*(N+1) for e in arr: if 0<=e