A. Splitting in Teams
 
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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·105) — the number of groups.

The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.

Output

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

Examples
input
4
1 1 2 1
output
1
input
2
2 2
output
0
input
7
2 2 2 1 1 1 1
output
3
input
3
1 1 1
output
1
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).

代码:

 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
int n;
while(~scanf("%d",&n)){
int num1=,num2=;
for(int i=;i<n;i++){
int x;
scanf("%d",&x);
if(x==)num1++;
else num2++;
}
if(num2>num1)cout<<num1<<endl;
else cout<<num2+(num1-num2)/<<endl;
}
return ;
}
 
 

Codeforces 899 A.Splitting in Teams的更多相关文章

  1. Codeforces Round #452 (Div. 2)-899A.Splitting in Teams 899B.Months and Years 899C.Dividing the numbers(规律题)

    A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. CF899A Splitting in Teams

    CF899A Splitting in Teams 题意翻译 n个数,只有1,2,把它们任意分组,和为3的组最多多少 题目描述 There were nn groups of students whi ...

  3. 【Codeforces Round #452 (Div. 2) A】 Splitting in Teams

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心 1优先和2组队. 如果1没有了 就结束. 如果1还有多余的. 那么就自己3个3个组队 [代码] #include <bi ...

  4. CodeForces Round #527 (Div3) B. Teams Forming

    http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...

  5. Codeforces 872C Maximum splitting:数学【分解成合数之和】

    题目链接:http://codeforces.com/contest/872/problem/C 题意: 给你一个数n,问你最多能将n分解成多少个合数之和.(若不能分解,输出-1) 题解: 若要让合数 ...

  6. 【CodeForces 297C】Splitting the Uniqueness

    题意 序列s有n个数,每个数都是不同的,把它每个数分成两个数,组成两个序列a和b,使ab序列各自去掉个数后各自的其它数字都不同. 如果存在一个划分,就输出YES,并且输出两个序列,否则输出NO. 分析 ...

  7. Codeforces 899 F. Letters Removing (二分、树状数组)

    题目链接:Letters Removing 题意: 给你一个长度为n的字符串,给出m次操作.每次操作给出一个l,r和一个字符c,要求删除字符串l到r之间所有的c. 题解: 看样例可以看出,这题最大的难 ...

  8. Codeforces 870C Maximum splitting (贪心+找规律)

    <题目链接> 题目大意: 给定数字n,让你将其分成合数相加的形式,问你最多能够将其分成几个合数相加. 解题分析: 因为要将其分成合数相加的个数最多,所以自然是尽可能地将其分成尽可能小的合数 ...

  9. Codeforces 899 C.Dividing the numbers-规律

      C. Dividing the numbers   time limit per test 1 second memory limit per test 256 megabytes input s ...

随机推荐

  1. Tufurama CodeForces - 961E

    Tufurama CodeForces - 961E 题意:有一部电视剧有n季,每一季有ai集.问有多少对i,j存在第i季第j集也同时存在第j季第i集. 思路:核心问题还是统计对于第i季,你要统计第i ...

  2. A1025 PAT Ranking (25)(25 分)

    A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...

  3. 修改python新建文件时的模板

  4. android/libs/libammsdk.jar" already exists! 解决方法

    Error: Uh oh!"/work/2016/fengkongbao/.meteor/local/cordova-build/platforms/android/libs/libamms ...

  5. datagrid的右键菜单

    1. 2.右键菜单,主要是用onRowContextMenu:function(e,index,row){}方法来实现 onRowContextMenu:function(e,index,row){ ...

  6. java中equals和==

    https://www.cnblogs.com/bluestorm/archive/2012/03/02/2377615.html

  7. C 语言 习题 1-14

    练习 1-14 编写一个程序,打印输入中各个字符出现频度的直方图. #include <stdio.h> /* count digits, white space, others */ i ...

  8. Python基础-week06 面向对象编程基础

    一.面向对象编程 1.面向过程 与 面向对象编程 面向过程的程序设计: 核心是 过程二字,过程指的是解决问题的步骤,即先干什么再干什么......面向过程的设计就好比精心设计好一条流水线,是一种机械式 ...

  9. webpack vue-cli 常见问题总结

    1. webpack打包压缩 ES6 js..vue报错: ERROR in js/test.js from UglifyJs Unexpected token punc ?(?, expected ...

  10. android TranslateAnimation动画执行时的坐标获取。

    android 的Tween动画并不会改变控件的属性值,比如以下测试片段: 定义一个从屏幕右边进入,滚动到屏幕左边消失的一个TranslateAnimation动画: <?xml version ...