Codeforces 451C Predict outcome of the Game

Source: Internet
Author: User

Predict outcome of the GameTime limit:2000MS Memory Limit:262144KB 64bit IO Format:%i64d &%i6 4u SubmitStatusPracticecodeforces 451C

Description

There is n Games in a football tournament. Three teams is participating in it. Currently K Games had already been played.

You is an avid football fan and recently you missed the whole K Games. Fortunately, you remember a guess of the Your friend for the these KGames. Your friend did not tell the exact number of wins of each team, instead he thought that absolute difference between number of Wins of first and second team would be D1 and that ofbetween second and third team would be D 2.

You don't want any of the team win the tournament and that's each team should has the same number of wins after N Games. That's why you want to know:does there exist a valid tournament satisfying the friend's guess such that no team would win This tournament?

Note that outcome of a match can is not a draw, it have to be either win or loss.

Input

The first line of the input contains a single integer corresponding to number of test cases T(1≤ t ≤105).

Each of the next T lines would contain four space-separated integers n, K, D C11>1, D2(1≤ n ≤1012; 0≤ kn; 0≤ D1, d 2≤ k)-data for the current test case.

Output

For each test case, the output a single line containing either "yes" if it's possible to has no winner of tournament, or "No" otherwise (without quotes).

Sample Input

Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
Yes
Yes
Yes
No
No

Hint

Sample 1. There have not been any match up to now (k = 0, d1 = 0, d2 = 0). If There'll is three matches (1-2, 2-3, 3-1) and each of the team wins once, then the end of each team would have 1 win.

Sample 2. You missed all the Games (k = 3). As d1 = 0 and d2 = 0, and there is a-to-play three games with no winner of Tournamen T (described in the previous sample), the answer is "yes".

Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be:1-2 (win 2), 1-3 (Win 3), 1-2 (Win 1), 1-3 (Win 1). Currently the first team has 2 wins, the second team had 1 win, the third team has 1 win. The remaining matches can Be:1-2 (win 2), 1-3 (Win 3). The end all the teams has equal number of wins (2 wins).

1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 6 intMain ()7 {8     intT;9     Long Longn,k,d1,d2;Ten     Long Longi,j; Onescanf"%d",&T); A      while(t--) -     { -scanf"%i64d%i64d%i64d%i64d",&n,&k,&d1,&D2); the         Long LongX,y,z,c,v,ma; -  -         intflg=0; -  +V=k-d1-2*D2; -         if(v>=0&& v%3==0&& flg==0) +         { Ax=v/3+d1+d2,y=v/3+d2,z=v/3; at             if((n-k-(x-y+x-z)) >=0&& (n-k-(x-y+x-z))%3==0) -flg=1; -             //if (flg==1) -             //printf ("%d\n", 1); -         } -  inv=k-d1+2*D2; -         if(v>=0&& v%3==0&& flg==0) to         { +x=v/3+d1-d2,y=v/3-d2,z=v/3; -             if(x>=0&& y>=0&& z>=0) the             { *Ma=Max (x, y); $Ma=Max (ma,z);Panax Notoginseng                 if((n-k-(ma-x+ma-y+ma-z)) >=0&& (n-k-(ma-x+ma-y+ma-z))%3==0) -flg=1; the             } +             //if (flg==1) A             //printf ("%d\n", 2); the         } +          -  $V=k+d1-2*D2; $         if(v>=0&& v%3==0&& flg==0) -         { -x=v/3-d1+d2,y=v/3+d2,z=v/3; the             if(x>=0&& y>=0&& z>=0) -             {WuyiMa=Max (x, y); theMa=Max (ma,z); -                 if((n-k-(ma-x+ma-y+ma-z)) >=0&& (n-k-(ma-x+ma-y+ma-z))%3==0) Wuflg=1; -             } About             //if (flg==1) $             //printf ("%d\n", 3); -         } -          -  Av=k+d1+2*D2; +         if(v>=0&& v%3==0&& flg==0) the         { -x=v/3-d1-d2,y=v/3-d2,z=v/3; $             if(x>=0&& y>=0&& z>=0) the             { theMa=Max (x, y); theMa=Max (ma,z); the                 if((n-k-(ma-x+ma-y+ma-z)) >=0&& (n-k-(ma-x+ma-y+ma-z))%3==0) -flg=1; in             } the             //if (flg==1) the             //printf ("%d\n", 4); About         } the          the  the         if(flg==1) +printf"yes\n"); -         Else theprintf"no\n");Bayi     } the  the}
View Code

Codeforces 451C Predict outcome of the Game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.