from fractions import Fraction
import sys
sys.setrecursionlimit(10000)
def parse(inFile):
return (inFile.getInt(), [z - 1 for z in inFile.getInts()])
def whatis(N, hs):
xs = []
for i in xrange(N - 1):
rec = i + 1
for j in xrange(i + 2, N):
if (hs[j] - hs[i]) * (rec - i) > (hs[rec] - hs[i]) * (j - i):
rec = j
xs += [rec]
return xs
def shift(k):
n = len(k)
return [(n - i) + k[i] for i in xrange(n)]
def slv(xs, i, j):
if (i > j): return []
if (i == j): return [0]
return [0] + shift(slv(xs, i + 1, xs[i] - 1)) + slv(xs, xs[i], j)
def solve((N, xs)):
for j in xrange(N - 1):
for k in xrange(j + 1, xs[j]):
if xs[k] > xs[j]:
return "Impossible"
hs = slv(xs, 0, N - 1)
mh = max(hs)
hs = [mh - i for i in hs]
return " ".join(["%d" % h for h in hs])
if __name__ == "__main__":
from GCJ import GCJ
GCJ(parse, solve, "/Users/lpebody/gcj/2012_2/c", "C").run()
ZnJvbSBmcmFjdGlvbnMgaW1wb3J0IEZyYWN0aW9uCmltcG9ydCBzeXMKCnN5cy5zZXRyZWN1cnNpb25saW1pdCgxMDAwMCkKCmRlZiBwYXJzZShpbkZpbGUpOgogICAgcmV0dXJuIChpbkZpbGUuZ2V0SW50KCksIFt6IC0gMSBmb3IgeiBpbiBpbkZpbGUuZ2V0SW50cygpXSkKCmRlZiB3aGF0aXMoTiwgaHMpOgogICAgeHMgPSBbXQogICAgZm9yIGkgaW4geHJhbmdlKE4gLSAxKToKICAgICAgICByZWMgPSBpICsgMQogICAgICAgIGZvciBqIGluIHhyYW5nZShpICsgMiwgTik6CiAgICAgICAgICAgIGlmIChoc1tqXSAtIGhzW2ldKSAqIChyZWMgLSBpKSA+IChoc1tyZWNdIC0gaHNbaV0pICogKGogLSBpKToKICAgICAgICAgICAgICAgIHJlYyA9IGoKICAgICAgICB4cyArPSBbcmVjXQogICAgcmV0dXJuIHhzCgpkZWYgc2hpZnQoayk6CiAgICBuID0gbGVuKGspCiAgICByZXR1cm4gWyhuIC0gaSkgKyBrW2ldIGZvciBpIGluIHhyYW5nZShuKV0KCmRlZiBzbHYoeHMsIGksIGopOgogICAgaWYgKGkgPiBqKTogcmV0dXJuIFtdCiAgICBpZiAoaSA9PSBqKTogcmV0dXJuIFswXQogICAgcmV0dXJuIFswXSArIHNoaWZ0KHNsdih4cywgaSArIDEsIHhzW2ldIC0gMSkpICsgc2x2KHhzLCB4c1tpXSwgaikKCmRlZiBzb2x2ZSgoTiwgeHMpKToKICAgIGZvciBqIGluIHhyYW5nZShOIC0gMSk6CiAgICAgICAgZm9yIGsgaW4geHJhbmdlKGogKyAxLCB4c1tqXSk6CiAgICAgICAgICAgIGlmIHhzW2tdID4geHNbal06CiAgICAgICAgICAgICAgICByZXR1cm4gIkltcG9zc2libGUiCiAgICBocyA9IHNsdih4cywgMCwgTiAtIDEpCiAgICBtaCA9IG1heChocykKICAgIGhzID0gW21oIC0gaSBmb3IgaSBpbiBoc10KICAgIHJldHVybiAiICIuam9pbihbIiVkIiAlIGggZm9yIGggaW4gaHNdKQoKaWYgX19uYW1lX18gPT0gIl9fbWFpbl9fIjoKICAgIGZyb20gR0NKIGltcG9ydCBHQ0oKICAgIEdDSihwYXJzZSwgc29sdmUsICIvVXNlcnMvbHBlYm9keS9nY2ovMjAxMl8yL2MiLCAiQyIpLnJ1bigpCg==