# -*- coding: utf-8 -*-

import sys
from heapq import heappush, heappop
import itertools
from functools import total_ordering


def is_scalar(obj):
    return not hasattr(obj, '__iter__') or isinstance(obj, basestring)


def prefixed(arg, prefix=None):
    if prefix and not arg.startswith(prefix):
        arg = prefix + arg
    return arg


@total_ordering
class MaxInt(long):
    """
    A quite-large integer type that tries to be like float('inf')
    (Infinity), but can be used for slicing and other integer
    operations. float('inf') is generally more correct, except that
    mixing a float and integer in arithmetic operations will result in
    a float, which will raise an error on slicing.
    """
    def __new__(cls, *a, **kw):
        return super(MaxInt, cls).__new__(cls, sys.maxint + 1)

    def __init__(self, name='MAX'):
        self._name = str(name)