{"problem":{"name":"J. Straight Master","description":{"content":"A straight is a poker hand containing five cards of sequential rank, not necessarily to be the same suit. For example, a hand containing 7 club, 6 spade, 5 spade, 4 heart and 3 diamond forms a straigh","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10177J"},"statements":[{"statement_type":"Markdown","content":"A straight is a poker hand containing five cards of sequential rank, not necessarily to be the same suit. For example, a hand containing 7 club, 6 spade, 5 spade, 4 heart and 3 diamond forms a straight. In this problem, we extend the definition of a straight to allow 3 to 5 cards of sequential rank. Hence a hand containing K spade, Q club, and J heart is also a straight.\n\nMr. Panda is playing a poker game called Straight Master. The game uses a large deck of card that has N ranks from 1 to N. The rule of the game is simple: split the cards in Mr. Panda's hand into several straights of length from 3 to 5.\n\nNow given a hand of cards, can you help Mr. Panda to determine if it is possible to split the cards into straights?\n\nThe first line of the input gives the number of test cases, T. T test cases follow.\n\nEach test case contains two lines. The first line contains an integer N, indicating the number of ranks in the deck. The next line contains N integers a1, a2, ..., aN indicating the number of cards for each rank in Mr. Panda's hand.\n\nFor each test case, output one line containing \"_Case #x: y_\", where _x_ is the test case number (starting from 1) and _y_ is _Yes_ if Mr. Panda can split all his cards into straights of length from 3 to 5, or _No_ otherwise.\n\nIn the first test case, Mr. Panda can split his cards into two straights: [1, 2, 3] and [2, 3, 4]. In the second test case, there is no way to form a straight for card 6 and 7.\n\n## Input\n\nThe first line of the input gives the number of test cases, T. T test cases follow.Each test case contains two lines. The first line contains an integer N, indicating the number of ranks in the deck. The next line contains N integers a1, a2, ..., aN indicating the number of cards for each rank in Mr. Panda's hand.  1 ≤ T ≤ 100.  1 ≤ N ≤ 2 × 105.  0 ≤ ai ≤ 109.  . \n\n## Output\n\nFor each test case, output one line containing \"_Case #x: y_\", where _x_ is the test case number (starting from 1) and _y_ is _Yes_ if Mr. Panda can split all his cards into straights of length from 3 to 5, or _No_ otherwise.\n\n[samples]\n\n## Note\n\nIn the first test case, Mr. Panda can split his cards into two straights: [1, 2, 3] and [2, 3, 4]. In the second test case, there is no way to form a straight for card 6 and 7.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $, let $ l_k, r_k \\in \\mathbb{Z} $ with $ 1 \\le l_k \\le r_k \\le 10^{18} $.  \n\nFor any integer $ x \\in [l_k, r_k] $, let $ d $ be the number of decimal digits of $ x $.  \nDefine the **left half** $ L(x) $ and **right half** $ R(x) $ as:  \n- If $ d $ is even ($ d = 2m $):  \n  $ L(x) = \\left\\lfloor \\frac{x}{10^m} \\right\\rfloor $, $ R(x) = x \\bmod 10^m $  \n- If $ d $ is odd ($ d = 2m+1 $):  \n  $ L(x) = \\left\\lfloor \\frac{x}{10^m} \\right\\rfloor $, $ R(x) = x \\bmod 10^m $  \n\nRequire:  \n- $ L(x) > 0 $, $ R(x) > 0 $  \n- $ \\gcd(L(x), R(x)) = 1 $  \n\n**Constraints**  \n1. $ 1 \\le T \\le 10^5 $  \n2. For each test case: $ 1 \\le l_k \\le r_k \\le 10^{18} $  \n\n**Objective**  \nFor each test case $ k $, find:  \n$$\nx_k^* = \\max \\left\\{ x \\in [l_k, r_k] \\,\\middle|\\, L(x) > 0,\\, R(x) > 0,\\, \\gcd(L(x), R(x)) = 1 \\right\\}\n$$  \nIf no such $ x $ exists, set $ x_k^* = -1 $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10177J","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}