489B.md (1508B)
1 Source: https://codeforces.com/problemset/problem/489/B 2 3 B. BerSU Ball 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. 22 23 We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. 24 25 For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from *n* boys and *m* girls. 26 27 Input 28 29 The first line contains an integer *n* (1 ≤ *n* ≤ 100) — the number of boys. The second line contains sequence *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 100), where *a**i* is the *i*-th boy's dancing skill. 30 31 Similarly, the third line contains an integer *m* (1 ≤ *m* ≤ 100) — the number of girls. The fourth line contains sequence *b*1, *b*2, ..., *b**m* (1 ≤ *b**j* ≤ 100), where *b**j* is the *j*-th girl's dancing skill. 32 33 Output 34 35 Print a single number — the required maximum possible number of pairs. 36 37 Examples 38 39 Input 40 41 ``` 42 4 43 1 4 6 2 44 5 45 5 1 5 7 9 46 ``` 47 48 Output 49 50 ``` 51 3 52 ``` 53 54 Input 55 56 ``` 57 4 58 1 2 3 4 59 4 60 10 11 12 13 61 ``` 62 63 Output 64 65 ``` 66 0 67 ``` 68 69 Input 70 71 ``` 72 5 73 1 1 1 1 1 74 3 75 1 2 3 76 ``` 77 78 Output 79 80 ``` 81 2 82 ```