contestId
int64
0
1.01k
name
stringlengths
2
58
tags
sequencelengths
0
11
title
stringclasses
523 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
sequencelengths
0
7
demo-output
sequencelengths
0
7
note
stringlengths
0
5.24k
test_cases
listlengths
0
402
timeConsumedMillis
int64
0
8k
memoryConsumedBytes
int64
0
537M
score
float64
-1
3.99
__index_level_0__
int64
0
621k
69
Young Physicist
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β€” thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
62
0
0
109
955
Not simply beatiful strings
[ "implementation" ]
null
null
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others β€” a group of *b*-s), but cccc is not since in each possible consequent partition letters in these two groups coincide. You're given a string *s*. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string.
The only line contains *s* (1<=≀<=|*s*|<=≀<=105) consisting of lowercase latin letters.
Print Β«YesΒ» if the string can be split according to the criteria above or Β«NoΒ» otherwise. Each letter can be printed in arbitrary case.
[ "ababa\n", "zzcxx\n", "yeee\n" ]
[ "Yes\n", "Yes\n", "No\n" ]
In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable. There's no suitable partition in sample case three.
[ { "input": "ababa", "output": "Yes" }, { "input": "zzcxx", "output": "Yes" }, { "input": "yeee", "output": "No" }, { "input": "a", "output": "No" }, { "input": "bbab", "output": "No" }, { "input": "abcd", "output": "Yes" }, { "input": "abc", "output": "No" }, { "input": "abcdaaaa", "output": "Yes" }, { "input": "aaaaaaaaaaaaaaa", "output": "No" }, { "input": "adb", "output": "No" }, { "input": "dcccbad", "output": "Yes" }, { "input": "bcbccccccca", "output": "Yes" }, { "input": "abcdefgh", "output": "No" }, { "input": "aabcdef", "output": "No" }, { "input": "aabc", "output": "Yes" }, { "input": "ssab", "output": "Yes" }, { "input": "ccdd", "output": "Yes" }, { "input": "abcc", "output": "Yes" }, { "input": "ab", "output": "No" }, { "input": "abcde", "output": "No" }, { "input": "aa", "output": "No" }, { "input": "aaabbb", "output": "Yes" }, { "input": "bbbba", "output": "No" }, { "input": "abbbc", "output": "Yes" }, { "input": "baabaa", "output": "Yes" }, { "input": "abacabadde", "output": "No" }, { "input": "aabbcc", "output": "Yes" }, { "input": "abbc", "output": "Yes" }, { "input": "aaaaaaabbbbbbcder", "output": "No" }, { "input": "aabb", "output": "Yes" }, { "input": "aabbccddee", "output": "No" }, { "input": "abca", "output": "Yes" }, { "input": "aaabbbccc", "output": "Yes" } ]
155
7,270,400
3
110
732
Buy a Shovel
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≀<=*r*<=≀<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
The single line of input contains two integers *k* and *r* (1<=≀<=*k*<=≀<=1000, 1<=≀<=*r*<=≀<=9)Β β€” the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9Β·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2Β·15 = 30 burles. It is obvious that he can pay this sum without any change.
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", "output": "1" }, { "input": "1000 9", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "999 9", "output": "1" }, { "input": "999 8", "output": "2" }, { "input": "105 6", "output": "2" }, { "input": "403 9", "output": "3" }, { "input": "546 4", "output": "4" }, { "input": "228 9", "output": "5" }, { "input": "57 2", "output": "6" }, { "input": "437 9", "output": "7" }, { "input": "997 6", "output": "8" }, { "input": "109 1", "output": "9" }, { "input": "998 9", "output": "5" }, { "input": "4 2", "output": "3" }, { "input": "9 3", "output": "7" }, { "input": "8 2", "output": "4" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "7" }, { "input": "1 8", "output": "8" }, { "input": "100 3", "output": "1" }, { "input": "1000 2", "output": "1" }, { "input": "1000 4", "output": "1" }, { "input": "1000 5", "output": "1" }, { "input": "1000 6", "output": "1" }, { "input": "1000 7", "output": "1" }, { "input": "1000 8", "output": "1" }, { "input": "23 4", "output": "8" }, { "input": "33 1", "output": "7" }, { "input": "33 2", "output": "4" }, { "input": "666 5", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "5 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "12 4", "output": "2" }, { "input": "15 5", "output": "1" }, { "input": "2 5", "output": "5" }, { "input": "25 5", "output": "1" }, { "input": "2 9", "output": "5" }, { "input": "6 7", "output": "5" }, { "input": "8 9", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "4 7", "output": "5" }, { "input": "2 1", "output": "5" }, { "input": "261 1", "output": "1" } ]
31
0
0
111
519
A and B and Compilation Errors
[ "data structures", "implementation", "sortings" ]
null
null
A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake. However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared β€” the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change. Can you help B find out exactly what two errors he corrected?
The first line of the input contains integer *n* (3<=≀<=*n*<=≀<=105) β€” the initial number of compilation errors. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109) β€” the errors the compiler displayed for the first time. The third line contains *n*<=-<=1 space-separated integers *b*1,<=*b*2,<=...,<=*b**n*<=-<=1 β€” the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one. The fourth line contains *n*<=-<=2 space-separated integers *с*1,<=*с*2,<=...,<=*с**n*<=-<=2 β€” the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
[ "5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n", "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n" ]
[ "8\n123\n", "1\n3\n" ]
In the first test sample B first corrects the error number 8, then the error number 123. In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
[ { "input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7", "output": "8\n123" }, { "input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5", "output": "1\n3" }, { "input": "3\n1 2 3\n3 2\n2", "output": "1\n3" }, { "input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 388684428 9301599 656422756 784303821 460626451 277246428", "output": "25720377\n661369649" }, { "input": "3\n796067435 964699482 819602309\n964699482 796067435\n964699482", "output": "819602309\n796067435" }, { "input": "3\n374054998 726316780 902899520\n902899520 726316780\n726316780", "output": "374054998\n902899520" }, { "input": "3\n168638990 939116221 323703261\n168638990 323703261\n168638990", "output": "939116221\n323703261" }, { "input": "3\n77 77 77\n77 77\n77", "output": "77\n77" }, { "input": "3\n84 30 9\n9 84\n9", "output": "30\n84" }, { "input": "6\n5 4 3 3 5 5\n3 5 5 4 3\n3 5 4 3", "output": "5\n5" }, { "input": "4\n1 5 7 8\n1 5 7\n1 5", "output": "8\n7" } ]
2,000
9,420,800
0
112
584
Olesya and Rodion
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1.
The single line contains two numbers, *n* and *t* (1<=≀<=*n*<=≀<=100, 2<=≀<=*t*<=≀<=10) β€” the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, β€” the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input": "18 8", "output": "888888888888888888" }, { "input": "1 5", "output": "5" }, { "input": "1 10", "output": "-1" }, { "input": "100 5", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "10 2", "output": "2222222222" }, { "input": "18 10", "output": "111111111111111110" }, { "input": "1 9", "output": "9" }, { "input": "7 6", "output": "6666666" }, { "input": "4 4", "output": "4444" }, { "input": "14 7", "output": "77777777777777" }, { "input": "3 8", "output": "888" }, { "input": "1 3", "output": "3" }, { "input": "2 8", "output": "88" }, { "input": "3 8", "output": "888" }, { "input": "4 3", "output": "3333" }, { "input": "5 9", "output": "99999" }, { "input": "4 8", "output": "8888" }, { "input": "3 4", "output": "444" }, { "input": "9 4", "output": "444444444" }, { "input": "8 10", "output": "11111110" }, { "input": "1 6", "output": "6" }, { "input": "20 3", "output": "33333333333333333333" }, { "input": "15 10", "output": "111111111111110" }, { "input": "31 4", "output": "4444444444444444444444444444444" }, { "input": "18 9", "output": "999999999999999999" }, { "input": "72 4", "output": "444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "76 8", "output": "8888888888888888888888888888888888888888888888888888888888888888888888888888" }, { "input": "12 5", "output": "555555555555" }, { "input": "54 5", "output": "555555555555555555555555555555555555555555555555555555" }, { "input": "96 10", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "15 9", "output": "999999999999999" }, { "input": "100 2", "output": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" }, { "input": "99 3", "output": "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" }, { "input": "98 4", "output": "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "97 5", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "100 6", "output": "6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666" }, { "input": "99 7", "output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "98 8", "output": "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888" }, { "input": "97 9", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "100 10", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "3 10", "output": "110" }, { "input": "2 4", "output": "44" }, { "input": "2 10", "output": "10" }, { "input": "10 10", "output": "1111111110" }, { "input": "4 10", "output": "1110" }, { "input": "25 10", "output": "1111111111111111111111110" }, { "input": "50 10", "output": "11111111111111111111111111111111111111111111111110" }, { "input": "5 10", "output": "11110" }, { "input": "99 10", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "100 10", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "1 2", "output": "2" }, { "input": "20 10", "output": "11111111111111111110" }, { "input": "99 7", "output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "89 5", "output": "55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "6 10", "output": "111110" }, { "input": "3 8", "output": "888" }, { "input": "1 9", "output": "9" }, { "input": "1 4", "output": "4" }, { "input": "100 7", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" } ]
1,000
0
0
113
222
Shooshuns and Sequence
[ "brute force", "implementation" ]
null
null
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.
The first line contains two space-separated integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=105) β€” the sequence that the shooshuns found.
Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
[ "3 2\n3 1 1\n", "3 1\n3 1 1\n" ]
[ "1\n", "-1\n" ]
In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
[ { "input": "3 2\n3 1 1", "output": "1" }, { "input": "3 1\n3 1 1", "output": "-1" }, { "input": "1 1\n1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "2 1\n2 1", "output": "-1" }, { "input": "4 4\n1 2 3 4", "output": "3" }, { "input": "4 3\n1 2 3 4", "output": "-1" }, { "input": "5 3\n2 1 1 1 1", "output": "1" }, { "input": "5 3\n1 1 1 1 1", "output": "0" }, { "input": "5 5\n1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 1\n2 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 2\n2 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "10 2\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 3\n3 2 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10 1\n1 2 3 4 5 6 7 8 9 10", "output": "-1" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "20 10\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 11\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "10" }, { "input": "20 9\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "20 20\n20 1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10", "output": "19" } ]
62
0
0
114
851
Arpa and a research in Mexican wave
[ "implementation", "math" ]
null
null
Arpa is researching the Mexican wave. There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0. - At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-th spectator stands and the first spectator sits. - At time *k*<=+<=2, the (*k*<=+<=2)-th spectator stands and the second spectator sits. - ... - At time *n*, the *n*-th spectator stands and the (*n*<=-<=*k*)-th spectator sits. - At time *n*<=+<=1, the (*n*<=+<=1<=-<=*k*)-th spectator sits. - ... - At time *n*<=+<=*k*, the *n*-th spectator sits. Arpa wants to know how many spectators are standing at time *t*.
The first line contains three integers *n*, *k*, *t* (1<=≀<=*n*<=≀<=109, 1<=≀<=*k*<=≀<=*n*, 1<=≀<=*t*<=&lt;<=*n*<=+<=*k*).
Print single integer: how many spectators are standing at time *t*.
[ "10 5 3\n", "10 5 7\n", "10 5 12\n" ]
[ "3\n", "5\n", "3\n" ]
In the following a sitting spectator is represented as -, a standing spectator is represented as ^. - At *t* = 0  ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. - At *t* = 1  ^--------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 2  ^^-------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 3  ^^^------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 4  ^^^^------ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 5  ^^^^^----- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 6  -^^^^^---- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 7  --^^^^^--- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 8  ---^^^^^-- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 9  ----^^^^^- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 10 -----^^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 11 ------^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 12 -------^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 13 --------^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 14 ---------^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 15 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0.
[ { "input": "10 5 3", "output": "3" }, { "input": "10 5 7", "output": "5" }, { "input": "10 5 12", "output": "3" }, { "input": "840585600 770678331 788528791", "output": "770678331" }, { "input": "25462281 23343504 8024619", "output": "8024619" }, { "input": "723717988 205757169 291917494", "output": "205757169" }, { "input": "27462087 20831796 15492397", "output": "15492397" }, { "input": "966696824 346707476 1196846860", "output": "116557440" }, { "input": "290274403 41153108 327683325", "output": "3744186" }, { "input": "170963478 151220598 222269210", "output": "99914866" }, { "input": "14264008 309456 11132789", "output": "309456" }, { "input": "886869816 281212106 52891064", "output": "52891064" }, { "input": "330543750 243917820 205522400", "output": "205522400" }, { "input": "457658451 18625039 157624558", "output": "18625039" }, { "input": "385908940 143313325 509731380", "output": "19490885" }, { "input": "241227633 220621961 10025257", "output": "10025257" }, { "input": "474139818 268918981 388282504", "output": "268918981" }, { "input": "25963410 3071034 820199", "output": "820199" }, { "input": "656346757 647995766 75748423", "output": "75748423" }, { "input": "588568132 411878522 521753621", "output": "411878522" }, { "input": "735788762 355228487 139602545", "output": "139602545" }, { "input": "860798593 463398487 506871376", "output": "463398487" }, { "input": "362624055 110824996 194551217", "output": "110824996" }, { "input": "211691721 195866131 313244576", "output": "94313276" }, { "input": "45661815 26072719 9643822", "output": "9643822" }, { "input": "757183104 590795077 709609355", "output": "590795077" }, { "input": "418386749 1915035 197248338", "output": "1915035" }, { "input": "763782282 297277890 246562421", "output": "246562421" }, { "input": "893323188 617630677 607049638", "output": "607049638" }, { "input": "506708261 356545583 296093684", "output": "296093684" }, { "input": "984295813 427551190 84113823", "output": "84113823" }, { "input": "774984967 61373612 96603505", "output": "61373612" }, { "input": "774578969 342441237 91492393", "output": "91492393" }, { "input": "76495801 8780305 56447339", "output": "8780305" }, { "input": "48538385 582843 16805978", "output": "582843" }, { "input": "325794610 238970909 553089099", "output": "11676420" }, { "input": "834925315 316928679 711068031", "output": "316928679" }, { "input": "932182199 454838315 267066713", "output": "267066713" }, { "input": "627793782 552043394 67061810", "output": "67061810" }, { "input": "24317170 17881607 218412", "output": "218412" }, { "input": "1000000000 1000 1", "output": "1" }, { "input": "1000000000 1000 2", "output": "2" }, { "input": "1000000000 1 1000", "output": "1" }, { "input": "100 100 100", "output": "100" }, { "input": "100 100 99", "output": "99" }, { "input": "100 100 101", "output": "99" }, { "input": "100 100 199", "output": "1" }, { "input": "1000000000 1000000000 1999999999", "output": "1" }, { "input": "10 5 5", "output": "5" }, { "input": "5 3 5", "output": "3" }, { "input": "10 3 3", "output": "3" }, { "input": "10 5 6", "output": "5" }, { "input": "3 2 4", "output": "1" }, { "input": "10 5 14", "output": "1" }, { "input": "6 1 4", "output": "1" }, { "input": "10 10 19", "output": "1" }, { "input": "10 4 11", "output": "3" }, { "input": "2 2 3", "output": "1" }, { "input": "10 5 11", "output": "4" }, { "input": "600 200 700", "output": "100" }, { "input": "2000 1000 2001", "output": "999" }, { "input": "1000 1000 1001", "output": "999" }, { "input": "5 4 6", "output": "3" }, { "input": "2 1 2", "output": "1" }, { "input": "10 3 10", "output": "3" }, { "input": "15 10 10", "output": "10" }, { "input": "10 5 13", "output": "2" }, { "input": "2 2 2", "output": "2" }, { "input": "5 5 6", "output": "4" }, { "input": "10 6 12", "output": "4" }, { "input": "7 5 8", "output": "4" }, { "input": "10 4 9", "output": "4" }, { "input": "9 2 6", "output": "2" }, { "input": "5 2 6", "output": "1" }, { "input": "6 2 6", "output": "2" }, { "input": "5 5 8", "output": "2" }, { "input": "3 3 5", "output": "1" }, { "input": "10 2 5", "output": "2" }, { "input": "5 3 7", "output": "1" }, { "input": "5 4 8", "output": "1" }, { "input": "10 6 11", "output": "5" }, { "input": "5 3 6", "output": "2" }, { "input": "10 6 14", "output": "2" }, { "input": "10 10 10", "output": "10" }, { "input": "1000000000 1 1000000000", "output": "1" }, { "input": "20 4 22", "output": "2" }, { "input": "5 4 4", "output": "4" }, { "input": "4 3 6", "output": "1" }, { "input": "12 8 18", "output": "2" }, { "input": "10 5 10", "output": "5" }, { "input": "100 50 149", "output": "1" }, { "input": "4 4 4", "output": "4" }, { "input": "7 6 9", "output": "4" }, { "input": "16 10 21", "output": "5" }, { "input": "10 2 11", "output": "1" }, { "input": "600 200 500", "output": "200" }, { "input": "100 30 102", "output": "28" }, { "input": "10 10 18", "output": "2" }, { "input": "15 3 10", "output": "3" }, { "input": "1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "5 5 5", "output": "5" }, { "input": "10 3 12", "output": "1" }, { "input": "747 457 789", "output": "415" }, { "input": "5 4 7", "output": "2" }, { "input": "15 5 11", "output": "5" }, { "input": "3 2 2", "output": "2" }, { "input": "7 6 8", "output": "5" }, { "input": "7 4 8", "output": "3" }, { "input": "10 4 13", "output": "1" }, { "input": "10 3 9", "output": "3" }, { "input": "20 2 21", "output": "1" }, { "input": "6 5 9", "output": "2" }, { "input": "10 9 18", "output": "1" }, { "input": "12 4 9", "output": "4" }, { "input": "10 7 15", "output": "2" }, { "input": "999999999 999999998 1500000000", "output": "499999997" }, { "input": "20 5 20", "output": "5" }, { "input": "4745 4574 4757", "output": "4562" }, { "input": "10 7 12", "output": "5" }, { "input": "17 15 18", "output": "14" }, { "input": "3 1 3", "output": "1" }, { "input": "100 3 7", "output": "3" }, { "input": "6 2 7", "output": "1" }, { "input": "8 5 10", "output": "3" }, { "input": "3 3 3", "output": "3" }, { "input": "9 5 10", "output": "4" }, { "input": "10 6 13", "output": "3" }, { "input": "13 10 14", "output": "9" }, { "input": "13 12 15", "output": "10" }, { "input": "10 4 12", "output": "2" }, { "input": "41 3 3", "output": "3" }, { "input": "1000000000 1000000000 1400000000", "output": "600000000" }, { "input": "10 3 11", "output": "2" }, { "input": "12 7 18", "output": "1" }, { "input": "15 3 17", "output": "1" }, { "input": "10 2 8", "output": "2" }, { "input": "1000000000 1000 1000000999", "output": "1" }, { "input": "5 5 9", "output": "1" }, { "input": "100 3 6", "output": "3" }, { "input": "100 5 50", "output": "5" }, { "input": "10000 10 10000", "output": "10" }, { "input": "1 1 1", "output": "1" }, { "input": "6 4 4", "output": "4" }, { "input": "9979797 555554 10101010", "output": "434341" }, { "input": "13 5 12", "output": "5" }, { "input": "9 4 10", "output": "3" }, { "input": "7 5 10", "output": "2" }, { "input": "100000000 10000000 100005000", "output": "9995000" }, { "input": "100000 50000 100001", "output": "49999" }, { "input": "15 10 20", "output": "5" }, { "input": "4 4 5", "output": "3" }, { "input": "5 3 3", "output": "3" }, { "input": "30 5 30", "output": "5" }, { "input": "200000 10 200005", "output": "5" }, { "input": "10 9 12", "output": "7" }, { "input": "10 6 15", "output": "1" }, { "input": "1000000000 10 1000000000", "output": "10" }, { "input": "7 5 11", "output": "1" }, { "input": "9 4 4", "output": "4" }, { "input": "14 3 15", "output": "2" }, { "input": "1000000000 100000000 1000000000", "output": "100000000" }, { "input": "40 10 22", "output": "10" }, { "input": "50 10 51", "output": "9" }, { "input": "999999997 999999995 1999999991", "output": "1" }, { "input": "92 79 144", "output": "27" }, { "input": "8 4 4", "output": "4" } ]
77
2,764,800
-1
115
686
Free Ice Cream
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue). If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress. Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
The first line contains two space-separated integers *n* and *x* (1<=≀<=*n*<=≀<=1000, 0<=≀<=*x*<=≀<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≀<=*d**i*<=≀<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Print two space-separated integersΒ β€” number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining.
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { "input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46", "output": "46 0" }, { "input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100", "output": "700 0" }, { "input": "1 0\n- 526403222", "output": "0 1" }, { "input": "1 897986543\n- 371188251", "output": "526798292 0" }, { "input": "1 0\n+ 1", "output": "1 0" }, { "input": "1 0\n- 1", "output": "0 1" }, { "input": "1 10\n+ 10", "output": "20 0" }, { "input": "1 3\n- 5", "output": "3 1" }, { "input": "1 0\n- 5", "output": "0 1" }, { "input": "1 0\n+ 5", "output": "5 0" } ]
156
1,433,600
3
117
822
I'm bored with life
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
The first and single line contains two integers *A* and *B* (1<=≀<=*A*,<=*B*<=≀<=109,<=*min*(*A*,<=*B*)<=≀<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1Β·2Β·3Β·4 = 24. 3! = 1Β·2Β·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "output": "6" }, { "input": "11 562314608", "output": "39916800" }, { "input": "3 990639260", "output": "6" }, { "input": "11 859155400", "output": "39916800" }, { "input": "1 1", "output": "1" }, { "input": "5 3", "output": "6" }, { "input": "1 4", "output": "1" }, { "input": "5 4", "output": "24" }, { "input": "1 12", "output": "1" }, { "input": "9 7", "output": "5040" }, { "input": "2 3", "output": "2" }, { "input": "6 11", "output": "720" }, { "input": "6 7", "output": "720" }, { "input": "11 11", "output": "39916800" }, { "input": "4 999832660", "output": "24" }, { "input": "7 999228288", "output": "5040" }, { "input": "11 999257105", "output": "39916800" }, { "input": "11 999286606", "output": "39916800" }, { "input": "3 999279109", "output": "6" }, { "input": "999632727 11", "output": "39916800" }, { "input": "999625230 7", "output": "5040" }, { "input": "999617047 3", "output": "6" }, { "input": "999646548 7", "output": "5040" }, { "input": "999639051 3", "output": "6" }, { "input": "12 12", "output": "479001600" }, { "input": "12 1", "output": "1" }, { "input": "1213 5", "output": "120" }, { "input": "8 9", "output": "40320" }, { "input": "12 9", "output": "362880" }, { "input": "12 1000000000", "output": "479001600" }, { "input": "1000000000 1", "output": "1" }, { "input": "12 13", "output": "479001600" }, { "input": "2 29845", "output": "2" }, { "input": "10 21", "output": "3628800" }, { "input": "12 20", "output": "479001600" }, { "input": "15 12", "output": "479001600" }, { "input": "1 1", "output": "1" }, { "input": "1000000000 12", "output": "479001600" }, { "input": "11 30", "output": "39916800" }, { "input": "17 12", "output": "479001600" }, { "input": "4 19", "output": "24" }, { "input": "12 15", "output": "479001600" }, { "input": "20 6", "output": "720" }, { "input": "10 20", "output": "3628800" }, { "input": "10 10", "output": "3628800" }, { "input": "22 12", "output": "479001600" }, { "input": "20 12", "output": "479001600" }, { "input": "12 23", "output": "479001600" }, { "input": "12 22", "output": "479001600" }, { "input": "18 3", "output": "6" }, { "input": "14 10", "output": "3628800" }, { "input": "14 12", "output": "479001600" }, { "input": "8 3", "output": "6" }, { "input": "5 5", "output": "120" } ]
46
0
3
118
75
Life Without Zeros
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≀<=*a*,<=*b*<=≀<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }, { "input": "693\n970", "output": "NO" }, { "input": "981\n1", "output": "YES" }, { "input": "352\n276", "output": "YES" }, { "input": "164\n691", "output": "YES" }, { "input": "110036\n43", "output": "YES" }, { "input": "100\n1000", "output": "NO" }, { "input": "1000000000\n1000000000", "output": "YES" }, { "input": "999999999\n999999999", "output": "YES" }, { "input": "6\n4", "output": "NO" }, { "input": "123456\n876543", "output": "YES" }, { "input": "1234567\n9876543", "output": "NO" }, { "input": "1111111\n1119111", "output": "NO" }, { "input": "10502405\n40403403", "output": "YES" }, { "input": "1\n1", "output": "YES" }, { "input": "5\n4", "output": "YES" }, { "input": "1\n6", "output": "YES" }, { "input": "40\n17", "output": "NO" }, { "input": "35\n81", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "2081\n7450", "output": "NO" }, { "input": "84355694\n373629503", "output": "NO" }, { "input": "885992048\n510468672", "output": "NO" }, { "input": "540144752\n647307841", "output": "NO" }, { "input": "341781108\n784147010", "output": "NO" }, { "input": "960440938\n572334653", "output": "NO" }, { "input": "657414510\n768771903", "output": "NO" }, { "input": "501871728\n725074574", "output": "NO" }, { "input": "968\n851", "output": "YES" }, { "input": "943\n939", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "611\n41", "output": "YES" }, { "input": "737\n289", "output": "NO" }, { "input": "168\n571", "output": "YES" }, { "input": "868\n463", "output": "YES" }, { "input": "815732007\n913882008", "output": "NO" }, { "input": "459039901\n453033850", "output": "NO" }, { "input": "975305404\n484601256", "output": "NO" } ]
92
0
3.977
120
675
Infinite Sequence
[ "math" ]
null
null
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help.
The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≀<=*a*,<=*b*,<=*c*<=≀<=109)Β β€” the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes).
[ "1 7 3\n", "10 10 0\n", "1 -4 5\n", "0 60 50\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. In the third sample all elements of the sequence are greater than Vasya's favorite integer. In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
[ { "input": "1 7 3", "output": "YES" }, { "input": "10 10 0", "output": "YES" }, { "input": "1 -4 5", "output": "NO" }, { "input": "0 60 50", "output": "NO" }, { "input": "1 -4 -5", "output": "YES" }, { "input": "0 1 0", "output": "NO" }, { "input": "10 10 42", "output": "YES" }, { "input": "-1000000000 1000000000 -1", "output": "NO" }, { "input": "10 16 4", "output": "NO" }, { "input": "-1000000000 1000000000 5", "output": "YES" }, { "input": "1000000000 -1000000000 5", "output": "NO" }, { "input": "1000000000 -1000000000 0", "output": "NO" }, { "input": "1000000000 1000000000 0", "output": "YES" }, { "input": "115078364 -899474523 -1", "output": "YES" }, { "input": "-245436499 416383245 992", "output": "YES" }, { "input": "-719636354 536952440 2", "output": "YES" }, { "input": "-198350539 963391024 68337739", "output": "YES" }, { "input": "-652811055 875986516 1091", "output": "YES" }, { "input": "119057893 -516914539 -39748277", "output": "YES" }, { "input": "989140430 731276607 -36837689", "output": "YES" }, { "input": "677168390 494583489 -985071853", "output": "NO" }, { "input": "58090193 777423708 395693923", "output": "NO" }, { "input": "479823846 -403424770 -653472589", "output": "NO" }, { "input": "-52536829 -132023273 -736287999", "output": "NO" }, { "input": "-198893776 740026818 -547885271", "output": "NO" }, { "input": "-2 -2 -2", "output": "YES" }, { "input": "-2 -2 -1", "output": "YES" }, { "input": "-2 -2 0", "output": "YES" }, { "input": "-2 -2 1", "output": "YES" }, { "input": "-2 -2 2", "output": "YES" }, { "input": "-2 -1 -2", "output": "NO" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "-2 -1 0", "output": "NO" }, { "input": "-2 -1 1", "output": "YES" }, { "input": "-2 -1 2", "output": "NO" }, { "input": "-2 0 -2", "output": "NO" }, { "input": "-2 0 -1", "output": "NO" }, { "input": "-2 0 0", "output": "NO" }, { "input": "-2 0 1", "output": "YES" }, { "input": "-2 0 2", "output": "YES" }, { "input": "-2 1 -2", "output": "NO" }, { "input": "-2 1 -1", "output": "NO" }, { "input": "-2 1 0", "output": "NO" }, { "input": "-2 1 1", "output": "YES" }, { "input": "-2 1 2", "output": "NO" }, { "input": "-2 2 -2", "output": "NO" }, { "input": "-2 2 -1", "output": "NO" }, { "input": "-2 2 0", "output": "NO" }, { "input": "-2 2 1", "output": "YES" }, { "input": "-2 2 2", "output": "YES" }, { "input": "-1 -2 -2", "output": "NO" }, { "input": "-1 -2 -1", "output": "YES" }, { "input": "-1 -2 0", "output": "NO" }, { "input": "-1 -2 1", "output": "NO" }, { "input": "-1 -2 2", "output": "NO" }, { "input": "-1 -1 -2", "output": "YES" }, { "input": "-1 -1 -1", "output": "YES" }, { "input": "-1 -1 0", "output": "YES" }, { "input": "-1 -1 1", "output": "YES" }, { "input": "-1 -1 2", "output": "YES" }, { "input": "-1 0 -2", "output": "NO" }, { "input": "-1 0 -1", "output": "NO" }, { "input": "-1 0 0", "output": "NO" }, { "input": "-1 0 1", "output": "YES" }, { "input": "-1 0 2", "output": "NO" }, { "input": "-1 1 -2", "output": "NO" }, { "input": "-1 1 -1", "output": "NO" }, { "input": "-1 1 0", "output": "NO" }, { "input": "-1 1 1", "output": "YES" }, { "input": "-1 1 2", "output": "YES" }, { "input": "-1 2 -2", "output": "NO" }, { "input": "-1 2 -1", "output": "NO" }, { "input": "-1 2 0", "output": "NO" }, { "input": "-1 2 1", "output": "YES" }, { "input": "-1 2 2", "output": "NO" }, { "input": "0 -2 -2", "output": "YES" }, { "input": "0 -2 -1", "output": "YES" }, { "input": "0 -2 0", "output": "NO" }, { "input": "0 -2 1", "output": "NO" }, { "input": "0 -2 2", "output": "NO" }, { "input": "0 -1 -2", "output": "NO" }, { "input": "0 -1 -1", "output": "YES" }, { "input": "0 -1 0", "output": "NO" }, { "input": "0 -1 1", "output": "NO" }, { "input": "0 -1 2", "output": "NO" }, { "input": "0 0 -2", "output": "YES" }, { "input": "0 0 -1", "output": "YES" }, { "input": "0 0 0", "output": "YES" }, { "input": "0 0 1", "output": "YES" }, { "input": "0 0 2", "output": "YES" }, { "input": "0 1 -2", "output": "NO" }, { "input": "0 1 -1", "output": "NO" }, { "input": "0 1 0", "output": "NO" }, { "input": "0 1 1", "output": "YES" }, { "input": "0 1 2", "output": "NO" }, { "input": "0 2 -2", "output": "NO" }, { "input": "0 2 -1", "output": "NO" }, { "input": "0 2 0", "output": "NO" }, { "input": "0 2 1", "output": "YES" }, { "input": "0 2 2", "output": "YES" }, { "input": "1 -2 -2", "output": "NO" }, { "input": "1 -2 -1", "output": "YES" }, { "input": "1 -2 0", "output": "NO" }, { "input": "1 -2 1", "output": "NO" }, { "input": "1 -2 2", "output": "NO" }, { "input": "1 -1 -2", "output": "YES" }, { "input": "1 -1 -1", "output": "YES" }, { "input": "1 -1 0", "output": "NO" }, { "input": "1 -1 1", "output": "NO" }, { "input": "1 -1 2", "output": "NO" }, { "input": "1 0 -2", "output": "NO" }, { "input": "1 0 -1", "output": "YES" }, { "input": "1 0 0", "output": "NO" }, { "input": "1 0 1", "output": "NO" }, { "input": "1 0 2", "output": "NO" }, { "input": "1 1 -2", "output": "YES" }, { "input": "1 1 -1", "output": "YES" }, { "input": "1 1 0", "output": "YES" }, { "input": "1 1 1", "output": "YES" }, { "input": "1 1 2", "output": "YES" }, { "input": "1 2 -2", "output": "NO" }, { "input": "1 2 -1", "output": "NO" }, { "input": "1 2 0", "output": "NO" }, { "input": "1 2 1", "output": "YES" }, { "input": "1 2 2", "output": "NO" }, { "input": "2 -2 -2", "output": "YES" }, { "input": "2 -2 -1", "output": "YES" }, { "input": "2 -2 0", "output": "NO" }, { "input": "2 -2 1", "output": "NO" }, { "input": "2 -2 2", "output": "NO" }, { "input": "2 -1 -2", "output": "NO" }, { "input": "2 -1 -1", "output": "YES" }, { "input": "2 -1 0", "output": "NO" }, { "input": "2 -1 1", "output": "NO" }, { "input": "2 -1 2", "output": "NO" }, { "input": "2 0 -2", "output": "YES" }, { "input": "2 0 -1", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "2 0 1", "output": "NO" }, { "input": "2 0 2", "output": "NO" }, { "input": "2 1 -2", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "2 1 0", "output": "NO" }, { "input": "2 1 1", "output": "NO" }, { "input": "2 1 2", "output": "NO" }, { "input": "2 2 -2", "output": "YES" }, { "input": "2 2 -1", "output": "YES" }, { "input": "2 2 0", "output": "YES" }, { "input": "2 2 1", "output": "YES" }, { "input": "2 2 2", "output": "YES" }, { "input": "-1000000000 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 2", "output": "YES" }, { "input": "1000000000 -1000000000 -1", "output": "YES" }, { "input": "5 2 3", "output": "NO" }, { "input": "2 1 -1", "output": "YES" }, { "input": "3 2 1", "output": "NO" }, { "input": "0 -5 -3", "output": "NO" }, { "input": "2 5 5", "output": "NO" }, { "input": "0 10 1", "output": "YES" }, { "input": "15 5 -5", "output": "YES" }, { "input": "2 1 1", "output": "NO" }, { "input": "20 10 0", "output": "NO" }, { "input": "20 15 5", "output": "NO" }, { "input": "1 6 1", "output": "YES" }, { "input": "1000000000 0 -1000000000", "output": "YES" }, { "input": "1 1 -5", "output": "YES" }, { "input": "4 6 1", "output": "YES" }, { "input": "-5 -10 -5", "output": "YES" }, { "input": "2 0 0", "output": "NO" }, { "input": "10 9 -1", "output": "YES" }, { "input": "-2 -1 -1", "output": "NO" }, { "input": "1 13 3", "output": "YES" }, { "input": "2 3 0", "output": "NO" }, { "input": "1 1 -1", "output": "YES" }, { "input": "5 -10 -5", "output": "YES" }, { "input": "5 3 1", "output": "NO" }, { "input": "1 1000000000 1", "output": "YES" }, { "input": "-1000000000 1000000000 1000000000", "output": "YES" } ]
0
0
-1
121
805
3-palindrome
[ "constructive algorithms" ]
null
null
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
The first line contains single integer *n* (1<=≀<=*n*<=≀<=2Β·105)Β β€” the length of the string.
Print the string that satisfies all the constraints. If there are multiple answers, print any of them.
[ "2\n", "3\n" ]
[ "aa\n", "bba\n" ]
A palindrome is a sequence of characters which reads the same backward and forward.
[ { "input": "2", "output": "aa" }, { "input": "3", "output": "aab" }, { "input": "38", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa" }, { "input": "47", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "59", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "67", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "77", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "89", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "98", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaa" }, { "input": "109", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "117", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba" }, { "input": "1", "output": "a" }, { "input": "200000", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "100000", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "143670", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "104217", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "17879", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "131809", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "140873", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "77859", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "153022", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "179227", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "182801", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "5188", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "86539", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "12802", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "120289", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "132866", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "133377", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "31775", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "160397", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "161415", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "163623", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "22942", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "134767", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "52257", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "64905", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "183758", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "60131", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "146883", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..." }, { "input": "6", "output": "aabbaa" }, { "input": "4", "output": "aabb" } ]
46
0
0
122
25
IQ test
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≀<=*n*<=≀<=100) β€” amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
60
0
0
123
606
Magic Spheres
[ "implementation" ]
null
null
Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible, in multiple actions)?
The first line of the input contains three integers *a*, *b* and *c* (0<=≀<=*a*,<=*b*,<=*c*<=≀<=1<=000<=000)Β β€” the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, *x*, *y* and *z* (0<=≀<=*x*,<=*y*,<=*z*<=≀<=1<=000<=000)Β β€” the number of blue, violet and orange spheres that he needs to get.
If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".
[ "4 4 0\n2 1 2\n", "5 6 1\n2 7 2\n", "3 3 3\n2 2 2\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs.
[ { "input": "4 4 0\n2 1 2", "output": "Yes" }, { "input": "5 6 1\n2 7 2", "output": "No" }, { "input": "3 3 3\n2 2 2", "output": "Yes" }, { "input": "0 0 0\n0 0 0", "output": "Yes" }, { "input": "0 0 0\n0 0 1", "output": "No" }, { "input": "0 1 0\n0 0 0", "output": "Yes" }, { "input": "1 0 0\n1 0 0", "output": "Yes" }, { "input": "2 2 1\n1 1 2", "output": "No" }, { "input": "1 3 1\n2 1 1", "output": "Yes" }, { "input": "1000000 1000000 1000000\n1000000 1000000 1000000", "output": "Yes" }, { "input": "1000000 500000 500000\n0 750000 750000", "output": "Yes" }, { "input": "500000 1000000 500000\n750001 0 750000", "output": "No" }, { "input": "499999 500000 1000000\n750000 750000 0", "output": "No" }, { "input": "500000 500000 0\n0 0 500000", "output": "Yes" }, { "input": "0 500001 499999\n500000 0 0", "output": "No" }, { "input": "1000000 500000 1000000\n500000 1000000 500000", "output": "Yes" }, { "input": "1000000 1000000 499999\n500000 500000 1000000", "output": "No" }, { "input": "500000 1000000 1000000\n1000000 500001 500000", "output": "No" }, { "input": "1000000 500000 500000\n0 1000000 500000", "output": "Yes" }, { "input": "500000 500000 1000000\n500001 1000000 0", "output": "No" }, { "input": "500000 999999 500000\n1000000 0 500000", "output": "No" }, { "input": "4 0 3\n2 2 1", "output": "Yes" }, { "input": "0 2 4\n2 0 2", "output": "Yes" }, { "input": "3 1 0\n1 1 1", "output": "Yes" }, { "input": "4 4 1\n1 3 2", "output": "Yes" }, { "input": "1 2 4\n2 1 3", "output": "No" }, { "input": "1 1 0\n0 0 1", "output": "No" }, { "input": "4 0 0\n0 1 1", "output": "Yes" }, { "input": "0 3 0\n1 0 1", "output": "No" }, { "input": "0 0 3\n1 0 1", "output": "Yes" }, { "input": "1 12 1\n4 0 4", "output": "Yes" }, { "input": "4 0 4\n1 2 1", "output": "Yes" }, { "input": "4 4 0\n1 1 3", "output": "No" }, { "input": "0 9 0\n2 2 2", "output": "No" }, { "input": "0 10 0\n2 2 2", "output": "Yes" }, { "input": "9 0 9\n0 8 0", "output": "Yes" }, { "input": "0 9 9\n9 0 0", "output": "No" }, { "input": "9 10 0\n0 0 9", "output": "Yes" }, { "input": "10 0 9\n0 10 0", "output": "No" }, { "input": "0 10 10\n10 0 0", "output": "Yes" }, { "input": "10 10 0\n0 0 11", "output": "No" }, { "input": "307075 152060 414033\n381653 222949 123101", "output": "No" }, { "input": "569950 228830 153718\n162186 357079 229352", "output": "No" }, { "input": "149416 303568 749016\n238307 493997 190377", "output": "No" }, { "input": "438332 298094 225324\n194220 400244 245231", "output": "No" }, { "input": "293792 300060 511272\n400687 382150 133304", "output": "No" }, { "input": "295449 518151 368838\n382897 137148 471892", "output": "No" }, { "input": "191789 291147 691092\n324321 416045 176232", "output": "Yes" }, { "input": "286845 704749 266526\n392296 104421 461239", "output": "Yes" }, { "input": "135522 188282 377041\n245719 212473 108265", "output": "Yes" }, { "input": "404239 359124 133292\n180069 184791 332544", "output": "No" }, { "input": "191906 624432 244408\n340002 367217 205432", "output": "No" }, { "input": "275980 429361 101824\n274288 302579 166062", "output": "No" }, { "input": "136092 364927 395302\n149173 343146 390922", "output": "No" }, { "input": "613852 334661 146012\n363786 326286 275233", "output": "No" }, { "input": "348369 104625 525203\n285621 215396 366411", "output": "No" }, { "input": "225307 153572 114545\n154753 153282 149967", "output": "Yes" }, { "input": "438576 124465 629784\n375118 276028 390116", "output": "Yes" }, { "input": "447521 327510 158732\n395759 178458 259139", "output": "Yes" }, { "input": "8 5 5\n5 5 5", "output": "Yes" }, { "input": "100 100 100\n1 1 1", "output": "Yes" }, { "input": "100 100 100\n0 0 0", "output": "Yes" }, { "input": "3 2 3\n2 3 2", "output": "No" }, { "input": "5 4 3\n2 2 2", "output": "Yes" }, { "input": "14 9 8\n12 5 10", "output": "Yes" }, { "input": "10 10 10\n1 1 1", "output": "Yes" }, { "input": "6 3 3\n3 3 3", "output": "Yes" }, { "input": "10 0 4\n2 4 2", "output": "Yes" }, { "input": "100 100 100\n2 2 2", "output": "Yes" }, { "input": "4 6 0\n2 1 2", "output": "Yes" }, { "input": "4 6 3\n4 2 3", "output": "Yes" }, { "input": "5 5 5\n1 1 1", "output": "Yes" }, { "input": "41 17 34\n0 19 24", "output": "Yes" }, { "input": "8 8 8\n3 3 3", "output": "Yes" }, { "input": "7 7 1\n1 1 2", "output": "Yes" }, { "input": "6 6 0\n2 2 2", "output": "Yes" }, { "input": "5 5 5\n2 2 2", "output": "Yes" }, { "input": "400 400 400\n1 1 1", "output": "Yes" }, { "input": "4 4 4\n2 2 2", "output": "Yes" } ]
61
0
0
124
58
Chat room
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
62
0
3.969
125
166
Rank List
[ "binary search", "implementation", "sortings" ]
null
null
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place. You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a*<=&gt;<=*p**b*, or *p**a*<==<=*p**b* and *t**a*<=&lt;<=*t**b*. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y*<=+<=1, *y*<=+<=2, ..., *y*<=+<=*x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y*<=+<=*x*<=+<=1-th place. Your task is to count what number of teams from the given list shared the *k*-th place.
The first line contains two integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≀<=*p**i*,<=*t**i*<=≀<=50) β€” the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces.
In the only line print the sought number of teams that got the *k*-th place in the final results' table.
[ "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n" ]
[ "3\n", "4\n" ]
The final results' table for the first sample is: - 1-3 places β€” 4 solved problems, the penalty time equals 10 - 4 place β€” 3 solved problems, the penalty time equals 20 - 5-6 places β€” 2 solved problems, the penalty time equals 1 - 7 place β€” 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams. The final table for the second sample is: - 1 place β€” 5 solved problems, the penalty time equals 3 - 2-5 places β€” 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.
[ { "input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "output": "3" }, { "input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1", "output": "4" }, { "input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2", "output": "2" }, { "input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5", "output": "1" }, { "input": "5 5\n3 1\n10 2\n2 2\n1 10\n10 2", "output": "1" }, { "input": "3 2\n3 3\n3 3\n3 3", "output": "3" }, { "input": "4 3\n10 3\n6 10\n5 2\n5 2", "output": "2" }, { "input": "5 3\n10 10\n10 10\n1 1\n10 10\n4 3", "output": "3" }, { "input": "3 1\n2 1\n1 1\n1 2", "output": "1" }, { "input": "1 1\n28 28", "output": "1" }, { "input": "2 2\n1 2\n1 2", "output": "2" }, { "input": "5 3\n2 3\n4 2\n5 3\n2 4\n3 5", "output": "1" }, { "input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8", "output": "1" }, { "input": "50 6\n11 20\n18 13\n1 13\n3 11\n4 17\n15 10\n15 8\n9 16\n11 17\n16 3\n3 20\n14 13\n12 15\n9 10\n14 2\n12 12\n13 17\n6 10\n20 9\n2 8\n13 7\n7 20\n15 3\n1 20\n2 13\n2 5\n14 7\n10 13\n15 12\n15 5\n17 6\n9 11\n18 5\n10 1\n15 14\n3 16\n6 12\n4 1\n14 9\n7 14\n8 17\n17 13\n4 6\n19 16\n5 6\n3 15\n4 19\n15 20\n2 10\n20 10", "output": "1" }, { "input": "50 12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "50" }, { "input": "50 28\n2 2\n1 1\n2 1\n1 2\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n2 2\n2 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n2 2\n2 1\n2 1\n2 2\n1 2\n1 2\n1 2\n1 1\n2 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n2 1\n1 1\n2 2\n2 2\n2 2\n2 2", "output": "13" }, { "input": "50 40\n2 3\n3 1\n2 1\n2 1\n2 1\n3 1\n1 1\n1 2\n2 3\n1 3\n1 3\n2 1\n3 1\n1 1\n3 1\n3 1\n2 2\n1 1\n3 3\n3 1\n3 2\n2 3\n3 3\n3 1\n1 3\n2 3\n2 1\n3 2\n3 3\n3 1\n2 1\n2 2\n1 3\n3 3\n1 1\n3 2\n1 2\n2 3\n2 1\n2 2\n3 2\n1 3\n3 1\n1 1\n3 3\n2 3\n2 1\n2 3\n2 3\n1 2", "output": "5" }, { "input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3", "output": "1" }, { "input": "50 32\n6 6\n4 2\n5 5\n1 1\n2 4\n6 5\n2 3\n6 5\n2 3\n6 3\n1 4\n1 6\n3 3\n2 4\n3 2\n6 2\n4 1\n3 3\n3 1\n5 5\n1 2\n2 1\n5 4\n3 1\n4 4\n5 6\n4 1\n2 5\n3 1\n4 6\n2 3\n1 1\n6 5\n2 6\n3 3\n2 6\n2 3\n2 6\n3 4\n2 6\n4 5\n5 4\n1 6\n3 2\n5 1\n4 1\n4 6\n4 2\n1 2\n5 2", "output": "1" }, { "input": "50 48\n5 1\n6 4\n3 2\n2 1\n4 7\n3 6\n7 1\n7 5\n6 5\n5 6\n4 7\n5 7\n5 7\n5 5\n7 3\n3 5\n4 3\n5 4\n6 2\n1 6\n6 3\n6 5\n5 2\n4 2\n3 1\n1 1\n5 6\n1 3\n6 5\n3 7\n1 5\n7 5\n6 5\n3 6\n2 7\n5 3\n5 3\n4 7\n5 2\n6 5\n5 7\n7 1\n2 3\n5 5\n2 6\n4 1\n6 2\n6 5\n3 3\n1 6", "output": "1" }, { "input": "50 8\n5 3\n7 3\n4 3\n7 4\n2 2\n4 4\n5 4\n1 1\n7 7\n4 8\n1 1\n6 3\n1 5\n7 3\n6 5\n4 5\n8 6\n3 6\n2 1\n3 2\n2 5\n7 6\n5 8\n1 3\n5 5\n8 4\n4 5\n4 4\n8 8\n7 2\n7 2\n3 6\n2 8\n8 3\n3 2\n4 5\n8 1\n3 2\n8 7\n6 3\n2 3\n5 1\n3 4\n7 2\n6 3\n7 3\n3 3\n6 4\n2 2\n5 1", "output": "3" }, { "input": "20 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "20" }, { "input": "20 20\n1 2\n2 2\n1 1\n2 1\n2 2\n1 1\n1 1\n2 1\n1 1\n1 2\n2 2\n1 2\n1 2\n2 2\n2 2\n1 2\n2 1\n2 1\n1 2\n2 2", "output": "6" }, { "input": "30 16\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "30" }, { "input": "30 22\n2 1\n1 2\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n2 2\n1 2\n2 2\n1 2\n1 2\n2 1\n1 2\n2 2\n2 2\n1 2\n2 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n2 2\n1 2\n2 2\n2 1\n1 1", "output": "13" }, { "input": "30 22\n1 1\n1 3\n2 3\n3 1\n2 3\n3 1\n1 2\n3 3\n2 1\n2 1\n2 2\n3 1\n3 2\n2 3\n3 1\n1 3\n2 3\n3 1\n1 2\n1 2\n2 3\n2 1\n3 3\n3 2\n1 3\n3 3\n3 3\n3 3\n3 3\n3 1", "output": "5" }, { "input": "50 16\n2 1\n3 2\n5 2\n2 2\n3 4\n4 4\n3 3\n4 1\n2 3\n1 5\n4 1\n2 2\n1 5\n3 2\n2 1\n5 4\n5 2\n5 4\n1 1\n3 5\n2 1\n4 5\n5 1\n5 5\n5 4\n2 4\n1 2\n5 5\n4 4\n1 5\n4 2\n5 1\n2 4\n2 5\n2 2\n3 4\n3 1\n1 1\n5 5\n2 2\n3 4\n2 4\n5 2\n4 1\n3 1\n1 1\n4 1\n4 4\n1 4\n1 3", "output": "1" }, { "input": "50 22\n4 9\n8 1\n3 7\n1 2\n3 8\n9 8\n8 5\n2 10\n5 8\n1 3\n1 8\n2 3\n7 9\n10 2\n9 9\n7 3\n8 6\n10 6\n5 4\n8 1\n1 5\n6 8\n9 5\n9 5\n3 2\n3 3\n3 8\n7 5\n4 5\n8 10\n8 2\n3 5\n3 2\n1 1\n7 2\n2 7\n6 8\n10 4\n7 5\n1 7\n6 5\n3 1\n4 9\n2 3\n3 6\n5 8\n4 10\n10 7\n7 10\n9 8", "output": "1" }, { "input": "50 22\n29 15\n18 10\n6 23\n38 28\n34 40\n40 1\n16 26\n22 33\n14 30\n26 7\n15 16\n22 40\n14 15\n6 28\n32 27\n33 3\n38 22\n40 17\n16 27\n21 27\n34 26\n5 15\n34 9\n38 23\n7 36\n17 6\n19 37\n40 1\n10 28\n9 14\n8 31\n40 8\n14 2\n24 16\n38 33\n3 37\n2 9\n21 21\n40 26\n28 33\n24 31\n10 12\n27 27\n17 4\n38 5\n21 31\n5 12\n29 7\n39 12\n26 14", "output": "1" }, { "input": "50 14\n4 20\n37 50\n46 19\n20 25\n47 10\n6 34\n12 41\n47 9\n22 28\n41 34\n47 40\n12 42\n9 4\n15 15\n27 8\n38 9\n4 17\n8 13\n47 7\n9 38\n30 48\n50 7\n41 34\n23 11\n16 37\n2 32\n18 46\n37 48\n47 41\n13 9\n24 50\n46 14\n33 49\n9 50\n35 30\n49 44\n42 49\n39 15\n33 42\n3 18\n44 15\n44 28\n9 17\n16 4\n10 36\n4 22\n47 17\n24 12\n2 31\n6 30", "output": "2" }, { "input": "2 1\n50 50\n50 50", "output": "2" }, { "input": "2 2\n50 50\n50 50", "output": "2" }, { "input": "2 1\n50 50\n50 49", "output": "1" }, { "input": "2 2\n50 50\n50 49", "output": "1" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50", "output": "50" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n49 50", "output": "1" }, { "input": "50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 50\n50 49", "output": "49" }, { "input": "10 1\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4", "output": "1" }, { "input": "4 3\n1 1\n1 2\n2 1\n2 2", "output": "1" }, { "input": "4 2\n1 2\n1 3\n1 5\n1 2", "output": "2" }, { "input": "6 1\n4 3\n4 2\n5 1\n5 2\n5 3\n5 3", "output": "1" }, { "input": "5 3\n2 1\n1 3\n1 2\n1 1\n1 1", "output": "2" }, { "input": "3 1\n1 1\n1 2\n1 3", "output": "1" }, { "input": "10 10\n3 1\n3 2\n3 2\n2 3\n2 3\n2 3\n2 4\n2 4\n2 4\n2 4", "output": "4" }, { "input": "5 1\n5 5\n5 6\n5 7\n5 8\n5 5", "output": "2" }, { "input": "4 1\n1 1\n1 1\n1 2\n1 3", "output": "2" } ]
92
0
3
127
115
Party
[ "dfs and similar", "graphs", "trees" ]
null
null
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*. The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager. Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*. What is the minimum number of groups that must be formed?
The first line contains integer *n* (1<=≀<=*n*<=≀<=2000) β€” the number of employees. The next *n* lines contain the integers *p**i* (1<=≀<=*p**i*<=≀<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager. It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=β‰ <=*i*). Also, there will be no managerial cycles.
Print a single integer denoting the minimum number of groups that will be formed in the party.
[ "5\n-1\n1\n2\n1\n-1\n" ]
[ "3\n" ]
For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
[ { "input": "5\n-1\n1\n2\n1\n-1", "output": "3" }, { "input": "4\n-1\n1\n2\n3", "output": "4" }, { "input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11", "output": "4" }, { "input": "6\n-1\n-1\n2\n3\n1\n1", "output": "3" }, { "input": "3\n-1\n1\n1", "output": "2" }, { "input": "1\n-1", "output": "1" }, { "input": "2\n2\n-1", "output": "2" }, { "input": "2\n-1\n-1", "output": "1" }, { "input": "3\n2\n-1\n1", "output": "3" }, { "input": "3\n-1\n-1\n-1", "output": "1" }, { "input": "5\n4\n5\n1\n-1\n4", "output": "3" }, { "input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7", "output": "4" }, { "input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4", "output": "5" }, { "input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1", "output": "2" }, { "input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1", "output": "1" }, { "input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11", "output": "12" }, { "input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2", "output": "11" }, { "input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6", "output": "6" }, { "input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1", "output": "3" }, { "input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1", "output": "2" }, { "input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1", "output": "3" }, { "input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8", "output": "5" }, { "input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10", "output": "6" }, { "input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1", "output": "4" }, { "input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9", "output": "4" }, { "input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8", "output": "3" }, { "input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11", "output": "7" }, { "input": "7\n7\n6\n-1\n-1\n4\n4\n-1", "output": "3" }, { "input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34", "output": "6" }, { "input": "5\n2\n3\n4\n5\n-1", "output": "5" } ]
310
10,547,200
-1
128
362
Petya and Staircases
[ "implementation", "sortings" ]
null
null
Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.
The first line contains two integers *n* and *m* (1<=≀<=*n*<=≀<=109, 0<=≀<=*m*<=≀<=3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≀<=*d**i*<=≀<=*n*) β€” the numbers of the dirty stairs (in an arbitrary order).
Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO".
[ "10 5\n2 4 8 3 6\n", "10 5\n2 4 5 7 9\n" ]
[ "NO", "YES" ]
none
[ { "input": "10 5\n2 4 8 3 6", "output": "NO" }, { "input": "10 5\n2 4 5 7 9", "output": "YES" }, { "input": "10 9\n2 3 4 5 6 7 8 9 10", "output": "NO" }, { "input": "5 2\n4 5", "output": "NO" }, { "input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37", "output": "YES" }, { "input": "10 10\n7 6 4 2 5 10 8 3 9 1", "output": "NO" }, { "input": "12312 0", "output": "YES" }, { "input": "9817239 1\n6323187", "output": "YES" }, { "input": "1 1\n1", "output": "NO" }, { "input": "5 4\n4 2 5 1", "output": "NO" }, { "input": "5 3\n4 3 5", "output": "NO" }, { "input": "500 3\n18 62 445", "output": "YES" }, { "input": "500 50\n72 474 467 241 442 437 336 234 410 120 438 164 405 177 142 114 27 20 445 235 46 176 88 488 242 391 28 414 145 92 206 334 152 343 367 254 100 243 155 348 148 450 461 483 97 34 471 69 416 362", "output": "NO" }, { "input": "500 8\n365 313 338 410 482 417 325 384", "output": "YES" }, { "input": "1000000000 10\n2 3 5 6 8 9 123 874 1230 1000000000", "output": "NO" }, { "input": "1000000000 10\n1 2 3 5 6 8 9 123 874 1230", "output": "NO" }, { "input": "10 1\n1", "output": "NO" }, { "input": "10 4\n1 2 4 5", "output": "NO" }, { "input": "50 20\n22 33 17 23 27 5 26 31 41 20 8 24 6 3 4 29 40 25 13 16", "output": "NO" }, { "input": "50 40\n14 27 19 30 31 20 28 11 37 29 23 33 7 26 22 16 1 6 18 3 47 36 38 2 48 9 41 8 5 50 4 45 44 25 39 12 43 42 40 46", "output": "NO" }, { "input": "123 12\n35 95 47 99 79 122 58 94 31 57 18 10", "output": "YES" }, { "input": "10 5\n1 3 5 7 9", "output": "NO" }, { "input": "100 7\n2 3 5 6 8 9 100", "output": "NO" }, { "input": "100 3\n98 99 100", "output": "NO" }, { "input": "100 3\n97 98 99", "output": "NO" }, { "input": "100 3\n96 98 99", "output": "YES" }, { "input": "10 6\n2 3 5 6 8 9", "output": "YES" }, { "input": "1000000000 10\n2 4 10 18 40 42 49 58 59 60", "output": "NO" }, { "input": "10 3\n1 4 6", "output": "NO" }, { "input": "8 3\n2 3 4", "output": "NO" }, { "input": "100 3\n4 5 6", "output": "NO" }, { "input": "10 2\n10 1", "output": "NO" }, { "input": "10 1\n10", "output": "NO" }, { "input": "4 2\n2 3", "output": "YES" }, { "input": "2 1\n1", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "4 3\n2 3 4", "output": "NO" }, { "input": "5 3\n4 2 3", "output": "NO" } ]
499
204,800
-1
129
802
Fake News (easy)
[ "implementation", "strings" ]
null
null
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
[ "abcheaibcdi\n", "hiedi\n" ]
[ "YES", "NO" ]
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
[ { "input": "abcheaibcdi", "output": "YES" }, { "input": "hiedi", "output": "NO" }, { "input": "ihied", "output": "NO" }, { "input": "diehi", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "iheid", "output": "NO" }, { "input": "eihdi", "output": "NO" }, { "input": "ehdii", "output": "NO" }, { "input": "edhii", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "ehdii", "output": "NO" }, { "input": "eufyajkssayhjhqcwxmctecaeepjwmfoscqprpcxsqfwnlgzsmmuwuoruantipholrauvxydfvftwfzhnckxswussvlidcojiciflpvkcxkkcmmvtfvxrkwcpeelwsuzqgamamdtdgzscmikvojfvqehblmjczkvtdeymgertgkwfwfukafqlfdhtedcctixhyetdypswgagrpyto", "output": "YES" }, { "input": "arfbvxgdvqzuloojjrwoyqqbxamxybaqltfimofulusfebodjkwwrgwcppkwiodtpjaraglyplgerrpqjkpoggjmfxhwtqrijpijrcyxnoodvwpyjfpvqaoazllbrpzananbrvvybboedidtuvqquklkpeflfaltukjhzjgiofombhbmqbihgtapswykfvlgdoapjqntvqsaohmbvnphvyyhvhavslamczuqifxnwknkaenqmlvetrqogqxmlptgrmqvxzdxdmwobjesmgxckpmawtioavwdngyiwkzypfnxcovwzdohshwlavwsthdssiadhiwmhpvgkrbezm", "output": "YES" }, { "input": "zcectngbqnejjjtsfrluummmqabzqbyccshjqbrjthzhlbmzjfxugvjouwhumsgrnopiyakfadjnbsesamhynsbfbfunupwbxvohfmpwlcpxhovwpfpciclatgmiufwdvtsqrsdcymvkldpnhfeisrzhyhhlkwdzthgprvkpyldeysvbmcibqkpudyrraqdlxpjecvwcvuiklcrsbgvqasmxmtxqzmawcjtozioqlfflinnxpeexbzloaeqjvglbdeufultpjqexvjjjkzemtzuzmxvawilcqdrcjzpqyhtwfphuonzwkotthsaxrmwtnlmcdylxqcfffyndqeouztluqwlhnkkvzwcfiscikv", "output": "YES" }, { "input": "plqaykgovxkvsiahdbglktdlhcqwelxxmtlyymrsyubxdskvyjkrowvcbpdofpjqspsrgpakdczletxujzlsegepzleipiyycpinzxgwjsgslnxsotouddgfcybozfpjhhocpybfjbaywsehbcfrayvancbrumdfngqytnhihyxnlvilrqyhnxeckprqafofelospffhtwguzjbbjlzbqrtiielbvzutzgpqxosiaqznndgobcluuqlhmffiowkjdlkokehtjdyjvmxsiyxureflmdomerfekxdvtitvwzmdsdzplkpbtafxqfpudnhfqpoiwvjnylanunmagoweobdvfjgepbsymfutrjarlxclhgavpytiiqwvojrptofuvlohzeguxdsrihsbucelhhuedltnnjgzxwyblbqvnoliiydfinzlogbvucwykryzcyibnniggbkdkdcdgcsbvvnavtyhtkanrblpvomvjs", "output": "YES" }, { "input": "fbldqzggeunkpwcfirxanmntbfrudijltoertsdvcvcmbwodbibsrxendzebvxwydpasaqnisrijctsuatihxxygbeovhxjdptdcppkvfytdpjspvrannxavmkmisqtygntxkdlousdypyfkrpzapysfpdbyprufwzhunlsfugojddkmxzinatiwfxdqmgyrnjnxvrclhxyuwxtshoqdjptmeecvgmrlvuwqtmnfnfeeiwcavwnqmyustawbjodzwsqmnjxhpqmgpysierlwbbdzcwprpsexyvreewcmlbvaiytjlxdqdaqftefdlmtmmjcwvfejshymhnouoshdzqcwzxpzupkbcievodzqkqvyjuuxxwepxjalvkzufnveji", "output": "YES" }, { "input": "htsyljgoelbbuipivuzrhmfpkgderqpoprlxdpasxhpmxvaztccldtmujjzjmcpdvsdghzpretlsyyiljhjznseaacruriufswuvizwwuvdioazophhyytvbiogttnnouauxllbdn", "output": "YES" }, { "input": "ikmxzqdzxqlvgeojsnhqzciujslwjyzzexnregabdqztpplosdakimjxmuqccbnwvzbajoiqgdobccwnrwmixohrbdarhoeeelzbpigiybtesybwefpcfx", "output": "YES" }, { "input": "bpvbpjvbdfiodsmahxpcubjxdykesubnypalhypantshkjffmxjmelblqnjdmtaltneuyudyevkgedkqrdmrfeemgpghwrifcwincfixokfgurhqbcfzeajrgkgpwqwsepudxulywowwxzdxkumsicsvnzfxspmjpaixgejeaoyoibegosqoyoydmphfpbutrrewyjecowjckvpcceoamtfbitdneuwqfvnagswlskmsmkhmxyfsrpqwhxzocyffiumcy", "output": "YES" }, { "input": "vllsexwrazvlfvhvrtqeohvzzresjdiuhomfpgqcxpqdevplecuaepixhlijatxzegciizpvyvxuembiplwklahlqibykfideysjygagjbgqkbhdhkatddcwlxboinfuomnpc", "output": "YES" }, { "input": "pnjdwpxmvfoqkjtbhquqcuredrkwqzzfjmdvpnbqtypzdovemhhclkvigjvtprrpzbrbcbatkucaqteuciuozytsptvsskkeplaxdaqmjkmef", "output": "NO" }, { "input": "jpwfhvlxvsdhtuozvlmnfiotrgapgjxtcsgcjnodcztupysvvvmjpzqkpommadppdrykuqkcpzojcwvlogvkddedwbggkrhuvtsvdiokehlkdlnukcufjvqxnikcdawvexxwffxtriqbdmkahxdtygodzohwtdmmuvmatdkvweqvaehaxiefpevkvqpyxsrhtmgjsdfcwzqobibeduooldrmglbinrepmunizheqzvgqvpdskhxfidxfnbisyizhepwyrcykcmjxnkyfjgrqlkixcvysa", "output": "YES" }, { "input": "aftcrvuumeqbfvaqlltscnuhkpcifrrhnutjinxdhhdbzvizlrapzjdatuaynoplgjketupgaejciosofuhcgcjdcucarfvtsofgubtphijciswsvidnvpztlaarydkeqxzwdhfbmullkimerukusbrdnnujviydldrwhdfllsjtziwfeaiqotbiprespmxjulnyunkdtcghrzvhtcychkwatqqmladxpvmvlkzscthylbzkpgwlzfjqwarqvdeyngekqvrhrftpxnkfcibbowvnqdkulcdydspcubwlgoyinpnzgidbgunparnueddzwtzdiavbprbbg", "output": "YES" }, { "input": "oagjghsidigeh", "output": "NO" }, { "input": "chdhzpfzabupskiusjoefrwmjmqkbmdgboicnszkhdrlegeqjsldurmbshijadlwsycselhlnudndpdhcnhruhhvsgbthpruiqfirxkhpqhzhqdfpyozolbionodypfcqfeqbkcgmqkizgeyyelzeoothexcoaahedgrvoemqcwccbvoeqawqeuusyjxmgjkpfwcdttfmwunzuwvsihliexlzygqcgpbdiawfvqukikhbjerjkyhpcknlndaystrgsinghlmekbvhntcpypmchcwoglsmwwdulqneuabuuuvtyrnjxfcgoothalwkzzfxakneusezgnnepkpipzromqubraiggqndliz", "output": "YES" }, { "input": "lgirxqkrkgjcutpqitmffvbujcljkqardlalyigxorscczuzikoylcxenryhskoavymexysvmhbsvhtycjlmzhijpuvcjshyfeycvvcfyzytzoyvxajpqdjtfiatnvxnyeqtfcagfftafllhhjhplbdsrfpctkqpinpdfrtlzyjllfbeffputywcckupyslkbbzpgcnxgbmhtqeqqehpdaokkjtatrhyiuusjhwgiiiikxpzdueasemosmmccoakafgvxduwiuflovhhfhffgnnjhoperhhjtvocpqytjxkmrknnknqeglffhfuplopmktykxuvcmbwpoeisrlyyhdpxfvzseucofyhziuiikihpqheqdyzwigeaqzhxzvporgisxgvhyicqyejovqloibhbunsvsunpvmdckkbuokitdzleilfwutcvuuytpupizinfjrzhxudsmjcjyfcpfgthujjowdwtgbvi", "output": "YES" }, { "input": "uuehrvufgerqbzyzksmqnewacotuimawhlbycdbsmhshrsbqwybbkwjwsrkwptvlbbwjiivqugzrxxwgidrcrhrwsmwgeoleptfamzefgaeyxouxocrpvomjrazmxrnffdwrrmblgdiabdncvfougtmjgvvazasnygdrigbsrieoonirlivfyodvulouslxosswgpdexuldmkdbpdlgutiotvxjyecbrsvbmqxrlcpcipjjncduyqtohlzybvlemmfdeubihwlwqglkgjvnwrbgydcpwklmjeewqklmqdbajqgrpnynaxfvxjzgibqerxyhnxenrmcdqaaeksbzyrcaepozqpetaurlhjuxxhwppuhgoihxdxbmxeiahyaqkbknktlzkheaarjoqqrsyeducvoygwalgarldcdlqogfvsncejssmx", "output": "YES" }, { "input": "iiopulfjxoitgiusqrhgbkiyzinphjtclodbkkydetylvuimkhdkklmyoacmekdvjpuxcrvqnjhqhhbfenlpzpwijtykqziocilvtpqhxuyrphdlamawjuzgjwiebkqyrzyqgtkcrhntjxqmcgkrqcslogjegfrivzidfedeegwbbsopvxvdoididlpypjogxaodtueebbwuwilacunqpozczcgrpaxxrtogpxgfkudtxchoravrrdtimhenwmnafxaruuojduxxglefejycfcyxllfimkszmbrhcwpnwjqgwvzysmlaaifdxfjjpgjmcksiigpanappjdloiolojmcqbnpnjjzaufdpjaknylmyvolhwypygwepmqwpiglpcnpypnudhdzpdvgzosyjthzcwtytxq", "output": "YES" } ]
77
0
0
130
385
Bear and Strings
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≀<=*i*<=≀<=*j*<=≀<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring. String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≀<=*k*<=≀<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*. Help the bear cope with the given problem.
The first line contains a non-empty string *s* (1<=≀<=|*s*|<=≀<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number β€” the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output": "4419" }, { "input": "bear", "output": "1" }, { "input": "a", "output": "0" }, { "input": "be", "output": "0" } ]
93
307,200
-1
131
911
Two Cakes
[ "binary search", "brute force", "implementation" ]
null
null
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one β€” into *b* pieces. Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: 1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake. Help Ivan to calculate this number *x*!
The first line contains three integers *n*, *a* and *b* (1<=≀<=*a*,<=*b*<=≀<=100, 2<=≀<=*n*<=≀<=*a*<=+<=*b*) β€” the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake.
[ "5 2 3\n", "4 7 10\n" ]
[ "1\n", "3\n" ]
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.
[ { "input": "5 2 3", "output": "1" }, { "input": "4 7 10", "output": "3" }, { "input": "100 100 100", "output": "2" }, { "input": "10 100 3", "output": "3" }, { "input": "2 9 29", "output": "9" }, { "input": "4 6 10", "output": "3" }, { "input": "3 70 58", "output": "35" }, { "input": "5 7 10", "output": "3" }, { "input": "5 30 22", "output": "10" }, { "input": "5 5 6", "output": "2" }, { "input": "2 4 3", "output": "3" }, { "input": "10 10 31", "output": "3" }, { "input": "2 1 1", "output": "1" }, { "input": "10 98 99", "output": "19" }, { "input": "4 10 16", "output": "5" }, { "input": "11 4 8", "output": "1" }, { "input": "5 10 14", "output": "4" }, { "input": "6 7 35", "output": "7" }, { "input": "5 6 7", "output": "2" }, { "input": "4 15 3", "output": "3" }, { "input": "7 48 77", "output": "16" }, { "input": "4 4 10", "output": "3" }, { "input": "4 7 20", "output": "6" }, { "input": "5 2 8", "output": "2" }, { "input": "3 2 3", "output": "1" }, { "input": "14 95 1", "output": "1" }, { "input": "99 82 53", "output": "1" }, { "input": "10 71 27", "output": "9" }, { "input": "5 7 8", "output": "2" }, { "input": "11 77 77", "output": "12" }, { "input": "10 5 28", "output": "3" }, { "input": "7 3 12", "output": "2" }, { "input": "10 15 17", "output": "3" }, { "input": "7 7 7", "output": "1" }, { "input": "4 11 18", "output": "6" }, { "input": "3 3 4", "output": "2" }, { "input": "9 2 10", "output": "1" }, { "input": "100 90 20", "output": "1" }, { "input": "3 2 2", "output": "1" }, { "input": "12 45 60", "output": "8" }, { "input": "3 94 79", "output": "47" }, { "input": "41 67 34", "output": "2" }, { "input": "9 3 23", "output": "2" }, { "input": "10 20 57", "output": "7" }, { "input": "55 27 30", "output": "1" }, { "input": "100 100 10", "output": "1" }, { "input": "20 8 70", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "4 9 15", "output": "5" }, { "input": "3 1 3", "output": "1" }, { "input": "2 94 94", "output": "94" }, { "input": "5 3 11", "output": "2" }, { "input": "4 3 2", "output": "1" }, { "input": "12 12 100", "output": "9" }, { "input": "6 75 91", "output": "25" }, { "input": "3 4 3", "output": "2" }, { "input": "3 2 5", "output": "2" }, { "input": "6 5 15", "output": "3" }, { "input": "4 3 6", "output": "2" }, { "input": "3 9 9", "output": "4" }, { "input": "26 93 76", "output": "6" }, { "input": "41 34 67", "output": "2" }, { "input": "6 12 6", "output": "3" }, { "input": "5 20 8", "output": "5" }, { "input": "2 1 3", "output": "1" }, { "input": "35 66 99", "output": "4" }, { "input": "30 7 91", "output": "3" }, { "input": "5 22 30", "output": "10" }, { "input": "8 19 71", "output": "10" }, { "input": "3 5 6", "output": "3" }, { "input": "5 3 8", "output": "2" }, { "input": "2 4 2", "output": "2" }, { "input": "4 3 7", "output": "2" }, { "input": "5 20 10", "output": "5" }, { "input": "5 100 50", "output": "25" }, { "input": "6 3 10", "output": "2" }, { "input": "2 90 95", "output": "90" }, { "input": "4 8 6", "output": "3" }, { "input": "6 10 3", "output": "2" }, { "input": "3 3 5", "output": "2" }, { "input": "5 33 33", "output": "11" }, { "input": "5 5 8", "output": "2" }, { "input": "19 24 34", "output": "3" }, { "input": "5 5 12", "output": "3" }, { "input": "8 7 10", "output": "2" }, { "input": "5 56 35", "output": "17" }, { "input": "4 3 5", "output": "1" }, { "input": "18 100 50", "output": "8" }, { "input": "5 6 8", "output": "2" }, { "input": "5 98 100", "output": "33" }, { "input": "6 5 8", "output": "2" }, { "input": "3 40 80", "output": "40" }, { "input": "4 8 11", "output": "4" }, { "input": "66 100 99", "output": "3" }, { "input": "17 100 79", "output": "10" }, { "input": "3 2 10", "output": "2" }, { "input": "99 100 99", "output": "2" }, { "input": "21 100 5", "output": "5" }, { "input": "3 10 2", "output": "2" }, { "input": "4 100 63", "output": "33" }, { "input": "2 2 10", "output": "2" }, { "input": "5 94 79", "output": "31" }, { "input": "4 12 5", "output": "4" }, { "input": "5 5 40", "output": "5" }, { "input": "99 99 99", "output": "1" }, { "input": "8 97 44", "output": "16" }, { "input": "11 4 10", "output": "1" }, { "input": "6 3 3", "output": "1" }, { "input": "7 3 4", "output": "1" }, { "input": "8 4 4", "output": "1" }, { "input": "9 4 5", "output": "1" }, { "input": "12 6 6", "output": "1" }, { "input": "4 48 89", "output": "29" }, { "input": "8 3 6", "output": "1" }, { "input": "4 6 3", "output": "2" }, { "input": "5 5 1", "output": "1" }, { "input": "11 6 5", "output": "1" }, { "input": "4 5 4", "output": "2" }, { "input": "6 6 4", "output": "1" }, { "input": "2 1 2", "output": "1" }, { "input": "4 1 3", "output": "1" }, { "input": "3 3 1", "output": "1" }, { "input": "9 4 6", "output": "1" }, { "input": "6 5 6", "output": "1" }, { "input": "2 2 3", "output": "2" }, { "input": "4 5 1", "output": "1" }, { "input": "13 6 7", "output": "1" }, { "input": "14 7 7", "output": "1" }, { "input": "12 97 13", "output": "8" }, { "input": "4 2 9", "output": "2" }, { "input": "10 20 59", "output": "7" }, { "input": "12 34 56", "output": "7" }, { "input": "4 5 9", "output": "3" }, { "input": "2 2 2", "output": "2" }, { "input": "4 66 41", "output": "22" } ]
124
20,172,800
0
132
96
Football
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "output": "NO" }, { "input": "1010010100000000010", "output": "YES" }, { "input": "101010101", "output": "NO" }, { "input": "000000000100000000000110101100000", "output": "YES" }, { "input": "100001000000110101100000", "output": "NO" }, { "input": "100001000011010110000", "output": "NO" }, { "input": "010", "output": "NO" }, { "input": "10101011111111111111111111111100", "output": "YES" }, { "input": "1001101100", "output": "NO" }, { "input": "1001101010", "output": "NO" }, { "input": "1111100111", "output": "NO" }, { "input": "00110110001110001111", "output": "NO" }, { "input": "11110001001111110001", "output": "NO" }, { "input": "10001111001011111101", "output": "NO" }, { "input": "10000010100000001000110001010100001001001010011", "output": "YES" }, { "input": "01111011111010111100101100001011001010111110000010", "output": "NO" }, { "input": "00100000100100101110011001011011101110110110010100", "output": "NO" }, { "input": "10110100110001001011110101110010100010000000000100101010111110111110100011", "output": "YES" }, { "input": "00011101010101111001011011001101101011111101000010100000111000011100101011", "output": "NO" }, { "input": "01110000110100110101110100111000101101011101011110110100100111100001110111", "output": "NO" }, { "input": "11110110011000100111100111101101011111110100010101011011111101110110110111", "output": "YES" }, { "input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100", "output": "NO" }, { "input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010", "output": "NO" }, { "input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110", "output": "NO" }, { "input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000", "output": "NO" }, { "input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110", "output": "YES" }, { "input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000", "output": "NO" }, { "input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101", "output": "YES" }, { "input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101", "output": "YES" }, { "input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000", "output": "NO" }, { "input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000", "output": "YES" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "YES" }, { "input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111", "output": "YES" }, { "input": "10100101000", "output": "NO" }, { "input": "11110111011101", "output": "NO" }, { "input": "10000000", "output": "YES" }, { "input": "00000001", "output": "YES" }, { "input": "01111111", "output": "YES" }, { "input": "11111110", "output": "YES" } ]
30
0
0
134
121
Lucky Sum
[ "implementation" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem.
The single line contains two integers *l* and *r* (1<=≀<=*l*<=≀<=*r*<=≀<=109) β€” the left and right interval limits.
In the single line print the only number β€” the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2 7\n", "7 7\n" ]
[ "33\n", "7\n" ]
In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33 In the second sample: *next*(7) = 7
[ { "input": "2 7", "output": "33" }, { "input": "7 7", "output": "7" }, { "input": "1 9", "output": "125" }, { "input": "4 7", "output": "25" }, { "input": "12 47", "output": "1593" }, { "input": "6 77", "output": "4012" }, { "input": "1 100", "output": "14247" }, { "input": "1000000000 1000000000", "output": "4444444444" }, { "input": "77 77", "output": "77" }, { "input": "69 788", "output": "452195" }, { "input": "474 747", "output": "202794" }, { "input": "4 77777", "output": "4070145675" }, { "input": "1 1000000", "output": "1394675359387" }, { "input": "47 744447", "output": "381286992761" }, { "input": "47444 1000000000", "output": "1394672348253941136" }, { "input": "48 854888", "output": "749733199853" }, { "input": "854444 985555", "output": "582719941728" }, { "input": "774744 774747", "output": "3098985" }, { "input": "654 987654", "output": "1339803940266" }, { "input": "477777 1000000000", "output": "1394672167300009765" }, { "input": "77777 777777777", "output": "407018021649898097" }, { "input": "963 85555574", "output": "7526978888069560" }, { "input": "47 7444", "output": "38125896" }, { "input": "1 1000000000", "output": "1394672350065645019" }, { "input": "474 999888555", "output": "1394177038954402791" }, { "input": "777 1000000000", "output": "1394672350065239125" }, { "input": "7 777777774", "output": "407018023386632646" }, { "input": "369 852", "output": "606732" }, { "input": "47 47", "output": "47" }, { "input": "747 748", "output": "1521" }, { "input": "77777440 77777444", "output": "388887220" }, { "input": "987545885 999875584", "output": "54798666661186800" }, { "input": "2 777777776", "output": "407018024942188226" }, { "input": "1 1", "output": "4" }, { "input": "1 2", "output": "8" }, { "input": "999999999 1000000000", "output": "8888888888" }, { "input": "777777777 1000000000", "output": "987654325123456789" }, { "input": "777777778 1000000000", "output": "987654324345679012" }, { "input": "5 6", "output": "14" }, { "input": "49 49", "output": "74" }, { "input": "6 6", "output": "7" }, { "input": "3 4", "output": "8" } ]
2,000
3,276,800
0
135
415
Mashmokh and Tokens
[ "binary search", "greedy", "implementation", "math" ]
null
null
Bimokh is Mashmokh's boss. For the following *n* days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back *w* tokens then he'll get dollars. Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has *n* numbers *x*1,<=*x*2,<=...,<=*x**n*. Number *x**i* is the number of tokens given to each worker on the *i*-th day. Help him calculate for each of *n* days the number of tokens he can save.
The first line of input contains three space-separated integers *n*,<=*a*,<=*b*Β (1<=≀<=*n*<=≀<=105;Β 1<=≀<=*a*,<=*b*<=≀<=109). The second line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n*Β (1<=≀<=*x**i*<=≀<=109).
Output *n* space-separated integers. The *i*-th of them is the number of tokens Mashmokh can save on the *i*-th day.
[ "5 1 4\n12 6 11 9 1\n", "3 1 2\n1 2 3\n", "1 1 1\n1\n" ]
[ "0 2 3 1 1 ", "1 0 1 ", "0 " ]
none
[ { "input": "5 1 4\n12 6 11 9 1", "output": "0 2 3 1 1 " }, { "input": "3 1 2\n1 2 3", "output": "1 0 1 " }, { "input": "1 1 1\n1", "output": "0 " }, { "input": "1 1 1000000000\n1000000000", "output": "0 " }, { "input": "1 1 1000000000\n999999999", "output": "999999999 " }, { "input": "10 1 100000000\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999", "output": "99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 99999999 " } ]
280
11,059,200
0
138
886
ACM ICPC
[ "brute force" ]
null
null
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≀<=*a**i*<=≀<=1000) β€” scores of the participants
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "1 3 2 1 2 1\n", "1 1 1 1 1 99\n" ]
[ "YES\n", "NO\n" ]
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second β€” of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5. In the second sample, score of participant number 6 is too high: his team score will be definitely greater.
[ { "input": "1 3 2 1 2 1", "output": "YES" }, { "input": "1 1 1 1 1 99", "output": "NO" }, { "input": "1000 1000 1000 1000 1000 1000", "output": "YES" }, { "input": "0 0 0 0 0 0", "output": "YES" }, { "input": "633 609 369 704 573 416", "output": "NO" }, { "input": "353 313 327 470 597 31", "output": "NO" }, { "input": "835 638 673 624 232 266", "output": "NO" }, { "input": "936 342 19 398 247 874", "output": "NO" }, { "input": "417 666 978 553 271 488", "output": "NO" }, { "input": "71 66 124 199 67 147", "output": "YES" }, { "input": "54 26 0 171 239 12", "output": "YES" }, { "input": "72 8 186 92 267 69", "output": "YES" }, { "input": "180 179 188 50 75 214", "output": "YES" }, { "input": "16 169 110 136 404 277", "output": "YES" }, { "input": "101 400 9 200 300 10", "output": "YES" }, { "input": "101 400 200 9 300 10", "output": "YES" }, { "input": "101 200 400 9 300 10", "output": "YES" }, { "input": "101 400 200 300 9 10", "output": "YES" }, { "input": "101 200 400 300 9 10", "output": "YES" }, { "input": "4 4 4 4 5 4", "output": "NO" }, { "input": "2 2 2 2 2 1", "output": "NO" }, { "input": "1000 1000 999 1000 1000 1000", "output": "NO" }, { "input": "129 1 10 29 8 111", "output": "NO" }, { "input": "1000 1000 1000 999 999 1000", "output": "YES" }, { "input": "101 200 300 400 9 10", "output": "YES" }, { "input": "101 400 200 300 10 9", "output": "YES" }, { "input": "101 200 400 300 10 9", "output": "YES" }, { "input": "101 200 300 400 10 9", "output": "YES" }, { "input": "101 200 300 10 400 9", "output": "YES" }, { "input": "1 1 1 1 1 5", "output": "NO" }, { "input": "8 1 1 3 3 0", "output": "NO" }, { "input": "1 1 2 2 3 3", "output": "YES" }, { "input": "1 2 2 5 2 5", "output": "NO" }, { "input": "1 2 3 6 6 6", "output": "NO" }, { "input": "36 91 7 86 51 89", "output": "NO" }, { "input": "10 1 1 1 23 24", "output": "NO" }, { "input": "1 1 1 10 23 24", "output": "NO" }, { "input": "20 10 1 2 3 44", "output": "NO" }, { "input": "7 0 14 11 8 6", "output": "NO" }, { "input": "100 496 1 1 1 1", "output": "NO" }, { "input": "5 4 2 5 11 3", "output": "NO" }, { "input": "1 3 7 8 8 9", "output": "YES" }, { "input": "1 3 4 5 18 19", "output": "YES" }, { "input": "5 5 1 2 2 15", "output": "NO" }, { "input": "2 1 0 0 0 5", "output": "NO" }, { "input": "1 6 6 1 20 2", "output": "NO" }, { "input": "2 10 0 0 0 0", "output": "NO" }, { "input": "1 1 3 1 1 11", "output": "NO" }, { "input": "10 10 1 1 1 37", "output": "NO" }, { "input": "1 1 0 0 0 4", "output": "NO" }, { "input": "1 1 10 1 1 28", "output": "NO" }, { "input": "1 5 5 5 6 8", "output": "YES" }, { "input": "0 2 3 4 4 5", "output": "YES" } ]
61
0
0
140
294
Shaass and Oskols
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire. Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away. Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
The first line of the input contains an integer *n*, (1<=≀<=*n*<=≀<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≀<=*a**i*<=≀<=100). The third line contains an integer *m*, (0<=≀<=*m*<=≀<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≀<=*x**i*<=≀<=*n*,<=1<=≀<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51", "output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52" }, { "input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1", "output": "0\n0" }, { "input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5", "output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21" }, { "input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0", "output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95" }, { "input": "1\n100\n1\n1 100", "output": "0" }, { "input": "1\n100\n1\n1 1", "output": "0" }, { "input": "1\n50\n1\n1 25", "output": "0" }, { "input": "2\n50 0\n1\n1 1", "output": "0\n49" }, { "input": "1\n10\n0", "output": "10" } ]
92
0
3
141
909
Python Indentation
[ "dp" ]
null
null
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. Simple statements are written in a single line, one per line. An example of a simple statement is assignment. For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty. You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.
The first line contains a single integer *N* (1<=≀<=*N*<=≀<=5000)Β β€” the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.
Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7.
[ "4\ns\nf\nf\ns\n", "4\nf\ns\nf\ns\n" ]
[ "1\n", "2\n" ]
In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one. In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one. or
[ { "input": "4\ns\nf\nf\ns", "output": "1" }, { "input": "4\nf\ns\nf\ns", "output": "2" }, { "input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\nf\nf\nf\ns\nf\ns\ns\ns\nf\nf\ns\ns\ns\ns\ns\nf\nf\nf\nf\ns\nf\nf\ns\nf\ns\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\nf\ns\ns\nf\nf\nf\ns\ns\nf\nf\nf\ns\nf\ns\nf\nf\ns", "output": "666443222" }, { "input": "4\nf\nf\ns\ns", "output": "3" }, { "input": "2\nf\ns", "output": "1" }, { "input": "1\ns", "output": "1" }, { "input": "3\nf\nf\ns", "output": "1" }, { "input": "2\ns\ns", "output": "1" }, { "input": "156\ns\nf\ns\ns\ns\ns\nf\ns\ns\ns\nf\nf\ns\nf\nf\ns\nf\nf\nf\ns\nf\nf\ns\nf\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\nf\nf\nf\ns\ns\nf\nf\ns\nf\ns\ns\ns\ns\ns\ns\ns\nf\ns\nf\nf\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\ns\ns\nf\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\nf\ns\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\ns\nf\ns\nf\ns\ns\ns\nf\nf\ns", "output": "479461584" }, { "input": "66\ns\nf\ns\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\ns", "output": "392847498" } ]
31
0
0
144
446
DZY Loves Sequences
[ "dp", "implementation", "two pointers" ]
null
null
DZY has a sequence *a*, consisting of *n* integers. We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≀<=*i*<=≀<=*j*<=≀<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment. Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find.
The first line contains integer *n*Β (1<=≀<=*n*<=≀<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*Β (1<=≀<=*a**i*<=≀<=109).
In a single line print the answer to the problem β€” the maximum length of the required subsegment.
[ "6\n7 2 3 1 5 6\n" ]
[ "5\n" ]
You can choose subsegment *a*<sub class="lower-index">2</sub>, *a*<sub class="lower-index">3</sub>, *a*<sub class="lower-index">4</sub>, *a*<sub class="lower-index">5</sub>, *a*<sub class="lower-index">6</sub> and change its 3rd element (that is *a*<sub class="lower-index">4</sub>) to 4.
[ { "input": "6\n7 2 3 1 5 6", "output": "5" }, { "input": "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422", "output": "9" }, { "input": "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202363 350490028 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737 35005212 521595369 294702568 726956430 336465783 861021531 59961394 89018457 101513930 125898168 131176230 145174068 233665124 278722863 315634023 369133070 468703136 628175012 635723059 653377374 656478043 801979803 859484422 914544920 608413785 756898538 734575199 973594325 149798316 38664371", "output": "19" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "2" }, { "input": "5\n1 2 3 4 1", "output": "5" }, { "input": "10\n1 2 3 4 5 5 6 7 8 9", "output": "6" }, { "input": "5\n1 1 1 1 1", "output": "2" }, { "input": "5\n1 1 2 3 4", "output": "5" }, { "input": "5\n1 2 3 1 6", "output": "5" }, { "input": "1\n42", "output": "1" }, { "input": "5\n1 2 42 3 4", "output": "4" }, { "input": "5\n1 5 9 6 10", "output": "4" }, { "input": "5\n5 2 3 4 5", "output": "5" }, { "input": "3\n2 1 3", "output": "3" }, { "input": "5\n1 2 3 3 4", "output": "4" }, { "input": "8\n1 2 3 4 1 5 6 7", "output": "5" }, { "input": "1\n3", "output": "1" }, { "input": "3\n5 1 2", "output": "3" }, { "input": "4\n1 4 3 4", "output": "4" }, { "input": "6\n7 2 12 4 5 6", "output": "5" }, { "input": "6\n7 2 3 1 4 5", "output": "4" }, { "input": "6\n2 3 5 5 6 7", "output": "6" }, { "input": "5\n2 4 7 6 8", "output": "5" }, { "input": "3\n3 1 2", "output": "3" }, { "input": "3\n1 1 2", "output": "3" }, { "input": "2\n1 2", "output": "2" }, { "input": "5\n4 1 2 3 4", "output": "5" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6", "output": "7" }, { "input": "4\n1 2 1 3", "output": "3" }, { "input": "4\n4 3 1 2", "output": "3" }, { "input": "6\n1 2 2 3 4 5", "output": "5" }, { "input": "4\n1 1 1 2", "output": "3" }, { "input": "4\n5 1 2 3", "output": "4" }, { "input": "5\n9 1 2 3 4", "output": "5" }, { "input": "2\n1 1", "output": "2" }, { "input": "5\n1 3 2 4 5", "output": "4" }, { "input": "6\n1 2 1 2 4 5", "output": "5" }, { "input": "10\n1 1 5 3 2 9 9 7 7 6", "output": "3" }, { "input": "6\n1 2 3 100000 100 101", "output": "6" }, { "input": "4\n3 3 3 4", "output": "3" }, { "input": "3\n4 3 5", "output": "3" }, { "input": "5\n1 3 2 3 4", "output": "4" }, { "input": "10\n1 2 3 4 5 10 10 11 12 13", "output": "10" }, { "input": "7\n11 2 1 2 13 4 14", "output": "5" }, { "input": "3\n5 1 3", "output": "3" }, { "input": "4\n1 5 3 4", "output": "4" }, { "input": "10\n1 2 3 4 100 6 7 8 9 10", "output": "10" }, { "input": "3\n5 3 5", "output": "3" }, { "input": "5\n100 100 7 8 9", "output": "4" }, { "input": "5\n1 2 3 4 5", "output": "5" }, { "input": "5\n1 2 4 4 5", "output": "5" }, { "input": "6\n7 4 5 6 7 8", "output": "6" }, { "input": "9\n3 4 1 6 3 4 5 6 7", "output": "7" }, { "input": "3\n1000 1 2", "output": "3" }, { "input": "3\n20 1 9", "output": "3" }, { "input": "6\n7 2 3 1 4 6", "output": "4" }, { "input": "3\n100 5 10", "output": "3" }, { "input": "4\n2 2 2 3", "output": "3" }, { "input": "6\n4 2 8 1 2 5", "output": "4" }, { "input": "3\n25 1 6", "output": "3" }, { "input": "10\n17 99 23 72 78 36 5 43 95 9", "output": "5" }, { "input": "7\n21 16 22 21 11 13 19", "output": "4" }, { "input": "5\n1 2 5 3 4", "output": "4" }, { "input": "6\n2 2 2 3 4 5", "output": "5" }, { "input": "5\n1 3 1 2 3", "output": "4" }, { "input": "3\n81 33 64", "output": "3" }, { "input": "7\n14 3 3 19 13 19 15", "output": "4" }, { "input": "9\n1 2 3 4 5 42 7 8 9", "output": "9" }, { "input": "5\n2 3 7 5 6", "output": "5" }, { "input": "5\n1 3 3 4 5", "output": "5" }, { "input": "6\n1 5 4 3 4 5", "output": "4" } ]
61
4,608,000
0
145
278
Circle Line
[ "implementation" ]
null
null
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station. The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*.
The first line contains integer *n* (3<=≀<=*n*<=≀<=100) β€” the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≀<=*d**i*<=≀<=100) β€” the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≀<=*s*,<=*t*<=≀<=*n*) β€” the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces.
Print a single number β€” the length of the shortest path between stations number *s* and *t*.
[ "4\n2 3 4 9\n1 3\n", "4\n5 8 2 100\n4 1\n", "3\n1 1 1\n3 1\n", "3\n31 41 59\n1 1\n" ]
[ "5\n", "15\n", "1\n", "0\n" ]
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13. In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15. In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2. In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
[ { "input": "4\n2 3 4 9\n1 3", "output": "5" }, { "input": "4\n5 8 2 100\n4 1", "output": "15" }, { "input": "3\n1 1 1\n3 1", "output": "1" }, { "input": "3\n31 41 59\n1 1", "output": "0" }, { "input": "5\n16 13 10 30 15\n4 2", "output": "23" }, { "input": "6\n89 82 87 32 67 33\n4 4", "output": "0" }, { "input": "7\n2 3 17 10 2 2 2\n4 2", "output": "18" }, { "input": "3\n4 37 33\n3 3", "output": "0" }, { "input": "8\n87 40 96 7 86 86 72 97\n6 8", "output": "158" }, { "input": "10\n91 94 75 99 100 91 79 86 79 92\n2 8", "output": "348" }, { "input": "19\n1 1 1 1 2 1 1 1 1 1 2 1 3 2 2 1 1 1 2\n7 7", "output": "0" }, { "input": "34\n96 65 24 99 74 76 97 93 99 69 94 82 92 91 98 83 95 97 96 81 90 95 86 87 43 78 88 86 82 62 76 99 83 96\n21 16", "output": "452" }, { "input": "50\n75 98 65 75 99 89 84 65 9 53 62 61 61 53 80 7 6 47 86 1 89 27 67 1 31 39 53 92 19 20 76 41 60 15 29 94 76 82 87 89 93 38 42 6 87 36 100 97 93 71\n2 6", "output": "337" }, { "input": "99\n1 15 72 78 23 22 26 98 7 2 75 58 100 98 45 79 92 69 79 72 33 88 62 9 15 87 17 73 68 54 34 89 51 91 28 44 20 11 74 7 85 61 30 46 95 72 36 18 48 22 42 46 29 46 86 53 96 55 98 34 60 37 75 54 1 81 20 68 84 19 18 18 75 84 86 57 73 34 23 43 81 87 47 96 57 41 69 1 52 44 54 7 85 35 5 1 19 26 7\n4 64", "output": "1740" }, { "input": "100\n33 63 21 27 49 82 86 93 43 55 4 72 89 85 5 34 80 7 23 13 21 49 22 73 89 65 81 25 6 92 82 66 58 88 48 96 1 1 16 48 67 96 84 63 87 76 20 100 36 4 31 41 35 62 55 76 74 70 68 41 4 16 39 81 2 41 34 73 66 57 41 89 78 93 68 96 87 47 92 60 40 58 81 12 19 74 56 83 56 61 83 97 26 92 62 52 39 57 89 95\n71 5", "output": "2127" }, { "input": "100\n95 98 99 81 98 96 100 92 96 90 99 91 98 98 91 78 97 100 96 98 87 93 96 99 91 92 96 92 90 97 85 83 99 95 66 91 87 89 100 95 100 88 99 84 96 79 99 100 94 100 99 99 92 89 99 91 100 94 98 97 91 92 90 87 84 99 97 98 93 100 90 85 75 95 86 71 98 93 91 87 92 95 98 94 95 94 100 98 96 100 97 96 95 95 86 86 94 97 98 96\n67 57", "output": "932" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 97 100 100 100 100 100 99 100 100 99 99 100 99 100 100 100 100 100 100 100 100 100 97 99 98 98 100 98 98 100 99 100 100 100 100 99 100 98 100 99 98 99 98 98 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 98 100 99 99 100 96 100 96 100 99 100 100 99 100 99 100 100 100 99 100 100 100 100 98 98 97 100 100 99 98\n16 6", "output": "997" }, { "input": "100\n3 6 23 4 23 1 2 14 2 3 3 9 17 8 10 5 1 14 8 5 7 4 13 8 5 6 24 3 12 3 4 9 2 8 2 1 2 1 3 2 1 6 14 23 8 6 3 5 7 8 18 9 2 5 22 6 13 16 2 4 31 20 4 3 3 6 6 1 1 18 5 11 1 14 4 16 6 37 11 1 8 3 7 11 21 14 3 3 12 2 5 1 9 16 3 1 3 4 4 2\n98 24", "output": "195" }, { "input": "100\n1 1 3 1 1 2 1 2 1 1 2 2 2 1 1 1 1 1 1 3 1 1 1 3 1 3 3 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 3 3 2 1 1 1 1 1 2 2 1 3 1 1 1 2 4 1 1 2 5 2 1 1 2 1 1 1 2 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 2 3 1 7 3 1 3 1 2 1 2 1\n49 10", "output": "60" }, { "input": "100\n75 62 31 96 62 76 93 96 72 67 88 35 67 34 60 56 95 86 82 48 64 61 74 100 56 98 76 98 78 55 53 10 12 78 58 45 86 90 93 77 69 73 88 66 92 88 33 50 95 69 89 12 93 57 93 89 59 53 71 86 15 13 61 93 24 100 58 76 46 95 76 82 50 20 79 38 5 72 99 81 55 90 90 65 85 44 63 39 6 34 98 72 88 30 59 73 84 61 25 67\n86 25", "output": "2523" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n1 51", "output": "5000" }, { "input": "4\n1 1 1 1\n2 4", "output": "2" }, { "input": "4\n1 1 2 1\n2 4", "output": "2" } ]
218
0
3
148
615
Bulbs
[ "implementation" ]
null
null
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.
The first line of the input contains integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100)Β β€” the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≀<=*x**i*<=≀<=*m*)Β β€” the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≀<=*y**ij*<=≀<=*m*)Β β€” the numbers of these bulbs.
If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO".
[ "3 4\n2 1 4\n3 1 3 1\n1 2\n", "3 3\n1 1\n1 2\n1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
[ { "input": "3 4\n2 1 4\n3 1 3 1\n1 2", "output": "YES" }, { "input": "3 3\n1 1\n1 2\n1 1", "output": "NO" }, { "input": "3 4\n1 1\n1 2\n1 3", "output": "NO" }, { "input": "1 5\n5 1 2 3 4 5", "output": "YES" }, { "input": "1 5\n5 4 4 1 2 3", "output": "NO" }, { "input": "1 5\n5 1 1 1 1 5", "output": "NO" }, { "input": "2 5\n4 3 1 4 2\n4 2 3 4 5", "output": "YES" }, { "input": "5 7\n2 6 7\n5 1 1 1 1 1\n3 6 5 4\n0\n4 4 3 2 1", "output": "YES" }, { "input": "100 100\n0\n0\n0\n1 53\n0\n0\n1 34\n1 54\n0\n1 14\n0\n1 33\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 82\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n1 26\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n0\n0\n0\n1 3\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 40\n0\n0\n0\n1 26\n0\n0\n0\n0\n0\n1 97\n0\n1 5\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "100 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "5 6\n3 1 2 6\n3 1 2 6\n1 1\n2 3 4\n3 1 5 6", "output": "YES" }, { "input": "5 2\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "NO" }, { "input": "1 4\n3 1 2 3", "output": "NO" }, { "input": "1 4\n3 2 3 4", "output": "NO" }, { "input": "2 4\n3 2 3 4\n1 1", "output": "YES" }, { "input": "2 4\n3 1 2 3\n1 4", "output": "YES" }, { "input": "5 1\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "1 1\n0", "output": "NO" }, { "input": "1 10\n10 1 2 3 4 5 6 7 8 9 10", "output": "YES" }, { "input": "1 1\n1 1", "output": "YES" }, { "input": "1 100\n99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99", "output": "NO" }, { "input": "1 3\n3 1 2 1", "output": "NO" }, { "input": "1 100\n100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "YES" } ]
46
0
3
150
920
Swap Adjacent Elements
[ "dfs and similar", "greedy", "math", "sortings", "two pointers" ]
null
null
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array. For some indices *i* (1<=≀<=*i*<=≀<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the number of times you swap *i*-th element with (*i*<=+<=1)-th (if the position is not forbidden). Can you make this array sorted in ascending order performing some sequence of swapping operations?
The first line contains one integer *n* (2<=≀<=*n*<=≀<=200000) β€” the number of elements in the array. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=200000) β€” the elements of the array. Each integer from 1 to *n* appears exactly once. The third line contains a string of *n*<=-<=1 characters, each character is either 0 or 1. If *i*-th character is 1, then you can swap *i*-th element with (*i*<=+<=1)-th any number of times, otherwise it is forbidden to swap *i*-th element with (*i*<=+<=1)-th.
If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO.
[ "6\n1 2 5 3 4 6\n01110\n", "6\n1 2 5 3 4 6\n01010\n" ]
[ "YES\n", "NO\n" ]
In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>.
[ { "input": "6\n1 2 5 3 4 6\n01110", "output": "YES" }, { "input": "6\n1 2 5 3 4 6\n01010", "output": "NO" }, { "input": "6\n1 6 3 4 5 2\n01101", "output": "NO" }, { "input": "6\n2 3 1 4 5 6\n01111", "output": "NO" }, { "input": "4\n2 3 1 4\n011", "output": "NO" }, { "input": "2\n2 1\n0", "output": "NO" }, { "input": "5\n1 2 4 5 3\n0101", "output": "NO" }, { "input": "5\n1 2 4 5 3\n0001", "output": "NO" }, { "input": "5\n1 4 5 2 3\n0110", "output": "NO" }, { "input": "5\n4 5 1 2 3\n0111", "output": "NO" }, { "input": "3\n3 1 2\n10", "output": "NO" }, { "input": "5\n2 3 4 5 1\n0011", "output": "NO" }, { "input": "16\n3 4 14 16 11 7 13 9 10 8 6 5 15 12 1 2\n111111101111111", "output": "NO" }, { "input": "5\n1 5 3 4 2\n1101", "output": "NO" }, { "input": "6\n6 1 2 3 4 5\n11101", "output": "NO" }, { "input": "3\n2 3 1\n01", "output": "NO" }, { "input": "6\n1 6 3 4 5 2\n01110", "output": "NO" }, { "input": "7\n1 7 3 4 5 6 2\n010001", "output": "NO" }, { "input": "5\n5 2 3 4 1\n1001", "output": "NO" }, { "input": "4\n1 3 4 2\n001", "output": "NO" }, { "input": "5\n4 5 1 2 3\n1011", "output": "NO" }, { "input": "6\n1 5 3 4 2 6\n11011", "output": "NO" }, { "input": "5\n1 4 2 5 3\n1101", "output": "NO" }, { "input": "5\n3 2 4 1 5\n1010", "output": "NO" }, { "input": "6\n1 4 3 5 6 2\n01101", "output": "NO" }, { "input": "6\n2 3 4 5 1 6\n00010", "output": "NO" }, { "input": "10\n5 2 7 9 1 10 3 4 6 8\n111101000", "output": "NO" }, { "input": "5\n2 4 3 1 5\n0110", "output": "NO" }, { "input": "4\n3 1 2 4\n100", "output": "NO" }, { "input": "6\n1 5 3 4 2 6\n01010", "output": "NO" }, { "input": "4\n3 1 2 4\n101", "output": "NO" }, { "input": "4\n2 4 3 1\n011", "output": "NO" }, { "input": "4\n2 3 4 1\n001", "output": "NO" }, { "input": "4\n3 4 1 2\n011", "output": "NO" }, { "input": "5\n2 4 1 3 5\n0110", "output": "NO" }, { "input": "4\n1 3 4 2\n101", "output": "NO" }, { "input": "20\n20 19 18 17 16 15 1 2 3 4 5 14 13 12 11 10 9 8 7 6\n1111111011111111111", "output": "NO" }, { "input": "6\n6 5 4 1 2 3\n11100", "output": "NO" }, { "input": "5\n2 3 5 1 4\n0011", "output": "NO" }, { "input": "4\n1 4 2 3\n010", "output": "NO" }, { "input": "6\n1 6 3 4 5 2\n01001", "output": "NO" }, { "input": "7\n1 7 2 4 3 5 6\n011110", "output": "NO" }, { "input": "5\n1 3 4 2 5\n0010", "output": "NO" }, { "input": "5\n5 4 3 1 2\n1110", "output": "NO" }, { "input": "5\n2 5 4 3 1\n0111", "output": "NO" }, { "input": "4\n2 3 4 1\n101", "output": "NO" }, { "input": "5\n1 4 5 2 3\n1011", "output": "NO" }, { "input": "5\n1 3 2 5 4\n1110", "output": "NO" }, { "input": "6\n3 2 4 1 5 6\n10111", "output": "NO" }, { "input": "7\n3 1 7 4 5 2 6\n101110", "output": "NO" }, { "input": "10\n5 4 10 9 2 1 6 7 3 8\n011111111", "output": "NO" }, { "input": "5\n1 5 3 2 4\n1110", "output": "NO" }, { "input": "4\n2 3 4 1\n011", "output": "NO" }, { "input": "5\n5 4 3 2 1\n0000", "output": "NO" }, { "input": "12\n6 9 11 1 12 7 5 8 10 4 3 2\n11111111110", "output": "NO" }, { "input": "5\n3 1 5 2 4\n1011", "output": "NO" }, { "input": "5\n4 5 1 2 3\n1110", "output": "NO" }, { "input": "10\n1 2 3 4 5 6 8 9 7 10\n000000000", "output": "NO" }, { "input": "6\n5 6 3 2 4 1\n01111", "output": "NO" }, { "input": "5\n1 3 4 2 5\n0100", "output": "NO" }, { "input": "4\n2 1 4 3\n100", "output": "NO" }, { "input": "6\n1 2 3 4 6 5\n00000", "output": "NO" }, { "input": "6\n4 6 5 3 2 1\n01111", "output": "NO" }, { "input": "5\n3 1 4 5 2\n1001", "output": "NO" }, { "input": "5\n5 2 3 1 4\n1011", "output": "NO" }, { "input": "3\n2 3 1\n10", "output": "NO" }, { "input": "10\n6 5 9 4 3 2 8 10 7 1\n111111110", "output": "NO" }, { "input": "7\n1 2 7 3 4 5 6\n111101", "output": "NO" }, { "input": "6\n5 6 1 2 4 3\n11101", "output": "NO" }, { "input": "6\n4 6 3 5 2 1\n11110", "output": "NO" }, { "input": "5\n5 4 2 3 1\n1110", "output": "NO" }, { "input": "2\n2 1\n1", "output": "YES" }, { "input": "3\n1 3 2\n10", "output": "NO" }, { "input": "5\n3 4 5 1 2\n1110", "output": "NO" }, { "input": "5\n3 4 2 1 5\n0110", "output": "NO" }, { "input": "6\n6 1 2 3 4 5\n10001", "output": "NO" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10\n000000000", "output": "YES" }, { "input": "3\n3 2 1\n00", "output": "NO" }, { "input": "5\n5 4 3 2 1\n1110", "output": "NO" }, { "input": "6\n3 1 2 5 6 4\n10011", "output": "NO" }, { "input": "6\n3 2 1 6 5 4\n11000", "output": "NO" }, { "input": "2\n1 2\n0", "output": "YES" }, { "input": "2\n1 2\n1", "output": "YES" }, { "input": "11\n1 2 3 4 5 6 7 8 9 10 11\n0000000000", "output": "YES" }, { "input": "4\n2 4 3 1\n101", "output": "NO" }, { "input": "4\n3 4 1 2\n101", "output": "NO" }, { "input": "3\n1 3 2\n01", "output": "YES" }, { "input": "6\n6 2 3 1 4 5\n11110", "output": "NO" }, { "input": "3\n2 1 3\n01", "output": "NO" }, { "input": "5\n1 5 4 3 2\n0111", "output": "YES" }, { "input": "6\n1 2 6 3 4 5\n11110", "output": "NO" }, { "input": "7\n2 3 1 7 6 5 4\n011111", "output": "NO" }, { "input": "6\n5 6 1 2 3 4\n01111", "output": "NO" }, { "input": "4\n1 2 4 3\n001", "output": "YES" }, { "input": "6\n1 2 3 6 4 5\n11001", "output": "NO" }, { "input": "11\n9 8 10 11 1 2 3 4 5 6 7\n1101111111", "output": "NO" }, { "input": "5\n1 5 3 4 2\n0101", "output": "NO" }, { "input": "10\n9 1 2 3 7 8 5 6 4 10\n110111100", "output": "NO" }, { "input": "7\n1 2 7 3 4 5 6\n111011", "output": "NO" }, { "input": "10\n3 10 1 2 6 4 5 7 8 9\n111111001", "output": "NO" }, { "input": "10\n1 3 6 5 2 9 7 8 4 10\n001101111", "output": "NO" }, { "input": "10\n1 8 9 7 6 10 4 2 3 5\n111111101", "output": "NO" }, { "input": "7\n1 2 5 3 6 4 7\n111011", "output": "NO" }, { "input": "4\n2 4 3 1\n100", "output": "NO" }, { "input": "6\n1 2 3 4 6 5\n00001", "output": "YES" }, { "input": "6\n2 1 3 4 5 6\n10000", "output": "YES" }, { "input": "5\n3 2 1 5 4\n1100", "output": "NO" }, { "input": "9\n2 1 3 6 5 4 7 9 8\n10011001", "output": "YES" }, { "input": "8\n2 6 4 1 5 7 3 8\n1010010", "output": "NO" }, { "input": "5\n1 2 4 5 3\n1101", "output": "NO" }, { "input": "6\n1 3 5 2 4 6\n00110", "output": "NO" }, { "input": "6\n1 3 6 2 4 5\n10111", "output": "NO" }, { "input": "9\n9 8 7 6 5 4 3 1 2\n11111110", "output": "NO" }, { "input": "10\n6 7 8 9 10 1 2 3 4 5\n111111110", "output": "NO" }, { "input": "8\n6 1 7 8 3 2 5 4\n1011111", "output": "NO" }, { "input": "70\n4 65 66 30 67 16 39 35 57 14 42 51 5 21 61 53 63 13 60 29 68 70 69 46 20 2 43 47 49 52 26 44 54 62 25 19 12 28 27 24 18 36 6 33 7 8 11 1 45 32 64 38 23 22 56 59 15 9 41 37 40 55 3 31 34 48 50 10 17 58\n111111101101111111111110101111111111111101101111010010110011011110010", "output": "NO" }, { "input": "5\n5 3 2 4 1\n0100", "output": "NO" }, { "input": "6\n3 2 6 5 1 4\n11011", "output": "NO" }, { "input": "6\n1 2 4 5 6 3\n10011", "output": "NO" }, { "input": "7\n1 7 3 2 5 6 4\n111001", "output": "NO" } ]
249
20,480,000
3
151
169
Chores
[ "sortings" ]
null
null
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter β€” its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=&gt;<=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≀<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*). In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores?
The first input line contains three integers *n*,<=*a* and *b* (2<=≀<=*n*<=≀<=2000; *a*,<=*b*<=β‰₯<=1; *a*<=+<=*b*<==<=*n*) β€” the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≀<=*h**i*<=≀<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different. All numbers on the lines are separated by single spaces.
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
[ "5 2 3\n6 2 3 100 1\n", "7 3 4\n1 1 9 1 1 1 1\n" ]
[ "3\n", "0\n" ]
In the first sample the possible values of *x* are 3, 4 or 5. In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
[ { "input": "5 2 3\n6 2 3 100 1", "output": "3" }, { "input": "7 3 4\n1 1 9 1 1 1 1", "output": "0" }, { "input": "2 1 1\n10 2", "output": "8" }, { "input": "2 1 1\n7 7", "output": "0" }, { "input": "2 1 1\n1 1000000000", "output": "999999999" }, { "input": "3 1 2\n6 5 5", "output": "1" }, { "input": "3 2 1\n10 10 8", "output": "2" }, { "input": "8 3 5\n42 55 61 72 83 10 22 33", "output": "6" }, { "input": "10 5 5\n1 2 3 4 5 999999999 999999998 999999997 999999996 999999995", "output": "999999990" }, { "input": "4 1 3\n10 8 7 3", "output": "2" }, { "input": "4 2 2\n402 10 10 402", "output": "392" }, { "input": "4 1 3\n10 402 402 10", "output": "0" }, { "input": "4 3 1\n100 100 200 200", "output": "0" }, { "input": "150 10 140\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "102 101 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" } ]
93
6,656,000
-1
152
846
Curriculum Vitae
[ "brute force", "implementation" ]
null
null
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array *s*1,<=*s*2,<=...,<=*s**n* of zeros and ones. Zero corresponds to an unsuccessful game, one β€” to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV.
The first line contains one integer number *n* (1<=≀<=*n*<=≀<=100). The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≀<=*s**i*<=≀<=1). 0 corresponds to an unsuccessful game, 1 β€” to a successful one.
Print one integer β€” the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one.
[ "4\n1 1 0 1\n", "6\n0 1 0 0 1 0\n", "1\n0\n" ]
[ "3\n", "4\n", "1\n" ]
none
[ { "input": "4\n1 1 0 1", "output": "3" }, { "input": "6\n0 1 0 0 1 0", "output": "4" }, { "input": "1\n0", "output": "1" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "100" }, { "input": "100\n0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "80" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1", "output": "53" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "3\n1 0 0", "output": "2" }, { "input": "10\n1 1 0 0 0 1 1 0 0 0", "output": "6" }, { "input": "90\n1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0", "output": "52" }, { "input": "78\n0 0 1 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0", "output": "42" }, { "input": "4\n1 0 0 1", "output": "3" }, { "input": "2\n0 1", "output": "2" }, { "input": "5\n0 1 0 0 1", "output": "4" }, { "input": "3\n1 0 1", "output": "2" }, { "input": "3\n1 1 0", "output": "2" }, { "input": "16\n1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 1", "output": "9" } ]
46
0
-1
153
950
Left-handers, Right-handers and Ambidexters
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
The only line contains three integers *l*, *r* and *a* (0<=≀<=*l*,<=*r*,<=*a*<=≀<=100) β€” the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integerΒ β€” the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { "input": "0 0 0", "output": "0" }, { "input": "100 100 100", "output": "300" }, { "input": "1 1 1", "output": "2" }, { "input": "30 70 35", "output": "130" }, { "input": "89 44 76", "output": "208" }, { "input": "0 100 100", "output": "200" }, { "input": "100 0 100", "output": "200" }, { "input": "100 1 100", "output": "200" }, { "input": "1 100 100", "output": "200" }, { "input": "100 100 0", "output": "200" }, { "input": "100 100 1", "output": "200" }, { "input": "1 2 1", "output": "4" }, { "input": "0 0 100", "output": "100" }, { "input": "0 100 0", "output": "0" }, { "input": "100 0 0", "output": "0" }, { "input": "10 8 7", "output": "24" }, { "input": "45 47 16", "output": "108" }, { "input": "59 43 100", "output": "202" }, { "input": "34 1 30", "output": "62" }, { "input": "14 81 1", "output": "30" }, { "input": "53 96 94", "output": "242" }, { "input": "62 81 75", "output": "218" }, { "input": "21 71 97", "output": "188" }, { "input": "49 82 73", "output": "204" }, { "input": "88 19 29", "output": "96" }, { "input": "89 4 62", "output": "132" }, { "input": "58 3 65", "output": "126" }, { "input": "27 86 11", "output": "76" }, { "input": "35 19 80", "output": "134" }, { "input": "4 86 74", "output": "156" }, { "input": "32 61 89", "output": "182" }, { "input": "68 60 98", "output": "226" }, { "input": "37 89 34", "output": "142" }, { "input": "92 9 28", "output": "74" }, { "input": "79 58 98", "output": "234" }, { "input": "35 44 88", "output": "166" }, { "input": "16 24 19", "output": "58" }, { "input": "74 71 75", "output": "220" }, { "input": "83 86 99", "output": "268" }, { "input": "97 73 15", "output": "176" }, { "input": "77 76 73", "output": "226" }, { "input": "48 85 55", "output": "188" }, { "input": "1 2 2", "output": "4" }, { "input": "2 2 2", "output": "6" }, { "input": "2 1 2", "output": "4" }, { "input": "2 2 1", "output": "4" }, { "input": "3 2 1", "output": "6" }, { "input": "1 2 3", "output": "6" }, { "input": "1 3 2", "output": "6" }, { "input": "2 1 3", "output": "6" }, { "input": "2 3 1", "output": "6" }, { "input": "3 1 2", "output": "6" }, { "input": "99 99 99", "output": "296" }, { "input": "99 99 100", "output": "298" }, { "input": "99 100 99", "output": "298" }, { "input": "99 100 100", "output": "298" }, { "input": "100 99 99", "output": "298" }, { "input": "100 99 100", "output": "298" }, { "input": "100 100 99", "output": "298" }, { "input": "89 32 23", "output": "110" }, { "input": "4 5 0", "output": "8" }, { "input": "3 0 3", "output": "6" }, { "input": "0 0 2", "output": "2" }, { "input": "97 97 0", "output": "194" }, { "input": "1 4 0", "output": "2" }, { "input": "5 2 0", "output": "4" }, { "input": "0 5 10", "output": "14" }, { "input": "0 1 2", "output": "2" }, { "input": "5 2 3", "output": "10" }, { "input": "5 5 0", "output": "10" }, { "input": "0 0 10", "output": "10" }, { "input": "0 1 1", "output": "2" }, { "input": "0 0 1", "output": "0" } ]
77
7,372,800
0
154
522
Photo to Remember
[ "*special", "data structures", "dp", "implementation" ]
null
null
One day *n* friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the *i*-th of them occupies the rectangle of width *w**i* pixels and height *h**i* pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is *W*<=Γ—<=*H*, where *W* is the total sum of all widths and *H* is the maximum height of all the photographed friends. As is usually the case, the friends made *n* photos β€” the *j*-th (1<=≀<=*j*<=≀<=*n*) photo had everybody except for the *j*-th friend as he was the photographer. Print the minimum size of each made photo in pixels.
The first line contains integer *n* (2<=≀<=*n*<=≀<=200<=000) β€” the number of friends. Then *n* lines follow: the *i*-th line contains information about the *i*-th friend. The line contains a pair of integers *w**i*,<=*h**i* (1<=≀<=*w**i*<=≀<=10,<=1<=≀<=*h**i*<=≀<=1000) β€” the width and height in pixels of the corresponding rectangle.
Print *n* space-separated numbers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* β€” the total number of pixels on the minimum photo containing all friends expect for the *i*-th one.
[ "3\n1 10\n5 5\n10 1\n", "3\n2 1\n1 2\n2 1\n" ]
[ "75 110 60 ", "6 4 6 " ]
none
[ { "input": "3\n1 10\n5 5\n10 1", "output": "75 110 60 " }, { "input": "3\n2 1\n1 2\n2 1", "output": "6 4 6 " }, { "input": "2\n1 5\n2 3", "output": "6 5 " }, { "input": "2\n2 3\n1 1", "output": "1 6 " }, { "input": "3\n1 10\n2 10\n3 10", "output": "50 40 30 " }, { "input": "3\n2 10\n1 9\n3 7", "output": "36 50 30 " }, { "input": "3\n1 1\n3 2\n2 3", "output": "15 9 8 " }, { "input": "3\n3 123\n1 456\n2 789", "output": "2367 3945 1824 " }, { "input": "3\n2 987\n3 654\n1 321", "output": "2616 2961 4935 " }, { "input": "3\n3 143\n2 543\n1 893", "output": "2679 3572 2715 " }, { "input": "2\n1 1\n1 2", "output": "2 1 " }, { "input": "3\n2 22\n1 11\n2 22", "output": "66 88 66 " }, { "input": "3\n1 11\n1 12\n1 13", "output": "26 26 24 " }, { "input": "3\n1 11\n1 12\n2 10", "output": "36 33 24 " }, { "input": "10\n6 20\n1 175\n1 758\n1 169\n2 490\n2 600\n4 463\n7 377\n9 40\n4 961", "output": "29791 34596 34596 34596 33635 33635 31713 28830 26908 25014 " }, { "input": "10\n8 158\n1 709\n6 766\n4 335\n5 356\n2 972\n1 108\n4 235\n3 631\n1 414", "output": "26244 33048 28188 30132 29160 25278 33048 30132 31104 33048 " }, { "input": "10\n7 549\n9 115\n8 141\n3 650\n5 730\n3 841\n7 18\n9 170\n2 217\n1 155", "output": "39527 37845 38686 42891 41209 37230 39527 37845 43732 44573 " }, { "input": "10\n6 386\n9 816\n9 268\n9 481\n8 284\n10 715\n9 351\n7 580\n4 327\n7 392", "output": "58752 49335 56304 56304 57120 55488 56304 57936 60384 57936 " }, { "input": "10\n9 292\n4 6\n6 638\n8 461\n10 970\n10 488\n9 769\n10 644\n8 280\n5 334", "output": "67900 72750 70810 68870 53061 66930 67900 66930 68870 71780 " }, { "input": "10\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000", "output": "90000 90000 90000 90000 90000 90000 90000 90000 90000 90000 " } ]
904
12,697,600
3
155
450
Jzzhu and Children
[ "implementation" ]
null
null
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
The first line contains two integers *n*,<=*m* (1<=≀<=*n*<=≀<=100;Β 1<=≀<=*m*<=≀<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=100).
Output a single integer, representing the number of the last child.
[ "5 2\n1 3 1 4 2\n", "6 4\n1 1 2 2 3 3\n" ]
[ "4\n", "6\n" ]
Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home. Child 4 is the last one who goes home.
[ { "input": "5 2\n1 3 1 4 2", "output": "4" }, { "input": "6 4\n1 1 2 2 3 3", "output": "6" }, { "input": "7 3\n6 1 5 4 2 3 1", "output": "4" }, { "input": "10 5\n2 7 3 6 2 5 1 3 4 5", "output": "4" }, { "input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "100" }, { "input": "9 3\n9 5 2 3 7 1 8 4 6", "output": "7" }, { "input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58", "output": "16" }, { "input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54", "output": "48" }, { "input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1", "output": "44" }, { "input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3", "output": "46" }, { "input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78", "output": "40" }, { "input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69", "output": "11" }, { "input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95", "output": "50" }, { "input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9", "output": "86" }, { "input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7", "output": "93" }, { "input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42", "output": "77" }, { "input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48", "output": "97" }, { "input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78", "output": "20" }, { "input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41", "output": "97" }, { "input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82", "output": "51" }, { "input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58", "output": "97" }, { "input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88", "output": "47" }, { "input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51", "output": "98" }, { "input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67", "output": "94" }, { "input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19", "output": "95" }, { "input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49", "output": "88" }, { "input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1", "output": "99" }, { "input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95", "output": "100" }, { "input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15", "output": "98" }, { "input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16", "output": "100" }, { "input": "1 3\n5", "output": "1" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 3\n4 2", "output": "1" }, { "input": "2 5\n99 97", "output": "2" }, { "input": "3 4\n7 5 2", "output": "2" }, { "input": "3 50\n47 86 51", "output": "3" }, { "input": "5 100\n82 100 85 1 37", "output": "5" }, { "input": "5 20\n40 39 21 5 20", "output": "3" }, { "input": "1 27\n81", "output": "1" }, { "input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1", "output": "7" }, { "input": "2 1\n100 2", "output": "1" }, { "input": "2 2\n6 4", "output": "1" }, { "input": "5 2\n6 4 4 1 1", "output": "1" }, { "input": "1 4\n3", "output": "1" }, { "input": "3 2\n1 5 3", "output": "2" }, { "input": "3 1\n3 2 2", "output": "1" }, { "input": "3 1\n2 3 2", "output": "2" }, { "input": "5 1\n5 1 1 1 1", "output": "1" }, { "input": "2 3\n7 4", "output": "1" } ]
31
0
0
156
977
Wrong Subtraction
[ "implementation" ]
null
null
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions. It is guaranteed that the result will be positive integer number.
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) β€” the number from which Tanya will subtract and the number of subtractions correspondingly.
Print one integer number β€” the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number.
[ "512 4\n", "1000000000 9\n" ]
[ "50\n", "1\n" ]
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
[ { "input": "512 4", "output": "50" }, { "input": "1000000000 9", "output": "1" }, { "input": "131203 11", "output": "12" }, { "input": "999999999 50", "output": "9999" }, { "input": "999999999 49", "output": "99990" }, { "input": "131203 9", "output": "130" }, { "input": "900000000 16", "output": "1" }, { "input": "909090909 50", "output": "3" }, { "input": "1001 2", "output": "100" }, { "input": "5 2", "output": "3" }, { "input": "2 1", "output": "1" } ]
77
0
3
158
385
Bear and Raspberry
[ "brute force", "greedy", "implementation" ]
null
null
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≀<=*i*<=≀<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry. Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≀<=*d*<=&lt;<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel. The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.
The first line contains two space-separated integers, *n* and *c* (2<=≀<=*n*<=≀<=100,<=0<=≀<=*c*<=≀<=100), β€” the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≀<=*x**i*<=≀<=100), the price of a honey barrel on day *i*.
Print a single integer β€” the answer to the problem.
[ "5 1\n5 10 7 3 20\n", "6 2\n100 1 10 40 10 40\n", "3 0\n1 2 3\n" ]
[ "3\n", "97\n", "0\n" ]
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3. In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97.
[ { "input": "5 1\n5 10 7 3 20", "output": "3" }, { "input": "6 2\n100 1 10 40 10 40", "output": "97" }, { "input": "3 0\n1 2 3", "output": "0" }, { "input": "2 0\n2 1", "output": "1" }, { "input": "10 5\n10 1 11 2 12 3 13 4 14 5", "output": "4" }, { "input": "100 4\n2 57 70 8 44 10 88 67 50 44 93 79 72 50 69 19 21 9 71 47 95 13 46 10 68 72 54 40 15 83 57 92 58 25 4 22 84 9 8 55 87 0 16 46 86 58 5 21 32 28 10 46 11 29 13 33 37 34 78 33 33 21 46 70 77 51 45 97 6 21 68 61 87 54 8 91 37 12 76 61 57 9 100 45 44 88 5 71 98 98 26 45 37 87 34 50 33 60 64 77", "output": "87" }, { "input": "100 5\n15 91 86 53 18 52 26 89 8 4 5 100 11 64 88 91 35 57 67 72 71 71 69 73 97 23 11 1 59 86 37 82 6 67 71 11 7 31 11 68 21 43 89 54 27 10 3 33 8 57 79 26 90 81 6 28 24 7 33 50 24 13 27 85 4 93 14 62 37 67 33 40 7 48 41 4 14 9 95 10 64 62 7 93 23 6 28 27 97 64 26 83 70 0 97 74 11 82 70 93", "output": "84" }, { "input": "6 100\n10 9 8 7 6 5", "output": "0" }, { "input": "100 9\n66 71 37 41 23 38 77 11 74 13 51 26 93 56 81 17 12 70 85 37 54 100 14 99 12 83 44 16 99 65 13 48 92 32 69 33 100 57 58 88 25 45 44 85 5 41 82 15 37 18 21 45 3 68 33 9 52 64 8 73 32 41 87 99 26 26 47 24 79 93 9 44 11 34 85 26 14 61 49 38 25 65 49 81 29 82 28 23 2 64 38 13 77 68 67 23 58 57 83 46", "output": "78" }, { "input": "100 100\n9 72 46 37 26 94 80 1 43 85 26 53 58 18 24 19 67 2 100 52 61 81 48 15 73 41 97 93 45 1 73 54 75 51 28 79 0 14 41 42 24 50 70 18 96 100 67 1 68 48 44 39 63 77 78 18 10 51 32 53 26 60 1 13 66 39 55 27 23 71 75 0 27 88 73 31 16 95 87 84 86 71 37 40 66 70 65 83 19 4 81 99 26 51 67 63 80 54 23 44", "output": "0" }, { "input": "43 65\n32 58 59 75 85 18 57 100 69 0 36 38 79 95 82 47 7 55 28 88 27 88 63 71 80 86 67 53 69 37 99 54 81 19 55 12 2 17 84 77 25 26 62", "output": "4" }, { "input": "12 64\n14 87 40 24 32 36 4 41 38 77 68 71", "output": "0" }, { "input": "75 94\n80 92 25 48 78 17 69 52 79 73 12 15 59 55 25 61 96 27 98 43 30 43 36 94 67 54 86 99 100 61 65 8 65 19 18 21 75 31 2 98 55 87 14 1 17 97 94 11 57 29 34 71 76 67 45 0 78 29 86 82 29 23 77 100 48 43 65 62 88 34 7 28 13 1 1", "output": "0" }, { "input": "59 27\n76 61 24 66 48 18 69 84 21 8 64 90 19 71 36 90 9 36 30 37 99 37 100 56 9 79 55 37 54 63 11 11 49 71 91 70 14 100 10 44 52 23 21 19 96 13 93 66 52 79 76 5 62 6 90 35 94 7 27", "output": "63" }, { "input": "86 54\n41 84 16 5 20 79 73 13 23 24 42 73 70 80 69 71 33 44 62 29 86 88 40 64 61 55 58 19 16 23 84 100 38 91 89 98 47 50 55 87 12 94 2 12 0 1 4 26 50 96 68 34 94 80 8 22 60 3 72 84 65 89 44 52 50 9 24 34 81 28 56 17 38 85 78 90 62 60 1 40 91 2 7 41 84 22", "output": "38" }, { "input": "37 2\n65 36 92 92 92 76 63 56 15 95 75 26 15 4 73 50 41 92 26 20 19 100 63 55 25 75 61 96 35 0 14 6 96 3 28 41 83", "output": "91" }, { "input": "19 4\n85 2 56 70 33 75 89 60 100 81 42 28 18 92 29 96 49 23 14", "output": "79" }, { "input": "89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 35 55 88 53 87 61 22 100 56 14 87 36 84 24", "output": "91" }, { "input": "67 0\n40 48 15 46 90 7 65 52 24 15 42 81 2 6 71 94 32 18 97 67 83 98 48 51 10 47 8 68 36 46 65 75 90 30 62 9 5 35 80 60 69 58 62 68 58 73 80 9 22 46 56 64 44 11 93 73 62 54 15 20 17 69 16 33 85 62 49", "output": "83" }, { "input": "96 0\n38 97 82 43 80 40 1 99 50 94 81 63 92 13 57 24 4 10 25 32 79 56 96 19 25 14 69 56 66 22 23 78 87 76 37 30 75 77 61 64 35 64 62 32 44 62 6 84 91 44 99 5 71 19 17 12 35 52 1 14 35 18 8 36 54 42 4 67 80 11 88 44 34 35 12 38 66 42 4 90 45 10 1 44 37 96 23 28 100 90 75 17 27 67 51 70", "output": "94" }, { "input": "14 14\n87 63 62 31 59 47 40 89 92 43 80 30 99 42", "output": "43" }, { "input": "12 0\n100 1 100 2 100 3 100 4 100 5 100 0", "output": "100" }, { "input": "3 1\n1 2 3", "output": "0" }, { "input": "3 2\n3 3 3", "output": "0" }, { "input": "3 3\n3 2 1", "output": "0" }, { "input": "3 100\n1 2 3", "output": "0" }, { "input": "2 100\n0 0", "output": "0" }, { "input": "2 90\n10 5", "output": "0" }, { "input": "2 5\n5 4", "output": "0" }, { "input": "3 1\n19 20 1", "output": "18" }, { "input": "5 1\n5 10 7 4 20", "output": "2" }, { "input": "5 1\n1 2 3 4 5", "output": "0" } ]
187
0
3
159
103
Testing Pants for Sadness
[ "greedy", "implementation", "math" ]
A. Testing Pants for Sadness
2
256
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question *n*. Question *i* contains *a**i* answer variants, exactly one of them is correct. A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the *n* questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves. Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≀<=*a**i*<=≀<=109), the number of answer variants to question *i*.
Print a single number β€” the minimal number of clicks needed to pass the test it the worst-case scenario. Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2\n1 1\n", "2\n2 2\n", "1\n10\n" ]
[ "2", "5", "10" ]
Note to the second sample. In the worst-case scenario you will need five clicks: - the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the third click selects the first variant to the second question, it is wrong and we go back to question 1; - the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question; - the fifth click selects the second variant to the second question, it proves correct, the test is finished.
[ { "input": "2\n1 1", "output": "2" }, { "input": "2\n2 2", "output": "5" }, { "input": "1\n10", "output": "10" }, { "input": "3\n2 4 1", "output": "10" }, { "input": "4\n5 5 3 1", "output": "22" }, { "input": "2\n1000000000 1000000000", "output": "2999999999" }, { "input": "10\n5 7 8 1 10 3 6 4 10 6", "output": "294" }, { "input": "100\n5 7 5 3 5 4 6 5 3 6 4 6 6 2 1 9 6 5 3 8 4 10 1 9 1 3 7 6 5 5 8 8 7 7 8 9 2 10 3 5 4 2 6 10 2 6 9 6 1 9 3 7 7 8 3 9 9 5 10 10 3 10 7 8 3 9 8 3 2 4 10 2 1 1 7 3 9 10 4 6 9 8 2 1 4 10 1 10 6 8 7 5 3 3 6 2 7 10 3 8", "output": "24212" }, { "input": "100\n96 23 25 62 34 30 85 15 26 61 59 87 34 99 60 41 52 73 63 84 50 89 42 29 87 99 19 94 84 43 82 90 41 100 60 61 99 49 26 3 97 5 24 34 51 59 69 61 11 41 72 60 33 36 18 29 82 53 18 80 52 98 38 32 56 95 55 79 32 80 37 64 45 13 62 80 70 29 1 58 88 24 79 68 41 80 12 72 52 39 64 19 54 56 70 58 19 3 83 62", "output": "261115" }, { "input": "100\n883 82 79 535 478 824 700 593 262 385 403 183 176 386 126 648 710 516 922 97 800 728 372 9 954 911 975 526 476 3 74 459 471 174 295 831 698 21 927 698 580 856 712 430 5 473 592 40 301 230 763 266 38 213 393 70 333 779 811 249 130 456 763 657 578 699 939 660 898 918 438 855 892 85 35 232 54 593 849 777 917 979 796 322 473 887 284 105 522 415 86 480 80 592 516 227 680 574 488 644", "output": "2519223" }, { "input": "100\n6659 5574 5804 7566 7431 1431 3871 6703 200 300 3523 3580 8500 2312 4812 3149 3324 5846 8965 5758 5831 1341 7733 4477 355 3024 2941 9938 1494 16 1038 8262 9938 9230 5192 8113 7575 7696 5566 2884 8659 1951 1253 6480 3877 3707 5482 3825 5359 44 3219 3258 1785 5478 4525 5950 2417 1991 8885 4264 8769 2961 7107 8904 5097 2319 5713 8811 9723 8677 2153 3237 7174 9528 9260 7390 3050 6823 6239 5222 4602 933 7823 4198 8304 244 5845 3189 4490 3216 7877 6323 1938 4597 880 1206 1691 1405 4122 5950", "output": "24496504" }, { "input": "50\n515844718 503470143 928669067 209884122 322869098 241621928 844696197 105586164 552680307 968792756 135928721 842094825 298782438 829020472 791637138 285482545 811025527 428952878 887796419 11883658 546401594 6272027 100292274 308219869 372132044 955814846 644008184 521195760 919389466 215065725 687764134 655750167 181397022 404292682 643251185 776299412 741398345 865144798 369796727 673902099 124966684 35796775 794385099 594562033 550366869 868093561 695094388 580789105 755076935 198783899", "output": "685659563557" }, { "input": "10\n12528238 329065023 620046219 303914458 356423530 751571368 72944261 883971060 123105651 868129460", "output": "27409624352" }, { "input": "1\n84355694", "output": "84355694" }, { "input": "2\n885992042 510468669", "output": "1906929379" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "100\n2 1 2 2 2 2 1 2 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 1 2 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 2 2 2 1 2 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 1 1 1 2 1 2 2 2 1 1 1", "output": "2686" }, { "input": "100\n1 3 2 1 1 2 1 3 2 2 3 1 1 1 2 2 1 3 3 1 1 2 2 3 2 1 3 1 3 2 1 1 3 3 2 1 2 2 2 3 2 2 3 2 2 3 2 1 3 1 1 2 1 3 2 2 1 1 1 1 1 1 3 1 2 3 1 1 1 1 1 2 3 3 1 1 1 1 2 3 3 1 3 2 2 3 2 1 3 2 2 3 1 1 3 2 3 2 3 1", "output": "4667" } ]
124
0
3.969
160
886
Vlad and Cafes
[]
null
null
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
In first line there is one integer *n* (1<=≀<=*n*<=≀<=2Β·105)Β β€” number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=2Β·105) are writtenΒ β€” indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Print one integerΒ β€” index of the cafe that Vlad hasn't visited for as long as possible.
[ "5\n1 3 2 1 2\n", "6\n2 1 2 2 4 1\n" ]
[ "3\n", "2\n" ]
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
[ { "input": "5\n1 3 2 1 2", "output": "3" }, { "input": "6\n2 1 2 2 4 1", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "1\n200000", "output": "200000" }, { "input": "2\n2018 2017", "output": "2018" }, { "input": "5\n100 1000 1000 1000 1000", "output": "100" }, { "input": "8\n200000 1 200000 1 200000 1 200000 2", "output": "1" }, { "input": "5\n20000 1 2 3 4", "output": "20000" }, { "input": "2\n200000 1", "output": "200000" }, { "input": "3\n2 100 2", "output": "100" }, { "input": "2\n10 1", "output": "10" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "3\n5 5 5", "output": "5" }, { "input": "2\n5 1", "output": "5" } ]
46
0
-1
162
200
Drinks
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink.
The first input line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≀<=*p**i*<=≀<=100) β€” the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3Β·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent.
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39 75", "output": "48.142857142857" }, { "input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22", "output": "11.615384615385" }, { "input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18", "output": "12.761904761905" }, { "input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84", "output": "69.538461538462" }, { "input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94", "output": "91.551724137931" }, { "input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100", "output": "99.515151515152" }, { "input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2", "output": "8.147058823529" }, { "input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93", "output": "91.921052631579" }, { "input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100", "output": "97.019230769231" }, { "input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6", "output": "50.965517241379" }, { "input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10", "output": "7.505882352941" }, { "input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6", "output": "10.418918918919" }, { "input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41", "output": "20.928571428571" }, { "input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96", "output": "49.191919191919" }, { "input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92", "output": "73.484848484848" }, { "input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6", "output": "7.640000000000" }, { "input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100", "output": "77.660000000000" }, { "input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81", "output": "91.480000000000" }, { "input": "1\n0", "output": "0.000000000000" }, { "input": "1\n100", "output": "100.000000000000" }, { "input": "1\n78", "output": "78.000000000000" }, { "input": "2\n0 100", "output": "50.000000000000" }, { "input": "2\n100 100", "output": "100.000000000000" }, { "input": "5\n0 0 0 0 1", "output": "0.200000000000" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99", "output": "99.990000000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1", "output": "0.010000000000" }, { "input": "5\n100 100 100 100 100", "output": "100.000000000000" } ]
92
0
3
163
463
Gargari and Bishops
[ "greedy", "hashing", "implementation" ]
null
null
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a *n*<=Γ—<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number *x* written on it, if this cell is attacked by one of the bishops Gargari will get *x* dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).
The first line contains a single integer *n* (2<=≀<=*n*<=≀<=2000). Each of the next *n* lines contains *n* integers *a**ij* (0<=≀<=*a**ij*<=≀<=109) β€” description of the chessboard.
On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≀<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≀<=*n*), where *x**i* is the number of the row where the *i*-th bishop should be placed, *y**i* is the number of the column where the *i*-th bishop should be placed. Consider rows are numbered from 1 to *n* from top to bottom, and columns are numbered from 1 to *n* from left to right. If there are several optimal solutions, you can print any of them.
[ "4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n" ]
[ "12\n2 2 3 2\n" ]
none
[ { "input": "4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1", "output": "12\n2 2 3 2" }, { "input": "10\n48 43 75 80 32 30 65 31 18 91\n99 5 12 43 26 90 54 91 4 88\n8 87 68 95 73 37 53 46 53 90\n50 1 85 24 32 16 5 48 98 74\n38 49 78 2 91 3 43 96 93 46\n35 100 84 2 94 56 90 98 54 43\n88 3 95 72 78 78 87 82 25 37\n8 15 85 85 68 27 40 10 22 84\n7 8 36 90 10 81 98 51 79 51\n93 66 53 39 89 30 16 27 63 93", "output": "2242\n6 6 7 6" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0", "output": "0\n1 1 1 2" }, { "input": "15\n2 6 9 4 8 9 10 10 3 8 8 4 4 8 7\n10 9 2 6 8 10 5 2 8 4 9 6 9 10 10\n3 1 5 1 6 5 1 6 4 4 3 3 9 8 10\n5 7 10 6 4 9 6 8 1 5 4 9 10 4 8\n9 6 10 5 8 6 9 9 3 4 4 7 6 2 4\n8 6 10 7 3 3 8 10 3 8 4 8 8 3 1\n7 3 6 8 8 5 5 8 3 7 2 6 3 9 7\n6 8 4 7 7 7 10 4 6 4 3 10 1 10 2\n1 6 7 8 3 4 2 8 1 7 4 4 4 9 5\n3 4 4 6 1 10 2 2 5 8 7 7 7 7 6\n10 9 3 6 8 6 1 9 5 4 7 10 7 1 8\n3 3 4 9 8 6 10 2 9 5 9 5 3 7 3\n1 8 1 3 4 8 10 4 8 4 7 5 4 6 7\n3 10 9 6 8 8 1 8 9 9 4 9 5 6 5\n7 6 3 9 9 8 6 10 3 6 4 2 10 9 7", "output": "361\n7 9 9 8" }, { "input": "8\n3 6 9 2 2 1 4 2\n1 4 10 1 1 10 1 4\n3 8 9 1 8 4 4 4\n5 8 10 5 5 6 4 7\n3 2 10 6 5 3 8 5\n6 7 5 8 8 5 4 2\n4 4 3 1 8 8 5 4\n5 6 8 9 3 1 8 5", "output": "159\n4 4 5 4" }, { "input": "13\n9 9 3 3 5 6 8 2 6 1 10 3 8\n10 4 9 2 10 3 5 10 10 7 10 7 3\n5 8 4 1 10 2 1 2 4 7 9 1 10\n6 3 10 10 10 1 3 10 4 4 2 10 4\n1 7 5 7 9 9 7 4 1 8 5 4 1\n10 10 9 2 2 6 4 1 5 5 1 9 4\n4 2 5 5 7 8 1 2 6 1 2 4 6\n5 1 10 8 1 1 9 1 2 10 6 7 2\n2 1 2 10 4 7 4 1 4 10 10 4 3\n7 7 5 1 2 1 1 4 8 2 4 8 2\n8 8 8 4 1 1 7 3 1 10 1 4 2\n4 5 1 10 8 8 8 4 10 9 4 10 4\n3 1 10 10 5 7 9 4 2 10 4 8 4", "output": "280\n6 6 7 6" }, { "input": "9\n3 9 6 1 7 6 2 8 4\n5 4 1 1 7 2 7 4 10\n7 9 9 4 6 2 7 2 8\n5 7 7 4 9 5 9 1 3\n7 3 10 2 9 4 2 1 2\n5 8 7 4 6 6 2 2 3\n4 8 4 3 4 2 1 8 10\n5 8 2 8 4 4 7 5 4\n2 8 7 4 3 6 10 8 1", "output": "181\n5 4 6 4" } ]
77
2,457,600
0
164
919
Perfect Number
[ "binary search", "brute force", "dp", "implementation", "number theory" ]
null
null
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
A single number, denoting the $k$-th smallest perfect integer.
[ "1\n", "2\n" ]
[ "19\n", "28\n" ]
The first perfect integer is $19$ and the second one is $28$.
[ { "input": "1", "output": "19" }, { "input": "2", "output": "28" }, { "input": "13", "output": "136" }, { "input": "101", "output": "1432" }, { "input": "1023", "output": "100270" }, { "input": "9999", "output": "10800010" }, { "input": "10000", "output": "10800100" }, { "input": "2333", "output": "310060" }, { "input": "9139", "output": "10134010" }, { "input": "9859", "output": "10422001" }, { "input": "5987", "output": "2221201" }, { "input": "3", "output": "37" }, { "input": "4", "output": "46" }, { "input": "5", "output": "55" }, { "input": "7", "output": "73" }, { "input": "9", "output": "91" }, { "input": "10", "output": "109" }, { "input": "15", "output": "154" }, { "input": "51", "output": "613" }, { "input": "99", "output": "1414" }, { "input": "138", "output": "2224" }, { "input": "233", "output": "5050" }, { "input": "666", "output": "27100" }, { "input": "1234", "output": "110206" }, { "input": "3567", "output": "1033003" }, { "input": "4445", "output": "1221301" }, { "input": "5689", "output": "2114002" }, { "input": "6666", "output": "3102004" }, { "input": "7777", "output": "5300200" }, { "input": "8888", "output": "10110061" }, { "input": "9411", "output": "10214200" }, { "input": "5539", "output": "2101114" }, { "input": "6259", "output": "2511100" }, { "input": "2387", "output": "312220" }, { "input": "8515", "output": "10030114" } ]
30
0
0
165
23
Party
[ "constructive algorithms", "graphs", "math" ]
B. Party
2
256
*n* people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,<=3,<=...,<=*n*<=-<=1 friends among those who stayed by the moment of their leaving, did the same. What is the maximum amount of people that could stay at the party in the end?
The first input line contains one number *t* β€” amount of tests (1<=≀<=*t*<=≀<=105). Each of the following *t* lines contains one integer number *n* (1<=≀<=*n*<=≀<=105).
For each test output in a separate line one number β€” the maximum amount of people that could stay in the end.
[ "1\n3\n" ]
[ "1\n" ]
none
[ { "input": "1\n3", "output": "1" } ]
2,000
8,192,000
0
166
349
Cinema Line
[ "greedy", "implementation" ]
null
null
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?
The first line contains integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 β€” the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
[ "4\n25 25 50 50\n", "2\n25 100\n", "4\n50 50 25 25\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
[ { "input": "4\n25 25 50 50", "output": "YES" }, { "input": "2\n25 100", "output": "NO" }, { "input": "4\n50 50 25 25", "output": "NO" }, { "input": "3\n25 50 100", "output": "NO" }, { "input": "10\n25 25 25 25 25 25 25 25 25 25", "output": "YES" }, { "input": "10\n50 50 50 50 50 50 50 50 50 50", "output": "NO" }, { "input": "10\n100 100 100 100 100 100 100 100 100 100", "output": "NO" }, { "input": "7\n25 25 25 25 50 100 50", "output": "YES" }, { "input": "2\n25 25", "output": "YES" }, { "input": "3\n50 100 100", "output": "NO" }, { "input": "3\n25 50 50", "output": "NO" }, { "input": "2\n50 25", "output": "NO" }, { "input": "14\n25 25 25 25 25 25 25 50 50 50 100 100 100 100", "output": "NO" }, { "input": "5\n25 25 25 100 100", "output": "NO" }, { "input": "7\n25 50 25 50 25 50 100", "output": "NO" }, { "input": "5\n25 50 25 50 100", "output": "NO" }, { "input": "5\n25 25 50 50 50", "output": "NO" }, { "input": "5\n25 25 50 100 50", "output": "NO" }, { "input": "5\n25 25 50 50 100", "output": "NO" }, { "input": "1\n50", "output": "NO" } ]
2,000
14,540,800
0
167
61
Ultra-Fast Mathematician
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line β€” the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
77
6,758,400
3.968161
169
899
Dividing the numbers
[ "constructive algorithms", "graphs", "math" ]
null
null
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help Petya to split the integers. Each of *n* integers should be exactly in one group.
The first line contains a single integer *n* (2<=≀<=*n*<=≀<=60<=000) β€” the number of integers Petya has.
Print the smallest possible absolute difference in the first line. In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
[ "4\n", "2\n" ]
[ "0\n2 1 4 \n", "1\n1 1 \n" ]
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0. In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.
[ { "input": "4", "output": "0\n2 1 4 " }, { "input": "2", "output": "1\n1 1 " }, { "input": "3", "output": "0\n1\n3 " }, { "input": "5", "output": "1\n3\n1 2 5 " }, { "input": "59998", "output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "60000", "output": "0\n30000 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59991", "output": "0\n29995\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "59989", "output": "1\n29995\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "6", "output": "1\n3 1 4 5 " }, { "input": "7", "output": "0\n3\n1 6 7 " }, { "input": "8", "output": "0\n4 1 4 5 8 " }, { "input": "9", "output": "1\n5\n1 2 3 8 9 " }, { "input": "10", "output": "1\n5 1 4 5 8 9 " }, { "input": "11", "output": "0\n5\n1 2 9 10 11 " }, { "input": "12", "output": "0\n6 1 4 5 8 9 12 " }, { "input": "13", "output": "1\n7\n1 2 3 4 11 12 13 " }, { "input": "14", "output": "1\n7 1 4 5 8 9 12 13 " }, { "input": "15", "output": "0\n7\n1 2 3 12 13 14 15 " }, { "input": "16", "output": "0\n8 1 4 5 8 9 12 13 16 " }, { "input": "17", "output": "1\n9\n1 2 3 4 5 14 15 16 17 " }, { "input": "18", "output": "1\n9 1 4 5 8 9 12 13 16 17 " }, { "input": "19", "output": "0\n9\n1 2 3 4 15 16 17 18 19 " }, { "input": "20", "output": "0\n10 1 4 5 8 9 12 13 16 17 20 " }, { "input": "21", "output": "1\n11\n1 2 3 4 5 6 17 18 19 20 21 " }, { "input": "22", "output": "1\n11 1 4 5 8 9 12 13 16 17 20 21 " }, { "input": "23", "output": "0\n11\n1 2 3 4 5 18 19 20 21 22 23 " }, { "input": "24", "output": "0\n12 1 4 5 8 9 12 13 16 17 20 21 24 " }, { "input": "59999", "output": "0\n29999\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "59997", "output": "1\n29999\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "59996", "output": "0\n29998 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59995", "output": "0\n29997\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "59994", "output": "1\n29997 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59993", "output": "1\n29997\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "59992", "output": "0\n29996 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "59990", "output": "1\n29995 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "100", "output": "0\n50 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 " }, { "input": "1000", "output": "0\n500 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..." }, { "input": "10001", "output": "1\n5001\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..." }, { "input": "103", "output": "0\n51\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 " }, { "input": "1002", "output": "1\n501 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..." }, { "input": "31724", "output": "0\n15862 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "2032", "output": "0\n1016 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "42620", "output": "0\n21310 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "18076", "output": "0\n9038 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "53520", "output": "0\n26760 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "37193", "output": "1\n18597\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "12645", "output": "1\n6323\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..." }, { "input": "53237", "output": "1\n26619\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "28693", "output": "1\n14347\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "4145", "output": "1\n2073\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..." }, { "input": "36042", "output": "1\n18021 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "16646", "output": "1\n8323 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "57238", "output": "1\n28619 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "27542", "output": "1\n13771 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..." }, { "input": "8146", "output": "1\n4073 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..." }, { "input": "46659", "output": "0\n23329\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "27259", "output": "0\n13629\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "2715", "output": "0\n1357\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..." }, { "input": "38159", "output": "0\n19079\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 1..." }, { "input": "18759", "output": "0\n9379\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 15..." } ]
62
0
0
170
955
Sad powers
[ "binary search", "math", "number theory" ]
null
null
You're given *Q* queries of the form (*L*,<=*R*). For each query you have to find the number of such *x* that *L*<=≀<=*x*<=≀<=*R* and there exist integer numbers *a*<=&gt;<=0, *p*<=&gt;<=1 such that *x*<==<=*a**p*.
The first line contains the number of queries *Q* (1<=≀<=*Q*<=≀<=105). The next *Q* lines contains two integers *L*, *R* each (1<=≀<=*L*<=≀<=*R*<=≀<=1018).
Output *Q* lines β€” the answers to the queries.
[ "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n" ]
[ "2\n1\n0\n3\n17\n1111\n" ]
In query one the suitable numbers are 1 and 4.
[ { "input": "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000", "output": "2\n1\n0\n3\n17\n1111" }, { "input": "20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770", "output": "1\n4\n5\n6\n14\n32\n20\n9\n0\n2\n1\n1\n6\n4\n4\n15\n26\n2\n2\n4" } ]
2,000
49,664,000
0
172
999
Alphabetic Removals
[ "implementation" ]
null
null
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string.
The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) β€” the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters.
Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).
[ "15 3\ncccaabababaccbc\n", "15 9\ncccaabababaccbc\n", "1 1\nu\n" ]
[ "cccbbabaccbc\n", "cccccc\n", "" ]
none
[ { "input": "15 3\ncccaabababaccbc", "output": "cccbbabaccbc" }, { "input": "15 9\ncccaabababaccbc", "output": "cccccc" }, { "input": "5 2\nzyzyx", "output": "zzy" }, { "input": "4 3\nhack", "output": "k" }, { "input": "4 3\nzzzz", "output": "z" }, { "input": "6 5\naaccdd", "output": "d" }, { "input": "2 1\nzz", "output": "z" }, { "input": "14 5\nhxehmvkybeklnj", "output": "xmvkyklnj" } ]
77
6,860,800
3
173
339
Xenia and Ringroad
[ "implementation" ]
null
null
Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise. Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete the *i*-th task, she needs to be in the house number *a**i* and complete all tasks with numbers less than *i*. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
The first line contains two integers *n* and *m* (2<=≀<=*n*<=≀<=105,<=1<=≀<=*m*<=≀<=105). The second line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≀<=*a**i*<=≀<=*n*). Note that Xenia can have multiple consecutive tasks in one house.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "4 3\n3 2 3\n", "4 3\n2 3 3\n" ]
[ "6\n", "2\n" ]
In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
[ { "input": "4 3\n3 2 3", "output": "6" }, { "input": "4 3\n2 3 3", "output": "2" }, { "input": "2 2\n1 1", "output": "0" }, { "input": "2 2\n1 2", "output": "1" }, { "input": "2 2\n1 2", "output": "1" }, { "input": "100 100\n56 46 1 47 5 86 45 35 81 1 31 70 67 70 62 99 100 47 44 33 78 35 32 37 92 12 95 18 3 22 54 24 22 90 25 22 78 88 51 92 46 84 15 29 28 40 8 5 93 68 77 47 45 76 85 39 84 94 52 69 93 64 31 60 99 17 51 59 62 37 46 47 86 60 88 14 68 22 47 93 50 10 55 87 46 50 43 63 44 43 61 65 91 43 33 97 67 57 66 70", "output": "4869" }, { "input": "78 58\n23 14 73 45 47 14 27 59 65 39 15 23 5 1 50 37 3 51 46 69 75 65 45 68 48 59 77 39 53 21 72 33 46 32 34 5 69 55 56 53 47 31 32 5 42 23 76 15 2 77 65 24 16 68 61 28 55 10", "output": "2505" }, { "input": "14 54\n9 13 14 9 5 12 4 7 3 14 5 12 13 1 1 11 10 2 7 9 5 2 2 8 10 7 3 9 5 11 2 2 6 12 11 5 4 11 11 6 2 11 14 13 8 7 13 9 4 9 11 3 7 13", "output": "362" }, { "input": "100 100\n48 73 63 16 49 88 36 17 66 6 87 13 94 52 58 70 71 52 7 70 25 42 24 36 57 9 79 26 75 39 13 14 38 26 33 66 88 28 75 98 53 48 67 54 63 25 69 87 88 32 72 17 36 35 29 67 74 89 70 47 20 90 78 13 94 57 32 73 29 74 45 78 85 64 81 56 12 65 19 67 34 86 55 71 41 33 76 13 100 47 44 76 86 78 37 15 26 98 83 98", "output": "4997" }, { "input": "99 100\n88 65 10 91 18 35 58 49 42 2 22 57 74 31 53 24 27 93 45 4 71 2 69 39 21 90 97 89 45 73 20 45 82 98 35 90 37 76 68 26 21 65 95 63 24 74 50 59 3 93 65 6 30 37 62 71 18 88 40 12 56 40 89 56 38 71 90 41 97 43 44 23 19 22 10 80 3 24 32 85 26 65 70 60 76 85 66 68 74 11 64 88 12 63 16 15 79 57 93 58", "output": "4809" }, { "input": "65 100\n53 14 5 10 32 60 31 52 52 56 38 6 8 17 52 23 59 3 18 28 15 2 46 26 8 2 40 6 58 30 28 46 49 23 47 24 9 53 3 47 55 12 36 49 12 24 54 55 58 7 50 42 15 4 58 49 34 40 19 4 59 19 31 17 35 65 36 50 45 5 33 11 29 52 55 40 48 11 32 41 31 7 46 55 32 41 56 51 39 13 5 59 58 34 38 50 55 10 43 30", "output": "3149" }, { "input": "10 100\n7 6 2 10 7 2 3 8 10 4 6 1 4 5 7 10 1 2 3 5 4 10 8 2 3 3 6 8 3 9 4 1 9 10 1 2 5 1 8 8 5 9 2 8 1 2 3 2 1 10 10 7 1 3 2 2 7 1 6 6 6 9 2 3 1 7 2 2 9 7 3 3 2 10 7 4 7 3 3 3 2 4 4 2 2 8 4 1 10 10 5 10 6 10 6 10 3 10 8 9", "output": "428" }, { "input": "2 100\n1 1 2 2 2 2 1 2 1 2 2 2 1 1 2 2 2 2 1 1 2 1 2 2 1 1 2 2 2 1 2 1 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 1 1 2 2 1 2 1 2 2 2 1 1 1 1 1 2 2 2 1 1 2 2 1 1 2 2 1 1 2 1 1 1 1 2 2 1 1 1 2 1 1 1 1 1 1 1 2", "output": "47" }, { "input": "67 100\n49 5 25 48 37 55 5 33 14 30 59 28 57 46 45 32 47 22 40 28 58 34 27 29 4 52 63 44 31 65 42 61 11 17 32 17 18 1 12 33 38 11 59 46 43 55 23 30 23 2 42 21 45 51 30 19 35 15 10 30 13 21 32 34 33 3 5 59 23 63 6 9 20 43 64 3 42 41 40 4 14 20 40 33 25 44 1 2 50 46 13 10 3 20 22 64 28 42 58 30", "output": "3245" }, { "input": "100 100\n81 62 26 90 7 87 60 35 75 81 54 94 53 71 64 80 58 83 53 70 40 96 87 50 37 63 5 77 83 75 53 28 22 98 52 45 72 70 62 21 1 99 37 93 16 98 68 27 96 37 21 83 92 23 62 96 85 31 85 66 38 77 45 16 90 86 6 21 75 42 18 60 2 17 51 61 94 68 97 79 17 59 66 14 87 78 70 40 63 78 58 22 87 7 90 17 20 97 9 31", "output": "5530" }, { "input": "2 1\n1", "output": "0" }, { "input": "2 10\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "2 10\n1 1 1 2 2 2 1 1 1 2", "output": "3" }, { "input": "3 6\n1 2 3 3 2 1", "output": "6" } ]
154
12,185,600
3
175
80
Panoramix's Prediction
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 isΒ not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
The first and only input line contains two positive integers β€” *n* and *m* (2<=≀<=*n*<=&lt;<=*m*<=≀<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≀<=*n*<=&lt;<=*m*<=≀<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", "output": "YES" }, { "input": "5 7", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "11 13", "output": "YES" }, { "input": "13 17", "output": "YES" }, { "input": "17 19", "output": "YES" }, { "input": "19 23", "output": "YES" }, { "input": "23 29", "output": "YES" }, { "input": "29 31", "output": "YES" }, { "input": "31 37", "output": "YES" }, { "input": "37 41", "output": "YES" }, { "input": "41 43", "output": "YES" }, { "input": "43 47", "output": "YES" }, { "input": "2 5", "output": "NO" }, { "input": "2 7", "output": "NO" }, { "input": "2 6", "output": "NO" }, { "input": "2 11", "output": "NO" }, { "input": "3 6", "output": "NO" }, { "input": "3 7", "output": "NO" }, { "input": "3 9", "output": "NO" }, { "input": "5 6", "output": "NO" }, { "input": "5 9", "output": "NO" }, { "input": "5 11", "output": "NO" }, { "input": "5 13", "output": "NO" }, { "input": "5 15", "output": "NO" }, { "input": "7 8", "output": "NO" }, { "input": "7 13", "output": "NO" }, { "input": "13 15", "output": "NO" }, { "input": "13 17", "output": "YES" }, { "input": "19 21", "output": "NO" }, { "input": "13 20", "output": "NO" }, { "input": "41 49", "output": "NO" }, { "input": "43 49", "output": "NO" }, { "input": "47 50", "output": "NO" }, { "input": "47 49", "output": "NO" }, { "input": "47 48", "output": "NO" }, { "input": "23 25", "output": "NO" }, { "input": "2 50", "output": "NO" }, { "input": "31 33", "output": "NO" } ]
184
0
3.954
176
44
Indian Summer
[ "implementation" ]
A. Indian Summer
2
256
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy β€” she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.
Output the single number β€” the number of Alyona's leaves.
[ "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n", "3\noak yellow\noak yellow\noak yellow\n" ]
[ "4\n", "1\n" ]
none
[ { "input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green", "output": "4" }, { "input": "3\noak yellow\noak yellow\noak yellow", "output": "1" }, { "input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae", "output": "5" }, { "input": "1\nqvwli hz", "output": "1" }, { "input": "4\nsrhk x\nsrhk x\nqfoe vnrjuab\nqfoe vnrjuab", "output": "2" }, { "input": "4\nsddqllmmpk syded\nfprsq fnenjnaz\nn hdej\nsddqllmmpk syded", "output": "3" }, { "input": "17\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw", "output": "1" }, { "input": "18\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nb d\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp", "output": "2" }, { "input": "13\nsvpzwtwn rykzfdce\nqweiyeck jkreouy\nhk nnli\ntwxrnbbdt vtuv\nxokqjtylly sz\nesdt dbfidjslq\ng ybqgomvw\nxcpfjmf zcqvz\nifajadhj invzueip\nvdemdnxifb hckwebmi\nsdpnhipam wvowzavh\nuqdlfskhgo vunbpghae\ne dtigwnb", "output": "13" }, { "input": "20\nm vkfh\nvptikamead mvx\nitu mf\nklruxckw aqega\nekqkd enjllwol\ncc uybfdh\nimrfdngvo u\ne uh\ntwt jsslcfuogk\nbljwqsag tuqbdn\nqcv q\nasx gzhvwwmajj\nqcv q\nekqkd enjllwol\nasx gzhvwwmajj\nks vv\nkzyfi cn\ncc uybfdh\nitu mf\ncjbjhtbyvk vatwfmux", "output": "15" }, { "input": "2\nab ab\na bab", "output": "2" } ]
92
0
3.977
177
600
Queries about less or equal elements
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≀<=*n*,<=*m*<=≀<=2Β·105) β€” the sizes of arrays *a* and *b*. The second line contains *n* integers β€” the elements of array *a* (<=-<=109<=≀<=*a**i*<=≀<=109). The third line contains *m* integers β€” the elements of array *b* (<=-<=109<=≀<=*b**j*<=≀<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874", "output": "11 9 8 2 2 1 5 5 0 0 1" }, { "input": "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897", "output": "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11" }, { "input": "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9", "output": "1 1 2 2 3 3 4 4 5" }, { "input": "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1", "output": "1" }, { "input": "5 1\n1 3 3 3 5\n3", "output": "4" }, { "input": "4 5\n1 1 1 4\n1 5 5 4 3", "output": "3 4 4 4 3" }, { "input": "5 4\n0 5 5 5 6\n5 1 6 3", "output": "4 1 5 1" }, { "input": "1 3\n0\n-1 0 1", "output": "0 1 1" }, { "input": "96 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1", "output": "96" }, { "input": "7 1\n1 2 3 4 5 6 7\n1", "output": "1" }, { "input": "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "7 13 7 13 7 13 7 13 7 13 7 13 7" }, { "input": "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5", "output": "1 2 3 4 5" }, { "input": "3 8\n1 1 1\n1 1 1 1 1 1 1 1", "output": "3 3 3 3 3 3 3 3" }, { "input": "1 1\n-11111\n-5938", "output": "1" }, { "input": "1 1\n1\n400000009", "output": "1" }, { "input": "1 1\n1\n300000009", "output": "1" }, { "input": "1 1\n1\n200000009", "output": "1" }, { "input": "1 1\n1\n200000003", "output": "1" } ]
2,000
11,776,000
0
178
251
Points on Line
[ "binary search", "combinatorics", "two pointers" ]
null
null
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen points doesn't matter.
The first line contains two integers: *n* and *d* (1<=≀<=*n*<=≀<=105;Β 1<=≀<=*d*<=≀<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 β€” the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "4 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n" ]
[ "4\n", "2\n", "1\n" ]
In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
[ { "input": "4 3\n1 2 3 4", "output": "4" }, { "input": "4 2\n-3 -2 -1 0", "output": "2" }, { "input": "5 19\n1 10 20 30 50", "output": "1" }, { "input": "10 5\n31 36 43 47 48 50 56 69 71 86", "output": "2" }, { "input": "10 50\n1 4 20 27 65 79 82 83 99 100", "output": "25" }, { "input": "10 90\n24 27 40 41 61 69 73 87 95 97", "output": "120" }, { "input": "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -51 -50 -49 -48 -46 -45 -44 -37 -36 -33 -30 -28 -27 -16 -15 -13 -12 -10 -9 -7 -6 -5 -4 2 3 5 8 9 10 11 13 14 15 16 17 19 22 24 25 26 27 28 30 31 32 36 40 43 45 46 47 50 51 52 53 58 60 63 69 70 73 78 80 81 82 85 88 89 90 91 95 96 97 99", "output": "79351" }, { "input": "1 14751211\n847188590", "output": "0" }, { "input": "2 1000000000\n-907894512 -289906312", "output": "0" }, { "input": "2 1000000000\n-14348867 1760823", "output": "0" }, { "input": "3 1000000000\n-5 -1 1", "output": "1" } ]
466
10,444,800
3
179
0
none
[ "none" ]
null
null
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≀<=*b*1<=≀<=*b*2<=≀<=...<=≀<=*b**l*<=≀<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≀<=*i*<=≀<=*l*<=-<=1). Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7).
The first line of input contains two space-separated integers *n*,<=*k*Β (1<=≀<=*n*,<=*k*<=≀<=2000).
Output a single integer β€” the number of good sequences of length *k* modulo 1000000007 (109<=+<=7).
[ "3 2\n", "6 4\n", "2 1\n" ]
[ "5\n", "39\n", "2\n" ]
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
[ { "input": "3 2", "output": "5" }, { "input": "6 4", "output": "39" }, { "input": "2 1", "output": "2" }, { "input": "1478 194", "output": "312087753" }, { "input": "1415 562", "output": "953558593" }, { "input": "1266 844", "output": "735042656" }, { "input": "680 1091", "output": "351905328" }, { "input": "1229 1315", "output": "100240813" }, { "input": "1766 1038", "output": "435768250" }, { "input": "1000 1", "output": "1000" }, { "input": "2000 100", "output": "983281065" }, { "input": "1 1", "output": "1" }, { "input": "2000 1000", "output": "228299266" }, { "input": "1928 1504", "output": "81660104" }, { "input": "2000 2000", "output": "585712681" }, { "input": "29 99", "output": "23125873" }, { "input": "56 48", "output": "20742237" }, { "input": "209 370", "output": "804680894" }, { "input": "83 37", "output": "22793555" }, { "input": "49 110", "output": "956247348" }, { "input": "217 3", "output": "4131" }, { "input": "162 161", "output": "591739753" }, { "input": "273 871", "output": "151578252" }, { "input": "43 1640", "output": "173064407" }, { "input": "1472 854", "output": "748682383" }, { "input": "1639 1056", "output": "467464129" }, { "input": "359 896", "output": "770361185" }, { "input": "1544 648", "output": "9278889" }, { "input": "436 1302", "output": "874366220" }, { "input": "1858 743", "output": "785912917" }, { "input": "991 1094", "output": "483493131" }, { "input": "1013 1550", "output": "613533467" }, { "input": "675 741", "output": "474968598" }, { "input": "1420 1223", "output": "922677437" }, { "input": "1544 1794", "output": "933285446" }, { "input": "1903 1612", "output": "620810276" }, { "input": "500 1304", "output": "706176027" }, { "input": "525 314", "output": "245394744" }, { "input": "39 1930", "output": "992125404" }, { "input": "1895 753", "output": "180474828" }, { "input": "1722 1474", "output": "742424590" }, { "input": "1153 1823", "output": "791493066" }, { "input": "1409 734", "output": "627413973" }, { "input": "478 1301", "output": "476483030" }, { "input": "1887 1729", "output": "730033374" }, { "input": "1610 774", "output": "50897314" }, { "input": "1770 679", "output": "235295539" }, { "input": "987 1292", "output": "560110556" }, { "input": "1707 1117", "output": "237674323" }, { "input": "1424 1431", "output": "184145444" }, { "input": "86 1078", "output": "252515343" }, { "input": "1066 995", "output": "180753612" }, { "input": "1024 133", "output": "392603027" }, { "input": "659 974", "output": "397026719" }, { "input": "1349 1606", "output": "522392901" }, { "input": "473 211", "output": "809550224" }, { "input": "634 1825", "output": "438513382" }, { "input": "22 373", "output": "907321755" }, { "input": "531 147", "output": "242883376" }, { "input": "1307 1247", "output": "21512331" }, { "input": "415 735", "output": "393705804" }, { "input": "1659 1501", "output": "225266660" }, { "input": "1454 296", "output": "750032659" }, { "input": "158 772", "output": "850911301" }, { "input": "2000 1", "output": "2000" } ]
124
3,584,000
0
180
344
Magnets
[ "implementation" ]
null
null
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
The first line of the input contains an integer *n* (1<=≀<=*n*<=≀<=100000) β€” the number of magnets. Then *n* lines follow. The *i*-th line (1<=≀<=*i*<=≀<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
On the single line of the output print the number of groups of magnets.
[ "6\n10\n10\n10\n01\n10\n10\n", "4\n01\n01\n10\n10\n" ]
[ "3\n", "2\n" ]
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
[ { "input": "6\n10\n10\n10\n01\n10\n10", "output": "3" }, { "input": "4\n01\n01\n10\n10", "output": "2" }, { "input": "1\n10", "output": "1" }, { "input": "2\n01\n10", "output": "2" }, { "input": "2\n10\n10", "output": "1" }, { "input": "3\n10\n01\n10", "output": "3" }, { "input": "1\n01", "output": "1" }, { "input": "2\n01\n01", "output": "1" }, { "input": "2\n10\n01", "output": "2" }, { "input": "3\n01\n01\n01", "output": "1" }, { "input": "3\n10\n10\n01", "output": "2" }, { "input": "3\n01\n10\n10", "output": "2" }, { "input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10", "output": "55" } ]
62
0
0
181
18
Stripe
[ "data structures", "implementation" ]
C. Stripe
2
64
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
The first input line contains integer *n* (1<=≀<=*n*<=≀<=105) β€” amount of squares in the stripe. The second line contains *n* space-separated numbers β€” they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
[ "9\n1 5 -6 7 9 -16 0 -2 2\n", "3\n1 1 1\n", "2\n0 0\n" ]
[ "3\n", "0\n", "1\n" ]
none
[ { "input": "9\n1 5 -6 7 9 -16 0 -2 2", "output": "3" }, { "input": "3\n1 1 1", "output": "0" }, { "input": "2\n0 0", "output": "1" }, { "input": "4\n100 1 10 111", "output": "1" }, { "input": "10\n0 4 -3 0 -2 2 -3 -3 2 5", "output": "3" }, { "input": "10\n0 -1 2 2 -1 1 0 0 0 2", "output": "0" }, { "input": "10\n-1 -1 1 -1 0 1 0 1 1 1", "output": "1" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "9" }, { "input": "50\n-4 -3 3 4 -1 0 2 -4 -3 -4 1 4 3 0 4 1 0 -3 4 -3 -2 2 2 1 0 -4 -4 -5 3 2 -1 4 5 -3 -3 4 4 -5 2 -3 4 -5 2 5 -4 4 1 -2 -4 3", "output": "3" }, { "input": "15\n0 4 0 3 -1 4 -2 -2 -4 -4 3 2 4 -1 -3", "output": "0" }, { "input": "10\n3 -1 -3 -1 3 -2 0 3 1 -2", "output": "0" }, { "input": "100\n-4 2 4 4 1 3 -3 -3 2 1 -4 0 0 2 3 -1 -4 -3 4 -2 -3 -3 -3 -1 -2 -3 -1 -4 0 4 0 -1 4 0 -4 -4 4 -4 -2 1 -4 1 -3 -2 3 -4 4 0 -1 3 -1 4 -1 4 -1 3 -3 -3 -2 -2 4 -3 -3 4 -3 -2 -1 0 -2 4 0 -3 -1 -2 -3 1 -4 1 -3 -3 -3 -2 -3 0 1 -2 -2 -4 -3 -1 2 3 -1 1 1 0 3 -3 -1 -2", "output": "1" }, { "input": "100\n-2 -1 1 0 -2 -1 2 2 0 0 2 1 0 2 0 2 1 0 -1 -1 -1 0 -2 -1 2 -1 -2 2 -2 2 -2 -2 2 1 1 1 -2 2 0 0 2 -1 2 2 2 0 -1 -1 -1 1 -2 2 2 2 -2 0 0 -2 0 -2 -2 0 -1 -1 -2 -1 1 2 -2 -1 1 -2 -1 0 -2 2 2 -1 -2 2 0 0 0 1 0 1 2 1 -2 -2 -1 -1 -2 -2 -2 -1 2 2 2 -2", "output": "6" }, { "input": "100\n2 7 6 0 8 -2 0 1 8 -1 7 -4 -1 1 0 3 4 -4 3 7 8 -4 -6 6 4 -2 -5 7 4 6 1 6 3 8 -2 6 -6 -3 0 -1 -7 -8 -2 5 8 6 -2 -2 -5 -4 -7 -3 -5 -3 -3 -1 5 8 4 0 -7 -6 8 -4 -1 7 2 6 6 4 -5 -4 -5 -2 2 -2 -7 -1 5 -8 -6 -2 -5 4 2 8 -6 7 -8 -1 -5 8 6 -3 -1 7 -1 2 -8 -8", "output": "0" }, { "input": "1\n0", "output": "0" }, { "input": "1\n10000", "output": "0" }, { "input": "1\n-10000", "output": "0" } ]
60
0
0
182
919
Substring
[ "dfs and similar", "dp", "graphs" ]
null
null
You are given a graph with $n$ nodes and $m$ directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is $3$. Your task is find a path whose value is the largest.
The first line contains two positive integers $n, m$ ($1 \leq n, m \leq 300\,000$), denoting that the graph has $n$ nodes and $m$ directed edges. The second line contains a string $s$ with only lowercase English letters. The $i$-th character is the letter assigned to the $i$-th node. Then $m$ lines follow. Each line contains two integers $x, y$ ($1 \leq x, y \leq n$), describing a directed edge from $x$ to $y$. Note that $x$ can be equal to $y$ and there can be multiple edges between $x$ and $y$. Also the graph can be not connected.
Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead.
[ "5 4\nabaca\n1 2\n1 3\n3 4\n4 5\n", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4\n", "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7\n" ]
[ "3\n", "-1\n", "4\n" ]
In the first sample, the path with largest value is $1 \to 3 \to 4 \to 5$. The value is $3$ because the letter 'a' appears $3$ times.
[ { "input": "5 4\nabaca\n1 2\n1 3\n3 4\n4 5", "output": "3" }, { "input": "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4", "output": "-1" }, { "input": "10 14\nxzyzyzyzqx\n1 2\n2 4\n3 5\n4 5\n2 6\n6 8\n6 5\n2 10\n3 9\n10 9\n4 6\n1 10\n2 8\n3 7", "output": "4" }, { "input": "1 1\nf\n1 1", "output": "-1" }, { "input": "10 50\nebibwbjihv\n1 10\n1 2\n5 4\n1 8\n9 7\n5 6\n1 8\n8 7\n2 6\n5 4\n1 9\n3 2\n8 3\n5 6\n5 9\n2 4\n2 7\n3 9\n1 2\n1 7\n1 10\n3 7\n1 8\n3 10\n8 6\n1 7\n10 6\n1 6\n5 8\n1 5\n2 10\n3 9\n5 8\n8 3\n3 7\n5 2\n1 10\n1 4\n5 3\n3 2\n1 2\n5 8\n10 4\n2 10\n8 2\n1 9\n1 8\n1 2\n3 4\n1 8", "output": "2" }, { "input": "13 37\ndwpzcppjmhkmz\n2 6\n3 6\n6 7\n6 7\n6 7\n6 7\n6 8\n6 8\n6 8\n6 8\n4 6\n4 6\n5 6\n4 6\n4 6\n6 9\n6 9\n6 10\n6 10\n6 10\n6 10\n4 6\n1 6\n1 6\n10 11\n6 11\n1 6\n6 12\n6 12\n6 12\n6 13\n6 13\n6 13\n6 13\n3 6\n2 6\n2 6", "output": "3" }, { "input": "5 8\ntetqw\n2 1\n4 4\n5 5\n5 2\n4 5\n1 5\n1 5\n1 1", "output": "-1" }, { "input": "5 8\nreeet\n4 3\n2 5\n4 2\n2 4\n4 2\n5 2\n3 3\n3 4", "output": "-1" } ]
3,000
129,843,200
0
183
784
Crunching Numbers Just for You
[ "*special", "implementation" ]
null
null
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. Sort it in non-descending order.
The input consists of a single line of space-separated integers. The first number is *n* (1<=≀<=*n*<=≀<=10) β€” the size of the array. The following *n* numbers are the elements of the array (1<=≀<=*a**i*<=≀<=100).
Output space-separated elements of the sorted array.
[ "3 3 1 2\n" ]
[ "1 2 3 \n" ]
Remember, this is a very important feature, and you have to make sure the customers appreciate it!
[ { "input": "3 3 1 2", "output": "1 2 3 " }, { "input": "10 54 100 27 1 33 27 80 49 27 6", "output": "1 6 27 27 27 33 49 54 80 100 " } ]
0
0
-1
186
834
The Useless Toy
[ "implementation" ]
null
null
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption. Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one): After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in. Slastyona managed to have spinner rotating for exactly *n* seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), &lt; (ASCII code 60), ^ (ASCII code 94) or &gt; (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number *n* is given (0<=≀<=*n*<=≀<=109) – the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a *n* second spin in any of the directions, assuming the given starting position.
Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.
[ "^ &gt;\n1\n", "&lt; ^\n3\n", "^ v\n6\n" ]
[ "cw\n", "ccw\n", "undefined\n" ]
none
[ { "input": "^ >\n1", "output": "cw" }, { "input": "< ^\n3", "output": "ccw" }, { "input": "^ v\n6", "output": "undefined" }, { "input": "^ >\n999999999", "output": "ccw" }, { "input": "> v\n1", "output": "cw" }, { "input": "v <\n1", "output": "cw" }, { "input": "< ^\n1", "output": "cw" }, { "input": "v <\n422435957", "output": "cw" }, { "input": "v >\n139018901", "output": "ccw" }, { "input": "v ^\n571728018", "output": "undefined" }, { "input": "^ ^\n0", "output": "undefined" }, { "input": "< >\n2", "output": "undefined" }, { "input": "> >\n1000000000", "output": "undefined" }, { "input": "v v\n8", "output": "undefined" }, { "input": "< <\n1568", "output": "undefined" }, { "input": "^ v\n2", "output": "undefined" }, { "input": "^ <\n1", "output": "ccw" }, { "input": "< v\n1", "output": "ccw" }, { "input": "v >\n1", "output": "ccw" }, { "input": "> ^\n1", "output": "ccw" }, { "input": "v <\n422435957", "output": "cw" }, { "input": "v v\n927162384", "output": "undefined" }, { "input": "v ^\n571728018", "output": "undefined" }, { "input": "^ <\n467441155", "output": "cw" }, { "input": "^ >\n822875521", "output": "cw" }, { "input": "^ <\n821690113", "output": "ccw" }, { "input": "^ <\n171288453", "output": "ccw" }, { "input": "^ <\n110821381", "output": "ccw" }, { "input": "^ ^\n539580280", "output": "undefined" }, { "input": "^ >\n861895563", "output": "ccw" }, { "input": "v v\n4", "output": "undefined" }, { "input": "^ ^\n4", "output": "undefined" }, { "input": "> >\n4", "output": "undefined" }, { "input": "< <\n8", "output": "undefined" }, { "input": "v v\n0", "output": "undefined" }, { "input": "^ <\n11", "output": "cw" }, { "input": "< <\n4", "output": "undefined" }, { "input": "< <\n0", "output": "undefined" }, { "input": "< v\n3", "output": "cw" }, { "input": "^ <\n3", "output": "cw" }, { "input": "^ <\n7", "output": "cw" }, { "input": "< >\n6", "output": "undefined" }, { "input": "v >\n3", "output": "cw" }, { "input": "> >\n300", "output": "undefined" }, { "input": "> >\n0", "output": "undefined" }, { "input": "v <\n3", "output": "ccw" }, { "input": "> >\n12", "output": "undefined" } ]
46
4,608,000
-1
187
94
Restoring Password
[ "implementation", "strings" ]
A. Restoring Password
2
256
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password". Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" β€” thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address. Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits. Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Print one line containing 8 characters β€” The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
[ "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n", "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000\n" ]
[ "12345678\n", "30234919\n" ]
none
[ { "input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110", "output": "12345678" }, { "input": "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000", "output": "30234919" }, { "input": "00010101101110110101100110101100010101100010101111000101011010011010110010000011\n0101010110\n0001001101\n1001101011\n0000100011\n0010101111\n1110110101\n0001010110\n0110111000\n0000111110\n0010000011", "output": "65264629" }, { "input": "10100100010010010011011001101000100100110110011010011001101011000100110110011010\n1111110011\n1001000111\n1001000100\n1100010011\n0110011010\n0010000001\n1110101110\n0010000110\n0010010011\n1010010001", "output": "98484434" }, { "input": "00101100011111010001001000000110110000000110010011001111111010110010001011000000\n0010000001\n0110010011\n0010000010\n1011001000\n0011111110\n0110001000\n1111010001\n1011000000\n0000100110\n0010110001", "output": "96071437" }, { "input": "10001110111110000001000010001010001110110000100010100010111101101101010000100010\n0000010110\n1101010111\n1000101111\n0001011110\n0011110101\n0101100100\n0110110101\n0000100010\n1000111011\n1110000001", "output": "89787267" }, { "input": "10010100011001010001010101001101010100110100111011001010111100011001000010100000\n0011100000\n1001100100\n0001100100\n0010100000\n0101010011\n0010101110\n0010101111\n0100111011\n1001010001\n1111111110", "output": "88447623" }, { "input": "01101100111000000101011011001110000001011111111000111111100001011010001001011001\n1000000101\n0101101000\n0101110101\n1101011110\n0000101100\n1111111000\n0001001101\n0110111011\n0110110011\n1001011001", "output": "80805519" }, { "input": "11100011000100010110010011101010101010011110001100011010111110011000011010110111\n1110001100\n0110101111\n0100111010\n0101000000\n1001100001\n1010101001\n0000100010\n1010110111\n1100011100\n0100010110", "output": "09250147" }, { "input": "10000110110000010100000010001000111101110110101011110111000100001101000000100010\n0000010100\n0000110001\n0110101011\n1101110001\n1000011011\n0000110100\n0011110111\n1000110010\n0000100010\n0000011011", "output": "40862358" }, { "input": "01000000010000000110100101000110110000100100000001101100001000011111111001010001\n1011000010\n1111101010\n0111110011\n0000000110\n0000001001\n0001111111\n0110010010\n0100000001\n1011001000\n1001010001", "output": "73907059" }, { "input": "01111000111110011001110101110011110000111110010001101100110110100111101011001101\n1110010001\n1001100000\n1100001000\n1010011110\n1011001101\n0111100011\n1101011100\n1110011001\n1111000011\n0010000101", "output": "57680434" }, { "input": "01001100101000100010001011110001000101001001100010010000001001001100101001011111\n1001011111\n1110010111\n0111101011\n1000100010\n0011100101\n0100000010\n0010111100\n0100010100\n1001100010\n0100110010", "output": "93678590" }, { "input": "01110111110000111011101010110110101011010100110111000011101101110101011101001000\n0110000101\n1010101101\n1101010111\n1101011100\n0100110111\n0111011111\n1100011001\n0111010101\n0000111011\n1101001000", "output": "58114879" }, { "input": "11101001111100110101110011010100110011011110100111010110110011000111000011001101\n1100011100\n1100110101\n1011101000\n0011011110\n0011001101\n0100010001\n1110100111\n1010101100\n1110110100\n0101101100", "output": "61146904" }, { "input": "10101010001011010001001001011000100101100001011011101010101110101010001010101000\n0010110101\n1010011010\n1010101000\n1011010001\n1010101011\n0010010110\n0110100010\n1010100101\n0001011011\n0110100001", "output": "23558422" }, { "input": "11110101001100010000110100001110101011011111010100110001000001001010001001101111\n0101101100\n1001101111\n1010101101\n0100101000\n1111110000\n0101010010\n1100010000\n1111010100\n1101000011\n1011111111", "output": "76827631" }, { "input": "10001100110000110111100011001101111110110011110101000011011100001101110000110111\n0011110101\n0101100011\n1000110011\n1011011001\n0111111011\n0101111011\n0000110111\n0100001110\n1000000111\n0110110111", "output": "26240666" }, { "input": "10000100010000111101100100111101111011101000001001100001000110000010010000111101\n1001001111\n0000111101\n1000010001\n0110011101\n0110101000\n1011111001\n0111101110\n1000001001\n1101011111\n0001010100", "output": "21067271" }, { "input": "01101111000110111100011011110001101111001010001100101000110001010101100100000010\n1010001100\n0011010011\n0101010110\n1111001100\n1100011000\n0100101100\n1001100101\n0110111100\n0011001101\n0100000010", "output": "77770029" }, { "input": "10100111011010001011111000000111100000010101000011000010111101010000111010011101\n1010011101\n1010111111\n0110100110\n1111000100\n1110000001\n0000101111\n0011111000\n1000110001\n0101000011\n1010001011", "output": "09448580" }, { "input": "10000111111000011111001010101010010011111001001111000010010100100011000010001100\n1101101110\n1001001111\n0000100101\n1100111010\n0010101010\n1110000110\n1100111101\n0010001100\n1110000001\n1000011111", "output": "99411277" }, { "input": "10110110111011001111101100111100111111011011011011001111110110010011100010000111\n0111010011\n0111101100\n1001101010\n0101000101\n0010000111\n0011111101\n1011001111\n1101111000\n1011011011\n1001001110", "output": "86658594" }, { "input": "01001001100101100011110110111100000110001111001000100000110111110010000000011000\n0100100110\n1000001011\n1000111110\n0000011000\n0101100011\n1101101111\n1111001000\n1011011001\n1000001101\n0010101000", "output": "04536863" }, { "input": "10010100011101000011100100001100101111000010111100000010010000001001001101011101\n1001000011\n1101000011\n1001010001\n1101011101\n1000010110\n0011111101\n0010111100\n0000100100\n1010001000\n0101000110", "output": "21066773" }, { "input": "01111111110101111111011111111111010010000001100000101000100100111001011010001001\n0111111111\n0101111111\n0100101101\n0001100000\n0011000101\n0011100101\n1101001000\n0010111110\n1010001001\n1111000111", "output": "01063858" }, { "input": "00100011111001001010001111000011101000001110100000000100101011101000001001001010\n0010001111\n1001001010\n1010011001\n0011100111\n1000111000\n0011110000\n0000100010\n0001001010\n1111110111\n1110100000", "output": "01599791" }, { "input": "11011101000100110100110011010101100011111010011010010011010010010010100110101111\n0100110100\n1001001010\n0001111101\n1101011010\n1101110100\n1100110101\n0110101111\n0110001111\n0001101000\n1010011010", "output": "40579016" }, { "input": "10000010111101110110011000111110000011100110001111100100000111000011011000001011\n0111010100\n1010110110\n1000001110\n1110000100\n0110001111\n1101110110\n1100001101\n1000001011\n0000000101\n1001000001", "output": "75424967" }, { "input": "11101100101110111110111011111010001111111111000001001001000010001111111110110010\n0101100001\n1111010011\n1110111110\n0100110100\n1110011111\n1000111111\n0010010000\n1110110010\n0011000010\n1111000001", "output": "72259657" }, { "input": "01011110100101111010011000001001100000101001110011010111101011010000110110010101\n0100111100\n0101110011\n0101111010\n0110000010\n0101001111\n1101000011\n0110010101\n0111011010\n0001101110\n1001110011", "output": "22339256" }, { "input": "01100000100101111000100001100010000110000010100100100001100000110011101001110000\n0101111000\n1001110000\n0001000101\n0110110111\n0010100100\n1000011000\n1101110110\n0110000010\n0001011010\n0011001110", "output": "70554591" }, { "input": "11110011011000001001111100110101001000010100100000110011001110011111100100100001\n1010011000\n1111001101\n0100100001\n1111010011\n0100100000\n1001111110\n1010100111\n1000100111\n1000001001\n1100110011", "output": "18124952" }, { "input": "10001001011000100101010110011101011001110010000001010110000101000100101111101010\n0101100001\n1100001100\n1111101010\n1000100101\n0010000001\n0100010010\n0010110110\n0101100111\n0000001110\n1101001110", "output": "33774052" }, { "input": "00110010000111001001001100100010010111101011011110001011111100000101000100000001\n0100000001\n1011011110\n0010111111\n0111100111\n0100111001\n0000010100\n1001011110\n0111001001\n0100010011\n0011001000", "output": "97961250" }, { "input": "01101100001000110101101100101111101110010011010111100011010100010001101000110101\n1001101001\n1000110101\n0110110000\n0111100100\n0011010111\n1110111001\n0001000110\n0000000100\n0001101001\n1011001011", "output": "21954161" }, { "input": "10101110000011010110101011100000101101000110100000101101101101110101000011110010\n0110100000\n1011011011\n0011110010\n0001110110\n0010110100\n1100010010\n0001101011\n1010111000\n0011010110\n0111010100", "output": "78740192" }, { "input": "11000101011100100111010000010001000001001100101100000011000000001100000101011010\n1100010101\n1111101011\n0101011010\n0100000100\n1000110111\n1100100111\n1100101100\n0111001000\n0000110000\n0110011111", "output": "05336882" }, { "input": "11110100010000101110010110001000001011100101100010110011011011111110001100110110\n0101100010\n0100010001\n0000101110\n1100110110\n0101000101\n0011001011\n1111010001\n1000110010\n1111111000\n1010011111", "output": "62020383" }, { "input": "00011001111110000011101011010001010111100110100101000110011111011001100000001100\n0111001101\n0101011110\n0001100111\n1101011111\n1110000011\n0000001100\n0111010001\n1101100110\n1010110100\n0110100101", "output": "24819275" }, { "input": "10111110010011111001001111100101010111010011111001001110101000111110011001111101\n0011111001\n0101011101\n0100001010\n0001110010\n1001111101\n0011101010\n1111001001\n1100100001\n1001101000\n1011111001", "output": "90010504" }, { "input": "01111101111100101010001001011110111001110111110111011111011110110111111011011111\n1111110111\n0010000101\n0110000100\n0111111011\n1011100111\n1100101010\n1011011111\n1100010001\n0111110111\n0010010111", "output": "85948866" }, { "input": "01111100000111110000110010111001111100001001101010110010111010001000101001101010\n0100010101\n1011110101\n1010100100\n1010000001\n1001101010\n0101100110\n1000100010\n0111110000\n1100101110\n0110010110", "output": "77874864" }, { "input": "11100011010000000010011110010111001011111001000111000000001000000000100111100101\n0000000010\n1110001101\n0011010101\n0111100101\n1001000111\n1101001111\n0111010110\n1100101111\n0110000000\n1101101011", "output": "10374003" }, { "input": "01111011100111101110011001000110001111101000111110100100100001011111001011100010\n0110010100\n1100010001\n0111101110\n1001001000\n1010011011\n1000111110\n0010110101\n1011100010\n0101111100\n0110010001", "output": "22955387" }, { "input": "11011010001100000011000100110011010101000110011110110000001100111100001000011111\n0000100010\n1000011111\n1101101000\n0110011110\n0011110000\n1100000011\n0010001100\n0101101000\n0001001100\n1101010100", "output": "25893541" }, { "input": "01011001011111010010101111011001000011001100011101101111011011010011101011110110\n0100001100\n0101100101\n1111111011\n1111010010\n1111101100\n1100011101\n1011000011\n1101001110\n1011110110\n0110001010", "output": "13805878" }, { "input": "11110011011000111111001100111110001111111100000010111100110100110011111111001101\n1111001101\n1001101010\n1100110010\n0011001111\n0001011110\n1000110011\n1000111111\n0110001010\n1001011101\n1100000010", "output": "06369030" }, { "input": "01110011110010000011011001011000001000010110010110011001100001100110001100101000\n0000100001\n0110011000\n1010000010\n1110011101\n0111001111\n1100101000\n0010000011\n0110010000\n1100100101\n0110010110", "output": "46909115" }, { "input": "00001011001111110111111111011111111101110101110100010111010010100101100001010110\n1111110111\n0001010110\n0111011011\n0111000001\n1010010110\n0101110100\n0001000101\n0000111000\n0110100001\n0000101100", "output": "90005541" } ]
156
0
3.961
188
447
DZY Loves Strings
[ "greedy", "implementation" ]
null
null
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
The first line contains a single string *s*Β (1<=≀<=|*s*|<=≀<=103). The second line contains a single integer *k*Β (0<=≀<=*k*<=≀<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Print a single integer β€” the largest possible value of the resulting string DZY could get.
[ "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" ]
[ "41\n" ]
In the test sample DZY can obtain "abcbbc", *value* = 1Β·1 + 2Β·2 + 3Β·2 + 4Β·2 + 5Β·2 + 6Β·2 = 41.
[ { "input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41" }, { "input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453", "output": "29978" }, { "input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\n23\n359 813 772 413 733 654 33 87 890 433 395 311 801 852 376 148 914 420 636 695 583 733 664 394 407 314", "output": "1762894" }, { "input": "uahngxejpomhbsebcxvelfsojbaouynnlsogjyvktpwwtcyddkcdqcqs\n34\n530 709 150 660 947 830 487 142 208 276 885 542 138 214 76 184 273 753 30 195 722 236 82 691 572 585", "output": "2960349" }, { "input": "xnzeqmouqyzvblcidmhbkqmtusszuczadpooslqxegldanwopilmdwzbczvrwgnwaireykwpugvpnpafbxlyggkgawghysufuegvmzvpgcqyjkoadcreaguzepbendwnowsuekxxivkziibxvxfoilofxcgnxvfefyezfhevfvtetsuhwtyxdlkccdkvqjl\n282\n170 117 627 886 751 147 414 187 150 960 410 70 576 681 641 729 798 877 611 108 772 643 683 166 305 933", "output": "99140444" }, { "input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuenqojrmzaxlaoxnljnvqgnabtmcftisaazzgbmubmpsorygyusmeonrhrgphnfhlaxrvyhuxsnnezjxmdoklpquzpvjbxgbywppmegzxknhfzyygrmejleesoqfwheulmqhonqaukyuejtwxskjldplripyihbfpookxkuehiwqthbfafyrgmykuxglpplozycgydyecqkgfjljfqvigqhuxssqqtfanwszduwbsoytnrtgc\n464\n838 95 473 955 690 84 436 19 179 437 674 626 377 365 781 4 733 776 462 203 119 256 381 668 855 686", "output": "301124161" }, { "input": "qkautnuilwlhjsldfcuwhiqtgtoihifszlyvfaygrnivzgvwthkrzzdtfjcirrjjlrmjtbjlzmjeqmuffsjorjyggzefwgvmblvotvzffnwjhqxorpowzdcnfksdibezdtfjjxfozaghieksbmowrbeehuxlesmvqjsphlvauxiijm\n98\n121 622 0 691 616 959 838 161 581 862 876 830 267 812 598 106 337 73 588 323 999 17 522 399 657 495", "output": "30125295" }, { "input": "tghyxqfmhz\n8\n191 893 426 203 780 326 148 259 182 140 847 636 778 97 167 773 219 891 758 993 695 603 223 779 368 165", "output": "136422" }, { "input": "nyawbfjxnxjiyhwkydaruozobpphgjqdpfdqzezcsoyvurnapu\n30\n65 682 543 533 990 148 815 821 315 916 632 771 332 513 472 864 12 73 548 687 660 572 507 192 226 348", "output": "2578628" }, { "input": "pylrnkrbcjgoytvdnhmlvnkknijkdgdhworlvtwuonrkhrilkewcnofodaumgvnsisxooswgrgtvdeauyxhkipfoxrrtysuepjcf\n60\n894 206 704 179 272 337 413 828 119 182 330 46 440 102 250 191 242 539 678 783 843 431 612 567 33 338", "output": "9168707" }, { "input": "vhjnkrxbyhjhnjrxvwxmhxwoxttbtqosfxtcuvhfjlkyfspeypthsdkkwnqdpxdlnxsgtzvkrgqosgfjrwetqbxgoarkjhrjbspzgblsapifltkfxbfdbxqwoohlgyzijmiwnpmveybyzvasoctxsmgjehpyysmqblwnmkappbecklqjfmxhlyceordroflnposohfplrvijxbwvqdtvzhobtrumiujnyrfbwthvciinuveoizkccelxtaveiiagryqnyvsgfnipnavrtmdqlcnldepocbpzmqnarkdvykds\n276\n364 244 798 82 582 9 309 950 286 547 892 371 569 159 705 975 740 845 655 179 130 993 255 552 882 657", "output": "144901921" }, { "input": "gsaddmezrnttfalbwlqbnedumvikplfosw\n12\n290 850 872 361 483 895 152 118 974 619 701 154 899 285 328 712 669 984 407 340 851 775 324 892 554 860", "output": "809931" }, { "input": "a\n0\n5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "5" }, { "input": "lol\n3\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "21" } ]
109
0
3
189
818
Diplomas and Certificates
[ "implementation", "math" ]
null
null
There are *n* students who have taken part in an olympiad. Now it's time to award the students. Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners. You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
The first (and the only) line of input contains two integers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.
[ "18 2\n", "9 10\n", "1000000000000 5\n", "1000000000000 499999999999\n" ]
[ "3 6 9\n", "0 0 9\n", "83333333333 416666666665 500000000002\n", "1 499999999999 500000000000\n" ]
none
[ { "input": "18 2", "output": "3 6 9" }, { "input": "9 10", "output": "0 0 9" }, { "input": "1000000000000 5", "output": "83333333333 416666666665 500000000002" }, { "input": "1000000000000 499999999999", "output": "1 499999999999 500000000000" }, { "input": "1 1", "output": "0 0 1" }, { "input": "5 3", "output": "0 0 5" }, { "input": "42 6", "output": "3 18 21" }, { "input": "1000000000000 1000", "output": "499500499 499500499000 500000000501" }, { "input": "999999999999 999999", "output": "499999 499998500001 500000999999" }, { "input": "732577309725 132613", "output": "2762066 366285858458 366288689201" }, { "input": "152326362626 15", "output": "4760198832 71402982480 76163181314" }, { "input": "2 1", "output": "0 0 2" }, { "input": "1000000000000 500000000000", "output": "0 0 1000000000000" }, { "input": "100000000000 50000000011", "output": "0 0 100000000000" }, { "input": "1000000000000 32416187567", "output": "15 486242813505 513757186480" }, { "input": "1000000000000 7777777777", "output": "64 497777777728 502222222208" }, { "input": "1000000000000 77777777777", "output": "6 466666666662 533333333332" }, { "input": "100000000000 578485652", "output": "86 49749766072 50250233842" }, { "input": "999999999999 10000000000", "output": "49 490000000000 509999999950" }, { "input": "7 2", "output": "1 2 4" }, { "input": "420506530901 752346673804", "output": "0 0 420506530901" }, { "input": "960375521135 321688347872", "output": "1 321688347872 638687173262" }, { "input": "1000000000000 1000000000000", "output": "0 0 1000000000000" }, { "input": "99999999999 15253636363", "output": "3 45760909089 54239090907" }, { "input": "19 2", "output": "3 6 10" }, { "input": "999999999999 1000000000000", "output": "0 0 999999999999" }, { "input": "1000000000000 5915587276", "output": "84 496909331184 503090668732" }, { "input": "1000000000000 1000000006", "output": "499 499000002994 500999996507" }, { "input": "549755813888 134217728", "output": "2047 274743689216 275012122625" }, { "input": "99999999999 3333333", "output": "14999 49996661667 50003323333" }, { "input": "9 1", "output": "2 2 5" }, { "input": "1000000000000 250000000001", "output": "1 250000000001 749999999998" }, { "input": "5 1", "output": "1 1 3" }, { "input": "3107038133 596040207", "output": "2 1192080414 1914957717" }, { "input": "1000000000000 73786977", "output": "6776 499980556152 500019437072" }, { "input": "1000000000000 73786976", "output": "6776 499980549376 500019443848" }, { "input": "1000000000000 25000000000", "output": "19 475000000000 524999999981" }, { "input": "216929598879 768233755932", "output": "0 0 216929598879" }, { "input": "1000000000000 250000000000", "output": "1 250000000000 749999999999" }, { "input": "1000000000000 100000000001", "output": "4 400000000004 599999999992" }, { "input": "100000000000 100000000001", "output": "0 0 100000000000" }, { "input": "900000000000 100281800001", "output": "4 401127200004 498872799992" }, { "input": "906028900004 109123020071", "output": "4 436492080284 469536819716" }, { "input": "1000000000000 1", "output": "250000000000 250000000000 500000000000" } ]
77
4,608,000
3
190
352
Jeff and Digits
[ "brute force", "implementation", "math" ]
null
null
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
The first line contains integer *n* (1<=≀<=*n*<=≀<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card.
In a single line print the answer to the problem β€” the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
[ "4\n5 0 5 0\n", "11\n5 5 5 5 5 5 5 5 0 5 5\n" ]
[ "0\n", "5555555550\n" ]
In the first test you can make only one number that is a multiple of 90 β€” 0. In the second test you can make number 5555555550, it is a multiple of 90.
[ { "input": "4\n5 0 5 0", "output": "0" }, { "input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550" }, { "input": "7\n5 5 5 5 5 5 5", "output": "-1" }, { "input": "1\n5", "output": "-1" }, { "input": "1\n0", "output": "0" }, { "input": "11\n5 0 5 5 5 0 0 5 5 5 5", "output": "0" }, { "input": "23\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "output": "55555555555555555500000" }, { "input": "9\n5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "24\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "output": "55555555555555555500000" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "10\n5 5 5 5 5 0 0 5 0 5", "output": "0" }, { "input": "3\n5 5 0", "output": "0" }, { "input": "5\n5 5 0 5 5", "output": "0" }, { "input": "14\n0 5 5 0 0 0 0 0 0 5 5 5 5 5", "output": "0" }, { "input": "3\n5 5 5", "output": "-1" }, { "input": "3\n0 5 5", "output": "0" }, { "input": "13\n0 0 5 0 5 0 5 5 0 0 0 0 0", "output": "0" }, { "input": "9\n5 5 0 5 5 5 5 5 5", "output": "0" }, { "input": "8\n0 0 0 0 0 0 0 0", "output": "0" }, { "input": "101\n5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 5 0 0 0 0 0 5 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 5 0 0 5 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 5 0 0", "output": "5555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "214\n5 0 5 0 5 0 0 0 5 5 0 5 0 5 5 0 5 0 0 0 0 5 5 0 0 5 5 0 0 0 0 5 5 5 5 0 5 0 0 0 0 0 0 5 0 0 0 5 0 0 5 0 0 5 5 0 0 5 5 0 0 0 0 0 5 0 5 0 5 5 0 5 0 0 5 5 5 0 5 0 5 0 5 5 0 5 0 0 0 5 5 0 5 0 5 5 5 5 5 0 0 0 0 0 0 5 0 5 5 0 5 0 5 0 5 5 0 0 0 0 5 0 5 0 5 0 0 5 0 0 5 5 5 5 5 0 0 5 0 0 5 0 0 5 0 0 5 0 0 5 0 5 0 0 0 5 0 0 5 5 5 0 0 5 5 5 0 0 5 5 0 0 0 5 0 0 5 5 5 5 5 5 0 5 0 0 5 5 5 5 0 5 5 0 0 0 5 5 5 5 0 0 0 0 5 0 0 5 0 0 5 5 0 0", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "80\n0 0 0 0 5 0 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 0 0 5 5 0 5 0 0 0 0 0 0 5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 5 5 0 0 0", "output": "555555555000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "2\n0 0", "output": "0" }, { "input": "3\n5 0 0", "output": "0" }, { "input": "4\n5 5 5 5", "output": "-1" }, { "input": "2\n0 5", "output": "0" }, { "input": "14\n5 5 5 5 5 5 5 5 5 5 5 5 5 0", "output": "5555555550" }, { "input": "18\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "10\n5 5 5 5 5 5 5 5 5 0", "output": "5555555550" }, { "input": "10\n5 5 5 5 5 5 5 5 5 5", "output": "-1" }, { "input": "20\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "-1" } ]
92
0
0
192
377
Maze
[ "dfs and similar" ]
null
null
Pavel loves grid mazes. A grid maze is an *n*<=Γ—<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him.
The first line contains three integers *n*, *m*, *k* (1<=≀<=*n*,<=*m*<=≀<=500, 0<=≀<=*k*<=&lt;<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze. Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.
Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
[ "3 4 2\n#..#\n..#.\n#...\n", "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n" ]
[ "#.X#\nX.#.\n#...\n", "#XXX\n#X#.\nX#..\n...#\n.#.#\n" ]
none
[ { "input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#" }, { "input": "3 3 2\n#.#\n...\n#.#", "output": "#X#\nX..\n#.#" }, { "input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#", "output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#...\nX#...#.\nX.#.#..\n#.....#" }, { "input": "1 1 0\n.", "output": "." }, { "input": "2 3 1\n..#\n#..", "output": "X.#\n#.." }, { "input": "2 3 1\n#..\n..#", "output": "#.X\n..#" }, { "input": "3 3 1\n...\n.#.\n..#", "output": "...\n.#X\n..#" }, { "input": "3 3 1\n...\n.#.\n#..", "output": "...\nX#.\n#.." }, { "input": "5 4 4\n#..#\n....\n.##.\n....\n#..#", "output": "#XX#\nXX..\n.##.\n....\n#..#" }, { "input": "5 5 2\n.#..#\n..#.#\n#....\n##.#.\n###..", "output": "X#..#\nX.#.#\n#....\n##.#.\n###.." }, { "input": "4 6 3\n#.....\n#.#.#.\n.#...#\n...#.#", "output": "#.....\n#X#.#X\nX#...#\n...#.#" }, { "input": "7 5 4\n.....\n.#.#.\n#...#\n.#.#.\n.#...\n..#..\n....#", "output": "X...X\nX#.#X\n#...#\n.#.#.\n.#...\n..#..\n....#" }, { "input": "16 14 19\n##############\n..############\n#.############\n#..###########\n....##########\n..############\n.#############\n.#.###########\n....##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###....#......\n#...#...##.###", "output": "##############\nXX############\n#X############\n#XX###########\nXXXX##########\nXX############\nX#############\nX#.###########\nX...##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###...X#......\n#X..#XXX##.###" }, { "input": "10 17 32\n######.##########\n####.#.##########\n...#....#########\n.........########\n##.......########\n........#########\n#.....###########\n#################\n#################\n#################", "output": "######X##########\n####X#X##########\nXXX#XXXX#########\nXXXXXXXXX########\n##XXX.XXX########\nXXXX...X#########\n#XX...###########\n#################\n#################\n#################" }, { "input": "16 10 38\n##########\n##########\n##########\n..########\n...#######\n...#######\n...#######\n....######\n.....####.\n......###.\n......##..\n.......#..\n.........#\n.........#\n.........#\n.........#", "output": "##########\n##########\n##########\nXX########\nXXX#######\nXXX#######\nXXX#######\nXXXX######\nXXXXX####.\nXXXXX.###.\nXXXX..##..\nXXX....#..\nXXX......#\nXX.......#\nX........#\n.........#" }, { "input": "15 16 19\n########.....###\n########.....###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n.....#####.#..##\n................\n.#...........###\n###.########.###\n###.########.###", "output": "########XXXXX###\n########XXXXX###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\nXXXX.#####.#..##\nXXX.............\nX#...........###\n###.########.###\n###X########.###" }, { "input": "12 19 42\n.........##########\n...................\n.##.##############.\n..################.\n..#################\n..#################\n..#################\n..#################\n..#################\n..#################\n..##########.######\n.............######", "output": "XXXXXXXXX##########\nXXXXXXXXXXXXXXXXXXX\nX##X##############X\nXX################X\nXX#################\nXX#################\nXX#################\nX.#################\nX.#################\n..#################\n..##########.######\n.............######" }, { "input": "3 5 1\n#...#\n..#..\n..#..", "output": "#...#\n..#..\nX.#.." }, { "input": "4 5 10\n.....\n.....\n..#..\n..#..", "output": "XXX..\nXXX..\nXX#..\nXX#.." }, { "input": "3 5 3\n.....\n..#..\n..#..", "output": ".....\nX.#..\nXX#.." }, { "input": "3 5 1\n#....\n..#..\n..###", "output": "#....\n..#.X\n..###" }, { "input": "4 5 1\n.....\n.##..\n..#..\n..###", "output": ".....\n.##..\n..#.X\n..###" }, { "input": "3 5 2\n..#..\n..#..\n....#", "output": "X.#..\nX.#..\n....#" }, { "input": "10 10 1\n##########\n##......##\n#..#..#..#\n#..####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########", "output": "##########\n##......##\n#..#..#..#\n#X.####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########" }, { "input": "10 10 3\n..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######..\n.#######..\n.####..###\n.......###", "output": "..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######X.\n.#######XX\n.####..###\n.......###" }, { "input": "5 7 10\n..#....\n..#.#..\n.##.#..\n..#.#..\n....#..", "output": "XX#....\nXX#.#..\nX##.#..\nXX#.#..\nXXX.#.." }, { "input": "5 7 10\n..#....\n..#.##.\n.##.##.\n..#.#..\n....#..", "output": "XX#....\nXX#.##.\nX##.##.\nXX#.#..\nXXX.#.." }, { "input": "10 10 1\n##########\n##..##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########", "output": "##########\n##.X##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########" }, { "input": "4 5 1\n.....\n.###.\n..#..\n..#..", "output": ".....\n.###.\n..#..\n.X#.." }, { "input": "2 5 2\n###..\n###..", "output": "###X.\n###X." }, { "input": "2 5 3\n.....\n..#..", "output": "X....\nXX#.." }, { "input": "12 12 3\n############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######..#\n#.#######..#\n#.####..####\n#.......####\n############", "output": "############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######X.#\n#.#######XX#\n#.####..####\n#.......####\n############" }, { "input": "5 5 1\n.....\n.##..\n..###\n..###\n#####", "output": ".....\n.##.X\n..###\n..###\n#####" }, { "input": "4 4 1\n....\n.#..\n..##\n..##", "output": "....\n.#.X\n..##\n..##" }, { "input": "5 5 1\n....#\n.##..\n.##..\n...##\n...##", "output": "....#\n.##..\n.##.X\n...##\n...##" }, { "input": "5 5 1\n.....\n.##..\n..###\n..###\n..###", "output": ".....\n.##.X\n..###\n..###\n..###" }, { "input": "4 5 1\n#....\n#.#..\n..###\n..###", "output": "#....\n#.#.X\n..###\n..###" }, { "input": "4 4 3\n....\n.#..\n..##\n..##", "output": "...X\n.#XX\n..##\n..##" }, { "input": "4 7 6\n.......\n....#..\n.##.#..\n....#..", "output": "X......\nX...#..\nX##.#..\nXXX.#.." }, { "input": "8 8 7\n........\n.##.....\n.#######\n..######\n..######\n..######\n..######\n..######", "output": ".....XXX\n.##.XXXX\n.#######\n..######\n..######\n..######\n..######\n..######" } ]
280
23,449,600
-1
193
863
Graphic Settings
[]
null
null
Recently Ivan bought a new computer. Excited, he unpacked it and installed his favourite game. With his old computer Ivan had to choose the worst possible graphic settings (because otherwise the framerate would be really low), but now he wants to check, maybe his new computer can perform well even with the best possible graphics? There are *m* graphics parameters in the game. *i*-th parameter can be set to any positive integer from 1 to *a**i*, and initially is set to *b**i* (*b**i*<=≀<=*a**i*). So there are different combinations of parameters. Ivan can increase or decrease any of these parameters by 1; after that the game will be restarted with new parameters (and Ivan will have the opportunity to check chosen combination of parameters). Ivan wants to try all *p* possible combinations. Also he wants to return to the initial settings after trying all combinations, because he thinks that initial settings can be somehow best suited for his hardware. But Ivan doesn't really want to make a lot of restarts. So he wants you to tell the following: - If there exists a way to make exactly *p* changes (each change either decreases or increases some parameter by 1) to try all possible combinations and return to initial combination, then Ivan wants to know this way. - Otherwise, if there exists a way to make exactly *p*<=-<=1 changes to try all possible combinations (including the initial one), then Ivan wants to know this way. Help Ivan by showing him the way to change parameters!
The first line of input contains one integer number *m* (1<=≀<=*m*<=≀<=6). The second line contains *m* integer numbers *a*1,<=*a*2,<=...,<=*a**m* (2<=≀<=*a**i*<=≀<=1000). It is guaranteed that . The third line contains *m* integer numbers *b*1,<=*b*2,<=...,<=*b**m* (1<=≀<=*b**i*<=≀<=*a**i*).
If there is a way to make exactly *p* changes (each change either decreases or increases some parameter by 1) to try all possible combinations and return to initial combination, then output Cycle in the first line. Then *p* lines must follow, each desribing a change. The line must be either inc x (increase parameter *x* by 1) or dec x (decrease it). Otherwise, if there is a way to make exactly *p*<=-<=1 changes to try all possible combinations (including the initial one), then output Path in the first line. Then *p*<=-<=1 lines must follow, each describing the change the same way as mentioned above. Otherwise, output No.
[ "1\n3\n1\n", "1\n3\n2\n", "2\n3 2\n1 1\n" ]
[ "Path\ninc 1\ninc 1\n", "No\n", "Cycle\ninc 1\ninc 1\ninc 2\ndec 1\ndec 1\ndec 2\n" ]
none
[]
31
0
0
195
572
Arrays
[ "sortings" ]
null
null
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
The first line contains two integers *n**A*,<=*n**B* (1<=≀<=*n**A*,<=*n**B*<=≀<=105), separated by a space β€” the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≀<=*k*<=≀<=*n**A*,<=1<=≀<=*m*<=≀<=*n**B*), separated by a space. The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≀<=*a*1<=≀<=*a*2<=≀<=...<=≀<=*a**n**A*<=≀<=109), separated by spaces β€” elements of array *A*. The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≀<=*b*1<=≀<=*b*2<=≀<=...<=≀<=*b**n**B*<=≀<=109), separated by spaces β€” elements of array *B*.
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
[ "3 3\n2 1\n1 2 3\n3 4 5\n", "3 3\n3 3\n1 2 3\n3 4 5\n", "5 2\n3 1\n1 1 1 1 1\n2 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 &lt; 3 and 2 &lt; 3). In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
[ { "input": "3 3\n2 1\n1 2 3\n3 4 5", "output": "YES" }, { "input": "3 3\n3 3\n1 2 3\n3 4 5", "output": "NO" }, { "input": "5 2\n3 1\n1 1 1 1 1\n2 2", "output": "YES" }, { "input": "3 5\n1 1\n5 5 5\n5 5 5 5 5", "output": "NO" }, { "input": "1 1\n1 1\n1\n1", "output": "NO" }, { "input": "3 3\n1 1\n1 2 3\n1 2 3", "output": "YES" }, { "input": "3 3\n1 2\n1 2 3\n1 2 3", "output": "YES" }, { "input": "3 3\n2 2\n1 2 3\n1 2 3", "output": "NO" }, { "input": "10 15\n10 1\n1 1 5 17 22 29 32 36 39 48\n9 10 20 23 26 26 32 32 33 39 43 45 47 49 49", "output": "YES" }, { "input": "10 15\n1 15\n91 91 91 92 92 94 94 95 98 100\n92 92 93 93 93 94 95 96 97 98 98 99 99 100 100", "output": "YES" }, { "input": "15 10\n12 5\n9 25 25 32 32 38 40 41 46 46 48 51 64 64 73\n5 14 30 35 50 52 67 79 89 99", "output": "YES" }, { "input": "15 10\n4 10\n22 32 35 45 45 50 51 55 79 80 83 88 90 92 93\n46 48 52 55 60 60 68 75 80 81", "output": "YES" }, { "input": "20 30\n2 8\n6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 10\n1 1 2 2 2 2 2 2 2 3 3 4 5 5 5 5 6 6 6 6 6 6 7 7 7 8 8 9 10 10", "output": "NO" }, { "input": "20 30\n19 29\n1 1 2 2 2 3 4 4 7 7 7 8 8 8 8 8 9 9 9 9\n6 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "NO" }, { "input": "1 1\n1 1\n-1000000000\n30", "output": "YES" }, { "input": "3 3\n1 3\n1 3 3\n3 3 3", "output": "YES" }, { "input": "3 3\n1 1\n3 3 3\n2 2 2", "output": "NO" }, { "input": "5 5\n3 3\n1 5 6 7 8\n1 2 5 6 7", "output": "NO" }, { "input": "3 4\n2 2\n5 6 7\n1 2 3 4", "output": "NO" }, { "input": "3 3\n3 3\n1 2 3\n4 5 6", "output": "YES" }, { "input": "5 5\n4 5\n2 2 3 4 5\n5 6 7 8 9", "output": "YES" } ]
61
4,608,000
-1
197
233
Perfect Permutation
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≀<=*i*<=≀<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=β‰ <=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
A single line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* β€” permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", "output": "-1" }, { "input": "20", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 " }, { "input": "8", "output": "2 1 4 3 6 5 8 7 " }, { "input": "9", "output": "-1" }, { "input": "10", "output": "2 1 4 3 6 5 8 7 10 9 " }, { "input": "11", "output": "-1" }, { "input": "21", "output": "-1" }, { "input": "50", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 " }, { "input": "51", "output": "-1" }, { "input": "52", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 " }, { "input": "84", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 " }, { "input": "86", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 " }, { "input": "100", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 " }, { "input": "98", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 " }, { "input": "96", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 " }, { "input": "33", "output": "-1" }, { "input": "34", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 " }, { "input": "36", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 " }, { "input": "38", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 " }, { "input": "40", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 " }, { "input": "42", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 " }, { "input": "44", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 " }, { "input": "46", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 " }, { "input": "48", "output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 " } ]
62
0
0
198
0
none
[ "none" ]
null
null
Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**i* and *r**i*, and its elements are *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*]. Alyona is going to find mex for each of the chosen subarrays. Among these *m* mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible. You are to find an array *a* of *n* elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible. The mex of a set *S* is a minimum possible non-negative integer that is not in *S*.
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=105). The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≀<=*l**i*<=≀<=*r**i*<=≀<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,<=*a*[*r**i*].
In the first line print single integerΒ β€” the maximum possible minimum mex. In the second line print *n* integersΒ β€” the array *a*. All the elements in *a* should be between 0 and 109. It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109. If there are multiple solutions, print any of them.
[ "5 3\n1 3\n2 5\n4 5\n", "4 2\n1 4\n2 4\n" ]
[ "2\n1 0 2 1 0\n", "3\n5 2 0 1" ]
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
[ { "input": "5 3\n1 3\n2 5\n4 5", "output": "2\n0 1 0 1 0" }, { "input": "4 2\n1 4\n2 4", "output": "3\n0 1 2 0" }, { "input": "1 1\n1 1", "output": "1\n0" }, { "input": "2 1\n2 2", "output": "1\n0 0" }, { "input": "5 6\n2 4\n2 3\n1 4\n3 4\n2 5\n1 3", "output": "2\n0 1 0 1 0" }, { "input": "8 3\n2 3\n2 8\n3 6", "output": "2\n0 1 0 1 0 1 0 1" }, { "input": "10 10\n1 9\n4 8\n4 8\n5 9\n1 9\n3 8\n1 6\n1 9\n1 6\n6 9", "output": "4\n0 1 2 3 0 1 2 3 0 1" }, { "input": "3 6\n1 3\n1 3\n1 1\n1 1\n3 3\n3 3", "output": "1\n0 0 0" }, { "input": "3 3\n1 3\n2 2\n1 3", "output": "1\n0 0 0" }, { "input": "6 8\n3 5\n3 6\n4 6\n2 5\n2 5\n1 3\n3 6\n3 5", "output": "3\n0 1 2 0 1 2" }, { "input": "10 4\n4 10\n4 6\n6 8\n1 10", "output": "3\n0 1 2 0 1 2 0 1 2 0" }, { "input": "9 1\n1 1", "output": "1\n0 0 0 0 0 0 0 0 0" }, { "input": "3 8\n2 3\n1 3\n1 2\n2 3\n1 3\n2 2\n1 2\n1 2", "output": "1\n0 0 0" }, { "input": "3 8\n1 2\n1 2\n1 1\n2 3\n2 3\n1 1\n1 3\n1 3", "output": "1\n0 0 0" }, { "input": "7 3\n7 7\n3 7\n5 7", "output": "1\n0 0 0 0 0 0 0" }, { "input": "9 9\n4 5\n5 8\n1 8\n4 8\n3 4\n7 8\n1 4\n7 8\n6 7", "output": "2\n0 1 0 1 0 1 0 1 0" }, { "input": "10 10\n1 5\n7 10\n2 10\n2 5\n2 9\n5 9\n3 10\n4 9\n6 9\n2 7", "output": "4\n0 1 2 3 0 1 2 3 0 1" }, { "input": "8 7\n5 8\n3 7\n1 8\n3 4\n2 8\n2 7\n4 6", "output": "2\n0 1 0 1 0 1 0 1" }, { "input": "10 3\n2 4\n8 10\n4 6", "output": "3\n0 1 2 0 1 2 0 1 2 0" }, { "input": "5 8\n3 4\n1 5\n3 4\n3 5\n3 4\n1 4\n1 5\n2 5", "output": "2\n0 1 0 1 0" }, { "input": "9 4\n5 9\n3 8\n2 8\n1 4", "output": "4\n0 1 2 3 0 1 2 3 0" }, { "input": "7 7\n2 4\n1 4\n3 6\n2 6\n5 7\n3 6\n1 4", "output": "3\n0 1 2 0 1 2 0" }, { "input": "6 2\n4 6\n2 5", "output": "3\n0 1 2 0 1 2" }, { "input": "7 9\n6 7\n1 2\n2 5\n4 7\n1 7\n5 6\n2 3\n6 7\n1 2", "output": "2\n0 1 0 1 0 1 0" } ]
46
0
-1
200
160
Twins
[ "greedy", "sortings" ]
null
null
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally. As you woke up, you found Mom's coins and read her note. "But why split the money equally?" β€” you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
The first line contains integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=100) β€” the coins' values. All numbers are separated with spaces.
In the single line print the single number β€” the minimum needed number of coins.
[ "2\n3 3\n", "3\n2 1 2\n" ]
[ "2\n", "2\n" ]
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
[ { "input": "2\n3 3", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "5\n4 2 2 2 2", "output": "3" }, { "input": "7\n1 10 1 2 1 1 1", "output": "1" }, { "input": "5\n3 2 3 3 1", "output": "3" }, { "input": "2\n2 1", "output": "1" }, { "input": "3\n2 1 3", "output": "2" }, { "input": "6\n1 1 1 1 1 1", "output": "4" }, { "input": "7\n10 10 5 5 5 5 1", "output": "3" }, { "input": "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1", "output": "8" }, { "input": "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4", "output": "8" }, { "input": "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40", "output": "8" }, { "input": "20\n7 84 100 10 31 35 41 2 63 44 57 4 63 11 23 49 98 71 16 90", "output": "6" }, { "input": "50\n19 2 12 26 17 27 10 26 17 17 5 24 11 15 3 9 16 18 19 1 25 23 18 6 2 7 25 7 21 25 13 29 16 9 25 3 14 30 18 4 10 28 6 10 8 2 2 4 8 28", "output": "14" }, { "input": "70\n2 18 18 47 25 5 14 9 19 46 36 49 33 32 38 23 32 39 8 29 31 17 24 21 10 15 33 37 46 21 22 11 20 35 39 13 11 30 28 40 39 47 1 17 24 24 21 46 12 2 20 43 8 16 44 11 45 10 13 44 31 45 45 46 11 10 33 35 23 42", "output": "22" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "51" }, { "input": "100\n1 2 2 1 2 1 1 2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2", "output": "37" }, { "input": "100\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2", "output": "36" }, { "input": "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3", "output": "33" }, { "input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2", "output": "30" }, { "input": "100\n16 9 11 8 11 4 9 17 4 8 4 10 9 10 6 3 3 15 1 6 1 15 12 18 6 14 13 18 1 7 18 4 10 7 10 12 3 16 14 4 10 8 10 7 19 13 15 1 4 8 16 10 6 4 3 16 11 10 7 3 4 16 1 20 1 11 4 16 10 7 7 12 18 19 3 17 19 3 4 19 2 12 11 3 18 20 2 2 14 4 20 13 13 11 16 20 19 14 7 2", "output": "29" }, { "input": "100\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1", "output": "30" }, { "input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "output": "29" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "30" }, { "input": "1\n1", "output": "1" }, { "input": "4\n4 1 2 3", "output": "2" }, { "input": "5\n2 2 2 4 4", "output": "2" }, { "input": "4\n100 99 99 100", "output": "2" } ]
0
0
-1
201
940
Our Tanya is Crying Out Loud
[ "dp", "greedy" ]
null
null
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations: 1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins.
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=2Β·109). The second line contains a single integer *k* (1<=≀<=*k*<=≀<=2Β·109). The third line contains a single integer *A* (1<=≀<=*A*<=≀<=2Β·109). The fourth line contains a single integer *B* (1<=≀<=*B*<=≀<=2Β·109).
Output a single integerΒ β€” the minimum amount of coins you have to pay to make *x* equal to 1.
[ "9\n2\n3\n1\n", "5\n5\n2\n20\n", "19\n3\n4\n2\n" ]
[ "6\n", "8\n", "12\n" ]
In the first testcase, the optimal strategy is as follows: - Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin. The total cost is 6 coins. In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total.
[ { "input": "9\n2\n3\n1", "output": "6" }, { "input": "5\n5\n2\n20", "output": "8" }, { "input": "19\n3\n4\n2", "output": "12" }, { "input": "1845999546\n999435865\n1234234\n2323423", "output": "1044857680578777" }, { "input": "1604353664\n1604353665\n9993432\n1", "output": "16032999235141416" }, { "input": "777888456\n1\n98\n43", "output": "76233068590" }, { "input": "1162261467\n3\n1\n2000000000", "output": "1162261466" }, { "input": "1000000000\n1999999999\n789987\n184569875", "output": "789986999210013" }, { "input": "2000000000\n2\n1\n2000000000", "output": "1999999999" }, { "input": "1999888325\n3\n2\n2000000000", "output": "3333258884" }, { "input": "1897546487\n687\n89798979\n879876541", "output": "110398404423" }, { "input": "20\n1\n20\n1", "output": "380" }, { "input": "16\n5\n17\n3", "output": "54" }, { "input": "19\n19\n19\n1", "output": "1" }, { "input": "18\n2\n3\n16", "output": "40" }, { "input": "1\n11\n8\n9", "output": "0" }, { "input": "9\n10\n1\n20", "output": "8" }, { "input": "19\n10\n19\n2", "output": "173" }, { "input": "16\n9\n14\n2", "output": "100" }, { "input": "15\n2\n5\n2", "output": "21" }, { "input": "14\n7\n13\n1", "output": "14" }, { "input": "43\n3\n45\n3", "output": "189" }, { "input": "99\n1\n98\n1", "output": "9604" }, { "input": "77\n93\n100\n77", "output": "7600" }, { "input": "81\n3\n91\n95", "output": "380" }, { "input": "78\n53\n87\n34", "output": "2209" }, { "input": "80\n3\n15\n1", "output": "108" }, { "input": "97\n24\n4\n24", "output": "40" }, { "input": "100\n100\n1\n100", "output": "99" }, { "input": "87\n4\n17\n7", "output": "106" }, { "input": "65\n2\n3\n6", "output": "36" }, { "input": "1000000\n1435\n3\n999999", "output": "1005804" }, { "input": "783464\n483464\n2\n966928", "output": "1566926" }, { "input": "248035\n11\n3\n20", "output": "202" }, { "input": "524287\n2\n945658\n999756", "output": "34963354" }, { "input": "947352\n78946\n85\n789654", "output": "790589" }, { "input": "1000000\n1\n999899\n60", "output": "999898000101" }, { "input": "753687\n977456\n6547\n456", "output": "4934382242" }, { "input": "1000000\n500000\n1\n999997", "output": "999998" }, { "input": "997458\n843596\n1\n843596", "output": "997457" }, { "input": "821109\n92\n6547\n98787", "output": "394566" }, { "input": "1073741823\n2\n9543\n8923453", "output": "188412866" }, { "input": "1000999777\n1934999345\n2356346\n34534565", "output": "2358701818178496" }, { "input": "2000000000\n1\n2000000000\n98", "output": "3999999998000000000" }, { "input": "1999324353\n978435356\n1\n978435356", "output": "1020888998" }, { "input": "2000000000\n2\n2000000000\n2000000000", "output": "84000000000" }, { "input": "241375690\n17\n2\n1998789654", "output": "482751378" }, { "input": "171507000\n350\n789\n6548687", "output": "14216965" }, { "input": "1100220011\n10001\n2\n1999778654", "output": "1999998674" }, { "input": "1867622656\n43216\n789644\n12315468", "output": "24630936" }, { "input": "1867622656\n43216\n1\n1879865413", "output": "1867622655" }, { "input": "1999999999\n1000000000\n789987\n184569875", "output": "789987183779888" }, { "input": "1987987897\n103546\n7\n98754563", "output": "98946650" }, { "input": "10\n2\n2\n5", "output": "13" }, { "input": "7\n2\n1\n100000", "output": "6" }, { "input": "7\n2\n3\n1", "output": "8" }, { "input": "2000000000\n666666667\n1\n1", "output": "666666668" }, { "input": "1999999997\n666666666\n2\n2", "output": "1333333334" } ]
124
22,528,000
0
204
110
Nearly Lucky Number
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
The only line contains an integer *n* (1<=≀<=*n*<=≀<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { "input": "4744000695826", "output": "YES" }, { "input": "10000000004744744", "output": "YES" }, { "input": "446486416781684178", "output": "YES" }, { "input": "999999999", "output": "NO" }, { "input": "7777", "output": "YES" }, { "input": "87414417444", "output": "NO" }, { "input": "111222333444555667", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "4700", "output": "NO" }, { "input": "3794555488744477", "output": "NO" }, { "input": "444444444444444444", "output": "NO" }, { "input": "474447447774444774", "output": "NO" }, { "input": "777777777777777", "output": "NO" }, { "input": "34777745021000000", "output": "NO" }, { "input": "963", "output": "NO" }, { "input": "855474448854788540", "output": "NO" }, { "input": "999999999999994744", "output": "YES" }, { "input": "400000000474", "output": "YES" }, { "input": "123456789123456789", "output": "YES" }, { "input": "740577777584945874", "output": "NO" }, { "input": "7777777", "output": "YES" }, { "input": "4444000111222333", "output": "YES" }, { "input": "9847745885202111", "output": "YES" }, { "input": "123456000000", "output": "NO" }, { "input": "4744447444444", "output": "NO" }, { "input": "7477", "output": "YES" }, { "input": "4747477", "output": "YES" }, { "input": "777777777444444444", "output": "NO" } ]
92
0
0
205
478
Random Teams
[ "combinatorics", "constructive algorithms", "greedy", "math" ]
null
null
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.
The only line of input contains two integers *n* and *m*, separated by a single space (1<=≀<=*m*<=≀<=*n*<=≀<=109) β€” the number of participants and the number of teams respectively.
The only line of the output should contain two integers *k**min* and *k**max* β€” the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
[ "5 1\n", "3 2\n", "6 3\n" ]
[ "10 10\n", "1 1\n", "3 6\n" ]
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends. In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one. In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.
[ { "input": "5 1", "output": "10 10" }, { "input": "3 2", "output": "1 1" }, { "input": "6 3", "output": "3 6" }, { "input": "5 3", "output": "2 3" }, { "input": "10 2", "output": "20 36" }, { "input": "10 6", "output": "4 10" }, { "input": "1000000000 1", "output": "499999999500000000 499999999500000000" }, { "input": "5000000 12", "output": "1041664166668 12499942500066" }, { "input": "1833 195", "output": "7722 1342341" }, { "input": "1000000000 1000000000", "output": "0 0" }, { "input": "1000000000 1000000", "output": "499500000000 499000500499500000" }, { "input": "1000000000 32170", "output": "15541930838100 499967831017438365" }, { "input": "1000000 1000", "output": "499500000 499000999500" }, { "input": "1234 1123", "output": "111 6216" }, { "input": "599222887 298488", "output": "601178656545 179355218158217800" }, { "input": "999999999 500000000", "output": "499999999 124999999750000000" }, { "input": "1000000000 384842119", "output": "845473643 189209609585784021" }, { "input": "1000000000 384842119", "output": "845473643 189209609585784021" }, { "input": "1000000000 2", "output": "249999999500000000 499999998500000001" }, { "input": "1000000000 999999999", "output": "1 1" }, { "input": "38447 383", "output": "1910550 724453080" }, { "input": "100000000 99999799", "output": "201 20301" }, { "input": "1 1", "output": "0 0" }, { "input": "2 1", "output": "1 1" }, { "input": "2 2", "output": "0 0" }, { "input": "10 10", "output": "0 0" } ]
61
0
3
207
793
Igor and his way to work
[ "dfs and similar", "graphs", "implementation", "shortest paths" ]
null
null
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel, so he can make no more than two turns on his way to his office in bank. Bankopolis looks like a grid of *n* rows and *m* columns. Igor should find a way from his home to the bank that has no more than two turns and doesn't contain cells with road works, or determine that it is impossible and he should work from home. A turn is a change in movement direction. Igor's car can only move to the left, to the right, upwards and downwards. Initially Igor can choose any direction. Igor is still sleepy, so you should help him.
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=1000)Β β€” the number of rows and the number of columns in the grid. Each of the next *n* lines contains *m* characters denoting the corresponding row of the grid. The following characters can occur: - "." β€” an empty cell; - "*" β€” a cell with road works; - "S" β€” the cell where Igor's home is located; - "T" β€” the cell where Igor's office is located. It is guaranteed that "S" and "T" appear exactly once each.
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
[ "5 5\n..S..\n****.\nT....\n****.\n.....\n", "5 5\nS....\n****.\n.....\n.****\n..T..\n" ]
[ "YES", "NO" ]
The first sample is shown on the following picture: In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:
[ { "input": "5 5\nS....\n****.\n.....\n.****\n..T..", "output": "NO" }, { "input": "1 2\nST", "output": "YES" }, { "input": "3 1\nS\n*\nT", "output": "NO" }, { "input": "3 3\n*..\n...\nTS.", "output": "YES" }, { "input": "3 3\nT.*\n*.*\n*S*", "output": "YES" }, { "input": "7 7\n.S.****\n...*.*.\n.****..\n.*.**.*\n..T*...\n***..*.\n*******", "output": "YES" }, { "input": "3 3\n**T\n*S*\n***", "output": "NO" }, { "input": "2 2\nST\n*.", "output": "YES" }, { "input": "2 2\nS.\n.T", "output": "YES" }, { "input": "2 2\nTS\n.*", "output": "YES" }, { "input": "2 2\n.T\nS*", "output": "YES" } ]
3,000
127,897,600
0
208
41
Translation
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the Β«translationΒ». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
30
0
0
209
868
Race Against Time
[ "implementation" ]
null
null
Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other. The entire universe turned into an enormous clock face with three handsΒ β€” hour, minute, and second. Time froze, and clocks now show the time *h* hours, *m* minutes, *s* seconds. Last time Misha talked with the coordinator at *t*1 o'clock, so now he stands on the number *t*1 on the clock face. The contest should be ready by *t*2 o'clock. In the terms of paradox it means that Misha has to go to number *t*2 somehow. Note that he doesn't have to move forward only: in these circumstances time has no direction. Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way). Given the hands' positions, *t*1, and *t*2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from *t*1 to *t*2 by the clock face.
Five integers *h*, *m*, *s*, *t*1, *t*2 (1<=≀<=*h*<=≀<=12, 0<=≀<=*m*,<=*s*<=≀<=59, 1<=≀<=*t*1,<=*t*2<=≀<=12, *t*1<=β‰ <=*t*2). Misha's position and the target time do not coincide with the position of any hand.
Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
[ "12 30 45 3 11\n", "12 0 1 12 1\n", "3 47 0 4 9\n" ]
[ "NO\n", "YES\n", "YES\n" ]
The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same.
[ { "input": "12 30 45 3 11", "output": "NO" }, { "input": "12 0 1 12 1", "output": "YES" }, { "input": "3 47 0 4 9", "output": "YES" }, { "input": "10 22 59 6 10", "output": "YES" }, { "input": "3 1 13 12 3", "output": "NO" }, { "input": "11 19 28 9 10", "output": "YES" }, { "input": "9 38 22 6 1", "output": "NO" }, { "input": "5 41 11 5 8", "output": "NO" }, { "input": "11 2 53 10 4", "output": "YES" }, { "input": "9 41 17 10 1", "output": "YES" }, { "input": "6 54 48 12 6", "output": "YES" }, { "input": "12 55 9 5 1", "output": "NO" }, { "input": "8 55 35 9 3", "output": "NO" }, { "input": "3 21 34 3 10", "output": "YES" }, { "input": "2 52 1 12 3", "output": "NO" }, { "input": "7 17 11 1 7", "output": "NO" }, { "input": "11 6 37 6 4", "output": "YES" }, { "input": "9 6 22 8 1", "output": "NO" }, { "input": "3 10 5 5 9", "output": "YES" }, { "input": "7 12 22 11 2", "output": "YES" }, { "input": "7 19 4 7 3", "output": "NO" }, { "input": "11 36 21 4 6", "output": "NO" }, { "input": "10 32 49 1 3", "output": "YES" }, { "input": "1 9 43 11 3", "output": "NO" }, { "input": "1 8 33 4 8", "output": "NO" }, { "input": "3 0 33 9 4", "output": "NO" }, { "input": "7 15 9 10 3", "output": "NO" }, { "input": "8 3 57 11 1", "output": "NO" }, { "input": "1 33 49 5 9", "output": "NO" }, { "input": "3 40 0 5 7", "output": "YES" }, { "input": "5 50 9 2 7", "output": "NO" }, { "input": "10 0 52 6 1", "output": "YES" }, { "input": "3 10 4 1 11", "output": "NO" }, { "input": "2 41 53 4 6", "output": "YES" }, { "input": "10 29 30 4 7", "output": "NO" }, { "input": "5 13 54 9 11", "output": "NO" }, { "input": "1 0 23 3 9", "output": "NO" }, { "input": "1 0 41 12 1", "output": "NO" }, { "input": "6 30 30 3 9", "output": "YES" }, { "input": "3 7 32 11 10", "output": "YES" }, { "input": "1 0 25 12 4", "output": "NO" }, { "input": "12 0 0 5 6", "output": "YES" }, { "input": "1 5 4 3 2", "output": "YES" }, { "input": "6 30 30 9 10", "output": "YES" }, { "input": "6 0 0 2 8", "output": "NO" }, { "input": "10 50 59 9 10", "output": "YES" }, { "input": "12 59 59 12 6", "output": "NO" }, { "input": "3 0 30 3 4", "output": "NO" }, { "input": "2 10 10 1 11", "output": "YES" }, { "input": "10 5 30 1 12", "output": "YES" }, { "input": "5 29 31 5 10", "output": "YES" }, { "input": "5 2 2 11 2", "output": "NO" }, { "input": "5 15 46 3 10", "output": "YES" }, { "input": "1 30 50 1 2", "output": "NO" }, { "input": "5 26 14 1 12", "output": "YES" }, { "input": "1 58 43 12 1", "output": "YES" }, { "input": "12 0 12 11 1", "output": "NO" }, { "input": "6 52 41 6 5", "output": "YES" }, { "input": "5 8 2 1 3", "output": "NO" }, { "input": "2 0 0 1 3", "output": "NO" }, { "input": "1 5 6 2 1", "output": "YES" }, { "input": "9 5 5 11 12", "output": "YES" }, { "input": "12 5 19 3 4", "output": "NO" }, { "input": "6 14 59 1 3", "output": "NO" }, { "input": "10 38 34 4 12", "output": "YES" }, { "input": "2 54 14 2 12", "output": "YES" }, { "input": "5 31 0 6 7", "output": "NO" }, { "input": "6 15 30 3 9", "output": "YES" }, { "input": "3 54 41 8 10", "output": "NO" }, { "input": "3 39 10 10 12", "output": "YES" }, { "input": "1 11 50 1 2", "output": "NO" }, { "input": "5 40 24 8 1", "output": "NO" }, { "input": "9 5 59 1 3", "output": "NO" }, { "input": "5 0 0 6 7", "output": "YES" }, { "input": "4 40 59 6 8", "output": "YES" }, { "input": "10 13 55 12 1", "output": "YES" }, { "input": "6 50 0 5 6", "output": "YES" }, { "input": "7 59 3 7 4", "output": "YES" }, { "input": "6 0 1 6 7", "output": "NO" }, { "input": "6 15 55 3 5", "output": "NO" }, { "input": "12 9 55 10 2", "output": "YES" }, { "input": "2 0 1 11 2", "output": "NO" }, { "input": "8 45 17 12 9", "output": "NO" }, { "input": "5 30 31 11 3", "output": "YES" }, { "input": "6 43 0 10 6", "output": "NO" }, { "input": "6 30 30 1 11", "output": "YES" }, { "input": "11 59 59 11 12", "output": "YES" }, { "input": "5 45 35 9 5", "output": "NO" }, { "input": "2 43 4 9 7", "output": "NO" }, { "input": "12 30 50 6 9", "output": "NO" }, { "input": "1 10 1 2 3", "output": "NO" }, { "input": "10 5 55 9 1", "output": "NO" }, { "input": "1 59 59 2 3", "output": "YES" }, { "input": "1 49 14 10 3", "output": "NO" }, { "input": "3 15 15 2 4", "output": "YES" }, { "input": "10 5 55 1 5", "output": "NO" }, { "input": "6 33 45 12 6", "output": "YES" }, { "input": "1 20 20 11 1", "output": "YES" }, { "input": "2 30 45 1 11", "output": "YES" }, { "input": "1 55 1 11 10", "output": "YES" }, { "input": "3 0 1 11 1", "output": "NO" }, { "input": "1 5 6 1 12", "output": "YES" }, { "input": "12 10 5 11 4", "output": "YES" }, { "input": "6 5 59 12 1", "output": "YES" }, { "input": "12 0 20 11 12", "output": "YES" }, { "input": "3 25 30 4 5", "output": "YES" }, { "input": "2 15 18 11 1", "output": "YES" }, { "input": "12 5 48 11 9", "output": "NO" }, { "input": "6 30 30 10 2", "output": "YES" }, { "input": "1 0 11 1 2", "output": "NO" }, { "input": "10 0 1 10 11", "output": "NO" }, { "input": "3 30 45 10 1", "output": "YES" }, { "input": "11 21 56 3 12", "output": "YES" }, { "input": "3 16 16 3 4", "output": "YES" }, { "input": "11 55 55 1 12", "output": "YES" }, { "input": "12 12 12 11 12", "output": "YES" }, { "input": "3 5 1 1 2", "output": "NO" }, { "input": "3 30 45 10 11", "output": "YES" }, { "input": "10 0 1 9 10", "output": "YES" }, { "input": "3 0 5 3 6", "output": "NO" }, { "input": "1 1 49 1 10", "output": "NO" }, { "input": "9 45 15 11 12", "output": "YES" }, { "input": "12 15 59 3 8", "output": "NO" }, { "input": "5 0 5 3 6", "output": "NO" }, { "input": "3 30 45 1 2", "output": "YES" }, { "input": "2 10 11 2 4", "output": "YES" }, { "input": "2 10 10 4 3", "output": "YES" }, { "input": "3 30 59 1 2", "output": "YES" }, { "input": "11 59 59 12 11", "output": "YES" }, { "input": "10 25 50 5 6", "output": "NO" }, { "input": "6 30 30 9 3", "output": "YES" }, { "input": "8 14 40 12 3", "output": "NO" }, { "input": "2 10 10 1 6", "output": "YES" } ]
140
0
0
210
509
Maximum in Table
[ "brute force", "implementation" ]
null
null
An *n*<=Γ—<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1. These conditions define all the values in the table. You are given a number *n*. You need to determine the maximum value in the *n*<=Γ—<=*n* table defined by the rules above.
The only line of input contains a positive integer *n* (1<=≀<=*n*<=≀<=10) β€” the number of rows and columns of the table.
Print a single line containing a positive integer *m* β€” the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" }, { "input": "9", "output": "12870" }, { "input": "10", "output": "48620" }, { "input": "8", "output": "3432" } ]
46
0
3
211
144
Arrival of the General
[ "implementation" ]
null
null
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important. For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong. Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
The first input line contains the only integer *n* (2<=≀<=*n*<=≀<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Print the only integer β€” the minimum number of seconds the colonel will need to form a line-up the general will like.
[ "4\n33 44 11 22\n", "7\n10 10 58 31 63 40 76\n" ]
[ "2\n", "10\n" ]
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10)
[ { "input": "4\n33 44 11 22", "output": "2" }, { "input": "7\n10 10 58 31 63 40 76", "output": "10" }, { "input": "2\n88 89", "output": "1" }, { "input": "5\n100 95 100 100 88", "output": "0" }, { "input": "7\n48 48 48 48 45 45 45", "output": "0" }, { "input": "10\n68 47 67 29 63 71 71 65 54 56", "output": "10" }, { "input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92", "output": "4" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14", "output": "0" }, { "input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42", "output": "7" }, { "input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99", "output": "47" }, { "input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57", "output": "50" }, { "input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13", "output": "3" }, { "input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36", "output": "3" }, { "input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73", "output": "73" }, { "input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68", "output": "7" }, { "input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94", "output": "15" }, { "input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64", "output": "104" }, { "input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97", "output": "33" }, { "input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43", "output": "145" }, { "input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26", "output": "76" }, { "input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34", "output": "15" }, { "input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81", "output": "11" }, { "input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95", "output": "13" }, { "input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15", "output": "104" }, { "input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67", "output": "100" }, { "input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32", "output": "107" }, { "input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22", "output": "50" }, { "input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61", "output": "59" }, { "input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95", "output": "99" }, { "input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10", "output": "0" }, { "input": "3\n2 1 2", "output": "1" }, { "input": "2\n100 99", "output": "0" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "197" }, { "input": "100\n87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87", "output": "0" }, { "input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n2 2 2", "output": "0" }, { "input": "3\n1 3 2", "output": "2" } ]
60
0
0
212
468
24 Game
[ "constructive algorithms", "greedy", "math" ]
null
null
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game. Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them, let's denote them *a* and *b*, erase them from the sequence, and append to the sequence either *a*<=+<=*b*, or *a*<=-<=*b*, or *a*<=Γ—<=*b*. After *n*<=-<=1 steps there is only one number left. Can you make this number equal to 24?
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=105).
If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes). If there is a way to obtain 24 as the result number, in the following *n*<=-<=1 lines print the required operations an operation per line. Each operation should be in form: "*a* *op* *b* = *c*". Where *a* and *b* are the numbers you've picked at this operation; *op* is either "+", or "-", or "*"; *c* is the result of corresponding operation. Note, that the absolute value of *c* mustn't be greater than 1018. The result of the last operation must be equal to 24. Separate operator sign and equality sign from numbers with spaces. If there are multiple valid answers, you may print any of them.
[ "1\n", "8\n" ]
[ "NO\n", "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24\n" ]
none
[ { "input": "1", "output": "NO" }, { "input": "8", "output": "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24" }, { "input": "12", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24" }, { "input": "100", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "1000", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "987", "output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..." }, { "input": "2", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24" }, { "input": "5", "output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24" }, { "input": "6", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24" }, { "input": "7", "output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24" }, { "input": "100000", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "99999", "output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..." }, { "input": "99998", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "99997", "output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..." }, { "input": "580", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "422", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "116", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "447", "output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..." }, { "input": "62052", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "25770", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "56118", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "86351", "output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..." }, { "input": "48108", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "33373", "output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24\n9 - 8 = 1\n24 * 1 = 24\n11 - 10 = 1\n24 * 1 = 24\n13 - 12 = 1\n24 * 1 = 24\n15 - 14 = 1\n24 * 1 = 24\n17 - 16 = 1\n24 * 1 = 24\n19 - 18 = 1\n24 * 1 = 24\n21 - 20 = 1\n24 * 1 = 24\n23 - 22 = 1\n24 * 1 = 24\n25 - 24 = 1\n24 * 1 = 24\n27 - 26 = 1\n24 * 1 = 24\n29 - 28 = 1\n24 * 1 = 24\n31 - 30 = 1\n24 * 1 = 24\n33 - 32 = 1\n24 * 1 = 24\n35 - 34 = 1\n24 * 1 = 24\n37 - 36 = 1\n24 * 1 = 24\n39 - 38 = 1\n24 * 1 = 24\n41 - 40 = 1\n24 * 1 = 2..." }, { "input": "9782", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "19082", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 = 1\n24 * 1 = 24\n12 - 11 = 1\n24 * 1 = 24\n14 - 13 = 1\n24 * 1 = 24\n16 - 15 = 1\n24 * 1 = 24\n18 - 17 = 1\n24 * 1 = 24\n20 - 19 = 1\n24 * 1 = 24\n22 - 21 = 1\n24 * 1 = 24\n24 - 23 = 1\n24 * 1 = 24\n26 - 25 = 1\n24 * 1 = 24\n28 - 27 = 1\n24 * 1 = 24\n30 - 29 = 1\n24 * 1 = 24\n32 - 31 = 1\n24 * 1 = 24\n34 - 33 = 1\n24 * 1 = 24\n36 - 35 = 1\n24 * 1 = 24\n38 - 37 = 1\n24 * 1 = 24\n40 - 39 = 1\n24 * 1 = 24\n42 - 41..." }, { "input": "4", "output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24" }, { "input": "7", "output": "YES\n5 - 3 = 2\n2 * 4 = 8\n1 + 2 = 3\n8 * 3 = 24\n7 - 6 = 1\n24 * 1 = 24" }, { "input": "3", "output": "NO" } ]
249
26,828,800
3
213
868
Bark to Unlock
[ "brute force", "implementation", "strings" ]
null
null
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.
The first line contains two lowercase English lettersΒ β€” the password on the phone. The second line contains single integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of words Kashtanka knows. The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "ya\n4\nah\noy\nto\nha\n", "hp\n2\nht\ntp\n", "ah\n1\nha\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES". In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring. In the third example the string "hahahaha" contains "ah" as a substring.
[ { "input": "ya\n4\nah\noy\nto\nha", "output": "YES" }, { "input": "hp\n2\nht\ntp", "output": "NO" }, { "input": "ah\n1\nha", "output": "YES" }, { "input": "bb\n4\nba\nab\naa\nbb", "output": "YES" }, { "input": "bc\n4\nca\nba\nbb\ncc", "output": "YES" }, { "input": "ba\n4\ncd\nad\ncc\ncb", "output": "YES" }, { "input": "pg\n4\nzl\nxs\ndi\nxn", "output": "NO" }, { "input": "bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nro\nya\nqy\ngu\nvk\nqk\ngs\nyq\nop\nhw\nrj\neo\nlz\nbh\nkr\nkb\nma\nrd\nza\nuf\nhq\nmc\nmn\nti\nwn\nsh\nax\nsi\nnd\ntz\ndu\nfj\nkl\nws\now\nnf\nvr\nye\nzc\niw\nfv\nkv\noo\nsm\nbc\nrs\nau\nuz\nuv\ngh\nsu\njn\ndz\nrl\nwj\nbk\nzl\nas\nms\nit\nwu", "output": "YES" }, { "input": "bb\n1\naa", "output": "NO" }, { "input": "qm\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm", "output": "NO" }, { "input": "mq\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm", "output": "YES" }, { "input": "aa\n1\naa", "output": "YES" }, { "input": "bb\n1\nbb", "output": "YES" }, { "input": "ba\n1\ncc", "output": "NO" }, { "input": "ha\n1\nha", "output": "YES" }, { "input": "aa\n1\naa", "output": "YES" }, { "input": "ez\n1\njl", "output": "NO" }, { "input": "aa\n2\nab\nba", "output": "YES" }, { "input": "aa\n2\nca\ncc", "output": "NO" }, { "input": "dd\n2\nac\ndc", "output": "NO" }, { "input": "qc\n2\nyc\nkr", "output": "NO" }, { "input": "aa\n3\nba\nbb\nab", "output": "YES" }, { "input": "ca\n3\naa\nbb\nab", "output": "NO" }, { "input": "ca\n3\nbc\nbd\nca", "output": "YES" }, { "input": "dd\n3\nmt\nrg\nxl", "output": "NO" }, { "input": "be\n20\nad\ncd\ncb\ndb\ndd\naa\nab\nca\nae\ned\ndc\nbb\nba\nda\nee\nea\ncc\nac\nec\neb", "output": "YES" }, { "input": "fc\n20\nca\nbb\nce\nfd\nde\nfa\ncc\nec\nfb\nfc\nff\nbe\ncf\nba\ndb\ned\naf\nae\nda\nef", "output": "YES" }, { "input": "ca\n20\ndc\naf\ndf\neg\naa\nbc\nea\nbd\nab\ndb\ngc\nfb\nba\nbe\nee\ngf\ncf\nag\nga\nca", "output": "YES" }, { "input": "ke\n20\nzk\nra\nbq\nqz\nwt\nzg\nmz\nuk\nge\nuv\nud\nfd\neh\ndm\nsk\nki\nfv\ntp\nat\nfb", "output": "YES" }, { "input": "hh\n50\nag\nhg\ndg\nfh\neg\ngh\ngd\nda\nbh\nab\nhf\ndc\nhb\nfe\nad\nec\nac\nfd\nca\naf\ncg\nhd\neb\nce\nhe\nha\ngb\nea\nae\nfb\nff\nbe\nch\nhh\nee\nde\nge\ngf\naa\ngg\neh\ned\nbf\nfc\nah\nga\nbd\ncb\nbg\nbc", "output": "YES" }, { "input": "id\n50\nhi\ndc\nfg\nee\ngi\nhc\nac\nih\ndg\nfc\nde\ned\nie\neb\nic\ncf\nib\nfa\ngc\nba\nbe\nga\nha\nhg\nia\ndf\nab\nei\neh\nad\nii\nci\ndh\nec\nif\ndi\nbg\nag\nhe\neg\nca\nae\ndb\naa\nid\nfh\nhh\ncc\nfb\ngb", "output": "YES" }, { "input": "fe\n50\nje\nbi\nbg\ngc\nfb\nig\ndf\nji\ndg\nfe\nfc\ncf\ngf\nai\nhe\nac\nch\nja\ngh\njf\nge\ncb\nij\ngb\ncg\naf\neh\nee\nhd\njd\njb\nii\nca\nci\nga\nab\nhi\nag\nfj\nej\nfi\nie\ndj\nfg\nef\njc\njg\njh\nhf\nha", "output": "YES" }, { "input": "rn\n50\nba\nec\nwg\nao\nlk\nmz\njj\ncf\nfa\njk\ndy\nsz\njs\nzr\nqv\ntx\nwv\nrd\nqw\nls\nrr\nvt\nrx\nkc\neh\nnj\niq\nyi\nkh\nue\nnv\nkz\nrn\nes\nua\nzf\nvu\nll\neg\nmj\ncz\nzj\nxz\net\neb\nci\nih\nig\nam\nvd", "output": "YES" }, { "input": "ee\n100\nah\nfb\ncd\nbi\nii\nai\nid\nag\nie\nha\ndi\nec\nae\nce\njb\ndg\njg\ngd\ngf\nda\nih\nbd\nhj\ngg\nhb\ndf\ned\nfh\naf\nja\nci\nfc\nic\nji\nac\nhi\nfj\nch\nbc\njd\naa\nff\nad\ngj\nej\nde\nee\nhe\ncf\nga\nia\ncg\nbb\nhc\nbe\ngi\njf\nbg\naj\njj\nbh\nfe\ndj\nef\ngb\nge\ndb\nig\ncj\ndc\nij\njh\nei\ndd\nib\nhf\neg\nbf\nfg\nab\ngc\nfd\nhd\ngh\neh\njc\neb\nhh\nca\nje\nbj\nif\nea\nhg\nfa\ncc\nba\ndh\ncb\nfi", "output": "YES" }, { "input": "if\n100\njd\nbc\nje\nhi\nga\nde\nkb\nfc\ncd\ngd\naj\ncb\nei\nbf\ncf\ndk\ndb\ncg\nki\ngg\nkg\nfa\nkj\nii\njf\njg\ngb\nbh\nbg\neh\nhj\nhb\ndg\ndj\njc\njb\nce\ndi\nig\nci\ndf\nji\nhc\nfk\naf\nac\ngk\nhd\nae\nkd\nec\nkc\neb\nfh\nij\nie\nca\nhh\nkf\nha\ndd\nif\nef\nih\nhg\nej\nfe\njk\nea\nib\nck\nhf\nak\ngi\nch\ndc\nba\nke\nad\nka\neg\njh\nja\ngc\nfd\ncc\nab\ngj\nik\nfg\nbj\nhe\nfj\nge\ngh\nhk\nbk\ned\nid\nfi", "output": "YES" }, { "input": "kd\n100\nek\nea\nha\nkf\nkj\ngh\ndl\nfj\nal\nga\nlj\nik\ngd\nid\ncb\nfh\ndk\nif\nbh\nkb\nhc\nej\nhk\ngc\ngb\nef\nkk\nll\nlf\nkh\ncl\nlh\njj\nil\nhh\nci\ndb\ndf\ngk\njg\nch\nbd\ncg\nfg\nda\neb\nlg\ndg\nbk\nje\nbg\nbl\njl\ncj\nhb\nei\naa\ngl\nka\nfa\nfi\naf\nkc\nla\ngi\nij\nib\nle\ndi\nck\nag\nlc\nca\nge\nie\nlb\nke\nii\nae\nig\nic\nhe\ncf\nhd\nak\nfb\nhi\ngf\nad\nba\nhg\nbi\nkl\nac\ngg\ngj\nbe\nlk\nld\naj", "output": "YES" }, { "input": "ab\n1\nab", "output": "YES" }, { "input": "ya\n1\nya", "output": "YES" }, { "input": "ay\n1\nyb", "output": "NO" }, { "input": "ax\n2\nii\nxa", "output": "YES" }, { "input": "hi\n1\nhi", "output": "YES" }, { "input": "ag\n1\nag", "output": "YES" }, { "input": "th\n1\nth", "output": "YES" }, { "input": "sb\n1\nsb", "output": "YES" }, { "input": "hp\n1\nhp", "output": "YES" }, { "input": "ah\n1\nah", "output": "YES" }, { "input": "ta\n1\nta", "output": "YES" }, { "input": "tb\n1\ntb", "output": "YES" }, { "input": "ab\n5\nca\nda\nea\nfa\nka", "output": "NO" }, { "input": "ac\n1\nac", "output": "YES" }, { "input": "ha\n2\nha\nzz", "output": "YES" }, { "input": "ok\n1\nok", "output": "YES" }, { "input": "bc\n1\nbc", "output": "YES" }, { "input": "az\n1\nzz", "output": "NO" }, { "input": "ab\n2\nba\ntt", "output": "YES" }, { "input": "ah\n2\nap\nhp", "output": "NO" }, { "input": "sh\n1\nsh", "output": "YES" }, { "input": "az\n1\nby", "output": "NO" }, { "input": "as\n1\nas", "output": "YES" }, { "input": "ab\n2\nab\ncd", "output": "YES" }, { "input": "ab\n2\nxa\nza", "output": "NO" }, { "input": "ab\n2\net\nab", "output": "YES" }, { "input": "ab\n1\naa", "output": "NO" }, { "input": "ab\n2\nab\nde", "output": "YES" }, { "input": "ah\n2\nba\nha", "output": "YES" }, { "input": "ha\n3\ndd\ncc\nha", "output": "YES" }, { "input": "oo\n1\nox", "output": "NO" }, { "input": "ab\n2\nax\nbx", "output": "NO" }, { "input": "ww\n4\nuw\now\npo\nko", "output": "NO" }, { "input": "ay\n1\nay", "output": "YES" }, { "input": "yo\n1\nyo", "output": "YES" }, { "input": "ba\n1\nba", "output": "YES" }, { "input": "qw\n1\nqw", "output": "YES" }, { "input": "la\n1\nla", "output": "YES" }, { "input": "ab\n2\nbb\nbc", "output": "NO" }, { "input": "aa\n2\nab\nac", "output": "NO" }, { "input": "ah\n2\nbb\nha", "output": "YES" }, { "input": "ya\n42\nab\nac\nad\nae\naf\nag\nah\nai\nak\naj\nba\nbc\nbd\nbe\nbf\nbg\nbh\nbi\nbk\nbj\ncb\nca\ncd\nce\ncf\ncg\nch\nci\nck\ncj\ndb\ndc\nda\nde\ndf\ndg\ndh\ndi\ndk\ndj\nef\nek", "output": "NO" }, { "input": "ab\n3\nab\nxx\nyy", "output": "YES" }, { "input": "ab\n2\nab\ncc", "output": "YES" }, { "input": "sa\n2\nxx\nas", "output": "YES" }, { "input": "ma\n1\nma", "output": "YES" }, { "input": "ba\n1\nbb", "output": "NO" }, { "input": "bc\n1\nab", "output": "NO" }, { "input": "fa\n1\nfa", "output": "YES" }, { "input": "ap\n1\nap", "output": "YES" }, { "input": "ab\n1\nbb", "output": "NO" }, { "input": "bk\n1\nbk", "output": "YES" }, { "input": "xy\n2\nxy\naa", "output": "YES" }, { "input": "ab\n2\nza\nbz", "output": "YES" } ]
62
0
-1
214
897
Chtholly's request
[ "brute force" ]
null
null
β€” I experienced so many great things. β€” You gave me memories like dreams... But I have to leave now... β€” One last request, can you... β€” Help me solve a Codeforces problem? β€” ...... β€” What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not. Given integers *k* and *p*, calculate the sum of the *k* smallest zcy numbers and output this sum modulo *p*. Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!
The first line contains two integers *k* and *p* (1<=≀<=*k*<=≀<=105,<=1<=≀<=*p*<=≀<=109).
Output single integerΒ β€” answer to the problem.
[ "2 100\n", "5 30\n" ]
[ "33\n", "15\n" ]
In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
[ { "input": "2 100", "output": "33" }, { "input": "5 30", "output": "15" }, { "input": "42147 412393322", "output": "251637727" }, { "input": "77809 868097296", "output": "440411873" }, { "input": "5105 443422097", "output": "363192634" }, { "input": "75615 376679484", "output": "373089399" }, { "input": "22951 23793302", "output": "1898631" }, { "input": "12785 993582106", "output": "286204743" }, { "input": "60276 428978808", "output": "376477293" }, { "input": "84776 104860385", "output": "10209596" }, { "input": "41984 653766991", "output": "17823101" }, { "input": "100000 1000000000", "output": "495495496" }, { "input": "41163 472310076", "output": "207304047" }, { "input": "6983 765352180", "output": "586866999" }, { "input": "33493 967727004", "output": "305705165" }, { "input": "90898 94010922", "output": "65928728" }, { "input": "67298 349286579", "output": "156435206" }, { "input": "92452 296773064", "output": "229486976" }, { "input": "58832 563860457", "output": "16775206" }, { "input": "90234 156145441", "output": "44023160" }, { "input": "91454 977186148", "output": "681779748" }, { "input": "11108 444095250", "output": "188075844" }, { "input": "46304 584475527", "output": "275627129" }, { "input": "1 1", "output": "0" }, { "input": "1 1000000000", "output": "11" }, { "input": "100000 1", "output": "0" } ]
93
2,150,400
3
216
46
Ball Game
[ "brute force", "implementation" ]
A. Ball Game
2
256
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends. The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.
The first line contains integer *n* (2<=≀<=*n*<=≀<=100) which indicates the number of kids in the circle.
In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.
[ "10\n", "3\n" ]
[ "2 4 7 1 6 2 9 7 6\n", "2 1\n" ]
none
[ { "input": "10", "output": "2 4 7 1 6 2 9 7 6" }, { "input": "3", "output": "2 1" }, { "input": "4", "output": "2 4 3" }, { "input": "5", "output": "2 4 2 1" }, { "input": "6", "output": "2 4 1 5 4" }, { "input": "7", "output": "2 4 7 4 2 1" }, { "input": "8", "output": "2 4 7 3 8 6 5" }, { "input": "9", "output": "2 4 7 2 7 4 2 1" }, { "input": "2", "output": "2" }, { "input": "11", "output": "2 4 7 11 5 11 7 4 2 1" }, { "input": "12", "output": "2 4 7 11 4 10 5 1 10 8 7" }, { "input": "13", "output": "2 4 7 11 3 9 3 11 7 4 2 1" }, { "input": "20", "output": "2 4 7 11 16 2 9 17 6 16 7 19 12 6 1 17 14 12 11" }, { "input": "25", "output": "2 4 7 11 16 22 4 12 21 6 17 4 17 6 21 12 4 22 16 11 7 4 2 1" }, { "input": "30", "output": "2 4 7 11 16 22 29 7 16 26 7 19 2 16 1 17 4 22 11 1 22 14 7 1 26 22 19 17 16" }, { "input": "35", "output": "2 4 7 11 16 22 29 2 11 21 32 9 22 1 16 32 14 32 16 1 22 9 32 21 11 2 29 22 16 11 7 4 2 1" }, { "input": "40", "output": "2 4 7 11 16 22 29 37 6 16 27 39 12 26 1 17 34 12 31 11 32 14 37 21 6 32 19 7 36 26 17 9 2 36 31 27 24 22 21" }, { "input": "45", "output": "2 4 7 11 16 22 29 37 1 11 22 34 2 16 31 2 19 37 11 31 7 29 7 31 11 37 19 2 31 16 2 34 22 11 1 37 29 22 16 11 7 4 2 1" }, { "input": "50", "output": "2 4 7 11 16 22 29 37 46 6 17 29 42 6 21 37 4 22 41 11 32 4 27 1 26 2 29 7 36 16 47 29 12 46 31 17 4 42 31 21 12 4 47 41 36 32 29 27 26" }, { "input": "55", "output": "2 4 7 11 16 22 29 37 46 1 12 24 37 51 11 27 44 7 26 46 12 34 2 26 51 22 49 22 51 26 2 34 12 46 26 7 44 27 11 51 37 24 12 1 46 37 29 22 16 11 7 4 2 1" }, { "input": "60", "output": "2 4 7 11 16 22 29 37 46 56 7 19 32 46 1 17 34 52 11 31 52 14 37 1 26 52 19 47 16 46 17 49 22 56 31 7 44 22 1 41 22 4 47 31 16 2 49 37 26 16 7 59 52 46 41 37 34 32 31" }, { "input": "65", "output": "2 4 7 11 16 22 29 37 46 56 2 14 27 41 56 7 24 42 61 16 37 59 17 41 1 27 54 17 46 11 42 9 42 11 46 17 54 27 1 41 17 59 37 16 61 42 24 7 56 41 27 14 2 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "70", "output": "2 4 7 11 16 22 29 37 46 56 67 9 22 36 51 67 14 32 51 1 22 44 67 21 46 2 29 57 16 46 7 39 2 36 1 37 4 42 11 51 22 64 37 11 56 32 9 57 36 16 67 49 32 16 1 57 44 32 21 11 2 64 57 51 46 42 39 37 36" }, { "input": "75", "output": "2 4 7 11 16 22 29 37 46 56 67 4 17 31 46 62 4 22 41 61 7 29 52 1 26 52 4 32 61 16 47 4 37 71 31 67 29 67 31 71 37 4 47 16 61 32 4 52 26 1 52 29 7 61 41 22 4 62 46 31 17 4 67 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "80", "output": "2 4 7 11 16 22 29 37 46 56 67 79 12 26 41 57 74 12 31 51 72 14 37 61 6 32 59 7 36 66 17 49 2 36 71 27 64 22 61 21 62 24 67 31 76 42 9 57 26 76 47 19 72 46 21 77 54 32 11 71 52 34 17 1 66 52 39 27 16 6 77 69 62 56 51 47 44 42 41" }, { "input": "85", "output": "2 4 7 11 16 22 29 37 46 56 67 79 7 21 36 52 69 2 21 41 62 84 22 46 71 12 39 67 11 41 72 19 52 1 36 72 24 62 16 56 12 54 12 56 16 62 24 72 36 1 52 19 72 41 11 67 39 12 71 46 22 84 62 41 21 2 69 52 36 21 7 79 67 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "90", "output": "2 4 7 11 16 22 29 37 46 56 67 79 2 16 31 47 64 82 11 31 52 74 7 31 56 82 19 47 76 16 47 79 22 56 1 37 74 22 61 11 52 4 47 1 46 2 49 7 56 16 67 29 82 46 11 67 34 2 61 31 2 64 37 11 76 52 29 7 76 56 37 19 2 76 61 47 34 22 11 1 82 74 67 61 56 52 49 47 46" }, { "input": "95", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 11 26 42 59 77 1 21 42 64 87 16 41 67 94 27 56 86 22 54 87 26 61 2 39 77 21 61 7 49 92 41 86 37 84 37 86 41 92 49 7 61 21 77 39 2 61 26 87 54 22 86 56 27 94 67 41 16 87 64 42 21 1 77 59 42 26 11 92 79 67 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "96", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 10 25 41 58 76 95 19 40 62 85 13 38 64 91 23 52 82 17 49 82 20 55 91 32 70 13 53 94 40 83 31 76 26 73 25 74 28 79 35 88 46 5 61 22 80 43 7 68 34 1 65 34 4 71 43 16 86 61 37 14 88 67 47 28 10 89 73 58 44 31 19 8 94 85 77 70 64 59 55 52 50 49" }, { "input": "97", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 9 24 40 57 75 94 17 38 60 83 10 35 61 88 19 48 78 12 44 77 14 49 85 25 63 5 45 86 31 74 21 66 15 62 13 62 15 66 21 74 31 86 45 5 63 25 85 49 14 77 44 12 78 48 19 88 61 35 10 83 60 38 17 94 75 57 40 24 9 92 79 67 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "98", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 8 23 39 56 74 93 15 36 58 81 7 32 58 85 15 44 74 7 39 72 8 43 79 18 56 95 37 78 22 65 11 56 4 51 1 50 2 53 7 60 16 71 29 86 46 7 67 30 92 57 23 88 56 25 93 64 36 9 81 56 32 9 85 64 44 25 7 88 72 57 43 30 18 7 95 86 78 71 65 60 56 53 51 50" }, { "input": "99", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 7 22 38 55 73 92 13 34 56 79 4 29 55 82 11 40 70 2 34 67 2 37 73 11 49 88 29 70 13 56 1 46 92 40 88 38 88 40 92 46 1 56 13 70 29 88 49 11 73 37 2 67 34 2 70 40 11 82 55 29 4 79 56 34 13 92 73 55 38 22 7 92 79 67 56 46 37 29 22 16 11 7 4 2 1" }, { "input": "100", "output": "2 4 7 11 16 22 29 37 46 56 67 79 92 6 21 37 54 72 91 11 32 54 77 1 26 52 79 7 36 66 97 29 62 96 31 67 4 42 81 21 62 4 47 91 36 82 29 77 26 76 27 79 32 86 41 97 54 12 71 31 92 54 17 81 46 12 79 47 16 86 57 29 2 76 51 27 4 82 61 41 22 4 87 71 56 42 29 17 6 96 87 79 72 66 61 57 54 52 51" } ]
92
0
3.977
217
979
Pizza, Pizza, Pizza!!!
[ "math" ]
null
null
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro. She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over. Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator. As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$)Β β€” the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
A single integerΒ β€” the number of straight cuts Shiro needs.
[ "3\n", "4\n" ]
[ "2", "5" ]
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them. To cut the round pizza into five equal parts one has to make five cuts.
[ { "input": "3", "output": "2" }, { "input": "4", "output": "5" }, { "input": "10", "output": "11" }, { "input": "10000000000", "output": "10000000001" }, { "input": "1234567891", "output": "617283946" }, { "input": "7509213957", "output": "3754606979" }, { "input": "99999999999999999", "output": "50000000000000000" }, { "input": "21", "output": "11" }, { "input": "712394453192", "output": "712394453193" }, { "input": "172212168", "output": "172212169" }, { "input": "822981260158260519", "output": "411490630079130260" }, { "input": "28316250877914571", "output": "14158125438957286" }, { "input": "779547116602436424", "output": "779547116602436425" }, { "input": "578223540024979436", "output": "578223540024979437" }, { "input": "335408917861648766", "output": "335408917861648767" }, { "input": "74859962623690078", "output": "74859962623690079" }, { "input": "252509054433933439", "output": "126254527216966720" }, { "input": "760713016476190622", "output": "760713016476190623" }, { "input": "919845426262703496", "output": "919845426262703497" }, { "input": "585335723211047194", "output": "585335723211047195" }, { "input": "522842184971407769", "output": "261421092485703885" }, { "input": "148049062628894320", "output": "148049062628894321" }, { "input": "84324828731963974", "output": "84324828731963975" }, { "input": "354979173822804781", "output": "177489586911402391" }, { "input": "1312150450968413", "output": "656075225484207" }, { "input": "269587449430302150", "output": "269587449430302151" }, { "input": "645762258982631926", "output": "645762258982631927" }, { "input": "615812229161735895", "output": "307906114580867948" }, { "input": "0", "output": "0" }, { "input": "349993004923078531", "output": "174996502461539266" }, { "input": "891351282707723851", "output": "445675641353861926" }, { "input": "563324731189330734", "output": "563324731189330735" }, { "input": "520974001910286909", "output": "260487000955143455" }, { "input": "666729339802329204", "output": "666729339802329205" }, { "input": "856674611404539671", "output": "428337305702269836" }, { "input": "791809296303238499", "output": "395904648151619250" }, { "input": "711066337317063338", "output": "711066337317063339" }, { "input": "931356503492686566", "output": "931356503492686567" }, { "input": "234122432773361866", "output": "234122432773361867" }, { "input": "1000000000000000000", "output": "1000000000000000001" }, { "input": "1", "output": "1" }, { "input": "2", "output": "3" }, { "input": "7", "output": "4" }, { "input": "63", "output": "32" }, { "input": "24", "output": "25" }, { "input": "8", "output": "9" }, { "input": "15", "output": "8" } ]
15
0
0
218
1
Ancient Berland Circus
[ "geometry", "math" ]
C. Ancient Berland Circus
2
64
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different. In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges. Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time. You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have.
The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point.
Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100.
[ "0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000\n" ]
[ "1.00000000\n" ]
[ { "input": "0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000", "output": "1.00000000" }, { "input": "71.756151 7.532275\n-48.634784 100.159986\n91.778633 158.107739", "output": "9991.27897663" }, { "input": "18.716839 40.852752\n66.147248 -4.083161\n111.083161 43.347248", "output": "4268.87997505" }, { "input": "-13.242302 -45.014124\n-33.825369 51.083964\n84.512928 -55.134407", "output": "16617.24002771" }, { "input": "115.715093 141.583620\n136.158119 -23.780834\n173.673212 64.802787", "output": "24043.74046813" }, { "input": "17.288379 68.223317\n48.776683 71.688379\n23.170559 106.572762", "output": "1505.27997374" }, { "input": "76.820252 66.709341\n61.392328 82.684207\n44.267775 -2.378694", "output": "6503.44762335" }, { "input": "-46.482632 -31.161247\n19.689679 -70.646972\n-17.902656 -58.455808", "output": "23949.55226823" }, { "input": "34.236058 108.163949\n28.639345 104.566515\n25.610069 86.002927", "output": "780.93431702" }, { "input": "25.428124 39.407248\n17.868098 39.785933\n11.028461 43.028890", "output": "1152.21351717" }, { "input": "36.856072 121.845502\n46.453956 109.898647\n-30.047767 77.590282", "output": "5339.35578947" }, { "input": "-18.643272 56.008305\n9.107608 -22.094058\n-6.456146 70.308320", "output": "9009.25177521" }, { "input": "88.653021 18.024220\n51.942488 -2.527850\n76.164701 24.553012", "output": "1452.52866331" }, { "input": "80.181999 -38.076894\n23.381778 122.535736\n47.118815 140.734014", "output": "28242.17663744" }, { "input": "1.514204 81.400629\n32.168797 100.161401\n7.778734 46.010993", "output": "3149.43107333" }, { "input": "84.409605 38.496141\n77.788313 39.553807\n75.248391 59.413884", "output": "438.85760782" }, { "input": "12.272903 101.825792\n-51.240438 -12.708472\n-29.729299 77.882032", "output": "24908.67540438" }, { "input": "35.661751 27.283571\n96.513550 51.518022\n97.605986 131.258287", "output": "13324.78113326" }, { "input": "-20.003518 -4.671086\n93.588632 6.362759\n-24.748109 24.792124", "output": "11191.04493104" }, { "input": "93.583067 132.858352\n63.834975 19.353720\n33.677824 102.529376", "output": "10866.49390021" }, { "input": "-7.347450 36.971423\n84.498728 89.423536\n75.469963 98.022482", "output": "8977.83404724" }, { "input": "51.679280 56.072393\n-35.819256 73.390532\n-10.661374 129.756454", "output": "7441.86549199" }, { "input": "97.326813 61.492460\n100.982131 57.717635\n68.385216 22.538372", "output": "1840.59945324" }, { "input": "-16.356805 109.310423\n124.529388 25.066276\n-37.892043 80.604904", "output": "22719.36404168" }, { "input": "103.967164 63.475916\n86.466163 59.341930\n69.260229 73.258917", "output": "1621.96700296" }, { "input": "122.381894 -48.763263\n163.634346 -22.427845\n26.099674 73.681862", "output": "22182.51901824" }, { "input": "119.209229 133.905087\n132.001535 22.179509\n96.096673 0.539763", "output": "16459.52899209" }, { "input": "77.145533 85.041789\n67.452820 52.513188\n80.503843 85.000149", "output": "1034.70898496" }, { "input": "28.718442 36.116251\n36.734593 35.617015\n76.193973 99.136077", "output": "6271.48941610" }, { "input": "0.376916 17.054676\n100.187614 85.602831\n1.425829 132.750915", "output": "13947.47744984" }, { "input": "46.172435 -22.819705\n17.485134 -1.663888\n101.027565 111.619705", "output": "16483.23337238" }, { "input": "55.957968 -72.765994\n39.787413 -75.942282\n24.837014 128.144762", "output": "32799.66697178" }, { "input": "40.562163 -47.610606\n10.073051 -54.490068\n54.625875 -40.685797", "output": "31224.34817875" }, { "input": "20.965151 74.716562\n167.264364 81.864800\n5.931644 48.813212", "output": "30115.26346791" }, { "input": "105.530943 80.920069\n40.206723 125.323331\n40.502256 -85.455877", "output": "36574.64621711" }, { "input": "104.636703 49.583778\n85.940583 95.426299\n69.375168 93.234795", "output": "2632.68754075" }, { "input": "72.873708 -59.083734\n110.911118 -6.206576\n-44.292395 13.106202", "output": "19244.42781859" }, { "input": "49.320630 48.119616\n65.888396 93.514980\n27.342377 97.600590", "output": "2437.50897386" }, { "input": "6.949504 69.606390\n26.139268 72.136945\n24.032442 57.407195", "output": "372.09309018" }, { "input": "-21.925928 -24.623076\n-33.673619 -11.677794\n4.692348 52.266292", "output": "5669.99444283" }, { "input": "109.515505 37.575315\n5.377080 101.729711\n17.501630 103.324931", "output": "25142.85604936" }, { "input": "-56.880888 172.997993\n81.126977 42.144034\n-51.413417 17.057807", "output": "29051.57171313" }, { "input": "80.895061 94.491414\n42.361631 65.191687\n77.556800 76.694829", "output": "2386.01792476" }, { "input": "165.094169 94.574129\n46.867578 147.178855\n174.685774 62.705213", "output": "32087.47120554" }, { "input": "146.604506 -3.502359\n24.935572 44.589981\n106.160918 -51.162271", "output": "13799.61044048" }, { "input": "139.847022 19.153937\n104.096879 75.379874\n49.164271 46.404632", "output": "7083.26303902" }, { "input": "31.312532 151.532355\n182.646053 56.534075\n15.953947 127.065925", "output": "25712.80766033" }, { "input": "42.147045 64.165917\n70.260284 4.962470\n10.532991 76.277713", "output": "14261.92257159" }, { "input": "129.400249 -44.695226\n122.278798 -53.696996\n44.828427 -83.507917", "output": "26227.47891833" }, { "input": "28.420253 0.619862\n10.966628 21.724132\n14.618862 10.754642", "output": "1760.14006648" } ]
122
0
0
219
498
Crazy Town
[ "geometry" ]
null
null
Crazy Town is a plane on which there are *n* infinite line roads. Each road is defined by the equation *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, where *a**i* and *b**i* are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect. Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step). Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
The first line contains two space-separated integers *x*1, *y*1 (<=-<=106<=≀<=*x*1,<=*y*1<=≀<=106) β€” the coordinates of your home. The second line contains two integers separated by a space *x*2, *y*2 (<=-<=106<=≀<=*x*2,<=*y*2<=≀<=106) β€” the coordinates of the university you are studying at. The third line contains an integer *n* (1<=≀<=*n*<=≀<=300) β€” the number of roads in the city. The following *n* lines contain 3 space-separated integers (<=-<=106<=≀<=*a**i*,<=*b**i*,<=*c**i*<=≀<=106; |*a**i*|<=+<=|*b**i*|<=&gt;<=0) β€” the coefficients of the line *a**i**x*<=+<=*b**i**y*<=+<=*c**i*<==<=0, defining the *i*-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output the answer to the problem.
[ "1 1\n-1 -1\n2\n0 1 0\n1 0 0\n", "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3\n" ]
[ "2\n", "2\n" ]
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
[ { "input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0", "output": "2" }, { "input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "output": "2" }, { "input": "841746 527518\n595261 331297\n10\n-946901 129987 670374\n-140388 -684770 309555\n-302589 415564 -387435\n-565799 -72069 -395358\n-523453 -511446 854898\n-846967 -749453 -341866\n-622388 434663 264157\n-638453 625357 344195\n-255265 -676356 -772398\n-824723 -319141 33585", "output": "0" }, { "input": "454379 373644\n-665078 -385892\n2\n-530 -468 -379786\n-173 -275 -100376", "output": "2" }, { "input": "841746 527518\n595261 331297\n10\n936 -209 -790797\n898 1240 -36994\n759 285 -413562\n174 323 34281\n662 400 -284846\n298 520 42086\n-36 -27 12861\n462 631 -22515\n-499 1105 919372\n582 1490 319884", "output": "0" }, { "input": "-537 648838\n227 -51454\n1\n678 0 235266", "output": "1" }, { "input": "-940 -984641\n403 -942522\n2\n530 0 -63600\n-439 0 95263", "output": "2" }, { "input": "-867 -465880\n793 -581568\n5\n73 0 57743\n-818 0 -635586\n-804 0 -415668\n-383 0 -52854\n1258 0 155992", "output": "5" }, { "input": "-632 -387435\n942 798117\n10\n249 0 135705\n536 0 271752\n750 0 375750\n799 0 -206142\n1102 0 -437494\n-453 0 197055\n-581 0 260288\n-322 0 161322\n1317 0 -878439\n-811 0 594463", "output": "10" }, { "input": "527189 -306471\n-998939 648838\n1\n-950717 -549267 -820616", "output": "1" }, { "input": "454379 373644\n-665078 -385892\n2\n-984641 503905 -909460\n-767954 -468772 -942522", "output": "2" }, { "input": "-589794 344286\n532652 -230711\n5\n-2919 -179425 -546698\n-465880 342737 794428\n-230739 -687865 713836\n-932054 513357 -97639\n-559361 -75096 -581568", "output": "5" }, { "input": "0 1\n2 2\n1\n1 1 2", "output": "0" }, { "input": "0 2\n-2 0\n2\n2 3 -1\n4 0 3", "output": "2" }, { "input": "1 -4\n1 5\n1\n0 1 0", "output": "1" }, { "input": "1 0\n2 0\n1\n1 0 0", "output": "0" }, { "input": "0 0\n0 2\n4\n1 0 1\n1 0 -1\n-2 0 1\n0 1 -1", "output": "1" }, { "input": "100000 100000\n-100000 100000\n1\n10000 0 7", "output": "1" }, { "input": "1 1\n-1 -1\n1\n1 1 0", "output": "1" }, { "input": "1 1\n3 3\n1\n1 0 2", "output": "0" }, { "input": "1 3\n1 1\n1\n1 1 3", "output": "0" }, { "input": "5 0\n15 0\n1\n10 0 -100", "output": "1" }, { "input": "3 4\n2 6\n1\n0 -2 5", "output": "0" }, { "input": "1 0\n1 2\n1\n0 1 -1", "output": "1" }, { "input": "0 0\n0 2\n1\n0 1 -1", "output": "1" }, { "input": "0 0\n0 1\n1\n1 0 10000", "output": "0" }, { "input": "0 0\n0 1\n1\n0 2 2", "output": "0" }, { "input": "10 18\n10 0\n2\n1 -1 0\n0 1 -5", "output": "2" }, { "input": "10 10\n8 8\n1\n1 1 19", "output": "0" }, { "input": "0 1\n1000000 1\n1\n1000000 1 0", "output": "0" } ]
109
0
3
220
672
Summer Camp
[ "implementation" ]
null
null
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1.
The only line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=1000)Β β€” the position of the digit you need to print.
Print the *n*-th digit of the line.
[ "3\n", "11\n" ]
[ "3\n", "0\n" ]
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit. In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
[ { "input": "3", "output": "3" }, { "input": "11", "output": "0" }, { "input": "12", "output": "1" }, { "input": "13", "output": "1" }, { "input": "29", "output": "9" }, { "input": "30", "output": "2" }, { "input": "1000", "output": "3" }, { "input": "999", "output": "9" }, { "input": "100", "output": "5" }, { "input": "123", "output": "6" }, { "input": "8", "output": "8" }, { "input": "157", "output": "3" }, { "input": "289", "output": "1" }, { "input": "179", "output": "4" }, { "input": "942", "output": "0" }, { "input": "879", "output": "9" }, { "input": "394", "output": "1" }, { "input": "423", "output": "7" }, { "input": "952", "output": "3" }, { "input": "121", "output": "5" }, { "input": "613", "output": "2" }, { "input": "945", "output": "1" }, { "input": "270", "output": "6" }, { "input": "781", "output": "2" }, { "input": "453", "output": "7" }, { "input": "171", "output": "0" }, { "input": "643", "output": "2" }, { "input": "570", "output": "6" }, { "input": "750", "output": "6" }, { "input": "500", "output": "0" }, { "input": "2", "output": "2" }, { "input": "1", "output": "1" }, { "input": "108", "output": "5" }, { "input": "500", "output": "0" }, { "input": "189", "output": "9" }, { "input": "491", "output": "0" }, { "input": "191", "output": "0" } ]
140
0
3
221
417
Elimination
[ "dp", "implementation", "math" ]
null
null
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds. The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of *c* problems, the winners of the round are the first *n* people in the rating list. Each of the additional elimination rounds consists of *d* problems. The winner of the additional round is one person. Besides, *k* winners of the past finals are invited to the finals without elimination. As a result of all elimination rounds at least *n*Β·*m* people should go to the finals. You need to organize elimination rounds in such a way, that at least *n*Β·*m* people go to the finals, and the total amount of used problems in all rounds is as small as possible.
The first line contains two integers *c* and *d* (1<=≀<=*c*,<=*d*<=≀<=100)Β β€” the number of problems in the main and additional rounds, correspondingly. The second line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100). Finally, the third line contains an integer *k* (1<=≀<=*k*<=≀<=100)Β β€” the number of the pre-chosen winners.
In the first line, print a single integer β€” the minimum number of problems the jury needs to prepare.
[ "1 10\n7 2\n1\n", "2 2\n2 1\n2\n" ]
[ "2\n", "0\n" ]
none
[ { "input": "1 10\n7 2\n1", "output": "2" }, { "input": "2 2\n2 1\n2", "output": "0" }, { "input": "8 9\n2 2\n3", "output": "8" }, { "input": "5 5\n8 8\n7", "output": "40" }, { "input": "1 8\n8 10\n8", "output": "9" }, { "input": "5 7\n9 1\n8", "output": "5" }, { "input": "35 28\n35 60\n44", "output": "2065" }, { "input": "19 76\n91 91\n87", "output": "1729" }, { "input": "20 38\n38 70\n58", "output": "1380" }, { "input": "2 81\n3 39\n45", "output": "48" }, { "input": "7 63\n18 69\n30", "output": "476" }, { "input": "89 69\n57 38\n15", "output": "3382" }, { "input": "3 30\n10 83\n57", "output": "234" }, { "input": "100 3\n93 23\n98", "output": "2200" }, { "input": "2 78\n21 24\n88", "output": "40" }, { "input": "40 80\n4 31\n63", "output": "640" }, { "input": "1 48\n89 76\n24", "output": "76" }, { "input": "5 25\n13 76\n86", "output": "350" }, { "input": "23 86\n83 88\n62", "output": "2024" }, { "input": "1 93\n76 40\n39", "output": "40" }, { "input": "53 93\n10 70\n9", "output": "3710" }, { "input": "100 100\n100 100\n100", "output": "9900" }, { "input": "10 100\n100 100\n99", "output": "1000" }, { "input": "1 100\n99 100\n1", "output": "100" }, { "input": "10 2\n7 2\n3", "output": "18" }, { "input": "4 1\n5 3\n8", "output": "6" }, { "input": "2 2\n2 1\n20", "output": "0" }, { "input": "7 5\n1 1\n10", "output": "0" }, { "input": "4 5\n9 10\n100", "output": "0" }, { "input": "10 1\n1 2\n1", "output": "1" }, { "input": "16 6\n3 12\n7", "output": "156" }, { "input": "10 1\n1 100\n1", "output": "99" }, { "input": "2 1\n3 4\n2", "output": "7" }, { "input": "2 1\n1 1\n10", "output": "0" }, { "input": "100 1\n2 3\n1", "output": "5" }, { "input": "10 2\n1 11\n1", "output": "20" }, { "input": "10 10\n1 1\n100", "output": "0" }, { "input": "100 1\n50 100\n1", "output": "4999" }, { "input": "10 1\n2 2\n3", "output": "1" }, { "input": "3 1\n9 10\n80", "output": "4" }, { "input": "100 1\n1 100\n1", "output": "99" }, { "input": "10 9\n10 10\n9", "output": "99" }, { "input": "1 1\n1 1\n99", "output": "0" }, { "input": "10 9\n1 1\n100", "output": "0" }, { "input": "4 1\n5 1\n10", "output": "0" }, { "input": "5 1\n6 3\n5", "output": "11" }, { "input": "10 1\n1 1\n10", "output": "0" }, { "input": "1 1\n1 1\n10", "output": "0" } ]
109
0
0
222
137
History
[ "sortings" ]
null
null
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history. Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=&lt;<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=&lt;<=*a**i* and *b**i*<=&lt;<=*b**j*. Your task is simpler: find the number of events that are included in some other event.
The first input line contains integer *n* (1<=≀<=*n*<=≀<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≀<=*a**i*<=&lt;<=*b**i*<=≀<=109) β€” the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=β‰ <=*a**j*,<=*a**i*<=β‰ <=*b**j*,<=*b**i*<=β‰ <=*a**j*,<=*b**i*<=β‰ <=*b**j* for all *i*, *j* (where *i*<=β‰ <=*j*). Events are given in arbitrary order.
Print the only integer β€” the answer to the problem.
[ "5\n1 10\n2 9\n3 8\n4 7\n5 6\n", "5\n1 100\n2 50\n51 99\n52 98\n10 60\n", "1\n1 1000000000\n" ]
[ "4\n", "4\n", "0\n" ]
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third β€” in the second and the second β€” in the first. In the second example all events except the first one are contained in the first. In the third example only one event, so the answer is 0.
[ { "input": "5\n1 10\n2 9\n3 8\n4 7\n5 6", "output": "4" }, { "input": "5\n1 100\n2 50\n51 99\n52 98\n10 60", "output": "4" }, { "input": "1\n1 1000000000", "output": "0" }, { "input": "2\n100 1000\n500 1500", "output": "0" }, { "input": "4\n1 100\n50 150\n120 200\n180 220", "output": "0" }, { "input": "10\n1 20\n2 19\n3 18\n4 17\n5 16\n6 15\n7 14\n8 13\n9 12\n10 11", "output": "9" }, { "input": "4\n1 5\n2 4\n10 15\n11 14", "output": "2" }, { "input": "10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20", "output": "0" }, { "input": "10\n58 22116\n112840 772160\n127432 399484\n182031 255417\n459340 548097\n603984 739189\n606173 663033\n280170 366159\n779239 906234\n874623 892907", "output": "7" }, { "input": "2\n2 3\n1 4", "output": "1" }, { "input": "3\n9 10\n1 2\n3 4", "output": "0" }, { "input": "4\n1 2\n3 6\n4 5\n10 11", "output": "1" }, { "input": "2\n5 6\n1 10", "output": "1" }, { "input": "7\n1 10\n2 5\n3 9\n100 1000\n200 500\n1001 1002\n777 7777", "output": "4" } ]
186
307,200
0
223
369
Valera and Plates
[ "greedy", "implementation" ]
null
null
Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates. When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally.
The first line of the input contains three integers *n*, *m*, *k* (1<=≀<=*n*,<=*m*,<=*k*<=≀<=1000)Β β€” the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=2). If *a**i* equals one, then on day *i* Valera will eat a first type dish. If *a**i* equals two, then on day *i* Valera will eat a second type dish.
Print a single integer β€” the minimum number of times Valera will need to wash a plate/bowl.
[ "3 1 1\n1 2 1\n", "4 3 1\n1 1 1 1\n", "3 1 2\n2 2 2\n", "8 2 2\n1 2 1 2 1 2 1 2\n" ]
[ "1\n", "1\n", "0\n", "4\n" ]
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all three days, and as they can be eaten from either a plate or a bowl, he will never need to wash a plate/bowl.
[ { "input": "3 1 1\n1 2 1", "output": "1" }, { "input": "4 3 1\n1 1 1 1", "output": "1" }, { "input": "3 1 2\n2 2 2", "output": "0" }, { "input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4" }, { "input": "2 100 100\n2 2", "output": "0" }, { "input": "1 1 1\n2", "output": "0" }, { "input": "233 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 1 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2", "output": "132" }, { "input": "123 100 1\n2 2 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 2 1 2 2 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 1 2 1 2 1 2 1 1 1", "output": "22" }, { "input": "188 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1", "output": "87" }, { "input": "3 1 2\n1 1 1", "output": "2" }, { "input": "3 2 2\n1 1 1", "output": "1" }, { "input": "3 2 1\n1 1 1", "output": "1" }, { "input": "3 1 1\n1 1 1", "output": "2" }, { "input": "5 1 2\n2 2 2 2 2", "output": "2" }, { "input": "5 2 2\n2 2 2 2 2", "output": "1" }, { "input": "5 2 1\n2 2 2 2 2", "output": "2" }, { "input": "5 1 1\n2 2 2 2 2", "output": "3" }, { "input": "1 1 2\n2", "output": "0" }, { "input": "1 2 2\n2", "output": "0" }, { "input": "1 2 1\n2", "output": "0" }, { "input": "1 1 1\n2", "output": "0" }, { "input": "6 3 1\n1 1 2 2 2 2", "output": "2" }, { "input": "100 40 20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "40" }, { "input": "7 5 2\n2 2 1 1 1 1 1", "output": "0" }, { "input": "10 4 4\n2 2 2 2 2 2 1 1 1 1", "output": "2" }, { "input": "3 2 1\n2 1 1", "output": "0" }, { "input": "7 6 1\n2 1 1 1 1 1 1", "output": "0" }, { "input": "7 5 1\n1 1 1 2 2 2 2", "output": "1" }, { "input": "5 3 1\n1 1 2 2 2", "output": "1" }, { "input": "3 1 1\n2 2 2", "output": "1" }, { "input": "5 2 2\n2 2 2 2 2", "output": "1" }, { "input": "3 1 3\n1 1 1", "output": "2" }, { "input": "5 2 1\n1 1 2 2 2", "output": "2" }, { "input": "4 3 2\n2 1 1 1", "output": "0" }, { "input": "4 2 1\n1 2 2 2", "output": "1" }, { "input": "14 4 7\n1 1 1 2 2 2 2 2 2 2 2 2 2 2", "output": "3" }, { "input": "12 10 4\n2 2 2 2 2 2 1 1 1 1 1 1", "output": "0" }, { "input": "5 3 2\n2 2 1 1 1", "output": "0" } ]
108
20,172,800
3
224
912
Tricky Alchemy
[ "implementation" ]
null
null
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, greenΒ β€” one yellow and one blue, and for a blue ball, three blue crystals are enough. Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.
The first line features two integers *A* and *B* (0<=≀<=*A*,<=*B*<=≀<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers *x*, *y* and *z* (0<=≀<=*x*,<=*y*,<=*z*<=≀<=109)Β β€” the respective amounts of yellow, green and blue balls to be obtained.
Print a single integerΒ β€” the minimum number of crystals that Grisha should acquire in addition.
[ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n" ]
[ "2\n", "1\n", "2147483648\n" ]
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
[ { "input": "4 3\n2 1 1", "output": "2" }, { "input": "3 9\n1 1 3", "output": "1" }, { "input": "12345678 87654321\n43043751 1000000000 53798715", "output": "2147483648" }, { "input": "12 12\n3 5 2", "output": "0" }, { "input": "770 1390\n170 442 311", "output": "12" }, { "input": "3555165 6693472\n1499112 556941 3075290", "output": "3089339" }, { "input": "0 0\n1000000000 1000000000 1000000000", "output": "7000000000" }, { "input": "1 1\n0 1 0", "output": "0" }, { "input": "117708228 562858833\n118004008 360437130 154015822", "output": "738362681" }, { "input": "999998118 700178721\n822106746 82987112 547955384", "output": "1753877029" }, { "input": "566568710 765371101\n60614022 80126928 809950465", "output": "1744607222" }, { "input": "448858599 829062060\n764716760 97644201 203890025", "output": "1178219122" }, { "input": "626115781 966381948\n395190569 820194184 229233367", "output": "1525971878" }, { "input": "803372962 103701834\n394260597 837711458 623172928", "output": "3426388098" }, { "input": "980630143 241021722\n24734406 928857659 312079781", "output": "1624075280" }, { "input": "862920032 378341609\n360240924 241342224 337423122", "output": "974174021" }, { "input": "40177212 515661496\n64343660 963892207 731362684", "output": "3694721078" }, { "input": "217434393 579352456\n694817470 981409480 756706026", "output": "4825785129" }, { "input": "394691574 716672343\n398920207 72555681 150645586", "output": "475704521" }, { "input": "276981463 853992230\n29394015 90072954 839552440", "output": "1754738044" }, { "input": "843552056 919184611\n341530221 423649259 101547519", "output": "263157645" }, { "input": "20809236 56504497\n972004030 441166533 495487081", "output": "4235488636" }, { "input": "198066417 825228166\n602477839 532312735 520830423", "output": "2808777834" }, { "input": "80356306 962548053\n601547868 549830008 914769984", "output": "4004161345" }, { "input": "257613487 394835231\n642087093 567347282 308709545", "output": "2692548667" }, { "input": "139903376 532155119\n641157122 289897263 629020178", "output": "3077110809" }, { "input": "612127849 669475006\n271630930 676010757 22959739", "output": "682559736" }, { "input": "0 0\n0 0 0", "output": "0" }, { "input": "1000000000 1000000000\n499999998 4 333333332", "output": "0" }, { "input": "1000000000 1000000000\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4 3\n1 0 1", "output": "0" }, { "input": "4 12\n1 2 3", "output": "0" }, { "input": "4 20\n1 2 1", "output": "0" }, { "input": "100 10\n2 3 4", "output": "5" }, { "input": "6 0\n1 1 1", "output": "4" }, { "input": "25 5\n3 3 3", "output": "7" }, { "input": "48 27\n22 39 20", "output": "107" }, { "input": "4 0\n1 1 1", "output": "4" } ]
61
6,656,000
0
225
721
One-dimensional Japanese Crossword
[ "implementation" ]
null
null
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=Γ—<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=Γ—<=*n*), which he wants to encrypt in the same way as in japanese crossword. Help Adaltik find the numbers encrypting the row he drew.
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W'Β β€” to white square in the row that Adaltik drew).
The first line should contain a single integer *k*Β β€” the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
[ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "4\nBBBB\n", "13\nWBBBBWWBWBBBW\n" ]
[ "1\n2 ", "3\n1 1 1 ", "0\n", "1\n4 ", "3\n4 1 3 " ]
The last sample case correspond to the picture in the statement.
[ { "input": "3\nBBW", "output": "1\n2 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "4\nWWWW", "output": "0" }, { "input": "4\nBBBB", "output": "1\n4 " }, { "input": "13\nWBBBBWWBWBBBW", "output": "3\n4 1 3 " }, { "input": "1\nB", "output": "1\n1 " }, { "input": "2\nBB", "output": "1\n2 " }, { "input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB", "output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "1\nW", "output": "0" }, { "input": "2\nWW", "output": "0" }, { "input": "2\nWB", "output": "1\n1 " }, { "input": "2\nBW", "output": "1\n1 " }, { "input": "3\nBBB", "output": "1\n3 " }, { "input": "3\nBWB", "output": "2\n1 1 " }, { "input": "3\nWBB", "output": "1\n2 " }, { "input": "3\nWWB", "output": "1\n1 " }, { "input": "3\nWBW", "output": "1\n1 " }, { "input": "3\nBWW", "output": "1\n1 " }, { "input": "3\nWWW", "output": "0" }, { "input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB", "output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 " }, { "input": "5\nBBBWB", "output": "2\n3 1 " }, { "input": "5\nBWWWB", "output": "2\n1 1 " }, { "input": "5\nWWWWB", "output": "1\n1 " }, { "input": "5\nBWWWW", "output": "1\n1 " }, { "input": "5\nBBBWW", "output": "1\n3 " }, { "input": "5\nWWBBB", "output": "1\n3 " }, { "input": "10\nBBBBBWWBBB", "output": "2\n5 3 " }, { "input": "10\nBBBBWBBWBB", "output": "3\n4 2 2 " }, { "input": "20\nBBBBBWWBWBBWBWWBWBBB", "output": "6\n5 1 2 1 1 3 " }, { "input": "20\nBBBWWWWBBWWWBWBWWBBB", "output": "5\n3 2 1 1 3 " }, { "input": "20\nBBBBBBBBWBBBWBWBWBBB", "output": "5\n8 3 1 1 3 " }, { "input": "20\nBBBWBWBWWWBBWWWWBWBB", "output": "6\n3 1 1 2 1 2 " }, { "input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB", "output": "5\n6 1 1 1 12 " }, { "input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB", "output": "9\n5 1 2 1 1 4 1 1 8 " }, { "input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB", "output": "7\n11 1 1 8 1 1 6 " }, { "input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", "output": "0" }, { "input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW", "output": "9\n5 1 1 1 1 2 2 1 1 " }, { "input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB", "output": "6\n1 1 1 1 1 5 " }, { "input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB", "output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB", "output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n100 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB", "output": "11\n20 1 1 1 2 1 1 1 1 1 20 " }, { "input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB", "output": "11\n4 1 1 1 1 2 1 1 1 1 6 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "10\nWWBWWWBWBB", "output": "3\n1 1 2 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n17 31 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n24 42 " }, { "input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB", "output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 " }, { "input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB", "output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 " }, { "input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB", "output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 " }, { "input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB", "output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 " }, { "input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB", "output": "11\n1 5 3 4 3 1 1 2 1 2 4 " } ]
62
0
3
227
977
Consecutive Subsequence
[ "dp" ]
null
null
You are given an integer array of length $n$. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $[x, x + 1, \dots, x + k - 1]$ for some value $x$ and length $k$. Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array $[5, 3, 1, 2, 4]$ the following arrays are subsequences: $[3]$, $[5, 3, 1, 2, 4]$, $[5, 1, 4]$, but the array $[1, 3]$ is not.
The first line of the input containing integer number $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the length of the array. The second line of the input containing $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β€” the array itself.
On the first line print $k$ β€” the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.
[ "7\n3 3 4 7 5 6 8\n", "6\n1 3 5 2 4 6\n", "4\n10 9 8 7\n", "9\n6 7 8 3 4 5 9 10 11\n" ]
[ "4\n2 3 5 6 \n", "2\n1 4 \n", "1\n1 \n", "6\n1 2 3 7 8 9 \n" ]
All valid answers for the first example (as sequences of indices): - $[1, 3, 5, 6]$ - $[2, 3, 5, 6]$ All valid answers for the second example: - $[1, 4]$ - $[2, 5]$ - $[3, 6]$ All valid answers for the third example: - $[1]$ - $[2]$ - $[3]$ - $[4]$ All valid answers for the fourth example: - $[1, 2, 3, 7, 8, 9]$
[ { "input": "7\n3 3 4 7 5 6 8", "output": "4\n2 3 5 6 " }, { "input": "6\n1 3 5 2 4 6", "output": "2\n1 4 " }, { "input": "4\n10 9 8 7", "output": "1\n1 " }, { "input": "9\n6 7 8 3 4 5 9 10 11", "output": "6\n1 2 3 7 8 9 " }, { "input": "1\n1337", "output": "1\n1 " }, { "input": "2\n456 123", "output": "1\n1 " }, { "input": "7\n100 3 4 7 5 6 8", "output": "4\n2 3 5 6 " }, { "input": "7\n3 3 4 5 6 7 8", "output": "6\n2 3 4 5 6 7 " }, { "input": "12\n1 2 3 4 5 6 7 8 9 10 11 12", "output": "12\n1 2 3 4 5 6 7 8 9 10 11 12 " } ]
15
0
0
228
0
none
[ "none" ]
null
null
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be *n* players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately. Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament. Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
The only line of the input contains a single integer *n* (2<=≀<=*n*<=≀<=1018)Β β€” the number of players to participate in the tournament.
Print the maximum number of games in which the winner of the tournament can take part.
[ "2\n", "3\n", "4\n", "10\n" ]
[ "1\n", "2\n", "2\n", "4\n" ]
In all samples we consider that player number 1 is the winner. In the first sample, there would be only one game so the answer is 1. In the second sample, player 1 can consequently beat players 2 and 3. In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
[ { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "2" }, { "input": "10", "output": "4" }, { "input": "1000", "output": "14" }, { "input": "2500", "output": "15" }, { "input": "690000", "output": "27" }, { "input": "3000000000", "output": "45" }, { "input": "123456789123456789", "output": "81" }, { "input": "5", "output": "3" }, { "input": "143", "output": "9" }, { "input": "144", "output": "10" }, { "input": "145", "output": "10" }, { "input": "232", "output": "10" }, { "input": "233", "output": "11" }, { "input": "234", "output": "11" }, { "input": "679891637638612257", "output": "84" }, { "input": "679891637638612258", "output": "85" }, { "input": "679891637638612259", "output": "85" }, { "input": "1000000000000000000", "output": "85" }, { "input": "10235439547", "output": "47" }, { "input": "1240723548", "output": "43" }, { "input": "92353046212453", "output": "66" }, { "input": "192403205846532", "output": "68" }, { "input": "13925230525389", "output": "62" }, { "input": "12048230592523", "output": "62" }, { "input": "19204385325853", "output": "63" }, { "input": "902353283921", "output": "56" }, { "input": "793056859214355", "output": "70" }, { "input": "982045466234565", "output": "71" }, { "input": "126743950353465", "output": "67" }, { "input": "12405430465", "output": "47" }, { "input": "10238439257768", "output": "61" }, { "input": "1728493055346", "output": "58" }, { "input": "927553829046", "output": "56" }, { "input": "62735129403", "output": "51" }, { "input": "71624823950223", "output": "65" }, { "input": "8902353464851212", "output": "75" }, { "input": "61824012598535", "output": "65" }, { "input": "1294902504603347", "output": "71" }, { "input": "6", "output": "3" }, { "input": "7", "output": "3" }, { "input": "8", "output": "4" }, { "input": "9", "output": "4" }, { "input": "11", "output": "4" }, { "input": "12", "output": "4" }, { "input": "13", "output": "5" }, { "input": "14", "output": "5" }, { "input": "15", "output": "5" }, { "input": "16", "output": "5" }, { "input": "17", "output": "5" }, { "input": "18", "output": "5" }, { "input": "19", "output": "5" }, { "input": "20", "output": "5" }, { "input": "21", "output": "6" }, { "input": "22", "output": "6" }, { "input": "23", "output": "6" }, { "input": "355687428096000", "output": "69" }, { "input": "576460752303423488", "output": "84" }, { "input": "32212254719", "output": "49" }, { "input": "26388279066623", "output": "63" }, { "input": "618473717761", "output": "56" }, { "input": "262406072477", "output": "54" } ]
62
4,608,000
0
230
228
Is your horseshoe on the other hoof?
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≀<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≀<=109) β€” the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer β€” the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 586975278", "output": "1" }, { "input": "259504825 377489979 588153796 377489979", "output": "1" }, { "input": "652588203 931100304 931100304 652588203", "output": "2" }, { "input": "391958720 651507265 391958720 651507265", "output": "2" }, { "input": "90793237 90793237 90793237 90793237", "output": "3" }, { "input": "551651653 551651653 551651653 551651653", "output": "3" }, { "input": "156630260 609654355 668943582 973622757", "output": "0" }, { "input": "17061017 110313588 434481173 796661222", "output": "0" }, { "input": "24975422 256716298 337790533 690960249", "output": "0" }, { "input": "255635360 732742923 798648949 883146723", "output": "0" }, { "input": "133315691 265159773 734556507 265159773", "output": "1" }, { "input": "28442865 741657755 978106882 978106882", "output": "1" }, { "input": "131245479 174845575 497483467 131245479", "output": "1" }, { "input": "139159884 616215581 958341883 616215581", "output": "1" }, { "input": "147784432 947653080 947653080 947653080", "output": "2" }, { "input": "94055790 756126496 756126496 94055790", "output": "2" }, { "input": "240458500 511952208 240458500 511952208", "output": "2" }, { "input": "681828506 972810624 972810624 681828506", "output": "2" }, { "input": "454961014 454961014 454961014 454961014", "output": "3" }, { "input": "915819430 915819430 915819430 915819430", "output": "3" }, { "input": "671645142 671645142 671645142 671645142", "output": "3" }, { "input": "132503558 132503558 132503558 132503558", "output": "3" }, { "input": "5 5 999999 6", "output": "1" }, { "input": "1 1 2 5", "output": "1" }, { "input": "2 1 2 3", "output": "1" }, { "input": "1 1 3 5", "output": "1" }, { "input": "1 1 3 3", "output": "2" }, { "input": "2 2 2 1", "output": "2" }, { "input": "3 1 1 1", "output": "2" }, { "input": "1 2 2 2", "output": "2" } ]
122
0
3
231
73
The Elder Trolls IV: Oblivon
[ "greedy", "math" ]
A. The Elder Trolls IV: Oblivon
2
256
Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "Unkillable"? Firstly, because it can be killed with cutting weapon only, so lovers of two-handed amber hammers should find suitable knife themselves. Secondly, it is necessary to make so many cutting strokes to Unkillable Slug. Extremely many. Too many! Vasya has already promoted his character to 80-th level and in order to gain level 81 he was asked to kill Unkillable Slug. The monster has a very interesting shape. It looks like a rectangular parallelepiped with size *x*<=Γ—<=*y*<=Γ—<=*z*, consisting of undestructable cells 1<=Γ—<=1<=Γ—<=1. At one stroke Vasya can cut the Slug along an imaginary grid, i.e. cut with a plane parallel to one of the parallelepiped side. Monster dies when amount of parts it is divided reaches some critical value. All parts of monster do not fall after each cut, they remains exactly on its places. I. e. Vasya can cut several parts with one cut. Vasya wants to know what the maximum number of pieces he can cut the Unkillable Slug into striking him at most *k* times. Vasya's character uses absolutely thin sword with infinite length.
The first line of input contains four integer numbers *x*,<=*y*,<=*z*,<=*k* (1<=≀<=*x*,<=*y*,<=*z*<=≀<=106,<=0<=≀<=*k*<=≀<=109).
Output the only number β€” the answer for the problem. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
[ "2 2 2 3\n", "2 2 2 1\n" ]
[ "8", "2" ]
In the first sample Vasya make 3 pairwise perpendicular cuts. He cuts monster on two parts with the first cut, then he divides each part on two with the second cut, and finally he divides each of the 4 parts on two.
[ { "input": "2 2 2 3", "output": "8" }, { "input": "2 2 2 1", "output": "2" }, { "input": "1 1 1 1", "output": "1" }, { "input": "1 2 3 3", "output": "6" }, { "input": "20 4 5 12", "output": "120" }, { "input": "100 500 100500 1000000000", "output": "5025000000" }, { "input": "2 5 5 9", "output": "50" }, { "input": "11 1 11 11", "output": "42" }, { "input": "100500 5000 500 100000000", "output": "251250000000" }, { "input": "2 2 2 0", "output": "1" }, { "input": "1000000 1000000 1000000 2444441", "output": "540974149875309150" }, { "input": "1000000 1000000 1000000 1000000000", "output": "1000000000000000000" }, { "input": "1000000 1000000 1000000 2999996", "output": "999999000000000000" }, { "input": "1000000 1000000 1000000 2999997", "output": "1000000000000000000" }, { "input": "999999 1000000 999997 999999999", "output": "999996000003000000" }, { "input": "500000 1000000 750000 100000", "output": "37040370459260" }, { "input": "999999 1 999998 1333333", "output": "444445555556" }, { "input": "500000 10000 1000000 29998", "output": "1000100000000" }, { "input": "10000 500000 1000000 29999", "output": "1000200010000" }, { "input": "10000 1000000 500000 29996", "output": "999900000000" }, { "input": "999999 123456 987654 0", "output": "1" }, { "input": "1 1 1 0", "output": "1" }, { "input": "219482 801483 941695 280976", "output": "821595067700400" }, { "input": "808994 288453 204353 580644", "output": "7250580779648149" }, { "input": "428676 64403 677407 626161", "output": "5081000961597840" }, { "input": "559002 326875 150818 157621", "output": "145045169133102" }, { "input": "178008 590076 624581 201286", "output": "302062187173952" }, { "input": "797745 854005 98703 735186", "output": "9996502351557447" }, { "input": "418223 118667 573175 776998", "output": "12857677898465963" }, { "input": "39436 384053 48008 313346", "output": "427693170156640" }, { "input": "661377 149342 523189 353305", "output": "1633415415004970" }, { "input": "781081 414037 495753 892089", "output": "26294515330164544" }, { "input": "402353 679460 969495 930195", "output": "29810031851367496" }, { "input": "593408 709898 624186 915570", "output": "28425961712082871" }, { "input": "1000 988 1000000 3000", "output": "1002820000" }, { "input": "91839 2 3 50", "output": "288" }, { "input": "999900 999990 4 129", "output": "16384" }, { "input": "1024 100000 4 13", "output": "144" }, { "input": "1000000 1000000 1000000 1000000000", "output": "1000000000000000000" }, { "input": "1 1000000 1 1000000000", "output": "1000000" }, { "input": "2 1000 1000000 1000000000", "output": "2000000000" }, { "input": "999999 2 1000000 1000000000", "output": "1999998000000" }, { "input": "1000 1 1 1", "output": "2" }, { "input": "1000 1 1 998", "output": "999" }, { "input": "1000 1 1 1000", "output": "1000" }, { "input": "33334 66667 1000000 100000", "output": "37040370459260" }, { "input": "1 1000000 2 23123", "output": "46246" } ]
92
0
0
232
24
Berland collider
[ "binary search" ]
E. Berland collider
1
256
Recently the construction of Berland collider has been completed. Collider can be represented as a long narrow tunnel that contains *n* particles. We associate with collider 1-dimensional coordinate system, going from left to right. For each particle we know its coordinate and velocity at the moment of start of the collider. The velocities of the particles don't change after the launch of the collider. Berland scientists think that the big bang will happen at the first collision of particles, whose velocities differs in directions. Help them to determine how much time elapses after the launch of the collider before the big bang happens.
The first line contains single integer *n* (1<=≀<=*n*<=≀<=5Β·105) β€” amount of particles in the collider. Next *n* lines contain description of particles. Each particle is described by two integers *x**i*, *v**i* (<=-<=109<=≀<=*x**i*,<=*v**i*<=≀<=109,<=*v**i*<=β‰ <=0) β€” coordinate and velocity respectively. All the coordinates are distinct. The particles are listed in order of increasing of coordinates. All the coordinates are in meters, and all the velocities β€” in meters per second. The negative velocity means that after the start of collider the particle will move to the left, and the positive β€” that the particle will move to the right.
If there will be no big bang, output -1. Otherwise output one number β€” how much time in seconds elapses after the launch of the collider before the big bang happens. Your answer must have a relative or absolute error less than 10<=-<=9.
[ "3\n-5 9\n0 1\n5 -1\n", "6\n1 3\n2 3\n3 3\n4 -3\n5 -1\n6 -100\n" ]
[ "1.00000000000000000000\n", "0.02912621359223301065\n" ]
none
[ { "input": "3\n-5 9\n0 1\n5 -1", "output": "1.00000000000000000000" }, { "input": "6\n1 3\n2 3\n3 3\n4 -3\n5 -1\n6 -100", "output": "0.02912621359223301065" }, { "input": "2\n-1000000000 1\n1000000000 -1", "output": "1000000000.00000000000000000000" }, { "input": "2\n-1000000000 -1000000000\n1000000000 1000000000", "output": "-1.00000000000000000000" }, { "input": "2\n-156937950 -374833246\n958300153 463070159", "output": "-1.00000000000000000000" }, { "input": "3\n-881879811 207649703\n458744977 -751771616\n589655887 -175300397", "output": "1.39732645236331265437" }, { "input": "4\n-925572098 -981226339\n-79539996 -599059823\n221011621 -813670952\n769702162 -909895529", "output": "-1.00000000000000000000" }, { "input": "10\n-774675771 179630170\n-743176829 190325067\n-718170081 850285922\n-672683474 -389325596\n-612117485 -338760201\n-200797120 -278253406\n-134576842 748798831\n301079085 755005057\n945958360 -883545251\n955629379 -312997434", "output": "0.03669424359124097423" }, { "input": "20\n-993032259 588930376\n-992093161 915475807\n-916464883 -313099768\n-777812700 -790244010\n-559998666 152323291\n-552926767 745694067\n-489434665 332658987\n-310676193 687524020\n-238620668 88387668\n-183633372 294074811\n-89656750 233743240\n-39938323 194724339\n15621290 -244257473\n118853137 -823979220\n215181269 961240622\n224560970 967953108\n297709949 665893756\n314124971 127542046\n317622290 -269656857\n710505266 635433994", "output": "0.00880495634198667429" }, { "input": "1\n-772620876 2105125", "output": "-1.00000000000000000000" }, { "input": "10\n-904213434 999999991\n-800146111 999999990\n-64167773 999998990\n40786982 999997990\n57739924 999996990\n140713247 -999995990\n242293931 -999996990\n470153869 -999997990\n688427965 -999998990\n979253150 -999999990", "output": "0.04148680711869298654" }, { "input": "14\n-916171372 999999988\n-892307487 999999987\n-882212312 999999986\n-700694118 999998986\n-490374058 999997986\n-179890370 999996986\n-153268251 999995986\n-143722350 -999994986\n822181362 -999995986\n888153520 -999996986\n913366887 -999997986\n971641961 -999998986\n982052281 -999999986\n989641415 -999999987", "output": "0.00477297204519581270" }, { "input": "20\n-990544325 999999983\n-982730292 999999982\n-954108391 999999981\n-843979328 999999980\n-842201083 999998980\n-841368019 999997980\n-713774935 999996980\n-526274553 999995980\n-414200681 999994980\n-380902854 999993980\n-356598408 -999991980\n82002495 -999992980\n337411348 -999993980\n431155182 -999994980\n495442299 -999995980\n500857279 -999996980\n501941044 -999997980\n666074520 -999998980\n766795088 -999999980\n889713230 -999999981", "output": "0.01215230830920432936" }, { "input": "10\n-904213434 999999991\n-800146111 999999990\n-64167773 3\n40786982 2\n57739924 1\n140713247 -1\n242293931 -2\n470153869 -3\n688427965 -4\n979253150 -999999990", "output": "0.88969963939699647781" }, { "input": "20\n-977812598 999999995\n-859749238 999999994\n-795105479 999999993\n-755580921 999999992\n-703290711 999999991\n-684916878 999999990\n-671093572 999999989\n-598373289 999999988\n-430900427 999999987\n-409406663 999999986\n-186156927 999999985\n137241693 999999984\n174675082 999999983\n233164672 999999982\n263947075 999999981\n281714302 999999980\n501584746 -1\n638491974 -2\n654696707 -999999980\n795033851 -999999981", "output": "0.18649120622982412465" }, { "input": "10\n-957843473 999999990\n-892079437 3\n-660108218 2\n-38604909 1\n117904913 -1\n161630686 -2\n300782495 -3\n503931515 -4\n624182611 -5\n946997174 -999999990", "output": "0.95242033302420336938" }, { "input": "20\n-991228878 999999990\n-966272577 999999989\n-832645426 999999988\n-595404692 999999987\n-593256652 999999986\n-403204913 999999985\n-331750739 999999984\n-254714125 999999983\n-252716873 999999982\n-242309489 999999981\n-99999163 999999980\n53963197 1\n102558090 -1\n208915316 -2\n327993195 -999999980\n338364526 -999999981\n353909346 -999999982\n699191947 -999999983\n748932019 -999999984\n807201175 -999999985", "output": "0.20255725684858788549" }, { "input": "5\n-99999163 999999980\n53963197 1\n102558090 -1\n208915316 -2\n327993195 -999999980", "output": "0.20255725684858788549" }, { "input": "1\n-554798529 -923175217", "output": "-1.00000000000000000000" }, { "input": "1\n-780061535 64785965", "output": "-1.00000000000000000000" }, { "input": "2\n635254031 797637946\n855431510 75159864", "output": "-1.00000000000000000000" }, { "input": "2\n-912376737 -339403417\n389839726 -135372297", "output": "-1.00000000000000000000" }, { "input": "2\n-1000000000 1000000000\n1000000000 -1000000000", "output": "1.00000000000000000000" }, { "input": "2\n-1 1000000000\n1 -1000000000", "output": "0.00000000100000000002" }, { "input": "2\n-1 1\n1 -1", "output": "1.00000000000000000000" }, { "input": "2\n-1 1000000000\n0 -1000000000", "output": "0.00000000050000000003" }, { "input": "2\n-1000000000 7\n1000000000 -6", "output": "153846153.84615385532379150391" } ]
1,500
34,816,000
0
233
786
Till I Collapse
[ "data structures", "divide and conquer" ]
null
null
Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. They Have generated *n* Mr. Meeseeks, standing in a line numbered from 1 to *n*. Each of them has his own color. *i*-th Mr. Meeseeks' color is *a**i*. Rick and Morty are gathering their army and they want to divide Mr. Meeseeks into some squads. They don't want their squads to be too colorful, so each squad should have Mr. Meeseeks of at most *k* different colors. Also each squad should be a continuous subarray of Mr. Meeseeks in the line. Meaning that for each 1<=≀<=*i*<=≀<=*e*<=≀<=*j*<=≀<=*n*, if Mr. Meeseeks number *i* and Mr. Meeseeks number *j* are in the same squad then Mr. Meeseeks number *e* should be in that same squad. Also, each squad needs its own presidio, and building a presidio needs money, so they want the total number of squads to be minimized. Rick and Morty haven't finalized the exact value of *k*, so in order to choose it, for each *k* between 1 and *n* (inclusive) need to know the minimum number of presidios needed.
The first line of input contains a single integer *n* (1<=≀<=*n*<=≀<=105) β€” number of Mr. Meeseeks. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* separated by spaces (1<=≀<=*a**i*<=≀<=*n*) β€” colors of Mr. Meeseeks in order they standing in a line.
In the first and only line of input print *n* integers separated by spaces. *i*-th integer should be the minimum number of presidios needed if the value of *k* is *i*.
[ "5\n1 3 4 3 3\n", "8\n1 5 7 8 1 7 6 1\n" ]
[ "4 2 1 1 1 \n", "8 4 3 2 1 1 1 1 \n" ]
For the first sample testcase, some optimal ways of dividing army into squads for each *k* are: 1. [1], [3], [4], [3, 3] 1. [1], [3, 4, 3, 3] 1. [1, 3, 4, 3, 3] 1. [1, 3, 4, 3, 3] 1. [1, 3, 4, 3, 3] For the second testcase, some optimal ways of dividing army into squads for each *k* are: 1. [1], [5], [7], [8], [1], [7], [6], [1] 1. [1, 5], [7, 8], [1, 7], [6, 1] 1. [1, 5, 7], [8], [1, 7, 6, 1] 1. [1, 5, 7, 8], [1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1] 1. [1, 5, 7, 8, 1, 7, 6, 1]
[ { "input": "5\n1 3 4 3 3", "output": "4 2 1 1 1 " }, { "input": "8\n1 5 7 8 1 7 6 1", "output": "8 4 3 2 1 1 1 1 " }, { "input": "10\n4 1 2 6 8 5 3 9 3 9", "output": "10 4 3 2 2 2 2 1 1 1 " }, { "input": "85\n23 11 69 1 49 10 7 13 66 35 81 4 51 2 62 55 31 18 85 34 59 44 20 28 27 5 6 79 43 78 45 64 61 56 12 40 54 52 24 14 26 65 75 72 30 46 67 80 38 70 25 60 50 8 17 84 41 71 58 76 19 47 73 29 3 48 82 33 39 63 15 37 83 36 9 32 16 57 68 53 21 77 22 42 74", "output": "85 43 29 22 17 15 13 11 10 9 8 8 7 7 6 6 5 5 5 5 5 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 " }, { "input": "100\n39 78 71 61 54 13 17 81 30 33 83 98 44 10 45 87 75 47 70 84 41 86 49 94 85 91 37 64 5 56 67 79 28 89 50 53 77 93 81 14 97 67 58 6 48 60 89 62 29 3 38 8 88 19 66 63 100 17 43 97 21 12 58 76 2 78 25 73 99 11 27 18 57 46 4 72 68 45 74 18 2 80 51 52 42 59 55 35 1 95 42 92 36 40 59 15 7 21 97 53", "output": "100 50 34 25 20 17 15 13 11 10 10 9 8 7 7 6 6 6 6 5 5 5 5 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "1\n1", "output": "1 " } ]
2,000
26,112,000
0
234
894
QAQ
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
The only line contains a string of length *n* (1<=≀<=*n*<=≀<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integerΒ β€” the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { "input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ", "output": "1077" }, { "input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA", "output": "568" }, { "input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA", "output": "70" }, { "input": "W", "output": "0" }, { "input": "DBA", "output": "0" }, { "input": "RQAWNACASAAKAGAAAAQ", "output": "10" }, { "input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA", "output": "111" }, { "input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA", "output": "411" }, { "input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ", "output": "625" }, { "input": "QORZOYAQ", "output": "1" }, { "input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA", "output": "13174" }, { "input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT", "output": "10420" }, { "input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ", "output": "12488" }, { "input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA", "output": "9114" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "35937" }, { "input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE", "output": "254" }, { "input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE", "output": "2174" }, { "input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ", "output": "2962" }, { "input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA", "output": "2482" }, { "input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ", "output": "7768" }, { "input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA", "output": "5422" }, { "input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ", "output": "3024" }, { "input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ", "output": "4527" }, { "input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH", "output": "6416" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ", "output": "13136" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA", "output": "14231" }, { "input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "15296" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA", "output": "20825" }, { "input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ", "output": "20825" }, { "input": "Q", "output": "0" }, { "input": "A", "output": "0" }, { "input": "FFF", "output": "0" }, { "input": "AAAAAA", "output": "0" } ]
109
0
3
235
230
T-primes
[ "binary search", "implementation", "math", "number theory" ]
null
null
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Π’-prime, if *t* has exactly three distinct positive divisors. You are given an array of *n* positive integers. For each of them determine whether it is Π’-prime or not.
The first line contains a single positive integer, *n* (1<=≀<=*n*<=≀<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≀<=*x**i*<=≀<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Π’-prime, and "NO" (without the quotes), if it isn't.
[ "3\n4 5 6\n" ]
[ "YES\nNO\nNO\n" ]
The given test has three numbers. The first number 4 has exactly three divisors β€” 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
[ { "input": "3\n4 5 6", "output": "YES\nNO\nNO" }, { "input": "2\n48 49", "output": "NO\nYES" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO" }, { "input": "1\n36", "output": "NO" }, { "input": "1\n999966000289", "output": "YES" }, { "input": "1\n999993399999", "output": "NO" }, { "input": "9\n111 121 131 111 121 131 111 121 131", "output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO" }, { "input": "1\n1", "output": "NO" }, { "input": "1\n10", "output": "NO" }, { "input": "1\n976197352729", "output": "NO" }, { "input": "1\n1000000000000", "output": "NO" }, { "input": "1\n9", "output": "YES" }, { "input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849", "output": "NO\nNO\nNO\nNO\nNO\nNO" }, { "input": "3\n223092870 6469693230 200560490130", "output": "NO\nNO\nNO" }, { "input": "2\n81 25", "output": "NO\nYES" }, { "input": "1\n16", "output": "NO" }, { "input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81", "output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO" }, { "input": "1\n225", "output": "NO" }, { "input": "1\n1521", "output": "NO" }, { "input": "1\n81", "output": "NO" } ]
2,000
14,336,000
0
236
534
Exam
[ "constructive algorithms", "implementation", "math" ]
null
null
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure. Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.
A single line contains integer *n* (1<=≀<=*n*<=≀<=5000) β€” the number of students at an exam.
In the first line print integer *k* β€” the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≀<=*a**i*<=≀<=*n*), where *a**i* is the number of the student on the *i*-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |*a**i*<=-<=*a**i*<=+<=1|<=β‰ <=1 for all *i* from 1 to *k*<=-<=1. If there are several possible answers, output any of them.
[ "6", "3\n" ]
[ "6\n1 5 3 6 2 4", "2\n1 3" ]
none
[ { "input": "6", "output": "6\n5 3 1 6 4 2 " }, { "input": "3", "output": "2\n1 3" }, { "input": "1", "output": "1\n1 " }, { "input": "2", "output": "1\n1" }, { "input": "4", "output": "4\n3 1 4 2 " }, { "input": "5", "output": "5\n5 3 1 4 2 " }, { "input": "7", "output": "7\n7 5 3 1 6 4 2 " }, { "input": "8", "output": "8\n7 5 3 1 8 6 4 2 " }, { "input": "9", "output": "9\n9 7 5 3 1 8 6 4 2 " }, { "input": "10", "output": "10\n9 7 5 3 1 10 8 6 4 2 " }, { "input": "13", "output": "13\n13 11 9 7 5 3 1 12 10 8 6 4 2 " }, { "input": "16", "output": "16\n15 13 11 9 7 5 3 1 16 14 12 10 8 6 4 2 " }, { "input": "25", "output": "25\n25 23 21 19 17 15 13 11 9 7 5 3 1 24 22 20 18 16 14 12 10 8 6 4 2 " }, { "input": "29", "output": "29\n29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 28 26 24 22 20 18 16 14 12 10 8 6 4 2 " }, { "input": "120", "output": "120\n119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 120 118 116 114 112 110 108 106 104 102 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 " }, { "input": "128", "output": "128\n127 125 123 121 119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 128 126 124 122 120 118 116 114 112 110 108 106 104 102 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 " }, { "input": "216", "output": "216\n215 213 211 209 207 205 203 201 199 197 195 193 191 189 187 185 183 181 179 177 175 173 171 169 167 165 163 161 159 157 155 153 151 149 147 145 143 141 139 137 135 133 131 129 127 125 123 121 119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 216 214 212 210 208 206 204 202 200 198 196 194 192 190 188 186 184 182 180 178 176 174 172 170 168 166 164 162 160 158 156 154 1..." }, { "input": "729", "output": "729\n729 727 725 723 721 719 717 715 713 711 709 707 705 703 701 699 697 695 693 691 689 687 685 683 681 679 677 675 673 671 669 667 665 663 661 659 657 655 653 651 649 647 645 643 641 639 637 635 633 631 629 627 625 623 621 619 617 615 613 611 609 607 605 603 601 599 597 595 593 591 589 587 585 583 581 579 577 575 573 571 569 567 565 563 561 559 557 555 553 551 549 547 545 543 541 539 537 535 533 531 529 527 525 523 521 519 517 515 513 511 509 507 505 503 501 499 497 495 493 491 489 487 485 483 481 479 47..." }, { "input": "1111", "output": "1111\n1111 1109 1107 1105 1103 1101 1099 1097 1095 1093 1091 1089 1087 1085 1083 1081 1079 1077 1075 1073 1071 1069 1067 1065 1063 1061 1059 1057 1055 1053 1051 1049 1047 1045 1043 1041 1039 1037 1035 1033 1031 1029 1027 1025 1023 1021 1019 1017 1015 1013 1011 1009 1007 1005 1003 1001 999 997 995 993 991 989 987 985 983 981 979 977 975 973 971 969 967 965 963 961 959 957 955 953 951 949 947 945 943 941 939 937 935 933 931 929 927 925 923 921 919 917 915 913 911 909 907 905 903 901 899 897 895 893 891 889 8..." }, { "input": "1597", "output": "1597\n1597 1595 1593 1591 1589 1587 1585 1583 1581 1579 1577 1575 1573 1571 1569 1567 1565 1563 1561 1559 1557 1555 1553 1551 1549 1547 1545 1543 1541 1539 1537 1535 1533 1531 1529 1527 1525 1523 1521 1519 1517 1515 1513 1511 1509 1507 1505 1503 1501 1499 1497 1495 1493 1491 1489 1487 1485 1483 1481 1479 1477 1475 1473 1471 1469 1467 1465 1463 1461 1459 1457 1455 1453 1451 1449 1447 1445 1443 1441 1439 1437 1435 1433 1431 1429 1427 1425 1423 1421 1419 1417 1415 1413 1411 1409 1407 1405 1403 1401 1399 1397 ..." }, { "input": "1777", "output": "1777\n1777 1775 1773 1771 1769 1767 1765 1763 1761 1759 1757 1755 1753 1751 1749 1747 1745 1743 1741 1739 1737 1735 1733 1731 1729 1727 1725 1723 1721 1719 1717 1715 1713 1711 1709 1707 1705 1703 1701 1699 1697 1695 1693 1691 1689 1687 1685 1683 1681 1679 1677 1675 1673 1671 1669 1667 1665 1663 1661 1659 1657 1655 1653 1651 1649 1647 1645 1643 1641 1639 1637 1635 1633 1631 1629 1627 1625 1623 1621 1619 1617 1615 1613 1611 1609 1607 1605 1603 1601 1599 1597 1595 1593 1591 1589 1587 1585 1583 1581 1579 1577 ..." }, { "input": "2048", "output": "2048\n2047 2045 2043 2041 2039 2037 2035 2033 2031 2029 2027 2025 2023 2021 2019 2017 2015 2013 2011 2009 2007 2005 2003 2001 1999 1997 1995 1993 1991 1989 1987 1985 1983 1981 1979 1977 1975 1973 1971 1969 1967 1965 1963 1961 1959 1957 1955 1953 1951 1949 1947 1945 1943 1941 1939 1937 1935 1933 1931 1929 1927 1925 1923 1921 1919 1917 1915 1913 1911 1909 1907 1905 1903 1901 1899 1897 1895 1893 1891 1889 1887 1885 1883 1881 1879 1877 1875 1873 1871 1869 1867 1865 1863 1861 1859 1857 1855 1853 1851 1849 1847 ..." }, { "input": "2999", "output": "2999\n2999 2997 2995 2993 2991 2989 2987 2985 2983 2981 2979 2977 2975 2973 2971 2969 2967 2965 2963 2961 2959 2957 2955 2953 2951 2949 2947 2945 2943 2941 2939 2937 2935 2933 2931 2929 2927 2925 2923 2921 2919 2917 2915 2913 2911 2909 2907 2905 2903 2901 2899 2897 2895 2893 2891 2889 2887 2885 2883 2881 2879 2877 2875 2873 2871 2869 2867 2865 2863 2861 2859 2857 2855 2853 2851 2849 2847 2845 2843 2841 2839 2837 2835 2833 2831 2829 2827 2825 2823 2821 2819 2817 2815 2813 2811 2809 2807 2805 2803 2801 2799 ..." }, { "input": "3001", "output": "3001\n3001 2999 2997 2995 2993 2991 2989 2987 2985 2983 2981 2979 2977 2975 2973 2971 2969 2967 2965 2963 2961 2959 2957 2955 2953 2951 2949 2947 2945 2943 2941 2939 2937 2935 2933 2931 2929 2927 2925 2923 2921 2919 2917 2915 2913 2911 2909 2907 2905 2903 2901 2899 2897 2895 2893 2891 2889 2887 2885 2883 2881 2879 2877 2875 2873 2871 2869 2867 2865 2863 2861 2859 2857 2855 2853 2851 2849 2847 2845 2843 2841 2839 2837 2835 2833 2831 2829 2827 2825 2823 2821 2819 2817 2815 2813 2811 2809 2807 2805 2803 2801 ..." }, { "input": "4181", "output": "4181\n4181 4179 4177 4175 4173 4171 4169 4167 4165 4163 4161 4159 4157 4155 4153 4151 4149 4147 4145 4143 4141 4139 4137 4135 4133 4131 4129 4127 4125 4123 4121 4119 4117 4115 4113 4111 4109 4107 4105 4103 4101 4099 4097 4095 4093 4091 4089 4087 4085 4083 4081 4079 4077 4075 4073 4071 4069 4067 4065 4063 4061 4059 4057 4055 4053 4051 4049 4047 4045 4043 4041 4039 4037 4035 4033 4031 4029 4027 4025 4023 4021 4019 4017 4015 4013 4011 4009 4007 4005 4003 4001 3999 3997 3995 3993 3991 3989 3987 3985 3983 3981 ..." }, { "input": "4990", "output": "4990\n4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 4789 ..." }, { "input": "4991", "output": "4991\n4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 ..." }, { "input": "4992", "output": "4992\n4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 4791 ..." }, { "input": "4993", "output": "4993\n4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 ..." }, { "input": "4994", "output": "4994\n4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 4793 ..." }, { "input": "4995", "output": "4995\n4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 ..." }, { "input": "4996", "output": "4996\n4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 4795 ..." }, { "input": "4997", "output": "4997\n4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 ..." }, { "input": "4998", "output": "4998\n4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 4797 ..." }, { "input": "4999", "output": "4999\n4999 4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 ..." }, { "input": "5000", "output": "5000\n4999 4997 4995 4993 4991 4989 4987 4985 4983 4981 4979 4977 4975 4973 4971 4969 4967 4965 4963 4961 4959 4957 4955 4953 4951 4949 4947 4945 4943 4941 4939 4937 4935 4933 4931 4929 4927 4925 4923 4921 4919 4917 4915 4913 4911 4909 4907 4905 4903 4901 4899 4897 4895 4893 4891 4889 4887 4885 4883 4881 4879 4877 4875 4873 4871 4869 4867 4865 4863 4861 4859 4857 4855 4853 4851 4849 4847 4845 4843 4841 4839 4837 4835 4833 4831 4829 4827 4825 4823 4821 4819 4817 4815 4813 4811 4809 4807 4805 4803 4801 4799 ..." } ]
62
204,800
3
237