-
Notifications
You must be signed in to change notification settings - Fork 180
/
07 - Maximize It!.py
35 lines (26 loc) · 762 Bytes
/
07 - Maximize It!.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# ========================
# Information
# ========================
# Direct Link: https://www.hackerrank.com/challenges/maximize-it/problem
# Difficulty: Hard
# Max Score: 50
# Language: Python
# ========================
# Solution
# ========================
import itertools
NUMBER_OF_LISTS, MODULUS = map(int, input().split())
LISTS_OF_LISTS = []
for i in range(0, NUMBER_OF_LISTS):
new_list = list(map(int, input().split()))
del new_list[0]
LISTS_OF_LISTS.append(new_list)
def squared(element):
return element**2
COMBS = list(itertools.product(*LISTS_OF_LISTS))
RESULTS = []
for i in COMBS:
result1 = sum(map(squared, [a for a in i]))
result2 = result1 % MODULUS
RESULTS.append(result2)
print(max(RESULTS))