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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Python
  3. Itertools
  4. Maximize It!

Maximize It!

Problem
Submissions
Leaderboard
Discussions
Editorial
  1. Prepare
  2. Python
  3. Itertools
  4. Maximize It!
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial

You are given a function . You are also given lists. The list consists of elements.

You have to pick one element from each list so that the value from the equation below is maximized:

%

denotes the element picked from the list . Find the maximized value obtained.

denotes the modulo operator.

Note that you need to take exactly one element from each list, not necessarily the largest element. You add the squares of the chosen elements and perform the modulo operation. The maximum value that you can obtain, will be the answer to the problem.

Input Format

The first line contains space separated integers and .
The next lines each contains an integer , denoting the number of elements in the list, followed by space separated integers denoting the elements in the list.

Constraints




Output Format

Output a single integer denoting the value .

Sample Input

3 1000
2 5 4
3 7 8 9 
5 5 7 8 9 10 

Sample Output

206

Explanation

Picking from the st list, from the nd list and from the rd list gives the maximum value equal to % = .

  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy