Gourmet Cat
Contest: Codeforces Round 552 (Div. 3)
Difficulty rating: 1400
Tags: implementation, math

Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food:

- on Mondays, Thursdays and Sundays he eats fish food;
- on Tuesdays and Saturdays he eats rabbit stew;
- on other days of week he eats chicken stake.

Polycarp plans to go on a trip and already packed his backpack. His backpack contains:

- $$$a$$$ daily rations of fish food;
- $$$b$$$ daily rations of rabbit stew;
- $$$c$$$ daily rations of chicken stakes.

Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.

Input format:
The first line of the input contains three positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 7\cdot10^8$$$) — the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly.

Output format:
Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday — rabbit stew and during Wednesday — chicken stake. So, after four days of the trip all food will be eaten.

In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack.

In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be $$$99$$$ portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip.

Example input:
2 1 1

Example output:
4

Example input:
3 2 2

Example output:
7

Editorial:
Let the number of rations of fish food be $$$a_1$$$, the number of rations of rabbit stew be $$$a_2$$$ and the number of rations of chicken stakes be $$$a_3$$$ (so we have an array $$$a$$$ consisting of $$$3$$$ elements).
Let $$$full$$$ be the maximum number of full weeks cat can eat if the starting day of the trip can be any day of the week. The value of $$$full$$$ is $$$min(\lfloor\frac{a_1}{3}\rfloor, \lfloor\frac{a_2}{2}\rfloor, \lfloor\frac{a_3}{2}\rfloor)$$$.
Let's subtract the value $$$3 \cdot full$$$ from $$$a_1$$$, and $$$2 \cdot full$$$ from $$$a_2$$$ and $$$a_3$$$. We can see that we cannot feed the cat at least one more full week. So the final answer is $$$7 \cdot full + add$$$, where $$$add < 7$$$.
Now it's time for some good implementation! Of course, you can try to analyze all cases and handle them using ifs or something similar, but I will try to suggest you a good enough way to implement the remaining part of the problem:
Let's create an array $$$idx$$$ of length $$$7$$$, where $$$idx_i$$$ means the type of the food cat eats during the $$$i$$$-th day of the week ($$$1$$$ for fish food, $$$2$$$ for rabbit stew and $$$3$$$ for chicken stake). It will be $$$idx = [1, 2, 3, 1, 3, 2, 1]$$$.
Now let's iterate over the day we will start our trip. Let it be $$$start$$$. For the current starting day let $$$cur$$$ be the number of rations cat has eaten already (initially it is zero), $$$day$$$ be the current day of the trip (initially it is $$$start$$$) and the array $$$b$$$ be the copy of the array $$$a$$$. Then let's do the following sequence of the operations, while $$$b_{idx_{day}}$$$ is greater than zero: decrease $$$b_{idx_{day}}$$$ by one, increase $$$cur$$$ by one and set $$$day := day \% 7 + 1$$$ (take it modulo $$$7$$$ and add one). After this cycle we can update the answer with the value of $$$7 \cdot full + cur$$$.