This page is still under construction.

Parts of this page are still being built. What you see may change.

Check the Check

Interview

Time limit2sMemory limit512 MB

Summary
Read dish names and price-quantity pairs until the line TOTAL, then print PAY if the waiter's total is at most the sum of price times quantity, else PROTEST.
Level

Easy2 of 10

Topics
Implementation, String, Math
Solved
No attempts yet

Problem

As a tourist in Paris, you are told to always check the itemized bill (also called the check) that arrives at the end of a meal, the one listing what you ordered and the total price. Such bills are often handwritten, and the waiter adds the total up by hand. You do not want to pay more than your meal costs, so you protest whenever a mistake favors the restaurant. If the restaurant charges you less than it should, you pay without a word.

Write a program that decides whether to pay the total printed on the check or to protest about it.

Input

The input consists of 2n+22n + 2 lines.

  • For every kk with 0≤k≤n−10 \le k \le n - 1, line 2k+12k + 1 holds the name dkd_k of an ordered dish.
  • For every kk with 0≤k≤n−10 \le k \le n - 1, line 2k+22k + 2 holds the integer price pkp_k of dkd_k in euros and the number of orders ckc_k of dkd_k, separated by one space.
  • Line 2n+12n + 1 holds the word TOTAL.
  • Line 2n+22n + 2 holds the integer total TT in euros computed by the waiter.

The value of nn is not given in the input. Read dish entries until you reach the line equal to TOTAL.

Limits

  • For every kk with 0≤k≤n−10 \le k \le n - 1:
    • dkd_k has at most 1000 characters, and is never equal to TOTAL;
    • 0≤pk≤10000 \le p_k \le 1000;
    • 0≤ck≤100 \le c_k \le 10;
  • 0≤n≤100 0000 \le n \le 100\,000;
  • T≤2 000 000 000T \le 2\,000\,000\,000.

Output

Print one line. Print PAY if the total TT on the check is less than or equal to the real total ∑k=0n−1pkck\sum_{k=0}^{n-1} p_k c_k, and PROTEST if it is larger.

Examples2

  1. Example 1

    Input
    Foie gras
    15 2
    Huîtres
    10 1
    Bœuf bourguignon
    18 1
    Magret de canard
    17 1
    Lapin à la moutarde
    16 1
    Crème brûlée
    6 1
    Mousse au chocolat
    5 2
    TOTAL
    100
    
    Expected output
    PAY
    
  2. Example 2

    Input
    Escargots de Bourgogne
    15 2
    Pâté en croûte
    10 1
    Blanquette de veau
    18 1
    Gratin dauphinois
    17 1
    Ratatouille
    16 1
    Profiteroles
    6 1
    Crêpe au sucre
    5 2
    TOTAL
    108
    
    Expected output
    PROTEST