Problem4538--找零

4538: 找零

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

有 lns="http://www.w3.org/1998/Math/MathML">N 名顾客,在一台自动售票机面前排队购票。一开始,售票机里没有任何纸币,每张票售价 lns="http://www.w3.org/1998/Math/MathML">5 元。

每名顾客只买一张票也只会塞一张纸币,纸币面额只可能是 lns="http://www.w3.org/1998/Math/MathML">5 元、lns="http://www.w3.org/1998/Math/MathML">10 元、lns="http://www.w3.org/1998/Math/MathML">20元中的一种。

售票机可以将先收到的纸币当零钱找给后来的顾客。当售票机的零钱不足时,它将拒绝出票,否则,售票机不能拒绝出票。

请计算,若售票机以最好策略找零,则能够卖出多少张票。

Input

  • 第一行:单个整数 lns="http://www.w3.org/1998/Math/MathML">N
  • 第二行:lns="http://www.w3.org/1998/Math/MathML">N 个整数表示 lns="http://www.w3.org/1998/Math/MathML">N 名客户所塞入的纸币面额,保证只可能是 lns="http://www.w3.org/1998/Math/MathML">5lns="http://www.w3.org/1998/Math/MathML">10lns="http://www.w3.org/1998/Math/MathML">20 中的一个。

1≤N≤50,000


Output

  • 单个整数:表示售票机卖出的最多票数。

Sample Input Copy

8
10 5 5 5 10 10 20 20

Sample Output Copy

6

Source/Category