Problem:


King's Inspection
-->

王様の視察

とある国の偉い王様が、突然友好国の土地を視察することになった。
その国は電車が有名で、王様はいろいろな駅を視察するという。

電車の駅は52個あり、それぞれに大文字か小文字のアルファベット1文字の名前がついている（重なっている名前はない）。
この電車の路線は環状になっていて、aの駅の次はbの駅、bの駅の次はcの駅と順に並んでいてz駅の次はA駅、その次はBの駅と順に進み、Z駅の次はa駅になって元に戻る。
単線であり、逆方向に進む電車は走っていない。

ある日、新聞社の記者が王様が訪れる駅の順番のリストを手に入れた。

「dcdkIlkP…」

最初にd駅を訪れ、次にc駅、次にd駅と順に訪れていくという。これで、偉い国の王様を追跡取材できると思った矢先、思わぬことが発覚した。そのリストは、テロ対策のため暗号化されていたのだ！記者の仲間が、その暗号を解く鍵を入手したという。早速この記者は鍵を譲ってもらい、リストの修正にとりかかった。鍵はいくつかの数字の列で構成されている。

「3 1 4 5 3」

この数字の意味するところは、はじめに訪れる駅は、リストに書いてある駅の3つ前の駅。
2番目に訪れる駅はリストの2番目の駅の前の駅、という風に、実際訪れる駅がリストの駅の何駅前かを示している。
記者は修正に取りかかったが、訪れる駅のリストの数よりも、鍵の数の方が小さい、どうするのかと仲間に聞いたところ、最後の鍵をつかったら、またはじめの鍵から順に使っていけばよいらしい。
そして記者はようやくリストを修正することができた。

「abZfFijL…」

これでもう怖い物は無いだろう、そう思った矢先、さらに思わぬ事態が発覚した。
偉い王様は何日間も滞在し、さらにそれぞれの日程ごとにリストと鍵が存在したのだ。
記者は上司から、すべてのリストを復号するように指示されたが、量が量だけに、彼一人では終わらない。
あなたの仕事は彼を助け、このリストの復号を自動で行うプログラムを作成することである。

Input

入力は複数のデータセットから構成される。各データセットの形式は次の通りである。

n
k1 k2... kn
s

n は鍵の数を表す整数であり、1以上 100 以下と仮定して良い。
続く行には鍵のリストが記載されている。kiはi番目の鍵を示す。1以上52以下と仮定して良い。
sはアルファベット大文字・小文字からなる文字列で、訪れる駅のリストを示す。1文字以上100文字以下であると仮定して良い。
n=0 は入力の終わりを示す。これはデータセットには含めない。

Output

各データセットに対する復号されたリストを各1行に出力せよ。

Sample Input

2
1 2
bdd
3
3 2 1
DDDA
5
3 1 4 5 3
dcdkIlkP
0

Output for Sample Input

abc
ABCx
abZfFijL



Sample input:
2
1 2
bdd
3
3 2 1
DDDA
5
3 1 4 5 3
dcdkIlkP
0


Sample output:
abc
ABCx
abZfFijL

Submission status: Wrong Answer

Solution code:
while 1:
    n=int(input())
    if n==0:break
    a=list(map(int,input().split()))
    s=list(input())
    for i in range(len(s)):
        for j in range(a[i%n]):
            if s[i]=='A':s[i]='a'
            elif s[i]=='a':s[i]='Z'
            else:s[i]=s[i]=chr(ord(s[i])-1)
    print(*s,sep='')

Submission status: Wrong Answer

Solution code:
def reset(n_lis,chr_lis):
    k = len(n_lis)
    for i in range(len(chr_lis)):
        n = ord(chr_lis[i])
        a = n_lis[i%k]
 #       print(n_lis)
        if  n>96 and n-a<97:
            n -= 6
        elif n-a<65:
            n+=58
        n-=a
        chr_lis[i]=chr(n)

    for ch in chr_lis:
        print(ch,end='')
    print()

while True:
    if input()=='0':
        break
    n_lis = [int(i) for i in input().split(' ')]
    c_lis = [i for i in input()]
    reset(n_lis,c_lis)

Submission status: Wrong Answer

Solution code:
def suber(c, k):
    if ord('a')<=ord(c):
        w = ord(c) - ord('a')
        if w < k:
            return chr(ord('Z') - (k - w - 1))
        return chr(ord('a') + (w - k))
    else:
        w = ord(c) - ord('A')
        if w < k:
            return chr(ord('z') - (k - w - 1))
        return chr(ord('A') + (w - k))
while True:
    n = input()
    if n==0:
        break
    k = map(int, raw_input().split())
    s = raw_input()
    print "".join(suber(s[i], k[i%n]) for i in xrange(len(s)))

Submission status: Wrong Answer

Solution code:
station = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQESTUVWXYZ"
while True:
    n = input()
    if n==0:
        break
    k = map(int, raw_input().split())
    s = raw_input()
    print "".join(station[(station.find(s[i])-k[i%n])%52] for i in xrange(len(s)))

Submission status: Accepted

Solution code:
a = ord("a")
A = ord("A")
dic1 = {}
dic2 = {}
for i in range(26):
  dic1[i] = chr(a + i)
  dic2[chr(a + i)] = i
  dic1[i + 26] = chr(A + i)
  dic2[chr(A + i)] = i + 26
while True:
  n = int(input())
  if n == 0:break
  klst = list(map(int, input().split())) * 100
  s = input()
  ans = ""
  for c, k in zip(s, klst):
    ans += dic1[(dic2[c] - k) % 52]
  print(ans)

Submission status: Accepted

Solution code:
al = [chr(c) for c in range(ord('A'), ord('Z') + 1)] + [chr(c) for c in range(ord('a'), ord('z') + 1)] 

def f1(c):
    if 'A' <= c <= 'Z':
        return ord(c) - ord('A')
    return ord(c) - ord('a') + ord('Z') - ord('A') + 1
while True:
    if not int(input()):
        break
    k = list(map(int, input().split()))
    s = list(map(f1, input()))
    print(''.join([al[c - k[i % len(k)]]  for i, c in enumerate(s)]))

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        self.chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            k = map(int, raw_input().split())
            s = raw_input()
            ans = ''
            for i in range(len(s)):
                ans += self.chars[self.chars.index(s[i]) - k[i % len(k)]]
            print ans
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

char_list = list(map(chr,range(ord('a'),ord('z')+1)))
char_list += list(map(chr,range(ord('A'),ord('Z')+1)))
while True:
    n = int(input())
    if n == 0:
        break
    keys = list(map(int,input().split(" ")))
    sentence = input()
    for i in range(len(sentence)):
        if sentence[i].isupper():
            j = ord(sentence[i]) - ord('A') + 26
        else:
            j = ord(sentence[i]) - ord('a')
        print(char_list[j-keys[i%len(keys)]],end="")
    print()

Submission status: Accepted

Solution code:
def myord(c):
	asc = ord(c)
	if asc <= 90:
		return asc
	else :
		return asc - 6
def mychr(asc):
	if asc <= 90:
		return chr(asc)
	else :
		return chr(asc + 6)
import sys
while 1:
	n = int(raw_input())
	if n == 0:
		break
	k = map(int,raw_input().split())
	length = len(k)
	inc = 0
	station = []
	s = raw_input()
	for ls in s:
		key = k[inc]
		asc = myord(ls) - k[inc]
		station.append(mychr(asc) if asc >= 65 else mychr(116 - (65 - asc) + 1))
		inc = inc + 1 if inc + 1 < length else 0
	for si in station:
		sys.stdout.write(si)
	print ""

Submission status: Accepted

Solution code:
n2c = dict(zip(range(0,52),"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
c2n = dict(zip("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",range(0,52)))

def f(c,k):
	return n2c[(c2n[c]-k)%52]


while True:
	kl=int(raw_input())
	if kl==0: break
	ks = map(int, raw_input().split())
	oms = list(raw_input())
	nms = []
	for ki, om in enumerate(oms):
		k = ks[ki%kl]
		nm = f(om,k)
		nms.append(nm)
	print "".join(nms)

Submission status: Accepted

Solution code:
#!/usr/bin/python                                                                                                                                 
# -*- coding: utf-8 -*-                                                                                                                           

import sys


def main():
    station = ""
    for c in range(ord('a'), ord('z') + 1):
        station += chr(c)
    for c in range(ord('A'), ord('Z') + 1):
        station += chr(c)

    while True:
        n = int(sys.stdin.readline())
        if n == 0:
            return 0

        l = sys.stdin.readline()
        l = map(lambda x: int(x), l.split())

        s = sys.stdin.readline().rstrip()
        res = ""
        for i, x in enumerate(s):
            index = ord(x) - (ord('a') if x.islower() else ord('A') + 26) - l[i % len(l)]
            index %= len(station)
            res += station[index]
        print res

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    a=list(map(int,input().split()))
    s=list(input())
    for i in range(len(s)):
        for j in range(a[i%n]):
            if s[i]=='A':s[i]='z'
            elif s[i]=='a':s[i]='Z'
            else:s[i]=s[i]=chr(ord(s[i])-1)
    print(*s,sep='')

Submission status: Accepted

Solution code:
d = ''
for i in range(26):
    d += chr(ord('a') + i)
for i in range(26):
    d += chr(ord('A') + i)

def decode(c,key):
    i = d.find(c)
    return d[(i-key) % 52]

while True:
    N = int(input())
    if N == 0: break
    ks = list(map(int,input().split()))
    S = input()
    ans = ''
    for i,c in enumerate(S):
        ans += decode(c, ks[i%N])
    print(ans)

Submission status: Accepted

Solution code:
abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

while True:
    n = int(input())
    if n == 0:
        break

    k = list(map(int, input().split()))
    s = str(input())
    for itr, c in enumerate(s):
        idx = abc[(abc.find(c) - k[itr % n] + 52) % 52]
        print(idx, end = "")
    print()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    s = string.ascii_letters

    while True:
        n = I()
        if n == 0:
            break
        a = LI()
        l = len(a)
        t = S()
        r = ''
        for i in range(len(t)):
            c = t[i]
            b = a[i%n]
            ci = s.index(c)
            r += s[ci-b]
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
import string 
letters = string.ascii_letters

while True:
    n = int(input())
    if n == 0:
        exit(0)
    k = list(map(int, input().split()))
    s = input()
    
    res = ""
    i = 0
    for x in s:
        res += letters[letters.find(x) - k[i]]
        i = (i + 1) % n

    print(res)

Submission status: Accepted

Solution code:
def reset(n_lis,chr_lis):
    k = len(n_lis)
    for i in range(len(chr_lis)):
        n = ord(chr_lis[i])
        a = n_lis[i%k]
        """
 #       print(n_lis)
       # if  n>96 and n-a<97:
            n -= 6
        if n-a<65:
            n+=58
        n-=a
        chr_lis[i]=chr(n)
"""
        c_type = True
        n -= 64
        if n > 27:
            n -=32
            c_type = False
        n -= a
        if n<1:
            n+=26
            c_type=not(c_type)
        if n<1:
            n+=26
            c_type=not(c_type)
        
        if c_type:
            n+=64
        else:
            n+=96
        
        chr_lis[i]=chr(n)


    for ch in chr_lis:
        print(ch,end='')
    print()

while True:
    if input()=='0':
        break
    n_lis = [int(i) for i in input().split(' ')]
    c_lis = [i for i in input()]
    reset(n_lis,c_lis)

Submission status: Accepted

Solution code:
from itertools import cycle
f=lambda a,b:[chr(i) for i in range(a,b)]
c=(f(97,123)+f(65,91))[::-1]
c*=2
while int(input()):
    l=cycle(map(int,input().split()))
    s=input()
    print("".join([c[c.index(i)+j] for (i,j) in zip(s,l)]))

Submission status: Accepted

Solution code:
L=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', '\
P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', \
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',\
 'v', 'w', 'x', 'y', 'z']
while True:
    n=input()
    if n==0:break
    K=map(int,raw_input().split())
    s=raw_input()
    ans=""
    i=0
    for c in s:
        idx=L.index(c)
        ans+=L[idx-K[i]]
        i+=1
        if i>=n:
            i%=n
    print ans

Submission status: Accepted

Solution code:
ref="ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
while 1:
	n=input()
	if n==0:break
	key=map(int,raw_input().split())
	code=list(raw_input())
	for i in range(len(code)):
		code[i]=ref[(ref.index(code[i])+key[i%n])%52]
	print "".join(map(str,code))

Submission status: Accepted

Solution code:
station = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
while True:
    n = input()
    if n==0:
        break
    k = map(int, raw_input().split())
    s = raw_input()
    print "".join(station[(station.find(s[i])-k[i%n]+52)%52] for i in xrange(len(s)))

Submission status: Accepted

Solution code:
while True :
    n = int(input())
    if n == 0 :
        break
    key = list(map(int, input().split()))
    station = list(input())
    
    i = 0
    j = 0
    while True :
        if i == len(station) :
            break
        if j == len(key) :
            j = 0
        if 97 <= ord(station[i]) <= 122 :
            x = ord(station[i]) - key[j]
            if 71 <= x <= 96 :
                x -= 6
            elif 45 <= x <= 70 :
                x += 52
        elif 65 <= ord(station[i]) <= 90 :
            x = ord(station[i]) - key[j]
            if 39 <= x <= 64 :
                x += 58
            elif 13 <= x <= 38 :
                x += 52
        print(chr(x), end="")
        
        i += 1
        j += 1
    print()

Submission status: Accepted

Solution code:
a = []
for i in range(26):
    a.append(chr(97+i))
for i in range(26):
    a.append(chr(65+i))

while 1:
    n = int(input())
    if n == 0: break
    k = list(map(int, input().split()))
    s = input()
    for i in range(len(s)):
        print(a[(a.index(s[i]) - k[i%n])%52], end='')
    print()

Submission status: Accepted

Solution code:
"王様の視察"
while True:
    N = int(input())
    if N == 0:
        break
    K = list(map(int, input().split()))
    S = str(input())

    ans = ""
    station = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
    station_position = {}
    search_station = {}
    # 双方向の辞書を作成する
    for i, s in enumerate(station, start=1):
        station_position.setdefault(i)
        station_position[i] = s  # keyが数字で、バリューが文字
        search_station[s] = i  # keyが文字で、バリューが数字
    i = 0
    for s in S:
        encryption = search_station[s]  # 数字
        encryption -= K[i]
        if encryption <= 0:
            encryption += 52
        ans += station_position[encryption]
        i += 1
        if i == len(K):
            i = 0
    print(ans)

Submission status: Accepted

Solution code:
alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
while True:
    n = int(input())
    if n == 0:
        break
    else:
        k = [int(k) for k in input().split()]
        s = list(input())
        for i in range(1,len(s)+1):
            if (i) % len(k) == 0:
                s[i-1] = alphabet[alphabet.index(s[i-1])-k[len(k)-1]]
            else:
                s[i-1] = alphabet[alphabet.index(s[i-1])-k[i % len(k)-1]]
        print("".join(s))

Submission status: Accepted

Solution code:
def main():
    while True:
        n = int(input())
        if n == 0:
            return
        kk = list(map(int,input().split()))
        S = input()
        ans = ""
        for i,s in enumerate(S):
            if s.islower():
                k = (ord(s)-ord('a')-kk[i%len(kk)])
                if k < -26:
                    ans += chr(ord('a')+k%26)
                elif k < 0:
                    ans += chr(ord('A')+k%26)
                else:
                    ans += chr(ord('a')+k)
            if s.isupper():
                k = (ord(s)-ord('A')-kk[i%len(kk)])
                if k < -26:
                    ans += chr(ord('A')+k%26)
                elif k < 0:
                    ans += chr(ord('a')+k%26)
                else:
                    ans += chr(ord('A')+k)
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# from sys import exit

alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g',
        'h', 'i', 'j', 'k', 'l', 'm', 'n',
         'o', 'p', 'q', 'r', 's', 't', 'u',
          'v', 'w', 'x', 'y', 'z']
alp += [a.upper() for a in alp]
id = [i for i in range(0, 52)]
alp2num = dict(zip(alp, id))
num2alp = dict(enumerate(alp))
while(True):
    N = int(input())
    if N == 0:
        exit()
    k = [int(n) for n in input().split()]
    S = input()
    L = len(S)
    for i in range(L):
        id = alp2num[S[i]]-k[i % N] % 52
        if id < 0:
            id += 52
        print(num2alp[id], end="")
    print()

Submission status: Accepted

Solution code:
word_list=[]
for i in range(97,123):
    word_list.append(chr(i))
for i in range(65,91):
    word_list.append(chr(i))
l_w_l=len(word_list)
while 1:
    n=int(input())
    if n==0:break
    li=list(map(int,input().split()))
    s=input()
    ans=""
    for i in range(len(s)):
        w_k=word_list.index(s[i])-li[i%n]
        while w_k<0:w_k+=l_w_l
        ans+=word_list[w_k]
    print(ans)

Submission status: Accepted

Solution code:
alpha = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

while 1:
    n = int(input())
    if n == 0:
        break
    K = list(map(int, input().split()))
    S = list(input())

    ans = ""
    for i, s in enumerate(S):
        diff = K[i % len(K)]
        if diff <= 0:
            num = 52 + diff
        else:
            num = diff
        ans += alpha[alpha.index(s)-num]

    print(ans)

Submission status: Accepted

Solution code:
def horizontal_input(T=str):
    return list(map(T,input().split()))

def vertical_input(n,T=str,sep=False,septype=tuple):
    data=[]
    if sep:
        for i in range(n):
            data.append(septype(map(T,input().split())))
    else:
        for i in range(n):
            data.append(T(input()))
    return data

d='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
while 1:
    n=int(input())
    if n==0:
        break
    data=horizontal_input(int)
    s=input()
    ans=[]
    i=0
    for c in s:
        ans.append(d[d.find(c)-data[i]])
        i=(i+1)%len(data)
    print(''.join(ans))

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        self.chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            k = map(int, raw_input().split())
            s = raw_input()
            ans = ''
            for i in range(len(s)):
                ans += self.chars[self.chars.index(s[i]) - k[i % len(k)]]
            print ans
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python                                                                                                                                 
# -*- coding: utf-8 -*-                                                                                                                           

import sys


station = ""
for c in range(ord('a'), ord('z') + 1):
    station += chr(c)
for c in range(ord('A'), ord('Z') + 1):
    station += chr(c)

while True:
    n = int(sys.stdin.readline())
    if n == 0:
        break

    l = sys.stdin.readline()
    l = map(lambda x: int(x), l.split())

    s = sys.stdin.readline().rstrip()
    res = ""
    for i, x in enumerate(s):
        index = ord(x) - (ord('a') if x.islower() else ord('A') + 26) - l[i % len(l)]
        res += station[index]
    print res

Submission status: Runtime Error

Solution code:
#!/usr/bin/python                                                                                                                                 
# -*- coding: utf-8 -*-                                                                                                                           

import sys


def main():
    station = ""
    for c in range(ord('a'), ord('z') + 1):
        station += chr(c)
    for c in range(ord('A'), ord('Z') + 1):
        station += chr(c)

    while True:
        n = int(sys.stdin.readline())
        if n == 0:
            break

        l = sys.stdin.readline()
        l = map(lambda x: int(x), l.split())

        s = sys.stdin.readline().rstrip()
        res = ""
        for i, x in enumerate(s):
            index = ord(x) - (ord('a') if x.islower() else ord('A') + 26) - l[i % len(l)]
            res += station[index]
        print res

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python                                                                                                                                 
# -*- coding: utf-8 -*-                                                                                                                           

import sys


def main():
    station = ""
    for c in range(ord('a'), ord('z') + 1):
        station += chr(c)
    for c in range(ord('A'), ord('Z') + 1):
        station += chr(c)

    while True:
        n = int(sys.stdin.readline())
        if n == 0:
            return

        l = sys.stdin.readline()
        l = map(lambda x: int(x), l.split())

        s = sys.stdin.readline().rstrip()
        res = ""
        for i, x in enumerate(s):
            index = ord(x) - (ord('a') if x.islower() else ord('A') + 26) - l[i % len(l)]
            res += station[index]
        print res

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python                                                                                                                                 
# -*- coding: utf-8 -*-                                                                                                                           

import sys


def main():
    station = ""
    for c in range(ord('a'), ord('z') + 1):
        station += chr(c)
    for c in range(ord('A'), ord('Z') + 1):
        station += chr(c)

    while True:
        n = int(sys.stdin.readline())
        if n == 0:
            return 0

        l = sys.stdin.readline()
        l = map(lambda x: int(x), l.split())

        s = sys.stdin.readline().rstrip()
        res = ""
        for i, x in enumerate(s):
            index = ord(x) - (ord('a') if x.islower() else ord('A') + 26) - l[i % len(l)]
            res += station[index]
        print res

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
 while 1:
	n = int(input())
	k_line = list(map(int, input().split()))
	s = input()
	if (n == 0):
		break;
	alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
	k_line *= (-(-len(s)//len(k_line)))
	for num, c in enumerate(s):
		index = alpha.index(c) - k_line[num]
		print(alpha[index], end='')
	print('')

Submission status: Runtime Error

Solution code:
while 1:
    n = int(input())
    k_line = list(map(int, input().split()))
    s = input()
    if (n == 0):
        break;
    alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    k_line *= (-(-len(s) // len(k_line)))
    s = [alpha[(alpha.index(c) + 52*10 - k_line[num])%52] for num, c in enumerate(s)]

    print("".join(s))

Submission status: Runtime Error

Solution code:
ef suber(c, k):
    if ord('a')<=ord(c):
        w = ord(c) - ord('a')
        if w < k:
            return chr(ord('Z') - (k - w - 1)) if k<=26 else chr(ord('z') - (k - w - 27))
        return chr(ord('a') + (w - k))
    else:
        w = ord(c) - ord('A')
        if w < k:
            return chr(ord('z') - (k - w - 1)) if k<=26 else chr(ord('Z') - (k - w - 27))
        return chr(ord('A') + (w - k))
while True:
    n = input()
    if n==0:
        break
    k = map(int, raw_input().split())
    s = raw_input()
    print "".join(suber(s[i], k[i%n]) for i in xrange(len(s)))

Submission status: Runtime Error

Solution code:
station = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQESTUVWXYZ"
while True:
    n = input()
    if n==0:
        break
    k = map(int, raw_input().split())
    s = raw_input()
    print "".join(station[station.find(s[i])-k[i%n]] for i in xrange(len(s)))