Codeforces Round 452 (Div. 2)
A
Splitting in Teams
Codeforces
800
原题
←B →
翻译中…

There were $*n*$ groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.

翻译中…

The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.

翻译中…

Input

翻译中…

The first line contains single integer $*n*$ ($2 ≤ *n* ≤ 2·10^{5}$) — the number of groups.

翻译中…

The second line contains a sequence of integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($1 ≤ *a*_{*i*} ≤ 2$), where $*a*_{*i*}$ is the number of people in group $*i*$.

翻译中…

Output

翻译中…

Print the maximum number of teams of three people the coach can form.

翻译中…

Note

翻译中…

In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.

翻译中…

In the second example he can't make a single team.

翻译中…

In the third example the coach can form three teams. For example, he can do this in the following way:

翻译中…
  • The first group (of two people) and the seventh group (of one person),
  • The second group (of two people) and the sixth group (of one person),
  • The third group (of two people) and the fourth group (of one person).
翻译中…

样例

Input #1
4
1 1 2 1
Output #1
1
InputCopy OutputCopy
Input #2
2
2 2
Output #2
0
InputCopy OutputCopy
Input #3
7
2 2 2 1 1 1 1
Output #3
3
InputCopy OutputCopy
Input #4
3
1 1 1
Output #4
1
InputCopy OutputCopy
题目信息
题号
899A
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。