CF628F.Bear and Fair Set

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Limak is a grizzly bear. He is big and dreadful. You were chilling in the forest when you suddenly met him. It's very unfortunate for you. He will eat all your cookies unless you can demonstrate your mathematical skills. To test you, Limak is going to give you a puzzle to solve.

It's a well-known fact that Limak, as every bear, owns a set of numbers. You know some information about the set:

  • The elements of the set are distinct positive integers.
  • The number of elements in the set is nn . The number nn is divisible by 55 .
  • All elements are between 11 and bb , inclusive: bears don't know numbers greater than bb .
  • For each rr in 0,1,2,3,4{0,1,2,3,4} , the set contains exactly elements that give remainder rr when divided by 55 . (That is, there are elements divisible by 55 , elements of the form 5k+15k+1 , elements of the form 5k+25k+2 , and so on.)

Limak smiles mysteriously and gives you qq hints about his set. The ii -th hint is the following sentence: "If you only look at elements that are between 11 and upToiupTo_{i} , inclusive, you will find exactly quantityiquantity_{i} such elements in my set."

In a moment Limak will tell you the actual puzzle, but something doesn't seem right... That smile was very strange. You start to think about a possible reason. Maybe Limak cheated you? Or is he a fair grizzly bear?

Given nn , bb , qq and hints, check whether Limak can be fair, i.e. there exists at least one set satisfying the given conditions. If it's possible then print ''fair". Otherwise, print ''unfair".

输入格式

The first line contains three integers nn , bb and qq ( 5<=n<=b<=1045<=n<=b<=10^{4} , 1<=q<=1041<=q<=10^{4} , nn divisible by 55 ) — the size of the set, the upper limit for numbers in the set and the number of hints.

The next qq lines describe the hints. The ii -th of them contains two integers upToiupTo_{i} and quantityiquantity_{i} ( 1<=upToi<=b1<=upTo_{i}<=b , 0<=quantityi<=n0<=quantity_{i}<=n ).

输出格式

Print ''fair" if there exists at least one set that has all the required properties and matches all the given hints. Otherwise, print ''unfair".

输入输出样例

  • 输入#1

    10 20 1
    10 10
    

    输出#1

    fair
    
  • 输入#2

    10 20 3
    15 10
    5 0
    10 5
    

    输出#2

    fair
    
  • 输入#3

    10 20 2
    15 3
    20 10
    

    输出#3

    unfair
    

说明/提示

In the first example there is only one set satisfying all conditions: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.

In the second example also there is only one set satisfying all conditions: {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}.

Easy to see that there is no set satisfying all conditions from the third example. So Limak lied to you :-(

首页