Search is not available for this dataset
problem_id
stringlengths
32
32
name
stringlengths
2
112
problem
stringlengths
200
14k
test_cases
stringlengths
33
79.2M
difficulty
stringclasses
33 values
language
sequencelengths
1
1
source
stringclasses
14 values
num_solutions
int64
2
1.9M
starter_code
stringlengths
0
1.47k
subset
stringclasses
3 values
6b5a6f7fd3372a62826ecad686da6fb9
Cinema Cashier
All cinema halls in Berland are rectangles with *K* rows of *K* seats each, and *K* is an odd number. Rows and seats are numbered from 1 to *K*. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the responsibility of a special seating program. It was found out that the large majority of Berland's inhabitants go to the cinema in order to watch a movie, that's why they want to sit as close to the hall center as possible. Moreover, a company of *M* people, who come to watch a movie, want necessarily to occupy *M* successive seats in one row. Let's formulate the algorithm, according to which the program chooses seats and sells tickets. As the request for *M* seats comes, the program should determine the row number *x* and the segment [*y**l*,<=*y**r*] of the seats numbers in this row, where *y**r*<=-<=*y**l*<=+<=1<==<=*M*. From all such possible variants as a final result the program should choose the one with the minimum function value of total seats remoteness from the center. Say, — the row and the seat numbers of the most "central" seat. Then the function value of seats remoteness from the hall center is . If the amount of minimum function values is more than one, the program should choose the one that is closer to the screen (i.e. the row number *x* is lower). If the variants are still multiple, it should choose the one with the minimum *y**l*. If you did not get yet, your task is to simulate the work of this program. The first line contains two integers *N* and *K* (1<=≤<=*N*<=≤<=1000,<=1<=≤<=*K*<=≤<=99) — the amount of requests and the hall size respectively. The second line contains *N* space-separated integers *M**i* from the range [1,<=*K*] — requests to the program. Output *N* lines. In the *i*-th line output «-1» (without quotes), if it is impossible to find *M**i* successive seats in one row, otherwise output three numbers *x*,<=*y**l*,<=*y**r*. Separate the numbers with a space. Sample Input 2 1 1 1 4 3 1 2 3 1 Sample Output 1 1 1 -1 2 2 2 1 1 2 3 1 3 2 1 1
{"inputs": ["2 1\n1 1", "4 3\n1 2 3 1", "1 3\n1", "2 3\n3 3", "3 3\n3 2 3", "1 5\n5", "2 5\n3 4", "3 5\n2 5 2", "4 5\n5 5 3 5", "5 5\n4 1 3 1 1", "10 11\n3 11 6 4 4 11 9 2 1 9", "10 13\n12 8 7 11 11 9 2 12 10 1", "10 15\n15 6 1 9 3 10 11 1 14 10", "10 17\n5 8 13 5 11 12 10 17 16 7", "10 19\n8 19 17 12 4 5 9 16 7 3", "50 21\n8 17 19 1 14 17 16 19 6 2 8 5 20 17 6 17 20 4 16 15 16 17 4 3 17 20 17 8 13 10 21 21 6 13 6 13 10 5 12 7 21 21 21 2 12 16 13 5 5 9", "50 23\n11 20 3 5 5 14 20 18 18 22 9 17 6 13 1 23 21 3 2 3 11 4 16 20 14 22 6 6 19 21 13 10 8 10 21 9 10 9 21 23 6 21 21 17 1 23 15 10 13 20", "50 25\n19 18 3 12 15 2 22 14 4 4 6 15 16 1 23 1 21 12 13 9 22 5 17 6 8 24 12 2 13 13 22 6 4 7 23 20 8 3 5 6 9 3 1 17 22 7 23 25 23 13", "50 27\n12 23 16 12 9 24 3 15 13 23 1 16 17 8 19 17 14 6 22 12 11 16 6 13 15 13 14 19 7 4 23 10 8 4 26 12 8 21 14 6 4 6 12 7 18 2 13 17 24 3", "80 29\n19 15 15 27 2 25 2 5 29 11 6 4 20 11 27 16 6 6 10 2 5 12 8 23 11 7 11 13 19 29 8 4 9 13 14 22 16 29 7 12 17 5 17 14 6 15 8 25 11 16 14 4 3 7 25 2 5 2 12 12 22 18 14 16 5 19 25 4 21 24 7 11 21 27 10 16 21 17 19 13", "100 51\n49 27 24 32 36 5 25 25 11 42 32 38 17 30 10 49 23 32 12 42 19 44 5 22 30 21 19 18 36 13 48 46 43 21 13 18 41 13 42 3 27 41 21 41 7 26 51 23 14 13 43 6 5 6 32 44 19 5 44 36 29 48 24 22 45 12 24 48 9 7 7 14 29 26 11 30 23 14 37 13 25 28 28 38 22 41 43 46 26 38 44 48 32 49 32 25 50 33 24 4", "100 53\n43 8 14 35 48 10 4 2 38 50 7 25 20 19 33 31 49 51 14 6 34 31 44 40 30 51 41 44 42 33 33 24 33 53 12 20 25 47 16 2 26 5 45 40 21 17 38 37 2 48 16 45 13 11 5 33 38 19 6 2 37 8 45 39 33 15 5 22 14 36 11 23 28 5 46 5 46 35 32 25 26 36 22 42 15 38 41 45 27 53 51 12 16 12 22 10 1 8 20 29", "100 55\n9 2 36 28 47 12 54 2 18 34 15 25 19 19 22 27 55 13 41 8 31 31 55 26 49 26 44 15 30 18 3 47 40 16 41 1 5 32 49 51 15 29 43 54 24 30 51 52 34 33 31 51 13 3 12 13 30 21 3 25 39 43 25 25 15 44 26 40 14 40 32 7 39 16 45 26 44 5 35 41 17 14 32 44 30 41 5 35 16 43 25 7 19 1 39 20 5 39 15 16", "100 57\n5 19 50 55 18 54 30 56 54 16 44 49 10 47 6 26 5 28 52 28 6 11 1 25 6 43 36 24 48 34 50 46 24 9 35 17 10 28 19 5 23 43 55 25 48 42 15 6 2 26 45 6 22 1 54 17 19 40 32 19 25 10 55 48 14 37 14 42 57 26 23 16 37 43 13 37 37 18 17 16 8 46 28 39 2 11 8 46 33 21 20 9 40 19 12 16 53 53 42 6", "100 59\n48 13 59 51 54 5 35 36 16 25 18 59 9 42 58 1 53 12 19 9 54 5 51 42 45 15 4 35 33 19 36 42 14 46 41 13 7 17 43 43 36 7 24 40 40 1 43 4 42 4 37 51 56 12 5 59 56 21 21 30 54 9 19 30 58 18 7 21 45 32 45 8 12 36 29 52 37 48 27 55 10 28 51 3 33 11 15 49 47 17 22 42 33 14 47 23 42 2 22 10", "100 61\n29 27 54 52 15 7 11 55 3 19 48 52 58 36 41 25 29 20 28 4 57 51 20 16 40 14 15 26 57 2 27 17 39 13 13 50 23 56 5 60 41 9 23 49 34 34 21 41 41 23 24 7 25 36 8 22 9 59 35 58 5 36 47 53 32 11 45 28 10 13 44 52 30 42 41 57 7 7 26 55 17 52 2 6 54 48 58 60 54 53 5 9 40 20 8 18 32 40 24 35", "100 63\n37 58 22 61 4 24 39 23 3 7 52 9 39 33 28 58 44 32 26 46 51 10 18 14 2 33 36 48 60 45 23 31 62 39 22 59 53 8 45 63 49 37 50 4 7 32 13 62 24 29 57 40 26 58 29 20 3 8 38 8 30 42 16 35 54 9 3 44 15 39 31 59 56 36 27 12 25 14 48 60 61 36 14 6 38 42 55 34 63 52 7 17 39 32 29 22 36 26 11 6", "100 65\n20 39 12 31 16 51 58 15 7 37 58 39 39 44 43 55 59 61 13 22 25 13 8 26 3 55 28 45 27 27 19 59 63 13 14 46 7 36 20 9 30 37 63 12 34 59 50 33 65 56 5 17 17 36 61 12 51 45 30 11 12 62 46 65 11 49 49 40 15 19 15 2 41 34 55 57 8 18 39 36 38 49 49 3 15 43 48 13 3 49 58 5 56 41 25 10 64 52 4 54", "100 67\n66 12 2 49 62 63 59 14 13 26 15 25 22 16 33 52 15 14 13 33 9 10 53 28 17 27 18 39 35 64 1 59 33 24 66 64 4 2 4 5 22 9 52 36 44 57 62 3 52 21 62 55 25 2 65 18 20 40 8 30 27 28 47 19 67 67 42 6 53 17 36 38 57 37 45 13 58 12 31 24 15 67 9 18 56 20 34 8 20 31 13 19 42 12 16 15 54 35 20 33", "100 69\n43 49 44 68 20 67 45 53 55 67 68 32 31 6 13 69 18 20 26 5 6 24 46 13 57 8 11 19 27 46 34 32 10 47 28 66 50 49 31 25 54 67 25 27 11 26 41 36 64 55 43 9 65 29 4 45 63 8 45 16 50 58 41 65 1 57 5 56 29 20 49 63 64 28 5 64 64 35 1 27 25 64 42 69 50 41 52 59 31 19 40 50 56 54 63 51 10 49 14 12"], "outputs": ["1 1 1\n-1", "2 2 2\n1 1 2\n3 1 3\n2 1 1", "2 2 2", "2 1 3\n1 1 3", "2 1 3\n1 1 2\n3 1 3", "3 1 5", "3 2 4\n2 1 4", "3 2 3\n2 1 5\n3 4 5", "3 1 5\n2 1 5\n4 2 4\n1 1 5", "3 1 4\n2 3 3\n4 2 4\n1 3 3\n2 2 2", "6 5 7\n5 1 11\n7 3 8\n4 4 7\n8 4 7\n3 1 11\n9 2 10\n6 3 4\n6 8 8\n2 2 10", "7 1 12\n6 3 10\n8 4 10\n5 2 12\n9 2 12\n4 3 11\n10 6 7\n3 1 12\n11 2 11\n10 8 8", "8 1 15\n7 5 10\n9 8 8\n6 4 12\n10 7 9\n5 3 12\n11 3 13\n9 7 7\n4 1 14\n12 3 12", "9 7 11\n8 5 12\n10 3 15\n7 7 11\n11 4 14\n6 3 14\n12 4 13\n5 1 17\n13 1 16\n4 6 12", "10 6 13\n9 1 19\n11 2 18\n8 4 15\n12 8 11\n7 8 12\n13 6 14\n6 2 17\n14 7 13\n10 14 16", "11 7 14\n10 3 19\n12 2 20\n9 11 11\n13 4 17\n8 3 19\n14 3 18\n7 2 20\n9 5 10\n9 12 13\n15 7 14\n11 15 19\n6 1 20\n16 3 19\n5 8 13\n17 3 19\n4 1 20\n9 14 17\n18 3 18\n3 4 18\n19 3 18\n2 3 19\n11 3 6\n15 15 17\n20 3 19\n1 1 20\n21 3 19\n5 14 21\n-1\n-1\n-1\n-1\n15 1 6\n-1\n5 2 7\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n9 3 4\n-1\n-1\n-1\n-1\n-1\n-1", "12 7 17\n11 2 21\n13 11 13\n10 10 14\n14 10 14\n9 5 18\n15 2 21\n8 3 20\n16 3 20\n7 1 22\n13 2 10\n17 4 20\n13 14 19\n6 6 18\n10 9 9\n18 1 23\n5 2 22\n10 15 17\n14 8 9\n14 15 17\n19 7 17\n10 5 8\n4 4 19\n20 2 21\n3 5 18\n21 1 22\n12 1 6\n12 18 23\n2 3 21\n22 2 22\n1 6 18\n23 7 16\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n14 2 7\n-1\n-1\n-1\n10 18 18\n-1\n-1\n-1\n-1\n-1", "13 4 22\n12 4 21\n14 12 14\n11 7 18\n15 6 20\n10 12 13\n16 2 23\n9 6 19\n14 8 11\n14 15 18\n17 10 15\n8 6 20\n18 5 20\n10 14 14\n7 2 24\n10 11 11\n19 3 23\n6 7 18\n20 7 19\n10 15 23\n5 2 23\n10 6 10\n21 5 21\n14 2 7\n17 16 23\n4 1 24\n22 7 18\n14 19 20\n3 7 19\n23 7 19\n2 2 23\n11 19 24\n17 6 9\n24 10 16\n1 2 24\n25 3 22\n24 2 9\n11 4 6\n14 21 25\n9 20 25\n24 17 25\n12 22 24\n13 3 3\n-1\n-1\n6 19 25\n-1\n-1\n-1\n-1", "14 8 19\n13 3 25\n15 6 21\n12 8 19\n16 10 18\n11 2 25\n17 13 15\n10 7 21\n18 8 20\n9 3 25\n17 12 12\n19 6 21\n8 6 22\n20 10 17\n7 5 23\n21 6 22\n6 7 20\n17 16 21\n22 3 24\n5 8 19\n17 1 11\n23 6 21\n14 20 25\n4 8 20\n24 7 21\n3 8 20\n25 7 20\n2 5 23\n14 1 7\n16 6 9\n26 3 25\n20 18 27\n16 19 26\n12 20 23\n1 1 26\n27 8 19\n20 2 9\n-1\n-1\n12 2 7\n15 22 25\n17 22 27\n-1\n18 1 7\n-1\n15 4 5\n-1\n-1\n-1\n16 3 5", "15 6 24\n14 8 22\n16 8 22\n13 2 28\n17 14 15\n12 3 27\n17 16 17\n18 13 17\n11 1 29\n19 10 20\n10 12 17\n17 10 13\n20 5 24\n9 10 20\n21 2 28\n8 7 22\n17 18 23\n18 7 12\n22 10 19\n18 18 19\n7 13 17\n23 9 20\n6 11 18\n24 4 26\n5 10 20\n10 18 24\n25 10 20\n4 9 21\n26 6 24\n3 1 29\n17 2 9\n18 20 23\n10 3 11\n27 9 21\n2 8 21\n28 4 25\n1 7 22\n29 1 29\n14 1 7\n7 1 12\n-1\n14 23 27\n-1\n-1\n16 2 7\n-1\n19 2 9\n-1\n7 18 28\n-1\n-1\n16 23 26\n15 3 5\n19 21 27\n-1\n15 25 26\n17 24 28\n9 8 9\n-1\n-1\n-1\n-1\n-1\n-1\n9...", "26 2 50\n25 13 39\n27 14 37\n24 10 41\n28 8 43\n23 24 28\n29 14 38\n22 14 38\n30 21 31\n21 5 46\n31 10 41\n20 7 44\n32 18 34\n19 11 40\n33 21 30\n18 2 50\n34 15 37\n17 10 41\n23 12 23\n35 5 46\n16 17 35\n36 4 47\n23 29 33\n15 15 36\n37 11 40\n14 16 36\n38 17 35\n13 17 34\n39 8 43\n30 8 20\n12 2 49\n40 3 48\n11 5 47\n41 16 36\n30 32 44\n23 34 51\n10 6 46\n33 31 43\n42 5 46\n27 38 40\n9 13 39\n43 6 46\n8 16 36\n44 6 46\n33 14 20\n7 13 38\n45 1 51\n6 15 37\n32 4 17\n27 1 13\n46 5 47\n25 7 12\n25 40 44\n32 35 ...", "27 6 48\n26 23 30\n28 20 33\n25 10 44\n29 3 50\n24 22 31\n30 25 28\n23 26 27\n31 8 45\n22 2 51\n32 24 30\n21 15 39\n33 17 36\n20 18 36\n34 11 43\n19 12 42\n35 3 51\n18 2 52\n23 28 41\n26 31 36\n36 10 43\n17 12 42\n37 5 48\n16 7 46\n38 12 41\n15 2 52\n39 7 47\n14 5 48\n40 6 47\n13 11 43\n41 11 43\n30 29 52\n12 11 43\n42 1 53\n23 14 25\n26 3 22\n11 15 39\n43 4 50\n30 9 24\n24 32 33\n10 14 39\n28 34 38\n44 5 49\n9 7 46\n24 1 21\n28 3 19\n45 8 45\n8 9 45\n32 22 23\n46 3 50\n32 31 46\n7 5 49\n24 34 46\n26 37 47...", "28 24 32\n27 27 28\n29 10 45\n26 14 41\n30 5 51\n25 22 33\n31 1 54\n27 29 30\n24 19 36\n32 11 44\n23 21 35\n33 16 40\n22 19 37\n34 19 37\n21 17 38\n35 15 41\n20 1 55\n27 14 26\n36 8 48\n27 31 38\n19 13 43\n37 13 43\n18 1 55\n38 15 40\n17 4 52\n39 15 40\n16 6 49\n28 9 23\n40 13 42\n28 33 50\n25 34 36\n15 5 51\n41 8 47\n25 6 21\n14 8 48\n25 37 37\n27 39 43\n42 12 43\n13 4 52\n43 3 53\n12 21 35\n44 14 42\n11 7 49\n45 1 54\n10 16 39\n46 13 42\n9 3 53\n47 2 53\n8 11 44\n48 12 44\n7 13 43\n49 3 53\n23 8 20\n23 3...", "29 27 31\n28 20 38\n30 4 53\n27 2 56\n31 20 37\n26 2 55\n32 14 43\n25 1 56\n33 2 55\n24 21 36\n34 7 50\n23 5 53\n29 17 26\n35 6 52\n29 32 37\n22 16 41\n36 27 31\n21 15 42\n37 3 54\n20 15 42\n38 26 31\n19 24 34\n29 38 38\n39 17 41\n18 26 31\n40 8 50\n17 11 46\n41 17 40\n16 5 52\n42 12 45\n15 4 53\n43 6 51\n14 17 40\n29 39 47\n44 12 46\n36 10 26\n36 32 41\n13 15 42\n28 1 19\n28 39 43\n45 18 40\n12 8 50\n46 2 56\n38 32 56\n11 5 52\n47 8 49\n31 38 52\n31 14 19\n24 37 38\n10 16 41\n48 7 51\n29 11 16\n38 4 25\n1...", "30 6 53\n29 24 36\n31 1 59\n28 5 55\n32 3 56\n27 28 32\n33 13 47\n26 12 47\n34 22 37\n25 18 42\n35 21 38\n24 1 59\n36 26 34\n23 9 50\n37 1 58\n27 27 27\n22 4 56\n38 24 35\n21 21 39\n27 33 41\n39 3 56\n27 22 26\n20 5 55\n40 9 50\n19 8 52\n41 23 37\n29 20 23\n18 13 47\n42 14 46\n29 37 55\n17 12 47\n43 9 50\n16 23 36\n44 7 52\n15 10 50\n36 13 25\n36 35 41\n45 22 38\n14 9 51\n46 9 51\n13 12 47\n27 15 21\n47 18 41\n12 10 49\n48 10 49\n29 19 19\n11 9 51\n34 38 41\n49 9 50\n29 15 18\n10 12 48\n50 5 55\n9 2 57\n34...", "31 17 45\n30 18 44\n32 4 57\n29 5 56\n33 24 38\n28 28 34\n34 26 36\n27 4 58\n35 30 32\n26 22 40\n36 7 54\n25 5 56\n37 2 59\n24 13 48\n38 11 51\n23 19 43\n39 17 45\n22 21 40\n40 17 44\n35 26 29\n21 3 59\n41 6 56\n35 33 52\n28 12 27\n20 11 50\n28 35 48\n42 24 38\n19 18 43\n43 3 59\n34 24 25\n18 18 44\n34 37 53\n44 12 50\n33 11 23\n33 39 51\n17 6 55\n45 20 42\n16 3 58\n35 21 25\n46 1 60\n15 11 51\n34 15 23\n47 20 42\n14 7 55\n48 14 47\n13 14 47\n49 21 41\n12 11 51\n50 11 51\n11 20 42\n51 19 42\n26 15 21\n10 1...", "32 14 50\n31 3 60\n33 21 42\n30 2 62\n34 30 33\n29 20 43\n35 13 51\n28 21 43\n36 31 33\n27 29 35\n37 6 57\n34 34 42\n26 13 51\n38 16 48\n25 18 45\n39 3 60\n24 10 53\n40 16 47\n23 19 44\n41 9 54\n22 7 57\n34 20 29\n36 13 30\n36 34 47\n27 27 28\n42 16 48\n21 14 49\n43 8 55\n20 2 61\n44 10 54\n19 21 43\n45 17 47\n18 1 62\n46 13 51\n27 36 57\n17 3 61\n47 6 58\n27 19 26\n16 10 54\n48 1 63\n15 8 56\n49 14 50\n14 7 56\n33 43 46\n33 14 20\n50 16 47\n34 43 55\n13 1 62\n51 20 43\n12 18 46\n52 4 60\n11 12 51\n53 19 4...", "33 23 42\n32 14 52\n34 27 38\n31 18 48\n35 25 40\n30 8 58\n36 4 61\n29 26 40\n37 30 36\n28 15 51\n38 4 61\n27 14 52\n39 14 52\n26 11 54\n40 12 54\n25 6 60\n41 4 62\n24 3 63\n42 27 39\n23 22 43\n43 21 45\n34 39 51\n34 19 26\n22 20 45\n37 27 29\n44 6 60\n21 19 46\n45 11 55\n20 20 46\n46 20 46\n37 37 55\n19 4 62\n47 2 64\n33 43 55\n35 41 54\n18 10 55\n33 16 22\n48 15 50\n35 5 24\n37 18 26\n17 18 47\n49 15 51\n16 2 64\n29 14 25\n50 16 49\n15 4 62\n51 8 57\n14 17 49\n52 1 65\n13 5 60\n29 41 45\n34 2 18\n42 10 2...", "34 1 66\n33 28 39\n35 33 34\n32 10 58\n36 3 64\n31 3 65\n37 5 63\n30 27 40\n38 28 40\n29 21 46\n39 27 41\n28 22 46\n40 23 44\n35 35 50\n27 18 50\n41 8 59\n35 18 32\n26 27 40\n42 28 40\n25 18 50\n33 40 48\n43 29 38\n24 8 60\n44 20 47\n23 26 42\n45 21 47\n22 25 42\n46 15 53\n21 17 51\n47 2 65\n33 27 27\n20 5 63\n48 18 50\n33 3 26\n19 1 66\n49 2 65\n30 41 44\n38 26 27\n38 41 44\n30 22 26\n18 23 44\n38 17 25\n50 8 59\n17 16 51\n51 12 55\n16 6 62\n52 3 64\n39 24 26\n15 8 59\n39 42 62\n53 3 64\n14 7 61\n43 39 63...", "35 14 56\n34 11 59\n36 13 56\n33 1 68\n37 25 44\n32 2 68\n38 13 57\n31 9 61\n39 8 62\n30 2 68\n40 1 68\n29 19 50\n41 20 50\n28 32 37\n42 29 41\n27 1 69\n43 26 43\n26 25 44\n44 22 47\n25 33 37\n45 32 37\n24 23 46\n46 12 57\n23 29 41\n47 7 63\n28 38 45\n22 30 40\n48 26 44\n21 22 48\n49 12 57\n20 18 51\n50 19 50\n28 22 31\n19 12 58\n51 21 48\n18 2 67\n52 10 59\n17 11 59\n53 20 50\n37 45 69\n16 8 61\n54 2 68\n25 8 32\n25 38 64\n37 14 24\n45 38 63\n15 15 55\n55 17 52\n14 3 66\n56 8 62\n13 14 56\n42 20 28\n57 3 ..."]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
6b5c9fda8d18efd41bd1e2f20140d0ed
Mind the Gap
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides. Find the earliest time when Arkady can insert the takeoff. The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order. Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. Sample Input 6 60 0 0 1 20 3 21 5 0 19 30 23 40 16 50 0 30 1 20 3 0 4 30 6 10 7 50 9 30 11 10 12 50 14 30 16 10 17 50 19 30 21 10 22 50 23 59 3 17 0 30 1 0 12 0 Sample Output 6 1 24 50 0 0
{"inputs": ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0", "24 60\n0 21\n2 21\n2 46\n3 17\n4 15\n5 43\n6 41\n7 50\n8 21\n9 8\n10 31\n10 45\n12 30\n14 8\n14 29\n14 32\n14 52\n15 16\n16 7\n16 52\n18 44\n20 25\n21 13\n22 7", "20 60\n0 9\n0 19\n0 57\n2 42\n3 46\n3 47\n5 46\n8 1\n9 28\n9 41\n10 54\n12 52\n13 0\n14 49\n17 28\n17 39\n19 34\n20 52\n21 35\n23 22", "57 20\n0 2\n0 31\n1 9\n1 42\n1 58\n2 4\n2 35\n2 49\n3 20\n3 46\n4 23\n4 52\n5 5\n5 39\n6 7\n6 48\n6 59\n7 8\n7 35\n8 10\n8 46\n8 53\n9 19\n9 33\n9 43\n10 18\n10 42\n11 0\n11 26\n12 3\n12 5\n12 30\n13 1\n13 38\n14 13\n14 54\n15 31\n16 5\n16 44\n17 18\n17 30\n17 58\n18 10\n18 34\n19 13\n19 49\n19 50\n19 59\n20 17\n20 23\n20 40\n21 18\n21 57\n22 31\n22 42\n22 56\n23 37", "66 20\n0 16\n0 45\n0 58\n1 6\n1 19\n2 7\n2 9\n3 9\n3 25\n3 57\n4 38\n4 58\n5 21\n5 40\n6 16\n6 19\n6 58\n7 6\n7 26\n7 51\n8 13\n8 36\n8 55\n9 1\n9 15\n9 33\n10 12\n10 37\n11 15\n11 34\n12 8\n12 37\n12 55\n13 26\n14 0\n14 34\n14 36\n14 48\n15 23\n15 29\n15 43\n16 8\n16 41\n16 45\n17 5\n17 7\n17 15\n17 29\n17 46\n18 12\n18 19\n18 38\n18 57\n19 32\n19 58\n20 5\n20 40\n20 44\n20 50\n21 18\n21 49\n22 18\n22 47\n23 1\n23 38\n23 50", "1 1\n0 0", "10 1\n0 2\n0 4\n0 5\n0 8\n0 9\n0 11\n0 13\n0 16\n0 19\n0 21", "10 1\n0 2\n0 5\n0 8\n0 11\n0 15\n0 17\n0 25\n0 28\n0 29\n0 32", "15 20\n0 47\n2 24\n4 19\n4 34\n5 46\n8 15\n9 8\n10 28\n17 47\n17 52\n18 32\n19 50\n20 46\n20 50\n23 21", "1 5\n1 0", "24 60\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59", "1 30\n0 29", "1 2\n3 0", "16 60\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "1 5\n0 6", "2 60\n0 59\n23 59", "1 58\n0 1", "25 60\n0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59", "2 3\n0 3\n0 30", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 9", "1 60\n2 0", "2 60\n0 0\n5 0", "1 30\n0 31", "2 60\n0 59\n3 1", "2 60\n0 59\n5 0", "1 59\n0 0", "3 25\n0 0\n1 0\n2 0", "1 2\n2 3"], "outputs": ["6 1", "24 50", "0 0", "23 8", "6 47", "23 58", "1 40", "0 2", "0 0", "0 0", "0 0", "0 0", "25 0", "1 0", "0 0", "25 0", "0 0", "2 0", "1 0", "25 0", "0 7", "24 0", "0 0", "1 1", "0 0", "2 0", "2 0", "1 0", "0 26", "0 0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
85
codeforces
6b803dbd74756c7a0ce25de8e96ff2e5
A Compatible Pair
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally. The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109. Print a single integer — the brightness of the chosen pair. Sample Input 2 2 20 18 2 14 5 3 -1 0 1 2 3 -1 0 1 Sample Output 252 2
{"inputs": ["2 2\n20 18\n2 14", "5 3\n-1 0 1 2 3\n-1 0 1", "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7", "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6", "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611", "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974", "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410", "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682", "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106", "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544", "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617", "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478", "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867", "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081", "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625", "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542", "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604", "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017", "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528", "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396", "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983", "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000"], "outputs": ["252", "2", "70", "100", "127184126241438168", "922371547895579571", "663200522440413120", "883931400924882950", "910849554065102112", "504117593849498724", "534123411186652380", "848714444125692276", "866064226130454915", "501307028237810934", "822104826327386019", "941783658451562540", "-1288212069119760", "-18990884587723", "-1464096896176096", "-120782803247464704", "-640647347631440", "-1000000000000000000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
92
codeforces
6b871f4add35d8a08ea4c61c04c0b5d4
Mishka and trip
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country. Here are some interesting facts about XXX: 1. XXX consists of *n* cities, *k* of whose (just imagine!) are capital cities. 1. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of *i*-th city equals to *c**i*. 1. All the cities are consecutively connected by the roads, including 1-st and *n*-th city, forming a cyclic route 1<=—<=2<=—<=...<=—<=*n*<=—<=1. Formally, for every 1<=≤<=*i*<=&lt;<=*n* there is a road between *i*-th and *i*<=+<=1-th city, and another one between 1-st and *n*-th city. 1. Each capital city is connected with each other city directly by the roads. Formally, if city *x* is a capital city, then for every 1<=≤<=*i*<=≤<=*n*,<=<=*i*<=≠<=*x*, there is a road between cities *x* and *i*. 1. There is at most one road between any two cities. 1. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities *i* and *j*, price of passing it equals *c**i*·*c**j*. Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities *a* and *b* (*a*<=&lt;<=*b*), such that there is a road between *a* and *b* you are to find sum of products *c**a*·*c**b*. Will you help her? The first line of the input contains two integers *n* and *k* (3<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*<=≤<=*n*) — the number of cities in XXX and the number of capital cities among them. The second line of the input contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=10<=000) — beauty values of the cities. The third line of the input contains *k* distinct integers *id*1,<=*id*2,<=...,<=*id**k* (1<=≤<=*id**i*<=≤<=*n*) — indices of capital cities. Indices are given in ascending order. Print the only integer — summary price of passing each of the roads in XXX. Sample Input 4 1 2 3 1 2 3 5 2 3 5 2 2 4 1 4 Sample Output 1771
{"inputs": ["4 1\n2 3 1 2\n3", "5 2\n3 5 2 2 4\n1 4", "3 1\n1 1 1\n1", "3 3\n1 1 1\n1 2 3", "7 7\n6 9 2 7 4 8 7\n1 2 3 4 5 6 7", "5 5\n6 2 4 10 2\n1 2 3 4 5", "5 5\n6 7 8 8 8\n1 2 3 4 5", "9 4\n5 6 7 1 5 4 8 7 1\n1 5 7 9", "7 2\n1 6 8 3 3 5 5\n1 3", "9 4\n182 938 865 240 911 25 373 22 875\n3 6 7 8", "10 4\n7931 7116 4954 8578 847 6206 5398 4103 7814 1245\n1 3 5 7", "9 7\n341 106 584 605 495 512 66 992 713\n1 4 5 6 7 8 9", "8 2\n43 2961 202 2637 1007 4469 9031 9900\n4 7", "8 5\n751 782 792 243 111 161 746 331\n1 3 4 6 8", "8 4\n733 7990 4777 3024 7627 2283 4959 1698\n1 3 5 7", "8 6\n736 620 367 629 539 975 867 937\n1 2 5 6 7 8", "6 2\n9436 8718 315 2056 4898 7352\n4 6", "6 1\n916 913 649 645 312 968\n6", "6 2\n6703 5345 9335 5285 1268 5207\n3 6", "51 3\n834 817 726 282 783 437 729 423 444 422 692 522 479 27 744 955 634 885 280 839 851 781 555 286 761 459 245 494 709 464 470 254 862 597 409 276 372 746 135 464 742 400 970 766 388 351 474 104 702 945 835\n12 28 29", "52 17\n5281 7307 2542 1181 6890 5104 5081 4658 9629 6973 3504 4423 3184 6012 2538 6778 9611 3163 1907 4489 4923 685 5753 2553 5986 520 192 8643 4805 6469 5311 3074 2045 6836 6993 7126 1415 6149 9093 9635 6004 1983 7263 3171 4378 9436 9813 6464 8656 3819 130 763\n1 5 7 9 11 13 16 19 21 23 35 38 40 42 47 49 51", "76 45\n29 219 740 819 616 699 8 557 969 550 66 259 615 101 560 640 75 632 752 598 820 714 418 858 669 819 456 597 290 956 461 941 359 318 155 378 257 292 699 249 306 676 890 292 25 225 22 520 776 268 397 438 468 239 174 508 265 216 933 857 564 165 59 779 526 826 597 77 704 420 688 1 689 769 323 98\n1 2 3 5 7 8 10 12 14 15 17 18 22 23 25 26 28 30 31 33 34 35 36 37 38 40 43 44 46 47 52 53 55 56 58 60 61 62 63 64 66 69 71 72 73", "76 24\n6814 3834 1131 6256 2598 850 7353 1702 5773 1699 35 5103 1368 2258 7891 7455 8546 7316 7428 8864 6536 5750 8455 2624 7326 2197 8239 3806 3016 7126 85 3249 1138 6783 9684 4417 7417 3660 6334 7324 9760 9755 7605 9891 3676 8784 8739 8266 3272 9250 5875 939 4130 6540 7813 6867 9148 781 6190 964 5612 1864 949 7826 9148 6293 4936 870 2042 5838 7141 2030 1241 259 5617 2539\n3 5 9 12 15 18 20 23 25 29 31 33 35 37 39 44 46 48 59 63 65 68 72 76", "50 15\n915 8535 2997 4040 9747 2161 9628 8364 1943 136 1403 7037 9713 7741 7463 4316 1543 994 7320 95 6211 8110 2713 5806 7652 6749 3996 2886 8971 6878 1267 9546 1551 6835 9256 5725 9609 1748 8246 6169 9465 4620 9565 1419 3327 1003 9938 9556 882 6178\n3 8 10 12 15 18 22 24 27 29 33 37 41 43 46", "73 27\n651 944 104 639 369 961 338 573 516 690 889 227 480 160 299 783 270 331 793 796 64 712 649 88 695 550 829 303 965 780 570 374 371 506 954 632 660 987 986 253 144 993 708 710 890 257 303 651 923 107 386 893 301 387 852 596 72 699 63 241 336 855 160 5 981 447 601 601 305 680 448 676 374\n1 3 4 5 6 11 17 18 19 20 27 29 32 33 40 43 46 47 48 53 55 57 61 62 63 67 71", "74 27\n8668 693 205 9534 6686 9598 2837 3425 8960 3727 8872 4393 4835 8438 7881 3591 7914 5218 8959 7342 7134 8170 1778 5107 3467 6998 9506 3635 8929 2004 49 701 5059 7285 5236 1540 7643 365 229 2062 7732 3142 7668 8871 2783 7309 529 1695 4255 8084 2708 6936 8300 4015 1142 3705 8564 1031 1685 9262 5077 3674 4788 4981 4693 9896 792 322 5482 584 3852 3484 9410 3889\n1 4 6 12 16 19 21 23 26 29 31 33 36 39 41 43 46 48 51 53 55 58 61 64 67 69 73", "3 1\n1 2 3\n3"], "outputs": ["17", "71", "3", "3", "775", "208", "546", "647", "255", "4972597", "836854437", "8322420", "246280951", "5635386", "382022214", "13910835", "319961666", "5373770", "361632002", "62712861", "20412478312", "508857909", "43060198680", "19733750400", "460505110", "41845373785", "11"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
6ba63d2f5d8138cc02354cc2aa491aa6
Watermelon
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Sample Input 8 Sample Output YES
{"inputs": ["8", "5", "4", "3", "2", "1", "7", "6", "10", "9", "53", "77", "32", "44", "98", "99", "90", "67", "100", "88"], "outputs": ["YES", "NO", "YES", "NO", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "YES", "NO", "YES", "NO", "YES", "YES"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
693
codeforces
6bf60cd692f741caed0e551b1119e8ec
Devu, the Singer and Churu, the Joker
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly. People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest. You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions: - The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event. The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. Sample Input 3 30 2 2 1 3 20 2 1 1 Sample Output 5 -1
{"inputs": ["3 30\n2 2 1", "3 20\n2 1 1", "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "50 10000\n4 7 15 9 11 12 20 9 14 14 10 13 6 13 14 17 6 8 20 12 10 15 13 17 5 12 13 11 7 5 5 2 3 15 13 7 14 14 19 2 13 14 5 15 3 19 15 16 4 1", "100 9000\n5 2 3 1 1 3 4 9 9 6 7 10 10 10 2 10 6 8 8 6 7 9 9 5 6 2 1 10 10 9 4 5 9 2 4 3 8 5 6 1 1 5 3 6 2 6 6 6 5 8 3 6 7 3 1 10 9 1 8 3 10 9 5 6 3 4 1 1 10 10 2 3 4 8 10 10 5 1 5 3 6 8 10 6 10 2 1 8 10 1 7 6 9 10 5 2 3 5 3 2", "100 8007\n5 19 14 18 9 6 15 8 1 14 11 20 3 17 7 12 2 6 3 17 7 20 1 14 20 17 2 10 13 7 18 18 9 10 16 8 1 11 11 9 13 18 9 20 12 12 7 15 12 17 11 5 11 15 9 2 15 1 18 3 18 16 15 4 10 5 18 13 13 12 3 8 17 2 12 2 13 3 1 13 2 4 9 10 18 10 14 4 4 17 12 19 2 9 6 5 5 20 18 12", "39 2412\n1 1 1 1 1 1 26 1 1 1 99 1 1 1 1 1 1 1 1 1 1 88 7 1 1 1 1 76 1 1 1 93 40 1 13 1 68 1 32", "39 2617\n47 1 1 1 63 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 70 1 99 63 1 1 1 1 1 1 1 1 64 1 1", "39 3681\n83 77 1 94 85 47 1 98 29 16 1 1 1 71 96 85 31 97 96 93 40 50 98 1 60 51 1 96 100 72 1 1 1 89 1 93 1 92 100", "45 894\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 28 28 1 1 1 1 1 1 1 1 1 1 1 1 1 1 99 3 1 1", "45 4534\n1 99 65 99 4 46 54 80 51 30 96 1 28 30 44 70 78 1 1 100 1 62 1 1 1 85 1 1 1 61 1 46 75 1 61 77 97 26 67 1 1 63 81 85 86", "72 3538\n52 1 8 1 1 1 7 1 1 1 1 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 40 1 1 38 1 1 1 1 1 1 1 1 1 1 1 35 1 93 79 1 1 1 1 1 1 1 1 1 51 1 1 1 1 1 1 1 1 1 1 1 1 96 1", "81 2200\n1 59 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 93 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 1 1 1 1", "81 2577\n85 91 1 1 2 1 1 100 1 80 1 1 17 86 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 37 1 66 24 1 1 96 49 1 66 1 44 1 1 1 1 98 1 1 1 1 35 1 37 3 35 1 1 87 64 1 24 1 58 1 1 42 83 5 1 1 1 1 1 95 1 94 1 50 1 1", "81 4131\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 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "81 6315\n1 1 67 100 1 99 36 1 92 5 1 96 42 12 1 57 91 1 1 66 41 30 74 95 1 37 1 39 91 69 1 52 77 47 65 1 1 93 96 74 90 35 85 76 71 92 92 1 1 67 92 74 1 1 86 76 35 1 56 16 27 57 37 95 1 40 20 100 51 1 80 60 45 79 95 1 46 1 25 100 96", "96 1688\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 71 1 1 1 30 1 1 1", "96 8889\n1 1 18 1 1 1 1 1 1 1 1 1 99 1 1 1 1 88 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 96 1 1 1 1 21 1 1 1 1 1 1 1 73 1 1 1 1 1 10 1 1 1 1 1 1 1 46 43 1 1 1 1 1 98 1 1 1 1 1 1 6 1 1 1 1 1 74 1 25 1 55 1 1 1 13 1 1 54 1 1 1", "10 100\n1 1 1 1 1 1 1 1 1 1", "100 10000\n54 46 72 94 79 83 91 54 73 3 24 55 54 31 28 20 19 6 25 19 47 23 1 70 15 87 51 39 54 77 55 5 60 3 15 99 56 88 22 78 79 21 38 27 28 86 7 88 12 59 55 70 25 1 70 49 1 45 69 72 50 17 4 56 8 100 90 34 35 20 61 76 88 79 4 74 65 68 75 26 40 72 59 94 10 67 96 85 29 90 47 24 44 1 66 93 55 36 1 99", "100 6000\n41 31 23 17 24 78 26 96 93 48 46 2 49 33 35 9 73 100 34 48 83 36 33 69 43 24 3 74 8 81 27 33 94 38 77 9 76 90 62 90 21 67 22 22 12 2 17 27 61 18 72 85 59 65 71 38 90 75 74 66 60 47 58 50 90 95 75 10 5 100 97 29 83 88 65 26 93 90 22 98 36 55 70 38 50 92 88 72 99 96 25 14 74 16 25 92 67 94 77 96", "1 1\n1", "1 6\n1", "1 5\n1", "1 3\n4", "3 24\n2 1 2"], "outputs": ["5", "-1", "1943", "1891", "1688", "1391", "368", "435", "326", "139", "514", "586", "384", "174", "807", "490", "284", "1589", "18", "1017", "-1", "0", "1", "0", "-1", "-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
471
codeforces
6c1dc382c40cf5b2c5380259ad2c0879
Dima and Containers
Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck. Inna wants her present to show Dima how great a programmer he is. For that, she is going to give Dima commands one by one. There are two types of commands: 1. Add a given number into one of containers. For the queue and the stack, you can add elements only to the end. For the deck, you can add elements to the beginning and to the end. 1. Extract a number from each of at most three distinct containers. Tell all extracted numbers to Inna and then empty all containers. In the queue container you can extract numbers only from the beginning. In the stack container you can extract numbers only from the end. In the deck number you can extract numbers from the beginning and from the end. You cannot extract numbers from empty containers. Every time Dima makes a command of the second type, Inna kisses Dima some (possibly zero) number of times. Dima knows Inna perfectly well, he is sure that this number equals the sum of numbers he extracts from containers during this operation. As we've said before, Dima knows Inna perfectly well and he knows which commands Inna will give to Dima and the order of the commands. Help Dima find the strategy that lets him give as more kisses as possible for his birthday! The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of Inna's commands. Then *n* lines follow, describing Inna's commands. Each line consists an integer: 1. Integer *a* (1<=≤<=*a*<=≤<=105) means that Inna gives Dima a command to add number *a* into one of containers. 1. Integer 0 shows that Inna asks Dima to make at most three extractions from different containers. Each command of the input must correspond to one line of the output — Dima's action. For the command of the first type (adding) print one word that corresponds to Dima's choice: - pushStack — add to the end of the stack; - pushQueue — add to the end of the queue; - pushFront — add to the beginning of the deck; - pushBack — add to the end of the deck. For a command of the second type first print an integer *k* (0<=≤<=*k*<=≤<=3), that shows the number of extract operations, then print *k* words separated by space. The words can be: - popStack — extract from the end of the stack; - popQueue — extract from the beginning of the line; - popFront — extract from the beginning from the deck; - popBack — extract from the end of the deck. The printed operations mustn't extract numbers from empty containers. Also, they must extract numbers from distinct containers. The printed sequence of actions must lead to the maximum number of kisses. If there are multiple sequences of actions leading to the maximum number of kisses, you are allowed to print any of them. Sample Input 10 0 1 0 1 2 0 1 2 3 0 4 1 2 3 0 Sample Output 0 pushStack 1 popStack pushStack pushQueue 2 popStack popQueue pushStack pushQueue pushFront 3 popStack popQueue popFront pushStack pushQueue pushFront 3 popStack popQueue popFront
{"inputs": ["10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "4\n1\n2\n3\n0", "2\n0\n1", "5\n1\n1\n1\n2\n1", "5\n3\n2\n3\n1\n0", "49\n8735\n95244\n50563\n33648\n10711\n30217\n49166\n28240\n0\n97232\n12428\n16180\n58610\n61112\n74423\n56323\n43327\n0\n12549\n48493\n43086\n69266\n27033\n37338\n43900\n5570\n25293\n44517\n7183\n41969\n31944\n32247\n96959\n44890\n98237\n52601\n29081\n93641\n14980\n29539\n84672\n57310\n91014\n31721\n6944\n67672\n22040\n86269\n86709", "55\n73792\n39309\n73808\n47389\n34803\n87947\n32460\n14649\n70151\n35816\n8272\n78886\n71345\n61907\n16977\n85362\n0\n43792\n8118\n83254\n89459\n32230\n87068\n82617\n94847\n83528\n37629\n31438\n97413\n62260\n13651\n47564\n43543\n61292\n51025\n64106\n0\n19282\n35422\n19657\n95170\n10266\n43771\n3190\n93962\n11747\n43021\n91531\n88370\n1760\n10950\n77059\n61741\n52965\n10445", "10\n1\n2\n3\n5\n4\n9\n8\n6\n7\n0", "10\n1\n3\n4\n2\n6\n8\n5\n7\n10\n9", "1\n0"], "outputs": ["0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront", "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront", "0\npushQueue", "pushQueue\npushQueue\npushQueue\npushQueue\npushQueue", "pushStack\npushQueue\npushFront\npushBack\n3 popStack popQueue popFront", "pushBack\npushStack\npushQueue\npushBack\npushBack\npushBack\npushFront\npushBack\n3 popStack popQueue popFront\npushStack\npushBack\npushBack\npushBack\npushQueue\npushFront\npushBack\npushBack\n3 popStack popQueue popFront\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\n...", "pushBack\npushBack\npushBack\npushBack\npushBack\npushStack\npushBack\npushBack\npushBack\npushBack\npushBack\npushQueue\npushBack\npushBack\npushBack\npushFront\n3 popStack popQueue popFront\npushBack\npushBack\npushBack\npushStack\npushBack\npushBack\npushBack\npushQueue\npushBack\npushBack\npushBack\npushFront\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\npushBack\n3 popStack popQueue popFront\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQue...", "pushBack\npushBack\npushBack\npushBack\npushBack\npushStack\npushQueue\npushBack\npushFront\n3 popStack popQueue popFront", "pushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue\npushQueue", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
6c50edebb128b0ef825474bcdce42054
Find The Bone
Zane the wizard is going to perform a magic show shuffling the cups. There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*. The problematic bone is initially at the position *x*<==<=1. Zane will confuse the audience by swapping the cups *k* times, the *i*-th time of which involves the cups at the positions *x*<==<=*u**i* and *x*<==<=*v**i*. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations. Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at *x*<==<=4 and the one at *x*<==<=6, they will not be at the position *x*<==<=5 at any moment during the operation. Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone. The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively. The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*n*) — the positions along the *x*-axis where there is a hole on the table. Each of the next *k* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the positions of the cups to be swapped. Print one integer — the final position along the *x*-axis of the bone. Sample Input 7 3 4 3 4 6 1 2 2 5 5 7 7 1 5 1 2 2 1 2 2 4 Sample Output 12
{"inputs": ["7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1", "5 1 2\n2\n1 2\n2 4", "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11", "100000 3 7\n2 3 4\n1 5\n5 1\n1 5\n5 1\n1 4\n4 3\n3 2", "1000000 9 11\n38 59 999999 199 283 4849 1000000 2 554\n39 94\n3 9\n1 39\n39 40\n40 292\n5399 5858\n292 49949\n49949 222\n222 38\n202 9494\n38 59", "1000000 11 9\n19 28 39 82 99 929384 8298 892849 202020 777777 123123\n19 28\n28 39\n1 123124\n39 28\n28 99\n99 8298\n123124 123122\n2300 3200\n8298 1000000", "2 1 1\n1\n1 2", "7 3 6\n1 4 5\n1 2\n2 3\n3 5\n4 5\n4 5\n4 5", "10 3 8\n1 5 10\n1 2\n2 3\n3 4\n3 4\n3 4\n4 5\n5 6\n6 5", "5 2 9\n2 4\n1 3\n3 5\n3 5\n3 4\n4 2\n2 4\n1 4\n1 2\n1 4", "10 10 13\n1 2 3 4 5 6 7 8 9 10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n6 7\n6 10\n10 9\n9 1\n1 10\n1 10\n1 10", "3 3 3\n1 2 3\n1 2\n2 3\n3 2", "100 7 7\n17 27 37 47 57 67 77\n49 39\n55 1\n50 3\n89 1\n1 99\n100 55\n98 55", "9 1 9\n9\n1 2\n3 2\n4 3\n8 9\n4 5\n7 4\n8 5\n1 3\n3 2", "300000 1 1\n200000\n300000 1", "203948 2 14\n203948 203946\n39 38\n4959 3030\n1 203947\n2929 9292\n203944 203948\n203947 203944\n203944 203922\n203922 203948\n2495 20495\n29419 5959\n12949 12\n49 29292\n1 94\n1 203", "203948 2 14\n203948 203947\n39 38\n4959 3030\n1 203947\n2929 9292\n203944 203948\n203947 203944\n203944 203922\n203922 203948\n2495 20495\n29419 5959\n12949 12\n49 29292\n1 94\n1 203", "100 2 5\n1 2\n2 39\n39 29\n99 100\n1 2\n2 39", "3 1 1\n1\n1 2", "5 2 2\n1 2\n1 2\n2 3", "2 2 1\n1 2\n2 1", "5 2 1\n1 2\n2 1", "5 1 1\n5\n3 4", "3 2 1\n1 2\n2 1", "5 1 2\n2\n2 1\n2 3", "3 1 2\n2\n2 1\n2 3", "3 2 2\n2 3\n2 1\n2 3", "4 2 1\n1 2\n2 1", "4 1 1\n2\n2 3", "3 2 1\n1 3\n3 1", "10 1 3\n2\n2 1\n2 4\n9 10", "5 2 4\n3 5\n1 2\n4 2\n3 4\n3 5", "4 3 1\n1 2 3\n2 1"], "outputs": ["1", "2", "55", "4", "38", "123122", "1", "1", "1", "4", "1", "1", "100", "8", "300000", "203948", "203947", "1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "1", "1", "1", "2", "3", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
50
codeforces
6c621b042edda2efa0b07e0276d2de62
Ilya and Diplomas
Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there. At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma. They also decided that there must be given at least *min*1 and at most *max*1 diplomas of the first degree, at least *min*2 and at most *max*2 diplomas of the second degree, and at least *min*3 and at most *max*3 diplomas of the third degree. After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree. Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations. It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all *n* participants of the Olympiad will receive a diploma of some degree. The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=3·106) — the number of schoolchildren who will participate in the Olympiad. The next line of the input contains two integers *min*1 and *max*1 (1<=≤<=*min*1<=≤<=*max*1<=≤<=106) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed. The third line of the input contains two integers *min*2 and *max*2 (1<=≤<=*min*2<=≤<=*max*2<=≤<=106) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed. The next line of the input contains two integers *min*3 and *max*3 (1<=≤<=*min*3<=≤<=*max*3<=≤<=106) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed. It is guaranteed that *min*1<=+<=*min*2<=+<=*min*3<=≤<=*n*<=≤<=*max*1<=+<=*max*2<=+<=*max*3. In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas. The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree. Sample Input 6 1 5 2 6 3 7 10 1 2 1 3 1 5 6 1 3 2 2 2 2 Sample Output 1 2 3 2 3 5 2 2 2
{"inputs": ["6\n1 5\n2 6\n3 7", "10\n1 2\n1 3\n1 5", "6\n1 3\n2 2\n2 2", "55\n1 1000000\n40 50\n10 200", "3\n1 1\n1 1\n1 1", "3\n1 1000000\n1 1000000\n1 1000000", "1000\n100 400\n300 500\n400 1200", "3000000\n1 1000000\n1 1000000\n1 1000000", "11\n3 5\n3 5\n3 5", "12\n3 5\n3 5\n3 5", "13\n3 5\n3 5\n3 5", "3000000\n1000000 1000000\n1000000 1000000\n1000000 1000000", "50\n1 100\n1 100\n1 100", "1279\n123 670\n237 614\n846 923", "1589\n213 861\n5 96\n506 634", "2115\n987 987\n112 483\n437 959", "641\n251 960\n34 370\n149 149", "1655\n539 539\n10 425\n605 895", "1477\n210 336\n410 837\n448 878", "1707\n149 914\n190 422\n898 899", "1529\n515 515\n563 869\n169 451", "1543\n361 994\n305 407\n102 197", "1107\n471 849\n360 741\n71 473", "1629279\n267360 999930\n183077 674527\n202618 786988", "1233589\n2850 555444\n500608 921442\n208610 607343", "679115\n112687 183628\n101770 982823\n81226 781340", "1124641\n117999 854291\n770798 868290\n76651 831405", "761655\n88152 620061\n60403 688549\n79370 125321", "2174477\n276494 476134\n555283 954809\n319941 935631", "1652707\n201202 990776\n34796 883866\n162979 983308", "2065529\n43217 891429\n434379 952871\n650231 855105", "1702543\n405042 832833\n50931 747750\n381818 796831", "501107\n19061 859924\n126478 724552\n224611 489718", "1629279\n850831 967352\n78593 463906\n452094 885430", "1233589\n2850 157021\n535109 748096\n392212 475634", "679115\n125987 786267\n70261 688983\n178133 976789", "1124641\n119407 734250\n213706 860770\n102149 102149", "761655\n325539 325539\n280794 792505\n18540 106895", "2174477\n352351 791072\n365110 969163\n887448 955610", "1652707\n266774 638522\n65688 235422\n924898 992826", "2065529\n608515 608515\n751563 864337\n614898 705451", "1702543\n5784 996578\n47395 300407\n151614 710197", "501107\n8073 390048\n190494 647328\n274071 376923", "200\n50 50\n100 100\n50 50", "14\n1 100\n1 100\n8 9", "300\n200 400\n50 100\n40 80", "10\n3 6\n3 6\n3 6", "14\n3 6\n3 6\n3 6", "17\n3 6\n3 6\n3 6", "1000000\n300000 600000\n300000 600000\n300000 600000", "1400000\n300000 600000\n300000 600000\n300000 600000", "1700000\n300000 600000\n300000 600000\n300000 600000", "561\n400 400\n80 80\n81 81", "2000\n100 1000\n1 1\n1 2000", "1000002\n1 1000000\n1 1000000\n999999 1000000", "1000002\n1 1000000\n1 1000000\n1000000 1000000"], "outputs": ["1 2 3 ", "2 3 5 ", "2 2 2 ", "5 40 10 ", "1 1 1 ", "1 1 1 ", "300 300 400 ", "1000000 1000000 1000000 ", "5 3 3 ", "5 4 3 ", "5 5 3 ", "1000000 1000000 1000000 ", "48 1 1 ", "196 237 846 ", "861 96 632 ", "987 483 645 ", "458 34 149 ", "539 425 691 ", "336 693 448 ", "619 190 898 ", "515 845 169 ", "994 407 142 ", "676 360 71 ", "999930 426731 202618 ", "524371 500608 208610 ", "183628 414261 81226 ", "277192 770798 76651 ", "620061 62224 79370 ", "476134 954809 743534 ", "990776 498952 162979 ", "891429 523869 650231 ", "832833 487892 381818 ", "150018 126478 224611 ", "967352 209833 452094 ", "157021 684356 392212 ", "430721 70261 178133 ", "734250 288242 102149 ", "325539 417576 18540 ", "791072 495957 887448 ", "638522 89287 924898 ", "608515 842116 614898 ", "996578 300407 405558 ", "36542 190494 274071 ", "50 100 50 ", "5 1 8 ", "210 50 40 ", "4 3 3 ", "6 5 3 ", "6 6 5 ", "400000 300000 300000 ", "600000 500000 300000 ", "600000 600000 500000 ", "400 80 81 ", "1000 1 999 ", "2 1 999999 ", "1 1 1000000 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
151
codeforces
6c6b2a5d327c870946b66c611f883ca5
Array
Chris the Rabbit has been interested in arrays ever since he was a child. At the moment he is researching arrays with the length of *n*, containing only integers from 1 to *n*. He is not good at math, that's why some simple things drive him crazy. For example, yesterday he grew keen on counting how many different beautiful arrays there are. Chris thinks that an array is beautiful if it meets one of the two conditions: - each elements, starting from the second one, is no more than the preceding one - each element, starting from the second one, is no less than the preceding one Having got absolutely mad at himself and at math, Chris came to Stewie and Brian to ask them for help. However, they only laughed at him and said that the answer is too simple and not interesting. Help Chris the Rabbit to find the answer at last. The single line contains an integer *n* which is the size of the array (1<=≤<=*n*<=≤<=105). You must print the answer on a single line. As it can be rather long, you should print it modulo 1000000007. Sample Input 2 3 Sample Output 4 17
{"inputs": ["2", "3", "12", "19", "20", "26", "35", "38", "42", "82", "388", "691", "1000", "1300", "1589", "1885", "2197", "2490", "2798", "49948", "52402", "54904", "57500", "59913", "62467", "64922", "67491", "69942", "72484", "74977", "77461", "79964", "82463", "84999", "87440", "89915", "92481", "94962", "97469", "99925", "1662", "44892", "88122", "31353", "74583", "17813", "61043", "4273", "47504", "67828", "100000", "99999", "99998", "1"], "outputs": ["4", "17", "2704144", "345263536", "846527841", "529476652", "358906180", "917151454", "769030659", "105516606", "121470312", "66828054", "72474738", "13198519", "910090838", "80236682", "649466350", "150738377", "671813603", "188470824", "68720508", "917915735", "540890446", "836170548", "407412105", "124840329", "448912826", "474688044", "895032755", "502088741", "228321485", "729228388", "466136228", "200164009", "926716958", "457356022", "287683730", "44271116", "568733613", "414342728", "487795363", "657147284", "891210641", "990883671", "385361995", "54476064", "75760676", "154508332", "469586508", "564997335", "879367333", "690990293", "37611412", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
6c7887430d8f0c8d26269c0b9a7af34e
You're a Professional
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system. You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user. Output the number of items in the list liked by at least *T* of user's friends. The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*). The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise. Output an integer — the number of items liked by at least *T* of user's friends. Sample Input 3 3 2 YYY NNN YNY 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YY\nYNYY\nYNNN\nNNNN\nNYNN\nYNNN\nNNYN\nNYNN", "9 10 7\nNNYNNYYYYY\nYNYYNYYNYN\nNYNYYNNNNY\nYYYYYYYYYN\nYYNYNYYNNN\nYYYNNYYYYY\nNYYYYYNNNN\nNYNNYYYYNN\nYYYYYNNYYY", "6 4 2\nNNNN\nNYYY\nNYNN\nNYNN\nYNNY\nNNNN", "3 1 1\nN\nY\nN", "7 1 3\nY\nY\nY\nN\nY\nY\nY", "9 8 7\nNYYNNNYY\nYYYNYNNN\nYNYNYNNY\nNYYYNNNY\nNYYYYNYN\nNNNNYYNN\nYNYYYYYY\nNNYNYNYY\nNYYNNYYY", "9 5 9\nYYYYN\nYYYNN\nNNYNN\nNNYYY\nYNNNN\nNYNNN\nYYYYN\nYNYYN\nNNNYN", "8 4 1\nYYYN\nNNNN\nNYNY\nYNNY\nYNYY\nYNYN\nYNNY\nNNYN", "7 9 5\nYNNYYYYNN\nYNYYYNNYY\nYNYYYYYNN\nYYNYYNYYN\nNNYYNNNYY\nYYNYNYYNN\nYYNNYYNYN", "5 8 3\nNYYYNNNN\nYNNNNNYY\nYNYYYNYY\nNNNNNYNN\nYYYYYYYY", "5 10 4\nYYYYNNNNYN\nYYYNYYYNNY\nNNNYNYNYNY\nYNYNNNNNNY\nNNYNYNYNYY", "6 9 6\nNYYNNYNYN\nYNYNYNNNN\nNNYNNYYYY\nNNYNNNYNY\nNYYYNNYNY\nNNYYNNNYN", "4 4 1\nYNYY\nNNNY\nYNNN\nNNYN", "1 3 1\nYYN", "10 4 5\nNNYN\nYYNY\nYYNY\nNYYN\nYNYY\nYNYY\nYYNN\nYNYN\nYYYY\nYYNY"], "outputs": ["2", "4", "0", "5", "0", "0", "10", "9", "1", "0", "1", "1", "2", "6", "0", "0", "1", "6", "4", "2", "2", "1", "1", "1", "0", "4", "3", "5", "2", "1", "3", "2", "4"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
16
codeforces
6c919e2b0df67554198028b21a7e301e
First Digit Law
In the probability theory the following paradox called Benford's law is known: "In many lists of random numbers taken from real sources, numbers starting with digit 1 occur much more often than numbers starting with any other digit" (that's the simplest form of the law). Having read about it on Codeforces, the Hedgehog got intrigued by the statement and wishes to thoroughly explore it. He finds the following similar problem interesting in particular: there are *N* random variables, the *i*-th of which can take any integer value from some segment [*L**i*;*R**i*] (all numbers from this segment are equiprobable). It means that the value of the *i*-th quantity can be equal to any integer number from a given interval [*L**i*;*R**i*] with probability 1<=/<=(*R**i*<=-<=*L**i*<=+<=1). The Hedgehog wants to know the probability of the event that the first digits of at least *K*% of those values will be equal to one. In other words, let us consider some set of fixed values of these random variables and leave only the first digit (the MSD — most significant digit) of each value. Then let's count how many times the digit 1 is encountered and if it is encountered in at least *K* per cent of those *N* values, than such set of values will be called a good one. You have to find the probability that a set of values of the given random variables will be a good one. The first line contains number *N* which is the number of random variables (1<=≤<=*N*<=≤<=1000). Then follow *N* lines containing pairs of numbers *L**i*,<=*R**i*, each of whom is a description of a random variable. It is guaranteed that 1<=≤<=*L**i*<=≤<=*R**i*<=≤<=1018. The last line contains an integer *K* (0<=≤<=*K*<=≤<=100). All the numbers in the input file are integers. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Print the required probability. Print the fractional number with such a precision that the relative or absolute error of the result won't exceed 10<=-<=9. Sample Input 1 1 2 50 2 1 2 9 11 50 Sample Output 0.5000000000000000.833333333333333
{"inputs": ["1\n1 2\n50", "2\n1 2\n9 11\n50", "3\n2 9\n20 99\n5 5\n0", "3\n2 9\n20 99\n5 5\n100", "1\n1 1\n100", "4\n1 100\n11 19\n101 199\n15 15\n100", "10\n10 17\n10 12\n3 6\n17 18\n6 15\n9 18\n3 10\n10 15\n17 19\n2 13\n59", "10\n5 20\n13 16\n12 30\n7 16\n10 29\n21 21\n22 26\n14 22\n2 10\n1 29\n48", "15\n11 20\n16 18\n10 17\n11 17\n2 19\n12 20\n5 24\n17 17\n16 18\n22 23\n3 17\n4 5\n14 21\n23 25\n14 15\n73", "15\n15 35\n9 12\n2 23\n26 32\n7 32\n1 22\n2 7\n12 27\n8 14\n26 34\n25 35\n22 25\n9 21\n18 34\n19 30\n75", "20\n7 18\n8 16\n8 15\n3 18\n16 18\n1 19\n2 12\n11 15\n8 13\n8 20\n9 14\n1 6\n1 12\n6 9\n1 5\n7 10\n3 8\n15 16\n2 11\n17 19\n65", "20\n10 21\n9 29\n4 8\n1 27\n24 29\n5 5\n22 22\n4 5\n1 4\n7 12\n11 23\n11 21\n13 13\n10 27\n13 16\n1 24\n4 26\n10 24\n4 19\n26 27\n42", "20\n3 21\n15 28\n21 26\n4 6\n13 28\n20 23\n22 27\n4 13\n1 7\n5 35\n3 3\n16 30\n9 32\n9 16\n3 7\n21 22\n24 29\n6 25\n15 25\n28 33\n32", "1\n1 1000000000000000000\n50", "1\n1000000000000000000 1000000000000000000\n50", "1\n1000000000000000000 1000000000000000000\n100", "1\n100000000000 1000000000000000000\n100"], "outputs": ["0.500000000000000", "0.833333333333333", "1.000000000000000", "0.000000000000000", "1.000000000000000", "0.120000000000000", "0.976666666666667", "0.470619916649862", "0.377283950617284", "0.000000000000000", "0.194241434778525", "0.556819904295018", "0.120023958942805", "0.111111111111111", "1.000000000000000", "1.000000000000000", "0.111111111111111"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
6ca98a9abcdc68bfd325eb090fa72aab
New Year Cards
As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has *n* friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to *n* in the order in which they send the cards. Let's introduce the same numbering for the cards, that is, according to the numbering the *i*-th friend sent to Alexander a card number *i*. Alexander also sends cards to friends, but he doesn't look for the new cards on the Net. He simply uses the cards previously sent to him (sometimes, however, he does need to add some crucial details). Initially Alexander doesn't have any cards. Alexander always follows the two rules: 1. He will never send to a firend a card that this friend has sent to him. 1. Among the other cards available to him at the moment, Alexander always chooses one that Alexander himself likes most. Alexander plans to send to each friend exactly one card. Of course, Alexander can send the same card multiple times. Alexander and each his friend has the list of preferences, which is a permutation of integers from 1 to *n*. The first number in the list is the number of the favorite card, the second number shows the second favorite, and so on, the last number shows the least favorite card. Your task is to find a schedule of sending cards for Alexander. Determine at which moments of time Alexander must send cards to his friends, to please each of them as much as possible. In other words, so that as a result of applying two Alexander's rules, each friend receives the card that is preferred for him as much as possible. Note that Alexander doesn't choose freely what card to send, but he always strictly follows the two rules. The first line contains an integer *n* (2<=≤<=*n*<=≤<=300) — the number of Alexander's friends, equal to the number of cards. Next *n* lines contain his friends' preference lists. Each list consists of *n* different integers from 1 to *n*. The last line contains Alexander's preference list in the same format. Print *n* space-separated numbers: the *i*-th number should be the number of the friend, whose card Alexander receives right before he should send a card to the *i*-th friend. If there are several solutions, print any of them. Sample Input 4 1 2 3 4 4 1 3 2 4 3 1 2 3 4 2 1 3 1 2 4 Sample Output 2 1 1 4
{"inputs": ["4\n1 2 3 4\n4 1 3 2\n4 3 1 2\n3 4 2 1\n3 1 2 4", "2\n1 2\n2 1\n2 1", "3\n1 2 3\n2 3 1\n1 3 2\n3 2 1", "5\n1 4 2 3 5\n5 1 3 4 2\n3 2 4 1 5\n1 4 5 3 2\n5 2 3 4 1\n5 4 2 1 3", "10\n5 1 6 2 8 3 4 10 9 7\n3 1 10 6 8 5 2 7 9 4\n2 9 1 4 10 6 8 7 3 5\n10 1 7 8 3 2 4 6 5 9\n3 2 10 4 7 8 5 6 1 9\n5 6 3 10 8 7 2 9 4 1\n6 5 1 3 2 7 9 10 8 4\n1 10 9 3 7 8 4 2 6 5\n6 8 4 5 9 1 2 10 7 3\n9 6 8 5 10 3 1 7 2 4\n5 7 4 8 9 6 1 10 3 2"], "outputs": ["2 1 1 3", "2 1", "2 3 1", "4 5 2 1 2", "5 1 1 1 4 5 5 1 4 5"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
6cb4576303d3b40dbf510002d41cd3b1
Andrey and Problem
Andrey needs one more problem to conduct a programming contest. He has *n* friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him. Help Andrey choose people to ask. As he needs only one problem, Andrey is going to be really upset if no one comes up with a problem or if he gets more than one problem from his friends. You need to choose such a set of people that maximizes the chances of Andrey not getting upset. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of Andrey's friends. The second line contains *n* real numbers *p**i* (0.0<=≤<=*p**i*<=≤<=1.0) — the probability that the *i*-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point. Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10<=-<=9. Sample Input 4 0.1 0.2 0.3 0.8 2 0.1 0.2 Sample Output 0.800000000000 0.260000000000
{"inputs": ["4\n0.1 0.2 0.3 0.8", "2\n0.1 0.2", "1\n0.217266", "2\n0.608183 0.375030", "3\n0.388818 0.399762 0.393874", "4\n0.801024 0.610878 0.808545 0.732504", "5\n0.239482 0.686259 0.543226 0.764939 0.401318", "6\n0.462434 0.775020 0.479749 0.373861 0.492031 0.746333", "7\n0.745337 0.892271 0.792853 0.892917 0.768246 0.901623 0.815793", "1\n0.057695", "2\n0.057750 0.013591", "3\n0.087234 0.075148 0.033833", "4\n0.016717 0.061051 0.036222 0.096258", "5\n0.057095 0.046954 0.054676 0.025927 0.080810", "6\n0.010924 0.032857 0.021824 0.020356 0.007107 0.082489", "7\n0.016061 0.043107 0.088973 0.014785 0.044298 0.028315 0.086014", "100\n0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01", "1\n1.0", "3\n0.1 0.1 0.1", "3\n0.2 0.2 0.2", "5\n0.01 0.01 0.01 0.01 0.01", "3\n1.0 1.0 0", "3\n0.1 0.2 0.3", "7\n0.1 0.1 0.1 0.1 0.1 0.1 0.1", "5\n0.5 0.5 0.5 1 0.5", "3\n0.4 0.2 0.4", "10\n0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1", "2\n1.0 1.0", "10\n0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01", "5\n1.0 1.0 1.0 0.1 0", "5\n0.0001 0.0001 0.0001 0.0001 0.0001", "20\n0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1", "2\n0.0 1.0", "5\n0.00001 0.00001 0.00001 0.00001 0.00001", "3\n0.2 0.8 1", "4\n0.1 0.1 0.1 0.1", "5\n0.31 0.21 0.05 0.37 0.18", "5\n1 1 1 1 1", "4\n1 1 1 1", "7\n0.14 0.28 0.13 0.31 0.15 0.17 0.27", "20\n0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001", "100\n0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1"], "outputs": ["0.800000000000", "0.260000000000", "0.217266000000", "0.608183000000", "0.478724284024", "0.808545000000", "0.764939000000", "0.775020000000", "0.901623000000", "0.057695000000", "0.069771239500", "0.172781711023", "0.181832937456", "0.214634688963", "0.154629381329", "0.246482855791", "0.369729637650", "1.000000000000", "0.243000000000", "0.384000000000", "0.048029800500", "1.000000000000", "0.398000000000", "0.372008700000", "1.000000000000", "0.480000000000", "0.387420489000", "1.000000000000", "0.091351724748", "1.000000000000", "0.000499800030", "0.387420489000", "1.000000000000", "0.000049998000", "1.000000000000", "0.291600000000", "0.450600000000", "1.000000000000", "1.000000000000", "0.438108000000", "0.019623400697", "0.387420489000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
6cd6eb131d7d6138089bf3122403faa6
Winner
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. Print the name of the winner. Sample Input 3 mike 3 andrew 5 mike 2 3 andrew 3 andrew 2 mike 5 Sample Output andrew andrew
{"inputs": ["3\nmike 3\nandrew 5\nmike 2", "3\nandrew 3\nandrew 2\nmike 5", "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734", "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879", "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735", "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158"], "outputs": ["andrew", "andrew", "kaxqybeultn", "ksjuuerbnlklcfdjeyq", "fcgslzkicjrpbqaifgweyzreajjfdo", "aawtvezfntstrcpgbzjbf", "ivhgbxiv"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
296
codeforces
6cefe83344a570d72979ed5ace1b0015
Alyona and copybooks
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109). Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4. Sample Input 1 1 3 4 6 2 1 1 4 4 4 4 999999999 1000000000 1000000000 1000000000 Sample Output 3 1 0 1000000000
{"inputs": ["1 1 3 4", "6 2 1 1", "4 4 4 4", "999999999 1000000000 1000000000 1000000000", "1016 3 2 1", "17 100 100 1", "17 2 3 100", "18 1 3 3", "19 1 1 1", "999999997 999999990 1000000000 1000000000", "999999998 1000000000 999999990 1000000000", "634074578 336470888 481199252 167959139", "999999999 1000000000 1000000000 999999990", "804928248 75475634 54748096 641009859", "535590429 374288891 923264237 524125987", "561219907 673102149 496813081 702209411", "291882089 412106895 365329221 585325539", "757703054 5887448 643910770 58376259", "783332532 449924898 72235422 941492387", "513994713 43705451 940751563 824608515", "539624191 782710197 514300407 2691939", "983359971 640274071 598196518 802030518", "8989449 379278816 26521171 685146646", "34618927 678092074 895037311 863230070", "205472596 417096820 468586155 41313494", "19 5 1 2", "17 1 2 2", "18 3 3 1", "19 4 3 1", "936134778 715910077 747167704 219396918", "961764255 454914823 615683844 102513046", "692426437 48695377 189232688 985629174", "863280107 347508634 912524637 458679894", "593942288 86513380 486073481 341796022", "914539062 680293934 764655030 519879446", "552472140 509061481 586588704 452405440", "723325809 807874739 160137548 335521569", "748955287 546879484 733686393 808572289", "774584765 845692742 162011045 691688417", "505246946 439473295 30527185 869771841", "676100616 178478041 604076030 752887969", "701730093 477291299 177624874 930971393", "432392275 216296044 751173719 109054817", "458021753 810076598 324722563 992170945", "188683934 254114048 48014511 170254369", "561775796 937657403 280013594 248004555", "1000000000 1000000000 1000000000 1000000000", "3 10000 10000 3", "3 12 3 4", "3 10000 10000 1", "3 1000 1000 1", "3 10 10 1", "3 100 100 1", "3 100000 10000 1", "7 10 2 3", "3 1000 1000 2", "1 100000 1 100000", "7 4 3 1", "3 1000 1000 3", "3 1000 1 1", "3 10 1 1", "3 100000 1 1", "3 100 1 1", "3 100000 100000 1", "3 1000 1 100", "3 1000000000 1 1000000000", "3 1000 1 10", "3 200 1 100", "7 4 1 1", "7 4 12 1", "3 9 1 1", "3 10000000 1000000 1", "7 1000 1000 1", "3 10000 1 30", "3 1000 1 2", "7 12 6 1", "3 100000 1 1000", "7 1000 1000 3", "3 4 3 1", "3 3000000 1 100000", "3 3 1 1", "3 10 1 5", "3 2000 2000 1", "3 10000000 10000000 1", "3 5 1 1", "3 100 1 33", "7 9 2 7", "4448 2 3 6", "2228 1 6 3"], "outputs": ["3", "1", "0", "1000000000", "0", "1", "5", "2", "1", "1000000000", "999999990", "335918278", "1000000000", "0", "524125987", "673102149", "585325539", "11774896", "0", "131116353", "8075817", "640274071", "405799987", "678092074", "0", "3", "2", "2", "3", "438793836", "307539138", "146086131", "347508634", "0", "764655030", "0", "335521569", "546879484", "691688417", "30527185", "0", "654916173", "216296044", "992170945", "48014511", "0", "0", "9", "7", "3", "3", "3", "3", "3", "5", "6", "100000", "3", "9", "2", "2", "2", "2", "3", "101", "1000000000", "11", "101", "2", "3", "2", "3", "3", "31", "3", "3", "1001", "9", "3", "100001", "2", "6", "3", "3", "2", "34", "9", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
142
codeforces
6cf2d7404c1710c85dd4176b03c54664
Summer Camp
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. Sample Input 3 11 Sample Output 3 0
{"inputs": ["3", "11", "12", "13", "29", "30", "1000", "999", "100", "123", "8", "157", "289", "179", "942", "879", "394", "423", "952", "121", "613", "945", "270", "781", "453", "171", "643", "570", "750", "500", "2", "1", "108", "500", "189", "491", "191"], "outputs": ["3", "0", "1", "1", "9", "2", "3", "9", "5", "6", "8", "3", "1", "4", "0", "9", "1", "7", "3", "5", "2", "1", "6", "2", "7", "0", "2", "6", "6", "0", "2", "1", "5", "0", "9", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
368
codeforces
6d148cae240f77dfadc8aeb8612faf2f
Lucky Numbers
The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits. The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold. Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits. Sample Input 2 Sample Output 6
{"inputs": ["2", "1", "3", "5", "12", "34", "43", "49", "54", "55"], "outputs": ["6", "2", "14", "62", "8190", "34359738366", "17592186044414", "1125899906842622", "36028797018963966", "72057594037927934"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
58
codeforces
6d1cac7373c96ae8858afbefb263bce5
Pangram
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters. Output "YES", if the string is a pangram and "NO" otherwise. Sample Input 12 toosmallword 35 TheQuickBrownFoxJumpsOverTheLazyDog Sample Output NO YES
{"inputs": ["12\ntoosmallword", "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "1\na", "26\nqwertyuiopasdfghjklzxcvbnm", "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "48\nthereisasyetinsufficientdataforameaningfulanswer", "30\nToBeOrNotToBeThatIsTheQuestion", "30\njackdawslovemybigsphinxofquarz", "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY", "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "26\nMGJYIZDKsbhpVeNFlquRTcWoAx", "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ", "26\nngPMVFSThiRCwLEuyOAbKxQzDJ", "25\nnxYTzLFwzNolAumjgcAboyxAj", "26\npRWdodGdxUESvcScPGbUoooZsC", "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj", "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa", "26\nEoqxUbsLjPytUHMiFnvcGWZdRK", "26\nvCUFRKElZOnjmXGylWQaHDiPst", "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY", "26\npGiFluRteQwkaVoPszJyNBChxM", "26\ncTUpqjPmANrdbzSFhlWIoKxgVY", "26\nLndjgvAEuICHKxPwqYztosrmBN", "26\nMdaXJrCipnOZLykfqHWEStevbU", "26\nEjDWsVxfKTqGXRnUMOLYcIzPba", "26\nxKwzRMpunYaqsdfaBgJcVElTHo", "26\nnRYUQsTwCPLZkgshfEXvBdoiMa", "26\nHNCQPfJutyAlDGsvRxZWMEbIdO", "26\nDaHJIpvKznQcmUyWsTGObXRFDe", "26\nkqvAnFAiRhzlJbtyuWedXSPcOG", "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF", "26\njLfXXiMhBTcAwQVReGnpKzdsYu", "26\nlNMcVuwItjxRBGAekjhyDsQOzf", "26\nRkSwbNoYldUGtAZvpFMcxhIJFE", "26\nDqspXZJTuONYieKgaHLMBwfVSC", "26\necOyUkqNljFHRVXtIpWabGMLDz", "26\nEKAvqZhBnPmVCDRlgWJfOusxYI", "26\naLbgqeYchKdMrsZxIPFvTOWNjA", "26\nxfpBLsndiqtacOCHGmeWUjRkYz", "26\nXsbRKtqleZPNIVCdfUhyagAomJ", "26\nAmVtbrwquEthZcjKPLiyDgSoNF", "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB", "26\nEKWJqCFLRmstxVBdYuinpbhaOg", "26\nmnbvcxxlkjhgfdsapoiuytrewq", "26\naAbcdefghijklmnopqrstuvwxy", "30\nABCDEFGHTYRIOPLabcdefghtyriopl", "25\nabcdefghijklmnopqrstuvwxy", "26\nabcdefhijklmnopqrstVxyzABC", "25\nqwertyuiopasdfghjklxcvbnm", "34\nTheQuickBrownFoxJumpsOverTheLayDog", "26\nabcdefghigklmnopqrstuvwxyz", "26\nabcdefghijklmnopqrstuvwxyA", "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM", "35\nTheQuickBrownFoxJumpsOverTheLasyDog", "25\nbcdefghijklmnopqrstuvwxyz", "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa", "26\nabcdefghiklmnopqrstvxyzABC", "26\nabcdefghijklmnopqrstuvwxzZ", "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY"], "outputs": ["NO", "YES", "NO", "YES", "YES", "NO", "NO", "NO", "YES", "NO", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
568
codeforces
6d2e99edaf65af436e74bf409494fe5b
Very Beautiful Number
Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the number in the teachers' office. The teacher remembers that the "very beautiful number" was strictly positive, didn't contain any leading zeroes, had the length of exactly *p* decimal digits, and if we move the last digit of the number to the beginning, it grows exactly *x* times. Besides, the teacher is sure that among all such numbers the "very beautiful number" is minimal possible. The teachers' office isn't near and the teacher isn't young. But we've passed the test and we deserved the right to see the "very beautiful number". Help to restore the justice, find the "very beautiful number" for us! The single line contains integers *p*, *x* (1<=≤<=*p*<=≤<=106,<=1<=≤<=*x*<=≤<=9). If the teacher's made a mistake and such number doesn't exist, then print on a single line "Impossible" (without the quotes). Otherwise, print the "very beautiful number" without leading zeroes. Sample Input 6 5 1 2 6 4 Sample Output 142857Impossible 102564
{"inputs": ["6 5", "1 2", "6 4", "11 1", "42 5", "36 5", "56 3", "88 9", "81 7", "100 1", "58 6", "3282 5", "24002 7", "8140 7", "23910 4", "11478 4", "12818 8", "999999 8", "100002 4", "337 6", "11389 6", "1000000 3", "1000000 1", "2 7", "1 1"], "outputs": ["142857", "Impossible", "102564", "11111111111", "102040816326530612244897959183673469387755", "142857142857142857142857142857142857", "10344827586206896551724137931034482758620689655172413793", "1011235955056179775280898876404494382022471910112359550561797752808988764044943820224719", "Impossible", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "1016949152542372881355932203389830508474576271186440677966", "1428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571...", "1014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144...", "1014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144927536231884057971014492753623188405797101449275362318840579710144...", "1025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641...", "1025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641...", "1012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012...", "1012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012658227848101265822784810126582278481012...", "1025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641025641...", "Impossible", "Impossible", "Impossible", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...", "Impossible", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
6d5221a978b652defdeae7f5e3469cac
Levko and Permutation
Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*. Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numbers *a* and *b*. Levko assumes that element *p**i* of permutation *p*1,<=*p*2,<=... ,<=*p**n* is good if *gcd*(*i*,<=*p**i*)<=&gt;<=1. Levko considers a permutation beautiful, if it has exactly *k* good elements. Unfortunately, he doesn’t know any beautiful permutation. Your task is to help him to find at least one of them. The single line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*). In a single line print either any beautiful permutation or -1, if such permutation doesn’t exist. If there are multiple suitable permutations, you are allowed to print any of them. Sample Input 4 2 1 1 Sample Output 2 4 3 1-1
{"inputs": ["4 2", "1 1", "7 4", "10 9", "10000 5000", "7 0", "1 0", "7 7", "100000 47", "100000 100000", "100000 43425", "7 6", "100000 99999", "47 46", "5 0", "4 2", "1533 1052", "81314 52747", "17767 145", "18168 7942", "26593 15915", "26593 8877", "13852 12727", "4 1", "8834 8834", "8485 8484", "14564 14564", "8254 8253", "81314 81312", "5795 5792", "6417 3", "6896 0", "6778 1", "9448 1", "5938 2", "3072 0", "8576 0", "2 1", "4 4", "5 5", "2 2", "100000 1", "100000 50000", "4 1", "100000 9999", "100000 99000", "100000 12347"], "outputs": ["2 1 3 4 ", "-1", "3 1 2 4 5 6 7 ", "1 2 3 4 5 6 7 8 9 10 ", "5000 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 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 153 15...", "7 1 2 3 4 5 6 ", "1 ", "-1", "99953 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 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 153 1...", "-1", "56575 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 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 153 1...", "1 2 3 4 5 6 7 ", "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 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 153 154 155...", "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 ", "5 1 2 3 4 ", "2 1 3 4 ", "481 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 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 153 154...", "28567 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 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 153 1...", "17622 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 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 153 1...", "10226 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 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 153 1...", "10678 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 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 153 1...", "17716 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 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 153 1...", "1125 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 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 153 15...", "3 1 2 4 ", "-1", "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 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 153 154 155...", "-1", "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 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 153 154 155...", "2 1 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 153 154 155...", "3 1 2 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 153 154 155...", "6414 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 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 153 15...", "6896 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 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 153 15...", "6777 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 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 153 15...", "9447 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 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 153 15...", "5936 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 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 153 15...", "3072 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 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 153 15...", "8576 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 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 153 15...", "1 2 ", "-1", "-1", "-1", "99999 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 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 153 1...", "50000 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 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 153 1...", "3 1 2 4 ", "90001 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 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 153 1...", "1000 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 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 153 15...", "87653 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 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 153 1..."]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
108
codeforces
6d5b1c026ba6c1af6fba85c8d6e409bb
Purification
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an *n*<=×<=*n* grid. The rows are numbered 1 through *n* from top to bottom, and the columns are numbered 1 through *n* from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door: Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells. The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile — then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once. You would like to purify all *n*<=×<=*n* cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell. Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way. The first line will contain a single integer *n* (1<=≤<=*n*<=≤<=100). Then, *n* lines follows, each contains *n* characters. The *j*-th character in the *i*-th row represents the cell located at row *i* and column *j*. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise. If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts *x* "Purification" spells (where *x* is the minimum possible number of spells), output *x* lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell. Sample Input 3 .E. E.E .E. 3 EEE E.. E.E 5 EE.EE E.EE. E...E .EE.E EE.EE Sample Output 1 1 2 2 3 3 -1 3 3 1 3 2 2 4 4 5 3
{"inputs": ["3\n.E.\nE.E\n.E.", "3\nEEE\nE..\nE.E", "5\nEE.EE\nE.EE.\nE...E\n.EE.E\nEE.EE", "3\n.EE\n.EE\n.EE", "5\nEE.EE\nEE..E\nEEE..\nEE..E\nEE.EE", "1\nE", "8\nE.EEE..E\nEEE.E.E.\nEEE.E.E.\nEE.E.E..\nE...EE..\nE.EE....\n..EE....\nE..E.EE.", "17\nEE...E.EE.EE..E..\nE.....EE..E..E..E\nEEEE.EEEE..E..E.E\n.E.E.EEE.EEEEE...\nEEEEEEEEEEEEEEEEE\nEE.E.EEEEE.E.....\n..E.EE.EEE.E....E\n.E..E..E...EE.E.E\nEEEE.EEE.E.EEEE..\n...E...EEEEEEE.E.\n..E.E.EE..E.EE..E\n.E..E..E.EEE.....\n.E.....E..EEE.EE.\nEE.E...E.EEEE.EE.\n...EEEEEEE.E..E.E\nEEEE.EEEEEE....E.\n..EEEEEEE....EEEE", "17\n.EEEEE...EEEE..EE\nEEE..E...EEEEE..E\n.E..E..EEE.EE...E\n.EEE.EE..EE...E..\nE..EEEEEE.EE.....\nE.EE...EEEEEEE.E.\nEEEE....EE..E.EEE\n...EEEEE.E..EE...\nEEE.E..EEEE.EEE..\n..E.E....EEE.....\nEE..E..E.E..EEEEE\nEEE..E.EEEEE.E...\n..EEEEE.E..EE.EE.\nEE.E...E..E..E.EE\n..E.EEE.EE..EE.E.\nE..EE........E.E.\nE..E..EEE.E...E..", "1\n.", "2\nEE\nEE", "2\n.E\n.E", "3\n.EE\nEEE\nEEE", "3\n...\nEEE\n..E", "4\nE...\nE.EE\nEEEE\nEEEE", "4\n....\nE..E\nEEE.\n.EE.", "8\nE..EEEEE\nEE..EEE.\nEE..E...\nEEE.E..E\n.E.EEEE.\nEEEEEEEE\n.EEEE.EE\n.EE.E.E.", "3\nE..\nEEE\nE..", "4\nEEEE\n..E.\n..E.\n..E.", "3\n..E\n.EE\n.EE", "6\n.EEEEE\n.EEEEE\n......\n......\n......\nEEEEEE"], "outputs": ["1 1\n2 2\n3 1", "-1", "1 3\n2 2\n3 2\n4 1\n5 3", "1 1\n2 1\n3 1", "1 3\n2 3\n3 4\n4 3\n5 3", "-1", "1 2\n2 4\n3 4\n4 3\n5 2\n6 2\n7 1\n8 2", "-1", "1 1\n2 4\n3 1\n4 1\n5 2\n6 2\n7 5\n8 1\n9 4\n10 1\n11 3\n12 4\n13 1\n14 3\n15 1\n16 2\n17 2", "1 1", "-1", "1 1\n2 1", "-1", "1 1\n1 2\n1 3", "-1", "1 1\n2 2\n3 4\n4 1", "-1", "-1", "-1", "1 1\n2 1\n3 1", "1 1\n3 2\n3 3\n3 4\n3 5\n3 6"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
21
codeforces
6dadd620920edfb1edbee1553bb820ee
Dasha and Password
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length *n* which satisfies the following requirements: - There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string, - There is at least one of three listed symbols in the string: '#', '*', '&amp;'. Considering that these are programming classes it is not easy to write the password. For each character of the password we have a fixed string of length *m*, on each of these *n* strings there is a pointer on some character. The *i*-th character displayed on the screen is the pointed character in the *i*-th string. Initially, all pointers are on characters with indexes 1 in the corresponding strings (all positions are numbered starting from one). During one operation Dasha can move a pointer in one string one character to the left or to the right. Strings are cyclic, it means that when we move the pointer which is on the character with index 1 to the left, it moves to the character with the index *m*, and when we move it to the right from the position *m* it moves to the position 1. You need to determine the minimum number of operations necessary to make the string displayed on the screen a valid password. The first line contains two integers *n*, *m* (3<=≤<=*n*<=≤<=50,<=1<=≤<=*m*<=≤<=50) — the length of the password and the length of strings which are assigned to password symbols. Each of the next *n* lines contains the string which is assigned to the *i*-th symbol of the password string. Its length is *m*, it consists of digits, lowercase English letters, and characters '#', '*' or '&amp;'. You have such input data that you can always get a valid password. Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password. Sample Input 3 4 1**2 a3*0 c4** 5 5 #*&amp;#* *a1c&amp; &amp;q2w* #a3c# *&amp;#*&amp; Sample Output 1 3
{"inputs": ["3 4\n1**2\na3*0\nc4**", "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&", "5 2\n&l\n*0\n*9\n*#\n#o", "25 16\nvza**ooxkmd#*ywa\ndip#*#&ef&z&&&pv\nwggob&&72#*&&nku\nrsb##*&jm&#u**te\nzif#lu#t&2w#jbqb\nwfo&#&***0xp#&hp\njbw##h*###nkmkdn\nqrn*&y#3cnf&d*rc\nend*zg&0f*&g*&ak\niayh&r#8om#o**yq\nwym&e&*v0j&#zono\ntzu*vj&i18iew&ht\nhpfnceb193&#&acf\ngesvq&l&*&m*l*ru\nfot#u&pq&0y&s*pg\nqdfgs&hk*wob&&bw\nbqd&&&lnv&&ax&ql\nell#&t&k*p#n*rlg\nclfou#ap#*vxulmt\nfhp*gax&s1&pinql\nyihmh*yy&2&#&prc\nrmv**#h*bxyf&&eq\nziu##ku#f#uh*fek\nhmg&&cvx0p*#odgw\nquu&csv*aph#dkiq", "3 5\n*****\n1***a\n**a**", "5 2\n&e\n#j\n&&\n*2\n94", "5 2\ns*\nsq\n*v\nes\n*5", "10 2\n0n\n5h\n7&\n1b\n5&\n4*\n9k\n0*\n7m\n62", "10 2\n89\n7&\ns8\now\n2#\n5&\nu&\n89\n8#\n3u", "10 2\n#y\njc\n#6\n#0\nt7\ns7\nd#\nn2\n#7\n&3", "15 12\n502j2*su#*j4\n48vt&#2w8#r5\n43wl0085#&64\n99pedbk#*ol2\n08w#h#&y1346\n259*874&b*76\n40l#5hc*qta4\n280#h#r*3k98\n20t8o&l1##55\n8048l#6&o*37\n01a3z0179#30\n65p28q#0*3j3\n51tx885#**56\n105&&f64n639\n40v3&l61yr65", "15 12\ndcmzv&*zzflc\neftqm&**njyp\ntwlsi*jvuman\ngcxdlb#xwbul\nnpgvufdyqoaz\nxvvpk##&bpso\njlwcfb&kqlbu\nnpxxr#1augfd\nngnaph#erxpl\nlsfaoc*ulsbi\npffbe&6lrybj\nsuvpz#q&aahf\nizhoba**jjmc\nmkdtg#6*xtnp\nqqfpjo1gddqo", "15 12\n#&*&s#&&9&&&\n*&##*4&le&*#\n#*##24qh3*#&\n&***2j&a2###\n#*&#n68*z###\n##**1#&w#**&\n*&*#*0#&#***\n#*#*2723&*##\n&#&&mg3iu##*\n*&&#zl4k#&*&\n##&*5g#01&&*\n*##&wg1#6&*#\n#&**pvr6*&&#\n&&#*mzd#5&*#\n###*e2684#**", "20 13\n885**jh##mj0t\nky3h&h&clr#27\nq6n&v127i64xo\n3lz4du4zi5&z9\n0r7056qp8r*5a\nc8v94v#402l7n\nu968vxt9&2fkn\n2jl4m**o6412n\nh10v&vl*#4&h4\nj4864*##48*9d\n402i&3#x&o786\nzn8#w&*p#8&6l\n2e7&68p#&kc47\njf4e7fv&o0*3z\n0z67ocr7#5*79\nr8az68#&u&5a9\n65a#&9#*8o178\nqjevs&&muj893\n4c83i63j##m37\ng1g85c##f7y3f", "20 13\nvpym*054*4hoi\nldg&1u*yu4inw\nvs#b7*s27iqgo\nfp&*s2g#1i&#k\nyp&v474*58*#w\nzwfxx***4hqdg\nqqv*3163r2*&l\naxdc4l7&5l#fj\nqq&h#1z*&5#*a\nyml&&&9#a2*pr\nmpn&&78rbthpb\nac#d50**b7t#o\ndk&z7q&z&&#&j\ngyh#&f#0q5#&x\ncxw*#hgm#9nqn\nqm#&*c*k&2&bz\nxc#&86o#d9g#w\nzjm&12&9x3#hp\nzy&s##47u1jyf\nub*&9ao5qy#ip", "20 13\n*8002g&87&8&6\n&4&#2n*51i4&0\n40*#iq3pnc&87\n#*&0*s458&475\n802*8&1z*g533\n7171&a&2&2*8*\n*&##&&&&&t**&\n3#&*7#80*m18#\n#4#&#099qt9*7\n6*#56*#*&762&\n9406&ge0&7&07\n9**&6lv*v*2&&\n9##&c&i&z13#*\n68#*4g*9&f4&1\n37##80#&f2*&2\n81##*xo#q#5&0\n5247#hqy&d9&2\n#*13*5477*9#*\n2*&#q*0*fb9#*\n&2&4v*2##&&32", "25 16\n5v7dnmg1##qqa75*\n0187oa*&c&&ew9h*\nr70*&##*q#4i6*&#\n7*wk*&4v06col***\n28*0h94x**&21*f5\neh5vbt#8&8#8#3r&\np*01u&&90&08p*#*\nb9#e7&r8lc56b*##\nyb4&x#&4956iw&8*\n39&5#4d5#&3r8t5x\n7x13**kk#0n**&80\n4oux8yhz*pg84nnr\nb2yfb&b70xa&k56e\nqt5&q4&6#&*z5#3&\n5*#*086*51l&&44#\n84k5**0lij37j#&v\ns&j0m4j&2v3fv9h&\np&hu68704*&cufs#\n34ra*i1993*i*&55\nr#w#4#1#30*cudj*\n0m3p&e3t##y97&90\nk6my174e##5z1##4\n2*&v#0u&49f#*47#\nv5276hv1xn*wz8if\nk24*#&hu7e*##n8&", "25 16\n&*#&#**sw&**&#&#\n&*#*d#j*3b&q***#\n###&yq*v3q*&##**\n#**&#j&#6pt#*#*#\n***#y*cd&l*oe*##\n&&&***#k*e&*p&#*\n&###*&fkn*pni#**\n**&#ybz*&u*##&&#\n**##p&renhvlq#&#\n*#*&q&*#1&p#&&#&\n**&##&##2*ved&&*\n##*&tug&x*fx&*&*\n###**nt*u&&ux*&&\n&#&#**##1xca*#&&\n*#*&jw#rc#vow&&&\n&*#&exgq&&m*&#*&\n&&##l&&mbizc&**&\n##*&&#m*0&o#*##*\n&#*&fcqsy#&&#*#&\n**#**#*cdm#yf*&*\n*&##s#*v#*g#*&**\n*&##&*#mu##eh&#*\n####v#&i5*bnb&&&\n**##*hj&9#ro#&**\n#&&**&s*9x#f&&*#", "50 1\n#\n4\n7\n#\n&\n*\n3\n&\nc\n*\n7\n*\n#\nw\n1\n&\n8\n7\n&\n&\ny\ng\n#\n5\n*\n4\nx\ny\np\n6\nf\ne\np\n&\n#\n#\ns\nt\na\nm\n&\n1\nv\n#\n&\n1\nq\n0\ny\n3", "3 1\nr\n&\n6", "3 1\n1\nz\n#", "3 1\n6\n*\nt", "3 1\ni\n3\n&", "3 1\nj\n#\n0", "3 1\n&\n7\no", "3 1\n&\nr\n3", "3 8\n*1a*****\n*******a\n*******1", "3 15\naaaaaaa1aaaaaaa\naaaaaaa*aaaaaaa\naaaaaaa*aaaaaaa"], "outputs": ["1", "3", "2", "10", "2", "1", "1", "2", "1", "1", "5", "11", "8", "3", "6", "4", "1", "12", "0", "0", "0", "0", "0", "0", "0", "0", "2", "14"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
43
codeforces
6dd4ecd12771553ae125882e94ff943c
Significant Cups
Stepan is a very experienced olympiad participant. He has *n* cups for Physics olympiads and *m* cups for Informatics olympiads. Each cup is characterized by two parameters — its significance *c**i* and width *w**i*. Stepan decided to expose some of his cups on a shelf with width *d* in such a way, that: - there is at least one Physics cup and at least one Informatics cup on the shelf, - the total width of the exposed cups does not exceed *d*, - from each subjects (Physics and Informatics) some of the most significant cups are exposed (i. e. if a cup for some subject with significance *x* is exposed, then all the cups for this subject with significance greater than *x* must be exposed too). Your task is to determine the maximum possible total significance, which Stepan can get when he exposes cups on the shelf with width *d*, considering all the rules described above. The total significance is the sum of significances of all the exposed cups. The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100<=000, 1<=≤<=*d*<=≤<=109) — the number of cups for Physics olympiads, the number of cups for Informatics olympiads and the width of the shelf. Each of the following *n* lines contains two integers *c**i* and *w**i* (1<=≤<=*c**i*,<=*w**i*<=≤<=109) — significance and width of the *i*-th cup for Physics olympiads. Each of the following *m* lines contains two integers *c**j* and *w**j* (1<=≤<=*c**j*,<=*w**j*<=≤<=109) — significance and width of the *j*-th cup for Informatics olympiads. Print the maximum possible total significance, which Stepan can get exposing cups on the shelf with width *d*, considering all the rules described in the statement. If there is no way to expose cups on the shelf, then print 0. Sample Input 3 1 8 4 2 5 5 4 2 3 2 4 3 12 3 4 2 4 3 5 3 4 3 5 5 2 3 4 2 2 2 5 3 6 3 4 2 8 1 Sample Output 8 11 0
{"inputs": ["3 1 8\n4 2\n5 5\n4 2\n3 2", "4 3 12\n3 4\n2 4\n3 5\n3 4\n3 5\n5 2\n3 4", "2 2 2\n5 3\n6 3\n4 2\n8 1", "10 10 229\n15 17\n5 4\n4 15\n4 17\n15 11\n7 6\n5 19\n14 8\n4 1\n10 12\n20 13\n20 14\n16 13\n7 15\n2 16\n11 11\n19 20\n6 7\n4 11\n14 16", "10 20 498\n40 12\n23 25\n20 9\n8 1\n23 8\n31 24\n33 2\n22 33\n4 13\n25 20\n40 5\n27 5\n17 6\n8 5\n4 19\n33 23\n30 19\n27 12\n13 22\n16 32\n28 36\n20 18\n36 38\n9 24\n21 35\n20 9\n33 29\n29 33\n18 25\n11 8", "20 10 761\n42 41\n47 7\n35 6\n22 40\n15 2\n47 28\n46 47\n3 45\n12 19\n44 41\n46 2\n49 23\n9 8\n7 41\n5 3\n16 42\n12 50\n17 22\n25 9\n45 12\n41 44\n34 47\n33 35\n32 47\n49 6\n27 18\n43 36\n23 6\n39 22\n38 45", "1 1 1000000000\n4 500000000\n6 500000000", "4 2 8\n1000000000 2\n1000000000 2\n1000000000 2\n1000000000 2\n1000000000 2\n1000000000 2", "1 1 1000000000\n1 1000000000\n1 1000000000", "1 1 1\n1 1\n1 1"], "outputs": ["8", "11", "0", "198", "644", "900", "10", "4000000000", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
6df7a596947d9d0d3c1607821180ca35
Beautiful Paintings
There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of *a* in any order. What is the maximum possible number of indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1), such that *a**i*<=+<=1<=&gt;<=*a**i*. The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of painting. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* means the beauty of the *i*-th painting. Print one integer — the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=&gt;<=*a**i*, after the optimal rearrangement. Sample Input 5 20 30 10 50 40 4 200 100 100 200 Sample Output 4 2
{"inputs": ["5\n20 30 10 50 40", "4\n200 100 100 200", "10\n2 2 2 2 2 2 2 2 2 2", "1\n1000", "2\n444 333", "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14", "1\n995", "10\n103 101 103 103 101 102 100 100 101 104", "20\n102 100 102 104 102 101 104 103 100 103 105 105 100 105 100 100 101 105 105 102", "20\n990 994 996 999 997 994 990 992 990 993 992 990 999 999 992 994 997 990 993 998", "100\n1 8 3 8 10 8 5 3 10 3 5 8 4 5 5 5 10 3 6 6 6 6 6 7 2 7 2 4 7 8 3 8 7 2 5 6 1 5 5 7 9 7 6 9 1 8 1 3 6 5 1 3 6 9 5 6 8 4 8 6 10 9 2 9 3 8 7 5 2 10 2 10 3 6 5 5 3 5 10 2 3 7 10 8 8 4 3 4 9 6 10 7 6 6 6 4 9 9 8 9"], "outputs": ["4", "2", "0", "0", "1", "95", "0", "7", "15", "15", "84"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
97
codeforces
6dfc961b9b9cd5602504e14fc0fb01c4
Finding Team Member
There is a programing contest named SnakeUp, 2*n* people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the strengths are distinct. Every contestant hopes that he can find a teammate so that their team’s strength is as high as possible. That is, a contestant will form a team with highest strength possible by choosing a teammate from ones who are willing to be a teammate with him/her. More formally, two people *A* and *B* may form a team if each of them is the best possible teammate (among the contestants that remain unpaired) for the other one. Can you determine who will be each person’s teammate? There are 2*n* lines in the input. The first line contains an integer *n* (1<=≤<=*n*<=≤<=400) — the number of teams to be formed. The *i*-th line (*i*<=&gt;<=1) contains *i*<=-<=1 numbers *a**i*1, *a**i*2, ... , *a**i*(*i*<=-<=1). Here *a**ij* (1<=≤<=*a**ij*<=≤<=106, all *a**ij* are distinct) denotes the strength of a team consisting of person *i* and person *j* (people are numbered starting from 1.) Output a line containing 2*n* numbers. The *i*-th number should represent the number of teammate of *i*-th person. Sample Input 2 6 1 2 3 4 5 3 487060 3831 161856 845957 794650 976977 83847 50566 691206 498447 698377 156232 59015 382455 626960 Sample Output 2 1 4 3 6 5 4 3 2 1
{"inputs": ["2\n6\n1 2\n3 4 5", "3\n487060\n3831 161856\n845957 794650 976977\n83847 50566 691206 498447\n698377 156232 59015 382455 626960", "3\n8\n1 6\n14 13 15\n4 2 11 9\n12 5 3 7 10", "1\n1000000", "3\n1000000\n999999 999998\n999997 999996 999995\n999994 999993 999992 999991\n999990 999989 999988 999987 999986"], "outputs": ["2 1 4 3", "6 5 4 3 2 1", "6 5 4 3 2 1", "2 1", "2 1 4 3 6 5"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
6dfcac919c08dffa6e6836e1c3a3b8ed
Sequence Formatting
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,...,   10" will be corrected to "1, 2, 3, ..., 10". In this task you are given a string *s*, which is composed by a concatination of terms, each of which may be: - a positive integer of an arbitrary length (leading zeroes are not allowed), - a "comma" symbol (","), - a "space" symbol (" "), - "three dots" ("...", that is, exactly three points written one after another, also known as suspension points). Polycarp wants to add and remove spaces in the string *s* to ensure the following: - each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it), - each "three dots" term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term), - if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left, - there should not be other spaces. Automate Polycarp's work and write a program that will process the given string *s*. The input data contains a single string *s*. Its length is from 1 to 255 characters. The string *s* does not begin and end with a space. Its content matches the description given above. Print the string *s* after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. Sample Input 1,2 ,3,..., 10 1,,,4...5......6 ...,1,2,3,... Sample Output 1, 2, 3, ..., 10 1, , , 4 ...5 ... ...6 ..., 1, 2, 3, ...
{"inputs": ["1,2 ,3,..., 10", "1,,,4...5......6", ",,,,,,,,,,,,,", "123456789", ",", "1 4 5 6 7 999 1 1 1 2 311111111111111111111111111111111111111111", "1,2,,,,,,,,,5566", "...,", ",,", ",...,", "1...10", ", ,", "123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123", "12 56 511 23 12356346151112 1235634615111235634615 34615111235634615111 1123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563 151112356346151112356346151 1511 3", "1, 56 511 23 12356,,,151112 1235,34,15,11,356,4615 , , 34615111235,34615111, , 11235634615111235634615111235634615111235634615111235,3461511123563461511123563461511123563 ,151112356346151112356346151 15,, ,3", "1,... 511 23 ...56,,,151112 1235,34,15,11,356,4615 , , 34.........,34615111, , ...1123563461511...563461511123563461511123563461511123...461511123563461511123563461511123563 ,151112356346151112356346151 ... 15,, ,3", ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", "..........................................................................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,", "1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1", "12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12", ",...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,,...,", "1,", ",1", "1", "1 1", "1 1 1", "... ,", "......,,,,,...... 1234 1234 1234 , 1234 ... , 1234 ... 1234 ... , 1234", "9999999999999999999999999999999999999999999999999999999999, 1", "5555555555555555555 6666 77777777 8888888888888 ,,...,55,5...55...,.........5 , , ... , 5 5 , 5 ... 5 5 ... , ... ... ... 5", "...5", "1,2 4,78 799,4...5 3......6,"], "outputs": ["1, 2, 3, ..., 10", "1, , , 4 ...5 ... ...6", ", , , , , , , , , , , , ,", "123456789", ",", "1 4 5 6 7 999 1 1 1 2 311111111111111111111111111111111111111111", "1, 2, , , , , , , , , 5566", "...,", ", ,", ", ...,", "1 ...10", ", ,", "123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563461511123", "12 56 511 23 12356346151112 1235634615111235634615 34615111235634615111 1123563461511123563461511123563461511123563461511123563461511123563461511123563461511123563 151112356346151112356346151 1511 3", "1, 56 511 23 12356, , , 151112 1235, 34, 15, 11, 356, 4615, , 34615111235, 34615111, , 11235634615111235634615111235634615111235634615111235, 3461511123563461511123563461511123563, 151112356346151112356346151 15, , , 3", "1, ...511 23 ...56, , , 151112 1235, 34, 15, 11, 356, 4615, , 34 ... ... ..., 34615111, , ...1123563461511 ...563461511123563461511123563461511123 ...461511123563461511123563461511123563, 151112356346151112356346151 ...15, , , 3", ", , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,", "... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ..., , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,", "1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1 ...1", "12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12", ", ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ..., , ...,", "1,", ", 1", "1", "1 1", "1 1 1", "...,", "... ..., , , , , ... ...1234 1234 1234, 1234 ..., 1234 ...1234 ..., 1234", "9999999999999999999999999999999999999999999999999999999999, 1", "5555555555555555555 6666 77777777 8888888888888, , ..., 55, 5 ...55 ..., ... ... ...5, , ..., 5 5, 5 ...5 5 ..., ... ... ...5", "...5", "1, 2 4, 78 799, 4 ...5 3 ... ...6,"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
6e0b77cb8cb7c6adcab680be206a2647
Points and Powers of Two
There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points $x_{i_1}, x_{i_2}, \dots, x_{i_m}$ such that for each pair $x_{i_j}$, $x_{i_k}$ it is true that $|x_{i_j} - x_{i_k}| = 2^d$ where $d$ is some non-negative integer number (not necessarily the same for each pair of points). The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of points. The second line contains $n$ pairwise distinct integers $x_1, x_2, \dots, x_n$ ($-10^9 \le x_i \le 10^9$) — the coordinates of points. In the first line print $m$ — the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print $m$ integers — the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Sample Input 6 3 5 4 7 10 12 5 -1 2 5 8 11 Sample Output 3 7 3 51 8
{"inputs": ["6\n3 5 4 7 10 12", "5\n-1 2 5 8 11", "1\n42", "3\n0 -536870912 536870912", "2\n536870912 -536870912", "3\n1 2 3", "4\n1 2 3 8", "2\n1 2", "3\n0 1 2", "2\n-3 -2", "2\n-4 -2", "2\n2 1", "1\n1", "3\n0 2 6", "3\n2 4 8", "2\n1 0", "3\n5 6 7", "3\n-1 1 0"], "outputs": ["3\n3 4 5 ", "1\n-1 ", "1\n42 ", "3\n-536870912 0 536870912 ", "2\n-536870912 536870912 ", "3\n1 2 3 ", "3\n1 2 3 ", "2\n1 2 ", "3\n0 1 2 ", "2\n-3 -2 ", "2\n-4 -2 ", "2\n1 2 ", "1\n1 ", "2\n0 2 ", "2\n2 4 ", "2\n0 1 ", "3\n5 6 7 ", "3\n-1 0 1 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
33
codeforces
6e0bc12d128f12665442cb838644357e
Giga Tower
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?). Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number. The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). Print the minimum *b* in a line. Sample Input 179 -1 18 Sample Output 1 9 10
{"inputs": ["179", "-1", "18", "-410058385", "-586825624", "852318890", "919067153", "690422411", "-408490162", "-8", "-6", "-4", "-2", "0", "2", "4", "6", "8", "1000000000", "-1000000000", "88888", "89", "-80000000", "-8888", "-17", "78", "-19", "-999999998", "-999999997", "999999997", "811111111", "-8", "-5", "-7", "1000000000"], "outputs": ["1", "9", "10", "1", "1", "1", "5", "7", "1", "16", "14", "12", "10", "8", "6", "4", "2", "10", "8", "2", "1", "9", "2", "1", "9", "2", "1", "9", "8", "1", "1", "16", "13", "15", "8"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
325
codeforces
6e0dc02ba7291c453c2ec9afee5215ce
Petya and Exam
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known that character "*" occurs no more than once in the pattern. Also, *n* query strings are given, it is required to determine for each of them if the pattern matches it or not. Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning. A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string. The good letters are given to Petya. All the others are bad. The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad. The second line contains the pattern — a string *s* of lowercase English letters, characters "?" and "*" (1<=≤<=|*s*|<=≤<=105). It is guaranteed that character "*" occurs in *s* no more than once. The third line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of query strings. *n* lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string. It is guaranteed that the total length of all query strings is not greater than 105. Print *n* lines: in the *i*-th of them print "YES" if the pattern matches the *i*-th query string, and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrary. Sample Input ab a?a 2 aaa aab abc a?a?a* 4 abacaba abaca apapa aaaaax Sample Output YES NO NO YES NO YES
{"inputs": ["ab\na?a\n2\naaa\naab", "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax", "s\nc*?cb\n26\nbbaa\nb\ncc\ncbaab\nacacc\nca\na\nc\ncb\nabb\nba\nb\nba\ncac\nccccb\nccb\nbbbc\nabbcb\na\nbc\nc\na\nabb\nca\ncacb\nac", "o\n*\n28\nbac\nbcc\ncbcb\ncaabc\ncb\nacab\ncbccb\ncbccc\nc\nbbaa\ncaaaa\nbbc\nba\nc\ncacbc\ncbab\naa\nac\nacc\na\nac\nbac\naaac\nba\nabbbb\nbbcc\nbaacb\naabaa", "u\n*b??c\n23\na\nbcbcc\nacb\na\nbacaa\nbb\nb\nbcba\ncbbcc\nb\nabbb\nbcacb\nabcb\ncbca\nb\ncba\ncabcb\nbc\ncc\naaacc\nccac\ncc\nccbcb", "g\nc?*\n58\nb\ncaac\nbbc\nabb\ncaccc\ncb\naba\nbcaa\ncca\ncbbcb\ncac\nbbaca\nbcba\nbba\nabbab\nccc\nc\nbcb\naac\nbcbbc\nbca\nc\ncbb\nccabb\naaccc\nccaa\nc\nc\nbcca\naa\nccb\ncb\ncbcb\ncc\nab\ncccc\nbbbab\nbab\na\nc\ncbba\nbbacb\naa\nb\nbaab\nacabb\nbcbab\ncbbcb\nbc\ncccba\naa\ncccca\ncacc\naacbb\na\nc\nab\nccca", "g\nbc*a\n40\nbabac\nccbb\ncacbc\nc\na\naba\nbc\na\nba\nbbcca\nccbac\na\nc\nbabc\ncccbc\nab\nabca\nccb\nacbbb\nb\nbbac\naa\nb\nca\nbc\naaba\nbaaaa\nbcc\nab\na\naba\nb\nc\nba\nbc\nca\nbb\nc\nc\nca", "g\n*cc?\n93\nac\ncaab\nacaca\ncccc\nbcc\nbab\nbc\nc\nc\nbbaa\nb\ncc\ncb\naa\nabcbb\nbccc\nc\ncbcbc\nac\nca\nbcba\nbb\nbab\nba\nb\nbbba\nbabbc\nbacab\nbc\na\ncbccc\nbbaac\ncbab\ncab\ncc\ncbbcb\nc\nc\ncbaa\nca\nbacab\nc\nbcac\nbbbc\nc\nac\nccab\nccccb\ncccab\nc\nacb\nac\nbccba\nca\nbbbbc\naaca\naa\na\nbabac\nbb\nc\ncac\naca\naacb\naacbb\na\nacaab\ncbb\nbcc\ncb\nbcbaa\ncca\nb\nbaac\nbcca\nc\ncbb\nac\nc\naccc\naac\nbcbc\nabc\nbacab\nb\na\na\nbbacc\ncb\na\nccac\nb\nbbc", "c\n*\n83\nbbc\ncacb\nbcbc\naca\nba\nc\nccac\nab\nab\nbacba\nbb\nc\nbcc\nc\ncbc\ncbbb\nac\nb\nacbcb\nbccc\ncccb\nb\na\nca\nc\nccaa\naa\ncacb\nccc\na\nccc\nababb\nbab\ncaa\nbaa\na\ncc\ncbbbc\naaaa\nabbab\naabac\nbcbab\nbcb\nacaa\nbcb\na\ncca\na\nbacc\nacacb\nc\nc\ncba\nbcaca\na\ncaac\na\nb\na\nccc\naabca\nbbab\nb\nac\nbabc\nc\nac\nba\nbbcb\nc\naaab\ncab\nacb\nbba\nbbcba\nc\na\naccbb\naaccc\nac\nbaa\nbaabb\nabca", "s\n*cb\n70\nab\nccb\naaab\nb\nab\ncba\na\nbbaca\nac\nccacb\nbaabb\naaab\nccca\ncb\nba\nbccac\nc\ncc\ncbbbb\ncab\nabbb\ncbb\naabc\ncac\nacb\na\nc\nc\ncbbbb\nbaaca\ncbcc\nbc\naa\nabcb\nacbbc\nbaaa\naa\ncc\ncc\nb\nb\nbcba\ncbacc\nbcb\ncaabc\nacaac\ncb\ncba\ncbaaa\nbcaaa\naccbb\naccac\nca\nacaa\ncc\nc\nb\nbac\nb\nbab\nb\ncca\naacc\nacb\nccc\nbc\nb\naab\naaca\naac", "k\n*b\n70\ncbc\nb\ncca\nacbc\nca\nab\nc\nbbb\nbaa\nbbb\nac\nbaacc\nbaabc\naac\na\nba\nb\nc\nc\nba\ncacbb\nabb\nbc\nabcb\nca\na\nbbbbb\ncca\nccacc\ncbaca\nba\ncbcca\ncb\nc\nbbbba\ncca\nabaac\na\nac\nc\nccbc\nbcac\nbcb\na\nc\nabbca\nbaacb\ncc\nacba\nc\nbcc\ncbba\nccba\na\na\ncbb\ncba\nb\naaaac\ncb\nbaacb\nab\nc\ncbbcb\nbab\nac\nca\nc\nac\nb", "l\na*\n40\nacbb\naba\nb\naab\nbb\nbbab\ncaba\naab\naaab\nacac\nacbaa\nbca\nac\nbb\na\nba\naaa\nbc\nbba\ncca\naacab\na\nc\nca\naacaa\nbaac\nbb\nc\nba\nc\nbab\nb\na\ncabaa\nccacc\ncbbab\nbaaca\ncabb\naaccc\nbcbac", "u\ncba*\n26\ncaa\ncccb\nbc\nbacb\nca\nccaaa\nb\naaca\nba\ncacc\ncccac\nabba\nbabc\na\nac\nca\nbbba\na\naa\naaabb\nb\nc\nbba\nbbba\nacaa\nba", "cba\n?*cbc\n88\ncccca\ncbc\nb\nbcb\naaa\ncaac\nbacb\nacbb\na\nab\ncbcca\nbccc\nabcc\naca\nba\nbbac\nacc\ncba\nbcba\nbc\naa\nab\ncaba\ncccab\ncba\ncbcc\nba\ncacbb\nabcc\na\nc\nbac\nccaba\nb\nac\nbbb\nac\nccaca\na\nba\nacbcc\nbbc\nacbc\nbbabc\nccbb\nb\nacaa\na\nba\nacb\na\nab\naa\nbbbb\naabb\nbcbc\nb\nca\nb\nccab\nab\nc\nb\naabab\nc\ncbbbc\nacbbb\nbacaa\nbcccc\ncbac\nc\nac\nb\nca\ncbb\nccbc\nc\nc\nbcb\nc\nbaaba\nc\nbac\nb\nba\ncb\ncc\nbaaca", "a\naa\n1\naaa", "a\naaa\n1\naaaa", "a\naa*aa\n1\naaa", "a\nbb*bb\n1\nbbbbbbbbbbbbbbbb", "a\na*\n1\nabbbbbbb", "a\na?a\n1\naaab", "xy\ncab*aba\n1\ncaba", "a\n*\n4\nb\na\nab\nba", "abc\na?a?*a\n3\nababxa\nababca\nababa", "abc\n??a*df?c\n6\nabadfcc\naaaadfac\nbbagthfac\nacadddfac\ndaagdffc\naaaadfcc", "abc\nabc*a\n1\nabckka", "b\n*a\n1\naba", "a\nabc*g\n1\nabcdefg", "a\nab\n1\na", "abcdefghijklmnopqrstuvwxyz\n*a\n1\na", "as\naba*aba\n1\naba", "ab\naweerrtab\n4\naw\naweerrtabwqeqrw\naweerrtabxcvxcbcxbdsfdsfewrewrqweq\naweerrtabaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a\na\n1\nab", "a\na*b\n1\nabb", "a\nb*a\n1\nbbadd", "a\naaaa\n1\naaa", "z\n*abcd\n1\nggggggg", "abc\n*??\n1\nqqqqqqqqab", "b\naa\n1\na", "ab\na*pa\n1\nappppa", "a\nbbb\n1\nbbbbb", "ab\nabcd?\n1\nabcd", "c\na\n1\nab"], "outputs": ["YES\nNO", "NO\nYES\nNO\nYES", "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO", "YES\nYES\nYES\nYES\nYES\nYES\nYES\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nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO", "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "YES\nNO\nNO\nNO", "YES\nNO\nYES", "YES\nNO\nNO\nYES\nNO\nNO", "YES", "NO", "YES", "NO", "YES", "NO", "NO\nNO\nNO\nNO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "YES", "NO", "NO", "NO"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
6e3a93f64f548eb3db06492d2471a959
Alex and broken contest
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. Print "YES", if problem is from this contest, and "NO" otherwise. Sample Input Alex_and_broken_contest NikitaAndString Danil_and_Olya Sample Output NOYESNO
{"inputs": ["Alex_and_broken_contest", "NikitaAndString", "Danil_and_Olya", "Slava____and_the_game", "Olya_and_energy_drinks", "Danil_and_part_time_job", "Ann_and_books", "Olya", "Nikita", "Slava", "Vanya", "I_dont_know_what_to_write_here", "danil_and_work", "Ann", "Batman_Nananananananan_Batman", "Olya_Nikita_Ann_Slava_Danil", "its_me_Mario", "A", "Wake_up_Neo", "Hardest_problem_ever", "Nikita_Nikita", "____________________________________________________________________________________________________", "Nikitb", "Unn", "oLya_adn_smth", "FloorISLava", "ann", "aa", "AAnnnnn", "AnnAnn", "Annn", "Dilzhan", "Danilaaa", "AndAnn", "OlyaAnnAnn", "DanilDanilOlya", "DDanil", "AnnAnnDanil", "And_Danil", "abcddddDanil", "DanilOlyaOlya", "Nikitaaa", "aaabbba", "Ann_Ann_Danil", "Danil_Danil_Nikita", "AlexaaaaaaBBBBBOlyaDDDDD", "IloveDaniland", "AnAnn", "Danil_Danil_Olya", "DanilDanilSlava", "DanilDanil", "OlyOlya", "NikitaNikitb", "ababaca", "AnnNikitaNikitaNikitaNikita__good_luck"], "outputs": ["NO", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "YES", "NO", "NO", "NO", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "NO", "NO"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
246
codeforces
6e5afbd84d28e58ac91f81bf4f65bc6c
Hexadecimal's Numbers
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy. But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully. Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). Output the only number — answer to the problem. Sample Input 10 Sample Output 2
{"inputs": ["10", "20", "72", "99", "100", "101", "102", "111", "112", "745", "23536", "1", "1010011", "312410141", "1000000000", "999999999", "111111111", "101010101", "121212121", "106341103", "901556123", "832513432", "3", "732875234", "7", "9", "2", "11", "12", "13", "101020101", "111100100", "110110101", "100111001", "100100", "110100102"], "outputs": ["2", "3", "3", "3", "4", "5", "5", "7", "7", "7", "31", "1", "83", "511", "512", "511", "511", "341", "511", "383", "511", "511", "1", "511", "1", "1", "1", "3", "3", "3", "351", "484", "437", "313", "36", "421"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
156
codeforces
6e8114ca264a25df7a13855f7cf6b174
Palindrome
Given a string *s*, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of *s* and is as long as possible. The only line of the input contains one string *s* of length *n* (1<=≤<=*n*<=≤<=5·104) containing only lowercase English letters. If *s* contains a palindrome of length exactly 100 as a subsequence, print any palindrome of length 100 which is a subsequence of *s*. If *s* doesn't contain any palindromes of length exactly 100, print a palindrome that is a subsequence of *s* and is as long as possible. If there exists multiple answers, you are allowed to print any of them. Sample Input bbbabcbbb rquwmzexectvnbanemsmdufrg Sample Output bbbcbbb rumenanemur
{"inputs": ["bbbabcbbb", "rquwmzexectvnbanemsmdufrg", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "ab", "abacaba", "startcup", "aabccb", "abbacc", "iwlauggytlpahjhteurdyoaulbnnhashwktxlrhpgqnypnuitmfhhbkwysjuhljshaanowhngeaumdovrlvuofzsbhhzdyngntdu", "zypzepzqni", "a", "oliifeuoyzhkootktyulrxshmboejshoguwgufxpuloouoojovufukdokoeyouzihyaeuucutypfxictojtnfoouoniuyuvkrglsueihpuxsulrrifyuwuyolutotzozsvhoyjxuguecywbfuuqmpzooojergudvwucsocoojfplaulvfpcooxxublcfpguuoouooouo", "kyzxnaiwjgnotlekhycrnapekfcfxydbvnjboevgdzgigxvijgwrqnacumglzlxkcurmqmxzxxbuxlwruycdhzzdmtvobmvylyibyynjvonmbwvwqzmidfhnndecrwyfxjxwquiubrimmcwoeecotwnkfrojwuxmficzurwaqljfvdcvixcictxfzztzzbvbdypayhay", "carfnnnuxxbntssoxafxxbbxnonpunapjxtxexlptcwqxkjnxaanntriyunvnoxkdxnsxjxxoixyplkvxctuoenxxjixxgyxlgnxhklxqxqzxafxcnealxxwspbpcfgpnnovwrnnaxjcjpnierselogxxcxrxnlpnkbzjnqvrkurhxaxyjxxnxxnpipuntongeuusujf", "yggmkggmvkfmmsvijnyvwgswdpwkwvmcmmswksmhwwmmgwzgwkkwogwiglwggwwnmwgkqggkugwmfwawxggrwgwclgwclknltxrkjwogwejgeymtmwziwmskrwsmfmmiwkwwvsgwsdmmkfmggkmpgg", "mstmytylsulbuhumamahahbbmmtttmlulhamyhlmbulyylubmlhymahlulmtttmmbbhahamamuhubluslytymtsmxp", "ouwvwggffgoowjzkzeggbzieagwwznzzzlwvzswfznvozveezgopefecoezfsofqzqfoovaofwzgefzzweggvztzvofgevivgevwwslhofzwopopzzgfvwzeogovvgzdzafgwzshovvrwwwgmooczezivfwgybgezogsmgfgwwzevvwgeehwvegfdzgzwgzoffgteztwvgwfvogeggfogkeovxzzlzzwzzlvifgxzwvrogeeeggeoefhhzoweerwvxofgvwovozwvizofzogozgwevwllexooktoggvoeowgtezffzfdohvgmofofvwzzofwvwsfbwyzzziofvfcofmzgrofzozzgghseafefdpwwwogpzzfowfhlsoeitfogeezfagofqqesocewfpwveozeenwsvffzwozwzlwoeffzonveaivgfebvegveozzfoowzwzkwezjeeuwzgezoovwwgzgzggwzowzevwfgggoozfozfwg", "gamjuklsvzwddaocadujdmvlenyyvlflipneqofeyipmtunbdmbdyhkovnpdetueeiunsipowrhxrhtastjniqdhmehcumdcrghewljvpikcraoouhfwtnoaukbnykjapkvyakdnckkypargamvnsqtchesbmuffqqycnjvolmtpjfykvkeexkpdxjexrvdzpcbthhkxuucermkaebrvcxoovidpqnpkgbhiatyjvumihptrigqxsemqbbxwmyunmmayubqqjaioqmzyekhtqgoockiskyqihopmkastfvqiewtbtbriuyuszlndcweuhnywlkjgerqokxsxfxeaxcuwoocoonstwlxujrynkwzshpretbhlvkxyebnhafxfelpmqfkksurrfqeaykdxihtyqpaiftigdwkraxxzxkqicnfxlxhxwtkkknurzubtkivzpmlfebzduezuqeyequvyrighfzyldxenwxokumxtiieeeuku", "qpjnbjhmigtgtxolifwoyatdlqtejqovaslcgjufverrnkqxtsrrytqgtuikcseggjnltpggcpjizojthwycibvnvxetibpicujwmyzcojhpftttwvtlxaeefbvbvygouinnjrwuczlplbzahqciptrlrcuamyntvrzqxrnkrczmluocsuthwaptenwysoviwwcnrljuskynomlpslqyjcauagiveunrzognltohqxggprgreezjsqchcgihzbrleuwgnlsqeenybrbsqcnnlbipajlcfmajtchblnxsnegooewupmvufzbipnyjneuwelibvhoghtqpvqjehvpbiclalyzxzqwekemnsjabyzatjgzbrheubuzrcgtxvaokzapejesjntgnriupahoeousszcqprljhhgnqclbsuvvgfudhwmabfbyqjcqqgnnoocqxbyjpmvncmcieavcstjvvzgtbgcjbqnqbpueqlgibtvjpzsan", "nwgwxgxlbgbgnvqowqqocgwwnbnoqghxwxbbonxxgongqwbbxxbbwiqgnogxxnobmbxwxlgqonbnwhewgoqqwoqngbgbxgxwgwna", "vtaavlavalbvbbbccccddddeeeefltfffgvgvgtghlhhhiviiijjjjkkkkmmmmnnnlnooooppppqqvqqrrrrssssluuuvuwwwwtv", "iuaiubcide", "aavaaaadbbbddbbdbccccwvcceveeeedeffvdfvfffdggggvwgghhdhdwdhhhwiiwiiiiwjjjjjjkkkkdkklwvlllllmmmmmmvdnndnwndnndooowoooppppppwqwqdwqwqwdqqrdrwdrrrrsdssssvsttttttuvuuuwuuxxxdwwxwxdxyyyywyddwvdvdvdvvwddddv", "ibbbbiabbibbscccocccccdsdyddiddishddffjifhfffjffgggeggeggjgkkkjkkjkkklllaellllhlmymmmmssmmomnnanojennosasoennnjpopaopppspsyphepqaqqqjqqjqqrrjerrerrrrttttttttuuuujuhuiuuwwjwhswwwiwwxixxxyxsosixxxaizzzi", "ataaaamabbbbtmbbmtmtccctcttcmmcmtdmmmmmddddtdmeetmtmmeteteeftffmfffgmmggggmgmmhmhhhmhhiimtiiititmmjjjtjjjkkmtmtkmkmkklllmllmmtmlnmnnmnnnootooooptpppttppqmqqtqmqqmtmrrrtrrrssssssuuuuuuvvvvvvwwwwwwxxxxx", "agqdhdgqgannagbqbbhddddcgngchnhdceeqefqhgfdngfdhiiidhjgqjjndqkgqnkkgqqndlldlqqmddmmnqoqgnoqgqdopnqghdhdgpndpghqrrqdhrsnhgnssgddddhtttqgnnguqgudhuvvdqg", "hyhwkyvfpfpykwhchycwcpfppcuvuvupshcwwkwucpkppkpcuwkwwchspuvuvaucppfbpcwcyhchwkypfpfvykwhyh", "dpddpdddddidtddudddddqddddddddddddddddddddddcdddddddddddddddkkdddddgdddddddddjkdovfvvgnnvvvvvvvvvvnvvvvvkvvvvfnvuuvevvvfvvvpvvvkvvvvvvvvvlvvvifvvvvklvbvvovovvvvkvivnvvvvvvulvvvwwmjwtwwbwlwwwwwwwwwwpewewwwwwpwwwwwwwwwwwwwwwwwwlwbtwwwwjwmwwwwwlwwuwnwwwwiwwkwwwwwwwwxxxxxxoxxxoxxxbxxxxlxxxxxxxxxxxxxxxxkxxxxfixlxxxxxkpxfxxxxxxxxxxxxxexxxuuxxxxxxxxxyynyyyyyyyyyyfkyynynyynyyyyyyygyyyyyyyyyyyyyfyyoyyyyyyykyyyyyyjyyyyyyygykyykyyycyyqyzzzzzzzzzzzzzzzzzzuzzzzzzzzzzztzzzizppzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "aaaaaaaaakaaakaaaaaabbbbbbbbbbbxbbxbkbbbkxbcccccccccicccccccccddkdxdddkdkddddddkdddddikekeeeeeeeekeeeeeeeixieeffxfffffffffifffffffgikiigggggggggiggggggxgghhhhhkhhhhhhhhhhxhhhjjjjjiijjjjijjjjjxkjkjjjllllllllllkllllllllmmmmmimmmmmmmmmmmmmnnnnnnnnnnnnnnnknnnoooookooioooxioooooooopppppppppppippppxkpkkkppqqxqqqqqqqqiqiqqqqxiqqkqrrkrrrirrrrrrrrrrrrrssskskskssssssssxsssssiittttittxtttttttktttttuxuuuuuiiuuuuuuuuuuikuuvvvvivvixvvvvvvvvvivvvwxiwwwwwwwwwwwkwkwkwwwiwykyyyyyykyyykyxyyyyyyyzzzzzkzizzzzxkkxxkk", "aaaaaakaaaaaaaaaaaataaabbbbrbbbbbbbbbxbbbbbxbbbkctcccccccccccccncckcccccnddddrdddddddddddddddddnteeeeeeeeeeneteeneeeeeeeefffffffffnnffffffffnffffgggggggggtrgggrggggggggghhhhhhhhhnhhxhhhhhhhkhhhitiiiiiiiintiiiikiiiiiiiijxjjjjjjxjjjkjjjjjjjtjjjjlllllntllllllllllllkllllmmxmmmmmmmmmmmmmmmmmmmoooooooooooooonoooooooppprpppprppppptppnpppppppqqqqnnqqqqqqqqqqqqqqqqqssnsssssssstssnssssstssssuunuuuuuruunuuuuuuuukuuuuvvvvvvvvvvvvnvvvvvvvvvwwtwwwwwwwwkwwwwwwwwwxwwyyyyyyxyyyyyyyryyyyyyyyzzzzzzzztzzzzzzzkzzzzz", "afcyfydfxueffbukxgbhfkuufkbubkxiybuuufffkkyyxxbxfbffffbfxbxjxylykkmfffuuubyxkbubkfuukfbxkubffuxfyfyf", "b", "abababbabbabbabbbbbbbbabbabbaaaaaaaabbbabbabbbabbbabaaabbaba", "ttabacabadabffacavvbaeabacabadabacabafabacabavvvvdabacabzaeabacabadabacttttafba", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeee", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeee", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeeezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "qwertyuioplkjhgfdsazxcvbnm", "abaabacdefgb", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "gsayhacnaqwakieoeyomukmqueosoeuckuotyadhoniaovwgnbcpczjnibhgyapqmuosbrpqwkckqjakqjeamyqqwskmoueaakfixextmcwyaqdhtlylnowuiaaoraeskkqaohbwcupgsdcngyavctnaqaaaqomimemckzkaagaebucmjuwacaoicyoywkwmogdiknzqiakackvzgrywxfiojdkopsnsifwwcwkwuqqpfpuaeigcfjebbuakkaquajyelivanwewaq", "amltiwwuisnsaghiiwoaqgdgnpqkfudobascczacwipotugyeairyrcsgsuxxttsxaausijymcceapckvxfqnqdg", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "abababababababababababababababababababababababababcbababababababababababababababababababababababababa", "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeefeeeeeeeeeeddddddddddccccccccccbbbbbbbbbbaaaaaaaaaa"], "outputs": ["bbbcbbb", "rumenanemur", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a", "abacaba", "trt", "bccb", "abba", "ugyhhurounhashwkhnpnhkwhsahnuoruhhygu", "zpepz", "a", "ouooouoougpluoovufudooozuucuxjoouoyurlsupuslruyouoojxucuuzooodufuvooulpguoouooouo", "yahyapydbvbzixijqauzcurmmbuxwrcdhdmvbmvyybyyvmbvmdhdcrwxubmmruczuaqjixizbvbdypayhay", "fnnuxxnxxxxnnpnxxxlpcjxannrvoxxnxxxxlkxnxxixxnxklxxxxnxxovrnnaxjcplxxxnpnnxxxxnxxunnf", "ggmkggmfmmswgswwkwmmmswksmwwmmgwgwkkwgwgwggwwmwgkggkgwmwwggwgwgwkkwgwgmmwwmskwsmmmwkwwsgwsmmfmggkmgg", "mstmytylsulbuhumamahahbbmmtttmlulhamyhlmbulyylubmlhymahlulmtttmmbbhahamamuhubluslytymtsm", "gzoggwveoggvoegezfzovgofowzzowvswzovfcofzgofosfwozzowfsofogzfocfvozwsvwozzwofogvozfzegeovggoevwggozg", "uuemkexdhiyvuqequuzefvitbuzunkkxxfxxxrkwpthxyaeqfrrfqeayxhtpwkrxxxfxxkknuzubtivfezuuqequvyihdxekmeuu", "nspjvglqeqcgbgsenybqcnncjbwuvublghpqehpinsjazatgruurgtazajsnipheqphglbuvuwbjcnncqbynesgbgcqeqlgvjpsn", "nwgwxgxbgbgnqowqqogwwnbnoqgxwxbbonxxgongqwbbxxbbwqgnogxxnobbxwxgqonbnwwgoqqwoqngbgbxgxwgwn", "vtvlvlvltgvgvgtlvlvlvtv", "iuiui", "vddddwvvdvdvdvwddwdwwwdwvvddwdqqdwqwqwdqqdwddvvwdwwwdwddwvdvdvdvvwddddv", "iiaisosyiishjihjeejjjaehyssoaojnnosasonnjoaossyheajjjeejhijhsiiysosiaii", "tmtmmtmttttmmmtmmmmmtmtmtmmtttmmmgggggmmmtttmmtmtmtmmmmmtmmmttttmtmmtmt", "gqdhdgqgnngqhddddgnghnhdqqhgdngdhdhgqndqgqngqqnddqqddnqqgnqgqdnqghdhdgndghqqdhnhgngddddhqgnngqgdhdqg", "hyhwkyvfpfpykwhchycwcpfppcuvuvupshcwwkwucpkppkpcuwkwwchspuvuvucppfpcwcyhchwkypfpfvykwhyh", "pnuuefpklifklboowwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwooblkfilkpfeuunp", "kxkkxikxkkkikkkixixiikiiixkxiiixkkkikkixippppppppppppppppppixikkikkkxiiixkxiiikiixixikkkikkkxkixkkxk", "ktrxxktnknrntntnnnntrrnxktnjjjjjjjjjjkjjjjjjjjjjntkxnrrtnnnntntnrnkntkxxrtk", "fyfyfxuffbukxbfkuufkbubkxybuuufffkkyyxxbxfbffffbfxbxxyykkfffuuubyxkbubkfuukfbxkubffuxfyfyf", "b", "ababbaababbbbbbabbabbaaaaaaaabbabbabbbbbbabaabbaba", "abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacaba", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "q", "abaaba", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "qwaieyuqueeukodoiwgcznigowkcaawmueaakemaqtynuoakkaounytqamekaaeumwaackwoginzcgwiodokueeuquyeiawq", "gdnqfcacyisuxttxusiycacfqndg", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "abababababababababababababababababababababababababbababababababababababababababababababababababababa", "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeeeeeeeeeeeddddddddddccccccccccbbbbbbbbbbaaaaaaaaaa"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
6e860da383f076b1aad581c40df6343a
Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size *w*<=×<=*h*, represented by a rectangle with corners (0,<=0), (*w*,<=0), (*w*,<=*h*) and (0,<=*h*). It can be seen that no collisions will happen before one enters the stage. On the sides of the stage stand *n* dancers. The *i*-th of them falls into one of the following groups: - Vertical: stands at (*x**i*,<=0), moves in positive *y* direction (upwards); - Horizontal: stands at (0,<=*y**i*), moves in positive *x* direction (rightwards). According to choreography, the *i*-th dancer should stand still for the first *t**i* milliseconds, and then start moving in the specified direction at 1 unit per millisecond, until another border is reached. It is guaranteed that no two dancers have the same group, position and waiting time at the same time. When two dancers collide (i.e. are on the same point at some time when both of them are moving), they immediately exchange their moving directions and go on. Dancers stop when a border of the stage is reached. Find out every dancer's stopping position. The first line of input contains three space-separated positive integers *n*, *w* and *h* (1<=≤<=*n*<=≤<=100<=000, 2<=≤<=*w*,<=*h*<=≤<=100<=000) — the number of dancers and the width and height of the stage, respectively. The following *n* lines each describes a dancer: the *i*-th among them contains three space-separated integers *g**i*, *p**i*, and *t**i* (1<=≤<=*g**i*<=≤<=2, 1<=≤<=*p**i*<=≤<=99<=999, 0<=≤<=*t**i*<=≤<=100<=000), describing a dancer's group *g**i* (*g**i*<==<=1 — vertical, *g**i*<==<=2 — horizontal), position, and waiting time. If *g**i*<==<=1 then *p**i*<==<=*x**i*; otherwise *p**i*<==<=*y**i*. It's guaranteed that 1<=≤<=*x**i*<=≤<=*w*<=-<=1 and 1<=≤<=*y**i*<=≤<=*h*<=-<=1. It is guaranteed that no two dancers have the same group, position and waiting time at the same time. Output *n* lines, the *i*-th of which contains two space-separated integers (*x**i*,<=*y**i*) — the stopping position of the *i*-th dancer in the input. Sample Input 8 10 8 1 1 10 1 4 13 1 7 1 1 8 2 2 2 0 2 5 14 2 6 0 2 6 1 3 2 3 1 1 2 2 1 1 1 1 5 Sample Output 4 8 10 5 8 8 10 6 10 2 1 8 7 8 10 6 1 3 2 1 1 3
{"inputs": ["8 10 8\n1 1 10\n1 4 13\n1 7 1\n1 8 2\n2 2 0\n2 5 14\n2 6 0\n2 6 1", "3 2 3\n1 1 2\n2 1 1\n1 1 5", "1 10 10\n1 8 1", "3 4 5\n1 3 9\n2 1 9\n1 2 8", "10 500 500\n2 88 59\n2 470 441\n1 340 500\n2 326 297\n1 74 45\n1 302 273\n1 132 103\n2 388 359\n1 97 68\n2 494 465", "20 50000 50000\n2 45955 55488\n1 19804 29337\n2 3767 90811\n2 24025 33558\n1 46985 56518\n2 21094 30627\n2 5787 15320\n1 4262 91306\n2 37231 46764\n1 18125 27658\n1 36532 12317\n1 31330 40863\n1 18992 28525\n1 29387 38920\n1 44654 54187\n2 45485 55018\n2 36850 46383\n1 44649 54182\n1 40922 50455\n2 12781 99825", "20 15 15\n2 7 100000\n1 2 100000\n2 1 100000\n1 9 100000\n2 4 100000\n2 3 100000\n2 14 100000\n1 6 100000\n1 10 100000\n2 5 100000\n2 13 100000\n1 8 100000\n1 13 100000\n1 14 100000\n2 10 100000\n1 5 100000\n1 11 100000\n1 12 100000\n1 1 100000\n2 2 100000", "5 20 20\n1 15 3\n2 15 3\n2 3 1\n2 1 0\n1 16 4", "15 80 80\n2 36 4\n2 65 5\n1 31 2\n2 3 1\n2 62 0\n2 37 5\n1 16 4\n2 47 2\n1 17 5\n1 9 5\n2 2 0\n2 62 5\n2 34 2\n1 33 1\n2 69 3", "15 15 15\n1 10 1\n2 11 0\n2 6 4\n1 1 0\n1 7 5\n1 14 3\n1 3 1\n1 4 2\n1 9 0\n2 10 1\n1 12 1\n2 2 0\n1 5 3\n2 3 0\n2 4 2", "5 5 5\n1 1 0\n2 1 0\n2 2 1\n1 2 1\n2 4 3"], "outputs": ["4 8\n10 5\n8 8\n10 6\n10 2\n1 8\n7 8\n10 6", "1 3\n2 1\n1 3", "8 10", "3 5\n4 1\n2 5", "500 494\n97 500\n340 500\n302 500\n500 470\n500 88\n500 326\n132 500\n500 388\n74 500", "18125 50000\n50000 45955\n50000 12781\n31330 50000\n50000 5787\n40922 50000\n44649 50000\n50000 3767\n19804 50000\n44654 50000\n36532 50000\n50000 37231\n46985 50000\n50000 45485\n50000 21094\n18992 50000\n29387 50000\n50000 24025\n50000 36850\n4262 50000", "15 7\n15 2\n1 15\n9 15\n15 4\n15 3\n14 15\n6 15\n15 10\n5 15\n13 15\n8 15\n15 13\n15 14\n10 15\n15 5\n11 15\n12 15\n15 1\n2 15", "16 20\n15 20\n20 3\n20 1\n20 15", "80 37\n80 65\n31 80\n80 3\n80 62\n33 80\n16 80\n80 47\n17 80\n9 80\n80 2\n80 62\n80 36\n80 34\n80 69", "15 10\n12 15\n3 15\n1 15\n15 2\n15 11\n7 15\n15 6\n10 15\n9 15\n14 15\n5 15\n15 4\n15 3\n4 15", "5 2\n5 4\n2 5\n5 1\n1 5"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
6e98357b8c0bdb3110306bd85830da4a
Convert to Ones
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones. Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$. You can apply the following operations any number of times: - Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $a$ of length $n$, consisting of zeros and ones. Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations. Sample Input 5 1 10 01000 5 10 1 01000 7 2 3 1111111 Sample Output 11 2 0
{"inputs": ["5 1 10\n01000", "5 10 1\n01000", "7 2 3\n1111111", "1 60754033 959739508\n0", "1 431963980 493041212\n1", "1 314253869 261764879\n0", "1 491511050 399084767\n1", "2 163093925 214567542\n00", "2 340351106 646854722\n10", "2 222640995 489207317\n01", "2 399898176 552898277\n11", "2 690218164 577155357\n00", "2 827538051 754412538\n10", "2 636702427 259825230\n01", "2 108926899 102177825\n11", "3 368381052 440077270\n000", "3 505700940 617334451\n100", "3 499624340 643020827\n010", "3 75308005 971848814\n110", "3 212627893 854138703\n001", "3 31395883 981351561\n101", "3 118671447 913685773\n011", "3 255991335 385910245\n111", "3 688278514 268200134\n000", "3 825598402 445457315\n100", "3 300751942 45676507\n010", "3 517900980 438071829\n110", "3 400190869 280424424\n001", "3 577448050 344115384\n101", "3 481435271 459737939\n011", "3 931962412 913722450\n111", "4 522194562 717060616\n0000", "4 659514449 894317797\n1000", "4 71574977 796834337\n0100", "4 248832158 934154224\n1100", "4 71474110 131122047\n0010", "4 308379228 503761290\n1010", "4 272484957 485636409\n0110", "4 662893590 704772137\n1110", "4 545183479 547124732\n0001", "4 684444619 722440661\n1001", "4 477963686 636258459\n0101", "4 360253575 773578347\n1101", "4 832478048 910898234\n0011", "4 343185412 714767937\n1011", "4 480505300 892025118\n0111", "4 322857895 774315007\n1111", "4 386548854 246539479\n0000", "4 523868742 128829368\n1000", "4 956155921 11119257\n0100", "4 188376438 93475808\n1100", "4 754947032 158668188\n0010", "4 927391856 637236921\n1010", "4 359679035 109461393\n0110", "4 991751283 202031630\n1110", "4 339351517 169008463\n0001", "4 771638697 346265644\n1001", "4 908958584 523522825\n0101", "4 677682252 405812714\n1101", "4 815002139 288102603\n0011", "4 952322026 760327076\n1011", "4 663334158 312481698\n0111", "4 840591339 154834293\n1111", "14 3 11\n10110100011001", "19 1 1\n1010101010101010101", "1 10 1\n1", "1 100 1\n1", "5 1000 1\n11111", "5 10 1\n11111", "7 3 2\n1111111", "5 1 10\n10101", "1 3 2\n1", "2 10 1\n11", "4 148823922 302792601\n1010", "1 2 1\n1", "5 2 3\n00011", "1 5 0\n1", "7 2 3\n1001001", "10 1 1000000000\n1111010111", "25 999999998 999999999\n1011001110101010100111001", "2 0 1\n00", "2 1 100\n10", "7 20 3\n1111111", "1 1 0\n1", "3 1 10\n010", "2 1 0\n11", "7 100 3\n1111111", "5 1 1000\n10101", "5 2 1\n11111", "1 1000 1\n1", "1 799543940 488239239\n1", "6 1 1000\n010101", "5 11 1\n11111", "5 2 3\n10101", "3 10 1\n111", "7 9 10\n1001011", "5 5 6\n10101", "1 1000000000 0\n1", "4 0 1\n0101", "8 2 3\n10101010", "6 3 100\n010101", "3 3 2\n111", "1 20 1\n1", "2 1 2\n01"], "outputs": ["11", "2", "0", "959739508", "0", "261764879", "0", "214567542", "646854722", "489207317", "0", "577155357", "754412538", "259825230", "0", "440077270", "617334451", "1142645167", "971848814", "854138703", "981351561", "913685773", "0", "268200134", "445457315", "91353014", "438071829", "280424424", "344115384", "459737939", "0", "717060616", "894317797", "868409314", "934154224", "202596157", "812140518", "758121366", "704772137", "547124732", "722440661", "1114222145", "773578347", "910898234", "714767937", "892025118", "0", "246539479", "128829368", "22238514", "93475808", "317336376", "1274473842", "218922786", "202031630", "169008463", "346265644", "1047045650", "405812714", "288102603", "760327076", "312481698", "0", "20", "9", "0", "0", "0", "0", "0", "11", "0", "0", "451616523", "0", "3", "0", "5", "1000000001", "7999999985", "1", "100", "0", "0", "11", "0", "0", "1001", "0", "0", "0", "1002", "0", "5", "0", "19", "11", "0", "1", "9", "106", "0", "0", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
118
codeforces
6e9dcbd071b375bcf1238a31296b6008
Bear and Big Brother
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob? The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. Sample Input 4 7 4 9 1 1 Sample Output 2 3 1
{"inputs": ["4 7", "4 9", "1 1", "4 6", "1 10", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "1 8", "1 9", "1 10", "2 2", "2 3", "2 4", "2 5", "2 6", "2 7", "2 8", "2 9", "2 10", "3 3", "3 4", "3 5", "3 6", "3 7", "3 8", "3 9", "3 10", "4 4", "4 5", "4 6", "4 7", "4 8", "4 9", "4 10", "5 5", "5 6", "5 7", "5 8", "5 9", "5 10", "6 6", "6 7", "6 8", "6 9", "6 10", "7 7", "7 8", "7 9", "7 10", "8 8", "8 9", "8 10", "9 9", "9 10", "10 10", "10 10", "1 2"], "outputs": ["2", "3", "1", "2", "6", "1", "2", "3", "4", "4", "5", "5", "6", "6", "6", "1", "2", "2", "3", "3", "4", "4", "4", "4", "1", "1", "2", "2", "3", "3", "3", "3", "1", "1", "2", "2", "2", "3", "3", "1", "1", "1", "2", "2", "2", "1", "1", "1", "2", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
631
codeforces
6eb3acd71c00c75cca50a5dd39bc7fab
Defining Macros
Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use. In this problem we consider the following model of #define constructions (also called macros). Each macro has its name and value. The generic syntax for declaring a macro is the following: #define macro_name macro_value After the macro has been declared, "macro_name" is replaced with "macro_value" each time it is met in the program (only the whole tokens can be replaced; i.e. "macro_name" is replaced only when it is surrounded by spaces or other non-alphabetic symbol). A "macro_value" within our model can only be an arithmetic expression consisting of variables, four arithmetic operations, brackets, and also the names of previously declared macros (in this case replacement is performed sequentially). The process of replacing macros with their values is called substitution. One of the main problems arising while using macros — the situation when as a result of substitution we get an arithmetic expression with the changed order of calculation because of different priorities of the operations. Let's consider the following example. Say, we declared such a #define construction: #define sum x + y and further in the program the expression "2 * sum" is calculated. After macro substitution is performed we get "2 * x + y", instead of intuitively expected "2 * (x + y)". Let's call the situation "suspicious", if after the macro substitution the order of calculation changes, falling outside the bounds of some macro. Thus, your task is to find out by the given set of #define definitions and the given expression if this expression is suspicious or not. Let's speak more formally. We should perform an ordinary macros substitution in the given expression. Moreover, we should perform a "safe" macros substitution in the expression, putting in brackets each macro value; after this, guided by arithmetic rules of brackets expansion, we can omit some of the brackets. If there exist a way to get an expression, absolutely coinciding with the expression that is the result of an ordinary substitution (character-by-character, but ignoring spaces), then this expression and the macros system are called correct, otherwise — suspicious. Note that we consider the "/" operation as the usual mathematical division, not the integer division like in C/C++. That's why, for example, in the expression "a*(b/c)" we can omit brackets to get the expression "a*b/c". The first line contains the only number *n* (0<=≤<=*n*<=≤<=100) — the amount of #define constructions in the given program. Then there follow *n* lines, each of them contains just one #define construction. Each construction has the following syntax: #define name expression where - name — the macro name, - expression — the expression with which the given macro will be replaced. An expression is a non-empty string, containing digits,names of variables, names of previously declared macros, round brackets and operational signs +-*/. It is guaranteed that the expression (before and after macros substitution) is a correct arithmetic expression, having no unary operations. The expression contains only non-negative integers, not exceeding 109. All the names (#define constructions' names and names of their arguments) are strings of case-sensitive Latin characters. It is guaranteed that the name of any variable is different from any #define construction. Then, the last line contains an expression that you are to check. This expression is non-empty and satisfies the same limitations as the expressions in #define constructions. The input lines may contain any number of spaces anywhere, providing these spaces do not break the word "define" or the names of constructions and variables. In particular, there can be any number of spaces before and after the "#" symbol. The length of any line from the input file does not exceed 100 characters. Output "OK", if the expression is correct according to the above given criterion, otherwise output "Suspicious". Sample Input 1 #define sum x + y 1 * sum 1 #define sum (x + y) sum - sum 4 #define sum x + y #define mul a * b #define div a / b #define expr sum + mul * div * mul expr 3 #define SumSafe (a+b) #define DivUnsafe a/b #define DenominatorUnsafe a*b ((SumSafe) + DivUnsafe/DivUnsafe + x/DenominatorUnsafe) Sample Output Suspicious OK OK Suspicious
{"inputs": ["1\n#define sum x + y\n1 * sum", "1\n#define sum (x + y)\nsum - sum", "4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr", "3\n#define SumSafe (a+b)\n#define DivUnsafe a/b\n#define DenominatorUnsafe a*b\n((SumSafe) + DivUnsafe/DivUnsafe + x/DenominatorUnsafe)", "0\naa + b - c * (ddd * eee / fff * a / b * c + d - b + c - (a + b)) - d", "2\n#define a b\n#define c d\na + b + c + d + 1234567 -10*(2-2+1000*1000*1000*1000*1000)", "2\n # define macros ( x + y ) \n # define Macros (x+y)\nmacros/Macros", "2\n#define A v\n#define a v/v/v\nv/A", "2\n#define A v\n#define a v/v/v\nv/a", "2\n#define A v\n#define a v/v/v\nv/(a)", "1\n#define a x*y\nc/a", "1\n#define a b*c\na/a*a", "3\n#define mul x*y\n#define bad x/mul\n#define good x/(mul)\ngood", "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define mult a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nsum+difference+(sum)*(difference)-mult+mult*division+division*mult+division/(mult+sum-(difference))", "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n(difference/division)+sum", "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n(difference)*sum", "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n(sum)/multiplication", "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nsum/(multiplication)", "5\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n#define res (0-difference)\nsum+res*multiplication", "4\n#define sum xx+yy\n#define difference aaaa-bbbBBBB\n#define multiplication a*b\n#define division aaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\ndivision/(multiplication/(division)/DIVISION/(sum-division-multiplication-(difference)))", "3\n#define sum x + y\n#define SomeBad (2 * sum)\n#define SomePossiblyGood 0 * SomeBad + (x + x - 2*x) * SomeBad\nSomePossiblyGood", "2\n#define a 0\n#define b (a-a)*(x/x-1)\nb-b/b*b", "2\n#define fkdsjfslkjfsdk x/0\n#define fkdsjfslkjfsdksdds 0/(0-0)\nfkdsjfslkjfsdk + fkdsjfslkjfsdks + fkdsjfslkjfsdkssds", "3\n#define null x/0\n#define some x/x\n#define bad 1/x\nbad/0+0/bad+0/0*bad", "3\n#define MWjGY x+x*53 *x\n#define ovqZ 2/926+x/A\n#define uU 55-qRj*A*2\nx*A/x-A", "4\n#define zz 5+7/x*x*9\n#define mlTL 6+x/7+x/x\n#define DUO 7*7-x+zz\n#define IH 6*4-x+x\n67/(5)-IH", "5\n#define Oc 9/51+65+vN\n#define gga 53/ 94/x/x\n#define ArB x/x/9-77-8\n#define j 76-6/93+vN\n#define cALNN Oc+60499\n8*6-66/x*x", "3\n#define fSdvwOj (W)*W+73\n#define NAZjc 7695*55-x\n#define AHGGglVwch (6-a-W)\n((5))+W+W", "4\n#define m bJJD +x \n#define yYkQNzjR (x*19)-892\n#define MNvfxqfbq (x-6*x/8)\n#define nJZdvO 8/4 *m/m\n 9+m/x+x", "5\n#define Sl x*7-(x)/O\n#define srAOHccTln 3+x*2*O\n#define OFAZk 239751817\n#define JYWrOEgazV (x-O/4)-x\n#define XsOZvalgOh 89905879/7\nx/Sl-(Sl)", "3\n#define uYdw ((9-x-3) )\n#define fy (((x+21)))\n#define nY ((2+x)-46)\n141141432", "4\n#define GCvqH (58 )-(x)\n#define g ((x/x+x))\n#define spst hQTJ\n#define i GCvqH\n(((x+6)))", "5\n#define rg (67)+((x))\n#define ya x-(6/x)*rg\n#define anTxe 10*ya*(x)\n#define xcmo ((x)*(vT))\n#define eg ((vT)) -ya\n((x*(Ii)))", "3\n#define T ((b/1 +1))\n#define pm (s)-43-(s)\n#define jkNBpvDZl ((x ))/65\n(((58*7)))", "4\n#define cJitUt 21/(4)+4+4\n#define zHwBOLIvF 4*((41/x))\n#define GbtYVo (E)+(x+3)\n#define zTcZBaby (58)+x-x+x\n(E+E)/8 *4", "5\n#define mBURKdeKvy 266693986\n#define nWi ( ((x))-4)\n#define iYreeOt ((7/x+42))\n#define laLzP ((aB/35)) \n#define dXjRJ (((B*hX)))\n(1*2+(67))", "3\n#define UVMQLGvEqOxaAgRkvJH tBd\n#define QoAsBMaUcJzXai x/x-hm/83+8*8/5/hm /x/hm\n#define QtxtzEHCmidm 75 +491928441\n((x)/VUpYoEdDUtLFanGyqfQR )", "4\n#define efemx 2/1*3*69+81+10/690445104\n#define AyjrEzAjMKZpRPfCOaO 21*9+( j*40+3*4)*ND+w-j*j+x*55\n#define YkJkHcNhXcci 85*3215/40/365819568\n#define MUzvOZSXJujI 9-4/j*j-7-w*23*5+j+9-9*ND*2/37\nND/j*28 -1* ND+22889023/j/j/j", "5\n#define QNUkjqPcGWF 6*4/908975666-7/10-x*7\n#define xqwhNWiiMaZOcmgiXYY 3936*(e*5*H+2)-TsA+(e)/1-25\n#define tRsSqfqJt ((uT*82/e)+e/(23+(45)-9)+(50))\n#define DtIOWRkYe (8*3/9)*e*x *60041512*2-(e)\n#define qgPgxja (4/x+e/uT*16358009- 6/13*5)\ne+x*e/84/x+uT*H", "3\n#define lTCUUO JQmj\n#define oUeQMB (12*x+x+x)-75-(79/1)-(7)*1/mr\n#define LAQu xwvBtky\n8654 *1*5-mr-3*J/oUeQMB/x/6/9", "4\n#define VLuQIO 1-x/33+ Fk+wS/35-wS-(x*iz )\n#define BCIsIR 5*(wS)/x/iz/1+x-x-4-x/68/x/8*x\n#define QPUpmTiB 21-x/895912506+2\n#define wcZLUIqJS 7/65-x*61-(24+iz)+x+315670+x/x\nBCIsIR/VLuQIO", "5\n#define FDmMYOENCOKmYwYlOl 6-(L)/((((ud/x))/ud-26*8-5))\n#define QkopKBjKdJxhc (6)*4/7-L/781844832 \n#define UjgTieUBXTSTbiLFAhkV 3*1*(52)/6-6*65/x+((L-56))+x+x\n#define yWVYDuqliezpKLwnI 8/4+1+88+97946+(1)-((68))-L/L\n#define AvvED 719901121+95/2/78/1-10+37\n(1*x+ 528176190+17/ud)", "3\n#define e x *R/5+(x)+4/18/x*R/x-8+1+R\n#define GgGqGYjXoJjIezAVu (( 491563947*R))*9-e-3/4\n#define XgznGUWMxQwh (8/R+4*(e)+10/4*x+24*R+21)-224\n (82493582)", "4\n#define MrKSTrKhPLeJqOcEPvv (x+x/x)/Qdf-x-x-(2/23)+9442-x\n#define zPHUgmIYE 10- 7*x/x+VwRUuIRezDR*80\n#define OsfThxasHeFZCEZTfD 271456028-(x*x)-8+2*x*x*x+(x)\n#define zVYasB x/x -x-(51)-x*x*((x)) /x \n(x/64-x*( (5+x+x)-(37)/3*22))", "5\n#define WREol (fcdGZaLzhiFpVQmhHO)\n#define lDTNxcMqPPP 3+(57)/x/91540-x*71-x*6-((1))\n#define afFJVBkr ((12*x-8+9 *lDlx+7+lDlx))\n#define mYEizEWrNtRSQNCcDQrn 732480960+9+x-78-x/1+12*x\n#define IZTmjheAahbNSNFa ((x-x*7+407643063 ))\nXQvMxLNpQnhpimNhAkfX", "3\n#define Mc x+x*55231- x/x/x+35/x*(5*(x)) -5*x*(1-2-(29/1))\n#define afSVLCdjvylSu bgqv/6+4*x*((Mc/1318/x-8-4)-Mc/Mc/(9))\n#define ZOSV (1+2/x+6* 174806683)-x/x*Mc+52*x-x\nbgqv-x-6*x/72/(x )/afSVLCdjvylSu", "4\n#define RJIiiGQqn dmpWFcrqQeM+V-o* 55/9*o-o/V*V*o\n#define ElDZlrtzDkeKgsX 498718105* 3/(y)/(4)-(5*x)*1\n#define qwKl jHqPHX\n#define qXzAZkCuchBYR (qy*qwKl-6+5*1+2)-7-3+(38)-o*4/4-1-V*x/6+1*x/o\no*((V))-o+2+((((2*V)/V-o*V/4)))/o*33+y/7 -x+x ", "5\n#define WTovyGexUNjGMRJv (MQG*18-6)/x/x*x/x-x*akNyw*x+x-x/2/x*20\n#define hpextyhVCa 70*x/67-x*87931-(497612505-7*x-MQG)-x\n#define MRkKnCXFt x-5-21962-x/sOmThNSS/x/6-4+(65+57+x+x+7-7+x/x)\n#define ajsczBLLklBSqqh nGj-38*9 *x/47/8*5/5-72/x*x-x*x*31 /7-44-3+64\n#define jgqfv WTovyGexUNjGMRJv\n 4+338/x*x+13 -795*3-74*2/4+563-x/76401438/83025", "3\n#define G u+13-35348/2-(u/u)-u/u*u*(OC)-OC -u-u/u*u/9 \n#define RNRQ G*G*u+G/755750/G/G +((u-6*G+6)*2)- 5*96+5/u*275-u\n#define Zg 94363/u*u-41+Gm*G-81/5-1-G*G*x-(5517*5/4)*21 +75\n406690013/WM*G+(u+u)*Zg+2", "4\n#define RMWAZhIp x*x+12+94*12*5*1-x-141915293\n#define EeguG 9-55+x/29+x+x/E*8*81/x-x*75-4*17-81/x/6+619978*x*x\n#define HvUYEvQTyYmBGvqHSb 454574730/644135926*x/23+E-sy/14\n#define BqMGcT x/(43)+819897061-x*(7/x)-(x)+sy-E-x*79-E+(x)/6/63\n76+3/x/8*x+E-76+sy-sy+9*6/66/sy-77+x-x*sy+E/50/64", "5\n#define cbt ((((d))+9-3+ (d)/d/6*SDDNqj*50/d+d-m+8/d/1)) \n#define gLrUE 18+ 70*d/3-d*d-d/35 +33-5/9+d-d*387+d-1\n#define AvjmK 9-d-8+(d+m+5/2/x*d+1)/x/d-5-2*(m)+d+17/d+ 4/52/8\n#define SjrJ 90/7/5/d+ 254877982+(m) *x-19\n#define PlykoqfDbwxR 540304590 +d*x/11-(m+d-d-4)*(d-3-1)/d\nd-2+1+46-29620+9-(9*3 /d)*6*m/d+9+(1670)/cbt/d+d", "3\n#define BuAiJLgAlkj x-3+419032556/409023036-(17*84)+x+8+A\n#define wU 516506880\n#define HeyDGlnaGxBaHjzelvF iRSPqHfgHw/4-(99)*(I)+A+I-9*46*x\nI/CRklg-HeyDGlnaGxBaHjzelvF/3+5 ", "4\n#define SOlTohcPGckDyF ((D)/G-83+KHGSuJFLHqD/5)\n#define KEUXeOYpg 9+x-8-8/x/9-65-6+4+55*x-58/x+84+D*2-7+D/x-x*G/4-2\n#define YZl (1/67*x*6/2*G)-D/1595107*D+6/x*1+D+3/9/x/26-6+9 \n#define gCatFsZn uBBqilYclMhpVfKKTkGK\n(28682537+ YZl*(4*52) )*x/8- gCatFsZn*x/54/7", "5\n#define iiXEqDYeyVmIYsOaO fj/x-9-6/x*x+ 1/ 7*2-x -x+9+235*23*Ww+x-2*K+2-x/70\n#define XVgLzhoTUxoBr ( x+x/x/x*6-x)* x+K/24206-2 /5/8-x-7/Ww/K-x+6 \n#define QdfRBaJk 470551685-( 54-x)-30\n#define gEJcAGnF x+x-x+(x/x+9)/x-41-1/fj/1157561+x/x -x/26/x+K*x\n#define lO 7-1*(x*58 )-K*fj /722113691/x/K+2\n2+4*85/86/x*27 /49252-x*x/6-83-7/x+x+K-lO+8-K-x", "1\n#define sum x+y\nr-sum", "1\n#define sum x+y\nr+sum", "1\n#define sum x+y\nr*sum", "1\n#define sum x+y\nr/sum", "1\n#define sum x-y\nr+sum", "1\n#define sum x-y\nr-sum", "1\n#define sum x-y\nr*sum", "1\n#define sum x-y\nr/sum", "1\n#define sum x*y\nr+sum", "1\n#define sum x*y\nr-sum", "1\n#define sum x*y\nr*sum", "1\n#define sum x*y\nr/sum", "1\n#define sum x/y\nr+sum", "1\n#define sum x/y\nr-sum", "1\n#define sum x/y\nr*sum", "1\n#define sum x/y\nr/sum", "1\n#define sum x+y\nsum+r", "1\n#define sum x+y\nsum-r", "1\n#define sum x+y\nsum*r", "1\n#define sum x+y\nsum/r", "1\n#define sum x-y\nsum+r", "1\n#define sum x-y\nsum-r", "1\n#define sum x-y\nsum*r", "1\n#define sum x-y\nsum/r", "1\n#define sum x*y\nsum+r", "1\n#define sum x*y\nsum-r", "1\n#define sum x*y\nsum*r", "1\n#define sum x*y\nsum/r", "1\n#define sum x/y\nsum+r", "1\n#define sum x/y\nsum-r", "1\n#define sum x/y\nsum*r", "1\n#define sum x/y\nsum/r", "1\n#define x 3/2\n2*x", "2\n # define sum 1000000000 + 1000000000 + 1000000000 \n # define a b + 45 * sum \n a "], "outputs": ["Suspicious", "OK", "OK", "Suspicious", "OK", "OK", "OK", "OK", "Suspicious", "OK", "Suspicious", "Suspicious", "OK", "OK", "Suspicious", "Suspicious", "Suspicious", "Suspicious", "Suspicious", "OK", "Suspicious", "Suspicious", "OK", "Suspicious", "OK", "Suspicious", "OK", "OK", "Suspicious", "Suspicious", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "Suspicious", "Suspicious", "OK", "OK", "OK", "OK", "Suspicious", "OK", "OK", "Suspicious", "OK", "OK", "Suspicious", "Suspicious", "Suspicious", "Suspicious", "OK", "Suspicious", "Suspicious", "OK", "Suspicious", "Suspicious", "Suspicious", "OK", "OK", "OK", "Suspicious", "OK", "OK", "OK", "Suspicious", "OK", "OK", "Suspicious", "Suspicious", "OK", "OK", "Suspicious", "Suspicious", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "Suspicious"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
6ec23bfaec147ed3968f9eb421419a85
Sorting Railway Cars
An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train? The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train. The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train. Print a single integer — the minimum number of actions needed to sort the railway cars. Sample Input 5 4 1 2 5 3 4 4 1 3 2 Sample Output 2 2
{"inputs": ["5\n4 1 2 5 3", "4\n4 1 3 2", "1\n1", "2\n1 2", "2\n2 1", "6\n5 3 6 1 4 2", "7\n1 2 3 6 7 4 5", "8\n6 2 1 8 5 7 3 4", "3\n1 2 3", "3\n1 3 2", "3\n2 1 3", "3\n2 3 1", "3\n3 1 2", "3\n3 2 1", "7\n1 3 5 7 2 4 6", "7\n1 5 2 6 3 7 4", "5\n1 4 2 3 5", "9\n1 6 4 5 9 8 7 3 2", "10\n5 1 6 2 8 3 4 10 9 7", "50\n39 8 41 9 45 1 5 18 38 31 28 7 12 49 33 19 26 6 42 13 37 27 2 21 20 22 14 16 48 47 32 50 25 17 35 24 36 4 29 15 43 10 11 30 40 46 3 23 44 34", "50\n43 15 10 33 32 31 13 7 5 22 36 1 25 14 38 19 8 6 24 42 28 21 44 35 4 3 49 30 27 46 2 9 17 37 45 41 18 39 12 11 16 20 50 26 29 34 40 47 48 23", "50\n10 40 34 43 50 17 15 13 9 2 32 18 11 46 27 24 36 16 29 45 42 4 47 19 48 37 41 5 21 26 22 25 44 31 35 49 20 8 12 23 6 38 14 1 7 28 3 33 39 30", "50\n10 37 3 46 45 29 36 13 21 25 35 5 18 33 12 19 50 16 30 47 20 42 39 28 2 6 38 8 7 31 22 27 26 9 15 14 34 48 4 32 40 43 44 24 11 1 23 17 49 41", "50\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 42 37 38 39 40 41 36 43 44 45 46 47 48 49 50", "50\n1 2 3 4 5 6 7 8 43 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 50 33 34 35 36 37 38 39 40 41 42 9 44 45 46 47 48 49 32", "50\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 49 40 41 47 43 44 45 46 42 50 39 48", "50\n1 2 3 4 27 6 7 8 9 10 30 12 13 14 15 16 17 18 19 20 21 22 23 24 28 26 5 25 29 11 31 32 33 34 38 36 37 35 39 40 41 42 43 44 45 46 47 48 49 50", "50\n1 2 3 4 5 6 7 49 9 10 17 12 13 14 15 16 11 18 19 20 21 22 23 24 25 26 27 38 29 36 30 32 33 34 35 31 37 28 39 40 41 42 43 44 45 46 47 48 8 50", "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 31 18 19 20 21 23 22 24 25 26 27 28 29 49 17 32 33 34 39 36 37 38 47 44 41 42 43 40 45 46 35 48 30 50", "50\n1 2 15 4 5 6 7 8 9 10 11 12 13 14 3 16 17 18 19 32 21 22 36 28 23 26 27 24 29 30 31 20 33 34 37 25 35 38 40 39 41 42 43 44 45 46 47 48 49 50", "5\n4 3 1 2 5", "6\n1 3 5 6 4 2", "10\n2 1 4 3 6 5 8 7 10 9", "5\n1 2 4 5 3", "7\n1 4 2 3 7 6 5", "4\n3 1 2 4", "6\n2 5 4 3 6 1", "5\n1 3 4 5 2", "6\n2 4 6 5 1 3", "6\n1 2 4 5 6 3", "9\n9 8 7 4 5 6 3 2 1", "7\n4 1 2 3 6 5 7"], "outputs": ["2", "2", "0", "0", "1", "4", "2", "5", "0", "1", "1", "1", "1", "2", "5", "3", "2", "7", "6", "46", "47", "46", "46", "14", "27", "11", "36", "38", "33", "39", "3", "4", "8", "2", "4", "2", "4", "2", "4", "3", "6", "4"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
82
codeforces
6eec6d76e2ac4d80c0ce716c2185a9b9
Lizards and Basements 2
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced. Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the *i*-th archer with his fire ball (they are numbered from left to right), the archer loses *a* health points. At the same time the spell damages the archers adjacent to the *i*-th (if any) — they lose *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=10) health points each. As the extreme archers (i.e. archers numbered 1 and *n*) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball. The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies? Polycarp can throw his fire ball into an archer if the latter is already killed. The first line of the input contains three integers *n*,<=*a*,<=*b* (3<=≤<=*n*<=≤<=10; 1<=≤<=*b*<=&lt;<=*a*<=≤<=10). The second line contains a sequence of *n* integers — *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=15), where *h**i* is the amount of health points the *i*-th archer has. In the first line print *t* — the required minimum amount of fire balls. In the second line print *t* numbers — indexes of the archers that Polycarp should hit to kill all the archers in *t* shots. All these numbers should be between 2 and *n*<=-<=1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order. Sample Input 3 2 1 2 2 2 4 3 1 1 4 1 1 Sample Output 3 2 2 2 4 2 2 3 3
{"inputs": ["3 2 1\n2 2 2", "4 3 1\n1 4 1 1", "3 5 3\n1 2 1", "3 5 3\n3 2 2", "3 5 3\n3 2 2", "3 5 1\n10 10 10", "3 5 3\n10 9 7", "3 5 1\n1 9 10", "3 5 3\n10 9 7", "3 5 2\n9 3 6", "4 5 3\n2 2 2 1", "4 5 3\n2 3 2 2", "4 5 3\n4 2 4 2", "4 5 1\n4 9 1 8", "4 5 3\n9 9 3 4", "4 5 1\n8 8 9 8", "4 5 3\n10 10 10 10", "4 5 2\n7 3 8 5", "4 5 3\n5 10 7 7", "4 3 1\n8 10 9 7", "10 9 5\n12 14 11 11 14 14 12 15 14 12", "10 5 2\n12 10 6 7 11 4 3 5 9 3", "10 4 1\n5 12 10 5 13 6 5 5 2 10", "10 10 1\n10 12 11 4 12 1 15 15 11 12", "10 9 1\n6 12 9 3 7 3 3 11 13 10", "10 9 1\n8 7 9 8 14 1 9 11 8 13", "10 4 3\n9 11 9 11 4 5 7 13 12 9", "10 8 2\n11 10 13 12 9 10 9 9 10 12", "10 3 1\n9 6 8 7 10 10 9 6 6 7", "10 4 1\n6 5 4 5 5 4 5 4 5 4", "10 4 3\n2 1 2 4 2 4 3 2 2 4", "10 3 1\n4 4 3 3 3 3 2 1 3 1", "10 7 1\n3 3 2 1 3 1 2 2 3 1", "10 10 1\n8 8 8 8 8 8 8 8 8 8", "10 4 1\n11 9 11 10 10 11 9 10 9 11", "10 4 2\n10 9 14 9 13 11 14 10 14 10", "10 8 6\n14 12 14 12 10 8 10 13 9 12", "10 4 1\n7 8 9 8 8 7 8 9 7 7", "10 2 1\n9 10 9 9 10 9 9 10 9 10", "10 9 4\n11 10 10 10 10 12 10 10 10 12", "10 10 4\n1 1 1 1 1 1 1 1 1 1", "10 2 1\n9 12 12 8 8 5 14 10 7 3", "10 2 1\n14 15 15 14 15 15 15 14 14 14", "10 6 3\n9 8 8 8 11 11 9 10 9 11", "10 6 2\n11 8 10 11 10 8 8 13 9 13", "10 3 1\n3 7 9 12 11 3 4 3 14 8", "10 4 1\n6 7 10 7 6 8 9 8 6 9", "10 7 2\n2 9 2 6 8 7 6 5 6 2", "10 7 3\n2 7 2 7 3 4 3 2 4 3", "10 6 3\n8 9 8 9 8 9 10 9 8 9", "10 2 1\n10 9 10 9 9 9 10 8 8 10", "10 4 3\n4 4 5 6 4 6 4 5 5 4", "10 9 2\n5 7 8 8 7 5 7 4 4 5", "10 9 5\n8 7 5 9 8 7 8 11 11 8", "10 7 4\n5 6 6 6 7 7 6 5 5 5", "10 9 1\n10 11 11 11 11 11 11 11 11 11", "10 5 1\n6 5 6 5 6 6 6 5 6 6", "10 3 1\n8 7 9 7 9 12 12 6 8 8", "10 4 2\n7 3 5 3 5 5 3 4 2 4", "10 7 2\n5 2 5 3 2 3 4 3 5 3", "10 2 1\n5 3 6 6 7 4 4 4 3 3", "10 6 1\n13 13 13 13 13 13 13 13 13 13", "10 2 1\n14 11 11 11 15 15 12 15 12 14", "10 7 1\n9 15 15 11 8 10 13 9 15 9", "10 10 4\n12 12 14 13 14 12 14 14 11 14", "10 6 4\n5 5 5 5 5 5 5 6 4 4", "10 8 7\n15 15 15 15 15 15 15 15 15 15", "10 9 5\n11 10 4 4 6 9 11 4 10 8", "10 6 3\n9 12 8 11 7 14 8 5 15 10", "10 3 1\n4 4 4 4 3 4 3 3 3 3", "10 6 4\n11 10 10 10 12 12 12 10 10 10", "10 6 1\n3 2 4 4 8 12 5 10 12 6", "10 9 5\n13 13 13 13 13 12 12 12 12 12", "10 4 1\n7 7 6 6 6 8 6 7 6 7", "10 6 3\n13 10 12 10 9 12 11 8 12 12", "10 6 2\n1 4 5 4 4 2 3 6 6 4", "10 8 1\n12 6 7 9 3 12 5 9 5 11", "10 4 2\n13 14 10 6 8 7 8 8 11 5", "10 8 1\n3 4 5 6 4 6 5 6 5 4", "10 7 2\n12 10 9 9 15 15 10 14 15 15", "10 3 1\n9 9 8 8 8 9 9 8 8 8", "10 2 1\n5 4 5 4 4 4 4 4 4 5", "10 6 5\n11 8 5 13 8 9 11 15 11 12", "10 5 1\n7 10 15 5 15 5 5 5 11 7", "10 3 2\n5 5 4 4 4 4 4 4 5 4", "10 6 2\n5 8 4 5 1 3 6 7 5 3", "10 5 2\n10 12 10 10 11 9 11 11 9 9", "10 6 5\n9 8 10 10 11 11 8 9 10 11", "10 3 2\n3 5 1 4 5 3 3 1 3 4", "10 3 2\n4 9 6 9 6 8 4 5 6 9", "10 3 2\n8 9 8 9 8 8 8 8 8 8", "10 2 1\n11 6 9 9 11 10 7 13 11 9", "10 6 1\n4 5 5 3 7 5 6 5 6 8", "10 9 6\n15 14 14 12 15 10 9 14 13 8", "10 7 1\n9 9 9 9 9 9 9 9 9 9", "10 6 5\n4 5 4 1 3 6 3 2 2 2", "10 10 3\n10 8 11 11 10 11 11 9 7 10", "10 3 2\n7 8 11 6 8 7 2 3 8 7", "10 8 6\n9 9 8 10 7 13 7 11 13 12", "10 3 2\n9 13 9 10 12 10 14 13 11 11", "10 3 2\n12 12 14 15 15 12 12 14 12 14", "10 7 4\n6 4 8 4 8 7 10 6 8 6", "10 5 4\n14 14 14 10 13 15 13 13 10 14", "10 10 2\n10 10 13 10 10 12 6 8 11 12", "10 6 4\n5 6 5 6 6 7 5 7 9 9", "10 7 5\n10 10 10 10 10 10 10 10 10 10", "10 5 1\n11 10 10 10 11 11 11 10 11 11", "10 10 4\n13 13 13 13 13 13 13 13 13 13", "10 5 2\n4 5 3 6 7 8 4 4 9 6", "10 7 3\n5 9 8 8 8 7 6 7 6 5", "10 2 1\n12 13 15 14 14 11 12 14 11 15", "10 2 1\n13 12 15 12 14 14 14 15 13 15", "10 2 1\n14 15 15 14 14 15 14 15 14 15", "10 2 1\n9 7 14 8 14 15 15 9 12 13", "10 2 1\n14 15 15 14 15 14 15 14 15 15", "10 2 1\n9 7 14 8 14 15 15 9 12 13", "10 2 1\n4 14 13 15 14 5 8 11 12 14"], "outputs": ["3\n2 2 2 ", "4\n2 2 3 3 ", "1\n2 ", "2\n2 2 ", "2\n2 2 ", "11\n2 2 2 2 2 2 2 2 2 2 2 ", "4\n2 2 2 2 ", "11\n2 2 2 2 2 2 2 2 2 2 2 ", "4\n2 2 2 2 ", "5\n2 2 2 2 2 ", "2\n2 3 ", "2\n2 3 ", "3\n2 2 3 ", "14\n2 2 2 2 2 3 3 3 3 3 3 3 3 3 ", "6\n2 2 2 2 3 3 ", "18\n2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 ", "8\n2 2 2 2 3 3 3 3 ", "7\n2 2 2 2 3 3 3 ", "5\n2 2 3 3 3 ", "17\n2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 ", "10\n2 2 2 4 5 6 7 9 9 9 ", "13\n2 2 2 2 2 2 2 4 5 5 7 9 9 ", "25\n2 2 2 2 2 2 3 4 5 5 5 6 7 8 9 9 9 9 9 9 9 9 9 9 9 ", "30\n2 2 2 2 2 2 2 2 2 2 2 4 5 5 7 7 9 9 9 9 9 9 9 9 9 9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 3 4 4 4 4 5 5 5 5 5 6 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
6ef0e2137716f500bd93702edd34f22b
Propagating tree
Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of *n* nodes numbered from 1 to *n*, each node *i* having an initial value *a**i*. The root of the tree is node 1. This tree has a special property: when a value *val* is added to a value of node *i*, the value -*val* is added to values of all the children of node *i*. Note that when you add value -*val* to a child of node *i*, you also add -(-*val*) to all children of the child of node *i* and so on. Look an example explanation to understand better how it works. This tree supports two types of queries: - "1 *x* *val*" — *val* is added to the value of node *x*; - "2 *x*" — print the current value of node *x*. In order to help Iahub understand the tree better, you must answer *m* queries of the preceding type. The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=1000). Each of the next *n*–1 lines contains two integers *v**i* and *u**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*), meaning that there is an edge between nodes *v**i* and *u**i*. Each of the next *m* lines contains a query in the format described above. It is guaranteed that the following constraints hold for all queries: 1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*val*<=≤<=1000. For each query of type two (print the value of node *x*) you must print the answer to the query on a separate line. The queries must be answered in the order given in the input. Sample Input 5 5 1 2 1 1 2 1 2 1 3 2 4 2 5 1 2 3 1 1 2 2 1 2 2 2 4 Sample Output 3 3 0
{"inputs": ["5 5\n1 2 1 1 2\n1 2\n1 3\n2 4\n2 5\n1 2 3\n1 1 2\n2 1\n2 2\n2 4", "10 10\n137 197 856 768 825 894 86 174 218 326\n7 8\n4 7\n8 9\n7 10\n1 2\n2 4\n3 6\n3 5\n2 3\n1 9 624\n2 1\n2 4\n1 6 505\n1 8 467\n1 3 643\n2 1\n1 8 631\n2 4\n1 7 244", "10 10\n418 45 865 869 745 901 177 773 854 462\n4 8\n1 4\n3 6\n1 5\n1 10\n5 9\n1 2\n4 7\n1 3\n2 2\n1 6 246\n1 4 296\n1 2 378\n1 8 648\n2 6\n1 5 288\n1 6 981\n1 2 868\n2 7"], "outputs": ["3\n3\n0", "137\n768\n137\n768", "45\n1147\n-119"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
6ef6aa8c3cea245a90dd5d88c9e3b6e7
Captains Mode
Kostya is a progamer specializing in the discipline of Dota 2. Valve Corporation, the developer of this game, has recently released a new patch which turned the balance of the game upside down. Kostya, as the captain of the team, realizes that the greatest responsibility lies on him, so he wants to resort to the analysis of innovations patch from the mathematical point of view to choose the best heroes for his team in every game. A Dota 2 match involves two teams, each of them must choose some heroes that the players of the team are going to play for, and it is forbidden to choose the same hero several times, even in different teams. In large electronic sports competitions where Kostya's team is going to participate, the matches are held in the Captains Mode. In this mode the captains select the heroes by making one of two possible actions in a certain, predetermined order: pick or ban. - To pick a hero for the team. After the captain picks, the picked hero goes to his team (later one of a team members will play it) and can no longer be selected by any of the teams. - To ban a hero. After the ban the hero is not sent to any of the teams, but it still can no longer be selected by any of the teams. The team captain may miss a pick or a ban. If he misses a pick, a random hero is added to his team from those that were available at that moment, and if he misses a ban, no hero is banned, as if there was no ban. Kostya has already identified the strength of all the heroes based on the new patch fixes. Of course, Kostya knows the order of picks and bans. The strength of a team is the sum of the strengths of the team's heroes and both teams that participate in the match seek to maximize the difference in strengths in their favor. Help Kostya determine what team, the first one or the second one, has advantage in the match, and how large the advantage is. The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the number of heroes in Dota 2. The second line contains *n* integers *s*1, *s*2, ..., *s**n* (1<=≤<=*s**i*<=≤<=106) — the strengths of all the heroes. The third line contains a single integer *m* (2<=≤<=*m*<=≤<=*min*(*n*,<=20)) — the number of actions the captains of the team must perform. Next *m* lines look like "*action* *team*", where *action* is the needed action: a pick (represented as a "p") or a ban (represented as a "b"), and *team* is the number of the team that needs to perform the action (number 1 or 2). It is guaranteed that each team makes at least one pick. Besides, each team has the same number of picks and the same number of bans. Print a single integer — the difference between the strength of the first team and the strength of the second team if the captains of both teams will act optimally well. Sample Input 2 2 1 2 p 1 p 2 6 6 4 5 4 5 5 4 b 2 p 1 b 1 p 2 4 1 2 3 4 4 p 2 b 2 p 1 b 1 Sample Output 1 0 -2
{"inputs": ["2\n2 1\n2\np 1\np 2", "6\n6 4 5 4 5 5\n4\nb 2\np 1\nb 1\np 2", "4\n1 2 3 4\n4\np 2\nb 2\np 1\nb 1", "4\n1 2 3 5\n4\nb 2\np 1\np 2\nb 1", "6\n6 7 8 1 2 3\n6\nb 1\np 1\np 2\nb 2\np 2\np 1", "8\n1 2 3 4 5 6 7 8\n6\np 1\np 2\np 2\np 1\np 1\np 2", "8\n1 2 4 8 16 32 64 128\n8\nb 1\np 2\nb 2\np 1\nb 2\np 1\nb 1\np 2", "100\n94 46 36 81 100 20 36 55 53 97 25 93 99 50 47 61 42 21 66 74 38 71 30 5 10 33 5 33 21 65 98 13 84 96 73 31 36 10 33 48 55 18 52 65 16 29 31 69 28 52 37 25 49 96 18 98 68 99 2 47 92 6 77 65 43 71 5 40 25 66 5 77 41 73 90 44 45 53 22 89 16 32 90 88 5 15 33 23 30 55 89 92 67 77 42 89 26 48 56 29\n20\np 1\np 2\np 2\np 1\np 1\np 1\np 2\np 1\np 1\np 2\nb 2\np 2\nb 1\nb 2\nb 2\nb 2\np 2\nb 1\nb 1\nb 1", "100\n88 33 90 2 35 49 78 76 46 43 46 89 41 15 19 57 39 2 37 18 71 91 5 38 88 60 57 21 86 68 92 25 11 92 61 12 78 44 66 81 4 97 10 100 24 6 5 57 85 72 36 57 52 56 100 82 41 2 41 49 82 61 65 60 1 67 92 63 32 39 14 100 33 38 10 53 21 53 51 26 19 75 84 1 71 9 46 88 13 83 10 19 37 89 30 44 2 65 75 60\n20\np 1\np 1\nb 2\np 1\nb 1\np 1\nb 1\nb 1\nb 1\np 2\np 2\np 2\np 2\nb 1\nb 2\nb 1\nb 2\nb 2\nb 2\nb 2", "4\n4 4 4 1\n4\nb 1\nb 2\np 1\np 2", "4\n4 3 2 1\n4\nb 1\nb 2\np 2\np 1", "4\n1 2 4 5\n4\nb 2\np 1\np 2\nb 1", "4\n1 2 4 5\n4\nb 2\nb 1\np 1\np 2", "4\n5 4 2 1\n4\nb 2\nb 1\np 2\np 1", "6\n7 6 6 6 3 2\n6\nb 1\nb 2\np 1\np 2\np 2\np 1", "6\n1 2 3 6 7 8\n6\nb 1\np 2\np 1\np 1\nb 2\np 2", "6\n6 7 8 1 2 3\n6\nb 1\np 1\np 2\np 2\np 1\nb 2", "8\n1 2 3 4 5 6 7 8\n8\nb 1\nb 2\np 1\np 2\np 2\np 1\np 1\np 2", "100\n14 25 3 3 14 45 7 74 4 81 7 10 62 90 25 82 92 39 1 55 55 51 94 25 20 77 38 69 8 14 6 77 96 43 32 61 84 77 98 94 29 50 71 27 40 66 63 41 54 89 64 16 39 14 77 81 17 51 87 87 24 13 63 68 2 38 41 55 50 78 41 2 34 64 37 39 30 73 7 72 76 25 54 52 20 58 94 8 23 38 18 33 97 74 11 35 33 3 68 49\n20\np 2\np 1\nb 1\nb 2\nb 2\np 2\np 1\nb 1\np 2\np 1\np 2\np 2\np 2\np 1\np 2\np 2\np 1\np 1\np 1\np 1", "100\n6 43 9 46 3 100 58 24 2 77 98 55 44 32 16 38 100 95 56 81 17 64 83 53 98 68 9 6 63 97 24 54 22 54 81 33 88 47 92 56 4 52 86 96 85 88 34 86 17 36 22 82 21 63 44 54 76 76 32 93 46 97 86 30 88 20 86 49 84 42 37 58 71 86 90 70 66 12 36 91 28 75 28 20 56 17 53 44 32 55 86 1 94 28 40 91 68 89 62 57\n20\np 1\nb 2\nb 2\nb 2\nb 1\np 2\nb 1\nb 2\np 1\nb 2\nb 1\nb 2\np 2\nb 2\nb 1\nb 1\nb 1\nb 1\nb 1\nb 2", "14\n32 22 37 76 66 96 70 16 87 57 56 78 32 94\n14\np 1\np 1\nb 1\np 1\nb 1\np 2\np 1\np 2\np 2\np 2\nb 1\nb 2\nb 2\nb 2", "14\n40 26 97 41 91 40 91 34 52 38 92 66 76 56\n14\np 1\nb 2\nb 1\nb 2\nb 2\nb 1\np 1\nb 1\np 2\np 2\np 2\np 1\np 1\np 2", "14\n85 41 58 94 50 56 76 83 37 16 26 72 28 61\n14\np 2\nb 2\np 1\np 2\nb 1\nb 1\np 2\nb 2\nb 1\np 1\np 1\np 2\np 1\nb 2", "14\n35 86 25 96 18 24 10 49 7 76 92 2 75 74\n14\np 1\nb 1\np 1\nb 1\np 1\np 1\nb 2\np 2\nb 1\np 2\np 2\np 2\nb 2\nb 2", "14\n97 84 46 77 67 40 75 1 15 84 48 3 20 68\n14\nb 2\np 1\np 1\nb 1\np 2\np 2\np 1\np 2\nb 1\np 2\nb 1\nb 2\np 1\nb 2", "16\n11 24 75 46 8 57 91 2 75 36 42 11 28 44 17 17\n16\nb 1\nb 2\np 1\np 1\np 1\np 2\np 2\nb 2\nb 2\nb 1\nb 2\nb 1\np 2\np 1\np 2\nb 1", "16\n76 62 98 40 52 72 84 100 74 66 56 61 5 43 100 82\n16\np 2\nb 1\np 2\nb 2\np 1\nb 2\np 1\nb 2\nb 1\nb 1\nb 2\nb 1\np 2\np 2\np 1\np 1", "16\n12 28 50 20 6 11 49 7 5 49 36 23 76 8 27 77\n16\nb 1\np 2\nb 2\nb 1\nb 2\np 1\np 2\np 1\np 2\nb 1\np 2\np 1\nb 2\nb 2\np 1\nb 1", "16\n68 61 10 72 14 53 81 24 4 72 85 42 59 62 39 55\n16\nb 1\nb 2\nb 2\np 1\nb 1\np 2\np 2\np 2\np 1\nb 1\nb 2\np 2\nb 1\nb 2\np 1\np 1", "16\n72 64 24 27 71 84 45 47 36 33 94 15 1 40 2 3\n16\nb 1\np 1\nb 1\np 2\np 2\np 1\nb 2\np 1\np 1\nb 2\np 2\np 2\nb 2\nb 1\nb 2\nb 1", "18\n69 3 91 93 4 29 30 33 41 97 45 90 48 9 1 90 77 16\n18\nb 2\nb 1\np 1\np 2\np 1\nb 1\np 2\np 2\nb 2\np 1\np 1\nb 1\nb 1\np 1\np 2\nb 2\np 2\nb 2", "18\n42 36 10 39 92 70 33 33 75 38 4 32 86 29 13 25 53 47\n18\np 2\np 1\np 2\nb 2\np 1\np 2\nb 1\np 2\nb 2\np 1\np 1\nb 1\np 1\nb 1\np 2\nb 2\nb 1\nb 2", "18\n33 12 22 8 33 98 66 87 65 8 21 88 54 82 89 38 57 23\n18\np 1\nb 2\nb 1\nb 2\nb 2\nb 1\nb 2\np 2\np 1\np 2\nb 1\nb 1\np 1\np 1\np 2\np 1\np 2\np 2", "18\n5 43 41 3 60 34 67 71 97 11 56 21 75 23 2 46 46 76\n18\nb 2\nb 2\np 1\nb 1\nb 2\nb 2\nb 1\np 2\nb 1\np 2\np 2\nb 1\np 2\np 2\np 1\np 1\np 1\np 1", "18\n69 97 12 87 3 44 36 83 23 33 7 31 89 67 13 76 51 33\n18\np 2\nb 1\nb 1\nb 1\nb 1\np 1\nb 2\np 2\nb 2\np 1\nb 2\nb 2\np 1\np 1\np 1\np 2\np 2\np 2", "20\n68 9 33 68 7 18 43 51 26 12 61 95 82 16 43 83 51 97 15 55\n20\nb 2\nb 1\np 2\nb 1\np 2\nb 1\np 2\np 1\nb 1\nb 1\np 1\np 2\np 2\np 1\nb 2\nb 2\nb 2\np 1\np 1\nb 2", "20\n88 91 6 31 26 14 87 57 82 76 12 38 8 80 59 97 68 40 72 61\n20\nb 1\np 2\np 2\nb 1\np 2\nb 2\nb 2\np 2\np 1\nb 2\np 1\np 1\np 2\np 1\nb 1\nb 1\np 1\nb 1\nb 2\nb 2", "20\n14 14 59 42 11 15 33 76 15 48 90 6 49 15 75 76 33 25 34 48\n20\np 2\np 2\np 1\np 2\np 1\np 1\np 1\nb 1\nb 1\nb 2\nb 1\nb 1\nb 2\nb 1\np 2\np 1\nb 2\nb 2\nb 2\np 2", "20\n83 48 5 20 15 18 92 78 17 60 71 19 42 64 18 42 70 27 25 92\n20\nb 2\np 1\np 2\np 2\np 1\nb 2\nb 1\np 2\nb 1\np 1\np 1\np 2\np 2\nb 2\nb 2\np 1\nb 2\nb 1\nb 1\nb 1", "20\n19 16 77 41 51 96 2 6 17 78 4 15 56 61 37 42 75 81 78 97\n20\np 1\nb 1\nb 1\np 1\np 2\np 1\nb 2\nb 1\nb 1\np 1\nb 2\nb 1\nb 2\np 2\nb 2\np 1\nb 2\np 2\np 2\np 2", "8\n100 100 100 60 1 1 1 1\n6\nb 1\np 2\np 1\np 1\np 2\nb 2", "20\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10\n20\nb 1\nb 2\nb 1\nb 2\nb 1\nb 2\nb 1\nb 2\nb 1\nb 2\nb 1\nb 2\nb 1\nb 2\nb 1\nb 2\nb 1\nb 2\np 1\np 2", "4\n1 1 50 100\n4\nb 1\np 1\nb 2\np 2", "6\n100 99 50 10 9 1\n6\nb 1\np 2\np 1\np 2\np 1\nb 2", "6\n1 2 3 4 5 6\n4\nb 1\np 1\np 2\nb 2"], "outputs": ["1", "0", "-2", "1", "0", "1", "-45", "14", "35", "0", "-2", "1", "3", "-1", "-3", "3", "1", "1", "-36", "4", "125", "56", "-56", "234", "5", "100", "-66", "-59", "-56", "41", "52", "-35", "86", "-123", "55", "-137", "-120", "-24", "-9", "196", "99", "0", "99", "-2", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
6f1948aa1a3f58e6b1b4feacc7b7e014
Tower of Hanoi
The Tower of Hanoi is a well-known mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 1. Only one disk can be moved at a time. 1. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack. 1. No disk may be placed on top of a smaller disk. With three disks, the puzzle can be solved in seven moves. The minimum number of moves required to solve a Tower of Hanoi puzzle is 2*n*<=-<=1, where *n* is the number of disks. (c) Wikipedia. SmallY's puzzle is very similar to the famous Tower of Hanoi. In the Tower of Hanoi puzzle you need to solve a puzzle in minimum number of moves, in SmallY's puzzle each move costs some money and you need to solve the same puzzle but for minimal cost. At the beginning of SmallY's puzzle all *n* disks are on the first rod. Moving a disk from rod *i* to rod *j* (1<=≤<=*i*,<=*j*<=≤<=3) costs *t**ij* units of money. The goal of the puzzle is to move all the disks to the third rod. In the problem you are given matrix *t* and an integer *n*. You need to count the minimal cost of solving SmallY's puzzle, consisting of *n* disks. Each of the first three lines contains three integers — matrix *t*. The *j*-th integer in the *i*-th line is *t**ij* (1<=≤<=*t**ij*<=≤<=10000; *i*<=≠<=*j*). The following line contains a single integer *n* (1<=≤<=*n*<=≤<=40) — the number of disks. It is guaranteed that for all *i* (1<=≤<=*i*<=≤<=3), *t**ii*<==<=0. Print a single integer — the minimum cost of solving SmallY's puzzle. Sample Input 0 1 1 1 0 1 1 1 0 3 0 2 2 1 0 100 1 2 0 3 0 2 1 1 0 100 1 2 0 5 Sample Output 7 19 87
{"inputs": ["0 1 1\n1 0 1\n1 1 0\n3", "0 2 2\n1 0 100\n1 2 0\n3", "0 2 1\n1 0 100\n1 2 0\n5", "0 5835 1487\n6637 0 9543\n6961 6820 0\n7", "0 3287 5433\n6796 0 5787\n1445 6158 0\n26", "0 4449 3122\n6816 0 8986\n1048 1468 0\n4", "0 913 8129\n8352 0 4408\n9073 7625 0\n30", "0 8392 3430\n5262 0 6256\n8590 8091 0\n29", "0 6593 2887\n9821 0 7109\n8501 917 0\n11", "0 2957 4676\n9787 0 1241\n5147 8582 0\n8", "0 4085 4623\n1929 0 2793\n902 8722 0\n11", "0 1404 2399\n3960 0 9399\n7018 4159 0\n34", "0 1429 1052\n4984 0 2116\n4479 782 0\n21", "0 3844 8950\n8110 0 8591\n5977 4462 0\n7", "0 7336 3824\n3177 0 6795\n4491 7351 0\n28", "0 8518 8166\n799 0 266\n7987 4940 0\n15", "0 2990 3624\n5985 0 9822\n3494 6400 0\n15", "0 3003 1005\n4320 0 1463\n4961 5563 0\n40", "0 9916 3929\n5389 0 6509\n2557 4099 0\n38", "0 2653 5614\n9654 0 8668\n6421 133 0\n40", "0 6103 5951\n3308 0 8143\n3039 2918 0\n40", "0 1655 1941\n7562 0 6518\n8541 184 0\n38", "0 7561 1463\n7621 0 9485\n1971 1024 0\n38", "0 5903 6945\n5521 0 2812\n8703 8684 0\n38", "0 5382 7365\n7671 0 679\n3183 2634 0\n40", "0 3448 4530\n6398 0 5321\n1302 139 0\n39", "0 5105 2640\n1902 0 9380\n302 3014 0\n38", "0 9756 5922\n9233 0 8371\n6826 8020 0\n40", "0 1177 7722\n4285 0 8901\n3880 8549 0\n40", "0 3792 500\n1183 0 3169\n1357 9914 0\n40", "0 7600 9420\n2996 0 974\n2995 3111 0\n39", "0 65 3859\n6032 0 555\n6731 9490 0\n38", "0 3341 2142\n452 0 4434\n241 8379 0\n38", "0 2975 131\n4408 0 8557\n7519 8541 0\n40", "0 5638 2109\n3346 0 1684\n2770 8831 0\n40", "0 649 576\n2780 0 6415\n7629 1233 0\n38", "0 5222 6817\n8403 0 6167\n2424 2250 0\n39", "0 9628 4599\n6755 0 5302\n5753 1995 0\n39", "0 9358 745\n7093 0 7048\n1767 5267 0\n39", "0 4405 3533\n8676 0 3288\n1058 5977 0\n38", "0 1096 1637\n5625 0 4364\n8026 7246 0\n39", "0 8494 3561\n8215 0 9313\n1980 9423 0\n39", "0 3461 4834\n1096 0 3259\n8158 3363 0\n40", "0 2986 6350\n59 0 9863\n8674 1704 0\n40", "0 7829 1008\n2914 0 2636\n4439 8654 0\n39", "0 6991 1482\n1274 0 6332\n7588 5049 0\n38", "0 4499 7885\n6089 0 8400\n8724 2588 0\n40", "0 9965 5863\n5956 0 3340\n9497 5040 0\n38", "0 5125 2904\n763 0 4213\n4171 3367 0\n38", "0 328 3888\n3730 0 760\n9382 6574 0\n38", "0 6082 5094\n2704 0 991\n7522 6411 0\n40", "0 655 1599\n4254 0 7484\n3983 9099 0\n39", "0 1099 3412\n9261 0 3868\n758 8489 0\n38", "0 8246 1436\n8823 0 5285\n8283 7277 0\n39", "0 1446 2980\n9298 0 9679\n7865 6963 0\n38", "0 10000 10000\n10000 0 10000\n10000 10000 0\n40", "0 1 1\n1 0 1\n1 1 0\n1", "0 1 10\n1 0 1\n10 1 0\n1", "0 1 10\n1 0 1\n10 1 0\n1", "0 1 100\n1 0 1\n100 1 0\n1"], "outputs": ["7", "19", "87", "723638", "293974120391", "73486", "6310499935698", "3388490535940", "11231429", "1162341", "7450335", "79409173073874", "5047111802", "875143", "1538910647942", "162320667", "175936803", "3633519425831590", "1482783056079892", "6216516575480675", "5710985562714285", "1280396561454826", "1219526376186314", "1709923833066384", "4417349048592850", "1967209554081624", "912380857210937", "8928156585485415", "5921725291311720", "3176855596478157", "2526066880932431", "1040962633462383", "740490539331253", "5516494172354496", "4211129534337070", "731862427166001", "2978027243887585", "2894220024221629", "2711090254202573", "1089982526985246", "2596191288960748", "3798507254080314", "4092687698447757", "4350584259212361", "2446779875619187", "1272852690054827", "7298008429373546", "1907744300121994", "1013123610034430", "1073001180618872", "5301967237043705", "2158371867244476", "975259178289234", "3474823247533881", "1747643190259529", "10995116277750000", "1", "2", "2", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
6f32c4a1bdb0354e980a56e43f7f70b4
Matrix Walk
There is a matrix *A* of size *x*<=×<=*y* filled with integers. For every , *A**i*,<=*j*<==<=*y*(*i*<=-<=1)<=+<=*j*. Obviously, every integer from [1..*xy*] occurs exactly once in this matrix. You have traversed some path in this matrix. Your path can be described as a sequence of visited cells *a*1, *a*2, ..., *a**n* denoting that you started in the cell containing the number *a*1, then moved to the cell with the number *a*2, and so on. From the cell located in *i*-th line and *j*-th column (we denote this cell as (*i*,<=*j*)) you can move into one of the following cells: 1. (*i*<=+<=1,<=*j*) — only if *i*<=&lt;<=*x*; 1. (*i*,<=*j*<=+<=1) — only if *j*<=&lt;<=*y*; 1. (*i*<=-<=1,<=*j*) — only if *i*<=&gt;<=1; 1. (*i*,<=*j*<=-<=1) — only if *j*<=&gt;<=1. Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know *x* and *y* exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer *a*1, then move to the cell containing *a*2 (in one step), then move to the cell containing *a*3 (also in one step) and so on. Can you choose *x* and *y* so that they don't contradict with your sequence of moves? The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of cells you visited on your path (if some cell is visited twice, then it's listed twice). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — the integers in the cells on your path. If all possible values of *x* and *y* such that 1<=≤<=*x*,<=*y*<=≤<=109 contradict with the information about your path, print NO. Otherwise, print YES in the first line, and in the second line print the values *x* and *y* such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109. Sample Input 8 1 2 3 6 9 8 5 2 6 1 2 1 2 5 3 2 1 10 Sample Output YES 3 3 NO YES 4 9
{"inputs": ["8\n1 2 3 6 9 8 5 2", "6\n1 2 1 2 5 3", "2\n1 10", "3\n1 2 2", "1\n1", "1\n6", "2\n2 3", "2\n1000000000 1", "4\n3 2 4 2", "5\n1 2 5 4 3", "2\n1 1", "3\n1 3 4", "1\n1000000000", "6\n1 4 5 6 3 2", "8\n1 2 3 6 9 8 7 6", "9\n4 3 2 1 5 6 7 8 9", "8\n2 5 8 9 6 3 2 1", "4\n1 2 1 3", "3\n1 4 3", "5\n1 2 3 4 1", "6\n3 5 2 1 2 1", "2\n1000000000 999999999", "3\n2 4 3", "5\n1 2 3 2 4", "6\n10 8 6 4 2 1", "7\n1 4 7 8 9 10 11", "8\n1 2 3 2 3 4 3 8", "4\n3 4 3 5", "4\n1 4 3 2", "13\n1 3 4 6 5 3 1 2 4 6 5 3 1", "3\n1 3 2", "6\n4 3 6 9 8 7", "6\n1 2 4 3 5 6", "5\n1 2 4 3 1", "5\n1 2 4 3 5", "5\n3 6 5 4 3", "37\n94 7 32 29 57 22 11 70 57 61 12 75 93 24 4 47 98 43 99 22 50 32 37 64 80 9 40 87 38 70 17 41 77 76 20 66 48", "2\n99999999 100000000", "5\n3 4 5 6 2", "6\n3 8 7 6 5 4", "10\n999999999 999999998 999999997 999999996 999999995 999999994 999999993 999999992 999999991 999999990", "2\n1000000000 999999998", "5\n8 9 10 14 13", "4\n1 3 2 4", "4\n2 3 5 6", "5\n1 2 3 4 2", "3\n5 6 4", "1\n1000000", "3\n9 10 1", "28\n1 3 5 7 9 10 8 6 4 2 1 2 4 3 5 6 8 7 9 10 8 7 5 6 4 3 1 2", "5\n3 4 5 6 9", "3\n6 8 7", "1\n100000000", "6\n2 4 6 5 6 5", "2\n999999999 1000000000", "4\n3 6 7 8", "23\n92 34 58 40 76 3 38 66 76 23 85 36 47 43 22 46 98 72 97 80 57 77 96", "3\n6 7 4", "4\n1 2 4 3", "3\n3 2 4", "5\n1 4 3 2 1", "5\n1 3 5 4 3", "3\n19260816 19260817 19260818", "3\n1 3 6", "2\n999999998 1000000000", "8\n2 4 6 5 6 5 3 4", "3\n4 3 6", "2\n246642 246641", "3\n9 7 5", "10\n1 2 1 2 1 2 1 2 1 2", "5\n1 3 5 7 8", "4\n1 10 9 10", "2\n2 4", "8\n1 2 4 3 5 6 8 7", "3\n4 3 2", "3\n3 2 1", "4\n999 1000 2000 2001", "3\n4 2 5", "2\n500000000 1000000000", "3\n4 5 7", "5\n1 3 4 5 4", "7\n550 555 554 553 554 555 560"], "outputs": ["YES\n1000000000 3", "NO", "YES\n1000000000 9", "NO", "YES\n1000000000 1", "YES\n1000000000 1", "YES\n1000000000 1", "YES\n1000000000 999999999", "NO", "NO", "NO", "YES\n1000000000 2", "YES\n1000000000 1", "YES\n1000000000 3", "NO", "NO", "YES\n1000000000 3", "YES\n1000000000 2", "NO", "NO", "NO", "YES\n1000000000 1", "YES\n1000000000 2", "NO", "YES\n1000000000 2", "NO", "YES\n1000000000 5", "YES\n1000000000 2", "NO", "YES\n1000000000 2", "NO", "NO", "YES\n1000000000 2", "YES\n1000000000 2", "YES\n1000000000 2", "NO", "NO", "YES\n1000000000 1", "NO", "NO", "YES\n1000000000 1", "YES\n1000000000 2", "NO", "NO", "NO", "NO", "YES\n1000000000 2", "YES\n1000000000 1", "NO", "YES\n1000000000 2", "NO", "YES\n1000000000 2", "YES\n1000000000 1", "YES\n1000000000 2", "YES\n1000000000 1", "NO", "NO", "NO", "YES\n1000000000 2", "NO", "NO", "NO", "YES\n1000000000 1", "NO", "YES\n1000000000 2", "YES\n1000000000 2", "NO", "YES\n1000000000 1", "YES\n1000000000 2", "YES\n1000000000 1", "YES\n1000000000 2", "NO", "YES\n1000000000 2", "YES\n1000000000 2", "YES\n1000000000 1", "YES\n1000000000 1", "NO", "NO", "YES\n1000000000 500000000", "NO", "NO", "YES\n1000000000 5"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
6f6ba61afc5da72f67d05cadb8e29e00
Hungry Student Problem
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken. CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly this amount of chicken. Formally, Ivan wants to know if he can choose two non-negative integers *a* and *b* in such a way that *a* small portions and *b* large ones contain exactly *x* chunks. Help Ivan to answer this question for several values of *x*! The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases. The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. Sample Input 2 6 5 Sample Output YES NO
{"inputs": ["2\n6\n5", "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100", "3\n6\n6\n6", "47\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "3\n1\n52\n76", "87\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "3\n3\n2\n1", "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100"], "outputs": ["YES\nNO", "NO\nNO\nYES\nNO\nNO\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES", "YES\nYES\nYES", "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO", "NO\nYES\nYES", "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES", "YES\nNO\nNO", "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
205
codeforces
6f88d078f556c38aa64f874a732d49a1
Spit Problem
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists. The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position. If there are two camels, which spitted at each other, output YES. Otherwise, output NO. Sample Input 2 0 1 1 -1 3 0 1 1 1 2 -2 5 2 -10 3 10 0 5 5 -5 10 1 Sample Output YES NO YES
{"inputs": ["2\n0 1\n1 -1", "3\n0 1\n1 1\n2 -2", "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n7594 7675\n-5412 -6872", "11\n-1536 3809\n-2406 -8438\n-1866 395\n5636 -490\n-6867 -7030\n7525 3575\n-6796 2908\n3884 4629\n-2862 -6122\n-8984 6122\n7137 -326", "12\n-9765 1132\n-1382 -215\n-9405 7284\n-2040 3947\n-9360 3150\n6425 9386\n806 -2278\n-2121 -7284\n5663 -1608\n-8377 9297\n6245 708\n8470 6024", "15\n8122 -9991\n-4068 -3386\n8971 3731\n3458 5161\n-8700 7562\n2691 8735\n-1510 -3892\n5183 -3753\n-7018 6637\n-7454 3386\n-818 -6377\n6771 -8647\n-7357 -1246\n-6186 1922\n9889 -3627", "20\n-5264 6424\n-3664 -7459\n-2780 -9859\n-3317 6842\n5681 -8092\n1555 1904\n-6684 1414\n6593 -1253\n-5708 -1202\n335 1733\n-926 7579\n3459 -1904\n-4486 4006\n6201 3616\n2847 -5255\n8438 7057\n8171 6042\n-9102 3545\n7731 -233\n6264 6563", "30\n-398 -1774\n313 -6974\n2346 -4657\n8552 -9647\n-5265 1538\n8195 4864\n-5641 -5219\n-1394 8563\n-1190 1992\n-4669 -1156\n7574 256\n9206 -2414\n4140 -549\n-294 2169\n7029 -2871\n3808 -9799\n3141 5690\n4648 -2680\n-5990 9800\n-2299 1697\n6077 -7177\n-400 -9724\n-4644 -2392\n-2198 -9531\n-2105 9386\n-8165 -4201\n-1589 -7916\n2518 -7840\n4173 -6949\n-3368 -9943"], "outputs": ["YES", "NO", "YES", "NO", "YES", "YES", "YES", "YES", "NO"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
244
codeforces
6f94033e42e6a08e91be2f6a70cd3a1f
Lakes in Berland
The map of Berland is a rectangle of the size *n*<=×<=*m*, which consists of cells of size 1<=×<=1. Each cell is either land or water. The map is surrounded by the ocean. Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell. You task is to fill up with the earth the minimum number of water cells so that there will be exactly *k* lakes in Berland. Note that the initial number of lakes on the map is not less than *k*. The first line of the input contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=50, 0<=≤<=*k*<=≤<=50) — the sizes of the map and the number of lakes which should be left on the map. The next *n* lines contain *m* characters each — the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '*' (it means that the corresponding cell is land). It is guaranteed that the map contain at least *k* lakes. In the first line print the minimum number of cells which should be transformed from water to land. In the next *n* lines print *m* symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them. It is guaranteed that the answer exists on the given data. Sample Input 5 4 1 **** *..* **** **.* ..** 3 3 0 *** *.* *** Sample Output 1 **** *..* **** **** ..** 1 *** *** ***
{"inputs": ["5 4 1\n****\n*..*\n****\n**.*\n..**", "3 3 0\n***\n*.*\n***", "3 5 1\n.**.*\n*.*.*\n***..", "3 5 0\n.**.*\n*.*.*\n***..", "3 50 7\n***.********.*********************.**********.****\n*...**..*.**.*.*.*.*.*.*.*..*.*.*.*.*.*.*.*.*.*..*\n****************.*.********.**********************", "50 3 4\n***\n*.*\n*.*\n*.*\n***\n***\n*.*\n***\n.**\n***\n..*\n***\n***\n*.*\n***\n*.*\n***\n***\n*.*\n***\n*.*\n*.*\n*.*\n*.*\n***\n*.*\n*.*\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n*.*\n***\n***\n***\n*.*\n***\n***\n***\n*.*\n*.*\n*.*\n***\n***\n***\n***", "1 1 0\n.", "1 1 0\n*"], "outputs": ["1\n****\n*..*\n****\n****\n..**", "1\n***\n***\n***", "0\n.**.*\n*.*.*\n***..", "1\n.**.*\n***.*\n***..", "8\n***.********.*********************.**********.****\n*...**..****.***.*.*******..*******.*.*.*.*.*.*..*\n****************.*.********.**********************", "8\n***\n***\n***\n***\n***\n***\n***\n***\n.**\n***\n..*\n***\n***\n***\n***\n***\n***\n***\n***\n***\n*.*\n*.*\n*.*\n*.*\n***\n*.*\n*.*\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n*.*\n***\n***\n***\n***\n***\n***\n***\n*.*\n*.*\n*.*\n***\n***\n***\n***", "0\n.", "0\n*"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
6fa56519080e5ae2d001b4538fae2064
Less or Equal
You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$. Note that the sequence can contain equal elements. If there is no such $x$, print "-1" (without quotes). The first line of the input contains integer numbers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $0 \le k \le n$). The second line of the input contains $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the sequence itself. Print any integer number $x$ from range $[1; 10^9]$ such that exactly $k$ elements of given sequence is less or equal to $x$. If there is no such $x$, print "-1" (without quotes). Sample Input 7 4 3 7 5 1 10 3 20 7 2 3 7 5 1 10 3 20 Sample Output 6-1
{"inputs": ["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20", "1 0\n1", "1 0\n2", "1 1\n1000000000", "3 0\n3 3 3", "3 0\n2 2 3", "5 0\n3 4 5 6 7", "4 0\n2 3 4 5", "2 2\n1000000000 1000000000", "7 2\n2 7 5 1 10 2 20", "2 1\n1 1", "5 3\n1 3 3 4 5", "4 4\n1000000000 1000000000 1000000000 1000000000"], "outputs": ["5", "-1", "-1", "1", "1000000000", "2", "1", "2", "1", "1000000000", "-1", "-1", "3", "1000000000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
6fad140b01b60938c5f1ca7ca0c595c1
A Mist of Florescence
"I've been here once," Mino exclaims with delight, "it's breathtakingly amazing." "What is it like?" "Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?" There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses. The wood can be represented by a rectangular grid of $n$ rows and $m$ columns. In each cell of the grid, there is exactly one type of flowers. According to Mino, the numbers of connected components formed by each kind of flowers are $a$, $b$, $c$ and $d$ respectively. Two cells are considered in the same connected component if and only if a path exists between them that moves between cells sharing common edges and passes only through cells containing the same flowers. You are to help Kanno depict such a grid of flowers, with $n$ and $m$ arbitrarily chosen under the constraints given below. It can be shown that at least one solution exists under the constraints of this problem. Note that you can choose arbitrary $n$ and $m$ under the constraints below, they are not given in the input. The first and only line of input contains four space-separated integers $a$, $b$, $c$ and $d$ ($1 \leq a, b, c, d \leq 100$) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively. In the first line, output two space-separated integers $n$ and $m$ ($1 \leq n, m \leq 50$) — the number of rows and the number of columns in the grid respectively. Then output $n$ lines each consisting of $m$ consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and 'D', representing Amaranths, Begonias, Centaureas and Dianthuses, respectively. In case there are multiple solutions, print any. You can output each letter in either case (upper or lower). Sample Input 5 3 2 1 50 50 1 1 1 6 4 5 Sample Output 4 7 DDDDDDD DABACAD DBABACD DDDDDDD4 50 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ABABABABABABABABABABABABABABABABABABABABABABABABAB BABABABABABABABABABABABABABABABABABABABABABABABABA DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD7 7 DDDDDDD DDDBDBD DDCDCDD DBDADBD DDCDCDD DBDBDDD DDDDDDD
{"inputs": ["5 3 2 1", "50 50 1 1", "1 6 4 5", "1 1 1 1", "4 8 16 32", "1 1 1 50", "19 58 20 18", "100 100 100 100", "1 1 1 2", "1 1 3 1", "1 4 1 1", "5 1 1 1", "1 4 7 3", "6 2 5 1", "1 5 6 3", "4 1 4 5", "4 5 3 6", "2 5 1 17", "11 4 5 14", "19 19 8 10", "49 49 49 49", "49 50 50 50", "50 50 51 50", "15 63 41 45", "45 36 25 13", "31 41 59 26", "18 90 64 16", "77 88 99 1", "99 100 1 100", "100 50 100 49"], "outputs": ["5 13\nAABABBBBCDDAD\nABAABBBBCDADD\nAAAABBBBCDDAD\nAAAABCBBCDADD\nAAAABBBBCDDDD", "10 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABABABABABABABABABABABABABABABABAA\nBABABABABABABABABABABABABABABABABABABABABABABABABA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\nDADADADADADADADADADADADADADADADADADADADADADADADADD\nADADADADADADADADADADADADADADADADADADADADADADADADAD\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...", "6 13\nAABABBCBCCDCD\nABAABBBBCCCCD\nAABABBCBCCDCD\nABAABCBBCDCCD\nAABABBBBCCDCD\nAAAABBBBCCCCD", "2 4\nABCD\nABCD", "16 32\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABAAAAAAABAAAAAAAAAAAAAAABABAAAA\nBAAAAAAAAAAABAAAAAAAAAAABAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBCBBBBBCBCBCBCBCBBBCBCBBBBBBBBBB\nCBCBBBBBBBBBCBBBCBBBCBBBBBCBBBCB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCC\nDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDC\nCCCCCCCC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ABABABABABABAAAAABABAA\nAABAAAAAAAAAAABAAABAAABABABAAABABAAABABABABABABAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAAAABABABAAAAAAABABABABABAAABABABABABABAAAAAAABABA\nABABABAAABABABAAABABAAABAAABABABABABAAABABABABABAB\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABAAABAAABABAAAAAAABAAAAAAABABAAABAAABAAAAABAA\nBABABABAAABABABABABAAABABABABAAABABAAABABABAAABABA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...", "2 7\nABCCDCD\nABCCCCD", "3 7\nABBCBCD\nABCBBCD\nABBBBCD", "4 7\nAABABCD\nABAABCD\nAABABCD\nAAAABCD", "5 7\nABCDDAD\nABCDADD\nABCDDAD\nABCDADD\nABCDDDD", "7 13\nAAAABBCBCCDCD\nABAABCBBCCCCD\nAAAABBCBCCCCD\nABAABCBBCCCCD\nAABABBCBCCCCD\nAAAABCBBCDCCD\nAAAABBBBCCCCD", "6 13\nAAAABBCBCDDAD\nAAAABBBBCDADD\nAAAABBCBCDDAD\nAAAABCBBCDADD\nAABABBCBCDDAD\nAAAABBBBCDDDD", "6 13\nAAAABBCBCCCCD\nABAABCBBCCCCD\nAABABBCBCCCCD\nABAABCBBCDCCD\nAABABBCBCCDCD\nAAAABBBBCCCCD", "5 13\nABBCBCCDCDDAD\nABCBBCDCCDDDD\nABBBBCCDCDDAD\nABCBBCDCCDADD\nABBBBCCCCDDDD", "6 16\nAAAABBCBCCDCDDAD\nABAABBBBCDCCDDDD\nAABABBCBCCDCDDAD\nABAABBBBCDCCDDDD\nAABABBBBCCDCDDAD\nAAAABBBBCCCCDDDD", "13 17\nAAAAAAAAAAAAAAAAA\nABAAAAAAABAAAAAAA\nAABAAAAAAAAABAAAA\nAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBB\nCCCCCCCCCCCCCCCCC\nCDCDCDCDCDCDCDCDC\nDCDCDCDCDCDCDCDCC\nCCCCCCCCCCCCCCCCC\nDDDDDDDDDDDDDDDDD\nDDDDDDDDDDDDDDDDD\nDDADDDDDDDDDDDDDD\nDDDDDDDDDDDDDDDDD", "14 16\nAAAABBBBCCDCDDDD\nABAABBBBCDCCDADD\nAAAABBBBCCDCDDAD\nAAAABBBBCDCCDADD\nAAAABBBBCCDCDDAD\nAAAABBBBCDCCDADD\nAAAABBBBCCDCDDAD\nAAAABCBBCDCCDDDD\nAAAABBCBCCDCDDDD\nABAABCBBCDCCDADD\nAAAABBBBCCDCDDAD\nAAAABCBBCDCCDADD\nAABABBBBCCDCDDAD\nAAAABBBBCCCCDDDD", "16 19\nAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABA\nBABABABABABABABABAA\nAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBB\nBBBCBBBBBBBBBCBBBCB\nBBCBBBCBCBBBBBCBBBB\nBBBBBBBBBBBBBBBBBBB\nCCCCCCCCCCCCCCCCCCC\nCCCDCCCCCDCCCDCCCDC\nCCCCDCDCCCDCCCDCDCC\nCCCCCCCCCCCCCCCCCCC\nDDDDDDDDDDDDDDDDDDD\nDADADADADADADADADAD\nADADADADADADADADADD\nDDDDDDDDDDDDDDDDDDD", "16 49\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABABABABABABABABABABABABABABABABA\nBABABABABABABABABABABABABABABABABABABABABABABABAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCB\nCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDC...", "16 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABABABABABABABABABABABABABABABABAA\nBABABABABABABABABABABABABABABABABABABABABABABABABA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBB\nCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD...", "19 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABABABABABABABABABABABABABABABABAA\nBABABABABABABABABABABABABABABABABABABABABABABABABA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBCBBBBBCBCBBBBBCBBBCBBBCBBBBBBBCBCBBBCBBBBBCBBBB\nCBCBCBCBCBBBBBBBBBBBBBBBBBBBCBCBBBCBCBCBBBCBCBCBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBCBCBBBBBCBBBCBBBCBCBCBCBCBCBCBCBCBCBBBCBBBBBCBCB\nBBBBBCBBBCBBBBBCBBBBBCBBBCBBBCBBBCBB...", "19 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABAAABABABABABAAABABAAAAABABAAABABAAAAABAA\nAAAABABABAAABABABABABAAABAAABAAABABABABABAAABAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAABAAABABABAAABABABABAAAAAAABABAAABAAABAAABAAABABA\nABABAAABAAABABAAABAAAAABAAABABAAABABAAABAAABAAAAAB\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBCBCBCBCBCBCBCBCBCBCBBBCBBBCBBBCBCBCBCBCBCBCBCBB\nCBBBCBCBCBCBCBCBCBBBCBCBCBCBCBCBBBBB...", "16 45\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABAAABABABABAAABABABABABAAABABABABABAAAAABAAA\nBABABABABABABAAAAABABABABABABABABABABAAABABAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBCBCBCBCBCBBBCBBBBBBBBBBBBBBBCBCBCBBBCBCBBBCB\nCBBBCBCBCBCBBBBBCBBBBBBBBBCBBBCBBBBBCBCBCBCBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nCCCCCCCCCCCCCCCCCCCDCCCCCCCCCDCCCCCDCCCCCDCCC\nCCCCCCCCCCCCDCCCDCCCCCDCDCCCCCDCCC...", "19 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABAAAAABAAABABABABABABABABAAABABABABABAA\nBABABABABABABAAABABAAABAAABAAABABABABAAABABABABABA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBCBBBBBCBCBCBBBCBBBCBBBCBBBBBBBCBCBBBCBBBBBCBBBB\nCBCBCBCBCBCBBBBBBBBBBBBBCBBBCBCBBBCBCBCBBBCBCBCBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBCBCBBBBBCBBBCBBBCBCBCBCBCBCBCBCBCBCBBBCBBBBBCBCB\nBCBBBCBBBCBBBCBCBBBBBCBBBCBBBCBCBCBC...", "22 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABABABABABABABABABABABABABABAAABAA\nAABABABABAAABABABABABABABAAABABABABABABABABABABAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAABABABABABABABABABABABABABABABAAABABABABABABABABA\nABABABABABABABAAABABAAABABABABABABABABABABABAAABAB\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBCBCBCBBBCBBBBBCBCBCBBBCBCBCBBBCBBBCBCBCBCBCBB\nCBCBCBBBCBCBBBCBBBCBCBBBCBCBBBCBCBBB...", "22 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABABABABABABABABABABABABABAAAAABAA\nAABABABABAAABABABABABABABAAABABABABABABABABABABAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAABABABABABABABABABABABABAAABABAAABABABABABABABABA\nABABABABABABABAAABABAAABABABABABABABABABABABAAABAB\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBB\nCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCBCB...", "28 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAAABAAABAAABAAABABABABABABAAABABABABABABAAAAABABAA\nAABAAAAAAAAAAABAAABAAABABABAAABABAAABABABABABABAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nAAAABABABAAAAAAABABABABABAAABABABABABABAAAAAAABABA\nABABABAAABABABAAABABAAABAAABABABABABAAABABABABABAB\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABAAABAAABABAAAAAAABAAAAAAABABAAABAAABAAAAABAA\nBABABABAAABABABABABAAABABABABAAABABAAABABABAAABABA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...", "28 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABABABABABABABABABABABABABABABABAA\nBABABABABABABABABABABABABABABABABABABABABABABABABA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBCBCBBBBBCBCBCBBBCBBBBBCBCBBBCBCBCBBBCBCBCBCBBBBBB\nBBBBCBCBCBCBBBCBCBCBCBCBBBCBCBCBCBBBCBCBCBCBCBCBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBCBCBBBBBCBCBCBCBCBCBCBCBCBCBBBCBCBCBBBBBCBCBCBCB\nBCBBBBBCBCBCBBBCBCBBBCBCBCBBBBBCBCBB..."]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
37
codeforces
6fcc6e981568cc6fcb2d4525c65fed0a
Queries for Number of Palindromes
You've got a string *s*<==<=*s*1*s*2... *s*|*s*| of length |*s*|, consisting of lowercase English letters. There also are *q* queries, each query is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|). The answer to the query is the number of substrings of string *s*[*l**i*... *r**i*], which are palindromes. String *s*[*l*... *r*]<==<=*s**l**s**l*<=+<=1... *s**r* (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) is a substring of string *s*<==<=*s*1*s*2... *s*|*s*|. String *t* is called a palindrome, if it reads the same from left to right and from right to left. Formally, if *t*<==<=*t*1*t*2... *t*|*t*|<==<=*t*|*t*|*t*|*t*|<=-<=1... *t*1. The first line contains string *s* (1<=≤<=|*s*|<=≤<=5000). The second line contains a single integer *q* (1<=≤<=*q*<=≤<=106) — the number of queries. Next *q* lines contain the queries. The *i*-th of these lines contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|) — the description of the *i*-th query. It is guaranteed that the given string consists only of lowercase English letters. Print *q* integers — the answers to the queries. Print the answers in the order, in which the queries are given in the input. Separate the printed numbers by whitespaces. Sample Input caaaba 5 1 1 1 4 2 3 4 6 4 5 Sample Output 1 7 3 4 2
{"inputs": ["caaaba\n5\n1 1\n1 4\n2 3\n4 6\n4 5", "a\n100\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\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ON3" ]
CODEFORCES
1
codeforces
6fd7e39fbfb49f8c3355674346e9c9e3
none
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater than *v**i* meters per second in any of the two directions along the road: south or north. You are to compute the minimum time needed to gather all the *n* friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate. The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters. The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — the maximum speeds of the friends, in meters per second. Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds. Sample Input 3 7 1 3 1 2 1 4 5 10 3 2 2 3 2 4 Sample Output 2.000000000000 1.400000000000
{"inputs": ["3\n7 1 3\n1 2 1", "4\n5 10 3 2\n2 3 2 4", "3\n1 1000000000 2\n1 2 1000000000", "2\n4 5\n10 8", "4\n14 12 10 17\n8 6 5 10", "5\n1 15 61 29 43\n15 11 19 19 19", "10\n20 11 17 38 15 27 2 40 24 37\n22 30 22 30 28 16 7 20 22 13", "2\n1000000000 1000000000\n1 1", "3\n1 1 1\n1 1 1"], "outputs": ["2.000000000000", "1.400000000000", "333333332.999999999971", "0.055555555556", "0.466666666667", "1.764705882353", "1.750000000000", "0.000000000000", "0.000000000000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
126
codeforces
6fda7a991fde3dff8210e9177cbb9d24
Lightsabers (easy)
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission. Heidi has *n* Jedi Knights standing in front of her, each one with a lightsaber of one of *m* possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly *k*1 knights with lightsabers of the first color, *k*2 knights with lightsabers of the second color, ..., *k**m* knights with lightsabers of the *m*-th color. Help her find out if this is possible. The first line of the input contains *n* (1<=≤<=*n*<=≤<=100) and *m* (1<=≤<=*m*<=≤<=*n*). The second line contains *n* integers in the range {1,<=2,<=...,<=*m*} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains *m* integers *k*1,<=*k*2,<=...,<=*k**m* (with ) – the desired counts of lightsabers of each color from 1 to *m*. Output YES if an interval with prescribed color counts exists, or output NO if there is none. Sample Input 5 2 1 1 2 2 1 1 2 Sample Output YES
{"inputs": ["5 2\n1 1 2 2 1\n1 2", "1 1\n1\n1", "2 1\n1 1\n1", "2 1\n1 1\n2", "2 2\n1 2\n1 1", "3 3\n1 1 3\n0 1 2", "4 4\n2 3 3 2\n0 0 1 0", "2 2\n2 2\n0 2", "3 3\n1 1 3\n0 1 1", "4 4\n2 4 4 3\n1 1 1 1", "2 2\n2 1\n0 1", "3 3\n3 1 1\n1 1 1", "4 4\n1 3 1 4\n1 0 0 1", "2 2\n2 1\n1 0", "3 3\n3 1 1\n2 0 0", "4 4\n4 4 2 2\n1 1 1 1", "2 2\n1 2\n0 2", "3 3\n3 2 3\n0 2 1", "4 4\n1 2 4 2\n0 0 1 0", "2 2\n2 1\n1 1", "3 3\n2 2 1\n1 1 1", "6 6\n5 1 6 3 3 2\n1 1 2 0 0 1", "4 4\n1 2 1 1\n2 1 0 0", "5 5\n5 3 5 2 5\n0 0 0 0 1", "6 6\n1 2 2 4 6 1\n1 0 0 0 0 1", "4 4\n2 2 4 1\n0 2 0 0", "5 5\n1 5 3 5 1\n1 0 0 0 1", "6 6\n5 4 4 3 4 6\n0 0 1 1 0 0", "4 4\n1 3 4 4\n1 0 1 1", "5 5\n2 5 2 5 3\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3 10 7 6 7 3 3 9 2 3 8 2 9 9 5 7 5 8 6 6 6 6 10 10 4 2 2 7 4 1 4 7 4 6 4 6 8 8 6 3 10 2 3 5 2 10 3 4 7 3 10\n0 0 0 1 0 0 0 0 1 0", "100 10\n5 5 6 8 2 3 3 6 5 4 10 2 10 1 8 9 7 6 5 10 4 9 8 8 5 4 2 10 7 9 3 6 10 1 9 5 8 7 8 6 1 1 9 1 9 6 3 10 4 4 9 9 1 7 6 3 1 10 3 9 7 9 8 5 7 6 10 4 8 2 9 1 7 1 7 7 9 1 2 3 9 1 6 7 10 7 9 8 2 2 5 1 1 3 8 10 6 4 2 6\n0 0 1 0 0 0 1 0 0 0", "100 100\n48 88 38 80 20 25 80 40 71 17 5 68 84 16 20 91 86 29 51 37 62 100 25 19 44 58 90 75 27 68 77 67 74 33 43 10 86 33 66 4 66 84 86 8 50 75 95 1 52 16 93 90 70 25 50 37 53 97 44 33 44 66 57 75 43 52 1 73 49 25 3 82 62 75 24 96 41 33 3 91 72 62 43 3 71 13 73 69 88 19 23 10 26 28 81 27 1 86 4 63\n3 0 3 2 1 0 0 1 0 2 0 0 1 0 0 2 1 0 2 1 0 0 1 1 3 1 2 1 1 0 0 0 4 0 0 0 2 0 0 1 1 0 3 3 0 0 0 0 1 2 1 2 1 0 0 0 1 1 0 0 0 3 1 0 0 3 1 2 1 1 2 1 2 1 4 0 1 0 0 0 1 1 0 2 0 4 0 1 0 2 2 0 1 0 1 1 1 0 0 1", "100 100\n98 31 82 85 31 21 82 23 9 72 13 79 73 63 19 74 5 29 91 24 70 55 36 2 75 49 19 44 39 97 43 51 68 63 79 91 14 14 7 56 50 79 14 43 21 10 29 26 17 18 7 85 65 31 16 55 15 80 36 99 99 97 96 72 3 2 14 33 47 9 71 33 61 11 69 13 12 99 40 5 83 43 99 59 84 62 14 30 12 91 20 12 32 16 65 45 19 72 37 30\n0 0 0 0 0 0 2 0 0 1 0 0 0 2 1 1 1 1 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 2 0", "100 100\n46 97 18 86 7 31 2 100 32 67 85 97 62 76 36 88 75 31 46 55 79 37 50 99 9 68 18 97 12 5 65 42 87 86 40 46 87 90 32 68 79 1 40 9 30 50 13 9 73 100 1 90 7 39 65 79 99 86 94 22 49 43 63 78 53 68 89 25 55 66 30 27 77 97 75 70 56 49 54 60 84 16 65 45 47 51 12 70 75 8 13 76 80 84 60 92 15 53 2 3\n2 0 0 0 1 0 1 0 3 0 0 1 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 2 1 1 0 0 0 0 1 0 1 2 0 1 1 0 1 2 1 0 2 2 0 0 1 1 2 1 0 0 0 1 0 0 1 0 3 1 0 3 0 1 0 0 1 0 2 0 1 1 3 0 0 0 0 1 0 2 2 0 1 2 0 0 0 1 0 0 2 0 2 1", "100 100\n52 93 36 69 49 37 48 42 63 27 16 60 16 63 80 37 69 24 86 38 73 15 43 65 49 35 39 98 91 24 20 35 12 40 75 32 54 4 76 22 23 7 50 86 41 9 9 91 23 18 41 61 47 66 1 79 49 21 99 29 87 94 42 55 87 21 60 67 36 89 40 71 6 63 65 88 17 12 89 32 79 99 34 30 63 33 53 56 10 11 66 80 73 50 47 12 91 42 28 56\n1 0 0 1 0 1 1 0 2 1 1 1 0 0 0 0 1 1 0 0 2 1 2 0 0 0 0 0 1 1 0 2 1 1 0 1 0 0 0 1 2 1 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 1 0 2 0 1 2 1 0 0 0 1 0 1 0 1 1 0 0 2 1 0 0 0 0 0 1 2 1 2 0 1 0 0 1 0 0 0 0 2 0", "100 100\n95 60 61 26 78 50 77 97 64 8 16 74 43 79 100 37 66 91 1 20 97 70 95 87 42 83 54 66 31 64 57 15 38 76 31 89 76 61 77 22 90 79 59 26 63 60 82 57 3 50 100 9 85 33 32 78 31 50 45 64 93 60 28 84 74 19 51 24 71 32 71 42 77 94 7 81 99 13 42 64 94 65 45 5 95 75 50 100 33 1 46 77 44 81 93 9 39 6 71 93\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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0", "100 100\n20 7 98 36 47 73 38 11 46 9 98 97 24 60 72 24 14 71 41 24 77 24 23 2 15 12 99 34 14 3 79 74 8 22 57 77 93 62 62 88 32 54 8 5 34 14 46 30 65 20 55 93 76 15 27 18 11 47 80 38 41 14 65 36 75 64 1 16 64 62 33 37 51 7 78 1 39 22 84 91 78 79 77 32 24 48 14 56 21 2 42 60 96 87 23 73 44 24 20 80\n2 0 0 0 0 0 1 0 0 0 1 0 0 2 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 1 1 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 2 2 0 0 0 0 0 0 0 0 0 1 1 1 2 1 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0", "100 100\n14 95 7 48 86 65 51 9 5 54 22 58 93 72 31 65 86 27 20 23 24 43 5 78 12 68 60 24 55 55 83 18 1 60 37 62 15 2 5 70 86 93 98 34 45 24 69 66 55 55 74 77 87 55 83 27 46 37 55 12 33 91 1 23 4 78 74 97 8 25 63 63 9 16 60 27 41 18 42 84 35 76 59 8 33 92 40 89 19 23 90 18 30 51 42 62 42 34 75 61\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 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", "100 100\n94 78 24 48 89 1 2 22 11 42 86 26 7 23 94 100 82 27 24 28 98 62 12 53 67 43 33 45 13 1 80 99 3 79 71 20 26 35 20 69 45 52 39 48 23 3 80 43 60 90 66 43 54 40 93 35 13 20 90 47 55 39 79 2 61 95 83 60 53 4 55 3 33 74 17 38 78 83 83 94 34 43 34 99 46 71 42 58 65 94 65 64 70 88 49 39 2 36 10 55\n0 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 1 1 1 0 0 2 0 0 0 1 0 0 0 0 0 1 1 2 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 3 0 0 0 0 0 0 1 0 0 1 1 1 0 0 0 1 0"], "outputs": ["YES", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "YES", "NO", "NO", "NO", "NO", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
6fef8e4304c116331fb41daf0b0b2c4b
Bear and Different Names
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't. You are a spy in the enemy's camp. You noticed *n* soldiers standing in a row, numbered 1 through *n*. The general wants to choose a group of *k* consecutive soldiers. For every *k* consecutive soldiers, the general wrote down whether they would be an effective group or not. You managed to steal the general's notes, with *n*<=-<=*k*<=+<=1 strings *s*1,<=*s*2,<=...,<=*s**n*<=-<=*k*<=+<=1, each either "YES" or "NO". - The string *s*1 describes a group of soldiers 1 through *k* ("YES" if the group is effective, and "NO" otherwise). - The string *s*2 describes a group of soldiers 2 through *k*<=+<=1. - And so on, till the string *s**n*<=-<=*k*<=+<=1 that describes a group of soldiers *n*<=-<=*k*<=+<=1 through *n*. Your task is to find possible names of *n* soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example. Find and print any solution. It can be proved that there always exists at least one solution. The first line of the input contains two integers *n* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=50) — the number of soldiers and the size of a group respectively. The second line contains *n*<=-<=*k*<=+<=1 strings *s*1,<=*s*2,<=...,<=*s**n*<=-<=*k*<=+<=1. The string *s**i* is "YES" if the group of soldiers *i* through *i*<=+<=*k*<=-<=1 is effective, and "NO" otherwise. Find any solution satisfying all given conditions. In one line print *n* space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them. Sample Input 8 3 NO NO YES YES YES NO 9 8 YES NO 3 2 NO NO Sample Output Adam Bob Bob Cpqepqwer Limak Adam Bob AdamR Q Ccccccccc Ccocc Ccc So Strong Samples CccNa Na Na
{"inputs": ["8 3\nNO NO YES YES YES NO", "9 8\nYES NO", "3 2\nNO NO", "2 2\nYES", "2 2\nNO", "7 2\nYES NO YES YES NO YES", "18 7\nYES YES YES YES YES YES YES NO NO NO NO NO", "50 3\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO", "19 15\nNO YES YES YES NO", "3 2\nNO NO", "3 2\nNO YES", "3 2\nYES NO", "3 2\nYES YES", "26 17\nNO YES YES YES NO YES NO YES YES YES", "12 2\nYES YES YES YES YES YES YES YES YES YES YES", "16 2\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO", "42 20\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "37 14\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO", "29 10\nYES NO YES NO YES NO YES YES YES YES YES NO NO NO NO NO YES YES YES YES", "37 3\nYES NO YES NO YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO NO YES NO NO YES YES YES YES NO", "44 11\nNO NO YES NO YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES NO NO YES NO NO YES YES YES NO", "50 49\nNO YES", "50 49\nYES YES", "50 49\nNO NO", "50 49\nYES NO", "46 42\nNO YES YES YES NO", "45 26\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "45 26\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO", "50 3\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES", "50 2\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO", "50 3\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES YES YES YES YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES", "49 2\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO NO NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES", "35 22\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO", "46 41\nYES YES YES YES YES YES", "12 4\nYES YES NO NO NO NO NO YES YES", "50 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "50 4\nYES YES YES YES YES NO YES YES YES YES NO NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "34 5\nYES YES YES YES YES NO YES YES YES YES NO NO YES YES YES NO NO YES NO YES YES YES YES YES YES YES YES YES YES YES", "50 43\nYES NO YES NO YES YES YES YES", "38 30\nNO NO YES NO YES NO NO NO NO", "50 50\nNO", "50 50\nYES", "5 3\nYES NO YES", "30 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "50 50\nYES", "27 27\nYES", "28 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "50 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "8 3\nYES NO YES NO YES NO", "42 30\nNO YES YES NO NO YES NO YES NO YES NO NO YES", "50 49\nYES YES", "50 3\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES", "7 5\nYES NO YES", "8 4\nNO YES NO YES NO", "50 50\nNO", "50 48\nYES NO YES", "29 14\nYES NO YES NO NO YES YES NO NO YES YES NO NO YES YES YES", "10 3\nNO YES NO YES NO YES NO YES", "10 5\nYES NO YES NO YES NO"], "outputs": ["Ab Ac Ab Ac Af Ag Ah Ag ", "Ab Ac Ad Ae Af Ag Ah Ai Ac ", "Ab Ab Ab ", "Ab Ac ", "Ab Ab ", "Ab Ac Ac Ae Af Af Ah ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ai Aj Ak Al Am ", "Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Bx Ac ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ab Aq Ar As Af ", "Ab Ab Ab ", "Ab Ab Ad ", "Ab Ac Ac ", "Ab Ac Ad ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ab As At Au Af Aw Ah Ay Az Ba ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am ", "Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Ac Am Ae Ao Ag Aq Ar As At Au Am Ae Ao Ag Aq Ba Bb Bc Bd ", "Ab Ac Ad Ac Af Ac Ah Ac Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Ba Bb Be Bb Be Bh Bi Bj Bk Bj ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Ab Ac An Ae Ap Ag Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Au Bf Bg Bh Bi Bj Ba Bb Bm Bd Au Bp Bq Br Bi ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Ab By ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Ab Ac ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx Ac ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Ab Br Bs Bt Af ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au ", "Ab Ac Ab Ae Ab Ag Ab Ai Ab Ak Ab Am Ab Ao Ab Aq Ab As Ab Au Ab Aw Ab Ay Ab Ba Ab Bc Ab Be Ab Bg Ab Bi Ab Bk Ab Bm Ab Bo Ab Bq Ab Bs Ab Bu Ab Bw Ab By ", "Ab Ab Ad Ad Af Af Ah Ah Aj Aj Al Al An An Ap Ap Ar Ar At At Av Av Ax Ax Az Az Bb Bb Bd Bd Bf Bf Bh Bh Bj Bj Bl Bl Bn Bn Bp Bp Br Br Bt Bt Bv Bv Bx Bx ", "Ab Ac Ab Ae Ab Ag Ab Ai Ab Ak Ab Am Ab Ao Ab Aq Ab As Ab Au Ab Aw Ab Ay Ab Ba Ab Bc Bd Be Bf Bg Bf Bi Bf Bk Bf Bm Bf Bo Bf Bq Bf Bs Bf Bu Bf Bw Bf By ", "Ab Ab Ad Ad Af Af Ah Ah Aj Aj Al Al An An Ap Ap Ar Ar At At Av Av Ax Ax Ax Ax Bb Bb Bd Bd Bf Bf Bh Bh Bj Bj Bl Bl Bn Bn Bp Bp Br Br Bt Bt Bv Bv Bx ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu ", "Ab Ac Ad Ae Af Ad Ae Af Ad Ae Al Am ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By ", "Ab Ac Ad Ae Af Ag Ah Ai Ag Ak Al Am An Al Am Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bc Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ag Al Am An Ao Al Am Ar As At Am Ar Aw At Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Ac Bt Ae Bv Bw Bx By ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Ab Ac Bg Ae Bi Ag Ah Ai Aj ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx Ab ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By ", "Ab Ac Ad Ac Af ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By ", "Ab Ac Ad Ac Af Ac Ah Ac ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Ab Bf Bg Ae Af Bj Ah Bl Aj Bn Al Am Bq ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By ", "Ab Ac Ad Ae Af Ac Ah ", "Ab Ac Ad Ab Af Ad Ah Af ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx Ab ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Ac By ", "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ac Aq Ae Af At Au Ai Aj Ax Ay Am An Bb Bc Bd ", "Ab Ac Ab Ae Ab Ag Ab Ai Ab Ak ", "Ab Ac Ad Ae Af Ac Ah Ae Aj Ac "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
48
codeforces
6ff3cefda98378fc0c21b62cb6ae02e9
Music
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track. Tell Lesha, for how many times he will start the song, including the very first start. The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=&lt;<=*T*<=≤<=105). Print a single integer — the number of times the song will be restarted. Sample Input 5 2 2 5 4 7 6 2 3 Sample Output 2 1 1
{"inputs": ["5 2 2", "5 4 7", "6 2 3", "2 1 2", "2 1 3", "2 1 10000", "12326 6163 2", "10000 2500 4", "100000 99999 4", "12351 1223 6", "100000 1 10000", "10028 13 10000", "100000 99999 2", "100000 99999 3", "100000 1 2", "100000 1 3", "100000 1 4", "100000 1 5", "100000 3125 2", "12628 1804 7", "100000 45 13", "100000 500 3", "356 2 3", "50 2 2", "65465 12 3", "10033 3 8", "100000 3 2", "64 1 8", "10000 9 2", "25 2 2", "129 2 2", "6562 1 3", "100000 1 10"], "outputs": ["2", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "1", "1", "1", "17", "11", "9", "8", "5", "1", "4", "5", "5", "5", "8", "4", "16", "2", "11", "4", "7", "9", "5"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
92
codeforces
6ff5c28d8fd9e8778ea5afef93fb2782
Lucky Tree
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. One day Petya encountered a tree with *n* vertexes. Besides, the tree was weighted, i. e. each edge of the tree has weight (a positive integer). An edge is lucky if its weight is a lucky number. Note that a tree with *n* vertexes is an undirected connected graph that has exactly *n*<=-<=1 edges. Petya wondered how many vertex triples (*i*,<=*j*,<=*k*) exists that on the way from *i* to *j*, as well as on the way from *i* to *k* there must be at least one lucky edge (all three vertexes are pairwise distinct). The order of numbers in the triple matters, that is, the triple (1,<=2,<=3) is not equal to the triple (2,<=1,<=3) and is not equal to the triple (1,<=3,<=2). Find how many such triples of vertexes exist. The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of tree vertexes. Next *n*<=-<=1 lines contain three integers each: *u**i* *v**i* *w**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=109) — the pair of vertexes connected by the edge and the edge's weight. On the single line print the single number — the answer. Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is recommended to use the cin, cout streams or the %I64d specificator. Sample Input 4 1 2 4 3 1 2 1 4 7 4 1 2 4 1 3 47 1 4 7447 Sample Output 16 24
{"inputs": ["4\n1 2 4\n3 1 2\n1 4 7", "4\n1 2 4\n1 3 47\n1 4 7447", "9\n1 2 7\n1 3 12\n4 1 2\n4 5 4\n4 6 47\n4 7 9\n5 8 2\n5 9 1", "2\n1 2 7", "2\n2 1 1000000000", "9\n1 2 1\n1 3 7\n3 4 19\n3 5 2\n4 6 46\n7 4 25\n5 8 64\n5 9 73", "7\n1 2 47\n1 3 9\n3 7 7\n3 4 2\n3 5 4\n3 6 1", "5\n1 2 1\n2 3 1\n3 4 1\n4 5 2", "7\n1 2 4\n2 3 7\n3 4 44\n4 5 47\n5 6 74\n6 7 77", "5\n1 2 1000000000\n2 3 747774\n3 4 4\n4 5 8447854", "5\n1 2 1\n2 3 4\n3 4 4\n4 5 1", "9\n9 7 4\n7 2 10\n2 3 28\n2 1 1\n1 6 47\n1 5 7\n1 4 4\n1 8 2", "10\n9 1 4\n9 2 7\n9 3 74447\n9 4 744\n9 5 777777777\n9 6 447477\n9 7 74\n9 8 777\n4 10 977", "10\n9 2 6\n5 3 7\n7 8 9\n2 1 7\n8 6 3\n1 4 5\n3 10 7\n7 4 3\n6 3 5", "10\n4 8 480392999\n3 4 32525297\n9 7 417904789\n6 2 836294777\n5 3 616099185\n1 7 830574407\n8 10 838073755\n6 10 547050646\n2 1 12607780"], "outputs": ["16", "24", "282", "0", "0", "98", "114", "0", "210", "36", "36", "284", "688", "328", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
6ff65660825765bf2edf2a8845293afc
Gotta Catch Em' All!
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur. Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper. Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today? Note: uppercase and lowercase letters are considered different. Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*. The string *s* contains lowercase and uppercase English letters, i.e. . Output a single integer, the answer to the problem. Sample Input Bulbbasaur F aBddulbasaurrgndgbualdBdsagaurrgndbb Sample Output 1 0 2
{"inputs": ["Bulbbasaur", "F", "aBddulbasaurrgndgbualdBdsagaurrgndbb", "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr", "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuu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uuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr", "CeSlSwec", "PnMrWPBGzVcmRcO", "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM", "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC", "bulsar", "Bblsar", "Bbusar", "Bbular", "Bbulsr", "Bbulsa", "Bbulsar", "Bbulsar", "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh", "Bulbasaur", "BulbasaurBulbasaur", "Bulbbasar", "Bulbasur", "Bulbsaur", "BulbsurBulbsurBulbsurBulbsur", "Blbbasar", "Bulbasar", "BBullllbbaassaauurr", "BulbasaurBulbasar", "BulbasaurBulbsaur", "Bubasaur", "ulbasaurulbasaur", "Bulbasr", "BBBuuulllbbbaaasssaaauuurrr", "BBuuuullbbaaaassrr", "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr", "BBuullbbaassaarr", "Bulbasau", "BBuullbbaassaauurr", "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau", "Blbasaur", "BulbasaurBulbasaurd", "ulbasaur", "Bulbaaur", "BBuuuullbbbbbbbbbbbbbbbaassrr", "Bulbasua", "Bubbasaur", "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr", "BulbasaurBubasaur", "Baab", "BulbasaurBulbasau", "Bulbasauu", "BulbasauBulbasau", "BBBBBBBBBBB", "Bulbbasau", "BulbbasaurBulbbasar", "Bulaaaasaur", "BulbasaurBulbasauBulbasauBulbasau"], "outputs": ["1", "0", "2", "5", "0", "0", "10", "20", "0", "0", "0", "6", "0", "0", "0", "0", "0", "0", "0", "0", "2", "1", "2", "0", "0", "0", "0", "0", "0", "1", "1", "1", "0", "0", "0", "3", "2", "4", "1", "0", "2", "0", "0", "2", "0", "0", "1", "0", "0", "3", "1", "0", "1", "0", "0", "0", "0", "1", "0", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
162
codeforces
704b7c118ec16d231e3db433b28d05dd
Minimal string
Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves: - Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u* with this character. Petya wants to get strings *s* and *t* empty and string *u* lexicographically minimal. You should write a program that will help Petya win the game. First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters. Print resulting string *u*. Sample Input cab acdb Sample Output abc abdc
{"inputs": ["cab", "acdb", "a", "ab", "ba", "dijee", "bhrmc", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbba", "bccbbcccbccbacacbaccaababcbaababaaaaabcaaabcaacbabcaababaabaccacacccbacbcacbbbaacaaccccabbbbacbcbbba", "eejahjfbbcdhbieiigaihidhageiechaadieecaaehcehjbddgcjgagdfgffdaaihbecebdjhjagghecdhbhdfbedhfhfafbjajg", "bnrdfnybkzepmluyrhofwnwvfmkdwolvyzrqhuhztvlwjldqmoyxzytpfmrgouymeupxrvpbesyxixnrfbxnqcwgmgjstknqtwrr", "bcaeaae", "edcadcbcdd", "a", "a", "a", "b", "b", "a", "c", "a", "b", "c", "b", "a", "e", "b", "b", "aa", "aa", "aa", "aa", "bb", "bb", "ba", "ca", "ab", "cb", "bb", "aa", "da", "ab", "cd", "aaa", "aaa", "aaa", "aab", "aaa", "baa", "bab", "baa", "ccc", "ddd", "ccd", "bca", "cde", "ece", "bdd", "aaaa", "aaaa", "aaaa", "abaa", "abab", "bbbb", "bbba", "caba", "ccbb", "abac", "daba", "cdbb", "bddd", "dacb", "abcc", "aaaaa", "aaaaa", "aaaaa", "baaab", "aabbb", "aabaa", "abcba", "bacbc", "bacba", "bdbda", "accbb", "dbccc", "decca", "dbbdd", "accec", "aaaaaa", "aaaaaa", "aaaaaa", "bbbbab", "bbbbab", "aaaaba", "cbbbcc", "aaacac", "bacbbc", "cacacc", "badbdc", "ddadad", "ccdece", "eecade", "eabdcb", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaabbaa", "baaabab", "bbababa", "bcccacc", "cbbcccc", "abacaaa", "ccdbdac", "bbacaba", "abbaccc", "bdcbcab", "dabcbce", "abaaabe", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "ababbbba", "aaaaaaba", "babbbaab", "bcaccaab", "bbccaabc", "cacaaaac", "daacbddc", "cdbdcdaa", "bccbdacd", "abbeaade", "ccabecba", "ececaead", "aaaaaaaaa", "aaaaaaaaa", "aaaaaaaaa", "aabaaabbb", "abbbbbaab", "bbbaababb", "babcaaccb", "ccbcabaac", "caaaccccb", "abbcdbddb", "dbcaacbbb", "cadcbddac", "ecebadadb", "bdbeeccdd", "daaedecda", "aaaaaaaaaa", "aaaaaaaaaa", "aaaaaaaaaa", "abaaaaabbb", "bbaaaabaaa", "bbabbaaaaa", "cbaabcaacc", "aaaaccccab", "bccaccaacc", "dbdccdcacd", "caaddaaccb", "adbbabcbdc", "cdeabdbbad", "eeddcbeeec", "bbcebddeba"], "outputs": ["abc", "abdc", "a", "ab", "ab", "deeji", "bcmrh", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbcbcbbbbcccccbbbccbcbccccccbbbcbbccbcbbbbcbbccbccbccbcccbbccb", "aaaaaaaaaaaaagjjbffhfhdebfdhbhdcehggjhjdbecebhidffgfdggjcgddbjhecheceeidhceieghdihigiieibhdcbbfjhjee", "bbbbcggjknqrrwttsmwqnxfrnxixysepvrxpuemyuogrmfptyzxyomqdljwlvtzhuhqrzyvlowdkmfvwnwfohryulmpezkynfdrn", "aaaecbe", "abccdcddde", "a", "a", "a", "b", "b", "a", "c", "a", "b", "c", "b", "a", "e", "b", "b", "aa", "aa", "aa", "aa", "bb", "bb", "ab", "ac", "ab", "bc", "bb", "aa", "ad", "ab", "cd", "aaa", "aaa", "aaa", "aab", "aaa", "aab", "abb", "aab", "ccc", "ddd", "ccd", "acb", "cde", "cee", "bdd", "aaaa", "aaaa", "aaaa", "aaab", "aabb", "bbbb", "abbb", "aabc", "bbcc", "aabc", "aabd", "bbdc", "bddd", "abcd", "abcc", "aaaaa", "aaaaa", "aaaaa", "aaabb", "aabbb", "aaaab", "aabcb", "abbcc", "aabcb", "adbdb", "abbcc", "bcccd", "acced", "bbddd", "accce", "aaaaaa", "aaaaaa", "aaaaaa", "abbbbb", "abbbbb", "aaaaab", "bbbccc", "aaaacc", "abbbcc", "aacccc", "abbcdd", "aadddd", "cccede", "acdeee", "abbcde", "aaaaaaa", "aaaaaaa", "aaaaaaa", "aaaaabb", "aaaabbb", "aaabbbb", "acccbcc", "bbccccc", "aaaaacb", "acdbdcc", "aaabcbb", "aabbccc", "abcbcdb", "abbccde", "aaaabbe", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaabbbbb", "aaaaaaab", "aaabbbbb", "aaabcccb", "aabccbbc", "aaaaaccc", "aabccddd", "aadcdbdc", "acdbccbd", "aaadebbe", "aabcebcc", "aadecece", "aaaaaaaaa", "aaaaaaaaa", "aaaaaaaaa", "aaaaabbbb", "aaabbbbbb", "aaabbbbbb", "aaabcccbb", "aaabcbccc", "aaabccccc", "abbbbdddc", "aabbbccbd", "aacddbcdc", "aabddbece", "bbccddeed", "aaadceded", "aaaaaaaaaa", "aaaaaaaaaa", "aaaaaaaaaa", "aaaaaabbbb", "aaaaaaabbb", "aaaaaabbbb", "aaaacbbccc", "aaaaabcccc", "aaaccccbcc", "accdccdbdd", "aaaabccddc", "aabbbbccdd", "aabbdbdedc", "bcceeeddee", "abeddbecbb"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
51
codeforces
70508fa3136cf8b828716a70521f6ef9
Couple Cover
Couple Cover, a wildly popular luck-based game, is about to begin! Two players must work together to construct a rectangle. A bag with *n* balls, each with an integer written on it, is placed on the table. The first player reaches in and grabs a ball randomly (all balls have equal probability of being chosen) — the number written on this ball is the rectangle's width in meters. This ball is not returned to the bag, and the second player reaches into the bag and grabs another ball — the number written on this ball is the rectangle's height in meters. If the area of the rectangle is greater than or equal some threshold *p* square meters, the players win. Otherwise, they lose. The organizers of the game are trying to select an appropriate value for *p* so that the probability of a couple winning is not too high and not too low, but they are slow at counting, so they have hired you to answer some questions for them. You are given a list of the numbers written on the balls, the organizers would like to know how many winning pairs of balls exist for different values of *p*. Note that two pairs are different if either the first or the second ball is different between the two in pair, and two different balls with the same number are considered different. The input begins with a single positive integer *n* in its own line (1<=≤<=*n*<=≤<=106). The second line contains *n* positive integers — the *i*-th number in this line is equal to *a**i* (1<=≤<=*a**i*<=≤<=3·106), the number written on the *i*-th ball. The next line contains an integer *m* (1<=≤<=*m*<=≤<=106), the number of questions you are being asked. Then, the following line contains *m* positive integers — the *j*-th number in this line is equal to the value of *p* (1<=≤<=*p*<=≤<=3·106) in the *j*-th question you are being asked. For each question, print the number of winning pairs of balls that exist for the given value of *p* in the separate line. Sample Input 5 4 2 6 1 3 4 1 3 5 8 2 5 6 2 30 31 Sample Output 20 18 14 10 2 0
{"inputs": ["5\n4 2 6 1 3\n4\n1 3 5 8", "2\n5 6\n2\n30 31", "2\n2000000 2000000\n1\n2000000", "1\n1\n1\n5", "10\n18 34 3 49 40 50 53 30 23 44\n10\n246 305 45 212 788 621 449 876 459 899"], "outputs": ["20\n18\n14\n10", "2\n0", "2", "0", "72\n72\n90\n72\n60\n66\n70\n58\n70\n56"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
705bd4865fdc3cbea4d14da2c58f73e0
Online Courses In BSU
Now you can take online courses in the Berland State University! Polycarp needs to pass *k* main online courses of his specialty to get a diploma. In total *n* courses are availiable for the passage. The situation is complicated by the dependence of online courses, for each course there is a list of those that must be passed before starting this online course (the list can be empty, it means that there is no limitation). Help Polycarp to pass the least number of courses in total to get the specialty (it means to pass all main and necessary courses). Write a program which prints the order of courses. Polycarp passes courses consistently, he starts the next course when he finishes the previous one. Each course can't be passed more than once. The first line contains *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the number of online-courses and the number of main courses of Polycarp's specialty. The second line contains *k* distinct integers from 1 to *n* — numbers of main online-courses of Polycarp's specialty. Then *n* lines follow, each of them describes the next course: the *i*-th of them corresponds to the course *i*. Each line starts from the integer *t**i* (0<=≤<=*t**i*<=≤<=*n*<=-<=1) — the number of courses on which the *i*-th depends. Then there follows the sequence of *t**i* distinct integers from 1 to *n* — numbers of courses in random order, on which the *i*-th depends. It is guaranteed that no course can depend on itself. It is guaranteed that the sum of all values *t**i* doesn't exceed 105. Print -1, if there is no the way to get a specialty. Otherwise, in the first line print the integer *m* — the minimum number of online-courses which it is necessary to pass to get a specialty. In the second line print *m* distinct integers — numbers of courses which it is necessary to pass in the chronological order of their passage. If there are several answers it is allowed to print any of them. Sample Input 6 2 5 3 0 0 0 2 2 1 1 4 1 5 9 3 3 9 5 0 0 3 9 4 5 0 0 1 8 1 6 1 2 2 1 2 3 3 1 2 3 1 2 1 3 1 1 Sample Output 5 1 2 3 4 5 6 1 2 9 4 5 3 -1
{"inputs": ["6 2\n5 3\n0\n0\n0\n2 2 1\n1 4\n1 5", "9 3\n3 9 5\n0\n0\n3 9 4 5\n0\n0\n1 8\n1 6\n1 2\n2 1 2", "3 3\n1 2 3\n1 2\n1 3\n1 1", "5 3\n2 1 4\n0\n0\n1 5\n0\n0", "5 2\n4 1\n0\n1 4\n1 5\n0\n2 1 2", "5 2\n4 5\n2 3 4\n1 4\n1 4\n0\n0", "6 6\n5 4 3 2 6 1\n1 4\n0\n2 2 6\n2 3 6\n3 3 4 6\n0", "6 6\n4 1 6 3 2 5\n2 3 5\n4 1 3 4 5\n1 5\n2 3 5\n0\n2 1 5", "6 5\n2 4 1 3 5\n0\n0\n0\n1 1\n0\n1 3", "7 6\n4 3 2 1 6 5\n0\n2 4 5\n1 6\n1 7\n1 6\n0\n1 4", "7 2\n1 5\n5 2 3 4 5 6\n2 1 7\n0\n3 1 2 7\n0\n2 5 7\n0", "7 6\n2 5 3 1 7 6\n1 7\n2 3 7\n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", "11 3\n9 11 5\n0\n0\n0\n0\n1 8\n0\n2 1 11\n0\n1 2\n0\n0", "11 11\n5 4 2 1 6 10 3 7 11 8 9\n0\n1 3\n0\n0\n0\n2 9 11\n1 9\n0\n0\n0\n0", "11 10\n9 6 10 3 2 8 4 7 11 5\n1 2\n0\n5 1 8 9 10 11\n4 1 7 8 11\n3 2 7 11\n3 1 7 10\n0\n2 6 11\n6 1 2 6 7 10 11\n2 1 11\n2 1 7", "11 10\n5 8 7 6 1 4 9 3 2 11\n3 3 8 10\n2 4 8\n1 5\n2 1 11\n1 4\n3 4 8 9\n2 3 11\n1 5\n3 1 5 8\n2 3 5\n0", "12 9\n9 2 5 7 6 1 10 12 11\n0\n3 6 7 12\n1 4\n1 7\n1 3\n1 1\n0\n0\n2 1 4\n1 3\n0\n2 2 10", "12 10\n2 6 1 5 7 9 10 8 12 3\n1 10\n1 9\n1 11\n0\n1 10\n0\n1 3\n1 7\n1 6\n1 11\n0\n0", "12 10\n9 11 3 6 4 12 2 7 10 8\n1 7\n3 7 8 9\n3 1 8 11\n4 1 7 9 10\n1 4\n1 12\n1 2\n1 2\n0\n2 1 9\n1 7\n1 7", "12 3\n8 10 11\n4 2 5 6 7\n5 4 7 8 10 11\n6 2 4 5 6 8 10\n2 6 8\n0\n3 5 7 8\n0\n2 3 7\n8 2 4 5 6 8 10 11 12\n2 4 7\n6 2 3 5 6 7 12\n5 1 3 6 7 8", "12 1\n8\n2 2 4\n1 9\n1 10\n1 12\n4 6 10 11 12\n0\n0\n1 9\n0\n1 8\n0\n0", "12 10\n4 10 9 6 7 2 1 11 3 8\n1 4\n0\n7 2 4 5 6 7 8 11\n3 1 10 11\n3 4 8 12\n6 4 7 8 10 11 12\n2 2 11\n1 11\n6 3 4 8 10 11 12\n1 12\n1 1\n0", "12 3\n4 7 8\n2 11 12\n0\n0\n2 3 9\n3 7 11 12\n5 1 3 7 8 10\n1 3\n0\n2 2 8\n1 11\n0\n2 8 11", "12 9\n2 10 6 3 4 12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6 ", "9\n1 2 3 4 5 6 7 8 9 ", "-1", "-1", "-1", "3\n2 6 9 ", "-1", "8\n4 2 3 5 7 8 6 9 ", "7\n1 2 4 5 6 7 9 ", "-1", "-1", "-1", "7\n8 7 3 1 2 4 6 ", "2\n4 7 ", "-1", "-1", "-1", "2\n4 9 ", "3\n7 3 5 ", "2\n5 1 ", "1\n4 ", "10\n7 9 2 4 8 1 6 10 3 5 ", "-1", "7\n1 3 4 5 6 10 8 ", "-1", "-1", "-1", "-1", "-1", "-1", "5\n4 1 2 3 6 ", "-1", "-1", "-1", "6\n1 11 2 3 7 10 ", "7\n6 7 3 4 9 11 10 ", "6\n3 2 7 8 10 11 ", "-1", "8\n2 11 1 10 3 4 7 9 ", "8\n7 9 2 11 3 5 10 6 ", "11\n2 3 4 7 11 9 1 5 8 10 6 ", "7\n1 2 3 4 6 8 7 ", "5\n2 8 5 9 11 ", "11\n1 3 2 4 5 9 11 6 7 8 10 ", "11\n2 1 7 11 10 6 8 9 3 4 5 ", "-1", "-1", "11\n11 10 1 6 9 2 3 5 7 8 12 ", "-1", "-1", "2\n9 8 ", "-1", "6\n2 3 8 9 4 7 ", "10\n1 2 3 8 4 5 6 7 10 12 ", "6\n1 12 2 5 11 10 ", "9\n1 3 12 5 10 4 11 9 7 ", "3\n5 4 11 ", "9\n8 9 12 7 11 2 3 5 6 ", "-1", "1\n4 ", "-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
7064cdd96129ae92a071cde28506aecb
Learning Languages
The "BerCorp" company has got *n* employees. These employees can use *m* approved official languages for the formal correspondence. The languages are numbered with integers from 1 to *m*. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar. Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of employees and the number of languages. Then *n* lines follow — each employee's language list. At the beginning of the *i*-th line is integer *k**i* (0<=≤<=*k**i*<=≤<=*m*) — the number of languages the *i*-th employee knows. Next, the *i*-th line contains *k**i* integers — *a**ij* (1<=≤<=*a**ij*<=≤<=*m*) — the identifiers of languages the *i*-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces. Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). Sample Input 5 5 1 2 2 2 3 2 3 4 2 4 5 1 5 8 7 0 3 1 2 3 1 1 2 5 4 2 6 7 1 3 2 7 4 1 1 2 2 1 2 0 Sample Output 0 2 1
{"inputs": ["5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5", "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1", "2 2\n1 2\n0", "2 2\n0\n0", "5 5\n1 3\n0\n0\n2 4 1\n0", "6 2\n0\n0\n2 1 2\n1 1\n1 1\n0", "7 3\n3 1 3 2\n3 2 1 3\n2 2 3\n1 1\n2 2 3\n3 3 2 1\n3 2 3 1", "8 4\n0\n0\n4 2 3 1 4\n4 2 1 4 3\n3 4 3 1\n1 2\n2 4 1\n2 4 2", "10 10\n5 7 5 2 8 1\n7 10 6 9 5 8 2 4\n2 2 7\n5 8 6 9 10 1\n2 9 5\n3 6 5 2\n6 5 8 7 9 10 4\n0\n1 1\n2 8 6", "11 42\n4 20 26 9 24\n14 34 7 28 32 12 15 26 4 10 38 21 20 8 11\n4 21 8 36 6\n11 32 1 39 11 21 10 25 17 26 15 4\n2 8 12\n2 21 31\n8 17 10 3 39 32 30 5 15\n20 24 20 38 17 4 7 21 19 32 28 31 22 30 37 10 5 33 2 13 9\n7 38 34 42 27 20 11 6\n3 40 3 39\n14 39 40 4 30 33 8 36 28 14 23 16 7 25 9", "100 100\n1 33\n0\n2 35 4\n2 40 78\n1 69\n0\n1 2\n0\n0\n2 81 34\n1 45\n0\n1 87\n1 50\n1 97\n0\n2 100 59\n0\n0\n0\n1 45\n0\n0\n0\n1 6\n1 54\n0\n0\n0\n4 79 96 52 84\n1 86\n0\n0\n0\n0\n0\n0\n0\n0\n3 90 2 80\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 2\n0\n1 64\n0\n1 78\n1 82\n0\n0\n0\n0\n0\n1 6\n0\n0\n2 47 57\n1 95\n0\n2 91 79\n0\n1 27\n0\n1 74\n0\n0\n1 14\n0\n0\n2 90 19\n0\n1 10\n0\n0\n0\n0\n0\n1 57\n0\n2 28 50\n0\n0\n0\n1 47\n0\n0\n1 14\n0\n1 84\n1 1\n0\n0", "2 2\n2 1 2\n2 1 2", "2 2\n2 1 2\n1 1", "2 2\n1 2\n1 1", "3 100\n0\n0\n0", "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", "3 3\n0\n0\n0"], "outputs": ["0", "2", "1", "2", "4", "3", "0", "2", "1", "0", "87", "0", "0", "1", "3", "100", "3"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
105
codeforces
706acd5730014b72a9d13d61f09d85ff
Mister B and Book Reading
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages. At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at second — *v*0<=+<=*a* pages, at third — *v*0<=+<=2*a* pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than *v*1 pages per day. Also, to refresh his memory, every day, starting from the second, Mister B had to reread last *l* pages he read on the previous day. Mister B finished the book when he read the last page for the first time. Help Mister B to calculate how many days he needed to finish the book. First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=&lt;<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading. Print one integer — the number of days Mister B needed to finish the book. Sample Input 5 5 10 5 4 12 4 12 4 1 15 1 100 0 0 Sample Output 1 3 15
{"inputs": ["5 5 10 5 4", "12 4 12 4 1", "15 1 100 0 0", "1 1 1 0 0", "1000 999 1000 1000 998", "1000 2 2 5 1", "1000 1 1 1000 0", "737 41 74 12 11", "1000 1000 1000 0 999", "765 12 105 5 7", "15 2 2 1000 0", "1000 1 1000 1000 0", "20 3 7 1 2", "1000 500 500 1000 499", "1 1000 1000 1000 0", "1000 2 1000 56 0", "1000 2 1000 802 0", "16 1 8 2 0", "20 6 10 2 2", "8 2 12 4 1", "8 6 13 2 5", "70 4 20 87 0", "97 8 13 234 5", "16 4 23 8 3", "65 7 22 7 4", "93 10 18 11 7", "86 13 19 15 9", "333 17 50 10 16", "881 16 55 10 12", "528 11 84 3 9", "896 2 184 8 1", "236 10 930 9 8", "784 1 550 14 0", "506 1 10 4 0", "460 1 3 2 0", "701 1 3 1 0", "100 49 50 1000 2", "100 1 100 100 0", "12 1 4 2 0", "22 10 12 0 0", "20 10 15 1 4", "1000 5 10 1 4", "1000 1 1000 1 0", "4 1 2 2 0", "1 5 5 1 1", "19 10 11 0 2", "1 2 3 0 0", "10 1 4 10 0", "20 3 100 1 1", "1000 5 9 5 0", "1 11 12 0 10", "1 1 1 1 0", "1000 1 20 1 0", "9 1 4 2 0", "129 2 3 4 0", "4 2 2 0 1", "1000 1 10 100 0", "100 1 100 1 0", "8 3 4 2 0", "20 1 6 4 0", "8 2 4 2 0", "11 5 6 7 2", "100 120 130 120 0", "7 1 4 1 0", "5 3 10 0 2", "5 2 2 0 0", "1000 10 1000 10 0", "25 3 50 4 2", "9 10 10 10 9", "17 10 12 6 5", "15 5 10 3 0", "8 3 5 1 0", "19 1 12 5 0", "1000 10 1000 1 0", "100 1 2 1000 0", "20 10 11 1000 9", "16 2 100 1 1", "18 10 13 2 5", "12 3 5 3 1", "17 3 11 2 0", "4 2 100 1 1", "7 4 5 2 3", "100 1 2 2 0", "50 4 5 5 0", "1 2 2 0 1", "1000 2 3 10 1", "500 10 500 1000 0", "1000 4 12 1 0", "18 10 13 1 5", "7 3 6 2 2", "15 5 100 1 2", "100 1 10 1 0", "8 2 7 5 1", "11 2 4 1 1", "1000 500 900 100 300", "7 1 2 5 0", "7 3 5 3 2", "7 3 10 2 1", "1000 501 510 1 499", "1000 1 1000 2 0", "1 5 5 0 0", "18 10 15 1 5", "100 4 1000 1 2", "20 2 40 1 1", "1 11 1000 100 1", "6 4 4 1 2", "8 3 5 3 1", "10 5 7 1 2", "400 100 198 1 99", "3 1 2 5 0"], "outputs": ["1", "3", "15", "1", "2", "999", "1000", "13", "1", "17", "8", "2", "6", "501", "1", "7", "3", "4", "3", "3", "2", "5", "13", "3", "5", "9", "9", "12", "23", "19", "16", "8", "12", "53", "154", "235", "3", "2", "4", "3", "3", "169", "45", "3", "1", "3", "1", "4", "5", "112", "1", "1", "60", "4", "44", "3", "101", "14", "3", "5", "3", "3", "1", "4", "3", "3", "14", "4", "1", "2", "3", "3", "4", "37", "51", "6", "5", "3", "4", "4", "2", "3", "51", "11", "1", "500", "2", "87", "3", "3", "4", "15", "2", "5", "3", "4", "3", "2", "50", "32", "1", "3", "13", "6", "1", "2", "3", "3", "25", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
195
codeforces
7076598337a1b1fdaeeb053b998c22c7
none
Память компьютера состоит из *n* ячеек, которые выстроены в ряд. Пронумеруем ячейки от 1 до *n* слева направо. Про каждую ячейку известно, свободна она или принадлежит какому-либо процессу (в таком случае известен процесс, которому она принадлежит). Для каждого процесса известно, что принадлежащие ему ячейки занимают в памяти непрерывный участок. С помощью операций вида «переписать данные из занятой ячейки в свободную, а занятую теперь считать свободной» требуется расположить все принадлежащие процессам ячейки в начале памяти компьютера. Другими словами, любая свободная ячейка должна располагаться правее (иметь больший номер) любой занятой. Вам необходимо найти минимальное количество операций переписывания данных из одной ячейки в другую, с помощью которых можно достичь описанных условий. Допустимо, что относительный порядок ячеек в памяти для каждого из процессов изменится после дефрагментации, но относительный порядок самих процессов должен остаться без изменений. Это значит, что если все ячейки, принадлежащие процессу *i*, находились в памяти раньше всех ячеек процесса *j*, то и после перемещений это условие должно выполняться. Считайте, что номера всех процессов уникальны, хотя бы одна ячейка памяти занята каким-либо процессом. В первой строке входных данных записано число *n* (1<=≤<=*n*<=≤<=200<=000) — количество ячеек в памяти компьютера. Во второй строке входных данных следуют *n* целых чисел *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), где *a**i* равно либо 0 (это означает, что *i*-я ячейка памяти свободна), либо номеру процесса, которому принадлежит *i*-я ячейка памяти. Гарантируется, что хотя бы одно значение *a**i* не равно 0. Процессы пронумерованы целыми числами от 1 до *n* в произвольном порядке. При этом процессы не обязательно пронумерованы последовательными числами. Выведите одно целое число — минимальное количество операций, которое нужно сделать для дефрагментации памяти. Sample Input 4 0 2 2 1 8 0 8 8 8 0 4 4 2 Sample Output 2 4
{"inputs": ["4\n0 2 2 1", "8\n0 8 8 8 0 4 4 2", "5\n0 0 0 1 1", "6\n0 0 0 3 0 0", "10\n0 10 10 0 0 3 3 0 0 0", "10\n0 9 9 9 9 0 8 8 8 8", "15\n0 0 6 6 0 0 0 0 4 0 0 0 9 0 0", "21\n0 11 11 11 11 0 7 0 12 12 12 12 12 0 19 19 19 0 1 1 1", "24\n0 0 6 6 6 0 22 22 0 23 23 0 19 19 19 19 0 0 17 0 0 3 3 3", "15\n1 1 1 1 5 5 5 4 4 4 3 3 3 2 7", "1\n1", "21\n11 0 0 0 0 7 0 12 0 0 0 0 0 19 0 0 0 1 0 0 0", "24\n6 6 0 0 0 22 0 0 23 0 0 19 0 0 0 0 17 17 0 3 3 0 0 0", "6\n4 4 2 6 6 6"], "outputs": ["2", "4", "2", "1", "3", "3", "4", "11", "14", "0", "0", "4", "7", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
708021a251c01c25860c6d84972d479c
Primes or Palindromes?
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this! Let us remind you that a number is called prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one. Rikhail calls a number a palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left. One problem with prime numbers is that there are too many of them. Let's introduce the following notation: π(*n*) — the number of primes no larger than *n*, *rub*(*n*) — the number of palindromic numbers no larger than *n*. Rikhail wants to prove that there are a lot more primes than palindromic ones. He asked you to solve the following problem: for a given value of the coefficient *A* find the maximum *n*, such that π(*n*)<=≤<=*A*·*rub*(*n*). The input consists of two positive integers *p*, *q*, the numerator and denominator of the fraction that is the value of *A* (, ). If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes). Sample Input 1 1 1 42 6 4 Sample Output 40 1 172
{"inputs": ["1 1", "1 42", "6 4", "3 1", "42 1", "10000 239", "5 8", "7 11", "16 60", "214 210", "620 35", "940 480", "1307 3420", "6811 5416", "7 267", "106 6", "10000 10000", "10000 9999", "9999 9998", "9999 9999", "4 9", "1000 10000", "238 9996", "999 10000", "241 10000", "239 10000", "5858 674"], "outputs": ["40", "1", "172", "2530", "1179858", "1168638", "16", "16", "1", "40", "251262", "1372", "1", "66", "1", "250300", "40", "40", "40", "40", "10", "1", "1", "1", "1", "1", "71118"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
33
codeforces
708287e8934727d8ebe2beebfac85f87
Chtholly's request
— 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. Sample Input 2 100 5 30 Sample Output 33 15
{"inputs": ["2 100", "5 30", "42147 412393322", "77809 868097296", "5105 443422097", "75615 376679484", "22951 23793302", "12785 993582106", "60276 428978808", "84776 104860385", "41984 653766991", "100000 1000000000", "41163 472310076", "6983 765352180", "33493 967727004", "90898 94010922", "67298 349286579", "92452 296773064", "58832 563860457", "90234 156145441", "91454 977186148", "11108 444095250", "46304 584475527", "1 1", "1 1000000000", "100000 1"], "outputs": ["33", "15", "251637727", "440411873", "363192634", "373089399", "1898631", "286204743", "376477293", "10209596", "17823101", "495495496", "207304047", "586866999", "305705165", "65928728", "156435206", "229486976", "16775206", "44023160", "681779748", "188075844", "275627129", "0", "11", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
239
codeforces
7086902dabc23efb313bf9a8eb66893f
Presents
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. Sample Input 4 2 3 4 1 3 1 3 2 2 1 2 Sample Output 4 1 2 3 1 3 2 1 2
{"inputs": ["4\n2 3 4 1", "3\n1 3 2", "2\n1 2", "1\n1", "10\n1 3 2 6 4 5 7 9 8 10", "5\n5 4 3 2 1", "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19", "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19", "10\n3 4 5 6 7 8 9 10 1 2", "8\n1 5 3 7 2 6 4 8", "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47", "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17", "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85", "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49", "12\n3 8 7 4 6 5 2 1 11 9 10 12", "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76", "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43", "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27", "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22", "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13", "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21", "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33", "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23", "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12", "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31", "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3", "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8", "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71", "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9", "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44", "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17", "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7", "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16", "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65", "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16", "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51", "12\n12 3 1 5 11 6 7 10 2 8 9 4", "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17", "8\n1 3 5 2 4 8 6 7", "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14", "10\n2 9 4 6 10 1 7 5 3 8", "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3", "10\n2 4 9 3 6 8 10 5 1 7", "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15", "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1", "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30", "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52", "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18", "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16", "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37", "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71", "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22", "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12", "7\n2 1 5 7 3 4 6", "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35", "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16", "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52", "9\n8 5 2 6 1 9 4 7 3", "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27", "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34", "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29", "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7", "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34", "9\n4 8 6 5 3 9 2 7 1", "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29", "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47", "13\n3 12 9 2 8 5 13 4 11 1 10 7 6", "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29", "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3", "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20", "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42", "6\n4 3 6 5 1 2", "9\n7 8 5 3 1 4 2 9 6", "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37", "1\n1", "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11", "2\n2 1", "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28", "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13", "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14", "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29", "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5", "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54", "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29", "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23", "10\n2 10 7 4 1 5 8 6 3 9", "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13", "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2", "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53", "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53", "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64", "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86", "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75", "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53", "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39", "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87", "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25", "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61", "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92", "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6", "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"], "outputs": ["4 1 2 3", "1 3 2", "1 2", "1", "1 3 2 5 6 4 7 9 8 10", "5 4 3 2 1", "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19", "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19", "9 10 1 2 3 4 5 6 7 8", "1 5 3 7 2 6 4 8", "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19", "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25", "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30", "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49", "8 7 1 4 6 5 3 2 10 11 9 12", "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4", "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1", "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3", "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53", "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24", "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61", "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14", "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21", "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9", "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13", "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16", "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6", "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90", "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9", "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20", "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28", "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5", "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43", "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43", "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45", "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64", "3 9 2 12 4 6 7 10 11 8 5 1", "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44", "1 4 2 5 3 7 8 6", "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12", "6 1 9 3 8 4 7 10 2 5", "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7", "9 1 4 2 8 5 10 6 3 7", "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23", "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27", "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23", "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50", "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98", "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25", "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54", "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71", "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8", "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51", "2 1 5 6 3 7 4", "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31", "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21", "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11", "5 3 9 7 2 4 8 1 6", "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13", "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6", "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14", "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16", "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24", "9 7 5 1 4 3 8 2 6", "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32", "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11", "10 4 1 8 6 13 12 5 3 11 9 2 7", "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37", "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25", "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24", "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59", "5 6 2 1 4 3", "5 7 4 6 3 9 1 2 8", "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13", "1", "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13", "2 1", "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18", "8 6 3 13 12 2 7 11 10 9 5 4 14 1", "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36", "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32", "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40", "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21", "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4", "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50", "5 1 9 4 6 8 3 7 10 2", "3 2 11 12 13 5 10 4 9 8 7 6 14 1", "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11", "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37", "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53", "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49", "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38", "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2", "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5", "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12", "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82", "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97", "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96", "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96", "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36", "100 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"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
875
codeforces
709787118e4472b115d8d0cf837ebc30
A Determined Cleanup
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must. Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this... Given two integers *p* and *k*, find a polynomial *f*(*x*) with non-negative integer coefficients strictly less than *k*, whose remainder is *p* when divided by (*x*<=+<=*k*). That is, *f*(*x*)<==<=*q*(*x*)·(*x*<=+<=*k*)<=+<=*p*, where *q*(*x*) is a polynomial (not necessarily with integer coefficients). The only line of input contains two space-separated integers *p* and *k* (1<=≤<=*p*<=≤<=1018, 2<=≤<=*k*<=≤<=2<=000). If the polynomial does not exist, print a single integer -1, or output two lines otherwise. In the first line print a non-negative integer *d* — the number of coefficients in the polynomial. In the second line print *d* space-separated integers *a*0,<=*a*1,<=...,<=*a**d*<=-<=1, describing a polynomial fulfilling the given requirements. Your output should satisfy 0<=≤<=*a**i*<=&lt;<=*k* for all 0<=≤<=*i*<=≤<=*d*<=-<=1, and *a**d*<=-<=1<=≠<=0. If there are many possible solutions, print any of them. Sample Input 46 2 2018 214 Sample Output 7 0 1 0 0 1 1 1 3 92 205 1
{"inputs": ["46 2", "2018 214", "4 2", "5 2", "10 3", "250 1958", "1000000000000000000 2000", "1 2", "2 2", "3 2", "6 2", "7 2", "8 2", "9 2", "10 2", "1 3", "2 3", "3 3", "4 3", "5 3", "6 3", "7 3", "8 3", "9 3", "462 2", "462 3", "2018 4", "20180214 5", "1317 221", "1314 520", "1562 862", "6666666666666666 3", "252525252525252525 252", "271828182845904523 536", "314159265358979323 846", "393939393939393939 393", "233333333333333333 2000", "998244353998244353 2000", "1000000000000000000 2", "1000000000000000000 3"], "outputs": ["7\n0 1 0 0 1 1 1", "3\n92 205 1", "3\n0 0 1", "3\n1 0 1", "3\n1 0 1", "1\n250", "7\n0 0 0 0 500 1969 1", "1\n1", "3\n0 1 1", "3\n1 1 1", "5\n0 1 0 1 1", "5\n1 1 0 1 1", "5\n0 0 0 1 1", "5\n1 0 0 1 1", "5\n0 1 1 1 1", "1\n1", "1\n2", "3\n0 2 1", "3\n1 2 1", "3\n2 2 1", "3\n0 1 1", "3\n1 1 1", "3\n2 1 1", "3\n0 0 1", "11\n0 1 0 0 1 0 1 1 0 1 1", "7\n0 2 1 1 0 1 1", "7\n2 0 2 1 0 2 1", "11\n4 3 4 4 4 3 2 2 2 0 2", "3\n212 216 1", "3\n274 518 1", "3\n700 861 1", "35\n0 1 2 0 0 2 2 1 2 2 1 1 2 2 2 2 0 0 0 2 1 2 1 1 1 1 1 2 1 2 0 1 1 2 1", "9\n189 176 211 80 27 238 231 249 1", "7\n3 157 21 240 147 288 12", "7\n553 47 111 353 790 122 1", "7\n237 191 82 181 11 30 107", "7\n1333 1334 1334 1334 584 1993 1", "7\n353 878 500 1456 391 1969 1", "61\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 1 0 0 0 0 1 0 0 0 1 0 0 1", "39\n1 0 0 0 2 0 2 2 0 2 0 0 1 1 1 2 1 1 1 0 1 2 2 0 1 1 1 2 0 0 0 1 0 0 0 1 1 1 1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
37
codeforces
709fd4d9e29409d95b3039b0cf648ced
Correcting Mistakes
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words *S* and *T* of the same length *n* determine how many words *W* of length *n*<=+<=1 are there with such property that you can transform *W* into both *S*, and *T* by deleting exactly one character. Words *S* and *T* consist of lowercase English letters. Word *W* also should consist of lowercase English letters. The first line contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of words *S* and *T*. The second line contains word *S*. The third line contains word *T*. Words *S* and *T* consist of lowercase English letters. It is guaranteed that *S* and *T* are distinct words. Print a single integer — the number of distinct words *W* that can be transformed to *S* and *T* due to a typo. Sample Input 7 reading trading 5 sweet sheep 3 toy try Sample Output 1 0 2
{"inputs": ["7\nreading\ntrading", "5\nsweet\nsheep", "3\ntoy\ntry", "5\nspare\nspars", "1\na\nb", "1\nz\ny", "2\nab\nac", "2\nba\nca", "2\nac\ncb", "100\neebdeddddbecdbddaaecbbaccbecdeacedddcaddcdebedbabbceeeadecadbbeaecdaeabbceacbdbdbbdacebbbccdcbbeedbe\ndacdeebebeaeaacdeedadbcbaedcbddddddedacbabeddebaaebbdcebebaaccbaeccbecdbcbceadaaecadecbadbcddcdabecd", "250\niiffiehchidfgigdbcciahdehjjfacbbaaadagaibjjcehjcbjdhaadebaejiicgidbhajfbfejcdicgfbcchgbahfccbefdcddbjjhejigiafhdjbiiehadfficicbebeeegcebideijidbgdecffeaegjfjbbcfiabfbaiddbjgidebdiccfcgfbcbbfhaejaibeicghecchjbiaceaibfgibhgcfgifiedcbhhfadhccfdhejeggcah\njbadcfjffcfabbecfabgcafgfcgfeffjjhhdaajjgcbgbechhiadfahjidcdiefhbabhjhjijghghcgghcefhidhdgficiffdjgfdahcaicidfghiedgihbbjgicjeiacihdihfhadjhccddhigiibafiafficegaiehabafiiecbjcbfhdbeaebigaijehhdbfeehbcahaggbbdjcdbgbiajgeigdeabdbddbgcgjibfdgjghhdidjdhh", "100\nabababbbababbababaaabbbbaaaabbabbabbabababbbaaaabbababbbbababbabbbaaababababbbaaaabbbabbababbbbbbaba\nabababbbababbababaaabbbbaaaabbabbabbabababbbaaaabaababbbbababbabbbaaababababbbaaaabbbabbababbbbbbaba", "100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "100\naaaaaaaaaaaaaaaaaaaaaalaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaakaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "100\ndwtsrrtztfuibkrpwbxjrcxsonrwoydkmbhxrghekvusiyzqkyvulrvtfxmvrphpzpmazizogfbyauxtjfesocssnxvjjdedomlz\ndwtsrrtztfuibkrpwbxjrcxsonrwoydkmbhxrghekvusiyzqkyvulrvtfxmvrphpzpzazizogfbyauxtjfesocssnxvjjdedomlz", "100\naaabaabbbababbbaabbbbbaaababbabbaaabbabaabbabbabbbbbabbaaabbbbbbbbbbbbbbbababaaababbaaabeabbabaabbab\naaabaabbbababbbaabbbbbaaababbabbaaabbabaabbabbabbbbbabbaaabbbbbbbbbbbbbbbababaaababbaaabtabbabaabbab", "100\naaaabaaaaabbaababaaabaababaabbbaabaaabbbaaababbabaabbabababbaaabaabababbbababbbabbaaaabbbbbbbaaababa\naaaabaaaaabbaababaaabaababaabbbaabaaabbbaaaabbbabaabbabababbaaabaabababbbababbbabbaaaabbbbbbbaaababa", "100\neebdeddddbecdbddaaecbbaccbecdeacedddcaddcdebedbabbceeeadecadbbeaecdaeabbceacbdbdbbdacebbbccdcbbeedbe\needbeddddbecdbddaaecbbaccbecdeacedddcaddcdebedbabbceeeadecadbbeaecdaeabbceacbdbdbbdacebbbccdcbbeedbe", "100\nxjywrmrwqaytezhtqmcnrrjomslvcmevncvzeddnvqgkbusnbzrppdsuzsmcobmnslpvosunavayvdbxhtavvwodorwijxfjjlat\nxjywrmrwqaytezhtqmcrnrjomslvcmevncvzeddnvqgkbusnbzrppdsuzsmcobmnslpvosunavayvdbxhtavvwodorwijxfjjlat", "4\nbbca\nabab", "4\nabcb\nccac", "4\ncaaa\nabab", "4\nacca\nbabb", "4\nccba\nbabb", "4\nbcca\ncbaa", "4\naaca\ncaab", "4\nbaab\nbcbc", "4\nabba\ncaca", "4\nbcbb\nccac", "4\ncbba\nabba", "4\nbaca\nccbc", "4\ncabc\naacc", "4\nbbab\ncbaa", "4\nabcc\nbcab", "4\nbaaa\nbbbc", "4\naabc\naacb", "4\nccbb\nbbcb", "4\nbaba\naccc", "4\nbbbc\nbbab", "2\nab\nba", "5\ncabac\ncbabc", "3\naba\nbab", "5\nabxxx\nbayyy", "4\nxaxa\naxax", "5\nababa\nbabab", "5\nbabab\nababa", "154\nwqpewhyutqnhaewqpewhywqpewhyutqnhaeutqnhaeutqnhaewqpewhyutqnhaewqpewhywqpewhyutqnhaeutqnhaeutqnhaeutqnhaewqpewhyutqnhaewqpewhywqpewhywqpewhywqpewhyutqnhae\nutqnhaeutqnhaeutqnhaewqpewhywqpewhyutqnhaewqpewhyutqnhaewqpewhywqpewhyutqnhaeutqnhaeutqnhaewqpewhyutqnhaewqpewhywqpewhywqpewhyutqnhaewqpewhyutqnhaewqpewhy", "7\ntrading\nrtading", "5\nxabax\nxbabx", "3\nabc\nacb", "4\nabab\nbaba", "3\naab\naba", "2\ner\nre", "5\ntabat\ntbaat"], "outputs": ["1", "0", "2", "2", "2", "2", "2", "2", "1", "0", "0", "2", "2", "2", "2", "2", "2", "2", "2", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "2", "0", "0", "0", "0", "0", "2", "0", "0", "1", "2", "2", "2", "0", "2", "2", "2", "0", "2", "2", "2", "2", "2", "2", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
70ad39a204d5f344618bb21bc61d6a45
Karen and Supermarket
On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to *b* dollars. The supermarket sells *n* goods. The *i*-th good can be bought for *c**i* dollars. Of course, each good can only be bought once. Lately, the supermarket has been trying to increase its business. Karen, being a loyal customer, was given *n* coupons. If Karen purchases the *i*-th good, she can use the *i*-th coupon to decrease its price by *d**i*. Of course, a coupon cannot be used without buying the corresponding good. There is, however, a constraint with the coupons. For all *i*<=≥<=2, in order to use the *i*-th coupon, Karen must also use the *x**i*-th coupon (which may mean using even more coupons to satisfy the requirement for that coupon). Karen wants to know the following. What is the maximum number of goods she can buy, without exceeding her budget *b*? The first line of input contains two integers *n* and *b* (1<=≤<=*n*<=≤<=5000, 1<=≤<=*b*<=≤<=109), the number of goods in the store and the amount of money Karen has, respectively. The next *n* lines describe the items. Specifically: - The *i*-th line among these starts with two integers, *c**i* and *d**i* (1<=≤<=*d**i*<=&lt;<=*c**i*<=≤<=109), the price of the *i*-th good and the discount when using the coupon for the *i*-th good, respectively. - If *i*<=≥<=2, this is followed by another integer, *x**i* (1<=≤<=*x**i*<=&lt;<=*i*), denoting that the *x**i*-th coupon must also be used before this coupon can be used. Output a single integer on a line by itself, the number of different goods Karen can buy, without exceeding her budget. Sample Input 6 16 10 9 10 5 1 12 2 1 20 18 3 10 2 3 2 1 5 5 10 3 1 3 1 1 3 1 2 3 1 3 3 1 4 Sample Output 4 5
{"inputs": ["6 16\n10 9\n10 5 1\n12 2 1\n20 18 3\n10 2 3\n2 1 5", "5 10\n3 1\n3 1 1\n3 1 2\n3 1 3\n3 1 4", "13 30\n6 4\n25 5 1\n7 1 2\n9 4 2\n10 2 1\n12 3 1\n5 2 3\n10 9 6\n2 1 1\n5 3 9\n10 2 10\n10 9 6\n3 2 11", "8 9\n4 3\n8 3 1\n2 1 1\n4 2 2\n7 2 2\n3 1 2\n7 3 5\n2 1 3", "9 15\n3 1\n6 2 1\n8 3 2\n4 1 2\n2 1 2\n3 2 3\n8 7 1\n6 5 5\n8 4 4", "15 1000\n449 257\n881 657 1\n182 101 1\n733 545 2\n277 13 2\n991 689 3\n360 302 3\n965 570 4\n502 178 4\n43 28 5\n446 406 5\n484 152 6\n451 335 6\n874 600 7\n602 34 7", "9 7\n3 1\n6 2 1\n8 3 2\n4 1 2\n2 1 2\n3 2 3\n8 7 1\n6 5 5\n8 4 4", "3 100\n100 48\n50 1 1\n50 1 1", "1 1\n2 1", "1 1\n1000000000 1", "1 1000000000\n1000000000 1", "2 1000000000\n500000001 1\n500000001 1 1"], "outputs": ["4", "5", "9", "4", "7", "7", "3", "2", "1", "0", "1", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
70cd612001f2bd39369ae10726c2feac
none
A remote island chain contains *n* islands, labeled 1 through *n*. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands *n* and 1. The center of each island contains an identical pedestal, and all but one of the islands has a fragile, uniquely colored statue currently held on the pedestal. The remaining island holds only an empty pedestal. The islanders want to rearrange the statues in a new order. To do this, they repeat the following process: First, they choose an island directly adjacent to the island containing an empty pedestal. Then, they painstakingly carry the statue on this island across the adjoining bridge and place it on the empty pedestal. Determine if it is possible for the islanders to arrange the statues in the desired order. The first line contains a single integer *n* (2<=≤<=*n*<=≤<=200<=000) — the total number of islands. The second line contains *n* space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=*n*<=-<=1) — the statue currently placed on the *i*-th island. If *a**i*<==<=0, then the island has no statue. It is guaranteed that the *a**i* are distinct. The third line contains *n* space-separated integers *b**i* (0<=≤<=*b**i*<=≤<=*n*<=-<=1) — the desired statues of the *i*th island. Once again, *b**i*<==<=0 indicates the island desires no statue. It is guaranteed that the *b**i* are distinct. Print "YES" (without quotes) if the rearrangement can be done in the existing network, and "NO" otherwise. Sample Input 3 1 0 2 2 0 1 2 1 0 0 1 4 1 2 3 0 0 3 2 1 Sample Output YES YES NO
{"inputs": ["3\n1 0 2\n2 0 1", "2\n1 0\n0 1", "4\n1 2 3 0\n0 3 2 1", "9\n3 8 4 6 7 1 5 2 0\n6 4 8 5 3 1 2 0 7", "4\n2 3 1 0\n2 0 1 3", "4\n0 1 2 3\n2 0 1 3", "4\n3 0 1 2\n1 0 2 3", "3\n0 2 1\n1 2 0", "2\n0 1\n0 1", "6\n3 1 5 4 0 2\n0 4 3 5 2 1", "4\n2 0 3 1\n3 1 0 2", "5\n3 0 2 1 4\n4 3 0 1 2", "3\n2 0 1\n1 0 2", "10\n6 2 3 8 0 4 9 1 5 7\n2 3 8 4 0 9 1 5 7 6", "10\n2 4 8 3 6 1 9 0 5 7\n3 6 1 9 0 5 7 2 8 4", "10\n2 0 1 6 4 9 8 5 3 7\n6 4 9 0 5 3 7 2 1 8", "3\n0 1 2\n0 1 2", "4\n0 1 2 3\n1 0 2 3", "3\n0 1 2\n1 0 2", "5\n1 2 0 3 4\n4 0 1 2 3", "4\n1 0 2 3\n1 0 2 3", "3\n0 1 2\n0 2 1", "4\n0 1 2 3\n2 3 1 0", "4\n0 2 3 1\n1 2 3 0", "3\n0 2 1\n2 0 1", "2\n1 0\n1 0", "4\n1 2 3 0\n1 0 2 3", "4\n0 1 3 2\n2 1 3 0", "4\n1 2 3 0\n1 2 0 3"], "outputs": ["YES", "YES", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
45
codeforces
71036523df309a43e8e98745069c0f05
Palindromic Times
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome. In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment. However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him. The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits. Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time. Sample Input 12:21 23:59 Sample Output 13:31 00:00
{"inputs": ["12:21", "23:59", "15:51", "10:44", "04:02", "02:11", "12:15", "07:07", "00:17", "04:55", "02:17", "07:56", "00:29", "23:31", "19:30", "12:14", "17:32", "03:44", "07:15", "18:42", "08:56", "04:50", "14:32", "23:23", "08:35", "03:32", "07:59", "14:12", "23:52", "16:36", "17:50", "06:59", "16:50", "00:00", "23:59", "23:33"], "outputs": ["13:31", "00:00", "20:02", "11:11", "04:40", "02:20", "12:21", "10:01", "01:10", "05:50", "02:20", "10:01", "01:10", "23:32", "20:02", "12:21", "20:02", "04:40", "10:01", "20:02", "10:01", "05:50", "14:41", "23:32", "10:01", "04:40", "10:01", "14:41", "00:00", "20:02", "20:02", "10:01", "20:02", "01:10", "00:00", "00:00"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
151
codeforces
7106a5a4ccf392528293f254daca3836
Permutations
You are given a permutation *p* of numbers 1,<=2,<=...,<=*n*. Let's define *f*(*p*) as the following sum: Find the lexicographically *m*-th permutation of length *n* in the set of permutations having the maximum possible value of *f*(*p*). The single line of input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*cnt**n*), where *cnt**n* is the number of permutations of length *n* with maximum possible value of *f*(*p*). The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows. - In subproblem B1 (3 points), the constraint 1<=≤<=*n*<=≤<=8 will hold. - In subproblem B2 (4 points), the constraint 1<=≤<=*n*<=≤<=50 will hold. Output *n* number forming the required permutation. Sample Input 2 2 3 2 Sample Output 2 1 1 3 2
{"inputs": ["2 2", "3 2", "1 1", "3 1", "3 3", "3 4", "4 1", "4 3", "4 4", "4 8", "5 2", "5 7", "5 15", "6 23", "7 7", "7 44", "8 1", "8 127", "8 128"], "outputs": ["2 1 ", "1 3 2 ", "1 ", "1 2 3 ", "2 3 1 ", "3 2 1 ", "1 2 3 4 ", "1 3 4 2 ", "1 4 3 2 ", "4 3 2 1 ", "1 2 3 5 4 ", "1 4 5 3 2 ", "4 5 3 2 1 ", "2 5 6 4 3 1 ", "1 2 3 6 7 5 4 ", "2 4 7 6 5 3 1 ", "1 2 3 4 5 6 7 8 ", "7 8 6 5 4 3 2 1 ", "8 7 6 5 4 3 2 1 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
48
codeforces
713151a56baa3874daf5f2778bd1c45e
Company Income Growth
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to *a*1 billion bourles, in 2002 — to *a*2 billion, ..., and in the current (2000<=+<=*n*)-th year — *a**n* billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year — 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers *a**i* can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers *a**i* from the sequence and leave only some subsequence that has perfect growth. Thus Petya has to choose a sequence of years *y*1, *y*2, ..., *y**k*,so that in the year *y*1 the company income amounted to 1 billion bourles, in the year *y*2 — 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence. The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *a**i* (<=-<=100<=≤<=*a**i*<=≤<=100). The number *a**i* determines the income of BerSoft company in the (2000<=+<=*i*)-th year. The numbers in the line are separated by spaces. Output *k* — the maximum possible length of a perfect sequence. In the next line output the sequence of years *y*1, *y*2, ..., *y**k*. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0. Sample Input 10 -2 1 1 3 2 3 4 -10 -2 5 3 -1 -2 -3 Sample Output 5 2002 2005 2006 2007 2010 0
{"inputs": ["10\n-2 1 1 3 2 3 4 -10 -2 5", "3\n-1 -2 -3", "1\n0", "1\n0", "2\n-1 1", "2\n-1 1", "2\n-2 0", "2\n3 -3", "3\n1 1 1", "3\n-2 -2 1", "4\n-4 2 3 -1", "5\n-3 -3 -4 2 -2", "100\n-1 -9 0 -2 -7 -3 -1 -1 6 -5 -3 5 10 -5 7 7 4 9 -6 1 0 3 0 1 -9 -9 6 -8 3 7 -9 -4 -5 -6 8 2 2 7 2 2 0 -6 5 3 9 7 -7 -7 -2 6 -3 -4 10 3 3 -4 2 -9 9 9 -6 -1 -7 -3 -6 10 10 -1 -8 -3 8 1 10 9 -9 10 4 -10 -6 9 7 8 5 -3 2 2 2 -7 -6 0 -4 -1 4 -2 -4 -1 2 -8 10 9", "100\n5 -1 6 0 2 10 -6 6 -10 0 10 6 -10 3 8 4 2 6 3 -9 1 -1 -8 6 -6 -10 0 -3 -1 -6 -7 -9 -5 -5 5 -10 -3 4 -6 8 -4 2 2 8 2 -7 -4 -4 -9 4 -9 6 -4 -10 -8 -6 2 6 -4 3 3 4 -1 -9 8 9 -6 5 3 9 -4 0 -9 -10 3 -10 2 5 7 0 9 4 5 -3 5 -5 9 -4 6 -7 4 -1 -10 -1 -2 2 -1 4 -10 6", "100\n10 9 -10 0 -9 1 10 -6 -3 8 0 5 -7 -9 9 -1 1 4 9 0 4 -7 3 10 -3 -10 -6 4 -3 0 -7 8 -6 -1 5 0 -6 1 5 -7 10 10 -2 -10 -4 -1 -1 2 5 1 6 -7 3 -1 1 10 4 2 4 -3 -10 9 4 5 1 -10 -1 -9 -8 -2 4 -4 -10 -9 -5 -9 -1 -3 -3 -8 -8 -3 6 -3 6 10 -4 -1 -3 8 -9 0 -2 2 1 6 -4 -7 -9 3", "100\n-8 -3 -4 2 1 -9 5 4 4 -8 -8 6 -7 -1 9 -6 -1 1 -5 9 6 10 -8 -5 -2 10 7 10 -5 8 -7 5 -4 0 3 9 -9 -5 -4 -2 4 -1 -4 -5 -9 6 2 7 0 -2 2 3 -9 6 -10 6 5 -4 -9 -9 1 -7 -9 -3 -5 -8 4 0 4 10 -8 -6 -8 -9 5 -8 -6 -9 10 5 -6 -7 6 -5 8 3 1 3 7 3 -1 0 5 4 4 7 -7 5 -8 -2", "100\n-15 8 -20 -2 -16 3 -19 -15 16 19 -1 -17 -14 9 7 2 20 -16 8 20 10 3 17 -3 2 5 9 15 3 3 -17 12 7 17 -19 -15 -5 16 -10 -4 10 -15 -16 9 -15 15 -16 7 -15 12 -17 7 4 -8 9 -2 -19 14 12 -1 17 -6 19 14 19 -9 -12 3 14 -10 5 7 19 11 5 10 18 2 -6 -12 7 5 -9 20 10 2 -20 6 -10 -16 -6 -5 -15 -2 15 -12 0 -18 2 -5", "100\n11 18 14 -19 -12 -5 -14 -3 13 14 -20 11 -6 12 -2 19 -16 -2 -4 -4 -18 -2 -15 5 -7 -18 11 5 -8 16 17 1 6 8 -20 13 17 -15 -20 7 16 -3 -17 -1 1 -18 2 9 4 2 -18 13 16 -14 -18 -14 16 19 13 4 -14 3 5 -7 5 -17 -14 13 20 16 -13 7 12 15 0 4 16 -16 -6 -15 18 -19 2 8 -4 -8 14 -4 20 -15 -20 14 7 -10 -17 -20 13 -1 -11 -4", "100\n3 99 47 -26 96 90 21 -74 -19 -17 80 -43 -24 -82 -39 -40 44 84 87 72 -78 -94 -82 -87 96 71 -29 -90 66 49 -87 19 -31 97 55 -29 -98 16 -23 68 84 -54 74 -71 -60 -32 -72 95 -55 -17 -49 -73 63 39 -31 -91 40 -29 -60 -33 -33 49 93 -56 -81 -18 38 45 -29 63 -37 27 75 13 -100 52 -51 75 -38 -49 28 39 -7 -37 -86 100 -8 28 -89 -57 -17 -52 -98 -92 56 -49 -24 92 28 31", "100\n-36 -88 -23 -71 33 53 21 49 97 -50 -91 24 -83 -100 -77 88 -56 -31 -27 7 -74 -69 -75 -59 78 -66 53 21 -41 72 -31 -93 26 98 58 78 -95 -64 -2 34 74 14 23 -25 -51 -94 -46 100 -44 79 46 -8 79 25 -55 16 35 67 29 58 49 75 -53 80 63 -50 -59 -5 -71 -72 -57 75 -71 6 -5 -44 34 -2 -10 -58 -98 67 -42 22 95 46 -58 88 62 82 85 -74 -94 -5 -64 12 -8 44 -57 87", "100\n-76 -73 -93 85 -30 66 -29 -79 13 -82 -12 90 8 -68 86 15 -5 55 -91 92 80 5 83 19 59 -1 -17 83 52 44 25 -3 83 -51 62 -66 -91 58 20 51 15 -70 -77 22 -92 -4 -70 55 -33 -27 -59 6 94 60 -79 -28 -20 -38 -83 100 -20 100 51 -35 -44 -82 44 -5 88 -6 -26 -79 -16 -2 -61 12 -81 -80 68 -68 -23 96 -77 80 -75 -57 93 97 12 20 -65 -46 -90 81 16 -77 -43 -3 8 -58", "100\n-64 -18 -21 46 28 -100 21 -98 49 -44 -38 52 -85 62 42 -85 19 -27 88 -45 28 -86 -20 15 34 61 17 88 95 21 -40 -2 -12 90 -61 30 7 -13 -74 43 -57 43 -30 51 -19 -51 -22 -2 -76 85 1 -53 -31 -77 96 -61 61 88 -62 88 -6 -59 -70 18 -65 90 91 -27 -86 37 8 -92 -82 -78 -57 -81 17 -53 3 29 -88 -92 -28 49 -2 -41 32 -89 -38 49 22 37 -17 -1 -78 -80 -12 36 -95 30", "1\n1", "2\n1 2", "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", "100\n-29 -92 -94 81 -100 1 -29 2 3 97 -37 4 5 -52 6 7 -81 86 8 9 10 98 36 -99 11 -18 12 -46 13 14 15 16 17 18 19 20 21 23 53 22 23 24 6 17 45 25 99 26 -53 -51 48 -11 71 27 -56 28 29 -36 30 31 61 -53 -64 32 33 89 -90 34 35 54 36 -89 13 -89 5 37 38 39 -57 26 55 80 40 63 41 42 43 44 92 45 46 47 -10 -10 -32 48 49 50 -10 -99", "100\n1 2 84 -97 3 -59 30 -55 4 -6 80 5 6 7 -8 8 3 -96 88 9 10 -20 -95 11 12 67 5 4 -15 -62 -74 13 14 15 16 17 18 19 20 21 22 -15 23 -35 -17 24 25 -99 26 27 69 2 -92 -96 -77 28 29 -95 -75 30 -36 31 17 -88 10 52 32 33 34 -94 35 -38 -16 36 37 38 31 -58 39 -81 83 46 40 41 42 43 -44 44 4 49 -60 17 64 45 46 47 48 49 -38 50", "100\n1 2 80 30 95 51 -3 -12 3 -11 4 -90 5 6 7 8 -18 52 77 -82 9 10 11 -51 -16 70 12 13 14 15 16 17 58 18 36 19 -86 20 21 40 -53 94 22 23 27 67 24 -90 -38 17 -71 40 25 72 -82 26 27 -4 28 29 30 31 32 67 33 34 90 42 -52 35 36 37 -6 38 39 -11 30 40 41 42 -42 21 -96 43 -50 44 -73 16 45 90 46 47 48 2 -37 -88 49 -27 -43 50", "100\n1 2 3 -72 6 4 5 6 7 8 9 10 11 -57 12 13 14 -37 74 15 16 17 3 18 19 20 21 22 -6 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 -24 39 40 41 42 43 44 45 -52 46 -65 47 -82 48 49 50 47 -28 51 52 53 54 55 -30 56 57 58 59 12 60 61 62 63 -14 64 65 66 67 -77 68 69 70 71 72 73 74 -4 -6 -75 75 -26 76 49 77 -86", "100\n10 5 -69 1 -79 -57 -80 87 -38 -54 -91 33 29 81 20 -58 -97 70 2 -13 71 57 -15 98 -18 100 34 -25 -39 75 100 -88 3 95 48 -92 -20 -13 5 4 -19 -99 4 -46 -35 12 -43 -30 -37 -51 77 90 -47 -87 3 -84 -62 -51 69 -38 74 -63 -5 5 6 7 -65 90 -33 -23 8 19 -69 -98 24 28 100 9 -90 -34 -69 72 -15 8 27 -80 6 33 62 -57 -4 10 40 81 -78 58 43 83 57 21", "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", "10\n2 3 1 3 3 2 1 2 1 2", "15\n4 1 4 6 3 2 1 1 3 2 4 4 1 4 1", "15\n3 3 3 2 2 2 1 1 1 2 2 2 4 4 4", "15\n6 5 2 3 4 1 3 2 4 5 1 2 6 4 4"], "outputs": ["5\n2002 2005 2006 2007 2010 ", "0", "0", "0", "1\n2002 ", "1\n2002 ", "0", "0", "1\n2001 ", "1\n2003 ", "0", "0", "5\n2020 2036 2044 2077 2083 ", "6\n2021 2042 2060 2062 2068 2089 ", "6\n2006 2048 2053 2057 2064 2083 ", "7\n2005 2047 2052 2067 2075 2083 2089 ", "0", "4\n2032 2047 2062 2076 ", "0", "0", "0", "1\n2051 ", "1\n2001 ", "2\n2001 2002 ", "100\n2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 ", "50\n2006 2008 2009 2012 2013 2015 2016 2019 2020 2021 2025 2027 2029 2030 2031 2032 2033 2034 2035 2036 2037 2040 2041 2042 2046 2048 2054 2056 2057 2059 2060 2064 2065 2068 2069 2071 2076 2077 2078 2083 2085 2086 2087 2088 2090 2091 2092 2096 2097 2098 ", "50\n2001 2002 2005 2009 2012 2013 2014 2016 2020 2021 2024 2025 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2043 2046 2047 2049 2050 2056 2057 2060 2062 2067 2068 2069 2071 2074 2075 2076 2079 2083 2084 2085 2086 2088 2094 2095 2096 2097 2098 2100 ", "50\n2001 2002 2009 2011 2013 2014 2015 2016 2021 2022 2023 2027 2028 2029 2030 2031 2032 2034 2036 2038 2039 2043 2044 2047 2053 2056 2057 2059 2060 2061 2062 2063 2065 2066 2070 2071 2072 2074 2075 2078 2079 2080 2084 2086 2089 2091 2092 2093 2097 2100 ", "77\n2001 2002 2003 2006 2007 2008 2009 2010 2011 2012 2013 2015 2016 2017 2020 2021 2022 2024 2025 2026 2027 2028 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2047 2048 2049 2050 2051 2052 2053 2055 2057 2059 2060 2061 2064 2065 2066 2067 2068 2070 2071 2072 2073 2075 2076 2077 2078 2080 2081 2082 2083 2085 2086 2087 2088 2089 2090 2091 2095 2097 2099 ", "10\n2004 2019 2033 2040 2064 2065 2066 2071 2078 2092 ", "0", "2\n2003 2006 ", "4\n2002 2006 2009 2011 ", "2\n2007 2010 ", "2\n2006 2008 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
52
codeforces
7138af4685444691c2b25b0bdce983e3
Destruction of a Tree
You are given a tree (a graph with *n* vertices and *n*<=-<=1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted. Destroy all vertices in the given tree or determine that it is impossible. The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — number of vertices in a tree. The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=*n*). If *p**i*<=≠<=0 there is an edge between vertices *i* and *p**i*. It is guaranteed that the given graph is a tree. If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes). If it's possible to destroy all vertices, in the next *n* lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any. Sample Input 5 0 1 2 1 2 4 0 1 2 3 Sample Output YES 1 2 3 5 4 NO
{"inputs": ["5\n0 1 2 1 2", "4\n0 1 2 3", "1\n0", "8\n3 1 4 0 4 2 4 5", "100\n81 96 65 28 4 40 5 49 5 89 48 70 94 70 17 58 58 1 61 19 45 33 46 19 22 83 56 67 62 82 57 16 29 36 84 71 42 66 78 54 73 45 82 80 67 88 79 69 61 66 5 36 24 60 96 21 77 67 68 29 87 37 91 34 78 43 0 69 49 62 16 2 68 79 57 1 60 12 39 99 14 37 30 92 47 18 14 75 73 39 94 12 43 87 90 22 91 59 54 71", "100\n57 85 27 81 41 27 73 10 73 95 91 90 89 41 86 44 6 20 9 13 46 73 56 19 37 32 40 42 79 76 96 5 6 8 76 52 14 86 33 69 100 95 58 87 43 47 17 39 48 28 77 65 100 100 41 39 87 5 61 67 94 64 61 88 32 23 79 44 0 67 44 23 48 96 48 56 86 75 90 2 17 46 4 75 42 90 17 77 5 33 87 91 27 28 58 95 58 47 33 6", "21\n11 10 12 3 6 0 8 6 16 14 5 9 7 19 1 13 15 21 4 2 20", "61\n10 42 20 50 4 24 18 55 19 5 57 13 3 35 58 48 31 46 40 45 15 53 14 25 43 41 22 23 54 39 38 44 16 37 12 34 32 28 26 30 59 47 21 9 8 52 1 0 33 49 36 51 17 11 29 7 48 61 6 27 2", "21\n11 19 4 19 6 0 13 7 6 2 5 3 16 10 1 9 15 21 9 21 2", "61\n47 61 20 5 10 59 46 55 44 1 57 13 3 35 21 48 31 7 9 45 43 53 14 6 42 39 22 23 54 40 45 37 16 36 12 44 34 28 25 19 26 33 25 39 33 36 42 0 50 4 52 46 17 11 29 7 48 15 41 27 58", "79\n0 56 56 42 56 56 56 56 4 56 56 22 56 56 56 48 56 56 56 56 56 24 56 16 56 56 56 9 56 56 56 56 56 56 56 56 56 55 56 56 12 20 56 28 56 56 56 38 56 56 56 56 56 56 44 1 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56", "121\n110 31 57 33 45 33 33 33 91 102 79 33 61 72 107 101 117 10 118 33 33 64 24 94 117 76 33 23 33 49 5 52 95 78 33 39 33 92 17 33 25 33 56 33 3 88 33 108 62 15 28 111 67 33 33 11 96 33 36 70 46 98 80 104 33 19 60 33 112 51 33 2 33 33 121 59 33 41 50 81 105 33 115 34 33 18 84 32 33 33 87 13 86 103 16 119 33 63 30 43 83 53 26 100 69 33 14 38 33 75 66 120 33 33 9 99 0 93 1 48 116", "21\n5 20 9 19 8 0 13 6 13 19 5 3 8 10 1 9 1 20 3 10 18", "61\n5 61 20 5 50 59 56 29 44 1 48 13 20 35 61 33 38 52 30 8 43 17 35 43 24 59 22 23 11 26 38 37 48 36 13 37 44 23 30 19 26 1 15 19 8 18 42 0 50 33 52 36 17 11 29 18 48 15 24 22 42", "21\n18 18 18 18 18 0 18 18 18 18 18 18 18 18 18 18 18 6 18 18 18", "61\n56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 0 56 56 56 56 56 56 56 48 56 56 56 56 56", "21\n15 6 13 7 15 21 8 0 7 16 16 21 12 6 12 12 13 6 15 16 7", "61\n58 39 45 57 31 43 11 24 8 18 56 54 47 37 50 40 19 16 29 10 1 23 36 28 21 48 52 55 27 42 2 33 46 25 53 6 15 26 14 17 9 44 56 34 5 61 38 12 30 7 49 32 20 41 51 0 3 4 60 35 13", "21\n21 6 4 20 14 1 13 10 11 0 10 18 10 12 4 1 2 2 8 2 13", "61\n17 19 8 53 10 38 59 60 46 25 49 28 46 15 25 56 53 60 60 54 18 49 10 53 29 19 11 61 24 11 17 52 32 54 29 55 0 1 14 56 25 14 33 53 47 56 8 6 53 55 16 46 47 9 24 37 3 52 25 37 26", "21\n18 0 18 2 21 2 9 15 3 5 8 2 8 21 6 10 21 13 9 1 13", "61\n45 48 30 23 15 47 8 3 35 56 54 35 17 47 35 56 32 42 14 37 36 44 6 44 1 44 41 46 43 0 33 3 44 54 43 3 47 57 7 32 29 60 36 36 43 61 36 47 3 48 18 8 17 29 3 54 3 6 43 43 56"], "outputs": ["YES\n1\n2\n3\n5\n4", "NO", "YES\n1", "NO", "NO", "NO", "YES\n21\n18\n2\n20\n14\n10\n4\n19\n12\n3\n16\n9\n7\n13\n6\n8\n11\n5\n15\n17\n1", "YES\n27\n60\n53\n22\n31\n17\n28\n38\n14\n23\n12\n35\n3\n13\n45\n20\n55\n8\n54\n29\n57\n11\n16\n48\n49\n33\n4\n50\n10\n5\n7\n56\n46\n18\n51\n52\n34\n36\n32\n37\n9\n44\n40\n19\n39\n30\n41\n26\n6\n59\n25\n24\n21\n43\n58\n15\n2\n61\n47\n42\n1", "YES\n7\n8\n16\n13\n10\n14\n2\n21\n18\n20\n3\n12\n19\n4\n6\n9\n11\n5\n15\n17\n1", "YES\n6\n24\n41\n59\n40\n30\n9\n19\n37\n32\n52\n51\n46\n7\n18\n56\n36\n34\n61\n2\n15\n58\n43\n21\n25\n39\n26\n44\n55\n8\n54\n29\n57\n11\n16\n48\n28\n38\n14\n23\n12\n35\n3\n13\n27\n60\n53\n22\n31\n17\n45\n20\n42\n33\n50\n49\n5\n4\n1\n47\n10", "YES\n12\n41\n24\n22\n48\n16\n55\n38\n28\n44\n4\n9\n20\n42\n56\n2\n3\n5\n6\n7\n8\n10\n11\n13\n14\n15\n17\n18\n19\n21\n23\n25\n26\n27\n29\n30\n31\n32\n33\n34\n35\n36\n37\n39\n40\n43\n45\n46\n47\n49\n50\n51\n52\n53\n54\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n1", "YES\n33\n4\n6\n7\n8\n12\n20\n21\n27\n29\n35\n37\n40\n42\n44\n47\n54\n55\n58\n65\n68\n71\n73\n74\n77\n82\n85\n89\n90\n97\n106\n109\n113\n114\n16\n95\n83\n101\n9\n115\n87\n91\n34\n84\n41\n78\n117\n25\n39\n17\n59\n36\n26\n76\n94\n103\n23\n24\n51\n28\n60\n70\n53\n67\n10\n102\n86\n18\n118\n93\n66\n19\n52\n111\n88\n32\n61\n46\n92\n13\n108\n38\n120\n48\n69\n112\n81\n105\n63\n80\n62\n98\n30\n49\n116\n99\n75\n121\n64\n22\n100\n104\n56\n43\n79\n11\n15\n50\n14\n107\n2\n72\n5\n31\n3\n45\n96\n57\n1\n110\n119", "YES\n18\n21\n20\n2\n10\n14\n19\n4\n3\n12\n9\n16\n13\n7\n8\n6\n5\n11\n1\n15\n17", "YES\n56\n7\n18\n46\n52\n51\n36\n34\n37\n32\n44\n9\n19\n40\n30\n39\n26\n41\n59\n6\n24\n25\n43\n21\n15\n58\n61\n2\n42\n47\n1\n5\n4\n50\n49\n33\n16\n48\n11\n29\n8\n20\n3\n13\n12\n35\n14\n23\n28\n38\n17\n22\n27\n60\n53\n31\n45\n55\n54\n57\n10", "YES\n18\n2\n3\n4\n5\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n6\n19\n20\n21\n1", "YES\n56\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n49\n50\n51\n52\n53\n54\n55\n48\n57\n58\n59\n60\n61\n1", "YES\n6\n2\n14\n18\n7\n4\n8\n9\n16\n10\n11\n20\n15\n5\n12\n21\n13\n3\n17\n19\n1", "YES\n23\n22\n6\n36\n56\n43\n7\n11\n15\n50\n14\n37\n2\n39\n5\n31\n3\n45\n4\n57\n60\n59\n53\n35\n10\n20\n16\n18\n17\n40\n29\n19\n52\n27\n33\n32\n61\n46\n47\n13\n26\n38\n12\n48\n41\n54\n8\n9\n28\n24\n51\n55\n30\n49\n44\n42\n25\n34\n1\n58\n21", "YES\n8\n19\n11\n9\n21\n13\n7\n10\n14\n5\n18\n12\n20\n4\n3\n15\n2\n17\n1\n6\n16", "YES\n15\n14\n39\n42\n59\n7\n3\n57\n18\n21\n28\n12\n26\n61\n19\n2\n16\n51\n9\n54\n20\n34\n33\n43\n37\n56\n40\n46\n13\n52\n32\n58\n8\n60\n47\n45\n6\n48\n1\n17\n53\n4\n24\n29\n25\n10\n5\n23\n41\n35\n55\n36\n50\n44\n49\n11\n27\n30\n22\n31\n38", "YES\n3\n9\n7\n19\n6\n2\n4\n12\n10\n16\n21\n5\n14\n17\n13\n8\n15\n11\n1\n18\n20", "YES\n41\n27\n46\n28\n56\n10\n16\n61\n29\n54\n11\n34\n15\n5\n7\n39\n8\n52\n57\n38\n33\n31\n44\n22\n24\n26\n23\n4\n6\n58\n14\n19\n37\n20\n47\n48\n2\n50\n18\n51\n60\n42\n43\n35\n9\n12\n36\n21\n3\n30\n32\n17\n13\n53\n40\n49\n55\n59\n1\n45\n25"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
716e110f0464198d037e1dd300a49754
Bear and Five Cards
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards. He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number. Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards? The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. Print the minimum possible sum of numbers written on remaining cards. Sample Input 7 3 7 3 20 7 9 3 1 8 10 10 10 10 10 Sample Output 26 28 20
{"inputs": ["7 3 7 3 20", "7 9 3 1 8", "10 10 10 10 10", "8 7 1 8 7", "7 7 7 8 8", "8 8 8 2 2", "8 8 2 2 2", "5 50 5 5 60", "100 100 100 100 100", "1 1 1 1 1", "29 29 20 20 20", "20 29 20 29 20", "31 31 20 20 20", "20 20 20 31 31", "20 31 20 31 20", "20 20 20 30 30", "30 30 20 20 20", "8 1 8 8 8", "1 1 1 8 1", "1 2 3 4 5", "100 99 98 97 96", "1 1 100 100 100", "100 100 99 99 98", "98 99 100 99 100", "1 90 1 91 1", "60 1 75 1 92", "15 40 90 40 90", "1 1 15 20 20", "90 11 11 10 10", "20 21 22 23 24", "1 1 2 98 99", "3 7 7 7 10", "1 3 3 3 1", "1 9 9 9 10", "100 1 1 1 1", "2 2 2 100 100", "1 2 2 2 2", "1 1 2 2 5", "1 2 3 4 1", "11 10 10 10 10", "2 2 2 10 10", "1 1 1 1 4", "98 98 98 98 23", "1 2 3 100 100", "2 2 5 10 10", "2 2 3 3 3", "1 1 1 1 2", "12 12 7 7 7"], "outputs": ["26", "28", "20", "15", "16", "4", "6", "110", "200", "2", "58", "58", "60", "60", "60", "60", "60", "9", "9", "15", "490", "2", "296", "296", "181", "227", "95", "17", "110", "110", "199", "13", "2", "11", "101", "6", "3", "7", "9", "21", "6", "5", "121", "6", "9", "4", "3", "21"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
133
codeforces
7191b886b2342aa9f0bc1752ce01932b
Pasha and String
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string. Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent *m* days performing the following transformations on his string — each day he chose integer *a**i* and reversed a piece of string (a segment) from position *a**i* to position |*s*|<=-<=*a**i*<=+<=1. It is guaranteed that 2·*a**i*<=≤<=|*s*|. You face the following task: determine what Pasha's string will look like after *m* days. The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters. The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) —  the number of days when Pasha changed his string. The third line contains *m* space-separated elements *a**i* (1<=≤<=*a**i*; 2·*a**i*<=≤<=|*s*|) — the position from which Pasha started transforming the string on the *i*-th day. In the first line of the output print what Pasha's string *s* will look like after *m* days. Sample Input abcdef 1 2 vwxyz 2 2 2 abcdef 3 1 2 3 Sample Output aedcbf vwxyz fbdcea
{"inputs": ["abcdef\n1\n2", "vwxyz\n2\n2 2", "abcdef\n3\n1 2 3", "jc\n5\n1 1 1 1 1", "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3", "keicnqmuqinhsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavs\n2\n5 12", "xwcxggxvfqbdklewbxkjzibmufnaywuxsqvwakefxbbkfandvigasbhbatsxyqxicrosatfsfybedklsaztyyiuurfbrzmwumujy\n100\n14 43 30 13 8 19 33 7 8 14 15 35 5 18 44 1 35 1 18 7 50 47 9 49 28 29 39 37 27 17 19 12 5 24 37 42 37 23 35 31 10 26 5 38 40 34 42 47 2 40 43 34 16 25 14 45 35 38 46 48 49 27 49 38 10 49 5 7 3 3 41 25 24 34 37 33 17 50 48 11 40 43 48 10 9 50 18 39 32 13 26 40 37 16 45 50 27 3 7 31"], "outputs": ["aedcbf", "vwxyz", "fbdcea", "cj", "wyjldgqxlc", "keiccyobhhphsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlniqumqnfavs", "xjcxggxvfbbruliyyxkjzikdebnfyftxsorcaxqyxbtkfhbdvigasnababsxfekiwvqsauwsayfumblsaztbweukdfqrzmwumuwy"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
104
codeforces
71bdb35746c7c54bba2602aa6767893a
Arthur and Brackets
Notice that the memory limit is non-standard. Recently Arthur and Sasha have studied correct bracket sequences. Arthur understood this topic perfectly and become so amazed about correct bracket sequences, so he even got himself a favorite correct bracket sequence of length 2*n*. Unlike Arthur, Sasha understood the topic very badly, and broke Arthur's favorite correct bracket sequence just to spite him. All Arthur remembers about his favorite sequence is for each opening parenthesis ('(') the approximate distance to the corresponding closing one (')'). For the *i*-th opening bracket he remembers the segment [*l**i*,<=*r**i*], containing the distance to the corresponding closing bracket. Formally speaking, for the *i*-th opening bracket (in order from left to right) we know that the difference of its position and the position of the corresponding closing bracket belongs to the segment [*l**i*,<=*r**i*]. Help Arthur restore his favorite correct bracket sequence! The first line contains integer *n* (1<=≤<=*n*<=≤<=600), the number of opening brackets in Arthur's favorite correct bracket sequence. Next *n* lines contain numbers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=&lt;<=2*n*), representing the segment where lies the distance from the *i*-th opening bracket and the corresponding closing one. The descriptions of the segments are given in the order in which the opening brackets occur in Arthur's favorite sequence if we list them from left to right. If it is possible to restore the correct bracket sequence by the given data, print any possible choice. If Arthur got something wrong, and there are no sequences corresponding to the given information, print a single line "IMPOSSIBLE" (without the quotes). Sample Input 4 1 1 1 1 1 1 1 1 3 5 5 3 3 1 1 3 5 5 3 3 2 2 3 2 3 1 4 1 4 Sample Output ()()()() ((())) IMPOSSIBLE (())()
{"inputs": ["4\n1 1\n1 1\n1 1\n1 1", "3\n5 5\n3 3\n1 1", "3\n5 5\n3 3\n2 2", "3\n2 3\n1 4\n1 4", "6\n1 5\n2 4\n1 1\n1 1\n1 1\n1 1", "3\n1 4\n2 2\n1 1", "5\n1 3\n2 5\n3 4\n1 2\n1 9", "2\n3 3\n3 3", "1\n1 1", "10\n9 9\n5 5\n1 1\n1 1\n13 13\n11 11\n1 1\n5 5\n1 1\n1 1", "50\n97 97\n61 61\n59 59\n29 29\n13 13\n7 7\n5 5\n3 3\n1 1\n3 3\n1 1\n13 13\n11 11\n9 9\n3 3\n1 1\n1 1\n1 1\n27 27\n25 25\n1 1\n21 21\n19 19\n17 17\n15 15\n5 5\n1 1\n1 1\n7 7\n1 1\n3 3\n1 1\n15 15\n13 13\n1 1\n9 9\n7 7\n5 5\n3 3\n1 1\n15 15\n5 5\n1 1\n1 1\n3 3\n1 1\n1 1\n1 1\n1 1\n1 1", "1\n1 1", "2\n2 2\n1 1", "3\n1 5\n1 5\n1 3", "4\n4 4\n1 1\n2 2\n2 2", "5\n2 9\n3 8\n5 5\n1 9\n1 9", "6\n11 11\n2 2\n1 1\n1 1\n1 6\n2 6", "7\n2 2\n7 7\n6 7\n1 3\n2 2\n3 3\n2 2", "8\n10 10\n9 10\n1 1\n2 2\n1 1\n1 1\n8 9\n1 3", "9\n11 13\n3 4\n3 3\n3 3\n2 2\n2 3\n3 4\n1 4\n3 3", "10\n5 11\n4 4\n2 2\n3 7\n4 7\n2 5\n2 7\n2 6\n1 6\n3 4"], "outputs": ["()()()()", "((()))", "IMPOSSIBLE", "(())()", "()(())()()()", "IMPOSSIBLE", "()((()))()", "IMPOSSIBLE", "()", "IMPOSSIBLE", "((((((((())))(()))((((())()()))))((()(((((()())(()(()))))))))))((()((((()))))))((()())(())()())())()", "()", "IMPOSSIBLE", "()()()", "IMPOSSIBLE", "(((()())))", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
71e025842157ee5552327ed027b3b6d3
Substring
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. Sample Input 5 4 abaca 1 2 1 3 3 4 4 5 6 6 xzyabc 1 2 3 1 2 3 5 4 4 3 6 4 10 14 xzyzyzyzqx 1 2 2 4 3 5 4 5 2 6 6 8 6 5 2 10 3 9 10 9 4 6 1 10 2 8 3 7 Sample Output 3 -1 4
{"inputs": ["5 4\nabaca\n1 2\n1 3\n3 4\n4 5", "6 6\nxzyabc\n1 2\n3 1\n2 3\n5 4\n4 3\n6 4", "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", "1 1\nf\n1 1", "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", "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", "5 8\ntetqw\n2 1\n4 4\n5 5\n5 2\n4 5\n1 5\n1 5\n1 1", "5 8\nreeet\n4 3\n2 5\n4 2\n2 4\n4 2\n5 2\n3 3\n3 4"], "outputs": ["3", "-1", "4", "-1", "2", "3", "-1", "-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
24
codeforces
71f7922bb52860546e0b6c4ad6365d5d
Quasi-palindrome
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String *t* is called a palindrome, if it reads the same from left to right and from right to left. For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes. You are given some integer number *x*. Check if it's a quasi-palindromic number. The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). Sample Input 131 320 2010200 Sample Output YES NO YES
{"inputs": ["131", "320", "2010200", "1", "1000000000", "999999999", "999999998", "102000", "210000000", "213443120", "99", "22002", "1010", "1201", "6460046", "503435", "21002", "101001", "200102", "20010002", "33003", "100101", "1021", "1101", "10101100", "101", "1011", "11010", "10110", "110000", "2011", "10020001", "12505021", "12310", "100501", "11001", "20020002", "202002", "1001", "1020021", "60660", "98809", "11000000", "807008"], "outputs": ["YES", "NO", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
246
codeforces
72154bce8f297ac2e3f2dbe058abef0e
Marvolo Gaunt's Ring
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made. Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative. First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Sample Input 5 1 2 3 1 2 3 4 5 5 1 2 -3 -1 -2 -3 -4 -5 Sample Output 30 12
{"inputs": ["5 1 2 3\n1 2 3 4 5", "5 1 2 -3\n-1 -2 -3 -4 -5", "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777", "4 -96405765 -495906217 625385006\n-509961652 392159235 -577128498 -744548876", "43 959134961 -868367850 142426380\n921743429 63959718 -797293233 122041422 -407576197 700139744 299598010 168207043 362252658 591926075 941946099 812263640 -76679927 -824267725 89529990 -73303355 83596189 -982699817 -235197848 654773327 125211479 -497091570 -2301804 203486596 -126652024 309810546 -581289415 -740125230 64425927 -501018049 304730559 34930193 -762964086 723645139 -826821494 495947907 816331024 9932423 -876541603 -782692568 322360800 841436938 40787162", "1 0 0 0\n0", "1 1000000000 1000000000 1000000000\n1000000000", "1 -1000000000 -1000000000 1000000000\n1000000000", "1 -1000000000 -1000000000 -1000000000\n1000000000", "3 1000000000 1000000000 1000000000\n-1000000000 -1000000000 -1000000000", "1 1 1 1\n-1", "1 -1 -1 -1\n1", "1 1000000000 1000000000 1000000000\n-1000000000", "1 1 2 3\n-1", "3 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000", "2 -1000000000 -1000000000 -1000000000\n1000000000 1000000000", "3 1 1 1\n-1 -1 -1", "1 -1000000000 0 0\n1000000000", "1 -100 -100 -100\n100", "5 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000", "1 999999999 999999999 999999999\n-999999999", "3 -1000000000 -1000000000 1\n1000000000 1000000000 1000000000", "3 -2 3 -2\n1 2 1", "2 1 -1 1\n1 -1", "1 -1000000000 1 -1000000000\n1000000000", "1 1000000000 1000000000 -1000000000\n-1000000000", "1 -1000000000 -1000000000 0\n1000000000"], "outputs": ["30", "12", "376059240645059046", "547306902373544674", "1876641179289775029", "0", "3000000000000000000", "-1000000000000000000", "-3000000000000000000", "-3000000000000000000", "-3", "-3", "-3000000000000000000", "-6", "-3000000000000000000", "-3000000000000000000", "-3", "-1000000000000000000", "-30000", "-3000000000000000000", "-2999999994000000003", "-1999999999000000000", "2", "1", "-1999999999000000000", "-1000000000000000000", "-2000000000000000000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
96
codeforces
72192ff030fb3bf908ee666a246cd70b
Mentors
In BerSoft $n$ programmers work, the programmer $i$ is characterized by a skill $r_i$. A programmer $a$ can be a mentor of a programmer $b$ if and only if the skill of the programmer $a$ is strictly greater than the skill of the programmer $b$ $(r_a &gt; r_b)$ and programmers $a$ and $b$ are not in a quarrel. You are given the skills of each programmers and a list of $k$ pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer $i$, find the number of programmers, for which the programmer $i$ can be a mentor. The first line contains two integers $n$ and $k$ $(2 \le n \le 2 \cdot 10^5$, $0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$ — total number of programmers and number of pairs of programmers which are in a quarrel. The second line contains a sequence of integers $r_1, r_2, \dots, r_n$ $(1 \le r_i \le 10^{9})$, where $r_i$ equals to the skill of the $i$-th programmer. Each of the following $k$ lines contains two distinct integers $x$, $y$ $(1 \le x, y \le n$, $x \ne y)$ — pair of programmers in a quarrel. The pairs are unordered, it means that if $x$ is in a quarrel with $y$ then $y$ is in a quarrel with $x$. Guaranteed, that for each pair $(x, y)$ there are no other pairs $(x, y)$ and $(y, x)$ in the input. Print $n$ integers, the $i$-th number should be equal to the number of programmers, for which the $i$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input. Sample Input 4 2 10 4 10 15 1 2 4 3 10 4 5 4 1 5 4 3 7 1 2 5 4 6 2 1 10 8 3 5 Sample Output 0 0 1 2 5 4 0 5 3 3 9 0 2 5
{"inputs": ["4 2\n10 4 10 15\n1 2\n4 3", "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5", "2 0\n3 1", "2 0\n1 1", "10 35\n322022227 751269818 629795150 369443545 344607287 250044294 476897672 184054549 986884572 917181121\n6 3\n7 3\n1 9\n7 9\n10 7\n3 4\n8 6\n7 4\n6 10\n7 2\n3 5\n6 9\n3 10\n8 7\n6 5\n8 1\n8 5\n1 7\n8 10\n8 2\n1 5\n10 4\n6 7\n4 6\n2 6\n5 4\n9 10\n9 2\n4 8\n5 9\n4 1\n3 2\n2 1\n4 2\n9 8"], "outputs": ["0 0 1 2 ", "5 4 0 5 3 3 9 0 2 5 ", "1 0 ", "0 0 ", "1 1 2 0 0 0 1 0 2 3 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
7228f18da7fed17083cc15458e82d310
Domino piling
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output one number — the maximal number of dominoes, which can be placed. Sample Input 2 4 3 3 Sample Output 4 4
{"inputs": ["2 4", "3 3", "1 5", "1 6", "1 15", "1 16", "2 5", "2 6", "2 7", "2 14", "2 15", "1 4", "2 16", "3 5", "3 6", "3 10", "3 14", "3 15", "3 16", "5 7", "16 16", "15 16", "2 3", "15 15", "14 16", "11 13", "5 16", "8 15", "2 2", "3 4", "4 4", "1 1", "1 2", "1 3", "14 15"], "outputs": ["4", "4", "2", "3", "7", "8", "5", "6", "7", "14", "15", "2", "16", "7", "9", "15", "21", "22", "24", "17", "128", "120", "3", "112", "112", "71", "40", "60", "2", "6", "8", "0", "1", "1", "105"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3,908
codeforces
722da95a33955b90c2bf82a34b3bb610
Pig and Palindromes
Peppa the Pig was walking and walked into the forest. What a strange coincidence! The forest has the shape of a rectangle, consisting of *n* rows and *m* columns. We enumerate the rows of the rectangle from top to bottom with numbers from 1 to *n*, and the columns — from left to right with numbers from 1 to *m*. Let's denote the cell at the intersection of the *r*-th row and the *c*-th column as (*r*,<=*c*). Initially the pig stands in cell (1,<=1), and in the end she wants to be in cell (*n*,<=*m*). Since the pig is in a hurry to get home, she can go from cell (*r*,<=*c*), only to either cell (*r*<=+<=1,<=*c*) or (*r*,<=*c*<=+<=1). She cannot leave the forest. The forest, where the pig is, is very unusual. Some cells of the forest similar to each other, and some look very different. Peppa enjoys taking pictures and at every step she takes a picture of the cell where she is now. The path through the forest is considered to be beautiful if photographs taken on her way, can be viewed in both forward and in reverse order, showing the same sequence of photos. More formally, the line formed by the cells in order of visiting should be a palindrome (you can read a formal definition of a palindrome in the previous problem). Count the number of beautiful paths from cell (1,<=1) to cell (*n*,<=*m*). Since this number can be very large, determine the remainder after dividing it by 109<=+<=7. The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=500) — the height and width of the field. Each of the following *n* lines contains *m* lowercase English letters identifying the types of cells of the forest. Identical cells are represented by identical letters, different cells are represented by different letters. Print a single integer — the number of beautiful paths modulo 109<=+<=7. Sample Input 3 4 aaab baaa abba Sample Output 3
{"inputs": ["3 4\naaab\nbaaa\nabba", "2 2\nab\naa", "3 5\nqqqrw\nwqqtw\newqqq", "1 5\nabbba", "1 5\nabbbb", "1 4\nabca", "5 1\na\na\na\na\na", "5 2\nab\nab\ncc\nba\nba", "5 3\naba\naba\nccc\nbaa\nbaa", "5 5\naaaaa\naaaaa\naaaaa\naaaaa\naaaaa", "5 5\naaaaa\nadaaa\naaaaa\naaaaa\naacaa", "5 5\naaaqa\naaaaa\naaaaa\naaaaa\naaaaa", "5 6\naaaaaa\naafaaa\naaaafa\naafaaa\naaaaaa", "10 10\naaaaaaaaaa\naaaaaaaaaa\naaaaaaaaaa\naaaaaaaaaa\naaaaaaaaaa\naaaaaaaaaa\naaaaaaaaaa\naaaaaaaaaa\naaaaaaaaaa\naaaaaaaaaa", "10 9\naaaaaaaaa\naaaaaaaaa\naaaaaaaaa\naaaaaaaaa\naaaaaaaaa\naaaaaaaaa\naaaaaaaaa\naaaaaaaaa\naaaaaaaaa\naaaaaaaaa", "1 500\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "1 499\nzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], "outputs": ["3", "2", "3", "1", "0", "0", "1", "1", "1", "70", "23", "65", "47", "48620", "24310", "1", "1", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
72392bfc46fcb8be3645ce5e5dc8ca05
Mountain Scenery
Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordinates (1,<=*y*1), (2,<=*y*2), ..., (2*n*<=+<=1,<=*y*2*n*<=+<=1), with the *i*-th segment connecting the point (*i*,<=*y**i*) and the point (*i*<=+<=1,<=*y**i*<=+<=1). For any even *i* (2<=≤<=*i*<=≤<=2*n*) the following condition holds: *y**i*<=-<=1<=&lt;<=*y**i* and *y**i*<=&gt;<=*y**i*<=+<=1. We shall call a vertex of a polyline with an even *x* coordinate a mountain peak. Bolek fancied a little mischief. He chose exactly *k* mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the *y* coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1,<=*r*1), (2,<=*r*2), ..., (2*n*<=+<=1,<=*r*2*n*<=+<=1). Given Bolek's final picture, restore the initial one. The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100). The next line contains 2*n*<=+<=1 space-separated integers *r*1,<=*r*2,<=...,<=*r*2*n*<=+<=1 (0<=≤<=*r**i*<=≤<=100) — the *y* coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks. Print 2*n*<=+<=1 integers *y*1,<=*y*2,<=...,<=*y*2*n*<=+<=1 — the *y* coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. Sample Input 3 2 0 5 3 5 1 5 2 1 1 0 2 0 Sample Output 0 5 3 4 1 4 2 0 1 0
{"inputs": ["3 2\n0 5 3 5 1 5 2", "1 1\n0 2 0", "1 1\n1 100 0", "3 1\n0 1 0 1 0 2 0", "3 1\n0 1 0 2 0 1 0", "3 3\n0 100 35 67 40 60 3", "7 3\n1 2 1 3 1 2 1 2 1 3 1 3 1 2 1", "100 100\n1 3 1 3 1 3 0 2 0 3 1 3 1 3 1 3 0 3 1 3 0 2 0 2 0 3 0 2 0 2 0 3 1 3 1 3 1 3 1 3 0 2 0 3 1 3 0 2 0 2 0 2 0 2 0 2 0 3 0 3 0 3 0 3 0 2 0 3 1 3 1 3 1 3 0 3 0 2 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", "0 2 1 2 0 ", "98 99 1 6 2 ", "8 10 9 10 3 4 1 ", "0 4 3 4 2 4 2 ", "4 5 2 3 2 ", "0 2 1 2 0 1 0 ", "5 6 2 ", "3 4 1 2 1 ", "0 4 3 5 0 4 0 ", "1 3 2 3 1 2 1 ", "0 8 7 99 0 ", "1 3 2 4 1 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
128
codeforces
724a4c13f3ca6aa5877b722fc19e0413
Resource Distribution
One department of some software company has $n$ servers of different specifications. Servers are indexed with consecutive integers from $1$ to $n$. Suppose that the specifications of the $j$-th server may be expressed with a single integer number $c_j$ of artificial resource units. In order for production to work, it is needed to deploy two services $S_1$ and $S_2$ to process incoming requests using the servers of the department. Processing of incoming requests of service $S_i$ takes $x_i$ resource units. The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service $S_i$ is deployed using $k_i$ servers, then the load is divided equally between these servers and each server requires only $x_i / k_i$ (that may be a fractional number) resource units. Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides. Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services. The first line contains three integers $n$, $x_1$, $x_2$ ($2 \leq n \leq 300\,000$, $1 \leq x_1, x_2 \leq 10^9$) — the number of servers that the department may use, and resource units requirements for each of the services. The second line contains $n$ space-separated integers $c_1, c_2, \ldots, c_n$ ($1 \leq c_i \leq 10^9$) — the number of resource units provided by each of the servers. If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes). Otherwise print the word "Yes" (without the quotes). In the second line print two integers $k_1$ and $k_2$ ($1 \leq k_1, k_2 \leq n$) — the number of servers used for each of the services. In the third line print $k_1$ integers, the indices of the servers that will be used for the first service. In the fourth line print $k_2$ integers, the indices of the servers that will be used for the second service. No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them. Sample Input 6 8 16 3 5 2 9 8 7 4 20 32 21 11 11 12 4 11 32 5 5 16 16 5 12 20 7 8 4 11 9 Sample Output Yes 3 2 1 2 6 5 4Yes 1 3 1 2 3 4 No No
{"inputs": ["6 8 16\n3 5 2 9 8 7", "4 20 32\n21 11 11 12", "4 11 32\n5 5 16 16", "5 12 20\n7 8 4 11 9", "2 1 1\n1 1", "2 1 1\n1 1000000", "2 1 1\n1000000000 1000000000", "2 1 2\n1 1", "15 250 200\n71 2 77 69 100 53 54 40 73 32 82 58 24 82 41", "4 12 11\n4 4 6 11"], "outputs": ["Yes\n4 2\n3 1 2 6\n5 4", "Yes\n1 3\n1\n2 3 4", "No", "No", "Yes\n1 1\n1\n2", "Yes\n1 1\n1\n2", "Yes\n1 1\n1\n2", "No", "Yes\n11 3\n13 10 8 15 6 7 12 4 1 9 3\n11 14 5", "Yes\n3 1\n1 2 3\n4"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
8
codeforces
72820233354134500e4063498a6717f0
Weird Rounding
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*. In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103<==<=1000. Write a program that prints the minimum number of digits to be deleted from the given integer number *n*, so that the result is divisible by 10*k*. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. The only line of the input contains two integer numbers *n* and *k* (0<=≤<=*n*<=≤<=2<=000<=000<=000, 1<=≤<=*k*<=≤<=9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Print *w* — the required minimal number of digits to erase. After removing the appropriate *w* digits from the number *n*, the result should have a value that is divisible by 10*k*. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Sample Input 30020 3 100 9 10203049 2 Sample Output 1 2 3
{"inputs": ["30020 3", "100 9", "10203049 2", "0 1", "0 9", "100 2", "102030404 2", "1000999999 3", "12000000 4", "1090090090 5", "10 1", "10 2", "10 9", "100 1", "100 3", "101010110 3", "101010110 1", "101010110 2", "101010110 4", "101010110 5", "101010110 9", "1234567890 1", "1234567890 2", "1234567890 9", "2000000000 1", "2000000000 2", "2000000000 3", "2000000000 9", "1010101010 1", "1010101010 2", "1010101010 3", "1010101010 4", "1010101010 5", "1010101010 6", "1010101010 7", "1010101010 8", "1010101010 9", "10001000 1", "10001000 2", "10001000 3", "10001000 4", "10001000 5", "10001000 6", "10001000 7", "10001000 8", "10001000 9", "1000000001 1", "1000000001 2", "1000000001 3", "1000000001 6", "1000000001 7", "1000000001 8", "1000000001 9", "1000 1", "100001100 3", "7057 6", "30000000 5", "470 1", "500500000 4", "2103 8", "600000000 2", "708404442 1", "5000140 6", "1100047 3", "309500 5", "70053160 4", "44000 1", "400370000 3", "5800 6", "20700050 1", "650 1", "320005070 6", "370000 4", "1011 2", "1000111 5", "1001111 5", "99990 3", "10100200 6", "200 3", "103055 3", "1030555 3", "100111 4", "101 2", "1001 3", "100000 6", "1100000 6", "123450 2", "1003 3", "1111100 4", "532415007 8", "801 2", "1230 2", "9900 3", "14540444 2", "11111100 4", "11001 3", "1011110 3", "15450112 2", "2220 3", "90099 3", "10005 4", "1010 3", "444444400 3", "10020 4", "10303 3", "123000 4", "12300 3", "101 1", "500001 8", "121002 3", "10011 3", "505050 4", "1421011 2", "1202022 3", "1000023 7", "110 2", "111000 4", "10340 3", "101 9", "2001 3", "122320 2", "22200 3", "11110 2", "11010 3", "1000002333 6", "101010 4", "210 9", "500555 3", "1110111 3", "1100000000 9", "11000 4", "100 4", "234560 3", "10230 3", "10030234 5", "1200 3", "123400 3", "1034543 4", "10100 4", "10 5", "4501022 3", "12340 2", "30020 4", "1111100 6", "10101 5", "32132100 3", "1000023 6", "12300 4", "78400 3", "10203049 5", "404044 3", "1024 2", "505 2", "20 2", "1111100 3", "1000 9", "3333300 3", "1100 3", "963000 4", "100457 5", "10049 3"], "outputs": ["1", "2", "3", "0", "0", "0", "2", "6", "0", "2", "0", "1", "1", "0", "2", "3", "0", "2", "4", "8", "8", "0", "9", "9", "0", "0", "0", "0", "0", "1", "2", "3", "4", "9", "9", "9", "9", "0", "0", "0", "1", "1", "1", "7", "7", "7", "1", "1", "1", "1", "1", "1", "9", "0", "2", "3", "0", "0", "0", "3", "0", "4", "6", "2", "5", "7", "0", "0", "3", "0", "0", "8", "0", "3", "6", "6", "4", "7", "2", "5", "6", "5", "2", "3", "5", "6", "5", "3", "6", "8", "2", "3", "3", "7", "7", "4", "6", "7", "3", "4", "4", "3", "8", "4", "4", "5", "4", "1", "5", "5", "4", "5", "6", "6", "6", "2", "5", "4", "2", "3", "5", "4", "4", "4", "9", "5", "2", "5", "6", "9", "4", "2", "5", "4", "7", "3", "5", "6", "4", "1", "6", "4", "4", "6", "4", "7", "6", "4", "4", "7", "5", "3", "2", "1", "6", "3", "6", "3", "5", "5", "4"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
179
codeforces
72b27ecee4e2a8f3268f429ae77dad23
Ant on the Tree
Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are *n* vertexes in the tree, and they are connected by *n*<=-<=1 edges so that there is a path between any pair of vertexes. A leaf is a distinct from root vertex, which is connected with exactly one other vertex. The ant wants to visit every vertex in the tree and return to the root, passing every edge twice. In addition, he wants to visit the leaves in a specific order. You are to find some possible route of the ant. The first line contains integer *n* (3<=≤<=*n*<=≤<=300) — amount of vertexes in the tree. Next *n*<=-<=1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The last line contains *k* integers, where *k* is amount of leaves in the tree. These numbers describe the order in which the leaves should be visited. It is guaranteed that each leaf appears in this order exactly once. If the required route doesn't exist, output -1. Otherwise, output 2*n*<=-<=1 numbers, describing the route. Every time the ant comes to a vertex, output it's index. Sample Input 3 1 2 2 3 3 6 1 2 1 3 2 4 4 5 4 6 5 6 3 6 1 2 1 3 2 4 4 5 4 6 5 3 6 Sample Output 1 2 3 2 1 1 2 4 5 4 6 4 2 1 3 1 -1
{"inputs": ["3\n1 2\n2 3\n3", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3", "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6", "10\n8 10\n2 1\n7 5\n5 4\n6 10\n2 3\n3 10\n2 9\n7 2\n6 9 4 8", "8\n4 3\n6 7\n8 6\n6 1\n4 6\n6 5\n6 2\n3 2 7 8 5", "8\n4 3\n1 4\n8 5\n7 6\n3 5\n7 3\n4 2\n2 6 8", "20\n4 13\n17 7\n19 10\n18 1\n5 15\n2 6\n11 7\n3 6\n5 1\n20 16\n12 5\n10 17\n14 18\n8 13\n13 15\n19 1\n9 19\n6 13\n17 20\n14 12 4 2 3 9 8 11 16", "37\n27 3\n27 35\n6 8\n12 21\n4 7\n32 27\n27 17\n24 14\n1 10\n3 23\n20 8\n12 4\n16 33\n2 34\n15 36\n5 31\n31 14\n5 9\n8 28\n29 12\n33 35\n24 10\n18 25\n33 18\n2 37\n17 5\n36 29\n12 26\n20 26\n22 11\n23 8\n15 30\n34 6\n13 7\n22 4\n23 19\n37 11 9 32 28 16 21 30 25 19 13", "51\n28 3\n42 40\n40 51\n48 20\n13 28\n18 40\n44 40\n22 5\n22 27\n45 34\n40 9\n34 46\n40 34\n22 1\n22 11\n40 7\n28 40\n40 22\n14 40\n34 30\n40 20\n47 40\n12 34\n28 23\n40 24\n40 43\n41 40\n28 15\n49 32\n40 8\n32 10\n40 50\n40 36\n40 21\n16 33\n40 38\n34 2\n28 16\n34 4\n17 34\n19 40\n32 35\n40 29\n6 40\n40 39\n22 26\n37 40\n32 40\n31 20\n34 25\n35 15 7 9 12 31 36 50 19 17 29 46 5 42 8 13 10 24 44 25 41 2 38 23 43 30 18 3 26 47 37 11 39 33 49 14 4 45 6 51 48 21 27", "3\n1 2\n1 3\n2 3", "3\n1 2\n1 3\n3 2", "4\n1 2\n1 3\n1 4\n4 3 2", "5\n1 2\n4 3\n1 4\n4 5\n5 2 3"], "outputs": ["1 2 3 2 1 ", "1 2 4 5 4 6 4 2 1 3 1 ", "-1", "-1", "1 6 4 3 4 6 2 6 7 6 8 6 5 6 1 ", "1 4 2 4 3 7 6 7 3 5 8 5 3 4 1 ", "-1", "-1", "-1", "1 2 1 3 1 ", "1 3 1 2 1 ", "1 4 1 3 1 2 1 ", "-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
72b42c09aa731632c82d0fda042cc4d8
Lucky Subsequence
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has sequence *a* consisting of *n* integers. The subsequence of the sequence *a* is such subsequence that can be obtained from *a* by removing zero or more of its elements. Two sequences are considered different if index sets of numbers included in them are different. That is, the values ​of the elements ​do not matter in the comparison of subsequences. In particular, any sequence of length *n* has exactly 2*n* different subsequences (including an empty subsequence). A subsequence is considered lucky if it has a length exactly *k* and does not contain two identical lucky numbers (unlucky numbers can be repeated any number of times). Help Petya find the number of different lucky subsequences of the sequence *a*. As Petya's parents don't let him play with large numbers, you should print the result modulo prime number 1000000007 (109<=+<=7). The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the sequence *a*. On the single line print the single number — the answer to the problem modulo prime number 1000000007 (109<=+<=7). Sample Input 3 2 10 10 10 4 2 4 4 7 7 Sample Output 3 4
{"inputs": ["3 2\n10 10 10", "4 2\n4 4 7 7", "7 4\n1 2 3 4 5 6 7", "7 4\n7 7 7 7 7 7 7", "10 1\n1 2 3 4 5 6 7 8 9 10", "10 7\n1 2 3 4 5 6 7 8 9 10", "20 7\n1 4 5 8 47 777777777 1 5 4 8 5 9 5 4 7 4 5 7 7 44474", "5 2\n47 47 47 47 47", "13 5\n44 44 44 44 44 44 44 44 77 55 66 99 55", "3 2\n1 47 47", "2 2\n47 47", "2 2\n44 44"], "outputs": ["3", "4", "35", "0", "10", "120", "29172", "0", "41", "2", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
72bbbcff66eb716aa7bc1702a512ce3d
Dima and Guards
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards... There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift. In order to pass through a guardpost, one needs to bribe both guards. The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly *n* rubles on it. Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that! The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers *a*,<=*b*,<=*c*,<=*d* (1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly. In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line. The guardposts are numbered from 1 to 4 according to the order given in the input. If there are multiple solutions, you can print any of them. Sample Input 10 5 6 5 6 6 6 7 7 5 8 6 6 9 9 9 9 10 6 6 6 6 7 7 7 7 4 4 4 4 8 8 8 8 5 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Sample Output 1 5 5 3 4 6 -1
{"inputs": ["10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9", "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8", "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3", "100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000", "5\n3 2 3 3\n3 2 3 3\n4 4 4 4\n4 4 1 1", "100\n1 1 2 2\n100 100 2 2\n99 99 2 2\n2 2 99 99", "1000\n500 500 550 550\n450 450 500 500\n999 1 1 999\n1 999 1 999", "50\n30 30 30 30\n20 20 40 40\n10 10 50 50\n1 1 50 55", "10000\n1000 7000 8000 6000\n8000 8000 6000 6000\n5000 6000 6000 6000\n10000 10000 2 3", "40000\n25000 25000 30000 30000\n1 1 1 1\n30000 20000 30000 30000\n40000 40000 40000 50000", "4\n2 1 4 4\n4 4 1 1\n3 1 2 2\n4 4 4 4", "50\n5 5 5 5\n5 5 5 5\n5 5 5 5\n5 5 5 5", "10\n7 2 3 20\n20 20 20 20\n20 20 20 20\n7 2 3 20", "10\n8 2 7 8\n20 20 20 20\n20 20 20 20\n8 2 7 8", "100000\n50000 50000 50000 50000\n50000 50000 50000 50000\n50000 50000 50000 50000\n50000 50000 50000 50000", "100000\n25000 75000 80000 80000\n99999 99999 2 2\n99999 2 99999 99999\n2 99999 99999 99999", "1231\n123 132 85 78\n123 5743 139 27\n4598 347 12438 12\n34589 2349 123 123", "6\n2 6 2 9\n4 8 5 1\n5 6 4 3\n1 2 5 1", "8\n5 5 3 3\n1 1 8 8\n2 8 8 7\n10 7 2 2", "100000\n25000 50000 50001 75001\n25000 50000 50001 75001\n25000 50000 50001 75001\n25000 50000 50001 75001", "100000\n25000 50000 75001 50001\n25000 50000 75001 50001\n25000 50000 75001 50001\n25000 50000 75001 50001", "5\n3 7 6 2\n100 100 100 100\n100 100 100 100\n100 100 100 100", "10\n1 100 100 1\n1 100 100 1\n1 100 100 1\n1 100 100 1", "10\n7 5 5 7\n10 10 10 10\n10 10 10 10\n10 10 10 10", "10\n9 9 9 9\n9 9 9 9\n9 9 9 9\n1 1 1 1", "10\n8 6 5 3\n8 6 5 3\n8 6 5 3\n8 6 5 3", "10\n9 9 9 9\n9 9 9 9\n9 9 9 9\n9 4 9 6", "10\n6 6 4 4\n6 6 4 4\n6 6 4 4\n6 6 4 4", "100000\n99000 100000 999 100000\n100000 100000 100000 100000\n100000 100000 100000 100000\n100000 100000 100000 100000"], "outputs": ["1 5 5", "3 4 6", "-1", "-1", "1 2 3", "1 1 99", "3 1 999", "-1", "1 1000 9000", "2 1 39999", "3 1 3", "1 5 45", "1 2 8", "1 2 8", "1 50000 50000", "-1", "2 123 1108", "4 1 5", "1 5 3", "1 25000 75000", "1 25000 75000", "1 3 2", "1 1 9", "1 5 5", "4 1 9", "1 6 4", "4 4 6", "1 6 4", "1 99000 1000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
57
codeforces
72d25ec743d032211913d9611cd07a45
Square Earth?
Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensional circle. No, wait, it's even worse — as a square of side *n*. Thus, the task has been reduced to finding the shortest path between two dots on a square (the path should go through the square sides). To simplify the task let us consider the vertices of the square to lie at points whose coordinates are: (0,<=0), (*n*,<=0), (0,<=*n*) and (*n*,<=*n*). The single line contains 5 space-separated integers: *n*,<=*x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*n*<=≤<=1000,<=0<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*) which correspondingly represent a side of the square, the coordinates of the first point and the coordinates of the second point. It is guaranteed that the points lie on the sides of the square. You must print on a single line the shortest distance between the points. Sample Input 2 0 0 1 0 2 0 1 2 1 100 0 0 100 100 Sample Output 1 4 200
{"inputs": ["2 0 0 1 0", "2 0 1 2 1", "100 0 0 100 100", "4 0 3 1 4", "10 8 10 10 0", "26 21 0 26 14", "15 0 1 11 0", "26 26 7 26 12", "6 6 0 2 6", "5 1 5 2 5", "99 12 0 35 99", "44 44 31 28 0", "42 42 36 5 0", "87 87 66 0 5", "85 0 32 0 31", "30 20 30 3 0", "5 4 0 5 1", "40 24 40 4 0", "11 0 2 11 4", "82 0 11 35 0", "32 19 32 0 1", "54 12 0 0 44", "75 42 75 28 0", "48 31 48 0 4", "69 4 69 69 59", "561 0 295 233 0", "341 158 0 0 190", "887 887 461 39 887", "700 0 288 700 368", "512 70 512 512 99", "826 188 826 592 0", "953 0 773 0 903", "80 80 4 0 54", "208 73 0 208 123", "983 0 894 199 0", "686 615 686 470 686", "869 869 833 0 578", "169 0 94 0 132", "68 42 68 68 28", "967 967 607 279 0", "489 489 139 455 489", "964 205 964 604 964", "86 0 34 86 21", "209 166 209 131 0", "684 684 113 314 684", "16 0 6 0 8", "862 154 862 297 862", "418 222 0 254 418", "571 504 571 143 571", "371 371 210 81 371", "1000 0 0 1000 1000", "1000 564 0 436 1000", "1000 0 573 12 1000", "1000 984 0 1000 999", "100 10 0 10 0"], "outputs": ["1", "4", "200", "2", "12", "19", "12", "5", "10", "1", "146", "47", "73", "158", "1", "53", "2", "68", "17", "46", "50", "56", "145", "75", "75", "528", "348", "1274", "1356", "855", "1606", "130", "138", "258", "1093", "145", "1196", "38", "66", "1295", "384", "399", "141", "330", "941", "2", "143", "778", "361", "451", "2000", "2000", "439", "1015", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
7307aab67e8176e638767b6378a44995
Chocolate Bar
You have a rectangular chocolate bar consisting of *n*<=×<=*m* single squares. You want to eat exactly *k* squares, so you may need to break the chocolate bar. In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically. The cost of breaking is equal to square of the break length. For example, if you have a chocolate bar consisting of 2<=×<=3 unit squares then you can break it horizontally and get two 1<=×<=3 pieces (the cost of such breaking is 32<==<=9), or you can break it vertically in two ways and get two pieces: 2<=×<=1 and 2<=×<=2 (the cost of such breaking is 22<==<=4). For several given values *n*, *m* and *k* find the minimum total cost of breaking. You can eat exactly *k* squares of chocolate if after all operations of breaking there is a set of rectangular pieces of chocolate with the total size equal to *k* squares. The remaining *n*·*m*<=-<=*k* squares are not necessarily form a single rectangular piece. The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=40910) — the number of values *n*, *m* and *k* to process. Each of the next *t* lines contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=30,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=50)) — the dimensions of the chocolate bar and the number of squares you want to eat respectively. For each *n*, *m* and *k* print the minimum total cost needed to break the chocolate bar, in order to make it possible to eat exactly *k* squares. Sample Input 4 2 2 1 2 2 3 2 2 2 2 2 4 Sample Output 5 5 4 0
{"inputs": ["4\n2 2 1\n2 2 3\n2 2 2\n2 2 4"], "outputs": ["5\n5\n4\n0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
733c09dbb540865f8619f90de41154e5
The Wall
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink. After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question. The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. Sample Input 2 3 6 18 Sample Output 3
{"inputs": ["2 3 6 18", "4 6 20 201", "15 27 100 10000", "105 60 3456 78910", "1 1 1000 100000", "3 2 5 5", "555 777 1 1000000", "1000 1000 1 32323", "45 125 93451125 100000000", "101 171 1 1000000000", "165 255 69696 1000000000", "555 777 666013 1000000000", "23 46 123321 900000000", "321 123 15 1000000", "819 1000 9532 152901000", "819 1000 10000 1000000", "1 1 1 1", "1 2 2 1000003", "1 1 1 1000000000", "10 15 69 195610342", "2 1 1 1000000000", "1000 1000 1 20", "1 1 1 2000000000", "1 2 1 2000000000", "2 1 1 2000000000", "2 3 1 1000000000", "2 3 1 2000000000", "3 7 1 1000000000", "1 1 1000000000 2000000000", "2 2 1 2000000000", "1 1 2 2000000000", "3 2 1 2000000000", "1 1 2000000000 2000000000", "2 3 7 7", "3 3 3 7"], "outputs": ["3", "15", "74", "179", "99001", "0", "257", "32", "5821", "57900", "356482", "257229", "19562537", "75", "186", "1", "1", "500001", "1000000000", "6520342", "500000000", "0", "2000000000", "1000000000", "1000000000", "166666666", "333333333", "47619047", "1000000001", "1000000000", "1999999999", "333333333", "1", "0", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
148
codeforces
7342c11337a3f2aed7498a23929c2593
GCD Table
Consider a table *G* of size *n*<=×<=*m* such that *G*(*i*,<=*j*)<==<=*GCD*(*i*,<=*j*) for all 1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*j*<=≤<=*m*. *GCD*(*a*,<=*b*) is the greatest common divisor of numbers *a* and *b*. You have a sequence of positive integer numbers *a*1,<=*a*2,<=...,<=*a**k*. We say that this sequence occurs in table *G* if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1<=≤<=*i*<=≤<=*n* and 1<=≤<=*j*<=≤<=*m*<=-<=*k*<=+<=1 should exist that *G*(*i*,<=*j*<=+<=*l*<=-<=1)<==<=*a**l* for all 1<=≤<=*l*<=≤<=*k*. Determine if the sequence *a* occurs in table *G*. The first line contains three space-separated integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1012; 1<=≤<=*k*<=≤<=10000). The second line contains *k* space-separated integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=1012). Print a single word "YES", if the given sequence occurs in table *G*, otherwise print "NO". Sample Input 100 100 5 5 2 1 2 1 100 8 5 5 2 1 2 1 100 100 7 1 2 3 4 5 6 7 Sample Output YES NO NO
{"inputs": ["100 100 5\n5 2 1 2 1", "100 8 5\n5 2 1 2 1", "100 100 7\n1 2 3 4 5 6 7", "5 5 5\n1 1 1 1 1", "11 10 1\n11", "108 942 35\n1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 31 1 3 1 1 3 1 1 3 1 1", "1000000000000 1000000000000 116\n1587924000 7 2 3 4 5 6 1 56 9 10 1 12 13 2 105 16 1 18 1 620 3 14 1 24 25 26 27 4 203 30 1 32 3 2 5 252 1 2 39 40 1 6 7 4 45 2 1 48 1 350 93 52 1 54 5 8 21 58 1 60 1 2 9 224 65 6 1 4 3 10 7 72 1 2 75 4 1 546 1 80 81 62 1 12 35 2 87 8 1 90 13 28 3 2 5 96 1 2 63 100 1 6 1 104 15 14 1 108 1 10 3 16 217 6 5", "1000000000000 1000000000000 10\n99991 99992 99993 99994 99995 99996 99997 99998 99999 31000000000", "100 100 10\n3 5 1 1 1 1 1 1 1 9", "54275126675 128566125 50\n1 1 3 1 1 3 7 1 9 1 11 3 13 7 3 1 1 27 1 1 21 11 1 3 1 13 9 7 1 3 1 1 33 1 7 9 37 1 39 1 1 21 1 11 27 1 1 3 7 1", "100000 49999 2\n50000 1", "1000000000000 1000000000000 59\n1 1 3 1 5 3 1 1 3 5 1 3 1 1 15 1 1 3 1 5 3 1 1 3 5 1 3 1 1 15 1 1 3 1 5 3 1 1 3 5 1 3 1 1 15 1 1 3 1 5 3 1 1 3 5 1 3 1 1", "1000000000000 1000000000000 6\n8 21 2 1 12 1", "1000000000000 1000000000000 6\n1 6 5 2 3 2", "1000000000000 1000000000000 100\n2 9 2 1 6 1 2 3 2 1 18 1 2 3 2 1 6 1 2 9 2 1 6 1 2 3 2 1 18 1 74 3 2 1 6 1 2 9 2 1 6 1 2 3 2 1 18 1 2 3 2 1 6 1 2 9 2 1 6 1 2 3 2 1 18 1 2 111 2 1 6 1 2 9 2 1 6 1 2 3 2 1 18 1 2 3 2 1 6 1 2 9 2 1 6 1 2 3 2 1", "1000000000000 1000000000000 100\n2 9 2 1 6 1 2 3 2 1 18 1 2 3 2 1 6 1 2 9 2 1 6 1 2 3 2 1 18 1 74 3 2 1 6 1 2 9 2 1 6 1 2 3 2 1 18 1 2 3 2 1 6 1 2 9 2 1 12 1 2 3 2 1 18 1 2 111 2 1 6 1 2 9 2 1 6 1 2 3 2 1 18 1 2 3 2 1 6 1 2 9 2 1 6 1 2 3 2 1", "1000000000000 1000000000000 100\n2 9 2 1 6 1 2 3 2 1 18 1 2 3 2 1 6 1 2 9 2 1 6 1 2 3 2 1 18 1 74 3 2 1 6 1 2 9 2 1 6 1 2 3 2 1 18 1 2 3 2 1 6 1 2 9 2 1 6 1 2 3 2 1 18 1 2 111 2 1 6 1 2 9 2 1 6 1 2 3 2 1 9 1 2 3 2 1 6 1 2 9 2 1 6 1 2 3 2 1", "1000000000000 1000000000000 40\n2 1 8 1 10 1 4 1 2 25 16 1 2 1 20 1 2 1 8 5 2 1 4 1 10 1 128 1 2 5 4 1 2 1 1000 1 2 1 4 5", "1000000000000 1000000000000 40\n2 1 8 1 10 1 4 1 2 5 16 1 2 1 20 1 2 1 8 5 2 1 4 1 10 1 64 1 2 5 4 1 2 1 500 1 2 1 4 5", "1000000000000 1000000000000 2\n1 1000000000000", "1000000000000 1000000000000 4\n1 2 1 100000000000", "991234567890 927215128595 5\n6 11 8 3 2000000014", "991234567890 182000001269 5\n6 11 8 3 2000000014", "999999999999 999999999999 2\n20145182300 20145182301"], "outputs": ["YES", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "YES", "NO", "NO"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
735a04aff31665beb4885fab2271e2bf
Playing with Paper
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson? The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=&lt;<=*a*<=≤<=1012) — the sizes of the original sheet of paper. Print a single integer — the number of ships that Vasya will make. Sample Input 2 1 10 7 1000000000000 1 Sample Output 2 6 1000000000000
{"inputs": ["2 1", "10 7", "1000000000000 1", "3 1", "4 1", "3 2", "4 2", "1000 700", "959986566087 524054155168", "4 3", "7 6", "1000 999", "1000 998", "1000 997", "42 1", "1000 1", "8 5", "13 8", "987 610", "442 42", "754 466", "1000000000000 999999999999", "1000000000000 999999999998", "941 14", "998 2", "1000 42", "1000 17", "5 1", "5 2", "5 3", "5 4", "293 210", "787878787878 424242424242", "956722026041 591286729879", "956722026041 365435296162", "628625247282 464807889701", "695928431619 424778620208", "1000000000000 42", "987654345678 23", "10000000001 2", "1000000000000 2", "1000000000000 3", "100000000000 3", "100000000000 23", "999999999997 7", "8589934592 4294967296"], "outputs": ["2", "6", "1000000000000", "3", "4", "3", "2", "6", "90", "4", "7", "1000", "500", "336", "42", "1000", "5", "6", "15", "22", "13", "1000000000000", "500000000000", "74", "499", "32", "66", "5", "4", "4", "5", "17", "8", "58", "58", "102", "167", "23809523821", "42941493300", "5000000002", "500000000000", "333333333336", "33333333336", "4347826109", "142857142861", "2"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
312
codeforces
736d64400df84fb0b7e53e0ca922c7a8
Polycarpus' Dice
Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what number, she knows only the sum *A* and the values *d*1,<=*d*2,<=...,<=*d**n*. However, she finds it enough to make a series of statements of the following type: dice *i* couldn't show number *r*. For example, if Polycarp had two six-faced dice and the total sum is *A*<==<=11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible). For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is *A*. The first line contains two integers *n*,<=*A* (1<=≤<=*n*<=≤<=2·105,<=*n*<=≤<=*A*<=≤<=*s*) — the number of dice and the sum of shown values where *s*<==<=*d*1<=+<=*d*2<=+<=...<=+<=*d**n*. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=106), where *d**i* is the maximum value that the *i*-th dice can show. Print *n* integers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* is the number of values for which it is guaranteed that the *i*-th dice couldn't show them. Sample Input 2 8 4 4 1 3 5 2 3 2 3 Sample Output 3 3 4 0 1
{"inputs": ["2 8\n4 4", "1 3\n5", "2 3\n2 3", "1 1\n3", "1 2\n3", "2 2\n2 3", "2 4\n2 3", "3 3\n5 1 5", "3 4\n5 1 5", "3 5\n5 1 5", "3 6\n5 1 5", "3 7\n5 1 5", "3 8\n5 1 5", "3 5\n1 2 100", "10 20\n1 1 1 1 5 100 1 1 1 1", "5 50\n1 1 1 1 1000000", "5 50\n2 2 2 2 1000000", "5 50\n10 10 10 10 1000000", "10 19\n1 5 6 1 6 4 1 2 9 5", "10 40\n1 5 6 1 6 4 1 2 9 5", "10 16\n5 7 7 5 9 3 8 5 7 2", "10 58\n5 7 7 5 9 3 8 5 7 2", "10 13\n9 9 6 9 10 4 5 10 8 9", "10 79\n9 9 6 9 10 4 5 10 8 9", "10 16\n4 1 8 3 3 3 4 3 6 6", "10 41\n4 1 8 3 3 3 4 3 6 6", "10 18\n8 1 9 8 4 1 1 8 6 2", "10 48\n8 1 9 8 4 1 1 8 6 2", "1 5\n5"], "outputs": ["3 3 ", "4 ", "0 1 ", "2 ", "2 ", "1 2 ", "0 1 ", "4 0 4 ", "3 0 3 ", "2 0 2 ", "1 0 1 ", "0 0 0 ", "1 0 1 ", "0 0 98 ", "0 0 0 0 0 95 0 0 0 0 ", "0 0 0 0 999999 ", "0 0 0 0 999995 ", "0 0 0 0 999963 ", "0 0 0 0 0 0 0 0 0 0 ", "0 4 5 0 5 3 0 1 8 4 ", "0 0 0 0 2 0 1 0 0 0 ", "4 6 6 4 8 2 7 4 6 1 ", "5 5 2 5 6 0 1 6 4 5 ", "8 8 5 8 9 3 4 9 7 8 ", "0 0 1 0 0 0 0 0 0 0 ", "3 0 7 2 2 2 3 2 5 5 ", "0 0 0 0 0 0 0 0 0 0 ", "7 0 8 7 3 0 0 7 5 1 ", "4 "]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
70
codeforces
73844bd17524419c97f556d2c107bd32
Clothes
A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells *n* clothing items, and exactly *m* pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend. The first input file line contains integers *n* and *m* — the total number of clothing items in the shop and the total number of matching pairs of clothing items (). Next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the prices of the clothing items in rubles. Next *m* lines each contain a pair of space-separated integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*). Each such pair of numbers means that the *u**i*-th and the *v**i*-th clothing items match each other. It is guaranteed that in each pair *u**i* and *v**i* are distinct and all the unordered pairs (*u**i*,<=*v**i*) are different. Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes). Sample Input 3 3 1 2 3 1 2 2 3 3 1 3 2 2 3 4 2 3 2 1 4 4 1 1 1 1 1 2 2 3 3 4 4 1 Sample Output 6 -1 -1
{"inputs": ["3 3\n1 2 3\n1 2\n2 3\n3 1", "3 2\n2 3 4\n2 3\n2 1", "4 4\n1 1 1 1\n1 2\n2 3\n3 4\n4 1", "4 3\n10 10 5 1\n2 1\n3 1\n3 4", "4 0\n9 8 2 10", "4 3\n5 5 9 6\n3 2\n1 4\n3 4", "4 3\n5 1 10 1\n2 1\n3 2\n1 4", "4 3\n1 2 8 6\n1 3\n1 4\n3 4", "4 4\n9 3 3 1\n1 2\n3 1\n3 2\n4 3", "4 3\n6 8 10 1\n2 3\n1 4\n3 4", "4 5\n4 10 3 9\n1 2\n3 1\n3 2\n2 4\n4 3", "4 2\n2 9 8 4\n1 3\n4 2", "4 3\n5 3 4 4\n2 1\n4 1\n3 4", "6 6\n39 15 73 82 37 40\n2 1\n5 1\n1 6\n2 6\n6 3\n4 6", "6 7\n85 2 34 6 83 61\n1 2\n2 3\n4 2\n4 3\n1 5\n4 5\n6 3", "6 8\n64 44 5 31 14 16\n1 2\n1 3\n1 4\n2 5\n3 5\n6 1\n6 3\n6 4", "6 8\n36 19 99 8 52 77\n2 1\n3 1\n4 2\n4 3\n1 5\n5 4\n1 6\n6 2", "6 5\n59 69 52 38 93 53\n4 2\n1 5\n6 1\n4 6\n5 6", "6 11\n95 81 74 94 60 69\n3 2\n1 4\n4 2\n3 4\n1 5\n5 2\n5 3\n1 6\n2 6\n3 6\n4 6", "6 8\n69 36 41 23 91 35\n1 2\n3 1\n3 2\n1 4\n3 4\n3 5\n5 4\n4 6", "6 6\n33 76 98 59 4 69\n1 2\n3 2\n5 1\n2 5\n4 5\n6 5", "6 6\n92 56 15 83 30 28\n3 1\n4 1\n2 5\n5 4\n2 6\n6 3", "6 10\n17 5 55 24 55 74\n1 3\n2 3\n3 4\n5 1\n5 2\n5 3\n4 5\n6 2\n6 3\n6 5", "3 3\n1000000 1000000 1000000\n2 1\n1 3\n3 2", "3 0\n1 1 1", "3 3\n100000 100000 100001\n1 2\n2 3\n3 1", "3 3\n1 1 999999\n1 2\n2 3\n3 1", "3 3\n999999 1 1\n1 2\n2 3\n3 1", "3 3\n1000000 1000000 1000000\n1 2\n2 3\n1 3"], "outputs": ["6", "-1", "-1", "-1", "-1", "-1", "-1", "15", "15", "-1", "17", "-1", "-1", "94", "42", "85", "132", "205", "215", "133", "113", "-1", "115", "3000000", "-1", "300001", "1000001", "1000001", "3000000"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
73ac9650486f781ac4e25a416255efdb
Cutting Carrot
Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area. Formally, the carrot can be viewed as an isosceles triangle with base length equal to 1 and height equal to *h*. Igor wants to make *n*<=-<=1 cuts parallel to the base to cut the carrot into *n* pieces. He wants to make sure that all *n* pieces have the same area. Can you help Igor determine where to cut the carrot so that each piece have equal area? The first and only line of input contains two space-separated integers, *n* and *h* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=105). The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=&lt;<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=-<=1<=&lt;<=*h* must hold. Your output will be considered correct if absolute or relative error of every number in your output doesn't exceed 10<=-<=6. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . Sample Input 3 2 2 100000 Sample Output 1.154700538379 1.632993161855 70710.678118654752
{"inputs": ["3 2", "2 100000", "1000 100000", "2 1", "1000 1", "20 17", "999 1", "998 99999", "574 29184", "2 5713", "937 23565", "693 39706", "449 88550", "642 37394", "961 53535", "4 31901", "4 23850", "4 72694", "4 21538", "4 70383", "5 1", "5 1", "5 1", "5 1", "5 1", "20 1", "775 1", "531 1", "724 1", "917 1", "458 100"], "outputs": ["1.154700538379 1.632993161855", "70710.678118654752", "3162.277660168379 4472.135954999579 5477.225575051661 6324.555320336759 7071.067811865475 7745.966692414834 8366.600265340755 8944.271909999159 9486.832980505138 10000.000000000000 10488.088481701515 10954.451150103322 11401.754250991380 11832.159566199232 12247.448713915890 12649.110640673517 13038.404810405297 13416.407864998738 13784.048752090222 14142.135623730950 14491.376746189439 14832.396974191326 15165.750888103101 15491.933384829668 15811.388300841897 16124.515496597099 16431.676725154983 16733.2...", "0.707106781187", "0.031622776602 0.044721359550 0.054772255751 0.063245553203 0.070710678119 0.077459666924 0.083666002653 0.089442719100 0.094868329805 0.100000000000 0.104880884817 0.109544511501 0.114017542510 0.118321595662 0.122474487139 0.126491106407 0.130384048104 0.134164078650 0.137840487521 0.141421356237 0.144913767462 0.148323969742 0.151657508881 0.154919333848 0.158113883008 0.161245154966 0.164316767252 0.167332005307 0.170293863659 0.173205080757 0.176068168617 0.178885438200 0.181659021246 0.184390889146 0...", "3.801315561750 5.375872022286 6.584071688553 7.602631123499 8.500000000000 9.311283477588 10.057335631269 10.751744044572 11.403946685249 12.020815280171 12.607537428063 13.168143377105 13.705838172108 14.223220451079 14.722431864335 15.205262246999 15.673225577398 16.127616066859 16.569550386175", "0.031638599858 0.044743737014 0.054799662435 0.063277199717 0.070746059996 0.077498425829 0.083707867056 0.089487474029 0.094915799575 0.100050037531 0.104933364623 0.109599324870 0.114074594073 0.118380800867 0.122535770349 0.126554399434 0.130449289063 0.134231211043 0.137909459498 0.141492119993 0.144986278734 0.148398187395 0.151733394554 0.154996851658 0.158192999292 0.161325838061 0.164398987305 0.167415734111 0.170379074505 0.173291748303 0.176156268782 0.178974948057 0.181749918935 0.184483153795 0...", "3165.413034717700 4476.570044210349 5482.656203071844 6330.826069435401 7078.078722492680 7753.646760213179 8374.895686665300 8953.140088420697 9496.239104153101 10009.914924893578 10498.487342658843 10965.312406143687 11413.059004696742 11843.891063542002 12259.591967329534 12661.652138870802 13051.332290848021 13429.710132631046 13797.715532900862 14156.157444985360 14505.744837393740 14847.103184390411 15180.787616204127 15507.293520426358 15827.065173588502 16140.502832606510 16447.968609215531 16749.7...", "1218.116624752432 1722.677051277028 2109.839883615525 2436.233249504864 2723.791577469041 2983.764177844748 3222.833656968322 3445.354102554056 3654.349874257297 3852.022989934325 4040.035795197963 4219.679767231051 4391.981950040022 4557.775066957079 4717.745401404559 4872.466499009729 5022.423508175150 5168.031153831084 5309.647268742708 5447.583154938083 5582.111638212139 5713.473414041731 5841.882108059006 5967.528355689497 6090.583123762161 6211.200439444432 6329.519650846576 6445.667313936643 6559.75...", "4039.701040918746", "769.834993893392 1088.711089153444 1333.393322867831 1539.669987786784 1721.403377803760 1885.702921177414 2036.791944396843 2177.422178306887 2309.504981680176 2434.432003204934 2553.253825229922 2666.786645735663 2775.679544129132 2880.458791498282 2981.558110676796 3079.339975573568 3174.110994119182 3266.133267460331 3355.632941582547 3442.806755607520 3527.827132142336 3610.846187821139 3691.998931463184 3771.405842354828 3849.174969466960 3925.403656108988 4000.179968603494 4073.583888793686 4145.688...", "1508.306216302128 2133.067107306117 2612.463000007259 3016.612432604256 3372.675230537060 3694.580605808168 3990.603149268227 4266.134214612233 4524.918648906384 4769.683052505315 5002.485788434792 5224.926000014517 5438.275401978402 5643.565095743912 5841.644856719264 6033.224865208513 6218.905845589392 6399.201321918350 6574.554372775177 6745.350461074120 6911.927407376938 7074.583247583148 7233.582498950279 7389.161211616337 7541.531081510641 7690.882829397851 7837.389000021776 7981.206298536455 8122.47...", "4178.932872810542 5909.903544975429 7238.124057127628 8357.865745621084 9344.377977012855 10236.253207728862 11056.417127089408 11819.807089950858 12536.798618431626 13214.946067032045 13859.952363194553 14476.248114255256 15067.356749640443 15636.135052384012 16184.937421313947 16715.731491242168 17230.181636963718 17729.710634926286 18215.546084421264 18688.755954025709 19150.276213793575 19600.932605874766 20041.458005232581 20472.506415457724 20894.664364052710 21308.460264455309 21714.372171382883 221...", "1475.823459881026 2087.129552632132 2556.201215516026 2951.646919762052 3300.041579082908 3615.014427137354 3904.661853880105 4174.259105264265 4427.470379643078 4666.963557534173 4894.752673229489 5112.402431032051 5321.157158133711 5522.025750238117 5715.839682061424 5903.293839524104 6084.976009853978 6261.388657896397 6432.965320127946 6600.083158165816 6763.072717296425 6922.225614943105 7077.800671741869 7230.028854274709 7379.117299405130 7525.252620551370 7668.603646548077 7809.323707760210 7947.55...", "1726.935483870968 2442.255582633666 2991.139999458060 3453.870967741935 3861.545134691976 4230.110754190240 4569.041820575576 4884.511165267332 5180.806451612903 5461.049501197232 5727.597037150849 5982.279998916119 6226.554436514989 6461.600909707837 6688.392369006905 6907.741935483871 7120.337408627144 7326.766747900998 7527.537256208063 7723.090269383951 7913.812575143900 8100.045409746687 8282.091632275692 8460.221508380480 8634.677419354839 8805.677730973862 8973.419998374179 9138.083641151152 9299.83...", "15950.500000000000 22557.413426632053 27627.076406127377", "11925.000000000000 16864.496731299158 20654.705880258862", "36347.000000000000 51402.420351574886 62954.850702705983", "10769.000000000000 15229.665853195861 18652.455146709240", "35191.500000000000 49768.296580252774 60953.465994560145", "0.447213595500 0.632455532034 0.774596669241 0.894427191000", "0.447213595500 0.632455532034 0.774596669241 0.894427191000", "0.447213595500 0.632455532034 0.774596669241 0.894427191000", "0.447213595500 0.632455532034 0.774596669241 0.894427191000", "0.447213595500 0.632455532034 0.774596669241 0.894427191000", "0.223606797750 0.316227766017 0.387298334621 0.447213595500 0.500000000000 0.547722557505 0.591607978310 0.632455532034 0.670820393250 0.707106781187 0.741619848710 0.774596669241 0.806225774830 0.836660026534 0.866025403784 0.894427191000 0.921954445729 0.948683298051 0.974679434481", "0.035921060405 0.050800050800 0.062217101684 0.071842120811 0.080321932890 0.087988269013 0.095038192662 0.101600101600 0.107763181216 0.113592366849 0.119136679436 0.124434203368 0.129515225161 0.134404301006 0.139121668728 0.143684241621 0.148106326235 0.152400152400 0.156576272252 0.160643865780 0.164610978351 0.168484707835 0.172271353843 0.175976538026 0.179605302027 0.183162187956 0.186651305051 0.190076385325 0.193440830330 0.196747750735 0.200000000000 0.203200203200 0.206350781829 0.209453975235 0...", "0.043396303660 0.061371641193 0.075164602800 0.086792607321 0.097037084957 0.106298800691 0.114815827305 0.122743282386 0.130188910981 0.137231161599 0.143929256529 0.150329205601 0.156467598013 0.162374100149 0.168073161363 0.173585214641 0.178927543753 0.184114923580 0.189160102178 0.194074169913 0.198866846404 0.203546706606 0.208121361089 0.212597601381 0.216981518301 0.221278599182 0.225493808401 0.229631654609 0.233696247231 0.237691344271 0.241620392998 0.245486564773 0.249292785005 0.253041759057 0...", "0.037164707312 0.052558833123 0.064371161313 0.074329414625 0.083102811914 0.091034569355 0.098328573097 0.105117666246 0.111494121937 0.117525123681 0.123261389598 0.128742322627 0.133999257852 0.139057601643 0.143938292487 0.148658829249 0.153234013794 0.157676499368 0.161997203441 0.166205623829 0.170310084440 0.174317928887 0.178235674883 0.182069138710 0.185823536562 0.189503567803 0.193113483940 0.196657146194 0.200138073886 0.203559485381 0.206924332929 0.210235332491 0.213494989396 0.216705620524 0...", "0.033022909334 0.046701446249 0.057197356781 0.066045818668 0.073841470086 0.080889277691 0.087370405666 0.093402892499 0.099068728003 0.104427608461 0.109524599747 0.114394713561 0.119065792869 0.123560412643 0.127897177895 0.132091637337 0.136156943250 0.140104338748 0.143943524609 0.147682940172 0.151329981692 0.154891174376 0.158372309576 0.161778555382 0.165114546671 0.168384459091 0.171592070342 0.174740811332 0.177833809176 0.180873923568 0.183863777748 0.186805784998 0.189702171441 0.192554995756 0...", "4.672693135160 6.608186004551 8.093341918275 9.345386270320 10.448459488214 11.445713905748 12.362783988552 13.216372009102 14.018079405480 14.776353114139 15.497569889795 16.186683836551 16.847634693328 17.483616785299 18.097262694412 18.690772540640 19.266007352363 19.824558013653 20.367797170339 20.896918976429 21.412969991171 21.916873521973 22.409449036367 22.891427811495 23.363465675800 23.826153477212 24.280025754826 24.725567977104 25.163222626003 25.593394344267 26.016454316384 26.432744018204 26...."]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
167
codeforces
73c2c373039ed01f1cd16fb20ce3d7a7
Lucky Mask
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a mask of a positive integer *n* the number that is obtained after successive writing of all lucky digits of number *n* from the left to the right. For example, the mask of number 72174994 is number 7744, the mask of 7 is 7, the mask of 9999047 is 47. Obviously, mask of any number is always a lucky number. Petya has two numbers — an arbitrary integer *a* and a lucky number *b*. Help him find the minimum number *c* (*c*<=&gt;<=*a*) such that the mask of number *c* equals *b*. The only line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=105). It is guaranteed that number *b* is lucky. In the only line print a single number — the number *c* that is sought by Petya. Sample Input 1 7 100 47 Sample Output 7 147
{"inputs": ["1 7", "100 47", "458 47", "7 7", "547 47", "77 77", "44 4", "740 4", "100000 77777", "77777 77777", "47 74", "74 77", "77 74", "98545 7474", "99997 4", "100000 7", "99997 47", "47774 774", "47744 7", "45896 4", "45679 77777", "99979 77", "10 77777", "1 47774", "47774 47774", "47580 47774", "55557 74", "59765 4774", "76492 447", "69700 77477", "31975 74", "369 47", "39999 4", "39999 4774", "474 74", "40007 74444", "40007 74", "1 4", "4 4", "700 74", "476 47", "99999 77", "46 7"], "outputs": ["7", "147", "467", "17", "647", "177", "45", "804", "177777", "177777", "74", "77", "174", "107474", "100004", "100007", "100047", "50774", "50007", "45898", "77777", "100077", "77777", "47774", "147774", "47774", "55574", "64774", "80447", "77477", "32074", "407", "40000", "40774", "574", "74444", "50074", "4", "14", "704", "478", "100077", "57"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
33
codeforces
73c44a48d44126430dc7349b0c20f436
Magnum Opus
Salve, mi amice. Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus. Rp:     I Aqua Fortis     I Aqua Regia     II Amalgama     VII Minium     IV Vitriol Misce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci invia est via. Fac et spera, Vale, Nicolas Flamel The first line of input contains several space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100). Print a single integer. Sample Input 2 4 6 8 10 Sample Output 1
{"inputs": ["2 4 6 8 10", "50 27 17 31 89", "50 87 29 81 21", "74 21 36 68 80", "75 82 48 95 12", "41 85 14 43 23", "94 28 3 29 9", "94 21 36 89 20", "60 92 82 71 53", "46 68 3 0 51", "12 39 3 50 84", "12 31 47 31 84", "79 2 93 92 16", "65 46 3 77 81", "31 38 47 26 13", "42 9 59 19 24", "51 19 70 5 78", "51 56 14 99 21", "28 49 58 47 54", "3 26 69 33 18", "14 63 14 25 18", "81 67 58 8 51", "81 26 69 0 84", "32 36 80 54 48", "0 74 25 35 48", "67 66 69 96 92", "52 43 80 14 79", "18 13 91 64 22", "19 84 69 57 55", "71 61 47 9 19", "0 0 0 0 0", "1 1 2 7 4", "1 0 2 7 4", "1 1 2 6 4", "1 1 1 7 4", "1 2 2 7 4", "1 1 3 7 4", "2 2 3 14 8", "100 100 100 100 100"], "outputs": ["1", "4", "5", "9", "3", "5", "1", "5", "10", "0", "1", "4", "2", "1", "3", "2", "0", "5", "6", "3", "3", "1", "0", "7", "0", "13", "2", "5", "8", "1", "0", "1", "0", "0", "0", "1", "1", "1", "14"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
17
codeforces
73d950c4bb08b0f14ae222ba7f1c8b69
Compatible Numbers
Two integers *x* and *y* are compatible, if the result of their bitwise "AND" equals zero, that is, *a* &amp; *b*<==<=0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 &amp; 1001002<==<=02, and numbers 3 (112) and 6 (1102) are not compatible, as 112 &amp; 1102<==<=102. You are given an array of integers *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find the following for each array element: is this element compatible with some other element from the given array? If the answer to this question is positive, then you also should find any suitable element. The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the number of elements in the given array. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=4·106) — the elements of the given array. The numbers in the array can coincide. Print *n* integers *ans**i*. If *a**i* isn't compatible with any other element of the given array *a*1,<=*a*2,<=...,<=*a**n*, then *ans**i* should be equal to -1. Otherwise *ans**i* is any such number, that *a**i* &amp; *ans**i*<==<=0, and also *ans**i* occurs in the array *a*1,<=*a*2,<=...,<=*a**n*. Sample Input 2 90 36 4 3 6 3 6 5 10 6 9 8 2 Sample Output 36 90-1 -1 -1 -1-1 8 2 2 8
{"inputs": ["2\n90 36", "4\n3 6 3 6", "5\n10 6 9 8 2", "10\n4 9 8 3 2 6 8 2 9 7", "10\n3 5 18 12 4 20 11 19 15 6", "15\n8 4 9 3 6 6 6 6 1 6 7 1 8 9 2", "20\n280 983 126 941 167 215 868 748 383 554 917 285 43 445 331 800 527 998 503 164", "5\n1 4 2 3 5", "1\n1", "1\n4000000", "1\n2097152"], "outputs": ["36 90", "-1 -1 -1 -1", "-1 8 2 2 8", "8 4 4 8 8 8 4 8 4 8", "4 18 4 18 18 3 4 4 -1 -1", "4 8 4 8 8 8 8 8 8 8 8 8 4 4 8", "164 -1 -1 -1 280 800 -1 -1 -1 -1 -1 -1 -1 -1 164 215 -1 -1 -1 280", "4 2 4 4 2", "-1", "-1", "-1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
73e0e3099a08bef90835f286bcd130e8
none
One day student Vasya was sitting on a lecture and mentioned a string *s*1*s*2... *s**n*, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph *G* with the following properties: - *G* has exactly *n* vertices, numbered from 1 to *n*. - For all pairs of vertices *i* and *j*, where *i*<=≠<=*j*, there is an edge connecting them if and only if characters *s**i* and *s**j* are either equal or neighbouring in the alphabet. That is, letters in pairs "a"-"b" and "b"-"c" are neighbouring, while letters "a"-"c" are not. Vasya painted the resulting graph near the string and then erased the string. Next day Vasya's friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya's adventure and now he wants to find out whether it could be the original graph *G*, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string *s*, such that if Vasya used this *s* he would produce the given graph *G*. The first line of the input contains two integers *n* and *m*  — the number of vertices and edges in the graph found by Petya, respectively. Each of the next *m* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*) — the edges of the graph *G*. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once. In the first line print "Yes" (without the quotes), if the string *s* Petya is interested in really exists and "No" (without the quotes) otherwise. If the string *s* exists, then print it on the second line of the output. The length of *s* must be exactly *n*, it must consist of only letters "a", "b" and "c" only, and the graph built using this string must coincide with *G*. If there are multiple possible answers, you may print any of them. Sample Input 2 1 1 2 4 3 1 2 1 3 1 4 Sample Output Yes aa No
{"inputs": ["2 1\n1 2", "4 3\n1 2\n1 3\n1 4", "4 4\n1 2\n1 3\n1 4\n3 4", "1 0", "8 28\n3 2\n4 2\n7 4\n6 3\n3 7\n8 1\n3 4\n5 1\n6 5\n5 3\n7 1\n5 8\n5 4\n6 1\n6 4\n2 1\n4 1\n8 2\n7 2\n6 8\n8 4\n6 7\n3 1\n7 8\n3 8\n5 7\n5 2\n6 2", "8 28\n3 2\n4 2\n7 4\n6 3\n3 7\n8 1\n3 4\n5 1\n6 5\n5 3\n7 1\n5 8\n5 4\n6 1\n6 4\n2 1\n4 1\n8 2\n7 2\n6 8\n8 4\n6 7\n3 1\n7 8\n3 8\n5 7\n5 2\n6 2", "4 3\n4 3\n2 4\n2 3", "4 2\n4 3\n1 2", "5 3\n1 2\n1 3\n4 5", "6 4\n1 2\n1 3\n4 5\n4 6", "6 4\n1 2\n2 3\n4 5\n4 6", "6 4\n3 2\n1 3\n6 5\n4 6", "6 4\n1 2\n1 3\n4 6\n5 6", "7 13\n1 2\n2 3\n1 3\n4 5\n5 6\n4 6\n2 5\n2 7\n3 7\n7 4\n7 6\n7 1\n7 5", "8 18\n3 7\n2 5\n5 3\n3 8\n8 6\n6 3\n6 4\n4 8\n1 2\n6 1\n2 7\n2 4\n4 5\n4 3\n6 5\n1 4\n5 7\n3 1", "20 55\n20 11\n14 5\n4 9\n17 5\n16 5\n20 16\n11 17\n2 14\n14 19\n9 15\n20 19\n5 18\n15 20\n1 16\n12 20\n4 7\n16 19\n17 19\n16 12\n19 9\n11 13\n18 17\n10 8\n20 1\n16 8\n1 13\n11 12\n13 18\n4 13\n14 10\n9 13\n8 9\n6 9\n2 13\n10 16\n19 1\n7 17\n20 4\n12 8\n3 2\n18 10\n6 13\n14 9\n7 9\n19 7\n8 15\n20 6\n16 13\n14 13\n19 8\n7 14\n6 2\n9 1\n7 1\n10 6", "15 84\n11 9\n3 11\n13 10\n2 12\n5 9\n1 7\n14 4\n14 2\n14 1\n11 8\n1 8\n14 10\n4 15\n10 5\n5 12\n13 11\n6 14\n5 7\n12 11\n9 1\n10 15\n2 6\n7 15\n14 9\n9 7\n11 14\n8 15\n12 7\n13 6\n2 9\n9 6\n15 3\n12 15\n6 15\n4 6\n4 1\n9 12\n10 7\n6 1\n11 10\n2 3\n5 2\n13 2\n13 3\n12 6\n4 3\n5 8\n12 1\n9 15\n14 5\n12 14\n10 1\n9 4\n7 13\n3 6\n15 1\n13 9\n11 1\n10 4\n9 3\n8 12\n13 12\n6 7\n12 10\n4 12\n13 15\n2 10\n3 8\n1 5\n15 2\n4 11\n2 1\n10 8\n14 3\n14 8\n8 7\n13 1\n5 4\n11 2\n6 8\n5 15\n2 4\n9 8\n9 10", "15 13\n13 15\n13 3\n14 3\n10 7\n2 5\n5 12\n12 11\n9 2\n13 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 4\n3 4", "4 3\n1 3\n2 4\n1 4", "5 6\n1 2\n2 4\n2 5\n3 4\n3 5\n4 5", "6 10\n1 5\n1 4\n3 4\n3 6\n1 2\n3 5\n2 5\n2 6\n1 6\n4 6", "4 3\n1 2\n3 4\n2 3"], "outputs": ["Yes\naa", "No", "Yes\nbacc", "Yes\na", "Yes\naaaaaaaa", "Yes\naaaaaaaa", "Yes\naccc", "Yes\naacc", "No", "No", "No", "No", "No", "No", "No", "No", "No", "No", "No", "Yes\naaaa", "Yes\nabcc", "Yes\nacaa", "Yes\nbacc", "Yes\nacbc", "Yes\nabbc", "Yes\nacba", "Yes\nbabc", "Yes\naabc", "Yes\naaca", "Yes\nbaca", "Yes\nacac", "Yes\nabca", "Yes\nbbac", "Yes\nabac", "Yes\nacca", "Yes\nbaac", "Yes\naaac", "Yes\naccb", "Yes\nabcb", "Yes\nacab", "Yes\nbacb", "Yes\naacb", "Yes\nacbb", "Yes\nac", "No", "Yes\naac", "Yes\nabc", "Yes\naaa", "Yes\nacc", "Yes\naca", "No", "Yes\nbbabc", "No", "No", "No", "No", "No", "No", "No", "No", "No"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
740f0bdf10e187653b10fb1e412b52c9
Game
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally. The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50. This problem doesn't have subproblems. You will get 3 points for the correct submission. Output "First" if the first player wins and "Second" otherwise. Sample Input 2 2 1 2 2 1 1 1 Sample Output Second First
{"inputs": ["2 2 1 2", "2 1 1 1", "5 7 4 1", "5 7 1 4", "5 7 10 10", "5 7 1 10", "1 1 1 1", "50 50 50 50", "50 49 1 2", "50 48 3 1", "48 50 12 11", "49 50 11 12", "49 49 4 1", "49 49 3 3", "1 50 1 50", "1 50 50 50", "50 1 1 1", "50 1 1 50", "32 31 10 9", "32 4 17 3"], "outputs": ["Second", "First", "Second", "Second", "Second", "Second", "Second", "Second", "First", "First", "Second", "Second", "Second", "Second", "Second", "Second", "First", "First", "First", "First"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
375
codeforces