43C.md (2056B)
1 Source: https://codeforces.com/problemset/problem/43/C 2 3 C. Lucky Tickets 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid also threw part of the pieces away. Having seen this, Vasya got terrified but still tried to restore the collection. He chose several piece pairs and glued each pair together so that each pair formed a lucky ticket. The rest of the pieces Vasya threw away reluctantly. Thus, after the gluing of the 2*t* pieces he ended up with *t* tickets, each of which was lucky. 22 23 When Leonid tore the tickets in two pieces, one piece contained the first several letters of his number and the second piece contained the rest. 24 25 Vasya can glue every pair of pieces in any way he likes, but it is important that he gets a lucky ticket in the end. For example, pieces 123 and 99 can be glued in two ways: 12399 and 99123. 26 27 What maximum number of tickets could Vasya get after that? 28 29 Input 30 31 The first line contains integer *n* (1 ≤ *n* ≤ 104) — the number of pieces. The second line contains *n* space-separated numbers *a**i* (1 ≤ *a**i* ≤ 108) — the numbers on the pieces. Vasya can only glue the pieces in pairs. Even if the number of a piece is already lucky, Vasya should glue the piece with some other one for it to count as lucky. Vasya does not have to use all the pieces. The numbers on the pieces an on the resulting tickets may coincide. 32 33 Output 34 35 Print the single number — the maximum number of lucky tickets that will be able to be restored. Don't forget that every lucky ticket is made of exactly two pieces glued together. 36 37 Examples 38 39 Input 40 41 ``` 42 3 43 123 123 99 44 ``` 45 46 Output 47 48 ``` 49 1 50 ``` 51 52 Input 53 54 ``` 55 6 56 1 1 1 23 10 3 57 ``` 58 59 Output 60 61 ``` 62 1 63 ```