SPOJ "Pesel" challemge
Likely what is taking up extra time is the line:

 p = map(int, re.findall('.',sys.stdin.readline()))


There are a few things here. Firstly, regular expressions are relatively expensive. Underneath, it likely needs to compile the regular expression (which in this case is very simple, but still). Further, you don't need regular expressions to do this in python. For example, assume the string was something like '343898934'. Then this is equivalent to:

p = [int(k) for k in '343898934']


The above will likely be slightly faster.

The second place here that could be optimized (memory wise) is that map in Python 2.x returns a list as opposed to a generator. So instead we could do:

p = (int(k) for k in sys.stdin.readline())


The fact that this also removes the re import may also impact timing and memory usage, depending on how they measure.