LightingRL Series
Collection
Diffusion Large Language Models with a SOTA Accuracy–Parallelism Trade-off • 7 items • Updated • 2
question stringlengths 29 1.88k | test_input listlengths 0 10 | test_output listlengths 0 10 | test_time_limit int64 1 1 | test_method stringclasses 1
value |
|---|---|---|---|---|
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if $\operatorname{mod}(x, b) \neq 0$ and $\frac{\operatorname{div}(x, b)}{\operatorname{mod}(x, b)} = k$, where k is some integer... | [
"1 1\n",
"2 2\n",
"4 1\n",
"4 2\n",
"4 3\n",
"4 4\n",
"3 4\n",
"2 4\n",
"1 4\n",
"1000 1000\n"
] | [
"0\n",
"8\n",
"0\n",
"24\n",
"102\n",
"264\n",
"162\n",
"84\n",
"30\n",
"247750000\n"
] | 1 | stdio |
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve... | [
"19 29\n",
"3 6\n",
"39 91\n",
"76 134\n",
"93 95\n",
"17 35\n",
"94 95\n",
"51 52\n",
"47 52\n",
"38 98\n"
] | [
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n"
] | 1 | stdio |
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!). $8$ illustration by 猫屋 https://twitter.com/nekoyaliu ... | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n",
"QA\n",
"IAQVAQZLQBQVQFTQQQADAQJA\n",
"QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ\n",
"AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ\n",
"AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA\n",
"KAZXAVLPJQBQVQQQQQ... | [
"4\n",
"3\n",
"0\n",
"24\n",
"378\n",
"1077\n",
"568\n",
"70\n",
"0\n",
"0\n"
] | 1 | stdio |
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of ... | [
"101\n",
"110010\n",
"10000\n",
"1111111110\n",
"10100101011110101\n",
"111010010111\n",
"11110111011100000000\n",
"11110010010100001110110101110011110110100111101\n",
"1001011111010010100111111\n",
"1111111111\n"
] | [
"11\n",
"11010\n",
"1000\n",
"111111111\n",
"1100101011110101\n",
"11110010111\n",
"1111111011100000000\n",
"1111010010100001110110101110011110110100111101\n",
"101011111010010100111111\n",
"111111111\n"
] | 1 | stdio |
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two di... | [
"2\n2 3\n",
"2\n5 3\n",
"3\n5 6 7\n",
"10\n72 96 24 66 6 18 12 30 60 48\n",
"10\n78 66 6 60 18 84 36 96 72 48\n",
"10\n98 63 42 56 14 77 70 35 84 21\n",
"2\n1 1000000000\n",
"2\n1000000000 999999999\n",
"3\n2 4 6\n",
"2\n4 6\n"
] | [
"Alice\n",
"Alice\n",
"Bob\n",
"Bob\n",
"Bob\n",
"Bob\n",
"Bob\n",
"Bob\n",
"Bob\n",
"Alice\n"
] | 1 | stdio |
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of h_{i} identical blocks. For clarification see picture for the first sample.
Limak will repeat the following operation till everything is destroyed.
Block is called internal i... | [
"6\n2 1 4 6 2 2\n",
"7\n3 3 3 1 3 3 3\n",
"7\n5128 5672 5805 5452 5882 5567 5032\n",
"10\n1 2 2 3 5 5 5 4 2 1\n",
"14\n20 20 20 20 20 20 3 20 20 20 20 20 20 20\n",
"50\n3 2 4 3 5 3 4 5 3 2 3 3 3 4 5 4 2 2 3 3 4 4 3 2 3 3 2 3 4 4 5 2 5 2 3 5 4 4 2 2 3 5 2 5 2 2 5 4 5 4\n",
"1\n1\n",
"1\n1000000000\n",
... | [
"3\n",
"2\n",
"4\n",
"5\n",
"5\n",
"4\n",
"1\n",
"1\n",
"1\n",
"1\n"
] | 1 | stdio |
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain posi... | [
"21\n",
"20\n",
"1\n",
"2\n",
"3\n",
"100000001\n",
"1000000000\n",
"999999979\n",
"9\n",
"10\n"
] | [
"1\n15\n",
"0\n",
"0\n",
"1\n1\n",
"0\n",
"2\n99999937\n100000000\n",
"1\n999999932\n",
"2\n999999899\n999999908\n",
"0\n",
"1\n5\n"
] | 1 | stdio |
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' $\rightarrow$ 'y' $\rightarrow$ 'x' $\rightarrow \ldots \rightarrow$ 'b' $\rightarrow$ 'a' $\rightarrow$ 'z'. In other words, each character is replaced with th... | [
"codeforces\n",
"abacaba\n",
"babbbabaababbaa\n",
"bcbacaabcababaccccaaaabacbbcbbaa\n",
"cabaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda\n",
"a\n",
"eeeedddccbceaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec\n",
"fd... | [
"bncdenqbdr\n",
"aaacaba\n",
"aabbbabaababbaa\n",
"abaacaabcababaccccaaaabacbbcbbaa\n",
"babaccaacccabaacdbdcbcdbccbccbabbdadbdcdcdbdbcdcdbdadcbcda\n",
"z\n",
"ddddcccbbabdaabdaecaebaeaecccbdeeeaadcecdbeacecdcdcceabaadbcbbadcdaeddbcccaaeebccecaeeeaebcaaccbdaccbdcadadaaeacbbdcbaeeaecedeeeedadec\n",
"ec... | 1 | stdio |
Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward).
... | [
"3\n4 2 1\n",
"1\n4\n",
"2\n1 1\n",
"1\n2\n",
"1\n3\n",
"1\n5\n",
"2\n2 2\n",
"3\n1 2 4\n",
"3\n3 3 3\n",
"3\n3 3 6\n"
] | [
"1\naabcbaa\n",
"4\naaaa\n",
"0\nab\n",
"2\naa\n",
"3\naaa\n",
"5\naaaaa\n",
"2\nabba\n",
"1\nbccaccb\n",
"0\naaabbbccc\n",
"0\naaabbbcccccc\n"
] | 1 | stdio |
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with n rows and m col... | [
"2 4\n",
"2 1\n",
"1 1\n",
"1 2\n",
"1 3\n",
"2 2\n",
"2 3\n",
"3 1\n",
"3 2\n",
"3 3\n"
] | [
"YES\n5 4 7 2 \n3 6 1 8 \n",
"NO\n",
"YES\n1\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n6 1 8\n7 5 3\n2 9 4\n"
] | 1 | stdio |
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 10^9 + ... | [
"ab\n",
"aab\n",
"aaaaabaabababaaaaaba\n",
"abaabaaabbabaabab\n",
"abbaa\n",
"abbaaabaabaaaaabbbbaababaaaaabaabbaaaaabbaabbaaaabbbabbbabb\n",
"aababbaaaabbaabbbbbbbbabbababbbaaabbaaabbabbba\n",
"aabbaababbabbbaabbaababaaaabbaaaabaaaaaababbaaaabaababbabbbb\n",
"aaabaaaabbababbaabbababbbbaaaaaaabbabbb... | [
"1\n",
"3\n",
"17307\n",
"1795\n",
"2\n",
"690283580\n",
"2183418\n",
"436420225\n",
"8431094\n",
"8180\n"
] | 1 | stdio |
Sonya was unable to think of a story for this problem, so here comes the formal description.
You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operati... | [
"7\n2 1 5 11 5 9 11\n",
"5\n5 4 3 2 1\n",
"2\n1 1000\n",
"2\n1000 1\n",
"5\n100 80 60 70 90\n",
"10\n10 16 17 11 1213 1216 1216 1209 3061 3062\n",
"20\n103 103 110 105 107 119 113 121 116 132 128 124 128 125 138 137 140 136 154 158\n",
"1\n1\n",
"5\n1 1 1 2 3\n",
"1\n1000\n"
] | [
"9\n",
"12\n",
"0\n",
"1000\n",
"54\n",
"16\n",
"43\n",
"0\n",
"3\n",
"0\n"
] | 1 | stdio |
You are given an array $a$ of $n$ integers.
You want to make all elements of $a$ equal to zero by doing the following operation exactly three times: Select a segment, for each number in this segment we can add a multiple of $len$ to it, where $len$ is the length of this segment (added integers can be different).
It... | [
"4\n1 3 2 4\n",
"1\n34688642\n",
"2\n-492673762 -496405053\n",
"4\n-432300451 509430974 -600857890 -140418957\n",
"16\n-15108237 489260742 681810357 -78861365 -416467743 -896443270 904192296 -932642644 173249302 402207268 -329323498 537696045 -899233426 902347982 -595589754 -480337024\n",
"8\n-311553829 4... | [
"1 4\n-4 -12 -8 0\n1 3\n3 9 6 \n4 4\n-4\n",
"1 1\n-34688642\n1 1\n0\n1 1\n0\n",
"1 2\n985347524 0\n1 1\n-492673762 \n2 2\n496405053\n",
"1 4\n1729201804 -2037723896 2403431560 0\n1 3\n-1296901353 1528292922 -1802573670 \n4 4\n140418957\n",
"1 16\n241731792 -7828171872 -10908965712 1261781840 6663483888 1434... | 1 | stdio |
Little X has n distinct integers: p_1, p_2, ..., p_{n}. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied: If number x belongs to set A, then number a - x must also belong to set A. If number x belongs to set B, then number b - x must also belong to set B.
Help Lit... | [
"4 5 9\n2 3 4 5\n",
"3 3 4\n1 2 4\n",
"100 8883 915\n1599 4666 663 3646 754 2113 2200 3884 4082 1640 3795 2564 2711 2766 1122 4525 1779 2678 2816 2182 1028 2337 4918 1273 4141 217 2682 1756 309 4744 915 1351 3302 1367 3046 4032 4503 711 2860 890 2443 4819 4169 4721 3472 2900 239 3551 1977 2420 3361 3035 956 253... | [
"YES\n0 0 1 1\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"YES\n0\n",
"YES\n0\n",
"YES\n1 1\n",
"NO\n",
"NO\n"
] | 1 | stdio |
Nikita likes tasks on order statistics, for example, he can easily find the $k$-th number in increasing order on a segment of an array. But now Nikita wonders how many segments of an array there are such that a given number $x$ is the $k$-th number in increasing order on this segment. In other words, you should find th... | [
"5 3\n1 2 3 4 5\n",
"2 6\n-5 9\n",
"6 99\n-1 -1 -1 -1 -1 -1\n",
"5 -2\n-1 -1 -4 -5 1\n",
"5 -6\n-4 2 -7 -1 -5\n",
"10 29\n88 57 -3 -9 16 48 -84 80 -73 -46\n",
"1 1000000000\n1\n",
"2 -1000000000\n465132 210\n",
"10 -8\n7 -1 0 -8 8 -1 -10 -7 4 0\n",
"10 9\n-2 6 0 -6 7 -8 -5 4 -3 3\n"
] | [
"6 5 4 0 0 0 ",
"1 2 0 ",
"0 6 5 4 3 2 1 ",
"4 5 6 0 0 0 ",
"6 9 0 0 0 0 ",
"5 13 11 11 8 4 3 0 0 0 0 ",
"0 1 ",
"3 0 0 ",
"27 28 0 0 0 0 0 0 0 0 0 ",
"0 10 9 8 7 6 5 4 3 2 1 "
] | 1 | stdio |
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read. His father decided t... | [
"4\nezor\n",
"10\nnznooeeoer\n",
"4\neorz\n",
"3\nnoe\n",
"40\noeerzzozozzrezeezzzoroozrrreorrreereooeo\n",
"32\noeonznzneeononnerooooooeeeneenre\n",
"35\nozrorrooeoeeeozonoenzoeoreenzrzenen\n",
"30\nooeoeneenneooeennnoeeonnooneno\n",
"400\nzzzerrzrzzrozrezooreroeoeezerrzeerooereezeeererrezrororoorr... | [
"0 \n",
"1 1 0 \n",
"0 \n",
"1 \n",
"0 0 0 0 0 0 0 0 0 0 \n",
"1 1 1 1 1 1 1 1 0 0 \n",
"1 1 1 1 1 0 0 0 0 0 \n",
"1 1 1 1 1 1 1 1 1 1 \n",
"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 | stdio |
Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p_1, p_2, ..., p_{n}.
Your task is to find such permutation p of length n, that the group of numbers |p_1 - p_2|, |p_2 - p_3|, ..., |p_... | [
"3 2\n",
"3 1\n",
"5 2\n",
"5 4\n",
"10 4\n",
"10 3\n",
"10 9\n",
"2 1\n",
"4 1\n",
"4 2\n"
] | [
"1 3 2\n",
"1 2 3\n",
"1 3 2 4 5\n",
"1 5 2 4 3\n",
"1 10 2 9 8 7 6 5 4 3\n",
"1 10 2 3 4 5 6 7 8 9\n",
"1 10 2 9 3 8 4 7 5 6\n",
"1 2\n",
"1 2 3 4\n",
"1 4 3 2\n"
] | 1 | stdio |
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.
Note that the order of the points inside the group of three chosen point... | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n",
"10 5\n31 36 43 47 48 50 56 69 71 86\n",
"10 50\n1 4 20 27 65 79 82 83 99 100\n",
"10 90\n24 27 40 41 61 69 73 87 95 97\n",
"100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -5... | [
"4\n",
"2\n",
"1\n",
"2\n",
"25\n",
"120\n",
"79351\n",
"0\n",
"0\n",
"0\n"
] | 1 | stdio |
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly a_{i} feet high.
[Image]
A group of bears is a non-empty contiguous segment of the line. The siz... | [
"10\n1 2 3 4 5 4 3 2 1 6\n",
"3\n524125987 923264237 374288891\n",
"5\n585325539 365329221 412106895 291882089 564718673\n",
"20\n452405440 586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717... | [
"6 4 4 3 3 2 2 1 1 1 \n",
"923264237 524125987 374288891 \n",
"585325539 365329221 365329221 291882089 291882089 \n",
"954478790 641889899 519361360 452405440 346543678 346543678 208050516 208050516 208050516 208050516 80960260 80960260 80960260 66743034 66743034 16115810 16115810 16115810 16115810 16115810 \... | 1 | stdio |
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n",
"10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n",
"5\n10\n10\n10\n10\n10\n",
"11\n291\n381\n126\n39\n19\n20\n3\n1\n20\n45\n2\n",
"1\n1\n",
"13\n67\n75\n76\n80\n69\n86\n75\n86\n81\n84\n73\n72\n76\n",
"25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\... | [
"3\n",
"1680\n",
"12520708\n",
"425711769\n",
"902382672\n",
"1\n",
"232242896\n",
"362689152\n",
"295545118\n",
"691446102\n"
] | 1 | stdio |
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from... | [
"ababa\naba\n",
"welcometoroundtwohundredandeightytwo\nd\n",
"ddd\nd\n",
"vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\nnssnssns\n",
"kpjmawawawawawawawawawawawawawawawawawawawawawawaw\nwawawawa\n",
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvv\n",
"a\na\n",
"a\naa\n",
"a\nb\n"... | [
"5\n",
"274201\n",
"12\n",
"943392\n",
"834052\n",
"2728075\n",
"1\n",
"0\n",
"0\n",
"35\n"
] | 1 | stdio |
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that... | [
"2\n6 12 10\n4 3 10\n",
"4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n",
"10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2\n",
"10\n1 3 10\n6 2 6\n2 3 9\n7 8 4\n5 6 10\n1 2 7\n0 3 6\n9 3 4\n4 4 9\n10 9 10\n",
"10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 9\n6 7 9\n9 1 4\n",
"1... | [
"Finite\nInfinite\n",
"Finite\nFinite\nFinite\nInfinite\n",
"Finite\nInfinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite\n",
"Infinite\nFinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nInfinite\n",
"Infinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nF... | 1 | stdio |
You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $x$ and $y$ with an edge if and only if $x \& y = 0$. Here $\&$ is the bitwise AND operation. Count the number of connected components i... | [
"2 3\n1 2 3\n",
"5 5\n5 19 10 20 12\n",
"3 5\n3 5 0 6 7\n",
"0 1\n0\n",
"1 1\n1\n",
"1 1\n0\n",
"6 30\n3 8 13 16 18 19 21 22 24 25 26 28 29 31 33 42 44 46 49 50 51 53 54 57 58 59 60 61 62 63\n",
"6 35\n5 7 10 11 13 14 17 18 25 27 28 29 30 31 33 35 36 37 39 40 41 43 46 47 50 52 55 56 57 58 59 60 61 62 ... | [
"2\n",
"2\n",
"1\n",
"1\n",
"1\n",
"1\n",
"10\n",
"13\n",
"20\n",
"19\n"
] | 1 | stdio |
In order to fly to the Moon Mister B just needs to solve the following problem.
There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles.
We are sure that Mister B will solve the problem soon and will fly to the Mo... | [
"3\n",
"5\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"9\n",
"10\n",
"11\n"
] | [
"2\n3 1 2 3\n3 1 2 3\n",
"6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2\n",
"4\n3 4 1 2\n3 2 3 4\n3 1 2 3\n3 3 4 1\n",
"6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2\n",
"9\n3 6 1 2\n4 6 2 5 3\n3 3 4 5\n3 1 2 3\n4 1 3 6 4\n3 4 5 6\n3 2 3 4\n4 2 4 1 5\n3 5 6 1\n",
"12\n4 2 3 1 4... | 1 | stdio |
Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being of any kind is equal. As the north of wall is full of dangers, he... | [
"1 1\n1\n",
"2 2\n1\n2\n",
"3 5\n1\n4\n20\n50\n300\n",
"4 5\n2\n4\n30\n100\n1000\n",
"5 6\n1\n2\n3\n4\n5\n6\n",
"6 6\n10\n20\n30\n40\n50\n60\n",
"990 1\n990\n",
"7 10\n100\n200\n300\n400\n500\n600\n700\n800\n900\n1000\n",
"8 10\n50\n150\n250\n350\n450\n550\n650\n750\n850\n950\n",
"1 1\n1000\n"
] | [
"1\n",
"2\n2\n",
"3\n3\n3\n3\n3\n",
"4\n4\n4\n4\n7\n",
"5\n5\n5\n5\n5\n5\n",
"6\n6\n6\n7\n7\n7\n",
"7177\n",
"9\n10\n11\n12\n13\n14\n14\n15\n16\n17\n",
"10\n12\n13\n14\n15\n16\n17\n18\n19\n19\n",
"1\n"
] | 1 | stdio |
Consider a sequence [a_1, a_2, ... , a_{n}]. Define its prefix product sequence $[ a_{1} \operatorname{mod} n,(a_{1} a_{2}) \operatorname{mod} n, \cdots,(a_{1} a_{2} \cdots a_{n}) \operatorname{mod} n ]$.
Now given n, find a permutation of [1, 2, ..., n], such that its prefix product sequence is a permutation of [0, 1... | [
"7\n",
"6\n",
"7137\n",
"1941\n",
"55004\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n"
] | [
"YES\n1\n2\n5\n6\n3\n4\n7\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n1\n",
"YES\n1\n2\n",
"YES\n1\n2\n3\n",
"YES\n1\n3\n2\n4",
"YES\n1\n2\n4\n3\n5\n"
] | 1 | stdio |
You are given a prime number $p$, $n$ integers $a_1, a_2, \ldots, a_n$, and an integer $k$.
Find the number of pairs of indexes $(i, j)$ ($1 \le i < j \le n$) for which $(a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p$.
-----Input-----
The first line contains integers $n, p, k$ ($2 \le n \le 3 \cdot 10^5$, $2 \le p \l... | [
"3 3 0\n0 1 2\n",
"6 7 2\n1 2 3 4 5 6\n",
"5 5 3\n3 0 4 1 2\n",
"7 7 3\n4 0 5 3 1 2 6\n",
"2 2 1\n1 0\n",
"3 3 0\n0 2 1\n",
"2 2 0\n1 0\n",
"3 3 1\n0 2 1\n",
"3 3 2\n0 1 2\n"
] | [
"1",
"3",
"1",
"0",
"1",
"1",
"0",
"1",
"1"
] | 1 | stdio |
Let's assume that v(n) is the largest prime number, that does not exceed n;
u(n) is the smallest prime number strictly greater than n.
Find $\sum_{i = 2}^{n} \frac{1}{v(i) u(i)}$.
-----Input-----
The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases.
Each of the following t lines of the ... | [
"2\n2\n3\n",
"1\n1000000000\n",
"5\n3\n6\n9\n10\n5\n",
"5\n5\n8\n18\n17\n17\n",
"5\n7\n40\n37\n25\n4\n",
"5\n72\n72\n30\n75\n11\n",
"5\n79\n149\n136\n194\n124\n",
"6\n885\n419\n821\n635\n63\n480\n",
"1\n649580447\n"
] | [
"1/6\n7/30\n",
"999999941999999673/1999999887999999118\n",
"7/30\n5/14\n61/154\n9/22\n23/70\n",
"23/70\n59/154\n17/38\n287/646\n287/646\n",
"57/154\n39/82\n1437/3034\n615/1334\n3/10\n",
"71/146\n71/146\n29/62\n5615/11534\n119/286\n",
"6393/13114\n22199/44998\n135/274\n37631/76042\n14121/28702\n",
"781... | 1 | stdio |
Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.
Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater... | [
"6\n",
"9\n",
"2\n",
"10\n",
"100\n",
"1\n",
"3\n",
"5\n"
] | [
"2\n6 3\n2 4\n",
"3\n9 3\n2 4\n6 8\n",
"0\n",
"4\n2 4\n6 8\n10 5\n9 3\n",
"44\n33 27\n22 11\n25 5\n64 66\n42 44\n31 62\n58 29\n43 86\n15 21\n6 99\n8 12\n85 65\n7 49\n23 46\n16 14\n20 18\n90 92\n48 50\n40 36\n74 37\n35 55\n10 95\n56 60\n47 94\n45 39\n93 87\n88 84\n72 76\n28 24\n75 81\n78 80\n54 52\n38 19\n3 ... | 1 | stdio |
You are given a sequence a consisting of n integers. Find the maximum possible value of $a_{i} \operatorname{mod} a_{j}$ (integer remainder of a_{i} divided by a_{j}), where 1 ≤ i, j ≤ n and a_{i} ≥ a_{j}.
-----Input-----
The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·10^5).
The second l... | [
"3\n3 4 5\n",
"3\n1 2 4\n",
"1\n1\n",
"1\n1000000\n",
"2\n1000000 999999\n",
"12\n4 4 10 13 28 30 41 43 58 61 70 88\n",
"7\n2 13 22 32 72 91 96\n",
"5\n5 11 12 109 110\n"
] | [
"2\n",
"0\n",
"0\n",
"0\n",
"1\n",
"30\n",
"27\n",
"10\n"
] | 1 | stdio |
You are given a string S of length n with each character being one of the first m lowercase English letters.
Calculate how many different strings T of length n composed from the first m lowercase English letters exist such that the length of LCS (longest common subsequence) between S and T is n - 1.
Recall that LCS ... | [
"3 3\naaa\n",
"3 3\naab\n",
"1 2\na\n",
"10 9\nabacadefgh\n",
"15 3\nabababababababa\n",
"100 26\njysrixyptvsesnapfljeqkytlpeepjopspmkviqdqbdkylvfiawhdjjdvqqvcjmmsgfdmpjwahuwhgsyfcgnefzmqlvtvqqfbfsf\n",
"1 26\nz\n"
] | [
"6\n",
"11\n",
"1\n",
"789\n",
"345\n",
"237400\n",
"25\n"
] | 1 | stdio |
You are given a sequence a = \{a_1, ..., a_N\} with all zeros, and a sequence b = \{b_1, ..., b_N\} consisting of 0 and 1. The length of both is N.
You can perform Q kinds of operations. The i-th operation is as follows:
- Replace each of a_{l_i}, a_{l_i + 1}, ..., a_{r_i} with 1.
Minimize the hamming distance between... | [
"3\n1 0 1\n1\n1 3\n",
"3\n1 0 1\n2\n1 1\n3 3\n",
"3\n1 0 1\n2\n1 1\n2 3\n",
"5\n0 1 0 1 0\n1\n1 5\n",
"9\n0 1 0 1 1 1 0 1 0\n3\n1 4\n5 8\n6 7\n",
"15\n1 1 0 0 0 0 0 0 1 0 1 1 1 0 0\n9\n4 10\n13 14\n1 7\n4 14\n9 11\n2 6\n7 8\n3 12\n7 13\n",
"10\n0 0 0 1 0 0 1 1 1 0\n7\n1 4\n2 5\n1 3\n6 7\n9 9\n1 5\n7 9\n... | [
"1\n",
"0\n",
"1\n",
"2\n",
"3\n",
"5\n",
"1\n"
] | 1 | stdio |
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $f(0) = a$; $f(1) = b$; $f(n) = f(n-1) \oplus f(n-2)$ when $n > 1$, where $\o... | [
"3\n3 4 2\n4 5 0\n325 265 1231232\n",
"10\n0 0 1000000000\n1002 2003 36523\n233 5656 898989\n0 2352 0\n21132 23256 2323256\n12313 454878 11000\n1213 0 21\n11 1 1\n1 1 98532\n1000000000 1000000000 1000000000\n",
"1\n25369 85223 58963241\n",
"2\n168342 440469 517112\n841620 806560 140538\n",
"10\n669924290 40... | [
"7\n4\n76\n",
"0\n2003\n233\n0\n2132\n442567\n1213\n1\n1\n1000000000\n",
"77822\n",
"272643\n841620\n",
"1069371953\n696139211\n286024744\n189259304\n707829111\n54555019\n578351356\n463366171\n178762989\n825160173\n",
"1\n"
] | 1 | stdio |
The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive.
All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that... | [
"3\n1 1\n",
"5\n1 2 3 4\n",
"31\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\n",
"29\n1 2 2 4 4 6 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28\n",
"2\n1\n",
"3\n1 2\n"
] | [
"4 3 3",
"5 8 9 8 5",
"73741817 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 ... | 1 | stdio |
For strings s and t, we will say that s and t are prefix-free when neither is a prefix of the other.
Let L be a positive integer. A set of strings S is a good string set when the following conditions hold true:
- Each string in S has a length between 1 and L (inclusive) and consists of the characters 0 and 1.
- Any t... | [
"2 2\n00\n01\n",
"2 2\n00\n11\n",
"3 3\n0\n10\n110\n",
"2 1\n0\n1\n",
"1 2\n11\n",
"2 3\n101\n11\n"
] | [
"Alice\n",
"Bob\n",
"Alice\n",
"Bob\n",
"Alice\n",
"Bob\n"
] | 1 | stdio |
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are r... | [
"6 4\n()(())\n",
"8 8\n(()(()))\n",
"20 10\n((()))()((()()(())))\n",
"40 30\n((((((((()()()))))))))((())((()())))(())\n",
"2 2\n()\n"
] | [
"()()\n",
"(()(()))\n",
"((()))()()\n",
"((((((((()()()))))))))(())()()\n",
"()\n"
] | 1 | stdio |
The Bubble Cup hypothesis stood unsolved for $130$ years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem:
Given a number $m$, how many polynomials $P$ with coefficients in set ${\{0,1,2... | [
"2\n2 4\n",
"1\n9\n",
"5\n4 1 8 3 9\n",
"6\n8 7 8 6 8 9\n",
"8\n1 1 7 6 1 5 8 7\n",
"7\n9 6 3 1 3 1 7\n",
"3\n9 2 8\n",
"5\n3 7 3 4 7\n",
"5\n4 8 3 2 6\n",
"5\n2 7 4 8 3\n"
] | [
"2\n4\n",
"9\n",
"4\n1\n9\n2\n9\n",
"9\n6\n9\n6\n9\n9\n",
"1\n1\n6\n6\n1\n4\n9\n6\n",
"9\n6\n2\n1\n2\n1\n6\n",
"9\n2\n9\n",
"2\n6\n2\n4\n6\n",
"4\n9\n2\n2\n6\n",
"2\n6\n4\n9\n2\n"
] | 1 | stdio |
Let's denote as $\text{popcount}(x)$ the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and $\text{popcount}(x)$ is maximum possible. If there are multiple... | [
"3\n1 2\n2 4\n1 10\n",
"55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10\n7 7\n7 8\n7 9\n7 10\n8 8\n8 9\n8 10\n9 9\n9 10\n10 10\n... | [
"1\n3\n7\n",
"1\n1\n3\n3\n3\n3\n7\n7\n7\n7\n2\n3\n3\n3\n3\n7\n7\n7\n7\n3\n3\n3\n3\n7\n7\n7\n7\n4\n5\n5\n7\n7\n7\n7\n5\n5\n7\n7\n7\n7\n6\n7\n7\n7\n7\n7\n7\n7\n7\n8\n9\n9\n9\n9\n10\n",
"7\n63\n511\n8191\n65535\n524287\n8388607\n67108863\n536870911\n8589934591\n68719476735\n549755813887\n8796093022207\n70368744177... | 1 | stdio |
AtCoDeer the deer found N rectangle lying on the table, each with height 1.
If we consider the surface of the desk as a two-dimensional plane, the i-th rectangle i(1≤i≤N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i], as shown in the following figure:
AtCoDeer will move these rectangles ho... | [
"3\n1 3\n5 7\n1 3\n",
"3\n2 5\n4 6\n1 4\n",
"5\n999999999 1000000000\n1 2\n314 315\n500000 500001\n999999999 1000000000\n",
"5\n123456 789012\n123 456\n12 345678901\n123456 789012\n1 23\n",
"1\n1 400\n"
] | [
"2\n",
"0\n",
"1999999680\n",
"246433\n",
"0\n"
] | 1 | stdio |
In number world, two different numbers are friends if they have a lot in common, but also each one has unique perks.
More precisely, two different numbers $a$ and $b$ are friends if $gcd(a,b)$, $\frac{a}{gcd(a,b)}$, $\frac{b}{gcd(a,b)}$ can form sides of a triangle.
Three numbers $a$, $b$ and $c$ can form sides of a ... | [
"3\n1 5 10\n",
"6\n12 432 21 199 7 1\n",
"7\n1 10 100 1000 10000 100000 1000000\n",
"100\n42 486 341 527 189 740 490 388 989 489 711 174 305 844 971 492 998 954 832 442 424 619 906 154 293 395 439 735 738 915 453 748 786 550 871 932 693 326 53 904 732 835 354 364 691 669 157 719 282 875 573 672 695 790 58 872... | [
"1\n3\n3\n",
"4\n76\n7\n41\n4\n1\n",
"1\n3\n22\n158\n1205\n9528\n78331\n",
"11\n85\n62\n92\n37\n123\n86\n69\n156\n86\n119\n35\n56\n137\n154\n87\n158\n153\n137\n78\n75\n106\n145\n32\n56\n70\n78\n122\n122\n147\n80\n124\n129\n93\n141\n149\n117\n60\n13\n145\n121\n137\n65\n65\n117\n113\n33\n120\n55\n141\n97\n113\n... | 1 | stdio |
You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x_1, x_2, ..., x_{k}} (1 ≤ x_{i} ≤ n, 0 < k < n) the sums of elements on that positions in a and b are different, i. e. $\sum_{i = 1}^{k} a_{x_{i}} \neq \sum_{i = 1}^{k} b_{x_{i}}$... | [
"2\n1 2\n",
"4\n1000 100 10 1\n",
"5\n1 3 4 5 2\n",
"1\n10000000\n",
"4\n1 5 8 4\n",
"3\n1 3 2\n",
"4\n3 1 2 4\n",
"12\n7 1 62 12 3 5 8 9 10 22 23 0\n",
"17\n1 3 2 5 4 6 7 8 10 9 13 11 12 14 15 16 18\n",
"22\n1 3 5 7 22 2 4 6 8 9 10 11 12 13 15 14 17 18 16 20 19 23\n"
] | [
"2 1 \n",
"100 1 1000 10\n",
"5 2 3 4 1 \n",
"10000000 \n",
"8 4 5 1 \n",
"3 2 1 \n",
"2 4 1 3 \n",
"5 0 23 10 1 3 7 8 9 12 22 62 \n",
"18 2 1 4 3 5 6 7 9 8 12 10 11 13 14 15 16 \n",
"23 2 4 6 20 1 3 5 7 8 9 10 11 12 14 13 16 17 15 19 18 22 \n"
] | 1 | stdio |