use float('inf') instead of a large value
bugs in min1 and sum1; much simpler algo in seg_tree