Problem o: CCC '13 J5S3 - Chances of Winning

Problem o: CCC '13 J5S3 - Chances of Winning

Time Limit: 2 Sec  Memory Limit: 128 MB
Submit: 36  Solved: 12
[Submit] [Status] [Web Board] [Creator:]

Description

20points

English:

You want to determine the chances that your favourite team will be the champion of a small tournament.

There are exactly four teams. At the end of the tournament, a total of six games will have been played with each team playing every other team exactly once. For each game, either one team wins (and the other loses), or the game ends in a tie. If the game does not end in a tie, the winning team is awarded three points and the losing team is awarded zero points. If the game ends in a tie, each team is awarded one point.

Your favourite team will only be the champion if it ends the tournament with strictly more total points than every other team (i.e., a tie for first place is not good enough for your favourite team).

The tournament is not over yet but you know the scores of every game that has already been played. You want to consider all possible ways points could be awarded in the remaining games that have not yet been played and determine in how many of these cases your favourite team will be the tournament champion.





Chinese:  

您想确定您最喜欢的球队成为小型锦标赛冠军的机会。 总共有四支队伍。在锦标赛结束时,总共将进行六场比赛,每队比赛一次,每队比赛一次。对于每场比赛,一个队获胜(另一队输掉),或比赛以平局结束。如果比赛未平局,则获胜球队将获得3分,而失败球队将获得0分。如果比赛以平局结束,则每支球队将获得1分。 您最喜欢的球队只有在比赛结束时获得的总积分比其他所有球队都要多的情况下才能成为冠军(即,并列第一的平局对您最喜欢的球队而言还不够好)。 比赛尚未结束,但是您知道每场比赛的得分。您想考虑所有可能的方式来在尚未玩过的其余游戏中获得积分,并确定您最喜欢的球队在多少情况下将成为锦标赛冠军。



Input

The first line of input will contain an integer T which is your favourite team (1≤T≤4). The second line will contain an integer G, the number of games already played (0≤G≤5).  The next G lines will give the results of games that have already been played. Each of these lines will consist of four integers A, B, SA, SB separated by single spaces where 1≤A<B≤4, and SA,SB≥0. This corresponds to a game between team A(which had score SA) and team B (which had score SB) where team A won if SA>SB, team Bwon if SA<SB and the game ended in a tie if SA=SB. The pairs A and B on the input lines are distinct, since no pair of teams plays twice.        



输入的第一行将包含一个整数T,它是您最喜欢的团队(1≤T≤4)。 第二行将包含整数G,即已玩过的游戏数量(0≤G≤5)。 接下来的G行将给出已经玩过的游戏的结果。 这些行中的每行将由四个整数A,B,SA,SB组成,这些整数之间用单个空格分隔,其中1≤A<B≤4,并且SA,SB≥0。 这对应于A队(得分为SA)和B队(得分为SB)之间的一场比赛,如果SA> SBSA> SB,则A队获胜;如果SA <SBSA <SB,则BB队获胜,并且游戏以平局结束 如果SA = SB。 输入线上的A和B对是不同的,因为没有一对球队比赛两次。




Output

The output will consist of a single integer which is the number of times that team T is the champion over all possible awarding of points in the remaining games in the tournament.


输出将由单个整数组成,该整数是T团队在锦标赛剩余比赛中所有可能的积分奖励中获得冠军的次数。

Sample Input Copy

Sample Input 1
3
3
1 3 7 5
3 4 0 8
2 4 2 2


Sample Input 2

3
4
1 3 5 7
3 4 8 0
2 4 2 2
1 2 5 5

Sample Output Copy

Output for Sample Input 1
0

Output for Sample Input 2
9