{"raw_statement":[{"iden":"statement","content":"This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use the stream flushing operation after each query's output in order not to leave part of your output in some buffer. For example, in C++ you've got to use the _fflush(stdout)_ function, in Java — call _System.out.flush()_, and in Pascal — _flush(output)_.\n\nBulls and Cows (also known as Cows and Bulls or Pigs and Bulls or Bulls and Cleots) is an old code-breaking paper and pencil game for two players, predating the similar commercially marketed board game Mastermind.\n\nOn a sheet of paper, the first player thinks a secret string. This string consists only of digits and has the length 4. The digits in the string **must** be all different, no two or more equal digits are allowed.\n\nThen the second player tries to guess his opponent's string. For every guess the first player gives the number of matches. If the matching digits are on their right positions, they are \"bulls\", if on different positions, they are \"cows\". Thus a response is a pair of numbers — the number of \"bulls\" and the number of \"cows\". A try can contain equal digits.\n\nMore formally, let's the secret string is _s_ and the second player are trying to guess it with a string _x_. The number of \"bulls\" is a number of such positions _i_ (1 ≤ _i_ ≤ 4) where _s_\\[_i_\\] = _x_\\[_i_\\]. The number of \"cows\" is a number of such digits _c_ that _s_ contains _c_ in the position _i_ (i.e. _s_\\[_i_\\] = _c_), _x_ contains _c_, but _x_\\[_i_\\] ≠ _c_.\n\nFor example, the secret string is \"_0427_\", the opponent's try is \"_0724_\", then the answer is 2 bulls and 2 cows (the bulls are \"0\" and \"2\", the cows are \"4\" and \"7\"). If the secret string is \"_0123_\", the opponent's try is \"_0330_\", then the answer is 1 bull and 1 cow.\n\nIn this problem you are to guess the string _s_ that the system has chosen. You only know that the chosen string consists of 4 distinct digits.\n\nYou can make queries to the testing system, each query is the output of a single 4\\-digit string. The answer to the query is the number of bulls and number of cows. If the system's response equals \"4 0\", that means the interaction with your problem is over and the program must terminate. That is possible for two reasons — the program either guessed the number _x_ or made an invalid action (for example, printed letters instead of digits).\n\nYour program is allowed to do at most 50 queries.\n\nYou can hack solutions of other participants providing a 4-digit string containing distinct digits — the secret string."},{"iden":"input","content":"To read answers to the queries, the program must use the standard input.\n\nThe program will receive pairs of non-negative integers in the input, one pair per line. The first number in a pair is a number of bulls and the second one is a number of cows of the string _s_ and the string _x__i_ printed by your program. If the system response equals \"4 0\", then your solution should terminate.\n\nThe testing system will let your program read the _i_\\-th pair of integers from the input only after your program displays the corresponding system query in the output: prints value _x__i_ in a single line and executes operation _flush_."},{"iden":"output","content":"The program must use the standard output to print queries.\n\nYour program must output requests — 4\\-digit strings _x_1, _x_2, ..., one per line. After the output of each line the program must execute _flush_ operation. The program should read the answer to the query from the standard input.\n\nYour program is allowed to do at most 50 queries."},{"iden":"examples","content":"Input\n\n0 1\n2 0\n1 1\n0 4\n2 1\n4 0\n\nOutput\n\n8000\n0179\n3159\n3210\n0112\n0123"},{"iden":"note","content":"The secret string _s_ in the example is \"_0123_\"."}],"translated_statement":[{"iden":"statement","content":"这个问题有点特殊。你需要实现与测试系统的交互。这意味着你可以在在线模式下发出查询并获取响应。请确保在每次查询输出后执行流刷新操作，以免将部分输出留在缓冲区中。例如，在 C++ 中你需要使用 _fflush(stdout)_ 函数，在 Java 中调用 _System.out.flush()_，在 Pascal 中使用 _flush(output)_。\n\n猜数字（也称为 Cows and Bulls 或 Pigs and Bulls 或 Bulls and Cleots）是一种古老的纸笔密码破解游戏，适用于两名玩家，早于类似的商业板游戏 Mastermind。\n\n在一张纸上，第一位玩家思考一个秘密字符串。该字符串仅由数字组成，长度为 #cf_span[4]。字符串中的数字 *必须* 全部不同，不允许出现两个或更多相同的数字。\n\n然后第二位玩家尝试猜测对手的字符串。对于每一次猜测，第一位玩家会给出匹配数字的数量。如果匹配的数字位置正确，则称为“bulls”（公牛）；如果数字存在但位置错误，则称为“cows”（母牛）。因此，响应是一个由两个数字组成的对——“bulls”的数量和“cows”的数量。一次猜测可以包含重复的数字。\n\n更正式地，设秘密字符串为 #cf_span[s]，第二位玩家猜测的字符串为 #cf_span[x]。“bulls”的数量是满足 #cf_span[1 ≤ i ≤ 4] 且 #cf_span[s[i] = x[i]] 的位置 #cf_span[i] 的个数。“cows”的数量是满足以下条件的数字 #cf_span[c] 的个数：#cf_span[s] 在某个位置 #cf_span[i] 包含 #cf_span[c]（即 #cf_span[s[i] = c]），#cf_span[x] 也包含 #cf_span[c]，但 #cf_span[x[i] ≠ c]。\n\n例如，秘密字符串为 \"_0427_\"，对手的猜测为 \"_0724_\"，则答案为 #cf_span[2] 个 bulls 和 #cf_span[2] 个 cows（bulls 是 \"0\" 和 \"2\"，cows 是 \"4\" 和 \"7\"）。如果秘密字符串是 \"_0123_\"，对手的猜测是 \"_0330_\"，则答案为 #cf_span[1] 个 bull 和 #cf_span[1] 个 cow。\n\n在本题中，你需要猜出系统选择的字符串 #cf_span[s]。你只知道所选字符串由 #cf_span[4] 个互不相同的数字组成。\n\n你可以向测试系统发出查询，每次查询是输出一个 #cf_span[4] 位的字符串。查询的回答是 bulls 和 cows 的数量。如果系统响应为 \"4 0\"，则表示与你的程序的交互结束，程序必须终止。这可能有两种原因：程序要么猜中了数字 #cf_span[x]，要么执行了无效操作（例如，打印了字母而非数字）。\n\n你的程序最多允许进行 #cf_span[50] 次查询。\n\n你可以通过提供一个包含互不相同数字的 4 位字符串（即秘密字符串）来 hack 其他参赛者的解决方案。\n\n为了读取查询的答案，程序必须使用标准输入。\n\n程序将从输入中接收到一系列非负整数对，每行一对。每对中的第一个数字是 bulls 的数量，第二个数字是 cows 的数量，对应于系统秘密字符串 #cf_span[s] 和你的程序输出的字符串 #cf_span[xi]。如果系统响应为 \"4 0\"，则你的解决方案应终止。\n\n只有当你的程序在输出中显示了相应的系统查询（即在单独一行中打印值 #cf_span[xi] 并执行 _flush_ 操作）后，测试系统才会允许你的程序从输入中读取第 #cf_span[i] 对整数。\n\n程序必须使用标准输出打印查询。\n\n你的程序必须输出请求——#cf_span[4] 位的字符串 #cf_span[x1, x2, ...]，每行一个。在每行输出后，程序必须执行 _flush_ 操作。程序应从标准输入读取查询的答案。\n\n你的程序最多允许进行 #cf_span[50] 次查询。\n\n示例中的秘密字符串 #cf_span[s] 是 \"_0123_\"。\n"},{"iden":"input","content":"为了读取查询的答案，程序必须使用标准输入。程序将从输入中接收到一系列非负整数对，每行一对。每对中的第一个数字是 bulls 的数量，第二个数字是 cows 的数量，对应于系统秘密字符串 #cf_span[s] 和你的程序输出的字符串 #cf_span[xi]。如果系统响应为 \"4 0\"，则你的解决方案应终止。测试系统仅在你的程序在输出中显示了相应的系统查询（即在单独一行中打印值 #cf_span[xi] 并执行 _flush_ 操作）后，才会允许你的程序从输入中读取第 #cf_span[i] 对整数。"},{"iden":"output","content":"程序必须使用标准输出打印查询。你的程序必须输出请求——#cf_span[4] 位的字符串 #cf_span[x1, x2, ...]，每行一个。在每行输出后，程序必须执行 _flush_ 操作。程序应从标准输入读取查询的答案。你的程序最多允许进行 #cf_span[50] 次查询。"},{"iden":"examples","content":"输入\n0 1\n2 0\n1 1\n0 4\n2 1\n4 0\n输出\n8000\n0179\n3159\n3210\n0112\n0123"},{"iden":"note","content":"示例中的秘密字符串 #cf_span[s] 是 \"_0123_\"。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ s \\in \\{0,1,\\dots,9\\}^4 $ be the secret string, with all digits distinct.  \nLet $ Q \\subseteq \\{0,1,\\dots,9\\}^4 $ be the set of queries made by the program, with $ |Q| \\leq 50 $.  \nFor any query $ x \\in Q $, define:  \n- $ \\text{bulls}(s, x) = |\\{ i \\in \\{1,2,3,4\\} \\mid s[i] = x[i] \\}| $,  \n- $ \\text{cows}(s, x) = |\\{ c \\in \\{0,1,\\dots,9\\} \\mid c \\text{ appears in } s \\text{ and } x, \\text{ but not at the same position} \\}| $.  \n\n**Constraints**  \n1. $ s $ contains exactly 4 distinct digits.  \n2. For each query $ x \\in Q $, $ x $ is a 4-digit string (digits may repeat).  \n3. The program may issue at most 50 queries.  \n4. The interaction terminates upon receiving response $ (4, 0) $.  \n\n**Objective**  \nDetermine $ s $ by adaptively selecting queries $ x_1, x_2, \\dots, x_k \\in \\{0,1,\\dots,9\\}^4 $, $ k \\leq 50 $, such that after receiving responses $ (b_i, c_i) = (\\text{bulls}(s, x_i), \\text{cows}(s, x_i)) $, the secret string $ s $ is uniquely identified and the program outputs $ s $ when $ (b_k, c_k) = (4, 0) $.","simple_statement":null,"has_page_source":false}