Bear and Fair Set

题意翻译

## 题目描述 Limak 是一只可怕的大灰熊。有一天你穿行在森林中,非常不幸地,你碰到了 Limak——它会吃掉你的所有曲奇(然而那是你准备野餐的零食 QwQ)除非你充分向它展示出你的数学才能。为了考验你的数学能力,它给你出了一道难题。 众所周知,Limak 就像其他熊一样,拥有一个集合: 1. 集合里的元素均为正整数且互不相同; 2. 元素的个数为 $n$ ,$n$ 是 $5$ 的倍数; 3. 元素的大小在 $1$ 和 $b$ 之间(包括 $1,b$); 4. 集合中恰有 $\frac n5$ 个数除以 $5$ 余 $0$、$\frac n5$ 个数除以 $5$ 余 $1$ …… $\frac n5$ 个数除以 $5$ 余 $4$; Limak 露出了狡黠的笑容(TAT)并给了你 $q$ 个关于这个集合的提示,每个提示表示如下: > 大小在 $1$ 到 $u_i$ 的元素恰好有 $t_i$ 个 于是你开始思考,突然你意识到有什么不对——Limak 是否在欺骗你?也就是说根本没有一个集合满足它的提示以及集合本身的要求? 如果存在至少一个集合满足条件,输出 "fair" 即 Limak 没有说谎;否则输出 "unfair" ,真是一只狡诈的灰熊! ## 输入 第一行为 $n,b,q$ ,含义见上文;接下来 $q$ 行,每行包括两个整数 $u_i,t_i$ ,表示一个提示。 ## 输出 一行,"fair" 或 "unfair"。 ## 数据规模 $4≤n≤b≤10^4$,$n$ 被 $5$ 整除;$1≤q≤10^4$;$1≤u_i≤b$;$0≤t_i≤ n$ 。

题目描述

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 $ n $ . The number $ n $ is divisible by $ 5 $ . - All elements are between $ 1 $ and $ b $ , inclusive: bears don't know numbers greater than $ b $ . - For each $ r $ in $ {0,1,2,3,4} $ , the set contains exactly ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF628F/3fde03ba1459bf896eaa2d517e8e4b61f6946c2a.png) elements that give remainder $ r $ when divided by $ 5 $ . (That is, there are ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF628F/3fde03ba1459bf896eaa2d517e8e4b61f6946c2a.png) elements divisible by $ 5 $ , ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF628F/3fde03ba1459bf896eaa2d517e8e4b61f6946c2a.png) elements of the form $ 5k+1 $ , ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF628F/3fde03ba1459bf896eaa2d517e8e4b61f6946c2a.png) elements of the form $ 5k+2 $ , and so on.) Limak smiles mysteriously and gives you $ q $ hints about his set. The $ i $ -th hint is the following sentence: "If you only look at elements that are between $ 1 $ and $ upTo_{i} $ , inclusive, you will find exactly $ quantity_{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 $ n $ , $ b $ , $ q $ 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 $ n $ , $ b $ and $ q $ ( $ 5<=n<=b<=10^{4} $ , $ 1<=q<=10^{4} $ , $ n $ divisible by $ 5 $ ) — the size of the set, the upper limit for numbers in the set and the number of hints. The next $ q $ lines describe the hints. The $ i $ -th of them contains two integers $ upTo_{i} $ and $ quantity_{i} $ ( $ 1<=upTo_{i}<=b $ , $ 0<=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 :-(