406746: GYM102535 C Working with Locks 3

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Working with Locks 3time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Dr. Doofenshmirtz did something to the space-time continuum.

Now there are one billion days, one billion locks, and one billion keys. This is the type of thing that only happens in cartoons and math problems!!

1,000,000,000 days of summer vacation and school comes along just to end it! For the rest of summer vacation, Dr. Doofenshmirtz will occasionally be doing things to take over the Greater Tri-State Area and Perry the Platypus has to stop him.

The good news is that Agent P has managed to make an imprint of a set of keys and duplicate all of them. The bad news is that each day, Perry will be locked inside a different room with a different lock. And the set of keys he has might not have a correct key to open the lock on some days.

There are a total of 1,000,000,000 different locks, one for each day of summer vacation, and there are 1,000,000,000 different keys. As before, each key can open a lock if the difference between their numbers is exactly one. To be more explicit:

  • Key #1 can open lock #2.
  • Key #2 can open lock #1 and lock #3.
  • Key #3 can open lock #2 and lock #4.
  • ...
  • Key #999,999,998 can open lock #999,999,997 and lock #999,999,999.
  • Key #999,999,999 can open lock #999,999,998 and lock #1,000,000,000.
  • Key #1,000,000,000 can open lock #999,999,999.

You will be given the set of keys that Perry the Platypus has as well as the lock numbers on the days that Dr. Doofenshmirtz will be active.

Output how many days Perry can successfully stop the mad doctor.

Input

Each test case consists of four lines.

The first line contains an integer $$$k$$$, the number of keys that Perry has.

The second line contains $$$k$$$ space-separated integers representing each key $$$k_i$$$.

The third line contains an integer $$$L$$$, the number of locks.

The fourth line contains $$$L$$$ space-separated integers, representing each lock $$$L_i$$$.

Constraints

$$$1 \le k \le 10^5$$$

$$$1 \le k_i \le 10^9$$$

$$$1 \le L \le 10^5$$$

$$$1 \le L_i \le 10^9$$$

No two $$$k_i$$$s are the same.

No two $$$L_i$$$s are the same.

Output

Output a single integer, the number of days that Perry can successfully stop Dr. Doofenshmirtz.

ExampleInput
5
2 4 6 8 10
3
1 5 102
Output
2

加入题单

算法标签: