A. Three Decks
Source: codeforces
Tags: math

Monocarp placed three decks of cards in a row on the table. The first deck consists of $a$ cards, the second deck consists of $b$ cards, and the third deck consists of $c$ cards, with the condition $a < b < c$.
Monocarp wants to take some number of cards (at least one, but no more than $c$) from the third deck and distribute them between the first two decks so that each of the taken cards ends up in either the first or the second deck. It is possible that all the cards taken from the third deck will go into the same deck.
Your task is to determine whether Monocarp can make the number of cards in all three decks equal using the described operation.

-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The only line of each test case contains three integers $a, b$, and $c$ ($1 \le a, b, c \le 10^8$) — the number of cards in the first, second, and third decks, respectively.
Additional constraint on the input: $a < b < c$.

-----Output-----
For each test case, output "YES" (without quotes) if Monocarp can make the number of cards in all three decks equal using the described operation. Otherwise, output "NO" (without quotes).

-----Examples-----
Input:
4
3 5 10
12 20 30
3 5 7
1 5 6
Output:
YES
NO
YES
NO

-----Note-----
In the first test case, Monocarp has to take $4$ cards from the third deck, put $3$ cards in the first deck, and $1$ card in the second deck. Thus, there will be $6$ cards in all three decks.
In the second test case, it is impossible to make the number of cards in all three decks equal.
In the third test case, Monocarp has to take $2$ cards from the third deck and put both in the first deck. Thus, there will be $5$ cards in all three decks.
In the fourth test case, it is also impossible to make the number of cards in all three decks equal.

C++ solution:
#include <iostream>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    
    while (t--) {
        long long a, b, c;
        cin >> a >> b >> c;
        
        long long total = a + b + c;
        if (total % 3 != 0) {
            cout << "NO\n";
        } else {
            long long k = total / 3;
            if (k >= a && k >= b && (c >= (k - a) + (k - b))) {
                cout << "YES\n";
            } else {
                cout << "NO\n";
            }
        }
    }
    
    return 0;
}

Go solution:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())

	for i := 0; i < t; i++ {
		scanner.Scan()
		line := scanner.Text()
		parts := strings.Fields(line)
		a, _ := strconv.Atoi(parts[0])
		b, _ := strconv.Atoi(parts[1])
		c, _ := strconv.Atoi(parts[2])

		total := a + b + c
		if total%3 == 0 {
			k := total / 3
			if k >= b && (k-a)+(k-b) == c-k && (k-a) >= 0 && (k-b) >= 0 {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		} else {
			fmt.Println("NO")
		}
	}
}

Java solution:
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        for (int i = 0; i < t; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            int c = Integer.parseInt(st.nextToken());
            long sum = (long) a + b + c;
            if (sum % 3 == 0) {
                long k = sum / 3;
                if (k >= a && k >= b && (k - a) + (k - b) <= c) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
            } else {
                System.out.println("NO");
            }
        }
    }
}

JavaScript solution:
const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];
let currentLine = 0;

rl.on('line', (line) => {
    input.push(line);
});

rl.on('close', () => {
    solve();
});

function solve() {
    const t = parseInt(input[0]);
    for (let i = 1; i <= t; i++) {
        const [a, b, c] = input[i].split(' ').map(Number);
        const total = a + b + c;
        if (total % 3 === 0) {
            const k = total / 3;
            if (k >= a && k >= b && k >= c - (2 * k - a - b)) {
                console.log("YES");
            } else {
                console.log("NO");
            }
        } else {
            console.log("NO");
        }
    }
}

Python solution:
t=int(input())
for _ in range(t):
    a,b,c=map(int,input().split())
    d=(c-b)-(b-a)
    print("YES" if( d>=0 and d%3==0 )else "NO")

Ruby solution:
t = gets.to_i
t.times do
  a, b, c = gets.split.map(&:to_i)
  total = a + b + c
  if total % 3 == 0
    x = total / 3
    if (x - a) + (x - b) <= c && (x - a) >= 0 && (x - b) >= 0
      puts "YES"
    else
      puts "NO"
    end
  else
    puts "NO"
  end
end