We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Python
  3. Itertools
  4. Maximize It!
  5. Discussions

Maximize It!

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 868 Discussions, By:

recency

Please Login in order to post a comment

  • dillonm483
    8 hours ago+ 0 comments
    import itertools
    
    k, m = [int(i) for i in input().split()]
    lists = [[int(j)**2 for j in input().split()[1:]] for i in range(k)]
    remainders = [sum(l) % m for l in itertools.product(*lists)]
    print(max(remainders))
    
    0|
    Permalink
  • jarek108
    9 hours ago+ 0 comments
    K, M = map(int, input().split())
    could = [0]
    for i in range(K):    
        new = list(map(int, input().split()))[1:]
        could = [(n*n + c) % M for n in new for c in could]
    print(max(could))
    
    0|
    Permalink
  • keshabkjha
    22 hours ago+ 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from itertools import product
    k, m = map(int, input().split())
    li = (list(map(int, input().split()))[1:] for _ in range(k))
    li = product(*li)
    s = [sum(map(lambda x: x*x, i))%m for i in li]
    print(max(s))
    
    0|
    Permalink
  • efremovdti
    7 days ago+ 0 comments
    from itertools import product
    K, M = map(int, input().split())
    S = [[int(i)**2 for i in input().split()[1:]] for k in range(K)]
    print(max(map(lambda x: sum(x) % M, product(*S))))
    
    0|
    Permalink
  • maxim_metelsky
    1 week ago+ 0 comments
    from itertools import *
    
    K, M = map(int, input().split())
    
    lists = []
    for i in range(K):
        lists.append(list(map(lambda x: int(x)**2, input().split()[1:])))
    
    pr = list(product(*lists))
    maximum = max(map(lambda x: sum(x) % M, pr))
    print(maximum)    
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy