题库练习 Splitting in Teams
← 上一题 下一题 →

A11383 | Splitting in Teams

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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.

输入格式

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$ .

输出格式

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

输入输出样例

输入 #1
4
1 1 2 1
输出 #1
1
输入 #2
2
2 2
输出 #2
0
输入 #3
7
2 2 2 1 1 1 1
输出 #3
3
输入 #4
3
1 1 1
输出 #4
1
C++ 编辑器
输入
输出