problem_id
stringlengths
32
32
name
stringlengths
2
112
problem
stringlengths
200
14k
test_cases
stringlengths
33
79.2M
difficulty
stringclasses
34 values
language
listlengths
1
1
source
stringclasses
15 values
num_solutions
int64
1
1.12M
starter_code
stringlengths
0
1.47k
subset
stringclasses
4 values
fc15856b0b1fce8b88f14daf45f5346a
Painting Fence
Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as *n* vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from o...
{"inputs": ["5\n2 2 1 2 1", "2\n2 2", "1\n5", "5\n2 2 1 2 2", "5\n2 2 1 5 1", "1\n1", "1\n1000000000", "2\n999635584 999595693", "10\n3 3 6 4 2 3 2 2 3 3", "14\n1 1 3 1 1 4 4 4 4 4 4 4 4 4", "6\n100 100 100 100 100 1", "7\n5 5 1 5 5 4 1", "4\n3 4 5 6", "4\n2 3 4 5", "8\n5000 5000 5 5000 5000 5000 5000 5000", "10\n4 4 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
fc1b001cfed3da5734fdd1993f262d18
Demiurges Play Again
Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game. There is a rooted tree on *n* nodes, *m* of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves...
{"inputs": ["5\n1 2\n1 3\n2 4\n2 5", "6\n1 2\n1 3\n3 4\n1 5\n5 6", "1", "2\n1 2", "3\n1 2\n1 3", "10\n1 2\n1 3\n3 4\n3 5\n4 6\n1 7\n3 8\n2 9\n6 10", "50\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
fc3f5cc330553f4dda9bd40e698161f3
Quantity of Strings
Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly *n*, based on the alphabet of size *m*. Any its substring with length equal to *k* is a palindrome. How many such strings exist? Your task ...
{"inputs": ["1 1 1", "5 2 4", "7 4 20", "8 13 9", "10 23 9", "10 25 8", "997 1752 1000", "784 1 1999", "341 9 342", "777 1 777", "542 13 542", "1501 893 1501", "1321 95 2", "2000 1000 3", "1769 849 1000", "1000 2 1", "345 1777 1", "1999 2000 2000", "1984 1847 1992", "2000 2000 2000", "1451 239 1451", "2000 2000 1", "12...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
fc5b374c0c467d1243d8dce71f849633
Remove Duplicates
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. The first line contains a single integer $n$ ($1 \le n \...
{"inputs": ["6\n1 5 5 1 6 1", "5\n2 4 2 4 4", "5\n6 6 6 6 6", "7\n1 2 3 4 2 2 3", "9\n100 100 100 99 99 99 100 100 100", "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868", "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
191
codeforces
fc7661143e4b4a08461bb4de57185e76
Connecting Universities
Treeland is a country in which there are *n* towns connected by *n*<=-<=1 two-way road such that it's possible to get from any town to any other town. In Treeland there are 2*k* universities which are located in different towns. Recently, the president signed the decree to connect universities by high-speed network...
{"inputs": ["7 2\n1 5 6 2\n1 3\n3 2\n4 5\n3 7\n4 3\n4 6", "9 3\n3 2 1 6 5 9\n8 9\n3 2\n2 7\n3 4\n7 6\n4 5\n2 1\n2 8", "41 3\n11 10 15 35 34 6\n28 2\n25 3\n9 4\n11 5\n7 6\n24 7\n19 8\n1 9\n34 10\n23 11\n17 12\n32 13\n32 14\n32 15\n33 16\n8 17\n19 18\n40 19\n15 20\n6 21\n41 22\n35 23\n13 24\n6 25\n22 26\n4 27\n31 28\n34 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
fc7f2f0fe3c4df9f28490f80781ce3fe
The Tag Game
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree. Alice starts at vertex 1 and Bob starts at vertex *x* (*x*<=≠<=1). The moves are made in turns, Bob go...
{"inputs": ["4 3\n1 2\n2 3\n2 4", "5 2\n1 2\n2 3\n3 4\n2 5", "2 2\n2 1", "3 3\n2 1\n3 1", "3 3\n1 2\n3 2", "10 4\n5 4\n8 3\n4 6\n5 3\n7 9\n1 3\n5 10\n2 9\n9 8", "10 7\n8 7\n2 8\n2 3\n10 6\n4 6\n4 1\n10 5\n7 5\n9 8", "8 3\n2 1\n3 1\n4 3\n5 1\n6 1\n7 1\n8 6", "34 33\n2 1\n3 2\n4 3\n5 2\n6 3\n7 2\n8 5\n9 7\n10 8\n11 7\n12...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
fc8112700bb19b73b5f2cb0b6e677aac
Robot Arm
Roger is a robot. He has an arm that is a series of *n* segments connected to each other. The endpoints of the *i*-th segment are initially located at points (*i*<=-<=1,<=0) and (*i*,<=0). The endpoint at (*i*<=-<=1,<=0) is colored red and the endpoint at (*i*,<=0) is colored blue for all segments. Thus, the blue endpo...
{"inputs": ["5 4\n1 1 3\n2 3 90\n2 5 48\n1 4 1", "1 1\n2 1 302", "50 50\n1 41 261\n2 47 324\n1 41 256\n1 31 339\n2 23 116\n2 44 184\n2 32 115\n1 40 301\n2 40 303\n1 29 309\n2 49 348\n2 47 356\n1 41 263\n2 42 276\n1 45 135\n1 33 226\n2 31 166\n1 50 171\n2 47 166\n2 50 284\n2 25 324\n2 48 307\n2 41 176\n1 50 353\n1 45 32...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
fc94946d03aa4b544ec22213ebaed643
Jury Size
In 2013, the writers of Berland State University should prepare problems for *n* Olympiads. We will assume that the Olympiads are numbered with consecutive integers from 1 to *n*. For each Olympiad we know how many members of the jury must be involved in its preparation, as well as the time required to prepare the prob...
{"inputs": ["2\n5 23 1 2\n3 13 2 3", "3\n12 9 2 1\n12 8 1 3\n12 8 2 2", "1\n1 10 1 13", "3\n3 16 25 1\n3 15 9 34\n3 14 90 87", "4\n2 15 52 53\n2 15 35 81\n2 15 39 96\n2 14 87 7", "5\n3 6 40 89\n3 4 24 64\n2 28 83 1\n3 3 15 32\n3 8 54 28", "10\n8 8 4 18\n8 10 100 36\n8 9 17 51\n8 10 90 8\n8 10 64 45\n8 10 90 81\n8 11 20...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
fcc1dd7c8d355e18d211514350671eac
Curriculum Vitae
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zer...
{"inputs": ["4\n1 1 0 1", "6\n0 1 0 0 1 0", "1\n0", "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", "100\n0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
88
codeforces
fccff7b6eaf8ac7a2e50f9817666b74d
Flowers
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red. But, for a dinner to be tasty...
{"inputs": ["3 2\n1 3\n2 3\n4 4", "1 1\n1 3", "1 2\n64329 79425"], "outputs": ["6\n5\n5", "14", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
fcd19da2696717da4756587afbd33c82
Epic Game
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take...
{"inputs": ["3 5 9", "1 1 100", "23 12 16", "95 26 29", "73 32 99", "1 1 1", "41 12 65", "13 61 100", "100 100 10", "12 24 26", "73 21 96", "17 22 81", "14 88 97", "42 81 17", "34 36 19", "21 87 12", "97 92 98", "49 25 62", "29 17 44", "10 1 10", "99 98 100", "100 100 1", "11 99 55", "8 13 21", "34 55 89", "21 34 55", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
780
codeforces
fcf8b343a907be0b2bab4149edfec28a
Valhalla Siege
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T...
{"inputs": ["5 5\n1 2 1 2 1\n3 10 1 1 1", "4 4\n1 2 3 4\n9 1 10 6", "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5", "1 1\n56563128\n897699770", "100 55\n1 2 4 4 3 5 5 2 3 4 2 1 1 2 3 5 1 5 4 2 5 4 4 3 3 5 3 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 1 4 5 3 4 4 1 5 1 5 2 2 1 4 5 3 3 1 4 2 5 4 5 3 2 5 5 2 3 2 3 2 2 3 4 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
129
codeforces
fd02ef2593cc46942a3abcb5c85a76c8
Case of Matryoshkas
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to *n*. A matryoshka with a smaller number can...
{"inputs": ["3 2\n2 1 2\n1 3", "7 3\n3 1 3 7\n2 2 5\n2 4 6", "1 1\n1 1", "3 2\n1 2\n2 1 3", "5 3\n1 4\n3 1 2 3\n1 5", "8 5\n2 1 2\n2 3 4\n1 5\n2 6 7\n1 8", "10 10\n1 5\n1 4\n1 10\n1 3\n1 7\n1 1\n1 8\n1 6\n1 9\n1 2", "20 6\n3 8 9 13\n3 4 14 20\n2 15 17\n3 2 5 11\n5 7 10 12 18 19\n4 1 3 6 16", "50 10\n6 17 21 31 42 45 49...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
fd0688f764c0b19252d911aef21b9a3b
AND-permutations
Given an integer *N*, find two permutations: 1. Permutation *p* of numbers from 1 to *N* such that *p**i*<=≠<=*i* and *p**i*<=&amp;<=*i*<==<=0 for all *i*<==<=1,<=2,<=...,<=*N*. 1. Permutation *q* of numbers from 1 to *N* such that *q**i*<=≠<=*i* and *q**i*<=&amp;<=*i*<=≠<=0 for all *i*<==<=1,<=2,<=...,<=*N*. &amp;...
{"inputs": ["3", "6", "100000", "15", "16", "17", "1", "2", "4", "5", "7", "8", "9", "10", "31", "32", "33", "63", "64", "65", "127", "128", "129", "255", "256", "257", "511", "512", "513", "1023", "1024", "1025", "2047", "2048", "2049", "4095", "4096", "4097", "8191", "8192", "8193", "16383", "16384", "16385", "32767"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
fd06e19867352ee76d0b1a3b9ab11217
Ann and Books
In Ann's favorite book shop are as many as *n* books on math and economics. Books are numbered from 1 to *n*. Each of them contains non-negative number of problems. Today there is a sale: any subsegment of a segment from *l* to *r* can be bought at a fixed price. Ann decided that she wants to buy such non-empty subs...
{"inputs": ["4 1\n1 1 1 2\n1 1 1 1\n4\n1 2\n1 3\n1 4\n3 4", "4 0\n1 2 1 2\n0 0 0 0\n1\n1 4", "10 10\n2 1 1 1 1 1 1 1 1 2\n0 10 10 0 0 10 10 10 10 0\n10\n4 10\n3 7\n9 9\n2 9\n10 10\n5 5\n2 2\n6 8\n3 4\n1 3", "10 -10\n1 2 1 2 1 1 2 2 2 1\n7 7 10 3 7 10 6 8 0 1\n10\n2 6\n10 10\n6 9\n5 8\n7 10\n2 7\n2 9\n2 7\n5 6\n2 8", "1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
fd09090ef729ff93446db38cf1352d0b
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co...
{"inputs": ["next\n2\nnextpermutation\nnextelement", "find\n4\nfind\nfindfirstof\nfindit\nfand", "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "kudljmxcse\n4\nkudljmxcse\nszjebdoad\nchz\na", "ntqwpa\n5\nvvepyowvn\nntqwpakay\nhh\nygiafasda\nntqwpadm", "aflb\n6\nsaej\nujxsiijg\npp\nhgoprw\ncp\nnt", "dzwzyj\n7\nwvixktp\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
135
codeforces
fd0a5d9f400dd636829e4e517f91376f
Friends and Presents
You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends. In addition, the...
{"inputs": ["3 1 2 3", "1 3 2 3", "916200 69682 2 3", "808351 17767 433 509", "8851 901 20897 26183", "5099 2895 16273 29473", "5099 2895 16273 29473", "4969 694 293 2347", "683651932 161878530 2 5", "325832598 637961741 2 3", "999999999 1 2 3", "11006 976 6287 9007", "150064728 173287472 439 503", "819712074 101394406...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
33
codeforces
fd147d05260e80bd25ba2a334bf9f277
Comparing Two Long Integers
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can r...
{"inputs": ["9\n10", "11\n10", "00012345\n12345", "0123\n9", "0123\n111", "9\n9", "0\n0000", "1213121\n1213121", "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
93
codeforces
fd1ce315ca7b872f90047714c866c036
Inventory
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything. During an audit, you were surprised to find out that the...
{"inputs": ["3\n1 3 2", "4\n2 2 3 3", "1\n2", "3\n3 3 1", "5\n1 1 1 1 1", "5\n5 3 4 4 2", "5\n19 11 8 8 10", "15\n2 2 1 2 1 2 3 3 1 3 2 1 2 3 2", "18\n3 11 5 9 5 4 6 4 5 7 5 1 8 11 11 2 1 9", "42\n999 863 440 1036 1186 908 330 265 382 417 858 286 834 922 42 569 79 158 312 1175 1069 188 21 1207 985 375 59 417 256 595 73...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
88
codeforces
fd83dbf0a860282e31913add3b44f5c3
Permutations
A permutation is a sequence of integers from 1 to *n* of length *n* containing each number exactly once. For example, (1), (4,<=3,<=5,<=1,<=2), (3,<=2,<=1) are permutations, and (1,<=1), (4,<=3,<=1), (2,<=3,<=4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine tha...
{"inputs": ["9\n1 2 3 1 2 1 4 2 5", "4\n4 3 2 1", "4\n1 2 2 3", "1\n1", "1\n2", "5\n1 1 1 1 1", "3\n2 1 1", "6\n3 3 2 2 1 1", "2\n1000 1", "5\n2 2 1 1 3", "10\n2 1 2 4 6 1 5 3 7 1", "10\n4 1 2 1 3 3 1 2 2 1", "10\n1 2 5 1 1 1 4 1 3 2", "20\n2 7 3 8 4 6 3 7 6 4 13 5 1 12 1 10 2 11 5 9", "20\n1 1 1 2 3 1 5 9 5 8 4 6 7 3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
fd8886c6850c1ea1e514d52a6f360e82
Autocompletion
Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor. Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboard click in order to be printed. Moreover, when Arcady has a non-e...
{"inputs": ["snow affects sports such as skiing, snowboarding, and snowmachine travel.\nsnowboarding is a recreational activity and olympic and paralympic sport.", "'co-co-co, codeforces?!'", "thun-thun-thunder, thunder, thunder\nthunder, thun-, thunder\nthun-thun-thunder, thunder\nthunder, feel the thunder\nlightning ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
fd92b19e89743bc74823f16a399a7d87
none
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 subst...
{"inputs": ["ababa\naba", "welcometoroundtwohundredandeightytwo\nd", "ddd\nd", "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\nnssnssns", "kpjmawawawawawawawawawawawawawawawawawawawawawawaw\nwawawawa", "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvv", "a\na", "a\naa", "a\nb", "ababababab\nabab"], "ou...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
fdd530dfaa50125be7d4251073dd47dd
Hiring Staff
A new Berland businessman Vitaly is going to open a household appliances' store. All he's got to do now is to hire the staff. The store will work seven days a week, but not around the clock. Every day at least *k* people must work in the store. Berland has a law that determines the order of working days and non-worki...
{"inputs": ["4 3 2", "3 3 1", "5 5 3", "7 6 8", "8 3 2", "5 1 1", "6 5 1", "2 1 1", "2 2 1", "3 1 1", "3 2 1", "3 3 1", "4 1 1", "4 2 1", "4 3 1", "4 4 1", "183 1 1", "284 282 1", "359 358 1", "801 801 1", "1000 1 1", "1000 999 1", "1000 1000 1", "2 1 2", "2 2 2", "3 1 2", "3 2 2", "3 3 2", "4 1 2", "4 2 2", "4 3 2", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
fde4f9235dd44012d3470d60a923de13
Sereja and Intervals
Sereja is interested in intervals of numbers, so he has prepared a problem about intervals for you. An interval of numbers is a pair of integers [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*m*). Interval [*l*1,<=*r*1] belongs to interval [*l*2,<=*r*2] if the following condition is met: *l*2<=≤<=*l*1<=≤<=*r*1<=≤<=*r*2. Sereja w...
{"inputs": ["1 1 1", "3 5 1", "2 3 3", "11 79 54", "18 46 26", "8 96 61", "154 5 3", "34 22 8", "29 27 7", "12 68 35", "23 12 10", "6 42 23", "143 645 43", "14 724 55", "166 36 1", "273 41 17", "54 806 191", "6159 7 7", "115 624 37", "8 967 200", "112 440 258", "490 119 1", "745 116 85", "52 978 871", "37 746 303", "10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
feaa637b31fdce3c496608b4398a079b
Tricky Function
Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be t...
{"inputs": ["4\n1 0 0 -1", "2\n1 -1", "100\n-57 -64 83 76 80 27 60 76 -80 -56 52 72 -17 92 -96 87 41 -88 94 89 12 42 36 34 -100 -43 -42 62 3 87 -69 -6 -27 -59 -7 5 -90 -23 63 -87 -60 -92 -40 54 -16 -47 67 -64 10 33 -19 53 -7 -62 16 -74 -36 4 -75 -55 92 3 -22 43 -30 48 -27 88 -58 41 36 8 -40 -30 -18 16 22 -66 -91 -46 48...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
feb6b1e03e665a72ca3cb3f0ccfc5ca2
Two Arithmetic Progressions
You are given two arithmetic progressions: *a*1*k*<=+<=*b*1 and *a*2*l*<=+<=*b*2. Find the number of integers *x* such that *L*<=≤<=*x*<=≤<=*R* and *x*<==<=*a*1*k*'<=+<=*b*1<==<=*a*2*l*'<=+<=*b*2, for some integers *k*',<=*l*'<=≥<=0. The only line contains six integers *a*1,<=*b*1,<=*a*2,<=*b*2,<=*L*,<=*R* (0<=&lt;<=*a...
{"inputs": ["2 0 3 3 5 21", "2 4 3 0 6 17", "2 0 4 2 -39 -37", "1 9 3 11 49 109", "3 81 5 72 -1761 501", "8 -89 20 67 8771 35222", "1 -221 894 86403 -687111 141371", "1 -1074 271 17741 -2062230 1866217", "3 2408 819 119198 -8585197 7878219", "1 341 8581 3946733 -59420141 33253737", "1 10497 19135 2995296 -301164547 -18...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
febea4f23d6799418a46ea0af82f70af
Permutation
You are given a permutation of numbers from 1 to *n*. Determine whether there's a pair of integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=*n*; *a*<=≠<=*b*) such that the element (note, that it is usual division, not integer one) is between *a* and *b* in this permutation. First line consists of a single integer *n* (1<=≤<=*n*...
{"inputs": ["4\n1 3 4 2", "5\n1 5 2 4 3", "100\n17 41 19 23 46 16 10 31 82 12 77 32 11 71 83 25 98 18 34 59 13 73 80 65 37 22 6 2 24 5 94 42 51 63 52 92 97 26 93 38 36 87 64 70 14 43 68 85 33 44 74 89 56 1 69 88 20 49 48 21 84 90 7 47 39 55 81 86 76 57 3 62 15 78 100 60 61 66 91 30 58 35 99 96 54 27 79 9 29 50 45 72 75...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
fed340b160e4eb32c6a5954134630705
Hierarchy
Nick's company employed *n* people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are *m* applications written in the following form: «employee *a**i* is ready to become a supervisor of emp...
{"inputs": ["4\n7 2 3 1\n4\n1 2 5\n2 4 1\n3 4 1\n1 3 5", "3\n1 2 3\n2\n3 1 2\n3 1 3", "1\n2\n0", "2\n5 3\n4\n1 2 0\n1 2 5\n1 2 0\n1 2 7", "3\n9 4 5\n5\n3 2 4\n1 2 4\n3 2 8\n1 3 5\n3 2 5", "3\n2 5 9\n5\n3 1 7\n2 1 1\n2 1 6\n2 1 2\n3 1 5", "3\n6 2 9\n5\n1 2 10\n3 1 4\n1 2 5\n1 2 2\n3 1 4", "4\n10 6 7 4\n5\n1 3 1\n3 4 1\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
85
codeforces
fee1c0d82e0df1ec46bbb228704921c3
Relatively Prime Graph
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
{"inputs": ["5 6", "6 12", "572 99643", "571 99403", "100 3043", "10 31", "1 1", "2 1", "100000 1", "100000 99999", "100000 100000", "1000 100000", "572 99644", "571 99404", "100 3044", "10 32", "100000 99998", "55910 88645", "72050 72069", "53599 55493", "56557 100000", "1001 100000", "50000 100000", "530 100000", "46...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
fef0dc43ecff47f600561e8599217ddf
Bookshelves
Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive price. Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office. He learned that in the ne...
{"inputs": ["10 4\n9 14 28 1 7 13 15 29 2 31", "7 3\n3 14 15 92 65 35 89", "40 5\n6 18 24 5 14 16 31 9 15 5 25 2 18 12 19 27 10 23 23 18 22 14 1 14 6 14 17 28 11 21 8 23 10 30 21 5 17 11 26 16", "20 15\n927353279298143 655102800384382 40376603048780 1008958973042960 1123049780860278 853122601026128 154596679092462 2000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
fefe761d353a35a1825f8de3622e0e44
Phone numbers
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three...
{"inputs": ["6\n549871", "7\n1198733", "2\n74", "2\n33", "3\n074", "3\n081", "4\n3811", "5\n21583", "8\n33408349", "9\n988808426", "10\n0180990956", "15\n433488906230138", "22\n7135498415686025907059", "49\n2429965524999668169991253653390090510755018570235", "72\n49192533778411177050014761988172752557003973550743936062...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
157
codeforces
ff10d04958977d2d3ed41f2c817605a8
String Compression
Ivan wants to write a letter to his friend. The letter is a string *s* consisting of lowercase Latin letters. Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string *s* instea...
{"inputs": ["aaaaaaaaaa", "abcab", "cczabababab", "kbyjorwqjk", "baaabbbaba", "aaaaaaaaaa", "cbbbcccbbc", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "hltcdvuobkormkxkbmpfjniilublkrckmvvxemcyietgxcyjgrjwsdsgsfmoqnmbxozfavxopklhldhnsjpxhejxaxuctxeifglx", "agdmd...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
ff140e99d830432ae85962a533046d13
Feed the cat
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points. At any time Andrew can visit the store where tasty buns are...
{"inputs": ["19 00\n255 1 100 1", "17 41\n1000 6 15 11", "16 34\n61066 14 50 59", "18 18\n23331 86 87 41", "10 48\n68438 8 18 29", "08 05\n63677 9 83 25", "00 00\n100000 100 100 100", "20 55\n100000 100 100 100", "23 59\n100000 100 100 100", "00 00\n1 100 100 100", "21 26\n33193 54 97 66", "20 45\n33756 24 21 1", "14 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
144
codeforces
ff421c3540ee1df661234b450f1c7093
Chip Play
Let's consider the following game. We have a rectangular field *n*<=×<=*m* in size. Some squares of the field contain chips. Each chip has an arrow painted on it. Thus, each chip on the field points in one of the following directions: up, down, left or right. The player may choose a chip and make a move with it. The...
{"inputs": ["4 4\nDRLD\nU.UL\n.UUR\nRDDL", "2 2\nRD\nUL", "5 5\nUD..L\nRRD..\n..RDD\nUUL..\nDDLRR", "10 10\n.L.....R..\n.........U\n..D....D..\n.R......L.\n....L.....\n.........D\n......U...\nD....R....\n...U......\n........L.", "17 13\n...LD.UR.RUU.\nLDLULDUDRRDRL\nDD.RRLRUR.UD.\nRU...D...LD..\n.UR.R...URUUD\n.RURD.RL...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
ff63427e0a246e9a8c857186864b88ce
k-String
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string...
{"inputs": ["2\naazz", "3\nabcabcabz", "1\na", "2\nabba", "2\naaab", "7\nabacaba", "5\naaaaa", "3\naabaaaaabb", "2\naaab", "2\nbabac", "3\nbbbccc", "2\naa", "250\ncecececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececec...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
324
codeforces
ff80a5b10d8a65e60f520fb16ca6252b
none
Fox Ciel is participating in a party in Prime Kingdom. There are *n* foxes there (include Fox Ciel). The i-th fox is *a**i* years old. They will have dinner around some round tables. You want to distribute foxes such that: 1. Each fox is sitting at some table. 1. Each table has at least 3 foxes sitting around it. 1...
{"inputs": ["4\n3 4 8 9", "5\n2 2 2 2 2", "12\n2 3 4 5 6 7 8 9 10 11 12 13", "24\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25", "4\n2 2 9973 9967", "30\n2 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", "20\n76 38 74 176 106 134 12 88 66 178 63 105 199 99 29 67 135 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
ff9235cd44659116788a8be5c260fa52
Lucky Permutation
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically *k*-th permutation of integers from 1 to *n*. Determine ...
{"inputs": ["7 4", "4 7", "7 1", "7 5040", "10 1023", "7 7477", "10 10000", "3 7", "27 1", "40 8544", "47 1", "47 8547744", "50 1000000000", "64 87", "98 854555", "100 1", "9985 5888454", "1 1", "1 2", "2 1000000000", "10 1000000000", "20 1000000000", "777777 1", "777777 2", "777474 10000", "1000000000 1", "777777777 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
ffffc0199ae7229539d28ba0d02e9047
Mr. Kitayuta's Gift
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes...
{"inputs": ["revive", "ee", "kitayuta", "evima", "a", "yutampo", "fft", "shuseki", "lsdijfjisl", "ewcdcwerp", "noon", "add", "iq", "hogloid", "yosupo", "stat", "level", "iwiwi", "racecar", "dog", "squirrel", "slime", "palindrome", "nqwcvcwqn", "lsdijfjisl", "jewiiwefj", "vnwmvvmonv", "zennyuu", "mrtoudai", "z", "babccb...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
108
codeforces