Q:

Finding squares of big numbers in python using math.pow

I am trying hackers rank to improve my python skills. I have picked a problem.I am able to solve this but I am not getting right output in all the scenarios. Below is the scenario
Link to problem is this
https://www.hackerrank.com/challenges/maximize-it/problem
Below is my code
import math
import sys
lis= sys.stdin.readlines()
def newFunc(lis):
    numLines = lis[0].split(" ")[0]
    divisor = lis[0].split(" ")[1]
    iter = 1
    newLis = []
    while(int(numLines) >= int(iter)) :
        paramNum = lis[iter].split(" ")[0]
        iter1 = 1
        bigNum = 0
        while(int(paramNum) >= int(iter1)):
            if int(lis[iter].split(" ")[iter1]) > bigNum:
                bigNum = int(lis[iter].split(" ")[iter1])
            iter1 = iter1 + 1
        newLis.append(bigNum)
        iter = iter + 1

    sum = 0
    for num in newLis:
        sum = sum + math.pow(num,2)

    finalNum = sum % int(divisor)
    return finalNum

value = newFunc(lis)
print int(value)

When I am testing my code against below output
5 84
1 765952241
3 289380515 265118103 309882974
2 747649220 587740446
2 682866882 596381508
1 342723101

Expected output is 83
Actual I am getting is 48
I don't know why. Can somebody help me with this

A:

try this
import itertools

(K, N) = map(int, raw_input().split())

L = list()
for i in range(K):
    l = map(int, raw_input().split())
    n = l[0]
    L.append(l[1:])
    assert len(L[i]) == n

S_max = 0
L_max = None

for l in itertools.product(*L):
    s = sum([x**2 for x in l]) % N

    if s > S_max:
        S_max = s
        L_max = l

print S_max

