This page is still under construction.

Parts of this page are still being built. What you see may change.

Traffic Volume

Interview

Time limit1sMemory limit256 MB

Summary
Count how many cars came from the left from the unordered times in two boxes with offsets of 500, 1000, and 1500.
Level

Medium5 of 10

Topics
Greedy, Sorting, Simulation
Solved
No attempts yet

Problem

Seungmin measures the traffic on the Mapo Bridge. He hung two strings across the road, parallel and a fixed distance apart. Every time a car wheel rolls over a string, a small box at the end of that string records the time. Records from the left string go into the left box, records from the right string go into the right box.

One car coming from the left leaves four records.

  • time tt, when the front wheels cross the left string
  • time t+500t + 500, when the rear wheels cross the left string
  • time t+1000t + 1000, when the front wheels cross the right string
  • time t+1500t + 1500, when the rear wheels cross the right string

A car coming from the right follows the same rule with left and right swapped. The right box gets tt and t+500t + 500, the left box gets t+1000t + 1000 and t+1500t + 1500.

At most one car is on a string at any moment. Given the recorded times in the two boxes, find how many cars came from the left.

Input

The first line has the number of test cases nn (1≤n≤1001 \le n \le 100).

The first line of each test case has mm (0≤m≤2000 \le m \le 200), the number of times recorded in one box. Each car leaves two records in each box, so mm is even. The second line has the mm times from the left box, and the third line has the mm times from the right box. Every time is a non-negative integer smaller than 10910^9, and the times come in no particular order. When m=0m = 0, both lines are empty.

The input can always be explained by a set of cars that obey the rules above.

Output

For each test case, print the number of cars that came from the left, one per line.

Examples4

  1. Example 1

    Input
    2
    4
    17 517 1432 1932
    432 932 1017 1517
    6
    235 451 735 951 2351 2851
    1235 1351 1451 1735 1851 1951
    
    Expected output
    1
    2
    
  2. Example 2

    Input
    2
    2
    0 500
    1000 1500
    2
    1000 1500
    0 500
    
    Expected output
    1
    0
    
  3. Example 3

    Input
    1
    4
    10 510 1010 1510
    1010 1510 10 510
    
    Expected output
    1
    
  4. Example 4

    Input
    3
    0
    
    
    2
    1007 1507
    7 507
    4
    7 507 2600 3100
    1007 1507 3600 4100
    
    Expected output
    0
    0
    2