Small Change by hirose

while 1:
 x=raw_input().split(" ");m=map(int,x[1:]);s=[0]*999+[[]]
 for _ in" "*int(x[0][:-1]):
  t=0
  for i in m:
\x09if s[-i]!=0and(t==0or len(s[-i])<len(t)):t=s[-i]+[i]
  s+=[t]
 print t and" ".join(map(str,t))or"-" 

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return top