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. All Contests
  2. ProjectEuler+
  3. Project Euler #93: Arithmetic expressions

Project Euler #93: Arithmetic expressions

Problem
Submissions
Leaderboard
Discussions

This problem is a programming version of Problem 93 from projecteuler.net

By using each of the digits from the set, , exactly once, and making use of the four arithmetic operations and brackets/parentheses, it is possible to form different positive integer targets.

For example,




Note that concatenations of the digits, like , are not allowed.

Using the set, , it is possible to obtain thirty-one different target numbers of which 36 is the maximum, and each of the numbers to can be obtained before encountering the first non-expressible number.

Given a set of distinct digits, , find the largest possible integer such that each integer from to is expressible using elements of and following the above rules. If is also not expressible, output instead.

Input Format

The first line contains .
The second line contains space separated integers, the elements of .

Constraints

Output Format

Output a single integer, the answer to the problem.

Sample Input

4
1 2 3 4

Sample Output

28

Explanation

Explained in the statement.

Author

shashank21j

Difficulty

Medium

Max Score

100

Submitted By

1095

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy