# Path: misc/numerical.py
# INF = float('inf')


from random import shuffle, choice
from itertools import cycle, islice, permutations, chain, product, count
from collections import Iterable
from functools import reduce
from .numerical import INF
import operator
import time
  values = list(sequence)
  scores = [function(x) for x in values]
  return values[scores.index(min(scores))]

def pop_max(function, array):
  scores = [function(x) for x in array]
  return array.pop(scores.index(max(scores)))

def pop_min(function, array):
  scores = [function(x) for x in array]
  return array.pop(scores.index(min(scores)))

def safe_remove(sequence, item):
  try:
    sequence.remove(item)
    return True
  except ValueError:
    return False

def safe_function(function, sequence, default):
  if len(sequence) == 0:
    return default
  return function(sequence)

def safe_choice(sequence, default=None):
  return safe_function(choice, sequence, default)

def safe_max(sequence, default=-INF):
  return safe_function(max, sequence, default)


# Path: misc/numerical.py
# INF = float('inf')


# Path: misc/functions.py
from random import shuffle, choice
from itertools import cycle, islice, permutations, chain, product, count
from collections import Iterable
from functools import reduce
from .numerical import INF
import operator
import time

  values = list(sequence)
  scores = [function(x) for x in values]
  return values[scores.index(min(scores))]

def pop_max(function, array):
  scores = [function(x) for x in array]
  return array.pop(scores.index(max(scores)))

def pop_min(function, array):
  scores = [function(x) for x in array]
  return array.pop(scores.index(min(scores)))

def safe_remove(sequence, item):
  try:
    sequence.remove(item)
    return True
  except ValueError:
    return False

def safe_function(function, sequence, default):
  if len(sequence) == 0:
    return default
  return function(sequence)

def safe_choice(sequence, default=None):
  return safe_function(choice, sequence, default)

def safe_max(sequence, default=-INF):
  return safe_function(max, sequence, default)


def safe_min(sequence, default=INF):