Log inSign up
Problems / B065

Lock passcode

300 ptsCases 15Set by dongbinna
Added October 30.
1 solved1 attempted1 submissionssolvers took 1.0 tries on average

Statement

A warehouse door has a dial lock on it. The passcode of this lock has k+1 digits, and each digit holds one of the numbers from 0 to 9. The numbers in the digits of the passcode are all different from each other. So the passcode cannot be longer than ten digits.

The person who installed the lock left a note so as not to forget the passcode. The note carries k signs that show how two neighboring digits compare. The i-th sign from the left is the result of comparing the number in digit i with the number in digit i+1. If the sign is <, the number on the left is smaller than the number on the right, and if it is >, the number on the left is larger than the number on the right.

Several passcodes can satisfy all the signs on the note. Write a program that, given the k signs, finds the largest and the smallest passcode among those that satisfy the conditions. Every passcode is the same length, k+1 digits, so the one that reads larger from the left is the larger passcode. A passcode with 0 in its first digit can also be used on the lock as it is.

For example, suppose k=2 and the signs on the note are as in the table below.

Sign number12
Sign<>

Here the passcode has three digits, the first digit has to be smaller than the second digit, and the second digit has to be larger than the third digit. The largest and the smallest passcode among those that satisfy the conditions are as follows.

KindPasscodeFirst digitSecond digitThird digit
Largest passcode897897
Smallest passcode021021

8 is smaller than 9 and 9 is larger than 7, so 897 satisfies the conditions. The second digit cannot go above 9, and a first digit above 8 would clash with the second digit, so there is no passcode larger than 897. Also 0 is smaller than 2 and 2 is larger than 1, so 021 satisfies the conditions too. 021 has 0 in its first digit, but it works as a three-digit passcode as it is, so it has to be given as 021, with the leading 0 kept.

Input and Output Examples

Example 1

Input

2
< >

Output

897
021

Example 2

Input

3
< < <

Output

6789
0123

Example 3

Input

3
> < <

Output

9678
1023

Input

  • First the number of signs k on the note is given on the first line. k is a natural number from 2 to 9. So the passcode is k+1 digits long, which is from 3 to 10.

  • Next the k signs are given on the second line, in order from the left, separated by spaces. Each sign is either < or >.

Output

  • Print the largest passcode that satisfies the conditions on the first line, and the smallest passcode on the second line. Both passcodes are k+1 digits long, so even when the leading digit is 0, keep that 0 and print all k+1 digits.

Requirements

  • The numbers in the digits of the passcode are all different from each other
  • The i-th sign is the result of comparing digit i with digit i+1
  • A passcode with 0 in its leading digit is also an answer when it satisfies the conditions
  • Keep the 0 in the leading digit and print all k+1 digits
  • You must write a program that reads from standard input and writes to standard output
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
  • There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 15 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.

Input
Expected output
2
< >
897
021
3
> < <
9678
1023
3
< < <
6789
0123

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 414ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 3 public cases. Submitting runs the hidden cases too.

People who solved this problem

The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.

1bampal255ms792 charsPythonWindows NT 10.0 / Chrome/156.0.0.0 / 8코어 / 16GB

Log in and you can see the code once you solve this problem.