{"problem":{"name":"127. Latin Squares","description":{"content":"A _latin square_ is defined as a 4 by 4 grid of numbers, where all of the numbers in each row and column are distinct, i.e. no two pairs of elements in each row and column are equal.  You're given a ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":8000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10269127"},"statements":[{"statement_type":"Markdown","content":"A _latin square_ is defined as a 4 by 4 grid of numbers, where all of the numbers in each row and column are distinct, i.e. no two pairs of elements in each row and column are equal. \n\nYou're given a partially filled in latin square. Figure out how many valid latin squares can be formed by filling in the empty digits of the latin square.\n\nThe input consists of 4 lines, each consisting of 4 integers: the digits in the latin square. For each digit, if it has already been filled in, it will be represented with a digit from 1 to 4, and if it hasn't been filled in yet, it will be represented with a \"0\".\n\nOutput a single positive integer $n$: the number of ways to fill in the latin square as described above.\n\n## Input\n\nThe input consists of 4 lines, each consisting of 4 integers: the digits in the latin square. For each digit, if it has already been filled in, it will be represented with a digit from 1 to 4, and if it hasn't been filled in yet, it will be represented with a \"0\".\n\n## Output\n\nOutput a single positive integer $n$: the number of ways to fill in the latin square as described above.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ L \\in \\{0,1,2,3,4\\}^{4 \\times 4} $ be a partial Latin square, where $ L_{i,j} \\in \\{1,2,3,4\\} $ if filled, and $ L_{i,j} = 0 $ if empty.\n\n**Constraints**  \n1. For each row $ i \\in \\{1,2,3,4\\} $, all non-zero entries are distinct.  \n2. For each column $ j \\in \\{1,2,3,4\\} $, all non-zero entries are distinct.  \n3. Any complete filling must result in a Latin square: each row and each column is a permutation of $ \\{1,2,3,4\\} $.  \n\n**Objective**  \nCount the number of completions $ L' \\in \\{1,2,3,4\\}^{4 \\times 4} $ such that:  \n- $ L'_{i,j} = L_{i,j} $ for all $ (i,j) $ where $ L_{i,j} \\neq 0 $,  \n- Each row of $ L' $ is a permutation of $ \\{1,2,3,4\\} $,  \n- Each column of $ L' $ is a permutation of $ \\{1,2,3,4\\} $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10269127","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}