**OCTOBER LONG** * MARRAYS*:

Can anyone help me saying why my code is giving TLE although I had memoized and I think it runs in O(n1+n2+n3)?

My solution link: https://www.codechef.com/viewsolution/15900491

```
import sys
import math
memo = []
def taste(arrays, n, length, level, endidx):
if level == n: return 0
if memo[level][endidx] > -1:
#print(level, endidx, 'rerurned from memo')
return memo[level][endidx]
sum = 0
if level == 0:
for i in range (length[level]):
temp = taste(arrays, n, length, level + 1, (i-1)%length[level])
#memo[level][endidx] = temp
sum = max(sum, temp)
memo[level][endidx] = sum
#print(memo)
return sum
for i in range (length[level]):
#print('level = %d, length[level] = %d, endidx = %d, i = %d, (i - 1) mod length[level] = %d' %(level, length[level], endidx, i, (i - 1) % length[level]))
temp = abs(arrays[level - 1][endidx] - arrays[level][i]) * level + taste(arrays, n, length, level + 1, (i-1)%length[level])
#print(temp)
#memo[level][endidx] = temp
sum = max(sum, temp)
#print(sum)
memo[level][endidx] = sum
#print(memo)
return sum
t = int(sys.stdin.readline())
for _ in range (t):
arrays, length = [], []
n = int(sys.stdin.readline())
maxlen = 0
for __ in range (n):
temp = list(map(int, sys.stdin.readline().split()))
length.append(temp[0])
maxlen = max(maxlen, temp[0])
del temp[0]
arrays.append(temp)
#print(arrays)
memo = [[-1 for i in range (maxlen)] for j in range (n)]
#print(memo)
print(taste(arrays, n, length, 0, 0))
```

Plz someone help me

**And thanks in advance **