Pets and Friends#11694

Pets and Friends

1 second
256 megabytes
Easy

Anton's birthday is coming soon, and he decided to invite his friends over. He has friends. Some of them have a dog, a cat, or both pets. But also some of them are afraid of dogs, cats, or both animals at the same time.

Information about the -th friend (1 \le i \le n) is represented with two integers a_i and b_i varying from to , where a_i corresponds to the pets that a friend has, and b_i corresponds to the animals which they are afraid of. Here are the meanings of these digits:

Let the "x y" person be a person that can be described with digits and . Here are some possible examples of friends:

All Anton's friends love their pets, so they will not come over without them. But he cannot invite a friend who is afraid of some species of animal and a friend who owns a pet of this species at once.

You need to determine the maximum number of friends Anton can invite.

Please note that:

Input

The first line contains one integer (1 \le n \le 10^5) — the number of Anton's friends.

Each of the next lines contains the information about each friend in the form of two digits a_i,b_i (0 \leq a_i,b_i \leq 3) separated by space, where a_i stands for pets a friend has and b_i — for animals they are afraid of.

It is guaranteed that there are no friends who are afraid of their pets.

Output

In the only line, you need to output the maximum number of guests that Anton can invite so that there are no friends who are afraid of any of the other's pets.

Examples

Example

Loading
Loading

Example 1

Loading
Loading

Example 2

Loading
Loading

Note

In the first sample, both friends cannot be invited at once since they both are afraid of each other's pet. But any one of them can still be the only friend invited.

In the second sample, Anton cannot invite all his friends at once since the second one has a cat which the first and the third ones are afraid of. But the first and the third friends can be invited together.

In the third sample, there are the possible combinations of friends invited:

  • the -st, -rd, and the -th ones;

  • the -nd, -th, and the -th ones.

It can be shown that Anton cannot invite more than friends in this sample.

Scoring

  1. ( points): none of the friends is afraid of either of the animals;

  2. ( points): every friend has exactly one pet and is afraid of exactly one animal;

  3. ( points): none of the friends has a cat;

  4. ( points): every friend has at most one pet and is afraid of at most one animal;

  5. ( points): n \le 20;

  6. ( points): no additional constraints.