Huge Boxes of Animal Toys (Codeforces 1425H)
Tags: Others, constructive algorithms

Chaneka has a hobby of playing with animal toys. Every toy has a different fun value, a real number. Chaneka has four boxes to store the toys with specification:   The first box stores toys with fun values in range of $$$(-\infty,-1]$$$.  The second box stores toys with fun values in range of $$$(-1, 0)$$$.  The third box stores toys with fun values in range of $$$(0, 1)$$$.  The fourth box stores toys with fun value in range of $$$[1, \infty)$$$. Chaneka has $$$A$$$, $$$B$$$, $$$C$$$, $$$D$$$ toys in the first, second, third, and fourth box, respectively. One day she decides that she only wants one toy, a super toy. So she begins to create this super toy by sewing all the toys she has.While the number of toys Chaneka has is more than 1, she takes two different toys randomly and then sews them together, creating a new toy. The fun value of this new toy is equal to the multiplication of fun values of the sewn toys. She then puts this new toy in the appropriate box. She repeats this process until she only has one toy. This last toy is the super toy, and the box that stores this toy is the special box.As an observer, you only know the number of toys in each box initially but do not know their fun values. You also don't see the sequence of Chaneka's sewing. Determine which boxes can be the special box after Chaneka found her super toy.

Input: The first line has an integer $$$T$$$ $$$(1 \le T \le 5 \cdot 10^4)$$$, the number of test cases.Every case contains a line with four space-separated integers $$$A$$$ $$$B$$$ $$$C$$$ $$$D$$$ $$$(0 \le A, B, C, D \le 10^6, A + B + C + D > 0)$$$, which denotes the number of toys in the first, second, third, and fourth box, respectively.

Output: For each case, print four space-separated strings. Each string represents the possibility that the first, second, third, and fourth box can be the special box from left to right.For each box, print "Ya" (Without quotes, Indonesian for yes) if that box can be the special box. Print "Tidak" (Without quotes, Indonesian for No) otherwise.

Note: For the first case, here is a scenario where the first box is the special box:   The first box had toys with fun values $$$\{-3\}$$$.  The second box had toys with fun values $$$\{ -0.5, -0.5 \}$$$  The fourth box had toys with fun values $$$\{ 3 \}$$$ The sewing sequence:   Chaneka sews the toy with fun $$$-0.5$$$ and $$$-0.5$$$ to a toy with fun $$$0.25$$$ and then put it in the third box.  Chaneka sews the toy with fun $$$-3$$$ and $$$0.25$$$ to a toy with fun $$$-0.75$$$ and then put it in the second box.  Chaneka sews the toy with fun $$$-0.75$$$ and $$$3$$$ to a toy with fun $$$-1.25$$$ and then put it in the first box, which then became the special box. Here is a scenario where the second box ends up being the special box:   The first box had toys with fun values $$$\{-3\}$$$  The second box had toys with fun values $$$\{ -0.33, -0.25 \}$$$.  The fourth box had toys with fun values $$$\{ 3 \}$$$. The sewing sequence:   Chaneka sews the toy with fun $$$-3$$$ and $$$-0.33$$$ to a toy with fun $$$0.99$$$ and then put it in the third box.  Chaneka sews the toy with fun $$$0.99$$$ and $$$3$$$ to a toy with fun $$$2.97$$$ and then put in it the fourth box.  Chaneka sews the toy with fun $$$2.97$$$ and $$$-0.25$$$ to a toy with fun $$$-0.7425$$$ and then put it in the second box, which then became the special box.  There is only one toy for the second case, so Chaneka does not have to sew anything because that toy, by definition, is the super toy.

Sample Inputs:
2
1 2 0 1
0 1 0 0

Sample Outputs:
Ya Ya Tidak Tidak
Tidak Ya Tidak Tidak

Solution (Python):
from sys import stdin

def ii():
    return list(map(int, stdin.readline().strip().split()))
for _ in range(int(input())):
    a = ii()
    res = ['Tidak'] * 4
    neg = a[0] + a[1]
    if neg % 2 == 0:
        if a[-4] != 0 or a[-1] != 0:
            res[-1] = 'Ya'
        if a[-3] != 0 or a[-2] != 0:
            res[-2] = 'Ya'
    else:
        if a[-4] != 0 or a[-1] != 0:
            res[-4] = 'Ya'
        if a[-3] != 0 or a[-2] != 0:
            res[-3] = 'Ya'
    print(' '.join(res))

Solution (Python):
from sys import stdin

def get_ints():
    return list(map(int, stdin.readline().strip().split()))
for _ in range(int(input())):
    ar = get_ints()
    res = ['Tidak'] * 4
    bigs = ar[0] + ar[3]
    smalls = ar[1] + ar[2]
    if (ar[0] + ar[1]) % 2 == 1:
        if bigs > 0 and smalls > 0:
            res[0] = 'Ya'
            res[1] = 'Ya'
        elif bigs > 0 and (not smalls > 0):
            res[0] = 'Ya'
        else:
            res[1] = 'Ya'
    elif bigs > 0 and smalls > 0:
        res[2] = 'Ya'
        res[3] = 'Ya'
    elif bigs > 0 and (not smalls > 0):
        res[3] = 'Ya'
    else:
        res[2] = 'Ya'
    print(' '.join(res))

Solution (Python):
l = []
for _ in range(int(input())):
    (a, b, c, d) = map(int, input().split())
    s = []
    if (a + b) % 2 == 0:
        s.append('Tidak Tidak')
        if b + c == 0:
            s.append('Tidak Ya')
        elif d != 0 or a != 0:
            s.append('Ya Ya')
        else:
            s.append('Ya Tidak')
    else:
        if b + c == 0:
            s.append('Ya Tidak')
        elif a == 0 and d == 0:
            s.append('Tidak Ya')
        else:
            s.append('Ya Ya')
        s.append('Tidak Tidak')
    l.append(' '.join(s))
for i in l:
    print(i)