CF43C.Lucky Tickets

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

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.

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.

What maximum number of tickets could Vasya get after that?

瓦西娅认为,幸运车票是指其编号能被 33 整除的车票。他收集了相当多的此类车票,但有一天,他的弟弟列昂尼德闹脾气,决定毁掉这些收藏。他首先将每张车票恰好撕成两片;但他觉得这还不够,于是列昂尼德又扔掉了一部分碎片。瓦西娅看到后大为惊恐,但仍试图恢复收藏:他选出若干对碎片,并将每对碎片粘合在一起,使得每对粘合后都形成一张幸运车票;其余未配对的碎片则被瓦西娅不情愿地丢弃了。因此,在将 2t2t 片碎片粘合成 tt 张车票后,他最终得到了 tt 张幸运车票。

当列昂尼德将车票撕成两片时,其中一片包含该车票编号的前若干位数字,另一片包含剩余的后续数字。

瓦西娅可以以任意顺序将每对碎片拼接(即两片可互换前后位置),但关键在于:拼接后的完整数字必须是一张幸运车票。例如,碎片 123 和 99 可以以两种方式拼接:12399 或 99123。

问:瓦西娅最多能得到多少张车票?

输入格式

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.

第一行包含一个整数 nn(1≤n≤1041 \leq n \leq 10^4)—— 表示纸片的数量。
第二行包含 nn 个用空格分隔的整数 aia_i(1≤ai≤1081 \leq a_i \leq 10^8)—— 表示每张纸片上的数字。
瓦夏只能将纸片两两粘合。即使某张纸片上的数字本身已是“幸运数”,瓦夏仍需将其与另一张纸片粘合,该纸片才被计为幸运。
瓦夏不必使用所有纸片。
纸片上的数字以及最终生成的票面上的数字可以重复。

输出格式

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.

输出一个整数——能够恢复的幸运车票的最大数量。注意,每张幸运车票恰好由两片拼接而成。

输入输出样例

  • 输入#1

    3
    123 123 99

    输出#1

    1
  • 输入#2

    6
    1 1 1 23 10 3

    输出#2

    1

输入解题思路,AI测评打分。不知道怎么写?

首页