Search is not available for this dataset
problem_id
stringlengths
32
32
name
stringlengths
2
112
problem
stringlengths
200
14k
test_cases
stringlengths
33
79.2M
difficulty
stringclasses
33 values
language
sequencelengths
1
1
source
stringclasses
14 values
num_solutions
int64
2
1.9M
starter_code
stringlengths
0
1.47k
subset
stringclasses
3 values
34c570004ec7795aaadb7d0ef147acd6
brcktsrm
Problem description. Vipul is a hardworking super-hero who maintains the bracket ratio of all the strings in the world. Recently he indulged himself in saving the string population so much that he lost his ability for checking brackets (luckily, not permanently ).Being his super-hero friendΒ help him in his time of hardship. Input The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single string S denoting the string to be checked. Output For each test case, output a single line printing "YES" or "NO" (without " " and in uppercase only) , denoting if the brackets in the given string is balanced or not . Constraints 1 ≀ T ≀ 10 1 ≀ length of S ≀ 60 Example Input: 3 ((())) (())() ()(() Output: YES YES NO Β  Explanation Example is self-explanatory.
{"inputs": ["3\n((()))\n(())()\n()(()", "3\n((()))\n(())()\n()())", "3\n((()()\n(())()\n()(()", "3\n((()))\n(())))\n()())", "3\n)))(((\n(())))\n()())", "3\n((()))\n(())()\n))(((", "3\n((()()\n(())()\n()(((", "3\n((()))\n(())()\n()()(", "3\n((()()\n'())()\n()(((", "3\n)))(((\n(())))\n()(*)", "3\n)(()()\n'())()\n()(((", "3\n))*(((\n(())))\n()(*)", "3\n)()(()\n'())()\n()(((", "3\n)*)(((\n(())))\n()(*)", "3\n)()())\n'())()\n()(((", "3\n)*)(((\n(()())\n()(*)", "3\n)()())\n'()())\n()(((", "3\n)*)(((\n(()())\n))(*(", "3\n)()()(\n'()())\n()(((", "3\n)()(*(\n(()())\n))(*(", "3\n)()()(\n))()('\n()(((", "3\n)()(*(\n(())))\n))(*(", "3\n)')()(\n))()('\n()(((", "3\n)()(*(\n(())))\n))()(", "3\n)')()(\n)(())'\n()(((", "3\n)()(*(\n(())))\n()())", "3\n))'()(\n)(())'\n()(((", "3\n)('()(\n)(())'\n()(((", "3\n)('()(\n)('))(\n()(((", "3\n)('()(\n)('))(\n')(((", "3\n)('()(\n())'()\n')(((", "3\n)('()(\n)())'(\n')(((", "3\n)('()(\n)())'(\n((()'", "3\n)('()(\n))))'(\n((()'", "3\n((()))\n)())()\n()(()", "3\n)))(((\n(())()\n()())", "3\n((()()\n(())()\n()(')", "3\n)))(((\n(())()\n))(((", "3\n)((())\n(())))\n()())", "3\n((()()\n(())()\n((()(", "3\n((()))\n(())()\n')()(", "3\n)))(()\n(())))\n()())", "3\n((()()\n&())()\n()(((", "3\n)))(((\n))))((\n()(*)", "3\n)(()()\n'())()\n(((((", "3\n))*(((\n(())))\n)*()(", "3\n)()(()\n'())((\n()(((", "3\n)*)(((\n(())))\n*)(()", "3\n)()())\n'())()\n()('(", "3\n)*)(((\n))()((\n()(*)", "3\n)')())\n'()())\n()(((", "3\n)()()(\n'()())\n()()(", "3\n)()(*(\n(()())\n))(*)", "3\n)()()(\n))()('\n((()(", "3\n)')')(\n))()('\n()(((", "3\n)()(*(\n(())))\n)())(", "3\n()()')\n)(())'\n()(((", "3\n(*)(()\n(())))\n()())", "3\n))'()(\n'))(()\n()(((", "3\n)('(((\n)(())'\n()(((", "3\n)('()(\n((')))\n()(((", "3\n)('()(\n)('))(\n')()(", "3\n)('()(\n())'()\n((()'", "3\n)('()(\n)())((\n')(((", "3\n)('()(\n)())'(\n((()(", "3\n()('))\n))))'(\n((()'", "3\n((())(\n)())()\n()(()", "3\n)))(((\n)())()\n()())", "3\n((()()\n(()(()\n()(')", "3\n)))(((\n(())()\n*)(((", "3\n)((())\n'())))\n()())", "3\n((()()\n(())()\n()()(", "3\n((()))\n)()(()\n')()(", "3\n)))((*\n(())))\n()())", "3\n()((()\n&())()\n()(((", "3\n)))(((\n))))((\n(*(*)", "3\n)(()()\n)())('\n(((((", "3\n))*(((\n()()))\n)*()(", "3\n)()())\n'())()\n()(''", "3\n)')())\n'()())\n((()(", "3\n)()()(\n&()())\n()()(", "3\n)()(*(\n(()())\n*)(*)", "3\n)()()(\n))()('\n(())(", "3\n)')')(\n))()('\n()(('", "3\n)()(*(\n(())))\n)()((", "3\n)')())\n)(())'\n()(((", "3\n)*)(()\n(())))\n()())", "3\n))'()(\n'))((*\n()(((", "3\n)('(((\n)(())'\n()(('", "3\n)('()(\n((')))\n(((((", "3\n)('()'\n)('))(\n')()(", "3\n)('()(\n)())((\n')('(", "3\n)('()(\n'()))(\n((()(", "3\n()('))\n('))))\n((()'", "3\n((())(\n*())()\n()(()", "3\n)))(((\n)())()\n((())", "3\n((()))\n(())()\n*)(((", "3\n)((())\n'())))\n()'))", "3\n((()()\n(())()\n')()(", "3\n((()))\n)()(()\n()()'", "3\n)))((*\n(())))\n))())"], "outputs": ["YES\nYES\nNO", "YES\nYES\nNO\n", "NO\nYES\nNO\n", "YES\nNO\nNO\n", "NO\nNO\nNO\n", "YES\nYES\nNO\n", "NO\nYES\nNO\n", "YES\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "YES\nNO\nNO\n", "NO\nYES\nNO\n", "NO\nYES\nNO\n", "NO\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\n", "YES\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\n", "YES\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "YES\nYES\nNO\n", "NO\nNO\nNO\n", "NO\nYES\nNO\n", "YES\nNO\nNO\n", "NO\nNO\nNO\n"]}
6
[ "PYTHON3" ]
1
2
code_contests
ef0bd132d1ee833bb59308942bab8a9c
comm3
The Chef likes to stay in touch with his staff. So, the Chef, the head server, and the sous-chef all carry two-way transceivers so they can stay in constant contact. Of course, these transceivers have a limited range so if two are too far apart, they cannot communicate directly. The Chef invested in top-of-the-line transceivers which have a few advanced features. One is that even if two people cannot talk directly because they are out of range, if there is another transceiver that is close enough to both, then the two transceivers can still communicate with each other using the third transceiver as an intermediate device. There has been a minor emergency in the Chef's restaurant and he needs to communicate with both the head server and the sous-chef right away. Help the Chef determine if it is possible for all three people to communicate with each other, even if two must communicate through the third because they are too far apart. Input The first line contains a single positive integer T ≀ 100 indicating the number of test cases to follow. The first line of each test case contains a positive integer R ≀ 1,000 indicating that two transceivers can communicate directly without an intermediate transceiver if they are at most R meters away from each other. The remaining three lines of the test case describe the current locations of the Chef, the head server, and the sous-chef, respectively. Each such line contains two integers X,Y (at most 10,000 in absolute value) indicating that the respective person is located at position X,Y. Output For each test case you are to output a single line containing a single string. If it is possible for all three to communicate then you should output "yes". Otherwise, you should output "no". To be clear, we say that two transceivers are close enough to communicate directly if the length of the straight line connecting their X,Y coordinates is at most R. Example Input: 3 1 0 1 0 0 1 0 2 0 1 0 0 1 0 2 0 0 0 2 2 1 Output: yes yes no
{"inputs": ["3\n1\n0 1\n0 0\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n1\n0 1\n0 -1\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n2\n0 1\n0 -1\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n2\n0 -1\n0 -1\n1 0\n2\n0 0\n0 0\n1 0\n2\n1 0\n1 2\n2 1", "3\n2\n0 -1\n-1 -1\n2 0\n2\n1 0\n0 -1\n1 -1\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n0 -1\n2 0\n2\n2 0\n0 -1\n1 -2\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n0 -1\n2 -1\n1\n2 0\n0 -1\n1 -2\n2\n1 0\n1 2\n1 1", "3\n2\n0 -2\n-1 -1\n1 0\n2\n-1 0\n-1 0\n1 -1\n1\n1 -1\n1 2\n1 1", "3\n2\n0 1\n0 -1\n2 -1\n1\n2 0\n0 -1\n1 -2\n2\n0 0\n1 2\n1 2", "3\n2\n0 0\n0 -1\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n2\n0 0\n0 -1\n1 0\n2\n0 0\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n2\n0 0\n0 -1\n1 0\n2\n0 0\n0 0\n1 0\n2\n0 0\n1 2\n2 1", "3\n2\n0 -1\n0 -1\n1 0\n2\n0 0\n0 0\n1 0\n2\n0 0\n1 2\n2 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n0 0\n0 0\n1 0\n2\n1 0\n1 2\n2 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n0 0\n0 0\n1 0\n2\n1 0\n1 2\n0 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n0 0\n0 0\n1 -1\n2\n1 0\n1 2\n0 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n0 0\n0 0\n1 -1\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n0 0\n0 -1\n1 -1\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n1 0\n0 -1\n1 -1\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n2 0\n2\n1 0\n0 -1\n1 -2\n2\n1 0\n1 2\n1 1", "3\n1\n0 -1\n-1 -1\n2 0\n2\n1 0\n0 -1\n1 -2\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n0 -1\n2 0\n2\n1 0\n0 -1\n1 -2\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n0 -1\n2 0\n1\n2 0\n0 -1\n1 -2\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n0 -1\n2 0\n1\n2 1\n0 -1\n1 -2\n2\n1 0\n1 2\n1 1", "3\n1\n0 1\n0 0\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 3\n2 1", "3\n1\n0 1\n0 -1\n1 0\n2\n0 1\n0 0\n1 1\n2\n0 0\n0 2\n2 1", "3\n2\n0 0\n0 0\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n2\n0 0\n0 -1\n1 0\n2\n0 0\n-1 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n2\n0 0\n1 -1\n1 0\n2\n0 0\n0 0\n1 0\n2\n0 0\n1 2\n2 1", "3\n2\n0 -1\n0 -1\n1 0\n3\n0 0\n0 0\n1 0\n2\n0 0\n1 2\n2 1", "3\n2\n0 -1\n0 -1\n1 0\n2\n0 0\n0 0\n1 0\n2\n1 0\n1 2\n2 2", "3\n3\n0 -1\n-1 -1\n1 0\n2\n0 0\n0 0\n1 0\n2\n1 0\n1 2\n2 1", "3\n2\n0 -1\n-1 -1\n1 -1\n2\n0 0\n0 0\n1 0\n2\n1 0\n1 2\n0 1", "3\n4\n0 -1\n-1 -1\n1 0\n2\n0 0\n0 0\n1 -1\n2\n1 0\n1 2\n0 1", "3\n2\n0 -2\n-1 -1\n1 0\n2\n0 0\n0 0\n1 -1\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n0 1\n0 -1\n1 -1\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n1 0\n1 -1\n1 -1\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n2 0\n2\n1 0\n0 -1\n1 -1\n3\n1 0\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n2 0\n2\n1 0\n0 -1\n0 -2\n2\n1 0\n1 2\n1 1", "3\n1\n0 -1\n-1 0\n2 0\n2\n1 0\n0 -1\n1 -2\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n0 -1\n2 0\n2\n1 0\n0 -2\n1 -2\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n0 -1\n2 0\n2\n2 0\n0 -1\n1 -2\n2\n1 1\n1 2\n1 1", "3\n2\n0 -1\n0 -1\n2 1\n1\n2 1\n0 -1\n1 -2\n2\n1 0\n1 2\n1 1", "3\n1\n0 1\n0 0\n1 0\n4\n0 1\n0 0\n1 0\n2\n0 0\n0 3\n2 1", "3\n2\n0 1\n0 0\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n2\n0 0\n0 -1\n1 0\n2\n0 0\n-1 0\n1 0\n2\n0 0\n0 2\n3 1", "3\n2\n0 0\n1 -1\n1 0\n2\n0 0\n0 0\n1 -1\n2\n0 0\n1 2\n2 1", "3\n3\n0 -1\n-1 -1\n1 0\n2\n-1 0\n0 0\n1 0\n2\n1 0\n1 2\n2 1", "3\n2\n0 -1\n-1 -1\n2 -1\n2\n0 0\n0 0\n1 0\n2\n1 0\n1 2\n0 1", "3\n4\n0 -1\n-1 -1\n1 0\n2\n0 -1\n0 0\n1 -1\n2\n1 0\n1 2\n0 1", "3\n2\n0 -2\n-1 -1\n1 0\n2\n0 0\n0 0\n1 -1\n2\n1 -1\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n0 1\n0 -1\n1 -1\n2\n2 0\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n1 0\n1 -1\n1 -1\n2\n1 0\n2 2\n1 1", "3\n2\n0 -1\n-1 -1\n2 0\n2\n1 0\n0 -1\n1 -1\n3\n1 0\n1 2\n1 0", "3\n2\n0 -1\n-1 -1\n2 0\n2\n1 1\n0 -1\n0 -2\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n0 -1\n2 1\n2\n2 0\n0 -1\n1 -2\n2\n1 1\n1 2\n1 1", "3\n2\n0 -1\n0 -1\n2 -1\n1\n2 0\n0 -1\n1 -2\n2\n1 0\n1 2\n1 2", "3\n2\n0 -1\n0 -1\n2 1\n1\n2 0\n0 -1\n1 -2\n2\n1 0\n1 2\n1 1", "3\n1\n0 1\n0 0\n1 0\n4\n0 1\n0 0\n0 0\n2\n0 0\n0 3\n2 1", "3\n2\n0 2\n0 0\n1 0\n2\n0 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n2\n0 0\n0 -1\n1 0\n2\n0 0\n-1 0\n1 0\n2\n0 0\n1 2\n3 1", "3\n2\n0 0\n1 -1\n1 0\n3\n0 0\n0 0\n1 -1\n2\n0 0\n1 2\n2 1", "3\n3\n0 -1\n-1 -1\n1 0\n2\n-1 0\n0 0\n1 0\n2\n1 0\n1 2\n1 1", "3\n4\n0 -1\n-1 -1\n1 1\n2\n0 -1\n0 0\n1 -1\n2\n1 0\n1 2\n0 1", "3\n2\n0 -2\n-1 -1\n1 0\n2\n0 0\n0 0\n1 -1\n1\n1 -1\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n0 1\n-1 -1\n1 -1\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n1 0\n1 -1\n1 -1\n2\n1 0\n2 2\n2 1", "3\n2\n0 -1\n-1 -1\n2 0\n2\n1 0\n1 -1\n1 -1\n3\n1 0\n1 2\n1 0", "3\n2\n0 -1\n-1 -1\n2 1\n2\n1 1\n0 -1\n0 -2\n2\n1 0\n1 2\n1 1", "3\n2\n0 -1\n0 -1\n2 1\n2\n2 1\n0 -1\n1 -2\n2\n1 1\n1 2\n1 1", "3\n2\n0 0\n0 -1\n2 -1\n1\n2 0\n0 -1\n1 -2\n2\n1 0\n1 2\n1 2", "3\n2\n0 -1\n0 -1\n2 1\n1\n2 0\n0 -1\n1 -2\n2\n1 0\n0 2\n1 1", "3\n1\n0 0\n0 0\n1 0\n4\n0 1\n0 0\n0 0\n2\n0 0\n0 3\n2 1", "3\n2\n0 2\n0 0\n1 0\n2\n-1 1\n0 0\n1 0\n2\n0 0\n0 2\n2 1", "3\n2\n0 0\n0 -1\n1 0\n2\n0 0\n-1 0\n1 0\n2\n0 0\n1 2\n3 2", "3\n2\n0 0\n1 -1\n1 0\n3\n0 0\n0 0\n1 -1\n3\n0 0\n1 2\n2 1", "3\n3\n0 -1\n-1 -2\n1 0\n2\n-1 0\n0 0\n1 0\n2\n1 0\n1 2\n1 1", "3\n4\n0 -1\n-1 -1\n1 1\n2\n0 -1\n0 0\n1 -1\n2\n2 0\n1 2\n0 1", "3\n2\n0 -2\n-1 -1\n1 0\n2\n0 0\n-1 0\n1 -1\n1\n1 -1\n1 2\n1 1", "3\n2\n0 -1\n-1 -1\n1 0\n2\n0 1\n-1 -1\n1 -1\n2\n1 0\n1 2\n2 1", "3\n2\n0 -1\n0 -1\n1 0\n2\n1 0\n1 -1\n1 -1\n2\n1 0\n2 2\n1 1", "3\n2\n0 -1\n-1 -1\n2 0\n2\n1 0\n1 -1\n1 -1\n3\n1 0\n2 2\n1 0", "3\n2\n0 -1\n0 -1\n2 1\n2\n2 1\n0 -1\n1 -2\n2\n1 1\n1 3\n1 1", "3\n2\n0 1\n0 -1\n2 -1\n1\n2 0\n0 -1\n1 -2\n2\n1 0\n1 2\n1 2", "3\n2\n0 -1\n0 -1\n2 1\n1\n3 0\n0 -1\n1 -2\n2\n1 0\n0 2\n1 1", "3\n1\n0 0\n0 0\n1 0\n4\n0 2\n0 0\n0 0\n2\n0 0\n0 3\n2 1", "3\n2\n0 2\n0 0\n1 0\n2\n-1 1\n0 0\n1 0\n2\n-1 0\n0 2\n2 1", "3\n2\n0 0\n1 -2\n1 0\n3\n0 0\n0 0\n1 -1\n3\n0 0\n1 2\n2 1", "3\n3\n0 -1\n-2 -2\n1 0\n2\n-1 0\n0 0\n1 0\n2\n1 0\n1 2\n1 1", "3\n7\n0 -1\n-1 -1\n1 1\n2\n0 -1\n0 0\n1 -1\n2\n2 0\n1 2\n0 1", "3\n2\n-1 -1\n-1 -1\n1 0\n2\n0 1\n-1 -1\n1 -1\n2\n1 0\n1 2\n2 1", "3\n2\n0 -1\n0 -1\n1 0\n2\n1 0\n2 -1\n1 -1\n2\n1 0\n2 2\n1 1", "3\n2\n0 -1\n-1 -1\n2 0\n2\n1 0\n1 -1\n1 -1\n3\n1 0\n2 1\n1 0", "3\n2\n0 -1\n0 -2\n2 1\n2\n2 1\n0 -1\n1 -2\n2\n1 1\n1 3\n1 1", "3\n2\n0 1\n0 -1\n2 -1\n1\n2 -1\n0 -1\n1 -2\n2\n1 0\n1 2\n1 2", "3\n2\n0 -1\n0 -1\n2 1\n1\n3 0\n0 -1\n1 -2\n2\n1 1\n0 2\n1 1", "3\n1\n0 0\n0 0\n1 0\n4\n0 2\n0 1\n0 0\n2\n0 0\n0 3\n2 1", "3\n2\n0 2\n0 0\n1 0\n2\n-1 0\n0 0\n1 0\n2\n-1 0\n0 2\n2 1", "3\n2\n0 0\n1 -2\n1 0\n3\n0 1\n0 0\n1 -1\n3\n0 0\n1 2\n2 1", "3\n3\n0 -1\n-2 -1\n1 0\n2\n-1 0\n0 0\n1 0\n2\n1 0\n1 2\n1 1", "3\n4\n0 -1\n-1 -1\n1 1\n2\n0 -1\n0 0\n2 -1\n2\n2 0\n1 2\n0 1"], "outputs": ["yes\nyes\nno\n", "no\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nyes\n", "no\nyes\nyes\n", "no\nno\nyes\n", "yes\nno\nyes\n", "no\nno\nno\n", "yes\nno\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "no\nyes\nyes\n", "no\nyes\nyes\n", "no\nyes\nyes\n", "no\nno\nyes\n", "no\nno\nyes\n", "yes\nyes\nno\n", "no\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "no\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "no\nyes\nyes\n", "no\nyes\nyes\n", "no\nyes\nyes\n", "no\nyes\nyes\n", "no\nno\nyes\n", "no\nno\nyes\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "no\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "no\nyes\nyes\n", "no\nno\nyes\n", "no\nno\nyes\n", "yes\nno\nyes\n", "no\nno\nyes\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "no\nyes\nno\n", "yes\nno\nyes\n", "yes\nyes\nyes\n", "no\nyes\nyes\n", "no\nno\nyes\n", "no\nno\nyes\n", "yes\nno\nyes\n", "no\nno\nyes\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nno\n", "no\nyes\nno\n", "yes\nno\nyes\n", "yes\nyes\nyes\n", "no\nyes\nyes\n", "no\nno\nyes\n", "yes\nno\nyes\n", "no\nno\nyes\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nno\n", "no\nno\nyes\n", "yes\nyes\nyes\n", "no\nyes\nyes\n", "no\nno\nyes\n", "yes\nno\nyes\n", "no\nno\nyes\n", "yes\nyes\nno\n", "yes\nyes\nno\n", "yes\nyes\nyes\n", "yes\nyes\nyes\n", "yes\nyes\nno\n"]}
1
[ "PYTHON3" ]
1
2
code_contests
749440f73d213d141ea3e1da803f6198
gcd2
Frank explained its friend Felman the algorithm of Euclides to calculate the GCD of two numbers. Then Felman implements it algorithm int gcd(int a, int b) { if (b==0) return a; else return gcd(b,a%b); } and it proposes to Frank that makes it but with a little integer and another integer that has up to 250 digits. Your task is to help Frank programming an efficient code for the challenge of Felman. Input The first line of the input file contains a number representing the number of lines to follow. Each line consists of two number A and B (0 ≀ A ≀ 40000 and A ≀ B < 10^250). Output Print for each pair (A,B) in the input one integer representing the GCD of A and B. Example Input: 2 2 6 10 11 Output: 2 1
{"inputs": ["2\n2 6\n10 11", "2\n3 6\n10 11", "2\n1 3\n10 11", "2\n0 6\n10 11", "2\n0 6\n0 11", "2\n3 6\n8 22", "2\n3 6\n8 4", "2\n5 2\n10 2", "2\n4 10\n8 6", "2\n7 14\n8 6", "2\n7 14\n8 4", "2\n2 6\n5 2", "2\n0 14\n16 2", "2\n0 11\n10 1", "2\n0 14\n16 1", "2\n1 3\n10 5", "2\n0 12\n0 11", "2\n3 8\n8 4", "2\n0 5\n8 6", "2\n7 14\n8 5", "2\n0 6\n0 2", "2\n0 20\n10 1", "2\n0 6\n12 20", "2\n0 4\n5 2", "2\n0 18\n7 1", "2\n0 4\n16 6", "2\n0 20\n12 2", "2\n3 6\n9 15", "2\n1 2\n14 7", "2\n1 2\n14 14", "2\n0 1\n9 6", "2\n0 4\n20 4", "2\n0 12\n21 2", "2\n7 15\n16 16", "2\n0 2\n14 14", "2\n0 2\n9 6", "2\n0 12\n21 3", "2\n0 10\n1 10", "2\n0 10\n3 3", "2\n8 18\n16 16", "2\n0 17\n1 17", "2\n1 6\n11 22", "2\n0 17\n0 17", "2\n0 23\n39 1", "2\n0 2\n10 30", "2\n0 5\n1 17", "2\n0 2\n12 30", "2\n1 2\n0 12", "2\n1 2\n0 20", "2\n0 2\n0 20", "2\n0 8\n2 5", "2\n0 3\n0 20", "2\n0 8\n0 5", "2\n0 4\n0 11", "2\n0 6\n10 5", "2\n3 6\n8 8", "2\n3 6\n6 6", "2\n0 9\n5 1", "2\n0 13\n10 1", "2\n0 26\n11 1", "2\n2 6\n4 20", "2\n2 3\n10 20", "2\n0 2\n0 11", "2\n3 8\n8 8", "2\n3 6\n0 14", "2\n0 2\n5 25", "2\n0 25\n0 2", "2\n0 32\n12 1", "2\n3 6\n9 18", "2\n0 4\n9 6", "2\n0 10\n8 10", "2\n0 8\n4 2", "2\n0 6\n21 28", "2\n3 9\n0 15", "2\n7 7\n16 16", "2\n5 10\n14 14", "2\n0 10\n0 10", "2\n0 9\n3 3", "2\n0 19\n26 3", "2\n0 17\n0 14", "2\n0 34\n39 1", "2\n1 3\n6 42", "2\n0 2\n15 30", "2\n2 3\n0 25", "2\n2 2\n0 12", "2\n1 8\n0 9", "2\n0 4\n10 5", "2\n0 52\n11 1", "2\n3 3\n10 11", "2\n3 6\n8 11", "2\n5 3\n10 11", "2\n2 3\n10 11", "2\n5 1\n10 11", "2\n2 3\n14 11", "2\n5 2\n10 11", "2\n2 3\n14 13", "2\n3 6\n8 3", "2\n2 1\n14 13", "2\n3 6\n8 6", "2\n5 3\n10 2", "2\n0 1\n14 13"], "outputs": ["2\n1\n", "3\n1\n", "1\n1\n", "6\n1\n", "6\n11\n", "3\n2\n", "3\n4\n", "1\n2\n", "2\n2\n", "7\n2\n", "7\n4\n", "2\n1\n", "14\n2\n", "11\n1\n", "14\n1\n", "1\n5\n", "12\n11\n", "1\n4\n", "5\n2\n", "7\n1\n", "6\n2\n", "20\n1\n", "6\n4\n", "4\n1\n", "18\n1\n", "4\n2\n", "20\n2\n", "3\n3\n", "1\n7\n", "1\n14\n", "1\n3\n", "4\n4\n", "12\n1\n", "1\n16\n", "2\n14\n", "2\n3\n", "12\n3\n", "10\n1\n", "10\n3\n", "2\n16\n", "17\n1\n", "1\n11\n", "17\n17\n", "23\n1\n", "2\n10\n", "5\n1\n", "2\n6\n", "1\n12\n", "1\n20\n", "2\n20\n", "8\n1\n", "3\n20\n", "8\n5\n", "4\n11\n", "6\n5\n", "3\n8\n", "3\n6\n", "9\n1\n", "13\n1\n", "26\n1\n", "2\n4\n", "1\n10\n", "2\n11\n", "1\n8\n", "3\n14\n", "2\n5\n", "25\n2\n", "32\n1\n", "3\n9\n", "4\n3\n", "10\n2\n", "8\n2\n", "6\n7\n", "3\n15\n", "7\n16\n", "5\n14\n", "10\n10\n", "9\n3\n", "19\n1\n", "17\n14\n", "34\n1\n", "1\n6\n", "2\n15\n", "1\n25\n", "2\n12\n", "1\n9\n", "4\n5\n", "52\n1\n", "3\n1\n", "3\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "3\n1\n", "1\n1\n", "3\n2\n", "1\n2\n", "1\n1\n"]}
2
[ "PYTHON3" ]
1
2
code_contests
653443722527be14f1ea12ffbd80a3f3
luckybal
A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7. The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≀ X ≀ M) such that the number of digits 4 in the substring T[1, X - 1] is equal to the number of digits 7 in the substring T[X, M]. For example, the string S = 7477447 is balanced since S[1, 4] = 7477 has 1 digit 4 and S[5, 7] = 447 has 1 digit 7. On the other hand, one can verify that the string S = 7 is not balanced. The Little Elephant has the string S of the length N. He wants to know the number of such pairs of integers (L; R) that 1 ≀ L ≀ R ≀ N and the substring S[L, R] is balanced. Help him to find this number. Notes. Let S be some lucky string. Then |S| denotes the length of the string S; S[i] (1 ≀ i ≀ |S|) denotes the i^th character of S (the numeration of characters starts from 1); S[L, R] (1 ≀ L ≀ R ≀ |S|) denotes the string with the following sequence of characters: S[L], S[L + 1], ..., S[R], and is called a substring of S. For L > R we mean by S[L, R] an empty string. Input The first line of the input file contains a single integer T, the number of test cases. Each of the following T lines contains one string, the string S for the corresponding test case. The input file does not contain any whitespaces. Output For each test case output a single line containing the answer for this test case. Constraints 1 ≀ T ≀ 10 1 ≀ |S| ≀ 100000 S consists only of the lucky digits 4 and 7. Example Input: 4 47 74 477 4747477 Output: 2 2 3 23 Explanation In the first test case balance substrings are S[1, 1] = 4 and S[1, 2] = 47. In the second test case balance substrings are S[2, 2] = 4 and S[1, 2] = 74. Unfortunately, we can't provide you with the explanations of the third and the fourth test cases. You should figure it out by yourself. Please, don't ask about this in comments.
{"inputs": ["4\n47\n74\n477\n4747477", "4\n47\n47\n477\n4747477", "4\n7\n47\n477\n4747477", "4\n4\n47\n477\n4747477", "4\n7\n7\n477\n4747477", "4\n7\n44\n477\n4747477", "4\n44\n74\n477\n4747477", "4\n7\n44\n7\n4747477", "4\n47\n44\n477\n4747477", "4\n47\n4\n477\n4747477", "4\n7\n7\n447\n4747477", "4\n47\n7\n477\n4747477", "4\n44\n44\n477\n4747477", "4\n4\n44\n477\n4747477", "4\n74\n47\n477\n4747477", "4\n44\n47\n477\n4747477", "4\n7\n74\n477\n4747477", "4\n7\n77\n477\n4747477", "4\n47\n77\n477\n4747477", "4\n4\n74\n477\n4747477"], "outputs": ["2\n2\n3\n23\n", "2\n2\n3\n23\n", "0\n2\n3\n23\n", "1\n2\n3\n23\n", "0\n0\n3\n23\n", "0\n3\n3\n23\n", "3\n2\n3\n23\n", "0\n3\n0\n23\n", "2\n3\n3\n23\n", "2\n1\n3\n23\n", "0\n0\n5\n23\n", "2\n0\n3\n23\n", "3\n3\n3\n23\n", "1\n3\n3\n23\n", "2\n2\n3\n23\n", "3\n2\n3\n23\n", "0\n2\n3\n23\n", "0\n0\n3\n23\n", "2\n0\n3\n23\n", "1\n2\n3\n23\n"]}
2
[ "PYTHON3" ]
1
2
code_contests
713702cb48591218c127ac8b5855b911
prpaln
Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before. Input First line of the input contains a single integer T denoting number of test cases. For each test case, you are given a single line containing string s. Output For each test case, print YES or NO depending on the answer of the problem. Constraints Example Input: 4 aaa abc abdbca abba Output: YES NO YES YES Explanation Example case 1. Delete any one 'a', resulting string is "aa" which is a palindrome. Example case 2. It is not possible to delete exactly one character and having a palindrome. Example case 3. Delete 'c', resulting string is "abdba" which is a palindrome. Example case 4. Delete 'b', resulting string is "aba" which is a palindrome.
{"inputs": ["4\naaa\nabc\nabdbca\nabba", "4\naaa\nabc\nabdbca\nabca", "4\naaa\nabc\nabdbc`\naaca", "4\naab\nacc\n`bd`cb\naaad", "4\nbaa\nabc\n`bd`bb\naabd", "4\nbab\nabb\nbb`db`\naabd", "4\nbaa\n`aa\nbb`c`b\ndba`", "4\nba`\n`aa\nbb`c_c\ndba`", "4\n`a_\naa`\ndda`^c\nca^a", "4\n_c`\n]`_\ncdad^`\n`c_^", "4\n_c`\n]`_\ncdac^`\n_c_^", "4\ne`_\n_\\^\nd_`c_d\nbc^_", "4\naaa\nabc\nabdbca\naaca", "4\naaa\nabc\n`bdbc`\naaca", "4\naab\nabc\n`bdbc`\naaca", "4\nbaa\nabc\n`bdbc`\naaca", "4\nbaa\nabc\nabdbc`\naaca", "4\nbaa\nabc\nabd`cb\naaca", "4\nbaa\nabc\nabd`cb\nacaa", "4\nbaa\nabc\n`bd`cb\nacaa", "4\nbaa\nabc\n`bd`cb\nadaa", "4\nbaa\nabc\n`bd`cb\naaad", "4\naab\nabc\n`bd`cb\naaad", "4\naab\nacc\n`bd`bb\naaad", "4\naab\nacc\n`cd`bb\naaad", "4\nbaa\nacc\n`cd`bb\naaad", "4\nbaa\nacc\n`bd`bb\naaad", "4\nbaa\nabc\n`bd`bb\naaad", "4\nbaa\nabc\nbb`db`\naabd", "4\nbab\nabc\nbb`db`\naabd", "4\nbab\nacb\nbb`db`\naabd", "4\nbab\naca\nbb`db`\naabd", "4\nbab\naba\nbb`db`\naabd", "4\nbab\naba\nbb`cb`\naabd", "4\nbab\naba\ncb`cb`\naabd", "4\naab\naba\ncb`cb`\naabd", "4\naab\naba\n`bc`bc\naabd", "4\nbaa\naba\ncb`cb`\naabd", "4\nbaa\naaa\ncb`cb`\naabd", "4\nbaa\naaa\ncb`cb`\ndbaa", "4\nbaa\naaa\nbb`cb`\ndbaa", "4\nbaa\naaa\nbb`cb`\ndba`", "4\nbaa\n`aa\nbb`cb`\ndba`", "4\nbaa\na`a\nbb`c`b\ndba`", "4\nbaa\na`a\nbb`c`c\ndba`", "4\nbaa\na`a\nbb`c_c\ndba`", "4\nbaa\n`aa\nbb`c_c\ndba`", "4\nba_\n`aa\nbb`c_c\ndba`", "4\nba_\n`aa\nbb_c_c\ndba`", "4\nba_\n`aa\nbb_c_c\nabd`", "4\naa_\n`aa\nbb_c_c\nabd`", "4\nab_\n`aa\nbb_c_c\nabd`", "4\nab_\n`aa\nbb_c_c\nab`d", "4\nab_\n`aa\nbb_c_c\nba`d", "4\nab_\n`aa\nbb_c_c\nbad`", "4\nab_\n`aa\nbb_c_c\n`dab", "4\n_ba\n`aa\nbb_c_c\n`dab", "4\n_ba\n`aa\n_b_cbc\n`dab", "4\n_ba\n`aa\ncbc_b_\n`dab", "4\nab_\n`aa\ncbc_b_\n`dab", "4\nab_\naa`\ncbc_b_\n`dab", "4\n_ba\naa`\ncbc_b_\n`dab", "4\n_ba\naa`\ncbc__b\n`dab", "4\n^ba\naa`\ncbc__b\n`dab", "4\n^ba\naa`\ncbc__b\n`cab", "4\n^ba\naa`\ncbc__b\n_cab", "4\n^aa\naa`\ncbc__b\n_cab", "4\n^aa\naa`\ncbc__b\n_caa", "4\n^aa\naa`\ncbc__c\n_caa", "4\n^aa\naa`\ncbc__c\n^caa", "4\naa^\naa`\ncbc__c\n^caa", "4\naa^\n`aa\ncbc__c\n^caa", "4\naa^\n`aa\ncbc`_c\n^caa", "4\naa^\n``a\ncbc`_c\n^caa", "4\naa^\n`a`\ncbc`_c\n^caa", "4\naa^\n`a`\ncbc`_c\nc^aa", "4\naa^\n`a`\ndbc`_c\nc^aa", "4\naa_\n`a`\ndbc`_c\nc^aa", "4\naa_\n`a`\ndac`_c\nc^aa", "4\naa_\n`a`\nc_`cad\nc^aa", "4\n`a_\n`a`\nc_`cad\nc^aa", "4\n`a_\n`a`\nc_`dad\nc^aa", "4\n`a_\n`a`\ndad`_c\nc^aa", "4\n`a_\n`a`\ndad`^c\nc^aa", "4\n`a_\n`a`\ndad`^c\naa^c", "4\n`a_\na``\ndad`^c\naa^c", "4\n`a_\na``\ndda`^c\naa^c", "4\n`a_\naa`\ndda`^c\naa^c", "4\n`a_\naa`\nc^`add\nca^a", "4\n`a_\naa`\ndda`^c\ncb^a", "4\n`a_\naa`\ndda`^c\na^bc", "4\n`a_\na``\ndda`^c\na^bc", "4\n`a_\na``\ndda`^c\n`^bc", "4\n`a_\na``\ncda`^c\n`^bc", "4\n_a`\na``\ncda`^c\n`^bc", "4\n`a_\n``a\ncda`^c\n`^bc", "4\n`a_\na``\ncd``^c\n`^bc", "4\n`a_\na``\ncd``^c\nb^`c", "4\n`b_\na``\ncd``^c\nb^`c", "4\n_b`\na``\ncd``^c\nb^`c", "4\n_b`\na``\ncd``^c\nb^_c"], "outputs": ["YES\nNO\nYES\nYES\n", "YES\nNO\nYES\nYES\n", "YES\nNO\nNO\nYES\n", "YES\nYES\nNO\nYES\n", "YES\nNO\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nYES\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nYES\n", "NO\nNO\nNO\nNO\n", "NO\nNO\nNO\nYES\n", "NO\nNO\nYES\nNO\n", "YES\nNO\nYES\nYES\n", "YES\nNO\nYES\nYES\n", "YES\nNO\nYES\nYES\n", "YES\nNO\nYES\nYES\n", "YES\nNO\nNO\nYES\n", "YES\nNO\nNO\nYES\n", "YES\nNO\nNO\nYES\n", "YES\nNO\nNO\nYES\n", "YES\nNO\nNO\nYES\n", "YES\nNO\nNO\nYES\n", "YES\nNO\nNO\nYES\n", "YES\nYES\nNO\nYES\n", "YES\nYES\nNO\nYES\n", "YES\nYES\nNO\nYES\n", "YES\nYES\nNO\nYES\n", "YES\nNO\nNO\nYES\n", "YES\nNO\nNO\nNO\n", "YES\nNO\nNO\nNO\n", "YES\nNO\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nYES\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "YES\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nYES\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n", "NO\nYES\nNO\nNO\n"]}
2
[ "PYTHON3" ]
1
2
code_contests
91659162144fae7c6e65f91d02379043
tf01
An established group of scientists are working on finding solution to NP hard problems. They claim Subset Sum as an NP-hard problem. The problem is to determine whether there exists a subset of a given set S whose sum is a given number K. You are a computer engineer and you claim to solve this problem given that all numbers in the set are non-negative. Given a set S of size N of non-negative integers, find whether there exists a subset whose sum is K. Input First line of input contains T, the number of test cases. T test cases follow. Each test case contains 2 lines. First line contains two integers N and K. Next line contains N space separated non-negative integers (each less than 100000). 0 < T < 1000 0 < N < 1000 0 < K < 1000 Output Output T lines, one for each test case. Every line should be either 0 or 1 depending on whether such a subset exists or not. Example Input: 2 5 10 3 4 6 1 9 3 2 1 3 4 Output: 1 0
{"inputs": ["2\n5 10\n3 4 6 1 9\n3 2\n1 3 4"], "outputs": ["1\n0"]}
6
[ "PYTHON3" ]
1
2
code_contests
78e09093cc14a9153fa66da7dded8afd
1012_E. Cycle sort
You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following operation any number of times: select several distinct indices i_1, i_2, ..., i_k (1 ≀ i_j ≀ n) and move the number standing at the position i_1 to the position i_2, the number at the position i_2 to the position i_3, ..., the number at the position i_k to the position i_1. In other words, the operation cyclically shifts elements: i_1 β†’ i_2 β†’ … i_k β†’ i_1. For example, if you have n=4, an array a_1=10, a_2=20, a_3=30, a_4=40, and you choose three indices i_1=2, i_2=1, i_3=4, then the resulting array would become a_1=20, a_2=40, a_3=30, a_4=10. Your goal is to make the array sorted in non-decreasing order with the minimum number of operations. The additional constraint is that the sum of cycle lengths over all operations should be less than or equal to a number s. If it's impossible to sort the array while satisfying that constraint, your solution should report that as well. Input The first line of the input contains two integers n and s (1 ≀ n ≀ 200 000, 0 ≀ s ≀ 200 000)β€”the number of elements in the array and the upper bound on the sum of cycle lengths. The next line contains n integers a_1, a_2, ..., a_nβ€”elements of the array (1 ≀ a_i ≀ 10^9). Output If it's impossible to sort the array using cycles of total length not exceeding s, print a single number "-1" (quotes for clarity). Otherwise, print a single number qβ€” the minimum number of operations required to sort the array. On the next 2 β‹… q lines print descriptions of operations in the order they are applied to the array. The description of i-th operation begins with a single line containing one integer k (1 ≀ k ≀ n)β€”the length of the cycle (that is, the number of selected indices). The next line should contain k distinct integers i_1, i_2, ..., i_k (1 ≀ i_j ≀ n)β€”the indices of the cycle. The sum of lengths of these cycles should be less than or equal to s, and the array should be sorted after applying these q operations. If there are several possible answers with the optimal q, print any of them. Examples Input 5 5 3 2 3 1 1 Output 1 5 1 4 2 3 5 Input 4 3 2 1 4 3 Output -1 Input 2 0 2 2 Output 0 Note In the first example, it's also possible to sort the array with two operations of total length 5: first apply the cycle 1 β†’ 4 β†’ 1 (of length 2), then apply the cycle 2 β†’ 3 β†’ 5 β†’ 2 (of length 3). However, it would be wrong answer as you're asked to use the minimal possible number of operations, which is 1 in that case. In the second example, it's possible to the sort the array with two cycles of total length 4 (1 β†’ 2 β†’ 1 and 3 β†’ 4 β†’ 3). However, it's impossible to achieve the same using shorter cycles, which is required by s=3. In the third example, the array is already sorted, so no operations are needed. Total length of empty set of cycles is considered to be zero.
{"inputs": ["5 5\n3 2 3 1 1\n", "4 3\n2 1 4 3\n", "2 0\n2 2\n", "5 0\n884430748 884430748 708433020 708433020 708433020\n", "2 1\n1 1\n", "2 0\n2 1\n", "5 2\n65390026 770505072 65390026 65390026 65390026\n", "5 4\n812067558 674124159 106041640 106041640 674124159\n", "5 4\n167616600 574805150 651016425 150949603 379708534\n", "5 5\n472778319 561757623 989296065 99763286 352037329\n", "5 4\n201429826 845081337 219611799 598937628 680006294\n", "2 2\n2 1\n", "5 0\n1000000000 1000000000 1000000000 1000000000 1000000000\n", "5 6\n971458729 608568364 891718769 464295315 98863653\n", "5 5\n641494999 641494999 228574099 535883079 535883079\n", "5 5\n815605413 4894095 624809427 264202135 152952491\n", "1 0\n258769137\n", "2 0\n1 1\n", "1 0\n2\n", "5 4\n335381650 691981363 691981363 335381650 335381650\n", "5 4\n81224924 319704343 319704343 210445208 128525140\n", "5 4\n579487081 564229995 665920667 665920667 644707366\n", "5 200000\n682659092 302185582 518778252 29821187 14969298\n", "5 0\n884430748 884430748 182474629 708433020 708433020\n", "5 2\n65390026 1454694739 65390026 65390026 65390026\n", "5 4\n167616600 574805150 651016425 232181430 379708534\n", "5 4\n201429826 845081337 219611799 598937628 1013339305\n", "2 2\n4 1\n", "5 6\n971458729 608568364 891718769 268781113 98863653\n", "5 5\n539341452 4894095 624809427 264202135 152952491\n", "1 0\n483419747\n", "5 4\n579487081 564229995 288357375 665920667 644707366\n", "5 200000\n682659092 302185582 185982759 29821187 14969298\n", "4 3\n2 2 6 3\n", "5 4\n201429826 845081337 219611799 1097635109 1811343985\n", "5 6\n335381650 691981363 484551438 335381650 201569796\n", "5 1\n641494999 641494999 228574099 535883079 535883079\n", "1 0\n1\n", "5 4\n335381650 691981363 691981363 335381650 201569796\n", "5 1\n81224924 319704343 319704343 210445208 128525140\n", "4 3\n2 1 6 3\n", "5 -1\n884430748 884430748 182474629 708433020 708433020\n", "5 2\n65390026 1454694739 65390026 65390026 100733760\n", "0 4\n167616600 574805150 651016425 232181430 379708534\n", "5 4\n201429826 845081337 219611799 598937628 1811343985\n", "1 2\n4 1\n", "5 3\n971458729 608568364 891718769 268781113 98863653\n", "5 0\n641494999 641494999 228574099 535883079 535883079\n", "5 2\n539341452 4894095 624809427 264202135 152952491\n", "1 1\n483419747\n", "0 0\n1\n", "5 4\n335381650 691981363 484551438 335381650 201569796\n", "5 1\n81224924 413380565 319704343 210445208 128525140\n", "5 4\n579487081 564229995 288357375 946230441 644707366\n", "5 200000\n682659092 302185582 185982759 20056766 14969298\n", "5 -1\n884430748 884430748 267312749 708433020 708433020\n", "5 2\n501175 1454694739 65390026 65390026 100733760\n", "0 4\n167616600 90071718 651016425 232181430 379708534\n", "1 2\n6 1\n", "5 3\n971458729 341020287 891718769 268781113 98863653\n", "5 -1\n641494999 641494999 228574099 535883079 535883079\n", "5 2\n539341452 4894095 624809427 264202135 209695341\n", "1 1\n682471575\n", "0 0\n2\n", "3 1\n81224924 413380565 319704343 210445208 128525140\n", "5 4\n579487081 92588299 288357375 946230441 644707366\n"], "outputs": ["1\n5\n1 4 2 3 5 \n", "-1\n", "0\n", "-1\n", "0\n", "-1\n", "1\n2\n2 5 \n", "-1\n", "-1\n", "1\n5\n1 3 5 2 4 \n", "1\n4\n2 5 4 3 \n", "1\n2\n1 2 \n", "0\n", "2\n2\n1 5\n3\n2 3 4\n", "1\n5\n1 4 2 5 3 \n", "2\n3\n1 5 2\n2\n3 4\n", "0\n", "0\n", "0\n", "1\n4\n2 4 3 5 \n", "1\n4\n2 4 3 5 \n", "2\n2\n1 2\n2\n3 5\n", "2\n2\n1 5\n3\n2 3 4\n", "-1\n", "1\n2\n2 5 \n", "2\n2\n2 4 \n2\n3 5 \n", "1\n3\n2 4 3 \n", "1\n2\n1 2 \n", "2\n2\n1 5 \n3\n2 3 4 \n", "1\n5\n1 4 3 5 2 \n", "0\n", "2\n2\n1 3 \n2\n4 5 \n", "2\n2\n1 5 \n2\n2 4 \n", "1\n2\n3 4 \n", "1\n2\n2 3 \n", "1\n5\n1 3 4 2 5 \n", "-1\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "0\n", "1\n3\n2 4 3 \n", "0\n", "-1\n", "-1\n", "-1\n", "0\n", "0\n", "-1\n", "-1\n", "2\n2\n1 3 \n2\n4 5 \n", "2\n2\n1 5 \n2\n2 4 \n", "-1\n", "-1\n", "0\n", "0\n", "-1\n", "-1\n", "-1\n", "0\n", "0\n", "-1\n", "-1\n"]}
11
[ "PYTHON3" ]
2
2
code_contests
2134415ced87b8fc2bce4549a0aeef7a
1037_E. Trips
There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends. We want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold: * Either this person does not go on the trip, * Or at least k of his friends also go on the trip. Note that the friendship is not transitive. That is, if a and b are friends and b and c are friends, it does not necessarily imply that a and c are friends. For each day, find the maximum number of people that can go on the trip on that day. Input The first line contains three integers n, m, and k (2 ≀ n ≀ 2 β‹… 10^5, 1 ≀ m ≀ 2 β‹… 10^5, 1 ≀ k < n) β€” the number of people, the number of days and the number of friends each person on the trip should have in the group. The i-th (1 ≀ i ≀ m) of the next m lines contains two integers x and y (1≀ x, y≀ n, xβ‰  y), meaning that persons x and y become friends on the morning of day i. It is guaranteed that x and y were not friends before. Output Print exactly m lines, where the i-th of them (1≀ i≀ m) contains the maximum number of people that can go on the trip on the evening of the day i. Examples Input 4 4 2 2 3 1 2 1 3 1 4 Output 0 0 3 3 Input 5 8 2 2 1 4 2 5 4 5 2 4 3 5 1 4 1 3 2 Output 0 0 0 3 3 4 4 5 Input 5 7 2 1 5 3 2 2 5 3 4 1 2 5 3 1 3 Output 0 0 0 0 3 4 4 Note In the first example, * 1,2,3 can go on day 3 and 4. In the second example, * 2,4,5 can go on day 4 and 5. * 1,2,4,5 can go on day 6 and 7. * 1,2,3,4,5 can go on day 8. In the third example, * 1,2,5 can go on day 5. * 1,2,3,5 can go on day 6 and 7.
{"inputs": ["4 4 2\n2 3\n1 2\n1 3\n1 4\n", "5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n", "5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "2 1 1\n2 1\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 10\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 4\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "9 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 3\n13 15\n1 8\n7 15\n1 7\n8 15\n", "2 1 2\n2 1\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 4\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 3\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 3\n13 15\n1 14\n7 15\n1 7\n8 15\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 3\n5 3\n11 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 3\n13 15\n1 14\n7 15\n1 7\n8 15\n", "27 20 2\n10 3\n5 3\n20 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 3\n10 3\n5 1\n20 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 3\n5 3\n10 5\n12 3\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "9 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 2\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 4\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 12\n13 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 4\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n9 3\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 3\n5 3\n13 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 3\n13 15\n1 14\n7 15\n1 7\n8 15\n", "16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 10\n2 5\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 4\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 3\n10 3\n14 4\n15 14\n4 13\n13 3\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 3\n5 3\n11 9\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 3\n13 15\n1 14\n7 15\n1 7\n8 15\n", "9 7 2\n1 5\n4 2\n2 5\n3 4\n1 2\n5 3\n1 3\n", "16 20 2\n10 4\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n6 12\n13 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 3\n5 3\n11 9\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 3\n13 15\n1 14\n3 15\n1 7\n8 15\n", "9 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n7 1\n3 2\n", "16 20 2\n10 4\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 3\n10 3\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 2\n10 3\n5 1\n20 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 3\n10 3\n5 1\n20 5\n12 7\n7 6\n12 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 3\n10 3\n5 1\n20 5\n12 5\n7 6\n12 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 3\n10 3\n5 1\n20 5\n12 5\n7 6\n12 10\n2 6\n1 10\n11 16\n11 1\n16 4\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 3\n10 3\n5 1\n20 5\n12 5\n13 6\n12 10\n2 6\n1 10\n11 16\n11 1\n16 4\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 3\n10 3\n5 1\n20 5\n12 5\n13 6\n12 10\n2 6\n1 10\n11 16\n11 1\n16 4\n3 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "2 1 3\n2 1\n", "27 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n19 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 2\n10 3\n5 3\n20 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 23\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 2\n10 3\n5 1\n20 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 16\n", "27 20 3\n10 3\n5 1\n20 2\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 3\n10 3\n5 1\n20 5\n12 7\n7 6\n12 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n25 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 3\n10 3\n5 1\n20 7\n12 5\n7 6\n12 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 3\n10 3\n5 1\n20 5\n12 5\n13 6\n12 10\n2 6\n1 10\n11 16\n11 1\n16 4\n10 2\n14 4\n15 24\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "27 20 3\n10 3\n5 1\n20 5\n12 5\n13 6\n12 10\n3 6\n1 10\n11 16\n11 1\n16 4\n3 2\n14 4\n15 14\n3 13\n1 15\n1 8\n7 15\n1 7\n8 15\n", "16 20 2\n10 3\n5 3\n13 5\n12 7\n7 6\n9 10\n2 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 3\n13 15\n2 14\n7 15\n1 7\n8 15\n", "16 20 2\n10 4\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 3\n10 3\n14 4\n15 14\n4 13\n13 3\n1 8\n7 15\n2 7\n8 15\n"], "outputs": ["0\n0\n3\n3\n", "0\n0\n0\n3\n3\n4\n4\n5\n", "0\n0\n0\n0\n3\n4\n4\n", "0\n0\n3\n3\n3\n3\n7\n7\n7\n7\n7\n11\n11\n11\n11\n15\n15\n15\n15\n16\n", "2\n", "0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n3\n7\n7\n7\n7\n11\n11\n14\n14\n15\n", "0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n3\n7\n7\n7\n7\n11\n11\n13\n13\n14\n", "0\n0\n0\n0\n0\n0\n4\n4\n4\n4\n4\n9\n9\n9\n9\n13\n13\n13\n13\n14\n", "0\n0\n0\n3\n3\n4\n4\n5\n", "0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n3\n7\n7\n7\n7\n7\n7\n12\n12\n13\n", "0\n", "0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n3\n7\n7\n7\n7\n7\n7\n11\n11\n12\n", "0\n0\n0\n0\n0\n0\n4\n4\n4\n4\n10\n10\n10\n10\n10\n14\n14\n14\n14\n15\n", "0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n3\n7\n7\n7\n7\n7\n9\n12\n12\n12\n", "0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n3\n7\n7\n7\n7\n7\n7\n10\n10\n11\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n5\n5\n7\n7\n7\n7\n7\n9\n12\n12\n12\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n5\n5\n5\n5\n5\n5\n8\n8\n9\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n3\n7\n7\n7\n7\n11\n11\n15\n15\n16\n", "0\n0\n0\n0\n3\n4\n4\n", "0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n6\n6\n6\n6\n6\n10\n10\n12\n13\n14\n", "0\n0\n0\n0\n0\n0\n4\n4\n4\n4\n4\n9\n9\n9\n10\n10\n10\n12\n12\n13\n", "0\n0\n0\n0\n0\n0\n4\n4\n4\n4\n4\n4\n4\n4\n4\n11\n11\n11\n12\n13\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n5\n5\n5\n5\n11\n11\n13\n13\n13\n", "0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n7\n7\n7\n7\n7\n7\n7\n7\n9\n10\n", "0\n0\n0\n0\n0\n0\n4\n4\n4\n4\n10\n10\n10\n10\n10\n12\n12\n14\n14\n15\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n4\n4\n6\n6\n6\n6\n6\n9\n12\n12\n12\n", "0\n0\n0\n0\n3\n5\n5\n", "0\n0\n0\n0\n0\n0\n4\n4\n4\n4\n4\n9\n9\n9\n9\n9\n9\n12\n12\n13\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n4\n4\n6\n6\n6\n6\n6\n9\n10\n12\n12\n", "0\n0\n0\n3\n3\n4\n4\n5\n", "0\n0\n0\n0\n0\n0\n4\n4\n4\n4\n10\n10\n10\n10\n10\n14\n14\n14\n14\n15\n", "0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n3\n7\n7\n7\n7\n7\n7\n10\n10\n11\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n5\n5\n5\n5\n5\n5\n8\n8\n9\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n", "0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n3\n7\n7\n7\n7\n7\n7\n10\n10\n11\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n5\n5\n5\n5\n5\n5\n8\n8\n9\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n5\n5\n5\n5\n5\n5\n8\n8\n9\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n5\n5\n5\n5\n11\n11\n13\n13\n13\n", "0\n0\n0\n0\n0\n0\n4\n4\n4\n4\n10\n10\n10\n10\n10\n12\n12\n14\n14\n15\n"]}
11
[ "PYTHON3" ]
2
2
code_contests
0df7a8f97f44a05d3e4d8a030305533f
1060_A. Phone Numbers
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit. For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not. You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct. Input The first line contains an integer n β€” the number of cards with digits that you have (1 ≀ n ≀ 100). The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, …, s_n. The string will not contain any other characters, such as leading or trailing spaces. Output If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0. Examples Input 11 00000000008 Output 1 Input 22 0011223344556677889988 Output 2 Input 11 31415926535 Output 0 Note In the first example, one phone number, "8000000000", can be made from these cards. In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789". In the third example you can't make any phone number from the given cards.
{"inputs": ["22\n0011223344556677889988\n", "11\n00000000008\n", "11\n31415926535\n", "51\n882889888888689888850888388887688788888888888858888\n", "55\n7271714707719515303911625619272900050990324951111943573\n", "72\n888488888888823288848804883838888888887888888888228888218488897809784868\n", "65\n44542121362830719677175203560438858260878894083124543850593761845\n", "54\n438283821340622774637957966575424773837418828888614203\n", "100\n1976473621569903172721407763737179639055561746310369779167351419713916160700096173622427077757986026\n", "100\n2833898888858387469888804083887280788584887487186899808436848018181838884988432785338497585788803883\n", "42\n885887846290886288816884858898812858495482\n", "75\n878909759892888846183608689257806813376950958863798487856148633095072259838\n", "11\n55814018693\n", "31\n0868889888343881888987888838808\n", "21\n888888888888000000000\n", "62\n18888883884288488882387888486858887882838885288886472818688888\n", "77\n11111111111111111111111111111111111111111111111111111111111111111111111111111\n", "30\n888888888888888888888888888888\n", "64\n8885984815868480968883818886281846682409262501034555933863969284\n", "44\n15920309219313427633220119270900111650391207\n", "97\n4088468966684435599488804806521288358953088399738904557539253573051442198885776802972628197705081\n", "100\n8800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", "50\n88888888888888888888888888888888888888888888888888\n", "20\n88888888888888888888\n", "32\n88888888888888888888888888888888\n", "82\n8889809888888888485881851986857288588888888881988888868888836888887858888888888878\n", "91\n8828880888888884883888488888888888888881888888888884888888848588888808888888888888888880888\n", "87\n311753415808202195240425076966761033489788093280714672959929008324554784724650182457298\n", "85\n6888887655188885918863889822590788834182048952565514598298586848861396753319582883848\n", "100\n8088888818885808888888848829886788884187188858898888888788988688884828586988888888288078638898728181\n", "21\n888111111111111111111\n", "1\n8\n", "93\n888088898748888038885888818882806848806887888888882087481868888888177809288888889648468888188\n", "77\n11233392925013001334679215120076714945221576003953746107506364475115045309091\n", "40\n8888888888888888888888888888888888888888\n", "33\n888800000000000000000000000000000\n", "21\n881234567900123456790\n", "98\n87247250157776241281197787785951754485531639139778166755966603305697265958800376912432893847612736\n", "90\n888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888\n", "22\n4215079217017196952791\n", "99\n509170332523502565755650047942914747120102240396245453406790272793996913905060450414255616791704320\n", "96\n812087553199958040928832802441581868680188987878748641868838838835609806814288472573117388803351\n", "1\n0\n", "100\n8888888888828188888888888888888808888888888888888888891888888768888888888288888885886888838888888888\n", "11\n80000000000\n", "86\n84065885114540280210185082984888812185222886689129308815942798404861082196041321701260\n", "92\n86888880558884738878888381088888888895888881888888888368878888888884888768881888888888808888\n", "76\n7900795570936733366353829649382870728119825830883973668601071678041634916557\n", "32\n88000000000000000000000000000000\n", "70\n8888888888888888888888888888888888888888888888888888888888888888888888\n", "11\n88888888888\n", "21\n888000000000000000000\n", "66\n747099435917145962031075767196746707764157706291155762576312312094\n", "22\n8899999999999999999999\n", "11\n81234567123\n", "41\n78888884888874788841882882888088888588888\n", "10\n8888888888\n", "100\n2867878187889776883889958480848802884888888878218089281860321588888888987288888884288488988628618888\n", "66\n157941266854773786962397310504192100434183957442977444078457168272\n", "44\n30153452341853403190257244993442815171970194\n", "63\n728385948188688801288285888788852829888898565895847689806684688\n", "100\n1835563855281170226095294644116563180561156535623048783710060508361834822227075869575873675232708159\n", "21\n888888555555555555555\n", "100\n8881888389882878867888888888888888888886388888888870888884878888089888883898887888808688888487888888\n", "53\n85838985300863473289888099788588319484149888886832906\n", "60\n888888888888888888888888888888888888888888888888888888888888\n", "100\n8820286285185244938452488887088871457098945874486988698468788381417332842888928188688887641132194956\n", "11\n24572366390\n", "84\n181288888282608548858058871581888853888486785801381108858832882809848798828837386086\n", "32\n88257478884887437239023185588797\n", "99\n097167815527663544905782574817314139311067328533970663873718450545467450059059869618211361469505108\n", "43\n7404899846883344886153727489084158470112581\n", "100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008\n", "8\n12345678\n", "88\n2694079127792970410465292300936220976260790323517221561516591792566791677970332966660472\n", "21\n582586788289484878588\n", "33\n270375004567749549929235905225024\n", "50\n88000000000000000000000000000000000000000000000000\n", "33\n429980628264468835720540136177288\n", "27\n888000000000000000000000000\n", "10\n8000000000\n", "74\n70988894874867688968816582886488688881063425288316858438189808828755218508\n", "22\n6188156585823394680191\n", "81\n808888883488887888888808888888888888188888888388888888888888868688888488888882888\n", "57\n888888888888888888888888888888888888888888888888888888888\n", "100\n6451941807833681891890004306065158148809856572066617888008875119881621810329816763604830895480467878\n", "83\n88584458884288808888588388818938838468960248387898182887888867888888888886088895788\n", "11\n81234567090\n", "21\n880000000000000000000\n", "94\n8188948828818938226378510887848897889883818858778688882933888883888898198978868888808082461388\n", "52\n8878588869084488848898838898788838337877898817818888\n", "61\n8880888836888988888988888887388888888888868898887888818888888\n", "71\n88888888888888888888888188888805848888788088888883888883187888838888888\n", "95\n29488352815808808845913584782288724288898869488882098428839370889284838688458247785878848884289\n", "73\n2185806538483837898808836883483888818818988881880688028788888081888907898\n", "80\n88888888888888888888888888888888888888888888888888888888888888888888888888888888\n", "55\n3982037603326093160114589190899881252765957832414122484\n", "100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888\n", "51\n1732111733638718702525811518175029394157760329139501\n", "55\n8150965228922987149322123425550549439018369681986057802\n", "72\n129108839650139854381903715683735947815379560715643428841035623040980032\n", "42\n1251996236006506309908626867460855811743437\n", "11\n78451611424\n", "31\n1288033400433082469939233589875\n", "77\n11111111111111111111111111110111111111111111111111111111111111111111111111111\n", "100\n6152069453350735030379611937645928787504993143655436498747601445943408903686298029084639414463403044\n", "91\n14936165072891114728916862658660934186358455115509481550778215813586122858153579186424029047\n", "99\n274084708428239737964144281827339813543219110156398212401158259206614326520025226572837805871014585\n", "65\n48741672913800855829009396895109319701475498378204701259174825079\n", "54\n779678408554409873811691913824373072271022281181199372\n", "100\n2956058251342921002154580504550305512343357719751238174127440647858171411479019640719389442193156761\n", "75\n1447209574891881128506764534477602010865884193215132888674271629390187643471\n", "21\n144372480849939667628\n", "62\n22219613982136747210935631389171649693997034283345662337583626\n", "30\n1753916125842151020270252344941\n", "64\n11582262715289018472878260813237715750398740538192284144993914364\n", "50\n176486247346285355078927403393181612062909344472557\n", "20\n91475329980766165627\n", "32\n19421253273631271902830546309853\n", "82\n7130439677311429054289691926669678715559951971255528089422170252214949673055037409\n", "87\n162583935074903283877678799324942261343776405281956667200663049919992379727457618445822\n", "85\n5179672314445498518747825535464653999958180121132851369872452192607293658801721323112\n", "100\n9056860173107534527953825197265296206177542053400053495648579654157105028804543604477636859834254169\n", "1\n1\n", "93\n142900738143682625540105342312253998971541513968430294618654527208656244186427714456429260061\n", "40\n5893664850088420104653125672989780401302\n", "33\n1316344704121056356767252590078035\n", "21\n961247912193573032091\n", "98\n49633593424238946228753574785033663393046515774919065229285836778263762289889151310882662050295958\n", "90\n730563418212452051964132091144698723276121264664193850618023916261543013128815335399938850\n", "22\n7062633451897974105718\n", "96\n961606338203745446796386398079921610824760993214546398685366784604568762326307249029204455750851\n", "1\n2\n", "100\n7175584485805705849693168885514278862585249734475140923711025638113565719364706001732933879282593903\n", "86\n89039327901659721416677561947986258951074654231236865933796800700895217312937370088565\n", "92\n13903087491287793799250985459288313710990837230413759979322281000113896197749900430556616452\n", "76\n5668848880083489060516181669185910162345821775435654230881288559909881276359\n", "32\n58450846655060080321140700557862\n", "70\n16574756577915966791279923539175441020736780209276978053521928356127012\n", "11\n113055057882\n", "21\n268581310685218650707\n", "22\n17634833004338166206452\n", "11\n145852211224\n", "41\n156430801927200855536123837894662214568721\n", "63\n573970989884638574001047539444219592287349724845896428516061930\n", "100\n1649954454354216348324856353744769591239957512599507743765021441866612320593824942841904141584444809\n", "100\n10073026040057460848727605087211482331696312132261702754626166388448133087167204984955299978572844873\n", "53\n10294950976088816073199215671673167174963164469332544\n", "60\n903744304501293516369258888423725616678289531242891710261181\n", "84\n248058851050244586329972244431845068342053230180314142152399592177294389690811412469\n", "43\n1139522786373859748629536978350302283047435\n", "21\n414764769360229758359\n", "50\n125006241747367172352961887620449940392294290156400\n", "33\n163445991198719783945688442744574\n", "27\n1771475345807520480504293951\n", "74\n36141517601805443470215839078489508863753596872271855476653668390338703335\n", "22\n6162495896368099518135\n", "81\n1363025613301211201344873793522274412138701392236333959084281266030086492586969946\n", "57\n1423705310783370356206488007848026002555725247788497695627\n", "100\n8214196852752695233729514144265209784838859240743133895909669295408086624114628470690490149346858149\n", "11\n125693053523\n", "21\n308846580116646657569\n", "94\n7747830900414725615555168784062745495617871594159096430181393382508562672892413314594899237874\n", "52\n15654026030811325908652336362901586634418944356707873\n", "61\n3124080573365283337934382711688970811847579177395736805511317\n", "95\n41233047758106206206178493651979098498928879946838810418979522774647327191027440365238678414753\n", "73\n4184646398440799539343302069138501059187195143871098078245424570574650630\n", "80\n70052317105276311821557953815064235609254227147552660921877560719279678214601763\n", "55\n2532584617276433831959785690851391005271119317728379073\n", "100\n12214470388509637187316171407185732399094381485438987303313809772379863936872280956215437122989955784\n", "11\n50641445791\n", "51\n1645695007619178112182600011052173832799865107349261\n", "55\n8052132475340067086462704381340546682468514641256540302\n", "65\n80507303857224037529289924361631148371584546228214411186937338609\n", "42\n1400161523759972055334925227721345988082774\n", "75\n381633323259241978825160604051651800305930639598198353611274713769732694803\n", "11\n85999264342\n", "21\n158411602392309813153\n", "77\n11111111111111111111111111110111111111111111111111111111111111110111111111111\n"], "outputs": ["2\n", "1\n", "0\n", "4\n", "0\n", "6\n", "5\n", "4\n", "1\n", "9\n", "3\n", "6\n", "1\n", "2\n", "1\n", "5\n", "0\n", "2\n", "5\n", "0\n", "8\n", "2\n", "4\n", "1\n", "2\n", "7\n", "8\n", "7\n", "7\n", "9\n", "1\n", "0\n", "8\n", "0\n", "3\n", "3\n", "1\n", "8\n", "8\n", "0\n", "0\n", "8\n", "0\n", "9\n", "1\n", "7\n", "8\n", "6\n", "2\n", "6\n", "1\n", "1\n", "0\n", "2\n", "1\n", "3\n", "0\n", "9\n", "5\n", "2\n", "5\n", "9\n", "1\n", "9\n", "4\n", "5\n", "9\n", "0\n", "7\n", "2\n", "9\n", "3\n", "1\n", "0\n", "0\n", "1\n", "0\n", "2\n", "3\n", "2\n", "0\n", "6\n", "2\n", "7\n", "5\n", "9\n", "7\n", "1\n", "1\n", "8\n", "4\n", "5\n", "6\n", "8\n", "6\n", "7\n", "5\n", "9\n", "4\n", "5\n", "6\n", "3\n", "1\n", "2\n", "0\n", "7\n", "8\n", "9\n", "5\n", "4\n", "6\n", "6\n", "1\n", "4\n", "1\n", "5\n", "4\n", "1\n", "2\n", "4\n", "7\n", "7\n", "7\n", "0\n", "7\n", "3\n", "1\n", "0\n", "8\n", "8\n", "2\n", "8\n", "0\n", "9\n", "7\n", "8\n", "6\n", "2\n", "3\n", "1\n", "1\n", "2\n", "1\n", "3\n", "5\n", "7\n", "9\n", "3\n", "5\n", "7\n", "3\n", "1\n", "2\n", "3\n", "2\n", "6\n", "2\n", "6\n", "5\n", "9\n", "0\n", "1\n", "8\n", "4\n", "5\n", "8\n", "6\n", "4\n", "5\n", "9\n", "0\n", "4\n", "5\n", "5\n", "3\n", "6\n", "1\n", "1\n", "0\n"]}
7
[ "PYTHON3" ]
2
2
code_contests
c43bbddcd6fcd849ac321f690995ea54
1081_G. Mergesort Strikes Back
Chouti thought about his very first days in competitive programming. When he had just learned to write merge sort, he thought that the merge sort is too slow, so he restricted the maximum depth of recursion and modified the merge sort to the following: <image> Chouti found his idea dumb since obviously, this "merge sort" sometimes cannot sort the array correctly. However, Chouti is now starting to think of how good this "merge sort" is. Particularly, Chouti wants to know for a random permutation a of 1, 2, …, n the expected number of inversions after calling MergeSort(a, 1, n, k). It can be proved that the expected number is rational. For the given prime q, suppose the answer can be denoted by u/d where gcd(u,d)=1, you need to output an integer r satisfying 0 ≀ r<q and rd ≑ u \pmod q. It can be proved that such r exists and is unique. Input The first and only line contains three integers n, k, q (1 ≀ n, k ≀ 10^5, 10^8 ≀ q ≀ 10^9, q is a prime). Output The first and only line contains an integer r. Examples Input 3 1 998244353 Output 499122178 Input 3 2 998244353 Output 665496236 Input 9 3 998244353 Output 449209967 Input 9 4 998244353 Output 665496237 Note In the first example, all possible permutations are [1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]. With k=1, MergeSort(a, 1, n, k) will only return the original permutation. Thus the answer is 9/6=3/2, and you should output 499122178 because 499122178 Γ— 2 ≑ 3 \pmod {998244353}. In the second example, all possible permutations are [1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1] and the corresponding outputs of MergeSort(a, 1, n, k) are [1,2,3],[1,2,3],[2,1,3],[1,2,3],[2,3,1],[1,3,2] respectively. Thus the answer is 4/6=2/3, and you should output 665496236 because 665496236 Γ— 3 ≑ 2 \pmod {998244353}.
{"inputs": ["3 2 998244353\n", "9 3 998244353\n", "3 1 998244353\n", "9 4 998244353\n", "53812 4 967428361\n", "7 2 400166453\n", "75727 16 485722667\n", "65536 10 802338989\n", "65535 12 196344479\n", "5000 4 961162523\n", "13694 5 579788161\n", "99999 14 746231791\n", "14823 8 622667251\n", "65536 1 262776883\n", "65535 4 585040979\n", "1 2 932173633\n", "65535 13 543456539\n", "56907 7 653135281\n", "65535 16 589256509\n", "79602 9 341282581\n", "65535 15 148502831\n", "91299 13 883710911\n", "65536 7 999999937\n", "65535 3 200770211\n", "4558 9 768001957\n", "78790 14 947580449\n", "11045 4 779484089\n", "65536 7 474924587\n", "100000 1 327496733\n", "7 4 674998729\n", "93705 8 728681249\n", "65535 7 775068599\n", "93014 3 464769397\n", "65536 9 512750233\n", "65536 8 624488609\n", "2 2 105534269\n", "4 2 717931793\n", "29670 1 798626077\n", "1 100000 355399153\n", "4866 5 828460181\n", "5000 3 947484677\n", "4862 11 340369703\n", "67260 11 159230609\n", "96560 6 621206447\n", "6 4 142235399\n", "319 6 736338271\n", "99999 4 721319531\n", "5000 5000 824957897\n", "95449 16 477786341\n", "65536 4 530056207\n", "5 2 488196377\n", "99999 10 201673531\n", "8 2 401001541\n", "65536 2 547031129\n", "65535 6 100000007\n", "87440 14 373345151\n", "99999 5 950991961\n", "65535 10 764125471\n", "39062 3 557718113\n", "100000 4 866430809\n", "99999 7 612486629\n", "65610 7 576223171\n", "3 3 537728333\n", "79173 7 329778431\n", "19679 2 978579983\n", "65535 1 969378797\n", "8 4 617453693\n", "99999 2 594212063\n", "99999 3 538530137\n", "99999 15 385602223\n", "65535 2 332622313\n", "31581 2 803297119\n", "65536 16 307380313\n", "5 4 294228373\n", "12657 1 328355033\n", "4 3 691608353\n", "65536 17 355422121\n", "2 3 738541207\n", "68102 2 409693891\n", "65535 14 379941571\n", "65536 12 883299773\n", "59614 14 431666281\n", "99999 11 739822453\n", "20621 4 420701179\n", "65536 14 292184353\n", "23880 14 515153497\n", "99999 8 616151843\n", "33727 15 177545087\n", "8 3 930233189\n", "65536 6 526215803\n", "9292 12 386116849\n", "3 2 457143689\n", "5 3 698057369\n", "64554 13 711786883\n", "99999 18 278747437\n", "6 3 706327789\n", "6 2 126580711\n", "100000 3 372547751\n", "99999 17 222262553\n", "7 3 957060541\n", "99999 6 769267349\n", "58791 1 627994511\n", "92275 9 505206379\n", "65535 9 939195329\n", "65535 8 629794369\n", "65536 11 506680939\n", "99999 1 501051697\n", "5000 2 444286949\n", "99999 12 608975467\n", "99999 16 424240459\n", "65535 5 492219967\n", "9569 7 974022443\n", "100000 2 330782867\n", "65536 5 347538067\n", "99999 9 543989543\n", "93976 8 747153793\n", "42288 6 367611719\n", "100000 100000 658399519\n", "65536 3 759400619\n", "65536 13 543490043\n", "99999 13 838056061\n", "65535 6 563701807\n", "65535 17 131827369\n", "1 1 807831149\n", "65536 15 568071787\n", "65535 11 390043253\n", "58370 15 756534617\n", "74973 12 872697443\n", "53812 5 967428361\n", "12 2 400166453\n", "27203 10 802338989\n", "59715 12 196344479\n", "14823 11 622667251\n", "80668 1 262776883\n", "1 4 932173633\n", "8041 13 543456539\n", "89551 7 653135281\n", "65535 13 589256509\n", "65535 9 148502831\n", "76586 13 883710911\n", "65535 6 200770211\n", "58162 7 775068599\n", "93014 2 464769397\n", "65536 6 512750233\n", "5000 2 947484677\n", "4862 4 340369703\n", "478 6 736338271\n", "95449 8 477786341\n", "65536 4 427104367\n", "7 2 488196377\n", "40929 10 201673531\n", "4 2 401001541\n", "65536 2 937051711\n", "99999 10 950991961\n", "55933 10 764125471\n", "39062 5 557718113\n", "7205 7 576223171\n", "3 1 537728333\n", "79173 13 329778431\n", "65535 2 969378797\n", "12657 2 328355033\n", "5 3 691608353\n", "68102 4 409693891\n", "98757 14 379941571\n", "20621 1 420701179\n", "99999 13 616151843\n", "33727 10 177545087\n", "6 2 457143689\n", "99999 2 278747437\n", "7 2 126580711\n", "31157 1 627994511\n", "21025 9 939195329\n", "65535 11 629794369\n", "99999 4 608975467\n", "9569 9 974022443\n", "100000 2 356499727\n", "4558 15 768001957\n", "8 4 674998729\n", "2 2 196326497\n", "2 100000 355399153\n", "67260 20 159230609\n", "8 7 617453693\n", "65536 28 307380313\n", "5 8 294228373\n", "2888 17 355422121\n", "23880 25 515153497\n", "8 6 930233189\n", "9292 16 386116849\n"], "outputs": ["665496236\n", "449209967\n", "499122178\n", "665496237\n", "950881274\n", "37158321\n", "166058860\n", "462855383\n", "7405077\n", "935148925\n", "20837734\n", "534083991\n", "282687828\n", "22617908\n", "73478343\n", "0\n", "170536956\n", "367828981\n", "362272581\n", "15283453\n", "46429722\n", "238048909\n", "195101941\n", "26568059\n", "338635790\n", "804769289\n", "766560946\n", "244871950\n", "207497869\n", "0\n", "90464274\n", "580904942\n", "3096497\n", "56371267\n", "456424095\n", "0\n", "59827651\n", "619382846\n", "0\n", "236115936\n", "453430334\n", "187513462\n", "38214063\n", "336730170\n", "0\n", "133698563\n", "482453887\n", "0\n", "181225428\n", "175616225\n", "455649955\n", "6497465\n", "108365903\n", "68232417\n", "19616415\n", "58174995\n", "236965854\n", "44493100\n", "311741364\n", "315155497\n", "160702769\n", "475692890\n", "0\n", "112881569\n", "166411803\n", "589003274\n", "0\n", "241186421\n", "420705596\n", "286320285\n", "23332505\n", "335334542\n", "210721421\n", "0\n", "40046748\n", "0\n", "0\n", "0\n", "248567049\n", "364848655\n", "385022293\n", "382826545\n", "286705678\n", "289746143\n", "211044160\n", "28372663\n", "506564910\n", "137396822\n", "465116600\n", "158448501\n", "339357599\n", "304762460\n", "1\n", "501856006\n", "0\n", "529745844\n", "61180682\n", "341122978\n", "24806593\n", "239265139\n", "537638613\n", "550083467\n", "372045131\n", "374972142\n", "563763277\n", "206613192\n", "245192364\n", "161627985\n", "317105066\n", "81192002\n", "1097877\n", "297115301\n", "20709968\n", "50947333\n", "330542468\n", "239386990\n", "235655808\n", "0\n", "725177449\n", "510005251\n", "772746099\n", "478190145\n", "0\n", "0\n", "2593916\n", "2137720\n", "174119749\n", "741474461\n", "917661730", "283075928", "609490011", "177057827", "371585348", "50150091", "0", "4639320", "376344920", "39302203", "112736555", "796832946", "172311008", "105621524", "253519494", "440659059", "580574907", "88006673", "215597521", "350368233", "26721086", "407992694", "119000082", "167083977", "867192219", "241380517", "116443791", "516123427", "372129053", "268864168", "58492360", "469948571", "81278217", "1", "357288965", "34664831", "106301255", "245015784", "173904684", "236190911", "132612778", "35261777", "242681873", "714422268", "438097614", "46413838", "224951190", "153235142", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"]}
13
[ "PYTHON3" ]
2
2
code_contests
63c58103babdabf55a2b6db2cd0ed35e
1101_A. Minimum Integer
You are given q queries in the following form: Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i]. Can you answer all the queries? Recall that a number x belongs to segment [l, r] if l ≀ x ≀ r. Input The first line contains one integer q (1 ≀ q ≀ 500) β€” the number of queries. Then q lines follow, each containing a query given in the format l_i r_i d_i (1 ≀ l_i ≀ r_i ≀ 10^9, 1 ≀ d_i ≀ 10^9). l_i, r_i and d_i are integers. Output For each query print one integer: the answer to this query. Example Input 5 2 4 2 5 10 4 3 10 1 1 2 3 4 6 5 Output 6 4 1 3 10
{"inputs": ["5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n", "20\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n", "1\n78 79 79\n", "1\n6 6 6\n", "20\n1 1 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n", "1\n78 1000 1\n", "1\n77 10000 1\n", "20\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n", "10\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n", "1\n78 80 1\n", "20\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n", "1\n1 1 123456789\n", "1\n80 100 1\n", "5\n1000000000 1000000000 1\n1000000000 1000000000 1\n1000000000 1000000000 1\n1000000000 1000000000 1\n1000000000 1000000000 1\n", "1\n78 10000 1\n", "1\n79 80 100\n", "5\n1 1000000000 1\n1 999999999 1\n1 999999998 1\n1 999999997 1\n1 999999996 1\n", "5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n", "30\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n", "1\n78 89 34\n", "1\n1 1 1\n", "1\n1 3 2\n", "10\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n", "4\n1 999999999 1\n1 999999998 1\n1 999999997 1\n1 999999996 1\n", "5\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n", "2\n1 1 2\n1 1 2\n", "1\n80 100 80\n", "25\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n", "30\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n", "16\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n", "1\n1 1000000000 6\n", "1\n5 5 5\n", "1\n2 5 6\n", "8\n1 999999998 1\n1 999999997 1\n1 999999996 1\n1 999999995 1\n1 999999994 1\n1 999999993 1\n1 999999992 1\n1 999999991 1\n", "5\n80 100 10\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n", "1\n1 1000000000 1017\n", "1\n1 1000000000 2\n", "1\n78 1 79\n", "1\n2 6 6\n", "20\n1 1 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 832136582 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n", "1\n78 1100 1\n", "1\n77 10000 2\n", "20\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000100000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n", "10\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000010 1\n1 1000000000 1\n", "20\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000010 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n", "1\n0 1 123456789\n", "5\n1000000000 1000000000 1\n1000000000 1000000000 1\n1000000000 1100000000 1\n1000000000 1000000000 1\n1000000000 1000000000 1\n", "1\n79 144 100\n", "5\n1 1000000000 1\n1 999999999 1\n1 999999998 1\n2 999999997 1\n1 999999996 1\n", "5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 4 5\n", "30\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 749549584 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n", "1\n69 89 34\n", "1\n0 3 2\n", "4\n1 999999999 1\n1 999999998 2\n1 999999997 1\n1 999999996 1\n", "5\n1 1000000000 1\n2 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n", "2\n1 1 4\n1 1 2\n", "1\n80 000 80\n", "25\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 639799271 1000000000\n5 6 5\n", "30\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 2\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n", "16\n1 1000000000 1\n1 1000000000 1\n1 1000100000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n", "1\n1 1000010000 2\n", "1\n5 5 6\n", "8\n1 999999998 1\n1 999999997 1\n1 999999996 1\n1 999999995 1\n1 999999994 1\n1 999999993 1\n1 999999992 2\n1 999999991 1\n", "5\n80 101 10\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n", "1\n1 1000000010 1017\n", "1\n1 1000000000 4\n", "5\n2 4 2\n5 10 4\n3 10 1\n2 2 3\n4 6 5\n", "1\n78 1 125\n", "20\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n2 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000100000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n", "1\n79 263 100\n", "5\n1 1100000000 1\n1 999999999 1\n1 999999998 1\n2 999999997 1\n1 999999996 1\n", "5\n2 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 4 5\n", "1\n69 89 56\n", "4\n1 474817329 1\n1 999999998 2\n1 999999997 1\n1 999999996 1\n", "1\n80 000 109\n", "25\n1 1000000000 1\n1 0000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 639799271 1000000000\n5 6 5\n", "16\n2 1000000000 1\n1 1000000000 1\n1 1000100000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n", "1\n5 5 8\n", "8\n1 999999998 1\n1 999999997 1\n1 402421533 1\n1 999999995 1\n1 999999994 1\n1 999999993 1\n1 999999992 2\n1 999999991 1\n", "1\n1 1000000010 1391\n", "1\n1 1000001000 4\n", "1\n0 2 227752323\n", "1\n79 306 100\n", "5\n2 1100000000 1\n1 999999999 1\n1 999999998 1\n2 999999997 1\n1 999999996 1\n", "30\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 1467985723 2\n1 999999999 2\n1 749549584 2\n2 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n", "1\n6 89 56\n", "1\n1 2 3\n", "4\n1 474817329 1\n1 999999998 2\n1 999999997 1\n2 999999996 1\n", "16\n2 1000000000 1\n1 1000000000 1\n1 1000100000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1001000000 1\n1 1000000000 1\n", "5\n62 101 10\n5 10 4\n1 10 1\n1 2 3\n4 6 5\n", "1\n1 1000000000 3\n", "5\n1100000000 1000000000 1\n1000000000 1000000000 1\n1000000000 1100000000 2\n1000000000 1000000001 1\n1000000000 1000000000 1\n", "1\n110 306 100\n", "5\n1 1100000000 1\n1 999999999 1\n1 999999998 1\n2 999999997 1\n1 440567035 1\n", "5\n2 1000000000 1\n1 1000000000 1001000000\n2 1000000000 1\n2 999999999 1000000000\n5 4 5\n", "4\n1 474817329 1\n1 999999998 1\n1 999999997 1\n2 999999996 1\n", "1\n4 4 7\n", "5\n62 101 10\n5 10 4\n1 10 2\n1 2 3\n4 6 5\n", "1\n0 1000000010 2440\n", "1\n1 1000000000 1\n", "1\n2 6 11\n", "1\n78 119 1\n", "1\n80 100 2\n", "1\n145 10000 1\n", "1\n1 1 2\n", "1\n2 4 6\n", "1\n2 10 6\n", "20\n1 1 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 2\n1 999999999 1\n1 999999999 1\n1 832136582 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n", "1\n142 1100 1\n", "1\n60 10000 2\n", "1\n78 92 1\n", "20\n1 1000000000 3\n1 1000000000 3\n1 1000000000 6\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000010 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n", "1\n0 2 123456789\n", "1\n67 100 2\n", "5\n1100000000 1000000000 1\n1000000000 1000000000 1\n1000000000 1100000000 1\n1000000000 1000000000 1\n1000000000 1000000000 1\n", "1\n145 10001 1\n", "30\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 749549584 2\n2 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n", "1\n1 0 2\n", "1\n1 3 3\n", "1\n2 1000010000 2\n", "1\n2 3 6\n", "5\n62 101 10\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n", "1\n2 10 4\n", "1\n142 1100 2\n", "1\n60 10001 2\n", "1\n78 132 1\n", "20\n1 1000000000 3\n1 1000000000 3\n1 1000000000 6\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000010 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n2 1000000000 3\n1 1000000000 3\n1 1000000000 3\n", "1\n67 100 4\n", "5\n1100000000 1000000000 1\n1000000000 1000000000 1\n1000000000 1100000000 1\n1000000000 1000000001 1\n1000000000 1000000000 1\n", "1\n181 10001 1\n", "5\n2 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n2 999999999 1000000000\n5 4 5\n", "1\n0 0 2\n", "1\n80 100 109\n", "25\n1 1000000000 1\n1 0000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000010000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 639799271 1000000000\n5 6 5\n", "1\n5 4 8\n", "1\n4 4 6\n", "1\n0 1000000010 1391\n"], "outputs": ["6\n4\n1\n3\n10\n", "1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n", "158\n", "12\n", "2\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n", "1\n", "1\n", "1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n", "1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n", "1\n", "1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n", "123456789\n", "1\n", "1\n1\n1\n1\n1\n", "1\n", "100\n", "1000000001\n1000000000\n999999999\n999999998\n999999997\n", "1000000001\n2000000000\n1\n1000000000\n10\n", "1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n", "34\n", "2\n", "4\n", "999999999\n999999999\n999999999\n999999999\n999999999\n999999999\n999999999\n999999999\n999999999\n999999999\n", "1000000000\n999999999\n999999998\n999999997\n", "1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n", "2\n2\n", "160\n", "1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n", "1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n", "1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n", "1000000002\n", "10\n", "6\n", "999999999\n999999998\n999999997\n999999996\n999999995\n999999994\n999999993\n999999992\n", "10\n4\n1\n3\n10\n", "1000000845\n", "1000000002\n", "79\n", "12\n", "2\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n832136583\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n", "1\n", "2\n", "1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000100001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n", "1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000011\n1000000001\n", "1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000011\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n", "123456789\n", "1\n1\n1\n1\n1\n", "200\n", "1000000001\n1000000000\n999999999\n1\n999999997\n", "1000000001\n2000000000\n1\n1000000000\n5\n", "1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n749549586\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n", "34\n", "4\n", "1000000000\n1000000000\n999999998\n999999997\n", "1000000001\n1\n1000000001\n1000000001\n1000000001\n", "4\n2\n", "80\n", "1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n", "1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000002\n1000000001\n1000000001\n1000000001\n1000000001\n", "1000000001\n1000000001\n1000100001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n", "1000010002\n", "6\n", "999999999\n999999998\n999999997\n999999996\n999999995\n999999994\n999999994\n999999992\n", "10\n4\n1\n3\n10\n", "1000000845\n", "1000000004\n", "6\n4\n1\n3\n10\n", "125\n", "1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000100001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n", "300\n", "1100000001\n1000000000\n999999999\n1\n999999997\n", "1\n2000000000\n1\n1000000000\n5\n", "56\n", "474817330\n1000000000\n999999998\n999999997\n", "109\n", "1000000001\n1000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n", "1\n1000000001\n1000100001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n", "8\n", "999999999\n999999998\n402421534\n999999996\n999999995\n999999994\n999999994\n999999992\n", "1000001028\n", "1000001004\n", "227752323\n", "400\n", "1\n1000000000\n999999999\n1\n999999997\n", "1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1467985724\n1000000000\n749549586\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n", "112\n", "3\n", "474817330\n1000000000\n999999998\n1\n", "1\n1000000001\n1000100001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1001000001\n1000000001\n", "10\n4\n11\n3\n10\n", "1000000002\n", "1\n1\n2\n1\n1\n", "100\n", "1100000001\n1000000000\n999999999\n1\n440567036\n", "1\n1001000000\n1\n1000000000\n5\n", "474817330\n999999999\n999999998\n1\n", "7\n", "10\n4\n12\n3\n10\n", "1000002280\n", "1000000001\n", "11\n", "1\n", "2\n", "1\n", "2\n", "6\n", "12\n", "2\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n832136583\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n", "1\n", "2\n", "1\n", "1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000011\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n", "123456789\n", "2\n", "1\n1\n1\n1\n1\n", "1\n", "1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n749549586\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n", "2\n", "6\n", "1000010002\n", "6\n", "10\n4\n1\n3\n10\n", "12\n", "2\n", "2\n", "1\n", "1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000011\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n", "4\n", "1\n1\n1\n1\n1\n", "1\n", "1\n2000000000\n1\n1000000000\n5\n", "2\n", "109\n", "1000000001\n1000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n", "8\n", "6\n", "1000001028\n"]}
7
[ "PYTHON3" ]
2
2
code_contests
72ed9419c7424b29635b014c21d66344
1129_D. Isolation
Find the number of ways to divide an array a of n integers into any number of disjoint non-empty segments so that, in each segment, there exist at most k distinct integers that appear exactly once. Since the answer can be large, find it modulo 998 244 353. Input The first line contains two space-separated integers n and k (1 ≀ k ≀ n ≀ 10^5) β€” the number of elements in the array a and the restriction from the statement. The following line contains n space-separated integers a_1, a_2, …, a_n (1 ≀ a_i ≀ n) β€” elements of the array a. Output The first and only line contains the number of ways to divide an array a modulo 998 244 353. Examples Input 3 1 1 1 2 Output 3 Input 5 2 1 1 2 1 3 Output 14 Input 5 5 1 2 3 4 5 Output 16 Note In the first sample, the three possible divisions are as follows. * [[1], [1], [2]] * [[1, 1], [2]] * [[1, 1, 2]] Division [[1], [1, 2]] is not possible because two distinct integers appear exactly once in the second segment [1, 2].
{"inputs": ["5 5\n1 2 3 4 5\n", "3 1\n1 1 2\n", "5 2\n1 1 2 1 3\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 16 3 13 17 48 8 31 32 6 31 31 49 9 40 9 21 23 41 17 31 45 47 17 1 12 15 50 40 38 4 20 1 9 37 4 47 4 24\n", "100 30\n31 57 26 94 41 92 88 4 46 51 64 45 89 59 91 49 3 28 17 63 9 74 77 60 83 30 73 64 90 47 34 80 94 89 66 31 19 84 86 83 62 59 96 67 93 58 7 86 11 34 35 15 53 59 71 16 98 4 73 70 23 53 33 95 40 45 90 51 2 20 7 73 38 67 89 90 39 8 66 76 4 57 50 80 81 96 10 46 16 45 84 3 3 3 97 9 94 61 86 63\n", "10 1\n4 2 9 2 1 4 4 1 4 10\n", "100 10\n59 95 5 20 91 78 30 76 32 82 3 84 38 92 19 65 79 39 7 81 49 98 29 4 28 71 67 55 99 65 53 58 31 61 4 59 5 55 33 41 81 55 58 23 95 98 60 62 54 94 47 33 20 67 31 67 34 26 47 96 96 64 31 21 49 58 82 15 73 15 42 94 100 8 50 31 77 37 68 65 83 54 28 92 68 24 16 12 55 34 28 16 68 76 1 96 52 70 91 90\n", "1 1\n1\n", "100 1\n7 75 3 62 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 48 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 95 78 10 69\n", "2 2\n2 1\n", "2 1\n2 2\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 18 3 13 17 48 8 31 32 6 31 31 49 9 40 9 21 23 41 17 31 45 47 17 1 12 15 50 40 38 4 20 1 9 37 4 47 4 24\n", "100 30\n31 57 41 94 41 92 88 4 46 51 64 45 89 59 91 49 3 28 17 63 9 74 77 60 83 30 73 64 90 47 34 80 94 89 66 31 19 84 86 83 62 59 96 67 93 58 7 86 11 34 35 15 53 59 71 16 98 4 73 70 23 53 33 95 40 45 90 51 2 20 7 73 38 67 89 90 39 8 66 76 4 57 50 80 81 96 10 46 16 45 84 3 3 3 97 9 94 61 86 63\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 48 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 95 78 10 69\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 18 3 13 17 48 8 31 32 6 31 31 49 9 40 18 21 23 41 17 31 45 47 17 1 12 15 50 40 38 4 20 1 9 37 4 47 4 24\n", "100 30\n31 57 26 94 41 92 88 4 46 51 64 45 89 59 91 49 3 28 17 63 9 74 77 60 83 30 73 64 90 47 34 80 94 89 66 31 19 84 86 83 62 59 96 66 93 58 7 86 11 34 35 15 53 59 71 16 98 4 73 70 23 53 33 95 40 45 90 51 2 20 7 73 38 67 89 90 39 8 66 76 4 57 50 80 81 96 10 46 16 45 84 3 3 3 97 9 94 61 86 63\n", "10 1\n4 2 9 2 2 4 4 1 4 10\n", "100 10\n59 95 5 20 91 78 30 76 32 82 3 84 38 92 19 65 79 39 7 81 49 98 29 4 28 71 67 55 99 65 53 58 31 61 4 59 5 55 33 41 81 55 58 23 95 98 60 62 54 94 47 33 20 67 31 67 34 26 47 96 96 64 31 21 49 58 82 2 73 15 42 94 100 8 50 31 77 37 68 65 83 54 28 92 68 24 16 12 55 34 28 16 68 76 1 96 52 70 91 90\n", "2 2\n2 2\n", "5 2\n2 1 2 1 3\n", "100 30\n31 57 26 94 41 92 88 4 46 51 64 45 89 59 91 49 3 28 17 63 9 74 77 60 83 30 73 64 90 47 34 80 94 89 66 31 19 84 86 83 62 59 96 66 93 58 7 86 11 34 35 15 53 59 71 16 98 4 73 70 23 53 33 95 40 45 90 51 2 20 7 73 38 67 89 90 39 8 66 76 4 57 50 80 81 96 10 46 16 45 84 3 3 3 97 9 94 98 86 63\n", "10 1\n4 2 9 2 2 4 4 1 3 10\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 18 3 13 17 48 8 47 32 6 31 31 49 9 40 18 21 23 41 17 30 45 47 17 1 12 15 50 40 38 4 20 1 9 37 3 47 4 24\n", "100 30\n31 57 26 94 41 92 88 4 46 51 64 45 89 59 91 49 3 28 17 63 9 74 77 60 83 30 73 64 90 47 34 80 94 89 66 31 19 84 86 83 62 59 96 66 93 58 7 86 11 34 35 15 53 59 71 16 98 4 73 70 23 53 33 95 40 45 90 51 2 20 7 73 38 67 89 90 39 8 66 76 4 57 50 80 81 96 10 46 16 1 84 3 3 3 97 9 94 98 86 63\n", "10 1\n4 2 9 2 2 7 4 1 4 10\n", "100 10\n59 95 5 20 91 78 31 76 32 82 3 84 38 92 19 65 79 39 7 81 49 98 29 4 28 71 67 55 99 65 53 58 7 61 4 59 5 55 5 41 81 55 58 23 95 98 60 62 54 94 47 33 20 67 31 67 34 26 47 96 96 64 31 21 49 58 82 2 73 15 42 94 100 8 50 29 77 37 68 65 83 54 28 92 68 24 16 12 55 34 28 16 68 76 1 96 52 70 91 90\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 95 78 10 69\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 18 3 13 17 48 8 31 32 6 31 31 49 9 40 18 21 23 41 17 30 45 47 17 1 12 15 50 40 38 4 20 1 9 37 4 47 4 24\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 56 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 95 78 10 69\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 56 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 40 88 4 66 30 47 92 88 51 20 33 25 50 95 78 10 69\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 16 3 13 17 48 8 31 32 6 31 31 49 9 40 9 21 25 41 17 31 45 47 17 1 12 15 50 40 38 4 20 1 9 37 4 47 4 24\n", "100 1\n7 75 6 62 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 48 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 95 78 10 69\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 48 56 54 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 95 78 10 69\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 18 3 13 17 48 8 31 32 6 31 31 49 9 40 18 21 23 41 17 31 45 47 17 1 12 15 50 40 38 4 20 1 9 35 4 47 4 24\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 12 50 95 78 10 69\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 18 3 13 17 48 8 47 32 6 31 31 49 9 40 18 21 23 41 17 30 45 47 17 1 12 15 50 40 38 4 20 1 9 37 4 47 4 24\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 56 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 7 33 25 50 95 78 10 69\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 16 3 13 17 48 8 31 32 6 31 31 49 9 40 9 21 25 41 17 31 45 47 33 1 12 15 50 40 38 4 20 1 9 37 4 47 4 24\n", "100 10\n59 95 5 20 91 78 31 76 32 82 3 84 38 92 19 65 79 39 7 81 49 98 29 4 28 71 67 55 99 65 53 58 31 61 4 59 5 55 33 41 81 55 58 23 95 98 60 62 54 94 47 33 20 67 31 67 34 26 47 96 96 64 31 21 49 58 82 2 73 15 42 94 100 8 50 31 77 37 68 65 83 54 28 92 68 24 16 12 55 34 28 16 68 76 1 96 52 70 91 90\n", "100 1\n7 75 6 62 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 41 30 48 64 10 61 8 60 74 26 100 48 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 95 78 10 69\n", "5 2\n2 1 1 1 3\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 48 56 54 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 50 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 95 78 10 69\n", "50 1\n50 8 46 9 12 38 41 18 49 10 23 15 1 3 13 17 48 8 31 32 6 31 31 49 9 40 18 21 23 41 17 31 45 47 17 1 12 15 50 40 38 4 20 1 9 35 4 47 4 24\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 1 66 30 47 92 88 51 20 33 12 50 95 78 10 69\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 56 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 5 33 25 50 95 78 10 69\n", "50 1\n50 8 46 9 13 38 41 18 49 10 23 15 16 3 13 17 48 8 31 32 6 31 31 49 9 40 9 21 25 41 17 31 45 47 33 1 12 15 50 40 38 4 20 1 9 37 4 47 4 24\n", "100 10\n59 95 5 20 91 78 31 76 32 82 3 84 38 92 19 65 79 39 7 81 49 98 29 4 28 71 67 55 99 65 53 58 7 61 4 59 5 55 33 41 81 55 58 23 95 98 60 62 54 94 47 33 20 67 31 67 34 26 47 96 96 64 31 21 49 58 82 2 73 15 42 94 100 8 50 31 77 37 68 65 83 54 28 92 68 24 16 12 55 34 28 16 68 76 1 96 52 70 91 90\n", "100 1\n7 75 6 62 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 41 30 48 64 10 61 8 60 74 13 100 48 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 95 78 10 69\n", "2 2\n2 1 1 1 3\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 46 56 54 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 50 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 95 78 10 69\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 1 66 30 47 92 88 51 20 33 12 98 95 78 10 69\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 67 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 56 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 5 33 25 50 95 78 10 69\n", "50 1\n50 8 46 9 13 38 41 18 49 10 23 15 16 3 13 17 48 8 31 32 6 31 31 49 9 40 9 21 25 41 17 31 45 47 33 1 12 15 50 40 38 4 20 1 9 37 4 47 1 24\n", "100 30\n31 57 10 94 41 92 88 4 46 51 64 45 89 59 91 49 3 28 17 63 9 74 77 60 83 30 73 64 90 47 34 80 94 89 66 31 19 84 86 83 62 59 96 66 93 58 7 86 11 34 35 15 53 59 71 16 98 4 73 70 23 53 33 95 40 45 90 51 2 20 7 73 38 67 89 90 39 8 66 76 4 57 50 80 81 96 10 46 16 1 84 3 3 3 97 9 94 98 86 63\n", "10 1\n4 2 9 2 4 7 4 1 4 10\n", "100 10\n59 95 5 20 91 78 31 76 32 82 3 84 38 92 19 65 79 39 7 81 49 98 29 4 28 71 67 55 99 65 53 58 7 61 4 59 5 55 33 41 81 55 58 23 95 98 60 62 54 94 47 33 20 67 31 67 34 26 47 96 96 64 31 21 49 58 82 2 73 15 42 94 100 8 50 29 77 37 68 65 83 54 28 92 68 24 16 12 55 34 28 16 68 76 1 96 52 70 91 90\n", "100 1\n7 75 6 62 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 41 30 48 64 10 61 8 60 74 13 100 48 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 47 78 10 69\n", "2 2\n2 1 1 1 0\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 88 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 1 66 30 47 92 88 51 20 33 12 98 95 78 10 69\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 67 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 56 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 69 88 4 66 30 47 92 88 51 5 33 25 50 95 78 10 69\n", "100 1\n7 75 6 62 10 31 43 96 32 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 41 30 48 64 10 61 8 60 74 13 100 48 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 4 66 30 47 92 88 51 20 33 25 50 47 78 10 69\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 56 98 85 76 5 25 98 73 78 55 4 44 53 10 8 12 10 78 25 58 88 19 45 67 86 72 90 93 78 77 36 20 69 8 73 88 1 66 30 47 92 88 91 20 33 12 98 95 78 10 69\n", "100 1\n7 75 3 82 10 31 43 96 31 62 13 76 93 85 38 96 72 69 67 44 88 53 35 21 67 18 34 2 60 14 23 56 95 69 86 51 37 82 30 48 64 10 61 8 60 74 26 100 9 67 98 85 76 5 25 98 73 78 55 4 44 7 10 8 12 10 56 25 58 47 19 45 67 86 72 90 93 78 77 36 20 69 8 69 88 4 66 30 47 92 88 51 5 33 25 50 95 78 10 69\n", "100 10\n59 95 5 20 91 78 31 76 32 82 3 84 38 92 19 65 79 39 7 81 49 98 29 4 28 71 67 55 99 65 53 58 7 61 4 59 5 55 5 41 81 55 58 23 95 98 60 80 54 94 47 33 20 67 31 67 34 26 47 96 96 64 31 21 49 58 82 2 73 15 42 94 100 8 50 29 77 37 68 65 83 54 28 92 68 24 16 12 55 34 28 16 68 76 1 96 52 70 91 90\n"], "outputs": ["16", "3", "14", "16", "726975503", "24", "244208148", "1", "1", "2", "2", "16\n", "873835092\n", "1\n", "8\n", "853187053\n", "37\n", "105389903\n", "2\n", "14\n", "564452064\n", "24\n", "4\n", "834061098\n", "12\n", "955855650\n", "1\n", "8\n", "1\n", "1\n", "16\n", "1\n", "1\n", "8\n", "1\n", "8\n", "1\n", "16\n", "105389903\n", "1\n", "16\n", "1\n", "8\n", "1\n", "1\n", "16\n", "105389903\n", "1\n", "2\n", "1\n", "1\n", "1\n", "8\n", "834061098\n", "8\n", "105389903\n", "1\n", "2\n", "1\n", "2\n", "1\n", "1\n", "2\n", "955855650\n"]}
10
[ "PYTHON3" ]
2
2
code_contests
0b569eed1e206cbe60dc42bf3517403b
1149_E. Election Promises
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes. There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles β€” it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax. Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles. The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves? Input The first line of the input contains two integers n, m (1 ≀ n ≀ 200 000, 0 ≀ m ≀ 200 000) β€” the number of cities and roads in Byteland. The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≀ h_i ≀ 10^9); h_i denotes the amount of taxes paid in the i-th city. Each of the following m lines contains two integers (1 ≀ u, v ≀ n, u β‰  v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities. We can show that the conventions cannot be held indefinitely for any correct test case. Output If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≀ h'_i ≀ 2 β‹… 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 β‹… 10^{18} bourles. If the party cannot assure their victory, output LOSE in the first and only line of the output. Examples Input 4 2 2 1 1 5 1 2 3 4 Output WIN 1 5 1 5 Input 4 2 1 5 1 5 1 2 3 4 Output LOSE Input 3 3 314 159 265 1 2 1 3 3 2 Output WIN 0 0 0 Input 6 4 2 2 5 5 6 6 1 3 2 4 3 5 4 6 Output LOSE Note In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally. The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win. In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
{"inputs": ["6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n", "3 3\n314 159 265\n1 2\n1 3\n3 2\n", "4 2\n2 1 1 5\n1 2\n3 4\n", "4 2\n1 5 1 5\n1 2\n3 4\n", "2 1\n1000000000 1000000000\n2 1\n", "3 2\n123 345 567\n1 2\n3 2\n", "3 0\n4 1 4\n", "3 2\n1 0 1\n3 2\n2 1\n", "3 0\n1 2 3\n", "3 2\n1 1 1\n1 2\n2 3\n", "2 0\n1000000000 1000000000\n", "2 0\n123456789 987654321\n", "3 2\n123 345 123\n1 2\n3 2\n", "1 0\n271828182\n", "2 1\n1000000000 1000000000\n1 2\n", "6 3\n678678678 395063145 789789 2 3 4\n4 1\n5 2\n6 3\n", "3 2\n2 3 4\n1 2\n1 3\n", "1 0\n0\n", "3 2\n123 87 567\n1 2\n3 2\n", "3 0\n4 1 8\n", "3 2\n1 0 2\n3 2\n2 1\n", "2 0\n1000000000 1100000000\n", "2 0\n123456789 1174603023\n", "1 0\n137880027\n", "2 1\n1000000000 1010000000\n1 2\n", "6 4\n2 2 5 5 9 6\n1 3\n2 4\n3 5\n4 6\n", "3 0\n4 2 8\n", "3 2\n1 1 2\n3 2\n2 1\n", "3 2\n2 0 2\n3 2\n2 1\n", "2 0\n1000010000 1100100000\n", "2 0\n1000000100 1010000000\n1 2\n", "2 0\n1100000100 1010100010\n1 1\n", "3 0\n3 1 4\n", "3 0\n1 1 3\n", "6 3\n678678678 395063145 528292 2 3 4\n4 1\n5 2\n6 3\n", "6 4\n2 3 5 5 9 6\n1 3\n2 4\n3 5\n4 6\n", "3 0\n7 2 8\n", "2 0\n1000000000 0100100000\n", "2 0\n1000010001 1100100000\n", "2 0\n1000000110 1010000000\n1 2\n", "3 0\n1000000100 1010100000\n1 2\n", "3 2\n2 0 4\n3 1\n2 1\n", "3 0\n2 1 4\n", "2 0\n1000000000 1100100000\n", "2 0\n123456789 635671754\n", "2 1\n1000000100 1010000000\n1 2\n", "6 4\n2 2 9 5 9 6\n1 3\n2 4\n3 5\n4 6\n", "3 2\n2 0 3\n3 2\n2 1\n", "2 0\n1000000100 1010100000\n1 2\n", "3 2\n2 0 4\n3 2\n2 1\n", "2 0\n1000000100 1010100010\n1 2\n", "2 0\n1000000100 1010100010\n1 1\n", "2 0\n1101000100 1010100010\n1 1\n", "2 0\n1101010100 1010100010\n1 1\n", "2 0\n1101010100 1010100010\n2 1\n", "2 0\n1101010100 1010100010\n2 0\n", "2 1\n1000000000 1000000001\n2 1\n", "1 0\n1000000000 1000000000\n", "2 0\n123456789 406345671\n", "2 0\n0000000000 1100000000\n", "1 0\n47568404\n", "2 0\n1000000000 1010000000\n1 2\n", "1 0\n123456789 635671754\n", "2 0\n1100000110 1010100010\n1 1\n", "2 0\n1101000100 1010100010\n1 0\n", "2 0\n1101010100 1010100010\n1 0\n", "2 0\n1111010100 1010100010\n2 0\n", "2 0\n1 1 3\n"], "outputs": ["LOSE\n", "WIN\n0 0 0 \n", "WIN\n1 5 1 5 \n", "LOSE\n", "WIN\n0 0 \n", "WIN\n123 0 123 \n", "WIN\n4 0 4 \n", "LOSE\n", "LOSE\n", "WIN\n1 0 1 \n", "LOSE\n", "WIN\n123456789 123456789 \n", "WIN\n123 0 123 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n0 4 4 \n", "LOSE\n", "WIN\n123 0 123 \n", "WIN\n4 1 5 \n", "WIN\n1 0 1 \n", "WIN\n1000000000 1000000000 \n", "WIN\n123456789 123456789 \n", "WIN\n0 \n", "WIN\n0 0 \n", "WIN\n2 2 5 5 6 6 \n", "WIN\n4 2 6 \n", "WIN\n2 0 2 \n", "LOSE\n", "WIN\n1000010000 1000010000 \n", "WIN\n1000000100 1000000100 \n", "WIN\n1010100010 1010100010 \n", "WIN\n3 1 2 \n", "WIN\n1 1 0 \n", "WIN\n678678678 395063145 1073741823 2 3 1 \n", "WIN\n2 3 5 5 7 6 \n", "WIN\n7 2 5 \n", "WIN\n100100000 100100000 \n", "WIN\n1000010001 1000010001 \n", "WIN\n1000000110 1000000110 \n", "WIN\n1000000100 1000000101 1 \n", "WIN\n0 0 0 \n", "WIN\n2 1 3 \n", "WIN\n1000000000 1000000000 \n", "WIN\n123456789 123456789 \n", "WIN\n0 0 \n", "WIN\n2 2 5 5 6 6 \n", "WIN\n2 0 2 \n", "WIN\n1000000100 1000000100 \n", "WIN\n2 0 2 \n", "WIN\n1000000100 1000000100 \n", "WIN\n1000000100 1000000100 \n", "WIN\n1010100010 1010100010 \n", "WIN\n1010100010 1010100010 \n", "WIN\n1010100010 1010100010 \n", "WIN\n1010100010 1010100010 \n", "WIN\n0 0 \n", "WIN\n0 \n", "WIN\n123456789 123456789 \n", "WIN\n0 0 \n", "WIN\n0 \n", "WIN\n1000000000 1000000000 \n", "WIN\n0 \n", "WIN\n1010100010 1010100010 \n", "WIN\n1010100010 1010100010 \n", "WIN\n1010100010 1010100010 \n", "WIN\n1010100010 1010100010 \n", "LOSE\n"]}
11
[ "PYTHON3" ]
2
2
code_contests
45fa32d9bd135bc2149efcf13e86cfff
1189_D1. Add on a Tree
Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on all edges on the simple path between u and v. For example, on the picture below you can see the result of applying two operations to the graph: adding 2 on the path from 7 to 6, and then adding -0.5 on the path from 4 to 5. <image> Is it true that for any configuration of real numbers written on edges, we can achieve it with a finite number of operations? Leaf is a node of a tree of degree 1. Simple path is a path that doesn't contain any node twice. Input The first line contains a single integer n (2 ≀ n ≀ 10^5) β€” the number of nodes. Each of the next n-1 lines contains two integers u and v (1 ≀ u, v ≀ n, u β‰  v), meaning that there is an edge between nodes u and v. It is guaranteed that these edges form a tree. Output If there is a configuration of real numbers written on edges of the tree that we can't achieve by performing the operations, output "NO". Otherwise, output "YES". You can print each letter in any case (upper or lower). Examples Input 2 1 2 Output YES Input 3 1 2 2 3 Output NO Input 5 1 2 1 3 1 4 2 5 Output NO Input 6 1 2 1 3 1 4 2 5 2 6 Output YES Note In the first example, we can add any real x to the value written on the only edge (1, 2). <image> In the second example, one of configurations that we can't reach is 0 written on (1, 2) and 1 written on (2, 3). <image> Below you can see graphs from examples 3, 4: <image> <image>
{"inputs": ["2\n1 2\n", "3\n1 2\n2 3\n", "5\n1 2\n1 3\n1 4\n2 5\n", "6\n1 2\n1 3\n1 4\n2 5\n2 6\n", "50\n16 4\n17 9\n31 19\n22 10\n8 1\n40 30\n3 31\n20 29\n47 27\n22 25\n32 34\n12 15\n40 32\n10 33\n47 12\n6 24\n46 41\n14 23\n12 35\n31 42\n46 28\n31 20\n46 37\n1 39\n29 49\n37 47\n40 6\n42 36\n47 2\n24 46\n2 13\n8 45\n41 3\n32 17\n4 7\n47 26\n28 8\n41 50\n34 44\n33 21\n25 5\n16 40\n3 14\n8 18\n28 11\n32 22\n2 38\n3 48\n44 43\n", "10\n8 1\n1 2\n8 9\n8 5\n1 3\n1 10\n1 6\n1 7\n8 4\n", "5\n5 1\n5 4\n4 3\n1 2\n", "7\n1 2\n2 3\n1 4\n1 5\n3 6\n3 7\n", "3\n1 3\n2 3\n", "60\n26 6\n59 30\n31 12\n31 3\n38 23\n59 29\n53 9\n38 56\n53 54\n29 21\n17 55\n59 38\n26 16\n24 59\n24 25\n17 35\n24 41\n30 15\n31 27\n8 44\n26 5\n26 48\n8 32\n53 17\n3 34\n3 51\n30 28\n47 10\n53 60\n36 42\n24 53\n59 22\n53 40\n26 52\n36 4\n59 8\n29 37\n36 20\n17 47\n53 18\n3 50\n30 2\n17 7\n8 58\n59 1\n31 11\n24 26\n24 43\n53 57\n59 45\n47 13\n26 46\n17 33\n30 31\n26 39\n26 19\n24 36\n8 49\n38 14\n", "7\n1 2\n2 3\n3 4\n3 5\n1 6\n1 7\n", "20\n19 16\n19 18\n20 7\n9 4\n6 17\n14 2\n9 15\n2 13\n5 11\n19 12\n12 20\n16 9\n11 8\n19 5\n3 1\n19 14\n5 3\n12 10\n19 6\n", "7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n", "10\n9 5\n7 1\n9 10\n7 2\n5 4\n9 6\n2 9\n10 8\n1 3\n", "4\n2 4\n2 3\n2 1\n", "4\n1 4\n3 2\n1 3\n", "3\n1 2\n1 3\n", "5\n1 2\n1 5\n1 3\n1 4\n", "20\n14 9\n12 13\n10 15\n2 1\n20 19\n16 6\n16 3\n17 14\n3 5\n2 11\n3 10\n15 8\n14 2\n6 4\n3 20\n5 18\n1 7\n1 16\n4 12\n", "20\n7 5\n14 13\n17 6\n3 8\n16 12\n18 9\n3 18\n14 1\n17 3\n15 2\n17 4\n9 11\n2 7\n15 17\n3 20\n16 10\n17 14\n2 16\n1 19\n", "8\n1 2\n2 3\n3 4\n1 7\n1 8\n4 5\n4 6\n", "5\n5 1\n5 2\n5 3\n5 4\n", "50\n49 6\n43 7\n1 27\n19 35\n15 37\n16 12\n19 21\n16 28\n49 9\n48 39\n13 1\n2 48\n9 50\n44 3\n41 32\n48 31\n49 33\n6 11\n13 20\n49 22\n13 41\n48 29\n13 46\n15 47\n34 2\n49 13\n48 14\n34 24\n16 36\n13 40\n49 34\n49 17\n43 25\n11 23\n10 15\n19 26\n34 44\n16 42\n19 18\n46 8\n29 38\n1 45\n12 43\n13 16\n46 30\n15 5\n49 10\n11 19\n32 4\n", "20\n13 1\n18 2\n3 7\n18 5\n20 16\n3 12\n18 9\n3 10\n18 11\n13 6\n3 18\n20 15\n20 17\n3 13\n3 4\n13 14\n3 20\n18 8\n3 19\n", "10\n8 2\n5 6\n1 8\n2 9\n1 4\n8 10\n10 5\n2 7\n2 3\n", "50\n16 4\n17 9\n31 19\n3 10\n8 1\n40 30\n3 31\n20 29\n47 27\n22 25\n32 34\n12 15\n40 32\n10 33\n47 12\n6 24\n46 41\n14 23\n12 35\n31 42\n46 28\n31 20\n46 37\n1 39\n29 49\n37 47\n40 6\n42 36\n47 2\n24 46\n2 13\n8 45\n41 3\n32 17\n4 7\n47 26\n28 8\n41 50\n34 44\n33 21\n25 5\n16 40\n3 14\n8 18\n28 11\n32 22\n2 38\n3 48\n44 43\n", "7\n1 2\n1 3\n2 4\n2 5\n1 6\n2 7\n", "5\n5 1\n5 4\n4 3\n2 2\n", "60\n26 6\n59 30\n31 12\n31 3\n38 23\n59 29\n53 9\n38 56\n53 54\n29 21\n17 55\n59 38\n26 16\n24 59\n24 25\n17 35\n24 41\n30 15\n31 27\n8 44\n26 5\n26 48\n8 32\n53 17\n3 34\n3 51\n20 28\n47 10\n53 60\n36 42\n24 53\n59 22\n53 40\n26 52\n36 4\n59 8\n29 37\n36 20\n17 47\n53 18\n3 50\n30 2\n17 7\n8 58\n59 1\n31 11\n24 26\n24 43\n53 57\n59 45\n47 13\n26 46\n17 33\n30 31\n26 39\n26 19\n24 36\n8 49\n38 14\n", "7\n1 2\n2 4\n3 4\n3 5\n1 6\n1 7\n", "7\n1 2\n1 3\n2 4\n2 5\n1 6\n3 7\n", "10\n9 5\n4 1\n9 10\n7 2\n5 4\n9 6\n2 9\n10 8\n1 3\n", "4\n3 4\n2 3\n2 1\n", "6\n1 2\n1 3\n2 4\n2 5\n2 6\n", "60\n26 6\n59 30\n31 12\n31 3\n38 23\n59 29\n53 9\n38 56\n53 54\n29 21\n17 55\n59 38\n26 16\n24 59\n24 25\n17 35\n24 41\n30 15\n31 27\n8 44\n26 5\n26 48\n8 32\n53 17\n3 34\n3 51\n20 28\n47 10\n53 60\n36 42\n24 53\n59 22\n53 40\n26 52\n36 4\n59 8\n29 37\n36 20\n17 47\n53 18\n3 50\n30 2\n17 7\n8 58\n59 1\n31 11\n24 26\n24 43\n53 57\n59 45\n47 13\n49 46\n17 33\n30 31\n26 39\n26 19\n24 36\n8 49\n38 14\n", "10\n9 5\n4 1\n9 10\n7 1\n5 4\n9 6\n2 9\n10 8\n1 3\n", "6\n1 2\n1 3\n2 4\n4 5\n2 6\n", "60\n26 6\n59 30\n31 12\n31 3\n38 23\n59 29\n53 9\n59 56\n53 54\n29 21\n17 55\n59 38\n26 16\n24 59\n24 25\n17 35\n24 41\n30 15\n31 27\n8 44\n26 5\n26 48\n8 32\n53 17\n3 34\n3 51\n20 28\n47 10\n53 60\n36 42\n24 53\n59 22\n53 40\n26 52\n36 4\n59 8\n29 37\n36 20\n17 47\n53 18\n3 50\n30 2\n17 7\n8 58\n59 1\n31 11\n24 26\n24 43\n53 57\n59 45\n47 13\n49 46\n17 33\n30 31\n26 39\n26 19\n24 36\n8 49\n38 14\n", "7\n1 2\n1 3\n2 4\n3 5\n1 6\n2 7\n", "6\n1 2\n1 3\n2 4\n4 5\n1 6\n", "60\n26 6\n59 30\n31 12\n32 3\n38 23\n59 29\n53 9\n59 56\n53 54\n29 21\n17 55\n59 38\n26 16\n24 59\n24 25\n17 35\n24 41\n30 15\n31 27\n8 44\n26 5\n26 48\n8 32\n53 17\n3 34\n3 51\n20 28\n47 10\n53 60\n36 42\n24 53\n59 22\n53 40\n26 52\n36 4\n59 8\n29 37\n36 20\n17 47\n53 18\n3 50\n30 2\n17 7\n8 58\n59 1\n31 11\n24 26\n24 43\n53 57\n59 45\n47 13\n49 46\n17 33\n30 31\n26 39\n26 19\n24 36\n8 49\n38 14\n", "7\n1 2\n1 1\n2 4\n3 5\n1 6\n2 7\n", "10\n8 1\n1 2\n8 9\n8 5\n1 3\n2 10\n1 6\n1 7\n8 4\n", "20\n19 16\n19 18\n20 7\n9 4\n6 17\n14 2\n9 15\n2 13\n5 11\n19 12\n12 20\n16 9\n11 8\n19 5\n3 1\n19 14\n5 3\n18 10\n19 6\n", "7\n1 2\n1 3\n2 4\n2 5\n4 6\n3 7\n", "4\n4 4\n2 3\n2 1\n", "4\n1 4\n2 2\n1 3\n", "20\n14 9\n12 13\n10 15\n2 1\n20 19\n16 6\n16 3\n17 8\n3 5\n2 11\n3 10\n15 8\n14 2\n6 4\n3 20\n5 18\n1 7\n1 16\n4 12\n", "20\n7 5\n14 13\n17 6\n3 8\n16 12\n18 9\n3 18\n14 1\n17 3\n15 2\n17 4\n2 11\n2 7\n15 17\n3 20\n16 10\n17 14\n2 16\n1 19\n", "50\n49 6\n43 7\n1 27\n19 35\n15 37\n16 12\n19 21\n16 28\n49 9\n48 39\n13 1\n2 48\n9 50\n44 3\n41 32\n48 31\n49 33\n6 11\n13 20\n49 22\n13 41\n48 29\n13 46\n15 47\n34 2\n49 13\n48 14\n34 24\n16 36\n13 40\n49 34\n49 17\n43 25\n19 23\n10 15\n19 26\n34 44\n16 42\n19 18\n46 8\n29 38\n1 45\n12 43\n13 16\n46 30\n15 5\n49 10\n11 19\n32 4\n", "10\n1 2\n5 6\n1 8\n2 9\n1 4\n8 10\n10 5\n2 7\n2 3\n", "5\n1 3\n1 3\n1 4\n4 5\n", "50\n16 4\n17 9\n31 19\n3 10\n8 1\n40 30\n3 31\n20 29\n47 27\n22 25\n32 34\n12 15\n40 32\n20 33\n47 12\n6 24\n46 41\n14 23\n12 35\n31 42\n46 28\n31 20\n46 37\n1 39\n29 49\n37 47\n40 6\n42 36\n47 2\n24 46\n2 13\n8 45\n41 3\n32 17\n4 7\n47 26\n28 8\n41 50\n34 44\n33 21\n25 5\n16 40\n3 14\n8 18\n28 11\n32 22\n2 38\n3 48\n44 43\n", "5\n5 1\n5 4\n4 3\n2 3\n", "60\n26 6\n59 30\n31 12\n31 3\n38 23\n55 29\n53 9\n38 56\n53 54\n29 21\n17 55\n59 38\n26 16\n24 59\n24 25\n17 35\n24 41\n30 15\n31 27\n8 44\n26 5\n26 48\n8 32\n53 17\n3 34\n3 51\n20 28\n47 10\n53 60\n36 42\n24 53\n59 22\n53 40\n26 52\n36 4\n59 8\n29 37\n36 20\n17 47\n53 18\n3 50\n30 2\n17 7\n8 58\n59 1\n31 11\n24 26\n24 43\n53 57\n59 45\n47 13\n26 46\n17 33\n30 31\n26 39\n26 19\n24 36\n8 49\n38 14\n", "7\n1 2\n1 3\n2 4\n2 5\n1 6\n1 7\n", "6\n1 2\n1 3\n2 4\n4 2\n2 6\n", "60\n26 6\n59 30\n31 12\n32 3\n38 23\n59 29\n53 9\n59 56\n53 54\n29 21\n17 55\n59 38\n26 16\n24 59\n24 25\n17 35\n24 41\n30 15\n31 27\n8 44\n26 5\n26 48\n8 32\n53 17\n3 34\n3 51\n20 28\n47 10\n53 60\n36 42\n24 53\n59 22\n53 40\n26 52\n36 4\n59 8\n29 37\n36 20\n17 47\n53 18\n3 50\n30 2\n17 7\n8 58\n59 1\n31 11\n24 26\n24 43\n53 57\n59 45\n47 13\n49 46\n17 33\n30 31\n30 39\n26 19\n24 36\n8 49\n38 14\n", "7\n1 2\n1 1\n3 4\n3 5\n1 6\n2 7\n", "10\n8 2\n1 2\n8 9\n8 5\n1 3\n2 10\n1 6\n1 7\n8 4\n", "4\n1 4\n2 2\n1 4\n", "20\n14 9\n12 13\n10 15\n2 1\n20 19\n16 6\n16 3\n17 8\n3 5\n2 11\n3 10\n2 8\n14 2\n6 4\n3 20\n5 18\n1 7\n1 16\n4 12\n", "20\n7 5\n14 14\n17 6\n3 8\n16 12\n18 9\n3 18\n14 1\n17 3\n15 2\n17 4\n2 11\n2 7\n15 17\n3 20\n16 10\n17 14\n2 16\n1 19\n", "50\n49 6\n43 7\n1 27\n19 35\n15 37\n16 12\n19 21\n16 28\n49 9\n48 39\n13 1\n2 48\n9 50\n44 3\n41 32\n48 31\n49 33\n6 11\n13 20\n49 22\n13 41\n48 29\n13 46\n15 47\n34 2\n49 13\n48 14\n34 24\n16 36\n23 40\n49 34\n49 17\n43 25\n19 23\n10 15\n19 26\n34 44\n16 42\n19 18\n46 8\n29 38\n1 45\n12 43\n13 16\n46 30\n15 5\n49 10\n11 19\n32 4\n", "5\n1 2\n1 3\n1 4\n4 5\n", "6\n1 2\n1 3\n2 4\n4 2\n1 6\n", "10\n8 2\n1 4\n8 9\n8 5\n1 3\n2 10\n1 6\n1 7\n8 4\n", "4\n1 4\n2 2\n2 4\n", "20\n14 9\n8 13\n10 15\n2 1\n20 19\n16 6\n16 3\n17 8\n3 5\n2 11\n3 10\n2 8\n14 2\n6 4\n3 20\n5 18\n1 7\n1 16\n4 12\n", "20\n7 5\n14 14\n17 6\n3 8\n16 12\n18 9\n3 18\n14 1\n11 3\n15 2\n17 4\n2 11\n2 7\n15 17\n3 20\n16 10\n17 14\n2 16\n1 19\n", "50\n49 6\n43 7\n1 27\n19 35\n15 37\n16 12\n19 21\n16 28\n49 17\n48 39\n13 1\n2 48\n9 50\n44 3\n41 32\n48 31\n49 33\n6 11\n13 20\n49 22\n13 41\n48 29\n13 46\n15 47\n34 2\n49 13\n48 14\n34 24\n16 36\n23 40\n49 34\n49 17\n43 25\n19 23\n10 15\n19 26\n34 44\n16 42\n19 18\n46 8\n29 38\n1 45\n12 43\n13 16\n46 30\n15 5\n49 10\n11 19\n32 4\n", "5\n1 1\n1 3\n1 4\n4 5\n", "10\n8 1\n1 2\n8 9\n7 5\n1 3\n1 10\n1 6\n1 7\n8 4\n", "7\n1 2\n3 3\n1 4\n1 5\n3 6\n3 7\n", "7\n1 2\n2 3\n3 5\n3 5\n1 6\n1 7\n", "7\n1 2\n1 3\n2 4\n2 5\n3 6\n1 7\n", "10\n9 5\n7 1\n9 10\n7 2\n9 4\n9 6\n2 9\n10 8\n1 3\n", "5\n1 2\n1 5\n2 3\n1 4\n", "8\n1 2\n2 3\n3 4\n1 7\n1 8\n4 5\n2 6\n", "50\n49 6\n43 7\n1 27\n19 35\n15 37\n16 12\n19 21\n16 28\n49 9\n48 39\n13 1\n2 48\n9 50\n44 3\n41 32\n48 31\n49 33\n6 11\n13 20\n49 22\n13 41\n1 29\n13 46\n15 47\n34 2\n49 13\n48 14\n34 24\n16 36\n13 40\n49 34\n49 17\n43 25\n11 23\n10 15\n19 26\n34 44\n16 42\n19 18\n46 8\n29 38\n1 45\n12 43\n13 16\n46 30\n15 5\n49 10\n11 19\n32 4\n", "5\n1 2\n1 3\n1 4\n1 5\n", "5\n5 1\n5 4\n4 2\n2 2\n", "7\n1 2\n2 4\n3 4\n5 5\n1 6\n1 7\n", "7\n1 2\n1 3\n2 1\n2 5\n1 6\n3 7\n", "6\n1 2\n2 3\n2 4\n4 5\n2 6\n", "6\n1 4\n1 3\n2 4\n4 5\n1 6\n", "10\n8 1\n1 2\n8 9\n8 5\n1 3\n3 10\n1 6\n1 7\n8 4\n", "10\n1 2\n5 6\n1 8\n2 9\n1 4\n8 10\n10 5\n2 7\n3 3\n", "5\n5 1\n1 4\n4 3\n2 3\n", "60\n26 6\n59 30\n31 12\n31 3\n38 23\n55 29\n53 9\n38 56\n53 54\n29 21\n17 55\n59 38\n26 16\n24 59\n24 25\n17 35\n24 41\n30 15\n31 27\n8 44\n26 5\n26 48\n8 32\n53 17\n3 34\n3 51\n20 28\n47 10\n53 60\n10 42\n24 53\n59 22\n53 40\n26 52\n36 4\n59 8\n29 37\n36 20\n17 47\n53 18\n3 50\n30 2\n17 7\n8 58\n59 1\n31 11\n24 26\n24 43\n53 57\n59 45\n47 13\n26 46\n17 33\n30 31\n26 39\n26 19\n24 36\n8 49\n38 14\n", "60\n26 6\n59 30\n31 12\n32 3\n38 23\n59 29\n53 9\n59 56\n53 54\n29 21\n17 55\n59 38\n26 16\n24 59\n24 25\n17 35\n24 41\n30 15\n31 27\n8 44\n26 5\n26 48\n8 32\n53 17\n3 34\n3 51\n20 28\n52 10\n53 60\n36 42\n24 53\n59 22\n53 40\n26 52\n36 4\n59 8\n29 37\n36 20\n17 47\n53 18\n3 50\n30 2\n17 7\n8 58\n59 1\n31 11\n24 26\n24 43\n53 57\n59 45\n47 13\n49 46\n17 33\n30 31\n30 39\n26 19\n24 36\n8 49\n38 14\n", "10\n8 2\n1 2\n8 9\n8 5\n1 3\n2 10\n1 6\n2 7\n8 4\n", "20\n14 9\n12 13\n10 15\n2 1\n20 19\n2 6\n16 3\n17 8\n3 5\n2 11\n3 10\n2 8\n14 2\n6 4\n3 20\n5 18\n1 7\n1 16\n4 12\n", "20\n7 5\n14 14\n17 6\n3 8\n16 12\n18 9\n3 18\n14 1\n17 3\n15 2\n17 4\n2 11\n2 7\n15 17\n3 17\n16 10\n17 14\n2 16\n1 19\n"], "outputs": ["YES", "NO", "NO", "YES", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "YES", "NO", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n"]}
10
[ "PYTHON3" ]
2
2
code_contests
037588be343a5ac87b81a51ace4a5b70
1208_D. Restore Permutation
An array of integers p_{1},p_{2}, …,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2], [1,1], [2,3,4]. There is a hidden permutation of length n. For each index i, you are given s_{i}, which equals to the sum of all p_{j} such that j < i and p_{j} < p_{i}. In other words, s_i is the sum of elements before the i-th element that are smaller than the i-th element. Your task is to restore the permutation. Input The first line contains a single integer n (1 ≀ n ≀ 2 β‹… 10^{5}) β€” the size of the permutation. The second line contains n integers s_{1}, s_{2}, …, s_{n} (0 ≀ s_{i} ≀ (n(n-1))/(2)). It is guaranteed that the array s corresponds to a valid permutation of length n. Output Print n integers p_{1}, p_{2}, …, p_{n} β€” the elements of the restored permutation. We can show that the answer is always unique. Examples Input 3 0 0 0 Output 3 2 1 Input 2 0 1 Output 1 2 Input 5 0 1 1 1 10 Output 1 4 3 2 5 Note In the first example for each i there is no index j satisfying both conditions, hence s_i are always 0. In the second example for i = 2 it happens that j = 1 satisfies the conditions, so s_2 = p_1. In the third example for i = 2, 3, 4 only j = 1 satisfies the conditions, so s_2 = s_3 = s_4 = 1. For i = 5 all j = 1, 2, 3, 4 are possible, so s_5 = p_1 + p_2 + p_3 + p_4 = 10.
{"inputs": ["3\n0 0 0\n", "5\n0 1 1 1 10\n", "2\n0 1\n", "100\n0 0 57 121 57 0 19 251 19 301 19 160 57 578 664 57 19 50 0 621 91 5 263 34 5 96 713 649 22 22 22 5 108 198 1412 1147 84 1326 1777 0 1780 132 2000 479 1314 525 68 690 1689 1431 1288 54 1514 1593 1037 1655 807 465 1674 1747 1982 423 837 139 1249 1997 1635 1309 661 334 3307 2691 21 3 533 1697 250 3920 0 343 96 242 2359 3877 3877 150 1226 96 358 829 228 2618 27 2854 119 1883 710 0 4248 435\n", "20\n0 1 7 15 30 15 59 42 1 4 1 36 116 36 16 136 10 36 46 36\n", "1\n0\n", "15\n0 0 3 3 13 3 6 34 47 12 20 6 6 21 55\n", "2\n0 0\n", "3\n0 1 1\n", "3\n0 0 1\n", "3\n0 2 0\n", "5\n0 0 1 1 10\n", "5\n0 0 1 1 6\n", "15\n0 0 0 3 13 3 6 34 47 12 20 6 6 21 55\n", "5\n0 1 1 1 6\n", "5\n0 0 0 1 10\n", "15\n0 0 0 3 13 3 3 34 47 12 20 6 6 21 55\n", "3\n0 0 3\n", "3\n0 1 3\n", "5\n0 0 0 1 6\n", "5\n0 0 1 1 1\n", "5\n0 1 1 1 3\n", "5\n0 0 1 1 3\n", "15\n0 0 1 3 13 3 3 34 47 12 20 6 6 21 55\n", "5\n0 1 1 1 1\n", "5\n0 0 0 0 10\n", "15\n0 0 0 1 13 3 3 34 47 12 20 6 6 21 55\n", "5\n0 0 0 0 6\n", "5\n0 0 0 1 3\n", "5\n0 0 0 0 3\n", "5\n0 0 2 0 3\n", "5\n0 0 0 1 1\n", "5\n0 0 0 0 1\n", "5\n0 0 0 0 0\n", "15\n0 1 3 3 13 3 6 34 47 12 20 6 6 21 55\n", "5\n0 0 0 2 0\n", "5\n0 0 0 3 6\n", "15\n0 0 1 3 13 3 6 34 47 12 20 6 6 21 55\n"], "outputs": ["3 2 1 ", "1 4 3 2 5 ", "1 2 ", "94 57 64 90 58 19 53 71 50 67 38 56 45 86 89 42 31 36 5 68 37 10 49 24 7 32 65 59 14 12 11 6 27 34 91 72 21 87 98 3 97 25 100 46 85 48 18 51 88 83 70 13 79 82 62 80 55 43 73 76 81 40 52 22 60 77 69 61 47 35 92 84 9 4 41 66 28 99 2 33 17 26 74 96 95 20 54 15 29 44 23 75 8 78 16 63 39 1 93 30 ", "1 6 8 15 17 12 18 16 3 4 2 14 20 13 7 19 5 10 11 9 ", "1 ", "2 1 15 10 12 3 6 13 14 8 9 5 4 7 11 ", "2 1\n", "1 3 2\n", "3 1 2\n", "2 3 1\n", "4 1 3 2 5\n", "5 1 3 2 4\n", "15 2 1 10 12 3 6 13 14 8 9 5 4 7 11\n", "1 5 3 2 4\n", "4 3 1 2 5\n", "15 2 1 10 12 6 3 13 14 8 9 5 4 7 11\n", "2 1 3\n", "1 2 3\n", "5 3 1 2 4\n", "5 1 4 3 2\n", "1 5 4 2 3\n", "5 1 4 2 3\n", "15 1 2 10 12 6 3 13 14 8 9 5 4 7 11\n", "1 5 4 3 2\n", "4 3 2 1 5\n", "15 10 1 2 12 6 3 13 14 8 9 5 4 7 11\n", "5 3 2 1 4\n", "5 4 1 2 3\n", "5 4 2 1 3\n", "5 2 4 1 3\n", "5 4 1 3 2\n", "5 4 3 1 2\n", "5 4 3 2 1\n", "1 2 15 10 12 3 6 13 14 8 9 5 4 7 11\n", "5 4 2 3 1\n", "5 2 1 3 4\n", "15 1 2 10 12 3 6 13 14 8 9 5 4 7 11\n"]}
10
[ "PYTHON3" ]
2
2
code_contests
41f76e73f328946954e9a18f217a149b
1227_D1. Optimal Subsequences (Easy Version)
This is the easier version of the problem. In this version 1 ≀ n, m ≀ 100. You can hack this problem only if you solve and lock both problems. You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily go consecutively). For example, for the sequence a=[11,20,11,33,11,20,11]: * [11,20,11,33,11,20,11], [11,20,11,33,11,20], [11,11,11,11], [20], [33,20] are subsequences (these are just some of the long list); * [40], [33,33], [33,20,20], [20,20,11,11] are not subsequences. Suppose that an additional non-negative integer k (1 ≀ k ≀ n) is given, then the subsequence is called optimal if: * it has a length of k and the sum of its elements is the maximum possible among all subsequences of length k; * and among all subsequences of length k that satisfy the previous item, it is lexicographically minimal. Recall that the sequence b=[b_1, b_2, ..., b_k] is lexicographically smaller than the sequence c=[c_1, c_2, ..., c_k] if the first element (from the left) in which they differ less in the sequence b than in c. Formally: there exists t (1 ≀ t ≀ k) such that b_1=c_1, b_2=c_2, ..., b_{t-1}=c_{t-1} and at the same time b_t<c_t. For example: * [10, 20, 20] lexicographically less than [10, 21, 1], * [7, 99, 99] is lexicographically less than [10, 21, 1], * [10, 21, 0] is lexicographically less than [10, 21, 1]. You are given a sequence of a=[a_1,a_2,...,a_n] and m requests, each consisting of two numbers k_j and pos_j (1 ≀ k ≀ n, 1 ≀ pos_j ≀ k_j). For each query, print the value that is in the index pos_j of the optimal subsequence of the given sequence a for k=k_j. For example, if n=4, a=[10,20,30,20], k_j=2, then the optimal subsequence is [20,30] β€” it is the minimum lexicographically among all subsequences of length 2 with the maximum total sum of items. Thus, the answer to the request k_j=2, pos_j=1 is the number 20, and the answer to the request k_j=2, pos_j=2 is the number 30. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the length of the sequence a. The second line contains elements of the sequence a: integer numbers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9). The third line contains an integer m (1 ≀ m ≀ 100) β€” the number of requests. The following m lines contain pairs of integers k_j and pos_j (1 ≀ k ≀ n, 1 ≀ pos_j ≀ k_j) β€” the requests. Output Print m integers r_1, r_2, ..., r_m (1 ≀ r_j ≀ 10^9) one per line: answers to the requests in the order they appear in the input. The value of r_j should be equal to the value contained in the position pos_j of the optimal subsequence for k=k_j. Examples Input 3 10 20 10 6 1 1 2 1 2 2 3 1 3 2 3 3 Output 20 10 20 10 20 10 Input 7 1 2 1 3 1 2 1 9 2 1 2 2 3 1 3 2 3 3 1 1 7 1 7 7 7 4 Output 2 3 2 3 2 3 1 1 3 Note In the first example, for a=[10,20,10] the optimal subsequences are: * for k=1: [20], * for k=2: [10,20], * for k=3: [10,20,10].
{"inputs": ["3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n", "2\n1 10\n3\n2 2\n2 1\n1 1\n", "2\n3922 3922\n3\n2 2\n2 1\n1 1\n", "1\n1000000000\n1\n1 1\n", "1\n1\n3\n1 1\n1 1\n1 1\n", "5\n3 1 4 1 2\n15\n5 5\n5 4\n5 3\n5 2\n5 1\n4 4\n4 3\n4 2\n4 1\n3 3\n3 2\n3 1\n2 2\n2 1\n1 1\n", "2\n392222 322\n3\n2 2\n2 1\n1 1\n", "2\n1 10\n2\n2 2\n2 1\n1 1\n", "2\n3922 3922\n1\n2 2\n2 1\n1 1\n", "1\n1\n2\n1 1\n1 1\n1 1\n", "2\n392222 187\n3\n2 2\n2 1\n1 1\n", "2\n4612 3922\n1\n2 1\n2 0\n1 1\n", "2\n3555 3922\n3\n2 2\n2 1\n1 1\n", "5\n3 1 4 2 2\n15\n5 5\n5 4\n5 3\n5 2\n5 1\n4 4\n4 3\n4 2\n4 1\n3 3\n3 2\n3 1\n2 2\n2 1\n1 1\n", "3\n10 20 10\n2\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "7\n1 2 1 6 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n", "2\n1 10\n2\n2 2\n2 2\n1 1\n", "2\n392222 187\n3\n2 2\n2 2\n1 1\n", "2\n392222 313\n3\n2 2\n2 2\n1 1\n", "2\n176692 313\n3\n2 2\n2 2\n1 1\n", "2\n3259 4209\n1\n2 1\n2 1\n1 2\n", "2\n3259 4209\n2\n2 1\n2 1\n1 2\n", "2\n3922 3052\n1\n2 2\n2 1\n3 1\n", "2\n2189 2193\n1\n2 2\n0 2\n3 0\n", "2\n2189 2193\n1\n2 1\n0 2\n3 0\n", "2\n1426 2193\n1\n2 1\n0 2\n3 0\n", "2\n2436 2072\n1\n2 1\n0 2\n5 0\n", "2\n1 7\n3\n2 2\n2 1\n1 1\n", "2\n2123 3922\n3\n2 2\n2 1\n1 1\n", "5\n3 1 4 1 2\n15\n5 5\n5 3\n5 3\n5 2\n5 1\n4 4\n4 3\n4 2\n4 1\n3 3\n3 2\n3 1\n2 2\n2 1\n1 1\n", "2\n336365 322\n3\n2 2\n2 1\n1 1\n", "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n5 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n", "2\n3922 265\n1\n2 2\n2 1\n1 1\n", "2\n392222 16\n3\n2 2\n2 1\n1 1\n", "2\n392222 50\n3\n2 2\n2 2\n1 1\n", "2\n2842 3492\n1\n2 2\n2 0\n1 0\n", "2\n3922 5235\n1\n2 2\n2 2\n3 1\n", "2\n673 2193\n1\n2 1\n0 2\n3 0\n", "2\n1426 2072\n1\n2 2\n0 2\n5 0\n", "2\n1 7\n1\n2 2\n2 1\n1 1\n", "5\n3 1 4 1 2\n15\n5 5\n5 3\n5 3\n5 2\n5 1\n4 4\n4 3\n4 2\n4 1\n3 3\n3 2\n3 1\n2 2\n2 2\n1 1\n", "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n5 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 5\n", "2\n8322 3922\n1\n2 1\n2 0\n1 2\n", "2\n3922 1526\n1\n2 2\n3 2\n3 0\n", "2\n3922 3922\n1\n2 1\n2 1\n1 1\n", "1\n1\n2\n1 1\n1 1\n2 1\n", "2\n3922 3922\n1\n2 1\n2 0\n1 1\n", "2\n3922 3922\n1\n2 2\n2 1\n2 1\n", "2\n3922 4209\n1\n2 1\n2 1\n1 1\n", "2\n3922 3922\n1\n2 2\n2 0\n1 1\n", "2\n4612 6198\n1\n2 1\n2 0\n1 1\n", "2\n3922 3922\n1\n2 2\n2 0\n2 1\n", "2\n3922 4209\n1\n2 1\n2 1\n1 2\n", "2\n1723 3922\n1\n2 2\n2 0\n1 1\n", "2\n3922 3922\n1\n2 2\n2 0\n3 1\n", "2\n2842 3922\n1\n2 2\n2 0\n1 1\n", "2\n3922 3922\n1\n2 2\n2 1\n3 1\n", "2\n2842 3922\n1\n2 2\n3 0\n1 1\n", "2\n2842 3922\n1\n2 2\n2 0\n1 0\n", "2\n3922 3052\n1\n2 2\n2 2\n3 1\n", "2\n2842 3922\n1\n2 2\n2 -1\n1 0\n", "2\n3922 3052\n1\n2 2\n2 2\n3 0\n", "2\n2189 3052\n1\n2 2\n2 2\n3 0\n", "2\n2189 3052\n1\n2 2\n1 2\n3 0\n", "2\n2189 3052\n1\n2 2\n0 2\n3 0\n", "2\n1426 2193\n1\n2 1\n0 2\n5 0\n", "2\n1426 2072\n1\n2 1\n0 2\n5 0\n", "2\n2436 550\n1\n2 1\n0 2\n5 0\n", "2\n3922 3922\n1\n2 1\n2 1\n1 0\n", "2\n3922 4480\n1\n2 1\n2 0\n1 1\n", "2\n4612 3922\n1\n2 1\n2 0\n1 2\n", "5\n3 1 4 2 2\n15\n5 5\n5 4\n5 3\n5 2\n5 1\n4 3\n4 3\n4 2\n4 1\n3 3\n3 2\n3 1\n2 2\n2 1\n1 1\n", "2\n3922 3922\n1\n2 2\n3 1\n1 1\n", "2\n3922 2384\n1\n2 1\n2 1\n1 1\n", "2\n4612 6198\n1\n2 1\n2 1\n1 1\n", "2\n3922 6047\n1\n2 1\n2 1\n1 2\n", "2\n1723 3922\n1\n2 2\n2 0\n2 1\n", "2\n3922 3922\n1\n2 2\n2 0\n5 1\n", "2\n3259 4209\n1\n2 1\n2 1\n1 0\n", "2\n580 3922\n1\n2 2\n2 1\n3 1\n", "2\n3922 3052\n1\n2 2\n3 1\n3 1\n", "2\n2842 3922\n1\n2 2\n3 -1\n1 0\n", "2\n3922 3052\n1\n2 2\n3 2\n3 0\n", "2\n833 3052\n1\n2 2\n2 2\n3 0\n", "2\n1908 3052\n1\n2 2\n1 2\n3 0\n", "2\n2189 3052\n1\n2 2\n0 3\n3 0\n", "2\n2189 2193\n1\n2 2\n0 2\n3 1\n", "2\n2189 2193\n1\n2 1\n0 2\n6 0\n", "2\n1426 2855\n1\n2 1\n0 2\n5 0\n", "2\n2436 2072\n1\n2 1\n0 0\n5 0\n", "2\n3922 265\n1\n2 2\n0 1\n1 1\n", "2\n3922 3922\n1\n2 1\n0 1\n1 0\n", "2\n3922 3730\n1\n2 1\n2 0\n1 1\n", "2\n3922 3922\n1\n2 2\n3 0\n1 1\n", "2\n4612 1428\n1\n2 1\n2 1\n1 1\n", "2\n3922 6047\n1\n2 1\n2 2\n1 2\n", "2\n3922 3922\n1\n2 2\n2 0\n4 1\n", "2\n3922 5235\n1\n2 1\n2 2\n3 1\n", "2\n818 3052\n1\n2 2\n2 2\n3 0\n", "2\n1908 3052\n1\n2 2\n0 2\n3 0\n", "2\n2189 3052\n1\n2 2\n0 3\n3 -1\n", "2\n2189 2193\n1\n2 2\n0 2\n6 1\n", "2\n2189 2193\n1\n2 1\n0 2\n10 0\n"], "outputs": ["20\n10\n20\n10\n20\n10\n", "2\n3\n2\n3\n2\n3\n1\n1\n3\n", "10\n1\n10\n", "3922\n3922\n3922\n", "1000000000\n", "1\n1\n1\n", "2\n1\n4\n1\n3\n2\n4\n1\n3\n2\n4\n3\n4\n3\n4\n", "322\n392222\n392222\n", "10\n1\n", "3922\n", "1\n1\n", "187\n392222\n392222\n", "4612\n", "3922\n3555\n3922\n", "2\n2\n4\n1\n3\n2\n2\n4\n3\n2\n4\n3\n4\n3\n4\n", "20\n10\n", "2\n6\n2\n6\n2\n6\n1\n1\n6\n", "10\n10\n", "187\n187\n392222\n", "313\n313\n392222\n", "313\n313\n176692\n", "3259\n", "3259\n3259\n", "3052\n", "2193\n", "2189\n", "1426\n", "2436\n", "7\n1\n7\n", "3922\n2123\n3922\n", "2\n4\n4\n1\n3\n2\n4\n1\n3\n2\n4\n3\n4\n3\n4\n", "322\n336365\n336365\n", "2\n3\n1\n3\n2\n3\n1\n1\n3\n", "265\n", "16\n392222\n392222\n", "50\n50\n392222\n", "3492\n", "5235\n", "673\n", "2072\n", "7\n", "2\n4\n4\n1\n3\n2\n4\n1\n3\n2\n4\n3\n4\n4\n4\n", "2\n3\n1\n3\n2\n3\n1\n1\n1\n", "8322\n", "1526\n", "3922\n", "1\n1\n", "3922\n", "3922\n", "3922\n", "3922\n", "4612\n", "3922\n", "3922\n", "3922\n", "3922\n", "3922\n", "3922\n", "3922\n", "3922\n", "3052\n", "3922\n", "3052\n", "3052\n", "3052\n", "3052\n", "1426\n", "1426\n", "2436\n", "3922\n", "3922\n", "4612\n", "2\n2\n4\n1\n3\n2\n2\n4\n3\n2\n4\n3\n4\n3\n4\n", "3922\n", "3922\n", "4612\n", "3922\n", "3922\n", "3922\n", "3259\n", "3922\n", "3052\n", "3922\n", "3052\n", "3052\n", "3052\n", "3052\n", "2193\n", "2189\n", "1426\n", "2436\n", "265\n", "3922\n", "3922\n", "3922\n", "4612\n", "3922\n", "3922\n", "3922\n", "3052\n", "3052\n", "3052\n", "2193\n", "2189\n"]}
10
[ "PYTHON3" ]
2
2
code_contests
cda5de16c54a2386a48801a871557317
1269_E. K Integers
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≀ i ≀ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. Let f(k) be the minimum number of moves that you need to make a subsegment with values 1,2,…,k appear in the permutation. You need to find f(1), f(2), …, f(n). Input The first line of input contains one integer n (1 ≀ n ≀ 200 000): the number of elements in the permutation. The next line of input contains n integers p_1, p_2, …, p_n: given permutation (1 ≀ p_i ≀ n). Output Print n integers, the minimum number of moves that you need to make a subsegment with values 1,2,…,k appear in the permutation, for k=1, 2, …, n. Examples Input 5 5 4 3 2 1 Output 0 1 3 6 10 Input 3 1 2 3 Output 0 0 0
{"inputs": ["3\n1 2 3\n", "5\n5 4 3 2 1\n", "1\n1\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39\n", "10\n5 1 6 2 8 3 4 10 9 7\n", "5\n5 4 3 1 2\n", "3\n3 2 1\n", "3\n2 3 1\n", "10\n5 1 6 2 8 4 3 10 9 7\n", "3\n3 1 2\n", "3\n2 1 3\n", "5\n5 4 1 2 3\n", "3\n1 3 2\n"], "outputs": ["0 0 0\n", "0 1 3 6 10\n", "0\n", "0 42 52 101 101 117 146 166 166 188 194 197 249 258 294 298 345 415 445 492 522 529 540 562 569 628 628 644 684 699 765 766 768 774 791 812 828 844 863 931 996 1011 1036 1040 1105 1166 1175 1232 1237 1251 1282 1364 1377 1409 1445 1455 1461 1534 1553 1565 1572 1581 1664 1706 1715 1779 1787 1837 1841 1847 1909 1919 1973 1976 2010 2060 2063 2087 2125 2133 2192 2193 2196 2276 2305 2305 2324 2327 2352 2361 2417 2418 2467 2468 2510 2598 2599 2697 2697 2770\n", "0 1 2 3 8 9 12 12 13 13\n", "0 0 2 5 9\n", "0 1 3\n", "0 2 2\n", "0 1 3 4 9 10 13 13 14 14\n", "0 0 2\n", "0 1 1\n", "0 0 0 3 7\n", "0 1 1\n"]}
11
[ "PYTHON3" ]
2
2
code_contests
1b3ab1c9255874e7c4c09e388d58598f
1291_E. Prefix Enlightenment
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1). You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≀ i_1 < i_2 < i_3 ≀ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = βˆ…. In one operation, you can choose one of these k subsets and switch the state of all lamps in it. It is guaranteed that, with the given subsets, it's possible to make all lamps be simultaneously on using this type of operation. Let m_i be the minimum number of operations you have to do in order to make the i first lamps be simultaneously on. Note that there is no condition upon the state of other lamps (between i+1 and n), they can be either off or on. You have to compute m_i for all 1 ≀ i ≀ n. Input The first line contains two integers n and k (1 ≀ n, k ≀ 3 β‹… 10^5). The second line contains a binary string of length n, representing the initial state of each lamp (the lamp i is off if s_i = 0, on if s_i = 1). The description of each one of the k subsets follows, in the following format: The first line of the description contains a single integer c (1 ≀ c ≀ n) β€” the number of elements in the subset. The second line of the description contains c distinct integers x_1, …, x_c (1 ≀ x_i ≀ n) β€” the elements of the subset. It is guaranteed that: * The intersection of any three subsets is empty; * It's possible to make all lamps be simultaneously on using some operations. Output You must output n lines. The i-th line should contain a single integer m_i β€” the minimum number of operations required to make the lamps 1 to i be simultaneously on. Examples Input 7 3 0011100 3 1 4 6 3 3 4 7 2 2 3 Output 1 2 3 3 3 3 3 Input 8 6 00110011 3 1 3 8 5 1 2 5 6 7 2 6 8 2 3 5 2 4 7 1 2 Output 1 1 1 1 1 1 4 4 Input 5 3 00011 3 1 2 3 1 4 3 3 4 5 Output 1 1 1 1 1 Input 19 5 1001001001100000110 2 2 3 2 5 6 2 8 9 5 12 13 14 15 16 1 19 Output 0 1 1 1 2 2 2 3 3 3 3 4 4 4 4 4 4 4 5 Note In the first example: * For i = 1, we can just apply one operation on A_1, the final states will be 1010110; * For i = 2, we can apply operations on A_1 and A_3, the final states will be 1100110; * For i β‰₯ 3, we can apply operations on A_1, A_2 and A_3, the final states will be 1111111. In the second example: * For i ≀ 6, we can just apply one operation on A_2, the final states will be 11111101; * For i β‰₯ 7, we can apply operations on A_1, A_3, A_4, A_6, the final states will be 11111111.
{"inputs": ["5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n", "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n", "7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n", "1 1\n1\n1\n1\n", "5 3\n00011\n3\n1 2 3\n1\n4\n3\n2 4 5\n", "1 1\n0\n1\n1\n", "1 0\n1\n1\n1\n", "8 6\n00100011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n", "5 3\n00011\n3\n1 2 3\n2\n4\n3\n2 4 5\n", "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 2\n", "5 3\n00011\n3\n1 2 3\n2\n4\n3\n1 4 5\n", "5 3\n00011\n3\n1 2 3\n1\n4\n2\n2 4 5\n", "5 3\n00011\n3\n1 2 3\n2\n2\n3\n2 4 5\n", "5 1\n00011\n3\n1 2 3\n2\n4\n3\n1 4 5\n", "5 3\n00011\n3\n1 2 3\n2\n2\n3\n0 4 5\n", "5 3\n00011\n3\n1 2 3\n2\n4\n3\n2 1 5\n", "5 1\n00011\n3\n1 2 3\n2\n4\n6\n1 4 5\n", "5 1\n00011\n3\n1 2 3\n2\n2\n3\n0 4 5\n", "1 0\n1\n1\n2\n", "5 1\n00011\n3\n1 2 3\n2\n4\n6\n1 4 4\n", "5 1\n00011\n3\n1 2 3\n4\n2\n3\n0 4 5\n", "5 1\n00011\n3\n1 2 3\n4\n1\n3\n0 4 5\n", "5 3\n00011\n3\n1 2 3\n1\n4\n0\n3 4 5\n", "5 1\n00011\n3\n1 2 3\n2\n4\n3\n2 4 5\n", "5 1\n00011\n3\n1 2 3\n2\n4\n3\n2 4 9\n", "1 0\n1\n1\n0\n", "5 3\n00011\n3\n1 2 3\n2\n4\n3\n2 1 2\n", "5 1\n00011\n3\n1 2 3\n2\n4\n6\n1 4 10\n", "1 0\n1\n1\n4\n", "5 1\n00011\n3\n1 2 3\n4\n2\n6\n0 4 5\n", "5 3\n00011\n3\n1 2 3\n1\n4\n0\n5 4 5\n", "5 1\n00011\n3\n1 2 3\n2\n4\n6\n2 4 9\n", "1 0\n1\n0\n0\n", "5 3\n00011\n3\n1 2 3\n2\n4\n4\n2 1 2\n", "5 1\n00011\n3\n1 2 3\n4\n2\n5\n0 4 5\n", "5 3\n00011\n3\n1 2 3\n1\n4\n0\n5 5 5\n", "5 1\n00011\n3\n1 2 3\n2\n4\n6\n2 0 9\n", "1 0\n1\n0\n-1\n", "5 1\n00011\n3\n1 2 3\n4\n2\n5\n0 4 0\n", "5 3\n00011\n3\n1 2 3\n1\n4\n0\n5 1 5\n", "5 1\n00011\n3\n1 2 3\n2\n4\n6\n0 0 9\n", "1 0\n1\n-1\n-1\n", "5 1\n00011\n3\n1 2 3\n5\n2\n5\n0 4 0\n", "5 1\n00011\n3\n1 2 3\n5\n2\n7\n0 4 0\n", "5 1\n00011\n3\n1 2 3\n5\n2\n7\n0 4 -1\n", "5 2\n00011\n3\n1 2 3\n1\n4\n3\n2 4 5\n", "5 1\n00011\n3\n1 2 3\n2\n4\n3\n1 8 5\n", "5 1\n00011\n3\n1 2 3\n2\n2\n3\n0 8 5\n", "5 1\n00011\n3\n1 2 3\n4\n4\n3\n0 4 5\n", "5 3\n00011\n3\n1 2 3\n1\n1\n0\n3 4 5\n", "5 1\n00011\n3\n1 2 3\n2\n6\n3\n2 4 9\n", "5 1\n00011\n3\n1 2 3\n2\n4\n6\n1 5 10\n", "5 3\n00011\n3\n1 2 3\n1\n1\n0\n5 5 5\n", "5 1\n00011\n3\n1 2 3\n2\n4\n6\n2 0 6\n", "5 1\n00011\n3\n1 2 3\n2\n3\n6\n0 0 9\n", "1 0\n1\n-1\n-2\n", "5 1\n00011\n3\n1 2 3\n5\n2\n6\n0 4 0\n"], "outputs": ["1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n1\n4\n4\n", "0\n1\n1\n1\n2\n2\n2\n3\n3\n3\n3\n4\n4\n4\n4\n4\n4\n4\n5\n", "1\n2\n3\n3\n3\n3\n3\n", "0\n", "1\n1\n1\n1\n1\n", "1\n", "0\n", "1\n1\n1\n2\n2\n2\n2\n2\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "0\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "0\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "0\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "0\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "0\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "0\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "1\n1\n1\n1\n1\n", "0\n", "1\n1\n1\n1\n1\n"]}
11
[ "PYTHON3" ]
2
2
code_contests
3f21abc4d2d4c7ede6c1748c7bc6230b
1311_F. Moving Points
There are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All n points move with the constant speed, the coordinate of the i-th point at the moment t (t can be non-integer) is calculated as x_i + t β‹… v_i. Consider two points i and j. Let d(i, j) be the minimum possible distance between these two points over any possible moments of time (even non-integer). It means that if two points i and j coincide at some moment, the value d(i, j) will be 0. Your task is to calculate the value βˆ‘_{1 ≀ i < j ≀ n} d(i, j) (the sum of minimum distances over all pairs of points). Input The first line of the input contains one integer n (2 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≀ x_i ≀ 10^8), where x_i is the initial coordinate of the i-th point. It is guaranteed that all x_i are distinct. The third line of the input contains n integers v_1, v_2, ..., v_n (-10^8 ≀ v_i ≀ 10^8), where v_i is the speed of the i-th point. Output Print one integer β€” the value βˆ‘_{1 ≀ i < j ≀ n} d(i, j) (the sum of minimum distances over all pairs of points). Examples Input 3 1 3 2 -100 2 3 Output 3 Input 5 2 1 4 3 5 2 2 2 3 4 Output 19 Input 2 2 1 -3 0 Output 0
{"inputs": ["3\n1 3 2\n-100 2 3\n", "2\n2 1\n-3 0\n", "5\n2 1 4 3 5\n2 2 2 3 4\n", "3\n1 3 2\n-100 2 6\n", "2\n2 1\n-4 0\n", "2\n0 1\n-4 0\n", "2\n0 2\n-4 0\n", "3\n1 5 2\n-167 2 6\n", "3\n1 3 2\n-75 1 0\n", "3\n1 7 2\n-255 0 6\n", "3\n1 3 8\n-75 1 0\n", "3\n1 3 8\n-75 1 1\n", "3\n0 4 8\n-75 1 1\n", "3\n0 4 8\n-75 1 0\n", "5\n2 1 4 3 5\n0 2 2 3 4\n", "3\n1 3 4\n-109 2 6\n", "3\n1 3 2\n-167 2 6\n", "3\n1 3 2\n-172 2 6\n", "3\n1 3 2\n-109 2 6\n", "3\n1 3 2\n-75 2 3\n", "2\n2 1\n-5 0\n", "3\n1 3 2\n-100 1 6\n", "2\n2 1\n-4 1\n", "3\n1 3 2\n-11 2 6\n", "2\n0 2\n-7 0\n", "3\n1 3 2\n-109 3 6\n", "3\n1 3 2\n-75 1 3\n", "2\n2 1\n-5 -1\n", "3\n1 3 2\n-189 1 6\n", "2\n0 1\n-4 1\n", "3\n1 5 2\n-255 2 6\n", "3\n0 3 2\n-11 2 6\n", "2\n0 2\n-7 1\n", "3\n1 3 2\n-75 1 2\n", "2\n0 2\n-4 1\n", "3\n1 5 2\n-255 0 6\n", "2\n0 2\n-7 2\n", "2\n0 1\n-7 1\n", "2\n0 2\n-10 2\n", "3\n1 3 4\n-75 1 0\n", "3\n1 7 2\n-215 0 6\n", "2\n1 2\n-10 2\n", "3\n1 7 2\n-215 0 9\n", "2\n1 3\n-10 2\n", "2\n1 3\n-5 2\n", "3\n1 4 8\n-75 1 1\n", "2\n2 3\n-5 2\n", "2\n2 3\n-10 2\n", "3\n1 3 2\n-100 2 10\n", "2\n1 2\n-4 0\n", "3\n1 3 2\n-167 0 6\n", "3\n1 3 2\n-172 4 6\n", "2\n0 4\n-4 0\n", "3\n1 3 2\n-82 2 3\n", "2\n3 1\n-5 -1\n", "3\n1 5 2\n-167 2 9\n", "3\n1 6 2\n-11 2 6\n", "2\n1 2\n-7 0\n", "3\n1 3 4\n-109 3 6\n"], "outputs": ["3\n", "0\n", "19\n", "3\n", "0\n", "1\n", "2\n", "5\n", "4\n", "7\n", "9\n", "14\n", "16\n", "12\n", "18\n", "6\n", "3\n", "3\n", "3\n", "3\n", "0\n", "3\n", "0\n", "3\n", "2\n", "3\n", "3\n", "0\n", "3\n", "1\n", "5\n", "5\n", "2\n", "3\n", "2\n", "5\n", "2\n", "1\n", "2\n", "5\n", "7\n", "1\n", "7\n", "2\n", "2\n", "14\n", "1\n", "1\n", "3\n", "1\n", "3\n", "3\n", "4\n", "3\n", "0\n", "5\n", "6\n", "1\n", "6\n"]}
12
[ "PYTHON3" ]
2
2
code_contests
README.md exists but content is empty.
Downloads last month
36