"""Recover the reduction flag from the residue and the added modular weight."""
from itertools import product
import json


def experiment():
    counts=0;first=None
    for p in (3,5,7,11,13,17,19,23,29,31):
        for c,x in product(range(p),repeat=2):
            y=(x+c)%p
            assert (y<c)==(x+c>=p) and (y-c)%p==x
            counts+=1
        if first is None:
            c=1
            for x in range(p,2*p):
                y=(x+c)%p
                if (y<c)!=(x+c>=p):
                    first=dict(p=p,c=c,x=x,y=y,other=x-p)
                    break
    return dict(cases=counts,outside=first)


if __name__=='__main__':print(json.dumps(experiment(),indent=2))
