EGYPIZZA - Pizza

no tags 

Abotrika is having a party because his team won the African cup so he is inviting his friends to eat some pizza. Unfortunately, his friends can't eat an entire pizza but all of them know exactly how much pizza they can eat and insist on getting the exact amount of pizza but Abotrika eats one complete pizza and all of them wants his amount of pizza in one slice. Their requests break down to three different pizza slices-either one quarter or a half or three quarters of pizza.

Write a program that will help Abotrika to find out what is the minimal number of pizzas he has to order so that everyone gets exact amount of pizza they want.

Input

First line contains an integer N, 0 ≤ N ≤ 10 000, the number of friends. In each of next N lines there is amount of pizza that each of Abotrika's friends wants to eat, that is the fraction 1/4, 1/2 or 3/4.

Output

In the first and only line you should write the minimal number of pizzas Abotrika has to order don't forget to order one complete pizza for Abotrika.

Example 1

Input:
3
1/2
3/4
3/4

Output:
4

Example 2

Input:
5
1/2
3/4
1/2
1/4
1/4 

Output:
4

hide comments
kkislay20: 2018-06-13 20:15:49





Thanks @ace_cocytus for your comment, your comment helped more than others
1. Pizzas 3/4 always take full portion
2. Pizzas 1/2 take a full portion including leftover (ceiling)
3.a. Pizzas 1/4 can take all leftovers from 3/4
3.b. Pizzas 1/4 can take last leftovers from pizza 1/2 (up to 2 portion)
3.c. Pizzas 1/4 can take 4 portion full pizza

zephyr_96: 2018-03-20 21:09:34

Good question !!

sinersnvrsleep: 2018-02-11 07:34:07

spoj toolkit is giving wrong answers for 4 (1/4) case

bani_raheja: 2017-12-28 22:37:30

instead of checking the test cases, just keep in mind that you should maintain pairing up of 1/4 and 3/4 as the highest priority and then proceed onto further cases. 3/4 and 1/2 cannot be paired.

nessaa_05: 2017-07-26 14:50:33

got me 20 wa :( because of zero and then only ac

Last edit: 2017-07-26 14:50:49
monukumar: 2017-07-06 20:17:57

use bufferreader for java..

shauryauppal: 2017-06-19 10:41:02

After 2WA got AC

Consider
3/4+1/4=1
1/2+1/4+1/4=1


First store all the counts ct1 for 1/2 , ct2 for 3/4 ,ct3 for 1/4
This way you will solve this easily.

This Test case is posted by many people and is misleading O/p->6
12
3/4
3/4
3/4
1/4
1/4
1/4
1/4
1/4
1/4
1/4
1/2
1/2

o/p=6
Sometimes even spojtoolkit can be Wrong XD.

bsiddhartha: 2017-06-14 08:22:54

easy logic :)
cut pizza... haha

kspoj: 2017-06-10 18:06:04

how is 4 the answer for the first test case they've given? It should be three right?
1 (for Abotrika) + 1/2 + 3/4 + 3/4 = 1 + 2/4 + 3/4 + 3/4 = 1 + 8/4 = 3 right?
Please help ...

adarsh035: 2017-06-03 16:50:43

For case 9: check
37
1/2
1/2
1/4
1/2
3/4
1/4
1/2
3/4
3/4
1/4
1/4
1/2
3/4
3/4
1/2
1/4
3/4
1/4
1/2
3/4
1/2
1/2
1/2
3/4
1/4
1/4
1/4
1/4
1/4
3/4
1/4
1/4
1/4
3/4
1/4
1/4
1/4

Output: 18


Added by:Kawmia Institutes
Date:2010-08-18
Time limit:0.204s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 BF LISP sbcl LISP clisp JS-RHINO LUA OBJC PHP VB.NET
Resource:Croatian Highschool Competitions in Informatics 2004