def parse(inFile):
return tuple(inFile.getInts())
def rotate(n, k):
v = str(n)
v = "0" * (k - len(v)) + v
return int(v[1:]+v[0])
def solve((A,B)):
k = len(str(A))
count = 0
for n in xrange(A, B):
m = rotate(n, k)
while (m != n):
if (n < m) and (m <= B):
count += 1
m = rotate(m, k)
return count
if __name__ == "__main__":
from GCJ import GCJ
GCJ(parse, solve, "/Users/lpebody/gcj/2012_q/", "c").run()
ZGVmIHBhcnNlKGluRmlsZSk6CiAgICByZXR1cm4gdHVwbGUoaW5GaWxlLmdldEludHMoKSkKCmRlZiByb3RhdGUobiwgayk6CiAgICB2ID0gc3RyKG4pCiAgICB2ID0gIjAiICogKGsgLSBsZW4odikpICsgdgogICAgcmV0dXJuIGludCh2WzE6XSt2WzBdKQoKZGVmIHNvbHZlKChBLEIpKToKICAgIGsgPSBsZW4oc3RyKEEpKQogICAgY291bnQgPSAwCiAgICBmb3IgbiBpbiB4cmFuZ2UoQSwgQik6CiAgICAgICAgbSA9IHJvdGF0ZShuLCBrKQogICAgICAgIHdoaWxlIChtICE9IG4pOgogICAgICAgICAgICBpZiAobiA8IG0pIGFuZCAobSA8PSBCKToKICAgICAgICAgICAgICAgIGNvdW50ICs9IDEKICAgICAgICAgICAgbSA9IHJvdGF0ZShtLCBrKQogICAgcmV0dXJuIGNvdW50CgppZiBfX25hbWVfXyA9PSAiX19tYWluX18iOgogICAgZnJvbSBHQ0ogaW1wb3J0IEdDSgogICAgR0NKKHBhcnNlLCBzb2x2ZSwgIi9Vc2Vycy9scGVib2R5L2djai8yMDEyX3EvIiwgImMiKS5ydW4oKQoKICAgICAgICAgICAgCg==