PizzaSocks makes and delivers pizza on a regular schedule. A schedule has a period of 1, 2, 3, or 4 weeks, and the quantity of pizzas delivered is fixed for every day of the period. The first day of every period is always the first day of a week.
A schedule is described by:
A manager lost the schedule of one very important client; only the history of past deliveries survives. You must determine how well a schedule can explain that history.
The task is complicated because the client sometimes changed an order — asking for more or fewer pizzas than scheduled, cancelling an order entirely, or placing an unscheduled one — so no schedule may fit the history perfectly.
For a fixed schedule, count the number of days on which the recorded quantity differs from the quantity the schedule prescribes. Days before the first recorded order and after the last recorded order are ignored. Over all schedules whose period is 1, 2, 3, or 4 weeks, find the smallest possible number of such mismatched days.
The input consists of integers describing the delivery history:
There is at most one record for any single day. Every day that lies between the earliest and the latest recorded day but is not listed explicitly is treated as a day with a zero-quantity order. Weeks are aligned so that a schedule period always begins on the first day of a week.
Print a single integer: the minimum possible number of days on which the recorded quantity differs from the schedule, taken over all schedules whose period is 1, 2, 3, or 4 weeks.