#C8666. Ali's Change Problem

    ID: 52673 Type: Default 1000ms 256MiB

Ali's Change Problem

Ali's Change Problem

Ali runs a lemonade stall where each drink costs $25. Customers pay with bills of 25, 50, or 100 dollars. Ali must give the correct change to each customer in the order they come.

Rules:

  • If a customer pays with a $25 bill, no change is required.
  • If a customer pays with a $50 bill, Ali must provide $25 as change.
  • If a customer pays with a $100 bill, Ali must either provide one $50 bill and one $25 bill or three $25 bills as change.

Formally, if we denote the number of $25, $50, and $100 bills by $c_{25}$, $c_{50}$, and $c_{100}$ respectively, determine if there exists a valid sequence such that change is correctly given after each transaction.

inputFormat

The first line contains an integer nn, representing the number of customers. The second line contains nn space-separated integers, each being 25, 50, or 100, representing the bill each customer pays with in order.

outputFormat

Output a single line with either 'True' if Ali can provide the correct change to every customer, or 'False' otherwise.## sample

3
25 25 50
True