fork download
  1. def r(t,y,z):import numpy;l=numpy.array([i.split()for i in z.split('\n')]);A,B,C,D=t[0],y[0],t[1],y[1];p=[1,-1];a=p[A>B];b=p[C>D];n=range(A,B+a,a);m=range(C,D+b,b);w=[l[:,i][::-1][p]for i,p in zip([[A]*len(m),n][A!=B],[[C]*len(n),m][C!=D])];return w
  2. a=eval(input())
  3. print(''.join(r(eval(input()),eval(input()),a)))
Success #stdin #stdout 0.2s 27400KB
stdin
"A G O A T C A T\nE A T M E N O W\nW O R D S E A R\nA K L L K J H G\nN P L F G H F D\nA S P L K J H G\nO P I L F G H J\nT F A S E J K L"
(0,4)
(4,0)
stdout
APPLE