F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Borrow

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 360    Accepted Submission(s): 146


Problem Description
Alice, Bob and Cindy are good friends. They go shopping together and buy the same. However, they don't bring the same units money with themselves so one of them suggests that the one with the most money should borrow 1 unit money to someone else with equal probability. That is to say, if they have $x, y, z(x \ge y \ge z)$ units money separately, the one with $x$ units money (if multiple people have the most then they decide one should borrow with equal probability) will give 1 unit to one of his/her friends with equal probability. After that, they have $x - 1, y + 1, z$ or $x - 1, y, z + 1$ units money.

This act will last until everyone has the same units money. Three smart guys want to know the expected times of this act or if this situation will never come.
 

Input
The input contains several test cases.
The first line contains a single integer $T$, indicating the number of test cases.
Following $T$ lines, each line contains three integer $x, y, z$ indicating the money of three guys.

$x + y + z \le 10^6, \sum{x + y + z} \le 3\times 10^6$
 

Output
For each test case, if the situation that everyone has the same units money will never come then print $- 1$, else print the expected times in a line. If the expected times is $\frac{P}{Q}$, you should output $P\cdot Q^{-1}\bmod 998244353$, where $Q^{-1}$ denotes the multiplicative inverse of $Q$ modulo $998244353$.
 

Sample Input
3 1 2 3 1 1 4 5 1 4
 

Sample Output
2 3 -1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-19 22:03:07, Gzip enabled