Problem p02618 (python)

Fixed submission:
from time import time
from random import randint

from numba import njit
from numpy import int64

@njit('i8(i8[:],i8[:])')
def func(s,x):
    last=[0]*26
    score=0
    for i,v in enumerate(x,1):
        last[v]=i
        c=0
        for j in range(26):
            c+=s[j]*(last[j]-i)
        score=score+s[i*26+v]-c
    return score

def main():
    start=time()
    d,*s=map(int,open(0).read().split())
    s=int64(s)
    x=int64(([*range(26)]*15)[:d])
    M=func(s,x)
    while time()-start<1:
        y=x.copy()
        y[randint(0,d-1)]=randint(0,25)
        t=func(s,y)
        if t>M:
            M=t
            x=y
    print(*x+1,sep='\n')

main()

Buggy submission (verdict: Runtime Error):
import sys
from time import time
from random import randint
from numpy import int64

def func(s, x, score, t1, t2, t3):
    if t1 == -1:
        for i in range(26):
            last = 0
            for j, v in enumerate(x, 1):
                if v == i:
                    last = j
                    score[i] += s[j * 26 + v]
                score[i] -= s[i] * (j - last)    
    if t1 > -1:
        last = score[t1] = 0
        for i, v in enumerate(x, 1):
            if v == t1:
                last = i
                score[t1] += s[i * 26 + v]
            score[t1] -= s[t1] * (i - last)
    if t2 > -1:
        last = score[t2] = 0
        for i, v in enumerate(x, 1):
            if v == t2:
                last = i
                score[t2] += s[i * 26 + v]
            score[t2] -= s[t2] * (i - last)
    if t3 > -1:
        last = score[t3] = 0
        for i, v in enumerate(x, 1):
            if v == t3:
                last = i
                score[t3] += s[i * 26 + v]
            score[t3] -= s[t3] * (i - last)
    score[26] = score[:26].sum()
    return score

def main():
    start = time()
    d, *s = map(int, sys.stdin.buffer.read().split())
    s = int64(s)
    x = int64(([*range(26)] * 15)[:d])
    score = func(s, x, int64([0] * 27), -1, -1, -1)
    while time() - start < 1.8:
        y = x.copy()
        if randint(0, 1):
            i = randint(0, d - 1)
            j = k = -1
            y[i] = randint(0, 25)
        elif randint(0, 1):
            i = randint(0, d - 16)
            j = randint(i + 1, i + 15)
            k = -1
            y[i], y[j] = y[j], y[i]
        else:
            i = randint(0, d - 15)
            j = randint(i + 1, i + 7)
            k = randint(j + 1, j + 7)
            if randint(0, 1):
                y[i], y[j], y[k] = y[j], y[k], y[i]
            else:
                y[i], y[j], y[k] = y[k], y[i], y[j]
        t = func(s, y, score, i, j, k)
        if t[26] > score[26]:
            score = t
            x = y
    print(*x + 1, sep='\n')

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('func', 'i8[:](i8[:], i8[:], i8[:], i8, i8, i8)')(func)
    cc.compile()

if __name__ == '__main__':
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import func
    main()

Buggy submission (verdict: Runtime Error):
import sys
from time import time
from random import randint
from numpy import int64

def func(s, x, score, t1, t2, t3):
    if t1 == -1:
        for i in range(26):
            last = 0
            for j, v in enumerate(x, 1):
                if v == i:
                    last = j
                    score[i] += s[j * 26 + v]
                score[i] -= s[i] * (j - last)    
    if t1 > -1:
        last = 0
        for i, v in enumerate(x, 1):
            if v == t1:
                last = i
                score[t1] += s[i * 26 + v]
            score[t1] -= s[t1] * (i - last)
    if t2 > -1:
        last = 0
        for i, v in enumerate(x, 1):
            if v == t2:
                last = i
                score[t2] += s[i * 26 + v]
            score[t2] -= s[t2] * (i - last)
    if t3 > -1:
        last = 0
        for i, v in enumerate(x, 1):
            if v == t3:
                last = i
                score[t3] += s[i * 26 + v]
            score[t3] -= s[t3] * (i - last)
    score[26] = score[:26].sum()
    return score

def main():
    start = time()
    d, *s = map(int, sys.stdin.buffer.read().split())
    s = int64(s)
    x = int64(([*range(26)] * 15)[:d])
    score = func(s, x, int64([0] * 27), -1, -1, -1)
    while time() - start < 1.88:
        y = x.copy()
        if randint(0, 1):
            i = randint(0, d - 1)
            j = k = -1
            y[i] = randint(0, 25)
        elif randint(0, 1):
            i = randint(0, d - 16)
            j = randint(i + 1, i + 15)
            k = -1
            y[i], y[j] = y[j], y[i]
        else:
            i = randint(0, d - 15)
            j = randint(i + 1, i + 7)
            k = randint(j + 1, j + 7)
            if randint(0, 1):
                y[i], y[j], y[k] = y[j], y[k], y[i]
            else:
                y[i], y[j], y[k] = y[k], y[i], y[j]
        t = func(s, y, score, i, j, k)
        if t[26] > score[26]:
            score = t
            x = y
    print(*x + 1, sep='\n')

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('func', 'i8[:](i8[:], i8[:], i8[:], i8, i8, i8)')(func)
    cc.compile()

if __name__ == '__main__':
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import func
    main()