from collections import defaultdict import math import pickle