{"raw_statement":[{"iden":"statement","content":"Tomaz and Danftito are playing a game with 3 stacks of rocks, each with a, b and c rocks respectively. Each turn, a player must take from 1 to m rocks from a stack, but they can't empty a stack if there are rocks in any stack to the left. The player that removes the last rock wins. If Tomaz goes first and they take turns playing, determine who will win the game if both players play optimally.\n\nThe input contains one line with four integers: m (1 ≤ m ≤ 1018) representing the maximum amount of rocks to be removed in a single turn, a, b and c (1 ≤ a, b, c ≤ 1018) each representing how many rocks there are initially in the first, second and third stacks respectively. \n\nPrint \"Tomaz\" if Tomaz will win the game, and \"Danftito\" otherwise.\n\n"},{"iden":"input","content":"The input contains one line with four integers: m (1 ≤ m ≤ 1018) representing the maximum amount of rocks to be removed in a single turn, a, b and c (1 ≤ a, b, c ≤ 1018) each representing how many rocks there are initially in the first, second and third stacks respectively. "},{"iden":"output","content":"Print \"Tomaz\" if Tomaz will win the game, and \"Danftito\" otherwise."}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n, x \\in \\mathbb{Z}_{\\geq 0} $ be the number of rooms and initial stone count.  \nLet $ m \\in \\mathbb{Z}_{>0} $ be the number of pile descriptions.  \nFor $ i \\in \\{1, \\dots, m\\} $, let $ (p_i, q_i, c_i) \\in \\mathbb{Z}_{\\geq 0}^3 $ denote $ c_i $ identical piles of $ p_i $ stones in room $ q_i $.  \nLet $ Q \\in \\mathbb{Z}_{>0} $ be the number of queries.  \nFor $ j \\in \\{1, \\dots, Q\\} $, let $ (l_j, r_j) \\in \\mathbb{Z}^2 $ with $ 1 \\leq l_j \\leq r_j \\leq n $ be a query interval.\n\nDefine for each room $ k \\in \\{1, \\dots, n\\} $:  \n- $ P_k = \\{ p_i \\mid q_i = k \\} $: set of pile sizes in room $ k $.  \n- $ C_k(p) = \\sum_{i: q_i = k, p_i = p} c_i $: total number of piles of size $ p $ in room $ k $.  \n\n**Constraints**  \n1. $ 1 \\leq n \\leq 500 $, $ 1 \\leq m \\leq 10000 $, $ 1 \\leq Q \\leq \\binom{n+1}{2} $  \n2. $ 0 \\leq p_i, x \\leq 500 $, $ 1 \\leq c_i \\leq 10000 $, $ 1 \\leq q_i \\leq n $  \n3. $ 1 \\leq l_j \\leq r_j \\leq n $ for all $ j \\in \\{1, \\dots, Q\\} $\n\n**Objective**  \nFor each query $ j $, compute the number of ways to select a subset of piles (at most one pile per room) from rooms $ l_j $ to $ r_j $, such that the XOR-sum of selected pile sizes equals $ x $, modulo $ 10007 $.  \n\nFormally, for interval $ [l_j, r_j] $, define:  \n$$\n\\text{Answer}_j = \\left| \\left\\{ S \\subseteq \\bigcup_{k=l_j}^{r_j} \\left( \\{ (p, \\text{idx}) \\mid p \\in P_k, \\text{idx} \\in \\{1, \\dots, C_k(p)\\} \\} \\right) \\ \\middle| \\ \\begin{array}{c}\n|S \\cap \\text{room } k| \\leq 1 \\ \\forall k \\in [l_j, r_j] \\\\\n\\bigoplus_{(p, \\cdot) \\in S} p = x\n\\end{array} \\right\\} \\right| \\mod 10007\n$$\n\nEquivalently, using generating functions per room:  \nLet $ f_k(t) = 1 + \\sum_{p \\in P_k} C_k(p) \\cdot t^p $ for room $ k $, where exponent represents XOR value and coefficient counts ways.  \nThen:  \n$$\n\\text{Answer}_j = \\left[ t^x \\right] \\left( \\prod_{k=l_j}^{r_j} f_k(t) \\right) \\mod 10007\n$$","simple_statement":"You are given n rooms and a magic number x.  \nEach room has some piles of stones.  \nFor each query (l, r), you can pick 0 or 1 pile from each room between l and r.  \nYou play Nim with the chosen piles — first player wins if XOR ≠ 0.  \nQkoqhh wants to know: how many ways can he pick piles (0 or 1 per room in [l,r]) so that the XOR of all chosen piles equals x?  \nAnswer each query mod 10007.","has_page_source":false}