from axelrod.llIIIlIlIllIIllllll import Action
from axelrod.player import Player
lllIIIIIIIlIIll, IlIlIIIIlIlIlIlIIlll = Action.C, Action.D
def IIllIllIlII(IIlIlIIllIlII, IlIIIllIIllll, IllIIllllIl, IllllIlIlIIIlIII):
    return {(lllIIIIIIIlIIll, lllIIIIIIIlIIll): IIlIlIIllIlII, (lllIIIIIIIlIIll, IlIlIIIIlIlIlIlIIlll): IlIIIllIIllll, (IlIlIIIIlIlIlIlIIlll, lllIIIIIIIlIIll): IllIIllllIl, (IlIlIIIIlIlIlIlIIlll, IlIlIIIIlIlIlIlIIlll): IllllIlIlIIIlIII}
def IllllIllIlI(llIIIlIlIllIIllllll):
    if llIIIlIlIllIIllllll == lllIIIIIIIlIIll:
        return 1
    return 0
def IIllIIIIIlllI(IIIllllIlI, lIIIIllllIIlIIlll, lIIlIlllllI):
    if IIIllllIlI.is_stochastic():
        IllIIlIIlIIlll = IIIllllIlI.get_siblings()
        llllIIlIlIIIl = IIIllllIlI.pC * IIllIIIIIlllI(
            IllIIlIIlIIlll[0], lIIIIllllIIlIIlll, lIIlIlllllI
        ) + (1 - IIIllllIlI.pC) * IIllIIIIIlllI(
            IllIIlIIlIIlll[1], lIIIIllllIIlIIlll, lIIlIlllllI
        )
        return llllIIlIlIIIl
    else:  
        if IIIllllIlI.depth == lIIlIlllllI:
            return IIIllllIlI.get_value()
        elif IIIllllIlI.depth == 0:
            IllIIlIIlIIlll = IIIllllIlI.get_siblings(lIIIIllllIIlIIlll)
            return (
                IIllIIIIIlllI(IllIIlIIlIIlll[0], lIIIIllllIIlIIlll, lIIlIlllllI)
                + IIIllllIlI.get_value(),
                IIllIIIIIlllI(IllIIlIIlIIlll[1], lIIIIllllIIlIIlll, lIIlIlllllI)
                + IIIllllIlI.get_value(),
            )
        elif IIIllllIlI.depth < lIIlIlllllI:
            IllIIlIIlIIlll = IIIllllIlI.get_siblings(lIIIIllllIIlIIlll)
            lIlIIlIIlllIIl = IIllIIIIIlllI(IllIIlIIlIIlll[0], lIIIIllllIIlIIlll, lIIlIlllllI)
            llllIIIlIIIlIIl = IIllIIIIIlllI(IllIIlIIlIIlll[1], lIIIIllllIIlIIlll, lIIlIlllllI)
            llllIIlIlIIIl = max(lIlIIlIIlllIIl, llllIIIlIIIlIIl) + IIIllllIlI.get_value()
            return llllIIlIlIIIl
def lIlIlIllIIlII(IlllIllIIlll, lIIIIllllIIlIIlll, lllIlIIlIIll=5):
    lllIIlIllIlI = DeterministicNode(IlllIllIIlll[0], IlllIllIIlll[1], depth=0)
    IlIIlIIII = IIllIIIIIlllI(
        lllIIlIllIlI, lIIIIllllIIlIIlll, lllIlIIlIIll
    )
    IIIIIllIlIllI = (lllIIIIIIIlIIll, IlIlIIIIlIlIlIlIIlll)
    return IIIIIllIlIllI[IlIIlIIII.index(max(IlIIlIIII))]
class llIlllIIIlIlII(Player):
    lIIIllIIIlllI = "strategy"
    lllllIlIlIIl = {
        "memory_depth": float("inf"),
        "stochastic": False,
        "long_run_time": True,
        "inspects_source": False,
        "manipulates_source": False,
        "manipulates_state": False,
    }
    def __init__(
        IIIlIIIIlIllllI,
        IlIllIIlIlIIIIII=0.75,
        IIlIlIllIIIlIlIlIll=3,
        lllIIIIIIlIIII=4,
        llllllIIIIlIIIIl=3,
        lIlllllIII=5,
    ):
        super().__init__()
        IIIlIIIIlIllllI.IIlIIIIIIlIIIII = IIllIllIlII(1, 1, 0, 0)
        IIIlIIIIlIllllI.IllIlllIll = {}
        IIIlIIIIlIllllI.lIIllllII = IIIlIIIIlIllllI.IIlIIIIIIlIIIII
        IIIlIIIIlIllllI.lllIIIllllI = {}
        IIIlIIIIlIllllI.llllllIIIIlIIIIl = llllllIIIIlIIIIl
        IIIlIIIIlIllllI.lllIIIIIIlIIII = lllIIIIIIlIIII
        IIIlIIIIlIllllI.IIlIlIllIIIlIlIlIll = IIlIlIllIIIlIlIlIll
        IIIlIIIIlIllllI.lIlllllIII = lIlllllIII
        IIIlIIIIlIllllI.lIlllIlIlIIIIIIll = 0
        IIIlIIIIlIllllI.IIIlllllIlIl = IlIllIIlIlIIIIII
        IIIlIIIIlIllllI.IlllIIII = {
            (lllIIIIIIIlIIll, lllIIIIIIIlIIll): ([1], [1]),
            (lllIIIIIIIlIIll, IlIlIIIIlIlIlIlIIlll): ([1], [1]),
            (IlIlIIIIlIlIlIlIIlll, lllIIIIIIIlIIll): ([0], [1]),
            (IlIlIIIIlIlIlIlIIlll, IlIlIIIIlIlIlIlIIlll): ([0], [1]),
        }
    def lllllIlll(IIIlIIIIlIllllI, llIlIIllI, IIlIlIllIIIlIlIlIll=3):
        if llIlIIllI[1] == lllIIIIIIIlIIll:
            IIlllllIIIlllII = 0
        elif llIlIIllI[1] == IlIlIIIIlIlIlIlIIlll:
            IIlllllIIIlllII = 1
        IllIlIIllIlIlll = 1
        lIllIlIllIlIIIllII = 0
        while IllIlIIllIlIlll < len(IIIlIIIIlIllllI.IlllIIII[llIlIIllI[0]][0]) and not (
            IIIlIIIIlIllllI.IlllIIII[llIlIIllI[0]][0][1:][-IllIlIIllIlIlll] == IIlllllIIIlllII
            and IIIlIIIIlIllllI.IlllIIII[llIlIIllI[0]][1][1:][-IllIlIIllIlIlll] == 1
        ):
            if IIIlIIIIlIllllI.IlllIIII[llIlIIllI[0]][1][1:][-IllIlIIllIlIlll] == 1:
                lIllIlIllIlIIIllII += 1
            IllIlIIllIlIlll += 1
        if lIllIlIllIlIIIllII >= IIlIlIllIIIlIlIlIll:
            return True
        return False
    def lIIIIllIIIIIlllIl(IIIlIIIIlIllllI, llIlIIIIlIII, lllIIIIIIlIIII=4):
        return IIIlIIIIlIllllI.lllIIIllllI[llIlIIIIlIII[0]] >= lllIIIIIIlIIII
    def lIlIIIIllIlllIIl(IIIlIIIIlIllllI, llIIIIIIlIIlIIlIlI):
        IlIllllIIII = (IIIlIIIIlIllllI.history[-2], llIIIIIIlIIlIIlIlI[-2])
        for IlllIllIIlll, llIIIIIIIlI in IIIlIIIIlIllllI.IlllIIII.items():
            lllIlllIlIlIlIl, lllIIIIlIll = llIIIIIIIlI
            if IlllIllIIlll == IlIllllIIII:
                if llIIIIIIlIIlIIlIlI[-1] == lllIIIIIIIlIIll:
                    lllIlllIlIlIlIl.append(1)
                else:
                    lllIlllIlIlIlIl.append(0)
                lllIIIIlIll.append(1)
            else:
                lllIlllIlIlIlIl.append(0)
                lllIIIIlIll.append(0)
    def IlIIlllIIl(IIIlIIIIlIllllI, IlllIllIIlll, IIIlllllIlIl=1):
        lllIlllIlIlIlIl = IIIlIIIIlIllllI.IlllIIII[IlllIllIIlll][0]
        lllIIIIlIll = IIIlIIIIlIllllI.IlllIIII[IlllIllIIlll][1]
        IllIlllllllIIlIIll = 0
        IIlIlIlII = 0
        lIlllIlIIIlII = 1
        for lIlIIIllll, llIIIlIIIl in zip(lllIlllIlIlIlIl[::-1], lllIIIIlIll[::-1]):
            IllIlllllllIIlIIll += lIlllIlIIIlII * lIlIIIllll
            IIlIlIlII += lIlllIlIIIlII * llIIIlIIIl
            lIlllIlIIIlII = IIIlllllIlIl * lIlllIlIIIlII
        lIlIIlIIIl = IllIlllllllIIlIIll / IIlIlIlII
        return lIlIIlIIIl
    def llIlIIlIll(IIIlIIIIlIllllI, lIlIllII: Player) -> Action:
        if not IIIlIIIIlIllllI.history:
            return lllIIIIIIIlIIll
        if len(lIlIllII.history) >= 2:
            IIIlIIIIlIllllI.lIlIIIIllIlllIIl(lIlIllII.history)
            IlIllllIIII = (IIIlIIIIlIllllI.history[-2], lIlIllII.history[-2])
            llIlIIllI = (IlIllllIIII, lIlIllII.history[-1])
            llIlIIIIlIII = (IlIllllIIII, ({lllIIIIIIIlIIll, IlIlIIIIlIlIlIlIIlll} - {lIlIllII.history[-1]}).pop())
            if llIlIIllI[0] not in IIIlIIIIlIllllI.IllIlllIll.keys():
                if IIIlIIIIlIllllI.lllllIlll(llIlIIllI, IIIlIIIIlIllllI.IIlIlIllIIIlIlIlIll):
                    IIIlIIIIlIllllI.IllIlllIll[llIlIIllI[0]] = IllllIllIlI(llIlIIllI[1])
                    IIIlIIIIlIllllI.lllIIIllllI[llIlIIllI[0]] = 0
                    IIIlIIIIlIllllI.lllIIIllllI[llIlIIllI[0]] = 0
            if llIlIIllI[0] in IIIlIIIIlIllllI.IllIlllIll.keys():
                llIlllllIlIII = lllIIIIIIIlIIll if IIIlIIIIlIllllI.IllIlllIll[llIlIIllI[0]] == 1 else IlIlIIIIlIlIlIlIIlll
                if llIlIIllI[1] == llIlllllIlIII:
                    IIIlIIIIlIllllI.lllIIIllllI[llIlIIllI[0]] = 0
                elif llIlIIIIlIII[1] == llIlllllIlIII:
                    IIIlIIIIlIllllI.lllIIIllllI[llIlIIllI[0]] += 1
                    if IIIlIIIIlIllllI.lIIIIllIIIIIlllIl(llIlIIIIlIII, IIIlIIIIlIllllI.lllIIIIIIlIIII):
                        IIIlIIIIlIllllI.IIlIIIIIIlIIIII.update(IIIlIIIIlIllllI.IllIlllIll)
                        IIIlIIIIlIllllI.IllIlllIll.clear()
                        IIIlIIIIlIllllI.lllIIIllllI.clear()
                        IIIlIIIIlIllllI.lIlllIlIlIIIIIIll = 0
            lIllIllIllIlIIIIlII = llIlIIllI[0] in IIIlIIIIlIllllI.IllIlllIll.keys() and IIIlIIIIlIllllI.IllIlllIll[
                llIlIIllI[0]
            ] == IllllIllIlI(llIlIIllI[1])
            IlIlIIIIIlI = llIlIIIIlIII[0] in IIIlIIIIlIllllI.IIlIIIIIIlIIIII.keys() and IIIlIIIIlIllllI.IIlIIIIIIlIIIII[
                llIlIIIIlIII[0]
            ] == IllllIllIlI(llIlIIIIlIII[1])
            if IlIlIIIIIlI:
                IIIlIIIIlIllllI.lIlllIlIlIIIIIIll += 1
            if (IIIlIIIIlIllllI.lIlllIlIlIIIIIIll > IIIlIIIIlIllllI.llllllIIIIlIIIIl) or (
                lIllIllIllIlIIIIlII and IlIlIIIIIlI
            ):
                IIIlIIIIlIllllI.IIlIIIIIIlIIIII.clear()
                IIIlIIIIlIllllI.lIlllIlIlIIIIIIll = 0
            IIIlIIIIlIllIlI = {}
            IIIllllIll = [(lllIIIIIIIlIIll, lllIIIIIIIlIIll), (lllIIIIIIIlIIll, IlIlIIIIlIlIlIlIIlll), (IlIlIIIIlIlIlIlIIlll, lllIIIIIIIlIIll), (IlIlIIIIlIlIlIlIIlll, IlIlIIIIlIlIlIlIIlll)]
            for IlllIllIIlll in IIIllllIll:
                if (IlllIllIIlll not in IIIlIIIIlIllllI.IllIlllIll.keys()) and (
                    IlllIllIIlll not in IIIlIIIIlIllllI.IIlIIIIIIlIIIII.keys()
                ):
                    IIIlIIIIlIllIlI[IlllIllIIlll] = IIIlIIIIlIllllI.IlIIlllIIl(IlllIllIIlll, IIIlIIIIlIllllI.IIIlllllIlIl)
            IIIlIIIIlIllllI.lIIllllII = {}
            IIIlIIIIlIllllI.lIIllllII.update(IIIlIIIIlIllllI.IllIlllIll)
            IIIlIIIIlIllllI.lIIllllII.update(IIIlIIIIlIllllI.IIlIIIIIIlIIIII)
            IIIlIIIIlIllllI.lIIllllII.update(IIIlIIIIlIllIlI)
        return lIlIlIllIIlII(
            (IIIlIIIIlIllllI.history[-1], lIlIllII.history[-1]),
            IIIlIIIIlIllllI.lIIllllII,
            lllIlIIlIIll=IIIlIIIIlIllllI.lIlllllIII,
        )