QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#8632. Arithmetic Combination Lock

统计

Little C has installed a combination lock on his bicycle, but he often struggles with forgetting the password. Although his memory is not great, Little C possesses extraordinary calculation skills, so he designed a special combination lock for himself.

This combination lock has 6 positions. Like a conventional combination lock, each position is a dial that can be rotated freely. However, instead of a simple arrangement of digits 0–9, each dial contains specific numbers or symbols:

  • The 1st, 3rd, 5th, and 6th dials each contain digits.
  • The 2nd dial contains operators, with 4 possibilities: addition (+), subtraction (-), multiplication (*), and division (/).
  • The 4th dial contains relational operators, with 3 possibilities: greater than (>), equal to (=), and less than (<).

Each dial contains $n$ numbers or characters. By rotating the dials, these numbers and characters can form $n$ different equations when viewed from different angles. For any given rotation of the dials, some of these $n$ equations will be correct and others will be incorrect. Little C has carefully designed the lock so that it opens when the dials are rotated to a position where the number of correct equations is maximized.

With Little C's calculation skills, he can determine on the spot how to rotate the dials to maximize the number of correct equations. You are curious about this lock and want to try to open it, but since you lack his calculation skills, you decide to write a program to help.

Note that equations with leading zeros are considered correct, such as 1+1=02 or 2-2=00. Division is mathematical division, not integer division as in computer science; for example, an equation like 9/4=02 is considered incorrect. Equations involving division by zero are considered incorrect, such as 1/0=00.

Input

Read from standard input.

The first line contains a positive integer $n$, representing the number of equations the lock can form, which is also the number of characters on each dial.

The next 6 lines each contain a string $s_i$ of length $n$, representing the numbers or symbols on the $i$-th dial from left to right (described in order starting from the initial position of the dial). Among these:

  • The characters in $s_1, s_3, s_5, s_6$ are digits (0123456789).
  • The characters in $s_2$ are operators (+-*/).
  • The characters in $s_4$ are relational operators (>=<).

Output

Output to standard output.

Output a single line containing a non-negative integer, representing the maximum number of correct equations possible after rotating the combination lock.

Examples

Input 1

2
23
*+
34
><
12
05

Output 1

2

Note

One way to rotate the dials so that both equations are correct is:

2+3<25
3*4>10

Input 2

10
0123456789
+-*/+-+-*/
0123456789
=<=>=<=>=>
0123456789
0123456789

Output 2

5

Constraints

For all test cases, it is guaranteed that $n \leq 10$.

Test Case ID $n \leq $ Special Property
$1\sim 2$ .h=4 $1$ AB
$3\sim 4$ A
$5\sim 6$ B
$7\sim 9$ None
$10\sim 11$ .h=2 $2$ AB
$12\sim 13$ .h=4 $10$ AB
$14\sim 15$ A
$16\sim 17$ B
$18\sim 20$ None

"Special Property A" means: $s_2$ contains only the character +.

"Special Property B" means: $s_4$ contains only the character =.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.